Esempio n. 1
0
        public void GetRateForDate()
        {
            // First test is with empty data
            FMainDS.LoadAll();
            FMainDS.DeleteAllRows();
            FMainDS.SaveChanges();
            FLedgerDS.CreateTestLedger();

            // define our working date range
            DateTime dtStart = new DateTime(2000, 01, 01);
            DateTime dtEnd = new DateTime(2000, 12, 31);

            // First test is with empty data - should return 1.0m
            TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null);
            decimal result = mainScreen.GetLastExchangeValueOfInterval(STANDARD_TEST_LEDGER_NUMBER, dtStart, dtEnd, "GBP");
            Assert.AreEqual(1.0m, result, "The result should be 1.0m when the table contains no data");

            // Repeat test with data but outside the date range - again should return 1.0m
            FMainDS.InsertStandardModalRows();
            FMainDS.SaveChanges();

            mainScreen = new TFrmSetupDailyExchangeRate(null);
            result = mainScreen.GetLastExchangeValueOfInterval(STANDARD_TEST_LEDGER_NUMBER, dtStart, dtEnd, "GBP");
            Assert.AreEqual(1.0m, result, "The result should be 1.0m because there is no data in the date range");

            // Repeat again with data inside the range
            FMainDS.AddARow("GBP", STANDARD_TEST_CURRENCY, new DateTime(2000, 6, 1), 2.0m);
            FMainDS.AddARow("GBP", STANDARD_TEST_CURRENCY, new DateTime(2000, 6, 10), 2.05m);
            FMainDS.AddARow("GBP", STANDARD_TEST_CURRENCY, new DateTime(2000, 6, 30), 2.15m);           // This is the latest
            FMainDS.AddARow("GBP", STANDARD_TEST_CURRENCY, new DateTime(2000, 6, 20), 2.10m);
            FMainDS.SaveChanges();

            mainScreen = new TFrmSetupDailyExchangeRate(null);
            result = mainScreen.GetLastExchangeValueOfInterval(STANDARD_TEST_LEDGER_NUMBER, dtStart, dtEnd, "GBP");
            Assert.AreEqual(2.15m, result);
        }
        private String GetListOfRevaluationCurrencies()
        {
            TFrmSetupDailyExchangeRate frmExchangeRate =
                new TFrmSetupDailyExchangeRate(this);

            DataTable table = TDataCache.TMFinance.GetCacheableFinanceTable(
                TCacheableFinanceTablesEnum.AccountList, FLedgerNumber);

            int ic = 0;
            String strRevaluationCurrencies = "";

            foreach (DataRow row in table.Rows)
            {
                bool blnIsLedger = (FLedgerNumber == (int)row["a_ledger_number_i"]);
                bool blnAccountActive = (bool)row["a_account_active_flag_l"];
                bool blnAccountForeign = (bool)row["a_foreign_currency_flag_l"];
                bool blnAccountHasPostings = (bool)row["a_posting_status_l"];

                if (blnIsLedger && blnAccountActive
                    && blnAccountForeign && blnAccountHasPostings)
                {
                    if (strRevaluationCurrencies == "")
                    {
                        strRevaluationCurrencies =
                            "[" + (string)row["a_foreign_currency_code_c"];
                    }
                    else
                    {
                        strRevaluationCurrencies = strRevaluationCurrencies +
                                                   "|" + (string)row["a_foreign_currency_code_c"];
                    }

                    string strCurrencyCode = (string)row["a_foreign_currency_code_c"];
                    decimal decExchangeRate = frmExchangeRate.GetLastExchangeValueOfInterval(FLedgerNumber,
                        FperiodStart, FperiodEnd, strCurrencyCode);
                    AddADataRow(ic, strCurrencyCode, decExchangeRate);
                    ++ic;
                }
            }

            if (strRevaluationCurrencies != "")
            {
                strRevaluationCurrencies = strRevaluationCurrencies + "]";
            }

            return strRevaluationCurrencies;
        }