Fixed net value calculations for GRN leading to unbalanced clearing account.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 13 Oct 2015 18:41:39 +0000 (20:41 +0200)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 13 Oct 2015 18:46:45 +0000 (20:46 +0200)
purchasing/includes/db/grn_db.inc
purchasing/includes/po_class.inc

index 4d85cc9fc8f9c8cd710c7e58d64f9884aabe02b5..f973af91cd50f265cb12c0719fa2dbbc1afeeab7 100644 (file)
@@ -119,7 +119,7 @@ function add_grn(&$po)
                                if ($clearing_act)
                                        $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $grn, $date_, $stock_gl_code["inventory_account"],
                                                $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
-                                               $order_line->receive_qty * $order_line->taxfree_charge_price($po), $po->supplier_id, '', 0, $order_line->stock_id);
+                                               $order_line->taxfree_charge_value($po), $po->supplier_id, '', 0, $order_line->stock_id);
                                update_average_material_cost($po->supplier_id, $order_line->stock_id, $order_line->price,
                                        $order_line->receive_qty, $date_);
                        }               
@@ -145,7 +145,7 @@ function add_grn(&$po)
                        /* Update location stock records - NB  a po cannot be entered for a service/kit parts done automatically */
                        add_stock_move(ST_SUPPRECEIVE, $order_line->stock_id, $grn, $po->Location, $date_, "",
                                $order_line->receive_qty, $order_line->standard_cost,
-                       $po->supplier_id, 1, $order_line->taxfree_charge_price($po));
+                       $po->supplier_id, 1, $order_line->taxfree_charge_value($po)/$order_line->receive_qty);
 
                } /*quantity received is != 0 */
        } /*end of order_line loop */
index f9f75aacc027574db79d361e770ba2f2c3201d5c..dff291a7c16bfc5ef8b70c5716582b3d9733c08a 100644 (file)
@@ -236,10 +236,20 @@ class po_line_details
                $this->standard_cost =0;
                $this->grn_item_id = $grn_item_id;
        }
-       
+
+       // Deprecated, use with care. If you need line value as it is calculated in invoice, use taxfree_charge_value below.
        function taxfree_charge_price($po)
        {
-               return get_tax_free_price_for_item($this->stock_id, $this->price, 
+               return get_tax_free_price_for_item($this->stock_id, $this->price,
+                 $po->tax_group_id, $po->tax_included, $po->tax_group_array);
+       }
+
+       //
+       // GRN line tax free value.
+       //
+       function taxfree_charge_value($po)
+       {
+               return get_tax_free_price_for_item($this->stock_id, $this->receive_qty*$this->price,
                  $po->tax_group_id, $po->tax_included, $po->tax_group_array);
        }
 }