3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #use warnings; FIXME - Bug 2505
26 use C4::Circulation qw(ReturnLostItem);
27 use C4::Log qw(logaction);
29 use Data::Dumper qw(Dumper);
31 use vars qw($VERSION @ISA @EXPORT);
34 # set the version for version checking
35 $VERSION = 3.07.00.049;
50 &recordpayment_selectaccts
57 C4::Accounts - Functions for dealing with Koha accounts
65 The functions in this module deal with the monetary aspect of Koha,
66 including looking up and modifying the amount of money owed by a
73 &recordpayment($borrowernumber, $payment);
75 Record payment by a patron. C<$borrowernumber> is the patron's
76 borrower number. C<$payment> is a floating-point number, giving the
79 Amounts owed are paid off oldest first. That is, if the patron has a
80 $1 fine from Feb. 1, another $1 fine from Mar. 1, and makes a payment
81 of $1.50, then the oldest fine will be paid off in full, and $0.50
82 will be credited to the next one.
89 #here we update the account lines
90 my ( $borrowernumber, $data ) = @_;
91 my $dbh = C4::Context->dbh;
94 my $branch = C4::Context->userenv->{'branch'};
95 my $amountleft = $data;
97 $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
100 my $nextaccntno = getnextacctno($borrowernumber);
102 # get lines with outstanding amounts to offset
103 my $sth = $dbh->prepare(
104 "SELECT * FROM accountlines
105 WHERE (borrowernumber = ?) AND (amountoutstanding<>0)
108 $sth->execute($borrowernumber);
110 # offset transactions
112 while ( ( $accdata = $sth->fetchrow_hashref ) and ( $amountleft > 0 ) ) {
113 if ( $accdata->{'amountoutstanding'} < $amountleft ) {
115 $amountleft -= $accdata->{'amountoutstanding'};
118 $newamtos = $accdata->{'amountoutstanding'} - $amountleft;
121 my $thisacct = $accdata->{accountlines_id};
122 my $usth = $dbh->prepare(
123 "UPDATE accountlines SET amountoutstanding= ?
124 WHERE (accountlines_id = ?)"
126 $usth->execute( $newamtos, $thisacct );
128 if ( C4::Context->preference("FinesLog") ) {
129 $accdata->{'amountoutstanding_new'} = $newamtos;
130 logaction("FINES", 'MODIFY', $borrowernumber, Dumper({
131 action => 'fee_payment',
132 borrowernumber => $accdata->{'borrowernumber'},
133 old_amountoutstanding => $accdata->{'amountoutstanding'},
134 new_amountoutstanding => $newamtos,
135 amount_paid => $accdata->{'amountoutstanding'} - $newamtos,
136 accountlines_id => $accdata->{'accountlines_id'},
137 accountno => $accdata->{'accountno'},
138 manager_id => $manager_id,
140 push( @ids, $accdata->{'accountlines_id'} );
145 my $usth = $dbh->prepare(
146 "INSERT INTO accountlines
147 (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id)
148 VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?)"
150 $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, 0 - $amountleft, $manager_id );
152 UpdateStats( $branch, 'payment', $data, '', '', '', $borrowernumber, $nextaccntno );
154 if ( C4::Context->preference("FinesLog") ) {
155 $accdata->{'amountoutstanding_new'} = $newamtos;
156 logaction("FINES", 'CREATE',$borrowernumber,Dumper({
157 action => 'create_payment',
158 borrowernumber => $borrowernumber,
159 accountno => $nextaccntno,
160 amount => $data * -1,
161 amountoutstanding => $amountleft * -1,
162 accounttype => 'Pay',
163 accountlines_paid => \@ids,
164 manager_id => $manager_id,
172 &makepayment($accountlines_id, $borrowernumber, $acctnumber, $amount, $branchcode);
174 Records the fact that a patron has paid off the entire amount he or
177 C<$borrowernumber> is the patron's borrower number. C<$acctnumber> is
178 the account that was credited. C<$amount> is the amount paid (this is
179 only used to record the payment. It is assumed to be equal to the
180 amount owed). C<$branchcode> is the code of the branch where payment
186 # FIXME - I'm not at all sure about the above, because I don't
187 # understand what the acct* tables in the Koha database are for.
190 #here we update both the accountoffsets and the account lines
191 #updated to check, if they are paying off a lost item, we return the item
192 # from their card, and put a note on the item record
193 my ( $accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch, $payment_note ) = @_;
194 my $dbh = C4::Context->dbh;
196 $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
199 my $nextaccntno = getnextacctno($borrowernumber);
201 my $sth = $dbh->prepare("SELECT * FROM accountlines WHERE accountlines_id=?");
202 $sth->execute( $accountlines_id );
203 my $data = $sth->fetchrow_hashref;
206 if ( $data->{'accounttype'} eq "Pay" ){
210 SET amountoutstanding = 0, description = 'Payment,thanks'
211 WHERE accountlines_id = ?
214 $udp->execute($accountlines_id);
219 SET amountoutstanding = 0
220 WHERE accountlines_id = ?
223 $udp->execute($accountlines_id);
226 my $payment = 0 - $amount;
227 $payment_note //= "";
232 INTO accountlines (borrowernumber, accountno, date, amount, itemnumber, description, accounttype, amountoutstanding, manager_id, note)
233 VALUES ( ?, ?, now(), ?, ?, 'Payment,thanks', 'Pay', 0, ?, ?)"
235 $ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id, $payment_note);
238 if ( C4::Context->preference("FinesLog") ) {
239 logaction("FINES", 'MODIFY', $borrowernumber, Dumper({
240 action => 'fee_payment',
241 borrowernumber => $borrowernumber,
242 old_amountoutstanding => $data->{'amountoutstanding'},
243 new_amountoutstanding => 0,
244 amount_paid => $data->{'amountoutstanding'},
245 accountlines_id => $data->{'accountlines_id'},
246 accountno => $data->{'accountno'},
247 manager_id => $manager_id,
251 logaction("FINES", 'CREATE',$borrowernumber,Dumper({
252 action => 'create_payment',
253 borrowernumber => $borrowernumber,
254 accountno => $nextaccntno,
256 amountoutstanding => 0,,
257 accounttype => 'Pay',
258 accountlines_paid => [$data->{'accountlines_id'}],
259 manager_id => $manager_id,
264 # FIXME - The second argument to &UpdateStats is supposed to be the
266 # UpdateStats is now being passed $accountno too. MTJ
267 UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber,
270 #check to see what accounttype
271 if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) {
272 C4::Circulation::ReturnLostItem( $borrowernumber, $data->{'itemnumber'} );
274 my $sthr = $dbh->prepare("SELECT max(accountlines_id) AS lastinsertid FROM accountlines");
276 my $datalastinsertid = $sthr->fetchrow_hashref;
277 return $datalastinsertid->{'lastinsertid'};
282 $nextacct = &getnextacctno($borrowernumber);
284 Returns the next unused account number for the patron with the given
290 # FIXME - Okay, so what does the above actually _mean_?
292 my ($borrowernumber) = shift or return;
293 my $sth = C4::Context->dbh->prepare(
294 "SELECT accountno+1 FROM accountlines
295 WHERE (borrowernumber = ?)
296 ORDER BY accountno DESC
299 $sth->execute($borrowernumber);
300 return ($sth->fetchrow || 1);
303 =head2 fixaccounts (removed)
305 &fixaccounts($accountlines_id, $borrowernumber, $accountnumber, $amount);
308 # FIXME - I don't understand what this function does.
310 my ( $accountlines_id, $borrowernumber, $accountno, $amount ) = @_;
311 my $dbh = C4::Context->dbh;
312 my $sth = $dbh->prepare(
313 "SELECT * FROM accountlines WHERE accountlines_id=?"
315 $sth->execute( $accountlines_id );
316 my $data = $sth->fetchrow_hashref;
318 # FIXME - Error-checking
319 my $diff = $amount - $data->{'amount'};
320 my $outstanding = $data->{'amountoutstanding'} + $diff;
325 SET amount = '$amount',
326 amountoutstanding = '$outstanding'
327 WHERE accountlines_id = $accountlines_id
329 # FIXME: exceedingly bad form. Use prepare with placholders ("?") in query and execute args.
335 # lost ==1 Lost, lost==2 longoverdue, lost==3 lost and paid for
336 # FIXME: itemlost should be set to 3 after payment is made, should be a warning to the interface that
337 # a charge has been added
338 # FIXME : if no replacement price, borrower just doesn't get charged?
339 my $dbh = C4::Context->dbh();
340 my ($borrowernumber, $itemnumber, $amount, $description) = @_;
342 # first make sure the borrower hasn't already been charged for this item
343 my $sth1=$dbh->prepare("SELECT * from accountlines
344 WHERE borrowernumber=? AND itemnumber=? and accounttype='L'");
345 $sth1->execute($borrowernumber,$itemnumber);
346 my $existing_charge_hashref=$sth1->fetchrow_hashref();
349 unless ($existing_charge_hashref) {
351 $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
352 # This item is on issue ... add replacement cost to the borrower's record and mark it returned
353 # Note that we add this to the account even if there's no replacement price, allowing some other
354 # process (or person) to update it, since we don't handle any defaults for replacement prices.
355 my $accountno = getnextacctno($borrowernumber);
356 my $sth2=$dbh->prepare("INSERT INTO accountlines
357 (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber,manager_id)
358 VALUES (?,?,now(),?,?,'L',?,?,?)");
359 $sth2->execute($borrowernumber,$accountno,$amount,
360 $description,$amount,$itemnumber,$manager_id);
362 if ( C4::Context->preference("FinesLog") ) {
363 logaction("FINES", 'CREATE', $borrowernumber, Dumper({
364 action => 'create_fee',
365 borrowernumber => $borrowernumber,
366 accountno => $accountno,
368 amountoutstanding => $amount,
369 description => $description,
371 itemnumber => $itemnumber,
372 manager_id => $manager_id,
381 &manualinvoice($borrowernumber, $itemnumber, $description, $type,
384 C<$borrowernumber> is the patron's borrower number.
385 C<$description> is a description of the transaction.
386 C<$type> may be one of C<CS>, C<CB>, C<CW>, C<CF>, C<CL>, C<N>, C<L>,
388 C<$itemnumber> is the item involved, if pertinent; otherwise, it
389 should be the empty string.
394 # FIXME: In Koha 3.0 , the only account adjustment 'types' passed to this function
397 # 'FOR' = FORGIVEN (Formerly 'F', but 'F' is taken to mean 'FINE' elsewhere)
400 # 'A' = Account Management fee
406 my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note ) = @_;
408 $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
409 my $dbh = C4::Context->dbh;
412 my $accountno = getnextacctno($borrowernumber);
413 my $amountleft = $amount;
415 if ( $type eq 'N' ) {
416 $desc .= " New Card";
418 if ( $type eq 'F' ) {
421 if ( $type eq 'A' ) {
422 $desc .= " Account Management fee";
424 if ( $type eq 'M' ) {
428 if ( $type eq 'L' && $desc eq '' ) {
430 $desc = " Lost Item";
432 if ( ( $type eq 'L' )
436 or ( $type eq 'M' ) )
442 $desc .= ' ' . $itemnum;
443 my $sth = $dbh->prepare(
444 'INSERT INTO accountlines
445 (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber,notify_id, note, manager_id)
446 VALUES (?, ?, now(), ?,?, ?,?,?,?,?,?)');
447 $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid, $note, $manager_id) || return $sth->errstr;
449 my $sth=$dbh->prepare("INSERT INTO accountlines
450 (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding,notify_id, note, manager_id)
451 VALUES (?, ?, now(), ?, ?, ?, ?,?,?,?)"
453 $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type,
454 $amountleft, $notifyid, $note, $manager_id );
457 if ( C4::Context->preference("FinesLog") ) {
458 logaction("FINES", 'CREATE',$borrowernumber,Dumper({
459 action => 'create_fee',
460 borrowernumber => $borrowernumber,
461 accountno => $accountno,
463 description => $desc,
464 accounttype => $type,
465 amountoutstanding => $amountleft,
466 notify_id => $notifyid,
468 itemnumber => $itemnum,
469 manager_id => $manager_id,
477 my ( $borrowerno, $timestamp, $accountno ) = @_;
478 my $dbh = C4::Context->dbh;
479 my $timestamp2 = $timestamp - 1;
481 my $sth = $dbh->prepare(
482 "SELECT * FROM accountlines WHERE borrowernumber=? AND accountno = ?"
484 $sth->execute( $borrowerno, $accountno );
487 while ( my $data = $sth->fetchrow_hashref ) {
494 my ( $accountlines_id, $note ) = @_;
495 my $dbh = C4::Context->dbh;
496 my $sth = $dbh->prepare('UPDATE accountlines SET note = ? WHERE accountlines_id = ?');
497 $sth->execute( $note, $accountlines_id );
501 my ( $date, $date2 ) = @_;
502 my $dbh = C4::Context->dbh;
503 my $sth = $dbh->prepare(
504 "SELECT * FROM accountlines,borrowers
505 WHERE amount < 0 AND accounttype <> 'Pay' AND accountlines.borrowernumber = borrowers.borrowernumber
506 AND timestamp >=TIMESTAMP(?) AND timestamp < TIMESTAMP(?)"
509 $sth->execute( $date, $date2 );
511 while ( my $data = $sth->fetchrow_hashref ) {
512 $data->{'date'} = $data->{'timestamp'};
520 my ( $date, $date2 ) = @_;
521 my $dbh = C4::Context->dbh;
523 my $sth = $dbh->prepare(
524 "SELECT *,timestamp AS datetime
525 FROM accountlines,borrowers
526 WHERE (accounttype = 'REF'
527 AND accountlines.borrowernumber = borrowers.borrowernumber
528 AND date >=? AND date <?)"
531 $sth->execute( $date, $date2 );
534 while ( my $data = $sth->fetchrow_hashref ) {
542 my ( $accountlines_id ) = @_;
543 my $dbh = C4::Context->dbh;
545 my $sth = $dbh->prepare('SELECT * FROM accountlines WHERE accountlines_id = ?');
546 $sth->execute( $accountlines_id );
547 my $row = $sth->fetchrow_hashref();
548 my $amount_outstanding = $row->{'amountoutstanding'};
550 if ( $amount_outstanding <= 0 ) {
551 $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = amount * -1, description = CONCAT( description, " Reversed -" ) WHERE accountlines_id = ?');
552 $sth->execute( $accountlines_id );
554 $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = 0, description = CONCAT( description, " Reversed -" ) WHERE accountlines_id = ?');
555 $sth->execute( $accountlines_id );
558 if ( C4::Context->preference("FinesLog") ) {
560 $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
562 if ( $amount_outstanding <= 0 ) {
563 $row->{'amountoutstanding'} *= -1;
565 $row->{'amountoutstanding'} = '0';
567 $row->{'description'} .= ' Reversed -';
568 logaction("FINES", 'MODIFY', $row->{'borrowernumber'}, Dumper({
569 action => 'reverse_fee_payment',
570 borrowernumber => $row->{'borrowernumber'},
571 old_amountoutstanding => $row->{'amountoutstanding'},
572 new_amountoutstanding => 0 - $amount_outstanding,,
573 accountlines_id => $row->{'accountlines_id'},
574 accountno => $row->{'accountno'},
575 manager_id => $manager_id,
582 =head2 recordpayment_selectaccts
584 recordpayment_selectaccts($borrowernumber, $payment,$accts);
586 Record payment by a patron. C<$borrowernumber> is the patron's
587 borrower number. C<$payment> is a floating-point number, giving the
588 amount that was paid. C<$accts> is an array ref to a list of
589 accountnos which the payment can be recorded against
591 Amounts owed are paid off oldest first. That is, if the patron has a
592 $1 fine from Feb. 1, another $1 fine from Mar. 1, and makes a payment
593 of $1.50, then the oldest fine will be paid off in full, and $0.50
594 will be credited to the next one.
598 sub recordpayment_selectaccts {
599 my ( $borrowernumber, $amount, $accts, $note ) = @_;
601 my $dbh = C4::Context->dbh;
604 my $branch = C4::Context->userenv->{branch};
605 my $amountleft = $amount;
607 $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
608 my $sql = 'SELECT * FROM accountlines WHERE (borrowernumber = ?) ' .
609 'AND (amountoutstanding<>0) ';
611 $sql .= ' AND accountno IN ( ' . join ',', @{$accts};
614 $sql .= ' ORDER BY date';
616 my $nextaccntno = getnextacctno($borrowernumber);
618 # get lines with outstanding amounts to offset
619 my $rows = $dbh->selectall_arrayref($sql, { Slice => {} }, $borrowernumber);
621 # offset transactions
622 my $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding= ? ' .
623 'WHERE accountlines_id=?');
626 for my $accdata ( @{$rows} ) {
627 if ($amountleft == 0) {
630 if ( $accdata->{amountoutstanding} < $amountleft ) {
632 $amountleft -= $accdata->{amountoutstanding};
635 $newamtos = $accdata->{amountoutstanding} - $amountleft;
638 my $thisacct = $accdata->{accountlines_id};
639 $sth->execute( $newamtos, $thisacct );
641 if ( C4::Context->preference("FinesLog") ) {
642 logaction("FINES", 'MODIFY', $borrowernumber, Dumper({
643 action => 'fee_payment',
644 borrowernumber => $borrowernumber,
645 old_amountoutstanding => $accdata->{'amountoutstanding'},
646 new_amountoutstanding => $newamtos,
647 amount_paid => $accdata->{'amountoutstanding'} - $newamtos,
648 accountlines_id => $accdata->{'accountlines_id'},
649 accountno => $accdata->{'accountno'},
650 manager_id => $manager_id,
652 push( @ids, $accdata->{'accountlines_id'} );
658 $sql = 'INSERT INTO accountlines ' .
659 '(borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding,manager_id,note) ' .
660 q|VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?,?)|;
661 $dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft, $manager_id, $note );
662 UpdateStats( $branch, 'payment', $amount, '', '', '', $borrowernumber, $nextaccntno );
664 if ( C4::Context->preference("FinesLog") ) {
665 logaction("FINES", 'CREATE',$borrowernumber,Dumper({
666 action => 'create_payment',
667 borrowernumber => $borrowernumber,
668 accountno => $nextaccntno,
669 amount => 0 - $amount,
670 amountoutstanding => 0 - $amountleft,
671 accounttype => 'Pay',
672 accountlines_paid => \@ids,
673 manager_id => $manager_id,
680 # makepayment needs to be fixed to handle partials till then this separate subroutine
682 sub makepartialpayment {
683 my ( $accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch, $payment_note ) = @_;
685 $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
686 if (!$amount || $amount < 0) {
689 $payment_note //= "";
690 my $dbh = C4::Context->dbh;
692 my $nextaccntno = getnextacctno($borrowernumber);
695 my $data = $dbh->selectrow_hashref(
696 'SELECT * FROM accountlines WHERE accountlines_id=?',undef,$accountlines_id);
697 my $new_outstanding = $data->{amountoutstanding} - $amount;
699 my $update = 'UPDATE accountlines SET amountoutstanding = ? WHERE accountlines_id = ? ';
700 $dbh->do( $update, undef, $new_outstanding, $accountlines_id);
702 if ( C4::Context->preference("FinesLog") ) {
703 logaction("FINES", 'MODIFY', $borrowernumber, Dumper({
704 action => 'fee_payment',
705 borrowernumber => $borrowernumber,
706 old_amountoutstanding => $data->{'amountoutstanding'},
707 new_amountoutstanding => $new_outstanding,
708 amount_paid => $data->{'amountoutstanding'} - $new_outstanding,
709 accountlines_id => $data->{'accountlines_id'},
710 accountno => $data->{'accountno'},
711 manager_id => $manager_id,
716 my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, '
717 . 'description, accounttype, amountoutstanding, itemnumber, manager_id, note) '
718 . ' VALUES (?, ?, now(), ?, ?, ?, 0, ?, ?, ?)';
720 $dbh->do( $insert, undef, $borrowernumber, $nextaccntno, $amount,
721 "Payment, thanks - $user", 'Pay', $data->{'itemnumber'}, $manager_id, $payment_note);
723 UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber, $accountno );
725 if ( C4::Context->preference("FinesLog") ) {
726 logaction("FINES", 'CREATE',$borrowernumber,Dumper({
727 action => 'create_payment',
728 borrowernumber => $user,
729 accountno => $nextaccntno,
730 amount => 0 - $amount,
731 accounttype => 'Pay',
732 itemnumber => $data->{'itemnumber'},
733 accountlines_paid => [ $data->{'accountlines_id'} ],
734 manager_id => $manager_id,
743 WriteOffFee( $borrowernumber, $accountline_id, $itemnum, $accounttype, $amount, $branch, $payment_note );
745 Write off a fine for a patron.
746 C<$borrowernumber> is the patron's borrower number.
747 C<$accountline_id> is the accountline_id of the fee to write off.
748 C<$itemnum> is the itemnumber of of item whose fine is being written off.
749 C<$accounttype> is the account type of the fine being written off.
750 C<$amount> is a floating-point number, giving the amount that is being written off.
751 C<$branch> is the branchcode of the library where the writeoff occurred.
752 C<$payment_note> is the note to attach to this payment
757 my ( $borrowernumber, $accountlines_id, $itemnum, $accounttype, $amount, $branch, $payment_note ) = @_;
758 $payment_note //= "";
759 $branch ||= C4::Context->userenv->{branch};
761 $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
763 # if no item is attached to fine, make sure to store it as a NULL
767 my $dbh = C4::Context->dbh();
770 UPDATE accountlines SET amountoutstanding = 0
771 WHERE accountlines_id = ? AND borrowernumber = ?
773 $sth = $dbh->prepare( $query );
774 $sth->execute( $accountlines_id, $borrowernumber );
776 if ( C4::Context->preference("FinesLog") ) {
777 logaction("FINES", 'MODIFY', $borrowernumber, Dumper({
778 action => 'fee_writeoff',
779 borrowernumber => $borrowernumber,
780 accountlines_id => $accountlines_id,
781 manager_id => $manager_id,
786 INSERT INTO accountlines
787 ( borrowernumber, accountno, itemnumber, date, amount, description, accounttype, manager_id, note )
788 VALUES ( ?, ?, ?, NOW(), ?, 'Writeoff', 'W', ?, ? )
790 $sth = $dbh->prepare( $query );
791 my $acct = getnextacctno($borrowernumber);
792 $sth->execute( $borrowernumber, $acct, $itemnum, $amount, $manager_id, $payment_note );
794 if ( C4::Context->preference("FinesLog") ) {
795 logaction("FINES", 'CREATE',$borrowernumber,Dumper({
796 action => 'create_writeoff',
797 borrowernumber => $borrowernumber,
799 amount => 0 - $amount,
801 itemnumber => $itemnum,
802 accountlines_paid => [ $accountlines_id ],
803 manager_id => $manager_id,
807 UpdateStats( $branch, 'writeoff', $amount, q{}, q{}, q{}, $borrowernumber );
811 END { } # module clean-up code here (global destructor)