/// <summary> /// setup a ledger with simple test data /// </summary> public static int SetupTestLedgerWithPostedBatches() { // create a new ledger int LedgerNumber = CommonNUnitFunctions.CreateNewLedger(); // post a sample batch TCommonAccountingTool commonAccountingTool = new TCommonAccountingTool(LedgerNumber, "NUNIT"); commonAccountingTool.AddBaseCurrencyJournal(); commonAccountingTool.JournalDescription = "Test Data accounts"; string strAccountBank = "6000"; string StandardCostCentre = TGLTransactionWebConnector.GetStandardCostCentre(LedgerNumber); // Accounting of a start balance commonAccountingTool.AddBaseCurrencyTransaction( "6200", StandardCostCentre, "Start Balance", "Debit", MFinanceConstants.IS_DEBIT, 40); commonAccountingTool.AddBaseCurrencyTransaction( "9700", StandardCostCentre, "Start Balance", "Credit", MFinanceConstants.IS_CREDIT, 40); // Accounting of some gifts ... commonAccountingTool.AddBaseCurrencyTransaction( strAccountBank, StandardCostCentre, "Gift Example", "Debit", MFinanceConstants.IS_DEBIT, 100); commonAccountingTool.AddBaseCurrencyTransaction( "0100", StandardCostCentre, "Gift Example", "Credit", MFinanceConstants.IS_CREDIT, 100); // Accounting of some expense ... commonAccountingTool.AddBaseCurrencyTransaction( strAccountBank, StandardCostCentre, "Expense Example", "Credit", MFinanceConstants.IS_CREDIT, 20); commonAccountingTool.AddBaseCurrencyTransaction( "4200", StandardCostCentre, "Expense Example", "Debit", MFinanceConstants.IS_DEBIT, 20); commonAccountingTool.CloseSaveAndPost(); // returns true if posting seemed to work return(LedgerNumber); }
public void Test_SwitchToNextMonth() { FLedgerNumber = CommonNUnitFunctions.CreateNewLedger(); TLedgerInfo ledgerInfo = new TLedgerInfo(FLedgerNumber); int counter = 0; do { Int32 CurrentPeriod = ledgerInfo.CurrentPeriod; ++counter; Assert.Greater(20, counter, "Too many loops"); // Set revaluation flag ... new TLedgerInitFlagHandler(FLedgerNumber, TLedgerInitFlagEnum.Revaluation).Flag = true; // Run MonthEnd ... TVerificationResultCollection verificationResult; bool blnHasErrors = TPeriodIntervalConnector.PeriodMonthEnd( FLedgerNumber, false, out verificationResult); if (!ledgerInfo.ProvisionalYearEndFlag) { Assert.AreEqual(CurrentPeriod + 1, ledgerInfo.CurrentPeriod, "Period increment"); } Assert.IsFalse(blnHasErrors, "Month end without any error"); System.Diagnostics.Debug.WriteLine("Counter: " + counter.ToString()); } while (!ledgerInfo.ProvisionalYearEndFlag); }
public void Test_TAccountPeriodToNewYear() { // create new ledger which is in year 2010 int intLedgerNumber2010 = CommonNUnitFunctions.CreateNewLedger(new DateTime(2010, 1, 1)); // We are in 2010 and this and 2011 is not a leap year TVerificationResultCollection verificationResult = new TVerificationResultCollection(); TAccountPeriodToNewYear accountPeriodToNewYear = new TAccountPeriodToNewYear(intLedgerNumber2010); accountPeriodToNewYear.VerificationResultCollection = verificationResult; accountPeriodToNewYear.IsInInfoMode = false; // RunEndOfPeriodOperation ... accountPeriodToNewYear.RunOperation(); TAccountPeriodInfo accountPeriodInfo = new TAccountPeriodInfo(intLedgerNumber2010); accountPeriodInfo.AccountingPeriodNumber = 2; Assert.AreEqual(2011, accountPeriodInfo.PeriodStartDate.Year, "Test of the year"); Assert.AreEqual(28, accountPeriodInfo.PeriodEndDate.Day, "Test of the Feb. 28th"); // Switch to 2012 - this is a leap year ... accountPeriodToNewYear = new TAccountPeriodToNewYear(intLedgerNumber2010); accountPeriodToNewYear.IsInInfoMode = false; accountPeriodToNewYear.RunOperation(); accountPeriodInfo = new TAccountPeriodInfo(intLedgerNumber2010); accountPeriodInfo.AccountingPeriodNumber = 2; Assert.AreEqual(29, accountPeriodInfo.PeriodEndDate.Day, "Test of the Feb. 29th"); }
public void Init() { TPetraServerConnector.Connect(); FLedgerNumber = CommonNUnitFunctions.CreateNewLedger(); FledgerInfo = new TLedgerInfo(FLedgerNumber); System.Diagnostics.Debug.WriteLine("Init: " + this.ToString()); }
public void Test_PEMM_05_Revaluation() { FLedgerNumber = CommonNUnitFunctions.CreateNewLedger(); // load foreign currency account 6001 CommonNUnitFunctions.LoadTestDataBase("csharp\\ICT\\Testing\\lib\\MFinance\\GL\\" + "test-sql\\gl-test-account-data.sql", FLedgerNumber); // post a batch for foreign currency account 6001 TCommonAccountingTool commonAccountingTool = new TCommonAccountingTool(FLedgerNumber, "NUNIT"); commonAccountingTool.AddForeignCurrencyJournal("GBP", 1.1m); commonAccountingTool.JournalDescription = "Test foreign currency account"; string strAccountGift = "0200"; string strAccountBank = "6001"; // Accounting of some gifts ... commonAccountingTool.AddBaseCurrencyTransaction( strAccountBank, (FLedgerNumber * 100).ToString(), "Gift Example", "Debit", MFinanceConstants.IS_DEBIT, 100); commonAccountingTool.AddBaseCurrencyTransaction( strAccountGift, (FLedgerNumber * 100).ToString(), "Gift Example", "Credit", MFinanceConstants.IS_CREDIT, 100); commonAccountingTool.CloseSaveAndPost(); // returns true if posting seemed to work TVerificationResultCollection verificationResult; bool blnHasErrors = TPeriodIntervalConnector.TPeriodMonthEnd( FLedgerNumber, true, out verificationResult); bool blnStatusArrived = false; for (int i = 0; i < verificationResult.Count; ++i) { if (verificationResult[i].ResultCode.Equals( TPeriodEndErrorAndStatusCodes.PEEC_05.ToString())) { blnStatusArrived = true; Assert.IsTrue(verificationResult[i].ResultSeverity == TResultSeverity.Resv_Critical, "we need a critical error: need to run revaluation first ..."); } } Assert.IsTrue(blnStatusArrived, "Status message has been shown"); Assert.IsTrue(blnHasErrors, "should fail because revaluation needs to be run first"); // run revaluation blnHasErrors = TRevaluationWebConnector.Revaluate(FLedgerNumber, new TLedgerInfo( FLedgerNumber).CurrentPeriod, new string[] { "GBP" }, new decimal[] { 1.2m }, out verificationResult); TLogging.Log(verificationResult.BuildVerificationResultString()); Assert.IsFalse(blnHasErrors, "Problem running the revaluation"); blnHasErrors = TPeriodIntervalConnector.TPeriodMonthEnd( FLedgerNumber, true, out verificationResult); Assert.IsFalse(blnHasErrors, "should now be able to close the month now that the revaluation has been run"); }
public void Test_TAccountPeriodToNewYear() { // create new ledger which is in year 2010 int intLedgerNumber2010 = CommonNUnitFunctions.CreateNewLedger(new DateTime(2010, 1, 1)); TDBTransaction transaction = new TDBTransaction(); TDataBase db = DBAccess.Connect("Test_TAccountPeriodToNewYear"); bool SubmissionOK = false; TAccountPeriodToNewYear accountPeriodToNewYear = null; db.WriteTransaction( ref transaction, ref SubmissionOK, delegate { // We are in 2010 and this and 2011 is not a leap year TVerificationResultCollection verificationResult = new TVerificationResultCollection(); accountPeriodToNewYear = new TAccountPeriodToNewYear(intLedgerNumber2010, transaction); accountPeriodToNewYear.VerificationResultCollection = verificationResult; accountPeriodToNewYear.IsInInfoMode = false; // RunEndOfPeriodOperation ... accountPeriodToNewYear.RunOperation(); SubmissionOK = true; }); TAccountPeriodInfo accountPeriodInfo = new TAccountPeriodInfo(intLedgerNumber2010); accountPeriodInfo.AccountingPeriodNumber = 2; Assert.AreEqual(2011, accountPeriodInfo.PeriodStartDate.Year, "Test of the year"); Assert.AreEqual(28, accountPeriodInfo.PeriodEndDate.Day, "Test of the Feb. 28th"); SubmissionOK = false; db.WriteTransaction( ref transaction, ref SubmissionOK, delegate { // Switch to 2012 - this is a leap year ... accountPeriodToNewYear = new TAccountPeriodToNewYear(intLedgerNumber2010, transaction); accountPeriodToNewYear.IsInInfoMode = false; accountPeriodToNewYear.RunOperation(); SubmissionOK = true; }); accountPeriodInfo = new TAccountPeriodInfo(intLedgerNumber2010); accountPeriodInfo.AccountingPeriodNumber = 2; Assert.AreEqual(29, accountPeriodInfo.PeriodEndDate.Day, "Test of the Feb. 29th"); }
private void PrepareTestCaseData() { // new database because period July has to be open FLedgerNumber = CommonNUnitFunctions.CreateNewLedger(); TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(); // Check if some special test data are available - otherwise load ... bool CostCentreTestCasesAvailable = ACostCentreAccess.Exists(FLedgerNumber, "4301", Transaction); DBAccess.GDBAccessObj.RollbackTransaction(); if (!CostCentreTestCasesAvailable) { CommonNUnitFunctions.LoadTestDataBase("csharp\\ICT\\Testing\\lib\\MFinance\\GL\\" + "test-sql\\gl-test-costcentre-data.sql", FLedgerNumber); } }
public void Init() { TPetraServerConnector.Connect(); FLedgerNumber = CommonNUnitFunctions.CreateNewLedger(); // add costcentre 7300 for gift batch ACostCentreTable CostCentres = new ACostCentreTable(); ACostCentreRow CCRow = CostCentres.NewRowTyped(); CCRow.LedgerNumber = FLedgerNumber; CCRow.CostCentreCode = "7300"; CCRow.CostCentreName = "7300"; CCRow.CostCentreType = MFinanceConstants.FOREIGN_CC_TYPE; CCRow.CostCentreToReportTo = MFinanceConstants.INTER_LEDGER_HEADING; CCRow.PostingCostCentreFlag = true; CCRow.CostCentreActiveFlag = true; CostCentres.Rows.Add(CCRow); ACostCentreAccess.SubmitChanges(CostCentres, null); System.Diagnostics.Debug.WriteLine("Init: " + this.ToString()); }
public void Test_SwitchToNextMonth() { FLedgerNumber = CommonNUnitFunctions.CreateNewLedger(); TLedgerInfo LedgerInfo = new TLedgerInfo(FLedgerNumber); int Counter = 0; do { Int32 CurrentPeriod = LedgerInfo.CurrentPeriod; ++Counter; Assert.Greater(20, Counter, "Too many loops"); // Set revaluation flag ... new TLedgerInitFlag(FLedgerNumber, "Reval").IsSet = true; // Run MonthEnd ... TVerificationResultCollection verificationResult; List <Int32> glBatchNumbers; Boolean stewardshipBatch; bool blnHasErrors = !TPeriodIntervalConnector.PeriodMonthEnd( FLedgerNumber, false, out glBatchNumbers, out stewardshipBatch, out verificationResult); if (!LedgerInfo.ProvisionalYearEndFlag) { Assert.AreEqual(CurrentPeriod + 1, LedgerInfo.CurrentPeriod, "Period increment"); } Assert.IsFalse(blnHasErrors, "Month end without any error"); System.Diagnostics.Debug.WriteLine("Counter: " + Counter.ToString()); } while (!LedgerInfo.ProvisionalYearEndFlag); }
private void PrepareTestCaseData() { // new database because period July has to be open FLedgerNumber = CommonNUnitFunctions.CreateNewLedger(); TDBTransaction Transaction = new TDBTransaction(); TDataBase db = DBAccess.Connect("PrepareTestCaseData"); bool CostCentreTestCasesAvailable = false; db.ReadTransaction(ref Transaction, delegate { // Check if some special test data are available - otherwise load ... CostCentreTestCasesAvailable = ACostCentreAccess.Exists(FLedgerNumber, "4301", Transaction); }); db.CloseDBConnection(); if (!CostCentreTestCasesAvailable) { CommonNUnitFunctions.LoadTestDataBase("csharp\\ICT\\Testing\\lib\\MFinance\\server\\GL\\" + "test-sql\\gl-test-costcentre-data.sql", FLedgerNumber); } }
public void Test_YearEnd() { intLedgerNumber = CommonNUnitFunctions.CreateNewLedger(); TLedgerInfo LedgerInfo = new TLedgerInfo(intLedgerNumber); Assert.AreEqual(0, LedgerInfo.CurrentFinancialYear, "Before YearEnd, we should be in year 0"); TAccountPeriodInfo periodInfo = new TAccountPeriodInfo(intLedgerNumber, 1); Assert.AreEqual(new DateTime(DateTime.Now.Year, 1, 1), periodInfo.PeriodStartDate, "Calendar from base database should start with January 1st of this year"); CommonNUnitFunctions.LoadTestDataBase("csharp\\ICT\\Testing\\lib\\MFinance\\server\\GL\\test-sql\\gl-test-year-end.sql", intLedgerNumber); TCommonAccountingTool commonAccountingTool = new TCommonAccountingTool(intLedgerNumber, "NUNIT"); commonAccountingTool.AddBaseCurrencyJournal(); commonAccountingTool.JournalDescription = "Test Data accounts"; string strAccountGift = "0200"; string strAccountBank = "6200"; string strAccountExpense = "4100"; // Accounting of some gifts ... commonAccountingTool.AddBaseCurrencyTransaction( strAccountBank, "4301", "Gift Example", "Debit", MFinanceConstants.IS_DEBIT, 100); commonAccountingTool.AddBaseCurrencyTransaction( strAccountBank, "4302", "Gift Example", "Debit", MFinanceConstants.IS_DEBIT, 200); commonAccountingTool.AddBaseCurrencyTransaction( strAccountBank, "4303", "Gift Example", "Debit", MFinanceConstants.IS_DEBIT, 300); commonAccountingTool.AddBaseCurrencyTransaction( strAccountGift, "4301", "Gift Example", "Credit", MFinanceConstants.IS_CREDIT, 100); commonAccountingTool.AddBaseCurrencyTransaction( strAccountGift, "4302", "Gift Example", "Credit", MFinanceConstants.IS_CREDIT, 200); commonAccountingTool.AddBaseCurrencyTransaction( strAccountGift, "4303", "Gift Example", "Credit", MFinanceConstants.IS_CREDIT, 300); // Accounting of some expenses ... commonAccountingTool.AddBaseCurrencyTransaction( strAccountExpense, "4301", "Expense Example", "Debit", MFinanceConstants.IS_DEBIT, 150); commonAccountingTool.AddBaseCurrencyTransaction( strAccountExpense, "4302", "Expense Example", "Debit", MFinanceConstants.IS_DEBIT, 150); commonAccountingTool.AddBaseCurrencyTransaction( strAccountExpense, "4303", "Expense Example", "Debit", MFinanceConstants.IS_DEBIT, 200); commonAccountingTool.AddBaseCurrencyTransaction( strAccountBank, "4301", "Expense Example", "Credit", MFinanceConstants.IS_CREDIT, 150); commonAccountingTool.AddBaseCurrencyTransaction( strAccountBank, "4302", "Expense Example", "Credit", MFinanceConstants.IS_CREDIT, 150); commonAccountingTool.AddBaseCurrencyTransaction( strAccountBank, "4303", "Expense Example", "Credit", MFinanceConstants.IS_CREDIT, 200); commonAccountingTool.CloseSaveAndPost(); // returns true if posting seemed to work TVerificationResultCollection verificationResult = new TVerificationResultCollection(); bool blnLoop = true; while (blnLoop) { if (LedgerInfo.ProvisionalYearEndFlag) { blnLoop = false; } else { TVerificationResultCollection VerificationResult; List <Int32> glBatchNumbers; Boolean stewardshipBatch; TPeriodIntervalConnector.PeriodMonthEnd( intLedgerNumber, false, out glBatchNumbers, out stewardshipBatch, out VerificationResult); CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult, "Running MonthEnd gave critical error"); } } // check before year end that income and expense accounts are not 0 int intYear = 0; CheckGLMEntry(intLedgerNumber, intYear, strAccountBank, -50, 0, 50, 0, 100, 0); CheckGLMEntry(intLedgerNumber, intYear, strAccountExpense, 150, 0, 150, 0, 200, 0); CheckGLMEntry(intLedgerNumber, intYear, strAccountGift, 100, 0, 200, 0, 300, 0); // test that we cannot post to period 12 anymore, all periods are closed? LedgerInfo = new TLedgerInfo(intLedgerNumber); Assert.AreEqual(true, LedgerInfo.ProvisionalYearEndFlag, "Provisional YearEnd flag should be set"); List <Int32> glBatches = new List <int>(); TDBTransaction transaction = null; bool SubmissionOK = false; DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction( IsolationLevel.Serializable, TEnforceIsolationLevel.eilMinimum, ref transaction, ref SubmissionOK, delegate { // // Reallocation is never called explicitly like this - it's not really appropriate // because I'm about to call it again as part of YearEnd, below. // But a tweak in the reallocation code means that it should now cope with being called twice. TReallocation reallocation = new TReallocation(LedgerInfo, glBatches, transaction); reallocation.VerificationResultCollection = verificationResult; reallocation.IsInInfoMode = false; reallocation.RunOperation(); SubmissionOK = true; }); // check amounts after reallocation CheckGLMEntry(intLedgerNumber, intYear, strAccountBank, -50, 0, 50, 0, 100, 0); CheckGLMEntry(intLedgerNumber, intYear, strAccountExpense, 0, -150, 0, -150, 0, -200); CheckGLMEntry(intLedgerNumber, intYear, strAccountGift, 0, -100, 0, -200, 0, -300); // first run in info mode TPeriodIntervalConnector.PeriodYearEnd(intLedgerNumber, true, out glBatches, out verificationResult); CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(verificationResult, "YearEnd test should not have critical errors"); // now run for real TPeriodIntervalConnector.PeriodYearEnd(intLedgerNumber, false, out glBatches, out verificationResult); CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(verificationResult, "YearEnd should not have critical errors"); ++intYear; // check after year end that income and expense accounts are 0, bank account remains CheckGLMEntry(intLedgerNumber, intYear, strAccountBank, -50, 0, 50, 0, 100, 0); CheckGLMEntry(intLedgerNumber, intYear, strAccountExpense, 0, 0, 0, 0, 0, 0); CheckGLMEntry(intLedgerNumber, intYear, strAccountGift, 0, 0, 0, 0, 0, 0); // also check the glm period records CheckGLMPeriodEntry(intLedgerNumber, intYear, 1, strAccountBank, -50, 50, 100); CheckGLMPeriodEntry(intLedgerNumber, intYear, 1, strAccountExpense, 0, 0, 0); CheckGLMPeriodEntry(intLedgerNumber, intYear, 1, strAccountGift, 0, 0, 0); // 9700 is the account that the expenses and income from last year is moved to TGlmInfo glmInfo = new TGlmInfo(intLedgerNumber, intYear, "9700"); glmInfo.Reset(); Assert.IsTrue(glmInfo.MoveNext(), "9700 account not found"); Assert.AreEqual(100, glmInfo.YtdActualBase); Assert.AreEqual(0, glmInfo.ClosingPeriodActualBase); LedgerInfo = new TLedgerInfo(intLedgerNumber); Assert.AreEqual(1, LedgerInfo.CurrentFinancialYear, "After YearEnd, we are in a new financial year"); Assert.AreEqual(1, LedgerInfo.CurrentPeriod, "After YearEnd, we are in Period 1"); Assert.AreEqual(false, LedgerInfo.ProvisionalYearEndFlag, "After YearEnd, ProvisionalYearEnd flag should not be set"); periodInfo = new TAccountPeriodInfo(intLedgerNumber, 1); Assert.AreEqual(new DateTime(DateTime.Now.Year + 1, 1, 1), periodInfo.PeriodStartDate, "new Calendar should start with January 1st of next year"); }
public void Test_2YearEnds() { intLedgerNumber = CommonNUnitFunctions.CreateNewLedger(); CommonNUnitFunctions.LoadTestDataBase("csharp\\ICT\\Testing\\lib\\MFinance\\server\\GL\\test-sql\\gl-test-year-end.sql", intLedgerNumber); TLedgerInfo LedgerInfo = new TLedgerInfo(intLedgerNumber); for (int countYear = 0; countYear < 2; countYear++) { TLogging.Log("preparing year number " + countYear.ToString()); // accounting one gift string strAccountGift = "0200"; string strAccountBank = "6200"; TCommonAccountingTool commonAccountingTool = new TCommonAccountingTool(intLedgerNumber, "NUNIT"); commonAccountingTool.AddBaseCurrencyJournal(); commonAccountingTool.JournalDescription = "Test Data accounts"; commonAccountingTool.AddBaseCurrencyTransaction( strAccountBank, "4301", "Gift Example", "Debit", MFinanceConstants.IS_DEBIT, 100); commonAccountingTool.AddBaseCurrencyTransaction( strAccountGift, "4301", "Gift Example", "Credit", MFinanceConstants.IS_CREDIT, 100); Boolean PostedOk = commonAccountingTool.CloseSaveAndPost(); // returns true if posting seemed to work Assert.AreEqual(true, PostedOk, "Test batch can't be posted"); bool blnLoop = true; while (blnLoop) { // System.Windows.Forms.MessageBox.Show(LedgerInfo.CurrentPeriod.ToString(), "MonthEnd Period"); if (LedgerInfo.ProvisionalYearEndFlag) { blnLoop = false; } else { List <Int32> glBatchNumbers; Boolean stewardshipBatch; TVerificationResultCollection VerificationResult; TPeriodIntervalConnector.PeriodMonthEnd( intLedgerNumber, false, out glBatchNumbers, out stewardshipBatch, out VerificationResult); CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult, "MonthEnd gave critical error at Period" + LedgerInfo.CurrentPeriod + ":\r\n"); } } TDBTransaction transaction = null; bool SubmissionOK = false; DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction( IsolationLevel.Serializable, TEnforceIsolationLevel.eilMinimum, ref transaction, ref SubmissionOK, delegate { TLogging.Log("Closing year number " + countYear.ToString()); List <Int32> glBatches = new List <int>(); TReallocation reallocation = new TReallocation(LedgerInfo, glBatches, transaction); TVerificationResultCollection verificationResult = new TVerificationResultCollection(); reallocation.VerificationResultCollection = verificationResult; reallocation.IsInInfoMode = false; // Assert.AreEqual(1, reallocation.GetJobSize(), "Check 1 reallocation job is required"); // No job size is published by Reallocation reallocation.RunOperation(); TYearEnd YearEndOperator = new TYearEnd(LedgerInfo); TGlmNewYearInit glmNewYearInit = new TGlmNewYearInit(LedgerInfo, countYear, YearEndOperator, transaction); glmNewYearInit.VerificationResultCollection = verificationResult; glmNewYearInit.IsInInfoMode = false; // Assert.Greater(glmNewYearInit.GetJobSize(), 0, "Check that NewYearInit has work to do"); // in this version, GetJobSize returns 0 glmNewYearInit.RunOperation(); YearEndOperator.SetNextPeriod(transaction); SubmissionOK = true; }); } Assert.AreEqual(2, LedgerInfo.CurrentFinancialYear, "After YearEnd, Ledger is in year 2"); TAccountPeriodInfo periodInfo = new TAccountPeriodInfo(intLedgerNumber, 1); Assert.AreEqual(new DateTime(DateTime.Now.Year + 2, 1, 1), periodInfo.PeriodStartDate, "new Calendar should start with January 1st of next year"); } // Test_2YearEnds
public void Test_PEMM_05_Revaluation() { FLedgerNumber = CommonNUnitFunctions.CreateNewLedger(); // load foreign currency account 6001 CommonNUnitFunctions.LoadTestDataBase("csharp\\ICT\\Testing\\lib\\MFinance\\GL\\" + "test-sql\\gl-test-account-data.sql", FLedgerNumber); // post a batch for foreign currency account 6001 TCommonAccountingTool commonAccountingTool = new TCommonAccountingTool(FLedgerNumber, "NUNIT"); commonAccountingTool.AddForeignCurrencyJournal("GBP", 1.1m); commonAccountingTool.JournalDescription = "Test foreign currency account"; string strAccountGift = "0200"; string strAccountBank = "6001"; // Accounting of some gifts ... commonAccountingTool.AddBaseCurrencyTransaction( strAccountBank, (FLedgerNumber * 100).ToString(), "Gift Example", "Debit", MFinanceConstants.IS_DEBIT, 100); commonAccountingTool.AddBaseCurrencyTransaction( strAccountGift, (FLedgerNumber * 100).ToString(), "Gift Example", "Credit", MFinanceConstants.IS_CREDIT, 100); Boolean PostedOk = commonAccountingTool.CloseSaveAndPost(); // returns true if posting seemed to work Assert.IsTrue(PostedOk, "Post foreign gift batch"); TVerificationResultCollection verificationResult; /* * This error is no longer critical - it's OK to run month end even if a reval is required. (Mantis# 03905) * * bool blnHasErrors = TPeriodIntervalConnector.TPeriodMonthEnd( * FLedgerNumber, true, out verificationResult); * * for (int i = 0; i < verificationResult.Count; ++i) * { * if (verificationResult[i].ResultCode.Equals( * TPeriodEndErrorAndStatusCodes.PEEC_05.ToString())) * { * blnStatusArrived = true; * Assert.IsTrue(verificationResult[i].ResultSeverity == TResultSeverity.Resv_Critical, * "A critical error is required: need to run revaluation first ..."); * } * } */ // run revaluation Boolean blnHasErrors = TRevaluationWebConnector.Revaluate(FLedgerNumber, new string[] { "GBP" }, new decimal[] { 1.2m }, TLedgerInfo.GetStandardCostCentre(FLedgerNumber), out verificationResult); if (blnHasErrors) { TLogging.Log("\n\n\nTRevaluationWebConnector.Revaluate returned false, VerificationResult follows:"); TLogging.Log(verificationResult.BuildVerificationResultString()); } Assert.IsFalse(blnHasErrors, "Problem running the revaluation"); blnHasErrors = TPeriodIntervalConnector.PeriodMonthEnd( FLedgerNumber, true, out verificationResult); if (blnHasErrors) { TLogging.Log("\n\n\nTPeriodMonthEnd returned true, VerificationResult follows:"); TLogging.Log(verificationResult.BuildVerificationResultString()); } Assert.IsFalse(blnHasErrors, "should now be able to close the month now that the revaluation has been run"); }
public void Test_YearEnd() { intLedgerNumber = CommonNUnitFunctions.CreateNewLedger(); TLedgerInfo LedgerInfo = new TLedgerInfo(intLedgerNumber); Assert.AreEqual(0, LedgerInfo.CurrentFinancialYear, "Before YearEnd, we should be in year 0"); TAccountPeriodInfo periodInfo = new TAccountPeriodInfo(intLedgerNumber, 1); Assert.AreEqual(new DateTime(DateTime.Now.Year, 1, 1), periodInfo.PeriodStartDate, "Calendar from base database should start with January 1st of this year"); CommonNUnitFunctions.LoadTestDataBase("csharp\\ICT\\Testing\\lib\\MFinance\\GL\\test-sql\\gl-test-year-end.sql", intLedgerNumber); CommonNUnitFunctions.LoadTestDataBase("csharp\\ICT\\Testing\\lib\\MFinance\\GL\\test-sql\\gl-test-year-end-account-property.sql", intLedgerNumber); TCommonAccountingTool commonAccountingTool = new TCommonAccountingTool(intLedgerNumber, "NUNIT"); commonAccountingTool.AddBaseCurrencyJournal(); commonAccountingTool.JournalDescription = "Test Data accounts"; string strAccountGift = "0200"; string strAccountBank = "6200"; string strAccountExpense = "4100"; // Accounting of some gifts ... commonAccountingTool.AddBaseCurrencyTransaction( strAccountBank, "4301", "Gift Example", "Debit", MFinanceConstants.IS_DEBIT, 100); commonAccountingTool.AddBaseCurrencyTransaction( strAccountBank, "4302", "Gift Example", "Debit", MFinanceConstants.IS_DEBIT, 200); commonAccountingTool.AddBaseCurrencyTransaction( strAccountBank, "4303", "Gift Example", "Debit", MFinanceConstants.IS_DEBIT, 300); commonAccountingTool.AddBaseCurrencyTransaction( strAccountGift, "4301", "Gift Example", "Credit", MFinanceConstants.IS_CREDIT, 100); commonAccountingTool.AddBaseCurrencyTransaction( strAccountGift, "4302", "Gift Example", "Credit", MFinanceConstants.IS_CREDIT, 200); commonAccountingTool.AddBaseCurrencyTransaction( strAccountGift, "4303", "Gift Example", "Credit", MFinanceConstants.IS_CREDIT, 300); // Accounting of some expenses ... commonAccountingTool.AddBaseCurrencyTransaction( strAccountExpense, "4301", "Expense Example", "Debit", MFinanceConstants.IS_DEBIT, 150); commonAccountingTool.AddBaseCurrencyTransaction( strAccountExpense, "4302", "Expense Example", "Debit", MFinanceConstants.IS_DEBIT, 150); commonAccountingTool.AddBaseCurrencyTransaction( strAccountExpense, "4303", "Expense Example", "Debit", MFinanceConstants.IS_DEBIT, 200); commonAccountingTool.AddBaseCurrencyTransaction( strAccountBank, "4301", "Expense Example", "Credit", MFinanceConstants.IS_CREDIT, 150); commonAccountingTool.AddBaseCurrencyTransaction( strAccountBank, "4302", "Expense Example", "Credit", MFinanceConstants.IS_CREDIT, 150); commonAccountingTool.AddBaseCurrencyTransaction( strAccountBank, "4303", "Expense Example", "Credit", MFinanceConstants.IS_CREDIT, 200); commonAccountingTool.CloseSaveAndPost(); // returns true if posting seemed to work TVerificationResultCollection verificationResult = new TVerificationResultCollection(); bool blnLoop = true; while (blnLoop) { if (LedgerInfo.ProvisionalYearEndFlag) { blnLoop = false; } else { TVerificationResultCollection VerificationResult; TPeriodIntervalConnector.TPeriodMonthEnd(intLedgerNumber, false, out VerificationResult); CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult, "Running MonthEnd gave critical error"); } } // check before year end that income and expense accounts are not 0 int intYear = 0; CheckGLMEntry(intLedgerNumber, intYear, strAccountBank, -50, 0, 50, 0, 100, 0); CheckGLMEntry(intLedgerNumber, intYear, strAccountExpense, 150, 0, 150, 0, 200, 0); CheckGLMEntry(intLedgerNumber, intYear, strAccountGift, 100, 0, 200, 0, 300, 0); // test that we cannot post to period 12 anymore, all periods are closed? LedgerInfo = new TLedgerInfo(intLedgerNumber); Assert.AreEqual(true, LedgerInfo.ProvisionalYearEndFlag, "Provisional YearEnd flag should be set"); Assert.AreEqual(TYearEndProcessStatus.RESET_STATUS, (TYearEndProcessStatus)LedgerInfo.YearEndProcessStatus, "YearEnd process status should be still on RESET"); TReallocation reallocation = new TReallocation(LedgerInfo); reallocation.VerificationResultCollection = verificationResult; reallocation.IsInInfoMode = false; Assert.AreEqual(6, reallocation.GetJobSize(), "Six reallocation jobs expected"); reallocation.RunOperation(); // // Now if I try to do the same thing again, it should find there's nothing to do: reallocation = new TReallocation(LedgerInfo); reallocation.VerificationResultCollection = verificationResult; reallocation.IsInInfoMode = true; Assert.AreEqual(0, reallocation.GetJobSize(), "After TReallocation, all reallocation jobs should be clear"); // check amounts after reallocation CheckGLMEntry(intLedgerNumber, intYear, strAccountBank, -50, 0, 50, 0, 100, 0); CheckGLMEntry(intLedgerNumber, intYear, strAccountExpense, 0, -150, 0, -150, 0, -200); CheckGLMEntry(intLedgerNumber, intYear, strAccountGift, 0, -100, 0, -200, 0, -300); // first run in info mode TPeriodIntervalConnector.TPeriodYearEnd(intLedgerNumber, true, out verificationResult); CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(verificationResult, "YearEnd test should not have critical errors"); // now run for real TPeriodIntervalConnector.TPeriodYearEnd(intLedgerNumber, false, out verificationResult); CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(verificationResult, "YearEnd should not have critical errors"); ++intYear; // check after year end that income and expense accounts are 0, bank account remains CheckGLMEntry(intLedgerNumber, intYear, strAccountBank, -50, 0, 50, 0, 100, 0); CheckGLMEntry(intLedgerNumber, intYear, strAccountExpense, 0, 0, 0, 0, 0, 0); CheckGLMEntry(intLedgerNumber, intYear, strAccountGift, 0, 0, 0, 0, 0, 0); // also check the glm period records CheckGLMPeriodEntry(intLedgerNumber, intYear, 1, strAccountBank, -50, 50, 100); CheckGLMPeriodEntry(intLedgerNumber, intYear, 1, strAccountExpense, 0, 0, 0); CheckGLMPeriodEntry(intLedgerNumber, intYear, 1, strAccountGift, 0, 0, 0); // 8200 is the account that the expenses and income from last year is moved to TGlmInfo glmInfo = new TGlmInfo(intLedgerNumber, intYear, "8200"); glmInfo.Reset(); glmInfo.MoveNext(); Assert.AreEqual(100, glmInfo.YtdActualBase); Assert.AreEqual(0, glmInfo.ClosingPeriodActualBase); LedgerInfo = new TLedgerInfo(intLedgerNumber); Assert.AreEqual(1, LedgerInfo.CurrentFinancialYear, "After YearEnd, we are in a new financial year"); Assert.AreEqual(1, LedgerInfo.CurrentPeriod, "After YearEnd, we are in Period 1"); Assert.AreEqual(false, LedgerInfo.ProvisionalYearEndFlag, "After YearEnd, ProvisionalYearEnd flag should not be set"); Assert.AreEqual(TYearEndProcessStatus.RESET_STATUS, (TYearEndProcessStatus)LedgerInfo.YearEndProcessStatus, "after year end, year end process status should be RESET"); periodInfo = new TAccountPeriodInfo(intLedgerNumber, 1); Assert.AreEqual(new DateTime(DateTime.Now.Year + 1, 1, 1), periodInfo.PeriodStartDate, "new Calendar should start with January 1st of next year"); }