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 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 "
127 ."WHERE debtor_no='$customer_id'");
130 function db_has_customer_branches()
132 return check_empty_result("SELECT COUNT(*) FROM "
133 .TB_PREF."cust_branch WHERE !inactive");
136 function check_db_has_customer_branches($msg)
138 global $path_to_root;
139 if (!db_has_customer_branches())
141 display_error($msg, true);
147 function db_has_sales_people()
149 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."salesman");
152 function check_db_has_sales_people($msg)
154 global $path_to_root;
155 if (!db_has_sales_people())
157 display_error($msg, true);
163 function db_has_sales_areas()
165 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."areas");
168 function check_db_has_sales_areas($msg)
170 global $path_to_root;
171 if (!db_has_sales_areas())
173 display_error($msg, true);
179 function db_has_shippers()
181 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."shippers");
184 function check_db_has_shippers($msg)
186 global $path_to_root;
187 if (!db_has_shippers())
189 display_error($msg, true);
195 function db_has_open_workorders()
197 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."workorders WHERE closed=0");
200 function db_has_workorders()
202 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."workorders");
205 function check_db_has_workorders($msg)
207 global $path_to_root;
208 if (!db_has_workorders())
210 display_error($msg, true);
216 function db_has_open_dimensions()
218 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."dimensions WHERE closed=0");
221 function db_has_dimensions()
223 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."dimensions");
226 function check_db_has_dimensions($msg)
228 global $path_to_root;
229 if (!db_has_dimensions())
231 display_error($msg, true);
238 function db_has_suppliers()
240 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."suppliers");
243 function check_db_has_suppliers($msg)
245 global $path_to_root;
246 if (!db_has_suppliers())
248 display_error($msg, true);
254 function db_has_stock_items()
256 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master");
259 function check_db_has_stock_items($msg)
261 global $path_to_root;
262 if (!db_has_stock_items())
264 display_error($msg, true);
270 function db_has_bom_stock_items()
272 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE mb_flag='M'");
275 function check_db_has_bom_stock_items($msg)
277 global $path_to_root;
278 if (!db_has_bom_stock_items())
280 display_error($msg, true);
286 function db_has_manufacturable_items()
288 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE (mb_flag='M')");
291 function check_db_has_manufacturable_items($msg)
293 global $path_to_root;
294 if (!db_has_manufacturable_items())
296 display_error($msg, true);
302 function db_has_purchasable_items()
304 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE mb_flag!='M'");
307 function check_db_has_purchasable_items($msg)
309 global $path_to_root;
310 if (!db_has_purchasable_items())
312 display_error($msg, true);
318 function db_has_costable_items()
320 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE mb_flag!='D'");
323 function check_db_has_costable_items($msg)
325 global $path_to_root;
326 if (!db_has_costable_items())
328 display_error($msg, true);
334 function db_has_stock_categories()
336 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_category");
339 function check_db_has_stock_categories($msg)
341 global $path_to_root;
342 if (!db_has_stock_categories())
344 display_error($msg, true);
350 function db_has_workcentres()
352 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."workcentres");
355 function check_db_has_workcentres($msg)
357 global $path_to_root;
358 if (!db_has_workcentres())
360 display_error($msg, true);
366 function db_has_locations()
368 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."locations");
371 function check_db_has_locations($msg)
373 global $path_to_root;
374 if (!db_has_locations())
376 display_error($msg, true);
382 function db_has_bank_accounts()
384 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."bank_accounts");
387 function check_db_has_bank_accounts($msg)
389 global $path_to_root;
391 if (!db_has_bank_accounts())
393 display_error($msg, true);
399 function db_has_cash_accounts()
401 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."bank_accounts
402 WHERE account_type=3");
405 function db_has_gl_accounts()
407 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."chart_master");
410 function db_has_gl_account_groups()
412 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."chart_types");
415 function check_db_has_gl_account_groups($msg)
417 global $path_to_root;
418 if (!db_has_gl_account_groups())
420 display_error($msg, true);
426 function db_has_quick_entries()
428 return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."quick_entries");
431 function check_empty_result($sql)
433 $result = db_query($sql, "could not do check empty query");
435 $myrow = db_fetch_row($result);
436 return $myrow[0] > 0;
439 // Integer input check
440 // Return 1 if number has proper form and is within <min, max> range
442 function check_int($postname, $min=null, $max=null) {
443 if(!isset($_POST[$postname]))
445 $num = input_num($postname);
448 if (isset($min) && ($num<$min))
450 if (isset($max) && ($num>$max))
455 // Numeric input check.
456 // Return 1 if number has proper form and is within <min, max> range
458 function check_num($postname, $min=null, $max=null) {
459 if(!isset($_POST[$postname]))
461 $num = input_num($postname);
464 if (isset($min) && ($num<$min))
466 if (isset($max) && ($num>$max))