171 lines
6.9 KiB
C#
171 lines
6.9 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.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.Compact;
|
|
using BS.Shared.Extensions;
|
|
using BS.Shared.Services;
|
|
|
|
namespace PflegedienstWessel.Validation
|
|
{
|
|
public class CustomServiceRecordValidator : ServiceRecordValidator
|
|
{
|
|
public override List<ServiceRecordValidationResultDC> ValidateServiceRecord(ServiceRecordDC newServiceRecord, SupportConceptStatisticsDC statistics,
|
|
int maxDaysEditServiceRecordsAllowed, IList<long> employeeOids, IList<long> cb2scOids)
|
|
{
|
|
if (newServiceRecord.End.Value > DateTime.Now)
|
|
{
|
|
var list2 = new List<ServiceRecordValidationResultDC>();
|
|
list2.Add(new ServiceRecordValidationResultDC
|
|
{
|
|
ResultType = ServiceRecordValidationResult.Custom,
|
|
Message = "Der gewählte Zeitraum darf nicht in der Zukunft liegen."
|
|
});
|
|
|
|
return list2;
|
|
}
|
|
|
|
var list = base.ValidateServiceRecord(newServiceRecord, statistics, maxDaysEditServiceRecordsAllowed, employeeOids, cb2scOids);
|
|
|
|
if (newServiceRecord.ServiceDescription.Category.IsBillable && newServiceRecord.RoundedDuration == 0)
|
|
{
|
|
|
|
list.Add(new ServiceRecordValidationResultDC
|
|
{
|
|
ResultType = ServiceRecordValidationResult.Custom,
|
|
Message = "Die Dauer darf nicht 0 sein."
|
|
});
|
|
|
|
}
|
|
|
|
return list;
|
|
}
|
|
public override ServiceRecordValidationResultDC CheckOverlappingCustomerServiceRecords(ServiceRecordDC newServiceRecord, DateTime start,
|
|
IList<ServiceRecord> allCustomerRecords, bool isGroupRecord, decimal roundedDuration)
|
|
{
|
|
|
|
if (newServiceRecord.ServiceDescription.Category.IsBillable)
|
|
{
|
|
bool darfUeberlappen = newServiceRecord.ServiceDescription.Category.Name.Contains("Pflege") ||
|
|
newServiceRecord.ServiceDescription.Category.Name.StartsWith("HD Tag ") ||
|
|
newServiceRecord.ServiceDescription.Category.Name.StartsWith("HD Rufbereitschaft WG ");
|
|
|
|
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();
|
|
}
|
|
|
|
if (darfUeberlappen)
|
|
{
|
|
customerRecordsWithTime = customerRecordsWithTime.Where(r => !r.ServiceDescription.ServiceCategory.Name.Contains("Pflege") &&
|
|
!r.ServiceDescription.ServiceCategory.Name.StartsWith("HD Tag ") &&
|
|
!r.ServiceDescription.ServiceCategory.Name.StartsWith("HD Rufbereitschaft WG ")).ToList();
|
|
}
|
|
|
|
ServiceRecord overlappingRecord =
|
|
customerRecordsWithTime.FirstOrDefault(
|
|
record => record.ServiceDescription.ServiceCategory.IsBillable &&
|
|
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)
|
|
//{
|
|
// bool darfUeberlappen = newServiceRecord.ServiceDescription.Category.Name.Contains("Pflege") ||
|
|
// newServiceRecord.ServiceDescription.Category.Name.StartsWith("HD Tag ");
|
|
|
|
|
|
// var span = new DateTimeSpan();
|
|
// span.StartDate = start.Date.AddDays(-1);
|
|
// span.EndDate = newServiceRecord.End.Value.Date.AddDays(1);
|
|
// IList<ServiceRecord> empRecords = DAOFactory.SearchDAO.FindEmployeeServiceRecords(employeeOid, span, null, null);
|
|
// if (newServiceRecord.ServiceRecordOid.HasValue)
|
|
// {
|
|
// empRecords = empRecords.Where(r => r.Oid != newServiceRecord.ServiceRecordOid.Value).ToList();
|
|
// }
|
|
// empRecords = empRecords.Where(r => r.Start.HasValue && r.Start.Value.Second == 0).ToList();
|
|
|
|
// if (darfUeberlappen)
|
|
// {
|
|
// empRecords = empRecords.Where(r => !r.ServiceDescription.ServiceCategory.Name.Contains("Pflege") &&
|
|
// !r.ServiceDescription.ServiceCategory.Name.StartsWith("HD Tag ")).ToList();
|
|
// }
|
|
|
|
// try
|
|
// {
|
|
// ServiceRecord overlappingRecord =
|
|
// empRecords.FirstOrDefault(
|
|
// record =>
|
|
// TimeSpanOverlapsWithOtherTimeSpan(start, record.Start, roundedDuration, record.RoundedDuration));
|
|
|
|
// if (overlappingRecord != null)
|
|
// {
|
|
// 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;
|
|
//}
|
|
|
|
|
|
}
|
|
} |