Files
BeWoPlaner/ReportImp/LyvieKupfer/Service/CustomServiceRecordStatisticFactory.cs

121 lines
4.7 KiB
C#

using BeWo.Data.Entities;
using BeWo.Service.Plugins;
using BS.Shared.DataContracts;
using BS.Shared.Extensions;
using BS.Shared.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LyvieKupfer.Service
{
public class CustomServiceRecordStatisticFactory : ServiceRecordStatisticFactory
{
protected override void ProcessServiceRecord(ServiceRecord sr, CostBearer2SupportConcept cb2sc, SupportConceptStatisticsDC stats, DateTime statisticsDate, Calculations calc)
{
decimal minutesProvided = 0;
decimal minutesProvidedRounded = 0;
decimal minutesProvidedThisWeek = 0;
decimal minutesProvidedThisMonth = 0;
decimal minutesProvidedUntilLastMonth = 0;
bool billable = false;
if (sr.ServiceDescription != null && sr.ServiceDescription.ServiceCategory != null)
{
billable = sr.ServiceDescription.ServiceCategory.IsBillable;
}
bool outOfPeriod = true;
if (cb2sc.StartDate.HasValue && cb2sc.EndDate.HasValue)
{
outOfPeriod = false;
DateTime end = cb2sc.EndDate.Value;
if (end < DateTime.MaxValue.Date)
end = end.AddDays(1);
if (sr.Start < cb2sc.StartDate || sr.Start >= end)
{
outOfPeriod = true;
}
}
SupportConceptPeriodStatisticsDC periodStats =
GetPeriodDCFromServiceRecord(stats.PeriodStatistics, sr);
if (billable || (periodStats != null && periodStats.SupportConceptApprovalPeriod.ServiceCategory != null))
{
minutesProvided = (decimal)sr.DurationMinutes;
if (!billable && periodStats.SupportConceptApprovalPeriod.ServiceCategory != null &&
!periodStats.SupportConceptApprovalPeriod.ServiceCategory.IsBillable)
{
minutesProvidedRounded = minutesProvided;
}
else
{
var srDc = MapToServiceRecordDCForStatistic(sr);
minutesProvidedRounded = calc.GetDocumentedDurationInMinutes(srDc, true);
if (periodStats != null)
{
if (periodStats.ServiceRecords == null)
{
periodStats.ServiceRecords = new List<ServiceRecordDC>();
}
periodStats.ServiceRecords.Add(srDc);
}
}
var firstOfMonthDt = new DateTime(statisticsDate.Year, statisticsDate.Month, 1);
DateTime mondayDt = statisticsDate.GetLast(DayOfWeek.Monday).Date;
DateTime sundayDt = statisticsDate.GetNext(DayOfWeek.Sunday).Date;
if (sr.Start >= mondayDt && sr.Start < mondayDt.AddDays(7))
{
minutesProvidedThisWeek = minutesProvidedRounded;
}
if (sr.Start >= firstOfMonthDt && sr.Start < firstOfMonthDt.AddMonths(1))
{
minutesProvidedThisMonth = minutesProvidedRounded;
}
if (sr.Start >= stats.StatisticsStartDate && sr.Start < firstOfMonthDt)
{
minutesProvidedUntilLastMonth += minutesProvidedRounded;
}
CalculateFixedAmountBudget(sr, periodStats, statisticsDate);
}
if (outOfPeriod)
{
stats.MinutesOutOfApprovedPeriod += minutesProvidedRounded;
}
stats.MinutesProvidedTotal += minutesProvided;
stats.MinutesProvidedTotalRounded += minutesProvidedRounded;
stats.MinutesProvidedThisMonth += minutesProvidedThisMonth;
stats.IstTotalUntilThisMonth += minutesProvidedUntilLastMonth;
stats.MinutesProvidedThisWeek += minutesProvidedThisWeek;
if (periodStats != null)
{
if (outOfPeriod)
{
periodStats.MinutesOutOfApprovedPeriod += minutesProvidedRounded;
}
periodStats.MinutesProvidedTotal += minutesProvided;
periodStats.MinutesProvidedTotalRounded += minutesProvidedRounded;
periodStats.MinutesProvidedThisWeek += minutesProvidedThisWeek;
periodStats.MinutesProvidedThisMonth += minutesProvidedThisMonth;
periodStats.IstTotalUntilThisMonth += minutesProvidedUntilLastMonth;
}
}
}
}