5 include_once($path_to_root . "/includes/session.inc");
7 include_once($path_to_root . "/includes/date_functions.inc");
8 include_once($path_to_root . "/includes/db/inventory_db.inc");
9 include_once($path_to_root . "/includes/manufacturing.inc");
11 include_once($path_to_root . "/manufacturing/includes/manufacturing_db.inc");
12 include_once($path_to_root . "/manufacturing/includes/manufacturing_ui.inc");
16 $js .= get_js_date_picker();
17 page(_("Produce or Unassemble Finished Items From Work Order"), false, false, "", $js);
19 if (isset($_GET['trans_no']) && $_GET['trans_no'] != "")
21 $_POST['selected_id'] = $_GET['trans_no'];
24 //--------------------------------------------------------------------------------------------------
26 if (isset($_GET['AddedID']))
29 display_note(_("The manufacturing process has been entered."));
31 hyperlink_no_params("search_work_orders.php", _("Select another Work Order to Process"));
37 //--------------------------------------------------------------------------------------------------
39 $wo_details = get_work_order($_POST['selected_id']);
41 if (strlen($wo_details[0]) == 0)
43 display_error(_("The order number sent is not valid."));
47 //--------------------------------------------------------------------------------------------------
49 function can_process()
53 if (!references::is_valid($_POST['ref']))
55 display_error(_("You must enter a reference."));
60 if (!is_new_reference($_POST['ref'], 29))
62 display_error(_("The entered reference is already in use."));
67 if (!check_num('quantity', 0))
69 display_error(_("The quantity entered is not a valid number or less then zero."));
70 set_focus('quantity');
74 if (!is_date($_POST['date_']))
76 display_error(_("The entered date is invalid."));
80 elseif (!is_date_in_fiscalyear($_POST['date_']))
82 display_error(_("The entered date is not in fiscal year."));
86 if (date_diff(sql2date($wo_details["released_date"]), $_POST['date_'], "d") > 0)
88 display_error(_("The production date cannot be before the release date of the work order."));
93 // if unassembling we need to check the qoh
94 if (($_POST['ProductionType'] == 0) && !sys_prefs::allow_negative_stock())
96 $wo_details = get_work_order($_POST['selected_id']);
98 $qoh = get_qoh_on_date($wo_details["stock_id"], $wo_details["loc_code"], $date_);
99 if (-$_POST['quantity'] + $qoh < 0)
101 display_error(_("The unassembling cannot be processed because there is insufficient stock."));
102 set_focus('quantity');
110 //--------------------------------------------------------------------------------------------------
112 if (isset($_POST['Process']) || (isset($_POST['ProcessAndClose']) && can_process() == true))
116 if (isset($_POST['ProcessAndClose']) && ($_POST['ProcessAndClose']!=""))
119 // if unassembling, negate quantity
120 if ($_POST['ProductionType'] == 0)
121 $_POST['quantity'] = -$_POST['quantity'];
123 $id = work_order_produce($_POST['selected_id'], $_POST['ref'], $_POST['quantity'],
124 $_POST['date_'], $_POST['memo_'], $close_wo);
126 meta_forward($_SERVER['PHP_SELF'], "AddedID=$id");
129 //-------------------------------------------------------------------------------------
131 display_wo_details($_POST['selected_id']);
133 //-------------------------------------------------------------------------------------
137 hidden('selected_id', $_POST['selected_id']);
138 //hidden('WOReqQuantity', $_POST['WOReqQuantity']);
140 if (!isset($_POST['quantity']) || $_POST['quantity'] == '')
142 $_POST['quantity'] = max($wo_details["units_reqd"] - $wo_details["units_issued"], 0);
147 ref_row(_("Reference:"), 'ref', references::get_next(29));
149 if (!isset($_POST['ProductionType']))
150 $_POST['ProductionType'] = 1;
152 yesno_list_row(_("Type:"), 'ProductionType', $_POST['ProductionType'],
153 _("Produce Finished Items"), _("Return Items to Work Order"));
155 text_row(_("Quantity:"), 'quantity', $_POST['quantity'], 13, 15);
157 date_row(_("Date:"), 'date_');
159 textarea_row(_("Memo:"), 'memo_', null, 40, 3);
163 submit_center_first('Process', _("Process"));
164 submit_center_last('ProcessAndClose', _("Process And Close Order"));