A Purchasing Price of 12.34 with a conversion factor of 100,0000 caused a false inter...
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Mon, 24 Aug 2009 14:20:57 +0000 (14:20 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Mon, 24 Aug 2009 14:20:57 +0000 (14:20 +0000)
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
includes/current_user.inc
includes/ui/ui_input.inc
inventory/purchasing_data.php
purchasing/includes/ui/invoice_ui.inc
purchasing/includes/ui/po_ui.inc
purchasing/po_receive_items.php
purchasing/view/view_grn.php
purchasing/view/view_po.php
reporting/rep209.php

index 08abbd99cabd1de8077fe86b88e5c851969708e9..4e0d4b38cb1552856cfc000343b814c4b0f7163f 100644 (file)
@@ -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
index f0aa525cc03d5f3a80bff3a4f0570df3012911cc..a47b822a1cce6b225e709d56d1149155b7832e58 100644 (file)
@@ -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) {
index dd2930c4dc2e2f5ef71c8a2f941eb6e18fcbf987..f5a127c0ecb7746401a57e16916f55be03f86cb2 100644 (file)
@@ -340,6 +340,12 @@ function email_cell($label, $params="", $id=null)
        label_cell("<a href='mailto:$label'>$label</a>", $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)
index ce1c9b7853c5226ad78e02f4e328d968ad34723b..84d67482e8062793128202f6368fc1dc0f1c0ee4 100644 (file)
@@ -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'] == "")
index 5e9520e54f6128e74ad6ddd003c177905d8c6db4..57aa36704a640f92a52f6164852ffddc8625c65c 100644 (file)
@@ -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)
index cf29dbc6d037107d53ae2db7916dc56a506f585c..87cb4941b7e74b5844b3d4de0de100d925841ebb 100644 (file)
@@ -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());
index 8daa1ebf5161819f9f8e66f4988d4c1a440f4664..af897d7a3286e4651fe0dc2f9c3cc8b646505f2e 100644 (file)
@@ -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();
                }
index 9a8cbc7fb6b5233c822103ecf62083398a8fcb4b..b0c37d7f7c85b29cc08595f9b9a3ac4017eb35bb 100644 (file)
@@ -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();
index 57ff3a470bfc3a512f076a0601da6df39808a478..81028338c80d2be97fa7444662e6c8a4a922fa4f 100644 (file)
@@ -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);
index 046738d025e47900f17d3530add9cc4db2d3dc3d..b9a8a049509fd75b3252f9abc339b2bced951cd1 100644 (file)
@@ -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);