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