using LCU.Library.Internal.IncentiveApiModels.Entities; using LCU.Library.Internal.IncentiveApiModels.Enums; using LCU.Library.Internal.IncentiveApiModels.Common; namespace LCU.API.Internal.Operations.IncentiveApi.Models; public class EmployeeProgress : IViewTransformable { public EmployeeProgress(AppUser employee, MonthRange monthRange, IReadOnlyCollection personalRules) { Employee = employee; MonthRange = monthRange; PersonalRules = personalRules; Progress = new Dictionary(); Goals = new Dictionary(); Departments = employee.Departments.Where(dept => dept.StartDate.Date < monthRange.EndTime.Date && (dept.EndDate == null || monthRange.StartTime.Date < dept.EndDate.Value.Date)).ToList(); foreach (var department in Departments) { Progress[department.DepartmentId] = new PerProductActivity(); Goals[department.DepartmentId] = new PerProductGoal(); } ActivityAudit = new List(); GoalAudit = new List(); } public AppUser Employee { get; } public MonthRange MonthRange { get; } public ICollection Departments { get; } public IDictionary Progress { get; } public IDictionary Goals { get; } public IEnumerable ActivityAudit { get; set; } public IEnumerable GoalAudit { get; set; } private IReadOnlyCollection PersonalRules { get; } public void ApplyAll(ICollection activities) { ActivityAudit = ActivityAudit.Concat(activities); foreach (var product in ProductDetail.ProductDetails) { foreach (var activity in activities) { if (Progress.Keys.Contains(activity.DepartmentId) == false) { Progress[activity.DepartmentId] = new PerProductActivity(); } if (!PersonalRules.Any(x => x.RestrictedByPayoutRule(activity, product.Product))) { Progress[activity.DepartmentId].ProductActivity[product.Product] += activity.CalculatedValueTowardsGoal(product.Product); } Progress[activity.DepartmentId].ProductOther[product.Product] += activity.CalculatedValueTowardsOther(product.Product); if (product.Product == Product.Vehicle && activity.Product == Product.Vehicle) { if (!Goals.ContainsKey(activity.DepartmentId)) { Goals[activity.DepartmentId] = new PerProductGoal(); } Goals[activity.DepartmentId].ProductGoals[Product.GAPInsurance] += activity.CalculatedValueTowardsGapInsurance(); } } } } public void ApplyGoals(ICollection findDepartmentGoals) { GoalAudit = GoalAudit.Concat(findDepartmentGoals); foreach (var goal in findDepartmentGoals) { if (Goals.Keys.Contains(goal.DepartmentId) == false) { Goals[goal.DepartmentId] = new PerProductGoal(); } Goals[goal.DepartmentId].ProductGoals[goal.Product] += goal.Value; } } public EmployeeProgress TransformForView() { foreach (var activity in ActivityAudit) { activity?.TransformForView(); } return this; } }