[0004212] Work Order Entry: fixed error when voided WO refence is reused.
[fa-stable.git] / manufacturing / includes / manufacturing_ui.inc
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 include_once($path_to_root . "/includes/ui.inc");
13
14 //--------------------------------------------------------------------------------------
15
16 function display_bom($item_check)
17 {
18     $result = get_bom($item_check);
19
20     if (db_num_rows($result) == 0)
21     {
22         display_note(_("The bill of material for this item is empty."), 0, 1);
23     }
24     else
25     {
26
27         start_table(TABLESTYLE);
28         $th = array(_("Component"), _("Description"), _("Work Centre"),
29                 _("From Location"), _("Quantity"), _("Unit Cost"), _("Cost"));
30
31         table_header($th);
32
33         $j = 1;
34         $k = 0; //row colour counter
35
36         $total_cost = 0;
37
38         while ($myrow = db_fetch($result))
39         {
40
41                         alt_table_row_color($k);
42
43                         label_cell($myrow["component"]);
44                         label_cell($myrow["description"]);
45                         label_cell($myrow["WorkCentreDescription"]);
46                         label_cell($myrow["location_name"]);
47                         qty_cell($myrow["quantity"], false, get_qty_dec($myrow["component"]));
48                         amount_cell($myrow["ProductCost"]);
49                         amount_cell($myrow["ComponentCost"]);
50                         end_row();
51                 $total_cost += $myrow["ComponentCost"];
52
53                 $j++;
54                 if ($j == 12)
55                 {
56                         $j = 1;
57                         table_header($th);
58                 }
59                 }
60
61                 $item = get_item($item_check);
62                 if ($item['labour_cost'] != 0)
63                 {
64                         $total_cost += $item['labour_cost'];
65                         alt_table_row_color($k);
66                 label_cells(_("Standard Labour Cost"), number_format2($item['labour_cost'],user_price_dec()),
67                 "colspan=6 align=left", "class=odd_row nowrap align=right");
68             end_row();
69                 }
70                 if ($item['overhead_cost'] != 0)
71                 {
72                         $total_cost += $item['overhead_cost'];
73                         alt_table_row_color($k);
74                 label_cells(_("Standard Overhead Cost"), number_format2($item['overhead_cost'],user_price_dec()),
75                 "colspan=6 align=left", "nowrap align=right");
76             end_row();
77                 }
78         label_row("<b>" . _("Total Cost") . "</b>", "<b>" . number_format2($total_cost,user_price_dec()) ."</b>",
79                 "colspan=6 align=right", "nowrap align=right");
80                 end_table();
81     }
82 }
83
84 //--------------------------------------------------------------------------------------
85
86 function display_wo_requirements($woid, $quantity, $show_qoh=false, $date=null)
87 {
88         global $SysPrefs;
89
90     $result = get_wo_requirements($woid);
91
92     if (db_num_rows($result) == 0)
93     {
94         display_note(_("There are no Requirements for this Order."), 1, 0);
95     }
96     else
97     {
98
99         start_table(TABLESTYLE, "width='80%'");
100         $th = array(_("Component"), _("From Location"), _("Work Centre"),
101                 _("Unit Quantity"), _("Total Quantity"), _("Units Issued"), _("On Hand"));
102
103         table_header($th);
104
105         $k = 0; //row colour counter
106                 $has_marked = false;
107
108                 if ($date == null)
109                         $date = Today();
110
111         while ($myrow = db_fetch($result))
112         {
113
114                         $qoh = 0;
115                         $show_qoh = true;
116                         // if it's a non-stock item (eg. service) don't show qoh
117                         if (!has_stock_holding($myrow["mb_flag"]))
118                                 $show_qoh = false;
119
120                         if ($show_qoh)
121                                 $qoh = get_qoh_on_date($myrow["stock_id"], $myrow["loc_code"], $date);
122
123                         if ($show_qoh && ($myrow["units_req"] * $quantity > $qoh) &&
124                                 !$SysPrefs->allow_negative_stock())
125                         {
126                                 // oops, we don't have enough of one of the component items
127                                 start_row("class='stockmankobg'");
128                                 $has_marked = true;
129                         }
130                         else
131                                 alt_table_row_color($k);
132
133                 if (user_show_codes())
134                         label_cell($myrow["stock_id"]. " - " . $myrow["description"]);
135                 else
136                         label_cell($myrow["description"]);
137
138                         label_cell($myrow["location_name"]);
139                         label_cell($myrow["WorkCentreDescription"]);
140                         $dec = get_qty_dec($myrow["stock_id"]);
141             qty_cell($myrow["units_req"], false, $dec);
142                         qty_cell($myrow["units_req"] * $quantity, false, $dec);
143             qty_cell($myrow["units_issued"], false, $dec);
144                         if ($show_qoh)
145                                 qty_cell($qoh, false, $dec);
146                         else
147                                 label_cell("");
148                         end_row();
149
150                 }
151
152                 end_table();
153
154                 if ($has_marked)
155                         display_note(_("Marked items have insufficient quantities in stock."), 0, 0, "class='red'");
156     }
157 }
158
159 //--------------------------------------------------------------------------------------
160
161 function display_wo_productions($woid)
162 {
163         global $path_to_root;
164
165     $result = get_work_order_productions($woid);
166
167     if (db_num_rows($result) == 0)
168     {
169         display_note(_("There are no Productions for this Order."), 1, 1);
170     }
171     else
172     {
173         start_table(TABLESTYLE);
174         $th = array(_("#"), _("Reference"), _("Date"), _("Quantity"));
175
176         table_header($th);
177
178         $k = 0; //row colour counter
179                 $total_qty = 0;
180
181         while ($myrow = db_fetch($result))
182         {
183
184                         alt_table_row_color($k);
185
186                         $total_qty += $myrow['quantity'];
187
188                 label_cell(get_trans_view_str(ST_MANURECEIVE, $myrow["id"]));
189                         label_cell($myrow['reference']);
190                         label_cell(sql2date($myrow["date_"]));
191                         qty_cell($myrow['quantity'], false, get_qty_dec($myrow['reference']));
192                         end_row();
193                 }//end of while
194
195                 label_row(_("Total"), number_format2($total_qty,user_qty_dec()),
196                         "colspan=3", "nowrap align=right");
197
198                 end_table();
199     }
200 }
201
202 //--------------------------------------------------------------------------------------
203
204 function display_wo_issues($woid)
205 {
206         global $path_to_root;
207
208     $result = get_work_order_issues($woid);
209
210     if (db_num_rows($result) == 0)
211     {
212         display_note(_("There are no Issues for this Order."), 0, 1);
213     }
214     else
215     {
216         start_table(TABLESTYLE);
217         $th = array(_("#"), _("Reference"), _("Date"));
218
219         table_header($th);
220
221         $k = 0; //row colour counter
222
223         while ($myrow = db_fetch($result))
224         {
225
226                         alt_table_row_color($k);
227
228                 label_cell(get_trans_view_str(ST_MANUISSUE, $myrow["issue_no"]));
229                         label_cell($myrow['reference']);
230                         label_cell(sql2date($myrow["issue_date"]));
231                         end_row();
232                 }
233
234                 end_table();
235     }
236 }
237
238 //--------------------------------------------------------------------------------------
239
240 function display_wo_payments($woid)
241 {
242         global $path_to_root, $wo_cost_types;
243
244     $result = get_wo_costing($woid);
245
246     if (db_num_rows($result) == 0)
247     {
248         display_note(_("There are no additional costs for this Order."), 0, 1);
249     }
250     else
251     {
252         start_table(TABLESTYLE);
253         $th = array(_("#"), _("Type"), _("Date"), _("Amount"));
254
255         table_header($th);
256
257         $k = 0;
258         while ($myrow = db_fetch($result))
259         {
260                         alt_table_row_color($k);
261
262                 label_cell(get_gl_view_str( $myrow["trans_type"], $myrow["trans_no"], $myrow["trans_no"]));
263                 label_cell($wo_cost_types[$myrow['cost_type']]);
264                 $date = sql2date($myrow["tran_date"]);
265                 label_cell($date);
266                         amount_cell($myrow['amount']);
267                         end_row();
268                 }
269
270                 end_table();
271     }
272 }
273
274 //--------------------------------------------------------------------------------------
275
276 function display_wo_details($woid, $suppress_view_link=false)
277 {
278         global $wo_types_array;
279
280         $myrow = get_work_order($woid);
281
282     if (strlen($myrow[0]) == 0)
283     {
284         display_note(_("The work order number sent is not valid."));
285         exit;
286     }
287
288         start_table(TABLESTYLE, "width='80%'");
289
290         if ($myrow["released"] == true)
291                 $th = array(_("#"), _("Reference"), _("Type"), _("Manufactured Item"),
292                         _("Into Location"), _("Date"), _("Required By"), _("Quantity Required"),
293                         _("Released Date"), _("Manufactured"));
294         else
295                 $th = array(_("#"), _("Reference"), _("Type"), _("Manufactured Item"),
296                         _("Into Location"), _("Date"), _("Required By"), _("Quantity Required"));
297
298         table_header($th);
299         start_row();
300         if ($suppress_view_link)
301                 label_cell($myrow["id"]);
302         else
303                 label_cell(get_trans_view_str(ST_WORKORDER, $myrow["id"]));
304         label_cell($myrow["wo_ref"]);
305         label_cell($wo_types_array[$myrow["type"]]);
306         view_stock_status_cell($myrow["stock_id"], $myrow["StockItemName"]);
307         label_cell($myrow["location_name"]);
308         label_cell(sql2date($myrow["date_"]));
309         label_cell(sql2date($myrow["required_by"]));
310         $dec = get_qty_dec($myrow["stock_id"]);
311         qty_cell($myrow["units_reqd"], false, $dec);
312
313         if ($myrow["released"] == true)
314         {
315                 label_cell(sql2date($myrow["released_date"]));
316                 qty_cell($myrow["units_issued"], false, $dec);
317         }
318         end_row();
319
320         comments_display_row(ST_WORKORDER, $woid);
321
322         end_table();
323
324     if ($myrow["closed"] == true)
325     {
326         display_note(_("This work order is closed."));
327     }
328 }
329
330 //--------------------------------------------------------------------------------------
331
332 function display_wo_details_quick($woid, $suppress_view_link=false)
333 {
334         global $wo_types_array;
335
336         $myrow = get_work_order($woid);
337
338     if (strlen($myrow[0]) == 0)
339     {
340         display_note(_("The work order number sent is not valid."));
341         exit;
342     }
343
344         start_table(TABLESTYLE, "width='80%'");
345
346         $th = array(_("#"), _("Reference"), _("Type"), _("Manufactured Item"),
347                 _("Into Location"), _("Date"), _("Quantity"));
348         table_header($th);
349
350         start_row();
351         if ($suppress_view_link)
352                 label_cell($myrow["id"]);
353         else
354                 label_cell(get_trans_view_str(ST_WORKORDER, $myrow["id"]));
355         label_cell($myrow["wo_ref"]);
356         label_cell($wo_types_array[$myrow["type"]]);
357         view_stock_status_cell($myrow["stock_id"], $myrow["StockItemName"]);
358         label_cell($myrow["location_name"]);
359         label_cell(sql2date($myrow["date_"]));
360
361         qty_cell($myrow["units_issued"], false, get_qty_dec($myrow["stock_id"]));
362
363         end_row();
364
365         comments_display_row(ST_WORKORDER, $woid);
366
367         end_table();
368
369     if ($myrow["closed"] == true)
370     {
371         display_note(_("This work order is closed."));
372     }
373 }
374