public void GivenNextSalesRep_WhenEmploymentAndSalesRepRelationshipAreCreated_ThenSalesRepIsAddedToUserGroup() { var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").Build(); var usergroups = internalOrganisation.UserGroupsWhereParty; usergroups.Filter.AddEquals(UserGroups.Meta.Parent, new Roles(this.DatabaseSession).Sales.UserGroupWhereRole); var salesRepUserGroup = usergroups.First; this.DatabaseSession.Derive(true); Assert.AreEqual(1, salesRepUserGroup.Members.Count); Assert.Contains(new Persons(this.DatabaseSession).FindBy(Persons.Meta.LastName, "salesRep"), salesRepUserGroup.Members); var salesrep2 = new PersonBuilder(this.DatabaseSession).WithLastName("salesRep2").WithUserName("salesRep2").Build(); new EmploymentBuilder(this.DatabaseSession) .WithFromDate(DateTime.UtcNow) .WithEmployee(salesrep2) .WithEmployer(internalOrganisation) .Build(); new SalesRepRelationshipBuilder(this.DatabaseSession) .WithFromDate(DateTime.UtcNow) .WithCustomer(customer) .WithSalesRepresentative(salesrep2) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(2, salesRepUserGroup.Members.Count); Assert.IsTrue(salesRepUserGroup.Members.Contains(salesrep2)); }
public void GivenJournal_WhenBuildWithout_ThenCloseWhenInBalanceIsFalse() { var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.DatabaseSession) .WithAccountNumber("0001") .WithName("GeneralLedgerAccount") .WithBalanceSheetAccount(true) .Build(); var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.DatabaseSession) .WithInternalOrganisation(internalOrganisation) .WithGeneralLedgerAccount(generalLedgerAccount) .Build(); var journal = new JournalBuilder(this.DatabaseSession) .WithInternalOrganisation(internalOrganisation) .WithJournalType(new JournalTypes(this.DatabaseSession).Bank) .WithContraAccount(internalOrganisationGlAccount) .WithDescription("journal") .Build(); this.DatabaseSession.Derive(); Assert.IsFalse(journal.CloseWhenInBalance); }
public void GivenOrder_WhenDeriving_ThenLocaleMustExist() { var englischLocale = new Locales(this.DatabaseSession).EnglishGreatBritain; var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); ContactMechanism takenViaContactMechanism = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var supplierContactMechanism = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(takenViaContactMechanism) .WithUseAsDefault(true) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).OrderAddress) .Build(); supplier.AddPartyContactMechanism(supplierContactMechanism); var order = new PurchaseOrderBuilder(this.DatabaseSession) .WithTakenViaSupplier(supplier) .WithShipToBuyer(internalOrganisation) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(englischLocale, order.Locale); }
public void GivenOrder_WhenDeriving_ThenRequiredRelationsMustExist() { var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); ContactMechanism takenViaContactMechanism = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var supplierContactMechanism = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(takenViaContactMechanism) .WithUseAsDefault(true) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).OrderAddress) .Build(); supplier.AddPartyContactMechanism(supplierContactMechanism); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var builder = new PurchaseOrderBuilder(this.DatabaseSession); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithTakenViaSupplier(supplier); builder.Build(); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); builder.WithTakenViaContactMechanism(takenViaContactMechanism); builder.Build(); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); }
public void GivenEmployment_WhenEmploymentPeriodIsNotValid_ThenEmployeeIsNotInSalesRepUserGroup() { var salesRep = new Persons(this.DatabaseSession).FindBy(Persons.Meta.LastName, "salesRep"); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); var usergroups = internalOrganisation.UserGroupsWhereParty; usergroups.Filter.AddEquals(UserGroups.Meta.Parent, new Roles(this.DatabaseSession).Sales.UserGroupWhereRole); var salesRepUserGroup = usergroups.First; Assert.AreEqual(1, salesRepUserGroup.Members.Count); Assert.Contains(salesRep, salesRepUserGroup.Members); salesRep.EmploymentsWhereEmployee.First.FromDate = DateTime.UtcNow.AddDays(+1); salesRep.EmploymentsWhereEmployee.First.RemoveThroughDate(); this.DatabaseSession.Derive(true); Assert.AreEqual(0, salesRepUserGroup.Members.Count); salesRep.EmploymentsWhereEmployee.First.FromDate = DateTime.UtcNow; salesRep.EmploymentsWhereEmployee.First.RemoveThroughDate(); this.DatabaseSession.Derive(true); Assert.AreEqual(1, salesRepUserGroup.Members.Count); Assert.Contains(salesRep, salesRepUserGroup.Members); salesRep.EmploymentsWhereEmployee.First.FromDate = DateTime.UtcNow.AddDays(-2); salesRep.EmploymentsWhereEmployee.First.ThroughDate = DateTime.UtcNow.AddDays(-1); this.DatabaseSession.Derive(true); Assert.AreEqual(0, salesRepUserGroup.Members.Count); }
public void GivenOrganisation_WhenCurrentUserIsContactForOrganisation_ThenCustomerPermissionsAreGranted() { var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); var organisation = new OrganisationBuilder(this.DatabaseSession).WithName("organisation").Build(); var customer = new PersonBuilder(this.DatabaseSession).WithLastName("Customer").WithUserName("customer").Build(); new CustomerRelationshipBuilder(this.DatabaseSession).WithCustomer(organisation).WithInternalOrganisation(internalOrganisation).Build(); new OrganisationContactRelationshipBuilder(this.DatabaseSession).WithContact(customer).WithOrganisation(organisation).WithFromDate(DateTime.UtcNow).Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("customer", "Forms"), new string[0]); var acl = new AccessControlList(organisation, new Users(this.DatabaseSession).GetCurrentUser()); Assert.IsTrue(acl.CanRead(Organisations.Meta.Name)); Assert.IsTrue(acl.CanWrite(Organisations.Meta.Name)); Assert.IsTrue(acl.CanRead(Organisations.Meta.LegalForm)); Assert.IsTrue(acl.CanWrite(Organisations.Meta.LegalForm)); Assert.IsTrue(acl.CanRead(Organisations.Meta.LogoImage)); Assert.IsTrue(acl.CanWrite(Organisations.Meta.LogoImage)); Assert.IsTrue(acl.CanRead(Organisations.Meta.Locale)); Assert.IsTrue(acl.CanWrite(Organisations.Meta.Locale)); Assert.IsFalse(acl.CanRead(Organisations.Meta.OwnerSecurityToken)); Assert.IsFalse(acl.CanWrite(Organisations.Meta.OwnerSecurityToken)); }
public void GivenOwnCreditCardForInternalOrganisationThatDoesAccounting_WhenDeriving_ThenEitherGeneralLedgerAccountOrJournalMustExist() { var supplier = new OrganisationBuilder(this.DatabaseSession) .WithName("supplier") .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain) .Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); var supplierRelationship = new SupplierRelationshipBuilder(this.DatabaseSession) .WithSupplier(supplier) .WithInternalOrganisation(internalOrganisation) .WithFromDate(DateTime.UtcNow) .Build(); var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.DatabaseSession) .WithAccountNumber("0001") .WithName("GeneralLedgerAccount") .WithBalanceSheetAccount(true) .Build(); var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.DatabaseSession) .WithInternalOrganisation(internalOrganisation) .WithGeneralLedgerAccount(generalLedgerAccount) .Build(); var journal = new JournalBuilder(this.DatabaseSession).WithDescription("journal").Build(); var creditCard = new CreditCardBuilder(this.DatabaseSession) .WithCardNumber("4012888888881881") .WithExpirationYear(2016) .WithExpirationMonth(03) .WithNameOnCard("M.E. van Knippenberg") .WithCreditCardCompany(new CreditCardCompanyBuilder(this.DatabaseSession).WithName("Visa").Build()) .Build(); var paymentMethod = new OwnCreditCardBuilder(this.DatabaseSession) .WithCreditCard(creditCard) .WithCreditor(supplierRelationship) .Build(); this.DatabaseSession.Commit(); internalOrganisation.RemovePaymentMethods(); internalOrganisation.AddPaymentMethod(paymentMethod); internalOrganisation.DoAccounting = true; Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); paymentMethod.Journal = journal; Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); paymentMethod.RemoveJournal(); paymentMethod.GeneralLedgerAccount = internalOrganisationGlAccount; Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); }
public void GivenTimeEntry_WhenDeriving_ThenRequiredRelationsMustExist() { // Arrange var timeEntry = new TimeEntryBuilder(this.Session) .WithRateType(new RateTypes(this.Session).StandardRate) .Build(); // Act var derivation = this.Session.Derive(false); var originalCount = derivation.Errors.Count(); // Assert Assert.True(derivation.HasErrors); //// Re-arrange var tomorrow = DateTime.UtcNow.AddDays(1); timeEntry.ThroughDate = tomorrow; // Act derivation = this.Session.Derive(false); // Assert Assert.True(derivation.HasErrors); Assert.Equal(originalCount - 1, derivation.Errors.Count()); //// Re-arrange var workOrder = new WorkTaskBuilder(this.Session).WithName("Work").Build(); timeEntry.WorkEffort = workOrder; // Act derivation = this.Session.Derive(false); // Assert Assert.True(derivation.HasErrors); Assert.Equal(originalCount - 2, derivation.Errors.Count()); //// Re-arrange var worker = new PersonBuilder(this.Session).WithFirstName("Good").WithLastName("Worker").Build(); var organisation = new InternalOrganisations(this.Session).Extent().First; var employment = new EmploymentBuilder(this.Session).WithEmployee(worker).WithEmployer(organisation).Build(); derivation = this.Session.Derive(false); worker.TimeSheetWhereWorker.AddTimeEntry(timeEntry); // Act derivation = this.Session.Derive(false); // Assert Assert.False(derivation.HasErrors); }
public void GivenPerson_WhenSubContractor_ThenTimeSheetSynced() { var subContractor = new PersonBuilder(this.Session).WithFirstName("Sub").WithLastName("Contractor").Build(); var organisation = new InternalOrganisations(this.Session).Extent().First; var contractorRelation = new SubContractorRelationshipBuilder(this.Session).WithSubContractor(subContractor).Build(); contractorRelation.AddParty(organisation); this.Session.Derive(true); Assert.NotNull(subContractor.TimeSheetWhereWorker); }
public void GivenPartyWithOpenOrders_WhenDeriving_ThenOpenOrderAmountIsUpdated() { var organisation = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new CustomerRelationshipBuilder(this.DatabaseSession).WithCustomer(organisation).WithInternalOrganisation(internalOrganisation).Build(); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var postalAddress = new PostalAddressBuilder(this.DatabaseSession) .WithAddress1("Kleine Nieuwedijkstraat 2") .WithGeographicBoundary(mechelen) .Build(); var good = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build()) .WithName("good") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); this.DatabaseSession.Derive(true); var salesOrder1 = new SalesOrderBuilder(this.DatabaseSession).WithBillToCustomer(organisation).WithShipToAddress(postalAddress).WithComment("salesorder1").Build(); var orderItem1 = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(good) .WithQuantityOrdered(10) .WithActualUnitPrice(10) .Build(); salesOrder1.AddSalesOrderItem(orderItem1); var salesOrder2 = new SalesOrderBuilder(this.DatabaseSession).WithBillToCustomer(organisation).WithShipToAddress(postalAddress).WithComment("salesorder2").Build(); var orderItem2 = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(good) .WithQuantityOrdered(10) .WithActualUnitPrice(10) .Build(); salesOrder2.AddSalesOrderItem(orderItem2); var salesOrder3 = new SalesOrderBuilder(this.DatabaseSession).WithBillToCustomer(organisation).WithShipToAddress(postalAddress).WithComment("salesorder3").Build(); var orderItem3 = new SalesOrderItemBuilder(this.DatabaseSession) .WithProduct(good) .WithQuantityOrdered(10) .WithActualUnitPrice(10) .Build(); salesOrder3.AddSalesOrderItem(orderItem3); salesOrder3.Cancel(); this.DatabaseSession.Derive(true); Assert.AreEqual(242M, organisation.OpenOrderAmount); }
public void GivenPurchaseShipmentBuilder_WhenBuild_ThenPostBuildRelationsMustExist() { var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); var shipment = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(new PurchaseShipmentObjectStates(this.DatabaseSession).Created, shipment.CurrentObjectState); Assert.AreEqual(internalOrganisation, shipment.ShipToParty); Assert.AreEqual(internalOrganisation.ShippingAddress, shipment.ShipToAddress); Assert.AreEqual(shipment.ShipToParty, shipment.ShipToParty); }
public void GivenPerson_WhenEmployed_ThenTimeSheetSynced() { var person = new PersonBuilder(this.Session).WithFirstName("Good").WithLastName("Employee").Build(); var employer = new InternalOrganisations(this.Session).Extent().First; var employment = new EmploymentBuilder(this.Session) .WithEmployee(person) .WithFromDate(DateTime.UtcNow) .Build(); this.Session.Derive(); Assert.NotNull(person.TimeSheetWhereWorker); }
public void GivenCashPaymentMethodForInternalOrganisationThatDoesAccounting_WhenDeriving_ThenEitherGeneralLedgerAccountOrJournalMustExist() { var supplier = new OrganisationBuilder(this.DatabaseSession) .WithName("supplier") .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain) .Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); var supplierRelationship = new SupplierRelationshipBuilder(this.DatabaseSession) .WithSupplier(supplier) .WithInternalOrganisation(internalOrganisation) .WithFromDate(DateTime.UtcNow) .Build(); var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.DatabaseSession) .WithAccountNumber("0001") .WithName("GeneralLedgerAccount") .WithBalanceSheetAccount(true) .Build(); var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.DatabaseSession) .WithInternalOrganisation(internalOrganisation) .WithGeneralLedgerAccount(generalLedgerAccount) .Build(); var journal = new JournalBuilder(this.DatabaseSession).WithDescription("journal").Build(); this.DatabaseSession.Commit(); var cash = new CashBuilder(this.DatabaseSession) .WithDescription("description") .WithCreditor(supplierRelationship) .Build(); internalOrganisation.RemovePaymentMethods(); internalOrganisation.AddPaymentMethod(cash); internalOrganisation.DoAccounting = true; Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); cash.Journal = journal; Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); cash.RemoveJournal(); cash.GeneralLedgerAccount = internalOrganisationGlAccount; Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); }
public void GivenTimeEntryWithRequiredAssignmentOrganisation_WhenDeriving_ThenWorkEffortPartyAssignmentSynced() { // Arrange var workOrder = new WorkTaskBuilder(this.Session).WithName("Task").Build(); var organisation = new InternalOrganisations(this.Session).Extent().First; var employee = new PersonBuilder(this.Session).WithFirstName("Good").WithLastName("Worker").Build(); var employment = new EmploymentBuilder(this.Session).WithEmployee(employee).WithEmployer(organisation).Build(); organisation.RequireExistingWorkEffortPartyAssignment = true; this.Session.Derive(true); var today = DateTimeFactory.CreateDateTime(DateTime.UtcNow); var tomorrow = DateTimeFactory.CreateDateTime(DateTime.UtcNow.AddDays(1)); var hour = new TimeFrequencies(this.Session).Hour; var timeEntry = new TimeEntryBuilder(this.Session) .WithRateType(new RateTypes(this.Session).StandardRate) .WithFromDate(today) .WithThroughDate(tomorrow) .WithTimeFrequency(hour) .WithWorkEffort(workOrder) .Build(); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntry); // Act var derivation = this.Session.Derive(false); // Assert Assert.True(derivation.HasErrors); Assert.Contains(derivation.Errors.SelectMany(e => e.Relations), r => r.AssociationType.Equals(M.WorkEffort.WorkEffortPartyAssignmentsWhereAssignment)); //// Re-Arrange employee.TimeSheetWhereWorker.RemoveTimeEntries(); var assignment = new WorkEffortPartyAssignmentBuilder(this.Session) .WithAssignment(workOrder) .WithParty(employee) .Build(); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntry); // Act derivation = this.Session.Derive(false); // Assert Assert.True(derivation.HasErrors); }
public void GivenNewGoodCoredOnFinishedGood_WhenDeriving_ThenNonSerializedInventryItemIsCreatedForEveryFinishedGoodAndFacility() { var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); var secondFacility = new WarehouseBuilder(this.DatabaseSession).WithName("second facility").WithOwner(internalOrganisation).Build(); new SupplierRelationshipBuilder(this.DatabaseSession) .WithInternalOrganisation(internalOrganisation) .WithSupplier(supplier) .WithFromDate(DateTime.UtcNow) .Build(); var finishedGood = new FinishedGoodBuilder(this.DatabaseSession) .WithName("part") .Build(); var purchasePrice = new ProductPurchasePriceBuilder(this.DatabaseSession) .WithFromDate(DateTime.UtcNow) .WithCurrency(new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR")) .WithPrice(1) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); var good = new GoodBuilder(this.DatabaseSession) .WithName("Good") .WithSku("10101") .WithFinishedGood(finishedGood) .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build()) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); new SupplierOfferingBuilder(this.DatabaseSession) .WithProduct(good) .WithSupplier(supplier) .WithProductPurchasePrice(purchasePrice) .WithFromDate(DateTime.UtcNow) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(2, good.FinishedGood.InventoryItemsWherePart.Count); Assert.AreEqual(1, internalOrganisation.DefaultFacility.InventoryItemsWhereFacility.Count); Assert.AreEqual(1, secondFacility.InventoryItemsWhereFacility.Count); }
public void GivenShipmentReceiptForGoodWithoutSelectedInventoryItemWhenDerivingThenInventoryItemIsFromDefaultFacility() { var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); var good = new GoodBuilder(this.DatabaseSession) .WithName("Good") .WithSku("10101") .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build()) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); var order = new PurchaseOrderBuilder(this.DatabaseSession).WithTakenViaSupplier(supplier).Build(); var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantityOrdered(1).Build(); order.AddPurchaseOrderItem(item1); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); order.Confirm(); var shipment = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build(); var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithGood(good).Build(); shipment.AddShipmentItem(shipmentItem); var receipt = new ShipmentReceiptBuilder(this.DatabaseSession) .WithQuantityAccepted(1M) .WithShipmentItem(shipmentItem) .WithOrderItem(item1) .Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); shipment.AppsComplete(); Assert.AreEqual(new Warehouses(this.DatabaseSession).FindBy(Warehouses.Meta.Name, "facility"), receipt.InventoryItem.Facility); Assert.AreEqual(good.InventoryItemsWhereGood[0], receipt.InventoryItem); this.DatabaseSession.Rollback(); }
public void GivenStore_WhenBuild_ThenPostBuildRelationsMustExist() { var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); var store = new StoreBuilder(this.DatabaseSession) .WithName("Organisation store") .WithDefaultCarrier(new Carriers(this.DatabaseSession).Fedex) .WithDefaultShipmentMethod(new ShipmentMethods(this.DatabaseSession).Ground) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(0, store.CreditLimit); Assert.AreEqual(0, store.PaymentGracePeriod); Assert.AreEqual(0, store.ShipmentThreshold); Assert.AreEqual(internalOrganisation, store.Owner); Assert.AreEqual(internalOrganisation.DefaultPaymentMethod, store.DefaultPaymentMethod); Assert.AreEqual(1, store.PaymentMethods.Count); Assert.AreEqual(new Warehouses(this.DatabaseSession).FindBy(Warehouses.Meta.Name, "facility"), store.DefaultFacility); }
public void GivenOrganisationGlAccount_WhenBuild_ThenHasBankStatementTransactionsIsAlwaysFalse() { var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.DatabaseSession) .WithAccountNumber("0001") .WithName("GeneralLedgerAccount") .WithBalanceSheetAccount(true) .WithSide(new DebitCreditConstants(this.DatabaseSession).Debit) .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.DatabaseSession).WithDescription("accountType").Build()) .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.DatabaseSession).WithDescription("accountGroup").Build()) .Build(); var organisationGlAccount = new OrganisationGlAccountBuilder(this.DatabaseSession) .WithInternalOrganisation(internalOrganisation) .WithGeneralLedgerAccount(generalLedgerAccount) .Build(); this.DatabaseSession.Derive(); Assert.IsFalse(organisationGlAccount.HasBankStatementTransactions); }
public void GivenShipmentReceiptWhenValidatingThenRequiredRelationsMustExist() { var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); var good = new GoodBuilder(this.DatabaseSession) .WithName("Good") .WithSku("10101") .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build()) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); var inventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good).Build(); inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(100).WithReason(new VarianceReasons(this.DatabaseSession).Order).Build()); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var builder = new ShipmentReceiptBuilder(this.DatabaseSession); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithInventoryItem(inventoryItem); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); var shipment = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build(); var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithGood(good).Build(); shipment.AddShipmentItem(shipmentItem); builder.WithShipmentItem(shipmentItem); builder.Build(); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); }
public void GivenShipmentReceiptWhenDerivingThenOrderItemQuantityReceivedIsUpdated() { var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); var good = new GoodBuilder(this.DatabaseSession) .WithName("Good") .WithSku("10101") .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build()) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); var order = new PurchaseOrderBuilder(this.DatabaseSession).WithTakenViaSupplier(supplier).Build(); var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantityOrdered(10).Build(); order.AddPurchaseOrderItem(item1); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); order.Confirm(); var shipment = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build(); var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithGood(good).Build(); shipment.AddShipmentItem(shipmentItem); new ShipmentReceiptBuilder(this.DatabaseSession) .WithQuantityAccepted(10) .WithShipmentItem(shipmentItem) .WithOrderItem(item1) .Build(); shipment.AppsComplete(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); Assert.AreEqual(10, item1.QuantityReceived); this.DatabaseSession.Rollback(); }
public void GivenShipmentReceiptWhenDerivingThenInventoryItemQuantityOnHandIsUpdated() { var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var mechelenAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var shipToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(mechelenAddress) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).ShippingAddress) .WithUseAsDefault(true) .Build(); var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").WithPartyContactMechanism(shipToMechelen).Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build(); var good = new GoodBuilder(this.DatabaseSession) .WithName("Good") .WithSku("10101") .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build()) .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); var inventoryItem = new NonSerializedInventoryItemBuilder(this.DatabaseSession).WithGood(good).Build(); inventoryItem.AddInventoryItemVariance(new InventoryItemVarianceBuilder(this.DatabaseSession).WithQuantity(20).WithReason(new VarianceReasons(this.DatabaseSession).Unknown).Build()); this.DatabaseSession.Derive(true); var order1 = new SalesOrderBuilder(this.DatabaseSession) .WithBillToCustomer(customer) .WithShipToCustomer(customer) .WithDeliveryDate(DateTime.UtcNow) .Build(); var salesItem = new SalesOrderItemBuilder(this.DatabaseSession).WithDescription("item1").WithProduct(good).WithQuantityOrdered(30).WithActualUnitPrice(15).Build(); order1.AddSalesOrderItem(salesItem); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); order1.Confirm(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var sessionInventoryItem = (NonSerializedInventoryItem)this.DatabaseSession.Instantiate(inventoryItem); var sessionSalesItem = (SalesOrderItem)this.DatabaseSession.Instantiate(salesItem); var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); Assert.AreEqual(20, sessionSalesItem.QuantityPendingShipment); Assert.AreEqual(30, sessionSalesItem.QuantityReserved); Assert.AreEqual(10, sessionSalesItem.QuantityShortFalled); var order = new PurchaseOrderBuilder(this.DatabaseSession).WithTakenViaSupplier(supplier).Build(); var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantityOrdered(10).Build(); order.AddPurchaseOrderItem(item1); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); order.Confirm(); var shipment = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build(); var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithGood(good).Build(); shipment.AddShipmentItem(shipmentItem); new ShipmentReceiptBuilder(this.DatabaseSession) .WithQuantityAccepted(10) .WithShipmentItem(shipmentItem) .WithOrderItem(item1) .Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); shipment.AppsComplete(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); Assert.AreEqual(30, sessionInventoryItem.QuantityOnHand); Assert.AreEqual(30, sessionSalesItem.QuantityPendingShipment); Assert.AreEqual(30, sessionSalesItem.QuantityReserved); Assert.AreEqual(0, sessionSalesItem.QuantityShortFalled); }
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 GivenPurchaseOrder_WhenShipmentIsReceived_ThenCurrenShipmentStatusIsUpdated() { var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); var part = new RawMaterialBuilder(this.DatabaseSession).WithName("RawMaterial").Build(); var order = new PurchaseOrderBuilder(this.DatabaseSession) .WithTakenViaSupplier(supplier) .WithBillToPurchaser(internalOrganisation) .WithVatRegime(new VatRegimes(this.DatabaseSession).Exempt) .Build(); var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(1).Build(); var item2 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(2).Build(); var item3 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(3).Build(); order.AddPurchaseOrderItem(item1); order.AddPurchaseOrderItem(item2); order.AddPurchaseOrderItem(item3); this.DatabaseSession.Derive(true); order.Confirm(); this.DatabaseSession.Derive(true); var shipment1 = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build(); var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithPart(part).Build(); shipment1.AddShipmentItem(shipmentItem); new ShipmentReceiptBuilder(this.DatabaseSession) .WithQuantityAccepted(1) .WithShipmentItem(shipmentItem) .WithOrderItem(item1) .Build(); shipment1.AppsComplete(); this.DatabaseSession.Derive(true); Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).Received, item1.CurrentShipmentStatus.PurchaseOrderItemObjectState); Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).PartiallyReceived, order.CurrentShipmentStatus.PurchaseOrderObjectState); Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).InProcess, order.CurrentOrderStatus.PurchaseOrderObjectState); var shipment2 = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build(); shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithPart(part).Build(); shipment2.AddShipmentItem(shipmentItem); new ShipmentReceiptBuilder(this.DatabaseSession) .WithQuantityAccepted(2) .WithShipmentItem(shipmentItem) .WithOrderItem(item2) .Build(); shipment2.AppsComplete(); this.DatabaseSession.Derive(true); Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).Received, item2.CurrentShipmentStatus.PurchaseOrderItemObjectState); Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).PartiallyReceived, order.CurrentShipmentStatus.PurchaseOrderObjectState); Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).InProcess, order.CurrentOrderStatus.PurchaseOrderObjectState); var shipment3 = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build(); shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithPart(part).Build(); shipment3.AddShipmentItem(shipmentItem); new ShipmentReceiptBuilder(this.DatabaseSession) .WithQuantityAccepted(3) .WithShipmentItem(shipmentItem) .WithOrderItem(item3) .Build(); shipment3.AppsComplete(); this.DatabaseSession.Derive(true); Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).Received, item3.CurrentShipmentStatus.PurchaseOrderItemObjectState); Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).Received, order.CurrentShipmentStatus.PurchaseOrderObjectState); Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).Completed, order.CurrentOrderStatus.PurchaseOrderObjectState); }
public void GivenPurchaseOrder_WhenOrdering_ThenAllValidItemsAreInInProcessState() { var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); var part = new RawMaterialBuilder(this.DatabaseSession).WithName("RawMaterial").Build(); var order = new PurchaseOrderBuilder(this.DatabaseSession) .WithTakenViaSupplier(supplier) .WithVatRegime(new VatRegimes(this.DatabaseSession).Exempt) .Build(); var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(1).Build(); var item2 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(2).Build(); var item3 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(3).Build(); order.AddPurchaseOrderItem(item1); order.AddPurchaseOrderItem(item2); order.AddPurchaseOrderItem(item3); this.DatabaseSession.Derive(true); order.Confirm(); this.DatabaseSession.Derive(true); Assert.AreEqual(3, order.ValidOrderItems.Count); Assert.Contains(item1, order.ValidOrderItems); Assert.Contains(item2, order.ValidOrderItems); Assert.Contains(item3, order.ValidOrderItems); Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).InProcess, item1.CurrentObjectState); Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).InProcess, item2.CurrentObjectState); Assert.AreEqual(new PurchaseOrderItemObjectStates(this.DatabaseSession).InProcess, item3.CurrentObjectState); }
public void GivenPurchaseOrder_WhenDeriving_ThenTakenViaSupplierMustBeInSupplierRelationship() { var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new PurchaseOrderBuilder(this.DatabaseSession) .WithTakenViaSupplier(supplier) .WithBillToPurchaser(internalOrganisation) .Build(); var expectedError = ErrorMessages.PartyIsNotASupplier; Assert.AreEqual(expectedError, this.DatabaseSession.Derive().Errors[0].Message); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); }
public void GivenPurchaseOrderCreatedByProcurementLevel1Role_WhenCurrentUserInSameProcurementLevel1RoleUserGroup_ThenAccessIsGranted() { var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); var purchaser2 = new PersonBuilder(this.DatabaseSession).WithLastName("purchaser2").WithUserName("purchaser2").Build(); new EmploymentBuilder(this.DatabaseSession) .WithFromDate(DateTime.UtcNow) .WithEmployee(purchaser2) .WithEmployer(internalOrganisation) .Build(); var usergroups = internalOrganisation.UserGroupsWhereParty; var userGroup = usergroups.First; userGroup.AddMember(purchaser2); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("purchaser", "Forms"), new string[0]); var order = new PurchaseOrderBuilder(this.DatabaseSession).WithTakenViaSupplier(supplier).Build(); this.DatabaseSession.Derive(true); var acl = new AccessControlList(order, new Users(this.DatabaseSession).GetCurrentUser()); Assert.IsTrue(acl.CanWrite(SalesOrders.Meta.Comment)); Assert.IsTrue(acl.CanRead(SalesOrders.Meta.Comment)); Assert.IsTrue(acl.CanExecute(PurchaseOrders.Meta.Confirm)); Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("purchaser2", "Forms"), new string[0]); acl = new AccessControlList(order, new Users(this.DatabaseSession).GetCurrentUser()); Assert.IsTrue(acl.CanWrite(PurchaseOrders.Meta.Comment)); Assert.IsTrue(acl.CanRead(PurchaseOrders.Meta.Comment)); Assert.IsTrue(acl.CanExecute(PurchaseOrders.Meta.Confirm)); }
public void GivenPurchaseOrderBuilder_WhenBuild_ThenPostBuildRelationsMustExist() { var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); var order = new PurchaseOrderBuilder(this.DatabaseSession).WithTakenViaSupplier(supplier).Build(); Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).Provisional, order.CurrentObjectState); Assert.AreEqual(DateTime.UtcNow.Date, order.OrderDate.Date); Assert.AreEqual(DateTime.UtcNow.Date, order.EntryDate.Date); Assert.AreEqual(order.PreviousTakenViaSupplier, order.TakenViaSupplier); Assert.AreEqual(internalOrganisation, order.ShipToBuyer); Assert.AreEqual(internalOrganisation, order.BillToPurchaser); Assert.AreEqual(order.ShipToBuyer.PreferredCurrency, order.CustomerCurrency); Assert.IsTrue(order.ExistUniqueId); }
public void GivenSalesOrder_WhenDeriving_ThenDerivedSalesRepMustExist() { var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var customer = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build(); var salesrep = new PersonBuilder(this.DatabaseSession).WithLastName("salesrep").Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new CustomerRelationshipBuilder(this.DatabaseSession) .WithCustomer(customer) .WithInternalOrganisation(internalOrganisation) .WithFromDate(DateTime.UtcNow) .Build(); new SalesRepRelationshipBuilder(this.DatabaseSession) .WithFromDate(DateTime.UtcNow) .WithCustomer(customer) .WithSalesRepresentative(salesrep) .Build(); var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build(); var part1 = new FinishedGoodBuilder(this.DatabaseSession).WithName("part1").Build(); var good1 = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(vatRate21) .WithName("good1") .WithFinishedGood(part1) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); this.DatabaseSession.Derive(true); var order = new SalesOrderBuilder(this.DatabaseSession) .WithShipToCustomer(customer) .WithShipToAddress(new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build()) .Build(); order.AddSalesOrderItem(new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(good1).WithQuantityOrdered(1).WithActualUnitPrice(10).Build()); this.DatabaseSession.Derive(true); Assert.Contains(salesrep, order.SalesReps); }
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 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 GivenShipmentReceiptForPartWithoutSelectedInventoryItemWhenDerivingThenInventoryItemIsFromDefaultFacility() { var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); var part = new RawMaterialBuilder(this.DatabaseSession) .WithName("RawMaterial") .Build(); var order = new PurchaseOrderBuilder(this.DatabaseSession) .WithTakenViaSupplier(supplier) .WithVatRegime(new VatRegimes(this.DatabaseSession).Export) .Build(); var item1 = new PurchaseOrderItemBuilder(this.DatabaseSession).WithPart(part).WithQuantityOrdered(1).Build(); order.AddPurchaseOrderItem(item1); this.DatabaseSession.Derive(true); order.Confirm(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); var shipment = new PurchaseShipmentBuilder(this.DatabaseSession).WithShipFromParty(supplier).Build(); var shipmentItem = new ShipmentItemBuilder(this.DatabaseSession).WithPart(part).Build(); shipment.AddShipmentItem(shipmentItem); var receipt = new ShipmentReceiptBuilder(this.DatabaseSession) .WithQuantityAccepted(1M) .WithShipmentItem(shipmentItem) .WithOrderItem(item1) .Build(); shipment.AppsComplete(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); Assert.AreEqual(new Warehouses(this.DatabaseSession).FindBy(Warehouses.Meta.Name, "facility"), receipt.InventoryItem.Facility); Assert.AreEqual(part.InventoryItemsWherePart[0], receipt.InventoryItem); this.DatabaseSession.Rollback(); }
public void GivenPurchaseOrder_WhenObjectStateIsOnHold_ThenCheckTransitions() { Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("orderProcessor", "Forms"), new string[0]); var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); var order = new PurchaseOrderBuilder(this.DatabaseSession) .WithTakenViaSupplier(supplier) .WithBillToPurchaser(internalOrganisation) .Build(); order.Confirm(); this.DatabaseSession.Derive(true); order.Hold(); this.DatabaseSession.Derive(true); Assert.AreEqual(new PurchaseOrderObjectStates(this.DatabaseSession).OnHold, order.CurrentObjectState); var acl = new AccessControlList(order, new Users(this.DatabaseSession).GetCurrentUser()); Assert.IsTrue(acl.CanExecute(PurchaseOrders.Meta.Cancel)); Assert.IsTrue(acl.CanExecute(PurchaseOrders.Meta.Continue)); Assert.IsFalse(acl.CanExecute(PurchaseOrders.Meta.Confirm)); Assert.IsFalse(acl.CanExecute(PurchaseOrders.Meta.Reject)); Assert.IsFalse(acl.CanExecute(PurchaseOrders.Meta.Approve)); Assert.IsFalse(acl.CanExecute(PurchaseOrders.Meta.Hold)); }
public override void Init() { base.Init(); var euro = new Currencies(this.DatabaseSession).FindBy(Currencies.Meta.IsoCode, "EUR"); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); ContactMechanism takenViaContactMechanism = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var supplierContactMechanism = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(takenViaContactMechanism) .WithUseAsDefault(true) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).BillingAddress) .Build(); var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation"); this.supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build(); this.supplier.AddPartyContactMechanism(supplierContactMechanism); new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build(); this.finishedGood = new FinishedGoodBuilder(this.DatabaseSession) .WithManufacturerId("10101") .WithName("finished good") .Build(); var supplierOffering = new SupplierOfferingBuilder(this.DatabaseSession) .WithPart(this.finishedGood) .WithSupplier(this.supplier) .WithFromDate(DateTime.UtcNow.AddYears(-1)) .Build(); var previousPurchasePrice = new ProductPurchasePriceBuilder(this.DatabaseSession) .WithCurrency(euro) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithFromDate(DateTime.UtcNow.AddYears(-1)) .WithThroughDate(DateTime.UtcNow.AddDays(-1)) .WithPrice(8) .Build(); this.currentPurchasePrice = new ProductPurchasePriceBuilder(this.DatabaseSession) .WithCurrency(euro) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithFromDate(DateTime.UtcNow) .WithThroughDate(DateTime.UtcNow.AddYears(1).AddDays(-1)) .WithPrice(10) .Build(); var futurePurchasePrice = new ProductPurchasePriceBuilder(this.DatabaseSession) .WithCurrency(euro) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .WithFromDate(DateTime.UtcNow.AddYears(1)) .WithPrice(8) .Build(); supplierOffering.AddProductPurchasePrice(previousPurchasePrice); supplierOffering.AddProductPurchasePrice(this.currentPurchasePrice); supplierOffering.AddProductPurchasePrice(futurePurchasePrice); this.order = new PurchaseOrderBuilder(this.DatabaseSession) .WithTakenViaSupplier(this.supplier) .WithBillToContactMechanism(takenViaContactMechanism) .WithDeliveryDate(DateTime.UtcNow) .WithVatRegime(new VatRegimes(this.DatabaseSession).Exempt) .Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); }
public void 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); }