2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU Affero General Public License,
5 AGPL, as published by the Free Software Foundation, either version
6 3 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/agpl-3.0.html>.
11 ***********************************************************************/
12 function db_has_customers()
14 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."debtors_master");
17 function check_db_has_customers($msg)
20 if (!db_has_customers())
22 display_error($msg, true);
28 function db_has_currencies()
30 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."currencies");
33 function check_db_has_currencies($msg)
36 if (!db_has_currencies())
38 display_error($msg, true);
44 function db_has_sales_types()
46 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."sales_types");
49 function check_db_has_sales_types($msg)
52 if (!db_has_sales_types())
54 display_error($msg, true);
60 function db_has_item_tax_types()
62 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."item_tax_types");
65 function check_db_has_item_tax_types($msg)
68 if (!db_has_item_tax_types())
70 display_error($msg, true);
76 function db_has_tax_types()
78 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."tax_types");
81 function check_db_has_tax_types($msg)
84 if (!db_has_tax_types())
86 display_error($msg, true);
92 function db_has_tax_groups()
94 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."tax_groups");
97 function check_db_has_tax_groups($msg)
100 if (!db_has_tax_groups())
102 display_error($msg, true);
108 function db_has_movement_types()
110 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."movement_types");
113 function check_db_has_movement_types($msg)
115 global $path_to_root;
116 if (!db_has_movement_types())
118 display_error($msg, true);
124 function db_customer_has_branches($customer_id)
126 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."cust_branch WHERE debtor_no='$customer_id'");
129 function db_has_customer_branches()
131 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."cust_branch");
134 function check_db_has_customer_branches($msg)
136 global $path_to_root;
137 if (!db_has_customer_branches())
139 display_error($msg, true);
145 function db_has_sales_people()
147 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."salesman");
150 function check_db_has_sales_people($msg)
152 global $path_to_root;
153 if (!db_has_sales_people())
155 display_error($msg, true);
161 function db_has_sales_areas()
163 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."areas");
166 function check_db_has_sales_areas($msg)
168 global $path_to_root;
169 if (!db_has_sales_areas())
171 display_error($msg, true);
177 function db_has_shippers()
179 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."shippers");
182 function check_db_has_shippers($msg)
184 global $path_to_root;
185 if (!db_has_shippers())
187 display_error($msg, true);
193 function db_has_open_workorders()
195 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."workorders WHERE closed=0");
198 function db_has_workorders()
200 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."workorders");
203 function check_db_has_workorders($msg)
205 global $path_to_root;
206 if (!db_has_workorders())
208 display_error($msg, true);
214 function db_has_open_dimensions()
216 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."dimensions WHERE closed=0");
219 function db_has_dimensions()
221 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."dimensions");
224 function check_db_has_dimensions($msg)
226 global $path_to_root;
227 if (!db_has_dimensions())
229 display_error($msg, true);
236 function db_has_suppliers()
238 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."suppliers");
241 function check_db_has_suppliers($msg)
243 global $path_to_root;
244 if (!db_has_suppliers())
246 display_error($msg, true);
252 function db_has_stock_items()
254 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master");
257 function check_db_has_stock_items($msg)
259 global $path_to_root;
260 if (!db_has_stock_items())
262 display_error($msg, true);
268 function db_has_bom_stock_items()
270 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE (mb_flag='M' OR mb_flag='K')");
273 function check_db_has_bom_stock_items($msg)
275 global $path_to_root;
276 if (!db_has_bom_stock_items())
278 display_error($msg, true);
284 function db_has_manufacturable_items()
286 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE (mb_flag='M')");
289 function check_db_has_manufacturable_items($msg)
291 global $path_to_root;
292 if (!db_has_manufacturable_items())
294 display_error($msg, true);
300 function db_has_purchasable_items()
302 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE (mb_flag!='M' AND mb_flag!='K')");
305 function check_db_has_purchasable_items($msg)
307 global $path_to_root;
308 if (!db_has_purchasable_items())
310 display_error($msg, true);
316 function db_has_costable_items()
318 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE (mb_flag!='D' AND mb_flag!='K')");
321 function check_db_has_costable_items($msg)
323 global $path_to_root;
324 if (!db_has_costable_items())
326 display_error($msg, true);
332 function db_has_stock_categories()
334 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_category");
337 function check_db_has_stock_categories($msg)
339 global $path_to_root;
340 if (!db_has_stock_categories())
342 display_error($msg, true);
348 function db_has_workcentres()
350 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."workcentres");
353 function check_db_has_workcentres($msg)
355 global $path_to_root;
356 if (!db_has_workcentres())
358 display_error($msg, true);
364 function db_has_locations()
366 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."locations");
369 function check_db_has_locations($msg)
371 global $path_to_root;
372 if (!db_has_locations())
374 display_error($msg, true);
380 function db_has_bank_accounts()
382 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."bank_accounts");
385 function check_db_has_bank_accounts($msg)
387 global $path_to_root;
388 if (!db_has_bank_accounts())
390 display_error($msg, true);
396 function db_has_gl_accounts()
398 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."chart_master");
401 function db_has_gl_account_groups()
403 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."chart_types");
406 function check_db_has_gl_account_groups($msg)
408 global $path_to_root;
409 if (!db_has_gl_account_groups())
411 display_error($msg, true);
417 function db_has_quick_entries()
419 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."quick_entries");
422 function check_empty_result($sql)
424 $result = db_query($sql, "could not do check empty query");
426 $myrow = db_fetch_row($result);
427 return $myrow[0] > 0;
430 // Integer input check
431 // Return 1 if number has proper form and is within <min, max> range
433 function check_int($postname, $min=null, $max=null) {
434 if(!isset($_POST[$postname]))
436 $num = input_num($postname);
439 if (isset($min) && ($num<$min))
441 if (isset($max) && ($num>$max))
446 // Numeric input check.
447 // Return 1 if number has proper form and is within <min, max> range
449 function check_num($postname, $min=null, $max=null) {
450 if(!isset($_POST[$postname]))
452 $num = input_num($postname);
455 if (isset($min) && ($num<$min))
457 if (isset($max) && ($num>$max))