*** empty log message ***
[fa-stable.git] / inventory / purchasing_data.php
1 <?php
2
3
4 $page_security = 4;
5 $path_to_root="..";
6 include_once($path_to_root . "/includes/session.inc");
7
8 page(_("Supplier Purchasing Data"));
9
10 include_once($path_to_root . "/includes/date_functions.inc");
11 include_once($path_to_root . "/includes/ui.inc");
12 include_once($path_to_root . "/includes/manufacturing.inc");
13 include_once($path_to_root . "/includes/data_checks.inc");
14
15 check_db_has_purchasable_items(_("There are no purchasable inventory items defined in the system."));
16 check_db_has_suppliers(_("There are no suppliers defined in the system."));
17
18 if (isset($_GET['supplier_id']))
19 {
20         $supplier_id = strtoupper($_GET['supplier_id']);
21
22 elseif (isset($_POST['supplier_id']))
23 {
24         $supplier_id = strtoupper($_POST['supplier_id']);
25 }
26
27 if (isset($_GET['stock_id']))
28 {
29         $_POST['stock_id'] = $_GET['stock_id'];
30 }
31
32 //--------------------------------------------------------------------------------------------------
33
34 if ((isset($_POST['AddRecord']) || isset($_POST['UpdateRecord'])) && isset($supplier_id))
35 {
36
37         $input_error = 0;
38         if ($_POST['stock_id'] == "" || !isset($_POST['stock_id']))
39         {
40         $input_error = 1;
41         display_error( _("There is no item selected."));
42         }
43         elseif (!is_numeric($_POST['price']) || $_POST['price']==0)
44         {
45         $input_error = 1;
46         display_error( _("The price entered was not numeric."));
47         }
48         elseif (!is_numeric($_POST['conversion_factor']))
49         {
50         $input_error = 1;
51         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."));
52         }
53
54         if ($input_error == 0)
55         {
56         if (isset($_POST['AddRecord']))
57         {
58
59                 $sql = "INSERT INTO ".TB_PREF."purch_data (supplier_id, stock_id, price, suppliers_uom,
60                         conversion_factor, supplier_description) VALUES (";
61                 $sql .= "'$supplier_id', '" . $_POST['stock_id'] . "', " . $_POST['price'] . ", '" . $_POST['suppliers_uom'] . "', " .
62                         $_POST['conversion_factor'] . ", '" . $_POST['supplier_description'] . "')";
63
64                 db_query($sql,"The supplier purchasing details could not be added");
65                 display_notification(_("This supplier purchasing data has been added."));
66         }
67
68         if (isset($_POST['UpdateRecord']))
69         {
70                 $sql = "UPDATE ".TB_PREF."purch_data SET price=" . $_POST['price'] . ",
71                                 suppliers_uom='" . $_POST['suppliers_uom'] . "',
72                                 conversion_factor=" . $_POST['conversion_factor'] . ",
73                                 supplier_description='" . $_POST['supplier_description'] . "'
74                                 WHERE stock_id='" . $_POST['stock_id'] . "' AND
75                                 supplier_id='$supplier_id'";
76                 db_query($sql,"The supplier purchasing details could not be updated");
77
78                 display_notification(_("Supplier purchasing data has been updated."));
79         }
80
81         if (isset($_POST['UpdateRecord']) || isset($_POST['AddRecord']))
82         {
83                 //update or insert took place and need to clear the form
84                 unset($supplier_id);
85                 unset($_POST['price']);
86                 unset($_POST['suppliers_uom']);
87                 unset($_POST['conversion_factor']);
88                 unset($_POST['supplier_description']);
89         }
90         }
91 }
92
93 //--------------------------------------------------------------------------------------------------
94
95 if (isset($_GET['Delete']))
96 {
97
98         $sql = "DELETE FROM ".TB_PREF."purch_data WHERE supplier_id='$supplier_id'
99                 AND stock_id='" . $_POST['stock_id'] . "'";
100         db_query($sql,"could not delete purchasing data");
101
102         display_note(_("The purchasing data item has been sucessfully deleted."));
103         unset ($supplier_id);
104 }
105
106 //--------------------------------------------------------------------------------------------------
107
108 start_form(false, true);
109
110 if (!isset($_POST['stock_id']))
111         $_POST['stock_id'] = get_global_stock_item();
112
113 echo "<center>" . _("Item:"). "&nbsp;";
114 stock_purchasable_items_list('stock_id', $_POST['stock_id'], false, true);
115
116 echo "<hr><center>";
117
118 set_global_stock_item($_POST['stock_id']);
119
120 $mb_flag = get_mb_flag($_POST['stock_id']);
121
122 if ($mb_flag == -1) 
123 {
124         display_error(_("Entered item is not defined. Please re-enter."));
125
126 else 
127 {
128
129     $sql = "SELECT ".TB_PREF."purch_data.*,".TB_PREF."suppliers.supp_name,".TB_PREF."suppliers.curr_code
130                 FROM ".TB_PREF."purch_data INNER JOIN ".TB_PREF."suppliers
131                 ON ".TB_PREF."purch_data.supplier_id=".TB_PREF."suppliers.supplier_id
132                 WHERE stock_id = '" . $_POST['stock_id'] . "'";
133
134     $result = db_query($sql, "The supplier purchasing details for the selected part could not be retrieved");
135
136     if (db_num_rows($result) == 0)
137     {
138         display_note(_("There is no purchasing data set up for the part selected"));
139     } 
140     else 
141     {
142         start_table("$table_style width=60%");
143
144                 $th = array(_("Supplier"), _("Price"), _("Currency"),
145                         _("Supplier's Unit"), _("Supplier's Description"), "", "");
146
147         table_header($th);
148
149         $k = $j = 0; //row colour counter
150
151         while ($myrow = db_fetch($result))
152         {
153                         alt_table_row_color($k);
154
155             label_cell($myrow["supp_name"]);
156             amount_cell($myrow["price"]);
157             label_cell($myrow["curr_code"]);
158             label_cell($myrow["suppliers_uom"]);
159             label_cell($myrow["supplier_description"]);
160             edit_link_cell("stock_id=" . $_POST['stock_id']. "&supplier_id=" . $myrow["supplier_id"] . "&Edit=1");
161             delete_link_cell("stock_id=" . $_POST['stock_id']. "&supplier_id=" . $myrow["supplier_id"] . "&Delete=1");
162             end_row();
163
164             $j++;
165             If ($j == 12)
166             {
167                 $j = 1;
168                         table_header($th);
169             } //end of page full new headings
170         } //end of while loop
171
172         end_table();
173     }
174 }
175
176 //------------------------------------------------------------------------------------------------
177
178 if (isset($_GET['Edit']))
179 {
180
181         $sql = "SELECT ".TB_PREF."purch_data.*,".TB_PREF."suppliers.supp_name FROM ".TB_PREF."purch_data
182                 INNER JOIN ".TB_PREF."suppliers ON ".TB_PREF."purch_data.supplier_id=".TB_PREF."suppliers.supplier_id
183                 WHERE ".TB_PREF."purch_data.supplier_id='$supplier_id'
184                 AND ".TB_PREF."purch_data.stock_id='" . $_POST['stock_id'] . "'";
185
186         $result = db_query($sql, "The supplier purchasing details for the selected supplier and item could not be retrieved");
187
188         $myrow = db_fetch($result);
189
190     $supp_name = $myrow["supp_name"];
191     $_POST['price'] = $myrow["price"];
192     $_POST['suppliers_uom'] = $myrow["suppliers_uom"];
193     $_POST['supplier_description'] = $myrow["supplier_description"];
194     $_POST['conversion_factor'] = $myrow["conversion_factor"];
195 }
196
197 echo "<br>";
198 start_table($table_style2);
199
200 if (isset($_GET['Edit'])) 
201 {
202         hidden('supplier_id', $supplier_id);
203         label_row(_("Supplier:"), $supp_name);
204
205 else
206 {
207         supplier_list_row(_("Supplier:"), 'supplier_id', null, false, true);
208         $supplier_id = $_POST['supplier_id'];
209 }       
210 text_row(_("Price:"), 'price', null, 12, 12, "", get_supplier_currency($supplier_id));
211 text_row(_("Suppliers Unit of Measure:"), 'suppliers_uom', null, 50, 51);
212
213 if (!isset($_POST['conversion_factor']) || $_POST['conversion_factor'] == "")
214 {
215         $_POST['conversion_factor'] = 1;
216 }
217 text_row(_("Conversion Factor (to our UOM):"), 'conversion_factor', $_POST['conversion_factor'], 12, 12);
218 text_row(_("Supplier's Code or Description:"), 'supplier_description', null, 50, 51);
219
220 end_table(1);
221
222 if (isset($_GET['Edit']))
223 {
224         submit_center('UpdateRecord', _("Update Purchasing Data"));
225
226 else 
227 {
228         submit_center('AddRecord', _("Add Purchasing Data"));
229 }
230
231 end_form();
232 end_page();
233
234 ?>