Added css parameter in page()
[fa-stable.git] / includes / data_checks.inc
index 0b94f9328723b49f80317879c8cfa5c2b919285d..ff316953030d9c322fea21c2a7e3aced11717340 100644 (file)
@@ -1,4 +1,14 @@
 <?php
+/**********************************************************************
+    Copyright (C) FrontAccounting, LLC.
+       Released under the terms of the GNU General Public License, GPL, 
+       as published by the Free Software Foundation, either version 3 
+       of the License, or (at your option) any later version.
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
+***********************************************************************/
 function db_has_customers()
 {
        return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."debtors_master");
@@ -113,12 +123,14 @@ function check_db_has_movement_types($msg)
 
 function db_customer_has_branches($customer_id)
 {
-       return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."cust_branch WHERE debtor_no='$customer_id'");
+       return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."cust_branch "
+               ."WHERE debtor_no='$customer_id'");
 }
 
 function db_has_customer_branches()
 {
-       return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."cust_branch");
+       return check_empty_result("SELECT COUNT(*) FROM "
+               .TB_PREF."cust_branch WHERE !inactive");
 }
 
 function check_db_has_customer_branches($msg)
@@ -257,7 +269,7 @@ function check_db_has_stock_items($msg)
 
 function db_has_bom_stock_items()
 {
-       return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE (mb_flag='M' OR mb_flag='K')");
+       return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE mb_flag='M'");
 }
 
 function check_db_has_bom_stock_items($msg)
@@ -289,7 +301,7 @@ function check_db_has_manufacturable_items($msg)
 
 function db_has_purchasable_items()
 {
-       return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE (mb_flag!='M' AND mb_flag!='K')");
+       return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE mb_flag!='M'");
 }
 
 function check_db_has_purchasable_items($msg)
@@ -305,7 +317,7 @@ function check_db_has_purchasable_items($msg)
 
 function db_has_costable_items()
 {
-       return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE (mb_flag!='D' AND mb_flag!='K')");
+       return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE mb_flag!='D'");
 }
 
 function check_db_has_costable_items($msg)
@@ -375,6 +387,7 @@ function db_has_bank_accounts()
 function check_db_has_bank_accounts($msg)
 {
        global $path_to_root;
+
     if (!db_has_bank_accounts()) 
     {
        display_error($msg, true);
@@ -383,6 +396,12 @@ function check_db_has_bank_accounts($msg)
     }  
 }
 
+function db_has_cash_accounts()
+{
+       return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."bank_accounts
+               WHERE account_type=3");
+}
+
 function db_has_gl_accounts()
 {
        return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."chart_master");
@@ -409,6 +428,22 @@ function db_has_quick_entries()
        return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."quick_entries");
 }
 
+function db_has_tags($type)
+{
+       return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."tags WHERE type=$type");
+}
+
+function check_db_has_tags($type, $msg)
+{
+       global $path_to_root;
+    if (!db_has_tags($type)) 
+    {
+       display_error($msg, true);
+       end_page();
+       exit;   
+    }  
+}
+
 function check_empty_result($sql)
 {
        $result = db_query($sql, "could not do check empty query");     
@@ -435,12 +470,13 @@ function check_int($postname, $min=null, $max=null) {
 //
 //     Numeric input check.
 //     Return 1 if number has proper form and is within <min, max> range
+//     Empty/not defined fields are defaulted to $dflt value.
 //
-function check_num($postname, $min=null, $max=null) {
+function check_num($postname, $min=null, $max=null, $dflt=0) {
        if(!isset($_POST[$postname]))
          return 0;
-    $num = input_num($postname);
-    if ($num === false) 
+    $num = input_num($postname, $dflt);
+    if ($num === false || $num === null
          return 0;
     if (isset($min) && ($num<$min)) 
          return 0;