|
Lines 24-29
use C4::Context;
Link Here
|
| 24 |
use C4::Stats; |
24 |
use C4::Stats; |
| 25 |
use C4::Members; |
25 |
use C4::Members; |
| 26 |
use C4::Circulation qw(ReturnLostItem); |
26 |
use C4::Circulation qw(ReturnLostItem); |
|
|
27 |
use C4::Log qw(logaction); |
| 28 |
|
| 29 |
use Data::Dumper qw(Dumper); |
| 27 |
|
30 |
|
| 28 |
use vars qw($VERSION @ISA @EXPORT); |
31 |
use vars qw($VERSION @ISA @EXPORT); |
| 29 |
|
32 |
|
|
Lines 106-111
sub recordpayment {
Link Here
|
| 106 |
$sth->execute($borrowernumber); |
109 |
$sth->execute($borrowernumber); |
| 107 |
|
110 |
|
| 108 |
# offset transactions |
111 |
# offset transactions |
|
|
112 |
my @ids; |
| 109 |
while ( ( $accdata = $sth->fetchrow_hashref ) and ( $amountleft > 0 ) ) { |
113 |
while ( ( $accdata = $sth->fetchrow_hashref ) and ( $amountleft > 0 ) ) { |
| 110 |
if ( $accdata->{'amountoutstanding'} < $amountleft ) { |
114 |
if ( $accdata->{'amountoutstanding'} < $amountleft ) { |
| 111 |
$newamtos = 0; |
115 |
$newamtos = 0; |
|
Lines 121-135
sub recordpayment {
Link Here
|
| 121 |
WHERE (accountlines_id = ?)" |
125 |
WHERE (accountlines_id = ?)" |
| 122 |
); |
126 |
); |
| 123 |
$usth->execute( $newamtos, $thisacct ); |
127 |
$usth->execute( $newamtos, $thisacct ); |
| 124 |
$usth->finish; |
128 |
|
| 125 |
# $usth = $dbh->prepare( |
129 |
if ( C4::Context->preference("FinesLog") ) { |
| 126 |
# "INSERT INTO accountoffsets |
130 |
$accdata->{'amountoutstanding_new'} = $newamtos; |
| 127 |
# (borrowernumber, accountno, offsetaccount, offsetamount) |
131 |
logaction("FINES", 'MODIFY', $borrowernumber, Dumper({ |
| 128 |
# VALUES (?,?,?,?)" |
132 |
action => 'fee_payment', |
| 129 |
# ); |
133 |
borrowernumber => $accdata->{'borrowernumber'}, |
| 130 |
# $usth->execute( $borrowernumber, $accdata->{'accountno'}, |
134 |
old_amountoutstanding => $accdata->{'amountoutstanding'}, |
| 131 |
# $nextaccntno, $newamtos ); |
135 |
new_amountoutstanding => $newamtos, |
| 132 |
$usth->finish; |
136 |
amount_paid => $accdata->{'amountoutstanding'} - $newamtos, |
|
|
137 |
accountlines_id => $accdata->{'accountlines_id'}, |
| 138 |
accountno => $accdata->{'accountno'}, |
| 139 |
manager_id => $manager_id, |
| 140 |
})); |
| 141 |
push( @ids, $accdata->{'accountlines_id'} ); |
| 142 |
} |
| 133 |
} |
143 |
} |
| 134 |
|
144 |
|
| 135 |
# create new line |
145 |
# create new line |
|
Lines 139-147
sub recordpayment {
Link Here
|
| 139 |
VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?)" |
149 |
VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?)" |
| 140 |
); |
150 |
); |
| 141 |
$usth->execute( $borrowernumber, $nextaccntno, 0 - $data, 0 - $amountleft, $manager_id ); |
151 |
$usth->execute( $borrowernumber, $nextaccntno, 0 - $data, 0 - $amountleft, $manager_id ); |
| 142 |
$usth->finish; |
152 |
|
| 143 |
UpdateStats( $branch, 'payment', $data, '', '', '', $borrowernumber, $nextaccntno ); |
153 |
UpdateStats( $branch, 'payment', $data, '', '', '', $borrowernumber, $nextaccntno ); |
| 144 |
$sth->finish; |
154 |
|
|
|
155 |
if ( C4::Context->preference("FinesLog") ) { |
| 156 |
$accdata->{'amountoutstanding_new'} = $newamtos; |
| 157 |
logaction("FINES", 'CREATE',$borrowernumber,Dumper({ |
| 158 |
action => 'create_payment', |
| 159 |
borrowernumber => $borrowernumber, |
| 160 |
accountno => $nextaccntno, |
| 161 |
amount => $data * -1, |
| 162 |
amountoutstanding => $amountleft * -1, |
| 163 |
accounttype => 'Pay', |
| 164 |
accountlines_paid => \@ids, |
| 165 |
manager_id => $manager_id, |
| 166 |
})); |
| 167 |
} |
| 168 |
|
| 145 |
} |
169 |
} |
| 146 |
|
170 |
|
| 147 |
=head2 makepayment |
171 |
=head2 makepayment |
|
Lines 180-186
sub makepayment {
Link Here
|
| 180 |
my $data = $sth->fetchrow_hashref; |
204 |
my $data = $sth->fetchrow_hashref; |
| 181 |
$sth->finish; |
205 |
$sth->finish; |
| 182 |
|
206 |
|
| 183 |
if($data->{'accounttype'} eq "Pay"){ |
207 |
my $payment; |
|
|
208 |
if ( $data->{'accounttype'} eq "Pay" ){ |
| 184 |
my $udp = |
209 |
my $udp = |
| 185 |
$dbh->prepare( |
210 |
$dbh->prepare( |
| 186 |
"UPDATE accountlines |
211 |
"UPDATE accountlines |
|
Lines 202-208
sub makepayment {
Link Here
|
| 202 |
$udp->finish; |
227 |
$udp->finish; |
| 203 |
|
228 |
|
| 204 |
# create new line |
229 |
# create new line |
| 205 |
my $payment = 0 - $amount; |
230 |
$payment = 0 - $amount; |
| 206 |
|
231 |
|
| 207 |
my $ins = |
232 |
my $ins = |
| 208 |
$dbh->prepare( |
233 |
$dbh->prepare( |
|
Lines 214-225
sub makepayment {
Link Here
|
| 214 |
$ins->finish; |
239 |
$ins->finish; |
| 215 |
} |
240 |
} |
| 216 |
|
241 |
|
|
|
242 |
if ( C4::Context->preference("FinesLog") ) { |
| 243 |
logaction("FINES", 'MODIFY', $borrowernumber, Dumper({ |
| 244 |
action => 'fee_payment', |
| 245 |
borrowernumber => $borrowernumber, |
| 246 |
old_amountoutstanding => $data->{'amountoutstanding'}, |
| 247 |
new_amountoutstanding => 0, |
| 248 |
amount_paid => $data->{'amountoutstanding'}, |
| 249 |
accountlines_id => $data->{'accountlines_id'}, |
| 250 |
accountno => $data->{'accountno'}, |
| 251 |
manager_id => $manager_id, |
| 252 |
})); |
| 253 |
|
| 254 |
|
| 255 |
logaction("FINES", 'CREATE',$borrowernumber,Dumper({ |
| 256 |
action => 'create_payment', |
| 257 |
borrowernumber => $borrowernumber, |
| 258 |
accountno => $nextaccntno, |
| 259 |
amount => $payment, |
| 260 |
amountoutstanding => 0,, |
| 261 |
accounttype => 'Pay', |
| 262 |
accountlines_paid => [$data->{'accountlines_id'}], |
| 263 |
manager_id => $manager_id, |
| 264 |
})); |
| 265 |
} |
| 266 |
|
| 267 |
|
| 217 |
# FIXME - The second argument to &UpdateStats is supposed to be the |
268 |
# FIXME - The second argument to &UpdateStats is supposed to be the |
| 218 |
# branch code. |
269 |
# branch code. |
| 219 |
# UpdateStats is now being passed $accountno too. MTJ |
270 |
# UpdateStats is now being passed $accountno too. MTJ |
| 220 |
UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber, |
271 |
UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber, |
| 221 |
$accountno ); |
272 |
$accountno ); |
| 222 |
#from perldoc: for SELECT only #$sth->finish; |
|
|
| 223 |
|
273 |
|
| 224 |
#check to see what accounttype |
274 |
#check to see what accounttype |
| 225 |
if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) { |
275 |
if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) { |
|
Lines 314-320
sub chargelostitem{
Link Here
|
| 314 |
$sth2->execute($borrowernumber,$accountno,$amount, |
364 |
$sth2->execute($borrowernumber,$accountno,$amount, |
| 315 |
$description,$amount,$itemnumber,$manager_id); |
365 |
$description,$amount,$itemnumber,$manager_id); |
| 316 |
$sth2->finish; |
366 |
$sth2->finish; |
| 317 |
# FIXME: Log this ? |
367 |
|
|
|
368 |
if ( C4::Context->preference("FinesLog") ) { |
| 369 |
logaction("FINES", 'CREATE', $borrowernumber, Dumper({ |
| 370 |
action => 'create_fee', |
| 371 |
borrowernumber => $borrowernumber, |
| 372 |
accountno => $accountno, |
| 373 |
amount => $amount, |
| 374 |
amountoutstanding => $amount, |
| 375 |
description => $description, |
| 376 |
accounttype => 'L', |
| 377 |
itemnumber => $itemnumber, |
| 378 |
manager_id => $manager_id, |
| 379 |
})); |
| 380 |
} |
| 381 |
|
| 318 |
} |
382 |
} |
| 319 |
} |
383 |
} |
| 320 |
|
384 |
|
|
Lines 409-414
sub manualinvoice {
Link Here
|
| 409 |
$sth->execute( $borrowernumber, $accountno, $amount, $desc, $type, |
473 |
$sth->execute( $borrowernumber, $accountno, $amount, $desc, $type, |
| 410 |
$amountleft, $notifyid, $note, $manager_id ); |
474 |
$amountleft, $notifyid, $note, $manager_id ); |
| 411 |
} |
475 |
} |
|
|
476 |
} |
| 477 |
|
| 478 |
if ( C4::Context->preference("FinesLog") ) { |
| 479 |
logaction("FINES", 'CREATE',$borrowernumber,Dumper({ |
| 480 |
action => 'create_fee', |
| 481 |
borrowernumber => $borrowernumber, |
| 482 |
accountno => $accountno, |
| 483 |
amount => $amount, |
| 484 |
description => $desc, |
| 485 |
accounttype => $type, |
| 486 |
amountoutstanding => $amountleft, |
| 487 |
notify_id => $notifyid, |
| 488 |
note => $note, |
| 489 |
itemnumber => $itemnum, |
| 490 |
manager_id => $manager_id, |
| 491 |
})); |
| 492 |
} |
| 493 |
|
| 412 |
return 0; |
494 |
return 0; |
| 413 |
} |
495 |
} |
| 414 |
|
496 |
|
|
Lines 653-659
sub ReversePayment {
Link Here
|
| 653 |
my ( $accountlines_id ) = @_; |
735 |
my ( $accountlines_id ) = @_; |
| 654 |
my $dbh = C4::Context->dbh; |
736 |
my $dbh = C4::Context->dbh; |
| 655 |
|
737 |
|
| 656 |
my $sth = $dbh->prepare('SELECT amountoutstanding FROM accountlines WHERE accountlines_id = ?'); |
738 |
my $sth = $dbh->prepare('SELECT * FROM accountlines WHERE accountlines_id = ?'); |
| 657 |
$sth->execute( $accountlines_id ); |
739 |
$sth->execute( $accountlines_id ); |
| 658 |
my $row = $sth->fetchrow_hashref(); |
740 |
my $row = $sth->fetchrow_hashref(); |
| 659 |
my $amount_outstanding = $row->{'amountoutstanding'}; |
741 |
my $amount_outstanding = $row->{'amountoutstanding'}; |
|
Lines 665-670
sub ReversePayment {
Link Here
|
| 665 |
$sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = 0, description = CONCAT( description, " Reversed -" ) WHERE accountlines_id = ?'); |
747 |
$sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = 0, description = CONCAT( description, " Reversed -" ) WHERE accountlines_id = ?'); |
| 666 |
$sth->execute( $accountlines_id ); |
748 |
$sth->execute( $accountlines_id ); |
| 667 |
} |
749 |
} |
|
|
750 |
|
| 751 |
if ( C4::Context->preference("FinesLog") ) { |
| 752 |
my $manager_id = 0; |
| 753 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
| 754 |
|
| 755 |
if ( $amount_outstanding <= 0 ) { |
| 756 |
$row->{'amountoutstanding'} *= -1; |
| 757 |
} else { |
| 758 |
$row->{'amountoutstanding'} = '0'; |
| 759 |
} |
| 760 |
$row->{'description'} .= ' Reversed -'; |
| 761 |
logaction("FINES", 'MODIFY', $row->{'borrowernumber'}, Dumper({ |
| 762 |
action => 'reverse_fee_payment', |
| 763 |
borrowernumber => $row->{'borrowernumber'}, |
| 764 |
old_amountoutstanding => $row->{'amountoutstanding'}, |
| 765 |
new_amountoutstanding => 0 - $amount_outstanding,, |
| 766 |
accountlines_id => $row->{'accountlines_id'}, |
| 767 |
accountno => $row->{'accountno'}, |
| 768 |
manager_id => $manager_id, |
| 769 |
})); |
| 770 |
|
| 771 |
} |
| 772 |
|
| 668 |
} |
773 |
} |
| 669 |
|
774 |
|
| 670 |
=head2 recordpayment_selectaccts |
775 |
=head2 recordpayment_selectaccts |
|
Lines 709-714
sub recordpayment_selectaccts {
Link Here
|
| 709 |
# offset transactions |
814 |
# offset transactions |
| 710 |
my $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding= ? ' . |
815 |
my $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding= ? ' . |
| 711 |
'WHERE accountlines_id=?'); |
816 |
'WHERE accountlines_id=?'); |
|
|
817 |
|
| 818 |
my @ids; |
| 712 |
for my $accdata ( @{$rows} ) { |
819 |
for my $accdata ( @{$rows} ) { |
| 713 |
if ($amountleft == 0) { |
820 |
if ($amountleft == 0) { |
| 714 |
last; |
821 |
last; |
|
Lines 723-728
sub recordpayment_selectaccts {
Link Here
|
| 723 |
} |
830 |
} |
| 724 |
my $thisacct = $accdata->{accountlines_id}; |
831 |
my $thisacct = $accdata->{accountlines_id}; |
| 725 |
$sth->execute( $newamtos, $thisacct ); |
832 |
$sth->execute( $newamtos, $thisacct ); |
|
|
833 |
|
| 834 |
if ( C4::Context->preference("FinesLog") ) { |
| 835 |
logaction("FINES", 'MODIFY', $borrowernumber, Dumper({ |
| 836 |
action => 'fee_payment', |
| 837 |
borrowernumber => $borrowernumber, |
| 838 |
old_amountoutstanding => $accdata->{'amountoutstanding'}, |
| 839 |
new_amountoutstanding => $newamtos, |
| 840 |
amount_paid => $accdata->{'amountoutstanding'} - $newamtos, |
| 841 |
accountlines_id => $accdata->{'accountlines_id'}, |
| 842 |
accountno => $accdata->{'accountno'}, |
| 843 |
manager_id => $manager_id, |
| 844 |
})); |
| 845 |
push( @ids, $accdata->{'accountlines_id'} ); |
| 846 |
} |
| 847 |
|
| 726 |
} |
848 |
} |
| 727 |
|
849 |
|
| 728 |
# create new line |
850 |
# create new line |
|
Lines 731-736
sub recordpayment_selectaccts {
Link Here
|
| 731 |
q|VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?)|; |
853 |
q|VALUES (?,?,now(),?,'Payment,thanks','Pay',?,?)|; |
| 732 |
$dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft, $manager_id ); |
854 |
$dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft, $manager_id ); |
| 733 |
UpdateStats( $branch, 'payment', $amount, '', '', '', $borrowernumber, $nextaccntno ); |
855 |
UpdateStats( $branch, 'payment', $amount, '', '', '', $borrowernumber, $nextaccntno ); |
|
|
856 |
|
| 857 |
if ( C4::Context->preference("FinesLog") ) { |
| 858 |
logaction("FINES", 'CREATE',$borrowernumber,Dumper({ |
| 859 |
action => 'create_payment', |
| 860 |
borrowernumber => $borrowernumber, |
| 861 |
accountno => $nextaccntno, |
| 862 |
amount => 0 - $amount, |
| 863 |
amountoutstanding => 0 - $amountleft, |
| 864 |
accounttype => 'Pay', |
| 865 |
accountlines_paid => \@ids, |
| 866 |
manager_id => $manager_id, |
| 867 |
})); |
| 868 |
} |
| 869 |
|
| 734 |
return; |
870 |
return; |
| 735 |
} |
871 |
} |
| 736 |
|
872 |
|
|
Lines 755-760
sub makepartialpayment {
Link Here
|
| 755 |
my $update = 'UPDATE accountlines SET amountoutstanding = ? WHERE accountlines_id = ? '; |
891 |
my $update = 'UPDATE accountlines SET amountoutstanding = ? WHERE accountlines_id = ? '; |
| 756 |
$dbh->do( $update, undef, $new_outstanding, $accountlines_id); |
892 |
$dbh->do( $update, undef, $new_outstanding, $accountlines_id); |
| 757 |
|
893 |
|
|
|
894 |
if ( C4::Context->preference("FinesLog") ) { |
| 895 |
logaction("FINES", 'MODIFY', $borrowernumber, Dumper({ |
| 896 |
action => 'fee_payment', |
| 897 |
borrowernumber => $borrowernumber, |
| 898 |
old_amountoutstanding => $data->{'amountoutstanding'}, |
| 899 |
new_amountoutstanding => $new_outstanding, |
| 900 |
amount_paid => $data->{'amountoutstanding'} - $new_outstanding, |
| 901 |
accountlines_id => $data->{'accountlines_id'}, |
| 902 |
accountno => $data->{'accountno'}, |
| 903 |
manager_id => $manager_id, |
| 904 |
})); |
| 905 |
} |
| 906 |
|
| 758 |
# create new line |
907 |
# create new line |
| 759 |
my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, ' |
908 |
my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, ' |
| 760 |
. 'description, accounttype, amountoutstanding, itemnumber, manager_id) ' |
909 |
. 'description, accounttype, amountoutstanding, itemnumber, manager_id) ' |
|
Lines 765-770
sub makepartialpayment {
Link Here
|
| 765 |
|
914 |
|
| 766 |
UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber, $accountno ); |
915 |
UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber, $accountno ); |
| 767 |
|
916 |
|
|
|
917 |
if ( C4::Context->preference("FinesLog") ) { |
| 918 |
logaction("FINES", 'CREATE',$borrowernumber,Dumper({ |
| 919 |
action => 'create_payment', |
| 920 |
borrowernumber => $user, |
| 921 |
accountno => $nextaccntno, |
| 922 |
amount => 0 - $amount, |
| 923 |
accounttype => 'Pay', |
| 924 |
itemnumber => $data->{'itemnumber'}, |
| 925 |
accountlines_paid => [ $data->{'accountlines_id'} ], |
| 926 |
manager_id => $manager_id, |
| 927 |
})); |
| 928 |
} |
| 929 |
|
| 768 |
return; |
930 |
return; |
| 769 |
} |
931 |
} |
| 770 |
|
932 |
|
|
Lines 783-789
C<$branch> is the branchcode of the library where the writeoff occurred.
Link Here
|
| 783 |
=cut |
945 |
=cut |
| 784 |
|
946 |
|
| 785 |
sub WriteOffFee { |
947 |
sub WriteOffFee { |
| 786 |
my ( $borrowernumber, $accountline_id, $itemnum, $accounttype, $amount, $branch ) = @_; |
948 |
my ( $borrowernumber, $accountlines_id, $itemnum, $accounttype, $amount, $branch ) = @_; |
| 787 |
$branch ||= C4::Context->userenv->{branch}; |
949 |
$branch ||= C4::Context->userenv->{branch}; |
| 788 |
my $manager_id = 0; |
950 |
my $manager_id = 0; |
| 789 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
951 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
|
Lines 799-805
sub WriteOffFee {
Link Here
|
| 799 |
WHERE accountlines_id = ? AND borrowernumber = ? |
961 |
WHERE accountlines_id = ? AND borrowernumber = ? |
| 800 |
"; |
962 |
"; |
| 801 |
$sth = $dbh->prepare( $query ); |
963 |
$sth = $dbh->prepare( $query ); |
| 802 |
$sth->execute( $accountline_id, $borrowernumber ); |
964 |
$sth->execute( $accountlines_id, $borrowernumber ); |
|
|
965 |
|
| 966 |
if ( C4::Context->preference("FinesLog") ) { |
| 967 |
logaction("FINES", 'MODIFY', $borrowernumber, Dumper({ |
| 968 |
action => 'fee_writeoff', |
| 969 |
borrowernumber => $borrowernumber, |
| 970 |
accountlines_id => $accountlines_id, |
| 971 |
manager_id => $manager_id, |
| 972 |
})); |
| 973 |
} |
| 803 |
|
974 |
|
| 804 |
$query =" |
975 |
$query =" |
| 805 |
INSERT INTO accountlines |
976 |
INSERT INTO accountlines |
|
Lines 810-815
sub WriteOffFee {
Link Here
|
| 810 |
my $acct = getnextacctno($borrowernumber); |
981 |
my $acct = getnextacctno($borrowernumber); |
| 811 |
$sth->execute( $borrowernumber, $acct, $itemnum, $amount, $manager_id ); |
982 |
$sth->execute( $borrowernumber, $acct, $itemnum, $amount, $manager_id ); |
| 812 |
|
983 |
|
|
|
984 |
if ( C4::Context->preference("FinesLog") ) { |
| 985 |
logaction("FINES", 'CREATE',$borrowernumber,Dumper({ |
| 986 |
action => 'create_writeoff', |
| 987 |
borrowernumber => $borrowernumber, |
| 988 |
accountno => $acct, |
| 989 |
amount => 0 - $amount, |
| 990 |
accounttype => 'W', |
| 991 |
itemnumber => $itemnum, |
| 992 |
accountlines_paid => [ $accountlines_id ], |
| 993 |
manager_id => $manager_id, |
| 994 |
})); |
| 995 |
} |
| 996 |
|
| 813 |
UpdateStats( $branch, 'writeoff', $amount, q{}, q{}, q{}, $borrowernumber ); |
997 |
UpdateStats( $branch, 'writeoff', $amount, q{}, q{}, q{}, $borrowernumber ); |
| 814 |
|
998 |
|
| 815 |
} |
999 |
} |