3 //----------------------------------------------------------------------------------
5 // add a bank transaction
6 // $amount is in $currency
7 // $date_ is display date (non-sql)
9 function add_bank_trans($type, $trans_no, $bank_act, $ref, $date_, $bank_trans_type_id,
10 $amount, $person_type_id, $person_id, $currency="", $err_msg="")
12 $sqlDate = date2sql($date_);
14 // convert $amount to the bank's currency
17 $bank_account_currency = get_bank_account_currency($bank_act);
18 $to_bank_currency = get_exchange_rate_from_to($currency, $bank_account_currency, $date_);
19 $amount_bank = ($amount / $to_bank_currency);
22 $amount_bank = $amount;
25 // Also store the rate to the home
26 //$BankToHomeCurrencyRate = get_exchange_rate_to_home_currency($bank_account_currency, $date_);
28 $sql = "INSERT INTO ".TB_PREF."bank_trans (type, trans_no, bank_act, ref,
29 trans_date, bank_trans_type_id, amount, person_type_id, person_id) ";
31 $sql .= "VALUES ($type, $trans_no, $bank_act, '$ref', '$sqlDate', '$bank_trans_type_id',
32 $amount_bank, $person_type_id, '$person_id')";
35 $err_msg = "The bank transaction could not be inserted";
37 db_query($sql, $err_msg);
40 //----------------------------------------------------------------------------------------
42 function exists_bank_trans($type, $type_no)
44 $sql = "SELECT trans_no FROM ".TB_PREF."bank_trans WHERE type=$type
45 AND trans_no=$type_no";
46 $result = db_query($sql, "Cannot retreive a bank transaction");
48 return (db_num_rows($result) > 0);
51 //----------------------------------------------------------------------------------------
53 function get_bank_trans($type, $trans_no=null, $person_type_id=null, $person_id=null)
55 $sql = "SELECT *, bank_account_name, account_code, bank_curr_code, name AS BankTransType
56 FROM ".TB_PREF."bank_trans, ".TB_PREF."bank_accounts, ".TB_PREF."bank_trans_types
57 WHERE ".TB_PREF."bank_trans_types.id = ".TB_PREF."bank_trans.bank_trans_type_id
58 AND ".TB_PREF."bank_accounts.account_code=".TB_PREF."bank_trans.bank_act ";
60 $sql .= " AND type=$type ";
61 if ($trans_no != null)
62 $sql .= " AND ".TB_PREF."bank_trans.trans_no = $trans_no ";
63 if ($person_type_id != null)
64 $sql .= " AND ".TB_PREF."bank_trans.person_type_id = $person_type_id ";
65 if ($person_id != null)
66 $sql .= " AND ".TB_PREF."bank_trans.person_id = '$person_id'";
67 $sql .= " ORDER BY trans_date, ".TB_PREF."bank_trans.id";
69 return db_query($sql, "query for bank transaction");
72 //----------------------------------------------------------------------------------------
74 function get_gl_trans_value($account, $type, $trans_no)
76 $sql = "SELECT SUM(amount) FROM ".TB_PREF."gl_trans WHERE account=$account AND type=$type AND type_no=$trans_no";
78 $result = db_query($sql, "query for gl trans value");
80 $row = db_fetch_row($result);
84 //----------------------------------------------------------------------------------------
86 function void_bank_trans($type, $type_no, $nested=false)
91 $sql = "UPDATE ".TB_PREF."bank_trans SET amount=0
92 WHERE type=$type AND trans_no=$type_no";
94 $result = db_query($sql, "could not void bank transactions for type=$type and trans_no=$type_no");
96 void_gl_trans($type, $type_no, true);
98 // in case it's a customer trans - probably better to check first
99 void_cust_allocations($type, $type_no);
100 void_customer_trans($type, $type_no);
102 // in case it's a supplier trans - probably better to check first
103 void_supp_allocations($type, $type_no);
104 void_supp_trans($type, $type_no);
107 commit_transaction();
110 //----------------------------------------------------------------------------------