|
Lines 614-665
sub transfer_items {
Link Here
|
| 614 |
} |
614 |
} |
| 615 |
|
615 |
|
| 616 |
sub process_quote { |
616 |
sub process_quote { |
| 617 |
my $quote = shift; |
617 |
my $quote_message = shift; |
| 618 |
|
618 |
|
| 619 |
$quote->status('processing'); |
619 |
$quote_message->status('processing'); |
| 620 |
$quote->update; |
620 |
$quote_message->update; |
| 621 |
|
621 |
|
| 622 |
my $edi = Koha::Edifact->new( { transmission => $quote->raw_msg, } ); |
622 |
my $edi = Koha::Edifact->new( { transmission => $quote_message->raw_msg, } ); |
| 623 |
|
623 |
|
| 624 |
my $messages = $edi->message_array(); |
624 |
my $messages = $edi->message_array(); |
| 625 |
my $process_errors = 0; |
625 |
my $process_errors = 0; |
| 626 |
my $logger = Koha::Logger->get( { interface => 'edi' } ); |
626 |
my $logger = Koha::Logger->get( { interface => 'edi' } ); |
| 627 |
my $schema = Koha::Database->new()->schema(); |
627 |
my $schema = Koha::Database->new()->schema(); |
| 628 |
my $message_count = 0; |
628 |
my $message_count = 0; |
|
|
629 |
my $split_message; |
| 629 |
my @added_baskets; # if auto & multiple baskets need to order all |
630 |
my @added_baskets; # if auto & multiple baskets need to order all |
| 630 |
|
631 |
|
| 631 |
if ( @{$messages} && $quote->vendor_id ) { |
632 |
if ( @{$messages} && $quote_message->vendor_id ) { |
| 632 |
foreach my $msg ( @{$messages} ) { |
633 |
foreach my $msg ( @{$messages} ) { |
| 633 |
++$message_count; |
634 |
++$message_count; |
| 634 |
my $basketno = |
635 |
my $basketno = NewBasket( |
| 635 |
NewBasket( $quote->vendor_id, 0, $quote->filename, q{}, |
636 |
$quote_message->vendor_id, 0, $quote_message->filename, q{}, |
| 636 |
q{} . q{} ); |
637 |
q{} . q{} |
|
|
638 |
); |
| 637 |
push @added_baskets, $basketno; |
639 |
push @added_baskets, $basketno; |
| 638 |
if ( $message_count > 1 ) { |
640 |
if ( $message_count > 1 ) { |
| 639 |
my $m_filename = $quote->filename; |
641 |
my $m_filename = $quote_message->filename; |
| 640 |
$m_filename .= "_$message_count"; |
642 |
$m_filename .= "_$message_count"; |
| 641 |
$schema->resultset('EdifactMessage')->create( |
643 |
$split_message = $schema->resultset('EdifactMessage')->create( |
| 642 |
{ |
644 |
{ |
| 643 |
message_type => $quote->message_type, |
645 |
message_type => $quote_message->message_type, |
| 644 |
transfer_date => $quote->transfer_date, |
646 |
transfer_date => $quote_message->transfer_date, |
| 645 |
vendor_id => $quote->vendor_id, |
647 |
vendor_id => $quote_message->vendor_id, |
| 646 |
edi_acct => $quote->edi_acct, |
648 |
edi_acct => $quote_message->edi_acct, |
| 647 |
status => 'recmsg', |
649 |
status => 'recmsg', |
| 648 |
basketno => $basketno, |
650 |
basketno => $basketno, |
| 649 |
raw_msg => q{}, |
651 |
raw_msg => q{}, |
| 650 |
filename => $m_filename, |
652 |
filename => $m_filename, |
| 651 |
} |
653 |
} |
| 652 |
); |
654 |
); |
| 653 |
} |
655 |
} else { |
| 654 |
else { |
656 |
$quote_message->basketno($basketno); |
| 655 |
$quote->basketno($basketno); |
|
|
| 656 |
} |
657 |
} |
| 657 |
$logger->trace("Created basket :$basketno"); |
658 |
$logger->trace("Created basket :$basketno"); |
| 658 |
my $items = $msg->lineitems(); |
659 |
my $items = $msg->lineitems(); |
| 659 |
my $refnum = $msg->message_refno; |
660 |
my $refnum = $msg->message_refno; |
| 660 |
|
661 |
|
| 661 |
for my $item ( @{$items} ) { |
662 |
for my $item ( @{$items} ) { |
| 662 |
if ( !quote_item( $item, $quote, $basketno ) ) { |
663 |
my $message = $split_message // $quote_message; |
|
|
664 |
if ( !quote_item( $item, $message, $basketno ) ) { |
| 663 |
++$process_errors; |
665 |
++$process_errors; |
| 664 |
} |
666 |
} |
| 665 |
} |
667 |
} |
|
Lines 670-681
sub process_quote {
Link Here
|
| 670 |
$status = 'error'; |
672 |
$status = 'error'; |
| 671 |
} |
673 |
} |
| 672 |
|
674 |
|
| 673 |
$quote->status($status); |
675 |
$quote_message->status($status); |
| 674 |
$quote->update; # status and basketno link |
676 |
$quote_message->update; # status and basketno link |
| 675 |
# Do we automatically generate orders for this vendor |
677 |
# Do we automatically generate orders for this vendor |
| 676 |
my $v = $schema->resultset('VendorEdiAccount')->search( |
678 |
my $v = $schema->resultset('VendorEdiAccount')->search( |
| 677 |
{ |
679 |
{ |
| 678 |
vendor_id => $quote->vendor_id, |
680 |
vendor_id => $quote_message->vendor_id, |
| 679 |
} |
681 |
} |
| 680 |
)->single; |
682 |
)->single; |
| 681 |
if ( $v->auto_orders ) { |
683 |
if ( $v->auto_orders ) { |
|
Lines 687-711
sub process_quote {
Link Here
|
| 687 |
} |
689 |
} |
| 688 |
); |
690 |
); |
| 689 |
Koha::Acquisition::Baskets->find($b)->close; |
691 |
Koha::Acquisition::Baskets->find($b)->close; |
|
|
692 |
|
| 690 |
# Log the approval |
693 |
# Log the approval |
| 691 |
if (C4::Context->preference("AcquisitionLog")) { |
694 |
if ( C4::Context->preference("AcquisitionLog") ) { |
| 692 |
my $approved = Koha::Acquisition::Baskets->find( $b ); |
695 |
my $approved = Koha::Acquisition::Baskets->find($b); |
| 693 |
logaction( |
696 |
logaction( |
| 694 |
'ACQUISITIONS', |
697 |
'ACQUISITIONS', |
| 695 |
'APPROVE_BASKET', |
698 |
'APPROVE_BASKET', |
| 696 |
$b, |
699 |
$b, |
| 697 |
to_json($approved->unblessed) |
700 |
to_json( $approved->unblessed ) |
| 698 |
); |
701 |
); |
| 699 |
} |
702 |
} |
| 700 |
} |
703 |
} |
| 701 |
} |
704 |
} |
| 702 |
|
705 |
|
| 703 |
|
|
|
| 704 |
return; |
706 |
return; |
| 705 |
} |
707 |
} |
| 706 |
|
708 |
|
| 707 |
sub quote_item { |
709 |
sub quote_item { |
| 708 |
my ( $item, $quote, $basketno ) = @_; |
710 |
my ( $item, $quote_message, $basketno ) = @_; |
| 709 |
|
711 |
|
| 710 |
my $schema = Koha::Database->new()->schema(); |
712 |
my $schema = Koha::Database->new()->schema(); |
| 711 |
my $logger = Koha::Logger->get( { interface => 'edi' } ); |
713 |
my $logger = Koha::Logger->get( { interface => 'edi' } ); |
|
Lines 714-719
sub quote_item {
Link Here
|
| 714 |
# So this call should not fail unless that has |
716 |
# So this call should not fail unless that has |
| 715 |
my $basket = Koha::Acquisition::Baskets->find( $basketno ); |
717 |
my $basket = Koha::Acquisition::Baskets->find( $basketno ); |
| 716 |
unless ( $basket ) { |
718 |
unless ( $basket ) { |
|
|
719 |
$quote_message->add_to_edifact_errors( |
| 720 |
{ |
| 721 |
section => "", |
| 722 |
details => "Failed to create basket" |
| 723 |
} |
| 724 |
); |
| 717 |
$logger->error('Skipping order creation no valid basketno'); |
725 |
$logger->error('Skipping order creation no valid basketno'); |
| 718 |
return; |
726 |
return; |
| 719 |
} |
727 |
} |
|
Lines 721-727
sub quote_item {
Link Here
|
| 721 |
my $bib = _check_for_existing_bib( $item->item_number_id() ); |
729 |
my $bib = _check_for_existing_bib( $item->item_number_id() ); |
| 722 |
if ( !defined $bib ) { |
730 |
if ( !defined $bib ) { |
| 723 |
$bib = {}; |
731 |
$bib = {}; |
| 724 |
my $bib_record = _create_bib_from_quote( $item, $quote ); |
732 |
my $bib_record = _create_bib_from_quote( $item, $quote_message ); |
| 725 |
|
733 |
|
| 726 |
# Check for and add default 008 as this is a mandatory field |
734 |
# Check for and add default 008 as this is a mandatory field |
| 727 |
$bib_record = _handle_008_field($bib_record); |
735 |
$bib_record = _handle_008_field($bib_record); |
|
Lines 742-747
sub quote_item {
Link Here
|
| 742 |
$order_quantity ||= 1; # quantity not necessarily present |
750 |
$order_quantity ||= 1; # quantity not necessarily present |
| 743 |
if ( $gir_count > 1 ) { |
751 |
if ( $gir_count > 1 ) { |
| 744 |
if ( $gir_count != $order_quantity ) { |
752 |
if ( $gir_count != $order_quantity ) { |
|
|
753 |
$quote_message->add_to_edifact_errors( |
| 754 |
{ |
| 755 |
section => "GIR", |
| 756 |
details => "Order for $order_quantity items, $gir_count segments present" |
| 757 |
} |
| 758 |
); |
| 745 |
$logger->error( |
759 |
$logger->error( |
| 746 |
"Order for $order_quantity items, $gir_count segments present"); |
760 |
"Order for $order_quantity items, $gir_count segments present"); |
| 747 |
} |
761 |
} |
|
Lines 752-758
sub quote_item {
Link Here
|
| 752 |
if (!$price) { |
766 |
if (!$price) { |
| 753 |
$price = $item->price_gross; |
767 |
$price = $item->price_gross; |
| 754 |
} |
768 |
} |
| 755 |
my $vendor = Koha::Acquisition::Booksellers->find( $quote->vendor_id ); |
769 |
my $vendor = Koha::Acquisition::Booksellers->find( $quote_message->vendor_id ); |
| 756 |
|
770 |
|
| 757 |
# NB quote will not include tax info it only contains the list price |
771 |
# NB quote will not include tax info it only contains the list price |
| 758 |
my $ecost = _discounted_price( $vendor->discount, $price, $item->price_info_inclusive ); |
772 |
my $ecost = _discounted_price( $vendor->discount, $price, $item->price_info_inclusive ); |
|
Lines 822-833
sub quote_item {
Link Here
|
| 822 |
my $skip = '0'; |
836 |
my $skip = '0'; |
| 823 |
if ( !$budget ) { |
837 |
if ( !$budget ) { |
| 824 |
if ( $item->quantity > 1 ) { |
838 |
if ( $item->quantity > 1 ) { |
| 825 |
carp 'Skipping line with no budget info'; |
839 |
$quote_message->add_to_edifact_errors( |
|
|
840 |
{ |
| 841 |
section => "GIR", |
| 842 |
details => "Skipped GIR line with invalid budget: " . $item->girfield('fund_allocation') |
| 843 |
} |
| 844 |
); |
| 826 |
$logger->trace('girfield skipped for invalid budget'); |
845 |
$logger->trace('girfield skipped for invalid budget'); |
| 827 |
$skip++; |
846 |
$skip++; |
| 828 |
} |
847 |
} else { |
| 829 |
else { |
848 |
$quote_message->add_to_edifact_errors( |
| 830 |
carp 'Skipping line with no budget info'; |
849 |
{ |
|
|
850 |
section => "GIR", |
| 851 |
details => "Skipped orderline line with invalid budget: " . $item->girfield('fund_allocation') |
| 852 |
} |
| 853 |
); |
| 831 |
$logger->trace('orderline skipped for invalid budget'); |
854 |
$logger->trace('orderline skipped for invalid budget'); |
| 832 |
return; |
855 |
return; |
| 833 |
} |
856 |
} |
|
Lines 854-860
sub quote_item {
Link Here
|
| 854 |
$ordernumber{ $budget->budget_id } = $o; |
877 |
$ordernumber{ $budget->budget_id } = $o; |
| 855 |
|
878 |
|
| 856 |
if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) { |
879 |
if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) { |
| 857 |
$item_hash = _create_item_from_quote( $item, $quote ); |
880 |
$item_hash = _create_item_from_quote( $item, $quote_message ); |
| 858 |
|
881 |
|
| 859 |
my $created = 0; |
882 |
my $created = 0; |
| 860 |
while ( $created < $order_quantity ) { |
883 |
while ( $created < $order_quantity ) { |
|
Lines 881-886
sub quote_item {
Link Here
|
| 881 |
$rota->add_item($itemnumber); |
904 |
$rota->add_item($itemnumber); |
| 882 |
$logger->trace("Item added to rota $rota->id"); |
905 |
$logger->trace("Item added to rota $rota->id"); |
| 883 |
} else { |
906 |
} else { |
|
|
907 |
$quote_message->add_to_edifact_errors( |
| 908 |
{ |
| 909 |
section => "LRP", |
| 910 |
details => "No rota found for passed $lrp in orderline" |
| 911 |
} |
| 912 |
); |
| 884 |
$logger->error("No rota found matching $lrp in orderline"); |
913 |
$logger->error("No rota found matching $lrp in orderline"); |
| 885 |
} |
914 |
} |
| 886 |
} |
915 |
} |
|
Lines 899-905
sub quote_item {
Link Here
|
| 899 |
if ( !$budget ) { |
928 |
if ( !$budget ) { |
| 900 |
my $bad_budget = |
929 |
my $bad_budget = |
| 901 |
$item->girfield( 'fund_allocation', $occurrence ); |
930 |
$item->girfield( 'fund_allocation', $occurrence ); |
| 902 |
carp 'Skipping line with no budget info'; |
931 |
$quote_message->add_to_edifact_errors( |
|
|
932 |
{ |
| 933 |
section => "GIR", |
| 934 |
details => "Skipped GIR line with invalid budget: $bad_budget" |
| 935 |
} |
| 936 |
); |
| 903 |
$logger->trace( |
937 |
$logger->trace( |
| 904 |
"girfield skipped for invalid budget:$bad_budget"); |
938 |
"girfield skipped for invalid budget:$bad_budget"); |
| 905 |
++$occurrence; ## lets look at the next one not this one again |
939 |
++$occurrence; ## lets look at the next one not this one again |
|
Lines 931-937
sub quote_item {
Link Here
|
| 931 |
|
965 |
|
| 932 |
if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) { |
966 |
if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) { |
| 933 |
if ( !defined $item_hash ) { |
967 |
if ( !defined $item_hash ) { |
| 934 |
$item_hash = _create_item_from_quote( $item, $quote ); |
968 |
$item_hash = _create_item_from_quote( $item, $quote_message ); |
| 935 |
} |
969 |
} |
| 936 |
my $new_item = { |
970 |
my $new_item = { |
| 937 |
itype => |
971 |
itype => |
|
Lines 986-994
sub quote_item {
Link Here
|
| 986 |
{ key => 'stockrotationrotas_title' } ); |
1020 |
{ key => 'stockrotationrotas_title' } ); |
| 987 |
if ($rota) { |
1021 |
if ($rota) { |
| 988 |
$rota->add_item($itemnumber); |
1022 |
$rota->add_item($itemnumber); |
| 989 |
$logger->trace("Item added to rota $rota->id"); |
1023 |
$logger->trace("Item added to rota " .$rota->id); |
| 990 |
} |
1024 |
} |
| 991 |
else { |
1025 |
else { |
|
|
1026 |
$quote_message->add_to_edifact_errors( |
| 1027 |
{ |
| 1028 |
section => "LRP", |
| 1029 |
details => "No rota found for passed $lrp in orderline" |
| 1030 |
} |
| 1031 |
); |
| 992 |
$logger->error( |
1032 |
$logger->error( |
| 993 |
"No rota found matching $lrp in orderline"); |
1033 |
"No rota found matching $lrp in orderline"); |
| 994 |
} |
1034 |
} |
|
Lines 1059-1064
sub quote_item {
Link Here
|
| 1059 |
$logger->trace("Item added to rota $rota->id"); |
1099 |
$logger->trace("Item added to rota $rota->id"); |
| 1060 |
} |
1100 |
} |
| 1061 |
else { |
1101 |
else { |
|
|
1102 |
$quote_message->add_to_edifact_errors( |
| 1103 |
{ |
| 1104 |
section => "LRP", |
| 1105 |
details => "No rota found for passed $lrp in orderline" |
| 1106 |
} |
| 1107 |
); |
| 1062 |
$logger->error( |
1108 |
$logger->error( |
| 1063 |
"No rota found matching $lrp in orderline"); |
1109 |
"No rota found matching $lrp in orderline"); |
| 1064 |
} |
1110 |
} |
|
Lines 1070-1076
sub quote_item {
Link Here
|
| 1070 |
} |
1116 |
} |
| 1071 |
} |
1117 |
} |
| 1072 |
return 1; |
1118 |
return 1; |
| 1073 |
|
|
|
| 1074 |
} |
1119 |
} |
| 1075 |
|
1120 |
|
| 1076 |
sub get_edifact_ean { |
1121 |
sub get_edifact_ean { |
| 1077 |
- |
|
|