Lines 35-40
use C4::ImportBatch qw(
Link Here
|
35 |
SetImportBatchNoMatchAction |
35 |
SetImportBatchNoMatchAction |
36 |
SetImportBatchItemAction |
36 |
SetImportBatchItemAction |
37 |
SetImportBatchStatus |
37 |
SetImportBatchStatus |
|
|
38 |
GetImportBatchOverlayAction |
39 |
GetImportBatchNoMatchAction |
40 |
GetImportBatchItemAction |
41 |
GetImportBatch |
38 |
); |
42 |
); |
39 |
use C4::Search qw( FindDuplicate ); |
43 |
use C4::Search qw( FindDuplicate ); |
40 |
use C4::Acquisition qw( NewBasket ); |
44 |
use C4::Acquisition qw( NewBasket ); |
Lines 329-343
sub _stage_file {
Link Here
|
329 |
|
333 |
|
330 |
=head3 _get_MarcFieldsToOrder_syspref_data |
334 |
=head3 _get_MarcFieldsToOrder_syspref_data |
331 |
|
335 |
|
332 |
my $marc_fields_to_order = _get_MarcFieldsToOrder_syspref_data('MarcFieldsToOrder', $marcrecord, $fields); |
336 |
my $marc_fields_to_order = _get_MarcFieldsToOrder_syspref_data( $marcrecord ); |
333 |
|
337 |
|
334 |
Fetches data from a marc record based on the mappings in the syspref MarcFieldsToOrder using the fields selected in $fields (array). |
338 |
Fetches data from a marc record based on the mappings in the syspref MarcFieldsToOrder using the fields selected in $fields (array). |
335 |
|
339 |
|
336 |
=cut |
340 |
=cut |
337 |
|
341 |
|
338 |
sub _get_MarcFieldsToOrder_syspref_data { |
342 |
sub _get_MarcFieldsToOrder_syspref_data { |
339 |
my ($syspref_name, $record, $field_list) = @_; |
343 |
my ( $record ) = @_; |
340 |
my $syspref = C4::Context->preference($syspref_name); |
344 |
my $syspref = C4::Context->preference('MarcFieldsToOrder'); |
341 |
$syspref = "$syspref\n\n"; |
345 |
$syspref = "$syspref\n\n"; |
342 |
my $yaml = eval { |
346 |
my $yaml = eval { |
343 |
YAML::XS::Load(Encode::encode_utf8($syspref)); |
347 |
YAML::XS::Load(Encode::encode_utf8($syspref)); |
Lines 347-353
sub _get_MarcFieldsToOrder_syspref_data {
Link Here
|
347 |
return (); |
351 |
return (); |
348 |
} |
352 |
} |
349 |
my $r; |
353 |
my $r; |
350 |
for my $field_name ( @$field_list ) { |
354 |
for my $field_name ( keys %$yaml ) { |
351 |
next unless exists $yaml->{$field_name}; |
355 |
next unless exists $yaml->{$field_name}; |
352 |
my @fields = split /\|/, $yaml->{$field_name}; |
356 |
my @fields = split /\|/, $yaml->{$field_name}; |
353 |
for my $field ( @fields ) { |
357 |
for my $field ( @fields ) { |
Lines 364-378
sub _get_MarcFieldsToOrder_syspref_data {
Link Here
|
364 |
|
368 |
|
365 |
=head3 _get_MarcItemFieldsToOrder_syspref_data |
369 |
=head3 _get_MarcItemFieldsToOrder_syspref_data |
366 |
|
370 |
|
367 |
my $marc_item_fields_to_order = _get_MarcItemFieldsToOrder_syspref_data('MarcItemFieldsToOrder', $marcrecord, $fields); |
371 |
my $marc_item_fields_to_order = _get_MarcItemFieldsToOrder_syspref_data( $marcrecord ); |
368 |
|
372 |
|
369 |
Fetches data from a marc record based on the mappings in the syspref MarcItemFieldsToOrder using the fields selected in $fields (array). |
373 |
Fetches data from a marc record based on the mappings in the syspref MarcItemFieldsToOrder using the fields selected in $fields (array). |
370 |
|
374 |
|
371 |
=cut |
375 |
=cut |
372 |
|
376 |
|
373 |
sub _get_MarcItemFieldsToOrder_syspref_data { |
377 |
sub _get_MarcItemFieldsToOrder_syspref_data { |
374 |
my ($syspref_name, $record, $field_list) = @_; |
378 |
my ( $record ) = @_; |
375 |
my $syspref = C4::Context->preference($syspref_name); |
379 |
my $syspref = C4::Context->preference('MarcItemFieldsToOrder'); |
376 |
$syspref = "$syspref\n\n"; |
380 |
$syspref = "$syspref\n\n"; |
377 |
my $yaml = eval { |
381 |
my $yaml = eval { |
378 |
YAML::XS::Load(Encode::encode_utf8($syspref)); |
382 |
YAML::XS::Load(Encode::encode_utf8($syspref)); |
Lines 385-391
sub _get_MarcItemFieldsToOrder_syspref_data {
Link Here
|
385 |
my @tags_list; |
389 |
my @tags_list; |
386 |
|
390 |
|
387 |
# Check tags in syspref definition |
391 |
# Check tags in syspref definition |
388 |
for my $field_name ( @$field_list ) { |
392 |
for my $field_name ( keys %$yaml ) { |
389 |
next unless exists $yaml->{$field_name}; |
393 |
next unless exists $yaml->{$field_name}; |
390 |
my @fields = split /\|/, $yaml->{$field_name}; |
394 |
my @fields = split /\|/, $yaml->{$field_name}; |
391 |
for my $field ( @fields ) { |
395 |
for my $field ( @fields ) { |
Lines 413-419
sub _get_MarcItemFieldsToOrder_syspref_data {
Link Here
|
413 |
if($tags_count->{count}){ |
417 |
if($tags_count->{count}){ |
414 |
for (my $i = 0; $i < $tags_count->{count}; $i++) { |
418 |
for (my $i = 0; $i < $tags_count->{count}; $i++) { |
415 |
my $r; |
419 |
my $r; |
416 |
for my $field_name ( @$field_list ) { |
420 |
for my $field_name ( keys %$yaml ) { |
417 |
next unless exists $yaml->{$field_name}; |
421 |
next unless exists $yaml->{$field_name}; |
418 |
my @fields = split /\|/, $yaml->{$field_name}; |
422 |
my @fields = split /\|/, $yaml->{$field_name}; |
419 |
for my $field ( @fields ) { |
423 |
for my $field ( @fields ) { |
Lines 576-582
sub add_items_from_import_record {
Link Here
|
576 |
my @order_line_details; |
580 |
my @order_line_details; |
577 |
|
581 |
|
578 |
if($agent eq 'cron') { |
582 |
if($agent eq 'cron') { |
579 |
my $marc_fields_to_order = _get_MarcFieldsToOrder_syspref_data('MarcFieldsToOrder', $marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2']); |
583 |
my $marc_fields_to_order = _get_MarcFieldsToOrder_syspref_data( $marcrecord ); |
580 |
my $quantity = $marc_fields_to_order->{quantity}; |
584 |
my $quantity = $marc_fields_to_order->{quantity}; |
581 |
my $budget_code = $marc_fields_to_order->{budget_code} || $budget_id; # Use fallback from ordering profile if not mapped |
585 |
my $budget_code = $marc_fields_to_order->{budget_code} || $budget_id; # Use fallback from ordering profile if not mapped |
582 |
my $price = $marc_fields_to_order->{price}; |
586 |
my $price = $marc_fields_to_order->{price}; |
Lines 593-599
sub add_items_from_import_record {
Link Here
|
593 |
} |
597 |
} |
594 |
} |
598 |
} |
595 |
|
599 |
|
596 |
my $marc_item_fields_to_order = _get_MarcItemFieldsToOrder_syspref_data('MarcItemFieldsToOrder', $marcrecord, ['homebranch', 'holdingbranch', 'itype', 'nonpublic_note', 'public_note', 'loc', 'ccode', 'notforloan', 'uri', 'copyno', 'price', 'replacementprice', 'itemcallnumber', 'quantity', 'budget_code']); |
600 |
my $marc_item_fields_to_order = _get_MarcItemFieldsToOrder_syspref_data( $marcrecord ); |
597 |
my $item_homebranch = $marc_item_fields_to_order->{homebranch}; |
601 |
my $item_homebranch = $marc_item_fields_to_order->{homebranch}; |
598 |
my $item_holdingbranch = $marc_item_fields_to_order->{holdingbranch}; |
602 |
my $item_holdingbranch = $marc_item_fields_to_order->{holdingbranch}; |
599 |
my $item_itype = $marc_item_fields_to_order->{itype}; |
603 |
my $item_itype = $marc_item_fields_to_order->{itype}; |
Lines 1020-1029
sub import_biblios_list {
Link Here
|
1020 |
); |
1024 |
); |
1021 |
my $marcrecord = $import_record->get_marc_record || die "couldn't translate marc information"; |
1025 |
my $marcrecord = $import_record->get_marc_record || die "couldn't translate marc information"; |
1022 |
|
1026 |
|
1023 |
my $infos = _get_MarcFieldsToOrder_syspref_data( |
1027 |
my $infos = _get_MarcFieldsToOrder_syspref_data( $marcrecord ); |
1024 |
'MarcFieldsToOrder', $marcrecord, |
|
|
1025 |
[ 'price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2', 'replacementprice' ] |
1026 |
); |
1027 |
my $price = $infos->{price}; |
1028 |
my $price = $infos->{price}; |
1028 |
my $replacementprice = $infos->{replacementprice}; |
1029 |
my $replacementprice = $infos->{replacementprice}; |
1029 |
my $quantity = $infos->{quantity}; |
1030 |
my $quantity = $infos->{quantity}; |
Lines 1043-1105
sub import_biblios_list {
Link Here
|
1043 |
# Items |
1044 |
# Items |
1044 |
my @itemlist = (); |
1045 |
my @itemlist = (); |
1045 |
my $all_items_quantity = 0; |
1046 |
my $all_items_quantity = 0; |
1046 |
my $alliteminfos = _get_MarcItemFieldsToOrder_syspref_data( |
1047 |
my $alliteminfos = _get_MarcItemFieldsToOrder_syspref_data( $marcrecord ); |
1047 |
'MarcItemFieldsToOrder', |
|
|
1048 |
$marcrecord, |
1049 |
[ |
1050 |
'homebranch', 'holdingbranch', 'itype', 'nonpublic_note', 'public_note', 'loc', 'ccode', 'notforloan', |
1051 |
'uri', 'copyno', 'price', 'replacementprice', 'itemcallnumber', 'quantity', 'budget_code' |
1052 |
] |
1053 |
); |
1054 |
if ( !$alliteminfos || %$alliteminfos != -1 ) { |
1048 |
if ( !$alliteminfos || %$alliteminfos != -1 ) { |
1055 |
my $item_homebranch = $alliteminfos->{homebranch}; |
1049 |
# Quantity is required, default to one if not supplied |
1056 |
my $item_holdingbranch = $alliteminfos->{holdingbranch}; |
1050 |
my $quantity = delete $alliteminfos->{quantity} || 1; |
1057 |
my $item_itype = $alliteminfos->{itype}; |
1051 |
|
1058 |
my $item_nonpublic_note = $alliteminfos->{nonpublic_note}; |
1052 |
# Handle incorrectly named original parameters for MarcItemFieldsToOrder |
1059 |
my $item_public_note = $alliteminfos->{public_note}; |
1053 |
$alliteminfos->{location} = delete $alliteminfos->{loc} if $alliteminfos->{loc}; |
1060 |
my $item_loc = $alliteminfos->{loc}; |
1054 |
$alliteminfos->{copynumber} = delete $alliteminfos->{copyno} if $alliteminfos->{copyno}; |
1061 |
my $item_ccode = $alliteminfos->{ccode}; |
1055 |
$alliteminfos->{itemprice} = delete $alliteminfos->{price} if $alliteminfos->{price}; |
1062 |
my $item_notforloan = $alliteminfos->{notforloan}; |
1056 |
|
1063 |
my $item_uri = $alliteminfos->{uri}; |
1057 |
# Convert budget code to a budget id |
1064 |
my $item_copyno = $alliteminfos->{copyno}; |
1058 |
my $item_budget_code = delete $alliteminfos->{budget_code}; |
1065 |
my $item_quantity = $alliteminfos->{quantity} || 1; |
1059 |
if ($item_budget_code) { |
1066 |
my $item_budget_code = $alliteminfos->{budget_code}; |
1060 |
my $item_budget = GetBudgetByCode($item_budget_code); |
1067 |
my $item_budget_id; |
1061 |
$alliteminfos->{budget_id} = $item_budget->{budget_id} || $budget_id; |
1068 |
|
|
|
1069 |
if ( $alliteminfos->{budget_code} ) { |
1070 |
my $item_budget = GetBudgetByCode( $alliteminfos->{budget_code} ); |
1071 |
if ($item_budget) { |
1072 |
$item_budget_id = $item_budget->{budget_id}; |
1073 |
} |
1074 |
} |
1062 |
} |
1075 |
my $item_price = $alliteminfos->{price}; |
1063 |
|
1076 |
my $item_replacement_price = $alliteminfos->{replacementprice}; |
1064 |
# Clone the item data for the needed quantity |
1077 |
my $item_callnumber = $alliteminfos->{itemcallnumber}; |
1065 |
# Add the incremented item id for each item in that quantity |
1078 |
|
1066 |
for ( my $i = 0 ; $i < $quantity ; $i++ ) { |
1079 |
for ( my $i = 0 ; $i < $item_quantity ; $i++ ) { |
1067 |
my $itemrecord = {%$alliteminfos}; |
1080 |
|
1068 |
$itemrecord->{item_id} = $item_id++; |
1081 |
my %itemrecord = ( |
|
|
1082 |
'item_id' => $item_id++, |
1083 |
'biblio_count' => $biblio_count, |
1084 |
'homebranch' => $item_homebranch, |
1085 |
'holdingbranch' => $item_holdingbranch, |
1086 |
'itype' => $item_itype, |
1087 |
'nonpublic_note' => $item_nonpublic_note, |
1088 |
'public_note' => $item_public_note, |
1089 |
'loc' => $item_loc, |
1090 |
'ccode' => $item_ccode, |
1091 |
'notforloan' => $item_notforloan, |
1092 |
'uri' => $item_uri, |
1093 |
'copyno' => $item_copyno, |
1094 |
'quantity' => $item_quantity, |
1095 |
'budget_id' => $item_budget_id || $budget_id, |
1096 |
'itemprice' => $item_price || $price, |
1097 |
'replacementprice' => $item_replacement_price || $replacementprice, |
1098 |
'itemcallnumber' => $item_callnumber, |
1099 |
); |
1100 |
$all_items_quantity++; |
1069 |
$all_items_quantity++; |
1101 |
push @itemlist, \%itemrecord; |
1070 |
push @itemlist, $itemrecord; |
1102 |
|
|
|
1103 |
} |
1071 |
} |
1104 |
|
1072 |
|
1105 |
$cellrecord{'iteminfos'} = \@itemlist; |
1073 |
$cellrecord{'iteminfos'} = \@itemlist; |
Lines 1109-1115
sub import_biblios_list {
Link Here
|
1109 |
push @list, \%cellrecord; |
1077 |
push @list, \%cellrecord; |
1110 |
|
1078 |
|
1111 |
# If MarcItemFieldsToOrder is not set, we use MarcFieldsToOrder to populate the order form. |
1079 |
# If MarcItemFieldsToOrder is not set, we use MarcFieldsToOrder to populate the order form. |
1112 |
if ( $alliteminfos || %$alliteminfos == -1 ) { |
1080 |
if ( !$alliteminfos || %$alliteminfos == -1 ) { |
1113 |
$cellrecord{price} = $price || ''; |
1081 |
$cellrecord{price} = $price || ''; |
1114 |
$cellrecord{replacementprice} = $replacementprice || ''; |
1082 |
$cellrecord{replacementprice} = $replacementprice || ''; |
1115 |
$cellrecord{quantity} = $quantity || ''; |
1083 |
$cellrecord{quantity} = $quantity || ''; |
1116 |
- |
|
|