Added rounding when needed to avoid document inconsistency
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 17 Mar 2008 09:24:00 +0000 (09:24 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 17 Mar 2008 09:24:00 +0000 (09:24 +0000)
18 files changed:
includes/banking.inc
purchasing/includes/supp_trans_class.inc
purchasing/includes/ui/po_ui.inc
purchasing/po_entry_items.php
purchasing/supplier_credit_grns.php
purchasing/supplier_invoice_grns.php
reporting/rep107.php
reporting/rep109.php
reporting/rep110.php
reporting/rep209.php
sales/includes/cart_class.inc
sales/includes/ui/sales_credit_ui.inc
sales/includes/ui/sales_order_ui.inc
sales/view/view_credit.php
sales/view/view_dispatch.php
sales/view/view_invoice.php
sales/view/view_sales_order.php
taxes/tax_calc.inc

index a8a1c62e6296b9608b4307699bf90fd8c48da728..d3ca75bd5c4295992b88f4b270a21e47ece046a3 100644 (file)
@@ -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());
 }
 
 //----------------------------------------------------------------------------------           
index 596114c915ae22265788a34b8dbbf984f9f800b1..d6e06714b2f670bf0a8e203e1ba48a348182713b 100644 (file)
@@ -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;
index 893de6b4a25cbf33d9e83eef1d296d63c9394035..1bdac7e4291bf633a3d8e01daf1573f6351de5d6 100644 (file)
@@ -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']))
index 7e30f39ec65313f6b6a676008dad891a76c5ae56..ea7ae862705e05db4854a95e04a389ecb88c6240 100644 (file)
@@ -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");
index 15ea083045bad55fd36608e2bfdfdc5e4efa0d57..3d18c98ae93c451f8e0d1f01a33277297b8b783f 100644 (file)
@@ -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)
index ecbfe1684bffefefa9a63e87a3e745d792f24de4..95c345192056b535f22fea52fa7d48f5d563cd8b 100644 (file)
@@ -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++;
index 7baef1a4daadcb783c316f9f3a6aca3f6684494c..06e30233e0cbedd476e441849ba85acad44a4cd8 100644 (file)
@@ -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());
index dac0e0563f873d459e78f08d4d17e2c57dbb8825..36d5e491596530557f253a434056cea99e3cf529 100644 (file)
@@ -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());
index de81925bcc5e600d6bc5e5740fad9127af50fc81..d30d06a94424fa5d3cbd10400e81cc866ee64174 100644 (file)
@@ -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());
index 32108d5ab4c3d550565dc0e28c5f4e75a882fad3..c2c3c0fe58ca988492bcae63f57f59527c4e81ad 100644 (file)
@@ -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());
index 463b762256a517cca8b7c7e8a9b1e2b48235df01..9a730136fb4ed09806b210a394f71cf2fe264f2d 100644 (file)
@@ -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 */
index 3eb1a39921c2febae5e8c9060f1ad0122426c561..06ef1fe0326a9cf9d21582b99b3f1a2ae107607d 100644 (file)
@@ -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
index 23a2fc1878bd338dd0bd613298bf4ea0d2cd4f90..9329f81686c5732a06ce3168d0c34a8c99ab128e 100644 (file)
@@ -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;
index 0ba000898ee19fd0bf02ee549352e2f8e1e85bce..ec14f0313f250e6d5356781cfdb42901ddd9e939 100644 (file)
@@ -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)
index 8a4460c0ee154029c03b07cd6027225d478fa32f..20ecb619d60ab7feea10c34af63a100dd519357d 100644 (file)
@@ -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)
index b6da97d4373497a03fede71d1e11a848eefc1891..c15753b6c2678c80396e32f6cde34d788ba28a0f 100644 (file)
@@ -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"]);
index 76c58b45a4fd828722ee2c577f134bbe53d6fcd6..13bebb09beec97d4fcb670a17d68c6bcfe8123c6 100644 (file)
@@ -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);
 
index 6ca9fbbfc53d4155847ce2eb62f308ce3814d920..9d1ba576097fba04bc6ccac1e86fdf24a4c4b6e1 100644 (file)
@@ -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());
                                }
                        }
                }