From b0887cd162a5bc4f6274d33d24b9b19d7915c48f Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 21 Nov 2012 14:54:17 -0500 Subject: [PATCH] Bug 9129 - Add the ability to set the maximum fine for an item to its replacement price Content-Type: text/plain; charset="utf-8" Test plan: 1) Apply patch 2) Run updatedatabase.pl 3) Enable MaxFineIsReplacementPrice 4) Pick an item, set it's replacementprice to some amount ( e.g. $6.50 ) 5) Check it out to a patron, back date the due date by an amount such that the fine should exceed the replacement price ( a year ago should be good ). 6) Run fines.pl 7) Verify the fine for the item is not exceeded the replacement price. Signed-off-by: Chris Cormack Make sure that you also have maximum fine amount to be higher than the replacement price you set, otherwise it will stop at that amount. Signed-off-by: Marcel de Rooy --- C4/Overdues.pm | 16 +++++++++++++++- installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 7 +++++++ .../prog/en/modules/admin/preferences/patrons.pref | 6 ++++++ 4 files changed, 29 insertions(+), 1 deletions(-) diff --git a/C4/Overdues.pm b/C4/Overdues.pm index 80771ae..544a855 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -272,8 +272,12 @@ sub CalcFine { } else { # a zero (or null) chargeperiod or negative units_minus_grace value means no charge. } + $amount = $data->{overduefinescap} if $data->{overduefinescap} && $amount > $data->{overduefinescap}; + $amount = $item->{'replacementprice'} if ( C4::Context->preference('MaxFineIsReplacementPrice') && $item->{'replacementprice'} && $amount > $item->{'replacementprice'} ); + $debug and warn sprintf("CalcFine returning (%s, %s, %s, %s)", $amount, $data->{'chargename'}, $units_minus_grace, $chargeable_units); + return ($amount, $data->{'chargename'}, $units_minus_grace, $chargeable_units); # FIXME: chargename is NEVER populated anywhere. } @@ -546,16 +550,26 @@ sub UpdateFine { } $total_amount_other += $rec->{'amount'}; } + + if ( C4::Context->preference('MaxFineIsReplacementPrice') ) { + my $item = C4::Items::GetItem( $itemnum ); + if ( $item->{'replacementprice'} && $amount > $item->{'replacementprice'} ) { + $debug && warn "Reducing fine for item $itemnum borrower $borrowernumber from $amount to $item->{'replacementprice'} - Fine exceeds replacement price"; + $amount = $item->{'replacementprice'}; + } + } + if (my $maxfine = C4::Context->preference('MaxFine')) { if ($total_amount_other + $amount > $maxfine) { my $new_amount = $maxfine - $total_amount_other; - warn "Reducing fine for item $itemnum borrower $borrowernumber from $amount to $new_amount - MaxFine reached"; + $debug && warn "Reducing fine for item $itemnum borrower $borrowernumber from $amount to $new_amount - MaxFine reached"; return if $new_amount <= 0.00; $amount = $new_amount; } } + if ( $data ) { # we're updating an existing fine. Only modify if amount changed diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index e3966ce..d953206 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -421,3 +421,4 @@ INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES( INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('PatronSelfRegistrationAdditionalInstructions','','A free text field to display additional instructions to newly self registered patrons.','','free'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('UseQueryParser', '0', 'If enabled, try to use QueryParser for queries.', NULL, 'YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('FinesIncludeGracePeriod','1','If enabled, fines calculations will include the grace period.',NULL,'YesNo'); +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('MaxFineIsReplacementPrice',0,'Make the replacement price a second max fine ceiling.',NULL,'YesNo'); diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index cca1b12..60a7db2 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -6526,6 +6526,13 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.11.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('MaxFineIsReplacementPrice',0,'Make the replacement price a second max fine ceiling.',NULL,'YesNo')"); + print "Upgrade to $DBversion done (Bug 9129: Add syspref MaxFineIsReplacementPrice)\n"; + SetVersion ($DBversion); +} + =head1 FUNCTIONS diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref index 74d14af..33cb821 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref @@ -80,6 +80,12 @@ Patrons: - '[% local_currency %].' - Empty value means no limit. Single item caps are specified in the circulation rules matrix. - + - pref: MaxFineIsReplacementPrice + choices: + yes: Allow + no: "Don't allow" + - the maximum fine for an item to exceed the replacement price for that item. + - - pref: memberofinstitution choices: yes: Do -- 1.7.7.6