Some more fixes related to ajax combos behaviour and usage
[fa-stable.git] / inventory / prices.php
1 <?php
2
3 $page_security = 2;
4 $path_to_root="..";
5 include_once($path_to_root . "/includes/session.inc");
6
7 page(_("Inventory Item Sales prices"));
8
9 include_once($path_to_root . "/includes/ui.inc");
10 include_once($path_to_root . "/includes/data_checks.inc");
11
12 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
13
14 //---------------------------------------------------------------------------------------------------
15
16 check_db_has_stock_items(_("There are no items defined in the system."));
17
18 check_db_has_sales_types(_("There are no sales types in the system. Please set up sales types befor entering pricing."));
19
20 //---------------------------------------------------------------------------------------------------
21
22 $input_error = 0;
23
24 if (isset($_GET['stock_id']))
25 {
26         $_POST['stock_id'] = $_GET['stock_id'];
27 }
28 if (isset($_GET['Item']))
29 {
30         $_POST['stock_id'] = $_GET['Item'];
31 }
32
33 if (!isset($_POST['curr_abrev']))
34 {
35         $_POST['curr_abrev'] = get_company_currency();
36 }
37
38 //---------------------------------------------------------------------------------------------------
39
40 start_form(false, true);
41
42 if (!isset($_POST['stock_id']))
43         $_POST['stock_id'] = get_global_stock_item();
44
45 echo "<center>" . _("Item:"). "&nbsp;";
46 stock_items_list('stock_id', $_POST['stock_id'], false, true);
47 echo "<hr></center>";
48
49 // if stock sel has changed, clear the form
50 if ($_POST['stock_id'] != get_global_stock_item())
51 {
52         clear_data();
53 }
54
55 set_global_stock_item($_POST['stock_id']);
56
57 //----------------------------------------------------------------------------------------------------
58
59 function clear_data()
60 {
61         unset($_POST['PriceID']);
62         unset($_POST['price']);
63 }
64
65 //----------------------------------------------------------------------------------------------------
66
67 if (isset($_POST['updatePrice']))
68 {
69
70         if (!check_num('price', 0))
71         {
72                 $input_error = 1;
73                 display_error( _("The price entered must be numeric."));
74                 set_focus('price');
75         }
76
77         if ($input_error != 1)
78         {
79
80                 if (isset($_POST['PriceID']))
81                 {
82                         //editing an existing price
83                         update_item_price($_POST['PriceID'], $_POST['sales_type_id'],
84                         $_POST['curr_abrev'], input_num('price'));
85
86                         $msg = _("This price has been updated.");
87                 }
88                 elseif ($input_error !=1)
89                 {
90
91                         add_item_price($_POST['stock_id'], $_POST['sales_type_id'],
92                             $_POST['curr_abrev'], input_num('price'));
93
94                         display_note(_("The new price has been added."));
95                 }
96                 clear_data();
97         }
98
99 }
100
101 //------------------------------------------------------------------------------------------------------
102
103 if (isset($_GET['delete']))
104 {
105
106         //the link to delete a selected record was clicked
107         delete_item_price($_GET['PriceID']);
108         echo _("The selected price has been deleted.");
109
110 }
111 if (isset($_POST['_stock_id_update']))
112         $Ajax->activate('price_table');
113 //---------------------------------------------------------------------------------------------------
114
115 $mb_flag = get_mb_flag($_POST['stock_id']);
116
117 $prices_list = get_prices($_POST['stock_id']);
118
119 div_start('price_table');
120 start_table("$table_style width=30%");
121
122 $th = array(_("Currency"), _("Sales Type"), _("Price"), "", "");
123 table_header($th);
124 $k = 0; //row colour counter
125
126 while ($myrow = db_fetch($prices_list))
127 {
128
129         alt_table_row_color($k);
130
131         label_cell($myrow["curr_abrev"]);
132     label_cell($myrow["sales_type"]);
133     amount_cell($myrow["price"]);
134     edit_link_cell("PriceID=" . $myrow["id"]. "&Edit=1");
135     delete_link_cell("PriceID=" . $myrow["id"]. "&delete=yes");
136     end_row();
137
138 }
139 end_table();
140 div_end();
141 //------------------------------------------------------------------------------------------------
142
143 if (db_num_rows($prices_list) == 0)
144 {
145         display_note(_("There are no prices set up for this part."));
146 }
147
148 echo "<br>";
149
150 if (isset($_GET['Edit']))
151 {
152         $myrow = get_stock_price($_GET['PriceID']);
153         hidden('PriceID', $_GET['PriceID']);
154         $_POST['curr_abrev'] = $myrow["curr_abrev"];
155         $_POST['sales_type_id'] = $myrow["sales_type_id"];
156         $_POST['price'] = price_format($myrow["price"]);
157 }
158
159 start_table($table_style2);
160
161 currencies_list_row(_("Currency:"), 'curr_abrev', null);
162
163 sales_types_list_row(_("Sales Type:"), 'sales_type_id', null);
164
165 small_amount_row(_("Price:"), 'price', null);
166
167 end_table(1);
168
169 submit_center('updatePrice', _("Add/Update Price"));
170
171
172 end_form();
173 end_page();
174 ?>