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