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

(-)a/Koha/Account.pm (-19 / +4 lines)
Lines 421-439 Return the balance (sum of amountoutstanding columns) Link Here
421
421
422
sub balance {
422
sub balance {
423
    my ($self) = @_;
423
    my ($self) = @_;
424
    my $fines = Koha::Account::Lines->search(
424
    return Koha::Account::Lines->search(
425
        {
425
        {
426
            borrowernumber => $self->{patron_id},
426
            borrowernumber => $self->{patron_id},
427
        },
428
        {
429
            select => [ { sum => 'amountoutstanding' } ],
430
            as => ['total_amountoutstanding'],
431
        }
427
        }
432
    );
428
    )->total_outstanding;
433
434
    return ( $fines->count )
435
      ? $fines->next->get_column('total_amountoutstanding') + 0
436
      : 0;
437
}
429
}
438
430
439
=head3 outstanding_debits
431
=head3 outstanding_debits
Lines 509-527 sub non_issues_charges { Link Here
509
    }
501
    }
510
    @not_fines = map { substr( $_, 0, $ACCOUNT_TYPE_LENGTH ) } uniq(@not_fines);
502
    @not_fines = map { substr( $_, 0, $ACCOUNT_TYPE_LENGTH ) } uniq(@not_fines);
511
503
512
    my $non_issues_charges = Koha::Account::Lines->search(
504
    return Koha::Account::Lines->search(
513
        {
505
        {
514
            borrowernumber => $self->{patron_id},
506
            borrowernumber => $self->{patron_id},
515
            accounttype    => { -not_in => \@not_fines }
507
            accounttype    => { -not_in => \@not_fines }
516
        },
508
        },
517
        {
509
    )->total_outstanding;
518
            select => [ { sum => 'amountoutstanding' } ],
519
            as     => ['non_issues_charges'],
520
        }
521
    );
522
    return $non_issues_charges->count
523
      ? $non_issues_charges->next->get_column('non_issues_charges') + 0
524
      : 0;
525
}
510
}
526
511
527
1;
512
1;
(-)a/Koha/Account/Lines.pm (-3 / +11 lines)
Lines 46-54 empty it returns 0. Link Here
46
sub total_outstanding {
46
sub total_outstanding {
47
    my ( $self ) = @_;
47
    my ( $self ) = @_;
48
48
49
    my $total = sum0( $self->get_column('amountoutstanding') );
49
    my $lines = $self->search(
50
50
        {},
51
    return $total;
51
        {
52
            select => [ { sum => 'amountoutstanding' } ],
53
            as => ['total_amountoutstanding'],
54
        }
55
    );
56
57
    return $lines->count
58
      ? $lines->next->get_column('total_amountoutstanding') + 0
59
      : 0;
52
}
60
}
53
61
54
=head2 Internal methods
62
=head2 Internal methods
(-)a/opac/opac-user.pl (-8 / +2 lines)
Lines 197-205 if ( $pending_checkouts->count ) { # Useless test Link Here
197
                accounttype       => [ 'F', 'FU', 'L' ],
197
                accounttype       => [ 'F', 'FU', 'L' ],
198
                itemnumber        => $issue->{itemnumber}
198
                itemnumber        => $issue->{itemnumber}
199
            },
199
            },
200
            { select => [ { sum => 'amountoutstanding' } ], as => ['charges'] }
201
        );
200
        );
202
        $issue->{charges} = $charges->count ? $charges->next->get_column('charges') : 0;
201
        $issue->{charges} = $charges->total_outstanding;
203
202
204
        my $rental_fines = Koha::Account::Lines->search(
203
        my $rental_fines = Koha::Account::Lines->search(
205
            {
204
            {
Lines 207-219 if ( $pending_checkouts->count ) { # Useless test Link Here
207
                amountoutstanding => { '>' => 0 },
206
                amountoutstanding => { '>' => 0 },
208
                accounttype       => 'Rent',
207
                accounttype       => 'Rent',
209
                itemnumber        => $issue->{itemnumber}
208
                itemnumber        => $issue->{itemnumber}
210
            },
211
            {
212
                select => [ { sum => 'amountoutstanding' } ],
213
                as     => ['rental_fines']
214
            }
209
            }
215
        );
210
        );
216
        $issue->{rentalfines} = $rental_fines->count ? $rental_fines->next->get_column('rental_fines') : 0;
211
        $issue->{rentalfines} = $rental_fines->total_outstanding
217
212
218
        my $marcrecord = GetMarcBiblio({ biblionumber => $issue->{'biblionumber'} });
213
        my $marcrecord = GetMarcBiblio({ biblionumber => $issue->{'biblionumber'} });
219
        $issue->{'subtitle'} = GetRecordValue('subtitle', $marcrecord, GetFrameworkCode($issue->{'biblionumber'}));
214
        $issue->{'subtitle'} = GetRecordValue('subtitle', $marcrecord, GetFrameworkCode($issue->{'biblionumber'}));
220
- 

Return to bug 21673