- $_s = $entered_grn->item_code;
- $_d = $deliveries[0];
- $_od = $old_date;
- $_cd = $mat_cost - $deliveries[1];
- $memo = _("Cost difference adjustment for $_s. $_d items delivered since $_od. The cost difference is $_cd");
- add_gl_trans($trans_type, $invoice_id, $date_, $stock_gl_code["cogs_account"],
- $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo,
- $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_, $iv_act,
- 0, 0, $memo, -$amt, null, null, null,
- "The general ledger transaction could not be added for the price variance of the inventory item");
- }
- update_stock_move_pid(ST_CUSTDELIVERY, $entered_grn->item_code, $old_date, $date_, 0, $mat_cost);
- } */
- if (is_inventory_item($entered_grn->item_code))
- update_stock_move_pid(ST_SUPPRECEIVE, $entered_grn->item_code, $old_date, $old_date, $supp_trans->supplier_id, $mat_cost);
- //}
+
+ $gl_cart->add_gl_item($stock_gl_code["inventory_account"], // cart is in supplier currency, so need to fix by ex_rate here
+ $dimension, $dimension2, $diff/$gl_cart->rate, _('GRN Provision')); // subject to rounding errors?
+
+ $gl_cart->add_gl_item($clearing_act,
+ $dimension, $dimension2, -$diff/$gl_cart->rate);
+
+ //Chaitanya
+ //If QOH is 0 or negative then update_average_material_cost will be skipped
+ //Thus difference in PO and Supp Invoice should be handled separately
+ $qoh = get_qoh_on_date($item->item_code);
+ if ($qoh <= 0)
+ {
+ global $Refs;
+ //Chaitanya : Post a journal entry
+ $id = get_next_trans_no(ST_JOURNAL);
+ $ref = $Refs->get_next(ST_JOURNAL, null, $date_);
+ add_journal(ST_JOURNAL, $id, $diff, $date_, get_company_currency(), $ref);
+ $stock_id = $item->item_code;
+ $stock_gl_code = get_stock_gl_code($stock_id);
+ $memo = _("Supplier invoice adjustment for zero inventory of ").$stock_id." "._("Invoice")." ".$supp_trans->reference;
+ //Reverse the inventory effect if $qoh <=0
+ add_gl_trans_std_cost(ST_JOURNAL, $id, $date_,
+ $stock_gl_code["inventory_account"],
+ $dimension, $dimension2,
+ $memo, -$diff);
+ //GL Posting to inventory adjustment account
+ add_gl_trans_std_cost(ST_JOURNAL, $id, $date_,
+ $stock_gl_code["adjustment_account"],
+ $dimension, $dimension2,
+ $memo, $diff);
+ add_audit_trail(ST_JOURNAL, $id, $date_);
+ add_comments(ST_JOURNAL, $id, $date_, $memo);
+ $Refs->save(ST_JOURNAL, $id, $ref);
+ }
+ }
+ $gl_cart->add_gl_item($clearing_act, $dimension, $dimension2, $taxfree_line);
+ }
+ else // no postings on GRN, so post full cost here
+ $gl_cart->add_gl_item($stock_gl_code["inventory_account"], $dimension, $dimension2, $taxfree_line);
+
+ }
+
+// if (is_fa_item($item->item_code)) {
+// add_actual_cost($item->order_price, $item->item_code);
+// }
+
+ if ($trans_type == ST_SUPPCREDIT)
+ set_grn_item_credited($item, $supp_trans->supplier_id, $invoice_id, $date_);
+ else {
+ add_or_update_purchase_data($supp_trans->supplier_id, $item->item_code, $item->chg_price);
+
+ update_supp_received_items_for_invoice($item->id, $item->po_detail_item,
+ $item->this_quantity_inv, $item->chg_price);