$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);
- $iv_act = $clearing_act ? $clearing_act : (is_inventory_item($entered_grn->item_code) ? $stock_gl_code["inventory_account"] :
+ if ($trans_type == ST_SUPPCREDIT)
+ {
+ $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);
-
- // -------------- if price changed since po received. 16 Aug 2008 Joe Hunt
- if ($trans_type == ST_SUPPINVOICE)
+ $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,
//{
//$diff = $entered_grn->chg_price - $old_price;
$old_date = sql2date($old[1]);
- if (is_inventory_item($entered_grn->item_code))
+ 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);
if (($diff * $entered_grn->this_quantity_inv) != 0 )
{
$diff_amt = $diff * $entered_grn->this_quantity_inv;
- add_gl_trans($trans_type, $invoice_id, $date_, $iv_act,
+ $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");
+ //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
FROM ".TB_PREF."supp_trans, ".TB_PREF."supp_invoice_items, "
.TB_PREF."purch_order_details, ".TB_PREF."purch_orders
WHERE ".TB_PREF."supp_invoice_items.supp_trans_no = ".TB_PREF."supp_trans.trans_no
+ AND ".TB_PREF."supp_invoice_items.supp_trans_type = ".TB_PREF."supp_trans.type
AND ".TB_PREF."supp_invoice_items.po_detail_item_id = ".TB_PREF."purch_order_details.po_detail_item
AND ".TB_PREF."purch_orders.supplier_id = ".TB_PREF."supp_trans.supplier_id
+ AND ".TB_PREF."purch_orders.order_no = ".TB_PREF."purch_order_details.order_no
AND ".TB_PREF."purch_order_details.order_no = ".db_escape($po_number);
return db_query($sql, "The invoices/credits for the po $po_number could not be retreived");
add_stock_move(ST_SUPPRECEIVE, $myrow["item_code"], $myrow['grn_batch_id'], $grn['loc_code'], sql2date($grn["delivery_date"]), "",
-$myrow["QtyOstdg"], $myrow['std_cost_unit'], $grn["supplier_id"], 1, $myrow['unit_price']);
+
+ $clearing_act = get_company_pref('grn_clearing_act');
+ if ($clearing_act) { // otherwise GRN clearing account is not used
+ if (is_inventory_item($myrow['item_code']))
+ {
+ $total = 0;
+ $stock_gl_code = get_stock_gl_code($myrow['item_code']);
+ $date = sql2date($grn["delivery_date"]);
+ $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $myrow['grn_batch_id'], $date, $stock_gl_code["inventory_account"],
+ $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
+ -$myrow['QtyOstdg'] * $myrow['unit_price'], $grn["supplier_id"], "", 0, _("GRN Removal"));
+ $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $myrow['grn_batch_id'], $date, $clearing_act,
+ 0, 0, -$total, null, "", 0, _("GRN Removal"));
+ }
+ }
commit_transaction();
}