using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.ServiceModel; using System.Threading; 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; } public List GetAccountingAnalysis(DateTimeSpan pSpan) { try { // return MapperFactory.AccountingTransactionDC_AccountingTransaction.MapToNewDCs( // DAOFactory.SearchDAO.FindAccoutingTransactions(pSpan)); return null; } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public List 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 GetCostBearerFLSAnalysis(DateTime? startDate, DateTime? endDate, bool fetchServiceRecordNotice, List goalOids) { var config = new FLSAnalysisConfigDC { StartDate = startDate, EndDate = endDate, FetchServiceRecordNotice = fetchServiceRecordNotice, GoalOids = goalOids }; return GetCostBearerFLSAnalysis(config); } public List GetCostBearerFLSAnalysis(FLSAnalysisConfigDC config) { try { var plugin = PluginLoader.FindClass(); return plugin.GetCostBearerFLSAnalysis(config); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public List GetCustomerFLSAnalysis(DateTime? startDate, DateTime? endDate, bool fetchApprovedFLS, bool fetchServiceRecordNotice, long? employeeOid, List goalOids) { var config = new FLSAnalysisConfigDC { StartDate = startDate, EndDate = endDate, FetchApprovedFLS = fetchApprovedFLS, FetchServiceRecordNotice = fetchServiceRecordNotice, EmployeeOid = employeeOid, GoalOids = goalOids }; return GetCustomerFLSAnalysis(config); } public List GetCustomerFLSAnalysis(FLSAnalysisConfigDC config) { try { var plugin = PluginLoader.FindClass(); return plugin.GetCustomerFLSAnalysis(config); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public List GetCustomerFLSAnalysisForCustomer(long customerOid, DateTime? startDate, DateTime? endDate, bool fetchApprovedFLS, bool fetchServiceRecordNotice, long? employeeOid, List goalOids) { var config = new FLSAnalysisConfigDC { CustomerOid = customerOid, StartDate = startDate, EndDate = endDate, FetchApprovedFLS = fetchApprovedFLS, FetchServiceRecordNotice = fetchServiceRecordNotice, EmployeeOid = employeeOid, GoalOids = goalOids }; return GetCustomerFLSAnalysisForCustomer(config); } public List GetCustomerFLSAnalysisForCustomer(FLSAnalysisConfigDC config) { try { var plugin = PluginLoader.FindClass(); return plugin.GetCustomerFLSAnalysisForCustomer(config); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public List GetEmployeeFLSAnalysis(DateTime? startDate, DateTime? endDate, bool fetchApprovedFLS, bool fetchServiceRecordNotice, long? customerOid, List 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 GetEmployeeFLSAnalysis(FLSAnalysisConfigDC config) { try { var plugin = PluginLoader.FindClass(); return plugin.GetEmployeeFLSAnalysis(config); // var settings = AppSettings.CreateSettings(); // var employees = config.ShouldAnalyzeArchivedEmployees ? DAOFactory.GenericDAO.GetAllActiveAndArchived() : DAOFactory.GenericDAO.GetAllActive(); //// (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(); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public List GetEmployeeFLSAnalysisForEmployee(long employeeOid, DateTime? startDate, DateTime? endDate, bool fetchApprovedFLS, bool fetchServiceRecordNotice, long? customerOid, List goalOids) { var config = new FLSAnalysisConfigDC { EmployeeOid = employeeOid, StartDate = startDate, EndDate = endDate, FetchApprovedFLS = fetchApprovedFLS, FetchServiceRecordNotice = fetchServiceRecordNotice, CustomerOid = customerOid, GoalOids = goalOids }; return GetEmployeeFLSAnalysisForEmployee(config); } public List GetEmployeeFLSAnalysisForEmployee(FLSAnalysisConfigDC config) { try { var plugin = PluginLoader.FindClass(); return plugin.GetEmployeeFLSAnalysisForEmployee(config); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public List GetTeamFLSAnalysis(DateTime? startDate, DateTime? endDate, bool fetchServiceRecordNotice, List goalOids, List teamOids) { var config = new FLSAnalysisConfigDC { StartDate = startDate, EndDate = endDate, FetchServiceRecordNotice = fetchServiceRecordNotice, GoalOids = goalOids, TeamOids = teamOids }; return GetTeamFLSAnalysis(config); } public List GetTeamFLSAnalysis(FLSAnalysisConfigDC config) { try { var plugin = PluginLoader.FindClass(); return plugin.GetTeamFLSAnalysis(config); } catch (Exception e) { throw (BeWo.Service.Core.Utils.CreateBeWoFaultException(e)); } } public List GetExpiringSupportConcepts(long? employeeOid, DateTime expiredUntil) { try { var hcg = PluginLoader.FindClass(); return hcg.GetExpiringSupportConcepts(employeeOid, expiredUntil); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public List GetLastLogins(string loginName) { try { return MapperFactory.LoginDC_Login.MapToNewDCs(DAOFactory.SearchDAO.FindLastLogins(loginName)); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public List GetOutstandingReceivables(bool showOnlyOutstanding, bool showOnlyArchivedSCs) { return GetOutstandingReceivables(showOnlyOutstanding, showOnlyArchivedSCs, null, null); } public List GetOutstandingReceivables(bool showOnlyOutstanding, bool showOnlyArchivedSCs, DateTime? start, DateTime? end) { try { List result = new List(); var financeItemsByCb2scOid = new Dictionary(); IEnumerable 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 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; //DateTime dt = at.BookingDate.Value; //if (at.GueltigkeitsDatum.HasValue) //{ // dt = at.GueltigkeitsDatum.Value; //} //if (start <= dt && dt <= end) //{ // dc.AmountPaidInReportTimeSpan += at.Amount; //} //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 GetPersonsHavingBirthday(DateTime birthdayUntil) { try { var hcg = PluginLoader.FindClass(); return hcg.GetPersonsHavingBirthday(birthdayUntil); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public List GetSupportConceptAnalysis2(long? employeeOid, long? teamOid, DateTime? appointedDate, int? expiredMonths, bool showArchivedScs) { try { var ac = PluginLoader.FindClass(); return ac.GetSupportConceptAnalysis(null, employeeOid, teamOid, appointedDate, expiredMonths, showArchivedScs); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public List GetSupportConceptAnalysis3(long? employeeOid, long? teamOid, long? catOid, DateTime? appointedDate, int? expiredMonths, bool showArchivedScs) { try { var ac = PluginLoader.FindClass(); return ac.GetSupportConceptAnalysis2(null, employeeOid, teamOid, catOid, appointedDate, expiredMonths, showArchivedScs); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public List GetSupportConceptAnalysisWithC2SOids(IList c2sOids, DateTime? appointedDate) { try { var ac = PluginLoader.FindClass(); return ac.GetSupportConceptAnalysis(c2sOids, null, null, appointedDate, null, true); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public List GetSupportConceptAnalysis(long? currentEmployeeOid, bool showOnlyRelatedSCs, bool showArchivedSCs, DateTime? appointedDate) { return GetSupportConceptAnalysis2(currentEmployeeOid, null, appointedDate, null, showArchivedSCs); } public List GetSupportConceptsWithConferenceDate(long? employeeOid, DateTime conferenceDateUntil) { try { var g = PluginLoader.FindClass(); return g.GetSupportConceptsWithConferenceDate(employeeOid, conferenceDateUntil); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public List GetTasksForEmployee(long employeeOid) { try { var g = PluginLoader.FindClass(); return g.GetTasksForEmployee(employeeOid); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public List GetTasksForEmployeeByDate(long employeeOid, DateTime date) { 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; dc.ValidityDate = at.ValidityDate; 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; } // private Dictionary GetPeriodSpans(CostBearer2SupportConcept iCb2Sc) // { // var result = new Dictionary(); // 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(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 crList = new List(); // 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; } 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; srDC.Notice2 = sr.Notice2; srDC.Notice3 = sr.Notice3; srDC.Notice4 = sr.Notice4; srDC.Notice5 = sr.Notice5; srDC.InsertedOn = sr.InsTs; srDC.InsUser = sr.InsUser; if (useRoundedDuration) { 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 GetAuslastungAnalysis(DateTime? startDate, DateTime? endDate, long? employeeOid, long? teamOid) { try { var lResult = new List(); 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(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(employeeOid.Value); root.EmployeeAnalysisList.Add(CreateEmployeeAuslastung(emp, startDate, endDate, settings.ShowRoundedDurationInEmployeeAnalysis)); } else { IList list = DAOFactory.GenericDAO.GetAllActive(); 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; IList 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 supportConceptDict = new Dictionary(); 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(); 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 groupBookingDict = new Dictionary(); 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(); } 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 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(costbearerOid.Value); factory = PluginLoader.FindClass(cb.ID) ?? AnnualReportFactory.GetInstance(cb.ID); } if (factory == null) { factory = PluginLoader.FindClass() ?? 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 FilterActiveServiceRecords(IList records) { return records.Where(sr => IsServiceRecordActive(sr)).ToList(); } public static IList FilterGroupServiceRecords(IList records) { Dictionary groupBookingDict = new Dictionary(); IList groupFilteredRecords = new List(); 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; } public AccountingReportDC CreateAccountingReport(DateTime start, DateTime end) { var report = new AccountingReportDC { AccountingReportRows = new List(), 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(); 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; } } }