+ $sql = "UPDATE ".TB_PREF."purch_order_details
+ SET quantity_received = quantity_received + "
+ .db_escape($entered_grn->this_quantity_inv).",
+ quantity_ordered = quantity_ordered + "
+ .db_escape($entered_grn->this_quantity_inv).",
+ qty_invoiced = qty_invoiced + ".db_escape($entered_grn->this_quantity_inv).",
+ std_cost_unit=".db_escape($mcost).",
+ act_price=".db_escape($entered_grn->chg_price)."
+ WHERE po_detail_item = ".$myrow["po_detail_item"];
+ db_query($sql, "a purchase order details record could not be updated. This receipt of goods has not been processed ");
+
+ //$sql = "UPDATE ".TB_PREF."grn_items SET qty_recd=0, quantity_inv=0 WHERE id=$entered_grn->id";
+ $sql = "UPDATE ".TB_PREF."grn_items SET qty_recd=qty_recd+".db_escape($entered_grn->this_quantity_inv)
+ .",quantity_inv=quantity_inv+".db_escape($entered_grn->this_quantity_inv)
+ ." WHERE id=".db_escape($entered_grn->id);
+ db_query($sql);
+
+ add_stock_move(ST_SUPPCREDIT, $entered_grn->item_code, $transno, $myrow['loc_code'], $date, "",
+ $entered_grn->this_quantity_inv, $mcost, $supplier, 1, $entered_grn->chg_price);
+}
+
+function get_grn_items($grn_batch_id=0, $supplier_id="", $outstanding_only=false,
+ $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
+ FROM ".TB_PREF."grn_batch, ".TB_PREF."grn_items, "
+ .TB_PREF."purch_order_details, ".TB_PREF."stock_master";
+ if ($invoice_no != 0)
+ $sql .= ", ".TB_PREF."supp_invoice_items";
+ $sql .= " WHERE ".TB_PREF."grn_items.grn_batch_id=".TB_PREF."grn_batch.id
+ AND ".TB_PREF."grn_items.po_detail_item=".TB_PREF."purch_order_details.po_detail_item";
+ if ($invoice_no != 0)
+ $sql .= " AND ".TB_PREF."supp_invoice_items.supp_trans_type=".ST_SUPPINVOICE." AND
+ ".TB_PREF."supp_invoice_items.supp_trans_no=$invoice_no AND
+ ".TB_PREF."grn_items.id=".TB_PREF."supp_invoice_items.grn_item_id";
+ $sql .= " AND ".TB_PREF."stock_master.stock_id=".TB_PREF."grn_items.item_code ";
+
+ if ($begin != "")
+ $sql .= " AND ".TB_PREF."grn_batch.delivery_date>='".date2sql($begin)."'";
+ if ($end != "")
+ $sql .= " AND ".TB_PREF."grn_batch.delivery_date<='".date2sql($end)."'";