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");
15 if ($use_popup_windows)
16 $js .= get_js_open_window(900, 500);
18 $js .= get_js_date_picker();
19 page(_("Produce or Unassemble Finished Items From Work Order"), false, false, "", $js);
21 if (isset($_GET['trans_no']) && $_GET['trans_no'] != "")
23 $_POST['selected_id'] = $_GET['trans_no'];
26 //--------------------------------------------------------------------------------------------------
28 if (isset($_GET['AddedID']))
31 display_note(_("The manufacturing process has been entered."));
33 hyperlink_no_params("search_work_orders.php", _("Select another Work Order to Process"));
39 //--------------------------------------------------------------------------------------------------
41 $wo_details = get_work_order($_POST['selected_id']);
43 if (strlen($wo_details[0]) == 0)
45 display_error(_("The order number sent is not valid."));
49 //--------------------------------------------------------------------------------------------------
51 function can_process()
55 if (!references::is_valid($_POST['ref']))
57 display_error(_("You must enter a reference."));
62 if (!is_new_reference($_POST['ref'], 29))
64 display_error(_("The entered reference is already in use."));
69 if (!check_num('quantity', 0))
71 display_error(_("The quantity entered is not a valid number or less then zero."));
72 set_focus('quantity');
76 if (!is_date($_POST['date_']))
78 display_error(_("The entered date is invalid."));
82 elseif (!is_date_in_fiscalyear($_POST['date_']))
84 display_error(_("The entered date is not in fiscal year."));
88 if (date_diff(sql2date($wo_details["released_date"]), $_POST['date_'], "d") > 0)
90 display_error(_("The production date cannot be before the release date of the work order."));
95 // if unassembling we need to check the qoh
96 if (($_POST['ProductionType'] == 0) && !sys_prefs::allow_negative_stock())
98 $wo_details = get_work_order($_POST['selected_id']);
100 $qoh = get_qoh_on_date($wo_details["stock_id"], $wo_details["loc_code"], $date_);
101 if (-$_POST['quantity'] + $qoh < 0)
103 display_error(_("The unassembling cannot be processed because there is insufficient stock."));
104 set_focus('quantity');
112 //--------------------------------------------------------------------------------------------------
114 if (isset($_POST['Process']) || (isset($_POST['ProcessAndClose']) && can_process() == true))
118 if (isset($_POST['ProcessAndClose']) && ($_POST['ProcessAndClose']!=""))
121 // if unassembling, negate quantity
122 if ($_POST['ProductionType'] == 0)
123 $_POST['quantity'] = -$_POST['quantity'];
125 $id = work_order_produce($_POST['selected_id'], $_POST['ref'], $_POST['quantity'],
126 $_POST['date_'], $_POST['memo_'], $close_wo);
128 meta_forward($_SERVER['PHP_SELF'], "AddedID=$id");
131 //-------------------------------------------------------------------------------------
133 display_wo_details($_POST['selected_id']);
135 //-------------------------------------------------------------------------------------
139 hidden('selected_id', $_POST['selected_id']);
140 //hidden('WOReqQuantity', $_POST['WOReqQuantity']);
142 if (!isset($_POST['quantity']) || $_POST['quantity'] == '')
144 $_POST['quantity'] = max($wo_details["units_reqd"] - $wo_details["units_issued"], 0);
149 ref_row(_("Reference:"), 'ref', '', references::get_next(29));
151 if (!isset($_POST['ProductionType']))
152 $_POST['ProductionType'] = 1;
154 yesno_list_row(_("Type:"), 'ProductionType', $_POST['ProductionType'],
155 _("Produce Finished Items"), _("Return Items to Work Order"));
157 small_qty_row(_("Quantity:"), 'quantity', null, null, null, get_qty_dec($wo_details["stock_id"]));
159 date_row(_("Date:"), 'date_');
161 textarea_row(_("Memo:"), 'memo_', null, 40, 3);
165 submit_center_first('Process', _("Process"), '', true);
166 submit_center_last('ProcessAndClose', _("Process And Close Order"), '', true);