From f0f5fc006f4fdc05b5acb23fe728d01add006fae Mon Sep 17 00:00:00 2001
From: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Date: Fri, 18 Oct 2024 14:48:34 +0000
Subject: [PATCH] Bug 38207: Add a new payment_method column to aqbooksellers

(cherry picked from commit 881f96172a8c1b35d3e74f7f0f6aa44629578021)
---
 .../bug_38207-add-vendor-payment-method.pl    | 41 +++++++++++++++++++
 installer/data/mysql/kohastructure.sql        |  1 +
 .../vue/components/Vendors/VendorFormAdd.vue  |  9 ++++
 3 files changed, 51 insertions(+)
 create mode 100644 installer/data/mysql/atomicupdate/bug_38207-add-vendor-payment-method.pl

diff --git a/installer/data/mysql/atomicupdate/bug_38207-add-vendor-payment-method.pl b/installer/data/mysql/atomicupdate/bug_38207-add-vendor-payment-method.pl
new file mode 100644
index 00000000000..13adc1bb811
--- /dev/null
+++ b/installer/data/mysql/atomicupdate/bug_38207-add-vendor-payment-method.pl
@@ -0,0 +1,41 @@
+use Modern::Perl;
+use Koha::Installer::Output qw(say_warning say_failure say_success say_info);
+
+return {
+    bug_number  => "38207",
+    description => "Add a payment method to the vendor table",
+    up          => sub {
+        my ($args) = @_;
+        my ( $dbh, $out ) = @$args{qw(dbh out)};
+
+        unless ( column_exists( 'aqbooksellers', 'payment_method' ) ) {
+            $dbh->do(
+                q{
+                    ALTER TABLE aqbooksellers
+                        ADD COLUMN `payment_method` varchar(255) NULL DEFAULT NULL
+                        COMMENT 'the payment method for the vendor'
+                        AFTER external_id
+            }
+            );
+
+            say $out "Added new column 'aqbooksellers.payment_method'";
+        }
+
+        $dbh->do(
+            q{
+            INSERT IGNORE INTO authorised_value_categories( category_name, is_system ) VALUES ('VENDOR_PAYMENT_METHOD', 1);
+        }
+        );
+        say $out "Added VENDOR_PAYMENT_METHOD authorised value category";
+
+        $dbh->do(
+            q{
+            INSERT IGNORE INTO authorised_values (category, authorised_value, lib)
+            VALUES
+                ('VENDOR_PAYMENT_METHOD', 'card', 'Card'),
+                ('VENDOR_PAYMENT_METHOD', 'bacs', 'BACS');
+        }
+        );
+        say $out "Added Card and BACS to VENDOR_PAYMENT_METHODS authorised value category";
+    },
+};
diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index d3686595715..428010e612d 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -502,6 +502,7 @@ CREATE TABLE `aqbooksellers` (
   `fax` varchar(50) DEFAULT NULL COMMENT 'vendor fax number',
   `deliverytime` int(11) DEFAULT NULL COMMENT 'vendor delivery time',
   `external_id` varchar(255) DEFAULT NULL COMMENT 'external id of the vendor',
+  `payment_method` varchar(255) DEFAULT NULL COMMENT 'the payment method for the vendor',
   PRIMARY KEY (`id`),
   KEY `listprice` (`listprice`),
   KEY `invoiceprice` (`invoiceprice`),
diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorFormAdd.vue
index 333b453206c..a1663b61102 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorFormAdd.vue
+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorFormAdd.vue
@@ -89,6 +89,9 @@ export default {
                     vendor.address3 && (physical += vendor.address3 + "\n")
                     vendor.address4 && (physical += vendor.address4 + "\n")
                     this.vendor.physical = physical
+                    this.vendor.payment_method = vendor.payment_method
+                        ? vendor.payment_method.split("|")
+                        : []
                     this.initialized = true
                 },
                 error => {}
@@ -123,6 +126,12 @@ export default {
                     requiredProperties
             )
 
+            if (vendor.payment_method && vendor.payment_method.length > 0) {
+                vendor.payment_method = vendor.payment_method.join("|")
+            } else {
+                vendor.payment_method = null
+            }
+
             const client = APIClient.acquisition
             if (vendorId) {
                 client.vendors.update(vendor, vendorId).then(
-- 
2.39.3 (Apple Git-146)