Lines 263-268
sub pay {
Link Here
|
263 |
return $payment->id; |
263 |
return $payment->id; |
264 |
} |
264 |
} |
265 |
|
265 |
|
|
|
266 |
=head3 add_credit |
267 |
|
268 |
This method allows adding credits to a patron's account |
269 |
|
270 |
my $credit_line = Koha::Account->new({ patron_id => $patron_id })->add_credit( |
271 |
{ |
272 |
amount => $amount, |
273 |
description => $description, |
274 |
note => $note, |
275 |
user_id => $user_id, |
276 |
library_id => $library_id, |
277 |
sip => $sip, |
278 |
payment_type => $payment_type, |
279 |
type => $credit_type |
280 |
} |
281 |
); |
282 |
|
283 |
$credit_type can be any of 'credit', 'payment', 'forgiven' or 'writeoff' |
284 |
|
285 |
=cut |
286 |
|
287 |
sub add_credit { |
288 |
|
289 |
my ( $self, $params ) = @_; |
290 |
|
291 |
# amount is passed as a positive value, but we store credit as negative values |
292 |
my $amount = $params->{amount} * -1; |
293 |
my $description = $params->{description} // q{}; |
294 |
my $note = $params->{note} // q{}; |
295 |
my $user_id = $params->{user_id}; |
296 |
my $library_id = $params->{library_id}; |
297 |
my $sip = $params->{sip}; |
298 |
my $payment_type = $params->{payment_type}; |
299 |
my $type = $params->{type} || 'payment'; |
300 |
|
301 |
my $schema = Koha::Database->new->schema; |
302 |
|
303 |
my $account_type = $Koha::Account::account_type->{$type}; |
304 |
$account_type .= $sip |
305 |
if defined $sip && |
306 |
$sip ne "" && |
307 |
$type eq 'payment'; |
308 |
|
309 |
my $line; |
310 |
|
311 |
$schema->txn_do( |
312 |
sub { |
313 |
# We should remove accountno, it is no longer needed |
314 |
my $last = Koha::Account::Lines->search( { borrowernumber => $self->{patron_id} }, |
315 |
{ order_by => 'accountno' } )->next(); |
316 |
my $accountno = $last ? $last->accountno + 1 : 1; |
317 |
|
318 |
# Insert the account line |
319 |
$line = Koha::Account::Line->new( |
320 |
{ borrowernumber => $self->{patron_id}, |
321 |
date => \'NOW()', |
322 |
amount => $amount, |
323 |
description => $description, |
324 |
accounttype => $Koha::Account::account_type->{$type}, |
325 |
amountoutstanding => $amount, |
326 |
payment_type => $payment_type, |
327 |
note => $note, |
328 |
manager_id => $user_id |
329 |
} |
330 |
)->store(); |
331 |
|
332 |
# Record the account offset |
333 |
my $account_offset = Koha::Account::Offset->new( |
334 |
{ debit_id => $line->id, |
335 |
type => $Koha::Account::offset_type->{$type}, |
336 |
amount => $amount |
337 |
} |
338 |
)->store(); |
339 |
|
340 |
UpdateStats( |
341 |
{ branch => $library_id, |
342 |
type => $type, |
343 |
amount => $amount, |
344 |
borrowernumber => $self->{patron_id}, |
345 |
accountno => $accountno, |
346 |
} |
347 |
); |
348 |
|
349 |
if ( C4::Context->preference("FinesLog") ) { |
350 |
logaction( |
351 |
"FINES", 'CREATE', |
352 |
$self->{patron_id}, |
353 |
Dumper( |
354 |
{ action => "create_$type", |
355 |
borrowernumber => $self->{patron_id}, |
356 |
accountno => $accountno, |
357 |
amount => $amount, |
358 |
amountoutstanding => $amount, |
359 |
accounttype => $Koha::Account::account_type->{$type}, |
360 |
manager_id => $user_id, |
361 |
} |
362 |
) |
363 |
); |
364 |
} |
365 |
} |
366 |
); |
367 |
|
368 |
return $line; |
369 |
} |
370 |
|
266 |
=head3 balance |
371 |
=head3 balance |
267 |
|
372 |
|
268 |
my $balance = $self->balance |
373 |
my $balance = $self->balance |
Lines 340-345
sub non_issues_charges {
Link Here
|
340 |
|
445 |
|
341 |
1; |
446 |
1; |
342 |
|
447 |
|
|
|
448 |
=head2 Name mappings |
449 |
|
450 |
=head3 $offset_type |
451 |
|
452 |
=cut |
453 |
|
454 |
our $offset_type = { |
455 |
'credit' => 'Payment', |
456 |
'forgiven' => 'Writeoff', |
457 |
'payment' => 'Payment', |
458 |
'writeoff' => 'Writeoff' |
459 |
}; |
460 |
|
461 |
=head3 $account_type |
462 |
|
463 |
=cut |
464 |
|
465 |
our $account_type = { |
466 |
'credit' => 'C', |
467 |
'forgiven' => 'FOR', |
468 |
'payment' => 'Pay', |
469 |
'writeoff' => 'W' |
470 |
}; |
471 |
|
343 |
=head1 AUTHOR |
472 |
=head1 AUTHOR |
344 |
|
473 |
|
345 |
Kyle M Hall <kyle.m.hall@gmail.com> |
474 |
Kyle M Hall <kyle.m.hall@gmail.com> |
346 |
- |
|
|