Files
BeWoPlaner/Service/ServiceImplementations/AnalysisServiceImp.cs

1078 lines
41 KiB
C#
Raw Normal View History

2016-06-27 01:45:38 +02:00
using System;
using System.Collections.Generic;
using System.Data;
2020-08-17 16:52:25 +02:00
using System.IO;
2016-06-27 01:45:38 +02:00
using System.Linq;
using System.ServiceModel;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Service.Configuration;
using BeWo.Service.DCEntityMapper;
using BeWo.Service.Plugins;
using BeWo.Service.ServiceContracts;
using BS.Shared;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using BS.Shared.Extensions;
using BS.Shared.Services;
using Utils = BeWo.Service.Core.Utils;
using BS.Shared.DataContracts.Reports;
using BeWo.Service.Reporting;
namespace BeWo.Service.ServiceImplementations
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)]
public class AnalysisServiceImp : IAnalysisService
{
public CompactCustomerDC CreateCompactCustomerDC(Customer c)
{
var dc = new CompactCustomerDC();
dc.CustomerOid = c.Oid.Value;
dc.FirstName = c.Person.FirstName;
dc.LastName = c.Person.LastName;
dc.DateOfBirth = c.Person.DateOfBirth;
dc.ActivationType = c.IsActive;
dc.Sex = c.Person.Sex;
return dc;
}
2018-10-08 11:57:16 +02:00
2016-06-27 01:45:38 +02:00
public List<AccountingAnalysisDC> GetAccountingAnalysis(DateTimeSpan pSpan)
{
try
{
// return MapperFactory.AccountingTransactionDC_AccountingTransaction.MapToNewDCs(
// DAOFactory.SearchDAO.FindAccoutingTransactions(pSpan));
return null;
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
public List<FLSAnalysisRootDC> GetFLSAnalysis(FLSAnalysisConfigDC config)
{
if (config.ReportType == FLSReportType.Employee)
{
if (config.EmployeeOid.HasValue)
{
return GetEmployeeFLSAnalysisForEmployee(config);
}
return GetEmployeeFLSAnalysis(config);
}
if (config.ReportType == FLSReportType.Customer)
{
if (config.CustomerOid.HasValue)
{
return GetCustomerFLSAnalysisForCustomer(config);
}
return GetCustomerFLSAnalysis(config);
}
if (config.ReportType == FLSReportType.Costbearer)
{
return GetCostBearerFLSAnalysis(config);
}
return GetTeamFLSAnalysis(config);
}
public List<FLSAnalysisRootDC> GetCostBearerFLSAnalysis(DateTime? startDate, DateTime? endDate,
bool fetchServiceRecordNotice, List<long> goalOids)
{
var config = new FLSAnalysisConfigDC
{
StartDate = startDate,
EndDate = endDate,
FetchServiceRecordNotice = fetchServiceRecordNotice,
GoalOids = goalOids
};
return GetCostBearerFLSAnalysis(config);
}
public List<FLSAnalysisRootDC> GetCostBearerFLSAnalysis(FLSAnalysisConfigDC config)
{
try
{
2018-10-08 11:57:16 +02:00
var plugin = PluginLoader.FindClass<StundenuebersichtAuswertung>();
2016-06-27 01:45:38 +02:00
2018-10-08 11:57:16 +02:00
return plugin.GetCostBearerFLSAnalysis(config);
2016-06-27 01:45:38 +02:00
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
public List<FLSAnalysisRootDC> GetCustomerFLSAnalysis(DateTime? startDate, DateTime? endDate, bool fetchApprovedFLS,
bool fetchServiceRecordNotice, long? employeeOid, List<long> goalOids)
{
var config = new FLSAnalysisConfigDC
{
StartDate = startDate,
EndDate = endDate,
FetchApprovedFLS = fetchApprovedFLS,
FetchServiceRecordNotice = fetchServiceRecordNotice,
EmployeeOid = employeeOid,
GoalOids = goalOids
};
return GetCustomerFLSAnalysis(config);
}
public List<FLSAnalysisRootDC> GetCustomerFLSAnalysis(FLSAnalysisConfigDC config)
{
try
{
2018-10-08 11:57:16 +02:00
var plugin = PluginLoader.FindClass<StundenuebersichtAuswertung>();
2016-06-27 01:45:38 +02:00
2018-10-08 11:57:16 +02:00
return plugin.GetCustomerFLSAnalysis(config);
2016-06-27 01:45:38 +02:00
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
public List<FLSAnalysisRootDC> GetCustomerFLSAnalysisForCustomer(long customerOid, DateTime? startDate, DateTime? endDate, bool fetchApprovedFLS, bool fetchServiceRecordNotice, long? employeeOid, List<long> goalOids)
{
var config = new FLSAnalysisConfigDC
{
CustomerOid = customerOid,
StartDate = startDate,
EndDate = endDate,
FetchApprovedFLS = fetchApprovedFLS,
FetchServiceRecordNotice = fetchServiceRecordNotice,
EmployeeOid = employeeOid,
GoalOids = goalOids
};
return GetCustomerFLSAnalysisForCustomer(config);
}
public List<FLSAnalysisRootDC> GetCustomerFLSAnalysisForCustomer(FLSAnalysisConfigDC config)
{
try
{
2018-10-08 11:57:16 +02:00
var plugin = PluginLoader.FindClass<StundenuebersichtAuswertung>();
2016-06-27 01:45:38 +02:00
2018-10-08 11:57:16 +02:00
return plugin.GetCustomerFLSAnalysisForCustomer(config);
2016-06-27 01:45:38 +02:00
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
public List<FLSAnalysisRootDC> GetEmployeeFLSAnalysis(DateTime? startDate, DateTime? endDate, bool fetchApprovedFLS, bool fetchServiceRecordNotice, long? customerOid, List<long> goalOids, String text1, String text2, String text3, String text4, String text5)
{
var config = new FLSAnalysisConfigDC
{
StartDate = startDate,
EndDate = endDate,
FetchApprovedFLS = fetchApprovedFLS,
FetchServiceRecordNotice = fetchServiceRecordNotice,
CustomerOid = customerOid,
GoalOids = goalOids,
Text1 = text1,
Text2 = text2,
Text3 = text3,
Text4 = text4,
Text5 = text5
};
return GetEmployeeFLSAnalysis(config);
}
public List<FLSAnalysisRootDC> GetEmployeeFLSAnalysis(FLSAnalysisConfigDC config)
{
try
{
2018-10-08 11:57:16 +02:00
var plugin = PluginLoader.FindClass<StundenuebersichtAuswertung>();
2016-06-27 01:45:38 +02:00
2018-10-08 11:57:16 +02:00
return plugin.GetEmployeeFLSAnalysis(config);
// var settings = AppSettings.CreateSettings();
2016-06-27 01:45:38 +02:00
2018-10-08 11:57:16 +02:00
// var employees = config.ShouldAnalyzeArchivedEmployees ? DAOFactory.GenericDAO.GetAllActiveAndArchived<Employee>() : DAOFactory.GenericDAO.GetAllActive<Employee>();
2016-06-27 01:45:38 +02:00
2018-10-08 11:57:16 +02:00
//// (Archiviert) hinter dem Vornamen archivierter Mitarbeiter anzeigen?
////if(config.ShouldAnalyzeArchivedEmployees)
//// foreach (var emp in employees)
//// {
//// if (emp.IsActive.Equals(ActivationTypeId.Archived))
//// emp.Person.FirstName += " (Archiviert)";
//// }
// return (from iEmployee in employees where CheckEmployeeTextProperties(iEmployee, config.Text1, config.Text2, config.Text3, config.Text4, config.Text5) select CreateEmployeeFLSRootDC(iEmployee, config, settings.ShowRoundedDurationInEmployeeAnalysis)).ToList();
2016-06-27 01:45:38 +02:00
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
2018-10-08 11:57:16 +02:00
2016-06-27 01:45:38 +02:00
public List<FLSAnalysisRootDC> GetEmployeeFLSAnalysisForEmployee(long employeeOid, DateTime? startDate, DateTime? endDate, bool fetchApprovedFLS, bool fetchServiceRecordNotice, long? customerOid, List<long> goalOids)
{
var config = new FLSAnalysisConfigDC
{
EmployeeOid = employeeOid,
StartDate = startDate,
EndDate = endDate,
FetchApprovedFLS = fetchApprovedFLS,
FetchServiceRecordNotice = fetchServiceRecordNotice,
CustomerOid = customerOid,
GoalOids = goalOids
};
return GetEmployeeFLSAnalysisForEmployee(config);
}
public List<FLSAnalysisRootDC> GetEmployeeFLSAnalysisForEmployee(FLSAnalysisConfigDC config)
{
try
{
2018-10-08 11:57:16 +02:00
var plugin = PluginLoader.FindClass<StundenuebersichtAuswertung>();
2016-06-27 01:45:38 +02:00
2018-10-08 11:57:16 +02:00
return plugin.GetEmployeeFLSAnalysisForEmployee(config);
2016-06-27 01:45:38 +02:00
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
public List<FLSAnalysisRootDC> GetTeamFLSAnalysis(DateTime? startDate, DateTime? endDate, bool fetchServiceRecordNotice, List<long> goalOids, List<long> teamOids)
{
var config = new FLSAnalysisConfigDC
{
StartDate = startDate,
EndDate = endDate,
FetchServiceRecordNotice = fetchServiceRecordNotice,
GoalOids = goalOids,
TeamOids = teamOids
};
return GetTeamFLSAnalysis(config);
}
public List<FLSAnalysisRootDC> GetTeamFLSAnalysis(FLSAnalysisConfigDC config)
{
try
{
2018-10-08 11:57:16 +02:00
var plugin = PluginLoader.FindClass<StundenuebersichtAuswertung>();
2016-06-27 01:45:38 +02:00
2018-10-08 11:57:16 +02:00
return plugin.GetTeamFLSAnalysis(config);
2016-06-27 01:45:38 +02:00
}
catch (Exception e)
{
throw (BeWo.Service.Core.Utils.CreateBeWoFaultException(e));
}
}
public List<CompactSupportConceptDC> GetExpiringSupportConcepts(long? employeeOid, DateTime expiredUntil)
{
try
{
var hcg = PluginLoader.FindClass<HomeContentGenerator>();
return hcg.GetExpiringSupportConcepts(employeeOid, expiredUntil);
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
public List<LoginDC> GetLastLogins(string loginName)
{
try
{
return MapperFactory.LoginDC_Login.MapToNewDCs(DAOFactory.SearchDAO.FindLastLogins(loginName));
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
public List<FinanceOverviewItemDC> GetOutstandingReceivables(bool showOnlyOutstanding, bool showOnlyArchivedSCs)
{
return GetOutstandingReceivables(showOnlyOutstanding, showOnlyArchivedSCs, null, null);
}
public List<FinanceOverviewItemDC> GetOutstandingReceivables(bool showOnlyOutstanding, bool showOnlyArchivedSCs, DateTime? start, DateTime? end)
{
try
{
List<FinanceOverviewItemDC> result = new List<FinanceOverviewItemDC>();
var financeItemsByCb2scOid = new Dictionary<long, FinanceOverviewItemDC>();
IEnumerable<SupportConcept> scList = DAOFactory.SearchDAO.GetAllActiveAndArchivedSupportConcepts();
foreach (SupportConcept sc in scList)
{
foreach (CostBearer2SupportConcept cb2sc in sc.CostBearer2SupportConceptList)
{
if (!financeItemsByCb2scOid.ContainsKey(cb2sc.Oid.Value))
{
bool cont = true;
if (end.HasValue && cb2sc.StartDate.HasValue && cb2sc.StartDate > end)
{
cont = false;
}
if (cont)
{
DateTime? hilfeplanEnde = cb2sc.EndDate;
if (hilfeplanEnde.HasValue && cb2sc.SupportConcept.Customer.TerminationDate.HasValue &&
cb2sc.SupportConcept.Customer.TerminationDate < hilfeplanEnde)
{
hilfeplanEnde = cb2sc.SupportConcept.Customer.TerminationDate;
}
if (start.HasValue && hilfeplanEnde.HasValue && hilfeplanEnde < start)
{
cont = false;
}
}
if (cont)
{
FinanceOverviewItemDC dc = new FinanceOverviewItemDC();
result.Add(dc);
dc.SupportConcept = this.CreateCompactSupportConceptDC(sc);
dc.CostBearer = this.CreateCompactCostBearerDC(cb2sc);
dc.AmountTotal = this.GetTotalAmount(cb2sc);
financeItemsByCb2scOid.Add(cb2sc.Oid.Value, dc);
}
}
}
}
IEnumerable<AccountingTransaction> atList = DAOFactory.SearchDAO.GetAllAccountingTransactionsWithDetails();
foreach (AccountingTransaction at in atList)
{
if (at.CostBearer2SupportConcept == null ||
(at.CostBearer2SupportConcept.SupportConcept.IsActive != ActivationTypeId.Deleted &&
at.CostBearer2SupportConcept.SupportConcept.Customer.IsActive != ActivationTypeId.Deleted))
{
FinanceOverviewItemDC dc;
long oid = -1;
if (at.CostBearer2SupportConcept != null)
{
oid = at.CostBearer2SupportConcept.Oid.Value;
}
if (financeItemsByCb2scOid.ContainsKey(oid))
{
dc = financeItemsByCb2scOid[oid];
dc.AmountPaid += at.Amount;
2019-02-12 19:22:22 +01:00
//DateTime dt = at.BookingDate.Value;
//if (at.GueltigkeitsDatum.HasValue)
//{
// dt = at.GueltigkeitsDatum.Value;
//}
//if (start <= dt && dt <= end)
//{
// dc.AmountPaidInReportTimeSpan += at.Amount;
//}
2016-06-27 01:45:38 +02:00
//AccountingTransactionDC atdc = this.CreateAccountingTransactionDC(at);
//dc.AccountingTransactions.Add(atdc);
}
//else
//{
// dc = new FinanceOverviewItemDC();
// result.Add(dc);
// if (at.CostBearer2SupportConcept != null)
// {
// dc.SupportConcept =
// this.CreateCompactSupportConceptDC(at.CostBearer2SupportConcept.SupportConcept);
// dc.CostBearer = this.CreateCompactCostBearerDC(at.CostBearer2SupportConcept);
// dc.AmountTotal = this.GetTotalAmount(at.CostBearer2SupportConcept);
// }
// financeItemsByCb2scOid.Add(oid, dc);
//}
}
}
return result.OrderBy(
item =>
{
if (item.SupportConcept == null || item.SupportConcept.Customer == null)
{
return string.Empty;
}
return item.SupportConcept.Customer.LastName + ", " + item.SupportConcept.Customer.FirstName;
}).ToList();
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
public List<CompactPersonDC> GetPersonsHavingBirthday(DateTime birthdayUntil)
{
try
{
var hcg = PluginLoader.FindClass<HomeContentGenerator>();
return hcg.GetPersonsHavingBirthday(birthdayUntil);
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
2017-03-24 10:30:18 +01:00
public List<SupportConceptOverviewDC> GetSupportConceptAnalysis2(long? employeeOid, long? teamOid, DateTime? appointedDate, int? expiredMonths, bool showArchivedScs)
{
try
{
var ac = PluginLoader.FindClass<SupportConceptAnalysisCreator>();
return ac.GetSupportConceptAnalysis(null, employeeOid, teamOid, appointedDate, expiredMonths, showArchivedScs);
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
2016-06-27 01:45:38 +02:00
2017-03-24 10:30:18 +01:00
public List<SupportConceptOverviewDC> GetSupportConceptAnalysisWithC2SOids(IList<long> c2sOids, DateTime? appointedDate)
2016-06-27 01:45:38 +02:00
{
try
{
2017-02-01 13:53:59 +01:00
var ac = PluginLoader.FindClass<SupportConceptAnalysisCreator>();
2016-06-27 01:45:38 +02:00
2017-03-24 10:30:18 +01:00
return ac.GetSupportConceptAnalysis(c2sOids, null, null, appointedDate, null, true);
2016-06-27 01:45:38 +02:00
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
2017-02-10 11:08:38 +01:00
public List<SupportConceptOverviewDC> GetSupportConceptAnalysis(long? currentEmployeeOid,
bool showOnlyRelatedSCs,
2017-03-24 10:30:18 +01:00
bool showArchivedSCs,
2017-02-10 11:08:38 +01:00
DateTime? appointedDate)
{
2017-03-24 10:30:18 +01:00
return GetSupportConceptAnalysis2(currentEmployeeOid, null, appointedDate, null, showArchivedSCs);
2017-02-10 11:08:38 +01:00
}
2016-06-27 01:45:38 +02:00
public List<CompactSupportConceptDC> GetSupportConceptsWithConferenceDate(long? employeeOid, DateTime conferenceDateUntil)
{
try
{
2017-09-14 19:03:26 +02:00
var g = PluginLoader.FindClass<HomeContentGenerator>();
return g.GetSupportConceptsWithConferenceDate(employeeOid, conferenceDateUntil);
2016-06-27 01:45:38 +02:00
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
public List<TaskDC> GetTasksForEmployee(long employeeOid)
{
try
{
2017-06-07 15:23:30 +02:00
var g = PluginLoader.FindClass<HomeContentGenerator>();
return g.GetTasksForEmployee(employeeOid);
2016-06-27 01:45:38 +02:00
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
2017-06-07 15:23:30 +02:00
public List<TaskDC> GetTasksForEmployeeByDate(long employeeOid, DateTime date)
2016-06-27 01:45:38 +02:00
{
try
{
return MapperFactory.TaskDC_Task.MapToNewDCs(DAOFactory.SearchDAO.GetTasksForEmployeeByDate(employeeOid, date));
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
private AccountingTransactionDC CreateAccountingTransactionDC(AccountingTransaction at)
{
var dc = new AccountingTransactionDC();
dc.AccountingTransactionOid = at.Oid;
dc.AccountingTransactionVersion = at.Version;
dc.Amount = at.Amount;
dc.InsertedOn = at.InsTs;
dc.InsUser = at.InsUser;
var lCat = at.ValueList.SingleOrDefault(entry => entry.Entry.Type == ValueListEntryType.AccountingTransactionType);
if (lCat != null)
{
dc.Category = MapperFactory.ValueListEntryDC_ValueListEntry.MapToNewDC(lCat.Entry);
}
dc.Notice = at.Notice;
dc.BookingDate = at.BookingDate;
2017-02-01 13:53:59 +01:00
dc.ValidityDate = at.ValidityDate;
2016-06-27 01:45:38 +02:00
return dc;
}
private CompactCostBearerDC CreateCompactCostBearerDC(CostBearer2SupportConcept entity)
{
var dc = new CompactCostBearerDC();
if (entity.CostBearer != null && entity.CostBearer.Organisation != null)
{
var orgDC = new CompactOrganisationDC();
orgDC.Name = entity.CostBearer.Organisation.Name;
orgDC.OrganisationOid = entity.CostBearer.Organisation.Oid.Value;
dc.Organisation = orgDC;
dc.IsCalculatingWithFactor = entity.CostBearer.IsCalculatingWithFactor;
// dc.Street = entity.CostBearer.Organisation.Address.Street;
// dc.PostalCode = entity.CostBearer.Organisation.Address.PostalCode;
// dc.Town = entity.CostBearer.Organisation.Address.Town;
}
dc.CostBearer2SupportConceptOid = entity.Oid.Value;
dc.CustomerReferenceNumber = entity.CustomerReferenceNumber;
dc.RequestedStartDate = entity.RequestedStartDate;
dc.RequestedEndDate = entity.RequestedEndDate;
dc.ApprovedStartDate = entity.ApprovedStartDate;
dc.ApprovedEndDate = entity.ApprovedEndDate;
// dc.ApprovedFLS = entity.ApprovedFLS;
// dc.ApprovedFLSTotal = entity.ApprovedFLSTotal;
dc.SupportConceptStatus = entity.Status;
return dc;
}
private CompactSupportConceptDC CreateCompactSupportConceptDC(SupportConcept entity)
{
var dc = new CompactSupportConceptDC();
dc.SupportConceptOid = entity.Oid.Value;
dc.SupportConceptVersion = entity.Version.Value;
dc.ActivationType = entity.IsActive;
dc.ConferenceDate = entity.ConferenceDate;
dc.Customer = this.CreateCompactCustomerDC(entity.Customer);
return dc;
}
2018-10-08 11:57:16 +02:00
2016-06-27 01:45:38 +02:00
// private Dictionary<SupportConceptApprovalPeriod, DateTimeSpan> GetPeriodSpans(CostBearer2SupportConcept iCb2Sc)
// {
// var result = new Dictionary<SupportConceptApprovalPeriod, DateTimeSpan>();
// var ordered = iCb2Sc.ApprovalPeriodList.Where(i => i.EndDate.HasValue).OrderBy(i => i.EndDate).ToList();
// ordered.Add(iCb2Sc.ApprovalPeriodList.Single(i => !i.EndDate.HasValue));
// var currentStart = iCb2Sc.ApprovedStartDate.Value;
// foreach (var iPeriod in ordered)
// {
// var end = iPeriod.EndDate.HasValue
// ? iPeriod.EndDate.Value
// : iCb2Sc.ApprovedEndDate.Value;
// result.Add(iPeriod, new DateTimeSpan
// {
// StartDateTime = currentStart,
// EndDateTime = end
// });
// currentStart = end;
// }
// return result;
// }
private decimal GetTotalAmount(CostBearer2SupportConcept cb2sc)
{
var calc = PluginLoader.FindClass<Calculations>(cb2sc.CostBearer.ID) ?? Calculations.GetInstance(cb2sc.CostBearer.ID);
return calc.GetApprovedAmountTotal(cb2sc.MapToNewDC()) ?? 0m;
// decimal amount = 0;
// if (cb2sc != null)
// {
// CostBearer2SupportConceptData data = new CostBearer2SupportConceptData();
// data.RequestedStartDate = cb2sc.RequestedStartDate;
// data.RequestedEndDate = cb2sc.RequestedEndDate;
// data.ApprovedStartDate = cb2sc.ApprovedStartDate;
// data.ApprovedEndDate = cb2sc.ApprovedEndDate;
// data.MonthlyPayment = cb2sc.MonthlyPayment;
// //data.ApprovedFLS = cb2sc.ApprovedFLS;
// //data.ApprovedFLSTotal = cb2sc.ApprovedFLSTotal;
// if (cb2sc.CostBearer != null)
// {
// // data.IsCalculatingWithFactor = cb2sc.CostBearer.IsCalculatingWithFactor;
// }
// List<CostRate> crList = new List<CostRate>();
// foreach (var item in cb2sc.CostBearer.CostRatePeriods)
// {
// CostRate cr = new CostRate();
// cr.Amount = item.CostRateValue;
// cr.CostRateType = (CostRateType)item.CostRateType;
// cr.EndDate = item.EndDate;
// cr.StartDate = item.StartDate;
// crList.Add(cr);
// }
// data.CostRateList = crList;
// amount = CostRateCalculationService.GetAmountTotal(data);
// }
// return amount;
}
2018-10-08 11:57:16 +02:00
2016-06-27 01:45:38 +02:00
private ServiceRecordFLSOverviewDC CreateServiceRecordFLSOverviewDC(ServiceRecord sr, bool useGroupInfo, bool useRoundedDuration)
{
ServiceRecordFLSOverviewDC srDC = new ServiceRecordFLSOverviewDC();
srDC.Start = sr.Start;
srDC.End = sr.End;
srDC.DistanceInMeter = sr.DistanceInMeter;
srDC.Notice = sr.Notice;
2017-02-01 13:53:59 +01:00
srDC.Notice2 = sr.Notice2;
srDC.Notice3 = sr.Notice3;
srDC.Notice4 = sr.Notice4;
srDC.Notice5 = sr.Notice5;
2019-08-29 15:43:23 +02:00
srDC.InsertedOn = sr.InsTs;
srDC.InsUser = sr.InsUser;
2017-02-01 13:53:59 +01:00
if (useRoundedDuration)
2016-06-27 01:45:38 +02:00
{
srDC.RoundedDuration = sr.RoundedDuration;
}
else
{
srDC.RoundedDuration = (decimal)sr.End.Value.Subtract(sr.Start.Value).TotalMinutes;
}
if (sr.ServiceDescription != null)
srDC.ServiceDescription = MapperFactory.ServiceDescriptionDC_ServiceDescription.MapToNewDC(sr.ServiceDescription);
srDC.ServiceRecordOid = sr.Oid;
srDC.EmployeeOid = sr.EmployeeOid;
srDC.CustomerOid = sr.CustomerOid;
srDC.CostBearer2SupportConceptOid = sr.CostBearer2SupportConceptOid;
if (useGroupInfo)
{
srDC.GroupEmployeeCount = sr.GroupEmployeeCount;
srDC.GroupPersonCount = sr.GroupPersonCount;
srDC.GroupRoundedDuration = sr.GroupRoundedDuration;
srDC.GroupOid = sr.GroupOid;
}
return srDC;
}
public List<AuslastungAnalysisRootDC> GetAuslastungAnalysis(DateTime? startDate, DateTime? endDate, long? employeeOid, long? teamOid)
{
try
{
var lResult = new List<AuslastungAnalysisRootDC>();
var settings = AppSettings.CreateSettings();
AuslastungAnalysisRootDC root = new AuslastungAnalysisRootDC();
root.StartDate = startDate;
root.EndDate = endDate;
lResult.Add(root);
if (teamOid.HasValue)
{
Team team = DAOFactory.GenericDAO.LoadByID<Team>(teamOid.Value);
root.Team = MapperFactory.CompactTeamDC_Team.MapToNewDC(team);
foreach (var item in team.MemberList)
{
var a = CreateEmployeeAuslastung(item, startDate, endDate, settings.ShowRoundedDurationInEmployeeAnalysis);
root.EmployeeAnalysisList.Add(a);
root.TotalFLM += a.TotalFLM;
}
}
else if (employeeOid.HasValue)
{
var emp = DAOFactory.GenericDAO.LoadByID<Employee>(employeeOid.Value);
root.EmployeeAnalysisList.Add(CreateEmployeeAuslastung(emp, startDate, endDate, settings.ShowRoundedDurationInEmployeeAnalysis));
}
else
{
IList<Employee> list = DAOFactory.GenericDAO.GetAllActive<Employee>();
foreach (var emp in list)
{
root.EmployeeAnalysisList.Add(CreateEmployeeAuslastung(emp, startDate, endDate, settings.ShowRoundedDurationInEmployeeAnalysis));
}
}
if (root.EmployeeAnalysisList.Count > 1)
root.EmployeeAnalysisList.Sort((a, b) => (a.EmployeeLastName + ", " + a.EmployeeFirstName).CompareTo(b.EmployeeLastName + ", " + b.EmployeeFirstName));
return lResult;
}
catch (Exception e)
{
throw (BeWo.Service.Core.Utils.CreateBeWoFaultException(e));
}
}
private AuslastungAnalysisEmployeeDC CreateEmployeeAuslastung(Employee emp, DateTime? startDate, DateTime? endDate, bool useRoundedDuration)
{
AuslastungAnalysisEmployeeDC empDC = new AuslastungAnalysisEmployeeDC();
empDC.EmployeeOid = emp.Oid;
empDC.EmployeeFirstName = emp.Person.FirstName;
empDC.EmployeeLastName = emp.Person.LastName;
Contract contract = emp.LastContract;
if (contract != null && contract.WeeklyFLS.HasValue)
empDC.WeeklyTotalHours = contract.WeeklyTotalHours;
if (contract != null && contract.MonthlyTotalHours.HasValue)
empDC.MonthlyTotalHours = contract.MonthlyTotalHours;
2016-06-27 01:45:38 +02:00
IList<ServiceRecord> serviceRecords = null;
if (startDate != null && endDate != null)
{
var span = new DateTimeSpan();
span.StartDateTime = startDate.Value;
span.EndDateTime = endDate.Value;
serviceRecords = DAOFactory.SearchDAO.FindEmployeeServiceRecords(emp.Oid.Value, span, null, null);
}
else
{
serviceRecords = emp.ServiceRecordList;
}
//supportconcepts by costbearer2supportconceptoid
Dictionary<long, AuslastungAnalysisSupportConceptDC> supportConceptDict = new Dictionary<long, AuslastungAnalysisSupportConceptDC>();
if (emp.Employee2CustomerList != null)
{
foreach (Employee2Customer e2c in emp.Employee2CustomerList)
{
bool isMainAttendant = false;
if (e2c.ValueList.Count > 0)
{
SystemEntryID? id = e2c.ValueList[0].Entry.SystemEntryID;
if (id.HasValue && id.Value == SystemEntryID.EmployeeRoleMainAttendant)
isMainAttendant = true;
}
if (isMainAttendant && e2c.Customer != null)
{
if (e2c.Customer.IsActive != ActivationTypeId.Deleted && e2c.Customer.SupportConcepts != null)
{
foreach (SupportConcept sc in e2c.Customer.SupportConcepts)
{
if (sc.IsActive != ActivationTypeId.Deleted && sc.CostBearer2SupportConceptList != null)
{
foreach (CostBearer2SupportConcept cb2sc in sc.CostBearer2SupportConceptList)
{
bool inTimeRange = true;
if (startDate.HasValue && endDate.HasValue)
{
DateTime? start = cb2sc.ApprovedStartDate;
if (!start.HasValue)
start = cb2sc.RequestedStartDate;
DateTime? end = cb2sc.ApprovedEndDate;
if (!end.HasValue)
end = cb2sc.RequestedEndDate;
if (start.HasValue && end.HasValue)
{
if (start > endDate || end < startDate)
{
inTimeRange = false;
}
}
}
if (inTimeRange && !supportConceptDict.ContainsKey(cb2sc.Oid.Value))
{
//if (scStartDate == null || scEndDate == null || ())
AuslastungAnalysisSupportConceptDC scDC = new AuslastungAnalysisSupportConceptDC();
scDC.ServiceRecords = new List<ServiceRecordFLSOverviewDC>();
supportConceptDict.Add(cb2sc.Oid.Value, scDC);
CompactCustomerDC cdc = CreateCompactCustomerDC(e2c.Customer);
scDC.CustomerOid = cdc.CustomerOid;
scDC.CustomerFirstName = cdc.FirstName;
scDC.CustomerLastName = cdc.LastName;
scDC.CostBearer2SupportConcept = MapperFactory.SupportConceptCostBearerRelDC_CostBearer2SupportConcept.MapToNewDC(cb2sc);
empDC.SupportConceptAnalysisList.Add(scDC);
}
else
{
//AuslastungAnalysisSupportConceptDC scDCTemp = new AuslastungAnalysisSupportConceptDC();
//scDCTemp.Customer = CreateCompactCustomerDC(e2c.Customer);
//scDCTemp.CostBearer2SupportConcept = MapperFactory.SupportConceptCostBearerRelDC_CostBearer2SupportConcept.MapToNewDC(cb2sc);
//AuslastungAnalysisSupportConceptDC scDC2 = supportConceptDict[cb2sc.Oid.Value];
}
}
}
}
}
}
}
}
AuslastungAnalysisSupportConceptDC otherDC = null;
Dictionary<long, ServiceRecord> groupBookingDict = new Dictionary<long, ServiceRecord>();
foreach (ServiceRecord sr in serviceRecords)
{
bool cont = true;
if (sr.Customer != null && sr.Customer.IsActive == ActivationTypeId.Deleted)
cont = false;
if (cont && sr.SupportConcept != null && sr.SupportConcept.IsActive == ActivationTypeId.Deleted)
cont = false;
if (cont && sr.GroupOid != null && groupBookingDict.ContainsKey(sr.GroupOid.Value))
cont = false;
if (cont)
{
ServiceRecordFLSOverviewDC srDC = CreateServiceRecordFLSOverviewDC(sr, true, useRoundedDuration);
if (srDC.GroupOid != null)
{
groupBookingDict.Add(sr.GroupOid.Value, sr);
}
if (sr.CostBearer2SupportConceptOid != null && sr.CustomerOid != null)
{
AuslastungAnalysisSupportConceptDC scDC = null;
if (supportConceptDict.ContainsKey(sr.CostBearer2SupportConceptOid.Value))
{
scDC = supportConceptDict[sr.CostBearer2SupportConceptOid.Value];
//if (scDC == null)
//{
//scDC = new AuslastungAnalysisSupportConceptDC();
//supportConceptDict.Add(sr.CostBearer2SupportConceptOid.Value, scDC);
//Customer c = sr.Customer;
//if (c != null)
//{
// scDC.Customer = CreateCompactCustomerDC(c);
//}
//CostBearer2SupportConcept c2s = sr.CostBearer2SupportConcept;
//if (c2s != null)
//{
// scDC.CostBearer2SupportConcept = MapperFactory.SupportConceptCostBearerRelDC_CostBearer2SupportConcept.MapToNewDC(c2s);
//}
//empDC.SupportConceptAnalysisList.Add(scDC);
//}
scDC.ServiceRecords.Add(srDC);
}
}
else
{
if (otherDC == null)
{
otherDC = new AuslastungAnalysisSupportConceptDC();
otherDC.ServiceRecords = new List<ServiceRecordFLSOverviewDC>();
}
otherDC.ServiceRecords.Add(srDC);
}
}
}
empDC.SupportConceptAnalysisList.Sort((a, b) => (a.CustomerLastName + ", " + a.CustomerFirstName).CompareTo(b.CustomerLastName + ", " + b.CustomerFirstName));
if (otherDC != null)
empDC.SupportConceptAnalysisList.Add(otherDC);
return empDC;
}
public List<AnnualReportDC> CreateAnnualReport(long? costbearerOid, long? teamOid, long? customerCareTypeValueListEntryOid, DateTime startDate, DateTime endDate)
{
try
{
AnnualReportFactory factory = null;
CostBearer cb = null;
if (costbearerOid.HasValue)
{
cb = DAOFactory.GenericDAO.LoadByID<CostBearer>(costbearerOid.Value);
factory = PluginLoader.FindClass<AnnualReportFactory>(cb.ID) ?? AnnualReportFactory.GetInstance(cb.ID);
}
if (factory == null)
{
factory = PluginLoader.FindClass<AnnualReportFactory>() ?? new AnnualReportFactory();
}
return factory.CreateAnnualReport(cb, teamOid, customerCareTypeValueListEntryOid, startDate, endDate);
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
public static bool IsServiceRecordActive(ServiceRecord sr)
{
if (sr.Customer != null && sr.Customer.IsActive == ActivationTypeId.Deleted)
{
return false;
}
if (sr.SupportConcept != null && sr.SupportConcept.IsActive == ActivationTypeId.Deleted)
{
return false;
}
return true;
}
public static IList<ServiceRecord> FilterActiveServiceRecords(IList<ServiceRecord> records)
{
return records.Where(sr => IsServiceRecordActive(sr)).ToList();
}
2017-02-01 13:53:59 +01:00
public static IList<ServiceRecord> FilterGroupServiceRecords(IList<ServiceRecord> records)
{
Dictionary<long, bool> groupBookingDict = new Dictionary<long, bool>();
IList<ServiceRecord> groupFilteredRecords = new List<ServiceRecord>();
foreach (var item in records)
{
if (!item.GroupOid.HasValue || !groupBookingDict.ContainsKey(item.GroupOid.Value))
{
groupFilteredRecords.Add(item);
if (item.GroupOid.HasValue)
{
groupBookingDict.Add(item.GroupOid.Value, true);
}
}
}
return groupFilteredRecords;
}
2016-06-27 01:45:38 +02:00
public AccountingReportDC CreateAccountingReport(DateTime start, DateTime end)
{
var report = new AccountingReportDC
{
AccountingReportRows = new List<AccountingReportRowDC>(),
StartDate = start,
EndDate = end
};
var span = new DateTimeSpan {StartDate = start, EndDate = end.AddDays(1).AddTicks(-1)};
var serviceRecords = DAOFactory.SearchDAO.FindServiceRecordsInSpan(span, null);
var rowDict = new Dictionary<long, AccountingReportRowDC>();
foreach (var serviceRecord in serviceRecords)
{
if (serviceRecord.CostBearer2SupportConceptOid.HasValue)
{
AccountingReportRowDC row = null;
if (rowDict.ContainsKey(serviceRecord.CostBearer2SupportConceptOid.Value))
{
row = rowDict[serviceRecord.CostBearer2SupportConceptOid.Value];
}
else
{
row = new AccountingReportRowDC();
rowDict.Add(serviceRecord.CostBearer2SupportConceptOid.Value, row);
row.Customer = MapperFactory.CompactCustomerDC_Customer.MapToNewDC(serviceRecord.Customer);
row.SupportConceptStart = serviceRecord.SupportConcept.StartDate;
row.SupportConceptEnd = serviceRecord.SupportConcept.EndDate;
CostBearer2SupportConcept cb2sc = serviceRecord.CostBearer2SupportConcept;
var costBearer = new CompactCostBearerDC
{
IsCalculatingWithFactor = cb2sc.CostBearer.IsCalculatingWithFactor,
CostBearerID = cb2sc.CostBearer.ID,
CostBearerOid = cb2sc.CostBearer.Oid.Value,
CostBearer2SupportConceptOid = cb2sc.Oid.Value,
SupportConceptStatus = cb2sc.Status,
RequestedStartDate = cb2sc.RequestedStartDate,
RequestedEndDate = cb2sc.RequestedEndDate,
ApprovedStartDate = cb2sc.ApprovedStartDate,
ApprovedEndDate = cb2sc.ApprovedEndDate,
Organisation =
MapperFactory.CompactOrganisationDC_Organisation.MapToNewDC(
cb2sc.CostBearer.Organisation)
};
row.CostBearer = costBearer;
report.AccountingReportRows.Add(row);
}
row.TotalDuration += serviceRecord.RoundedDuration;
}
}
return report;
}
}
}