Files
BeWoPlaner/ReportImp/Club74DB2/Mitarbeiterauslastung.cs
Christian 0cdbf53408 cb
2021-11-16 10:56:40 +01:00

173 lines
5.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.Core;
using BS.Shared.Extensions;
using BS.Shared.Services;
using DevExpress.XtraPrinting;
namespace BeWo.Club74
{
[IDSpecificClass(Identifier = "Mitarbeiterauslastung")]
public partial class Mitarbeiterauslastung : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<MitarbeiterauslastungRO>
{
public Mitarbeiterauslastung()
{
InitializeComponent();
}
public void SetReportDataSource(MitarbeiterauslastungRO pRO)
{
AuslastungBerechnung b = new CustomAuslastungBerechnung();
b.CreateReport(pRO);
if (pRO.EmployeeDetailList != null)
{
foreach (var ed in pRO.EmployeeDetailList)
{
if (ed.SupportConceptDetailList != null)
{
foreach (var sd in ed.SupportConceptDetailList)
{
decimal factor = 0;
if (sd.CostBearer2SupportConcept != null)
{
var rel = MapperFactory.SupportConceptCostBearerRelDC_CostBearer2SupportConcept.MapToNewDC(
sd.CostBearer2SupportConcept);
Calculations calc = PluginLoader.FindClass<Calculations>(sd.CostBearer2SupportConcept.CostBearer.ID) ?? Calculations.GetInstance(sd.CostBearer2SupportConcept.CostBearer.ID);
sd.MinutesSoll =
Math.Round(calc.GetApprovedHoursTillNow(rel, pRO.ReportEndDate.AddDays(-1)) ?? 0, 2,
MidpointRounding.AwayFromZero);
var cr = rel.CostBearer.CostRatePeriods.GetCostRatePeriodForDate(CostRatePeriodType.RateFactor,
pRO.ReportStartDate);
if (cr != null && cr.CostRateValue.HasValue)
{
factor = cr.CostRateValue.Value;
}
}
sd.DirectIst = CreateIst(sd, pRO.ReportEndDate) / 60;
if (factor > 0)
{
sd.DirectIst *= (100 + factor) / 100;
sd.MinutesSoll *= (100 + factor) / 100;
}
sd.RelationIstSoll = sd.DirectIst - sd.MinutesSoll;
sd.Name = GetRolle(ed, sd);
}
}
}
}
this.bindingSource1.DataSource = pRO;
}
private string GetRolle(MitarbeiterauslastungRO.EmployeeDetail ed, MitarbeiterauslastungRO.SupportConceptDetail sd)
{
if (sd.Customer != null)
{
foreach (var e2c in ed.Employee.Employee2CustomerList)
{
if (e2c.CustomerOid == sd.Customer.Oid)
{
foreach (var v2o in e2c.ValueList)
{
if (v2o.Entry.Type == ValueListEntryType.StaffRoleType)
{
return v2o.Entry.Value;
}
}
}
}
}
return "";
}
private decimal CreateIst(MitarbeiterauslastungRO.SupportConceptDetail sd, DateTime reportEndDate)
{
if (sd.CostBearer2SupportConcept == null || !sd.CostBearer2SupportConcept.Oid.HasValue)
{
return 0;
}
decimal minutes = 0;
IList<ServiceRecord> records = DAOFactory.SearchDAO.FindServiceRecordsDetailsForLastDays(sd.CostBearer2SupportConcept.Oid.Value, null); ;
Dictionary<long, bool> groupOids = new Dictionary<long, bool>();
Dictionary<long, bool> srOids = new Dictionary<long, bool>();
foreach (ServiceRecord sr in records)
{
if (!srOids.ContainsKey(sr.Oid.Value))
{
srOids.Add(sr.Oid.Value, true);
if (sr.Start.Value < reportEndDate)
{
if (!sr.GroupOid.HasValue || !groupOids.ContainsKey(sr.GroupOid.Value))
{
if (sr.GroupOid.HasValue)
{
groupOids.Add(sr.GroupOid.Value, true);
}
if (sr.ServiceDescription != null && sr.ServiceDescription.ServiceCategory != null &&
sr.ServiceDescription.ServiceCategory.IsBillable)
{
minutes += sr.RoundedDuration;
}
}
//var scd = GetSupportConceptDetailForServiceRecord(empDetail, sr);
//if (scd != null)
//{
// //if (empDetail.Employee != null)
// //{
// // if (sr.EmployeeOid.HasValue && sr.EmployeeOid == empDetail.Employee.Oid)
// // {
// // AddServiceRecord(ro, scd, sr);
// // }
// //}
// //else if (empDetail.Customer != null)
// //{
// AddServiceRecord(ro, scd, sr);
// //}
// if (sr.GroupOid != null)
// {
// //groupBookingDict.Add(sr.GroupOid.Value, sr);
// }
//}
}
}
else
{
int test = 0;
}
}
return minutes;
}
}
}