- $iv_act = (is_inventory_item($entered_grn->item_code) ? $stock_gl_code["inventory_account"] :
- ($supplier_accounts["purchase_account"] ? $supplier_accounts["purchase_account"] : $stock_gl_code["cogs_account"]));
- $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $iv_act,
- $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
- $entered_grn->this_quantity_inv * $line_taxfree, $supp_trans->supplier_id);
- }
- else
- {
- // -------------- if price changed since po received. 16 Aug 2008 Joe Hunt
- $iv_act = is_inventory_item($entered_grn->item_code) ? ($clearing_act ? $clearing_act : $stock_gl_code["inventory_account"]) :
- ($supplier_accounts["purchase_account"] ? $supplier_accounts["purchase_account"] : $stock_gl_code["cogs_account"]);
- $old = update_supp_received_items_for_invoice($entered_grn->id, $entered_grn->po_detail_item,
- $entered_grn->this_quantity_inv, $entered_grn->chg_price);
- // Since the standard cost is always calculated on basis of the po unit_price,
- // this is also the price that should be the base of calculating the price diff.
- // In cases where there is two different po invoices on the same delivery with different unit prices this will not work either
-
- //$old_price = $old[0];
-
- $old_price = $old[2];
-
- /*
- If statement is removed. Should always check for deliveries nomatter if there has been a price change.
- */
- //if ($old_price != $entered_grn->chg_price) // price-change, so update
- //{
- //$diff = $entered_grn->chg_price - $old_price;
- $old_date = sql2date($old[1]);
- if (!is_inventory_item($entered_grn->item_code))
- $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $iv_act,
- $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
- $entered_grn->this_quantity_inv * $line_taxfree, $supp_trans->supplier_id);
- else
- {
- $currency = get_supplier_currency($supp_trans->supplier_id);
- $ex_rate = get_exchange_rate_from_home_currency($currency, $old_date);
- $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $iv_act,
- $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
- $entered_grn->this_quantity_inv * $old_price, $supp_trans->supplier_id, "", $ex_rate);
- $diff = get_diff_in_home_currency($supp_trans->supplier_id, $old_date, $date_, $old_price,
- $entered_grn->chg_price);
-
- // always return due to change in currency.
- /*$mat_cost = update_average_material_cost(null, $entered_grn->item_code,
- $diff, $entered_grn->this_quantity_inv, $old_date, true); */
- $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 )