Moved page number, when more than 1 page, on documents down 2 lines.
[fa-stable.git] / taxes / db / tax_types_db.inc
index 71096f32743c72be92210ab39b03247a4aa344b1..a9325b60b10fd8b561beffc2ff19394e0e5da2d6 100644 (file)
@@ -29,7 +29,7 @@ function update_tax_type($type_id, $name, $sales_gl_code, $purchasing_gl_code, $
        db_query($sql, "could not update tax type");
 }
 
-function get_all_tax_types()
+function get_all_tax_types($all=false)
 {
        $sql = "SELECT ".TB_PREF."tax_types.*,
                Chart1.account_name AS SalesAccountName,
@@ -39,6 +39,7 @@ function get_all_tax_types()
                WHERE ".TB_PREF."tax_types.sales_gl_code = Chart1.account_code
                AND ".TB_PREF."tax_types.purchasing_gl_code = Chart2.account_code";
 
+       if (!$all) $sql .= " AND !".TB_PREF."tax_types.inactive";
        return db_query($sql, "could not get all tax types");
 }
 
@@ -82,7 +83,7 @@ function delete_tax_type($type_id)
        db_query($sql, "could not delete tax type");
 
        // also delete any item tax exemptions associated with this type
-       $sql = "DELETE FROM ".TB_PREF."item_tax_type_exemptions WHERE tax_type_id=$type_id";
+       $sql = "DELETE FROM ".TB_PREF."item_tax_type_exemptions WHERE tax_type_id=".db_escape($type_id);
 
        db_query($sql, "could not delete item tax type exemptions");
 
@@ -112,4 +113,18 @@ function is_tax_gl_unique($gl_code, $gl_code2=-1, $selected_id=-1) {
 
        return $gl_code2 == -1 ? ($row[0] <= 1) : ($row[0] == 0);
 }
-?>
\ No newline at end of file
+
+function is_tax_account($account_code)
+{
+       $sql= "SELECT id FROM ".TB_PREF."tax_types WHERE 
+               sales_gl_code=".db_escape($account_code)." OR purchasing_gl_code=".db_escape($account_code);
+       $result = db_query($sql, "checking account is tax account");
+       if (db_num_rows($result) > 0) {
+               $acct = db_fetch($result);
+               return $acct['id'];
+       } else
+               return false;
+}
+
+
+?>