diff --git a/Koha/EDI.pm b/Koha/EDI.pm index 305c9fb6c9..14cec0cd1c 100644 --- a/Koha/EDI.pm +++ b/Koha/EDI.pm @@ -649,11 +649,29 @@ sub process_quote { my $split_message; my @added_baskets; # if auto & multiple baskets need to order all + # Get vendor EDI account configuration + my $v = $schema->resultset('VendorEdiAccount')->search( + { + vendor_id => $quote_message->vendor_id, + } + )->single; + if ( @{$messages} && $quote_message->vendor_id ) { + foreach my $msg ( @{$messages} ) { ++$message_count; + + # Determine basket name based on vendor configuration + my $basket_name = $quote_message->filename; + if ( $v && $v->po_is_basketname ) { + my $purchase_order_number = $msg->purchase_order_number; + if ($purchase_order_number) { + $basket_name = $purchase_order_number; + } + } + my $basketno = NewBasket( - $quote_message->vendor_id, 0, $quote_message->filename, q{}, + $quote_message->vendor_id, 0, $basket_name, q{}, q{} . q{} ); push @added_baskets, $basketno; @@ -695,12 +713,7 @@ sub process_quote { $quote_message->status($status); $quote_message->update; # status and basketno link # Do we automatically generate orders for this vendor - my $v = $schema->resultset('VendorEdiAccount')->search( - { - vendor_id => $quote_message->vendor_id, - } - )->single; - if ( $v->auto_orders ) { + if ( $v && $v->auto_orders ) { for my $i ( 0 .. $#added_baskets ) { my $basketno = $added_baskets[$i]; diff --git a/Koha/Edifact/Message.pm b/Koha/Edifact/Message.pm index 32d580d458..08895e264b 100644 --- a/Koha/Edifact/Message.pm +++ b/Koha/Edifact/Message.pm @@ -183,6 +183,22 @@ sub supplier_ean { } +sub purchase_order_number { + my $self = shift; + foreach my $s ( @{ $self->{datasegs} } ) { + if ( $s->tag eq 'LIN' ) { + last; + } + if ( $s->tag eq 'RFF' ) { + my $qualifier = $s->elem( 0, 0 ); + if ( $qualifier eq 'ON' ) { + return $s->elem( 0, 1 ); + } + } + } + return; +} + sub lineitems { my $self = shift; if ( $self->{quotation_lines} ) { @@ -280,6 +296,10 @@ Missing POD for buyer_ean. Missing POD for supplier_ean. +=head2 purchase_order_number + +Missing POD for purchase_order_number. + =head2 lineitems Missing POD for lineitems. diff --git a/admin/edi_accounts.pl b/admin/edi_accounts.pl index ffbf6e9b04..9a5f71efa5 100755 --- a/admin/edi_accounts.pl +++ b/admin/edi_accounts.pl @@ -93,6 +93,7 @@ if ( $op eq 'acct_form' ) { auto_orders => $input->param('auto_orders') ? 1 : 0, id_code_qualifier => scalar $input->param('id_code_qualifier'), plugin => scalar $input->param('plugin'), + po_is_basketname => $input->param('po_is_basketname') ? 1 : 0, }; if ($id) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/edi_accounts.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/edi_accounts.tt index 4879e2bc4c..ed231d5b71 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/edi_accounts.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/edi_accounts.tt @@ -96,9 +96,10 @@ New account [% END %] -