public void GivenCustomerRelationshipBuilder_WhenBuild_ThenSubAccountNumerIsValidElevenTestNumber() { var internalOrganisation = Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation; internalOrganisation.SubAccountCounter.Value = 1000; this.DatabaseSession.Commit(); var customer1 = new PersonBuilder(this.DatabaseSession).WithLastName("customer1").Build(); var customerRelationship1 = new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer1).Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(1007, customerRelationship1.SubAccountNumber); var customer2 = new PersonBuilder(this.DatabaseSession).WithLastName("customer2").Build(); var customerRelationship2 = new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(1015, customerRelationship2.SubAccountNumber); var customer3 = new PersonBuilder(this.DatabaseSession).WithLastName("customer3").Build(); var customerRelationship3 = new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer3).Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(1023, customerRelationship3.SubAccountNumber); }
public void GivenPartyWithOpenOrders_WhenDeriving_ThenOpenOrderAmountIsUpdated() { var store = this.Session.Extent <Store>().First; store.IsImmediatelyPicked = false; var organisation = new OrganisationBuilder(this.Session).WithName("customer").Build(); var customerRelationship = new CustomerRelationshipBuilder(this.Session).WithCustomer(organisation).Build(); this.Session.Derive(); var partyFinancial = organisation.PartyFinancialRelationshipsWhereParty.First(v => Equals(v.InternalOrganisation, customerRelationship.InternalOrganisation)); var mechelen = new CityBuilder(this.Session).WithName("Mechelen").Build(); var postalAddress = new PostalAddressBuilder(this.Session) .WithAddress1("Kleine Nieuwedijkstraat 2") .WithPostalAddressBoundary(mechelen) .Build(); var good = new Goods(this.Session).FindBy(M.Good.Name, "good1"); this.Session.Derive(); var salesOrder1 = new SalesOrderBuilder(this.Session).WithBillToCustomer(organisation).WithShipToAddress(postalAddress).WithComment("salesorder1").Build(); var orderItem1 = new SalesOrderItemBuilder(this.Session) .WithProduct(good) .WithQuantityOrdered(10) .WithAssignedUnitPrice(10) .Build(); salesOrder1.AddSalesOrderItem(orderItem1); this.Session.Derive(); var salesOrder2 = new SalesOrderBuilder(this.Session).WithBillToCustomer(organisation).WithShipToAddress(postalAddress).WithComment("salesorder2").Build(); var orderItem2 = new SalesOrderItemBuilder(this.Session) .WithProduct(good) .WithQuantityOrdered(10) .WithAssignedUnitPrice(10) .Build(); salesOrder2.AddSalesOrderItem(orderItem2); this.Session.Derive(); var salesOrder3 = new SalesOrderBuilder(this.Session).WithBillToCustomer(organisation).WithShipToAddress(postalAddress).WithComment("salesorder3").Build(); var orderItem3 = new SalesOrderItemBuilder(this.Session) .WithProduct(good) .WithQuantityOrdered(10) .WithAssignedUnitPrice(10) .Build(); salesOrder3.AddSalesOrderItem(orderItem3); salesOrder3.Cancel(); this.Session.Derive(); Assert.Equal(242M, partyFinancial.OpenOrderAmount); }
public void Edit() { var allors = new Organisations(this.Session).FindBy(M.Organisation.Name, "Allors BVBA"); var people = new People(this.Session).Extent(); var person = people.First(v => v.PartyName.Equals("John0 Doe0")); var editPartyRelationship = new CustomerRelationshipBuilder(this.Session) .WithCustomer(person) .WithInternalOrganisation(allors) .Build(); this.Session.Derive(); this.Session.Commit(); var before = new PartyRelationships(this.Session).Extent().ToArray(); var personOverview = this.personListPage.Select(person); var page = personOverview.SelectPartyRelationship(editPartyRelationship); page.FromDate.Set(DateTimeFactory.CreateDate(2018, 12, 22)) .ThroughDate.Set(DateTimeFactory.CreateDate(2018, 12, 22).AddYears(1)) .Save.Click(); this.Driver.WaitForAngular(); this.Session.Rollback(); var after = new PartyRelationships(this.Session).Extent().ToArray(); Assert.Equal(after.Length, before.Length); //Assert.Equal(DateTimeFactory.CreateDate(2018, 12, 22).Date, this.editPartyRelationship.FromDate.Date.ToUniversalTime().Date); //Assert.Equal(DateTimeFactory.CreateDate(2018, 12, 22).AddYears(1).Date, this.editPartyRelationship.ThroughDate.Value.Date.ToUniversalTime().Date); }
public void GivenCustomerWithUnpaidInvoices_WhenDeriving_ThenAmountOverDueIsUpdated() { var mechelen = new CityBuilder(this.Session).WithName("Mechelen").Build(); var customer = new PersonBuilder(this.Session).WithLastName("customer").Build(); var customerRelationship = new CustomerRelationshipBuilder(this.Session).WithFromDate(DateTime.UtcNow.AddDays(-31)).WithCustomer(customer).Build(); Session.Derive(); var partyFinancial = customer.PartyFinancialRelationshipsWhereParty.First(v => Equals(v.InternalOrganisation, customerRelationship.InternalOrganisation)); var billToContactMechanism = new PostalAddressBuilder(this.Session).WithGeographicBoundary(mechelen).WithAddress1("Mechelen").Build(); var good = new Goods(this.Session).FindBy(M.Good.Name, "good1"); good.VatRate = new VatRateBuilder(this.Session).WithRate(0).Build(); this.Session.Derive(); var invoice1 = new SalesInvoiceBuilder(this.Session) .WithSalesInvoiceType(new SalesInvoiceTypes(this.Session).SalesInvoice) .WithBillToCustomer(customer) .WithBillToContactMechanism(billToContactMechanism) .WithInvoiceDate(DateTime.UtcNow.AddDays(-30)) .WithSalesInvoiceItem(new SalesInvoiceItemBuilder(this.Session).WithProduct(good).WithQuantity(1).WithActualUnitPrice(100M).WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem).Build()) .Build(); this.Session.Derive(); var invoice2 = new SalesInvoiceBuilder(this.Session) .WithSalesInvoiceType(new SalesInvoiceTypes(this.Session).SalesInvoice) .WithBillToCustomer(customer) .WithBillToContactMechanism(billToContactMechanism) .WithInvoiceDate(DateTime.UtcNow.AddDays(-5)) .WithSalesInvoiceItem(new SalesInvoiceItemBuilder(this.Session).WithProduct(good).WithQuantity(1).WithActualUnitPrice(200M).WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem).Build()) .Build(); this.Session.Derive(); Assert.Equal(100M, partyFinancial.AmountOverDue); new ReceiptBuilder(this.Session) .WithAmount(20) .WithPaymentApplication(new PaymentApplicationBuilder(this.Session).WithInvoiceItem(invoice1.SalesInvoiceItems[0]).WithAmountApplied(20).Build()) .Build(); this.Session.Derive(); Assert.Equal(80, partyFinancial.AmountOverDue); invoice2.InvoiceDate = DateTime.UtcNow.AddDays(-10); this.Session.Derive(); Assert.Equal(280, partyFinancial.AmountOverDue); }
public void GivenCustomerRelationship_WhenDerivingWithout_ThenAmountOverDueIsZero() { var customer = new PersonBuilder(this.Session).WithLastName("customer").Build(); var customerRelationship = new CustomerRelationshipBuilder(this.Session).WithFromDate(DateTime.UtcNow).WithCustomer(customer).Build(); this.Session.Derive(); var partyFinancial = customer.PartyFinancialRelationshipsWhereParty.First(v => Equals(v.InternalOrganisation, customerRelationship.InternalOrganisation)); Assert.Equal(0, partyFinancial.AmountOverDue); }
public void GivenInternalOrganisation_ActiveCustomers_AreDerived() { var internalOrganisation = this.InternalOrganisation; var activeCustomersBefore = this.InternalOrganisation.ActiveCustomers.Count; var acme = new OrganisationBuilder(this.Session).WithName("Acme").Build(); var nike = new OrganisationBuilder(this.Session).WithName("Nike").Build(); var acmeRelation = new CustomerRelationshipBuilder(this.Session) .WithInternalOrganisation(internalOrganisation).WithCustomer(acme) .WithFromDate(this.Session.Now().AddDays(-10)) .Build(); var nikeRelation = new CustomerRelationshipBuilder(this.Session) .WithInternalOrganisation(internalOrganisation) .WithCustomer(nike) .Build(); this.Session.Derive(); Assert.True(this.InternalOrganisation.ExistCustomerRelationshipsWhereInternalOrganisation); Assert.True(this.InternalOrganisation.ExistActiveCustomers); Assert.Equal(activeCustomersBefore + 2, this.InternalOrganisation.ActiveCustomers.Count); // Removing will not do anything. ((OrganisationDerivedRoles)this.InternalOrganisation).RemoveActiveCustomers(); this.Session.Derive(); Assert.True(this.InternalOrganisation.ExistActiveCustomers); Assert.Equal(activeCustomersBefore + 2, this.InternalOrganisation.ActiveCustomers.Count); // Ending a RelationShip affects the ActiveCustomers acmeRelation.ThroughDate = this.Session.Now().AddDays(-1).Date; this.Session.Derive(); Assert.True(this.InternalOrganisation.ExistCustomerRelationshipsWhereInternalOrganisation); Assert.True(this.InternalOrganisation.ExistActiveCustomers); Assert.Equal(activeCustomersBefore + 1, this.InternalOrganisation.ActiveCustomers.Count); }
public void GivenCustomerRelationship_WhenDeriving_ThenSubAccountNumberMustBeUniqueWithinSingleton() { var customer2 = new OrganisationBuilder(this.Session).WithName("customer").Build(); var belgium = new Countries(this.Session).CountryByIsoCode["BE"]; var euro = belgium.Currency; var bank = new BankBuilder(this.Session).WithCountry(belgium).WithName("ING België").WithBic("BBRUBEBB").Build(); var ownBankAccount = new OwnBankAccountBuilder(this.Session) .WithDescription("BE23 3300 6167 6391") .WithBankAccount(new BankAccountBuilder(this.Session).WithBank(bank).WithCurrency(euro).WithIban("BE23 3300 6167 6391").WithNameOnAccount("Koen").Build()) .Build(); var mechelen = new CityBuilder(this.Session).WithName("Mechelen").Build(); var address1 = new PostalAddressBuilder(this.Session).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var internalOrganisation2 = new OrganisationBuilder(this.Session) .WithIsInternalOrganisation(true) .WithDoAccounting(true) .WithName("internalOrganisation2") .WithDefaultCollectionMethod(ownBankAccount) .WithSubAccountCounter(new CounterBuilder(this.Session).WithUniqueId(Guid.NewGuid()).WithValue(0).Build()) .Build(); var customerRelationship2 = new CustomerRelationshipBuilder(this.Session) .WithCustomer(customer2) .WithInternalOrganisation(internalOrganisation2) .WithFromDate(DateTime.UtcNow) .Build(); Session.Derive(); var partyFinancial = customer2.PartyFinancialRelationshipsWhereParty.First(v => Equals(v.InternalOrganisation, customerRelationship2.InternalOrganisation)); partyFinancial.SubAccountNumber = 19; Assert.False(this.Session.Derive(false).HasErrors); }
public void Edit() { var allors = new Organisations(this.Session).FindBy(M.Organisation.Name, "Allors BVBA"); var person = new People(this.Session).Extent().First; var editPartyRelationship = new CustomerRelationshipBuilder(this.Session) .WithCustomer(person) .WithInternalOrganisation(allors) .Build(); this.Session.Derive(); this.Session.Commit(); var before = new PartyRelationships(this.Session).Extent().ToArray(); this.personListPage.Table.DefaultAction(person); var personOverview = new PersonOverviewComponent(this.personListPage.Driver); var partyRelationshipOverview = personOverview.PartyrelationshipOverviewPanel.Click(); partyRelationshipOverview.Table.DefaultAction(editPartyRelationship); var customerRelationshipEditComponent = new CustomerRelationshipEditComponent(this.Driver); customerRelationshipEditComponent.FromDate.Set(DateTimeFactory.CreateDate(2018, 12, 22)) .ThroughDate.Set(DateTimeFactory.CreateDate(2018, 12, 22).AddYears(1)) .SAVE.Click(); this.Driver.WaitForAngular(); this.Session.Rollback(); var after = new PartyRelationships(this.Session).Extent().ToArray(); Assert.Equal(after.Length, before.Length); // Assert.Equal(DateTimeFactory.CreateDate(2018, 12, 22).Date, this.editPartyRelationship.FromDate.Date.ToUniversalTime().Date); // Assert.Equal(DateTimeFactory.CreateDate(2018, 12, 22).AddYears(1).Date, this.editPartyRelationship.ThroughDate.Value.Date.ToUniversalTime().Date); }
public void GivenCustomerRelationshipBuilder_WhenBuild_ThenSubAccountNumerIsValidElevenTestNumber() { var internalOrganisation = this.InternalOrganisation; internalOrganisation.SubAccountCounter.Value = 1000; this.Session.Commit(); var customer1 = new PersonBuilder(this.Session).WithLastName("customer1").Build(); var customerRelationship1 = new CustomerRelationshipBuilder(this.Session) .WithFromDate(DateTime.UtcNow) .WithCustomer(customer1) .Build(); this.Session.Derive(); var partyFinancial1 = customer1.PartyFinancialRelationshipsWhereParty.First(v => Equals(v.InternalOrganisation, customerRelationship1.InternalOrganisation)); Assert.Equal(1007, partyFinancial1.SubAccountNumber); var customer2 = new PersonBuilder(this.Session).WithLastName("customer2").Build(); var customerRelationship2 = new CustomerRelationshipBuilder(this.Session).WithFromDate(DateTime.UtcNow).WithCustomer(customer2).Build(); this.Session.Derive(); var partyFinancial2 = customer2.PartyFinancialRelationshipsWhereParty.First(v => Equals(v.InternalOrganisation, customerRelationship2.InternalOrganisation)); Assert.Equal(1015, partyFinancial2.SubAccountNumber); var customer3 = new PersonBuilder(this.Session).WithLastName("customer3").Build(); var customerRelationship3 = new CustomerRelationshipBuilder(this.Session).WithFromDate(DateTime.UtcNow).WithCustomer(customer3).Build(); this.Session.Derive(); var partyFinancial3 = customer3.PartyFinancialRelationshipsWhereParty.First(v => Equals(v.InternalOrganisation, customerRelationship3.InternalOrganisation)); Assert.Equal(1023, partyFinancial3.SubAccountNumber); }
public void GivenOrganisationContactRelationship_WhenRelationshipPeriodIsNotValid_ThenContactIsNotInCustomerContactUserGroup() { var party = new OrganisationBuilder(this.Session).WithName("customer").Build(); this.Session.Derive(); var customerRelationship = new CustomerRelationshipBuilder(this.Session) .WithInternalOrganisation(this.InternalOrganisation) .WithCustomer(party) .WithFromDate(DateTime.UtcNow.AddYears(-1)) .Build(); this.Session.Derive(); Assert.Contains(customerRelationship, party.CurrentPartyRelationships); Assert.Empty(party.InactivePartyRelationships); var supplierRelationship = new SupplierRelationshipBuilder(this.Session) .WithInternalOrganisation(this.InternalOrganisation) .WithSupplier(party) .WithFromDate(DateTime.UtcNow.AddYears(-1)) .Build(); this.Session.Derive(); Assert.Contains(customerRelationship, party.CurrentPartyRelationships); Assert.Contains(supplierRelationship, party.CurrentPartyRelationships); Assert.Empty(party.InactivePartyRelationships); customerRelationship.ThroughDate = DateTime.UtcNow.AddDays(-1); this.Session.Derive(); Assert.Contains(supplierRelationship, party.CurrentPartyRelationships); Assert.Contains(customerRelationship, party.InactivePartyRelationships); }
public void GivenCustomerWithUnpaidInvoices_WhenDeriving_ThenAmountOverDueIsUpdated() { var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").Build(); var customerRelationship = new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).Build(); var billToContactMechanism = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Mechelen").Build(); var good = new GoodBuilder(this.DatabaseSession) .WithSku("10101") .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(0).Build()) .WithName("good") .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized) .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece) .Build(); this.DatabaseSession.Derive(true); var invoice1 = new SalesInvoiceBuilder(this.DatabaseSession) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .WithBillToCustomer(customer) .WithBillToContactMechanism(billToContactMechanism) .WithInvoiceDate(DateTime.UtcNow.AddDays(-30)) .WithSalesInvoiceItem(new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantity(1).WithActualUnitPrice(100M).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).Build()) .Build(); this.DatabaseSession.Derive(true); var invoice2 = new SalesInvoiceBuilder(this.DatabaseSession) .WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice) .WithBillToCustomer(customer) .WithBillToContactMechanism(billToContactMechanism) .WithInvoiceDate(DateTime.UtcNow.AddDays(-5)) .WithSalesInvoiceItem(new SalesInvoiceItemBuilder(this.DatabaseSession).WithProduct(good).WithQuantity(1).WithActualUnitPrice(200M).WithSalesInvoiceItemType(new SalesInvoiceItemTypes(this.DatabaseSession).ProductItem).Build()) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(100M, customerRelationship.AmountOverDue); new ReceiptBuilder(this.DatabaseSession) .WithAmount(20) .WithPaymentApplication(new PaymentApplicationBuilder(this.DatabaseSession).WithInvoiceItem(invoice1.SalesInvoiceItems[0]).WithAmountApplied(20).Build()) .Build(); this.DatabaseSession.Derive(true); Assert.AreEqual(80, customerRelationship.AmountOverDue); invoice2.InvoiceDate = DateTime.UtcNow.AddDays(-10); this.DatabaseSession.Derive(true); Assert.AreEqual(280, customerRelationship.AmountOverDue); }
public void GivenWorkEffort_WhenCreatingModel_ThenValuesAreSet() { // Arrange var frequencies = new TimeFrequencies(this.Session); var purposes = new ContactMechanismPurposes(this.Session); //// Customer Contact and Address Data var customer = new OrganisationBuilder(this.Session).WithName("Customer").Build(); var customerContact = new PersonBuilder(this.Session).WithFirstName("Customer").WithLastName("Contact").Build(); var organisation = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation); var customerRelation = new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(organisation).Build(); var usa = new Countries(this.Session).Extent().First(c => c.IsoCode.Equals("US")); var michigan = new StateBuilder(this.Session).WithName("Michigan").WithCountry(usa).Build(); var northville = new CityBuilder(this.Session).WithName("Northville").WithState(michigan).Build(); var postalCode = new PostalCodeBuilder(this.Session).WithCode("48167").Build(); var billingAddress = this.CreatePostalAddress("Billing Address", "123 Street", "Suite S1", northville, postalCode); var shippingAddress = this.CreatePostalAddress("Shipping Address", "123 Street", "Dock D1", northville, postalCode); var phone = new TelecommunicationsNumberBuilder(this.Session).WithCountryCode("1").WithAreaCode("616").WithContactNumber("774-2000").Build(); customer.AddPartyContactMechanism(this.CreatePartyContactMechanism(purposes.BillingAddress, billingAddress)); customer.AddPartyContactMechanism(this.CreatePartyContactMechanism(purposes.ShippingAddress, shippingAddress)); customerContact.AddPartyContactMechanism(this.CreatePartyContactMechanism(purposes.GeneralPhoneNumber, phone)); //// Work Effort Data var salesPerson = new PersonBuilder(this.Session).WithFirstName("Sales").WithLastName("Person").Build(); var salesOrder = this.CreateSalesOrder(customer, organisation); var workOrder = this.CreateWorkEffort(organisation, customer, customerContact, salesOrder.SalesOrderItems.First); var employee = new PersonBuilder(this.Session).WithFirstName("Good").WithLastName("Worker").Build(); var employment = new EmploymentBuilder(this.Session).WithEmployee(employee).WithEmployer(organisation).Build(); var salesOrderItem = salesOrder.SalesOrderItems.First; ((SalesOrderDerivedRoles)salesOrder).AddValidOrderItem(salesOrderItem); //// Work Effort Inventory Assignmets var part1 = this.CreatePart("P1"); var part2 = this.CreatePart("P2"); var part3 = this.CreatePart("P3"); this.Session.Derive(true); var inventoryAssignment1 = this.CreateInventoryAssignment(workOrder, part1, 11); var inventoryAssignment2 = this.CreateInventoryAssignment(workOrder, part2, 12); var inventoryAssignment3 = this.CreateInventoryAssignment(workOrder, part3, 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 timeEntryYesterday = this.CreateTimeEntry(yesterday, laterYesterday, frequencies.Day, workOrder, standardRate); var timeEntryToday = this.CreateTimeEntry(today, laterToday, frequencies.Hour, workOrder, standardRate); var timeEntryTomorrow = this.CreateTimeEntry(tomorrow, laterTomorrow, frequencies.Minute, workOrder, overtimeRate); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryYesterday); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryToday); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryTomorrow); this.Session.Derive(true); // Act var model = new WorkTaskModel.Model(workOrder); // Assert Assert.Equal(3, model.TimeEntries.Length); Assert.Single(model.TimeEntriesByBillingRate); }
public void GivenCustomerRelationship_WhenDerivingWithout_ThenAmountOverDueIsZero() { var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").Build(); var customerRelationship = new CustomerRelationshipBuilder(this.DatabaseSession).WithFromDate(DateTime.UtcNow).WithCustomer(customer).Build(); var internalOrganisation = Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation; this.DatabaseSession.Derive(true); Assert.AreEqual(0, customerRelationship.AmountOverDue); }
public void GivenCustomerRelationship_WhenDeriving_ThenSameSubAccountNumberIsAllowedAtInternalOrganisation() { var customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").Build(); var customerRelationship = new CustomerRelationshipBuilder(this.DatabaseSession) .WithCustomer(customer) .WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation) .Build(); this.DatabaseSession.Derive(true); customerRelationship.SubAccountNumber = customerRelationship.InternalOrganisation.CustomerRelationshipsWhereInternalOrganisation.First.SubAccountNumber; Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); }
public void GivenWorkEffortPrintDocument_WhenPrinting_ThenMediaCreated() { // Arrange var frequencies = new TimeFrequencies(this.Session); var purposes = new ContactMechanismPurposes(this.Session); //// Customer Contact and Address Data var customer = new OrganisationBuilder(this.Session).WithName("Customer").Build(); var customerContact = new PersonBuilder(this.Session).WithFirstName("Customer").WithLastName("Contact").Build(); var organisation = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation); var customerRelation = new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(organisation).Build(); var usa = new Countries(this.Session).Extent().First(c => c.IsoCode.Equals("US")); var michigan = new StateBuilder(this.Session).WithName("Michigan").WithCountry(usa).Build(); var northville = new CityBuilder(this.Session).WithName("Northville").WithState(michigan).Build(); var postalCode = new PostalCodeBuilder(this.Session).WithCode("48167").Build(); var billingAddress = this.CreatePostalAddress("Billing Address", "123 Street", "Suite S1", northville, postalCode); var shippingAddress = this.CreatePostalAddress("Shipping Address", "123 Street", "Dock D1", northville, postalCode); var phone = new TelecommunicationsNumberBuilder(this.Session).WithCountryCode("1").WithAreaCode("616").WithContactNumber("774-2000").Build(); customer.AddPartyContactMechanism(this.CreatePartyContactMechanism(purposes.BillingAddress, billingAddress)); customer.AddPartyContactMechanism(this.CreatePartyContactMechanism(purposes.ShippingAddress, shippingAddress)); customerContact.AddPartyContactMechanism(this.CreatePartyContactMechanism(purposes.GeneralPhoneNumber, phone)); //// Work Effort Data var salesPerson = new PersonBuilder(this.Session).WithFirstName("Sales").WithLastName("Person").Build(); var salesRepRelation = new SalesRepRelationshipBuilder(this.Session).WithCustomer(customer).WithSalesRepresentative(salesPerson).Build(); var salesOrder = this.CreateSalesOrder(customer, organisation); var workOrder = this.CreateWorkEffort(organisation, customer, customerContact, salesOrder.SalesOrderItems.First); var employee = new PersonBuilder(this.Session).WithFirstName("Good").WithLastName("Worker").Build(); var employment = new EmploymentBuilder(this.Session).WithEmployee(employee).WithEmployer(organisation).Build(); var salesOrderItem = salesOrder.SalesOrderItems.First; salesOrder.AddValidOrderItem(salesOrderItem); //// Work Effort Inventory Assignmets var part1 = this.CreatePart("P1"); var part2 = this.CreatePart("P2"); var part3 = this.CreatePart("P3"); this.Session.Derive(true); var inventoryAssignment1 = this.CreateInventoryAssignment(workOrder, part1, 11); var inventoryAssignment2 = this.CreateInventoryAssignment(workOrder, part2, 12); var inventoryAssignment3 = this.CreateInventoryAssignment(workOrder, part3, 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 timeEntryYesterday = this.CreateTimeEntry(yesterday, laterYesterday, frequencies.Day, workOrder); var timeEntryToday = this.CreateTimeEntry(today, laterToday, frequencies.Hour, workOrder); var timeEntryTomorrow = this.CreateTimeEntry(tomorrow, laterTomorrow, frequencies.Minute, workOrder); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryYesterday); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryToday); employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryTomorrow); this.Session.Derive(true); // Act workOrder.Print(); this.Session.Derive(); this.Session.Commit(); // Assert Assert.True(workOrder.PrintDocument.ExistMedia); var desktopDir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); var outputFile = System.IO.File.Create(System.IO.Path.Combine(desktopDir, "workTask.odt")); var stream = new System.IO.MemoryStream(workOrder.PrintDocument.Media.MediaContent.Data); stream.CopyTo(outputFile); stream.Close(); }
public void GivenCustomerWithUnpaidInvoices_WhenDeriving_ThenAmountDueIsUpdated() { var mechelen = new CityBuilder(this.Session).WithName("Mechelen").Build(); var customer = new OrganisationBuilder(this.Session).WithName("customer").Build(); var customerRelationship = new CustomerRelationshipBuilder(this.Session).WithFromDate(this.Session.Now()).WithCustomer(customer).Build(); this.Session.Derive(); var partyFinancial = customer.PartyFinancialRelationshipsWhereParty.First(v => Equals(v.InternalOrganisation, customerRelationship.InternalOrganisation)); var billToContactMechanism = new PostalAddressBuilder(this.Session).WithPostalAddressBoundary(mechelen).WithAddress1("Mechelen").Build(); var good = new Goods(this.Session).FindBy(M.Good.Name, "good1"); good.VatRegime = new VatRegimes(this.Session).ZeroRated; this.Session.Derive(); var invoice1 = new SalesInvoiceBuilder(this.Session) .WithSalesInvoiceType(new SalesInvoiceTypes(this.Session).SalesInvoice) .WithBillToCustomer(customer) .WithAssignedBillToContactMechanism(billToContactMechanism) .WithSalesInvoiceItem(new SalesInvoiceItemBuilder(this.Session).WithProduct(good).WithQuantity(1).WithAssignedUnitPrice(100M).WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem).Build()) .Build(); this.Session.Derive(); var invoice2 = new SalesInvoiceBuilder(this.Session) .WithSalesInvoiceType(new SalesInvoiceTypes(this.Session).SalesInvoice) .WithBillToCustomer(customer) .WithAssignedBillToContactMechanism(billToContactMechanism) .WithSalesInvoiceItem(new SalesInvoiceItemBuilder(this.Session).WithProduct(good).WithQuantity(1).WithAssignedUnitPrice(200M).WithInvoiceItemType(new InvoiceItemTypes(this.Session).ProductItem).Build()) .Build(); this.Session.Derive(); Assert.Equal(300M, partyFinancial.AmountDue); new ReceiptBuilder(this.Session) .WithAmount(50) .WithPaymentApplication(new PaymentApplicationBuilder(this.Session).WithInvoiceItem(invoice1.SalesInvoiceItems[0]).WithAmountApplied(50).Build()) .Build(); this.Session.Derive(); Assert.Equal(250, partyFinancial.AmountDue); new ReceiptBuilder(this.Session) .WithAmount(200) .WithPaymentApplication(new PaymentApplicationBuilder(this.Session).WithInvoiceItem(invoice2.SalesInvoiceItems[0]).WithAmountApplied(200).Build()) .Build(); this.Session.Derive(); Assert.Equal(50, partyFinancial.AmountDue); new ReceiptBuilder(this.Session) .WithAmount(50) .WithPaymentApplication(new PaymentApplicationBuilder(this.Session).WithInvoiceItem(invoice1.SalesInvoiceItems[0]).WithAmountApplied(50).Build()) .Build(); this.Session.Derive(); Assert.Equal(0, partyFinancial.AmountDue); }
public void GivenCustomerRelationship_WhenDeriving_ThenSubAccountNumberMustBeUniqueWithinInternalOrganisation() { var customer2 = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build(); var belgium = new Countries(this.DatabaseSession).CountryByIsoCode["BE"]; var euro = belgium.Currency; var bank = new BankBuilder(this.DatabaseSession).WithCountry(belgium).WithName("ING België").WithBic("BBRUBEBB").Build(); var ownBankAccount = new OwnBankAccountBuilder(this.DatabaseSession) .WithDescription("BE23 3300 6167 6391") .WithBankAccount(new BankAccountBuilder(this.DatabaseSession).WithBank(bank).WithCurrency(euro).WithIban("BE23 3300 6167 6391").WithNameOnAccount("Koen").Build()) .Build(); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); var address1 = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); var billingAddress = new PartyContactMechanismBuilder(this.DatabaseSession) .WithContactMechanism(address1) .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).BillingAddress) .WithUseAsDefault(true) .Build(); var internalOrganisation2 = new InternalOrganisationBuilder(this.DatabaseSession) .WithName("internalOrganisation2") .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain) .WithEmployeeRole(new Roles(this.DatabaseSession).Administrator) .WithPartyContactMechanism(billingAddress) .WithDefaultPaymentMethod(ownBankAccount) .WithPreferredCurrency(euro) .Build(); var customerRelationship2 = new CustomerRelationshipBuilder(this.DatabaseSession) .WithCustomer(customer2) .WithInternalOrganisation(internalOrganisation2) .WithFromDate(DateTime.UtcNow) .Build(); customerRelationship2.SubAccountNumber = 19; Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); }