Lines 609-660
sub transfer_items {
Link Here
|
609 |
} |
609 |
} |
610 |
|
610 |
|
611 |
sub process_quote { |
611 |
sub process_quote { |
612 |
my $quote = shift; |
612 |
my $quote_message = shift; |
613 |
|
613 |
|
614 |
$quote->status('processing'); |
614 |
$quote_message->status('processing'); |
615 |
$quote->update; |
615 |
$quote_message->update; |
616 |
|
616 |
|
617 |
my $edi = Koha::Edifact->new( { transmission => $quote->raw_msg, } ); |
617 |
my $edi = Koha::Edifact->new( { transmission => $quote_message->raw_msg, } ); |
618 |
|
618 |
|
619 |
my $messages = $edi->message_array(); |
619 |
my $messages = $edi->message_array(); |
620 |
my $process_errors = 0; |
620 |
my $process_errors = 0; |
621 |
my $logger = Koha::Logger->get({ interface => 'edi' }); |
621 |
my $logger = Koha::Logger->get( { interface => 'edi' } ); |
622 |
my $schema = Koha::Database->new()->schema(); |
622 |
my $schema = Koha::Database->new()->schema(); |
623 |
my $message_count = 0; |
623 |
my $message_count = 0; |
|
|
624 |
my $split_message; |
624 |
my @added_baskets; # if auto & multiple baskets need to order all |
625 |
my @added_baskets; # if auto & multiple baskets need to order all |
625 |
|
626 |
|
626 |
if ( @{$messages} && $quote->vendor_id ) { |
627 |
if ( @{$messages} && $quote_message->vendor_id ) { |
627 |
foreach my $msg ( @{$messages} ) { |
628 |
foreach my $msg ( @{$messages} ) { |
628 |
++$message_count; |
629 |
++$message_count; |
629 |
my $basketno = |
630 |
my $basketno = NewBasket( |
630 |
NewBasket( $quote->vendor_id, 0, $quote->filename, q{}, |
631 |
$quote_message->vendor_id, 0, $quote_message->filename, q{}, |
631 |
q{} . q{} ); |
632 |
q{} . q{} |
|
|
633 |
); |
632 |
push @added_baskets, $basketno; |
634 |
push @added_baskets, $basketno; |
633 |
if ( $message_count > 1 ) { |
635 |
if ( $message_count > 1 ) { |
634 |
my $m_filename = $quote->filename; |
636 |
my $m_filename = $quote_message->filename; |
635 |
$m_filename .= "_$message_count"; |
637 |
$m_filename .= "_$message_count"; |
636 |
$schema->resultset('EdifactMessage')->create( |
638 |
$split_message = $schema->resultset('EdifactMessage')->create( |
637 |
{ |
639 |
{ |
638 |
message_type => $quote->message_type, |
640 |
message_type => $quote_message->message_type, |
639 |
transfer_date => $quote->transfer_date, |
641 |
transfer_date => $quote_message->transfer_date, |
640 |
vendor_id => $quote->vendor_id, |
642 |
vendor_id => $quote_message->vendor_id, |
641 |
edi_acct => $quote->edi_acct, |
643 |
edi_acct => $quote_message->edi_acct, |
642 |
status => 'recmsg', |
644 |
status => 'recmsg', |
643 |
basketno => $basketno, |
645 |
basketno => $basketno, |
644 |
raw_msg => q{}, |
646 |
raw_msg => q{}, |
645 |
filename => $m_filename, |
647 |
filename => $m_filename, |
646 |
} |
648 |
} |
647 |
); |
649 |
); |
648 |
} |
650 |
} else { |
649 |
else { |
651 |
$quote_message->basketno($basketno); |
650 |
$quote->basketno($basketno); |
|
|
651 |
} |
652 |
} |
652 |
$logger->trace("Created basket :$basketno"); |
653 |
$logger->trace("Created basket :$basketno"); |
653 |
my $items = $msg->lineitems(); |
654 |
my $items = $msg->lineitems(); |
654 |
my $refnum = $msg->message_refno; |
655 |
my $refnum = $msg->message_refno; |
655 |
|
656 |
|
656 |
for my $item ( @{$items} ) { |
657 |
for my $item ( @{$items} ) { |
657 |
if ( !quote_item( $item, $quote, $basketno ) ) { |
658 |
my $message = $split_message // $quote_message; |
|
|
659 |
if ( !quote_item( $item, $message, $basketno ) ) { |
658 |
++$process_errors; |
660 |
++$process_errors; |
659 |
} |
661 |
} |
660 |
} |
662 |
} |
Lines 665-676
sub process_quote {
Link Here
|
665 |
$status = 'error'; |
667 |
$status = 'error'; |
666 |
} |
668 |
} |
667 |
|
669 |
|
668 |
$quote->status($status); |
670 |
$quote_message->status($status); |
669 |
$quote->update; # status and basketno link |
671 |
$quote_message->update; # status and basketno link |
670 |
# Do we automatically generate orders for this vendor |
672 |
# Do we automatically generate orders for this vendor |
671 |
my $v = $schema->resultset('VendorEdiAccount')->search( |
673 |
my $v = $schema->resultset('VendorEdiAccount')->search( |
672 |
{ |
674 |
{ |
673 |
vendor_id => $quote->vendor_id, |
675 |
vendor_id => $quote_message->vendor_id, |
674 |
} |
676 |
} |
675 |
)->single; |
677 |
)->single; |
676 |
if ( $v->auto_orders ) { |
678 |
if ( $v->auto_orders ) { |
Lines 682-706
sub process_quote {
Link Here
|
682 |
} |
684 |
} |
683 |
); |
685 |
); |
684 |
Koha::Acquisition::Baskets->find($b)->close; |
686 |
Koha::Acquisition::Baskets->find($b)->close; |
|
|
687 |
|
685 |
# Log the approval |
688 |
# Log the approval |
686 |
if (C4::Context->preference("AcquisitionLog")) { |
689 |
if ( C4::Context->preference("AcquisitionLog") ) { |
687 |
my $approved = Koha::Acquisition::Baskets->find( $b ); |
690 |
my $approved = Koha::Acquisition::Baskets->find($b); |
688 |
logaction( |
691 |
logaction( |
689 |
'ACQUISITIONS', |
692 |
'ACQUISITIONS', |
690 |
'APPROVE_BASKET', |
693 |
'APPROVE_BASKET', |
691 |
$b, |
694 |
$b, |
692 |
to_json($approved->unblessed) |
695 |
to_json( $approved->unblessed ) |
693 |
); |
696 |
); |
694 |
} |
697 |
} |
695 |
} |
698 |
} |
696 |
} |
699 |
} |
697 |
|
700 |
|
698 |
|
|
|
699 |
return; |
701 |
return; |
700 |
} |
702 |
} |
701 |
|
703 |
|
702 |
sub quote_item { |
704 |
sub quote_item { |
703 |
my ( $item, $quote, $basketno ) = @_; |
705 |
my ( $item, $quote_message, $basketno ) = @_; |
704 |
|
706 |
|
705 |
my $schema = Koha::Database->new()->schema(); |
707 |
my $schema = Koha::Database->new()->schema(); |
706 |
my $logger = Koha::Logger->get({ interface => 'edi' }); |
708 |
my $logger = Koha::Logger->get({ interface => 'edi' }); |
Lines 709-714
sub quote_item {
Link Here
|
709 |
# So this call should not fail unless that has |
711 |
# So this call should not fail unless that has |
710 |
my $basket = Koha::Acquisition::Baskets->find( $basketno ); |
712 |
my $basket = Koha::Acquisition::Baskets->find( $basketno ); |
711 |
unless ( $basket ) { |
713 |
unless ( $basket ) { |
|
|
714 |
$quote_message->add_to_edifact_errors( |
715 |
{ |
716 |
section => "", |
717 |
details => "Failed to create basket" |
718 |
} |
719 |
); |
712 |
$logger->error('Skipping order creation no valid basketno'); |
720 |
$logger->error('Skipping order creation no valid basketno'); |
713 |
return; |
721 |
return; |
714 |
} |
722 |
} |
Lines 716-722
sub quote_item {
Link Here
|
716 |
my $bib = _check_for_existing_bib( $item->item_number_id() ); |
724 |
my $bib = _check_for_existing_bib( $item->item_number_id() ); |
717 |
if ( !defined $bib ) { |
725 |
if ( !defined $bib ) { |
718 |
$bib = {}; |
726 |
$bib = {}; |
719 |
my $bib_record = _create_bib_from_quote( $item, $quote ); |
727 |
my $bib_record = _create_bib_from_quote( $item, $quote_message ); |
720 |
|
728 |
|
721 |
# Check for and add default 008 as this is a mandatory field |
729 |
# Check for and add default 008 as this is a mandatory field |
722 |
$bib_record = _handle_008_field($bib_record); |
730 |
$bib_record = _handle_008_field($bib_record); |
Lines 737-742
sub quote_item {
Link Here
|
737 |
$order_quantity ||= 1; # quantity not necessarily present |
745 |
$order_quantity ||= 1; # quantity not necessarily present |
738 |
if ( $gir_count > 1 ) { |
746 |
if ( $gir_count > 1 ) { |
739 |
if ( $gir_count != $order_quantity ) { |
747 |
if ( $gir_count != $order_quantity ) { |
|
|
748 |
$quote_message->add_to_edifact_errors( |
749 |
{ |
750 |
section => "GIR", |
751 |
details => "Order for $order_quantity items, $gir_count segments present" |
752 |
} |
753 |
); |
740 |
$logger->error( |
754 |
$logger->error( |
741 |
"Order for $order_quantity items, $gir_count segments present"); |
755 |
"Order for $order_quantity items, $gir_count segments present"); |
742 |
} |
756 |
} |
Lines 747-753
sub quote_item {
Link Here
|
747 |
if (!$price) { |
761 |
if (!$price) { |
748 |
$price = $item->price_gross; |
762 |
$price = $item->price_gross; |
749 |
} |
763 |
} |
750 |
my $vendor = Koha::Acquisition::Booksellers->find( $quote->vendor_id ); |
764 |
my $vendor = Koha::Acquisition::Booksellers->find( $quote_message->vendor_id ); |
751 |
|
765 |
|
752 |
# NB quote will not include tax info it only contains the list price |
766 |
# NB quote will not include tax info it only contains the list price |
753 |
my $ecost = _discounted_price( $vendor->discount, $price, $item->price_info_inclusive ); |
767 |
my $ecost = _discounted_price( $vendor->discount, $price, $item->price_info_inclusive ); |
Lines 817-828
sub quote_item {
Link Here
|
817 |
my $skip = '0'; |
831 |
my $skip = '0'; |
818 |
if ( !$budget ) { |
832 |
if ( !$budget ) { |
819 |
if ( $item->quantity > 1 ) { |
833 |
if ( $item->quantity > 1 ) { |
820 |
carp 'Skipping line with no budget info'; |
834 |
$quote_message->add_to_edifact_errors( |
|
|
835 |
{ |
836 |
section => "GIR", |
837 |
details => "Skipped GIR line with invalid budget: " . $item->girfield('fund_allocation') |
838 |
} |
839 |
); |
821 |
$logger->trace('girfield skipped for invalid budget'); |
840 |
$logger->trace('girfield skipped for invalid budget'); |
822 |
$skip++; |
841 |
$skip++; |
823 |
} |
842 |
} else { |
824 |
else { |
843 |
$quote_message->add_to_edifact_errors( |
825 |
carp 'Skipping line with no budget info'; |
844 |
{ |
|
|
845 |
section => "GIR", |
846 |
details => "Skipped orderline line with invalid budget: " . $item->girfield('fund_allocation') |
847 |
} |
848 |
); |
826 |
$logger->trace('orderline skipped for invalid budget'); |
849 |
$logger->trace('orderline skipped for invalid budget'); |
827 |
return; |
850 |
return; |
828 |
} |
851 |
} |
Lines 849-855
sub quote_item {
Link Here
|
849 |
$ordernumber{ $budget->budget_id } = $o; |
872 |
$ordernumber{ $budget->budget_id } = $o; |
850 |
|
873 |
|
851 |
if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) { |
874 |
if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) { |
852 |
$item_hash = _create_item_from_quote( $item, $quote ); |
875 |
$item_hash = _create_item_from_quote( $item, $quote_message ); |
853 |
|
876 |
|
854 |
my $created = 0; |
877 |
my $created = 0; |
855 |
while ( $created < $order_quantity ) { |
878 |
while ( $created < $order_quantity ) { |
Lines 876-881
sub quote_item {
Link Here
|
876 |
$rota->add_item($itemnumber); |
899 |
$rota->add_item($itemnumber); |
877 |
$logger->trace("Item added to rota $rota->id"); |
900 |
$logger->trace("Item added to rota $rota->id"); |
878 |
} else { |
901 |
} else { |
|
|
902 |
$quote_message->add_to_edifact_errors( |
903 |
{ |
904 |
section => "LRP", |
905 |
details => "No rota found for passed $lrp in orderline" |
906 |
} |
907 |
); |
879 |
$logger->error("No rota found matching $lrp in orderline"); |
908 |
$logger->error("No rota found matching $lrp in orderline"); |
880 |
} |
909 |
} |
881 |
} |
910 |
} |
Lines 894-900
sub quote_item {
Link Here
|
894 |
if ( !$budget ) { |
923 |
if ( !$budget ) { |
895 |
my $bad_budget = |
924 |
my $bad_budget = |
896 |
$item->girfield( 'fund_allocation', $occurrence ); |
925 |
$item->girfield( 'fund_allocation', $occurrence ); |
897 |
carp 'Skipping line with no budget info'; |
926 |
$quote_message->add_to_edifact_errors( |
|
|
927 |
{ |
928 |
section => "GIR", |
929 |
details => "Skipped GIR line with invalid budget: $bad_budget" |
930 |
} |
931 |
); |
898 |
$logger->trace( |
932 |
$logger->trace( |
899 |
"girfield skipped for invalid budget:$bad_budget"); |
933 |
"girfield skipped for invalid budget:$bad_budget"); |
900 |
++$occurrence; ## lets look at the next one not this one again |
934 |
++$occurrence; ## lets look at the next one not this one again |
Lines 926-932
sub quote_item {
Link Here
|
926 |
|
960 |
|
927 |
if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) { |
961 |
if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) { |
928 |
if ( !defined $item_hash ) { |
962 |
if ( !defined $item_hash ) { |
929 |
$item_hash = _create_item_from_quote( $item, $quote ); |
963 |
$item_hash = _create_item_from_quote( $item, $quote_message ); |
930 |
} |
964 |
} |
931 |
my $new_item = { |
965 |
my $new_item = { |
932 |
itype => |
966 |
itype => |
Lines 981-989
sub quote_item {
Link Here
|
981 |
{ key => 'stockrotationrotas_title' } ); |
1015 |
{ key => 'stockrotationrotas_title' } ); |
982 |
if ($rota) { |
1016 |
if ($rota) { |
983 |
$rota->add_item($itemnumber); |
1017 |
$rota->add_item($itemnumber); |
984 |
$logger->trace("Item added to rota $rota->id"); |
1018 |
$logger->trace("Item added to rota " .$rota->id); |
985 |
} |
1019 |
} |
986 |
else { |
1020 |
else { |
|
|
1021 |
$quote_message->add_to_edifact_errors( |
1022 |
{ |
1023 |
section => "LRP", |
1024 |
details => "No rota found for passed $lrp in orderline" |
1025 |
} |
1026 |
); |
987 |
$logger->error( |
1027 |
$logger->error( |
988 |
"No rota found matching $lrp in orderline"); |
1028 |
"No rota found matching $lrp in orderline"); |
989 |
} |
1029 |
} |
Lines 1054-1059
sub quote_item {
Link Here
|
1054 |
$logger->trace("Item added to rota $rota->id"); |
1094 |
$logger->trace("Item added to rota $rota->id"); |
1055 |
} |
1095 |
} |
1056 |
else { |
1096 |
else { |
|
|
1097 |
$quote_message->add_to_edifact_errors( |
1098 |
{ |
1099 |
section => "LRP", |
1100 |
details => "No rota found for passed $lrp in orderline" |
1101 |
} |
1102 |
); |
1057 |
$logger->error( |
1103 |
$logger->error( |
1058 |
"No rota found matching $lrp in orderline"); |
1104 |
"No rota found matching $lrp in orderline"); |
1059 |
} |
1105 |
} |
Lines 1065-1071
sub quote_item {
Link Here
|
1065 |
} |
1111 |
} |
1066 |
} |
1112 |
} |
1067 |
return 1; |
1113 |
return 1; |
1068 |
|
|
|
1069 |
} |
1114 |
} |
1070 |
|
1115 |
|
1071 |
sub get_edifact_ean { |
1116 |
sub get_edifact_ean { |
1072 |
- |
|
|