$date_ = $po->orig_order_date;
begin_transaction();
+ hook_db_prewrite($po, ST_SUPPRECEIVE);
$grn = add_grn_batch($po->order_no, $po->supplier_id, $po->reference, $po->Location, $date_);
+ $clearing_act = get_company_pref('grn_clearing_act');
+ if ($clearing_act) { // otherwise GRN clearing account is not used
+ $total = 0;
+ }
foreach ($po->line_items as $line_no => $order_line)
{
-
if ($order_line->receive_qty != 0 && $order_line->receive_qty != "" && isset($order_line->receive_qty))
{
+ $stock_gl_code = get_stock_gl_code($order_line->stock_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($po->supplier_id, $order_line->stock_id, $order_line->price,
- $order_line->receive_qty, $date_);
+ //------------------- 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)
{
$order_line->standard_cost, $order_line->receive_qty, $order_line->price);
$po->line_items[$line_no]->grn_item_id = $grn_item;
- /* Update location stock records - NB a po cannot be entered for a service/kit parts */
- add_stock_move(ST_SUPPRECEIVE, $order_line->stock_id, $grn, $po->Location, $date_, "",
- $order_line->receive_qty, $order_line->standard_cost,
- $po->supplier_id, 1, $order_line->price);
+ /* Update location stock records - NB a po cannot be entered for a service/kit parts done automatically */
+ add_stock_move(ST_SUPPRECEIVE, $order_line->stock_id, $grn, $po->Location, $date_, "",
+ $order_line->receive_qty, $order_line->standard_cost,
+ $po->supplier_id, 1, $order_line->price);
} /*quantity received is != 0 */
} /*end of order_line loop */
+ if ($clearing_act && $total != 0.0) {
+ $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $grn, $date_, $clearing_act,
+ 0, 0, -$total, null);
+ }
$Refs->save(ST_SUPPRECEIVE, $grn, $po->reference);
add_audit_trail(ST_SUPPRECEIVE, $grn, $date_);
+ $po->trans_no = $grn;
+ hook_db_postwrite($po, ST_SUPPRECEIVE);
commit_transaction();
return $grn;
$is_invoiced_only=false, $invoice_no=0, $begin="", $end="")
{
$sql = "SELECT ".TB_PREF."grn_batch.*, ".TB_PREF."grn_items.*, "
- .TB_PREF."purch_order_details.unit_price,
- ".TB_PREF."purch_order_details.std_cost_unit, units
+ .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, "
.TB_PREF."purch_order_details, ".TB_PREF."stock_master";
if ($invoice_no != 0)
}
$order->add_to_order($order->lines_on_order, $myrow["item_code"],
- 1,$myrow["description"], $myrow["unit_price"],$units,
+ $myrow["qty_recd"],$myrow["description"], $myrow["unit_price"],$units,
sql2date($myrow["delivery_date"]), $myrow["quantity_inv"],
$myrow["qty_recd"]);
if ($result)
{
+ $order->trans_type = ST_SUPPRECEIVE;
$order->orig_order_date = sql2date($row["delivery_date"]);
$order->location = $row["loc_code"];
$order->reference = $row["reference"];
return false;
begin_transaction();
+ hook_db_prevoid(ST_SUPPRECEIVE, $grn_batch);
void_bank_trans(ST_SUPPRECEIVE, $grn_batch, true);
void_gl_trans(ST_SUPPRECEIVE, $grn_batch, true);