From bcc682fcfc36ebbe01976e1ed223d67ad3a62385 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 9 Jul 2025 16:07:26 +0100 Subject: [PATCH] Bug 40333: Add EDIFACT message link to invoice display page This enhancement adds a link from the invoice display page back to the EDIFACT message that was used to create the invoice, improving workflow and traceability for acquisitions staff. 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. To test: 1. Enable EDIFACT system preference 2. Create an invoice linked to an EDIFACT message 3. View the invoice - EDIFACT section should appear after vendor info 4. Click "View EDIFACT message" to see the raw EDIFACT data in a modal 5. If there are processing errors, they should be displayed clearly --- acqui/invoice.pl | 29 ++ .../prog/en/includes/modals/edifact-modal.inc | 38 +++ .../prog/en/modules/acqui/edifactmsgs.tt | 290 +++++++----------- .../prog/en/modules/acqui/invoice.tt | 35 +++ .../prog/js/modals/edifact-modal.js | 70 +++++ 5 files changed, 284 insertions(+), 178 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..eb2ae3a82f4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/edifactmsgs.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/edifactmsgs.tt @@ -37,196 +37,130 @@ - - - - - + [% 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 %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/modals/edifact-modal.js b/koha-tmpl/intranet-tmpl/prog/js/modals/edifact-modal.js new file mode 100644 index 00000000000..1e4c22a73e6 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/js/modals/edifact-modal.js @@ -0,0 +1,70 @@ +// EDIFACT modal JavaScript functionality +// This script handles the EDIFACT message modal interactions +// Include this after the edifact-modal.inc template + +/* global __ interface theme */ +$(document).ready(function () { + // Initialize modal elements + var EDIModal = $("#EDI_modal"); + var EDIModalBody = $("#EDI_modal .modal-body"); + var EDIErrorsModal = $("#EDI_errors_modal"); + + // Handle view EDIFACT message button clicks + $("body").on("click", ".view_edifact_message", function (e) { + e.preventDefault(); + var message_id = $(this).data("message-id"); + var page = + "/cgi-bin/koha/acqui/edimsg.pl?id=" + + encodeURIComponent(message_id); + EDIModalBody.load(page + " #edimsg"); + EDIModal.modal("show"); + }); + + // Handle view_message button clicks (for compatibility with existing code) + $("body").on("click", ".view_message", function (e) { + e.preventDefault(); + var page = $(this).attr("href"); + EDIModalBody.load(page + " #edimsg"); + EDIModal.modal("show"); + }); + + // Handle modal close button + EDIModal.on("click", ".btn-close", function (e) { + e.preventDefault(); + EDIModal.modal("hide"); + }); + + // Reset modal content when hidden + EDIModal.on("hidden.bs.modal", function () { + EDIModalBody.html( + "
Loading
" + ); + }); + + // Handle EDIFACT errors modal + const errorsModal = document.getElementById("EDI_errors_modal"); + if (errorsModal) { + errorsModal.addEventListener("show.bs.modal", function (event) { + // Link that triggered the modal + const link = event.relatedTarget; + + // Extract info from data-bs-* attributes + const filename = link.getAttribute("data-bs-filename"); + const errors = link.getAttribute("data-bs-errors"); + + // Update the modal's title + const modalTitleSpan = errorsModal.querySelector( + ".modal-title #EDI_errors_filename" + ); + modalTitleSpan.textContent = filename; + + // Update the modal's content + const modalBody = errorsModal.querySelector(".modal-body"); + modalBody.innerHTML = errors; + }); + } +}); -- 2.50.0