Bugzilla – Attachment 64065 Details for
Bug 18736
Problems in order calculations (rounding errors)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18736: Correctly handle rounding
Bug-18736-Correctly-handle-rounding.patch (text/plain), 17.75 KB, created by
Jonathan Druart
on 2017-06-06 19:11:33 UTC
(
hide
)
Description:
Bug 18736: Correctly handle rounding
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2017-06-06 19:11:33 UTC
Size:
17.75 KB
patch
obsolete
>From c6fa682f47a019c8c3bda039be44814ad9a4d5fd Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 6 Jun 2017 15:58:54 -0300 >Subject: [PATCH] Bug 18736: Correctly handle rounding > >The values displayed should be the sum of the rounded values, not the >reverse. > >In ModReceiveOrder, i am wondering if: > tax_value_on_ordering = quantity * format(ecost_tax_excluded) * format(tax_rate_on_ordering) > >is correct or if it must be: > tax_value_on_ordering = quantity * format(ecost_tax_excluded * tax_rate_on_ordering) > >Note: the second form is used in 16.06.00.042 (bug 13321) >--- > C4/Acquisition.pm | 18 +++++++++--------- > C4/Budgets.pm | 16 ++++++++-------- > acqui/basket.pl | 11 ++++++----- > acqui/basketgroup.pl | 9 +++++---- > acqui/invoice.pl | 5 +++-- > acqui/parcel.pl | 11 ++++++----- > acqui/pdfformat/layout3pages.pm | 6 +++--- > acqui/pdfformat/layout3pagesfr.pm | 6 +++--- > reports/orders_by_fund.pl | 4 ++-- > 9 files changed, 45 insertions(+), 41 deletions(-) > >diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm >index ed80b26484..65fd830c84 100644 >--- a/C4/Acquisition.pm >+++ b/C4/Acquisition.pm >@@ -1465,8 +1465,8 @@ sub ModReceiveOrder { > $dbh->do(q| > UPDATE aqorders > SET >- tax_value_on_ordering = quantity * ecost_tax_excluded * tax_rate_on_ordering, >- tax_value_on_receiving = quantity * unitprice_tax_excluded * tax_rate_on_receiving >+ tax_value_on_ordering = quantity * ROUND(ecost_tax_excluded, 2) * ROUND(tax_rate_on_ordering, 2), >+ tax_value_on_receiving = quantity * ROUND(unitprice_tax_excluded, 2) * ROUND(tax_rate_on_receiving, 2) > WHERE ordernumber = ? > |, undef, $order->{ordernumber}); > >@@ -1478,8 +1478,8 @@ sub ModReceiveOrder { > $order->{tax_rate_on_ordering} //= 0; > $order->{unitprice_tax_excluded} //= 0; > $order->{tax_rate_on_receiving} //= 0; >- $order->{tax_value_on_ordering} = $order->{quantity} * $order->{ecost_tax_excluded} * $order->{tax_rate_on_ordering}; >- $order->{tax_value_on_receiving} = $order->{quantity} * $order->{unitprice_tax_excluded} * $order->{tax_rate_on_receiving}; >+ $order->{tax_value_on_ordering} = $order->{quantity} * Koha::Number::Price->new($order->{ecost_tax_excluded})->format() * Koha::Number::Price->new($order->{tax_rate_on_ordering})->format(); >+ $order->{tax_value_on_receiving} = $order->{quantity} * Koha::Number::Price->new($order->{unitprice_tax_excluded})->format() * Koha::Number::Price->new($order->{tax_rate_on_receiving})->format(); > $order->{datereceived} = $datereceived; > $order->{invoiceid} = $invoice->{invoiceid}; > $order->{orderstatus} = 'complete'; >@@ -1640,8 +1640,8 @@ sub CancelReceipt { > $dbh->do(q| > UPDATE aqorders > SET >- tax_value_on_ordering = quantity * ecost_tax_excluded * tax_rate_on_ordering, >- tax_value_on_receiving = quantity * unitprice_tax_excluded * tax_rate_on_receiving >+ tax_value_on_ordering = quantity * ROUND(ecost_tax_excluded, 2) * ROUND(tax_rate_on_ordering, 2), >+ tax_value_on_receiving = quantity * ROUND(unitprice_tax_excluded, 2) * ROUND(tax_rate_on_receiving, 2) > WHERE ordernumber = ? > |, undef, $parent_ordernumber); > >@@ -2155,7 +2155,7 @@ sub GetLateOrders { > # FIXME: account for IFNULL as above > $select .= " > aqorders.quantity AS quantity, >- aqorders.quantity * aqorders.rrp AS subtotal, >+ aqorders.quantity * ROUND(aqorders.rrp, 2) AS subtotal, > (CAST(now() AS date) - closedate) AS latesince > "; > if ( defined $delay ) { >@@ -2969,7 +2969,7 @@ sub populate_order_with_prices { > > # tax value = quantity * ecost tax excluded * tax rate > $order->{tax_value_on_ordering} = >- $order->{quantity} * $order->{ecost_tax_excluded} * $order->{tax_rate_on_ordering}; >+ $order->{quantity} * Koha::Number::Price->new( $order->{ecost_tax_excluded} )->format() * $order->{tax_rate_on_ordering}; > } > > if ($receiving) { >@@ -3003,7 +3003,7 @@ sub populate_order_with_prices { > } > > # tax value = quantity * unit price tax excluded * tax rate >- $order->{tax_value_on_receiving} = $order->{quantity} * $order->{unitprice_tax_excluded} * $order->{tax_rate_on_receiving}; >+ $order->{tax_value_on_receiving} = $order->{quantity} * Koha::Number::Price->new( $order->{unitprice_tax_excluded} ) * $order->{tax_rate_on_receiving}; > } > > return $order; >diff --git a/C4/Budgets.pm b/C4/Budgets.pm >index c68fbecd3e..9ed54cb67b 100644 >--- a/C4/Budgets.pm >+++ b/C4/Budgets.pm >@@ -212,7 +212,7 @@ sub GetBudgetsPlanCell { > # get the actual amount > $sth = $dbh->prepare( qq| > >- SELECT SUM(ecost_tax_included) AS actual FROM aqorders >+ SELECT SUM(ROUND(ecost_tax_included, 2)) AS actual FROM aqorders > WHERE budget_id = ? AND > entrydate like "$cell->{'authvalue'}%" | > ); >@@ -221,7 +221,7 @@ sub GetBudgetsPlanCell { > # get the actual amount > $sth = $dbh->prepare( qq| > >- SELECT SUM(ecost_tax_included) FROM aqorders >+ SELECT SUM(ROUD(ecost_tax_included, 2)) FROM aqorders > LEFT JOIN aqorders_items > ON (aqorders.ordernumber = aqorders_items.ordernumber) > LEFT JOIN items >@@ -233,7 +233,7 @@ sub GetBudgetsPlanCell { > # get the actual amount > $sth = $dbh->prepare( qq| > >- SELECT SUM( ecost_tax_included * quantity) AS actual >+ SELECT SUM( ROUND(ecost_tax_included, 2) * quantity) AS actual > FROM aqorders JOIN biblioitems > ON (biblioitems.biblionumber = aqorders.biblionumber ) > WHERE aqorders.budget_id = ? and itemtype = ? | >@@ -246,7 +246,7 @@ sub GetBudgetsPlanCell { > # get the actual amount > $sth = $dbh->prepare( qq| > >- SELECT SUM(ecost_tax_included * quantity) AS actual >+ SELECT SUM(ROUND(ecost_tax_included, 2) * quantity) AS actual > FROM aqorders > JOIN aqbudgets ON (aqbudgets.budget_id = aqorders.budget_id ) > WHERE aqorders.budget_id = ? AND >@@ -330,7 +330,7 @@ sub GetBudgetSpent { > # unitprice_tax_included should always been set here > # we should not need to retrieve ecost_tax_included > my $sth = $dbh->prepare(qq| >- SELECT SUM( COALESCE(unitprice_tax_included, ecost_tax_included) * quantity ) AS sum FROM aqorders >+ SELECT SUM( ROUND(COALESCE(unitprice_tax_included, ecost_tax_included), 2) * quantity ) AS sum FROM aqorders > WHERE budget_id = ? AND > quantityreceived > 0 AND > datecancellationprinted IS NULL >@@ -339,7 +339,7 @@ sub GetBudgetSpent { > my $sum = $sth->fetchrow_array; > > $sth = $dbh->prepare(qq| >- SELECT SUM(shipmentcost) AS sum >+ SELECT SUM(ROUND(shipmentcost, 2)) AS sum > FROM aqinvoices > WHERE shipmentcost_budgetid = ? > AND closedate IS NOT NULL >@@ -356,7 +356,7 @@ sub GetBudgetOrdered { > my ($budget_id) = @_; > my $dbh = C4::Context->dbh; > my $sth = $dbh->prepare(qq| >- SELECT SUM(ecost_tax_included * quantity) AS sum FROM aqorders >+ SELECT SUM(ROUND(ecost_tax_included, 2) * quantity) AS sum FROM aqorders > WHERE budget_id = ? AND > quantityreceived = 0 AND > datecancellationprinted IS NULL >@@ -365,7 +365,7 @@ sub GetBudgetOrdered { > my $sum = $sth->fetchrow_array; > > $sth = $dbh->prepare(qq| >- SELECT SUM(shipmentcost) AS sum >+ SELECT SUM(ROUND(shipmentcost, 2)) AS sum > FROM aqinvoices > WHERE shipmentcost_budgetid = ? > AND closedate IS NULL >diff --git a/acqui/basket.pl b/acqui/basket.pl >index 244e471a9b..6b8e9eaf6d 100755 >--- a/acqui/basket.pl >+++ b/acqui/basket.pl >@@ -41,6 +41,7 @@ use Date::Calc qw/Add_Delta_Days/; > use Koha::Database; > use Koha::EDI qw( create_edi_order get_edifact_ean ); > use Koha::CsvProfiles; >+use Koha::Number::Price; > > =head1 NAME > >@@ -348,13 +349,13 @@ if ( $op eq 'list' ) { > push @books_loop, $line; > > $foot{$$line{tax_rate}}{tax_rate} = $$line{tax_rate}; >- $foot{$$line{tax_rate}}{tax_value} += $$line{tax_value}; >+ $foot{$$line{tax_rate}}{tax_value} += Koha::Number::Price->new( $$line{tax_value} )->format; > $total_tax_value += $$line{tax_value}; > $foot{$$line{tax_rate}}{quantity} += $$line{quantity}; > $total_quantity += $$line{quantity}; >- $foot{$$line{tax_rate}}{total_tax_excluded} += $$line{total_tax_excluded}; >+ $foot{$$line{tax_rate}}{total_tax_excluded} += Koha::Number::Price->new( $$line{total_tax_excluded} )->format; > $total_tax_excluded += $$line{total_tax_excluded}; >- $foot{$$line{tax_rate}}{total_tax_included} += $$line{total_tax_included}; >+ $foot{$$line{tax_rate}}{total_tax_included} += Koha::Number::Price->new( $$line{total_tax_included} )->format; > $total_tax_included += $$line{total_tax_included}; > } > >@@ -454,8 +455,8 @@ sub get_order_infos { > $line{basketno} = $basketno; > $line{budget_name} = $budget->{budget_name}; > >- $line{total_tax_included} = $line{ecost_tax_included} * $line{quantity}; >- $line{total_tax_excluded} = $line{ecost_tax_excluded} * $line{quantity}; >+ $line{total_tax_included} = Koha::Number::Price->new( $line{ecost_tax_included} )->format * $line{quantity}; >+ $line{total_tax_excluded} = Koha::Number::Price->new( $line{ecost_tax_excluded} )->format * $line{quantity}; > $line{tax_value} = $line{tax_value_on_ordering}; > $line{tax_rate} = $line{tax_rate_on_ordering}; > >diff --git a/acqui/basketgroup.pl b/acqui/basketgroup.pl >index 9e50484de7..3e2f98f629 100755 >--- a/acqui/basketgroup.pl >+++ b/acqui/basketgroup.pl >@@ -57,6 +57,7 @@ use Koha::EDI qw/create_edi_order get_edifact_ean/; > > use Koha::Acquisition::Booksellers; > use Koha::ItemTypes; >+use Koha::Number::Price; > > our $input=new CGI; > >@@ -77,9 +78,9 @@ sub BasketTotal { > for my $order (@orders){ > # FIXME The following is wrong > if ( $bookseller->listincgst ) { >- $total = $total + ( $order->{ecost_tax_included} * $order->{quantity} ); >+ $total = $total + ( Koha::Number::Price->new($order->{ecost_tax_included})->format() * $order->{quantity} ); > } else { >- $total = $total + ( $order->{ecost_tax_excluded} * $order->{quantity} ); >+ $total = $total + ( Koha::Number::Price->new($order->{ecost_tax_excluded})->format() * $order->{quantity} ); > } > } > $total .= " " . ($bookseller->invoiceprice // 0); >@@ -171,8 +172,8 @@ sub printbasketgrouppdf{ > > $ord->{tax_value} = $ord->{tax_value_on_ordering}; > $ord->{tax_rate} = $ord->{tax_rate_on_ordering}; >- $ord->{total_tax_included} = $ord->{ecost_tax_included} * $ord->{quantity}; >- $ord->{total_tax_excluded} = $ord->{ecost_tax_excluded} * $ord->{quantity}; >+ $ord->{total_tax_included} = Koha::Number::Price->new($ord->{ecost_tax_included})->format() * $ord->{quantity}; >+ $ord->{total_tax_excluded} = Koha::Number::Price->new($ord->{ecost_tax_excluded})->format() * $ord->{quantity}; > > my $bib = GetBiblioData($ord->{biblionumber}); > >diff --git a/acqui/invoice.pl b/acqui/invoice.pl >index 3ab2d9f7c2..b3d48756de 100755 >--- a/acqui/invoice.pl >+++ b/acqui/invoice.pl >@@ -38,6 +38,7 @@ use C4::Budgets; > use Koha::Acquisition::Booksellers; > use Koha::Acquisition::Currencies; > use Koha::DateUtils; >+use Koha::Number::Price; > use Koha::Misc::Files; > > my $input = new CGI; >@@ -124,8 +125,8 @@ my $total_tax_value = 0; > foreach my $order (@$orders) { > my $line = get_infos( $order, $bookseller); > >- $line->{total_tax_excluded} = $line->{unitprice_tax_excluded} * $line->{quantity}; >- $line->{total_tax_included} = $line->{unitprice_tax_included} * $line->{quantity}; >+ $line->{total_tax_excluded} = Koha::Price::Number->new($line->{unitprice_tax_excluded})->format() * $line->{quantity}; >+ $line->{total_tax_included} = Koha::Price::Number->new($line->{unitprice_tax_included})->format() * $line->{quantity}; > > $line->{tax_value} = $line->{tax_value_on_receiving}; > $line->{tax_rate} = $line->{tax_rate_on_receiving}; >diff --git a/acqui/parcel.pl b/acqui/parcel.pl >index 4ba5b5fe30..e7575e6d3c 100755 >--- a/acqui/parcel.pl >+++ b/acqui/parcel.pl >@@ -70,6 +70,7 @@ use Koha::Acquisition::Bookseller; > use Koha::Biblios; > use Koha::DateUtils; > use Koha::Biblios; >+use Koha::Number::Price; > > use JSON; > >@@ -134,7 +135,7 @@ for my $order ( @orders ) { > $order->{unitprice} = $order->{unitprice_tax_excluded}; > } > >- $order->{total} = $order->{unitprice} * $order->{quantity}; >+ $order->{total} = Koha::Number::Price->new($order->{unitprice})->format() * $order->{quantity}; > > my %line = %{ $order }; > $line{invoice} = $invoice->{invoicenumber}; >@@ -152,8 +153,8 @@ for my $order ( @orders ) { > $line{tax_rate} = $line{tax_rate_on_receiving}; > $foot{$line{tax_rate}}{tax_rate} = $line{tax_rate}; > $foot{$line{tax_rate}}{tax_value} += $line{tax_value}; >- $total_tax_excluded += $line{unitprice_tax_excluded} * $line{quantity}; >- $total_tax_included += $line{unitprice_tax_included} * $line{quantity}; >+ $total_tax_excluded += Koha::Number::Price->new($line{unitprice_tax_excluded})->format() * $line{quantity}; >+ $total_tax_included += Koha::Number::Price->new($line{unitprice_tax_included})->format() * $line{quantity}; > > my $suggestion = GetSuggestionInfoFromBiblionumber($line{biblionumber}); > $line{suggestionid} = $suggestion->{suggestionid}; >@@ -172,7 +173,7 @@ for my $order ( @orders ) { > my $budget_name = GetBudgetName( $line{budget_id} ); > $line{budget_name} = $budget_name; > >- $subtotal_for_funds->{ $line{budget_name} }{ecost} += $order->{ecost} * $order->{quantity}; >+ $subtotal_for_funds->{ $line{budget_name} }{ecost} += Koha::Number::Price->new($order->{ecost})->format() * $order->{quantity}; > $subtotal_for_funds->{ $line{budget_name} }{unitprice} += $order->{total}; > > push @loop_received, \%line; >@@ -230,7 +231,7 @@ unless( defined $invoice->{closedate} ) { > } else { > $order->{ecost} = $order->{ecost_tax_excluded}; > } >- $order->{total} = $order->{ecost} * $order->{quantity}; >+ $order->{total} = Koha::Price::Number->new($order->{ecost})->format() * $order->{quantity}; > > my %line = %$order; > >diff --git a/acqui/pdfformat/layout3pages.pm b/acqui/pdfformat/layout3pages.pm >index f825ed35f7..d91fcd1994 100644 >--- a/acqui/pdfformat/layout3pages.pm >+++ b/acqui/pdfformat/layout3pages.pm >@@ -222,9 +222,9 @@ sub printbaskets { > $total_tax_excluded += $ord->{total_tax_excluded}; > $total_tax_included += $ord->{total_tax_included}; > $totaltax_value += $ord->{tax_value}; >- $totaldiscount += ($ord->{rrp_tax_excluded} - $ord->{ecost_tax_excluded} ) * $ord->{quantity}; >- $total_rrp_tax_excluded += $ord->{rrp_tax_excluded} * $ord->{quantity}; >- $total_rrp_tax_included += $ord->{rrp_tax_included} * $ord->{quantity}; >+ $totaldiscount += (Koha::Price::Number->new($ord->{rrp_tax_excluded})->format() - Koha::Price::Number->new($ord->{ecost_tax_excluded})->format() ) * $ord->{quantity}; >+ $total_rrp_tax_excluded += Koha::Price::Number->new($ord->{rrp_tax_excluded})->format() * $ord->{quantity}; >+ $total_rrp_tax_included += Koha::Price::Number->new($ord->{rrp_tax_included})->format() * $ord->{quantity}; > push @gst, $ord->{tax_rate}; > } > @gst = uniq map { $_ * 100 } @gst; >diff --git a/acqui/pdfformat/layout3pagesfr.pm b/acqui/pdfformat/layout3pagesfr.pm >index 14b0cc0c38..1e07019739 100644 >--- a/acqui/pdfformat/layout3pagesfr.pm >+++ b/acqui/pdfformat/layout3pagesfr.pm >@@ -222,9 +222,9 @@ sub printbaskets { > $total_tax_excluded += $ord->{total_tax_excluded}; > $total_tax_included += $ord->{total_tax_included}; > $totaltax_value += $ord->{tax_value}; >- $totaldiscount += ($ord->{rrp_tax_excluded} - $ord->{ecost_tax_excluded} ) * $ord->{quantity}; >- $total_rrp_tax_excluded += $ord->{rrp_tax_excluded} * $ord->{quantity}; >- $total_rrp_tax_included += $ord->{rrp_tax_included} * $ord->{quantity}; >+ $totaldiscount += (Koha::Price::Number->new($ord->{rrp_tax_excluded})->format() - Koha::Price::Number->new($ord->{ecost_tax_excluded})->format() ) * $ord->{quantity}; >+ $total_rrp_tax_excluded += Koha::Price::Number->new($ord->{rrp_tax_excluded})->format() * $ord->{quantity}; >+ $total_rrp_tax_included += Koha::Price::Number->new($ord->{rrp_tax_included})->format() * $ord->{quantity}; > push @gst, $ord->{tax_rate}; > } > @gst = uniq map { $_ * 100 } @gst; >diff --git a/reports/orders_by_fund.pl b/reports/orders_by_fund.pl >index 469b2c2c8d..829a6f35d9 100755 >--- a/reports/orders_by_fund.pl >+++ b/reports/orders_by_fund.pl >@@ -105,8 +105,8 @@ if ( $get_orders ) { > > $order->{'title'} = $biblio->{'title'} || $order->{'biblionumber'}; > >- $order->{'total_rrp'} = $order->{'quantity'} * $order->{'rrp'}; >- $order->{'total_ecost'} = $order->{'quantity'} * $order->{'ecost'}; >+ $order->{'total_rrp'} = $order->{'quantity'} * Koha::Price::Number->new($order->{'rrp'})->format(); >+ $order->{'total_ecost'} = $order->{'quantity'} * Koha::Price::Number->new($order->{'ecost'})->format(); > > # Format the dates and currencies correctly > $order->{'datereceived'} = output_pref(dt_from_string($order->{'datereceived'})); >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 18736
:
64061
|
64065
|
70187
|
70188
|
70189
|
70768
|
71062
|
71063
|
71627
|
71628
|
71629
|
71630
|
71631
|
71632
|
74335
|
74336
|
74337
|
74338
|
74339
|
74340
|
74341
|
74342
|
74370
|
74371
|
74374
|
74397
|
74398
|
74422
|
74427
|
74438
|
76979
|
76980
|
76981
|
76982
|
76983
|
76984
|
76985
|
76986
|
76987
|
76988
|
76989
|
76990
|
76991
|
77614
|
77615
|
77616
|
77617
|
77618
|
78101
|
78120
|
78981
|
78982
|
78983
|
78984
|
78985
|
78986
|
78987
|
78988
|
79087
|
79088
|
79089
|
79090
|
79091
|
79092
|
79093
|
79094
|
79098
|
79099
|
79100
|
79101
|
79102
|
79103
|
79104
|
79105
|
79187
|
79223
|
79562
|
79563
|
82967
|
82968
|
82969
|
82970
|
82971
|
82972
|
82973
|
82974
|
82975
|
82976
|
82977
|
83212
|
83213
|
83214
|
83973
|
83974
|
83975
|
83976
|
83977
|
83978
|
83979
|
83980
|
83981
|
83982
|
83983
|
83984
|
83985
|
86646
|
86647
|
86648
|
86649
|
86650
|
86651
|
86652
|
86653
|
86654
|
86655
|
86656
|
86657
|
86658