Bugzilla – Attachment 43747 Details for
Bug 9129
Add the ability to set the maximum fine for an item to its replacement price
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 9129 - Add the ability to set the maximum fine for an item to its replacement price
Bug-9129---Add-the-ability-to-set-the-maximum-fine.patch (text/plain), 16.40 KB, created by
Kyle M Hall (khall)
on 2015-10-22 10:41:03 UTC
(
hide
)
Description:
Bug 9129 - Add the ability to set the maximum fine for an item to its replacement price
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2015-10-22 10:41:03 UTC
Size:
16.40 KB
patch
obsolete
>From 44c36569caacc4f7a2cbb89e3f833f49d79b8a68 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Thu, 22 Oct 2015 06:40:12 -0400 >Subject: [PATCH] Bug 9129 - Add the ability to set the maximum fine for an item to its replacement price > >This patch adds the ability to set the maximum fine for a given item to >its replacement price ( assuming the replacement price is set ). If >overduefinescap is also set, the fine will be the lesser of the two, if >both apply to the given overdue checkout. > >To enable this new limit, create or edit your circulation rules and >check the checkbox for "Cap fines at replacement price" > >Test Plan: >1) Apply this patch >2) Run updatedatabase.pl >3) Pick an item, and set it's replacement price to 3.99 >4) Edit the circulation rule that would apply to this item > and the patron you will check it out to. >5) Check out the item to the patron, and backdate the due date > such that the fine generated would be more than 3.99 >6) Enable CalculateFinesOnReturn >7) Return the item, and view the fine generated, it should be 3.99 > >Signed-off-by: Cindy Murdock Ames <cmurdock@ccfls.org> >--- > C4/Overdues.pm | 5 +- > admin/smart-rules.pl | 52 ++++---- > .../prog/en/modules/admin/smart-rules.tt | 45 +++++-- > t/db_dependent/Circulation/CalcFine.t | 146 ++++++++++++++++++++ > 4 files changed, 209 insertions(+), 39 deletions(-) > create mode 100644 t/db_dependent/Circulation/CalcFine.t > >diff --git a/C4/Overdues.pm b/C4/Overdues.pm >index 80c6be0..a07b7d3 100644 >--- a/C4/Overdues.pm >+++ b/C4/Overdues.pm >@@ -112,14 +112,14 @@ sub Getoverdues { > my $statement; > if ( C4::Context->preference('item-level_itypes') ) { > $statement = " >- SELECT issues.*, items.itype as itemtype, items.homebranch, items.barcode, items.itemlost >+ SELECT issues.*, items.itype as itemtype, items.homebranch, items.barcode, items.itemlost, items.replacementprice > FROM issues > LEFT JOIN items USING (itemnumber) > WHERE date_due < NOW() > "; > } else { > $statement = " >- SELECT issues.*, biblioitems.itemtype, items.itype, items.homebranch, items.barcode, items.itemlost >+ SELECT issues.*, biblioitems.itemtype, items.itype, items.homebranch, items.barcode, items.itemlost, replacementprice > FROM issues > LEFT JOIN items USING (itemnumber) > LEFT JOIN biblioitems USING (biblioitemnumber) >@@ -264,6 +264,7 @@ 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 ( $data->{cap_fine_to_replacement_price} && $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. >diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl >index de090cb..435b7b4 100755 >--- a/admin/smart-rules.pl >+++ b/admin/smart-rules.pl >@@ -132,36 +132,38 @@ elsif ($op eq 'add') { > my $rentaldiscount = $input->param('rentaldiscount'); > my $opacitemholds = $input->param('opacitemholds') || 0; > my $overduefinescap = $input->param('overduefinescap') || undef; >- $debug and warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty"; >+ my $cap_fine_to_replacement_price = $input->param('cap_fine_to_replacement_price') eq 'on'; >+ $debug and warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price"; > > my $schema = Koha::Database->new()->schema(); > my $rs = $schema->resultset('Issuingrule'); > > my $params = { >- branchcode => $br, >- categorycode => $bor, >- itemtype => $itemtype, >- fine => $fine, >- finedays => $finedays, >- maxsuspensiondays => $maxsuspensiondays, >- firstremind => $firstremind, >- chargeperiod => $chargeperiod, >- chargeperiod_charge_at => $chargeperiod_charge_at, >- maxissueqty => $maxissueqty, >- maxonsiteissueqty => $maxonsiteissueqty, >- renewalsallowed => $renewalsallowed, >- renewalperiod => $renewalperiod, >- norenewalbefore => $norenewalbefore, >- auto_renew => $auto_renew, >- reservesallowed => $reservesallowed, >- issuelength => $issuelength, >- lengthunit => $lengthunit, >- hardduedate => $hardduedate, >- hardduedatecompare => $hardduedatecompare, >- rentaldiscount => $rentaldiscount, >- onshelfholds => $onshelfholds, >- opacitemholds => $opacitemholds, >- overduefinescap => $overduefinescap, >+ branchcode => $br, >+ categorycode => $bor, >+ itemtype => $itemtype, >+ fine => $fine, >+ finedays => $finedays, >+ maxsuspensiondays => $maxsuspensiondays, >+ firstremind => $firstremind, >+ chargeperiod => $chargeperiod, >+ chargeperiod_charge_at => $chargeperiod_charge_at, >+ maxissueqty => $maxissueqty, >+ maxonsiteissueqty => $maxonsiteissueqty, >+ renewalsallowed => $renewalsallowed, >+ renewalperiod => $renewalperiod, >+ norenewalbefore => $norenewalbefore, >+ auto_renew => $auto_renew, >+ reservesallowed => $reservesallowed, >+ issuelength => $issuelength, >+ lengthunit => $lengthunit, >+ hardduedate => $hardduedate, >+ hardduedatecompare => $hardduedatecompare, >+ rentaldiscount => $rentaldiscount, >+ onshelfholds => $onshelfholds, >+ opacitemholds => $opacitemholds, >+ overduefinescap => $overduefinescap, >+ cap_fine_to_replacement_price => $cap_fine_to_replacement_price, > }; > > $rs->update_or_create($params); >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt >index b3300e0..abefc58 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt >@@ -16,6 +16,9 @@ function clear_edit(){ > $(this).val(""); > $(this).removeAttr("disabled"); > } >+ if ( type == "checkbox" ) { >+ $(this).attr('checked', false); >+ } > }); > $(edit_row).find("select").removeAttr("disabled"); > $(edit_row).find("select option:first").attr("selected", "selected"); >@@ -23,6 +26,9 @@ function clear_edit(){ > } > > $(document).ready(function() { >+ $('#cap_fine_to_replacement_price').on('change', function(){ >+ $('#overduefinescap').prop('disabled', $(this).is(':checked') ); >+ }); > $('#selectlibrary').find("input:submit").hide(); > $('#branch').change(function() { > $('#selectlibrary').submit(); >@@ -38,7 +44,23 @@ $(document).ready(function() { > itm = $(this).text(); > itm = itm.replace(/^\s*|\s*$/g,''); > var current_column = $("#edit_row td:eq("+i+")"); >- if ( i != 6 ) { >+ if ( i == 6 ) { >+ // specific processing for the Hard due date column >+ var select_value = $(this).find("input[type='hidden'][name='hardduedatecomparebackup']").val(); >+ var input_value = ''; >+ if (typeof select_value === 'undefined'){ >+ select_value = '-1'; >+ }else { >+ input_value = itm.split(' ')[1]; >+ } >+ $(current_column).find("input[type='text']").val(input_value); >+ $(current_column).find("select").val(select_value); >+ } else if ( i == 12 ) { >+ // specific processing for cap_fine_to_replacement_price >+ var cap_fine_to_replacement_price = $(this).find("input[type='checkbox']"); >+ $('#cap_fine_to_replacement_price').attr('checked', cap_fine_to_replacement_price.is(':checked') ); >+ $('#overduefinescap').prop('disabled', cap_fine_to_replacement_price.is(':checked') ); >+ } else { > $(current_column).find("input[type='text']").val(itm); > // select the corresponding option > $(current_column).find("select option").each(function(){ >@@ -66,17 +88,6 @@ $(document).ready(function() { > $(current_column).find("input[type='text']").val(""); > } > } >- } else { >- // specific processing for the Hard due date column >- var select_value = $(this).find("input[type='hidden'][name='hardduedatecomparebackup']").val(); >- var input_value = ''; >- if (typeof select_value === 'undefined'){ >- select_value = '-1'; >- }else { >- input_value = itm.split(' ')[1]; >- } >- $(current_column).find("input[type='text']").val(input_value); >- $(current_column).find("select").val(select_value); > } > }); > $("#default-circulation-rules tr:last td:eq(0) select").attr('disabled', 'disabled'); >@@ -151,6 +162,7 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde > <th>Charge when?</th> > <th>Fine grace period</th> > <th>Overdue fines cap (amount)</th> >+ <th>Cap fine at replacement price</th> > <th>Suspension in days (day)</th> > <th>Max. suspension duration (day)</th> > <th>Renewals allowed (count)</th> >@@ -216,6 +228,13 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde > <td>[% IF rule.chargeperiod_charge_at %]Start of interval[% ELSE %]End of interval[% END %]</td> > <td>[% rule.firstremind %]</td> > <td>[% rule.overduefinescap FILTER format("%.2f") %]</td> >+ <td> >+ [% IF rule.cap_fine_to_replacement_price %] >+ <input type="checkbox" checked="checked" disabled="disabled" /> >+ [% ELSE %] >+ <input type="checkbox" disabled="disabled" /> >+ [% END %] >+ </td> > <td>[% rule.finedays %]</td> > <td>[% rule.maxsuspensiondays %]</td> > <td>[% rule.renewalsallowed %]</td> >@@ -283,6 +302,7 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde > </td> > <td><input type="text" name="firstremind" id="firstremind" size="2" /> </td> > <td><input type="text" name="overduefinescap" id="overduefinescap" size="6" /> </td> >+ <td><input type="checkbox" name="cap_fine_to_replacement_price" id="cap_fine_to_replacement_price" /></td> > <td><input type="text" name="finedays" id="fined" size="3" /> </td> > <td><input type="text" name="maxsuspensiondays" id="maxsuspensiondays" size="3" /> </td> > <td><input type="text" name="renewalsallowed" id="renewalsallowed" size="2" /></td> >@@ -329,6 +349,7 @@ for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde > <th>Charge when?</th> > <th>Fine grace period</th> > <th>Overdue fines cap (amount)</th> >+ <th>Cap fine at replacement price</th> > <th>Suspension in days (day)</th> > <th>Max. suspension duration (day)</th> > <th>Renewals allowed (count)</th> >diff --git a/t/db_dependent/Circulation/CalcFine.t b/t/db_dependent/Circulation/CalcFine.t >new file mode 100644 >index 0000000..d5ab276 >--- /dev/null >+++ b/t/db_dependent/Circulation/CalcFine.t >@@ -0,0 +1,146 @@ >+#!/usr/bin/perl >+ >+use Modern::Perl; >+ >+use Test::More tests => 2; >+ >+use C4::Context; >+use C4::Overdues; >+ >+use Koha::DateUtils qw( dt_from_string ); >+ >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+ >+our $dbh = C4::Context->dbh; >+$dbh->{AutoCommit} = 0; >+$dbh->{RaiseError} = 1; >+ >+$dbh->do(q|DELETE FROM issues|); >+ >+my $builder = t::lib::TestBuilder->new(); >+ >+my $branch = $builder->build( >+ { >+ source => 'Branch', >+ } >+); >+ >+my $category = $builder->build( >+ { >+ source => 'Category', >+ } >+); >+ >+my $patron = $builder->build( >+ { >+ source => 'Borrower', >+ value => { >+ categorycode => $category->{categorycode}, >+ branchcode => $branch->{branchcode}, >+ }, >+ } >+); >+ >+my $biblio = $builder->build( >+ { >+ source => 'Biblio', >+ value => { >+ branchcode => $branch->{branchcode}, >+ }, >+ } >+); >+ >+my $item = $builder->build( >+ { >+ source => 'Item', >+ value => { >+ biblionumber => $biblio->{biblionumber}, >+ homebranch => $branch->{branchcode}, >+ holdingbranch => $branch->{branchcode}, >+ replacementprice => '5.00', >+ }, >+ } >+); >+ >+subtest 'Test basic functionality' => sub { >+ plan tests => 1; >+ my $issuingrule = $builder->build( >+ { >+ source => 'Issuingrule', >+ value => { >+ branchcode => '*', >+ categorycode => '*', >+ itemtype => '*', >+ fine => '1.00', >+ lengthunit => 'days', >+ finedays => 0, >+ firstremind => 0, >+ chargeperiod => 1, >+ overduefinescap => undef, >+ cap_fine_to_replacement_price => 0, >+ }, >+ } >+ ); >+ >+ my $start_dt = DateTime->new( >+ year => 2000, >+ month => 01, >+ day => 01, >+ ); >+ >+ my $end_dt = DateTime->new( >+ year => 2000, >+ month => 01, >+ day => 30, >+ ); >+ >+ my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt ); >+ >+ is( $amount, 29, 'Amount is calculated correctly' ); >+ >+ teardown(); >+}; >+ >+subtest 'Test cap_fine_to_replacement_price' => sub { >+ plan tests => 1; >+ my $issuingrule = $builder->build( >+ { >+ source => 'Issuingrule', >+ value => { >+ branchcode => '*', >+ categorycode => '*', >+ itemtype => '*', >+ fine => '1.00', >+ lengthunit => 'days', >+ finedays => 0, >+ firstremind => 0, >+ chargeperiod => 1, >+ overduefinescap => undef, >+ cap_fine_to_replacement_price => 1, >+ }, >+ } >+ ); >+ >+ my $start_dt = DateTime->new( >+ year => 2000, >+ month => 01, >+ day => 01, >+ ); >+ >+ my $end_dt = DateTime->new( >+ year => 2000, >+ month => 01, >+ day => 30, >+ ); >+ >+ my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt ); >+ >+ is( $amount, '5.00', 'Amount is calculated correctly' ); >+ >+ teardown(); >+}; >+ >+sub teardown { >+ $dbh->do(q|DELETE FROM issuingrules|); >+} >-- >1.7.2.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 9129
:
13612
|
13614
|
13615
|
13616
|
14553
|
16197
|
17989
|
17990
|
17991
|
17992
|
18366
|
18367
|
18368
|
18370
|
18371
|
18642
|
18643
|
23305
|
43252
|
43253
|
43298
|
43592
|
43685
|
43686
|
43688
|
43689
|
43745
|
43746
|
43747
|
43781
|
43782
|
43783
|
43784
|
46157