Exemplo n.º 1
0
 public void UpdateBatch(ReceiptBatch batch, ApplicationDbContext context)
 {
     batch.TransactionSubTypeId = ReceiptTypeId;
     batch.ExpectedAmount       = ExpectedAmount.GetValueOrDefault();
     batch.Effective            = EffectiveDate.Date;
     UpdateTransactions(batch, context);
 }
        private void EditBatchReferenceNumbers(ReceiptBatch batch)
        {
            var referenceNumber = batch.BatchReferenceNumber ?? GenerateReferenceNumber(batch);

            batch.Transactions
            .ForEach((t, i) =>
            {
                t.BatchReferenceNumber = "{0}-{1}".FormatWith(referenceNumber, i + 1);
            });
        }
Exemplo n.º 3
0
        private IDictionary <int, SubsidiaryAccount> GetAccountLookup(ReceiptBatch 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 <SubsidiaryAccount>()
                   .ToDictionary(a => a.Id));
        }
Exemplo n.º 4
0
 public void Update(Receipt receipt, ReceiptBatch batch)
 {
     receipt.AccountId            = this.AccountId;
     receipt.ReceiptSourceId      = ReceiptSourceId;
     receipt.TransactionSubTypeId = batch.TransactionSubTypeId.Value;
     receipt.Effective            = batch.Effective;
     receipt.ReceiptNumber        = ReceiptNumber;
     receipt.ReceivedFor          = ReceivedFor;
     receipt.ReceivedFrom         = ReceivedFrom;
     receipt.Comments             = this.Comments;
     receipt.Amount = this.Amount.GetValueOrDefault();
 }
        private Task CreateTransactions(SubsidiaryBatchReceiptEditorForm editor, ReceiptBatch batch)
        {
            var batchAccounts = GetAccounts(editor);

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

            return(context.SaveChangesAsync());
        }
Exemplo n.º 6
0
 public static SubsidiaryBatchReceiptEditorForm FromBatch(ReceiptBatch batch, Receipt[] transactions, ReceiptType[] receiptTypes)
 {
     return(new SubsidiaryBatchReceiptEditorForm
     {
         BatchId = batch.Id,
         ReferenceNumber = batch.BatchReferenceNumber,
         FundId = batch.FundId,
         AvailableTypes = receiptTypes,
         ReceiptTypeId = batch.ReceiptType.Id,
         ExpectedAmount = batch.ExpectedAmount,
         TotalAmount = transactions.Sum(t => t.Amount),
         EffectiveDate = batch.Effective.ToUniversalTime(),
         Transactions = transactions.Select(SubsidiaryReceipt.FromTransaction)
                        .ToArray()
     });
 }
Exemplo n.º 7
0
 public Receipt BuildReceipt(ReceiptBatch batch, ApplicationDbContext context)
 {
     return(new Receipt
     {
         FundId = batch.FundId,
         AccountId = AccountId,
         TransactionBatchId = batch.Id,
         TransactionSubTypeId = batch.TransactionSubTypeId.Value,
         ReceiptSourceId = ReceiptSourceId,
         ReceivedFor = ReceivedFor,
         ReceivedFrom = ReceivedFrom,
         ReceiptNumber = ReceiptNumber,
         Amount = Amount.GetValueOrDefault(),
         Comments = Comments
     });
 }
Exemplo n.º 8
0
        protected override void UpdateTransactions(ReceiptBatch batch, ApplicationDbContext context)
        {
            var accountLookup = GetAccountLookup(batch, context);

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

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

            //add new transactions
            this.Transactions.Where(editor => !editor.Id.HasValue)
            .ForEach(editor =>
            {
                var account = accountLookup[editor.AccountId];
                var receipt = editor.BuildReceipt(batch, context);
                account.AddReceipt(receipt);
                batch.Transactions.Add(receipt);
            });
        }
 private string GenerateReferenceNumber(ReceiptBatch batch)
 {
     return("{0}-{1}".FormatWith(batch.Organization.Abbreviation, batch.Id.ToString("D9")));
 }
Exemplo n.º 10
0
 protected abstract void UpdateTransactions(ReceiptBatch batch, ApplicationDbContext context);