Example #1
0
        public void GivenBank_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var netherlands = new Countries(this.DatabaseSession).CountryByIsoCode["NL"];

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

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

            this.DatabaseSession.Rollback();

            builder.WithCountry(netherlands);
            builder.Build();

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

            this.DatabaseSession.Rollback();

            builder.WithBic("RABONL2U");
            builder.Build();

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

            this.DatabaseSession.Rollback();

            builder.WithName("Rabo");
            builder.Build();

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Example #2
0
        public void GivenStoreWithoutDefaultPaymentMethod_WhenSinglePaymentMethodIsAdded_ThenDefaultPaymentMethodIsSet()
        {
            Singleton.Instance(this.DatabaseSession).RemoveDefaultInternalOrganisation();
            this.DatabaseSession.Commit();

            var netherlands = new Countries(this.DatabaseSession).CountryByIsoCode["NL"];
            var euro = netherlands.Currency;

            var bank = new BankBuilder(this.DatabaseSession).WithCountry(netherlands).WithName("RABOBANK GROEP").WithBic("RABONL2U").Build();

            var ownBankAccount = new OwnBankAccountBuilder(this.DatabaseSession)
                .WithDescription("BE23 3300 6167 6391")
                .WithBankAccount(new BankAccountBuilder(this.DatabaseSession).WithBank(bank).WithCurrency(euro).WithIban("NL50RABO0109546784").WithNameOnAccount("Martien").Build())
                .Build();

            var store = new StoreBuilder(this.DatabaseSession)
                .WithName("Organisation store")
                .WithDefaultCarrier(new Carriers(this.DatabaseSession).Fedex)
                .WithDefaultShipmentMethod(new ShipmentMethods(this.DatabaseSession).Ground)
                .WithPaymentMethod(ownBankAccount)
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(ownBankAccount, store.DefaultPaymentMethod);
        }
Example #3
0
        public void GivenPurchaseInvoice_WhenGettingInvoiceNumberWithoutFormat_ThenInvoiceNumberShouldBeReturned()
        {
            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 internalOrganisation = new InternalOrganisationBuilder(this.DatabaseSession)
                .WithName("org")
                .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain)
                .WithDefaultPaymentMethod(ownBankAccount)
                .WithPreferredCurrency(euro)
                .Build();

            var invoice1 = new PurchaseInvoiceBuilder(this.DatabaseSession)
                .WithPurchaseInvoiceType(new PurchaseInvoiceTypes(this.DatabaseSession).PurchaseInvoice)
                .WithBilledToInternalOrganisation(internalOrganisation)
                .Build();

            Assert.AreEqual("1", invoice1.InvoiceNumber);

            var invoice2 = new PurchaseInvoiceBuilder(this.DatabaseSession)
                .WithPurchaseInvoiceType(new PurchaseInvoiceTypes(this.DatabaseSession).PurchaseInvoice)
                .WithBilledToInternalOrganisation(internalOrganisation)
                .Build();

            Assert.AreEqual("2", invoice2.InvoiceNumber);
        }
Example #4
0
        public void GivenGeographicBoundary_WhenDeriving_ThenFormattedFullAddressIsSet()
        {
            var city = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            var postalCode = new PostalCodeBuilder(this.DatabaseSession).WithCode("2800").Build();
            var country = new Countries(this.DatabaseSession).FindBy(Countries.Meta.IsoCode, "BE");

            var address = new PostalAddressBuilder(this.DatabaseSession).WithAddress1("Haverwerf 15").Build();

            this.DatabaseSession.Derive(false);

            Assert.AreEqual("Haverwerf 15", address.FormattedFullAddress);

            address.Address2 = "address2";

            this.DatabaseSession.Derive(false);

            Assert.AreEqual("Haverwerf 15<br />address2", address.FormattedFullAddress);

            address.RemoveAddress2();

            address.AddGeographicBoundary(postalCode);
            address.AddGeographicBoundary(city);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual("Haverwerf 15<br />2800 Mechelen", address.FormattedFullAddress);

            address.AddGeographicBoundary(country);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual("Haverwerf 15<br />2800 Mechelen<br />Belgium", address.FormattedFullAddress);
        }
Example #5
0
        public void GivenSetConfiguration_WhenApplied_ThenCountryEuMemberStateIsSet()
        {
            var finland = new Countries(this.DatabaseSession).FindBy(Countries.Meta.IsoCode, "FI");
            Assert.IsTrue(finland.EuMemberState.Value);

            var norway = new Countries(this.DatabaseSession).FindBy(Countries.Meta.IsoCode, "NO");
            Assert.IsFalse(norway.EuMemberState.Value);
        }
Example #6
0
        public void GivenSetConfiguration_WhenApplied_ThenCountryIbanDataIsSet()
        {
            var finland = new Countries(this.DatabaseSession).FindBy(Countries.Meta.IsoCode, "FI");
            Assert.AreEqual(18, finland.IbanLength);
            Assert.AreEqual(@"\d{14}", finland.IbanRegex);

            var norway = new Countries(this.DatabaseSession).FindBy(Countries.Meta.IsoCode, "NO");
            Assert.AreEqual(15, norway.IbanLength);
            Assert.AreEqual(@"\d{11}", norway.IbanRegex);
        }
Example #7
0
        public void GivenBankWithBic_WhenDeriving_ThenFirstfourCharactersMustBeAlphabetic()
        {
            var netherlands = new Countries(this.DatabaseSession).CountryByIsoCode["NL"];

            var bank = new BankBuilder(this.DatabaseSession).WithCountry(netherlands).WithName("RABOBANK GROEP").WithBic("RABONL2U").Build();

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

            bank.Bic = "RAB1NL2U";

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);
        }
Example #8
0
        public void GivenBankAccount_WhenDeriving_ThenIbanMustBeUnique()
        {
            var netherlands = new Countries(this.DatabaseSession).CountryByIsoCode["NL"];
            var euro = netherlands.Currency;

            var bank = new BankBuilder(this.DatabaseSession).WithCountry(netherlands).WithName("RABOBANK GROEP").WithBic("RABONL2U").Build();
            new BankAccountBuilder(this.DatabaseSession).WithBank(bank).WithCurrency(euro).WithIban("NL50RABO0109546784").Build();

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

            new BankAccountBuilder(this.DatabaseSession).WithBank(bank).WithCurrency(euro).WithIban("NL50RABO0109546784").Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);
        }
Example #9
0
        public void GivenBankWithBic_WhenDeriving_ThenStringLengthMustBeEightOrEleven()
        {
            var netherlands = new Countries(this.DatabaseSession).CountryByIsoCode["NL"];

            var bank = new BankBuilder(this.DatabaseSession).WithCountry(netherlands).WithName("RABOBANK GROEP").WithBic("RABONL2").Build();

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

            bank.Bic = "RABONL2UAAAA";

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

            bank.Bic = "RABONL2UAAA";

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Example #10
0
File: Bank.cs Project: Allors/apps
        public void AppsOnDerive(ObjectOnDerive method)
        {
            var derivation = method.Derivation;

            if (this.ExistBic)
            {
                if (!Regex.IsMatch(this.Bic, "^([a-zA-Z]){4}([a-zA-Z]){2}([0-9a-zA-Z]){2}([0-9a-zA-Z]{3})?$"))
                {
                    derivation.Validation.AddError(this, this.Meta.Bic, ErrorMessages.NotAValidBic);
                }

                var country = new Countries(this.Strategy.Session).FindBy(M.Country.IsoCode, this.Bic.Substring(4, 2));
                if (country == null)
                {
                    derivation.Validation.AddError(this, this.Meta.Bic, ErrorMessages.NotAValidBic);
                }
            }
        }
Example #11
0
        public void GivenLocaleWhenValidatingThenRequiredRelationsMustExist()
        {
            var dutch = new Languages(this.DatabaseSession).LanguageByCode["nl"];
            var netherlands = new Countries(this.DatabaseSession).CountryByIsoCode["NL"];

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

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

            builder.WithLanguage(dutch).Build();

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

            builder.WithCountry(netherlands).Build();

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Example #12
0
        public void GivenGeographicBoundary_WhenDeriving_ThenCountryCityAndPostalCodeAreDerived()
        {
            var city = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            var postalCode = new PostalCodeBuilder(this.DatabaseSession).WithCode("2800").Build();
            var country = new Countries(this.DatabaseSession).FindBy(Countries.Meta.IsoCode, "BE");

            var address = new PostalAddressBuilder(this.DatabaseSession)
                .WithAddress1("Haverwerf 15")
                .WithGeographicBoundary(postalCode)
                .WithGeographicBoundary(city)
                .WithGeographicBoundary(country)
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(postalCode, address.PostalCode);
            Assert.AreEqual(city, address.City);
            Assert.AreEqual(country, address.Country);
        }
Example #13
0
        public void GivenBankAccount_WhenOwnBankAccount_ThenRequiredRelationsMustExist()
        {
            var netherlands = new Countries(this.DatabaseSession).CountryByIsoCode["NL"];
            var euro = netherlands.Currency;
            var bank = new BankBuilder(this.DatabaseSession).WithCountry(netherlands).WithName("RABOBANK GROEP").WithBic("RABONL2U").Build();

            this.DatabaseSession.Commit();

            var builder = new BankAccountBuilder(this.DatabaseSession).WithIban("NL50RABO0109546784");
            var bankAccount = builder.Build();

            new OwnBankAccountBuilder(this.DatabaseSession).WithBankAccount(bankAccount).Build();

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

            this.DatabaseSession.Rollback();

            builder.WithBank(bank);
            bankAccount = builder.Build();

            new OwnBankAccountBuilder(this.DatabaseSession).WithBankAccount(bankAccount).Build();

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

            this.DatabaseSession.Rollback();

            builder.WithCurrency(euro);
            bankAccount = builder.Build();

            new OwnBankAccountBuilder(this.DatabaseSession).WithBankAccount(bankAccount).Build();

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

            this.DatabaseSession.Rollback();

            builder.WithNameOnAccount("name");
            bankAccount = builder.Build();

            new OwnBankAccountBuilder(this.DatabaseSession).WithBankAccount(bankAccount).WithDescription("description").Build();

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Example #14
0
        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 GivenSupplierRelationship_WhenDeriving_ThenSubAccountNumberMustBeUniqueWithinInternalOrganisation()
        {
            var supplier2 = new OrganisationBuilder(this.Session).WithName("supplier").Build();

            this.Session.Derive();

            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 internalOrganisation2 = new OrganisationBuilder(this.Session)
                                        .WithIsInternalOrganisation(true)
                                        .WithName("internalOrganisation2")
                                        .WithDefaultCollectionMethod(ownBankAccount)
                                        .Build();

            this.Session.Derive();

            var supplierRelationship2 = new SupplierRelationshipBuilder(this.Session)
                                        .WithSupplier(supplier2)
                                        .WithInternalOrganisation(internalOrganisation2)
                                        .WithFromDate(DateTime.UtcNow)
                                        .Build();

            this.Session.Derive();

            var partyFinancial2 = supplier2.PartyFinancialRelationshipsWhereParty.First(v => Equals(v.InternalOrganisation, supplierRelationship2.InternalOrganisation));

            partyFinancial2.SubAccountNumber = 19;

            Assert.False(this.Session.Derive(false).HasErrors);
        }
        public void GivenOwnBankAccount_WhenDeriving_ThenBankAccountRelationMustExist()
        {
            var netherlands = new Countries(this.Session).CountryByIsoCode["NL"];
            var euro        = netherlands.Currency;

            var bank        = new BankBuilder(this.Session).WithCountry(netherlands).WithName("RABOBANK GROEP").WithBic("RABONL2U").Build();
            var bankAccount = new BankAccountBuilder(this.Session).WithBank(bank).WithCurrency(euro).WithIban("NL50RABO0109546784").WithNameOnAccount("Martien").Build();

            this.Session.Commit();

            var builder = new OwnBankAccountBuilder(this.Session);

            builder.Build();

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

            this.Session.Rollback();

            builder.WithBankAccount(bankAccount);
            builder.Build();

            Assert.False(this.Session.Derive(false).HasErrors);
        }
Example #17
0
        protected override void CoreSetup(Setup setup)
        {
            var countries = new Countries(this.Session);
            var languages = new Languages(this.Session);

            var merge = this.LocaleByIdentifier.Merger().Action();

            merge(EnglishGreatBritainName, v =>
            {
                v.Country  = countries.CountryByIsoCode["GB"];
                v.Language = languages.LanguageByCode["en"];
            });

            merge(EnglishUnitedStatesName, v =>
            {
                v.Country  = countries.CountryByIsoCode["US"];
                v.Language = languages.LanguageByCode["en"];
            });

            merge(DutchNetherlandsName, v =>
            {
                v.Country  = countries.CountryByIsoCode["NL"];
                v.Language = languages.LanguageByCode["nl"];
            });

            merge(DutchBelgiumName, v =>
            {
                v.Country  = countries.CountryByIsoCode["BE"];
                v.Language = languages.LanguageByCode["nl"];
            });

            merge(SpanishName, v =>
            {
                v.Country  = countries.CountryByIsoCode["ES"];
                v.Language = languages.LanguageByCode["es"];
            });
        }
Example #18
0
        private static void SetupFull()
        {
            var configuration = new Adapters.Memory.IntegerId.Configuration { ObjectFactory = Config.ObjectFactory };
            Config.Default = new Adapters.Memory.IntegerId.Database(configuration);

            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-GB");
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-GB");

            var database = Config.Default;
            database.Init();

            using (var session = database.CreateSession())
            {
                new Setup(session, null).Apply();
                new Security(session).Apply();

                session.Derive(true);
                session.Commit();

                using (var stringWriter = new StringWriter())
                {
                    using (var writer = new XmlTextWriter(stringWriter))
                    {
                        database.Save(writer);
                        basicXml = stringWriter.ToString();
                    }
                }

                var singleton = Singleton.Instance(session);
                singleton.Guest = new PersonBuilder(session).WithUserName("guest").WithLastName("guest").Build();

                var administrator = new PersonBuilder(session).WithUserName("administrator").WithLastName("Administrator").Build();

                var belgium = new Countries(session).CountryByIsoCode["BE"];
                var euro = belgium.Currency;

                var bank = new BankBuilder(session).WithCountry(belgium).WithName("ING België").WithBic("BBRUBEBB").Build();

                var ownBankAccount = new OwnBankAccountBuilder(session)
                    .WithBankAccount(new BankAccountBuilder(session).WithBank(bank)
                                        .WithCurrency(euro)
                                        .WithIban("BE68539007547034")
                                        .WithNameOnAccount("Koen")
                                        .Build())
                    .WithDescription("Main bank account")
                    .Build();

                var postalBoundary = new PostalBoundaryBuilder(session).WithLocality("Mechelen").WithCountry(belgium).Build();
                var postalAddress = new PostalAddressBuilder(session).WithAddress1("Kleine Nieuwedijkstraat 2").WithPostalBoundary(postalBoundary).Build();

                var billingAddress =
                    new PartyContactMechanismBuilder(session).WithContactMechanism(postalAddress).WithContactPurpose(
                        new ContactMechanismPurposes(session).BillingAddress).WithUseAsDefault(true).Build();

                var shippingAddress =
                    new PartyContactMechanismBuilder(session).WithContactMechanism(postalAddress).WithContactPurpose(
                        new ContactMechanismPurposes(session).ShippingAddress).WithUseAsDefault(true).Build();

                var internalOrganisation = new InternalOrganisationBuilder(session)
                    .WithLocale(new Locales(session).EnglishGreatBritain)
                    .WithName("internalOrganisation")
                    .WithPreferredCurrency(euro)
                    .WithIncomingShipmentNumberPrefix("incoming shipmentno: ")
                    .WithPurchaseInvoiceNumberPrefix("incoming invoiceno: ")
                    .WithPurchaseOrderNumberPrefix("purchase orderno: ")
                    .WithPartyContactMechanism(billingAddress)
                    .WithPartyContactMechanism(shippingAddress)
                    .WithEmployeeRole(new Roles(session).Administrator)
                    .WithEmployeeRole(new Roles(session).Procurement)
                    .WithEmployeeRole(new Roles(session).Sales)
                    .WithEmployeeRole(new Roles(session).Operations)
                    .WithEmployeeRole(new Roles(session).Administrator)
                    .WithDefaultPaymentMethod(ownBankAccount)
                    .Build();

                Singleton.Instance(session).DefaultInternalOrganisation = internalOrganisation;

                var facility = new WarehouseBuilder(session).WithName("facility").WithOwner(internalOrganisation).Build();
                internalOrganisation.DefaultFacility = facility;

                new StoreBuilder(session)
                    .WithName("store")
                    .WithDefaultFacility(facility)
                    .WithOwner(internalOrganisation)
                    .WithOutgoingShipmentNumberPrefix("shipmentno: ")
                    .WithSalesInvoiceNumberPrefix("invoiceno: ")
                    .WithSalesOrderNumberPrefix("orderno: ")
                    .WithDefaultShipmentMethod(new ShipmentMethods(session).Ground)
                    .WithDefaultCarrier(new Carriers(session).Fedex)
                    .WithCreditLimit(500)
                    .WithPaymentGracePeriod(10)
                    .Build();

                var customer = new OrganisationBuilder(session).WithName("customer").WithLocale(singleton.DefaultLocale).Build();
                var supplier = new OrganisationBuilder(session).WithName("supplier").WithLocale(singleton.DefaultLocale).Build();
                var purchaser = new PersonBuilder(session).WithLastName("purchaser").WithUserName("purchaser").Build();
                var salesrep = new PersonBuilder(session).WithLastName("salesRep").WithUserName("salesRep").Build();
                var orderProcessor =
                    new PersonBuilder(session).WithLastName("orderProcessor").WithUserName("orderProcessor").Build();

                new CustomerRelationshipBuilder(session).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).WithFromDate(DateTime.UtcNow).Build();

                new SupplierRelationshipBuilder(session).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).WithFromDate(DateTime.UtcNow).Build();

                new EmploymentBuilder(session).WithFromDate(DateTime.UtcNow).WithEmployee(purchaser).WithEmployer(internalOrganisation).Build();

                new EmploymentBuilder(session).WithFromDate(DateTime.UtcNow).WithEmployee(salesrep).WithEmployer(internalOrganisation).Build();

                new EmploymentBuilder(session).WithFromDate(DateTime.UtcNow).WithEmployee(orderProcessor).WithEmployer(internalOrganisation).Build();

                new SalesRepRelationshipBuilder(session).WithFromDate(DateTime.UtcNow).WithCustomer(customer).WithSalesRepresentative(salesrep).Build();

                session.Derive(true);

                var administrators = new UserGroups(session).Administrators;
                administrators.AddMember(administrator);

                var usergroups = internalOrganisation.UserGroupsWhereParty;
                usergroups = internalOrganisation.UserGroupsWhereParty;
                usergroups.Filter.AddEquals(UserGroups.Meta.Parent, new Roles(session).Operations.UserGroupWhereRole);
                var userGroup = usergroups.First;

                userGroup.AddMember(orderProcessor);

                usergroups = internalOrganisation.UserGroupsWhereParty;
                usergroups.Filter.AddEquals(UserGroups.Meta.Parent, new Roles(session).Procurement.UserGroupWhereRole);
                userGroup = usergroups.First;

                userGroup.AddMember(purchaser);

                session.Derive(true);
                session.Commit();

                using (var stringWriter = new StringWriter())
                {
                    using (var writer = new XmlTextWriter(stringWriter))
                    {
                        database.Save(writer);
                        fullXml = stringWriter.ToString();
                    }
                }
            }
        }
Example #19
0
        public override void Init()
        {
            base.Init();

            var belgium = new Countries(this.DatabaseSession).CountryByIsoCode["BE"];
            this.euro = belgium.Currency;

            var bank = new BankBuilder(this.DatabaseSession).WithCountry(belgium).WithName("ING België").WithBic("BBRUBEBB").Build();

            this.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();

            this.billingAddress = new PartyContactMechanismBuilder(this.DatabaseSession)
                .WithContactMechanism(new WebAddressBuilder(this.DatabaseSession).WithElectronicAddressString("billfrom").Build())
                .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).BillingAddress)
                .WithUseAsDefault(true)
                .Build();

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();
        }
Example #20
0
        public void GivenSalesInvoiceCreatedBySalesRep_WhenCurrentUserInAnotherSalesRepUserGroup_ThenAccessIsDenied()
        {
            var salesRep2 = new PersonBuilder(this.DatabaseSession).WithUserName("salesRep2").WithLastName("salesRep2").Build();
            var customer2 = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build();
            var contactMechanism = new PostalAddressBuilder(this.DatabaseSession)
                .WithAddress1("Haverwerf 15")
                .WithPostalBoundary(new PostalBoundaryBuilder(this.DatabaseSession)
                                        .WithLocality("Mechelen")
                                        .WithCountry(new Countries(this.DatabaseSession).FindBy(Countries.Meta.IsoCode, "BE"))
                                        .Build())

                .Build();

            var belgium = new Countries(this.DatabaseSession).CountryByIsoCode["BE"];
            var euro = belgium.Currency;

            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            var mechelenAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build();

            var billToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession)
                .WithContactMechanism(mechelenAddress)
                .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).BillingAddress)
                .WithUseAsDefault(true)
                .Build();

            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 internalOrganisation2 = new InternalOrganisationBuilder(this.DatabaseSession)
                .WithName("internalOrganisation2")
                .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain)
                .WithEmployeeRole(new Roles(this.DatabaseSession).Administrator)
                .WithEmployeeRole(new Roles(this.DatabaseSession).Sales)
                .WithDefaultPaymentMethod(ownBankAccount)
                .WithPreferredCurrency(euro)
                .WithPartyContactMechanism(billToMechelen)
                .Build();

            var facility = new WarehouseBuilder(this.DatabaseSession).WithName("facility").WithOwner(internalOrganisation2).Build();
            internalOrganisation2.DefaultFacility = facility;

            new StoreBuilder(this.DatabaseSession)
                .WithName("store")
                .WithDefaultFacility(facility)
                .WithOwner(internalOrganisation2)
                .WithDefaultShipmentMethod(new ShipmentMethods(this.DatabaseSession).Ground)
                .WithDefaultCarrier(new Carriers(this.DatabaseSession).Fedex)
                .WithCreditLimit(500)
                .WithPaymentGracePeriod(10)
                .Build();

            new EmploymentBuilder(this.DatabaseSession).WithEmployee(salesRep2).WithEmployer(internalOrganisation2).WithFromDate(DateTime.UtcNow).Build();

            new CustomerRelationshipBuilder(this.DatabaseSession)
                .WithCustomer(customer2)
                .WithInternalOrganisation(internalOrganisation2)
                .WithFromDate(DateTime.UtcNow)
                .Build();

            new SalesRepRelationshipBuilder(this.DatabaseSession)
                .WithSalesRepresentative(salesRep2)
                .WithCustomer(customer2)
                .WithInternalOrganisation(internalOrganisation2)
                .WithFromDate(DateTime.UtcNow)
                .Build();

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("salesRep2", "Forms"), new string[0]);

            var invoice = new SalesInvoiceBuilder(this.DatabaseSession)
                .WithBilledFromInternalOrganisation(internalOrganisation2)
                .WithBillToCustomer(customer2)
                .WithBillToContactMechanism(contactMechanism)
                .Build();

            this.DatabaseSession.Derive(true);

            var acl = new AccessControlList(invoice, new Users(this.DatabaseSession).GetCurrentUser());

            Assert.IsTrue(acl.CanWrite(SalesInvoices.Meta.Comment));
            Assert.IsTrue(acl.CanRead(SalesInvoices.Meta.Comment));
            Assert.IsTrue(acl.CanExecute(SalesInvoices.Meta.Send));

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("salesRep", "Forms"), new string[0]);
            acl = new AccessControlList(invoice, new Users(this.DatabaseSession).GetCurrentUser());

            Assert.IsFalse(acl.HasReadOperation);
        }
Example #21
0
        private void DeriveIban(IDerivation derivation)
        {
            if (this.ExistIban)
            {
                var iban = Regex.Replace(this.Iban, @"\s", "").ToUpper(); // remove empty space & convert all uppercase

                if (Regex.IsMatch(iban, @"\W")) // contains chars other than (a-zA-Z0-9)
                {
                    derivation.Validation.AddError(this, this.Meta.Iban, ErrorMessages.IbanIllegalCharacters);
                }

                if (!Regex.IsMatch(iban, @"^\D\D\d\d.+")) // first chars are letter letter digit digit
                {
                    derivation.Validation.AddError(this, this.Meta.Iban, ErrorMessages.IbanStructuralFailure);
                }

                if (Regex.IsMatch(iban, @"^\D\D00.+|^\D\D01.+|^\D\D99.+")) // check digit are 00 or 01 or 99
                {
                    derivation.Validation.AddError(this, this.Meta.Iban, ErrorMessages.IbanCheckDigitsError);
                }

                var country = new Countries(this.Strategy.Session).FindBy(M.Country.IsoCode, this.Iban.Substring(0, 2));

                if (country == null || !country.ExistIbanRegex || !country.ExistIbanLength)
                {
                    derivation.Validation.AddError(this, this.Meta.Iban, ErrorMessages.IbanValidationUnavailable);
                }

                if (country != null && country.ExistIbanRegex && country.ExistIbanLength)
                {
                    if (iban.Length != country.IbanLength) // fits length to country
                    {
                        derivation.Validation.AddError(this, this.Meta.Iban, ErrorMessages.IbanLengthFailure);
                    }

                    if (!Regex.IsMatch(iban.Remove(0, 4), country.IbanRegex)) // check country specific structure
                    {
                        derivation.Validation.AddError(this, this.Meta.Iban, ErrorMessages.IbanStructuralFailure);
                    }
                }

                if (!derivation.Validation.HasErrors)
                {
                    // ******* from wikipedia.org
                    //The checksum is a basic ISO 7064 mod 97-10 calculation where the remainder must equal 1.
                    //To validate the checksum:
                    //1- Check that the total IBAN length is correct as per the country. If not, the IBAN is invalid.
                    //2- Move the four initial characters to the end of the string.
                    //3- Replace each letter in the string with two digits, thereby expanding the string, where A=10, B=11, ..., Z=35.
                    //4- Interpret the string as a decimal integer and compute the remainder of that number on division by 97.
                    //The IBAN number can only be valid if the remainder is 1.
                    var modifiedIban = iban.ToUpper().Substring(4) + iban.Substring(0, 4);
                    modifiedIban = Regex.Replace(modifiedIban, @"\D", m => (m.Value[0] - 55).ToString(CultureInfo.InvariantCulture));

                    var remainer = 0;
                    while (modifiedIban.Length >= 7)
                    {
                        remainer = int.Parse(remainer + modifiedIban.Substring(0, 7)) % 97;
                        modifiedIban = modifiedIban.Substring(7);
                    }

                    remainer = int.Parse(remainer + modifiedIban) % 97;

                    if (remainer != 1)
                    {
                        derivation.Validation.AddError(this, this.Meta.Iban, ErrorMessages.IbanIncorrect);
                    }
                }
            }
        }
Example #22
0
        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);
        }
Example #23
0
        protected override void BaseSetup(Setup setup)
        {
            var dutchLocale = new Locales(this.Session).DutchNetherlands;
            var netherlands = new Countries(this.Session).FindBy(M.Country.IsoCode, "NL");
            var belgium     = new Countries(this.Session).FindBy(M.Country.IsoCode, "BE");
            var spain       = new Countries(this.Session).FindBy(M.Country.IsoCode, "ES");

            var merge         = this.Cache.Merger().Action();
            var localisedName = new LocalisedTextAccessor(this.Meta.LocalisedNames);

            merge(DutchStandardId, v =>
            {
                v.Name = "Dutch standard VAT tariff";
                localisedName.Set(v, dutchLocale, "Nederland hoog BTW-tarief");
                v.Country  = netherlands;
                v.IsActive = true;
            });
            var vatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, DutchStandardId);

            vatregime.AddVatRate(new VatRates(this.Session).Dutch21);

            merge(DutchReducedId, v =>
            {
                v.Name = "Dutch reduced VAT tariff";
                localisedName.Set(v, dutchLocale, "Nederland laag BTW-tarief");
                v.Country  = netherlands;
                v.IsActive = true;
            });
            vatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, DutchReducedId);
            vatregime.AddVatRate(new VatRates(this.Session).Dutch9);

            merge(BelgiumStandardId, v =>
            {
                v.Name = "Belgium standard VAT tariff";
                localisedName.Set(v, dutchLocale, "Belgie hoog BTW-tarief");
                v.Country  = belgium;
                v.IsActive = true;
            });
            vatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, BelgiumStandardId);
            vatregime.AddVatRate(new VatRates(this.Session).Belgium21);

            merge(BelgiumReducedTableAId, v =>
            {
                v.Name = "Belgium reduced VAT 6%";
                localisedName.Set(v, dutchLocale, "Belgie laag BTW-tarief 6%");
                v.Country  = belgium;
                v.IsActive = true;
            });
            vatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, BelgiumReducedTableAId);
            vatregime.AddVatRate(new VatRates(this.Session).Belgium6);

            merge(BelgiumReducedTableBId, v =>
            {
                v.Name = "Belgium reduced VAT tariff 12%";
                localisedName.Set(v, dutchLocale, "Belgie laag BTW-tarief 12%");
                v.Country  = belgium;
                v.IsActive = true;
            });
            vatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, BelgiumReducedTableBId);
            vatregime.AddVatRate(new VatRates(this.Session).Belgium12);

            merge(ServiceB2BId, v =>
            {
                v.Name = "Service B2B: Not VAT assessable";
                localisedName.Set(v, dutchLocale, "Service B2B: Niet BTW-plichtig");
                v.VatClause = new VatClauses(this.Session).ServiceB2B;
                v.Country   = belgium;
                v.IsActive  = true;
            });
            vatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, ServiceB2BId);
            vatregime.AddVatRate(new VatRates(this.Session).BelgiumServiceB2B0);

            merge(SpainStandardId, v =>
            {
                v.Name = "Spain standard VAT tariff";
                localisedName.Set(v, dutchLocale, "Spanje hoog BTW-tarief");
                v.Country  = spain;
                v.IsActive = true;
            });
            vatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, SpainStandardId);
            vatregime.AddVatRate(new VatRates(this.Session).Spain21);

            merge(SpainReducedId, v =>
            {
                v.Name = "Spain reduced VAT tariff";
                localisedName.Set(v, dutchLocale, "Spanje laag BTW-tarief");
                v.Country  = spain;
                v.IsActive = true;
            });
            vatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, SpainReducedId);
            vatregime.AddVatRate(new VatRates(this.Session).Spain10);

            merge(SpainSuperReducedId, v =>
            {
                v.Name = "Spain super reduced VAT tariff";
                localisedName.Set(v, dutchLocale, "Spanje extra laag BTW-tarief");
                v.Country  = spain;
                v.IsActive = true;
            });
            vatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, SpainSuperReducedId);
            vatregime.AddVatRate(new VatRates(this.Session).Spain4);

            merge(SpainCanaryIslandsId, v =>
            {
                v.Name = "Spain Canary islands VAT tariff";
                localisedName.Set(v, dutchLocale, "Spanje Canarische eilanden BTW-tarief");
                v.Country  = spain;
                v.IsActive = true;
            });
            vatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, SpainCanaryIslandsId);
            vatregime.AddVatRate(new VatRates(this.Session).Spain7);

            merge(ZeroRatedId, v =>
            {
                v.Name = "VAT Zero rated tariff";
                localisedName.Set(v, dutchLocale, "BTW nul tarief");
                v.IsActive = true;
            });
            var zeroRatedvatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, ZeroRatedId);

            zeroRatedvatregime.AddVatRate(new VatRates(this.Session).ZeroRated0);

            merge(ExemptId, v =>
            {
                v.Name = "VAT Exempt";
                localisedName.Set(v, dutchLocale, "Vrijgesteld van BTW");
                v.IsActive = true;
            });
            var exemptVatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, ExemptId);

            exemptVatregime.AddVatRate(new VatRates(this.Session).Exempt0);

            merge(IntraCommunautairId, v =>
            {
                v.Name = "VAT intra-community";
                localisedName.Set(v, dutchLocale, "BTW Intracommunautair");
                v.VatClause = new VatClauses(this.Session).Intracommunautair;
                v.IsActive  = true;
            });
            var EuVatregime = new VatRegimes(this.Session).FindBy(M.VatRegime.UniqueId, IntraCommunautairId);

            EuVatregime.AddVatRate(new VatRates(this.Session).Intracommunity0);

            foreach (Country country in this.Session.Extent <Country>())
            {
                ((CountryDerivedRoles)country).AddDerivedVatRegime(zeroRatedvatregime);
                ((CountryDerivedRoles)country).AddDerivedVatRegime(exemptVatregime);

                if (Countries.EuMemberStates.Contains(country.IsoCode))
                {
                    ((CountryDerivedRoles)country).AddDerivedVatRegime(EuVatregime);
                }
            }
        }
Example #24
0
        public void GivenCustomerShipment_WhenDeriving_ThenBillFromContactMechanismMustExist()
        {
            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("own account")
                .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 customer = new PersonBuilder(this.DatabaseSession).WithLastName("customer").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 internalOrganisation = new InternalOrganisationBuilder(this.DatabaseSession)
                .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain)
                .WithName("internalOrganisation")
                .WithPreferredCurrency(euro)
                .WithDefaultPaymentMethod(ownBankAccount)
                .Build();

            internalOrganisation.AddPartyContactMechanism(billingAddress);

            this.DatabaseSession.Derive(true);

            var shipment1 = new CustomerShipmentBuilder(this.DatabaseSession)
                .WithBillFromInternalOrganisation(internalOrganisation)
                .WithShipToParty(customer)
                .WithShipToAddress(new PostalAddresses(this.DatabaseSession).Extent().First)
                .WithShipmentMethod(new ShipmentMethods(this.DatabaseSession).Boat)
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(address1, shipment1.BillFromContactMechanism);
        }
Example #25
0
        public void GivenPostalBoundary_WhenDeriving_ThenCountryIsDerived()
        {
            var country = new Countries(this.DatabaseSession).FindBy(Countries.Meta.IsoCode, "BE");
            var postalBoundary = new PostalBoundaryBuilder(this.DatabaseSession).WithLocality("locality").WithCountry(country).Build();

            var address = new PostalAddressBuilder(this.DatabaseSession)
                .WithAddress1("Haverwerf 15")
                .WithPostalBoundary(postalBoundary)
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.IsNull(address.PostalCode);
            Assert.IsNull(address.City);
            Assert.AreEqual(country, address.Country);
        }
Example #26
0
        public void GivenPostalBoundary_WhenDeriving_ThenFormattedFullAddressIsSet()
        {
            var country = new Countries(this.DatabaseSession).CountryByIsoCode["BE"];
            var postalBoundary = new PostalBoundaryBuilder(this.DatabaseSession).WithLocality("Mechelen").WithCountry(country).Build();
            this.DatabaseSession.Derive();
            this.DatabaseSession.Commit();

            var address = new PostalAddressBuilder(this.DatabaseSession).WithAddress1("Haverwerf 15").Build();

            this.DatabaseSession.Derive(false);

            Assert.AreEqual("Haverwerf 15", address.FormattedFullAddress);

            address.Address2 = "address2";

            this.DatabaseSession.Derive(false);

            Assert.AreEqual("Haverwerf 15<br />address2", address.FormattedFullAddress);

            address.RemoveAddress2();

            address.PostalBoundary = postalBoundary;

            this.DatabaseSession.Derive(true);

            Assert.AreEqual("Haverwerf 15<br />Mechelen<br />Belgium", address.FormattedFullAddress);

            address.PostalBoundary.PostalCode = "2800";

            this.DatabaseSession.Derive(true);

            Assert.AreEqual("Haverwerf 15<br />2800 Mechelen<br />Belgium", address.FormattedFullAddress);
        }
Example #27
0
        public void GivenAccountingPeriod_WhenMonthInNextQuarterIsAdded_ThenPeriodsForMonthAndForQuarterAreAdded()
        {
            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("own account")
                .WithBankAccount(new BankAccountBuilder(this.DatabaseSession).WithBank(bank).WithCurrency(euro).WithIban("BE23 3300 6167 6391").WithNameOnAccount("Koen").Build())
                .Build();

            var organisation = new InternalOrganisationBuilder(this.DatabaseSession)
                .WithName("Internal")
                .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain)
                .WithPreferredCurrency(euro)
                .WithDefaultPaymentMethod(ownBankAccount)
                .Build();

            organisation.AppsStartNewFiscalYear();

            Assert.AreEqual(4, this.DatabaseSession.Extent<AccountingPeriod>().Count);

            organisation.ActualAccountingPeriod.AddNextMonth();

            Assert.AreEqual(5, this.DatabaseSession.Extent<AccountingPeriod>().Count);

            organisation.ActualAccountingPeriod.AddNextMonth();

            Assert.AreEqual(6, this.DatabaseSession.Extent<AccountingPeriod>().Count);

            var fourthMonth = organisation.ActualAccountingPeriod.AddNextMonth();

            Assert.AreEqual(8, this.DatabaseSession.Extent<AccountingPeriod>().Count);

            Assert.AreEqual(organisation.ActualAccountingPeriod.PeriodNumber + 3, fourthMonth.PeriodNumber);
            Assert.AreEqual(new TimeFrequencies(this.DatabaseSession).Month, fourthMonth.TimeFrequency);
            Assert.AreEqual(organisation.ActualAccountingPeriod.FromDate.AddMonths(3).Date, fourthMonth.FromDate);
            Assert.AreEqual(organisation.ActualAccountingPeriod.FromDate.AddMonths(4).AddSeconds(-1).Date, fourthMonth.ThroughDate);
            Assert.IsTrue(fourthMonth.ExistParent);
            Assert.Contains(fourthMonth, organisation.AccountingPeriods);

            var secondQuarter = fourthMonth.Parent;

            Assert.AreEqual(organisation.ActualAccountingPeriod.Parent.PeriodNumber + 1, secondQuarter.PeriodNumber);
            Assert.AreEqual(new TimeFrequencies(this.DatabaseSession).Trimester, secondQuarter.TimeFrequency);
            Assert.AreEqual(organisation.ActualAccountingPeriod.Parent.FromDate.AddMonths(3).Date, secondQuarter.FromDate);
            Assert.AreEqual(organisation.ActualAccountingPeriod.Parent.FromDate.AddMonths(6).AddSeconds(-1).Date, secondQuarter.ThroughDate);
            Assert.AreEqual(organisation.ActualAccountingPeriod.Parent.Parent, secondQuarter.Parent);
            Assert.Contains(secondQuarter, organisation.AccountingPeriods);
        }
Example #28
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 #29
0
        private void DeriveIban(IDerivation derivation)
        {
            if (!string.IsNullOrEmpty(this.Iban))
            {
                var iban = Regex.Replace(this.Iban, @"\s", string.Empty).ToUpper(); // remove empty space & convert all uppercase

                if (Regex.IsMatch(iban, @"\W"))
                {
                    // contains chars other than (a-zA-Z0-9)
                    derivation.Validation.AddError(this, this.Meta.Iban, ErrorMessages.IbanIllegalCharacters);
                }

                if (!Regex.IsMatch(iban, @"^\D\D\d\d.+"))
                {
                    // first chars are letter letter digit digit
                    derivation.Validation.AddError(this, this.Meta.Iban, ErrorMessages.IbanStructuralFailure);
                }

                if (Regex.IsMatch(iban, @"^\D\D00.+|^\D\D01.+|^\D\D99.+"))
                {
                    // check digit are 00 or 01 or 99
                    derivation.Validation.AddError(this, this.Meta.Iban, ErrorMessages.IbanCheckDigitsError);
                }

                var country = new Countries(this.Strategy.Session).FindBy(M.Country.IsoCode, this.Iban.Substring(0, 2));

                if (country == null || !country.ExistIbanRegex || !country.ExistIbanLength)
                {
                    derivation.Validation.AddError(this, this.Meta.Iban, ErrorMessages.IbanValidationUnavailable);
                }

                if (country != null && country.ExistIbanRegex && country.ExistIbanLength)
                {
                    if (iban.Length != country.IbanLength)
                    {
                        // fits length to country
                        derivation.Validation.AddError(this, this.Meta.Iban, ErrorMessages.IbanLengthFailure);
                    }

                    if (!Regex.IsMatch(iban.Remove(0, 4), country.IbanRegex))
                    {
                        // check country specific structure
                        derivation.Validation.AddError(this, this.Meta.Iban, ErrorMessages.IbanStructuralFailure);
                    }
                }

                if (!derivation.Validation.HasErrors)
                {
                    // ******* from wikipedia.org
                    // The checksum is a basic ISO 7064 mod 97-10 calculation where the remainder must equal 1.
                    // To validate the checksum:
                    // 1- Check that the total IBAN length is correct as per the country. If not, the IBAN is invalid.
                    // 2- Move the four initial characters to the end of the string.
                    // 3- Replace each letter in the string with two digits, thereby expanding the string, where A=10, B=11, ..., Z=35.
                    // 4- Interpret the string as a decimal integer and compute the remainder of that number on division by 97.
                    // The IBAN number can only be valid if the remainder is 1.
                    var modifiedIban = iban.ToUpper().Substring(4) + iban.Substring(0, 4);
                    modifiedIban = Regex.Replace(modifiedIban, @"\D", m => (m.Value[0] - 55).ToString(CultureInfo.InvariantCulture));

                    var remainer = 0;
                    while (modifiedIban.Length >= 7)
                    {
                        remainer     = int.Parse(remainer + modifiedIban.Substring(0, 7)) % 97;
                        modifiedIban = modifiedIban.Substring(7);
                    }

                    remainer = int.Parse(remainer + modifiedIban) % 97;

                    if (remainer != 1)
                    {
                        derivation.Validation.AddError(this, this.Meta.Iban, ErrorMessages.IbanIncorrect);
                    }
                }
            }
        }
Example #30
0
        public void GivenPurchaseOrderCreatedByProcurementLevel1Role_WhenCurrentUserInAnotherProcurementLevel1RoleUserGroup_ThenAccessIsDenied()
        {
            var belgium = new Countries(this.DatabaseSession).CountryByIsoCode["BE"];
            var euro = belgium.Currency;

            var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build();
            var mechelenAddress = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build();

            var billToMechelen = new PartyContactMechanismBuilder(this.DatabaseSession)
                .WithContactMechanism(mechelenAddress)
                .WithContactPurpose(new ContactMechanismPurposes(this.DatabaseSession).BillingAddress)
                .WithUseAsDefault(true)
                .Build();

            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 purchaser2 = new PersonBuilder(this.DatabaseSession).WithLastName("purchaser2").WithUserName("purchaser2").Build();

            var internalOrganisation = new InternalOrganisationBuilder(this.DatabaseSession)
                .WithName("new internalOrganisation")
                .WithLocale(Singleton.Instance(this.DatabaseSession).DefaultLocale)
                .WithEmployeeRole(new Roles(this.DatabaseSession).Administrator)
                .WithDefaultPaymentMethod(ownBankAccount)
                .WithPreferredCurrency(euro)
                .WithPartyContactMechanism(billToMechelen)
                .Build();

            var supplier = new OrganisationBuilder(this.DatabaseSession).WithName("supplier").Build();
            new SupplierRelationshipBuilder(this.DatabaseSession).WithSupplier(supplier).WithInternalOrganisation(internalOrganisation).Build();

            new EmploymentBuilder(this.DatabaseSession)
                .WithFromDate(DateTime.UtcNow)
                .WithEmployee(purchaser2)
                .WithEmployer(internalOrganisation)
                .Build();

            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).WithShipToBuyer(internalOrganisation).Build();

            this.DatabaseSession.Derive(true);

            var 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));

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("purchaser2", "Forms"), new string[0]);
            acl = new AccessControlList(order, new Users(this.DatabaseSession).GetCurrentUser());

            Assert.IsFalse(acl.HasReadOperation);
        }
Example #31
0
        public void GivenPostalBoundary_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var country = new Countries(this.DatabaseSession).CountryByIsoCode["BE"];
            var postalBoundary = new PostalBoundaryBuilder(this.DatabaseSession).WithLocality("Mechelen").WithCountry(country).Build();
            this.DatabaseSession.Derive();
            this.DatabaseSession.Commit();

            new PostalAddressBuilder(this.DatabaseSession).Build();

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

            this.DatabaseSession.Rollback();

            new PostalAddressBuilder(this.DatabaseSession).WithAddress1("address1").Build();

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

            this.DatabaseSession.Rollback();

            new PostalAddressBuilder(this.DatabaseSession).WithPostalBoundary(postalBoundary).Build();

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

            this.DatabaseSession.Rollback();

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

            this.DatabaseSession.Rollback();

            new PostalAddressBuilder(this.DatabaseSession).WithAddress1("address1").WithPostalBoundary(postalBoundary).Build();

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Example #32
0
        public void GivenAccountingPeriod_WhenMonthInNextSemesterIsAdded_ThenPeriodsForMonthForQuarterAndForSemesterAreAdded()
        {
            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("own account")
                                 .WithBankAccount(new BankAccountBuilder(this.Session).WithBank(bank).WithCurrency(euro).WithIban("BE23 3300 6167 6391").WithNameOnAccount("Koen").Build())
                                 .Build();

            var organisation = new OrganisationBuilder(this.Session)
                               .WithIsInternalOrganisation(true)
                               .WithName("Internal")
                               .WithDefaultCollectionMethod(ownBankAccount)
                               .Build();

            this.Session.Derive();

            organisation.StartNewFiscalYear();

            Assert.Equal(4, this.Session.Extent <AccountingPeriod>().Count);

            organisation.ActualAccountingPeriod.AddNextMonth();

            Assert.Equal(5, this.Session.Extent <AccountingPeriod>().Count);

            organisation.ActualAccountingPeriod.AddNextMonth();

            Assert.Equal(6, this.Session.Extent <AccountingPeriod>().Count);

            organisation.ActualAccountingPeriod.AddNextMonth();

            Assert.Equal(8, this.Session.Extent <AccountingPeriod>().Count);

            organisation.ActualAccountingPeriod.AddNextMonth();

            Assert.Equal(9, this.Session.Extent <AccountingPeriod>().Count);

            organisation.ActualAccountingPeriod.AddNextMonth();

            Assert.Equal(10, this.Session.Extent <AccountingPeriod>().Count);

            var seventhMonth = organisation.ActualAccountingPeriod.AddNextMonth();

            Assert.Equal(13, this.Session.Extent <AccountingPeriod>().Count);

            var thirdQuarter = seventhMonth.Parent;

            Assert.Equal(organisation.ActualAccountingPeriod.Parent.PeriodNumber + 2, thirdQuarter.PeriodNumber);
            Assert.Equal(new TimeFrequencies(this.Session).Trimester, thirdQuarter.Frequency);
            Assert.Equal(organisation.ActualAccountingPeriod.Parent.FromDate.AddMonths(6).Date, thirdQuarter.FromDate);
            Assert.Equal(organisation.ActualAccountingPeriod.Parent.FromDate.AddMonths(9).AddSeconds(-1).Date, thirdQuarter.ThroughDate);

            var secondSemester = thirdQuarter.Parent;

            Assert.Equal(organisation.ActualAccountingPeriod.Parent.Parent.PeriodNumber + 1, secondSemester.PeriodNumber);
            Assert.Equal(new TimeFrequencies(this.Session).Semester, secondSemester.Frequency);
            Assert.Equal(organisation.ActualAccountingPeriod.Parent.Parent.FromDate.AddMonths(6).Date, secondSemester.FromDate);
            Assert.Equal(organisation.ActualAccountingPeriod.Parent.Parent.FromDate.AddMonths(12).AddSeconds(-1).Date, secondSemester.ThroughDate);
            Assert.Equal(organisation.ActualAccountingPeriod.Parent.Parent.Parent, secondSemester.Parent);
        }
Example #33
0
        public void GivenGeographicBoundary_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var country = new Countries(this.DatabaseSession).CountryByIsoCode["BE"];

            new PostalAddressBuilder(this.DatabaseSession).Build();

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

            this.DatabaseSession.Rollback();

            new PostalAddressBuilder(this.DatabaseSession).WithAddress1("address1").Build();

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

            this.DatabaseSession.Rollback();

            new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(country).Build();

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

            this.DatabaseSession.Rollback();

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

            this.DatabaseSession.Rollback();

            new PostalAddressBuilder(this.DatabaseSession).WithAddress1("address1").WithGeographicBoundary(country).Build();

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Example #34
0
        public void GivenPickListCreatedByOrderProcessor_WhenCurrentUserInAnotherOrderProcessorUserGroup_ThenAccessIsDenied()
        {
            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("own account")
                .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 orderProcessor2 = new PersonBuilder(this.DatabaseSession).WithLastName("orderProcessor2").WithUserName("orderProcessor2").Build();
            var internalOrganisation = new InternalOrganisationBuilder(this.DatabaseSession)
                .WithName("employer2")
                .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain)
                .WithEmployeeRole(new Roles(this.DatabaseSession).Administrator)
                .WithEmployeeRole(new Roles(this.DatabaseSession).Operations)
                .WithDefaultPaymentMethod(ownBankAccount)
                .WithPreferredCurrency(euro)
                .WithPartyContactMechanism(billingAddress)
                .Build();

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            var usergroups = internalOrganisation.UserGroupsWhereParty;
            usergroups.Filter.AddEquals(UserGroups.Meta.Parent, new Roles(this.DatabaseSession).Operations.UserGroupWhereRole);
            var orderProcessorUserGroup = usergroups.First;

            new EmploymentBuilder(this.DatabaseSession)
                .WithFromDate(DateTime.UtcNow)
                .WithEmployee(orderProcessor2)
                .WithEmployer(internalOrganisation)
                .Build();

            orderProcessorUserGroup.AddMember(orderProcessor2);

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("orderProcessor", "Forms"), new string[0]);
            var pickList = new PickListBuilder(this.DatabaseSession).Build();

            this.DatabaseSession.Derive(true);

            var acl = new AccessControlList(pickList, new Users(this.DatabaseSession).GetCurrentUser());

            Assert.IsTrue(acl.CanWrite(PickLists.Meta.Picker));
            Assert.IsTrue(acl.CanRead(PickLists.Meta.Picker));
            Assert.IsTrue(acl.CanExecute(PickLists.Meta.Cancel));

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("orderProcessor2", "Forms"), new string[0]);
            acl = new AccessControlList(pickList, new Users(this.DatabaseSession).GetCurrentUser());

            Assert.IsFalse(acl.HasReadOperation);
        }
Example #35
0
        private static void SetupFull()
        {
            var configuration = new Adapters.Memory.IntegerId.Configuration { ObjectFactory = Config.ObjectFactory };
            Config.Default = new Adapters.Memory.IntegerId.Database(configuration);

            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-GB");
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-GB");

            var database = Config.Default;
            database.Init();

            using (var session = database.CreateSession())
            {
                new Setup(session, null).Apply();
                new Security(session).Apply();

                session.Derive(true);
                session.Commit();

                using (var stringWriter = new StringWriter())
                {
                    using (var writer = new XmlTextWriter(stringWriter))
                    {
                        database.Save(writer);
                        basicXml = stringWriter.ToString();
                    }
                }

                var singleton = Singleton.Instance(session);
                singleton.Guest = new PersonBuilder(session).WithUserName("guest").WithLastName("guest").Build();

                var administrator = new PersonBuilder(session).WithUserName("administrator").WithLastName("Administrator").Build();

                var belgium = new Countries(session).CountryByIsoCode["BE"];
                var euro = belgium.Currency;

                session.Derive(true);
                session.Commit();

                using (var stringWriter = new StringWriter())
                {
                    using (var writer = new XmlTextWriter(stringWriter))
                    {
                        database.Save(writer);
                        fullXml = stringWriter.ToString();
                    }
                }
            }
        }