using System; using System.Collections.Generic; namespace LCU.Library.Internal.IncentiveApiModels.Entities { public class AccountingSummary { public IReadOnlyCollection DepartmentPayouts { get; set; } public decimal Total { get; set; } public DateTime PayoutPeriod { get; } public AccountingSummary(DateTime payoutPeriod) { PayoutPeriod = payoutPeriod; DepartmentPayouts = new List(); Total = 0; } public void Apply(List allNewPayouts, Dictionary deptNames) { var departmentSet = new Dictionary(); 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; } } }