Fixed mysqli related warnings.
[fa-stable.git] / gl / includes / db / gl_db_accounts.inc
index 3cddd5e9a1227728e4208c31815c573d1e42cb00..25bc84fce7e6b058e500eb450c2d97c1d0c2cd57 100644 (file)
@@ -96,6 +96,7 @@ function gl_account_in_company_defaults($acc)
                OR name='profit_loss_year_act'
                OR name='retained_earnings_act'
                OR name='freight_act'
+               OR name='deferred_income_act'
                OR name='default_sales_act' 
                OR name='default_sales_discount_act'
                OR name='default_prompt_payment_act'
@@ -205,6 +206,18 @@ function is_subledger_account($account)
        return $myrow[0];
 }
 
+function get_subaccount_data($code_id, $person_id)
+{
+       $sql = "SELECT debtor_ref as name, branch_code as id 
+               FROM ".TB_PREF."cust_branch branch LEFT JOIN ".TB_PREF."debtors_master d ON branch.debtor_no = d.debtor_no
+               WHERE branch.receivables_account=".db_escape($code_id)." AND d.debtor_no=".db_escape($person_id)
+               ." UNION SELECT supp_ref as name, '' as id FROM ".TB_PREF."suppliers supp
+               WHERE supplier_id=".db_escape($person_id)." AND payable_account=".db_escape($code_id);
+       $result = db_query($sql, 'cannot retrieve counterparty name');
+
+       return  db_fetch($result);
+}
+
 function get_subaccount_name($code_id, $person_id)
 {
        $sql = "SELECT debtor_ref as ref FROM ".TB_PREF."cust_branch branch LEFT JOIN ".TB_PREF."debtors_master d ON branch.debtor_no = d.debtor_no
@@ -226,4 +239,22 @@ function gl_account_in_bank_accounts($acc)
        $myrow = db_fetch_row($result);
        return ($myrow[0] > 0); 
 }
-?>
\ No newline at end of file
+
+//----------------------------------------------------------------------------------
+//     Check if given account is used by any bank_account. 
+//     Returns id of first bank_account using account_code, null otherwise.
+//
+//     Keep in mind that direct posting to bank account is depreciated
+//     because we have no way to select right bank account if 
+//     there is more than one using given gl account.
+//
+function is_bank_account($account_code)
+{
+       $sql= "SELECT id FROM ".TB_PREF."bank_accounts WHERE account_code=".db_escape($account_code);
+       $result = db_query($sql, "checking account is bank account");
+       if (db_num_rows($result) > 0) {
+               $acct = db_fetch($result);
+               return $acct['id'];
+       } else
+               return false;
+}