public void GivenWorkEffortAndTimeEntries_WhenDeriving_ThenActualHoursDerived() { // Arrange var customer = new OrganisationBuilder(this.Session).WithName("Org1").Build(); var internalOrganisation = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation); new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); var workOrder = new WorkTaskBuilder(this.Session).WithName("Task").WithCustomer(customer).WithTakenBy(internalOrganisation).Build(); var employee = new PersonBuilder(this.Session).WithFirstName("Good").WithLastName("Worker").Build(); new EmploymentBuilder(this.Session).WithEmployee(employee).WithEmployer(internalOrganisation).Build(); this.Session.Derive(true); var yesterday = DateTimeFactory.CreateDateTime(this.Session.Now().AddDays(-1)); var laterYesterday = DateTimeFactory.CreateDateTime(yesterday.AddHours(3)); var today = DateTimeFactory.CreateDateTime(this.Session.Now()); var laterToday = DateTimeFactory.CreateDateTime(today.AddHours(4)); var tomorrow = DateTimeFactory.CreateDateTime(this.Session.Now().AddDays(1)); var laterTomorrow = DateTimeFactory.CreateDateTime(tomorrow.AddHours(6)); var timeEntry1 = new TimeEntryBuilder(this.Session) .WithRateType(new RateTypes(this.Session).StandardRate) .WithFromDate(yesterday) .WithThroughDate(laterYesterday) .WithWorkEffort(workOrder) .Build(); var timeEntry2 = new TimeEntryBuilder(this.Session) .WithRateType(new RateTypes(this.Session).StandardRate) .WithFromDate(today) .WithThroughDate(laterToday) .WithWorkEffort(workOrder) .Build(); var timeEntry3 = new TimeEntryBuilder(this.Session) .WithRateType(new RateTypes(this.Session).StandardRate) .WithFromDate(tomorrow) .WithThroughDate(laterTomorrow) .WithWorkEffort(workOrder) .Build(); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntry1); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntry2); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntry3); // Act this.Session.Derive(true); // Assert Assert.Equal(13.0M, workOrder.ActualHours); }
public void GivenTimeEntryWithFromDateAndAmountOfTime_WhenDeriving_ThenThroughDateDerived() { // Arrange var frequencies = new TimeFrequencies(this.Session); var workOrder = new WorkTaskBuilder(this.Session).WithName("Task").Build(); var employee = new PersonBuilder(this.Session).WithFirstName("Good").WithLastName("Worker").Build(); var employment = new EmploymentBuilder(this.Session).WithEmployee(employee).Build(); this.Session.Derive(true); var now = DateTimeFactory.CreateDateTime(this.Session.Now()); var hour = frequencies.Hour; var timeEntry = new TimeEntryBuilder(this.Session) .WithRateType(new RateTypes(this.Session).StandardRate) .WithFromDate(now) .WithAmountOfTime(4.0M) .WithTimeFrequency(hour) .WithWorkEffort(workOrder) .Build(); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntry); // Act this.Session.Derive(true); // Assert var timeSpan = timeEntry.ThroughDate - timeEntry.FromDate; Assert.Equal(4.00, timeSpan.Value.TotalHours); Assert.Equal(4.0M, timeEntry.ActualHours); //// Re-arrange timeEntry.RemoveThroughDate(); timeEntry.TimeFrequency = frequencies.Minute; // Act this.Session.Derive(true); // Assert timeSpan = timeEntry.ThroughDate - timeEntry.FromDate; Assert.Equal(4.00, timeSpan.Value.TotalMinutes); Assert.Equal(Math.Round(4.0M / 60.0M, M.TimeEntry.AmountOfTime.Scale ?? 2), timeEntry.ActualHours); //// Re-arrange timeEntry.RemoveThroughDate(); timeEntry.TimeFrequency = frequencies.Day; // Act this.Session.Derive(true); // Assert timeSpan = timeEntry.ThroughDate - timeEntry.FromDate; Assert.Equal(4.00, timeSpan.Value.TotalDays); Assert.Equal(4.00M * 24.00M, timeEntry.ActualHours); }
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 GivenTimeEntryWithRequiredAssignmentOrganisation_WhenDeriving_ThenWorkEffortPartyAssignmentSynced() { // Arrange var customer = new OrganisationBuilder(this.Session).WithName("Org1").Build(); var internalOrganisation = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation); new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); var workOrder = new WorkTaskBuilder(this.Session).WithName("Task").WithCustomer(customer).WithTakenBy(internalOrganisation).Build(); var employee = new PersonBuilder(this.Session).WithFirstName("Good").WithLastName("Worker").Build(); new EmploymentBuilder(this.Session).WithEmployee(employee).WithEmployer(internalOrganisation).Build(); internalOrganisation.RequireExistingWorkEffortPartyAssignment = true; this.Session.Derive(true); var today = DateTimeFactory.CreateDateTime(this.Session.Now()); var tomorrow = DateTimeFactory.CreateDateTime(this.Session.Now().AddDays(1)); var hour = new TimeFrequencies(this.Session).Hour; var timeEntry = new TimeEntryBuilder(this.Session) .WithRateType(new RateTypes(this.Session).StandardRate) .WithFromDate(today) .WithThroughDate(tomorrow) .WithTimeFrequency(hour) .WithWorkEffort(workOrder) .Build(); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntry); // Act var derivation = this.Session.Derive(false); // Assert Assert.True(derivation.HasErrors); Assert.Contains(derivation.Errors.SelectMany(e => e.Relations), r => r.AssociationType.Equals(M.WorkEffort.WorkEffortPartyAssignmentsWhereAssignment)); //// Re-Arrange employee.TimeSheetWhereWorker.RemoveTimeEntries(); var assignment = new WorkEffortPartyAssignmentBuilder(this.Session) .WithAssignment(workOrder) .WithParty(employee) .Build(); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntry); // Act derivation = this.Session.Derive(false); // Assert Assert.False(derivation.HasErrors); }
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 WorkTask_StateCancelled_TimeEntry() { var customer = new OrganisationBuilder(this.Session).WithName("Org1").Build(); var internalOrganisation = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation); new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); var workTask = new WorkTaskBuilder(this.Session).WithName("Activity").WithCustomer(customer).WithTakenBy(internalOrganisation).Build(); this.Session.Derive(); var employee = new PersonBuilder(this.Session).WithFirstName("Good").WithLastName("Worker").Build(); new EmploymentBuilder(this.Session).WithEmployee(employee).WithEmployer(internalOrganisation).Build(); this.Session.Derive(); var timeEntry = new TimeEntryBuilder(this.Session) .WithRateType(new RateTypes(this.Session).StandardRate) .WithFromDate(DateTimeFactory.CreateDateTime(this.Session.Now())) .WithTimeFrequency(new TimeFrequencies(this.Session).Hour) .WithWorkEffort(workTask) .Build(); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntry); this.Session.Derive(); workTask.Cancel(); this.Session.Derive(); Assert.Equal(new WorkEffortStates(this.Session).Cancelled, workTask.WorkEffortState); User user = this.Administrator; this.Session.SetUser(user); var acl = new AccessControlLists(this.Administrator)[timeEntry]; Assert.False(acl.CanWrite(M.TimeEntry.AmountOfTime)); }
public void GivenWorkEffortAndTimeEntry_WhenDeriving_ThenWorkEffortPartyAssignmentSynced() { // Arrange var customer = new OrganisationBuilder(this.Session).WithName("Org1").Build(); var internalOrganisation = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation); new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); var workOrder = new WorkTaskBuilder(this.Session).WithName("Task").WithCustomer(customer).WithTakenBy(internalOrganisation).Build(); var employee = new PersonBuilder(this.Session).WithFirstName("Good").WithLastName("Worker").Build(); new EmploymentBuilder(this.Session).WithEmployee(employee).WithEmployer(internalOrganisation).Build(); this.Session.Derive(true); var today = DateTimeFactory.CreateDateTime(this.Session.Now()); var tomorrow = DateTimeFactory.CreateDateTime(this.Session.Now().AddDays(1)); var hour = new TimeFrequencies(this.Session).Hour; var timeEntry = new TimeEntryBuilder(this.Session) .WithRateType(new RateTypes(this.Session).StandardRate) .WithFromDate(today) .WithThroughDate(tomorrow) .WithTimeFrequency(hour) .WithWorkEffort(workOrder) .Build(); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntry); // Act this.Session.Derive(true); // Assert var partyAssignment = workOrder.WorkEffortPartyAssignmentsWhereAssignment.First; Assert.Equal(workOrder, partyAssignment.Assignment); Assert.Equal(employee, partyAssignment.Party); Assert.False(partyAssignment.ExistFromDate); Assert.False(partyAssignment.ExistThroughDate); }
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 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); }
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 GivenParentWorkEffortAndTimeEntriesWithBillingRate_WhenInvoiced_ThenTimeEntryBillingRateIsUsed() { var frequencies = new TimeFrequencies(this.Session); var organisation = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation); var customer = new PersonBuilder(this.Session).WithLastName("Customer").Build(); new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(organisation).Build(); var employee = new PersonBuilder(this.Session).WithFirstName("Good").WithLastName("Worker").Build(); new EmploymentBuilder(this.Session).WithEmployee(employee).WithEmployer(organisation).Build(); var parentWorkOrder = new WorkTaskBuilder(this.Session).WithName("Parent Task").WithCustomer(customer).Build(); this.Session.Derive(true); var yesterday = DateTimeFactory.CreateDateTime(this.Session.Now().AddDays(-1)); var laterYesterday = DateTimeFactory.CreateDateTime(yesterday.AddHours(3)); var today = DateTimeFactory.CreateDateTime(this.Session.Now()); var laterToday = DateTimeFactory.CreateDateTime(today.AddHours(4)); var tomorrow = DateTimeFactory.CreateDateTime(this.Session.Now().AddDays(1)); var laterTomorrow = DateTimeFactory.CreateDateTime(tomorrow.AddHours(6)); var timeEntryYesterday = new TimeEntryBuilder(this.Session) .WithRateType(new RateTypes(this.Session).StandardRate) .WithFromDate(yesterday) .WithThroughDate(laterYesterday) .WithWorkEffort(parentWorkOrder) .WithAssignedBillingRate(10) .Build(); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryYesterday); var timeEntryToday = new TimeEntryBuilder(this.Session) .WithRateType(new RateTypes(this.Session).StandardRate) .WithFromDate(today) .WithThroughDate(laterToday) .WithWorkEffort(parentWorkOrder) .WithAssignedBillingRate(12) .Build(); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryToday); var childWorkOrder = new WorkTaskBuilder(this.Session).WithName("Child Task").WithCustomer(customer).Build(); parentWorkOrder.AddChild(childWorkOrder); var timeEntryTomorrow = new TimeEntryBuilder(this.Session) .WithRateType(new RateTypes(this.Session).StandardRate) .WithFromDate(tomorrow) .WithThroughDate(laterTomorrow) .WithWorkEffort(childWorkOrder) .WithAssignedBillingRate(14) .Build(); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryTomorrow); parentWorkOrder.Complete(); this.Session.Derive(true); parentWorkOrder.Invoice(); var salesInvoice = customer.SalesInvoicesWhereBillToCustomer.First; Assert.Equal(3, salesInvoice.InvoiceItems.Length); Assert.Equal(10, timeEntryYesterday.TimeEntryBillingsWhereTimeEntry.First.InvoiceItem.AssignedUnitPrice); Assert.Equal(3, timeEntryYesterday.TimeEntryBillingsWhereTimeEntry.First.InvoiceItem.Quantity); Assert.Equal(12, timeEntryToday.TimeEntryBillingsWhereTimeEntry.First.InvoiceItem.AssignedUnitPrice); Assert.Equal(4, timeEntryToday.TimeEntryBillingsWhereTimeEntry.First.InvoiceItem.Quantity); Assert.Equal(14, timeEntryTomorrow.TimeEntryBillingsWhereTimeEntry.First.InvoiceItem.AssignedUnitPrice); Assert.Equal(6, timeEntryTomorrow.TimeEntryBillingsWhereTimeEntry.First.InvoiceItem.Quantity); }
public void GivenWorkEffortAndTimeEntries_WhenDeriving_ThenActualStartAndCompletionDerived() { // Arrange var frequencies = new TimeFrequencies(this.Session); var workOrder = new WorkTaskBuilder(this.Session).WithName("Task").Build(); var employee = new PersonBuilder(this.Session).WithFirstName("Good").WithLastName("Worker").Build(); var employment = new EmploymentBuilder(this.Session).WithEmployee(employee).Build(); this.Session.Derive(true); var yesterday = DateTimeFactory.CreateDateTime(this.Session.Now().AddDays(-1)); var laterYesterday = DateTimeFactory.CreateDateTime(yesterday.AddHours(3)); var today = DateTimeFactory.CreateDateTime(this.Session.Now()); var laterToday = DateTimeFactory.CreateDateTime(today.AddHours(4)); var tomorrow = DateTimeFactory.CreateDateTime(this.Session.Now().AddDays(1)); var laterTomorrow = DateTimeFactory.CreateDateTime(tomorrow.AddHours(6)); var timeEntryToday = new TimeEntryBuilder(this.Session) .WithRateType(new RateTypes(this.Session).StandardRate) .WithFromDate(today) .WithThroughDate(laterToday) .WithWorkEffort(workOrder) .Build(); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryToday); // Act this.Session.Derive(true); // Assert Assert.Equal(today, workOrder.ActualStart); Assert.Equal(laterToday, workOrder.ActualCompletion); //// Re-arrange var timeEntryYesterday = new TimeEntryBuilder(this.Session) .WithRateType(new RateTypes(this.Session).StandardRate) .WithFromDate(yesterday) .WithThroughDate(laterYesterday) .WithWorkEffort(workOrder) .Build(); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryYesterday); // Act this.Session.Derive(true); // Assert Assert.Equal(yesterday, workOrder.ActualStart); Assert.Equal(laterToday, workOrder.ActualCompletion); //// Re-arrange var timeEntryTomorrow = new TimeEntryBuilder(this.Session) .WithRateType(new RateTypes(this.Session).StandardRate) .WithFromDate(tomorrow) .WithThroughDate(laterTomorrow) .WithTimeFrequency(frequencies.Minute) .WithWorkEffort(workOrder) .Build(); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryTomorrow); // Act this.Session.Derive(true); // Assert Assert.Equal(yesterday, workOrder.ActualStart); Assert.Equal(laterTomorrow, workOrder.ActualCompletion); }
public void GivenWorkEffortAndPartsUsed_WhenInvoiced_ThenPartsAreInvoiced() { var organisation = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation); var customerEmail = new PartyContactMechanismBuilder(this.Session) .WithContactMechanism(new EmailAddressBuilder(this.Session).WithElectronicAddressString($"*****@*****.**").Build()) .WithContactPurpose(new ContactMechanismPurposes(this.Session).BillingAddress) .WithUseAsDefault(true) .Build(); var customer = new PersonBuilder(this.Session).WithLastName("Customer").WithPartyContactMechanism(customerEmail).Build(); new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(organisation).Build(); var employee = new PersonBuilder(this.Session).WithFirstName("Good").WithLastName("Worker").Build(); new EmploymentBuilder(this.Session).WithEmployee(employee).WithEmployer(organisation).Build(); var yesterday = DateTimeFactory.CreateDateTime(this.Session.Now().AddDays(-1)); var today = DateTimeFactory.CreateDateTime(this.Session.Now()); var laterToday = DateTimeFactory.CreateDateTime(today.AddHours(4)); var tomorrow = DateTimeFactory.CreateDateTime(this.Session.Now().AddDays(1)); var part1 = this.CreatePart("P1"); new InventoryItemTransactionBuilder(this.Session) .WithPart(part1) .WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment) .WithQuantity(11) .Build(); var part1BasePriceYesterday = new BasePriceBuilder(this.Session) .WithDescription("baseprice part1") .WithPrice(9) .WithPart(part1) .WithFromDate(yesterday) .WithThroughDate(today) .Build(); var part1BasePriceToday = new BasePriceBuilder(this.Session) .WithDescription("baseprice part1") .WithPrice(10) .WithPart(part1) .WithFromDate(today) .WithThroughDate(tomorrow) .Build(); var part1BasePriceTomorrow = new BasePriceBuilder(this.Session) .WithDescription("baseprice part1") .WithPrice(11) .WithPart(part1) .WithFromDate(tomorrow) .Build(); var workOrder = new WorkTaskBuilder(this.Session).WithName("Task").WithCustomer(customer).Build(); this.Session.Derive(true); var timeEntryToday = new TimeEntryBuilder(this.Session) .WithRateType(new RateTypes(this.Session).StandardRate) .WithFromDate(today) .WithThroughDate(laterToday) .WithWorkEffort(workOrder) .WithBillingRate(12) .Build(); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryToday); new WorkEffortInventoryAssignmentBuilder(this.Session).WithAssignment(workOrder).WithInventoryItem(part1.InventoryItemsWherePart.First).WithQuantity(3).Build(); this.Session.Derive(true); workOrder.Complete(); this.Session.Derive(true); workOrder.Invoice(); this.Session.Derive(true); var salesInvoice = customer.SalesInvoicesWhereBillToCustomer.First; Assert.Equal(2, salesInvoice.InvoiceItems.Length); Assert.Equal(10, workOrder.WorkEffortBillingsWhereWorkEffort.First.InvoiceItem.ActualUnitPrice); Assert.Equal(30, workOrder.WorkEffortBillingsWhereWorkEffort.First.InvoiceItem.TotalBasePrice); }
public void GivenWorkEffortAndTimeEntriesWithoutBillingRate_WhenInvoiced_ThenWorkEffortRateIsUsed() { var frequencies = new TimeFrequencies(this.Session); var organisation = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation); var customer = new PersonBuilder(this.Session).WithLastName("Customer").Build(); new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(organisation).Build(); var employee = new PersonBuilder(this.Session).WithFirstName("Good").WithLastName("Worker").Build(); new EmploymentBuilder(this.Session).WithEmployee(employee).WithEmployer(organisation).Build(); var workOrder = new WorkTaskBuilder(this.Session).WithName("Task").WithCustomer(customer).Build(); new WorkEffortAssignmentRateBuilder(this.Session).WithWorkEffort(workOrder).WithRate(10).WithRateType(new RateTypes(this.Session).StandardRate).Build(); this.Session.Derive(true); var yesterday = DateTimeFactory.CreateDateTime(this.Session.Now().AddDays(-1)); var laterYesterday = DateTimeFactory.CreateDateTime(yesterday.AddHours(3)); var today = DateTimeFactory.CreateDateTime(this.Session.Now()); var laterToday = DateTimeFactory.CreateDateTime(today.AddHours(4)); var tomorrow = DateTimeFactory.CreateDateTime(this.Session.Now().AddDays(1)); var laterTomorrow = DateTimeFactory.CreateDateTime(tomorrow.AddHours(6)); var timeEntryYesterday = new TimeEntryBuilder(this.Session) .WithRateType(new RateTypes(this.Session).StandardRate) .WithFromDate(yesterday) .WithThroughDate(laterYesterday) .WithWorkEffort(workOrder) .Build(); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryYesterday); var timeEntryToday = new TimeEntryBuilder(this.Session) .WithRateType(new RateTypes(this.Session).StandardRate) .WithFromDate(today) .WithThroughDate(laterToday) .WithWorkEffort(workOrder) .Build(); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryToday); var timeEntryTomorrow = new TimeEntryBuilder(this.Session) .WithRateType(new RateTypes(this.Session).StandardRate) .WithFromDate(tomorrow) .WithThroughDate(laterTomorrow) .WithTimeFrequency(frequencies.Minute) .WithWorkEffort(workOrder) .Build(); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryTomorrow); workOrder.Complete(); this.Session.Derive(true); workOrder.Invoice(); var salesInvoice = customer.SalesInvoicesWhereBillToCustomer.First; Assert.Single(salesInvoice.InvoiceItems); Assert.Equal(130, salesInvoice.InvoiceItems.First().ActualUnitPrice); // (3 * 10) + (4 * 10) + (6 * 10) }
public void GivenWorkEffortPrintDocument_WhenPrinting_ThenMediaCreated() { // Arrange var frequencies = new TimeFrequencies(this.Session); var purposes = new ContactMechanismPurposes(this.Session); //// Customer Contact and Address Data var customer = new OrganisationBuilder(this.Session).WithName("Customer").Build(); var customerContact = new PersonBuilder(this.Session).WithFirstName("Customer").WithLastName("Contact").Build(); var organisation = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation); var customerRelation = new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(organisation).Build(); var usa = new Countries(this.Session).Extent().First(c => c.IsoCode.Equals("US")); var michigan = new StateBuilder(this.Session).WithName("Michigan").WithCountry(usa).Build(); var northville = new CityBuilder(this.Session).WithName("Northville").WithState(michigan).Build(); var postalCode = new PostalCodeBuilder(this.Session).WithCode("48167").Build(); var billingAddress = this.CreatePostalAddress("Billing Address", "123 Street", "Suite S1", northville, postalCode); var shippingAddress = this.CreatePostalAddress("Shipping Address", "123 Street", "Dock D1", northville, postalCode); var phone = new TelecommunicationsNumberBuilder(this.Session).WithCountryCode("1").WithAreaCode("616").WithContactNumber("774-2000").Build(); customer.AddPartyContactMechanism(this.CreatePartyContactMechanism(purposes.BillingAddress, billingAddress)); customer.AddPartyContactMechanism(this.CreatePartyContactMechanism(purposes.ShippingAddress, shippingAddress)); customerContact.AddPartyContactMechanism(this.CreatePartyContactMechanism(purposes.GeneralPhoneNumber, phone)); //// Work Effort Data var salesPerson = new PersonBuilder(this.Session).WithFirstName("Sales").WithLastName("Person").Build(); var salesRepRelation = new SalesRepRelationshipBuilder(this.Session).WithCustomer(customer).WithSalesRepresentative(salesPerson).Build(); var salesOrder = this.CreateSalesOrder(customer, organisation); var workOrder = this.CreateWorkEffort(organisation, customer, customerContact, salesOrder.SalesOrderItems.First); var employee = new PersonBuilder(this.Session).WithFirstName("Good").WithLastName("Worker").Build(); var employment = new EmploymentBuilder(this.Session).WithEmployee(employee).WithEmployer(organisation).Build(); var salesOrderItem = salesOrder.SalesOrderItems.First; salesOrder.AddValidOrderItem(salesOrderItem); //// Work Effort Inventory Assignmets var part1 = this.CreatePart("P1"); var part2 = this.CreatePart("P2"); var part3 = this.CreatePart("P3"); this.Session.Derive(true); var inventoryAssignment1 = this.CreateInventoryAssignment(workOrder, part1, 11); var inventoryAssignment2 = this.CreateInventoryAssignment(workOrder, part2, 12); var inventoryAssignment3 = this.CreateInventoryAssignment(workOrder, part3, 13); //// Work Effort Time Entries var yesterday = DateTimeFactory.CreateDateTime(this.Session.Now().AddDays(-1)); var laterYesterday = DateTimeFactory.CreateDateTime(yesterday.AddHours(3)); var today = DateTimeFactory.CreateDateTime(this.Session.Now()); var laterToday = DateTimeFactory.CreateDateTime(today.AddHours(4)); var tomorrow = DateTimeFactory.CreateDateTime(this.Session.Now().AddDays(1)); var laterTomorrow = DateTimeFactory.CreateDateTime(tomorrow.AddHours(6)); var timeEntryYesterday = this.CreateTimeEntry(yesterday, laterYesterday, frequencies.Day, workOrder); var timeEntryToday = this.CreateTimeEntry(today, laterToday, frequencies.Hour, workOrder); var timeEntryTomorrow = this.CreateTimeEntry(tomorrow, laterTomorrow, frequencies.Minute, workOrder); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryYesterday); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryToday); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryTomorrow); this.Session.Derive(true); // Act workOrder.Print(); this.Session.Derive(); this.Session.Commit(); // Assert Assert.True(workOrder.PrintDocument.ExistMedia); var desktopDir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); var outputFile = System.IO.File.Create(System.IO.Path.Combine(desktopDir, "workTask.odt")); var stream = new System.IO.MemoryStream(workOrder.PrintDocument.Media.MediaContent.Data); stream.CopyTo(outputFile); stream.Close(); }