inventory location transfer from sales kit did not work. Fixed.
[fa-stable.git] / inventory / includes / stock_transfers_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         $kit = get_item_kit($new_item);
20         foreach($kit as $item) {
21                 if ($order->find_cart_item($item['stock_id']))
22                         display_error(_("For Part :") . $item['stock_id'] . " " . "This item is already on this document. You can change the quantity on the existing line if necessary.");
23                 else
24                         $order->add_to_cart (count($order->line_items), $item['stock_id'], $new_item_qty * $item['quantity'], $standard_cost);
25         }
26 }
27
28 //--------------------------------------------------------------------------------
29
30 function display_order_header(&$order)
31 {
32         global $Refs;
33
34         start_outer_table(TABLESTYLE, "width='70%'");
35
36         table_section(1);
37         
38         locations_list_row(_("From Location:"), 'FromStockLocation', null, false, false, $order->fixed_asset);
39         locations_list_row(_("To Location:"), 'ToStockLocation', null,false, false, $order->fixed_asset);
40
41         table_section(2, "50%");
42
43     date_row(_("Date:"), 'AdjDate', '', true);
44
45         ref_row(_("Reference:"), 'ref', '', $Refs->get_next(ST_LOCTRANSFER, null, array('date'=>get_post('AdjDate'), 'location'=> get_post('FromStockLocation'))), false, ST_LOCTRANSFER);
46
47         end_outer_table(1); // outer table
48 }
49
50 //---------------------------------------------------------------------------------
51
52 function display_transfer_items($title, &$order)
53 {
54         global $path_to_root;
55
56         display_heading($title);
57     div_start('items_table');
58         start_table(TABLESTYLE, "width='80%'");
59         $th = array(_("Item Code"), _("Item Description"), _("Quantity"), _("Unit"), '');
60         if (!$order->fixed_asset && count($order->line_items)) $th[] = '';
61         table_header($th);
62         $k = 0;  //row colour counter
63
64         $low_stock = $order->check_qoh($_POST['FromStockLocation'], $_POST['AdjDate'], true);
65         $id = find_submit('Edit');
66         foreach ($order->line_items as $line_no=>$stock_item)
67         {
68
69                 if ($id != $line_no)
70                 {
71                         if (in_array($stock_item->stock_id, $low_stock))
72                                 start_row("class='stockmankobg'");      // notice low stock status
73                         else 
74                                 alt_table_row_color($k);
75
76                         if ($order->fixed_asset)
77                                 label_cell($stock_item->stock_id);
78                         else
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
84                 if (!$order->fixed_asset)
85                                 edit_button_cell("Edit$line_no", _("Edit"),     _('Edit document line'));
86                         delete_button_cell("Delete$line_no", _("Delete"), _('Remove line from document'));
87                 end_row();
88                 }
89                 else
90                         transfer_edit_item_controls($order, $line_no);
91         }
92
93         if ($id == -1)
94                 transfer_edit_item_controls($order);
95
96     end_table();
97         if ($low_stock)
98                 display_note(_("Marked items have insufficient quantities in stock as on day of transfer."), 0, 1, "class='stockmankofg'");
99         div_end();
100 }
101
102 //---------------------------------------------------------------------------------
103
104 function transfer_edit_item_controls(&$order, $line_no=-1)
105 {
106         global $Ajax;
107         start_row();
108
109         $id = find_submit('Edit');
110         if ($line_no != -1 && $line_no == $id)
111         {
112                 $_POST['stock_id'] = $order->line_items[$id]->stock_id;
113                 $_POST['qty'] = qty_format($order->line_items[$id]->quantity, $order->line_items[$id]->stock_id, $dec);
114                 $_POST['units'] = $order->line_items[$id]->units;
115
116                 hidden('stock_id', $_POST['stock_id']);
117                 label_cell($_POST['stock_id']);
118                 label_cell($order->line_items[$id]->item_description);
119             $Ajax->activate('items_table');
120         }
121         else
122         {
123                 if ($order->fixed_asset)
124                         stock_disposable_fa_list_cells(null, 'stock_id', null, false, true, $order->line_items);
125                 else
126                         sales_items_list_cells(null,'stock_id', null, false, true, true);
127
128                 if (list_updated('stock_id')) {
129                         $Ajax->activate('units');
130                         $Ajax->activate('qty');
131                 }
132
133         $item_info = get_item_edit_info($_POST['stock_id']);
134
135                 $dec = $item_info['decimals'];
136                 $_POST['qty'] = number_format2(0, $dec);
137                 $_POST['units'] = $item_info["units"];
138         }
139
140         if ($order->fixed_asset) {
141                 hidden('qty', 1);
142                 qty_cell(1, false, 0);
143         } else
144                 small_qty_cells(null, 'qty', $_POST['qty'], null, null, $dec);
145
146         label_cell($_POST['units'], '', 'units');
147
148         if ($id != -1)
149         {
150                 button_cell('UpdateItem', _("Update"), _('Confirm changes'), ICON_UPDATE);
151                 button_cell('CancelItemChanges', _("Cancel"), _('Cancel changes'), ICON_CANCEL);
152                 hidden('LineNo', $line_no);
153                 set_focus('qty');
154         }
155         else
156                 submit_cells('AddItem', _("Add Item"), "colspan=2", _('Add new item to document'), true);
157
158         end_row();
159 }
160
161
162 //---------------------------------------------------------------------------------
163
164 function transfer_options_controls()
165 {
166     echo "<br>";
167     start_table();
168
169         textarea_row(_("Memo"), 'memo_', null, 50, 3);
170
171         end_table(1);
172 }
173
174
175 //---------------------------------------------------------------------------------
176