3 # Copyright 2018 Koha Development team
5 # This file is part of Koha
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.
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.
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>
22 use Test::More tests => 1;
25 use Koha::Account::Offsets;
27 use t::lib::TestBuilder;
29 my $schema = Koha::Database->new->schema;
30 my $builder = t::lib::TestBuilder->new;
32 subtest 'total_outstanding() tests' => sub {
36 $schema->storage->txn_begin;
38 my $line = $builder->build_object( { class => 'Koha::Account::Lines' } );
46 my $offset_1 = Koha::Account::Offset->new(
47 { type => 'OVERDUE', amount => $amount_1, credit_id => $line->id } )->store;
48 my $offset_2 = Koha::Account::Offset->new(
49 { type => 'OVERDUE', 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 => 'OVERDUE', amount => $amount_5, credit_id => $line->id } )->store;
57 my $debits = Koha::Account::Offsets->search( { type => 'OVERDUE', credit_id => $line->id } );
58 is( $debits->total, $amount_1 + $amount_2 + $amount_5 );
60 my $credits = Koha::Account::Offsets->search( { type => 'Payment', credit_id => $line->id } );
61 is( $credits->total, $amount_3 + $amount_4 );
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 );
66 my $none = Koha::Account::Offsets->search( { credit_id => $line->id + 1 } );
67 is( $none->total, 0, 'No offsets, returns 0' );
69 $schema->storage->txn_rollback;