Files
BeWoPlaner/ReportImp/RomanRogerPuth/Service/CustomVacationService.cs
2023-05-05 14:53:18 +02:00

65 lines
2.4 KiB
C#

using BeWo.Service.Plugins;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RomanRogerPuth.Service
{
public class CustomVacationService : VacationService
{
public override decimal CalcCorrectNumberOfLeaveDaysForSpecialContractSituation(DateTime entryDate, DateTime? endDate, int anzahlArbeitstage, int restlicheTageImJahr, decimal? urlaubstageProJahr)
{
decimal urlaubstage = 0;
if (urlaubstageProJahr == null)
urlaubstageProJahr = 0m;
if (entryDate.Day == 1 && entryDate.Month == 1 || entryDate.Day == 2 && entryDate.Month == 1) //Erster Tag im Jahr
{
//Prüfen, ob Enddatum Ende des Jahres oder früher ist
if (endDate == null)
urlaubstage = (decimal)urlaubstageProJahr;
else if (endDate.Value.Day == 31 && endDate.Value.Month == 12)
urlaubstage = (decimal)urlaubstageProJahr;
else
{
if (anzahlArbeitstage < 5) // weniger als 5 Tage
urlaubstage = (decimal)urlaubstageProJahr / 5m * anzahlArbeitstage;
else
{
if (anzahlArbeitstage == 5) // 5 Tage
urlaubstage = (decimal)urlaubstageProJahr / 365m * restlicheTageImJahr;
else if (anzahlArbeitstage == 6) // 6 Tage
urlaubstage = (decimal)urlaubstageProJahr / 365m * restlicheTageImJahr;
}
}
}
else // Mitten im Jahr
{
urlaubstage = (decimal)urlaubstageProJahr / 365m * restlicheTageImJahr;
}
// Runden
if (urlaubstage - (int)urlaubstage <= 0.1m)
{
urlaubstage = Math.Round(urlaubstage, MidpointRounding.AwayFromZero);
}
else if (urlaubstage - (int)urlaubstage <= 0.5m)
{
decimal digits = urlaubstage - (int)urlaubstage;
urlaubstage = urlaubstage - digits + 0.5m;
}
else if (urlaubstage - (int)urlaubstage <= 1.0m)
{
urlaubstage = Math.Ceiling(urlaubstage);
}
return urlaubstage;
}
}
}