Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/Payments.Mvc/Controllers/InvoicesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,14 +452,37 @@ public async Task<IActionResult> Send(int id, [FromBody] SendInvoiceModel model)

await _invoiceService.SendInvoice(invoice, model);

if(invoice.Type == Invoice.InvoiceTypes.Recharge && invoice.Status == Invoice.StatusCodes.PendingApproval)
var user = await _userManager.GetUserAsync(User);

// check if the user email is the same as the customer email for recharges so it goes directly to the pending approval.
if (invoice.Type == Invoice.InvoiceTypes.Recharge &&
string.Equals(user.Email, invoice.CustomerEmail, StringComparison.OrdinalIgnoreCase) &&
invoice.Status == Invoice.StatusCodes.Sent &&
invoice.RechargeAccounts.Where(a => a.Direction == RechargeAccount.CreditDebit.Debit).Any())
{
invoice.PaidAt = DateTime.UtcNow;
invoice.Status = Invoice.StatusCodes.PendingApproval;
var approvalAction = new History()
{
Type = HistoryActionTypes.RechargePaidByCustomer.TypeCode,
ActionDateTime = DateTime.UtcNow,
Actor = user.Name,
Data = new RechargePaidByCustomerHistoryActionType().SerializeData(new RechargePaidByCustomerHistoryActionType.DataType
{
RechargeAccounts = invoice.RechargeAccounts.Where(a => a.Direction == RechargeAccount.CreditDebit.Debit).ToArray()
})
};
invoice.History.Add(approvalAction);
}

if (invoice.Type == Invoice.InvoiceTypes.Recharge && invoice.Status == Invoice.StatusCodes.PendingApproval)
{
//Need to resend these ones too
await _invoiceService.SendFinancialApproverEmail(invoice, null); //Will pull them with a private method
}

// record action
var user = await _userManager.GetUserAsync(User);

var action = new History()
{
Type = HistoryActionTypes.InvoiceSent.TypeCode,
Expand Down
Loading