Fixed many issues in output HTML code according to HTML 4.01 Transitional format.
[fa-stable.git] / manufacturing / includes / work_order_issue_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 include_once($path_to_root . "/includes/ui/items_cart.inc");
14
15 //--------------------------------------------------------------------------------
16
17 function add_to_issue(&$order, $new_item, $new_item_qty, $standard_cost)
18 {
19     if ($order->find_cart_item($new_item))
20          display_error(_("For Part :") . $new_item . " " . "This item is already on this issue.  You can change the quantity issued of the existing line if necessary.");
21         else
22          $order->add_to_cart (count($order->line_items), $new_item, $new_item_qty, $standard_cost);
23 }
24 //---------------------------------------------------------------------------------
25
26 function display_issue_items($title, &$order)
27 {
28         global $path_to_root;
29
30         display_heading($title);
31     div_start('items_table');
32         start_table(TABLESTYLE, "width='80%'");
33         $th = array(_("Item Code"), _("Item Description"), _("Quantity"),
34                 _("Unit"), _("Unit Cost"), '');
35         if ( count($order->line_items)) $th[] = '';
36
37         table_header($th);
38 //      $total = 0;
39         $k = 0;  //row colour counter
40
41         if (count($order->line_items))
42                 $low_stock = $order->check_qoh($_POST['Location'], $_POST['date_'], !$_POST['IssueType']);
43         $id = find_submit('Edit');
44         foreach ($order->line_items as $line_no=>$stock_item)
45         {
46
47 //              $total += ($stock_item->standard_cost * $stock_item->quantity);
48
49                 if ($id != $line_no)
50                 {
51                         if (in_array($stock_item->stock_id, $low_stock))
52                                 start_row("class='stockmankobg'");      // notice low stock status
53                         else 
54                                 alt_table_row_color($k);
55
56                         view_stock_status_cell($stock_item->stock_id);
57                         label_cell($stock_item->item_description);
58                 qty_cell($stock_item->quantity, false, get_qty_dec($stock_item->stock_id));
59                         label_cell($stock_item->units);
60                         amount_cell($stock_item->standard_cost);
61 //                      amount_cell($stock_item->standard_cost * $stock_item->quantity);
62
63                         edit_button_cell("Edit$line_no", _("Edit"),
64                                 _('Edit document line'));
65                         delete_button_cell("Delete$line_no", _("Delete"),
66                                 _('Remove line from document'));
67                         end_row();
68                 }
69                 else
70                 {
71                         issue_edit_item_controls($order, $line_no);
72                 }
73         }
74
75         if ($id == -1)
76                 issue_edit_item_controls($order);
77
78 //      label_row(_("Total"), number_format2($total,user_price_dec()), "colspan=5", "align=right");
79
80     end_table();
81         if (@$low_stock)
82                 display_note(_("Marked items have insufficient quantities in stock as on day of issue."), 0, 1, "class='stockmankofg'");
83         div_end();
84 }
85
86 //---------------------------------------------------------------------------------
87
88 function issue_edit_item_controls(&$order, $line_no=-1)
89 {
90         global $Ajax;
91         start_row();
92
93         $id = find_submit('Edit');
94         if ($line_no != -1 && $line_no == $id)
95         {
96                 $_POST['stock_id'] = $order->line_items[$id]->stock_id;
97                 $_POST['qty'] = qty_format($order->line_items[$id]->quantity, 
98                         $order->line_items[$id]->stock_id, $dec);
99                 //$_POST['std_cost'] = price_format($order->line_items[$id]->standard_cost);
100                 $std_cost = $order->line_items[$id]->standard_cost;
101                 $_POST['units'] = $order->line_items[$id]->units;
102
103                 hidden('stock_id', $_POST['stock_id']);
104                 label_cell($_POST['stock_id']);
105                 label_cell($order->line_items[$id]->item_description);
106             $Ajax->activate('items_table');
107         }
108         else
109         {
110                 $wo_details = get_work_order($_SESSION['issue_items']->order_id);
111
112                 stock_component_items_list_cells(null, 'stock_id', 
113                         $wo_details["stock_id"], null, false, true);
114                 if (list_updated('stock_id')) {
115                             $Ajax->activate('units');
116                             $Ajax->activate('qty');
117                             $Ajax->activate('std_cost');
118                 }
119
120         $item_info = get_item_edit_info($_POST['stock_id']);
121
122                 $dec = $item_info["decimals"];
123                 $_POST['qty'] = number_format2(0, $dec);
124                 //$_POST['std_cost'] = price_format($item_info["standard_cost"]);
125                 $std_cost = $item_info["standard_cost"];
126                 $_POST['units'] = $item_info["units"];
127         }
128
129         qty_cells(null, 'qty', $_POST['qty'], null, null, $dec);
130         label_cell($_POST['units'], '', 'units');
131
132         //amount_cells(null, 'std_cost', $_POST['std_cost']);
133         hidden('std_cost', $std_cost);
134         amount_cell($std_cost);
135
136         if ($id != -1)
137         {
138                 button_cell('UpdateItem', _("Update"),
139                                 _('Confirm changes'), ICON_UPDATE);
140                 button_cell('CancelItemChanges', _("Cancel"),
141                                 _('Cancel changes'), ICON_CANCEL);
142                 hidden('LineNo', $line_no);
143                 set_focus('qty');
144         }
145         else
146         {
147                 submit_cells('AddItem', _("Add Item"), "colspan=2",
148                     _('Add new item to document'), true);
149         }
150
151         end_row();
152 }
153
154
155 //---------------------------------------------------------------------------------
156
157 function issue_options_controls()
158 {
159         global $Refs;
160
161         echo "<br>";
162         start_table();
163     ref_row(_("Reference:"), 'ref', '', $Refs->get_next(28));
164  
165         if (!isset($_POST['IssueType']))
166                 $_POST['IssueType'] = 0;
167  
168         yesno_list_row(_("Type:"), 'IssueType', $_POST['IssueType'],
169                 _("Return Items to Location"), _("Issue Items to Work order"));
170  
171         locations_list_row(_("From Location:"), 'Location');
172         workcenter_list_row(_("To Work Centre:"), 'WorkCentre');
173  
174         date_row(_("Issue Date:"), 'date_');
175
176         textarea_row(_("Memo"), 'memo_', null, 50, 3);
177
178         end_table(1);
179 }
180 //---------------------------------------------------------------------------------
181
182 ?>