Fixed line edition layout
[fa-stable.git] / inventory / includes / item_adjustments_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_style2;
21
22         start_table("width=70% $table_style2"); // outer table
23         echo "<tr><td valign=top width=33%>";
24         echo "<table>"; // inner table
25
26         locations_list_row(_("Location:"), 'StockLocation', null);
27         ref_row(_("Reference:"), 'ref', '', references::get_next(systypes::inventory_adjustment()));
28
29         echo "</table>"; // inner table
30
31         echo "</td><td width=33%>";
32
33         echo "<table>"; // inner table
34
35     date_row(_("Date:"), 'AdjDate');
36
37         echo "</table>"; // inner table
38
39         echo "</td><td width=33%>";
40
41         echo "<table>"; // inner table
42     movement_types_list_row(_("Detail:"), 'type', null);
43
44     if (!isset($_POST['Increase']))
45         $_POST['Increase'] = 1;
46     yesno_list_row(_("Type:"), 'Increase', $_POST['Increase'],
47         _("Positive Adjustment"), _("Negative Adjustment"));
48
49         echo "</table>"; // inner table
50
51         echo "</td></tr>";
52         end_table(1); // outer table
53 }
54
55 //---------------------------------------------------------------------------------
56
57 function display_adjustment_items($title, &$order)
58 {
59         global $table_style, $path_to_root;
60
61         display_heading($title);
62     div_start('items_table');
63         start_table("$table_style width=80%");
64         $th = array(_("Item Code"), _("Item Description"), _("Quantity"),
65                 _("Unit"), _("Unit Cost"), _("Total"));
66         if ( count($order->line_items)) $th[] = '';
67
68         table_header($th);
69         $total = 0;
70         $k = 0;  //row colour counter
71
72         $id = find_submit('Edit');
73         foreach ($order->line_items as $line_no=>$stock_item)
74         {
75
76                 $total += ($stock_item->standard_cost * $stock_item->quantity);
77
78                 if ($id != $line_no)
79                 {
80                 alt_table_row_color($k);
81
82                         view_stock_status_cell($stock_item->stock_id);
83                         label_cell($stock_item->item_description);
84                 qty_cell($stock_item->quantity, false, get_qty_dec($stock_item->stock_id));
85                         label_cell($stock_item->units);
86                         amount_cell($stock_item->standard_cost);
87                         amount_cell($stock_item->standard_cost * $stock_item->quantity);
88
89                         edit_button_cell("Edit$line_no", _("Edit"),
90                                 _('Edit document line'));
91                         edit_button_cell("Delete$line_no", _("Delete"),
92                                 _('Remove line from document'));
93                         end_row();
94                 }
95                 else
96                 {
97                         adjustment_edit_item_controls($order, $line_no);
98                 }
99         }
100
101         if ($id == -1)
102                 adjustment_edit_item_controls($order);
103
104         label_row(_("Total"), number_format2($total,user_price_dec()), "colspan=5", "align=right");
105
106     end_table();
107         div_end();
108 }
109
110 //---------------------------------------------------------------------------------
111
112 function adjustment_edit_item_controls(&$order, $line_no=-1)
113 {
114         global $Ajax;
115         start_row();
116
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['units'] = $order->line_items[$id]->units;
125
126                 hidden('stock_id', $_POST['stock_id']);
127                 label_cell($_POST['stock_id']);
128                 label_cell($order->line_items[$id]->item_description, 'nowrap');
129             $Ajax->activate('items_table');
130         }
131         else
132         {
133         stock_costable_items_list_cells(null, 'stock_id', null, false, true);
134                 if(isset($_POST['_stock_id_update'])) {
135                             $Ajax->activate('units');
136                             $Ajax->activate('qty');
137                             $Ajax->activate('std_cost');
138                 }
139
140         $item_info = get_item_edit_info($_POST['stock_id']);
141
142                 $_POST['qty'] = qty_format(0, $_POST['stock_id'], $dec);
143                 $_POST['std_cost'] = price_format($item_info["standard_cost"]);
144                 $_POST['units'] = $item_info["units"];
145         }
146
147         qty_cells(null, 'qty', $_POST['qty'], null, null, $dec);
148         label_cell($_POST['units'], '', 'units');
149
150         amount_cells(null, 'std_cost', $_POST['std_cost']);
151         label_cell("&nbsp;");
152
153         if ($id != -1)
154         {
155                 edit_button_cell('UpdateItem', _("Update"),
156                                 _('Confirm changes'));
157                 edit_button_cell('CancelItemChanges', _("Cancel"),
158                                 _('Cancel changes'));
159                 hidden('LineNo', $line_no);
160                 set_focus('qty');
161         }
162         else
163         {
164                 submit_cells('AddItem', _("Add Item"), "colspan=2",
165                     _('Add new item to document'), true);
166         }
167
168         end_row();
169 }
170
171
172 //---------------------------------------------------------------------------------
173
174 function adjustment_options_controls()
175 {
176           echo "<br>";
177           start_table();
178
179           textarea_row(_("Memo"), 'memo_', null, 50, 3);
180
181           end_table(1);
182 }
183
184
185 //---------------------------------------------------------------------------------
186
187 ?>