235 lines
8.8 KiB
C#
235 lines
8.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Report;
|
|
using BeWo.Report.ReportObjects;
|
|
using BeWo.Service.DCEntityMapper;
|
|
using BeWo.Service.Plugins;
|
|
using BS.Shared;
|
|
using BS.Shared.Extensions;
|
|
using BS.Shared.Services;
|
|
|
|
namespace WahlEv
|
|
{
|
|
public partial class Stundenzettel : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<ServicesOverviewRO>
|
|
{
|
|
public Stundenzettel()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public void SetReportDataSource(ServicesOverviewRO pRO)
|
|
{
|
|
CalculateFLSSollIst(pRO);
|
|
double geleistet = 0;
|
|
double stundenausgleich = 0;
|
|
|
|
if (pRO.Services != null)
|
|
{
|
|
List<ServicesOverviewRO.ServiceDetail> servicesBillable = new List<ServicesOverviewRO.ServiceDetail>();
|
|
|
|
foreach (ServicesOverviewRO.ServiceDetail s in pRO.Services)
|
|
{
|
|
if (s.IsBillable || s.ServiceCategory == "Stundenausgleich")
|
|
{
|
|
ServicesOverviewRO.CreateGoalList(s);
|
|
|
|
SetNotice(pRO, s);
|
|
|
|
ServicesOverviewRO.CreateGoalList(s);
|
|
servicesBillable.Add(s);
|
|
|
|
geleistet += s.Minutes;
|
|
}
|
|
|
|
if (s.ServiceCategory == "Stundenausgleich")
|
|
{
|
|
stundenausgleich += s.Minutes;
|
|
}
|
|
}
|
|
|
|
pRO.Services = servicesBillable;
|
|
}
|
|
|
|
decimal sollProMonat = Math.Round(pRO.ApprovedFLSPerWeek * 4.33m, 2, MidpointRounding.AwayFromZero);
|
|
|
|
lblStdWocheBewilligt.Text = String.Format("{0:0.00}", pRO.ApprovedFLSPerWeek);
|
|
lblStdMonatBewilligt.Text = String.Format("{0:0.00}", sollProMonat);
|
|
|
|
decimal geleisteteStunden = Math.Round((decimal)geleistet / 60, 2, MidpointRounding.AwayFromZero);
|
|
|
|
var vormonat = Math.Round((pRO.MinutenGeleistetBisVormonat - pRO.MinutenSollBisVormonat) / 60, 2, MidpointRounding.AwayFromZero);
|
|
|
|
|
|
if (vormonat >= 0)
|
|
{
|
|
lblZuvielVormonat.Text = String.Format("{0:0.00}", vormonat);
|
|
lblZuwenigVormonat.Text = String.Format("{0:0.00}", 0);
|
|
}
|
|
else
|
|
{
|
|
lblZuvielVormonat.Text = String.Format("{0:0.00}", 0);
|
|
lblZuwenigVormonat.Text = String.Format("{0:0.00}", vormonat * -1);
|
|
}
|
|
decimal nochzuleisten = vormonat + (geleisteteStunden - sollProMonat);
|
|
lblGeleistet.Text = String.Format("{0:0.00}", geleisteteStunden);
|
|
cellGeleistetGesamt.Text = String.Format("{0:0.00}", geleisteteStunden);
|
|
|
|
if (stundenausgleich > 0)
|
|
{
|
|
nochzuleisten -= Math.Round((decimal) stundenausgleich / 60, 2, MidpointRounding.AwayFromZero);
|
|
}
|
|
|
|
lblDiff.Text = String.Format("{0:0.00}", nochzuleisten);
|
|
|
|
this.bindingSource1.DataSource = pRO;
|
|
}
|
|
|
|
private void CalculateFLSSollIst(ServicesOverviewRO pRo)
|
|
{
|
|
if (pRo.SupportConceptCostBearer != null &&
|
|
pRo.SupportConceptCostBearer.CostBearer2SupportConceptOid != null)
|
|
{
|
|
|
|
var c2s = DAOFactory.GenericDAO.LoadByID<CostBearer2SupportConcept>(pRo.SupportConceptCostBearer
|
|
.CostBearer2SupportConceptOid.Value);
|
|
|
|
var sc = c2s.SupportConcept;
|
|
|
|
decimal sollGesamt = 0;
|
|
|
|
DateTime start = sc.StartDate ?? pRo.StartDate;
|
|
DateTime ende = pRo.StartDate
|
|
.AddTicks(-1); // Ein Tag vor aktuellem Monat, da ja das Soll der Vergangenheit berechnet werden soll
|
|
|
|
var calc = PluginLoader.FindClass<Calculations>(c2s.CostBearer.ID) ??
|
|
Calculations.GetInstance(c2s.CostBearer.ID);
|
|
var costRatePeriods =
|
|
MapperFactory.CostRatePeriodDC_CostRatePeriod.MapToNewDCs(c2s.CostBearer.CostRatePeriods);
|
|
|
|
|
|
|
|
// Erstelle Soll
|
|
while (start < ende)
|
|
{
|
|
DateTime monatsEnde = new DateTime(start.Year, start.Month, 1).AddMonths(1).AddDays(-1);
|
|
|
|
foreach (var ic2s in sc.CostBearer2SupportConceptList)
|
|
{
|
|
|
|
foreach (var scap in ic2s.ApprovalPeriodList)
|
|
{
|
|
if (scap.StartDate.HasValue && scap.StartDate <= monatsEnde && scap.EndDate.HasValue &&
|
|
scap.EndDate >= start)
|
|
{
|
|
var scapdc = MapperFactory.SupportConceptApprovalPeriodDC_SupportConceptApprovalPeriod
|
|
.MapToNewDC(scap);
|
|
|
|
decimal soll =
|
|
calc.GetApprovedHoursForPeriod(scapdc, costRatePeriods, start, monatsEnde) ??
|
|
0;
|
|
sollGesamt += Math.Round(soll, 2, MidpointRounding.AwayFromZero);
|
|
}
|
|
}
|
|
}
|
|
|
|
start = monatsEnde.AddDays(1);
|
|
}
|
|
|
|
start = sc.StartDate ?? pRo.StartDate;
|
|
|
|
//Berechne Ist bis Ende des Vormonats
|
|
decimal minutenIst = 0;
|
|
|
|
IList<ServiceRecord> allServiceRecords = new List<ServiceRecord>();
|
|
|
|
foreach (var ic2s in sc.CostBearer2SupportConceptList)
|
|
{
|
|
allServiceRecords.AddRange(ic2s.ServiceRecords);
|
|
}
|
|
|
|
|
|
Dictionary<long, bool> groupBookingDict = new Dictionary<long, bool>();
|
|
decimal stundenausgleich = 0;
|
|
|
|
foreach (var item in allServiceRecords)
|
|
{
|
|
if (!item.GroupOid.HasValue || !groupBookingDict.ContainsKey(item.GroupOid.Value))
|
|
{
|
|
if (item.Start != null)
|
|
{
|
|
if (item.Start >= start && item.Start.Value <= ende)
|
|
{
|
|
if (item.ServiceDescription != null &&
|
|
item.ServiceDescription.ServiceCategory != null)
|
|
{
|
|
var prozent = item.ServiceDescription.ServiceCategory.ProzentAbrechnung;
|
|
if (item.ServiceDescription.ProzentAbrechnung.HasValue)
|
|
{
|
|
prozent = item.ServiceDescription.ProzentAbrechnung.Value;
|
|
|
|
}
|
|
|
|
var d = (item.RoundedDuration * prozent) / 100;
|
|
if (item.ServiceDescription.ServiceCategory.IsBillable)
|
|
{
|
|
minutenIst += d;
|
|
}
|
|
|
|
if (item.ServiceDescription.ServiceCategory.Name == "Stundenausgleich")
|
|
{
|
|
stundenausgleich += d;
|
|
}
|
|
|
|
if (item.GroupOid.HasValue)
|
|
groupBookingDict.Add(item.GroupOid.Value, true);
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
pRo.MinutenGeleistetBisVormonat = minutenIst - stundenausgleich;
|
|
pRo.MinutenSollBisVormonat = sollGesamt * 60;
|
|
}
|
|
|
|
}
|
|
|
|
private void SetNotice(ServicesOverviewRO pRo, ServicesOverviewRO.ServiceDetail sd)
|
|
{
|
|
var customer = DAOFactory.GenericDAO.LoadByID<Customer>(pRo.CustomerOid);
|
|
|
|
sd.Notice = "";
|
|
|
|
if (sd.ServiceCategory == "Vertretung Fachkraft")
|
|
{
|
|
sd.Notice = "Vertretung";
|
|
}
|
|
else
|
|
{
|
|
foreach (var e2c in customer.Employee2CustomerList)
|
|
{
|
|
if (e2c.EmployeeOid == sd.EmployeeOid)
|
|
{
|
|
foreach (var v2o in e2c.ValueList)
|
|
{
|
|
if (v2o.Entry.Type == ValueListEntryType.StaffRoleType)
|
|
{
|
|
sd.Notice = v2o.Entry.Value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (String.IsNullOrWhiteSpace(sd.Notice))
|
|
{
|
|
sd.Notice = "Vertretung";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|