Bug 3379 - Rounding error for fines total in C4::Members::GetMemberAccountRecords
Summary: Rounding error for fines total in C4::Members::GetMemberAccountRecords
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Staff interface (show other bugs)
Version: unspecified
Hardware: Other All
: P4 minor (vote)
Assignee: D Ruth Holloway
QA Contact:
URL:
Keywords:
Depends on:
Blocks: 18481 18487
  Show dependency treegraph
 
Reported: 2009-06-30 06:43 UTC by D Ruth Holloway
Modified: 2017-04-24 13:39 UTC (History)
2 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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);
}