Bug 18452: Correcting 'url' to say 'URL' in catalog detail
[koha.git] / Koha / RefundLostItemFeeRules.pm
blob2e83c76f9c2b14e05f7ec3726029a5522e43a419
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
10 # version.
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.
20 use Modern::Perl;
22 use Koha::Database;
23 use Koha::Exceptions;
25 use Koha::RefundLostItemFeeRule;
27 use base qw(Koha::Objects);
29 =head1 NAME
31 Koha::RefundLostItemFeeRules - Koha RefundLostItemFeeRules object set class
33 =head1 API
35 =head2 Class Methods
37 =cut
39 =head3 type
41 =cut
43 sub _type {
44 return 'RefundLostItemFeeRule';
47 =head3 object_class
49 =cut
51 sub object_class {
52 return 'Koha::RefundLostItemFeeRule';
55 =head3 should_refund
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.
62 =cut
64 sub should_refund {
66 my $self = shift;
67 my $params = shift;
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.
80 =cut
82 sub _effective_branch_rule {
84 my $self = shift;
85 my $branch = shift;
87 my $specific_rule = $self->find({ branchcode => $branch });
89 return ( defined $specific_rule )
90 ? $specific_rule->refund
91 : $self->_default_rule;
94 =head3 _choose_branch
96 my $branch = Koha::RefundLostItemFeeRules->_choose_branch({
97 current_branch => 'current_branch_code',
98 item_home_branch => 'item_home_branch',
99 item_holding_branch => 'item_holding_branch'
102 Helper function that determines the branch to be used to apply the rule.
104 =cut
106 sub _choose_branch {
108 my $self = shift;
109 my $param = shift;
111 my $behaviour = C4::Context->preference( 'RefundLostOnReturnControl' ) // 'CheckinLibrary';
113 my $param_mapping = {
114 CheckinLibrary => 'current_branch',
115 ItemHomeBranch => 'item_home_branch',
116 ItemHoldingBranch => 'item_holding_branch'
119 my $branch = $param->{ $param_mapping->{ $behaviour } };
121 if ( !defined $branch ) {
122 Koha::Exceptions::MissingParameter->throw(
123 "$behaviour requires the " .
124 $param_mapping->{ $behaviour } .
125 " param"
129 return $branch;
132 =head3 _default_rule (internal)
134 This function returns the default rule defined for refunding lost
135 item fees on return. It defaults to 1 if no rule is defined.
137 =cut
139 sub _default_rule {
141 my $self = shift;
142 my $default_rule = $self->find({ branchcode => '*' });
144 return (defined $default_rule)
145 ? $default_rule->refund
146 : 1;