|
Lines 64-70
patron.
Link Here
|
| 64 |
|
64 |
|
| 65 |
Record payment by a patron. C<$borrowernumber> is the patron's |
65 |
Record payment by a patron. C<$borrowernumber> is the patron's |
| 66 |
borrower number. C<$payment> is a floating-point number, giving the |
66 |
borrower number. C<$payment> is a floating-point number, giving the |
| 67 |
amount that was paid. |
67 |
amount that was paid. |
| 68 |
|
68 |
|
| 69 |
Amounts owed are paid off oldest first. That is, if the patron has a |
69 |
Amounts owed are paid off oldest first. That is, if the patron has a |
| 70 |
$1 fine from Feb. 1, another $1 fine from Mar. 1, and makes a payment |
70 |
$1 fine from Feb. 1, another $1 fine from Mar. 1, and makes a payment |
|
Lines 105-116
sub recordpayment {
Link Here
|
| 105 |
$newamtos = $accdata->{'amountoutstanding'} - $amountleft; |
105 |
$newamtos = $accdata->{'amountoutstanding'} - $amountleft; |
| 106 |
$amountleft = 0; |
106 |
$amountleft = 0; |
| 107 |
} |
107 |
} |
| 108 |
my $thisacct = $accdata->{accountno}; |
108 |
my $thisacct = $accdata->{accountlinesid}; |
| 109 |
my $usth = $dbh->prepare( |
109 |
my $usth = $dbh->prepare( |
| 110 |
"UPDATE accountlines SET amountoutstanding= ? |
110 |
"UPDATE accountlines SET amountoutstanding= ? |
| 111 |
WHERE (borrowernumber = ?) AND (accountno=?)" |
111 |
WHERE (accountlinesid = ?)" |
| 112 |
); |
112 |
); |
| 113 |
$usth->execute( $newamtos, $borrowernumber, $thisacct ); |
113 |
$usth->execute( $newamtos, $thisacct ); |
| 114 |
$usth->finish; |
114 |
$usth->finish; |
| 115 |
# $usth = $dbh->prepare( |
115 |
# $usth = $dbh->prepare( |
| 116 |
# "INSERT INTO accountoffsets |
116 |
# "INSERT INTO accountoffsets |
|
Lines 136-142
sub recordpayment {
Link Here
|
| 136 |
|
136 |
|
| 137 |
=head2 makepayment |
137 |
=head2 makepayment |
| 138 |
|
138 |
|
| 139 |
&makepayment($borrowernumber, $acctnumber, $amount, $branchcode); |
139 |
&makepayment($accountlinesid, $borrowernumber, $acctnumber, $amount, $branchcode); |
| 140 |
|
140 |
|
| 141 |
Records the fact that a patron has paid off the entire amount he or |
141 |
Records the fact that a patron has paid off the entire amount he or |
| 142 |
she owes. |
142 |
she owes. |
|
Lines 157-163
sub makepayment {
Link Here
|
| 157 |
#here we update both the accountoffsets and the account lines |
157 |
#here we update both the accountoffsets and the account lines |
| 158 |
#updated to check, if they are paying off a lost item, we return the item |
158 |
#updated to check, if they are paying off a lost item, we return the item |
| 159 |
# from their card, and put a note on the item record |
159 |
# from their card, and put a note on the item record |
| 160 |
my ( $borrowernumber, $accountno, $amount, $user, $branch ) = @_; |
160 |
my ( $accountlinesid, $borrowernumber, $accountno, $amount, $user, $branch ) = @_; |
| 161 |
my $dbh = C4::Context->dbh; |
161 |
my $dbh = C4::Context->dbh; |
| 162 |
my $manager_id = 0; |
162 |
my $manager_id = 0; |
| 163 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
163 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
|
Lines 165-174
sub makepayment {
Link Here
|
| 165 |
# begin transaction |
165 |
# begin transaction |
| 166 |
my $nextaccntno = getnextacctno($borrowernumber); |
166 |
my $nextaccntno = getnextacctno($borrowernumber); |
| 167 |
my $newamtos = 0; |
167 |
my $newamtos = 0; |
| 168 |
my $sth = |
168 |
my $sth = $dbh->prepare("SELECT * FROM accountlines WHERE accountlinesid=?"); |
| 169 |
$dbh->prepare( |
169 |
$sth->execute( $accountlinesid ); |
| 170 |
"SELECT * FROM accountlines WHERE borrowernumber=? AND accountno=?"); |
|
|
| 171 |
$sth->execute( $borrowernumber, $accountno ); |
| 172 |
my $data = $sth->fetchrow_hashref; |
170 |
my $data = $sth->fetchrow_hashref; |
| 173 |
$sth->finish; |
171 |
$sth->finish; |
| 174 |
|
172 |
|
|
Lines 177-198
sub makepayment {
Link Here
|
| 177 |
$dbh->prepare( |
175 |
$dbh->prepare( |
| 178 |
"UPDATE accountlines |
176 |
"UPDATE accountlines |
| 179 |
SET amountoutstanding = 0, description = 'Payment,thanks' |
177 |
SET amountoutstanding = 0, description = 'Payment,thanks' |
| 180 |
WHERE borrowernumber = ? |
178 |
WHERE accountlinesid = ? |
| 181 |
AND accountno = ? |
|
|
| 182 |
" |
179 |
" |
| 183 |
); |
180 |
); |
| 184 |
$udp->execute($borrowernumber, $accountno ); |
181 |
$udp->execute($accountlinesid); |
| 185 |
$udp->finish; |
182 |
$udp->finish; |
| 186 |
}else{ |
183 |
}else{ |
| 187 |
my $udp = |
184 |
my $udp = |
| 188 |
$dbh->prepare( |
185 |
$dbh->prepare( |
| 189 |
"UPDATE accountlines |
186 |
"UPDATE accountlines |
| 190 |
SET amountoutstanding = 0 |
187 |
SET amountoutstanding = 0 |
| 191 |
WHERE borrowernumber = ? |
188 |
WHERE accountlinesid = ? |
| 192 |
AND accountno = ? |
|
|
| 193 |
" |
189 |
" |
| 194 |
); |
190 |
); |
| 195 |
$udp->execute($borrowernumber, $accountno ); |
191 |
$udp->execute($accountlinesid); |
| 196 |
$udp->finish; |
192 |
$udp->finish; |
| 197 |
|
193 |
|
| 198 |
# create new line |
194 |
# create new line |
|
Lines 219-224
sub makepayment {
Link Here
|
| 219 |
if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) { |
215 |
if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) { |
| 220 |
C4::Circulation::ReturnLostItem( $borrowernumber, $data->{'itemnumber'} ); |
216 |
C4::Circulation::ReturnLostItem( $borrowernumber, $data->{'itemnumber'} ); |
| 221 |
} |
217 |
} |
|
|
218 |
my $sthr = $dbh->prepare("SELECT max(accountlinesid) AS lastinsertid FROM accountlines"); |
| 219 |
$sthr->execute(); |
| 220 |
my $datalastinsertid = $sthr->fetchrow_hashref; |
| 221 |
$sthr->finish; |
| 222 |
return $datalastinsertid->{'lastinsertid'}; |
| 222 |
} |
223 |
} |
| 223 |
|
224 |
|
| 224 |
=head2 getnextacctno |
225 |
=head2 getnextacctno |
|
Lines 246-263
sub getnextacctno ($) {
Link Here
|
| 246 |
|
247 |
|
| 247 |
=head2 fixaccounts (removed) |
248 |
=head2 fixaccounts (removed) |
| 248 |
|
249 |
|
| 249 |
&fixaccounts($borrowernumber, $accountnumber, $amount); |
250 |
&fixaccounts($accountlinesid, $borrowernumber, $accountnumber, $amount); |
| 250 |
|
251 |
|
| 251 |
#' |
252 |
#' |
| 252 |
# FIXME - I don't understand what this function does. |
253 |
# FIXME - I don't understand what this function does. |
| 253 |
sub fixaccounts { |
254 |
sub fixaccounts { |
| 254 |
my ( $borrowernumber, $accountno, $amount ) = @_; |
255 |
my ( $accountlinesid, $borrowernumber, $accountno, $amount ) = @_; |
| 255 |
my $dbh = C4::Context->dbh; |
256 |
my $dbh = C4::Context->dbh; |
| 256 |
my $sth = $dbh->prepare( |
257 |
my $sth = $dbh->prepare( |
| 257 |
"SELECT * FROM accountlines WHERE borrowernumber=? |
258 |
"SELECT * FROM accountlines WHERE accountlinesid=?" |
| 258 |
AND accountno=?" |
|
|
| 259 |
); |
259 |
); |
| 260 |
$sth->execute( $borrowernumber, $accountno ); |
260 |
$sth->execute( $accountlinesid ); |
| 261 |
my $data = $sth->fetchrow_hashref; |
261 |
my $data = $sth->fetchrow_hashref; |
| 262 |
|
262 |
|
| 263 |
# FIXME - Error-checking |
263 |
# FIXME - Error-checking |
|
Lines 269-276
sub fixaccounts {
Link Here
|
| 269 |
UPDATE accountlines |
269 |
UPDATE accountlines |
| 270 |
SET amount = '$amount', |
270 |
SET amount = '$amount', |
| 271 |
amountoutstanding = '$outstanding' |
271 |
amountoutstanding = '$outstanding' |
| 272 |
WHERE borrowernumber = $borrowernumber |
272 |
WHERE accountlinesid = $accountlinesid |
| 273 |
AND accountno = $accountno |
|
|
| 274 |
EOT |
273 |
EOT |
| 275 |
# FIXME: exceedingly bad form. Use prepare with placholders ("?") in query and execute args. |
274 |
# FIXME: exceedingly bad form. Use prepare with placholders ("?") in query and execute args. |
| 276 |
} |
275 |
} |
|
Lines 448-459
sub fixcredit {
Link Here
|
| 448 |
$newamtos = $accdata->{'amountoutstanding'} - $amountleft; |
447 |
$newamtos = $accdata->{'amountoutstanding'} - $amountleft; |
| 449 |
$amountleft = 0; |
448 |
$amountleft = 0; |
| 450 |
} |
449 |
} |
| 451 |
my $thisacct = $accdata->{accountno}; |
450 |
my $thisacct = $accdata->{accountlinesid}; |
| 452 |
my $usth = $dbh->prepare( |
451 |
my $usth = $dbh->prepare( |
| 453 |
"UPDATE accountlines SET amountoutstanding= ? |
452 |
"UPDATE accountlines SET amountoutstanding= ? |
| 454 |
WHERE (borrowernumber = ?) AND (accountno=?)" |
453 |
WHERE (accountlinesid = ?)" |
| 455 |
); |
454 |
); |
| 456 |
$usth->execute( $newamtos, $borrowernumber, $thisacct ); |
455 |
$usth->execute( $newamtos, $thisacct ); |
| 457 |
$usth->finish; |
456 |
$usth->finish; |
| 458 |
$usth = $dbh->prepare( |
457 |
$usth = $dbh->prepare( |
| 459 |
"INSERT INTO accountoffsets |
458 |
"INSERT INTO accountoffsets |
|
Lines 487-498
sub fixcredit {
Link Here
|
| 487 |
$newamtos = $accdata->{'amountoutstanding'} - $amountleft; |
486 |
$newamtos = $accdata->{'amountoutstanding'} - $amountleft; |
| 488 |
$amountleft = 0; |
487 |
$amountleft = 0; |
| 489 |
} |
488 |
} |
| 490 |
my $thisacct = $accdata->{accountno}; |
489 |
my $thisacct = $accdata->{accountlinesid}; |
| 491 |
my $usth = $dbh->prepare( |
490 |
my $usth = $dbh->prepare( |
| 492 |
"UPDATE accountlines SET amountoutstanding= ? |
491 |
"UPDATE accountlines SET amountoutstanding= ? |
| 493 |
WHERE (borrowernumber = ?) AND (accountno=?)" |
492 |
WHERE (accountlinesid = ?)" |
| 494 |
); |
493 |
); |
| 495 |
$usth->execute( $newamtos, $borrowernumber, $thisacct ); |
494 |
$usth->execute( $newamtos, $thisacct ); |
| 496 |
$usth->finish; |
495 |
$usth->finish; |
| 497 |
$usth = $dbh->prepare( |
496 |
$usth = $dbh->prepare( |
| 498 |
"INSERT INTO accountoffsets |
497 |
"INSERT INTO accountoffsets |
|
Lines 553-564
sub refund {
Link Here
|
| 553 |
} |
552 |
} |
| 554 |
|
553 |
|
| 555 |
# print $amountleft; |
554 |
# print $amountleft; |
| 556 |
my $thisacct = $accdata->{accountno}; |
555 |
my $thisacct = $accdata->{accountlinesid}; |
| 557 |
my $usth = $dbh->prepare( |
556 |
my $usth = $dbh->prepare( |
| 558 |
"UPDATE accountlines SET amountoutstanding= ? |
557 |
"UPDATE accountlines SET amountoutstanding= ? |
| 559 |
WHERE (borrowernumber = ?) AND (accountno=?)" |
558 |
WHERE (accountlinesid = ?)" |
| 560 |
); |
559 |
); |
| 561 |
$usth->execute( $newamtos, $borrowernumber, $thisacct ); |
560 |
$usth->execute( $newamtos, $thisacct ); |
| 562 |
$usth->finish; |
561 |
$usth->finish; |
| 563 |
$usth = $dbh->prepare( |
562 |
$usth = $dbh->prepare( |
| 564 |
"INSERT INTO accountoffsets |
563 |
"INSERT INTO accountoffsets |
|
Lines 591-600
sub getcharges {
Link Here
|
| 591 |
} |
590 |
} |
| 592 |
|
591 |
|
| 593 |
sub ModNote { |
592 |
sub ModNote { |
| 594 |
my ( $borrowernumber, $accountno, $note ) = @_; |
593 |
my ( $accountlinesid, $note ) = @_; |
| 595 |
my $dbh = C4::Context->dbh; |
594 |
my $dbh = C4::Context->dbh; |
| 596 |
my $sth = $dbh->prepare('UPDATE accountlines SET note = ? WHERE borrowernumber = ? AND accountno = ?'); |
595 |
my $sth = $dbh->prepare('UPDATE accountlines SET note = ? WHERE accountlinesid = ?'); |
| 597 |
$sth->execute( $note, $borrowernumber, $accountno ); |
596 |
$sth->execute( $note, $accountlinesid ); |
| 598 |
} |
597 |
} |
| 599 |
|
598 |
|
| 600 |
sub getcredits { |
599 |
sub getcredits { |
|
Lines 639-659
sub getrefunds {
Link Here
|
| 639 |
} |
638 |
} |
| 640 |
|
639 |
|
| 641 |
sub ReversePayment { |
640 |
sub ReversePayment { |
| 642 |
my ( $borrowernumber, $accountno ) = @_; |
641 |
my ( $accountlinesid ) = @_; |
| 643 |
my $dbh = C4::Context->dbh; |
642 |
my $dbh = C4::Context->dbh; |
| 644 |
|
643 |
|
| 645 |
my $sth = $dbh->prepare('SELECT amountoutstanding FROM accountlines WHERE borrowernumber = ? AND accountno = ?'); |
644 |
my $sth = $dbh->prepare('SELECT amountoutstanding FROM accountlines WHERE accountlinesid = ?'); |
| 646 |
$sth->execute( $borrowernumber, $accountno ); |
645 |
$sth->execute( $accountlinesid ); |
| 647 |
my $row = $sth->fetchrow_hashref(); |
646 |
my $row = $sth->fetchrow_hashref(); |
| 648 |
my $amount_outstanding = $row->{'amountoutstanding'}; |
647 |
my $amount_outstanding = $row->{'amountoutstanding'}; |
| 649 |
|
648 |
|
| 650 |
if ( $amount_outstanding <= 0 ) { |
649 |
if ( $amount_outstanding <= 0 ) { |
| 651 |
$sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = amount * -1, description = CONCAT( description, " Reversed -" ) WHERE borrowernumber = ? AND accountno = ?'); |
650 |
$sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = amount * -1, description = CONCAT( description, " Reversed -" ) WHERE accountlinesid = ?'); |
| 652 |
$sth->execute( $borrowernumber, $accountno ); |
651 |
$sth->execute( $accountlinesid ); |
| 653 |
} else { |
652 |
} else { |
| 654 |
$sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = 0, description = CONCAT( description, " Reversed -" ) WHERE borrowernumber = ? AND accountno = ?'); |
653 |
$sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = 0, description = CONCAT( description, " Reversed -" ) WHERE accountlinesid = ?'); |
| 655 |
$sth->execute( $borrowernumber, $accountno ); |
654 |
$sth->execute( $accountlinesid ); |
| 656 |
} |
655 |
} |
| 657 |
} |
656 |
} |
| 658 |
|
657 |
|
| 659 |
=head2 recordpayment_selectaccts |
658 |
=head2 recordpayment_selectaccts |
|
Lines 695-701
sub recordpayment_selectaccts {
Link Here
|
| 695 |
|
694 |
|
| 696 |
# offset transactions |
695 |
# offset transactions |
| 697 |
my $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding= ? ' . |
696 |
my $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding= ? ' . |
| 698 |
'WHERE (borrowernumber = ?) AND (accountno=?)'); |
697 |
'WHERE accountlinesid=?'); |
| 699 |
for my $accdata ( @{$rows} ) { |
698 |
for my $accdata ( @{$rows} ) { |
| 700 |
if ($amountleft == 0) { |
699 |
if ($amountleft == 0) { |
| 701 |
last; |
700 |
last; |
|
Lines 708-715
sub recordpayment_selectaccts {
Link Here
|
| 708 |
$newamtos = $accdata->{amountoutstanding} - $amountleft; |
707 |
$newamtos = $accdata->{amountoutstanding} - $amountleft; |
| 709 |
$amountleft = 0; |
708 |
$amountleft = 0; |
| 710 |
} |
709 |
} |
| 711 |
my $thisacct = $accdata->{accountno}; |
710 |
my $thisacct = $accdata->{accountlinesid}; |
| 712 |
$sth->execute( $newamtos, $borrowernumber, $thisacct ); |
711 |
$sth->execute( $newamtos, $thisacct ); |
| 713 |
} |
712 |
} |
| 714 |
|
713 |
|
| 715 |
# create new line |
714 |
# create new line |
|
Lines 724-730
sub recordpayment_selectaccts {
Link Here
|
| 724 |
# makepayment needs to be fixed to handle partials till then this separate subroutine |
723 |
# makepayment needs to be fixed to handle partials till then this separate subroutine |
| 725 |
# fills in |
724 |
# fills in |
| 726 |
sub makepartialpayment { |
725 |
sub makepartialpayment { |
| 727 |
my ( $borrowernumber, $accountno, $amount, $user, $branch ) = @_; |
726 |
my ( $accountlinesid, $borrowernumber, $accountno, $amount, $user, $branch ) = @_; |
| 728 |
my $manager_id = 0; |
727 |
my $manager_id = 0; |
| 729 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
728 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
| 730 |
if (!$amount || $amount < 0) { |
729 |
if (!$amount || $amount < 0) { |
|
Lines 736-747
sub makepartialpayment {
Link Here
|
| 736 |
my $newamtos = 0; |
735 |
my $newamtos = 0; |
| 737 |
|
736 |
|
| 738 |
my $data = $dbh->selectrow_hashref( |
737 |
my $data = $dbh->selectrow_hashref( |
| 739 |
'SELECT * FROM accountlines WHERE borrowernumber=? AND accountno=?',undef,$borrowernumber,$accountno); |
738 |
'SELECT * FROM accountlines WHERE accountlinesid=?',undef,$accountlinesid); |
| 740 |
my $new_outstanding = $data->{amountoutstanding} - $amount; |
739 |
my $new_outstanding = $data->{amountoutstanding} - $amount; |
| 741 |
|
740 |
|
| 742 |
my $update = 'UPDATE accountlines SET amountoutstanding = ? WHERE borrowernumber = ? ' |
741 |
my $update = 'UPDATE accountlines SET amountoutstanding = ? WHERE accountlinesid = ? '; |
| 743 |
. ' AND accountno = ?'; |
742 |
$dbh->do( $update, undef, $new_outstanding, $accountlinesid); |
| 744 |
$dbh->do( $update, undef, $new_outstanding, $borrowernumber, $accountno); |
|
|
| 745 |
|
743 |
|
| 746 |
# create new line |
744 |
# create new line |
| 747 |
my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, ' |
745 |
my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, ' |