Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# Copyright 2018 Koha Development team |
4 |
# |
5 |
# This file is part of Koha |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it |
8 |
# under the terms of the GNU General Public License as published by |
9 |
# the Free Software Foundation; either version 3 of the License, or |
10 |
# (at your option) any later version. |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but |
13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
# GNU General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses> |
19 |
|
20 |
use Modern::Perl; |
21 |
|
22 |
use Test::More tests => 1; |
23 |
use Test::Exception; |
24 |
|
25 |
use Koha::Account::Offsets; |
26 |
|
27 |
use t::lib::TestBuilder; |
28 |
|
29 |
my $schema = Koha::Database->new->schema; |
30 |
my $builder = t::lib::TestBuilder->new; |
31 |
|
32 |
subtest 'total_outstanding() tests' => sub { |
33 |
|
34 |
plan tests => 4; |
35 |
|
36 |
$schema->storage->txn_begin; |
37 |
|
38 |
my $line = $builder->build_object( { class => 'Koha::Account::Lines' } ); |
39 |
|
40 |
my $amount_1 = 100; |
41 |
my $amount_2 = 200; |
42 |
my $amount_3 = -100; |
43 |
my $amount_4 = -300; |
44 |
my $amount_5 = 500; |
45 |
|
46 |
my $offset_1 = Koha::Account::Offset->new( |
47 |
{ type => 'Fine', amount => $amount_1, credit_id => $line->id } )->store; |
48 |
my $offset_2 = Koha::Account::Offset->new( |
49 |
{ type => 'Fine', amount => $amount_2, credit_id => $line->id } )->store; |
50 |
my $offset_3 = Koha::Account::Offset->new( |
51 |
{ type => 'Payment', amount => $amount_3, credit_id => $line->id } )->store; |
52 |
my $offset_4 = Koha::Account::Offset->new( |
53 |
{ type => 'Payment', amount => $amount_4, credit_id => $line->id } )->store; |
54 |
my $offset_5 = Koha::Account::Offset->new( |
55 |
{ type => 'Fine', amount => $amount_5, credit_id => $line->id } )->store; |
56 |
|
57 |
my $debits = Koha::Account::Offsets->search( { type => 'Fine', credit_id => $line->id } ); |
58 |
is( $debits->total, $amount_1 + $amount_2 + $amount_5 ); |
59 |
|
60 |
my $credits = Koha::Account::Offsets->search( { type => 'Payment', credit_id => $line->id } ); |
61 |
is( $credits->total, $amount_3 + $amount_4 ); |
62 |
|
63 |
my $all = Koha::Account::Offsets->search( { credit_id => $line->id } ); |
64 |
is( $all->total, $amount_1 + $amount_2 + $amount_3 + $amount_4 + $amount_5 ); |
65 |
|
66 |
my $none = Koha::Account::Offsets->search( { credit_id => $line->id + 1 } ); |
67 |
is( $none->total, 0, 'No offsets, returns 0' ); |
68 |
|
69 |
$schema->storage->txn_rollback; |
70 |
}; |