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