219 lines
8.9 KiB
C#
219 lines
8.9 KiB
C#
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
|
using LCU.Library.Internal.IncentiveApiModels.Common;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Converters;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace LCU.Library.Internal.IncentiveApiModels.Entities
|
|
{
|
|
public class Activity : Auditable, IViewTransformable<Activity>
|
|
{
|
|
public int Id { get; set; }
|
|
public Guid AppUserId { get; set; }
|
|
|
|
[Required]
|
|
[JsonConverter(typeof(StringEnumConverter))]
|
|
public Product Product { get; set; }
|
|
|
|
[Required]
|
|
[JsonConverter(typeof(StringEnumConverter))]
|
|
public ActivityType Type { get; set; } = ActivityType.Sale;
|
|
|
|
[Required]
|
|
[JsonConverter(typeof(StringEnumConverter))]
|
|
public SystemType SourceSystem { get; set; }
|
|
|
|
public string? SourceId { get; set; }
|
|
public DateTime SourceCreated { get; set; }
|
|
|
|
[Required]
|
|
public ActivityDetail Detail { get; set; }
|
|
|
|
public List<ActivityMetaData> MetaData { get; set; }
|
|
|
|
[Required]
|
|
public int DepartmentId { get; set; }
|
|
|
|
[Required]
|
|
public string EmployeeId { get; set; }
|
|
|
|
public string? EmployeeEmail { get; set; }
|
|
|
|
public int MatchingActivityId { get; set; }
|
|
|
|
public int MatchingDpAccessoryActivityId { get; set; }
|
|
|
|
public DateTime Accepted { get; set; }
|
|
|
|
[JsonConverter(typeof(StringEnumConverter))]
|
|
public ActivityState State { get; set; } = ActivityState.Created;
|
|
|
|
public virtual IList<ActivityPayoutLineItem> ActivityPayouts { get; set; }
|
|
|
|
public int MatchingGapInsuranceActivityId { get; set; }
|
|
|
|
public static Activity CopyActivityForTransfer(
|
|
Activity activity,
|
|
ActivityTransferAction activityTransferAction,
|
|
string employeeEmail
|
|
)
|
|
{
|
|
return new Activity
|
|
{
|
|
Accepted = activity.Accepted,
|
|
DepartmentId = activityTransferAction.NewActivityDepartmentId,
|
|
Detail = new ActivityDetail
|
|
{
|
|
AccountBalance = activity.Detail.AccountBalance,
|
|
AccountNewBalance = activity.Detail.AccountNewBalance,
|
|
AccountNumber = activity.Detail.AccountNumber,
|
|
AccountStatus = activity.Detail.AccountStatus,
|
|
AgreementNumber = activity.Detail.AgreementNumber,
|
|
BranchOrgName = activity.Detail.BranchOrgName,
|
|
BranchOrgNbr = activity.Detail.BranchOrgNbr,
|
|
DnaPersonNbr = activity.Detail.DnaPersonNbr,
|
|
DebtProtectionAddDate = activity.Detail.DebtProtectionAddDate,
|
|
DebtProtectionRemoveDate = activity.Detail.DebtProtectionRemoveDate,
|
|
GapInsuranceAddDate = activity.Detail.GapInsuranceAddDate,
|
|
GapInsuranceRemoveDate = activity.Detail.GapInsuranceRemoveDate,
|
|
IsDebtProtectionEligible = activity.Detail.IsDebtProtectionEligible,
|
|
IsGapInsuranceEligible = activity.Detail.IsGapInsuranceEligible,
|
|
MemberName = activity.Detail.MemberName,
|
|
StationName = activity.Detail.StationName,
|
|
SubAccountNumber = activity.Detail.SubAccountNumber,
|
|
SubjectOrgNbr = activity.Detail.SubjectOrgNbr,
|
|
SubjectPersonNbr = activity.Detail.SubjectPersonNbr,
|
|
},
|
|
EmployeeEmail = employeeEmail,
|
|
EmployeeId = activityTransferAction.NewActivityEmployeeId,
|
|
MatchingActivityId = activity.MatchingActivityId,
|
|
MatchingDpAccessoryActivityId = activity.MatchingDpAccessoryActivityId,
|
|
MatchingGapInsuranceActivityId = activity.MatchingGapInsuranceActivityId,
|
|
MetaData = activity.MetaData,
|
|
Product = activity.Product,
|
|
SourceCreated = activity.SourceCreated,
|
|
SourceId = activity.SourceId,
|
|
SourceSystem = activity.SourceSystem,
|
|
State = activityTransferAction.ActivityStateBeforeTransfer,
|
|
Type = activity.Type
|
|
};
|
|
}
|
|
|
|
public static Activity CopyActivityForDpAccessory(Activity activity)
|
|
{
|
|
return new Activity
|
|
{
|
|
Accepted = activity.Detail.DebtProtectionAddDate ?? activity.Accepted,
|
|
DepartmentId = activity.DepartmentId,
|
|
Detail = new ActivityDetail
|
|
{
|
|
AccountBalance = activity.Detail.AccountBalance,
|
|
AccountNewBalance = activity.Detail.AccountNewBalance,
|
|
AccountNumber = activity.Detail.AccountNumber,
|
|
AccountStatus = activity.Detail.AccountStatus,
|
|
AgreementNumber = activity.Detail.AgreementNumber,
|
|
BranchOrgName = activity.Detail.BranchOrgName,
|
|
BranchOrgNbr = activity.Detail.BranchOrgNbr,
|
|
DnaPersonNbr = activity.Detail.DnaPersonNbr,
|
|
DebtProtectionAddDate = activity.Detail.DebtProtectionAddDate,
|
|
DebtProtectionRemoveDate = activity.Detail.DebtProtectionRemoveDate,
|
|
GapInsuranceAddDate = activity.Detail.GapInsuranceAddDate,
|
|
GapInsuranceRemoveDate = activity.Detail.GapInsuranceRemoveDate,
|
|
IsDebtProtectionEligible = activity.Detail.IsDebtProtectionEligible,
|
|
IsGapInsuranceEligible = activity.Detail.IsGapInsuranceEligible,
|
|
MemberName = activity.Detail.MemberName,
|
|
StationName = activity.Detail.StationName,
|
|
SubAccountNumber = activity.Detail.SubAccountNumber,
|
|
SubjectOrgNbr = activity.Detail.SubjectOrgNbr,
|
|
SubjectPersonNbr = activity.Detail.SubjectPersonNbr
|
|
},
|
|
EmployeeEmail = activity.EmployeeEmail,
|
|
EmployeeId = activity.EmployeeId,
|
|
MatchingActivityId = activity.MatchingActivityId,
|
|
MatchingDpAccessoryActivityId = activity.Id,
|
|
MatchingGapInsuranceActivityId = activity.MatchingGapInsuranceActivityId,
|
|
MetaData = activity.MetaData,
|
|
Product = Product.DebtProtection,
|
|
SourceCreated = activity.Detail.DebtProtectionAddDate ?? activity.SourceCreated,
|
|
SourceId = activity.SourceId,
|
|
SourceSystem = activity.SourceSystem,
|
|
State = ActivityState.Created,
|
|
Type = activity.Type
|
|
};
|
|
}
|
|
|
|
public bool CanAutoDecision()
|
|
{
|
|
return State != ActivityState.Rejected;
|
|
}
|
|
|
|
public double CalculatedValueTowardsGoal(Product countsForProduct)
|
|
{
|
|
if (Type == ActivityType.Other
|
|
|| State != ActivityState.Accepted && State != ActivityState.PendingTransfer)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
var details = ProductDetail.DetailsForProduct(Product);
|
|
if (countsForProduct == Product.DebtProtectionEligibleLoan && Detail != null)
|
|
{
|
|
return Detail.IsDebtProtectionEligible && Detail.DebtProtectionAddDate != null && Detail.DebtProtectionRemoveDate == null ? 1 : 0;
|
|
}
|
|
|
|
if (countsForProduct == Product && details.ValueType == ProductValue.Numeric)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
if (countsForProduct == Product && Detail is { AccountBalance: { } })
|
|
{
|
|
return Detail.AccountBalance.Value;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
public int CalculatedValueTowardsOther(Product countsForProduct)
|
|
{
|
|
if (Detail != null && countsForProduct == Product.DebtProtectionEligibleLoan && Detail.IsDebtProtectionEligible)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
public int CalculatedValueTowardsGapInsurance() =>
|
|
Detail?.IsGapInsuranceEligible ?? false ? 1 : 0;
|
|
|
|
public bool HasDpAccessory()
|
|
{
|
|
return Type == ActivityType.Sale
|
|
&& Detail.IsDebtProtectionEligible
|
|
&& (
|
|
MatchingDpAccessoryActivityId != 0
|
|
|| Detail.DebtProtectionAddDate?.Date != null
|
|
|| Detail.DebtProtectionRemoveDate?.Date != null
|
|
);
|
|
}
|
|
|
|
public bool HasActiveGapAccessory()
|
|
{
|
|
return Type == ActivityType.Sale
|
|
&& MatchingGapInsuranceActivityId != 0
|
|
&& Detail.IsGapInsuranceEligible
|
|
&& Detail.GapInsuranceAddDate != null
|
|
&& Detail.GapInsuranceRemoveDate?.Date == null;
|
|
}
|
|
|
|
public Activity TransformForView()
|
|
{
|
|
Detail?.TransformForView();
|
|
return this;
|
|
}
|
|
}
|
|
}
|