Sql usage optimization.
[fa-stable.git] / inventory / includes / stock_transfers_ui.inc
1 <?php
2
3 include_once($path_to_root . "/includes/ui.inc");
4 include_once($path_to_root . "/includes/ui/items_cart.inc");
5
6 //--------------------------------------------------------------------------------
7
8 function add_to_order(&$order, $new_item, $new_item_qty, $standard_cost)
9 {
10     if ($order->find_cart_item($new_item))
11          display_error(_("For Part :") . $new_item . " " . "This item is already on this order.  You can change the quantity ordered of the existing line if necessary.");
12         else
13          $order->add_to_cart (count($order->line_items), $new_item, $new_item_qty, $standard_cost);
14 }
15
16 //--------------------------------------------------------------------------------
17
18 function display_order_header(&$order)
19 {
20         global $table_style;
21
22         start_table("width=70% $table_style");
23         echo "<tr><td width=33% valign=top>"; // outer table
24         echo "<table>";
25
26         locations_list_row(_("From Location:"), 'FromStockLocation', null);
27         locations_list_row(_("To Location:"), 'ToStockLocation', null);
28
29         echo "</table>";
30
31         echo "</td><td width=33%>"; // outer table
32
33         echo "<table>";
34
35         ref_row(_("Reference:"), 'ref', '', references::get_next(systypes::location_transfer()));
36
37     date_row(_("Date:"), 'AdjDate');
38
39         echo "</table>";
40
41         echo "</td><td width=33%>"; // outer table
42
43         echo "<table>";
44     movement_types_list_row(_("Transfer Type:"), 'type', null);
45         echo "</table>";
46
47         echo "</td></tr>";
48         end_table(1); // outer table
49 }
50
51 //---------------------------------------------------------------------------------
52
53 function display_transfer_items($title, &$order)
54 {
55         global $table_style, $path_to_root;
56
57         display_heading($title);
58     div_start('items_table');
59         start_table("$table_style width=80%");
60         $th = array(_("Item Code"), _("Item Description"), _("Quantity"), _("Unit"), '');
61         table_header($th);
62         $subtotal = 0;
63         $k = 0;  //row colour counter
64
65         $id = find_submit('Edit');
66         foreach ($order->line_items as $line_no=>$stock_item)
67         {
68
69                 if ($id != $line_no)
70                 {
71                 alt_table_row_color($k);
72
73                         view_stock_status_cell($stock_item->stock_id);
74                 label_cell($stock_item->item_description);
75                 qty_cell($stock_item->quantity, false, get_qty_dec($stock_item->stock_id));
76                 label_cell($stock_item->units);
77
78                         edit_button_cell("Edit$line_no", _("Edit"),
79                                 _('Edit document line'));
80                         edit_button_cell("Delete$line_no", _("Delete"),
81                                 _('Remove line from document'));
82                 end_row();
83                 }
84                 else
85                 {
86                         transfer_edit_item_controls($order, $line_no);
87                 }
88         }
89
90         if ($id == -1)
91                 transfer_edit_item_controls($order);
92
93     end_table();
94         div_end();
95 }
96
97 //---------------------------------------------------------------------------------
98
99 function transfer_edit_item_controls(&$order, $line_no=-1)
100 {
101         global $Ajax;
102         start_row();
103
104         $id = find_submit('Edit');
105         if ($line_no != -1 && $line_no == $id)
106         {
107                 $_POST['stock_id'] = $order->line_items[$id]->stock_id;
108                 $_POST['qty'] = qty_format($order->line_items[$id]->quantity, $order->line_items[$id]->stock_id, $dec);
109                 $_POST['units'] = $order->line_items[$id]->units;
110
111                 hidden('stock_id', $_POST['stock_id']);
112                 label_cell($_POST['stock_id']);
113                 label_cell($order->line_items[$id]->item_description);
114             $Ajax->activate('items_table');
115         }
116         else
117         {
118         stock_costable_items_list_cells(null, 'stock_id', null, false, true);
119                 if (list_updated('stock_id')) {
120                             $Ajax->activate('units');
121                             $Ajax->activate('qty');
122                 }
123
124         $item_info = get_item_edit_info($_POST['stock_id']);
125
126                 $dec = $item_info['decimals'];
127                 $_POST['qty'] = number_format2(0, $dec);
128                 $_POST['units'] = $item_info["units"];
129         }
130
131         small_qty_cells(null, 'qty', $_POST['qty'], null, null, $dec);
132         label_cell($_POST['units'], '', 'units');
133
134         if ($id != -1)
135         {
136                 edit_button_cell('UpdateItem', _("Update"),
137                                 _('Confirm changes'));
138                 edit_button_cell('CancelItemChanges', _("Cancel"),
139                                 _('Cancel changes'));
140                 hidden('LineNo', $line_no);
141                 set_focus('qty');
142         }
143         else
144         {
145                 submit_cells('AddItem', _("Add Item"), "colspan=2",
146                     _('Add new item to document'), true);
147         }
148
149         end_row();
150 }
151
152
153 //---------------------------------------------------------------------------------
154
155 function transfer_options_controls()
156 {
157           echo "<br>";
158           start_table();
159
160           textarea_row(_("Memo"), 'memo_', null, 50, 3);
161
162           end_table(1);
163 }
164
165
166 //---------------------------------------------------------------------------------
167
168 ?>