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