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