Fixed many issues in output HTML code according to HTML 4.01 Transitional format.
[fa-stable.git] / inventory / includes / item_adjustments_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_order(&$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 document. You can change the quantity on 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
27 function display_order_header(&$order)
28 {
29         global $Refs;
30
31         start_outer_table(TABLESTYLE2, "width='70%'"); // outer table
32         table_section(1);
33
34         locations_list_row(_("Location:"), 'StockLocation', null);
35         ref_row(_("Reference:"), 'ref', '', $Refs->get_next(ST_INVADJUST));
36
37         table_section(2, "33%");
38
39     date_row(_("Date:"), 'AdjDate', '', true);
40
41         table_section(3, "33%");
42
43     movement_types_list_row(_("Detail:"), 'type', null);
44
45     if (!isset($_POST['Increase']))
46         $_POST['Increase'] = 1;
47     yesno_list_row(_("Type:"), 'Increase', $_POST['Increase'],
48         _("Positive Adjustment"), _("Negative Adjustment"));
49
50         end_outer_table(1); // outer table
51 }
52
53 //---------------------------------------------------------------------------------
54
55 function display_adjustment_items($title, &$order)
56 {
57         global $path_to_root;
58
59         display_heading($title);
60     div_start('items_table');
61         start_table(TABLESTYLE, "width='80%'");
62         $th = array(_("Item Code"), _("Item Description"), _("Quantity"),
63                 _("Unit"), _("Unit Cost"), _("Total"), "");
64         if ( count($order->line_items)) $th[] = '';
65
66         table_header($th);
67         $total = 0;
68         $k = 0;  //row colour counter
69
70         $low_stock = $order->check_qoh($_POST['StockLocation'], $_POST['AdjDate'], !$_POST['Increase']);
71         $id = find_submit('Edit');
72         foreach ($order->line_items as $line_no=>$stock_item)
73         {
74
75                 $total += ($stock_item->standard_cost * $stock_item->quantity);
76
77                 if ($id != $line_no)
78                 {
79                         if (in_array($stock_item->stock_id, $low_stock))
80                                 start_row("class='stockmankobg'");      // notice low stock status
81                         else 
82                                 alt_table_row_color($k);
83
84                         view_stock_status_cell($stock_item->stock_id);
85                         label_cell($stock_item->item_description);
86                 qty_cell($stock_item->quantity, false, get_qty_dec($stock_item->stock_id));
87                         label_cell($stock_item->units);
88                         amount_decimal_cell($stock_item->standard_cost);
89                         amount_cell($stock_item->standard_cost * $stock_item->quantity);
90
91                         edit_button_cell("Edit$line_no", _("Edit"),
92                                 _('Edit document line'));
93                         delete_button_cell("Delete$line_no", _("Delete"),
94                                 _('Remove line from document'));
95                         end_row();
96                 }
97                 else
98                 {
99                         adjustment_edit_item_controls($order, $line_no);
100                 }
101         }
102
103         if ($id == -1)
104                 adjustment_edit_item_controls($order);
105
106         label_row(_("Total"), number_format2($total,user_price_dec()), "align=right colspan=5", "align=right", 2);
107
108     end_table();
109         if ($low_stock)
110                 display_note(_("Marked items have insufficient quantities in stock as on day of adjustment."), 0, 1, "class='stockmankofg'");
111         div_end();
112 }
113
114 //---------------------------------------------------------------------------------
115
116 function adjustment_edit_item_controls(&$order, $line_no=-1)
117 {
118         global $Ajax;
119         start_row();
120
121         $dec2 = 0;
122         $id = find_submit('Edit');
123         if ($line_no != -1 && $line_no == $id)
124         {
125                 $_POST['stock_id'] = $order->line_items[$id]->stock_id;
126                 $_POST['qty'] = qty_format($order->line_items[$id]->quantity, 
127                         $order->line_items[$id]->stock_id, $dec);
128                 //$_POST['std_cost'] = price_format($order->line_items[$id]->standard_cost);
129                 $_POST['std_cost'] = price_decimal_format($order->line_items[$id]->standard_cost, $dec2);
130                 $_POST['units'] = $order->line_items[$id]->units;
131
132                 hidden('stock_id', $_POST['stock_id']);
133                 label_cell($_POST['stock_id']);
134                 label_cell($order->line_items[$id]->item_description, 'nowrap');
135             $Ajax->activate('items_table');
136         }
137         else
138         {
139         stock_costable_items_list_cells(null, 'stock_id', null, false, true);
140                 if (list_updated('stock_id')) {
141                             $Ajax->activate('units');
142                             $Ajax->activate('qty');
143                             $Ajax->activate('std_cost');
144                 }
145
146         $item_info = get_item_edit_info($_POST['stock_id']);
147                 $dec = $item_info['decimals'];
148                 $_POST['qty'] = number_format2(0, $dec);
149                 //$_POST['std_cost'] = price_format($item_info["standard_cost"]);
150                 $_POST['std_cost'] = price_decimal_format($item_info["standard_cost"], $dec2);
151                 $_POST['units'] = $item_info["units"];
152         }
153
154         qty_cells(null, 'qty', $_POST['qty'], null, null, $dec);
155         label_cell($_POST['units'], '', 'units');
156
157         //amount_cells(null, 'std_cost', $_POST['std_cost']);
158         amount_cells(null, 'std_cost', null, null, null, $dec2);
159         label_cell("&nbsp;");
160
161         if ($id != -1)
162         {
163                 button_cell('UpdateItem', _("Update"),
164                                 _('Confirm changes'), ICON_UPDATE);
165                 button_cell('CancelItemChanges', _("Cancel"),
166                                 _('Cancel changes'), ICON_CANCEL);
167                 hidden('LineNo', $line_no);
168                 set_focus('qty');
169         }
170         else
171         {
172                 submit_cells('AddItem', _("Add Item"), "colspan=2",
173                     _('Add new item to document'), true);
174         }
175
176         end_row();
177 }
178
179
180 //---------------------------------------------------------------------------------
181
182 function adjustment_options_controls()
183 {
184           echo "<br>";
185           start_table();
186
187           textarea_row(_("Memo"), 'memo_', null, 50, 3);
188
189           end_table(1);
190 }
191
192
193 //---------------------------------------------------------------------------------
194
195 ?>