public static BudgetTDS LoadBudgetForAutoGenerate(Int32 ALedgerNumber) { TDBTransaction Transaction = null; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, ref Transaction, delegate { //TODO: need to filter on Year ABudgetAccess.LoadViaALedger(FMainDS, ALedgerNumber, Transaction); ABudgetRevisionAccess.LoadViaALedger(FMainDS, ALedgerNumber, Transaction); //TODO: need to filter on ABudgetPeriod using LoadViaBudget or LoadViaUniqueKey ABudgetPeriodAccess.LoadAll(FMainDS, Transaction); ALedgerAccess.LoadByPrimaryKey(FMainDS, ALedgerNumber, Transaction); ABudgetTypeAccess.LoadAll(FMainDS, Transaction); }); // Accept row changes here so that the Client gets 'unmodified' rows FMainDS.AcceptChanges(); // Remove all Tables that were not filled with data before remoting them. FMainDS.RemoveEmptyTables(); return(FMainDS); }
private static Int32 FindFinancialYearByDate(Int32 ALedgerNumber, DateTime ADate) { Int32 yearDateBelongsTo = 99; DateTime yearStartDate = DateTime.Today; TDBTransaction transaction = null; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.Serializable, ref transaction, delegate { ALedgerTable LedgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, transaction); if (LedgerTable.Count == 0) { return; } ALedgerRow LedgerRow = (ALedgerRow)LedgerTable.Rows[0]; yearDateBelongsTo = LedgerRow.CurrentFinancialYear; AAccountingPeriodTable AccPeriodTable = AAccountingPeriodAccess.LoadViaALedger(ALedgerNumber, transaction); if (AccPeriodTable.Count == 0) { return; } //Find earliest start date (don't assume PK order) AAccountingPeriodRow AccPeriodRow = null; for (int i = 0; i < AccPeriodTable.Count; i++) { DateTime currentStartDate; AccPeriodRow = (AAccountingPeriodRow)AccPeriodTable.Rows[i]; currentStartDate = AccPeriodRow.PeriodStartDate; if (i > 0) { if (yearStartDate > currentStartDate) { yearStartDate = currentStartDate; } } else { yearStartDate = currentStartDate; } } //Find the correct year while (ADate < yearStartDate) { ADate = ADate.AddYears(1); yearDateBelongsTo--; } }); // Get NewOrExisting AutoReadTransaction //Set the year to return return(yearDateBelongsTo); } // Find FinancialYear ByDate
public static bool GetAccountingYearPeriodByDate(Int32 ALedgerNumber, DateTime ADate, out Int32 AYearNumber, out Int32 APeriodNumber) { bool newTransaction; Int32 CurrentFinancialYear; //Set the year to return AYearNumber = FindFinancialYearByDate(ALedgerNumber, ADate); if (AYearNumber == 99) { AYearNumber = 0; APeriodNumber = 0; return(false); } TDBTransaction Transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.Serializable, out newTransaction); ALedgerTable LedgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, Transaction); CurrentFinancialYear = ((ALedgerRow)LedgerTable.Rows[0]).CurrentFinancialYear; AAccountingPeriodTable AccPeriodTableTmp = new AAccountingPeriodTable(); AAccountingPeriodRow TemplateRow = AccPeriodTableTmp.NewRowTyped(false); TemplateRow.LedgerNumber = ALedgerNumber; TemplateRow.PeriodStartDate = ADate.AddYears(CurrentFinancialYear - AYearNumber); TemplateRow.PeriodEndDate = ADate.AddYears(CurrentFinancialYear - AYearNumber); StringCollection operators = StringHelper.InitStrArr(new string[] { "=", "<=", ">=" }); AAccountingPeriodTable AccountingPeriodTable = AAccountingPeriodAccess.LoadUsingTemplate(TemplateRow, operators, null, Transaction); if ((AccountingPeriodTable == null) || (AccountingPeriodTable.Count == 0)) { if (newTransaction) { DBAccess.GDBAccessObj.RollbackTransaction(); } APeriodNumber = 0; return(false); } AAccountingPeriodRow AccountingPeriodRow = (AAccountingPeriodRow)AccountingPeriodTable.Rows[0]; APeriodNumber = AccountingPeriodRow.AccountingPeriodNumber; if (newTransaction) { DBAccess.GDBAccessObj.RollbackTransaction(); } return(true); }
public static GiftBatchTDS LoadMotivationDetails(Int32 ALedgerNumber, string AMotivationGroupCode) { GiftBatchTDS MainDS = new GiftBatchTDS(); TDBTransaction Transaction = new TDBTransaction(); TDataBase db = DBAccess.Connect("LoadMotivationDetails"); db.ReadTransaction( ref Transaction, delegate { ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction); if (AMotivationGroupCode.Length > 0) { AMotivationGroupAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, AMotivationGroupCode, Transaction); AMotivationDetailAccess.LoadViaAMotivationGroup(MainDS, ALedgerNumber, AMotivationGroupCode, Transaction); } else { AMotivationGroupAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction); AMotivationDetailAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction); } AMotivationDetailFeeAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction); }); // Accept row changes here so that the Client gets 'unmodified' rows MainDS.AcceptChanges(); // Remove all Tables that were not filled with data before remoting them. MainDS.RemoveEmptyTables(); return(MainDS); }
public static Boolean GetCurrentPeriodDates(Int32 ALedgerNumber, out DateTime AStartDateCurrentPeriod, out DateTime AEndDateCurrentPeriod) { DateTime startDate = new DateTime(); DateTime endDate = new DateTime(); TDBTransaction Transaction = new TDBTransaction(); TDataBase db = DBAccess.Connect("GetCurrentPeriodDates"); db.ReadTransaction( ref Transaction, delegate { ALedgerTable ledgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, Transaction); AAccountingPeriodTable accountingPeriodTable = AAccountingPeriodAccess.LoadByPrimaryKey(ALedgerNumber, ledgerTable[0].CurrentPeriod, Transaction); startDate = accountingPeriodTable[0].PeriodStartDate; endDate = accountingPeriodTable[0].PeriodEndDate; }); db.CloseDBConnection(); AStartDateCurrentPeriod = startDate; AEndDateCurrentPeriod = endDate; return(true); }
public static Boolean GetCurrentPostingRangeDates(Int32 ALedgerNumber, out DateTime AStartDateCurrentPeriod, out DateTime AEndDateLastForwardingPeriod) { DateTime StartDateCurrentPeriod = new DateTime(); DateTime EndDateLastForwardingPeriod = new DateTime(); TDBTransaction Transaction = null; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, ref Transaction, delegate { ALedgerTable LedgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, Transaction); AAccountingPeriodTable AccountingPeriodTable = AAccountingPeriodAccess.LoadByPrimaryKey(ALedgerNumber, LedgerTable[0].CurrentPeriod, Transaction); StartDateCurrentPeriod = AccountingPeriodTable[0].PeriodStartDate; AccountingPeriodTable = AAccountingPeriodAccess.LoadByPrimaryKey(ALedgerNumber, LedgerTable[0].CurrentPeriod + LedgerTable[0].NumberFwdPostingPeriods, Transaction); EndDateLastForwardingPeriod = AccountingPeriodTable[0].PeriodEndDate; }); AStartDateCurrentPeriod = StartDateCurrentPeriod; AEndDateLastForwardingPeriod = EndDateLastForwardingPeriod; return(true); }
public static Boolean GetCurrentPeriodDates(Int32 ALedgerNumber, out DateTime AStartDateCurrentPeriod, out DateTime AEndDateCurrentPeriod) { DateTime startDate = new DateTime(); DateTime endDate = new DateTime(); TDBTransaction Transaction = null; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, ref Transaction, delegate { ALedgerTable ledgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, Transaction); AAccountingPeriodTable accountingPeriodTable = AAccountingPeriodAccess.LoadByPrimaryKey(ALedgerNumber, ledgerTable[0].CurrentPeriod, Transaction); startDate = accountingPeriodTable[0].PeriodStartDate; endDate = accountingPeriodTable[0].PeriodEndDate; }); AStartDateCurrentPeriod = startDate; AEndDateCurrentPeriod = endDate; return(true); }
public static GiftBatchTDS LoadMotivationDetails(Int32 ALedgerNumber) { GiftBatchTDS MainDS = new GiftBatchTDS(); TDBTransaction Transaction = null; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, ref Transaction, delegate { ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction); AMotivationGroupAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction); AMotivationDetailAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction); AMotivationDetailFeeAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction); }); // Accept row changes here so that the Client gets 'unmodified' rows MainDS.AcceptChanges(); // Remove all Tables that were not filled with data before remoting them. MainDS.RemoveEmptyTables(); return(MainDS); }
public static BudgetTDS LoadBudget(Int32 ALedgerNumber) { BudgetTDS MainDS = new BudgetTDS(); TDBTransaction Transaction = null; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, ref Transaction, delegate { //TODO: need to filter on Year ABudgetAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction); ABudgetRevisionAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction); //TODO: need to filter on ABudgetPeriod using LoadViaBudget or LoadViaUniqueKey ABudgetPeriodAccess.LoadAll(MainDS, Transaction); ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction); // ABudgetPeriodTable BudgetPeriodTable = new ABudgetPeriodTable(); // ABudgetPeriodRow TemplateRow = (ABudgetPeriodRow)BudgetPeriodTable.NewRow(false); // // TemplateRow.BudgetSequence; // ABudgetPeriodAccess.LoadViaABudgetTemplate(MainDS, TemplateRow, Transaction); }); // Accept row changes here so that the Client gets 'unmodified' rows MainDS.AcceptChanges(); // Remove all Tables that were not filled with data before remoting them. MainDS.RemoveEmptyTables(); return(MainDS); }
public static bool GetCurrentPostingRangeDates(Int32 ALedgerNumber, out DateTime AStartDateCurrentPeriod, out DateTime AEndDateLastForwardingPeriod) { bool newTransaction = false; TDBTransaction Transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.Serializable, out newTransaction); ALedgerTable LedgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, Transaction); AAccountingPeriodTable AccountingPeriodTable = AAccountingPeriodAccess.LoadByPrimaryKey(ALedgerNumber, LedgerTable[0].CurrentPeriod, Transaction); AStartDateCurrentPeriod = AccountingPeriodTable[0].PeriodStartDate; AccountingPeriodTable = AAccountingPeriodAccess.LoadByPrimaryKey(ALedgerNumber, LedgerTable[0].CurrentPeriod + LedgerTable[0].NumberFwdPostingPeriods, Transaction); AEndDateLastForwardingPeriod = AccountingPeriodTable[0].PeriodEndDate; if (newTransaction) { DBAccess.GDBAccessObj.RollbackTransaction(); } return(true); }
private void GetLedgerInfo(out DateTime APeriodStartDate, out DateTime APeriodEndDate, out string AForexGainsLossesAccount, TDataBase ADataBase) { ALedgerTable LedgerTable = null; TDataBase db = DBAccess.Connect("GetLedgerInfo", ADataBase); TDBTransaction Transaction = new TDBTransaction(); DateTime PeriodStartDate = DateTime.Today; DateTime PeriodEndDate = DateTime.Today; string ForexGainsLossesAccount = String.Empty; db.ReadTransaction(ref Transaction, delegate { LedgerTable = ALedgerAccess.LoadByPrimaryKey(FLedgerNumber, Transaction); ForexGainsLossesAccount = LedgerTable[0].ForexGainsLossesAccount; TFinancialYear.GetStartAndEndDateOfPeriod(FLedgerNumber, LedgerTable[0].CurrentPeriod, out PeriodStartDate, out PeriodEndDate, Transaction); }); AForexGainsLossesAccount = ForexGainsLossesAccount; APeriodStartDate = PeriodStartDate; APeriodEndDate = PeriodEndDate; }
public static Int32 GetNumberOfPeriods( System.Int32 ALedgerNumber) { Int32 returnValue = 0; bool newTransaction = false; try { TDBTransaction Transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.Serializable, out newTransaction); ALedgerTable LedgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, Transaction); returnValue = LedgerTable[0].NumberOfAccountingPeriods; } finally { if (newTransaction) { DBAccess.GDBAccessObj.RollbackTransaction(); } } return(returnValue); }
private Int64 GetLedgerPartnerKey(Int32 ALedgerNumber) { Int64 retVal = 0; bool NewTransaction = false; TDBTransaction Transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.Serializable, out NewTransaction); try { GiftBatchTDS MainDS = new GiftBatchTDS(); ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction); if (MainDS.ALedger.Count > 0) { retVal = MainDS.ALedger[0].PartnerKey; } } catch (Exception) { throw; } finally { if (NewTransaction) { DBAccess.GDBAccessObj.RollbackTransaction(); } } return(retVal); }
public static void SetLastReceiptNumber(Int32 ALedgerNumber, Int32 AReceiptNumber) { TDBTransaction ReadWriteTransaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable); ALedgerTable LedgerTbl; try { LedgerTbl = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, ReadWriteTransaction); if (LedgerTbl.Rows.Count > 0) { LedgerTbl[0].LastHeaderRNumber = AReceiptNumber; ALedgerAccess.SubmitChanges(LedgerTbl, ReadWriteTransaction); DBAccess.GDBAccessObj.CommitTransaction(); } } catch (Exception Exc) { TLogging.Log("An Exception occured during the setting of the last Receipt Number:" + Environment.NewLine + Exc.ToString()); DBAccess.GDBAccessObj.RollbackTransaction(); throw; } }
public static Int32 GetLastReceiptNumber(Int32 ALedgerNumber) { TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted); ALedgerTable LedgerTbl; try { LedgerTbl = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, Transaction); DBAccess.GDBAccessObj.RollbackTransaction(); } catch (Exception Exc) { TLogging.Log("An Exception occured during the getting of the last Receipt Number:" + Environment.NewLine + Exc.ToString()); DBAccess.GDBAccessObj.RollbackTransaction(); throw; } if (LedgerTbl.Rows.Count > 0) { return(LedgerTbl[0].LastHeaderRNumber); } else { return(0); // This is obviously the wrong answer, but I judge it to be unlikely. } }
/// <summary> /// Get the start and end date of the given period in the given year /// </summary> public static bool GetStartAndEndDateOfPeriod(Int32 ALedgerNumber, Int32 AYear, Int32 APeriodNumber, out DateTime APeriodStartDate, out DateTime APeriodEndDate, TDBTransaction ATransaction) { #region Validate Arguments if (ALedgerNumber <= 0) { throw new EFinanceSystemInvalidLedgerNumberException(String.Format(Catalog.GetString( "Function:{0} - The Ledger number must be greater than 0!"), Utilities.GetMethodName(true)), ALedgerNumber); } // ATransaction can be null //else if (ATransaction == null) //{ // throw new EFinanceSystemDBTransactionNullException(String.Format(Catalog.GetString( // "Function:{0} - Database Transaction must not be NULL!"), // Utilities.GetMethodName(true))); //} #endregion Validate Arguments // invalid period if (APeriodNumber == -1) { APeriodStartDate = DateTime.MinValue; APeriodEndDate = DateTime.MaxValue; return(false); } AAccountingPeriodTable AccPeriodTable = AAccountingPeriodAccess.LoadByPrimaryKey(ALedgerNumber, APeriodNumber, ATransaction); #region Validate Data if ((AccPeriodTable == null) || (AccPeriodTable.Count == 0)) { throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString( "Function:{0} - Accounting Period data for period {1} in Ledger number {2} does not exist or could not be accessed!"), Utilities.GetMethodName(true), APeriodNumber, ALedgerNumber)); } #endregion Validate Data AAccountingPeriodRow AccPeriodRow = (AAccountingPeriodRow)AccPeriodTable.Rows[0]; ALedgerTable LedgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, ATransaction); Int32 currentYear = LedgerTable[0].CurrentFinancialYear; Int32 yearsAgo = currentYear - AYear; APeriodStartDate = AccPeriodRow.PeriodStartDate.AddYears(0 - yearsAgo); APeriodEndDate = AccPeriodRow.PeriodEndDate.AddYears(0 - yearsAgo); return(true); }
public static bool GetAccountingYearPeriodByDate(Int32 ALedgerNumber, DateTime ADate, out Int32 AYearNumber, out Int32 APeriodNumber) { Int32 CurrentFinancialYear; //Set the year to return Int32 YearNumber = FindFinancialYearByDate(ALedgerNumber, ADate); AYearNumber = YearNumber; if (AYearNumber == 99) { AYearNumber = 0; APeriodNumber = 0; return(false); } Int32 PeriodNumber = 0; TDBTransaction transaction = null; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.Serializable, ref transaction, delegate { ALedgerTable LedgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, transaction); CurrentFinancialYear = ((ALedgerRow)LedgerTable.Rows[0]).CurrentFinancialYear; AAccountingPeriodTable AccPeriodTableTmp = new AAccountingPeriodTable(); AAccountingPeriodRow TemplateRow = AccPeriodTableTmp.NewRowTyped(false); TemplateRow.LedgerNumber = ALedgerNumber; TemplateRow.PeriodStartDate = ADate.AddYears(CurrentFinancialYear - YearNumber); TemplateRow.PeriodEndDate = ADate.AddYears(CurrentFinancialYear - YearNumber); StringCollection operators = StringHelper.InitStrArr(new string[] { "=", "<=", ">=" }); AAccountingPeriodTable AccountingPeriodTable = AAccountingPeriodAccess.LoadUsingTemplate(TemplateRow, operators, null, transaction); if (AccountingPeriodTable.Count == 0) { return; } AAccountingPeriodRow AccountingPeriodRow = (AAccountingPeriodRow)AccountingPeriodTable.Rows[0]; PeriodNumber = AccountingPeriodRow.AccountingPeriodNumber; }); APeriodNumber = PeriodNumber; return(true); } // Get AccountingYear Period ByDate
public static BudgetTDS LoadBudgetForAutoGenerate(Int32 ALedgerNumber) { BudgetTDS FMainDS = new BudgetTDS(); TDBTransaction Transaction = new TDBTransaction(); TDataBase db = DBAccess.Connect("LoadBudgetForAutoGenerate"); db.ReadTransaction( ref Transaction, delegate { ALedgerAccess.LoadByPrimaryKey(FMainDS, ALedgerNumber, Transaction); #region Validate Data if ((FMainDS.ALedger == null) || (FMainDS.ALedger.Count == 0)) { throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString( "Function:{0} - Ledger data for Ledger number {1} does not exist or could not be accessed!"), Utilities.GetMethodName(true), ALedgerNumber)); } #endregion Validate Data int CurrentFinancialYear = FMainDS.ALedger[0].CurrentFinancialYear; //Load all by Ledger/Year but none may exist ABudgetTable BudgetTable = new ABudgetTable(); ABudgetRow TemplateRow = (ABudgetRow)BudgetTable.NewRow(); TemplateRow.LedgerNumber = ALedgerNumber; TemplateRow.Year = CurrentFinancialYear; StringCollection Operators = StringHelper.InitStrArr(new string[] { "=", "=" }); StringCollection OrderList = new StringCollection(); OrderList.Add("ORDER BY"); OrderList.Add(ABudgetTable.GetCostCentreCodeDBName() + " ASC"); OrderList.Add(ABudgetTable.GetAccountCodeDBName() + " ASC"); ABudgetAccess.LoadUsingTemplate(FMainDS, TemplateRow, Operators, null, Transaction, OrderList, 0, 0); ABudgetPeriodAccess.LoadViaABudgetTemplate(FMainDS, TemplateRow, Operators, null, Transaction, OrderList, 0, 0); ABudgetRevisionAccess.LoadByPrimaryKey(FMainDS, ALedgerNumber, CurrentFinancialYear, 0, Transaction); ABudgetTypeAccess.LoadAll(FMainDS, Transaction); }); // Accept row changes here so that the Client gets 'unmodified' rows FMainDS.AcceptChanges(); // Remove all Tables that were not filled with data before remoting them. FMainDS.RemoveEmptyTables(); return(FMainDS); }
/// <summary> /// init the exchange rate, to avoid messages "Cannot find exchange rate for EUR USD" /// </summary> public static void InitExchangeRate() { TAccountPeriodInfo AccountingPeriodInfo = new TAccountPeriodInfo(FLedgerNumber, 1); ADailyExchangeRateTable dailyrates = new ADailyExchangeRateTable(); ADailyExchangeRateRow row = dailyrates.NewRowTyped(true); row.DateEffectiveFrom = AccountingPeriodInfo.PeriodStartDate; row.TimeEffectiveFrom = 100; row.FromCurrencyCode = "USD"; row.ToCurrencyCode = "EUR"; row.RateOfExchange = 1.34m; dailyrates.Rows.Add(row); row = dailyrates.NewRowTyped(true); row.DateEffectiveFrom = AccountingPeriodInfo.PeriodStartDate; row.TimeEffectiveFrom = 100; row.FromCurrencyCode = "USD"; row.ToCurrencyCode = "GBP"; row.RateOfExchange = 1.57m; dailyrates.Rows.Add(row); if (!ADailyExchangeRateAccess.Exists(row.FromCurrencyCode, row.ToCurrencyCode, row.DateEffectiveFrom, row.TimeEffectiveFrom, null)) { ADailyExchangeRateAccess.SubmitChanges(dailyrates, null); } ALedgerTable Ledger = ALedgerAccess.LoadByPrimaryKey(FLedgerNumber, null); for (int periodCounter = 1; periodCounter <= Ledger[0].NumberOfAccountingPeriods + Ledger[0].NumberFwdPostingPeriods; periodCounter++) { AccountingPeriodInfo = new TAccountPeriodInfo(FLedgerNumber, periodCounter); ACorporateExchangeRateTable corprates = new ACorporateExchangeRateTable(); ACorporateExchangeRateRow corprow = corprates.NewRowTyped(true); corprow.DateEffectiveFrom = AccountingPeriodInfo.PeriodStartDate; corprow.TimeEffectiveFrom = 100; corprow.FromCurrencyCode = "USD"; corprow.ToCurrencyCode = "EUR"; corprow.RateOfExchange = 1.34m; corprates.Rows.Add(corprow); corprow = corprates.NewRowTyped(true); corprow.DateEffectiveFrom = AccountingPeriodInfo.PeriodStartDate; corprow.TimeEffectiveFrom = 100; corprow.FromCurrencyCode = "USD"; corprow.ToCurrencyCode = "GBP"; corprow.RateOfExchange = 1.57m; corprates.Rows.Add(corprow); if (!ACorporateExchangeRateAccess.Exists(corprow.FromCurrencyCode, corprow.ToCurrencyCode, corprow.DateEffectiveFrom, null)) { ACorporateExchangeRateAccess.SubmitChanges(corprates, null); } } }
/// <summary> /// Return the country code for the ledger with this key /// </summary> public static string GetCountryCodeFromLedger(TDBTransaction ATransaction, Int32 LedgerNumber) { ALedgerTable ledgerTable = ALedgerAccess.LoadByPrimaryKey((int)(DomainManager.GSiteKey / 1000000), ATransaction); if (ledgerTable.Rows.Count == 1) { return(ledgerTable[0].CountryCode); } // no Ledger row for this key, so return invalid country code return("99"); }
private DataTable GetLedgerDetailsTable(TDBTransaction AReadTransaction, System.Int32 ALedgerNumber, string ATableName) { // StringCollection FieldList = new StringCollection(); // FieldList.Add(ALedgerTable.GetLedgerNumberDBName()); // FieldList.Add(ALedgerTable.GetNumberFwdPostingPeriodsDBName()); // FieldList.Add(ALedgerTable.GetNumberOfAccountingPeriodsDBName()); // FieldList.Add(ALedgerTable.GetCurrentPeriodDBName()); // FieldList.Add(ALedgerTable.GetCurrentFinancialYearDBName()); // FieldList.Add(ALedgerTable.GetBranchProcessingDBName()); // FieldList.Add(ALedgerTable.GetBaseCurrencyDBName()); // FieldList.Add(ALedgerTable.GetIntlCurrencyDBName()); return(ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, AReadTransaction)); }
public static string GetLedgerBaseCurrency(Int32 ALedgerNumber) { string ReturnValue = ""; TDBTransaction Transaction = null; DBAccess.GDBAccessObj.BeginAutoReadTransaction(ref Transaction, delegate { ReturnValue = ((ALedgerRow)ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, Transaction).Rows[0]).BaseCurrency; }); return(ReturnValue); }
public static Int32 GetNumberOfPeriods(Int32 ALedgerNumber) { Int32 returnValue = 0; TDBTransaction transaction = null; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.Serializable, ref transaction, delegate { ALedgerTable LedgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, transaction); returnValue = LedgerTable[0].NumberOfAccountingPeriods; }); return(returnValue); }
/// <summary> /// create a new batch with a consecutive batch number in the ledger /// for call inside a server function /// for performance reasons submitting (save the data in the database) is done later (not here) /// </summary> /// <param name="AMainDS"></param> /// <param name="ATransaction"></param> /// <param name="ALedgerNumber"></param> /// <returns>the new gift batch row</returns> public static ARecurringGiftBatchRow CreateANewRecurringGiftBatchRow(ref GiftBatchTDS AMainDS, ref TDBTransaction ATransaction, Int32 ALedgerNumber) { #region Validate Arguments if (AMainDS == null) { throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString( "Function:{0} - The Gift Batch dataset is NULL!"), Utilities.GetMethodName(true))); } else if (ATransaction == null) { throw new EFinanceSystemDBTransactionNullException(String.Format(Catalog.GetString( "Function:{0} - Database Transaction must not be NULL!"), Utilities.GetMethodName(true))); } else if (ALedgerNumber <= 0) { throw new EFinanceSystemInvalidLedgerNumberException(String.Format(Catalog.GetString( "Function:{0} - The Ledger number must be greater than 0!"), Utilities.GetMethodName(true)), ALedgerNumber); } #endregion Validate Arguments TLedgerInfo info = new TLedgerInfo(ALedgerNumber, ATransaction.DataBaseObj); ALedgerAccess.LoadByPrimaryKey(AMainDS, ALedgerNumber, ATransaction); if ((AMainDS.ALedger == null) || (AMainDS.ALedger.Count == 0)) { throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString( "Function:{0} - The Ledger table is NULL or is empty!"), Utilities.GetMethodName(true))); } ARecurringGiftBatchRow NewRow = AMainDS.ARecurringGiftBatch.NewRowTyped(true); NewRow.LedgerNumber = ALedgerNumber; NewRow.BatchNumber = ++AMainDS.ALedger[0].LastRecGiftBatchNumber; NewRow.BatchDescription = Catalog.GetString("Please enter recurring batch description"); NewRow.BankAccountCode = info.GetDefaultBankAccount(); NewRow.BankCostCentre = info.GetStandardCostCentre(); NewRow.CurrencyCode = AMainDS.ALedger[0].BaseCurrency; AMainDS.ARecurringGiftBatch.Rows.Add(NewRow); return(NewRow); }
public static bool GetCurrentPeriodDates(Int32 ALedgerNumber, out DateTime AStartDate, out DateTime AEndDate) { TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable); ALedgerTable LedgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, Transaction); AAccountingPeriodTable AccountingPeriodTable = AAccountingPeriodAccess.LoadByPrimaryKey(ALedgerNumber, LedgerTable[0].CurrentPeriod, Transaction); AStartDate = AccountingPeriodTable[0].PeriodStartDate; AEndDate = AccountingPeriodTable[0].PeriodEndDate; DBAccess.GDBAccessObj.RollbackTransaction(); return(true); }
public static string GetLedgerBaseCurrency(Int32 ALedgerNumber) { string ReturnValue = ""; TDBTransaction ReadTransaction = null; // Automatic handling of a Read-only DB Transaction - and also the automatic establishment and closing of a DB // Connection where a DB Transaction can be exectued (only if that should be needed). DBAccess.SimpleAutoReadTransactionWrapper(IsolationLevel.ReadCommitted, "TFinanceServerLookups.GetLedgerBaseCurrency", out ReadTransaction, delegate { ReturnValue = ((ALedgerRow)ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, ReadTransaction).Rows[0]).BaseCurrency; }); return(ReturnValue); }
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); }
public static Int32 GetNumberOfPeriods(Int32 ALedgerNumber) { Int32 returnValue = 0; TDBTransaction transaction = new TDBTransaction(); TDataBase db = DBAccess.Connect("GetNumberOfPeriods"); db.ReadTransaction(ref transaction, delegate { ALedgerTable LedgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, transaction); returnValue = LedgerTable[0].NumberOfAccountingPeriods; }); db.CloseDBConnection(); return(returnValue); }
public static bool GetCurrentPeriodDates(Int32 ALedgerNumber, out DateTime AStartDate, out DateTime AEndDate) { TDBTransaction transaction = null; AAccountingPeriodTable AccountingPeriodTable = null; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.Serializable, TEnforceIsolationLevel.eilMinimum, ref transaction, delegate { ALedgerTable LedgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, transaction); AccountingPeriodTable = AAccountingPeriodAccess.LoadByPrimaryKey(ALedgerNumber, LedgerTable[0].CurrentPeriod, transaction); }); AStartDate = AccountingPeriodTable[0].PeriodStartDate; AEndDate = AccountingPeriodTable[0].PeriodEndDate; return(true); }
public static string GetLedgerBaseCurrency(Int32 ALedgerNumber) { string ReturnValue = ""; TDBTransaction ReadTransaction = null; // Need to use 'GetNewOrExistingAutoReadTransaction' rather than 'BeginAutoReadTransaction' to allow // opening of the 'GL Transaction Find' screen while a Report is calculating (Bug #3879). DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, ref ReadTransaction, delegate { ReturnValue = ((ALedgerRow)ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, ReadTransaction).Rows[0]).BaseCurrency; }); return(ReturnValue); }