示例#1
0
        private void AddBatchReferenceNumbers(TransferBatch batch)
        {
            var referenceNumber = GenerateReferenceNumber(batch);

            batch.BatchReferenceNumber = referenceNumber;

            batch.Transactions
            .ForEach((t, i) =>
            {
                t.BatchReferenceNumber = "{0}-{1}".FormatWith(referenceNumber, i + 1);
            });
        }
示例#2
0
        public async Task <ICommandResult> Handle(TransferAmountCommand message)
        {
            Logger.Trace("Handle");

            if (message.ModelState.NotValid())
            {
                return(new FailureResult("Unable to transfer {0:C} from account {1} to account {2}"
                                         .FormatWith(message.Editor.Amount, message.Editor.FromAccountId, message.Editor.ToAccountId)));
            }

            var payee = await payees.GetById(message.Editor.PayeeId)
                        .FirstAsync();

            var fromAccount = await accounts.GetById(message.Editor.FromAccountId)
                              .FirstAsync();

            var expeneseType = await context.TransactionSubTypes.OfType <ExpenseType>()
                               .FirstAsync(t => t.Name == ExpenseType.Transfer);

            var expense = new Expense
            {
                ExpenseType = expeneseType,
                Amount      = message.Editor.Amount,
                Memo        = "Transfer",
                Fund        = fromAccount.Fund,
                Account     = fromAccount,
                Payee       = payee
            };

            fromAccount.AddExpense(expense);

            var toAccount = await accounts.GetById(message.Editor.ToAccountId)
                            .FirstAsync();

            var receiptType = await context.TransactionSubTypes.OfType <ReceiptType>()
                              .FirstAsync(t => t.Name == ReceiptType.Transfer);

            var receipt = new Receipt
            {
                ReceiptType  = receiptType,
                Amount       = message.Editor.Amount,
                ReceivedFrom = fromAccount.Name,
                Fund         = fromAccount.Fund,
                Account      = toAccount
            };

            toAccount.AddReceipt(receipt);

            var transferBatch = new TransferBatch
            {
                ParentId         = message.Editor.ParentBatchId,
                TriggerId        = message.Editor.TriggerTransactionId,
                TriggerAccountId = message.Editor.TriggerTransactionAccountId,
                FundId           = fromAccount.FundId,
                ExpectedAmount   = 0,
                FromAccount      = fromAccount,
                ToAccount        = toAccount,
                Effective        = DateTime.UtcNow,
                Committed        = true,
                Transactions     = new Transaction[] { expense, receipt }
            };

            context.Batches.Add(transferBatch);

            await context.SaveChangesAsync();

            return(await Task.FromResult(new SuccessResult(transferBatch.Id)));
        }
示例#3
0
 private string GenerateReferenceNumber(TransferBatch batch)
 {
     return("{0}-{1}".FormatWith(batch.Organization.Abbreviation, batch.Id.ToString("D9")));
 }