@@ -, +, @@ tax_value_on_ordering = quantity * format(ecost_tax_excluded) * format(tax_rate_on_ordering) tax_value_on_ordering = quantity * format(ecost_tax_excluded * tax_rate_on_ordering) --- 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(-) --- a/C4/Acquisition.pm +++ a/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; --- a/C4/Budgets.pm +++ a/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 --- a/acqui/basket.pl +++ a/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}; --- a/acqui/basketgroup.pl +++ a/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}); --- a/acqui/invoice.pl +++ a/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}; --- a/acqui/parcel.pl +++ a/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; --- a/acqui/pdfformat/layout3pages.pm +++ a/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; --- a/acqui/pdfformat/layout3pagesfr.pm +++ a/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; --- a/reports/orders_by_fund.pl +++ a/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'})); --