MH: Haus Dülken Doppelbuchungen nicht mehr möglich außer beim Bearbeiten ohne Zeitenänderung
This commit is contained in:
@@ -26,5 +26,149 @@ namespace KetteReports.Validation
|
||||
{
|
||||
return new[] { "Arbeitszeit", "Pause" };
|
||||
}
|
||||
|
||||
public override ServiceRecordValidationResultDC CheckOverlappingCustomerServiceRecords(ServiceRecordDC newServiceRecord, DateTime start, IList<ServiceRecord> allCustomerRecords, bool isGroupRecord, decimal roundedDuration)
|
||||
{
|
||||
|
||||
if (SollBeiDiesemEintragGeprueftWerdenObAndereCustomerEintraegeUeberschnittenWerden(newServiceRecord))
|
||||
{
|
||||
|
||||
var customerRecordsWithTime = allCustomerRecords.Where(r => r.Start.HasValue && r.Start.Value.Second == 0).ToList();
|
||||
|
||||
if (isGroupRecord && newServiceRecord.GroupOid.HasValue)
|
||||
{
|
||||
customerRecordsWithTime =
|
||||
customerRecordsWithTime.Where(r => !r.GroupOid.HasValue || r.GroupOid != newServiceRecord.GroupOid).ToList();
|
||||
}
|
||||
|
||||
|
||||
ServiceRecord overlappingRecord =
|
||||
customerRecordsWithTime.FirstOrDefault(
|
||||
record => TimeSpanOverlapsWithOtherTimeSpan(start, record.Start,
|
||||
roundedDuration,
|
||||
record.GroupRoundedDuration ?? record.RoundedDuration));
|
||||
|
||||
if (overlappingRecord != null)
|
||||
{
|
||||
|
||||
var rdc = new ServiceRecordValidationResultDC
|
||||
{
|
||||
ResultType = ServiceRecordValidationResult.ServiceRecordOverlapping,
|
||||
Message = String.Format("{0}, Dauer {1:0} Minuten", overlappingRecord.Start.Value.ToShortTimeString(),
|
||||
overlappingRecord.GroupRoundedDuration ?? overlappingRecord.RoundedDuration)
|
||||
};
|
||||
|
||||
Customer c = overlappingRecord.Customer;
|
||||
if (c != null)
|
||||
{
|
||||
rdc.CustomerName = String.Format("{0}, {1}", c.Person.LastName, c.Person.FirstName);
|
||||
}
|
||||
Employee e = overlappingRecord.Employee;
|
||||
if (e != null)
|
||||
{
|
||||
rdc.EmployeeName = String.Format("{0} {1}", e.Person.FirstName, e.Person.LastName);
|
||||
}
|
||||
|
||||
|
||||
return rdc;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public override ServiceRecordValidationResultDC CheckOverlappingEmployeeServiceRecords(ServiceRecordDC newServiceRecord, DateTime start, long employeeOid, decimal roundedDuration)
|
||||
{
|
||||
var empRecords = GetEmployeeServiceRecordsWithTimeForLastDay(newServiceRecord, start, employeeOid);
|
||||
|
||||
|
||||
String[] ignoreNames = GetIgnoreCategoriesForOverlappingCheck();
|
||||
|
||||
if (ignoreNames != null)
|
||||
{
|
||||
bool ignore = ignoreNames.Contains(newServiceRecord.ServiceDescription.Category.Name);
|
||||
|
||||
if (ignore)
|
||||
{
|
||||
empRecords =
|
||||
empRecords.Where(r => ignoreNames.Contains(r.ServiceDescription.ServiceCategory.Name)).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
empRecords =
|
||||
empRecords.Where(r => !ignoreNames.Contains(r.ServiceDescription.ServiceCategory.Name)).ToList();
|
||||
}
|
||||
}
|
||||
ignoreNames = GetIgnoreServiceDescriptionsForOverlappingCheck();
|
||||
|
||||
if (ignoreNames != null)
|
||||
{
|
||||
bool ignore = ignoreNames.Contains(newServiceRecord.ServiceDescription.Name);
|
||||
|
||||
if (ignore)
|
||||
{
|
||||
empRecords =
|
||||
empRecords.Where(r => ignoreNames.Contains(r.ServiceDescription.Name)).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
empRecords =
|
||||
empRecords.Where(r => !ignoreNames.Contains(r.ServiceDescription.Name)).ToList();
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
ServiceRecord overlappingRecord =
|
||||
empRecords.FirstOrDefault(
|
||||
record =>
|
||||
TimeSpanOverlapsWithOtherTimeSpan(start, record.Start, roundedDuration, record.GroupRoundedDuration ?? record.RoundedDuration));
|
||||
|
||||
if (overlappingRecord != null && SollBeiDiesemEintragGeprueftWerdenObAndereCustomerEintraegeUeberschnittenWerden(newServiceRecord))
|
||||
{
|
||||
var rdc = new ServiceRecordValidationResultDC
|
||||
{
|
||||
ResultType = ServiceRecordValidationResult.EmployeeOverlapping,
|
||||
Message = String.Format("{0}, Dauer {1:0} Minuten", overlappingRecord.Start.Value.ToShortTimeString(),
|
||||
overlappingRecord.GroupRoundedDuration ?? overlappingRecord.RoundedDuration)
|
||||
};
|
||||
|
||||
Customer c = overlappingRecord.Customer;
|
||||
if (c != null)
|
||||
{
|
||||
rdc.Message += String.Format(" bei Klient/in {0}, {1}", c.Person.LastName, c.Person.FirstName);
|
||||
}
|
||||
Employee e = overlappingRecord.Employee;
|
||||
if (e != null)
|
||||
{
|
||||
rdc.EmployeeName = String.Format("{0} {1}", e.Person.FirstName, e.Person.LastName);
|
||||
}
|
||||
|
||||
return rdc;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return new ServiceRecordValidationResultDC { ResultType = ServiceRecordValidationResult.Error };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool SollBeiDiesemEintragGeprueftWerdenObAndereCustomerEintraegeUeberschnittenWerden(ServiceRecordDC editServiceRecord)
|
||||
{
|
||||
//Bei neuen Einträgen soll immer geprüft werden
|
||||
if (!editServiceRecord.ServiceRecordOid.HasValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
var original = DAOFactory.GenericDAO.LoadByID<ServiceRecord>(editServiceRecord.ServiceRecordOid.Value);
|
||||
if (original.Start == editServiceRecord.Start && original.End == editServiceRecord.End)
|
||||
{
|
||||
//Wenn sich das Datum nicht ändert, muss keine Überlappung geprüft werden (z.B. wenn sich nur der Dokutext ändert)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user