- my ( $total , $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
- my $charges = 0;
- foreach my $ac (@$accts) {
- if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
- $charges += $ac->{'amountoutstanding'}
- if $ac->{'accounttype'} eq 'F';
- $charges += $ac->{'amountoutstanding'}
- if $ac->{'accounttype'} eq 'FU';
- $charges += $ac->{'amountoutstanding'}
- if $ac->{'accounttype'} eq 'L';
+ # Must be moved in a module if reused
+ my $charges = Koha::Account::Lines->search(
+ {
+ borrowernumber => $patron->borrowernumber,
+ amountoutstanding => { '>' => 0 },
+ accounttype => [ 'F', 'FU', 'L' ],
+ itemnumber => $issue->{itemnumber}
+ },
+ { select => [ { sum => 'amountoutstanding' } ], as => ['charges'] }
+ );
+ $issue->{charges} = $charges->count ? $charges->next->get_column('charges') : 0;
+
+ my $rental_fines = Koha::Account::Lines->search(
+ {
+ borrowernumber => $patron->borrowernumber,
+ amountoutstanding => { '>' => 0 },
+ accounttype => 'Rent',
+ itemnumber => $issue->{itemnumber}
+ },
+ {
+ select => [ { sum => 'amountoutstanding' } ],
+ as => ['rental_fines']