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