Lines 122-128
sub create_order_lines_from_file {
Link Here
|
122 |
}); |
122 |
}); |
123 |
|
123 |
|
124 |
while( my $import_record = $import_records->next ){ |
124 |
while( my $import_record = $import_records->next ){ |
125 |
my $result = add_biblios_from_import_record({ |
125 |
my $result = add_biblio_from_import_record({ |
126 |
import_batch_id => $import_batch_id, |
126 |
import_batch_id => $import_batch_id, |
127 |
import_record => $import_record, |
127 |
import_record => $import_record, |
128 |
matcher_id => $params->{matcher_id}, |
128 |
matcher_id => $params->{matcher_id}, |
Lines 333-341
sub _stage_file {
Link Here
|
333 |
}; |
333 |
}; |
334 |
} |
334 |
} |
335 |
|
335 |
|
|
|
336 |
=head3 _get_MarcFieldsToOrder_syspref_data |
337 |
|
338 |
my $marc_fields_to_order = _get_MarcFieldsToOrder_syspref_data( $marcrecord ); |
339 |
|
340 |
Fetches data from a marc record based on the mappings in the syspref MarcFieldsToOrder using the fields selected in $fields (array). |
341 |
|
342 |
=cut |
343 |
|
344 |
sub _get_MarcFieldsToOrder_syspref_data { |
345 |
my ( $record ) = @_; |
346 |
my $syspref = C4::Context->preference('MarcFieldsToOrder'); |
347 |
$syspref = "$syspref\n\n"; |
348 |
my $yaml = eval { |
349 |
YAML::XS::Load(Encode::encode_utf8($syspref)); |
350 |
}; |
351 |
if ( $@ ) { |
352 |
warn "Unable to parse $syspref syspref : $@"; |
353 |
return (); |
354 |
} |
355 |
my $r; |
356 |
for my $field_name ( keys %$yaml ) { |
357 |
next unless exists $yaml->{$field_name}; |
358 |
my @fields = split /\|/, $yaml->{$field_name}; |
359 |
for my $field ( @fields ) { |
360 |
my ( $f, $sf ) = split /\$/, $field; |
361 |
next unless $f and $sf; |
362 |
if ( my $v = $record->subfield( $f, $sf ) ) { |
363 |
$r->{$field_name} = $v; |
364 |
} |
365 |
last if $yaml->{$field}; |
366 |
} |
367 |
} |
368 |
return $r; |
369 |
} |
370 |
|
336 |
=head3 _get_MarcItemFieldsToOrder_syspref_data |
371 |
=head3 _get_MarcItemFieldsToOrder_syspref_data |
337 |
|
372 |
|
338 |
my $marc_item_fields_to_order = _get_MarcItemFieldsToOrder_syspref_data('MarcItemFieldsToOrder', $marcrecord, $fields); |
373 |
my $marc_item_fields_to_order = _get_MarcItemFieldsToOrder_syspref_data($marcrecord); |
339 |
|
374 |
|
340 |
Fetches data from a marc record based on the mappings in the syspref MarcItemFieldsToOrder using the fields selected in $fields (array). |
375 |
Fetches data from a marc record based on the mappings in the syspref MarcItemFieldsToOrder using the fields selected in $fields (array). |
341 |
|
376 |
|
Lines 358-365
sub _get_MarcItemFieldsToOrder_syspref_data {
Link Here
|
358 |
} |
393 |
} |
359 |
@tags_list = List::MoreUtils::uniq(@tags_list); |
394 |
@tags_list = List::MoreUtils::uniq(@tags_list); |
360 |
|
395 |
|
361 |
die "System preference MarcItemFieldsToOrder has not been filled in. Please set the mapping values to use this cron script." if scalar(@tags_list == 0); |
|
|
362 |
|
363 |
my $tags_count = _verify_number_of_fields(\@tags_list, $record); |
396 |
my $tags_count = _verify_number_of_fields(\@tags_list, $record); |
364 |
# Return if the number of these fields in the record is not the same. |
397 |
# Return if the number of these fields in the record is not the same. |
365 |
die "Invalid number of fields detected on field $tags_count->{key}, please check this file" if $tags_count->{error}; |
398 |
die "Invalid number of fields detected on field $tags_count->{key}, please check this file" if $tags_count->{error}; |
Lines 417-423
sub _verify_number_of_fields {
Link Here
|
417 |
return { error => 1, key => $key } if $tag_fields_count->{$key} != $tags_count; # All counts of various fields should be equal if they exist |
450 |
return { error => 1, key => $key } if $tag_fields_count->{$key} != $tags_count; # All counts of various fields should be equal if they exist |
418 |
} |
451 |
} |
419 |
} |
452 |
} |
420 |
|
|
|
421 |
return { error => 0, count => $tags_count }; |
453 |
return { error => 0, count => $tags_count }; |
422 |
} |
454 |
} |
423 |
|
455 |
|
Lines 539-549
sub add_items_from_import_record {
Link Here
|
539 |
my $marcrecord = $record_result->{marcrecord}; |
571 |
my $marcrecord = $record_result->{marcrecord}; |
540 |
|
572 |
|
541 |
if ( $agent eq 'cron' ) { |
573 |
if ( $agent eq 'cron' ) { |
542 |
my $marc_fields_to_order = _get_MarcFieldsToOrder_syspref_data( |
574 |
my $marc_fields_to_order = _get_MarcFieldsToOrder_syspref_data($marcrecord); |
543 |
'MarcFieldsToOrder', $marcrecord, |
|
|
544 |
[ 'price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2' ] |
545 |
); |
546 |
|
547 |
my $marc_item_fields_to_order = _get_MarcItemFieldsToOrder_syspref_data($marcrecord); |
575 |
my $marc_item_fields_to_order = _get_MarcItemFieldsToOrder_syspref_data($marcrecord); |
548 |
|
576 |
|
549 |
my $item_fields = _create_item_fields_from_syspref( |
577 |
my $item_fields = _create_item_fields_from_syspref( |
Lines 556-562
sub add_items_from_import_record {
Link Here
|
556 |
|
584 |
|
557 |
my $order_line_fields = parse_input_into_order_line_fields( |
585 |
my $order_line_fields = parse_input_into_order_line_fields( |
558 |
{ |
586 |
{ |
559 |
agent => $agent, |
|
|
560 |
biblionumber => $biblionumber, |
587 |
biblionumber => $biblionumber, |
561 |
budget_id => $budget_id, |
588 |
budget_id => $budget_id, |
562 |
basket_id => $basket_id, |
589 |
basket_id => $basket_id, |
Lines 579-585
sub add_items_from_import_record {
Link Here
|
579 |
if ( $agent eq 'client' ) { |
606 |
if ( $agent eq 'client' ) { |
580 |
my $order_line_fields = parse_input_into_order_line_fields( |
607 |
my $order_line_fields = parse_input_into_order_line_fields( |
581 |
{ |
608 |
{ |
582 |
agent => $agent, |
|
|
583 |
biblionumber => $biblionumber, |
609 |
biblionumber => $biblionumber, |
584 |
budget_id => $budget_id, |
610 |
budget_id => $budget_id, |
585 |
basket_id => $basket_id, |
611 |
basket_id => $basket_id, |
Lines 618-624
sub create_order_lines {
Link Here
|
618 |
my $order_line_details = $args->{order_line_details}; |
644 |
my $order_line_details = $args->{order_line_details}; |
619 |
|
645 |
|
620 |
foreach my $order_detail ( @{ $order_line_details } ) { |
646 |
foreach my $order_detail ( @{ $order_line_details } ) { |
621 |
my @itemnumbers = $order_detail->{itemnumbers}; |
647 |
my @itemnumbers = $order_detail->{itemnumbers} || (); |
622 |
delete($order_detail->{itemnumber}); |
648 |
delete($order_detail->{itemnumber}); |
623 |
my $order = Koha::Acquisition::Order->new( \%{ $order_detail } ); |
649 |
my $order = Koha::Acquisition::Order->new( \%{ $order_detail } ); |
624 |
$order->populate_with_prices_for_ordering(); |
650 |
$order->populate_with_prices_for_ordering(); |
Lines 816-822
sub import_biblios_list {
Link Here
|
816 |
push @list, \%cellrecord; |
842 |
push @list, \%cellrecord; |
817 |
|
843 |
|
818 |
# If MarcItemFieldsToOrder is not set, we use MarcFieldsToOrder to populate the order form. |
844 |
# If MarcItemFieldsToOrder is not set, we use MarcFieldsToOrder to populate the order form. |
819 |
if ( $alliteminfos || %$alliteminfos == -1 ) { |
845 |
if ( $alliteminfos == -1 || scalar(@$alliteminfos) == 0 ) { |
820 |
$cellrecord{price} = $price || ''; |
846 |
$cellrecord{price} = $price || ''; |
821 |
$cellrecord{replacementprice} = $replacementprice || ''; |
847 |
$cellrecord{replacementprice} = $replacementprice || ''; |
822 |
$cellrecord{quantity} = $quantity || ''; |
848 |
$cellrecord{quantity} = $quantity || ''; |
Lines 887-893
This function takes inputs from either the cronjob or UI and then parses that in
Link Here
|
887 |
|
913 |
|
888 |
my $order_line_fields = parse_input_into_order_line_fields( |
914 |
my $order_line_fields = parse_input_into_order_line_fields( |
889 |
{ |
915 |
{ |
890 |
agent => $agent, |
|
|
891 |
biblionumber => $biblionumber, |
916 |
biblionumber => $biblionumber, |
892 |
budget_id => $budget_id, |
917 |
budget_id => $budget_id, |
893 |
basket_id => $basket_id, |
918 |
basket_id => $basket_id, |
Lines 900-950
my $order_line_fields = parse_input_into_order_line_fields(
Link Here
|
900 |
sub parse_input_into_order_line_fields { |
925 |
sub parse_input_into_order_line_fields { |
901 |
my ($args) = @_; |
926 |
my ($args) = @_; |
902 |
|
927 |
|
903 |
my $agent = $args->{agent}; |
|
|
904 |
my $client = $agent eq 'client' ? 1 : 0; |
905 |
my $biblionumber = $args->{biblionumber}; |
928 |
my $biblionumber = $args->{biblionumber}; |
906 |
my $budget_id = $args->{budget_id}; |
929 |
my $budget_id = $args->{budget_id}; |
907 |
my $basket_id = $args->{basket_id}; |
930 |
my $basket_id = $args->{basket_id}; |
908 |
my $fields = $args->{fields}; |
931 |
my $fields = $args->{fields}; |
909 |
|
932 |
|
910 |
my $quantity = $fields->{quantity} || 1; |
933 |
my $quantity = $fields->{quantity} || 1; |
911 |
# my @homebranches = $client ? @{ $fields->{homebranches} } : ( ( $fields->{homebranch} ) x $quantity ); |
|
|
912 |
# my @holdingbranches = $client ? @{ $fields->{holdingbranches} } : ( ( $fields->{holdingbranch} ) x $quantity ); |
913 |
# my @itypes = $client ? @{ $fields->{itypes} } : ( ( $fields->{itype} ) x $quantity ); |
914 |
# my @nonpublic_notes = $client ? @{ $fields->{nonpublic_notes} } : ( ( $fields->{nonpublic_note} ) x $quantity ); |
915 |
# my @public_notes = $client ? @{ $fields->{public_notes} } : ( ( $fields->{public_note} ) x $quantity ); |
916 |
# my @locs = $client ? @{ $fields->{locs} } : ( ( $fields->{loc} ) x $quantity ); |
917 |
# my @ccodes = $client ? @{ $fields->{ccodes} } : ( ( $fields->{ccode} ) x $quantity ); |
918 |
# my @notforloans = $client ? @{ $fields->{notforloans} } : ( ( $fields->{notforloan} ) x $quantity ); |
919 |
# my @uris = $client ? @{ $fields->{uris} } : ( ( $fields->{uri} ) x $quantity ); |
920 |
# my @copynos = $client ? @{ $fields->{copynos} } : ( ( $fields->{copyno} ) x $quantity ); |
921 |
# my @itemprices = $client ? @{ $fields->{itemprices} } : ( ( $fields->{price} ) x $quantity ); |
922 |
# my @replacementprices = |
923 |
# $client ? @{ $fields->{replacementprices} } : ( ( $fields->{replacementprice} ) x $quantity ); |
924 |
# my @itemcallnumbers = $client ? @{ $fields->{itemcallnumbers} } : ( ( $fields->{itemcallnumber} ) x $quantity ); |
925 |
# my $c_quantity = $client ? $fields->{c_quantity} : $fields->{c_quantity}; |
926 |
# my $c_budget_id = $client ? $fields->{c_budget_id} : $fields->{c_budget_id}; |
927 |
# my $c_discount = $client ? $fields->{c_discount} : $fields->{c_discount}; |
928 |
# my $c_sort1 = $client ? $fields->{c_sort1} : $fields->{c_sort1}; |
929 |
# my $c_sort2 = $client ? $fields->{c_sort2} : $fields->{c_sort2}; |
930 |
# my $c_replacement_price = $client ? $fields->{c_replacement_price} : $fields->{c_replacement_price}; |
931 |
# my $c_price = $client ? $fields->{c_price} : $fields->{c_price}; |
932 |
|
933 |
# If using the cronjob, we want to default to the account budget if not mapped on the record |
934 |
# my $item_budget_id; |
935 |
# if ( !$client && ( $fields->{budget_code} || $fields->{c_budget_code} ) ) { |
936 |
# my $budget_code = $fields->{budget_code} || $fields->{c_budget_code}; |
937 |
# my $item_budget = GetBudgetByCode($budget_code); |
938 |
# if ($item_budget) { |
939 |
# $item_budget_id = $item_budget->{budget_id}; |
940 |
# } else { |
941 |
# $item_budget_id = $budget_id; |
942 |
# } |
943 |
# } else { |
944 |
# $item_budget_id = $budget_id; |
945 |
# } |
946 |
# my @budget_codes = $client ? @{ $fields->{budget_codes} } : ($item_budget_id); |
947 |
# my $loop_limit = $client ? scalar(@homebranches) : $quantity; |
948 |
|
934 |
|
949 |
my $order_line_fields = { |
935 |
my $order_line_fields = { |
950 |
biblionumber => $biblionumber, |
936 |
biblionumber => $biblionumber, |
Lines 1124-1130
sub _create_item_fields_from_syspref {
Link Here
|
1124 |
push @uris, $infoset->{uri}; |
1110 |
push @uris, $infoset->{uri}; |
1125 |
push @copynos, $infoset->{copyno}; |
1111 |
push @copynos, $infoset->{copyno}; |
1126 |
push @budget_codes, $item_budget_id; |
1112 |
push @budget_codes, $item_budget_id; |
1127 |
push @itemprices, $infoset->{itemprice}; |
1113 |
push @itemprices, $infoset->{price}; |
1128 |
push @replacementprices, $infoset->{replacementprice}; |
1114 |
push @replacementprices, $infoset->{replacementprice}; |
1129 |
push @itemcallnumbers, $infoset->{itemcallnumber}; |
1115 |
push @itemcallnumbers, $infoset->{itemcallnumber}; |
1130 |
} |
1116 |
} |