6 include_once($path_to_root . "/purchasing/includes/po_class.inc");
8 include_once($path_to_root . "/includes/session.inc");
10 include_once($path_to_root . "/purchasing/includes/purchasing_ui.inc");
13 if ($use_popup_windows)
14 $js .= get_js_open_window(900, 500);
16 $js .= get_js_date_picker();
18 if (isset($_GET['ModifyOrderNumber']))
20 page(_("Modify Purchase Order #") . $_GET['ModifyOrderNumber'], false, false, "", $js);
24 page(_("Purchase Order Entry"), false, false, "", $js);
27 //---------------------------------------------------------------------------------------------------
29 check_db_has_suppliers(_("There are no suppliers defined in the system."));
31 check_db_has_purchasable_items(_("There are no purchasable inventory items defined in the system."));
33 //---------------------------------------------------------------------------------------------------------------
35 if (isset($_GET['AddedID']))
37 $order_no = $_GET['AddedID'];
38 $trans_type = systypes::po();
40 if (!isset($_GET['Updated']))
41 display_notification_centered(_("Purchase Order has been entered"));
43 display_notification_centered(_("Purchase Order has been updated") . " #$order_no");
44 display_note(get_trans_view_str($trans_type, $order_no, _("View this order")));
46 hyperlink_params($path_to_root . "/purchasing/po_receive_items.php", _("Receive Items on this Purchase Order"), "PONumber=$order_no");
48 hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another Purchase Order"), "NewOrder=yes");
50 hyperlink_no_params($path_to_root."/purchasing/inquiry/po_search.php", _("Select An Outstanding Purchase Order"));
52 display_footer_exit();
55 //--------------------------------------------------------------------------------------------------
59 $_SESSION['PO']->supplier_id = $_POST['supplier_id'];
60 $_SESSION['PO']->orig_order_date = $_POST['OrderDate'];
61 $_SESSION['PO']->reference = $_POST['ref'];
62 $_SESSION['PO']->requisition_no = $_POST['Requisition'];
63 $_SESSION['PO']->Comments = $_POST['Comments'];
64 $_SESSION['PO']->Location = $_POST['StkLocation'];
65 $_SESSION['PO']->delivery_address = $_POST['delivery_address'];
68 //--------------------------------------------------------------------------------------------------
70 function copy_from_po()
72 $_POST['supplier_id'] = $_SESSION['PO']->supplier_id;
73 $_POST['OrderDate'] = $_SESSION['PO']->orig_order_date;
74 $_POST['Requisition'] = $_SESSION['PO']->requisition_no;
75 $_POST['ref'] = $_SESSION['PO']->reference;
76 $_POST['Comments'] = $_SESSION['PO']->Comments;
77 $_POST['StkLocation'] = $_SESSION['PO']->Location;
78 $_POST['delivery_address'] = $_SESSION['PO']->delivery_address;
81 //--------------------------------------------------------------------------------------------------
83 function unset_form_variables() {
84 unset($_POST['stock_id']);
86 unset($_POST['price']);
87 unset($_POST['req_del_date']);
90 //---------------------------------------------------------------------------------------------------
92 function handle_delete_item()
94 $line_no = $_GET['Delete'];
95 if($_SESSION['PO']->some_already_received($line_no) == 0)
97 $_SESSION['PO']->remove_from_order($line_no);
98 unset_form_variables();
102 display_error(_("This item cannot be deleted because some of it has already been received."));
106 //---------------------------------------------------------------------------------------------------
108 function handle_cancel_po()
110 global $path_to_root;
112 //need to check that not already dispatched or invoiced by the supplier
113 if(($_SESSION['PO']->order_no != 0) &&
114 $_SESSION['PO']->any_already_received() == 1)
116 display_error(_("This order cannot be cancelled because some of it has already been received.")
117 . "<br>" . _("The line item quantities may be modified to quantities more than already received. prices cannot be altered for lines that have already been received and quantities cannot be reduced below the quantity already received."));
121 if($_SESSION['PO']->order_no != 0)
123 delete_po($_SESSION['PO']->order_no);
126 $_SESSION['PO']->clear_items();
127 $_SESSION['PO'] = new purch_order;
129 display_note(_("This purchase order has been cancelled."), 0, 1);
131 hyperlink_params($path_to_root . "/purchasing/po_entry_items.php", _("Enter a new purchase order"), "NewOrder=Yes");
138 //---------------------------------------------------------------------------------------------------
139 if (isset($_GET['Delete']) || isset($_GET['Edit']))
144 if (isset($_GET['Delete']))
146 handle_delete_item();
149 //---------------------------------------------------------------------------------------------------
151 function check_data()
153 if (!check_num('qty',0))
155 display_error(_("The quantity of the order item must be numeric and not less than zero."));
159 if (!check_num('price', 0))
161 display_error(_("The price entered must be numeric and not less than zero."));
164 if (!is_date($_POST['req_del_date'])){
165 display_error(_("The date entered is in an invalid format."));
172 //---------------------------------------------------------------------------------------------------
174 function handle_update_item()
176 $allow_update = check_data();
179 ($_SESSION['PO']->line_items[$_POST['line_no']]->qty_inv > input_num('qty') ||
180 $_SESSION['PO']->line_items[$_POST['line_no']]->qty_received > input_num('qty')))
182 display_error(_("You are attempting to make the quantity ordered a quantity less than has already been invoiced or received. This is prohibited.") .
183 "<br>" . _("The quantity received can only be modified by entering a negative receipt and the quantity invoiced can only be reduced by entering a credit note against this item."));
187 $_SESSION['PO']->update_order_item($_POST['line_no'], input_num('qty'), input_num('price'),
188 $_POST['req_del_date']);
189 unset_form_variables();
192 //---------------------------------------------------------------------------------------------------
194 function handle_add_new_item()
196 $allow_update = check_data();
198 if ($allow_update == true)
200 if (count($_SESSION['PO']->line_items) > 0)
202 foreach ($_SESSION['PO']->line_items AS $order_item)
205 /* do a loop round the items on the order to see that the item
206 is not already on this order */
207 if (($order_item->stock_id == $_POST['stock_id']) &&
208 ($order_item->Deleted==False))
210 $allow_update = False;
211 display_error(_("The selected item is already on this order."));
213 } /* end of the foreach loop to look for pre-existing items of the same code */
216 if ($allow_update == true)
218 $sql = "SELECT description, units, mb_flag
219 FROM ".TB_PREF."stock_master WHERE stock_id = '". $_POST['stock_id'] . "'";
221 $result = db_query($sql,"The stock details for " . $_POST['stock_id'] . " could not be retrieved");
223 if (db_num_rows($result) == 0)
225 $allow_update = False;
230 $myrow = db_fetch($result);
231 $_SESSION['PO']->add_to_order ($_POST['line_no'], $_POST['stock_id'], input_num('qty'),
232 $myrow["description"], input_num('price'), $myrow["units"],
233 $_POST['req_del_date'], 0, 0);
235 unset_form_variables();
236 $_POST['StockID2'] = $_POST['stock_id'] = "";
240 display_error(_("The selected item does not exist or it is a kit part and therefore cannot be purchased."));
243 } /* end of if not already on the order and allow input was true*/
247 //---------------------------------------------------------------------------------------------------
249 function can_commit()
251 if (!is_date($_POST['OrderDate']))
253 display_error(_("The entered order date is invalid."));
257 if (!$_SESSION['PO']->order_no)
259 if (!references::is_valid($_SESSION['PO']->reference))
261 display_error(_("There is no reference entered for this purchase order."));
265 if (!is_new_reference($_SESSION['PO']->reference, systypes::po()))
267 display_error(_("The entered reference is already in use."));
272 if ($_SESSION['PO']->delivery_address == "")
274 display_error(_("There is no delivery address specified."));
278 if (!isset($_SESSION['PO']->Location) || $_SESSION['PO']->Location == "")
280 display_error(_("There is no location specified to move any items into."));
284 if ($_SESSION['PO']->order_has_items() == false)
286 display_error (_("The order cannot be placed because there are no lines entered on this order."));
293 //---------------------------------------------------------------------------------------------------
295 function handle_commit_order()
302 if ($_SESSION['PO']->order_no == 0)
305 /*its a new order to be inserted */
306 $order_no = add_po($_SESSION['PO']);
308 unset($_SESSION['PO']);
310 meta_forward($_SERVER['PHP_SELF'], "AddedID=$order_no");
316 /*its an existing order need to update the old order info */
317 $order_no = update_po($_SESSION['PO']);
319 unset($_SESSION['PO']);
321 meta_forward($_SERVER['PHP_SELF'], "AddedID=$order_no&Updated=1");
326 //---------------------------------------------------------------------------------------------------
328 if (isset($_POST['Commit']))
330 handle_commit_order();
333 //---------------------------------------------------------------------------------------------------
335 if (isset($_POST['UpdateLine']))
338 handle_update_item();
341 //---------------------------------------------------------------------------------------------------
343 If (isset($_POST['EnterLine']))
346 handle_add_new_item();
349 //---------------------------------------------------------------------------------------------------
351 if (isset($_POST['CancelOrder']))
356 //---------------------------------------------------------------------------------------------------
358 if (isset($_POST['CancelUpdate']))
361 unset_form_variables();
364 //---------------------------------------------------------------------------------------------------
366 if (isset($_GET['ModifyOrderNumber']) && $_GET['ModifyOrderNumber'] != "")
370 $_SESSION['PO']->order_no = $_GET['ModifyOrderNumber'];
372 /*read in all the selected order into the Items cart */
373 read_po($_SESSION['PO']->order_no, $_SESSION['PO']);
377 //--------------------------------------------------------------------------------
379 if (isset($_GET['NewOrder']))
385 if (!isset($_POST['supplier_id']))
386 $_POST['supplier_id'] = $_SESSION['PO']->supplier_id;
387 if (!isset($_POST['OrderDate']))
388 $_POST['OrderDate'] = $_SESSION['PO']->orig_order_date;
389 if (!isset($_POST['Requisition']))
390 $_POST['Requisition'] = $_SESSION['PO']->requisition_no;
391 if (!isset($_POST['Comments']))
392 $_POST['Comments'] = $_SESSION['PO']->Comments;
395 //---------------------------------------------------------------------------------------------------
397 start_form(false, true);
399 display_po_header($_SESSION['PO']);
402 display_po_items($_SESSION['PO']);
404 start_table($table_style2);
405 textarea_row(_("Memo:"), 'Comments', null, 70, 4);
408 if ($_SESSION['PO']->order_has_items())
410 if ($_SESSION['PO']->order_no)
411 submit_center_first('Commit', _("Update Order"));
413 submit_center_first('Commit', _("Place Order"));
414 submit_center_last('CancelOrder', _("Cancel Order"));
417 submit_center('CancelOrder', _("Cancel Order"));
419 //---------------------------------------------------------------------------------------------------