From 005fa26a39bb13c9749371b7263138a8dbafe263 Mon Sep 17 00:00:00 2001 From: Thibaud Guillot Date: Tue, 16 Jan 2024 16:02:11 +0100 Subject: [PATCH] Bug 35114: Fix calculation around basketgroup and basket details Test plan: 1) I purpose a simple way to test it with new fresh data. First of all go to one of your vendor and set a discount of 9%. Then create a new basket, add to basket a new line from an empty record. Set a vendor price to 15.90 and just add this order 2) Configure the basket.pl table to show all columns, see budgeted cost and actual cost (exc or inc). There is already a difference of one cent. 3) Let's take a look at the basket groups now, for this, close this basket. Go on tab menu and select basket group. Click on new basket group. Normally you will see the new basket created on step 1. The total here is 14.47.. and when you check on basket detail it's 14.46 cause this total (from basket groups) comes from ecost exc. while total line on basket detail comes from actual cost exc. 4) Apply this patch and see changes Sponsored-by: BibLibre --- acqui/basket.pl | 30 +++++++++++++++----------- acqui/basketgroup.pl | 8 +++---- koha-tmpl/intranet-tmpl/prog/js/acq.js | 2 +- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/acqui/basket.pl b/acqui/basket.pl index 33253aad47..6721e7267c 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -341,16 +341,22 @@ if ( $op eq 'list' ) { push @books_loop, $line; $foot{$$line{tax_rate}}{tax_rate} = $$line{tax_rate}; - $foot{$$line{tax_rate}}{tax_value} += get_rounded_price($$line{tax_value}); + $foot{$$line{tax_rate}}{tax_value} += $$line{tax_value}; $total_tax_value += $$line{tax_value}; - $foot{$$line{tax_rate}}{quantity} += get_rounded_price($$line{quantity}); + $foot{$$line{tax_rate}}{quantity} += $$line{quantity}; $total_quantity += $$line{quantity}; - $foot{$$line{tax_rate}}{total_tax_excluded} += $$line{total_tax_excluded}; - $total_tax_excluded += $$line{total_tax_excluded}; - $foot{$$line{tax_rate}}{total_tax_included} += $$line{total_tax_included}; - $total_tax_included += $$line{total_tax_included}; + $foot{$$line{tax_rate}}{total_tax_excluded} += $$line{sum_total_tax_excluded}; + $total_tax_excluded += $$line{sum_total_tax_excluded}; + $foot{$$line{tax_rate}}{total_tax_included} += $$line{sum_total_tax_included}; + $total_tax_included += $$line{sum_total_tax_included}; } + foreach my $tax_rate (keys %foot) { + $foot{$tax_rate}{total_tax_excluded} = get_rounded_price($foot{$tax_rate}{total_tax_excluded}); + $foot{$tax_rate}{total_tax_included} = get_rounded_price($foot{$tax_rate}{total_tax_included}); + } + + push @book_foot_loop, map {$_} values %foot; # Get cancelled orders @@ -408,9 +414,9 @@ if ( $op eq 'list' ) { book_foot_loop => \@book_foot_loop, cancelledorders_loop => \@cancelledorders_loop, total_quantity => $total_quantity, - total_tax_excluded => $total_tax_excluded, - total_tax_included => $total_tax_included, - total_tax_value => $total_tax_value, + total_tax_excluded => get_rounded_price($total_tax_excluded), + total_tax_included => get_rounded_price($total_tax_included), + total_tax_value => get_rounded_price($total_tax_value), currency => $active_currency->currency, listincgst => $bookseller->listincgst, basketgroups => $basketgroups, @@ -456,10 +462,8 @@ sub get_order_infos { # If we have an actual cost that should be the total, otherwise use the ecost $line{unitprice_tax_included} += 0; $line{unitprice_tax_excluded} += 0; - my $cost_tax_included = $line{unitprice_tax_included} || $line{ecost_tax_included}; - my $cost_tax_excluded = $line{unitprice_tax_excluded} || $line{ecost_tax_excluded}; - $line{total_tax_included} = get_rounded_price($cost_tax_included) * $line{quantity}; - $line{total_tax_excluded} = get_rounded_price($cost_tax_excluded) * $line{quantity}; + $line{total_tax_included} = $line{ecost_tax_included} * $line{quantity}; + $line{total_tax_excluded} = $line{ecost_tax_excluded} * $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 38f7b6b44c..1f83708002 100755 --- a/acqui/basketgroup.pl +++ b/acqui/basketgroup.pl @@ -75,14 +75,14 @@ sub BasketTotal { my $total = 0; my @orders = GetOrders($basketno); for my $order (@orders){ - # FIXME The following is wrong + # FIXME The following is wrong <- still true ? remove if patch 35114 fixed it if ( $bookseller->listincgst ) { - $total = $total + ( get_rounded_price($order->{ecost_tax_included}) * $order->{quantity} ); + $total = $total + ( $order->{ecost_tax_included} * $order->{quantity} ); } else { - $total = $total + ( get_rounded_price($order->{ecost_tax_excluded}) * $order->{quantity} ); + $total = $total + ( $order->{ecost_tax_excluded} * $order->{quantity} ); } } - return $total; + return get_rounded_price($total); } #displays all basketgroups and all closed baskets (in their respective groups) diff --git a/koha-tmpl/intranet-tmpl/prog/js/acq.js b/koha-tmpl/intranet-tmpl/prog/js/acq.js index 89e1ad1fc4..83e70b7361 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/acq.js +++ b/koha-tmpl/intranet-tmpl/prog/js/acq.js @@ -190,7 +190,7 @@ function updateCosts(){ var rep = new Number(listprice*exchangerate); var ecost = rrp; if ( 100-discount != 100 ) { //Prevent rounding issues if no discount - ecost = new Number(Math.floor(rrp * (100 - discount )) / 100); + ecost = new Number(Math.round(rrp * (100 - discount )) / 100); } var total = new Number( ecost * quantity); $("#rrp").val(rrp.toFixed(2)); -- 2.30.2