Lines 56-62
Koha::Account->new( { patron_id => $borrowernumber } )->pay(
Link Here
|
56 |
library_id => $branchcode, |
56 |
library_id => $branchcode, |
57 |
lines => $lines, # Arrayref of Koha::Account::Line objects to pay |
57 |
lines => $lines, # Arrayref of Koha::Account::Line objects to pay |
58 |
account_type => $type, # accounttype code |
58 |
account_type => $type, # accounttype code |
59 |
offset_type => $offset_type, # offset type code |
59 |
offset_type => $offset_type, # offset type code |
|
|
60 |
credit_id => credit_id, # pay from balance of existing credit |
60 |
} |
61 |
} |
61 |
); |
62 |
); |
62 |
|
63 |
|
Lines 75-80
sub pay {
Link Here
|
75 |
my $payment_type = $params->{payment_type} || undef; |
76 |
my $payment_type = $params->{payment_type} || undef; |
76 |
my $account_type = $params->{account_type}; |
77 |
my $account_type = $params->{account_type}; |
77 |
my $offset_type = $params->{offset_type} || $type eq 'writeoff' ? 'Writeoff' : 'Payment'; |
78 |
my $offset_type = $params->{offset_type} || $type eq 'writeoff' ? 'Writeoff' : 'Payment'; |
|
|
79 |
my $credit_id = $params->{credit_id}; |
78 |
|
80 |
|
79 |
my $userenv = C4::Context->userenv; |
81 |
my $userenv = C4::Context->userenv; |
80 |
|
82 |
|
Lines 208-227
sub pay {
Link Here
|
208 |
|
210 |
|
209 |
$description ||= $type eq 'writeoff' ? 'Writeoff' : q{}; |
211 |
$description ||= $type eq 'writeoff' ? 'Writeoff' : q{}; |
210 |
|
212 |
|
211 |
my $payment = Koha::Account::Line->new( |
213 |
my $payment; |
212 |
{ |
214 |
if ($credit_id) { |
213 |
borrowernumber => $self->{patron_id}, |
215 |
$payment = Koha::Account::Lines->find($credit_id); |
214 |
accountno => $accountno, |
216 |
$payment->amountoutstanding( $balance_remaining * -1 ); |
215 |
date => dt_from_string(), |
217 |
$payment->store(); |
216 |
amount => 0 - $amount, |
218 |
} |
217 |
description => $description, |
219 |
else { |
218 |
accounttype => $account_type, |
220 |
$payment = Koha::Account::Line->new( |
219 |
payment_type => $payment_type, |
221 |
{ |
220 |
amountoutstanding => 0 - $balance_remaining, |
222 |
borrowernumber => $self->{patron_id}, |
221 |
manager_id => $manager_id, |
223 |
accountno => $accountno, |
222 |
note => $note, |
224 |
date => dt_from_string(), |
223 |
} |
225 |
amount => 0 - $amount, |
224 |
)->store(); |
226 |
description => $description, |
|
|
227 |
accounttype => $account_type, |
228 |
payment_type => $payment_type, |
229 |
amountoutstanding => 0 - $balance_remaining, |
230 |
manager_id => $manager_id, |
231 |
note => $note, |
232 |
} |
233 |
)->store(); |
234 |
} |
225 |
|
235 |
|
226 |
foreach my $o ( @account_offsets ) { |
236 |
foreach my $o ( @account_offsets ) { |
227 |
$o->credit_id( $payment->id() ); |
237 |
$o->credit_id( $payment->id() ); |
Lines 230-262
sub pay {
Link Here
|
230 |
|
240 |
|
231 |
$library_id ||= $userenv ? $userenv->{'branch'} : undef; |
241 |
$library_id ||= $userenv ? $userenv->{'branch'} : undef; |
232 |
|
242 |
|
233 |
UpdateStats( |
243 |
unless ( $credit_id ) { |
234 |
{ |
244 |
UpdateStats( |
235 |
branch => $library_id, |
245 |
{ |
236 |
type => $type, |
246 |
branch => $library_id, |
237 |
amount => $amount, |
247 |
type => $type, |
238 |
borrowernumber => $self->{patron_id}, |
248 |
amount => $amount, |
239 |
accountno => $accountno, |
249 |
borrowernumber => $self->{patron_id}, |
240 |
} |
250 |
accountno => $accountno, |
241 |
); |
251 |
} |
242 |
|
|
|
243 |
if ( C4::Context->preference("FinesLog") ) { |
244 |
logaction( |
245 |
"FINES", 'CREATE', |
246 |
$self->{patron_id}, |
247 |
Dumper( |
248 |
{ |
249 |
action => "create_$type", |
250 |
borrowernumber => $self->{patron_id}, |
251 |
accountno => $accountno, |
252 |
amount => 0 - $amount, |
253 |
amountoutstanding => 0 - $balance_remaining, |
254 |
accounttype => $account_type, |
255 |
accountlines_paid => \@fines_paid, |
256 |
manager_id => $manager_id, |
257 |
} |
258 |
) |
259 |
); |
252 |
); |
|
|
253 |
|
254 |
if ( C4::Context->preference("FinesLog") ) { |
255 |
logaction( |
256 |
"FINES", 'CREATE', |
257 |
$self->{patron_id}, |
258 |
Dumper( |
259 |
{ |
260 |
action => "create_$type", |
261 |
borrowernumber => $self->{patron_id}, |
262 |
accountno => $accountno, |
263 |
amount => 0 - $amount, |
264 |
amountoutstanding => 0 - $balance_remaining, |
265 |
accounttype => $account_type, |
266 |
accountlines_paid => \@fines_paid, |
267 |
manager_id => $manager_id, |
268 |
} |
269 |
) |
270 |
); |
271 |
} |
260 |
} |
272 |
} |
261 |
|
273 |
|
262 |
return $payment->id; |
274 |
return $payment->id; |
Lines 286-291
sub balance {
Link Here
|
286 |
: 0; |
298 |
: 0; |
287 |
} |
299 |
} |
288 |
|
300 |
|
|
|
301 |
=head3 normalize_balance |
302 |
|
303 |
$account->normalize_balance(); |
304 |
|
305 |
Find outstanding credits and use them to pay outstanding debits |
306 |
|
307 |
=cut |
308 |
|
309 |
sub normalize_balance { |
310 |
my ($self) = @_; |
311 |
my @credits = Koha::Account::Lines->search( |
312 |
{ |
313 |
borrowernumber => $self->{patron_id}, |
314 |
amountoutstanding => { '<' => 0 }, |
315 |
} |
316 |
); |
317 |
|
318 |
foreach my $credit (@credits) { |
319 |
$self->pay( |
320 |
{ |
321 |
credit_id => $credit->id, |
322 |
amount => $credit->amountoutstanding * -1, |
323 |
} |
324 |
); |
325 |
} |
326 |
|
327 |
return $self; |
328 |
} |
329 |
|
289 |
1; |
330 |
1; |
290 |
|
331 |
|
291 |
=head1 AUTHOR |
332 |
=head1 AUTHOR |