Problems letting various currency bank accounts sharing the same GL account
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Sun, 27 Dec 2009 14:01:19 +0000 (14:01 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Sun, 27 Dec 2009 14:01:19 +0000 (14:01 +0000)
Rollback of bank_accounts.php

CHANGELOG.txt
gl/includes/db/gl_db_banking.inc
gl/manage/bank_accounts.php

index aca7c9d2683dc267c2d94f879a15f17cedc2fba1..d62db57a8817503367a0d2de3072018be7d665a3 100644 (file)
@@ -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
index 84df6f9d2a53ab1866b08759de5b3cc344a0ffc3..afc9e516ccdad66570c4dd028863e230eb8e9353 100644 (file)
@@ -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_);
index 09f07b04b91121b9d1f1d9409ceca0f77c01316c..ae1dc41e6f8cc7e924b4a1bc0ef88397afa17286 100644 (file)
@@ -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);