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