397 lines
12 KiB
C#
397 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using BeWo.Data.Entities;
|
|
using BS.Shared;
|
|
using BS.Shared.Extensions;
|
|
|
|
namespace BeWo.Report.ReportObjects
|
|
{
|
|
public class FlsAuslastungsauswertungRO : AbstractBeWoReportObject<FlsAuslastungsauswertungRO>
|
|
{
|
|
public FLSAuswertungstyp FlsAuswertungstyp { get; }
|
|
|
|
public string Auswertungszeitraum => $"{StartDate:dd.MM.yyyy} - {EndDate:dd.MM.yyyy}";
|
|
|
|
public Employee Employee { get; set; }
|
|
|
|
public string EmployeeName
|
|
{
|
|
get
|
|
{
|
|
var name = Employee?.Person?.LastNameFirstName ?? string.Empty;
|
|
|
|
var weeklyFls = Employee?.LastContract?.WeeklyFLS == null ? string.Empty : $"({Employee.LastContract.WeeklyFLS.Value})";
|
|
|
|
return $"{name} {weeklyFls}";
|
|
}
|
|
}
|
|
|
|
public Team Team { get; set; }
|
|
|
|
public string TeamName => Team?.Name ?? string.Empty;
|
|
|
|
public string TargetObjectDescription { get; }
|
|
|
|
public string TargetObjectName { get; set; }
|
|
|
|
public List<Customer2Values> Customer2Values { get; set; } = new List<Customer2Values>();
|
|
|
|
public DateTime StartDate { get; set; }
|
|
|
|
public DateTime EndDate { get; set; }
|
|
|
|
public FlsAuslastungsauswertungRO(DateTime startDate, DateTime endDate, FLSAuswertungstyp flsAuswertungstyp)
|
|
{
|
|
StartDate = startDate;
|
|
EndDate = endDate;
|
|
FlsAuswertungstyp = flsAuswertungstyp;
|
|
}
|
|
|
|
public FlsAuslastungsauswertungRO(Employee employee, DateTime startDate, DateTime endDate, FLSAuswertungstyp flsAuswertungstyp)
|
|
{
|
|
Employee = employee;
|
|
TargetObjectDescription = "Mitarbeiter";
|
|
StartDate = startDate;
|
|
EndDate = endDate;
|
|
FlsAuswertungstyp = flsAuswertungstyp;
|
|
}
|
|
|
|
public FlsAuslastungsauswertungRO(Team team, DateTime startDate, DateTime endDate, FLSAuswertungstyp flsAuswertungstyp)
|
|
{
|
|
Team = team;
|
|
TargetObjectDescription = "Team";
|
|
StartDate = startDate;
|
|
EndDate = endDate;
|
|
FlsAuswertungstyp = flsAuswertungstyp;
|
|
}
|
|
|
|
public void UpdateTargetObjectName()
|
|
{
|
|
if(Employee != null)
|
|
{
|
|
TargetObjectName = $"{Employee.Person.LastNameFirstName}({GetVertraglicheArbeitszeit():0.00}) Mehr/Minderarbeit: {GetMehrMinderauslastung():0.00}";
|
|
}
|
|
else if(Team != null)
|
|
{
|
|
TargetObjectName = $"{Team.Name} Mehr/Minderarbeit: {GetMehrMinderauslastung():0.00}";
|
|
}
|
|
}
|
|
|
|
public Customer2Values GetCustomer2ValuesByCustomer(Customer customer)
|
|
{
|
|
return Customer2Values?.FirstOrDefault(customer2Values => customer2Values.Customer?.Equals(customer) ?? false);
|
|
}
|
|
|
|
public int GetMonthCount()
|
|
{
|
|
return StartDate.GetMonthCount(EndDate);
|
|
}
|
|
|
|
public int GetWeekCount()
|
|
{
|
|
return StartDate.GetWeekOfYearCount(EndDate);
|
|
}
|
|
|
|
public int GetStartWeekOfYear()
|
|
{
|
|
return StartDate.GetIso8601WeekOfYear();
|
|
}
|
|
|
|
public decimal GetMehrMinderauslastung()
|
|
{
|
|
decimal mehrMinderauslastung = 0;
|
|
|
|
foreach(var customer2Value in Customer2Values)
|
|
{
|
|
mehrMinderauslastung += customer2Value.SollSum + customer2Value.IstSum;
|
|
}
|
|
|
|
return mehrMinderauslastung;
|
|
}
|
|
|
|
public decimal GetVertraglicheArbeitszeit()
|
|
{
|
|
if(Employee != null)
|
|
{
|
|
var lastContract = Employee.LastContract;
|
|
|
|
if(lastContract?.WeeklyFLS != null)
|
|
{
|
|
return lastContract.WeeklyFLS.Value;
|
|
}
|
|
}
|
|
|
|
return 0M;
|
|
}
|
|
|
|
public Customer2Values this[long index]
|
|
{
|
|
get
|
|
{
|
|
if(Customer2Values == null)
|
|
{
|
|
Customer2Values = new List<Customer2Values>();
|
|
}
|
|
|
|
return Customer2Values.FirstOrDefault(f => { return f.Customer?.Oid == index; });
|
|
}
|
|
}
|
|
|
|
|
|
public decimal DiffSum
|
|
{
|
|
get
|
|
{
|
|
return Customer2Values.Sum(c2V => { return c2V.DiffSum; });
|
|
}
|
|
}
|
|
|
|
public decimal SollSum
|
|
{
|
|
get
|
|
{
|
|
return Customer2Values.Sum(c2V => { return c2V.SollSum; });
|
|
}
|
|
}
|
|
|
|
public string DiffSumInPercent
|
|
{
|
|
get
|
|
{
|
|
var dsip = SollSum == 0 ? 0M : DiffSum / SollSum * 100;
|
|
|
|
return string.Format(new CultureInfo("de-DE"), "{0:0.00}%", dsip);
|
|
}
|
|
}
|
|
}
|
|
|
|
public class Customer2Values
|
|
{
|
|
private readonly FLSAuswertungstyp _FlsAuswertungstyp;
|
|
|
|
public readonly Guid Id;
|
|
|
|
public string CustomerName => Customer?.Person?.LastNameFirstName;
|
|
public Customer Customer { get; set; }
|
|
|
|
public FlsValueObject Day1 { get; set; }
|
|
public FlsValueObject Day2 { get; set; }
|
|
public FlsValueObject Day3 { get; set; }
|
|
public FlsValueObject Day4 { get; set; }
|
|
public FlsValueObject Day5 { get; set; }
|
|
public FlsValueObject Day6 { get; set; }
|
|
public FlsValueObject Day7 { get; set; }
|
|
public FlsValueObject Day8 { get; set; }
|
|
public FlsValueObject Day9 { get; set; }
|
|
public FlsValueObject Day10 { get; set; }
|
|
public FlsValueObject Day11 { get; set; }
|
|
public FlsValueObject Day12 { get; set; }
|
|
public FlsValueObject Day13 { get; set; }
|
|
public FlsValueObject Day14 { get; set; }
|
|
public FlsValueObject Day15 { get; set; }
|
|
public FlsValueObject Day16 { get; set; }
|
|
public FlsValueObject Day17 { get; set; }
|
|
public FlsValueObject Day18 { get; set; }
|
|
public FlsValueObject Day19 { get; set; }
|
|
public FlsValueObject Day20 { get; set; }
|
|
public FlsValueObject Day21 { get; set; }
|
|
public FlsValueObject Day22 { get; set; }
|
|
public FlsValueObject Day23 { get; set; }
|
|
public FlsValueObject Day24 { get; set; }
|
|
public FlsValueObject Day25 { get; set; }
|
|
public FlsValueObject Day26 { get; set; }
|
|
public FlsValueObject Day27 { get; set; }
|
|
public FlsValueObject Day28 { get; set; }
|
|
public FlsValueObject Day29 { get; set; }
|
|
public FlsValueObject Day30 { get; set; }
|
|
|
|
|
|
public FlsValueObject Week1 { get; set; }
|
|
public FlsValueObject Week2 { get; set; }
|
|
public FlsValueObject Week3 { get; set; }
|
|
public FlsValueObject Week4 { get; set; }
|
|
public FlsValueObject Week5 { get; set; }
|
|
public FlsValueObject Week6 { get; set; }
|
|
|
|
|
|
public FlsValueObject Month1 { get; set; }
|
|
public FlsValueObject Month2 { get; set; }
|
|
public FlsValueObject Month3 { get; set; }
|
|
|
|
|
|
public DateTime StartDate { get; set; }
|
|
public DateTime EndDate { get; set; }
|
|
|
|
|
|
public Customer2Values(Customer customer, FLSAuswertungstyp flsAuswertungstyp, DateTime startDate, DateTime endDate)
|
|
{
|
|
Customer = customer;
|
|
_FlsAuswertungstyp = flsAuswertungstyp;
|
|
StartDate = startDate;
|
|
EndDate = endDate;
|
|
|
|
Id = Guid.NewGuid();
|
|
}
|
|
|
|
public Customer2Values()
|
|
{
|
|
Id = Guid.NewGuid();
|
|
}
|
|
|
|
public void CalcDifferences()
|
|
{
|
|
int count;
|
|
string prefix;
|
|
var sollSum = 0M;
|
|
var istSum = 0M;
|
|
|
|
switch(_FlsAuswertungstyp)
|
|
{
|
|
case FLSAuswertungstyp.Daily:
|
|
count = 30;
|
|
prefix = "Day";
|
|
break;
|
|
case FLSAuswertungstyp.Weekly:
|
|
count = GetWeekCount();
|
|
prefix = "Week";
|
|
break;
|
|
case FLSAuswertungstyp.Monthly:
|
|
count = GetMonthCount();
|
|
prefix = "Month";
|
|
break;
|
|
default:
|
|
count = 30;
|
|
prefix = "Day";
|
|
break;
|
|
}
|
|
|
|
for(var i = 1; i <= count; i++)
|
|
{
|
|
var propertyName = $"{prefix}{i}";
|
|
var propertyInfo = GetType().GetProperty(propertyName);
|
|
|
|
if(propertyInfo != null)
|
|
{
|
|
var propertyValue = (FlsValueObject)propertyInfo.GetValue(this, null);
|
|
|
|
if(propertyValue != null)
|
|
{
|
|
sollSum += propertyValue.Soll;
|
|
istSum += propertyValue.Ist;
|
|
}
|
|
}
|
|
}
|
|
|
|
var diffSum = sollSum - istSum;
|
|
|
|
SollSum = sollSum;
|
|
IstSum = istSum;
|
|
DiffSum = diffSum;
|
|
|
|
DifferenzGanzerAbrechnungszeitraum = diffSum;
|
|
AuslastungNachEnddatumKunde = sollSum > 0 ? diffSum / sollSum * 100 : 0M;
|
|
DiffSumInPercent = AuslastungNachEnddatumKunde;
|
|
}
|
|
|
|
public decimal SollSum { get; set; }
|
|
public decimal IstSum { get; set; }
|
|
public decimal DiffSum { get; set; }
|
|
public decimal DiffSumInPercent { get; set; }
|
|
|
|
|
|
public decimal DifferenzGanzerAbrechnungszeitraum { get; set; }
|
|
|
|
public decimal AuslastungNachEnddatumKunde { get; set; }
|
|
|
|
public decimal RestlicheFlsProWoche { get; set; }
|
|
|
|
public void AddOrUpdateDay(string propertyName, decimal soll, decimal ist, string timeUnitString)
|
|
{
|
|
try
|
|
{
|
|
var propertyValue = (FlsValueObject) this.GetPropertyValue(propertyName);
|
|
|
|
if(propertyValue == null)
|
|
{
|
|
propertyValue = new FlsValueObject(soll, ist, timeUnitString);
|
|
this.SetPropertyValue(propertyName, propertyValue);
|
|
}
|
|
else
|
|
{
|
|
propertyValue.Soll += soll;
|
|
propertyValue.Ist += ist;
|
|
}
|
|
}
|
|
catch(Exception exception)
|
|
{
|
|
Debug.WriteLine(exception);
|
|
}
|
|
}
|
|
|
|
public FlsValueObject GetFlsValueObject(string prefix, int suffix)
|
|
{
|
|
try
|
|
{
|
|
var propertyInfo = GetType().GetProperty($"{prefix}{suffix}");
|
|
|
|
if(propertyInfo != null)
|
|
{
|
|
return (FlsValueObject) propertyInfo.GetValue(this, null);
|
|
}
|
|
}
|
|
catch(Exception exception)
|
|
{
|
|
Debug.WriteLine(exception);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public int GetMonthCount()
|
|
{
|
|
return StartDate.GetMonthCount(EndDate);
|
|
}
|
|
|
|
public int GetWeekCount()
|
|
{
|
|
return StartDate.GetWeekOfYearCount(EndDate);
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
if(obj is Customer2Values customer2Values)
|
|
{
|
|
return Equals(Customer, customer2Values.Customer);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return Id.GetHashCode();
|
|
}
|
|
}
|
|
|
|
public class FlsValueObject
|
|
{
|
|
public decimal Soll { get; set; }
|
|
|
|
public decimal Ist { get; set; }
|
|
|
|
public decimal DiffSollIst => Soll - Ist;
|
|
|
|
public string TimeUnit { get; set; }
|
|
|
|
public FlsValueObject(decimal soll, decimal ist, string timeUnit)
|
|
{
|
|
Soll = soll;
|
|
Ist = ist;
|
|
TimeUnit = timeUnit;
|
|
}
|
|
}
|
|
}
|