5 include_once($path_to_root . "/includes/session.inc");
7 page(_("Inventory Item Sales prices"));
9 include_once($path_to_root . "/includes/ui.inc");
10 include_once($path_to_root . "/includes/data_checks.inc");
12 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
14 //---------------------------------------------------------------------------------------------------
16 check_db_has_stock_items(_("There are no items defined in the system."));
18 check_db_has_sales_types(_("There are no sales types in the system. Please set up sales types befor entering pricing."));
20 //---------------------------------------------------------------------------------------------------
24 if (isset($_GET['stock_id']))
26 $_POST['stock_id'] = $_GET['stock_id'];
28 if (isset($_GET['Item']))
30 $_POST['stock_id'] = $_GET['Item'];
33 if (!isset($_POST['curr_abrev']))
35 $_POST['curr_abrev'] = get_company_currency();
38 //---------------------------------------------------------------------------------------------------
40 start_form(false, true);
42 if (!isset($_POST['stock_id']))
43 $_POST['stock_id'] = get_global_stock_item();
45 echo "<center>" . _("Item:"). " ";
46 stock_items_list('stock_id', $_POST['stock_id'], false, true);
49 // if stock sel has changed, clear the form
50 if ($_POST['stock_id'] != get_global_stock_item())
55 set_global_stock_item($_POST['stock_id']);
57 //----------------------------------------------------------------------------------------------------
61 unset($_POST['PriceID']);
62 unset($_POST['price']);
65 //----------------------------------------------------------------------------------------------------
67 if (isset($_POST['updatePrice']))
70 if (!check_num('price', 0))
73 display_error( _("The price entered must be numeric."));
76 if ($input_error != 1)
79 if (isset($_POST['PriceID']))
81 //editing an existing price
82 update_item_price($_POST['PriceID'], $_POST['sales_type_id'],
83 $_POST['curr_abrev'], input_num('price'));
85 $msg = _("This price has been updated.");
87 elseif ($input_error !=1)
90 add_item_price($_POST['stock_id'], $_POST['sales_type_id'],
91 $_POST['curr_abrev'], input_num('price'));
93 display_note(_("The new price has been added."));
100 //------------------------------------------------------------------------------------------------------
102 if (isset($_GET['delete']))
105 //the link to delete a selected record was clicked
106 delete_item_price($_GET['PriceID']);
107 echo _("The selected price has been deleted.");
111 //---------------------------------------------------------------------------------------------------
113 $mb_flag = get_mb_flag($_POST['stock_id']);
115 $prices_list = get_prices($_POST['stock_id']);
117 start_table("$table_style width=30%");
119 $th = array(_("Currency"), _("Sales Type"), _("Price"), "", "");
121 $k = 0; //row colour counter
123 while ($myrow = db_fetch($prices_list))
126 alt_table_row_color($k);
128 label_cell($myrow["curr_abrev"]);
129 label_cell($myrow["sales_type"]);
130 amount_cell($myrow["price"]);
131 edit_link_cell("PriceID=" . $myrow["id"]. "&Edit=1");
132 delete_link_cell("PriceID=" . $myrow["id"]. "&delete=yes");
138 //------------------------------------------------------------------------------------------------
140 if (db_num_rows($prices_list) == 0)
142 display_note(_("There are no prices set up for this part."));
147 if (isset($_GET['Edit']))
149 $myrow = get_stock_price($_GET['PriceID']);
150 hidden('PriceID', $_GET['PriceID']);
151 $_POST['curr_abrev'] = $myrow["curr_abrev"];
152 $_POST['sales_type_id'] = $myrow["sales_type_id"];
153 $_POST['price'] = price_format($myrow["price"]);
156 start_table($table_style2);
158 currencies_list_row(_("Currency:"), 'curr_abrev', null);
160 sales_types_list_row(_("Sales Type:"), 'sales_type_id', null);
162 small_amount_row(_("Price:"), 'price', null);
166 submit_center('updatePrice', _("Add/Update Price"));