252 lines
9.1 KiB
C#
252 lines
9.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Service.DCEntityMapper;
|
|
using BS.Shared;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Extensions;
|
|
|
|
namespace BeWo.Report.ReportObjects
|
|
{
|
|
public class FLSSollIstReportRO
|
|
{
|
|
public DateTime? ReportEndDate { get; set; }
|
|
public FLSAnalysisConfigDC ReportConfig { get; set; }
|
|
public DateTime? ReportStartDate { get; set; }
|
|
|
|
public List<FLSSollIstRootRO> RootObjectList { get; set; } = new List<FLSSollIstRootRO>();
|
|
|
|
|
|
|
|
public class FLSSollIstRootRO
|
|
{
|
|
public string Name { get; set; }
|
|
|
|
public long ObjectOid { get; set; }
|
|
|
|
public TableID ObjectTid { get; set; }
|
|
|
|
public List<FLSSollIstReportGroupRO> Groups { get; set; } = new List<FLSSollIstReportGroupRO>();
|
|
public decimal SollGesamt { get; set; }
|
|
public decimal IstGesamt { get; set; }
|
|
public decimal DifferenzSollIstGesamt { get; set; }
|
|
|
|
public String CustomValue1 { get; set; }
|
|
|
|
public String CustomValue2 { get; set; }
|
|
|
|
public String CustomValue3 { get; set; }
|
|
|
|
public String CustomValue4 { get; set; }
|
|
|
|
public String CustomValue5 { get; set; }
|
|
public List<ServiceRecordFLSOverviewDC> ServiceRecords { get; internal set; } = new List<ServiceRecordFLSOverviewDC>();
|
|
}
|
|
|
|
public class FLSSollIstReportGroupRO
|
|
{
|
|
public string Name { get; set; }
|
|
|
|
public long ObjectOid { get; set; }
|
|
|
|
public TableID ObjectTid { get; set; }
|
|
|
|
public List<SupportConceptCostBearerRelDC> CostBearer2SupportConceptList { get; set; } = new List<SupportConceptCostBearerRelDC>();
|
|
|
|
public List<FLSSollIstWochenSummen> WochenSummen { get; set; } = new List<FLSSollIstWochenSummen>();
|
|
|
|
public decimal SollGesamt { get; set; }
|
|
|
|
public decimal IstGesamt { get; set; }
|
|
public decimal DifferenzSollIstGesamt { get; set; }
|
|
public String CustomValue1 { get; set; }
|
|
|
|
public String CustomValue2 { get; set; }
|
|
|
|
public String CustomValue3 { get; set; }
|
|
|
|
public String CustomValue4 { get; set; }
|
|
|
|
public String CustomValue5 { get; set; }
|
|
public List<ServiceRecordFLSOverviewDC> ServiceRecords { get; internal set; } = new List<ServiceRecordFLSOverviewDC>();
|
|
}
|
|
|
|
public class FLSSollIstWochenSummen
|
|
{
|
|
public long ObjectOid { get; set; } // Entweder Employee oder CustomerOid, je nachdem wer ausgewertet wird
|
|
public decimal? SollStunden { get; set; }
|
|
|
|
public decimal? IstStunden { get; set; }
|
|
|
|
public decimal? Differenz
|
|
{
|
|
get
|
|
{
|
|
if (IstStunden.HasValue && SollStunden.HasValue)
|
|
{
|
|
return IstStunden - SollStunden;
|
|
}
|
|
if (SollStunden.HasValue)
|
|
{
|
|
return SollStunden * -1;
|
|
}
|
|
return IstStunden;
|
|
}
|
|
}
|
|
|
|
public DateTime WocheStart { get; set; }
|
|
|
|
public DateTime WocheEnde { get; set; }
|
|
|
|
public int KalenderWoche
|
|
{
|
|
get
|
|
{
|
|
var ci = System.Globalization.CultureInfo.InvariantCulture;
|
|
|
|
return ci.Calendar.GetWeekOfYear(
|
|
WocheStart,
|
|
System.Globalization.CalendarWeekRule.FirstFourDayWeek,
|
|
DayOfWeek.Monday);
|
|
}
|
|
}
|
|
|
|
public List<ServiceRecordFLSOverviewDC> ServiceRecords { get; internal set; } = new List<ServiceRecordFLSOverviewDC>();
|
|
}
|
|
|
|
public static FLSSollIstReportRO Create(List<FLSAnalysisRootDC> dcList, FLSAnalysisConfigDC config)
|
|
{
|
|
var ro = new FLSSollIstReportRO();
|
|
ro.ReportConfig = config;
|
|
ro.ReportStartDate = config.StartDate;
|
|
ro.ReportEndDate = config.EndDate;
|
|
|
|
foreach (var root in dcList.OrderBy(a => a.DisplayName))
|
|
{
|
|
var rootRo = new FLSSollIstRootRO();
|
|
rootRo.Name = root.DisplayName;
|
|
rootRo.SollGesamt = 0; //root.SollFLSTotal ?;
|
|
if (root.Employee != null)
|
|
{
|
|
rootRo.ObjectOid = root.Employee.EmployeeOid;
|
|
rootRo.ObjectTid = TableID.Employee;
|
|
}
|
|
else if (root.Customer != null)
|
|
{
|
|
rootRo.ObjectOid = root.Customer.CustomerOid;
|
|
rootRo.ObjectTid = TableID.Customer;
|
|
}
|
|
foreach (var item in root.Groups.OrderBy(a => a.DisplayName))
|
|
{
|
|
var grpRo = new FLSSollIstReportGroupRO();
|
|
grpRo.Name = item.DisplayName;
|
|
if (item.Employee != null)
|
|
{
|
|
grpRo.ObjectOid = item.Employee.EmployeeOid;
|
|
grpRo.ObjectTid = TableID.Employee;
|
|
}
|
|
else if (item.Customer != null)
|
|
{
|
|
grpRo.ObjectOid = item.Customer.CustomerOid;
|
|
grpRo.ObjectTid = TableID.Customer;
|
|
}
|
|
long wochenObjectOid = 0;
|
|
if (root.Employee != null)
|
|
{
|
|
wochenObjectOid = root.Employee.EmployeeOid;
|
|
}
|
|
else if (root.Customer != null)
|
|
{
|
|
wochenObjectOid = root.Customer.CustomerOid;
|
|
}
|
|
grpRo.WochenSummen = ErstelleWochensummen(config.StartDate, config.EndDate, null, wochenObjectOid);
|
|
|
|
foreach (var sc in item.SupportConcepts)
|
|
{
|
|
grpRo.CostBearer2SupportConceptList.Add(sc.SupportConcept2CostBearer);
|
|
|
|
foreach (var sr in sc.ServiceRecords)
|
|
{
|
|
rootRo.ServiceRecords.Add(sr);
|
|
grpRo.ServiceRecords.Add(sr);
|
|
|
|
var ws = grpRo.WochenSummen.FirstOrDefault(w => w.WocheStart <= sr.Start && sr.Start < w.WocheEnde.AddDays(1));
|
|
|
|
if (ws != null)
|
|
{
|
|
ws.ServiceRecords.Add(sr);
|
|
if (!ws.IstStunden.HasValue)
|
|
{
|
|
ws.IstStunden = 0;
|
|
}
|
|
ws.IstStunden += sr.RoundedDuration / 60;
|
|
|
|
if (!ws.SollStunden.HasValue)
|
|
{
|
|
ws.SollStunden = sr.SollFLSPerWeek;
|
|
}
|
|
}
|
|
|
|
grpRo.IstGesamt += sr.RoundedDuration;
|
|
}
|
|
}
|
|
|
|
foreach (var ws in grpRo.WochenSummen)
|
|
{
|
|
if (!ws.SollStunden.HasValue)
|
|
{
|
|
ws.SollStunden = root.SollFLSPerWeek;
|
|
}
|
|
}
|
|
grpRo.IstGesamt = grpRo.IstGesamt / 60;
|
|
rootRo.IstGesamt += grpRo.IstGesamt;
|
|
rootRo.SollGesamt = grpRo.WochenSummen.Sum(w => w.SollStunden) ?? 0;
|
|
rootRo.Groups.Add(grpRo);
|
|
}
|
|
|
|
rootRo.DifferenzSollIstGesamt = rootRo.IstGesamt - rootRo.SollGesamt;
|
|
|
|
if (rootRo.Groups.Count > 0)
|
|
{
|
|
ro.RootObjectList.Add(rootRo);
|
|
}
|
|
}
|
|
|
|
return ro;
|
|
}
|
|
|
|
private static List<FLSSollIstWochenSummen> ErstelleWochensummen(DateTime? startDate, DateTime? endDate, decimal? defaultSoll, long objectOid)
|
|
{
|
|
var liste = new List<FLSSollIstWochenSummen>();
|
|
if (startDate.HasValue && endDate.HasValue)
|
|
{
|
|
DateTime dt = startDate.Value;
|
|
|
|
while (dt <= endDate.Value)
|
|
{
|
|
int days = ((int)DayOfWeek.Sunday - (int)dt.DayOfWeek + 7) % 7;
|
|
var sonntag = dt.AddDays(days);
|
|
|
|
var ws = new FLSSollIstWochenSummen();
|
|
ws.ObjectOid = objectOid;
|
|
ws.WocheStart = dt;
|
|
|
|
//Ermittele den nächsten Sonntag
|
|
ws.WocheEnde = sonntag;
|
|
|
|
if (ws.WocheEnde > endDate)
|
|
{
|
|
ws.WocheEnde = endDate.Value;
|
|
}
|
|
ws.SollStunden = defaultSoll;
|
|
|
|
liste.Add(ws);
|
|
dt = sonntag.AddDays(1);
|
|
}
|
|
}
|
|
return liste;
|
|
}
|
|
}
|
|
} |