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

(-)a/Koha/Account/Line.pm (-4 / +4 lines)
Lines 132-139 Return the credit_offsets linked to this account line if some exist Link Here
132
=cut
132
=cut
133
133
134
sub credit_offsets {
134
sub credit_offsets {
135
    my ( $self ) = @_;
135
    my ( $self, $cond, $attr ) = @_;
136
    my $rs = $self->_result->account_offsets_credits;
136
    my $rs = $self->_result->search_related( 'account_offsets_credits', $cond, $attr);
137
    return unless $rs;
137
    return unless $rs;
138
    return Koha::Account::Offsets->_new_from_dbic($rs);
138
    return Koha::Account::Offsets->_new_from_dbic($rs);
139
}
139
}
Lines 145-152 Return the debit_offsets linked to this account line if some exist Link Here
145
=cut
145
=cut
146
146
147
sub debit_offsets {
147
sub debit_offsets {
148
    my ( $self ) = @_;
148
    my ( $self, $cond, $attr ) = @_;
149
    my $rs = $self->_result->account_offsets_debits;
149
    my $rs = $self->_result->search_related( 'account_offsets_debits', $cond, $attr);
150
    return unless $rs;
150
    return unless $rs;
151
    return Koha::Account::Offsets->_new_from_dbic($rs);
151
    return Koha::Account::Offsets->_new_from_dbic($rs);
152
}
152
}
(-)a/Koha/Account/Offsets.pm (-1 / +1 lines)
Lines 51-57 sub total { Link Here
51
    my $offsets = $self->search(
51
    my $offsets = $self->search(
52
        {},
52
        {},
53
        {
53
        {
54
            select => [ { sum => 'amount' } ],
54
            select => [ { sum => 'me.amount' } ],
55
            as     => ['total_amount'],
55
            as     => ['total_amount'],
56
        }
56
        }
57
    );
57
    );
(-)a/Koha/Item.pm (-8 / +7 lines)
Lines 1006-1022 sub _set_found_trigger { Link Here
1006
                    # some amount has been cancelled. collect the offsets that are not writeoffs
1006
                    # some amount has been cancelled. collect the offsets that are not writeoffs
1007
                    # this works because the only way to subtract from this kind of a debt is
1007
                    # this works because the only way to subtract from this kind of a debt is
1008
                    # using the UI buttons 'Pay' and 'Write off'
1008
                    # using the UI buttons 'Pay' and 'Write off'
1009
                    my $credits_offsets = Koha::Account::Offsets->search(
1009
                    my $credit_offsets = $lost_charge->debit_offsets(
1010
                        {
1010
                        {
1011
                            debit_id  => $lost_charge->id,
1011
                            'credit_id'               => { '!=' => undef },
1012
                            credit_id => { '!=' => undef },     # it is not the debit itself
1012
                            'credit.credit_type_code' => { '!=' => 'Writeoff' }
1013
                            type      => { '!=' => 'Writeoff' },
1013
                        },
1014
                            amount    => { '<' => 0 }    # credits are negative on the DB
1014
                        { join => 'credit' }
1015
                        }
1016
                    );
1015
                    );
1017
1016
1018
                    $total_to_refund = ( $credits_offsets->count > 0 )
1017
                    $total_to_refund = ( $credit_offsets->count > 0 )
1019
                      ? $credits_offsets->total * -1    # credits are negative on the DB
1018
                      ? $credit_offsets->total * -1    # credits are negative on the DB
1020
                      : 0;
1019
                      : 0;
1021
                }
1020
                }
1022
1021
(-)a/t/db_dependent/Koha/Account/Offsets.t (-2 / +1 lines)
Lines 29-35 use t::lib::TestBuilder; Link Here
29
my $schema  = Koha::Database->new->schema;
29
my $schema  = Koha::Database->new->schema;
30
my $builder = t::lib::TestBuilder->new;
30
my $builder = t::lib::TestBuilder->new;
31
31
32
subtest 'total_outstanding() tests' => sub {
32
subtest 'total() tests' => sub {
33
33
34
    plan tests => 4;
34
    plan tests => 4;
35
35
36
- 

Return to bug 22435