Example #1
0
        public void GivenFinishedGoodWithSerializedInventory_WhenDeriving_ThenQuantityOnHandUpdated()
        {
            // Arrange
            var available = new SerialisedInventoryItemStates(this.Session).Available;
            var warehouse = new Facilities(this.Session).FindBy(M.Facility.FacilityType, new FacilityTypes(this.Session).Warehouse);

            var kinds          = new InventoryItemKinds(this.Session);
            var unitsOfMeasure = new UnitsOfMeasure(this.Session);
            var unknown        = new InventoryTransactionReasons(this.Session).Unknown;

            var vatRate21   = new VatRateBuilder(this.Session).WithRate(21).Build();
            var category    = new ProductCategoryBuilder(this.Session).WithName("category").Build();
            var serialPart  = CreatePart("FG1", kinds.Serialised);
            var serialItem1 = new SerialisedItemBuilder(this.Session).WithSerialNumber("1").Build();
            var serialItem2 = new SerialisedItemBuilder(this.Session).WithSerialNumber("2").Build();
            var serialItem3 = new SerialisedItemBuilder(this.Session).WithSerialNumber("3").Build();

            serialPart.AddSerialisedItem(serialItem1);
            serialPart.AddSerialisedItem(serialItem2);
            serialPart.AddSerialisedItem(serialItem3);

            var good = CreateGood("10101", vatRate21, "good1", unitsOfMeasure.Piece, category, serialPart);

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

            CreateInventoryTransaction(1, unknown, serialPart, serialItem1);
            CreateInventoryTransaction(1, unknown, serialPart, serialItem2);
            CreateInventoryTransaction(1, unknown, serialPart, serialItem3);

            this.Session.Derive(true);

            // Assert
            Assert.Equal(3, serialPart.QuantityOnHand);
        }
        public void GivenSerializedInventoryItems_WhenVarianceContainsInvalidQuantity_ThenDerivationExceptionRaised()
        {
            // Arrange
            var kinds          = new InventoryItemKinds(this.Session);
            var unitsOfMeasure = new UnitsOfMeasure(this.Session);
            var unknown        = new InventoryTransactionReasons(this.Session).Unknown;

            var vatRegime    = new VatRegimes(this.Session).BelgiumStandard;
            var category     = new ProductCategoryBuilder(this.Session).WithName("category").Build();
            var finishedGood = this.CreatePart("FG1", kinds.Serialised);
            var good         = this.CreateGood("10101", vatRegime, "good1", unitsOfMeasure.Piece, category, finishedGood);
            var serialItem   = new SerialisedItemBuilder(this.Session).WithSerialNumber("1").Build();
            var variance     = this.CreateInventoryTransaction(10, unknown, finishedGood, serialItem);

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

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

            // Re-Arrange
            variance.Quantity = -10;

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

            // Assert
            Assert.True(derivation.HasErrors);
            Assert.Contains(M.InventoryItemTransaction.Quantity, derivation.Errors.SelectMany(e => e.RoleTypes));
        }
        public void GivenInventoryItem_WhenPositiveVariance_ThenQuantityOnHandIsRaised()
        {
            var nonSerialized = new InventoryItemKinds(this.Session).NonSerialised;
            var unknown       = new InventoryTransactionReasons(this.Session).Unknown;
            var vatRate21     = new VatRateBuilder(this.Session).WithRate(21).Build();
            var piece         = new UnitsOfMeasure(this.Session).Piece;
            var category      = this.Session.Extent <ProductCategory>().First;

            var finishedGood = this.CreatePart("FG1", nonSerialized);

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

            var inventoryItem = (NonSerialisedInventoryItem)finishedGood.InventoryItemsWherePart.First();

            Assert.Equal(0, finishedGood.QuantityOnHand);
            Assert.Equal(0, inventoryItem.QuantityOnHand);

            var transaction = this.CreateInventoryTransaction(10, unknown, finishedGood);

            this.Session.Derive(true);

            Assert.Equal(10, finishedGood.QuantityOnHand);
            Assert.Equal(10, inventoryItem.QuantityOnHand);
        }
        public void GivenInventoryItem_WhenQuantityOnHandIsDecreased_ThenSalesOrderItemsWithQuantityRequestsShippingAreUpdated()
        {
            // Arrange
            var inventoryItemKinds = new InventoryItemKinds(this.Session);
            var unitsOfMeasure     = new UnitsOfMeasure(this.Session);
            var varianceReasons    = new InventoryTransactionReasons(this.Session);
            var contactMechanisms  = new ContactMechanismPurposes(this.Session);

            var vatRate21    = new VatRateBuilder(this.Session).WithRate(21).Build();
            var category     = new ProductCategoryBuilder(this.Session).WithName("category").Build();
            var finishedGood = CreatePart("1", inventoryItemKinds.NonSerialised);
            var good         = CreateGood("10101", vatRate21, "good1", unitsOfMeasure.Piece, category, finishedGood);

            CreateInventoryTransaction(5, varianceReasons.Unknown, finishedGood);

            this.Session.Derive(true);

            var mechelen             = new CityBuilder(this.Session).WithName("Mechelen").Build();
            var mechelenAddress      = new PostalAddressBuilder(this.Session).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build();
            var shipToMechelen       = CreateShipTo(mechelenAddress, contactMechanisms.ShippingAddress, true);
            var customer             = new PersonBuilder(this.Session).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build();
            var internalOrganisation = this.InternalOrganisation;

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

            this.Session.Derive(true);

            var order     = CreateSalesOrder(customer, customer, DateTime.UtcNow, false);
            var salesItem = CreateSalesOrderItem("item1", good, 10, 15);

            // Act
            order.AddSalesOrderItem(salesItem);
            this.Session.Derive(true);

            order.Confirm();
            this.Session.Derive(true);

            // Assert
            Assert.Equal(5, salesItem.QuantityRequestsShipping);
            Assert.Equal(0, salesItem.QuantityPendingShipment);
            Assert.Equal(10, salesItem.QuantityReserved);
            Assert.Equal(5, salesItem.QuantityShortFalled);

            // Rearrange
            CreateInventoryTransaction(-2, varianceReasons.Unknown, finishedGood);

            // Act
            this.Session.Derive();

            // Assert
            Assert.Equal(3, salesItem.QuantityRequestsShipping);
            Assert.Equal(0, salesItem.QuantityPendingShipment);
            Assert.Equal(10, salesItem.QuantityReserved);
            Assert.Equal(7, salesItem.QuantityShortFalled);
        }
Example #5
0
        public void GivenInventoryItemForPart_WhenDerived_ThenUnitOfMeasureIsPartUnitOfMeasure()
        {
            var uom  = new UnitsOfMeasure(this.Session).Centimeter;
            var part = new NonUnifiedPartBuilder(this.Session)
                       .WithProductIdentification(new PartNumberBuilder(this.Session)
                                                  .WithIdentification("1")
                                                  .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build())
                       .WithInventoryItemKind(new InventoryItemKinds(this.Session).NonSerialised)
                       .WithUnitOfMeasure(uom)
                       .Build();

            this.Session.Derive();

            Assert.Equal(part.UnitOfMeasure, part.InventoryItemsWherePart.Single().UnitOfMeasure);
        }
Example #6
0
        public void GivenSerializedItemInMultipleFacilities_WhenDeriving_ThenMultipleQuantityOnHandTracked()
        {
            // Arrange
            var warehouseType = new FacilityTypes(this.Session).Warehouse;
            var warehouse1    = CreateFacility("WH1", warehouseType, this.InternalOrganisation);
            var warehouse2    = CreateFacility("WH2", warehouseType, this.InternalOrganisation);

            var serialized = new InventoryItemKinds(this.Session).Serialised;
            var piece      = new UnitsOfMeasure(this.Session).Piece;
            var unknown    = new InventoryTransactionReasons(this.Session).Unknown;

            var vatRate21    = new VatRateBuilder(this.Session).WithRate(21).Build();
            var category     = new ProductCategoryBuilder(this.Session).WithName("category").Build();
            var finishedGood = CreatePart("FG1", serialized);
            var serialItem1  = new SerialisedItemBuilder(this.Session).WithSerialNumber("1").Build();
            var serialItem2  = new SerialisedItemBuilder(this.Session).WithSerialNumber("2").Build();

            finishedGood.AddSerialisedItem(serialItem1);
            finishedGood.AddSerialisedItem(serialItem2);

            var good = CreateGood("10101", vatRate21, "good1", piece, category, finishedGood);

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

            CreateInventoryTransaction(1, unknown, finishedGood, serialItem1, warehouse1);
            CreateInventoryTransaction(1, unknown, finishedGood, serialItem2, warehouse2);

            this.Session.Derive(true);

            // Assert
            var item1 = (SerialisedInventoryItem) new InventoryItems(this.Session).Extent().First(i => i.Facility.Equals(warehouse1));

            Assert.Equal(1, item1.QuantityOnHand);

            var item2 = (SerialisedInventoryItem) new InventoryItems(this.Session).Extent().First(i => i.Facility.Equals(warehouse2));

            Assert.Equal(1, item2.QuantityOnHand);

            Assert.Equal(2, finishedGood.QuantityOnHand);
        }
        public void GivenInventoryItemForGood_WhenDerived_ThenUnitOfMeasureIsGoodUnitOfMeasure()
        {
            var uom = new UnitsOfMeasure(this.DatabaseSession).Centimeter;

            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();
            var category = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("category").Build();
            var good = new GoodBuilder(this.DatabaseSession)
             .WithSku("10101")
             .WithVatRate(vatRate21)
             .WithName("good1")
             .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
             .WithUnitOfMeasure(uom)
             .WithPrimaryProductCategory(category)
             .Build();

            var item = new NonSerializedInventoryItemBuilder(this.DatabaseSession)
                .WithGood(good)
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(good.UnitOfMeasure, item.UnitOfMeasure);
        }
        public void GivenInventoryItemForPart_WhenDerived_ThenUnitOfMeasureIsPartUnitOfMeasure()
        {
            var uom = new UnitsOfMeasure(this.DatabaseSession).Centimeter;
            var part = new FinishedGoodBuilder(this.DatabaseSession).WithName("part").WithManufacturerId("10101").WithUnitOfMeasure(uom).Build();
            var item = new NonSerializedInventoryItemBuilder(this.DatabaseSession)
                .WithPart(part)
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(part.UnitOfMeasure, item.UnitOfMeasure);
        }
Example #9
0
        public void GivenSupplierOffering_WhenCalculatingUnitSellingPrice_ThenConsiderHighestHistoricalPurchaseRate()
        {
            var settings = this.Session.GetSingleton().Settings;

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

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

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

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

            this.Session.Derive();

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

            this.Session.Derive();

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

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

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

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

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

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

            this.Session.Derive();

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

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

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

            this.Session.Derive();

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

            Assert.Equal(100, workEffortInventoryAssignement.UnitSellingPrice);
        }
Example #10
0
        public void GivenInventoryItem_WhenQuantityOnHandIsRaised_ThenSalesOrderItemsWithQuantityShortFalledAreUpdated()
        {
            // Arrange
            var inventoryItemKinds = new InventoryItemKinds(this.Session);
            var unitsOfMeasure     = new UnitsOfMeasure(this.Session);
            var varianceReasons    = new InventoryTransactionReasons(this.Session);
            var contactMechanisms  = new ContactMechanismPurposes(this.Session);

            var store = this.Session.Extent <Store>().First;

            store.IsImmediatelyPicked = false;

            var vatRate21    = new VatRateBuilder(this.Session).WithRate(21).Build();
            var category     = new ProductCategoryBuilder(this.Session).WithName("category").Build();
            var finishedGood = this.CreatePart("1", inventoryItemKinds.NonSerialised);
            var good         = this.CreateGood("10101", vatRate21, "good1", unitsOfMeasure.Piece, category, finishedGood);

            this.Session.Derive();

            this.CreateInventoryTransaction(5, varianceReasons.Unknown, finishedGood);

            this.Session.Derive();

            var mechelen        = new CityBuilder(this.Session).WithName("Mechelen").Build();
            var mechelenAddress = new PostalAddressBuilder(this.Session).WithPostalAddressBoundary(mechelen).WithAddress1("Haverwerf 15").Build();
            var shipToMechelen  = this.CreateShipTo(mechelenAddress, contactMechanisms.ShippingAddress, true);
            var customer        = new PersonBuilder(this.Session).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build();

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

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

            var order1     = this.CreateSalesOrder(customer, customer, this.Session.Now());
            var salesItem1 = this.CreateSalesOrderItem("item1", good, 10, 15);
            var salesItem2 = this.CreateSalesOrderItem("item2", good, 20, 15);

            order1.AddSalesOrderItem(salesItem1);
            order1.AddSalesOrderItem(salesItem2);

            var order2     = this.CreateSalesOrder(customer, customer, this.Session.Now().AddDays(1));
            var salesItem3 = this.CreateSalesOrderItem("item3", good, 10, 15);
            var salesItem4 = this.CreateSalesOrderItem("item4", good, 20, 15);

            order2.AddSalesOrderItem(salesItem3);
            order2.AddSalesOrderItem(salesItem4);

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

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

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

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

            Assert.Equal(0, salesItem1.ReservedFromNonSerialisedInventoryItem.AvailableToPromise);
            Assert.Equal(5, salesItem1.ReservedFromNonSerialisedInventoryItem.QuantityOnHand);

            order2.SetReadyForPosting();

            this.Session.Derive(true);

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

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

            // Assert
            Assert.Equal(0, salesItem1.QuantityRequestsShipping);
            Assert.Equal(5, salesItem1.QuantityPendingShipment);
            Assert.Equal(10, salesItem1.QuantityReserved);
            Assert.Equal(5, salesItem1.QuantityShortFalled);

            Assert.Equal(0, salesItem2.QuantityRequestsShipping);
            Assert.Equal(0, salesItem2.QuantityPendingShipment);
            Assert.Equal(20, salesItem2.QuantityReserved);
            Assert.Equal(20, salesItem2.QuantityShortFalled);

            Assert.Equal(0, salesItem3.QuantityRequestsShipping);
            Assert.Equal(0, salesItem3.QuantityPendingShipment);
            Assert.Equal(10, salesItem3.QuantityReserved);
            Assert.Equal(10, salesItem3.QuantityShortFalled);

            Assert.Equal(0, salesItem4.QuantityRequestsShipping);
            Assert.Equal(0, salesItem4.QuantityPendingShipment);
            Assert.Equal(20, salesItem4.QuantityReserved);
            Assert.Equal(20, salesItem4.QuantityShortFalled);

            Assert.Equal(0, salesItem1.ReservedFromNonSerialisedInventoryItem.AvailableToPromise);
            Assert.Equal(5, salesItem1.ReservedFromNonSerialisedInventoryItem.QuantityOnHand);

            // Re-arrange
            this.CreateInventoryTransaction(15, varianceReasons.Unknown, finishedGood);

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

            // Assert
            // Orderitems are sorted as follows: item1, item2, item3, item4
            Assert.Equal(0, salesItem1.QuantityRequestsShipping);
            Assert.Equal(10, salesItem1.QuantityPendingShipment);
            Assert.Equal(10, salesItem1.QuantityReserved);
            Assert.Equal(0, salesItem1.QuantityShortFalled);

            Assert.Equal(0, salesItem2.QuantityRequestsShipping);
            Assert.Equal(10, salesItem2.QuantityPendingShipment);
            Assert.Equal(20, salesItem2.QuantityReserved);
            Assert.Equal(10, salesItem2.QuantityShortFalled);

            Assert.Equal(0, salesItem3.QuantityRequestsShipping);
            Assert.Equal(0, salesItem3.QuantityPendingShipment);
            Assert.Equal(10, salesItem3.QuantityReserved);
            Assert.Equal(10, salesItem3.QuantityShortFalled);

            Assert.Equal(0, salesItem4.QuantityRequestsShipping);
            Assert.Equal(0, salesItem4.QuantityPendingShipment);
            Assert.Equal(20, salesItem4.QuantityReserved);
            Assert.Equal(20, salesItem4.QuantityShortFalled);

            Assert.Equal(0, salesItem1.ReservedFromNonSerialisedInventoryItem.AvailableToPromise);
            Assert.Equal(20, salesItem1.ReservedFromNonSerialisedInventoryItem.QuantityOnHand);

            // Re-arrange
            this.CreateInventoryTransaction(85, varianceReasons.Unknown, finishedGood);

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

            // Assert
            // Orderitems are sorted as follows: item2, item1, item4, item 3
            Assert.Equal(0, salesItem1.QuantityRequestsShipping);
            Assert.Equal(10, salesItem1.QuantityPendingShipment);
            Assert.Equal(10, salesItem1.QuantityReserved);
            Assert.Equal(0, salesItem1.QuantityShortFalled);

            Assert.Equal(0, salesItem2.QuantityRequestsShipping);
            Assert.Equal(20, salesItem2.QuantityPendingShipment);
            Assert.Equal(20, salesItem2.QuantityReserved);
            Assert.Equal(0, salesItem2.QuantityShortFalled);

            Assert.Equal(0, salesItem3.QuantityRequestsShipping);
            Assert.Equal(10, salesItem3.QuantityPendingShipment);
            Assert.Equal(10, salesItem3.QuantityReserved);
            Assert.Equal(0, salesItem3.QuantityShortFalled);

            Assert.Equal(0, salesItem4.QuantityRequestsShipping);
            Assert.Equal(20, salesItem4.QuantityPendingShipment);
            Assert.Equal(20, salesItem4.QuantityReserved);
            Assert.Equal(0, salesItem4.QuantityShortFalled);

            Assert.Equal(45, salesItem1.ReservedFromNonSerialisedInventoryItem.AvailableToPromise);
            Assert.Equal(105, salesItem1.ReservedFromNonSerialisedInventoryItem.QuantityOnHand);
        }
Example #11
0
        public void GivenPurchasePriceInDifferenUnitOfMeasureComparedToProduct_WhenDerivingMarkupAndProfitMargin_ThenUnitOfMeasureConversionIsPerformed()
        {
            var pair = new UnitsOfMeasure(this.DatabaseSession).Pair;
            var piece = new UnitsOfMeasure(this.DatabaseSession).Piece;

            var fromPairToPiece = new UnitOfMeasureConversionBuilder(this.DatabaseSession)
                .WithToUnitOfMeasure(piece)
                .WithConversionFactor(2).Build();

            var fromPieceToPair = new UnitOfMeasureConversionBuilder(this.DatabaseSession)
                .WithToUnitOfMeasure(pair)
                .WithConversionFactor(0.5M).Build();

            pair.AddUnitOfMeasureConversion(fromPairToPiece);
            pair.AddUnitOfMeasureConversion(fromPieceToPair);

            this.goodPurchasePrice.UnitOfMeasure = pair;
            this.good.UnitOfMeasure = piece;

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

            this.InstantiateObjects(this.DatabaseSession);

            const decimal quantity = 3;
            var item1 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(this.good).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).WithQuantity(quantity).Build();
            this.invoice.AddSalesInvoiceItem(item1);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(this.currentGood1BasePrice.Price, item1.UnitBasePrice);
            Assert.AreEqual(0, item1.UnitDiscount);
            Assert.AreEqual(0, item1.UnitSurcharge);
            Assert.AreEqual(this.currentGood1BasePrice.Price, item1.CalculatedUnitPrice);
            Assert.AreEqual(decimal.Round((item1.CalculatedUnitPrice * this.vatRate21.Rate) / 100, 2), item1.UnitVat);
            Assert.AreEqual(this.goodPurchasePrice.Price * 0.5M, item1.UnitPurchasePrice);

            Assert.AreEqual(this.currentGood1BasePrice.Price * quantity, item1.TotalBasePrice);
            Assert.AreEqual(0, item1.TotalDiscount);
            Assert.AreEqual(0, item1.TotalSurcharge);
            Assert.AreEqual(this.currentGood1BasePrice.Price * quantity, item1.TotalExVat);
            Assert.AreEqual(decimal.Round((item1.CalculatedUnitPrice * this.vatRate21.Rate) / 100, 2) * quantity, item1.TotalVat);

            var purchasePrice = this.goodPurchasePrice.Price * 0.5M;

            Assert.AreEqual(decimal.Round(((item1.UnitBasePrice / purchasePrice) - 1) * 100, 2), item1.InitialMarkupPercentage);
            Assert.AreEqual(decimal.Round(((item1.CalculatedUnitPrice / purchasePrice) - 1) * 100, 2), item1.MaintainedMarkupPercentage);
            Assert.AreEqual(decimal.Round(((item1.UnitBasePrice - purchasePrice) / item1.UnitBasePrice) * 100, 2), item1.InitialProfitMargin);
            Assert.AreEqual(decimal.Round(((item1.CalculatedUnitPrice - purchasePrice) / item1.CalculatedUnitPrice) * 100, 2), item1.MaintainedProfitMargin);

            Assert.AreEqual(this.currentGood1BasePrice.Price * quantity, this.invoice.TotalBasePrice);
            Assert.AreEqual(0, this.invoice.TotalDiscount);
            Assert.AreEqual(0, this.invoice.TotalSurcharge);
            Assert.AreEqual(this.currentGood1BasePrice.Price * quantity, this.invoice.TotalExVat);
            Assert.AreEqual(decimal.Round((item1.CalculatedUnitPrice * this.vatRate21.Rate) / 100, 2) * quantity, this.invoice.TotalVat);
            Assert.AreEqual(item1.UnitPurchasePrice, this.invoice.TotalPurchasePrice);
        }