|
Lines 72-78
patron.
Link Here
|
| 72 |
|
72 |
|
| 73 |
Record payment by a patron. C<$borrowernumber> is the patron's |
73 |
Record payment by a patron. C<$borrowernumber> is the patron's |
| 74 |
borrower number. C<$payment> is a floating-point number, giving the |
74 |
borrower number. C<$payment> is a floating-point number, giving the |
| 75 |
amount that was paid. |
75 |
amount that was paid. |
| 76 |
|
76 |
|
| 77 |
Amounts owed are paid off oldest first. That is, if the patron has a |
77 |
Amounts owed are paid off oldest first. That is, if the patron has a |
| 78 |
$1 fine from Feb. 1, another $1 fine from Mar. 1, and makes a payment |
78 |
$1 fine from Feb. 1, another $1 fine from Mar. 1, and makes a payment |
|
Lines 115-126
sub recordpayment {
Link Here
|
| 115 |
$newamtos = $accdata->{'amountoutstanding'} - $amountleft; |
115 |
$newamtos = $accdata->{'amountoutstanding'} - $amountleft; |
| 116 |
$amountleft = 0; |
116 |
$amountleft = 0; |
| 117 |
} |
117 |
} |
| 118 |
my $thisacct = $accdata->{accountno}; |
118 |
my $thisacct = $accdata->{accountlines_id}; |
| 119 |
my $usth = $dbh->prepare( |
119 |
my $usth = $dbh->prepare( |
| 120 |
"UPDATE accountlines SET amountoutstanding= ? |
120 |
"UPDATE accountlines SET amountoutstanding= ? |
| 121 |
WHERE (borrowernumber = ?) AND (accountno=?)" |
121 |
WHERE (accountlines_id = ?)" |
| 122 |
); |
122 |
); |
| 123 |
$usth->execute( $newamtos, $borrowernumber, $thisacct ); |
123 |
$usth->execute( $newamtos, $thisacct ); |
| 124 |
$usth->finish; |
124 |
$usth->finish; |
| 125 |
# $usth = $dbh->prepare( |
125 |
# $usth = $dbh->prepare( |
| 126 |
# "INSERT INTO accountoffsets |
126 |
# "INSERT INTO accountoffsets |
|
Lines 146-152
sub recordpayment {
Link Here
|
| 146 |
|
146 |
|
| 147 |
=head2 makepayment |
147 |
=head2 makepayment |
| 148 |
|
148 |
|
| 149 |
&makepayment($borrowernumber, $acctnumber, $amount, $branchcode); |
149 |
&makepayment($accountlines_id, $borrowernumber, $acctnumber, $amount, $branchcode); |
| 150 |
|
150 |
|
| 151 |
Records the fact that a patron has paid off the entire amount he or |
151 |
Records the fact that a patron has paid off the entire amount he or |
| 152 |
she owes. |
152 |
she owes. |
|
Lines 167-173
sub makepayment {
Link Here
|
| 167 |
#here we update both the accountoffsets and the account lines |
167 |
#here we update both the accountoffsets and the account lines |
| 168 |
#updated to check, if they are paying off a lost item, we return the item |
168 |
#updated to check, if they are paying off a lost item, we return the item |
| 169 |
# from their card, and put a note on the item record |
169 |
# from their card, and put a note on the item record |
| 170 |
my ( $borrowernumber, $accountno, $amount, $user, $branch ) = @_; |
170 |
my ( $accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch ) = @_; |
| 171 |
my $dbh = C4::Context->dbh; |
171 |
my $dbh = C4::Context->dbh; |
| 172 |
my $manager_id = 0; |
172 |
my $manager_id = 0; |
| 173 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
173 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
|
Lines 175-184
sub makepayment {
Link Here
|
| 175 |
# begin transaction |
175 |
# begin transaction |
| 176 |
my $nextaccntno = getnextacctno($borrowernumber); |
176 |
my $nextaccntno = getnextacctno($borrowernumber); |
| 177 |
my $newamtos = 0; |
177 |
my $newamtos = 0; |
| 178 |
my $sth = |
178 |
my $sth = $dbh->prepare("SELECT * FROM accountlines WHERE accountlines_id=?"); |
| 179 |
$dbh->prepare( |
179 |
$sth->execute( $accountlines_id ); |
| 180 |
"SELECT * FROM accountlines WHERE borrowernumber=? AND accountno=?"); |
|
|
| 181 |
$sth->execute( $borrowernumber, $accountno ); |
| 182 |
my $data = $sth->fetchrow_hashref; |
180 |
my $data = $sth->fetchrow_hashref; |
| 183 |
$sth->finish; |
181 |
$sth->finish; |
| 184 |
|
182 |
|
|
Lines 187-208
sub makepayment {
Link Here
|
| 187 |
$dbh->prepare( |
185 |
$dbh->prepare( |
| 188 |
"UPDATE accountlines |
186 |
"UPDATE accountlines |
| 189 |
SET amountoutstanding = 0, description = 'Payment,thanks' |
187 |
SET amountoutstanding = 0, description = 'Payment,thanks' |
| 190 |
WHERE borrowernumber = ? |
188 |
WHERE accountlines_id = ? |
| 191 |
AND accountno = ? |
|
|
| 192 |
" |
189 |
" |
| 193 |
); |
190 |
); |
| 194 |
$udp->execute($borrowernumber, $accountno ); |
191 |
$udp->execute($accountlines_id); |
| 195 |
$udp->finish; |
192 |
$udp->finish; |
| 196 |
}else{ |
193 |
}else{ |
| 197 |
my $udp = |
194 |
my $udp = |
| 198 |
$dbh->prepare( |
195 |
$dbh->prepare( |
| 199 |
"UPDATE accountlines |
196 |
"UPDATE accountlines |
| 200 |
SET amountoutstanding = 0 |
197 |
SET amountoutstanding = 0 |
| 201 |
WHERE borrowernumber = ? |
198 |
WHERE accountlines_id = ? |
| 202 |
AND accountno = ? |
|
|
| 203 |
" |
199 |
" |
| 204 |
); |
200 |
); |
| 205 |
$udp->execute($borrowernumber, $accountno ); |
201 |
$udp->execute($accountlines_id); |
| 206 |
$udp->finish; |
202 |
$udp->finish; |
| 207 |
|
203 |
|
| 208 |
# create new line |
204 |
# create new line |
|
Lines 229-234
sub makepayment {
Link Here
|
| 229 |
if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) { |
225 |
if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) { |
| 230 |
C4::Circulation::ReturnLostItem( $borrowernumber, $data->{'itemnumber'} ); |
226 |
C4::Circulation::ReturnLostItem( $borrowernumber, $data->{'itemnumber'} ); |
| 231 |
} |
227 |
} |
|
|
228 |
my $sthr = $dbh->prepare("SELECT max(accountlines_id) AS lastinsertid FROM accountlines"); |
| 229 |
$sthr->execute(); |
| 230 |
my $datalastinsertid = $sthr->fetchrow_hashref; |
| 231 |
$sthr->finish; |
| 232 |
return $datalastinsertid->{'lastinsertid'}; |
| 232 |
} |
233 |
} |
| 233 |
|
234 |
|
| 234 |
=head2 getnextacctno |
235 |
=head2 getnextacctno |
|
Lines 256-273
sub getnextacctno ($) {
Link Here
|
| 256 |
|
257 |
|
| 257 |
=head2 fixaccounts (removed) |
258 |
=head2 fixaccounts (removed) |
| 258 |
|
259 |
|
| 259 |
&fixaccounts($borrowernumber, $accountnumber, $amount); |
260 |
&fixaccounts($accountlines_id, $borrowernumber, $accountnumber, $amount); |
| 260 |
|
261 |
|
| 261 |
#' |
262 |
#' |
| 262 |
# FIXME - I don't understand what this function does. |
263 |
# FIXME - I don't understand what this function does. |
| 263 |
sub fixaccounts { |
264 |
sub fixaccounts { |
| 264 |
my ( $borrowernumber, $accountno, $amount ) = @_; |
265 |
my ( $accountlines_id, $borrowernumber, $accountno, $amount ) = @_; |
| 265 |
my $dbh = C4::Context->dbh; |
266 |
my $dbh = C4::Context->dbh; |
| 266 |
my $sth = $dbh->prepare( |
267 |
my $sth = $dbh->prepare( |
| 267 |
"SELECT * FROM accountlines WHERE borrowernumber=? |
268 |
"SELECT * FROM accountlines WHERE accountlines_id=?" |
| 268 |
AND accountno=?" |
|
|
| 269 |
); |
269 |
); |
| 270 |
$sth->execute( $borrowernumber, $accountno ); |
270 |
$sth->execute( $accountlines_id ); |
| 271 |
my $data = $sth->fetchrow_hashref; |
271 |
my $data = $sth->fetchrow_hashref; |
| 272 |
|
272 |
|
| 273 |
# FIXME - Error-checking |
273 |
# FIXME - Error-checking |
|
Lines 279-286
sub fixaccounts {
Link Here
|
| 279 |
UPDATE accountlines |
279 |
UPDATE accountlines |
| 280 |
SET amount = '$amount', |
280 |
SET amount = '$amount', |
| 281 |
amountoutstanding = '$outstanding' |
281 |
amountoutstanding = '$outstanding' |
| 282 |
WHERE borrowernumber = $borrowernumber |
282 |
WHERE accountlines_id = $accountlines_id |
| 283 |
AND accountno = $accountno |
|
|
| 284 |
EOT |
283 |
EOT |
| 285 |
# FIXME: exceedingly bad form. Use prepare with placholders ("?") in query and execute args. |
284 |
# FIXME: exceedingly bad form. Use prepare with placholders ("?") in query and execute args. |
| 286 |
} |
285 |
} |
|
Lines 460-471
sub fixcredit {
Link Here
|
| 460 |
$newamtos = $accdata->{'amountoutstanding'} - $amountleft; |
459 |
$newamtos = $accdata->{'amountoutstanding'} - $amountleft; |
| 461 |
$amountleft = 0; |
460 |
$amountleft = 0; |
| 462 |
} |
461 |
} |
| 463 |
my $thisacct = $accdata->{accountno}; |
462 |
my $thisacct = $accdata->{accountlines_id}; |
| 464 |
my $usth = $dbh->prepare( |
463 |
my $usth = $dbh->prepare( |
| 465 |
"UPDATE accountlines SET amountoutstanding= ? |
464 |
"UPDATE accountlines SET amountoutstanding= ? |
| 466 |
WHERE (borrowernumber = ?) AND (accountno=?)" |
465 |
WHERE (accountlines_id = ?)" |
| 467 |
); |
466 |
); |
| 468 |
$usth->execute( $newamtos, $borrowernumber, $thisacct ); |
467 |
$usth->execute( $newamtos, $thisacct ); |
| 469 |
$usth->finish; |
468 |
$usth->finish; |
| 470 |
$usth = $dbh->prepare( |
469 |
$usth = $dbh->prepare( |
| 471 |
"INSERT INTO accountoffsets |
470 |
"INSERT INTO accountoffsets |
|
Lines 499-510
sub fixcredit {
Link Here
|
| 499 |
$newamtos = $accdata->{'amountoutstanding'} - $amountleft; |
498 |
$newamtos = $accdata->{'amountoutstanding'} - $amountleft; |
| 500 |
$amountleft = 0; |
499 |
$amountleft = 0; |
| 501 |
} |
500 |
} |
| 502 |
my $thisacct = $accdata->{accountno}; |
501 |
my $thisacct = $accdata->{accountlines_id}; |
| 503 |
my $usth = $dbh->prepare( |
502 |
my $usth = $dbh->prepare( |
| 504 |
"UPDATE accountlines SET amountoutstanding= ? |
503 |
"UPDATE accountlines SET amountoutstanding= ? |
| 505 |
WHERE (borrowernumber = ?) AND (accountno=?)" |
504 |
WHERE (accountlines_id = ?)" |
| 506 |
); |
505 |
); |
| 507 |
$usth->execute( $newamtos, $borrowernumber, $thisacct ); |
506 |
$usth->execute( $newamtos, $thisacct ); |
| 508 |
$usth->finish; |
507 |
$usth->finish; |
| 509 |
$usth = $dbh->prepare( |
508 |
$usth = $dbh->prepare( |
| 510 |
"INSERT INTO accountoffsets |
509 |
"INSERT INTO accountoffsets |
|
Lines 565-576
sub refund {
Link Here
|
| 565 |
} |
564 |
} |
| 566 |
|
565 |
|
| 567 |
# print $amountleft; |
566 |
# print $amountleft; |
| 568 |
my $thisacct = $accdata->{accountno}; |
567 |
my $thisacct = $accdata->{accountlines_id}; |
| 569 |
my $usth = $dbh->prepare( |
568 |
my $usth = $dbh->prepare( |
| 570 |
"UPDATE accountlines SET amountoutstanding= ? |
569 |
"UPDATE accountlines SET amountoutstanding= ? |
| 571 |
WHERE (borrowernumber = ?) AND (accountno=?)" |
570 |
WHERE (accountlines_id = ?)" |
| 572 |
); |
571 |
); |
| 573 |
$usth->execute( $newamtos, $borrowernumber, $thisacct ); |
572 |
$usth->execute( $newamtos, $thisacct ); |
| 574 |
$usth->finish; |
573 |
$usth->finish; |
| 575 |
$usth = $dbh->prepare( |
574 |
$usth = $dbh->prepare( |
| 576 |
"INSERT INTO accountoffsets |
575 |
"INSERT INTO accountoffsets |
|
Lines 603-612
sub getcharges {
Link Here
|
| 603 |
} |
602 |
} |
| 604 |
|
603 |
|
| 605 |
sub ModNote { |
604 |
sub ModNote { |
| 606 |
my ( $borrowernumber, $accountno, $note ) = @_; |
605 |
my ( $accountlines_id, $note ) = @_; |
| 607 |
my $dbh = C4::Context->dbh; |
606 |
my $dbh = C4::Context->dbh; |
| 608 |
my $sth = $dbh->prepare('UPDATE accountlines SET note = ? WHERE borrowernumber = ? AND accountno = ?'); |
607 |
my $sth = $dbh->prepare('UPDATE accountlines SET note = ? WHERE accountlines_id = ?'); |
| 609 |
$sth->execute( $note, $borrowernumber, $accountno ); |
608 |
$sth->execute( $note, $accountlines_id ); |
| 610 |
} |
609 |
} |
| 611 |
|
610 |
|
| 612 |
sub getcredits { |
611 |
sub getcredits { |
|
Lines 651-671
sub getrefunds {
Link Here
|
| 651 |
} |
650 |
} |
| 652 |
|
651 |
|
| 653 |
sub ReversePayment { |
652 |
sub ReversePayment { |
| 654 |
my ( $borrowernumber, $accountno ) = @_; |
653 |
my ( $accountlines_id ) = @_; |
| 655 |
my $dbh = C4::Context->dbh; |
654 |
my $dbh = C4::Context->dbh; |
| 656 |
|
655 |
|
| 657 |
my $sth = $dbh->prepare('SELECT amountoutstanding FROM accountlines WHERE borrowernumber = ? AND accountno = ?'); |
656 |
my $sth = $dbh->prepare('SELECT amountoutstanding FROM accountlines WHERE accountlines_id = ?'); |
| 658 |
$sth->execute( $borrowernumber, $accountno ); |
657 |
$sth->execute( $accountlines_id ); |
| 659 |
my $row = $sth->fetchrow_hashref(); |
658 |
my $row = $sth->fetchrow_hashref(); |
| 660 |
my $amount_outstanding = $row->{'amountoutstanding'}; |
659 |
my $amount_outstanding = $row->{'amountoutstanding'}; |
| 661 |
|
660 |
|
| 662 |
if ( $amount_outstanding <= 0 ) { |
661 |
if ( $amount_outstanding <= 0 ) { |
| 663 |
$sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = amount * -1, description = CONCAT( description, " Reversed -" ) WHERE borrowernumber = ? AND accountno = ?'); |
662 |
$sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = amount * -1, description = CONCAT( description, " Reversed -" ) WHERE accountlines_id = ?'); |
| 664 |
$sth->execute( $borrowernumber, $accountno ); |
663 |
$sth->execute( $accountlines_id ); |
| 665 |
} else { |
664 |
} else { |
| 666 |
$sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = 0, description = CONCAT( description, " Reversed -" ) WHERE borrowernumber = ? AND accountno = ?'); |
665 |
$sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = 0, description = CONCAT( description, " Reversed -" ) WHERE accountlines_id = ?'); |
| 667 |
$sth->execute( $borrowernumber, $accountno ); |
666 |
$sth->execute( $accountlines_id ); |
| 668 |
} |
667 |
} |
| 669 |
} |
668 |
} |
| 670 |
|
669 |
|
| 671 |
=head2 recordpayment_selectaccts |
670 |
=head2 recordpayment_selectaccts |
|
Lines 709-715
sub recordpayment_selectaccts {
Link Here
|
| 709 |
|
708 |
|
| 710 |
# offset transactions |
709 |
# offset transactions |
| 711 |
my $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding= ? ' . |
710 |
my $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding= ? ' . |
| 712 |
'WHERE (borrowernumber = ?) AND (accountno=?)'); |
711 |
'WHERE accountlines_id=?'); |
| 713 |
for my $accdata ( @{$rows} ) { |
712 |
for my $accdata ( @{$rows} ) { |
| 714 |
if ($amountleft == 0) { |
713 |
if ($amountleft == 0) { |
| 715 |
last; |
714 |
last; |
|
Lines 722-729
sub recordpayment_selectaccts {
Link Here
|
| 722 |
$newamtos = $accdata->{amountoutstanding} - $amountleft; |
721 |
$newamtos = $accdata->{amountoutstanding} - $amountleft; |
| 723 |
$amountleft = 0; |
722 |
$amountleft = 0; |
| 724 |
} |
723 |
} |
| 725 |
my $thisacct = $accdata->{accountno}; |
724 |
my $thisacct = $accdata->{accountlines_id}; |
| 726 |
$sth->execute( $newamtos, $borrowernumber, $thisacct ); |
725 |
$sth->execute( $newamtos, $thisacct ); |
| 727 |
} |
726 |
} |
| 728 |
|
727 |
|
| 729 |
# create new line |
728 |
# create new line |
|
Lines 738-744
sub recordpayment_selectaccts {
Link Here
|
| 738 |
# makepayment needs to be fixed to handle partials till then this separate subroutine |
737 |
# makepayment needs to be fixed to handle partials till then this separate subroutine |
| 739 |
# fills in |
738 |
# fills in |
| 740 |
sub makepartialpayment { |
739 |
sub makepartialpayment { |
| 741 |
my ( $borrowernumber, $accountno, $amount, $user, $branch ) = @_; |
740 |
my ( $accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch ) = @_; |
| 742 |
my $manager_id = 0; |
741 |
my $manager_id = 0; |
| 743 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
742 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
| 744 |
if (!$amount || $amount < 0) { |
743 |
if (!$amount || $amount < 0) { |
|
Lines 750-761
sub makepartialpayment {
Link Here
|
| 750 |
my $newamtos = 0; |
749 |
my $newamtos = 0; |
| 751 |
|
750 |
|
| 752 |
my $data = $dbh->selectrow_hashref( |
751 |
my $data = $dbh->selectrow_hashref( |
| 753 |
'SELECT * FROM accountlines WHERE borrowernumber=? AND accountno=?',undef,$borrowernumber,$accountno); |
752 |
'SELECT * FROM accountlines WHERE accountlines_id=?',undef,$accountlines_id); |
| 754 |
my $new_outstanding = $data->{amountoutstanding} - $amount; |
753 |
my $new_outstanding = $data->{amountoutstanding} - $amount; |
| 755 |
|
754 |
|
| 756 |
my $update = 'UPDATE accountlines SET amountoutstanding = ? WHERE borrowernumber = ? ' |
755 |
my $update = 'UPDATE accountlines SET amountoutstanding = ? WHERE accountlines_id = ? '; |
| 757 |
. ' AND accountno = ?'; |
756 |
$dbh->do( $update, undef, $new_outstanding, $accountlines_id); |
| 758 |
$dbh->do( $update, undef, $new_outstanding, $borrowernumber, $accountno); |
|
|
| 759 |
|
757 |
|
| 760 |
# create new line |
758 |
# create new line |
| 761 |
my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, ' |
759 |
my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, ' |