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_,
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, amount, person_type_id, person_id) ";
31 $sql .= "VALUES ($type, $trans_no, '$bank_act', ".db_escape($ref).", '$sqlDate',
32 $amount_bank, $person_type_id, ". db_escape($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
56 FROM ".TB_PREF."bank_trans, ".TB_PREF."bank_accounts
57 WHERE ".TB_PREF."bank_accounts.id=".TB_PREF."bank_trans.bank_act ";
59 $sql .= " AND type=$type ";
60 if ($trans_no != null)
61 $sql .= " AND ".TB_PREF."bank_trans.trans_no = $trans_no ";
62 if ($person_type_id != null)
63 $sql .= " AND ".TB_PREF."bank_trans.person_type_id = $person_type_id ";
64 if ($person_id != null)
65 $sql .= " AND ".TB_PREF."bank_trans.person_id = '$person_id'";
66 $sql .= " ORDER BY trans_date, ".TB_PREF."bank_trans.id";
68 return db_query($sql, "query for bank transaction");
71 //----------------------------------------------------------------------------------------
73 function get_gl_trans_value($account, $type, $trans_no)
75 $sql = "SELECT SUM(amount) FROM ".TB_PREF."gl_trans WHERE account='$account' AND type=$type AND type_no=$trans_no";
77 $result = db_query($sql, "query for gl trans value");
79 $row = db_fetch_row($result);
83 //----------------------------------------------------------------------------------------
85 function void_bank_trans($type, $type_no, $nested=false)
90 $sql = "UPDATE ".TB_PREF."bank_trans SET amount=0
91 WHERE type=$type AND trans_no=$type_no";
93 $result = db_query($sql, "could not void bank transactions for type=$type and trans_no=$type_no");
95 void_gl_trans($type, $type_no, true);
97 // in case it's a customer trans - probably better to check first
98 void_cust_allocations($type, $type_no);
99 void_customer_trans($type, $type_no);
101 // in case it's a supplier trans - probably better to check first
102 void_supp_allocations($type, $type_no);
103 void_supp_trans($type, $type_no);
106 commit_transaction();
109 //----------------------------------------------------------------------------------