public void GivenOwnBankAccount_WhenDeriving_ThenBankAccountMustBeValidated() { var netherlands = new Countries(this.Session).CountryByIsoCode["NL"]; var euro = netherlands.Currency; var builder = new BankAccountBuilder(this.Session).WithCurrency(euro).WithIban("NL50RABO0109546784").WithNameOnAccount("Martien"); var bankAccount = builder.Build(); new OwnBankAccountBuilder(this.Session) .WithDescription("own account") .WithBankAccount(bankAccount).Build(); Assert.True(this.Session.Derive(false).HasErrors); this.Session.Rollback(); var bank = new BankBuilder(this.Session).WithCountry(netherlands).WithName("RABOBANK GROEP").WithBic("RABONL2U").Build(); builder.WithBank(bank); bankAccount = builder.Build(); new OwnBankAccountBuilder(this.Session) .WithDescription("own account") .WithBankAccount(bankAccount).Build(); Assert.False(this.Session.Derive(false).HasErrors); }
public void DoSomething() { var account = new BankAccountBuilder(); var bankService = new BankAccountService(); AddAccountsToService(bankService, account); Console.WriteLine(bankService.ToString()); }
public void WithdrawMoney_WithLimitExceeded_Throws() { var bankAccount = new BankAccountBuilder(DefaultBankAccountId).WithCurrency(Currency.Euro).WithDepositedMoney(100).Build(); var bankAccountRepository = ConfigureBankAccountRepositoryForAccount(bankAccount); var systemUnderTest = new WithdrawMoneyHandler(bankAccountRepository); var command = new WithdrawMoney(DefaultBankAccountId, Transaction.Of(Guid.Parse("996228f4-70cb-4e44-9716-8a2a3b27d18c")), new Money(200, Currency.Euro), TimeStamp.Of(3)); systemUnderTest.Awaiting(it => it.Handle(command, CancellationToken.None)).Should().Throw <LimitExceededException>(); }
public void WithdrawMoney_WithLimitNotExceeded_WithdrawsMoney() { var bankAccount = new BankAccountBuilder(DefaultBankAccountId).WithCurrency(Currency.Euro).WithDepositedMoney(50).WithDepositedMoney(50).Build(); var bankAccountRepository = ConfigureBankAccountRepositoryForAccount(bankAccount); var systemUnderTest = new WithdrawMoneyHandler(bankAccountRepository); var command = new WithdrawMoney(DefaultBankAccountId, Transaction.Of(Guid.Parse("996228f4-70cb-4e44-9716-8a2a3b27d18c")), new Money(100, Currency.Euro), TimeStamp.Of(3)); systemUnderTest.Handle(command, CancellationToken.None).GetAwaiter().GetResult(); var moneyDeposited = new MoneyWithdrawn(DefaultBankAccountId.Value, command.Transaction.Value, command.Amount.Amount, command.TimeStamp.Value); bankAccountRepository.Received().SaveAsync(Arg.Is <BankAccount>(it => it.IsCorrectBankAccount(DefaultBankAccountId, 4, moneyDeposited))); }
public void GivenBankAccount_WhenDeriving_ThenRequiredRelationsMustExist() { var builder = new BankAccountBuilder(this.DatabaseSession); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithIban("NL50RABO0109546784"); builder.Build(); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); }
public void GivenBankAccount_WhenDeriving_ThenRequiredRelationsMustExist() { var builder = new BankAccountBuilder(this.Session); builder.Build(); Assert.True(this.Session.Derive(false).HasErrors); this.Session.Rollback(); builder.WithIban("NL50RABO0109546784"); builder.Build(); Assert.False(this.Session.Derive(false).HasErrors); }
public void AddAccountsToService(IBankAccountService bankService, BankAccountBuilder accountBuilder) { BankAccount account1 = accountBuilder.Create("Hiroshi Nakmura", 370000, 1000, Status.Close, BankAccountTypes.Prime); BankAccount account2 = accountBuilder.Create("Ilon Mask", 2000000, 35000, Status.Open, BankAccountTypes.Silver); BankAccount account3 = accountBuilder.Create("Inkognito man", 22500, 1000, Status.Waiting, BankAccountTypes.Gold); BankAccount account4 = accountBuilder.Create("Kondratovich Maxim", 2555000, 58000, Status.Open, BankAccountTypes.Platinum); account1.Deposite(2500); account4.Deposite(5000); account2.Withdraw(1100); account3.Withdraw(2250); bankService.Add(account1); bankService.Add(account2); bankService.Add(account3); bankService.Add(account4); bankService.Deactivate(account1, Status.Waiting); }
public void GivenOwnBankAccount_WhenBuild_ThenPostBuildRelationsMustExist() { 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) .Build(); this.Session.Derive(); Assert.True(paymentMethod.IsActive); Assert.True(paymentMethod.ExistDescription); }
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); }
public void GivenBankAccount_WhenOwnBankAccount_ThenRequiredRelationsMustExist() { 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(); this.Session.Commit(); var builder = new BankAccountBuilder(this.Session).WithIban("NL50RABO0109546784"); var bankAccount = builder.Build(); new OwnBankAccountBuilder(this.Session).WithBankAccount(bankAccount).Build(); Assert.True(this.Session.Derive(false).HasErrors); this.Session.Rollback(); builder.WithBank(bank); bankAccount = builder.Build(); new OwnBankAccountBuilder(this.Session).WithBankAccount(bankAccount).Build(); Assert.True(this.Session.Derive(false).HasErrors); this.Session.Rollback(); builder.WithCurrency(euro); bankAccount = builder.Build(); new OwnBankAccountBuilder(this.Session).WithBankAccount(bankAccount).Build(); Assert.True(this.Session.Derive(false).HasErrors); this.Session.Rollback(); builder.WithNameOnAccount("name"); bankAccount = builder.Build(); new OwnBankAccountBuilder(this.Session).WithBankAccount(bankAccount).WithDescription("description").Build(); Assert.False(this.Session.Derive(false).HasErrors); }
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); }
public static Organisation CreateInternalOrganisation( ISession session, string name, string address, string postalCode, string locality, Country country, string phone1CountryCode, string phone1, ContactMechanismPurpose phone1Purpose, string phone2CountryCode, string phone2, ContactMechanismPurpose phone2Purpose, string emailAddress, string websiteAddress, string taxNumber, string bankName, string facilityName, string bic, string iban, Currency currency, string logo, string storeName, BillingProcess billingProcess, string outgoingShipmentNumberPrefix, string salesInvoiceNumberPrefix, string salesOrderNumberPrefix, string purchaseOrderNumberPrefix, string purchaseInvoiceNumberPrefix, string requestNumberPrefix, string quoteNumberPrefix, string productNumberPrefix, string workEffortPrefix, string creditNoteNumberPrefix, bool isImmediatelyPicked, bool autoGenerateShipmentPackage, bool isImmediatelyPacked, bool isAutomaticallyShipped, bool autoGenerateCustomerShipment, bool isAutomaticallyReceived, bool autoGeneratePurchaseShipment, bool useCreditNoteSequence, int?requestCounterValue, int?quoteCounterValue, int?orderCounterValue, int?purchaseOrderCounterValue, int?invoiceCounterValue, int?purchaseInvoiceCounterValue, bool purchaseOrderNeedsApproval, decimal?purchaseOrderApprovalThresholdLevel1, decimal?purchaseOrderApprovalThresholdLevel2, SerialisedItemSoldOn[] serialisedItemSoldOns, bool collectiveWorkEffortInvoice, InvoiceSequence invoiceSequence, RequestSequence requestSequence, QuoteSequence quoteSequence, CustomerShipmentSequence customerShipmentSequence, PurchaseShipmentSequence purchaseShipmentSequence, WorkEffortSequence workEffortSequence) { var postalAddress1 = new PostalAddressBuilder(session) .WithAddress1(address) .WithPostalCode(postalCode) .WithLocality(locality) .WithCountry(country) .Build(); var webSite = new WebAddressBuilder(session) .WithElectronicAddressString(websiteAddress) .Build(); BankAccount bankAccount = null; if (!string.IsNullOrEmpty(bic) && !string.IsNullOrEmpty(iban)) { var bank = new BankBuilder(session).WithName(bankName).WithBic(bic).WithCountry(country).Build(); bankAccount = new BankAccountBuilder(session) .WithBank(bank) .WithIban(iban) .WithNameOnAccount(name) .WithCurrency(currency) .Build(); } var internalOrganisation = new OrganisationBuilder(session) .WithIsInternalOrganisation(true) .WithTaxNumber(taxNumber) .WithName(name) .WithPreferredCurrency(new Currencies(session).FindBy(M.Currency.IsoCode, "EUR")) .WithInvoiceSequence(invoiceSequence) .WithRequestSequence(requestSequence) .WithQuoteSequence(quoteSequence) .WithCustomerShipmentSequence(customerShipmentSequence) .WithPurchaseShipmentSequence(purchaseShipmentSequence) .WithWorkEffortSequence(workEffortSequence) .WithFiscalYearStartMonth(01) .WithFiscalYearStartDay(01) .WithDoAccounting(false) .WithPurchaseOrderNeedsApproval(purchaseOrderNeedsApproval) .WithPurchaseOrderApprovalThresholdLevel1(purchaseOrderApprovalThresholdLevel1) .WithPurchaseOrderApprovalThresholdLevel2(purchaseOrderApprovalThresholdLevel2) .WithAutoGeneratePurchaseShipment(autoGeneratePurchaseShipment) .WithIsAutomaticallyReceived(isAutomaticallyReceived) .WithCollectiveWorkEffortInvoice(collectiveWorkEffortInvoice) .WithCountry(country) .Build(); internalOrganisation.SerialisedItemSoldOns = serialisedItemSoldOns; if (invoiceSequence == new InvoiceSequences(session).RestartOnFiscalYear) { var sequenceNumbers = internalOrganisation.FiscalYearsInternalOrganisationSequenceNumbers.FirstOrDefault(v => v.FiscalYear == session.Now().Year); if (sequenceNumbers == null) { sequenceNumbers = new FiscalYearInternalOrganisationSequenceNumbersBuilder(session).WithFiscalYear(session.Now().Year).Build(); internalOrganisation.AddFiscalYearsInternalOrganisationSequenceNumber(sequenceNumbers); } sequenceNumbers.PurchaseOrderNumberPrefix = purchaseOrderNumberPrefix; sequenceNumbers.PurchaseInvoiceNumberPrefix = purchaseInvoiceNumberPrefix; if (purchaseOrderCounterValue != null) { sequenceNumbers.PurchaseOrderNumberCounter = new CounterBuilder(session).WithValue(purchaseOrderCounterValue).Build(); } if (purchaseInvoiceCounterValue != null) { sequenceNumbers.PurchaseInvoiceNumberCounter = new CounterBuilder(session).WithValue(purchaseInvoiceCounterValue).Build(); } } else { internalOrganisation.PurchaseOrderNumberPrefix = purchaseOrderNumberPrefix; internalOrganisation.PurchaseInvoiceNumberPrefix = purchaseInvoiceNumberPrefix; if (purchaseOrderCounterValue != null) { internalOrganisation.PurchaseOrderNumberCounter = new CounterBuilder(session).WithValue(purchaseOrderCounterValue).Build(); } if (purchaseInvoiceCounterValue != null) { internalOrganisation.PurchaseInvoiceNumberCounter = new CounterBuilder(session).WithValue(purchaseInvoiceCounterValue).Build(); } } if (requestSequence == new RequestSequences(session).RestartOnFiscalYear) { var sequenceNumbers = internalOrganisation.FiscalYearsInternalOrganisationSequenceNumbers.FirstOrDefault(v => v.FiscalYear == session.Now().Year); if (sequenceNumbers == null) { sequenceNumbers = new FiscalYearInternalOrganisationSequenceNumbersBuilder(session).WithFiscalYear(session.Now().Year).Build(); internalOrganisation.AddFiscalYearsInternalOrganisationSequenceNumber(sequenceNumbers); } sequenceNumbers.RequestNumberPrefix = requestNumberPrefix; if (requestCounterValue != null) { sequenceNumbers.RequestNumberCounter = new CounterBuilder(session).WithValue(requestCounterValue).Build(); } } else { internalOrganisation.RequestNumberPrefix = requestNumberPrefix; if (requestCounterValue != null) { internalOrganisation.RequestNumberCounter = new CounterBuilder(session).WithValue(requestCounterValue).Build(); } } if (quoteSequence == new QuoteSequences(session).RestartOnFiscalYear) { var sequenceNumbers = internalOrganisation.FiscalYearsInternalOrganisationSequenceNumbers.FirstOrDefault(v => v.FiscalYear == session.Now().Year); if (sequenceNumbers == null) { sequenceNumbers = new FiscalYearInternalOrganisationSequenceNumbersBuilder(session).WithFiscalYear(session.Now().Year).Build(); internalOrganisation.AddFiscalYearsInternalOrganisationSequenceNumber(sequenceNumbers); } sequenceNumbers.QuoteNumberPrefix = quoteNumberPrefix; if (quoteCounterValue != null) { sequenceNumbers.QuoteNumberCounter = new CounterBuilder(session).WithValue(quoteCounterValue).Build(); } } else { internalOrganisation.QuoteNumberPrefix = quoteNumberPrefix; if (quoteCounterValue != null) { internalOrganisation.QuoteNumberCounter = new CounterBuilder(session).WithValue(quoteCounterValue).Build(); } } if (workEffortSequence == new WorkEffortSequences(session).RestartOnFiscalYear) { var sequenceNumbers = internalOrganisation.FiscalYearsInternalOrganisationSequenceNumbers.FirstOrDefault(v => v.FiscalYear == session.Now().Year); if (sequenceNumbers == null) { sequenceNumbers = new FiscalYearInternalOrganisationSequenceNumbersBuilder(session).WithFiscalYear(session.Now().Year).Build(); internalOrganisation.AddFiscalYearsInternalOrganisationSequenceNumber(sequenceNumbers); } sequenceNumbers.WorkEffortNumberPrefix = workEffortPrefix; } else { internalOrganisation.WorkEffortNumberPrefix = workEffortPrefix; } OwnBankAccount defaultCollectionMethod = null; if (bankAccount != null) { internalOrganisation.AddBankAccount(bankAccount); defaultCollectionMethod = new OwnBankAccountBuilder(session).WithBankAccount(bankAccount).WithDescription("Huisbank").Build(); internalOrganisation.DefaultCollectionMethod = defaultCollectionMethod; } if (!string.IsNullOrEmpty(emailAddress)) { var email = new EmailAddressBuilder(session) .WithElectronicAddressString(emailAddress) .Build(); internalOrganisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session) .WithUseAsDefault(true) .WithContactMechanism(email) .WithContactPurpose(new ContactMechanismPurposes(session).GeneralEmail) .Build()); } internalOrganisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session) .WithUseAsDefault(true) .WithContactMechanism(postalAddress1) .WithContactPurpose(new ContactMechanismPurposes(session).RegisteredOffice) .WithContactPurpose(new ContactMechanismPurposes(session).GeneralCorrespondence) .WithContactPurpose(new ContactMechanismPurposes(session).BillingAddress) .WithContactPurpose(new ContactMechanismPurposes(session).ShippingAddress) .Build()); internalOrganisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session) .WithUseAsDefault(true) .WithContactMechanism(webSite) .WithContactPurpose(new ContactMechanismPurposes(session).InternetAddress) .Build()); TelecommunicationsNumber phoneNumber1 = null; if (!string.IsNullOrEmpty(phone1)) { phoneNumber1 = new TelecommunicationsNumberBuilder(session).WithContactNumber(phone1).Build(); if (!string.IsNullOrEmpty(phone1CountryCode)) { phoneNumber1.CountryCode = phone1CountryCode; } } if (phoneNumber1 != null) { internalOrganisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session) .WithUseAsDefault(true) .WithContactMechanism(phoneNumber1) .WithContactPurpose(phone1Purpose) .Build()); } TelecommunicationsNumber phoneNumber2 = null; if (!string.IsNullOrEmpty(phone2)) { phoneNumber2 = new TelecommunicationsNumberBuilder(session).WithContactNumber(phone2).Build(); if (!string.IsNullOrEmpty(phone2CountryCode)) { phoneNumber2.CountryCode = phone2CountryCode; } } if (phoneNumber2 != null) { internalOrganisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session) .WithUseAsDefault(true) .WithContactMechanism(phoneNumber2) .WithContactPurpose(phone2Purpose) .Build()); } if (!string.IsNullOrWhiteSpace(logo)) { var singleton = session.GetSingleton(); internalOrganisation.LogoImage = new MediaBuilder(session).WithInFileName(logo).WithInData(singleton.GetResourceBytes(logo)).Build(); } Facility facility = null; if (facilityName != null) { facility = new FacilityBuilder(session) .WithName(facilityName) .WithFacilityType(new FacilityTypes(session).Warehouse) .WithOwner(internalOrganisation) .Build(); } var store = new StoreBuilder(session) .WithName(storeName) .WithDefaultCollectionMethod(defaultCollectionMethod) .WithDefaultShipmentMethod(new ShipmentMethods(session).Ground) .WithDefaultCarrier(new Carriers(session).Fedex) .WithBillingProcess(billingProcess) .WithIsImmediatelyPicked(isImmediatelyPicked) .WithAutoGenerateShipmentPackage(autoGenerateShipmentPackage) .WithIsImmediatelyPacked(isImmediatelyPacked) .WithIsAutomaticallyShipped(isAutomaticallyShipped) .WithAutoGenerateCustomerShipment(autoGenerateCustomerShipment) .WithUseCreditNoteSequence(useCreditNoteSequence) .WithInternalOrganisation(internalOrganisation) .Build(); if (defaultCollectionMethod == null) { store.DefaultCollectionMethod = new CashBuilder(session).Build(); } else { store.DefaultCollectionMethod = defaultCollectionMethod; } if (facility != null) { store.DefaultFacility = facility; } if (invoiceSequence == new InvoiceSequences(session).RestartOnFiscalYear) { var sequenceNumbers = new FiscalYearStoreSequenceNumbersBuilder(session).WithFiscalYear(session.Now().Year).Build(); sequenceNumbers.CreditNoteNumberPrefix = creditNoteNumberPrefix; sequenceNumbers.OutgoingShipmentNumberPrefix = outgoingShipmentNumberPrefix; sequenceNumbers.SalesInvoiceNumberPrefix = salesInvoiceNumberPrefix; sequenceNumbers.SalesOrderNumberPrefix = salesOrderNumberPrefix; if (orderCounterValue != null) { sequenceNumbers.SalesOrderNumberCounter = new CounterBuilder(session).WithValue(orderCounterValue).Build(); } if (invoiceCounterValue != null) { sequenceNumbers.SalesInvoiceNumberCounter = new CounterBuilder(session).WithValue(invoiceCounterValue).Build(); } store.AddFiscalYearsStoreSequenceNumber(sequenceNumbers); } else { store.CreditNoteNumberPrefix = creditNoteNumberPrefix; store.OutgoingShipmentNumberPrefix = outgoingShipmentNumberPrefix; store.SalesInvoiceNumberPrefix = salesInvoiceNumberPrefix; store.SalesOrderNumberPrefix = salesOrderNumberPrefix; if (orderCounterValue != null) { store.SalesOrderNumberCounter = new CounterBuilder(session).WithValue(orderCounterValue).Build(); } if (invoiceCounterValue != null) { store.SalesInvoiceNumberCounter = new CounterBuilder(session).WithValue(invoiceCounterValue).Build(); } } return(internalOrganisation); }
public static Organisation CreateInternalOrganisation( ISession session, string name, string address, string postalCode, string locality, Country country, string phone1CountryCode, string phone1, ContactMechanismPurpose phone1Purpose, string phone2CountryCode, string phone2, ContactMechanismPurpose phone2Purpose, string emailAddress, string websiteAddress, string taxNumber, string bankName, string facilityName, string bic, string iban, Currency currency, string logo, string storeName, BillingProcess billingProcess, string outgoingShipmentNumberPrefix, string salesInvoiceNumberPrefix, string salesOrderNumberPrefix, string requestNumberPrefix, string quoteNumberPrefix, string productNumberPrefix, int?requestCounterValue, int?quoteCounterValue, int?orderCounterValue, int?invoiceCounterValue) { var postalAddress1 = new PostalAddressBuilder(session) .WithAddress1(address) .WithPostalBoundary(new PostalBoundaryBuilder(session).WithPostalCode(postalCode).WithLocality(locality).WithCountry(country).Build()) .Build(); var email = new EmailAddressBuilder(session) .WithElectronicAddressString(emailAddress) .Build(); var webSite = new WebAddressBuilder(session) .WithElectronicAddressString(websiteAddress) .Build(); var bank = new BankBuilder(session).WithName(bankName).WithBic(bic).WithCountry(country).Build(); var bankaccount = new BankAccountBuilder(session) .WithBank(bank) .WithIban(iban) .WithNameOnAccount(name) .WithCurrency(currency) .Build(); var organisation = new OrganisationBuilder(session) .WithIsInternalOrganisation(true) .WithTaxNumber(taxNumber) .WithName(name) .WithBankAccount(bankaccount) .WithDefaultCollectionMethod(new OwnBankAccountBuilder(session).WithBankAccount(bankaccount).WithDescription("Huisbank").Build()) .WithPreferredCurrency(new Currencies(session).FindBy(M.Currency.IsoCode, "EUR")) .WithInvoiceSequence(new InvoiceSequences(session).EnforcedSequence) .WithFiscalYearStartMonth(01) .WithFiscalYearStartDay(01) .WithDoAccounting(false) .WithRequestNumberPrefix(requestNumberPrefix) .WithQuoteNumberPrefix(quoteNumberPrefix) .Build(); if (requestCounterValue != null) { organisation.RequestCounter = new CounterBuilder(session).WithValue(requestCounterValue).Build(); } if (quoteCounterValue != null) { organisation.QuoteCounter = new CounterBuilder(session).WithValue(quoteCounterValue).Build(); } organisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session) .WithUseAsDefault(true) .WithContactMechanism(email) .WithContactPurpose(new ContactMechanismPurposes(session).GeneralEmail) .Build()); organisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session) .WithUseAsDefault(true) .WithContactMechanism(postalAddress1) .WithContactPurpose(new ContactMechanismPurposes(session).GeneralCorrespondence) .Build()); organisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session) .WithUseAsDefault(true) .WithContactMechanism(webSite) .WithContactPurpose(new ContactMechanismPurposes(session).InternetAddress) .Build()); TelecommunicationsNumber phoneNumber1 = null; if (!string.IsNullOrEmpty(phone1)) { phoneNumber1 = new TelecommunicationsNumberBuilder(session).WithContactNumber(phone1).Build(); if (!string.IsNullOrEmpty(phone1CountryCode)) { phoneNumber1.CountryCode = phone1CountryCode; } } if (phoneNumber1 != null) { organisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session) .WithUseAsDefault(true) .WithContactMechanism(phoneNumber1) .WithContactPurpose(phone1Purpose) .Build()); } TelecommunicationsNumber phoneNumber2 = null; if (!string.IsNullOrEmpty(phone2)) { phoneNumber2 = new TelecommunicationsNumberBuilder(session).WithContactNumber(phone2).Build(); if (!string.IsNullOrEmpty(phone2CountryCode)) { phoneNumber2.CountryCode = phone2CountryCode; } } if (phoneNumber2 != null) { organisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session) .WithUseAsDefault(true) .WithContactMechanism(phoneNumber2) .WithContactPurpose(phone2Purpose) .Build()); } if (File.Exists(logo)) { var fileInfo = new FileInfo(logo); var fileName = System.IO.Path.GetFileNameWithoutExtension(fileInfo.FullName).ToLowerInvariant(); var content = File.ReadAllBytes(fileInfo.FullName); var image = new MediaBuilder(session).WithFileName(fileName).WithInData(content).Build(); organisation.LogoImage = image; } Facility facility = null; if (facilityName != null) { facility = new FacilityBuilder(session) .WithName(facilityName) .WithFacilityType(new FacilityTypes(session).Warehouse) .WithOwner(organisation) .Build(); } var paymentMethod = new OwnBankAccountBuilder(session).WithBankAccount(bankaccount).WithDescription("Hoofdbank").Build(); var store = new StoreBuilder(session) .WithName(storeName) .WithOutgoingShipmentNumberPrefix(outgoingShipmentNumberPrefix) .WithSalesInvoiceNumberPrefix(salesInvoiceNumberPrefix) .WithSalesOrderNumberPrefix(salesOrderNumberPrefix) .WithDefaultCollectionMethod(paymentMethod) .WithDefaultShipmentMethod(new ShipmentMethods(session).Ground) .WithDefaultCarrier(new Carriers(session).Fedex) .WithBillingProcess(billingProcess) .WithSalesInvoiceCounter(new CounterBuilder(session).WithUniqueId(Guid.NewGuid()).WithValue(0).Build()) .WithIsImmediatelyPicked(true) .WithIsAutomaticallyShipped(true) .WithInternalOrganisation(organisation) .Build(); if (facility != null) { store.DefaultFacility = facility; } if (orderCounterValue != null) { store.SalesOrderCounter = new CounterBuilder(session).WithValue(orderCounterValue).Build(); } if (invoiceCounterValue != null) { store.SalesInvoiceCounter = new CounterBuilder(session).WithValue(invoiceCounterValue).Build(); } return(organisation); }