Focus set to invalid field after submit check fail
[fa-stable.git] / manufacturing / work_order_add_finished.php
1 <?php
2
3 $page_security = 10;
4 $path_to_root="..";
5 include_once($path_to_root . "/includes/session.inc");
6
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");
10
11 include_once($path_to_root . "/manufacturing/includes/manufacturing_db.inc");
12 include_once($path_to_root . "/manufacturing/includes/manufacturing_ui.inc");
13
14 $js = "";
15 if ($use_date_picker)
16         $js .= get_js_date_picker();
17 page(_("Produce or Unassemble Finished Items From Work Order"), false, false, "", $js);
18
19 if (isset($_GET['trans_no']) && $_GET['trans_no'] != "")
20 {
21         $_POST['selected_id'] = $_GET['trans_no'];
22 }
23
24 //--------------------------------------------------------------------------------------------------
25
26 if (isset($_GET['AddedID'])) 
27 {
28
29         display_note(_("The manufacturing process has been entered."));
30
31         hyperlink_no_params("search_work_orders.php", _("Select another Work Order to Process"));
32
33         end_page();
34         exit;
35 }
36
37 //--------------------------------------------------------------------------------------------------
38
39 $wo_details = get_work_order($_POST['selected_id']);
40
41 if (strlen($wo_details[0]) == 0) 
42 {
43         display_error(_("The order number sent is not valid."));
44         exit;
45 }
46
47 //--------------------------------------------------------------------------------------------------
48
49 function can_process()
50 {
51         global $wo_details;
52
53         if (!references::is_valid($_POST['ref'])) 
54         {
55                 display_error(_("You must enter a reference."));
56                 set_focus('ref');
57                 return false;
58         }
59
60         if (!is_new_reference($_POST['ref'], 29)) 
61         {
62                 display_error(_("The entered reference is already in use."));
63                 set_focus('ref');
64                 return false;
65         }
66
67         if (!check_num('quantity', 0))
68         {
69                 display_error(_("The quantity entered is not a valid number or less then zero."));
70                 set_focus('quantity');
71                 return false;
72         }
73
74         if (!is_date($_POST['date_']))
75         {
76                 display_error(_("The entered date is invalid."));
77                 set_focus('date_');
78                 return false;
79         } 
80         elseif (!is_date_in_fiscalyear($_POST['date_'])) 
81         {
82                 display_error(_("The entered date is not in fiscal year."));
83                 set_focus('date_');
84                 return false;
85         }
86         if (date_diff(sql2date($wo_details["released_date"]), $_POST['date_'], "d") > 0) 
87         {
88                 display_error(_("The production date cannot be before the release date of the work order."));
89                 set_focus('date_');
90                 return false;
91         }
92
93         // if unassembling we need to check the qoh
94         if (($_POST['ProductionType'] == 0) && !sys_prefs::allow_negative_stock())
95         {
96                 $wo_details = get_work_order($_POST['selected_id']);
97
98                 $qoh = get_qoh_on_date($wo_details["stock_id"], $wo_details["loc_code"], $date_);
99                 if (-$_POST['quantity'] + $qoh < 0) 
100                 {
101                         display_error(_("The unassembling cannot be processed because there is insufficient stock."));
102                         set_focus('quantity');
103                         return false;
104                 }
105         }
106
107         return true;
108 }
109
110 //--------------------------------------------------------------------------------------------------
111
112 if (isset($_POST['Process']) || (isset($_POST['ProcessAndClose']) && can_process() == true)) 
113 {
114
115         $close_wo = 0;
116         if (isset($_POST['ProcessAndClose']) && ($_POST['ProcessAndClose']!=""))
117                 $close_wo = 1;
118
119         // if unassembling, negate quantity
120         if ($_POST['ProductionType'] == 0)
121                 $_POST['quantity'] = -$_POST['quantity'];
122
123          $id = work_order_produce($_POST['selected_id'], $_POST['ref'], $_POST['quantity'],
124                         $_POST['date_'], $_POST['memo_'], $close_wo);
125
126         meta_forward($_SERVER['PHP_SELF'], "AddedID=$id");
127 }
128
129 //-------------------------------------------------------------------------------------
130
131 display_wo_details($_POST['selected_id']);
132
133 //-------------------------------------------------------------------------------------
134
135 start_form();
136
137 hidden('selected_id', $_POST['selected_id']);
138 //hidden('WOReqQuantity', $_POST['WOReqQuantity']);
139
140 if (!isset($_POST['quantity']) || $_POST['quantity'] == '') 
141 {
142         $_POST['quantity'] = max($wo_details["units_reqd"] - $wo_details["units_issued"], 0);
143 }
144
145 start_table();
146
147 ref_row(_("Reference:"), 'ref', references::get_next(29));
148
149 if (!isset($_POST['ProductionType']))
150         $_POST['ProductionType'] = 1;
151
152 yesno_list_row(_("Type:"), 'ProductionType', $_POST['ProductionType'],
153         _("Produce Finished Items"), _("Return Items to Work Order"));
154
155 text_row(_("Quantity:"), 'quantity', $_POST['quantity'], 13, 15);
156
157 date_row(_("Date:"), 'date_');
158
159 textarea_row(_("Memo:"), 'memo_', null, 40, 3);
160
161 end_table(1);
162
163 submit_center_first('Process', _("Process"));
164 submit_center_last('ProcessAndClose', _("Process And Close Order"));
165
166 end_form();
167
168 end_page();
169
170 ?>