Bug 30563: Add syspref to make the "cash register" field mandatory
authorJulian Maurice <julian.maurice@biblibre.com>
Fri, 15 Apr 2022 08:01:00 +0000 (10:01 +0200)
committerFridolin Somers <fridolin.somers@biblibre.com>
Fri, 6 May 2022 20:33:09 +0000 (10:33 -1000)
Test plan:
1. Apply patch and run updatedatabase
2. Enable 'UseCashRegisters' syspref and create at least one cash
   register for your library
3. Verify that you have several authorized values in the 'PAYMENT_TYPE'
   category. One of them should be 'CASH'
4. Go to a patron accounting tab, create a manual invoice and go to the
   payment form. Select payment type 'CASH' and verify that you cannot
   submit the form if no cash register is selected.
   Select another payment type and verify that you can submit the form
   even if no cash register is selected
5. Set syspref 'RequireCashRegister' to 'always require a cash register'
6. Repeat step 4 but this time you should not be able to submit the form
   if no cash register is selected, no matter which payment type is
   selected.

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
installer/data/mysql/atomicupdate/add-syspref-RequireCashRegister.pl [new file with mode: 0644]
installer/data/mysql/mandatory/sysprefs.sql
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/accounting.pref
koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt

diff --git a/installer/data/mysql/atomicupdate/add-syspref-RequireCashRegister.pl b/installer/data/mysql/atomicupdate/add-syspref-RequireCashRegister.pl
new file mode 100644 (file)
index 0000000..da878d4
--- /dev/null
@@ -0,0 +1,17 @@
+use Modern::Perl;
+
+return {
+    bug_number => '30563',
+    description => 'Add system preference RequireCashRegister',
+    up => sub {
+        my ($args) = @_;
+        my ($dbh, $out) = @$args{qw(dbh out)};
+
+        $dbh->do(q{
+            INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`)
+            VALUES ('RequireCashRegister', '0', NULL, 'Require a cash register when collecting a payment', 'YesNo')
+        });
+
+        say $out 'System preference RequireCashRegister added';
+    },
+};
index 63f05a4..2b7259e 100644 (file)
@@ -569,6 +569,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('RentalsInNoissuesCharge','1',NULL,'Rental charges block checkouts (added to noissuescharge).','YesNo'),
 ('ReplyToDefault','',NULL,'Use this email address as the replyto in emails','Free'),
 ('ReportsLog','0',NULL,'If ON, log information about reports.','YesNo'),
+('RequireCashRegister','0',NULL,'Require a cash register when collecting a payment','YesNo'),
 ('RequirePaymentType','0','','Require staff to select a payment type when a payment is made','YesNo'),
 ('RequireStrongPassword','1','','Require a strong login password for staff and patrons','YesNo'),
 ('ReservesControlBranch','PatronLibrary','ItemHomeLibrary|PatronLibrary','Branch checked for members reservations rights','Choice'),
index fdede78..2ba1631 100644 (file)
@@ -34,6 +34,14 @@ Accounting:
                 0: "Don't use"
             - " cash registers with the accounting system to track payments."
         -
+            - "When collecting a payment, "
+            - pref: RequireCashRegister
+              default: no
+              choices:
+                no: "require a cash register only when the CASH payment type is selected"
+                yes: "always require a cash register"
+            - " (Requires UseCashRegisters)"
+        -
             - pref: EnablePointOfSale
               default: no
               choices:
index 3b493c2..b153e3b 100644 (file)
 
     [% IF Koha.Preference('UseCashRegisters') %]
     <li>
-        <label for="cash_register">Cash register: </label>
-        <select name="cash_register" id="cash_register">
+        [% IF Koha.Preference('RequireCashRegister') %]
+            <label for="cash_register" class="required">
+        [% ELSE %]
+            <label for="cash_register">
+        [% END %]
+            Cash register:
+        </label>
+
+        [% IF Koha.Preference('RequireCashRegister') %]
+            <select name="cash_register" id="cash_register" required>
+        [% ELSE %]
+            <select name="cash_register" id="cash_register">
+        [% END %]
             <option id="noregister" disabled selected="selected" value="">-- Select an option--</option>
             [% PROCESS options_for_registers %]
         </select>
+
+        [% IF Koha.Preference('RequireCashRegister') %]
+            <span class="required">Required</span>
+        [% END %]
     </li>
     [% END %]
 </ol>
                     },
                     [% IF Koha.Preference('UseCashRegisters') %]
                     cash_register: {
-                        required: function() {
-                            return $('#payment_type').val() == 'CASH'
-                        }
+                        [% IF Koha.Preference('RequireCashRegister') %]
+                            required: true
+                        [% ELSE %]
+                            required: function() {
+                                return $('#payment_type').val() == 'CASH'
+                            }
+                        [% END %]
                     }
                     [% END %]
                 },