private decimal GetCorporateExchangeRateFromDB(TDataBase databaseConnection, int pv_ledger_number_i, int pv_year_i, int pv_period_i, int currentFinancialYear) { ALedgerTable ledgerTable = ALedgerAccess.LoadByPrimaryKey(pv_ledger_number_i, databaseConnection.Transaction); AAccountingPeriodTable AccountingPeriodTable = AAccountingPeriodAccess.LoadByPrimaryKey(pv_ledger_number_i, pv_period_i, databaseConnection.Transaction); if (AccountingPeriodTable.Rows.Count < 1) { return(-1); // This is poor (because the caller can blindly use it!) // I wonder whether an exception would be better. (Tim Ingham, Oct 2013) } if (currentFinancialYear < 0) { currentFinancialYear = ledgerTable[0].CurrentFinancialYear; } DateTime startOfPeriod = AccountingPeriodTable[0].PeriodStartDate; DateTime endOfPeriod = AccountingPeriodTable[0].PeriodEndDate; startOfPeriod = new DateTime(startOfPeriod.Year - (currentFinancialYear - pv_year_i), startOfPeriod.Month, startOfPeriod.Day); if ((endOfPeriod.Month == 2) && (endOfPeriod.Day == 29) && (((currentFinancialYear - pv_year_i)) % 4 != 0)) { endOfPeriod = endOfPeriod.AddDays(-1); } endOfPeriod = new DateTime(endOfPeriod.Year - (currentFinancialYear - pv_year_i), endOfPeriod.Month, endOfPeriod.Day); // get the corporate exchange rate between base and intl currency for the period decimal IntlToBaseExchRate; TExchangeRateTools.GetCorporateExchangeRate(ledgerTable[0].IntlCurrency, ledgerTable[0].BaseCurrency, startOfPeriod, endOfPeriod, out IntlToBaseExchRate, databaseConnection); return(IntlToBaseExchRate); }
private ATransactionRow AddATransaction(string AAccount, string ACostCenter, string ANarrativeMessage, string AReferenceMessage, bool AIsDebit, decimal AAmountBaseCurrency, decimal AAmountForeignCurrency, bool ATransActionIsInForeign) { if (!blnReadyForTransaction) { EVerificationException terminate = new EVerificationException( Catalog.GetString("You have to add a journal before you can add a transaction!")); terminate.Context = "Common Accounting"; terminate.ErrorCode = "GL.CAT.06"; throw terminate; } if (AAccount.Trim().Length == 0) { throw new Exception("account code is empty"); } if (FForeignJournal) { if (ATransActionIsInForeign) { TAccountInfo accountCheck = new TAccountInfo(FLedgerInfo, AAccount); if (accountCheck.IsValid) { if (accountCheck.ForeignCurrencyFlag) { if (!accountCheck.ForeignCurrencyCode.Equals(this.FForeignCurrencyInfo.CurrencyCode)) { // This is a difficult error situation. Someone wants to account // JYP-Currencies on a GBP-account in an EUR ledger. string strMessage = Catalog.GetString("The ledger is defined in {0}, the account {1} is defined in " + "{2} and you want to account something in {3}?"); strMessage = String.Format(strMessage, FLedgerInfo.BaseCurrency, AAccount, accountCheck.ForeignCurrencyCode, FForeignCurrencyInfo.CurrencyCode); EVerificationException terminate = new EVerificationException(strMessage); terminate.Context = "Common Accounting"; terminate.ErrorCode = "GL.CAT.07"; throw terminate; } } } } } ATransactionRow transRow = null; transRow = FBatchTDS.ATransaction.NewRowTyped(); transRow.LedgerNumber = FJournalRow.LedgerNumber; transRow.BatchNumber = FJournalRow.BatchNumber; transRow.JournalNumber = FJournalRow.JournalNumber; transRow.TransactionNumber = ++FJournalRow.LastTransactionNumber; transRow.AccountCode = AAccount; transRow.CostCentreCode = ACostCenter; transRow.Narrative = ANarrativeMessage; transRow.Reference = AReferenceMessage; transRow.DebitCreditIndicator = AIsDebit; transRow.AmountInBaseCurrency = AAmountBaseCurrency; transRow.TransactionAmount = (ATransActionIsInForeign) ? AAmountForeignCurrency : AAmountBaseCurrency; // // The International currency calculation is changed to "Base -> International", because it's likely // we won't have a "Transaction -> International" conversion rate defined. // transRow.AmountInIntlCurrency = GLRoutines.Multiply(transRow.AmountInBaseCurrency, TExchangeRateTools.GetDailyExchangeRate( FLedgerInfo.BaseCurrency, FLedgerInfo.InternationalCurrency, transRow.TransactionDate)); transRow.TransactionDate = FBatchRow.DateEffective; FBatchTDS.ATransaction.Rows.Add(transRow); if (AIsDebit) { FJournalRow.JournalDebitTotal += AAmountBaseCurrency; } else { FJournalRow.JournalCreditTotal += AAmountBaseCurrency; } return(transRow); }