From e21946bbfdcf6e3b3af5abf136c6889ee6ef9ee3 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 8 Apr 2020 10:39:28 -0400 Subject: [PATCH] Bug 24380: Add syspref CalculateFinesOnBackdate --- C4/Circulation.pm | 6 +++++- installer/data/mysql/atomicupdate/bug_24380.perl | 9 +++++++++ installer/data/mysql/sysprefs.sql | 1 + .../prog/en/modules/admin/preferences/circulation.pref | 6 ++++++ t/db_dependent/Circulation/Returns.t | 3 ++- 5 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_24380.perl diff --git a/C4/Circulation.pm b/C4/Circulation.pm index bb419867d9..527b878858 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -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 index 0000000000..b5cb55f8a4 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_24380.perl @@ -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"); +} diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index a15c4c6c95..a83e6bd479 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -108,6 +108,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'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index d9823c74a6..cca99d52d6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -546,6 +546,12 @@ Circulation: - calculate and update overdue charges when an item is returned. - "
NOTE: If you are doing hourly loans then you should have this on." - "
NOTE: This system preference requires FinesMode to be set to 'Calculate and charge.'" + - + - 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 diff --git a/t/db_dependent/Circulation/Returns.t b/t/db_dependent/Circulation/Returns.t index 74ac815a98..eadaa9f6af 100644 --- a/t/db_dependent/Circulation/Returns.t +++ b/t/db_dependent/Circulation/Returns.t @@ -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( -- 2.24.1 (Apple Git-126)