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_PURCHASEPRICING';
16 $path_to_root = "../..";
18 include_once($path_to_root . "/includes/session.inc");
19 include_once($path_to_root . "/includes/date_functions.inc");
20 include_once($path_to_root . "/includes/ui.inc");
21 include_once($path_to_root . "/includes/data_checks.inc");
23 page(_($help_context = "Supplier Purchasing Data"));
25 check_db_has_purchasable_items(_("There are no purchasable inventory items defined in the system."));
26 check_db_has_suppliers(_("There are no suppliers defined in the system."));
28 //----------------------------------------------------------------------------------------
29 simple_page_mode(true);
30 if (isset($_GET['stock_id']))
32 $_POST['stock_id'] = $_GET['stock_id'];
35 //--------------------------------------------------------------------------------------------------
37 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
41 if ($_POST['stock_id'] == "" || !isset($_POST['stock_id']))
44 display_error( _("There is no item selected."));
45 set_focus('stock_id');
47 elseif (!check_num('price', 0))
50 display_error( _("The price entered was not numeric."));
53 elseif (!check_num('conversion_factor'))
56 display_error( _("The conversion factor entered was not numeric. The conversion factor is the number by which the price must be divided by to get the unit price in our unit of measure."));
57 set_focus('conversion_factor');
59 elseif ($Mode == 'ADD_ITEM' && get_item_purchasing_data($_POST['supplier_id'], $_POST['stock_id']))
62 display_error( _("The purchasing data for this supplier has already been added."));
63 set_focus('supplier_id');
65 if ($input_error == 0)
67 if ($Mode == 'ADD_ITEM')
69 add_item_purchasing_data($_POST['supplier_id'], $_POST['stock_id'], input_num('price',0),
70 $_POST['suppliers_uom'], input_num('conversion_factor'), $_POST['supplier_description']);
71 display_notification(_("This supplier purchasing data has been added."));
75 update_item_purchasing_data($selected_id, $_POST['stock_id'], input_num('price',0),
76 $_POST['suppliers_uom'], input_num('conversion_factor'), $_POST['supplier_description']);
77 display_notification(_("Supplier purchasing data has been updated."));
83 //--------------------------------------------------------------------------------------------------
85 if ($Mode == 'Delete')
87 delete_item_purchasing_data($selected_id, $_POST['stock_id']);
88 display_notification(_("The purchasing data item has been sucessfully deleted."));
97 if (isset($_POST['_selected_id_update']) )
99 $selected_id = $_POST['selected_id'];
100 $Ajax->activate('_page_body');
103 if (list_updated('stock_id'))
104 $Ajax->activate('price_table');
105 //--------------------------------------------------------------------------------------------------
107 $action = $_SERVER['PHP_SELF'];
109 $action .= "?stock_id=".get_post('stock_id');
110 start_form(false, false, $action);
112 if (!isset($_POST['stock_id']))
113 $_POST['stock_id'] = get_global_stock_item();
117 echo "<center>" . _("Item:"). " ";
118 //Chaitanya : All items can be purchased
119 echo stock_items_list('stock_id', $_POST['stock_id'], false, true);
120 //echo stock_purchasable_items_list('stock_id', $_POST['stock_id'], false, true);
121 echo "<hr></center>";
126 set_global_stock_item($_POST['stock_id']);
128 $mb_flag = get_mb_flag($_POST['stock_id']);
132 display_error(_("Entered item is not defined. Please re-enter."));
133 set_focus('stock_id');
137 $result = get_items_purchasing_data($_POST['stock_id']);
138 div_start('price_table');
139 if (db_num_rows($result) == 0)
141 display_note(_("There is no purchasing data set up for the part selected"));
145 start_table(TABLESTYLE, "width='65%'");
147 $th = array(_("Supplier"), _("Price"), _("Currency"),
148 _("Supplier's Unit"), _("Conversion Factor"), _("Supplier's Description"), "", "");
152 $k = $j = 0; //row colour counter
154 while ($myrow = db_fetch($result))
156 alt_table_row_color($k);
158 label_cell($myrow["supp_name"]);
159 amount_decimal_cell($myrow["price"]);
160 label_cell($myrow["curr_code"]);
161 label_cell($myrow["suppliers_uom"]);
162 qty_cell($myrow['conversion_factor'], false, 'max');
163 label_cell($myrow["supplier_description"]);
164 edit_button_cell("Edit".$myrow['supplier_id'], _("Edit"));
165 delete_button_cell("Delete".$myrow['supplier_id'], _("Delete"));
173 } //end of page full new headings
174 } //end of while loop
181 //-----------------------------------------------------------------------------------------------
186 $myrow = get_item_purchasing_data($selected_id, $_POST['stock_id']);
188 $supp_name = $myrow["supp_name"];
189 $_POST['price'] = price_decimal_format($myrow["price"], $dec2);
190 $_POST['suppliers_uom'] = $myrow["suppliers_uom"];
191 $_POST['supplier_description'] = $myrow["supplier_description"];
192 $_POST['conversion_factor'] = maxprec_format($myrow["conversion_factor"]);
196 hidden('selected_id', $selected_id);
199 hidden('popup', @$_GET['popup']);
202 start_table(TABLESTYLE2);
206 hidden('supplier_id');
207 label_row(_("Supplier:"), $supp_name);
211 supplier_list_row(_("Supplier:"), 'supplier_id', null, false, true);
212 $_POST['price'] = $_POST['suppliers_uom'] = $_POST['conversion_factor'] = $_POST['supplier_description'] = "";
214 amount_row(_("Price:"), 'price', null,'', get_supplier_currency($selected_id), $dec2);
215 text_row(_("Suppliers Unit of Measure:"), 'suppliers_uom', null, 50, 51);
217 if (!isset($_POST['conversion_factor']) || $_POST['conversion_factor'] == "")
219 $_POST['conversion_factor'] = maxprec_format(1);
221 amount_row(_("Conversion Factor (to our UOM):"), 'conversion_factor', null, null, null, 'max');
222 text_row(_("Supplier's Code or Description:"), 'supplier_description', null, 50, 51);
226 submit_add_or_update_center($selected_id == -1, '', 'both');