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; } }
public void GivenParty_WhenSalesRepRelationshipIsUpdated_ThenCurrentSalesRepsAreUpdated() { var salesRep1 = new PersonBuilder(this.Session).WithLastName("salesRep1").Build(); var salesRep2 = new PersonBuilder(this.Session).WithLastName("salesRep2").Build(); var salesRep3 = new PersonBuilder(this.Session).WithLastName("salesRep3").Build(); var organisation = new OrganisationBuilder(this.Session).WithName("customer").Build(); var salesRepRelationship1 = new SalesRepRelationshipBuilder(this.Session) .WithCustomer(organisation) .WithSalesRepresentative(salesRep1) .WithFromDate(DateTimeFactory.CreateDate(2010, 01, 01)) .Build(); this.Session.Derive(); Assert.Equal(1, organisation.CurrentSalesReps.Count); Assert.Contains(salesRep1, organisation.CurrentSalesReps); new SalesRepRelationshipBuilder(this.Session) .WithCustomer(organisation) .WithSalesRepresentative(salesRep2) .WithFromDate(DateTimeFactory.CreateDate(2010, 01, 01)) .Build(); this.Session.Derive(); Assert.Equal(2, organisation.CurrentSalesReps.Count); Assert.Contains(salesRep1, organisation.CurrentSalesReps); Assert.Contains(salesRep2, organisation.CurrentSalesReps); salesRepRelationship1.ThroughDate = DateTimeFactory.CreateDate(2010, 12, 31); this.Session.Derive(); Assert.Equal(1, organisation.CurrentSalesReps.Count); Assert.Contains(salesRep2, organisation.CurrentSalesReps); new SalesRepRelationshipBuilder(this.Session) .WithCustomer(organisation) .WithSalesRepresentative(salesRep3) .WithProductCategory(new ProductCategoryBuilder(this.Session) .WithName("category") .Build()) .Build(); this.Session.Derive(); Assert.Equal(2, organisation.CurrentSalesReps.Count); Assert.Contains(salesRep2, organisation.CurrentSalesReps); Assert.Contains(salesRep3, organisation.CurrentSalesReps); }
public void GivenInternalOrganisationWithCustomFiscalYearStartMonthAndNotExistActualAccountingPeriod_WhenStartingNewFiscalYear_ThenAccountingPeriodsAreCreated() { this.InstantiateObjects(this.Session); var organisation = new OrganisationBuilder(this.Session) .WithIsInternalOrganisation(true) .WithDoAccounting(true) .WithName("Internal") .WithFiscalYearStartMonth(05) .WithFiscalYearStartDay(15) .Build(); organisation.StartNewFiscalYear(); var fromDate = DateTimeFactory.CreateDate(this.Session.Now().Year, 05, 15).Date; var month = organisation.ActualAccountingPeriod; Assert.Equal(1, month.PeriodNumber); Assert.Equal(new TimeFrequencies(this.Session).Month, month.Frequency); Assert.Equal(fromDate, month.FromDate); Assert.Equal(fromDate.AddMonths(1).AddSeconds(-1).Date, month.ThroughDate); Assert.True(month.ExistParent); var trimester = month.Parent; Assert.Equal(1, trimester.PeriodNumber); Assert.Equal(new TimeFrequencies(this.Session).Trimester, trimester.Frequency); Assert.Equal(fromDate, trimester.FromDate); Assert.Equal(fromDate.AddMonths(3).AddSeconds(-1).Date, trimester.ThroughDate); Assert.True(trimester.ExistParent); var semester = trimester.Parent; Assert.Equal(1, semester.PeriodNumber); Assert.Equal(new TimeFrequencies(this.Session).Semester, semester.Frequency); Assert.Equal(fromDate, semester.FromDate); Assert.Equal(fromDate.AddMonths(6).AddSeconds(-1).Date, semester.ThroughDate); Assert.True(semester.ExistParent); var year = semester.Parent; Assert.Equal(1, year.PeriodNumber); Assert.Equal(new TimeFrequencies(this.Session).Year, year.Frequency); Assert.Equal(fromDate, year.FromDate); Assert.Equal(fromDate.AddMonths(12).AddSeconds(-1).Date, year.ThroughDate); Assert.False(year.ExistParent); Assert.True(organisation.ExistActualAccountingPeriod); }
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); }
public void GivenOrganisation_WhenActiveContactRelationship_ThenOrganisationCurrentOrganisationContactRelationshipsContainsOrganisation() { var contact = new PersonBuilder(this.Session).WithLastName("organisationContact").Build(); var organisation = new OrganisationBuilder(this.Session).WithName("organisation").Build(); new CustomerRelationshipBuilder(this.Session) .WithCustomer(organisation) .WithFromDate(DateTimeFactory.CreateDate(2010, 01, 01)) .Build(); new OrganisationContactRelationshipBuilder(this.Session) .WithContact(contact) .WithOrganisation(organisation) .WithFromDate(DateTime.UtcNow.Date) .Build(); this.Session.Derive(); Assert.Equal(contact.CurrentOrganisationContactRelationships[0].Organisation, organisation); Assert.Equal(0, contact.InactiveOrganisationContactRelationships.Count); }
public void GivenSalesAgreement_WhenDeriving_ThenRequiredRelationsMustExist() { var builder = new SalesAgreementBuilder(this.Session); 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.WithDescription("sales agreement"); builder.Build(); Assert.False(this.Session.Derive(false).HasErrors); }
public void GivenPerson_WhenInActiveContactRelationship_ThenPersonInactiveOrganisationContactRelationshipsContainsPerson() { var contact = new PersonBuilder(this.Session).WithLastName("organisationContact").Build(); var organisation = new OrganisationBuilder(this.Session).WithName("organisation").Build(); new CustomerRelationshipBuilder(this.Session) .WithCustomer(organisation) .WithFromDate(DateTimeFactory.CreateDate(2010, 01, 01)) .Build(); new OrganisationContactRelationshipBuilder(this.Session) .WithContact(contact) .WithOrganisation(organisation) .WithFromDate(this.Session.Now().Date.AddDays(-1)) .WithThroughDate(this.Session.Now().Date.AddDays(-1)) .Build(); this.Session.Derive(); Assert.Equal(contact, contact.InactiveOrganisationContactRelationships[0].Contact); Assert.Empty(contact.CurrentOrganisationContactRelationships); }