42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using LCU.Library.Internal.IncentiveApiModels.Common;
|
|
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
|
|
|
namespace LCU.API.Internal.Operations.IncentiveApi.Models;
|
|
|
|
public class EmployeeGoals
|
|
{
|
|
public EmployeeGoals(AppUser employee, MonthRange monthRange)
|
|
{
|
|
Employee = employee;
|
|
MonthRange = monthRange;
|
|
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)
|
|
{
|
|
Goals[department.DepartmentId] = new PerProductGoal();
|
|
}
|
|
|
|
GoalAudit = new List<Goal>();
|
|
}
|
|
|
|
public AppUser Employee { get; }
|
|
public MonthRange MonthRange { get; }
|
|
public ICollection<UserDepartment> Departments { get; }
|
|
public IDictionary<int, PerProductGoal> Goals { get; }
|
|
public IEnumerable<Goal> GoalAudit { get; set; }
|
|
|
|
public void ApplyAll(ICollection<Goal> goals)
|
|
{
|
|
GoalAudit = GoalAudit.Concat(goals);
|
|
foreach (var goal in goals)
|
|
{
|
|
if (Goals.Keys.Contains(goal.DepartmentId))
|
|
{
|
|
Goals[goal.DepartmentId].ProductGoals[goal.Product] += goal.Value;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|