- add_gl_trans_supplier($trans_type, $invoice_id, $date_, $stock_entry_account,
- $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
- $entered_grn->this_quantity_inv * $line_taxfree, $supp_trans->supplier_id);
-
-/*
- $supplierCurrency = get_supplier_currency($supp_trans->supplier_id);
- $localChgPrice = to_home_currency($entered_grn->chg_price, $supplierCurrency, $date_);
- $PurchPriceVar = $entered_grn->this_quantity_inv * ($localChgPrice - $entered_grn->std_cost_unit);
-
- echo "purchase price variance is $PurchPriceVar";
-
- // Yes but where to post this difference to - if its an inventory item the variance account
- // must be retreived from the stock category record
-
- if ($PurchPriceVar !=0){ // don't bother with this lot if there is no difference !
- // need to get the stock category record for this inventory item -
- $stock_gl_code = get_stock_gl_code($entered_grn->item_code);
-
-
- add_gl_trans_supplier($trans_type, $invoice_id, $date_, $stock_gl_code["purch_price_var_act"],
- $PurchPriceVar, $supp_trans->supplier_id,
- "The general ledger transaction could not be added for the price variance of the inventory item");
- }*/
-
- add_supp_invoice_item($trans_type, $invoice_id, $entered_grn->item_code,
- $entered_grn->item_description, 0, $line_taxfree, $line_tax,
- $entered_grn->this_quantity_inv, $entered_grn->id, $entered_grn->po_detail_item, "");
+ // always return due to change in currency.
+ $mat_cost = update_average_material_cost(null, $entered_grn->item_code,
+ $diff, $entered_grn->this_quantity_inv, null, true);
+
+ //Add GL transaction for GRN Provision in case of difference
+ if (($diff * $entered_grn->this_quantity_inv) != 0 )
+ {
+ $diff_amt = $diff * $entered_grn->this_quantity_inv;
+ $total += add_gl_trans($trans_type, $invoice_id, $date_, $stock_gl_code["inventory_account"],
+ $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], 'GRN Provision',
+ $diff_amt, null, null, null,
+ "The general ledger transaction could not be added for the GRN of the inventory item");
+
+ //add_gl_trans($trans_type, $invoice_id, $date_, $stock_gl_code["cogs_account"],
+ // 0, 0, 'GRN Provision', -$diff_amt, null, null, null,
+ // "The general ledger transaction could not be added for the GRN of the inventory item");
+ }
+ }
+ // added 2008-12-08 Joe Hunt. Update the purchase data table
+ add_or_update_purchase_data($supp_trans->supplier_id, $entered_grn->item_code, $entered_grn->chg_price);
+ /*$deliveries = get_deliveries_between($entered_grn->item_code, $old_date, Today()); // extend the period, if invoice is before any deliveries.
+ if ($deliveries[0] != 0) // have deliveries been done during the period?
+ {
+ $deliveries[1] /= $deliveries[0];
+ $amt = ($mat_cost - $deliveries[1]) * $deliveries[0]; // $amt in home currency
+ if ($amt != 0.0)
+ {
+ $_s = $entered_grn->item_code;
+ $_d = $deliveries[0];
+ $_od = $old_date;
+ $_cd = $mat_cost - $deliveries[1];
+ $memo = _("Cost difference adjustment for $_s. $_d items delivered since $_od. The cost difference is $_cd");
+ add_gl_trans($trans_type, $invoice_id, $date_, $stock_gl_code["cogs_account"],
+ $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo,
+ $amt, null, null, null,
+ "The general ledger transaction could not be added for the price variance of the inventory item");
+ add_gl_trans($trans_type, $invoice_id, $date_, $iv_act,
+ 0, 0, $memo, -$amt, null, null, null,
+ "The general ledger transaction could not be added for the price variance of the inventory item");
+ }
+ update_stock_move_pid(ST_CUSTDELIVERY, $entered_grn->item_code, $old_date, $date_, 0, $mat_cost);
+ } */
+ if (is_inventory_item($entered_grn->item_code))
+ update_stock_move_pid(ST_SUPPRECEIVE, $entered_grn->item_code, $old_date, $old_date, $supp_trans->supplier_id, $mat_cost);
+ //}
+ }
+ // ----------------------------------------------------------------------
+
+ add_supp_invoice_item($trans_type, $invoice_id, $entered_grn->item_code,
+ $entered_grn->item_description, 0, $entered_grn->chg_price, $line_tax,
+ $entered_grn->this_quantity_inv, $entered_grn->id, $entered_grn->po_detail_item, "");