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