56 lines
2.7 KiB
C#
56 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using LCU.API.Collections.RepoApi.Domain.Processing;
|
|
using LCU.Shared.Collections.RepoApiLib.Models;
|
|
using LCU.Shared.Collections.RepoApiLib.Models.Consumer;
|
|
|
|
namespace LCU.API.Collections.RepoApi.Domain.AlertChecker
|
|
{
|
|
public class PaymentReceivedChecker : TransactionHistoryChecker
|
|
{
|
|
private readonly List<string> _watchedStatuses = new List<string> { "O4R", "REPO", "SOLD" };
|
|
private readonly List<string> _watchedTransactionTypes = new List<string> { "COFR", "POFF", "EXT", "SPMT", "XPMT" };
|
|
private const string EmailDestination = "[email protected]";
|
|
|
|
public override List<EventAlert> CheckForAlert(RepoAccountProcessingSlip slip)
|
|
{
|
|
var newEventAlerts = new List<EventAlert>();
|
|
var results = GetRecentTransactionsFromType(_watchedTransactionTypes, slip.TransactionHistory);
|
|
if (results != null && _watchedStatuses.Contains(slip.UpdatedRepoAccount.Status))
|
|
{
|
|
var dueDate = slip.Loan?.NextDueDate.ToString(CultureInfo.CurrentCulture) ?? "Unknown";
|
|
foreach (var result in results)
|
|
{
|
|
newEventAlerts.Add(new EventAlert()
|
|
{
|
|
RepoId = slip.UpdatedRepoAccount.RepoId,
|
|
AccountNo = slip.UpdatedRepoAccount.AccountNo,
|
|
Message = "Payment Received",
|
|
SubMessage = FormatTransactionMessage(result),
|
|
CreatedBy = "Batch",
|
|
DateAdded = DateTime.Now,
|
|
EmailRecipient = EmailDestination,
|
|
EmailBody = CreateEmailBody(slip.UpdatedRepoAccount, result, dueDate)
|
|
});
|
|
}
|
|
}
|
|
|
|
return newEventAlerts.Count > 0 ? newEventAlerts : null;
|
|
}
|
|
|
|
private string CreateEmailBody(RepoAccount repoAccount, CoreTransaction coreTransaction, string nextDueDate)
|
|
{
|
|
var message = "Loan Payment<br/><br/>";
|
|
var member = repoAccount.Borrowers?.First(b => b.OwnershipType == 6);
|
|
var memberName = "Member Name: " + member?.IndividualName + "<br/>";
|
|
var accountNo = "Account No: " + repoAccount.AccountNo + "<br/>";
|
|
var paymentAmount = "Payment Amount: " + coreTransaction.amount + "<br/>";
|
|
var nextDueDateString = "Next Due Date: " + nextDueDate + "<br/>";
|
|
var loanBalance = "Loan Balance: " + coreTransaction.runningBalance + "<br/>";
|
|
|
|
return string.Concat(message, memberName, accountNo, paymentAmount, nextDueDateString, loanBalance);
|
|
}
|
|
}
|
|
} |