Lines 26-31
use C4::Members;
Link Here
|
26 |
use C4::Circulation qw(ReturnLostItem); |
26 |
use C4::Circulation qw(ReturnLostItem); |
27 |
use C4::Log qw(logaction); |
27 |
use C4::Log qw(logaction); |
28 |
use Koha::Account; |
28 |
use Koha::Account; |
|
|
29 |
use Koha::Account::Lines; |
29 |
|
30 |
|
30 |
use Data::Dumper qw(Dumper); |
31 |
use Data::Dumper qw(Dumper); |
31 |
|
32 |
|
Lines 366-427
C<$payment_note> is the note to attach to this payment
Link Here
|
366 |
|
367 |
|
367 |
sub WriteOffFee { |
368 |
sub WriteOffFee { |
368 |
my ( $borrowernumber, $accountlines_id, $itemnum, $accounttype, $amount, $branch, $payment_note ) = @_; |
369 |
my ( $borrowernumber, $accountlines_id, $itemnum, $accounttype, $amount, $branch, $payment_note ) = @_; |
369 |
$payment_note //= ""; |
|
|
370 |
$branch ||= C4::Context->userenv->{branch}; |
371 |
my $manager_id = 0; |
372 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
373 |
|
374 |
# if no item is attached to fine, make sure to store it as a NULL |
375 |
$itemnum ||= undef; |
376 |
|
377 |
my ( $sth, $query ); |
378 |
my $dbh = C4::Context->dbh(); |
379 |
|
380 |
$query = " |
381 |
UPDATE accountlines SET amountoutstanding = 0 |
382 |
WHERE accountlines_id = ? AND borrowernumber = ? |
383 |
"; |
384 |
$sth = $dbh->prepare( $query ); |
385 |
$sth->execute( $accountlines_id, $borrowernumber ); |
386 |
|
387 |
if ( C4::Context->preference("FinesLog") ) { |
388 |
logaction("FINES", 'MODIFY', $borrowernumber, Dumper({ |
389 |
action => 'fee_writeoff', |
390 |
borrowernumber => $borrowernumber, |
391 |
accountlines_id => $accountlines_id, |
392 |
manager_id => $manager_id, |
393 |
})); |
394 |
} |
395 |
|
370 |
|
396 |
$query =" |
371 |
my $line = Koha::Account::Lines->find($accountlines_id); |
397 |
INSERT INTO accountlines |
372 |
return Koha::Account->new( { patron_id => $borrowernumber } )->pay( |
398 |
( borrowernumber, accountno, itemnumber, date, amount, description, accounttype, manager_id, note ) |
373 |
{ |
399 |
VALUES ( ?, ?, ?, NOW(), ?, 'Writeoff', 'W', ?, ? ) |
374 |
amount => $amount, |
400 |
"; |
375 |
lines => [$line], |
401 |
$sth = $dbh->prepare( $query ); |
376 |
type => 'writeoff', |
402 |
my $acct = getnextacctno($borrowernumber); |
377 |
note => $payment_note, |
403 |
$sth->execute( $borrowernumber, $acct, $itemnum, $amount, $manager_id, $payment_note ); |
378 |
library_id => $branch, |
404 |
|
379 |
} |
405 |
if ( C4::Context->preference("FinesLog") ) { |
|
|
406 |
logaction("FINES", 'CREATE',$borrowernumber,Dumper({ |
407 |
action => 'create_writeoff', |
408 |
borrowernumber => $borrowernumber, |
409 |
accountno => $acct, |
410 |
amount => 0 - $amount, |
411 |
accounttype => 'W', |
412 |
itemnumber => $itemnum, |
413 |
accountlines_paid => [ $accountlines_id ], |
414 |
manager_id => $manager_id, |
415 |
})); |
416 |
} |
417 |
|
418 |
UpdateStats({ |
419 |
branch => $branch, |
420 |
type => 'writeoff', |
421 |
amount => $amount, |
422 |
borrowernumber => $borrowernumber} |
423 |
); |
380 |
); |
424 |
|
|
|
425 |
} |
381 |
} |
426 |
|
382 |
|
427 |
=head2 purge_zero_balance_fees |
383 |
=head2 purge_zero_balance_fees |