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