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
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
25 use Koha
::CirculationRule
;
27 use base
qw(Koha::CirculationRules);
31 Koha::RefundLostItemFeeRules - Koha RefundLostItemFeeRules object set class
44 return 'CirculationRule';
52 return 'Koha::CirculationRule';
57 Koha::RefundLostItemFeeRules->should_refund()
59 Returns a boolean telling if the fee needs to be refund given the
60 passed params, and the current rules/sysprefs configuration.
69 return $self->_effective_branch_rule( $self->_choose_branch( $params ) );
73 =head3 _effective_branch_rule
75 Koha::RefundLostItemFeeRules->_effective_branch_rule
77 Given a branch, returns a boolean representing the resulting rule.
78 It tries the branch-specific first. Then falls back to the defined default.
82 sub _effective_branch_rule
{
87 my $specific_rule = $self->search(
89 branchcode
=> $branch,
90 categorycode
=> undef,
92 rule_name
=> 'refund',
96 return ( defined $specific_rule )
97 ?
$specific_rule->rule_value
98 : $self->_default_rule;
101 =head3 _choose_branch
103 my $branch = Koha::RefundLostItemFeeRules->_choose_branch({
104 current_branch => 'current_branch_code',
105 item_home_branch => 'item_home_branch',
106 item_holding_branch => 'item_holding_branch'
109 Helper function that determines the branch to be used to apply the rule.
118 my $behaviour = C4
::Context
->preference( 'RefundLostOnReturnControl' ) // 'CheckinLibrary';
120 my $param_mapping = {
121 CheckinLibrary
=> 'current_branch',
122 ItemHomeBranch
=> 'item_home_branch',
123 ItemHoldingBranch
=> 'item_holding_branch'
126 my $branch = $param->{ $param_mapping->{ $behaviour } };
128 if ( !defined $branch ) {
129 Koha
::Exceptions
::MissingParameter
->throw(
130 "$behaviour requires the " .
131 $param_mapping->{ $behaviour } .
139 =head3 Koha::RefundLostItemFeeRules->find();
141 Inherit from Koha::Objects->find(), but forces rule_name => 'refund'
146 my ( $self, @pars ) = @_;
148 if ( ref($pars[0]) eq 'HASH' ) {
149 $pars[0]->{rule_name
} = 'refund';
152 return $self->SUPER::find
(@pars);
155 =head3 _default_rule (internal)
157 This function returns the default rule defined for refunding lost
158 item fees on return. It defaults to 1 if no rule is defined.
165 my $default_rule = $self->search(
168 categorycode
=> undef,
170 rule_name
=> 'refund',
174 return (defined $default_rule)
175 ?
$default_rule->rule_value