5 include_once($path_to_root . "/includes/session.inc");
7 page(_("Produce or Unassemble Finished Items From Work Order"));
9 include_once($path_to_root . "/includes/date_functions.inc");
10 include_once($path_to_root . "/includes/db/inventory_db.inc");
11 include_once($path_to_root . "/includes/manufacturing.inc");
13 include_once($path_to_root . "/manufacturing/includes/manufacturing_db.inc");
14 include_once($path_to_root . "/manufacturing/includes/manufacturing_ui.inc");
16 if (isset($_GET['trans_no']) && $_GET['trans_no'] != "")
18 $_POST['selected_id'] = $_GET['trans_no'];
21 //--------------------------------------------------------------------------------------------------
23 if (isset($_GET['AddedID']))
26 display_note(_("The manufacturing process has been entered."));
28 hyperlink_no_params("search_work_orders.php", _("Select another Work Order to Process"));
34 //--------------------------------------------------------------------------------------------------
36 $wo_details = get_work_order($_POST['selected_id']);
38 if (strlen($wo_details[0]) == 0)
40 display_error(_("The order number sent is not valid."));
44 //--------------------------------------------------------------------------------------------------
46 function can_process()
50 if (!references::is_valid($_POST['ref']))
52 display_error(_("You must enter a reference."));
56 if (!is_new_reference($_POST['ref'], 29))
58 display_error(_("The entered reference is already in use."));
62 if (!is_numeric($_POST['quantity']))
64 display_error(_("The quantity entered is not a valid number."));
68 if ($_POST['quantity'] <= 0)
70 display_error(_("The quantity entered must be greater than zero."));
74 if (!is_date($_POST['date_']))
76 display_error(_("The entered date is invalid."));
79 elseif (!is_date_in_fiscalyear($_POST['date_']))
81 display_error(_("The entered date is not in fiscal year."));
84 if (date_diff(sql2date($wo_details["released_date"]), $_POST['date_'], "d") > 0)
86 display_error(_("The production date cannot be before the release date of the work order."));
90 // if unassembling we need to check the qoh
91 if (($_POST['ProductionType'] == 0) && !sys_prefs::allow_negative_stock())
93 $wo_details = get_work_order($_POST['selected_id']);
95 $qoh = get_qoh_on_date($wo_details["stock_id"], $wo_details["loc_code"], $date_);
96 if (-$_POST['quantity'] + $qoh < 0)
98 display_error(_("The unassembling cannot be processed because there is insufficient stock."));
106 //--------------------------------------------------------------------------------------------------
108 if (isset($_POST['Process']) || (isset($_POST['ProcessAndClose']) && can_process() == true))
112 if (isset($_POST['ProcessAndClose']) && ($_POST['ProcessAndClose']!=""))
115 // if unassembling, negate quantity
116 if ($_POST['ProductionType'] == 0)
117 $_POST['quantity'] = -$_POST['quantity'];
119 $id = work_order_produce($_POST['selected_id'], $_POST['ref'], $_POST['quantity'],
120 $_POST['date_'], $_POST['memo_'], $close_wo);
122 meta_forward($_SERVER['PHP_SELF'], "AddedID=$id");
125 //-------------------------------------------------------------------------------------
127 display_wo_details($_POST['selected_id']);
129 //-------------------------------------------------------------------------------------
133 hidden('selected_id', $_POST['selected_id']);
134 //hidden('WOReqQuantity', $_POST['WOReqQuantity']);
136 if (!isset($_POST['quantity']) || $_POST['quantity'] == '')
138 $_POST['quantity'] = max($wo_details["units_reqd"] - $wo_details["units_issued"], 0);
143 ref_row(_("Reference:"), 'ref', references::get_next(29));
145 if (!isset($_POST['ProductionType']))
146 $_POST['ProductionType'] = 1;
148 yesno_list_row(_("Type:"), 'ProductionType', $_POST['ProductionType'],
149 _("Produce Finished Items"), _("Return Items to Work Order"));
151 text_row(_("Quantity:"), 'quantity', $_POST['quantity'], 13, 15);
153 date_row(_("Date:"), 'date_');
155 textarea_row(_("Memo:"), 'memo_', null, 40, 3);
159 submit_center_first('Process', _("Process"));
160 submit_center_last('ProcessAndClose', _("Process And Close Order"));