118 lines
4.5 KiB
C#
118 lines
4.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using LCU.API.Collections.CollectionsApiLib.Models;
|
|
using LCU.API.Collections.RepoApi.Domain.Extensions;
|
|
using LCU.API.Collections.RepoApi.Domain.Processing;
|
|
using LCU.API.Collections.RepoApi.Extensions;
|
|
using LCU.Shared.Collections.RepoApiLib.Models;
|
|
|
|
namespace LCU.API.Collections.RepoApi.Domain.AlertChecker
|
|
{
|
|
public class O4rNoRepoChecker : IAlertChecker
|
|
{
|
|
private readonly RepoType _repoType;
|
|
private const string O4RStatus = "O4R";
|
|
private const string EmailDestination = "[email protected]";
|
|
|
|
public O4rNoRepoChecker(RepoType repoType)
|
|
{
|
|
_repoType = repoType;
|
|
}
|
|
|
|
private int GetDayCount()
|
|
{
|
|
switch (_repoType)
|
|
{
|
|
case RepoType.Voluntary: return 2;
|
|
case RepoType.Involuntary: return 60;
|
|
case RepoType.PreSkip: return 31;
|
|
default: return -1;
|
|
}
|
|
}
|
|
|
|
private int GetRepeatDayCount()
|
|
{
|
|
switch (_repoType)
|
|
{
|
|
case RepoType.Voluntary: return 1;
|
|
case RepoType.Involuntary: return 30;
|
|
default: return 0;
|
|
}
|
|
}
|
|
|
|
public bool ShouldSendRepeatedAlert(int daysInStatus, int dayCount, int repeatCount)
|
|
{
|
|
return (
|
|
daysInStatus > dayCount
|
|
&& (repeatCount > 0)
|
|
&& ((daysInStatus - dayCount) % repeatCount == 0)
|
|
);
|
|
}
|
|
|
|
public bool IsRepoAssigned(RepoAccount repoAccount)
|
|
{
|
|
foreach (var collateral in repoAccount.Collaterals)
|
|
{
|
|
if (collateral.RepoCompanySelections?.FirstOrDefault(x => x.RepoCompanyAssignmentDate != null && x.RepoType == _repoType) != null)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public List<EventAlert> CheckForAlert(RepoAccountProcessingSlip slip)
|
|
{
|
|
var daysInStatus = slip.UpdatedRepoAccount.GetDaysInStatus(O4RStatus);
|
|
if (daysInStatus > 0 && slip.UpdatedRepoAccount.Status == O4RStatus)
|
|
{
|
|
// In order to reduce duplicate notifications, do not create a notification if no repo is assigned.
|
|
// An 'action needed' item will be created for O4R No Repo if no repo is assigned. A notification is redundant.
|
|
if (daysInStatus < GetDayCount() || !IsRepoAssigned(slip.UpdatedRepoAccount))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
if (daysInStatus == GetDayCount() || ShouldSendRepeatedAlert(daysInStatus, GetDayCount(), GetRepeatDayCount()))
|
|
{
|
|
return new List<EventAlert>
|
|
{
|
|
new EventAlert()
|
|
{
|
|
RepoId = slip.UpdatedRepoAccount.RepoId,
|
|
AccountNo = slip.UpdatedRepoAccount.AccountNo,
|
|
Message = "O4R No Repo",
|
|
CreatedBy = "Batch",
|
|
DateAdded = DateTime.Now,
|
|
EmailRecipient = _repoType == RepoType.PreSkip
|
|
? EmailDestination
|
|
: null,
|
|
EmailBody = _repoType == RepoType.PreSkip
|
|
? CreateEmailBody(slip.UpdatedRepoAccount)
|
|
: null
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
private string CreateEmailBody(RepoAccount repoAccount)
|
|
{
|
|
var message = "PreSkip has ended, please file a Skip Claim.<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 collateral = repoAccount.Collaterals.FirstOrDefault(c => c.RepoCompanySelections?.FirstOrDefault(x => x.RepoType == _repoType) != null);
|
|
var year = "Year: " + collateral.Year + "<br/>";
|
|
var make = "Make: " + collateral.Make + "<br/>";
|
|
var model = "Model: " + collateral.Model + "<br/>";
|
|
var vin = "VIN: " + collateral.Vin + "<br/>";
|
|
|
|
return string.Concat(message, memberName, accountNo, year, make, model, vin);
|
|
}
|
|
}
|
|
} |