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(_("Supplier Purchasing Data"));
18 include_once($path_to_root . "/includes/date_functions.inc");
19 include_once($path_to_root . "/includes/ui.inc");
20 include_once($path_to_root . "/includes/manufacturing.inc");
21 include_once($path_to_root . "/includes/data_checks.inc");
23 check_db_has_purchasable_items(_("There are no purchasable inventory items defined in the system."));
24 check_db_has_suppliers(_("There are no suppliers defined in the system."));
26 //----------------------------------------------------------------------------------------
27 simple_page_mode(true);
29 //--------------------------------------------------------------------------------------------------
31 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
35 if ($_POST['stock_id'] == "" || !isset($_POST['stock_id']))
38 display_error( _("There is no item selected."));
39 set_focus('stock_id');
41 elseif (!check_num('price', 0))
44 display_error( _("The price entered was not numeric."));
47 elseif (!check_num('conversion_factor'))
50 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."));
51 set_focus('conversion_factor');
54 if ($input_error == 0)
56 if ($Mode == 'ADD_ITEM')
59 $sql = "INSERT INTO ".TB_PREF."purch_data (supplier_id, stock_id, price, suppliers_uom,
60 conversion_factor, supplier_description) VALUES (";
61 $sql .= "'".$_POST['supplier_id']."', '" . $_POST['stock_id'] . "', " .
62 input_num('price',0) . ", '" . $_POST['suppliers_uom'] . "', " .
63 input_num('conversion_factor') . ", " . db_escape($_POST['supplier_description']) . ")";
65 db_query($sql,"The supplier purchasing details could not be added");
66 display_notification(_("This supplier purchasing data has been added."));
69 $sql = "UPDATE ".TB_PREF."purch_data SET price=" . input_num('price',0) . ",
70 suppliers_uom='" . $_POST['suppliers_uom'] . "',
71 conversion_factor=" . input_num('conversion_factor') . ",
72 supplier_description=" . db_escape($_POST['supplier_description']) . "
73 WHERE stock_id='" . $_POST['stock_id'] . "' AND
74 supplier_id='$selected_id'";
75 db_query($sql,"The supplier purchasing details could not be updated");
77 display_notification(_("Supplier purchasing data has been updated."));
83 //--------------------------------------------------------------------------------------------------
85 if ($Mode == 'Delete')
88 $sql = "DELETE FROM ".TB_PREF."purch_data WHERE supplier_id='$selected_id'
89 AND stock_id='" . $_POST['stock_id'] . "'";
90 db_query($sql,"could not delete purchasing data");
92 display_notification(_("The purchasing data item has been sucessfully deleted."));
101 if (isset($_POST['_selected_id_update']) )
103 $selected_id = $_POST['selected_id'];
104 $Ajax->activate('_page_body');
107 if (list_updated('stock_id'))
108 $Ajax->activate('price_table');
109 //--------------------------------------------------------------------------------------------------
113 if (!isset($_POST['stock_id']))
114 $_POST['stock_id'] = get_global_stock_item();
116 echo "<center>" . _("Item:"). " ";
117 stock_purchasable_items_list('stock_id', $_POST['stock_id'], false, true);
119 echo "<hr></center>";
121 set_global_stock_item($_POST['stock_id']);
123 $mb_flag = get_mb_flag($_POST['stock_id']);
127 display_error(_("Entered item is not defined. Please re-enter."));
128 set_focus('stock_id');
133 $sql = "SELECT ".TB_PREF."purch_data.*,".TB_PREF."suppliers.supp_name,".TB_PREF."suppliers.curr_code
134 FROM ".TB_PREF."purch_data INNER JOIN ".TB_PREF."suppliers
135 ON ".TB_PREF."purch_data.supplier_id=".TB_PREF."suppliers.supplier_id
136 WHERE stock_id = '" . $_POST['stock_id'] . "'";
138 $result = db_query($sql, "The supplier purchasing details for the selected part could not be retrieved");
139 div_start('price_table');
140 if (db_num_rows($result) == 0)
142 display_note(_("There is no purchasing data set up for the part selected"));
146 start_table("$table_style width=65%");
148 $th = array(_("Supplier"), _("Price"), _("Currency"),
149 _("Supplier's Unit"), _("Conversion Factor"), _("Supplier's Description"), "", "");
153 $k = $j = 0; //row colour counter
155 while ($myrow = db_fetch($result))
157 alt_table_row_color($k);
159 label_cell($myrow["supp_name"]);
160 amount_cell($myrow["price"]);
161 label_cell($myrow["curr_code"]);
162 label_cell($myrow["suppliers_uom"]);
163 qty_cell($myrow['conversion_factor'], false, user_exrate_dec());
164 label_cell($myrow["supplier_description"]);
165 edit_button_cell("Edit".$myrow['supplier_id'], _("Edit"));
166 delete_button_cell("Delete".$myrow['supplier_id'], _("Delete"));
174 } //end of page full new headings
175 } //end of while loop
182 //-----------------------------------------------------------------------------------------------
187 $sql = "SELECT ".TB_PREF."purch_data.*,".TB_PREF."suppliers.supp_name FROM ".TB_PREF."purch_data
188 INNER JOIN ".TB_PREF."suppliers ON ".TB_PREF."purch_data.supplier_id=".TB_PREF."suppliers.supplier_id
189 WHERE ".TB_PREF."purch_data.supplier_id='$selected_id'
190 AND ".TB_PREF."purch_data.stock_id='" . $_POST['stock_id'] . "'";
192 $result = db_query($sql, "The supplier purchasing details for the selected supplier and item could not be retrieved");
194 $myrow = db_fetch($result);
196 $supp_name = $myrow["supp_name"];
197 $_POST['price'] = price_format($myrow["price"]);
198 $_POST['suppliers_uom'] = $myrow["suppliers_uom"];
199 $_POST['supplier_description'] = $myrow["supplier_description"];
200 $_POST['conversion_factor'] = exrate_format($myrow["conversion_factor"]);
204 hidden('selected_id', $selected_id);
205 start_table($table_style2);
209 hidden('supplier_id');
210 label_row(_("Supplier:"), $supp_name);
214 supplier_list_row(_("Supplier:"), 'supplier_id', null, false, true);
215 $_POST['price'] = $_POST['suppliers_uom'] = $_POST['conversion_factor'] = $_POST['supplier_description'] = "";
217 amount_row(_("Price:"), 'price', null,'', get_supplier_currency($selected_id));
218 text_row(_("Suppliers Unit of Measure:"), 'suppliers_uom', null, 50, 51);
220 if (!isset($_POST['conversion_factor']) || $_POST['conversion_factor'] == "")
222 $_POST['conversion_factor'] = exrate_format(1);
224 amount_row(_("Conversion Factor (to our UOM):"), 'conversion_factor',
225 exrate_format($_POST['conversion_factor']), null, null, user_exrate_dec() );
226 text_row(_("Supplier's Code or Description:"), 'supplier_description', null, 50, 51);
230 submit_add_or_update_center($selected_id == -1, '', 'both');