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 ***********************************************************************/
14 include_once($path_to_root . "/includes/session.inc");
16 page(_("Inventory Item Sales prices"));
18 include_once($path_to_root . "/sales/includes/sales_db.inc");
19 include_once($path_to_root . "/sales/includes/db/sales_types_db.inc");
20 include_once($path_to_root . "/includes/ui.inc");
21 include_once($path_to_root . "/includes/data_checks.inc");
23 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
25 //---------------------------------------------------------------------------------------------------
27 check_db_has_stock_items(_("There are no items defined in the system."));
29 check_db_has_sales_types(_("There are no sales types in the system. Please set up sales types befor entering pricing."));
31 simple_page_mode(true);
32 //---------------------------------------------------------------------------------------------------
35 if (isset($_GET['stock_id']))
37 $_POST['stock_id'] = $_GET['stock_id'];
39 if (isset($_GET['Item']))
41 $_POST['stock_id'] = $_GET['Item'];
44 if (!isset($_POST['curr_abrev']))
46 $_POST['curr_abrev'] = get_company_currency();
49 //---------------------------------------------------------------------------------------------------
51 start_form(false, true);
53 if (!isset($_POST['stock_id']))
54 $_POST['stock_id'] = get_global_stock_item();
56 echo "<center>" . _("Item:"). " ";
57 sales_items_list('stock_id', $_POST['stock_id'], false, true);
60 set_global_stock_item($_POST['stock_id']);
62 //----------------------------------------------------------------------------------------------------
64 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
67 if (!check_num('price', 0))
70 display_error( _("The price entered must be numeric."));
74 if ($input_error != 1)
77 if ($selected_id != -1)
79 //editing an existing price
80 update_item_price($selected_id, $_POST['sales_type_id'],
81 $_POST['curr_abrev'], input_num('price'));
83 $msg = _("This price has been updated.");
88 add_item_price($_POST['stock_id'], $_POST['sales_type_id'],
89 $_POST['curr_abrev'], input_num('price'));
91 $msg = _("The new price has been added.");
93 display_notification($msg);
99 //------------------------------------------------------------------------------------------------------
101 if ($Mode == 'Delete')
103 //the link to delete a selected record was clicked
104 delete_item_price($selected_id);
105 display_notification(_("The selected price has been deleted."));
109 if ($Mode == 'RESET')
114 if (list_updated('stock_id')) {
115 $Ajax->activate('price_table');
116 $Ajax->activate('price_details');
118 if (list_updated('stock_id') || isset($_POST['_curr_abrev_update']) ) {
119 // after change of stock, currency or salestype selector
120 // display default calculated price for new settings.
121 // If we have this price already in db it is overwritten later.
122 unset($_POST['price']);
123 $Ajax->activate('price_details');
126 //---------------------------------------------------------------------------------------------------
128 $mb_flag = get_mb_flag($_POST['stock_id']);
130 $prices_list = get_prices($_POST['stock_id']);
132 div_start('price_table');
133 start_table("$table_style width=30%");
135 $th = array(_("Currency"), _("Sales Type"), _("Price"), "", "");
137 $k = 0; //row colour counter
139 while ($myrow = db_fetch($prices_list))
142 alt_table_row_color($k);
144 label_cell($myrow["curr_abrev"]);
145 label_cell($myrow["sales_type"]);
146 amount_cell($myrow["price"]);
147 edit_button_cell("Edit".$myrow['id'], _("Edit"));
148 delete_button_cell("Delete".$myrow['id'], _("Delete"));
153 if (db_num_rows($prices_list) == 0)
155 display_note(_("There are no prices set up for this part."), 1);
158 //------------------------------------------------------------------------------------------------
164 $myrow = get_stock_price($selected_id);
165 $_POST['curr_abrev'] = $myrow["curr_abrev"];
166 $_POST['sales_type_id'] = $myrow["sales_type_id"];
167 $_POST['price'] = price_format($myrow["price"]);
170 hidden('selected_id', $selected_id);
171 div_start('price_details');
172 start_table($table_style2);
174 currencies_list_row(_("Currency:"), 'curr_abrev', null, true);
176 sales_types_list_row(_("Sales Type:"), 'sales_type_id', null, true);
177 if (!isset($_POST['price'])) {
178 $_POST['price'] = price_format(get_kit_price(get_post('stock_id'),
179 get_post('curr_abrev'), get_post('sales_type_id')));
182 $kit = get_item_code_dflts($_POST['stock_id']);
183 small_amount_row(_("Price:"), 'price', null, '', _('per') .' '.$kit["units"]);
187 submit_add_or_update_center($selected_id == -1, '', true);