b903d2c8f500fb85254c9cf460a04a8bb68abb25
[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"]);
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
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             qty_cell($myrow["units_req"]);
117                         qty_cell($myrow["units_req"] * $quantity);
118             qty_cell($myrow["units_issued"]);
119                         if ($show_qoh)
120                                 qty_cell($qoh);
121                         else
122                                 label_cell("");
123                         end_row();
124
125                 }
126
127                 end_table();
128
129                 if ($has_marked)
130                         display_note(_("Marked items have insufficient quantities in stock."), 0, 0, "class='red'");
131     }
132 }
133
134 //--------------------------------------------------------------------------------------
135
136 function display_wo_productions($woid)
137 {
138         global $path_to_root, $table_style;
139
140     $result = get_work_order_productions($woid);
141
142     if (db_num_rows($result) == 0)
143     {
144         display_note(_("There are no Productions for this Order."), 1, 1);
145     } 
146     else 
147     {
148         start_table($table_style);
149         $th = array(_("#"), _("Reference"), _("Date"), _("Quantity"));
150
151         table_header($th);
152
153         $k = 0; //row colour counter
154                 $total_qty = 0;
155
156         while ($myrow = db_fetch($result)) 
157         {
158
159                         alt_table_row_color($k);
160
161                         $total_qty += $myrow['quantity'];
162
163                 label_cell(get_trans_view_str(29, $myrow["id"]));
164                         label_cell($myrow['reference']);
165                         label_cell(sql2date($myrow["date_"]));
166                         qty_cell($myrow['quantity']);
167                         end_row();
168                 }//end of while
169
170                 label_row(_("Total"), number_format2($total_qty,user_qty_dec()), 
171                         "colspan=3", "nowrap align=right");
172
173                 end_table();
174     }
175 }
176
177 //--------------------------------------------------------------------------------------
178
179 function display_wo_issues($woid)
180 {
181         global $path_to_root, $table_style;
182
183     $result = get_work_order_issues($woid);
184
185     if (db_num_rows($result) == 0)
186     {
187         display_note(_("There are no Issues for this Order."), 0, 1);
188     } 
189     else 
190     {
191         start_table($table_style);
192         $th = array(_("#"), _("Reference"), _("Date"));
193
194         table_header($th);
195
196         $k = 0; //row colour counter
197
198         while ($myrow = db_fetch($result)) 
199         {
200
201                         alt_table_row_color($k);
202
203                 label_cell(get_trans_view_str(28, $myrow["issue_no"]));
204                         label_cell($myrow['reference']);
205                         label_cell(sql2date($myrow["issue_date"]));
206                         end_row();
207                 }
208
209                 end_table();
210     }
211 }
212
213 //--------------------------------------------------------------------------------------
214
215 function display_wo_payments($woid)
216 {
217         global $path_to_root, $table_style;
218
219     $result = get_bank_trans(null, null, payment_person_types::WorkOrder(), $woid);
220
221     if (db_num_rows($result) == 0)
222     {
223         echo _("There are no Payments for this Order.") . "<br>";
224     } 
225     else 
226     {
227         start_table($table_style);
228         $th = array(_("#"), _("Reference"), _("Date"), _("Amount"));
229
230         table_header($th);
231
232         $k = 0; //row colour counter
233
234         while ($myrow = db_fetch($result)) 
235         {
236
237                         alt_table_row_color($k);
238
239                 label_cell(get_trans_view_str(1, $myrow["trans_no"]));
240                         label_cell($myrow['ref']);
241                         label_cell(sql2date($myrow["trans_date"]));
242                         amount_cell(-($myrow['amount']));
243                         label_cell($myrow['bank_curr_code']);
244                         end_row();
245                 }
246
247                 end_table();
248     }
249 }
250
251 //--------------------------------------------------------------------------------------
252
253 function display_wo_details($woid, $suppress_view_link=false)
254 {
255         global $table_style;
256
257         $myrow = get_work_order($woid);
258
259     if (strlen($myrow[0]) == 0) 
260     {
261         display_note(_("The work order number sent is not valid."));
262         exit;
263     }
264
265         start_table("$table_style width=80%");
266
267         if ($myrow["released"] == true) 
268                 $th = array(_("#"), _("Reference"), _("Type"), _("Manufactured Item"),
269                         _("Into Location"), _("Date"), _("Required By"), _("Quantity Required"),
270                         _("Released Date"), _("Manufactured"));
271         else            
272                 $th = array(_("#"), _("Reference"), _("Type"), _("Manufactured Item"),
273                         _("Into Location"), _("Date"), _("Required By"), _("Quantity Required"));
274
275         table_header($th);
276         start_row();
277         if ($suppress_view_link)
278                 label_cell($myrow["id"]);
279         else
280                 label_cell(get_trans_view_str(systypes::work_order(), $myrow["id"]));
281         label_cell($myrow["wo_ref"]);
282         label_cell(wo_types::name($myrow["type"]));
283         view_stock_status_cell($myrow["stock_id"], $myrow["StockItemName"]);
284         label_cell($myrow["location_name"]);
285         label_cell(sql2date($myrow["date_"]));
286         label_cell(sql2date($myrow["required_by"]));
287
288         qty_cell($myrow["units_reqd"]);
289
290         if ($myrow["released"] == true) 
291         {
292                 label_cell(sql2date($myrow["released_date"]));
293                 qty_cell($myrow["units_issued"]);
294         }
295         end_row();
296
297         comments_display_row(systypes::work_order(), $woid);
298
299         end_table();
300
301     if ($myrow["closed"] == true) 
302     {
303         display_note(_("This work order is closed."));
304     }
305 }
306
307 //--------------------------------------------------------------------------------------
308
309 function display_wo_details_quick($woid, $suppress_view_link=false)
310 {
311         global $table_style;
312
313         $myrow = get_work_order($woid);
314
315     if (strlen($myrow[0]) == 0) 
316     {
317         display_note(_("The work order number sent is not valid."));
318         exit;
319     }
320
321         start_table("$table_style width=80%");
322
323         $th = array(_("#"), _("Reference"), _("Type"), _("Manufactured Item"),
324                 _("Into Location"), _("Date"), _("Quantity"));
325         table_header($th);      
326
327         start_row();
328         if ($suppress_view_link)
329                 label_cell($myrow["id"]);
330         else
331                 label_cell(get_trans_view_str(systypes::work_order(), $myrow["id"]));
332         label_cell($myrow["wo_ref"]);
333         label_cell(wo_types::name($myrow["type"]));
334         view_stock_status_cell($myrow["stock_id"], $myrow["StockItemName"]);
335         label_cell($myrow["location_name"]);
336         label_cell(sql2date($myrow["date_"]));
337
338         qty_cell($myrow["units_issued"]);
339
340         end_row();
341
342         comments_display_row(systypes::work_order(), $woid);
343
344         end_table();
345
346     if ($myrow["closed"] == true) 
347     {
348         display_note(_("This work order is closed."));
349     }
350 }
351
352 ?>