View | Details | Raw Unified | Return to bug 40587
Collapse All | Expand All

(-)a/Koha/EDI.pm (-6 / +11 lines)
Lines 701-722 sub process_quote { Link Here
701
        }
701
        }
702
    )->single;
702
    )->single;
703
    if ( $v->auto_orders ) {
703
    if ( $v->auto_orders ) {
704
        for my $b (@added_baskets) {
704
        for my $i ( 0 .. $#added_baskets ) {
705
            my $basketno = $added_baskets[$i];
706
707
            # Use the correct buyer_ean for each message/basket
708
            my $buyer_ean = $messages->[$i] ? $messages->[$i]->buyer_ean : $messages->[0]->buyer_ean;
709
705
            create_edi_order(
710
            create_edi_order(
706
                {
711
                {
707
                    ean      => $messages->[0]->buyer_ean,
712
                    ean      => $buyer_ean,
708
                    basketno => $b,
713
                    basketno => $basketno,
709
                }
714
                }
710
            );
715
            );
711
            Koha::Acquisition::Baskets->find($b)->close;
716
            Koha::Acquisition::Baskets->find($basketno)->close;
712
717
713
            # Log the approval
718
            # Log the approval
714
            if ( C4::Context->preference("AcquisitionLog") ) {
719
            if ( C4::Context->preference("AcquisitionLog") ) {
715
                my $approved = Koha::Acquisition::Baskets->find($b);
720
                my $approved = Koha::Acquisition::Baskets->find($basketno);
716
                logaction(
721
                logaction(
717
                    'ACQUISITIONS',
722
                    'ACQUISITIONS',
718
                    'APPROVE_BASKET',
723
                    'APPROVE_BASKET',
719
                    $b,
724
                    $basketno,
720
                    to_json( $approved->unblessed )
725
                    to_json( $approved->unblessed )
721
                );
726
                );
722
            }
727
            }
(-)a/acqui/basket.pl (-1 / +75 lines)
Lines 103-109 if ($ediaccount) { Link Here
103
            join => 'branch',
103
            join => 'branch',
104
        }
104
        }
105
    );
105
    );
106
    $template->param( eans => \@eans );
106
107
    # Check if this basket was created from a QUOTE message and get the buyer EAN
108
    my $quote_ean     = undef;
109
    my $quote_message = $schema->resultset('EdifactMessage')->search(
110
        {
111
            basketno     => $basketno,
112
            message_type => 'QUOTE'
113
        }
114
    )->first;
115
116
    if ($quote_message) {
117
118
        # For the first message in a QUOTE transport, the raw_msg contains the full message
119
        # For subsequent messages, we need to get it from the original message
120
        my $raw_msg = $quote_message->raw_msg;
121
122
        # If this is a split message (empty raw_msg), find the original message
123
        if ( !$raw_msg ) {
124
125
            # Look for the original message with the same filename but without suffix
126
            my $original_filename = $quote_message->filename;
127
            $original_filename =~ s/_\d+$//;    # Remove _2, _3, etc. suffix
128
129
            my $original_message = $schema->resultset('EdifactMessage')->search(
130
                {
131
                    filename     => $original_filename,
132
                    message_type => 'QUOTE',
133
                    vendor_id    => $quote_message->vendor_id
134
                }
135
            )->first;
136
137
            $raw_msg = $original_message->raw_msg if $original_message;
138
        }
139
140
        if ($raw_msg) {
141
142
            # Parse the EDI message to find the buyer EAN for THIS specific basket
143
            eval {
144
                require Koha::Edifact;
145
                my $edi      = Koha::Edifact->new( { transmission => $raw_msg } );
146
                my $messages = $edi->message_array();
147
148
                # For multiple messages, we need to find which message corresponds to this basket
149
                # The current process_quote creates baskets in order, so we need to determine the index
150
                if ( @{$messages} ) {
151
                    if ( @{$messages} == 1 ) {
152
153
                        # Single message case
154
                        $quote_ean = $messages->[0]->buyer_ean;
155
                    } else {
156
157
                        # Multiple message case - determine which message this basket belongs to
158
                        # Check if this is a split message by looking at the filename suffix
159
                        my $filename = $quote_message->filename;
160
                        if ( $filename =~ /_(\d+)$/ ) {
161
                            my $message_index = $1 - 1;    # Convert to 0-based index
162
                            $quote_ean = $messages->[$message_index]->buyer_ean if $messages->[$message_index];
163
                        } else {
164
165
                            # This is the first message (no suffix)
166
                            $quote_ean = $messages->[0]->buyer_ean;
167
                        }
168
                    }
169
                }
170
            };
171
172
            # If there's an error parsing, we'll just fall back to normal behavior
173
            # Error is logged but doesn't prevent normal EAN selection
174
        }
175
    }
176
177
    $template->param(
178
        eans      => \@eans,
179
        quote_ean => $quote_ean
180
    );
107
}
181
}
108
182
109
unless ( CanUserManageBasket( $loggedinuser, $basket, $userflags ) ) {
183
unless ( CanUserManageBasket( $loggedinuser, $basket, $userflags ) ) {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt (-2 / +27 lines)
Lines 129-136 Link Here
129
                                        <button class="btn btn-default btn-xs disabled" disabled="disabled" href="#"><i class="fa fa-download"></i> Create EDIFACT order</button>
129
                                        <button class="btn btn-default btn-xs disabled" disabled="disabled" href="#"><i class="fa fa-download"></i> Create EDIFACT order</button>
130
                                    </div>
130
                                    </div>
131
                                [% ELSE %]
131
                                [% ELSE %]
132
                                    [%# Check if we have a quote EAN that matches one of the available EANs %]
133
                                    [% quote_ean_match = 0 %]
134
                                    [% quote_ean_account = {} %]
135
                                    [% IF quote_ean %]
136
                                        [% FOREACH eanacct IN eans %]
137
                                            [% IF eanacct.ean == quote_ean %]
138
                                                [% quote_ean_match = 1 %]
139
                                                [% quote_ean_account = eanacct %]
140
                                                [% LAST %]
141
                                            [% END %]
142
                                        [% END %]
143
                                    [% END %]
144
132
                                    <div class="btn-group">
145
                                    <div class="btn-group">
133
                                        [% IF eans.size == 1 %]
146
                                        [%# If we have a quote EAN match, use it directly, otherwise use original logic %]
147
                                        [% IF quote_ean_match %]
148
                                            <a
149
                                                class="btn btn-default btn-xs submit-form-link"
150
                                                href="#"
151
                                                data-ean="[% quote_ean_account.ean | html %]"
152
                                                data-basketno="[% basketno | html %]"
153
                                                data-action="basket.pl"
154
                                                data-method="post"
155
                                                data-op="cud-ediorder"
156
                                                title="Using EAN from original QUOTE message"
157
                                                ><i class="fa fa-download"></i> Create EDIFACT order</a
158
                                            >
159
                                        [% ELSIF eans.size == 1 %]
134
                                            <a
160
                                            <a
135
                                                class="btn btn-default btn-xs submit-form-link"
161
                                                class="btn btn-default btn-xs submit-form-link"
136
                                                href="#"
162
                                                href="#"
137
- 

Return to bug 40587