Files
BeWoPlaner/ReportImp/ahaEV/CustomVacationService.cs

92 lines
3.2 KiB
C#

using BeWo.Service.Plugins;
using BS.Shared.DataContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ahaEV
{
class CustomVacationService : VacationService
{
public override string Bundesland { get => "Hessen"; }
public override List<FeiertagDC> GetFeiertage(int year, string bundesland)
{
var list = base.GetFeiertage(year, bundesland);
list.Add(new FeiertagDC() { Datum = new DateTime(year, 12, 31), Name = "Silvester" });
return list;
}
public override decimal GetFeiertagsFaktor(DateTime start)
{
if (start.Month == 12 && start.Day == 24 || start.Month == 12 && start.Day == 31)
return 0.5m;
else if (IstFeiertag(start))
{
return 1;
}
return 0;
}
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 || (endDate.HasValue && endDate.Value.Day == 31 && endDate.Value.Month == 12))
urlaubstage = (decimal)urlaubstageProJahr;
else
urlaubstage = (decimal)urlaubstageProJahr / 365m * restlicheTageImJahr;
}
else
{
urlaubstage = (decimal)urlaubstageProJahr / 365m * restlicheTageImJahr;
}
// Runden
// Vor 2025 das hier
if (entryDate.Year <= 2024 || endDate.HasValue && endDate.Value.Year <= 2024)
urlaubstage = UrlaubstageRunden(urlaubstage);
// Ab 2025 das hier
else
urlaubstage = UrlaubstageRundenAberAndersAlsImStandard(urlaubstage);
return urlaubstage;
}
public override decimal UrlaubstageRunden(decimal urlaubstage)
{
urlaubstage = Math.Round(urlaubstage * 2, MidpointRounding.AwayFromZero) / 2;
return urlaubstage;
}
public decimal UrlaubstageRundenAberAndersAlsImStandard(decimal urlaubstage)
{
if (urlaubstage - (int)urlaubstage <= 0.1m)
{
urlaubstage = Math.Round(urlaubstage, MidpointRounding.AwayFromZero);
}
else if (urlaubstage - (int)urlaubstage <= 0.5m || urlaubstage - (int)urlaubstage <= 0.75m)
{
decimal digits = urlaubstage - (int)urlaubstage;
urlaubstage = urlaubstage - digits + 0.5m;
}
else if (urlaubstage - (int)urlaubstage <= 1.0m)
{
urlaubstage = Math.Ceiling(urlaubstage);
}
return urlaubstage;
}
}
}