コード例 #1
0
        public static WorkTaskBuilder WithScheduledInternalWork(this WorkTaskBuilder @this, Organisation internalOrganisation)
        {
            var faker = @this.Session.Faker();

            var otherInternalOrganization = @this.Session.Extent <Organisation>().Except(new List <Organisation> {
                internalOrganisation
            }).FirstOrDefault();

            @this.WithTakenBy(internalOrganisation);
            @this.WithExecutedBy(internalOrganisation);
            @this.WithCustomer(otherInternalOrganization);
            @this.WithFacility(faker.Random.ListItem(internalOrganisation.FacilitiesWhereOwner));
            @this.WithName(faker.Lorem.Words().ToString());
            @this.WithDescription(faker.Lorem.Sentence());
            @this.WithComment(faker.Lorem.Sentence());
            @this.WithWorkDone(faker.Lorem.Sentence());
            @this.WithPriority(faker.Random.ListItem(@this.Session.Extent <Priority>()));
            @this.WithWorkEffortPurpose(faker.Random.ListItem(@this.Session.Extent <WorkEffortPurpose>()));
            @this.WithScheduledStart(@this.Session.Now().AddDays(7));
            @this.WithScheduledCompletion(@this.Session.Now().AddDays(10));
            @this.WithEstimatedHours(faker.Random.Int(7, 30));
            @this.WithElectronicDocument(new MediaBuilder(@this.Session).WithInFileName("doc1.en.pdf").WithInData(faker.Random.Bytes(1000)).Build());

            return(@this);
        }
コード例 #2
0
        public void GivenWorkEffort_WhenAddingRates_ThenRateForPartyIsNotAllowed()
        {
            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();

            // Calculating rates per party is not implemented yet
            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();

            var assignedParty = new WorkEffortPartyAssignmentBuilder(this.Session).WithAssignment(workOrder).WithParty(employee).Build();

            this.Session.Derive(true);

            var assignedRate = new WorkEffortAssignmentRateBuilder(this.Session)
                               .WithWorkEffort(workOrder)
                               .WithRate(1)
                               .WithRateType(new RateTypes(this.Session).StandardRate)
                               .Build();

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

            assignedParty.AddAssignmentRate(assignedRate);

            var derivation = this.Session.Derive(false);

            Assert.True(derivation.HasErrors);
            Assert.Contains(derivation.Errors.SelectMany(e => e.Relations), r => r.RoleType.Equals(M.WorkEffortPartyAssignment.AssignmentRates));
        }
コード例 #3
0
        public void GivenWorkEffortAndTimeEntry_WhenDeriving_ThenWorkEffortPartyAssignmentSynced()
        {
            // Arrange
            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 today    = DateTimeFactory.CreateDateTime(DateTime.UtcNow);
            var tomorrow = DateTimeFactory.CreateDateTime(DateTime.UtcNow.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);
        }
コード例 #4
0
        public void WorkTask_StateCompleted()
        {
            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();

            workTask.Complete();

            this.Session.Derive();

            Assert.Equal(new WorkEffortStates(this.Session).Completed, workTask.WorkEffortState);

            User user = this.Administrator;

            this.Session.SetUser(user);

            var acl = new AccessControlLists(this.Administrator)[workTask];

            Assert.True(acl.CanExecute(M.WorkEffort.Invoice));
            Assert.False(acl.CanExecute(M.WorkEffort.Cancel));
            Assert.False(acl.CanExecute(M.WorkEffort.Reopen));
            Assert.False(acl.CanExecute(M.WorkEffort.Complete));
        }
コード例 #5
0
        public void GivenTimeEntryWithFromAndThroughDates_WhenDeriving_ThenAmountOfTimeDerived()
        {
            // Arrange
            var frequencies = new TimeFrequencies(this.Session);

            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 now   = DateTimeFactory.CreateDateTime(this.Session.Now());
            var later = DateTimeFactory.CreateDateTime(now.AddHours(4));

            var timeEntry = new TimeEntryBuilder(this.Session)
                            .WithRateType(new RateTypes(this.Session).StandardRate)
                            .WithFromDate(now)
                            .WithThroughDate(later)
                            .WithTimeFrequency(frequencies.Hour)
                            .WithWorkEffort(workOrder)
                            .Build();

            employee.TimeSheetWhereWorker.AddTimeEntry(timeEntry);

            // Act
            this.Session.Derive(true);

            // Assert
            Assert.Equal(4.00M, timeEntry.AmountOfTime);
            Assert.Equal(4.00M, timeEntry.ActualHours);

            //// Re-arrange
            ((TimeEntryDerivedRoles)timeEntry).RemoveAmountOfTime();
            timeEntry.TimeFrequency = frequencies.Day;

            // Act
            this.Session.Derive(true);

            // Assert
            Assert.Equal(Math.Round(4.0M / 24.0M, M.TimeEntry.AmountOfTime.Scale ?? 2), timeEntry.AmountOfTime);
            Assert.Equal(4.00M, timeEntry.ActualHours);

            //// Re-arrange
            ((TimeEntryDerivedRoles)timeEntry).RemoveAmountOfTime();
            timeEntry.TimeFrequency = frequencies.Minute;

            // Act
            this.Session.Derive(true);

            // Assert
            Assert.Equal(4.0M * 60.0M, timeEntry.AmountOfTime);
            Assert.Equal(4.00M, timeEntry.ActualHours);
        }
コード例 #6
0
        public void GivenWorkTask_WhenBuild_ThenPreviousObjectStateIsNull()
        {
            var workEffort = new WorkTaskBuilder(this.Session).WithName("Activity").Build();

            this.Session.Derive();

            Assert.Null(workEffort.PreviousWorkEffortState);
        }
コード例 #7
0
        public void GivenTimeEntry_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            // 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 timeEntry = new TimeEntryBuilder(this.Session)
                            .WithRateType(new RateTypes(this.Session).StandardRate)
                            .Build();

            // Act
            var derivation    = this.Session.Derive(false);
            var originalCount = derivation.Errors.Count();

            // Assert
            Assert.True(derivation.HasErrors);

            //// Re-arrange
            var tomorrow = this.Session.Now().AddDays(1);

            timeEntry.ThroughDate = tomorrow;

            // Act
            derivation = this.Session.Derive(false);

            // Assert
            Assert.True(derivation.HasErrors);
            Assert.Equal(originalCount, derivation.Errors.Count());

            //// Re-arrange
            var workOrder = new WorkTaskBuilder(this.Session).WithName("Work").WithCustomer(customer).WithTakenBy(internalOrganisation).Build();

            timeEntry.WorkEffort = workOrder;

            // Act
            derivation = this.Session.Derive(false);

            // Assert
            Assert.True(derivation.HasErrors);
            Assert.Equal(originalCount - 1, derivation.Errors.Count());

            //// Re-arrange
            var worker = new PersonBuilder(this.Session).WithFirstName("Good").WithLastName("Worker").Build();

            new EmploymentBuilder(this.Session).WithEmployee(worker).WithEmployer(internalOrganisation).Build();

            derivation = this.Session.Derive(false);

            worker.TimeSheetWhereWorker.AddTimeEntry(timeEntry);

            // Act
            derivation = this.Session.Derive(false);

            // Assert
            Assert.False(derivation.HasErrors);
        }
コード例 #8
0
        public void WorkTask_StateFinished()
        {
            var mechelen        = new CityBuilder(this.Session).WithName("Mechelen").Build();
            var mechelenAddress = new PostalAddressBuilder(this.Session).WithPostalAddressBoundary(mechelen).WithAddress1("Haverwerf 15").Build();

            var billToMechelen = new PartyContactMechanismBuilder(this.Session)
                                 .WithContactMechanism(mechelenAddress)
                                 .WithContactPurpose(new ContactMechanismPurposes(this.Session).BillingAddress)
                                 .WithUseAsDefault(true)
                                 .Build();

            var customer             = new OrganisationBuilder(this.Session).WithName("Org1").WithPartyContactMechanism(billToMechelen).Build();
            var internalOrganisation = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation);

            new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(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();

            var workTask = new WorkTaskBuilder(this.Session).WithName("Activity").WithCustomer(customer).WithTakenBy(internalOrganisation).Build();

            var timeEntry = new TimeEntryBuilder(this.Session)
                            .WithRateType(new RateTypes(this.Session).StandardRate)
                            .WithFromDate(DateTimeFactory.CreateDateTime(this.Session.Now()))
                            .WithThroughDate(DateTimeFactory.CreateDateTime(this.Session.Now().AddHours(1)))
                            .WithTimeFrequency(new TimeFrequencies(this.Session).Hour)
                            .WithWorkEffort(workTask)
                            .Build();

            employee.TimeSheetWhereWorker.AddTimeEntry(timeEntry);

            this.Session.Derive();

            workTask.Complete();

            this.Session.Derive();

            workTask.Invoice();

            this.Session.Derive();

            Assert.Equal(new WorkEffortStates(this.Session).Finished, workTask.WorkEffortState);

            User user = this.Administrator;

            this.Session.SetUser(user);

            var acl = new AccessControlLists(this.Administrator)[workTask];

            Assert.False(acl.CanExecute(M.WorkEffort.Invoice));
            Assert.False(acl.CanExecute(M.WorkEffort.Cancel));
            Assert.False(acl.CanExecute(M.WorkEffort.Reopen));
            Assert.False(acl.CanExecute(M.WorkEffort.Complete));
        }
コード例 #9
0
        public void GivenWorkTask_WhenBuild_ThenLastObjectStateEqualsCurrencObjectState()
        {
            var workEffort = new WorkTaskBuilder(this.Session).WithName("Activity").Build();

            this.Session.Derive();

            Assert.Equal(new WorkEffortStates(this.Session).Created, workEffort.WorkEffortState);
            Assert.Equal(workEffort.LastWorkEffortState, workEffort.WorkEffortState);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        public void GivenWorkEffort_WhenAddingInventoryAssignment_ThenInventoryConsumptionCreated()
        {
            // 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 reasons = new InventoryTransactionReasons(this.Session);

            var workEffort = new WorkTaskBuilder(this.Session).WithName("Activity").WithCustomer(customer).WithTakenBy(internalOrganisation).Build();
            var part       = new NonUnifiedPartBuilder(this.Session)
                             .WithProductIdentification(new PartNumberBuilder(this.Session)
                                                        .WithIdentification("P1")
                                                        .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build())
                             .Build();

            this.Session.Derive(true);

            new InventoryItemTransactionBuilder(this.Session)
            .WithPart(part)
            .WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment)
            .WithQuantity(11)
            .Build();

            // Act
            this.Session.Derive(true);

            // Assert
            Assert.Empty(workEffort.WorkEffortInventoryAssignmentsWhereAssignment);
            Assert.True(workEffort.WorkEffortState.IsCreated);

            // Re-arrange
            var inventoryAssignment = new WorkEffortInventoryAssignmentBuilder(this.Session)
                                      .WithAssignment(workEffort)
                                      .WithInventoryItem(part.InventoryItemsWherePart.First)
                                      .WithQuantity(10)
                                      .Build();

            // Act
            this.Session.Derive(true);

            // Assert
            var transactions = inventoryAssignment.InventoryItemTransactions;

            Assert.Single(transactions);
            var transaction = transactions[0];

            Assert.Equal(part, transaction.Part);
            Assert.Equal(10, transaction.Quantity);
            Assert.Equal(reasons.Consumption, transaction.Reason);

            Assert.Equal(0, part.QuantityCommittedOut);
            Assert.Equal(1, part.QuantityOnHand);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        public void GivenWorkEffortWithInventoryAssignment_WhenCompletingThenCancelling_ThenInventoryTransactionsCancelled()
        {
            // Arrange
            var reasons = new InventoryTransactionReasons(this.Session);

            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 workEffort = new WorkTaskBuilder(this.Session).WithName("Activity").WithCustomer(customer).WithTakenBy(internalOrganisation).Build();
            var part       = new NonUnifiedPartBuilder(this.Session)
                             .WithProductIdentification(new PartNumberBuilder(this.Session)
                                                        .WithIdentification("P1")
                                                        .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build())
                             .Build();

            this.Session.Derive(true);

            new InventoryItemTransactionBuilder(this.Session)
            .WithPart(part)
            .WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment)
            .WithQuantity(10)
            .Build();

            this.Session.Derive(true);

            var inventoryAssignment = new WorkEffortInventoryAssignmentBuilder(this.Session)
                                      .WithAssignment(workEffort)
                                      .WithInventoryItem(part.InventoryItemsWherePart.First)
                                      .WithQuantity(10)
                                      .Build();

            this.Session.Derive(true);

            // Act
            workEffort.Complete();
            this.Session.Derive(true);

            workEffort.Cancel();
            this.Session.Derive(true);

            // Assert
            var transactions            = inventoryAssignment.InventoryItemTransactions;
            var consumption             = transactions.First(t => t.Reason.Equals(reasons.Consumption) && (t.Quantity > 0));
            var consumptionCancellation = transactions.First(t => t.Reason.Equals(reasons.Consumption) && (t.Quantity < 0));

            Assert.Equal(2, transactions.Count);

            Assert.Equal(10, consumption.Quantity);
            Assert.Equal(-10, consumptionCancellation.Quantity);

            Assert.Equal(10, part.QuantityOnHand);
        }
コード例 #15
0
        public void GivenWorkTask_WhenBuild_ThenPreviousObjectStateIsNull()
        {
            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 workEffort = new WorkTaskBuilder(this.Session).WithName("Activity").WithCustomer(customer).WithTakenBy(internalOrganisation).Build();

            this.Session.Derive();

            Assert.Null(workEffort.PreviousWorkEffortState);
        }
コード例 #16
0
        public void GivenWorkTask_WhenBuild_ThenLastObjectStateEqualsCurrencObjectState()
        {
            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 workEffort = new WorkTaskBuilder(this.Session).WithName("Activity").WithCustomer(customer).WithTakenBy(internalOrganisation).Build();

            this.Session.Derive();

            Assert.Equal(new WorkEffortStates(this.Session).Created, workEffort.WorkEffortState);
            Assert.Equal(workEffort.LastWorkEffortState, workEffort.WorkEffortState);
        }
コード例 #17
0
        /// <summary>
        /// 指定した日付の予定をタスクとして取り込みます
        /// </summary>
        /// <param name="ymdString">取り込み対象日付</param>
        /// <returns></returns>
        public async Task <WorkTask[]> ImportToTaskAsync(YmdString ymdString)
        {
            try
            {
                _Logger.Info($"[ScheduleImporter] ▼スケジュール取り込み開始 target=[{ymdString}]");

                // イベントの取得
                var fromDateTime = ymdString.ToDateTime().Value;
                var toDateTime   = fromDateTime.AddDays(1).AddMinutes(-1);
                var targetKinds  = _WorkTaskBuilderConfig.EventMappers.Select(e => e.EventKind).ToArray();
                var events       = await _ScheduledEventRepository.FetchScheduledEventsAsync(targetKinds, fromDateTime, toDateTime);

                if (events == null)
                {
                    _Logger.Error("[ScheduleImporter] unknown error");
                    return(Array.Empty <WorkTask>());
                }

                // 未登録のイベントを取り込み
                var registedWorkTasks = _WorkTaskRepository.SelectByImportKeys(events.Select(e => e.Id).ToArray());

                var list    = new List <WorkTask>();
                var builder = new WorkTaskBuilder(_WorkTaskBuilderConfig, _ScheduleTitleMaps);
                foreach (var @event in events)
                {
                    // 登録済みは無視する
                    if (registedWorkTasks.Any(t => t.ImportKey == @event.Id))
                    {
                        continue;
                    }

                    // 未登録ならスケジュールに合わせて登録
                    (WorkTask workTask, ImportedTask importedTask) = builder.Build(@event);
                    workTask = _WorkTaskRepository.AddForSchedule(workTask, importedTask);
                    list.Add(workTask);

                    var newWorkingTime = WorkingTimeRange.FromScheduledEvent(workTask.Id, @event);
                    _WorkingTimeRangeRepository.Add(newWorkingTime);
                }

                return(list.ToArray());
            }
            finally
            {
                _Logger.Info($"[ScheduleImporter] ▲スケジュール取り込み終了 target=[{ymdString}]");
            }
        }
コード例 #18
0
        public void GivenWorkEffortWithInventoryAssignment_WhenCancelling_ThenInventoryReservationCancelled()
        {
            // Arrange
            var reasons = new InventoryTransactionReasons(this.Session);

            var workEffort = new WorkTaskBuilder(this.Session).WithName("Activity").Build();
            var part       = new NonUnifiedPartBuilder(this.Session)
                             .WithProductIdentification(new PartNumberBuilder(this.Session)
                                                        .WithIdentification("P1")
                                                        .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build())
                             .Build();

            new InventoryItemTransactionBuilder(this.Session)
            .WithPart(part)
            .WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment)
            .WithQuantity(10)
            .Build();

            this.Session.Derive(true);

            var inventoryAssignment = new WorkEffortInventoryAssignmentBuilder(this.Session)
                                      .WithAssignment(workEffort)
                                      .WithInventoryItem(part.InventoryItemsWherePart.First)
                                      .WithQuantity(10)
                                      .Build();

            this.Session.Derive(true);

            // Act
            workEffort.Cancel();
            this.Session.Derive(true);

            // Assert
            var transactions = inventoryAssignment.InventoryItemTransactions;

            Assert.Equal(2, transactions.Count);

            var reservation             = transactions.First(t => t.Reason.Equals(reasons.Reservation) && (t.Quantity > 0));
            var reservationCancellation = transactions.First(t => t.Reason.Equals(reasons.Reservation) && (t.Quantity < 0));

            Assert.Equal(10, reservation.Quantity);
            Assert.Equal(-10, reservationCancellation.Quantity);

            Assert.Equal(0, part.QuantityCommittedOut);
        }
コード例 #19
0
        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));
        }
コード例 #20
0
        public void WorkTask_StateFinished()
        {
            var mechelen        = new CityBuilder(this.Session).WithName("Mechelen").Build();
            var mechelenAddress = new PostalAddressBuilder(this.Session).WithPostalAddressBoundary(mechelen).WithAddress1("Haverwerf 15").Build();

            var billToMechelen = new PartyContactMechanismBuilder(this.Session)
                                 .WithContactMechanism(mechelenAddress)
                                 .WithContactPurpose(new ContactMechanismPurposes(this.Session).BillingAddress)
                                 .WithUseAsDefault(true)
                                 .Build();

            var customer             = new OrganisationBuilder(this.Session).WithName("Org1").WithPartyContactMechanism(billToMechelen).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();

            workTask.Complete();

            this.Session.Derive();

            workTask.Invoice();

            this.Session.Derive();

            Assert.Equal(new WorkEffortStates(this.Session).Finished, workTask.WorkEffortState);

            User user = this.Administrator;

            this.Session.SetUser(user);

            var acl = new AccessControlLists(this.Administrator)[workTask];

            Assert.False(acl.CanExecute(M.WorkEffort.Invoice));
            Assert.False(acl.CanExecute(M.WorkEffort.Cancel));
            Assert.False(acl.CanExecute(M.WorkEffort.Reopen));
            Assert.False(acl.CanExecute(M.WorkEffort.Complete));
        }
コード例 #21
0
        public void WorkTaskNewInSession()
        {
            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("worktask").WithCustomer(customer).Build();

            this.Session.Derive();

            var employee = new Employments(this.Session).Extent().Select(v => v.Employee).First();

            this.Session.SetUser(employee);

            Assert.True(workTask.Strategy.IsNewInSession);

            var acl = new AccessControlLists(employee)[workTask];

            Assert.True(acl.CanRead(M.WorkTask.Name));
            Assert.True(acl.CanWrite(M.WorkTask.Name));
        }
コード例 #22
0
        public async Task <WorkTask[]> ImportToTaskAsync(YmdString ymdString)
        {
            // イベントの取得
            var fromDateTime = ymdString.ToDateTime().Value;
            var toDateTime   = fromDateTime.AddDays(1).AddMinutes(-1);
            var targetKinds  = _WorkTaskBuilderConfig.EventMappers.Select(e => e.EventKind).ToArray();
            var events       = await _ScheduledEventRepository.FetchScheduledEventsAsync(targetKinds, fromDateTime, toDateTime);

            if (events == null)
            {
                return(new WorkTask[0]);
            }

            // 未登録のイベントを取り込み
            var registedWorkTasks = _WorkTaskRepository.SelectByImportKeys(events.Select(e => e.Id).ToArray());

            var list    = new List <WorkTask>();
            var builder = new WorkTaskBuilder(_WorkTaskBuilderConfig, _ScheduleTitleMaps);

            foreach (var @event in events)
            {
                // 登録済みは無視する
                if (registedWorkTasks.Any(t => t.ImportKey == @event.Id))
                {
                    continue;
                }

                // 未登録ならスケジュールに合わせて登録
                var workTask = builder.Build(@event);
                workTask = _WorkTaskRepository.Add(workTask);
                list.Add(workTask);

                var newWorkingTime = WorkingTimeRange.FromScheduledEvent(workTask.Id, @event);
                _WorkingTimeRangeRepository.Add(newWorkingTime);
            }

            return(list.ToArray());
        }
コード例 #23
0
        public void GivenWorkTask_WhenBuildingWithTakenBy_ThenWorkEffortNumberAssigned()
        {
            // Arrange
            var organisation1 = new OrganisationBuilder(this.Session).WithName("Org1").WithIsInternalOrganisation(true).Build();
            var organisation2 = new OrganisationBuilder(this.Session).WithName("Org2").WithIsInternalOrganisation(true).Build();
            var workOrder     = new WorkTaskBuilder(this.Session).WithName("Task").Build();

            // Act
            var derivation = this.Session.Derive(false);

            // Assert
            Assert.True(derivation.HasErrors);
            Assert.Contains(M.WorkTask.WorkEffortNumber, derivation.Errors.SelectMany(e => e.RoleTypes));

            //// Re-arrange
            workOrder.TakenBy = organisation2;

            // Act
            this.Session.Derive(true);

            // Assert
            Assert.NotNull(workOrder.WorkEffortNumber);
        }
コード例 #24
0
        public void GivenWorkEffort_WhenAddingRates_ThenRateForPartyIsNotAllowed()
        {
            // Calculating rates per party is not implemented yet
            var workOrder = new WorkTaskBuilder(this.Session).WithName("Task").Build();
            var employee  = new PersonBuilder(this.Session).WithFirstName("Good").WithLastName("Worker").Build();

            new EmploymentBuilder(this.Session).WithEmployee(employee).Build();

            this.Session.Derive(true);

            new WorkEffortAssignmentRateBuilder(this.Session)
            .WithWorkEffort(workOrder)
            .WithRate(1)
            .WithRateType(new RateTypes(this.Session).StandardRate)
            .Build();

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

            new WorkEffortAssignmentRateBuilder(this.Session)
            .WithWorkEffort(workOrder)
            .WithRate(1)
            .WithRateType(new RateTypes(this.Session).OvertimeRate)
            .Build();

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

            new WorkEffortAssignmentRateBuilder(this.Session)
            .WithWorkEffort(workOrder)
            .WithRate(1)
            .WithRateType(new RateTypes(this.Session).StandardRate)
            .Build();

            var derivation = this.Session.Derive(false);

            Assert.True(derivation.HasErrors);
            Assert.Contains(derivation.Errors.SelectMany(e => e.Relations), r => r.RoleType.Equals(M.WorkEffortAssignmentRate.RateType));
        }
コード例 #25
0
        public static WorkTaskBuilder WithScheduledWorkForExternalCustomer(this WorkTaskBuilder @this, Organisation internalOrganisation)
        {
            var faker = @this.Session.Faker();

            var customer = internalOrganisation.ActiveCustomers.Where(v => v.GetType().Name == typeof(Organisation).Name).FirstOrDefault();

            @this.WithTakenBy(internalOrganisation);
            @this.WithExecutedBy(internalOrganisation);
            @this.WithCustomer(customer);
            @this.WithFacility(faker.Random.ListItem(internalOrganisation.FacilitiesWhereOwner));
            @this.WithContactPerson(customer.CurrentContacts.FirstOrDefault());
            @this.WithName(faker.Lorem.Words().ToString());
            @this.WithDescription(faker.Lorem.Sentence());
            @this.WithComment(faker.Lorem.Sentence());
            @this.WithWorkDone(faker.Lorem.Sentence());
            @this.WithPriority(faker.Random.ListItem(@this.Session.Extent <Priority>()));
            @this.WithWorkEffortPurpose(faker.Random.ListItem(@this.Session.Extent <WorkEffortPurpose>()));
            @this.WithScheduledStart(@this.Session.Now().AddDays(7));
            @this.WithScheduledCompletion(@this.Session.Now().AddDays(10));
            @this.WithEstimatedHours(faker.Random.Int(7, 30));
            @this.WithElectronicDocument(new MediaBuilder(@this.Session).WithInFileName("doc1.en.pdf").WithInData(faker.Random.Bytes(1000)).Build());

            return(@this);
        }
コード例 #26
0
        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);
        }
コード例 #27
0
        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)
        }
コード例 #28
0
        public void GivenSupplierOffering_WhenCalculatingUnitSellingPrice_ThenConsiderHighestHistoricalPurchaseRate()
        {
            var settings = this.Session.GetSingleton().Settings;

            var supplier_1 = new OrganisationBuilder(this.Session).WithName("supplier uno").Build();
            var supplier_2 = new OrganisationBuilder(this.Session).WithName("supplier dos").Build();
            var supplier_3 = new OrganisationBuilder(this.Session).WithName("supplier tres").Build();
            var supplier_4 = new OrganisationBuilder(this.Session).WithName("supplier cuatro").Build();

            var internalOrganisation = new Organisations(this.Session).Extent().First(v => Equals(v.Name, "internalOrganisation"));

            new SupplierRelationshipBuilder(this.Session)
            .WithSupplier(supplier_1)
            .WithInternalOrganisation(internalOrganisation)
            .WithFromDate(this.Session.Now().AddYears(-3))
            .Build();
            new SupplierRelationshipBuilder(this.Session)
            .WithSupplier(supplier_2)
            .WithInternalOrganisation(internalOrganisation)
            .WithFromDate(this.Session.Now().AddYears(-2))
            .Build();
            new SupplierRelationshipBuilder(this.Session)
            .WithSupplier(supplier_3)
            .WithInternalOrganisation(internalOrganisation)
            .WithFromDate(this.Session.Now().AddYears(-1))
            .Build();
            new SupplierRelationshipBuilder(this.Session)
            .WithSupplier(supplier_4)
            .WithInternalOrganisation(internalOrganisation)
            .WithFromDate(this.Session.Now().AddMonths(-6))
            .Build();

            var finishedGood = new NonUnifiedPartBuilder(this.Session)
                               .WithNonSerialisedDefaults(internalOrganisation)
                               .Build();

            this.Session.Derive();

            new InventoryItemTransactionBuilder(this.Session).WithQuantity(10).WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment).WithPart(finishedGood).Build();

            this.Session.Derive();

            var euro  = new Currencies(this.Session).FindBy(M.Currency.IsoCode, "EUR");
            var piece = new UnitsOfMeasure(this.Session).Piece;

            new BasePriceBuilder(this.Session)
            .WithPart(finishedGood)
            .WithFromDate(this.Session.Now())
            .WithPrice(100)
            .Build();

            new SupplierOfferingBuilder(this.Session)
            .WithPart(finishedGood)
            .WithSupplier(supplier_1)
            .WithFromDate(this.Session.Now().AddMonths(-6))
            .WithThroughDate(this.Session.Now().AddMonths(-3))
            .WithUnitOfMeasure(piece)
            .WithPrice(100)
            .WithCurrency(euro)
            .Build();

            new SupplierOfferingBuilder(this.Session)
            .WithPart(finishedGood)
            .WithSupplier(supplier_2)
            .WithFromDate(this.Session.Now().AddYears(-1))
            .WithThroughDate(this.Session.Now().AddDays(-1))
            .WithUnitOfMeasure(piece)
            .WithPrice(120)
            .WithCurrency(euro)
            .Build();

            new SupplierOfferingBuilder(this.Session)
            .WithPart(finishedGood)
            .WithSupplier(supplier_3)
            .WithFromDate(this.Session.Now())
            .WithUnitOfMeasure(piece)
            .WithPrice(99)
            .WithCurrency(euro)
            .Build();

            new SupplierOfferingBuilder(this.Session)
            .WithPart(finishedGood)
            .WithSupplier(supplier_4)
            .WithFromDate(this.Session.Now().AddDays(7))
            .WithThroughDate(this.Session.Now().AddDays(30))
            .WithUnitOfMeasure(piece)
            .WithPrice(135)
            .WithCurrency(euro)
            .Build();

            this.Session.Derive();

            var customer = internalOrganisation.CreateB2BCustomer(this.Session.Faker());

            var workEffort = new WorkTaskBuilder(this.Session)
                             .WithName("Activity")
                             .WithCustomer(customer)
                             .WithTakenBy(internalOrganisation)
                             .Build();

            var workEffortInventoryAssignement = new WorkEffortInventoryAssignmentBuilder(this.Session)
                                                 .WithAssignment(workEffort)
                                                 .WithInventoryItem(finishedGood.InventoryItemsWherePart.First())
                                                 .WithQuantity(1)
                                                 .Build();

            this.Session.Derive();

            /*Purchase price times InternalSurchargePercentage
             * var sellingPrice = Math.Round(135 * (1 + (this.Session.GetSingleton().Settings.PartSurchargePercentage / 100)), 2);*/

            Assert.Equal(100, workEffortInventoryAssignement.UnitSellingPrice);
        }
コード例 #29
0
        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);
        }
コード例 #30
0
        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);
        }