From 5e43f52e39c4241c87f27622dfd71c7355bc49a6 Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Fri, 29 Nov 2024 09:16:35 +0000
Subject: [PATCH] Bug 37993: Replace edi_ean link with dropdown

The edi_ean page is a slim page with a single select input for selecting
the appropriate library and ean.  This patch replaces the link to that
page with a simple select in the menu on the original page instead.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
---
 acqui/basket.pl                               | 12 ++++++-
 .../prog/en/modules/acqui/basket.tt           | 33 +++++++++++++++----
 2 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/acqui/basket.pl b/acqui/basket.pl
index 1a6ef3ca478..b9715babc85 100755
--- a/acqui/basket.pl
+++ b/acqui/basket.pl
@@ -94,7 +94,17 @@ my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
 my $schema = Koha::Database->new()->schema();
 my $rs = $schema->resultset('VendorEdiAccount')->search(
     { vendor_id => $booksellerid, } );
-$template->param( ediaccount => ($rs->count > 0));
+my $ediaccount = ( $rs->count > 0 );
+$template->param( ediaccount => $ediaccount );
+if ($ediaccount) {
+    my @eans = $schema->resultset('EdifactEan')->search(
+        {},
+        {
+            join => 'branch',
+        }
+    );
+    $template->param( eans => \@eans );
+}
 
 unless (CanUserManageBasket($loggedinuser, $basket, $userflags)) {
     $template->param(
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 b7df301861d..66cbcc6419e 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt
@@ -110,13 +110,32 @@
                                         [% PROCESS csv_export %]
 
                                         [% IF Koha.Preference('EDIFACT') && ediaccount %]
-                                            <div class="btn-group"><form action="/cgi-bin/koha/acqui/edi_ean.pl" method="post">
-                                                [% INCLUDE 'csrf-token.inc' %]
-                                                <input type="hidden" name="op" value="cud-ediorder" />
-                                                <input type="hidden" name="basketno" value="[% basketno | html %]" />
-                                                <input type="hidden" name="booksellerid" value="[% booksellerid | html %]" />
-                                                <button type="submit" class="btn btn-default" id="ediorderbutton"><i class="fa fa-download"></i> Create EDIFACT order</button>
-                                            </form></div>
+                                            <div class="btn-group">
+                                                [% IF eans.count == 1 %]
+                                                    <form action="/cgi-bin/koha/acqui/basket.pl" method="post">
+                                                        [% INCLUDE 'csrf-token.inc' %]
+                                                        <input type="hidden" name="op" value="cud-ediorder" />
+                                                        <input type="hidden" name="basketno" value="[% basketno | html %]" />
+                                                        <input type="hidden" name="ean" value="[% eans.0 | html %]" />
+                                                        <button type="submit" class="btn btn-default" id="ediorderbutton"><i class="fa fa-download"></i> Create EDIFACT order</button>
+                                                    </form>
+                                                [% ELSE %]
+                                                    <button class="btn btn-default dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" id="ediorderbutton"><i class="fa fa-download"></i> Create EDIFACT order</button>
+                                                    <ul class="dropdown-menu">
+                                                        [% FOREACH eanacct IN eans %]
+                                                        <li>
+                                                        <form action="/cgi-bin/koha/acqui/basket.pl" method="post">
+                                                            [% INCLUDE 'csrf-token.inc' %]
+                                                            <input type="hidden" id="basketno" value="[% basketno | html %]" name="basketno" />
+                                                            <input type="hidden" value="cud-ediorder" name="op" />
+                                                            <input type="hidden" name="ean" value="[% eanacct.ean | html %]">
+                                                            <button type="submit" class="btn btn-default">[% eanacct.branch.branchname | html %] ([% eanacct.ean | html %]) [% IF eanacct.description %][[% eanacct.description | html %]][% END %]</button>
+                                                        </form>
+                                                        </li>
+                                                        [% END %]
+                                                    </ul>
+                                                [% END %]
+                                            </div>
                                         [% END %]
 
                                         [% IF ( active && books_loop ) %]
-- 
2.39.3 (Apple Git-146)