Lines 95-104
sub pay {
Link Here
|
95 |
&& !defined($cash_register) ); |
95 |
&& !defined($cash_register) ); |
96 |
|
96 |
|
97 |
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 |
98 |
|
99 |
# of OVERDUE and a status of UNRETURNED. We might want to try and renew |
99 |
# The outcome of any attempted item renewals as a result of fines being |
100 |
# these items. |
100 |
# paid off |
101 |
my $overdue_unreturned = {}; |
101 |
my $renew_outcomes = []; |
102 |
|
102 |
|
103 |
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 |
104 |
$balance_remaining ||= 0; |
104 |
$balance_remaining ||= 0; |
Lines 117-126
sub pay {
Link Here
|
117 |
$fine->amountoutstanding($new_amountoutstanding)->store(); |
117 |
$fine->amountoutstanding($new_amountoutstanding)->store(); |
118 |
$balance_remaining = $balance_remaining - $amount_to_pay; |
118 |
$balance_remaining = $balance_remaining - $amount_to_pay; |
119 |
|
119 |
|
120 |
# If we need to make a note of the item associated with this line, |
120 |
# Attempt to renew the item associated with this debit if |
121 |
# in order that we can potentially renew it, do so. |
121 |
# appropriate |
122 |
if (_fine_paid_renewable($new_amountoutstanding, $fine)) { |
122 |
if ($fine->renewable) { |
123 |
$overdue_unreturned->{$fine->itemnumber} = $fine; |
123 |
my $outcome = $fine->renew_item; |
|
|
124 |
push @{$renew_outcomes}, $outcome; |
124 |
} |
125 |
} |
125 |
|
126 |
|
126 |
# Same logic exists in Koha::Account::Line::apply |
127 |
# Same logic exists in Koha::Account::Line::apply |
Lines 186-193
sub pay {
Link Here
|
186 |
# If we need to make a note of the item associated with this line, |
187 |
# 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 |
# in order that we can potentially renew it, do so. |
188 |
my $amt = $old_amountoutstanding - $amount_to_pay; |
189 |
my $amt = $old_amountoutstanding - $amount_to_pay; |
189 |
if (_fine_paid_renewable($amt, $fine)) { |
190 |
if ($fine->renewable) { |
190 |
$overdue_unreturned->{$fine->itemnumber} = $fine; |
191 |
my $outcome = $fine->renew_item; |
|
|
192 |
push @{$renew_outcomes}, $outcome; |
191 |
} |
193 |
} |
192 |
|
194 |
|
193 |
if ( $fine->amountoutstanding == 0 |
195 |
if ( $fine->amountoutstanding == 0 |
Lines 270-280
sub pay {
Link Here
|
270 |
} |
272 |
} |
271 |
); |
273 |
); |
272 |
|
274 |
|
273 |
# If we have overdue unreturned items that have had payments made |
|
|
274 |
# against them, check whether the balance on those items is now zero |
275 |
# and, if the syspref is set, renew them |
276 |
my $renew_result = _maybe_renew($overdue_unreturned, $self->{patron_id}); |
277 |
|
278 |
if ( C4::Context->preference("FinesLog") ) { |
275 |
if ( C4::Context->preference("FinesLog") ) { |
279 |
logaction( |
276 |
logaction( |
280 |
"FINES", 'CREATE', |
277 |
"FINES", 'CREATE', |
Lines 322-328
sub pay {
Link Here
|
322 |
} |
319 |
} |
323 |
} |
320 |
} |
324 |
|
321 |
|
325 |
return { payment_id => $payment->id, renew_result => $renew_result }; |
322 |
return { payment_id => $payment->id, renew_result => $renew_outcomes }; |
326 |
} |
323 |
} |
327 |
|
324 |
|
328 |
=head3 add_credit |
325 |
=head3 add_credit |
Lines 724-802
sub reconcile_balance {
Link Here
|
724 |
return $self; |
721 |
return $self; |
725 |
} |
722 |
} |
726 |
|
723 |
|
727 |
=head3 _fine_paid_renewable |
|
|
728 |
|
729 |
my $bool = _fine_paid_renewable($amt, $fine); |
730 |
|
731 |
Given an outstanding amount and a fine object, determine if this item |
732 |
is potentially renewable as a result of the fine being paid off |
733 |
|
734 |
=cut |
735 |
|
736 |
sub _fine_paid_renewable { |
737 |
my ($amt, $fine) = @_; |
738 |
|
739 |
return ( |
740 |
$amt == 0 && |
741 |
$fine->accounttype && |
742 |
$fine->accounttype eq 'OVERDUE' && |
743 |
$fine->status && |
744 |
$fine->status eq 'UNRETURNED' |
745 |
) ? 1 : 0; |
746 |
} |
747 |
|
748 |
=head3 _maybe_renew |
749 |
|
750 |
my $result = _maybe_renew($overdue_unreturned, $patron_id, $library_id); |
751 |
|
752 |
If we have overdue unreturned items that have had payments made |
753 |
against them, check whether the balance on those items is now zero |
754 |
and, if the syspref is set, renew them |
755 |
|
756 |
=cut |
757 |
|
758 |
sub _maybe_renew { |
759 |
my ($items, $patron_id) = @_; |
760 |
|
761 |
my @results = (); |
762 |
|
763 |
if ( |
764 |
C4::Context->preference('RenewAccruingItemWhenPaid') && |
765 |
keys %{$items} |
766 |
) { |
767 |
foreach my $itemnumber (keys %{$items}) { |
768 |
# Only do something if this item has no fines left on it |
769 |
my $fine = C4::Overdues::GetFine( $itemnumber, $patron_id ); |
770 |
next if $fine && $fine > 0; |
771 |
|
772 |
my ( $can_renew, $error ) = |
773 |
C4::Circulation::CanBookBeRenewed($patron_id, $itemnumber); |
774 |
if ( $can_renew ) { |
775 |
my $due_date = C4::Circulation::AddRenewal( |
776 |
$patron_id, |
777 |
$itemnumber, |
778 |
$items->{$itemnumber}->{branchcode}, |
779 |
undef, |
780 |
undef, |
781 |
1 |
782 |
); |
783 |
push @results, { |
784 |
itemnumber => $itemnumber, |
785 |
due_date => $due_date, |
786 |
success => 1 |
787 |
}; |
788 |
} else { |
789 |
push @results, { |
790 |
itemnumber => $itemnumber, |
791 |
error => $error, |
792 |
success => 0 |
793 |
}; |
794 |
} |
795 |
} |
796 |
} |
797 |
return \@results; |
798 |
} |
799 |
|
800 |
1; |
724 |
1; |
801 |
|
725 |
|
802 |
=head2 Name mappings |
726 |
=head2 Name mappings |