167 lines
5.7 KiB
C#
167 lines
5.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Service.DCEntityMapper;
|
|
using BeWo.Service.Plugins;
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Extensions;
|
|
using BS.Shared.Services;
|
|
using DevExpress.XtraCharts;
|
|
using DevExpress.XtraCharts.Design;
|
|
|
|
namespace FeidPartnerReports.Calculation
|
|
{
|
|
public class CustomCalculations : BS.Shared.Services.Calculations
|
|
{
|
|
|
|
public override decimal? GetApprovedHoursForPeriod(SupportConceptCostBearerRelDC relDC,
|
|
SupportConceptApprovalPeriodDC scap,
|
|
List<CostRatePeriodDC> costRatePeriods,
|
|
DateTime? pStart,
|
|
DateTime? pEnd,
|
|
bool useIsCalculationWithFactor)
|
|
{
|
|
if (!pStart.HasValue || !pEnd.HasValue)
|
|
{
|
|
return 0;
|
|
}
|
|
return GetApprovedHoursForPeriod(pStart.Value, pEnd.Value, GetApprovedHoursPerMonth(scap));
|
|
|
|
}
|
|
|
|
public override decimal GetApprovedHoursForPeriod(SupportConceptCostBearerRelDC relDC, DateTime pStart, DateTime pEnd)
|
|
{
|
|
return base.GetApprovedHoursForPeriod(relDC, pStart, pEnd);
|
|
}
|
|
|
|
public override decimal? GetApprovedHoursForPeriod(SupportConceptApprovalPeriodDC scap, List<CostRatePeriodDC> costRatePeriods, DateTime? pStart,
|
|
DateTime? pEnd)
|
|
{
|
|
return base.GetApprovedHoursForPeriod(scap, costRatePeriods, pStart, pEnd);
|
|
}
|
|
|
|
public override decimal? GetApprovedHoursTillNow(SupportConceptApprovalPeriodDC scap, List<CostRatePeriodDC> costRates, DateTime? appointedDate,
|
|
bool excludeRateFactor)
|
|
{
|
|
DateTime end = (appointedDate.HasValue && appointedDate.Value < DateTime.Now.Date)
|
|
? appointedDate.Value
|
|
: DateTime.Now.Date;
|
|
|
|
if (scap.EndDate < end)
|
|
{
|
|
end = scap.EndDate.Value;
|
|
}
|
|
|
|
if (scap.StartDate.HasValue)
|
|
{
|
|
return GetApprovedHoursForPeriod(scap.StartDate.Value, end, GetApprovedHoursPerMonth(scap));
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override decimal? GetApprovedHoursTillNow(SupportConceptCostBearerRelDC relDC, DateTime? appointedDate)
|
|
{
|
|
decimal totalApproved = 0;
|
|
|
|
if (relDC.ApprovalPeriodList != null)
|
|
{
|
|
foreach (var scap in relDC.ApprovalPeriodList)
|
|
{
|
|
totalApproved += GetApprovedHoursTillNow(scap, null, appointedDate, false) ?? 0;
|
|
}
|
|
}
|
|
|
|
return totalApproved;
|
|
}
|
|
|
|
public override decimal? GetApprovedHoursTotal(SupportConceptCostBearerRelDC relDC, bool useIsCalculationWithFactor)
|
|
{
|
|
if (relDC.StartDate.HasValue && relDC.EndDate.HasValue)
|
|
{
|
|
decimal total = 0;
|
|
foreach (var scap in relDC.ApprovalPeriodList)
|
|
{
|
|
var approvedPerMonth = GetApprovedHoursPerMonth(scap);
|
|
var approved = GetApprovedHoursForPeriod(scap.StartDate.Value, scap.EndDate.Value, approvedPerMonth);
|
|
|
|
total += approved;
|
|
}
|
|
return total;
|
|
|
|
//return GetApprovedHoursForPeriod(relDC.StartDate.Value, relDC.EndDate.Value, GetApprovedHoursPerMonth(relDC));
|
|
}
|
|
return base.GetApprovedHoursTotal(relDC, useIsCalculationWithFactor);
|
|
}
|
|
|
|
private decimal GetApprovedHoursForPeriod(DateTime von, DateTime bis, decimal apprrovedPerMonth)
|
|
{
|
|
var monate = DateTimeUtils.GetTotalMonths(von, bis);
|
|
|
|
var proMonat = apprrovedPerMonth;
|
|
|
|
var gesamt = monate.GanzeMonate * proMonat;
|
|
|
|
if (monate.AnzahlMonateGesamt - monate.GanzeMonate > 0)
|
|
{
|
|
gesamt += proMonat * (monate.AnzahlMonateGesamt - monate.GanzeMonate);
|
|
}
|
|
|
|
return gesamt;
|
|
|
|
}
|
|
|
|
public decimal GetApprovedHoursPerMonthGehtNicht(SupportConceptCostBearerRelDC c2s)
|
|
{
|
|
decimal total = 0;
|
|
foreach (var scap in c2s.ApprovalPeriodList)
|
|
{
|
|
total += GetApprovedHoursPerMonth(scap);
|
|
|
|
|
|
|
|
}
|
|
|
|
return total;
|
|
}
|
|
|
|
private decimal GetApprovedHoursPerMonth(SupportConceptApprovalPeriodDC scap)
|
|
{
|
|
if (scap.ApprovedBEInterval.HasValue && scap.ApprovedBEPerInterval.HasValue)
|
|
{
|
|
if (scap.ApprovedBEInterval.Value == SupportConceptApprovalInterval.Monthly)
|
|
{
|
|
return scap.ApprovedBEPerInterval.Value;
|
|
}
|
|
else if (scap.ApprovedBEInterval.Value == SupportConceptApprovalInterval.Quarterly)
|
|
{
|
|
return scap.ApprovedBEPerInterval.Value / 3;
|
|
}
|
|
else if (scap.ApprovedBEInterval.Value == SupportConceptApprovalInterval.HalfYearly)
|
|
{
|
|
return scap.ApprovedBEPerInterval.Value / 6;
|
|
}
|
|
else if (scap.ApprovedBEInterval.Value == SupportConceptApprovalInterval.Yearly)
|
|
{
|
|
return scap.ApprovedBEPerInterval.Value / 12;
|
|
}
|
|
}
|
|
|
|
var flsProWoche = GetApprovedHoursPerWeek(scap, new List<CostRatePeriodDC>()) ?? 0;
|
|
|
|
return flsProWoche * 4.34m;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|