+function get_default_bank_account($curr)
+{
+ /* default bank account is selected as first found account from:
+ . default account in $curr if any
+ . first defined account in $curr if any
+ . default account in home currency
+ . first defined account in home currency
+ */
+ $home_curr = get_company_pref('curr_default');
+
+ $sql = "SELECT b.*, b.bank_curr_code='$home_curr' as fall_back FROM "
+ .TB_PREF."bank_accounts b"
+ ." WHERE b.bank_curr_code=".db_escape($curr)
+ ." OR b.bank_curr_code='$home_curr'
+ ORDER BY fall_back, dflt_curr_act desc";
+
+ $result = db_query($sql, "could not retreive default bank account");
+
+ return db_fetch($result);
+}