From 4b99b00586d59490550c8a70daf35cbad6f51ec8 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 9 Jul 2025 17:06:51 +0100 Subject: [PATCH] Bug 40334: Add EDIFACT message display to basket page This patch extends the EDIFACT message display functionality from the invoice page to the basket page, providing comprehensive access to EDIFACT messages and error reporting. Features added: - Toolbar buttons for viewing EDIFACT messages (quote/order) - Smart button display: single button for one message type, dropdown for multiple - EDIFACT parsing errors section with inline error display - Errors grouped by message type with detailed information - Conditional display: only shows when relevant data exists Changes: - acqui/basket.pl: Added EDIFACT message and error collection logic - basket.tt: Added toolbar buttons and parsing errors section - Uses existing modal system for raw message display --- acqui/basket.pl | 40 +++++ .../prog/en/modules/acqui/basket.tt | 139 ++++++++++++++++++ 2 files changed, 179 insertions(+) diff --git a/acqui/basket.pl b/acqui/basket.pl index 791acd32504..4d4254ce1c4 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -40,6 +40,7 @@ use Koha::Database; use Koha::EDI qw( create_edi_order ); use Koha::CsvProfiles; use Koha::Patrons; +use Koha::Edifact::Files; use Koha::AdditionalFields; use Koha::Old::Biblios; @@ -106,6 +107,45 @@ if ($ediaccount) { $template->param( eans => \@eans ); } +# Check for EDIFACT messages associated with this basket +my $edifact_enabled = C4::Context->preference('EDIFACT'); +my @edifact_messages = (); +my @edifact_errors = (); + +if ( $edifact_enabled && $basketno ) { + my $edifact_messages_rs = Koha::Edifact::Files->search( + { basketno => $basketno }, + { order_by => 'message_type' } + ); + + while ( my $message = $edifact_messages_rs->next ) { + push @edifact_messages, { + id => $message->id, + message_type => $message->message_type, + transfer_date => $message->transfer_date, + status => $message->status, + filename => $message->filename, + }; + + # Get errors for this message + my $errors = $message->errors; + while ( my $error = $errors->next ) { + push @edifact_errors, { + message_id => $message->id, + message_type => $message->message_type, + section => $error->section, + details => $error->details, + }; + } + } +} + +$template->param( + edifact_enabled => $edifact_enabled, + edifact_messages => \@edifact_messages, + edifact_errors => \@edifact_errors, +); + unless ( CanUserManageBasket( $loggedinuser, $basket, $userflags ) ) { $template->param( cannot_manage_basket => 1, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt index b35ab760426..1af5daa2aba 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt @@ -123,6 +123,51 @@ [% PROCESS csv_export %] + [% IF edifact_enabled && edifact_messages.size > 0 %] + [% SET quote_messages = [] %] + [% SET order_messages = [] %] + [% FOR message IN edifact_messages %] + [% IF message.message_type == 'QUOTE' %] + [% quote_messages.push(message) %] + [% ELSIF message.message_type == 'ORDERS' %] + [% order_messages.push(message) %] + [% END %] + [% END %] + + [% IF quote_messages.size > 0 && order_messages.size > 0 %] + +
+ + +
+ [% ELSIF quote_messages.size > 0 %] + +
+ +
+ [% ELSIF order_messages.size > 0 %] + +
+ +
+ [% END %] + [% END %] + [% IF Koha.Preference('EDIFACT') && ediaccount %] [% UNLESS eans.size %]
@@ -257,6 +302,51 @@
[% PROCESS csv_export %] + + [% IF edifact_enabled && edifact_messages.size > 0 %] + [% SET quote_messages = [] %] + [% SET order_messages = [] %] + [% FOR message IN edifact_messages %] + [% IF message.message_type == 'QUOTE' %] + [% quote_messages.push(message) %] + [% ELSIF message.message_type == 'ORDERS' %] + [% order_messages.push(message) %] + [% END %] + [% END %] + + [% IF quote_messages.size > 0 && order_messages.size > 0 %] + +
+ + +
+ [% ELSIF quote_messages.size > 0 %] + +
+ +
+ [% ELSIF order_messages.size > 0 %] + +
+ +
+ [% END %] + [% END %] [% END %] [% END # /UNLESS ( closedate ) %] @@ -315,6 +405,47 @@ [% IF ( basketno ) %]
+ [% IF edifact_enabled && edifact_errors.size > 0 %] +
+
+

EDIFACT parsing errors

+ + [% SET errors_by_message = {} %] + [% FOR error IN edifact_errors %] + [% SET msg_id = error.message_id %] + [% IF !errors_by_message.$msg_id %] + [% errors_by_message.$msg_id = [] %] + [% END %] + [% errors_by_message.$msg_id.push(error) %] + [% END %] + + [% FOR message IN edifact_messages %] + [% SET msg_id = message.id %] + [% IF errors_by_message.$msg_id %] +
+

[% message.message_type | html %] message ([% message.transfer_date | $KohaDates %])

+ [% IF message.filename %] +

Filename: [% message.filename | html %]

+ [% END %] +
    + [% FOR error IN errors_by_message.$msg_id %] +
  • + [% error.details | html %] + [% IF error.section %] +
    [% error.section | html %] section
    + [% END %] +
  • + [% END %] +
+
+ [% END %] + [% END %] +
+ +
+ + [% END %] +

General information

@@ -1111,6 +1242,10 @@
+[% IF edifact_enabled && edifact_messages.size > 0 %] + [% INCLUDE 'modals/edifact-modal.inc' %] +[% END %] + [% MACRO jsinclude BLOCK %] [% Asset.js("js/acquisitions-menu.js") | $raw %] [% INCLUDE 'datatables.inc' %] @@ -1336,6 +1471,10 @@ [% SET filter = 'baskets_managers' %] [% PROCESS patron_search_modal columns => columns, modal_title => t("Add user") %] [% PROCESS patron_search_js columns => columns, actions => ["add"], preview_on_name_click => 1 %] + + [% IF edifact_enabled && edifact_messages.size > 0 %] + [% Asset.js("js/modals/edifact-modal.js") | $raw %] + [% END %] [% END %] [% INCLUDE 'intranet-bottom.inc' %] -- 2.50.1