2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_SALESPRICE';
14 if (@$_GET['page_level'] == 1)
15 $path_to_root = "../..";
19 include_once($path_to_root . "/includes/session.inc");
20 include_once($path_to_root . "/sales/includes/sales_db.inc");
21 include_once($path_to_root . "/sales/includes/db/sales_types_db.inc");
22 include_once($path_to_root . "/includes/ui.inc");
23 include_once($path_to_root . "/includes/data_checks.inc");
24 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
27 if ($SysPrefs->use_popup_windows && $SysPrefs->use_popup_search)
28 $js .= get_js_open_window(900, 500);
29 page(_($help_context = "Inventory Item Sales prices"), false, false, "", $js);
31 //---------------------------------------------------------------------------------------------------
33 check_db_has_stock_items(_("There are no items defined in the system."));
35 check_db_has_sales_types(_("There are no sales types in the system. Please set up sales types befor entering pricing."));
37 simple_page_mode(true);
38 //---------------------------------------------------------------------------------------------------
41 if (isset($_GET['stock_id']))
43 $_POST['stock_id'] = $_GET['stock_id'];
45 if (isset($_GET['Item']))
47 $_POST['stock_id'] = $_GET['Item'];
50 if (!isset($_POST['curr_abrev']))
52 $_POST['curr_abrev'] = get_company_currency();
55 //---------------------------------------------------------------------------------------------------
56 $action = $_SERVER['PHP_SELF'];
58 $action .= "?stock_id=".get_post('stock_id');
59 start_form(false, false, $action);
61 if (!isset($_POST['stock_id']))
62 $_POST['stock_id'] = get_global_stock_item();
66 echo "<center>" . _("Item:"). " ";
67 echo sales_items_list('stock_id', $_POST['stock_id'], false, true, '', array('editable' => false));
72 set_global_stock_item($_POST['stock_id']);
74 //----------------------------------------------------------------------------------------------------
76 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
79 if (!check_num('price', 0))
82 display_error( _("The price entered must be numeric."));
85 elseif ($Mode == 'ADD_ITEM' && get_stock_price_type_currency($_POST['stock_id'], $_POST['sales_type_id'], $_POST['curr_abrev']))
88 display_error( _("The sales pricing for this item, sales type and currency has already been added."));
89 set_focus('supplier_id');
92 if ($input_error != 1)
95 if ($selected_id != -1)
97 //editing an existing price
98 update_item_price($selected_id, $_POST['sales_type_id'],
99 $_POST['curr_abrev'], input_num('price'));
101 $msg = _("This price has been updated.");
106 add_item_price($_POST['stock_id'], $_POST['sales_type_id'],
107 $_POST['curr_abrev'], input_num('price'));
109 $msg = _("The new price has been added.");
111 display_notification($msg);
117 //------------------------------------------------------------------------------------------------------
119 if ($Mode == 'Delete')
121 //the link to delete a selected record was clicked
122 delete_item_price($selected_id);
123 display_notification(_("The selected price has been deleted."));
127 if ($Mode == 'RESET')
132 if (list_updated('stock_id')) {
133 $Ajax->activate('price_table');
134 $Ajax->activate('price_details');
136 if (list_updated('stock_id') || isset($_POST['_curr_abrev_update']) || isset($_POST['_sales_type_id_update'])) {
137 // after change of stock, currency or salestype selector
138 // display default calculated price for new settings.
139 // If we have this price already in db it is overwritten later.
140 unset($_POST['price']);
141 $Ajax->activate('price_details');
144 //---------------------------------------------------------------------------------------------------
146 $prices_list = get_prices($_POST['stock_id']);
148 div_start('price_table');
149 start_table(TABLESTYLE, "width='30%'");
151 $th = array(_("Currency"), _("Sales Type"), _("Price"), "", "");
153 $k = 0; //row colour counter
155 while ($myrow = db_fetch($prices_list))
158 alt_table_row_color($k);
160 label_cell($myrow["curr_abrev"]);
161 label_cell($myrow["sales_type"]);
162 amount_cell($myrow["price"]);
163 edit_button_cell("Edit".$myrow['id'], _("Edit"));
164 delete_button_cell("Delete".$myrow['id'], _("Delete"));
169 if (db_num_rows($prices_list) == 0)
171 if (get_company_pref('add_pct') != -1)
173 display_note(_("There are no prices set up for this part."), 1);
176 //------------------------------------------------------------------------------------------------
182 $myrow = get_stock_price($selected_id);
183 $_POST['curr_abrev'] = $myrow["curr_abrev"];
184 $_POST['sales_type_id'] = $myrow["sales_type_id"];
185 $_POST['price'] = price_format($myrow["price"]);
188 hidden('selected_id', $selected_id);
190 div_start('price_details');
191 start_table(TABLESTYLE2);
193 currencies_list_row(_("Currency:"), 'curr_abrev', null, true);
195 sales_types_list_row(_("Sales Type:"), 'sales_type_id', null, true);
197 if (!isset($_POST['price'])) {
198 $_POST['price'] = price_format(get_kit_price(get_post('stock_id'),
199 get_post('curr_abrev'), get_post('sales_type_id')));
202 $kit = get_item_code_dflts($_POST['stock_id']);
203 small_amount_row(_("Price:"), 'price', null, '', _('per') .' '.$kit["units"]);
207 display_note(_("The price is calculated."), 0, 1);
209 submit_add_or_update_center($selected_id == -1, '', 'both');