private static void Validate(IEntry sourceEntry, IAccountMap accountMap) { // Performance.MarkStart("EntryHelper.Validate"); var matches = new List <Tuple <IAccount, IAccount, IAccountPredicate> >(); var entryItemAccountGroups = sourceEntry.Items.GroupBy(item => new { item.Account, item.Book }).ToList(); foreach (var entryItemAccountGroup in entryItemAccountGroups) { foreach (var accountMapItem in accountMap.Items) { if (!accountMapItem.Book.Equals(entryItemAccountGroup.First().Book)) { continue; } var account = entryItemAccountGroup.First().Account; if (!accountMapItem.AccountPredicate.Matches(account)) { continue; } if (accountMapItem.Account == null) { matches.Add(Tuple.Create(account, accountMapItem.Account, accountMapItem.AccountPredicate)); continue; } var duplicateItem = matches.SingleOrDefault(x => x.Item1.Equals(account)); if (duplicateItem != null) { throw new ValidationException(string.Format("Duplicate selected account:{0}{1}{0}{2} -> {3}{0}{4} -> {5}", Environment.NewLine, account, duplicateItem.Item3, duplicateItem.Item2, accountMapItem.AccountPredicate, accountMapItem.Account)); } matches.Add(Tuple.Create(account, accountMapItem.Account, accountMapItem.AccountPredicate)); } } if (matches.Select(x => x.Item1).Distinct().Count() != entryItemAccountGroups.Count()) { var missedAccounts = sourceEntry.Items.Select(x => x.Account).Except(matches.Select(x => x.Item1)).ToList(); throw new ValidationException($"Missed accounts:{Environment.NewLine}{string.Join(Environment.NewLine, missedAccounts)}"); } // Performance.MarkEnd("EntryHelper.Validate"); }
public static void Copy(this IEntry sourceEntry, IEntry destinationEntry, IAccountMap accountMap, bool closingOpeningEntryType = false) { // Performance.MarkStart("EntryHelper.Copy"); Validate(sourceEntry, accountMap); foreach (var accountMapItem in accountMap.Items) { if (accountMapItem.Account == null) { continue; } var items = sourceEntry.Items.Where(x => x.Book.Equals(accountMapItem.Book) && accountMapItem.AccountPredicate.Matches(x.Account)).ToList(); if (!items.Any()) { continue; } var entryItem = new EntryItem(); entryItem.Entry = destinationEntry; entryItem.Account = accountMapItem.Account; entryItem.Book = accountMapItem.Book; entryItem.Asset = items.Select(x => x.Asset).Distinct().Single(); entryItem.Debit = items.Sum(x => x.Debit); entryItem.Credit = items.Sum(x => x.Credit); if (entryItem.Debit != entryItem.Credit && entryItem.Debit != 0 && entryItem.Credit != 0 && closingOpeningEntryType) { var minValue = entryItem.Debit < entryItem.Credit ? entryItem.Debit : entryItem.Credit; entryItem.Debit -= minValue; entryItem.Credit -= minValue; } destinationEntry.Items.Add(entryItem); } // Performance.MarkEnd("EntryHelper.Copy"); }
public AccountRepository(IAccountDbContext dbc, IAccountMap map, ILogger <AccountData> log) : base(log, map) { entityContext = dbc; }
public AccountManager(IAccountMap accountMap) { _accountMap = accountMap; }
public static void Copy(this IBalance sourceBalance, IBalance destinationBalance, IAccountMap accountMap) { // Performance.MarkStart("BalanceHelper.Copy(balance)"); var sourceAccounts = new List <IAccount>(sourceBalance.Items.Select(balanceItem => balanceItem.Account)); var selectedAccounts = new List <IAccount>(); foreach (var accountMapItem in accountMap.Items) { if (!accountMapItem.Book.Equals(sourceBalance.Book)) { continue; } var balanceItems = sourceBalance.Items.GetBalanceItems(accountMapItem.AccountPredicate); if (!balanceItems.Any()) { continue; } var newBalanceItem = new BalanceItem(); newBalanceItem.Balance = destinationBalance; newBalanceItem.Account = accountMapItem.Account; newBalanceItem.Asset = balanceItems.First().Asset; newBalanceItem.TotalDebit = balanceItems.Sum(balanceItem => balanceItem.TotalDebit); newBalanceItem.TotalCredit = balanceItems.Sum(balanceItem => balanceItem.TotalCredit); destinationBalance.Items.Add(newBalanceItem); selectedAccounts.AddRange(balanceItems.Select(balanceItem => balanceItem.Account)); } // Performance.MarkStart("BalanceHelper.Copy(balance):Validate"); var missedSourceAccounts = sourceAccounts.Except(selectedAccounts).ToList(); if (missedSourceAccounts.Any()) { throw new ValidationException($"Missed accounts:{Environment.NewLine}{string.Join(Environment.NewLine, missedSourceAccounts)}"); } var duplicateSelectedSourceAccounts = selectedAccounts.GroupBy(account => account).Where(group => group.Count() > 1).Select(group => group.Key).ToList(); if (duplicateSelectedSourceAccounts.Any()) { throw new ValidationException($"Duplicate selected accounts:{Environment.NewLine}{string.Join(Environment.NewLine, duplicateSelectedSourceAccounts)}"); } // Performance.MarkEnd("BalanceHelper.Copy(balance):Validate"); // Performance.MarkEnd("BalanceHelper.Copy(balance)"); }
public AccountRepository(IMainDBContext dbc, IAccountMap map_factory) : base(map_factory) { entity_context = dbc; }