2016-06-27 01:45:38 +02:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
2022-04-25 15:45:02 +02:00
using BeWo.Data ;
2016-06-27 01:45:38 +02:00
using BeWo.Data.Access ;
using BeWo.Data.Entities ;
2023-11-08 00:34:17 +01:00
using BeWo.Data.Security ;
2022-01-28 14:27:43 +01:00
using BeWo.Service.Core ;
2016-06-27 01:45:38 +02:00
using BeWo.Service.DCEntityMapper ;
using BS.Shared ;
using BS.Shared.Core ;
2017-08-14 11:59:31 +02:00
using BS.Shared.DataContracts ;
2016-06-27 01:45:38 +02:00
using BS.Shared.DataContracts.Compact ;
using BS.Shared.Extensions ;
namespace BeWo.Service.Plugins
{
public class CustomerService : AbstractIDSpecificDefaultClass < CustomerService >
{
protected virtual bool FetchTeams ( )
{
return true ;
}
2017-08-14 11:59:31 +02:00
protected virtual bool FetchTeamsForSupportConcepts ( )
{
return false ;
}
2024-09-18 21:50:00 +02:00
2016-06-27 01:45:38 +02:00
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 ( ) )
{
2017-08-14 11:59:31 +02:00
teamOids = CreateTeamOidDict ( currentEmployeeOid ) ;
2016-06-27 01:45:38 +02:00
}
foreach ( Customer customer in customers )
{
if ( ! cProcessed . ContainsKey ( customer . Oid . Value ) )
{
CompactCustomerDC dc = CreateCompactCustomerDCWithEmployeeRelation ( customer , false , true , currentEmployeeOid , teamOids ) ;
2024-09-18 21:50:00 +02:00
2016-06-27 01:45:38 +02:00
result . Add ( dc ) ;
cProcessed . Add ( customer . Oid . Value , true ) ;
}
}
return result ;
}
2024-09-18 21:50:00 +02:00
2016-06-27 01:45:38 +02:00
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 )
{
2017-08-14 11:59:31 +02:00
teamOids = CreateTeamOidDict ( currentEmployeeOid . Value ) ;
2016-06-27 01:45:38 +02:00
}
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 > ( ) ;
2022-02-15 12:33:15 +01:00
var es = new EmployeeService ( ) ;
var teams = es . GetAllTeamsCompact ( ) ;
2016-06-27 01:45:38 +02:00
var cProcessed = new Dictionary < long , bool > ( ) ;
var customers = DAOFactory . SearchDAO . GetAllCustomersWithRelatedEmployee ( ) ;
var teamOids = new Dictionary < long , long > ( ) ;
if ( FetchTeams ( ) & & currentEmployeeOid . HasValue )
{
2017-08-14 11:59:31 +02:00
teamOids = CreateTeamOidDict ( currentEmployeeOid . Value ) ;
2016-06-27 01:45:38 +02:00
}
2022-08-04 08:18:13 +02:00
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 ) ;
}
2022-08-05 13:23:01 +02:00
if ( teamOids . Count = = 0 )
2024-09-18 21:50:00 +02:00
{
2022-08-04 08:18:13 +02:00
foreach ( var t in teams )
teamOids . Add ( t . TeamOid , t . TeamOid ) ;
2024-09-18 21:50:00 +02:00
}
2022-08-04 08:18:13 +02:00
2016-06-27 01:45:38 +02:00
foreach ( Customer customer in customers )
{
if ( ! cProcessed . ContainsKey ( customer . Oid . Value ) )
{
CompactCustomerDC dc = CreateCompactCustomerDCWithEmployeeRelation ( customer , fetchReferenceNumbers , true , currentEmployeeOid , teamOids ) ;
2022-02-15 12:33:15 +01:00
// Alle zugehörigen Teamnamen setzen
2022-08-04 08:18:13 +02:00
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
2024-09-18 21:50:00 +02:00
{
2022-02-15 12:33:15 +01:00
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 ) ;
}
2024-09-18 21:50:00 +02:00
2016-06-27 01:45:38 +02:00
result . Add ( dc ) ;
cProcessed . Add ( customer . Oid . Value , true ) ;
}
}
return result ;
}
2022-01-28 14:27:43 +01:00
public virtual CustomerDC LoadCustomer ( long pCustomerOid )
{
SettingsLogic . AddToUsersHistory < Customer > ( pCustomerOid ) ;
var dc = MapperFactory . CustomerDC_Customer . MapToNewDC ( DAOFactory . GenericDAO . LoadByID < Customer > ( pCustomerOid ) ) ;
return dc ;
2024-09-18 21:50:00 +02:00
2022-01-28 14:27:43 +01:00
}
2016-06-27 01:45:38 +02:00
//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 )
{
2024-09-18 21:50:00 +02:00
2016-06-27 01:45:38 +02:00
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 ) ;
2024-09-18 21:50:00 +02:00
dc . CustomerAlias = pEntity . CustomerAlias ;
2016-06-27 01:45:38 +02:00
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 ) ;
}
2017-11-17 22:24:00 +01:00
SetTeamAndEmployeeRelation ( dc , currentEmployeeOid , pEntity , teamOids ) ;
2024-09-18 21:50:00 +02:00
2017-08-14 11:59:31 +02:00
if ( fetchEmployees )
2016-06-27 01:45:38 +02:00
{
foreach ( Employee2Customer e2c in pEntity . Employee2CustomerList )
{
2017-08-14 11:59:31 +02:00
foreach ( ValueListEntry2Object vle2o in e2c . ValueList )
2016-06-27 01:45:38 +02:00
{
2017-08-14 11:59:31 +02:00
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 )
2016-06-27 01:45:38 +02:00
{
2017-08-14 11:59:31 +02:00
dc . CurrentEmployeeRole = vle . Value ;
2016-06-27 01:45:38 +02:00
}
}
}
2017-08-14 11:59:31 +02:00
}
return dc ;
}
2022-04-25 15:45:02 +02:00
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 )
2024-09-18 21:50:00 +02:00
{
2022-04-25 15:45:02 +02:00
result . Add ( dc ) ;
}
2024-09-18 21:50:00 +02:00
2022-04-25 15:45:02 +02:00
}
else if ( darfAlleEigenenSehen )
2024-09-18 21:50:00 +02:00
{
2022-04-25 15:45:02 +02:00
if ( dc . IsRelatedToEmployee )
2024-09-18 21:50:00 +02:00
{
2022-04-25 15:45:02 +02:00
result . Add ( dc ) ;
2024-09-18 21:50:00 +02:00
}
2022-04-25 15:45:02 +02:00
}
}
}
}
return result . OrderBy ( a = > a . CustomerName ) . ToList ( ) ;
}
public virtual List < CompactCustomerDC > GetAllAuthorizedCompactCustomers ( )
2024-09-18 21:50:00 +02:00
{
2022-04-25 15:45:02 +02:00
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 > ( ) ;
2024-09-18 21:50:00 +02:00
2022-04-25 15:45:02 +02:00
bool darfPersonenSehen = false ;
bool darfFamilieSehen = false ;
2024-09-18 21:50:00 +02:00
2022-04-25 15:45:02 +02:00
if ( Core . Utils . UserHasRight ( user , UserRightType . PersonView_View ) )
{
darfPersonenSehen = true ;
}
if ( Core . Utils . UserHasRight ( user , UserRightType . Person_FamilyView ) )
{
darfFamilieSehen = true ;
}
2024-09-18 21:50:00 +02:00
2022-04-25 15:45:02 +02:00
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 )
2024-09-18 21:50:00 +02:00
{
2022-04-25 15:45:02 +02:00
result = alleList ;
}
else if ( darfPersonenSehen & & ! darfFamilieSehen )
2024-09-18 21:50:00 +02:00
{
2022-04-25 15:45:02 +02:00
result = alleList . Where ( p = > ! p . IsFamilyMember ) . ToList ( ) ;
2024-09-18 21:50:00 +02:00
}
2022-04-25 15:45:02 +02:00
else if ( ! darfPersonenSehen & & darfFamilieSehen )
{
result = alleList . Where ( p = > p . IsFamilyMember ) . ToList ( ) ;
}
2024-09-18 21:50:00 +02:00
2022-04-25 15:45:02 +02:00
return result . OrderBy ( p = > p . ToString ( ) ) . ToList ( ) ;
}
2023-11-08 00:34:17 +01:00
public virtual List < CompactPersonDC > GetAllPersonsByTypeCompact ( PersonType pType )
2024-09-18 21:50:00 +02:00
{
2023-11-08 00:34:17 +01:00
var result = new List < CompactPersonDC > ( ) ;
bool darfFamilieSehen = false ;
bool darfAlleKlientenSehen = false ;
bool darfKlientenDesTeamsSehen = false ;
bool darfSeineKlientenSehen = false ;
List < long > allowedCustomerOids = new List < long > ( ) ;
if ( ! UserRightHelper . LoggedInUserHasRight ( UserRightType . PersonView_View ) )
{
return result ;
}
var user = UserRightHelper . GetLoggedInUser ( ) ;
if ( UserRightHelper . LoggedInUserHasRight ( UserRightType . Person_FamilyView ) )
{
darfFamilieSehen = true ;
}
if ( UserRightHelper . LoggedInUserHasRight ( UserRightType . CustomerView_View ) )
{
darfAlleKlientenSehen = true ;
darfKlientenDesTeamsSehen = true ;
darfSeineKlientenSehen = true ;
}
2024-09-18 21:50:00 +02:00
else if ( UserRightHelper . LoggedInUserHasRight ( UserRightType . Customer_ViewMyTeams ) )
{
darfKlientenDesTeamsSehen = true ;
2023-11-08 00:34:17 +01:00
darfSeineKlientenSehen = true ;
var dict = CreateTeamOidDict ( user . Employee . Oid . Value ) ;
2024-09-18 21:50:00 +02:00
foreach ( var oid in dict . Keys )
{
var clist = DAOFactory . SearchDAO . FindCustomerOfTeam ( oid ) ;
foreach ( var c in clist )
{
foreach ( var e2c in c . Employee2CustomerList )
{
if ( ! e2c . EndDate . HasValue | | e2c . EndDate . Value > = DateTime . Now . Date )
{
allowedCustomerOids . Add ( e2c . CustomerOid . Value ) ;
}
}
}
}
2023-11-08 00:34:17 +01:00
foreach ( var e2c in user . Employee . Employee2CustomerList )
{
if ( ! e2c . EndDate . HasValue | | e2c . EndDate . Value > = DateTime . Now . Date )
{
allowedCustomerOids . Add ( e2c . CustomerOid . Value ) ;
}
}
}
2024-09-18 21:50:00 +02:00
else if ( UserRightHelper . LoggedInUserHasRight ( UserRightType . Customer_ViewMyCustomers ) )
{
darfSeineKlientenSehen = true ;
foreach ( var e2c in user . Employee . Employee2CustomerList )
{
if ( ! e2c . EndDate . HasValue | | e2c . EndDate . Value > = DateTime . Now . Date )
{
allowedCustomerOids . Add ( e2c . CustomerOid . Value ) ;
}
}
}
2023-11-08 00:34:17 +01:00
2024-09-18 21:50:00 +02:00
IList < Person > persons = DAOFactory . GenericDAO . GetAll < Person > ( ) . Where ( p = > p . Type = = pType ) . ToList ( ) ;
2023-11-08 00:34:17 +01:00
Dictionary < long , List < CustomerPersonRelationDC > > person2CustomerOidDict = new Dictionary < long , List < CustomerPersonRelationDC > > ( ) ;
IList < long > personOids = new List < long > ( ) ;
foreach ( var person in persons )
{
personOids . Add ( person . Oid . Value ) ;
}
if ( ! darfFamilieSehen | | ! darfAlleKlientenSehen )
{
var c2oList = DAOFactory . SearchDAO . FindCustomerOid2Persons ( personOids ) ;
2024-08-07 16:26:43 +02:00
if ( c2oList ! = null )
2023-11-08 00:34:17 +01:00
{
2024-08-07 16:26:43 +02:00
foreach ( object [ ] item in c2oList )
2023-11-08 00:34:17 +01:00
{
2024-08-07 16:26:43 +02:00
var oid = ( long ) item [ 0 ] ;
var poid = ( long ) item [ 1 ] ;
var coid = ( long ) item [ 2 ] ;
var test = ( sbyte? ) item [ 3 ] ;
var isF = ( sbyte? ) item [ 3 ] ;
var c2p = new CustomerPersonRelationDC ( ) ;
c2p . Customer2PersonOid = oid ;
c2p . Person = new CompactPersonDC { PersonOid = poid } ;
c2p . Customer = new CompactCustomerDC { CustomerOid = coid } ;
c2p . IstFamilie = isF . HasValue ? isF . Value = = 1 : false ;
if ( ! person2CustomerOidDict . ContainsKey ( poid ) )
{
person2CustomerOidDict . Add ( poid , new List < CustomerPersonRelationDC > ( ) ) ;
}
person2CustomerOidDict [ poid ] . Add ( c2p ) ;
2023-11-08 00:34:17 +01:00
}
}
}
foreach ( var person in persons )
{
2024-09-24 00:00:31 +02:00
if ( ! String . IsNullOrEmpty ( person . FirstName ) & & person . FirstName . Contains ( "Test" ) )
{
}
2023-11-08 00:34:17 +01:00
List < CustomerPersonRelationDC > list = null ;
if ( person2CustomerOidDict . ContainsKey ( person . Oid . Value ) )
2024-09-18 21:50:00 +02:00
{
2023-11-08 00:34:17 +01:00
list = person2CustomerOidDict [ person . Oid . Value ] ;
2024-09-18 21:50:00 +02:00
}
2023-11-08 00:34:17 +01:00
else
2024-09-18 21:50:00 +02:00
{
2023-11-08 00:34:17 +01:00
list = new List < CustomerPersonRelationDC > ( ) ;
}
if ( UserIsAllowedToViewPerson ( person , list , allowedCustomerOids , darfFamilieSehen , darfAlleKlientenSehen , darfKlientenDesTeamsSehen , darfSeineKlientenSehen ) )
{
if ( person . Organisation2Persons . Count = = 0 )
{
var dc = MapperFactory . CompactPersonDC_Person . MapToNewDC ( person ) ;
result . Add ( dc ) ;
if ( pType = = PersonType . Others )
AddContacts ( dc , person , null ) ;
}
foreach ( var o2p in person . Organisation2Persons )
{
var dc = MapperFactory . CompactPersonDC_Person . MapToNewDC ( person ) ;
result . Add ( dc ) ;
if ( pType = = PersonType . Others )
{
AddContacts ( dc , person , o2p ) ;
dc . Organisation = o2p . Organisation . Name ;
if ( o2p . Organisation . Address ! = null )
{
2024-09-24 00:00:31 +02:00
if ( String . IsNullOrEmpty ( dc . Street ) & & String . IsNullOrEmpty ( dc . PostalCode ) & & String . IsNullOrEmpty ( dc . Town ) )
{
dc . Street = o2p . Organisation . Address . Street ;
dc . PostalCode = o2p . Organisation . Address . PostalCode ;
dc . Town = o2p . Organisation . Address . Town ;
}
2023-11-08 00:34:17 +01:00
}
}
}
}
}
SetFamilyMemberStatus ( result ) ;
return result ;
}
2024-09-18 21:50:00 +02:00
private bool UserIsAllowedToViewPerson ( Person person , List < CustomerPersonRelationDC > person2CustomerList , List < long > allowedCustomerOids , bool darfFamilieSehen , bool darfAlleKlientenSehen , bool darfKlientenDesTeamsSehen , bool darfSeineKlientenSehen )
{
2023-12-03 23:00:10 +01:00
if ( person . LastName = = "Aßmann" )
2024-09-18 21:50:00 +02:00
{
2023-12-03 23:00:10 +01:00
int test = 0 ;
2024-09-18 21:50:00 +02:00
}
2023-12-03 23:00:10 +01:00
if ( darfFamilieSehen & & darfAlleKlientenSehen )
2024-09-18 21:50:00 +02:00
{
2023-12-03 23:00:10 +01:00
return true ;
2024-09-18 21:50:00 +02:00
}
2023-12-03 23:00:10 +01:00
//if (!darfFamilieSehen)
2024-09-18 21:50:00 +02:00
//{
2023-12-03 23:00:10 +01:00
// return person2CustomerList.Count(p => p.IstFamilie) > 0;
2024-09-18 21:50:00 +02:00
//}
2023-11-08 00:34:17 +01:00
if ( darfAlleKlientenSehen )
2024-09-18 21:50:00 +02:00
{
2023-11-08 00:34:17 +01:00
return true ;
2024-09-18 21:50:00 +02:00
}
2023-11-08 00:34:17 +01:00
if ( darfKlientenDesTeamsSehen | | darfSeineKlientenSehen )
2024-09-18 21:50:00 +02:00
{
foreach ( var p2c in person2CustomerList )
{
2023-11-08 00:34:17 +01:00
if ( allowedCustomerOids . Contains ( p2c . Customer . CustomerOid ) )
2024-09-18 21:50:00 +02:00
{
2023-11-08 00:34:17 +01:00
return true ;
2024-09-18 21:50:00 +02:00
}
}
}
2023-11-08 00:34:17 +01:00
return false ;
2024-09-18 21:50:00 +02:00
}
2023-11-08 00:34:17 +01:00
2024-09-18 21:50:00 +02:00
private void SetFamilyMemberStatus ( List < CompactPersonDC > result )
2022-04-25 15:45:02 +02:00
{
var familyOids = DAOFactory . SearchDAO . FindFamilyMemberOids ( ) ;
foreach ( var p in result )
{
if ( familyOids . Contains ( p . PersonOid ) )
{
p . IsFamilyMember = true ;
}
}
}
2023-11-08 00:34:17 +01:00
public static void AddContacts ( CompactPersonDC dc , Person person , Organisation2Person o2p )
{
2024-09-24 00:00:31 +02:00
if ( person . Contacts ! = null )
{
foreach ( Contact contact in person . Contacts )
{
if ( contact . Type = = ContactType . private_Phone )
{
dc . Communication1 = contact . Value ;
}
if ( contact . Type = = ContactType . private_MobilePhone )
{
dc . Communication2 = contact . Value ;
}
if ( contact . Type = = ContactType . private_Mail )
{
dc . Communication3 = contact . Value ;
}
}
}
2023-11-08 00:34:17 +01:00
if ( o2p ! = null )
{
if ( o2p . Contacts ! = null )
{
foreach ( Contact contact in o2p . Contacts )
{
2024-09-24 00:00:31 +02:00
if ( String . IsNullOrEmpty ( dc . Communication1 ) )
{
if ( contact . Type = = ContactType . business_Phone )
{
dc . Communication1 = contact . Value ;
}
}
if ( String . IsNullOrEmpty ( dc . Communication2 ) )
2023-11-08 00:34:17 +01:00
{
2024-09-24 00:00:31 +02:00
if ( contact . Type = = ContactType . business_MobilePhone )
{
dc . Communication2 = contact . Value ;
}
2023-11-08 00:34:17 +01:00
}
2024-09-24 00:00:31 +02:00
if ( String . IsNullOrEmpty ( dc . Communication3 ) )
2023-11-08 00:34:17 +01:00
{
2024-09-24 00:00:31 +02:00
if ( contact . Type = = ContactType . business_Mail )
{
dc . Communication3 = contact . Value ;
}
2023-11-08 00:34:17 +01:00
}
}
}
if ( o2p . Organisation ! = null & & o2p . Organisation . Contacts ! = null )
{
if ( String . IsNullOrEmpty ( dc . Communication1 ) )
{
foreach ( Contact contact in o2p . Organisation . Contacts )
{
if ( contact . Type = = ContactType . business_Phone )
{
dc . Communication1 = contact . Value ;
}
}
}
if ( String . IsNullOrEmpty ( dc . Communication2 ) )
{
//foreach (var contact in org.Contacts)
//{
// if (contact.Type == ContactType.b)
// {
// dc.Communication2 = contact.Value;
// }
//}
}
if ( String . IsNullOrEmpty ( dc . Communication3 ) )
{
foreach ( Contact contact in o2p . Organisation . Contacts )
{
if ( contact . Type = = ContactType . business_Mail )
{
dc . Communication3 = contact . Value ;
}
}
}
}
}
2024-09-24 00:00:31 +02:00
2023-11-08 00:34:17 +01:00
}
2022-04-25 15:45:02 +02:00
private ApplicationUser GetLoggedInUser ( )
2024-09-18 21:50:00 +02:00
{
2022-04-25 15:45:02 +02:00
if ( LoggedInUserOperationContextExt . Current ! = null & &
LoggedInUserOperationContextExt . Current . User ! = null )
{
return LoggedInUserOperationContextExt . Current . User ;
}
else
{
return SessionFacade . LoggedInUser ;
}
2024-09-18 21:50:00 +02:00
2022-04-25 15:45:02 +02:00
return null ;
}
2017-08-14 11:59:31 +02:00
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 > ( ) ;
2016-06-27 01:45:38 +02:00
2017-11-17 22:24:00 +01:00
//if (FetchTeamsForSupportConcepts())
//{
2024-09-18 21:50:00 +02:00
teamOids = CreateTeamOidDict ( currentEmployeeOid ) ;
2017-11-17 22:24:00 +01:00
//}
2017-08-14 11:59:31 +02:00
foreach ( var item in list )
{
if ( item ! = null & & item . Oid ! = null & & ! scProcessed . ContainsKey ( item . Oid . Value ) )
2016-06-27 01:45:38 +02:00
{
2017-08-14 11:59:31 +02:00
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 ;
2023-09-25 17:15:21 +02:00
dc . NearlyExpiredBrush = GetBrushForNearlyExpiredSupportConcept ( ) ;
dc . ExpiredBrush = GetBrushForExpiredSupportConcept ( ) ;
2017-08-14 11:59:31 +02:00
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 ;
}
2020-11-10 02:25:15 +01:00
//else if (cust.TerminationDate.HasValue)
//{
// customerDC.TerminationReason = String.Format("Betreuung vorzeitig beendet am {0:dd.MM.yyyy}", cust.TerminationDate);
//}
2017-08-14 11:59:31 +02:00
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 ;
2023-08-16 15:39:16 +02:00
dc . Customer . RelatedTeams = cust . TeamSimpleString ;
2017-08-14 11:59:31 +02:00
dc . ActivationType = pEntity . IsActive ;
dc . ConferenceDate = pEntity . ConferenceDate ;
foreach ( CostBearer2SupportConcept iCBRel in pEntity . CostBearer2SupportConceptList )
{
2024-09-25 16:57:03 +02:00
dc . DefaultBrush = GetDefaultBrush ( pEntity , iCBRel ) ;
2017-08-14 11:59:31 +02:00
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 ) ;
}
}
2024-09-18 21:50:00 +02:00
SetTeamAndEmployeeRelation ( dc . Customer , currentEmployeeOid , cust , teamOids ) ;
dc . IsRelatedToEmployee = dc . Customer . IsRelatedToEmployee ;
2017-08-14 11:59:31 +02:00
return dc ;
}
2023-09-25 17:15:21 +02:00
protected virtual string GetBrushForNearlyExpiredSupportConcept ( )
{
return System . Windows . Media . Brushes . Yellow . ToString ( ) ;
}
protected virtual string GetBrushForExpiredSupportConcept ( )
2024-09-18 21:50:00 +02:00
{
2023-09-25 17:15:21 +02:00
return System . Windows . Media . Brushes . Red . ToString ( ) ;
}
2024-09-25 16:57:03 +02:00
protected virtual string GetDefaultBrush ( SupportConcept sc , CostBearer2SupportConcept c2s )
{
//Nur zum Überschreiben nötig
return null ;
}
2017-08-14 11:59:31 +02:00
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 ;
}
2017-11-17 22:24:00 +01:00
private void SetTeamAndEmployeeRelation ( CompactCustomerDC customerDc , long? employeeOid , Customer customer , Dictionary < long , long > teamOids )
2017-08-14 11:59:31 +02:00
{
if ( employeeOid ! = null )
{
foreach ( Employee2Customer e2c in customer . Employee2CustomerList )
{
2024-09-24 00:00:31 +02:00
if ( employeeOid = = e2c . EmployeeOid . Value & & ( ! e2c . StartDate . HasValue | | e2c . StartDate < = DateTime . Now . Date ) & & ( ! e2c . EndDate . HasValue | | e2c . EndDate > = DateTime . Now . Date ) )
2017-08-14 11:59:31 +02:00
{
2024-09-18 21:50:00 +02:00
customerDc . IsRelatedToEmployee = true ;
2017-08-14 11:59:31 +02:00
}
}
}
2017-11-17 22:24:00 +01:00
2024-09-18 21:50:00 +02:00
if ( teamOids ! = null & & teamOids . Count > 0 )
{
2017-11-17 22:24:00 +01:00
2024-09-18 21:50:00 +02:00
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 ;
}
}
}
}
2017-11-17 22:24:00 +01:00
2024-09-18 21:50:00 +02:00
private List < CompactSupportConceptDC > CreateFlatSupportConceptCostBearerDCList ( IEnumerable < SupportConcept > pEntityList , bool onlyWithAssignedCostbearer , long? employeeOid )
2017-08-14 11:59:31 +02:00
{
var list = new List < CompactSupportConceptDC > ( ) ;
var customerOIDs = new Dictionary < long , long > ( ) ;
2024-09-18 21:50:00 +02:00
var teamOids = new Dictionary < long , long > ( ) ;
2017-08-14 11:59:31 +02:00
2024-09-18 21:50:00 +02:00
if ( employeeOid . HasValue & & employeeOid > 0 )
2017-08-14 11:59:31 +02:00
{
var lEmployee = DAOFactory . GenericDAO . LoadByID < Employee > ( employeeOid . Value ) ;
IList < Employee2Customer > e2cList = lEmployee . Employee2CustomerList ;
2016-06-27 01:45:38 +02:00
2017-08-14 11:59:31 +02:00
foreach ( Employee2Customer item in e2cList )
{
2024-09-24 00:00:31 +02:00
if ( ( ! item . StartDate . HasValue | | item . StartDate < = DateTime . Now . Date ) & & ( ! item . EndDate . HasValue | | item . EndDate > = DateTime . Now . Date ) )
2017-08-14 11:59:31 +02:00
{
2024-09-24 00:00:31 +02:00
if ( ! customerOIDs . ContainsKey ( item . Customer . Oid . Value ) )
{
customerOIDs . Add ( item . Customer . Oid . Value , item . Customer . Oid . Value ) ;
}
2017-08-14 11:59:31 +02:00
}
2024-09-24 00:00:31 +02:00
2017-08-14 11:59:31 +02:00
}
2024-09-18 21:50:00 +02:00
//if (FetchTeamsForSupportConcepts())
//{
teamOids = CreateTeamOidDict ( employeeOid . Value ) ;
//}
2017-08-14 11:59:31 +02:00
}
//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 )
2016-06-27 01:45:38 +02:00
{
2017-08-14 11:59:31 +02:00
//t.Add(cb2sc.Oid.Value);
if ( ! c2sOids . ContainsKey ( cb2sc . Oid . Value ) )
2016-06-27 01:45:38 +02:00
{
2017-08-14 11:59:31 +02:00
CompactSupportConceptDC dc = CreateFlatSupportConcept ( sc , cb2sc ) ;
if ( customerOIDs . ContainsKey ( sc . Customer . Oid . Value ) )
2016-06-27 01:45:38 +02:00
{
dc . IsRelatedToEmployee = true ;
2017-08-14 11:59:31 +02:00
dc . Customer . IsRelatedToEmployee = true ;
2016-06-27 01:45:38 +02:00
}
2017-11-17 22:24:00 +01:00
2024-09-18 21:50:00 +02:00
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 ) ;
2017-11-17 22:24:00 +01:00
2024-09-18 21:50:00 +02:00
if ( teamOids . ContainsKey ( t2c . TeamOid . Value ) )
{
dc . Customer . IsRelatedToTeam = true ;
}
2017-11-17 22:24:00 +01:00
2024-09-18 21:50:00 +02:00
}
}
2017-11-17 22:24:00 +01:00
2024-09-18 21:50:00 +02:00
list . Add ( dc ) ;
2017-08-14 11:59:31 +02:00
c2sOids . Add ( cb2sc . Oid . Value , true ) ;
2016-06-27 01:45:38 +02:00
}
}
}
2017-08-14 11:59:31 +02:00
else
{
if ( ! onlyWithAssignedCostbearer )
{
list . Add ( MapperFactory . CompactSupportConceptDC_SupportConcept . MergeWithDC ( sc , new CompactSupportConceptDC ( ) ) ) ;
}
}
}
return list ;
}
2024-09-18 21:50:00 +02:00
public virtual long InsertNewSupportConcept ( SupportConceptDC pSupportConcept )
{
CheckDefaultServiceCategory ( pSupportConcept ) ;
var lSupportConcept = MapperFactory . SupportConceptDC_SupportConcept . MapToNewEntity ( pSupportConcept ) ;
lSupportConcept . Customer . Customer2CostBearerList . AddRange ( lSupportConcept . CostBearer2SupportConceptList . Where ( cb2sc = > ! lSupportConcept . Customer . Customer2CostBearerList . Exists ( c2cb = > c2cb . CostBearer . Equals ( cb2sc . CostBearer ) ) ) . Select ( c2cb = > new Customer2CostBearer { CostBearer = c2cb . CostBearer , ReferenceNumber = c2cb . CustomerReferenceNumber } ) ) ;
DAOFactory . GenericDAO . Insert ( lSupportConcept ) ;
MakeSupportConceptHistoryEntry ( lSupportConcept , lSupportConcept . Oid . Value , StatementType . Insert ) ;
return lSupportConcept . Oid . Value ;
}
public virtual long UpdateSupportConcept ( SupportConceptDC pSupportConcept )
{
CheckDefaultServiceCategory ( pSupportConcept ) ;
var lOriginal = DAOFactory . GenericDAO . LoadByID < SupportConcept > ( pSupportConcept . SupportConceptOid . Value ) ;
MapperFactory . SupportConceptDC_SupportConcept . MergeWithEntity ( pSupportConcept , lOriginal ) ;
lOriginal . Customer . Customer2CostBearerList . AddRange ( lOriginal . CostBearer2SupportConceptList . Where ( cb2sc = > ! lOriginal . Customer . Customer2CostBearerList . Exists ( c2cb = > c2cb . CostBearer . Equals ( cb2sc . CostBearer ) ) ) . Select ( c2cb = > new Customer2CostBearer { CostBearer = c2cb . CostBearer , ReferenceNumber = c2cb . CustomerReferenceNumber } ) ) ;
DAOFactory . GenericDAO . Update ( lOriginal ) ;
MakeSupportConceptHistoryEntry ( lOriginal , lOriginal . Oid . Value , StatementType . Update ) ;
return lOriginal . Oid . Value ;
}
public static void MakeSupportConceptHistoryEntry ( SupportConcept lOriginal , long? Oid , StatementType statementType )
{
var supportConceptHistoryEntry = new SupportConceptHistory ( )
{
ChangeType = statementType ,
SupportConcept_ApprovalDate = lOriginal . ApprovalDate ,
SupportConcept_Conference = lOriginal . Conference ,
SupportConcept_ConferenceDate = lOriginal . ConferenceDate ,
SupportConcept_ConferenceVenue = lOriginal . ConferenceVenue ,
SupportConcept_ConsultingNeeded = lOriginal . ConsultingNeeded ,
//SupportConcept_CostBearer2SupportConceptList = lOriginal.CostBearer2SupportConceptList,
SupportConcept_CustomerOid = lOriginal . Customer . Oid ,
SupportConcept_EmployeeOid = lOriginal . Originator . Oid ,
SupportConcept_RenewalSendDate = lOriginal . RenewalSendDate ,
SupportConcept_RequisitionSendDate = lOriginal . RequisitionSendDate ,
SupportConcept_SupportConceptSendDate = lOriginal . RequisitionSendDate ,
SupportConceptOid = lOriginal . Oid ,
Notice = lOriginal . Notice
} ;
DAOFactory . GenericDAO . Insert ( supportConceptHistoryEntry ) ;
List < CostBearer2SupportConceptHistory > cb2schToInsert = new List < CostBearer2SupportConceptHistory > ( ) ;
List < SupportConceptApprovalPeriodHistory > scApprovalPeriodHistoriesToInsert = new List < SupportConceptApprovalPeriodHistory > ( ) ;
foreach ( var originalC2S in lOriginal . CostBearer2SupportConceptList )
{
var C2SHistory = new CostBearer2SupportConceptHistory ( )
{
//CostBearer2SupportConcept_AccountingTransactions = originalC2S.AccountingTransactions,
CostBearer2SupportConcept_ApprovedEndDate = originalC2S . ApprovedEndDate ,
CostBearer2SupportConcept_ApprovedStartDate = originalC2S . ApprovedStartDate ,
CostBearer2SupportConcept_AuswahlBezeichnung = originalC2S . AuswahlBezeichnung ,
CostBearer2SupportConcept_CostBearerContactPersonOid = originalC2S . CostBearerContactPerson ? . Oid ,
CostBearer2SupportConcept_CostBearerOid = originalC2S . CostBearer ? . Oid ,
CostBearer2SupportConcept_CustomerReferenceNumber = originalC2S . CustomerReferenceNumber ,
CostBearer2SupportConcept_MonthlyPayment = originalC2S . MonthlyPayment ,
CostBearer2SupportConcept_RequestedEndDate = originalC2S . RequestedEndDate ,
CostBearer2SupportConcept_RequestedStartDate = originalC2S . RequestedStartDate ,
//CostBearer2SupportConcept_ServiceRecords = originalC2S.ServiceRecords,
CostBearer2SupportConcept_Status = originalC2S . Status ,
//CostBearer2SupportConcept_SupportConceptApprovalPeriodList = originalC2S.ApprovalPeriodList
CostBearer2SupportConcept_SupportConceptHistoryOid = lOriginal . Oid . Value ,
ChangeType = statementType ,
Notice = originalC2S . Notice
} ;
DAOFactory . GenericDAO . Insert ( C2SHistory ) ;
foreach ( var item in originalC2S . ApprovalPeriodList )
{
var scApprovalPeriodHistory = new SupportConceptApprovalPeriodHistory ( )
{
ChangeType = statementType ,
SupportConceptApprovalPeriod_ApprovedBEInterval = item . ApprovedBEInterval ,
SupportConceptApprovalPeriod_ApprovedBEPerInterval = item . ApprovedBEPerInterval ,
SupportConceptApprovalPeriod_ApprovedBETotal = item . ApprovedBETotal ,
SupportConceptApprovalPeriod_ApprovedFixedAmount = item . ApprovedFixedAmount ,
SupportConceptApprovalPeriod_ApprovedFixedAmountInterval = item . ApprovedFixedAmountInterval ,
SupportConceptApprovalPeriod_Bewilligungsart = item . Bewilligungsart ,
SupportConceptApprovalPeriod_BudgetOid = item . Budget ? . Oid . Value ,
SupportConceptApprovalPeriod_ContactCountInterval = item . ContactCountInterval ,
SupportConceptApprovalPeriod_ContactCountPerInterval = item . ContactCountPerInterval ,
SupportConceptApprovalPeriod_CostBearer2SupportConceptHistoryOid = originalC2S . Oid . Value ,
SupportConceptApprovalPeriod_EndDate = item . EndDate ,
SupportConceptApprovalPeriod_IsApprovedBEShifting = item . IsApprovedBEShifting ,
SupportConceptApprovalPeriod_IsApprovedFixedAmountShifting = item . IsApprovedFixedAmountShifting ,
SupportConceptApprovalPeriod_MonthlyPayment = item . MonthlyPayment ,
SupportConceptApprovalPeriod_StartDate = item . StartDate ,
SupportConceptApprovalPeriod_SupportConceptApprovalPeriod2Employee = item . SupportConceptApprovalPeriod2Employee ,
SupportConceptApprovalPeriod_SupportConceptHistoryOid = supportConceptHistoryEntry . Oid . Value ,
Notice = item . Notice
} ;
DAOFactory . GenericDAO . Insert ( scApprovalPeriodHistory ) ;
}
}
//MakeHistoryEntry(lOriginal.Customer2PersonList, originalCustomer2PersonList, lOriginal.Oid, statementType);
//MakeHistoryEntry(lOriginal.Customer2OrganisationList, originalC2OList, lOriginal.Oid, statementType);
//MakeHistoryEntry(lOriginal.Employee2CustomerList, originale2CList, lOriginal.Oid, statementType);
}
public static void CheckDefaultServiceCategory ( SupportConceptDC pSupportConcept )
{
if ( pSupportConcept . ServiceAccountings ! = null )
{
ServiceCategoryDC defaultCat = null ;
foreach ( ServiceAccountingDC sa in pSupportConcept . ServiceAccountings )
{
if ( sa . ServiceDescription . ScopeType = = ScopeTypeId . Individual )
{
if ( sa . ServiceDescription . Category = = null )
{
if ( defaultCat = = null )
{
ServiceCategory defaultCatEntity = DAOFactory . SearchDAO . FindDefaultIndividualServiceCategory ( ) ;
if ( defaultCatEntity = = null )
{
defaultCatEntity = new ServiceCategory ( ) ;
defaultCatEntity . Name = "Individuelle Leistungen" ;
defaultCatEntity . ScopeType = ScopeTypeId . Individual ;
defaultCatEntity . IsBillable = true ;
defaultCatEntity . BillableAmount = 100 ;
DAOFactory . GenericDAO . Insert ( defaultCatEntity ) ;
}
defaultCat = MapperFactory . ServiceCategoryDC_ServiceCategory . MapToNewDC ( defaultCatEntity ) ;
}
sa . ServiceDescription . Category = defaultCat ;
}
}
}
}
}
2017-08-14 11:59:31 +02:00
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 ;
2023-09-25 17:47:56 +02:00
dc . NearlyExpiredBrush = GetBrushForNearlyExpiredSupportConcept ( ) ;
dc . ExpiredBrush = GetBrushForExpiredSupportConcept ( ) ;
2024-09-25 16:57:03 +02:00
dc . DefaultBrush = GetDefaultBrush ( sc , cb2sc ) ;
2016-06-27 01:45:38 +02:00
2017-08-14 11:59:31 +02:00
var costBearer = new CompactCostBearerDC ( ) ;
if ( cb2sc . CostBearer . Organisation ! = null )
{
costBearer . Organisation = MapperFactory . CompactOrganisationDC_Organisation . MapToNewDC ( cb2sc . CostBearer . Organisation ) ;
2016-06-27 01:45:38 +02:00
}
2017-08-14 11:59:31 +02:00
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 )
2016-06-27 01:45:38 +02:00
{
2017-08-14 11:59:31 +02:00
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 ;
2023-05-02 14:24:26 +02:00
dc . CustomerAlias = pEntity . CustomerAlias ;
2017-08-14 11:59:31 +02:00
dc . DateOfBirth = pEntity . Person . DateOfBirth ;
dc . ActivationType = pEntity . IsActive ;
dc . TerminationDate = pEntity . TerminationDate ;
if ( pEntity . TerminationDate . HasValue )
{
if ( pEntity . TerminationReason ! = null )
2016-06-27 01:45:38 +02:00
{
2017-08-14 11:59:31 +02:00
dc . TerminationReason = pEntity . TerminationReason . Value ;
}
2020-11-10 02:25:15 +01:00
//else
//{
// dc.TerminationReason = String.Format("Betreuung vorzeitig beendet am {0:dd.MM.yyyy}", pEntity.TerminationDate);
//}
2017-08-14 11:59:31 +02:00
}
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
2016-06-27 01:45:38 +02:00
{
2017-08-14 11:59:31 +02:00
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 ) )
2016-06-27 01:45:38 +02:00
{
2017-08-14 11:59:31 +02:00
var lSupportConceptNode = new SupportConceptTreeNodeDC
2016-06-27 01:45:38 +02:00
{
2017-08-14 11:59:31 +02:00
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
2016-06-27 01:45:38 +02:00
{
2017-08-14 11:59:31 +02:00
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 ) ;
2016-06-27 01:45:38 +02:00
}
2017-08-14 11:59:31 +02:00
lSupportConceptNode . ChildNodes . Add ( lSC2CbNode ) ;
2016-06-27 01:45:38 +02:00
}
2017-08-14 11:59:31 +02:00
supportConceptProcessed . Add ( iSupportConcept . Oid . Value , true ) ;
2016-06-27 01:45:38 +02:00
}
}
2017-08-14 11:59:31 +02:00
customerProcessed . Add ( iCustomer . Oid . Value , true ) ;
2016-06-27 01:45:38 +02:00
}
}
2017-08-14 11:59:31 +02:00
long endtime = DateTime . Now . Ticks ;
long diff = endtime - starttime ;
double secs = diff / ( double ) 10000000 ;
// 10 Mio Ticks = 1Sec.
return lResult ;
}
2024-09-18 21:50:00 +02:00
2017-08-14 11:59:31 +02:00
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);
// }
2016-06-27 01:45:38 +02:00
return dc ;
}
2019-09-17 17:44:57 +02:00
2024-09-18 21:50:00 +02:00
public virtual long InsertNewCustomer ( CustomerDC pCustomerDc )
{
Customer lCustomer = MapperFactory . CustomerDC_Customer . MapToNewEntity ( pCustomerDc ) ;
DAOFactory . GenericDAO . Insert ( lCustomer ) ;
2019-09-17 17:44:57 +02:00
2024-09-18 21:50:00 +02:00
return lCustomer . Oid . Value ;
}
2020-10-20 17:31:26 +02:00
2024-10-21 13:27:52 +02:00
public virtual ImportSupportConceptResultDC ImportSupportConcept ( HilfeplanImportDC hidc )
2024-06-19 16:13:56 +02:00
{
2024-10-21 13:27:52 +02:00
var result = new ImportSupportConceptResultDC ( ) ;
2024-09-18 21:50:00 +02:00
var customer = FindOrCreateCustomer ( hidc ) ;
2024-10-21 13:27:52 +02:00
if ( ! customer . Oid . HasValue )
{
//Neue Klienten werden noch nicht unterstützt.
result . ImportMessage = String . Format ( "Klient/in '{0}, {1}', geb. {2:dd.MM.yyyy} wurde nicht gefunden. Bitte legen Sie zunächst den/die Klient/in an, bevor Sie die Hilfeplanziele importieren." , customer . Person . LastName , customer . Person . FirstName , customer . Person . DateOfBirth ) ;
return result ;
}
2024-09-18 21:50:00 +02:00
var supportConcept = FindOrCreateSupportConcept ( hidc , customer ) ;
2024-10-21 13:27:52 +02:00
if ( supportConcept = = null )
{
//Neue Klienten werden noch nicht unterstützt.
result . ImportMessage = String . Format ( "Es wurde kein passender Hilfeplan für Klient/in '{0}, {1}', geb. {2:dd.MM.yyyy} gefunden. Bitte legen Sie zunächst einen Hilfeplan an, bevor Sie die Ziele importieren." , customer . Person . LastName , customer . Person . FirstName , customer . Person . DateOfBirth ) ;
return result ;
}
2024-09-18 21:50:00 +02:00
2024-10-21 13:27:52 +02:00
var scDC = MapperFactory . SupportConceptDC_SupportConcept . MapToNewDC ( supportConcept ) ;
2024-09-18 21:50:00 +02:00
2024-10-21 13:27:52 +02:00
MatchZiele ( hidc , scDC ) ;
2024-09-18 21:50:00 +02:00
2024-10-21 13:27:52 +02:00
result . ImportedSupportConcept = scDC ;
2024-10-25 01:07:02 +02:00
//result.ImportMessage = "Import erfolgreich";
2024-10-21 13:27:52 +02:00
return result ;
}
2024-09-18 21:50:00 +02:00
2024-10-21 13:27:52 +02:00
private void MatchZiele ( HilfeplanImportDC hidc , SupportConceptDC supportConcept )
{
var types = new List < ValueListEntryType > ( ) ;
types . Add ( ValueListEntryType . SupportConceptGoalCategoryType ) ;
var alleZiele = MapperFactory . ValueListEntryDC_ValueListEntry . MapToNewDCs ( DAOFactory . SearchDAO . FindValueListEntries ( types ) . Where ( ve = > ve . IsActive = = ActivationTypeId . Active ) ) . ToList ( ) ;
if ( hidc . Ziele ! = null )
2024-09-18 21:50:00 +02:00
{
2024-10-21 13:27:52 +02:00
foreach ( var importziel in hidc . Ziele )
{
if ( ! String . IsNullOrEmpty ( importziel . Bereich ) )
{
ValueListEntryDC vorhandenerBereich = SucheBereichsZiel ( alleZiele , importziel . Bereich ) ;
if ( vorhandenerBereich = = null )
{
//Todo Bereich anlegen?
}
else
{
var ziel = SucheZiel ( supportConcept , importziel . ZielName ) ;
if ( ziel = = null )
{
ziel = new ValueListEntryDC ( ) ;
ziel . Parent = vorhandenerBereich ;
ziel . ParentOid = vorhandenerBereich . ValueListEntryOid ;
ziel . TypeDescription = importziel . ZielName ;
ziel . IsActive = true ;
ziel . Type = ValueListEntryType . SupportConceptIndividualGoalCategoryType ;
supportConcept . Goals . Add ( ziel ) ;
}
foreach ( var importMass in importziel . Massnahmen )
{
2024-10-25 01:07:02 +02:00
MatchMassnahme ( importMass , supportConcept , ziel ) ;
2024-10-21 13:27:52 +02:00
}
}
}
}
2024-09-18 21:50:00 +02:00
}
2024-10-21 13:27:52 +02:00
}
2024-10-25 01:07:02 +02:00
private void MatchMassnahme ( HilfeplanImportZielDC importMass , SupportConceptDC supportConcept , ValueListEntryDC parentZiel )
{
var splitByNewLine = importMass . ZielName . Split ( new [ ] { '\r' , '\n' } , StringSplitOptions . RemoveEmptyEntries ) ;
foreach ( var massnahmeName in splitByNewLine )
{
var massnahme = SucheZiel ( supportConcept , massnahmeName ) ;
if ( massnahme = = null )
{
massnahme = new ValueListEntryDC ( ) ;
massnahme . Parent = parentZiel ;
massnahme . ParentOid = parentZiel . ValueListEntryOid ;
massnahme . TypeDescription = massnahmeName ;
massnahme . IsActive = true ;
massnahme . Type = ValueListEntryType . SupportConceptIndividualGoalType ;
supportConcept . Goals . Add ( massnahme ) ;
}
}
}
public virtual ValueListEntryDC SucheZiel ( SupportConceptDC supportConcept , string zielName )
2024-10-21 13:27:52 +02:00
{
return supportConcept . Goals . Where ( z = > z . DisplayName ! = null & & z . DisplayName . Contains ( zielName ) ) . FirstOrDefault ( ) ;
2024-06-19 16:13:56 +02:00
}
2024-10-21 13:27:52 +02:00
public virtual ValueListEntryDC SucheBereichsZiel ( List < ValueListEntryDC > alleZiele , string bereich )
2024-09-18 21:50:00 +02:00
{
2024-10-21 13:27:52 +02:00
var ziel = alleZiele . Where ( z = > z . DisplayName ! = null & & z . DisplayName . Contains ( bereich ) ) . FirstOrDefault ( ) ;
if ( ziel = = null )
{
bereich = bereich . Replace ( "Lebensbereich" , "" ) . Trim ( ) ;
ziel = alleZiele . Where ( z = > z . DisplayName ! = null & & z . DisplayName . Contains ( bereich ) ) . FirstOrDefault ( ) ;
}
return ziel ;
2024-09-18 21:50:00 +02:00
}
private Customer FindOrCreateCustomer ( HilfeplanImportDC hidc )
{
if ( hidc . Gruppen ! = null )
{
var stammdaten = hidc . Gruppen . FirstOrDefault ( g = > g . Label = = "Stammdaten" ) ;
String firstname = GetValueFromImportItem ( stammdaten , "Firstname" ) ;
String lastname = GetValueFromImportItem ( stammdaten , "Lastname" ) ;
2024-10-21 13:27:52 +02:00
if ( String . IsNullOrEmpty ( firstname ) & & String . IsNullOrEmpty ( lastname ) )
{
String name = GetValueFromImportItem ( stammdaten , "LastnameFirstname" ) ;
if ( ! String . IsNullOrEmpty ( name ) )
{
var names = name . Split ( "," ) ;
if ( names . Count > 0 )
{
lastname = names [ 0 ] . Trim ( ) ;
if ( names . Count > 1 )
{
firstname = names [ 1 ] . Trim ( ) ;
}
}
}
}
2024-09-18 21:50:00 +02:00
DateTime ? birthdate = null ;
if ( DateTime . TryParse ( GetValueFromImportItem ( stammdaten , "Birthdate" ) , out var dt ) )
{
birthdate = dt ;
}
Customer customer = null ;
if ( ! String . IsNullOrEmpty ( firstname ) & & ! String . IsNullOrEmpty ( lastname ) & & birthdate . HasValue )
{
customer = DAOFactory . SearchDAO . FindCustomer ( firstname , lastname , birthdate . Value ) . FirstOrDefault ( ) ;
}
if ( customer = = null )
{
2024-10-21 13:27:52 +02:00
customer = new Customer ( ) ;
customer . Person = new Person ( ) ;
customer . Person . FirstName = firstname ;
customer . Person . LastName = lastname ;
customer . Person . DateOfBirth = birthdate ;
2024-09-18 21:50:00 +02:00
//Create Customer
}
if ( stammdaten ! = null & & stammdaten . Items ! = null )
{
// liste.Add(ErstelleStammdatenFeld("BEI_NRW für den Zeitraum vom", "ApprovalPeriod", zeilen, idx, out idx));
// liste.Add(ErstelleStammdatenFeld("GP-Nummer/Az", "CustomerReferenceNumber", zeilen, idx, out idx));
// liste.Add(ErstelleStammdatenFeld("Name", "Lastname", zeilen, idx, out idx));
// liste.Add(ErstelleStammdatenFeld("Vorname", "Firstname", zeilen, idx, out idx));
// liste.Add(ErstelleStammdatenFeld("Titel", "Titel", zeilen, idx, out idx));
// liste.Add(ErstelleStammdatenFeld("Geburtsdatum", "Birthdate", zeilen, idx, out idx));
// liste.Add(ErstelleStammdatenFeld("Geschlecht", "Sex", zeilen, idx, out idx));
// liste.Add(ErstelleStammdatenFeld("Nationalität", "Nationality", zeilen, idx, out idx));
// liste.Add(ErstelleStammdatenFeld("Beruf", "Job", zeilen, idx, out idx));
// liste.Add(ErstelleStammdatenFeld("Familienstand", "FamilyStatus", zeilen, idx, out idx));
// liste.Add(ErstelleStammdatenFeld("Anzahl und Alter der Kinder", "Children", zeilen, idx, out idx));
// liste.Add(ErstelleStammdatenFeld("PLZ", "PostalCode", zeilen, idx, out idx));
// liste.Add(ErstelleStammdatenFeld("Ort", "Town", zeilen, idx, out idx));
// liste.Add(ErstelleStammdatenFeld("Straße", "Street", zeilen, idx, out idx));
// liste.Add(ErstelleStammdatenFeld("Telefon", "Phone", zeilen, idx, out idx));
// liste.Add(ErstelleStammdatenFeld("Fax", "Fax", zeilen, idx, out idx));
// liste.Add(ErstelleStammdatenFeld("E-Mail", "EMail", zeilen, idx, out idx));
}
return customer ;
}
return null ;
}
private string GetValueFromImportItem ( HilfeplanImportItemDC stammdaten , string fieldName )
{
if ( stammdaten ! = null & & stammdaten . Items ! = null )
{
var item = stammdaten . Items . FirstOrDefault ( i = > i . FieldName = = fieldName ) ;
if ( item ! = null )
{
return item . Content ;
}
}
return null ;
}
private SupportConcept FindOrCreateSupportConcept ( HilfeplanImportDC hidc , Customer customer )
{
if ( hidc . SupportConceptOid . HasValue )
{
return DAOFactory . GenericDAO . LoadByID < SupportConcept > ( hidc . SupportConceptOid . Value ) ;
}
else
{
var stammdaten = hidc . Gruppen . FirstOrDefault ( g = > g . Label = = "Stammdaten" ) ;
var approvalPeriod = GetValueFromImportItem ( stammdaten , "ApprovalPeriod" ) ;
if ( ! String . IsNullOrEmpty ( approvalPeriod ) )
{
}
}
return null ;
}
2016-06-27 01:45:38 +02:00
}
}