-
-/*
- $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, "");
+ // -------------- if price changed since po received. 16 Aug 2008 Joe Hunt
+ $old_price = $old[0];
+ if ($old_price != $entered_grn->chg_price) // price-change, so update
+ {
+ $diff = $entered_grn->chg_price - $old_price;
+ $old_date = sql2date($old[1]);
+ // only update the diff (last parameter, adj_only is set to true).
+ $mat_cost = update_average_material_cost($supp_trans->supplier_id, $entered_grn->item_code,
+ $diff, $entered_grn->this_quantity_inv, $old_date, true);
+ // function just above this
+ $deliveries = get_deliveries_between($entered_grn->item_code, $old_date, $date_);
+ if ($deliveries[0] != 0) // have deliveries been done during the period?
+ {
+
+ $amt = ($mat_cost - $deliveries[1]) * $deliveries[0]; // $amt in home currency
+
+ add_gl_trans($trans_type, $invoice_id, $date_, $stock_gl_code["cogs_account"],
+ $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], _("Cost diff."),
+ $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_, $stock_gl_code["inventory_account"],
+ 0, 0, _("Cost diff."), -$amt, null, null, null,
+ "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, "");