From: Joe Hunt Date: Sun, 27 Dec 2009 14:01:19 +0000 (+0000) Subject: Problems letting various currency bank accounts sharing the same GL account X-Git-Tag: 2.3-final~1070 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=55c4c020fa63775839cd5864b24c8c297f5ab27e;p=fa-stable.git Problems letting various currency bank accounts sharing the same GL account Rollback of bank_accounts.php --- diff --git a/CHANGELOG.txt b/CHANGELOG.txt index aca7c9d2..d62db57a 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -21,8 +21,8 @@ $ -> Affected files 27-Dec-2009 Joe Hunt # Problems letting various currency bank accounts sharing the same GL account - Foreign currency accounts must have their own specific GL accounts. $ /gl/manage/bank_accounts.php + /gl/includes/db/gl_db_banking.inc ------------------------------- Release 2.2.2 ---------------------------------- 23-Dec-2009 Joe Hunt diff --git a/gl/includes/db/gl_db_banking.inc b/gl/includes/db/gl_db_banking.inc index 84df6f9d..afc9e516 100644 --- a/gl/includes/db/gl_db_banking.inc +++ b/gl/includes/db/gl_db_banking.inc @@ -17,6 +17,7 @@ function add_exchange_variation($trans_type, $trans_no, $date_, $acc_id, $accoun if ($date_ == null) $date_ = Today(); $rate = get_exchange_rate_from_home_currency($currency, $date_); +/* $result = db_query("SELECT SUM(amount) FROM ".TB_PREF."bank_trans WHERE bank_act=".db_escape($acc_id)." AND trans_date<='".date2sql($date_)."'", "Transactions for account $account could not be calculated"); @@ -24,6 +25,16 @@ function add_exchange_variation($trans_type, $trans_no, $date_, $acc_id, $accoun $foreign_amount = $row[0]; $amount = get_gl_trans_from_to("", $date_, $account); $diff = $amount - (round2($foreign_amount * $rate, user_price_dec())); +*/ + $result = db_query("SELECT SUM(bt.amount) AS foreign_amount, SUM(gt.amount) AS amount + FROM ".TB_PREF."bank_trans bt, ".TB_PREF."gl_trans gt, ".TB_PREF."bank_accounts ba + WHERE bt.bank_act=".db_escape($acc_id)." AND bt.trans_date<='".date2sql($date_)."' + AND ((bt.amount > 0 AND gt.amount > 0) OR (bt.amount <= 0 AND gt.amount <= 0)) + AND bt.type = gt.type AND bt.trans_no = gt.type_no + AND ba.id = bt.bank_act AND ba.account_code = gt.account", + "Transactions for account $account could not be calculated"); + $row = db_fetch($result); + $diff = $row['amount'] - (round2($row['foreign_amount'] * $rate, user_price_dec())); if ($diff != 0) { if ($trans_type == null) @@ -102,7 +113,9 @@ function add_bank_transfer($from_account, $to_account, $date_, $date_, $amount, PT_MISC, "", $currency, "Cannot insert a destination bank transaction"); - add_exchange_variation($trans_type, $trans_no, $date_, $from_account, $from_gl_account, + $currency = get_bank_account_currency($to_account); + + add_exchange_variation($trans_type, $trans_no, $date_, $to_account, $to_gl_account, $currency, PT_MISC, ""); add_comments($trans_type, $trans_no, $date_, $memo_); diff --git a/gl/manage/bank_accounts.php b/gl/manage/bank_accounts.php index 09f07b04..ae1dc41e 100644 --- a/gl/manage/bank_accounts.php +++ b/gl/manage/bank_accounts.php @@ -25,21 +25,9 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') //initialise no input errors assumed initially before we test $input_error = 0; - $curr = get_company_currency(); - $sql = "SELECT account_code FROM ".TB_PREF."bank_accounts - WHERE account_code = '".$_POST['account_code']."'"; - if ($curr == $_POST['BankAccountCurrency']) - $sql .= " AND bank_curr_code <> '".$_POST['BankAccountCurrency']."'"; - $sql .= " AND id <> $selected_id"; - $result = db_query($sql,"could not get bank accounts"); - if (db_num_rows($result) > 0) - { - $input_error = 1; - display_error(_("The GL account is already in use.")); - set_focus('account_code'); - } + //first off validate inputs sensible - if ($input_error == 0 && strlen($_POST['bank_account_name']) == 0) + if (strlen($_POST['bank_account_name']) == 0) { $input_error = 1; display_error(_("The bank account name cannot be empty.")); @@ -202,10 +190,9 @@ else yesno_list_row(_("Default currency account:"), 'dflt_curr_act'); -$curr = get_company_currency(); -if ($is_editing && $curr == $_POST['BankAccountCurrency']) +if($is_editing) label_row(_("Bank Account GL Code:"), $_POST['account_code']); -else +else gl_all_accounts_list_row(_("Bank Account GL Code:"), 'account_code', null); text_row(_("Bank Name:"), 'bank_name', null, 50, 60);