129 lines
4.2 KiB
C#
129 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Service.DCEntityMapper;
|
|
using BeWo.Service.Plugins;
|
|
using BS.Shared;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Extensions;
|
|
|
|
namespace ApiBerlin.Validation
|
|
{
|
|
public class BetreuwoServiceRecordValidator : ServiceRecordValidator
|
|
{
|
|
public override string[] GetIgnoreServiceDescriptionsForOverlappingCheck()
|
|
{
|
|
return new[] { "Fehlzeit", "Freihalteregelung", "Ausfall C19"};
|
|
}
|
|
|
|
public override List<ServiceRecordValidationResultDC> ValidateServiceRecord(ServiceRecordDC newServiceRecord, SupportConceptStatisticsDC statistics,
|
|
int maxDaysEditServiceRecordsAllowed, IList<long> employeeOids, IList<long> cb2scOids)
|
|
{
|
|
var result = base.ValidateServiceRecord(newServiceRecord, statistics, maxDaysEditServiceRecordsAllowed, employeeOids, cb2scOids);
|
|
|
|
bool hasZukunftResult = false;
|
|
|
|
foreach (var r in result)
|
|
{
|
|
if (r.ResultType == ServiceRecordValidationResult.Custom && r.Message.Contains("Zukunft"))
|
|
{
|
|
hasZukunftResult = true;
|
|
}
|
|
}
|
|
if (!hasZukunftResult)
|
|
{
|
|
if (newServiceRecord.End.Value > DateTime.Now)
|
|
{
|
|
result.Add(new ServiceRecordValidationResultDC
|
|
{
|
|
ResultType = ServiceRecordValidationResult.Custom,
|
|
Message = "Das gewählte Datum darf nicht in der Zukunft liegen."
|
|
});
|
|
}
|
|
}
|
|
|
|
bool isGroupRecord = (cb2scOids != null && cb2scOids.Count > 1) ||
|
|
(employeeOids != null && employeeOids.Count > 1);
|
|
|
|
|
|
// Recht bei Klientin mit 2 MA zu dokumentieren, aber nicht sich selbst doppelt!
|
|
// dafür muss das Recht "Zeiterfassung anlegen (bei Überscheidung mit Einträgen anderer Mitarbeiter)" entfernt werden
|
|
// "Zeiterfassung anlegen (bei Überscheidung mit anderen Einträgen eines Klienten)" muss rein
|
|
DateTime start = newServiceRecord.Start.Value;
|
|
bool noTime = (start.Hour == 0 && start.Minute == 0 && start.Second == 1); //Keine Zeit angegeben
|
|
var duration = (decimal)newServiceRecord.End.Value.Subtract(newServiceRecord.Start.Value).TotalMinutes;
|
|
if (!noTime && duration == 0)
|
|
{
|
|
noTime = true;
|
|
}
|
|
newServiceRecord.RoundedDuration = duration;
|
|
decimal roundedDuration = duration;
|
|
|
|
var srdc = PluginLoader.FindClass<ServiceRecordDurationCalculator>();
|
|
if (srdc != null)
|
|
{
|
|
srdc.CalculateRoundedDuration(newServiceRecord);
|
|
|
|
roundedDuration = newServiceRecord.RoundedDuration;
|
|
}
|
|
|
|
decimal? grd = newServiceRecord.GroupRoundedDuration;
|
|
|
|
if (isGroupRecord)
|
|
{
|
|
var groupcalc = PluginLoader.FindClass<GroupDurationCalculator>();
|
|
|
|
if (groupcalc != null)
|
|
{
|
|
var gd = groupcalc.CalculateGroupDuration(cb2scOids.Count, employeeOids.Count, duration, cb2scOids.ToArray());
|
|
if (gd == null)
|
|
{
|
|
grd = roundedDuration;
|
|
roundedDuration = Math.Round(roundedDuration / cb2scOids.Count, 0, MidpointRounding.AwayFromZero);
|
|
}
|
|
else
|
|
{
|
|
grd = gd.TotalDuration;
|
|
roundedDuration = gd.SingleDuration;
|
|
}
|
|
}
|
|
}
|
|
|
|
//var minuteInterval = cbDC.ActualMinuteIntervall;
|
|
//if (minuteInterval > 0)
|
|
newServiceRecord.RoundedDuration = roundedDuration;
|
|
decimal rd = newServiceRecord.RoundedDuration;
|
|
bool ignore = false;
|
|
String[] ignoreNames = GetIgnoreServiceDescriptionsForOverlappingCheck();
|
|
if (ignoreNames != null)
|
|
{
|
|
ignore = ignoreNames.Contains(newServiceRecord.ServiceDescription.Category.Name);
|
|
}
|
|
|
|
|
|
if (!isGroupRecord && !ignore)
|
|
{
|
|
ServiceRecordValidationResultDC resultdc = CheckOverlappingEmployeeServiceRecords(newServiceRecord, start, newServiceRecord.Employee.EmployeeOid, rd);
|
|
if (resultdc != null)
|
|
result.Add(resultdc);
|
|
}
|
|
else if (employeeOids != null && !ignore)
|
|
{
|
|
foreach (long employeeOid in employeeOids)
|
|
{
|
|
ServiceRecordValidationResultDC resultdc = null;
|
|
if (resultdc == null)
|
|
{
|
|
resultdc = CheckOverlappingEmployeeServiceRecords(newServiceRecord, start, employeeOid, grd ?? rd);
|
|
if (resultdc != null)
|
|
result.Add(resultdc);
|
|
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
} |