|
Lines 608-644
sub transfer_items {
Link Here
|
| 608 |
} |
608 |
} |
| 609 |
|
609 |
|
| 610 |
sub process_quote { |
610 |
sub process_quote { |
| 611 |
my $quote = shift; |
611 |
my $quote_message = shift; |
| 612 |
|
612 |
|
| 613 |
$quote->status('processing'); |
613 |
$quote_message->status('processing'); |
| 614 |
$quote->update; |
614 |
$quote_message->update; |
| 615 |
|
615 |
|
| 616 |
my $edi = Koha::Edifact->new( { transmission => $quote->raw_msg, } ); |
616 |
my $edi = Koha::Edifact->new( { transmission => $quote_message->raw_msg, } ); |
| 617 |
|
617 |
|
| 618 |
my $messages = $edi->message_array(); |
618 |
my $messages = $edi->message_array(); |
| 619 |
my $process_errors = 0; |
619 |
my $process_errors = 0; |
| 620 |
my $logger = Koha::Logger->get( { interface => 'edi' } ); |
620 |
my $logger = Koha::Logger->get( { interface => 'edi' } ); |
| 621 |
my $schema = Koha::Database->new()->schema(); |
621 |
my $schema = Koha::Database->new()->schema(); |
| 622 |
my $message_count = 0; |
622 |
my $message_count = 0; |
|
|
623 |
my $split_message; |
| 623 |
my @added_baskets; # if auto & multiple baskets need to order all |
624 |
my @added_baskets; # if auto & multiple baskets need to order all |
| 624 |
|
625 |
|
| 625 |
if ( @{$messages} && $quote->vendor_id ) { |
626 |
if ( @{$messages} && $quote_message->vendor_id ) { |
| 626 |
foreach my $msg ( @{$messages} ) { |
627 |
foreach my $msg ( @{$messages} ) { |
| 627 |
++$message_count; |
628 |
++$message_count; |
| 628 |
my $basketno = NewBasket( |
629 |
my $basketno = NewBasket( |
| 629 |
$quote->vendor_id, 0, $quote->filename, q{}, |
630 |
$quote_message->vendor_id, 0, $quote_message->filename, q{}, |
| 630 |
q{} . q{} |
631 |
q{} . q{} |
| 631 |
); |
632 |
); |
| 632 |
push @added_baskets, $basketno; |
633 |
push @added_baskets, $basketno; |
| 633 |
if ( $message_count > 1 ) { |
634 |
if ( $message_count > 1 ) { |
| 634 |
my $m_filename = $quote->filename; |
635 |
my $m_filename = $quote_message->filename; |
| 635 |
$m_filename .= "_$message_count"; |
636 |
$m_filename .= "_$message_count"; |
| 636 |
$schema->resultset('EdifactMessage')->create( |
637 |
$split_message = $schema->resultset('EdifactMessage')->create( |
| 637 |
{ |
638 |
{ |
| 638 |
message_type => $quote->message_type, |
639 |
message_type => $quote_message->message_type, |
| 639 |
transfer_date => $quote->transfer_date, |
640 |
transfer_date => $quote_message->transfer_date, |
| 640 |
vendor_id => $quote->vendor_id, |
641 |
vendor_id => $quote_message->vendor_id, |
| 641 |
edi_acct => $quote->edi_acct, |
642 |
edi_acct => $quote_message->edi_acct, |
| 642 |
status => 'recmsg', |
643 |
status => 'recmsg', |
| 643 |
basketno => $basketno, |
644 |
basketno => $basketno, |
| 644 |
raw_msg => q{}, |
645 |
raw_msg => q{}, |
|
Lines 646-659
sub process_quote {
Link Here
|
| 646 |
} |
647 |
} |
| 647 |
); |
648 |
); |
| 648 |
} else { |
649 |
} else { |
| 649 |
$quote->basketno($basketno); |
650 |
$quote_message->basketno($basketno); |
| 650 |
} |
651 |
} |
| 651 |
$logger->trace("Created basket :$basketno"); |
652 |
$logger->trace("Created basket :$basketno"); |
| 652 |
my $items = $msg->lineitems(); |
653 |
my $items = $msg->lineitems(); |
| 653 |
my $refnum = $msg->message_refno; |
654 |
my $refnum = $msg->message_refno; |
| 654 |
|
655 |
|
| 655 |
for my $item ( @{$items} ) { |
656 |
for my $item ( @{$items} ) { |
| 656 |
if ( !quote_item( $item, $quote, $basketno ) ) { |
657 |
my $message = $split_message // $quote_message; |
|
|
658 |
if ( !quote_item( $item, $message, $basketno ) ) { |
| 657 |
++$process_errors; |
659 |
++$process_errors; |
| 658 |
} |
660 |
} |
| 659 |
} |
661 |
} |
|
Lines 664-675
sub process_quote {
Link Here
|
| 664 |
$status = 'error'; |
666 |
$status = 'error'; |
| 665 |
} |
667 |
} |
| 666 |
|
668 |
|
| 667 |
$quote->status($status); |
669 |
$quote_message->status($status); |
| 668 |
$quote->update; # status and basketno link |
670 |
$quote_message->update; # status and basketno link |
| 669 |
# Do we automatically generate orders for this vendor |
671 |
# Do we automatically generate orders for this vendor |
| 670 |
my $v = $schema->resultset('VendorEdiAccount')->search( |
672 |
my $v = $schema->resultset('VendorEdiAccount')->search( |
| 671 |
{ |
673 |
{ |
| 672 |
vendor_id => $quote->vendor_id, |
674 |
vendor_id => $quote_message->vendor_id, |
| 673 |
} |
675 |
} |
| 674 |
)->single; |
676 |
)->single; |
| 675 |
if ( $v->auto_orders ) { |
677 |
if ( $v->auto_orders ) { |
|
Lines 699-705
sub process_quote {
Link Here
|
| 699 |
} |
701 |
} |
| 700 |
|
702 |
|
| 701 |
sub quote_item { |
703 |
sub quote_item { |
| 702 |
my ( $item, $quote, $basketno ) = @_; |
704 |
my ( $item, $quote_message, $basketno ) = @_; |
| 703 |
|
705 |
|
| 704 |
my $schema = Koha::Database->new()->schema(); |
706 |
my $schema = Koha::Database->new()->schema(); |
| 705 |
my $logger = Koha::Logger->get( { interface => 'edi' } ); |
707 |
my $logger = Koha::Logger->get( { interface => 'edi' } ); |
|
Lines 708-713
sub quote_item {
Link Here
|
| 708 |
# So this call should not fail unless that has |
710 |
# So this call should not fail unless that has |
| 709 |
my $basket = Koha::Acquisition::Baskets->find($basketno); |
711 |
my $basket = Koha::Acquisition::Baskets->find($basketno); |
| 710 |
unless ($basket) { |
712 |
unless ($basket) { |
|
|
713 |
$quote_message->add_to_edifact_errors( |
| 714 |
{ |
| 715 |
section => "", |
| 716 |
details => "Failed to create basket" |
| 717 |
} |
| 718 |
); |
| 711 |
$logger->error('Skipping order creation no valid basketno'); |
719 |
$logger->error('Skipping order creation no valid basketno'); |
| 712 |
return; |
720 |
return; |
| 713 |
} |
721 |
} |
|
Lines 715-721
sub quote_item {
Link Here
|
| 715 |
my $bib = _check_for_existing_bib( $item->item_number_id() ); |
723 |
my $bib = _check_for_existing_bib( $item->item_number_id() ); |
| 716 |
if ( !defined $bib ) { |
724 |
if ( !defined $bib ) { |
| 717 |
$bib = {}; |
725 |
$bib = {}; |
| 718 |
my $bib_record = _create_bib_from_quote( $item, $quote ); |
726 |
my $bib_record = _create_bib_from_quote( $item, $quote_message ); |
| 719 |
|
727 |
|
| 720 |
# Check for and add default 008 as this is a mandatory field |
728 |
# Check for and add default 008 as this is a mandatory field |
| 721 |
$bib_record = _handle_008_field($bib_record); |
729 |
$bib_record = _handle_008_field($bib_record); |
|
Lines 735-740
sub quote_item {
Link Here
|
| 735 |
$order_quantity ||= 1; # quantity not necessarily present |
743 |
$order_quantity ||= 1; # quantity not necessarily present |
| 736 |
if ( $gir_count > 1 ) { |
744 |
if ( $gir_count > 1 ) { |
| 737 |
if ( $gir_count != $order_quantity ) { |
745 |
if ( $gir_count != $order_quantity ) { |
|
|
746 |
$quote_message->add_to_edifact_errors( |
| 747 |
{ |
| 748 |
section => "GIR", |
| 749 |
details => "Order for $order_quantity items, $gir_count segments present" |
| 750 |
} |
| 751 |
); |
| 738 |
$logger->error("Order for $order_quantity items, $gir_count segments present"); |
752 |
$logger->error("Order for $order_quantity items, $gir_count segments present"); |
| 739 |
} |
753 |
} |
| 740 |
$order_quantity = 1; # attempts to create an orderline for each gir |
754 |
$order_quantity = 1; # attempts to create an orderline for each gir |
|
Lines 745-751
sub quote_item {
Link Here
|
| 745 |
if ( !$price ) { |
759 |
if ( !$price ) { |
| 746 |
$price = $item->price_gross; |
760 |
$price = $item->price_gross; |
| 747 |
} |
761 |
} |
| 748 |
my $vendor = Koha::Acquisition::Booksellers->find( $quote->vendor_id ); |
762 |
my $vendor = Koha::Acquisition::Booksellers->find( $quote_message->vendor_id ); |
| 749 |
|
763 |
|
| 750 |
# NB quote will not include tax info it only contains the list price |
764 |
# NB quote will not include tax info it only contains the list price |
| 751 |
my $ecost = _discounted_price( $vendor->discount, $price, $item->price_info_inclusive ); |
765 |
my $ecost = _discounted_price( $vendor->discount, $price, $item->price_info_inclusive ); |
|
Lines 813-823
sub quote_item {
Link Here
|
| 813 |
my $skip = '0'; |
827 |
my $skip = '0'; |
| 814 |
if ( !$budget ) { |
828 |
if ( !$budget ) { |
| 815 |
if ( $item->quantity > 1 ) { |
829 |
if ( $item->quantity > 1 ) { |
| 816 |
carp 'Skipping line with no budget info'; |
830 |
$quote_message->add_to_edifact_errors( |
|
|
831 |
{ |
| 832 |
section => "GIR", |
| 833 |
details => "Skipped GIR line with invalid budget: " . $item->girfield('fund_allocation') |
| 834 |
} |
| 835 |
); |
| 817 |
$logger->trace('girfield skipped for invalid budget'); |
836 |
$logger->trace('girfield skipped for invalid budget'); |
| 818 |
$skip++; |
837 |
$skip++; |
| 819 |
} else { |
838 |
} else { |
| 820 |
carp 'Skipping line with no budget info'; |
839 |
$quote_message->add_to_edifact_errors( |
|
|
840 |
{ |
| 841 |
section => "GIR", |
| 842 |
details => "Skipped orderline line with invalid budget: " . $item->girfield('fund_allocation') |
| 843 |
} |
| 844 |
); |
| 821 |
$logger->trace('orderline skipped for invalid budget'); |
845 |
$logger->trace('orderline skipped for invalid budget'); |
| 822 |
return; |
846 |
return; |
| 823 |
} |
847 |
} |
|
Lines 844-850
sub quote_item {
Link Here
|
| 844 |
$ordernumber{ $budget->budget_id } = $o; |
868 |
$ordernumber{ $budget->budget_id } = $o; |
| 845 |
|
869 |
|
| 846 |
if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) { |
870 |
if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) { |
| 847 |
$item_hash = _create_item_from_quote( $item, $quote ); |
871 |
$item_hash = _create_item_from_quote( $item, $quote_message ); |
| 848 |
|
872 |
|
| 849 |
my $created = 0; |
873 |
my $created = 0; |
| 850 |
while ( $created < $order_quantity ) { |
874 |
while ( $created < $order_quantity ) { |
|
Lines 871-876
sub quote_item {
Link Here
|
| 871 |
$rota->add_item($itemnumber); |
895 |
$rota->add_item($itemnumber); |
| 872 |
$logger->trace("Item added to rota $rota->id"); |
896 |
$logger->trace("Item added to rota $rota->id"); |
| 873 |
} else { |
897 |
} else { |
|
|
898 |
$quote_message->add_to_edifact_errors( |
| 899 |
{ |
| 900 |
section => "LRP", |
| 901 |
details => "No rota found for passed $lrp in orderline" |
| 902 |
} |
| 903 |
); |
| 874 |
$logger->error("No rota found matching $lrp in orderline"); |
904 |
$logger->error("No rota found matching $lrp in orderline"); |
| 875 |
} |
905 |
} |
| 876 |
} |
906 |
} |
|
Lines 890-896
sub quote_item {
Link Here
|
| 890 |
|
920 |
|
| 891 |
if ( !$budget ) { |
921 |
if ( !$budget ) { |
| 892 |
my $bad_budget = $item->girfield( 'fund_allocation', $occurrence ); |
922 |
my $bad_budget = $item->girfield( 'fund_allocation', $occurrence ); |
| 893 |
carp 'Skipping line with no budget info'; |
923 |
$quote_message->add_to_edifact_errors( |
|
|
924 |
{ |
| 925 |
section => "GIR", |
| 926 |
details => "Skipped GIR line with invalid budget: $bad_budget" |
| 927 |
} |
| 928 |
); |
| 894 |
$logger->trace("girfield skipped for invalid budget:$bad_budget"); |
929 |
$logger->trace("girfield skipped for invalid budget:$bad_budget"); |
| 895 |
++$occurrence; ## lets look at the next one not this one again |
930 |
++$occurrence; ## lets look at the next one not this one again |
| 896 |
next; |
931 |
next; |
|
Lines 920-926
sub quote_item {
Link Here
|
| 920 |
|
955 |
|
| 921 |
if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) { |
956 |
if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) { |
| 922 |
if ( !defined $item_hash ) { |
957 |
if ( !defined $item_hash ) { |
| 923 |
$item_hash = _create_item_from_quote( $item, $quote ); |
958 |
$item_hash = _create_item_from_quote( $item, $quote_message ); |
| 924 |
} |
959 |
} |
| 925 |
my $new_item = { |
960 |
my $new_item = { |
| 926 |
itype => $item->girfield( 'stock_category', $occurrence ), |
961 |
itype => $item->girfield( 'stock_category', $occurrence ), |
|
Lines 970-977
sub quote_item {
Link Here
|
| 970 |
); |
1005 |
); |
| 971 |
if ($rota) { |
1006 |
if ($rota) { |
| 972 |
$rota->add_item($itemnumber); |
1007 |
$rota->add_item($itemnumber); |
| 973 |
$logger->trace("Item added to rota $rota->id"); |
1008 |
$logger->trace( "Item added to rota " . $rota->id ); |
| 974 |
} else { |
1009 |
} else { |
|
|
1010 |
$quote_message->add_to_edifact_errors( |
| 1011 |
{ |
| 1012 |
section => "LRP", |
| 1013 |
details => "No rota found for passed $lrp in orderline" |
| 1014 |
} |
| 1015 |
); |
| 975 |
$logger->error("No rota found matching $lrp in orderline"); |
1016 |
$logger->error("No rota found matching $lrp in orderline"); |
| 976 |
} |
1017 |
} |
| 977 |
} |
1018 |
} |
|
Lines 1033-1038
sub quote_item {
Link Here
|
| 1033 |
$rota->add_item($itemnumber); |
1074 |
$rota->add_item($itemnumber); |
| 1034 |
$logger->trace("Item added to rota $rota->id"); |
1075 |
$logger->trace("Item added to rota $rota->id"); |
| 1035 |
} else { |
1076 |
} else { |
|
|
1077 |
$quote_message->add_to_edifact_errors( |
| 1078 |
{ |
| 1079 |
section => "LRP", |
| 1080 |
details => "No rota found for passed $lrp in orderline" |
| 1081 |
} |
| 1082 |
); |
| 1036 |
$logger->error("No rota found matching $lrp in orderline"); |
1083 |
$logger->error("No rota found matching $lrp in orderline"); |
| 1037 |
} |
1084 |
} |
| 1038 |
} |
1085 |
} |
|
Lines 1043-1049
sub quote_item {
Link Here
|
| 1043 |
} |
1090 |
} |
| 1044 |
} |
1091 |
} |
| 1045 |
return 1; |
1092 |
return 1; |
| 1046 |
|
|
|
| 1047 |
} |
1093 |
} |
| 1048 |
|
1094 |
|
| 1049 |
sub get_edifact_ean { |
1095 |
sub get_edifact_ean { |
| 1050 |
- |
|
|