$clearing_act = get_company_pref('grn_clearing_act');
if ($clearing_act) { // otherwise GRN clearing account is not used
$total = 0;
- $supplier_accounts = get_supplier_accounts($po->supplier_id);
}
foreach ($po->line_items as $line_no => $order_line)
{
{
$stock_gl_code = get_stock_gl_code($order_line->stock_id);
- if($clearing_act) {
- $inv_act = (is_inventory_item($order_line->stock_id) ? $stock_gl_code["inventory_account"] :
- ($supplier_accounts["purchase_account"] ? $supplier_accounts["purchase_account"] : $stock_gl_code["cogs_account"]));
-
- $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $grn, $date_, $inv_act,
- $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
- $order_line->receive_qty * $order_line->taxfree_charge_price($po), $po->supplier_id);
- }
/*Update sales_order_details for the new quantity received and the standard cost used for postings to GL and recorded in the stock movements for FIFO/LIFO stocks valuations*/
- //------------------- update average material cost ------------------------------------------ Joe Hunt Mar-03-2008
+ //------------------- update average material cost and clearing account ----- Joe Hunt Mar-03-2008
if (is_inventory_item($order_line->stock_id))
+ {
+ if ($clearing_act)
+ $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $grn, $date_, $stock_gl_code["inventory_account"],
+ $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
+ $order_line->receive_qty * $order_line->taxfree_charge_price($po), $po->supplier_id);
update_average_material_cost($po->supplier_id, $order_line->stock_id, $order_line->price,
$order_line->receive_qty, $date_);
+ }
//----------------------------------------------------------------------------------------------------------------
if ($order_line->qty_received == 0)
{
} /*quantity received is != 0 */
} /*end of order_line loop */
- if ($clearing_act) {
+ if ($clearing_act && $total != 0.0) {
$total += add_gl_trans_supplier(ST_SUPPRECEIVE, $grn, $date_, $clearing_act,
- 0, 0, -$total, $po->supplier_id);
+ 0, 0, -$total, null);
}
$Refs->save(ST_SUPPRECEIVE, $grn, $po->reference);
{
$sql = "SELECT ".TB_PREF."grn_batch.*, ".TB_PREF."grn_items.*, "
.TB_PREF."purch_order_details.unit_price,"
+ .TB_PREF."purch_order_details.act_price,"
.TB_PREF."purch_order_details.quantity_ordered,"
.TB_PREF."purch_order_details.std_cost_unit, units
FROM ".TB_PREF."grn_batch, ".TB_PREF."grn_items, "
$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