Lines 18-24
Link Here
|
18 |
|
18 |
|
19 |
use Modern::Perl; |
19 |
use Modern::Perl; |
20 |
|
20 |
|
21 |
use Test::More tests => 20; |
21 |
use Test::More tests => 21; |
22 |
use Test::MockModule; |
22 |
use Test::MockModule; |
23 |
use Test::Warn; |
23 |
use Test::Warn; |
24 |
|
24 |
|
Lines 253-265
subtest "Koha::Account::pay tests" => sub {
Link Here
|
253 |
is($note,'$200.00 payment note', '$200.00 payment note is registered'); |
253 |
is($note,'$200.00 payment note', '$200.00 payment note is registered'); |
254 |
|
254 |
|
255 |
my $line3 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 42, accounttype => 'TEST' })->store(); |
255 |
my $line3 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 42, accounttype => 'TEST' })->store(); |
256 |
my $payment_id = $account->pay( { accountlines_id => $line3->id, amount => 42 } ); |
256 |
my $payment_id = $account->pay( { lines => [$line3], amount => 42 } ); |
257 |
my $payment = Koha::Account::Lines->find( $payment_id ); |
257 |
my $payment = Koha::Account::Lines->find( $payment_id ); |
258 |
is( $payment->amount(), '-42.000000', "Payment paid the specified fine" ); |
258 |
is( $payment->amount(), '-42.000000', "Payment paid the specified fine" ); |
259 |
$line3 = Koha::Account::Lines->find( $line3->id ); |
259 |
$line3 = Koha::Account::Lines->find( $line3->id ); |
260 |
is( $line3->amountoutstanding, '0.000000', "Specified fine is paid" ); |
260 |
is( $line3->amountoutstanding, '0.000000', "Specified fine is paid" ); |
261 |
}; |
261 |
}; |
262 |
|
262 |
|
|
|
263 |
subtest "Koha::Account::pay particular line tests" => sub { |
264 |
|
265 |
plan tests => 5; |
266 |
|
267 |
# Create a borrower |
268 |
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; |
269 |
my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; |
270 |
|
271 |
my $borrower = Koha::Patron->new( { |
272 |
cardnumber => 'kylemhall', |
273 |
surname => 'Hall', |
274 |
firstname => 'Kyle', |
275 |
} ); |
276 |
$borrower->categorycode( $categorycode ); |
277 |
$borrower->branchcode( $branchcode ); |
278 |
$borrower->store; |
279 |
|
280 |
my $account = Koha::Account->new({ patron_id => $borrower->id }); |
281 |
|
282 |
my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 1 })->store(); |
283 |
my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 2 })->store(); |
284 |
my $line3 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 3 })->store(); |
285 |
my $line4 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 4 })->store(); |
286 |
|
287 |
is( $account->balance(), "10.000000", "Account balance is 10" ); |
288 |
|
289 |
$account->pay( |
290 |
{ |
291 |
lines => [$line2, $line3, $line4], |
292 |
amount => 4, |
293 |
} |
294 |
); |
295 |
|
296 |
$_->_result->discard_changes foreach ( $line1, $line2, $line3, $line4 ); |
297 |
|
298 |
# Line1 is not paid at all, as it was not passed in the lines param |
299 |
is( $line1->amountoutstanding, "1.000000", "Line 1 was not paid" ); |
300 |
# Line2 was paid in full, as it was the first in the lines list |
301 |
is( $line2->amountoutstanding, "0.000000", "Line 2 was paid in full" ); |
302 |
# Line3 was paid partially, as the remaining balance did not cover it entirely |
303 |
is( $line3->amountoutstanding, "1.000000", "Line 3 was paid to 1.00" ); |
304 |
# Line4 was not paid at all, as the payment was all used up by that point |
305 |
is( $line4->amountoutstanding, "4.000000", "Line 4 was not paid" ); |
306 |
}; |
307 |
|
263 |
subtest "makepayment() tests" => sub { |
308 |
subtest "makepayment() tests" => sub { |
264 |
|
309 |
|
265 |
plan tests => 6; |
310 |
plan tests => 6; |
266 |
- |
|
|