2017-02-01 13:53:59 +01:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
using BeWo.Data.Access ;
using BeWo.Data.Entities ;
using BeWo.Service.DCEntityMapper ;
using BS.Shared ;
using BS.Shared.Core ;
using BS.Shared.DataContracts ;
using BS.Shared.DataContracts.Compact ;
using BS.Shared.Extensions ;
using BS.Shared.Services ;
2022-12-28 23:57:47 +01:00
using System.Text ;
2017-02-01 13:53:59 +01:00
namespace BeWo.Service.Plugins
{
2017-09-14 19:03:26 +02:00
public class SupportConceptAnalysisCreator : AbstractIDSpecificDefaultClass < SupportConceptAnalysisCreator >
{
2023-09-05 11:15:39 +02:00
protected Dictionary < long , List < ServiceRecordDC > > _cs2ServiceRecords = null ;
2022-12-28 23:57:47 +01:00
2017-06-14 08:28:21 +02:00
public virtual List < SupportConceptOverviewDC > GetSupportConceptAnalysis ( IList < long > c2sOids , long? employeeOid , long? teamOid , DateTime ? appointedDate ,
2017-09-14 19:03:26 +02:00
int? expiredMonths , bool showArchivedScs )
2017-02-10 11:08:38 +01:00
{
2022-08-25 12:51:53 +02:00
return GetSupportConceptAnalysis2 ( c2sOids , employeeOid , teamOid , null , null , appointedDate , expiredMonths , showArchivedScs ) ;
2021-06-22 20:55:30 +02:00
}
2023-02-15 20:13:03 +01:00
//public virtual List<SupportConceptOverviewDC> GetSupportConceptAnalysisItems(IList<long> c2sOids, long? employeeOid, long? teamOid, long? catOid, DateTime? startDate, DateTime? endDate,
// int? expiredMonths, bool showArchivedScs)
//{
// //return GetSupportConceptAnalysis2Alt(c2sOids, employeeOid, teamOid, catOid, startDate, endDate, expiredMonths, showArchivedScs);
// var lResult = new List<SupportConceptOverviewDC>();
// long starttime = DateTime.Now.Ticks;
// if (catOid.HasValue && catOid.Value > 0)
// {
// //return GetSupportConceptAnalysisWithCategory(c2sOids, employeeOid, teamOid, catOid.Value, startDate, endDate, expiredMonths, showArchivedScs);
// }
// DateTime filterStartDate = startDate.HasValue ? startDate.Value : DateTime.MinValue;
// DateTime filterEndDate = endDate.HasValue ? endDate.Value.AddDays(1) : DateTime.MaxValue;
// List<SupportConceptOverviewItem> alleItems = new List<SupportConceptOverviewItem>();
// var scList = DAOFactory.SearchDAO.FindSupportConceptsInDateRange(showArchivedScs, filterStartDate, filterEndDate);
// //Filter alle Hilfepläne, die überhaupt durch die Parameter infrage kommen
// StringBuilder oidList = new StringBuilder();
// foreach (var sc in scList)
// {
// if (sc.Customer.Person.LastName == "Arndt" || sc.Customer.Person.LastName == "Arsovska")
// {
// int test = 0;
// }
// //Wenn TeamOids gesetzt ist, prüfe ob Klient zu einem der Teams gehört
// if (teamOid != null)
// {
// bool isRelatedToTeam = false;
// if (sc.Customer.Team2CustomerList.Count == 0)
// {
// var team = DAOFactory.GenericDAO.LoadByID<Team>(teamOid.Value);
// Dictionary<long, long> teamMemberOidDict = new Dictionary<long, long>();
// foreach (var member in team.MemberList)
// {
// if (!teamMemberOidDict.ContainsKey(member.Oid.Value))
// {
// teamMemberOidDict.Add(member.Oid.Value, member.Oid.Value);
// }
// //if (team.Leader != null && !teamMemberOidDict.ContainsKey(team.Leader.Oid.Value))
// //{
// // teamMemberOidDict.Add(team.Leader.Oid.Value, team.Leader.Oid.Value);
// //}
// }
// foreach (var e2c in sc.Customer.Employee2CustomerList)
// {
// if (!isRelatedToTeam)
// {
// if (teamMemberOidDict.ContainsKey(e2c.EmployeeOid.Value))
// {
// isRelatedToTeam = true;
// }
// }
// }
// }
// else
// {
// foreach (var team2Customer in sc.Customer.Team2CustomerList)
// {
// if (team2Customer.TeamOid == teamOid)
// {
// isRelatedToTeam = true;
// }
// }
// }
// if (!isRelatedToTeam)
// {
// //Gehört nicht zum Team also überspringen
// continue;
// }
// }
// // Wenn Mitarbeiter gesetzt ist prüfe ob Klient von Mitarbeiter betreut wird
// if (employeeOid != null && teamOid == null)
// {
// bool isRelatedToEmployee = false;
// foreach (var e2c in sc.Customer.Employee2CustomerList)
// {
// if (!isRelatedToEmployee)
// {
// if (employeeOid.Value == e2c.EmployeeOid.Value)
// {
// isRelatedToEmployee = true;
// }
// }
// }
// if (!isRelatedToEmployee)
// {
// //Wird nicht betreut also überspringen
// continue;
// }
// }
// foreach (var c2s in sc.CostBearer2SupportConceptList)
// {
// bool cont = AddToResult(c2s);
// if (cont)
// {
// if (c2sOids != null)
// {
// if (!c2sOids.Contains(c2s.Oid.Value))
// {
// cont = false;
// }
// }
// else
// {
// if (expiredMonths.HasValue)
// {
// cont = c2s.EndDate.HasValue && c2s.EndDate.Value < DateTime.Now.AddMonths(expiredMonths.Value);
// }
// }
// DateTime minDt = filterStartDate;
// if (cont)
// {
// cont = !c2s.EndDate.HasValue || c2s.EndDate.Value >= minDt;
// }
// if (cont)
// {
// var item = new SupportConceptOverviewItem();
// item.SupportConcept = sc;
// item.CostBearer2SupportConcept = c2s;
// alleItems.Add(item);
// if (oidList.Length > 0)
// {
// oidList.Append(",");
// }
// oidList.Append(c2s.Oid);
// }
// }
// }
// }
// var allServiceDescs = DAOFactory.GenericDAO.GetAll<ServiceDescription>();
// Dictionary<long, ServiceDescriptionDC> serviceDict = new Dictionary<long, ServiceDescriptionDC>();
// foreach (var item in allServiceDescs)
// {
// serviceDict.Add(item.Oid.Value, MapperFactory.ServiceDescriptionDC_ServiceDescription.MapToNewDC(item));
// }
// _cs2ServiceRecords = new Dictionary<long, List<ServiceRecordDC>>();
// if (alleItems.Count > 0)
// {
// String sql = "SELECT Oid, Version, StartDate, EndDate, DistanceInMeter, CostBearer2SupportConceptOid, Betrag, ServiceDescriptionOid, RoundedDuration, GroupEmployeeCount, GroupPersonCount, GroupRoundedDuration, GroupOid, oid as 'test' FROM servicerecord";
// sql += String.Format(" WHERE CostBearer2SupportConceptOid in ({0})", oidList.ToString());
// //sql += " WHERE CostBearer2SupportConceptOid is not null"
// var result = DAOFactory.SearchDAO.GetSqlResult(sql);
// //
// //update customer set debitornumber = '5' + debitornumber where debitornumber is not null
// foreach (object[] srRow in result)
// {
// var sr = CreateServiceRecordDC2(srRow, serviceDict);
// if (sr.CostBearer2SupportConceptOid.HasValue)
// {
// if (!_cs2ServiceRecords.ContainsKey(sr.CostBearer2SupportConceptOid.Value))
// {
// _cs2ServiceRecords.Add(sr.CostBearer2SupportConceptOid.Value, new List<ServiceRecordDC>());
// }
// _cs2ServiceRecords[sr.CostBearer2SupportConceptOid.Value].Add(sr);
// }
// }
// }
// foreach (var item in alleItems)
// {
// var iDC = new SupportConceptOverviewDC();
// var sc = item.SupportConcept;
// var c2s = item.CostBearer2SupportConcept;
// var scDC = MapperFactory.CompactSupportConceptDC_SupportConcept.MapToNewDC(sc);
// var calc = PluginLoader.FindClass<Calculations>(c2s.CostBearer.ID) ?? Calculations.GetInstance(c2s.CostBearer.ID);
// iDC.ActivationType = sc.IsActive;
// if (iDC.ActivationType == ActivationTypeId.Active && sc.Customer.IsActive != ActivationTypeId.Active)
// {
// iDC.ActivationType = sc.Customer.IsActive;
// }
// DateTime minDt = filterStartDate;
// iDC.CalculationDate = DateTime.Now.Date;
// iDC.RequestedStartDate = c2s.RequestedStartDate;
// iDC.RequestedEndDate = c2s.RequestedEndDate;
// iDC.SupportConceptOid = sc.Oid.Value;
// iDC.CostBearer2SupportConceptOid = c2s.Oid.Value;
// iDC.CostBearer = c2s.CostBearer.Organisation != null ? c2s.CostBearer.Organisation.Name : string.Empty;
// iDC.CostBearerId = c2s.CostBearer.ID;
// iDC.CustomerOid = sc.Customer.Oid.Value;
// iDC.CustomerFirstName = sc.Customer.Person.FirstName;
// iDC.CustomerLastName = sc.Customer.Person.LastName;
// var costRates = c2s.CostBearer.CostRatePeriods.MapToNewDCs();
// iDC.ServiceUnit = costRates.GetCurrentlyValidRate(CostRatePeriodType.MinutesPerServiceUnit);
// if (iDC.ServiceUnit == null)
// {
// iDC.ServiceUnit = new CostRatePeriodDC();
// iDC.ServiceUnit.CostRateType = CostRatePeriodType.MinutesPerServiceUnit;
// iDC.ServiceUnit.UnitName = "FLS";
// iDC.ServiceUnit.CostRateValue = 60;
// }
// iDC.CurrentHourlyRate = costRates.GetCurrentlyValidRateValue(CostRatePeriodType.HourlyRate) ?? 0m;
// iDC.CurrentRateFactor = costRates.GetCurrentlyValidRateValue(CostRatePeriodType.RateFactor) ?? 0m;
// var relDC = CreateCostbearer2SupportConceptDC(c2s, scDC);
// if (c2s.ApprovedStartDate.HasValue && c2s.ApprovedStartDate.Value > minDt)
// {
// minDt = c2s.ApprovedStartDate.Value.Date;
// }
// else if (c2s.RequestedStartDate.HasValue && c2s.RequestedStartDate.Value > minDt)
// {
// minDt = c2s.RequestedStartDate.Value.Date;
// }
// var records = GetServiceRecordDCs(c2s, minDt, filterEndDate);
// iDC.ServiceRecords = records;
// iDC.FLSRecordedTillNow = BerechneGeleisteteStunden(records, calc);
// iDC.FLSBilledTillNow = iDC.FLSRecordedTillNow;
// decimal lDurationInWeeksTillNow = calc.GetDurationInWeeksTillNow(relDC, endDate) ?? 0;
// decimal lDurationInWeeks = calc.GetDurationInWeeks(relDC) ?? 0;
// if (c2s.Status == CostBearer2SupportConceptStatus.Approved)
// {
// iDC.IsApproved = true;
// if (c2s.ApprovedStartDate != null && c2s.ApprovedEndDate != null)
// {
// iDC.ApprovedStartDate = c2s.ApprovedStartDate.Value;
// iDC.ApprovedEndDate = c2s.ApprovedEndDate.Value;
// }
// }
// else
// {
// iDC.IsApproved = false;
// }
// BerechneBewilligteStunden(calc, iDC, relDC, endDate);
// if (iDC.FLSApprovedSum <= 0)
// {
// iDC.FLSRecordedTillNowInPercent = 0;
// }
// else
// {
// iDC.FLSRecordedTillNowInPercent = iDC.FLSRecordedTillNow / iDC.FLSApprovedSum * 100;
// }
// iDC.FLSDifferenceApprovedRecordedTillNow = iDC.FLSRecordedTillNow - iDC.FLSApprovedTillNow;
// if (iDC.FLSApprovedTillNow <= 0)
// {
// iDC.FLSDifferenceApprovedRecordedTillNowInPercent = 0;
// }
// else
// {
// iDC.FLSDifferenceApprovedRecordedTillNowInPercent =
// iDC.FLSRecordedTillNow / iDC.FLSApprovedTillNow *
// 100;
// }
// iDC.FLSOpen = iDC.FLSApprovedSum - iDC.FLSRecordedTillNow;
// iDC.OpenWeeks = lDurationInWeeks - lDurationInWeeksTillNow;
// //TODO kostenträger spezifisch!? in Calculations verlagern!
// iDC.OpenMonths = iDC.OpenWeeks / 4.34m;
// if (iDC.OpenWeeks <= 0)
// {
// iDC.FLSOpenPerWeek = 0;
// }
// else
// {
// iDC.FLSOpenPerWeek = iDC.FLSOpen / iDC.OpenWeeks;
// }
// iDC.WeeksTotal = lDurationInWeeks;
// if (iDC.WeeksTotal != 0)
// {
// iDC.DurationPercentage = (lDurationInWeeksTillNow / iDC.WeeksTotal) * 100;
// }
// lResult.Add(iDC);
// iDC.BEApprovedPerWeek = iDC.ServiceUnit.GetHoursInBE(iDC.FLSApprovedPerWeek);
// iDC.BEApprovedSum = iDC.ServiceUnit.GetHoursInBE(iDC.FLSApprovedSum);
// iDC.BEApprovedTillNow = iDC.ServiceUnit.GetHoursInBE(iDC.FLSApprovedTillNow);
// iDC.BEBilledTillNow = iDC.ServiceUnit.GetHoursInBE(iDC.FLSBilledTillNow);
// iDC.BEDifferenceApprovedRecordedTillNow =
// iDC.ServiceUnit.GetHoursInBE(iDC.FLSDifferenceApprovedRecordedTillNow);
// iDC.BEDifferenceApprovedRecordedTillNowInPercent =
// iDC.ServiceUnit.GetHoursInBE(iDC.FLSDifferenceApprovedRecordedTillNowInPercent);
// iDC.BEOpen = iDC.ServiceUnit.GetHoursInBE(iDC.FLSOpen);
// iDC.BEOpenPerWeek = iDC.ServiceUnit.GetHoursInBE(iDC.FLSOpenPerWeek);
// if (iDC.BEOpenPerWeek > iDC.BEOpen)
// iDC.BEOpenPerWeek = iDC.BEOpen;
// iDC.BERecordedTillNow = iDC.ServiceUnit.GetHoursInBE(iDC.FLSRecordedTillNow);
// iDC.BERecordedTillNowInPercent = iDC.ServiceUnit.GetHoursInBE(iDC.FLSRecordedTillNowInPercent);
// SetKorridorStatus(iDC);
// var customerTeams = "";
// foreach (var t2c in sc.Customer.Team2CustomerList)
// {
// var team = t2c.Team;
// if (String.IsNullOrEmpty(iDC.Team))
// customerTeams = team.Name;
// else
// {
// if (!iDC.Team.Contains(team.Name))
// {
// customerTeams += ", " + team.Name;
// }
// }
// }
// iDC.CustomerTeams = customerTeams;
// }
// long endtime = DateTime.Now.Ticks;
// long diff = endtime - starttime;
// double secs = diff / (double)10000000;
// return lResult;
//}
public virtual List < SupportConceptOverviewDC > GetSupportConceptAnalysis2 ( IList < long > c2sOids , long? employeeOid , long? teamOid , long? catOid , DateTime ? startDate , DateTime ? endDate ,
2021-06-22 20:55:30 +02:00
int? expiredMonths , bool showArchivedScs )
2025-01-28 13:39:31 +01:00
{
2022-12-28 23:57:47 +01:00
//return GetSupportConceptAnalysis2Alt(c2sOids, employeeOid, teamOid, catOid, startDate, endDate, expiredMonths, showArchivedScs);
2023-02-15 20:13:03 +01:00
//if (catOid.HasValue && catOid.Value > 0)
//{
// return GetSupportConceptAnalysisWithCategory(c2sOids, employeeOid, teamOid, catOid.Value, startDate, endDate, expiredMonths, showArchivedScs);
//}
2022-12-28 23:57:47 +01:00
var lResult = new List < SupportConceptOverviewDC > ( ) ;
long starttime = DateTime . Now . Ticks ;
2022-08-25 12:51:53 +02:00
2023-02-15 20:13:03 +01:00
2022-12-28 23:57:47 +01:00
DateTime filterStartDate = startDate . HasValue ? startDate . Value : DateTime . MinValue ;
DateTime filterEndDate = endDate . HasValue ? endDate . Value . AddDays ( 1 ) : DateTime . MaxValue ;
List < SupportConceptOverviewItem > alleItems = new List < SupportConceptOverviewItem > ( ) ;
var scList = DAOFactory . SearchDAO . FindSupportConceptsInDateRange ( showArchivedScs , filterStartDate , filterEndDate ) ;
2024-06-06 10:21:24 +02:00
List < long > alleErlaubtenTeams = new List < long > ( ) ; //leere liste => alle Teams
if ( teamOid . HasValue )
{
alleErlaubtenTeams . Add ( teamOid . Value ) ;
}
else if ( ! employeeOid . HasValue )
{
var es = PluginLoader . FindClass < EmployeeService > ( ) ;
alleErlaubtenTeams . AddRange ( es . GetAllTeamsCompact ( ) . Select ( t = > t . TeamOid ) ) ;
}
2022-12-28 23:57:47 +01:00
//Filter alle Hilfepläne, die überhaupt durch die Parameter infrage kommen
StringBuilder oidList = new StringBuilder ( ) ;
foreach ( var sc in scList )
{
//Wenn TeamOids gesetzt ist, prüfe ob Klient zu einem der Teams gehört
2024-06-06 10:21:24 +02:00
if ( alleErlaubtenTeams . Count > 0 )
2022-12-28 23:57:47 +01:00
{
bool isRelatedToTeam = false ;
if ( sc . Customer . Team2CustomerList . Count = = 0 )
{
2024-06-06 10:21:24 +02:00
var teams = DAOFactory . GenericDAO . LoadByIDs < Team > ( alleErlaubtenTeams ) ;
2022-12-28 23:57:47 +01:00
Dictionary < long , long > teamMemberOidDict = new Dictionary < long , long > ( ) ;
2024-06-06 10:21:24 +02:00
foreach ( var team in teams )
2022-12-28 23:57:47 +01:00
{
2024-06-06 10:21:24 +02:00
foreach ( var member in team . MemberList )
2022-12-28 23:57:47 +01:00
{
2024-06-06 10:21:24 +02:00
if ( ! teamMemberOidDict . ContainsKey ( member . Oid . Value ) )
{
teamMemberOidDict . Add ( member . Oid . Value , member . Oid . Value ) ;
}
//if (team.Leader != null && !teamMemberOidDict.ContainsKey(team.Leader.Oid.Value))
//{
// teamMemberOidDict.Add(team.Leader.Oid.Value, team.Leader.Oid.Value);
//}
2022-12-28 23:57:47 +01:00
}
}
2024-06-06 10:21:24 +02:00
2022-12-28 23:57:47 +01:00
foreach ( var e2c in sc . Customer . Employee2CustomerList )
{
if ( ! isRelatedToTeam )
{
if ( teamMemberOidDict . ContainsKey ( e2c . EmployeeOid . Value ) )
{
isRelatedToTeam = true ;
}
}
}
}
else
{
foreach ( var team2Customer in sc . Customer . Team2CustomerList )
{
2024-06-06 10:21:24 +02:00
if ( alleErlaubtenTeams . Contains ( team2Customer . TeamOid . Value ) )
2022-12-28 23:57:47 +01:00
{
isRelatedToTeam = true ;
}
}
}
if ( ! isRelatedToTeam )
{
2024-06-19 16:13:56 +02:00
if ( employeeOid . HasValue | | teamOid . HasValue )
{
//Gehört nicht zum Team also überspringen
continue ;
}
2022-12-28 23:57:47 +01:00
}
}
// Wenn Mitarbeiter gesetzt ist prüfe ob Klient von Mitarbeiter betreut wird
2024-06-06 10:21:24 +02:00
if ( employeeOid ! = null & & alleErlaubtenTeams . Count = = 0 )
2022-12-28 23:57:47 +01:00
{
bool isRelatedToEmployee = false ;
foreach ( var e2c in sc . Customer . Employee2CustomerList )
{
if ( ! isRelatedToEmployee )
{
if ( employeeOid . Value = = e2c . EmployeeOid . Value )
{
2024-09-24 00:00:31 +02:00
if ( ( ! e2c . StartDate . HasValue | | e2c . StartDate < = DateTime . Now . Date ) & & ( ! e2c . EndDate . HasValue | | e2c . EndDate > = DateTime . Now . Date ) )
{
isRelatedToEmployee = true ;
}
2022-12-28 23:57:47 +01:00
}
}
}
if ( ! isRelatedToEmployee )
{
//Wird nicht betreut also überspringen
continue ;
}
}
foreach ( var c2s in sc . CostBearer2SupportConceptList )
{
bool cont = AddToResult ( c2s ) ;
if ( cont )
{
if ( c2sOids ! = null )
{
if ( ! c2sOids . Contains ( c2s . Oid . Value ) )
{
cont = false ;
}
}
else
{
if ( expiredMonths . HasValue )
{
2024-06-19 16:13:56 +02:00
cont = c2s . EndDate . HasValue & & c2s . EndDate . Value < = DateTime . Now . Date . AddMonths ( expiredMonths . Value ) ;
2022-12-28 23:57:47 +01:00
}
}
DateTime minDt = filterStartDate ;
if ( cont )
{
cont = ! c2s . EndDate . HasValue | | c2s . EndDate . Value > = minDt ;
}
if ( cont )
{
2023-02-15 20:13:03 +01:00
if ( catOid . HasValue & & catOid . Value > 0 )
{
foreach ( var scap in c2s . ApprovalPeriodList )
{
if ( AddToResult ( scap , catOid ) )
{
var item = new SupportConceptOverviewItem ( ) ;
item . SupportConcept = sc ;
item . CostBearer2SupportConcept = c2s ;
item . SupportConceptApprovalPeriod = scap ;
alleItems . Add ( item ) ;
}
2022-12-28 23:57:47 +01:00
2023-02-15 20:13:03 +01:00
}
}
else
{
var item = new SupportConceptOverviewItem ( ) ;
item . SupportConcept = sc ;
item . CostBearer2SupportConcept = c2s ;
alleItems . Add ( item ) ;
}
2022-12-28 23:57:47 +01:00
if ( oidList . Length > 0 )
{
oidList . Append ( "," ) ;
}
oidList . Append ( c2s . Oid ) ;
}
}
}
}
var allServiceDescs = DAOFactory . GenericDAO . GetAll < ServiceDescription > ( ) ;
Dictionary < long , ServiceDescriptionDC > serviceDict = new Dictionary < long , ServiceDescriptionDC > ( ) ;
foreach ( var item in allServiceDescs )
{
serviceDict . Add ( item . Oid . Value , MapperFactory . ServiceDescriptionDC_ServiceDescription . MapToNewDC ( item ) ) ;
}
_cs2ServiceRecords = new Dictionary < long , List < ServiceRecordDC > > ( ) ;
if ( alleItems . Count > 0 )
{
2023-02-15 20:13:03 +01:00
String sql = "SELECT Oid, Version, StartDate, EndDate, DistanceInMeter, CostBearer2SupportConceptOid, Betrag, ServiceDescriptionOid, RoundedDuration, GroupEmployeeCount, GroupPersonCount, GroupRoundedDuration, GroupOid FROM servicerecord" ;
if ( oidList . Length > 0 )
{
sql + = String . Format ( " WHERE CostBearer2SupportConceptOid in ({0})" , oidList . ToString ( ) ) ;
}
else
{
sql + = " WHERE CostBearer2SupportConceptOid is not null" ;
}
if ( catOid . HasValue & & catOid . Value > 0 )
{
sql + = String . Format ( " AND ServiceDescriptionOid in (SELECT sd.OID FROM ServiceDescription sd WHERE sd.ServiceCategoryOid = {0})" , catOid . Value ) ;
}
2022-12-28 23:57:47 +01:00
var result = DAOFactory . SearchDAO . GetSqlResult ( sql ) ;
//
//update customer set debitornumber = '5' + debitornumber where debitornumber is not null
foreach ( object [ ] srRow in result )
{
var sr = CreateServiceRecordDC2 ( srRow , serviceDict ) ;
if ( sr . CostBearer2SupportConceptOid . HasValue )
{
if ( ! _cs2ServiceRecords . ContainsKey ( sr . CostBearer2SupportConceptOid . Value ) )
{
_cs2ServiceRecords . Add ( sr . CostBearer2SupportConceptOid . Value , new List < ServiceRecordDC > ( ) ) ;
}
_cs2ServiceRecords [ sr . CostBearer2SupportConceptOid . Value ] . Add ( sr ) ;
}
}
}
2023-02-15 20:13:03 +01:00
//
//update customer set debitornumber = '5' + debitornumber where debitornumber is not null
2022-12-28 23:57:47 +01:00
foreach ( var item in alleItems )
{
var iDC = new SupportConceptOverviewDC ( ) ;
var sc = item . SupportConcept ;
2023-02-15 20:13:03 +01:00
2022-12-28 23:57:47 +01:00
var c2s = item . CostBearer2SupportConcept ;
2023-02-15 20:13:03 +01:00
var scap = item . SupportConceptApprovalPeriod ;
2022-12-28 23:57:47 +01:00
var scDC = MapperFactory . CompactSupportConceptDC_SupportConcept . MapToNewDC ( sc ) ;
var calc = PluginLoader . FindClass < Calculations > ( c2s . CostBearer . ID ) ? ? Calculations . GetInstance ( c2s . CostBearer . ID ) ;
2023-02-15 20:13:03 +01:00
2022-12-28 23:57:47 +01:00
iDC . ActivationType = sc . IsActive ;
if ( iDC . ActivationType = = ActivationTypeId . Active & & sc . Customer . IsActive ! = ActivationTypeId . Active )
{
iDC . ActivationType = sc . Customer . IsActive ;
}
if ( c2s . Status = = CostBearer2SupportConceptStatus . Approved )
{
iDC . IsApproved = true ;
if ( c2s . ApprovedStartDate ! = null & & c2s . ApprovedEndDate ! = null )
{
iDC . ApprovedStartDate = c2s . ApprovedStartDate . Value ;
iDC . ApprovedEndDate = c2s . ApprovedEndDate . Value ;
}
}
else
{
iDC . IsApproved = false ;
}
DateTime minDt = filterStartDate ;
2023-02-15 20:13:03 +01:00
DateTime maxDt = filterEndDate ;
2022-12-28 23:57:47 +01:00
iDC . CalculationDate = DateTime . Now . Date ;
iDC . RequestedStartDate = c2s . RequestedStartDate ;
iDC . RequestedEndDate = c2s . RequestedEndDate ;
iDC . SupportConceptOid = sc . Oid . Value ;
iDC . CostBearer2SupportConceptOid = c2s . Oid . Value ;
iDC . CostBearer = c2s . CostBearer . Organisation ! = null ? c2s . CostBearer . Organisation . Name : string . Empty ;
iDC . CostBearerId = c2s . CostBearer . ID ;
iDC . CustomerOid = sc . Customer . Oid . Value ;
iDC . CustomerFirstName = sc . Customer . Person . FirstName ;
iDC . CustomerLastName = sc . Customer . Person . LastName ;
2023-11-15 00:52:39 +01:00
2022-12-28 23:57:47 +01:00
var costRates = c2s . CostBearer . CostRatePeriods . MapToNewDCs ( ) ;
iDC . ServiceUnit = costRates . GetCurrentlyValidRate ( CostRatePeriodType . MinutesPerServiceUnit ) ;
if ( iDC . ServiceUnit = = null )
{
iDC . ServiceUnit = new CostRatePeriodDC ( ) ;
iDC . ServiceUnit . CostRateType = CostRatePeriodType . MinutesPerServiceUnit ;
iDC . ServiceUnit . UnitName = "FLS" ;
iDC . ServiceUnit . CostRateValue = 60 ;
}
iDC . CurrentHourlyRate = costRates . GetCurrentlyValidRateValue ( CostRatePeriodType . HourlyRate ) ? ? 0 m ;
iDC . CurrentRateFactor = costRates . GetCurrentlyValidRateValue ( CostRatePeriodType . RateFactor ) ? ? 0 m ;
var relDC = CreateCostbearer2SupportConceptDC ( c2s , scDC ) ;
if ( c2s . ApprovedStartDate . HasValue & & c2s . ApprovedStartDate . Value > minDt )
{
minDt = c2s . ApprovedStartDate . Value . Date ;
}
else if ( c2s . RequestedStartDate . HasValue & & c2s . RequestedStartDate . Value > minDt )
{
minDt = c2s . RequestedStartDate . Value . Date ;
}
2023-02-15 20:13:03 +01:00
decimal lDurationInWeeksTillNow = 0 ;
decimal lDurationInWeeks = 0 ;
2022-12-28 23:57:47 +01:00
2023-12-07 10:12:07 +01:00
if ( iDC . CustomerLastName = = "Krzizok" )
2023-02-15 20:13:03 +01:00
{
int test = 0 ;
}
if ( scap ! = null )
{
var scapDc = scap . MapToNewDC ( ) ;
2022-12-28 23:57:47 +01:00
2023-02-15 20:13:03 +01:00
iDC . RequestedStartDate = scap . StartDate ;
iDC . RequestedEndDate = scap . EndDate ;
2022-12-28 23:57:47 +01:00
2023-02-15 20:13:03 +01:00
if ( scap . StartDate . HasValue & & scap . StartDate . Value > minDt )
2022-12-28 23:57:47 +01:00
{
2023-02-15 20:13:03 +01:00
minDt = scap . StartDate . Value . Date ;
2022-12-28 23:57:47 +01:00
}
2023-02-15 20:13:03 +01:00
if ( scap . EndDate . HasValue & & scap . EndDate . Value < maxDt )
{
maxDt = scap . EndDate . Value . Date ;
}
lDurationInWeeksTillNow = GetDurationInWeeksTillNow ( scap . StartDate , scap . EndDate , endDate ) ? ? 0 ;
lDurationInWeeks = GetDurationInWeeks ( scap . StartDate , scap . EndDate ) ? ? 0 ;
BerechneBewilligteStunden ( calc , iDC , relDC , scapDc , endDate ) ;
2022-12-28 23:57:47 +01:00
}
else
{
2023-02-15 20:13:03 +01:00
lDurationInWeeksTillNow = calc . GetDurationInWeeksTillNow ( relDC , endDate ) ? ? 0 ;
lDurationInWeeks = calc . GetDurationInWeeks ( relDC ) ? ? 0 ;
BerechneBewilligteStunden ( calc , iDC , relDC , endDate ) ;
2022-12-28 23:57:47 +01:00
}
2023-02-15 20:13:03 +01:00
2022-12-28 23:57:47 +01:00
2023-02-15 20:13:03 +01:00
var records = GetServiceRecordDCs ( c2s , minDt , maxDt ) ;
2022-12-28 23:57:47 +01:00
2023-02-15 20:13:03 +01:00
iDC . ServiceRecords = records ;
2023-11-15 00:52:39 +01:00
//decimal tempDuration = 0;
//foreach (var temp in records)
//{
// if (temp.ServiceDescription.Category.IsBillable)
// {
// var dur = temp.RoundedDuration;
// if (temp.GroupEmployeeCount.HasValue && temp.GroupEmployeeCount > 1)
// {
// dur /= temp.GroupEmployeeCount.Value;
// }
// tempDuration += dur;
// }
//}
//tempDuration /= 60;
2025-01-28 13:39:31 +01:00
//iDC.FLSRecordedTillNow = BerechneGeleisteteStunden(records, calc); // alt, da werden Fehlkontakte nur zu 80% mit reingenommen. Aber vom Budget gehen ja 100% runter
iDC . FLSRecordedTillNow = BerechneGeleisteteStundenMit100ProzentFehlkontakten ( records , calc ) ;
2023-02-15 20:13:03 +01:00
iDC . FLSBilledTillNow = iDC . FLSRecordedTillNow ;
2022-12-28 23:57:47 +01:00
if ( iDC . FLSApprovedSum < = 0 )
{
iDC . FLSRecordedTillNowInPercent = 0 ;
}
else
{
iDC . FLSRecordedTillNowInPercent = iDC . FLSRecordedTillNow / iDC . FLSApprovedSum * 100 ;
}
iDC . FLSDifferenceApprovedRecordedTillNow = iDC . FLSRecordedTillNow - iDC . FLSApprovedTillNow ;
if ( iDC . FLSApprovedTillNow < = 0 )
{
iDC . FLSDifferenceApprovedRecordedTillNowInPercent = 0 ;
}
else
{
iDC . FLSDifferenceApprovedRecordedTillNowInPercent =
iDC . FLSRecordedTillNow / iDC . FLSApprovedTillNow *
100 ;
}
iDC . FLSOpen = iDC . FLSApprovedSum - iDC . FLSRecordedTillNow ;
iDC . OpenWeeks = lDurationInWeeks - lDurationInWeeksTillNow ;
//TODO kostenträger spezifisch!? in Calculations verlagern!
iDC . OpenMonths = iDC . OpenWeeks / 4.34 m ;
if ( iDC . OpenWeeks < = 0 )
{
iDC . FLSOpenPerWeek = 0 ;
}
else
{
iDC . FLSOpenPerWeek = iDC . FLSOpen / iDC . OpenWeeks ;
}
iDC . WeeksTotal = lDurationInWeeks ;
if ( iDC . WeeksTotal ! = 0 )
{
iDC . DurationPercentage = ( lDurationInWeeksTillNow / iDC . WeeksTotal ) * 100 ;
}
lResult . Add ( iDC ) ;
iDC . BEApprovedPerWeek = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSApprovedPerWeek ) ;
iDC . BEApprovedSum = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSApprovedSum ) ;
iDC . BEApprovedTillNow = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSApprovedTillNow ) ;
iDC . BEBilledTillNow = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSBilledTillNow ) ;
iDC . BEDifferenceApprovedRecordedTillNow =
iDC . ServiceUnit . GetHoursInBE ( iDC . FLSDifferenceApprovedRecordedTillNow ) ;
iDC . BEDifferenceApprovedRecordedTillNowInPercent =
iDC . ServiceUnit . GetHoursInBE ( iDC . FLSDifferenceApprovedRecordedTillNowInPercent ) ;
iDC . BEOpen = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSOpen ) ;
iDC . BEOpenPerWeek = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSOpenPerWeek ) ;
if ( iDC . BEOpenPerWeek > iDC . BEOpen )
iDC . BEOpenPerWeek = iDC . BEOpen ;
iDC . BERecordedTillNow = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSRecordedTillNow ) ;
iDC . BERecordedTillNowInPercent = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSRecordedTillNowInPercent ) ;
SetKorridorStatus ( iDC ) ;
}
long endtime = DateTime . Now . Ticks ;
long diff = endtime - starttime ;
double secs = diff / ( double ) 10000000 ;
return lResult ;
}
public virtual SupportConceptCostBearerRelDC CreateCostbearer2SupportConceptDC ( CostBearer2SupportConcept pEntity , CompactSupportConceptDC scDc )
{
SupportConceptCostBearerRelDC dc = new SupportConceptCostBearerRelDC ( ) ;
if ( pEntity . CostBearer . Organisation ! = null )
{
dc . CostBearer = MapperFactory . CompactOrganisationDC_Organisation . MapToNewDC ( pEntity . CostBearer . Organisation ) ;
}
dc . CostBearer2SupportConceptOid = pEntity . Oid ;
dc . CostBearer2SupportConceptVersion = pEntity . Version ;
dc . Notice = pEntity . Notice ;
dc . Status = pEntity . Status ;
dc . SupportConcept = scDc ;
// pDataContract.NoRelationExists = pEntity.ServiceRecords.Count == 0;
dc . RequestedStartDate = pEntity . RequestedStartDate ;
dc . RequestedEndDate = pEntity . RequestedEndDate ;
dc . ApprovedStartDate = pEntity . ApprovedStartDate ;
dc . ApprovedEndDate = pEntity . ApprovedEndDate ;
dc . CustomerReferenceNumber = pEntity . CustomerReferenceNumber ;
dc . AuswahlBezeichnung = pEntity . AuswahlBezeichnung ;
2025-08-05 16:27:16 +02:00
dc . KontoHilfeplan = pEntity . KontoHilfeplan ;
dc . KostenstelleHilfeplan = pEntity . KostenstelleHilfeplan ;
2022-12-28 23:57:47 +01:00
dc . MonthlyPayment = pEntity . MonthlyPayment ;
dc . ApprovalPeriodList = MapperFactory . SupportConceptApprovalPeriodDC_SupportConceptApprovalPeriod . MapToNewDCs ( pEntity . ApprovalPeriodList ) ;
if ( dc . ApprovalPeriodList ! = null )
{
foreach ( SupportConceptApprovalPeriodDC item in dc . ApprovalPeriodList )
{
if ( ! item . StartDate . HasValue )
{
item . StartDate = pEntity . ApprovedStartDate . HasValue ? pEntity . ApprovedStartDate : pEntity . RequestedStartDate ;
}
if ( ! item . EndDate . HasValue )
{
item . EndDate = pEntity . ApprovedEndDate . HasValue ? pEntity . ApprovedEndDate : pEntity . RequestedEndDate ;
}
}
}
return dc ;
}
public virtual List < SupportConceptOverviewDC > GetSupportConceptAnalysis2Alt ( IList < long > c2sOids , long? employeeOid , long? teamOid , long? catOid , DateTime ? startDate , DateTime ? endDate ,
int? expiredMonths , bool showArchivedScs )
{
long starttime = DateTime . Now . Ticks ;
if ( catOid . HasValue & & catOid . Value > 0 )
{
return GetSupportConceptAnalysisWithCategory ( c2sOids , employeeOid , teamOid , catOid . Value , startDate , endDate , expiredMonths , showArchivedScs ) ;
}
DateTime filterStartDate = startDate . HasValue ? startDate . Value : DateTime . MinValue ;
DateTime filterEndDate = endDate . HasValue ? endDate . Value . AddDays ( 1 ) : DateTime . MaxValue ;
2017-09-14 19:03:26 +02:00
var lResult = new List < SupportConceptOverviewDC > ( ) ;
2022-12-28 23:57:47 +01:00
var c2sList = DAOFactory . GenericDAO . GetAllActive < CostBearer2SupportConcept > ( ) ;
//var c2sList2 = DAOFactory.SearchDAO.FindCostBearer2SupportConceptInDateRange(showArchivedScs, filterStartDate, filterEndDate);
foreach ( var iCb2Sc in c2sList )
2017-09-14 19:03:26 +02:00
{
2022-12-28 23:57:47 +01:00
if ( iCb2Sc . SupportConcept . Customer . Person . LastName = = "Arndt" | | iCb2Sc . SupportConcept . Customer . Person . LastName = = "Arsovska" )
{
int test = 0 ;
}
2017-09-14 19:03:26 +02:00
bool cont = AddToResult ( iCb2Sc ) ;
if ( cont )
{
var calc = PluginLoader . FindClass < Calculations > ( iCb2Sc . CostBearer . ID ) ? ?
Calculations . GetInstance ( iCb2Sc . CostBearer . ID ) ;
var iDC = new SupportConceptOverviewDC ( ) ;
iDC . ActivationType = iCb2Sc . SupportConcept . IsActive ;
if ( iDC . ActivationType = = ActivationTypeId . Active & &
iCb2Sc . SupportConcept . Customer . IsActive ! = ActivationTypeId . Active )
{
iDC . ActivationType = iCb2Sc . SupportConcept . Customer . IsActive ;
}
if ( c2sOids ! = null )
{
if ( ! c2sOids . Contains ( iCb2Sc . Oid . Value ) )
{
cont = false ;
}
}
else
{
cont = ( showArchivedScs & & iDC . ActivationType ! = ActivationTypeId . Deleted ) | |
iDC . ActivationType = = ActivationTypeId . Active ;
if ( cont & & teamOid ! = null )
{
bool isRelatedToTeam = false ;
if ( iCb2Sc . SupportConcept . Customer . Team2CustomerList . Count = = 0 )
{
var team = DAOFactory . GenericDAO . LoadByID < Team > ( teamOid . Value ) ;
Dictionary < long , long > teamMemberOidDict = new Dictionary < long , long > ( ) ;
foreach ( var member in team . MemberList )
{
if ( ! teamMemberOidDict . ContainsKey ( member . Oid . Value ) )
{
teamMemberOidDict . Add ( member . Oid . Value , member . Oid . Value ) ;
}
//if (team.Leader != null && !teamMemberOidDict.ContainsKey(team.Leader.Oid.Value))
//{
// teamMemberOidDict.Add(team.Leader.Oid.Value, team.Leader.Oid.Value);
//}
}
foreach ( var e2c in iCb2Sc . SupportConcept . Customer . Employee2CustomerList )
{
if ( ! isRelatedToTeam )
{
if ( teamMemberOidDict . ContainsKey ( e2c . EmployeeOid . Value ) )
{
isRelatedToTeam = true ;
}
}
}
}
else
{
foreach ( var team2Customer in iCb2Sc . SupportConcept . Customer . Team2CustomerList )
{
if ( team2Customer . TeamOid = = teamOid )
{
isRelatedToTeam = true ;
}
}
}
if ( ! isRelatedToTeam )
{
cont = false ;
}
}
if ( cont & & employeeOid ! = null & & teamOid = = null )
{
bool isRelatedToEmployee = false ;
foreach ( var e2c in iCb2Sc . SupportConcept . Customer . Employee2CustomerList )
{
if ( ! isRelatedToEmployee )
{
if ( employeeOid . Value = = e2c . EmployeeOid . Value )
{
isRelatedToEmployee = true ;
}
}
}
if ( ! isRelatedToEmployee )
{
cont = false ;
}
}
if ( cont & & expiredMonths . HasValue )
{
cont = iCb2Sc . EndDate . HasValue & &
iCb2Sc . EndDate . Value < DateTime . Now . AddMonths ( expiredMonths . Value ) ;
}
}
2022-12-28 23:57:47 +01:00
DateTime minDt = filterStartDate ;
2017-09-14 19:03:26 +02:00
2022-08-25 12:51:53 +02:00
if ( cont )
{
2022-12-28 23:57:47 +01:00
cont = ! iCb2Sc . EndDate . HasValue | | iCb2Sc . EndDate . Value > = minDt ;
2022-08-25 12:51:53 +02:00
}
2017-09-14 19:03:26 +02:00
if ( cont )
{
iDC . CalculationDate = DateTime . Now . Date ;
iDC . RequestedStartDate = iCb2Sc . RequestedStartDate ;
iDC . RequestedEndDate = iCb2Sc . RequestedEndDate ;
iDC . SupportConceptOid = iCb2Sc . SupportConcept . Oid . Value ;
iDC . CostBearer2SupportConceptOid = iCb2Sc . Oid . Value ;
iDC . CostBearer = iCb2Sc . CostBearer . Organisation ! = null
? iCb2Sc . CostBearer . Organisation . Name
: string . Empty ;
iDC . CostBearerId = iCb2Sc . CostBearer . ID ;
iDC . CustomerOid = iCb2Sc . SupportConcept . Customer . Oid . Value ;
iDC . CustomerFirstName = iCb2Sc . SupportConcept . Customer . Person . FirstName ;
iDC . CustomerLastName = iCb2Sc . SupportConcept . Customer . Person . LastName ;
2022-08-25 12:51:53 +02:00
if ( iDC . CustomerLastName = = "Böhm" )
{
int test = 0 ;
}
2017-09-14 19:03:26 +02:00
var costRates = iCb2Sc . CostBearer . CostRatePeriods . MapToNewDCs ( ) ;
iDC . ServiceUnit = costRates . GetCurrentlyValidRate ( CostRatePeriodType . MinutesPerServiceUnit ) ;
if ( iDC . ServiceUnit = = null )
{
iDC . ServiceUnit = new CostRatePeriodDC ( ) ;
iDC . ServiceUnit . CostRateType = CostRatePeriodType . MinutesPerServiceUnit ;
iDC . ServiceUnit . UnitName = "FLS" ;
iDC . ServiceUnit . CostRateValue = 60 ;
}
iDC . CurrentHourlyRate = costRates . GetCurrentlyValidRateValue ( CostRatePeriodType . HourlyRate ) ? ? 0 m ;
iDC . CurrentRateFactor = costRates . GetCurrentlyValidRateValue ( CostRatePeriodType . RateFactor ) ? ? 0 m ;
var relDC = iCb2Sc . MapToNewDC ( ) ;
2022-08-25 12:51:53 +02:00
2022-12-28 23:57:47 +01:00
if ( iCb2Sc . ApprovedStartDate . HasValue )
2017-09-14 19:03:26 +02:00
{
2022-08-25 12:51:53 +02:00
minDt = iCb2Sc . ApprovedStartDate . Value . Date ;
2017-09-14 19:03:26 +02:00
}
2022-12-28 23:57:47 +01:00
else if ( iCb2Sc . RequestedStartDate . HasValue )
2017-09-14 19:03:26 +02:00
{
2022-08-25 12:51:53 +02:00
minDt = iCb2Sc . RequestedStartDate . Value . Date ;
2017-09-14 19:03:26 +02:00
}
2022-12-28 23:57:47 +01:00
var records = GetServiceRecordDCs ( iCb2Sc , minDt , filterEndDate ) ;
2017-09-14 19:03:26 +02:00
2022-11-09 09:44:24 +01:00
iDC . ServiceRecords = records ;
iDC . FLSRecordedTillNow = BerechneGeleisteteStunden ( records , calc ) ;
2022-12-28 23:57:47 +01:00
2017-09-14 19:03:26 +02:00
//var notBillableAbsenceTimes = calc.GetHoursNotBillableDueToAbsenceTimes(relDC, recordDCs,
// iCb2Sc.SupportConcept.Customer.GetAbsencesTimesNotBillableWholeWeeks(), false,
// false);
//var notBillableMoreThanApproved = calc.GetHoursNotBillableDueToMoreThanApproved(relDC, recordDCs,
// false, true);
iDC . FLSBilledTillNow = iDC . FLSRecordedTillNow ;
//- notBillableAbsenceTimes
//- notBillableMoreThanApproved;
2022-08-25 12:51:53 +02:00
decimal lDurationInWeeksTillNow = calc . GetDurationInWeeksTillNow ( relDC , endDate ) ? ? 0 ;
2017-09-14 19:03:26 +02:00
decimal lDurationInWeeks = calc . GetDurationInWeeks ( relDC ) ? ? 0 ;
if ( iCb2Sc . Status = = CostBearer2SupportConceptStatus . Approved )
{
iDC . IsApproved = true ;
if ( iCb2Sc . ApprovedStartDate ! = null & & iCb2Sc . ApprovedEndDate ! = null )
{
iDC . ApprovedStartDate = iCb2Sc . ApprovedStartDate . Value ;
iDC . ApprovedEndDate = iCb2Sc . ApprovedEndDate . Value ;
//lDurationInWeeks = Convert.ToDecimal((iDC.ApprovedEndDate.Value - iDC.ApprovedStartDate.Value).Days + 1) / 7;
//lCalcDate = lCalcDate > iCb2Sc.ApprovedEndDate
// ? iCb2Sc.ApprovedEndDate.Value.Date.AddDays(1)
// : lCalcDate;
//lDurationInWeeksTillNow = Convert.ToDecimal((lCalcDate - iCb2Sc.ApprovedStartDate.Value).Days) / 7m;
}
}
else
{
iDC . IsApproved = false ;
//if (iCb2Sc.RequestedStartDate != null && iCb2Sc.RequestedEndDate != null)
//{
//lDurationInWeeks = Convert.ToDecimal((iCb2Sc.RequestedEndDate.Value - iCb2Sc.RequestedStartDate.Value).Days + 1) / 7;
//lCalcDate = lCalcDate > iCb2Sc.RequestedEndDate
// ? iCb2Sc.RequestedEndDate.Value.Date
// : lCalcDate;
//lDurationInWeeksTillNow = Convert.ToDecimal((lCalcDate - iCb2Sc.RequestedStartDate.Value).Days) / 7m;
//}
}
2022-08-25 12:51:53 +02:00
BerechneBewilligteStunden ( calc , iDC , relDC , endDate ) ;
2017-09-14 19:03:26 +02:00
//if (flsTotal.HasValue && lDurationInWeeks != 0)
//{
// iDC.FLSApprovedTillNow = flsTotal.Value * ((lDurationInWeeksTillNow + (1m / 7m)) / lDurationInWeeks);
//}
//else
//{
// iDC.FLSApprovedTillNow = iDC.FLSApprovedPerWeek * (lDurationInWeeksTillNow + (1m / 7m));
//}
if ( iDC . FLSApprovedSum < = 0 )
{
iDC . FLSRecordedTillNowInPercent = 0 ;
}
else
{
iDC . FLSRecordedTillNowInPercent = iDC . FLSRecordedTillNow / iDC . FLSApprovedSum * 100 ;
}
iDC . FLSDifferenceApprovedRecordedTillNow = iDC . FLSRecordedTillNow - iDC . FLSApprovedTillNow ;
if ( iDC . FLSApprovedTillNow < = 0 )
{
iDC . FLSDifferenceApprovedRecordedTillNowInPercent = 0 ;
}
else
{
iDC . FLSDifferenceApprovedRecordedTillNowInPercent =
iDC . FLSRecordedTillNow / iDC . FLSApprovedTillNow *
100 ;
}
iDC . FLSOpen = iDC . FLSApprovedSum - iDC . FLSRecordedTillNow ;
iDC . OpenWeeks = lDurationInWeeks - lDurationInWeeksTillNow ;
//TODO kostenträger spezifisch!? in Calculations verlagern!
iDC . OpenMonths = iDC . OpenWeeks / 4.34 m ;
if ( iDC . OpenWeeks < = 0 )
{
iDC . FLSOpenPerWeek = 0 ;
}
else
{
iDC . FLSOpenPerWeek = iDC . FLSOpen / iDC . OpenWeeks ;
}
iDC . WeeksTotal = lDurationInWeeks ;
if ( iDC . WeeksTotal ! = 0 )
{
iDC . DurationPercentage = ( lDurationInWeeksTillNow / iDC . WeeksTotal ) * 100 ;
}
lResult . Add ( iDC ) ;
iDC . BEApprovedPerWeek = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSApprovedPerWeek ) ;
iDC . BEApprovedSum = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSApprovedSum ) ;
iDC . BEApprovedTillNow = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSApprovedTillNow ) ;
iDC . BEBilledTillNow = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSBilledTillNow ) ;
iDC . BEDifferenceApprovedRecordedTillNow =
iDC . ServiceUnit . GetHoursInBE ( iDC . FLSDifferenceApprovedRecordedTillNow ) ;
iDC . BEDifferenceApprovedRecordedTillNowInPercent =
iDC . ServiceUnit . GetHoursInBE ( iDC . FLSDifferenceApprovedRecordedTillNowInPercent ) ;
iDC . BEOpen = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSOpen ) ;
iDC . BEOpenPerWeek = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSOpenPerWeek ) ;
if ( iDC . BEOpenPerWeek > iDC . BEOpen )
iDC . BEOpenPerWeek = iDC . BEOpen ;
iDC . BERecordedTillNow = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSRecordedTillNow ) ;
iDC . BERecordedTillNowInPercent = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSRecordedTillNowInPercent ) ;
2018-06-13 14:38:35 +02:00
SetKorridorStatus ( iDC ) ;
2017-09-14 19:03:26 +02:00
}
}
}
2022-12-28 23:57:47 +01:00
long endtime = DateTime . Now . Ticks ;
long diff = endtime - starttime ;
double secs = diff / ( double ) 10000000 ;
2017-09-14 19:03:26 +02:00
return lResult ;
}
2022-08-25 12:51:53 +02:00
private List < SupportConceptOverviewDC > GetSupportConceptAnalysisWithCategory ( IList < long > c2sOids , long? employeeOid , long? teamOid , long catOid , DateTime ? startDate , DateTime ? endDate , int? expiredMonths , bool showArchivedScs )
2021-06-22 20:55:30 +02:00
{
2023-02-15 20:13:03 +01:00
DateTime filterStartDate = startDate . HasValue ? startDate . Value : DateTime . MinValue ;
DateTime filterEndDate = endDate . HasValue ? endDate . Value . AddDays ( 1 ) : DateTime . MaxValue ;
2021-06-22 20:55:30 +02:00
var lResult = new List < SupportConceptOverviewDC > ( ) ;
foreach ( var iCb2Sc in DAOFactory . GenericDAO . GetAllActive < CostBearer2SupportConcept > ( ) )
{
var calc = PluginLoader . FindClass < Calculations > ( iCb2Sc . CostBearer . ID ) ? ? Calculations . GetInstance ( iCb2Sc . CostBearer . ID ) ;
foreach ( var scap in iCb2Sc . ApprovalPeriodList )
{
bool cont = AddToResult ( scap , catOid ) ;
if ( cont )
{
var iDC = new SupportConceptOverviewDC ( ) ;
iDC . ActivationType = iCb2Sc . SupportConcept . IsActive ;
if ( iDC . ActivationType = = ActivationTypeId . Active & & iCb2Sc . SupportConcept . Customer . IsActive ! = ActivationTypeId . Active )
{
iDC . ActivationType = iCb2Sc . SupportConcept . Customer . IsActive ;
}
if ( c2sOids ! = null )
{
if ( ! c2sOids . Contains ( iCb2Sc . Oid . Value ) )
{
cont = false ;
}
}
else
{
cont = ( showArchivedScs & & iDC . ActivationType ! = ActivationTypeId . Deleted ) | |
iDC . ActivationType = = ActivationTypeId . Active ;
if ( cont & & teamOid ! = null )
{
bool isRelatedToTeam = false ;
if ( iCb2Sc . SupportConcept . Customer . Team2CustomerList . Count = = 0 )
{
var team = DAOFactory . GenericDAO . LoadByID < Team > ( teamOid . Value ) ;
Dictionary < long , long > teamMemberOidDict = new Dictionary < long , long > ( ) ;
foreach ( var member in team . MemberList )
{
if ( ! teamMemberOidDict . ContainsKey ( member . Oid . Value ) )
{
teamMemberOidDict . Add ( member . Oid . Value , member . Oid . Value ) ;
}
//if (team.Leader != null && !teamMemberOidDict.ContainsKey(team.Leader.Oid.Value))
//{
// teamMemberOidDict.Add(team.Leader.Oid.Value, team.Leader.Oid.Value);
//}
}
foreach ( var e2c in iCb2Sc . SupportConcept . Customer . Employee2CustomerList )
{
if ( ! isRelatedToTeam )
{
if ( teamMemberOidDict . ContainsKey ( e2c . EmployeeOid . Value ) )
{
isRelatedToTeam = true ;
}
}
}
}
else
{
foreach ( var team2Customer in iCb2Sc . SupportConcept . Customer . Team2CustomerList )
{
if ( team2Customer . TeamOid = = teamOid )
{
isRelatedToTeam = true ;
}
}
}
if ( ! isRelatedToTeam )
{
cont = false ;
}
}
if ( cont & & employeeOid ! = null & & teamOid = = null )
{
bool isRelatedToEmployee = false ;
foreach ( var e2c in iCb2Sc . SupportConcept . Customer . Employee2CustomerList )
{
if ( ! isRelatedToEmployee )
{
if ( employeeOid . Value = = e2c . EmployeeOid . Value )
{
isRelatedToEmployee = true ;
}
}
}
if ( ! isRelatedToEmployee )
{
cont = false ;
}
}
if ( cont & & expiredMonths . HasValue )
{
cont = iCb2Sc . EndDate . HasValue & &
iCb2Sc . EndDate . Value < DateTime . Now . AddMonths ( expiredMonths . Value ) ;
}
}
2023-02-15 20:13:03 +01:00
DateTime minDt = filterStartDate ;
2021-06-22 20:55:30 +02:00
if ( cont )
{
iDC . CalculationDate = DateTime . Now . Date ;
iDC . RequestedStartDate = scap . StartDate ;
iDC . RequestedEndDate = scap . EndDate ;
iDC . SupportConceptOid = iCb2Sc . SupportConcept . Oid . Value ;
iDC . CostBearer2SupportConceptOid = iCb2Sc . Oid . Value ;
iDC . CostBearer = iCb2Sc . CostBearer . Organisation ! = null
? iCb2Sc . CostBearer . Organisation . Name
: string . Empty ;
iDC . CostBearerId = iCb2Sc . CostBearer . ID ;
iDC . CustomerOid = iCb2Sc . SupportConcept . Customer . Oid . Value ;
iDC . CustomerFirstName = iCb2Sc . SupportConcept . Customer . Person . FirstName ;
iDC . CustomerLastName = iCb2Sc . SupportConcept . Customer . Person . LastName ;
var costRates = iCb2Sc . CostBearer . CostRatePeriods . MapToNewDCs ( ) ;
iDC . ServiceUnit = costRates . GetCurrentlyValidRate ( CostRatePeriodType . MinutesPerServiceUnit ) ;
if ( iDC . ServiceUnit = = null )
{
iDC . ServiceUnit = new CostRatePeriodDC ( ) ;
iDC . ServiceUnit . CostRateType = CostRatePeriodType . MinutesPerServiceUnit ;
iDC . ServiceUnit . UnitName = "FLS" ;
iDC . ServiceUnit . CostRateValue = 60 ;
}
iDC . CurrentHourlyRate = costRates . GetCurrentlyValidRateValue ( CostRatePeriodType . HourlyRate ) ? ? 0 m ;
iDC . CurrentRateFactor = costRates . GetCurrentlyValidRateValue ( CostRatePeriodType . RateFactor ) ? ? 0 m ;
var c2sDc = iCb2Sc . MapToNewDC ( ) ;
var scapDc = scap . MapToNewDC ( ) ;
2022-08-25 12:51:53 +02:00
if ( scap . StartDate . HasValue & & scap . StartDate . Value > minDt )
2021-06-22 20:55:30 +02:00
{
2022-08-25 12:51:53 +02:00
minDt = scap . StartDate . Value . Date ;
2021-06-22 20:55:30 +02:00
}
2022-08-25 12:51:53 +02:00
else if ( scap . EndDate . HasValue & & scap . EndDate . Value > minDt )
2021-06-22 20:55:30 +02:00
{
2022-08-25 12:51:53 +02:00
minDt = scap . EndDate . Value . Date ;
2021-06-22 20:55:30 +02:00
}
2023-02-15 20:13:03 +01:00
iDC . FLSRecordedTillNow = BerechneGeleisteteStunden ( iCb2Sc , catOid , minDt , filterEndDate , calc ) ;
2021-06-22 20:55:30 +02:00
//var notBillableAbsenceTimes = calc.GetHoursNotBillableDueToAbsenceTimes(relDC, recordDCs,
// iCb2Sc.SupportConcept.Customer.GetAbsencesTimesNotBillableWholeWeeks(), false,
// false);
//var notBillableMoreThanApproved = calc.GetHoursNotBillableDueToMoreThanApproved(relDC, recordDCs,
// false, true);
iDC . FLSBilledTillNow = iDC . FLSRecordedTillNow ;
//- notBillableAbsenceTimes
//- notBillableMoreThanApproved;
2022-08-25 12:51:53 +02:00
decimal lDurationInWeeksTillNow = GetDurationInWeeksTillNow ( scap . StartDate , scap . EndDate , endDate ) ? ? 0 ;
2021-06-22 20:55:30 +02:00
decimal lDurationInWeeks = GetDurationInWeeks ( scap . StartDate , scap . EndDate ) ? ? 0 ;
if ( iCb2Sc . Status = = CostBearer2SupportConceptStatus . Approved )
{
iDC . IsApproved = true ;
if ( iCb2Sc . ApprovedStartDate ! = null & & iCb2Sc . ApprovedEndDate ! = null )
{
iDC . ApprovedStartDate = iCb2Sc . ApprovedStartDate . Value ;
iDC . ApprovedEndDate = iCb2Sc . ApprovedEndDate . Value ;
//lDurationInWeeks = Convert.ToDecimal((iDC.ApprovedEndDate.Value - iDC.ApprovedStartDate.Value).Days + 1) / 7;
//lCalcDate = lCalcDate > iCb2Sc.ApprovedEndDate
// ? iCb2Sc.ApprovedEndDate.Value.Date.AddDays(1)
// : lCalcDate;
//lDurationInWeeksTillNow = Convert.ToDecimal((lCalcDate - iCb2Sc.ApprovedStartDate.Value).Days) / 7m;
}
}
else
{
iDC . IsApproved = false ;
//if (iCb2Sc.RequestedStartDate != null && iCb2Sc.RequestedEndDate != null)
//{
//lDurationInWeeks = Convert.ToDecimal((iCb2Sc.RequestedEndDate.Value - iCb2Sc.RequestedStartDate.Value).Days + 1) / 7;
//lCalcDate = lCalcDate > iCb2Sc.RequestedEndDate
// ? iCb2Sc.RequestedEndDate.Value.Date
// : lCalcDate;
//lDurationInWeeksTillNow = Convert.ToDecimal((lCalcDate - iCb2Sc.RequestedStartDate.Value).Days) / 7m;
//}
}
2022-08-25 12:51:53 +02:00
BerechneBewilligteStunden ( calc , iDC , c2sDc , scapDc , endDate ) ;
2021-06-22 20:55:30 +02:00
//if (flsTotal.HasValue && lDurationInWeeks != 0)
//{
// iDC.FLSApprovedTillNow = flsTotal.Value * ((lDurationInWeeksTillNow + (1m / 7m)) / lDurationInWeeks);
//}
//else
//{
// iDC.FLSApprovedTillNow = iDC.FLSApprovedPerWeek * (lDurationInWeeksTillNow + (1m / 7m));
//}
if ( iDC . FLSApprovedSum < = 0 )
{
iDC . FLSRecordedTillNowInPercent = 0 ;
}
else
{
iDC . FLSRecordedTillNowInPercent = iDC . FLSRecordedTillNow / iDC . FLSApprovedSum * 100 ;
}
iDC . FLSDifferenceApprovedRecordedTillNow = iDC . FLSRecordedTillNow - iDC . FLSApprovedTillNow ;
if ( iDC . FLSApprovedTillNow < = 0 )
{
iDC . FLSDifferenceApprovedRecordedTillNowInPercent = 0 ;
}
else
{
iDC . FLSDifferenceApprovedRecordedTillNowInPercent =
iDC . FLSRecordedTillNow / iDC . FLSApprovedTillNow *
100 ;
}
iDC . FLSOpen = iDC . FLSApprovedSum - iDC . FLSRecordedTillNow ;
iDC . OpenWeeks = lDurationInWeeks - lDurationInWeeksTillNow ;
//TODO kostenträger spezifisch!? in Calculations verlagern!
iDC . OpenMonths = iDC . OpenWeeks / 4.34 m ;
if ( iDC . OpenWeeks < = 0 )
{
iDC . FLSOpenPerWeek = 0 ;
}
else
{
iDC . FLSOpenPerWeek = iDC . FLSOpen / iDC . OpenWeeks ;
}
iDC . WeeksTotal = lDurationInWeeks ;
if ( iDC . WeeksTotal ! = 0 )
{
iDC . DurationPercentage = ( lDurationInWeeksTillNow / iDC . WeeksTotal ) * 100 ;
}
lResult . Add ( iDC ) ;
iDC . BEApprovedPerWeek = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSApprovedPerWeek ) ;
iDC . BEApprovedSum = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSApprovedSum ) ;
iDC . BEApprovedTillNow = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSApprovedTillNow ) ;
iDC . BEBilledTillNow = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSBilledTillNow ) ;
iDC . BEDifferenceApprovedRecordedTillNow =
iDC . ServiceUnit . GetHoursInBE ( iDC . FLSDifferenceApprovedRecordedTillNow ) ;
iDC . BEDifferenceApprovedRecordedTillNowInPercent =
iDC . ServiceUnit . GetHoursInBE ( iDC . FLSDifferenceApprovedRecordedTillNowInPercent ) ;
iDC . BEOpen = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSOpen ) ;
iDC . BEOpenPerWeek = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSOpenPerWeek ) ;
if ( iDC . BEOpenPerWeek > iDC . BEOpen )
iDC . BEOpenPerWeek = iDC . BEOpen ;
iDC . BERecordedTillNow = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSRecordedTillNow ) ;
iDC . BERecordedTillNowInPercent = iDC . ServiceUnit . GetHoursInBE ( iDC . FLSRecordedTillNowInPercent ) ;
SetKorridorStatus ( iDC ) ;
}
}
}
2022-08-25 12:51:53 +02:00
2021-06-22 20:55:30 +02:00
}
return lResult ;
}
public virtual decimal? GetDurationInWeeksTillNow ( DateTime ? start , DateTime ? end , DateTime ? appointedDate )
{
if ( start ! = null & & end ! = null )
{
DateTime lCalcDate = ( appointedDate . HasValue & & appointedDate . Value < DateTime . Now . Date )
? appointedDate . Value
: DateTime . Now . Date ;
lCalcDate = lCalcDate > end
? end . Value . Date . AddDays ( 1 )
: lCalcDate ;
return Convert . ToDecimal ( ( lCalcDate - start . Value ) . Days ) / 7 m ;
}
return null ;
}
public virtual decimal? GetDurationInWeeks ( DateTime ? start , DateTime ? end )
{
if ( start ! = null & & end ! = null )
{
return Convert . ToDecimal ( ( end . Value - start . Value ) . Days + 1 ) / 7 ;
}
return null ;
}
2018-06-13 14:38:35 +02:00
public virtual void SetKorridorStatus ( SupportConceptOverviewDC iDc )
{
iDc . KorridorStatus = null ;
decimal minpercent = - 1 ;
decimal maxpercent = - 1 ;
decimal sumPerYear = GetAppovedBEPerYear ( iDc ) ;
sumPerYear = Math . Round ( sumPerYear ) ;
if ( sumPerYear = = 99 )
{
minpercent = 8900 m / 99 m ;
maxpercent = 10900 m / 99 m ;
}
else if ( sumPerYear = = 120 )
{
minpercent = 11000 m / 120 m ;
maxpercent = 13300 m / 120 m ;
}
else if ( sumPerYear = = 147 )
{
minpercent = 13400 m / 147 m ;
maxpercent = 17200 m / 147 m ;
}
else if ( sumPerYear = = 198 )
{
minpercent = 17300 m / 198 m ;
maxpercent = 24300 m / 198 m ;
}
else if ( sumPerYear = = 288 )
{
minpercent = 24400 m / 288 m ;
maxpercent = 31500 m / 288 m ;
}
else if ( sumPerYear = = 343 )
{
minpercent = 31600 m / 343 m ;
maxpercent = 39600 m / 343 m ;
}
if ( minpercent > 0 )
{
if ( minpercent < = iDc . BEDifferenceApprovedRecordedTillNowInPercent & &
iDc . BEDifferenceApprovedRecordedTillNowInPercent < = maxpercent )
{
iDc . KorridorStatus = "Innerhalb des Korridors" ;
iDc . KorridorStatusFarbe = "ForestGreen" ;
}
else
{
iDc . KorridorStatus = "Außerhalb des Korridors" ;
iDc . KorridorStatusFarbe = "Red" ;
}
2022-08-25 12:51:53 +02:00
2018-06-13 14:38:35 +02:00
}
}
public virtual decimal GetAppovedBEPerYear ( SupportConceptOverviewDC iDc )
{
decimal total = iDc . BEApprovedSum ;
DateTime ? start = iDc . ApprovedStartDate ;
if ( ! start . HasValue )
start = iDc . RequestedStartDate ;
DateTime ? end = iDc . ApprovedEndDate ;
if ( ! end . HasValue )
end = iDc . RequestedEndDate ;
if ( start . HasValue & & end . HasValue )
{
decimal days = ( decimal ) end . Value . Subtract ( start . Value ) . Days + 1 ;
decimal years = days / 365 m ;
if ( years ! = 0 )
{
return total / years ;
}
}
return 0 ;
2022-08-25 12:51:53 +02:00
2018-06-13 14:38:35 +02:00
}
2017-09-14 19:03:26 +02:00
public virtual void BerechneBewilligteStunden ( Calculations calc , SupportConceptOverviewDC iDc , SupportConceptCostBearerRelDC relDc , DateTime ? appointedDate )
{
iDc . FLSApprovedPerWeek = calc . GetApprovedHoursPerWeekAverage ( relDc , true ) ? ? 0 m ;
decimal? flsTotal = calc . GetApprovedHoursTotal ( relDc , true ) ;
iDc . FLSApprovedSum = flsTotal ? ? 0 m ;
var approvedTillNow = calc . GetApprovedHoursTillNow ( relDc , appointedDate ) ;
iDc . FLSApprovedTillNow = approvedTillNow ? ? 0 ;
}
2021-06-22 20:55:30 +02:00
public virtual void BerechneBewilligteStunden ( Calculations calc , SupportConceptOverviewDC iDc , SupportConceptCostBearerRelDC relDc , SupportConceptApprovalPeriodDC scap , DateTime ? appointedDate )
{
iDc . FLSApprovedPerWeek = GetApprovedHoursPerWeek ( calc , relDc , scap , true ) ? ? 0 m ;
2023-02-15 20:13:03 +01:00
decimal? flsTotal = 0 ;
decimal? approvedTillNow = 0 ;
if ( scap ! = null )
{
flsTotal = calc . GetApprovedHoursTotal ( scap , relDc . CostBearer . CostRatePeriods ) ;
approvedTillNow = calc . GetApprovedHoursTillNow ( scap , relDc . CostBearer . CostRatePeriods , appointedDate , relDc . CostBearer . IsCalculatingWithFactor ) ;
}
else
{
flsTotal = calc . GetApprovedHoursTotal ( relDc , true ) ;
approvedTillNow = calc . GetApprovedHoursTillNow ( relDc , appointedDate ) ;
}
2021-06-22 20:55:30 +02:00
iDc . FLSApprovedSum = flsTotal ? ? 0 m ;
iDc . FLSApprovedTillNow = approvedTillNow ? ? 0 ;
}
public virtual decimal? GetApprovedHoursPerWeek ( Calculations calc , SupportConceptCostBearerRelDC relDC , SupportConceptApprovalPeriodDC scap , bool useIsCalculationWithFactor )
{
if ( scap . StartDate . HasValue & & scap . EndDate . HasValue )
{
2022-08-25 12:51:53 +02:00
2021-06-22 20:55:30 +02:00
decimal? hoursPerWeek = calc . GetApprovedHoursPerWeek ( scap , relDC . CostBearer . CostRatePeriods ) ;
if ( useIsCalculationWithFactor )
hoursPerWeek = calc . ApplyIsCalculationWithFactor ( relDC , hoursPerWeek ) ;
return hoursPerWeek ;
2022-08-25 12:51:53 +02:00
2021-06-22 20:55:30 +02:00
}
return null ;
2022-08-25 12:51:53 +02:00
2021-06-22 20:55:30 +02:00
}
2022-11-09 09:44:24 +01:00
public virtual decimal BerechneGeleisteteStunden ( CostBearer2SupportConcept c2s , DateTime minDate , DateTime maxDate , Calculations calc )
2017-09-14 19:03:26 +02:00
{
2022-11-09 09:44:24 +01:00
var recordDCs = GetServiceRecordDCs ( c2s , minDate , maxDate ) ;
2017-09-14 19:03:26 +02:00
2022-11-09 09:44:24 +01:00
return calc . GetBillableDurationInMinutes ( recordDCs ) / 60 m ;
}
2017-09-14 19:03:26 +02:00
2022-11-09 09:44:24 +01:00
public virtual decimal BerechneGeleisteteStunden ( List < ServiceRecordDC > recordDCs , Calculations calc )
{
2025-01-28 13:39:31 +01:00
return calc . GetBillableDurationInMinutes ( recordDCs ) / 60 m ; // Hier werden Fehlkontakte nur zu 80% geholt. Die Zeit geht ja aber zu 100% ab
}
public virtual decimal BerechneGeleisteteStundenMit100ProzentFehlkontakten ( List < ServiceRecordDC > recordDCs , Calculations calc )
{
return calc . GetDocumentedDurationInMinutes ( recordDCs ) / 60 m ; // Hier werden Fehlkontakte nur zu 80% geholt. Die Zeit geht ja aber zu 100% ab
2017-09-14 19:03:26 +02:00
}
2022-11-09 09:44:24 +01:00
public virtual List < ServiceRecordDC > GetServiceRecordDCs ( CostBearer2SupportConcept c2s , DateTime minDate , DateTime maxDate )
{
2022-12-28 23:57:47 +01:00
if ( _cs2ServiceRecords ! = null & & _cs2ServiceRecords . Count > 0 )
{
if ( _cs2ServiceRecords . ContainsKey ( c2s . Oid . Value ) )
{
var list = _cs2ServiceRecords [ c2s . Oid . Value ] ;
return list . Where ( s = > s . Start > = minDate & & s . Start < maxDate ) . ToList ( ) ;
}
return new List < ServiceRecordDC > ( ) ;
}
//var serviceRecordsInSpan = c2s.ServiceRecords.Where(s => s.Start >= minDate && s.Start < maxDate);
2022-11-09 09:44:24 +01:00
var serviceRecordsInSpan = c2s . ServiceRecords . Where ( s = > s . Start > = minDate & & s . Start < maxDate ) ;
var dcList = new List < ServiceRecordDC > ( ) ;
foreach ( var sr in serviceRecordsInSpan )
{
dcList . Add ( CreateServiceRecordDC ( sr ) ) ;
}
return dcList ;
}
public virtual ServiceRecordDC CreateServiceRecordDC ( ServiceRecord sr )
{
var dc = new ServiceRecordDC ( ) ;
2022-12-28 23:57:47 +01:00
2022-11-09 09:44:24 +01:00
dc . ServiceRecordOid = sr . Oid ;
dc . ServiceRecordVersion = sr . Version ;
dc . Start = sr . Start ;
dc . End = sr . End ;
dc . DistanceInMeter = ( int? ) sr . DistanceInMeter ;
dc . DistanceInMeterDecimal = sr . DistanceInMeter ;
dc . Relevance = sr . Relevance ;
dc . Betrag = sr . Betrag ;
if ( sr . ServiceDescription ! = null )
{
dc . ServiceDescription = MapperFactory . ServiceDescriptionDC_ServiceDescription . MapToNewDC ( sr . ServiceDescription ) ;
}
dc . RoundedDuration = sr . RoundedDuration ;
dc . GroupEmployeeCount = sr . GroupEmployeeCount ;
dc . GroupPersonCount = sr . GroupPersonCount ;
dc . GroupRoundedDuration = sr . GroupRoundedDuration ;
dc . GroupOid = sr . GroupOid ;
return dc ;
}
2022-12-28 23:57:47 +01:00
public virtual ServiceRecordDC CreateServiceRecordDC2 ( object [ ] sqlRow , Dictionary < long , ServiceDescriptionDC > serviceDict )
{
try
{
var dc = new ServiceRecordDC ( ) ;
//DAOFactory.SearchDAO.GetSqlResult("SELECT Oid, Version, Start, End, DistanceInMeter, CostBearer2SupportConceptOid, Betrag, ServiceDescriptionOid, RoundedDuration, GroupEmployeeCount, GroupPersonCount, GroupRoundedDuration, GroupOid FROM servicerecord");
dc . ServiceRecordOid = ( long? ) sqlRow [ 0 ] ;
dc . ServiceRecordVersion = ( long? ) sqlRow [ 1 ] ;
dc . Start = ( DateTime ? ) sqlRow [ 2 ] ;
dc . End = ( DateTime ? ) sqlRow [ 3 ] ;
2023-02-15 20:13:03 +01:00
var test = sqlRow [ 4 ] ;
if ( test ! = null )
{
decimal meter = 0 ;
if ( Decimal . TryParse ( test . ToString ( ) , out meter ) )
{
dc . DistanceInMeterDecimal = meter ;
}
}
2022-12-28 23:57:47 +01:00
if ( dc . DistanceInMeterDecimal . HasValue )
{
dc . DistanceInMeter = ( int ) dc . DistanceInMeterDecimal ;
}
dc . CostBearer2SupportConceptOid = ( long? ) sqlRow [ 5 ] ;
dc . Betrag = ( decimal? ) sqlRow [ 6 ] ;
long? sdOid = ( long? ) sqlRow [ 7 ] ;
if ( sdOid . HasValue & & serviceDict . ContainsKey ( sdOid . Value ) )
{
dc . ServiceDescription = serviceDict [ sdOid . Value ] ;
}
dc . RoundedDuration = ( decimal ) sqlRow [ 8 ] ;
dc . GroupEmployeeCount = ( int? ) sqlRow [ 9 ] ;
dc . GroupPersonCount = ( int? ) sqlRow [ 10 ] ;
dc . GroupRoundedDuration = ( decimal? ) sqlRow [ 11 ] ;
dc . GroupOid = ( long? ) sqlRow [ 12 ] ;
return dc ;
}
catch ( Exception e )
{
throw ;
}
}
2022-11-09 09:44:24 +01:00
2021-06-22 20:55:30 +02:00
public virtual decimal BerechneGeleisteteStunden ( CostBearer2SupportConcept iCb2Sc , long catOid , DateTime minDate , DateTime maxDate , Calculations calc )
{
2022-08-25 12:51:53 +02:00
2021-06-22 20:55:30 +02:00
var recordDCs = ( from sr in iCb2Sc . ServiceRecords
2022-08-25 12:51:53 +02:00
where ( sr . Start > = minDate & & sr . Start < maxDate )
select MapperFactory . ServiceRecordDC_ServiceRecord . MapToNewDC ( sr ) ) . ToList ( ) ;
2021-06-22 20:55:30 +02:00
return calc . GetBillableDurationInMinutes ( recordDCs . Where ( r = > r . ServiceDescription . Category . ServiceCategoryOid = = catOid ) . ToList ( ) ) / 60 m ;
}
2017-09-14 19:03:26 +02:00
public virtual bool AddToResult ( CostBearer2SupportConcept c2s )
{
return true ;
}
2021-06-22 20:55:30 +02:00
public virtual bool AddToResult ( SupportConceptApprovalPeriod scap , long? catOid )
{
if ( ! catOid . HasValue | | scap . ServiceCategory = = null )
{
return true ;
}
if ( scap . ServiceCategory . Oid ! = catOid )
{
return false ;
}
return true ;
}
2017-09-14 19:03:26 +02:00
}
2022-12-28 23:57:47 +01:00
public class SupportConceptOverviewItem
{
public CostBearer2SupportConcept CostBearer2SupportConcept { get ; set ; }
2023-02-15 20:13:03 +01:00
public SupportConceptApprovalPeriod SupportConceptApprovalPeriod { get ; set ; }
2022-12-28 23:57:47 +01:00
public SupportConcept SupportConcept { get ; set ; }
}
2017-02-01 13:53:59 +01:00
}