View | Details | Raw Unified | Return to bug 20990
Collapse All | Expand All

(-)a/Koha/Account.pm (-14 / +4 lines)
Lines 415-421 sub outstanding_debits { Link Here
415
        }
415
        }
416
    );
416
    );
417
417
418
    # sum returns undef it list is empty
418
    # sum returns undef if list is empty
419
    my $total = sum( $lines->get_column('amountoutstanding') ) + 0;
419
    my $total = sum( $lines->get_column('amountoutstanding') ) + 0;
420
420
421
    return ( $total, $lines );
421
    return ( $total, $lines );
Lines 430-448 my ( $total, $lines ) = Koha::Account->new({ patron_id => $patron_id })->outstan Link Here
430
sub outstanding_credits {
430
sub outstanding_credits {
431
    my ($self) = @_;
431
    my ($self) = @_;
432
432
433
    my $outstanding_credits = Koha::Account::Lines->search(
434
        {   borrowernumber    => $self->{patron_id},
435
            amountoutstanding => { '<' => 0 }
436
        },
437
        {   select => [ { sum => 'amountoutstanding' } ],
438
            as     => ['outstanding_credits_total'],
439
        }
440
    );
441
    my $total
442
        = ( $outstanding_credits->count )
443
        ? $outstanding_credits->next->get_column('outstanding_credits_total') + 0
444
        : 0;
445
446
    my $lines = Koha::Account::Lines->search(
433
    my $lines = Koha::Account::Lines->search(
447
        {
434
        {
448
            borrowernumber    => $self->{patron_id},
435
            borrowernumber    => $self->{patron_id},
Lines 450-455 sub outstanding_credits { Link Here
450
        }
437
        }
451
    );
438
    );
452
439
440
    # sum returns undef if list is empty
441
    my $total = sum( $lines->get_column('amountoutstanding') ) + 0;
442
453
    return ( $total, $lines );
443
    return ( $total, $lines );
454
}
444
}
455
445
(-)a/t/db_dependent/Koha/Account.t (-2 / +5 lines)
Lines 67-73 subtest 'outstanding_debits() tests' => sub { Link Here
67
67
68
subtest 'outstanding_credits() tests' => sub {
68
subtest 'outstanding_credits() tests' => sub {
69
69
70
    plan tests => 5;
70
    plan tests => 7;
71
71
72
    $schema->storage->txn_begin;
72
    $schema->storage->txn_begin;
73
73
Lines 91-96 subtest 'outstanding_credits() tests' => sub { Link Here
91
        $i++;
91
        $i++;
92
    }
92
    }
93
93
94
    ( $total, $lines ) =  Koha::Account->new({ patron_id => 'InvalidBorrowernumber' })->outstanding_credits();
95
    is( $total, 0, "Total if no outstanding credits is 0" );
96
    is( $lines->count, 0, "With no outstanding credits, we get back a Lines object with 0 lines" );
97
94
    $schema->storage->txn_rollback;
98
    $schema->storage->txn_rollback;
95
};
99
};
96
100
97
- 

Return to bug 20990