X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fbanking.inc;h=cf532ea05ec95548da9b870edbe694c8fc4e1ec4;hb=8c893a568ed275b1695b2f4df8cfda131a997a64;hp=d26bbbbd7c4c5097ad8970b4914662c1690a4434;hpb=654b2cb832f5ad2313cfbbd98832681fae05943a;p=fa-stable.git diff --git a/includes/banking.inc b/includes/banking.inc index d26bbbbd..cf532ea0 100644 --- a/includes/banking.inc +++ b/includes/banking.inc @@ -1,15 +1,33 @@ . +***********************************************************************/ include_once($path_to_root . "/gl/includes/gl_db.inc"); //---------------------------------------------------------------------------------- - +// Check if given account is used by any bank_account. +// Returns id of first bank_account using account_code, null otherwise. +// +// Keep in mind that direct posting to bank account is depreciated +// because we have no way to select right bank account if +// there is more than one using given gl account. +// function is_bank_account($account_code) { - $sql= "SELECT account_code FROM ".TB_PREF."bank_accounts WHERE account_code='$account_code'"; - $result = db_query($sql, "retreive bank account currency"); - - return (db_num_rows($result) > 0); + $sql= "SELECT id FROM ".TB_PREF."bank_accounts WHERE account_code='$account_code'"; + $result = db_query($sql, "checking account is bank account"); + if (db_num_rows($result) > 0) { + $acct = db_fetch($result); + return $acct['id']; + } else + return false; } //---------------------------------------------------------------------------------- @@ -35,9 +53,9 @@ function get_company_currency() //---------------------------------------------------------------------------------- -function get_bank_account_currency($bankAccount) +function get_bank_account_currency($id) { - $sql= "SELECT bank_curr_code FROM ".TB_PREF."bank_accounts WHERE account_code='$bankAccount'"; + $sql= "SELECT bank_curr_code FROM ".TB_PREF."bank_accounts WHERE id='$id'"; $result = db_query($sql, "retreive bank account currency"); $myrow = db_fetch_row($result); @@ -85,7 +103,9 @@ function get_exchange_rate_from_home_currency($currency_code, $date_) if (db_num_rows($result) == 0) { // no stored exchange rate, just return 1 - display_error(_("Cannot retrieve currency exchange rate for this date. Please add exchange rate manually on Exchange Rates page.") ); + display_error( + sprintf(_("Cannot retrieve exchange rate for currency %s as of %s. Please add exchange rate manually on Exchange Rates page."), + $currency_code, $date_)); return 1.000; } @@ -105,7 +125,7 @@ function get_exchange_rate_to_home_currency($currency_code, $date_) function to_home_currency($amount, $currency_code, $date_) { $ex_rate = get_exchange_rate_to_home_currency($currency_code, $date_); - return round($amount / $ex_rate, user_price_dec()); + return round2($amount / $ex_rate, user_price_dec()); } //---------------------------------------------------------------------------------- @@ -151,6 +171,7 @@ function exchange_variation($pyt_type, $pyt_no, $type, $trans_no, $pyt_date, $am $ar_ap_act = $trans['receivables_account']; $person_id = $trans['debtor_no']; $curr = $trans['curr_code']; + $date = sql2date($trans['tran_date']); } else { @@ -160,11 +181,12 @@ function exchange_variation($pyt_type, $pyt_no, $type, $trans_no, $pyt_date, $am $ar_ap_act = $supp_accs['payable_account']; $person_id = $trans['supplier_id']; $curr = $trans['SupplierCurrCode']; + $date = sql2date($trans['tran_date']); } if (is_company_currency($curr)) return; - $inv_amt = round($amount * $trans['rate'], user_price_dec()); - $pay_amt = round($amount * $pyt_trans['rate'], user_price_dec()); + $inv_amt = round2($amount * $trans['rate'], user_price_dec()); + $pay_amt = round2($amount * $pyt_trans['rate'], user_price_dec()); if ($inv_amt != $pay_amt) { $diff = $inv_amt - $pay_amt; @@ -173,9 +195,18 @@ function exchange_variation($pyt_type, $pyt_no, $type, $trans_no, $pyt_date, $am if ($neg) $diff = -$diff; $exc_var_act = get_company_pref('exchange_diff_act'); - $memo = systypes::name($type)." ".$trans_no; - add_gl_trans($pyt_type, $pyt_no, $pyt_date, $ar_ap_act, 0, 0, $memo, -$diff, null, $person_type, $person_id); - add_gl_trans($pyt_type, $pyt_no, $pyt_date, $exc_var_act, 0, 0, $memo, $diff, null, $person_type, $person_id); + if (date1_greater_date2($date, $pyt_date)) + { + $memo = systypes::name($pyt_type)." ".$pyt_no; + add_gl_trans($type, $trans_no, $date, $ar_ap_act, 0, 0, $memo, -$diff, null, $person_type, $person_id); + add_gl_trans($type, $trans_no, $date, $exc_var_act, 0, 0, $memo, $diff, null, $person_type, $person_id); + } + else + { + $memo = systypes::name($type)." ".$trans_no; + add_gl_trans($pyt_type, $pyt_no, $pyt_date, $ar_ap_act, 0, 0, $memo, -$diff, null, $person_type, $person_id); + add_gl_trans($pyt_type, $pyt_no, $pyt_date, $exc_var_act, 0, 0, $memo, $diff, null, $person_type, $person_id); + } } }