458 lines
16 KiB
C#
458 lines
16 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BS.Shared.Core;
|
|
using DevExpress.XtraReports.UI;
|
|
using BeWo.Report.ReportObjects;
|
|
using BeWo.Report;
|
|
using BeWo.Service.DCEntityMapper;
|
|
using BeWo.Service.Plugins;
|
|
using DevExpress.Charts.Native;
|
|
using BeWo.Service.Dienstplanung;
|
|
|
|
namespace BeWo.SeWo
|
|
{
|
|
public partial class Zeitzuschlagsbeleg : DevExpress.XtraReports.UI.XtraReport
|
|
{
|
|
private VacationService _vs = null;
|
|
|
|
private Dictionary<int, double> samstag2Minuten = new Dictionary<int, double>();
|
|
private Dictionary<int, double> sonntag2Minuten = new Dictionary<int, double>();
|
|
private Dictionary<int, double> feiertag2Minuten = new Dictionary<int, double>();
|
|
private Dictionary<int, double> nachtSchlaf2Minuten = new Dictionary<int, double>();
|
|
private Dictionary<int, double> nachtWache2Minuten = new Dictionary<int, double>();
|
|
private Dictionary<int, double> heiligSil2Minuten = new Dictionary<int, double>();
|
|
|
|
|
|
public Zeitzuschlagsbeleg()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public void SetReportDataSource(DateTime monat, MitarbeiterstundenkontoRO.EmployeeDetail ed)
|
|
{
|
|
ed.FirstName = "";
|
|
|
|
if (ed.Custom9 > 0 || ed.Custom8 > 0)
|
|
{
|
|
ed.FirstName = String.Format("{0:0.##} / {1:0.##}", ed.Custom9, ed.Custom8);
|
|
}
|
|
|
|
_vs = PluginLoader.FindClass<VacationService>();
|
|
InitTable(monat);
|
|
FillTableData(monat, ed);
|
|
|
|
lblZeitraum.Text = String.Format("{0:MMMM yyyy}", monat);
|
|
|
|
this.bindingSource1.DataSource = ed;
|
|
}
|
|
|
|
private void FillTableData(DateTime monat, MitarbeiterstundenkontoRO.EmployeeDetail ed)
|
|
{
|
|
decimal kmTotal = 0;
|
|
decimal rufTotal = 0;
|
|
decimal notdienstTotal = 0;
|
|
decimal hdPause = 0;
|
|
|
|
if (ed.ServiceRecordsInSelectedTimeSpan != null)
|
|
{
|
|
if (ed.ServiceRecordsInSelectedTimeSpan.Count == 0 && ed.StundenGesamtIst > 0 && ed.Employee.Contracts != null) // Bug wenn Vertrag im Monat endet
|
|
{
|
|
var lastDay = monat.AddMonths(1).AddTicks(-1);
|
|
var lastContract = ed.Employee.Contracts.Where(c => c.ContractEndDate.HasValue && c.ContractEndDate.Value.Year == monat.Year && c.ContractEndDate.Value.Month == monat.Month).FirstOrDefault();
|
|
if (lastContract != null && lastContract.ContractEndDate.HasValue && lastContract.ContractEndDate.Value.Year == lastDay.Year)
|
|
{
|
|
var lastDayContract = lastContract.ContractEndDate.Value.AddDays(1).AddTicks(-1);
|
|
lastDay = lastDayContract;
|
|
var records = ed.AllServiceRecords.Where(s => s.End >= monat && s.Start <= lastDay).ToList();
|
|
if (records != null && records.Count > 0)
|
|
{
|
|
ed.ServiceRecordsInSelectedTimeSpan = records;
|
|
}
|
|
}
|
|
}
|
|
if (ed.ServiceRecordsInSelectedTimeSpan != null)
|
|
{
|
|
foreach (var sr in ed.ServiceRecordsInSelectedTimeSpan)
|
|
{
|
|
if (sr.DistanceInMeter > 0)
|
|
{
|
|
kmTotal += sr.DistanceInMeter;
|
|
}
|
|
|
|
if (sr.ServiceDescription.Category.Name == "SeWo Ruf")
|
|
{
|
|
rufTotal += GetDuration(sr);
|
|
}
|
|
else if (sr.ServiceDescription.Category.Name == "SeWo Notdienst")
|
|
{
|
|
notdienstTotal += GetDuration(sr);
|
|
}
|
|
else if (sr.ServiceDescription.Name != null && sr.ServiceDescription.Name == "HD Pause")
|
|
{
|
|
hdPause += GetDuration(sr);
|
|
}
|
|
else
|
|
{
|
|
AddValueToTable(sr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
BerechneGesamtsummen();
|
|
lblGesamtKm.Text = String.Format("{0:0.00} km", kmTotal);
|
|
lblRufGesamt.Text = String.Format("{0:0.00} Std.", rufTotal / 60);
|
|
lblNotGesamt.Text = String.Format("{0:0.00} Std.", notdienstTotal / 60);
|
|
lblhdPauseGesamt.Text = String.Format("{0:0.00} Std.", hdPause / 60);
|
|
}
|
|
|
|
private void BerechneGesamtsummen()
|
|
{
|
|
BerechneGesamtsumme(table1.Rows[1], samstag2Minuten);
|
|
BerechneGesamtsumme(table1.Rows[4], sonntag2Minuten);
|
|
BerechneGesamtsumme(table1.Rows[7], nachtSchlaf2Minuten);
|
|
BerechneGesamtsumme(table1.Rows[9], feiertag2Minuten);
|
|
BerechneGesamtsumme(table1.Rows[11], nachtWache2Minuten);
|
|
BerechneGesamtsumme(table1.Rows[13], heiligSil2Minuten);
|
|
}
|
|
|
|
private void BerechneGesamtsumme(XRTableRow row, Dictionary<int, double> dict)
|
|
{
|
|
double gesamt = 0;
|
|
for (int i = 1; i <= 31; i++)
|
|
{
|
|
if (dict.ContainsKey(i))
|
|
{
|
|
gesamt += dict[i];
|
|
}
|
|
}
|
|
row.Cells[33].Text = String.Format("{0:0.00}", gesamt / 60);
|
|
}
|
|
|
|
|
|
private void InitTable(DateTime monat)
|
|
{
|
|
int rowIdx = 0;
|
|
|
|
foreach (XRTableRow row in table1.Rows)
|
|
{
|
|
if (rowIdx > 0)
|
|
{
|
|
bool isHeaderRow = false;
|
|
|
|
int maxDays = DateTime.DaysInMonth(monat.Year, monat.Month);
|
|
if (rowIdx == 1 || rowIdx == 4 || rowIdx == 7 || rowIdx == 9 || rowIdx == 11 || rowIdx == 13)
|
|
{
|
|
isHeaderRow = true;
|
|
}
|
|
|
|
int cellIdx = 0;
|
|
foreach (XRTableCell cell in row.Cells)
|
|
{
|
|
|
|
if (cellIdx > 1)
|
|
{
|
|
cell.Text = "";
|
|
if (cellIdx <= 32)
|
|
{
|
|
cell.Font = new DevExpress.Drawing.DXFont(cell.Font.Name, 8, DevExpress.Drawing.DXFontStyle.Regular);
|
|
}
|
|
|
|
bool setBackground = maxDays < 31 && cellIdx > maxDays + 1 && cellIdx <= 32;
|
|
|
|
if (setBackground)
|
|
{
|
|
cell.BackColor = Color.LightGray;
|
|
}
|
|
}
|
|
|
|
cellIdx++;
|
|
}
|
|
|
|
}
|
|
|
|
rowIdx++;
|
|
}
|
|
}
|
|
|
|
private void AddValueToTable(StundenkontoServiceRecord sr)
|
|
{
|
|
DateTime datum = sr.Start;
|
|
|
|
if (datum.Second == 0)
|
|
{
|
|
var zs = BerechneZuschlag(sr);
|
|
|
|
|
|
if (zs.MinutenFeiertag6_22 > 0)
|
|
{
|
|
AddValueToCell(zs.MinutenFeiertag6_22, datum, table1.Rows[9], feiertag2Minuten);
|
|
}
|
|
if (zs.MinutenNachtSchlaf22_6 > 0)
|
|
{
|
|
AddValueToCell(zs.MinutenNachtSchlaf22_6, datum, table1.Rows[7], nachtSchlaf2Minuten);
|
|
}
|
|
if (zs.MinutenNachtwache22_6 > 0)
|
|
{
|
|
AddValueToCell(zs.MinutenNachtwache22_6, datum, table1.Rows[11], nachtWache2Minuten);
|
|
}
|
|
if (zs.MinutenSamstag13_22 > 0)
|
|
{
|
|
AddValueToCell(zs.MinutenSamstag13_22, datum, table1.Rows[1], samstag2Minuten);
|
|
}
|
|
if (zs.MinutenSonntag6_22 > 0)
|
|
{
|
|
AddValueToCell(zs.MinutenSonntag6_22, datum, table1.Rows[4], sonntag2Minuten);
|
|
}
|
|
if (zs.MinutenHeiligabendSilvester18_22 > 0)
|
|
{
|
|
AddValueToCell(zs.MinutenHeiligabendSilvester18_22, datum, table1.Rows[13], heiligSil2Minuten);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void AddValueToCell(double minuten, DateTime datum, XRTableRow row, Dictionary<int, double> dict)
|
|
{
|
|
XRTableCell cell = row.Cells[datum.Day + 1];
|
|
|
|
if (!dict.ContainsKey(datum.Day))
|
|
{
|
|
dict[datum.Day] = 0;
|
|
}
|
|
|
|
dict[datum.Day] += minuten;
|
|
|
|
cell.Text = String.Format("{0:0.00}", dict[datum.Day] / 60);
|
|
|
|
}
|
|
|
|
private decimal GetDuration(StundenkontoServiceRecord sr)
|
|
{
|
|
decimal duration = 0;
|
|
|
|
if (sr.ServiceDescription.Name != "Pause" && !sr.ServiceDescription.Category.Name.Contains("Rufbereitschaft"))
|
|
{
|
|
if (sr.ServiceDescription.Category.Name == "Verwaltung" || sr.ServiceDescription.Category.Name == "Organisation")
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
if (sr.ServiceDescription.Category.Name.Contains("Overhead"))
|
|
{
|
|
if (sr.ServiceDescription.Name != "Übergabe" && sr.ServiceDescription.Name != "Fahrtzeit")
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
if (sr.GroupRoundedDuration.HasValue)
|
|
{
|
|
duration = sr.GroupRoundedDuration.Value;
|
|
}
|
|
else
|
|
{
|
|
duration = sr.RoundedDuration;
|
|
}
|
|
|
|
if (IsKrankheitAbsenceServiceRecord(sr) || IsUrlaubAbsenceServiceRecord(sr))
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
|
|
if (sr.ServiceDescription != null && sr.ServiceDescription.Category != null)
|
|
{
|
|
var p = sr.ServiceDescription.Category.ProzentStundenkonto ?? sr.ServiceDescription.Category.Percentage;
|
|
if (sr.ServiceDescription.ProzentStundenkonto.HasValue)
|
|
{
|
|
p = sr.ServiceDescription.ProzentStundenkonto.Value;
|
|
}
|
|
|
|
if (p != 100 && p > 0)
|
|
{
|
|
duration *= (p / 100);
|
|
}
|
|
}
|
|
|
|
|
|
//if (sr.ServiceDescription.ServiceCategory.Name == "SeWo Ruf" || sr.ServiceDescription.ServiceCategory.Name == "SeWo Notdienst")
|
|
//{
|
|
// var p = sr.ServiceDescription.ServiceCategory.Percentage;
|
|
// if (p != 100 && p > 0)
|
|
// {
|
|
// duration *= (p / 100);
|
|
|
|
// }
|
|
//}
|
|
//else
|
|
//{
|
|
// var p = sr.ServiceDescription.ServiceCategory.Percentage;
|
|
// if (p != 100 && p > 0)
|
|
// {
|
|
// duration *= (p / 100);
|
|
|
|
// }
|
|
//}
|
|
//var p = sr.ServiceDescription.ServiceCategory.Percentage;
|
|
//if (p != 100 && p > 0)
|
|
//{
|
|
// //duration *= (p / 100);
|
|
|
|
//}
|
|
|
|
}
|
|
else
|
|
{
|
|
int test = 0;
|
|
}
|
|
|
|
return duration;
|
|
}
|
|
|
|
private bool IsKrankheitAbsenceServiceRecord(StundenkontoServiceRecord item)
|
|
{
|
|
if (item.ServiceDescription.Name.ToLower().Contains("krankheit"))
|
|
{
|
|
return true;
|
|
}
|
|
if (item.ServiceDescription.Name.ToLower().Contains("corona"))
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private bool IsUrlaubAbsenceServiceRecord(StundenkontoServiceRecord item)
|
|
{
|
|
if (item.ServiceDescription.Name.ToLower().Contains("urlaub"))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
public virtual Zeitverteilung2 BerechneZuschlag(StundenkontoServiceRecord sr)
|
|
{
|
|
Zeitverteilung2 zv = new Zeitverteilung2();
|
|
|
|
DateTime datum = sr.Start;
|
|
|
|
var duration = GetDuration(sr);
|
|
int nachtStart = 22;
|
|
|
|
if (duration > 0)
|
|
{
|
|
if (datum.Month == 12 && (datum.Day == 24 || datum.Day == 31))
|
|
{
|
|
zv.MinutenHeiligabendSilvester18_22 = CheckUhrzeiten(datum, 18, 22, (double) duration);
|
|
|
|
if (sr.Start.DayOfWeek == DayOfWeek.Saturday)
|
|
{
|
|
zv.MinutenSamstag13_22 = CheckUhrzeiten(datum, 13, 18, (double) duration);
|
|
}
|
|
else if (sr.Start.DayOfWeek == DayOfWeek.Sunday)
|
|
{
|
|
zv.MinutenSonntag6_22 = CheckUhrzeiten(datum, 6, 18, (double) duration);
|
|
}
|
|
|
|
nachtStart = 23;
|
|
}
|
|
else if (_vs.IstFeiertag(datum))
|
|
{
|
|
zv.MinutenFeiertag6_22 = CheckUhrzeiten(datum, 6, 22, (double) duration);
|
|
}
|
|
else if (sr.Start.DayOfWeek == DayOfWeek.Sunday)
|
|
{
|
|
zv.MinutenSonntag6_22 = CheckUhrzeiten(datum, 6, 22, (double) duration);
|
|
}
|
|
else if (sr.Start.DayOfWeek == DayOfWeek.Saturday)
|
|
{
|
|
zv.MinutenSamstag13_22 = CheckUhrzeiten(datum, 13, 22, (double) duration);
|
|
}
|
|
if (sr.ServiceDescription.Category.Name == "Schlafbereitschaft")
|
|
{
|
|
zv.MinutenNachtSchlaf22_6 = CheckUhrzeiten(datum, nachtStart, 6, (double)duration);
|
|
}
|
|
else if (sr.ServiceDescription.Category.Name == "Nachtwache")
|
|
{
|
|
zv.MinutenNachtwache22_6 = CheckUhrzeiten(datum, nachtStart, 6, (double)duration);
|
|
}
|
|
|
|
}
|
|
|
|
return zv;
|
|
}
|
|
|
|
private double CheckUhrzeiten(DateTime start, int startStunde, int endStunde, double minuten)
|
|
{
|
|
if (startStunde > endStunde) //Nachts
|
|
{
|
|
DateTime nachtStartDt = start.Date.AddHours(startStunde);
|
|
DateTime nachtEndDt = start.Date.AddDays(1).AddHours(endStunde);
|
|
|
|
|
|
DateTime dtEnd = start.AddMinutes(minuten);
|
|
|
|
double minutes = GetOverlappingMinutes(start, dtEnd, nachtStartDt, nachtEndDt);
|
|
minutes += GetOverlappingMinutes(start, dtEnd, nachtStartDt.AddDays(-1), nachtEndDt.AddDays(-1));
|
|
minutes += GetOverlappingMinutes(start, dtEnd, nachtStartDt.AddDays(1), nachtEndDt.AddDays(1));
|
|
|
|
return minutes;
|
|
}
|
|
else
|
|
{
|
|
DateTime tagsStartDt = start.Date.AddHours(startStunde);
|
|
DateTime tagsEndDt = start.Date.AddHours(endStunde);
|
|
|
|
|
|
DateTime dtEnd = start.AddMinutes(minuten);
|
|
|
|
double minutes = GetOverlappingMinutes(start, dtEnd, tagsStartDt, tagsEndDt);
|
|
|
|
return minutes;
|
|
}
|
|
}
|
|
|
|
private double GetOverlappingMinutes(DateTime start, DateTime end, DateTime start2, DateTime end2)
|
|
{
|
|
if (end > start2 && start < end2)
|
|
{
|
|
DateTime dtStart = start;
|
|
|
|
if (dtStart < start2)
|
|
dtStart = start2;
|
|
|
|
DateTime dtEnd = end;
|
|
|
|
if (dtEnd > end2)
|
|
dtEnd = end2;
|
|
TimeSpan ts = dtEnd.Subtract(dtStart);
|
|
|
|
return ts.TotalMinutes;
|
|
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
|
|
public class Zeitverteilung2
|
|
{
|
|
public double MinutenSamstag13_22 { get; set; }
|
|
public double MinutenSonntag6_22 { get; set; }
|
|
public double MinutenNachtSchlaf22_6 { get; set; }
|
|
public double MinutenNachtwache22_6 { get; set; }
|
|
public double MinutenFeiertag6_22 { get; set; }
|
|
public double MinutenHeiligabendSilvester18_22 { get; set; }
|
|
|
|
}
|
|
}
|