Exemplo n.º 1
0
        /// <summary>
        /// Populate ledger with gifts and invoices, post batches, close periods and years, according to FNumberOfClosedPeriods
        /// </summary>
        /// <param name="datadirectory"></param>
        public static void PopulateData(string datadirectory)
        {
            int periodOverall = 0;
            int yearCounter   = 0;
            int period        = 1;
            int YearAD        = DateTime.Today.Year - (FNumberOfClosedPeriods / 12);

            SampleDataGiftBatches.LoadBatches(Path.Combine(datadirectory, "donations.csv"));
            SampleDataAccountsPayable.GenerateInvoices(Path.Combine(datadirectory, "invoices.csv"), YearAD);

            while (periodOverall <= FNumberOfClosedPeriods)
            {
                SampleDataGiftBatches.CreateGiftBatches(period);
                SampleDataGiftBatches.PostBatches(yearCounter, period, periodOverall == FNumberOfClosedPeriods ? 1 : 0);
                SampleDataAccountsPayable.PostAndPayInvoices(yearCounter, period, periodOverall == FNumberOfClosedPeriods ? 1 : 0);
                TLedgerInfo LedgerInfo = new TLedgerInfo(FLedgerNumber);

                if (periodOverall < FNumberOfClosedPeriods)
                {
                    TAccountPeriodInfo AccountingPeriodInfo =
                        new TAccountPeriodInfo(FLedgerNumber, period);
                    TLogging.Log("closing period at " + AccountingPeriodInfo.PeriodEndDate.ToShortDateString());

                    // run month end
                    TMonthEnd MonthEndOperator = new TMonthEnd(LedgerInfo);
                    MonthEndOperator.SetNextPeriod();

                    if (period == 12)
                    {
                        TYearEnd YearEndOperator = new TYearEnd(LedgerInfo);
                        // run year end
                        TVerificationResultCollection verificationResult = new TVerificationResultCollection();
                        TReallocation reallocation = new TReallocation(LedgerInfo);
                        reallocation.VerificationResultCollection = verificationResult;
                        reallocation.IsInInfoMode = false;
                        reallocation.RunOperation();

                        TGlmNewYearInit glmNewYearInit = new TGlmNewYearInit(LedgerInfo, yearCounter, YearEndOperator);
                        glmNewYearInit.VerificationResultCollection = verificationResult;
                        glmNewYearInit.IsInInfoMode = false;
                        glmNewYearInit.RunOperation();

                        YearAD++;
                        yearCounter++;
                        SampleDataAccountsPayable.GenerateInvoices(Path.Combine(datadirectory, "invoices.csv"), YearAD);
                        period = 0;
                    }
                }

                period++;
                periodOverall++;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Populate ledger with gifts and invoices, post batches, close periods and years, according to FNumberOfClosedPeriods
        /// </summary>
        public static void PopulateData(string datadirectory, bool smallNumber = false)
        {
            int periodOverall = 0;
            int yearCounter   = 0;
            int period        = 1;
            int YearAD        = DateTime.Today.Year - (FNumberOfClosedPeriods / 12);

            SampleDataGiftBatches.FLedgerNumber     = FLedgerNumber;
            SampleDataAccountsPayable.FLedgerNumber = FLedgerNumber;
            SampleDataGiftBatches.LoadBatches(Path.Combine(datadirectory, "donations.csv"), smallNumber);
            SampleDataAccountsPayable.GenerateInvoices(Path.Combine(datadirectory, "invoices.csv"), YearAD, smallNumber);

            while (periodOverall <= FNumberOfClosedPeriods)
            {
                TLogging.LogAtLevel(1, "working on year " + yearCounter.ToString() + " / period " + period.ToString());

                SampleDataGiftBatches.CreateGiftBatches(period);

                if (!SampleDataGiftBatches.PostBatches(yearCounter, period, (periodOverall == FNumberOfClosedPeriods) ? 1 : 0))
                {
                    throw new Exception("could not post gift batches");
                }

                if (!SampleDataAccountsPayable.PostAndPayInvoices(yearCounter, period, (periodOverall == FNumberOfClosedPeriods) ? 1 : 0))
                {
                    throw new Exception("could not post invoices");
                }

                TLedgerInfo LedgerInfo = new TLedgerInfo(FLedgerNumber);

                if (periodOverall < FNumberOfClosedPeriods)
                {
                    TAccountPeriodInfo AccountingPeriodInfo =
                        new TAccountPeriodInfo(FLedgerNumber, period);
                    TLogging.Log("closing period at " + AccountingPeriodInfo.PeriodEndDate.ToShortDateString());

                    // run month end
                    TMonthEnd MonthEndOperator = new TMonthEnd(LedgerInfo);
                    MonthEndOperator.SetNextPeriod(null);


                    if (period == 12)
                    {
                        TDBTransaction transaction  = null;
                        bool           SubmissionOK = false;

                        DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(
                            IsolationLevel.Serializable,
                            TEnforceIsolationLevel.eilMinimum,
                            ref transaction,
                            ref SubmissionOK,
                            delegate
                        {
                            TYearEnd YearEndOperator = new TYearEnd(LedgerInfo);
                            // run year end
                            TVerificationResultCollection verificationResult = new TVerificationResultCollection();
                            List <Int32> glBatches     = new List <int>();
                            TReallocation reallocation = new TReallocation(LedgerInfo, glBatches, transaction);
                            reallocation.VerificationResultCollection = verificationResult;
                            reallocation.IsInInfoMode = false;
                            reallocation.RunOperation();

                            TGlmNewYearInit glmNewYearInit = new TGlmNewYearInit(LedgerInfo, yearCounter, YearEndOperator, transaction);
                            glmNewYearInit.VerificationResultCollection = verificationResult;
                            glmNewYearInit.IsInInfoMode = false;
                            glmNewYearInit.RunOperation();
                            YearEndOperator.SetNextPeriod(transaction);

                            SampleDataLedger.InitExchangeRate();

                            YearAD++;
                            yearCounter++;
                            SampleDataAccountsPayable.GenerateInvoices(Path.Combine(datadirectory, "invoices.csv"), YearAD, smallNumber);
                            period       = 0;
                            SubmissionOK = true;
                        });
                    }
                }

                period++;
                periodOverall++;
            }
        }