From 8972eb515c3cf6929624794f0f3ec10133126f85 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 10 Jul 2025 14:22:08 +0100 Subject: [PATCH] Bug 40333: Add EDIFACT message view to invoice display page This enhancement adds an EDIFACT message section to the invoice display page. If there's a linked EDI Message for this invice, we display the basic details along with any parsing errors that may have been recorded and we add a button to trigger the display of the raw message in a modal. Changes include: - Display EDIFACT message information on invoice page when available - Show message type, transfer date, status, and filename - Add "View EDIFACT message" button that opens modal with raw message - Display EDIFACT processing errors directly on invoice page - Create reusable modal components for EDIFACT message display The implementation checks if the EDIFACT system is enabled and if the invoice has an associated message_id before displaying the EDIFACT section. Processing errors are highlighted in a warning box with clear formatting. --- acqui/invoice.pl | 29 ++++++++ .../prog/en/includes/modals/edifact-modal.inc | 38 ++++++++++ .../prog/en/modules/acqui/edifactmsgs.tt | 74 +------------------ .../prog/en/modules/acqui/invoice.tt | 35 +++++++++ .../prog/js/modals/edifact-modal.js | 70 ++++++++++++++++++ 5 files changed, 175 insertions(+), 71 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/modals/edifact-modal.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/js/modals/edifact-modal.js diff --git a/acqui/invoice.pl b/acqui/invoice.pl index d38a83d217b..e61d5cc30f8 100755 --- a/acqui/invoice.pl +++ b/acqui/invoice.pl @@ -44,6 +44,7 @@ use Koha::DateUtils qw( output_pref ); use Koha::Misc::Files; use Koha::Acquisition::Invoice::Adjustments; use Koha::Acquisition::Invoices; +use Koha::Edifact::Files; my $input = CGI->new; my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( @@ -317,6 +318,34 @@ $template->param( additional_field_values => $invoice->get_additional_field_values_for_template, ); +# Check for EDIFACT message information +my $edifact_message; +my $edifact_errors = []; +my $edifact_enabled = C4::Context->preference('EDIFACT'); + +if ( $edifact_enabled && $details->{'message_id'} ) { + $edifact_message = Koha::Edifact::Files->find( $details->{'message_id'} ); + + if ($edifact_message) { + + # Get any processing errors for this message using the relation accessor + my $errors = $edifact_message->errors; + + while ( my $error = $errors->next ) { + push @$edifact_errors, { + section => $error->section, + details => $error->details, + }; + } + } +} + +$template->param( + edifact_enabled => $edifact_enabled, + edifact_message => $edifact_message, + edifact_errors => $edifact_errors, +); + $template->param( invoiceid => $details->{'invoiceid'}, invoicenumber => $details->{'invoicenumber'}, diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/modals/edifact-modal.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/modals/edifact-modal.inc new file mode 100644 index 00000000000..7886d4990c3 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/modals/edifact-modal.inc @@ -0,0 +1,38 @@ +[%# EDIFACT message modal include %] +[%# This modal can be used on any page that needs to display EDIFACT messages %] + + + + + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/edifactmsgs.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/edifactmsgs.tt index 1c8d8a56a17..3e8bc28d4a5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/edifactmsgs.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/edifactmsgs.tt @@ -37,44 +37,13 @@ - - - - - + [% INCLUDE 'modals/edifact-modal.inc' %] [% END %] [% MACRO jsinclude BLOCK %] [% Asset.js("js/acquisitions-menu.js") | $raw %] [% INCLUDE 'datatables.inc' %] + [% Asset.js("js/modals/edifact-modal.js") | $raw %] [% END %] -[% INCLUDE 'intranet-bottom.inc' %] +[% INCLUDE 'intranet-bottom.inc' %] \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt index 91ef1acade2..766faccdeba 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt @@ -57,6 +57,37 @@

Vendor: [% suppliername | html %]

+ [% IF edifact_enabled && edifact_message %] +
+

EDIFACT Message

+

+ Message type: [% edifact_message.message_type | html %] Transfer date: [% edifact_message.transfer_date | $KohaDates %] Status: [% edifact_message.status | html %] + [% IF edifact_message.filename %] + Filename: [% edifact_message.filename | html %] + [% END %] +

+

+ View EDIFACT message +

+ + [% IF edifact_errors.size > 0 %] +
+

EDIFACT Processing Errors

+
    + [% FOREACH error IN edifact_errors %] +
  • + [% error.details | html %] + [% IF error.section %] +
    [% error.section | html %]
    + [% END %] +
  • + [% END %] +
+
+ [% END %] +
+ [% END %] +
[% INCLUDE 'csrf-token.inc' %]
@@ -524,6 +555,8 @@ +[% INCLUDE 'modals/edifact-modal.inc' %] +