Esempio n. 1
0
        public void GivenJournal_WhenBuildWithout_ThenCloseWhenInBalanceIsFalse()
        {
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");

            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.DatabaseSession)
                .WithAccountNumber("0001")
                .WithName("GeneralLedgerAccount")
                .WithBalanceSheetAccount(true)
                .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.DatabaseSession)
                .WithInternalOrganisation(internalOrganisation)
                .WithGeneralLedgerAccount(generalLedgerAccount)
                .Build();

            var journal = new JournalBuilder(this.DatabaseSession)
                .WithInternalOrganisation(internalOrganisation)
                .WithJournalType(new JournalTypes(this.DatabaseSession).Bank)
                .WithContraAccount(internalOrganisationGlAccount)
                .WithDescription("journal")
                .Build();

            this.DatabaseSession.Derive();

            Assert.IsFalse(journal.CloseWhenInBalance);
        }
        public void GivenGeneralLedgerAccount_WhenSettingDefaultCostUnit_ThenDefaultCostUnitMustBeInListOfAllowedCostUnits()
        {
            var costUnit = new Goods(this.Session).FindBy(M.Good.Name, "good1");

            var glAccount = new GeneralLedgerAccountBuilder(this.Session)
                            .WithAccountNumber("0001")
                            .WithName("GeneralLedgerAccount")
                            .WithCostUnitAccount(true)
                            .WithCostUnitRequired(true)
                            .WithDefaultCostUnit(costUnit)
                            .WithBalanceSheetAccount(true)
                            .WithSide(new DebitCreditConstants(this.Session).Debit)
                            .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.Session).WithDescription("accountType").Build())
                            .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.Session).WithDescription("accountGroup").Build())
                            .Build();

            var derivationLog   = this.Session.Derive(false);
            var expectedMessage = ErrorMessages.CostUnitNotAllowed;

            Assert.Equal(derivationLog.Errors[0].Message, expectedMessage);

            glAccount.AddCostUnitsAllowed(costUnit);

            Assert.False(this.Session.Derive(false).HasErrors);
        }
Esempio n. 3
0
        public void GivenGeneralLedgerAccount_WhenAddedToChartOfAccounts_ThenAccountNumberMustBeUnique()
        {
            var glAccount0001 = new GeneralLedgerAccountBuilder(this.DatabaseSession)
                .WithAccountNumber("0001")
                .WithName("GeneralLedgerAccount")
                .WithBalanceSheetAccount(true)
                .WithSide(new DebitCreditConstants(this.DatabaseSession).Debit)
                .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.DatabaseSession).WithDescription("accountType").Build())
                .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.DatabaseSession).WithDescription("accountGroup").Build())
                .Build();

            var glAccount0001Dup = new GeneralLedgerAccountBuilder(this.DatabaseSession)
                .WithAccountNumber("0001")
                .WithName("GeneralLedgerAccount duplicate number")
                .WithBalanceSheetAccount(true)
                .WithSide(new DebitCreditConstants(this.DatabaseSession).Debit)
                .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.DatabaseSession).WithDescription("accountType").Build())
                .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.DatabaseSession).WithDescription("accountGroup").Build())
                .Build();

            var chart = new ChartOfAccountsBuilder(this.DatabaseSession).WithName("name").WithGeneralLedgerAccount(glAccount0001).Build();

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

            chart.AddGeneralLedgerAccount(glAccount0001Dup);

            var derivationLog = this.DatabaseSession.Derive();
            var expectedMessage = ErrorMessages.AccountNumberUniqueWithinChartOfAccounts;

            Assert.AreEqual(derivationLog.Errors[0].Message, expectedMessage);

            new ChartOfAccountsBuilder(this.DatabaseSession).WithName("another Chart").WithGeneralLedgerAccount(glAccount0001Dup).Build();

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
        public void GivenGeneralLedgerAccount_WhenAddedToChartOfAccounts_ThenAccountNumberMustBeUnique()
        {
            var glAccount0001 = new GeneralLedgerAccountBuilder(this.Session)
                                .WithAccountNumber("0001")
                                .WithName("GeneralLedgerAccount")
                                .WithBalanceSheetAccount(true)
                                .WithSide(new DebitCreditConstants(this.Session).Debit)
                                .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.Session).WithDescription("accountType").Build())
                                .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.Session).WithDescription("accountGroup").Build())
                                .Build();

            var glAccount0001Dup = new GeneralLedgerAccountBuilder(this.Session)
                                   .WithAccountNumber("0001")
                                   .WithName("GeneralLedgerAccount duplicate number")
                                   .WithBalanceSheetAccount(true)
                                   .WithSide(new DebitCreditConstants(this.Session).Debit)
                                   .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.Session).WithDescription("accountType").Build())
                                   .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.Session).WithDescription("accountGroup").Build())
                                   .Build();

            var chart = new ChartOfAccountsBuilder(this.Session).WithName("name").WithGeneralLedgerAccount(glAccount0001).Build();

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

            chart.AddGeneralLedgerAccount(glAccount0001Dup);

            var derivationLog   = this.Session.Derive(false);
            var expectedMessage = ErrorMessages.AccountNumberUniqueWithinChartOfAccounts;

            Assert.Equal(derivationLog.Errors[0].Message, expectedMessage);

            new ChartOfAccountsBuilder(this.Session).WithName("another Chart").WithGeneralLedgerAccount(glAccount0001Dup).Build();

            Assert.False(this.Session.Derive(false).HasErrors);
        }
Esempio n. 5
0
        public void GivenJournal_WhenBuildWithout_ThenUseAsDefaultIsFalse()
        {
            this.InternalOrganisation.DoAccounting = true;

            this.Session.Derive();

            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.Session)
                                       .WithAccountNumber("0001")
                                       .WithName("GeneralLedgerAccount")
                                       .WithBalanceSheetAccount(true)
                                       .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.Session)
                                                .WithGeneralLedgerAccount(generalLedgerAccount)
                                                .Build();

            var journal = new JournalBuilder(this.Session)
                          .WithJournalType(new JournalTypes(this.Session).Bank)
                          .WithContraAccount(internalOrganisationGlAccount)
                          .WithDescription("journal")
                          .Build();

            this.Session.Derive(false);

            Assert.False(journal.UseAsDefault);
        }
Esempio n. 6
0
        public void GivenJournal_WhenDeriving_ThenSingletonMustExist()
        {
            this.InternalOrganisation.DoAccounting = true;

            this.Session.Derive();

            var glAccount = new GeneralLedgerAccountBuilder(this.Session)
                            .WithAccountNumber("0001")
                            .WithName("GeneralLedgerAccount")
                            .WithBalanceSheetAccount(true)
                            .WithSide(new DebitCreditConstants(this.Session).Debit)
                            .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.Session).WithDescription("accountType").Build())
                            .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.Session).WithDescription("accountGroup").Build())
                            .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.Session)
                                                .WithFromDate(this.Session.Now())
                                                .WithGeneralLedgerAccount(glAccount)
                                                .Build();

            this.Session.Commit();

            var builder = new JournalBuilder(this.Session);

            builder.WithDescription("description");
            builder.WithJournalType(new JournalTypes(this.Session).Bank);
            builder.WithContraAccount(internalOrganisationGlAccount);
            builder.Build();

            Assert.False(this.Session.Derive(false).HasErrors);
        }
Esempio n. 7
0
        public void GivenOwnCreditCardForInternalOrganisationThatDoesAccounting_WhenDeriving_ThenEitherGeneralLedgerAccountOrJournalMustExist()
        {
            var supplier = new OrganisationBuilder(this.DatabaseSession)
                .WithName("supplier")
                .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain)
                .Build();

            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");

            var supplierRelationship = new SupplierRelationshipBuilder(this.DatabaseSession)
                .WithSupplier(supplier)
                .WithInternalOrganisation(internalOrganisation)
                .WithFromDate(DateTime.UtcNow)
                .Build();

            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.DatabaseSession)
                .WithAccountNumber("0001")
                .WithName("GeneralLedgerAccount")
                .WithBalanceSheetAccount(true)
                .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.DatabaseSession)
                .WithInternalOrganisation(internalOrganisation)
                .WithGeneralLedgerAccount(generalLedgerAccount)
                .Build();

            var journal = new JournalBuilder(this.DatabaseSession).WithDescription("journal").Build();

            var creditCard = new CreditCardBuilder(this.DatabaseSession)
                .WithCardNumber("4012888888881881")
                .WithExpirationYear(2016)
                .WithExpirationMonth(03)
                .WithNameOnCard("M.E. van Knippenberg")
                .WithCreditCardCompany(new CreditCardCompanyBuilder(this.DatabaseSession).WithName("Visa").Build())
                .Build();

            var paymentMethod = new OwnCreditCardBuilder(this.DatabaseSession)
                .WithCreditCard(creditCard)
                .WithCreditor(supplierRelationship)
                .Build();

            this.DatabaseSession.Commit();

            internalOrganisation.RemovePaymentMethods();
            internalOrganisation.AddPaymentMethod(paymentMethod);
            internalOrganisation.DoAccounting = true;

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

            paymentMethod.Journal = journal;

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

            paymentMethod.RemoveJournal();
            paymentMethod.GeneralLedgerAccount = internalOrganisationGlAccount;

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Esempio n. 8
0
        public void GivenJournal_WhenDeriving_ThenContraAccountCanNotBeChangedWhenJournalEntriesArePresent()
        {
            this.InternalOrganisation.DoAccounting = true;

            this.Session.Derive();

            var generalLedgerAccount1 = new GeneralLedgerAccountBuilder(this.Session)
                                        .WithAccountNumber("0001")
                                        .WithName("bankAccount 1")
                                        .WithBalanceSheetAccount(true)
                                        .WithSide(new DebitCreditConstants(this.Session).Debit)
                                        .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.Session).WithDescription("accountType").Build())
                                        .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.Session).WithDescription("accountGroup").Build())
                                        .Build();

            var internalOrganisationGlAccount1 = new OrganisationGlAccountBuilder(this.Session)
                                                 .WithFromDate(this.Session.Now())
                                                 .WithGeneralLedgerAccount(generalLedgerAccount1)
                                                 .Build();

            var generalLedgerAccount2 = new GeneralLedgerAccountBuilder(this.Session)
                                        .WithAccountNumber("0002")
                                        .WithName("bankAccount 2")
                                        .WithBalanceSheetAccount(true)
                                        .WithSide(new DebitCreditConstants(this.Session).Debit)
                                        .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.Session).WithDescription("accountType").Build())
                                        .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.Session).WithDescription("accountGroup").Build())
                                        .Build();

            var internalOrganisationGlAccount2 = new OrganisationGlAccountBuilder(this.Session)
                                                 .WithFromDate(this.Session.Now())
                                                 .WithGeneralLedgerAccount(generalLedgerAccount2)
                                                 .Build();

            var journal = new JournalBuilder(this.Session)
                          .WithDescription("description")
                          .WithContraAccount(internalOrganisationGlAccount1)
                          .WithJournalType(new JournalTypes(this.Session).Bank)
                          .Build();

            this.Session.Derive();

            Assert.Equal(generalLedgerAccount1, journal.PreviousContraAccount.GeneralLedgerAccount);

            journal.AddJournalEntry(new JournalEntryBuilder(this.Session)
                                    .WithJournalEntryDetail(new JournalEntryDetailBuilder(this.Session)
                                                            .WithAmount(1)
                                                            .WithDebit(true)
                                                            .WithGeneralLedgerAccount(internalOrganisationGlAccount1)
                                                            .Build())
                                    .Build());

            journal.ContraAccount = internalOrganisationGlAccount2;

            Assert.Equal("Journal.ContraAccount, Journal.PreviousContraAccount are not equal", this.Session.Derive(false).Errors[0].Message);
        }
        public void GivenGeneralLedgerAccount_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var accountGroup = new GeneralLedgerAccountGroupBuilder(this.Session).WithDescription("accountGroup").Build();
            var accountType  = new GeneralLedgerAccountTypeBuilder(this.Session).WithDescription("accountType").Build();

            this.Session.Commit();

            var builder = new GeneralLedgerAccountBuilder(this.Session);

            builder.Build();

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

            this.Session.Rollback();

            builder.WithAccountNumber("0001");
            builder.Build();

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

            this.Session.Rollback();

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

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

            this.Session.Rollback();

            builder.WithBalanceSheetAccount(true);
            builder.Build();

            this.Session.Rollback();

            builder.WithSide(new DebitCreditConstants(this.Session).Debit);
            builder.Build();

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

            this.Session.Rollback();

            builder.WithGeneralLedgerAccountGroup(accountGroup);
            builder.Build();

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

            this.Session.Rollback();

            builder.WithGeneralLedgerAccountType(accountType);
            builder.Build();

            Assert.False(this.Session.Derive(false).HasErrors);
        }
        public void GivenOwnCreditCard_WhenDeriving_ThenGeneralLedgerAccountAndJournalAtMostOne()
        {
            this.InternalOrganisation.DoAccounting = true;

            this.Session.Derive();

            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.Session)
                                       .WithAccountNumber("0001")
                                       .WithName("GeneralLedgerAccount")
                                       .WithBalanceSheetAccount(true)
                                       .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.Session)
                                                .WithGeneralLedgerAccount(generalLedgerAccount)
                                                .Build();

            var journal = new JournalBuilder(this.Session).WithDescription("journal").Build();

            var creditCard = new CreditCardBuilder(this.Session)
                             .WithCardNumber("4012888888881881")
                             .WithExpirationYear(this.Session.Now().Year + 1)
                             .WithExpirationMonth(03)
                             .WithNameOnCard("M.E. van Knippenberg")
                             .WithCreditCardCompany(new CreditCardCompanyBuilder(this.Session).WithName("Visa").Build())
                             .Build();

            var collectionMethod = new OwnCreditCardBuilder(this.Session)
                                   .WithCreditCard(creditCard)
                                   .WithGeneralLedgerAccount(internalOrganisationGlAccount)
                                   .Build();

            ((OrganisationDerivedRoles)this.InternalOrganisation).AddActiveCollectionMethod(collectionMethod);

            this.Session.Commit();

            var internalOrganisation = this.InternalOrganisation;

            internalOrganisation.DoAccounting            = true;
            internalOrganisation.DefaultCollectionMethod = collectionMethod;

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

            collectionMethod.Journal = journal;

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

            collectionMethod.RemoveGeneralLedgerAccount();

            Assert.False(this.Session.Derive(false).HasErrors);
        }
Esempio n. 11
0
        public void GivenCashPaymentMethodForInternalOrganisationThatDoesAccounting_WhenDeriving_ThenEitherGeneralLedgerAccountOrJournalMustExist()
        {
            var supplier = new OrganisationBuilder(this.DatabaseSession)
                .WithName("supplier")
                .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain)
                .Build();

            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");

            var supplierRelationship = new SupplierRelationshipBuilder(this.DatabaseSession)
                .WithSupplier(supplier)
                .WithInternalOrganisation(internalOrganisation)
                .WithFromDate(DateTime.UtcNow)
                .Build();

            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.DatabaseSession)
                .WithAccountNumber("0001")
                .WithName("GeneralLedgerAccount")
                .WithBalanceSheetAccount(true)
                .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.DatabaseSession)
                .WithInternalOrganisation(internalOrganisation)
                .WithGeneralLedgerAccount(generalLedgerAccount)
                .Build();

            var journal = new JournalBuilder(this.DatabaseSession).WithDescription("journal").Build();

            this.DatabaseSession.Commit();

            var cash = new CashBuilder(this.DatabaseSession)
                .WithDescription("description")
                .WithCreditor(supplierRelationship)
                .Build();

            internalOrganisation.RemovePaymentMethods();
            internalOrganisation.AddPaymentMethod(cash);
            internalOrganisation.DoAccounting = true;

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

            cash.Journal = journal;

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

            cash.RemoveJournal();
            cash.GeneralLedgerAccount = internalOrganisationGlAccount;

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Esempio n. 12
0
        public void GivenJournal_WhenDeriving_ThenContraAccountCanBeChangedWhenNotUsedYet()
        {
            this.InternalOrganisation.DoAccounting = true;

            this.Session.Derive();

            var generalLedgerAccount1 = new GeneralLedgerAccountBuilder(this.Session)
                                        .WithAccountNumber("0001")
                                        .WithName("bankAccount 1")
                                        .WithBalanceSheetAccount(true)
                                        .WithSide(new DebitCreditConstants(this.Session).Debit)
                                        .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.Session).WithDescription("accountType").Build())
                                        .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.Session).WithDescription("accountGroup").Build())
                                        .Build();

            var internalOrganisationGlAccount1 = new OrganisationGlAccountBuilder(this.Session)
                                                 .WithFromDate(this.Session.Now())
                                                 .WithGeneralLedgerAccount(generalLedgerAccount1)
                                                 .Build();

            var generalLedgerAccount2 = new GeneralLedgerAccountBuilder(this.Session)
                                        .WithAccountNumber("0002")
                                        .WithName("bankAccount 2")
                                        .WithBalanceSheetAccount(true)
                                        .WithSide(new DebitCreditConstants(this.Session).Debit)
                                        .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.Session).WithDescription("accountType").Build())
                                        .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.Session).WithDescription("accountGroup").Build())
                                        .Build();

            var internalOrganisationGlAccount2 = new OrganisationGlAccountBuilder(this.Session)
                                                 .WithFromDate(this.Session.Now())
                                                 .WithGeneralLedgerAccount(generalLedgerAccount2)
                                                 .Build();

            var journal = new JournalBuilder(this.Session)
                          .WithDescription("description")
                          .WithContraAccount(internalOrganisationGlAccount1)
                          .WithJournalType(new JournalTypes(this.Session).Bank)
                          .Build();

            this.Session.Derive();

            Assert.Equal(generalLedgerAccount1, journal.PreviousContraAccount.GeneralLedgerAccount);

            journal.ContraAccount = internalOrganisationGlAccount2;

            this.Session.Derive();

            Assert.Equal(generalLedgerAccount2, journal.PreviousContraAccount.GeneralLedgerAccount);
        }
Esempio n. 13
0
        public void GivenGeneralLedgerAccount_WhenBuild_ThenPostBuildRelationsMustExist()
        {
            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.DatabaseSession)
                .WithAccountNumber("0001")
                .WithName("GeneralLedgerAccount")
                .WithBalanceSheetAccount(true)
                .Build();

            Assert.IsTrue(generalLedgerAccount.ExistUniqueId);
            Assert.AreEqual(generalLedgerAccount.CashAccount, false);
            Assert.AreEqual(generalLedgerAccount.CostCenterAccount, false);
            Assert.AreEqual(generalLedgerAccount.CostCenterRequired, false);
            Assert.AreEqual(generalLedgerAccount.CostUnitAccount, false);
            Assert.AreEqual(generalLedgerAccount.CostUnitRequired, false);
            Assert.AreEqual(generalLedgerAccount.Protected, false);
            Assert.AreEqual(generalLedgerAccount.ReconciliationAccount, false);
        }
        public void GivenGeneralLedgerAccount_WhenBuild_ThenPostBuildRelationsMustExist()
        {
            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.Session)
                                       .WithAccountNumber("0001")
                                       .WithName("GeneralLedgerAccount")
                                       .WithBalanceSheetAccount(true)
                                       .Build();

            Assert.True(generalLedgerAccount.ExistUniqueId);
            Assert.Equal(generalLedgerAccount.CashAccount, false);
            Assert.Equal(generalLedgerAccount.CostCenterAccount, false);
            Assert.Equal(generalLedgerAccount.CostCenterRequired, false);
            Assert.Equal(generalLedgerAccount.CostUnitAccount, false);
            Assert.Equal(generalLedgerAccount.CostUnitRequired, false);
            Assert.Equal(generalLedgerAccount.Protected, false);
            Assert.Equal(generalLedgerAccount.ReconciliationAccount, false);
        }
        public void GivenOwnBankAccountForSingletonThatDoesAccounting_WhenDeriving_ThenEitherGeneralLedgerAccountOrJournalMustExist()
        {
            var internalOrganisation = this.InternalOrganisation;

            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.Session)
                                       .WithAccountNumber("0001")
                                       .WithName("GeneralLedgerAccount")
                                       .WithBalanceSheetAccount(true)
                                       .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.Session)
                                                .WithGeneralLedgerAccount(generalLedgerAccount)
                                                .Build();

            var journal = new JournalBuilder(this.Session).WithDescription("journal").Build();

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

            var collectionMethod = new OwnBankAccountBuilder(this.Session)
                                   .WithDescription("own account")
                                   .WithBankAccount(bankAccount)
                                   .Build();

            this.Session.Commit();

            internalOrganisation.DoAccounting = true;

            ((OrganisationDerivedRoles)internalOrganisation).AddActiveCollectionMethod(collectionMethod);

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

            collectionMethod.Journal = journal;

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

            collectionMethod.RemoveJournal();
            collectionMethod.GeneralLedgerAccount = internalOrganisationGlAccount;

            Assert.False(this.Session.Derive(false).HasErrors);
        }
        public void GivenOwnBankAccount_WhenDeriving_ThenGeneralLedgerAccountAndJournalAtMostOne()
        {
            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.Session)
                                       .WithAccountNumber("0001")
                                       .WithName("GeneralLedgerAccount")
                                       .WithBalanceSheetAccount(true)
                                       .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.Session)
                                                .WithGeneralLedgerAccount(generalLedgerAccount)
                                                .Build();

            var journal = new JournalBuilder(this.Session).WithDescription("journal").Build();

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

            var paymentMethod = new OwnBankAccountBuilder(this.Session)
                                .WithDescription("own account")
                                .WithBankAccount(bankAccount)
                                .WithGeneralLedgerAccount(internalOrganisationGlAccount)
                                .Build();

            this.Session.Commit();

            var internalOrganisation = this.InternalOrganisation;

            internalOrganisation.DoAccounting            = true;
            internalOrganisation.DefaultCollectionMethod = paymentMethod;

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

            paymentMethod.Journal = journal;

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

            paymentMethod.RemoveGeneralLedgerAccount();

            Assert.False(this.Session.Derive(false).HasErrors);
        }
Esempio n. 17
0
        public void GivenOrganisationGlAccount_WhenBuild_ThenHasBankStatementTransactionsIsAlwaysFalse()
        {
            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.Session)
                                       .WithAccountNumber("0001")
                                       .WithName("GeneralLedgerAccount")
                                       .WithBalanceSheetAccount(true)
                                       .WithSide(new DebitCreditConstants(this.Session).Debit)
                                       .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.Session).WithDescription("accountType").Build())
                                       .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.Session).WithDescription("accountGroup").Build())
                                       .Build();

            var organisationGlAccount = new OrganisationGlAccountBuilder(this.Session)
                                        .WithGeneralLedgerAccount(generalLedgerAccount)
                                        .Build();

            this.Session.Derive();

            Assert.False(organisationGlAccount.HasBankStatementTransactions);
        }
        public void GivenOwnCreditCardForSingletonThatDoesAccounting_WhenDeriving_ThenEitherGeneralLedgerAccountOrJournalMustExist()
        {
            this.InternalOrganisation.DoAccounting = true;

            this.Session.Derive();

            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.Session)
                                       .WithAccountNumber("0001")
                                       .WithName("GeneralLedgerAccount")
                                       .WithBalanceSheetAccount(true)
                                       .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.Session)
                                                .WithGeneralLedgerAccount(generalLedgerAccount)
                                                .Build();

            var journal = new JournalBuilder(this.Session).WithDescription("journal").Build();

            var creditCard = new CreditCardBuilder(this.Session)
                             .WithCardNumber("4012888888881881")
                             .WithExpirationYear(this.Session.Now().Year + 1)
                             .WithExpirationMonth(03)
                             .WithNameOnCard("M.E. van Knippenberg")
                             .WithCreditCardCompany(new CreditCardCompanyBuilder(this.Session).WithName("Visa").Build())
                             .Build();

            var paymentMethod = new OwnCreditCardBuilder(this.Session)
                                .WithCreditCard(creditCard)
                                .Build();

            this.InternalOrganisation.AddPaymentMethod(paymentMethod);

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

            paymentMethod.Journal = journal;

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

            paymentMethod.RemoveJournal();
            paymentMethod.GeneralLedgerAccount = internalOrganisationGlAccount;

            Assert.False(this.Session.Derive(false).HasErrors);
        }
Esempio n. 19
0
        public void GivenCashPaymentMethodForSingletonThatDoesAccounting_WhenDeriving_ThenEitherGeneralLedgerAccountOrJournalMustExist()
        {
            var internalOrganisation = this.InternalOrganisation;

            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.Session)
                                       .WithAccountNumber("0001")
                                       .WithName("GeneralLedgerAccount")
                                       .WithBalanceSheetAccount(true)
                                       .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.Session)
                                                .WithInternalOrganisation(this.InternalOrganisation)
                                                .WithGeneralLedgerAccount(generalLedgerAccount)
                                                .Build();

            var journal = new JournalBuilder(this.Session)
                          .WithDescription("journal")
                          .Build();

            this.Session.Commit();

            var cash = new CashBuilder(this.Session)
                       .WithDescription("description")
                       .Build();

            internalOrganisation.DoAccounting = true;
            ((OrganisationDerivedRoles)internalOrganisation).AddActiveCollectionMethod(cash);

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

            cash.Journal = journal;

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

            cash.RemoveJournal();
            cash.GeneralLedgerAccount = internalOrganisationGlAccount;

            Assert.False(this.Session.Derive(false).HasErrors);
        }
Esempio n. 20
0
        public void GivenOrganisationGlAccount_WhenBuild_ThenHasBankStatementTransactionsIsAlwaysFalse()
        {
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");

            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.DatabaseSession)
                .WithAccountNumber("0001")
                .WithName("GeneralLedgerAccount")
                .WithBalanceSheetAccount(true)
                .WithSide(new DebitCreditConstants(this.DatabaseSession).Debit)
                .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.DatabaseSession).WithDescription("accountType").Build())
                .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.DatabaseSession).WithDescription("accountGroup").Build())
                .Build();

            var organisationGlAccount = new OrganisationGlAccountBuilder(this.DatabaseSession)
                .WithInternalOrganisation(internalOrganisation)
                .WithGeneralLedgerAccount(generalLedgerAccount)
                .Build();

            this.DatabaseSession.Derive();

            Assert.IsFalse(organisationGlAccount.HasBankStatementTransactions);
        }
Esempio n. 21
0
        public void GivenOrganisationGlAccount_WhenNotReferenced_ThenAccountIsNeutral()
        {
            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.Session)
                                       .WithAccountNumber("0001")
                                       .WithName("GeneralLedgerAccount")
                                       .WithBalanceSheetAccount(true)
                                       .WithSide(new DebitCreditConstants(this.Session).Debit)
                                       .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.Session).WithDescription("accountType").Build())
                                       .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.Session).WithDescription("accountGroup").Build())
                                       .Build();

            var organisationGlAccount = new OrganisationGlAccountBuilder(this.Session)
                                        .WithGeneralLedgerAccount(generalLedgerAccount)
                                        .Build();

            Assert.True(organisationGlAccount.IsNeutralAccount());
            Assert.False(organisationGlAccount.IsBankAccount());
            Assert.False(organisationGlAccount.IsCashAccount());
            Assert.False(organisationGlAccount.IsCostAccount());
            Assert.False(organisationGlAccount.IsCreditorAccount());
            Assert.False(organisationGlAccount.IsDebtorAccount());
            Assert.False(organisationGlAccount.IsInventoryAccount());
            Assert.False(organisationGlAccount.IsTurnOverAccount());
        }
Esempio n. 22
0
        public void GivenCashPaymentMethod_WhenDeriving_ThenGeneralLedgerAccountAndJournalAtMostOne()
        {
            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.Session)
                                       .WithAccountNumber("0001")
                                       .WithName("GeneralLedgerAccount")
                                       .WithBalanceSheetAccount(true)
                                       .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.Session)
                                                .WithGeneralLedgerAccount(generalLedgerAccount)
                                                .Build();

            var journal = new JournalBuilder(this.Session).WithDescription("journal").Build();

            this.Session.Commit();

            var cash = new CashBuilder(this.Session)
                       .WithDescription("description")
                       .WithGeneralLedgerAccount(internalOrganisationGlAccount)
                       .Build();

            var internalOrganisation = this.InternalOrganisation;

            internalOrganisation.DoAccounting            = true;
            internalOrganisation.DefaultCollectionMethod = cash;

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

            cash.Journal = journal;

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

            cash.RemoveGeneralLedgerAccount();

            Assert.False(this.Session.Derive(false).HasErrors);
        }
Esempio n. 23
0
        public void GivenGeneralLedgerAccount_WhenSettingDefaultCostCenter_ThenDefaultCostCenterMustBeInListOfAllowedCostCenters()
        {
            var costCenter = new CostCenterBuilder(this.DatabaseSession).WithName("costCenter").Build();

            var glAccount = new GeneralLedgerAccountBuilder(this.DatabaseSession)
                .WithAccountNumber("0001")
                .WithName("GeneralLedgerAccount")
                .WithCostCenterAccount(true)
                .WithCostCenterRequired(true)
                .WithDefaultCostCenter(costCenter)
                .WithBalanceSheetAccount(true)
                .WithSide(new DebitCreditConstants(this.DatabaseSession).Debit)
                .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.DatabaseSession).WithDescription("accountType").Build())
                .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.DatabaseSession).WithDescription("accountGroup").Build())
                .Build();

            var derivationLog = this.DatabaseSession.Derive();

            var expectedMessage = ErrorMessages.CostCenterNotAllowed;

            Assert.AreEqual(derivationLog.Errors[0].Message, expectedMessage);

            glAccount.AddCostCenterAllowed(costCenter);

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Esempio n. 24
0
        public void GivenGeneralLedgerAccount_WhenSettingDefaultCostUnit_ThenDefaultCostUnitMustBeInListOfAllowedCostUnits()
        {
            var costUnit = new GoodBuilder(this.DatabaseSession)
                .WithName("Good")
                .WithSku("10101")
                .WithVatRate(new VatRateBuilder(this.DatabaseSession).WithRate(21).Build())
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var glAccount = new GeneralLedgerAccountBuilder(this.DatabaseSession)
                .WithAccountNumber("0001")
                .WithName("GeneralLedgerAccount")
                .WithCostUnitAccount(true)
                .WithCostUnitRequired(true)
                .WithDefaultCostUnit(costUnit)
                .WithBalanceSheetAccount(true)
                .WithSide(new DebitCreditConstants(this.DatabaseSession).Debit)
                .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.DatabaseSession).WithDescription("accountType").Build())
                .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.DatabaseSession).WithDescription("accountGroup").Build())
                .Build();

            var derivationLog = this.DatabaseSession.Derive();
            var expectedMessage = ErrorMessages.CostUnitNotAllowed;

            Assert.AreEqual(derivationLog.Errors[0].Message, expectedMessage);

            glAccount.AddCostUnitAllowed(costUnit);

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Esempio n. 25
0
        public void GivenOrganisationGlAccount_WhenNotReferenced_ThenAccountIsNeutral()
        {
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");

            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.DatabaseSession)
                .WithAccountNumber("0001")
                .WithName("GeneralLedgerAccount")
                .WithBalanceSheetAccount(true)
                .WithSide(new DebitCreditConstants(this.DatabaseSession).Debit)
                .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.DatabaseSession).WithDescription("accountType").Build())
                .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.DatabaseSession).WithDescription("accountGroup").Build())
                .Build();

            var organisationGlAccount = new OrganisationGlAccountBuilder(this.DatabaseSession)
                .WithInternalOrganisation(internalOrganisation)
                .WithGeneralLedgerAccount(generalLedgerAccount)
                .Build();

            Assert.IsTrue(organisationGlAccount.IsNeutralAccount());
            Assert.IsFalse(organisationGlAccount.IsBankAccount());
            Assert.IsFalse(organisationGlAccount.IsCashAccount());
            Assert.IsFalse(organisationGlAccount.IsCostAccount());
            Assert.IsFalse(organisationGlAccount.IsCreditorAccount());
            Assert.IsFalse(organisationGlAccount.IsDebtorAccount());
            Assert.IsFalse(organisationGlAccount.IsInventoryAccount());
            Assert.IsFalse(organisationGlAccount.IsTurnOverAccount());
        }
Esempio n. 26
0
        public void GivenJournal_WhenDeriving_ThenJournalTypeMustExist()
        {
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");
            var glAccount = new GeneralLedgerAccountBuilder(this.DatabaseSession)
                .WithAccountNumber("0001")
                .WithName("GeneralLedgerAccount")
                .WithBalanceSheetAccount(true)
                .WithSide(new DebitCreditConstants(this.DatabaseSession).Debit)
                .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.DatabaseSession).WithDescription("accountType").Build())
                .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.DatabaseSession).WithDescription("accountGroup").Build())
                .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.DatabaseSession)
                .WithFromDate(DateTime.UtcNow)
                .WithInternalOrganisation(internalOrganisation)
                .WithGeneralLedgerAccount(glAccount)
                .Build();

            this.DatabaseSession.Commit();

            var builder = new JournalBuilder(this.DatabaseSession);
            builder.WithDescription("description");
            builder.WithContraAccount(internalOrganisationGlAccount);
            builder.Build();

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

            this.DatabaseSession.Rollback();

            builder.WithJournalType(new JournalTypes(this.DatabaseSession).Bank);
            builder.Build();

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Esempio n. 27
0
        public void GivenJournal_WhenDeriving_ThenContraAccountCanBeChangedWhenNotUsedYet()
        {
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");

            var generalLedgerAccount1 = new GeneralLedgerAccountBuilder(this.DatabaseSession)
                .WithAccountNumber("0001")
                .WithName("bankAccount 1")
                .WithBalanceSheetAccount(true)
                .WithSide(new DebitCreditConstants(this.DatabaseSession).Debit)
                .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.DatabaseSession).WithDescription("accountType").Build())
                .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.DatabaseSession).WithDescription("accountGroup").Build())
                .Build();

            var internalOrganisationGlAccount1 = new OrganisationGlAccountBuilder(this.DatabaseSession)
                .WithFromDate(DateTime.UtcNow)
                .WithInternalOrganisation(internalOrganisation)
                .WithGeneralLedgerAccount(generalLedgerAccount1)
                .Build();

            var generalLedgerAccount2 = new GeneralLedgerAccountBuilder(this.DatabaseSession)
                .WithAccountNumber("0002")
                .WithName("bankAccount 2")
                .WithBalanceSheetAccount(true)
                .WithSide(new DebitCreditConstants(this.DatabaseSession).Debit)
                .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.DatabaseSession).WithDescription("accountType").Build())
                .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.DatabaseSession).WithDescription("accountGroup").Build())
                .Build();

            var internalOrganisationGlAccount2 = new OrganisationGlAccountBuilder(this.DatabaseSession)
                .WithFromDate(DateTime.UtcNow)
                .WithInternalOrganisation(internalOrganisation)
                .WithGeneralLedgerAccount(generalLedgerAccount2)
                .Build();

            var journal = new JournalBuilder(this.DatabaseSession)
                .WithDescription("description")
                .WithContraAccount(internalOrganisationGlAccount1)
                .WithJournalType(new JournalTypes(this.DatabaseSession).Bank)
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(generalLedgerAccount1, journal.PreviousContraAccount.GeneralLedgerAccount);

            journal.ContraAccount = internalOrganisationGlAccount2;

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(generalLedgerAccount2, journal.PreviousContraAccount.GeneralLedgerAccount);
        }
Esempio n. 28
0
        public void GivenJournal_WhenDeriving_ThenJournalTypeCanNotBeChangedWhenJournalEntriesArePresent()
        {
            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");

            var generalLedgerAccount1 = new GeneralLedgerAccountBuilder(this.DatabaseSession)
                .WithAccountNumber("0001")
                .WithName("bankAccount 1")
                .WithBalanceSheetAccount(true)
                .WithSide(new DebitCreditConstants(this.DatabaseSession).Debit)
                .WithGeneralLedgerAccountType(new GeneralLedgerAccountTypeBuilder(this.DatabaseSession).WithDescription("accountType").Build())
                .WithGeneralLedgerAccountGroup(new GeneralLedgerAccountGroupBuilder(this.DatabaseSession).WithDescription("accountGroup").Build())
                .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.DatabaseSession)
                .WithFromDate(DateTime.UtcNow)
                .WithInternalOrganisation(internalOrganisation)
                .WithGeneralLedgerAccount(generalLedgerAccount1)
                .Build();

            var journal = new JournalBuilder(this.DatabaseSession)
                .WithDescription("description")
                .WithContraAccount(internalOrganisationGlAccount)
                .WithJournalType(new JournalTypes(this.DatabaseSession).Bank)
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(generalLedgerAccount1, journal.PreviousContraAccount.GeneralLedgerAccount);

            journal.AddJournalEntry(new JournalEntryBuilder(this.DatabaseSession)
                                        .WithJournalEntryDetail(new JournalEntryDetailBuilder(this.DatabaseSession)
                                                                    .WithAmount(1)
                                                                    .WithDebit(true)
                                                                    .WithGeneralLedgerAccount(internalOrganisationGlAccount)
                                                                    .Build())
                                        .Build());

            journal.JournalType = new JournalTypes(this.DatabaseSession).Cash;

            Assert.AreEqual("Journal.JournalType, Journal.PreviousJournalType are not equal", this.DatabaseSession.Derive().Errors[0].Message);
        }
Esempio n. 29
0
        public void GivenGeneralLedgerAccount_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var accountGroup = new GeneralLedgerAccountGroupBuilder(this.DatabaseSession).WithDescription("accountGroup").Build();
            var accountType = new GeneralLedgerAccountTypeBuilder(this.DatabaseSession).WithDescription("accountType").Build();

            this.DatabaseSession.Commit();

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

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

            this.DatabaseSession.Rollback();

            builder.WithAccountNumber("0001");
            builder.Build();

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

            this.DatabaseSession.Rollback();

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

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

            this.DatabaseSession.Rollback();

            builder.WithBalanceSheetAccount(true);
            builder.Build();

            this.DatabaseSession.Rollback();

            builder.WithSide(new DebitCreditConstants(this.DatabaseSession).Debit);
            builder.Build();

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

            this.DatabaseSession.Rollback();

            builder.WithGeneralLedgerAccountGroup(accountGroup);
            builder.Build();

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

            this.DatabaseSession.Rollback();

            builder.WithGeneralLedgerAccountType(accountType);
            builder.Build();

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