Files
BeWoPlaner/ReportImp/TeamPfeil/Validation/ServiceRecordValidator.cs

75 lines
3.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Service.Plugins;
using BS.Shared;
using BS.Shared.DataContracts;
namespace TeamPfeil.Validation
{
public class CustomServiceRecordValidator : ServiceRecordValidator
{
public override List<ServiceRecordValidationResultDC> ValidateServiceRecord(ServiceRecordDC newServiceRecord, SupportConceptStatisticsDC statistics,
int maxDaysEditServiceRecordsAllowed, IList<long> employeeOids, IList<long> cb2scOids)
{
var list = base.ValidateServiceRecord(newServiceRecord, statistics, maxDaysEditServiceRecordsAllowed, employeeOids, cb2scOids);
//Check ob in der Leistungskategorie das Max erreicht ist, Empfehlung zum Ausweichen auf andere Qualifikation
if (list != null && list.Count > 0 && list.Any(m => m.ResultType == ServiceRecordValidationResult.ApprovedFLSOverspending)
&& newServiceRecord.ServiceDescription.CategoryName.Contains("Qualifikationsniveau"))
{
String handlungsOption = "Möchten Sie trotzdem Speichern?";
bool hatDasRechtTrotzdemZuSpeichern = true;
list.Add(new ServiceRecordValidationResultDC
{
ResultType = ServiceRecordValidationResult.Custom,
Message = "Bitte anderes Qualifikationsniveau als Leistungskategorie wählen." +
"\nDieser Zeiterfassungseintrag überschreitet das Maximum der bewilligten Stunden auf diesem Qualifikationsniveau.\n" + handlungsOption,
Allow = hatDasRechtTrotzdemZuSpeichern
});
}
if (statistics != null)
{
SupportConceptPeriodStatisticsDC periodStat = GetStatisticsForServiceRecord(statistics, newServiceRecord);
if (periodStat == null && newServiceRecord.ServiceDescription.CategoryName.Contains("Qualifikationsniveau"))
{
if (!statistics.PeriodStatistics.Any(s => s.SupportConceptApprovalPeriod.ServiceCategory.Name == newServiceRecord.ServiceDescription.CategoryName))
{
String handlungsOption = "Möchten Sie trotzdem Speichern?";
bool hatDasRechtTrotzdemZuSpeichern = true;
list.Add(new ServiceRecordValidationResultDC
{
ResultType = ServiceRecordValidationResult.Custom,
Message = "Achtung für Ihr Qualifikationsniveau gibt in diesem Hilfeplan keine passende Bewilligung." +
" \nBitte anderes Qualifikationsniveau als Leistungskategorie wählen.\n" + handlungsOption,
Allow = hatDasRechtTrotzdemZuSpeichern
});
}
else
{
var aplist = statistics.PeriodStatistics.Where(s => s.SupportConceptApprovalPeriod.ServiceCategory.Name == newServiceRecord.ServiceDescription.CategoryName).ToList();
if (aplist == null && !aplist.Any(a => a.SupportConceptApprovalPeriod.StartDate <= newServiceRecord.Start && a.SupportConceptApprovalPeriod.EndDate >= newServiceRecord.Start))
{
String handlungsOption = "Möchten Sie trotzdem Speichern?";
bool hatDasRechtTrotzdemZuSpeichern = true;
list.Add(new ServiceRecordValidationResultDC
{
ResultType = ServiceRecordValidationResult.Custom,
Message = "Achtung für Ihr Qualifikationsniveau gibt in diesem Hilfeplan keine passende Bewilligung." +
" \nBitte anderes Qualifikationsniveau als Leistungskategorie wählen.\n" + handlungsOption,
Allow = hatDasRechtTrotzdemZuSpeichern
});
}
}
}
}
return list;
}
}
}