|
Lines 22-28
use strict;
Link Here
|
| 22 |
#use warnings; FIXME - Bug 2505 |
22 |
#use warnings; FIXME - Bug 2505 |
| 23 |
use C4::Context; |
23 |
use C4::Context; |
| 24 |
use C4::Stats; |
24 |
use C4::Stats; |
| 25 |
use C4::Members; |
25 |
use C4::Members qw(GetMemberAccountRecords); |
| 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 |
|
28 |
|
|
Lines 107-127
sub recordpayment {
Link Here
|
| 107 |
my $sth = $dbh->prepare( |
107 |
my $sth = $dbh->prepare( |
| 108 |
"SELECT * FROM accountlines |
108 |
"SELECT * FROM accountlines |
| 109 |
WHERE (borrowernumber = ?) AND (amountoutstanding<>0) |
109 |
WHERE (borrowernumber = ?) AND (amountoutstanding<>0) |
| 110 |
ORDER BY date" |
110 |
ORDER BY accountlines_id" |
| 111 |
); |
111 |
); |
| 112 |
$sth->execute($borrowernumber); |
112 |
$sth->execute($borrowernumber); |
|
|
113 |
|
| 114 |
my ( $total, undef, undef, $original_credit ) = C4::Members::GetMemberAccountRecords( $borrowernumber ); |
| 115 |
my $amount_to_pay = $total - $original_credit; |
| 116 |
my $amount_paid = $amount_to_pay; |
| 117 |
|
| 113 |
|
118 |
|
| 114 |
# offset transactions |
119 |
# offset transactions |
| 115 |
my @ids; |
120 |
my @ids; |
| 116 |
while ( ( $accdata = $sth->fetchrow_hashref ) and ( $amountleft > 0 ) ) { |
121 |
while ( ( $accdata = $sth->fetchrow_hashref ) ) { |
| 117 |
if ( $accdata->{'amountoutstanding'} < $amountleft ) { |
122 |
if ( $accdata->{'amountoutstanding'} < 0 ) { |
| 118 |
$newamtos = 0; |
123 |
if ( $amount_to_pay <= ( 0 - $accdata->{'amountoutstanding'} ) ) { |
| 119 |
$amountleft -= $accdata->{'amountoutstanding'}; |
124 |
$newamtos = $accdata->{'amountoutstanding'} + $amount_to_pay; |
|
|
125 |
$amount_to_pay = 0; |
| 126 |
} |
| 127 |
else { |
| 128 |
$newamtos = 0; |
| 129 |
$amount_to_pay += $accdata->{'amountoutstanding'}; |
| 130 |
} |
| 120 |
} |
131 |
} |
| 121 |
else { |
132 |
else { |
| 122 |
$newamtos = $accdata->{'amountoutstanding'} - $amountleft; |
133 |
$newamtos = 0; |
| 123 |
$amountleft = 0; |
|
|
| 124 |
} |
134 |
} |
|
|
135 |
|
| 125 |
my $thisacct = $accdata->{accountlines_id}; |
136 |
my $thisacct = $accdata->{accountlines_id}; |
| 126 |
my $usth = $dbh->prepare( |
137 |
my $usth = $dbh->prepare( |
| 127 |
"UPDATE accountlines SET amountoutstanding= ? |
138 |
"UPDATE accountlines SET amountoutstanding= ? |
|
Lines 146-151
sub recordpayment {
Link Here
|
| 146 |
} |
157 |
} |
| 147 |
} |
158 |
} |
| 148 |
|
159 |
|
|
|
160 |
|
| 149 |
# create new line |
161 |
# create new line |
| 150 |
my $usth = $dbh->prepare( |
162 |
my $usth = $dbh->prepare( |
| 151 |
"INSERT INTO accountlines |
163 |
"INSERT INTO accountlines |
|
Lines 155-167
sub recordpayment {
Link Here
|
| 155 |
|
167 |
|
| 156 |
my $paytype = "Pay"; |
168 |
my $paytype = "Pay"; |
| 157 |
$paytype .= $sip_paytype if defined $sip_paytype; |
169 |
$paytype .= $sip_paytype if defined $sip_paytype; |
| 158 |
$usth->execute( $borrowernumber, $nextaccntno, 0 - $data, $paytype, 0 - $amountleft, $manager_id, $payment_note ); |
170 |
$usth->execute( $borrowernumber, $nextaccntno, 0 - $amount_paid, $paytype, 0, $manager_id, $payment_note ); |
| 159 |
$usth->finish; |
171 |
$usth->finish; |
| 160 |
|
172 |
|
| 161 |
UpdateStats({ |
173 |
UpdateStats({ |
| 162 |
branch => $branch, |
174 |
branch => $branch, |
| 163 |
type =>'payment', |
175 |
type =>'payment', |
| 164 |
amount => $data, |
176 |
amount => $amount_paid, |
| 165 |
borrowernumber => $borrowernumber, |
177 |
borrowernumber => $borrowernumber, |
| 166 |
accountno => $nextaccntno } |
178 |
accountno => $nextaccntno } |
| 167 |
); |
179 |
); |
|
Lines 172-179
sub recordpayment {
Link Here
|
| 172 |
action => 'create_payment', |
184 |
action => 'create_payment', |
| 173 |
borrowernumber => $borrowernumber, |
185 |
borrowernumber => $borrowernumber, |
| 174 |
accountno => $nextaccntno, |
186 |
accountno => $nextaccntno, |
| 175 |
amount => $data * -1, |
187 |
amount => $amount_paid * -1, |
| 176 |
amountoutstanding => $amountleft * -1, |
188 |
amountoutstanding => $amount_to_pay * -1, |
| 177 |
accounttype => 'Pay', |
189 |
accounttype => 'Pay', |
| 178 |
accountlines_paid => \@ids, |
190 |
accountlines_paid => \@ids, |
| 179 |
manager_id => $manager_id, |
191 |
manager_id => $manager_id, |