Exemplo n.º 1
0
        public void GivenOrderItemForPartWithActualPrice_WhenDerivingPrices_ThenUseActualPrice()
        {
            this.InstantiateObjects(this.DatabaseSession);

            var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(this.finishedGood).WithQuantityOrdered(3).WithActualUnitPrice(15).Build();
            this.order.AddPurchaseOrderItem(item1);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(15, item1.UnitBasePrice);
            Assert.AreEqual(0, item1.UnitDiscount);
            Assert.AreEqual(0, item1.UnitSurcharge);
            Assert.AreEqual(15, item1.CalculatedUnitPrice);
            Assert.AreEqual(0, item1.UnitVat);
            Assert.AreEqual(45, item1.TotalBasePrice);
            Assert.AreEqual(0, item1.TotalDiscount);
            Assert.AreEqual(0, item1.TotalSurcharge);
            Assert.AreEqual(45, item1.TotalExVat);
            Assert.AreEqual(0, item1.TotalVat);
            Assert.AreEqual(45, item1.TotalIncVat);

            Assert.AreEqual(45, this.order.TotalBasePrice);
            Assert.AreEqual(0, this.order.TotalDiscount);
            Assert.AreEqual(0, this.order.TotalSurcharge);
            Assert.AreEqual(45, this.order.TotalExVat);
            Assert.AreEqual(0, this.order.TotalVat);
            Assert.AreEqual(45, this.order.TotalIncVat);
        }
Exemplo n.º 2
0
        public void GivenShipmentReceiptForGoodWithoutSelectedInventoryItemWhenDerivingThenInventoryItemIsFromDefaultFacility()
        {
            var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build();

            new SupplierRelationshipBuilder(this.Session).WithSupplier(supplier).Build();

            var good1 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good1");

            var order = new PurchaseOrderBuilder(this.Session).WithTakenViaSupplier(supplier).Build();

            var item1 = new PurchaseOrderItemBuilder(this.Session).WithPart(good1.Part).WithQuantityOrdered(1).Build();

            order.AddPurchaseOrderItem(item1);

            this.Session.Derive();
            this.Session.Commit();

            order.SetReadyForProcessing();
            this.Session.Derive();

            order.QuickReceive();
            this.Session.Derive();

            var shipment = (PurchaseShipment)item1.OrderShipmentsWhereOrderItem.First.ShipmentItem.ShipmentWhereShipmentItem;

            shipment.Receive();
            this.Session.Derive();

            var receipt = item1.ShipmentReceiptsWhereOrderItem.Single();

            Assert.Equal(new Facilities(this.Session).FindBy(M.Facility.FacilityType, new FacilityTypes(this.Session).Warehouse), receipt.InventoryItem.Facility);
            Assert.Equal(good1.Part.InventoryItemsWherePart[0], receipt.InventoryItem);

            this.Session.Rollback();
        }
        public void GivenOrderItemForPart_WhenDerivingPrices_ThenUsePartCurrentPurchasePrice()
        {
            this.InstantiateObjects(this.Session);

            const decimal QuantityOrdered = 3;
            var           item1           = new PurchaseOrderItemBuilder(this.Session).WithPart(this.finishedGood).WithQuantityOrdered(QuantityOrdered).Build();

            this.order.AddPurchaseOrderItem(item1);

            this.Session.Derive();

            Assert.Equal(this.currentPurchasePrice.Price, item1.UnitBasePrice);
            Assert.Equal(0, item1.UnitDiscount);
            Assert.Equal(0, item1.UnitSurcharge);
            Assert.Equal(this.currentPurchasePrice.Price, item1.UnitPrice);

            Assert.Equal(this.currentPurchasePrice.Price * QuantityOrdered, item1.TotalBasePrice);
            Assert.Equal(0, item1.TotalDiscount);
            Assert.Equal(0, item1.TotalSurcharge);
            Assert.Equal(this.currentPurchasePrice.Price * QuantityOrdered, item1.TotalExVat);

            Assert.Equal(this.currentPurchasePrice.Price * QuantityOrdered, this.order.TotalBasePrice);
            Assert.Equal(0, this.order.TotalDiscount);
            Assert.Equal(0, this.order.TotalSurcharge);
            Assert.Equal(this.currentPurchasePrice.Price * QuantityOrdered, this.order.TotalExVat);
        }
        public void GivenOrderItemForProduct_WhenDerivingPrices_ThenUseProductCurrentPurchasePrice()
        {
            var euro = new Currencies(this.Session).FindBy(M.Currency.IsoCode, "EUR");

            new SupplierOfferingBuilder(this.Session)
            .WithPart(this.finishedGood)
            .WithSupplier(this.supplier)
            .WithFromDate(this.Session.Now().AddYears(-1))
            .WithThroughDate(this.Session.Now().AddDays(-1))
            .WithCurrency(euro)
            .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Piece)
            .WithPrice(8)
            .Build();

            var currentOffer = new SupplierOfferingBuilder(this.Session)
                               .WithPart(this.finishedGood)
                               .WithSupplier(this.supplier)
                               .WithFromDate(this.Session.Now().AddMinutes(-1))
                               .WithThroughDate(this.Session.Now().AddYears(1).AddDays(-1))
                               .WithPrice(10)
                               .WithCurrency(euro)
                               .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Piece)
                               .Build();

            new SupplierOfferingBuilder(this.Session)
            .WithPart(this.finishedGood)
            .WithSupplier(this.supplier)
            .WithFromDate(this.Session.Now().AddYears(1))
            .WithPrice(8)
            .WithCurrency(euro)
            .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Piece)
            .Build();

            this.Session.Derive();
            this.Session.Commit();

            this.InstantiateObjects(this.Session);

            const decimal QuantityOrdered = 3;
            var           item1           = new PurchaseOrderItemBuilder(this.Session).WithPart(this.finishedGood).WithQuantityOrdered(QuantityOrdered).Build();

            this.order.AddPurchaseOrderItem(item1);

            this.Session.Derive();

            Assert.Equal(currentOffer.Price, item1.UnitBasePrice);
            Assert.Equal(0, item1.UnitDiscount);
            Assert.Equal(0, item1.UnitSurcharge);
            Assert.Equal(currentOffer.Price, item1.UnitPrice);

            Assert.Equal(currentOffer.Price * QuantityOrdered, item1.TotalBasePrice);
            Assert.Equal(0, item1.TotalDiscount);
            Assert.Equal(0, item1.TotalSurcharge);
            Assert.Equal(currentOffer.Price * QuantityOrdered, item1.TotalExVat);

            Assert.Equal(currentOffer.Price * QuantityOrdered, this.order.TotalBasePrice);
            Assert.Equal(0, this.order.TotalDiscount);
            Assert.Equal(0, this.order.TotalSurcharge);
            Assert.Equal(currentOffer.Price * QuantityOrdered, this.order.TotalExVat);
        }
Exemplo n.º 5
0
        public void GivenConfirmedOrderItemForGood_WhenOrderItemIsRemoved_ThenItemIsRemovedFromValidOrderItems()
        {
            this.InstantiateObjects(this.DatabaseSession);

            var good = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithName("good")
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithVatRate(new VatRates(this.DatabaseSession).FindBy(VatRates.Meta.Rate, 21))
                .Build();

            var item = new PurchaseOrderItemBuilder(this.DatabaseSession)
                .WithProduct(good)
                .WithQuantityOrdered(3)
                .WithActualUnitPrice(5)
                .Build();

            this.order.AddPurchaseOrderItem(item);

            this.DatabaseSession.Derive(true);

            this.order.Confirm();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(1, this.order.ValidOrderItems.Count);

            item.Cancel();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(0, this.order.ValidOrderItems.Count);
        }
Exemplo n.º 6
0
        public void GivenShipmentReceiptWhenDerivingThenOrderItemQuantityReceivedIsUpdated()
        {
            var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build();

            new SupplierRelationshipBuilder(this.Session).WithSupplier(supplier).Build();

            var good1 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good1");

            var order = new PurchaseOrderBuilder(this.Session).WithTakenViaSupplier(supplier).Build();

            var item1 = new PurchaseOrderItemBuilder(this.Session).WithPart(good1.Part).WithQuantityOrdered(10).Build();

            order.AddPurchaseOrderItem(item1);

            this.Session.Derive();
            this.Session.Commit();

            order.SetReadyForProcessing();
            this.Session.Derive();

            order.QuickReceive();
            this.Session.Derive();

            var shipment = (PurchaseShipment)item1.OrderShipmentsWhereOrderItem.First.ShipmentItem.ShipmentWhereShipmentItem;

            shipment.Receive();
            this.Session.Derive();

            Assert.Equal(10, item1.QuantityReceived);

            this.Session.Rollback();
        }
        public void GivenOrderItem_WhenObjectStateIsPartiallyReceived_ThenItemMayNotBeCancelledOrRejectedOrDeleted()
        {
            var administrator  = new PersonBuilder(this.Session).WithFirstName("Koen").WithUserName("admin").Build();
            var administrators = new UserGroups(this.Session).Administrators;

            administrators.AddMember(administrator);

            this.Session.Derive();
            this.Session.Commit();

            this.InstantiateObjects(this.Session);

            User user = this.Administrator;

            this.Session.SetUser(user);

            var item = new PurchaseOrderItemBuilder(this.Session)
                       .WithPart(this.finishedGood)
                       .WithQuantityOrdered(20)
                       .WithAssignedUnitPrice(5)
                       .Build();

            this.order.AddPurchaseOrderItem(item);

            this.order.SetReadyForProcessing();

            this.Session.Derive();

            var shipment = new PurchaseShipmentBuilder(this.Session).WithShipmentMethod(new ShipmentMethods(this.Session).Ground).WithShipFromParty(this.order.TakenViaSupplier).Build();

            this.Session.Derive();

            var shipmentItem = new ShipmentItemBuilder(this.Session).WithPart(this.finishedGood).WithQuantity(10).WithUnitPurchasePrice(1).Build();

            shipment.AddShipmentItem(shipmentItem);
            this.Session.Derive();

            new ShipmentReceiptBuilder(this.Session)
            .WithQuantityAccepted(3)
            .WithShipmentItem(shipmentItem)
            .WithOrderItem(item)
            .WithFacility(shipmentItem.StoredInFacility)
            .Build();

            this.Session.Derive();

            var acl = new AccessControlLists(this.Session.GetUser())[item];

            Assert.Equal(new PurchaseOrderItemShipmentStates(this.Session).PartiallyReceived, item.PurchaseOrderItemShipmentState);
            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Cancel));
            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Reject));
            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Delete));
        }
        public void GivenOrderItemForSerialisedPart_WhenDerived_ThenOrderQuantityMustBeEqualTo1()
        {
            this.InstantiateObjects(this.Session);

            var serialisedPart = new UnifiedGoodBuilder(this.Session).WithSerialisedDefaults(this.InternalOrganisation).Build();

            this.Session.Derive();
            this.Session.Commit();

            var item = new PurchaseOrderItemBuilder(this.Session)
                       .WithPart(serialisedPart)
                       .WithSerialNumber("1")
                       .WithQuantityOrdered(0)
                       .WithAssignedUnitPrice(1)
                       .Build();

            this.order.AddPurchaseOrderItem(item);

            var expectedErrorMessage = ErrorMessages.InvalidQuantity;

            var errors = new List <IDerivationError>(this.Session.Derive(false).Errors);

            Assert.Single(errors.FindAll(e => e.Message.Equals(expectedErrorMessage)));

            this.Session.Rollback();

            item = new PurchaseOrderItemBuilder(this.Session)
                   .WithPart(serialisedPart)
                   .WithSerialNumber("1")
                   .WithQuantityOrdered(2)
                   .WithAssignedUnitPrice(1)
                   .Build();

            this.order.AddPurchaseOrderItem(item);

            errors = new List <IDerivationError>(this.Session.Derive(false).Errors);
            Assert.Single(errors.FindAll(e => e.Message.Equals(expectedErrorMessage)));

            this.Session.Rollback();

            item = new PurchaseOrderItemBuilder(this.Session)
                   .WithPart(serialisedPart)
                   .WithAssignedUnitPrice(1)
                   .WithQuantityOrdered(1)
                   .WithSerialNumber("1")
                   .Build();

            this.order.AddPurchaseOrderItem(item);

            Assert.False(this.Session.Derive(false).HasErrors);
        }
Exemplo n.º 9
0
        public void GivenOrderItem_WhenObjectStateIsCompleted_ThenItemMayNotBeCancelledOrRejectedOrDeleted()
        {
            var administrator  = new PersonBuilder(this.Session).WithFirstName("Koen").WithUserName("admin").Build();
            var administrators = new UserGroups(this.Session).Administrators;

            administrators.AddMember(administrator);

            this.Session.Derive();
            this.Session.Commit();

            this.InstantiateObjects(this.Session);

            this.SetIdentity("admin");

            var item = new PurchaseOrderItemBuilder(this.Session)
                       .WithPart(this.finishedGood)
                       .WithQuantityOrdered(3)
                       .WithActualUnitPrice(5)
                       .Build();

            this.order.AddPurchaseOrderItem(item);

            this.order.Confirm();

            this.Session.Derive();

            var shipment     = new PurchaseShipmentBuilder(this.Session).WithShipFromParty(this.supplier).WithShipmentMethod(new ShipmentMethods(this.Session).Ground).Build();
            var shipmentItem = new ShipmentItemBuilder(this.Session).WithPart(this.finishedGood).Build();

            shipment.AddShipmentItem(shipmentItem);

            new ShipmentReceiptBuilder(this.Session)
            .WithQuantityAccepted(3)
            .WithShipmentItem(shipmentItem)
            .WithOrderItem(item)
            .Build();

            this.Session.Derive();

            shipment.AppsComplete();

            this.Session.Derive();

            Assert.Equal(new PurchaseOrderItemStates(this.Session).Completed, item.PurchaseOrderItemState);
            var acl = new AccessControlList(item, this.Session.GetUser());

            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Cancel));
            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Reject));
            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Delete));
        }
Exemplo n.º 10
0
        public void GivenShipmentReceiptForPartWithoutSelectedInventoryItemWhenDerivingThenInventoryItemIsFromDefaultFacility()
        {
            var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build();

            new SupplierRelationshipBuilder(this.Session).WithSupplier(supplier).Build();

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

            var order = new PurchaseOrderBuilder(this.Session)
                        .WithTakenViaSupplier(supplier)
                        .WithVatRegime(new VatRegimes(this.Session).Export)
                        .Build();

            var item1 = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(1).Build();

            order.AddPurchaseOrderItem(item1);

            this.Session.Derive();

            order.Confirm();

            this.Session.Derive();
            this.Session.Commit();

            var shipment     = new PurchaseShipmentBuilder(this.Session).WithShipmentMethod(new ShipmentMethods(this.Session).Ground).WithShipFromParty(supplier).Build();
            var shipmentItem = new ShipmentItemBuilder(this.Session).WithPart(part).Build();

            shipment.AddShipmentItem(shipmentItem);

            var receipt = new ShipmentReceiptBuilder(this.Session)
                          .WithQuantityAccepted(1M)
                          .WithShipmentItem(shipmentItem)
                          .WithOrderItem(item1)
                          .Build();

            shipment.AppsComplete();

            this.Session.Derive();
            this.Session.Commit();

            Assert.Equal(new Facilities(this.Session).FindBy(M.Facility.FacilityType, new FacilityTypes(this.Session).Warehouse), receipt.InventoryItem.Facility);
            Assert.Equal(part.InventoryItemsWherePart[0], receipt.InventoryItem);

            this.Session.Rollback();
        }
Exemplo n.º 11
0
        /*
         * Create PurchaseOrder with Serialized PurchaseOrderItem
         */
        public static PurchaseOrder CreatePurchaseOrderWithSerializedItem(this Organisation @this)
        {
            var serializedPart = new UnifiedGoodBuilder(@this.Session()).WithSerialisedDefaults(@this).Build();
            var serializedItem = new SerialisedItemBuilder(@this.Session()).WithDefaults(@this).Build();

            serializedPart.AddSerialisedItem(serializedItem);

            var purchaseOrder = new PurchaseOrderBuilder(@this.Session()).WithDefaults(@this).Build();

            var item = new PurchaseOrderItemBuilder(@this.Session()).WithSerializedPartDefaults(serializedPart, serializedItem).Build();

            purchaseOrder.AddPurchaseOrderItem(item);

            return(purchaseOrder);
        }
Exemplo n.º 12
0
        public void GivenOrderItemWithoutDeliveryDate_WhenDeriving_ThenDerivedDeliveryDateIsOrderDeliveryDate()
        {
            this.InstantiateObjects(this.Session);

            var item = new PurchaseOrderItemBuilder(this.Session)
                       .WithPart(this.finishedGood)
                       .WithQuantityOrdered(1)
                       .Build();

            this.order.AddPurchaseOrderItem(item);

            this.Session.Derive();

            Assert.Equal(item.DeliveryDate, this.order.DeliveryDate);
        }
Exemplo n.º 13
0
        public void GivenPurchaseOrder_WhenConfirming_ThenAllValidItemsAreInConfirmedState()
        {
            var supplier = new OrganisationBuilder(this.Session).WithName("customer2").Build();

            new SupplierRelationshipBuilder(this.Session).WithSupplier(supplier).Build();

            var part = new NonUnifiedPartBuilder(this.Session)
                       .WithProductIdentification(new PartNumberBuilder(this.Session)
                                                  .WithIdentification("1")
                                                  .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build())
                       .Build();

            var order = new PurchaseOrderBuilder(this.Session)
                        .WithTakenViaSupplier(supplier)
                        .WithVatRegime(new VatRegimes(this.Session).Exempt)
                        .Build();

            var item1 = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(1).Build();
            var item2 = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(2).Build();
            var item3 = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(3).Build();
            var item4 = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(4).Build();

            order.AddPurchaseOrderItem(item1);
            order.AddPurchaseOrderItem(item2);
            order.AddPurchaseOrderItem(item3);
            order.AddPurchaseOrderItem(item4);

            this.Session.Derive();

            order.Confirm();

            this.Session.Derive();

            item4.Cancel();

            this.Session.Derive();

            Assert.Equal(3, order.ValidOrderItems.Count);
            Assert.Contains(item1, order.ValidOrderItems);
            Assert.Contains(item2, order.ValidOrderItems);
            Assert.Contains(item3, order.ValidOrderItems);
            Assert.Equal(new PurchaseOrderItemStates(this.Session).InProcess, item1.PurchaseOrderItemState);
            Assert.Equal(new PurchaseOrderItemStates(this.Session).InProcess, item2.PurchaseOrderItemState);
            Assert.Equal(new PurchaseOrderItemStates(this.Session).InProcess, item3.PurchaseOrderItemState);
            Assert.Equal(new PurchaseOrderItemStates(this.Session).Cancelled, item4.PurchaseOrderItemState);
        }
Exemplo n.º 14
0
        public static PurchaseOrderItemBuilder WithNonSerializedPartDefaults(this PurchaseOrderItemBuilder @this, Part nonUnifiedPart)
        {
            var faker = @this.Session.Faker();

            @this.WithDescription(faker.Lorem.Sentences(2));
            @this.WithInvoiceItemType(new InvoiceItemTypes(@this.Session).PartItem);
            @this.WithPart(nonUnifiedPart);
            @this.WithAssignedUnitPrice(faker.Random.UInt(5, 10));
            @this.WithQuantityOrdered(faker.Random.UInt(5, 15));
            @this.WithAssignedDeliveryDate(@this.Session.Now().AddDays(5));
            @this.WithShippingInstruction(faker.Lorem.Sentences(3));
            @this.WithComment(faker.Lorem.Sentence());
            @this.WithInternalComment(faker.Lorem.Sentence());
            @this.WithMessage(faker.Lorem.Sentence());

            return(@this);
        }
Exemplo n.º 15
0
        public void GivenOrderItemForSubcontractingWork_WhenDerived_ThenOrderQuantityMustBeEqualTo1()
        {
            this.InstantiateObjects(this.Session);

            var item = new PurchaseOrderItemBuilder(this.Session)
                       .WithDescription("Do Something")
                       .WithQuantityOrdered(0)
                       .WithAssignedUnitPrice(1)
                       .Build();

            this.order.AddPurchaseOrderItem(item);

            var expectedErrorMessage = ErrorMessages.InvalidQuantity;

            var errors = new List <IDerivationError>(this.Session.Derive(false).Errors);

            Assert.Single(errors.FindAll(e => e.Message.Equals(expectedErrorMessage)));

            this.Session.Rollback();

            item = new PurchaseOrderItemBuilder(this.Session)
                   .WithDescription("Do Something")
                   .WithQuantityOrdered(2)
                   .WithAssignedUnitPrice(1)
                   .Build();

            this.order.AddPurchaseOrderItem(item);

            errors = new List <IDerivationError>(this.Session.Derive(false).Errors);
            Assert.Single(errors.FindAll(e => e.Message.Equals(expectedErrorMessage)));

            this.Session.Rollback();

            item = new PurchaseOrderItemBuilder(this.Session)
                   .WithDescription("Do Something")
                   .WithInvoiceItemType(new InvoiceItemTypes(this.Session).Service)
                   .WithQuantityOrdered(1)
                   .WithAssignedUnitPrice(1)
                   .Build();

            this.order.AddPurchaseOrderItem(item);

            Assert.False(this.Session.Derive(false).HasErrors);
        }
Exemplo n.º 16
0
        public void GivenShipmentReceiptForGoodWithoutSelectedInventoryItemWhenDerivingThenInventoryItemIsFromDefaultFacility()
        {
            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build();

            var good = new GoodBuilder(this.DatabaseSession)
                .WithName("Good")
                .WithSku("10101")
                .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build())
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var order = new PurchaseOrderBuilder(this.DatabaseSession).WithTakenViaSupplier(supplier).Build();

            var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantityOrdered(1).Build();
            order.AddPurchaseOrderItem(item1);

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            order.Confirm();

            var shipment = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build();
            var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithGood(good).Build();
            shipment.AddShipmentItem(shipmentItem);

            var receipt = new ShipmentReceiptBuilder(this.DatabaseSession)
                .WithQuantityAccepted(1M)
                .WithShipmentItem(shipmentItem)
                .WithOrderItem(item1)
                .Build();

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            shipment.AppsComplete();

            Assert.AreEqual(new Warehouses(this.DatabaseSession).FindBy(Warehouses.Meta.Name, "facility"), receipt.InventoryItem.Facility);
            Assert.AreEqual(good.InventoryItemsWhereGood[0], receipt.InventoryItem);

            this.DatabaseSession.Rollback();
        }
Exemplo n.º 17
0
        public static PurchaseOrderItemBuilder WithSerializedPartDefaults(this PurchaseOrderItemBuilder @this, Part unifiedGood, SerialisedItem serialisedItem, Organisation internalOrganisation)
        {
            var faker = @this.Session.Faker();

            @this.WithDescription(faker.Lorem.Sentences(2));
            @this.WithComment(faker.Lorem.Sentence());
            @this.WithInternalComment(faker.Lorem.Sentence());
            @this.WithInvoiceItemType(new InvoiceItemTypes(@this.Session).ProductItem);
            @this.WithPart(unifiedGood);
            @this.WithStoredInFacility(faker.Random.ListItem(internalOrganisation.FacilitiesWhereOwner));
            @this.WithAssignedUnitPrice(faker.Random.UInt(5, 10));
            @this.WithSerialisedItem(serialisedItem);
            @this.WithQuantityOrdered(1);
            @this.WithAssignedDeliveryDate(@this.Session.Now().AddDays(5));
            @this.WithShippingInstruction(faker.Lorem.Sentences(3));
            @this.WithMessage(faker.Lorem.Sentence());

            return(@this);
        }
Exemplo n.º 18
0
        public void GivenOrderItem_WhenObjectShipmentStateIsReceived_ThenReceiveIsNotAllowed()
        {
            var administrator  = new PersonBuilder(this.Session).WithFirstName("Koen").WithUserName("admin").Build();
            var administrators = new UserGroups(this.Session).Administrators;

            administrators.AddMember(administrator);

            this.Session.Derive();
            this.Session.Commit();

            this.InstantiateObjects(this.Session);

            User user = this.Administrator;

            this.Session.SetUser(user);

            var item = new PurchaseOrderItemBuilder(this.Session)
                       .WithPart(this.finishedGood)
                       .WithQuantityOrdered(3)
                       .WithAssignedUnitPrice(5)
                       .Build();

            this.order.AddPurchaseOrderItem(item);

            this.order.SetReadyForProcessing();
            this.Session.Derive();

            this.order.QuickReceive();
            this.Session.Derive();

            var shipment = (PurchaseShipment)item.OrderShipmentsWhereOrderItem.First.ShipmentItem.ShipmentWhereShipmentItem;

            shipment.Receive();
            this.Session.Derive();

            Assert.True(item.PurchaseOrderItemShipmentState.IsReceived);
            var acl = new AccessControlLists(this.Session.GetUser())[item];

            Assert.False(acl.CanExecute(M.PurchaseOrderItem.QuickReceive));
            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Cancel));
            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Reject));
            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Delete));
        }
Exemplo n.º 19
0
        /*
         * Create PurchaseOrder with NonSerialized PurchaseOrderItem
         */
        public static PurchaseOrder CreatePurchaseOrderWithNonSerializedItem(this Organisation @this, Faker faker)
        {
            var nonSerializedPart = new NonUnifiedPartBuilder(@this.Session()).WithNonSerialisedDefaults(@this).Build();

            var purchaseOrder = new PurchaseOrderBuilder(@this.Session()).WithDefaults(@this).Build();

            new SupplierOfferingBuilder(@this.Session())
            .WithPart(nonSerializedPart)
            .WithSupplier(purchaseOrder.TakenViaSupplier)
            .WithFromDate(@this.Session().Now().AddMinutes(-1))
            .WithUnitOfMeasure(new UnitsOfMeasure(@this.Session()).Piece)
            .WithPrice(faker.Random.Decimal(0, 10))
            .Build();

            var item = new PurchaseOrderItemBuilder(@this.Session()).WithNonSerializedPartDefaults(nonSerializedPart).Build();

            purchaseOrder.AddPurchaseOrderItem(item);

            return(purchaseOrder);
        }
Exemplo n.º 20
0
        public void GivenShipmentReceiptForPartWithoutSelectedInventoryItemWhenDerivingThenInventoryItemIsFromDefaultFacility()
        {
            var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build();

            new SupplierRelationshipBuilder(this.Session).WithSupplier(supplier).Build();

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

            var order = new PurchaseOrderBuilder(this.Session)
                        .WithTakenViaSupplier(supplier)
                        .WithVatRegime(new VatRegimes(this.Session).Export)
                        .Build();

            var item1 = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(1).Build();

            order.AddPurchaseOrderItem(item1);

            this.Session.Derive();

            order.SetReadyForProcessing();
            this.Session.Derive();

            order.QuickReceive();
            this.Session.Derive();

            var shipment = (PurchaseShipment)item1.OrderShipmentsWhereOrderItem.First.ShipmentItem.ShipmentWhereShipmentItem;

            shipment.Receive();
            this.Session.Derive();

            var receipt = item1.ShipmentReceiptsWhereOrderItem.Single();

            Assert.Equal(new Facilities(this.Session).FindBy(M.Facility.FacilityType, new FacilityTypes(this.Session).Warehouse), receipt.InventoryItem.Facility);
            Assert.Equal(part.InventoryItemsWherePart[0], receipt.InventoryItem);
        }
Exemplo n.º 21
0
        public void GivenShipmentReceiptWhenDerivingThenOrderItemQuantityReceivedIsUpdated()
        {
            var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build();

            new SupplierRelationshipBuilder(this.Session).WithSupplier(supplier).Build();

            var good1 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good1");

            var order = new PurchaseOrderBuilder(this.Session).WithTakenViaSupplier(supplier).Build();

            var item1 = new PurchaseOrderItemBuilder(this.Session).WithPart(good1.Part).WithQuantityOrdered(10).Build();

            order.AddPurchaseOrderItem(item1);

            this.Session.Derive();
            this.Session.Commit();

            order.Confirm();

            var shipment     = new PurchaseShipmentBuilder(this.Session).WithShipmentMethod(new ShipmentMethods(this.Session).Ground).WithShipFromParty(supplier).Build();
            var shipmentItem = new ShipmentItemBuilder(this.Session).WithGood(good1).Build();

            shipment.AddShipmentItem(shipmentItem);

            new ShipmentReceiptBuilder(this.Session)
            .WithQuantityAccepted(10)
            .WithShipmentItem(shipmentItem)
            .WithOrderItem(item1)
            .Build();

            shipment.AppsComplete();

            this.Session.Derive();
            this.Session.Commit();

            Assert.Equal(10, item1.QuantityReceived);

            this.Session.Rollback();
        }
Exemplo n.º 22
0
        public void GivenOrderItem_WhenObjectStateIsFinished_ThenItemMayNotBeCancelledOrRejectedOrDeleted()
        {
            var administrator  = new PersonBuilder(this.Session).WithFirstName("Koen").WithUserName("admin").Build();
            var administrators = new UserGroups(this.Session).Administrators;

            administrators.AddMember(administrator);

            this.Session.Derive();
            this.Session.Commit();

            this.InstantiateObjects(this.Session);

            User user = this.Administrator;

            this.Session.SetUser(user);

            var item = new PurchaseOrderItemBuilder(this.Session)
                       .WithPart(this.finishedGood)
                       .WithQuantityOrdered(3)
                       .WithAssignedUnitPrice(5)
                       .Build();

            this.order.AddPurchaseOrderItem(item);

            this.Session.Derive();

            this.order.PurchaseOrderState = new PurchaseOrderStates(this.Session).Finished;

            this.Session.Derive();

            Assert.Equal(new PurchaseOrderItemStates(this.Session).Finished, item.PurchaseOrderItemState);
            var acl = new AccessControlLists(this.Session.GetUser())[item];

            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Cancel));
            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Reject));
            Assert.False(acl.CanExecute(M.PurchaseOrderItem.Delete));
        }
Exemplo n.º 23
0
        public void GivenOrderItem_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            this.InstantiateObjects(this.DatabaseSession);

            var buyer = new OrganisationBuilder(this.DatabaseSession).WithName("buyer").Build();
            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            var shipToContactMechanism = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build();
            var partyContactMechanism = new PartyContactMechanismBuilder(this.DatabaseSession).WithContactMechanism(shipToContactMechanism).Build();
            var part = new RawMaterialBuilder(this.DatabaseSession).WithName("raw stuff").Build();
            buyer.AddPartyContactMechanism(partyContactMechanism);

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            var builder = new PurchaseOrderItemBuilder(this.DatabaseSession);
            order.AddPurchaseOrderItem(builder.Build());

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

            this.DatabaseSession.Rollback();

            builder.WithPart(part);
            order.AddPurchaseOrderItem(builder.Build());

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

            builder.WithProduct(new GoodBuilder(this.DatabaseSession).Build());
            var orderItem = builder.Build();
            order.AddPurchaseOrderItem(orderItem);

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

            orderItem.RemovePart();

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Exemplo n.º 24
0
        public void GivenOrderItemWithoutDeliveryDate_WhenDeriving_ThenDerivedDeliveryDateIsOrderDeliveryDate()
        {
            this.InstantiateObjects(this.DatabaseSession);

            var good = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithName("good")
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithVatRate(new VatRates(this.DatabaseSession).FindBy(VatRates.Meta.Rate,21))
                .Build();

            var item = new PurchaseOrderItemBuilder(this.DatabaseSession)
                .WithProduct(good)
                .WithQuantityOrdered(1)
                .Build();

            this.order.AddPurchaseOrderItem(item);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(item.DeliveryDate, this.order.DeliveryDate);
        }
Exemplo n.º 25
0
        public void GivenOrderItemForProduct_WhenDerivingPrices_ThenUseProductCurrentPurchasePrice()
        {
            var euro = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR");

            var good = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithVatRate(new VatRates(this.DatabaseSession).FindBy(VatRates.Meta.Rate,21))
                .WithName("good")
                .Build();

            var supplierOffering = new SupplierOfferingBuilder(this.DatabaseSession)
                .WithProduct(good)
                .WithSupplier(this.supplier)
                .WithFromDate(DateTime.UtcNow.AddYears(-1))
                .Build();

            var previousPurchasePriceGood = new ProductPurchasePriceBuilder(this.DatabaseSession)
                .WithCurrency(euro)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithFromDate(DateTime.UtcNow.AddYears(-1))
                .WithThroughDate(DateTime.UtcNow.AddDays(-1))
                .WithPrice(8)
                .Build();

            var currentPurchasePriceGood = new ProductPurchasePriceBuilder(this.DatabaseSession)
                .WithCurrency(euro)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithFromDate(DateTime.UtcNow.AddMinutes(-1))
                .WithThroughDate(DateTime.UtcNow.AddYears(1).AddDays(-1))
                .WithPrice(10)
                .Build();

            var futurePurchasePriceGood = new ProductPurchasePriceBuilder(this.DatabaseSession)
                .WithCurrency(euro)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithFromDate(DateTime.UtcNow.AddYears(1))
                .WithPrice(8)
                .Build();

            supplierOffering.AddProductPurchasePrice(previousPurchasePriceGood);
            supplierOffering.AddProductPurchasePrice(currentPurchasePriceGood);
            supplierOffering.AddProductPurchasePrice(futurePurchasePriceGood);

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            this.InstantiateObjects(this.DatabaseSession);

            const decimal QuantityOrdered = 3;
            var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantityOrdered(QuantityOrdered).Build();
            this.order.AddPurchaseOrderItem(item1);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(currentPurchasePriceGood.Price, item1.UnitBasePrice);
            Assert.AreEqual(0, item1.UnitDiscount);
            Assert.AreEqual(0, item1.UnitSurcharge);
            Assert.AreEqual(currentPurchasePriceGood.Price, item1.CalculatedUnitPrice);

            Assert.AreEqual(currentPurchasePriceGood.Price * QuantityOrdered, item1.TotalBasePrice);
            Assert.AreEqual(0, item1.TotalDiscount);
            Assert.AreEqual(0, item1.TotalSurcharge);
            Assert.AreEqual(currentPurchasePriceGood.Price * QuantityOrdered, item1.TotalExVat);

            Assert.AreEqual(currentPurchasePriceGood.Price * QuantityOrdered, this.order.TotalBasePrice);
            Assert.AreEqual(0, this.order.TotalDiscount);
            Assert.AreEqual(0, this.order.TotalSurcharge);
            Assert.AreEqual(currentPurchasePriceGood.Price * QuantityOrdered, this.order.TotalExVat);
        }
Exemplo n.º 26
0
        public void GivenOrderItemForPart_WhenDerivingPrices_ThenUsePartCurrentPurchasePrice()
        {
            this.InstantiateObjects(this.DatabaseSession);

            const decimal QuantityOrdered = 3;
            var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(this.finishedGood).WithQuantityOrdered(QuantityOrdered).Build();
            this.order.AddPurchaseOrderItem(item1);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(this.currentPurchasePrice.Price, item1.UnitBasePrice);
            Assert.AreEqual(0, item1.UnitDiscount);
            Assert.AreEqual(0, item1.UnitSurcharge);
            Assert.AreEqual(this.currentPurchasePrice.Price, item1.CalculatedUnitPrice);

            Assert.AreEqual(this.currentPurchasePrice.Price * QuantityOrdered, item1.TotalBasePrice);
            Assert.AreEqual(0, item1.TotalDiscount);
            Assert.AreEqual(0, item1.TotalSurcharge);
            Assert.AreEqual(this.currentPurchasePrice.Price * QuantityOrdered, item1.TotalExVat);

            Assert.AreEqual(this.currentPurchasePrice.Price * QuantityOrdered, this.order.TotalBasePrice);
            Assert.AreEqual(0, this.order.TotalDiscount);
            Assert.AreEqual(0, this.order.TotalSurcharge);
            Assert.AreEqual(this.currentPurchasePrice.Price * QuantityOrdered, this.order.TotalExVat);
        }
Exemplo n.º 27
0
        public void GivenShipmentReceiptForPartWithoutSelectedInventoryItemWhenDerivingThenInventoryItemIsFromDefaultFacility()
        {
            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build();

            var part = new RawMaterialBuilder(this.DatabaseSession)
                .WithName("RawMaterial")
                .Build();

            var order = new PurchaseOrderBuilder(this.DatabaseSession)
                .WithTakenViaSupplier(supplier)
                .WithVatRegime(new VatRegimes(this.DatabaseSession).Export)
                .Build();

            var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(1).Build();
            order.AddPurchaseOrderItem(item1);

            this.DatabaseSession.Derive(true);

            order.Confirm();

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            var shipment = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build();
            var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithPart(part).Build();
            shipment.AddShipmentItem(shipmentItem);

            var receipt = new ShipmentReceiptBuilder(this.DatabaseSession)
                .WithQuantityAccepted(1M)
                .WithShipmentItem(shipmentItem)
                .WithOrderItem(item1)
                .Build();

            shipment.AppsComplete();

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            Assert.AreEqual(new Warehouses(this.DatabaseSession).FindBy(Warehouses.Meta.Name, "facility"), receipt.InventoryItem.Facility);
            Assert.AreEqual(part.InventoryItemsWherePart[0], receipt.InventoryItem);

            this.DatabaseSession.Rollback();
        }
Exemplo n.º 28
0
        public void GivenShipmentReceiptWhenDerivingThenOrderItemQuantityReceivedIsUpdated()
        {
            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build();

            var good = new GoodBuilder(this.DatabaseSession)
                .WithName("Good")
                .WithSku("10101")
                .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build())
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var order = new PurchaseOrderBuilder(this.DatabaseSession).WithTakenViaSupplier(supplier).Build();

            var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantityOrdered(10).Build();
            order.AddPurchaseOrderItem(item1);

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            order.Confirm();

            var shipment = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build();
            var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithGood(good).Build();
            shipment.AddShipmentItem(shipmentItem);

            new ShipmentReceiptBuilder(this.DatabaseSession)
                .WithQuantityAccepted(10)
                .WithShipmentItem(shipmentItem)
                .WithOrderItem(item1)
                .Build();

            shipment.AppsComplete();

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            Assert.AreEqual(10, item1.QuantityReceived);

            this.DatabaseSession.Rollback();
        }
Exemplo n.º 29
0
        public void GivenShipmentReceiptWhenDerivingThenInventoryItemQuantityOnHandIsUpdated()
        {
            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            var mechelenAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build();
            var shipToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession)
                .WithContactMechanism(mechelenAddress)
                .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).ShippingAddress)
                .WithUseAsDefault(true)
                .Build();

            var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build();
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build();

            var good = new GoodBuilder(this.DatabaseSession)
                .WithName("Good")
                .WithSku("10101")
                .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build())
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var inventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good).Build();
            inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(20).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build());

            this.DatabaseSession.Derive(true);

            var order1 = new SalesOrderBuilder(this.DatabaseSession)
                .WithBillToCustomer(customer)
                .WithShipToCustomer(customer)
                .WithDeliveryDate(DateTime.UtcNow)
                .Build();

            var salesItem = new SalesOrderItemBuilder(this.DatabaseSession).WithDescription("item1").WithProduct(good).WithQuantityOrdered(30).WithActualUnitPrice(15).Build();
            order1.AddSalesOrderItem(salesItem);

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            order1.Confirm();

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            var sessionInventoryItem = (NonSerializedInventoryItem)this.DatabaseSession.Instantiate(inventoryItem);
            var sessionSalesItem = (SalesOrderItem)this.DatabaseSession.Instantiate(salesItem);

            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build();

            Assert.AreEqual(20, sessionSalesItem.QuantityPendingShipment);
            Assert.AreEqual(30, sessionSalesItem.QuantityReserved);
            Assert.AreEqual(10, sessionSalesItem.QuantityShortFalled);

            var order = new PurchaseOrderBuilder(this.DatabaseSession).WithTakenViaSupplier(supplier).Build();

            var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantityOrdered(10).Build();
            order.AddPurchaseOrderItem(item1);

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            order.Confirm();

            var shipment = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build();
            var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithGood(good).Build();
            shipment.AddShipmentItem(shipmentItem);

            new ShipmentReceiptBuilder(this.DatabaseSession)
                .WithQuantityAccepted(10)
                .WithShipmentItem(shipmentItem)
                .WithOrderItem(item1)
                .Build();

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            shipment.AppsComplete();

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            Assert.AreEqual(30, sessionInventoryItem.QuantityOnHand);

            Assert.AreEqual(30, sessionSalesItem.QuantityPendingShipment);
            Assert.AreEqual(30, sessionSalesItem.QuantityReserved);
            Assert.AreEqual(0, sessionSalesItem.QuantityShortFalled);
        }
Exemplo n.º 30
0
        public void GivenNonSerialisedNonUnifiedPart_WhenPurchased_ThenAverageCostIsCalculated()
        {
            this.InternalOrganisation.IsAutomaticallyReceived = true;

            var secondFacility = new FacilityBuilder(this.Session)
                                 .WithFacilityType(new FacilityTypes(this.Session).Warehouse)
                                 .WithName("second facility")
                                 .WithOwner(this.InternalOrganisation)
                                 .Build();

            var supplier = this.InternalOrganisation.ActiveSuppliers.First;
            var customer = this.InternalOrganisation.ActiveCustomers.First;

            var part = new NonUnifiedPartBuilder(this.Session).WithNonSerialisedDefaults(this.InternalOrganisation).Build();
            var good = new NonUnifiedGoodBuilder(this.Session)
                       .WithName(part.Name)
                       .WithPart(part)
                       .WithVatRate(new VatRates(this.Session).Zero)
                       .Build();

            this.Session.Derive();

            var purchaseOrder1 = new PurchaseOrderBuilder(this.Session)
                                 .WithTakenViaSupplier(supplier)
                                 .WithDeliveryDate(this.Session.Now())
                                 .Build();

            this.Session.Derive();

            // Beginning inventory: 150 items at 8 euro received in 2 facilities
            var purchaseItem = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(100).WithAssignedUnitPrice(8M).Build();

            purchaseOrder1.AddPurchaseOrderItem(purchaseItem);

            this.Session.Derive();

            purchaseOrder1.SetReadyForProcessing();
            this.Session.Derive();

            purchaseOrder1.Send();
            this.Session.Derive();

            purchaseItem.QuickReceive();
            this.Session.Derive();

            var purchaseOrder2 = new PurchaseOrderBuilder(this.Session)
                                 .WithTakenViaSupplier(supplier)
                                 .WithFacility(secondFacility)
                                 .WithDeliveryDate(this.Session.Now())
                                 .Build();

            this.Session.Derive();

            // Beginning inventory: 150 items at 8 euro
            purchaseItem = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(50).WithAssignedUnitPrice(8M).Build();
            purchaseOrder2.AddPurchaseOrderItem(purchaseItem);

            this.Session.Derive();

            purchaseOrder2.SetReadyForProcessing();
            this.Session.Derive();

            purchaseOrder2.Send();
            this.Session.Derive();

            purchaseItem.QuickReceive();
            this.Session.Derive();

            Assert.Equal(150, part.QuantityOnHand);
            Assert.Equal(8, part.PartWeightedAverage.AverageCost);

            purchaseOrder1.Revise();
            this.Session.Derive();

            // Purchase: 75 items at 8.1 euro
            purchaseItem = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(75).WithAssignedUnitPrice(8.1M).Build();
            purchaseOrder1.AddPurchaseOrderItem(purchaseItem);

            this.Session.Derive();

            purchaseOrder1.SetReadyForProcessing();
            this.Session.Derive();

            purchaseOrder1.Send();
            this.Session.Derive();

            purchaseItem.QuickReceive();
            this.Session.Derive();

            Assert.Equal(225, part.QuantityOnHand);
            Assert.Equal(8.03M, part.PartWeightedAverage.AverageCost);

            var salesOrder = new SalesOrderBuilder(this.Session)
                             .WithTakenBy(this.InternalOrganisation)
                             .WithShipToCustomer(customer)
                             .Build();

            this.Session.Derive();

            // Sell 50 items for 20 euro
            var salesItem1 = new SalesOrderItemBuilder(this.Session).WithProduct(good).WithQuantityOrdered(50).WithAssignedUnitPrice(20M).Build();

            salesOrder.AddSalesOrderItem(salesItem1);

            this.Session.Derive();

            salesOrder.SetReadyForPosting();
            this.Session.Derive();

            salesOrder.Post();
            this.Session.Derive();

            salesOrder.Accept();
            this.Session.Derive();

            salesOrder.Ship();
            this.Session.Derive();

            var customerShipment = salesItem1.OrderShipmentsWhereOrderItem.First.ShipmentItem.ShipmentWhereShipmentItem as CustomerShipment;

            customerShipment.Pick();
            this.Session.Derive();

            customer.PickListsWhereShipToParty.First(v => v.PickListState.Equals(new PickListStates(this.Session).Created)).SetPicked();

            var package = new ShipmentPackageBuilder(this.Session).Build();

            customerShipment.AddShipmentPackage(package);

            foreach (ShipmentItem shipmentItem in customerShipment.ShipmentItems)
            {
                package.AddPackagingContent(new PackagingContentBuilder(this.Session).WithShipmentItem(shipmentItem).WithQuantity(shipmentItem.Quantity).Build());
            }

            this.Session.Derive();

            customerShipment.Ship();
            this.Session.Derive();

            Assert.Equal(175, part.QuantityOnHand);
            Assert.Equal(8.03M, part.PartWeightedAverage.AverageCost);
            Assert.Equal(401.5M, salesItem1.CostOfGoodsSold);

            // Again Sell 50 items for 20 euro
            salesOrder.Revise();
            this.Session.Derive();

            var salesItem2 = new SalesOrderItemBuilder(this.Session).WithProduct(good).WithQuantityOrdered(50).WithAssignedUnitPrice(20M).Build();

            salesOrder.AddSalesOrderItem(salesItem2);

            this.Session.Derive();

            salesOrder.SetReadyForPosting();
            this.Session.Derive();

            salesOrder.Post();
            this.Session.Derive();

            salesOrder.Accept();
            this.Session.Derive();

            salesOrder.Ship();
            this.Session.Derive();

            var customerShipment2 = salesItem2.OrderShipmentsWhereOrderItem.First.ShipmentItem.ShipmentWhereShipmentItem as CustomerShipment;

            customerShipment2.Pick();
            this.Session.Derive();

            customer.PickListsWhereShipToParty.First(v => v.PickListState.Equals(new PickListStates(this.Session).Created)).SetPicked();

            var package2 = new ShipmentPackageBuilder(this.Session).Build();

            customerShipment2.AddShipmentPackage(package2);

            foreach (ShipmentItem shipmentItem in customerShipment2.ShipmentItems)
            {
                package.AddPackagingContent(new PackagingContentBuilder(this.Session).WithShipmentItem(shipmentItem).WithQuantity(shipmentItem.Quantity).Build());
            }

            this.Session.Derive();

            customerShipment2.Ship();
            this.Session.Derive();

            Assert.Equal(125, part.QuantityOnHand);
            Assert.Equal(8.03M, part.PartWeightedAverage.AverageCost);
            Assert.Equal(401.5M, salesItem1.CostOfGoodsSold);

            // Purchase: 50 items at 8.25 euro
            purchaseOrder1.Revise();
            this.Session.Derive();

            purchaseItem = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(50).WithAssignedUnitPrice(8.25M).Build();
            purchaseOrder1.AddPurchaseOrderItem(purchaseItem);

            this.Session.Derive();

            purchaseOrder1.SetReadyForProcessing();
            this.Session.Derive();

            purchaseOrder1.Send();
            this.Session.Derive();

            purchaseItem.QuickReceive();
            this.Session.Derive();

            Assert.Equal(175, part.QuantityOnHand);
            Assert.Equal(8.09M, part.PartWeightedAverage.AverageCost);

            // Use 65 items in a workorder
            var workEffort = new WorkTaskBuilder(this.Session).WithName("Activity").WithCustomer(customer).WithTakenBy(this.InternalOrganisation).Build();

            this.Session.Derive(true);

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

            this.Session.Derive(true);

            Assert.Equal(110, part.QuantityOnHand);
            Assert.Equal(8.09M, part.PartWeightedAverage.AverageCost);
            Assert.Equal(525.85M, inventoryAssignment.CostOfGoodsSold);

            // Cancel workeffort inventory assignment
            inventoryAssignment.Delete();

            this.Session.Derive(true);

            Assert.Equal(175, part.QuantityOnHand);
            Assert.Equal(8.09M, part.PartWeightedAverage.AverageCost);

            // Use 35 items in a workorder
            inventoryAssignment = new WorkEffortInventoryAssignmentBuilder(this.Session)
                                  .WithAssignment(workEffort)
                                  .WithInventoryItem(part.InventoryItemsWherePart.First)
                                  .WithQuantity(35)
                                  .Build();

            this.Session.Derive(true);

            this.Session.Derive(true);

            Assert.Equal(140, part.QuantityOnHand);
            Assert.Equal(8.09M, part.PartWeightedAverage.AverageCost);
            Assert.Equal(283.15M, inventoryAssignment.CostOfGoodsSold);

            // Use 30 items in a workorder form second facility
            inventoryAssignment = new WorkEffortInventoryAssignmentBuilder(this.Session)
                                  .WithAssignment(workEffort)
                                  .WithInventoryItem(part.InventoryItemsWherePart.First(v => v.Facility.Equals(secondFacility)))
                                  .WithQuantity(30)
                                  .Build();

            this.Session.Derive(true);

            Assert.Equal(110, part.QuantityOnHand);
            Assert.Equal(8.09M, part.PartWeightedAverage.AverageCost);
            Assert.Equal(242.7M, inventoryAssignment.CostOfGoodsSold);

            // Purchase: 90 items at 8.35 euro
            var purchaseOrder3 = new PurchaseOrderBuilder(this.Session)
                                 .WithTakenViaSupplier(supplier)
                                 .WithDeliveryDate(this.Session.Now())
                                 .Build();

            this.Session.Derive();

            purchaseItem = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(90).WithAssignedUnitPrice(8.35M).Build();
            purchaseOrder3.AddPurchaseOrderItem(purchaseItem);

            this.Session.Derive();

            purchaseOrder3.SetReadyForProcessing();
            this.Session.Derive();

            purchaseOrder3.Send();
            this.Session.Derive();

            purchaseOrder3.QuickReceive();
            this.Session.Derive();

            // Purchase: 50 items at 8.45 euro
            var purchaseOrder4 = new PurchaseOrderBuilder(this.Session)
                                 .WithTakenViaSupplier(supplier)
                                 .WithDeliveryDate(this.Session.Now())
                                 .Build();

            this.Session.Derive();

            purchaseItem = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(50).WithAssignedUnitPrice(8.45M).Build();
            purchaseOrder4.AddPurchaseOrderItem(purchaseItem);

            this.Session.Derive();

            purchaseOrder4.SetReadyForProcessing();
            this.Session.Derive();

            purchaseOrder4.Send();
            this.Session.Derive();

            purchaseOrder4.QuickReceive();
            this.Session.Derive();

            Assert.Equal(250, part.QuantityOnHand);
            Assert.Equal(8.26M, part.PartWeightedAverage.AverageCost);

            // Ship 10 items to customer (without sales order)
            var outgoingShipment = new CustomerShipmentBuilder(this.Session)
                                   .WithShipToParty(customer)
                                   .WithShipToAddress(customer.ShippingAddress)
                                   .WithShipmentMethod(new ShipmentMethods(this.Session).Ground)
                                   .Build();

            this.Session.Derive(true);

            var outgoingItem = new ShipmentItemBuilder(this.Session).WithGood(good).WithQuantity(10).Build();

            outgoingShipment.AddShipmentItem(outgoingItem);

            this.Session.Derive(true);

            outgoingShipment.Pick();
            this.Session.Derive();

            customer.PickListsWhereShipToParty.First(v => v.PickListState.Equals(new PickListStates(this.Session).Created)).SetPicked();

            package = new ShipmentPackageBuilder(this.Session).Build();
            customerShipment2.AddShipmentPackage(package);

            foreach (ShipmentItem shipmentItem in outgoingShipment.ShipmentItems)
            {
                package.AddPackagingContent(new PackagingContentBuilder(this.Session).WithShipmentItem(shipmentItem).WithQuantity(shipmentItem.Quantity).Build());
            }

            this.Session.Derive();

            outgoingShipment.Ship();
            this.Session.Derive();

            Assert.Equal(240, part.QuantityOnHand);
            Assert.Equal(8.26M, part.PartWeightedAverage.AverageCost);

            // Receive 10 items at 8.55 from supplier (without purchase order)
            var incomingShipment = new PurchaseShipmentBuilder(this.Session)
                                   .WithShipmentMethod(new ShipmentMethods(this.Session).Ground)
                                   .WithShipFromParty(supplier)
                                   .Build();

            this.Session.Derive();

            var incomingItem = new ShipmentItemBuilder(this.Session).WithPart(part).WithQuantity(10).WithUnitPurchasePrice(8.55M).Build();

            incomingShipment.AddShipmentItem(incomingItem);

            this.Session.Derive();

            incomingShipment.Receive();
            this.Session.Derive();

            Assert.Equal(250, part.QuantityOnHand);
            Assert.Equal(8.27M, part.PartWeightedAverage.AverageCost);

            // Receive 100 items at 7.9 from supplier (without purchase order)
            incomingShipment = new PurchaseShipmentBuilder(this.Session)
                               .WithShipmentMethod(new ShipmentMethods(this.Session).Ground)
                               .WithShipFromParty(supplier)
                               .Build();

            this.Session.Derive();

            incomingItem = new ShipmentItemBuilder(this.Session).WithPart(part).WithQuantity(100).WithUnitPurchasePrice(7.9M).Build();
            incomingShipment.AddShipmentItem(incomingItem);

            this.Session.Derive();

            incomingShipment.Receive();
            this.Session.Derive();

            Assert.Equal(350, part.QuantityOnHand);
            Assert.Equal(8.17M, part.PartWeightedAverage.AverageCost);

            // Ship all items to customer (without sales order)
            outgoingShipment = new CustomerShipmentBuilder(this.Session)
                               .WithShipToParty(customer)
                               .WithShipFromFacility(part.DefaultFacility)
                               .WithShipToAddress(customer.ShippingAddress)
                               .WithShipmentMethod(new ShipmentMethods(this.Session).Ground)
                               .Build();

            this.Session.Derive(true);

            outgoingItem = new ShipmentItemBuilder(this.Session).WithGood(good).WithQuantity(330).Build();
            outgoingShipment.AddShipmentItem(outgoingItem);

            this.Session.Derive(true);

            outgoingShipment.Pick();
            this.Session.Derive();

            customer.PickListsWhereShipToParty.First(v => v.PickListState.Equals(new PickListStates(this.Session).Created)).SetPicked();

            package = new ShipmentPackageBuilder(this.Session).Build();
            customerShipment2.AddShipmentPackage(package);

            foreach (ShipmentItem shipmentItem in outgoingShipment.ShipmentItems)
            {
                package.AddPackagingContent(new PackagingContentBuilder(this.Session).WithShipmentItem(shipmentItem).WithQuantity(shipmentItem.Quantity).Build());
            }

            this.Session.Derive();

            outgoingShipment.Ship();
            this.Session.Derive();

            // Ship all items to customer (without sales order)
            outgoingShipment = new CustomerShipmentBuilder(this.Session)
                               .WithShipToParty(customer)
                               .WithShipFromFacility(secondFacility)
                               .WithShipToAddress(customer.ShippingAddress)
                               .WithShipmentMethod(new ShipmentMethods(this.Session).Ground)
                               .Build();

            this.Session.Derive(true);

            outgoingItem = new ShipmentItemBuilder(this.Session).WithGood(good).WithQuantity(20).Build();
            outgoingShipment.AddShipmentItem(outgoingItem);

            this.Session.Derive(true);

            outgoingShipment.Pick();
            this.Session.Derive();

            customer.PickListsWhereShipToParty.First(v => v.PickListState.Equals(new PickListStates(this.Session).Created)).SetPicked();

            package = new ShipmentPackageBuilder(this.Session).Build();
            customerShipment2.AddShipmentPackage(package);

            foreach (ShipmentItem shipmentItem in outgoingShipment.ShipmentItems)
            {
                package.AddPackagingContent(new PackagingContentBuilder(this.Session).WithShipmentItem(shipmentItem).WithQuantity(shipmentItem.Quantity).Build());
            }

            this.Session.Derive();

            outgoingShipment.Ship();
            this.Session.Derive();

            Assert.Equal(0, part.QuantityOnHand);
            Assert.Equal(8.17M, part.PartWeightedAverage.AverageCost);

            purchaseOrder1.Revise();
            this.Session.Derive();

            // Purchase 150 items at 8 euro
            purchaseItem = new PurchaseOrderItemBuilder(this.Session).WithPart(part).WithQuantityOrdered(150).WithAssignedUnitPrice(8M).Build();
            purchaseOrder1.AddPurchaseOrderItem(purchaseItem);

            this.Session.Derive();

            purchaseOrder1.SetReadyForProcessing();
            this.Session.Derive();

            purchaseOrder1.Send();
            this.Session.Derive();

            purchaseItem.QuickReceive();
            this.Session.Derive();

            Assert.Equal(150, part.QuantityOnHand);
            Assert.Equal(8, part.PartWeightedAverage.AverageCost);
        }
Exemplo n.º 31
0
        public void GivenShipmentReceiptWhenDerivingThenInventoryItemQuantityOnHandIsUpdated()
        {
            var store = this.Session.Extent <Store>().First;

            store.IsImmediatelyPicked = false;

            var mechelen        = new CityBuilder(this.Session).WithName("Mechelen").Build();
            var mechelenAddress = new PostalAddressBuilder(this.Session).WithPostalAddressBoundary(mechelen).WithAddress1("Haverwerf 15").Build();
            var shipToMechelen  = new PartyContactMechanismBuilder(this.Session)
                                  .WithContactMechanism(mechelenAddress)
                                  .WithContactPurpose(new ContactMechanismPurposes(this.Session).ShippingAddress)
                                  .WithUseAsDefault(true)
                                  .Build();

            var customer = new PersonBuilder(this.Session).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build();

            new CustomerRelationshipBuilder(this.Session).WithFromDate(this.Session.Now()).WithCustomer(customer).Build();

            var good1 = new NonUnifiedGoods(this.Session).FindBy(M.Good.Name, "good1");

            new InventoryItemTransactionBuilder(this.Session).WithQuantity(20).WithReason(new InventoryTransactionReasons(this.Session).Unknown).WithPart(good1.Part).Build();

            this.Session.Derive();

            var inventoryItem = good1.Part.InventoryItemsWherePart.First;

            var order1 = new SalesOrderBuilder(this.Session)
                         .WithBillToCustomer(customer)
                         .WithShipToCustomer(customer)
                         .WithDeliveryDate(this.Session.Now())
                         .Build();

            var salesItem = new SalesOrderItemBuilder(this.Session).WithDescription("item1").WithProduct(good1).WithQuantityOrdered(30).WithAssignedUnitPrice(15).Build();

            order1.AddSalesOrderItem(salesItem);

            this.Session.Derive();
            this.Session.Commit();

            order1.SetReadyForPosting();

            this.Session.Derive();

            order1.Post();
            this.Session.Derive();

            order1.Accept();
            this.Session.Derive();

            var sessionInventoryItem = (NonSerialisedInventoryItem)this.Session.Instantiate(inventoryItem);
            var sessionSalesItem     = (SalesOrderItem)this.Session.Instantiate(salesItem);

            var supplier = new OrganisationBuilder(this.Session).WithName("supplier").Build();

            new SupplierRelationshipBuilder(this.Session).WithSupplier(supplier).Build();

            Assert.Equal(20, sessionSalesItem.QuantityPendingShipment);
            Assert.Equal(30, sessionSalesItem.QuantityReserved);
            Assert.Equal(10, sessionSalesItem.QuantityShortFalled);

            var order = new PurchaseOrderBuilder(this.Session).WithTakenViaSupplier(supplier).Build();

            var item1 = new PurchaseOrderItemBuilder(this.Session).WithPart(good1.Part).WithQuantityOrdered(10).Build();

            order.AddPurchaseOrderItem(item1);

            this.Session.Derive();
            this.Session.Commit();

            order.SetReadyForProcessing();

            order.OrderedBy.IsAutomaticallyReceived = true;
            order.QuickReceive();

            this.Session.Derive();
            this.Session.Commit();

            Assert.Equal(30, sessionInventoryItem.QuantityOnHand);

            Assert.Equal(30, sessionSalesItem.QuantityPendingShipment);
            Assert.Equal(30, sessionSalesItem.QuantityReserved);
            Assert.Equal(0, sessionSalesItem.QuantityShortFalled);
        }
Exemplo n.º 32
0
        public static void Full(this Singleton @this, DirectoryInfo dataPath, Faker faker)
        {
            var dutchLocale = new Locales(@this.Session()).DutchNetherlands;

            @this.AddAdditionalLocale(dutchLocale);

            var administrator = new PersonBuilder(@this.Session()).WithUserName("administrator").Build();

            new UserGroups(@this.Session()).Administrators.AddMember(administrator);
            new UserGroups(@this.Session()).Creators.AddMember(administrator);

            @this.Session().Derive();

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

            var be = new Countries(@this.Session()).FindBy(M.Country.IsoCode, "BE");
            var us = new Countries(@this.Session()).FindBy(M.Country.IsoCode, "US");

            var allorsLogo = dataPath + @"\www\admin\images\logo.png";

            var allors = Organisations.CreateInternalOrganisation(
                session: @this.Session(),
                name: "Allors BVBA",
                address: "Kleine Nieuwedijkstraat 4",
                postalCode: "2800",
                locality: "Mechelen",
                country: be,
                phone1CountryCode: "+32",
                phone1: "2 335 2335",
                phone1Purpose: new ContactMechanismPurposes(@this.Session()).GeneralPhoneNumber,
                phone2CountryCode: string.Empty,
                phone2: string.Empty,
                phone2Purpose: null,
                emailAddress: "*****@*****.**",
                websiteAddress: "www.allors.com",
                taxNumber: "BE 0476967014",
                bankName: "ING",
                facilityName: "Allors Warehouse 1",
                bic: "BBRUBEBB",
                iban: "BE89 3200 1467 7685",
                currency: euro,
                logo: allorsLogo,
                storeName: "Allors Store",
                billingProcess: new BillingProcesses(@this.Session()).BillingForOrderItems,
                outgoingShipmentNumberPrefix: "a-CS",
                salesInvoiceNumberPrefix: "a-SI",
                salesOrderNumberPrefix: "a-SO",
                purchaseOrderNumberPrefix: "a-PO",
                purchaseInvoiceNumberPrefix: "a-PI",
                requestNumberPrefix: "a-RFQ",
                quoteNumberPrefix: "a-Q",
                productNumberPrefix: "A-",
                workEffortPrefix: "a-WO-",
                creditNoteNumberPrefix: "a-CN-",
                isImmediatelyPicked: true,
                autoGenerateShipmentPackage: true,
                isImmediatelyPacked: true,
                isAutomaticallyShipped: true,
                autoGenerateCustomerShipment: true,
                isAutomaticallyReceived: false,
                autoGeneratePurchaseShipment: false,
                useCreditNoteSequence: true,
                requestCounterValue: 1,
                quoteCounterValue: 1,
                orderCounterValue: 1,
                purchaseOrderCounterValue: 1,
                invoiceCounterValue: 1,
                purchaseInvoiceCounterValue: 1,
                purchaseOrderNeedsApproval: true,
                purchaseOrderApprovalThresholdLevel1: 1000M,
                purchaseOrderApprovalThresholdLevel2: 5000M,
                serialisedItemSoldOn: new SerialisedItemSoldOns(@this.Session()).CustomerShipmentShip,
                collectiveWorkEffortInvoice: true);

            var dipu = Organisations.CreateInternalOrganisation(
                session: @this.Session(),
                name: "Dipu BVBA",
                address: "Kleine Nieuwedijkstraat 2",
                postalCode: "2800",
                locality: "Mechelen",
                country: be,
                phone1CountryCode: "+32",
                phone1: "2 15 49 49 49",
                phone1Purpose: new ContactMechanismPurposes(@this.Session()).GeneralPhoneNumber,
                phone2CountryCode: string.Empty,
                phone2: string.Empty,
                phone2Purpose: null,
                emailAddress: "*****@*****.**",
                websiteAddress: "www.dipu.com",
                taxNumber: "BE 0445366489",
                bankName: "ING",
                facilityName: "Dipu Facility",
                bic: "BBRUBEBB",
                iban: "BE23 3300 6167 6391",
                currency: euro,
                logo: allorsLogo,
                storeName: "Dipu Store",
                billingProcess: new BillingProcesses(@this.Session()).BillingForOrderItems,
                outgoingShipmentNumberPrefix: "d-CS",
                salesInvoiceNumberPrefix: "d-SI",
                salesOrderNumberPrefix: "d-SO",
                purchaseOrderNumberPrefix: "d-PO",
                purchaseInvoiceNumberPrefix: "d-PI",
                requestNumberPrefix: "d-RFQ",
                quoteNumberPrefix: "d-Q",
                productNumberPrefix: "D-",
                workEffortPrefix: "a-WO-",
                creditNoteNumberPrefix: "d-CN-",
                isImmediatelyPicked: true,
                autoGenerateShipmentPackage: true,
                isImmediatelyPacked: true,
                isAutomaticallyShipped: true,
                autoGenerateCustomerShipment: true,
                isAutomaticallyReceived: false,
                autoGeneratePurchaseShipment: false,
                useCreditNoteSequence: true,
                requestCounterValue: 1,
                quoteCounterValue: 1,
                orderCounterValue: 1,
                purchaseOrderCounterValue: 1,
                purchaseInvoiceCounterValue: 1,
                invoiceCounterValue: 1,
                purchaseOrderNeedsApproval: false,
                purchaseOrderApprovalThresholdLevel1: null,
                purchaseOrderApprovalThresholdLevel2: null,
                serialisedItemSoldOn: new SerialisedItemSoldOns(@this.Session()).CustomerShipmentShip,
                collectiveWorkEffortInvoice: true);

            // Give Administrator access
            new EmploymentBuilder(@this.Session()).WithEmployee(administrator).WithEmployer(allors).Build();

            @this.Settings.DefaultFacility = allors.FacilitiesWhereOwner.First;

            var allorsEmployee1                   = allors.CreateEmployee("letmein", faker);
            var allorsEmployee2                   = allors.CreateEmployee("letmein", faker);
            var allorsProductQuoteApprover        = allors.CreateEmployee("letmein", faker);
            var allorsPurchaseInvoiceApprover     = allors.CreateEmployee("letmein", faker);
            var allorsPurchaseOrderApproverLevel1 = allors.CreateEmployee("letmein", faker);
            var allorsPurchaseOrderApproverLevel2 = allors.CreateEmployee("letmein", faker);

            var dipuEmployee                = dipu.CreateEmployee("letmein", faker);
            var dipuProductQuoteApprover    = dipu.CreateEmployee("letmein", faker);
            var dipuPurchaseInvoiceApprover = dipu.CreateEmployee("letmein", faker);

            new FacilityBuilder(@this.Session())
            .WithName("Allors warehouse 2")
            .WithFacilityType(new FacilityTypes(@this.Session()).Warehouse)
            .WithOwner(allors)
            .Build();

            var vatRate      = new VatRateBuilder(@this.Session()).WithRate(21).Build();
            var manufacturer = new OrganisationBuilder(@this.Session()).WithManufacturerDefaults(faker).Build();

            allors.CreateSupplier(faker);
            allors.CreateSupplier(faker);

            allors.CreateSubContractor(faker);
            allors.CreateSubContractor(faker);

            @this.Session().Derive();

            var nonSerialisedPart1 = allors.CreateNonSerialisedNonUnifiedPart(faker);
            var nonSerialisedPart2 = allors.CreateNonSerialisedNonUnifiedPart(faker);
            var serialisedPart1    = allors.CreateSerialisedNonUnifiedPart(faker);
            var serialisedPart2    = allors.CreateSerialisedNonUnifiedPart(faker);

            var good1 = new NonUnifiedGoodBuilder(@this.Session()).WithNonSerialisedPartDefaults(allors).Build();

            var good2 = new NonUnifiedGoodBuilder(@this.Session()).WithSerialisedPartDefaults(allors).Build();

            var serialisedItem = new SerialisedItemBuilder(@this.Session()).WithDefaults(allors).Build();

            serialisedPart1.AddSerialisedItem(serialisedItem);

            new InventoryItemTransactionBuilder(@this.Session())
            .WithSerialisedItem(serialisedItem)
            .WithFacility(allors.FacilitiesWhereOwner.First)
            .WithQuantity(1)
            .WithReason(new InventoryTransactionReasons(@this.Session()).IncomingShipment)
            .WithSerialisedInventoryItemState(new SerialisedInventoryItemStates(@this.Session()).Good)
            .Build();

            var good3 = new NonUnifiedGoodBuilder(@this.Session()).WithNonSerialisedPartDefaults(allors).Build();

            var good4 = new NonUnifiedGoodBuilder(@this.Session()).WithSerialisedPartDefaults(allors).Build();

            var productCategory1 = new ProductCategoryBuilder(@this.Session())
                                   .WithInternalOrganisation(allors)
                                   .WithName("Best selling gizmo's")
                                   .WithLocalisedName(new LocalisedTextBuilder(@this.Session()).WithText("Meest verkochte gizmo's").WithLocale(dutchLocale).Build())
                                   .Build();

            var productCategory2 = new ProductCategoryBuilder(@this.Session())
                                   .WithInternalOrganisation(allors)
                                   .WithName("Big Gizmo's")
                                   .WithLocalisedName(new LocalisedTextBuilder(@this.Session()).WithText("Grote Gizmo's").WithLocale(dutchLocale).Build())
                                   .Build();

            var productCategory3 = new ProductCategoryBuilder(@this.Session())
                                   .WithInternalOrganisation(allors)
                                   .WithName("Small gizmo's")
                                   .WithLocalisedName(new LocalisedTextBuilder(@this.Session()).WithText("Kleine gizmo's").WithLocale(dutchLocale).Build())
                                   .WithProduct(good1)
                                   .WithProduct(good2)
                                   .WithProduct(good3)
                                   .WithProduct(good4)
                                   .Build();

            new CatalogueBuilder(@this.Session())
            .WithInternalOrganisation(allors)
            .WithName("New gizmo's")
            .WithLocalisedName(new LocalisedTextBuilder(@this.Session()).WithText("Nieuwe gizmo's").WithLocale(dutchLocale).Build())
            .WithDescription("Latest in the world of Gizmo's")
            .WithLocalisedDescription(new LocalisedTextBuilder(@this.Session()).WithText("Laatste in de wereld van Gizmo's").WithLocale(dutchLocale).Build())
            .WithProductCategory(productCategory1)
            .Build();

            @this.Session().Derive();

            var email2 = new EmailAddressBuilder(@this.Session())
                         .WithElectronicAddressString("*****@*****.**")
                         .Build();

            for (var i = 0; i < 10; i++)
            {
                var b2BCustomer = allors.CreateB2BCustomer(faker);

                @this.Session().Derive();

                new FaceToFaceCommunicationBuilder(@this.Session())
                .WithDescription($"Meeting {i}")
                .WithSubject($"meeting {i}")
                .WithEventPurpose(new CommunicationEventPurposes(@this.Session()).Meeting)
                .WithFromParty(allors.CurrentContacts.First)
                .WithToParty(b2BCustomer.CurrentContacts.First)
                .WithOwner(administrator)
                .WithActualStart(@this.Session().Now())
                .Build();

                new EmailCommunicationBuilder(@this.Session())
                .WithDescription($"Email {i}")
                .WithSubject($"email {i}")
                .WithFromParty(allors.CurrentContacts.First)
                .WithToParty(b2BCustomer.CurrentContacts.First)
                .WithFromEmail(allors.GeneralEmail)
                .WithToEmail(email2)
                .WithEventPurpose(new CommunicationEventPurposes(@this.Session()).Meeting)
                .WithOwner(administrator)
                .WithActualStart(@this.Session().Now())
                .Build();

                new LetterCorrespondenceBuilder(@this.Session())
                .WithDescription($"Letter {i}")
                .WithSubject($"letter {i}")
                .WithFromParty(administrator)
                .WithToParty(b2BCustomer.CurrentContacts.First)
                .WithEventPurpose(new CommunicationEventPurposes(@this.Session()).Meeting)
                .WithOwner(administrator)
                .WithActualStart(@this.Session().Now())
                .Build();

                new PhoneCommunicationBuilder(@this.Session())
                .WithDescription($"Phone {i}")
                .WithSubject($"phone {i}")
                .WithFromParty(administrator)
                .WithToParty(b2BCustomer.CurrentContacts.First)
                .WithEventPurpose(new CommunicationEventPurposes(@this.Session()).Meeting)
                .WithOwner(administrator)
                .WithActualStart(@this.Session().Now())
                .Build();

                var requestForQuote = new RequestForQuoteBuilder(@this.Session())
                                      .WithEmailAddress($"customer{i}@acme.com")
                                      .WithTelephoneNumber("+1 234 56789")
                                      .WithRecipient(allors)
                                      .Build();

                var requestItem = new RequestItemBuilder(@this.Session())
                                  .WithSerialisedItem(serialisedItem)
                                  .WithProduct(serialisedItem.PartWhereSerialisedItem.NonUnifiedGoodsWherePart.FirstOrDefault())
                                  .WithComment($"Comment {i}")
                                  .WithQuantity(1)
                                  .Build();

                requestForQuote.AddRequestItem(requestItem);

                var quote = new ProductQuoteBuilder(@this.Session()).WithSerializedDefaults(allors).Build();

                var salesOrderItem1 = new SalesOrderItemBuilder(@this.Session())
                                      .WithDescription("first item")
                                      .WithProduct(good1)
                                      .WithAssignedUnitPrice(3000)
                                      .WithQuantityOrdered(1)
                                      .WithMessage(@"line1
line2")
                                      .WithInvoiceItemType(new InvoiceItemTypes(@this.Session()).ProductItem)
                                      .Build();

                var salesOrderItem2 = new SalesOrderItemBuilder(@this.Session())
                                      .WithDescription("second item")
                                      .WithAssignedUnitPrice(2000)
                                      .WithQuantityOrdered(2)
                                      .WithInvoiceItemType(new InvoiceItemTypes(@this.Session()).ProductItem)
                                      .Build();

                var salesOrderItem3 = new SalesOrderItemBuilder(@this.Session())
                                      .WithDescription("Fee")
                                      .WithAssignedUnitPrice(100)
                                      .WithQuantityOrdered(1)
                                      .WithInvoiceItemType(new InvoiceItemTypes(@this.Session()).Fee)
                                      .Build();

                var order = new SalesOrderBuilder(@this.Session())
                            .WithTakenBy(allors)
                            .WithBillToCustomer(b2BCustomer)
                            .WithBillToEndCustomerContactMechanism(b2BCustomer.BillingAddress)
                            .WithSalesOrderItem(salesOrderItem1)
                            .WithSalesOrderItem(salesOrderItem2)
                            .WithSalesOrderItem(salesOrderItem3)
                            .WithCustomerReference("a reference number")
                            .WithDescription("Sale of 1 used Aircraft Towbar")
                            .WithVatRegime(new VatRegimes(@this.Session()).Assessable)
                            .Build();

                var salesInvoiceItem1 = new SalesInvoiceItemBuilder(@this.Session())
                                        .WithDescription("first item")
                                        .WithProduct(good1)
                                        .WithAssignedUnitPrice(3000)
                                        .WithQuantity(1)
                                        .WithMessage(@"line1
line2")
                                        .WithInvoiceItemType(new InvoiceItemTypes(@this.Session()).ProductItem)
                                        .Build();

                var salesInvoiceItem2 = new SalesInvoiceItemBuilder(@this.Session())
                                        .WithDescription("second item")
                                        .WithAssignedUnitPrice(2000)
                                        .WithQuantity(2)
                                        .WithInvoiceItemType(new InvoiceItemTypes(@this.Session()).ProductItem)
                                        .Build();

                var salesInvoiceItem3 = new SalesInvoiceItemBuilder(@this.Session())
                                        .WithDescription("Fee")
                                        .WithAssignedUnitPrice(100)
                                        .WithQuantity(1)
                                        .WithInvoiceItemType(new InvoiceItemTypes(@this.Session()).Fee)
                                        .Build();

                var exw      = new IncoTermTypes(@this.Session()).Exw;
                var incoTerm = new IncoTermBuilder(@this.Session()).WithTermType(exw).WithTermValue("XW").Build();

                var salesInvoice = new SalesInvoiceBuilder(@this.Session())
                                   .WithBilledFrom(allors)
                                   .WithBillToCustomer(b2BCustomer)
                                   .WithBillToContactPerson(b2BCustomer.CurrentContacts.First)
                                   .WithBillToContactMechanism(b2BCustomer.BillingAddress)
                                   .WithSalesInvoiceItem(salesInvoiceItem1)
                                   .WithSalesInvoiceItem(salesInvoiceItem2)
                                   .WithSalesInvoiceItem(salesInvoiceItem3)
                                   .WithCustomerReference("a reference number")
                                   .WithDescription("Sale of 1 used Aircraft Towbar")
                                   .WithSalesInvoiceType(new SalesInvoiceTypes(@this.Session()).SalesInvoice)
                                   .WithSalesTerm(incoTerm)
                                   .WithVatRegime(new VatRegimes(@this.Session()).Assessable)
                                   .Build();

                for (var j = 0; j < 3; j++)
                {
                    var salesInvoiceItem = new SalesInvoiceItemBuilder(@this.Session())
                                           .WithDescription("Extra Charge")
                                           .WithAssignedUnitPrice(100 + j)
                                           .WithQuantity(j)
                                           .WithInvoiceItemType(new InvoiceItemTypes(@this.Session()).MiscCharge)
                                           .Build();

                    salesInvoice.AddSalesInvoiceItem(salesInvoiceItem);
                }
            }

            @this.Session().Derive();

            for (var i = 0; i < 4; i++)
            {
                var supplier = faker.Random.ListItem(allors.CurrentSuppliers);

                var purchaseInvoiceItem1 = new PurchaseInvoiceItemBuilder(@this.Session())
                                           .WithDescription("first item")
                                           .WithPart(nonSerialisedPart1)
                                           .WithAssignedUnitPrice(3000)
                                           .WithQuantity(1)
                                           .WithMessage(@"line1
line2")
                                           .WithInvoiceItemType(new InvoiceItemTypes(@this.Session()).PartItem)
                                           .Build();

                var purchaseInvoiceItem2 = new PurchaseInvoiceItemBuilder(@this.Session())
                                           .WithDescription("second item")
                                           .WithAssignedUnitPrice(2000)
                                           .WithQuantity(2)
                                           .WithPart(nonSerialisedPart2)
                                           .WithInvoiceItemType(new InvoiceItemTypes(@this.Session()).PartItem)
                                           .Build();

                var purchaseInvoiceItem3 = new PurchaseInvoiceItemBuilder(@this.Session())
                                           .WithDescription("Fee")
                                           .WithAssignedUnitPrice(100)
                                           .WithQuantity(1)
                                           .WithInvoiceItemType(new InvoiceItemTypes(@this.Session()).Fee)
                                           .Build();

                var purchaseInvoice = new PurchaseInvoiceBuilder(@this.Session())
                                      .WithBilledTo(allors)
                                      .WithBilledFrom(supplier)
                                      .WithPurchaseInvoiceItem(purchaseInvoiceItem1)
                                      .WithPurchaseInvoiceItem(purchaseInvoiceItem2)
                                      .WithPurchaseInvoiceItem(purchaseInvoiceItem3)
                                      .WithCustomerReference("a reference number")
                                      .WithDescription("Purchase of 1 used Aircraft Towbar")
                                      .WithPurchaseInvoiceType(new PurchaseInvoiceTypes(@this.Session()).PurchaseInvoice)
                                      .WithVatRegime(new VatRegimes(@this.Session()).Assessable)
                                      .Build();

                var purchaseOrderItem1 = new PurchaseOrderItemBuilder(@this.Session())
                                         .WithDescription("first purchase order item")
                                         .WithPart(nonSerialisedPart1)
                                         .WithQuantityOrdered(1)
                                         .Build();

                var purchaseOrder = new PurchaseOrderBuilder(@this.Session())
                                    .WithOrderedBy(allors)
                                    .WithTakenViaSupplier(supplier)
                                    .WithPurchaseOrderItem(purchaseOrderItem1)
                                    .WithCustomerReference("reference " + i)
                                    .Build();
            }

            var anOrganisation = new Organisations(@this.Session()).FindBy(M.Organisation.IsInternalOrganisation, false);

            var item = new SerialisedItemBuilder(@this.Session())
                       .WithSerialNumber("112")
                       .WithSerialisedItemAvailability(new SerialisedItemAvailabilities(@this.Session()).Sold)
                       .WithAvailableForSale(false)
                       .WithOwnedBy(anOrganisation)
                       .Build();

            nonSerialisedPart2.AddSerialisedItem(item);

            var workTask = new WorkTaskBuilder(@this.Session())
                           .WithTakenBy(allors)
                           .WithCustomer(anOrganisation)
                           .WithName("maintenance")
                           .Build();

            new WorkEffortFixedAssetAssignmentBuilder(@this.Session())
            .WithFixedAsset(item)
            .WithAssignment(workTask)
            .Build();

            var workOrderPart1 = allors.CreateNonSerialisedNonUnifiedPart(faker);
            var workOrderPart2 = allors.CreateNonSerialisedNonUnifiedPart(faker);
            var workOrderPart3 = allors.CreateNonSerialisedNonUnifiedPart(faker);

            @this.Session().Derive();

            var workOrder = new WorkTaskBuilder(@this.Session())
                            .WithName("Task")
                            .WithTakenBy(allors)
                            .WithFacility(new Facilities(@this.Session()).Extent().First)
                            .WithCustomer(anOrganisation)
                            .WithWorkEffortPurpose(new WorkEffortPurposes(@this.Session()).Maintenance)
                            .WithSpecialTerms("Net 45 Days")
                            .Build();

            new WorkEffortFixedAssetAssignmentBuilder(@this.Session())
            .WithFixedAsset(item)
            .WithAssignment(workOrder)
            .WithComment("Busted tailpipe")
            .Build();

            workOrder.CreateInventoryAssignment(workOrderPart1, 11);
            workOrder.CreateInventoryAssignment(workOrderPart2, 12);
            workOrder.CreateInventoryAssignment(workOrderPart3, 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 standardRate = new RateTypes(@this.Session()).StandardRate;
            var overtimeRate = new RateTypes(@this.Session()).OvertimeRate;

            var frequencies = new TimeFrequencies(@this.Session());

            var timeEntryYesterday1 = workOrder.CreateTimeEntry(yesterday, laterYesterday, frequencies.Day, standardRate);
            var timeEntryToday1     = workOrder.CreateTimeEntry(today, laterToday, frequencies.Hour, standardRate);
            var timeEntryTomorrow1  = workOrder.CreateTimeEntry(tomorrow, laterTomorrow, frequencies.Minute, overtimeRate);

            allorsEmployee1.TimeSheetWhereWorker.AddTimeEntry(timeEntryYesterday1);
            allorsEmployee1.TimeSheetWhereWorker.AddTimeEntry(timeEntryToday1);
            allorsEmployee1.TimeSheetWhereWorker.AddTimeEntry(timeEntryTomorrow1);

            var timeEntryYesterday2 = workOrder.CreateTimeEntry(yesterday, laterYesterday, frequencies.Day, standardRate);
            var timeEntryToday2     = workOrder.CreateTimeEntry(today, laterToday, frequencies.Hour, standardRate);
            var timeEntryTomorrow2  = workOrder.CreateTimeEntry(tomorrow, laterTomorrow, frequencies.Minute, overtimeRate);

            allorsEmployee2.TimeSheetWhereWorker.AddTimeEntry(timeEntryYesterday2);
            allorsEmployee2.TimeSheetWhereWorker.AddTimeEntry(timeEntryToday2);
            allorsEmployee2.TimeSheetWhereWorker.AddTimeEntry(timeEntryTomorrow2);

            var po = new PurchaseOrders(@this.Session()).Extent().First;

            foreach (PurchaseOrderItem purchaseOrderItem in po.PurchaseOrderItems)
            {
                new WorkEffortPurchaseOrderItemAssignmentBuilder(@this.Session())
                .WithPurchaseOrderItem(purchaseOrderItem)
                .WithAssignment(workOrder)
                .WithQuantity(1)
                .Build();
            }

            @this.Session().Derive();
        }
Exemplo n.º 33
0
        public void Execute()
        {
            var singleton   = this.Session.GetSingleton();
            var dutchLocale = new Locales(this.Session).DutchNetherlands;

            singleton.AddAdditionalLocale(dutchLocale);

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

            var be = new Countries(this.Session).FindBy(M.Country.IsoCode, "BE");
            var us = new Countries(this.Session).FindBy(M.Country.IsoCode, "US");

            var email2 = new EmailAddressBuilder(this.Session)
                         .WithElectronicAddressString("*****@*****.**")
                         .Build();

            var allorsLogo = this.DataPath + @"\www\admin\images\logo.png";

            var serialisedItemSoldOns = new SerialisedItemSoldOn[] { new SerialisedItemSoldOns(this.Session).SalesInvoiceSend, new SerialisedItemSoldOns(this.Session).PurchaseInvoiceConfirm };

            var allors = Organisations.CreateInternalOrganisation(
                session: this.Session,
                name: "Allors BVBA",
                address: "Kleine Nieuwedijkstraat 4",
                postalCode: "2800",
                locality: "Mechelen",
                country: be,
                phone1CountryCode: "+32",
                phone1: "2 335 2335",
                phone1Purpose: new ContactMechanismPurposes(this.Session).GeneralPhoneNumber,
                phone2CountryCode: string.Empty,
                phone2: string.Empty,
                phone2Purpose: null,
                emailAddress: "*****@*****.**",
                websiteAddress: "www.allors.com",
                taxNumber: "BE 0476967014",
                bankName: "ING",
                facilityName: "Allors warehouse 1",
                bic: "BBRUBEBB",
                iban: "BE89 3200 1467 7685",
                currency: euro,
                logo: allorsLogo,
                storeName: "Allors Store",
                billingProcess: new BillingProcesses(this.Session).BillingForOrderItems,
                outgoingShipmentNumberPrefix: "a-CS",
                salesInvoiceNumberPrefix: "a-SI",
                salesOrderNumberPrefix: "a-SO",
                purchaseOrderNumberPrefix: "a-PO",
                purchaseInvoiceNumberPrefix: "a-PI",
                requestNumberPrefix: "a-RFQ",
                quoteNumberPrefix: "a-Q",
                productNumberPrefix: "A-",
                workEffortPrefix: "a-WO-",
                creditNoteNumberPrefix: "a-CN-",
                isImmediatelyPicked: true,
                autoGenerateShipmentPackage: true,
                isImmediatelyPacked: true,
                isAutomaticallyShipped: true,
                autoGenerateCustomerShipment: true,
                isAutomaticallyReceived: false,
                autoGeneratePurchaseShipment: false,
                useCreditNoteSequence: true,
                requestCounterValue: 1,
                quoteCounterValue: 1,
                orderCounterValue: 1,
                purchaseOrderCounterValue: 1,
                purchaseInvoiceCounterValue: 1,
                invoiceCounterValue: 1,
                purchaseOrderNeedsApproval: true,
                purchaseOrderApprovalThresholdLevel1: 1000M,
                purchaseOrderApprovalThresholdLevel2: 5000M,
                serialisedItemSoldOns: serialisedItemSoldOns,
                collectiveWorkEffortInvoice: true);

            var dipu = Organisations.CreateInternalOrganisation(
                session: this.Session,
                name: "Dipu BVBA",
                address: "Kleine Nieuwedijkstraat 2",
                postalCode: "2800",
                locality: "Mechelen",
                country: be,
                phone1CountryCode: "+32",
                phone1: "2 15 49 49 49",
                phone1Purpose: new ContactMechanismPurposes(this.Session).GeneralPhoneNumber,
                phone2CountryCode: string.Empty,
                phone2: string.Empty,
                phone2Purpose: null,
                emailAddress: "*****@*****.**",
                websiteAddress: "www.dipu.com",
                taxNumber: "BE 0445366489",
                bankName: "ING",
                facilityName: "Dipu Facility",
                bic: "BBRUBEBB",
                iban: "BE23 3300 6167 6391",
                currency: euro,
                logo: allorsLogo,
                storeName: "Dipu Store",
                billingProcess: new BillingProcesses(this.Session).BillingForOrderItems,
                outgoingShipmentNumberPrefix: "d-CS",
                salesInvoiceNumberPrefix: "d-SI",
                salesOrderNumberPrefix: "d-SO",
                purchaseOrderNumberPrefix: "d-PO",
                purchaseInvoiceNumberPrefix: "d-PI",
                requestNumberPrefix: "d-RFQ",
                quoteNumberPrefix: "d-Q",
                productNumberPrefix: "D-",
                workEffortPrefix: "d-WO-",
                creditNoteNumberPrefix: "d-CN-",
                isImmediatelyPicked: true,
                autoGenerateShipmentPackage: true,
                isImmediatelyPacked: true,
                isAutomaticallyShipped: true,
                autoGenerateCustomerShipment: true,
                isAutomaticallyReceived: false,
                autoGeneratePurchaseShipment: false,
                useCreditNoteSequence: true,
                requestCounterValue: 1,
                quoteCounterValue: 1,
                orderCounterValue: 1,
                purchaseOrderCounterValue: 1,
                purchaseInvoiceCounterValue: 1,
                invoiceCounterValue: 1,
                purchaseOrderNeedsApproval: false,
                purchaseOrderApprovalThresholdLevel1: null,
                purchaseOrderApprovalThresholdLevel2: null,
                serialisedItemSoldOns: serialisedItemSoldOns,
                collectiveWorkEffortInvoice: true);

            singleton.Settings.DefaultFacility = allors.FacilitiesWhereOwner.First;
            var faker = this.Session.Faker();

            allors.CreateEmployee("letmein", faker);
            allors.CreateAdministrator("letmein", faker);
            var allorsB2BCustomer = allors.CreateB2BCustomer(this.Session.Faker());
            var allorsB2CCustomer = allors.CreateB2CCustomer(this.Session.Faker());

            allors.CreateSupplier(this.Session.Faker());
            allors.CreateSubContractor(this.Session.Faker());

            new CustomerRelationshipBuilder(this.Session)
            .WithCustomer(allorsB2BCustomer)
            .WithInternalOrganisation(dipu)
            .WithFromDate(this.Session.Now())
            .Build();

            new CustomerRelationshipBuilder(this.Session)
            .WithCustomer(allorsB2CCustomer)
            .WithInternalOrganisation(dipu)
            .WithFromDate(this.Session.Now())
            .Build();

            new CustomerRelationshipBuilder(this.Session)
            .WithCustomer(dipu)
            .WithInternalOrganisation(allors)
            .WithFromDate(this.Session.Now())
            .Build();

            dipu.CreateEmployee("letmein", faker);
            dipu.CreateAdministrator("letmein", faker);
            var dipuB2BCustomer = dipu.CreateB2BCustomer(this.Session.Faker());
            var dipuB2CCustomer = dipu.CreateB2CCustomer(this.Session.Faker());

            dipu.CreateSupplier(this.Session.Faker());
            dipu.CreateSubContractor(this.Session.Faker());

            new CustomerRelationshipBuilder(this.Session)
            .WithCustomer(dipuB2BCustomer)
            .WithInternalOrganisation(allors)
            .WithFromDate(this.Session.Now())
            .Build();

            new CustomerRelationshipBuilder(this.Session)
            .WithCustomer(dipuB2CCustomer)
            .WithInternalOrganisation(allors)
            .WithFromDate(this.Session.Now())
            .Build();

            new CustomerRelationshipBuilder(this.Session)
            .WithCustomer(allors)
            .WithInternalOrganisation(dipu)
            .WithFromDate(this.Session.Now())
            .Build();

            this.Session.Derive();

            var facility = new FacilityBuilder(this.Session)
                           .WithName("Allors warehouse 2")
                           .WithFacilityType(new FacilityTypes(this.Session).Warehouse)
                           .WithOwner(allors)
                           .Build();

            var store = new StoreBuilder(this.Session).WithName("store")
                        .WithInternalOrganisation(allors)
                        .WithDefaultFacility(facility)
                        .WithDefaultShipmentMethod(new ShipmentMethods(this.Session).Ground)
                        .WithDefaultCarrier(new Carriers(this.Session).Fedex)
                        .Build();

            var productType = new ProductTypeBuilder(this.Session)
                              .WithName($"Gizmo Serialised")
                              .WithSerialisedItemCharacteristicType(new SerialisedItemCharacteristicTypeBuilder(this.Session)
                                                                    .WithName("Size")
                                                                    .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Afmeting").WithLocale(dutchLocale).Build())
                                                                    .Build())
                              .WithSerialisedItemCharacteristicType(new SerialisedItemCharacteristicTypeBuilder(this.Session)
                                                                    .WithName("Weight")
                                                                    .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Gewicht").WithLocale(dutchLocale).Build())
                                                                    .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Kilogram)
                                                                    .Build())
                              .Build();

            var vatRate = new VatRateBuilder(this.Session).WithRate(21).Build();

            var brand = new BrandBuilder(this.Session).WithDefaults().Build();

            var good_1 = new UnifiedGoodBuilder(this.Session).WithNonSerialisedDefaults(allors).Build();

            this.Session.Derive();

            new InventoryItemTransactionBuilder(this.Session)
            .WithPart(good_1)
            .WithQuantity(100)
            .WithReason(new InventoryTransactionReasons(this.Session).Unknown)
            .Build();

            var good_2 = new NonUnifiedGoodBuilder(this.Session)
                         .WithSerialisedPartDefaults(allors)
                         .Build();

            var serialisedItem1 = new SerialisedItemBuilder(this.Session).WithDefaults(allors).Build();

            good_2.Part.AddSerialisedItem(serialisedItem1);

            this.Session.Derive();

            new SerialisedInventoryItemBuilder(this.Session)
            .WithPart(good_2.Part)
            .WithSerialisedItem(serialisedItem1)
            .WithFacility(allors.StoresWhereInternalOrganisation.First.DefaultFacility)
            .Build();

            var good_3 = new NonUnifiedGoodBuilder(this.Session)
                         .WithNonSerialisedPartDefaults(allors)
                         .Build();

            var good_4 = new UnifiedGoodBuilder(this.Session).WithSerialisedDefaults(allors).Build();

            var productCategory_1 = new ProductCategoryBuilder(this.Session)
                                    .WithInternalOrganisation(allors)
                                    .WithName("Best selling gizmo's")
                                    .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Meest verkochte gizmo's").WithLocale(dutchLocale).Build())
                                    .Build();

            var productCategory_2 = new ProductCategoryBuilder(this.Session)
                                    .WithInternalOrganisation(allors)
                                    .WithName("Big Gizmo's")
                                    .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Grote Gizmo's").WithLocale(dutchLocale).Build())
                                    .Build();

            var productCategory_3 = new ProductCategoryBuilder(this.Session)
                                    .WithInternalOrganisation(allors)
                                    .WithName("Small gizmo's")
                                    .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Kleine gizmo's").WithLocale(dutchLocale).Build())
                                    .WithProduct(good_1)
                                    .WithProduct(good_2)
                                    .WithProduct(good_3)
                                    .WithProduct(good_4)
                                    .Build();

            new CatalogueBuilder(this.Session)
            .WithInternalOrganisation(allors)
            .WithName("New gizmo's")
            .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Nieuwe gizmo's").WithLocale(dutchLocale).Build())
            .WithDescription("Latest in the world of Gizmo's")
            .WithLocalisedDescription(new LocalisedTextBuilder(this.Session).WithText("Laatste in de wereld van Gizmo's").WithLocale(dutchLocale).Build())
            .WithProductCategory(productCategory_1)
            .Build();

            this.Session.Derive();

            var administrator = (Person) new UserGroups(this.Session).Administrators.Members.First;

            new FaceToFaceCommunicationBuilder(this.Session)
            .WithDescription($"Meeting")
            .WithSubject($"meeting")
            .WithEventPurpose(new CommunicationEventPurposes(this.Session).Meeting)
            .WithFromParty(allors.ActiveEmployees.First)
            .WithToParty(allors.ActiveCustomers.First)
            .WithOwner(administrator)
            .WithActualStart(DateTime.UtcNow)
            .Build();

            new EmailCommunicationBuilder(this.Session)
            .WithDescription($"Email")
            .WithSubject($"email")
            .WithFromParty(allors.ActiveEmployees.First)
            .WithToParty(allors.ActiveCustomers.First)
            .WithFromEmail(allors.ActiveEmployees.First.GeneralEmail)
            .WithToEmail(allors.ActiveCustomers.First.GeneralEmail)
            .WithEventPurpose(new CommunicationEventPurposes(this.Session).Meeting)
            .WithOwner(administrator)
            .WithActualStart(DateTime.UtcNow)
            .Build();

            new LetterCorrespondenceBuilder(this.Session)
            .WithDescription($"Letter")
            .WithSubject($"letter")
            .WithFromParty(administrator)
            .WithToParty(allors.ActiveCustomers.First)
            .WithEventPurpose(new CommunicationEventPurposes(this.Session).Meeting)
            .WithOwner(administrator)
            .WithActualStart(DateTime.UtcNow)
            .Build();

            new PhoneCommunicationBuilder(this.Session)
            .WithDescription($"Phone")
            .WithSubject($"phone")
            .WithFromParty(administrator)
            .WithToParty(allors.ActiveCustomers.First)
            .WithEventPurpose(new CommunicationEventPurposes(this.Session).Meeting)
            .WithOwner(administrator)
            .WithActualStart(DateTime.UtcNow)
            .Build();

            new SalesOrderBuilder(this.Session).WithOrganisationInternalDefaults(allors).Build();
            new SalesOrderBuilder(this.Session).WithOrganisationExternalDefaults(allors).Build();
            new SalesOrderBuilder(this.Session).WithPersonInternalDefaults(allors).Build();
            new SalesOrderBuilder(this.Session).WithPersonExternalDefaults(allors).Build();

            new SalesInvoiceBuilder(this.Session).WithSalesExternalB2BInvoiceDefaults(allors).Build();

            new SupplierOfferingBuilder(this.Session)
            .WithPart(good_1)
            .WithSupplier(allors.ActiveSuppliers.First)
            .WithFromDate(this.Session.Now().AddMinutes(-1))
            .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Piece)
            .WithPrice(7)
            .WithCurrency(euro)
            .Build();

            var purchaseInvoiceItem_1 = new PurchaseInvoiceItemBuilder(this.Session)
                                        .WithDescription("first item")
                                        .WithPart(good_1)
                                        .WithAssignedUnitPrice(3000)
                                        .WithQuantity(1)
                                        .WithMessage(@"line1
line2")
                                        .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem)
                                        .Build();

            var purchaseInvoiceItem_2 = new PurchaseInvoiceItemBuilder(this.Session)
                                        .WithDescription("second item")
                                        .WithAssignedUnitPrice(2000)
                                        .WithQuantity(2)
                                        .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem)
                                        .Build();

            var purchaseInvoiceItem_3 = new PurchaseInvoiceItemBuilder(this.Session)
                                        .WithDescription("Service")
                                        .WithAssignedUnitPrice(100)
                                        .WithQuantity(1)
                                        .WithInvoiceItemType(new InvoiceItemTypes(this.Session).Service)
                                        .Build();

            var purchaseInvoice = new PurchaseInvoiceBuilder(this.Session)
                                  .WithBilledTo(allors)
                                  .WithInvoiceNumber("1")
                                  .WithBilledFrom(allors.ActiveSuppliers.First)
                                  .WithPurchaseInvoiceItem(purchaseInvoiceItem_1)
                                  .WithPurchaseInvoiceItem(purchaseInvoiceItem_2)
                                  .WithPurchaseInvoiceItem(purchaseInvoiceItem_3)
                                  .WithCustomerReference("a reference number")
                                  .WithDescription("Purchase of 1 used Aircraft Towbar")
                                  .WithPurchaseInvoiceType(new PurchaseInvoiceTypes(this.Session).PurchaseInvoice)
                                  .WithVatRegime(new VatRegimes(this.Session).Assessable21)
                                  .Build();

            var purchaseOrderItem_1 = new PurchaseOrderItemBuilder(this.Session)
                                      .WithDescription("first purchase order item")
                                      .WithPart(good_1)
                                      .WithQuantityOrdered(1)
                                      .Build();

            var purchaseOrder = new PurchaseOrderBuilder(this.Session)
                                .WithOrderedBy(allors)
                                .WithTakenViaSupplier(allors.ActiveSuppliers.First)
                                .WithPurchaseOrderItem(purchaseOrderItem_1)
                                .WithCustomerReference("reference 123")
                                .WithStoredInFacility(facility)
                                .Build();

            var workTask = new WorkTaskBuilder(this.Session)
                           .WithTakenBy(allors)
                           .WithCustomer(allors.ActiveCustomers.First)
                           .WithName("maintenance")
                           .Build();

            new PositionTypeBuilder(this.Session)
            .WithTitle("Mechanic")
            .WithUniqueId(new Guid("E62A8F4B-8045-472E-AB18-E39C51A02696"))
            .Build();

            new PositionTypeRateBuilder(this.Session)
            .WithRate(100)
            .WithRateType(new RateTypes(this.Session).StandardRate)
            .WithFrequency(new TimeFrequencies(this.Session).Hour)
            .Build();

            this.Session.Derive();

            // Serialized RFQ with Serialized Unified-Good
            var serializedRFQ = new RequestForQuoteBuilder(this.Session).WithSerializedDefaults(allors).Build();

            // NonSerialized RFQ with NonSerialized Unified-Good
            var nonSerializedRFQ = new RequestForQuoteBuilder(this.Session).WithNonSerializedDefaults(allors).Build();

            var quote = new ProductQuoteBuilder(this.Session)
                        .WithIssuer(allors)
                        .WithDescription("quote")
                        .WithReceiver(allors.ActiveCustomers.First)
                        .WithFullfillContactMechanism(allors.ActiveCustomers.First.GeneralCorrespondence)
                        .Build();

            this.Session.Derive();

            var quoteItem = new QuoteItemBuilder(this.Session)
                            .WithProduct(new Goods(this.Session).Extent().First)
                            .WithQuantity(1)
                            .WithAssignedUnitPrice(10)
                            .Build();

            quote.AddQuoteItem(quoteItem);

            this.Session.Derive();

            var salesOrder = new SalesOrderBuilder(this.Session)
                             .WithTakenBy(allors)
                             .WithShipToCustomer(allors.ActiveCustomers.First)
                             .Build();

            this.Session.Derive();

            var salesOrderItem = new SalesOrderItemBuilder(this.Session)
                                 .WithProduct(good_1)
                                 .WithQuantityOrdered(1)
                                 .WithAssignedUnitPrice(10)
                                 .Build();

            salesOrder.AddSalesOrderItem(salesOrderItem);

            this.Session.Derive();

            new CustomerShipmentBuilder(this.Session).WithDefaults(allors).Build();

            this.Session.Derive();

            new PurchaseShipmentBuilder(this.Session).WithDefaults(allors).Build();

            this.Session.Derive();
        }
Exemplo n.º 34
0
        public void CreateWithNonSerializedPartDefaults()
        {
            var before = new PurchaseOrderItems(this.Session).Extent().ToArray();

            var expected = new PurchaseOrderItemBuilder(this.Session).WithNonSerializedPartDefaults(this.nonSerializedPartItem.Part).Build();

            this.purchaseOrder.AddPurchaseOrderItem(expected);

            this.Session.Derive();

            Assert.True(expected.ExistDescription);
            Assert.True(expected.ExistComment);
            Assert.True(expected.ExistInternalComment);
            Assert.True(expected.ExistInvoiceItemType);
            Assert.True(expected.ExistPart);
            Assert.True(expected.ExistQuantityOrdered);
            Assert.True(expected.ExistAssignedUnitPrice);
            Assert.True(expected.ExistMessage);

            var expectedDescription       = expected.Description;
            var expectedComment           = expected.Comment;
            var expectedInternalComment   = expected.InternalComment;
            var expectedInvoiceItemType   = expected.InvoiceItemType;
            var expectedPart              = expected.Part;
            var expectedQuantityOrdered   = expected.QuantityOrdered;
            var expectedAssignedUnitPrice = expected.AssignedUnitPrice;
            var expectedMessage           = expected.Message;

            this.purchaseOrderListPage.Table.DefaultAction(this.purchaseOrder);
            var purchaseOrderOverview          = new PurchaseOrderOverviewComponent(this.purchaseOrderListPage.Driver);
            var purchaseOrderItemOverviewPanel = purchaseOrderOverview.PurchaseorderitemOverviewPanel.Click();

            var purchaseOrderItemCreate = purchaseOrderItemOverviewPanel.CreatePurchaseOrderItem();

            purchaseOrderItemCreate.InvoiceItemType.Select(expected.InvoiceItemType);
            purchaseOrderItemCreate.PurchaseOrderItemPart_2.Select(expected.Part.Name);
            purchaseOrderItemCreate.OrderItemDescription_1.Set(expected.Description);
            purchaseOrderItemCreate.Comment.Set(expected.Comment);
            purchaseOrderItemCreate.InternalComment.Set(expected.InternalComment);
            purchaseOrderItemCreate.QuantityOrdered.Set(expected.QuantityOrdered.ToString());
            purchaseOrderItemCreate.AssignedUnitPrice.Set(expected.AssignedUnitPrice.ToString());
            purchaseOrderItemCreate.Message.Set(expected.Message);

            this.Session.Rollback();
            purchaseOrderItemCreate.SAVE.Click();

            this.Driver.WaitForAngular();
            this.Session.Rollback();

            var after = new PurchaseOrderItems(this.Session).Extent().ToArray();

            Assert.Equal(after.Length, before.Length + 1);

            var actual = after.Except(before).First();

            Assert.Equal(expectedDescription, actual.Description);
            Assert.Equal(expectedComment, actual.Comment);
            Assert.Equal(expectedInternalComment, actual.InternalComment);
            Assert.Equal(expectedInvoiceItemType, actual.InvoiceItemType);
            Assert.Equal(expectedPart, actual.Part);
            Assert.Equal(expectedQuantityOrdered, actual.QuantityOrdered);
            Assert.Equal(expectedAssignedUnitPrice, actual.AssignedUnitPrice);
            Assert.Equal(expectedMessage, actual.Message);
        }
Exemplo n.º 35
0
        public void GivenOrderItem_WhenObjectStateIsRejected_ThenItemMayNotBeCancelledOrRejectedOrDeleted()
        {
            var administrator = new PersonBuilder(this.DatabaseSession).WithFirstName("Koen").WithUserName("admin").Build();
            var administrators = new UserGroups(this.DatabaseSession).Administrators;
            administrators.AddMember(administrator);

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            this.InstantiateObjects(this.DatabaseSession);

            var good = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithName("good")
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithVatRate(new VatRates(this.DatabaseSession).FindBy(VatRates.Meta.Rate,21))
                .Build();

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin", "Forms"), new string[0]);

            var item = new PurchaseOrderItemBuilder(this.DatabaseSession)
                .WithProduct(good)
                .WithQuantityOrdered(3)
                .WithActualUnitPrice(5)
                .Build();

            this.order.AddPurchaseOrderItem(item);

            this.DatabaseSession.Derive(true);

            item.Reject();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).Rejected, item.CurrentObjectState);
            var acl = new AccessControlList(item, new Users(this.DatabaseSession).GetCurrentUser());
            Assert.IsFalse(acl.CanExecute(PurchaseOrderItems.Meta.Cancel));
            Assert.IsFalse(acl.CanExecute(PurchaseOrderItems.Meta.Reject));
            Assert.IsFalse(acl.CanExecute(PurchaseOrderItems.Meta.Delete));
        }
Exemplo n.º 36
0
        public void GivenOrderItem_WhenObjectStateIsPartiallyReceived_ThenProductChangeIsNotAllowed()
        {
            var administrator = new PersonBuilder(this.DatabaseSession).WithFirstName("Koen").WithUserName("admin").Build();
            var administrators = new UserGroups(this.DatabaseSession).Administrators;
            administrators.AddMember(administrator);

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            this.InstantiateObjects(this.DatabaseSession);

            var good = new GoodBuilder(this.DatabaseSession)
                .WithSku("10101")
                .WithName("good")
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithVatRate(new VatRates(this.DatabaseSession).FindBy(VatRates.Meta.Rate,21))
                .Build();

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin", "Forms"), new string[0]);

            var item = new PurchaseOrderItemBuilder(this.DatabaseSession)
                .WithProduct(good)
                .WithQuantityOrdered(3)
                .WithActualUnitPrice(5)
                .Build();

            this.order.AddPurchaseOrderItem(item);

            this.order.Confirm();

            this.DatabaseSession.Derive(true);

            var shipment = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(this.supplier).Build();
            var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithGood(good).Build();
            shipment.AddShipmentItem(shipmentItem);

            new ShipmentReceiptBuilder(this.DatabaseSession)
                .WithQuantityAccepted(1)
                .WithShipmentItem(shipmentItem)
                .WithOrderItem(item)
                .Build();

            shipment.AppsComplete();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).PartiallyReceived, item.CurrentObjectState);
            var acl = new AccessControlList(item, new Users(this.DatabaseSession).GetCurrentUser());
            Assert.IsFalse(acl.CanWrite(PurchaseOrderItems.Meta.Product));
        }
Exemplo n.º 37
0
        public void GivenPurchaseOrder_WhenShipmentIsReceived_ThenCurrenShipmentStatusIsUpdated()
        {
            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build();

            var part = new RawMaterialBuilder(this.DatabaseSession).WithName("RawMaterial").Build();

            var order = new PurchaseOrderBuilder(this.DatabaseSession)
                .WithTakenViaSupplier(supplier)
                .WithBillToPurchaser(internalOrganisation)
                .WithVatRegime(new VatRegimes(this.DatabaseSession).Exempt)
                .Build();

            var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(1).Build();
            var item2 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(2).Build();
            var item3 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(3).Build();
            order.AddPurchaseOrderItem(item1);
            order.AddPurchaseOrderItem(item2);
            order.AddPurchaseOrderItem(item3);

            this.DatabaseSession.Derive(true);

            order.Confirm();

            this.DatabaseSession.Derive(true);

            var shipment1 = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build();
            var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithPart(part).Build();
            shipment1.AddShipmentItem(shipmentItem);

            new ShipmentReceiptBuilder(this.DatabaseSession)
                .WithQuantityAccepted(1)
                .WithShipmentItem(shipmentItem)
                .WithOrderItem(item1)
                .Build();

            shipment1.AppsComplete();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).Received, item1.CurrentShipmentStatus.PurchaseOrderItemObjectState);
            Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).PartiallyReceived, order.CurrentShipmentStatus.PurchaseOrderObjectState);
            Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).InProcess, order.CurrentOrderStatus.PurchaseOrderObjectState);

            var shipment2 = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build();
            shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithPart(part).Build();
            shipment2.AddShipmentItem(shipmentItem);

            new ShipmentReceiptBuilder(this.DatabaseSession)
                .WithQuantityAccepted(2)
                .WithShipmentItem(shipmentItem)
                .WithOrderItem(item2)
                .Build();

            shipment2.AppsComplete();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).Received, item2.CurrentShipmentStatus.PurchaseOrderItemObjectState);
            Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).PartiallyReceived, order.CurrentShipmentStatus.PurchaseOrderObjectState);
            Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).InProcess, order.CurrentOrderStatus.PurchaseOrderObjectState);

            var shipment3 = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build();
            shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithPart(part).Build();
            shipment3.AddShipmentItem(shipmentItem);

            new ShipmentReceiptBuilder(this.DatabaseSession)
                .WithQuantityAccepted(3)
                .WithShipmentItem(shipmentItem)
                .WithOrderItem(item3)
                .Build();

            shipment3.AppsComplete();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).Received, item3.CurrentShipmentStatus.PurchaseOrderItemObjectState);
            Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).Received, order.CurrentShipmentStatus.PurchaseOrderObjectState);
            Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).Completed, order.CurrentOrderStatus.PurchaseOrderObjectState);
        }
Exemplo n.º 38
0
        public void GivenPurchaseOrder_WhenOrdering_ThenAllValidItemsAreInInProcessState()
        {
            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build();

            var part = new RawMaterialBuilder(this.DatabaseSession).WithName("RawMaterial").Build();

            var order = new PurchaseOrderBuilder(this.DatabaseSession)
                .WithTakenViaSupplier(supplier)
                .WithVatRegime(new VatRegimes(this.DatabaseSession).Exempt)
                .Build();

            var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(1).Build();
            var item2 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(2).Build();
            var item3 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(3).Build();
            order.AddPurchaseOrderItem(item1);
            order.AddPurchaseOrderItem(item2);
            order.AddPurchaseOrderItem(item3);

            this.DatabaseSession.Derive(true);

            order.Confirm();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(3, order.ValidOrderItems.Count);
            Assert.Contains(item1, order.ValidOrderItems);
            Assert.Contains(item2, order.ValidOrderItems);
            Assert.Contains(item3, order.ValidOrderItems);
            Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).InProcess, item1.CurrentObjectState);
            Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).InProcess, item2.CurrentObjectState);
            Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).InProcess, item3.CurrentObjectState);
        }
Exemplo n.º 39
0
        public void Execute()
        {
            var singleton   = this.Session.GetSingleton();
            var dutchLocale = new Locales(this.Session).DutchNetherlands;

            singleton.AddAdditionalLocale(dutchLocale);

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

            var be = new Countries(this.Session).FindBy(M.Country.IsoCode, "BE");
            var us = new Countries(this.Session).FindBy(M.Country.IsoCode, "US");

            var email2 = new EmailAddressBuilder(this.Session)
                         .WithElectronicAddressString("*****@*****.**")
                         .Build();

            var allorsLogo = this.DataPath + @"\www\admin\images\logo.png";

            var allors = Organisations.CreateInternalOrganisation(
                session: this.Session,
                name: "Allors BVBA",
                address: "Kleine Nieuwedijkstraat 4",
                postalCode: "2800",
                locality: "Mechelen",
                country: be,
                phone1CountryCode: "+32",
                phone1: "2 335 2335",
                phone1Purpose: new ContactMechanismPurposes(this.Session).GeneralPhoneNumber,
                phone2CountryCode: string.Empty,
                phone2: string.Empty,
                phone2Purpose: null,
                emailAddress: "*****@*****.**",
                websiteAddress: "www.allors.com",
                taxNumber: "BE 0476967014",
                bankName: "ING",
                facilityName: "Allors Warehouse 1",
                bic: "BBRUBEBB",
                iban: "BE89 3200 1467 7685",
                currency: euro,
                logo: allorsLogo,
                storeName: "Allors Store",
                billingProcess: new BillingProcesses(this.Session).BillingForOrderItems,
                outgoingShipmentNumberPrefix: "a-CS",
                salesInvoiceNumberPrefix: "a-SI",
                salesOrderNumberPrefix: "a-SO",
                requestNumberPrefix: "a-RFQ",
                quoteNumberPrefix: "a-Q",
                productNumberPrefix: "A-",
                requestCounterValue: 1,
                quoteCounterValue: 1,
                orderCounterValue: 1,
                invoiceCounterValue: 1);

            var dipu = Organisations.CreateInternalOrganisation(
                session: this.Session,
                name: "Dipu BVBA",
                address: "Kleine Nieuwedijkstraat 2",
                postalCode: "2800",
                locality: "Mechelen",
                country: be,
                phone1CountryCode: "+32",
                phone1: "2 15 49 49 49",
                phone1Purpose: new ContactMechanismPurposes(this.Session).GeneralPhoneNumber,
                phone2CountryCode: string.Empty,
                phone2: string.Empty,
                phone2Purpose: null,
                emailAddress: "*****@*****.**",
                websiteAddress: "www.dipu.com",
                taxNumber: "BE 0445366489",
                bankName: "ING",
                facilityName: "Dipu Facility",
                bic: "BBRUBEBB",
                iban: "BE23 3300 6167 6391",
                currency: euro,
                logo: allorsLogo,
                storeName: "Dipu Store",
                billingProcess: new BillingProcesses(this.Session).BillingForOrderItems,
                outgoingShipmentNumberPrefix: "d-CS",
                salesInvoiceNumberPrefix: "d-SI",
                salesOrderNumberPrefix: "d-SO",
                requestNumberPrefix: "d-RFQ",
                quoteNumberPrefix: "d-Q",
                productNumberPrefix: "D-",
                requestCounterValue: 1,
                quoteCounterValue: 1,
                orderCounterValue: 1,
                invoiceCounterValue: 1);

            singleton.Settings.DefaultFacility = allors.FacilitiesWhereOwner.First;

            this.SetupUser(allors, "*****@*****.**", "first", "allors employee", "letmein");
            this.SetupUser(dipu, "*****@*****.**", "first", "dipu employee", "letmein");

            new FacilityBuilder(this.Session)
            .WithName("Allors warehouse 2")
            .WithFacilityType(new FacilityTypes(this.Session).Warehouse)
            .WithOwner(allors)
            .Build();

            var manufacturer = new OrganisationBuilder(this.Session).WithName("Gizmo inc.").WithIsManufacturer(true).Build();

            var productType = new ProductTypeBuilder(this.Session)
                              .WithName($"Gizmo")
                              .WithSerialisedItemCharacteristicType(new SerialisedItemCharacteristicTypeBuilder(this.Session)
                                                                    .WithName("Size")
                                                                    .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Afmeting").WithLocale(dutchLocale).Build())
                                                                    .Build())
                              .WithSerialisedItemCharacteristicType(new SerialisedItemCharacteristicTypeBuilder(this.Session)
                                                                    .WithName("Weight")
                                                                    .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Gewicht").WithLocale(dutchLocale).Build())
                                                                    .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Kilogram)
                                                                    .Build())
                              .Build();

            var vatRate = new VatRateBuilder(this.Session).WithRate(21).Build();

            var brand = new BrandBuilder(this.Session)
                        .WithName("brand1")
                        .WithModel(new ModelBuilder(this.Session).WithName("model1").Build())
                        .Build();

            var finishedGood = new NonUnifiedPartBuilder(this.Session)
                               .WithProductIdentification(new SkuIdentificationBuilder(this.Session)
                                                          .WithIdentification("10101")
                                                          .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Sku).Build())
                               .WithName("finished good")
                               .WithBrand(brand)
                               .WithModel(brand.Models[0])
                               .WithInventoryItemKind(new InventoryItemKinds(this.Session).NonSerialised)
                               .WithManufacturedBy(manufacturer)
                               .Build();

            var good1 = new NonUnifiedGoodBuilder(this.Session)
                        .WithProductIdentification(new ProductNumberBuilder(this.Session)
                                                   .WithIdentification("G1")
                                                   .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Good).Build())
                        .WithName("Tiny blue round gizmo")
                        .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Zeer kleine blauwe ronde gizmo").WithLocale(dutchLocale).Build())
                        .WithDescription("Perfect blue with nice curves")
                        .WithLocalisedDescription(new LocalisedTextBuilder(this.Session).WithText("Perfect blauw met mooie rondingen").WithLocale(dutchLocale).Build())
                        .WithVatRate(vatRate)
                        .WithPart(finishedGood)
                        .Build();

            new InventoryItemTransactionBuilder(this.Session)
            .WithPart(finishedGood)
            .WithFacility(allors.FacilitiesWhereOwner.First)
            .WithQuantity(100)
            .WithReason(new InventoryTransactionReasons(this.Session).Unknown)
            .Build();

            var finishedGood2 = new NonUnifiedPartBuilder(this.Session)
                                .WithName("finished good2")
                                .WithInventoryItemKind(new InventoryItemKinds(this.Session).Serialised)
                                .WithProductType(productType)
                                .WithProductIdentification(new SkuIdentificationBuilder(this.Session)
                                                           .WithIdentification("10102")
                                                           .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Sku).Build())
                                .WithManufacturedBy(manufacturer)
                                .Build();

            var good2 = new NonUnifiedGoodBuilder(this.Session)
                        .WithProductIdentification(new ProductNumberBuilder(this.Session)
                                                   .WithIdentification("G2")
                                                   .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Good).Build())
                        .WithName("Tiny red round gizmo")
                        .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Zeer kleine rode ronde gizmo").WithLocale(dutchLocale).Build())
                        .WithDescription("Perfect red with nice curves")
                        .WithLocalisedDescription(new LocalisedTextBuilder(this.Session).WithText("Perfect rood met mooie rondingen").WithLocale(dutchLocale).Build())
                        .WithVatRate(vatRate)
                        .WithPart(finishedGood2)
                        .Build();

            var serialisedItem = new SerialisedItemBuilder(this.Session).WithSerialNumber("1").WithAvailableForSale(true).Build();

            finishedGood2.AddSerialisedItem(serialisedItem);

            new InventoryItemTransactionBuilder(this.Session)
            .WithSerialisedItem(serialisedItem)
            .WithFacility(allors.FacilitiesWhereOwner.First)
            .WithQuantity(1)
            .WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment)
            .WithSerialisedInventoryItemState(new SerialisedInventoryItemStates(this.Session).Available)
            .Build();

            var finishedGood3 = new NonUnifiedPartBuilder(this.Session)
                                .WithProductIdentification(new SkuIdentificationBuilder(this.Session)
                                                           .WithIdentification("10103")
                                                           .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Sku).Build())
                                .WithName("finished good3")
                                .WithInventoryItemKind(new InventoryItemKinds(this.Session).NonSerialised)
                                .WithManufacturedBy(manufacturer)
                                .Build();

            var good3 = new NonUnifiedGoodBuilder(this.Session)
                        .WithProductIdentification(new ProductNumberBuilder(this.Session)
                                                   .WithIdentification("G3")
                                                   .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Good).Build())
                        .WithName("Tiny green round gizmo")
                        .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Zeer kleine groene ronde gizmo").WithLocale(dutchLocale).Build())
                        .WithDescription("Perfect red with nice curves")
                        .WithLocalisedDescription(new LocalisedTextBuilder(this.Session).WithText("Perfect groen met mooie rondingen").WithLocale(dutchLocale).Build())
                        .WithVatRate(vatRate)
                        .WithPart(finishedGood3)
                        .Build();

            var finishedGood4 = new NonUnifiedPartBuilder(this.Session)
                                .WithName("finished good4")
                                .WithInventoryItemKind(new InventoryItemKinds(this.Session).Serialised)
                                .WithProductType(productType)
                                .WithManufacturedBy(manufacturer)
                                .Build();

            var good4 = new NonUnifiedGoodBuilder(this.Session)
                        .WithProductIdentification(new ProductNumberBuilder(this.Session)
                                                   .WithIdentification("G4")
                                                   .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Good).Build())
                        .WithName("Tiny purple round gizmo")
                        .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Zeer kleine paarse ronde gizmo").WithLocale(dutchLocale).Build())
                        .WithVatRate(vatRate)
                        .WithPart(finishedGood4)
                        .Build();

            var productCategory1 = new ProductCategoryBuilder(this.Session)
                                   .WithInternalOrganisation(allors)
                                   .WithName("Best selling gizmo's")
                                   .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Meest verkochte gizmo's").WithLocale(dutchLocale).Build())
                                   .Build();

            var productCategory2 = new ProductCategoryBuilder(this.Session)
                                   .WithInternalOrganisation(allors)
                                   .WithName("Big Gizmo's")
                                   .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Grote Gizmo's").WithLocale(dutchLocale).Build())
                                   .Build();

            var productCategory3 = new ProductCategoryBuilder(this.Session)
                                   .WithInternalOrganisation(allors)
                                   .WithName("Small gizmo's")
                                   .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Kleine gizmo's").WithLocale(dutchLocale).Build())
                                   .WithProduct(good1)
                                   .WithProduct(good2)
                                   .WithProduct(good3)
                                   .WithProduct(good4)
                                   .Build();

            new CatalogueBuilder(this.Session)
            .WithInternalOrganisation(allors)
            .WithName("New gizmo's")
            .WithLocalisedName(new LocalisedTextBuilder(this.Session).WithText("Nieuwe gizmo's").WithLocale(dutchLocale).Build())
            .WithDescription("Latest in the world of Gizmo's")
            .WithLocalisedDescription(new LocalisedTextBuilder(this.Session).WithText("Laatste in de wereld van Gizmo's").WithLocale(dutchLocale).Build())
            .WithProductCategory(productCategory1)
            .Build();

            this.Session.Derive();

            for (int i = 0; i < 100; i++)
            {
                var acmePostalAddress = new PostalAddressBuilder(this.Session)
                                        .WithAddress1($"Acme{i} address 1")
                                        .WithPostalBoundary(new PostalBoundaryBuilder(this.Session).WithLocality($"Acme{i} city").WithPostalCode("1111").WithCountry(us).Build())
                                        .Build();

                var acmeBillingAddress = new PartyContactMechanismBuilder(this.Session)
                                         .WithContactMechanism(acmePostalAddress)
                                         .WithContactPurpose(new ContactMechanismPurposes(this.Session).GeneralCorrespondence)
                                         .WithUseAsDefault(true)
                                         .Build();

                var acmeInquiries = new PartyContactMechanismBuilder(this.Session)
                                    .WithContactMechanism(new TelecommunicationsNumberBuilder(this.Session).WithCountryCode("+1").WithContactNumber("111 222 333").Build())
                                    .WithContactPurpose(new ContactMechanismPurposes(this.Session).GeneralPhoneNumber)
                                    .WithContactPurpose(new ContactMechanismPurposes(this.Session).OrderInquiriesPhone)
                                    .WithUseAsDefault(true)
                                    .Build();

                var acme = new OrganisationBuilder(this.Session)
                           .WithName($"Acme{i}")
                           .WithLocale(new Locales(this.Session).EnglishUnitedStates)
                           .WithPartyContactMechanism(acmeBillingAddress)
                           .WithPartyContactMechanism(acmeInquiries)
                           .WithTaxNumber($"{1000 + i}-{1000 + i}-{1000 + i}")
                           .Build();

                var contact1Email = new PartyContactMechanismBuilder(this.Session)
                                    .WithContactMechanism(new EmailAddressBuilder(this.Session).WithElectronicAddressString($"employee1@acme{i}.com").Build())
                                    .WithContactPurpose(new ContactMechanismPurposes(this.Session).PersonalEmailAddress)
                                    .WithUseAsDefault(true)
                                    .Build();

                var contact2PhoneNumber = new PartyContactMechanismBuilder(this.Session)
                                          .WithContactMechanism(new TelecommunicationsNumberBuilder(this.Session).WithCountryCode("+1").WithAreaCode("123").WithContactNumber("456").Build())
                                          .WithContactPurpose(new ContactMechanismPurposes(this.Session).GeneralPhoneNumber)
                                          .WithUseAsDefault(true)
                                          .Build();

                var contact1 = new PersonBuilder(this.Session)
                               .WithFirstName($"John{i}")
                               .WithLastName($"Doe{i}")
                               .WithGender(new GenderTypes(this.Session).Male)
                               .WithLocale(new Locales(this.Session).EnglishUnitedStates)
                               .WithPartyContactMechanism(contact1Email)
                               .Build();

                var contact2 = new PersonBuilder(this.Session)
                               .WithFirstName($"Jane{i}")
                               .WithLastName($"Doe{i}")
                               .WithGender(new GenderTypes(this.Session).Male)
                               .WithLocale(new Locales(this.Session).EnglishUnitedStates)
                               .WithPartyContactMechanism(contact2PhoneNumber)
                               .Build();

                new CustomerRelationshipBuilder(this.Session)
                .WithCustomer(acme)
                .WithInternalOrganisation(allors)
                .WithFromDate(DateTime.UtcNow)
                .Build();

                new OrganisationContactRelationshipBuilder(this.Session)
                .WithOrganisation(acme)
                .WithContact(contact1)
                .WithContactKind(new OrganisationContactKinds(this.Session).FindBy(M.OrganisationContactKind.Description, "General contact"))
                .WithFromDate(DateTime.UtcNow)
                .Build();

                new OrganisationContactRelationshipBuilder(this.Session)
                .WithOrganisation(acme)
                .WithContact(contact2)
                .WithContactKind(new OrganisationContactKinds(this.Session).FindBy(M.OrganisationContactKind.Description, "General contact"))
                .WithFromDate(DateTime.UtcNow)
                .Build();

                var administrator = (Person) new UserGroups(this.Session).Administrators.Members.First;

                new FaceToFaceCommunicationBuilder(this.Session)
                .WithDescription($"Meeting {i}")
                .WithSubject($"meeting {i}")
                .WithEventPurpose(new CommunicationEventPurposes(this.Session).Meeting)
                .WithFromParty(contact1)
                .WithToParty(contact2)
                .WithOwner(administrator)
                .WithActualStart(DateTime.UtcNow)
                .Build();

                new EmailCommunicationBuilder(this.Session)
                .WithDescription($"Email {i}")
                .WithSubject($"email {i}")
                .WithFromEmail(email2)
                .WithToEmail(email2)
                .WithEventPurpose(new CommunicationEventPurposes(this.Session).Meeting)
                .WithOwner(administrator)
                .WithActualStart(DateTime.UtcNow)
                .Build();

                new LetterCorrespondenceBuilder(this.Session)
                .WithDescription($"Letter {i}")
                .WithSubject($"letter {i}")
                .WithFromParty(administrator)
                .WithToParty(contact1)
                .WithEventPurpose(new CommunicationEventPurposes(this.Session).Meeting)
                .WithOwner(administrator)
                .WithActualStart(DateTime.UtcNow)
                .Build();

                new PhoneCommunicationBuilder(this.Session)
                .WithDescription($"Phone {i}")
                .WithSubject($"phone {i}")
                .WithFromParty(administrator)
                .WithToParty(contact1)
                .WithEventPurpose(new CommunicationEventPurposes(this.Session).Meeting)
                .WithOwner(administrator)
                .WithActualStart(DateTime.UtcNow)
                .Build();

                var requestForQuote = new RequestForQuoteBuilder(this.Session)
                                      .WithEmailAddress($"customer{i}@acme.com")
                                      .WithTelephoneNumber("+1 234 56789")
                                      .WithRecipient(allors)
                                      .Build();

                var requestItem = new RequestItemBuilder(this.Session)
                                  .WithSerialisedItem(serialisedItem)
                                  .WithProduct(serialisedItem.PartWhereSerialisedItem.NonUnifiedGoodsWherePart.FirstOrDefault())
                                  .WithComment($"Comment {i}")
                                  .WithQuantity(1)
                                  .Build();

                requestForQuote.AddRequestItem(requestItem);

                var productQuote = new ProductQuoteBuilder(this.Session)
                                   .WithIssuer(allors)
                                   .WithReceiver(acme)
                                   .WithFullfillContactMechanism(acmePostalAddress)
                                   .Build();

                var quoteItem = new QuoteItemBuilder(this.Session)
                                .WithSerialisedItem(serialisedItem)
                                .WithProduct(serialisedItem.PartWhereSerialisedItem.NonUnifiedGoodsWherePart.FirstOrDefault())
                                .WithComment($"Comment {i}")
                                .WithQuantity(1)
                                .Build();

                productQuote.AddQuoteItem(quoteItem);

                var salesOrderItem1 = new SalesOrderItemBuilder(this.Session)
                                      .WithDescription("first item")
                                      .WithProduct(good1)
                                      .WithActualUnitPrice(3000)
                                      .WithQuantityOrdered(1)
                                      .WithMessage(@"line1
line2")
                                      .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem)
                                      .Build();

                var salesOrderItem2 = new SalesOrderItemBuilder(this.Session)
                                      .WithDescription("second item")
                                      .WithActualUnitPrice(2000)
                                      .WithQuantityOrdered(2)
                                      .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem)
                                      .Build();

                var salesOrderItem3 = new SalesOrderItemBuilder(this.Session)
                                      .WithDescription("Fee")
                                      .WithActualUnitPrice(100)
                                      .WithQuantityOrdered(1)
                                      .WithInvoiceItemType(new InvoiceItemTypes(this.Session).Fee)
                                      .Build();

                var order = new SalesOrderBuilder(this.Session)
                            .WithTakenBy(allors)
                            .WithBillToCustomer(acme)
                            .WithBillToEndCustomerContactMechanism(acmeBillingAddress.ContactMechanism)
                            .WithSalesOrderItem(salesOrderItem1)
                            .WithSalesOrderItem(salesOrderItem2)
                            .WithSalesOrderItem(salesOrderItem3)
                            .WithCustomerReference("a reference number")
                            .WithDescription("Sale of 1 used Aircraft Towbar")
                            .WithVatRegime(new VatRegimes(this.Session).Assessable)
                            .Build();

                var salesInvoiceItem1 = new SalesInvoiceItemBuilder(this.Session)
                                        .WithDescription("first item")
                                        .WithProduct(good1)
                                        .WithActualUnitPrice(3000)
                                        .WithQuantity(1)
                                        .WithMessage(@"line1
line2")
                                        .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem)
                                        .Build();

                var salesInvoiceItem2 = new SalesInvoiceItemBuilder(this.Session)
                                        .WithDescription("second item")
                                        .WithActualUnitPrice(2000)
                                        .WithQuantity(2)
                                        .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem)
                                        .Build();

                var salesInvoiceItem3 = new SalesInvoiceItemBuilder(this.Session)
                                        .WithDescription("Fee")
                                        .WithActualUnitPrice(100)
                                        .WithQuantity(1)
                                        .WithInvoiceItemType(new InvoiceItemTypes(this.Session).Fee)
                                        .Build();

                var exw      = new IncoTermTypes(this.Session).Exw;
                var incoTerm = new IncoTermBuilder(this.Session).WithTermType(exw).WithTermValue("XW").Build();

                var salesInvoice = new SalesInvoiceBuilder(this.Session)
                                   .WithBilledFrom(allors)
                                   .WithBillToCustomer(acme)
                                   .WithBillToContactPerson(contact1)
                                   .WithBillToContactMechanism(acme.PartyContactMechanisms[0].ContactMechanism)
                                   .WithBillToEndCustomerContactMechanism(acmeBillingAddress.ContactMechanism)
                                   .WithShipToContactPerson(contact2)
                                   .WithSalesInvoiceItem(salesInvoiceItem1)
                                   .WithSalesInvoiceItem(salesInvoiceItem2)
                                   .WithSalesInvoiceItem(salesInvoiceItem3)
                                   .WithCustomerReference("a reference number")
                                   .WithDescription("Sale of 1 used Aircraft Towbar")
                                   .WithSalesInvoiceType(new SalesInvoiceTypes(this.Session).SalesInvoice)
                                   .WithSalesTerm(incoTerm)
                                   .WithVatRegime(new VatRegimes(this.Session).Assessable)
                                   .Build();

                for (var j = 0; j < 30; j++)
                {
                    var salesInvoiceItem = new SalesInvoiceItemBuilder(this.Session)
                                           .WithDescription("Extra Charge")
                                           .WithActualUnitPrice(100 + j)
                                           .WithQuantity(j)
                                           .WithInvoiceItemType(new InvoiceItemTypes(this.Session).MiscCharge)
                                           .Build();

                    salesInvoice.AddSalesInvoiceItem(salesInvoiceItem);
                }
            }

            for (int i = 0; i < 4; i++)
            {
                var supplierPostalAddress = new PostalAddressBuilder(this.Session)
                                            .WithAddress1($"Supplier{i} address 1")
                                            .WithPostalBoundary(new PostalBoundaryBuilder(this.Session).WithLocality($"Supplier{i} city").WithPostalCode("1111").WithCountry(us).Build())
                                            .Build();

                var supplierBillingAddress = new PartyContactMechanismBuilder(this.Session)
                                             .WithContactMechanism(supplierPostalAddress)
                                             .WithContactPurpose(new ContactMechanismPurposes(this.Session).GeneralCorrespondence)
                                             .WithUseAsDefault(true)
                                             .Build();

                var supplier = new OrganisationBuilder(this.Session)
                               .WithName($"Supplier{i}")
                               .WithLocale(new Locales(this.Session).EnglishUnitedStates)
                               .WithPartyContactMechanism(supplierBillingAddress)
                               .Build();

                new SupplierRelationshipBuilder(this.Session)
                .WithSupplier(supplier)
                .WithInternalOrganisation(allors)
                .WithFromDate(DateTime.UtcNow)
                .Build();

                var purchaseInvoiceItem1 = new PurchaseInvoiceItemBuilder(this.Session)
                                           .WithDescription("first item")
                                           .WithPart(finishedGood)
                                           .WithActualUnitPrice(3000)
                                           .WithQuantity(1)
                                           .WithMessage(@"line1
line2")
                                           .WithInvoiceItemType(new InvoiceItemTypes(this.Session).PartItem)
                                           .Build();

                var purchaseInvoiceItem2 = new PurchaseInvoiceItemBuilder(this.Session)
                                           .WithDescription("second item")
                                           .WithActualUnitPrice(2000)
                                           .WithQuantity(2)
                                           .WithPart(finishedGood2)
                                           .WithInvoiceItemType(new InvoiceItemTypes(this.Session).PartItem)
                                           .Build();

                var purchaseInvoiceItem3 = new PurchaseInvoiceItemBuilder(this.Session)
                                           .WithDescription("Fee")
                                           .WithActualUnitPrice(100)
                                           .WithQuantity(1)
                                           .WithInvoiceItemType(new InvoiceItemTypes(this.Session).Fee)
                                           .Build();

                var purchaseInvoice = new PurchaseInvoiceBuilder(this.Session)
                                      .WithBilledTo(allors)
                                      .WithBilledFrom(supplier)
                                      .WithPurchaseInvoiceItem(purchaseInvoiceItem1)
                                      .WithPurchaseInvoiceItem(purchaseInvoiceItem2)
                                      .WithPurchaseInvoiceItem(purchaseInvoiceItem3)
                                      .WithCustomerReference("a reference number")
                                      .WithDescription("Purchase of 1 used Aircraft Towbar")
                                      .WithPurchaseInvoiceType(new PurchaseInvoiceTypes(this.Session).PurchaseInvoice)
                                      .WithVatRegime(new VatRegimes(this.Session).Assessable)
                                      .Build();

                var purchaseOrderItem1 = new PurchaseOrderItemBuilder(this.Session)
                                         .WithDescription("first purchase order item")
                                         .WithPart(finishedGood)
                                         .WithQuantityOrdered(1)
                                         .Build();

                var purchaseOrder = new PurchaseOrderBuilder(this.Session)
                                    .WithOrderedBy(allors)
                                    .WithTakenViaSupplier(supplier)
                                    .WithPurchaseOrderItem(purchaseOrderItem1)
                                    .WithCustomerReference("a reference number")
                                    .Build();
            }

            var acme0 = new Organisations(this.Session).FindBy(M.Organisation.Name, "Acme0");

            var item = new SerialisedItemBuilder(this.Session)
                       .WithSerialNumber("112")
                       .WithSerialisedItemState(new SerialisedItemStates(this.Session).Sold)
                       .WithAvailableForSale(false)
                       .WithOwnedBy(acme0)
                       .Build();

            finishedGood2.AddSerialisedItem(item);

            var worktask = new WorkTaskBuilder(this.Session)
                           .WithTakenBy(allors)
                           .WithCustomer(new Organisations(this.Session).FindBy(M.Organisation.Name, "Acme0"))
                           .WithName("maintenance")
                           .Build();

            new WorkEffortFixedAssetAssignmentBuilder(this.Session)
            .WithFixedAsset(item)
            .WithAssignment(worktask)
            .Build();

            this.Session.Derive();
        }