|
Lines 20-25
use Modern::Perl;
Link Here
|
| 20 |
|
20 |
|
| 21 |
use Test::More tests => 27; |
21 |
use Test::More tests => 27; |
| 22 |
use Test::MockModule; |
22 |
use Test::MockModule; |
|
|
23 |
use Test::Exception; |
| 23 |
use Test::Warn; |
24 |
use Test::Warn; |
| 24 |
|
25 |
|
| 25 |
use t::lib::TestBuilder; |
26 |
use t::lib::TestBuilder; |
|
Lines 143-149
$dbh->do(q|DELETE FROM accountlines|);
Link Here
|
| 143 |
|
144 |
|
| 144 |
subtest "Koha::Account::pay tests" => sub { |
145 |
subtest "Koha::Account::pay tests" => sub { |
| 145 |
|
146 |
|
| 146 |
plan tests => 14; |
147 |
plan tests => 13; |
| 147 |
|
148 |
|
| 148 |
# Create a borrower |
149 |
# Create a borrower |
| 149 |
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; |
150 |
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; |
|
Lines 201-238
subtest "Koha::Account::pay tests" => sub {
Link Here
|
| 201 |
my $note = $sth->fetchrow_array; |
202 |
my $note = $sth->fetchrow_array; |
| 202 |
is($note,'$20.00 payment note', '$20.00 payment note is registered'); |
203 |
is($note,'$20.00 payment note', '$20.00 payment note is registered'); |
| 203 |
|
204 |
|
| 204 |
# We make a -$30 payment (a NEGATIVE payment) |
205 |
# We attempt to make a -$30 payment (a NEGATIVE payment) |
| 205 |
$data = '-30.00'; |
206 |
$data = '-30.00'; |
| 206 |
$payment_note = '-$30.00 payment note'; |
207 |
$payment_note = '-$30.00 payment note'; |
| 207 |
$account->pay( { amount => $data, note => $payment_note } ); |
208 |
throws_ok { $account->pay( { amount => $data, note => $payment_note } ) } qr//, 'Croaked on call to pay with negative amount'; |
| 208 |
|
|
|
| 209 |
# There is now $310 in the account |
| 210 |
$sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?"); |
| 211 |
$amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber); |
| 212 |
$amountleft = 0; |
| 213 |
for my $line ( @$amountoutstanding ) { |
| 214 |
$amountleft += $line; |
| 215 |
} |
| 216 |
is($amountleft, 310, 'The account has $310 as expected' ); |
| 217 |
# Is the payment note well registered |
| 218 |
$sth = $dbh->prepare("SELECT note FROM accountlines WHERE borrowernumber=? ORDER BY accountlines_id DESC LIMIT 1"); |
| 219 |
$sth->execute($borrower->borrowernumber); |
| 220 |
$note = $sth->fetchrow_array; |
| 221 |
is($note,'-$30.00 payment note', '-$30.00 payment note is registered'); |
| 222 |
|
209 |
|
| 223 |
#We make a $150 payment ( > 1stLine ) |
210 |
#We make a $150 payment ( > 1stLine ) |
| 224 |
$data = '150.00'; |
211 |
$data = '150.00'; |
| 225 |
$payment_note = '$150.00 payment note'; |
212 |
$payment_note = '$150.00 payment note'; |
| 226 |
$account->pay( { amount => $data, note => $payment_note } ); |
213 |
$account->pay( { amount => $data, note => $payment_note } ); |
| 227 |
|
214 |
|
| 228 |
# There is now $160 in the account |
215 |
# There is now $130 in the account |
| 229 |
$sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?"); |
216 |
$sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?"); |
| 230 |
$amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber); |
217 |
$amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber); |
| 231 |
$amountleft = 0; |
218 |
$amountleft = 0; |
| 232 |
for my $line ( @$amountoutstanding ) { |
219 |
for my $line ( @$amountoutstanding ) { |
| 233 |
$amountleft += $line; |
220 |
$amountleft += $line; |
| 234 |
} |
221 |
} |
| 235 |
is($amountleft, 160, 'The account has $160 as expected' ); |
222 |
is($amountleft, 130, 'The account has $130 as expected' ); |
| 236 |
|
223 |
|
| 237 |
# Is the payment note well registered |
224 |
# Is the payment note well registered |
| 238 |
$sth = $dbh->prepare("SELECT note FROM accountlines WHERE borrowernumber=? ORDER BY accountlines_id DESC LIMIT 1"); |
225 |
$sth = $dbh->prepare("SELECT note FROM accountlines WHERE borrowernumber=? ORDER BY accountlines_id DESC LIMIT 1"); |
|
Lines 245-258
subtest "Koha::Account::pay tests" => sub {
Link Here
|
| 245 |
$payment_note = '$200.00 payment note'; |
232 |
$payment_note = '$200.00 payment note'; |
| 246 |
$account->pay( { amount => $data, note => $payment_note } ); |
233 |
$account->pay( { amount => $data, note => $payment_note } ); |
| 247 |
|
234 |
|
| 248 |
# There is now -$40 in the account |
235 |
# There is now -$70 in the account |
| 249 |
$sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?"); |
236 |
$sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?"); |
| 250 |
$amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber); |
237 |
$amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber); |
| 251 |
$amountleft = 0; |
238 |
$amountleft = 0; |
| 252 |
for my $line ( @$amountoutstanding ) { |
239 |
for my $line ( @$amountoutstanding ) { |
| 253 |
$amountleft += $line; |
240 |
$amountleft += $line; |
| 254 |
} |
241 |
} |
| 255 |
is($amountleft, -40, 'The account has -$40 as expected, (credit situation)' ); |
242 |
is($amountleft, -70, 'The account has -$70 as expected, (credit situation)' ); |
| 256 |
|
243 |
|
| 257 |
# Is the payment note well registered |
244 |
# Is the payment note well registered |
| 258 |
$sth = $dbh->prepare("SELECT note FROM accountlines WHERE borrowernumber=? ORDER BY accountlines_id DESC LIMIT 1"); |
245 |
$sth = $dbh->prepare("SELECT note FROM accountlines WHERE borrowernumber=? ORDER BY accountlines_id DESC LIMIT 1"); |
|
Lines 352-358
subtest "Koha::Account::pay writeoff tests" => sub {
Link Here
|
| 352 |
my $writeoff = Koha::Account::Lines->find( $id ); |
339 |
my $writeoff = Koha::Account::Lines->find( $id ); |
| 353 |
|
340 |
|
| 354 |
is( $writeoff->credit_type_code, 'WRITEOFF', 'Type is correct for WRITEOFF' ); |
341 |
is( $writeoff->credit_type_code, 'WRITEOFF', 'Type is correct for WRITEOFF' ); |
| 355 |
is( $writeoff->description, 'Writeoff', 'Description is correct' ); |
342 |
is( $writeoff->description, '', 'Description is correct' ); |
| 356 |
is( $writeoff->amount+0, -42, 'Amount is correct' ); |
343 |
is( $writeoff->amount+0, -42, 'Amount is correct' ); |
| 357 |
}; |
344 |
}; |
| 358 |
|
345 |
|
|
Lines 411-417
subtest "More Koha::Account::pay tests" => sub {
Link Here
|
| 411 |
is( $stat->type, 'payment', "Correct statistic type" ); |
398 |
is( $stat->type, 'payment', "Correct statistic type" ); |
| 412 |
is( $stat->branch, $branch, "Correct branch logged to statistics" ); |
399 |
is( $stat->branch, $branch, "Correct branch logged to statistics" ); |
| 413 |
is( $stat->borrowernumber, $borrowernumber, "Correct borrowernumber logged to statistics" ); |
400 |
is( $stat->borrowernumber, $borrowernumber, "Correct borrowernumber logged to statistics" ); |
| 414 |
is( $stat->value+0, $amount, "Correct amount logged to statistics" ); |
401 |
is( $stat->value+0, -$amount, "Correct amount logged to statistics" ); |
| 415 |
} |
402 |
} |
| 416 |
}; |
403 |
}; |
| 417 |
|
404 |
|
|
Lines 471-477
subtest "Even more Koha::Account::pay tests" => sub {
Link Here
|
| 471 |
is( $stat->type, 'payment', "Correct statistic type" ); |
458 |
is( $stat->type, 'payment', "Correct statistic type" ); |
| 472 |
is( $stat->branch, $branch, "Correct branch logged to statistics" ); |
459 |
is( $stat->branch, $branch, "Correct branch logged to statistics" ); |
| 473 |
is( $stat->borrowernumber, $borrowernumber, "Correct borrowernumber logged to statistics" ); |
460 |
is( $stat->borrowernumber, $borrowernumber, "Correct borrowernumber logged to statistics" ); |
| 474 |
is( $stat->value+0, $partialamount, "Correct amount logged to statistics" ); |
461 |
is( $stat->value+0, -$partialamount, "Correct amount logged to statistics" ); |
| 475 |
} |
462 |
} |
| 476 |
}; |
463 |
}; |
| 477 |
|
464 |
|