Bug 3379

Summary: Rounding error for fines total in C4::Members::GetMemberAccountRecords
Product: Koha Reporter: D Ruth Holloway <ruth>
Component: Staff interfaceAssignee: D Ruth Holloway <ruth>
Status: CLOSED FIXED QA Contact:
Severity: minor    
Priority: P4 CC: katrin.fischer, veron
Version: unspecified   
Hardware: Other   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15741
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=17140
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Bug Depends on:    
Bug Blocks: 18481, 18487    

Description Chris Cormack 2010-05-21 01:09:48 UTC


---- Reported by dbavousett@ptfs.com 2009-06-30 18:43:03 ----

In this routine, perl retrieves all accountline records for a given borrower from the database, and shoves them into rows for handing back.  This works fine, as does the count of rows.  To return the total, however, it multiplies each row's amountoutstanding by 100, sums, then after the loop, divides by 100.

Internal documentation suggests that this is to prevent rounding error.   However, the data is already stored as decimal(28,6), and when there are large numbers of zero-balance items (thirty, in the example I discovered), this behavior actually *causes* rounding errors, causing the total to be low by 0.01.

There are two possible ways of handling this, perhaps.  Increase the multiply-and-divide to 1000, or eliminate it altogether.  The database correctly returns the sum when asked for SUM(amountoutstanding) WHERE borrowernumber=<foo>, which suggests to me that eliminating this bit of fan-dancing is probably the Right Thing.  Comments, please, but I intend to patch it one way or the other in the next day or two.



--- Bug imported by chris@bigballofwax.co.nz 2010-05-21 01:09 UTC  ---

This bug was previously known as _bug_ 3379 at http://bugs.koha.org/cgi-bin/bugzilla3/show_bug.cgi?id=3379

Unknown operating system Linux - Debian. Setting to default OS "All".
Actual time not defined. Setting to 0.0

Comment 1 Katrin Fischer 2013-04-13 17:12:36 UTC
The first suggestion for fixing this problem has been implemented:

    my $total = 0;
    while ( my $data = $sth->fetchrow_hashref ) {
        if ( $data->{itemnumber} ) {
            my $biblio = GetBiblioFromItemNumber( $data->{itemnumber} );
            $data->{biblionumber} = $biblio->{biblionumber};
            $data->{title}        = $biblio->{title};
        }
        $acctlines[$numlines] = $data;
        $numlines++;
        $total += int(1000 * $data->{'amountoutstanding'}); # convert float to integer to avoid round-off errors
    }
    $total /= 1000;
    return ( $total, \@acctlines,$numlines);
}