Files
BeWoPlaner/Service/Plugins/StundenuebersichtAuswertung.cs
Christian 6c92c8eacc cb
2019-08-29 15:43:23 +02:00

759 lines
33 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using BeWo.Data;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Service.Configuration;
using BeWo.Service.Core;
using BeWo.Service.DCEntityMapper;
using BeWo.Service.MessageContracts;
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 = BS.Shared.Core.Utils;
namespace BeWo.Service.Plugins
{
public class StundenuebersichtAuswertung : AbstractIDSpecificDefaultClass<StundenuebersichtAuswertung>
{
public virtual List<FLSAnalysisRootDC> GetEmployeeFLSAnalysis(FLSAnalysisConfigDC config)
{
var settings = AppSettings.CreateSettings();
var employees = config.ShouldAnalyzeArchivedEmployees ? DAOFactory.GenericDAO.GetAllActiveAndArchived<Employee>() : DAOFactory.GenericDAO.GetAllActive<Employee>();
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();
}
public virtual List<FLSAnalysisRootDC> GetEmployeeFLSAnalysisForEmployee(FLSAnalysisConfigDC config)
{
var lResult = new List<FLSAnalysisRootDC>();
var settings = AppSettings.CreateSettings();
var emp = DAOFactory.GenericDAO.LoadByID<Employee>(config.EmployeeOid.Value);
lResult.Add(CreateEmployeeFLSRootDC(emp, config, settings.ShowRoundedDurationInEmployeeAnalysis));
return lResult;
}
public virtual List<FLSAnalysisRootDC> GetCustomerFLSAnalysisForCustomer(FLSAnalysisConfigDC config)
{
var lResult = new List<FLSAnalysisRootDC>();
var customer = DAOFactory.GenericDAO.LoadByID<Customer>(config.CustomerOid.Value);
lResult.Add(this.CreateCustomerFLSOverviewDC(customer, config));
return lResult;
}
public virtual List<FLSAnalysisRootDC> GetCustomerFLSAnalysis(FLSAnalysisConfigDC config)
{
var lResult = new List<FLSAnalysisRootDC>();
foreach (var iCustomer in DAOFactory.GenericDAO.GetAllActiveAndArchived<Customer>())
{
lResult.Add(this.CreateCustomerFLSOverviewDC(iCustomer, config));
}
return lResult;
}
public virtual FLSAnalysisRootDC CreateCustomerFLSOverviewDC(Customer customer, FLSAnalysisConfigDC config)
{
var rootDC = new FLSAnalysisRootDC();
rootDC.Groups = new List<FLSAnalysisGroupDC>();
rootDC.Customer = MapperFactory.CompactCustomerDC_Customer.MapToNewDC(customer);
IList<ServiceRecord> serviceRecords = null;
if (config.StartDate != null && config.EndDate != null)
{
var span = new DateTimeSpan();
span.StartDateTime = config.StartDate.Value;
span.EndDateTime = config.EndDate.Value;
serviceRecords = DAOFactory.SearchDAO.FindCustomerServiceRecords(customer.Oid.Value, span, null, config.ShowOnlyMarker ? ServiceRecordTypeId.Content : (ServiceRecordTypeId?)null, false);
}
else
{
serviceRecords = customer.ServiceRecordList;
}
Dictionary<long, FLSAnalysisGroupDC> flsGroupDict = new Dictionary<long, FLSAnalysisGroupDC>();
Dictionary<string, SupportConceptFLSOverviewDC> supportConceptOverviewDict = new Dictionary<string, SupportConceptFLSOverviewDC>();
bool createGroups = AllowCustomerAnalysis(customer, config, serviceRecords);
if (createGroups)
{
Dictionary<long, ServiceRecord> groupBookingDict = new Dictionary<long, ServiceRecord>();
foreach (ServiceRecord sr in serviceRecords)
{
bool cont = true;
if (sr.Employee != null && sr.Employee.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)
{
cont = this.IsServiceRecordForGoal(sr, config.GoalOids);
}
if (cont && config.ServiceDescriptionOids != null && config.ServiceDescriptionOids.Count > 0 && !config.ServiceDescriptionOids.Contains(sr.ServiceDescription.Oid.Value))
{
cont = false;
}
if (cont && config.ShowOnlyMarker && (!sr.ServiceRecordType.HasValue || sr.ServiceRecordType.Value != ServiceRecordTypeId.Content))
{
cont = false;
}
if (cont)
{
ServiceRecordFLSOverviewDC srDC = CreateServiceRecordFLSOverviewDC(sr, true, true);
if (sr.GroupOid != null)
{
groupBookingDict.Add(sr.GroupOid.Value, sr);
}
if (sr.CostBearer2SupportConceptOid != null && sr.EmployeeOid != null)
{
FLSAnalysisGroupDC groupDC = null;
if (flsGroupDict.ContainsKey(sr.EmployeeOid.Value))
{
groupDC = flsGroupDict[sr.EmployeeOid.Value];
}
if (groupDC == null)
{
groupDC = new FLSAnalysisGroupDC();
groupDC.SupportConcepts = new List<SupportConceptFLSOverviewDC>();
flsGroupDict.Add(sr.EmployeeOid.Value, groupDC);
Employee e = sr.Employee;
if (e != null)
{
groupDC.Employee = this.CreateCompactEmployeeDC(e);
}
rootDC.Groups.Add(groupDC);
}
SupportConceptFLSOverviewDC scDC = null;
if (supportConceptOverviewDict.ContainsKey(sr.EmployeeOid.Value + "_" + sr.CostBearer2SupportConceptOid.Value))
{
scDC = supportConceptOverviewDict[sr.EmployeeOid.Value + "_" + sr.CostBearer2SupportConceptOid.Value];
}
if (scDC == null)
{
scDC = new SupportConceptFLSOverviewDC();
supportConceptOverviewDict.Add(sr.EmployeeOid.Value + "_" + sr.CostBearer2SupportConceptOid.Value, scDC);
CostBearer2SupportConcept c2s = sr.CostBearer2SupportConcept;
if (c2s != null)
{
scDC.SupportConcept2CostBearer = MapperFactory.SupportConceptCostBearerRelDC_CostBearer2SupportConcept.MapToNewDC(c2s);
}
groupDC.SupportConcepts.Add(scDC);
}
scDC.ServiceRecords.Add(srDC);
}
}
}
}
return rootDC;
}
public virtual bool AllowCustomerAnalysis(Customer customer, FLSAnalysisConfigDC config, IList<ServiceRecord> serviceRecords)
{
bool allow = true;
if (config.EmployeeOid != null)
{
allow = false;
foreach (ServiceRecord sr in serviceRecords)
{
if (sr.Employee != null && sr.Employee.Oid.Value == config.EmployeeOid.Value)
{
return true;
}
}
}
return allow;
}
public virtual List<FLSAnalysisRootDC> GetCostBearerFLSAnalysis(FLSAnalysisConfigDC config)
{
int count = 0;
var lResult = new List<FLSAnalysisRootDC>();
var rootDC = new FLSAnalysisRootDC();
rootDC.Groups = new List<FLSAnalysisGroupDC>();
lResult.Add(rootDC);
var flsGroupDict = new Dictionary<long, FLSAnalysisGroupDC>();
foreach (var iCostbearer in DAOFactory.GenericDAO.GetAllActive<CostBearer>())
{
if (iCostbearer.Organisation != null)
{
var groupDC = new FLSAnalysisGroupDC();
groupDC.SupportConcepts = new List<SupportConceptFLSOverviewDC>();
groupDC.Organisation = new CompactOrganisationDC();
groupDC.Organisation.OrganisationOid = iCostbearer.Organisation.Oid.Value;
groupDC.Organisation.OrganisationVersion = iCostbearer.Organisation.Version.Value;
groupDC.Organisation.Name = iCostbearer.Organisation.Name;
flsGroupDict.Add(iCostbearer.Oid.Value, groupDC);
rootDC.Groups.Add(groupDC);
}
}
var span = new DateTimeSpan();
span.StartDateTime = config.StartDate.Value;
span.EndDateTime = config.EndDate.Value;
IEnumerable<ServiceRecord> serviceRecordes = DAOFactory.SearchDAO.FindServiceRecordsInSpan(span, config.ShowOnlyMarker ? ServiceRecordTypeId.Content : (ServiceRecordTypeId?)null);
Dictionary<long, SupportConceptFLSOverviewDC> supportConceptOverviewDict = new Dictionary<long, SupportConceptFLSOverviewDC>();
Dictionary<String, bool> groupBookingDict = new Dictionary<String, bool>();
foreach (ServiceRecord sr in serviceRecordes)
{
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 && sr.CostBearer2SupportConceptOid != null)
{
String key = String.Format("{0}_{1}", sr.GroupOid, sr.CostBearer2SupportConceptOid);
if (groupBookingDict.ContainsKey(key))
cont = false;
}
if (cont)
{
cont = this.IsServiceRecordForGoal(sr, config.GoalOids);
}
if (cont && config.ServiceDescriptionOids != null && config.ServiceDescriptionOids.Count > 0 && !config.ServiceDescriptionOids.Contains(sr.ServiceDescription.Oid.Value))
{
cont = false;
}
if (cont && config.ShowOnlyMarker && (!sr.ServiceRecordType.HasValue || sr.ServiceRecordType.Value != ServiceRecordTypeId.Content))
{
cont = false;
}
if (cont)
{
ServiceRecordFLSOverviewDC srDC = CreateServiceRecordFLSOverviewDC(sr, false, true);
if (sr.GroupOid != null && sr.CostBearer2SupportConceptOid != null)
{
String key = String.Format("{0}_{1}", sr.GroupOid, sr.CostBearer2SupportConceptOid);
groupBookingDict.Add(key, true);
}
if (sr.CostBearer2SupportConceptOid != null)
{
CostBearer2SupportConcept cb2sc = sr.CostBearer2SupportConcept;
if (flsGroupDict.ContainsKey(cb2sc.CostBearer.Oid.Value))
{
FLSAnalysisGroupDC groupDC = flsGroupDict[cb2sc.CostBearer.Oid.Value];
SupportConceptFLSOverviewDC scDC = null;
if (supportConceptOverviewDict.ContainsKey(sr.CostBearer2SupportConceptOid.Value))
{
scDC = supportConceptOverviewDict[sr.CostBearer2SupportConceptOid.Value];
}
if (scDC == null)
{
scDC = new SupportConceptFLSOverviewDC();
supportConceptOverviewDict.Add(sr.CostBearer2SupportConceptOid.Value, scDC);
// CostBearer2SupportConcept c2s = null;
// if(c2sDict.ContainsKey(sr.CostBearer2SupportConceptOid.Value))
// c2s = c2sDict[sr.CostBearer2SupportConceptOid.Value];
CostBearer2SupportConcept c2s = sr.CostBearer2SupportConcept;
if (c2s != null)
{
scDC.SupportConcept2CostBearer = MapperFactory.SupportConceptCostBearerRelDC_CostBearer2SupportConcept.MapToNewDC(c2s);
}
groupDC.SupportConcepts.Add(scDC);
}
count++;
scDC.ServiceRecords.Add(srDC);
}
}
}
}
return lResult;
}
public virtual List<FLSAnalysisRootDC> GetTeamFLSAnalysis(FLSAnalysisConfigDC config)
{
int count = 0;
var settings = AppSettings.CreateSettings();
var lResult = new List<FLSAnalysisRootDC>();
FLSAnalysisRootDC rootDC = new FLSAnalysisRootDC();
rootDC.Groups = new List<FLSAnalysisGroupDC>();
lResult.Add(rootDC);
Dictionary<long, FLSAnalysisGroupDC> flsGroupsByCustomerOidDict = new Dictionary<long, FLSAnalysisGroupDC>();
Dictionary<long, Team> teamOidDict = new Dictionary<long, Team>();
IList<Team> teams = null;
if (BeWo.Service.Core.Utils.UserHasRight(LoggedInUserOperationContextExt.Current.User, UserRightType.TeamView_ViewAll))
{
teams = DAOFactory.GenericDAO.GetAllActive<Team>();
}
else if (BeWo.Service.Core.Utils.UserHasRight(LoggedInUserOperationContextExt.Current.User, UserRightType.TeamView_ViewMyTeams))
{
teams = DAOFactory.SearchDAO.FindAllActiveTeamsOfEmployee(LoggedInUserOperationContextExt.Current.User.Employee.Oid.Value);
}
foreach (var team in teams)
{
teamOidDict.Add(team.Oid.Value, team);
}
IList<Team2Customer> team2customers = DAOFactory.GenericDAO.GetAll<Team2Customer>();
foreach (var t2c in team2customers)
{
if ((config.TeamOids == null || config.TeamOids.Contains(t2c.TeamOid.Value)) && teamOidDict.ContainsKey(t2c.TeamOid.Value))
{
Team team = teamOidDict[t2c.TeamOid.Value];
FLSAnalysisGroupDC groupDC = new FLSAnalysisGroupDC();
groupDC.SupportConcepts = new List<SupportConceptFLSOverviewDC>();
groupDC.Team = new CompactTeamDC();
groupDC.Team.TeamOid = team.Oid.Value;
groupDC.Team.Name = team.Name;
if (!flsGroupsByCustomerOidDict.ContainsKey(t2c.CustomerOid.Value))
flsGroupsByCustomerOidDict.Add(t2c.CustomerOid.Value, groupDC);
rootDC.Groups.Add(groupDC);
}
}
var span = new DateTimeSpan();
span.StartDateTime = config.StartDate.Value;
span.EndDateTime = config.EndDate.Value;
IEnumerable<ServiceRecord> serviceRecordes = DAOFactory.SearchDAO.FindServiceRecordsInSpan(span, config.ShowOnlyMarker ? ServiceRecordTypeId.Content : (ServiceRecordTypeId?)null);
Dictionary<long, SupportConceptFLSOverviewDC> supportConceptOverviewDict = new Dictionary<long, SupportConceptFLSOverviewDC>();
decimal archived = 0;
decimal notarchived = 0;
foreach (ServiceRecord sr in serviceRecordes)
{
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)
cont = IsServiceRecordForGoal(sr, config.GoalOids);
if (cont && config.ServiceDescriptionOids != null && config.ServiceDescriptionOids.Count > 0 && !config.ServiceDescriptionOids.Contains(sr.ServiceDescription.Oid.Value))
{
cont = false;
}
if (cont && config.ShowOnlyMarker && (!sr.ServiceRecordType.HasValue || sr.ServiceRecordType.Value != ServiceRecordTypeId.Content))
{
cont = false;
}
if (cont)
{
//if (sr.Customer.IsActive == ActivationTypeId.Archived || sr.SupportConcept.IsActive == ActivationTypeId.Archived)
//{
// archived += sr.RoundedDuration;
//}
//else
//{
// notarchived += sr.RoundedDuration;
//}
ServiceRecordFLSOverviewDC srDC = CreateServiceRecordFLSOverviewDC(sr, false, settings.ShowRoundedDurationInEmployeeAnalysis);
if (sr.CostBearer2SupportConceptOid != null)
{
CostBearer2SupportConcept cb2sc = sr.CostBearer2SupportConcept;
if (flsGroupsByCustomerOidDict.ContainsKey(sr.CustomerOid.Value))
{
FLSAnalysisGroupDC groupDC = flsGroupsByCustomerOidDict[sr.CustomerOid.Value];
SupportConceptFLSOverviewDC scDC = null;
if (supportConceptOverviewDict.ContainsKey(sr.CostBearer2SupportConceptOid.Value))
scDC = supportConceptOverviewDict[sr.CostBearer2SupportConceptOid.Value];
if (scDC == null)
{
scDC = new SupportConceptFLSOverviewDC();
supportConceptOverviewDict.Add(sr.CostBearer2SupportConceptOid.Value, scDC);
//CostBearer2SupportConcept c2s = null;
//if(c2sDict.ContainsKey(sr.CostBearer2SupportConceptOid.Value))
// c2s = c2sDict[sr.CostBearer2SupportConceptOid.Value];
CostBearer2SupportConcept c2s = sr.CostBearer2SupportConcept;
if (c2s != null)
{
scDC.SupportConcept2CostBearer = MapperFactory.SupportConceptCostBearerRelDC_CostBearer2SupportConcept.MapToNewDC(c2s);
}
groupDC.SupportConcepts.Add(scDC);
}
count++;
scDC.ServiceRecords.Add(srDC);
}
}
}
}
return lResult;
}
private bool CheckEmployeeTextProperties(Employee emp, string text1, string text2, string text3, string text4, string text5)
{
bool valid = true;
if (!String.IsNullOrEmpty(text1))
{
valid = text1.Equals(emp.Text1);
}
if (valid && !String.IsNullOrEmpty(text2))
{
valid = text2.Equals(emp.Text2);
}
if (valid && !String.IsNullOrEmpty(text3))
{
valid = text3.Equals(emp.Text3);
}
if (valid && !String.IsNullOrEmpty(text4))
{
valid = text4.Equals(emp.Text4);
}
if (valid && !String.IsNullOrEmpty(text5))
{
valid = text5.Equals(emp.Text5);
}
return valid;
}
public virtual FLSAnalysisRootDC CreateEmployeeFLSRootDC(Employee emp, FLSAnalysisConfigDC config, bool useRoundedDuration)
{
FLSAnalysisRootDC rootDC = new FLSAnalysisRootDC();
rootDC.Groups = new List<FLSAnalysisGroupDC>();
rootDC.Employee = MapperFactory.CompactEmployeeDC_Employee.MapToNewDC(emp);
Contract contract = emp.LastContract;
if (contract != null && contract.WeeklyFLS.HasValue)
{
rootDC.SollFLSPerWeek = contract.WeeklyFLS.Value;
}
IList<ServiceRecord> serviceRecords = null;
if (config.StartDate != null && config.EndDate != null)
{
var span = new DateTimeSpan();
span.StartDateTime = config.StartDate.Value;
span.EndDateTime = config.EndDate.Value;
serviceRecords = DAOFactory.SearchDAO.FindEmployeeServiceRecords(emp.Oid.Value, span, config.CustomerOid, config.ShowOnlyMarker ? ServiceRecordTypeId.Content : (ServiceRecordTypeId?)null);
}
else
{
serviceRecords = emp.ServiceRecordList;
}
Dictionary<long, FLSAnalysisGroupDC> flsGroupDict = new Dictionary<long, FLSAnalysisGroupDC>();
Dictionary<long, SupportConceptFLSOverviewDC> supportConceptOverviewDict = new Dictionary<long, SupportConceptFLSOverviewDC>();
SupportConceptFLSOverviewDC otherDC = null;
Dictionary<long, ServiceRecord> groupBookingDict = new Dictionary<long, ServiceRecord>();
Dictionary<long, string> varFieldDefs = null;
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)
{
cont = this.IsServiceRecordForGoal(sr, config.GoalOids);
}
if (cont && config.ServiceDescriptionOids != null && config.ServiceDescriptionOids.Count > 0 && !config.ServiceDescriptionOids.Contains(sr.ServiceDescription.Oid.Value))
{
cont = false;
}
if (cont && config.ShowOnlyMarker && (!sr.ServiceRecordType.HasValue || sr.ServiceRecordType.Value != ServiceRecordTypeId.Content))
{
cont = false;
}
if (cont)
{
ServiceRecordFLSOverviewDC srDC = CreateServiceRecordFLSOverviewDC(sr, true, useRoundedDuration);
if (srDC.GroupRoundedDuration != null && useRoundedDuration)
{
//###CB Rundung bei Employee
srDC.RoundedDuration = srDC.GroupRoundedDuration.Value;
}
if (srDC.GroupOid != null)
{
groupBookingDict.Add(sr.GroupOid.Value, sr);
}
if (sr.CostBearer2SupportConceptOid != null && sr.CustomerOid != null)
{
FLSAnalysisGroupDC groupDC = null;
if (flsGroupDict.ContainsKey(sr.CustomerOid.Value))
{
groupDC = flsGroupDict[sr.CustomerOid.Value];
}
if (groupDC == null)
{
groupDC = new FLSAnalysisGroupDC();
groupDC.SupportConcepts = new List<SupportConceptFLSOverviewDC>();
flsGroupDict.Add(sr.CustomerOid.Value, groupDC);
// Customer c = null;
// if (customerDict.ContainsKey(sr.CustomerOid.Value))
// c = customerDict[sr.CustomerOid.Value];
Customer c = sr.Customer;
if (c != null)
{
groupDC.Customer = this.CreateCompactCustomerDC(c);
if (config.Text1 != null || config.Text2 != null || config.Text3 != null || config.Text4 != null || config.Text5 != null)
{
//if (MultitenancyOperationContextExt.Current.Tenant == )
if (varFieldDefs == null)
{
varFieldDefs = new Dictionary<long, string>();
IList<VarFieldDef> defs = DAOFactory.SearchDAO.GetVarFieldDefs(TableID.Customer);
foreach (var def in defs)
{
varFieldDefs[def.Oid.Value] = def.Label;
}
}
IList<VarFieldValue> varValues = c.VarFieldValueList;
if (varValues != null && varValues.Count > 0)
{
foreach (var item in varValues)
{
Type type = Type.GetType(item.TypeName);
object obj = BS.Shared.Core.Utils.XMLDeserializeFromString(item.SerializedValue, type);
if (obj != null)
{
groupDC.Customer.VarFieldValues[item.VarFieldDefOid.Value] = obj.ToString();
}
}
}
groupDC.Customer.VarFieldDefs = varFieldDefs;
}
}
rootDC.Groups.Add(groupDC);
}
SupportConceptFLSOverviewDC scDC = null;
if (supportConceptOverviewDict.ContainsKey(sr.CostBearer2SupportConceptOid.Value))
{
scDC = supportConceptOverviewDict[sr.CostBearer2SupportConceptOid.Value];
}
if (scDC == null)
{
scDC = new SupportConceptFLSOverviewDC();
supportConceptOverviewDict.Add(sr.CostBearer2SupportConceptOid.Value, scDC);
// CostBearer2SupportConcept c2s = null;
// if(c2sDict.ContainsKey(sr.CostBearer2SupportConceptOid.Value))
// c2s = c2sDict[sr.CostBearer2SupportConceptOid.Value];
CostBearer2SupportConcept c2s = sr.CostBearer2SupportConcept;
if (c2s != null)
{
scDC.SupportConcept2CostBearer = MapperFactory.SupportConceptCostBearerRelDC_CostBearer2SupportConcept.MapToNewDC(c2s);
}
groupDC.SupportConcepts.Add(scDC);
}
scDC.ServiceRecords.Add(srDC);
}
else
{
if (otherDC == null)
{
otherDC = new SupportConceptFLSOverviewDC();
FLSAnalysisGroupDC groupDC = new FLSAnalysisGroupDC();
groupDC.SupportConcepts = new List<SupportConceptFLSOverviewDC>();
rootDC.Groups.Add(groupDC);
groupDC.SupportConcepts.Add(otherDC);
}
otherDC.ServiceRecords.Add(srDC);
}
}
}
return rootDC;
}
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;
}
private bool IsServiceRecordForGoal(ServiceRecord sr, List<long> goalOids)
{
if (goalOids == null)
{
return true;
}
if (goalOids.Count == 0)
{
return true;
}
foreach (var v2o in sr.ValueList)
{
if (v2o.Entry.Type == ValueListEntryType.SupportConceptGoalType || v2o.Entry.Type == ValueListEntryType.SupportConceptGoalCategoryType || v2o.Entry.Type == ValueListEntryType.SupportConceptIndividualGoalType || v2o.Entry.Type == ValueListEntryType.SupportConceptIndividualGoalCategoryType)
{
foreach (var oid in goalOids)
{
if (v2o.Entry.Oid.Value == oid)
{
return true;
}
}
}
}
return false;
}
public virtual CompactEmployeeDC CreateCompactEmployeeDC(Employee e)
{
var dc = new CompactEmployeeDC();
dc.EmployeeOid = e.Oid.Value;
dc.FirstName = e.Person.FirstName;
dc.LastName = e.Person.LastName;
return dc;
}
public virtual 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;
}
}
}