MH: Services
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -491,6 +491,7 @@
|
||||
<Compile Include="UnitOfWork\HibernateSessionEndpointBehavior.cs" />
|
||||
<Compile Include="UnitOfWork\HibernateSessionBehaviorExtension.cs" />
|
||||
<Compile Include="UnitOfWork\HibernateSessionContextInitializer.cs" />
|
||||
<Compile Include="Urlaubsplanung\UrlaubsplanungsManager.cs" />
|
||||
<Compile Include="Vorlagen\VorlagenManager.cs" />
|
||||
<Compile Include="XAMLInformation\InfoViaXAMLManager.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -481,6 +481,20 @@ namespace BeWo.Service.ServiceContracts
|
||||
[OperationContract]
|
||||
Dictionary<long?, decimal> BerechneAnzEinerAbwesenheitFuerMehrereMitarbeiter(List<long?> empOids, int year, string reason);
|
||||
|
||||
[FaultContract(typeof(BeWoFault))]
|
||||
[OperationContract]
|
||||
decimal CountKrankheitstage(AbwesenheitsInformationDC infoDC);
|
||||
|
||||
[FaultContract(typeof(BeWoFault))]
|
||||
[OperationContract]
|
||||
decimal CountUrlaubstage(AbwesenheitsInformationDC infoDC);
|
||||
|
||||
[FaultContract(typeof(BeWoFault))]
|
||||
[OperationContract]
|
||||
UrlaubsplanerRootDC BuildUrlaubsplanerRootObject(AbsenceOverviewFilterDC filter);
|
||||
|
||||
[FaultContract(typeof(BeWoFault))]
|
||||
[OperationContract]
|
||||
List<EmployeeDC> GetAbsenceOverview(AbsenceOverviewFilterDC filter);
|
||||
}
|
||||
}
|
||||
@@ -1059,9 +1059,9 @@ namespace BeWo.Service.ServiceContracts
|
||||
[OperationContract]
|
||||
List<ServiceRecordDC> GetServiceRecordsByIds(List<long> serviceRecordOids);
|
||||
|
||||
[FaultContract(typeof(BeWoFault))]
|
||||
[OperationContract]
|
||||
List<EmployeeDC> GetAbsenceOverview(AbsenceOverviewFilterDC filter);
|
||||
//[FaultContract(typeof(BeWoFault))]
|
||||
//[OperationContract]
|
||||
//List<EmployeeDC> GetAbsenceOverview(AbsenceOverviewFilterDC filter);
|
||||
|
||||
[FaultContract(typeof(BeWoFault))]
|
||||
[OperationContract]
|
||||
@@ -1233,9 +1233,9 @@ namespace BeWo.Service.ServiceContracts
|
||||
[OperationContract]
|
||||
List<RatingTypeDC> GetRatingTypesByOids(List<long> ratingTypeOids);
|
||||
|
||||
[FaultContract(typeof(BeWoFault))]
|
||||
[OperationContract]
|
||||
UrlaubsplanerRootDC BuildUrlaubsplanerRootObject(AbsenceOverviewFilterDC filter);
|
||||
//[FaultContract(typeof(BeWoFault))]
|
||||
//[OperationContract]
|
||||
//UrlaubsplanerRootDC BuildUrlaubsplanerRootObject(AbsenceOverviewFilterDC filter);
|
||||
|
||||
[FaultContract(typeof(BeWoFault))]
|
||||
[OperationContract]
|
||||
|
||||
@@ -12,6 +12,7 @@ using BeWo.Service.Plugins;
|
||||
using BeWo.Service.SBD;
|
||||
using BeWo.Service.Security;
|
||||
using BeWo.Service.ServiceContracts;
|
||||
using BeWo.Service.Urlaubsplanung;
|
||||
using BeWo.View.Navigation.Filter;
|
||||
using BS.Shared;
|
||||
using BS.Shared.DataContracts;
|
||||
@@ -1936,6 +1937,19 @@ namespace BeWo.Service.ServiceImplementations
|
||||
}
|
||||
}
|
||||
|
||||
public UrlaubsplanerRootDC BuildUrlaubsplanerRootObject(AbsenceOverviewFilterDC filter)
|
||||
{
|
||||
try
|
||||
{
|
||||
UrlaubsplanungsManager manager = new UrlaubsplanungsManager();
|
||||
return manager.BuildUrlaubsplanerRootObject(filter);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw Utils.CreateBeWoFaultException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
public decimal CalculateUrlaubstage(DateTime entryDate, DateTime? endDate, int anzahlArbeitstage, int restlicheTageImJahr, decimal? urlaubstageProJahr) // Enddatum in die Parameterliste
|
||||
{
|
||||
try
|
||||
@@ -2122,11 +2136,8 @@ namespace BeWo.Service.ServiceImplementations
|
||||
{
|
||||
try
|
||||
{
|
||||
List<AbwesenheitsInformationPrint> entities = MapperFactory.AbwesenheitsInformationPrintDC_AbwesenheitsInformationPrint.MapToNewEntities(dcs);
|
||||
foreach (var e in entities)
|
||||
{
|
||||
DAOFactory.GenericDAO.Delete(e);
|
||||
}
|
||||
UrlaubsplanungsManager manager = new UrlaubsplanungsManager();
|
||||
manager.DeleteAbwesenheitsInformationPrints(dcs);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -2157,6 +2168,103 @@ namespace BeWo.Service.ServiceImplementations
|
||||
throw Utils.CreateBeWoFaultException(ex);
|
||||
}
|
||||
}
|
||||
public decimal CountKrankheitstage(AbwesenheitsInformationDC infoDC)
|
||||
{
|
||||
try
|
||||
{
|
||||
var manager = new UrlaubsplanungsManager();
|
||||
return manager.CountKrankheitstage(infoDC);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw Utils.CreateBeWoFaultException(ex);
|
||||
}
|
||||
}
|
||||
public decimal CountUrlaubstage(AbwesenheitsInformationDC infoDC)
|
||||
{
|
||||
try
|
||||
{
|
||||
var manager = new UrlaubsplanungsManager();
|
||||
return manager.CountUrlaubstage(infoDC);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw Utils.CreateBeWoFaultException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public List<EmployeeDC> GetAbsenceOverview(AbsenceOverviewFilterDC filter)
|
||||
{
|
||||
try
|
||||
{
|
||||
var res = new List<EmployeeDC>();
|
||||
var vs = PluginLoader.FindClass<VacationService>();
|
||||
|
||||
var allEmployees = DAOFactory.GenericDAO.GetAllActive<Employee>().ToList();
|
||||
|
||||
List<Team> teams = new List<Team>();
|
||||
if (filter.Teams != null)
|
||||
teams = DAOFactory.GenericDAO.GetActiveByIDs<Team>(filter.Teams) as List<Team>;
|
||||
|
||||
|
||||
//foreach (var emp in allEmployees.OrderBy(x => x.Person.LastNameFirstName))
|
||||
List<Employee> benoetigteMitarbeiter = new List<Employee>();
|
||||
if (teams.Count == 0)
|
||||
benoetigteMitarbeiter = allEmployees;
|
||||
else
|
||||
{
|
||||
foreach (var team in teams)
|
||||
{
|
||||
benoetigteMitarbeiter.AddRange(team.MemberList);
|
||||
}
|
||||
}
|
||||
benoetigteMitarbeiter.OrderBy(x => x.Person.LastNameFirstName).ToList();
|
||||
|
||||
foreach (var emp in benoetigteMitarbeiter)
|
||||
{
|
||||
if (filter.EmploymentType != null)
|
||||
if (!emp.Contracts.Any(x => x.EmploymentType != null && filter.EmploymentType.Contains(x.EmploymentType.Oid.Value)))
|
||||
continue;
|
||||
|
||||
|
||||
var dict = vs.BerechneUrlaubskonto(emp, filter.Year);
|
||||
|
||||
if (filter.AbsenceReasons != null)
|
||||
emp.AbsenceTimes.RemoveRange(x => !filter.AbsenceReasons.Contains(x.AbsenceReason.Oid.Value));
|
||||
|
||||
//if (filter.Teams != null)
|
||||
//{
|
||||
// bool isInTeam = false;
|
||||
// foreach (var team in teams)
|
||||
// {
|
||||
// if (team.MemberList.Contains(emp))
|
||||
// isInTeam = true;
|
||||
// }
|
||||
// if (!isInTeam)
|
||||
// continue;
|
||||
//}
|
||||
|
||||
var empDC = MapperFactory.EmployeeDC_Employee.MapToNewDC(emp);
|
||||
if (dict.ContainsKey(filter.Year))
|
||||
{
|
||||
empDC.Urlaubskonto = dict[filter.Year];
|
||||
}
|
||||
else
|
||||
{
|
||||
int test = 0;
|
||||
}
|
||||
|
||||
res.Add(empDC);
|
||||
}
|
||||
|
||||
return res.OrderBy(e => e.LastNameFirstName).ToList();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw Utils.CreateBeWoFaultException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void MakeNewContractHistoryEntry(Employee employee, StatementType statementType)
|
||||
{
|
||||
|
||||
304
Service/Urlaubsplanung/UrlaubsplanungsManager.cs
Normal file
304
Service/Urlaubsplanung/UrlaubsplanungsManager.cs
Normal file
@@ -0,0 +1,304 @@
|
||||
using BeWo.Data.Access;
|
||||
using BeWo.Data.Entities;
|
||||
using BeWo.Service.Core;
|
||||
using BeWo.Service.DCEntityMapper;
|
||||
using BeWo.Service.Plugins;
|
||||
using BeWo.Service.ServiceImplementations;
|
||||
using BS.Shared.DataContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeWo.Service.Urlaubsplanung
|
||||
{
|
||||
class UrlaubsplanungsManager
|
||||
{
|
||||
public UrlaubsplanerRootDC BuildUrlaubsplanerRootObject(AbsenceOverviewFilterDC filter)
|
||||
{
|
||||
UrlaubsplanerRootDC root = new UrlaubsplanerRootDC();
|
||||
VacationService vs = PluginLoader.FindClass<VacationService>();
|
||||
var empService = new EmployeeServiceImp();
|
||||
var feiertagDaten = vs.GetFeiertage(filter.Year).Where(f => f.Month == filter.Month).ToList();
|
||||
root.Feiertage = new List<FeiertagDC>();
|
||||
foreach (var datum in feiertagDaten)
|
||||
root.Feiertage.Add(vs.GetFeiertag(datum));
|
||||
|
||||
|
||||
root.Abwesenheiten = GetAllEmployeeAbsenceTimesForMonth(filter.Year, filter.Month);
|
||||
root.GeschenkteUrlaubstage = GetGeschenkteUrlaubstageForYear(filter.Year);
|
||||
|
||||
var DCsToDelete = GetAllAbwesenheitsInformationPrints();
|
||||
DeleteAbwesenheitsInformationPrints(DCsToDelete);
|
||||
|
||||
#region auskommentiert
|
||||
root.AlleAbwesenheitsInformationDCs = new List<AbwesenheitsInformationDC>();
|
||||
|
||||
var es = new EmployeeServiceImp();
|
||||
var employee = es.GetAbsenceOverview(filter);
|
||||
|
||||
foreach (var emp in employee)
|
||||
{
|
||||
var infoDC = new AbwesenheitsInformationDC()
|
||||
{
|
||||
Employee = emp,
|
||||
Month = filter.Month,
|
||||
Year = filter.Year,
|
||||
AbsenceTimes = root.Abwesenheiten.Where(a => a.EmployeeOid == emp.EmployeeOid).ToList(),
|
||||
GeschenkteUrlaubstage = root.GeschenkteUrlaubstage.Where(u => u.Employee == emp.EmployeeOid).ToList()
|
||||
};
|
||||
infoDC.TageUrlaub = CountUrlaubstage(infoDC);
|
||||
infoDC.TageKrankheit = CountKrankheitstage(infoDC);
|
||||
root.AlleAbwesenheitsInformationDCs.Add(infoDC);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
return root;
|
||||
}
|
||||
public decimal CountUrlaubstage(AbwesenheitsInformationDC info)
|
||||
{
|
||||
decimal tageUrlaub = 0;
|
||||
|
||||
List<AbsenceTimeDC> urlaubstage = new List<AbsenceTimeDC>();
|
||||
|
||||
List<DateTime> arbeitsfreieTage = GetArbeitsfreieTage(info);
|
||||
|
||||
foreach (var tag in info.AbsenceTimes)
|
||||
{
|
||||
if (tag.Reason.Description.Equals("Urlaub"))
|
||||
urlaubstage.Add(tag);
|
||||
}
|
||||
|
||||
if (urlaubstage.Count > 0)
|
||||
{
|
||||
foreach (var spanne in urlaubstage)
|
||||
{
|
||||
if (spanne.End == null)
|
||||
spanne.End = new DateTime(info.Year, info.Month, DateTime.DaysInMonth(info.Year, info.Month));
|
||||
// Nur ein Tag
|
||||
if (spanne.Start.Value.Date == spanne.End.Value.Date)
|
||||
{
|
||||
if (spanne.Start.Value.TimeOfDay != spanne.End.Value.TimeOfDay)
|
||||
tageUrlaub += 0.5m;
|
||||
else
|
||||
tageUrlaub++;
|
||||
|
||||
}
|
||||
// Mehrere Tage
|
||||
else
|
||||
{
|
||||
// Alle Tage in einem Monat
|
||||
if (spanne.Start.Value.Month == spanne.End.Value.Month)
|
||||
tageUrlaub += Convert.ToInt32((spanne.End.Value.Date - spanne.Start.Value.Date).TotalDays + 1);
|
||||
// Tage über Monate verteilt
|
||||
else
|
||||
{
|
||||
DateTime? tempStart = null;
|
||||
DateTime? tempEnd = null;
|
||||
// Prüfen, ob Start und/oder Ende nicht dem ausgewählten Monat entspricht
|
||||
if (spanne.Start.Value.Month != info.Month)
|
||||
{
|
||||
tempStart = new DateTime(info.Year, info.Month, 1);
|
||||
}
|
||||
if (spanne.End.Value.Month != info.Month)
|
||||
{
|
||||
tempEnd = new DateTime(info.Year, info.Month, 1).AddMonths(1).AddTicks(-1);
|
||||
}
|
||||
|
||||
if (tempStart != null && tempEnd != null)
|
||||
tageUrlaub += Convert.ToInt32((tempEnd.Value.Date - tempStart.Value.Date).TotalDays + 1);
|
||||
else if (tempStart != null && tempEnd == null)
|
||||
tageUrlaub += Convert.ToInt32((spanne.End.Value.Date - tempStart.Value.Date).TotalDays + 1);
|
||||
else if (tempStart == null && tempEnd != null)
|
||||
tageUrlaub += Convert.ToInt32((tempEnd.Value.Date - spanne.Start.Value.Date).TotalDays + 1);
|
||||
}
|
||||
}
|
||||
if (tageUrlaub != 0)
|
||||
{
|
||||
foreach (var tag in arbeitsfreieTage)
|
||||
{
|
||||
if (spanne.AbsenceSpan.ContainsDate(tag))
|
||||
tageUrlaub--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tageUrlaub; // Es wird die richtige Zahl zurückgegeben
|
||||
}
|
||||
public List<AbsenceTimeDC> GetAllEmployeeAbsenceTimesForMonth(int year, int month)
|
||||
{
|
||||
try
|
||||
{
|
||||
var startdate = new DateTime(year, month, 1);
|
||||
var enddate = startdate.AddMonths(1).AddTicks(-1);
|
||||
|
||||
var absencetimes = DAOFactory.SearchDAO.FindAbsenceTimes(startdate, enddate);
|
||||
|
||||
return MapperFactory.AbsenceTimeDC_AbsenceTime.MapToNewDCs(absencetimes);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw Utils.CreateBeWoFaultException(e);
|
||||
}
|
||||
}
|
||||
public List<GeschenkterUrlaubstagDC> GetGeschenkteUrlaubstageForYear(int year)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<GeschenkterUrlaubstagDC> tage = new List<GeschenkterUrlaubstagDC>();
|
||||
|
||||
var tageEntities = DAOFactory.SearchDAO.FindGeschenkteUrlaubstageByYear(year);
|
||||
if (tageEntities != null)
|
||||
tage.AddRange(MapperFactory.GeschenkterUrlaubstagDC_GeschenkterUrlaubstag.MapToNewDCs(tageEntities));
|
||||
|
||||
return tage;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw Utils.CreateBeWoFaultException(ex);
|
||||
}
|
||||
}
|
||||
public List<AbwesenheitsInformationPrintDC> GetAllAbwesenheitsInformationPrints()
|
||||
{
|
||||
try
|
||||
{
|
||||
var entities = DAOFactory.GenericDAO.GetAllActive<AbwesenheitsInformationPrint>();
|
||||
var dcs = MapperFactory.AbwesenheitsInformationPrintDC_AbwesenheitsInformationPrint.MapToNewDCs(entities);
|
||||
return dcs;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw Utils.CreateBeWoFaultException(ex);
|
||||
}
|
||||
}
|
||||
public void DeleteAbwesenheitsInformationPrints(List<AbwesenheitsInformationPrintDC> dcs)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<AbwesenheitsInformationPrint> entities = MapperFactory.AbwesenheitsInformationPrintDC_AbwesenheitsInformationPrint.MapToNewEntities(dcs);
|
||||
foreach (var e in entities)
|
||||
{
|
||||
DAOFactory.GenericDAO.Delete(e);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw Utils.CreateBeWoFaultException(ex);
|
||||
}
|
||||
}
|
||||
public decimal CountKrankheitstage(AbwesenheitsInformationDC info)
|
||||
{
|
||||
int tageKrankheit = 0;
|
||||
List<AbsenceTimeDC> krankheitstage = new List<AbsenceTimeDC>();
|
||||
|
||||
List<DateTime> arbeitsfreieTage = GetArbeitsfreieTage(info);
|
||||
|
||||
foreach (var tag in info.AbsenceTimes)
|
||||
{
|
||||
if (tag.Reason.Description.ToLower().Contains("krank"))
|
||||
krankheitstage.Add(tag);
|
||||
}
|
||||
if (krankheitstage.Count > 0)
|
||||
{
|
||||
foreach (var spanne in krankheitstage)
|
||||
{
|
||||
// Nur ein Tag
|
||||
if (spanne.Start == spanne.End)
|
||||
tageKrankheit++;
|
||||
// Mehrere Tage
|
||||
else
|
||||
{
|
||||
// Wenn Krankheit ein Enddatum hat
|
||||
if (spanne.End != null)
|
||||
{
|
||||
// Alle Tage in einem Monat
|
||||
if (spanne.Start.Value.Month == spanne.End.Value.Month)
|
||||
tageKrankheit += Convert.ToInt32((spanne.End.Value.Date - spanne.Start.Value.Date).TotalDays + 1);
|
||||
// Tage über mehrere Monate verteilt
|
||||
else
|
||||
{
|
||||
// Prüfen, ob Start und/oder Ende nicht dem ausgewählten Monat entspricht
|
||||
DateTime? tempStart = null;
|
||||
DateTime? tempEnd = null;
|
||||
if (spanne.Start.Value.Month != info.Month)
|
||||
{
|
||||
tempStart = new DateTime(info.Year, info.Month, 1);
|
||||
}
|
||||
if (spanne.End.Value.Month != info.Month)
|
||||
{
|
||||
tempEnd = new DateTime(info.Year, info.Month, 1).AddMonths(1).AddTicks(-1);
|
||||
}
|
||||
|
||||
if (tempStart != null && tempEnd != null)
|
||||
tageKrankheit += Convert.ToInt32((tempEnd.Value.Date - tempStart.Value.Date).TotalDays + 1);
|
||||
else if (tempStart != null && tempEnd == null)
|
||||
tageKrankheit += Convert.ToInt32((spanne.End.Value.Date - tempStart.Value.Date).TotalDays + 1);
|
||||
else if (tempStart == null && tempEnd != null)
|
||||
tageKrankheit += Convert.ToInt32((tempEnd.Value.Date - spanne.Start.Value.Date).TotalDays + 1);
|
||||
}
|
||||
}
|
||||
// Wenn Krankheit kein Enddatum gesetzt wurde
|
||||
else
|
||||
{
|
||||
if (spanne.Start.Value.Month != info.Month)
|
||||
{
|
||||
DateTime tempEnd = new DateTime(info.Year, info.Month, DateTime.DaysInMonth(info.Year, info.Month));
|
||||
DateTime tempStart = new DateTime(info.Year, info.Month, 1); ;
|
||||
|
||||
tageKrankheit += Convert.ToInt32((tempEnd.Date - tempStart.Date).TotalDays + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
DateTime tempEnd = new DateTime(spanne.Start.Value.Year, spanne.Start.Value.Month, DateTime.DaysInMonth(spanne.Start.Value.Year, spanne.Start.Value.Month));
|
||||
tageKrankheit += Convert.ToInt32((tempEnd.Date - spanne.Start.Value.Date).TotalDays + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tageKrankheit != 0)
|
||||
{
|
||||
foreach (var tag in arbeitsfreieTage)
|
||||
{
|
||||
if (spanne.AbsenceSpan.ContainsDate(tag))
|
||||
tageKrankheit--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tageKrankheit;
|
||||
}
|
||||
|
||||
private List<DateTime> GetArbeitsfreieTage(AbwesenheitsInformationDC info)
|
||||
{
|
||||
VacationService vs = PluginLoader.FindClass<VacationService>();
|
||||
var feiertage = vs.GetFeiertage(info.Year);
|
||||
|
||||
List<DateTime> wochenendtage = new List<DateTime>();
|
||||
for (int i = 1; i <= DateTime.DaysInMonth(info.Year, info.Month); i++)
|
||||
{
|
||||
var day = new DateTime(info.Year, info.Month, i);
|
||||
|
||||
//Auf Wochenende überprüfen
|
||||
if (day.DayOfWeek == DayOfWeek.Saturday || day.DayOfWeek == DayOfWeek.Sunday)
|
||||
{
|
||||
wochenendtage.Add(day);
|
||||
continue;
|
||||
}
|
||||
//Auf Feiertag überprüfen
|
||||
foreach (var tag in feiertage)
|
||||
{
|
||||
if (tag.Date == day)
|
||||
{
|
||||
wochenendtage.Add(day);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return wochenendtage;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user