5745: Supplier Credit Note Issue: Stock Move Price Overstated Due to Included Tax.
authorJoe <joe.hunt.consulting@gmail.com>
Wed, 16 Oct 2024 11:21:48 +0000 (13:21 +0200)
committerJoe <joe.hunt.consulting@gmail.com>
Wed, 16 Oct 2024 11:21:48 +0000 (13:21 +0200)
purchasing/includes/db/grn_db.inc
purchasing/includes/db/invoice_db.inc

index b12c102809aa0793e0ec6170e0b46236f45d591a..29452b77968500fc48df8c880c61d55c51e8f7ac 100644 (file)
@@ -215,10 +215,10 @@ function get_grn_batch($grn)
        return db_fetch($result);
 }
 
-function set_grn_item_credited(&$entered_grn, $supplier, $transno, $date)
+function set_grn_item_credited(&$entered_grn, $supplier, $transno, $date, $taxfree_line)
 {
        $mcost = update_average_material_cost($supplier, $entered_grn->item_code,
-               $entered_grn->chg_price, $entered_grn->this_quantity_inv, $date);
+               $taxfree_line, $entered_grn->this_quantity_inv, $date);
 
        $sql = "SELECT grn.*, item.*
        FROM ".TB_PREF."grn_batch grn,"
@@ -237,7 +237,7 @@ function set_grn_item_credited(&$entered_grn, $supplier, $transno, $date)
         .db_escape($entered_grn->this_quantity_inv).",
         qty_invoiced = qty_invoiced + ".db_escape($entered_grn->this_quantity_inv).",
         std_cost_unit=".db_escape($mcost).",
-        act_price=".db_escape($entered_grn->chg_price)."
+        act_price=".db_escape($taxfree_line)."
         WHERE po_detail_item = ".$myrow["po_detail_item"];
        db_query($sql, "a purchase order details record could not be updated. This receipt of goods has not been processed ");
 
@@ -248,7 +248,7 @@ function set_grn_item_credited(&$entered_grn, $supplier, $transno, $date)
        db_query($sql);
 
     add_stock_move(ST_SUPPCREDIT, $entered_grn->item_code, $transno, $myrow['loc_code'], $date, "",
-               $entered_grn->this_quantity_inv, $mcost, $entered_grn->chg_price);
+               $entered_grn->this_quantity_inv, $mcost, $taxfree_line);
 }
 
 function get_grn_items($grn_batch_id=0, $supplier_id="", $outstanding_only=false,
index a00432797b0f81154e3708630814f11e23b3fccc..f4338ca8f7f413b2cf38f35bfe1d9f1e890a5aa8 100644 (file)
@@ -256,11 +256,13 @@ function add_supp_invoice(&$supp_trans)
     $clearing_act = get_company_pref('grn_clearing_act');
     foreach ($supp_trans->grn_items as $line_no => $entered_grn)
     {
-
+       // moved this line up to calculate the taxfree price.
+       $taxfree_line = get_tax_free_price_for_item($entered_grn->item_code, $entered_grn->this_quantity_inv * $entered_grn->chg_price, 
+                         $supp_trans->tax_group_id, $supp_trans->tax_included) - $net_diff; $net_diff = 0;
        if ($trans_type == ST_SUPPCREDIT)
        {
                        $entered_grn->this_quantity_inv = -$entered_grn->this_quantity_inv;
-                       set_grn_item_credited($entered_grn, $supp_trans->supplier_id, $invoice_id, $date_);
+                       set_grn_item_credited($entered_grn, $supp_trans->supplier_id, $invoice_id, $date_, $taxfree_line);
        }
 
                // For tax included pricelist the net price is calculated down from tax_included price.
@@ -270,9 +272,7 @@ function add_supp_invoice(&$supp_trans)
                // taxes and sales accounts, so we add net_diff just to first posted net value. This is _ugly_hack_
                // which save us from rewriting whole routine, and works right only for small tax differences.
 
-               $taxfree_line = get_tax_free_price_for_item($entered_grn->item_code, $entered_grn->this_quantity_inv * $entered_grn->chg_price, 
-                         $supp_trans->tax_group_id, $supp_trans->tax_included) - $net_diff; $net_diff = 0;
-
+               
                $line_tax = get_full_price_for_item($entered_grn->item_code,
                        $entered_grn->this_quantity_inv * $entered_grn->chg_price, $supp_trans->tax_group_id, $supp_trans->tax_included) - $taxfree_line;