44 lines
1.5 KiB
C#
44 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace LCU.Library.Internal.IncentiveApiModels.Entities
|
|
{
|
|
public class AccountingSummary
|
|
{
|
|
public IReadOnlyCollection<DepartmentLineItem> DepartmentPayouts { get; set; }
|
|
public decimal Total { get; set; }
|
|
public DateTime PayoutPeriod { get; }
|
|
|
|
public AccountingSummary(DateTime payoutPeriod)
|
|
{
|
|
PayoutPeriod = payoutPeriod;
|
|
DepartmentPayouts = new List<DepartmentLineItem>();
|
|
Total = 0;
|
|
}
|
|
|
|
public void Apply(List<PayoutLineItem> allNewPayouts, Dictionary<int, string> deptNames)
|
|
{
|
|
var departmentSet = new Dictionary<int, DepartmentLineItem>();
|
|
foreach (var payoutLineItem in allNewPayouts)
|
|
{
|
|
if (!departmentSet.ContainsKey(payoutLineItem.DepartmentId))
|
|
{
|
|
departmentSet.Add(payoutLineItem.DepartmentId,
|
|
new DepartmentLineItem(payoutLineItem.DepartmentId, deptNames[payoutLineItem.DepartmentId],
|
|
PayoutPeriod));
|
|
}
|
|
|
|
departmentSet[payoutLineItem.DepartmentId].Apply(payoutLineItem);
|
|
Total += payoutLineItem.PayoutTotal;
|
|
}
|
|
|
|
foreach (var accountingSummaryLineItem in departmentSet.Values)
|
|
{
|
|
accountingSummaryLineItem.CalculatePercentage(Total);
|
|
}
|
|
|
|
DepartmentPayouts = departmentSet.Values;
|
|
}
|
|
}
|
|
}
|