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");
$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)
$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_);
//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."));
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);