Files
BeWoPlaner/ReportImp/PraunheimerWerkstaetten3/Reporting/CustomSupportConceptAnalysisCreator.cs
2020-08-17 15:50:00 +02:00

205 lines
5.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Service.DCEntityMapper;
using BS.Shared;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using BS.Shared.Extensions;
using BS.Shared.Services;
using BeWo.Service.Configuration;
using BeWo.Service.Plugins;
namespace PraunheimerWerkstaetten3.Reporting
{
public class CustomSupportConceptAnalysisCreator : SupportConceptAnalysisCreator
{
public override List<SupportConceptOverviewDC> GetSupportConceptAnalysis(IList<long> c2sOids, long? employeeOid, long? teamOid, DateTime? appointedDate,
int? expiredMonths, bool showArchivedScs)
{
return base.GetSupportConceptAnalysis(c2sOids, employeeOid, teamOid, appointedDate, expiredMonths, showArchivedScs);
}
public override void SetKorridorStatus(SupportConceptOverviewDC iDc)
{
iDc.KorridorStatus = null;
decimal min = -1;
decimal max = -1;
//if (iDc.CustomerLastName == "Akbari")
//{
// int test = 0;
//}
decimal sumPerYear = GetAppovedBEPerYear(iDc);
//if (sumPerYear != 99 && sumPerYear != 120 && sumPerYear != 147 && sumPerYear != 198 && sumPerYear != 288 && sumPerYear != 343 && sumPerYear != 450)
//{
// sumPerYear = iDc.FLSApprovedSum;
//}
sumPerYear = Math.Round(sumPerYear);
if (sumPerYear == 99)
{
min = -10;
max = 10;
}
else if (sumPerYear == 120)
{
min = -10;
max = 13;
}
else if (sumPerYear == 147)
{
min = -13;
max = 25;
}
else if (sumPerYear == 198)
{
min = -25;
max = 45;
}
else if (sumPerYear == 288)
{
min = -44;
max = 27;
}
else if (sumPerYear == 343)
{
min = -27;
max = 53;
}
else if (sumPerYear == 450)
{
min = -53.5m;
max = 53;
}
if (iDc.BEDifferenceApprovedRecordedTillNow < min)
{
iDc.KorridorStatus = "unter Korridor";
iDc.KorridorStatusFarbe = "Red";
}
else if (iDc.BEDifferenceApprovedRecordedTillNow > max)
{
iDc.KorridorStatus = "über Korridor";
iDc.KorridorStatusFarbe = "Red";
}
else
{
iDc.KorridorStatus = "im Korridor";
iDc.KorridorStatusFarbe = "ForestGreen";
}
// if (minpercent <= iDc.BEDifferenceApprovedRecordedTillNowInPercent &&
// iDc.BEDifferenceApprovedRecordedTillNowInPercent <= maxpercent)
// {
// iDc.KorridorStatus = "Innerhalb des Korridors";
// iDc.KorridorStatusFarbe = "ForestGreen";
// }
// else
// {
// iDc.KorridorStatus = "Außerhalb des Korridors";
// iDc.KorridorStatusFarbe = "Red";
// }
//}
iDc.FLSApprovedSum = sumPerYear;
}
public override decimal GetAppovedBEPerYear(SupportConceptOverviewDC iDc)
{
decimal total = iDc.BEApprovedSum;
DateTime? start = iDc.ApprovedStartDate;
if (!start.HasValue)
start = iDc.RequestedStartDate;
DateTime? end = iDc.ApprovedEndDate;
if (!end.HasValue)
end = iDc.RequestedEndDate;
if (start.HasValue && end.HasValue)
{
var monate = DateTimeUtils.GetTotalMonths(start.Value, end.Value);
var years = (total / monate.AnzahlMonateGesamt) * 12;
return years;
// decimal days = (decimal)end.Value.Subtract(start.Value).Days + 1;
//decimal years = days / 365m;
//if (years != 0)
//{
// return total / years;
//}
}
return 0;
}
//public override decimal GetAppovedBEPerYear(SupportConceptOverviewDC iDc)
//{
// int restTageStart = 0;
// int restTageEnd = 0;
// DateTime startDt = start;
// DateTime endDt = end;
// if (startDt.Day > 1)
// {
// var endMonat = new DateTime(startDt.Year, startDt.Month, 1).AddMonths(1).AddDays(-1);
// if (endDt < endMonat)
// {
// endMonat = endDt;
// }
// restTageStart = endMonat.Subtract(startDt).Days + 1;
// startDt = endMonat.AddDays(1);
// }
// if (startDt <= endDt && endDt.AddDays(1).Day != 1)
// {
// var startMonat = new DateTime(endDt.Year, endDt.Month, 1);
// restTageEnd += endDt.Subtract(startMonat).Days + 1;
// endDt = startMonat;
// }
// int fullMonths = 0;
// while (startDt < endDt)
// {
// fullMonths++;
// startDt = startDt.AddMonths(1);
// }
// decimal monthsTotal = fullMonths;
// if (restTageStart != 0)
// {
// monthsTotal += restTageStart / (decimal)DateTime.DaysInMonth(start.Date.Year, start.Date.Month);
// }
// if (restTageEnd != 0)
// {
// monthsTotal += restTageEnd / (decimal)DateTime.DaysInMonth(end.Date.Year, end.Date.Month);
// }
// var am = new AnzahlMonate();
// am.GanzeMonate = fullMonths;
// am.RestTageAnfang = restTageStart;
// am.RestTageEnde = restTageEnd;
// am.AnzahlMonateGesamt = monthsTotal;
// return am;
//}
}
}