0000593,0001093: Prepayments made against orders implemented.
[fa-stable.git] / includes / data_checks.inc
index 57f71e8f634ad1573ce17051c1962d0a46d3dfc7..cfb87a61e5c4d9c89c396431eab442b359dfa018 100644 (file)
@@ -1,13 +1,13 @@
 <?php
 /**********************************************************************
     Copyright (C) FrontAccounting, LLC.
-       Released under the terms of the GNU Affero General Public License,
-       AGPL, as published by the Free Software Foundation, either version 
-       of the License, or (at your option) any later version.
+       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/agpl-3.0.html>.
+    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
 function db_has_customers()
 {
@@ -123,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=".db_escape($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)
@@ -267,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)
@@ -299,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)
@@ -315,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)
@@ -385,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);
@@ -393,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");
@@ -419,12 +428,28 @@ 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=".db_escape($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");     
        
        $myrow = db_fetch_row($result);
-       return $myrow[0] > 0;           
+       return $myrow[0] > 0;
 }
 //
 //     Integer input check 
@@ -445,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;
@@ -459,5 +485,28 @@ function check_num($postname, $min=null, $max=null) {
     return 1;
 }
 
+function check_is_closed($type, $type_no, $msg=null)
+{
+       global $systypes_array;
+       
+    if (($type_no > 0) && is_closed_trans($type, $type_no))
+    {
+       if (!$msg)
+               $msg = sprintf(_("%s #%s is closed for further edition."), $systypes_array[$type], $type_no);
+       display_error($msg, true);
+       end_page();
+       exit;
+    }
+}
 
-?>
\ No newline at end of file
+function check_deferred_income_act($msg)
+{
+       global $path_to_root;
+
+    if (!get_company_pref('deferred_income_act')) 
+    {
+       display_error($msg, true);
+       end_page();
+       exit;
+    }
+}