public AccountTransactionViewModel(IWorkspace workspace, AccountTransaction model, AccountTransactionDocument document)
 {
     Model = model ?? AccountTransaction.Null;
     _document = document;
     _workspace = workspace;
     _accountTransactionType =
         AccountTransactionTypes.SingleOrDefault(x => x.Id == Model.AccountTransactionTypeId);
 }
        public AccountTransactionDocument CreateDocument(Account account, string description, decimal amount, decimal exchangeRate, IList <Account> accounts)
        {
            // <pex>
            if (account == null)
            {
                throw new ArgumentNullException("account");
            }
            if (account.AccountTypeId != MasterAccountTypeId)
            {
                throw new ArgumentException("Account Type should match Master Account Type");
            }
            // </pex>

            var result = new AccountTransactionDocument {
                Name = Name
            };

            foreach (var accountTransactionType in TransactionTypes)
            {
                var transaction = AccountTransaction.Create(accountTransactionType);
                transaction.Name = description;
                transaction.UpdateAmount(amount, exchangeRate);
                transaction.UpdateAccounts(MasterAccountTypeId, account.Id);
                if (accounts != null && accounts.Count > 0)
                {
                    if (transaction.SourceAccountTypeId != MasterAccountTypeId &&
                        transaction.SourceTransactionValue.AccountId == 0)
                    {
                        Account ac =
                            accounts.FirstOrDefault(x => x.AccountTypeId == transaction.SourceAccountTypeId);
                        if (ac != null)
                        {
                            transaction.SetSourceAccount(ac.AccountTypeId, ac.Id);
                        }
                    }
                    if (transaction.TargetAccountTypeId != MasterAccountTypeId &&
                        transaction.TargetTransactionValue.AccountId == 0)
                    {
                        Account ac =
                            accounts.FirstOrDefault(x => x.AccountTypeId == transaction.TargetAccountTypeId);
                        if (ac != null)
                        {
                            transaction.SetTargetAccount(ac.AccountTypeId, ac.Id);
                        }
                    }
                }
                result.AccountTransactions.Add(transaction);
            }
            return(result);
        }
        public AccountTransactionDocument CreateDocument(Account account, string description, decimal amount, decimal exchangeRate, IList <AccountData> accounts, IList <ForeignCurrency> currencies)
        {
            var result = new AccountTransactionDocument {
                Name = Name, DocumentTypeId = Id
            };

            foreach (var accountTransactionType in TransactionTypes)
            {
                var transaction = AccountTransaction.Create(accountTransactionType);
                var amountRate  = GetExchangeRate(accountTransactionType.ForeignCurrencyId, currencies);
                amount = amount * amountRate;
                transaction.UpdateAmount(amount, exchangeRate, accounts);
                transaction.UpdateAccount(MasterAccountTypeId, account.Id);
                if (accounts != null && accounts.Count > 0)
                {
                    if (transaction.SourceAccountTypeId != MasterAccountTypeId &&
                        transaction.SourceTransactionValue.AccountId == 0)
                    {
                        var ac = accounts.FirstOrDefault(x => x.AccountTypeId == transaction.SourceAccountTypeId);
                        if (ac != null)
                        {
                            transaction.SetSourceAccount(ac.AccountTypeId, ac.AccountId);
                        }
                    }

                    if (transaction.TargetAccountTypeId != MasterAccountTypeId &&
                        transaction.TargetTransactionValue.AccountId == 0)
                    {
                        var ac = accounts.FirstOrDefault(x => x.AccountTypeId == transaction.TargetAccountTypeId);
                        if (ac != null)
                        {
                            transaction.SetTargetAccount(ac.AccountTypeId, ac.AccountId);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(description))
                {
                    transaction.UpdateDescription(description);
                }
                result.AccountTransactions.Add(transaction);
            }
            return(result);
        }
예제 #4
0
 private static void ReverseTransaction(AccountTransaction transaction)
 {
     var ti = transaction.SourceAccountTypeId;
     var tv = transaction.SourceTransactionValue;
     transaction.SourceAccountTypeId = transaction.TargetAccountTypeId;
     transaction.SourceTransactionValue = transaction.TargetTransactionValue;
     transaction.TargetAccountTypeId = ti;
     transaction.TargetTransactionValue = tv;
     transaction.IsReversed = true;
 }
예제 #5
0
        public static AccountTransaction Create(AccountTransactionType template)
        {
            // <pex>
            if (template == null)
                throw new ArgumentNullException("template");
            // </pex>

            var result = new AccountTransaction
                             {
                                 Name = template.Name,
                                 AccountTransactionTypeId = template.Id,
                                 SourceTransactionValue = new AccountTransactionValue { AccountId = template.DefaultSourceAccountId, AccountTypeId = template.SourceAccountTypeId, Name = template.Name },
                                 TargetTransactionValue = new AccountTransactionValue { AccountId = template.DefaultTargetAccountId, AccountTypeId = template.TargetAccountTypeId, Name = template.Name },
                                 SourceAccountTypeId = template.SourceAccountTypeId,
                                 TargetAccountTypeId = template.TargetAccountTypeId
                             };

            return result;
        }
예제 #6
0
        public static AccountTransaction Create(AccountTransactionTemplate template)
        {
            var result = new AccountTransaction
                             {
                                 Name = template.Name,
                                 AccountTransactionTemplateId = template.Id,
                                 SourceTransactionValue = new AccountTransactionValue(),
                                 TargetTransactionValue = new AccountTransactionValue()
                             };

            if (result.SourceTransactionValue != null)
            {
                result.SourceTransactionValue.AccountId = template.DefaultSourceAccountId;
                result.SourceTransactionValue.Name = template.Name;
            }

            if (result.TargetTransactionValue != null)
            {
                result.TargetTransactionValue.AccountId = template.DefaultTargetAccountId;
                result.TargetTransactionValue.Name = template.Name;
            }

            result.SourceAccountTemplateId = template.SourceAccountTemplateId;
            result.TargetAccountTemplateId = template.TargetAccountTemplateId;

            result.DynamicPart = null;
            if (template.DefaultSourceAccountId == 0) result.DynamicPart = true;
            if (template.DefaultTargetAccountId == 0) result.DynamicPart = false;

            return result;
        }
예제 #7
0
        public static AccountTransaction Create(AccountTransactionTemplate template)
        {
            var result = new AccountTransaction
                             {
                                 Name = template.Name,
                                 AccountTransactionTemplateId = template.Id,
                                 SourceTransactionValue = new AccountTransactionValue { IsSource = true, AccountId = template.DefaultSourceAccountId, Name = template.Name },
                                 TargetTransactionValue = new AccountTransactionValue { IsSource = false, AccountId = template.DefaultTargetAccountId, Name = template.Name },
                                 SourceAccountTemplateId = template.SourceAccountTemplateId,
                                 TargetAccountTemplateId = template.TargetAccountTemplateId
                             };

            return result;
        }