From 7a9628201e7a05e56d0b6e8e8eeb2525ed65086c Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Mon, 24 Aug 2009 14:20:57 +0000 Subject: [PATCH] A Purchasing Price of 12.34 with a conversion factor of 100,0000 caused a false internal rounding error of 12.00. The Purchasing Price, price can now have up to 6 decimals (fractions of hundredth's) and are presented correctly. If you need to increase the decimals in a current value, then you have to delete it and create it again with new values. This is for safety reasons. --- CHANGELOG.txt | 15 +++++++++++++++ includes/current_user.inc | 14 ++++++++++++++ includes/ui/ui_input.inc | 6 ++++++ inventory/purchasing_data.php | 7 ++++--- purchasing/includes/ui/invoice_ui.inc | 5 +++-- purchasing/includes/ui/po_ui.inc | 11 +++++++---- purchasing/po_receive_items.php | 2 +- purchasing/view/view_grn.php | 2 +- purchasing/view/view_po.php | 2 +- reporting/rep209.php | 3 ++- 10 files changed, 54 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 08abbd9..4e0d4b3 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,6 +19,21 @@ Legend: ! -> Note $ -> Affected files +24-Aug-2009 Joe Hunt +# A Purchasing Price of 12.34 with a conversion factor of 100,0000 caused a false internal rounding error of 12.00. +! The Purchasing Price, price can now have up to 6 decimals (fractions of hundredth's) and are presented correctly. + If you need to increase the decimals in a current value, then you have to delete it and create it again with new values. + This is for safety reasons. +$ /includes/current_user.inc + /includes/ui/ui_input.inc + /inventory/purchasing_data.php + /purchasing/po_receive_items.php + /purchasing/includes/ui/invoice_ui.inc + /purchasing/includes/ui/po_ui.inc + /purchasing/view/view_grn.php + /purchasing/view/view_po.php + /reporting/rep209.php + 21-Aut-2009 Joe Hunt # [0000162] Deleting a GL account may cause problems with quick entries $ /gl/manage/gl_accounts.php diff --git a/includes/current_user.inc b/includes/current_user.inc index f0aa525..a47b822 100644 --- a/includes/current_user.inc +++ b/includes/current_user.inc @@ -150,6 +150,20 @@ function price_format($number) { return number_format2($number, $_SESSION["wa_current_user"]->prefs->price_dec()); } + +function price_decimal_format($number, &$dec) +{ + $dec = user_price_dec(); + $str = strval($number); + $pos = strpos($str, '.'); + if ($pos !== false) + { + $len = strlen(substr($str, $pos + 1)); + if ($len > $dec) + $dec = $len; + } + return number_format2($number, $dec); +} // 2008-06-15. Added extra parameter $stock_id and reference for $dec //-------------------------------------------------------------------- function qty_format($number, $stock_id=null, &$dec) { diff --git a/includes/ui/ui_input.inc b/includes/ui/ui_input.inc index dd2930c..f5a127c 100644 --- a/includes/ui/ui_input.inc +++ b/includes/ui/ui_input.inc @@ -340,6 +340,12 @@ function email_cell($label, $params="", $id=null) label_cell("$label", $params, $id); } +function amount_decimal_cell($label, $params="", $id=null) +{ + $dec = 0; + label_cell(price_decimal_format($label, $dec), "nowrap align=right ".$params, $id); +} + function amount_cell($label, $bold=false, $params="", $id=null) { if ($bold) diff --git a/inventory/purchasing_data.php b/inventory/purchasing_data.php index ce1c9b7..84d6748 100644 --- a/inventory/purchasing_data.php +++ b/inventory/purchasing_data.php @@ -165,7 +165,7 @@ else alt_table_row_color($k); label_cell($myrow["supp_name"]); - amount_cell($myrow["price"]); + amount_decimal_cell($myrow["price"]); label_cell($myrow["curr_code"]); label_cell($myrow["suppliers_uom"]); qty_cell($myrow['conversion_factor'], false, user_exrate_dec()); @@ -189,6 +189,7 @@ else //----------------------------------------------------------------------------------------------- +$dec2 = 6; if ($Mode =='Edit') { @@ -202,7 +203,7 @@ if ($Mode =='Edit') $myrow = db_fetch($result); $supp_name = $myrow["supp_name"]; - $_POST['price'] = price_format($myrow["price"]); + $_POST['price'] = price_decimal_format($myrow["price"], $dec2); $_POST['suppliers_uom'] = $myrow["suppliers_uom"]; $_POST['supplier_description'] = $myrow["supplier_description"]; $_POST['conversion_factor'] = exrate_format($myrow["conversion_factor"]); @@ -222,7 +223,7 @@ else supplier_list_row(_("Supplier:"), 'supplier_id', null, false, true); $_POST['price'] = $_POST['suppliers_uom'] = $_POST['conversion_factor'] = $_POST['supplier_description'] = ""; } -amount_row(_("Price:"), 'price', null,'', get_supplier_currency($selected_id)); +amount_row(_("Price:"), 'price', null,'', get_supplier_currency($selected_id), $dec2); text_row(_("Suppliers Unit of Measure:"), 'suppliers_uom', null, 50, 51); if (!isset($_POST['conversion_factor']) || $_POST['conversion_factor'] == "") diff --git a/purchasing/includes/ui/invoice_ui.inc b/purchasing/includes/ui/invoice_ui.inc index 5e9520e..57aa367 100644 --- a/purchasing/includes/ui/invoice_ui.inc +++ b/purchasing/includes/ui/invoice_ui.inc @@ -380,7 +380,8 @@ function display_grn_items_for_selection(&$supp_trans, $k) else qty_cells(null, 'This_QuantityCredited'.$n, number_format2(max($myrow["quantity_inv"], 0), $dec), null, null, $dec); - amount_cells(null, 'ChgPrice'.$n, price_format($myrow["unit_price"])); + $dec2 = 0; + amount_cells(null, 'ChgPrice'.$n, price_decimal_format($myrow["unit_price"], $dec2), null, null, $dec2); if ($supp_trans->is_invoice) amount_cell(round2($myrow["unit_price"] * ($myrow["qty_recd"] - $myrow["quantity_inv"]), user_price_dec())); else @@ -511,7 +512,7 @@ function display_grn_items(&$supp_trans, $mode=0) qty_cell($entered_grn->prev_quantity_inv, false, $dec); } qty_cell(abs($entered_grn->this_quantity_inv), true, $dec); - amount_cell($entered_grn->chg_price); + amount_decimal_cell($entered_grn->chg_price); amount_cell( round2($entered_grn->chg_price * abs($entered_grn->this_quantity_inv), user_price_dec()), true); if ($mode == 1) diff --git a/purchasing/includes/ui/po_ui.inc b/purchasing/includes/ui/po_ui.inc index cf29dbc..87cb494 100644 --- a/purchasing/includes/ui/po_ui.inc +++ b/purchasing/includes/ui/po_ui.inc @@ -190,7 +190,7 @@ function display_po_items(&$order, $editable=true) qty_cell($po_line->qty_received, false, get_qty_dec($po_line->stock_id)); label_cell($po_line->units); label_cell($po_line->req_del_date); - amount_cell($po_line->price); + amount_decimal_cell($po_line->price); amount_cell($line_total); if ($editable) @@ -279,6 +279,7 @@ function po_item_controls(&$order, $stock_id=null) global $Ajax; start_row(); + $dec2 = 0; $id = find_submit('Edit'); if (($id != -1) && $stock_id != null) { @@ -287,7 +288,8 @@ function po_item_controls(&$order, $stock_id=null) $_POST['stock_id'] = $order->line_items[$id]->stock_id; $dec = get_qty_dec($_POST['stock_id']); $_POST['qty'] = qty_format($order->line_items[$id]->quantity, $_POST['stock_id'], $dec); - $_POST['price'] = price_format($order->line_items[$id]->price); + //$_POST['price'] = price_format($order->line_items[$id]->price); + $_POST['price'] = price_decimal_format($order->line_items[$id]->price, $dec2); $_POST['req_del_date'] = $order->line_items[$id]->req_del_date; $_POST['units'] = $order->line_items[$id]->units; @@ -315,7 +317,8 @@ function po_item_controls(&$order, $stock_id=null) $dec = $item_info["decimals"]; $_POST['qty'] = number_format2(get_purchase_conversion_factor ($order->supplier_id, $_POST['stock_id']), $dec); - $_POST['price'] = price_format(get_purchase_price ($order->supplier_id, $_POST['stock_id'])); + //$_POST['price'] = price_format(get_purchase_price ($order->supplier_id, $_POST['stock_id'])); + $_POST['price'] = price_decimal_format(get_purchase_price ($order->supplier_id, $_POST['stock_id']), $dec2); $_POST['req_del_date'] = add_days(Today(), 10); $qty_rcvd = ''; } @@ -325,7 +328,7 @@ function po_item_controls(&$order, $stock_id=null) label_cell($_POST['units'], '', 'units'); date_cells(null, 'req_del_date', '', null, 0, 0, 0); - amount_cells(null, 'price', null); + amount_cells(null, 'price', null, null, null, $dec2); //$line_total = $_POST['qty'] * $_POST['price'] * (1 - $_POST['Disc'] / 100); $line_total = round(input_num('qty') * input_num('price'), user_price_dec()); diff --git a/purchasing/po_receive_items.php b/purchasing/po_receive_items.php index 8daa1eb..af897d7 100644 --- a/purchasing/po_receive_items.php +++ b/purchasing/po_receive_items.php @@ -102,7 +102,7 @@ function display_po_receive_items() else label_cell(number_format2($ln_itm->receive_qty, $dec), "align=right"); - amount_cell($ln_itm->price); + amount_decimal_cell($ln_itm->price); amount_cell($line_total); end_row(); } diff --git a/purchasing/view/view_grn.php b/purchasing/view/view_grn.php index 9a8cbc7..b0c37d7 100644 --- a/purchasing/view/view_grn.php +++ b/purchasing/view/view_grn.php @@ -58,7 +58,7 @@ foreach ($purchase_order->line_items as $stock_item) $dec = get_qty_dec($stock_item->stock_id); qty_cell($stock_item->qty_received, false, $dec); label_cell($stock_item->units); - amount_cell($stock_item->price); + amount_decimal_cell($stock_item->price); amount_cell($line_total); qty_cell($stock_item->qty_inv, false, $dec); end_row(); diff --git a/purchasing/view/view_po.php b/purchasing/view/view_po.php index 57ff3a4..8102833 100644 --- a/purchasing/view/view_po.php +++ b/purchasing/view/view_po.php @@ -70,7 +70,7 @@ foreach ($purchase_order->line_items as $stock_item) $dec = get_qty_dec($stock_item->stock_id); qty_cell($stock_item->quantity, false, $dec); label_cell($stock_item->units); - amount_cell($stock_item->price); + amount_decimal_cell($stock_item->price); amount_cell($line_total); label_cell($stock_item->req_del_date); qty_cell($stock_item->qty_received, false, $dec); diff --git a/reporting/rep209.php b/reporting/rep209.php index 046738d..b9a8a04 100644 --- a/reporting/rep209.php +++ b/reporting/rep209.php @@ -125,7 +125,8 @@ function print_po() } $Net = round2(($myrow2["unit_price"] * $myrow2["quantity_ordered"]), user_price_dec()); $SubTotal += $Net; - $DisplayPrice = number_format2($myrow2["unit_price"],$dec); + $dec2 = 0; + $DisplayPrice = price_decimal_format($myrow2["unit_price"],$dec2); $DisplayQty = number_format2($myrow2["quantity_ordered"],get_qty_dec($myrow2['item_code'])); $DisplayNet = number_format2($Net,$dec); //$rep->TextCol(0, 1, $myrow2['item_code'], -2); -- 2.30.2