sub balance {
my ($self) = @_;
- my $fines = Koha::Account::Lines->search(
+ return Koha::Account::Lines->search(
{
borrowernumber => $self->{patron_id},
- },
- {
- select => [ { sum => 'amountoutstanding' } ],
- as => ['total_amountoutstanding'],
}
- );
-
- return ( $fines->count )
- ? $fines->next->get_column('total_amountoutstanding') + 0
- : 0;
+ )->total_outstanding;
}
=head3 outstanding_debits
}
@not_fines = map { substr( $_, 0, $ACCOUNT_TYPE_LENGTH ) } uniq(@not_fines);
- my $non_issues_charges = Koha::Account::Lines->search(
+ return Koha::Account::Lines->search(
{
borrowernumber => $self->{patron_id},
accounttype => { -not_in => \@not_fines }
},
- {
- select => [ { sum => 'amountoutstanding' } ],
- as => ['non_issues_charges'],
- }
- );
- return $non_issues_charges->count
- ? $non_issues_charges->next->get_column('non_issues_charges') + 0
- : 0;
+ )->total_outstanding;
}
=head3 lines
sub total_outstanding {
my ( $self ) = @_;
- my $total = sum0( $self->get_column('amountoutstanding') );
-
- return $total;
+ my $lines = $self->search(
+ {},
+ {
+ select => [ { sum => 'amountoutstanding' } ],
+ as => ['total_amountoutstanding'],
+ }
+ );
+
+ return $lines->count
+ ? $lines->next->get_column('total_amountoutstanding') + 0
+ : 0;
}
=head2 Internal methods
accounttype => [ 'F', 'FU', 'L' ],
itemnumber => $issue->{itemnumber}
},
- { select => [ { sum => 'amountoutstanding' } ], as => ['charges'] }
);
- $issue->{charges} = $charges->count ? $charges->next->get_column('charges') : 0;
+ $issue->{charges} = $charges->total_outstanding;
my $rental_fines = Koha::Account::Lines->search(
{
amountoutstanding => { '>' => 0 },
accounttype => 'Rent',
itemnumber => $issue->{itemnumber}
- },
- {
- select => [ { sum => 'amountoutstanding' } ],
- as => ['rental_fines']
}
);
- $issue->{rentalfines} = $rental_fines->count ? $rental_fines->next->get_column('rental_fines') : 0;
+ $issue->{rentalfines} = $rental_fines->total_outstanding
my $marcrecord = GetMarcBiblio({
biblionumber => $issue->{'biblionumber'},