From d34add5e762a470a52fade37173b4491462ee22a Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Mon, 17 Mar 2008 09:24:00 +0000 Subject: [PATCH] Added rounding when needed to avoid document inconsistency --- includes/banking.inc | 2 +- purchasing/includes/supp_trans_class.inc | 6 ++++-- purchasing/includes/ui/po_ui.inc | 4 ++-- purchasing/po_entry_items.php | 3 --- purchasing/supplier_credit_grns.php | 2 +- purchasing/supplier_invoice_grns.php | 3 ++- reporting/rep107.php | 5 +++-- reporting/rep109.php | 5 +++-- reporting/rep110.php | 5 +++-- reporting/rep209.php | 5 +++-- sales/includes/cart_class.inc | 16 +++++++++------- sales/includes/ui/sales_credit_ui.inc | 3 ++- sales/includes/ui/sales_order_ui.inc | 3 ++- sales/view/view_credit.php | 3 ++- sales/view/view_dispatch.php | 3 ++- sales/view/view_invoice.php | 5 +++-- sales/view/view_sales_order.php | 3 ++- taxes/tax_calc.inc | 18 ++++++++++-------- 18 files changed, 54 insertions(+), 40 deletions(-) diff --git a/includes/banking.inc b/includes/banking.inc index a8a1c62e..d3ca75bd 100644 --- a/includes/banking.inc +++ b/includes/banking.inc @@ -104,7 +104,7 @@ function get_exchange_rate_to_home_currency($currency_code, $date_) function to_home_currency($amount, $currency_code, $date_) { $ex_rate = get_exchange_rate_to_home_currency($currency_code, $date_); - return $amount / $ex_rate; + return round($amount / $ex_rate, user_price_dec()); } //---------------------------------------------------------------------------------- diff --git a/purchasing/includes/supp_trans_class.inc b/purchasing/includes/supp_trans_class.inc index 596114c9..d6e06714 100644 --- a/purchasing/includes/supp_trans_class.inc +++ b/purchasing/includes/supp_trans_class.inc @@ -95,7 +95,8 @@ class supp_trans foreach ($this->grn_items as $ln_itm) { $items[] = $ln_itm->item_code; - $prices[] = ($ln_itm->this_quantity_inv * $ln_itm->taxfree_charge_price($tax_group_id, $tax_group)); + $prices[] =round( ($ln_itm->this_quantity_inv * $ln_itm->taxfree_charge_price($tax_group_id, $tax_group)), + user_price_dec()); } if ($tax_group_id == null) @@ -117,7 +118,8 @@ class supp_trans $tax_group = null; foreach ($this->grn_items as $ln_itm) - $total += ($ln_itm->this_quantity_inv * $ln_itm->taxfree_charge_price($tax_group_id, $tax_group)); + $total += round(($ln_itm->this_quantity_inv * $ln_itm->taxfree_charge_price($tax_group_id, $tax_group)), + user_price_dec()); foreach ($this->gl_codes as $gl_line) $total += $gl_line->amount; diff --git a/purchasing/includes/ui/po_ui.inc b/purchasing/includes/ui/po_ui.inc index 893de6b4..1bdac7e4 100644 --- a/purchasing/includes/ui/po_ui.inc +++ b/purchasing/includes/ui/po_ui.inc @@ -177,7 +177,7 @@ function display_po_items(&$order, $editable=true) if ($po_line->Deleted == false) { - $line_total = $po_line->quantity * $po_line->price; + $line_total = round($po_line->quantity * $po_line->price, user_price_dec()); if (!$editable || !isset($_GET['Edit']) || $_GET['Edit'] != $po_line->line_no) { alt_table_row_color($k); @@ -321,7 +321,7 @@ function po_item_controls(&$order, $stock_id=null) amount_cells(null, 'price', null); //$line_total = $_POST['qty'] * $_POST['price'] * (1 - $_POST['Disc'] / 100); - $line_total = input_num('qty') * input_num('price'); + $line_total = round(input_num('qty') * input_num('price'), user_price_dec()); amount_cell($line_total); if (isset($_GET['Edit'])) diff --git a/purchasing/po_entry_items.php b/purchasing/po_entry_items.php index 7e30f39e..ea7ae862 100644 --- a/purchasing/po_entry_items.php +++ b/purchasing/po_entry_items.php @@ -7,9 +7,6 @@ include_once($path_to_root . "/purchasing/includes/po_class.inc"); include_once($path_to_root . "/includes/session.inc"); -//include($path_to_root . "/includes/data_checks.inc"); -//include($path_to_root . "/includes/manufacturing.inc"); - include_once($path_to_root . "/purchasing/includes/purchasing_ui.inc"); $js = get_js_form_entry("StockID2", "stock_id", "qty"); diff --git a/purchasing/supplier_credit_grns.php b/purchasing/supplier_credit_grns.php index 15ea0830..3d18c98a 100644 --- a/purchasing/supplier_credit_grns.php +++ b/purchasing/supplier_credit_grns.php @@ -135,7 +135,7 @@ while ($myrow = db_fetch($result)) qty_cell($myrow["quantity_inv"]); qty_cell($myrow["qty_recd"] - $myrow["quantity_inv"]); amount_cell($myrow["unit_price"]); - amount_cell($myrow["unit_price"] * $myrow["quantity_inv"]); + amount_cell(round($myrow["unit_price"] * $myrow["quantity_inv"], user_price_dec())); end_row(); $i++; if ($i > 15) diff --git a/purchasing/supplier_invoice_grns.php b/purchasing/supplier_invoice_grns.php index ecbfe168..95c34519 100644 --- a/purchasing/supplier_invoice_grns.php +++ b/purchasing/supplier_invoice_grns.php @@ -164,7 +164,8 @@ function display_grn_items_for_selection() qty_cell($myrow["quantity_inv"]); qty_cell($myrow["qty_recd"] - $myrow["quantity_inv"]); amount_cell($myrow["unit_price"]); - amount_cell($myrow["unit_price"] * ($myrow["qty_recd"] - $myrow["quantity_inv"])); + amount_cell(round($myrow["unit_price"] * ($myrow["qty_recd"] - $myrow["quantity_inv"]), + user_price_dec())); end_row(); $i++; diff --git a/reporting/rep107.php b/reporting/rep107.php index 7baef1a4..06e30233 100644 --- a/reporting/rep107.php +++ b/reporting/rep107.php @@ -39,7 +39,7 @@ function print_invoices() $from = 0; if ($to == null) $to = 0; - $dec =user_price_dec(); + $dec = user_price_dec(); $fno = explode("-", $from); $tno = explode("-", $to); @@ -104,7 +104,8 @@ function print_invoices() $SubTotal = 0; while ($myrow2=db_fetch($result)) { - $Net = $sign * ((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]); + $Net = round($sign * ((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]), + user_price_dec()); $SubTotal += $Net; $DisplayPrice = number_format2($myrow2["unit_price"],$dec); $DisplayQty = number_format2($sign*$myrow2["quantity"],user_qty_dec()); diff --git a/reporting/rep109.php b/reporting/rep109.php index dac0e056..36d5e491 100644 --- a/reporting/rep109.php +++ b/reporting/rep109.php @@ -39,7 +39,7 @@ function print_sales_orders() $from = 0; if ($to == null) $to = 0; - $dec =user_price_dec(); + $dec = user_price_dec(); $cols = array(4, 60, 225, 300, 325, 385, 450, 515); @@ -92,7 +92,8 @@ function print_sales_orders() $SubTotal = 0; while ($myrow2=db_fetch($result)) { - $Net = ((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]); + $Net = round(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]), + user_price_dec()); $SubTotal += $Net; $DisplayPrice = number_format2($myrow2["unit_price"],$dec); $DisplayQty = number_format2($myrow2["quantity"],user_qty_dec()); diff --git a/reporting/rep110.php b/reporting/rep110.php index de81925b..d30d06a9 100644 --- a/reporting/rep110.php +++ b/reporting/rep110.php @@ -37,7 +37,7 @@ function print_deliveries() $from = 0; if ($to == null) $to = 0; - $dec =user_price_dec(); + $dec = user_price_dec(); $fno = explode("-", $from); $tno = explode("-", $to); @@ -83,7 +83,8 @@ function print_deliveries() $SubTotal = 0; while ($myrow2=db_fetch($result)) { - $Net = ((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]); + $Net = round(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]), + user_price_dec()); $SubTotal += $Net; $DisplayPrice = number_format2($myrow2["unit_price"],$dec); $DisplayQty = number_format2($myrow2["quantity"],user_qty_dec()); diff --git a/reporting/rep209.php b/reporting/rep209.php index 32108d5a..c2c3c0fe 100644 --- a/reporting/rep209.php +++ b/reporting/rep209.php @@ -61,7 +61,7 @@ function print_po() $from = 0; if ($to == null) $to = 0; - $dec =user_price_dec(); + $dec = user_price_dec(); $cols = array(4, 60, 225, 300, 325, 385, 450, 515); @@ -103,7 +103,8 @@ function print_po() $SubTotal = 0; while ($myrow2=db_fetch($result)) { - $Net = ($myrow2["unit_price"] * $myrow2["quantity_ordered"]); + $Net = round(($myrow2["unit_price"] * $myrow2["quantity_ordered"]), + user_price_dec()); $SubTotal += $Net; $DisplayPrice = number_format2($myrow2["unit_price"],$dec); $DisplayQty = number_format2($myrow2["quantity_ordered"],user_qty_dec()); diff --git a/sales/includes/cart_class.inc b/sales/includes/cart_class.inc index 463b7622..9a730136 100644 --- a/sales/includes/cart_class.inc +++ b/sales/includes/cart_class.inc @@ -268,7 +268,8 @@ class cart foreach ($this->line_items as $ln_itm) { $price = $ln_itm->line_price(); - $total += ($ln_itm->quantity * $price * (1 - $ln_itm->discount_percent)); + $total += round($ln_itm->quantity * $price * (1 - $ln_itm->discount_percent), + user_price_dec()); } return $total; } @@ -279,7 +280,8 @@ class cart foreach ($this->line_items as $ln_itm) { $price = $ln_itm->line_price(); - $total += ($ln_itm->qty_dispatched * $price * (1 - $ln_itm->discount_percent)); + $total += round(($ln_itm->qty_dispatched * $price * (1 - $ln_itm->discount_percent)), + user_price_dec()); } return $total; } @@ -326,12 +328,12 @@ class cart foreach ($this->line_items as $ln_itm) { $items[] = $ln_itm->stock_id; - $prices[] = ($ln_itm->qty_dispatched * - $ln_itm->line_price()* (1 - $ln_itm->discount_percent)); + $prices[] = round(($ln_itm->qty_dispatched * + $ln_itm->line_price()* (1 - $ln_itm->discount_percent)), user_price_dec()); } $taxes = get_tax_for_items($items, $prices, $shipping_cost, - $this->tax_group_id, $this->tax_included, $this->tax_group_array); + $this->tax_group_id, $this->tax_included, $this->tax_group_array); return $taxes; } @@ -360,9 +362,9 @@ class cart } } if($this->tax_included) - return $this->freight_cost*$tax_rate/($tax_rate+100); + return round($this->freight_cost*$tax_rate/($tax_rate+100), user_price_dec()); else - return $this->freight_cost*$tax_rate/100; + return round($this->freight_cost*$tax_rate/100, user_price_dec()); } } /* end of class defintion */ diff --git a/sales/includes/ui/sales_credit_ui.inc b/sales/includes/ui/sales_credit_ui.inc index 3eb1a399..06ef1fe0 100644 --- a/sales/includes/ui/sales_credit_ui.inc +++ b/sales/includes/ui/sales_credit_ui.inc @@ -117,7 +117,8 @@ function display_credit_items($title, &$order) foreach ($order->line_items as $line_no=>$line) { - $line_total = $line->qty_dispatched * $line->price * (1 - $line->discount_percent); + $line_total = round($line->qty_dispatched * $line->price * (1 - $line->discount_percent), + user_price_dec()); if (!isset($_GET['Edit'])) $id = -1; else diff --git a/sales/includes/ui/sales_order_ui.inc b/sales/includes/ui/sales_order_ui.inc index 23a2fc18..9329f816 100644 --- a/sales/includes/ui/sales_order_ui.inc +++ b/sales/includes/ui/sales_order_ui.inc @@ -100,7 +100,8 @@ function display_order_summary($title, &$order, $editable_items=false) foreach ($order->line_items as $line_no=>$stock_item) { - $line_total = $stock_item->qty_dispatched * $stock_item->price * (1 - $stock_item->discount_percent); + $line_total = round($stock_item->qty_dispatched * $stock_item->price * (1 - $stock_item->discount_percent), + user_price_dec()); if (!isset($_GET['Edit'])) $id = -1; diff --git a/sales/view/view_credit.php b/sales/view/view_credit.php index 0ba00089..ec14f031 100644 --- a/sales/view/view_credit.php +++ b/sales/view/view_credit.php @@ -90,7 +90,8 @@ if (db_num_rows($result) > 0) alt_table_row_color($k); - $value = ((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]); + $value = round(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]), + user_price_dec()); $sub_total += $value; if ($myrow2["discount_percent"] == 0) diff --git a/sales/view/view_dispatch.php b/sales/view/view_dispatch.php index 8a4460c0..20ecb619 100644 --- a/sales/view/view_dispatch.php +++ b/sales/view/view_dispatch.php @@ -111,7 +111,8 @@ if (db_num_rows($result) > 0) if($myrow2['quantity']==0) continue; alt_table_row_color($k); - $value = ((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]); + $value = round(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]), + user_price_dec()); $sub_total += $value; if ($myrow2["discount_percent"] == 0) diff --git a/sales/view/view_invoice.php b/sales/view/view_invoice.php index b6da97d4..c15753b6 100644 --- a/sales/view/view_invoice.php +++ b/sales/view/view_invoice.php @@ -111,7 +111,8 @@ if (db_num_rows($result) > 0) if($myrow2["quantity"]==0) continue; alt_table_row_color($k); - $value = ((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]); + $value = round(((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]), + user_price_dec()); $sub_total += $value; if ($myrow2["discount_percent"] == 0) @@ -120,7 +121,7 @@ if (db_num_rows($result) > 0) } else { - $display_discount = percent_format2($myrow2["discount_percent"]*100) . "%"; + $display_discount = percent_format($myrow2["discount_percent"]*100) . "%"; } label_cell($myrow2["stock_id"]); diff --git a/sales/view/view_sales_order.php b/sales/view/view_sales_order.php index 76c58b45..13bebb09 100644 --- a/sales/view/view_sales_order.php +++ b/sales/view/view_sales_order.php @@ -177,7 +177,8 @@ $k = 0; //row colour counter foreach ($_SESSION['Items']->line_items as $stock_item) { - $line_total = $stock_item->quantity * $stock_item->price * (1 - $stock_item->discount_percent); + $line_total = round($stock_item->quantity * $stock_item->price * (1 - $stock_item->discount_percent), + user_price_dec()); alt_table_row_color($k); diff --git a/taxes/tax_calc.inc b/taxes/tax_calc.inc index 6ca9fbbf..9d1ba576 100644 --- a/taxes/tax_calc.inc +++ b/taxes/tax_calc.inc @@ -67,7 +67,7 @@ function get_tax_free_price_for_item($stock_id, $price, $tax_group, $tax_include $tax_multiplier += $taxitem["rate"]; } - return $price / (1 + ($tax_multiplier / 100)); + return round($price / (1 + ($tax_multiplier / 100)), user_price_dec()); } // // Full price (incl. VAT) for item $stock_id with line price $price, @@ -103,7 +103,7 @@ function get_full_price_for_item($stock_id, $price, $tax_group, $tax_included, $ $tax_multiplier += $taxitem["rate"]; } - return $price * (1 + ($tax_multiplier / 100)); + return round($price * (1 + ($tax_multiplier / 100)), user_price_dec()); } //--------------------------------------------------------------------------------- @@ -176,10 +176,11 @@ function get_tax_for_items($items, $prices, $shipping_cost, $tax_group, $tax_inc { $index = $item_tax['tax_type_id']; if($tax_included==1) - $ret_tax_array[$index]['Value'] += $prices[$i] * $item_tax['rate'] - / ($item_tax['rate'] + 100); + $ret_tax_array[$index]['Value'] += round($prices[$i] * $item_tax['rate'] + / ($item_tax['rate'] + 100), user_price_dec()); else - $ret_tax_array[$index]['Value'] += $prices[$i] * $item_tax['rate'] / 100; + $ret_tax_array[$index]['Value'] += + round($prices[$i] * $item_tax['rate'] / 100, user_price_dec()); } } } @@ -195,10 +196,11 @@ function get_tax_for_items($items, $prices, $shipping_cost, $tax_group, $tax_inc $index = $item_tax['tax_type_id']; if(isset($ret_tax_array[$index])) { if($tax_included==1) - $ret_tax_array[$index]['Value'] += $shipping_cost * $item_tax['rate'] - / ($item_tax['rate'] + 100); + $ret_tax_array[$index]['Value'] += round($shipping_cost * $item_tax['rate'] + / ($item_tax['rate'] + 100), user_price_dec()); else - $ret_tax_array[$index]['Value'] += $shipping_cost * $item_tax['rate'] / 100; + $ret_tax_array[$index]['Value'] += + round($shipping_cost * $item_tax['rate'] / 100, user_price_dec()); } } } -- 2.30.2