1018 lines
33 KiB
C#
1018 lines
33 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BeWo.Data;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Service.Core;
|
|
using BeWo.Service.DCEntityMapper;
|
|
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.Compact;
|
|
using BS.Shared.Extensions;
|
|
|
|
namespace BeWo.Service.Plugins
|
|
{
|
|
public class CustomerService : AbstractIDSpecificDefaultClass<CustomerService>
|
|
{
|
|
protected virtual bool FetchTeams()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
protected virtual bool FetchTeamsForSupportConcepts()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public virtual List<CompactCustomerDC> GetAllActiveAndArchivedCustomersCompact(long currentEmployeeOid)
|
|
{
|
|
IEnumerable<Customer> customers = DAOFactory.SearchDAO.GetAllActiveAndArchivedCustomersWithRelatedEmployee();
|
|
|
|
var result = new List<CompactCustomerDC>();
|
|
var cProcessed = new Dictionary<long, bool>();
|
|
var teamOids = new Dictionary<long, long>();
|
|
|
|
if (FetchTeams())
|
|
{
|
|
teamOids = CreateTeamOidDict(currentEmployeeOid);
|
|
}
|
|
foreach (Customer customer in customers)
|
|
{
|
|
if (!cProcessed.ContainsKey(customer.Oid.Value))
|
|
{
|
|
CompactCustomerDC dc = CreateCompactCustomerDCWithEmployeeRelation(customer, false, true, currentEmployeeOid, teamOids);
|
|
|
|
result.Add(dc);
|
|
|
|
cProcessed.Add(customer.Oid.Value, true);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
public virtual List<CompactCustomerDC> GetAllActiveCustomersCompact(bool fetchReferenceNumbers, long? currentEmployeeOid)
|
|
{
|
|
IEnumerable<Customer> customers = DAOFactory.SearchDAO.GetAllActiveCustomersWithAddress();
|
|
|
|
var teamOids = new Dictionary<long, long>();
|
|
|
|
if (FetchTeams() && currentEmployeeOid.HasValue)
|
|
{
|
|
teamOids = CreateTeamOidDict(currentEmployeeOid.Value);
|
|
}
|
|
|
|
return customers.Select(customer => CreateCompactCustomerDCWithEmployeeRelation(customer, fetchReferenceNumbers, false, currentEmployeeOid, teamOids)).ToList();
|
|
}
|
|
|
|
public virtual List<CompactCustomerDC> GetAllCustomersCompact(bool fetchReferenceNumbers, long? currentEmployeeOid)
|
|
{
|
|
var result = new List<CompactCustomerDC>();
|
|
|
|
var es = new EmployeeService();
|
|
var teams = es.GetAllTeamsCompact();
|
|
|
|
var cProcessed = new Dictionary<long, bool>();
|
|
var customers = DAOFactory.SearchDAO.GetAllCustomersWithRelatedEmployee();
|
|
|
|
var teamOids = new Dictionary<long, long>();
|
|
|
|
if (FetchTeams() && currentEmployeeOid.HasValue)
|
|
{
|
|
teamOids = CreateTeamOidDict(currentEmployeeOid.Value);
|
|
}
|
|
|
|
UserDC user;
|
|
if (LoggedInUserOperationContextExt.Current != null && LoggedInUserOperationContextExt.Current.User != null)
|
|
{
|
|
user = MapperFactory.UserDC_User.MapToNewDC(LoggedInUserOperationContextExt.Current.User);
|
|
}
|
|
else
|
|
{
|
|
user = MapperFactory.UserDC_User.MapToNewDC(SessionFacade.LoggedInUser);
|
|
}
|
|
if (teamOids.Count == 0)
|
|
{
|
|
foreach (var t in teams)
|
|
teamOids.Add(t.TeamOid, t.TeamOid);
|
|
}
|
|
|
|
foreach (Customer customer in customers)
|
|
{
|
|
if (!cProcessed.ContainsKey(customer.Oid.Value))
|
|
{
|
|
CompactCustomerDC dc = CreateCompactCustomerDCWithEmployeeRelation(customer, fetchReferenceNumbers, true, currentEmployeeOid, teamOids);
|
|
|
|
// Alle zugehörigen Teamnamen setzen
|
|
if (dc.RelatedTeamOids != null) // Hier muss entweder eine neue Bedingung festgelegt werden oder es muss ganz weg, sonst wird man keine Teamzuordnungen sehen, wenn man selbst in keinem Team ist
|
|
{
|
|
foreach (var oid in dc.RelatedTeamOids)
|
|
{
|
|
var team = teams.FirstOrDefault(t => t.TeamOid == oid);
|
|
if (team != null)
|
|
{
|
|
if (dc.RelatedTeams == null)
|
|
dc.RelatedTeams = " | Teams: " + team.Name + ", ";
|
|
else
|
|
dc.RelatedTeams += team.Name + ", ";
|
|
}
|
|
}
|
|
if (dc.RelatedTeams != null && dc.RelatedTeams.Length > 0)
|
|
dc.RelatedTeams = dc.RelatedTeams.Remove(dc.RelatedTeams.Length - 2, 1);
|
|
}
|
|
|
|
result.Add(dc);
|
|
|
|
cProcessed.Add(customer.Oid.Value, true);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public virtual CustomerDC LoadCustomer(long pCustomerOid)
|
|
{
|
|
SettingsLogic.AddToUsersHistory<Customer>(pCustomerOid);
|
|
var dc = MapperFactory.CustomerDC_Customer.MapToNewDC(DAOFactory.GenericDAO.LoadByID<Customer>(pCustomerOid));
|
|
|
|
return dc;
|
|
|
|
}
|
|
|
|
//public virtual List<CompactCustomerDC> GetAllCustomersCompact(bool fetchReferenceNumbers, long? currentEmployeeOid)
|
|
//{
|
|
// var customers = DAOFactory.SearchDAO.GetAllCustomersWithAddress();
|
|
// var teamOids = new Dictionary<long, long>();
|
|
|
|
// if (FetchTeams() && currentEmployeeOid.HasValue)
|
|
// {
|
|
// var teams = DAOFactory.SearchDAO.FindTeamsOfEmployee(currentEmployeeOid.Value);
|
|
// var teams2 = DAOFactory.SearchDAO.FindLeadingTeams(currentEmployeeOid.Value);
|
|
|
|
// foreach (var t in teams)
|
|
// {
|
|
// if (!teamOids.ContainsKey(t.Oid.Value))
|
|
// {
|
|
// teamOids.Add(t.Oid.Value, t.Oid.Value);
|
|
// }
|
|
// }
|
|
// foreach (var t in teams2)
|
|
// {
|
|
// if (!teamOids.ContainsKey(t.Oid.Value))
|
|
// {
|
|
// teamOids.Add(t.Oid.Value, t.Oid.Value);
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// return customers.Select(customer => CreateCompactCustomerDCWithEmployeeRelation(customer, fetchReferenceNumbers, false, currentEmployeeOid, teamOids)).ToList();
|
|
//}
|
|
|
|
protected CompactCustomerDC CreateCompactCustomerDCWithEmployeeRelation(Customer pEntity, bool fetchReferenceNumbers, bool fetchEmployees, long? currentEmployeeOid, Dictionary<long, long> teamOids)
|
|
{
|
|
|
|
var dc = new CompactCustomerDC();
|
|
|
|
dc.CustomerOid = pEntity.Oid.Value;
|
|
dc.CustomerVersion = pEntity.Version.Value;
|
|
dc.FirstName = pEntity.Person.FirstName;
|
|
dc.LastName = pEntity.Person.LastName;
|
|
dc.DateOfBirth = pEntity.Person.DateOfBirth;
|
|
dc.ActivationType = pEntity.IsActive;
|
|
dc.TerminationDate = pEntity.TerminationDate;
|
|
dc.Sex = pEntity.Person.Sex;
|
|
dc.AbsenceTimes = MapperFactory.AbsenceTimeDC_AbsenceTime.MapToNewDCs(pEntity.AbsenceTimes);
|
|
dc.CustomerAlias = pEntity.CustomerAlias;
|
|
|
|
if (pEntity.Person.Address != null)
|
|
{
|
|
dc.Street = pEntity.Person.Address.Street;
|
|
dc.PostalCode = pEntity.Person.Address.PostalCode;
|
|
dc.Town = pEntity.Person.Address.Town;
|
|
}
|
|
|
|
if (fetchReferenceNumbers)
|
|
{
|
|
pEntity.Customer2CostBearerList.DoForEach(c2cb => dc.CostBearerReferenceNumbers[c2cb.CostBearer.Oid.Value] = c2cb.ReferenceNumber);
|
|
}
|
|
|
|
SetTeamAndEmployeeRelation(dc, currentEmployeeOid, pEntity, teamOids);
|
|
|
|
if (fetchEmployees)
|
|
{
|
|
foreach (Employee2Customer e2c in pEntity.Employee2CustomerList)
|
|
{
|
|
foreach (ValueListEntry2Object vle2o in e2c.ValueList)
|
|
{
|
|
ValueListEntry vle = vle2o.Entry;
|
|
if (vle.SystemEntryID != null && vle.SystemEntryID.Value == SystemEntryID.EmployeeRoleMainAttendant && e2c.EmployeeOid != currentEmployeeOid.Value)
|
|
{
|
|
string empName = e2c.Employee.Person.FirstName + " " + e2c.Employee.Person.LastName;
|
|
if (String.IsNullOrEmpty(dc.MainAttendant))
|
|
dc.MainAttendant = vle.Value + ": " + empName;
|
|
else
|
|
{
|
|
if (!dc.MainAttendant.Contains(empName))
|
|
{
|
|
if (dc.MainAttendant.Contains(vle.Value))
|
|
dc.MainAttendant += ", " + empName;
|
|
else
|
|
dc.MainAttendant += ", " + vle.Value + ": " + empName;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (currentEmployeeOid != null && e2c.EmployeeOid == currentEmployeeOid.Value)
|
|
{
|
|
dc.CurrentEmployeeRole = vle.Value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return dc;
|
|
}
|
|
|
|
public virtual List<CompactSupportConceptDC> GetAllAuthorizedCompactSupportConcepts()
|
|
{
|
|
var user = GetLoggedInUser();
|
|
|
|
var result = new List<CompactSupportConceptDC>();
|
|
|
|
var list = DAOFactory.SearchDAO.GetAllSupportConceptsCompact();
|
|
var scProcessed = new Dictionary<long, bool>();
|
|
var teamOids = new Dictionary<long, long>();
|
|
|
|
bool darfAlleSehen = false;
|
|
bool darfAlleDesTeamsSehen = false;
|
|
bool darfAlleEigenenSehen = false;
|
|
|
|
if (Core.Utils.UserHasRight(user, UserRightType.SupportConceptView_View))
|
|
{
|
|
darfAlleEigenenSehen = true;
|
|
}
|
|
if (Core.Utils.UserHasRight(user, UserRightType.SupportConcept_ViewAllSupportConcepts))
|
|
{
|
|
darfAlleSehen = true;
|
|
}
|
|
if (Core.Utils.UserHasRight(user, UserRightType.SupportConcept_ViewMyTeams))
|
|
{
|
|
darfAlleDesTeamsSehen = true;
|
|
}
|
|
//if (FetchTeamsForSupportConcepts())
|
|
//{
|
|
teamOids = CreateTeamOidDict(user.Employee.Oid.Value);
|
|
//}
|
|
|
|
foreach (var item in list)
|
|
{
|
|
if (item != null && item.Oid != null && !scProcessed.ContainsKey(item.Oid.Value))
|
|
{
|
|
var dc = CreateCompactSupportConceptDC(item, user.Employee.Oid.Value, teamOids);
|
|
|
|
//Supportconcepts können mehrfach vom SearchDAO zurückgeliefert werden, daher prüfen ob bereits verarbeitet
|
|
scProcessed.Add(item.Oid.Value, true);
|
|
|
|
if (dc.ActivationType == ActivationTypeId.Active)
|
|
{
|
|
if (darfAlleSehen)
|
|
{
|
|
result.Add(dc);
|
|
}
|
|
else if (darfAlleDesTeamsSehen)
|
|
{
|
|
if (dc.Customer.IsRelatedToEmployee || dc.Customer.IsRelatedToTeam)
|
|
{
|
|
result.Add(dc);
|
|
}
|
|
|
|
}
|
|
else if (darfAlleEigenenSehen)
|
|
{
|
|
if (dc.IsRelatedToEmployee)
|
|
{
|
|
result.Add(dc);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
return result.OrderBy(a => a.CustomerName).ToList();
|
|
}
|
|
|
|
public virtual List<CompactCustomerDC> GetAllAuthorizedCompactCustomers()
|
|
{
|
|
var user = GetLoggedInUser();
|
|
|
|
IEnumerable<Customer> customers = DAOFactory.SearchDAO.GetAllActiveAndArchivedCustomersWithRelatedEmployee();
|
|
|
|
var result = new List<CompactCustomerDC>();
|
|
var cProcessed = new Dictionary<long, bool>();
|
|
var teamOids = new Dictionary<long, long>();
|
|
|
|
bool darfAlleSehen = false;
|
|
bool darfAlleDesTeamsSehen = false;
|
|
bool darfAlleEigenenSehen = false;
|
|
|
|
if (Core.Utils.UserHasRight(user, UserRightType.Customer_ViewMyCustomers))
|
|
{
|
|
darfAlleEigenenSehen = true;
|
|
}
|
|
if (Core.Utils.UserHasRight(user, UserRightType.CustomerView_View))
|
|
{
|
|
darfAlleSehen = true;
|
|
}
|
|
if (Core.Utils.UserHasRight(user, UserRightType.Customer_ViewMyTeams))
|
|
{
|
|
darfAlleDesTeamsSehen = true;
|
|
}
|
|
|
|
if (FetchTeams())
|
|
{
|
|
teamOids = CreateTeamOidDict(user.Employee.Oid.Value);
|
|
}
|
|
foreach (Customer customer in customers)
|
|
{
|
|
if (!cProcessed.ContainsKey(customer.Oid.Value))
|
|
{
|
|
|
|
CompactCustomerDC dc = CreateCompactCustomerDCWithEmployeeRelation(customer, false, false, user.Employee.Oid.Value, teamOids);
|
|
|
|
cProcessed.Add(customer.Oid.Value, true);
|
|
|
|
if (dc.ActivationType == ActivationTypeId.Active)
|
|
{
|
|
if (darfAlleSehen)
|
|
{
|
|
result.Add(dc);
|
|
}
|
|
else if (darfAlleDesTeamsSehen)
|
|
{
|
|
if (dc.IsRelatedToEmployee || dc.IsRelatedToTeam)
|
|
{
|
|
result.Add(dc);
|
|
}
|
|
|
|
}
|
|
else if (darfAlleEigenenSehen)
|
|
{
|
|
if (dc.IsRelatedToEmployee)
|
|
{
|
|
result.Add(dc);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return result.OrderBy(a => a.LastNameFirstName).ToList();
|
|
}
|
|
|
|
public virtual List<CompactPersonDC> GetAllAuthorizedCompactPersons()
|
|
{
|
|
var user = GetLoggedInUser();
|
|
|
|
var result = new List<CompactPersonDC>();
|
|
var alleList = new List<CompactPersonDC>();
|
|
var cProcessed = new Dictionary<long, bool>();
|
|
|
|
bool darfPersonenSehen = false;
|
|
bool darfFamilieSehen = false;
|
|
|
|
if (Core.Utils.UserHasRight(user, UserRightType.PersonView_View))
|
|
{
|
|
darfPersonenSehen = true;
|
|
}
|
|
if (Core.Utils.UserHasRight(user, UserRightType.Person_FamilyView))
|
|
{
|
|
darfFamilieSehen = true;
|
|
}
|
|
|
|
IList<Person> persons = DAOFactory.GenericDAO.GetAllActive<Person>().Where(p => p.Type == PersonType.Others).ToList();
|
|
|
|
|
|
foreach (var person in persons)
|
|
{
|
|
var dc = MapperFactory.CompactPersonDC_Person.MapToNewDC(person);
|
|
alleList.Add(dc);
|
|
}
|
|
|
|
if (darfPersonenSehen && darfFamilieSehen)
|
|
{
|
|
result = alleList;
|
|
}
|
|
else if (darfPersonenSehen && !darfFamilieSehen)
|
|
{
|
|
result = alleList.Where(p => !p.IsFamilyMember).ToList();
|
|
}
|
|
else if (!darfPersonenSehen && darfFamilieSehen)
|
|
{
|
|
result = alleList.Where(p => p.IsFamilyMember).ToList();
|
|
}
|
|
|
|
return result.OrderBy(p => p.ToString()).ToList();
|
|
}
|
|
|
|
private void SetFamilyMemberStatus(List<CompactPersonDC> result)
|
|
{
|
|
var familyOids = DAOFactory.SearchDAO.FindFamilyMemberOids();
|
|
|
|
foreach (var p in result)
|
|
{
|
|
if (familyOids.Contains(p.PersonOid))
|
|
{
|
|
p.IsFamilyMember = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private ApplicationUser GetLoggedInUser()
|
|
{
|
|
|
|
if (LoggedInUserOperationContextExt.Current != null &&
|
|
LoggedInUserOperationContextExt.Current.User != null)
|
|
{
|
|
return LoggedInUserOperationContextExt.Current.User;
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
return SessionFacade.LoggedInUser;
|
|
}
|
|
|
|
|
|
return null;
|
|
}
|
|
|
|
public virtual List<CompactSupportConceptDC> GetAllSupportConceptsCompact(long currentEmployeeOid)
|
|
{
|
|
var result = new List<CompactSupportConceptDC>();
|
|
|
|
var list = DAOFactory.SearchDAO.GetAllSupportConceptsCompact();
|
|
var scProcessed = new Dictionary<long, bool>();
|
|
var teamOids = new Dictionary<long, long>();
|
|
|
|
//if (FetchTeamsForSupportConcepts())
|
|
//{
|
|
teamOids = CreateTeamOidDict(currentEmployeeOid);
|
|
//}
|
|
|
|
foreach (var item in list)
|
|
{
|
|
if (item != null && item.Oid != null && !scProcessed.ContainsKey(item.Oid.Value))
|
|
{
|
|
var dc = CreateCompactSupportConceptDC(item, currentEmployeeOid, teamOids);
|
|
result.Add(dc);
|
|
|
|
scProcessed.Add(item.Oid.Value, true);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public virtual CompactSupportConceptDC CreateCompactSupportConceptDC(SupportConcept pEntity, long? currentEmployeeOid, Dictionary<long, long> teamOids)
|
|
{
|
|
var dc = new CompactSupportConceptDC();
|
|
|
|
dc.SupportConceptOid = pEntity.Oid.Value;
|
|
dc.SupportConceptVersion = pEntity.Version.Value;
|
|
|
|
Customer cust = pEntity.Customer;
|
|
|
|
var customerDC = new CompactCustomerDC();
|
|
|
|
customerDC.CustomerOid = cust.Oid.Value;
|
|
customerDC.CustomerVersion = cust.Version.Value;
|
|
customerDC.FirstName = cust.Person.FirstName;
|
|
customerDC.LastName = cust.Person.LastName;
|
|
customerDC.CustomerAlias = cust.CustomerAlias;
|
|
customerDC.DateOfBirth = cust.Person.DateOfBirth;
|
|
customerDC.Sex = cust.Person.Sex;
|
|
customerDC.ActivationType = cust.IsActive;
|
|
customerDC.TerminationDate = cust.TerminationDate;
|
|
|
|
if (cust.TerminationReason != null)
|
|
{
|
|
customerDC.TerminationReason = cust.TerminationReason.Value;
|
|
}
|
|
//else if (cust.TerminationDate.HasValue)
|
|
//{
|
|
// customerDC.TerminationReason = String.Format("Betreuung vorzeitig beendet am {0:dd.MM.yyyy}", cust.TerminationDate);
|
|
//}
|
|
if (cust.Person.Address != null)
|
|
{
|
|
customerDC.Street = cust.Person.Address.Street;
|
|
customerDC.PostalCode = cust.Person.Address.PostalCode;
|
|
customerDC.Town = cust.Person.Address.Town;
|
|
}
|
|
|
|
dc.Customer = customerDC;
|
|
|
|
dc.ActivationType = pEntity.IsActive;
|
|
dc.ConferenceDate = pEntity.ConferenceDate;
|
|
|
|
foreach (CostBearer2SupportConcept iCBRel in pEntity.CostBearer2SupportConceptList)
|
|
{
|
|
if (!dc.CostBearerRelOids.Contains(iCBRel.Oid.Value))
|
|
{
|
|
var costBearer = new CompactCostBearerDC();
|
|
|
|
if (iCBRel.CostBearer.Organisation != null)
|
|
{
|
|
var orgDC = new CompactOrganisationDC();
|
|
orgDC.Name = iCBRel.CostBearer.Organisation.Name;
|
|
orgDC.OrganisationOid = iCBRel.CostBearer.Organisation.Oid.Value;
|
|
|
|
costBearer.Organisation = orgDC;
|
|
|
|
// costBearer.Street = iCBRel.CostBearer.Organisation.Address.Street;
|
|
// costBearer.PostalCode = iCBRel.CostBearer.Organisation.Address.PostalCode;
|
|
// costBearer.Town = iCBRel.CostBearer.Organisation.Address.Town;
|
|
}
|
|
|
|
costBearer.IsCalculatingWithFactor = iCBRel.CostBearer.IsCalculatingWithFactor;
|
|
costBearer.CostBearerID = iCBRel.CostBearer.ID;
|
|
costBearer.CostBearerOid = iCBRel.CostBearer.Oid.Value;
|
|
costBearer.CostBearer2SupportConceptOid = iCBRel.Oid.Value;
|
|
costBearer.SupportConceptStatus = iCBRel.Status;
|
|
costBearer.RequestedStartDate = iCBRel.RequestedStartDate;
|
|
costBearer.RequestedEndDate = iCBRel.RequestedEndDate;
|
|
costBearer.ApprovedStartDate = iCBRel.ApprovedStartDate;
|
|
costBearer.ApprovedEndDate = iCBRel.ApprovedEndDate;
|
|
//costBearer.ApprovedFLS = iCBRel.ApprovedFLS;
|
|
//costBearer.ApprovedFLSTotal = iCBRel.ApprovedFLSTotal;
|
|
costBearer.CustomerReferenceNumber = iCBRel.CustomerReferenceNumber;
|
|
|
|
dc.CostBearerList.Add(costBearer);
|
|
dc.CustomerReferenceNumbers.Add(iCBRel.CustomerReferenceNumber);
|
|
dc.CostBearerRelOids.Add(iCBRel.Oid.Value);
|
|
}
|
|
}
|
|
SetTeamAndEmployeeRelation(dc.Customer, currentEmployeeOid, cust, teamOids);
|
|
dc.IsRelatedToEmployee = dc.Customer.IsRelatedToEmployee;
|
|
return dc;
|
|
}
|
|
|
|
private Dictionary<long, long> CreateTeamOidDict(long employeeOid)
|
|
{
|
|
var teamOids = new Dictionary<long, long>();
|
|
|
|
var teams = DAOFactory.SearchDAO.FindTeamsOfEmployee(employeeOid);
|
|
var teams2 = DAOFactory.SearchDAO.FindLeadingTeams(employeeOid);
|
|
|
|
|
|
foreach (var t in teams)
|
|
{
|
|
if (!teamOids.ContainsKey(t.Oid.Value))
|
|
{
|
|
teamOids.Add(t.Oid.Value, t.Oid.Value);
|
|
}
|
|
}
|
|
foreach (var t in teams2)
|
|
{
|
|
if (!teamOids.ContainsKey(t.Oid.Value))
|
|
{
|
|
teamOids.Add(t.Oid.Value, t.Oid.Value);
|
|
}
|
|
}
|
|
|
|
return teamOids;
|
|
}
|
|
|
|
private void SetTeamAndEmployeeRelation(CompactCustomerDC customerDc, long? employeeOid, Customer customer, Dictionary<long, long> teamOids)
|
|
{
|
|
if (employeeOid != null)
|
|
{
|
|
foreach (Employee2Customer e2c in customer.Employee2CustomerList)
|
|
{
|
|
if (employeeOid == e2c.EmployeeOid.Value)
|
|
{
|
|
customerDc.IsRelatedToEmployee = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if (teamOids != null && teamOids.Count > 0)
|
|
{
|
|
|
|
foreach (var t2c in customer.Team2CustomerList)
|
|
{
|
|
if (customerDc.RelatedTeamOids == null)
|
|
{
|
|
customerDc.RelatedTeamOids = new List<long>();
|
|
}
|
|
customerDc.RelatedTeamOids.Add(t2c.TeamOid.Value);
|
|
|
|
if (teamOids.ContainsKey(t2c.TeamOid.Value))
|
|
{
|
|
customerDc.IsRelatedToTeam = true;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private List<CompactSupportConceptDC> CreateFlatSupportConceptCostBearerDCList(IEnumerable<SupportConcept> pEntityList, bool onlyWithAssignedCostbearer, long? employeeOid)
|
|
{
|
|
var list = new List<CompactSupportConceptDC>();
|
|
var customerOIDs = new Dictionary<long, long>();
|
|
var teamOids = new Dictionary<long, long>();
|
|
|
|
if (employeeOid.HasValue && employeeOid > 0)
|
|
{
|
|
var lEmployee = DAOFactory.GenericDAO.LoadByID<Employee>(employeeOid.Value);
|
|
IList<Employee2Customer> e2cList = lEmployee.Employee2CustomerList;
|
|
|
|
|
|
foreach (Employee2Customer item in e2cList)
|
|
{
|
|
if (!customerOIDs.ContainsKey(item.Customer.Oid.Value))
|
|
{
|
|
customerOIDs.Add(item.Customer.Oid.Value, item.Customer.Oid.Value);
|
|
}
|
|
}
|
|
|
|
//if (FetchTeamsForSupportConcepts())
|
|
//{
|
|
teamOids = CreateTeamOidDict(employeeOid.Value);
|
|
//}
|
|
}
|
|
//var t = new List<long>();
|
|
var c2sOids = new Dictionary<long, bool>();
|
|
foreach (SupportConcept sc in pEntityList)
|
|
{
|
|
if (sc.CostBearer2SupportConceptList != null && sc.CostBearer2SupportConceptList.Count > 0)
|
|
{
|
|
foreach (CostBearer2SupportConcept cb2sc in sc.CostBearer2SupportConceptList)
|
|
{
|
|
//t.Add(cb2sc.Oid.Value);
|
|
if (!c2sOids.ContainsKey(cb2sc.Oid.Value))
|
|
{
|
|
CompactSupportConceptDC dc = CreateFlatSupportConcept(sc, cb2sc);
|
|
if (customerOIDs.ContainsKey(sc.Customer.Oid.Value))
|
|
{
|
|
dc.IsRelatedToEmployee = true;
|
|
dc.Customer.IsRelatedToEmployee = true;
|
|
}
|
|
|
|
if (teamOids != null && teamOids.Count > 0)
|
|
{
|
|
|
|
foreach (var t2c in sc.Customer.Team2CustomerList)
|
|
{
|
|
if (dc.Customer.RelatedTeamOids == null)
|
|
{
|
|
dc.Customer.RelatedTeamOids = new List<long>();
|
|
}
|
|
dc.Customer.RelatedTeamOids.Add(t2c.TeamOid.Value);
|
|
|
|
if (teamOids.ContainsKey(t2c.TeamOid.Value))
|
|
{
|
|
dc.Customer.IsRelatedToTeam = true;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
list.Add(dc);
|
|
c2sOids.Add(cb2sc.Oid.Value, true);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!onlyWithAssignedCostbearer)
|
|
{
|
|
list.Add(MapperFactory.CompactSupportConceptDC_SupportConcept.MergeWithDC(sc, new CompactSupportConceptDC()));
|
|
}
|
|
}
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
public virtual CompactSupportConceptDC CreateFlatSupportConcept(SupportConcept sc, CostBearer2SupportConcept cb2sc)
|
|
{
|
|
var dc = new CompactSupportConceptDC();
|
|
|
|
dc.SupportConceptOid = sc.Oid.Value;
|
|
dc.SupportConceptVersion = sc.Version.Value;
|
|
dc.Customer = CreateCustomerForSupportConceptTree(sc.Customer);
|
|
dc.ActivationType = sc.IsActive;
|
|
dc.ConferenceDate = sc.ConferenceDate;
|
|
dc.IsApproved = cb2sc.Status == CostBearer2SupportConceptStatus.Approved;
|
|
|
|
|
|
var costBearer = new CompactCostBearerDC();
|
|
|
|
if (cb2sc.CostBearer.Organisation != null)
|
|
{
|
|
costBearer.Organisation = MapperFactory.CompactOrganisationDC_Organisation.MapToNewDC(cb2sc.CostBearer.Organisation);
|
|
}
|
|
|
|
costBearer.CostBearerID = cb2sc.CostBearer.ID;
|
|
costBearer.CostBearerOid = cb2sc.CostBearer.Oid.Value;
|
|
costBearer.CostBearer2SupportConceptOid = cb2sc.Oid.Value;
|
|
costBearer.SupportConceptStatus = cb2sc.Status;
|
|
costBearer.RequestedStartDate = cb2sc.RequestedStartDate;
|
|
costBearer.RequestedEndDate = cb2sc.RequestedEndDate;
|
|
costBearer.ApprovedStartDate = cb2sc.ApprovedStartDate;
|
|
costBearer.ApprovedEndDate = cb2sc.ApprovedEndDate;
|
|
costBearer.Bezeichnung = cb2sc.AuswahlBezeichnung;
|
|
// costBearer.ApprovedFLS = cb2sc.ApprovedFLS;
|
|
// costBearer.ApprovedFLSTotal = cb2sc.ApprovedFLSTotal;
|
|
costBearer.CustomerReferenceNumber = cb2sc.CustomerReferenceNumber;
|
|
costBearer.IsCalculatingWithFactor = cb2sc.CostBearer.IsCalculatingWithFactor;
|
|
|
|
dc.CostBearerList.Add(costBearer);
|
|
dc.CustomerReferenceNumbers.Add(cb2sc.CustomerReferenceNumber);
|
|
dc.CostBearerRelOids.Add(cb2sc.Oid.Value);
|
|
dc.CostBearerOids2CostBearerRelOids.Add(costBearer.CostBearerOid, cb2sc.Oid.Value);
|
|
|
|
return dc;
|
|
}
|
|
|
|
public virtual List<CompactSupportConceptDC> GetAllActiveSupportConceptCostbearer(bool onlyApproved, bool onlyWithAssignedCostbearer, long employeeOid)
|
|
{
|
|
IList<SupportConcept> list;
|
|
if (onlyApproved)
|
|
{
|
|
list = DAOFactory.SearchDAO.FindAllActiveApprovedSupportConcepts();
|
|
}
|
|
else
|
|
{
|
|
list = DAOFactory.GenericDAO.GetAllActive<SupportConcept>();
|
|
}
|
|
|
|
List<CompactSupportConceptDC> result = CreateFlatSupportConceptCostBearerDCList(list, onlyWithAssignedCostbearer, employeeOid);
|
|
|
|
if (onlyApproved)
|
|
{
|
|
return result.Where(i => i.IsApproved).ToList();
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public virtual IEnumerable<CompactSupportConceptDC> GetCompactSupportConcepts(long supportConceptOid, long? employeeOid)
|
|
{
|
|
var list = new List<SupportConcept>();
|
|
list.Add(DAOFactory.GenericDAO.GetByID<SupportConcept>(supportConceptOid));
|
|
|
|
|
|
List<CompactSupportConceptDC> result = CreateFlatSupportConceptCostBearerDCList(list, true, employeeOid);
|
|
|
|
return result;
|
|
}
|
|
|
|
public virtual CompactCustomerDC CreateCustomerForSupportConceptTree(Customer pEntity)
|
|
{
|
|
var dc = new CompactCustomerDC();
|
|
dc.CustomerOid = pEntity.Oid.Value;
|
|
dc.CustomerVersion = pEntity.Version.Value;
|
|
dc.FirstName = pEntity.Person.FirstName;
|
|
dc.LastName = pEntity.Person.LastName;
|
|
dc.DateOfBirth = pEntity.Person.DateOfBirth;
|
|
dc.ActivationType = pEntity.IsActive;
|
|
dc.TerminationDate = pEntity.TerminationDate;
|
|
|
|
if (pEntity.TerminationDate.HasValue)
|
|
{
|
|
if (pEntity.TerminationReason != null)
|
|
{
|
|
dc.TerminationReason = pEntity.TerminationReason.Value;
|
|
}
|
|
//else
|
|
//{
|
|
// dc.TerminationReason = String.Format("Betreuung vorzeitig beendet am {0:dd.MM.yyyy}", pEntity.TerminationDate);
|
|
//}
|
|
}
|
|
dc.Sex = pEntity.Person.Sex;
|
|
|
|
return dc;
|
|
}
|
|
|
|
public virtual List<SupportConceptTreeNodeDC> GetSupportConceptTreeByEmployee(long pEmployeeOid)
|
|
{
|
|
long starttime = DateTime.Now.Ticks;
|
|
|
|
var lResult = new List<SupportConceptTreeNodeDC>();
|
|
|
|
var lEmployee = DAOFactory.GenericDAO.LoadByID<Employee>(pEmployeeOid);
|
|
|
|
IList<Person> persons = DAOFactory.SearchDAO.GetActivePersonsWithType(PersonType.Customer);
|
|
|
|
IEnumerable<Customer> customers = DAOFactory.SearchDAO.GetAllActiveCustomersWithSupportConceptData();
|
|
|
|
// int test = customers.Count;
|
|
// customers = customers.Distinct().ToList();
|
|
// test = customers.Count;
|
|
IList<Employee2Customer> list = lEmployee.Employee2CustomerList;
|
|
|
|
var customerOIDs = new Dictionary<long, long>();
|
|
foreach (Employee2Customer item in list)
|
|
{
|
|
if (!customerOIDs.ContainsKey(item.Customer.Oid.Value))
|
|
{
|
|
customerOIDs.Add(item.Customer.Oid.Value, item.Customer.Oid.Value);
|
|
}
|
|
}
|
|
|
|
// IList<Address> Addresses = DAOFactory.GenericDAO.GetAll<Address>();
|
|
|
|
// IList<CostBearer2SupportConcept> costbearer2supportconcept = DAOFactory.GenericDAO.GetAll<CostBearer2SupportConcept>();
|
|
// IList<SupportConcept> supportConcepts = DAOFactory.GenericDAO.GetAll<SupportConcept>();
|
|
// IList<Organisation> Organisations = DAOFactory.GenericDAO.GetAll<Organisation>();
|
|
// IList<CostBearer> Costbearer = DAOFactory.GenericDAO.GetAll<CostBearer>();
|
|
|
|
// IList<AbsenceReason> AbsenceReasons = DAOFactory.GenericDAO.GetAll<AbsenceReason>();
|
|
// IList<AbsenceTime> AbsenceTimes = DAOFactory.GenericDAO.GetAll<AbsenceTime>();
|
|
|
|
// IList<Customer2CostBearer> Customer2CostBearers = DAOFactory.GenericDAO.GetAll<Customer2CostBearer>();
|
|
|
|
// IList<CostRatePeriod> CostRatePeriods = DAOFactory.GenericDAO.GetAll<CostRatePeriod>();
|
|
|
|
// IList<ServiceRecord> ServiceRecords = DAOFactory.GenericDAO.GetAll<ServiceRecord>();
|
|
|
|
// foreach (var iCustomer in lEmployee.Employee2CustomerList
|
|
// .Where(e2c => (e2c.IsActive == ActivationTypeId.Active || e2c.IsActive == ActivationTypeId.Archived) && (e2c.Customer.IsActive == ActivationTypeId.Active || e2c.Customer.IsActive == ActivationTypeId.Archived))
|
|
// .Select(e2c => e2c.Customer).Distinct())
|
|
var customerProcessed = new Dictionary<long, bool>();
|
|
var supportConceptProcessed = new Dictionary<long, bool>();
|
|
|
|
foreach (Customer iCustomer in customers)
|
|
{
|
|
if (iCustomer.Oid.Value == 53)
|
|
{
|
|
int test = 0;
|
|
}
|
|
if (!customerProcessed.ContainsKey(iCustomer.Oid.Value))
|
|
{
|
|
var lCustomerNode = new SupportConceptTreeNodeDC
|
|
{
|
|
NodeType = iCustomer.Person.Sex == Sex.Male
|
|
? NodeType.Customer_Male
|
|
: NodeType.Customer_Female,
|
|
Employee = MapperFactory.CompactEmployeeDC_Employee.MapToNewDC(lEmployee),
|
|
Customer = CreateCustomerForSupportConceptTree(iCustomer)
|
|
|
|
|
|
|
|
// MapperFactory.CompactCustomerDC_Customer.MapToNewDC(iCustomer)
|
|
};
|
|
if (customerOIDs.ContainsKey(iCustomer.Oid.Value))
|
|
{
|
|
lCustomerNode.IsRelatedToEmployee = true;
|
|
}
|
|
|
|
lResult.Add(lCustomerNode);
|
|
|
|
foreach (SupportConcept iSupportConcept in
|
|
iCustomer.SupportConcepts.Where(e2c => (e2c.IsActive == ActivationTypeId.Active || e2c.IsActive == ActivationTypeId.Archived)))
|
|
{
|
|
if (!supportConceptProcessed.ContainsKey(iSupportConcept.Oid.Value))
|
|
{
|
|
var lSupportConceptNode = new SupportConceptTreeNodeDC
|
|
{
|
|
NodeType = NodeType.SupportConcept,
|
|
Employee = lCustomerNode.Employee,
|
|
Customer = lCustomerNode.Customer,
|
|
SupportConcept = CreateSCForSupportConceptTree(iSupportConcept)
|
|
|
|
|
|
|
|
// MapperFactory.CompactSupportConceptDC_SupportConcept.MapToNewDC(iSupportConcept)
|
|
};
|
|
lSupportConceptNode.SupportConcept.Customer = lCustomerNode.Customer;
|
|
|
|
// if (getSupportConceptGoals)
|
|
// {
|
|
// lSupportConceptNode.SupportConcept.Goals = MapperFactory.ValueListEntryDC_ValueListEntry.MapToNewDCs(
|
|
// iSupportConcept.ValueList.FindByType(ValueListEntryType.CustomerCareType).Select(e2o => e2o.Entry));
|
|
// }
|
|
lSupportConceptNode.IsRelatedToEmployee = lCustomerNode.IsRelatedToEmployee;
|
|
lCustomerNode.ChildNodes.Add(lSupportConceptNode);
|
|
|
|
foreach (CostBearer2SupportConcept iSC2Cb in
|
|
iSupportConcept.CostBearer2SupportConceptList.Where(e2c => (e2c.IsActive == ActivationTypeId.Active || e2c.IsActive == ActivationTypeId.Archived)))
|
|
{
|
|
var lSC2CbNode = new SupportConceptTreeNodeDC
|
|
{
|
|
NodeType = NodeType.CostBearer,
|
|
Employee = lSupportConceptNode.Employee,
|
|
Customer = lSupportConceptNode.Customer,
|
|
SupportConcept = lSupportConceptNode.SupportConcept,
|
|
SupportConceptCostBearerRelDC = CreateSCCostBearerRelForSupportConceptTree(iSC2Cb)
|
|
|
|
|
|
// ??? warum nicht mapper?
|
|
// MapperFactory.SupportConceptCostBearerRelDC_CostBearer2SupportConcept.MapToNewDC(iSC2Cb)
|
|
};
|
|
lSC2CbNode.SupportConceptCostBearerRelDC.SupportConcept = lSupportConceptNode.SupportConcept;
|
|
|
|
lSC2CbNode.IsRelatedToEmployee = lCustomerNode.IsRelatedToEmployee;
|
|
|
|
if (iSC2Cb.CostBearer.Organisation != null)
|
|
{
|
|
lSC2CbNode.CostBearer = MapperFactory.CompactOrganisationDC_Organisation.MapToNewDC(iSC2Cb.CostBearer.Organisation);
|
|
}
|
|
|
|
lSupportConceptNode.ChildNodes.Add(lSC2CbNode);
|
|
}
|
|
|
|
supportConceptProcessed.Add(iSupportConcept.Oid.Value, true);
|
|
}
|
|
}
|
|
|
|
customerProcessed.Add(iCustomer.Oid.Value, true);
|
|
}
|
|
}
|
|
|
|
long endtime = DateTime.Now.Ticks;
|
|
|
|
long diff = endtime - starttime;
|
|
double secs = diff / (double)10000000;
|
|
|
|
// 10 Mio Ticks = 1Sec.
|
|
return lResult;
|
|
}
|
|
|
|
public virtual SupportConceptCostBearerRelDC CreateSCCostBearerRelForSupportConceptTree(CostBearer2SupportConcept pEntity)
|
|
{
|
|
var dc = new SupportConceptCostBearerRelDC();
|
|
|
|
// dc.ApprovedFLS = pEntity.ApprovedFLS;
|
|
// dc.ApprovedFLSTotal = pEntity.ApprovedFLSTotal;
|
|
dc.CostBearer2SupportConceptOid = pEntity.Oid;
|
|
dc.CostBearer2SupportConceptVersion = pEntity.Version;
|
|
dc.Notice = pEntity.Notice;
|
|
dc.Status = pEntity.Status;
|
|
dc.RequestedStartDate = pEntity.RequestedStartDate;
|
|
dc.RequestedEndDate = pEntity.RequestedEndDate;
|
|
dc.ApprovedStartDate = pEntity.ApprovedStartDate;
|
|
dc.ApprovedEndDate = pEntity.ApprovedEndDate;
|
|
dc.CustomerReferenceNumber = pEntity.CustomerReferenceNumber;
|
|
dc.MonthlyPayment = pEntity.MonthlyPayment;
|
|
|
|
// dc.NoRelationExists = pEntity.ServiceRecords.Count == 0;
|
|
if (pEntity.CostBearer.Organisation != null)
|
|
{
|
|
dc.CostBearer = MapperFactory.CompactOrganisationDC_Organisation.MapToNewDC(pEntity.CostBearer.Organisation);
|
|
}
|
|
|
|
// pDataContract.SupportConcept = MapperFactory.CompactSupportConceptDC_SupportConcept.MapToNewDC(pEntity.SupportConcept);
|
|
return dc;
|
|
}
|
|
|
|
public virtual CompactSupportConceptDC CreateSCForSupportConceptTree(SupportConcept pEntity)
|
|
{
|
|
var dc = new CompactSupportConceptDC();
|
|
|
|
dc.SupportConceptOid = pEntity.Oid.Value;
|
|
dc.SupportConceptVersion = pEntity.Version.Value;
|
|
|
|
// dc.Customer = MapperFactory.CompactCustomerDC_Customer.MapToNewDC(pEntity.Customer);
|
|
dc.ActivationType = pEntity.IsActive;
|
|
dc.ConferenceDate = pEntity.ConferenceDate;
|
|
|
|
// foreach (var iCBRel in pEntity.CostBearer2SupportConceptList)
|
|
// {
|
|
// CompactCostBearerDC costBearer = new CompactCostBearerDC();
|
|
|
|
// if (iCBRel.CostBearer.Organisation != null)
|
|
// costBearer.OrganisationName = iCBRel.CostBearer.Organisation.Name;
|
|
|
|
// costBearer.SupportConceptStatus = iCBRel.Status;
|
|
// costBearer.RequestedStartDate = iCBRel.RequestedStartDate;
|
|
// costBearer.RequestedEndDate = iCBRel.RequestedEndDate;
|
|
// costBearer.ApprovedStartDate = iCBRel.ApprovedStartDate;
|
|
// costBearer.ApprovedEndDate = iCBRel.ApprovedEndDate;
|
|
// costBearer.ApprovedFLS = iCBRel.ApprovedFLS;
|
|
// costBearer.CustomerReferenceNumber = iCBRel.CustomerReferenceNumber;
|
|
|
|
// pDataContract.CostBearerList.Add(costBearer);
|
|
// pDataContract.CustomerReferenceNumbers.Add(iCBRel.CustomerReferenceNumber);
|
|
// pDataContract.CostBearerRelOids.Add(iCBRel.Oid.Value);
|
|
// }
|
|
return dc;
|
|
}
|
|
|
|
public virtual long InsertNewCustomer(CustomerDC pCustomerDc)
|
|
{
|
|
Customer lCustomer = MapperFactory.CustomerDC_Customer.MapToNewEntity(pCustomerDc);
|
|
DAOFactory.GenericDAO.Insert(lCustomer);
|
|
|
|
return lCustomer.Oid.Value;
|
|
}
|
|
|
|
}
|
|
} |