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

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