예제 #1
0
 public void Update(Expense expense, ExpenseBatch batch)
 {
     expense.AccountId            = this.AccountId;
     expense.ExpenseCategoryId    = this.ExpenseCategoryId;
     expense.TransactionSubTypeId = batch.TransactionSubTypeId.Value;
     expense.PayeeId   = batch.PayeeId;
     expense.Effective = batch.Effective;
     expense.Comments  = this.Comments;
     expense.Amount    = this.Amount.GetValueOrDefault();
 }
        private void EditBatchReferenceNumbers(ExpenseBatch batch)
        {
            var referenceNumber = batch.BatchReferenceNumber ?? GenerateReferenceNumber(batch);

            batch.Transactions
            .ForEach((t, i) =>
            {
                t.BatchReferenceNumber = "{0}-{1}".FormatWith(referenceNumber, i + 1);
            });
        }
예제 #3
0
        public void UpdateBatch(ExpenseBatch batch, ApplicationDbContext context)
        {
            batch.TransactionSubTypeId = this.ExpenseTypeId;
            batch.PayeeId        = this.PayeeId;
            batch.ExpectedAmount = this.ExpectedAmount.GetValueOrDefault();
            batch.Effective      = this.EffectiveDate.Date;
            batch.Memo           = this.Memo;

            UpdateTransactions(batch, context);
        }
예제 #4
0
        private IDictionary <int, ClientAccount> GetAccountLookup(ExpenseBatch batch, ApplicationDbContext context)
        {
            var ids = this.Transactions.Select(t => t.AccountId)
                      .Union(batch.Transactions.Select(t => t.AccountId))
                      .Distinct()
                      .ToArray();

            return(context.Accounts.Where(a => ids.Contains(a.Id))
                   .OfType <ClientAccount>()
                   .ToDictionary(a => a.Id));
        }
        private Task CreateTransactions(SubsidiaryBatchExpenseEditorForm editor, ExpenseBatch batch)
        {
            var batchAccounts = GetAccounts(editor);

            editor.Transactions
            .Select(t => t.BuildExpense(batch, context))
            .ForEach(t =>
            {
                batchAccounts.First(x => x.Id == t.AccountId)
                .AddExpense(t);
            });

            return(context.SaveChangesAsync());
        }
예제 #6
0
 public Expense BuildExpense(ExpenseBatch batch, ApplicationDbContext context)
 {
     return(new Expense
     {
         FundId = batch.FundId,
         AccountId = this.AccountId,
         TransactionBatchId = batch.Id,
         TransactionSubTypeId = batch.TransactionSubTypeId.Value,
         ExpenseCategoryId = this.ExpenseCategoryId,
         PayeeId = batch.PayeeId,
         Effective = batch.Effective,
         Memo = "Batch Expense",
         Comments = this.Comments,
         Amount = this.Amount.GetValueOrDefault()
     });
 }
예제 #7
0
 public static ClientBatchExpenseEditorForm FromBatch(ExpenseBatch batch, Expense[] transactions, ExpenseType[] expenseTypes)
 {
     return(new ClientBatchExpenseEditorForm
     {
         BatchId = batch.Id,
         ReferenceNumber = batch.BatchReferenceNumber,
         FundId = batch.FundId,
         AvailableTypes = expenseTypes,
         ExpenseTypeId = batch.ExpenseType.Id,
         PayeeId = batch.PayeeId,
         PayeeName = batch.Payee.Name,
         ExpectedAmount = batch.ExpectedAmount,
         TotalAmount = transactions.Sum(t => t.Amount),
         EffectiveDate = batch.Effective,
         Memo = batch.Memo,
         Transactions = transactions.Select(ClientExpense.FromTransaction)
                        .ToArray()
     });
 }
예제 #8
0
        protected override void UpdateTransactions(ExpenseBatch batch, ApplicationDbContext context)
        {
            var accountLookup = GetAccountLookup(batch, context);

            //remove deleted transactions
            batch.Transactions.OfType <Expense>()
            .Where(expense => this.Transactions.All(editor => editor.Id != expense.Id))
            .ToArray()
            .ForEach(expense =>
            {
                var account = accountLookup[expense.AccountId];
                account.RemoveExpense(expense);
                batch.Transactions.Remove(expense);
            });

            //edit existing transactions
            batch.Transactions.OfType <Expense>()
            .Where(expense => this.Transactions.Any(editor => editor.Id == expense.Id))
            .ToArray()
            .ForEach(expense =>
            {
                var account = accountLookup[expense.AccountId];
                var editor  = this.Transactions.Single(e => e.Id == expense.Id);
                account.RemoveExpense(expense);
                editor.Update(expense, batch);
                account.AddExpense(expense);
            });

            //add new transactions
            this.Transactions.Where(editor => !editor.Id.HasValue)
            .ForEach(editor =>
            {
                var account = accountLookup[editor.AccountId];
                var expense = editor.BuildExpense(batch, context);
                account.AddExpense(expense);
                batch.Transactions.Add(expense);
            });
        }
 private string GenerateReferenceNumber(ExpenseBatch batch)
 {
     return("{0}-{1}".FormatWith(batch.Organization.Abbreviation, batch.Id.ToString("D9")));
 }
예제 #10
0
 protected abstract void UpdateTransactions(ExpenseBatch batch, ApplicationDbContext context);