$array[$key] = $el;
}
}
-
+//
+// Search $needle in $haystack or in $haystack[][$valuekey]
+// returns $needle found or null.
+//
function array_search_value($needle, $haystack, $valuekey=null)
{
foreach($haystack as $key => $value) {
}
return null;
}
-
-function array_search_key($needle, $haystack, $valuekey=null)
+//
+// Search $needle in $haystack or in $haystack[][$valuekey]
+// returns array of keys of $haystack elements found
+//
+function array_search_keys($needle, $haystack, $valuekey=null)
{
+ $keys = array();
foreach($haystack as $key => $value) {
$val = isset($valuekey) ? $value[$valuekey] : $value;
if ($needle == $val){
- return $key;
+ $keys[] = $key;
}
}
- return null;
+ return $keys;
+}
+//
+// Find first (single) $needle in $haystack or in $haystack[][$valuekey]
+// returns $haystack element found or null
+//
+function array_search_key($needle, $haystack, $valuekey=null)
+{
+ $keys = array_search_keys($needle, $haystack, $valuekey);
+ return @$keys[0];
}
?>
\ No newline at end of file
."<input type='text' $disabled name='{$name}_text' id='{$name}_text' size='".
$opts['editable']."' maxlength='".$opts['max']."' $rel value='$edit'>\n";
set_focus($name.'_text'); // prevent lost focus
- } else if (isset($_POST['_'.$name.'_edit']))
+ } else if (get_post($search_submit ? $search_submit : "_{$name}_button"))
set_focus($name); // prevent lost focus
if (!$opts['editable'])
$txt = $found;
{
global $all_items;
- $sql = "SELECT stock_id, s.description, c.description, s.inactive
+ $sql = "SELECT stock_id, s.description, c.description, s.inactive, s.editable
FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c WHERE s.category_id=c.category_id";
if ($editkey)
array('where'=>array("mb_flag!= 'M'"),
'show_inactive'=>$all), $editkey);
}
-
+//
+// This helper is used in PO/GRN/PI entry and supports editable descriptions.
+//
function stock_purchasable_items_list_cells($label, $name, $selected_id=null,
$all_option=false, $submit_on_change=false, $editkey=false)
{
echo "<td>$label</td>\n";
echo stock_items_list($name, $selected_id, $all_option, $submit_on_change,
array('where'=>array("mb_flag!= 'M'"),
+ 'editable' => 30,
'cells'=>true), $editkey);
}
-
+/*
function stock_purchasable_items_list_row($label, $name, $selected_id=null,
$all_option=false, $submit_on_change=false, $editkey=false)
{
$all_option, $submit_on_change, $editkey);
echo "</tr>\n";
}
-
+*/
//------------------------------------------------------------------------------------
function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=true)
//-------------------------------------------------------------------------------------------------------------
-function add_grn(&$po, $date_, $reference, $location)
+function add_grn(&$po)
{
global $Refs;
+ $date_ = $po->orig_order_date;
+
begin_transaction();
- $grn = add_grn_batch($po->order_no, $po->supplier_id, $reference, $location, $date_);
+ $grn = add_grn_batch($po->order_no, $po->supplier_id, $po->reference, $po->Location, $date_);
- foreach ($po->line_items as $order_line)
+ foreach ($po->line_items as $line_no => $order_line)
{
if ($order_line->receive_qty != 0 && $order_line->receive_qty != "" && isset($order_line->receive_qty))
$order_line->stock_id, $order_line->item_description,
$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, $location, $date_, "",
+ 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 */
- $Refs->save(ST_SUPPRECEIVE, $grn, $reference);
+ $Refs->save(ST_SUPPRECEIVE, $grn, $po->reference);
add_audit_trail(ST_SUPPRECEIVE, $grn, $date_);
$supp_trans->tran_date = sql2date($trans_row["tran_date"]);
$supp_trans->due_date = sql2date($trans_row["due_date"]);
//$supp_trans->Comments = $trans_row["TransText"];
- $supp_trans->Comments = "";
+ $supp_trans->Comments = get_comments_string($trans_type, $trans_no);
$supp_trans->reference = $trans_row["reference"];
$supp_trans->supp_reference = $trans_row["supp_reference"];
$supp_trans->ov_amount = $trans_row["ov_amount"];
db_escape($po_obj->Comments) . ",'" .
date2sql($po_obj->orig_order_date) . "', " .
db_escape($po_obj->reference) . ", " .
- db_escape($po_obj->requisition_no) . ", " .
+ db_escape($po_obj->supp_ref) . ", " .
db_escape($po_obj->Location) . ", " .
db_escape($po_obj->delivery_address) . ")";
$po_obj->order_no = db_insert_id();
/*Insert the purchase order detail records */
- foreach ($po_obj->line_items as $po_line)
+ foreach ($po_obj->line_items as $line_no => $po_line)
{
$sql = "INSERT INTO ".TB_PREF."purch_order_details (order_no, item_code, description, delivery_date, unit_price, quantity_ordered) VALUES (";
$sql .= $po_obj->order_no . ", " . db_escape($po_line->stock_id). "," .
db_escape($po_line->price) . ", " .
db_escape($po_line->quantity). ")";
db_query($sql, "One of the purchase order detail records could not be inserted");
+ $po_obj->line_items[$line_no]->po_detail_rec = db_insert_id();
}
$Refs->save(ST_PURCHORDER, $po_obj->order_no, $po_obj->reference);
/*Update the purchase order header with any changes */
$sql = "UPDATE ".TB_PREF."purch_orders SET Comments=" . db_escape($po_obj->Comments) . ",
- requisition_no= ". db_escape( $po_obj->requisition_no). ",
+ requisition_no= ". db_escape( $po_obj->supp_ref). ",
into_stock_location=" . db_escape($po_obj->Location). ",
ord_date='" . date2sql($po_obj->orig_order_date) . "',
delivery_address=" . db_escape($po_obj->delivery_address);
$order->orig_order_date = sql2date($myrow["ord_date"]);
$order->Comments = $myrow["comments"];
$order->Location = $myrow["into_stock_location"];
- $order->requisition_no = $myrow["requisition_no"];
+ $order->supp_ref = $myrow["requisition_no"];
$order->reference = $myrow["reference"];
$order->delivery_address = $myrow["delivery_address"];
class purch_order
{
- var $supplier_id;
-
+ var $trans_type; // order/grn/invoice (direct)
var $line_items; /*array of objects of class line_details using the product id as the pointer */
var $curr_code;
- var $requisition_no;
+ var $supp_ref;
var $delivery_address;
var $Comments;
var $Location;
+ var $supplier_id;
var $supplier_name;
var $orig_order_date;
var $order_no; /*Only used for modification of existing orders otherwise only established when order committed */
{
if ($qty != 0 && isset($qty))
{
- $this->line_items[$line_no] = new line_details($line_no, $stock_id, $item_descr, $qty, $price, $uom, $req_del_date, $qty_inv, $qty_recd);
+ $this->line_items[$line_no] = new line_details($line_no, $stock_id, $item_descr, $qty, $price, $uom,
+ $req_del_date, $qty_inv, $qty_recd);
$this->lines_on_order++;
return 1;
}
return 0;
}
- function update_order_item($line_no, $qty, $price, $req_del_date)
+ function update_order_item($line_no, $qty, $price, $req_del_date, $description="")
{
+ if ($description != "")
+ $this->line_items[$line_no]->item_description = $description;
$this->line_items[$line_no]->quantity = $qty;
$this->line_items[$line_no]->price = $price;
$this->line_items[$line_no]->req_del_date = $req_del_date;
var $line_no;
var $po_detail_rec;
+ var $grn_item_id;
var $stock_id;
var $item_description;
var $quantity;
var $qty_received;
var $standard_cost;
var $receive_qty;
+ var $descr_editable;
- function line_details($line_no, $stock_item, $item_descr, $qty, $prc, $uom, $req_del_date, $qty_inv, $qty_recd)
+ function line_details($line_no, $stock_item, $item_descr, $qty, $prc, $uom, $req_del_date,
+ $qty_inv, $qty_recd, $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->item_description = $item_descr;
+ $item_row = get_item($stock_item);
+ if (!$item_row)
+ return;
+
+ $this->descr_editable = $item_row["editable"];
+ if ($item_descr == null || !$this->descr_editable)
+ $this->item_description = $item_row["description"];
+ else
+ $this->item_description = $item_descr;
$this->quantity = $qty;
$this->req_del_date = $req_del_date;
$this->price = $prc;
- $this->units = $uom;
+// $this->units = $uom;
+ $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->standard_cost =0;
+ $this->grn_item_id = $grn_item_id;
}
}
"class='tableheader2'");
label_cells(_("Ordered On"), $po->orig_order_date, "class='tableheader2'");
- label_cells(_("Supplier's Reference"), $po->requisition_no, "class='tableheader2'");
end_row();
start_row();
$_POST['DefaultReceivedDate'] = new_doc_date();
date_cells(_("Date Items Received"), 'DefaultReceivedDate', '', true, 0, 0, 0, "class='tableheader2'");
-
+ // currently this is related order supp reference
+// ref_cells(_("Supplier's Reference"), 'supp_ref', _("Supplier's Reference"), null, "class='tableheader2'");
+ label_cells(_("Supplier's Reference"), $po->supp_ref, "class='tableheader2'");
}
else
{
label_cells(_("Reference"), $po->reference, "class='tableheader2'");
label_cells(_("Deliver Into Location"), get_location_name($po->Location), "class='tableheader2'");
+ label_cells(_("Supplier's Reference"), $po->supp_ref, "class='tableheader2'");
}
end_row();
***********************************************************************/
include_once($path_to_root . "/purchasing/includes/purchasing_db.inc");
+//--------------------------------------------------------------------------------------------------
+
+function copy_from_cart()
+{
+ $cart = &$_SESSION['PO'];
+
+ $_POST['supplier_id'] = $cart->supplier_id;
+ $_POST['OrderDate'] = $cart->orig_order_date;
+ $_POST['supp_ref'] = $cart->supp_ref;
+ $_POST['ref'] = $cart->reference;
+ $_POST['Comments'] = $cart->Comments;
+ $_POST['StkLocation'] = $cart->Location;
+ $_POST['delivery_address'] = $cart->delivery_address;
+}
+
+function copy_to_cart()
+{
+ $cart = &$_SESSION['PO'];
+
+ $cart->supplier_id = $_POST['supplier_id'];
+ $cart->orig_order_date = $_POST['OrderDate'];
+ $cart->reference = $_POST['ref'];
+ $cart->supp_ref = $_POST['supp_ref'];
+ $cart->Comments = $_POST['Comments'];
+ $cart->Location = $_POST['StkLocation'];
+ $cart->delivery_address = $_POST['delivery_address'];
+}
// ------------------------------------------------------------------------------
function get_supplier_details_to_order(&$order, $supplier_id)
//---------------------------------------------------------------------------------------------------
-function create_new_po()
+function create_new_po($trans_type, $trans_no)
{
- if (isset($_SESSION['PO']))
- {
- unset ($_SESSION['PO']->line_items);
- $_SESSION['PO']->lines_on_order = 0;
- unset ($_SESSION['PO']);
- }
+ global $Refs;
- //session_register("PO");
+ if (isset($_SESSION['PO']))
+ unset ($_SESSION['PO']->line_items, $_SESSION['PO']);
- $_SESSION['PO'] = new purch_order;
+ $cart = new purch_order;
$_POST['OrderDate'] = new_doc_date();
if (!is_date_in_fiscalyear($_POST['OrderDate']))
$_POST['OrderDate'] = end_fiscalyear();
- $_SESSION['PO']->orig_order_date = $_POST['OrderDate'];
+ $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);
+ $cart->order_no = $trans_no;
+ } else
+ $cart->reference = $Refs->get_next($trans_type);
+ $_SESSION['PO'] = &$cart;
}
//---------------------------------------------------------------------------------------------------
if ($editable)
{
- ref_row(_("Reference:"), 'ref', '', $Refs->get_next(ST_PURCHORDER));
+ ref_row(_("Reference:"), 'ref');
}
else
{
$Ajax->activate('_ex_rate');
}
- text_row(_("Supplier's Reference:"), 'Requisition', null, 16, 15);
+ text_row(_("Supplier's Reference:"), 'supp_ref', null, 16, 15);
echo "<tr><td>" . _("Receive Into:") . "</td>";
echo "<td>";
$th = array(_("Item Code"), _("Item Description"), _("Quantity"),
_("Received"), _("Unit"),
_("Required Delivery Date"), _("Price"), _("Line Total"), "");
-
+ if ($order->trans_type != ST_PURCHORDER)
+ array_remove($th, 5);
+
if (count($order->line_items)) $th[] = '';
table_header($th);
qty_cell($po_line->quantity, false, get_qty_dec($po_line->stock_id));
qty_cell($po_line->qty_received, false, get_qty_dec($po_line->stock_id));
label_cell($po_line->units);
- label_cell($po_line->req_del_date);
+ if ($order->trans_type == ST_PURCHORDER)
+ label_cell($po_line->req_del_date);
amount_decimal_cell($po_line->price);
amount_cell($line_total);
}
else
{
- po_item_controls($order, $po_line->stock_id);
+ po_item_controls($order, $k, $line_no);
}
$total += $line_total;
}
if ($id==-1 && $editable)
- po_item_controls($order);
+ po_item_controls($order, $k);
$display_total = price_format($total);
- label_row(_("Total Excluding Shipping/Tax"), $display_total, "colspan=7 align=right",
+ label_row(_("Total Excluding Shipping/Tax"), $display_total, "colspan="
+ .(count($order->line_items) ? 7:6)." align=right",
"nowrap align=right", 2);
end_table(1);
"class='tableheader2'");
}
- if ($po->requisition_no != "")
- label_cells(_("Supplier's Reference"), $po->requisition_no, "class='tableheader2'");
+ if ($po->supp_ref != "")
+ label_cells(_("Supplier's Reference"), $po->supp_ref, "class='tableheader2'");
end_row();
if (!$editable)
//--------------------------------------------------------------------------------
-function po_item_controls(&$order, $stock_id=null)
+function po_item_controls(&$order, &$rowcounter, $line_no=-1)
{
global $Ajax;
- start_row();
+
+ alt_table_row_color($rowcounter);
$dec2 = 0;
$id = find_submit('Edit');
- if (($id != -1) && $stock_id != null)
+ if (($id != -1) && $line_no == $id)
{
- hidden('line_no', $id);
+// hidden('line_no', $id);
$_POST['stock_id'] = $order->line_items[$id]->stock_id;
- $dec = get_qty_dec($_POST['stock_id']);
+ $dec = get_qty_dec($_POST['stock_id']);
$_POST['qty'] = qty_format($order->line_items[$id]->quantity, $_POST['stock_id'], $dec);
//$_POST['price'] = price_format($order->line_items[$id]->price);
$_POST['price'] = price_decimal_format($order->line_items[$id]->price, $dec2);
- $_POST['req_del_date'] = $order->line_items[$id]->req_del_date;
+ if ($order->trans_type == ST_PURCHORDER)
+ $_POST['req_del_date'] = $order->line_items[$id]->req_del_date;
$_POST['units'] = $order->line_items[$id]->units;
+ $_POST['item_description'] = $order->line_items[$id]->item_description;
hidden('stock_id', $_POST['stock_id']);
label_cell($_POST['stock_id']);
- label_cell($order->line_items[$id]->item_description);
+
+ if ($order->line_items[$id]->descr_editable)
+ text_cells(null,'item_description', null, 45, 150);
+ else {
+ hidden('item_description', $_POST['item_description']);
+// label_cell($_POST['item_description']);
+ label_cell($order->line_items[$id]->item_description);
+ }
+
$Ajax->activate('items_table');
$qty_rcvd = $order->line_items[$id]->qty_received;
}
else
{
- hidden('line_no', ($_SESSION['PO']->lines_on_order + 1));
+// hidden('line_no', ($_SESSION['PO']->lines_on_order + 1));
stock_purchasable_items_list_cells(null, 'stock_id', null, false, true, true);
if (list_updated('stock_id')) {
$_POST['qty'] = number_format2(get_purchase_conversion_factor ($order->supplier_id, $_POST['stock_id']), $dec);
//$_POST['price'] = price_format(get_purchase_price ($order->supplier_id, $_POST['stock_id']));
$_POST['price'] = price_decimal_format(get_purchase_price ($order->supplier_id, $_POST['stock_id']), $dec2);
- $_POST['req_del_date'] = add_days(Today(), 10);
+ if ($order->trans_type == ST_PURCHORDER)
+ $_POST['req_del_date'] = add_days(Today(), 10);
$qty_rcvd = '';
}
qty_cell($qty_rcvd, false, $dec);
label_cell($_POST['units'], '', 'units');
- date_cells(null, 'req_del_date', '', null, 0, 0, 0);
+ if ($order->trans_type == ST_PURCHORDER)
+ date_cells(null, 'req_del_date', '', null, 0, 0, 0);
amount_cells(null, 'price', null, null, null, $dec2);
//$line_total = $_POST['qty'] * $_POST['price'] * (1 - $_POST['Disc'] / 100);
_('Confirm changes'), ICON_UPDATE);
button_cell('CancelUpdate', _("Cancel"),
_('Cancel changes'), ICON_CANCEL);
+ hidden('line_no', $line_no);
set_focus('qty');
}
else
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
-$page_security = 'SA_PURCHASEORDER';
$path_to_root = "..";
+$page_security = 'SA_PURCHASEORDER';
include_once($path_to_root . "/purchasing/includes/po_class.inc");
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/purchasing/includes/purchasing_ui.inc");
include_once($path_to_root . "/reporting/includes/reporting.inc");
+set_page_security( @$_SESSION['PO']->trans_type,
+ array( ST_PURCHORDER => 'SA_PURCHASEORDER',
+ ST_SUPPRECEIVE => 'SA_GRN',
+ ST_SUPPINVOICE => 'SA_SUPPLIERINVOICE'),
+ array( 'NewOrder' => 'SA_PURCHASEORDER',
+ 'ModifyOrderNumber' => 'SA_PURCHASEORDER',
+ 'NewGRN' => 'SA_GRN',
+ 'NewInvoice' => 'SA_SUPPLIERINVOICE')
+);
+
$js = '';
if ($use_popup_windows)
$js .= get_js_open_window(900, 500);
if ($use_date_picker)
$js .= get_js_date_picker();
-if (isset($_GET['ModifyOrderNumber']))
-{
- page(_($help_context = "Modify Purchase Order #") . $_GET['ModifyOrderNumber'], false, false, "", $js);
-}
-else
-{
- page(_($help_context = "Purchase Order Entry"), false, false, "", $js);
+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']);
+ copy_from_cart();
+} elseif (isset($_GET['NewOrder'])) {
+
+ $_SESSION['page_title'] = _($help_context = "Purchase Order Entry");
+ create_new_po(ST_PURCHORDER, 0);
+ copy_from_cart();
+} elseif (isset($_GET['NewGRN'])) {
+
+ $_SESSION['page_title'] = _($help_context = "Direct GRN Entry");
+ create_new_po(ST_SUPPRECEIVE, 0);
+ copy_from_cart();
+} elseif (isset($_GET['NewInvoice'])) {
+
+ $_SESSION['page_title'] = _($help_context = "Direct Purchase Invoice Entry");
+ create_new_po(ST_SUPPINVOICE, 0);
+ copy_from_cart();
}
+page($_SESSION['page_title'], false, false, "", $js);
+
//---------------------------------------------------------------------------------------------------
check_db_has_suppliers(_("There are no suppliers defined in the system."));
hyperlink_no_params($path_to_root."/purchasing/inquiry/po_search.php", _("Select An &Outstanding Purchase Order"));
display_footer_exit();
-}
-//--------------------------------------------------------------------------------------------------
-function copy_from_cart()
-{
- $_POST['supplier_id'] = $_SESSION['PO']->supplier_id;
- $_POST['OrderDate'] = $_SESSION['PO']->orig_order_date;
- $_POST['Requisition'] = $_SESSION['PO']->requisition_no;
- $_POST['ref'] = $_SESSION['PO']->reference;
- $_POST['Comments'] = $_SESSION['PO']->Comments;
- $_POST['StkLocation'] = $_SESSION['PO']->Location;
- $_POST['delivery_address'] = $_SESSION['PO']->delivery_address;
-}
+} elseif (isset($_GET['AddedGRN'])) {
-function copy_to_cart()
-{
- $_SESSION['PO']->supplier_id = $_POST['supplier_id'];
- $_SESSION['PO']->orig_order_date = $_POST['OrderDate'];
- $_SESSION['PO']->reference = $_POST['ref'];
- $_SESSION['PO']->requisition_no = $_POST['Requisition'];
- $_SESSION['PO']->Comments = $_POST['Comments'];
- $_SESSION['PO']->Location = $_POST['StkLocation'];
- $_SESSION['PO']->delivery_address = $_POST['delivery_address'];
+ $trans_no = $_GET['AddedGRN'];
+ $trans_type = ST_SUPPRECEIVE;
+
+ display_notification_centered(_("Direct GRN has been entered"));
+
+ display_note(get_trans_view_str($trans_type, $trans_no, _("&View this GRN")), 0, 1);
+
+// not yet
+// display_note(print_document_link($trans_no, _("&Print This GRN"), true, $trans_type), 0, 1);
+
+ hyperlink_params("$path_to_root/purchasing/supplier_invoice.php",
+ _("Entry purchase &invoice for this receival"), "New=1");
+
+ hyperlink_params("$path_to_root/admin/attachments.php", _("Add an Attachment"),
+ "filterType=$trans_type&trans_no=$trans_no");
+
+ hyperlink_params($_SERVER['PHP_SELF'], _("Enter &Another GRN"), "NewGRN=Yes");
+
+ display_footer_exit();
+
+} elseif (isset($_GET['AddedPI'])) {
+
+ $trans_no = $_GET['AddedPI'];
+ $trans_type = ST_SUPPINVOICE;
+
+ display_notification_centered(_("Direct Purchase Invoice has been entered"));
+
+ display_note(get_trans_view_str($trans_type, $trans_no, _("&View this Invoice")), 0);
+
+// not yet
+// display_note(print_document_link($trans_no, _("&Print This Invoice"), true, $trans_type), 0, 1);
+
+ display_note(get_gl_view_str($trans_type, $trans_no, _("View the GL Journal Entries for this Invoice")), 1);
+
+ hyperlink_params("$path_to_root/purchasing/supplier_payment.php", _("Entry supplier &payment for this invoice"),
+ "PInvoice=".$trans_no);
+
+ hyperlink_params("$path_to_root/admin/attachments.php", _("Add an Attachment"),
+ "filterType=$trans_type&trans_no=$trans_no");
+
+ hyperlink_params($_SERVER['PHP_SELF'], _("Enter &Another Direct Invoice"), "NewInvoice=Yes");
+
+ display_footer_exit();
}
//--------------------------------------------------------------------------------------------------
function check_data()
{
+ if(!get_post('stock_id_text', true)) {
+ display_error( _("Item description cannot be empty."));
+ set_focus('stock_id_edit');
+ return false;
+ }
+
$dec = get_qty_dec($_POST['stock_id']);
$min = 1 / pow(10, $dec);
if (!check_num('qty',$min))
set_focus('price');
return false;
}
- if (!is_date($_POST['req_del_date'])){
+ if ($_SESSION['PO']->trans_type == ST_PURCHORDER && !is_date($_POST['req_del_date'])){
display_error(_("The date entered is in an invalid format."));
set_focus('req_del_date');
return false;
}
$_SESSION['PO']->update_order_item($_POST['line_no'], input_num('qty'), input_num('price'),
- $_POST['req_del_date']);
+ @$_POST['req_del_date'], $_POST['item_description'] );
unset_form_variables();
}
line_start_focus();
{
$result = get_short_info($_POST['stock_id']);
- if (db_num_rows($result) == 0)
- {
+ if (db_num_rows($result) == 0)
+ {
$allow_update = false;
- }
+ }
if ($allow_update)
- {
+ {
$myrow = db_fetch($result);
- $_SESSION['PO']->add_to_order ($_POST['line_no'], $_POST['stock_id'], input_num('qty'),
- $myrow["description"], input_num('price'), $myrow["units"],
- $_POST['req_del_date'], 0, 0);
+ $_SESSION['PO']->add_to_order (count($_SESSION['PO']->line_items), $_POST['stock_id'], input_num('qty'),
+ get_post('stock_id_text'), //$myrow["description"],
+ input_num('price'), '', // $myrow["units"], (retrived in cart)
+ $_SESSION['PO']->trans_type == ST_PURCHORDER ? $_POST['req_del_date'] : '', 0, 0);
unset_form_variables();
$_POST['stock_id'] = "";
return false;
}
- if (!is_new_reference(get_post('ref'), ST_PURCHORDER))
+ if (!is_new_reference(get_post('ref'), $_SESSION['PO']->trans_type))
{
display_error(_("The entered reference is already in use."));
set_focus('ref');
}
}
- if (get_post('delivery_address') == '')
+ if ($_SESSION['PO']->trans_type == ST_PURCHORDER && get_post('delivery_address') == '')
{
display_error(_("There is no delivery address specified."));
set_focus('delivery_address');
function handle_commit_order()
{
+ $cart = &$_SESSION['PO'];
- if (can_commit())
- {
- copy_to_cart();
+ if (can_commit()) {
- if ($_SESSION['PO']->order_no == 0)
- {
-
+ copy_to_cart();
+ if ($cart->trans_type != ST_PURCHORDER) {
+ // for direct grn/invoice set same dates for lines as for whole document
+ foreach ($cart->line_items as $line_no =>$line)
+ $cart->line_items[$line_no]->req_del_date = $cart->orig_order_date;
+ }
+ if ($cart->order_no == 0) { // new po/grn/invoice
/*its a new order to be inserted */
- $order_no = add_po($_SESSION['PO']);
- new_doc_date($_SESSION['PO']->orig_order_date);
+ $ref = $cart->reference;
+ if ($cart->trans_type != ST_PURCHORDER) {
+ $cart->reference = 'auto';
+ begin_transaction(); // all db changes as single transaction for direct document
+ }
+ $order_no = add_po($cart);
+ new_doc_date($cart->orig_order_date);
+ $cart->order_no = $order_no;
+
+ if ($cart->trans_type == ST_PURCHORDER) {
+ unset($_SESSION['PO']);
+ meta_forward($_SERVER['PHP_SELF'], "AddedID=$order_no");
+ }
+ //Direct GRN
+ if ($cart->trans_type == ST_SUPPRECEIVE)
+ $cart->reference = $ref;
+ $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);
+ if ($cart->trans_type == ST_SUPPRECEIVE) {
+ commit_transaction(); // save PO+GRN
+ unset($_SESSION['PO']);
+ meta_forward($_SERVER['PHP_SELF'], "AddedGRN=$grn_no");
+ }
+// Direct Purchase Invoice
+ $inv = new supp_trans;
+ $inv->is_invoice = true;
+ $inv->Comments = $cart->Comments;
+ $inv->supplier_id = $cart->supplier_id;
+ $inv->tran_date = $cart->orig_order_date;
+ $inv->reference = $ref;
+ $inv->supp_reference = $cart->supp_ref;
+ $supp = get_supplier($cart->supplier_id);
+ $inv->tax_group_id = $supp['tax_group_id'];
+// $inv->ov_discount 'this isn't used at all'
+// $inv->terms = not used, TODO
+ $terms = $supp['payment_terms'];
+ $inv->ov_amount = $inv->ov_gst = 0;
+ $inv->due_date = get_invoice_duedate($terms, $inv->tran_date);
+ 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->price, $line->price, true, get_standard_cost($line->stock_id), '');
+ $inv->ov_amount += round2(($line->receive_qty * $line->price), user_price_dec());
+ }
+ $taxes = $inv->get_taxes($inv->tax_group_id, 0, false);
+ foreach( $taxes as $taxitem) {
+ $inv->ov_gst += round2($taxitem['Value'], user_price_dec());
+ }
+ $inv_no = add_supp_invoice($inv);
+ commit_transaction(); // save PO+GRN+PI
+ // payment for cash terms...
unset($_SESSION['PO']);
-
- meta_forward($_SERVER['PHP_SELF'], "AddedID=$order_no");
-
- }
- else
- {
-
- /*its an existing order need to update the old order info */
- $order_no = update_po($_SESSION['PO']);
-
+ meta_forward($_SERVER['PHP_SELF'], "AddedPI=$inv_no");
+ }
+ else { // order modification
+
+ $order_no = update_po($cart);
unset($_SESSION['PO']);
-
meta_forward($_SERVER['PHP_SELF'], "AddedID=$order_no&Updated=1");
}
- }
+ }
}
//---------------------------------------------------------------------------------------------------
$id = find_submit('Delete');
if (isset($_POST['CancelUpdate']))
unset_form_variables();
-if (isset($_GET['ModifyOrderNumber']) && $_GET['ModifyOrderNumber'] != "")
-{
- create_new_po();
-
- $_SESSION['PO']->order_no = $_GET['ModifyOrderNumber'];
-
- /*read in all the selected order into the Items cart */
- read_po($_SESSION['PO']->order_no, $_SESSION['PO']);
-
- copy_from_cart();
-}
-
if (isset($_POST['CancelUpdate']) || isset($_POST['UpdateLine'])) {
line_start_focus();
}
-if (isset($_GET['NewOrder']))
- create_new_po();
-
//---------------------------------------------------------------------------------------------------
start_form();
function check_po_changed()
{
- /*Now need to check that the order details are the same as they were when they were read into the Items array. If they've changed then someone else must have altered them */
+ /*Now need to check that the order details are the same as they were when they were read
+ into the Items array. If they've changed then someone else must have altered them */
// Sherifoz 22.06.03 Compare against COMPLETED items only !!
// Otherwise if you try to fullfill item quantities separately will give error.
$result = get_po_items($_SESSION['PO']->order_no);
if (check_po_changed())
{
display_error(_("This order has been changed or invoiced since this delivery was started to be actioned. Processing halted. To enter a delivery against this purchase order, it must be re-selected and re-read again to update the changes made by the other user."));
+
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);
+
unset($_SESSION['PO']->line_items);
unset($_SESSION['PO']);
unset($_POST['ProcessGoodsReceived']);
$Ajax->activate('_page_body');
display_footer_exit();
}
+
+ $grn = &$_SESSION['PO'];
+ $grn->orig_order_date = $_POST['DefaultReceivedDate'];
+ $grn->reference = $_POST['ref'];
+ $grn->Location = $_POST['Location'];
- $grn = add_grn($_SESSION['PO'], $_POST['DefaultReceivedDate'],
- $_POST['ref'], $_POST['Location']);
+ $grn_no = add_grn($grn);
new_doc_date($_POST['DefaultReceivedDate']);
unset($_SESSION['PO']->line_items);
unset($_SESSION['PO']);
- meta_forward($_SERVER['PHP_SELF'], "AddedID=$grn");
+ meta_forward($_SERVER['PHP_SELF'], "AddedID=$grn_no");
}
//--------------------------------------------------------------------------------------------------
if (isset($_GET['PONumber']) && $_GET['PONumber'] > 0 && !isset($_POST['Update']))
{
-
- create_new_po();
-
- /*read in all the selected order into the Items cart */
- read_po($_GET['PONumber'], $_SESSION['PO']);
+ create_new_po(ST_PURCHORDER, $_GET['PONumber']);
+ $_SESSION['PO']->trans_type = ST_SUPPRECEIVE;
+ $_SESSION['PO']->reference = $Refs->get_next(ST_SUPPRECEIVE);
+ copy_from_cart();
}
//--------------------------------------------------------------------------------------------------