internal void SummaryByCurrencyEntries(EmpiriaHashTable <TrialBalanceEntry> summaryEntries, TrialBalanceEntry balanceEntry, StandardAccount targetAccount, Sector targetSector, TrialBalanceItemType itemType) { TrialBalanceEntry entry = TrialBalanceMapper.MapToTrialBalanceEntry(balanceEntry); if (_command.TrialBalanceType != TrialBalanceType.SaldosPorCuentaYMayor && entry.ItemType == TrialBalanceItemType.BalanceTotalCreditor) { entry.InitialBalance = -1 * entry.InitialBalance; entry.CurrentBalance = -1 * entry.CurrentBalance; } entry.GroupName = "TOTAL MONEDA " + entry.Currency.FullName; string hash; if (_command.TrialBalanceType == TrialBalanceType.SaldosPorCuentaYMayor) { entry.GroupNumber = ""; hash = $"{entry.GroupName}||{entry.Currency.Id}"; } else { hash = $"{entry.GroupName}||{targetSector.Code}||{entry.Currency.Id}||{entry.Ledger.Id}"; } GenerateOrIncreaseEntries(summaryEntries, entry, targetAccount, targetSector, itemType, hash); }
private void GenerateOrIncreaseEntries(EmpiriaHashTable <TrialBalanceEntry> summaryEntries, TrialBalanceEntry entry, StandardAccount targetAccount, Sector targetSector, TrialBalanceItemType itemType, string hash) { TrialBalanceEntry summaryEntry; summaryEntries.TryGetValue(hash, out summaryEntry); if (summaryEntry == null) { summaryEntry = new TrialBalanceEntry { Ledger = entry.Ledger, Currency = entry.Currency, Sector = targetSector, Account = targetAccount, ItemType = itemType, GroupNumber = entry.GroupNumber, GroupName = entry.GroupName, DebtorCreditor = entry.DebtorCreditor, SubledgerAccountIdParent = entry.SubledgerAccountIdParent }; summaryEntry.Sum(entry); summaryEntries.Insert(hash, summaryEntry); } else { summaryEntry.Sum(entry); } }
public void StandardAccount_Create_3AccountsAlreadyExist_Fails() { var account = new StandardAccount { CustomerId = 1, Balance = 1000, Number = "LT123456789012345678" }; var existingAccounts = new List <Account> { new StandardAccount { CustomerId = 1, Balance = 1000, Number = "LT123456789012345679" }, new StandardAccount { CustomerId = 1, Balance = 1000, Number = "LT123456789012345670" }, new StandardAccount { CustomerId = 1, Balance = 1000, Number = "LT123456789012345671" } }; Assert.Throws <BusinessException>(() => _accountDomainService.CanCreateAccount(account, existingAccounts)); }
/// <summary> /// Opens a new account for <paramref name="holder"/> with <paramref name="startBalance"/>. /// </summary> /// <param name="holder">person's full name</param> /// <param name="startBalance">first deposit amount</param> /// <returns>IBAN of a new account</returns> /// <exception cref="ArgumentException">Start balance is lesser than minimal.</exception> public string OpenNewAccount(string holder, decimal startBalance) { if (string.IsNullOrWhiteSpace(holder)) { throw new ArgumentException("No significant characters are given.", "holder"); } if (startBalance < MINDEPOSIT) { throw new ArgumentException($"Cannot create a bank account with balance lesser than {MINDEPOSIT}"); } BankAccount account; if (startBalance <= 1000) { account = new StandardAccount(ibanGenerator.GenerateIBAN(), holder, startBalance, bonusPoints: 0); } else if (startBalance <= 10000) { account = new GoldAccount(ibanGenerator.GenerateIBAN(), holder, startBalance, bonusPoints: 5); } else { account = new PlatinumAccount(ibanGenerator.GenerateIBAN(), holder, startBalance, bonusPoints: 10); } storage.AddAccount(account); return(account.IBAN); }
private void CreateOrAccumulateParentWithoutSector( List <TrialBalanceEntry> returnedEntries, TrialBalanceEntry entry, EmpiriaHashTable <TrialBalanceEntry> summaryParentEntries, StandardAccount currentParent) { var helper = new TrialBalanceHelper(_command); var entryWithoutSector = returnedEntries.FirstOrDefault( a => a.Ledger.Number == entry.Ledger.Number && a.Currency.Code == entry.Currency.Code && a.SubledgerAccountIdParent == entry.SubledgerAccountId && a.Account.Number == currentParent.Number && a.NotHasSector); if (entryWithoutSector == null) { helper.SummaryByEntry(summaryParentEntries, entry, currentParent, Sector.Empty, TrialBalanceItemType.BalanceSummary); } else { entryWithoutSector.Sum(entry); } }
public void StandardAccount_Create_Succeeds() { var account = new StandardAccount { CustomerId = 1, Balance = 1000, Number = "LT123456789012345678" }; var existingAccounts = new List <Account> { new StandardAccount { CustomerId = 1, Balance = 1000, Number = "LT123456789012345679" }, new StandardAccount { CustomerId = 1, Balance = 1000, Number = "LT123456789012345670" } }; Assert.True(_accountDomainService.CanCreateAccount(account, existingAccounts)); }
/// <summary> /// Opens a new account for <paramref name="owner"/> with <paramref name="startBalance"/>. /// </summary> /// <param name="owner">person's full name</param> /// <param name="startBalance">first deposit amount</param> /// <returns>IBAN of a new account</returns> /// <exception cref="ArgumentException">Start balance is lesser than minimal.</exception> public string OpenAccount(AccountOwner owner, decimal startBalance) { if (owner == null) { throw new ArgumentNullException(nameof(owner)); } BankAccount account; if (startBalance < 1000) { account = new StandardAccount(ibanGenerator.GenerateIBAN(), owner, startBalance, bonusPoints: 0); } else if (startBalance < 10000) { account = new GoldAccount(ibanGenerator.GenerateIBAN(), owner, startBalance, bonusPoints: 5); } else { account = new PlatinumAccount(ibanGenerator.GenerateIBAN(), owner, startBalance, bonusPoints: 10); } accountsRepo.Accounts.Create(account.ToDTO()); accountsRepo.Save(); return(account.IBAN); }
private void GenerateOrIncreaseParentEntries(List <TrialBalanceEntry> subsidiaryEntries, List <TrialBalanceEntry> returnedEntries) { var helper = new TrialBalanceHelper(_command); foreach (var entry in subsidiaryEntries) { int count = 0; List <TrialBalanceEntry> summaryEntries = new List <TrialBalanceEntry>(); var summaryParentEntries = new EmpiriaHashTable <TrialBalanceEntry>(); StandardAccount account = entry.Account; while (true) { var parent = returnedEntries.FirstOrDefault(a => a.Ledger.Number == entry.Ledger.Number && a.Currency.Code == entry.Currency.Code && a.SubledgerAccountId == 0 && a.SubledgerAccountIdParent == entry.SubledgerAccountId && a.Account.Number == account.Number && a.Sector.Code == entry.Sector.Code); if (parent == null) { count++; TrialBalanceItemType itemType = count == 1 ? TrialBalanceItemType.BalanceEntry : TrialBalanceItemType.BalanceSummary; helper.SummaryByEntry(summaryParentEntries, entry, account, entry.Sector, itemType); if (!account.HasParent && entry.HasSector && entry.SubledgerAccountId > 0) { CreateOrAccumulateParentWithoutSector(returnedEntries, entry, summaryParentEntries, account); break; } else if (!account.HasParent) { break; } else { account = account.GetParent(); } } else { parent.Sum(entry); if (!account.HasParent) { AccumulateSubledgerAccount(returnedEntries, entry, account); break; } else { account = account.GetParent(); } } } // while summaryEntries.AddRange(summaryParentEntries.Values.ToList()); returnedEntries.AddRange(summaryEntries); } // foreach }
public void Be_Valid() { var sut = new StandardAccount(null); var result = sut.Validate(new AccountValidation(null, 20000, AccountType.Standard)); result.Valid.Should().Be(true); }
internal void SummaryByEntry(EmpiriaHashTable <TrialBalanceEntry> summaryEntries, TrialBalanceEntry entry, StandardAccount targetAccount, Sector targetSector, TrialBalanceItemType itemType) { string hash = $"{targetAccount.Number}||{targetSector.Code}||{entry.Currency.Id}||{entry.Ledger.Id}"; GenerateOrIncreaseEntries(summaryEntries, entry, targetAccount, targetSector, itemType, hash); }
private void AccumulateSubledgerAccount(List <TrialBalanceEntry> returnedEntries, TrialBalanceEntry entry, StandardAccount currentParent) { var existTotalBySubledger = returnedEntries.FirstOrDefault( a => a.SubledgerAccountIdParent == entry.SubledgerAccountId && a.Currency.Code == entry.Currency.Code && a.Account.Number == currentParent.Number && a.NotHasSector); if (existTotalBySubledger != null) { existTotalBySubledger.Sum(entry); } }
internal void SummaryByAccount(EmpiriaHashTable <TrialBalanceEntry> summaryEntries, TrialBalanceEntry balanceEntry, StandardAccount targetAccount, Sector targetSector, TrialBalanceItemType itemType) { TrialBalanceEntry entry = TrialBalanceMapper.MapToTrialBalanceEntry(balanceEntry); entry.Ledger = Ledger.Empty; entry.GroupName = entry.Account.Name.ToUpper(); entry.InitialBalance = 0; entry.Debit = 0; entry.Credit = 0; entry.CurrentBalance = 0; string hash = $"{targetAccount.Number}||{targetSector.Code}||{entry.Currency.Id}||{entry.Ledger.Id}"; GenerateOrIncreaseEntries(summaryEntries, entry, targetAccount, targetSector, itemType, hash); }
private void SummaryByDebtorCreditorEntries(EmpiriaHashTable <TrialBalanceEntry> summaryEntries, TrialBalanceEntry balanceEntry, StandardAccount targetAccount, Sector targetSector, TrialBalanceItemType itemType) { TrialBalanceEntry entry = TrialBalanceMapper.MapToTrialBalanceEntry(balanceEntry); if (itemType == TrialBalanceItemType.BalanceTotalDebtor) { entry.GroupName = "TOTAL DEUDORAS " + entry.Currency.FullName; } else if (itemType == TrialBalanceItemType.BalanceTotalCreditor) { entry.GroupName = "TOTAL ACREEDORAS " + entry.Currency.FullName; } string hash = $"{entry.GroupName}||{targetSector.Code}||{entry.Currency.Id}||{entry.Ledger.Id}"; GenerateOrIncreaseEntries(summaryEntries, entry, targetAccount, targetSector, itemType, hash); }
private void GetDetailSummaryEntries(List <TrialBalanceEntry> detailSummaryEntries, EmpiriaHashTable <TrialBalanceEntry> summaryEntries, StandardAccount currentParent, TrialBalanceEntry entry) { TrialBalanceEntry detailsEntry; string key = $"{currentParent.Number}||{entry.Sector.Code}||{entry.Currency.Id}||{entry.Ledger.Id}"; summaryEntries.TryGetValue(key, out detailsEntry); if (detailsEntry != null) { var existEntry = detailSummaryEntries.FirstOrDefault(a => a.Ledger.Id == detailsEntry.Ledger.Id && a.Currency.Id == detailsEntry.Currency.Id && a.Account.Number == detailsEntry.Account.Number && a.Sector.Code == detailsEntry.Sector.Code); if (existEntry == null) { detailSummaryEntries.Add(detailsEntry); } } }
public void StandardAccountTest() { Assert.Throws <ArgumentException>(() => new StandardAccount(string.Empty, "owner", 22, 22)); Assert.Throws <ArgumentException>(() => new StandardAccount(null, "owner", 22, 22)); Assert.Throws <ArgumentException>(() => new StandardAccount(" ", "owner", 22, 22)); Assert.Throws <ArgumentException>(() => new StandardAccount("iban", string.Empty, 22, 22)); Assert.Throws <ArgumentException>(() => new StandardAccount("iban", null, 22, 22)); Assert.Throws <ArgumentException>(() => new StandardAccount("iban", " ", 22, 22)); Assert.Throws <ArgumentOutOfRangeException>(() => new StandardAccount("iban", "owner", 22, -1)); Assert.Throws <ArgumentOutOfRangeException>(() => new StandardAccount("iban", "owner", 22, 101)); var account = new StandardAccount("iban", "owner", 22, 22); account.BonusPoints -= 55; Assert.AreEqual(0, account.BonusPoints); account.BonusPoints += 155; Assert.AreEqual(100, account.BonusPoints); }
public void StandardAccountTest() { var owner = new AccountOwner("pid", "name", "email"); Assert.Throws <ArgumentException>(() => new StandardAccount(string.Empty, owner, 22, 22)); Assert.Throws <ArgumentException>(() => new StandardAccount(null, owner, 22, 22)); Assert.Throws <ArgumentException>(() => new StandardAccount(" ", owner, 22, 22)); Assert.Throws <ArgumentNullException>(() => new StandardAccount("iban", null, 22, 22)); Assert.Throws <ArgumentOutOfRangeException>(() => new StandardAccount("iban", owner, 22, -1)); Assert.Throws <ArgumentOutOfRangeException>(() => new StandardAccount("iban", owner, 22, 101)); var account = new StandardAccount("iban", owner, 22, 22); account.BonusPoints -= 55; Assert.AreEqual(0, account.BonusPoints); account.BonusPoints += 155; Assert.AreEqual(100, account.BonusPoints); account.BonusPoints -= 55; Assert.AreEqual(45, account.BonusPoints); }