From 7ba04d243e86ab59762d6a2a91ce05c80cac7184 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 4 Jun 2013 11:37:15 -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 --- C4/Overdues.pm | 5 +- Koha/Schema/Result/Issuingrule.pm | 12 ++- admin/smart-rules.pl | 50 ++++++------ installer/data/mysql/atomicupdate/bug_9192.sql | 1 + installer/data/mysql/kohastructure.sql | 1 + .../prog/en/modules/admin/smart-rules.tt | 88 ++++++++++++------- 6 files changed, 96 insertions(+), 61 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_9192.sql diff --git a/C4/Overdues.pm b/C4/Overdues.pm index 6eeb6cf..c6259c4 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -109,14 +109,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) @@ -261,6 +261,7 @@ sub CalcFine { # 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/Koha/Schema/Result/Issuingrule.pm b/Koha/Schema/Result/Issuingrule.pm index 53de573..195d7ee 100644 --- a/Koha/Schema/Result/Issuingrule.pm +++ b/Koha/Schema/Result/Issuingrule.pm @@ -166,6 +166,12 @@ __PACKAGE__->table("issuingrules"); is_nullable: 1 size: [28,6] +=head2 cap_fine_to_replacement_price + + data_type: 'tinyint' + default_value: 0 + is_nullable: 0 + =head2 onshelfholds data_type: 'tinyint' @@ -237,6 +243,8 @@ __PACKAGE__->add_columns( { data_type => "varchar", default_value => "", is_nullable => 0, size => 10 }, "overduefinescap", { data_type => "decimal", is_nullable => 1, size => [28, 6] }, + "cap_fine_to_replacement_price", + { data_type => "tinyint", default_value => 0, is_nullable => 0 }, "onshelfholds", { data_type => "tinyint", default_value => 0, is_nullable => 0 }, "opacitemholds", @@ -260,8 +268,8 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("branchcode", "categorycode", "itemtype"); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2015-05-13 17:48:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:H6LuTmUWdqmjCc5L4hsTQA +# Created by DBIx::Class::Schema::Loader v0.07040 @ 2015-10-08 06:50:50 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:70kyHQNhdQwxADNKEFs3UA # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index bedaef3..26fa8c3 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -131,35 +131,37 @@ 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, - 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, + 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/installer/data/mysql/atomicupdate/bug_9192.sql b/installer/data/mysql/atomicupdate/bug_9192.sql new file mode 100644 index 0000000..a6d0ca8 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_9192.sql @@ -0,0 +1 @@ +ALTER TABLE issuingrules ADD cap_fine_to_replacement_price BOOLEAN NOT NULL DEFAULT '0' AFTER overduefinescap diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 9f12618..b80aa5c 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1187,6 +1187,7 @@ CREATE TABLE `issuingrules` ( -- circulation and fine rules `reservesallowed` smallint(6) NOT NULL default "0", -- how many holds are allowed `branchcode` varchar(10) NOT NULL default '', -- the branch this rule is for (branches.branchcode) overduefinescap decimal(28,6) default NULL, -- the maximum amount of an overdue fine + cap_fine_to_replacement_price BOOLEAN NOT NULL DEFAULT '0', -- cap the fine based on item's replacement price onshelfholds tinyint(1) NOT NULL default 0, -- allow holds for items that are on shelf opacitemholds char(1) NOT NULL default 'N', -- allow opac users to place specific items on hold PRIMARY KEY (`branchcode`,`categorycode`,`itemtype`), 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 01fe3ff..b431476 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 == 11 ) { + // 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'); @@ -150,6 +161,7 @@ for="tobranch">Clone these rules to: Clone these rules to: + + [% IF rule.cap_fine_to_replacement_price %] + + [% ELSE %] + + [% END %] + [% rule.finedays %] [% rule.maxsuspensiondays %] [% rule.renewalsallowed %] @@ -275,6 +294,7 @@ for="tobranch">Clone these rules to: + @@ -309,27 +329,29 @@ for="tobranch">Clone these rules to:   + Patron category + Item type + Current checkouts allowed + Current on-site checkouts allowed + Loan period + Unit + Hard due date + Fine amount + Fine charging interval + Fine grace period + Overdue fines cap (amount) + Cap fine at replacement price + Suspension in days (day) + Max. suspension duration (day) + Renewals allowed (count) + Renewal period + No renewal before + Automatic renewal + Holds allowed (count) + On shelf holds allowed + Item level holds + Rental discount (%) +   -- 1.7.2.5