From 05bd295d7126d97c70d19ff7c26561e3e5aff15f Mon Sep 17 00:00:00 2001
From: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Date: Mon, 15 Jul 2024 14:17:40 +0000
Subject: [PATCH] Bug 28924: Add new columns to UI and controller

This patch adds the columns in the table and also updates the controller to allow these fields to be updated in the database from the UI form

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>
---
 admin/categories.pl                           | 101 ++++++++++--------
 .../prog/en/modules/admin/categories.tt       |  30 ++++++
 2 files changed, 86 insertions(+), 45 deletions(-)

diff --git a/admin/categories.pl b/admin/categories.pl
index c89fce0fbaf..7f98c6c3382 100755
--- a/admin/categories.pl
+++ b/admin/categories.pl
@@ -57,28 +57,31 @@ if ( $op eq 'add_form' ) {
     }
 }
 elsif ( $op eq 'cud-add_validate' ) {
+    my $categorycode                           = $input->param('categorycode');
+    my $description                            = $input->param('description');
+    my $enrolmentperiod                        = $input->param('enrolmentperiod');
+    my $enrolmentperioddate                    = $input->param('enrolmentperioddate')  || undef;
+    my $password_expiry_days                   = $input->param('password_expiry_days') || undef;
+    my $upperagelimit                          = $input->param('upperagelimit');
+    my $dateofbirthrequired                    = $input->param('dateofbirthrequired');
+    my $enrolmentfee                           = $input->param('enrolmentfee');
+    my $reservefee                             = $input->param('reservefee');
+    my $hidelostitems                          = $input->param('hidelostitems');
+    my $overduenoticerequired                  = $input->param('overduenoticerequired');
+    my $category_type                          = $input->param('category_type');
+    my $BlockExpiredPatronOpacActions          = join( ',', $input->multi_param('BlockExpiredPatronOpacActions') );
+    my $checkPrevCheckout                      = $input->param('checkprevcheckout');
+    my $can_place_ill_in_opac                  = $input->param('can_place_ill_in_opac') // 1;
+    my $default_privacy                        = $input->param('default_privacy');
+    my $reset_password                         = $input->param('reset_password');
+    my $change_password                        = $input->param('cud-change_password');
+    my $exclude_from_local_holds_priority      = $input->param('exclude_from_local_holds_priority');
+    my $min_password_length                    = $input->param('min_password_length');
+    my $require_strong_password                = $input->param('require_strong_password');
+    my $noissuescharge                         = $input->param('noissuescharge') || undef;
+    my $noissueschargeguarantees               = $input->param('noissueschargeguarantees') || undef;
+    my $noissueschargeguarantorswithguarantees = $input->param('noissueschargeguarantorswithguarantees') || undef;
 
-    my $categorycode = $input->param('categorycode');
-    my $description = $input->param('description');
-    my $enrolmentperiod = $input->param('enrolmentperiod');
-    my $enrolmentperioddate = $input->param('enrolmentperioddate') || undef;
-    my $password_expiry_days = $input->param('password_expiry_days') || undef;
-    my $upperagelimit = $input->param('upperagelimit');
-    my $dateofbirthrequired = $input->param('dateofbirthrequired');
-    my $enrolmentfee = $input->param('enrolmentfee');
-    my $reservefee = $input->param('reservefee');
-    my $hidelostitems = $input->param('hidelostitems');
-    my $overduenoticerequired = $input->param('overduenoticerequired');
-    my $category_type = $input->param('category_type');
-    my $BlockExpiredPatronOpacActions = join( ',', $input->multi_param('BlockExpiredPatronOpacActions') );
-    my $checkPrevCheckout = $input->param('checkprevcheckout');
-    my $can_place_ill_in_opac = $input->param('can_place_ill_in_opac') // 1;
-    my $default_privacy = $input->param('default_privacy');
-    my $reset_password = $input->param('reset_password');
-    my $change_password = $input->param('cud-change_password');
-    my $exclude_from_local_holds_priority = $input->param('exclude_from_local_holds_priority');
-    my $min_password_length = $input->param('min_password_length');
-    my $require_strong_password = $input->param('require_strong_password');
     my @branches = grep { $_ ne q{} } $input->multi_param('branches');
     my $can_be_guarantee = $input->param('can_be_guarantee');
 
@@ -113,6 +116,9 @@ elsif ( $op eq 'cud-add_validate' ) {
         $category->exclude_from_local_holds_priority($exclude_from_local_holds_priority);
         $category->min_password_length($min_password_length);
         $category->require_strong_password($require_strong_password);
+        $category->noissuescharge($noissuescharge);
+        $category->noissueschargeguarantees($noissueschargeguarantees);
+        $category->noissueschargeguarantorswithguarantees($noissueschargeguarantorswithguarantees);
         eval {
             $category->store;
             $category->replace_library_limits( \@branches );
@@ -124,30 +130,35 @@ elsif ( $op eq 'cud-add_validate' ) {
         }
     }
     else {
-        my $category = Koha::Patron::Category->new({
-            categorycode => $categorycode,
-            description => $description,
-            enrolmentperiod => $enrolmentperiod,
-            enrolmentperioddate => $enrolmentperioddate,
-            password_expiry_days => $password_expiry_days,
-            upperagelimit => $upperagelimit,
-            dateofbirthrequired => $dateofbirthrequired,
-            enrolmentfee => $enrolmentfee,
-            reservefee => $reservefee,
-            hidelostitems => $hidelostitems,
-            overduenoticerequired => $overduenoticerequired,
-            category_type => $category_type,
-            can_be_guarantee => $can_be_guarantee,
-            BlockExpiredPatronOpacActions => $BlockExpiredPatronOpacActions,
-            checkprevcheckout => $checkPrevCheckout,
-            can_place_ill_in_opac => $can_place_ill_in_opac,
-            default_privacy => $default_privacy,
-            reset_password => $reset_password,
-            change_password => $change_password,
-            exclude_from_local_holds_priority => $exclude_from_local_holds_priority,
-            min_password_length => $min_password_length,
-            require_strong_password => $require_strong_password,
-        });
+        my $category = Koha::Patron::Category->new(
+            {
+                categorycode                           => $categorycode,
+                description                            => $description,
+                enrolmentperiod                        => $enrolmentperiod,
+                enrolmentperioddate                    => $enrolmentperioddate,
+                password_expiry_days                   => $password_expiry_days,
+                upperagelimit                          => $upperagelimit,
+                dateofbirthrequired                    => $dateofbirthrequired,
+                enrolmentfee                           => $enrolmentfee,
+                reservefee                             => $reservefee,
+                hidelostitems                          => $hidelostitems,
+                overduenoticerequired                  => $overduenoticerequired,
+                category_type                          => $category_type,
+                can_be_guarantee                       => $can_be_guarantee,
+                BlockExpiredPatronOpacActions          => $BlockExpiredPatronOpacActions,
+                checkprevcheckout                      => $checkPrevCheckout,
+                can_place_ill_in_opac                  => $can_place_ill_in_opac,
+                default_privacy                        => $default_privacy,
+                reset_password                         => $reset_password,
+                change_password                        => $change_password,
+                exclude_from_local_holds_priority      => $exclude_from_local_holds_priority,
+                min_password_length                    => $min_password_length,
+                require_strong_password                => $require_strong_password,
+                noissuescharge                         => $noissuescharge,
+                noissueschargeguarantees               => $noissueschargeguarantees,
+                noissueschargeguarantorswithguarantees => $noissueschargeguarantorswithguarantees,
+            }
+        );
         eval {
             $category->store;
             $category->replace_library_limits( \@branches );
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt
index 5f6b18fe8be..89fa8070ef2 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt
@@ -445,6 +445,18 @@
                     </select>
                     <div class="hint">If <i>Yes</i>, holds placed by patrons of this category will not be given priority</div>
                 </li>
+                <li>
+                    <label for="noissuescharge">No issues charge: </label>
+                    <input type="text" name="noissuescharge" id="noissuescharge" value="[% category.noissuescharge | html %]" size="3" maxlength="3" />
+                </li>
+                <li>
+                    <label for="noissueschargeguarantees">No issues charge guarantees: </label>
+                    <input type="text" name="noissueschargeguarantees" id="noissueschargeguarantees" value="[% category.noissueschargeguarantees | html %]" size="3" maxlength="3" />
+                </li>
+                <li>
+                    <label for="noissueschargeguarantorswithguarantees">No issues charge guarantors with guarantees: </label>
+                    <input type="text" name="noissueschargeguarantorswithguarantees" id="noissueschargeguarantorswithguarantees" value="[% category.noissueschargeguarantorswithguarantees | html %]" size="3" maxlength="3" />
+                </li>
             </ol>
         </fieldset>
 
@@ -590,6 +602,9 @@
                     <th scope="col">Can be guarantee</th>
                     <th scope="col">Default privacy</th>
                     <th scope="col">Exclude from local holds priority</th>
+                    <th scope="col">No issues charge</th>
+                    <th scope="col">No issues charge guarantees</th>
+                    <th scope="col">No issues charge guarantors with guarantees</th>
                     <th scope="col">Actions</th>
                 </tr>
             </thead>
@@ -727,6 +742,21 @@
                                 <span>No</span>
                             [% END %]
                         </td>
+                        [% IF (category.noissuescharge) %]
+                            <td>[% category.noissuescharge | html %]</td>
+                        [% ELSE %]
+                            <td>0.00</td>
+                        [% END %]
+                        [% IF (category.noissueschargeguarantees) %]
+                            <td>[% category.noissueschargeguarantees | html %]</td>
+                        [% ELSE %]
+                            <td>0.00</td>
+                        [% END %]
+                        [% IF (category.noissueschargeguarantorswithguarantees) %]
+                            <td>[% category.noissueschargeguarantorswithguarantees | html %]</td>
+                        [% ELSE %]
+                            <td>0.00</td>
+                        [% END %]
                         <td class="actions">
                             <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/categories.pl?op=add_form&amp;categorycode=[% category.categorycode |uri %]"><i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit</a>
                             <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/categories.pl?op=delete_confirm&amp;categorycode=[% category.categorycode |uri %]"><i class="fa fa-trash-can"></i> Delete</a>
-- 
2.39.3 (Apple Git-146)