1 package Koha
::RefundLostItemFeeRules
;
3 # Copyright Theke Solutions 2016
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 use base
qw(Koha::Objects);
29 Koha::RefundLostItemFeeRules - Koha RefundLostItemFeeRules object set class
42 return 'RefundLostItemFeeRule';
50 return 'Koha::RefundLostItemFeeRule';
55 Koha::RefundLostItemFeeRules->should_refund()
57 Returns a boolean telling if the fee needs to be refund given the
58 passed params, and the current rules/sysprefs configuration.
67 return $self->_effective_branch_rule( $self->_choose_branch( $params ) );
71 =head3 _effective_branch_rule
73 Koha::RefundLostItemFeeRules->_effective_branch_rule
75 Given a branch, returns a boolean representing the resulting rule.
76 It tries the branch-specific first. Then falls back to the defined default.
80 sub _effective_branch_rule
{
85 my $specific_rule = $self->find({ branchcode
=> $branch });
87 return ( defined $specific_rule )
88 ?
$specific_rule->refund
89 : $self->_default_rule;
94 my $branch = Koha::RefundLostItemFeeRules->_choose_branch({
95 current_branch => 'current_branch_code',
96 item_home_branch => 'item_home_branch',
97 item_holding_branch => 'item_holding_branch'
100 Helper function that determines the branch to be used to apply the rule.
109 my $behaviour = C4
::Context
->preference( 'RefundLostOnReturnControl' ) // 'CheckinLibrary';
111 my $param_mapping = {
112 CheckinLibrary
=> 'current_branch',
113 ItemHomeBranch
=> 'item_home_branch',
114 ItemHoldingBranch
=> 'item_holding_branch'
117 my $branch = $param->{ $param_mapping->{ $behaviour } };
119 if ( !defined $branch ) {
120 Koha
::Exceptions
::MissingParameter
->throw(
121 "$behaviour requires the " .
122 $param_mapping->{ $behaviour } .
130 =head3 _default_rule (internal)
132 This function returns the default rule defined for refunding lost
133 item fees on return. It defaults to 1 if no rule is defined.
140 my $default_rule = $self->find({ branchcode
=> '*' });
142 return (defined $default_rule)
143 ?
$default_rule->refund