Lines 24-33
use Data::Dumper;
Link Here
|
24 |
use List::MoreUtils qw( uniq ); |
24 |
use List::MoreUtils qw( uniq ); |
25 |
use Try::Tiny; |
25 |
use Try::Tiny; |
26 |
|
26 |
|
27 |
use C4::Circulation qw( ReturnLostItem ); |
27 |
use C4::Circulation qw( ReturnLostItem CanBookBeRenewed AddRenewal ); |
28 |
use C4::Letters; |
28 |
use C4::Letters; |
29 |
use C4::Log qw( logaction ); |
29 |
use C4::Log qw( logaction ); |
30 |
use C4::Stats qw( UpdateStats ); |
30 |
use C4::Stats qw( UpdateStats ); |
|
|
31 |
use C4::Overdues qw(GetFine); |
31 |
|
32 |
|
32 |
use Koha::Patrons; |
33 |
use Koha::Patrons; |
33 |
use Koha::Account::Lines; |
34 |
use Koha::Account::Lines; |
Lines 95-100
sub pay {
Link Here
|
95 |
&& !defined($cash_register) ); |
96 |
&& !defined($cash_register) ); |
96 |
|
97 |
|
97 |
my @fines_paid; # List of account lines paid on with this payment |
98 |
my @fines_paid; # List of account lines paid on with this payment |
|
|
99 |
# Item numbers that have had a fine paid where the line has a accounttype |
100 |
# of OVERDUE and a status of UNRETURNED. We might want to try and renew |
101 |
# these items. |
102 |
my $overdue_unreturned = {}; |
98 |
|
103 |
|
99 |
my $balance_remaining = $amount; # Set it now so we can adjust the amount if necessary |
104 |
my $balance_remaining = $amount; # Set it now so we can adjust the amount if necessary |
100 |
$balance_remaining ||= 0; |
105 |
$balance_remaining ||= 0; |
Lines 113-118
sub pay {
Link Here
|
113 |
$fine->amountoutstanding($new_amountoutstanding)->store(); |
118 |
$fine->amountoutstanding($new_amountoutstanding)->store(); |
114 |
$balance_remaining = $balance_remaining - $amount_to_pay; |
119 |
$balance_remaining = $balance_remaining - $amount_to_pay; |
115 |
|
120 |
|
|
|
121 |
# If we need to make a note of the item associated with this line, |
122 |
# in order that we can potentially renew it, do so. |
123 |
if ( |
124 |
$new_amountoutstanding == 0 && |
125 |
$fine->accounttype && |
126 |
$fine->accounttype eq 'OVERDUE' && |
127 |
$fine->status && |
128 |
$fine->status eq 'UNRETURNED' |
129 |
) { |
130 |
$overdue_unreturned->{$fine->itemnumber} = $fine; |
131 |
} |
132 |
|
116 |
# Same logic exists in Koha::Account::Line::apply |
133 |
# Same logic exists in Koha::Account::Line::apply |
117 |
if ( $new_amountoutstanding == 0 |
134 |
if ( $new_amountoutstanding == 0 |
118 |
&& $fine->itemnumber |
135 |
&& $fine->itemnumber |
Lines 173-178
sub pay {
Link Here
|
173 |
$fine->amountoutstanding( $old_amountoutstanding - $amount_to_pay ); |
190 |
$fine->amountoutstanding( $old_amountoutstanding - $amount_to_pay ); |
174 |
$fine->store(); |
191 |
$fine->store(); |
175 |
|
192 |
|
|
|
193 |
# If we need to make a note of the item associated with this line, |
194 |
# in order that we can potentially renew it, do so. |
195 |
if ( |
196 |
$old_amountoutstanding - $amount_to_pay == 0 && |
197 |
$fine->accounttype && |
198 |
$fine->accounttype eq 'OVERDUE' && |
199 |
$fine->status && |
200 |
$fine->status eq 'UNRETURNED' |
201 |
) { |
202 |
$overdue_unreturned->{$fine->itemnumber} = $fine; |
203 |
} |
204 |
|
176 |
if ( $fine->amountoutstanding == 0 |
205 |
if ( $fine->amountoutstanding == 0 |
177 |
&& $fine->itemnumber |
206 |
&& $fine->itemnumber |
178 |
&& $fine->debit_type_code |
207 |
&& $fine->debit_type_code |
Lines 253-258
sub pay {
Link Here
|
253 |
} |
282 |
} |
254 |
); |
283 |
); |
255 |
|
284 |
|
|
|
285 |
# If we have overdue unreturned items that have had payments made |
286 |
# against them, check whether the balance on those items is now zero |
287 |
# and, if the syspref is set, renew them |
288 |
# Same logic exists in Koha::Account::Line::apply |
289 |
if ( |
290 |
C4::Context->preference('RenewAccruingItemWhenPaid') && |
291 |
keys %{$overdue_unreturned} |
292 |
) { |
293 |
foreach my $itemnumber (keys %{$overdue_unreturned}) { |
294 |
# Only do something if this item has no fines left on it |
295 |
my $fine = C4::Overdues::GetFine( $itemnumber, $self->{patron_id} ); |
296 |
next if $fine && $fine > 0; |
297 |
|
298 |
my ( $renew_ok, $error ) = |
299 |
C4::Circulation::CanBookBeRenewed( |
300 |
$self->{patron_id}, $itemnumber |
301 |
); |
302 |
if ( $renew_ok ) { |
303 |
C4::Circulation::AddRenewal( |
304 |
$self->{patron_id}, |
305 |
$itemnumber, |
306 |
$library_id, |
307 |
undef, |
308 |
undef, |
309 |
1 |
310 |
); |
311 |
} |
312 |
} |
313 |
} |
314 |
|
256 |
if ( C4::Context->preference("FinesLog") ) { |
315 |
if ( C4::Context->preference("FinesLog") ) { |
257 |
logaction( |
316 |
logaction( |
258 |
"FINES", 'CREATE', |
317 |
"FINES", 'CREATE', |