96 lines
3.4 KiB
C#
96 lines
3.4 KiB
C#
using BeWo.Service.Plugins;
|
|
using BS.Shared;
|
|
using BS.Shared.DataContracts;
|
|
using PerspektivenEV.Service;
|
|
using System;
|
|
|
|
namespace PerspektivenEV.Validation
|
|
{
|
|
public class CustomServiceRecordValidator : ServiceRecordValidator
|
|
{
|
|
public override ServiceRecordValidationResultDC CheckApprovedOverspending(SupportConceptCostBearerRelDC reldc, ServiceRecordDC newServiceRecord)
|
|
{
|
|
var calc = new CustomCalculations();
|
|
decimal totalFLSApproved = calc.GetApprovedHoursTotal(reldc, true) ?? 0m;
|
|
|
|
if (totalFLSApproved > 0)
|
|
{
|
|
var factory = PluginLoader.FindClass<ServiceRecordStatisticFactory>();
|
|
var stats = factory.CreateSupportConceptStatisticsImpl(reldc.CostBearer2SupportConceptOid.Value,
|
|
newServiceRecord.Start ?? DateTime.Now, newServiceRecord.ServiceRecordOid);
|
|
|
|
decimal flmTotalRounded = 0;
|
|
decimal flmApprovedForPeriod = 0;
|
|
decimal bewilligtProJahr = 0;
|
|
SupportConceptPeriodStatisticsDC periodStat = GetStatisticsForServiceRecord(stats, newServiceRecord);
|
|
if (periodStat != null)
|
|
{
|
|
flmTotalRounded = periodStat.MinutesProvidedTotalRounded;
|
|
flmApprovedForPeriod = periodStat.MinutesApprovedTotal;
|
|
if (periodStat.SupportConceptApprovalPeriod != null && periodStat.SupportConceptApprovalPeriod.ApprovedBEInterval == SupportConceptApprovalInterval.Yearly)
|
|
{
|
|
bewilligtProJahr = periodStat.SupportConceptApprovalPeriod.ApprovedBEPerInterval ?? 0;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
flmTotalRounded = stats.MinutesProvidedTotalRounded;
|
|
flmApprovedForPeriod = stats.MinutesApprovedTotal;
|
|
if (reldc.ApprovalPeriodList.Count > 0 && reldc.ApprovalPeriodList[0].ApprovedBEInterval == SupportConceptApprovalInterval.Yearly)
|
|
{
|
|
bewilligtProJahr = reldc.ApprovalPeriodList[0].ApprovedBEPerInterval ?? 0;
|
|
}
|
|
}
|
|
|
|
decimal totalFLSNew = (flmTotalRounded + newServiceRecord.RoundedDuration) / 60;
|
|
decimal approvedFlsForPeriod = Math.Round((flmApprovedForPeriod / 60), 2, MidpointRounding.AwayFromZero);
|
|
decimal quotient = 1;
|
|
if (bewilligtProJahr != 0)
|
|
quotient = approvedFlsForPeriod / bewilligtProJahr;
|
|
|
|
if (bewilligtProJahr == 99)
|
|
{
|
|
approvedFlsForPeriod += 10 * quotient;
|
|
}
|
|
else if (bewilligtProJahr == 120)
|
|
{
|
|
approvedFlsForPeriod += 13 * quotient;
|
|
}
|
|
else if (bewilligtProJahr == 147)
|
|
{
|
|
approvedFlsForPeriod += 25 * quotient;
|
|
}
|
|
else if (bewilligtProJahr == 198)
|
|
{
|
|
approvedFlsForPeriod += 45 * quotient;
|
|
}
|
|
else if (bewilligtProJahr == 288)
|
|
{
|
|
approvedFlsForPeriod += 27 * quotient;
|
|
}
|
|
else if (bewilligtProJahr == 343)
|
|
{
|
|
approvedFlsForPeriod += 53 * quotient;
|
|
}
|
|
|
|
if (approvedFlsForPeriod > 0 && totalFLSNew > approvedFlsForPeriod)
|
|
|
|
{
|
|
if (newServiceRecord.ServiceDescription.Category.IsBillable || (periodStat != null && periodStat.SupportConceptApprovalPeriod != null && periodStat.SupportConceptApprovalPeriod.ServiceCategory != null))
|
|
{
|
|
var dc = new ServiceRecordValidationResultDC
|
|
{
|
|
ResultType = ServiceRecordValidationResult.ApprovedFLSOverspending,
|
|
ApprovedHours = Math.Round((flmApprovedForPeriod / 60), 2, MidpointRounding.AwayFromZero),
|
|
HoursNew = Math.Round(totalFLSNew, 2, MidpointRounding.AwayFromZero)
|
|
};
|
|
|
|
dc.CustomerName = reldc.SupportConcept.CustomerFullName;
|
|
return dc;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
} |