157 lines
5.3 KiB
C#
157 lines
5.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Service.DCEntityMapper;
|
|
using BeWo.Service.Plugins;
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Extensions;
|
|
using BS.Shared.Services;
|
|
|
|
namespace Wetterleuchten
|
|
{
|
|
public class CustomServiceRecordStatisticFactory : ServiceRecordStatisticFactory
|
|
{
|
|
private Dictionary<long, decimal> sdOid2Hours = new Dictionary<long, decimal>();
|
|
|
|
public override bool UseFlexibleView() // damit deren Anpassungen nicht überschrieben werden
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public override ServiceRecordStatisticsInfoDC GetServiceRecordStatisticInfo(long costBearer2SupportConceptOid, DateTime statisticsDate)
|
|
{
|
|
var c2s = DAOFactory.GenericDAO.LoadByID<CostBearer2SupportConcept>(costBearer2SupportConceptOid);
|
|
ServiceCategory kombiCategory = null;
|
|
|
|
foreach (var scap in c2s.ApprovalPeriodList)
|
|
{
|
|
if (scap.ServiceCategory != null && scap.ServiceCategory.Name == "Kombisachleistung" && scap.ApprovedFixedAmount.HasValue && scap.ApprovedFixedAmount.Value > 0)
|
|
{
|
|
kombiCategory = scap.ServiceCategory;
|
|
}
|
|
}
|
|
|
|
if (kombiCategory == null)
|
|
{
|
|
return base.GetServiceRecordStatisticInfo(costBearer2SupportConceptOid, statisticsDate);
|
|
}
|
|
|
|
FillHoursDictionary(costBearer2SupportConceptOid);
|
|
var dc = new ServiceRecordStatisticsInfoDC();
|
|
|
|
var sdList = DAOFactory.SearchDAO.FindServiceDescriptionForCategory(kombiCategory.Oid.Value).ToList();
|
|
|
|
|
|
dc.Header = new string[sdList.Count + 2];
|
|
dc.Header[0] = "Betrag bewilligt:";
|
|
dc.Header[1] = "Betrag verbraucht:";
|
|
|
|
int index = 2;
|
|
foreach (var sd in sdList)
|
|
{
|
|
dc.Header[index++] = String.Format("Freie Stunden {0}:", sd.Name);
|
|
}
|
|
|
|
dc.ForegroundColor = new string[dc.Header.Length];
|
|
for (int i = 0; i < dc.ForegroundColor.Length; i++)
|
|
{
|
|
dc.ForegroundColor[i] = "#FF2B508B";
|
|
}
|
|
|
|
dc.PeriodStatisticInfos = new List<ServiceRecordPeriodStatisticsInfoDC>();
|
|
|
|
decimal gesamterBetragBewilligt = 0;
|
|
|
|
foreach (var scap in c2s.ApprovalPeriodList)
|
|
{
|
|
gesamterBetragBewilligt += scap.ApprovedFixedAmount ?? 0;
|
|
}
|
|
|
|
decimal gesamterBetragVerbraucht = 0;
|
|
|
|
foreach (var sd in sdList)
|
|
{
|
|
decimal stunden = 0;
|
|
|
|
if (sdOid2Hours.ContainsKey(sd.Oid.Value))
|
|
{
|
|
stunden = sdOid2Hours[sd.Oid.Value] / 60;
|
|
}
|
|
var preis = GetPreisForServiceDescription(sd);
|
|
|
|
gesamterBetragVerbraucht += preis * stunden;
|
|
|
|
}
|
|
|
|
ServiceRecordPeriodStatisticsInfoDC info = new ServiceRecordPeriodStatisticsInfoDC();
|
|
|
|
info.LeftValues = new string[dc.Header.Length];
|
|
//info.LeftValues[0] = String.Format("{0:dd.MM.yyyy} - {1:dd.MM.yyyy}", c2s.StartDate, c2s.EndDate);
|
|
info.LeftValues[0] = String.Format("{0:c}", gesamterBetragBewilligt);
|
|
info.LeftValues[1] = String.Format("{0:c}", gesamterBetragVerbraucht);
|
|
|
|
index = 2;
|
|
foreach (var sd in sdList)
|
|
{
|
|
var preis = GetPreisForServiceDescription(sd);
|
|
|
|
decimal freieStunden = 0;
|
|
|
|
if (preis > 0)
|
|
{
|
|
freieStunden = (gesamterBetragBewilligt - gesamterBetragVerbraucht) / preis;
|
|
}
|
|
info.LeftValues[index++] = String.Format("{0:0.00}", freieStunden);
|
|
}
|
|
|
|
info.LeftValueColors = new string[info.LeftValues.Length];
|
|
for (int i = 0; i < info.LeftValueColors.Length; i++)
|
|
{
|
|
info.LeftValueColors[i] = "#FF2B508B";
|
|
}
|
|
|
|
info.RightValues = new string[info.LeftValues.Length];
|
|
info.RightValueColors = new string[info.LeftValues.Length];
|
|
dc.PeriodStatisticInfos.Add(info);
|
|
|
|
return dc;
|
|
}
|
|
|
|
private void FillHoursDictionary(long c2sOid)
|
|
{
|
|
var list = DAOFactory.SearchDAO.FindServiceRecordsDetailsForLastDays(c2sOid, null);
|
|
|
|
foreach (var serviceRecord in list)
|
|
{
|
|
if (!sdOid2Hours.ContainsKey(serviceRecord.ServiceDescription.Oid.Value))
|
|
{
|
|
sdOid2Hours.Add(serviceRecord.ServiceDescription.Oid.Value, 0);
|
|
}
|
|
|
|
sdOid2Hours[serviceRecord.ServiceDescription.Oid.Value] += serviceRecord.RoundedDuration;
|
|
}
|
|
|
|
}
|
|
|
|
private decimal GetPreisForServiceDescription(ServiceDescription sd)
|
|
{
|
|
var sdDc = MapperFactory.ServiceDescriptionDC_ServiceDescription.MapToNewDC(sd);
|
|
|
|
foreach (var crp in sdDc.CostRatePeriods)
|
|
{
|
|
if (crp.CostRateValue.HasValue)
|
|
{
|
|
return crp.CostRateValue.Value;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
}
|