public static void BaseStartNewFiscalYear(this InternalOrganisation @this, InternalOrganisationStartNewFiscalYear method)
        {
            var organisation = (Organisation)@this;

            if (organisation.IsInternalOrganisation)
            {
                if (@this.ExistActualAccountingPeriod && @this.ActualAccountingPeriod.Active)
                {
                    return;
                }

                var year = @this.Strategy.Session.Now().Year;
                if (@this.ExistActualAccountingPeriod)
                {
                    year = @this.ActualAccountingPeriod.FromDate.Date.Year + 1;
                }

                var fromDate = DateTimeFactory
                               .CreateDate(year, @this.FiscalYearStartMonth.Value, @this.FiscalYearStartDay.Value).Date;

                var yearPeriod = new AccountingPeriodBuilder(@this.Strategy.Session)
                                 .WithPeriodNumber(1)
                                 .WithFrequency(new TimeFrequencies(@this.Strategy.Session).Year)
                                 .WithFromDate(fromDate)
                                 .WithThroughDate(fromDate.AddYears(1).AddSeconds(-1).Date)
                                 .Build();

                var semesterPeriod = new AccountingPeriodBuilder(@this.Strategy.Session)
                                     .WithPeriodNumber(1)
                                     .WithFrequency(new TimeFrequencies(@this.Strategy.Session).Semester)
                                     .WithFromDate(fromDate)
                                     .WithThroughDate(fromDate.AddMonths(6).AddSeconds(-1).Date)
                                     .WithParent(yearPeriod)
                                     .Build();

                var trimesterPeriod = new AccountingPeriodBuilder(@this.Strategy.Session)
                                      .WithPeriodNumber(1)
                                      .WithFrequency(new TimeFrequencies(@this.Strategy.Session).Trimester)
                                      .WithFromDate(fromDate)
                                      .WithThroughDate(fromDate.AddMonths(3).AddSeconds(-1).Date)
                                      .WithParent(semesterPeriod)
                                      .Build();

                var monthPeriod = new AccountingPeriodBuilder(@this.Strategy.Session)
                                  .WithPeriodNumber(1)
                                  .WithFrequency(new TimeFrequencies(@this.Strategy.Session).Month)
                                  .WithFromDate(fromDate)
                                  .WithThroughDate(fromDate.AddMonths(1).AddSeconds(-1).Date)
                                  .WithParent(trimesterPeriod)
                                  .Build();

                @this.ActualAccountingPeriod = monthPeriod;
            }
        }
Exemplo n.º 2
0
        private AccountingPeriod BaseAddNextSemester(AccountingPeriod previousPeriod)
        {
            var newSemester = new AccountingPeriodBuilder(this.Strategy.Session)
                              .WithPeriodNumber(previousPeriod.PeriodNumber + 1)
                              .WithFrequency(new TimeFrequencies(this.Strategy.Session).Semester)
                              .WithFromDate(previousPeriod.FromDate.AddMonths(6).Date)
                              .WithThroughDate(previousPeriod.FromDate.AddMonths(12).AddSeconds(-1).Date)
                              .WithParent(previousPeriod.Parent)
                              .Build();

            return(newSemester);
        }
Exemplo n.º 3
0
        public void GivenAccountingPeriod_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var builder = new AccountingPeriodBuilder(this.Session);

            builder.Build();

            Assert.True(this.Session.Derive(false).HasErrors);

            this.Session.Rollback();

            builder.WithPeriodNumber(1);
            builder.Build();

            Assert.True(this.Session.Derive(false).HasErrors);

            this.Session.Rollback();

            builder.WithFrequency(new TimeFrequencies(this.Session).Day);
            builder.Build();

            Assert.True(this.Session.Derive(false).HasErrors);

            this.Session.Rollback();

            builder.WithFromDate(DateTimeFactory.CreateDate(2010, 12, 31));
            builder.Build();

            Assert.True(this.Session.Derive(false).HasErrors);

            this.Session.Rollback();

            builder.WithThroughDate(DateTimeFactory.CreateDate(2011, 12, 31));
            builder.Build();

            Assert.True(this.Session.Derive(false).HasErrors);

            this.Session.Rollback();

            builder.WithDescription("description");
            builder.Build();

            Assert.False(this.Session.Derive(false).HasErrors);
        }
Exemplo n.º 4
0
        public void GivenAccountingPeriod_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var builder = new AccountingPeriodBuilder(this.DatabaseSession);
            builder.Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            this.DatabaseSession.Rollback();

            builder.WithPeriodNumber(1);
            builder.Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            this.DatabaseSession.Rollback();

            builder.WithTimeFrequency(new TimeFrequencies(this.DatabaseSession).Day);
            builder.Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            this.DatabaseSession.Rollback();

            builder.WithFromDate(DateTimeFactory.CreateDate(2010, 12, 31));
            builder.Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            this.DatabaseSession.Rollback();

            builder.WithThroughDate(DateTimeFactory.CreateDate(2011, 12, 31));
            builder.Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            this.DatabaseSession.Rollback();

            builder.WithDescription("description");
            builder.Build();

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Exemplo n.º 5
0
        private AccountingPeriod BaseAddNextQuarter(AccountingPeriod previousPeriod)
        {
            var newQuarter = new AccountingPeriodBuilder(this.Strategy.Session)
                             .WithPeriodNumber(previousPeriod.PeriodNumber + 1)
                             .WithFrequency(new TimeFrequencies(this.Strategy.Session).Trimester)
                             .WithFromDate(previousPeriod.FromDate.AddMonths(3).Date)
                             .WithThroughDate(previousPeriod.FromDate.AddMonths(6).AddSeconds(-1).Date)
                             .Build();

            if (newQuarter.PeriodNumber == 3)
            {
                newQuarter.Parent = this.BaseAddNextSemester(previousPeriod.Parent);
            }
            else
            {
                newQuarter.Parent = previousPeriod.Parent;
            }

            return(newQuarter);
        }
Exemplo n.º 6
0
        private AccountingPeriod BaseAddNextMonth()
        {
            var allPeriods = new AccountingPeriods(this.Strategy.Session).Extent();

            allPeriods.Filter.AddEquals(this.Meta.Frequency, new TimeFrequencies(this.Strategy.Session).Month);
            allPeriods.AddSort(this.Meta.FromDate.RoleType, SortDirection.Descending);

            var mostRecentMonth = allPeriods.First;

            var newMonth = new AccountingPeriodBuilder(this.Strategy.Session)
                           .WithPeriodNumber(mostRecentMonth.PeriodNumber + 1)
                           .WithFrequency(new TimeFrequencies(this.Strategy.Session).Month)
                           .Build();

            if (newMonth.PeriodNumber < 13)
            {
                newMonth.FromDate    = mostRecentMonth.FromDate.AddMonths(1).Date;
                newMonth.ThroughDate = mostRecentMonth.FromDate.AddMonths(2).AddSeconds(-1).Date;
            }
            else
            {
                newMonth.FromDate    = mostRecentMonth.FromDate;
                newMonth.ThroughDate = mostRecentMonth.ThroughDate;
            }

            if (newMonth.PeriodNumber == 4 || newMonth.PeriodNumber == 7 || newMonth.PeriodNumber == 10)
            {
                newMonth.Parent = this.BaseAddNextQuarter(mostRecentMonth.Parent);
            }
            else
            {
                newMonth.Parent = mostRecentMonth.Parent;
            }

            return(newMonth);
        }
Exemplo n.º 7
0
        private AccountingPeriod AppsAddNextMonth()
        {
            var allPeriods = this.InternalOrganisationWhereAccountingPeriod.AccountingPeriods;
            allPeriods.Filter.AddEquals(this.Meta.TimeFrequency, new TimeFrequencies(this.Strategy.Session).Month);
            allPeriods.AddSort(this.Meta.FromDate.RoleType, SortDirection.Descending);

            var mostRecentMonth = allPeriods.First;

            var newMonth = new AccountingPeriodBuilder(this.Strategy.Session)
                .WithPeriodNumber(mostRecentMonth.PeriodNumber + 1)
                .WithTimeFrequency(new TimeFrequencies(this.Strategy.Session).Month)
                .Build();

            if (newMonth.PeriodNumber < 13)
            {
                newMonth.FromDate = mostRecentMonth.FromDate.AddMonths(1).Date;
                newMonth.ThroughDate = mostRecentMonth.FromDate.AddMonths(2).AddSeconds(-1).Date;
            }
            else
            {
                newMonth.FromDate = mostRecentMonth.FromDate;
                newMonth.ThroughDate = mostRecentMonth.ThroughDate;
            }

            if (newMonth.PeriodNumber == 4 || newMonth.PeriodNumber == 7 || newMonth.PeriodNumber == 10)
            {
                newMonth.Parent = this.AppsAddNextQuarter(mostRecentMonth.Parent);
            }
            else
            {
                newMonth.Parent = mostRecentMonth.Parent;
            }

            this.InternalOrganisationWhereAccountingPeriod.AddAccountingPeriod(newMonth);
            return newMonth;
        }
Exemplo n.º 8
0
        public void GivenAccountingPeriod_WhenBuild_ThenPostBuildRelationsMustExist()
        {
            var accountingPeriod = new AccountingPeriodBuilder(this.Session).Build();

            Assert.True(accountingPeriod.Active);
        }
Exemplo n.º 9
0
        public void AppsStartNewFiscalYear()
        {
            if (this.ExistActualAccountingPeriod && this.ActualAccountingPeriod.Active)
            {
                return;
            }

            int year = DateTime.UtcNow.Year;
            if (this.ExistActualAccountingPeriod)
            {
                year = this.ActualAccountingPeriod.FromDate.Date.Year + 1;
            }

            var fromDate = DateTimeFactory.CreateDate(year, this.FiscalYearStartMonth, this.FiscalYearStartDay).Date;

            var yearPeriod = new AccountingPeriodBuilder(this.Strategy.Session)
                .WithPeriodNumber(1)
                .WithTimeFrequency(new TimeFrequencies(this.Strategy.Session).Year)
                .WithFromDate(fromDate)
                .WithThroughDate(fromDate.AddYears(1).AddSeconds(-1).Date)
                .Build();

            var semesterPeriod = new AccountingPeriodBuilder(this.Strategy.Session)
                .WithPeriodNumber(1)
                .WithTimeFrequency(new TimeFrequencies(this.Strategy.Session).Semester)
                .WithFromDate(fromDate)
                .WithThroughDate(fromDate.AddMonths(6).AddSeconds(-1).Date)
                .WithParent(yearPeriod)
                .Build();

            var trimesterPeriod = new AccountingPeriodBuilder(this.Strategy.Session)
                .WithPeriodNumber(1)
                .WithTimeFrequency(new TimeFrequencies(this.Strategy.Session).Trimester)
                .WithFromDate(fromDate)
                .WithThroughDate(fromDate.AddMonths(3).AddSeconds(-1).Date)
                .WithParent(semesterPeriod)
                .Build();

            var monthPeriod = new AccountingPeriodBuilder(this.Strategy.Session)
                .WithPeriodNumber(1)
                .WithTimeFrequency(new TimeFrequencies(this.Strategy.Session).Month)
                .WithFromDate(fromDate)
                .WithThroughDate(fromDate.AddMonths(1).AddSeconds(-1).Date)
                .WithParent(trimesterPeriod)
                .Build();

            this.AddAccountingPeriod(yearPeriod);
            this.AddAccountingPeriod(semesterPeriod);
            this.AddAccountingPeriod(trimesterPeriod);
            this.AddAccountingPeriod(monthPeriod);

            this.ActualAccountingPeriod = monthPeriod;
        }
Exemplo n.º 10
0
        private AccountingPeriod AppsAddNextQuarter(AccountingPeriod previousPeriod)
        {
            var newQuarter = new AccountingPeriodBuilder(this.Strategy.Session)
                .WithPeriodNumber(previousPeriod.PeriodNumber + 1)
                .WithTimeFrequency(new TimeFrequencies(this.Strategy.Session).Trimester)
                .WithFromDate(previousPeriod.FromDate.AddMonths(3).Date)
                .WithThroughDate(previousPeriod.FromDate.AddMonths(6).AddSeconds(-1).Date)
                .Build();

            if (newQuarter.PeriodNumber == 3)
            {
                newQuarter.Parent = this.AppsAddNextSemester(previousPeriod.Parent);
            }
            else
            {
                newQuarter.Parent = previousPeriod.Parent;
            }

            this.InternalOrganisationWhereAccountingPeriod.AddAccountingPeriod(newQuarter);
            return newQuarter;
        }
Exemplo n.º 11
0
        public void GivenAccountingPeriod_WhenBuild_ThenPostBuildRelationsMustExist()
        {
            var accountingPeriod = new AccountingPeriodBuilder(this.DatabaseSession).Build();

            Assert.IsTrue(accountingPeriod.Active);
        }