Lines 366-371
sub add_items_from_import_record {
Link Here
|
366 |
budget_id => $budget_id, |
366 |
budget_id => $budget_id, |
367 |
basket_id => $basket_id, |
367 |
basket_id => $basket_id, |
368 |
fields => $item_fields, |
368 |
fields => $item_fields, |
|
|
369 |
marcrecord => $marcrecord, |
369 |
} |
370 |
} |
370 |
); |
371 |
); |
371 |
|
372 |
|
Lines 389-394
sub add_items_from_import_record {
Link Here
|
389 |
budget_id => $budget_id, |
390 |
budget_id => $budget_id, |
390 |
basket_id => $basket_id, |
391 |
basket_id => $basket_id, |
391 |
fields => $client_item_fields, |
392 |
fields => $client_item_fields, |
|
|
393 |
marcrecord => $marcrecord, |
392 |
} |
394 |
} |
393 |
); |
395 |
); |
394 |
|
396 |
|
Lines 403-410
sub add_items_from_import_record {
Link Here
|
403 |
|
405 |
|
404 |
return $order_line_details; |
406 |
return $order_line_details; |
405 |
} |
407 |
} |
406 |
|
|
|
407 |
# return \@order_line_details; |
408 |
} |
408 |
} |
409 |
|
409 |
|
410 |
=head3 create_order_lines |
410 |
=head3 create_order_lines |
Lines 694-699
my $order_line_fields = parse_input_into_order_line_fields(
Link Here
|
694 |
budget_id => $budget_id, |
694 |
budget_id => $budget_id, |
695 |
basket_id => $basket_id, |
695 |
basket_id => $basket_id, |
696 |
fields => $item_fields, |
696 |
fields => $item_fields, |
|
|
697 |
marcrecord => $marcrecord, |
697 |
} |
698 |
} |
698 |
); |
699 |
); |
699 |
|
700 |
|
Lines 709-714
sub parse_input_into_order_line_fields {
Link Here
|
709 |
my $budget_id = $args->{budget_id}; |
710 |
my $budget_id = $args->{budget_id}; |
710 |
my $basket_id = $args->{basket_id}; |
711 |
my $basket_id = $args->{basket_id}; |
711 |
my $fields = $args->{fields}; |
712 |
my $fields = $args->{fields}; |
|
|
713 |
my $marcrecord = $args->{marcrecord}; |
712 |
|
714 |
|
713 |
my $quantity = $fields->{quantity} || 1; |
715 |
my $quantity = $fields->{quantity} || 1; |
714 |
my @homebranches = $client ? @{ $fields->{homebranches} } : ( ( $fields->{homebranch} ) x $quantity ); |
716 |
my @homebranches = $client ? @{ $fields->{homebranches} } : ( ( $fields->{homebranch} ) x $quantity ); |
Lines 724-737
sub parse_input_into_order_line_fields {
Link Here
|
724 |
my @itemprices = $client ? @{ $fields->{itemprices} } : ( ( $fields->{price} ) x $quantity ); |
726 |
my @itemprices = $client ? @{ $fields->{itemprices} } : ( ( $fields->{price} ) x $quantity ); |
725 |
my @replacementprices = |
727 |
my @replacementprices = |
726 |
$client ? @{ $fields->{replacementprices} } : ( ( $fields->{replacementprice} ) x $quantity ); |
728 |
$client ? @{ $fields->{replacementprices} } : ( ( $fields->{replacementprice} ) x $quantity ); |
727 |
my @itemcallnumbers = $client ? @{ $fields->{itemcallnumbers} } : ( ( $fields->{itemcallnumber} ) x $quantity ); |
729 |
my @itemcallnumbers = $client ? @{ $fields->{itemcallnumbers} } : ( ( $fields->{itemcallnumber} ) x $quantity ); |
728 |
my $c_quantity = $client ? $fields->{c_quantity} : $fields->{c_quantity}; |
730 |
my @coded_location_qualifiers = |
729 |
my $c_budget_id = $client ? $fields->{c_budget_id} : $fields->{c_budget_id}; |
731 |
$client ? @{ $fields->{coded_location_qualifiers} } : ( ( $fields->{coded_location_qualifier} ) x $quantity ); |
730 |
my $c_discount = $client ? $fields->{c_discount} : $fields->{c_discount}; |
732 |
my @barcodes = $client ? @{ $fields->{barcodes} } : ( ( $fields->{barcode} ) x $quantity ); |
731 |
my $c_sort1 = $client ? $fields->{c_sort1} : $fields->{c_sort1}; |
733 |
my @enumchrons = $client ? @{ $fields->{enumchrons} } : ( ( $fields->{enumchron} ) x $quantity ); |
732 |
my $c_sort2 = $client ? $fields->{c_sort2} : $fields->{c_sort2}; |
734 |
my $c_quantity = $client ? $fields->{c_quantity} : $fields->{c_quantity}; |
733 |
my $c_replacement_price = $client ? $fields->{c_replacement_price} : $fields->{c_replacement_price}; |
735 |
my $c_budget_id = $client ? $fields->{c_budget_id} : $fields->{c_budget_id}; |
734 |
my $c_price = $client ? $fields->{c_price} : $fields->{c_price}; |
736 |
my $c_discount = $client ? $fields->{c_discount} : $fields->{c_discount}; |
|
|
737 |
my $c_sort1 = $client ? $fields->{c_sort1} : $fields->{c_sort1}; |
738 |
my $c_sort2 = $client ? $fields->{c_sort2} : $fields->{c_sort2}; |
739 |
my $c_replacement_price = $client ? $fields->{c_replacement_price} : $fields->{c_replacement_price}; |
740 |
my $c_price = $client ? $fields->{c_price} : $fields->{c_price}; |
735 |
|
741 |
|
736 |
# If using the cronjob, we want to default to the account budget if not mapped on the record |
742 |
# If using the cronjob, we want to default to the account budget if not mapped on the record |
737 |
my $item_budget_id; |
743 |
my $item_budget_id; |
Lines 750-782
sub parse_input_into_order_line_fields {
Link Here
|
750 |
my $loop_limit = $client ? scalar(@homebranches) : $quantity; |
756 |
my $loop_limit = $client ? scalar(@homebranches) : $quantity; |
751 |
|
757 |
|
752 |
my $order_line_fields = { |
758 |
my $order_line_fields = { |
753 |
biblionumber => $biblionumber, |
759 |
biblionumber => $biblionumber, |
754 |
homebranch => \@homebranches, |
760 |
homebranch => \@homebranches, |
755 |
holdingbranch => \@holdingbranches, |
761 |
holdingbranch => \@holdingbranches, |
756 |
itemnotes_nonpublic => \@nonpublic_notes, |
762 |
itemnotes_nonpublic => \@nonpublic_notes, |
757 |
itemnotes => \@public_notes, |
763 |
itemnotes => \@public_notes, |
758 |
location => \@locs, |
764 |
location => \@locs, |
759 |
ccode => \@ccodes, |
765 |
ccode => \@ccodes, |
760 |
itype => \@itypes, |
766 |
itype => \@itypes, |
761 |
notforloan => \@notforloans, |
767 |
notforloan => \@notforloans, |
762 |
uri => \@uris, |
768 |
uri => \@uris, |
763 |
copynumber => \@copynos, |
769 |
copynumber => \@copynos, |
764 |
price => \@itemprices, |
770 |
price => \@itemprices, |
765 |
replacementprice => \@replacementprices, |
771 |
replacementprice => \@replacementprices, |
766 |
itemcallnumber => \@itemcallnumbers, |
772 |
itemcallnumber => \@itemcallnumbers, |
767 |
budget_code => \@budget_codes, |
773 |
coded_location_qualifier => \@coded_location_qualifiers, |
768 |
loop_limit => $loop_limit, |
774 |
barcode => \@barcodes, |
769 |
basket_id => $basket_id, |
775 |
enumchron => \@enumchrons, |
770 |
budget_id => $budget_id, |
776 |
budget_code => \@budget_codes, |
771 |
c_quantity => $c_quantity, |
777 |
loop_limit => $loop_limit, |
772 |
c_budget_id => $c_budget_id, |
778 |
basket_id => $basket_id, |
773 |
c_discount => $c_discount, |
779 |
budget_id => $budget_id, |
774 |
c_sort1 => $c_sort1, |
780 |
c_quantity => $c_quantity, |
775 |
c_sort2 => $c_sort2, |
781 |
c_budget_id => $c_budget_id, |
776 |
c_replacement_price => $c_replacement_price, |
782 |
c_discount => $c_discount, |
777 |
c_price => $c_price, |
783 |
c_sort1 => $c_sort1, |
|
|
784 |
c_sort2 => $c_sort2, |
785 |
c_replacement_price => $c_replacement_price, |
786 |
c_price => $c_price, |
787 |
marcrecord => $marcrecord, |
778 |
}; |
788 |
}; |
779 |
|
789 |
|
|
|
790 |
if($client) { |
791 |
$order_line_fields->{tags} = $fields->{tags}; |
792 |
$order_line_fields->{subfields} = $fields->{subfields}; |
793 |
$order_line_fields->{field_values} = $fields->{field_values}; |
794 |
$order_line_fields->{serials} = $fields->{serials}; |
795 |
$order_line_fields->{order_vendornote} = $fields->{order_vendornote}; |
796 |
$order_line_fields->{order_internalnote} = $fields->{order_internalnote}; |
797 |
$order_line_fields->{all_currency} = $fields->{all_currency}; |
798 |
} |
799 |
|
780 |
return $order_line_fields; |
800 |
return $order_line_fields; |
781 |
} |
801 |
} |
782 |
|
802 |
|
Lines 807-864
sub create_items_and_generate_order_hash {
Link Here
|
807 |
my $active_currency = $args->{active_currency}; |
827 |
my $active_currency = $args->{active_currency}; |
808 |
my @order_line_details; |
828 |
my @order_line_details; |
809 |
my $itemcreation = 0; |
829 |
my $itemcreation = 0; |
|
|
830 |
my @itemnumbers; |
810 |
|
831 |
|
811 |
for ( my $i = 0 ; $i < $loop_limit ; $i++ ) { |
832 |
for ( my $i = 0 ; $i < $loop_limit ; $i++ ) { |
812 |
$itemcreation = 1; |
833 |
$itemcreation = 1; |
813 |
my $item = Koha::Item->new( |
834 |
my $item = Koha::Item->new( |
814 |
{ |
835 |
{ |
815 |
biblionumber => $fields->{biblionumber}, |
836 |
biblionumber => $fields->{biblionumber}, |
816 |
homebranch => @{ $fields->{homebranch} }[$i], |
837 |
homebranch => @{ $fields->{homebranch} }[$i], |
817 |
holdingbranch => @{ $fields->{holdingbranch} }[$i], |
838 |
holdingbranch => @{ $fields->{holdingbranch} }[$i], |
818 |
itemnotes_nonpublic => @{ $fields->{itemnotes_nonpublic} }[$i], |
839 |
itemnotes_nonpublic => @{ $fields->{itemnotes_nonpublic} }[$i], |
819 |
itemnotes => @{ $fields->{itemnotes} }[$i], |
840 |
itemnotes => @{ $fields->{itemnotes} }[$i], |
820 |
location => @{ $fields->{location} }[$i], |
841 |
location => @{ $fields->{location} }[$i], |
821 |
ccode => @{ $fields->{ccode} }[$i], |
842 |
ccode => @{ $fields->{ccode} }[$i], |
822 |
itype => @{ $fields->{itype} }[$i], |
843 |
itype => @{ $fields->{itype} }[$i], |
823 |
notforloan => @{ $fields->{notforloan} }[$i], |
844 |
notforloan => @{ $fields->{notforloan} }[$i], |
824 |
uri => @{ $fields->{uri} }[$i], |
845 |
uri => @{ $fields->{uri} }[$i], |
825 |
copynumber => @{ $fields->{copynumber} }[$i], |
846 |
copynumber => @{ $fields->{copynumber} }[$i], |
826 |
price => @{ $fields->{price} }[$i], |
847 |
price => @{ $fields->{price} }[$i], |
827 |
replacementprice => @{ $fields->{replacementprice} }[$i], |
848 |
replacementprice => @{ $fields->{replacementprice} }[$i], |
828 |
itemcallnumber => @{ $fields->{itemcallnumber} }[$i], |
849 |
itemcallnumber => @{ $fields->{itemcallnumber} }[$i], |
|
|
850 |
coded_location_qualifier => @{ $fields->{coded_location_qualifier} }[$i], |
851 |
barcode => @{ $fields->{barcode} }[$i], |
852 |
enumchron => @{ $fields->{enumchron} }[$i], |
829 |
} |
853 |
} |
830 |
)->store; |
854 |
)->store; |
|
|
855 |
push( @itemnumbers, $item->itemnumber ); |
856 |
} |
831 |
|
857 |
|
832 |
my %order_detail_hash = ( |
858 |
if ( $itemcreation == 1 ) { |
833 |
biblionumber => $fields->{biblionumber}, |
859 |
# Group orderlines from MarcItemFieldsToOrder |
834 |
itemnumbers => ( $item->itemnumber ), |
860 |
my $budget_hash; |
835 |
basketno => $basket_id, |
861 |
my @budget_ids = @{ $fields->{budget_code} }; |
836 |
quantity => 1, |
862 |
for ( my $i = 0 ; $i < $loop_limit ; $i++ ) { |
837 |
budget_id => @{ $fields->{budget_code} }[$i] |
863 |
$budget_ids[$i] = $budget_id if !$budget_ids[$i]; # Use default budget if no budget provided |
838 |
|| $budget_id, |
864 |
$budget_hash->{ $budget_ids[$i] }->{quantity} += 1; |
839 |
currency => $vendor->listprice, |
865 |
$budget_hash->{ $budget_ids[$i] }->{price} = @{ $fields->{price} }[$i]; |
|
|
866 |
$budget_hash->{ $budget_ids[$i] }->{replacementprice} = |
867 |
@{ $fields->{replacementprice} }[$i]; |
868 |
$budget_hash->{ $budget_ids[$i] }->{itemnumbers} //= []; |
869 |
push @{ $budget_hash->{ $budget_ids[$i] }->{itemnumbers} }, |
870 |
$itemnumbers[$i]; |
871 |
} |
872 |
|
873 |
# Create orderlines from MarcItemFieldsToOrder |
874 |
while ( my ( $budget_id, $infos ) = each %$budget_hash ) { |
875 |
if ($budget_id) { |
876 |
my %orderinfo = ( |
877 |
biblionumber => $fields->{biblionumber}, |
878 |
basketno => $basket_id, |
879 |
quantity => $infos->{quantity}, |
880 |
budget_id => $budget_id, |
881 |
currency => $active_currency->currency, |
882 |
); |
883 |
|
884 |
my $price = $infos->{price}; |
885 |
if ($price) { |
886 |
$price = _format_price_to_CurrencyFormat_syspref($price); |
887 |
$price = Koha::Number::Price->new($price)->unformat; |
888 |
$orderinfo{tax_rate_on_ordering} = $vendor->tax_rate; |
889 |
$orderinfo{tax_rate_on_receiving} = $vendor->tax_rate; |
890 |
my $order_discount = $fields->{c_discount} ? $fields->{c_discount} : $vendor->discount; |
891 |
$orderinfo{discount} = $order_discount; |
892 |
$orderinfo{rrp} = $price; |
893 |
$orderinfo{ecost} = $order_discount ? $price * ( 1 - $order_discount / 100 ) : $price; |
894 |
$orderinfo{listprice} = $orderinfo{rrp} / $active_currency->rate; |
895 |
$orderinfo{unitprice} = $orderinfo{ecost}; |
896 |
$orderinfo{sort1} = $fields->{c_sort1}; |
897 |
$orderinfo{sort2} = $fields->{c_sort2}; |
898 |
} else { |
899 |
$orderinfo{listprice} = 0; |
900 |
} |
901 |
$orderinfo{replacementprice} = $infos->{replacementprice} || 0; |
902 |
|
903 |
# Remove uncertainprice flag if we have found a price in the MARC record |
904 |
$orderinfo{uncertainprice} = 0 if $orderinfo{listprice}; |
905 |
|
906 |
my $order = Koha::Acquisition::Order->new( \%orderinfo ); |
907 |
$order->populate_with_prices_for_ordering(); |
908 |
$order->populate_with_prices_for_receiving(); |
909 |
$order->store; |
910 |
$order->add_item($_) for @{ $budget_hash->{$budget_id}->{itemnumbers} }; |
911 |
} |
912 |
} |
913 |
} else { |
914 |
# Add an orderline for each MARC record |
915 |
# Get quantity in the MARC record (1 if none) |
916 |
my $quantity = GetMarcQuantity( $fields->{marcrecord}, C4::Context->preference('marcflavour') ) || 1; |
917 |
my %orderinfo = ( |
918 |
biblionumber => $fields->{biblionumber}, |
919 |
basketno => $basket_id, |
920 |
quantity => $fields->{c_quantity}, |
921 |
branchcode => C4::Context->userenv()->{'branch'}, |
922 |
budget_id => $fields->{c_budget_id}, |
923 |
uncertainprice => 1, |
924 |
sort1 => $fields->{c_sort1}, |
925 |
sort2 => $fields->{c_sort2}, |
926 |
order_internalnote => $fields->{order_internalnote}, |
927 |
order_vendornote => $fields->{order_vendornote}, |
928 |
currency => $fields->{all_currency}, |
929 |
replacementprice => $fields->{c_replacement_price}, |
840 |
); |
930 |
); |
841 |
|
931 |
|
842 |
if ( @{ $fields->{price} }[$i] ) { |
932 |
# Get the price if there is one. |
843 |
$order_detail_hash{tax_rate_on_ordering} = $vendor->tax_rate; |
933 |
if ($fields->{c_price}) { |
844 |
$order_detail_hash{tax_rate_on_receiving} = $vendor->tax_rate; |
934 |
$fields->{c_price} = _format_price_to_CurrencyFormat_syspref($fields->{c_price}); |
|
|
935 |
$fields->{c_price} = Koha::Number::Price->new( $fields->{c_price} )->unformat; |
936 |
$orderinfo{tax_rate_on_ordering} = $vendor->tax_rate; |
937 |
$orderinfo{tax_rate_on_receiving} = $vendor->tax_rate; |
845 |
my $order_discount = $fields->{c_discount} ? $fields->{c_discount} : $vendor->discount; |
938 |
my $order_discount = $fields->{c_discount} ? $fields->{c_discount} : $vendor->discount; |
846 |
$order_detail_hash{discount} = $order_discount; |
939 |
$orderinfo{discount} = $order_discount; |
847 |
$order_detail_hash{rrp} = @{ $fields->{price} }[$i]; |
940 |
$orderinfo{rrp} = $fields->{c_price}; |
848 |
$order_detail_hash{ecost} = |
941 |
$orderinfo{ecost} = |
849 |
$order_discount ? @{ $fields->{price} }[$i] * ( 1 - $order_discount / 100 ) : @{ $fields->{price} }[$i]; |
942 |
$order_discount ? $fields->{c_price} * ( 1 - $order_discount / 100 ) : $fields->{c_price}; |
850 |
$order_detail_hash{listprice} = $order_detail_hash{rrp} / $active_currency->rate; |
943 |
$orderinfo{listprice} = $orderinfo{rrp} / $active_currency->rate; |
851 |
$order_detail_hash{unitprice} = $order_detail_hash{ecost}; |
944 |
$orderinfo{unitprice} = $orderinfo{ecost}; |
852 |
} else { |
945 |
} else { |
853 |
$order_detail_hash{listprice} = 0; |
946 |
$orderinfo{listprice} = 0; |
854 |
} |
947 |
} |
855 |
$order_detail_hash{replacementprice} = @{ $fields->{replacementprice} }[$i] || 0; |
|
|
856 |
$order_detail_hash{uncertainprice} = 0 if $order_detail_hash{listprice}; |
857 |
|
948 |
|
858 |
push @order_line_details, \%order_detail_hash; |
949 |
# Remove uncertainprice flag if we have found a price in the MARC record |
|
|
950 |
$orderinfo{uncertainprice} = 0 if $orderinfo{listprice}; |
951 |
|
952 |
my $order = Koha::Acquisition::Order->new( \%orderinfo ); |
953 |
$order->populate_with_prices_for_ordering(); |
954 |
$order->populate_with_prices_for_receiving(); |
955 |
$order->store; |
859 |
|
956 |
|
|
|
957 |
my $basket = Koha::Acquisition::Baskets->find( $basket_id ); |
958 |
if ( $basket->effective_create_items eq 'ordering' && !$basket->is_standing ) { |
959 |
my @tags = @{ $fields->{tags} }; |
960 |
my @subfields = @{ $fields->{subfields} }; |
961 |
my @field_values = @{ $fields->{field_values} }; |
962 |
my @serials = @{ $fields->{serials} }; |
963 |
my $xml = TransformHtmlToXml( \@tags, \@subfields, \@field_values ); |
964 |
my $record = MARC::Record::new_from_xml( $xml, 'UTF-8' ); |
965 |
for ( my $qtyloop = 1 ; $qtyloop <= $fields->{c_quantity} ; $qtyloop++ ) { |
966 |
my ( $biblionumber, undef, $itemnumber ) = AddItemFromMarc( $fields->{marcrecord}, $fields->{biblionumber} ); |
967 |
$order->add_item($itemnumber); |
968 |
} |
969 |
} |
860 |
} |
970 |
} |
|
|
971 |
|
861 |
return \@order_line_details; |
972 |
return \@order_line_details; |
862 |
} |
973 |
} |
863 |
|
974 |
|
|
|
975 |
=head3 _format_price_to_CurrencyFormat_syspref |
976 |
|
977 |
In France, the cents separator is the ',' but sometimes a '.' is used |
978 |
In this case, the price will be x100 when unformatted |
979 |
The '.' needs replacing by a ',' to get a proper price calculation |
980 |
|
981 |
=cut |
982 |
|
983 |
sub _format_price_to_CurrencyFormat_syspref { |
984 |
my ($price) = @_; |
985 |
|
986 |
$price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR"; |
987 |
return $price; |
988 |
} |
989 |
|
864 |
1; |
990 |
1; |