From adf06464f85729e45a6730d9fd037b2def600d25 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 23 Oct 2019 11:32:28 +0100 Subject: [PATCH] Bug 23091: Add handling for new lostreturn rules This patch adds circulation handling for two new lost item return rules. These new rules allow for the new options of refund lost item charge plus charge a freshly calculated overdue fine and refind of lost item charge plus charge a new fine matching the amount from the original overdue fine. --- C4/Circulation.pm | 68 +++++++++++---- Koha/CirculationRules.pm | 19 +++- admin/smart-rules.pl | 16 ++-- .../prog/en/modules/admin/smart-rules.tt | 87 ++++++++++++------- 4 files changed, 128 insertions(+), 62 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index a0fde11397..aadebf9adf 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1446,19 +1446,34 @@ sub AddIssue { UpdateTotalIssues( $item_object->biblionumber, 1 ); } - ## If item was lost, it has now been found, reverse any list item charges if necessary. + ## If item was lost, it has now been found, reverse any lost item charges if necessary. if ( $item_object->itemlost ) { - if ( - Koha::CirculationRules->get_lostreturn_policy( - { - return_branch => C4::Context->userenv->{branch}, - item => $item_object - } - ) - ) - { + my $lostreturn_policy = + Koha::CirculationRules->get_lostreturn_policy( + { + return_branch => C4::Context->userenv->{branch}, + item => $item_object + } + ); + + if ($lostreturn_policy) { _FixAccountForLostAndFound( $item_object->itemnumber, undef, $item_object->barcode ); + + if ( $lostreturn_policy eq 'charge' ) { + _CalculateAndUpdateFine( + { + issue => $issue, + item => $item_unblessed, + borrower => $borrower + } + ); + _FixOverduesOnReturn( $borrower->{borrowernumber}, + $item_object->itemnumber, undef, 'RENEWED' ); + } + elsif ( $lostreturn_policy eq 'restore' ) { + + } } } @@ -2031,18 +2046,33 @@ sub AddReturn { if ( $item->itemlost ) { $messages->{'WasLost'} = 1; unless ( C4::Context->preference("BlockReturnOfLostItems") ) { - if ( - Koha::CirculationRules->get_lostreturn_policy( - { - return_branch => C4::Context->userenv->{branch}, - item => $item, - } - ) - ) - { + my $lostreturn_policy = + Koha::CirculationRules->get_lostreturn_policy( + { + return_branch => C4::Context->userenv->{branch}, + item => $item + } + ); + + if ($lostreturn_policy) { _FixAccountForLostAndFound( $item->itemnumber, $borrowernumber, $barcode ); $messages->{'LostItemFeeRefunded'} = 1; + + if ( $lostreturn_policy eq 'charge' ) { + _CalculateAndUpdateFine( + { + issue => $issue, + item => $item, + borrower => $patron_unblessed, + return_date => $return_date + } + ); + $messages->{'LostItemFeeCharged'} = 1; + } + elsif ( $lostreturn_policy eq 'restore' ) { + $messages->{'LostItemFeeRestored'} = 1; + } } } } diff --git a/Koha/CirculationRules.pm b/Koha/CirculationRules.pm index 0b989daffa..38aee10ccc 100644 --- a/Koha/CirculationRules.pm +++ b/Koha/CirculationRules.pm @@ -46,7 +46,7 @@ Any attempt to set a rule with a nonsensical scope (for instance, setting the C< =cut our $RULE_KINDS = { - refund => { + lostreturn => { scope => [ 'branchcode' ], }, @@ -425,7 +425,18 @@ sub get_onshelfholds_policy { =head3 get_lostreturn_policy - my $refund = Koha::CirculationRules->get_lostreturn_policy( { return_branch => $return_branch, item => $item } ); + my $lostrefund_policy = Koha::CirculationRules->get_lostreturn_policy( { return_branch => $return_branch, item => $item } ); + +Return values are: + +=over 2 + +=item 0 - Do not refund +=item refund - Refund the lost item charge +=item restore - Refund the lost item charge and restore the original overdue fine +=item charge - Refund the lost item charge and charge a new overdue fine + +=back =cut @@ -446,11 +457,11 @@ sub get_lostreturn_policy { my $rule = Koha::CirculationRules->get_effective_rule( { branchcode => $branch, - rule_name => 'refund', + rule_name => 'lostreturn', } ); - return $rule ? $rule->rule_value : 1; + return $rule ? $rule->rule_value : 'refund'; } =head3 article_requestable_rules diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index d72599faae..22add21fec 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -522,16 +522,16 @@ elsif ($op eq "add-branch-item") { } elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) { - my $refund = $input->param('refund'); + my $lostreturn = $input->param('lostreturn'); - if ( $refund eq '*' ) { + if ( $lostreturn eq '*' ) { if ( $branch ne '*' ) { - # only do something for $refund eq '*' if branch-specific + # only do something for $lostreturn eq '*' if branch-specific Koha::CirculationRules->set_rules( { branchcode => $branch, rules => { - refund => undef + lostreturn => undef } } ); @@ -541,18 +541,18 @@ elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) { { branchcode => $branch, rules => { - refund => $refund + lostreturn => $lostreturn } } ); } } -my $refundLostItemFeeRule = Koha::CirculationRules->find({ branchcode => ($branch eq '*') ? undef : $branch, rule_name => 'refund' }); -my $defaultLostItemFeeRule = Koha::CirculationRules->find({ branchcode => undef, rule_name => 'refund' }); +my $refundLostItemFeeRule = Koha::CirculationRules->find({ branchcode => ($branch eq '*') ? undef : $branch, rule_name => 'lostreturn' }); +my $defaultLostItemFeeRule = Koha::CirculationRules->find({ branchcode => undef, rule_name => 'lostreturn' }); $template->param( refundLostItemFeeRule => $refundLostItemFeeRule, - defaultRefundRule => $defaultLostItemFeeRule ? $defaultLostItemFeeRule->rule_value : 1 + defaultRefundRule => $defaultLostItemFeeRule ? $defaultLostItemFeeRule->rule_value : 'refund' ); my $patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description'] }); 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 5ae3bb94e1..0a2d7f74b0 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 @@ -718,23 +718,35 @@ - [%# Default branch %] [% IF ( current_branch == '*' ) %] - [% IF ( defaultRefundRule ) %] - + + + + [% ELSIF ( defaultRefundRule == 'charge' ) %] + + + + + [% ELSIF ( defaultRefundRule == 'restore' ) %] + + + + + [% ELSIF ( defaultRefundRule == 0 ) %] + + + + [% ELSE %] - + + + [% END %] - Yes - - [% IF ( not defaultRefundRule ) %] - [% ELSE %] [%# Branch-specific %] [% IF ( not refundLostItemFeeRule ) %] @@ -742,30 +754,43 @@ [% ELSE %] [% IF ( not refundLostItemFeeRule ) %] - - + + + + [% ELSE %] - [% IF ( refundLostItemFeeRule.rule_value ) %] - + + + + [% ELSIF ( refundLostItemFeeRule.rule_value == 'charge' ) %] + + + + + [% ELSIF ( refundLostItemFeeRule.rule_value == 'restore' ) %] + + + + + [% ELSIF ( refundLostItemFeeRule.rule_value == 0 ) %] + + + + [% END %] - Yes - - [% IF ( not refundLostItemFeeRule.rule_value ) %] - [% END %] [% END %] -- 2.20.1