62 lines
2.4 KiB
C#
62 lines
2.4 KiB
C#
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Service.Plugins;
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace BeWoDellbrueck
|
|
{
|
|
public class CustomServiceRecordValidator : ServiceRecordValidator
|
|
{
|
|
public override string[] GetIgnoreCategoriesForOverlappingCheck()
|
|
{
|
|
return new[] { "Arbeitszeit" };
|
|
}
|
|
|
|
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);
|
|
|
|
if (newServiceRecord.ServiceDescription.CategoryName == "Arbeitszeit")
|
|
{
|
|
var span = new DateTimeSpan();
|
|
span.StartDate = newServiceRecord.Start.Value.AddDays(-1);
|
|
span.EndDate = newServiceRecord.Start.Value;
|
|
IList<ServiceRecord> empRecords = DAOFactory.SearchDAO.FindEmployeeServiceRecords(newServiceRecord.Employee.EmployeeOid, span, null, null);
|
|
if (newServiceRecord.ServiceRecordOid.HasValue)
|
|
{
|
|
empRecords = empRecords.Where(r => r.Oid != newServiceRecord.ServiceRecordOid.Value).ToList();
|
|
}
|
|
if (newServiceRecord.GroupOid.HasValue)
|
|
{
|
|
empRecords = empRecords.Where(r => !r.GroupOid.HasValue || r.GroupOid != newServiceRecord.GroupOid).ToList();
|
|
}
|
|
var lastRecord = empRecords.Where(r => r.Start.HasValue && r.Start.Value.Second == 0
|
|
&& r.ServiceDescription.ServiceCategory.Name == newServiceRecord.ServiceDescription.CategoryName).OrderByDescending(r => r.End).FirstOrDefault();
|
|
|
|
if (lastRecord != null)
|
|
{
|
|
span.StartDate = lastRecord.End.Value;
|
|
if (span.EndDate.Subtract(span.StartDate).TotalHours < 11)
|
|
{
|
|
String handlungsOption = "Möchten Sie trotzdem Speichern?";
|
|
bool hatDasRechtTrotzdemZuSpeichern = true;
|
|
|
|
list.Add(new ServiceRecordValidationResultDC
|
|
{
|
|
ResultType = ServiceRecordValidationResult.Custom,
|
|
Message = "Achtung Ihre Ruhezeit nach dem letzten Arbeitszeiteintrag beträgt noch keine 11 Stunden. Bitte Ruhezeit einhalten.\n" + handlungsOption,
|
|
Allow = hatDasRechtTrotzdemZuSpeichern
|
|
});
|
|
}
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
}
|
|
} |