From 6f33d22bfd528a827b1490e0f56d17763f6e60ec Mon Sep 17 00:00:00 2001
From: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Date: Mon, 22 Jan 2024 12:14:02 +0000
Subject: [PATCH] Bug 28924: Add 3 new columns to categories table

This patch adds three new columns to the patron categories table:
noissuescharge
noissueschargegurantees
noissueschargeguarantorswithguarantees

These values will allow charge limits to be set at category level rather than globally for all patrons. If the values are not set at category level then the system will use the global level values

Sponsored-by: Cuyahoga County Public Library <https://cuyahogalibrary.org/>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
---
 .../atomicupdate/bug_28924-noissuescharges.pl | 30 +++++++++++++++++++
 installer/data/mysql/kohastructure.sql        |  3 ++
 2 files changed, 33 insertions(+)
 create mode 100755 installer/data/mysql/atomicupdate/bug_28924-noissuescharges.pl

diff --git a/installer/data/mysql/atomicupdate/bug_28924-noissuescharges.pl b/installer/data/mysql/atomicupdate/bug_28924-noissuescharges.pl
new file mode 100755
index 00000000000..d3ca993ffe7
--- /dev/null
+++ b/installer/data/mysql/atomicupdate/bug_28924-noissuescharges.pl
@@ -0,0 +1,30 @@
+use Modern::Perl;
+
+return {
+    bug_number  => "28924",
+    description => "Adds columns to patron categories to allow category level values for the no issue charge sysprefs",
+    up          => sub {
+        my ($args) = @_;
+        my ( $dbh, $out ) = @$args{qw(dbh out)};
+
+        unless ( column_exists( 'categories', 'noissuescharge' ) ) {
+            $dbh->do(
+                q{ ALTER TABLE categories ADD COLUMN `noissuescharge` int(11) AFTER `exclude_from_local_holds_priority` }
+            );
+
+            say $out "Added column 'noissuescharge' to categories";
+        }
+        unless ( column_exists( 'categories', 'noissueschargeguarantees' ) ) {
+            $dbh->do(q{ ALTER TABLE categories ADD COLUMN `noissueschargeguarantees` int(11) AFTER `noissuescharge` });
+
+            say $out "Added column 'noissueschargeguarantees' to categories";
+        }
+        unless ( column_exists( 'categories', 'noissueschargeguarantorswithguarantees' ) ) {
+            $dbh->do(
+                q{ ALTER TABLE categories ADD COLUMN `noissueschargeguarantorswithguarantees` int(11) AFTER `noissueschargeguarantees` }
+            );
+
+            say $out "Added column 'noissueschargeguarantorswithguarantees' to categories";
+        }
+    },
+};
diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index 14cef909b3a..bde40b17591 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -1806,6 +1806,9 @@ CREATE TABLE `categories` (
   `min_password_length` smallint(6) DEFAULT NULL COMMENT 'set minimum password length for patrons in this category',
   `require_strong_password` tinyint(1) DEFAULT NULL COMMENT 'set required password strength for patrons in this category',
   `exclude_from_local_holds_priority` tinyint(1) DEFAULT NULL COMMENT 'Exclude patrons of this category from local holds priority',
+  `noissuescharge` int(11) DEFAULT NULL COMMENT 'define maximum amount withstanding before checkouts are blocked',
+  `noissueschargeguarantees` int(11) DEFAULT NULL COMMENT 'define maximum amount withstanding before checkouts are blocked',
+  `noissueschargeguarantorswithguarantees` int(11) DEFAULT NULL COMMENT 'define maximum amount withstanding before checkouts are blocked',
   PRIMARY KEY (`categorycode`),
   UNIQUE KEY `categorycode` (`categorycode`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- 
2.39.2