Merged bugfixes upto [0000072] (version 2.0.3).
[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 . "/sales/includes/sales_db.inc");
10 include_once($path_to_root . "/sales/includes/db/sales_types_db.inc");
11 include_once($path_to_root . "/includes/ui.inc");
12 include_once($path_to_root . "/includes/data_checks.inc");
13
14 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
15
16 //---------------------------------------------------------------------------------------------------
17
18 check_db_has_stock_items(_("There are no items defined in the system."));
19
20 check_db_has_sales_types(_("There are no sales types in the system. Please set up sales types befor entering pricing."));
21
22 simple_page_mode(true);
23 //---------------------------------------------------------------------------------------------------
24 $input_error = 0;
25
26 if (isset($_GET['stock_id']))
27 {
28         $_POST['stock_id'] = $_GET['stock_id'];
29 }
30 if (isset($_GET['Item']))
31 {
32         $_POST['stock_id'] = $_GET['Item'];
33 }
34
35 if (!isset($_POST['curr_abrev']))
36 {
37         $_POST['curr_abrev'] = get_company_currency();
38 }
39
40 //---------------------------------------------------------------------------------------------------
41
42 start_form(false, true);
43
44 if (!isset($_POST['stock_id']))
45         $_POST['stock_id'] = get_global_stock_item();
46
47 echo "<center>" . _("Item:"). "&nbsp;";
48 stock_items_list('stock_id', $_POST['stock_id'], false, true);
49 echo "<hr></center>";
50
51 set_global_stock_item($_POST['stock_id']);
52
53 //----------------------------------------------------------------------------------------------------
54
55 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
56 {
57
58         if (!check_num('price', 0))
59         {
60                 $input_error = 1;
61                 display_error( _("The price entered must be numeric."));
62                 set_focus('price');
63         }
64
65         if ($input_error != 1)
66         {
67
68         if ($selected_id != -1) 
69                 {
70                         //editing an existing price
71                         update_item_price($selected_id, $_POST['sales_type_id'],
72                         $_POST['curr_abrev'], input_num('price'));
73
74                         $msg = _("This price has been updated.");
75                 }
76                 else
77                 {
78
79                         add_item_price($_POST['stock_id'], $_POST['sales_type_id'],
80                             $_POST['curr_abrev'], input_num('price'));
81
82                         $msg = _("The new price has been added.");
83                 }
84                 display_notification($msg);
85                 $Mode = 'RESET';
86         }
87
88 }
89
90 //------------------------------------------------------------------------------------------------------
91
92 if ($Mode == 'Delete')
93 {
94         //the link to delete a selected record was clicked
95         delete_item_price($selected_id);
96         display_notification(_("The selected price has been deleted."));
97         $Mode = 'RESET';
98 }
99
100 if ($Mode == 'RESET')
101 {
102         $selected_id = -1;
103 }
104
105 if (list_updated('stock_id')) {
106         $Ajax->activate('price_table');
107         $Ajax->activate('price_details');
108 }
109 if (list_updated('stock_id') || isset($_POST['_curr_abrev_update']) ) {
110         // after change of stock, currency or salestype selector
111         // display default calculated price for new settings. 
112         // If we have this price already in db it is overwritten later.
113         $_POST['price'] = price_format(get_price(get_post('stock_id'), 
114                 get_post('curr_abrev'), get_post('sales_type_id')));
115         $Ajax->activate('price_details');
116 }
117 //---------------------------------------------------------------------------------------------------
118
119 $mb_flag = get_mb_flag($_POST['stock_id']);
120
121 $prices_list = get_prices($_POST['stock_id']);
122
123 div_start('price_table');
124 start_table("$table_style width=30%");
125
126 $th = array(_("Currency"), _("Sales Type"), _("Price"), "", "");
127 table_header($th);
128 $k = 0; //row colour counter
129
130 while ($myrow = db_fetch($prices_list))
131 {
132
133         alt_table_row_color($k);
134
135         label_cell($myrow["curr_abrev"]);
136     label_cell($myrow["sales_type"]);
137     amount_cell($myrow["price"]);
138         edit_button_cell("Edit".$myrow['id'], _("Edit"));
139         edit_button_cell("Delete".$myrow['id'], _("Delete"));
140     end_row();
141
142 }
143 end_table();
144 if (db_num_rows($prices_list) == 0)
145 {
146         display_note(_("There are no prices set up for this part."));
147 }
148 div_end();
149 //------------------------------------------------------------------------------------------------
150
151 echo "<br>";
152
153 if ($Mode == 'Edit')
154 {
155         $myrow = get_stock_price($selected_id);
156         $_POST['curr_abrev'] = $myrow["curr_abrev"];
157         $_POST['sales_type_id'] = $myrow["sales_type_id"];
158         $_POST['price'] = price_format($myrow["price"]);
159 }
160
161 hidden('selected_id', $selected_id);
162 div_start('price_details');
163 start_table($table_style2);
164
165 currencies_list_row(_("Currency:"), 'curr_abrev', null, true);
166
167 sales_types_list_row(_("Sales Type:"), 'sales_type_id', null, true);
168
169 small_amount_row(_("Price:"), 'price', null);
170
171 end_table(1);
172
173 submit_add_or_update_center($selected_id == -1, '', true);
174 div_end();
175
176 end_form();
177 end_page();
178 ?>