Merging version 2.1 RC to main trunk.
[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;
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                                 !sys_prefs::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;
228
229     $result = get_bank_trans(null, null, payment_person_types::WorkOrder(), $woid);
230
231     if (db_num_rows($result) == 0)
232     {
233         display_note(_("There are no Payments for this Order."), 0, 1);
234     }
235     else
236     {
237         start_table($table_style);
238         $th = array(_("#"), _("Reference"), _("Date"), _("Amount"));
239
240         table_header($th);
241
242         $k = 0; //row colour counter
243
244         while ($myrow = db_fetch($result))
245         {
246
247                         alt_table_row_color($k);
248
249                 label_cell(get_trans_view_str(1, $myrow["trans_no"]));
250                         label_cell($myrow['ref']);
251                         label_cell(sql2date($myrow["trans_date"]));
252                         amount_cell(-($myrow['amount']));
253                         label_cell($myrow['bank_curr_code']);
254                         end_row();
255                 }
256
257                 end_table();
258     }
259 }
260
261 //--------------------------------------------------------------------------------------
262
263 function display_wo_details($woid, $suppress_view_link=false)
264 {
265         global $table_style;
266
267         $myrow = get_work_order($woid);
268
269     if (strlen($myrow[0]) == 0)
270     {
271         display_note(_("The work order number sent is not valid."));
272         exit;
273     }
274
275         start_table("$table_style width=80%");
276
277         if ($myrow["released"] == true)
278                 $th = array(_("#"), _("Reference"), _("Type"), _("Manufactured Item"),
279                         _("Into Location"), _("Date"), _("Required By"), _("Quantity Required"),
280                         _("Released Date"), _("Manufactured"));
281         else
282                 $th = array(_("#"), _("Reference"), _("Type"), _("Manufactured Item"),
283                         _("Into Location"), _("Date"), _("Required By"), _("Quantity Required"));
284
285         table_header($th);
286         start_row();
287         if ($suppress_view_link)
288                 label_cell($myrow["id"]);
289         else
290                 label_cell(get_trans_view_str(systypes::work_order(), $myrow["id"]));
291         label_cell($myrow["wo_ref"]);
292         label_cell(wo_types::name($myrow["type"]));
293         view_stock_status_cell($myrow["stock_id"], $myrow["StockItemName"]);
294         label_cell($myrow["location_name"]);
295         label_cell(sql2date($myrow["date_"]));
296         label_cell(sql2date($myrow["required_by"]));
297         $dec = get_qty_dec($myrow["stock_id"]);
298         qty_cell($myrow["units_reqd"], false, $dec);
299
300         if ($myrow["released"] == true)
301         {
302                 label_cell(sql2date($myrow["released_date"]));
303                 qty_cell($myrow["units_issued"], false, $dec);
304         }
305         end_row();
306
307         comments_display_row(systypes::work_order(), $woid);
308
309         end_table();
310
311     if ($myrow["closed"] == true)
312     {
313         display_note(_("This work order is closed."));
314     }
315 }
316
317 //--------------------------------------------------------------------------------------
318
319 function display_wo_details_quick($woid, $suppress_view_link=false)
320 {
321         global $table_style;
322
323         $myrow = get_work_order($woid);
324
325     if (strlen($myrow[0]) == 0)
326     {
327         display_note(_("The work order number sent is not valid."));
328         exit;
329     }
330
331         start_table("$table_style width=80%");
332
333         $th = array(_("#"), _("Reference"), _("Type"), _("Manufactured Item"),
334                 _("Into Location"), _("Date"), _("Quantity"));
335         table_header($th);
336
337         start_row();
338         if ($suppress_view_link)
339                 label_cell($myrow["id"]);
340         else
341                 label_cell(get_trans_view_str(systypes::work_order(), $myrow["id"]));
342         label_cell($myrow["wo_ref"]);
343         label_cell(wo_types::name($myrow["type"]));
344         view_stock_status_cell($myrow["stock_id"], $myrow["StockItemName"]);
345         label_cell($myrow["location_name"]);
346         label_cell(sql2date($myrow["date_"]));
347
348         qty_cell($myrow["units_issued"], false, get_qty_dec($myrow["stock_id"]));
349
350         end_row();
351
352         comments_display_row(systypes::work_order(), $woid);
353
354         end_table();
355
356     if ($myrow["closed"] == true)
357     {
358         display_note(_("This work order is closed."));
359     }
360 }
361
362 ?>