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); }
public void GivenSupplierOffering_WhenDeriving_ThenRequiredRelationsMustExist() { var supplier = new OrganisationBuilder(this.Session).WithName("organisation").Build(); var part = new NonUnifiedPartBuilder(this.Session) .WithProductIdentification(new PartNumberBuilder(this.Session) .WithIdentification("P1") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build()) .WithInventoryItemKind(new InventoryItemKinds(this.Session).NonSerialised) .Build(); this.Session.Commit(); var builder = new SupplierOfferingBuilder(this.Session); builder.Build(); Assert.True(this.Session.Derive(false).HasErrors); this.Session.Rollback(); builder.WithPrice(1); builder.Build(); Assert.True(this.Session.Derive(false).HasErrors); this.Session.Rollback(); builder.WithSupplier(supplier); builder.Build(); Assert.True(this.Session.Derive(false).HasErrors); this.Session.Rollback(); builder.WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Pack); builder.Build(); Assert.True(this.Session.Derive(false).HasErrors); this.Session.Rollback(); builder.WithCurrency(new Currencies(this.Session).FindBy(M.Currency.IsoCode, "EUR")); builder.Build(); Assert.False(this.Session.Derive(false).HasErrors); builder.WithPart(part); builder.Build(); Assert.False(this.Session.Derive(false).HasErrors); }
public override void Init() { base.Init(); var euro = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR"); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); ContactMechanism takenViaContactMechanism = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var supplierContactMechanism = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(takenViaContactMechanism) .WithUseAsDefault(true) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).BillingAddress) .Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); this.supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); this.supplier.AddPartyContactMechanism(supplierContactMechanism); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); this.finishedGood = new FinishedGoodBuilder(this.DatabaseSession) .WithManufacturerId("10101") .WithName("finished good") .Build(); var supplierOffering = new SupplierOfferingBuilder(this.DatabaseSession) .WithPart(this.finishedGood) .WithSupplier(this.supplier) .WithFromDate(DateTime.UtcNow.AddYears(-1)) .Build(); var previousPurchasePrice = 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(); this.currentPurchasePrice = new ProductPurchasePriceBuilder(this.DatabaseSession) .WithCurrency(euro) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithFromDate(DateTime.UtcNow) .WithThroughDate(DateTime.UtcNow.AddYears(1).AddDays(-1)) .WithPrice(10) .Build(); var futurePurchasePrice = new ProductPurchasePriceBuilder(this.DatabaseSession) .WithCurrency(euro) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithFromDate(DateTime.UtcNow.AddYears(1)) .WithPrice(8) .Build(); supplierOffering.AddProductPurchasePrice(previousPurchasePrice); supplierOffering.AddProductPurchasePrice(this.currentPurchasePrice); supplierOffering.AddProductPurchasePrice(futurePurchasePrice); this.order = new PurchaseOrderBuilder(this.DatabaseSession) .WithTakenViaSupplier(this.supplier) .WithBillToContactMechanism(takenViaContactMechanism) .WithDeliveryDate(DateTime.UtcNow) .WithVatRegime(new VatRegimes(this.DatabaseSession).Exempt) .Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); }
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); }
public void BaseApprove(PurchaseInvoiceApprove method) { this.PurchaseInvoiceState = new PurchaseInvoiceStates(this.Strategy.Session).NotPaid; var openTasks = this.TasksWhereWorkItem.Where(v => !v.ExistDateClosed).ToArray(); if (openTasks.OfType <PurchaseInvoiceApproval>().Any()) { openTasks.First().DateClosed = this.Session().Now(); } foreach (PurchaseInvoiceItem purchaseInvoiceItem in this.ValidInvoiceItems) { if (purchaseInvoiceItem.ExistPart) { var previousOffering = purchaseInvoiceItem.Part.SupplierOfferingsWherePart.FirstOrDefault(v => v.Supplier.Equals(this.BilledFrom) && v.FromDate <= this.Session().Now() && (!v.ExistThroughDate || v.ThroughDate >= this.Session().Now())); if (previousOffering != null) { if (purchaseInvoiceItem.UnitBasePrice != previousOffering.Price) { previousOffering.ThroughDate = this.Session().Now(); var newOffering = new SupplierOfferingBuilder(this.Session()) .WithSupplier(this.BilledFrom) .WithPart(purchaseInvoiceItem.Part) .WithPrice(purchaseInvoiceItem.UnitBasePrice) .WithFromDate(this.Session().Now()) .WithComment(previousOffering.Comment) .WithMinimalOrderQuantity(previousOffering.MinimalOrderQuantity) .WithPreference(previousOffering.Preference) .WithQuantityIncrements(previousOffering.QuantityIncrements) .WithRating(previousOffering.Rating) .WithStandardLeadTime(previousOffering.StandardLeadTime) .WithSupplierProductId(previousOffering.SupplierProductId) .WithSupplierProductName(previousOffering.SupplierProductName) .WithUnitOfMeasure(previousOffering.UnitOfMeasure) .Build(); newOffering.LocalisedComments = previousOffering.LocalisedComments; } } else { new SupplierOfferingBuilder(this.Session()) .WithSupplier(this.BilledFrom) .WithPart(purchaseInvoiceItem.Part) .WithUnitOfMeasure(purchaseInvoiceItem.Part?.UnitOfMeasure) .WithPrice(purchaseInvoiceItem.UnitBasePrice) .WithFromDate(this.Session().Now()) .Build(); } foreach (OrderItemBilling orderItemBilling in purchaseInvoiceItem.OrderItemBillingsWhereInvoiceItem) { foreach (ShipmentReceipt receipt in orderItemBilling.OrderItem.ShipmentReceiptsWhereOrderItem) { receipt.ShipmentItem.InventoryItemTransactionWhereShipmentItem.Cost = purchaseInvoiceItem.UnitBasePrice; } } } } }
public void GivenSupplierOffering_WhenDeriving_ThenRequiredRelationsMustExist() { var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("organisation").Build(); var part = new FinishedGoodBuilder(this.DatabaseSession).WithName("finishedGood").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 purchasePrice = new ProductPurchasePriceBuilder(this.DatabaseSession) .WithFromDate(DateTime.UtcNow) .WithCurrency(new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR")) .WithPrice(1) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); this.DatabaseSession.Commit(); var builder = new SupplierOfferingBuilder(this.DatabaseSession); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithProduct(good); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithProductPurchasePrice(purchasePrice); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithSupplier(supplier); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithFromDate(DateTime.UtcNow); builder.Build(); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); builder.WithPart(part); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); var supplierOffering = builder.Build(); supplierOffering.RemoveProduct(); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); }