Lines 60-66
Koha::Account->new( { patron_id => $borrowernumber } )->pay(
Link Here
|
60 |
library_id => $branchcode, |
60 |
library_id => $branchcode, |
61 |
lines => $lines, # Arrayref of Koha::Account::Line objects to pay |
61 |
lines => $lines, # Arrayref of Koha::Account::Line objects to pay |
62 |
account_type => $type, # accounttype code |
62 |
account_type => $type, # accounttype code |
63 |
offset_type => $offset_type, # offset type code |
63 |
offset_type => $offset_type, # offset type code |
|
|
64 |
credit_id => credit_id, # pay from balance of existing credit |
64 |
} |
65 |
} |
65 |
); |
66 |
); |
66 |
|
67 |
|
Lines 79-84
sub pay {
Link Here
|
79 |
my $payment_type = $params->{payment_type} || undef; |
80 |
my $payment_type = $params->{payment_type} || undef; |
80 |
my $account_type = $params->{account_type}; |
81 |
my $account_type = $params->{account_type}; |
81 |
my $offset_type = $params->{offset_type} || $type eq 'writeoff' ? 'Writeoff' : 'Payment'; |
82 |
my $offset_type = $params->{offset_type} || $type eq 'writeoff' ? 'Writeoff' : 'Payment'; |
|
|
83 |
my $credit_id = $params->{credit_id}; |
82 |
|
84 |
|
83 |
my $userenv = C4::Context->userenv; |
85 |
my $userenv = C4::Context->userenv; |
84 |
|
86 |
|
Lines 214-233
sub pay {
Link Here
|
214 |
|
216 |
|
215 |
$description ||= $type eq 'writeoff' ? 'Writeoff' : q{}; |
217 |
$description ||= $type eq 'writeoff' ? 'Writeoff' : q{}; |
216 |
|
218 |
|
217 |
my $payment = Koha::Account::Line->new( |
219 |
my $payment; |
218 |
{ |
220 |
if ($credit_id) { |
219 |
borrowernumber => $self->{patron_id}, |
221 |
$payment = Koha::Account::Lines->find($credit_id); |
220 |
accountno => $accountno, |
222 |
$payment->amountoutstanding( $balance_remaining * -1 ); |
221 |
date => dt_from_string(), |
223 |
$payment->store(); |
222 |
amount => 0 - $amount, |
224 |
} |
223 |
description => $description, |
225 |
else { |
224 |
accounttype => $account_type, |
226 |
$payment = Koha::Account::Line->new( |
225 |
payment_type => $payment_type, |
227 |
{ |
226 |
amountoutstanding => 0 - $balance_remaining, |
228 |
borrowernumber => $self->{patron_id}, |
227 |
manager_id => $manager_id, |
229 |
accountno => $accountno, |
228 |
note => $note, |
230 |
date => dt_from_string(), |
229 |
} |
231 |
amount => 0 - $amount, |
230 |
)->store(); |
232 |
description => $description, |
|
|
233 |
accounttype => $account_type, |
234 |
payment_type => $payment_type, |
235 |
amountoutstanding => 0 - $balance_remaining, |
236 |
manager_id => $manager_id, |
237 |
note => $note, |
238 |
} |
239 |
)->store(); |
240 |
} |
231 |
|
241 |
|
232 |
foreach my $o ( @account_offsets ) { |
242 |
foreach my $o ( @account_offsets ) { |
233 |
$o->credit_id( $payment->id() ); |
243 |
$o->credit_id( $payment->id() ); |
Lines 236-268
sub pay {
Link Here
|
236 |
|
246 |
|
237 |
$library_id ||= $userenv ? $userenv->{'branch'} : undef; |
247 |
$library_id ||= $userenv ? $userenv->{'branch'} : undef; |
238 |
|
248 |
|
239 |
UpdateStats( |
249 |
unless ( $credit_id ) { |
240 |
{ |
250 |
UpdateStats( |
241 |
branch => $library_id, |
251 |
{ |
242 |
type => $type, |
252 |
branch => $library_id, |
243 |
amount => $amount, |
253 |
type => $type, |
244 |
borrowernumber => $self->{patron_id}, |
254 |
amount => $amount, |
245 |
accountno => $accountno, |
255 |
borrowernumber => $self->{patron_id}, |
246 |
} |
256 |
accountno => $accountno, |
247 |
); |
257 |
} |
248 |
|
|
|
249 |
if ( C4::Context->preference("FinesLog") ) { |
250 |
logaction( |
251 |
"FINES", 'CREATE', |
252 |
$self->{patron_id}, |
253 |
Dumper( |
254 |
{ |
255 |
action => "create_$type", |
256 |
borrowernumber => $self->{patron_id}, |
257 |
accountno => $accountno, |
258 |
amount => 0 - $amount, |
259 |
amountoutstanding => 0 - $balance_remaining, |
260 |
accounttype => $account_type, |
261 |
accountlines_paid => \@fines_paid, |
262 |
manager_id => $manager_id, |
263 |
} |
264 |
) |
265 |
); |
258 |
); |
|
|
259 |
|
260 |
if ( C4::Context->preference("FinesLog") ) { |
261 |
logaction( |
262 |
"FINES", 'CREATE', |
263 |
$self->{patron_id}, |
264 |
Dumper( |
265 |
{ |
266 |
action => "create_$type", |
267 |
borrowernumber => $self->{patron_id}, |
268 |
accountno => $accountno, |
269 |
amount => 0 - $amount, |
270 |
amountoutstanding => 0 - $balance_remaining, |
271 |
accounttype => $account_type, |
272 |
accountlines_paid => \@fines_paid, |
273 |
manager_id => $manager_id, |
274 |
} |
275 |
) |
276 |
); |
277 |
} |
266 |
} |
278 |
} |
267 |
|
279 |
|
268 |
if ( C4::Context->preference('UseEmailReceipts') ) { |
280 |
if ( C4::Context->preference('UseEmailReceipts') ) { |
Lines 524-529
sub non_issues_charges {
Link Here
|
524 |
: 0; |
536 |
: 0; |
525 |
} |
537 |
} |
526 |
|
538 |
|
|
|
539 |
=head3 normalize_balance |
540 |
|
541 |
$account->normalize_balance(); |
542 |
|
543 |
Find outstanding credits and use them to pay outstanding debits |
544 |
|
545 |
=cut |
546 |
|
547 |
sub normalize_balance { |
548 |
my ($self) = @_; |
549 |
my @credits = Koha::Account::Lines->search( |
550 |
{ |
551 |
borrowernumber => $self->{patron_id}, |
552 |
amountoutstanding => { '<' => 0 }, |
553 |
} |
554 |
); |
555 |
|
556 |
foreach my $credit (@credits) { |
557 |
$self->pay( |
558 |
{ |
559 |
credit_id => $credit->id, |
560 |
amount => $credit->amountoutstanding * -1, |
561 |
} |
562 |
); |
563 |
} |
564 |
|
565 |
return $self; |
566 |
} |
567 |
|
527 |
1; |
568 |
1; |
528 |
|
569 |
|
529 |
=head2 Name mappings |
570 |
=head2 Name mappings |