Files
BeWoPlaner/Report/ReportObjects/MitarbeiterauslastungRO.cs

405 lines
15 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BS.Shared.Extensions;
namespace BeWo.Report.ReportObjects
{
public class MitarbeiterauslastungRO : AbstractBeWoReportObject<MitarbeiterauslastungRO>
{
private List<EmployeeDetail> employeeDetailList = new List<EmployeeDetail>();
private List<TeamDetail> teamDetailList = new List<TeamDetail>();
public DateTime ReportStartDate { get; set; }
public DateTime ReportEndDate { get; set; }
//Gesamt bewilligte Stunden pro Woche
public decimal ApprovedHoursPerWeekTotal { get; set; }
// Nur Anteil an Betreuung
public decimal ApprovedHoursPerWeek { get; set; }
public decimal ApprovedHoursPerWeekWithRateFactorTotal { get; set; }
public decimal ApprovedHoursPerWeekWithRateFactor { get; set; }
//Gesamt bewilligte Stunden pro Monat
public decimal ApprovedHoursPerMonthTotal { get; set; }
// Nur Anteil an Betreuung
public decimal ApprovedHoursPerMonth { get; set; }
public decimal ApprovedHoursPerMonthWithRateFactorTotal { get; set; }
public decimal ApprovedHoursPerMonthWithRateFactor { get; set; }
public decimal DirectIst { get; set; }
public decimal MittelbarIst { get; set; }
public decimal RelationDirectToMittelbar { get; set; }
public decimal RelationIstSoll { get; set; }
public List<EmployeeDetail> EmployeeDetailList
{
get { return employeeDetailList; }
set { employeeDetailList = value; }
}
public List<TeamDetail> TeamDetailList
{
get { return teamDetailList; }
set { teamDetailList = value; }
}
public static MitarbeiterauslastungRO Create(long? employeeOid, IList<long> teamOids, DateTime startDate, DateTime endDate)
{
IList<long> employeeOids = new List<long>();
if (employeeOid.HasValue)
{
employeeOids.Add(employeeOid.Value);
}
return Create(employeeOids, teamOids, startDate, endDate);
}
public static MitarbeiterauslastungRO Create(IList<long> employeeOids, IList<long> teamOids, DateTime startDate, DateTime endDate, bool teamnachklient = true)
{
var ro = new MitarbeiterauslastungRO();
ro.ReportStartDate = startDate;
ro.ReportEndDate = endDate;
var teamOid2Details = new Dictionary<long, TeamDetail>();
//Dictionary<String, bool> teamEmployeeDict = new Dictionary<string, bool>();
IList<Employee> employees = null;
if (employeeOids != null && employeeOids.Count > 0)
{
//Mitarbeiter wurde ausgewählt
employees = DAOFactory.GenericDAO.LoadByIDs<Employee>(employeeOids);
}
else if (teamOids != null)
{
//Ein oder alle Teams wurden ausgewählt
foreach (var teamOid in teamOids)
{
var teamTemp = DAOFactory.GenericDAO.GetByID<Team>(teamOid);
TeamDetail td = null;
if (!teamOid2Details.ContainsKey(teamTemp.Oid.Value))
{
td = new TeamDetail();
td.TeamName = teamTemp.Name;
td.TeamLeader = teamTemp.Leader;
ro.TeamDetailList.Add(td);
teamOid2Details.Add(teamTemp.Oid.Value, td);
}
else
{
td = teamOid2Details[teamTemp.Oid.Value];
}
if (!teamnachklient && teamTemp.MemberList != null && teamTemp.MemberList.Count > 0)
{
foreach (Employee emp in teamTemp.MemberList)
{
var empDetail = new EmployeeDetail();
ro.EmployeeDetailList.Add(empDetail);
td.EmployeeDetailList.Add(empDetail);
empDetail.Teams = DAOFactory.SearchDAO.FindTeamsOfEmployee(emp.Oid.Value);
empDetail.Employee = emp;
empDetail.LastName = emp.Person.LastName;
empDetail.FirstName = emp.Person.FirstName;
empDetail.FullName = String.Format("{0}, {1}", empDetail.LastName, empDetail.FirstName);
}
}
else
{
var customers = DAOFactory.SearchDAO.FindCustomerOfTeam(teamOid);
if (customers.Count > 0)
{
foreach (var c in customers)
{
var empDetail = new EmployeeDetail();
ro.EmployeeDetailList.Add(empDetail);
td.EmployeeDetailList.Add(empDetail);
empDetail.Teams = new List<Team> { teamTemp };
empDetail.Employee = null;
empDetail.Customer = c;
empDetail.LastName = c.Person.LastName;
empDetail.FirstName = c.Person.FirstName;
empDetail.FullName = String.Format("{0}, {1}", empDetail.LastName, empDetail.FirstName);
}
}
}
}
}
else
{
//Auswertung über alle Mitarbeiter
employees = DAOFactory.GenericDAO.GetAllActive<Employee>();
}
if (employees != null)
{
foreach (Employee emp in employees)
{
var empDetail = new EmployeeDetail();
ro.EmployeeDetailList.Add(empDetail);
empDetail.Teams = DAOFactory.SearchDAO.FindTeamsOfEmployee(emp.Oid.Value);
empDetail.Employee = emp;
empDetail.LastName = emp.Person.LastName;
empDetail.FirstName = emp.Person.FirstName;
empDetail.FullName = String.Format("{0}, {1}", empDetail.LastName, empDetail.FirstName);
}
foreach (EmployeeDetail employee in ro.EmployeeDetailList)
{
if (employee.Employee != null && employee.Teams.Count > 0)
{
foreach (Team t in employee.Teams)
{
TeamDetail td = null;
if (!teamOid2Details.ContainsKey(t.Oid.Value))
{
td = new TeamDetail();
td.TeamName = t.Name;
td.TeamLeader = t.Leader;
ro.TeamDetailList.Add(td);
teamOid2Details.Add(t.Oid.Value, td);
}
else
{
td = teamOid2Details[t.Oid.Value];
}
td.EmployeeDetailList.Add(employee);
}
}
}
}
ro.TeamDetailList.Sort((t1, t2) => t1.TeamName.CompareTo(t2.TeamName));
ro.EmployeeDetailList.Sort((e1, e2) => e1.FullName.CompareTo(e2.FullName));
return ro;
}
[DebuggerDisplay("{FirstName} {LastName}")]
public class EmployeeDetail
{
private List<SupportConceptDetail> scDetailList = new List<SupportConceptDetail>();
public IList<Team> Teams { get; set; }
public Employee Employee { get; set; }
public Customer Customer { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName { get; set; }
public bool HasContract { get; set; }
public decimal ApprovedHoursPerWeekTotal { get; set; }
public decimal ApprovedHoursPerWeek { get; set; }
public decimal ApprovedHoursPerWeekWithRateFactorTotal { get; set; }
public decimal ApprovedHoursPerWeekWithRateFactor { get; set; }
public decimal ApprovedHoursPerMonthTotal { get; set; }
public decimal ApprovedHoursPerMonth { get; set; }
public decimal ApprovedHoursPerMonthWithRateFactorTotal { get; set; }
public decimal ApprovedHoursPerMonthWithRateFactor { get; set; }
public decimal DirectIst { get; set; }
public decimal MittelbarIst { get; set; }
public decimal RelationDirectToMittelbar { get; set; }
public decimal RelationIstSoll { get; set; }
public decimal MinutesOfOtherActivities { get; set; }
public decimal WeeklyTotalHoursByContract { get; set; }
public decimal FLSTotalHoursByContract { get; set; }
public decimal MonthlyTotalHoursByContract { get; set; }
public decimal FLSTotalMonthlyHoursByContract { get; set; }
public String AbsenceTimeString { get; set; }
public List<SupportConceptDetail> SupportConceptDetailList
{
get { return scDetailList; }
set { scDetailList = value; }
}
}
[DebuggerDisplay("{CustomerFullName}")]
public class SupportConceptDetail
{
public Customer Customer { get; set; }
public String Name { get; set; }
public String OrganisationName
{
get
{
if (CostBearer2SupportConcept != null && CostBearer2SupportConcept.CostBearer != null)
{
return CostBearer2SupportConcept.CostBearer.Organisation.Name;
}
return null;
}
}
public String CustomerFullName
{
get
{
if (Customer != null)
return String.Format("{0}, {1}", Customer.Person.LastName, Customer.Person.FirstName);
return Name;
}
}
public CostBearer2SupportConcept CostBearer2SupportConcept { get; set; }
public SupportConceptApprovalPeriod SupportConceptApprovalPeriod { get; set; }
public String TimeRangeString
{
get
{
if (!StartDate.HasValue && !EndDate.HasValue)
return "";
return String.Format("{0:dd.MM.yyyy}-{1:dd.MM.yyyy}", StartDate, EndDate);
}
}
public decimal ApprovedHoursPerWeekTotal { get; set; }
public decimal ApprovedHoursPerWeek { get; set; }
public decimal ApprovedHoursPerWeekWithRateFactorTotal { get; set; }
public decimal ApprovedHoursPerWeekWithRateFactor { get; set; }
public decimal ApprovedHoursPerMonthTotal { get; set; }
public decimal ApprovedHoursPerMonth { get; set; }
public decimal ApprovedHoursPerMonthWithRateFactorTotal { get; set; }
public decimal ApprovedHoursPerMonthWithRateFactor { get; set; }
public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; }
public decimal DirectIst { get; set; }
public decimal MinutesSoll { get; set; }
public decimal MittelbarIst { get; set; }
public decimal FreiProWoche { get; set; }
public decimal FreiProMonat { get; set; }
public decimal RelationDirectToMittelbar { get; set; }
public decimal RelationIstSoll { get; set; }
public decimal WeekCountUntilNow { get; set; }
public decimal IstKw1 { get; set; }
public decimal IstKw2 { get; set; }
public decimal IstKw3 { get; set; }
public decimal IstKw4 { get; set; }
public decimal IstKw5 { get; set; }
public decimal IstKw6 { get; set; }
public String Custom1 { get; set; }
public String Custom2 { get; set; }
public String Custom3 { get; set; }
}
public class TeamDetail
{
private List<EmployeeDetail> employeeDetailList = new List<EmployeeDetail>();
private List<SupportConceptDetail> scDetailList = new List<SupportConceptDetail>();
public string TeamName { get; set; }
public Employee TeamLeader { get; set; }
public decimal ApprovedHoursPerWeekTotal { get; set; }
public decimal ApprovedHoursPerWeek { get; set; } // nur der Anteil an Betreuung
public decimal ApprovedHoursPerWeekWithRateFactorTotal { get; set; }
public decimal ApprovedHoursPerWeekWithRateFactor { get; set; } // nur der Anteil an Betreuung
public decimal ApprovedHoursPerMonthTotal { get; set; }
public decimal ApprovedHoursPerMonth { get; set; } // nur der Anteil an Betreuung
public decimal ApprovedHoursPerMonthWithRateFactorTotal { get; set; }
public decimal ApprovedHoursPerMonthWithRateFactor { get; set; } // nur der Anteil an Betreuung
public decimal DirectIst { get; set; }
public decimal MittelbarIst { get; set; }
public decimal RelationDirectToMittelbar { get; set; }
public decimal RelationIstSoll { get; set; }
public List<EmployeeDetail> EmployeeDetailList
{
get { return employeeDetailList; }
set { employeeDetailList = value; }
}
public List<SupportConceptDetail> SupportConceptDetailList
{
get { return scDetailList; }
set { scDetailList = value; }
}
}
}
}