public ReconcileBalanceViewModel( ILoggerFactory loggerFactory, IAccountService accountService, ICurrencyService currencyService, ITransactionService transactionService, IAccountLinkViewModelFactory accountLinkViewModelFactory, IForeignAmountViewService foreignAmountViewService, int accountId) { m_logger = loggerFactory.CreateLogger <ReconcileBalanceViewModel>(); m_accountService = accountService; m_currencyService = currencyService; m_transactionService = transactionService; m_accountLinkViewModelFactory = accountLinkViewModelFactory; m_foreignAmountViewService = foreignAmountViewService; m_accountId = accountId; m_primaryCurrencyCode = m_currencyService.GetPrimary().ShortName; m_accountCurrencyCode = m_accountService.Get(m_accountId).Currency.ShortName; m_openingBalance = m_targetBalance = m_accountService.GetBalance(m_accountId, true); m_at = DateTime.Now; IEnumerable <AccountLink> accountLinks = m_accountService.GetAllAsLinks().Where(al => al.Type == AccountType.Income); IEnumerable <IAccountLinkViewModel> accountLinkViewModels = accountLinks.Select(al => m_accountLinkViewModelFactory.Create(al)); Accounts = new ObservableCollection <IAccountLinkViewModel>(accountLinkViewModels.OrderBy(alvm => alvm.Name)); m_selectedCreditAccount = Accounts.FirstOrDefault(); }
internal StubAccountRelationshipItemViewModel( IAccountLinkViewModelFactory accountLinkViewModelFactory, AccountRelationship accountRelationship) { m_accountRelationship = accountRelationship; m_sourceAccount = accountLinkViewModelFactory.Create(m_accountRelationship.SourceAccount); m_destinationAccount = accountLinkViewModelFactory.Create(m_accountRelationship.DestinationAccount); }
internal StubAccountTransactionItemViewModel( IAccountLinkViewModelFactory viewModelFactory, Transaction transaction) { m_transaction = transaction; m_balance = 0; m_creditAccount = viewModelFactory.Create(m_transaction.CreditAccount); m_debitAccount = viewModelFactory.Create(m_transaction.DebitAccount); }
private void CreateExecute(object obj) { IBudgetTransactionItemViewModel initialTransactionViewModel = Transactions .Single(t => t.Type == BudgetTransactionType.Initial); IAccountLinkViewModel suggestedCreditAccount = initialTransactionViewModel.SelectedDebitAccount; // For the debit account, we want the next unused asset account. // Failing that, we want an asset account. // Failing that, we'll take anything! IEnumerable <IAccountLinkViewModel> assetAccountLinks = m_accountLinks .Where(alvm => alvm.Type == AccountType.Asset && alvm != suggestedCreditAccount); IEnumerable <IAccountLinkViewModel> usedAssetAccountLinks = Transactions .Select(t => t.SelectedDebitAccount) .Where(al => al.Type == AccountType.Asset); IEnumerable <IAccountLinkViewModel> unusedAssetAccountLinks = assetAccountLinks .Except(usedAssetAccountLinks); IAccountLinkViewModel suggestedDebitAccount = null; if (unusedAssetAccountLinks.Any()) { suggestedDebitAccount = unusedAssetAccountLinks.First(); } else if (usedAssetAccountLinks.Any()) { suggestedDebitAccount = usedAssetAccountLinks.First(); } else if (m_accountLinks.Any()) { suggestedDebitAccount = m_accountLinks.First(); } var newTransaction = new BudgetTransaction { CreditAccount = suggestedCreditAccount.ToAccountLink(), DebitAccount = suggestedDebitAccount.ToAccountLink(), Amount = 0m }; Transactions.Insert( Transactions.Count - 1,// we maintain that the surplus transaction is last, so - 1 CreateItemViewModel(newTransaction, BudgetTransactionType.Regular) ); }
public BudgetTransactionListViewModel( ILoggerFactory loggerFactory, IAccountService accountService, IBudgetService budgetService, IAccountLinkViewModelFactory accountLinkViewModelFactory, IBudgetTransactionItemViewModelFactory budgetTransactionItemViewModelFactory, IDeleteConfirmationViewService deleteConfirmationViewService, int budgetId) { m_logger = loggerFactory.CreateLogger <BudgetTransactionListViewModel>(); m_accountService = accountService; m_budgetService = budgetService; m_accountLinkViewModelFactory = accountLinkViewModelFactory; m_budgetTransactionItemViewModelFactory = budgetTransactionItemViewModelFactory; m_deleteConfirmationViewService = deleteConfirmationViewService; m_accountLinks = new ObservableCollection <IAccountLinkViewModel>( m_accountService .GetAllAsLinks() .OrderBy(al => al.Name) .Select(al => m_accountLinkViewModelFactory.Create(al))); m_budgetId = budgetId; if (m_budgetId == 0) { int firstIncomeAccountId = 0; int firstAssetAccountId = 0; int secondAssetAccountId = 0; IAccountLinkViewModel firstIncomeAccount = m_accountLinks.FirstOrDefault(al => al.Type == AccountType.Income); IAccountLinkViewModel firstAssetAccount = m_accountLinks.FirstOrDefault(al => al.Type == AccountType.Asset); IAccountLinkViewModel secondAssetAccount = m_accountLinks.Where(al => al.Type == AccountType.Asset) .ElementAtOrDefault(1); if (firstIncomeAccount != null) { firstIncomeAccountId = firstIncomeAccount.AccountId; } if (firstAssetAccount != null) { firstAssetAccountId = secondAssetAccount.AccountId; } if (secondAssetAccount != null) { secondAssetAccountId = secondAssetAccount.AccountId; } var transactions = new List <IBudgetTransactionItemViewModel>(); BudgetTransaction initialTransaction = new BudgetTransaction { CreditAccount = new AccountLink { AccountId = firstIncomeAccountId }, DebitAccount = new AccountLink { AccountId = firstAssetAccountId }, Amount = 0 }; BudgetTransaction surplusTransaction = new BudgetTransaction { CreditAccount = new AccountLink { AccountId = firstAssetAccountId }, DebitAccount = new AccountLink { AccountId = secondAssetAccountId }, Amount = 0 }; transactions.Add(CreateItemViewModel(initialTransaction, BudgetTransactionType.Initial)); transactions.Add(CreateItemViewModel(surplusTransaction, BudgetTransactionType.Surplus)); Transactions = new ObservableCollection <IBudgetTransactionItemViewModel>(transactions); } else { Budget budget = m_budgetService.Get(m_budgetId); var transactions = new List <IBudgetTransactionItemViewModel>(); transactions.Add(CreateItemViewModel(budget.InitialTransaction, BudgetTransactionType.Initial)); transactions.AddRange( budget.Transactions.Select(t => CreateItemViewModel(t, BudgetTransactionType.Regular)) ); transactions.Add(CreateItemViewModel(budget.SurplusTransaction, BudgetTransactionType.Surplus)); Transactions = new ObservableCollection <IBudgetTransactionItemViewModel>(transactions); } CalculateSurplusAmount(); }