5 include_once($path_to_root . "/includes/session.inc");
7 page(_("Inventory Item Sales prices"));
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");
14 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
16 //---------------------------------------------------------------------------------------------------
18 check_db_has_stock_items(_("There are no items defined in the system."));
20 check_db_has_sales_types(_("There are no sales types in the system. Please set up sales types befor entering pricing."));
22 simple_page_mode(true);
23 //---------------------------------------------------------------------------------------------------
26 if (isset($_GET['stock_id']))
28 $_POST['stock_id'] = $_GET['stock_id'];
30 if (isset($_GET['Item']))
32 $_POST['stock_id'] = $_GET['Item'];
35 if (!isset($_POST['curr_abrev']))
37 $_POST['curr_abrev'] = get_company_currency();
40 //---------------------------------------------------------------------------------------------------
42 start_form(false, true);
44 if (!isset($_POST['stock_id']))
45 $_POST['stock_id'] = get_global_stock_item();
47 echo "<center>" . _("Item:"). " ";
48 stock_items_list('stock_id', $_POST['stock_id'], false, true);
51 set_global_stock_item($_POST['stock_id']);
53 //----------------------------------------------------------------------------------------------------
55 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
58 if (!check_num('price', 0))
61 display_error( _("The price entered must be numeric."));
65 if ($input_error != 1)
68 if ($selected_id != -1)
70 //editing an existing price
71 update_item_price($selected_id, $_POST['sales_type_id'],
72 $_POST['curr_abrev'], input_num('price'));
74 $msg = _("This price has been updated.");
79 add_item_price($_POST['stock_id'], $_POST['sales_type_id'],
80 $_POST['curr_abrev'], input_num('price'));
82 $msg = _("The new price has been added.");
84 display_notification($msg);
90 //------------------------------------------------------------------------------------------------------
92 if ($Mode == 'Delete')
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."));
100 if ($Mode == 'RESET')
105 if (list_updated('stock_id')) {
106 $Ajax->activate('price_table');
107 $Ajax->activate('price_details');
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');
117 //---------------------------------------------------------------------------------------------------
119 $mb_flag = get_mb_flag($_POST['stock_id']);
121 $prices_list = get_prices($_POST['stock_id']);
123 div_start('price_table');
124 start_table("$table_style width=30%");
126 $th = array(_("Currency"), _("Sales Type"), _("Price"), "", "");
128 $k = 0; //row colour counter
130 while ($myrow = db_fetch($prices_list))
133 alt_table_row_color($k);
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"));
144 if (db_num_rows($prices_list) == 0)
146 display_note(_("There are no prices set up for this part."));
149 //------------------------------------------------------------------------------------------------
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"]);
161 hidden('selected_id', $selected_id);
162 div_start('price_details');
163 start_table($table_style2);
165 currencies_list_row(_("Currency:"), 'curr_abrev', null, true);
167 sales_types_list_row(_("Sales Type:"), 'sales_type_id', null, true);
169 small_amount_row(_("Price:"), 'price', null);
173 submit_add_or_update_center($selected_id == -1, '', true);