Line 0
Link Here
|
|
|
1 |
package Koha::RefundLostItemFeeRules; |
2 |
|
3 |
# Copyright Theke Solutions 2016 |
4 |
# |
5 |
# This file is part of Koha. |
6 |
# |
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. |
11 |
# |
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. |
15 |
# |
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. |
19 |
|
20 |
use Modern::Perl; |
21 |
|
22 |
use Koha::Database; |
23 |
use Koha::Exceptions; |
24 |
|
25 |
use base qw(Koha::Objects); |
26 |
|
27 |
=head1 NAME |
28 |
|
29 |
Koha::RefundLostItemFeeRules - Koha RefundLostItemFeeRules object set class |
30 |
|
31 |
=head1 API |
32 |
|
33 |
=head2 Class Methods |
34 |
|
35 |
=cut |
36 |
|
37 |
=head3 type |
38 |
|
39 |
=cut |
40 |
|
41 |
sub _type { |
42 |
return 'RefundLostItemFeeRule'; |
43 |
} |
44 |
|
45 |
=head3 object_class |
46 |
|
47 |
=cut |
48 |
|
49 |
sub object_class { |
50 |
return 'Koha::RefundLostItemFeeRule'; |
51 |
} |
52 |
|
53 |
=head3 should_refund |
54 |
|
55 |
Koha::RefundLostItemFeeRules->should_refund() |
56 |
|
57 |
Returns a boolean telling if the fee needs to be refund given the |
58 |
passed params, and the current rules/sysprefs configuration. |
59 |
|
60 |
=cut |
61 |
|
62 |
sub should_refund { |
63 |
|
64 |
my $self = shift; |
65 |
my $params = shift; |
66 |
|
67 |
return $self->_effective_branch_rule( $self->_choose_branch( $params ) ); |
68 |
} |
69 |
|
70 |
|
71 |
=head3 _effective_branch_rule |
72 |
|
73 |
Koha::RefundLostItemFeeRules->_effective_branch_rule |
74 |
|
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. |
77 |
|
78 |
=cut |
79 |
|
80 |
sub _effective_branch_rule { |
81 |
|
82 |
my $self = shift; |
83 |
my $branch = shift; |
84 |
|
85 |
my $specific_rule = $self->find({ branchcode => $branch }); |
86 |
|
87 |
return ( defined $specific_rule ) |
88 |
? $specific_rule->refund |
89 |
: $self->_default_rule; |
90 |
} |
91 |
|
92 |
=head3 _choose_branch |
93 |
|
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' |
98 |
}); |
99 |
|
100 |
Helper function that determines the branch to be used to apply the rule. |
101 |
|
102 |
=cut |
103 |
|
104 |
sub _choose_branch { |
105 |
|
106 |
my $self = shift; |
107 |
my $param = shift; |
108 |
|
109 |
my $behaviour = Koha::Config::SysPrefs |
110 |
->find( 'RefundLostOnReturnControl' ) |
111 |
->value // 'CheckinLibrary'; |
112 |
|
113 |
my $param_mapping = { |
114 |
CheckinLibrary => 'current_branch', |
115 |
ItemHomeBranch => 'item_home_branch', |
116 |
ItemHoldingBranch => 'item_holding_branch' |
117 |
}; |
118 |
|
119 |
my $branch = $param->{ $param_mapping->{ $behaviour } }; |
120 |
|
121 |
if ( !defined $branch ) { |
122 |
Koha::Exceptions::MissingParameter->throw( |
123 |
"$behaviour requires the " . |
124 |
$param_mapping->{ $behaviour } . |
125 |
" param" |
126 |
); |
127 |
} |
128 |
|
129 |
return $branch; |
130 |
} |
131 |
|
132 |
=head3 _default_rule (internal) |
133 |
|
134 |
This function returns the default rule defined for refunding lost |
135 |
item fees on return. |
136 |
|
137 |
=cut |
138 |
|
139 |
sub _default_rule { |
140 |
my $self = shift; |
141 |
|
142 |
return $self->find({ branchcode => '*' })->refund; |
143 |
} |
144 |
|
145 |
1; |