Lines 23-32
use Carp;
Link Here
|
23 |
use Data::Dumper; |
23 |
use Data::Dumper; |
24 |
use List::MoreUtils qw( uniq ); |
24 |
use List::MoreUtils qw( uniq ); |
25 |
|
25 |
|
26 |
use C4::Circulation qw( ReturnLostItem ); |
26 |
use C4::Circulation qw( ReturnLostItem CanBookBeRenewed AddRenewal ); |
27 |
use C4::Letters; |
27 |
use C4::Letters; |
28 |
use C4::Log qw( logaction ); |
28 |
use C4::Log qw( logaction ); |
29 |
use C4::Stats qw( UpdateStats ); |
29 |
use C4::Stats qw( UpdateStats ); |
|
|
30 |
use C4::Overdues qw(GetFine); |
30 |
|
31 |
|
31 |
use Koha::Patrons; |
32 |
use Koha::Patrons; |
32 |
use Koha::Account::Lines; |
33 |
use Koha::Account::Lines; |
Lines 88-93
sub pay {
Link Here
|
88 |
my $interface = $params ? ( $params->{interface} || C4::Context->interface ) : C4::Context->interface; |
89 |
my $interface = $params ? ( $params->{interface} || C4::Context->interface ) : C4::Context->interface; |
89 |
|
90 |
|
90 |
my @fines_paid; # List of account lines paid on with this payment |
91 |
my @fines_paid; # List of account lines paid on with this payment |
|
|
92 |
# Item numbers that have had a fine paid where the line has a accounttype |
93 |
# of OVERDUE and a status of UNRETURNED. We might want to try and renew |
94 |
# these items. |
95 |
my $overdue_unreturned = {}; |
91 |
|
96 |
|
92 |
my $balance_remaining = $amount; # Set it now so we can adjust the amount if necessary |
97 |
my $balance_remaining = $amount; # Set it now so we can adjust the amount if necessary |
93 |
$balance_remaining ||= 0; |
98 |
$balance_remaining ||= 0; |
Lines 106-111
sub pay {
Link Here
|
106 |
$fine->amountoutstanding($new_amountoutstanding)->store(); |
111 |
$fine->amountoutstanding($new_amountoutstanding)->store(); |
107 |
$balance_remaining = $balance_remaining - $amount_to_pay; |
112 |
$balance_remaining = $balance_remaining - $amount_to_pay; |
108 |
|
113 |
|
|
|
114 |
# If we need to make a note of the item associated with this line, |
115 |
# in order that we can potentially renew it, do so. |
116 |
if ( |
117 |
$new_amountoutstanding == 0 && |
118 |
$fine->accounttype && |
119 |
$fine->accounttype eq 'OVERDUE' && |
120 |
$fine->status && |
121 |
$fine->status eq 'UNRETURNED' |
122 |
) { |
123 |
$overdue_unreturned->{$fine->itemnumber} = $fine; |
124 |
} |
125 |
|
109 |
# Same logic exists in Koha::Account::Line::apply |
126 |
# Same logic exists in Koha::Account::Line::apply |
110 |
if ( $new_amountoutstanding == 0 |
127 |
if ( $new_amountoutstanding == 0 |
111 |
&& $fine->itemnumber |
128 |
&& $fine->itemnumber |
Lines 166-171
sub pay {
Link Here
|
166 |
$fine->amountoutstanding( $old_amountoutstanding - $amount_to_pay ); |
183 |
$fine->amountoutstanding( $old_amountoutstanding - $amount_to_pay ); |
167 |
$fine->store(); |
184 |
$fine->store(); |
168 |
|
185 |
|
|
|
186 |
# If we need to make a note of the item associated with this line, |
187 |
# in order that we can potentially renew it, do so. |
188 |
if ( |
189 |
$old_amountoutstanding - $amount_to_pay == 0 && |
190 |
$fine->accounttype && |
191 |
$fine->accounttype eq 'OVERDUE' && |
192 |
$fine->status && |
193 |
$fine->status eq 'UNRETURNED' |
194 |
) { |
195 |
$overdue_unreturned->{$fine->itemnumber} = $fine; |
196 |
} |
197 |
|
169 |
if ( $fine->amountoutstanding == 0 |
198 |
if ( $fine->amountoutstanding == 0 |
170 |
&& $fine->itemnumber |
199 |
&& $fine->itemnumber |
171 |
&& $fine->accounttype |
200 |
&& $fine->accounttype |
Lines 245-250
sub pay {
Link Here
|
245 |
} |
274 |
} |
246 |
); |
275 |
); |
247 |
|
276 |
|
|
|
277 |
# If we have overdue unreturned items that have had payments made |
278 |
# against them, check whether the balance on those items is now zero |
279 |
# and, if the syspref is set, renew them |
280 |
# Same logic exists in Koha::Account::Line::apply |
281 |
if ( |
282 |
C4::Context->preference('RenewAccruingItemWhenPaid') && |
283 |
keys %{$overdue_unreturned} |
284 |
) { |
285 |
foreach my $itemnumber (keys %{$overdue_unreturned}) { |
286 |
# Only do something if this item has no fines left on it |
287 |
my $fine = C4::Overdues::GetFine( $itemnumber, $self->{patron_id} ); |
288 |
next if $fine && $fine > 0; |
289 |
|
290 |
my ( $renew_ok, $error ) = |
291 |
C4::Circulation::CanBookBeRenewed( |
292 |
$self->{patron_id}, $itemnumber |
293 |
); |
294 |
if ( $renew_ok ) { |
295 |
C4::Circulation::AddRenewal( |
296 |
$self->{patron_id}, |
297 |
$itemnumber, |
298 |
$library_id, |
299 |
undef, |
300 |
undef, |
301 |
1 |
302 |
); |
303 |
} |
304 |
} |
305 |
} |
306 |
|
248 |
if ( C4::Context->preference("FinesLog") ) { |
307 |
if ( C4::Context->preference("FinesLog") ) { |
249 |
logaction( |
308 |
logaction( |
250 |
"FINES", 'CREATE', |
309 |
"FINES", 'CREATE', |