Files

104 lines
3.9 KiB
C#

using System;
using System.Collections.Generic;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Service.Plugins;
using BS.Shared;
using BS.Shared.DataContracts;
namespace AWOMuensterlandRecklinghausen.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);
var e = DAOFactory.GenericDAO.LoadByID<Employee>(newServiceRecord.Employee.EmployeeOid);
var c = e.GetValidContractForDate(newServiceRecord.Start.Value);
var vs = PluginLoader.FindClass<VacationService>();
// Check für MA mit ob Eintrag in den Ferien liegt
var ferien = vs.GetFerien(newServiceRecord.Start.Value, "nrw");
if (ferien != null)
{
if (c != null && c.EmploymentType != null)
{
if (c.EmploymentType.Name.StartsWith("MA mit"))
{
String handlungsOption = "Möchten Sie trotzdem Speichern?";
bool hatDasRechtTrotzdemZuSpeichern = true;
list.Add(new ServiceRecordValidationResultDC
{
ResultType = ServiceRecordValidationResult.Custom,
Message = "Achtung dieser Zeiterfassungseintrag liegt in den Schulferien und damit außerhalb Ihrer Arbeitszeit.\n" + handlungsOption,
Allow = hatDasRechtTrotzdemZuSpeichern
});
}
}
}
//Check ob MonatsMax erreicht ist, da Übertragbarkeit nur innerhalb des Monats ok
SupportConceptPeriodStatisticsDC periodStat = GetStatisticsForServiceRecord(statistics, newServiceRecord);
if (periodStat != null)
{
if (periodStat.SupportConceptApprovalPeriod != null && periodStat.SupportConceptApprovalPeriod.IsApprovedBEShifting)
{
DateTime start = new DateTime(newServiceRecord.Start.Value.Year, newServiceRecord.Start.Value.Month, 1);
DateTime end = start.AddMonths(1).AddDays(-1);
TimeSpan ts = end.Subtract(start);
int arbeitstageProWoche = 5;
var maxDays = (decimal)ts.TotalDays;
while (start < end)
{
var ferientag = vs.GetFerien(start, "nrw");
if (c != null && c.WeeklyDays.HasValue && c.WeeklyDays > 0)
{
arbeitstageProWoche = c.WeeklyDays.Value;
}
if (arbeitstageProWoche <= 5 && (start.DayOfWeek == DayOfWeek.Saturday || start.DayOfWeek == DayOfWeek.Sunday))
{
maxDays -= 1;
}
else
{
if (ferientag != null)
{
maxDays -= 1;
}
else
{
maxDays -= vs.GetFeiertagsFaktor(start);
}
}
start = start.AddDays(1);
}
decimal flsTotalForPeriod = Math.Round(periodStat.MinutesProvidedThisMonth / 60, 2, MidpointRounding.AwayFromZero);
if (periodStat.SupportConceptApprovalPeriod.ApprovedBEInterval.HasValue && periodStat.SupportConceptApprovalPeriod.ApprovedBEInterval.Value == SupportConceptApprovalInterval.Weekly
&& periodStat.SupportConceptApprovalPeriod.ApprovedBEPerInterval.HasValue)
{
decimal newtotalfls = newServiceRecord.RoundedDuration / 60 + flsTotalForPeriod;
decimal maxAllowed = periodStat.SupportConceptApprovalPeriod.ApprovedBEPerInterval.Value / arbeitstageProWoche * maxDays;
if (maxAllowed > 0 && newtotalfls > maxAllowed)
{
String handlungsOption = "Möchten Sie trotzdem Speichern?";
bool hatDasRechtTrotzdemZuSpeichern = true;
list.Add(new ServiceRecordValidationResultDC
{
ResultType = ServiceRecordValidationResult.Custom,
Message = "Achtung dieser Zeiterfassungseintrag überschreitet das monatliche Maximum der bewilligten Stunden.\n" + handlungsOption,
Allow = hatDasRechtTrotzdemZuSpeichern
});
}
}
}
}
return list;
}
}
}