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