Bug 24380: Add syspref CalculateFinesOnBackdate
authorKyle M Hall <kyle@bywatersolutions.com>
Wed, 8 Apr 2020 14:39:28 +0000 (10:39 -0400)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Wed, 15 Apr 2020 11:28:39 +0000 (12:28 +0100)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

C4/Circulation.pm
installer/data/mysql/atomicupdate/bug_24380.perl [new file with mode: 0644]
installer/data/mysql/sysprefs.sql
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
t/db_dependent/Circulation/Returns.t

index bb41986..527b878 100644 (file)
@@ -1973,7 +1973,11 @@ sub AddReturn {
                 MarkIssueReturned( $borrowernumber, $item->itemnumber, $return_date, $patron->privacy );
             };
             unless ( $@ ) {
-                if ( ( $return_date_specified || C4::Context->preference('CalculateFinesOnReturn') ) && !$item->itemlost ) {
+                my $calc_fine = C4::Context->preference('CalculateFinesOnReturn');
+                $calc_fine ||= $return_date_specified && C4::Context->preference('CalculateFinesOnBackdate');
+                $calc_fine &&= !$item->itemlost;
+
+                if ( $calc_fine ) {
                     _CalculateAndUpdateFine( { issue => $issue, item => $item->unblessed, borrower => $patron_unblessed, return_date => $return_date } );
                 }
             } else {
diff --git a/installer/data/mysql/atomicupdate/bug_24380.perl b/installer/data/mysql/atomicupdate/bug_24380.perl
new file mode 100644 (file)
index 0000000..b5cb55f
--- /dev/null
@@ -0,0 +1,9 @@
+$DBversion = 'XXX'; # will be replaced by the RM
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q{
+        INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
+        ('CalculateFinesOnBackdate','1','','Switch to control if overdue fines are calculated on return when backdating','YesNo');
+    });
+
+    NewVersion( $DBversion, 24380, "Add syspref CalculateFinesOnBackdate");
+}
index d4e5211..2c5b01f 100644 (file)
@@ -110,6 +110,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('BranchTransferLimitsType','ccode','itemtype|ccode','When using branch transfer limits, choose whether to limit by itemtype or collection code.','Choice'),
 ('BrowseResultSelection','0',NULL,'Enable/Disable browsing search results fromt the bibliographic record detail page in staff client','YesNo'),
 ('CalculateFinesOnReturn','1','','Switch to control if overdue fines are calculated on return or not','YesNo'),
+('CalculateFinesOnBackdate','1','','Switch to control if overdue fines are calculated on return when backdating','YesNo'),
 ('CalendarFirstDayOfWeek','0','0|1|2|3|4|5|6','Select the first day of week to use in the calendar.','Choice'),
 ('CanMarkHoldsToPullAsLost','do_not_allow','do_not_allow|allow|allow_and_notify','Add a button to the "Holds to pull" screen to mark an item as lost and notify the patron.','Choice'),
 ('canreservefromotherbranches','1','','With Independent branches on, can a user from one library place a hold on an item from another library','YesNo'),
index d9823c7..cca99d5 100644 (file)
@@ -547,6 +547,12 @@ Circulation:
             - "<br /><strong>NOTE: If you are doing hourly loans then you should have this on.</strong>"
             - "<br /><strong>NOTE: This system preference requires FinesMode to be set to 'Calculate and charge.'</strong>"
         -
+            - pref: CalculateFinesOnBackdate
+              choices:
+                  yes: Do
+                  no: "Don't"
+            - calculate and update overdue charges when an item is returned with a backdated return date.
+        -
             - pref: UpdateItemLocationOnCheckin
               type: textarea
               syntax: text/x-yaml
index 74ac815..eadaa9f 100644 (file)
@@ -402,7 +402,8 @@ subtest 'BranchTransferLimitsType' => sub {
 subtest 'Backdated returns should reduce fine if needed' => sub {
     plan tests => 1;
 
-    t::lib::Mocks::mock_preference( "CalculateFinesOnReturn", 0 );
+    t::lib::Mocks::mock_preference( "CalculateFinesOnReturn",   0 );
+    t::lib::Mocks::mock_preference( "CalculateFinesOnBackdate", 1 );
 
     my $biblio = $builder->build_object( { class => 'Koha::Biblios' } );
     my $item = $builder->build_object(