Lines 35-41
BEGIN {
Link Here
|
35 |
} |
35 |
} |
36 |
|
36 |
|
37 |
can_ok( 'C4::Accounts', |
37 |
can_ok( 'C4::Accounts', |
38 |
qw( recordpayment |
38 |
qw( |
39 |
makepayment |
39 |
makepayment |
40 |
getnextacctno |
40 |
getnextacctno |
41 |
chargelostitem |
41 |
chargelostitem |
Lines 139-145
for my $data (@test_data) {
Link Here
|
139 |
|
139 |
|
140 |
$dbh->do(q|DELETE FROM accountlines|); |
140 |
$dbh->do(q|DELETE FROM accountlines|); |
141 |
|
141 |
|
142 |
subtest "recordpayment() tests" => sub { |
142 |
subtest "Koha::Account::pay tests" => sub { |
143 |
|
143 |
|
144 |
plan tests => 10; |
144 |
plan tests => 10; |
145 |
|
145 |
|
Lines 156-161
subtest "recordpayment() tests" => sub {
Link Here
|
156 |
$borrower->branchcode( $branchcode ); |
156 |
$borrower->branchcode( $branchcode ); |
157 |
$borrower->store; |
157 |
$borrower->store; |
158 |
|
158 |
|
|
|
159 |
my $account = Koha::Account->new({ patron_id => $borrower->id }); |
160 |
|
159 |
my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 100 })->store(); |
161 |
my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 100 })->store(); |
160 |
my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 200 })->store(); |
162 |
my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 200 })->store(); |
161 |
$line1->_result->discard_changes; |
163 |
$line1->_result->discard_changes; |
Lines 166-172
subtest "recordpayment() tests" => sub {
Link Here
|
166 |
my $count = $sth->fetchrow_array; |
168 |
my $count = $sth->fetchrow_array; |
167 |
is($count, 2, 'There is 2 lines as expected'); |
169 |
is($count, 2, 'There is 2 lines as expected'); |
168 |
|
170 |
|
169 |
# Testing recordpayment ------------------------- |
|
|
170 |
# There is $100 in the account |
171 |
# There is $100 in the account |
171 |
$sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?"); |
172 |
$sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?"); |
172 |
my $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber); |
173 |
my $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber); |
Lines 179-187
subtest "recordpayment() tests" => sub {
Link Here
|
179 |
# We make a $20 payment |
180 |
# We make a $20 payment |
180 |
my $borrowernumber = $borrower->borrowernumber; |
181 |
my $borrowernumber = $borrower->borrowernumber; |
181 |
my $data = '20.00'; |
182 |
my $data = '20.00'; |
182 |
my $sys_paytype; |
|
|
183 |
my $payment_note = '$20.00 payment note'; |
183 |
my $payment_note = '$20.00 payment note'; |
184 |
recordpayment($borrowernumber, $data, $sys_paytype, $payment_note); |
184 |
$account->pay( { amount => $data, note => $payment_note } ); |
|
|
185 |
|
185 |
# There is now $280 in the account |
186 |
# There is now $280 in the account |
186 |
$sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?"); |
187 |
$sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?"); |
187 |
$amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber); |
188 |
$amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber); |
Lines 190-195
subtest "recordpayment() tests" => sub {
Link Here
|
190 |
$amountleft += $line; |
191 |
$amountleft += $line; |
191 |
} |
192 |
} |
192 |
is($amountleft, 280, 'The account has $280 as expected' ); |
193 |
is($amountleft, 280, 'The account has $280 as expected' ); |
|
|
194 |
|
193 |
# Is the payment note well registered |
195 |
# Is the payment note well registered |
194 |
$sth = $dbh->prepare("SELECT note FROM accountlines WHERE borrowernumber=? ORDER BY accountlines_id DESC LIMIT 1"); |
196 |
$sth = $dbh->prepare("SELECT note FROM accountlines WHERE borrowernumber=? ORDER BY accountlines_id DESC LIMIT 1"); |
195 |
$sth->execute($borrower->borrowernumber); |
197 |
$sth->execute($borrower->borrowernumber); |
Lines 199-205
subtest "recordpayment() tests" => sub {
Link Here
|
199 |
# We make a -$30 payment (a NEGATIVE payment) |
201 |
# We make a -$30 payment (a NEGATIVE payment) |
200 |
$data = '-30.00'; |
202 |
$data = '-30.00'; |
201 |
$payment_note = '-$30.00 payment note'; |
203 |
$payment_note = '-$30.00 payment note'; |
202 |
recordpayment($borrowernumber, $data, $sys_paytype, $payment_note); |
204 |
$account->pay( { amount => $data, note => $payment_note } ); |
|
|
205 |
|
203 |
# There is now $310 in the account |
206 |
# There is now $310 in the account |
204 |
$sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?"); |
207 |
$sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?"); |
205 |
$amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber); |
208 |
$amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber); |
Lines 217-223
subtest "recordpayment() tests" => sub {
Link Here
|
217 |
#We make a $150 payment ( > 1stLine ) |
220 |
#We make a $150 payment ( > 1stLine ) |
218 |
$data = '150.00'; |
221 |
$data = '150.00'; |
219 |
$payment_note = '$150.00 payment note'; |
222 |
$payment_note = '$150.00 payment note'; |
220 |
recordpayment($borrowernumber, $data, $sys_paytype, $payment_note); |
223 |
$account->pay( { amount => $data, note => $payment_note } ); |
|
|
224 |
|
221 |
# There is now $160 in the account |
225 |
# There is now $160 in the account |
222 |
$sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?"); |
226 |
$sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?"); |
223 |
$amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber); |
227 |
$amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber); |
Lines 235-241
subtest "recordpayment() tests" => sub {
Link Here
|
235 |
#We make a $200 payment ( > amountleft ) |
239 |
#We make a $200 payment ( > amountleft ) |
236 |
$data = '200.00'; |
240 |
$data = '200.00'; |
237 |
$payment_note = '$200.00 payment note'; |
241 |
$payment_note = '$200.00 payment note'; |
238 |
recordpayment($borrowernumber, $data, $sys_paytype, $payment_note); |
242 |
$account->pay( { amount => $data, note => $payment_note } ); |
|
|
243 |
|
239 |
# There is now -$40 in the account |
244 |
# There is now -$40 in the account |
240 |
$sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?"); |
245 |
$sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?"); |
241 |
$amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber); |
246 |
$amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber); |
242 |
- |
|
|