Adding
This commit is contained in:
+95
@@ -0,0 +1,95 @@
|
||||
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<EmployeeProgress>
|
||||
{
|
||||
public EmployeeProgress(AppUser employee, MonthRange monthRange, IReadOnlyCollection<IPayoutRule> personalRules)
|
||||
{
|
||||
Employee = employee;
|
||||
MonthRange = monthRange;
|
||||
PersonalRules = personalRules;
|
||||
Progress = new Dictionary<int, PerProductActivity>();
|
||||
Goals = new Dictionary<int, PerProductGoal>();
|
||||
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<Activity>();
|
||||
GoalAudit = new List<Goal>();
|
||||
}
|
||||
|
||||
public AppUser Employee { get; }
|
||||
public MonthRange MonthRange { get; }
|
||||
public ICollection<UserDepartment> Departments { get; }
|
||||
public IDictionary<int, PerProductActivity> Progress { get; }
|
||||
public IDictionary<int, PerProductGoal> Goals { get; }
|
||||
public IEnumerable<Activity> ActivityAudit { get; set; }
|
||||
public IEnumerable<Goal> GoalAudit { get; set; }
|
||||
private IReadOnlyCollection<IPayoutRule> PersonalRules { get; }
|
||||
|
||||
public void ApplyAll(ICollection<Activity> 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<Goal> 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user