//ST_SUPPCREDIT => ,
//ST_SUPPAYMENT => ,
- //ST_SUPPRECEIVE => ,
+ ST_SUPPRECEIVE => "/purchasing/po_receive_items.php?ModifyGRN=%d",
//ST_WORKORDER => ,
//ST_MANUISSUE => ,
ST_SUPPCREDIT => "/purchasing/supplier_credit.php?ModifyCredit=%d",
// 21=> Supplier Credit Note,
// 22=> Supplier Payment,
-// 25=> Purchase Order Delivery,
+ ST_SUPPRECEIVE => "/purchasing/po_receive_items.php?ModifyGRN=%d",
ST_PURCHORDER => "/purchasing/po_entry_items.php?ModifyOrderNumber=%d",
// 28=> Work Order Issue,
// 29=> Work Order Production",
}
//-------------------------------------------------------------------------------------------------------------
-
-function add_grn(&$po)
+//
+// Add or update GRN transaction.
+//
+function write_grn(&$po)
{
global $Refs;
$date_ = $po->orig_order_date;
+ $grn = $po->grn_id;
begin_transaction();
hook_db_prewrite($po, ST_SUPPRECEIVE);
} else
$po->ex_rate = 1;
- $grn = add_grn_batch($po->order_no, $po->supplier_id, $po->reference, $po->Location, $date_, $po->ex_rate);
+ if(!$grn)
+ $grn = add_grn_batch($po->order_no, $po->supplier_id, $po->reference, $po->Location, $date_, $po->ex_rate);
+ else {
- $clearing_act = get_company_pref('grn_clearing_act');
- if ($clearing_act) { // otherwise GRN clearing account is not used
- $total = 0;
+ update_grn_batch($grn, $po->reference, $po->Location, $date_);
+
+ void_gl_trans(ST_SUPPRECEIVE, $grn, true);
+ void_stock_move(ST_SUPPRECEIVE, $grn);
+ void_trans_tax_details(ST_SUPPRECEIVE, $grn);
+ delete_comments(ST_SUPPRECEIVE, $grn);
}
+
+ $clearing_act = get_company_pref('grn_clearing_act');
+ $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))
+ if ($order_line->quantity != 0)
{
$stock_gl_code = get_stock_gl_code($order_line->stock_id);
$stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
$order_line->taxfree_charge_value($po), $po->supplier_id, '', 0, $order_line->stock_id);
update_average_material_cost($po->supplier_id, $order_line->stock_id, $order_line->price,
- $order_line->receive_qty, $date_);
+ $order_line->quantity, $date_);
}
//------------------------------------------------------------------------------------------------------
if ($order_line->qty_received == 0)
$order_line->item_description);
/*Need to insert a grn item */ // also need to check for over-receive.(within allowance)
- if ($order_line->receive_qty + $order_line->qty_received > $order_line->quantity)
- $order_line->quantity = $order_line->receive_qty + $order_line->qty_received;
- $grn_item = add_grn_detail_item($grn, $order_line->po_detail_rec,
- $order_line->stock_id, $order_line->item_description,
- $order_line->unit_cost, $order_line->receive_qty, $order_line->price, $order_line->quantity);
+ if ($order_line->quantity + $order_line->qty_received > $order_line->qty_ordered)
+ $order_line->qty_ordered = $order_line->quantity + $order_line->qty_received;
+
+ $grn_item = write_grn_item($grn, $order_line->po_detail_rec,
+ $order_line->stock_id, $order_line->item_description, $order_line->quantity, $order_line->grn_item_id);
$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 done automatically */
add_stock_move(ST_SUPPRECEIVE, $order_line->stock_id, $grn, $po->Location, $date_, "",
- $order_line->receive_qty, $order_line->unit_cost, $order_line->taxfree_charge_value($po)/$order_line->receive_qty);
+ $order_line->quantity, $order_line->unit_cost, $order_line->taxfree_charge_value($po)/$order_line->quantity);
} /*quantity received is != 0 */
} /*end of order_line loop */
return db_insert_id();
}
+//----------------------------------------------------------------------------------------
+
+function update_grn_batch($grn, $reference, $location, $date_)
+{
+ $date = date2sql($date_);
+
+ $sql = "UPDATE ".TB_PREF."grn_batch SET
+ delivery_date=".db_escape($date).",
+ reference=".db_escape($reference).",
+ loc_code=".db_escape($location)."
+ WHERE id=".db_escape($grn);
+
+ db_query($sql, "A grn batch record could not be updated.");
+
+ return db_insert_id();
+}
//-------------------------------------------------------------------------------------------------------------
-function add_grn_detail_item($grn_batch_id, $po_detail_item, $item_code, $description, $standard_unit_cost,
- $quantity_received, $price, $quantity)
+function write_grn_item($grn_batch_id, $po_detail_item, $item_code, $description, $quantity_received, $grn_item_id)
{
- $sql = "UPDATE ".TB_PREF."purch_order_details
- SET quantity_received = quantity_received + ".db_escape($quantity_received).",
- std_cost_unit=".db_escape($standard_unit_cost).",
- quantity_ordered=".db_escape($quantity).",
- act_price=".db_escape($price)."
- WHERE po_detail_item = ".db_escape($po_detail_item);
- db_query($sql, "a purchase order details record could not be updated. This receipt of goods has not been processed ");
+ if ($grn_item_id)
+ $sql = "UPDATE ".TB_PREF."grn_items SET qty_recd=".db_escape($quantity_received)
+ ." WHERE id=".db_escape($grn_item_id);
+ else
+ $sql = "INSERT INTO ".TB_PREF."grn_items (grn_batch_id, po_detail_item, item_code, description, qty_recd)
+ VALUES (".db_escape($grn_batch_id).", "
+ .db_escape($po_detail_item).", ".db_escape($item_code).", ".db_escape($description)
+ .", ".db_escape($quantity_received).")";
- $sql = "INSERT INTO ".TB_PREF."grn_items (grn_batch_id, po_detail_item, item_code, description, qty_recd)
- VALUES (".db_escape($grn_batch_id).", "
- .db_escape($po_detail_item).", ".db_escape($item_code).", ".db_escape($description)
- .", ".db_escape($quantity_received).")";
+ db_query($sql, "A GRN detail item could not be stored.");
- db_query($sql, "A GRN detail item could not be inserted.");
+ $sql = "UPDATE ".TB_PREF."purch_order_details po,
+ (SELECT SUM(qty_recd) received FROM ".TB_PREF."grn_items grn WHERE po_detail_item=".db_escape($po_detail_item).") grn
+ SET po.quantity_received = grn.received
+ WHERE po_detail_item = ".db_escape($po_detail_item);
+ db_query($sql, "a purchase order details record could not be updated. This receipt of goods has not been processed ");
return db_insert_id();
}
po_item.unit_price,
po_item.act_price,
po_item.quantity_ordered,
+ po_item.quantity_received,
po_item.std_cost_unit, units
- FROM ".TB_PREF."grn_batch grn, "
- .TB_PREF."purch_order_details po_item, "
- .TB_PREF."stock_master stock_item,"
- .TB_PREF."grn_items grn_item ";
+ FROM ".TB_PREF."grn_batch grn"
+ ." INNER JOIN ".TB_PREF."grn_items grn_item ON grn_item.grn_batch_id=grn.id"
+ ." INNER JOIN ".TB_PREF."purch_order_details po_item ON grn_item.po_detail_item=po_item.po_detail_item"
+ ." INNER JOIN ".TB_PREF."stock_master stock_item ON stock_item.stock_id=grn_item.item_code";
if ($invoice_no != 0) {
$sql .= " LEFT JOIN ".TB_PREF."supp_invoice_items invoice_item ON ";
$inv_cond .= " = $invoice_no";
$sql .= "($inv_cond) AND grn_item.id=invoice_item.grn_item_id";
}
- $sql .= " WHERE grn_item.grn_batch_id=grn.id
- AND grn_item.po_detail_item=po_item.po_detail_item";
+
+ $sql .= " WHERE grn_item.qty_recd != 0";
if ($outstanding_only)
$sql .= " AND (".($invoice_no ? "$inv_cond OR ":'')."grn_item.qty_recd - grn_item.quantity_inv > 0)";
if (db_num_rows($result) > 0)
{
- while ($myrow = db_fetch($result))
+ while ($myrow = db_fetch_assoc($result))
{
if ($myrow['qty_recd'] == 0 && $myrow['quantity_inv'] == 0)
continue; // We will not have empty credited rows.
$order->add_to_order($order->lines_on_order, $myrow["item_code"],
$myrow["qty_recd"],$myrow["description"], $myrow["unit_price"],$units,
sql2date($myrow["req_del_date"]), $myrow["quantity_inv"],
- $myrow["qty_recd"]);
+ $myrow["quantity_received"], $myrow["quantity_ordered"], $myrow["id"]);
$order->line_items[$order->lines_on_order-1]->po_detail_rec = $myrow["po_detail_item"];
} /* line po from purchase order details */
$order->orig_order_date = sql2date($row["delivery_date"]);
$order->Location = $row["loc_code"];
$order->reference = $row["reference"];
+ $order->grn_id = $grn_batch;
read_grn_items_to_order($grn_batch, $order);
}
if ($order->add_to_order($order->lines_on_order, $myrow["item_code"],
$myrow["quantity_ordered"],$myrow["description"],
$myrow["unit_price"],$units, sql2date($myrow["delivery_date"]),
- $myrow["qty_invoiced"], $myrow["quantity_received"])) {
+ $myrow["qty_invoiced"], $myrow["quantity_received"], $myrow["quantity_ordered"])) {
$order->line_items[$order->lines_on_order-1]->po_detail_rec = $myrow["po_detail_item"];
}
} /* line po from purchase order details */
var $prepayments = array();
var $fixed_asset = false;
+ var $grn_id ; // grn batch id used in edition only
function __construct()
{
$this->tax_group_array = get_tax_group_items_as_array($tax_group_id);
}
- function add_to_order($line_no, $stock_id, $qty, $item_descr, $price, $uom, $req_del_date, $qty_inv, $qty_recd)
+ function add_to_order($line_no, $stock_id, $qty, $item_descr, $price, $uom, $req_del_date, $qty_inv, $qty_recd, $qty_ordered=0, $grn_item_id=0)
{
if (isset($qty) && $qty != 0)
{
$this->line_items[$line_no] = new po_line_details($line_no, $stock_id, $item_descr, $qty, $price, $uom,
- $req_del_date, $qty_inv, $qty_recd);
+ $req_del_date, $qty_inv, $qty_recd, $qty_ordered, $grn_item_id);
$this->lines_on_order++;
return 1;
}
foreach ($this->line_items as $ln_itm) {
$items[] = $ln_itm->stock_id;
- $prices[] = round($ln_itm->price * ($receival ? $ln_itm->receive_qty : $ln_itm->quantity), user_price_dec());
+ $prices[] = round($ln_itm->price * $ln_itm->quantity, user_price_dec());
}
$taxes = get_tax_for_items($items, $prices, $shipping_cost,
$this->tax_group_id, $this->tax_included, $this->tax_group_array);
var $tax_type;
var $tax_type_name;
- var $quantity; // current/entry quantity of PO line
- var $qty_inv; // quantity already invoiced against this line
- var $receive_qty; // current/entry GRN quantity
- var $qty_received; // quantity already received against this line
+ var $quantity; // this document line quantity
+ var $qty_inv; // quantity already invoiced against this line (all PIs)
+ var $qty_received; // quantity already received against this line (all GRNs)
+ var $qty_ordered; // quantity on order (not used on PO entry)
var $unit_cost;
var $descr_editable;
function __construct($line_no, $stock_item, $item_descr, $qty, $prc, $uom, $req_del_date,
- $qty_inv, $qty_recd, $grn_item_id=0)
+ $qty_inv, $qty_recd, $qty_ordered=0, $grn_item_id=0)
{
-
/* Constructor function to add a new LineDetail object with passed params */
$this->line_no = $line_no;
$this->stock_id = $stock_item;
$this->units = $item_row["units"];
$this->qty_received = $qty_recd;
$this->qty_inv = $qty_inv;
- $this->receive_qty = 0; /*initialise these last two only */
$this->unit_cost =0;
$this->grn_item_id = $grn_item_id;
+ $this->qty_ordered = $qty_ordered;
}
// Deprecated, use with care. If you need line value as it is calculated in invoice, use taxfree_charge_value below.
//
function taxfree_charge_value($po)
{
- return get_tax_free_price_for_item($this->stock_id, $this->receive_qty*$this->price,
+ return get_tax_free_price_for_item($this->stock_id, $this->quantity*$this->price,
$po->tax_group_id, $po->tax_included, $po->tax_group_array);
}
}
$cart->reference = $ref;
if ($cart->trans_type != ST_SUPPINVOICE)
$cart->Comments = $cart->reference; //grn does not hold supp_ref
- foreach($cart->line_items as $key => $line)
- $cart->line_items[$key]->receive_qty = $line->quantity;
- $grn_no = add_grn($cart);
+
+ $grn_no = write_grn($cart);
if ($cart->trans_type == ST_SUPPRECEIVE) {
commit_transaction(); // save PO+GRN
return $grn_no;
$total = 0;
foreach($cart->line_items as $key => $line) {
$inv->add_grn_to_trans($line->grn_item_id, $line->po_detail_rec, $line->stock_id,
- $line->item_description, $line->receive_qty, 0, $line->receive_qty,
+ $line->item_description, $line->quantity, 0, $line->quantity,
$line->price, $line->price, true, get_unit_cost($line->stock_id), '');
- $total += round2(($line->receive_qty * $line->price), user_price_dec());
+ $total += round2(($line->quantity * $line->price), user_price_dec());
}
$inv->tax_overrides = $cart->tax_overrides;
if (!$inv->tax_included) {
table_section(2);
if (!isset($_POST['ref']))
- $_POST['ref'] = $Refs->get_next(ST_SUPPRECEIVE, null, array('supplier' => $po->supplier_id, 'date' => Today()));
- ref_row(_("Reference"), 'ref', '', null);
-
+ $_POST['ref'] = $Refs->get_next(ST_SUPPRECEIVE, null, array('supplier' => $po->supplier_id, 'date' => Today()));
+ ref_row(_("Reference"), 'ref', '', null);
if (!isset($_POST['Location']))
$_POST['Location'] = $po->Location;
//---------------------------------------------------------------------------------------------------
-function create_new_po($trans_type, $trans_no)
+function create_cart($trans_type, $trans_no)
{
global $Refs;
unset ($_SESSION['PO']->line_items, $_SESSION['PO']);
$cart = new purch_order;
- $_POST['OrderDate'] = new_doc_date();
- if (!is_date_in_fiscalyear($_POST['OrderDate']))
- $_POST['OrderDate'] = end_fiscalyear();
- $cart->due_date = $cart->orig_order_date = $_POST['OrderDate'];
-
$cart->trans_type = $trans_type;
- $cart->order_no = $trans_no;
- /*read in all the selected order into the Items cart */
- if ($trans_no) {
- read_po($trans_no, $cart);
+
+ if ($trans_type == ST_SUPPRECEIVE && $trans_no != 0) {
+ read_grn($trans_no, $cart);
+ foreach($cart->line_items as &$line) {
+ $line->qty_old = $line->quantity; // for concurrency checks
+ $line->qty_received -= $line->quantity;
+ }
+ } else {
$cart->order_no = $trans_no;
- } else
- $cart->reference = $Refs->get_next($trans_type, null,
- array('supplier_id' => $cart->supplier_id, 'date' => get_post('OrderDate')));
+ $_POST['OrderDate'] = new_doc_date();
+ if (!is_date_in_fiscalyear($_POST['OrderDate']))
+ $_POST['OrderDate'] = end_fiscalyear();
+ $cart->due_date = $cart->orig_order_date = $_POST['OrderDate'];
+ /* read in all the selected order into the Items cart */
+ if ($trans_no) {
+ read_po($trans_no, $cart);
+ $cart->order_no = $trans_no;
+ } else
+ $cart->reference = $Refs->get_next($trans_type, null,
+ array('supplier_id' => $cart->supplier_id, 'date' => get_post('OrderDate')));
+ }
$_SESSION['PO'] = &$cart;
}
if (isset($_GET['ModifyOrderNumber']) && is_numeric($_GET['ModifyOrderNumber'])) {
$_SESSION['page_title'] = _($help_context = "Modify Purchase Order #") . $_GET['ModifyOrderNumber'];
- create_new_po(ST_PURCHORDER, $_GET['ModifyOrderNumber']);
+ create_cart(ST_PURCHORDER, $_GET['ModifyOrderNumber']);
copy_from_cart();
} elseif (isset($_GET['NewOrder'])) {
$_SESSION['page_title'] = _($help_context = "Purchase Order Entry");
- create_new_po(ST_PURCHORDER, 0);
+ create_cart(ST_PURCHORDER, 0);
copy_from_cart();
} elseif (isset($_GET['NewGRN'])) {
$_SESSION['page_title'] = _($help_context = "Direct GRN Entry");
- create_new_po(ST_SUPPRECEIVE, 0);
+ create_cart(ST_SUPPRECEIVE, 0);
copy_from_cart();
} elseif (isset($_GET['NewInvoice'])) {
- create_new_po(ST_SUPPINVOICE, 0);
+ create_cart(ST_SUPPINVOICE, 0);
copy_from_cart();
if (isset($_GET['FixedAsset'])) {
$js .= get_js_open_window(900, 500);
if (user_use_date_picker())
$js .= get_js_date_picker();
-page(_($help_context = "Receive Purchase Order Items"), false, false, "", $js);
+
+//--------------------------------------------------------------------------------------------------
+
+if (isset($_GET['PONumber']) && $_GET['PONumber'] > 0 && !isset($_POST['Update']))
+{
+ $_SESSION['page_title'] = _($help_context = "Receive Purchase Order Items");
+ create_cart(ST_PURCHORDER, $_GET['PONumber']);
+ $_SESSION['PO']->trans_type = ST_SUPPRECEIVE;
+ $_SESSION['PO']->reference = $Refs->get_next(ST_SUPPRECEIVE,
+ array('date' => Today(), 'supplier' => $_SESSION['PO']->supplier_id));
+ foreach ($_SESSION['PO']->line_items as $line)
+ $line->quantity = $line->qty_ordered - $line->qty_received;
+ copy_from_cart();
+}
+elseif (isset($_GET['ModifyGRN']) && $_GET['ModifyGRN'] > 0 && !isset($_POST['Update']))
+{
+ $_SESSION['page_title'] = _($help_context = "Modify GRN #") . $_GET['ModifyGRN'];
+ create_cart(ST_SUPPRECEIVE, $_GET['ModifyGRN']);
+ copy_from_cart();
+}
+
+page($_SESSION['page_title'], false, false, "", $js);
//---------------------------------------------------------------------------------------------------------------
-if (isset($_GET['AddedID']))
+if (isset($_GET['AddedID']) || isset($_GET['UpdatedID']))
{
- $grn = $_GET['AddedID'];
+ $new = isset($_GET['AddedID']);
+ $grn = $_GET[$new ? 'AddedID' : 'UpdatedID'];
$trans_type = ST_SUPPRECEIVE;
display_notification_centered(_("Purchase Order Delivery has been processed"));
hyperlink_params("$path_to_root/purchasing/supplier_invoice.php", _("Entry purchase &invoice for this receival"), "New=1");
- hyperlink_no_params("$path_to_root/purchasing/inquiry/po_search.php", _("Select a different &purchase order for receiving items against"));
+ if ($new)
+ hyperlink_no_params("$path_to_root/purchasing/inquiry/po_search.php", _("Select another &purchase order for receiving items against"));
+ else
+ hyperlink_no_params("$path_to_root/purchasing/inquiry/supplier_inquiry.php", _("Select another &document for edition"));
display_footer_exit();
}
//--------------------------------------------------------------------------------------------------
-if ((!isset($_GET['PONumber']) || $_GET['PONumber'] == 0) && !isset($_SESSION['PO']))
+if ((!isset($_GET['PONumber']) || $_GET['PONumber'] == 0) && (!isset($_GET['ModifyGRN']) || $_GET['ModifyGRN'] == 0) && !isset($_SESSION['PO']))
{
- die (_("This page can only be opened if a purchase order has been selected. Please select a purchase order first."));
+ die (_("This page can only be opened with valid Purchase Order or GRN number."));
}
//--------------------------------------------------------------------------------------------------
{
div_start('grn_items');
start_table(TABLESTYLE, "colspan=7 width='90%'");
- $th = array(_("Item Code"), _("Description"), _("Ordered"), _("Units"), _("Received"),
- _("Outstanding"), _("This Delivery"), _("Price"), _("Total"));
+ $mod_grn = $_SESSION['PO']->grn_id;
+
+ if ($mod_grn) // modify GRN
+ $th = array(_("Item Code"), _("Description"), _("Ordered"), _("Units"), _("Received"), _("Invoiced"), _("This Delivery"), _("Price"), _("Total"));
+ else
+ $th = array(_("Item Code"), _("Description"), _("Ordered"), _("Units"), _("Received"), _("Outstanding"), _("This Delivery"), _("Price"), _("Total"));
table_header($th);
- /*show the line items on the order with the quantity being received for modification */
+ /* show the line items on the order with the quantity being received for modification */
$total = 0;
$k = 0; //row colour counter
- if (count($_SESSION['PO']->line_items)> 0 )
+ if (count($_SESSION['PO']->line_items) > 0 )
{
foreach ($_SESSION['PO']->line_items as $ln_itm)
{
alt_table_row_color($k);
- $qty_outstanding = $ln_itm->quantity - $ln_itm->qty_received;
+ $qty_outstanding = $ln_itm->qty_ordered - $ln_itm->qty_received;
- if (!isset($_POST['Update']) && !isset($_POST['ProcessGoodsReceived']) && $ln_itm->receive_qty == 0)
+ if (!isset($_POST['Update']) && !isset($_POST['ProcessGoodsReceived']) && $ln_itm->quantity == 0)
{ //If no quantites yet input default the balance to be received
- $ln_itm->receive_qty = $qty_outstanding;
+ $ln_itm->quantity = $qty_outstanding;
}
- $line_total = ($ln_itm->receive_qty * $ln_itm->price);
+ $line_total = ($ln_itm->quantity * $ln_itm->price);
$total += $line_total;
label_cell($ln_itm->stock_id);
- if ($qty_outstanding > 0)
+ if ($mod_grn || $qty_outstanding > 0)
text_cells(null, $ln_itm->stock_id . "Desc", $ln_itm->item_description, 30, 50);
else
label_cell($ln_itm->item_description);
+
$dec = get_qty_dec($ln_itm->stock_id);
- qty_cell($ln_itm->quantity, false, $dec);
+ qty_cell($ln_itm->qty_ordered, false, $dec);
label_cell($ln_itm->units);
qty_cell($ln_itm->qty_received, false, $dec);
- qty_cell($qty_outstanding, false, $dec);
+ if ($mod_grn)
+ qty_cell($ln_itm->qty_inv, false, $dec);
+ else
+ qty_cell($qty_outstanding, false, $dec);
- if ($qty_outstanding > 0)
- qty_cells(null, $ln_itm->line_no, number_format2($ln_itm->receive_qty, $dec), "align=right", null, $dec);
+ if ($mod_grn || $qty_outstanding > 0)
+ qty_cells(null, $ln_itm->line_no, number_format2($ln_itm->quantity, $dec), "align=right", null, $dec);
else
- label_cell(number_format2($ln_itm->receive_qty, $dec), "align=right");
+ label_cell(number_format2($ln_itm->quantity, $dec), "align=right");
amount_decimal_cell($ln_itm->price);
amount_cell($line_total);
{
$ln_item = $_SESSION['PO']->line_items[$line_no];
// only compare against items that are outstanding
- $qty_outstanding = $ln_item->quantity - $ln_item->qty_received;
+ $qty_outstanding = $ln_item->qty_ordered - $ln_item->qty_received;
if ($qty_outstanding > 0)
{
if ($ln_item->qty_inv != $myrow["qty_invoiced"] ||
$ln_item->stock_id != $myrow["item_code"] ||
- $ln_item->quantity != $myrow["quantity_ordered"] ||
- $ln_item->qty_received != $myrow["quantity_received"])
+ $ln_item->qty_ordered != $myrow["quantity_ordered"] ||
+ $ln_item->qty_received + @$ln_item->qty_old != $myrow["quantity_received"])
{
return true;
}
function can_process()
{
global $SysPrefs;
-
+
if (count($_SESSION['PO']->line_items) <= 0)
{
display_error(_("There is nothing to process. Please enter valid quantities greater than zero."));
return false;
}
- if (!check_reference($_POST['ref'], ST_SUPPRECEIVE))
+ if (!check_reference($_POST['ref'], ST_SUPPRECEIVE, $_SESSION['PO']->grn_id))
{
set_focus('ref');
return false;
$something_received = 0;
foreach ($_SESSION['PO']->line_items as $order_line)
{
- if ($order_line->receive_qty > 0)
+ if ($order_line->quantity > 0)
{
$something_received = 1;
break;
$delivery_qty_too_large = 0;
foreach ($_SESSION['PO']->line_items as $order_line)
{
- if ($order_line->receive_qty+$order_line->qty_received >
- $order_line->quantity * (1+ ($SysPrefs->over_receive_allowance() / 100)))
+ if ($order_line->quantity+$order_line->qty_received >
+ $order_line->qty_ordered * (1+ ($SysPrefs->over_receive_allowance() / 100)))
{
$delivery_qty_too_large = 1;
break;
hyperlink_no_params("$path_to_root/purchasing/inquiry/po_search.php",
_("Select a different purchase order for receiving goods against"));
- hyperlink_params("$path_to_root/purchasing/po_receive_items.php",
- _("Re-Read the updated purchase order for receiving goods against"),
- "PONumber=" . $_SESSION['PO']->order_no);
+ if (!$_SESSION['PO']->grn_id)
+ hyperlink_params("$path_to_root/purchasing/po_receive_items.php",
+ _("Re-Read the updated purchase order for receiving goods against"),
+ "PONumber=" . $_SESSION['PO']->order_no);
+ else
+ hyperlink_params("$path_to_root/purchasing/po_receive_items.php",
+ _("Re-Read the GRN for reedition"),
+ "ModifyGRN=" . $_SESSION['PO']->grn_id);
unset($_SESSION['PO']->line_items);
unset($_SESSION['PO']);
$grn->Location = $_POST['Location'];
$grn->ex_rate = input_num('_ex_rate', null);
- $grn_no = add_grn($grn);
+ $trans_no = write_grn($grn);
+ $new = $grn->grn_id == 0;
new_doc_date($_POST['DefaultReceivedDate']);
unset($_SESSION['PO']->line_items);
unset($_SESSION['PO']);
- meta_forward($_SERVER['PHP_SELF'], "AddedID=$grn_no");
-}
-
-//--------------------------------------------------------------------------------------------------
-
-if (isset($_GET['PONumber']) && $_GET['PONumber'] > 0 && !isset($_POST['Update']))
-{
- create_new_po(ST_PURCHORDER, $_GET['PONumber']);
- $_SESSION['PO']->trans_type = ST_SUPPRECEIVE;
- $_SESSION['PO']->reference = $Refs->get_next(ST_SUPPRECEIVE,
- array('date' => Today(), 'supplier' => $_SESSION['PO']->supplier_id));
- copy_from_cart();
+ if ($new)
+ meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no");
+ else
+ meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$trans_no");
}
//--------------------------------------------------------------------------------------------------
if (isset($_POST['Update']) || isset($_POST['ProcessGoodsReceived']))
{
-
/* if update quantities button is hit page has been called and ${$line->line_no} would have be
set from the post to the quantity to be received in this receival*/
foreach ($_SESSION['PO']->line_items as $line)
{
- if( ($line->quantity - $line->qty_received)>0) {
+ if( ($line->qty_ordered - $line->qty_received) > 0) {
$_POST[$line->line_no] = max($_POST[$line->line_no], 0);
if (!check_num($line->line_no))
$_POST[$line->line_no] = number_format2(0, get_qty_dec($line->stock_id));
if (!isset($_POST['DefaultReceivedDate']) || $_POST['DefaultReceivedDate'] == "")
$_POST['DefaultReceivedDate'] = new_doc_date();
- $_SESSION['PO']->line_items[$line->line_no]->receive_qty = input_num($line->line_no);
+ $_SESSION['PO']->line_items[$line->line_no]->quantity = input_num($line->line_no);
if (isset($_POST[$line->stock_id . "Desc"]) && strlen($_POST[$line->stock_id . "Desc"]) > 0)
{
foreach ($purchase_order->line_items as $stock_item)
{
-
- $line_total = $stock_item->qty_received * $stock_item->price;
+ $line_total = $stock_item->quantity * $stock_item->price;
// if overdue and outstanding quantities, then highlight as so
if (date1_greater_date2($purchase_order->orig_order_date, $stock_item->req_del_date))
label_cell($stock_item->item_description);
label_cell($stock_item->req_del_date, "nowrap align=right");
$dec = get_qty_dec($stock_item->stock_id);
- qty_cell($stock_item->qty_received, false, $dec);
+ qty_cell($stock_item->quantity, false, $dec);
label_cell($stock_item->units);
amount_decimal_cell($stock_item->price);
amount_cell($line_total);