=cut
sub credit_offsets {
- my ( $self ) = @_;
- my $rs = $self->_result->account_offsets_credits;
+ my ( $self, $cond, $attr ) = @_;
+ my $rs = $self->_result->search_related( 'account_offsets_credits', $cond, $attr);
return unless $rs;
return Koha::Account::Offsets->_new_from_dbic($rs);
}
=cut
sub debit_offsets {
- my ( $self ) = @_;
- my $rs = $self->_result->account_offsets_debits;
+ my ( $self, $cond, $attr ) = @_;
+ my $rs = $self->_result->search_related( 'account_offsets_debits', $cond, $attr);
return unless $rs;
return Koha::Account::Offsets->_new_from_dbic($rs);
}
my $offsets = $self->search(
{},
{
- select => [ { sum => 'amount' } ],
+ select => [ { sum => 'me.amount' } ],
as => ['total_amount'],
}
);
# some amount has been cancelled. collect the offsets that are not writeoffs
# this works because the only way to subtract from this kind of a debt is
# using the UI buttons 'Pay' and 'Write off'
- my $credits_offsets = Koha::Account::Offsets->search(
+ my $credit_offsets = $lost_charge->debit_offsets(
{
- debit_id => $lost_charge->id,
- credit_id => { '!=' => undef }, # it is not the debit itself
- type => { '!=' => 'Writeoff' },
- amount => { '<' => 0 } # credits are negative on the DB
- }
+ 'credit_id' => { '!=' => undef },
+ 'credit.credit_type_code' => { '!=' => 'Writeoff' }
+ },
+ { join => 'credit' }
);
- $total_to_refund = ( $credits_offsets->count > 0 )
- ? $credits_offsets->total * -1 # credits are negative on the DB
+ $total_to_refund = ( $credit_offsets->count > 0 )
+ ? $credit_offsets->total * -1 # credits are negative on the DB
: 0;
}
my $schema = Koha::Database->new->schema;
my $builder = t::lib::TestBuilder->new;
-subtest 'total_outstanding() tests' => sub {
+subtest 'total() tests' => sub {
plan tests => 4;