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