110 lines
4.7 KiB
C#
110 lines
4.7 KiB
C#
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BS.Shared.DataContracts;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace TeamPfeil.Korridorberechnung
|
|
{
|
|
public class KorridorberechnungHelper
|
|
{
|
|
public static double BerechneStundenBewilligtGesamt(SupportConceptApprovalPeriodDC ap)
|
|
{
|
|
decimal bewilligt = 0;
|
|
|
|
if (ap.StartDate.HasValue && ap.EndDate.HasValue)
|
|
{
|
|
if (ap.ApprovedBETotal.HasValue)
|
|
bewilligt = ap.ApprovedBETotal.Value;
|
|
else if (ap.ApprovedBEInterval == BS.Shared.SupportConceptApprovalInterval.Daily && ap.ApprovedBEPerInterval.HasValue)
|
|
bewilligt = Convert.ToDecimal((ap.EndDate.Value - ap.StartDate.Value).TotalDays) * ap.ApprovedBEPerInterval.Value;
|
|
else if (ap.ApprovedBEInterval == BS.Shared.SupportConceptApprovalInterval.Weekly && ap.ApprovedBEPerInterval.HasValue)
|
|
bewilligt = Convert.ToDecimal((ap.EndDate.Value - ap.StartDate.Value).TotalDays) / 7 * ap.ApprovedBEPerInterval.Value;
|
|
else if (ap.ApprovedBEInterval == BS.Shared.SupportConceptApprovalInterval.Monthly && ap.ApprovedBEPerInterval.HasValue)
|
|
bewilligt = Convert.ToDecimal((ap.EndDate.Value - ap.StartDate.Value).TotalDays) / 30.42m * ap.ApprovedBEPerInterval.Value;
|
|
else if (ap.ApprovedBEInterval == BS.Shared.SupportConceptApprovalInterval.Yearly && ap.ApprovedBEPerInterval.HasValue)
|
|
bewilligt = Convert.ToDecimal((ap.EndDate.Value - ap.StartDate.Value).TotalDays) / 365 * ap.ApprovedBEPerInterval.Value;
|
|
|
|
}
|
|
|
|
return Convert.ToDouble(bewilligt);
|
|
}
|
|
public static double BerechneBudgetFuerQualAss(double bewilligtGesamt)
|
|
{
|
|
return bewilligtGesamt * 0.20;
|
|
}
|
|
public static double BerechneBudgetFuerUnterstAss(double bewilligtGesamt)
|
|
{
|
|
return bewilligtGesamt * 0.30;
|
|
}
|
|
public static double BerechneGenutzteKorridorstunden(long? supportConceptOid, ServiceCategoryDC serviceCategory, double budgetFuerKorridor, DateTime reportEndDate, bool categoryIsQualified)
|
|
{
|
|
double genutzteStunden = 0;
|
|
|
|
var serviceRecords = DAOFactory.SearchDAO.FindServiceRecordsForSupportConcept(supportConceptOid.Value)
|
|
.Where(sr => sr.ServiceDescription.ServiceCategory.Oid == serviceCategory.ServiceCategoryOid && sr.Start.Value <= reportEndDate)
|
|
.ToList();
|
|
|
|
if (serviceRecords != null && serviceRecords.Count > 0)
|
|
{
|
|
foreach (var sr in serviceRecords)
|
|
{
|
|
List<ValueListEntry2Object> employeeQualifications = sr.Employee.ValueList.Where(v => v.Entry.Type == BS.Shared.ValueListEntryType.StaffQualificationsType).ToList();
|
|
if (employeeQualifications.Count > 0)
|
|
{
|
|
int qualiIndex = SetzeQualiIndex(employeeQualifications); // 0 = nichts hinterlegt | 1 = qualifiziert | 2 = unterstützend | 3 = beides
|
|
if (qualiIndex == 0 || qualiIndex == 3)
|
|
return 0;
|
|
|
|
if (categoryIsQualified)
|
|
{
|
|
if (qualiIndex == 2)
|
|
genutzteStunden += sr.DurationMinutes / 60;
|
|
}
|
|
else
|
|
{
|
|
if (qualiIndex == 1)
|
|
genutzteStunden += sr.DurationMinutes / 60;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
return genutzteStunden;
|
|
}
|
|
|
|
private static int SetzeQualiIndex(List<ValueListEntry2Object> employeeQualifications)
|
|
{
|
|
// 0 = nichts hinterlegt | 1 = qualifiziert | 2 = unterstützend | 3 = beides
|
|
|
|
int index = 0;
|
|
bool hatQA = false;
|
|
bool hatUA = false;
|
|
|
|
foreach (var qualification in employeeQualifications)
|
|
{
|
|
if (qualification.Entry.Value != null)
|
|
{
|
|
if (qualification.Entry.Value.Contains("QA "))
|
|
hatQA = true;
|
|
if (qualification.Entry.Value.Contains("UA "))
|
|
hatUA = true;
|
|
}
|
|
}
|
|
|
|
if (hatQA && !hatUA)
|
|
index = 1;
|
|
else if (hatUA && !hatQA)
|
|
index = 2;
|
|
else if (hatQA && hatUA)
|
|
index = 3;
|
|
|
|
return index;
|
|
}
|
|
}
|
|
}
|