private IEnumerable<AccountSelectViewModel> GetAccountSelectors(AccountTransactionDocumentType documentType, Account selectedAccount, IAccountService accountService, ICacheService cacheService) { var accountMap = documentType.AccountTransactionDocumentAccountMaps.FirstOrDefault(x => x.AccountId == selectedAccount.Id); return accountMap != null ? documentType.GetNeededAccountTypes().Select(x => new AccountSelectViewModel(accountService, cacheService.GetAccountTypeById(x), accountMap.MappedAccountId, accountMap.MappedAccountName)) : documentType.GetNeededAccountTypes().Select(x => new AccountSelectViewModel(accountService, cacheService.GetAccountTypeById(x))); }
public AccountRowViewModel(Account account, AccountTransactionDocumentType documentType, IAccountService accountService, ICacheService cacheService) { _account = account; Amount = accountService.GetDefaultAmount(documentType, account); Description = accountService.GetDescription(documentType, account); TargetAccounts = GetAccountSelectors(documentType, account, accountService, cacheService).ToList(); }
public void CreateTransactionDocument(Account selectedAccount, AccountTransactionDocumentType documentType, string description, decimal amount, IEnumerable<Account> accounts) { var exchangeRate = GetExchangeRate(selectedAccount, documentType.ExchangeTemplate); _accountDao.CreateTransactionDocument(selectedAccount, documentType, description, amount, exchangeRate, accounts); }
public IEnumerable<Account> GetDocumentAccounts(AccountTransactionDocumentType documentType) { switch (documentType.Filter) { case 1: return GetBalancedAccounts(documentType.MasterAccountTypeId); case 2: return GetAccounts(documentType.AccountTransactionDocumentAccountMaps.Select(x => x.AccountId)); default: return GetAccounts(documentType.MasterAccountTypeId); } }
public string GetDescription(AccountTransactionDocumentType documentType, Account account) { var result = documentType.DescriptionTemplate; if (string.IsNullOrEmpty(result)) return result; while (Regex.IsMatch(result, "\\[:([^\\]]+)\\]")) { var match = Regex.Match(result, "\\[:([^\\]]+)\\]"); result = result.Replace(match.Groups[0].Value, GetCustomData(account, match.Groups[1].Value)); } if (result.Contains("[MONTH]")) result = result.Replace("[MONTH]", DateTime.Now.ToMonthName()); if (result.Contains("[NEXT MONTH]")) result = result.Replace("[NEXT MONTH]", DateTime.Now.ToNextMonthName()); if (result.Contains("[WEEK]")) result = result.Replace("[WEEK]", DateTime.Now.WeekOfYear().ToString(CultureInfo.CurrentCulture)); if (result.Contains("[NEXT WEEK]")) result = result.Replace("[NEXT WEEK]", (DateTime.Now.NextWeekOfYear()).ToString(CultureInfo.CurrentCulture)); if (result.Contains("[YEAR]")) result = result.Replace("[YEAR]", (DateTime.Now.Year).ToString(CultureInfo.CurrentCulture)); if (result.Contains("[ACCOUNT NAME]")) result = result.Replace("[ACCOUNT NAME]", account.Name); return result; }
public decimal GetDefaultAmount(AccountTransactionDocumentType documentType, Account account) { decimal result = 0; if (!string.IsNullOrEmpty(documentType.DefaultAmount)) { var da = documentType.DefaultAmount; if (Regex.IsMatch(da, "\\[:([^\\]]+)\\]")) { var match = Regex.Match(da, "\\[:([^\\]]+)\\]"); da = GetCustomData(account, match.Groups[1].Value); decimal.TryParse(da, out result); } else if (da == string.Format("[{0}]", Resources.Balance)) { result = Math.Abs(GetAccountBalance(account.Id)); } else if (da == string.Format("[{0}]", "BalanceEx")) { var er = GetExchangeRate(account, documentType.ExchangeTemplate); result = er != 1 ? Math.Abs(GetAccountExchangeBalance(account.Id) * er) : Math.Abs(GetAccountBalance(account.Id)); } else decimal.TryParse(da, out result); } return result; }
public DocumentTypeButtonViewModel(AccountTransactionDocumentType model, Account account) { Model = model; Account = account; SelectDocumentTypeCommand = new DelegateCommand<string>(OnSelectDocumentType); }
public void Update(AccountTransactionDocumentType value) { SelectedDocumentType = value; Accounts.Clear(); var accounts = GetAccounts(value); Accounts.AddRange(accounts .AsParallel() .SetCulture() .Select(x => new AccountRowViewModel(x, value, _accountService, _cacheService))); OnOnUpdate(EventArgs.Empty); }
private IEnumerable<Account> GetAccounts(AccountTransactionDocumentType documentType) { return _accountService.GetDocumentAccounts(documentType); }
public DocumentCreationData(Account account,AccountTransactionDocumentType documentType) { Account = account; DocumentType = documentType; }
public AccountTransactionDocument CreateTransactionDocument(Account selectedAccount, AccountTransactionDocumentType documentType, string description, decimal amount, IEnumerable<Account> accounts) { var exchangeRate = GetExchangeRate(selectedAccount.ForeignCurrencyId, documentType.ExchangeTemplate); var accountData = accounts.Select(x => new AccountData(x) { ExchangeRate = GetExchangeRate(x.ForeignCurrencyId, documentType.ExchangeTemplate) }); return _accountDao.CreateTransactionDocument(selectedAccount, documentType, description, amount, exchangeRate, accountData, _cacheService.GetForeignCurrencies()); }
private void CreateTransaction(AccountTransactionDocumentType accountTransactionDocumentType, Account masterAccount, decimal amount, params Account[] accounts) { _accountService.CreateTransactionDocument(masterAccount, accountTransactionDocumentType, "", amount, accounts); Workspace.CommitChanges(); }
private AccountTransactionDocumentType CreateTransactionDocument(AccountType masterAccountType, params AccountTransactionType[] transactionTypes) { var result = new AccountTransactionDocumentType(); foreach (var accountTransactionType in transactionTypes) { result.TransactionTypes.Add(accountTransactionType); } result.MasterAccountTypeId = masterAccountType.Id; Workspace.Add(result); Workspace.CommitChanges(); return result; }