From f2cd6ffc434506a3a76fb0334e9b58bf008e33fb Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 23 Oct 2019 11:32:28 +0100 Subject: [PATCH] Bug 23091: Work In Progress --- C4/Circulation.pm | 40 ++++++++++++++++++++++++- Koha/RefundLostItemFeeRules.pm | 54 ++++++++++++++++++++++++++++++---- 2 files changed, 87 insertions(+), 7 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 3568a32639..acbaa33e80 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1441,7 +1441,7 @@ 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::RefundLostItemFeeRules->should_refund( @@ -1456,6 +1456,25 @@ sub AddIssue { _FixAccountForLostAndReturned( $item_object->itemnumber, undef, $item_object->barcode ); } + if ( + Koha::RefundLostItemFeeRules->should_charge_fine( + { + current_branch => C4::Context->userenv->{branch}, + item_home_branch => $item_object->homebranch, + item_holding_branch => $item_object->holdingbranch + } + ) + ) + { + _CalculateAndUpdateFine( + { + issue => $issue, + item => $item_unblessed, + borrower => $borrower + } + ); + _FixOverduesOnReturn( $borrower->{borrowernumber}, $item_object->itemnumber, undef, 'RENEWED' ); + } } ModItem( @@ -2027,6 +2046,25 @@ sub AddReturn { $borrowernumber, $barcode ); $messages->{'LostItemFeeRefunded'} = 1; } + if ( + Koha::RefundLostItemFeeRules->should_charge_fine( + { + current_branch => C4::Context->userenv->{branch}, + item_home_branch => $item->homebranch, + item_holding_branch => $item_holding_branch + } + ) + ) + { + _CalculateAndUpdateFine( + { + issue => $issue, + item => $item_unblessed, + borrower => $patron_unblessed, + return_date => $return_date + } + ); + } } } diff --git a/Koha/RefundLostItemFeeRules.pm b/Koha/RefundLostItemFeeRules.pm index 86b01f0afd..d8e9d49ad7 100644 --- a/Koha/RefundLostItemFeeRules.pm +++ b/Koha/RefundLostItemFeeRules.pm @@ -66,7 +66,49 @@ sub should_refund { my $self = shift; my $params = shift; - return $self->_effective_branch_rule( $self->_choose_branch( $params ) ); + # Options are: + # 'none' - Do not refund + # 'refund' - Refund only + # 'restore' - Refund and Restore original fine value + # 'charge' - Refund and Charge new fine value + my $rule = $self->_effective_branch_rule( $self->_choose_branch( $params ) ); + return $rule eq 'none' ? 0 : 1; +} + +=head3 should_restore_fine + +Koha::RefundLostItemFeeRules->should_restore() + +Returns a boolean telling if the original overdue fee needs to be restored +given the passed params, and the current rules/sysprefs configuration. + +=cut + +sub should_restore_fine { + + my $self = shift; + my $params = shift; + + my $rule = $self->_effective_branch_rule( $self->_choose_branch( $params ) ); + return $rule eq 'restore' ? 1 : 0; +} + +=head3 should_charge_fine + +Koha::RefundLostItemFeeRules->should_charge_fine() + +Returns a boolean telling if a new overdue fee should be chargeed given the +passed params, and the current rules/sysprefs configuration. + +=cut + +sub should_charge_fine { + + my $self = shift; + my $params = shift; + + my $rule = $self->_effective_branch_rule( $self->_choose_branch( $params ) ); + return $rule eq 'charge' ? 1 : 0; } @@ -89,7 +131,7 @@ sub _effective_branch_rule { branchcode => $branch, categorycode => undef, itemtype => undef, - rule_name => 'refund', + rule_name => 'lost_return', } )->next(); @@ -138,7 +180,7 @@ sub _choose_branch { =head3 Koha::RefundLostItemFeeRules->find(); -Inherit from Koha::Objects->find(), but forces rule_name => 'refund' +Inherit from Koha::Objects->find(), but forces rule_name => 'lost_return' =cut @@ -146,7 +188,7 @@ sub find { my ( $self, @pars ) = @_; if ( ref($pars[0]) eq 'HASH' ) { - $pars[0]->{rule_name} = 'refund'; + $pars[0]->{rule_name} = 'lost_return'; } return $self->SUPER::find(@pars); @@ -167,13 +209,13 @@ sub _default_rule { branchcode => undef, categorycode => undef, itemtype => undef, - rule_name => 'refund', + rule_name => 'lost_return', } )->next(); return (defined $default_rule) ? $default_rule->rule_value - : 1; + : 'refund'; } 1; -- 2.20.1