Lines 108-114
sub import_record_and_create_order_lines {
Link Here
|
108 |
skip => $result->{skip} |
108 |
skip => $result->{skip} |
109 |
} if $result->{skip}; |
109 |
} if $result->{skip}; |
110 |
|
110 |
|
111 |
my $order_line_details = add_items_from_import_record( |
111 |
my $itemnumbers = add_items_from_import_record( |
112 |
{ |
112 |
{ |
113 |
record_result => $result->{record_result}, |
113 |
record_result => $result->{record_result}, |
114 |
basket_id => $basket_id, |
114 |
basket_id => $basket_id, |
Lines 119-126
sub import_record_and_create_order_lines {
Link Here
|
119 |
} |
119 |
} |
120 |
); |
120 |
); |
121 |
|
121 |
|
122 |
my $order_lines = create_order_lines( { order_line_details => $order_line_details } ); |
|
|
123 |
|
124 |
return { |
122 |
return { |
125 |
duplicates_in_batch => 0, |
123 |
duplicates_in_batch => 0, |
126 |
skip => 0 |
124 |
skip => 0 |
Lines 136-142
sub import_record_and_create_order_lines {
Link Here
|
136 |
=cut |
134 |
=cut |
137 |
|
135 |
|
138 |
sub _get_syspref_mappings { |
136 |
sub _get_syspref_mappings { |
139 |
my ($record, $syspref_to_read) = @_; |
137 |
my ( $record, $syspref_to_read ) = @_; |
140 |
my $syspref = C4::Context->yaml_preference($syspref_to_read); |
138 |
my $syspref = C4::Context->yaml_preference($syspref_to_read); |
141 |
my @result; |
139 |
my @result; |
142 |
my @tags_list; |
140 |
my @tags_list; |
Lines 183-189
sub _get_syspref_mappings {
Link Here
|
183 |
push @result, $r; |
181 |
push @result, $r; |
184 |
} |
182 |
} |
185 |
} |
183 |
} |
186 |
return \@result if $syspref_to_read eq 'MarcItemFieldsToOrder'; |
184 |
return \@result if $syspref_to_read eq 'MarcItemFieldsToOrder'; |
187 |
return $result[0] if $syspref_to_read eq 'MarcFieldsToOrder'; |
185 |
return $result[0] if $syspref_to_read eq 'MarcFieldsToOrder'; |
188 |
} |
186 |
} |
189 |
|
187 |
|
Lines 370-376
sub add_items_from_import_record {
Link Here
|
370 |
} |
368 |
} |
371 |
); |
369 |
); |
372 |
|
370 |
|
373 |
my $order_line_details = create_items_and_generate_order_hash( |
371 |
my $itemnumbers = create_items_and_generate_order_hash( |
374 |
{ |
372 |
{ |
375 |
fields => $order_line_fields, |
373 |
fields => $order_line_fields, |
376 |
vendor => $vendor, |
374 |
vendor => $vendor, |
Lines 379-385
sub add_items_from_import_record {
Link Here
|
379 |
} |
377 |
} |
380 |
); |
378 |
); |
381 |
|
379 |
|
382 |
return $order_line_details; |
380 |
return $itemnumbers; |
383 |
} |
381 |
} |
384 |
|
382 |
|
385 |
if ( $agent eq 'client' ) { |
383 |
if ( $agent eq 'client' ) { |
Lines 407-441
sub add_items_from_import_record {
Link Here
|
407 |
} |
405 |
} |
408 |
} |
406 |
} |
409 |
|
407 |
|
410 |
=head3 create_order_lines |
|
|
411 |
|
412 |
my $order_lines = create_order_lines({ |
413 |
order_line_details => $order_line_details |
414 |
}); |
415 |
|
416 |
Creates order lines based on an array of order line details |
417 |
|
418 |
=cut |
419 |
|
420 |
sub create_order_lines { |
421 |
my ($args) = @_; |
422 |
|
423 |
my $order_line_details = $args->{order_line_details}; |
424 |
|
425 |
foreach my $order_detail ( @{$order_line_details} ) { |
426 |
my @itemnumbers = $order_detail->{itemnumbers} || (); |
427 |
delete( $order_detail->{itemnumbers} ); |
428 |
my $order = Koha::Acquisition::Order->new( \%{$order_detail} ); |
429 |
$order->populate_with_prices_for_ordering(); |
430 |
$order->populate_with_prices_for_receiving(); |
431 |
$order->store; |
432 |
foreach my $itemnumber (@itemnumbers) { |
433 |
$order->add_item($itemnumber); |
434 |
} |
435 |
} |
436 |
return; |
437 |
} |
438 |
|
439 |
=head3 import_batches_list |
408 |
=head3 import_batches_list |
440 |
|
409 |
|
441 |
Fetches import batches matching the batch to be added to the basket and returns these to the template |
410 |
Fetches import batches matching the batch to be added to the basket and returns these to the template |
Lines 563-575
sub import_biblios_list {
Link Here
|
563 |
|
532 |
|
564 |
my $infos = _get_syspref_mappings( $marcrecord, 'MarcFieldsToOrder' ); |
533 |
my $infos = _get_syspref_mappings( $marcrecord, 'MarcFieldsToOrder' ); |
565 |
|
534 |
|
566 |
my $price = $infos->{price} || undef; |
535 |
my $price = $infos->{price} || undef; |
567 |
my $replacementprice = $infos->{replacementprice} || undef; |
536 |
my $replacementprice = $infos->{replacementprice} || undef; |
568 |
my $quantity = $infos->{quantity} || undef; |
537 |
my $quantity = $infos->{quantity} || undef; |
569 |
my $budget_code = $infos->{budget_code} || undef; |
538 |
my $budget_code = $infos->{budget_code} || undef; |
570 |
my $discount = $infos->{discount} || undef; |
539 |
my $discount = $infos->{discount} || undef; |
571 |
my $sort1 = $infos->{sort1} || undef; |
540 |
my $sort1 = $infos->{sort1} || undef; |
572 |
my $sort2 = $infos->{sort2} || undef; |
541 |
my $sort2 = $infos->{sort2} || undef; |
573 |
my $budget_id; |
542 |
my $budget_id; |
574 |
|
543 |
|
575 |
if ($budget_code) { |
544 |
if ($budget_code) { |
Lines 582-591
sub import_biblios_list {
Link Here
|
582 |
# Items |
551 |
# Items |
583 |
my @itemlist = (); |
552 |
my @itemlist = (); |
584 |
my $all_items_quantity = 0; |
553 |
my $all_items_quantity = 0; |
585 |
my $alliteminfos = _get_syspref_mappings( $marcrecord, 'MarcItemFieldsToOrder' ); |
554 |
my $alliteminfos = _get_syspref_mappings( $marcrecord, 'MarcItemFieldsToOrder' ); |
586 |
|
555 |
|
587 |
if ( $alliteminfos != -1 ) { |
556 |
if ( $alliteminfos != -1 ) { |
588 |
foreach my $iteminfos (@$alliteminfos) { |
557 |
foreach my $iteminfos (@$alliteminfos) { |
|
|
558 |
|
589 |
# Quantity is required, default to one if not supplied |
559 |
# Quantity is required, default to one if not supplied |
590 |
my $quantity = delete $iteminfos->{quantity} || 1; |
560 |
my $quantity = delete $iteminfos->{quantity} || 1; |
591 |
|
561 |
|
Lines 787-793
sub parse_input_into_order_line_fields {
Link Here
|
787 |
marcrecord => $marcrecord, |
757 |
marcrecord => $marcrecord, |
788 |
}; |
758 |
}; |
789 |
|
759 |
|
790 |
if($client) { |
760 |
if ($client) { |
791 |
$order_line_fields->{tags} = $fields->{tags}; |
761 |
$order_line_fields->{tags} = $fields->{tags}; |
792 |
$order_line_fields->{subfields} = $fields->{subfields}; |
762 |
$order_line_fields->{subfields} = $fields->{subfields}; |
793 |
$order_line_fields->{field_values} = $fields->{field_values}; |
763 |
$order_line_fields->{field_values} = $fields->{field_values}; |
Lines 825-832
sub create_items_and_generate_order_hash {
Link Here
|
825 |
my $budget_id = $fields->{budget_id}; |
795 |
my $budget_id = $fields->{budget_id}; |
826 |
my $vendor = $args->{vendor}; |
796 |
my $vendor = $args->{vendor}; |
827 |
my $active_currency = $args->{active_currency}; |
797 |
my $active_currency = $args->{active_currency}; |
828 |
my @order_line_details; |
798 |
my $itemcreation = 0; |
829 |
my $itemcreation = 0; |
|
|
830 |
my @itemnumbers; |
799 |
my @itemnumbers; |
831 |
|
800 |
|
832 |
for ( my $i = 0 ; $i < $loop_limit ; $i++ ) { |
801 |
for ( my $i = 0 ; $i < $loop_limit ; $i++ ) { |
Lines 856-866
sub create_items_and_generate_order_hash {
Link Here
|
856 |
} |
825 |
} |
857 |
|
826 |
|
858 |
if ( $itemcreation == 1 ) { |
827 |
if ( $itemcreation == 1 ) { |
|
|
828 |
|
859 |
# Group orderlines from MarcItemFieldsToOrder |
829 |
# Group orderlines from MarcItemFieldsToOrder |
860 |
my $budget_hash; |
830 |
my $budget_hash; |
861 |
my @budget_ids = @{ $fields->{budget_code} }; |
831 |
my @budget_ids = @{ $fields->{budget_code} }; |
862 |
for ( my $i = 0 ; $i < $loop_limit ; $i++ ) { |
832 |
for ( my $i = 0 ; $i < $loop_limit ; $i++ ) { |
863 |
$budget_ids[$i] = $budget_id if !$budget_ids[$i]; # Use default budget if no budget provided |
833 |
$budget_ids[$i] = $budget_id if !$budget_ids[$i]; # Use default budget if no budget provided |
864 |
$budget_hash->{ $budget_ids[$i] }->{quantity} += 1; |
834 |
$budget_hash->{ $budget_ids[$i] }->{quantity} += 1; |
865 |
$budget_hash->{ $budget_ids[$i] }->{price} = @{ $fields->{price} }[$i]; |
835 |
$budget_hash->{ $budget_ids[$i] }->{price} = @{ $fields->{price} }[$i]; |
866 |
$budget_hash->{ $budget_ids[$i] }->{replacementprice} = |
836 |
$budget_hash->{ $budget_ids[$i] }->{replacementprice} = |
Lines 911-916
sub create_items_and_generate_order_hash {
Link Here
|
911 |
} |
881 |
} |
912 |
} |
882 |
} |
913 |
} else { |
883 |
} else { |
|
|
884 |
|
914 |
# Add an orderline for each MARC record |
885 |
# Add an orderline for each MARC record |
915 |
# Get quantity in the MARC record (1 if none) |
886 |
# Get quantity in the MARC record (1 if none) |
916 |
my $quantity = GetMarcQuantity( $fields->{marcrecord}, C4::Context->preference('marcflavour') ) || 1; |
887 |
my $quantity = GetMarcQuantity( $fields->{marcrecord}, C4::Context->preference('marcflavour') ) || 1; |
Lines 930-937
sub create_items_and_generate_order_hash {
Link Here
|
930 |
); |
901 |
); |
931 |
|
902 |
|
932 |
# Get the price if there is one. |
903 |
# Get the price if there is one. |
933 |
if ($fields->{c_price}) { |
904 |
if ( $fields->{c_price} ) { |
934 |
$fields->{c_price} = _format_price_to_CurrencyFormat_syspref($fields->{c_price}); |
905 |
$fields->{c_price} = _format_price_to_CurrencyFormat_syspref( $fields->{c_price} ); |
935 |
$fields->{c_price} = Koha::Number::Price->new( $fields->{c_price} )->unformat; |
906 |
$fields->{c_price} = Koha::Number::Price->new( $fields->{c_price} )->unformat; |
936 |
$orderinfo{tax_rate_on_ordering} = $vendor->tax_rate; |
907 |
$orderinfo{tax_rate_on_ordering} = $vendor->tax_rate; |
937 |
$orderinfo{tax_rate_on_receiving} = $vendor->tax_rate; |
908 |
$orderinfo{tax_rate_on_receiving} = $vendor->tax_rate; |
Lines 954-960
sub create_items_and_generate_order_hash {
Link Here
|
954 |
$order->populate_with_prices_for_receiving(); |
925 |
$order->populate_with_prices_for_receiving(); |
955 |
$order->store; |
926 |
$order->store; |
956 |
|
927 |
|
957 |
my $basket = Koha::Acquisition::Baskets->find( $basket_id ); |
928 |
my $basket = Koha::Acquisition::Baskets->find($basket_id); |
958 |
if ( $basket->effective_create_items eq 'ordering' && !$basket->is_standing ) { |
929 |
if ( $basket->effective_create_items eq 'ordering' && !$basket->is_standing ) { |
959 |
my @tags = @{ $fields->{tags} }; |
930 |
my @tags = @{ $fields->{tags} }; |
960 |
my @subfields = @{ $fields->{subfields} }; |
931 |
my @subfields = @{ $fields->{subfields} }; |
Lines 963-975
sub create_items_and_generate_order_hash {
Link Here
|
963 |
my $xml = TransformHtmlToXml( \@tags, \@subfields, \@field_values ); |
934 |
my $xml = TransformHtmlToXml( \@tags, \@subfields, \@field_values ); |
964 |
my $record = MARC::Record::new_from_xml( $xml, 'UTF-8' ); |
935 |
my $record = MARC::Record::new_from_xml( $xml, 'UTF-8' ); |
965 |
for ( my $qtyloop = 1 ; $qtyloop <= $fields->{c_quantity} ; $qtyloop++ ) { |
936 |
for ( my $qtyloop = 1 ; $qtyloop <= $fields->{c_quantity} ; $qtyloop++ ) { |
966 |
my ( $biblionumber, undef, $itemnumber ) = AddItemFromMarc( $fields->{marcrecord}, $fields->{biblionumber} ); |
937 |
my ( $biblionumber, undef, $itemnumber ) = |
|
|
938 |
AddItemFromMarc( $fields->{marcrecord}, $fields->{biblionumber} ); |
967 |
$order->add_item($itemnumber); |
939 |
$order->add_item($itemnumber); |
968 |
} |
940 |
} |
969 |
} |
941 |
} |
970 |
} |
942 |
} |
971 |
|
943 |
|
972 |
return \@order_line_details; |
944 |
return \@itemnumbers; |
973 |
} |
945 |
} |
974 |
|
946 |
|
975 |
=head3 _format_price_to_CurrencyFormat_syspref |
947 |
=head3 _format_price_to_CurrencyFormat_syspref |