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