Changed API for input/lists functions, added empty hints when needed
[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     $allready_on_order = 0;
11
12         foreach ($order->line_items as $order_item) 
13         {
14         if (strcasecmp($order_item->stock_id, $new_item) == 0) 
15         {
16             $allready_on_order = 1;
17             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.");
18         }
19         }
20
21     if ($allready_on_order != 1)
22     {
23          $order->add_to_cart ($new_item, $new_item_qty, $standard_cost);
24     } /* end of if not already on the order */
25 }
26
27 //--------------------------------------------------------------------------------
28
29 function display_order_header(&$order)
30 {
31         global $table_style2;
32         
33         start_table("width=70% $table_style2"); // outer table
34         echo "<tr><td valign=top width=33%>"; 
35         echo "<table>"; // inner table
36
37         locations_list_row(_("Location:"), 'StockLocation', null);
38         ref_row(_("Reference:"), 'ref', '', references::get_next(systypes::inventory_adjustment()));
39
40         echo "</table>"; // inner table
41
42         echo "</td><td width=33%>"; 
43
44         echo "<table>"; // inner table
45
46     date_row(_("Date:"), 'AdjDate');
47
48         echo "</table>"; // inner table
49
50         echo "</td><td width=33%>"; 
51
52         echo "<table>"; // inner table
53     movement_types_list_row(_("Detail:"), 'type', null);
54
55     if (!isset($_POST['Increase']))
56         $_POST['Increase'] = 1;
57     yesno_list_row(_("Type:"), 'Increase', $_POST['Increase'],
58         _("Positive Adjustment"), _("Negative Adjustment"));
59
60         echo "</table>"; // inner table
61
62         echo "</td></tr>"; 
63         end_table(1); // outer table
64 }
65
66 //---------------------------------------------------------------------------------
67
68 function display_adjustment_items($title, &$order)
69 {
70         global $table_style, $path_to_root;
71
72         display_heading($title);
73         start_table("$table_style width=80%");
74         $th = array(_("Item Code"), _("Item Description"), _("Quantity"), 
75                 _("Unit"), _("Unit Cost"), _("Total"));
76         if ( count($order->line_items)) $th[] = '';
77
78         table_header($th);
79         $total = 0;
80         $k = 0;  //row colour counter
81
82         foreach ($order->line_items as $stock_item) 
83         {
84
85                 $quantity = number_format2($stock_item->quantity,user_qty_dec());
86
87                 $total += ($stock_item->standard_cost * $stock_item->quantity);
88
89                 if (!isset($_GET['Edit']) || $_GET['Edit'] != $stock_item->stock_id)
90                 {
91                 alt_table_row_color($k);
92
93                         label_cell("<a target='_blank' href='$path_to_root/inventory/inquiry/stock_status.php?" . SID . "stock_id=" . $stock_item->stock_id . "'>$stock_item->stock_id</a>");
94                         label_cell($stock_item->item_description);
95                         label_cell($quantity, "nowrap align=right");
96                         label_cell($stock_item->units);
97                         amount_cell($stock_item->standard_cost);
98                         amount_cell($stock_item->standard_cost * $stock_item->quantity);
99
100                         edit_link_cell(SID . "Edit=$stock_item->stock_id");
101                         delete_link_cell(SID . "Delete=$stock_item->stock_id");
102                         end_row();
103                 } 
104                 else 
105                 {
106                         adjustment_edit_item_controls($order, $stock_item->stock_id);
107                 }
108         }
109
110         if (!isset($_GET['Edit']))
111                 adjustment_edit_item_controls($order);
112
113         label_row(_("Total"), number_format2($total,user_price_dec()), "colspan=5", "align=right");
114
115     end_table();
116 }
117
118 //---------------------------------------------------------------------------------
119
120 function adjustment_edit_item_controls(&$order, $stock_id=null)
121 {
122         start_row();
123
124         if (isset($_GET['Edit']) and $stock_id!=null)
125         {
126                 if (!isset($_POST['stock_id']))
127                         $_POST['stock_id'] = $order->line_items[$stock_id]->stock_id;
128                 if (!isset($_POST['qty']) OR ($_POST['qty']==""))
129                         $_POST['qty'] = qty_format($order->line_items[$stock_id]->quantity);
130                 if (!isset($_POST['std_cost']) OR ($_POST['std_cost']==""))
131                         $_POST['std_cost'] = price_format($order->line_items[$stock_id]->standard_cost);
132
133                 $_POST['units'] = $order->line_items[$stock_id]->units;
134
135                 hidden('stock_id', $_POST['stock_id']);
136                 label_cell($_POST['stock_id']);
137                 label_cell($order->line_items[$stock_id]->item_description);
138         }
139         else
140         {
141         echo "<td colspan=2>";
142         stock_costable_items_list('stock_id', $_POST['stock_id'], false, true);
143         echo "</td>";
144
145         $item_info = get_item_edit_info($_POST['stock_id']);
146
147                 $_POST['qty'] = qty_format(0);
148                 $_POST['std_cost'] = price_format($item_info["standard_cost"]);
149                 $_POST['units'] = $item_info["units"];
150         }
151
152         qty_cells(null, 'qty', $_POST['qty']);
153
154         label_cell($_POST['units']);
155         amount_cells(null, 'std_cost', $_POST['std_cost']);
156         label_cell("&nbsp;");
157
158         if (isset($_GET['Edit'])) 
159         {
160         submit_cells('UpdateItem', _("Update"));
161         submit_cells('CancelItemChanges', _("Cancel"));
162         } 
163         else 
164         {
165                 submit_cells('AddItem', _("Add Item"), "colspan=2");
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 ?>