public static TelecommunicationsNumberBuilder WithDefaults(this TelecommunicationsNumberBuilder @this)
        {
            var faker = @this.Session.Faker();

            @this.WithCountryCode(faker.Phone.PhoneNumber("####"));
            @this.WithContactNumber(faker.Phone.PhoneNumber("## ## ##"));
            @this.WithDescription(faker.Lorem.Sentence());
            @this.WithContactMechanismType(faker.Random.ListItem(@this.Session.Extent <ContactMechanismType>()));

            return(@this);
        }
        public void GivenPartyContactMechanism_WhenPartyIsDeleted_ThenPartyContactMechanismIsDeleted()
        {
            var contactMechanism      = new TelecommunicationsNumberBuilder(this.Session).WithAreaCode("0495").WithContactNumber("493499").WithDescription("cellphone").Build();
            var partyContactMechanism = new PartyContactMechanismBuilder(this.Session).WithContactMechanism(contactMechanism).Build();
            var party = new PersonBuilder(this.Session).WithLastName("party").WithPartyContactMechanism(partyContactMechanism).Build();

            this.Session.Derive();
            var countBefore = this.Session.Extent <PartyContactMechanism>().Count;

            party.Delete();
            this.Session.Derive();

            Assert.Equal(countBefore - 1, this.Session.Extent <PartyContactMechanism>().Count);
        }
Example #3
0
        public void GivenPerson_WhenInContactRelationship_ThenCurrentOrganisationContactMechanismsIsDerived()
        {
            var contact       = new PersonBuilder(this.Session).WithLastName("organisationContact").Build();
            var organisation1 = new OrganisationBuilder(this.Session).WithName("organisation1").Build();
            var organisation2 = new OrganisationBuilder(this.Session).WithName("organisation2").Build();

            // Even when relationship is inactive CurrentOrganisationContactMechanisms is maintained
            new OrganisationContactRelationshipBuilder(this.Session)
            .WithContact(contact)
            .WithOrganisation(organisation1)
            .WithFromDate(DateTime.UtcNow.Date.AddDays(-1))
            .WithThroughDate(DateTime.UtcNow.Date.AddDays(-1))
            .Build();

            var contactMechanism1      = new TelecommunicationsNumberBuilder(this.Session).WithAreaCode("111").WithContactNumber("222").Build();
            var partyContactMechanism1 = new PartyContactMechanismBuilder(this.Session).WithContactMechanism(contactMechanism1).Build();

            organisation1.AddPartyContactMechanism(partyContactMechanism1);

            this.Session.Derive();

            Assert.Single(contact.CurrentOrganisationContactMechanisms);
            Assert.Contains(contactMechanism1, contact.CurrentOrganisationContactMechanisms);

            partyContactMechanism1.ThroughDate = partyContactMechanism1.FromDate;

            this.Session.Derive();

            Assert.Empty(contact.CurrentOrganisationContactMechanisms);

            partyContactMechanism1.RemoveThroughDate();

            new OrganisationContactRelationshipBuilder(this.Session)
            .WithContact(contact)
            .WithOrganisation(organisation2)
            .WithFromDate(DateTime.UtcNow.Date.AddDays(-1))
            .Build();

            var contactMechanism2      = new TelecommunicationsNumberBuilder(this.Session).WithAreaCode("222").WithContactNumber("333").Build();
            var partyContactMechanism2 = new PartyContactMechanismBuilder(this.Session).WithContactMechanism(contactMechanism2).Build();

            organisation2.AddPartyContactMechanism(partyContactMechanism2);

            this.Session.Derive();

            Assert.Equal(2, contact.CurrentOrganisationContactMechanisms.Count);
            Assert.Contains(contactMechanism1, contact.CurrentOrganisationContactMechanisms);
            Assert.Contains(contactMechanism2, contact.CurrentOrganisationContactMechanisms);
        }
        public void GivenPartyContactMechanism_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var contactMechanism = new TelecommunicationsNumberBuilder(this.DatabaseSession).WithAreaCode("0495").WithContactNumber("493499").WithDescription("cellphone").Build();
            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            var builder = new PartyContactMechanismBuilder(this.DatabaseSession);
            builder.Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            this.DatabaseSession.Rollback();

            builder.WithContactMechanism(contactMechanism);
            builder.Build();

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
        public void GivenPartyContactMechanism_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var contactMechanism = new TelecommunicationsNumberBuilder(this.Session).WithAreaCode("0495").WithContactNumber("493499").WithDescription("cellphone").Build();

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

            var builder = new PartyContactMechanismBuilder(this.Session);

            builder.Build();

            Assert.True(this.Session.Derive(false).HasErrors);

            this.Session.Rollback();

            builder.WithContactMechanism(contactMechanism);
            builder.Build();

            Assert.False(this.Session.Derive(false).HasErrors);
        }
Example #6
0
        public void GivenTelecommunicationsNumber_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var builder = new TelecommunicationsNumberBuilder(this.DatabaseSession);
            var contactMechanism = builder.Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            this.DatabaseSession.Rollback();

            builder.WithAreaCode("area");
            contactMechanism = builder.Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            this.DatabaseSession.Rollback();

            builder.WithContactNumber("number");
            contactMechanism = builder.Build();

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Example #7
0
        public void GivenTelecommunicationsNumber_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var builder          = new TelecommunicationsNumberBuilder(this.Session);
            var contactMechanism = builder.Build();

            Assert.True(this.Session.Derive(false).HasErrors);

            this.Session.Rollback();

            builder.WithAreaCode("area");
            contactMechanism = builder.Build();

            Assert.True(this.Session.Derive(false).HasErrors);

            this.Session.Rollback();

            builder.WithContactNumber("number");
            contactMechanism = builder.Build();

            Assert.False(this.Session.Derive(false).HasErrors);
        }
Example #8
0
        public static Organisation CreateInternalOrganisation(
            ISession session,
            string name,
            string address,
            string postalCode,
            string locality,
            Country country,
            string phone1CountryCode,
            string phone1,
            ContactMechanismPurpose phone1Purpose,
            string phone2CountryCode,
            string phone2,
            ContactMechanismPurpose phone2Purpose,
            string emailAddress,
            string websiteAddress,
            string taxNumber,
            string bankName,
            string facilityName,
            string bic,
            string iban,
            Currency currency,
            string logo,
            string storeName,
            BillingProcess billingProcess,
            string outgoingShipmentNumberPrefix,
            string salesInvoiceNumberPrefix,
            string salesOrderNumberPrefix,
            string purchaseOrderNumberPrefix,
            string purchaseInvoiceNumberPrefix,
            string requestNumberPrefix,
            string quoteNumberPrefix,
            string productNumberPrefix,
            string workEffortPrefix,
            string creditNoteNumberPrefix,
            bool isImmediatelyPicked,
            bool autoGenerateShipmentPackage,
            bool isImmediatelyPacked,
            bool isAutomaticallyShipped,
            bool autoGenerateCustomerShipment,
            bool isAutomaticallyReceived,
            bool autoGeneratePurchaseShipment,
            bool useCreditNoteSequence,
            int?requestCounterValue,
            int?quoteCounterValue,
            int?orderCounterValue,
            int?purchaseOrderCounterValue,
            int?invoiceCounterValue,
            int?purchaseInvoiceCounterValue,
            bool purchaseOrderNeedsApproval,
            decimal?purchaseOrderApprovalThresholdLevel1,
            decimal?purchaseOrderApprovalThresholdLevel2,
            SerialisedItemSoldOn[] serialisedItemSoldOns,
            bool collectiveWorkEffortInvoice,
            InvoiceSequence invoiceSequence,
            RequestSequence requestSequence,
            QuoteSequence quoteSequence,
            CustomerShipmentSequence customerShipmentSequence,
            PurchaseShipmentSequence purchaseShipmentSequence,
            WorkEffortSequence workEffortSequence)
        {
            var postalAddress1 = new PostalAddressBuilder(session)
                                 .WithAddress1(address)
                                 .WithPostalCode(postalCode)
                                 .WithLocality(locality)
                                 .WithCountry(country)
                                 .Build();

            var webSite = new WebAddressBuilder(session)
                          .WithElectronicAddressString(websiteAddress)
                          .Build();

            BankAccount bankAccount = null;

            if (!string.IsNullOrEmpty(bic) && !string.IsNullOrEmpty(iban))
            {
                var bank = new BankBuilder(session).WithName(bankName).WithBic(bic).WithCountry(country).Build();
                bankAccount = new BankAccountBuilder(session)
                              .WithBank(bank)
                              .WithIban(iban)
                              .WithNameOnAccount(name)
                              .WithCurrency(currency)
                              .Build();
            }

            var internalOrganisation = new OrganisationBuilder(session)
                                       .WithIsInternalOrganisation(true)
                                       .WithTaxNumber(taxNumber)
                                       .WithName(name)
                                       .WithPreferredCurrency(new Currencies(session).FindBy(M.Currency.IsoCode, "EUR"))
                                       .WithInvoiceSequence(invoiceSequence)
                                       .WithRequestSequence(requestSequence)
                                       .WithQuoteSequence(quoteSequence)
                                       .WithCustomerShipmentSequence(customerShipmentSequence)
                                       .WithPurchaseShipmentSequence(purchaseShipmentSequence)
                                       .WithWorkEffortSequence(workEffortSequence)
                                       .WithFiscalYearStartMonth(01)
                                       .WithFiscalYearStartDay(01)
                                       .WithDoAccounting(false)
                                       .WithPurchaseOrderNeedsApproval(purchaseOrderNeedsApproval)
                                       .WithPurchaseOrderApprovalThresholdLevel1(purchaseOrderApprovalThresholdLevel1)
                                       .WithPurchaseOrderApprovalThresholdLevel2(purchaseOrderApprovalThresholdLevel2)
                                       .WithAutoGeneratePurchaseShipment(autoGeneratePurchaseShipment)
                                       .WithIsAutomaticallyReceived(isAutomaticallyReceived)
                                       .WithCollectiveWorkEffortInvoice(collectiveWorkEffortInvoice)
                                       .WithCountry(country)
                                       .Build();

            internalOrganisation.SerialisedItemSoldOns = serialisedItemSoldOns;

            if (invoiceSequence == new InvoiceSequences(session).RestartOnFiscalYear)
            {
                var sequenceNumbers = internalOrganisation.FiscalYearsInternalOrganisationSequenceNumbers.FirstOrDefault(v => v.FiscalYear == session.Now().Year);
                if (sequenceNumbers == null)
                {
                    sequenceNumbers = new FiscalYearInternalOrganisationSequenceNumbersBuilder(session).WithFiscalYear(session.Now().Year).Build();
                    internalOrganisation.AddFiscalYearsInternalOrganisationSequenceNumber(sequenceNumbers);
                }

                sequenceNumbers.PurchaseOrderNumberPrefix   = purchaseOrderNumberPrefix;
                sequenceNumbers.PurchaseInvoiceNumberPrefix = purchaseInvoiceNumberPrefix;

                if (purchaseOrderCounterValue != null)
                {
                    sequenceNumbers.PurchaseOrderNumberCounter = new CounterBuilder(session).WithValue(purchaseOrderCounterValue).Build();
                }

                if (purchaseInvoiceCounterValue != null)
                {
                    sequenceNumbers.PurchaseInvoiceNumberCounter = new CounterBuilder(session).WithValue(purchaseInvoiceCounterValue).Build();
                }
            }
            else
            {
                internalOrganisation.PurchaseOrderNumberPrefix   = purchaseOrderNumberPrefix;
                internalOrganisation.PurchaseInvoiceNumberPrefix = purchaseInvoiceNumberPrefix;

                if (purchaseOrderCounterValue != null)
                {
                    internalOrganisation.PurchaseOrderNumberCounter = new CounterBuilder(session).WithValue(purchaseOrderCounterValue).Build();
                }

                if (purchaseInvoiceCounterValue != null)
                {
                    internalOrganisation.PurchaseInvoiceNumberCounter = new CounterBuilder(session).WithValue(purchaseInvoiceCounterValue).Build();
                }
            }

            if (requestSequence == new RequestSequences(session).RestartOnFiscalYear)
            {
                var sequenceNumbers = internalOrganisation.FiscalYearsInternalOrganisationSequenceNumbers.FirstOrDefault(v => v.FiscalYear == session.Now().Year);
                if (sequenceNumbers == null)
                {
                    sequenceNumbers = new FiscalYearInternalOrganisationSequenceNumbersBuilder(session).WithFiscalYear(session.Now().Year).Build();
                    internalOrganisation.AddFiscalYearsInternalOrganisationSequenceNumber(sequenceNumbers);
                }

                sequenceNumbers.RequestNumberPrefix = requestNumberPrefix;

                if (requestCounterValue != null)
                {
                    sequenceNumbers.RequestNumberCounter = new CounterBuilder(session).WithValue(requestCounterValue).Build();
                }
            }
            else
            {
                internalOrganisation.RequestNumberPrefix = requestNumberPrefix;

                if (requestCounterValue != null)
                {
                    internalOrganisation.RequestNumberCounter = new CounterBuilder(session).WithValue(requestCounterValue).Build();
                }
            }

            if (quoteSequence == new QuoteSequences(session).RestartOnFiscalYear)
            {
                var sequenceNumbers = internalOrganisation.FiscalYearsInternalOrganisationSequenceNumbers.FirstOrDefault(v => v.FiscalYear == session.Now().Year);
                if (sequenceNumbers == null)
                {
                    sequenceNumbers = new FiscalYearInternalOrganisationSequenceNumbersBuilder(session).WithFiscalYear(session.Now().Year).Build();
                    internalOrganisation.AddFiscalYearsInternalOrganisationSequenceNumber(sequenceNumbers);
                }

                sequenceNumbers.QuoteNumberPrefix = quoteNumberPrefix;

                if (quoteCounterValue != null)
                {
                    sequenceNumbers.QuoteNumberCounter = new CounterBuilder(session).WithValue(quoteCounterValue).Build();
                }
            }
            else
            {
                internalOrganisation.QuoteNumberPrefix = quoteNumberPrefix;

                if (quoteCounterValue != null)
                {
                    internalOrganisation.QuoteNumberCounter = new CounterBuilder(session).WithValue(quoteCounterValue).Build();
                }
            }

            if (workEffortSequence == new WorkEffortSequences(session).RestartOnFiscalYear)
            {
                var sequenceNumbers = internalOrganisation.FiscalYearsInternalOrganisationSequenceNumbers.FirstOrDefault(v => v.FiscalYear == session.Now().Year);
                if (sequenceNumbers == null)
                {
                    sequenceNumbers = new FiscalYearInternalOrganisationSequenceNumbersBuilder(session).WithFiscalYear(session.Now().Year).Build();
                    internalOrganisation.AddFiscalYearsInternalOrganisationSequenceNumber(sequenceNumbers);
                }

                sequenceNumbers.WorkEffortNumberPrefix = workEffortPrefix;
            }
            else
            {
                internalOrganisation.WorkEffortNumberPrefix = workEffortPrefix;
            }

            OwnBankAccount defaultCollectionMethod = null;

            if (bankAccount != null)
            {
                internalOrganisation.AddBankAccount(bankAccount);
                defaultCollectionMethod = new OwnBankAccountBuilder(session).WithBankAccount(bankAccount).WithDescription("Huisbank").Build();
                internalOrganisation.DefaultCollectionMethod = defaultCollectionMethod;
            }

            if (!string.IsNullOrEmpty(emailAddress))
            {
                var email = new EmailAddressBuilder(session)
                            .WithElectronicAddressString(emailAddress)
                            .Build();

                internalOrganisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session)
                                                              .WithUseAsDefault(true)
                                                              .WithContactMechanism(email)
                                                              .WithContactPurpose(new ContactMechanismPurposes(session).GeneralEmail)
                                                              .Build());
            }

            internalOrganisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session)
                                                          .WithUseAsDefault(true)
                                                          .WithContactMechanism(postalAddress1)
                                                          .WithContactPurpose(new ContactMechanismPurposes(session).RegisteredOffice)
                                                          .WithContactPurpose(new ContactMechanismPurposes(session).GeneralCorrespondence)
                                                          .WithContactPurpose(new ContactMechanismPurposes(session).BillingAddress)
                                                          .WithContactPurpose(new ContactMechanismPurposes(session).ShippingAddress)
                                                          .Build());

            internalOrganisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session)
                                                          .WithUseAsDefault(true)
                                                          .WithContactMechanism(webSite)
                                                          .WithContactPurpose(new ContactMechanismPurposes(session).InternetAddress)
                                                          .Build());

            TelecommunicationsNumber phoneNumber1 = null;

            if (!string.IsNullOrEmpty(phone1))
            {
                phoneNumber1 = new TelecommunicationsNumberBuilder(session).WithContactNumber(phone1).Build();
                if (!string.IsNullOrEmpty(phone1CountryCode))
                {
                    phoneNumber1.CountryCode = phone1CountryCode;
                }
            }

            if (phoneNumber1 != null)
            {
                internalOrganisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session)
                                                              .WithUseAsDefault(true)
                                                              .WithContactMechanism(phoneNumber1)
                                                              .WithContactPurpose(phone1Purpose)
                                                              .Build());
            }

            TelecommunicationsNumber phoneNumber2 = null;

            if (!string.IsNullOrEmpty(phone2))
            {
                phoneNumber2 = new TelecommunicationsNumberBuilder(session).WithContactNumber(phone2).Build();
                if (!string.IsNullOrEmpty(phone2CountryCode))
                {
                    phoneNumber2.CountryCode = phone2CountryCode;
                }
            }

            if (phoneNumber2 != null)
            {
                internalOrganisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session)
                                                              .WithUseAsDefault(true)
                                                              .WithContactMechanism(phoneNumber2)
                                                              .WithContactPurpose(phone2Purpose)
                                                              .Build());
            }

            if (!string.IsNullOrWhiteSpace(logo))
            {
                var singleton = session.GetSingleton();
                internalOrganisation.LogoImage = new MediaBuilder(session).WithInFileName(logo).WithInData(singleton.GetResourceBytes(logo)).Build();
            }

            Facility facility = null;

            if (facilityName != null)
            {
                facility = new FacilityBuilder(session)
                           .WithName(facilityName)
                           .WithFacilityType(new FacilityTypes(session).Warehouse)
                           .WithOwner(internalOrganisation)
                           .Build();
            }

            var store = new StoreBuilder(session)
                        .WithName(storeName)
                        .WithDefaultCollectionMethod(defaultCollectionMethod)
                        .WithDefaultShipmentMethod(new ShipmentMethods(session).Ground)
                        .WithDefaultCarrier(new Carriers(session).Fedex)
                        .WithBillingProcess(billingProcess)
                        .WithIsImmediatelyPicked(isImmediatelyPicked)
                        .WithAutoGenerateShipmentPackage(autoGenerateShipmentPackage)
                        .WithIsImmediatelyPacked(isImmediatelyPacked)
                        .WithIsAutomaticallyShipped(isAutomaticallyShipped)
                        .WithAutoGenerateCustomerShipment(autoGenerateCustomerShipment)
                        .WithUseCreditNoteSequence(useCreditNoteSequence)
                        .WithInternalOrganisation(internalOrganisation)
                        .Build();

            if (defaultCollectionMethod == null)
            {
                store.DefaultCollectionMethod = new CashBuilder(session).Build();
            }
            else
            {
                store.DefaultCollectionMethod = defaultCollectionMethod;
            }

            if (facility != null)
            {
                store.DefaultFacility = facility;
            }

            if (invoiceSequence == new InvoiceSequences(session).RestartOnFiscalYear)
            {
                var sequenceNumbers = new FiscalYearStoreSequenceNumbersBuilder(session).WithFiscalYear(session.Now().Year).Build();

                sequenceNumbers.CreditNoteNumberPrefix       = creditNoteNumberPrefix;
                sequenceNumbers.OutgoingShipmentNumberPrefix = outgoingShipmentNumberPrefix;
                sequenceNumbers.SalesInvoiceNumberPrefix     = salesInvoiceNumberPrefix;
                sequenceNumbers.SalesOrderNumberPrefix       = salesOrderNumberPrefix;

                if (orderCounterValue != null)
                {
                    sequenceNumbers.SalesOrderNumberCounter = new CounterBuilder(session).WithValue(orderCounterValue).Build();
                }

                if (invoiceCounterValue != null)
                {
                    sequenceNumbers.SalesInvoiceNumberCounter = new CounterBuilder(session).WithValue(invoiceCounterValue).Build();
                }

                store.AddFiscalYearsStoreSequenceNumber(sequenceNumbers);
            }
            else
            {
                store.CreditNoteNumberPrefix       = creditNoteNumberPrefix;
                store.OutgoingShipmentNumberPrefix = outgoingShipmentNumberPrefix;
                store.SalesInvoiceNumberPrefix     = salesInvoiceNumberPrefix;
                store.SalesOrderNumberPrefix       = salesOrderNumberPrefix;

                if (orderCounterValue != null)
                {
                    store.SalesOrderNumberCounter = new CounterBuilder(session).WithValue(orderCounterValue).Build();
                }

                if (invoiceCounterValue != null)
                {
                    store.SalesInvoiceNumberCounter = new CounterBuilder(session).WithValue(invoiceCounterValue).Build();
                }
            }

            return(internalOrganisation);
        }
Example #9
0
        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();
        }
Example #10
0
        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);
        }
Example #11
0
        public static Organisation CreateInternalOrganisation(
            ISession session,
            string name,
            string address,
            string postalCode,
            string locality,
            Country country,
            string phone1CountryCode,
            string phone1,
            ContactMechanismPurpose phone1Purpose,
            string phone2CountryCode,
            string phone2,
            ContactMechanismPurpose phone2Purpose,
            string emailAddress,
            string websiteAddress,
            string taxNumber,
            string bankName,
            string facilityName,
            string bic,
            string iban,
            Currency currency,
            string logo,
            string storeName,
            BillingProcess billingProcess,
            string outgoingShipmentNumberPrefix,
            string salesInvoiceNumberPrefix,
            string salesOrderNumberPrefix,
            string requestNumberPrefix,
            string quoteNumberPrefix,
            string productNumberPrefix,
            int?requestCounterValue,
            int?quoteCounterValue,
            int?orderCounterValue,
            int?invoiceCounterValue)
        {
            var postalAddress1 = new PostalAddressBuilder(session)
                                 .WithAddress1(address)
                                 .WithPostalBoundary(new PostalBoundaryBuilder(session).WithPostalCode(postalCode).WithLocality(locality).WithCountry(country).Build())
                                 .Build();

            var email = new EmailAddressBuilder(session)
                        .WithElectronicAddressString(emailAddress)
                        .Build();

            var webSite = new WebAddressBuilder(session)
                          .WithElectronicAddressString(websiteAddress)
                          .Build();

            var bank        = new BankBuilder(session).WithName(bankName).WithBic(bic).WithCountry(country).Build();
            var bankaccount = new BankAccountBuilder(session)
                              .WithBank(bank)
                              .WithIban(iban)
                              .WithNameOnAccount(name)
                              .WithCurrency(currency)
                              .Build();

            var organisation = new OrganisationBuilder(session)
                               .WithIsInternalOrganisation(true)
                               .WithTaxNumber(taxNumber)
                               .WithName(name)
                               .WithBankAccount(bankaccount)
                               .WithDefaultCollectionMethod(new OwnBankAccountBuilder(session).WithBankAccount(bankaccount).WithDescription("Huisbank").Build())
                               .WithPreferredCurrency(new Currencies(session).FindBy(M.Currency.IsoCode, "EUR"))
                               .WithInvoiceSequence(new InvoiceSequences(session).EnforcedSequence)
                               .WithFiscalYearStartMonth(01)
                               .WithFiscalYearStartDay(01)
                               .WithDoAccounting(false)
                               .WithRequestNumberPrefix(requestNumberPrefix)
                               .WithQuoteNumberPrefix(quoteNumberPrefix)
                               .Build();

            if (requestCounterValue != null)
            {
                organisation.RequestCounter = new CounterBuilder(session).WithValue(requestCounterValue).Build();
            }

            if (quoteCounterValue != null)
            {
                organisation.QuoteCounter = new CounterBuilder(session).WithValue(quoteCounterValue).Build();
            }

            organisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session)
                                                  .WithUseAsDefault(true)
                                                  .WithContactMechanism(email)
                                                  .WithContactPurpose(new ContactMechanismPurposes(session).GeneralEmail)
                                                  .Build());
            organisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session)
                                                  .WithUseAsDefault(true)
                                                  .WithContactMechanism(postalAddress1)
                                                  .WithContactPurpose(new ContactMechanismPurposes(session).GeneralCorrespondence)
                                                  .Build());
            organisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session)
                                                  .WithUseAsDefault(true)
                                                  .WithContactMechanism(webSite)
                                                  .WithContactPurpose(new ContactMechanismPurposes(session).InternetAddress)
                                                  .Build());

            TelecommunicationsNumber phoneNumber1 = null;

            if (!string.IsNullOrEmpty(phone1))
            {
                phoneNumber1 = new TelecommunicationsNumberBuilder(session).WithContactNumber(phone1).Build();
                if (!string.IsNullOrEmpty(phone1CountryCode))
                {
                    phoneNumber1.CountryCode = phone1CountryCode;
                }
            }

            if (phoneNumber1 != null)
            {
                organisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session)
                                                      .WithUseAsDefault(true)
                                                      .WithContactMechanism(phoneNumber1)
                                                      .WithContactPurpose(phone1Purpose)
                                                      .Build());
            }

            TelecommunicationsNumber phoneNumber2 = null;

            if (!string.IsNullOrEmpty(phone2))
            {
                phoneNumber2 = new TelecommunicationsNumberBuilder(session).WithContactNumber(phone2).Build();
                if (!string.IsNullOrEmpty(phone2CountryCode))
                {
                    phoneNumber2.CountryCode = phone2CountryCode;
                }
            }

            if (phoneNumber2 != null)
            {
                organisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session)
                                                      .WithUseAsDefault(true)
                                                      .WithContactMechanism(phoneNumber2)
                                                      .WithContactPurpose(phone2Purpose)
                                                      .Build());
            }

            if (File.Exists(logo))
            {
                var fileInfo = new FileInfo(logo);

                var fileName = System.IO.Path.GetFileNameWithoutExtension(fileInfo.FullName).ToLowerInvariant();
                var content  = File.ReadAllBytes(fileInfo.FullName);
                var image    = new MediaBuilder(session).WithFileName(fileName).WithInData(content).Build();
                organisation.LogoImage = image;
            }

            Facility facility = null;

            if (facilityName != null)
            {
                facility = new FacilityBuilder(session)
                           .WithName(facilityName)
                           .WithFacilityType(new FacilityTypes(session).Warehouse)
                           .WithOwner(organisation)
                           .Build();
            }

            var paymentMethod = new OwnBankAccountBuilder(session).WithBankAccount(bankaccount).WithDescription("Hoofdbank").Build();

            var store = new StoreBuilder(session)
                        .WithName(storeName)
                        .WithOutgoingShipmentNumberPrefix(outgoingShipmentNumberPrefix)
                        .WithSalesInvoiceNumberPrefix(salesInvoiceNumberPrefix)
                        .WithSalesOrderNumberPrefix(salesOrderNumberPrefix)
                        .WithDefaultCollectionMethod(paymentMethod)
                        .WithDefaultShipmentMethod(new ShipmentMethods(session).Ground)
                        .WithDefaultCarrier(new Carriers(session).Fedex)
                        .WithBillingProcess(billingProcess)
                        .WithSalesInvoiceCounter(new CounterBuilder(session).WithUniqueId(Guid.NewGuid()).WithValue(0).Build())
                        .WithIsImmediatelyPicked(true)
                        .WithIsAutomaticallyShipped(true)
                        .WithInternalOrganisation(organisation)
                        .Build();

            if (facility != null)
            {
                store.DefaultFacility = facility;
            }

            if (orderCounterValue != null)
            {
                store.SalesOrderCounter = new CounterBuilder(session).WithValue(orderCounterValue).Build();
            }

            if (invoiceCounterValue != null)
            {
                store.SalesInvoiceCounter = new CounterBuilder(session).WithValue(invoiceCounterValue).Build();
            }

            return(organisation);
        }