public void Always_DefaultIdentifier() { var category = new ProductCategoryBuilder().Build(); Assert.That(category.Id, Is.EqualTo(default(int))); Assert.That(category.SupplierId, Is.Null); }
public void GivenInventoryItem_WhenDeriving_ThenProductCategoriesAreDerived() { var level1 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("level1").Build(); var level2 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("level2").WithParent(level1).Build(); var level3 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("level3").WithParent(level2).Build(); var category = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("category").Build(); var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var good = new GoodBuilder(this.DatabaseSession) .WithName("Good") .WithSku("10101") .WithVatRate(vatRate21) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithProductCategory(level3) .WithProductCategory(category) .Build(); var goodInventory = new NonSerializedInventoryItemBuilder(this.DatabaseSession) .WithGood(good) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(4, goodInventory.DerivedProductCategories.Count); Assert.Contains(level3, goodInventory.DerivedProductCategories); Assert.Contains(level2, goodInventory.DerivedProductCategories); Assert.Contains(level1, goodInventory.DerivedProductCategories); Assert.Contains(category, goodInventory.DerivedProductCategories); }
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 NullProdCode_ThrowsArgumentNullException() { var category = new ProductCategoryBuilder().Build(); Assert.Throws <ArgumentNullException>(() => new Product(null, new ProductName("name2"), category, 999)); }
public void Always_DefaultIdentifier() { var category = new ProductCategoryBuilder().Build(); var product = new Product(new ProductCode("code1"), new ProductName("name2"), category, 999); Assert.That(product.Id, Is.EqualTo(default(int))); Assert.That(product.SupplierId, Is.Null); }
public void GivenGood_WhenProductCategoryParentsAreRemoved_ThenProductCategoriesExpandedAreRecalculated() { var productCategory1 = new ProductCategoryBuilder(this.Session) .WithName("1") .Build(); var productCategory2 = new ProductCategoryBuilder(this.Session) .WithName("2") .Build(); var productCategory11 = new ProductCategoryBuilder(this.Session) .WithName("1.1") .WithParent(productCategory1) .WithParent(productCategory2) .Build(); var productCategory12 = new ProductCategoryBuilder(this.Session) .WithName("1.2") .WithParent(productCategory1) .WithParent(productCategory2) .Build(); var productCategory111 = new ProductCategoryBuilder(this.Session) .WithName("1.1.1") .WithParent(productCategory11) .Build(); var vatRate21 = new VatRateBuilder(this.Session).WithRate(21).Build(); var good = new NonUnifiedGoodBuilder(this.Session) .WithName("good") .WithProductIdentification(new ProductNumberBuilder(this.Session) .WithIdentification("1") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Good).Build()) .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Piece) .WithVatRate(vatRate21) .WithPart(new NonUnifiedPartBuilder(this.Session) .WithProductIdentification(new PartNumberBuilder(this.Session) .WithIdentification("1") .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Part).Build()) .WithInventoryItemKind(new InventoryItemKinds(this.Session).NonSerialised).Build()) .Build(); productCategory111.AddProduct(good); this.Session.Derive(); Assert.Equal(4, good.ProductCategoriesExpanded.Count); Assert.Contains(productCategory111, good.ProductCategoriesExpanded); Assert.Contains(productCategory11, good.ProductCategoriesExpanded); Assert.Contains(productCategory1, good.ProductCategoriesExpanded); Assert.Contains(productCategory2, good.ProductCategoriesExpanded); productCategory11.RemoveParent(productCategory2); this.Session.Derive(); Assert.Equal(3, good.ProductCategoriesExpanded.Count); Assert.Contains(productCategory111, good.ProductCategoriesExpanded); Assert.Contains(productCategory11, good.ProductCategoriesExpanded); Assert.Contains(productCategory1, good.ProductCategoriesExpanded); }
public void GivenParentProductCategory_WhenPackageIsDefined_ThenValidationHasErrors() { var package = new PackageBuilder(this.DatabaseSession).WithName("package").Build(); var parent = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("parent").WithPackage(package).Build(); var child = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("child").WithParent(parent).Build(); Assert.IsTrue(new Derivation(this.DatabaseSession).Derive().HasErrors); }
public void Always_AssignsValues() { var category = new ProductCategoryBuilder().Build(); var product = new Product(new ProductCode("code1"), new ProductName("name2"), category, 999); Assert.That(product.ProductCode.Value, Is.EqualTo("code1")); Assert.That(product.Name.Value, Is.EqualTo("name2")); Assert.That(product.Category, Is.SameAs(category)); Assert.That(product.Price, Is.EqualTo(999)); }
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); }
public void NullName_ThrowsArgumentNullException() { try { var category = new ProductCategoryBuilder().Build(); var product = new Product(new ProductCode("code1"), null, category, 999); Assert.Fail("Expected exception to be thrown"); } catch (Exception ex) { Assert.That(ex, Is.InstanceOf <ArgumentNullException>()); Assert.That(ex.Message.ToLower(), Contains.Substring("name")); } }
public void GivenDeliverableCoredServiceWithPrimaryProductCategoryWithoutProductCategory_WhenDeriving_ThenFirstProductCategoryIsCopiedFromPrimaryCategory() { var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var productCategory = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("category").Build(); var deliverableBasedService = new DeliverableBasedServiceBuilder(this.DatabaseSession) .WithName("DeliverableCoredService") .WithPrimaryProductCategory(productCategory) .WithVatRate(vatRate21) .Build(); this.DatabaseSession.Derive(true); Assert.Contains(productCategory, deliverableBasedService.ProductCategories); }
protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); foreach (var property in builder.Model.GetEntityTypes().SelectMany(t => t.GetProperties()).Where(p => p.ClrType == typeof(decimal))) { property.Relational().ColumnType = "decimal(18, 2)"; } var brandBuilder = new BrandBuilder(builder.Entity <Brand>()); var colorBuilder = new ColorBuilder(builder.Entity <Color>()); var fileBuilder = new FileBuilder(builder.Entity <File>()); var languageBuilder = new LanguageBuilder(builder.Entity <Language>()); var pageBuilder = new PageBuilder(builder.Entity <Page>()); var postBuilder = new PostBuilder(builder.Entity <Post>()); var postCategoryBuilder = new PostCategoryBuilder(builder.Entity <PostCategory>()); var postPostCategoryBuilder = new PostPostCategoryBuilder(builder.Entity <PostPostCategory>()); var productBuilder = new ProductBuilder(builder.Entity <Product>()); var productCategoryBuilder = new ProductCategoryBuilder(builder.Entity <ProductCategory>()); var productColorBuilder = new ProductColorBuilder(builder.Entity <ProductColor>()); var productPhotoBuilder = new ProductPhotoBuilder(builder.Entity <ProductPhoto>()); var reviewBuilder = new ReviewBuilder(builder.Entity <Review>()); var slideBuilder = new SlideBuilder(builder.Entity <Slide>()); var sliderBuilder = new SliderBuilder(builder.Entity <Slider>()); var advertisementBuilder = new AdvertisementBuilder(builder.Entity <Advertisement>()); var storeBuilder = new StoreBuilder(builder.Entity <Store>()); var storeBrandBuilder = new StoreBrandBuilder(builder.Entity <StoreBrand>()); var wishlistBuilder = new WishlistBuilder(builder.Entity <Wishlist>()); var orderBuilder = new OrderBuilder(builder.Entity <Order>()); var orderItemBuilder = new OrderItemBuilder(builder.Entity <OrderItem>()); var addressBuilder = new AddressBuilder(builder.Entity <Address>()); var cityBuilder = new CityBuilder(builder.Entity <City>()); var countryBuilder = new CountryBuilder(builder.Entity <Country>()); var couponBuilder = new CouponBuilder(builder.Entity <Coupon>()); var districtBuilder = new DistrictBuilder(builder.Entity <District>()); var productQuestionBuilder = new ProductQuestionBuilder(builder.Entity <ProductQuestion>()); var questionCategoryBuilder = new QuestionCategoryBuilder(builder.Entity <QuestionCategory>()); var shipperBuilder = new ShipperBuilder(builder.Entity <Shipper>()); var cartBuilder = new CartBuilder(builder.Entity <Cart>()); var cartItemBuilder = new CartItemBuilder(builder.Entity <CartItem>()); // data seeding ApplicationDbContextSeed.Seed(builder); }
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 GivenProductCategory_WhenDeriving_ThenAncestorsAreSet() { var productCategory1 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1").Build(); var productCategory2 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("2").Build(); var productCategory11 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1.1").WithParent(productCategory1).WithParent(productCategory2).Build(); var productCategory12 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1.2").WithParent(productCategory1).WithParent(productCategory2).Build(); var productCategory111 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1.1.1").WithParent(productCategory11).Build(); var productCategory121 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1.2.1").WithParent(productCategory12).Build(); var productCategory122 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1.2.2").WithParent(productCategory12).Build(); this.DatabaseSession.Derive(true); Assert.IsFalse(productCategory1.ExistAncestors); Assert.IsFalse(productCategory2.ExistAncestors); Assert.AreEqual(2, productCategory11.Ancestors.Count); Assert.Contains(productCategory1, productCategory11.Ancestors); Assert.Contains(productCategory2, productCategory11.Ancestors); Assert.AreEqual(2, productCategory12.Ancestors.Count); Assert.Contains(productCategory1, productCategory12.Ancestors); Assert.Contains(productCategory2, productCategory12.Ancestors); Assert.AreEqual(3, productCategory111.Ancestors.Count); Assert.Contains(productCategory11, productCategory111.Ancestors); Assert.Contains(productCategory1, productCategory111.Ancestors); Assert.Contains(productCategory2, productCategory111.Ancestors); Assert.AreEqual(3, productCategory121.Ancestors.Count); Assert.Contains(productCategory12, productCategory121.Ancestors); Assert.Contains(productCategory1, productCategory121.Ancestors); Assert.Contains(productCategory2, productCategory121.Ancestors); Assert.AreEqual(3, productCategory122.Ancestors.Count); Assert.Contains(productCategory12, productCategory122.Ancestors); Assert.Contains(productCategory1, productCategory122.Ancestors); Assert.Contains(productCategory2, productCategory122.Ancestors); }
public void GivenInventoryItemForGood_WhenDerived_ThenSkuIsFromGood() { 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(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithPrimaryProductCategory(category) .Build(); var item = new NonSerializedInventoryItemBuilder(this.DatabaseSession) .WithGood(good) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(good.Sku, item.Sku); }
public void GivenInvoiceItemWithDiscountAmountForProductCatergory_WhenDeriving_ThenUseDiscountComponentsForProductCatergory() { const decimal quantity = 3; const decimal amount = 1; var category = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("gizmo").Build(); new DiscountComponentBuilder(this.DatabaseSession) .WithSpecifiedFor(this.internalOrganisation) .WithDescription("discount good for product category") .WithProductCategory(category) .WithProduct(this.good) .WithPrice(amount) .WithFromDate(DateTime.UtcNow.AddMinutes(-1)) .WithThroughDate(DateTime.UtcNow.AddYears(1).AddDays(-1)) .Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); this.InstantiateObjects(this.DatabaseSession); this.good.AddProductCategory(category); this.DatabaseSession.Derive(true); 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(amount, item1.UnitDiscount); Assert.AreEqual(0, item1.UnitSurcharge); Assert.AreEqual(this.currentGood1BasePrice.Price - amount, item1.CalculatedUnitPrice); Assert.AreEqual(this.goodPurchasePrice.Price, item1.UnitPurchasePrice); Assert.AreEqual(decimal.Round(((item1.UnitBasePrice / this.goodPurchasePrice.Price) - 1) * 100, 2), item1.InitialMarkupPercentage); Assert.AreEqual(decimal.Round(((item1.CalculatedUnitPrice / this.goodPurchasePrice.Price) - 1) * 100, 2), item1.MaintainedMarkupPercentage); Assert.AreEqual(decimal.Round(((item1.UnitBasePrice - this.goodPurchasePrice.Price) / item1.UnitBasePrice) * 100, 2), item1.InitialProfitMargin); Assert.AreEqual(decimal.Round(((item1.CalculatedUnitPrice - this.goodPurchasePrice.Price) / item1.CalculatedUnitPrice) * 100, 2), item1.MaintainedProfitMargin); }
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(allors, "*****@*****.**", "second", "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 Serialized") .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]) .WithManufacturedBy(manufacturer) .WithInventoryItemKind(new InventoryItemKinds(this.Session).NonSerialised) .Build(); var good1 = new NonUnifiedGoodBuilder(this.Session) .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).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) .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").Build(); finishedGood2.AddSerialisedItem(serialisedItem); new SerialisedInventoryItemBuilder(this.Session).WithPart(finishedGood2).WithSerialisedItem(serialisedItem).WithFacility(allors.StoresWhereInternalOrganisation.First.DefaultFacility).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) .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 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) .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 < 1; 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) .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 SupplierRelationshipBuilder(this.Session) .WithSupplier(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 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 salesInvoice = new SalesInvoiceBuilder(this.Session) .WithBilledFrom(allors) .WithInvoiceNumber("1") .WithBillToCustomer(acme) .WithBillToContactMechanism(acme.PartyContactMechanisms[0].ContactMechanism) .WithBillToEndCustomerContactMechanism(acmeBillingAddress.ContactMechanism) .WithSalesInvoiceItem(salesInvoiceItem1) .WithSalesInvoiceItem(salesInvoiceItem2) .WithSalesInvoiceItem(salesInvoiceItem3) .WithCustomerReference("a reference number") .WithDescription("Sale of 1 used Aircraft Towbar") .WithSalesInvoiceType(new SalesInvoiceTypes(this.Session).SalesInvoice) .WithVatRegime(new VatRegimes(this.Session).Assessable) .Build(); var purchaseInvoiceItem1 = new PurchaseInvoiceItemBuilder(this.Session) .WithDescription("first item") .WithProduct(good1) .WithActualUnitPrice(3000) .WithQuantity(1) .WithMessage(@"line1 line2") .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem) .Build(); var purchaseInvoiceItem2 = new PurchaseInvoiceItemBuilder(this.Session) .WithDescription("second item") .WithActualUnitPrice(2000) .WithQuantity(2) .WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem) .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) .WithInvoiceNumber("1") .WithBilledFrom(acme) .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(); } this.Session.Derive(); }
public static void Setup(IDatabase database) { CultureInfo.CurrentCulture = new CultureInfo("en-GB"); CultureInfo.CurrentUICulture = new CultureInfo("en-GB"); using (var session = database.CreateSession()) { new Setup(session, null).Apply(); var administrator = new Users(session).GetUser("administrator"); session.SetUser(administrator); var singleton = session.GetSingleton(); new UserGroups(session).Administrators.AddMember(administrator); singleton.Guest = new PersonBuilder(session).WithUserName("guest").WithLastName("guest").Build(); session.Derive(); session.Commit(); var belgium = new Countries(session).CountryByIsoCode["BE"]; var euro = belgium.Currency; var bank = new BankBuilder(session).WithCountry(belgium).WithName("ING België").WithBic("BBRUBEBB").Build(); var ownBankAccount = new OwnBankAccountBuilder(session) .WithBankAccount(new BankAccountBuilder(session).WithBank(bank) .WithCurrency(euro) .WithIban("BE68539007547034") .WithNameOnAccount("Koen") .Build()) .WithDescription("Main bank account") .Build(); var postalBoundary = new PostalBoundaryBuilder(session).WithLocality("Mechelen").WithCountry(belgium).Build(); var postalAddress = new PostalAddressBuilder(session).WithAddress1("Kleine Nieuwedijkstraat 2").WithPostalBoundary(postalBoundary).Build(); var internalOrganisation = new OrganisationBuilder(session) .WithIsInternalOrganisation(true) .WithDoAccounting(false) .WithName("internalOrganisation") .WithPreferredCurrency(new Currencies(session).CurrencyByCode["EUR"]) .WithIncomingShipmentNumberPrefix("incoming shipmentno: ") .WithPurchaseInvoiceNumberPrefix("incoming invoiceno: ") .WithPurchaseOrderNumberPrefix("purchase orderno: ") .WithDefaultCollectionMethod(ownBankAccount) .WithSubAccountCounter(new CounterBuilder(session).WithUniqueId(Guid.NewGuid()).WithValue(0).Build()) .Build(); internalOrganisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session) .WithUseAsDefault(true) .WithContactMechanism(postalAddress) .WithContactPurpose(new ContactMechanismPurposes(session).GeneralCorrespondence) .WithContactPurpose(new ContactMechanismPurposes(session).BillingAddress) .Build()); var facility = new FacilityBuilder(session) .WithFacilityType(new FacilityTypes(session).Warehouse) .WithName("facility") .WithOwner(internalOrganisation) .Build(); singleton.Settings.DefaultFacility = facility; var collectionMethod = new PaymentMethods(session).Extent().First; new StoreBuilder(session) .WithName("store") .WithBillingProcess(new BillingProcesses(session).BillingForShipmentItems) .WithInternalOrganisation(internalOrganisation) .WithOutgoingShipmentNumberPrefix("shipmentno: ") .WithSalesInvoiceNumberPrefix("invoiceno: ") .WithSalesOrderNumberPrefix("orderno: ") .WithDefaultShipmentMethod(new ShipmentMethods(session).Ground) .WithDefaultCarrier(new Carriers(session).Fedex) .WithCreditLimit(500) .WithPaymentGracePeriod(10) .WithDefaultCollectionMethod(collectionMethod) .WithIsImmediatelyPicked(false) .Build(); new ProductCategoryBuilder(session).WithName("Primary Category").Build(); var customer = new OrganisationBuilder(session).WithName("customer").WithLocale(singleton.DefaultLocale).Build(); var supplier = new OrganisationBuilder(session).WithName("supplier").WithLocale(singleton.DefaultLocale).Build(); var purchaser = new PersonBuilder(session).WithLastName("purchaser").WithUserName("purchaser").Build(); var salesrep = new PersonBuilder(session).WithLastName("salesRep").WithUserName("salesRep").Build(); var orderProcessor = new PersonBuilder(session).WithLastName("orderProcessor").WithUserName("orderProcessor").Build(); new CustomerRelationshipBuilder(session).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).WithFromDate(DateTime.UtcNow).Build(); new SupplierRelationshipBuilder(session).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).WithFromDate(DateTime.UtcNow).Build(); new EmploymentBuilder(session).WithFromDate(DateTime.UtcNow).WithEmployee(purchaser).WithEmployer(internalOrganisation).Build(); new EmploymentBuilder(session).WithFromDate(DateTime.UtcNow).WithEmployee(salesrep).WithEmployer(internalOrganisation).Build(); new EmploymentBuilder(session).WithFromDate(DateTime.UtcNow).WithEmployee(orderProcessor).WithEmployer(internalOrganisation).Build(); new SalesRepRelationshipBuilder(session).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithSalesRepresentative(salesrep).Build(); var vatRate21 = new VatRateBuilder(session).WithRate(21).Build(); var good1 = new NonUnifiedGoodBuilder(session) .WithProductIdentification(new ProductNumberBuilder(session) .WithIdentification("1") .WithProductIdentificationType(new ProductIdentificationTypes(session).Good).Build()) .WithVatRate(vatRate21) .WithName("good1") .WithUnitOfMeasure(new UnitsOfMeasure(session).Piece) .WithPart(new NonUnifiedPartBuilder(session) .WithProductIdentification(new PartNumberBuilder(session) .WithIdentification("1") .WithProductIdentificationType(new ProductIdentificationTypes(session).Part).Build()) .WithInventoryItemKind(new InventoryItemKinds(session).NonSerialised).Build()) .Build(); var good2 = new NonUnifiedGoodBuilder(session) .WithProductIdentification(new ProductNumberBuilder(session) .WithIdentification("2") .WithProductIdentificationType(new ProductIdentificationTypes(session).Good).Build()) .WithVatRate(vatRate21) .WithName("good2") .WithUnitOfMeasure(new UnitsOfMeasure(session).Piece) .WithPart(new NonUnifiedPartBuilder(session) .WithProductIdentification(new PartNumberBuilder(session) .WithIdentification("2") .WithProductIdentificationType(new ProductIdentificationTypes(session).Part).Build()) .WithInventoryItemKind(new InventoryItemKinds(session).NonSerialised).Build()) .Build(); var good3 = new NonUnifiedGoodBuilder(session) .WithProductIdentification(new ProductNumberBuilder(session) .WithIdentification("3") .WithProductIdentificationType(new ProductIdentificationTypes(session).Good).Build()) .WithVatRate(vatRate21) .WithName("good3") .WithUnitOfMeasure(new UnitsOfMeasure(session).Piece) .WithPart(new NonUnifiedPartBuilder(session) .WithProductIdentification(new PartNumberBuilder(session) .WithIdentification("3") .WithProductIdentificationType(new ProductIdentificationTypes(session).Part).Build()) .WithInventoryItemKind(new InventoryItemKinds(session).NonSerialised).Build()) .Build(); var catMain = new ProductCategoryBuilder(session).WithName("main cat").Build(); var cat1 = new ProductCategoryBuilder(session) .WithName("cat for good1") .WithParent(catMain) .WithProduct(good1) .Build(); var cat2 = new ProductCategoryBuilder(session) .WithName("cat for good2") .WithParent(catMain) .WithProduct(good2) .WithProduct(good3) .Build(); session.Derive(); session.Commit(); } }
public void Always_AssignsValues() { var category = new ProductCategoryBuilder().Build(); Assert.That(category.Name.Value, Is.EqualTo("furniture")); }
public void GivenProductCategory_WhenNewParentsAreInserted_ThenAncestorsAreRecalculated() { var productCategory1 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1").Build(); var productCategory2 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("2").Build(); var productCategory11 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1.1").WithParent(productCategory1).WithParent(productCategory2).Build(); var productCategory12 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1.2").WithParent(productCategory1).WithParent(productCategory2).Build(); var productCategory111 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1.1.1").WithParent(productCategory11).Build(); var productCategory121 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1.2.1").WithParent(productCategory12).Build(); var productCategory122 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1.2.2").WithParent(productCategory12).Build(); this.DatabaseSession.Derive(true); Assert.IsFalse(productCategory1.ExistAncestors); Assert.IsFalse(productCategory2.ExistAncestors); Assert.AreEqual(2, productCategory11.Ancestors.Count); Assert.Contains(productCategory1, productCategory11.Ancestors); Assert.Contains(productCategory2, productCategory11.Ancestors); Assert.AreEqual(2, productCategory12.Ancestors.Count); Assert.Contains(productCategory1, productCategory12.Ancestors); Assert.Contains(productCategory2, productCategory12.Ancestors); Assert.AreEqual(3, productCategory111.Ancestors.Count); Assert.Contains(productCategory11, productCategory111.Ancestors); Assert.Contains(productCategory1, productCategory111.Ancestors); Assert.Contains(productCategory2, productCategory111.Ancestors); Assert.AreEqual(3, productCategory121.Ancestors.Count); Assert.Contains(productCategory12, productCategory121.Ancestors); Assert.Contains(productCategory1, productCategory121.Ancestors); Assert.Contains(productCategory2, productCategory121.Ancestors); Assert.AreEqual(3, productCategory122.Ancestors.Count); Assert.Contains(productCategory12, productCategory122.Ancestors); Assert.Contains(productCategory1, productCategory122.Ancestors); Assert.Contains(productCategory2, productCategory122.Ancestors); var productCategory3 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("3").Build(); productCategory11.AddParent(productCategory3); this.DatabaseSession.Derive(true); Assert.IsFalse(productCategory1.ExistAncestors); Assert.IsFalse(productCategory2.ExistAncestors); Assert.IsFalse(productCategory3.ExistAncestors); Assert.AreEqual(3, productCategory11.Ancestors.Count); Assert.Contains(productCategory1, productCategory11.Ancestors); Assert.Contains(productCategory2, productCategory11.Ancestors); Assert.Contains(productCategory3, productCategory11.Ancestors); Assert.AreEqual(2, productCategory12.Ancestors.Count); Assert.Contains(productCategory1, productCategory12.Ancestors); Assert.Contains(productCategory2, productCategory12.Ancestors); Assert.AreEqual(4, productCategory111.Ancestors.Count); Assert.Contains(productCategory11, productCategory111.Ancestors); Assert.Contains(productCategory1, productCategory111.Ancestors); Assert.Contains(productCategory2, productCategory111.Ancestors); Assert.Contains(productCategory3, productCategory111.Ancestors); Assert.AreEqual(3, productCategory121.Ancestors.Count); Assert.Contains(productCategory12, productCategory121.Ancestors); Assert.Contains(productCategory1, productCategory121.Ancestors); Assert.Contains(productCategory2, productCategory121.Ancestors); Assert.AreEqual(3, productCategory122.Ancestors.Count); Assert.Contains(productCategory12, productCategory122.Ancestors); Assert.Contains(productCategory1, productCategory122.Ancestors); Assert.Contains(productCategory2, productCategory122.Ancestors); var productCategory13 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1.3").WithParent(productCategory1).Build(); productCategory122.AddParent(productCategory13); this.DatabaseSession.Derive(true); Assert.IsFalse(productCategory1.ExistAncestors); Assert.IsFalse(productCategory2.ExistAncestors); Assert.IsFalse(productCategory3.ExistAncestors); Assert.AreEqual(3, productCategory11.Ancestors.Count); Assert.Contains(productCategory1, productCategory11.Ancestors); Assert.Contains(productCategory2, productCategory11.Ancestors); Assert.Contains(productCategory3, productCategory11.Ancestors); Assert.AreEqual(2, productCategory12.Ancestors.Count); Assert.Contains(productCategory1, productCategory12.Ancestors); Assert.Contains(productCategory2, productCategory12.Ancestors); Assert.AreEqual(1, productCategory13.Ancestors.Count); Assert.Contains(productCategory1, productCategory13.Ancestors); Assert.AreEqual(4, productCategory111.Ancestors.Count); Assert.Contains(productCategory11, productCategory111.Ancestors); Assert.Contains(productCategory1, productCategory111.Ancestors); Assert.Contains(productCategory2, productCategory111.Ancestors); Assert.Contains(productCategory3, productCategory111.Ancestors); Assert.AreEqual(3, productCategory121.Ancestors.Count); Assert.Contains(productCategory12, productCategory121.Ancestors); Assert.Contains(productCategory1, productCategory121.Ancestors); Assert.Contains(productCategory2, productCategory121.Ancestors); Assert.AreEqual(4, productCategory122.Ancestors.Count); Assert.Contains(productCategory12, productCategory122.Ancestors); Assert.Contains(productCategory13, productCategory122.Ancestors); Assert.Contains(productCategory1, productCategory122.Ancestors); Assert.Contains(productCategory2, productCategory122.Ancestors); }
public void DeriveHistory() { var productItem = new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem; var contactMechanism = new ContactMechanisms(this.DatabaseSession).Extent().First; var customer1 = new OrganisationBuilder(this.DatabaseSession).WithName("customer1").Build(); var customer2 = new OrganisationBuilder(this.DatabaseSession).WithName("customer2").Build(); var salesRep1 = new PersonBuilder(this.DatabaseSession).WithLastName("salesRep1").Build(); var salesRep2 = new PersonBuilder(this.DatabaseSession).WithLastName("salesRep2").Build(); var package1 = new PackageBuilder(this.DatabaseSession).WithName("package1").Build(); var package2 = new PackageBuilder(this.DatabaseSession).WithName("package2").Build(); var salesChannel1 = new SalesChannels(this.DatabaseSession).WebChannel; var salesChannel2 = new SalesChannels(this.DatabaseSession).NoChannel; var catMain = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("main cat").Build(); var cat1 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("cat for good1").WithParent(catMain).WithPackage(package1).Build(); var cat2 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("cat for good2").WithParent(catMain).WithPackage(package2).Build(); new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).WithProductCategory(cat1).WithSalesRepresentative(salesRep1).Build(); new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).WithProductCategory(cat2).WithSalesRepresentative(salesRep2).Build(); this.DatabaseSession.Derive(true); new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).WithProductCategory(cat1).WithSalesRepresentative(salesRep1).Build(); new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).WithProductCategory(cat2).WithSalesRepresentative(salesRep2).Build(); this.DatabaseSession.Derive(true); var euro = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR"); var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var good1 = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(vatRate21) .WithName("good1") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithPrimaryProductCategory(cat1) .Build(); var good2 = new GoodBuilder(this.DatabaseSession) .WithSku("10102") .WithVatRate(vatRate21) .WithName("good2") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithPrimaryProductCategory(cat2) .Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); internalOrganisation.PreferredCurrency = euro; new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).WithInternalOrganisation(internalOrganisation).Build(); new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).WithInternalOrganisation(internalOrganisation).Build(); this.DatabaseSession.Derive(true); var invoice1 = new SalesInvoiceBuilder(this.DatabaseSession) .WithInvoiceDate(DateTime.UtcNow.AddMonths(-1)) .WithInvoiceNumber("1") .WithBillToCustomer(customer1) .WithBillToContactMechanism(contactMechanism) .WithSalesChannel(salesChannel1) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .Build(); var item1a = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build(); invoice1.AddSalesInvoiceItem(item1a); var item1b = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build(); invoice1.AddSalesInvoiceItem(item1b); var item1c = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantity(5).WithActualUnitPrice(10).WithSalesInvoiceItemType(productItem).Build(); invoice1.AddSalesInvoiceItem(item1c); this.DatabaseSession.Derive(true); var invoice2 = new SalesInvoiceBuilder(this.DatabaseSession) .WithInvoiceDate(DateTime.UtcNow) .WithInvoiceNumber("1") .WithBillToCustomer(customer1) .WithBillToContactMechanism(contactMechanism) .WithSalesChannel(salesChannel1) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .Build(); var item2a = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build(); invoice2.AddSalesInvoiceItem(item2a); var item2b = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build(); invoice2.AddSalesInvoiceItem(item2b); var item2c = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantity(5).WithActualUnitPrice(10).WithSalesInvoiceItemType(productItem).Build(); invoice2.AddSalesInvoiceItem(item2c); this.DatabaseSession.Derive(true); Singleton.Instance(this.DatabaseSession).DeriveRevenues(); var salesRep1RevenueHistory = salesRep1.SalesRepRevenueHistoriesWhereSalesRep.First; Assert.AreEqual(90, salesRep1RevenueHistory.Revenue); var salesRep2RevenueHistory = salesRep2.SalesRepRevenueHistoriesWhereSalesRep.First; Assert.AreEqual(50, salesRep2RevenueHistory.Revenue); var invoice3 = new SalesInvoiceBuilder(this.DatabaseSession) .WithInvoiceDate(DateTime.UtcNow) .WithInvoiceNumber("1") .WithBillToCustomer(customer2) .WithBillToContactMechanism(contactMechanism) .WithSalesChannel(salesChannel2) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .Build(); var item3a = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(1).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build(); invoice3.AddSalesInvoiceItem(item3a); var item3b = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantity(1).WithActualUnitPrice(10).WithSalesInvoiceItemType(productItem).Build(); invoice3.AddSalesInvoiceItem(item3b); this.DatabaseSession.Derive(true); Singleton.Instance(this.DatabaseSession).DeriveRevenues(); Assert.AreEqual(105, salesRep1RevenueHistory.Revenue); Assert.AreEqual(60, salesRep2RevenueHistory.Revenue); }
public void GivenTimeAndMaterialsServiceWithoutPrimaryProductCategoryWithOneProductCategory_WhenDeriving_ThenPrimaryProductCategoryIsCopiedFromCategory() { var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var productCategory = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("category").Build(); var timeAndMaterialsService = new TimeAndMaterialsServiceBuilder(this.DatabaseSession) .WithName("TimeAndMaterialsService") .WithProductCategory(productCategory) .WithVatRate(vatRate21) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(productCategory, timeAndMaterialsService.PrimaryProductCategory); }
public void GivenGoodWithoutPrimaryProductCategoryWithOneProductCategory_WhenDeriving_ThenPrimaryProductCategoryIsCopiedFromCategory() { var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var productCategory = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("category").Build(); var good = new GoodBuilder(this.DatabaseSession) .WithName("Good") .WithSku("10101") .WithVatRate(vatRate21) .WithProductCategory(productCategory) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(productCategory, good.PrimaryProductCategory); }
public void GivenSalesInvoice_WhenDerivingSalesReps_ThenSalesRepsAreCollectedFromSalesInvoiceItems() { var salesrep1 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for child product category").Build(); var salesrep2 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for parent category").Build(); var salesrep3 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for everything else").Build(); var parentProductCategory = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("parent").Build(); var childProductCategory = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("child").WithParent(parentProductCategory).Build(); var billToCustomer = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build(); var contactMechanism = new PostalAddressBuilder(this.DatabaseSession) .WithAddress1("Haverwerf 15") .WithPostalBoundary(new PostalBoundaryBuilder(this.DatabaseSession) .WithLocality("Mechelen") .WithCountry(new Countries(this.DatabaseSession).FindBy(Countries.Meta.IsoCode, "BE")) .Build()) .Build(); new SalesRepRelationshipBuilder(this.DatabaseSession) .WithSalesRepresentative(salesrep1) .WithCustomer(billToCustomer) .WithProductCategory(childProductCategory) .Build(); new SalesRepRelationshipBuilder(this.DatabaseSession) .WithSalesRepresentative(salesrep2) .WithCustomer(billToCustomer) .WithProductCategory(parentProductCategory) .Build(); new SalesRepRelationshipBuilder(this.DatabaseSession) .WithSalesRepresentative(salesrep3) .WithCustomer(billToCustomer) .Build(); var good1 = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithName("good") .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(0).Build()) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithProductCategory(childProductCategory) .Build(); var good2 = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithName("good") .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(0).Build()) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithProductCategory(parentProductCategory) .Build(); var good3 = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithName("good") .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(0).Build()) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); var invoice = new SalesInvoiceBuilder(this.DatabaseSession) .WithBillToCustomer(billToCustomer) .WithBillToContactMechanism(contactMechanism) .Build(); new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(invoice.BillToCustomer).WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation).Build(); var item1 = new SalesInvoiceItemBuilder(this.DatabaseSession) .WithProduct(good1) .WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem) .WithQuantity(3) .WithActualUnitPrice(5) .Build(); var item2 = new SalesInvoiceItemBuilder(this.DatabaseSession) .WithProduct(good2) .WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem) .WithQuantity(3) .WithActualUnitPrice(5) .Build(); var item3 = new SalesInvoiceItemBuilder(this.DatabaseSession) .WithProduct(good3) .WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem) .WithQuantity(3) .WithActualUnitPrice(5) .Build(); invoice.AddSalesInvoiceItem(item1); this.DatabaseSession.Derive(true); Assert.AreEqual(1, invoice.SalesReps.Count); Assert.Contains(salesrep1, invoice.SalesReps); invoice.AddSalesInvoiceItem(item2); this.DatabaseSession.Derive(true); Assert.AreEqual(2, invoice.SalesReps.Count); Assert.Contains(salesrep1, invoice.SalesReps); Assert.Contains(salesrep2, invoice.SalesReps); invoice.AddSalesInvoiceItem(item3); this.DatabaseSession.Derive(true); Assert.AreEqual(3, invoice.SalesReps.Count); Assert.Contains(salesrep1, invoice.SalesReps); Assert.Contains(salesrep2, invoice.SalesReps); Assert.Contains(salesrep3, invoice.SalesReps); }
public void GivenSalesOrder_WhenDerivingSalesReps_ThenSalesRepsAreCollectedFromSalesOrderItems() { var salesrep1 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for child product category").Build(); var salesrep2 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for parent category").Build(); var salesrep3 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for everything else").Build(); var parentProductCategory = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("parent").Build(); var childProductCategory = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("child").WithParent(parentProductCategory).Build(); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var customer = new OrganisationBuilder(this.DatabaseSession).WithName("company").Build(); var internalOrganisation = Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation; new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); new SalesRepRelationshipBuilder(this.DatabaseSession) .WithSalesRepresentative(salesrep1) .WithCustomer(customer) .WithProductCategory(childProductCategory) .Build(); new SalesRepRelationshipBuilder(this.DatabaseSession) .WithSalesRepresentative(salesrep2) .WithCustomer(customer) .WithProductCategory(parentProductCategory) .Build(); new SalesRepRelationshipBuilder(this.DatabaseSession) .WithSalesRepresentative(salesrep3) .WithCustomer(customer) .Build(); var good1 = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithName("good") .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build()) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithProductCategory(childProductCategory) .Build(); var good2 = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithName("good") .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build()) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithProductCategory(parentProductCategory) .Build(); var good3 = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithName("good") .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build()) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); this.DatabaseSession.Derive(true); var order = new SalesOrderBuilder(this.DatabaseSession) .WithBillToCustomer(customer) .WithShipToCustomer(customer) .WithShipToAddress(new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build()) .Build(); var item1 = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(good1) .WithQuantityOrdered(3) .WithActualUnitPrice(5) .Build(); order.AddSalesOrderItem(item1); this.DatabaseSession.Derive(true); Assert.AreEqual(1, order.SalesReps.Count); Assert.Contains(salesrep1, order.SalesReps); var item2 = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(good2) .WithQuantityOrdered(3) .WithActualUnitPrice(5) .Build(); order.AddSalesOrderItem(item2); this.DatabaseSession.Derive(true); Assert.AreEqual(2, order.SalesReps.Count); Assert.Contains(salesrep1, order.SalesReps); Assert.Contains(salesrep2, order.SalesReps); var item3 = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(good3) .WithQuantityOrdered(3) .WithActualUnitPrice(5) .Build(); order.AddSalesOrderItem(item3); this.DatabaseSession.Derive(true); Assert.AreEqual(3, order.SalesReps.Count); Assert.Contains(salesrep1, order.SalesReps); Assert.Contains(salesrep2, order.SalesReps); Assert.Contains(salesrep3, order.SalesReps); }
public void GivenGood_WhenProductCategoryParentsAreRemoved_ThenProductCategoriesExpandedAreRecalculated() { var productCategory1 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1").Build(); var productCategory2 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("2").Build(); var productCategory11 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1.1").WithParent(productCategory1).WithParent(productCategory2).Build(); var productCategory12 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1.2").WithParent(productCategory1).WithParent(productCategory2).Build(); var productCategory111 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1.1.1").WithParent(productCategory11).Build(); var productCategory121 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1.2.1").WithParent(productCategory12).Build(); var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var good = new GoodBuilder(this.DatabaseSession) .WithName("Good") .WithSku("10101") .WithPrimaryProductCategory(productCategory111) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithVatRate(vatRate21) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(4, good.ProductCategoriesExpanded.Count); Assert.Contains(productCategory111, good.ProductCategoriesExpanded); Assert.Contains(productCategory11, good.ProductCategoriesExpanded); Assert.Contains(productCategory1, good.ProductCategoriesExpanded); Assert.Contains(productCategory2, good.ProductCategoriesExpanded); productCategory11.RemoveParent(productCategory2); this.DatabaseSession.Derive(true); Assert.AreEqual(3, good.ProductCategoriesExpanded.Count); Assert.Contains(productCategory111, good.ProductCategoriesExpanded); Assert.Contains(productCategory11, good.ProductCategoriesExpanded); Assert.Contains(productCategory1, good.ProductCategoriesExpanded); }
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); }
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(); }
public void GivenInventoryItem_WhenQuantityOnHandIsRaised_ThenSalesOrderItemsWithQuantityShortFalledAreUpdated() { 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(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithPrimaryProductCategory(category) .Build(); var inventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good).Build(); inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(5).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); 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(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var order1 = new SalesOrderBuilder(this.DatabaseSession) .WithBillToCustomer(customer) .WithShipToCustomer(customer) .WithDeliveryDate(DateTime.UtcNow) .Build(); var item1 = new SalesOrderItemBuilder(this.DatabaseSession).WithDescription("item1").WithProduct(good).WithQuantityOrdered(10).WithActualUnitPrice(15).Build(); var item2 = new SalesOrderItemBuilder(this.DatabaseSession).WithDescription("item2").WithProduct(good).WithQuantityOrdered(20).WithActualUnitPrice(15).Build(); order1.AddSalesOrderItem(item1); order1.AddSalesOrderItem(item2); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); order1.Confirm(); this.DatabaseSession.Derive(true); var order2 = new SalesOrderBuilder(this.DatabaseSession) .WithBillToCustomer(customer) .WithShipToCustomer(customer) .WithDeliveryDate(DateTime.UtcNow.AddDays(1)) .Build(); var item3 = new SalesOrderItemBuilder(this.DatabaseSession).WithDescription("item3").WithProduct(good).WithQuantityOrdered(10).WithActualUnitPrice(15).Build(); var item4 = new SalesOrderItemBuilder(this.DatabaseSession).WithDescription("item4").WithProduct(good).WithQuantityOrdered(20).WithActualUnitPrice(15).Build(); order2.AddSalesOrderItem(item3); order2.AddSalesOrderItem(item4); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); order2.Confirm(); this.DatabaseSession.Derive(true); //Assert.AreEqual(0, item1.QuantityRequestsShipping); //Assert.AreEqual(5, item1.QuantityPendingShipment); //Assert.AreEqual(10, item1.QuantityReserved); //Assert.AreEqual(5, item1.QuantityShortFalled); //Assert.AreEqual(0, item2.QuantityRequestsShipping); //Assert.AreEqual(0, item2.QuantityPendingShipment); //Assert.AreEqual(20, item2.QuantityReserved); //Assert.AreEqual(20, item2.QuantityShortFalled); //Assert.AreEqual(0, item3.QuantityRequestsShipping); //Assert.AreEqual(0, item3.QuantityPendingShipment); //Assert.AreEqual(10, item3.QuantityReserved); //Assert.AreEqual(10, item3.QuantityShortFalled); //Assert.AreEqual(0, item4.QuantityRequestsShipping); //Assert.AreEqual(0, item4.QuantityPendingShipment); //Assert.AreEqual(20, item4.QuantityReserved); //Assert.AreEqual(20, item4.QuantityShortFalled); Assert.AreEqual(0, item1.ReservedFromInventoryItem.AvailableToPromise); Assert.AreEqual(5, item1.ReservedFromInventoryItem.QuantityOnHand); inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(15).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); //// Orderitems are sorted as follows: item1, item2, item3, item4 //Assert.AreEqual(0, item1.QuantityRequestsShipping); //Assert.AreEqual(10, item1.QuantityPendingShipment); //Assert.AreEqual(10, item1.QuantityReserved); //Assert.AreEqual(0, item1.QuantityShortFalled); //Assert.AreEqual(0, item2.QuantityRequestsShipping); //Assert.AreEqual(10, item2.QuantityPendingShipment); //Assert.AreEqual(20, item2.QuantityReserved); //Assert.AreEqual(10, item2.QuantityShortFalled); //Assert.AreEqual(0, item3.QuantityRequestsShipping); //Assert.AreEqual(0, item3.QuantityPendingShipment); //Assert.AreEqual(10, item3.QuantityReserved); //Assert.AreEqual(10, item3.QuantityShortFalled); //Assert.AreEqual(0, item4.QuantityRequestsShipping); //Assert.AreEqual(0, item4.QuantityPendingShipment); //Assert.AreEqual(20, item4.QuantityReserved); //Assert.AreEqual(20, item4.QuantityShortFalled); Assert.AreEqual(0, item1.ReservedFromInventoryItem.AvailableToPromise); Assert.AreEqual(20, item1.ReservedFromInventoryItem.QuantityOnHand); inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(85).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); //// Orderitems are sorted as follows: item2, item1, item4, item 3 Assert.AreEqual(0, item1.QuantityRequestsShipping); Assert.AreEqual(10, item1.QuantityPendingShipment); Assert.AreEqual(10, item1.QuantityReserved); Assert.AreEqual(0, item1.QuantityShortFalled); Assert.AreEqual(0, item2.QuantityRequestsShipping); Assert.AreEqual(20, item2.QuantityPendingShipment); Assert.AreEqual(20, item2.QuantityReserved); Assert.AreEqual(0, item2.QuantityShortFalled); Assert.AreEqual(0, item3.QuantityRequestsShipping); Assert.AreEqual(10, item3.QuantityPendingShipment); Assert.AreEqual(10, item3.QuantityReserved); Assert.AreEqual(0, item3.QuantityShortFalled); Assert.AreEqual(0, item4.QuantityRequestsShipping); Assert.AreEqual(20, item4.QuantityPendingShipment); Assert.AreEqual(20, item4.QuantityReserved); Assert.AreEqual(0, item4.QuantityShortFalled); Assert.AreEqual(45, item1.ReservedFromInventoryItem.AvailableToPromise); Assert.AreEqual(105, item1.ReservedFromInventoryItem.QuantityOnHand); }
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(); }
public void DeriveRevenues() { var productItem = new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem; var contactMechanism = new ContactMechanisms(this.DatabaseSession).Extent().First; var customer1 = new OrganisationBuilder(this.DatabaseSession).WithName("customer1").Build(); var customer2 = new OrganisationBuilder(this.DatabaseSession).WithName("customer2").Build(); var salesRep1 = new PersonBuilder(this.DatabaseSession).WithLastName("salesRep1").Build(); var salesRep2 = new PersonBuilder(this.DatabaseSession).WithLastName("salesRep2").Build(); var catMain = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("main cat").Build(); var cat1 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("cat for good1").WithParent(catMain).Build(); var cat2 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("cat for good2").WithParent(catMain).Build(); new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).WithProductCategory(cat1).WithSalesRepresentative(salesRep1).Build(); new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).WithProductCategory(cat2).WithSalesRepresentative(salesRep2).Build(); this.DatabaseSession.Derive(true); new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).WithProductCategory(cat1).WithSalesRepresentative(salesRep1).Build(); new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).WithProductCategory(cat2).WithSalesRepresentative(salesRep2).Build(); this.DatabaseSession.Derive(true); var euro = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR"); var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var good1 = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(vatRate21) .WithName("good1") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithPrimaryProductCategory(cat1) .Build(); var good2 = new GoodBuilder(this.DatabaseSession) .WithSku("10102") .WithVatRate(vatRate21) .WithName("good2") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithPrimaryProductCategory(cat2) .Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); internalOrganisation.PreferredCurrency = euro; new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).WithInternalOrganisation(internalOrganisation).Build(); new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).WithInternalOrganisation(internalOrganisation).Build(); this.DatabaseSession.Derive(true); var invoice1 = new SalesInvoiceBuilder(this.DatabaseSession) .WithInvoiceDate(DateTime.UtcNow) .WithInvoiceNumber("1") .WithBillToCustomer(customer1) .WithBillToContactMechanism(contactMechanism) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .Build(); var item1 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build(); invoice1.AddSalesInvoiceItem(item1); var item2 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build(); invoice1.AddSalesInvoiceItem(item2); var item3 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantity(5).WithActualUnitPrice(10).WithSalesInvoiceItemType(productItem).Build(); invoice1.AddSalesInvoiceItem(item3); this.DatabaseSession.Derive(true); Singleton.Instance(this.DatabaseSession).DeriveRevenues(); var customer1ProductRevenues = customer1.PartyProductRevenuesWhereParty; Assert.AreEqual(2, customer1ProductRevenues.Count); customer1ProductRevenues = customer1.PartyProductRevenuesWhereParty; customer1ProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.Product, good1); var customer1Good1Revenue = customer1ProductRevenues.First; customer1ProductRevenues = customer1.PartyProductRevenuesWhereParty; customer1ProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.Product, good2); var customer1Good2Revenue = customer1ProductRevenues.First; Assert.AreEqual(90, customer1Good1Revenue.Revenue); Assert.AreEqual(6, customer1Good1Revenue.Quantity); Assert.AreEqual(50, customer1Good2Revenue.Revenue); Assert.AreEqual(5, customer1Good2Revenue.Quantity); var invoice2 = new SalesInvoiceBuilder(this.DatabaseSession) .WithInvoiceDate(DateTime.UtcNow) .WithInvoiceNumber("1") .WithBillToCustomer(customer2) .WithBillToContactMechanism(contactMechanism) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .Build(); var item4 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(1).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build(); invoice2.AddSalesInvoiceItem(item4); this.DatabaseSession.Derive(true); var item5 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantity(1).WithActualUnitPrice(10).WithSalesInvoiceItemType(productItem).Build(); invoice2.AddSalesInvoiceItem(item5); this.DatabaseSession.Derive(true); Singleton.Instance(this.DatabaseSession).DeriveRevenues(); var customer2ProductRevenues = customer2.PartyProductRevenuesWhereParty; Assert.AreEqual(2, customer2ProductRevenues.Count); customer2ProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.Product, good1); var customer2Good1Revenue = customer2ProductRevenues.First; customer2ProductRevenues = customer2.PartyProductRevenuesWhereParty; customer2ProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.Product, good2); var customer2Good2Revenue = customer2ProductRevenues.First; Assert.AreEqual(15, customer2Good1Revenue.Revenue); Assert.AreEqual(1, customer2Good1Revenue.Quantity); Assert.AreEqual(10, customer2Good2Revenue.Revenue); Assert.AreEqual(1, customer2Good2Revenue.Quantity); }
public void GivenInvoiceItemWithSalesRepForThisProductsParent_WhenDerivingSalesRep_ThenSalesRepForParentCategoryIsSelected() { this.InstantiateObjects(this.DatabaseSession); var salesrep1 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for child product category").Build(); var salesrep2 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for parent category").Build(); var salesrep3 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for everything else").Build(); var parentProductCategory = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("parent").Build(); var childProductCategory = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("child").WithParent(parentProductCategory).Build(); new SalesRepRelationshipBuilder(this.DatabaseSession) .WithFromDate(DateTime.UtcNow.AddMinutes(-1)) .WithSalesRepresentative(salesrep1) .WithCustomer(this.invoice.BillToCustomer) .WithProductCategory(childProductCategory) .Build(); new SalesRepRelationshipBuilder(this.DatabaseSession) .WithFromDate(DateTime.UtcNow.AddMinutes(-1)) .WithSalesRepresentative(salesrep2) .WithCustomer(this.invoice.BillToCustomer) .WithProductCategory(parentProductCategory) .Build(); new SalesRepRelationshipBuilder(this.DatabaseSession) .WithFromDate(DateTime.UtcNow.AddMinutes(-1)) .WithSalesRepresentative(salesrep3) .WithCustomer(this.invoice.BillToCustomer) .Build(); this.good.AddProductCategory(parentProductCategory); this.DatabaseSession.Derive(true); var invoiceItem = new SalesInvoiceItemBuilder(this.DatabaseSession) .WithProduct(this.good) .WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem) .WithQuantity(3) .WithActualUnitPrice(5) .Build(); this.invoice.AddSalesInvoiceItem(invoiceItem); this.DatabaseSession.Derive(true); Assert.AreEqual(invoiceItem.SalesRep, salesrep2); }
public void GivenSalesInvoice_WhenDerived_ThenTotalExVatIsAddedToPartyPackageRevenueHistory() { var productItem = new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem; var contactMechanism = new ContactMechanisms(this.DatabaseSession).Extent().First; var euro = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR"); var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var package1 = new PackageBuilder(this.DatabaseSession).WithName("package1").Build(); var cat1 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("cat for good1").WithPackage(package1).Build(); var good1 = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(vatRate21) .WithName("good1") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithPrimaryProductCategory(cat1) .Build(); var customer = new Organisations(this.DatabaseSession).FindBy(Organisations.Meta.Name, "customer"); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); internalOrganisation.PreferredCurrency = euro; this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var date = DateTime.UtcNow.AddYears(-1).AddMonths(-1); decimal revenuePastTwelveMonths = 0; for (var i = 1; i <= 13; i++) { var invoice = new SalesInvoiceBuilder(this.DatabaseSession) .WithInvoiceDate(date) .WithBillToCustomer(customer) .WithBillToContactMechanism(contactMechanism) .WithSalesChannel(new SalesChannels(this.DatabaseSession).WebChannel) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .Build(); var item = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(1).WithActualUnitPrice(i * 10M).WithSalesInvoiceItemType(productItem).Build(); invoice.AddSalesInvoiceItem(item); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var history = customer.PartyPackageRevenueHistoriesWhereParty.First; //// first iteration is too old if (i > 1) { revenuePastTwelveMonths += i * 10M; } ////date in first iteration is too old, no history yet. if (history != null) { Assert.AreEqual(revenuePastTwelveMonths, history.Revenue); } date = date.AddMonths(1); } }
public void GivenSalesInvoice_WhenDeriving_ThenRevenuesAreCreatedAndUpdated() { var productItem = new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem; var contactMechanism = new ContactMechanisms(this.DatabaseSession).Extent().First; var customer1 = new OrganisationBuilder(this.DatabaseSession).WithName("customer1").Build(); var customer2 = new OrganisationBuilder(this.DatabaseSession).WithName("customer2").Build(); var salesRep1 = new PersonBuilder(this.DatabaseSession).WithLastName("salesRep1").Build(); var salesRep2 = new PersonBuilder(this.DatabaseSession).WithLastName("salesRep2").Build(); var catMain = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("main cat").Build(); var cat1 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("cat for good1").WithParent(catMain).Build(); var cat2 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("cat for good2").WithParent(catMain).Build(); new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).WithProductCategory(cat1).WithSalesRepresentative(salesRep1).Build(); new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).WithProductCategory(cat2).WithSalesRepresentative(salesRep2).Build(); this.DatabaseSession.Derive(true); new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).WithProductCategory(cat1).WithSalesRepresentative(salesRep1).Build(); new SalesRepRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).WithProductCategory(cat2).WithSalesRepresentative(salesRep2).Build(); this.DatabaseSession.Derive(true); var euro = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR"); var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var good1 = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(vatRate21) .WithName("good1") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithPrimaryProductCategory(cat1) .Build(); var good2 = new GoodBuilder(this.DatabaseSession) .WithSku("10102") .WithVatRate(vatRate21) .WithName("good2") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithPrimaryProductCategory(cat2) .Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); internalOrganisation.PreferredCurrency = euro; var invoice1 = new SalesInvoiceBuilder(this.DatabaseSession) .WithInvoiceDate(DateTime.UtcNow) .WithInvoiceNumber("1") .WithBillToCustomer(customer1) .WithBillToContactMechanism(contactMechanism) .WithSalesChannel(new SalesChannels(this.DatabaseSession).WebChannel) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .Build(); new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(invoice1.BillToCustomer).WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation).Build(); var item1 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build(); invoice1.AddSalesInvoiceItem(item1); var item2 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(3).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build(); invoice1.AddSalesInvoiceItem(item2); var item3 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantity(5).WithActualUnitPrice(10).WithSalesInvoiceItemType(productItem).Build(); invoice1.AddSalesInvoiceItem(item3); this.DatabaseSession.Derive(true); var customer1Revenue = customer1.PartyRevenuesWhereParty[0]; var internalOrganisationRevenue = internalOrganisation.InternalOrganisationRevenuesWhereInternalOrganisation[0]; var storeRevenue = invoice1.Store.StoreRevenuesWhereStore[0]; var salesChannelRevenue = invoice1.SalesChannel.SalesChannelRevenuesWhereSalesChannel[0]; var salesRep1Revenue = salesRep1.SalesRepRevenuesWhereSalesRep[0]; var salesRep2Revenue = salesRep2.SalesRepRevenuesWhereSalesRep[0]; var good1Revenue = good1.ProductRevenuesWhereProduct[0]; var good2Revenue = good2.ProductRevenuesWhereProduct[0]; var cat1Revenue = cat1.ProductCategoryRevenuesWhereProductCategory[0]; var cat2Revenue = cat2.ProductCategoryRevenuesWhereProductCategory[0]; var catMainRevenue = catMain.ProductCategoryRevenuesWhereProductCategory[0]; var customer1ProductRevenues = customer1.PartyProductRevenuesWhereParty; Assert.AreEqual(2, customer1ProductRevenues.Count); customer1ProductRevenues = customer1.PartyProductRevenuesWhereParty; customer1ProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.Product, good1); var customer1Good1Revenue = customer1ProductRevenues.First; customer1ProductRevenues = customer1.PartyProductRevenuesWhereParty; customer1ProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.Product, good2); var customer1Good2Revenue = customer1ProductRevenues.First; var customer1ProductCategoryRevenues = customer1.PartyProductCategoryRevenuesWhereParty; Assert.AreEqual(3, customer1ProductCategoryRevenues.Count); customer1ProductCategoryRevenues.Filter.AddEquals(PartyProductCategoryRevenues.Meta.ProductCategory, cat1); var customer1Cat1Revenue = customer1ProductCategoryRevenues.First; customer1ProductCategoryRevenues = customer1.PartyProductCategoryRevenuesWhereParty; customer1ProductCategoryRevenues.Filter.AddEquals(PartyProductCategoryRevenues.Meta.ProductCategory, cat2); var customer1Cat2Revenue = customer1ProductCategoryRevenues.First; customer1ProductCategoryRevenues = customer1.PartyProductCategoryRevenuesWhereParty; customer1ProductCategoryRevenues.Filter.AddEquals(PartyProductCategoryRevenues.Meta.ProductCategory, catMain); var customer1CatMainRevenue = customer1ProductCategoryRevenues.First; var salesRep1Customer1Revenues = salesRep1.SalesRepPartyRevenuesWhereSalesRep; salesRep1Customer1Revenues.Filter.AddEquals(SalesRepPartyRevenues.Meta.Party, customer1); var salesRep1Customer1Revenue = salesRep1Customer1Revenues.First; var salesRep2Customer1Revenues = salesRep2.SalesRepPartyRevenuesWhereSalesRep; salesRep2Customer1Revenues.Filter.AddEquals(SalesRepPartyRevenues.Meta.Party, customer1); var salesRep2Customer1Revenue = salesRep2Customer1Revenues.First; var salesRep1Customer1ProductCategoryRevenues = salesRep1.SalesRepPartyProductCategoryRevenuesWhereSalesRep; Assert.AreEqual(2, salesRep1Customer1ProductCategoryRevenues.Count); salesRep1Customer1ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.ProductCategory, cat1); salesRep1Customer1ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.Party, customer1); var salesRep1Customer1Cat1Revenue = salesRep1Customer1ProductCategoryRevenues.First; salesRep1Customer1ProductCategoryRevenues = salesRep1.SalesRepPartyProductCategoryRevenuesWhereSalesRep; salesRep1Customer1ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.ProductCategory, catMain); salesRep1Customer1ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.Party, customer1); var salesRep1Customer1CatMainRevenue = salesRep1Customer1ProductCategoryRevenues.First; var salesRep2Customer1ProductCategoryRevenues = salesRep2.SalesRepPartyProductCategoryRevenuesWhereSalesRep; Assert.AreEqual(2, salesRep2Customer1ProductCategoryRevenues.Count); salesRep2Customer1ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.ProductCategory, cat2); salesRep2Customer1ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.Party, customer1); var salesRep2Customer1Cat2Revenue = salesRep2Customer1ProductCategoryRevenues.First; salesRep2Customer1ProductCategoryRevenues = salesRep2.SalesRepPartyProductCategoryRevenuesWhereSalesRep; salesRep2Customer1ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.Party, customer1); salesRep2Customer1ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.ProductCategory, catMain); var salesRep2Customer1CatMainRevenue = salesRep2Customer1ProductCategoryRevenues.First; var salesRep1ProductCategoryRevenues = salesRep1.SalesRepProductCategoryRevenuesWhereSalesRep; Assert.AreEqual(2, salesRep1ProductCategoryRevenues.Count); salesRep1ProductCategoryRevenues.Filter.AddEquals(SalesRepProductCategoryRevenues.Meta.ProductCategory, cat1); var salesRep1Cat1Revenue = salesRep1ProductCategoryRevenues.First; salesRep1ProductCategoryRevenues = salesRep1.SalesRepProductCategoryRevenuesWhereSalesRep; salesRep1ProductCategoryRevenues.Filter.AddEquals(SalesRepProductCategoryRevenues.Meta.ProductCategory, catMain); var salesRep1CatMainRevenue = salesRep1ProductCategoryRevenues.First; var salesRep2ProductCategoryRevenues = salesRep2.SalesRepProductCategoryRevenuesWhereSalesRep; Assert.AreEqual(2, salesRep2ProductCategoryRevenues.Count); salesRep2ProductCategoryRevenues.Filter.AddEquals(SalesRepProductCategoryRevenues.Meta.ProductCategory, cat2); var salesRep2Cat2Revenue = salesRep2ProductCategoryRevenues.First; salesRep2ProductCategoryRevenues = salesRep2.SalesRepProductCategoryRevenuesWhereSalesRep; salesRep2ProductCategoryRevenues.Filter.AddEquals(SalesRepProductCategoryRevenues.Meta.ProductCategory, catMain); var salesRep2CatMainRevenue = salesRep2ProductCategoryRevenues.First; this.DatabaseSession.Derive(true); Assert.AreEqual(140, internalOrganisationRevenue.Revenue); Assert.AreEqual(140, storeRevenue.Revenue); Assert.AreEqual(140, salesChannelRevenue.Revenue); Assert.AreEqual(90, salesRep1Revenue.Revenue); Assert.AreEqual(50, salesRep2Revenue.Revenue); Assert.AreEqual(90, salesRep1Customer1Revenue.Revenue); Assert.AreEqual(50, salesRep2Customer1Revenue.Revenue); Assert.AreEqual(90, good1Revenue.Revenue); Assert.AreEqual(50, good2Revenue.Revenue); Assert.AreEqual(90, cat1Revenue.Revenue); Assert.AreEqual(50, cat2Revenue.Revenue); Assert.AreEqual(140, catMainRevenue.Revenue); Assert.AreEqual(90, customer1Cat1Revenue.Revenue); Assert.AreEqual(50, customer1Cat2Revenue.Revenue); Assert.AreEqual(140, customer1CatMainRevenue.Revenue); Assert.AreEqual(90, salesRep1Cat1Revenue.Revenue); Assert.AreEqual(90, salesRep1CatMainRevenue.Revenue); Assert.AreEqual(50, salesRep2Cat2Revenue.Revenue); Assert.AreEqual(50, salesRep2CatMainRevenue.Revenue); Assert.AreEqual(90, salesRep1Customer1Cat1Revenue.Revenue); Assert.AreEqual(90, salesRep1Customer1CatMainRevenue.Revenue); Assert.AreEqual(50, salesRep2Customer1Cat2Revenue.Revenue); Assert.AreEqual(50, salesRep2Customer1CatMainRevenue.Revenue); Assert.AreEqual(140, customer1Revenue.Revenue); Assert.AreEqual(90, customer1Good1Revenue.Revenue); Assert.AreEqual(50, customer1Good2Revenue.Revenue); var invoice2 = new SalesInvoiceBuilder(this.DatabaseSession) .WithInvoiceDate(DateTime.UtcNow) .WithInvoiceNumber("1") .WithBillToCustomer(customer2) .WithBillToContactMechanism(contactMechanism) .WithSalesChannel(new SalesChannels(this.DatabaseSession).WebChannel) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .Build(); new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(invoice2.BillToCustomer).WithInternalOrganisation(invoice2.BilledFromInternalOrganisation).Build(); var item4 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantity(1).WithActualUnitPrice(15).WithSalesInvoiceItemType(productItem).Build(); invoice2.AddSalesInvoiceItem(item4); this.DatabaseSession.Derive(true); var item5 = new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good2).WithQuantity(1).WithActualUnitPrice(10).WithSalesInvoiceItemType(productItem).Build(); invoice2.AddSalesInvoiceItem(item5); this.DatabaseSession.Derive(true); var customer2Revenue = customer2.PartyRevenuesWhereParty[0]; var customer2ProductRevenues = customer2.PartyProductRevenuesWhereParty; Assert.AreEqual(2, customer2ProductRevenues.Count); customer2ProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.Product, good1); var customer2Good1Revenue = customer2ProductRevenues.First; customer2ProductRevenues = customer2.PartyProductRevenuesWhereParty; customer2ProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.Product, good2); var customer2Good2Revenue = customer2ProductRevenues.First; var customer2ProductCategoryRevenues = customer2.PartyProductCategoryRevenuesWhereParty; Assert.AreEqual(3, customer2ProductCategoryRevenues.Count); customer2ProductCategoryRevenues.Filter.AddEquals(PartyProductCategoryRevenues.Meta.ProductCategory, cat1); var customer2Cat1Revenue = customer2ProductCategoryRevenues.First; customer2ProductCategoryRevenues = customer2.PartyProductCategoryRevenuesWhereParty; customer2ProductCategoryRevenues.Filter.AddEquals(PartyProductCategoryRevenues.Meta.ProductCategory, cat2); var customer2Cat2Revenue = customer2ProductCategoryRevenues.First; customer2ProductCategoryRevenues = customer2.PartyProductCategoryRevenuesWhereParty; customer2ProductCategoryRevenues.Filter.AddEquals(PartyProductCategoryRevenues.Meta.ProductCategory, catMain); var customer2CatMainRevenue = customer2ProductCategoryRevenues.First; var salesRep1Customer2Revenues = salesRep1.SalesRepPartyRevenuesWhereSalesRep; salesRep1Customer2Revenues.Filter.AddEquals(SalesRepPartyRevenues.Meta.Party, customer2); var salesRep1Customer2Revenue = salesRep1Customer2Revenues.First; var salesRep2Customer2Revenues = salesRep2.SalesRepPartyRevenuesWhereSalesRep; salesRep2Customer2Revenues.Filter.AddEquals(SalesRepPartyRevenues.Meta.Party, customer2); var salesRep2Customer2Revenue = salesRep2Customer2Revenues.First; var salesRep1Customer2ProductCategoryRevenues = salesRep1.SalesRepPartyProductCategoryRevenuesWhereSalesRep; salesRep1Customer2ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.Party, customer2); Assert.AreEqual(2, salesRep1Customer2ProductCategoryRevenues.Count); salesRep1Customer2ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.ProductCategory, cat1); salesRep1Customer2ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.Party, customer2); var salesRep1Customer2Cat1Revenue = salesRep1Customer2ProductCategoryRevenues.First; salesRep1Customer2ProductCategoryRevenues = salesRep1.SalesRepPartyProductCategoryRevenuesWhereSalesRep; salesRep1Customer2ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.ProductCategory, catMain); salesRep1Customer2ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.Party, customer2); var salesRep1Customer2CatMainRevenue = salesRep1Customer2ProductCategoryRevenues.First; var salesRep2Customer2ProductCategoryRevenues = salesRep2.SalesRepPartyProductCategoryRevenuesWhereSalesRep; salesRep2Customer2ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.Party, customer2); Assert.AreEqual(2, salesRep2Customer2ProductCategoryRevenues.Count); salesRep2Customer2ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.ProductCategory, cat2); salesRep2Customer2ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.Party, customer2); var salesRep2Customer2Cat2Revenue = salesRep2Customer2ProductCategoryRevenues.First; salesRep2Customer2ProductCategoryRevenues = salesRep2.SalesRepPartyProductCategoryRevenuesWhereSalesRep; salesRep2Customer2ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.Party, customer2); salesRep2Customer2ProductCategoryRevenues.Filter.AddEquals(SalesRepPartyProductCategoryRevenues.Meta.ProductCategory, catMain); var salesRep2Customer2CatMainRevenue = salesRep2Customer2ProductCategoryRevenues.First; Assert.AreEqual(165, internalOrganisationRevenue.Revenue); Assert.AreEqual(165, storeRevenue.Revenue); Assert.AreEqual(165, salesChannelRevenue.Revenue); Assert.AreEqual(105, salesRep1Revenue.Revenue); Assert.AreEqual(60, salesRep2Revenue.Revenue); Assert.AreEqual(15, salesRep1Customer2Revenue.Revenue); Assert.AreEqual(10, salesRep2Customer2Revenue.Revenue); Assert.AreEqual(105, cat1Revenue.Revenue); Assert.AreEqual(60, cat2Revenue.Revenue); Assert.AreEqual(165, catMainRevenue.Revenue); Assert.AreEqual(15, customer2Cat1Revenue.Revenue); Assert.AreEqual(10, customer2Cat2Revenue.Revenue); Assert.AreEqual(25, customer2CatMainRevenue.Revenue); Assert.AreEqual(105, salesRep1Cat1Revenue.Revenue); Assert.AreEqual(105, salesRep1CatMainRevenue.Revenue); Assert.AreEqual(60, salesRep2Cat2Revenue.Revenue); Assert.AreEqual(60, salesRep2CatMainRevenue.Revenue); Assert.AreEqual(15, salesRep1Customer2Cat1Revenue.Revenue); Assert.AreEqual(15, salesRep1Customer2CatMainRevenue.Revenue); Assert.AreEqual(10, salesRep2Customer2Cat2Revenue.Revenue); Assert.AreEqual(10, salesRep2Customer2CatMainRevenue.Revenue); Assert.AreEqual(105, good1Revenue.Revenue); Assert.AreEqual(60, good2Revenue.Revenue); Assert.AreEqual(25, customer2Revenue.Revenue); Assert.AreEqual(15, customer2Good1Revenue.Revenue); Assert.AreEqual(10, customer2Good2Revenue.Revenue); }
public void GivenOrderItemForProductWithoutCategory_WhenDerivingSalesRep_ThenSalesRepForCustomerIsSelected() { this.InstantiateObjects(this.DatabaseSession); var salesrep1 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for child product category").Build(); var salesrep2 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for parent category").Build(); var salesrep3 = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep for everything else").Build(); var productCategoryParent = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("parent").Build(); var childProductCategory = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("child").WithParent(productCategoryParent).Build(); new SalesRepRelationshipBuilder(this.DatabaseSession) .WithSalesRepresentative(salesrep1) .WithCustomer(this.order.ShipToCustomer) .WithProductCategory(childProductCategory) .WithFromDate(DateTime.UtcNow.AddMinutes(-1)) .Build(); new SalesRepRelationshipBuilder(this.DatabaseSession) .WithSalesRepresentative(salesrep2) .WithCustomer(this.order.ShipToCustomer) .WithProductCategory(productCategoryParent) .WithFromDate(DateTime.UtcNow.AddMinutes(-1)) .Build(); new SalesRepRelationshipBuilder(this.DatabaseSession) .WithSalesRepresentative(salesrep3) .WithCustomer(this.order.ShipToCustomer) .WithFromDate(DateTime.UtcNow.AddMinutes(-1)) .Build(); var orderItem = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(this.good) .WithQuantityOrdered(3) .WithActualUnitPrice(5) .Build(); this.order.AddSalesOrderItem(orderItem); this.DatabaseSession.Derive(true); Assert.AreEqual(orderItem.SalesRep, salesrep3); }
public void GivenProductCategory_WhenDeriving_ThenRequiredRelationsMustExist() { var builder = new ProductCategoryBuilder(this.DatabaseSession); var productCategory = builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithDescription("category"); productCategory = builder.Build(); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); }