- if (!$supp_trans->is_invoice)
- {
- $entered_grn->this_quantity_inv = -$entered_grn->this_quantity_inv;
- set_grn_item_credited($entered_grn, $supp_trans->supplier_id, $invoice_id, $date_);
- }
-
- $line_taxfree = $entered_grn->taxfree_charge_price($supp_trans->tax_group_id);
- $line_tax = $entered_grn->full_charge_price($supp_trans->tax_group_id) - $line_taxfree;
- $stock_gl_code = get_stock_gl_code($entered_grn->item_code);
-
- $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $stock_gl_code["inventory_account"],
- $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
- $entered_grn->this_quantity_inv * $line_taxfree, $supp_trans->supplier_id);
- // -------------- if price changed since po received. 16 Aug 2008 Joe Hunt
- if($supp_trans->is_invoice)
- {
- $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]);
- $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);
- // 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?