*** empty log message ***
[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         table_header($th);
77         $total = 0;
78         $k = 0;  //row colour counter
79
80         foreach ($order->line_items as $stock_item) 
81         {
82
83                 $quantity = number_format2($stock_item->quantity,user_qty_dec());
84
85                 $total += ($stock_item->standard_cost * $stock_item->quantity);
86
87                 if (!isset($_GET['Edit']) || $_GET['Edit'] != $stock_item->stock_id)
88                 {
89                 alt_table_row_color($k);
90
91                         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>");
92                         label_cell($stock_item->item_description);
93                         label_cell($quantity, "nowrap align=right");
94                         label_cell($stock_item->units);
95                         amount_cell($stock_item->standard_cost);
96                         amount_cell($stock_item->standard_cost * $stock_item->quantity);
97
98                         edit_link_cell(SID . "Edit=$stock_item->stock_id");
99                         delete_link_cell(SID . "Delete=$stock_item->stock_id");
100                         end_row();
101                 } 
102                 else 
103                 {
104                         adjustment_edit_item_controls($order, $stock_item->stock_id);
105                 }
106         }
107
108         if (!isset($_GET['Edit']))
109                 adjustment_edit_item_controls($order);
110
111         label_row(_("Total"), number_format2($total,user_price_dec()), "colspan=5", "align=right");
112
113     end_table();
114 }
115
116 //---------------------------------------------------------------------------------
117
118 function adjustment_edit_item_controls(&$order, $stock_id=null)
119 {
120         start_row();
121
122         if (isset($_GET['Edit']) and $stock_id!=null)
123         {
124                 if (!isset($_POST['stock_id']))
125                         $_POST['stock_id'] = $order->line_items[$stock_id]->stock_id;
126                 if (!isset($_POST['qty']) OR ($_POST['qty']==""))
127                         $_POST['qty'] = $order->line_items[$stock_id]->quantity;
128                 if (!isset($_POST['std_cost']) OR ($_POST['std_cost']==""))
129                         $_POST['std_cost'] = $order->line_items[$stock_id]->standard_cost;
130
131                 $_POST['units'] = $order->line_items[$stock_id]->units;
132
133                 hidden('stock_id', $_POST['stock_id']);
134                 label_cell($_POST['stock_id']);
135                 label_cell($order->line_items[$stock_id]->item_description);
136         }
137         else
138         {
139         echo "<td colspan=2>";
140         stock_costable_items_list('stock_id', $_POST['stock_id'], false, true);
141         echo "</td>";
142
143         $item_info = get_item_edit_info($_POST['stock_id']);
144
145                 $_POST['qty'] = 0;
146                 $_POST['std_cost'] = $item_info["standard_cost"];
147                 $_POST['units'] = $item_info["units"];
148         }
149
150         text_cells(null, 'qty', $_POST['qty'], 13, 15);
151
152         label_cell($_POST['units']);
153         text_cells(null, 'std_cost', $_POST['std_cost'], 15, 14);
154         label_cell("&nbsp;");
155
156         if (isset($_GET['Edit'])) 
157         {
158         submit_cells('UpdateItem', _("Update"));
159         submit_cells('CancelItemChanges', _("Cancel"));
160         } 
161         else 
162         {
163                 submit_cells('AddItem', _("Add Item"), "colspan=2");
164         }
165
166         end_row();
167 }
168
169
170 //---------------------------------------------------------------------------------
171
172 function adjustment_options_controls()
173 {
174           echo "<br>";
175           start_table();
176
177           textarea_row(_("Memo"), 'memo_', null, 50, 3);
178
179           end_table(1);
180 }
181
182
183 //---------------------------------------------------------------------------------
184
185 ?>