|
Lines 25-30
use Modern::Perl;
Link Here
|
| 25 |
use CGI qw ( -utf8 ); |
25 |
use CGI qw ( -utf8 ); |
| 26 |
use Carp; |
26 |
use Carp; |
| 27 |
use YAML qw/Load/; |
27 |
use YAML qw/Load/; |
|
|
28 |
use List::MoreUtils qw/uniq/; |
| 28 |
|
29 |
|
| 29 |
use C4::Context; |
30 |
use C4::Context; |
| 30 |
use C4::Auth; |
31 |
use C4::Auth; |
|
Lines 181-265
if ($op eq ""){
Link Here
|
| 181 |
} else { |
182 |
} else { |
| 182 |
SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' ); |
183 |
SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' ); |
| 183 |
} |
184 |
} |
| 184 |
# 3rd add order |
185 |
|
| 185 |
my $patron = C4::Members::GetMember( borrowernumber => $loggedinuser ); |
186 |
# Add items from MarcItemFieldsToOrder |
| 186 |
# get quantity in the MARC record (1 if none) |
187 |
my @homebranches = $input->multi_param('homebranch'); |
| 187 |
my $quantity = GetMarcQuantity($marcrecord, C4::Context->preference('marcflavour')) || 1; |
188 |
my $count = scalar @homebranches; |
| 188 |
my %orderinfo = ( |
189 |
my @holdingbranches = $input->multi_param('holdingbranch'); |
| 189 |
biblionumber => $biblionumber, |
190 |
my @itypes = $input->multi_param('itype'); |
| 190 |
basketno => $cgiparams->{'basketno'}, |
191 |
my @nonpublic_notes = $input->multi_param('nonpublic_note'); |
| 191 |
quantity => $c_quantity, |
192 |
my @public_notes = $input->multi_param('public_note'); |
| 192 |
branchcode => $patron->{branchcode}, |
193 |
my @locs = $input->multi_param('loc'); |
| 193 |
budget_id => $c_budget_id, |
194 |
my @ccodes = $input->multi_param('ccodes'); |
| 194 |
uncertainprice => 1, |
195 |
my @notforloans = $input->multi_param('notforloans'); |
| 195 |
sort1 => $c_sort1, |
196 |
my @uris = $input->multi_param('uri'); |
| 196 |
sort2 => $c_sort2, |
197 |
my @copynos = $input->multi_param('copyno'); |
| 197 |
order_internalnote => $cgiparams->{'all_order_internalnote'}, |
198 |
my @budget_codes = $input->multi_param('budget_code'); |
| 198 |
order_vendornote => $cgiparams->{'all_order_vendornote'}, |
199 |
my @itemprices = $input->multi_param('itemprice'); |
| 199 |
currency => $cgiparams->{'all_currency'}, |
200 |
my $itemcreation = 0; |
| 200 |
); |
201 |
for (my $i = 0; $i < $count; $i++) { |
| 201 |
# get the price if there is one. |
202 |
$itemcreation = 1; |
| 202 |
my $price= shift( @prices ) || GetMarcPrice($marcrecord, C4::Context->preference('marcflavour')); |
203 |
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ |
| 203 |
if ($price){ |
204 |
homebranch => $homebranches[$i], |
| 204 |
# in France, the cents separator is the , but sometimes, ppl use a . |
205 |
holdingbranch => $holdingbranches[$i], |
| 205 |
# in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation |
206 |
itemnotes_nonpublic => $nonpublic_notes[$i], |
| 206 |
$price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR"; |
207 |
itemnotes => $public_notes[$i], |
| 207 |
$price = Koha::Number::Price->new($price)->unformat; |
208 |
location => $locs[$i], |
| 208 |
$orderinfo{gstrate} = $bookseller->{gstrate}; |
209 |
ccode => $ccodes[$i], |
| 209 |
my $c = $c_discount ? $c_discount : $bookseller->{discount} / 100; |
210 |
notforloan => $notforloans[$i], |
| 210 |
if ( $bookseller->{listincgst} ) { |
211 |
uri => $uris[$i], |
| 211 |
if ( $c_discount ) { |
212 |
copynumber => $copynos[$i], |
| 212 |
$orderinfo{ecost} = $price; |
213 |
price => $itemprices[$i], |
| 213 |
$orderinfo{rrp} = $orderinfo{ecost} / ( 1 - $c ); |
214 |
}, $biblionumber); |
| 214 |
} else { |
215 |
} |
| 215 |
$orderinfo{ecost} = $price * ( 1 - $c ); |
216 |
if ($itemcreation == 1) { |
| 216 |
$orderinfo{rrp} = $price; |
217 |
# Group orderlines from MarcItemFieldsToOrder |
|
|
218 |
my $budget_hash; |
| 219 |
for (my $i = 0; $i < $count; $i++) { |
| 220 |
$budget_hash->{$budget_codes[$i]}->{quantity} += 1; |
| 221 |
$budget_hash->{$budget_codes[$i]}->{price} = $itemprices[$i]; |
| 222 |
} |
| 223 |
|
| 224 |
# Create orderlines from MarcItemFieldsToOrder |
| 225 |
while(my ($budget_id, $infos) = each $budget_hash) { |
| 226 |
if ($budget_id) { |
| 227 |
my %orderinfo = ( |
| 228 |
biblionumber => $biblionumber, |
| 229 |
basketno => $cgiparams->{'basketno'}, |
| 230 |
quantity => $infos->{quantity}, |
| 231 |
budget_id => $budget_id, |
| 232 |
currency => $cgiparams->{'all_currency'}, |
| 233 |
); |
| 234 |
|
| 235 |
my $price = $infos->{price}; |
| 236 |
if ($price){ |
| 237 |
# in France, the cents separator is the , but sometimes, ppl use a . |
| 238 |
# in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation |
| 239 |
$price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR"; |
| 240 |
$price = Koha::Number::Price->new($price)->unformat; |
| 241 |
$orderinfo{gstrate} = $bookseller->{gstrate}; |
| 242 |
my $c = $c_discount ? $c_discount : $bookseller->{discount} / 100; |
| 243 |
if ( $bookseller->{listincgst} ) { |
| 244 |
if ( $c_discount ) { |
| 245 |
$orderinfo{ecost} = $price; |
| 246 |
$orderinfo{rrp} = $orderinfo{ecost} / ( 1 - $c ); |
| 247 |
} else { |
| 248 |
$orderinfo{ecost} = $price * ( 1 - $c ); |
| 249 |
$orderinfo{rrp} = $price; |
| 250 |
} |
| 251 |
} else { |
| 252 |
if ( $c_discount ) { |
| 253 |
$orderinfo{ecost} = $price / ( 1 + $orderinfo{gstrate} ); |
| 254 |
$orderinfo{rrp} = $orderinfo{ecost} / ( 1 - $c ); |
| 255 |
} else { |
| 256 |
$orderinfo{rrp} = $price / ( 1 + $orderinfo{gstrate} ); |
| 257 |
$orderinfo{ecost} = $orderinfo{rrp} * ( 1 - $c ); |
| 258 |
} |
| 259 |
} |
| 260 |
$orderinfo{listprice} = $orderinfo{rrp} / $active_currency->rate; |
| 261 |
$orderinfo{unitprice} = $orderinfo{ecost}; |
| 262 |
$orderinfo{total} = $orderinfo{ecost} * $infos->{quantity}; |
| 263 |
} else { |
| 264 |
$orderinfo{listprice} = 0; |
| 265 |
} |
| 266 |
|
| 267 |
# remove uncertainprice flag if we have found a price in the MARC record |
| 268 |
$orderinfo{uncertainprice} = 0 if $orderinfo{listprice}; |
| 269 |
my $order = Koha::Acquisition::Order->new( \%orderinfo )->insert; |
| 217 |
} |
270 |
} |
| 218 |
} else { |
271 |
} |
| 219 |
if ( $c_discount ) { |
272 |
} else { |
| 220 |
$orderinfo{ecost} = $price / ( 1 + $orderinfo{gstrate} ); |
273 |
# 3rd add order |
| 221 |
$orderinfo{rrp} = $orderinfo{ecost} / ( 1 - $c ); |
274 |
my $patron = C4::Members::GetMember( borrowernumber => $loggedinuser ); |
|
|
275 |
# get quantity in the MARC record (1 if none) |
| 276 |
my $quantity = GetMarcQuantity($marcrecord, C4::Context->preference('marcflavour')) || 1; |
| 277 |
my %orderinfo = ( |
| 278 |
biblionumber => $biblionumber, |
| 279 |
basketno => $cgiparams->{'basketno'}, |
| 280 |
quantity => $c_quantity, |
| 281 |
branchcode => $patron->{branchcode}, |
| 282 |
budget_id => $c_budget_id, |
| 283 |
uncertainprice => 1, |
| 284 |
sort1 => $c_sort1, |
| 285 |
sort2 => $c_sort2, |
| 286 |
order_internalnote => $cgiparams->{'all_order_internalnote'}, |
| 287 |
order_vendornote => $cgiparams->{'all_order_vendornote'}, |
| 288 |
currency => $cgiparams->{'all_currency'}, |
| 289 |
); |
| 290 |
# get the price if there is one. |
| 291 |
my $price= shift( @prices ) || GetMarcPrice($marcrecord, C4::Context->preference('marcflavour')); |
| 292 |
if ($price){ |
| 293 |
# in France, the cents separator is the , but sometimes, ppl use a . |
| 294 |
# in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation |
| 295 |
$price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR"; |
| 296 |
$price = Koha::Number::Price->new($price)->unformat; |
| 297 |
$orderinfo{gstrate} = $bookseller->{gstrate}; |
| 298 |
my $c = $c_discount ? $c_discount : $bookseller->{discount} / 100; |
| 299 |
if ( $bookseller->{listincgst} ) { |
| 300 |
if ( $c_discount ) { |
| 301 |
$orderinfo{ecost} = $price; |
| 302 |
$orderinfo{rrp} = $orderinfo{ecost} / ( 1 - $c ); |
| 303 |
} else { |
| 304 |
$orderinfo{ecost} = $price * ( 1 - $c ); |
| 305 |
$orderinfo{rrp} = $price; |
| 306 |
} |
| 222 |
} else { |
307 |
} else { |
| 223 |
$orderinfo{rrp} = $price / ( 1 + $orderinfo{gstrate} ); |
308 |
if ( $c_discount ) { |
| 224 |
$orderinfo{ecost} = $orderinfo{rrp} * ( 1 - $c ); |
309 |
$orderinfo{ecost} = $price / ( 1 + $orderinfo{gstrate} ); |
|
|
310 |
$orderinfo{rrp} = $orderinfo{ecost} / ( 1 - $c ); |
| 311 |
} else { |
| 312 |
$orderinfo{rrp} = $price / ( 1 + $orderinfo{gstrate} ); |
| 313 |
$orderinfo{ecost} = $orderinfo{rrp} * ( 1 - $c ); |
| 314 |
} |
| 225 |
} |
315 |
} |
|
|
316 |
$orderinfo{listprice} = $orderinfo{rrp} / $active_currency->rate; |
| 317 |
$orderinfo{unitprice} = $orderinfo{ecost}; |
| 318 |
$orderinfo{total} = $orderinfo{ecost} * $c_quantity; |
| 319 |
} else { |
| 320 |
$orderinfo{listprice} = 0; |
| 226 |
} |
321 |
} |
| 227 |
$orderinfo{listprice} = $orderinfo{rrp} / $active_currency->rate; |
|
|
| 228 |
$orderinfo{unitprice} = $orderinfo{ecost}; |
| 229 |
$orderinfo{total} = $orderinfo{ecost} * $c_quantity; |
| 230 |
} else { |
| 231 |
$orderinfo{listprice} = 0; |
| 232 |
} |
| 233 |
|
322 |
|
| 234 |
# remove uncertainprice flag if we have found a price in the MARC record |
323 |
# remove uncertainprice flag if we have found a price in the MARC record |
| 235 |
$orderinfo{uncertainprice} = 0 if $orderinfo{listprice}; |
324 |
$orderinfo{uncertainprice} = 0 if $orderinfo{listprice}; |
| 236 |
my $order = Koha::Acquisition::Order->new( \%orderinfo )->insert; |
325 |
my $order = Koha::Acquisition::Order->new( \%orderinfo )->insert; |
| 237 |
|
326 |
|
| 238 |
# 4th, add items if applicable |
327 |
|
| 239 |
# parse the item sent by the form, and create an item just for the import_record_id we are dealing with |
328 |
# 4th, add items if applicable |
| 240 |
# this is not optimised, but it's working ! |
329 |
# parse the item sent by the form, and create an item just for the import_record_id we are dealing with |
| 241 |
my $basket = GetBasket($cgiparams->{basketno}); |
330 |
# this is not optimised, but it's working ! |
| 242 |
if ( C4::Context->preference('AcqCreateItem') eq 'ordering' && !$basket->{is_standing} ) { |
331 |
my $basket = GetBasket($cgiparams->{basketno}); |
| 243 |
my @tags = $input->multi_param('tag'); |
332 |
if ( C4::Context->preference('AcqCreateItem') eq 'ordering' && !$basket->{is_standing} ) { |
| 244 |
my @subfields = $input->multi_param('subfield'); |
333 |
my @tags = $input->multi_param('tag'); |
| 245 |
my @field_values = $input->multi_param('field_value'); |
334 |
my @subfields = $input->multi_param('subfield'); |
| 246 |
my @serials = $input->multi_param('serial'); |
335 |
my @field_values = $input->multi_param('field_value'); |
| 247 |
my @ind_tag = $input->multi_param('ind_tag'); |
336 |
my @serials = $input->multi_param('serial'); |
| 248 |
my @indicator = $input->multi_param('indicator'); |
337 |
my @ind_tag = $input->multi_param('ind_tag'); |
| 249 |
my $item; |
338 |
my @indicator = $input->multi_param('indicator'); |
| 250 |
push @{ $item->{tags} }, $tags[0]; |
339 |
my $item; |
| 251 |
push @{ $item->{subfields} }, $subfields[0]; |
340 |
push @{ $item->{tags} }, $tags[0]; |
| 252 |
push @{ $item->{field_values} }, $field_values[0]; |
341 |
push @{ $item->{subfields} }, $subfields[0]; |
| 253 |
push @{ $item->{ind_tag} }, $ind_tag[0]; |
342 |
push @{ $item->{field_values} }, $field_values[0]; |
| 254 |
push @{ $item->{indicator} }, $indicator[0]; |
343 |
push @{ $item->{ind_tag} }, $ind_tag[0]; |
| 255 |
my $xml = TransformHtmlToXml( \@tags, \@subfields, \@field_values, \@indicator, \@ind_tag ); |
344 |
push @{ $item->{indicator} }, $indicator[0]; |
| 256 |
my $record = MARC::Record::new_from_xml( $xml, 'UTF-8' ); |
345 |
my $xml = TransformHtmlToXml( \@tags, \@subfields, \@field_values, \@indicator, \@ind_tag ); |
| 257 |
for (my $qtyloop=1;$qtyloop <= $c_quantity;$qtyloop++) { |
346 |
my $record = MARC::Record::new_from_xml( $xml, 'UTF-8' ); |
| 258 |
my ( $biblionumber, $bibitemnum, $itemnumber ) = AddItemFromMarc( $record, $biblionumber ); |
347 |
for (my $qtyloop=1;$qtyloop <= $c_quantity;$qtyloop++) { |
| 259 |
$order->add_item( $itemnumber ); |
348 |
my ( $biblionumber, $bibitemnum, $itemnumber ) = AddItemFromMarc( $record, $biblionumber ); |
|
|
349 |
$order->add_item( $itemnumber ); |
| 350 |
} |
| 351 |
} else { |
| 352 |
SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' ); |
| 260 |
} |
353 |
} |
| 261 |
} else { |
|
|
| 262 |
SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' ); |
| 263 |
} |
354 |
} |
| 264 |
$imported++; |
355 |
$imported++; |
| 265 |
} |
356 |
} |
|
Lines 290-295
foreach my $r ( @{$budgets_hierarchy} ) {
Link Here
|
| 290 |
push @{$budget_loop}, |
381 |
push @{$budget_loop}, |
| 291 |
{ b_id => $r->{budget_id}, |
382 |
{ b_id => $r->{budget_id}, |
| 292 |
b_txt => $r->{budget_name}, |
383 |
b_txt => $r->{budget_name}, |
|
|
384 |
b_code => $r->{budget_code}, |
| 293 |
b_sort1_authcat => $r->{'sort1_authcat'}, |
385 |
b_sort1_authcat => $r->{'sort1_authcat'}, |
| 294 |
b_sort2_authcat => $r->{'sort2_authcat'}, |
386 |
b_sort2_authcat => $r->{'sort2_authcat'}, |
| 295 |
b_active => $r->{budget_period_active}, |
387 |
b_active => $r->{budget_period_active}, |
|
Lines 341-346
sub import_biblios_list {
Link Here
|
| 341 |
return () unless $batch and $batch->{import_status} =~ /^staged$|^reverted$/; |
433 |
return () unless $batch and $batch->{import_status} =~ /^staged$|^reverted$/; |
| 342 |
my $biblios = GetImportRecordsRange($import_batch_id,'','',$batch->{import_status}); |
434 |
my $biblios = GetImportRecordsRange($import_batch_id,'','',$batch->{import_status}); |
| 343 |
my @list = (); |
435 |
my @list = (); |
|
|
436 |
my $item_id = 1; |
| 437 |
my $item_error = 0; |
| 438 |
|
| 439 |
my $ccodes = GetKohaAuthorisedValues("items.ccode"); |
| 440 |
my $locations = GetKohaAuthorisedValues("items.location"); |
| 441 |
# location list |
| 442 |
my @locations; |
| 443 |
foreach (sort keys %$locations) { |
| 444 |
push @locations, { code => $_, description => "$_ - " . $locations->{$_} }; |
| 445 |
} |
| 446 |
my @ccodes; |
| 447 |
foreach (sort {$ccodes->{$a} cmp $ccodes->{$b}} keys %$ccodes) { |
| 448 |
push @ccodes, { code => $_, description => $ccodes->{$_} }; |
| 449 |
} |
| 450 |
|
| 451 |
|
| 344 |
|
452 |
|
| 345 |
foreach my $biblio (@$biblios) { |
453 |
foreach my $biblio (@$biblios) { |
| 346 |
my $citation = $biblio->{'title'}; |
454 |
my $citation = $biblio->{'title'}; |
|
Lines 364-370
sub import_biblios_list {
Link Here
|
| 364 |
); |
472 |
); |
| 365 |
my ( $marcblob, $encoding ) = GetImportRecordMarc( $biblio->{'import_record_id'} ); |
473 |
my ( $marcblob, $encoding ) = GetImportRecordMarc( $biblio->{'import_record_id'} ); |
| 366 |
my $marcrecord = MARC::Record->new_from_usmarc($marcblob) || die "couldn't translate marc information"; |
474 |
my $marcrecord = MARC::Record->new_from_usmarc($marcblob) || die "couldn't translate marc information"; |
| 367 |
my $infos = get_infos_syspref($marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2']); |
475 |
|
|
|
476 |
my $infos = get_infos_syspref('MarcFieldsToOrder', $marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2']); |
| 368 |
my $price = $infos->{price}; |
477 |
my $price = $infos->{price}; |
| 369 |
my $quantity = $infos->{quantity}; |
478 |
my $quantity = $infos->{quantity}; |
| 370 |
my $budget_code = $infos->{budget_code}; |
479 |
my $budget_code = $infos->{budget_code}; |
|
Lines 378-396
sub import_biblios_list {
Link Here
|
| 378 |
$budget_id = $biblio_budget->{budget_id}; |
487 |
$budget_id = $biblio_budget->{budget_id}; |
| 379 |
} |
488 |
} |
| 380 |
} |
489 |
} |
| 381 |
$cellrecord{price} = $price || ''; |
|
|
| 382 |
$cellrecord{quantity} = $quantity || ''; |
| 383 |
$cellrecord{budget_id} = $budget_id || ''; |
| 384 |
$cellrecord{discount} = $discount || ''; |
| 385 |
$cellrecord{sort1} = $sort1 || ''; |
| 386 |
$cellrecord{sort2} = $sort2 || ''; |
| 387 |
|
490 |
|
|
|
491 |
# Items |
| 492 |
my @itemlist = (); |
| 493 |
my $all_items_quantity = 0; |
| 494 |
my $alliteminfos = get_infos_syspref_on_item('MarcItemFieldsToOrder', $marcrecord, ['homebranch', 'holdingbranch', 'itype', 'nonpublic_note', 'public_note', 'loc', 'ccode', 'notforloan', 'uri', 'copyno', 'price', 'quantity', 'budget_code']); |
| 495 |
if ($alliteminfos != -1) { |
| 496 |
foreach my $iteminfos (@$alliteminfos) { |
| 497 |
my $item_homebranch = $iteminfos->{homebranch}; |
| 498 |
my $item_holdingbranch = $iteminfos->{holdingbranch}; |
| 499 |
my $item_itype = $iteminfos->{itype}; |
| 500 |
my $item_nonpublic_note = $iteminfos->{nonpublic_note}; |
| 501 |
my $item_public_note = $iteminfos->{public_note}; |
| 502 |
my $item_loc = $iteminfos->{loc}; |
| 503 |
my $item_ccode = $iteminfos->{ccode}; |
| 504 |
my $item_notforloan = $iteminfos->{notforloan}; |
| 505 |
my $item_uri = $iteminfos->{uri}; |
| 506 |
my $item_copyno = $iteminfos->{copyno}; |
| 507 |
my $item_quantity = $iteminfos->{quantity} || 1; |
| 508 |
my $item_budget_code = $iteminfos->{budget_code}; |
| 509 |
my $item_price = $iteminfos->{price}; |
| 510 |
|
| 511 |
for (my $i = 0; $i < $item_quantity; $i++) { |
| 512 |
|
| 513 |
my %itemrecord = ( |
| 514 |
'item_id' => $item_id++, |
| 515 |
'homebranch' => $item_homebranch, |
| 516 |
'holdingbranch' => $item_holdingbranch, |
| 517 |
'itype' => $item_itype, |
| 518 |
'nonpublic_note' => $item_nonpublic_note, |
| 519 |
'public_note' => $item_public_note, |
| 520 |
'loc' => $item_loc, |
| 521 |
'ccode' => $item_ccode, |
| 522 |
'notforloan' => $item_notforloan, |
| 523 |
'uri' => $item_uri, |
| 524 |
'copyno' => $item_copyno, |
| 525 |
'quantity' => $item_quantity, |
| 526 |
'budget_code' => $item_budget_code || $budget_code, |
| 527 |
'itemprice' => $item_price || $price, |
| 528 |
); |
| 529 |
$all_items_quantity++; |
| 530 |
push @itemlist, \%itemrecord; |
| 531 |
|
| 532 |
} |
| 533 |
} |
| 534 |
|
| 535 |
$cellrecord{'iteminfos'} = \@itemlist; |
| 536 |
} else { |
| 537 |
$item_error = 1; |
| 538 |
} |
| 388 |
push @list, \%cellrecord; |
539 |
push @list, \%cellrecord; |
|
|
540 |
|
| 541 |
if ($alliteminfos == -1 || scalar(@$alliteminfos) == 0) { |
| 542 |
$cellrecord{price} = $price || ''; |
| 543 |
$cellrecord{quantity} = $quantity || ''; |
| 544 |
$cellrecord{budget_id} = $budget_id || ''; |
| 545 |
$cellrecord{discount} = $discount || ''; |
| 546 |
$cellrecord{sort1} = $sort1 || ''; |
| 547 |
$cellrecord{sort2} = $sort2 || ''; |
| 548 |
} else { |
| 549 |
$cellrecord{quantity} = $all_items_quantity; |
| 550 |
} |
| 551 |
|
| 389 |
} |
552 |
} |
| 390 |
my $num_records = $batch->{'num_records'}; |
553 |
my $num_records = $batch->{'num_records'}; |
| 391 |
my $overlay_action = GetImportBatchOverlayAction($import_batch_id); |
554 |
my $overlay_action = GetImportBatchOverlayAction($import_batch_id); |
| 392 |
my $nomatch_action = GetImportBatchNoMatchAction($import_batch_id); |
555 |
my $nomatch_action = GetImportBatchNoMatchAction($import_batch_id); |
| 393 |
my $item_action = GetImportBatchItemAction($import_batch_id); |
556 |
my $item_action = GetImportBatchItemAction($import_batch_id); |
|
|
557 |
my @itypes = Koha::ItemTypes->search; |
| 394 |
$template->param(biblio_list => \@list, |
558 |
$template->param(biblio_list => \@list, |
| 395 |
num_results => $num_records, |
559 |
num_results => $num_records, |
| 396 |
import_batch_id => $import_batch_id, |
560 |
import_batch_id => $import_batch_id, |
|
Lines 399-405
sub import_biblios_list {
Link Here
|
| 399 |
"nomatch_action_${nomatch_action}" => 1, |
563 |
"nomatch_action_${nomatch_action}" => 1, |
| 400 |
nomatch_action => $nomatch_action, |
564 |
nomatch_action => $nomatch_action, |
| 401 |
"item_action_${item_action}" => 1, |
565 |
"item_action_${item_action}" => 1, |
| 402 |
item_action => $item_action |
566 |
item_action => $item_action, |
|
|
567 |
item_error => $item_error, |
| 568 |
branchloop => GetBranchesLoop(), |
| 569 |
locationloop => \@locations, |
| 570 |
itypeloop => \@itypes, |
| 571 |
ccodeloop => \@ccodes, |
| 403 |
); |
572 |
); |
| 404 |
batch_info($template, $batch); |
573 |
batch_info($template, $batch); |
| 405 |
} |
574 |
} |
|
Lines 446-459
sub add_matcher_list {
Link Here
|
| 446 |
} |
615 |
} |
| 447 |
|
616 |
|
| 448 |
sub get_infos_syspref { |
617 |
sub get_infos_syspref { |
| 449 |
my ($record, $field_list) = @_; |
618 |
my ($syspref_name, $record, $field_list) = @_; |
| 450 |
my $syspref = C4::Context->preference('MarcFieldsToOrder'); |
619 |
my $syspref = C4::Context->preference($syspref_name); |
| 451 |
$syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt |
620 |
$syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt |
| 452 |
my $yaml = eval { |
621 |
my $yaml = eval { |
| 453 |
YAML::Load($syspref); |
622 |
YAML::Load($syspref); |
| 454 |
}; |
623 |
}; |
| 455 |
if ( $@ ) { |
624 |
if ( $@ ) { |
| 456 |
warn "Unable to parse MarcFieldsToOrder syspref : $@"; |
625 |
warn "Unable to parse $syspref syspref : $@"; |
| 457 |
return (); |
626 |
return (); |
| 458 |
} |
627 |
} |
| 459 |
my $r; |
628 |
my $r; |
|
Lines 471-473
sub get_infos_syspref {
Link Here
|
| 471 |
} |
640 |
} |
| 472 |
return $r; |
641 |
return $r; |
| 473 |
} |
642 |
} |
|
|
643 |
|
| 644 |
sub equal_number_of_fields { |
| 645 |
my ($tags_list, $record) = @_; |
| 646 |
my $refcount = 0; |
| 647 |
my $count = 0; |
| 648 |
for my $tag (@$tags_list) { |
| 649 |
return -1 if $count != $refcount; |
| 650 |
$count = 0; |
| 651 |
for my $field ($record->field($tag)) { |
| 652 |
$count++; |
| 653 |
} |
| 654 |
$refcount = $count if ($refcount == 0); |
| 655 |
} |
| 656 |
return -1 if $count != $refcount; |
| 657 |
return $count; |
| 658 |
} |
| 659 |
|
| 660 |
sub get_infos_syspref_on_item { |
| 661 |
my ($syspref_name, $record, $field_list) = @_; |
| 662 |
my $syspref = C4::Context->preference($syspref_name); |
| 663 |
$syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt |
| 664 |
my $yaml = eval { |
| 665 |
YAML::Load($syspref); |
| 666 |
}; |
| 667 |
if ( $@ ) { |
| 668 |
warn "Unable to parse $syspref syspref : $@"; |
| 669 |
return (); |
| 670 |
} |
| 671 |
my @result; |
| 672 |
my @tags_list; |
| 673 |
|
| 674 |
# Check tags in syspref definition |
| 675 |
for my $field_name ( @$field_list ) { |
| 676 |
next unless exists $yaml->{$field_name}; |
| 677 |
my @fields = split /\|/, $yaml->{$field_name}; |
| 678 |
for my $field ( @fields ) { |
| 679 |
my ( $f, $sf ) = split /\$/, $field; |
| 680 |
next unless $f and $sf; |
| 681 |
push @tags_list, $f; |
| 682 |
} |
| 683 |
} |
| 684 |
@tags_list = List::MoreUtils::uniq(@tags_list); |
| 685 |
|
| 686 |
my $tags_count = equal_number_of_fields(\@tags_list, $record); |
| 687 |
# Return if the number of theses fields in the record is not the same. |
| 688 |
return -1 if $tags_count == -1; |
| 689 |
|
| 690 |
# Gather the fields |
| 691 |
my $fields_hash; |
| 692 |
foreach my $tag (@tags_list) { |
| 693 |
my @tmp_fields; |
| 694 |
foreach my $field ($record->field($tag)) { |
| 695 |
push @tmp_fields, $field; |
| 696 |
} |
| 697 |
$fields_hash->{$tag} = \@tmp_fields; |
| 698 |
} |
| 699 |
|
| 700 |
for (my $i = 0; $i < $tags_count; $i++) { |
| 701 |
my $r; |
| 702 |
for my $field_name ( @$field_list ) { |
| 703 |
next unless exists $yaml->{$field_name}; |
| 704 |
my @fields = split /\|/, $yaml->{$field_name}; |
| 705 |
for my $field ( @fields ) { |
| 706 |
my ( $f, $sf ) = split /\$/, $field; |
| 707 |
next unless $f and $sf; |
| 708 |
my $v = $fields_hash->{$f}[$i]->subfield( $sf ); |
| 709 |
$r->{$field_name} = $v if (defined $v); |
| 710 |
last if $yaml->{$field}; |
| 711 |
} |
| 712 |
} |
| 713 |
push @result, $r; |
| 714 |
} |
| 715 |
return \@result; |
| 716 |
} |