2016-06-27 01:45:38 +02:00
using System ;
2018-10-08 11:57:16 +02:00
using System.Collections ;
2016-06-27 01:45:38 +02:00
using System.Collections.Generic ;
2022-02-10 11:06:03 +01:00
using System.Diagnostics ;
2016-06-27 01:45:38 +02:00
using System.Linq ;
using System.Text ;
2017-12-22 18:09:52 -04:00
using System.Text.RegularExpressions ;
2016-06-27 01:45:38 +02:00
using BeWo.Data.Entities ;
2022-02-10 11:06:03 +01:00
using BeWo.Data.Utils ;
2020-12-16 21:49:47 +01:00
using BeWo.View.Navigation.Filter ;
2016-06-27 01:45:38 +02:00
using BS.Shared.Extensions ;
2016-11-30 13:42:50 +01:00
using NHibernate ;
2016-06-27 01:45:38 +02:00
using NHibernate.Criterion ;
2016-11-30 13:42:50 +01:00
using NHibernate.Engine ;
using NHibernate.Impl ;
using NHibernate.Loader.Criteria ;
using NHibernate.Persister.Entity ;
2016-06-27 01:45:38 +02:00
using NHibernate.SqlCommand ;
using BS.Shared.Core ;
using BS.Shared ;
2018-10-24 19:32:12 +02:00
using BS.Shared.DataContracts ;
2020-07-13 16:25:43 +02:00
using DevExpress.XtraScheduler ;
using DevExpress.XtraScheduler.Compatibility ;
2021-02-17 16:59:26 +01:00
using NHibernate.Transform ;
2018-10-24 19:32:12 +02:00
using static System . String ;
2020-07-13 16:25:43 +02:00
using Appointment = BeWo . Data . Entities . Appointment ;
2016-06-27 01:45:38 +02:00
using Login = BeWo . Data . Entities . Login ;
2020-07-13 16:25:43 +02:00
using Resource = BeWo . Data . Entities . Resource ;
2016-06-27 01:45:38 +02:00
namespace BeWo.Data.Access
{
public class SearchDAO : AbstractBaseDAO
{
2019-08-08 14:47:53 +02:00
private static readonly Regex RecurrenceIdRegex = new Regex ( "(Id=\\\"[a-z0-9-]+\\\")" ) ;
2018-10-24 19:32:12 +02:00
2016-06-27 01:45:38 +02:00
public IEnumerable < ValueListEntry > FindValueListEntry ( ValueListEntryType pType )
{
return CreateCriteria < ValueListEntry > ( ) . Add ( Restrictions . Eq ( ValueListEntry . PropertyName_Type , pType ) ) . AddOrder ( Order . Asc ( ValueListEntry . PropertyName_Value ) ) . List < ValueListEntry > ( ) ;
}
public IEnumerable < ValueListEntry > FindValueListEntries ( List < ValueListEntryType > pTypes )
{
return CreateCriteria < ValueListEntry > ( ) . Add ( Restrictions . In ( ValueListEntry . PropertyName_Type , pTypes ) ) . AddOrder ( Order . Asc ( ValueListEntry . PropertyName_Value ) ) . List < ValueListEntry > ( ) ;
}
public virtual IEnumerable < Employee > FindEmployee ( string pFirstName , string pLastName , string pPersonnelNumber )
{
return CreateCriteria < Employee > ( )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Like ( Employee . PropertyName_PersonnelNumber , pPersonnelNumber , MatchMode . Anywhere ) )
. CreateCriteria ( Employee . PropertyName_Person , JoinType . InnerJoin )
2016-06-27 01:45:38 +02:00
. Add ( Restrictions . Like ( Person . PropertyName_FirstName , pFirstName , MatchMode . Anywhere ) )
. Add ( Restrictions . Like ( Person . PropertyName_LastName , pLastName , MatchMode . Anywhere ) )
2021-04-19 04:43:31 +02:00
. List < Employee > ( ) ;
2016-06-27 01:45:38 +02:00
}
2021-04-19 04:43:31 +02:00
public virtual Employee FindEmployeeByFullname ( string pFullname )
{
var q = Session . CreateSQLQuery ( Format ( "SELECT e.oid FROM employee e join Person p on e.personoid = p.oid WHERE CONCAT_WS(' ', FirstName, LastName) LIKE '%{0}%' AND Type = 1" , pFullname ) ) ;
var x = q . List < long > ( ) ;
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
return x . Count > 0 ? DAOFactory . GenericDAO . GetByID < Employee > ( x . Last ( ) ) : null ;
}
2016-06-27 01:45:38 +02:00
public virtual IEnumerable < Wohnheim > FindWohnheim ( string pwohnheimName , string pWohnheimStrasse , string pWohnheimPlz )
{
return CreateCriteria < Wohnheim > ( )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Like ( Wohnheim . PropertyName_WohnheimName , pwohnheimName , MatchMode . Anywhere ) )
. CreateCriteria ( Wohnheim . PropertyName_Wohnheim , JoinType . InnerJoin )
2016-06-27 01:45:38 +02:00
. Add ( Restrictions . Like ( Wohnheim . PropertyName_Strasse , pWohnheimStrasse , MatchMode . Anywhere ) )
. Add ( Restrictions . Like ( Wohnheim . PropertyName_PlZ , pWohnheimPlz , MatchMode . Anywhere ) )
2021-04-19 04:43:31 +02:00
. List < Wohnheim > ( ) ;
2016-06-27 01:45:38 +02:00
}
public virtual Wohnheim FindWohnheimByFullname ( string pWohnheimName )
{
2018-10-24 19:32:12 +02:00
var q = Session . CreateSQLQuery ( Format ( "SELECT Oid FROM Wohnheim WHERE CONCAT_WS(' ', WohnheimName) LIKE '%{0}%'" , pWohnheimName ) ) ;
2016-06-27 01:45:38 +02:00
var x = q . List < long > ( ) ;
return x . Count > 0 ? DAOFactory . GenericDAO . GetByID < Wohnheim > ( x . First ( ) ) : null ;
}
public virtual IEnumerable < Customer > FindCustomer ( string pFirstName , string pLastName , string pReferenceNumber )
{
return CreateCriteria < Customer > ( )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Like ( Customer . PropertyName_ReferenceNumber , pReferenceNumber , MatchMode . Anywhere ) )
. CreateCriteria ( Customer . PropertyName_Person , JoinType . InnerJoin )
2016-06-27 01:45:38 +02:00
. Add ( Restrictions . Like ( Person . PropertyName_FirstName , pFirstName , MatchMode . Anywhere ) )
. Add ( Restrictions . Like ( Person . PropertyName_LastName , pLastName , MatchMode . Anywhere ) )
2021-04-19 04:43:31 +02:00
. List < Customer > ( ) ;
2016-06-27 01:45:38 +02:00
}
2018-11-22 14:05:45 +01:00
public virtual IList < Customer > FindCustomer ( string pFirstName , string pLastName , DateTime pBirthDate )
{
return CreateCriteriaIsActiveOrArchived < Customer > ( )
. CreateCriteria ( Customer . PropertyName_Person , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( Person . PropertyName_FirstName , pFirstName ) )
. Add ( Restrictions . Eq ( Person . PropertyName_LastName , pLastName ) )
. Add ( Restrictions . Eq ( Person . PropertyName_DateOfBirth , pBirthDate ) )
. List < Customer > ( ) ;
}
2021-05-03 15:13:53 +02:00
public virtual IList < DienstEintrag > GetAllDienstEintraege ( long wOid , DateTime start , DateTime end )
{
var c = CreateCriteria < DienstEintrag > ( )
. Add ( Restrictions . Eq ( "WohnheimOid" , wOid ) )
2022-12-15 13:21:56 +01:00
. Add ( Restrictions . Between ( "Datum" , start , end ) )
. Add ( Restrictions . Eq ( "IsActive" , ActivationTypeId . Active ) ) ;
2021-05-03 15:13:53 +02:00
return c . List < DienstEintrag > ( ) ;
}
public virtual IList < Employee > GetEmployeeForWohnheim ( long wOid )
{
var c = CreateCriteria < Wohnheim > ( )
. Add ( Restrictions . Eq ( "WohnheimOid" , wOid ) ) ;
return c . List < Employee > ( ) ;
}
2016-06-27 01:45:38 +02:00
public virtual IEnumerable < Person > FindPerson ( string pFirstName , string pLastName , DateTime ? pDateOfBirth , PersonType ? pPersonType )
{
var lCriteria = CreateCriteria < Person > ( )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Like ( Person . PropertyName_FirstName , pFirstName , MatchMode . Anywhere ) )
. Add ( Restrictions . Like ( Person . PropertyName_LastName , pLastName , MatchMode . Anywhere ) ) ;
if ( pDateOfBirth ! = null )
2016-06-27 01:45:38 +02:00
lCriteria . Add ( Restrictions . Eq ( Person . PropertyName_DateOfBirth , pDateOfBirth ) ) ;
2021-04-19 04:43:31 +02:00
if ( pPersonType ! = null )
2016-06-27 01:45:38 +02:00
lCriteria . Add ( Restrictions . Eq ( Person . PropertyName_Type , pPersonType ) ) ;
return lCriteria . List < Person > ( ) ;
}
public virtual IEnumerable < Organisation > FindOrganisation ( string pName , bool pOnlyCostBearer )
{
var lCriteria = CreateCriteria < Organisation > ( )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Like ( Organisation . PropertyName_Name , pName , MatchMode . Anywhere ) ) ;
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
if ( pOnlyCostBearer )
2016-06-27 01:45:38 +02:00
lCriteria . Add ( Restrictions . IsNotNull ( Organisation . PropertyName_CostBearer ) ) ;
return lCriteria . List < Organisation > ( ) ;
}
public virtual IEnumerable < Team > FindTeams ( string pTeamName , string pLeaderFirstName , string pLeaderLastName )
{
return CreateCriteria < Team > ( )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Like ( Team . PropertyName_Name , pTeamName , MatchMode . Anywhere ) )
. CreateCriteria ( Team . PropertyName_Leader , JoinType . InnerJoin )
2016-06-27 01:45:38 +02:00
. CreateCriteria ( Employee . PropertyName_Person )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Like ( Person . PropertyName_FirstName , pLeaderFirstName , MatchMode . Anywhere ) )
. Add ( Restrictions . Like ( Person . PropertyName_LastName , pLeaderLastName , MatchMode . Anywhere ) )
. List < Team > ( ) ;
}
public virtual IList < Team > FindTeamsOfEmployee ( long employeeOid )
{
return CreateCriteriaIsActiveOrArchived < Team > ( )
. CreateCriteria ( Team . PropertyName_MemberList , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_Oid , employeeOid ) )
. List < Team > ( ) ;
}
public virtual IEnumerable < Team > FindLeadingTeams ( long employeeOid )
{
return CreateCriteriaIsActiveOrArchived < Team > ( )
. CreateCriteria ( Team . PropertyName_Leader , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_Oid , employeeOid ) )
. List < Team > ( ) ;
}
2016-06-27 01:45:38 +02:00
2017-02-01 13:53:59 +01:00
public virtual IList < Team > FindAllActiveTeamsOfEmployee ( long employeeOid )
{
return CreateCriteriaIsActive < Team > ( )
2021-04-19 04:43:31 +02:00
. CreateAlias ( Team . PropertyName_MemberList , "m" , JoinType . InnerJoin )
. CreateAlias ( Team . PropertyName_Leader , "l" , JoinType . InnerJoin )
. Add ( Restrictions . Disjunction ( )
. Add ( Restrictions . Eq ( "m." + BeWoEntityBase . PropertyName_Oid , employeeOid ) )
. Add ( Restrictions . Eq ( "l." + BeWoEntityBase . PropertyName_Oid , employeeOid ) ) )
. List < Team > ( ) . Distinct ( ) . ToList ( ) ;
2017-02-01 13:53:59 +01:00
}
2017-09-14 19:03:26 +02:00
public virtual IList < Customer > FindCustomerOfTeam ( long teamOid )
{
return CreateCriteriaIsActiveOrArchived < Customer > ( )
. CreateCriteria ( Customer . PropertyName_Team2CustomerList , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( Team2Customer . PropertyName_TeamOid , teamOid ) )
. List < Customer > ( ) ;
}
2016-06-27 01:45:38 +02:00
public IEnumerable < ResourceBookingSequence > FindBookings ( long pResourceOid , DateTime pSpanStart , DateTime pSpanEnd )
{
var lResult = CreateCriteria < ResourceBookingSequence > ( )
2021-04-19 04:43:31 +02:00
. CreateAlias ( ResourceBookingSequence . PropertyName_Resource , "r" )
. CreateAlias ( ResourceBookingSequence . PropertyName_Details , "d" )
. Add ( Restrictions . Eq ( "r." + BeWoEntityBase . PropertyName_Oid , pResourceOid ) )
. Add ( Restrictions . Eq ( "d." + ResourceBooking . PropertyName_SequencePosition , 0 ) )
. Add ( Restrictions . Disjunction ( )
. Add ( Restrictions . Between ( "d." + ResourceBooking . PropertyName_Start , pSpanStart , pSpanEnd ) )
. Add ( Restrictions . Between ( ResourceBookingSequence . PropertyName_SequenceEnd , pSpanStart , pSpanEnd ) )
. Add ( Restrictions . Conjunction ( )
. Add ( Restrictions . Le ( "d." + ResourceBooking . PropertyName_Start , pSpanStart ) )
. Add ( Restrictions . Ge ( ResourceBookingSequence . PropertyName_SequenceEnd , pSpanEnd ) )
)
)
. List < ResourceBookingSequence > ( ) ;
2016-06-27 01:45:38 +02:00
return lResult ;
}
public IEnumerable < ResourceBookingSequence > FindBookings ( DateTime pSpanStart , DateTime pSpanEnd )
{
var lResult = CreateCriteria < ResourceBookingSequence > ( )
2021-04-19 04:43:31 +02:00
. CreateAlias ( ResourceBookingSequence . PropertyName_Details , "d" )
. Add ( Restrictions . Eq ( "d." + ResourceBooking . PropertyName_SequencePosition , 0 ) )
. Add ( Restrictions . Disjunction ( )
. Add ( Restrictions . Between ( "d." + ResourceBooking . PropertyName_Start , pSpanStart , pSpanEnd ) )
. Add ( Restrictions . Between ( ResourceBookingSequence . PropertyName_SequenceEnd , pSpanStart , pSpanEnd ) )
. Add ( Restrictions . Conjunction ( )
. Add ( Restrictions . Le ( "d." + ResourceBooking . PropertyName_Start , pSpanStart ) )
. Add ( Restrictions . Ge ( ResourceBookingSequence . PropertyName_SequenceEnd , pSpanEnd ) )
)
)
. List < ResourceBookingSequence > ( ) ;
2016-06-27 01:45:38 +02:00
return lResult ;
}
2023-01-26 12:55:56 +01:00
public void RemoveServiceRecordsFromAppointments ( IEnumerable < long > enumerable )
{
throw new NotImplementedException ( ) ;
}
2016-06-27 01:45:38 +02:00
public List < ServiceRecord > FindServiceRecords ( long? pEmployeeOid , long? pCostBearer2SupportConceptOid )
{
var c = CreateCriteria < ServiceRecord > ( )
. CreateAlias ( ServiceRecord . PropertyName_Employee , "e" , JoinType . InnerJoin ) ;
2021-04-19 04:43:31 +02:00
if ( pCostBearer2SupportConceptOid . HasValue )
2016-06-27 01:45:38 +02:00
{
c = c . CreateAlias ( ServiceRecord . PropertyName_SupportConcept , "sc" , JoinType . InnerJoin )
2021-04-19 04:43:31 +02:00
. CreateAlias ( "sc." + SupportConcept . PropertyName_CostBearer2SupportConceptList , "c2s" , JoinType . InnerJoin ) ;
2016-06-27 01:45:38 +02:00
}
2021-04-19 04:43:31 +02:00
if ( pEmployeeOid . HasValue )
2016-06-27 01:45:38 +02:00
c = c . Add ( Restrictions . Eq ( "e." + BeWoEntityBase . PropertyName_Oid , pEmployeeOid ) ) ;
2021-04-19 04:43:31 +02:00
if ( pCostBearer2SupportConceptOid . HasValue )
2016-06-27 01:45:38 +02:00
c = c . Add ( Restrictions . Eq ( "c2s." + BeWoEntityBase . PropertyName_Oid , pCostBearer2SupportConceptOid ) ) ;
return c . List < ServiceRecord > ( ) . ToList ( ) ;
}
2021-04-19 04:43:31 +02:00
public List < ServiceRecord > FindServiceRecordsForSupportConcept ( long pSupportConceptOid )
{
var c = CreateCriteria < ServiceRecord > ( )
. CreateAlias ( ServiceRecord . PropertyName_SupportConcept , "sc" , JoinType . InnerJoin ) ;
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
c = c . Add ( Restrictions . Eq ( "sc." + BeWoEntityBase . PropertyName_Oid , pSupportConceptOid ) ) ;
return c . List < ServiceRecord > ( ) . ToList ( ) ;
}
2016-06-27 01:45:38 +02:00
2020-08-17 15:50:00 +02:00
public List < ServiceRecord > FindServiceRecords ( long? supportConceptOid , long? costBearer2SupportConceptOid , long? serviceCategoryOid , DateTime ? start , DateTime ? end )
{
var c = CreateCriteria < ServiceRecord > ( )
. CreateAlias ( ServiceRecord . PropertyName_Employee , "e" , JoinType . InnerJoin ) ;
2021-04-19 04:43:31 +02:00
if ( supportConceptOid . HasValue )
2020-08-17 15:50:00 +02:00
{
c = c . CreateAlias ( ServiceRecord . PropertyName_SupportConcept , "sc" , JoinType . InnerJoin ) ;
}
2021-04-19 04:43:31 +02:00
if ( serviceCategoryOid . HasValue )
2020-08-17 15:50:00 +02:00
{
c = c . CreateAlias ( ServiceRecord . PropertyName_ServiceDescription , "sd" , JoinType . InnerJoin )
. CreateAlias ( "sd." + ServiceDescription . PropertyName_ServiceCategory , "cat" , JoinType . InnerJoin ) ;
}
2021-04-19 04:43:31 +02:00
if ( supportConceptOid . HasValue )
2020-08-17 15:50:00 +02:00
{
c = c . Add ( Restrictions . Eq ( "sc." + BeWoEntityBase . PropertyName_Oid , supportConceptOid ) ) ;
}
2021-04-19 04:43:31 +02:00
if ( costBearer2SupportConceptOid . HasValue )
2020-08-17 15:50:00 +02:00
{
c = c . Add ( Restrictions . Eq ( ServiceRecord . PropertyName_CostBearer2SupportConceptOid , costBearer2SupportConceptOid ) ) ;
}
2021-04-19 04:43:31 +02:00
if ( serviceCategoryOid . HasValue )
2020-08-17 15:50:00 +02:00
{
c = c . Add ( Restrictions . Eq ( "cat." + BeWoEntityBase . PropertyName_Oid , serviceCategoryOid ) ) ;
}
2021-04-19 04:43:31 +02:00
if ( start . HasValue & & end . HasValue )
2020-08-17 15:50:00 +02:00
{
c . Add ( Restrictions . Between ( ServiceRecord . PropertyName_Start , start , end ) ) ;
}
//{
// c = c.CreateAlias(ServiceRecord.PropertyName_SupportConcept, "sc", JoinType.InnerJoin)
// .CreateAlias("sc." + SupportConcept.PropertyName_CostBearer2SupportConceptList, "c2s", JoinType.InnerJoin);
//}
//if (pEmployeeOid.HasValue)
// c = c.Add(Restrictions.Eq("e." + BeWoEntityBase.PropertyName_Oid, pEmployeeOid));
return c . List < ServiceRecord > ( ) . ToList ( ) ;
}
2016-06-27 01:45:38 +02:00
public IList < SupportConceptApprovalPeriod2Employee > FindSupportConceptApprovalPeriod2Employees ( Employee emp )
{
var c = CreateCriteria < SupportConceptApprovalPeriod2Employee > ( )
. Add ( Restrictions . Eq ( SupportConceptApprovalPeriod2Employee . PropertyName_Employee , emp ) ) ;
return c . List < SupportConceptApprovalPeriod2Employee > ( ) . ToList ( ) ;
}
2017-07-25 10:52:20 +02:00
public IList < SupportConceptApprovalPeriod2Employee > FindSupportConceptApprovalPeriod2Employees ( SupportConceptApprovalPeriod scap )
{
var c = CreateCriteria < SupportConceptApprovalPeriod2Employee > ( )
. Add ( Restrictions . Eq ( SupportConceptApprovalPeriod2Employee . PropertyName_SupportConceptApprovalPeriod , scap ) ) ;
return c . List < SupportConceptApprovalPeriod2Employee > ( ) . ToList ( ) ;
}
2016-06-27 01:45:38 +02:00
public IEnumerable < ServiceRecord > FindServiceRecordsInSpan ( long pCostBearer2SupportConceptOid , DateTimeSpan period )
{
var criteria = CreateCriteria < ServiceRecord > ( )
. Add ( Restrictions . Eq ( ServiceRecord . PropertyName_CostBearer2SupportConceptOid , pCostBearer2SupportConceptOid ) ) ;
2021-04-19 04:43:31 +02:00
if ( period ! = null )
2016-06-27 01:45:38 +02:00
criteria =
criteria . Add (
Restrictions . Or (
Restrictions . Between ( ServiceRecord . PropertyName_Start , period . StartDateTime , period . EndDateTime ) ,
Restrictions . Between ( ServiceRecord . PropertyName_End , period . StartDateTime , period . EndDateTime ) ) ) ;
return criteria . List < ServiceRecord > ( ) . ToList ( ) ;
}
public IEnumerable < ServiceRecordHistory > FindServiceRecordHistory ( long serviceRecordOid )
{
var criteria = CreateCriteria < ServiceRecordHistory > ( )
. Add ( Restrictions . Eq ( ServiceRecordHistory . PropertyName_ServiceRecordOid , serviceRecordOid ) ) ;
return criteria . List < ServiceRecordHistory > ( ) . ToList ( ) ;
}
public IEnumerable < ServiceRecord > FindEmployeeServiceRecordsWithoutCustomer ( long pEmployeeOid , long? days )
{
var c = CreateCriteria < ServiceRecord > ( )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Eq ( ServiceRecord . PropertyName_EmployeeOid , pEmployeeOid ) )
. Add ( Restrictions . IsNull ( ServiceRecord . PropertyName_CostBearer2SupportConceptOid ) ) ;
2023-03-29 15:49:20 +02:00
2021-04-19 04:43:31 +02:00
if ( days . HasValue )
{
var minDate = DateTime . Now . Date . AddDays ( - 1 * days . Value ) ;
c . Add ( Restrictions . Ge ( ServiceRecord . PropertyName_Start , minDate ) ) ;
}
2016-06-27 01:45:38 +02:00
return c . List < ServiceRecord > ( ) . ToList ( ) ;
}
2021-04-19 04:43:31 +02:00
public IEnumerable < ServiceRecord > FindEmployeeServiceRecordsWithoutCustomerInSpan ( long pEmployeeOid , DateTimeSpan period )
{
var criteria = CreateCriteria < ServiceRecord > ( )
. Add ( Restrictions . Eq ( ServiceRecord . PropertyName_EmployeeOid , pEmployeeOid ) )
. Add ( Restrictions . IsNull ( ServiceRecord . PropertyName_CostBearer2SupportConceptOid ) ) ;
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
if ( period ! = null )
{
criteria =
criteria . Add (
Restrictions . Or (
Restrictions . Between ( ServiceRecord . PropertyName_Start , period . StartDateTime , period . EndDateTime ) ,
Restrictions . Between ( ServiceRecord . PropertyName_End , period . StartDateTime , period . EndDateTime ) ) ) ;
}
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
return criteria . List < ServiceRecord > ( ) . ToList ( ) ;
}
2016-06-27 01:45:38 +02:00
2017-03-14 12:48:31 +01:00
public IEnumerable < ServiceRecord > FindEmployeeServiceRecordsWithoutCustomerWithStartEndDate ( long pEmployeeOid , DateTime start , DateTime ende )
{
var c = CreateCriteria < ServiceRecord > ( )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Eq ( ServiceRecord . PropertyName_EmployeeOid , pEmployeeOid ) )
. Add ( Restrictions . IsNull ( ServiceRecord . PropertyName_CostBearer2SupportConceptOid ) ) ;
var max = ende . Date . AddDays ( 1 ) ;
2017-03-14 12:48:31 +01:00
2021-04-19 04:43:31 +02:00
c . Add ( Restrictions . Ge ( ServiceRecord . PropertyName_Start , start . Date ) )
. Add ( Restrictions . Lt ( ServiceRecord . PropertyName_End , max . Date ) ) ;
2017-03-14 12:48:31 +01:00
return c . List < ServiceRecord > ( ) . ToList ( ) ;
}
public IList < ServiceRecord > FindEmployeeServiceRecords ( long pEmployeeOid , DateTimeSpan pSpan , long? customerOid , ServiceRecordTypeId ? srTypeFilter )
2016-06-27 01:45:38 +02:00
{
var lCriteria = CreateCriteria < ServiceRecord > ( )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Eq ( ServiceRecord . PropertyName_EmployeeOid , pEmployeeOid ) ) ;
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
if ( pSpan ! = null )
lCriteria . Add ( Restrictions . Between ( ServiceRecord . PropertyName_Start , pSpan . StartDateTime , pSpan . EndDateTime ) ) ;
if ( customerOid ! = null )
2016-06-27 01:45:38 +02:00
lCriteria . Add ( Restrictions . Eq ( ServiceRecord . PropertyName_CustomerOid , customerOid . Value ) ) ;
2021-04-19 04:43:31 +02:00
if ( srTypeFilter . HasValue )
{
lCriteria . Add ( Restrictions . Eq ( ServiceRecord . PropertyName_ServiceRecordType , srTypeFilter . Value ) ) ;
}
2016-06-27 01:45:38 +02:00
var result = lCriteria . List < ServiceRecord > ( ) . ToList ( ) ;
return result ;
}
public IList < ServiceRecord > FindCustomerServiceRecords ( long customerOid )
{
var lCriteria = CreateCriteria < ServiceRecord > ( )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Eq ( ServiceRecord . PropertyName_CustomerOid , customerOid ) ) ;
2016-06-27 01:45:38 +02:00
return lCriteria . List < ServiceRecord > ( ) ;
}
2021-04-19 04:43:31 +02:00
public IList < ServiceRecord > FindCustomerServiceRecords ( long customerOid , DateTimeSpan pSpan , long? employeeOid , ServiceRecordTypeId ? srTypeFilter , bool includeEndDateInSearch )
2016-06-27 01:45:38 +02:00
{
var lCriteria = CreateCriteria < ServiceRecord > ( )
2017-06-28 09:00:09 +02:00
. Add ( Restrictions . Eq ( ServiceRecord . PropertyName_CustomerOid , customerOid ) ) ;
2021-04-19 04:43:31 +02:00
if ( includeEndDateInSearch )
{
var orCriteria = Restrictions . Or (
Restrictions . Between ( ServiceRecord . PropertyName_Start , pSpan . StartDateTime , pSpan . EndDateTime ) ,
Restrictions . Between ( ServiceRecord . PropertyName_End , pSpan . StartDateTime , pSpan . EndDateTime ) ) ;
2017-06-28 09:00:09 +02:00
orCriteria = Restrictions . Or ( orCriteria ,
Restrictions . And (
2021-04-19 04:43:31 +02:00
Restrictions . Le ( ServiceRecord . PropertyName_Start , pSpan . EndDateTime ) ,
2017-06-28 09:00:09 +02:00
Restrictions . Ge ( ServiceRecord . PropertyName_End , pSpan . StartDateTime ) ) ) ;
lCriteria . Add ( orCriteria ) ;
2021-04-19 04:43:31 +02:00
}
else
{
lCriteria . Add ( Restrictions . Between ( ServiceRecord . PropertyName_Start , pSpan . StartDateTime , pSpan . EndDateTime ) ) ;
}
if ( employeeOid ! = null )
2016-06-27 01:45:38 +02:00
lCriteria . Add ( Restrictions . Eq ( ServiceRecord . PropertyName_EmployeeOid , employeeOid . Value ) ) ;
2021-04-19 04:43:31 +02:00
if ( srTypeFilter . HasValue )
{
lCriteria . Add ( Restrictions . Eq ( ServiceRecord . PropertyName_ServiceRecordType , srTypeFilter . Value ) ) ;
}
2016-06-27 01:45:38 +02:00
return lCriteria . List < ServiceRecord > ( ) ;
}
public IEnumerable < ServiceRecord > FindServiceRecordsInSpan ( DateTimeSpan pSpan , ServiceRecordTypeId ? srTypeFilter )
{
var lCriteria = CreateCriteria < ServiceRecord > ( )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Between ( ServiceRecord . PropertyName_Start , pSpan . StartDateTime , pSpan . EndDateTime ) ) ;
if ( srTypeFilter . HasValue )
{
lCriteria . Add ( Restrictions . Eq ( ServiceRecord . PropertyName_ServiceRecordType , srTypeFilter . Value ) ) ;
}
2016-06-27 01:45:38 +02:00
return lCriteria . List < ServiceRecord > ( ) . ToList ( ) ;
}
public IEnumerable < AccountingTransaction > FindUnassignedAccountingTransactions ( )
{
return CreateCriteria < AccountingTransaction > ( )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . IsNull ( AccountingTransaction . PropertyName_CostBearer2SupportConcept ) )
2016-06-27 01:45:38 +02:00
. List < AccountingTransaction > ( ) . ToList ( ) ;
}
public IEnumerable < SupportConcept > FindSupportConcept (
2021-04-19 04:43:31 +02:00
string pCustomerFirstName ,
string pCustomerLastName ,
string pCustomerReferenceNumber ,
DateTime ? pFrom ,
DateTime ? pTill )
2016-06-27 01:45:38 +02:00
{
var lCriteria = CreateCriteria < SupportConcept > ( ) ;
//if (pFrom != null)
// lCriteria.Add(Expression.Ge(SupportConcept.PropertyName_Start, pFrom));
//if (pTill != null)
// lCriteria.Add(Expression.Le(SupportConcept.PropertyName_End, pTill));
lCriteria = lCriteria . CreateCriteria ( SupportConcept . PropertyName_Customer , JoinType . InnerJoin ) ;
2021-04-19 04:43:31 +02:00
if ( ! IsNullOrEmpty ( pCustomerReferenceNumber ) )
2016-06-27 01:45:38 +02:00
lCriteria . Add ( Restrictions . Eq ( Customer . PropertyName_ReferenceNumber , pCustomerReferenceNumber ) ) ;
2022-02-10 11:06:03 +01:00
if ( ! BS . Shared . Core . Utils . AreAllNullOrEmpty ( pCustomerFirstName , pCustomerLastName ) )
2016-06-27 01:45:38 +02:00
lCriteria . CreateCriteria ( Customer . PropertyName_Person )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Like ( Person . PropertyName_FirstName , pCustomerFirstName , MatchMode . Anywhere ) )
. Add ( Restrictions . Like ( Person . PropertyName_LastName , pCustomerLastName , MatchMode . Anywhere ) ) ;
2016-06-27 01:45:38 +02:00
return lCriteria . List < SupportConcept > ( ) ;
}
public IEnumerable < SupportConcept > FindCurrentSupportConcepts ( )
{
return CreateCriteriaIsActive < SupportConcept > ( )
//.Add(Expression.Ge(SupportConcept.PropertyName_End, DateTime.Now))
. List < SupportConcept > ( ) ;
}
public IEnumerable < SupportConcept > FindSupportConceptsInSpan ( DateTimeSpan pSpan )
{
return CreateCriteriaIsActive < SupportConcept > ( )
//.Add(Expression.Disjunction()
// .Add(Expression.Between(SupportConcept.PropertyName_Start, pSpan.StartDateTime, pSpan.EndDateTime))
// .Add(Expression.Between(SupportConcept.PropertyName_End, pSpan.StartDateTime, pSpan.EndDateTime))
// .Add(Expression.Conjunction()
// .Add(Expression.Le(SupportConcept.PropertyName_Start, pSpan.StartDateTime))
// .Add(Expression.Ge(SupportConcept.PropertyName_End, pSpan.EndDateTime))
// )
// )
2021-04-19 04:43:31 +02:00
. List < SupportConcept > ( ) ;
2016-06-27 01:45:38 +02:00
}
2017-02-01 13:53:59 +01:00
public IEnumerable < SupportConcept > FindExpiringSupportConcepts ( long? employeeOid , DateTime minDate , DateTime expiredUntil )
2016-06-27 01:45:38 +02:00
{
var c = CreateCriteriaIsActive < SupportConcept > ( ) ;
2021-04-19 04:43:31 +02:00
if ( employeeOid = = null )
2016-06-27 01:45:38 +02:00
{
return c
. CreateCriteria ( SupportConcept . PropertyName_CostBearer2SupportConceptList , JoinType . InnerJoin )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Between ( CostBearer2SupportConcept . PropertyName_ApprovedEndDate , minDate , expiredUntil ) )
. List < SupportConcept > ( ) ;
}
2016-06-27 01:45:38 +02:00
return c
. CreateAlias ( SupportConcept . PropertyName_CostBearer2SupportConceptList , "cb2sc" , JoinType . InnerJoin )
. CreateAlias ( SupportConcept . PropertyName_Customer , "c" , JoinType . InnerJoin )
2021-04-19 04:43:31 +02:00
. CreateAlias ( "c.Employee2CustomerList" , "e2c" , JoinType . InnerJoin )
2016-06-27 01:45:38 +02:00
. Add ( Restrictions . Eq ( "e2c." + Employee2Customer . PropertyName_EmployeeOid , employeeOid . Value ) )
2016-11-22 14:11:31 +01:00
. Add ( Restrictions . Or (
2021-04-19 04:43:31 +02:00
Restrictions . Between ( "cb2sc." + CostBearer2SupportConcept . PropertyName_ApprovedEndDate , minDate , expiredUntil ) ,
Restrictions . And ( Restrictions . IsNotNull ( "c.TerminationDate" ) , Restrictions . Between ( "c.TerminationDate" , minDate , expiredUntil ) ) ) )
2016-06-27 01:45:38 +02:00
. List < SupportConcept > ( ) . Distinct ( ) . ToList ( ) ;
}
public IEnumerable < SupportConcept > FindSupportConceptsWithConferenceDate ( long? employeeOid , DateTime conferenceDateUntil )
{
var c = CreateCriteriaIsActive < SupportConcept > ( ) ;
2021-04-19 04:43:31 +02:00
if ( employeeOid = = null )
2016-06-27 01:45:38 +02:00
{
return c
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Between ( SupportConcept . PropertyName_ConferenceDate , DateTime . Now , conferenceDateUntil ) )
. List < SupportConcept > ( ) ;
2016-06-27 01:45:38 +02:00
}
return c
. CreateAlias ( SupportConcept . PropertyName_Customer , "c" , JoinType . InnerJoin )
. CreateAlias ( "c.Employee2CustomerList" , "e2c" , JoinType . InnerJoin )
. Add ( Restrictions . Between ( SupportConcept . PropertyName_ConferenceDate , DateTime . Now . Date , conferenceDateUntil ) )
. Add ( Restrictions . Eq ( "e2c." + Employee2Customer . PropertyName_EmployeeOid , employeeOid . Value ) )
. List < SupportConcept > ( ) . Distinct ( ) . ToList ( ) ;
}
2021-04-19 04:43:31 +02:00
2017-02-01 13:53:59 +01:00
public ApplicationUser FindUserForEmployee ( Employee employee )
{
2023-02-10 16:18:18 +01:00
return CreateCriteriaIsActive < ApplicationUser > ( )
2017-02-01 13:53:59 +01:00
. Add ( Restrictions . Eq ( ApplicationUser . PropertyName_Employee , employee ) )
. List < ApplicationUser > ( ) . FirstOrDefault ( ) ;
}
2016-06-27 01:45:38 +02:00
public IEnumerable < Person > FindPersonsHavingBirthday ( DateTime birthdayUntil )
{
var ts = birthdayUntil . Subtract ( DateTime . Now ) ;
var days = ts . Days + 1 ;
2021-04-19 04:43:31 +02:00
2016-06-27 01:45:38 +02:00
return CreateCriteriaIsActive < Person > ( )
2021-04-19 04:43:31 +02:00
. Add ( Expression . Sql ( new SqlString ( "dayofyear(CAST(CONCAT(Year(CURDATE()), '-', Month(" + Person . PropertyName_DateOfBirth + "), '-', Day(" + Person . PropertyName_DateOfBirth + ")) AS DATE )) between dayofyear(CURDATE()) -4 and dayofyear(CURDATE()) + " + days ) ) )
. List < Person > ( ) ;
2016-06-27 01:45:38 +02:00
}
2021-04-19 04:43:31 +02:00
2016-06-27 01:45:38 +02:00
public IEnumerable < Login > FindLastLogins ( string loginName )
{
return CreateCriteria < Login > ( )
. Add ( Restrictions . Eq ( Login . PropertyName_LoginName , loginName ) )
2017-02-15 10:54:29 +01:00
. AddOrder ( Order . Desc ( "Oid" ) )
. SetMaxResults ( 10 )
2016-06-27 01:45:38 +02:00
. List < Login > ( ) ;
}
public IEnumerable < Query > FindQuery ( QueryType pType )
{
return CreateCriteria < Query > ( ) . Add ( Restrictions . Eq ( Query . PropertyName_Type , pType ) )
. List < Query > ( ) . ToList ( ) ;
}
public IList < AccountingTransaction > FindAccoutingTransactions ( DateTimeSpan pSpan )
{
var lCriteria = CreateCriteriaIsActive < AccountingTransaction > ( ) ;
2021-04-19 04:43:31 +02:00
if ( pSpan ! = null )
2016-06-27 01:45:38 +02:00
lCriteria . Add ( Restrictions . Between ( AccountingTransaction . PropertyName_BookingDate , pSpan . StartDateTime , pSpan . EndDateTime ) ) ;
var test = lCriteria . List < AccountingTransaction > ( ) ;
return test ;
}
2016-09-21 12:42:32 +02:00
public IEnumerable < AccountingTransaction > FindAccoutingTransactions ( DateTimeSpan pSpan , long? pSupportConceptOid , long? pSupportConceptCostBearerRelOid )
2016-06-27 01:45:38 +02:00
{
var lCriteria = CreateCriteriaIsActive < AccountingTransaction > ( )
. CreateAlias ( AccountingTransaction . PropertyName_CostBearer2SupportConcept , "cb2sc" , JoinType . LeftOuterJoin ) ;
2021-04-19 04:43:31 +02:00
if ( pSpan ! = null )
2016-06-27 01:45:38 +02:00
lCriteria . Add ( Restrictions . Between ( AccountingTransaction . PropertyName_BookingDate , pSpan . StartDateTime , pSpan . EndDateTime ) ) ;
2021-04-19 04:43:31 +02:00
if ( pSupportConceptCostBearerRelOid ! = null )
2016-06-27 01:45:38 +02:00
lCriteria . Add ( Restrictions . Eq ( "cb2sc." + BeWoEntityBase . PropertyName_Oid , pSupportConceptCostBearerRelOid ) ) ;
2021-04-19 04:43:31 +02:00
if ( pSupportConceptOid ! = null )
2016-06-27 01:45:38 +02:00
{
lCriteria . CreateCriteria ( "cb2sc." + CostBearer2SupportConcept . PropertyName_SupportConcept )
. Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_Oid , pSupportConceptOid ) ) ;
}
var test = lCriteria . List < AccountingTransaction > ( ) ;
return test ;
}
public IList < Settings > FindSettingsByValuePart ( SettingsType pType , string pValuePart )
{
return CreateCriteria < Settings > ( )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Eq ( Settings . PropertyName_Type , pType ) )
. Add ( Restrictions . Like ( Settings . PropertyName_Value , pValuePart , MatchMode . Anywhere ) )
. List < Settings > ( ) ;
2016-06-27 01:45:38 +02:00
}
public IList < FileAttachment > FindFileAttachments ( TableID pObjTid , long pObjOid )
{
return CreateCriteriaIsActive < FileAttachment > ( )
. Add ( Restrictions . Eq ( FileAttachment . PropertyName_ObjectOid , pObjOid ) )
. Add ( Restrictions . Eq ( FileAttachment . PropertyName_ObjectTid , pObjTid ) )
. List < FileAttachment > ( ) ;
}
public IEnumerable < FileAttachmentInfo > FindFileAttachmentInfos ( TableID pObjTid , long pObjOid )
{
return CreateCriteriaIsActive < FileAttachmentInfo > ( )
. Add ( Restrictions . Eq ( FileAttachmentInfo . PropertyName_ObjectOid , pObjOid ) )
. Add ( Restrictions . Eq ( FileAttachmentInfo . PropertyName_ObjectTid , pObjTid ) )
. List < FileAttachmentInfo > ( ) ;
}
public IList < BeWoFolder > FindBeWoFolders ( TableID pObjTid , long pObjOid )
{
var c = CreateCriteriaIsActive < BeWoFolder > ( )
. Add ( Restrictions . Eq ( BeWoFolder . PropertyName_ObjectTid , pObjTid ) ) ;
2021-04-19 04:43:31 +02:00
if ( pObjOid > 0 )
2016-06-27 01:45:38 +02:00
{
c . Add ( Restrictions . Eq ( BeWoFolder . PropertyName_ObjectOid , pObjOid ) ) ;
}
2021-04-19 04:43:31 +02:00
2016-06-27 01:45:38 +02:00
return c . List < BeWoFolder > ( ) ;
}
//public IList<SupportConcept> FindAllActiveApprovedLVRSupportConcepts()
//{
// return CreateCriteriaIsActive<SupportConcept>()
// .CreateCriteria(SupportConcept.PropertyName_CostBearer2SupportConceptList, JoinType.InnerJoin)
// .Add(Expression.Eq(CostBearer2SupportConcept.PropertyName_Status, CostBearer2SupportConceptStatus.Approved))
// .CreateCriteria(CostBearer2SupportConcept.PropertyName_CostBearer, JoinType.InnerJoin)
// .Add(Expression.Eq(CostBearer.PropertyName_SystemEntryID, SystemEntryID.CostBearerLVR))
// .List<SupportConcept>();
//}
public IList < SupportConcept > FindAllActiveApprovedSupportConcepts ( )
{
return CreateCriteriaIsActive < SupportConcept > ( )
. CreateCriteria ( SupportConcept . PropertyName_CostBearer2SupportConceptList , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( CostBearer2SupportConcept . PropertyName_Status , CostBearer2SupportConceptStatus . Approved ) )
. List < SupportConcept > ( ) . Distinct ( ) . ToList ( ) ;
}
public Employee FindEmployeeWithPersonOid ( long pPersonOid )
{
var person = DAOFactory . GenericDAO . LoadByID < Person > ( pPersonOid ) ;
2021-04-19 04:43:31 +02:00
if ( person ! = null )
2016-06-27 01:45:38 +02:00
{
return CreateCriteria < Employee > ( )
. Add ( Restrictions . Eq ( Employee . PropertyName_Person , person ) ) . UniqueResult < Employee > ( ) ;
}
2021-04-19 04:43:31 +02:00
2016-06-27 01:45:38 +02:00
return null ;
}
public Customer FindCustomerWithPersonOid ( long pPersonOid )
{
var person = DAOFactory . GenericDAO . LoadByID < Person > ( pPersonOid ) ;
2021-04-19 04:43:31 +02:00
if ( person ! = null )
2016-06-27 01:45:38 +02:00
{
return CreateCriteria < Customer > ( )
. Add ( Restrictions . Eq ( Customer . PropertyName_Person , person ) ) . UniqueResult < Customer > ( ) ;
}
2021-04-19 04:43:31 +02:00
2016-06-27 01:45:38 +02:00
return null ;
}
2017-12-15 10:47:43 +01:00
public IList < Customer > FindCustomersWithPersonOids ( IEnumerable < long > pPersonOid )
{
2021-04-19 04:43:31 +02:00
2017-12-15 10:47:43 +01:00
return CreateCriteriaIsActive < Customer > ( )
. CreateAlias ( Customer . PropertyName_Person , "p" , JoinType . InnerJoin )
. Add ( Restrictions . In ( "p." + BeWoEntityBase . PropertyName_Oid , pPersonOid . ToArray ( ) ) )
. List < Customer > ( ) ;
}
2016-06-27 01:45:38 +02:00
public IList < Person > GetActivePersonsWithType ( PersonType type )
{
return CreateCriteriaIsActive < Person > ( )
. Add ( Restrictions . Eq ( Person . PropertyName_Type , type ) )
. List < Person > ( ) ;
}
public IEnumerable < Customer > GetAllActiveCustomersWithSupportConceptData ( )
{
return CreateCriteriaIsActiveOrArchived < Customer > ( )
. CreateAlias ( Customer . PropertyName_SupportConcepts , "sc" , JoinType . LeftOuterJoin )
. CreateCriteria ( "sc." + SupportConcept . PropertyName_CostBearer2SupportConceptList , JoinType . LeftOuterJoin )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Eq ( "sc." + SupportConcept . PropertyName_IsActive , ActivationTypeId . Active ) )
2016-06-27 01:45:38 +02:00
. List < Customer > ( ) ;
}
public IEnumerable < Customer > GetAllActiveCustomersWithAddress ( )
{
return CreateCriteriaIsActive < Customer > ( )
. CreateCriteria ( Customer . PropertyName_Person , JoinType . LeftOuterJoin )
. CreateCriteria ( Person . PropertyName_Address , JoinType . LeftOuterJoin )
. List < Customer > ( ) ;
}
2021-04-19 04:43:31 +02:00
public IEnumerable < Customer > GetAllCustomersWithRelatedEmployee ( )
{
2017-02-01 13:53:59 +01:00
return CreateCriteria < Customer > ( )
. CreateAlias ( "Person" , "cp" , JoinType . InnerJoin )
. CreateAlias ( "cp." + Person . PropertyName_Address , "a" , JoinType . LeftOuterJoin )
. CreateAlias ( "Employee2CustomerList" , "e2c" , JoinType . LeftOuterJoin )
. CreateAlias ( "e2c." + Employee2Customer . PropertyName_Employee , "e" , JoinType . LeftOuterJoin )
. CreateCriteria ( "e2c." + Employee2Customer . PropertyName_ValueList , JoinType . LeftOuterJoin )
. CreateCriteria ( "e." + Employee . PropertyName_Person , JoinType . LeftOuterJoin )
. List < Customer > ( ) ;
}
2016-06-27 01:45:38 +02:00
public IList < ServiceRecord > FindServiceRecordsDetailsForLastDays ( long costbearer2SupportConcept , long? days )
{
var c = CreateCriteria < ServiceRecord > ( )
. Add ( Restrictions . Eq ( ServiceRecord . PropertyName_CostBearer2SupportConceptOid , costbearer2SupportConcept ) ) ;
2021-04-19 04:43:31 +02:00
if ( days . HasValue )
2016-06-27 01:45:38 +02:00
{
2021-04-19 04:43:31 +02:00
2016-06-27 01:45:38 +02:00
var minDate = DateTime . Now . Date . AddDays ( - 1 * days . Value ) ;
c . Add ( Restrictions . Ge ( ServiceRecord . PropertyName_Start , minDate ) ) ;
}
2017-03-14 12:48:31 +01:00
return c . CreateAlias ( ServiceRecord . PropertyName_ValueList , "vl" , JoinType . LeftOuterJoin )
. CreateAlias ( ServiceRecord . PropertyName_ServiceDescription , "sd" , JoinType . InnerJoin )
. CreateAlias ( "sd." + ServiceDescription . PropertyName_ServiceCategory , "sc" , JoinType . InnerJoin )
. CreateAlias ( ServiceRecord . PropertyName_Employee , "e" , JoinType . InnerJoin )
. CreateCriteria ( "e." + Employee . PropertyName_Person , JoinType . InnerJoin )
2021-06-20 23:11:01 +02:00
. List < ServiceRecord > ( ) . Distinct ( ) . ToList ( ) ;
2017-03-14 12:48:31 +01:00
}
public IList < ServiceRecord > FindServiceRecordsDetailsForLastDaysWithStartEndDate ( long costbearer2SupportConcept , DateTime start , DateTime ende )
{
var c = CreateCriteria < ServiceRecord > ( )
. Add ( Restrictions . Eq ( ServiceRecord . PropertyName_CostBearer2SupportConceptOid , costbearer2SupportConcept ) ) ;
2022-08-10 12:13:18 +02:00
var max = ende . Date . AddDays ( 1 ) ;
2017-03-14 12:48:31 +01:00
c . Add ( Restrictions . Ge ( ServiceRecord . PropertyName_Start , start . Date ) )
2022-08-10 12:13:18 +02:00
. Add ( Restrictions . Lt ( ServiceRecord . PropertyName_Start , max . Date ) ) ;
2021-04-19 04:43:31 +02:00
2023-03-31 17:07:46 +02:00
var result = c . CreateAlias ( ServiceRecord . PropertyName_ValueList , "vl" , JoinType . LeftOuterJoin )
2016-06-27 01:45:38 +02:00
. CreateAlias ( ServiceRecord . PropertyName_ServiceDescription , "sd" , JoinType . InnerJoin )
. CreateAlias ( "sd." + ServiceDescription . PropertyName_ServiceCategory , "sc" , JoinType . InnerJoin )
. CreateAlias ( ServiceRecord . PropertyName_Employee , "e" , JoinType . InnerJoin )
. CreateCriteria ( "e." + Employee . PropertyName_Person , JoinType . InnerJoin )
. List < ServiceRecord > ( ) ;
2023-03-31 17:07:46 +02:00
return result ;
2016-06-27 01:45:38 +02:00
}
public IList < ServiceRecord > FindServiceRecordsDetailWithServiceInfo ( long costbearer2SupportConcept )
{
var c = CreateCriteria < ServiceRecord > ( )
. Add ( Restrictions . Eq ( ServiceRecord . PropertyName_CostBearer2SupportConceptOid , costbearer2SupportConcept ) ) ;
2021-04-19 04:43:31 +02:00
2016-06-27 01:45:38 +02:00
return c . CreateAlias ( ServiceRecord . PropertyName_ServiceDescription , "sd" , JoinType . InnerJoin )
. CreateAlias ( "sd." + ServiceDescription . PropertyName_ServiceCategory , "sc" , JoinType . InnerJoin )
. List < ServiceRecord > ( ) ;
}
public Customer FindCustomerWithServiceRecordsWithDetail ( long pCustomerOid )
{
return CreateCriteria < Customer > ( )
. Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_Oid , pCustomerOid ) )
. CreateAlias ( Customer . PropertyName_ServiceRecordList , "sr" , JoinType . InnerJoin )
. CreateCriteria ( "sr." + ServiceRecord . PropertyName_ValueList , JoinType . LeftOuterJoin )
. CreateAlias ( "sr." + ServiceRecord . PropertyName_ServiceDescription , "sd" , JoinType . InnerJoin )
. CreateCriteria ( "sd." + ServiceDescription . PropertyName_ServiceCategory , JoinType . InnerJoin )
. CreateAlias ( "sr." + ServiceRecord . PropertyName_CostBearer2SupportConcept , "c2s" , JoinType . InnerJoin )
. CreateCriteria ( "c2s." + CostBearer2SupportConcept . PropertyName_SupportConcept , JoinType . InnerJoin )
. CreateAlias ( "c2s." + CostBearer2SupportConcept . PropertyName_CostBearer , "cb" , JoinType . InnerJoin )
. CreateAlias ( "cb." + CostBearer . PropertyName_Organisation , "org" , JoinType . InnerJoin )
. UniqueResult < Customer > ( ) ;
}
public ServiceRecordGroup FindServiceRecordGroup ( long pGroupOid )
{
return CreateCriteria < ServiceRecordGroup > ( )
. Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_Oid , pGroupOid ) )
. CreateCriteria ( ServiceRecordGroup . PropertyName_ServiceRecordList , JoinType . InnerJoin )
. UniqueResult < ServiceRecordGroup > ( ) ;
}
public IEnumerable < SupportConcept > GetAllActiveAndArchivedSupportConceptsCompact ( )
{
return CreateCriteria < SupportConcept > ( )
. Add ( Restrictions . Or ( Restrictions . Eq ( BeWoEntityBase . PropertyName_IsActive , ActivationTypeId . Active ) , Restrictions . Eq ( BeWoEntityBase . PropertyName_IsActive , ActivationTypeId . Archived ) ) )
. CreateAlias ( SupportConcept . PropertyName_CostBearer2SupportConceptList , "cb2sc" , JoinType . LeftOuterJoin )
. CreateAlias ( SupportConcept . PropertyName_Customer , "c" , JoinType . InnerJoin )
. CreateAlias ( "c." + Customer . PropertyName_Person , "p" , JoinType . InnerJoin )
. CreateAlias ( "p." + Person . PropertyName_Address , "a" , JoinType . LeftOuterJoin )
. CreateAlias ( "c." + Customer . PropertyName_Employee2CustomerList , "e2c" , JoinType . LeftOuterJoin )
. List < SupportConcept > ( ) ;
}
2021-04-19 04:43:31 +02:00
public IEnumerable < SupportConcept > GetAllSupportConceptsCompact ( )
{
return CreateCriteria < SupportConcept > ( )
. CreateAlias ( SupportConcept . PropertyName_CostBearer2SupportConceptList , "cb2sc" , JoinType . LeftOuterJoin )
. CreateAlias ( SupportConcept . PropertyName_Customer , "c" , JoinType . InnerJoin )
. CreateAlias ( "c." + Customer . PropertyName_Person , "p" , JoinType . InnerJoin )
. CreateAlias ( "p." + Person . PropertyName_Address , "a" , JoinType . LeftOuterJoin )
. CreateAlias ( "c." + Customer . PropertyName_Employee2CustomerList , "e2c" , JoinType . LeftOuterJoin )
. List < SupportConcept > ( ) ;
}
public IList < ListedSupportConcept > GetAllActiveAndArchivedListedSupportConceptsCompact ( )
{
return Session . CreateCriteria < ListedSupportConcept > ( )
. List < ListedSupportConcept > ( ) ;
}
public IList < ListedSupportConcept > GetAllActiveAndArchivedListedSupportConceptsCompact ( List < long > oids )
{
return Session . CreateCriteria < ListedSupportConcept > ( )
. Add ( Restrictions . In ( "SupportConceptOid" , oids ) )
. List < ListedSupportConcept > ( ) ;
}
2016-06-27 01:45:38 +02:00
public IList < Customer > GetAllCustomerWithServiceRecordsInSpan ( DateTimeSpan pSpan )
{
return CreateCriteria < Customer > ( )
. CreateCriteria ( Customer . PropertyName_ServiceRecordList , JoinType . InnerJoin )
. Add ( Restrictions . Between ( ServiceRecord . PropertyName_Start , pSpan . StartDateTime , pSpan . EndDateTime ) )
. List < Customer > ( ) ;
}
public IEnumerable < AccountingTransaction > GetAllAccountingTransactionsWithDetails ( )
{
return CreateCriteria < AccountingTransaction > ( )
. AddOrder ( Order . Desc ( AccountingTransaction . PropertyName_BookingDate ) )
. CreateAlias ( AccountingTransaction . PropertyName_CostBearer2SupportConcept , "cb2sc" , JoinType . LeftOuterJoin )
. CreateCriteria ( "cb2sc." + CostBearer2SupportConcept . PropertyName_CostBearer , JoinType . LeftOuterJoin )
. CreateCriteria ( CostBearer . PropertyName_Organisation , JoinType . LeftOuterJoin )
. CreateCriteria ( "cb2sc." + CostBearer2SupportConcept . PropertyName_SupportConcept , JoinType . LeftOuterJoin )
. CreateCriteria ( SupportConcept . PropertyName_Customer , JoinType . LeftOuterJoin )
. CreateCriteria ( Customer . PropertyName_Person , JoinType . LeftOuterJoin )
. List < AccountingTransaction > ( ) ;
}
2017-12-07 11:14:50 +01:00
public IEnumerable < AccountingTransaction > FindAccountingTransactionsWithImportNotice ( String notice )
{
return CreateCriteria < AccountingTransaction > ( )
. Add ( Restrictions . Eq ( AccountingTransaction . PropertyName_ImportNotice , notice ) ) . List < AccountingTransaction > ( ) ;
}
2016-06-27 01:45:38 +02:00
public IEnumerable < SupportConcept > GetAllActiveAndArchivedSupportConcepts ( )
{
return CreateCriteria < SupportConcept > ( )
. Add ( Restrictions . Or ( Restrictions . Eq ( BeWoEntityBase . PropertyName_IsActive , ActivationTypeId . Active ) , Restrictions . Eq ( BeWoEntityBase . PropertyName_IsActive , ActivationTypeId . Archived ) ) )
. CreateAlias ( SupportConcept . PropertyName_CostBearer2SupportConceptList , "cb2sc" , JoinType . InnerJoin )
. CreateAlias ( "cb2sc." + CostBearer2SupportConcept . PropertyName_CostBearer , "cb" , JoinType . InnerJoin )
. CreateAlias ( "cb." + CostBearer . PropertyName_Organisation , "org" , JoinType . InnerJoin )
. CreateAlias ( SupportConcept . PropertyName_Customer , "c" , JoinType . InnerJoin )
. CreateAlias ( "c." + Customer . PropertyName_Person , "p" , JoinType . InnerJoin )
. List < SupportConcept > ( ) ;
}
public IEnumerable < Customer > GetAllActiveAndArchivedCustomersWithRelatedEmployee ( )
{
return CreateCriteria < Customer > ( )
. Add ( Restrictions . Or ( Restrictions . Eq ( BeWoEntityBase . PropertyName_IsActive , ActivationTypeId . Active ) , Restrictions . Eq ( BeWoEntityBase . PropertyName_IsActive , ActivationTypeId . Archived ) ) )
. CreateAlias ( Customer . PropertyName_Person , "cp" , JoinType . InnerJoin )
. CreateAlias ( "cp." + Person . PropertyName_Address , "a" , JoinType . LeftOuterJoin )
. CreateAlias ( Customer . PropertyName_Employee2CustomerList , "e2c" , JoinType . LeftOuterJoin )
. CreateAlias ( "e2c." + Employee2Customer . PropertyName_Employee , "e" , JoinType . LeftOuterJoin )
. CreateCriteria ( "e2c." + Employee2Customer . PropertyName_ValueList , JoinType . LeftOuterJoin )
. CreateCriteria ( "e." + Employee . PropertyName_Person , JoinType . LeftOuterJoin )
. List < Customer > ( ) ;
}
public IEnumerable < SettlementInvoice > GetSettlementInvoiceBySupportConceptOid ( long supportConceptOid )
{
return CreateCriteriaIsActive < SettlementInvoice > ( )
. CreateAlias ( SettlementInvoice . PropertyName_InvoiceBase , "ib" , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( "ib." + InvoiceBase . PropertyName_SupportConceptOid , supportConceptOid ) )
. List < SettlementInvoice > ( ) ;
}
2021-04-19 04:43:31 +02:00
public IList < SettlementInvoice > GetSettlementInvoiceByCostBearer2SupportConceptOid ( long costBearer2SupportConceptOid )
{
return CreateCriteriaIsActive < SettlementInvoice > ( )
. CreateAlias ( SettlementInvoice . PropertyName_InvoiceBase , "ib" , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( "ib." + InvoiceBase . PropertyName_CostBearer2SupportConceptOid , costBearer2SupportConceptOid ) )
. List < SettlementInvoice > ( ) ;
}
2016-06-27 01:45:38 +02:00
public IEnumerable < SettlementInvoice > GetSettlementInvoicesForCostBearerAndPeriod ( long costBearerOid , DateTime periodStart , DateTime periodEnd )
{
return CreateCriteriaIsActive < SettlementInvoice > ( )
2021-04-19 04:43:31 +02:00
. CreateAlias ( SettlementInvoice . PropertyName_InvoiceBase , "ib" , JoinType . InnerJoin )
. CreateAlias ( "ib." + InvoiceBase . PropertyName_CostBearer2SupportConcept , "cb2sc" , JoinType . InnerJoin )
. CreateAlias ( "cb2sc." + CostBearer2SupportConcept . PropertyName_CostBearer , "cb" , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( "cb." + BeWoEntityBase . PropertyName_Oid , costBearerOid ) )
. Add ( Restrictions . Or (
2016-06-27 01:45:38 +02:00
Restrictions . Between ( "ib." + InvoiceBase . PropertyName_AccountingPeriodStart , periodStart , periodEnd ) ,
Restrictions . Between ( "ib." + InvoiceBase . PropertyName_AccountingPeriodEnd , periodStart , periodEnd ) ) )
2021-04-19 04:43:31 +02:00
. List < SettlementInvoice > ( ) ;
2016-06-27 01:45:38 +02:00
}
public IList < InvoiceBase > GetInvoiceBaseByTypeAndSupportConceptOid ( InvoiceType type , long supportConceptOid )
{
return SearchInvoiceBase ( type , InvoiceBase . PropertyName_SupportConceptOid , supportConceptOid ) ;
}
public IEnumerable < InvoiceBase > GetInvoiceBaseByOrganisationOid ( InvoiceType type , long organisationOid )
{
return SearchInvoiceBase ( type , InvoiceBase . PropertyName_RecipientOrganisationOid , organisationOid ) ;
}
public IEnumerable < InvoiceBase > GetInvoiceBaseByCustomerOid ( InvoiceType type , long customerOid )
{
return SearchInvoiceBase ( type , InvoiceBase . PropertyName_RecipientCustomerOid , customerOid ) ;
}
public IEnumerable < InvoiceBase > GetInvoiceBaseByPersonOid ( InvoiceType type , long personOid )
{
return SearchInvoiceBase ( type , InvoiceBase . PropertyName_RecipientPersonOid , personOid ) ;
}
private IList < InvoiceBase > SearchInvoiceBase ( InvoiceType type , string propertyname , long fkOid )
{
return CreateCriteriaIsActive < InvoiceBase > ( )
. Add ( Restrictions . Eq ( InvoiceBase . PropertyName_Type , type ) )
. Add ( Restrictions . Eq ( propertyname , fkOid ) )
. List < InvoiceBase > ( ) ;
}
public SettlementInvoice GetSettlementInvoiceByInvoiceBaseOid ( long invoiceBaseOid )
{
2023-01-12 12:12:27 +01:00
return CreateCriteria < SettlementInvoice > ( )
2016-06-27 01:45:38 +02:00
. CreateAlias ( SettlementInvoice . PropertyName_InvoiceBase , "ib" , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( "ib." + BeWoEntityBase . PropertyName_Oid , invoiceBaseOid ) )
. UniqueResult < SettlementInvoice > ( ) ;
}
public ServiceInvoice GetServiceInvoiceByInvoiceBaseOid ( long invoiceBaseOid )
{
var res = CreateCriteriaIsActive < ServiceInvoice > ( )
. CreateAlias ( ServiceInvoice . PropertyName_InvoiceBase , "ib" , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( "ib." + BeWoEntityBase . PropertyName_Oid , invoiceBaseOid ) )
. UniqueResult < ServiceInvoice > ( ) ;
return res ;
}
public IEnumerable < AssessmentSheetEntry > GetAssessmentSheetEntriesForCustomer ( long customerOid , DateTime startDt , DateTime endDt )
{
2021-04-19 04:43:31 +02:00
2016-06-27 01:45:38 +02:00
return CreateCriteriaIsActive < AssessmentSheetEntry > ( )
. CreateAlias ( AssessmentSheetEntry . PropertyName_Customer , "c" , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( "c." + BeWoEntityBase . PropertyName_Oid , customerOid ) )
. Add ( Restrictions . Ge ( AssessmentSheetEntry . PropertyName_Day , startDt ) )
. Add ( Restrictions . Lt ( AssessmentSheetEntry . PropertyName_Day , endDt ) )
. List < AssessmentSheetEntry > ( ) ;
}
public IList < VarFieldDef > GetVarFieldDefs ( TableID tid )
{
return CreateCriteriaIsActive < VarFieldDef > ( )
. Add ( Restrictions . Eq ( VarFieldDef . PropertyName_ObjectTid , tid ) )
. List < VarFieldDef > ( ) ;
}
public IEnumerable < Task > FindTasksForEmployee ( long employeeoid )
{
return CreateCriteriaIsActive < Task > ( )
. CreateAlias ( Task . PropertyName_SupportConcept , "sc" , JoinType . InnerJoin )
. CreateAlias ( "sc." + SupportConcept . PropertyName_Customer , "c" , JoinType . InnerJoin )
. CreateCriteria ( Task . PropertyName_EmployeeList , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_Oid , employeeoid ) )
. Add ( Restrictions . Eq ( "sc." + BeWoEntityBase . PropertyName_IsActive , ActivationTypeId . Active ) )
. Add ( Restrictions . Eq ( "c." + BeWoEntityBase . PropertyName_IsActive , ActivationTypeId . Active ) )
. List < Task > ( ) ;
}
public List < ServiceInvoice > GetServiceInvoices ( long costBearerOid , long? supportConceptOid , DateTimeSpan period )
{
var criteria = CreateCriteriaIsActive < ServiceInvoice > ( )
2021-04-19 04:43:31 +02:00
. CreateAlias ( ServiceInvoice . PropertyName_InvoiceBase , "ib" , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( "ib." + InvoiceBase . PropertyName_RecipientCostBearerOid , costBearerOid ) )
. Add ( Restrictions . Eq ( "ib." + BeWoEntityBase . PropertyName_IsActive , ActivationTypeId . Active ) ) ;
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
if ( supportConceptOid . HasValue )
2016-06-27 01:45:38 +02:00
criteria = criteria
. Add ( Restrictions . Eq ( "ib." + InvoiceBase . PropertyName_SupportConceptOid , supportConceptOid . Value ) ) ;
2021-04-19 04:43:31 +02:00
if ( period ! = null )
2016-06-27 01:45:38 +02:00
criteria = criteria
. Add ( Restrictions . Or (
2021-04-19 04:43:31 +02:00
Restrictions . Or (
Restrictions . Between ( "ib." + InvoiceBase . PropertyName_AccountingPeriodStart , period . StartDateTime , period . EndDateTime ) ,
Restrictions . Between ( "ib." + InvoiceBase . PropertyName_AccountingPeriodEnd , period . StartDateTime , period . EndDateTime ) ) ,
Restrictions . And (
Restrictions . Le ( "ib." + InvoiceBase . PropertyName_AccountingPeriodStart , period . StartDateTime ) ,
Restrictions . Ge ( "ib." + InvoiceBase . PropertyName_AccountingPeriodEnd , period . EndDateTime ) ) ) ) ;
2016-06-27 01:45:38 +02:00
return criteria . List < ServiceInvoice > ( ) . ToList ( ) ;
}
2018-11-22 14:05:45 +01:00
public List < ServiceInvoice > GetServiceInvoices ( long? costbearer2SupportConceptOid , DateTimeSpan period )
{
var criteria = CreateCriteriaIsActive < ServiceInvoice > ( )
. CreateAlias ( ServiceInvoice . PropertyName_InvoiceBase , "ib" , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( "ib." + BeWoEntityBase . PropertyName_IsActive , ActivationTypeId . Active ) ) ;
2021-04-19 04:43:31 +02:00
if ( costbearer2SupportConceptOid . HasValue )
2018-11-22 14:05:45 +01:00
criteria = criteria
. Add ( Restrictions . Eq ( "ib." + InvoiceBase . PropertyName_CostBearer2SupportConceptOid , costbearer2SupportConceptOid . Value ) ) ;
2021-04-19 04:43:31 +02:00
if ( period ! = null )
2018-11-22 14:05:45 +01:00
criteria = criteria
. Add ( Restrictions . Or (
Restrictions . Or (
Restrictions . Between ( "ib." + InvoiceBase . PropertyName_AccountingPeriodStart , period . StartDateTime , period . EndDateTime ) ,
Restrictions . Between ( "ib." + InvoiceBase . PropertyName_AccountingPeriodEnd , period . StartDateTime , period . EndDateTime ) ) ,
Restrictions . And (
Restrictions . Le ( "ib." + InvoiceBase . PropertyName_AccountingPeriodStart , period . StartDateTime ) ,
Restrictions . Ge ( "ib." + InvoiceBase . PropertyName_AccountingPeriodEnd , period . EndDateTime ) ) ) ) ;
return criteria . List < ServiceInvoice > ( ) . ToList ( ) ;
}
2016-06-27 01:45:38 +02:00
public IEnumerable < AssessmentSheetCategory > GetAssessmentSheetCategoryListForCustomer ( long customerOid )
{
return CreateCriteriaIsActive < AssessmentSheetCategory > ( )
. CreateAlias ( AssessmentSheetCategory . PropertyName_Customers , "c" , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( "c." + BeWoEntityBase . PropertyName_Oid , customerOid ) )
. List < AssessmentSheetCategory > ( ) ;
}
public IEnumerable < AbsenceTime > FindAbsenceTimes ( bool fetchEmployees , bool fetchCustomers )
{
var criteria = CreateCriteriaIsActive < AbsenceTime > ( ) ;
2021-04-19 04:43:31 +02:00
if ( ! fetchEmployees )
2016-06-27 01:45:38 +02:00
criteria = criteria
. Add ( Restrictions . IsNull ( AbsenceTime . PropertyName_EmployeeOid ) ) ;
2021-04-19 04:43:31 +02:00
else if ( ! fetchCustomers )
2016-06-27 01:45:38 +02:00
criteria = criteria
. Add ( Restrictions . IsNull ( AbsenceTime . PropertyName_CustomerOid ) ) ;
return criteria . List < AbsenceTime > ( ) . ToList ( ) ;
2021-04-19 04:43:31 +02:00
2018-05-21 16:39:24 +02:00
}
2021-05-04 08:14:15 +02:00
public List < AbsenceTime > FindAbsenceTimes ( DateTime startDate , DateTime endDate )
2018-05-21 16:39:24 +02:00
{
var criteria = CreateCriteriaIsActive < AbsenceTime > ( )
. Add (
2020-12-30 02:46:55 +01:00
Restrictions . Or (
Restrictions . And (
Restrictions . Ge ( AbsenceTime . PropertyName_End , startDate ) ,
Restrictions . Lt ( AbsenceTime . PropertyName_Start , endDate . Date . AddDays ( 1 ) )
) ,
Restrictions . And (
Restrictions . Lt ( AbsenceTime . PropertyName_Start , endDate . Date . AddDays ( 1 ) ) ,
Restrictions . IsNull ( AbsenceTime . PropertyName_End )
2018-05-21 16:39:24 +02:00
)
2020-12-30 02:46:55 +01:00
)
) ;
2019-09-27 15:55:01 +02:00
2018-05-21 16:39:24 +02:00
return criteria . List < AbsenceTime > ( ) . ToList ( ) ;
}
2020-12-30 02:46:55 +01:00
2021-10-12 16:00:17 +02:00
public IEnumerable < AbsenceTime > FindAbsenceTimesForEmployee
( DateTime startDate , DateTime endDate , long empOid )
2021-05-03 15:13:53 +02:00
{
var criteria = CreateCriteriaIsActive < AbsenceTime > ( )
. Add ( Restrictions . Eq ( "EmployeeOid" , empOid ) )
2021-09-22 15:34:38 +02:00
. Add ( Restrictions . Gt ( AbsenceTime . PropertyName_Start , startDate ) )
. Add ( Restrictions . Lt ( AbsenceTime . PropertyName_End , endDate ) ) ;
2020-12-30 02:46:55 +01:00
2021-05-03 15:13:53 +02:00
return criteria . List < AbsenceTime > ( ) . ToList ( ) ;
2018-05-21 16:39:24 +02:00
}
2021-05-14 06:57:09 +02:00
public IEnumerable < AbsenceTime > FindAbsenceTimesForMonth ( DateTime startDate , DateTime endDate )
{
var criteria = CreateCriteriaIsActive < AbsenceTime > ( ) ;
criteria . Add ( Restrictions . Gt ( "Start" , startDate ) ) ;
criteria . Add ( Restrictions . Lt ( "End" , endDate ) ) ;
return criteria . List < AbsenceTime > ( ) . ToList ( ) ;
}
2018-05-21 16:39:24 +02:00
public IEnumerable < Vertretung > FindVertretungen ( DateTime startDate , DateTime endDate )
{
var criteria = CreateCriteriaIsActive < Vertretung > ( )
. Add (
Restrictions . Or (
Restrictions . And (
Restrictions . Ge ( Vertretung . PropertyName_VertretungsZeitraumBis , startDate ) ,
Restrictions . Le ( Vertretung . PropertyName_VertretungsZeitraumVon , endDate )
) ,
Restrictions . And (
Restrictions . Le ( Vertretung . PropertyName_VertretungsZeitraumVon , endDate ) ,
Restrictions . IsNull ( Vertretung . PropertyName_VertretungsZeitraumBis )
)
)
) ;
return criteria . List < Vertretung > ( ) . ToList ( ) ;
2016-06-27 01:45:38 +02:00
}
public IEnumerable < Appointment > FindAppointments ( long? customerOid , long? employeeOid )
{
var criteria = CreateCriteriaIsActive < Appointment > ( ) ;
2018-05-25 15:07:47 +02:00
if ( employeeOid . HasValue )
{
criteria = criteria . Add ( Restrictions . Eq ( AbsenceTime . PropertyName_EmployeeOid , employeeOid ) ) ;
}
2016-06-27 01:45:38 +02:00
2018-05-25 15:07:47 +02:00
if ( customerOid . HasValue )
{
criteria = criteria . Add ( Restrictions . Eq ( AbsenceTime . PropertyName_CustomerOid , customerOid ) ) ;
}
2016-06-27 01:45:38 +02:00
return criteria . List < Appointment > ( ) . ToList ( ) ;
}
public ServiceCategory FindDefaultIndividualServiceCategory ( )
{
return CreateCriteriaIsActive < ServiceCategory > ( )
. Add ( Restrictions . Eq ( ServiceCategory . PropertyName_ScopeType , ScopeTypeId . Individual ) )
. List < ServiceCategory > ( ) . FirstOrDefault ( ) ;
}
2021-04-19 04:43:31 +02:00
public ServiceCategory FindServiceCategoryByName ( String name )
{
return CreateCriteriaIsActive < ServiceCategory > ( )
. Add ( Restrictions . Eq ( ServiceCategory . PropertyName_Name , name ) )
. List < ServiceCategory > ( ) . FirstOrDefault ( ) ;
}
2016-06-27 01:45:38 +02:00
public IEnumerable < FileAttachmentInfo > FindFileAttachmentInfoByType ( FileAttachmentType type )
{
var criteria = CreateCriteria < FileAttachmentInfo > ( )
. Add ( Restrictions . Eq ( "Type" , type ) ) ;
return criteria . List < FileAttachmentInfo > ( ) . ToList ( ) ;
}
2021-04-19 04:43:31 +02:00
public IEnumerable < AssessmentSheetEntry > GetAdditionalAssessmentSheetEntries ( DateTime dateTime )
{
return CreateCriteria < AssessmentSheetEntry > ( )
. Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_SystemEntryID , SystemEntryID . AdditionalServiceAssessmentSheet ) )
. Add ( Restrictions . Eq ( AssessmentSheetEntry . PropertyName_Day , dateTime . Date ) )
. List < AssessmentSheetEntry > ( ) ;
}
public IEnumerable < ResourceAppointment > GetResourceAppointmentExceptionsWithIndexAndId ( string info )
{
return CreateCriteria < ResourceAppointment > ( )
. Add ( Restrictions . Like ( ResourceAppointment . PropertyName_RecurrenceInfo , info ) )
. List < ResourceAppointment > ( ) ;
}
public IEnumerable < AdditionalServiceBooking > GetAdditionalServiceBookings ( long? regionOid , DateTime start , DateTime end )
{
var criteria = CreateCriteriaIsActive < AdditionalServiceBooking > ( )
. Add ( Restrictions . Between ( "Datum" , start , end ) ) ;
if ( regionOid . HasValue )
criteria = criteria . CreateAlias ( AdditionalServiceBooking . PropertyName_AdditionalServiceRegion , "asr" , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( "asr." + BeWoEntityBase . PropertyName_Oid , regionOid ) ) ;
return criteria . List < AdditionalServiceBooking > ( ) ;
}
public IEnumerable < AdditionalServiceBooking > GetAdditionalServiceBookingsForCustomer ( long customerOid , DateTime start , DateTime end )
{
return CreateCriteriaIsActive < AdditionalServiceBooking > ( )
. CreateAlias ( AdditionalServiceBooking . PropertyName_Customer2AddServiceBookings , "c2s" , JoinType . InnerJoin )
. Add ( Restrictions . Between ( "Datum" , start , end ) )
. Add ( Restrictions . Eq ( "c2s.CustomerOid" , customerOid ) )
. List < AdditionalServiceBooking > ( ) ;
}
public AssessmentSheetCategory GetAddServiceAssessmentSheetCategoryWithName ( string name )
{
return CreateCriteriaIsActive < AssessmentSheetCategory > ( )
. Add ( Restrictions . Eq ( AssessmentSheetCategory . PropertyName_Description , name ) )
. Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_SystemEntryID , SystemEntryID . AdditionalServiceAssessmentSheet ) )
. List < AssessmentSheetCategory > ( ) . FirstOrDefault ( ) ;
}
public IList < ServiceRecord > GetBillableServiceRecords ( )
{
var c = CreateCriteria < ServiceRecord > ( )
. CreateAlias ( ServiceRecord . PropertyName_ServiceDescription , "sd" , JoinType . InnerJoin )
. CreateAlias ( "sd." + ServiceDescription . PropertyName_ServiceCategory , "sc" , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( "sc." + ServiceCategory . PropertyName_IsBillable , true ) ) ;
return c . List < ServiceRecord > ( ) ;
}
public IList < ServiceRecord > GetBillableServiceRecords ( DateTime start , DateTime end )
{
var c = CreateCriteria < ServiceRecord > ( )
. CreateAlias ( ServiceRecord . PropertyName_ServiceDescription , "sd" , JoinType . InnerJoin )
. CreateAlias ( "sd." + ServiceDescription . PropertyName_ServiceCategory , "sc" , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( "sc." + ServiceCategory . PropertyName_IsBillable , true ) )
. Add ( Restrictions . Between ( ServiceRecord . PropertyName_Start , start , end ) ) ;
return c . List < ServiceRecord > ( ) ;
}
public IEnumerable < ServiceDescription > FindServiceDescriptionForCategory ( long categoryOid )
{
var c = CreateCriteriaIsActive < ServiceDescription > ( )
. CreateAlias ( ServiceDescription . PropertyName_ServiceCategory , "sc" , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( "sc." + BeWoEntityBase . PropertyName_Oid , categoryOid ) ) ;
return c . List < ServiceDescription > ( ) ;
}
public IEnumerable < ServiceAccounting > FindServiceAccountingsForServiceDescriptions ( IList < long > descriptionOids )
{
var c = CreateCriteriaIsActive < ServiceAccounting > ( )
. CreateAlias ( "ServiceDescription" , "sd" , JoinType . InnerJoin )
. Add ( Restrictions . In ( "sd." + BeWoEntityBase . PropertyName_Oid , descriptionOids . ToArray ( ) ) ) ;
return c . List < ServiceAccounting > ( ) ;
}
2016-06-27 01:45:38 +02:00
2017-12-07 11:14:50 +01:00
public IList < Medikamentenverordnungsliste > GetAllMedikamentenverordnungslistenButNewestByCustomerOid ( long customerOid , long newestOid , bool isBedarfsListe )
2021-04-19 04:43:31 +02:00
{
var c = CreateCriteria < Medikamentenverordnungsliste > ( )
. CreateAlias ( Medikamentenverordnungsliste . PropertyName_Customer , "c" )
. Add ( Restrictions . Eq ( "c." + BeWoEntityBase . PropertyName_Oid , customerOid ) )
. Add ( Restrictions . Not ( Restrictions . Eq ( BeWoEntityBase . PropertyName_Oid , newestOid ) ) )
. Add ( Restrictions . Eq ( Medikamentenverordnungsliste . PropertyName_MedListType , isBedarfsListe ) ) ;
return c . List < Medikamentenverordnungsliste > ( ) ;
}
public IList < SchedulerAppointment > GetAllOpenAppointmentsForEmployee ( long employeeOid )
{
var c = CreateCriteria < SchedulerAppointment > ( )
. Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_IsActive , ActivationTypeId . Active ) )
. Add ( Restrictions . Not ( Restrictions . Eq ( SchedulerAppointment . PropertyName_Originator + ".Oid" , employeeOid ) ) )
. Add ( Restrictions . Or ( Restrictions . Ge ( SchedulerAppointment . PropertyName_EndDate , DateTime . Now . AddDays ( - 7 ) ) , Restrictions . IsNull ( SchedulerAppointment . PropertyName_EndDate ) ) )
2020-12-07 13:37:14 +01:00
. CreateCriteria ( SchedulerAppointment . PropertyName_EmployeeList )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . And ( Restrictions . Eq ( Employee2SchedulerAppointment . PropertyName_Employee + ".Oid" , employeeOid ) ,
Restrictions . Eq ( Employee2SchedulerAppointment . PropertyName_ParticipationAnswer , ParticipationAnswer . Offen ) ) ) ;
return c . List < SchedulerAppointment > ( ) ;
}
public IEnumerable < SchedulerAppointment > GetAllParticipationNotificationsForEmployee ( long employeeOid )
{
var c = CreateCriteria < SchedulerAppointment > ( )
. Add ( Restrictions . And ( Restrictions . Eq ( BeWoEntityBase . PropertyName_IsActive , ActivationTypeId . Active ) , Restrictions . Eq ( SchedulerAppointment . PropertyName_Originator + ".Oid" , employeeOid ) ) )
. Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_IsActive , ActivationTypeId . Active ) )
. Add ( Restrictions . Or ( Restrictions . Ge ( SchedulerAppointment . PropertyName_EndDate , DateTime . Now . AddDays ( - 7 ) ) , Restrictions . IsNull ( SchedulerAppointment . PropertyName_EndDate ) ) )
2020-11-25 11:40:05 +01:00
. CreateCriteria ( SchedulerAppointment . PropertyName_EmployeeList )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . And ( Restrictions . And ( Restrictions . Eq ( Employee2SchedulerAppointment . PropertyName_IsPChanged , true ) , Restrictions . Not ( Restrictions . Eq ( Employee2SchedulerAppointment . PropertyName_Employee + ".Oid" , employeeOid ) ) ) , Restrictions . Not ( Restrictions . Eq ( Employee2SchedulerAppointment . PropertyName_ParticipationAnswer , ParticipationAnswer . Offen ) ) ) )
2017-04-07 13:50:07 +02:00
. Add ( Restrictions . Not ( Restrictions . Eq ( Employee2SchedulerAppointment . PropertyName_ParticipationAnswer , ParticipationAnswer . Verstrichen ) ) )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . IsNull ( Employee2SchedulerAppointment . PropertyName_IsPC_CheckedTs ) ) ;
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
var result = c . List < SchedulerAppointment > ( ) ;
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
return result ;
}
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
public IEnumerable < Employee2SchedulerAppointment > GetRemovedEmp2AppObjectsBySchAppOid ( long schAppOid )
{
var c = CreateCriteria < Employee2SchedulerAppointment > ( )
. Add ( Restrictions . Eq ( Employee2SchedulerAppointment . PropertyName_SchedulerAppointment , schAppOid ) ) ;
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
return c . List < Employee2SchedulerAppointment > ( ) ;
}
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
public IEnumerable < SchedulerAppointment > GetAllActiveAndNotDeclinedForEmployeeAppointments ( long employeeOid )
{
var detachedCriteria = DetachedCriteria . For < Employee2SchedulerAppointment > ( )
. Add ( Restrictions . And ( Restrictions . Not ( Restrictions . Eq ( Employee2SchedulerAppointment . PropertyName_Employee + ".Oid" , employeeOid ) ) ,
Restrictions . Eq ( Employee2SchedulerAppointment . PropertyName_ParticipationAnswer , ParticipationAnswer . Absage ) ) ) ;
detachedCriteria . SetProjection ( Projections . Property ( Employee2SchedulerAppointment . PropertyName_SchedulerAppointment ) ) ;
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
var crit = CreateCriteria < SchedulerAppointment > ( )
. Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_IsActive , ActivationTypeId . Active ) )
. Add ( Restrictions . Or ( Restrictions . Eq ( SchedulerAppointment . PropertyName_Originator + ".Oid" , employeeOid ) , Subqueries . PropertyIn ( BeWoEntityBase . PropertyName_Oid , detachedCriteria ) ) ) ;
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
return crit . List < SchedulerAppointment > ( ) ;
}
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
public bool ResetPasswordCodeExists ( string code , long userOid )
{
var c = CreateCriteria < ApplicationUser > ( )
. Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_Oid , userOid ) )
. CreateCriteria ( ApplicationUser . PropertyName_ResetPasswordInfos )
. Add ( Restrictions . Eq ( ResetPasswordInfo . PropertyName_Code , code ) ) ;
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
return c . List < ApplicationUser > ( ) . Count > 0 ;
}
2016-06-27 01:45:38 +02:00
2017-12-22 18:09:52 -04:00
public bool OverlappingAppointmentsExist ( DateTime start , DateTime end , IEnumerable < long > employees , IEnumerable < long > customers , IEnumerable < long > resources , long originator , long? appointmentOid , string recurrenceId = "" , int occurrenceIndex = 0 )
2020-11-20 23:28:09 +01:00
{
2021-01-07 19:40:15 +01:00
if ( employees = = null )
{
employees = new List < long > ( ) ;
}
if ( customers = = null )
{
customers = new List < long > ( ) ;
}
if ( resources = = null )
{
resources = new List < long > ( ) ;
}
2020-11-20 23:28:09 +01:00
var isRecurrenceException = appointmentOid = = null ;
2020-12-01 12:29:12 +01:00
var isBeingUpdatedToNormalAppointment = false ;
Guid ? recurrenceIdToIgnore = null ;
if ( appointmentOid ! = null )
{
2021-01-07 19:40:15 +01:00
// Das Pattern wird geladen, bzw. mit der Ausnahme mit Index 0 verglichen
2020-12-01 12:29:12 +01:00
// Wird die Serie in einen Einzeltermin geändert und es existiert eine Ausnahme mit Index 0, sollte die Ausnahme behalten werden und nicht der Root-Termin
var original = DAOFactory . GenericDAO . LoadByID < SchedulerAppointment > ( appointmentOid . Value ) ;
2021-01-07 19:40:15 +01:00
var ri = original ? . GetRecurrenceId ( ) ;
2020-12-01 12:29:12 +01:00
if ( ri ! = null & & IsNullOrWhiteSpace ( recurrenceId ) )
{
isBeingUpdatedToNormalAppointment = true ;
recurrenceIdToIgnore = ri ;
}
}
2020-11-20 23:28:09 +01:00
Guid ? recurrenceGuid = null ;
if ( Guid . TryParse ( recurrenceId , out var parsedGuid ) )
{
recurrenceGuid = parsedGuid ;
}
var betweenDateTimesCriterion = CreateBetweenDateTimesCriterion ( start , end , nameof ( SchedulerAppointment . StartDate ) , nameof ( SchedulerAppointment . EndDate ) ) ;
2016-06-27 01:45:38 +02:00
var criteria = CreateCriteria < SchedulerAppointment > ( )
2020-07-13 16:25:43 +02:00
. Add ( Restrictions . Eq ( nameof ( BeWoEntityBase . IsActive ) , ActivationTypeId . Active ) )
2019-02-28 12:38:29 +01:00
. Add ( Restrictions . Eq ( nameof ( SchedulerAppointment . IsTask ) , false ) )
2020-11-20 23:28:09 +01:00
. Add ( betweenDateTimesCriterion ) ;
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
if ( isRecurrenceException = = false )
{
criteria . Add ( Restrictions . Not ( Restrictions . Eq ( BeWoEntityBase . PropertyName_Oid , appointmentOid ) ) ) ;
}
var appTmp = criteria . List < SchedulerAppointment > ( ) ;
2016-06-27 01:45:38 +02:00
var appointments = appTmp . Where ( a = >
2021-04-19 04:43:31 +02:00
{
if ( a . RecurrenceInfo = = null )
{
return true ;
}
2016-06-27 01:45:38 +02:00
2020-11-20 23:28:09 +01:00
var recId2 = a . GetRecurrenceIdAndIndex ( out var index ) ;
2016-06-27 01:45:38 +02:00
2020-11-20 23:28:09 +01:00
return ! ( Guid . TryParse ( recurrenceId , out var guid ) & & guid . Equals ( recId2 ) & & occurrenceIndex = = index ) ;
2021-04-19 04:43:31 +02:00
} ) ;
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
var schedulerAppointments = appointments as IList < SchedulerAppointment > ? ? appointments . ToList ( ) ;
2016-06-27 01:45:38 +02:00
2020-07-15 12:15:13 +02:00
// Serientermine anhand der RecurrenceInfo erzeugen und den schedulerAppointments hinzufügen ------------------------------------------------------------
2022-02-10 11:06:03 +01:00
var deletedOccurences = schedulerAppointments . Where ( app = > app . Type = = 4 ) . Select ( app = > BS . Shared . Core . Utils . GetOccurrenceId ( app . RecurrenceInfo ) ) . ToList ( ) ;
var changedOccurences = schedulerAppointments . Where ( app = > app . Type = = 3 ) . Select ( app = > BS . Shared . Core . Utils . GetOccurrenceId ( app . RecurrenceInfo ) ) . ToList ( ) ;
2020-07-13 16:25:43 +02:00
2020-11-20 23:28:09 +01:00
var recurringAppointmentsCriteria = CreateRecurrenceCriteria ( start , end ) . Add ( Restrictions . Eq ( nameof ( SchedulerAppointment . Type ) , 1 ) ) ;
2020-07-13 16:25:43 +02:00
var recurringAppointments = recurringAppointmentsCriteria . List < SchedulerAppointment > ( ) . ToList ( ) ;
2020-12-01 12:29:12 +01:00
if ( isBeingUpdatedToNormalAppointment )
{
recurringAppointments = recurringAppointments . Where ( root = >
{
var recId = root . GetRecurrenceId ( ) ;
if ( recId ! = null & & recurrenceIdToIgnore ! = null )
{
if ( recId . Equals ( recurrenceIdToIgnore ) )
{
return false ;
}
}
return true ;
} ) . ToList ( ) ;
schedulerAppointments = schedulerAppointments . Where ( root = >
{
var recId = root . GetRecurrenceId ( ) ;
if ( recId ! = null & & recurrenceIdToIgnore ! = null )
{
if ( recId . Equals ( recurrenceIdToIgnore ) )
{
return false ;
}
}
return true ;
} ) . ToList ( ) ;
}
2020-07-13 16:25:43 +02:00
foreach ( var appointment in recurringAppointments )
{
var recurrenceInfo = new RecurrenceInfo ( ) ;
recurrenceInfo . FromXml ( appointment . RecurrenceInfo ) ;
var occurenceCalculator = OccurrenceCalculator . CreateInstance ( recurrenceInfo ) ;
2020-07-15 12:15:13 +02:00
// Das Muster für die Terminserie wird berechnet
2020-07-13 16:25:43 +02:00
var pattern = StaticAppointmentFactory . CreateAppointment ( AppointmentType . Pattern ) ;
2021-01-07 19:40:15 +01:00
if ( pattern = = null )
{
continue ;
}
2020-07-13 16:25:43 +02:00
pattern . RecurrenceInfo . FromXml ( appointment . RecurrenceInfo ) ;
pattern . Start = pattern . RecurrenceInfo . Start ;
2021-04-19 04:43:31 +02:00
pattern . End = appointment . EndDate . Value ; //pattern.RecurrenceInfo.End;
2020-07-13 16:25:43 +02:00
var patternId = pattern . RecurrenceInfo . Id . ToString ( ) ;
2020-07-15 12:15:13 +02:00
// In diesem Fall die Start- und Enddaten des zu überprüfenden, neuen Termins
2020-07-13 16:25:43 +02:00
var interval = new TimeInterval ( start , end ) ;
2020-07-15 12:15:13 +02:00
// Die Serientermine werden berechnet (ausnahmslos, d.h. es werden auch bearbeitete und gelöschte Termine erstellt, die herausgefiltert werden müssen).
2020-11-20 23:28:09 +01:00
var occurrences = occurenceCalculator . CalcOccurrences ( interval , pattern ) ;
2020-07-13 16:25:43 +02:00
2020-11-20 23:28:09 +01:00
foreach ( var occurrence in occurrences . GetAppointments ( interval ) )
2020-07-13 16:25:43 +02:00
{
if ( appointment . EndDate = = null | | appointment . StartDate = = null )
{
continue ;
}
2020-07-15 12:15:13 +02:00
// Terminindex in der Serie
2020-11-20 23:28:09 +01:00
var index = occurrence . RecurrenceIndex ;
2020-07-15 12:15:13 +02:00
// Das Ende ist offen, da die Terminserie kein Ende hat. Deshalb wird das Ende berechnet.
2020-07-13 16:25:43 +02:00
var duration = ( appointment . EndDate . Value - appointment . StartDate . Value ) . TotalMinutes ;
2020-11-20 23:28:09 +01:00
var guidParsingSuccessful = Guid . TryParse ( occurrence . RecurrenceInfo ? . Id ? . ToString ( ) , out var occurrenceGuid ) ;
2020-07-15 12:15:13 +02:00
// Der generierte Serientermin muss sich zeitlich mit dem neuen Termin überschneiden
// und darf nicht in der Liste der geänderten Serientermine oder der Liste der gelöschten Serientermine sein.
2020-12-01 12:29:12 +01:00
var isInIntervalTest = start . IsInInterval ( end , occurrence . Start , occurrence . Start . AddMinutes ( duration ) ) ;
2021-04-19 04:43:31 +02:00
if ( ! isInIntervalTest | |
2021-01-07 19:40:15 +01:00
changedOccurences ! = null & & changedOccurences . Any ( changedOccurence = > changedOccurence . PatternId . Equals ( patternId ) & & changedOccurence . Index = = index ) | |
deletedOccurences ! = null & & deletedOccurences . Any ( deletedOccurence = > deletedOccurence . PatternId . Equals ( patternId ) & & deletedOccurence . Index = = index ) | |
2021-04-19 04:43:31 +02:00
index = = occurrenceIndex & & guidParsingSuccessful & & recurrenceGuid ! = null & & recurrenceGuid . Equals ( occurrenceGuid ) )
2020-11-20 23:28:09 +01:00
{
continue ;
}
// Prüfen, ob es eine Ausnahme an dem Tag gibt, die zu dem Pattern gehört, um das Pattern auszuschließen
var relatedAppointments = FindAppointmentsByRecurrenceId ( new List < string > { recurrenceInfo . Id . ToString ( ) } , true ) ;
var relatedAppointmentsInInterval = relatedAppointments . Where ( a = >
{
if ( a . StartDate = = null | | a . EndDate = = null )
{
return false ;
}
var myStart = a . StartDate . Value . Date ;
var myEnd = a . EndDate . Value . Date ;
var isInInterval = start . Date . InBetween ( myStart . GetShortDateTime ( ) , myEnd , true ) ;
return isInInterval & & a . Type ! = 4 ;
} ) . ToList ( ) ;
var hasToStop = false ;
2020-12-01 12:29:12 +01:00
// Prüfen, ob es sich bei dem Termin für den Überschneidungen gesucht werden, um zu unterscheiden, ob ein Serientermin in einen normalen geändert wird.
var root = FindRootAppointmentByRecurrenceId ( recurrenceInfo . Id . ToString ( ) ) ;
if ( root . Oid ! = null & & appointmentOid ! = null & & root . Oid = = appointmentOid & & root . RecurrenceInfo ! = null & & IsNullOrWhiteSpace ( recurrenceId ) )
{
hasToStop = true ;
}
2020-11-20 23:28:09 +01:00
// Indices und Ids der RecurrenceInfo vergleichen. Stimmen sie überein, dann wird das generiert Serienelement ignoriert.
2020-12-01 12:29:12 +01:00
if ( occurrence . RecurrenceInfo ? . Id ! = null & & ! hasToStop )
2020-11-20 23:28:09 +01:00
{
if ( Guid . TryParse ( occurrence . RecurrenceInfo . Id . ToString ( ) , out var guid ) )
{
foreach ( var relatedAppointment in relatedAppointmentsInInterval )
{
var relatedAppointmentRecurrenceId = relatedAppointment . GetRecurrenceIdAndIndex ( out var relatedAppointmentRecurrenceIndex ) ;
if ( relatedAppointmentRecurrenceId ! = null )
{
if ( guid . Equals ( relatedAppointmentRecurrenceId ) & & relatedAppointmentRecurrenceIndex . Equals ( occurrence . RecurrenceIndex ) )
{
hasToStop = true ;
break ;
}
}
}
}
}
if ( hasToStop )
2020-07-13 16:25:43 +02:00
{
continue ;
}
var recurringAppointment = new SchedulerAppointment
{
2021-04-19 04:43:31 +02:00
AllDay = occurrence . AllDay ,
CustomerList = appointment . CustomerList ,
Notice = appointment . Notice ,
EmployeeList = appointment . EmployeeList ,
EndDate = occurrence . Start . AddMinutes ( duration ) ,
2020-07-13 16:25:43 +02:00
FormerBookingSequenceOid = appointment . FormerBookingSequenceOid ,
2021-04-19 04:43:31 +02:00
IsPrivate = appointment . IsPrivate ,
Location = appointment . Location ,
Originator = appointment . Originator ,
RecurrenceInfo = occurrence . RecurrenceInfo . ToXml ( ) ,
ReminderInfo = appointment . ReminderInfo ,
ResourceList = appointment . ResourceList ,
StartDate = occurrence . Start ,
Subject = appointment . Subject ? ? "" ,
Type = appointment . Type
2020-07-13 16:25:43 +02:00
} ;
schedulerAppointments . AddIfNotIn ( recurringAppointment ) ;
}
}
// --------------------------------------------------------------------------------------------------------------------------------------
2020-11-20 23:28:09 +01:00
// Falls es sich um eine Ausnahme einer Serie handelt, muss die Serie ignoriert werden
var shouldIgnoreAppointment = false ;
if ( isRecurrenceException & & recurrenceId ! = null )
{
if ( recurrenceGuid . HasValue )
{
shouldIgnoreAppointment = true ;
}
}
2020-07-13 16:25:43 +02:00
var oidList = new List < long > ( ) ;
2020-11-20 23:28:09 +01:00
schedulerAppointments = schedulerAppointments . Where ( appointment = > appointment . Type ! = 4 ) . ToList ( ) ;
2021-04-19 04:43:31 +02:00
foreach ( var appointment in schedulerAppointments )
2020-11-20 23:28:09 +01:00
{
if ( shouldIgnoreAppointment )
{
if ( ! ShouldDoAppointmentOverlappingCheck ( appointment , recurrenceGuid . Value ) )
{
continue ;
}
}
2021-04-19 04:43:31 +02:00
oidList . AddRange ( appointment . EmployeeList . Select ( rel = > rel . ParticipationAnswer ! = ParticipationAnswer . Absage & & rel . Employee . Oid ! = null ? rel . Employee . Oid . Value : 0 ) ) ;
}
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
var hasOverlappingEmployeeAppointments = oidList . Intersect ( employees ) . Any ( ) ;
var hasOverlappingCustomerAppointments = schedulerAppointments . Any ( app = > { return ShouldDoAppointmentOverlappingCheck ( app , recurrenceGuid ) & & app . CustomerList . Select ( c = > c . Oid ? ? 0 ) . Intersect ( customers ) . Any ( ) ; } ) ;
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
var hasOverlappingResourceAppointments = schedulerAppointments . Any ( app = > { return ShouldDoAppointmentOverlappingCheck ( app , recurrenceGuid ) & & app . ResourceList . Select ( r = > r . Oid ? ? 0 ) . Intersect ( resources ) . Any ( ) ; } ) ;
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
var hasOverlappingOriginatorAppointments = schedulerAppointments . Any ( appointment = >
2020-11-20 23:28:09 +01:00
{
if ( ! ShouldDoAppointmentOverlappingCheck ( appointment , recurrenceGuid ) )
{
return false ;
}
2016-06-27 01:45:38 +02:00
2020-11-20 23:28:09 +01:00
return appointment . Originator . Oid . HasValue & &
appointment . Originator . Oid . Value = = originator & &
( appointment . EmployeeList . Count = = 0 | | appointment . EmployeeList . Any ( a = > a . Employee . Oid . HasValue & & a . Employee . Oid . Value = = originator ) ) ;
} ) ;
2016-06-27 01:45:38 +02:00
2020-11-20 23:28:09 +01:00
return hasOverlappingEmployeeAppointments | | hasOverlappingCustomerAppointments | | hasOverlappingResourceAppointments | | hasOverlappingOriginatorAppointments ;
2021-04-19 04:43:31 +02:00
}
2016-06-27 01:45:38 +02:00
2020-11-20 23:28:09 +01:00
private static bool ShouldDoAppointmentOverlappingCheck ( SchedulerAppointment appointment , Guid ? recurrenceId )
{
if ( appointment . Oid . HasValue & & recurrenceId . HasValue )
{
var recId = appointment . GetRecurrenceIdAndIndex ( out var recIndex ) ;
2016-06-27 01:45:38 +02:00
2020-11-20 23:28:09 +01:00
if ( appointment . RecurrenceInfo ! = null & & recId ! = null )
{
if ( recId . Equals ( recurrenceId ) )
{
return false ;
}
}
}
2016-06-27 01:45:38 +02:00
2020-11-20 23:28:09 +01:00
return true ;
}
2016-06-27 01:45:38 +02:00
2020-11-20 23:28:09 +01:00
public IEnumerable < SchedulerAppointment > GetAllActiveAppointmentsForEmployeeInInterval ( DateTime start , DateTime end , long pEmployeeOid )
{
var hasResources = $"{BeWoEntityBase.PropertyName_Oid} IN (SELECT newschappoid FROM resource2newschapp)" ;
2016-06-27 01:45:38 +02:00
2020-11-20 23:28:09 +01:00
var criteria = CreateRecurrenceCriteria ( start , end )
. Add ( Restrictions . Or (
Expression . Sql ( new SqlString ( hasResources ) ) ,
CreateOwnAppointmentsCriteria ( pEmployeeOid ) ) ) ;
return criteria . List < SchedulerAppointment > ( ) ;
}
2016-06-27 01:45:38 +02:00
2020-11-20 23:28:09 +01:00
public IEnumerable < SchedulerAppointment > GetAllActiveAppointmentsInInterval ( DateTime start , DateTime end )
2021-04-19 04:43:31 +02:00
{
return CreateRecurrenceCriteria ( start , end ) . List < SchedulerAppointment > ( ) ;
}
public ResourceBooking GetFirstResourceBookingFromSequence ( long sequenceOid )
{
return CreateCriteria < ResourceBooking > ( )
. Add ( Restrictions . Eq ( ResourceBooking . PropertyName_SequencePosition , 0 ) )
. CreateAlias ( ResourceBooking . PropertyName_Sequence , "s" )
. Add ( Restrictions . Eq ( "s." + BeWoEntityBase . PropertyName_Oid , sequenceOid ) ) . UniqueResult < ResourceBooking > ( ) ;
}
public List < int > GetExcludedBookingSequencePositions ( long sequenceOid )
{
var c = CreateCriteria < ResourceBooking > ( )
. Add ( Restrictions . Gt ( ResourceBooking . PropertyName_SequencePosition , 0 ) )
. CreateAlias ( ResourceBooking . PropertyName_Sequence , "s" )
. Add ( Restrictions . Eq ( "s." + BeWoEntityBase . PropertyName_Oid , sequenceOid ) ) . List < ResourceBooking > ( ) ;
return c . Select ( s = > s . SequencePosition ) . ToList ( ) ;
}
2016-06-27 01:45:38 +02:00
2019-07-12 17:36:37 +02:00
public IEnumerable < InvoiceBase > GetInvoiceBases ( DateTime ? startDate , DateTime ? endDate , bool useInvoiceDate = true )
{
var lCriteria = CreateCriteriaIsActive < InvoiceBase > ( ) ;
2021-04-19 04:43:31 +02:00
if ( useInvoiceDate )
2019-07-12 17:36:37 +02:00
{
2021-04-19 04:43:31 +02:00
if ( startDate . HasValue )
2019-07-12 17:36:37 +02:00
lCriteria . Add ( Restrictions . Ge ( InvoiceBase . PropertyName_InvoiceDate , startDate ) ) ;
2021-04-19 04:43:31 +02:00
if ( endDate . HasValue )
2019-07-12 17:36:37 +02:00
lCriteria . Add ( Restrictions . Le ( InvoiceBase . PropertyName_InvoiceDate , endDate ) ) ;
}
else
{
2021-04-19 04:43:31 +02:00
if ( startDate . HasValue )
2019-07-12 17:36:37 +02:00
lCriteria . Add ( Restrictions . Ge ( InvoiceBase . PropertyName_AccountingPeriodEnd , startDate ) ) ;
2021-04-19 04:43:31 +02:00
if ( endDate . HasValue )
2019-07-12 17:36:37 +02:00
lCriteria . Add ( Restrictions . Le ( InvoiceBase . PropertyName_AccountingPeriodStart , endDate ) ) ;
2019-02-12 19:22:22 +01:00
}
2016-06-27 01:45:38 +02:00
2019-07-12 17:36:37 +02:00
return lCriteria . List < InvoiceBase > ( ) ;
}
2016-06-27 01:45:38 +02:00
2019-07-12 17:36:37 +02:00
public IEnumerable < SupportConcept > GetAllActiveSupportConceptsByCustomers ( List < long > customerOids , bool expiredOnesToo = false )
2021-04-19 04:43:31 +02:00
{
var c = CreateCriteria < SupportConcept > ( )
. Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_IsActive , ActivationTypeId . Active ) )
. CreateAlias ( SupportConcept . PropertyName_Customer , "c" )
. Add ( Restrictions . In ( "c." + BeWoEntityBase . PropertyName_Oid , customerOids ) ) ;
if ( expiredOnesToo )
{
}
return c . List < SupportConcept > ( ) ;
}
public IEnumerable < ServiceRecord > FindServiceRecordsForDays ( long? costBearer2SupportConceptOid , int dayCount , long? employeeOid )
{
var minStart = DateTime . Now . GetShortDateTime ( ) . AddDays ( - dayCount ) ;
var c = CreateCriteriaIsActive < ServiceRecord > ( ) ;
if ( costBearer2SupportConceptOid . HasValue )
{
c . Add ( Restrictions . Eq ( ServiceRecord . PropertyName_CostBearer2SupportConceptOid , costBearer2SupportConceptOid ) ) ;
}
else
{
c . Add ( Restrictions . Eq ( ServiceRecord . PropertyName_EmployeeOid , employeeOid ) )
. Add ( Restrictions . IsNull ( ServiceRecord . PropertyName_CostBearer2SupportConceptOid ) ) ;
}
if ( dayCount > 0 )
{
c . Add ( Restrictions . Ge ( ServiceRecord . PropertyName_Start , minStart ) ) ;
}
return c . List < ServiceRecord > ( ) ;
}
2016-06-27 01:45:38 +02:00
2017-11-17 22:24:00 +01:00
public IEnumerable < TextModule > GetActiveTextModuleByServiceCategory ( long pServiceCategoryOid )
2016-06-27 01:45:38 +02:00
{
2020-11-11 19:39:11 +01:00
var c = CreateCriteria < TextModule > ( ) ;
2016-06-27 01:45:38 +02:00
2018-04-27 14:13:42 +02:00
c . Add ( Restrictions . Or ( Restrictions . Eq ( TextModule . PropertyName_ServiceCategory + ".Oid" , pServiceCategoryOid ) , Restrictions . IsNull ( TextModule . PropertyName_ServiceCategory ) ) ) ;
2016-06-27 01:45:38 +02:00
2017-09-26 12:48:29 +02:00
return c . List < TextModule > ( ) ;
2016-06-27 01:45:38 +02:00
}
2017-11-17 22:24:00 +01:00
public IEnumerable < SchedulerAppointment > GetAllActiveAppointmentsForEmployeeInInterval2 ( DateTime start , DateTime end , List < long > pEmployeeOids )
2021-04-19 04:43:31 +02:00
{
var mainCriteria = CreateRecurrenceCriteria ( start , end ) ;
var detachedCriteria1 = DetachedCriteria . For < Employee2SchedulerAppointment > ( )
. Add ( Restrictions . In ( Employee2SchedulerAppointment . PropertyName_Employee + ".Oid" , pEmployeeOids ) )
. SetProjection ( Projections . Property ( Employee2SchedulerAppointment . PropertyName_SchedulerAppointment ) ) ;
var employee2SchedCrit = Subqueries . PropertyIn ( BeWoEntityBase . PropertyName_Oid , detachedCriteria1 ) ;
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
var originatorCrit = Restrictions . In ( SchedulerAppointment . PropertyName_Originator , pEmployeeOids ) ;
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
var detachedCriteria2 = DetachedCriteria . For < Employee2SchedulerAppointment > ( "e2s2" )
. SetProjection ( Projections . Property ( BeWoEntityBase . PropertyName_Oid ) )
. Add ( Restrictions . EqProperty ( "e2s2." + Employee2SchedulerAppointment . PropertyName_SchedulerAppointment , "sa.Oid" ) ) ;
2016-06-27 01:45:38 +02:00
2021-04-19 04:43:31 +02:00
var employee2SchedCrit2 = Subqueries . NotExists ( detachedCriteria2 ) ;
2018-10-12 12:42:24 +02:00
2021-04-19 04:43:31 +02:00
var and = Restrictions . And ( originatorCrit , employee2SchedCrit2 ) ;
2018-10-12 12:42:24 +02:00
2021-04-19 04:43:31 +02:00
ICriterion employeeCriterion = Restrictions . Or ( employee2SchedCrit , and ) ;
2018-10-12 12:42:24 +02:00
2021-04-19 04:43:31 +02:00
mainCriteria . Add ( employeeCriterion ) ;
2018-10-12 12:42:24 +02:00
var appointments = mainCriteria . List < SchedulerAppointment > ( ) ;
2016-06-27 01:45:38 +02:00
2018-10-12 12:42:24 +02:00
var exceptionalRecurrenceInfos = appointments . Where ( w = > w . RecurrenceInfo ! = null & & w . Type = = 3 ) . ToList ( ) ;
var exceptionIds = new List < long > ( ) ;
var regex = new Regex ( "(Id=\\\"[a-z0-9-]+\\\")" ) ;
foreach ( var appointment in exceptionalRecurrenceInfos )
{
var match = regex . Match ( appointment . RecurrenceInfo ) ;
if ( match . Success )
{
var value = match . Value ;
var actualId = value . Split ( "\"" ) ;
if ( actualId . Count > 1 )
{
var id = actualId [ 1 ] ;
if ( ! appointments . Any ( w = > w . RecurrenceInfo ! = null & & w . RecurrenceInfo . Contains ( id ) & & w . Type = = 1 ) )
{
exceptionIds . Add ( appointment . Oid . Value ) ;
}
}
}
}
var exceptionsToModify = appointments . Where ( w = > w . Oid . HasValue & & exceptionIds . Contains ( w . Oid . Value ) ) . ToList ( ) ;
foreach ( var exception in exceptionsToModify )
{
var replacingAppointment = new SchedulerAppointment
{
Oid = exception . Oid . Value * - 1 ,
Version = 1 ,
Type = 4 ,
RecurrenceInfo = exception . RecurrenceInfo ,
Originator = exception . Originator ,
EmployeeList = exception . EmployeeList ,
CustomerList = exception . CustomerList ,
ResourceList = exception . ResourceList
} ;
exception . RecurrenceInfo = null ;
exception . Type = 0 ;
appointments . Add ( replacingAppointment ) ;
}
2021-04-19 04:43:31 +02:00
2018-10-12 12:42:24 +02:00
var recurrenceIds = new List < string > ( ) ;
var allExceptionalRecurrenceInfos = appointments . Where ( w = > w . RecurrenceInfo ! = null ) ;
foreach ( var appointment in allExceptionalRecurrenceInfos )
{
var match = regex . Match ( appointment . RecurrenceInfo ) ;
if ( match . Success )
{
var value = match . Value ;
var actualId = value . Split ( "\"" ) ;
if ( actualId . Count > 1 )
{
recurrenceIds . AddIfNotIn ( actualId [ 1 ] ) ;
}
}
}
var changedOrDeletedOccurences = FindAppointmentsByRecurrenceId ( recurrenceIds , true ) ;
appointments . AddRangeIfElementsNotIn ( changedOrDeletedOccurences ) ;
return appointments ;
2021-04-19 04:43:31 +02:00
}
public IEnumerable < long > FilterEmployeesWithAppointments ( List < long > pEmployeeOids , DateTime pStartTime , DateTime pEndTime )
{
2021-07-16 18:00:38 +02:00
if ( pEmployeeOids = = null )
{
pEmployeeOids = new List < long > ( ) ;
}
2021-04-19 04:43:31 +02:00
var result = new List < long > ( ) ;
2021-07-16 18:00:38 +02:00
var appointments = GetAllActiveAppointmentsForEmployeeInInterval2 ( pStartTime , pEndTime , pEmployeeOids ) ? ? new List < SchedulerAppointment > ( ) ;
var gefilterteTermine =
appointments . Where ( w = > w . EmployeeList ! = null & & w . EmployeeList
. Select ( s = > s . Employee . Oid . Value )
. Intersect ( pEmployeeOids ) . Any ( ) | | ! w . EmployeeList . Select ( s = > s . Employee . Oid . Value )
. Intersect ( pEmployeeOids ) . Any ( ) & & pEmployeeOids . Contains ( w . Originator . Oid . Value ) ) . ToList ( ) ;
2021-04-19 04:43:31 +02:00
var employee2SchedulerAppointmentsList = gefilterteTermine . Select ( s = > s . EmployeeList ) . ToList ( ) ;
foreach ( var employee2SchedulerAppointments in employee2SchedulerAppointmentsList )
{
foreach ( var employee2SchedulerAppointment in employee2SchedulerAppointments )
{
if ( employee2SchedulerAppointment . Employee . Oid . HasValue & & ! result . Contains ( employee2SchedulerAppointment . Employee . Oid . Value ) )
{
result . Add ( employee2SchedulerAppointment . Employee . Oid . Value ) ;
}
}
}
foreach ( var originator in gefilterteTermine . Select ( s = > s . Originator ) )
{
if ( originator . Oid . HasValue & & ! result . Contains ( originator . Oid . Value ) )
{
result . Add ( originator . Oid . Value ) ;
}
}
var c = CreateCriteria < AbsenceTime > ( )
. Add ( Restrictions . In ( AbsenceTime . PropertyName_EmployeeOid , pEmployeeOids ) )
. Add ( Restrictions . Or (
Restrictions . Or (
Restrictions . Or (
Restrictions . And (
Restrictions . Eq ( AbsenceTime . PropertyName_Start , pStartTime ) ,
Restrictions . Eq ( AbsenceTime . PropertyName_End , pEndTime ) ) ,
Restrictions . And (
Restrictions . And (
Restrictions . Lt ( AbsenceTime . PropertyName_Start , pStartTime ) ,
Restrictions . Lt ( AbsenceTime . PropertyName_End , pStartTime ) ) ,
Restrictions . Gt ( AbsenceTime . PropertyName_End , pEndTime ) ) ) ,
Restrictions . And (
Restrictions . Lt ( AbsenceTime . PropertyName_Start , pStartTime ) ,
Restrictions . Gt ( AbsenceTime . PropertyName_End , pStartTime ) ) ) ,
Restrictions . And (
Restrictions . Gt ( AbsenceTime . PropertyName_Start , pStartTime ) ,
Restrictions . Lt ( AbsenceTime . PropertyName_End , pEndTime ) ) ) ) ;
var abwesenheiten = c . List < AbsenceTime > ( ) ;
foreach ( var abwesenheit in abwesenheiten )
{
result . AddIfNotIn ( abwesenheit . EmployeeOid . Value ) ;
}
return result ;
}
public IEnumerable < Task > GetTasksForEmployeeByDate ( long employeeOid , DateTime date )
{
var c = CreateCriteria < Task > ( ) . Add ( Restrictions . Between ( Task . PropertyName_DueDate , date , date . AddDays ( 1 ) ) ) . CreateCriteria ( Task . PropertyName_EmployeeList , JoinType . InnerJoin )
2016-06-27 01:45:38 +02:00
. Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_Oid , employeeOid ) ) . List < Task > ( ) ;
2021-04-19 04:43:31 +02:00
2020-06-29 19:24:24 +02:00
return c ;
2016-06-27 01:45:38 +02:00
}
public Wohnheimbuchung GetWohnheimbuchungByWohnheimAndBuchungsdatum ( long pWohnheimOid , DateTime pBuchungsdatum )
{
var c = CreateCriteriaIsActive < Wohnheimbuchung > ( ) ;
c . Add ( Restrictions . Eq ( Wohnheimbuchung . PropertyName_Buchungsdatum , pBuchungsdatum ) )
2018-10-24 19:32:12 +02:00
. Add ( Restrictions . Eq ( Format ( "{0}.Oid" , Wohnheimbuchung . PropertyName_Wohnheim ) , pWohnheimOid ) ) ;
2016-06-27 01:45:38 +02:00
return c . UniqueResult < Wohnheimbuchung > ( ) ;
}
public List < ServiceRecord > FindWohnheimbuchungsServiceRecords ( long pWohnheimbuchungsOid )
{
var c = CreateCriteria < ServiceRecord > ( )
. Add ( Restrictions . Eq ( ServiceRecord . PropertyName_WohnheimbuchungsOid , pWohnheimbuchungsOid ) ) ;
return c . List < ServiceRecord > ( ) . ToList ( ) ;
}
public bool CheckIfUserGroupIsLastWithUserGroupEditingRights ( List < long > pUserGroupOids )
{
var dc = DetachedCriteria . For < UserGroup > ( )
. Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_IsActive , ActivationTypeId . Active ) )
. SetProjection ( Projections . Property ( BeWoEntityBase . PropertyName_Oid ) ) ;
var c = CreateCriteriaIsActive < RightRelation > ( )
. Add ( Restrictions . Not ( Restrictions . In ( RightRelation . PropertyName_UserGroupOid , pUserGroupOids ) ) )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . In ( RightRelation . PropertyName_RightType , new [ ] { UserRightType . UserGroupView_View , UserRightType . UserGroupView_Edit , UserRightType . ViewAll , UserRightType . EditAll } ) )
2016-06-27 01:45:38 +02:00
. Add ( Subqueries . PropertyIn ( RightRelation . PropertyName_UserGroupOid , dc ) ) ;
var result = c . List < RightRelation > ( ) ;
var nachUserGroupOidSortiert = new Dictionary < long , List < UserRightType > > ( ) ;
2021-04-19 04:43:31 +02:00
foreach ( var relation in result )
2016-06-27 01:45:38 +02:00
{
nachUserGroupOidSortiert . AddOrUpdateValueInDictionary ( relation . UserGroupOid . Value , relation . RightType ) ;
}
2021-04-19 04:43:31 +02:00
var minRights2 = nachUserGroupOidSortiert . Any ( intersection = >
intersection . Value . Contains ( UserRightType . UserGroupView_Edit ) & & intersection . Value . Contains ( UserRightType . ViewAll ) | |
intersection . Value . Contains ( UserRightType . UserGroupView_Edit ) & & intersection . Value . Contains ( UserRightType . UserGroupView_View ) | |
intersection . Value . Contains ( UserRightType . EditAll ) & & intersection . Value . Contains ( UserRightType . ViewAll ) | |
intersection . Value . Contains ( UserRightType . EditAll ) & & intersection . Value . Contains ( UserRightType . UserGroupView_View ) ) ;
2016-06-27 01:45:38 +02:00
return minRights2 = = false ;
}
public ServiceDescription FindServiceDescriptionForWohnheimbuchungsServiceRecord ( long pWohnheimbuchungsOid )
{
var dc = DetachedCriteria . For < ServiceRecord > ( )
. Add ( Restrictions . Eq ( ServiceRecord . PropertyName_WohnheimbuchungsOid , pWohnheimbuchungsOid ) )
. SetProjection ( Projections . Property ( ServiceRecord . PropertyName_ServiceDescription + ".Oid" ) ) ;
var c = CreateCriteriaIsActive < ServiceDescription > ( )
. Add ( Subqueries . PropertyIn ( BeWoEntityBase . PropertyName_Oid , dc ) ) . SetMaxResults ( 1 ) ;
return c . List < ServiceDescription > ( ) . FirstOrDefault ( ) ;
}
public IEnumerable < Bargeldkasse > FindBargeldkasse ( TableID objectTid , long objectOid )
{
var c = CreateCriteriaIsActive < Bargeldkasse > ( )
. Add ( Restrictions . Eq ( Bargeldkasse . PropertyName_ObjectTid , objectTid ) )
. Add ( Restrictions . Eq ( Bargeldkasse . PropertyName_ObjectOid , objectOid ) ) ;
return c . List < Bargeldkasse > ( ) . ToList ( ) ;
}
2022-04-25 15:45:02 +02:00
public IEnumerable < Arbeitszeit > FindArbeitszeiten ( TableID objectTid , long objectOid )
{
var c = CreateCriteriaIsActive < Arbeitszeit > ( ) ;
if ( objectTid = = TableID . Employee )
{
c . Add ( Restrictions . Eq ( Arbeitszeit . PropertyName_EmployeeOid , objectOid ) ) ;
}
else
{
c . Add ( Restrictions . Eq ( "Customer" , DAOFactory . GenericDAO . GetByID < Customer > ( objectOid ) ) ) ;
}
return c . List < Arbeitszeit > ( ) . ToList ( ) ;
}
2018-10-08 11:57:16 +02:00
public IList < NotizenKategorie > FindNotizenKategorien ( TableID objectTid , long objectOid )
{
var c = CreateCriteriaIsActiveOrArchived < NotizenKategorie > ( )
. Add ( Restrictions . Eq ( NotizenKategorie . PropertyName_ObjectTid , objectTid ) )
. Add ( Restrictions . Eq ( NotizenKategorie . PropertyName_ObjectOid , objectOid ) ) ;
return c . List < NotizenKategorie > ( ) . ToList ( ) ;
}
2016-06-27 01:45:38 +02:00
public IEnumerable < MedRecord > FindMedRecordsForCustomer ( long pCustomerOid )
{
var c = CreateCriteriaIsActive < MedRecord > ( )
. Add ( Restrictions . Eq ( MedRecord . PropertyName_Customer + ".Oid" , pCustomerOid ) ) ;
return c . List < MedRecord > ( ) . ToList ( ) ;
}
public IEnumerable < Customer > FindAllChatActiveCustomers ( )
{
var c = CreateCriteriaIsActive < CustomerAPPCode > ( )
. Add ( Restrictions . Eq ( CustomerAPPCode . PropertyName_IsChatAktiv , 1 ) ) ;
var codes = c . List < CustomerAPPCode > ( ) . Select ( s = > s . CustomerOid . Value ) . ToArray ( ) ;
var c2 = CreateCriteriaIsActive < Customer > ( )
. Add ( Restrictions . In ( BeWoEntityBase . PropertyName_Oid , codes ) ) ;
return c2 . List < Customer > ( ) ;
}
2016-09-28 10:05:04 +02:00
public IEnumerable < Employee2Customer > FindAllChatpartnerEmployee2Customer ( long pRecipientOid )
{
var c = CreateCriteriaIsActive < Employee2Customer > ( )
. Add ( Restrictions . Eq ( Employee2Customer . PropertyName_EmployeeOid , pRecipientOid ) )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Eq ( Employee2Customer . PropertyName_Chatpartner , true ) ) ;
2016-09-28 10:05:04 +02:00
return c . List < Employee2Customer > ( ) ;
}
2021-04-19 04:43:31 +02:00
public IEnumerable < ChatMessage > FindAllChatMessages ( long senderOid , long empfaengerOid , int maxNachrichten )
2016-06-27 01:45:38 +02:00
{
var c = CreateCriteriaIsActive < ChatMessage > ( )
2016-07-25 09:26:56 +02:00
. Add (
Restrictions . Or (
Restrictions . And (
Restrictions . Eq ( ChatMessage . PropertyName_SenderPersonOid , senderOid ) ,
2016-09-30 10:19:11 +02:00
Restrictions . Eq ( ChatMessage . PropertyName_EmpfaengerPersonOid , empfaengerOid ) ) ,
2016-07-25 09:26:56 +02:00
Restrictions . And (
Restrictions . Eq ( ChatMessage . PropertyName_SenderPersonOid , empfaengerOid ) ,
2016-11-15 13:35:31 +01:00
Restrictions . Eq ( ChatMessage . PropertyName_EmpfaengerPersonOid , senderOid ) ) ) )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . IsNull ( ChatMessage . PropertyName_TeamOid ) )
. AddOrder ( Order . Desc ( ChatMessage . PropertyName_Uhrzeit ) )
. SetMaxResults ( maxNachrichten ) ;
2016-11-10 15:24:19 +01:00
return c . List < ChatMessage > ( ) ;
}
2021-04-19 04:43:31 +02:00
public IEnumerable < ChatMessage > FindNextChatMessages ( long senderOid , long empfaengerOid , int messlateZahl , List < string > list , bool isteam )
2016-11-10 15:24:19 +01:00
{
var c = CreateCriteriaIsActive < ChatMessage > ( ) ;
2021-04-19 04:43:31 +02:00
if ( ! isteam )
2016-11-10 15:24:19 +01:00
{
c . Add (
Restrictions . Or (
Restrictions . And (
Restrictions . Eq ( ChatMessage . PropertyName_SenderPersonOid , senderOid ) ,
Restrictions . Eq ( ChatMessage . PropertyName_EmpfaengerPersonOid , empfaengerOid ) ) ,
Restrictions . And (
Restrictions . Eq ( ChatMessage . PropertyName_SenderPersonOid , empfaengerOid ) ,
2016-11-14 15:46:54 +01:00
Restrictions . Eq ( ChatMessage . PropertyName_EmpfaengerPersonOid , senderOid ) ) ) ) . Add ( Restrictions . IsNull ( ChatMessage . PropertyName_TeamOid ) ) ;
2016-11-10 15:24:19 +01:00
}
else
{
2021-04-19 04:43:31 +02:00
2016-11-10 15:24:19 +01:00
c . Add ( Restrictions . Eq ( ChatMessage . PropertyName_TeamOid , empfaengerOid ) ) ;
}
c . Add ( Restrictions . Not ( Restrictions . In ( ChatMessage . PropertyName_MessageId , list ) ) ) ;
c . AddOrder ( Order . Desc ( ChatMessage . PropertyName_Uhrzeit ) ) ;
c . SetMaxResults ( messlateZahl ) ;
2016-06-27 01:45:38 +02:00
return c . List < ChatMessage > ( ) ;
}
2021-04-19 04:43:31 +02:00
public int CountChatMessages ( int aktuelleZahl , long senderOid , long empfaengerOid , bool isTeam )
2016-11-15 13:35:31 +01:00
{
//Zähle hier alle ChatMessages
int xc ;
2021-04-19 04:43:31 +02:00
if ( ! isTeam )
2016-11-15 13:35:31 +01:00
{
xc =
Session . QueryOver < ChatMessage > ( )
. Where (
message = >
message . SenderPersonOid = = senderOid & & message . EmpfaengerPersonOid = = empfaengerOid | |
message . SenderPersonOid = = empfaengerOid & & message . EmpfaengerPersonOid = = senderOid )
. RowCount ( ) ;
}
else
{
xc =
Session . QueryOver < ChatMessage > ( )
. Where (
message = >
2021-04-19 04:43:31 +02:00
message . TeamOid = = empfaengerOid )
2016-11-15 13:35:31 +01:00
. RowCount ( ) ;
}
2021-04-19 04:43:31 +02:00
2016-11-15 13:35:31 +01:00
int ergebnis = xc - aktuelleZahl ;
2021-04-19 04:43:31 +02:00
if ( ergebnis < 0 )
2016-11-15 13:35:31 +01:00
ergebnis = 0 ;
return ergebnis ;
}
2016-11-10 15:24:19 +01:00
public IEnumerable < ChatMessage > FindAllChatMessagesFromTeam ( long senderOid , long teamOid , int messlateZahl )
2021-04-19 04:43:31 +02:00
{
2016-08-05 12:48:13 +02:00
var c = CreateCriteriaIsActive < ChatMessage > ( )
. Add ( Restrictions . Eq ( ChatMessage . PropertyName_TeamOid , teamOid ) ) ;
2016-11-10 15:24:19 +01:00
c . AddOrder ( Order . Desc ( ChatMessage . PropertyName_Uhrzeit ) ) ;
c . SetMaxResults ( messlateZahl ) ;
2016-08-05 12:48:13 +02:00
return c . List < ChatMessage > ( ) ;
}
public IEnumerable < ChatMessage > FindAllEmpfängerChatMessages ( long senderOid , long empfaengerOid )
{
var c = CreateCriteriaIsActive < ChatMessage > ( )
. Add ( Restrictions . And (
2021-04-19 04:43:31 +02:00
Restrictions . Eq ( ChatMessage . PropertyName_SenderPersonOid , senderOid ) ,
Restrictions . Eq ( ChatMessage . PropertyName_EmpfaengerPersonOid , empfaengerOid ) ) ) ;
2016-08-05 12:48:13 +02:00
return c . List < ChatMessage > ( ) ;
}
2016-11-24 10:35:48 +01:00
2021-04-19 04:43:31 +02:00
public IEnumerable < ChatMessage > FindEmpfängerChatMessages ( long senderOid , long empfaengerOid , string messageOid )
2016-11-24 10:35:48 +01:00
{
var c = CreateCriteriaIsActive < ChatMessage > ( )
. Add ( Restrictions . And (
2021-04-19 04:43:31 +02:00
Restrictions . Eq ( ChatMessage . PropertyName_SenderPersonOid , senderOid ) ,
Restrictions . Eq ( ChatMessage . PropertyName_EmpfaengerPersonOid , empfaengerOid ) ) ) ;
2016-11-24 10:35:48 +01:00
c . Add ( Restrictions . Eq ( ChatMessage . PropertyName_MessageId , messageOid ) ) ;
return c . List < ChatMessage > ( ) ;
}
2016-08-05 12:48:13 +02:00
2016-06-27 01:45:38 +02:00
public IEnumerable < Employee > FindAllChatActiveEmployees ( )
{
var c = CreateCriteriaIsActive < EmployeeAPPCode > ( )
. Add ( Restrictions . Eq ( EmployeeAPPCode . PropertyName_IsChatAktiv , 1 ) ) ;
var codes = c . List < EmployeeAPPCode > ( ) . Select ( s = > s . EmployeeOid . Value ) . ToArray ( ) ;
var c2 = CreateCriteriaIsActive < Employee > ( )
. Add ( Restrictions . In ( BeWoEntityBase . PropertyName_Oid , codes ) ) ;
return c2 . List < Employee > ( ) ;
}
2016-08-17 12:20:27 +02:00
public bool CheckIfEmployeeIsAllowedToChat ( long pPersonOid )
{
var employee = FindEmployeeWithPersonOid ( pPersonOid ) ;
var c = CreateCriteriaIsActive < EmployeeAPPCode > ( )
. Add ( Restrictions . Eq ( EmployeeAPPCode . PropertyName_IsChatAktiv , 1 ) )
. Add ( Restrictions . Eq ( EmployeeAPPCode . PropertyName_EmployeeOid , employee . Oid ) ) ;
var codes = c . List < EmployeeAPPCode > ( ) . ToArray ( ) ;
2021-04-19 04:43:31 +02:00
2016-08-17 12:20:27 +02:00
return codes . Length > 0 ;
}
2017-11-13 16:37:21 +01:00
public IEnumerable < EmployeeAPPCode > FindAllEmployeeAppCodes ( long employeeoid )
2016-06-27 01:45:38 +02:00
{
var c = CreateCriteriaIsActive < EmployeeAPPCode > ( )
2017-11-13 16:37:21 +01:00
. Add ( Restrictions . Eq ( EmployeeAPPCode . PropertyName_EmployeeOid , employeeoid ) ) ;
2021-04-19 04:43:31 +02:00
2016-06-27 01:45:38 +02:00
return c . List < EmployeeAPPCode > ( ) ;
}
2021-04-19 04:43:31 +02:00
2017-11-13 16:37:21 +01:00
public IEnumerable < CustomerAPPCode > FindAllCustomerAppCodes ( long customeroid )
2016-06-27 01:45:38 +02:00
{
var c = CreateCriteriaIsActive < CustomerAPPCode > ( )
2017-11-13 16:37:21 +01:00
. Add ( Restrictions . Eq ( CustomerAPPCode . PropertyName_CustomerOid , customeroid ) ) ;
2016-06-27 01:45:38 +02:00
return c . List < CustomerAPPCode > ( ) ;
}
2016-08-17 12:20:27 +02:00
2017-10-20 07:36:08 +02:00
public IEnumerable < CustomerAPPCode > FindAllCustomerAppCodeBenutzer ( string benutzername )
{
var c =
CreateCriteriaIsActive < CustomerAPPCode > ( )
. Add ( Restrictions . Eq ( CustomerAPPCode . PropertyName_Benutzername , benutzername ) ) ;
return c . List < CustomerAPPCode > ( ) ;
}
2016-10-21 09:41:14 +02:00
public IEnumerable < ChatMessage > FindAllChatMessagesForAndroid ( long pSenderOid , long pRecipientOid , List < string > pExceptions , bool pForTeam )
2016-08-17 12:20:27 +02:00
{
var c = CreateCriteriaIsActive < ChatMessage > ( )
. Add (
Restrictions . Or (
Restrictions . And (
Restrictions . Eq ( ChatMessage . PropertyName_SenderPersonOid , pSenderOid ) ,
2016-09-30 10:19:11 +02:00
Restrictions . Eq ( ChatMessage . PropertyName_EmpfaengerPersonOid , pRecipientOid ) ) ,
2016-08-17 12:20:27 +02:00
Restrictions . And (
Restrictions . Eq ( ChatMessage . PropertyName_SenderPersonOid , pRecipientOid ) ,
2016-09-30 10:19:11 +02:00
Restrictions . Eq ( ChatMessage . PropertyName_EmpfaengerPersonOid , pSenderOid ) ) ) )
2016-11-09 11:48:46 +01:00
. Add ( Restrictions . Not ( Restrictions . In ( ChatMessage . PropertyName_MessageId , pExceptions ) ) )
. Add ( Restrictions . IsNull ( ChatMessage . PropertyName_TeamOid ) ) ;
2016-08-17 12:20:27 +02:00
if ( pForTeam )
{
c = CreateCriteriaIsActive < ChatMessage > ( )
. Add ( Restrictions . Eq ( ChatMessage . PropertyName_TeamOid , pRecipientOid ) )
2016-10-21 09:41:14 +02:00
. Add ( Restrictions . Not ( Restrictions . In ( ChatMessage . PropertyName_MessageId , pExceptions ) ) ) ;
2016-08-17 12:20:27 +02:00
}
return c . List < ChatMessage > ( ) ;
}
2016-09-16 14:44:58 +02:00
2016-10-21 09:41:14 +02:00
//public IEnumerable<ChatMessage> FindAllUnreadChatMessages(List<long> pExceptions)
//{
// var c = CreateCriteriaIsActive<ChatMessage>()
// .Add(Restrictions.Not(Restrictions.In(ChatMessage.PropertyName_MessageId, pExceptions)));
2016-09-16 14:44:58 +02:00
2016-10-21 09:41:14 +02:00
// return c.List<ChatMessage>();
//}
2016-09-21 12:42:32 +02:00
2016-10-07 12:40:16 +02:00
public Dictionary < Person , bool > FindAllChatAuthorizedPersonsForEmployee ( long pEmployeeOid )
2016-09-21 12:42:32 +02:00
{
2016-10-07 12:40:16 +02:00
var result = new Dictionary < Person , bool > ( ) ;
2016-09-21 12:42:32 +02:00
var employee = CreateCriteriaIsActive < Employee > ( ) . Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_Oid , pEmployeeOid ) ) . UniqueResult < Employee > ( ) ;
var relatedCustomerOids = employee . Employee2CustomerList . Select ( s = > s . CustomerOid . Value ) ;
var c1 = CreateCriteriaIsActive < CustomerAPPCode > ( )
. Add ( Restrictions . Eq ( CustomerAPPCode . PropertyName_IsChatAktiv , 1 ) ) ;
var codes = c1 . List < CustomerAPPCode > ( ) . Select ( s = > s . CustomerOid . Value ) . ToArray ( ) ;
var c2 = CreateCriteriaIsActive < Customer > ( )
. Add ( Restrictions . In ( BeWoEntityBase . PropertyName_Oid , codes ) )
. Add ( Restrictions . In ( BeWoEntityBase . PropertyName_Oid , relatedCustomerOids . ToList ( ) ) ) ;
var customers = c2 . List < Customer > ( ) ;
var employees = FindAllChatActiveEmployees ( ) ;
2016-10-07 12:40:16 +02:00
employees . DoForEach ( d = > result . Add ( d . Person , true ) ) ;
customers . DoForEach ( d = > result . Add ( d . Person , false ) ) ;
2016-09-21 12:42:32 +02:00
2016-10-07 12:40:16 +02:00
return result ;
2016-09-21 12:42:32 +02:00
}
2016-09-22 14:29:57 +02:00
2016-11-21 11:25:24 +01:00
public Dictionary < long , byte [ ] > FindImagesForChatAuthorizedPersonsForEmployee ( long pEmployeeOid )
{
var result = new Dictionary < long , byte [ ] > ( ) ;
var employee = CreateCriteriaIsActive < Employee > ( ) . Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_Oid , pEmployeeOid ) ) . UniqueResult < Employee > ( ) ;
var relatedCustomerOids = employee . Employee2CustomerList . Select ( s = > s . CustomerOid . Value ) ;
var c1 = CreateCriteriaIsActive < CustomerAPPCode > ( )
. Add ( Restrictions . Eq ( CustomerAPPCode . PropertyName_IsChatAktiv , 1 ) ) ;
var codes = c1 . List < CustomerAPPCode > ( ) . Select ( s = > s . CustomerOid . Value ) . ToArray ( ) ;
var c2 = CreateCriteriaIsActive < Customer > ( )
. Add ( Restrictions . In ( BeWoEntityBase . PropertyName_Oid , codes ) )
. Add ( Restrictions . In ( BeWoEntityBase . PropertyName_Oid , relatedCustomerOids . ToList ( ) ) ) ;
var customers = c2 . List < Customer > ( ) ;
var employees = FindAllChatActiveEmployees ( ) ;
2017-02-01 13:53:59 +01:00
//foreach (var customer in customers.Where(w => w.CustomerImage != null))
//{
// result.Add(customer.Person.Oid.Value, customer.CustomerImage);
//}
2016-11-21 11:25:24 +01:00
2017-02-01 13:53:59 +01:00
//foreach (var emp in employees.Where(w => w.EmployeeImage != null))
//{
// result.Add(emp.Person.Oid.Value, emp.EmployeeImage);
//}
2016-11-21 11:25:24 +01:00
return result ;
}
2016-09-22 14:29:57 +02:00
public IEnumerable < ChatMessage > FindUnreadChatMessagesForRecipient ( long pRecipientOid )
{
var c = CreateCriteriaIsActive < ChatMessage > ( )
2016-09-30 10:19:11 +02:00
. Add ( Restrictions . Eq ( ChatMessage . PropertyName_EmpfaengerPersonOid , pRecipientOid ) )
2016-09-22 14:29:57 +02:00
. Add ( Restrictions . Eq ( ChatMessage . PropertyName_IstGelesen , 0 ) ) ;
return c . List < ChatMessage > ( ) ;
}
2016-09-30 10:19:11 +02:00
public IEnumerable < ChatMessage > FindNewestChatMessages ( long pRecipientPersonOid )
{
2016-11-30 13:42:50 +01:00
var blubb = FindTeamsOfEmployee ( pRecipientPersonOid ) ;
var c = CreateCriteria < ChatMessage > ( ) ;
c . Add ( Subqueries . PropertyIn ( "Oid" ,
DetachedCriteria . For < NewestChatMessage > ( )
2016-10-21 09:41:14 +02:00
2021-04-19 04:43:31 +02:00
. Add (
Restrictions . Or (
Restrictions . And (
Restrictions . Or (
Restrictions . Eq ( NewestChatMessage . PropertyName_RecipientPersonOid , pRecipientPersonOid ) ,
Restrictions . Eq ( NewestChatMessage . PropertyName_SenderPersonOid , pRecipientPersonOid ) ) ,
Restrictions . Eq ( NewestChatMessage . PropertyName_IsTeam , false ) ) ,
Restrictions . And ( Restrictions . Eq ( NewestChatMessage . PropertyName_IsTeam , true ) , Restrictions . In ( NewestChatMessage . PropertyName_RecipientPersonOid , blubb . Select ( s = > s . Oid . Value ) . ToArray ( ) ) ) )
2016-11-30 13:42:50 +01:00
)
2021-04-19 04:43:31 +02:00
. SetProjection ( Projections . Property ( "ChatMessageOid" ) ) ) ) ;
2016-09-30 10:19:11 +02:00
2016-12-05 17:08:51 +01:00
var query = ToSql ( c ) ;
2016-11-30 13:42:50 +01:00
return c . List < ChatMessage > ( ) ;
}
2017-08-23 17:17:08 +02:00
public static string ToSql ( ICriteria criteria )
2016-11-30 13:42:50 +01:00
{
2020-09-30 19:23:42 +02:00
var criteriaImpl = ( CriteriaImpl ) criteria ;
var sessionImpl = ( SessionImpl ) criteriaImpl . Session ;
var factory = ( ISessionFactoryImplementor ) sessionImpl . SessionFactory ;
var implementors = factory . GetImplementors ( criteriaImpl . EntityOrClassName ) ;
if ( implementors . Length = = 0 )
{
return "No entity or class name found!" ;
}
2021-04-19 04:43:31 +02:00
var loader = new CriteriaLoader ( ( IOuterJoinLoadable ) factory . GetEntityPersister ( implementors [ 0 ] ) , factory , criteriaImpl , implementors [ 0 ] , sessionImpl . EnabledFilters ) ;
2016-11-30 13:42:50 +01:00
return loader . SqlString . ToString ( ) ;
2016-09-30 10:19:11 +02:00
}
2016-10-21 09:41:14 +02:00
public IEnumerable < string > FindChatMessageIds ( List < string > messageIds )
{
var c = CreateCriteria < ChatMessage > ( )
. Add ( Restrictions . In ( ChatMessage . PropertyName_MessageId , messageIds ) ) ;
var liste = c . List < ChatMessage > ( ) ;
return liste . Select ( s = > s . MessageId ) ;
}
2016-11-09 11:48:46 +01:00
2016-12-05 17:08:51 +01:00
public IEnumerable < ChatMessage > LoadChatMessagesChunkwise ( string pMessageId , long pRecipientOid , long pSenderOid , bool pForTeam , List < string > pExceptions , bool pIsInitialCall )
2016-11-09 11:48:46 +01:00
{
var c = CreateCriteriaIsActive < ChatMessage > ( )
. Add ( Restrictions . Or (
Restrictions . And (
Restrictions . Eq ( ChatMessage . PropertyName_SenderPersonOid , pSenderOid ) ,
Restrictions . Eq ( ChatMessage . PropertyName_EmpfaengerPersonOid , pRecipientOid ) ) ,
Restrictions . And (
Restrictions . Eq ( ChatMessage . PropertyName_SenderPersonOid , pRecipientOid ) ,
Restrictions . Eq ( ChatMessage . PropertyName_EmpfaengerPersonOid , pSenderOid ) ) ) ) ;
c . Add ( Restrictions . IsNull ( ChatMessage . PropertyName_TeamOid ) ) ;
2021-04-19 04:43:31 +02:00
if ( pForTeam )
2016-11-09 11:48:46 +01:00
{
c = CreateCriteriaIsActive < ChatMessage > ( )
. Add ( Restrictions . Eq ( ChatMessage . PropertyName_TeamOid , pRecipientOid ) ) ;
}
2021-04-19 04:43:31 +02:00
if ( ! IsNullOrEmpty ( pMessageId ) )
2016-11-09 11:48:46 +01:00
{
var c1 = CreateCriteriaIsActive < ChatMessage > ( )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Eq ( ChatMessage . PropertyName_MessageId , pMessageId ) )
. AddOrder ( Order . Desc ( BeWoEntityBase . PropertyName_InsTs ) ) ;
2016-11-09 11:48:46 +01:00
2016-11-30 13:42:50 +01:00
var list = c1 . List < ChatMessage > ( ) ;
2021-04-19 04:43:31 +02:00
if ( list . Count > 0 )
2016-11-30 13:42:50 +01:00
{
2016-12-05 17:08:51 +01:00
var lastLoadedChatMessage = c1 . List < ChatMessage > ( ) . First ( ) ;
2016-11-30 13:42:50 +01:00
c . Add ( Restrictions . Not ( Restrictions . In ( ChatMessage . PropertyName_MessageId , pExceptions ) ) ) ;
2016-12-05 17:08:51 +01:00
2021-04-19 04:43:31 +02:00
if ( pIsInitialCall )
2016-12-05 17:08:51 +01:00
{
c . Add ( Restrictions . Gt ( BeWoEntityBase . PropertyName_InsTs , lastLoadedChatMessage . InsTs ) ) ;
}
2016-11-30 13:42:50 +01:00
}
2016-11-09 11:48:46 +01:00
}
c . AddOrder ( Order . Desc ( BeWoEntityBase . PropertyName_InsTs ) ) ;
2016-11-14 14:21:42 +01:00
c . SetMaxResults ( 50 ) ;
2016-11-09 11:48:46 +01:00
2016-12-05 17:08:51 +01:00
var sqlQeury = ToSql ( c ) ;
2016-11-30 13:42:50 +01:00
2016-12-05 17:08:51 +01:00
var result = c . List < ChatMessage > ( ) ;
return result ;
2016-11-09 11:48:46 +01:00
}
2016-11-16 15:46:13 +01:00
public IList < ChatMediaMessage > GetChatMediaMessagesForChatMessage ( long chatMessageOid )
{
var c = CreateCriteriaIsActive < ChatMediaMessage > ( )
. Add ( Restrictions . Eq ( ChatMediaMessage . PropertyName_ChatMessageOid , chatMessageOid ) ) ;
return c . List < ChatMediaMessage > ( ) ;
}
2016-11-30 13:42:50 +01:00
public NewestChatMessage GetNewestChatMessageForConversation ( long pRecipientPersonOid , long pSenderPersonOid , bool pIsTeam )
{
var teams = new List < long > ( ) ;
2021-04-19 04:43:31 +02:00
if ( pIsTeam )
2016-11-30 13:42:50 +01:00
{
var employee = FindEmployeeWithPersonOid ( pSenderPersonOid ) ;
2021-04-19 04:43:31 +02:00
if ( employee ! = null )
2016-11-30 13:42:50 +01:00
{
teams . AddRange ( FindTeamsOfEmployee ( employee . Oid . Value ) . Select ( s = > s . Oid . Value ) ) ;
}
}
var c = CreateCriteria < NewestChatMessage > ( ) ;
2021-04-19 04:43:31 +02:00
if ( pIsTeam )
2016-11-30 13:42:50 +01:00
{
c . Add ( Restrictions . And ( Restrictions . Eq ( NewestChatMessage . PropertyName_IsTeam , true ) ,
2021-04-19 04:43:31 +02:00
Restrictions . Eq ( NewestChatMessage . PropertyName_RecipientPersonOid , pRecipientPersonOid ) ) ) ;
2016-11-30 13:42:50 +01:00
}
else
{
c . Add (
Restrictions . And (
Restrictions . Or (
Restrictions . And (
Restrictions . Eq ( NewestChatMessage . PropertyName_RecipientPersonOid , pRecipientPersonOid ) ,
Restrictions . Eq ( NewestChatMessage . PropertyName_SenderPersonOid , pSenderPersonOid ) ) ,
Restrictions . And (
Restrictions . Eq ( NewestChatMessage . PropertyName_RecipientPersonOid , pSenderPersonOid ) ,
Restrictions . Eq ( NewestChatMessage . PropertyName_SenderPersonOid , pRecipientPersonOid ) ) ) ,
Restrictions . Eq ( NewestChatMessage . PropertyName_IsTeam , false ) ) ) ;
}
return c . UniqueResult < NewestChatMessage > ( ) ;
}
2016-12-08 14:17:41 +01:00
public IList < Organisation > GetAllOrganisation2PersonRelations ( long personOid )
{
var c = CreateCriteriaIsActive < Person > ( )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_Oid , personOid ) ) . UniqueResult < Person > ( ) . Organisation2Persons . Select ( s = > s . Organisation ) . ToList ( ) ;
2016-12-08 14:17:41 +01:00
return c ;
}
2021-04-19 04:43:31 +02:00
2017-03-03 12:54:06 +01:00
public IList < Person > GetAllPerson2OrganisationRelations ( long organisationOid )
{
var c = CreateCriteriaIsActive < Organisation > ( )
. Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_Oid , organisationOid ) ) . UniqueResult < Organisation > ( ) . Organisation2PersonList . Select ( s = > s . Person ) . ToList ( ) ;
return c ;
}
2018-02-09 18:07:10 +01:00
public ServiceRecord FindServiceRecordforHistory ( long? pServiceRecordOid )
2021-04-19 04:43:31 +02:00
{
2018-02-09 18:07:10 +01:00
var c = CreateCriteria < ServiceRecord > ( ) . Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_Oid , pServiceRecordOid ) ) ;
2017-02-01 09:24:33 +01:00
return c . UniqueResult < ServiceRecord > ( ) ;
}
2017-04-07 13:44:07 +02:00
2017-05-15 09:11:13 +02:00
public ArbeitszeitListe FindEmployeeArbeitszeitListe ( long employeeOid )
{
2021-04-19 04:43:31 +02:00
var c = CreateCriteria < Arbeitszeit > ( ) . Add ( Restrictions . Eq ( Arbeitszeit . PropertyName_EmployeeOid , employeeOid ) ) ;
2017-05-15 09:11:13 +02:00
2021-04-19 04:43:31 +02:00
List < long > nAr = new List < long > ( ) ;
2017-05-15 09:11:13 +02:00
2021-04-19 04:43:31 +02:00
foreach ( var item in c . List < Arbeitszeit > ( ) )
2017-05-15 09:11:13 +02:00
{
nAr . Add ( item . Oid . Value ) ;
}
ArbeitszeitListe a = new ArbeitszeitListe ( ) ;
a . Arbeitszeit = c . List < Arbeitszeit > ( ) . ToList ( ) ;
2021-04-19 04:43:31 +02:00
if ( nAr . Count ! = 0 )
{
2017-05-15 09:11:13 +02:00
var cEintrag =
CreateCriteria < ArbeitszeitEintrag > ( )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . In ( ArbeitszeitEintrag . PropertyName_ArbeitszeitOid , nAr ) ) ;
2017-05-15 10:51:21 +02:00
2017-05-15 09:11:13 +02:00
a . ArbeitszeitEintrag = cEintrag . List < ArbeitszeitEintrag > ( ) . ToList ( ) ;
}
return a ;
2021-04-19 04:43:31 +02:00
}
2017-05-15 09:11:13 +02:00
2017-07-25 10:52:20 +02:00
public IList < SupportConcept > FindCostBearer2SupportConceptForDate ( DateTime datum )
{
var c = CreateCriteriaIsActive < SupportConcept > ( ) ;
return c
. CreateAlias ( SupportConcept . PropertyName_CostBearer2SupportConceptList , "cb2sc" , JoinType . InnerJoin )
. CreateAlias ( SupportConcept . PropertyName_Customer , "c" , JoinType . InnerJoin )
. Add ( Restrictions . Or (
2022-12-28 23:57:47 +01:00
Restrictions . And ( Restrictions . Le ( "cb2sc." + CostBearer2SupportConcept . PropertyName_RequestedStartDate , datum ) , Restrictions . Ge ( "cb2sc." + CostBearer2SupportConcept . PropertyName_RequestedEndDate , datum ) ) ,
Restrictions . And ( Restrictions . Le ( "cb2sc." + CostBearer2SupportConcept . PropertyName_ApprovedStartDate , datum ) , Restrictions . Ge ( "cb2sc." + CostBearer2SupportConcept . PropertyName_ApprovedEndDate , datum ) ) ) )
. List < SupportConcept > ( ) . Distinct ( ) . ToList ( ) ;
}
public IList < SupportConcept > FindSupportConceptsInDateRange ( bool auchArchivierteHolen , DateTime start , DateTime end )
{
ICriteria c = null ;
if ( auchArchivierteHolen )
{
c = CreateCriteriaIsActiveOrArchived < SupportConcept > ( ) ;
}
else
{
c = CreateCriteriaIsActive < SupportConcept > ( ) ;
}
return c
. CreateAlias ( SupportConcept . PropertyName_CostBearer2SupportConceptList , "cb2sc" , JoinType . InnerJoin )
. CreateAlias ( SupportConcept . PropertyName_Customer , "c" , JoinType . InnerJoin )
. Add (
Restrictions . Or ( Restrictions . And (
Restrictions . And ( Restrictions . IsNull ( "cb2sc." + CostBearer2SupportConcept . PropertyName_RequestedStartDate ) , Restrictions . IsNull ( "cb2sc." + CostBearer2SupportConcept . PropertyName_RequestedEndDate ) ) ,
Restrictions . And ( Restrictions . IsNull ( "cb2sc." + CostBearer2SupportConcept . PropertyName_ApprovedStartDate ) , Restrictions . IsNull ( "cb2sc." + CostBearer2SupportConcept . PropertyName_ApprovedEndDate ) ) ) ,
Restrictions . Or (
Restrictions . And ( Restrictions . Lt ( "cb2sc." + CostBearer2SupportConcept . PropertyName_RequestedStartDate , end ) , Restrictions . Ge ( "cb2sc." + CostBearer2SupportConcept . PropertyName_RequestedEndDate , start ) ) ,
Restrictions . And ( Restrictions . Lt ( "cb2sc." + CostBearer2SupportConcept . PropertyName_ApprovedStartDate , end ) , Restrictions . Ge ( "cb2sc." + CostBearer2SupportConcept . PropertyName_ApprovedEndDate , start ) ) ) ) )
2017-07-25 10:52:20 +02:00
. List < SupportConcept > ( ) . Distinct ( ) . ToList ( ) ;
}
2017-08-10 13:45:36 +02:00
public IList < QuittierungsCheck > FindQuittierungsCheckWithCustomerOids ( List < long > oids )
{
var c = CreateCriteria < QuittierungsCheck > ( )
. Add ( Restrictions . In ( QuittierungsCheck . PropertyName_CustomerOid , oids ) )
. List < QuittierungsCheck > ( ) ;
return c ;
}
2017-08-14 12:08:01 +02:00
public IList < QuittierungsCheck > FindQuittierungsCheckWithCustomerOid ( long oid )
2017-08-10 13:45:36 +02:00
{
var c = CreateCriteria < QuittierungsCheck > ( )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Eq ( QuittierungsCheck . PropertyName_CustomerOid , oid ) ) ;
//.UniqueResult<QuittierungsCheck>();
2017-08-10 13:45:36 +02:00
2017-08-14 12:08:01 +02:00
return c . List < QuittierungsCheck > ( ) ;
2017-08-10 13:45:36 +02:00
}
2019-07-12 17:36:37 +02:00
public IList < Timesheet > FindTimeSheetsForMonth ( DateTime monat )
{
DateTime start = new DateTime ( monat . Year , monat . Month , 1 ) ;
DateTime end = start . AddMonths ( 1 ) ;
return CreateCriteria < Timesheet > ( )
. Add ( Restrictions . And ( Restrictions . Lt ( SchedulerAppointment . PropertyName_StartDate , end ) , Restrictions . Ge ( SchedulerAppointment . PropertyName_EndDate , start ) ) )
. List < Timesheet > ( ) ;
}
public Timesheet FindEmployeeTimeSheetForMonth ( long employeeOid , DateTime monat )
{
DateTime start = new DateTime ( monat . Year , monat . Month , 1 ) ;
DateTime end = start . AddMonths ( 1 ) ;
return CreateCriteria < Timesheet > ( )
. Add ( Restrictions . Eq ( "EmployeeOid" , employeeOid ) )
. Add ( Restrictions . And ( Restrictions . Lt ( SchedulerAppointment . PropertyName_StartDate , end ) ,
Restrictions . Ge ( SchedulerAppointment . PropertyName_EndDate , start ) ) )
2020-09-02 18:19:15 +02:00
. List < Timesheet > ( ) . FirstOrDefault ( ) ;
2019-07-12 17:36:37 +02:00
}
public IList < Timesheet2Mail > FindTimeSheetMails ( long timesheetOid , long employeeOid )
{
return CreateCriteria < Timesheet2Mail > ( )
. Add ( Restrictions . Eq ( "TimesheetOid" , timesheetOid ) )
. Add ( Restrictions . Eq ( "EmployeeOid" , employeeOid ) )
. List < Timesheet2Mail > ( ) ;
}
public IEnumerable < AbsenceTime > GetAllAbsenceTimesInIntervalByEmployee ( DateTime start , DateTime end , long pEmployeeOid , bool pHasRightToSeeAllEmployeeAppointments )
2021-04-19 04:43:31 +02:00
{
// Wenn das Enddatum null ist, wird das Ende des Intervalls als Enddatum gesetzt (Ist ja eh read-only).
var criteria = CreateCriteriaIsActive < AbsenceTime > ( )
. Add ( Restrictions . IsNotNull ( AbsenceTime . PropertyName_EmployeeOid ) )
. Add ( Restrictions . Or
( Restrictions . Or ( Restrictions . Or (
Restrictions . And ( Restrictions . Ge ( AbsenceTime . PropertyName_Start , start ) , Restrictions . Le ( AbsenceTime . PropertyName_Start , end ) ) ,
Restrictions . Eq ( AbsenceTime . PropertyName_Start , start )
) , Restrictions . And ( Restrictions . Le ( AbsenceTime . PropertyName_Start , start ) , Restrictions . IsNull ( AbsenceTime . PropertyName_End ) )
) , Restrictions . And ( Restrictions . Lt ( AbsenceTime . PropertyName_Start , start ) , Restrictions . Gt ( AbsenceTime . PropertyName_End , start ) ) )
) ;
if ( ! pHasRightToSeeAllEmployeeAppointments )
{
criteria . Add ( Restrictions . Eq ( AbsenceTime . PropertyName_EmployeeOid , pEmployeeOid ) ) ;
}
return criteria . List < AbsenceTime > ( ) ;
}
public IEnumerable < TextModule > GetActiveTextModules ( bool pShouldOnlyLoadOwnTextModules , bool pHasRightToSeeAll , bool pIsInAdministrationView , long pEmployeeOid )
{
2022-12-15 23:16:04 +01:00
var criteria = CreateCriteriaIsActive < TextModule > ( ) ;
2021-04-19 04:43:31 +02:00
if ( pIsInAdministrationView )
{
criteria . Add ( Restrictions . Eq ( nameof ( TextModule . IsOnlyForEmployee ) , false ) ) ;
}
else if ( ! pHasRightToSeeAll )
{
criteria . Add ( Restrictions . Eq ( nameof ( TextModule . IsOnlyForEmployee ) , true ) )
. Add ( Restrictions . Eq ( nameof ( TextModule . Employee ) + "." + nameof ( BeWoEntityBase . Oid ) , pEmployeeOid ) ) ;
}
else
{
criteria . Add (
Restrictions . Or (
Restrictions . And (
Restrictions . Eq ( nameof ( TextModule . IsOnlyForEmployee ) , true ) ,
Restrictions . Eq ( nameof ( TextModule . Employee ) + "." + nameof ( BeWoEntityBase . Oid ) , pEmployeeOid ) ) ,
Restrictions . Eq ( nameof ( TextModule . IsOnlyForEmployee ) , false ) ) ) ;
}
2018-05-25 18:18:20 +02:00
return criteria . List < TextModule > ( ) ;
2021-04-19 04:43:31 +02:00
}
2017-11-09 12:18:50 +01:00
2018-10-08 11:57:16 +02:00
public IEnumerable < TextModule > GetChildTextModules ( TextModule textModule )
{
2020-11-11 19:39:11 +01:00
var criteria = CreateCriteria < TextModule > ( ) ;
2018-10-08 11:57:16 +02:00
criteria . Add ( Restrictions . Eq ( nameof ( TextModule . Parent ) , textModule ) ) ;
2021-04-19 04:43:31 +02:00
2018-10-08 11:57:16 +02:00
return criteria . List < TextModule > ( ) ;
}
2017-11-09 12:18:50 +01:00
public IEnumerable < ChatBewoMessageSync > FindEmployeeChatBewoMessageSync ( long oid )
{
var c = CreateCriteriaIsActive < ChatBewoMessageSync > ( )
. Add ( Restrictions . Eq ( ChatBewoMessageSync . PropertyName_EmployeeOid , oid ) ) ;
return c . List < ChatBewoMessageSync > ( ) ;
}
2017-11-23 10:58:07 +01:00
public IList < Customer2Person > FindCustomerPersonRelationsForPerson ( long personOid )
{
var c = CreateCriteriaIsActive < Customer2Person > ( )
. CreateCriteria ( Customer2Person . PropertyName_Person , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_Oid , personOid ) ) ;
return c . List < Customer2Person > ( ) ;
}
2017-12-12 17:20:23 -04:00
2022-04-06 16:47:09 +02:00
// KALENDER
2018-05-20 13:19:28 +02:00
public IList < SchedulerAppointment > LoadFilteredAppointments ( bool pHasRightToSeeAllEmployeeAppointments , long pEmployeeOid , DateTime pIntervalStart , DateTime pIntervalEnd , List < long > pSelectedEmployees , List < long > pSelectedCustomers , List < long > pSelectedResources , bool pEmployeesOnly , bool pCustomersOnly , bool pResourcesOnly , bool pPrivateAppointmentsOnly , bool pOnlyMyAppointments , bool pIncludeInactiveOnes )
2017-12-12 17:20:23 -04:00
{
2018-10-24 19:32:12 +02:00
var recurrenceBetween = Format ( "'{0:yyyy-MM-dd} 00:00:00' BETWEEN STR_TO_DATE(SUBSTRING({1}, 24, 19), '%m/%d/%Y %H:%i:%s') AND STR_TO_DATE(SUBSTRING({1}, 50, 19), '%m/%d/%Y %H:%i:%s')" , pIntervalStart , SchedulerAppointment . PropertyName_RecurrenceInfo ) ;
2017-12-12 17:20:23 -04:00
2018-05-20 13:19:28 +02:00
var criteria = CreateCriteria < SchedulerAppointment > ( ) ;
if ( ! pIncludeInactiveOnes )
{
criteria . Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_IsActive , ActivationTypeId . Active ) ) ;
}
2021-04-19 04:43:31 +02:00
2018-05-20 13:19:28 +02:00
criteria . Add ( Restrictions . Or (
2021-04-19 04:43:31 +02:00
Restrictions . And ( Restrictions . Not ( Restrictions . Like ( SchedulerAppointment . PropertyName_RecurrenceInfo , "Range" , MatchMode . Anywhere ) ) ,
Restrictions . Like ( SchedulerAppointment . PropertyName_RecurrenceInfo , "OccurrenceCount=\"10\"" , MatchMode . Anywhere ) ) ,
Restrictions . Or (
2017-12-12 17:20:23 -04:00
Restrictions . Or (
2021-04-19 04:43:31 +02:00
Restrictions . And ( Restrictions . Lt ( SchedulerAppointment . PropertyName_StartDate , pIntervalEnd ) , Restrictions . Ge ( SchedulerAppointment . PropertyName_EndDate , pIntervalStart ) ) ,
Restrictions . And ( Restrictions . IsNotNull ( SchedulerAppointment . PropertyName_RecurrenceInfo ) , Expression . Sql ( new SqlString ( recurrenceBetween ) ) ) ) ,
Restrictions . And ( Restrictions . Eq ( SchedulerAppointment . PropertyName_Type , 3 ) , Expression . Sql ( new SqlString ( recurrenceBetween ) ) ) ) ) ) ;
2017-12-12 17:20:23 -04:00
if ( pPrivateAppointmentsOnly )
{
criteria . Add ( Restrictions . Eq ( SchedulerAppointment . PropertyName_IsPrivate , true ) ) ;
}
else
{
if ( pEmployeesOnly )
{
var hasEmployees = $"{BeWoEntityBase.PropertyName_Oid} IN (SELECT newschappoid FROM employee2newschapp)" ;
criteria . Add ( Expression . Sql ( hasEmployees ) ) ;
}
if ( pCustomersOnly )
{
var hasCustomers = $"{BeWoEntityBase.PropertyName_Oid} IN (SELECT newschappoid FROM customer2newschapp)" ;
criteria . Add ( Expression . Sql ( hasCustomers ) ) ;
}
if ( pResourcesOnly )
{
2017-12-14 18:33:17 -04:00
var hasResources = $"{BeWoEntityBase.PropertyName_Oid} IN (SELECT newschappoid FROM resource2newschapp)" ;
2017-12-12 17:20:23 -04:00
criteria . Add ( Expression . Sql ( hasResources ) ) ;
}
if ( pSelectedEmployees . Any ( ) )
{
var detachedCriteria1 = DetachedCriteria . For < Employee2SchedulerAppointment > ( )
. Add ( Restrictions . In ( Employee2SchedulerAppointment . PropertyName_Employee + ".Oid" , pSelectedEmployees ) )
. SetProjection ( Projections . Property ( Employee2SchedulerAppointment . PropertyName_SchedulerAppointment ) ) ;
criteria . Add ( Subqueries . PropertyIn ( BeWoEntityBase . PropertyName_Oid , detachedCriteria1 ) ) ;
}
if ( pSelectedCustomers . Any ( ) )
{
var list = "" ;
for ( var i = 0 ; i < pSelectedCustomers . Count ; i + + )
{
if ( i ! = pSelectedCustomers . Count - 1 )
{
list + = "" + pSelectedCustomers [ i ] + "," ;
}
else
{
list + = "" + pSelectedCustomers [ i ] ;
}
}
var blah = $"{BeWoEntityBase.PropertyName_Oid} IN (SELECT newschappoid FROM customer2newschapp WHERE customeroid IN ({list}))" ;
criteria . Add ( Expression . Sql ( blah ) ) ;
}
if ( pSelectedResources . Any ( ) )
{
var list = "" ;
for ( var i = 0 ; i < pSelectedResources . Count ; i + + )
{
if ( i ! = pSelectedResources . Count - 1 )
{
list + = "" + pSelectedResources [ i ] + "," ;
}
else
{
list + = "" + pSelectedResources [ i ] ;
}
}
var blah = $"{BeWoEntityBase.PropertyName_Oid} IN (SELECT newschappoid FROM resource2newschapp WHERE resourceoid IN ({list}))" ;
criteria . Add ( Expression . Sql ( blah ) ) ;
}
}
2020-07-13 16:25:43 +02:00
var test = criteria . List < SchedulerAppointment > ( ) . ToList ( ) ;
2017-12-12 17:20:23 -04:00
return criteria . List < SchedulerAppointment > ( ) ;
}
2022-09-07 13:19:08 +02:00
// ToDo: zu anonymisierende Termine nicht herausfiltern! Also sämtliche, aktive Termine mit den ausgewählten Ressourcen laden!
2022-04-06 16:47:09 +02:00
// KALENDER
2018-05-20 13:19:28 +02:00
public IEnumerable < SchedulerAppointment > LoadFilteredAppointmentsForEmployee ( bool pHasRightToSeeAllEmployeeAppointments , long? pEmployeeOid , DateTime pIntervalStart , DateTime pIntervalEnd , List < long > pSelectedEmployees , List < long > pSelectedCustomers , List < long > pSelectedResources , bool pEmployeesOnly , bool pCustomersOnly , bool pResourcesOnly , bool pPrivateAppointmentsOnly , bool pOnlyMyAppointments , bool pIncludeInactiveOnes )
2017-12-12 17:20:23 -04:00
{
2018-05-20 13:19:28 +02:00
var mainCriteria = CreateRecurrenceCriteria ( pIntervalStart , pIntervalEnd , pIncludeInactiveOnes ) ;
2021-04-19 04:43:31 +02:00
2017-12-18 17:53:54 +01:00
ICriterion ownAppointmentCriterion = null ;
ICriterion employeeCriterion = null ;
ICriterion customerCriterion = null ;
ICriterion resourceCriterion = null ;
2017-12-12 17:20:23 -04:00
2018-05-20 13:19:28 +02:00
if ( pEmployeeOid . HasValue )
2017-12-14 18:33:17 -04:00
{
2017-12-22 18:09:52 -04:00
ownAppointmentCriterion = CreateOwnAppointmentsCriteria ( pEmployeeOid . Value ) ;
2017-12-14 18:33:17 -04:00
}
2017-12-18 17:53:54 +01:00
2017-12-22 18:09:52 -04:00
if ( pPrivateAppointmentsOnly )
2017-12-14 18:33:17 -04:00
{
2017-12-18 17:53:54 +01:00
mainCriteria . Add ( Restrictions . Eq ( SchedulerAppointment . PropertyName_IsPrivate , true ) ) ;
2017-12-14 18:33:17 -04:00
}
2017-12-12 17:20:23 -04:00
2017-12-19 13:45:48 -04:00
if ( pEmployeesOnly )
{
var hasEmployees = $"{BeWoEntityBase.PropertyName_Oid} IN (SELECT newschappoid FROM employee2newschapp)" ;
mainCriteria . Add ( Expression . Sql ( hasEmployees ) ) ;
}
2017-12-12 17:20:23 -04:00
2017-12-19 13:45:48 -04:00
if ( pCustomersOnly )
{
var hasCustomers = $"{BeWoEntityBase.PropertyName_Oid} IN (SELECT newschappoid FROM customer2newschapp)" ;
mainCriteria . Add ( Expression . Sql ( hasCustomers ) ) ;
}
2017-12-14 18:33:17 -04:00
2017-12-19 13:45:48 -04:00
if ( pResourcesOnly )
{
var hasResources = $"{BeWoEntityBase.PropertyName_Oid} IN (SELECT newschappoid FROM resource2newschapp)" ;
mainCriteria . Add ( Expression . Sql ( hasResources ) ) ;
}
2017-12-14 18:33:17 -04:00
2017-12-19 13:45:48 -04:00
if ( pSelectedEmployees . Any ( ) )
{
var detachedCriteria1 = DetachedCriteria . For < Employee2SchedulerAppointment > ( )
. Add ( Restrictions . In ( Employee2SchedulerAppointment . PropertyName_Employee + ".Oid" , pSelectedEmployees ) )
. SetProjection ( Projections . Property ( Employee2SchedulerAppointment . PropertyName_SchedulerAppointment ) ) ;
2018-03-02 16:24:55 +01:00
var employee2SchedCrit = Subqueries . PropertyIn ( BeWoEntityBase . PropertyName_Oid , detachedCriteria1 ) ;
var originatorCrit = Restrictions . In ( SchedulerAppointment . PropertyName_Originator , pSelectedEmployees ) ;
2022-02-10 11:06:03 +01:00
2018-03-02 16:24:55 +01:00
var detachedCriteria2 = DetachedCriteria . For < Employee2SchedulerAppointment > ( "e2s2" )
2018-05-20 13:19:28 +02:00
. SetProjection ( Projections . Property ( BeWoEntityBase . PropertyName_Oid ) )
2018-03-02 16:24:55 +01:00
. Add ( Restrictions . EqProperty ( "e2s2." + Employee2SchedulerAppointment . PropertyName_SchedulerAppointment , "sa.Oid" ) ) ;
var employee2SchedCrit2 = Subqueries . NotExists ( detachedCriteria2 ) ;
2021-04-19 04:43:31 +02:00
2018-03-02 16:24:55 +01:00
var and = Restrictions . And ( originatorCrit , employee2SchedCrit2 ) ;
employeeCriterion = Restrictions . Or ( employee2SchedCrit , and ) ;
2017-12-19 13:45:48 -04:00
}
if ( pSelectedCustomers . Any ( ) )
{
var list = "" ;
for ( var i = 0 ; i < pSelectedCustomers . Count ; i + + )
2017-12-14 18:33:17 -04:00
{
2017-12-19 13:45:48 -04:00
if ( i ! = pSelectedCustomers . Count - 1 )
2017-12-14 18:33:17 -04:00
{
2017-12-19 13:45:48 -04:00
list + = "" + pSelectedCustomers [ i ] + "," ;
2017-12-14 18:33:17 -04:00
}
2017-12-19 13:45:48 -04:00
else
{
list + = "" + pSelectedCustomers [ i ] ;
}
}
2017-12-14 18:33:17 -04:00
2017-12-19 13:45:48 -04:00
var blah = $"{BeWoEntityBase.PropertyName_Oid} IN (SELECT newschappoid FROM customer2newschapp WHERE customeroid IN ({list}))" ;
customerCriterion = Expression . Sql ( blah ) ;
}
2017-12-14 18:33:17 -04:00
2017-12-19 13:45:48 -04:00
if ( pSelectedResources . Any ( ) )
{
var list = "" ;
for ( var i = 0 ; i < pSelectedResources . Count ; i + + )
2017-12-14 18:33:17 -04:00
{
2017-12-19 13:45:48 -04:00
if ( i ! = pSelectedResources . Count - 1 )
2017-12-14 18:33:17 -04:00
{
2017-12-19 13:45:48 -04:00
list + = "" + pSelectedResources [ i ] + "," ;
}
else
{
list + = "" + pSelectedResources [ i ] ;
2017-12-14 18:33:17 -04:00
}
}
2017-12-19 13:45:48 -04:00
var blah = $"{BeWoEntityBase.PropertyName_Oid} IN (SELECT newschappoid FROM resource2newschapp WHERE resourceoid IN ({list}))" ;
resourceCriterion = Expression . Sql ( blah ) ;
}
2021-04-19 04:43:31 +02:00
2017-12-22 18:09:52 -04:00
var listOfCriterias = new List < ICriterion >
2017-12-18 17:53:54 +01:00
{
employeeCriterion ,
customerCriterion ,
resourceCriterion
} ;
2022-09-07 13:19:08 +02:00
if ( pSelectedResources . Count = = 0 )
2017-12-18 17:53:54 +01:00
{
2022-09-07 13:19:08 +02:00
if ( ! pHasRightToSeeAllEmployeeAppointments & & pSelectedEmployees . Count = = 0 )
{
mainCriteria . Add ( ownAppointmentCriterion ) ;
}
else
{
listOfCriterias . Add ( ownAppointmentCriterion ) ;
}
2017-12-18 17:53:54 +01:00
}
2021-04-19 04:43:31 +02:00
2017-12-18 17:53:54 +01:00
var orCriteria = CreateOrCriteria ( listOfCriterias ) ;
2017-12-14 18:33:17 -04:00
2018-05-20 13:19:28 +02:00
if ( orCriteria ! = null )
2017-12-18 17:53:54 +01:00
{
mainCriteria . Add ( orCriteria ) ;
}
2017-12-22 18:09:52 -04:00
var appointments = mainCriteria . List < SchedulerAppointment > ( ) ;
2022-09-07 13:19:08 +02:00
#region Serientermine
2017-12-22 18:09:52 -04:00
var exceptionalRecurrenceInfos = appointments . Where ( w = > w . RecurrenceInfo ! = null & & w . Type = = 3 ) . ToList ( ) ;
2021-04-19 04:43:31 +02:00
2017-12-22 18:09:52 -04:00
var exceptionIds = new List < long > ( ) ;
2021-04-19 04:43:31 +02:00
2017-12-22 18:09:52 -04:00
foreach ( var appointment in exceptionalRecurrenceInfos )
{
2018-10-24 19:32:12 +02:00
var match = RecurrenceIdRegex . Match ( appointment . RecurrenceInfo ) ;
2017-12-22 18:09:52 -04:00
if ( match . Success )
{
var value = match . Value ;
var actualId = value . Split ( "\"" ) ;
if ( actualId . Count > 1 )
{
var id = actualId [ 1 ] ;
2021-04-19 04:43:31 +02:00
2017-12-22 18:09:52 -04:00
if ( ! appointments . Any ( w = > w . RecurrenceInfo ! = null & & w . RecurrenceInfo . Contains ( id ) & & w . Type = = 1 ) )
{
exceptionIds . Add ( appointment . Oid . Value ) ;
}
}
}
}
2018-10-24 19:32:12 +02:00
// Serienausnahmen werden als gelöscht markiert und es wird die RecurrenceInfo entfernt.
// Der Type wird auf "normal" gesetzt, damit nicht die ganze Serie angezeigt werden muss, die unter Umständen nichts mit den Filterkriterien zu tun hat.
2017-12-22 18:09:52 -04:00
var exceptionsToModify = appointments . Where ( w = > w . Oid . HasValue & & exceptionIds . Contains ( w . Oid . Value ) ) . ToList ( ) ;
foreach ( var exception in exceptionsToModify )
{
var replacingAppointment = new SchedulerAppointment
{
Oid = exception . Oid . Value * - 1 ,
Version = 1 ,
Type = 4 ,
RecurrenceInfo = exception . RecurrenceInfo ,
Originator = exception . Originator ,
EmployeeList = exception . EmployeeList ,
CustomerList = exception . CustomerList ,
ResourceList = exception . ResourceList
} ;
exception . RecurrenceInfo = null ;
exception . Type = 0 ;
appointments . Add ( replacingAppointment ) ;
}
2021-04-19 04:43:31 +02:00
2018-06-14 15:17:01 +02:00
// Wenn ein Serientermin bearbeitet wird, sodass er außerhalb des Fetch-Zeitraumes liegt, wird er nicht mehr korrekt angezeigt.
// Deshalb werden hier alle Ausnahmen von den in der appointments-Collection enthaltenen Terminen mitgeladen.
var allExceptionalRecurrenceInfos = appointments . Where ( w = > w . RecurrenceInfo ! = null ) ;
2021-04-19 04:43:31 +02:00
2018-10-24 19:32:12 +02:00
var changedOrDeletedOccurences = FindAppointmentsByRecurrenceId ( ExtractRecurrenceIdFromRecurrenceInfo ( allExceptionalRecurrenceInfos . Select ( s = > s . RecurrenceInfo ) . ToList ( ) ) , true ) ;
2018-06-14 15:17:01 +02:00
appointments . AddRangeIfElementsNotIn ( changedOrDeletedOccurences ) ;
2020-07-13 16:25:43 +02:00
2022-09-07 13:19:08 +02:00
#endregion
2021-08-19 17:22:04 +02:00
var deletedAppointments = appointments . Where ( a = > a . IsActive ! = ActivationTypeId . Active ) . ToList ( ) ;
2017-12-22 18:09:52 -04:00
return appointments ;
2017-12-18 17:53:54 +01:00
}
2017-12-19 13:45:48 -04:00
private static ICriterion CreateOrCriteria ( IReadOnlyCollection < ICriterion > criterionList )
2017-12-18 17:53:54 +01:00
{
ICriterion orCriterion = null ;
2021-04-19 04:43:31 +02:00
if ( criterionList ! = null & & criterionList . Count > 0 )
2017-12-18 17:53:54 +01:00
{
2021-04-19 04:43:31 +02:00
foreach ( var c in criterionList )
2017-12-18 17:53:54 +01:00
{
2021-04-19 04:43:31 +02:00
if ( c ! = null )
2017-12-18 17:53:54 +01:00
{
2017-12-22 18:09:52 -04:00
orCriterion = orCriterion = = null ? c : Restrictions . Or ( orCriterion , c ) ;
2017-12-18 17:53:54 +01:00
}
}
}
return orCriterion ;
}
2017-12-22 18:09:52 -04:00
private static ICriterion CreateOwnAppointmentsCriteria ( long pEmployeeOid )
{
var detachedCriteria = DetachedCriteria . For < Employee2SchedulerAppointment > ( )
. Add ( Restrictions . And (
Restrictions . Eq ( Employee2SchedulerAppointment . PropertyName_Employee + ".Oid" , pEmployeeOid ) ,
Restrictions . Not ( Restrictions . Eq ( Employee2SchedulerAppointment . PropertyName_ParticipationAnswer ,
ParticipationAnswer . Absage ) ) ) ) ;
detachedCriteria . SetProjection ( Projections . Property ( Employee2SchedulerAppointment . PropertyName_SchedulerAppointment ) ) ;
var detachedCriteria2 = DetachedCriteria . For < Employee2SchedulerAppointment > ( )
. SetProjection ( Projections . Property ( Employee2SchedulerAppointment . PropertyName_SchedulerAppointment ) ) ;
ICriterion ownAppointmentCriterion = Restrictions . Or (
2018-04-27 14:13:42 +02:00
//Restrictions.And(Restrictions.Eq(SchedulerAppointment.PropertyName_Originator + ".Oid", pEmployeeOid), Subqueries.PropertyNotIn(BeWoEntityBase.PropertyName_Oid, detachedCriteria2)),
Restrictions . Eq ( SchedulerAppointment . PropertyName_Originator + ".Oid" , pEmployeeOid ) ,
2017-12-22 18:09:52 -04:00
Subqueries . PropertyIn ( BeWoEntityBase . PropertyName_Oid , detachedCriteria ) ) ;
2021-04-19 04:43:31 +02:00
2017-12-22 18:09:52 -04:00
return ownAppointmentCriterion ;
}
2022-02-10 11:06:03 +01:00
private ICriteria CreateRecurrenceCriteria ( DateTime start , DateTime end , bool pIncludeInactiveOnes = false , bool excludeTasks = false )
2017-12-18 17:53:54 +01:00
{
2018-10-24 19:32:12 +02:00
var recurrenceBetween = Format ( "'{0:yyyy-MM-dd} 00:00:00' BETWEEN STR_TO_DATE(SUBSTRING({1}, 24, 19), '%m/%d/%Y %H:%i:%s') AND STR_TO_DATE(SUBSTRING({1}, 50, 19), '%m/%d/%Y %H:%i:%s')" , start , SchedulerAppointment . PropertyName_RecurrenceInfo ) ;
2017-12-19 13:45:48 -04:00
var recurrenceAfter = $"'{start:yyyy-MM-dd} 00:00:00' > STR_TO_DATE(SUBSTRING({SchedulerAppointment.PropertyName_RecurrenceInfo}, 24, 19), '%m/%d/%Y %H:%i:%s')" ;
2017-12-18 17:53:54 +01:00
2018-05-20 13:19:28 +02:00
var criteria = CreateCriteria < SchedulerAppointment > ( "sa" ) ;
2022-02-10 11:06:03 +01:00
if ( ! excludeTasks )
{
criteria . Add ( Restrictions . Not ( Restrictions . Eq ( nameof ( SchedulerAppointment . IsTask ) , true ) ) ) ;
}
2018-05-20 13:19:28 +02:00
if ( ! pIncludeInactiveOnes )
{
criteria . Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_IsActive , ActivationTypeId . Active ) ) ;
}
2021-04-19 04:43:31 +02:00
2018-05-20 13:19:28 +02:00
criteria . Add ( Restrictions . Or (
2021-04-19 04:43:31 +02:00
Restrictions . And (
Restrictions . Not ( Restrictions . Like ( SchedulerAppointment . PropertyName_RecurrenceInfo , "Range" , MatchMode . Anywhere ) ) ,
Restrictions . Like ( SchedulerAppointment . PropertyName_RecurrenceInfo , "OccurrenceCount=\"10\"" , MatchMode . Anywhere ) ) ,
Restrictions . Or (
2017-12-18 17:53:54 +01:00
Restrictions . Or (
2021-04-19 04:43:31 +02:00
Restrictions . And ( Restrictions . Lt ( SchedulerAppointment . PropertyName_StartDate , end ) , Restrictions . Ge ( SchedulerAppointment . PropertyName_EndDate , start ) ) ,
Restrictions . Or ( Restrictions . And (
Restrictions . Like ( SchedulerAppointment . PropertyName_RecurrenceInfo , "End" , MatchMode . Anywhere ) ,
Restrictions . And ( Restrictions . IsNotNull ( SchedulerAppointment . PropertyName_RecurrenceInfo ) , Expression . Sql ( new SqlString ( recurrenceBetween ) ) )
) , Restrictions . And (
Restrictions . And (
Restrictions . IsNotNull ( SchedulerAppointment . PropertyName_RecurrenceInfo ) ,
Restrictions . Not ( Restrictions . Like ( SchedulerAppointment . PropertyName_RecurrenceInfo , "End" , MatchMode . Anywhere ) ) ) ,
Expression . Sql ( recurrenceAfter ) ) )
) ,
Restrictions . And ( Restrictions . Eq ( SchedulerAppointment . PropertyName_Type , 3 ) , Expression . Sql ( new SqlString ( recurrenceBetween ) ) ) ) ) ) ;
2017-12-18 17:53:54 +01:00
return criteria ;
2017-12-12 17:20:23 -04:00
}
2017-12-22 18:09:52 -04:00
public IList < SchedulerAppointment > FindDeletedRecurrencesByRecurrenceId ( string pRecurrenceId )
{
var c = CreateCriteria < SchedulerAppointment > ( )
. Add ( Restrictions . Like ( SchedulerAppointment . PropertyName_RecurrenceInfo , pRecurrenceId , MatchMode . Anywhere ) )
. Add ( Restrictions . Eq ( SchedulerAppointment . PropertyName_Type , 4 ) ) ;
return c . List < SchedulerAppointment > ( ) ;
}
2018-05-20 13:19:28 +02:00
2018-10-24 19:32:12 +02:00
public IList < SchedulerAppointment > FindAppointmentsByRecurrenecInfo ( List < string > pRecurrenceInfos , bool pExcludeRootAppointments = false )
{
if ( pRecurrenceInfos = = null | | pRecurrenceInfos . Count = = 0 )
{
return new List < SchedulerAppointment > ( ) ;
}
return FindAppointmentsByRecurrenceId ( ExtractRecurrenceIdFromRecurrenceInfo ( pRecurrenceInfos ) , pExcludeRootAppointments ) ;
}
2021-04-19 04:43:31 +02:00
2018-06-14 15:17:01 +02:00
public IList < SchedulerAppointment > FindAppointmentsByRecurrenceId ( List < string > pRecurrenceIds , bool pExcludeRootAppointments = false )
2018-05-20 13:19:28 +02:00
{
2021-04-19 04:43:31 +02:00
if ( pRecurrenceIds = = null | | pRecurrenceIds . Count = = 0 )
2018-10-08 11:57:16 +02:00
{
return new List < SchedulerAppointment > ( ) ;
}
2021-04-19 04:43:31 +02:00
2018-05-20 13:19:28 +02:00
var criterionList = new List < ICriterion > ( ) ;
2021-04-19 04:43:31 +02:00
pRecurrenceIds . DoForEach ( id = > { criterionList . AddIfNotIn ( Restrictions . Like ( SchedulerAppointment . PropertyName_RecurrenceInfo , id , MatchMode . Anywhere ) ) ; } ) ;
2018-05-20 13:19:28 +02:00
var recurrenceIdOr = CreateOrCriteria ( criterionList ) ;
2021-04-19 04:43:31 +02:00
if ( recurrenceIdOr = = null )
2018-10-08 11:57:16 +02:00
{
2021-04-19 04:43:31 +02:00
return new List < SchedulerAppointment > ( ) ;
;
2018-10-08 11:57:16 +02:00
}
2021-04-19 04:43:31 +02:00
2018-05-20 13:19:28 +02:00
var c = CreateCriteria < SchedulerAppointment > ( )
. Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_IsActive , ActivationTypeId . Active ) )
. Add ( Restrictions . IsNotNull ( SchedulerAppointment . PropertyName_RecurrenceInfo ) )
. Add ( recurrenceIdOr ) ;
2018-06-14 15:17:01 +02:00
if ( pExcludeRootAppointments )
{
2021-04-19 04:43:31 +02:00
c . Add ( Restrictions . In ( nameof ( Appointment . Type ) , new [ ] { 2 , 3 , 4 } ) ) ;
2018-06-14 15:17:01 +02:00
}
2021-04-19 04:43:31 +02:00
2018-05-20 13:19:28 +02:00
return c . List < SchedulerAppointment > ( ) ;
}
2018-05-25 15:07:47 +02:00
2020-11-20 23:28:09 +01:00
public SchedulerAppointment FindRootAppointmentByRecurrenceId ( string recurrenceId )
{
if ( Guid . TryParse ( recurrenceId , out var guid ) )
{
var criteria = CreateCriteria < SchedulerAppointment > ( )
. Add ( Restrictions . Like ( nameof ( SchedulerAppointment . RecurrenceInfo ) , recurrenceId , MatchMode . Anywhere ) )
. Add ( Restrictions . Eq ( nameof ( Appointment . Type ) , 1 ) ) ;
return criteria . List < SchedulerAppointment > ( ) . FirstOrDefault ( ) ;
}
return null ;
}
2018-05-25 15:07:47 +02:00
public IList < SchedulerAppointment > FindAppointmentsForCustomer ( long pCustomerOid )
{
var blah = $"{BeWoEntityBase.PropertyName_Oid} IN (SELECT newschappoid FROM customer2newschapp WHERE customeroid IN ({pCustomerOid}))" ;
var customerCriterion = Expression . Sql ( blah ) ;
var c = CreateCriteria < SchedulerAppointment > ( ) . Add ( customerCriterion ) ;
2021-04-19 04:43:31 +02:00
2018-05-25 15:07:47 +02:00
return c . List < SchedulerAppointment > ( ) ;
}
2023-04-20 00:53:02 +02:00
public IList < SchedulerAppointment > FindAppointmentsForEmployee ( long employeeOid )
{
var blah = $"{BeWoEntityBase.PropertyName_Oid} IN (SELECT newschappoid FROM employee2newschapp WHERE employeeOid IN ({employeeOid}))" ;
var ec = Expression . Sql ( blah ) ;
var c = CreateCriteria < SchedulerAppointment > ( ) . Add ( ec ) ;
return c . List < SchedulerAppointment > ( ) ;
}
2018-05-25 15:07:47 +02:00
public IList < GroupOfPeople > GroupOfPeopleForSupportConcept ( long pCostBearer2SupportConceptOid )
{
var c = CreateCriteria < GroupOfPeople > ( ) ;
2021-04-19 04:43:31 +02:00
c . CreateCriteria ( GroupOfPeople . PropertyName_CostBearer2SupportConceptList , JoinType . InnerJoin )
2018-05-25 15:07:47 +02:00
. Add ( Restrictions . Eq ( BeWoEntityBase . PropertyName_Oid , pCostBearer2SupportConceptOid ) ) ;
return c . List < GroupOfPeople > ( ) ;
}
2018-10-08 11:57:16 +02:00
public IList < CostRatePeriod > FindDefaultHourlyRateCostRatePeriods ( )
{
var c = CreateCriteria < CostRatePeriod > ( ) ;
c . Add ( Restrictions . Eq ( CostRatePeriod . PropertyName_CostRateType , CostRatePeriodType . HourlyRate ) )
. Add ( Restrictions . IsNull ( CostRatePeriod . PropertyName_ObjectOid ) ) ;
return c . List < CostRatePeriod > ( ) ;
}
public virtual IList GetSqlResult ( string sql )
{
var q = Session . CreateSQLQuery ( sql ) ;
return q . List ( ) ;
2021-04-19 04:43:31 +02:00
2018-10-08 11:57:16 +02:00
}
2018-10-24 19:32:12 +02:00
public SchedulerAppointment FindRootAppointmentForException ( SchedulerAppointmentDC pAppointment )
{
if ( pAppointment ? . RecurrenceInfo = = null )
{
return null ;
}
2021-04-19 04:43:31 +02:00
2018-10-24 19:32:12 +02:00
var match = RecurrenceIdRegex . Match ( pAppointment . RecurrenceInfo ) ;
if ( match . Success )
{
var value = match . Value ;
var actualId = value . Split ( "\"" ) ;
if ( actualId . Count > 1 )
{
var id = actualId [ 1 ] ;
var criteria = CreateCriteria < SchedulerAppointment > ( )
. Add ( Restrictions . IsNotNull ( nameof ( SchedulerAppointment . RecurrenceInfo ) ) )
. Add ( Restrictions . Like ( nameof ( SchedulerAppointment . RecurrenceInfo ) , id , MatchMode . Anywhere ) )
. Add ( Restrictions . Eq ( nameof ( Appointment . Type ) , 1 ) ) ;
var resultList = criteria . List < SchedulerAppointment > ( ) ;
if ( resultList = = null | | resultList . Count = = 0 )
{
return null ;
}
return resultList . First ( ) ;
}
}
return null ;
}
public SchedulerAppointment FindRootAppointmentForException ( SchedulerAppointment pAppointment )
{
if ( pAppointment ? . RecurrenceInfo = = null )
{
return null ;
}
var match = RecurrenceIdRegex . Match ( pAppointment . RecurrenceInfo ) ;
if ( match . Success )
{
var value = match . Value ;
var actualId = value . Split ( "\"" ) ;
if ( actualId . Count > 1 )
{
var id = actualId [ 1 ] ;
var criteria = CreateCriteria < SchedulerAppointment > ( )
. Add ( Restrictions . IsNotNull ( nameof ( SchedulerAppointment . RecurrenceInfo ) ) )
. Add ( Restrictions . Like ( nameof ( SchedulerAppointment . RecurrenceInfo ) , id , MatchMode . Anywhere ) )
. Add ( Restrictions . Eq ( nameof ( Appointment . Type ) , 1 ) ) ;
var resultList = criteria . List < SchedulerAppointment > ( ) ;
if ( resultList = = null | | resultList . Count = = 0 )
{
return null ;
}
return resultList . First ( ) ;
}
}
return null ;
}
private static List < string > ExtractRecurrenceIdFromRecurrenceInfo ( List < string > pRecurrenceInfos )
{
var recurrenceIds = new List < string > ( ) ;
foreach ( var info in pRecurrenceInfos )
{
var match = RecurrenceIdRegex . Match ( info ) ;
if ( match . Success )
{
var value = match . Value ;
var actualId = value . Split ( "\"" ) ;
if ( actualId . Count > 1 )
{
recurrenceIds . AddIfNotIn ( actualId [ 1 ] ) ;
}
}
}
return recurrenceIds ;
}
2019-02-28 12:38:29 +01:00
public IList < Task > LoadTasksForConversion ( long pEmployeeOid )
{
var c = CreateCriteriaIsActive < Task > ( ) ;
c . Add ( Expression . Sql ( $"this_.{nameof(BeWoEntityBase.Oid)} NOT IN (SELECT {nameof(SchedulerAppointment.FormerTaskOid)} FROM newschedulerappointment WHERE {nameof(SchedulerAppointment.FormerTaskOid)} IS NOT NULL)" ) ) ;
2021-04-19 04:43:31 +02:00
2019-02-28 12:38:29 +01:00
var result = c . CreateAlias ( nameof ( Task . SupportConcept ) , "sc" , JoinType . InnerJoin )
. CreateAlias ( "sc." + nameof ( SupportConcept . Customer ) , "c" , JoinType . InnerJoin )
. CreateCriteria ( nameof ( Task . EmployeeList ) , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( nameof ( BeWoEntityBase . Oid ) , pEmployeeOid ) )
. Add ( Restrictions . Eq ( "sc." + nameof ( BeWoEntityBase . IsActive ) , ActivationTypeId . Active ) )
. Add ( Restrictions . Eq ( "c." + nameof ( BeWoEntityBase . IsActive ) , ActivationTypeId . Active ) )
. List < Task > ( ) ;
return result ;
}
2020-11-25 11:40:05 +01:00
public IList < SchedulerAppointment > LoadTaskAppointmentsForEmployee ( long pEmployee , bool hideCompletedTasks )
2019-02-28 12:38:29 +01:00
{
var c = CreateCriteriaIsActive < SchedulerAppointment > ( )
. Add ( Restrictions . Eq ( nameof ( SchedulerAppointment . IsTask ) , true ) ) ;
2021-04-19 04:43:31 +02:00
if ( hideCompletedTasks )
2020-11-25 11:40:05 +01:00
{
c . Add ( Restrictions . IsNull ( nameof ( SchedulerAppointment . CompletedDate ) ) ) ;
}
2019-02-28 12:38:29 +01:00
var employeeListRelationCriteria = DetachedCriteria . For < Employee2SchedulerAppointment > ( )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . In ( Employee2SchedulerAppointment . PropertyName_Employee + ".Oid" , new List < long > { pEmployee } ) )
2019-02-28 12:38:29 +01:00
. SetProjection ( Projections . Property ( Employee2SchedulerAppointment . PropertyName_SchedulerAppointment ) ) ;
2021-04-19 04:43:31 +02:00
2019-02-28 12:38:29 +01:00
var employee2SchedCrit = Subqueries . PropertyIn ( BeWoEntityBase . PropertyName_Oid , employeeListRelationCriteria ) ;
c . Add ( employee2SchedCrit ) ;
2021-04-19 04:43:31 +02:00
2019-02-28 12:38:29 +01:00
var result = c . List < SchedulerAppointment > ( ) ;
return result ;
}
public IList < SchedulerAppointment > GetTasksForEmployeeBySupportConcept ( long pEmployeeOid , long pSupportConceptOid )
{
var c = CreateCriteriaIsActive < SchedulerAppointment > ( ) ;
var employeeListRelationCriteria = DetachedCriteria . For < Employee2SchedulerAppointment > ( )
. Add ( Restrictions . In ( nameof ( Employee2SchedulerAppointment . Employee ) + ".Oid" , new List < long > { pEmployeeOid } ) )
. SetProjection ( Projections . Property ( nameof ( Employee2SchedulerAppointment . SchedulerAppointmentOid ) ) ) ;
var employee2SchedCrit = Subqueries . PropertyIn ( nameof ( BeWoEntityBase . Oid ) , employeeListRelationCriteria ) ;
2021-04-19 04:43:31 +02:00
2019-02-28 12:38:29 +01:00
c . Add ( employee2SchedCrit ) ;
var sql = Expression . Sql ( $"{nameof(BeWoEntityBase.Oid)} IN (SELECT newschappoid FROM supportconcept2newschapp WHERE supportconceptoid = {pSupportConceptOid})" ) ;
c . Add ( sql ) ;
2021-04-19 04:43:31 +02:00
2019-02-28 12:38:29 +01:00
return c . List < SchedulerAppointment > ( ) ;
}
2019-07-01 15:11:19 +02:00
public IList < InvoiceBase > GetInvoiceBasesBySupportConceptOids ( List < long > pSupprortConceptOids )
{
var c = CreateCriteria < InvoiceBase > ( ) ;
c . Add ( Restrictions . In ( nameof ( InvoiceBase . SupportConceptOid ) , pSupprortConceptOids ) ) ;
return c . List < InvoiceBase > ( ) ;
}
public IEnumerable < SettlementInvoice > GetSettlementInvoiceBySupportConceptOids ( List < long > pSupportConceptOids )
{
return CreateCriteria < SettlementInvoice > ( )
. CreateAlias ( SettlementInvoice . PropertyName_InvoiceBase , "ib" , JoinType . InnerJoin )
. Add ( Restrictions . In ( "ib." + InvoiceBase . PropertyName_SupportConceptOid , pSupportConceptOids ) )
. List < SettlementInvoice > ( ) ;
}
public IList < ServiceInvoice > GetServiceInvoicesByInvoiceBaseOids ( List < long > pIinvoiceBaseOids )
{
var res = CreateCriteria < ServiceInvoice > ( )
. CreateAlias ( ServiceInvoice . PropertyName_InvoiceBase , "ib" , JoinType . InnerJoin )
. Add ( Restrictions . In ( "ib." + BeWoEntityBase . PropertyName_Oid , pIinvoiceBaseOids ) )
. List < ServiceInvoice > ( ) ;
return res ;
}
public IList < AdditionalServiceBooking > GetAllAdditionalServiceBookingsForCustomer ( long pCustomerOid )
{
return CreateCriteria < AdditionalServiceBooking > ( )
. CreateAlias ( AdditionalServiceBooking . PropertyName_Customer2AddServiceBookings , "c2s" , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( "c2s.CustomerOid" , pCustomerOid ) )
. List < AdditionalServiceBooking > ( ) ;
}
public IList < AdditionalServiceGroupOfPeople > GetAdditionalServiceGroupOfPeopleForCustomer ( long pCustomerOid )
{
var c = CreateCriteria < AdditionalServiceGroupOfPeople > ( ) ;
c . CreateCriteria ( nameof ( AdditionalServiceGroupOfPeople . CustomerList ) , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( nameof ( BeWoEntityBase . Oid ) , pCustomerOid ) ) ;
return c . List < AdditionalServiceGroupOfPeople > ( ) ;
}
public IList < SchedulerAppointment > GetTasksAndAppointmentsBySupportConceptOids ( List < long > pSupportConceptOids )
{
var c = CreateCriteria < SchedulerAppointment > ( ) ;
var list = "" ;
2021-04-19 04:43:31 +02:00
for ( var i = 0 ; i < pSupportConceptOids . Count ; i + + )
2019-07-01 15:11:19 +02:00
{
2021-04-19 04:43:31 +02:00
if ( i ! = pSupportConceptOids . Count - 1 )
2019-07-01 15:11:19 +02:00
{
list + = "" + pSupportConceptOids [ i ] + "," ;
}
else
{
list + = "" + pSupportConceptOids [ i ] ;
}
}
var blah = $"{nameof(BeWoEntityBase.Oid)} IN (SELECT newschappoid FROM supportconcept2newschapp WHERE supportconceptoid IN ({list}))" ;
var supportConceptCriterion = Expression . Sql ( blah ) ;
c . Add ( supportConceptCriterion ) ;
return c . List < SchedulerAppointment > ( ) ;
}
public IList < Customer2Token > GetCustomer2TokensByCustomerOid ( long pCustomerOid )
{
var c = CreateCriteria < Customer2Token > ( ) ;
c . Add ( Restrictions . Eq ( nameof ( Customer2Token . Customer ) + "." + nameof ( BeWoEntityBase . Oid ) , pCustomerOid ) ) ;
return c . List < Customer2Token > ( ) ;
}
public IList < SchedulerAppointment > GetTestAppointments ( )
{
var c = CreateCriteria < SchedulerAppointment > ( ) ;
2022-02-10 11:06:03 +01:00
c . Add ( Restrictions . Eq ( nameof ( BeWoEntityBase . Notice ) , BS . Shared . Core . Utils . TestAppointmentNotice ) ) ;
2019-07-01 15:11:19 +02:00
return c . List < SchedulerAppointment > ( ) ;
}
2019-08-08 14:47:53 +02:00
2019-09-02 15:48:37 +02:00
public bool CheckForOverlappingSubstitutions ( long? employeeOid , long? customerOid , DateTime startDate , DateTime endDate , long? substitutionOid )
2019-08-08 14:47:53 +02:00
{
2019-09-02 15:48:37 +02:00
var c = CreateCriteria < Vertretung > ( ) ;
2019-08-08 14:47:53 +02:00
2019-09-02 15:48:37 +02:00
var employeeRestriction = Restrictions . Eq ( nameof ( Vertretung . EmployeeOid ) , employeeOid ) ;
var customerRestriction = Restrictions . Eq ( nameof ( Vertretung . CustomerOid ) , customerOid ) ;
var notCurrentSubstitution = Restrictions . Not ( Restrictions . Eq ( nameof ( BeWoEntityBase . Oid ) , substitutionOid ) ) ;
2019-08-08 14:47:53 +02:00
var peopleRestriction = Restrictions . Or ( employeeRestriction , customerRestriction ) ;
2019-09-02 15:48:37 +02:00
var timeRestriction = CreateBetweenDateTimesCriterion ( startDate , endDate , nameof ( Vertretung . VertretungsZeitraumVon ) , nameof ( Vertretung . VertretungsZeitraumBis ) ) ;
2019-08-08 14:47:53 +02:00
2019-09-02 15:48:37 +02:00
c . Add ( peopleRestriction ) . Add ( timeRestriction ) . Add ( notCurrentSubstitution ) ;
2019-08-08 14:47:53 +02:00
2019-09-02 15:48:37 +02:00
return c . List < Vertretung > ( ) . Any ( ) ;
2019-08-08 14:47:53 +02:00
}
2019-08-16 18:03:30 +02:00
private static AbstractCriterion CreateBetweenDateTimesCriterion ( DateTime start , DateTime end , string propertyNameStart , string propertyNameEnd )
{
2020-11-20 23:28:09 +01:00
/ * - - VERALTET - - - - - VERALTET - - - - - VERALTET - - - - - VERALTET - - - - - VERALTET - - - - - VERALTET - - - - - VERALTET - - - - - VERALTET - -
2020-10-20 21:07:26 +02:00
* Sql für Spalten namens ' StartDate ' und ' EndDate ' :
* WHERE
* ( ( start > = StartDate AND end < = StartDate ) OR ( start < = StartDate AND end > = EndDate ) )
* OR
* ( ( start < = StartDate AND start > = EndDate ) OR ( start > = StartDate AND end < = EndDate ) )
* /
2020-11-20 23:28:09 +01:00
//var inBetween1 = Restrictions.And(Restrictions.Ge(propertyNameStart, start), Restrictions.Le(propertyNameStart, end));
//var inBetween2 = Restrictions.And(Restrictions.Le(propertyNameStart, start), Restrictions.Ge(propertyNameEnd, end));
//var inBetween3 = Restrictions.And(Restrictions.Le(propertyNameStart, start), Restrictions.Ge(propertyNameEnd, start));
//var inBetween4 = Restrictions.And(Restrictions.Ge(propertyNameStart, start), Restrictions.Le(propertyNameEnd, end));
//return Restrictions.Or(Restrictions.Or(inBetween1, inBetween2), Restrictions.Or(inBetween3, inBetween4));
// -- VERALTET ----- VERALTET ----- VERALTET ----- VERALTET ----- VERALTET ----- VERALTET ----- VERALTET ----- VERALTET --
// NEU -- NEU -- NEU -- NEU -- NEU -- NEU -- NEU -- NEU -- NEU -- NEU -- NEU -- NEU -- NEU -- NEU -- NEU -- NEU -- NEU
/ * Sql für Spalten namens ' StartDate ' und ' EndDate ' :
* ( StartDate < ' 2020 - 11 - 19 10 : 00 : 00 ' AND EndDate < = ' 2020 - 11 - 19 12 : 00 : 00 ' AND EndDate > ' 2020 - 11 - 19 10 : 00 : 00 ' )
OR
( StartDate < ' 2020 - 11 - 19 10 : 00 : 00 ' AND EndDate > ' 2020 - 11 - 19 12 : 00 : 00 ' )
OR
( StartDate > ' 2020 - 11 - 19 10 : 00 : 00 ' AND StartDate < ' 2020 - 11 - 19 12 : 00 : 00 ' )
OR
( StartDate = ' 2020 - 11 - 19 10 : 00 : 00 ' AND EndDate = ' 2020 - 11 - 19 12 : 00 : 00 ' )
OR
( StartDate = ' 2020 - 11 - 19 10 : 00 : 00 ' AND EndDate > = ' 2020 - 11 - 19 12 : 00 : 00 ' )
* /
// NEU -- NEU -- NEU -- NEU -- NEU -- NEU -- NEU -- NEU -- NEU -- NEU -- NEU -- NEU -- NEU -- NEU -- NEU -- NEU -- NEU
var inBetween1 = Restrictions . And ( Restrictions . Lt ( propertyNameStart , start ) , Restrictions . And ( Restrictions . Le ( propertyNameEnd , end ) , Restrictions . Gt ( propertyNameEnd , start ) ) ) ;
var inBetween2 = Restrictions . And ( Restrictions . Lt ( propertyNameStart , start ) , Restrictions . Gt ( propertyNameEnd , end ) ) ;
var inBetween3 = Restrictions . And ( Restrictions . Gt ( propertyNameStart , start ) , Restrictions . Lt ( propertyNameStart , end ) ) ;
var inBetween4 = Restrictions . And ( Restrictions . Eq ( propertyNameStart , start ) , Restrictions . Eq ( propertyNameEnd , end ) ) ;
var inBetween5 = Restrictions . And ( Restrictions . Eq ( propertyNameStart , start ) , Restrictions . Le ( propertyNameEnd , end ) ) ;
2019-08-16 18:03:30 +02:00
2020-11-20 23:28:09 +01:00
return Restrictions . Or ( inBetween1 , Restrictions . Or ( Restrictions . Or ( inBetween2 , inBetween3 ) , Restrictions . Or ( inBetween4 , inBetween5 ) ) ) ;
2019-08-16 18:03:30 +02:00
}
2019-09-02 15:48:37 +02:00
public bool CheckForOverlappingAbsenceTimes ( DateTime startDate , DateTime endDate , long? employeeOid , long? customerOid )
{
var c = CreateCriteria < AbsenceTime > ( ) ;
2019-09-27 15:55:01 +02:00
var peopleRestriction = employeeOid ! = null ? Restrictions . Eq ( nameof ( AbsenceTime . EmployeeOid ) , employeeOid ) : Restrictions . Eq ( nameof ( AbsenceTime . CustomerOid ) , customerOid ) ;
2019-09-02 15:48:37 +02:00
var timeRestriction = CreateBetweenDateTimesCriterion ( startDate , endDate , nameof ( AbsenceTime . Start ) , nameof ( AbsenceTime . End ) ) ;
c . Add ( peopleRestriction ) . Add ( timeRestriction ) ;
return c . List < AbsenceTime > ( ) . Any ( ) ;
}
public IList < Vertretung > GetLastSubstitutionItems ( long employeeOid , int count )
{
var criteria = CreateCriteria < Vertretung > ( ) ;
criteria . Add ( Restrictions . Eq ( nameof ( Vertretung . EmployeeOid ) , employeeOid ) ) ;
criteria . AddOrder ( Order . Desc ( nameof ( Vertretung . VertretungsZeitraumBis ) ) ) ;
criteria . SetMaxResults ( count ) ;
2019-12-07 21:06:03 +01:00
return criteria . List < Vertretung > ( ) . Where ( w = > w . VertretungsZeitraumVon > DateTime . MinValue & & w . VertretungsZeitraumBis > DateTime . MinValue ) . ToList ( ) ;
2019-09-02 15:48:37 +02:00
}
2019-09-27 15:55:01 +02:00
public Dictionary < Customer , List < ArbeitszeitEintrag > > GetAssistanceTimesForEmployee ( long employeeOid , DateTime start , DateTime end )
{
// Arbeitszeit -> keine EmployeeOid, nur in den Arbeitszeiteinträgen
var criteria = CreateCriteria < Arbeitszeit > ( ) ;
var detachedCriteria = DetachedCriteria . For < ArbeitszeitEintrag > ( ) . Add ( Restrictions . Eq ( nameof ( ArbeitszeitEintrag . Employee ) + ".Oid" , employeeOid ) ) . SetProjection ( Projections . Property ( nameof ( ArbeitszeitEintrag . ArbeitszeitOid ) ) ) ;
var subquery = Subqueries . PropertyIn ( nameof ( BeWoEntityBase . Oid ) , detachedCriteria ) ;
criteria . Add ( subquery ) ;
criteria . Add ( CreateArbeitszeitenTimeRestictions ( start , end ) ) ;
var assistanceTimes = criteria . List < Arbeitszeit > ( ) ;
var result = new Dictionary < Customer , List < ArbeitszeitEintrag > > ( ) ;
foreach ( var assistanceTimeEntry in assistanceTimes )
{
if ( assistanceTimeEntry . Customer ! = null )
{
result . AddOrUpdateValueInDictionary ( assistanceTimeEntry . Customer , assistanceTimeEntry . ArbeitszeitEintraege . ToList ( ) ) ;
}
}
return result ;
}
private ICriterion CreateArbeitszeitenTimeRestictions ( DateTime start , DateTime end )
{
// GueltigVon und GueltigBis sind null
var gueltigVonAndGueltigBisAreNull = Restrictions . And ( Restrictions . IsNull ( nameof ( Arbeitszeit . GueltigVon ) ) , Restrictions . IsNull ( nameof ( Arbeitszeit . GueltigBis ) ) ) ;
// GueltigVon ist null, GueltigBis ist nicht null
var gueltigVonIsNullAndGueltigBisIsGtStart = Restrictions . And ( Restrictions . And ( Restrictions . IsNull ( nameof ( Arbeitszeit . GueltigVon ) ) , Restrictions . Gt ( nameof ( Arbeitszeit . GueltigBis ) , start ) ) , Restrictions . And ( Restrictions . IsNull ( nameof ( Arbeitszeit . GueltigVon ) ) , Restrictions . Ge ( nameof ( Arbeitszeit . GueltigBis ) , start ) ) ) ;
// GueltigVon ist nicht null, GueltigBis ist null
var gueltigBisIsNullAndGueltigVonIsLtEnd = Restrictions . And ( Restrictions . IsNotNull ( nameof ( Arbeitszeit . GueltigVon ) ) , Restrictions . And ( Restrictions . IsNull ( nameof ( Arbeitszeit . GueltigBis ) ) , Restrictions . Gt ( nameof ( Arbeitszeit . GueltigVon ) , end ) ) ) ;
var and1 = Restrictions . And ( Restrictions . IsNotNull ( nameof ( Arbeitszeit . GueltigVon ) ) , Restrictions . IsNotNull ( nameof ( Arbeitszeit . GueltigBis ) ) ) ;
var and3 = Restrictions . And ( Restrictions . Le ( nameof ( Arbeitszeit . GueltigVon ) , start ) , Restrictions . Ge ( nameof ( Arbeitszeit . GueltigBis ) , start ) ) ;
var and4 = Restrictions . And ( Restrictions . Le ( nameof ( Arbeitszeit . GueltigVon ) , end ) , Restrictions . Gt ( nameof ( Arbeitszeit . GueltigBis ) , end ) ) ;
var and5 = Restrictions . And ( Restrictions . Ge ( nameof ( Arbeitszeit . GueltigVon ) , start ) , Restrictions . Le ( nameof ( Arbeitszeit . GueltigBis ) , end ) ) ;
var or1 = Restrictions . Or ( and4 , and5 ) ;
var or2 = Restrictions . Or ( and3 , or1 ) ;
// GueltigVon und GueltigBis sind nicht null
var gueltigVonAndGueltigBisAreNotNull = Restrictions . And ( and1 , or2 ) ;
return Restrictions . Or ( gueltigVonAndGueltigBisAreNull , Restrictions . Or ( Restrictions . Or ( gueltigVonIsNullAndGueltigBisIsGtStart , gueltigBisIsNullAndGueltigVonIsLtEnd ) , gueltigVonAndGueltigBisAreNotNull ) ) ;
}
public IList < Customer > GetCustomersWithSubstitutionNeedUnset ( )
{
var c = CreateCriteria < Customer > ( ) ;
c . Add ( Restrictions . IsNull ( nameof ( Customer . SubstitutionNeed ) ) ) ;
return c . List < Customer > ( ) ;
}
public List < long > FindTeamRelatedCustomerOids ( long employeeOid )
{
var result = new List < long > ( ) ;
var teams = CreateCriteriaIsActive < Team > ( )
. Add ( Restrictions . IsNotNull ( nameof ( BeWoEntityBase . Oid ) ) )
. CreateCriteria ( nameof ( Team . MemberList ) , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( nameof ( BeWoEntityBase . Oid ) , employeeOid ) )
. List < Team > ( ) ;
var members = new List < Employee > ( ) ;
foreach ( var team in teams )
{
members . AddRangeIfElementsNotIn ( team . MemberList ) ;
}
foreach ( var member in members )
{
foreach ( var employee2customer in member . Employee2CustomerList )
{
if ( employee2customer . CustomerOid . HasValue )
{
result . AddIfNotIn ( employee2customer . CustomerOid . Value ) ;
}
}
}
return result ;
}
public List < Customer > FindCustomersForAbsenceTimesByStartAndEnd ( DateTime intervalStart , DateTime intervalEnd )
{
var criteria = CreateCriteriaIsActive < Customer > ( ) ;
// Arbeitszeiten im gewählten Intervall holen und dann die einträge nach customeroid durchsuchen
// TODO: implementieren
return criteria . List < Customer > ( ) . ToList ( ) ;
}
2020-04-02 13:19:14 +02:00
public List < CostBearer2SupportConcept > FindCostBearer2SupportConceptsByOids ( List < long > costbearer2SupportConceptOids )
{
var c = CreateCriteriaIsActive < CostBearer2SupportConcept > ( ) ;
2021-04-19 04:43:31 +02:00
2020-04-02 13:19:14 +02:00
c . Add ( Restrictions . In ( nameof ( CostBearer2SupportConcept . Oid ) , costbearer2SupportConceptOids ) ) ;
return c . List < CostBearer2SupportConcept > ( ) . ToList ( ) ;
}
2020-06-29 19:24:24 +02:00
public bool IsResourceAvailable ( DateTime start , DateTime end , long resourceOid )
{
var c = CreateCriteriaIsActive < Resource > ( ) ;
var sql = $"SELECT COUNT(*) FROM resource WHERE oid = {resourceOid} AND isactive = 1 AND oid NOT IN (SELECT resourceoid FROM resource2newschapp r WHERE r.newschappoid NOT IN (SELECT oid FROM newschedulerappointment WHERE startdate > '{start:yyyy-MM-dd HH:mm:ss}' OR enddate < '{end:yyyy-MM-dd HH:mm:ss}'));" ;
var criterion = Expression . Sql ( sql ) ;
c . Add ( criterion ) ;
return c . List ( ) . Count > 0 ;
}
public List < Resource > GetAvailableResources ( DateTime start , DateTime end )
{
var c = CreateCriteria < Resource > ( "r" ) . Add ( Restrictions . Eq ( nameof ( BeWoEntityBase . IsActive ) , ActivationTypeId . Active ) ) ;
var sql = $"Oid NOT IN (SELECT Oid FROM resource WHERE isactive = 1 AND Oid NOT IN (SELECT resourceoid FROM resource2newschapp r2n WHERE r2n.newschappoid NOT IN (SELECT oid FROM newschedulerappointment WHERE startdate > '{start:yyyy-MM-dd HH:mm:ss}' OR enddate < '{end:yyyy-MM-dd HH:mm:ss}')))" ;
var criterion = Expression . Sql ( sql ) ;
c . Add ( criterion ) ;
return c . List < Resource > ( ) . ToList ( ) ;
}
/// <summary>
/// Prüft anhand der Oids von Ressourcen deren Verfügbarkeit in einem Zeitraum.
/// Gibt die nicht verfügbaren Ressourcen zurück für eine detaillierte Fehlermeldung.
/// </summary>
/// <param name="resourceOids">Die Oids der zu überprüfenden Ressourcen</param>
2023-01-12 19:47:14 +01:00
/// <param name="start">Anfang des zu prüfenden Intervalls</param>
/// <param name="end">Ende des zu prüfenden Intervalls</param>
/// <param name="selectedAppointmentOid">Die Oid des Termins</param>
/// <param name="recurrenceId">Recurrence Id, falls es sich um einen Serientermin handelt, der keine eigene Oid hat.</param>
/// <param name="occurrenceIndex">Occurrence-Index des Serientermins ohne eigene Oid</param>
/// <returns>Die im angegebenen Zeitraum belegten Ressourcen</returns>
public List < Resource > CheckAvailabilityOfResources ( List < long > resourceOids , DateTime start , DateTime end , long? selectedAppointmentOid , Guid ? recurrenceId = null , int? occurrenceIndex = null )
2020-06-29 19:24:24 +02:00
{
var c = CreateCriteria < Resource > ( "r" ) . Add ( Restrictions . Eq ( nameof ( BeWoEntityBase . IsActive ) , ActivationTypeId . Active ) ) . Add ( Restrictions . In ( nameof ( BeWoEntityBase . Oid ) , resourceOids ) ) ;
2023-01-18 13:43:11 +01:00
var excludingSelectedAppointment = selectedAppointmentOid . HasValue ? $"Oid <> {selectedAppointmentOid} AND " : "" ;
2020-06-29 19:24:24 +02:00
var sql = "Oid IN " +
2023-01-18 13:43:11 +01:00
"(SELECT ResourceOid FROM resource2newschapp r2n WHERE r2n.NewSchAppOid IN " +
$"(SELECT Oid FROM newschedulerappointment WHERE IsActive = 1 AND Type <> 4 AND {excludingSelectedAppointment}('{start:yyyy-MM-dd HH:mm:ss}' > StartDate OR '{end:yyyy-MM-dd HH:mm:ss}' > StartDate) AND ('{start:yyyy-MM-dd HH:mm:ss}' < EndDate OR '{end:yyyy-MM-dd HH:mm:ss}' < EndDate)))" ;
2020-06-29 19:24:24 +02:00
var criterion = Expression . Sql ( sql ) ;
c . Add ( criterion ) ;
2021-04-19 04:43:31 +02:00
2020-12-01 12:29:12 +01:00
var resources = c . List < Resource > ( ) . ToList ( ) ;
var recurringAppointmentsCriteria = CreateRecurrenceCriteria ( start , end ) . Add ( Restrictions . Eq ( nameof ( SchedulerAppointment . Type ) , 1 ) ) ;
var recurringAppointments = recurringAppointmentsCriteria . List < SchedulerAppointment > ( ) . ToList ( ) ;
2023-01-26 12:55:56 +01:00
2020-12-01 12:29:12 +01:00
recurringAppointments = recurringAppointments . Where ( s = > s . ResourceList . Any ( r = > r . Oid . HasValue & & resourceOids . Contains ( r . Oid . Value ) ) ) . ToList ( ) ;
2023-01-26 00:31:27 +01:00
if ( recurringAppointments . Count = = 0 )
2023-01-26 12:55:56 +01:00
{
return resources ;
}
2020-12-01 12:29:12 +01:00
var changedOccurrencesCriteria = CreateCriteriaIsActive < SchedulerAppointment > ( ) . Add ( Restrictions . Eq ( nameof ( SchedulerAppointment . Type ) , 3 ) ) ;
var deletedOccurrencesCriteria = CreateCriteria < SchedulerAppointment > ( ) . Add ( Restrictions . Eq ( nameof ( SchedulerAppointment . Type ) , 4 ) ) ;
var inBetween = CreateBetweenDateTimesCriterion ( start , end , nameof ( SchedulerAppointment . StartDate ) , nameof ( SchedulerAppointment . EndDate ) ) ;
changedOccurrencesCriteria . Add ( inBetween ) ;
deletedOccurrencesCriteria . Add ( inBetween ) ;
var appointments = new List < SchedulerAppointment > ( ) ;
if ( selectedAppointmentOid . HasValue )
{
changedOccurrencesCriteria . Add ( Restrictions . Not ( Restrictions . Eq ( nameof ( BeWoEntityBase . Oid ) , selectedAppointmentOid . Value ) ) ) ;
deletedOccurrencesCriteria . Add ( Restrictions . Not ( Restrictions . Eq ( nameof ( BeWoEntityBase . Oid ) , selectedAppointmentOid . Value ) ) ) ;
}
2023-01-26 12:55:56 +01:00
var changedOccurrences = new List < SchedulerAppointment > ( ) ;
2023-01-19 17:19:09 +01:00
var recurrenceIds = string . Empty ;
recurringAppointments . DoForEach ( appointment = > recurrenceIds + = $"'{appointment.GetRecurrenceId()}'," ) ;
recurrenceIds = recurrenceIds . Trim ( ',' ) ;
2023-01-26 12:55:56 +01:00
if ( recurrenceIds . Any ( ) )
{
var changedCriteria = CreateCriteriaIsActive < SchedulerAppointment > ( )
. Add ( Restrictions . Eq ( nameof ( SchedulerAppointment . Type ) , 3 ) )
. Add ( Expression . Sql ( $"RecurrenceInfo IS NOT NULL AND RecurrenceInfo LIKE '%Id%' AND SUBSTRING(RecurrenceInfo, LOCATE('Id', RecurrenceInfo) + 4, 36) IN ({recurrenceIds})" ) ) ;
2023-01-19 17:19:09 +01:00
2023-01-26 12:55:56 +01:00
changedOccurrences = changedCriteria . List < SchedulerAppointment > ( ) . ToList ( ) ;
}
2023-01-19 17:19:09 +01:00
//var changedOccurrences = changedOccurrencesCriteria.List<SchedulerAppointment>().Where(a => a.ResourceList.Any(r => r.Oid.HasValue && resourceOids.Contains(r.Oid.Value))).ToList();
2020-12-01 12:29:12 +01:00
var deletedOccurrences = deletedOccurrencesCriteria . List < SchedulerAppointment > ( ) . Where ( a = > a . ResourceList . Any ( r = > r . Oid . HasValue & & resourceOids . Contains ( r . Oid . Value ) ) ) . ToList ( ) ;
2023-01-12 19:47:14 +01:00
2020-12-01 12:29:12 +01:00
// Sich wiederholende Termine erzeugen und dabei die Ausnahmen und gelöschten Ausnahmen ignorieren
var interval = new TimeInterval ( start , end ) ;
foreach ( var recurringAppointment in recurringAppointments )
{
var recurrenceInfo = new RecurrenceInfo ( ) ;
recurrenceInfo . FromXml ( recurringAppointment . RecurrenceInfo ) ;
var occurenceCalculator = OccurrenceCalculator . CreateInstance ( recurrenceInfo ) ;
// Das Muster für die Terminserie wird berechnet
var pattern = StaticAppointmentFactory . CreateAppointment ( AppointmentType . Pattern ) ;
pattern . RecurrenceInfo . FromXml ( recurringAppointment . RecurrenceInfo ) ;
pattern . Start = pattern . RecurrenceInfo . Start ;
pattern . End = pattern . RecurrenceInfo . End ;
if ( ! Guid . TryParse ( pattern . RecurrenceInfo . Id . ToString ( ) , out var patternId ) )
{
continue ;
}
// Die Serientermine werden berechnet (ausnahmslos, d.h. es werden auch bearbeitete und gelöschte Termine erstellt, die herausgefiltert werden müssen).
var occurrences = occurenceCalculator . CalcOccurrences ( interval , pattern ) ;
2023-01-12 19:47:14 +01:00
var occurrenceAppointments = occurrences . GetAppointments ( interval ) ;
foreach ( var occurrence in occurrenceAppointments )
2020-12-01 12:29:12 +01:00
{
2023-01-18 13:43:11 +01:00
if ( recurringAppointment . EndDate is null | | recurringAppointment . StartDate is null )
2020-12-01 12:29:12 +01:00
{
continue ;
}
// Sicher machen
var index = occurrence . RecurrenceIndex ;
var isDeletedOrChanged = changedOccurrences . Any ( a = >
{
var guid = a . GetRecurrenceIdAndIndex ( out var i ) ;
2023-01-26 13:46:34 +01:00
if ( guid is null )
2020-12-01 12:29:12 +01:00
{
2023-01-26 13:46:34 +01:00
return false ;
}
if ( guid . Value . Equals ( patternId ) & & index = = i )
{
return true ;
2020-12-01 12:29:12 +01:00
}
return false ;
} ) | | deletedOccurrences . Any ( a = >
{
var guid = a . GetRecurrenceIdAndIndex ( out var i ) ;
2023-01-26 13:46:34 +01:00
if ( guid is null )
2020-12-01 12:29:12 +01:00
{
2023-01-26 13:46:34 +01:00
return false ;
}
if ( guid . Value . Equals ( patternId ) & & index = = i )
{
return true ;
2020-12-01 12:29:12 +01:00
}
return false ;
} ) ;
if ( isDeletedOrChanged )
{
continue ;
}
var duration = ( recurringAppointment . EndDate . Value - recurringAppointment . StartDate . Value ) . TotalMinutes ;
var isInIntervalTest = start . IsInInterval ( end , occurrence . Start , occurrence . Start . AddMinutes ( duration ) ) ;
if ( ! isInIntervalTest )
{
continue ;
}
var occurrenceAppointment = new SchedulerAppointment
{
2023-01-12 19:47:14 +01:00
AllDay = occurrence . AllDay ,
CustomerList = recurringAppointment . CustomerList ,
Notice = recurringAppointment . Notice ,
EmployeeList = recurringAppointment . EmployeeList ,
EndDate = occurrence . Start . AddMinutes ( duration ) ,
2020-12-01 12:29:12 +01:00
FormerBookingSequenceOid = recurringAppointment . FormerBookingSequenceOid ,
2023-01-12 19:47:14 +01:00
IsPrivate = recurringAppointment . IsPrivate ,
Location = recurringAppointment . Location ,
Originator = recurringAppointment . Originator ,
RecurrenceInfo = occurrence . RecurrenceInfo . ToXml ( ) ,
ReminderInfo = recurringAppointment . ReminderInfo ,
ResourceList = recurringAppointment . ResourceList ,
StartDate = occurrence . Start ,
Subject = recurringAppointment . Subject ? ? Empty ,
Type = recurringAppointment . Type
2020-12-01 12:29:12 +01:00
} ;
2023-01-12 19:47:14 +01:00
if ( ! ( recurrenceId is null ) & & occurrenceIndex . HasValue )
{
var recId = occurrenceAppointment . GetRecurrenceId ( ) ;
if ( ( recId ? . Equals ( recurrenceId . Value ) ? ? false ) & & index . Equals ( occurrenceIndex . Value ) )
{
continue ;
}
}
2020-12-01 12:29:12 +01:00
appointments . AddIfNotIn ( occurrenceAppointment ) ;
}
}
appointments . DoForEach ( a = > a . ResourceList . DoForEach ( resources . AddIfNotIn ) ) ;
return resources ;
2020-06-29 19:24:24 +02:00
}
2020-07-07 16:09:48 +02:00
public IList < ServiceRecord > FindCustomerServiceRecordsForKilometerauswertung ( long customerOid , DateTimeSpan pSpan )
{
var lCriteria = CreateCriteria < ServiceRecord > ( )
. Add ( Restrictions . Eq ( nameof ( ServiceRecord . CustomerOid ) , customerOid ) )
2020-12-07 13:37:14 +01:00
. Add ( Restrictions . IsNotNull ( nameof ( ServiceRecord . DistanceInMeter ) ) )
2022-11-09 09:44:24 +01:00
. Add ( Restrictions . Gt ( nameof ( ServiceRecord . DistanceInMeter ) , 0 m ) ) ;
2020-07-07 16:09:48 +02:00
var orCriteria = Restrictions . Or (
Restrictions . Between ( nameof ( ServiceRecord . Start ) , pSpan . StartDateTime , pSpan . EndDateTime ) ,
Restrictions . Between ( nameof ( ServiceRecord . End ) , pSpan . StartDateTime , pSpan . EndDateTime ) ) ;
orCriteria = Restrictions . Or ( orCriteria ,
Restrictions . And (
Restrictions . Le ( nameof ( ServiceRecord . Start ) , pSpan . EndDateTime ) ,
Restrictions . Ge ( nameof ( ServiceRecord . End ) , pSpan . StartDateTime ) ) ) ;
lCriteria . Add ( orCriteria ) ;
return lCriteria . List < ServiceRecord > ( ) ;
}
2023-03-14 18:12:07 +01:00
public Dictionary < long , List < ServiceRecord > > FindListOfCustomerServiceRecordsForKilometerauswertung ( List < long > customerOids , List < long > serviceDescriptionOids , DateTimeSpan span )
2020-07-07 16:09:48 +02:00
{
var lCriteria = CreateCriteria < ServiceRecord > ( )
. Add ( Restrictions . In ( nameof ( ServiceRecord . CustomerOid ) , customerOids ) )
2020-12-07 13:37:14 +01:00
. Add ( Restrictions . IsNotNull ( nameof ( ServiceRecord . DistanceInMeter ) ) )
2022-11-09 09:44:24 +01:00
. Add ( Restrictions . Gt ( nameof ( ServiceRecord . DistanceInMeter ) , 0 m ) ) ;
2020-07-07 16:09:48 +02:00
var orCriteria = Restrictions . Or (
Restrictions . Between ( nameof ( ServiceRecord . Start ) , span . StartDateTime , span . EndDateTime ) ,
Restrictions . Between ( nameof ( ServiceRecord . End ) , span . StartDateTime , span . EndDateTime ) ) ;
orCriteria = Restrictions . Or ( orCriteria ,
Restrictions . And (
Restrictions . Le ( nameof ( ServiceRecord . Start ) , span . EndDateTime ) ,
Restrictions . Ge ( nameof ( ServiceRecord . End ) , span . StartDateTime ) ) ) ;
lCriteria . Add ( orCriteria ) ;
var allServiceRecords = lCriteria . List < ServiceRecord > ( ) . ToList ( ) ;
var result = new Dictionary < long , List < ServiceRecord > > ( ) ;
2023-03-14 18:12:07 +01:00
foreach ( var serviceRecord in allServiceRecords )
2020-07-07 16:09:48 +02:00
{
2023-03-24 13:07:59 +01:00
if ( serviceDescriptionOids = = null | | serviceDescriptionOids . Count = = 0 | | serviceDescriptionOids . Contains ( serviceRecord . ServiceDescription . Oid . Value ) )
2023-03-14 18:12:07 +01:00
{
result . AddOrUpdateValueInDictionary ( serviceRecord . CustomerOid . Value , new List < ServiceRecord > { serviceRecord } ) ;
}
2020-07-07 16:09:48 +02:00
}
return result ;
}
2020-07-08 16:51:11 +02:00
public bool CheckForAnyServiceRecordsWithDistanceValues ( List < long > customerOids , DateTimeSpan span )
{
2023-03-14 18:12:07 +01:00
return FindListOfCustomerServiceRecordsForKilometerauswertung ( customerOids , null , span ) . Any ( ) ;
2020-07-08 16:51:11 +02:00
}
2020-09-14 19:07:23 +02:00
public List < Customer > GetAllCustomersForEmployee ( long? employeeOid )
{
ApplicationUser user ;
if ( employeeOid . HasValue )
{
var employee = CreateCriteria < Employee > ( ) . Add ( Restrictions . Eq ( nameof ( Employee . Oid ) , employeeOid ) ) . UniqueResult < Employee > ( ) ;
user = FindUserForEmployee ( employee ) ;
}
else
{
if ( LoggedInUserOperationContextExt . Current ! = null & & LoggedInUserOperationContextExt . Current . User ! = null )
{
user = LoggedInUserOperationContextExt . Current . User ;
}
else
{
user = SessionFacade . LoggedInUser ;
}
}
var rights = new List < UserRightType > ( ) ;
user . UserGroups . DoForEach ( s = > s . Rights . DoForEach ( right = > rights . AddIfNotIn ( right . RightType ) ) ) ;
var lCriteria = CreateCriteriaIsActive < Customer > ( ) ;
if ( rights . Contains ( UserRightType . ViewAll ) | | rights . Contains ( UserRightType . CustomerView_View ) )
{
return lCriteria . List < Customer > ( ) . ToList ( ) ;
}
var result = new List < Customer > ( ) ;
if ( rights . Contains ( UserRightType . Customer_ViewMyCustomers ) )
{
result = user . Employee . Employee2CustomerList . Select ( employee2Customer = > employee2Customer . Customer ) . Distinct ( ) . ToList ( ) ;
}
if ( rights . Contains ( UserRightType . Customer_ViewMyTeams ) )
{
var teams = FindAllActiveTeamsOfEmployee ( user . Employee . Oid . Value ) ;
2021-04-19 04:43:31 +02:00
teams . DoForEach ( team = > { team . MemberList . DoForEach ( member = > result . AddRangeIfElementsNotIn ( member . Employee2CustomerList . Select ( employee2Customer = > employee2Customer . Customer ) ) ) ; } ) ;
2020-09-14 19:07:23 +02:00
}
return result ;
}
2020-09-23 16:00:51 +02:00
2021-02-17 16:59:26 +01:00
// TODO 16.02.2021: Alias für EmployeeOid erstellen?
2020-09-23 16:00:51 +02:00
public IList < ConfirmationReceiptSignature > GetConfirmationReceiptSignaturesByEmployee ( long employeeOid , DateTimeSpan timeSpan )
{
2020-09-30 19:23:42 +02:00
var liste = CreateCriteria < ConfirmationReceiptSignature > ( )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Eq ( nameof ( ConfirmationReceiptSignature . SignatureType ) , SignatureType . Employee ) )
. Add ( Restrictions . Eq ( nameof ( BeWoEntityBase . IsActive ) , ActivationTypeId . Active ) )
//.Add(Restrictions.Eq(nameof(ConfirmationReceiptSignature.EmployeeOid), employeeOid))
. CreateAlias ( nameof ( ConfirmationReceiptSignature . Employee ) , "e" , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( nameof ( BeWoEntityBase . Oid ) , employeeOid ) )
. CreateAlias ( nameof ( ConfirmationReceiptSignature . ServiceRecords ) , "s" , JoinType . InnerJoin )
. Add ( CreateBetweenDateTimesCriterion ( timeSpan . StartDateTime , timeSpan . EndDateTime , "s.Start" , "s.End" ) ) . List < ConfirmationReceiptSignature > ( ) ;
2020-09-23 16:00:51 +02:00
2020-09-30 19:23:42 +02:00
return liste ;
2020-09-23 16:00:51 +02:00
}
public List < ConfirmationReceiptSignature > GetConfirmationReceiptSignaturesByServiceRecord ( long serviceRecordOid )
{
2020-10-20 21:07:26 +02:00
var criteria = CreateCriteria < ConfirmationReceiptSignature > ( )
. CreateAlias ( nameof ( ConfirmationReceiptSignature . ServiceRecords ) , "serviceRecord" )
. Add ( Restrictions . Eq ( "serviceRecord.Oid" , serviceRecordOid ) ) ;
2020-09-23 16:00:51 +02:00
2020-10-20 21:07:26 +02:00
return criteria . List < ConfirmationReceiptSignature > ( ) . ToList ( ) ;
2020-09-23 16:00:51 +02:00
}
2020-09-30 19:23:42 +02:00
public IList < ServiceRecord > FindEmployeeServiceRecordsForKilometerauswertung ( long employeeOid , DateTimeSpan timeSpan )
{
var lCriteria = CreateCriteria < ServiceRecord > ( )
. Add ( Restrictions . Eq ( nameof ( ServiceRecord . EmployeeOid ) , employeeOid ) )
2020-12-07 13:37:14 +01:00
. Add ( Restrictions . IsNotNull ( nameof ( ServiceRecord . DistanceInMeter ) ) )
2022-11-09 09:44:24 +01:00
. Add ( Restrictions . Gt ( nameof ( ServiceRecord . DistanceInMeter ) , 0 m ) ) ;
2020-09-30 19:23:42 +02:00
var orCriteria = Restrictions . Or (
Restrictions . Between ( nameof ( ServiceRecord . Start ) , timeSpan . StartDateTime , timeSpan . EndDateTime ) ,
Restrictions . Between ( nameof ( ServiceRecord . End ) , timeSpan . StartDateTime , timeSpan . EndDateTime ) ) ;
orCriteria = Restrictions . Or ( orCriteria ,
Restrictions . And (
Restrictions . Le ( nameof ( ServiceRecord . Start ) , timeSpan . EndDateTime ) ,
Restrictions . Ge ( nameof ( ServiceRecord . End ) , timeSpan . StartDateTime ) ) ) ;
lCriteria . Add ( orCriteria ) ;
return lCriteria . List < ServiceRecord > ( ) ;
}
2023-03-14 18:12:07 +01:00
public Dictionary < long , List < ServiceRecord > > FindListOfEmployeeServiceRecordsForKilometerauswertung ( List < long > employeeOids , List < long > serviceDescriptionOids , DateTimeSpan span )
2020-09-30 19:23:42 +02:00
{
var lCriteria = CreateCriteria < ServiceRecord > ( )
. Add ( Restrictions . In ( nameof ( ServiceRecord . EmployeeOid ) , employeeOids ) )
2020-12-07 13:37:14 +01:00
. Add ( Restrictions . IsNotNull ( nameof ( ServiceRecord . DistanceInMeter ) ) )
2022-11-09 09:44:24 +01:00
. Add ( Restrictions . Gt ( nameof ( ServiceRecord . DistanceInMeter ) , 0 m ) ) ;
2020-09-30 19:23:42 +02:00
var orCriteria = Restrictions . Or (
Restrictions . Between ( nameof ( ServiceRecord . Start ) , span . StartDateTime , span . EndDateTime ) ,
Restrictions . Between ( nameof ( ServiceRecord . End ) , span . StartDateTime , span . EndDateTime ) ) ;
orCriteria = Restrictions . Or ( orCriteria ,
Restrictions . And (
Restrictions . Le ( nameof ( ServiceRecord . Start ) , span . EndDateTime ) ,
Restrictions . Ge ( nameof ( ServiceRecord . End ) , span . StartDateTime ) ) ) ;
lCriteria . Add ( orCriteria ) ;
2022-09-27 10:56:02 +02:00
2020-09-30 19:23:42 +02:00
var allServiceRecords = lCriteria . List < ServiceRecord > ( ) . ToList ( ) ;
var result = new Dictionary < long , List < ServiceRecord > > ( ) ;
foreach ( var serviceRecord in allServiceRecords )
{
2023-03-24 13:07:59 +01:00
if ( serviceDescriptionOids = = null | | serviceDescriptionOids . Count = = 0 | | serviceDescriptionOids . Contains ( serviceRecord . ServiceDescription . Oid . Value ) )
2023-03-14 18:12:07 +01:00
{
result . AddOrUpdateValueInDictionary ( serviceRecord . EmployeeOid . Value , new List < ServiceRecord > { serviceRecord } ) ;
}
2020-09-30 19:23:42 +02:00
}
return result ;
}
public IList < Employee > GetAllActiveEmployeesForEmployee ( long? employeeOid )
{
ApplicationUser user ;
if ( employeeOid . HasValue )
{
var employee = CreateCriteria < Employee > ( ) . Add ( Restrictions . Eq ( nameof ( Employee . Oid ) , employeeOid ) ) . UniqueResult < Employee > ( ) ;
user = FindUserForEmployee ( employee ) ;
}
else
{
if ( LoggedInUserOperationContextExt . Current ! = null & & LoggedInUserOperationContextExt . Current . User ! = null )
{
user = LoggedInUserOperationContextExt . Current . User ;
}
else
{
user = SessionFacade . LoggedInUser ;
}
}
if ( user . Employee . Oid = = null )
{
return new List < Employee > ( ) ;
}
var rights = new List < UserRightType > ( ) ;
user . UserGroups . DoForEach ( s = > s . Rights . DoForEach ( right = > rights . AddIfNotIn ( right . RightType ) ) ) ;
var lCriteria = CreateCriteriaIsActive < Employee > ( ) ;
2022-12-30 16:28:23 +01:00
if ( rights . Contains ( UserRightType . ViewAll ) | | rights . Contains ( UserRightType . EmployeeView_View ) )
2020-09-30 19:23:42 +02:00
{
return lCriteria . List < Employee > ( ) . ToList ( ) ;
}
var result = new List < Employee > ( ) ;
if ( rights . Contains ( UserRightType . Employee_AllowViewOwnEmployees ) )
{
result . AddIfNotIn ( user . Employee ) ;
}
if ( rights . Contains ( UserRightType . Employee_AllowViewOwnTeam ) )
{
var leadingTeams = user . Employee . LeadingTeams ;
leadingTeams . DoForEach ( team = >
{
result . AddIfNotIn ( team . Leader ) ;
result . AddRangeIfElementsNotIn ( team . MemberList ) ;
} ) ;
var teams = FindTeamsOfEmployee ( user . Employee . Oid . Value ) ;
teams . DoForEach ( team = >
{
result . AddIfNotIn ( team . Leader ) ;
result . AddRangeIfElementsNotIn ( team . MemberList ) ;
} ) ;
}
return result ;
}
2020-10-20 21:07:26 +02:00
2020-10-19 17:22:40 +02:00
public IList < Quittierungsbelegsstatus > GetAllQuittierungsbelegStatusForMonth ( DateTime start , DateTime ende )
{
DateTime begin = new DateTime ( start . Year , start . Month , start . Day ) ;
DateTime end = new DateTime ( ende . Year , ende . Month , ende . Day ) ;
var crit = CreateCriteria < Quittierungsbelegsstatus > ( ) ;
crit . Add ( Restrictions . Ge ( "Startdatum" , begin ) ) ;
crit . Add ( Restrictions . Le ( "Enddatum" , end ) ) ;
return crit . List < Quittierungsbelegsstatus > ( ) ;
}
2021-04-19 04:43:31 +02:00
2020-12-11 11:44:05 +01:00
public IList < Vorlagentabelle > GetAllActiveVorlagentabellen ( )
{
var crit = CreateCriteria < Vorlagentabelle > ( ) ;
crit . Add ( Restrictions . Gt ( "IsActive" , 0 ) ) ;
return crit . List < Vorlagentabelle > ( ) ;
}
public IList < Dokumentvorlage > GetAllDokumentvorlagenInFolder ( long folderOid )
{
var crit = CreateCriteria < Dokumentvorlage > ( ) ;
crit . Add ( Restrictions . Eq ( "Parent" , folderOid ) ) ;
2021-04-19 04:43:31 +02:00
2020-12-11 11:44:05 +01:00
return crit . List < Dokumentvorlage > ( ) ;
}
2020-11-09 17:55:01 +01:00
2021-02-17 16:59:26 +01:00
// TODO 16.02.2021: Alias für EmployeeOid erstellen?
2020-11-09 17:55:01 +01:00
public bool HasConfirmationReceiptSignaturesByEmployeeAndServiceRecords ( long employeeOid , IEnumerable < long > serviceRecordOids )
{
2021-04-19 04:43:31 +02:00
var criteria = CreateCriteria < ConfirmationReceiptSignature > ( )
. Add ( Restrictions . Eq ( nameof ( ConfirmationReceiptSignature . SignatureType ) , SignatureType . Employee ) )
//.Add(Restrictions.Eq(nameof(ConfirmationReceiptSignature.EmployeeOid), employeeOid))
. CreateAlias ( nameof ( ConfirmationReceiptSignature . Employee ) , "e" , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( nameof ( BeWoEntityBase . Oid ) , employeeOid ) )
. CreateAlias ( nameof ( ConfirmationReceiptSignature . ServiceRecords ) , "serviceRecord" )
. Add ( Restrictions . In ( "serviceRecord.Oid" , serviceRecordOids . ToList ( ) ) ) ;
2020-11-09 17:55:01 +01:00
var hasSignatures = criteria . List < ConfirmationReceiptSignature > ( ) . Any ( ) ;
return hasSignatures ;
}
2021-02-17 16:59:26 +01:00
public bool HasConfirmationReceiptSignatureByDateAndCustomer ( long customerOid , DateTimeSpan timeSpan , SignatureType signatureType )
2020-11-09 17:55:01 +01:00
{
var start = timeSpan . StartDate ;
var end = timeSpan . EndDate ;
var timeSpanCriterion = CreateBetweenDateTimesCriterion ( start , end , $"serviceRecord.{nameof(ServiceRecord.Start)}" , $"serviceRecord.{nameof(ServiceRecord.End)}" ) ;
var criteria = CreateCriteria < ConfirmationReceiptSignature > ( )
2021-02-17 16:59:26 +01:00
. Add ( Restrictions . Eq ( nameof ( ConfirmationReceiptSignature . SignatureType ) , signatureType ) )
2020-11-09 17:55:01 +01:00
. CreateAlias ( nameof ( ConfirmationReceiptSignature . ServiceRecords ) , "serviceRecord" )
. Add ( Restrictions . Eq ( $"serviceRecord.{nameof(ServiceRecord.CustomerOid)}" , customerOid ) )
. Add ( timeSpanCriterion ) ;
return criteria . List < ConfirmationReceiptSignature > ( ) . Any ( ) ;
}
public IList < Team > GetAllActiveTeamsForEmployee ( long? employeeOid )
{
ApplicationUser user ;
var result = new List < Team > ( ) ;
if ( employeeOid . HasValue )
{
var employee = CreateCriteria < Employee > ( ) . Add ( Restrictions . Eq ( nameof ( Employee . Oid ) , employeeOid ) ) . UniqueResult < Employee > ( ) ;
user = FindUserForEmployee ( employee ) ;
}
else
{
if ( LoggedInUserOperationContextExt . Current ! = null & & LoggedInUserOperationContextExt . Current . User ! = null )
{
user = LoggedInUserOperationContextExt . Current . User ;
}
else
{
user = SessionFacade . LoggedInUser ;
}
}
if ( user . Employee . Oid = = null )
{
return result ;
}
var rights = new List < UserRightType > ( ) ;
user . UserGroups . DoForEach ( s = > s . Rights . DoForEach ( right = > rights . AddIfNotIn ( right . RightType ) ) ) ;
2021-04-19 04:43:31 +02:00
2020-11-09 17:55:01 +01:00
if ( rights . Contains ( UserRightType . ViewAll ) | | rights . Contains ( UserRightType . TeamView_ViewAll ) )
{
return CreateCriteriaIsActive < Team > ( ) . List < Team > ( ) ;
}
if ( rights . Contains ( UserRightType . TeamView_ViewMyTeams ) )
{
result . AddRangeIfElementsNotIn ( FindLeadingTeams ( user . Employee . Oid . Value ) ) ;
result . AddRangeIfElementsNotIn ( FindTeamsOfEmployee ( user . Employee . Oid . Value ) ) ;
return result ;
}
return result ;
}
2021-02-17 16:59:26 +01:00
// TODO 16.02.2021: Alias für EmployeeOid erstellen?
2020-11-09 17:55:01 +01:00
public IEnumerable < ConfirmationReceiptSignature > FindConfirmationReceiptSignaturesByEmployeeAndServiceRecords ( long employeeOid , IEnumerable < long > serviceRecordOids )
{
var criteria = CreateCriteria < ConfirmationReceiptSignature > ( )
2021-02-17 16:59:26 +01:00
. Add ( Restrictions . Eq ( nameof ( ConfirmationReceiptSignature . SignatureType ) , SignatureType . Employee ) )
//.Add(Restrictions.Eq(nameof(ConfirmationReceiptSignature.EmployeeOid), employeeOid))
. CreateAlias ( nameof ( ConfirmationReceiptSignature . Employee ) , "e" , JoinType . InnerJoin )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . Eq ( nameof ( BeWoEntityBase . Oid ) , employeeOid ) )
2020-11-09 17:55:01 +01:00
. CreateAlias ( nameof ( ConfirmationReceiptSignature . ServiceRecords ) , "serviceRecord" )
2021-04-19 04:43:31 +02:00
. Add ( Restrictions . In ( "serviceRecord.Oid" , serviceRecordOids . ToList ( ) ) ) ;
2020-11-09 17:55:01 +01:00
return criteria . List < ConfirmationReceiptSignature > ( ) ;
}
2020-12-01 12:29:12 +01:00
//public SchedulerAppointment FindRootAppointmentByRecurrenceId(string recurrenceId)
//{
// if(Guid.TryParse(recurrenceId, out var guid))
// {
// var criteria = CreateCriteria<SchedulerAppointment>()
// .Add(Restrictions.Like(nameof(SchedulerAppointment.RecurrenceInfo), recurrenceId, MatchMode.Anywhere))
// .Add(Restrictions.Eq(nameof(Appointment.Type), 1));
// return criteria.List<SchedulerAppointment>().FirstOrDefault();
// }
// return null;
//}
public SchedulerAppointment FindIndexZeroChangedOccurrence ( Guid ? recurrenceId )
{
if ( recurrenceId = = null )
{
return null ;
}
var kek = recurrenceId . ToString ( ) ;
var str = $"<RecurrenceInfo Id=\" { kek } \ " />" ;
var criteria = CreateCriteria < SchedulerAppointment > ( )
. Add ( Restrictions . Like ( nameof ( SchedulerAppointment . RecurrenceInfo ) , str , MatchMode . Exact ) )
. Add ( Restrictions . Not ( Restrictions . Like ( nameof ( SchedulerAppointment . RecurrenceInfo ) , "Index=\"" , MatchMode . Anywhere ) ) )
. Add ( Restrictions . Eq ( nameof ( Appointment . Type ) , 3 ) ) ;
return criteria . List < SchedulerAppointment > ( ) . FirstOrDefault ( ) ;
}
2020-12-02 21:46:58 +01:00
public string ValidateSchedulerAppointment ( DateTime start , DateTime end , IEnumerable < long > employees , IEnumerable < long > customers , List < long > resources , long originator , long? appointmentOid , Guid ? recurrenceId = null , int occurrenceIndex = 0 , bool shouldSkipResourceAvailability = false )
2020-12-01 12:29:12 +01:00
{
2020-12-02 21:46:58 +01:00
var isOverlapping = OverlappingAppointmentsExist ( start , end , employees , customers , resources , originator , appointmentOid , recurrenceId ? . ToString ( ) ? ? "" , occurrenceIndex ) ;
2020-12-01 12:29:12 +01:00
2023-01-12 19:47:14 +01:00
var unavailableResources = shouldSkipResourceAvailability ? new List < Resource > ( ) : CheckAvailabilityOfResources ( resources . ToList ( ) , start , end , appointmentOid , recurrenceId , occurrenceIndex ) ;
2020-12-01 12:29:12 +01:00
var stringBuilder = new StringBuilder ( ) ;
2021-04-19 04:43:31 +02:00
2020-12-01 12:29:12 +01:00
if ( unavailableResources . Any ( ) )
{
var names = string . Empty ;
unavailableResources . DoForEach ( resource = > names + = resource . Name + ", " ) ;
names = names . TrimEnd ( ' ' ) . TrimEnd ( ',' ) ;
var resourceCount = resources . Count ( ) ;
var suffix = ( resourceCount > 1 ? "n" : string . Empty ) ;
2021-04-19 04:43:31 +02:00
var ressourceWarningMessage = resourceCount > 1 ? $"Ein{(resourceCount > 1 ? " ige " : " e ")} der ausgewählten Ressourcen ({names}) sind" : $"{(resourceCount > 1 ? " Eine der " : " Die ")} ausgewählte{suffix} Ressource{suffix} ({names}) ist" ;
2020-12-01 12:29:12 +01:00
2020-12-02 21:46:58 +01:00
ressourceWarningMessage + = $" zum gewählten Zeitpunkt ({start.GetDateString(end)}) nicht verfügbar." ;
2020-12-01 12:29:12 +01:00
stringBuilder . Append ( ressourceWarningMessage ) ;
}
2020-12-02 21:46:58 +01:00
if ( isOverlapping )
{
if ( unavailableResources . Any ( ) )
{
stringBuilder . Append ( "\n\n" ) ;
}
stringBuilder . Append ( "Dieser Termin überschneidet sich mit einem anderen bereits existierenden Termin." ) ;
}
if ( unavailableResources . Any ( ) | | isOverlapping )
{
stringBuilder . Append ( "\n\nMöchten Sie trotzdem speichern?" ) ;
}
2020-12-01 12:29:12 +01:00
return stringBuilder . ToString ( ) ;
}
2020-12-16 21:49:47 +01:00
2021-01-13 11:21:51 +01:00
public virtual IList FindFileattachmentOids ( string text )
{
var q = Session . CreateSQLQuery ( Format ( "SELECT Oid, bewofolderoid, objectoid, objecttid, path FROM FileAttachment WHERE Path like '%{0}%'" , text ) ) ;
return q . List ( ) ;
}
2021-04-19 04:43:31 +02:00
2020-12-16 21:49:47 +01:00
public List < SupportConcept > GetActiveSupportConceptsForEmployee ( long? employeeOid , CustomerFilterEnum supportConceptFilter )
{
ApplicationUser user ;
if ( employeeOid . HasValue )
{
var employee = CreateCriteria < Employee > ( ) . Add ( Restrictions . Eq ( nameof ( Employee . Oid ) , employeeOid ) ) . UniqueResult < Employee > ( ) ;
user = FindUserForEmployee ( employee ) ;
}
else
{
if ( LoggedInUserOperationContextExt . Current ! = null & & LoggedInUserOperationContextExt . Current . User ! = null )
{
user = LoggedInUserOperationContextExt . Current . User ;
}
else
{
user = SessionFacade . LoggedInUser ;
}
}
var lCriteria = CreateCriteriaIsActive < SupportConcept > ( ) ;
var teamCustomerOids = new List < long > ( ) ;
var teams = FindAllActiveTeamsOfEmployee ( user . Employee . Oid . Value ) ;
teams . DoForEach ( team = >
{
2021-03-30 10:58:50 +02:00
var customer = FindCustomerOfTeam ( team . Oid . Value ) ;
teamCustomerOids . AddRangeIfElementsNotIn ( customer . Select ( c = > c . Oid . Value ) ) ;
2020-12-16 21:49:47 +01:00
} ) ;
// Der ApplicationUser darf alles Sehen oder alle Hilfepläne
if ( user . CheckForAtLeastOneRight ( new List < UserRightType > { UserRightType . ViewAll , UserRightType . SupportConcept_ViewAllSupportConcepts } ) & & supportConceptFilter = = CustomerFilterEnum . All )
{
return lCriteria . List < SupportConcept > ( ) . ToList ( ) ;
}
2021-04-12 20:32:10 +02:00
var customerOids = user . Employee . Employee2CustomerList . Where ( employee2Customer = > employee2Customer . Customer . Oid . HasValue ) . Select ( employee2Customer = > employee2Customer . Customer . Oid . Value ) . Distinct ( ) . ToList ( ) ;
2020-12-16 21:49:47 +01:00
// Der ApplicationUser darf die Hilfepläne seiner Teams sehen
2021-04-19 04:43:31 +02:00
if ( user . CheckForRight ( UserRightType . SupportConcept_ViewMyTeams ) & & ( supportConceptFilter = = CustomerFilterEnum . TeamCustomer | | supportConceptFilter = = CustomerFilterEnum . All ) )
2020-12-16 21:49:47 +01:00
{
2021-04-19 04:43:31 +02:00
foreach ( var coid in customerOids )
2021-03-30 10:58:50 +02:00
{
2021-04-19 04:43:31 +02:00
if ( ! teamCustomerOids . Contains ( coid ) )
2021-03-30 10:58:50 +02:00
{
teamCustomerOids . Add ( coid ) ;
}
}
2021-04-19 04:43:31 +02:00
2020-12-16 21:49:47 +01:00
return GetAllActiveSupportConceptsByCustomers ( teamCustomerOids , true ) . ToList ( ) ;
}
return GetAllActiveSupportConceptsByCustomers ( customerOids , true ) . ToList ( ) ;
}
2021-01-14 16:30:28 +01:00
public IEnumerable < SchedulerAppointment > GetAllMobileTestAppointments ( )
{
var c = CreateCriteria < SchedulerAppointment > ( )
. Add ( Restrictions . Eq ( nameof ( SchedulerAppointment . Notice ) , "mob-dev-app" ) ) ;
return c . List < SchedulerAppointment > ( ) ;
}
2021-02-17 16:59:26 +01:00
public bool HasConfirmationReceiptSignature ( IList < long > serviceRecordOids , SignatureType signatureType )
2021-01-14 16:30:28 +01:00
{
2021-02-17 16:59:26 +01:00
// Prüfen, ob alle ServiceRecords mit ein und derselben Mitarbeiterunterschrift verknüpft sind.
// Eine Unterschrift kann mehrere ServiceRecords in der LinkListe haben, die nicht in der zu prüfenden Oid-Liste sind.
var c = CreateCriteriaIsActive < ConfirmationReceiptSignature > ( )
. Add ( Restrictions . Eq ( nameof ( ConfirmationReceiptSignature . SignatureType ) , signatureType ) )
. CreateAlias ( nameof ( ConfirmationReceiptSignature . ServiceRecords ) , "sr" , JoinType . InnerJoin )
. Add ( Restrictions . In ( $"sr.{nameof(BeWoEntityBase.Oid)}" , serviceRecordOids . ToArray ( ) ) ) ;
2021-01-14 16:30:28 +01:00
2021-02-17 16:59:26 +01:00
var signatures = c . List < ConfirmationReceiptSignature > ( ) . ToList ( ) ;
2021-01-14 16:30:28 +01:00
2021-02-17 16:59:26 +01:00
var result = false ;
2021-01-14 16:30:28 +01:00
2021-02-17 16:59:26 +01:00
if ( serviceRecordOids . Any ( ) & & signatures . Any ( ) )
2021-01-14 16:30:28 +01:00
{
2021-02-17 16:59:26 +01:00
var blubb = new List < long > ( ) ;
2021-04-19 04:43:31 +02:00
signatures . DoForEach ( s = >
{
2021-02-17 16:59:26 +01:00
s . ServiceRecords . DoForEach ( sr = >
{
if ( sr . Oid . HasValue )
{
blubb . AddIfNotIn ( sr . Oid . Value ) ;
}
} ) ;
} ) ;
2021-01-14 16:30:28 +01:00
2021-02-17 16:59:26 +01:00
result = serviceRecordOids . ContainsSameItemsAs ( blubb ) ;
2021-01-14 16:30:28 +01:00
}
2021-02-17 16:59:26 +01:00
return result ;
}
2021-01-14 16:30:28 +01:00
2021-02-17 16:59:26 +01:00
// Methode, die herausfindet, ob eine Liste mit ServiceRecordOids zu genau einer Mitarbeiterunterschrift gehört
public ConfirmationReceiptSignature GetConfirmationReceiptSignatureForServiceRecords ( List < long > serviceRecordOids , SignatureType signatureType )
{
var c = CreateCriteriaIsActive < ConfirmationReceiptSignature > ( )
. Add ( Restrictions . Eq ( nameof ( ConfirmationReceiptSignature . SignatureType ) , signatureType ) )
2022-10-11 16:48:36 +02:00
. AddOrder ( Order . Desc ( nameof ( ConfirmationReceiptSignature . Oid ) ) )
2021-02-17 16:59:26 +01:00
. CreateAlias ( nameof ( ConfirmationReceiptSignature . ServiceRecords ) , "sr" , JoinType . InnerJoin )
. Add ( Restrictions . In ( $"sr.{nameof(BeWoEntityBase.Oid)}" , serviceRecordOids . ToArray ( ) ) ) ;
2021-01-14 16:30:28 +01:00
2021-02-17 16:59:26 +01:00
var signatures = c . List < ConfirmationReceiptSignature > ( ) . ToList ( ) ;
2021-01-14 16:30:28 +01:00
2021-02-17 16:59:26 +01:00
var relatedServiceRecordOids = new List < long > ( ) ;
signatures . DoForEach ( s = > relatedServiceRecordOids . AddRangeIfElementsNotIn ( s . ServiceRecords . Select ( x = > x . Oid . Value ) ) ) ;
var containsItems = relatedServiceRecordOids . ContainsItems ( serviceRecordOids ) ;
return containsItems ? signatures . FirstOrDefault ( ) : null ;
}
public List < ConfirmationReceiptSignature > LoadConfirmationReceiptSignaturesByServiceRecordOids ( IList < long > serviceRecordOids , SignatureType signatureType )
{
var c = CreateCriteriaIsActive < ConfirmationReceiptSignature > ( )
. Add ( Restrictions . Eq ( nameof ( ConfirmationReceiptSignature . SignatureType ) , signatureType ) )
. CreateAlias ( nameof ( ConfirmationReceiptSignature . ServiceRecords ) , "sr" , JoinType . InnerJoin )
. Add ( Restrictions . In ( $"sr.{nameof(BeWoEntityBase.Oid)}" , serviceRecordOids . ToArray ( ) ) ) ;
// Der ResultTransformer erzeugt ein SELECT DISTINCT für den Roottypen (ConfirmationReceiptSignature)
c . SetResultTransformer ( new DistinctRootEntityResultTransformer ( ) ) ;
2021-01-14 16:30:28 +01:00
2021-02-17 16:59:26 +01:00
var result = c . List < ConfirmationReceiptSignature > ( ) . ToList ( ) ;
return result ;
}
public bool HasConfirmationReceiptSignaturesByCustomerAndServiceRecords ( long customerOid , IEnumerable < long > serviceRecordOids )
{
var criteria = CreateCriteria < ConfirmationReceiptSignature > ( )
. Add ( Restrictions . Eq ( nameof ( ConfirmationReceiptSignature . SignatureType ) , SignatureType . Customer ) )
. Add ( Restrictions . Eq ( nameof ( ConfirmationReceiptSignature . CustomerOid ) , customerOid ) )
. CreateAlias ( nameof ( ConfirmationReceiptSignature . ServiceRecords ) , "serviceRecord" )
. Add ( Restrictions . In ( "serviceRecord.Oid" , serviceRecordOids . ToList ( ) ) ) ;
var hasSignatures = criteria . List < ConfirmationReceiptSignature > ( ) . Any ( ) ;
return hasSignatures ;
}
public List < ConfirmationReceiptSignature > LoadConfirmationReceiptSignaturesByServiceRecordOids ( IList < long > serviceRecordOids )
{
var c = CreateCriteriaIsActive < ConfirmationReceiptSignature > ( )
. CreateAlias ( nameof ( ConfirmationReceiptSignature . ServiceRecords ) , "sr" , JoinType . InnerJoin )
. Add ( Restrictions . In ( $"sr.{nameof(BeWoEntityBase.Oid)}" , serviceRecordOids . ToArray ( ) ) ) ;
// Der ResultTransformer erzeugt ein SELECT DISTINCT für den Roottypen (ConfirmationReceiptSignature)
c . SetResultTransformer ( new DistinctRootEntityResultTransformer ( ) ) ;
var result = c . List < ConfirmationReceiptSignature > ( ) . ToList ( ) ;
return result ;
}
public List < long > LoadServiceRecordOidsWithConfirmationReceiptSignatures ( IList < long > serviceRecordOids )
{
var c = CreateCriteriaIsActive < ConfirmationReceiptSignature > ( )
. CreateAlias ( nameof ( ConfirmationReceiptSignature . ServiceRecords ) , "sr" , JoinType . InnerJoin )
. Add ( Restrictions . In ( $"sr.{nameof(BeWoEntityBase.Oid)}" , serviceRecordOids . ToArray ( ) ) ) ;
// Der ResultTransformer erzeugt ein SELECT DISTINCT für den Roottypen (ConfirmationReceiptSignature)
c . SetResultTransformer ( new DistinctRootEntityResultTransformer ( ) ) ;
var confirmationReceiptSignatures = c . List < ConfirmationReceiptSignature > ( ) . ToList ( ) ;
var result = new List < long > ( ) ;
confirmationReceiptSignatures . DoForEach ( crs = > crs . ServiceRecords . DoForEach ( sr = >
{
if ( sr . Oid . HasValue )
2021-01-14 16:30:28 +01:00
{
2021-02-17 16:59:26 +01:00
result . AddIfNotIn ( sr . Oid . Value ) ;
2021-01-14 16:30:28 +01:00
}
2021-02-17 16:59:26 +01:00
} ) ) ;
2021-01-14 16:30:28 +01:00
2021-02-17 16:59:26 +01:00
return result ;
}
2021-01-14 16:30:28 +01:00
2021-02-17 16:59:26 +01:00
public List < long > LoadServiceRecordOidsWithConfirmationReceiptSignatures ( IList < long > serviceRecordOids , SignatureType signatureType )
{
var c = CreateCriteriaIsActive < ConfirmationReceiptSignature > ( )
. Add ( Restrictions . Eq ( nameof ( ConfirmationReceiptSignature . SignatureType ) , signatureType ) )
. CreateAlias ( nameof ( ConfirmationReceiptSignature . ServiceRecords ) , "sr" , JoinType . InnerJoin )
. Add ( Restrictions . In ( $"sr.{nameof(BeWoEntityBase.Oid)}" , serviceRecordOids . ToArray ( ) ) ) ;
2021-01-14 16:30:28 +01:00
2021-02-17 16:59:26 +01:00
// Der ResultTransformer erzeugt ein SELECT DISTINCT für den Roottypen (ConfirmationReceiptSignature)
c . SetResultTransformer ( new DistinctRootEntityResultTransformer ( ) ) ;
var confirmationReceiptSignatures = c . List < ConfirmationReceiptSignature > ( ) . ToList ( ) ;
2021-01-14 16:30:28 +01:00
2021-02-17 16:59:26 +01:00
var result = new List < long > ( ) ;
confirmationReceiptSignatures . DoForEach ( crs = > crs . ServiceRecords . DoForEach ( sr = >
{
if ( sr . Oid . HasValue )
{
result . AddIfNotIn ( sr . Oid . Value ) ;
}
} ) ) ;
return result ;
}
public IEnumerable < ServiceRecord > GetServiceRecordsWithoutConfirmationReceiptSignature ( IList < long > serviceRecordOids , SignatureType signatureType )
{
2021-01-14 16:30:28 +01:00
var c = CreateCriteriaIsActive < ConfirmationReceiptSignature > ( )
2021-02-17 16:59:26 +01:00
. Add ( Restrictions . Eq ( nameof ( ConfirmationReceiptSignature . SignatureType ) , signatureType ) )
2021-01-14 16:30:28 +01:00
. CreateAlias ( nameof ( ConfirmationReceiptSignature . ServiceRecords ) , "sr" , JoinType . InnerJoin )
2021-02-17 16:59:26 +01:00
. Add ( Restrictions . In ( $"sr.{nameof(BeWoEntityBase.Oid)}" , serviceRecordOids . ToArray ( ) ) )
. SetResultTransformer ( new DistinctRootEntityResultTransformer ( ) ) ;
2021-01-14 16:30:28 +01:00
2021-02-17 16:59:26 +01:00
var confirmationReceiptSignatures = c . List < ConfirmationReceiptSignature > ( ) . ToList ( ) ;
2021-01-14 16:30:28 +01:00
2021-02-17 16:59:26 +01:00
var serviceRecords = new List < ServiceRecord > ( ) ;
2021-01-14 16:30:28 +01:00
2021-02-17 16:59:26 +01:00
confirmationReceiptSignatures . DoForEach ( crs = > serviceRecords . AddRangeIfElementsNotIn ( crs . ServiceRecords ) ) ;
2021-01-14 16:30:28 +01:00
2021-02-17 16:59:26 +01:00
return serviceRecords ;
2021-01-14 16:30:28 +01:00
}
2021-02-21 19:01:51 +01:00
public InvoiceBase FindMaxInvoiceNumber ( string numberPrefix )
{
return CreateCriteriaIsActive < InvoiceBase > ( )
. Add ( Restrictions . Like ( InvoiceBase . PropertyName_InvoiceNumber , numberPrefix + "%" ) )
. List < InvoiceBase > ( ) . OrderByDescending ( i = > i . InvoiceNumber ) . FirstOrDefault ( ) ;
}
2021-04-19 04:38:29 +02:00
2022-10-11 16:48:36 +02:00
public List < Customer > GetActiveCustomersForEmployee ( long? employeeOid , CustomerFilterEnum customerFilter , bool ignoreViewAllRight = false )
2021-04-19 04:38:29 +02:00
{
ApplicationUser user ;
if ( employeeOid . HasValue )
{
var employee = CreateCriteria < Employee > ( ) . Add ( Restrictions . Eq ( nameof ( Employee . Oid ) , employeeOid ) ) . UniqueResult < Employee > ( ) ;
user = FindUserForEmployee ( employee ) ;
}
else
{
user = LoggedInUserOperationContextExt . Current ? . User ! = null ? LoggedInUserOperationContextExt . Current . User : SessionFacade . LoggedInUser ;
}
var lCriteria = CreateCriteriaIsActive < Customer > ( ) ;
2021-04-22 00:56:10 +02:00
2021-04-19 04:38:29 +02:00
// Der ApplicationUser darf alles sehen
2022-10-11 16:48:36 +02:00
var viewAllRights = new List < UserRightType > { UserRightType . CustomerView_View } ;
if ( ! ignoreViewAllRight )
{
viewAllRights . Add ( UserRightType . ViewAll ) ;
}
if ( user . CheckForAtLeastOneRight ( viewAllRights ) & & customerFilter = = CustomerFilterEnum . All )
2021-04-19 04:38:29 +02:00
{
return lCriteria . List < Customer > ( ) . ToList ( ) ;
}
var customerOids = user . Employee . Employee2CustomerList . Where ( employee2Customer = > employee2Customer . Customer . Oid . HasValue ) . Select ( employee2Customer = > employee2Customer . Customer . Oid . Value ) . Distinct ( ) . ToList ( ) ;
// Der ApplicationUser darf die Klienten seiner Teams sehen
2022-10-11 16:48:36 +02:00
if ( user . CheckForRight ( UserRightType . Customer_ViewMyTeams ) & & ( customerFilter = = CustomerFilterEnum . TeamCustomer | | customerFilter = = CustomerFilterEnum . All ) & & ( user . Employee ? . Oid . HasValue ? ? false ) )
2021-04-19 04:38:29 +02:00
{
2021-04-22 00:56:10 +02:00
var teamCustomerOids = new List < long > ( ) ;
var teams = FindAllActiveTeamsOfEmployee ( user . Employee . Oid . Value ) ;
teams . DoForEach ( team = >
2021-04-19 04:38:29 +02:00
{
2022-10-11 16:48:36 +02:00
if ( team . Oid is null )
{
return ;
}
2021-04-22 00:56:10 +02:00
var customer = FindCustomerOfTeam ( team . Oid . Value ) ;
2022-10-11 16:48:36 +02:00
teamCustomerOids . AddRangeIfElementsNotIn ( customer . Where ( w = > w . Oid . HasValue ) . Select ( c = > c . Oid . Value ) ) ;
2021-04-22 00:56:10 +02:00
} ) ;
//foreach (var customerOid in customerOids.Where(customerOid => !teamCustomerOids.Contains(customerOid)))
//{
// teamCustomerOids.Add(customerOid);
//}
2021-04-19 04:38:29 +02:00
return lCriteria . Add ( Restrictions . In ( nameof ( Customer . Oid ) , teamCustomerOids . ToArray ( ) ) ) . List < Customer > ( ) . ToList ( ) ;
}
// Der ApplicationUser darf nur seine eigenen Klienten sehen
return lCriteria . Add ( Restrictions . In ( nameof ( Customer . Oid ) , customerOids . ToArray ( ) ) ) . List < Customer > ( ) . ToList ( ) ;
}
2021-04-19 04:43:31 +02:00
2021-04-19 01:15:53 +02:00
public IList < long > FindFamilyMemberOids ( )
{
2022-01-25 10:43:43 +01:00
var q = Session . CreateSQLQuery ( "SELECT personoid FROM customer2person where istfamilie = 1" ) ;
2021-04-19 01:15:53 +02:00
return q . List < long > ( ) ;
}
2021-04-29 15:11:56 +02:00
public List < SchedulerAppointment > FindActiveAppointmentsForCustomers ( List < long > customerOids , DateTime startDate , DateTime endDate )
{
var customerOidSqlString = string . Empty ;
customerOids . DoForEach ( oid = > customerOidSqlString + = $"{oid}," ) ;
customerOidSqlString = customerOidSqlString . Trim ( ',' ) ;
var sqlQuery = $" {nameof(BeWoEntityBase.Oid)} IN (SELECT newschappoid FROM customer2newschapp WHERE customeroid IN ({customerOidSqlString})) " ;
var customerCriterion = Expression . Sql ( sqlQuery ) ;
var between = CreateBetweenDateTimesCriterion ( startDate , endDate , nameof ( SchedulerAppointment . StartDate ) , nameof ( SchedulerAppointment . EndDate ) ) ;
var criteria = CreateCriteriaIsActive < SchedulerAppointment > ( )
. Add ( customerCriterion )
. Add ( between )
. Add ( Restrictions . Eq ( nameof ( SchedulerAppointment . IsTask ) , false ) ) ;
return criteria . List < SchedulerAppointment > ( ) . ToList ( ) ;
}
2021-04-29 16:11:53 +02:00
2021-05-05 18:35:46 +02:00
public List < SchedulerAppointment > LoadFilteredAllActiveAppointments ( long employeeOid , DateTime start , DateTime end , List < long > customerOids )
{
var appointments = LoadFilteredAppointments (
true ,
employeeOid ,
start , end ,
new List < long > ( ) ,
customerOids ,
new List < long > ( ) ,
false ,
true ,
false ,
false ,
false ,
false ) ;
return appointments . ToList ( ) ;
2021-04-29 16:11:53 +02:00
}
2021-05-17 14:01:06 +02:00
public List < ServiceRecord > FindServiceRecordsForFlsAuslastungsauswertungByCustomerAndEmployees ( long? customerOid , List < long > employeeOids , DateTime start , DateTime end , bool onlyBillableCategories )
{
var c = CreateCriteriaIsActive < ServiceRecord > ( ) . Add ( Restrictions . Eq ( nameof ( ServiceRecord . CustomerOid ) , customerOid ) ) ;
c . Add ( Restrictions . In ( nameof ( ServiceRecord . EmployeeOid ) , employeeOids ) ) ;
var betweenCriterion = CreateBetweenDateTimesCriterion ( start , end , nameof ( ServiceRecord . Start ) , nameof ( ServiceRecord . End ) ) ;
c . Add ( betweenCriterion ) ;
if ( onlyBillableCategories )
{
c . CreateAlias ( ServiceRecord . PropertyName_ServiceDescription , "sd" , JoinType . InnerJoin )
. CreateAlias ( "sd." + ServiceDescription . PropertyName_ServiceCategory , "sc" , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( "sc." + ServiceCategory . PropertyName_IsBillable , true ) ) ;
}
return c . List < ServiceRecord > ( ) . ToList ( ) ;
}
2021-06-10 14:40:23 +02:00
public IList < GeschenkterUrlaubstag > FindGeschenkteUrlaubstageByEmpOid ( long empOid )
{
var criteria = CreateCriteriaIsActive < GeschenkterUrlaubstag > ( )
. Add ( Restrictions . Eq ( "Employee" , empOid ) ) ;
return criteria . List < GeschenkterUrlaubstag > ( ) ;
}
public IList < GeschenkterUrlaubstag > FindGeschenkteUrlaubstageByYear ( int year )
{
DateTime start = new DateTime ( year , 1 , 1 ) . AddTicks ( - 1 ) ;
DateTime end = new DateTime ( year , 12 , 31 ) . AddDays ( 1 ) . AddTicks ( - 1 ) ;
var criteria = CreateCriteriaIsActive < GeschenkterUrlaubstag > ( )
. Add ( Restrictions . Between ( "Date" , start , end ) ) ;
return criteria . List < GeschenkterUrlaubstag > ( ) ;
}
2021-06-29 15:13:20 +02:00
public List < ServiceRecord > GetActiveServiceRecordsBySupportConceptWithServiceCategoryForCustomer ( List < long > customerOids , long serviceCategoryOid , int month , int year )
{
var c = CreateCriteriaIsActive < SupportConcept > ( )
. Add ( Restrictions . In ( nameof ( SupportConcept . Customer ) + ".Oid" , customerOids . ToArray ( ) ) )
. CreateAlias ( SupportConcept . PropertyName_ServiceAccountings , "sa" , JoinType . InnerJoin )
. CreateAlias ( "sa." + nameof ( ServiceAccounting . ServiceDescription ) , "sd" , JoinType . InnerJoin )
. CreateAlias ( "sd." + ServiceDescription . PropertyName_ServiceCategory , "cat" , JoinType . InnerJoin )
. Add ( Restrictions . Eq ( "cat.Oid" , serviceCategoryOid ) ) ;
var c2 = CreateCriteriaIsActive < SupportConcept > ( )
. Add ( Restrictions . In ( nameof ( SupportConcept . Customer ) + ".Oid" , customerOids . ToArray ( ) ) )
. Add ( Restrictions . IsEmpty ( nameof ( SupportConcept . ServiceAccountings ) ) ) ;
var supportConcepts = c . List < SupportConcept > ( ) . ToList ( ) ;
supportConcepts . AddRangeIfElementsNotIn ( c2 . List < SupportConcept > ( ) ) ;
var start = new DateTime ( year , month , 1 , 0 , 0 , 0 ) ;
var end = start . AddMonths ( 1 ) . AddSeconds ( - 1 ) ;
var criteria = CreateCriteriaIsActive < ServiceRecord > ( )
. Add ( Restrictions . In ( nameof ( ServiceRecord . CustomerOid ) , customerOids . ToArray ( ) ) )
. Add ( CreateBetweenDateTimesCriterion ( start , end , "Start" , "End" ) )
. Add ( Restrictions . In ( nameof ( ServiceRecord . SupportConcept ) + ".Oid" , supportConcepts . Select ( sc = > sc . Oid ) . ToArray ( ) ) ) ;
return criteria . List < ServiceRecord > ( ) . ToList ( ) ;
}
2021-08-19 17:22:04 +02:00
public List < Customer > GetCustomersForEmployeeWithServiceRecordsInInterval ( DateTime start , DateTime end , long employeeOid )
{
var result = new List < Customer > ( ) ;
// Customers aus Zeitraum, die ServiceRecords haben, wo der Employee dabei ist.
var serviceRecords = FindEmployeeServiceRecords ( employeeOid , new DateTimeSpan ( start , end ) , null , null ) ;
serviceRecords . DoForEach ( sr = >
{
if ( sr ? . Customer ! = null )
{
result . AddIfNotIn ( sr . Customer ) ;
}
} ) ;
return result ;
}
public List < Customer > GetCustomersForTeamWithServiceRecordsInInterval ( DateTime start , DateTime end , List < long > employeeOids )
{
var result = new List < Customer > ( ) ;
var serviceRecords = FindEmployeeServiceRecords ( employeeOids , new DateTimeSpan ( start , end ) ) ;
serviceRecords . DoForEach ( sr = >
{
if ( sr ? . Customer ! = null )
{
result . AddIfNotIn ( sr . Customer ) ;
}
} ) ;
return result ;
}
public IList < ServiceRecord > FindEmployeeServiceRecords ( List < long > employeeOids , DateTimeSpan span )
{
var lCriteria = CreateCriteria < ServiceRecord > ( )
. Add ( Restrictions . In ( nameof ( ServiceRecord . EmployeeOid ) , employeeOids ) ) ;
if ( span ! = null )
{
lCriteria . Add ( Restrictions . Between ( ServiceRecord . PropertyName_Start , span . StartDateTime , span . EndDateTime ) ) ;
}
var result = lCriteria . List < ServiceRecord > ( ) . ToList ( ) ;
return result ;
}
2021-10-12 16:00:17 +02:00
public IList < DienstInfo > FindDiensteForWohnheim ( long? whOid )
{
var criteria = CreateCriteriaIsActive < DienstInfo > ( )
. Add ( Restrictions . Or ( Restrictions . Eq ( "Wohnheim" , whOid ) , Restrictions . IsNull ( "Wohnheim" ) ) ) ;
2022-01-05 16:23:38 +01:00
return criteria . List < DienstInfo > ( ) ; // Hier fliegt man raus
2021-10-12 16:00:17 +02:00
}
2021-11-08 20:24:26 +01:00
public long? GetActiveMedVerListOidForCustomer ( long customerOid )
{
// Gültig und MedListType = 0
var criteria = CreateCriteria < Medikamentenverordnungsliste > ( )
. Add ( Restrictions . Eq ( nameof ( Medikamentenverordnungsliste . Gueltig ) , true ) )
. Add ( Restrictions . Eq ( nameof ( Medikamentenverordnungsliste . Customer ) + ".Oid" , customerOid ) )
. Add ( Restrictions . Eq ( nameof ( Medikamentenverordnungsliste . MedListType ) , false ) ) ;
var list = criteria . UniqueResult < Medikamentenverordnungsliste > ( ) ;
return list ? . Oid ;
}
public List < SchedulerAppointment > LoadOccurrencesByRecurrenceId ( string recurrenceId )
{
var criteria = CreateCriteria < SchedulerAppointment > ( )
. Add ( Restrictions . Like ( nameof ( SchedulerAppointment . RecurrenceInfo ) , recurrenceId , MatchMode . Anywhere ) ) ;
var list = criteria . List < SchedulerAppointment > ( ) ;
return list . ToList ( ) ;
}
2022-02-10 11:06:03 +01:00
// TODO: Intervalle werden als frei angezeigt, wenn sie am Ende eines Tages sind und sich mit Serienterminen überschneiden
public Dictionary < DateTime , List < DateTimeSpan > > FindAppointmentsInRange ( int duration , DateTime intervalStart , DateTime intervalEnd , List < long > resourceOids , List < long > customerOids , List < long > employeeOids , long loggedInEmployeeOid , int intervalBuffer = 30 , bool skipWeekends = true )
{
var result = new List < SchedulerAppointment > ( ) ;
var intervals = IntervalFinderHelper . CreateIntervals ( duration , intervalStart , intervalEnd , skipWeekends , intervalBuffer ) ;
var subset = IntervalFinderHelper . GenereateIntervalsForChecking ( intervalStart , intervalEnd ) ;
var sw = new Stopwatch ( ) ;
sw . Start ( ) ;
foreach ( var dts in subset )
{
var start = dts . StartDate . MergeDatesByDate ( intervalStart ) ;
var end = dts . EndDate . MergeDatesByDate ( intervalEnd ) ;
var apptmts = LoadAppointmentsForIntervalFinder ( start , end , resourceOids , customerOids , employeeOids , loggedInEmployeeOid , skipWeekends ) ;
result . AddRangeIfElementsNotIn ( apptmts ) ;
}
sw . Stop ( ) ;
var ms = sw . ElapsedMilliseconds ;
Debug . WriteLine ( $"FindAppointmentsInRange: Es dauerte {ms}ms {result.Count} Termine zwischen dem {intervalStart:dd.MM.yyyy HH:mm} und dem {intervalEnd:dd.MM.yyyy HH:mm} aus der Datenbank zu laden" ) ;
/ *
Normal = 0 ,
Pattern = 1 ,
Occurrence = 2 ,
ChangedOccurrence = 3 ,
DeletedOccurrence = 4
* /
var changedOccurrences = result . Where ( a = > a . Type = = 3 ) . Select ( s = > BS . Shared . Core . Utils . GetOccurrenceId ( s . RecurrenceInfo ) ) . ToList ( ) ;
var deletedOccurrences = result . Where ( a = > a . Type = = 4 ) . Select ( s = > BS . Shared . Core . Utils . GetOccurrenceId ( s . RecurrenceInfo ) ) . ToList ( ) ;
var kek = IntervalFinderHelper . GetRecurrencesForIntervalFinder ( result , intervalStart , intervalEnd , changedOccurrences , deletedOccurrences , skipWeekends ) ;
result . AddRange ( kek ) ;
var freeIntervals = new List < DateTimeSpan > ( ) ;
if ( intervals . Count > 0 )
{
if ( result . Count > 0 )
{
foreach ( var interval in intervals )
{
if ( ! result . Any ( a = > a . StartDate . HasValue & & a . EndDate . HasValue & & a . StartDate . Value . IsInInterval ( a . EndDate . Value , interval . StartDate , interval . EndDate ) ) )
{
freeIntervals . Add ( interval ) ;
}
}
}
else
{
return IntervalFinderHelper . CreateFreeIntervalsDictionary ( intervals ) ;
}
}
return IntervalFinderHelper . CreateFreeIntervalsDictionary ( freeIntervals ) ;
}
private IEnumerable < SchedulerAppointment > LoadAppointmentsForIntervalFinder ( DateTime intervalStart , DateTime intervalEnd , IReadOnlyCollection < long > resourceOids , IReadOnlyCollection < long > customerOids , List < long > employeeOids , long loggedInEmployeeOid , bool skipWeekends )
{
var result = new List < SchedulerAppointment > ( ) ;
if ( intervalStart < intervalEnd )
{
var intervals = IntervalFinderHelper . GenerateIntervalsForCriteria ( intervalStart , intervalEnd , skipWeekends ) ;
var intervalRecurrenceCriterias = IntervalFinderHelper . CreateIntervalRecurrenceCriterias ( intervals , skipWeekends ) ;
var or = CreateOrCriteria ( intervalRecurrenceCriterias ) ;
var criteria = CreateCriteriaIsActiveWithAlias < SchedulerAppointment > ( "sa" )
. Add ( Restrictions . Not ( Restrictions . Eq ( nameof ( SchedulerAppointment . IsTask ) , true ) ) ) ;
if ( intervals . Count > 0 )
{
if ( intervals . Count > 1 )
{
var criterionList = new List < ICriterion > ( ) ;
foreach ( var dts in intervals )
{
criterionList . AddIfNotIn (
Restrictions . Or (
Restrictions . Between ( nameof ( SchedulerAppointment . StartDate ) , dts . StartDate , dts . EndDate ) ,
Restrictions . Or (
Restrictions . Between ( nameof ( SchedulerAppointment . EndDate ) , dts . StartDate , dts . EndDate ) ,
Restrictions . And (
Restrictions . Lt ( nameof ( SchedulerAppointment . StartDate ) , dts . StartDate ) ,
Restrictions . Gt ( nameof ( SchedulerAppointment . EndDate ) , dts . EndDate ) ) )
) ) ;
}
criteria . Add ( Restrictions . Or ( or , CreateOrCriteria ( criterionList ) ) ) ;
}
else
{
var dts = intervals . FirstOrDefault ( ) ;
if ( dts ! = null )
{
var cri = Restrictions . Or (
Restrictions . Between ( nameof ( SchedulerAppointment . StartDate ) , dts . StartDate , dts . EndDate ) ,
Restrictions . Or (
Restrictions . Between ( nameof ( SchedulerAppointment . EndDate ) , dts . StartDate , dts . EndDate ) ,
Restrictions . And (
Restrictions . Lt ( nameof ( SchedulerAppointment . StartDate ) , dts . StartDate ) ,
Restrictions . Gt ( nameof ( SchedulerAppointment . EndDate ) , dts . EndDate ) ) )
) ;
criteria . Add ( Restrictions . Or ( or , cri ) ) ;
}
}
}
ICriterion resourceCriterion = null ;
ICriterion customerCriterion = null ;
if ( employeeOids . Count = = 0 )
{
employeeOids . Add ( loggedInEmployeeOid ) ;
}
var detachedCriteria1 = DetachedCriteria . For < Employee2SchedulerAppointment > ( )
. Add ( Restrictions . In ( nameof ( Employee2SchedulerAppointment . Employee ) + ".Oid" , employeeOids ) )
. SetProjection ( Projections . Property ( nameof ( Employee2SchedulerAppointment . SchedulerAppointmentOid ) ) ) ;
var employee2SchedCrit = Subqueries . PropertyIn ( nameof ( BeWoEntityBase . Oid ) , detachedCriteria1 ) ;
var originatorCrit = Restrictions . In ( nameof ( SchedulerAppointment . Originator ) , employeeOids ) ;
var detachedCriteria2 = DetachedCriteria . For < Employee2SchedulerAppointment > ( "e2s2" )
. SetProjection ( Projections . Property ( nameof ( BeWoEntityBase . Oid ) ) )
. Add ( Restrictions . EqProperty ( "e2s2." + nameof ( Employee2SchedulerAppointment . SchedulerAppointmentOid ) , "sa.Oid" ) ) ;
var employee2SchedCrit2 = Subqueries . NotExists ( detachedCriteria2 ) ;
var and = Restrictions . And ( originatorCrit , employee2SchedCrit2 ) ;
var employeeCriterion = Restrictions . Or ( employee2SchedCrit , and ) ;
if ( customerOids ? . Count > 0 )
{
var customerSql = $"{BeWoEntityBase.PropertyName_Oid} IN (SELECT newschappoid FROM customer2newschapp WHERE customeroid IN ({customerOids.ToSeparatedString(" , ")}))" ;
customerCriterion = Expression . Sql ( customerSql ) ;
}
if ( resourceOids ? . Count > 0 )
{
var resourceSql = $"{BeWoEntityBase.PropertyName_Oid} IN (SELECT newschappoid FROM resource2newschapp WHERE resourceoid IN ({resourceOids.ToSeparatedString(" , ")}))" ;
resourceCriterion = Expression . Sql ( resourceSql ) ;
}
var listOfCriterias = new List < ICriterion >
{
employeeCriterion ,
customerCriterion ,
resourceCriterion
} ;
if ( listOfCriterias . Count > 0 )
{
var orCriteria = CreateOrCriteria ( listOfCriterias ) ;
if ( orCriteria ! = null )
{
criteria . Add ( orCriteria ) ;
}
}
var criteriaAsString = criteria . ToString ( ) ;
var appointments = criteria . List < SchedulerAppointment > ( ) . ToList ( ) ;
result . AddRange ( appointments ) ;
}
return result ;
}
private static string GetGeneratedSql ( ICriteria criteria )
{
var criteriaImpl = ( CriteriaImpl ) criteria ;
var sessionImpl = ( SessionImpl ) criteriaImpl . Session ;
var factory = ( SessionFactoryImpl ) sessionImpl . SessionFactory ;
var implementors = factory . GetImplementors ( criteriaImpl . EntityOrClassName ) ;
var loader = new CriteriaLoader ( ( IOuterJoinLoadable ) factory . GetEntityPersister ( implementors [ 0 ] ) , factory , criteriaImpl , implementors [ 0 ] , sessionImpl . EnabledFilters ) ;
return loader . SqlString . ToString ( ) ;
}
2022-10-10 12:57:34 +02:00
public long GetMaxOidFromFileAttachment ( )
{
var q = Session . CreateSQLQuery ( "select max(oid) from fileattachment" ) ;
return q . List < long > ( ) . First ( ) ;
}
2022-12-30 16:28:23 +01:00
public IEnumerable < AbsenceTime > GetAllAbsenceTimesInIntervalForCustomers ( DateTime start , DateTime end , List < long > customerOids )
{
// Wenn das Enddatum null ist, wird das Ende des Intervalls als Enddatum gesetzt (Ist ja eh read-only).
var criteria = CreateCriteriaIsActive < AbsenceTime > ( )
. Add ( Restrictions . IsNotNull ( nameof ( AbsenceTime . CustomerOid ) ) )
. Add ( Restrictions . Or
( Restrictions . Or ( Restrictions . Or (
Restrictions . And ( Restrictions . Ge ( AbsenceTime . PropertyName_Start , start ) , Restrictions . Le ( AbsenceTime . PropertyName_Start , end ) ) ,
Restrictions . Eq ( AbsenceTime . PropertyName_Start , start )
) , Restrictions . And ( Restrictions . Le ( AbsenceTime . PropertyName_Start , start ) , Restrictions . IsNull ( AbsenceTime . PropertyName_End ) )
) , Restrictions . And ( Restrictions . Lt ( AbsenceTime . PropertyName_Start , start ) , Restrictions . Gt ( AbsenceTime . PropertyName_End , start ) ) )
)
. Add ( Restrictions . In ( nameof ( AbsenceTime . CustomerOid ) , customerOids ) ) ;
var absenceTimes = criteria . List < AbsenceTime > ( ) ;
return criteria . List < AbsenceTime > ( ) ;
}
public IEnumerable < AbsenceTime > GetAllEmployeeAbsenceTimesInIntervalForEmployee ( DateTime start , DateTime end , List < long > employeeOids )
{
// Wenn das Enddatum null ist, wird das Ende des Intervalls als Enddatum gesetzt (Ist ja eh read-only).
var criteria = CreateCriteriaIsActive < AbsenceTime > ( )
. Add ( Restrictions . IsNotNull ( nameof ( AbsenceTime . EmployeeOid ) ) )
. Add ( Restrictions . Or
( Restrictions . Or ( Restrictions . Or (
Restrictions . And ( Restrictions . Ge ( AbsenceTime . PropertyName_Start , start ) , Restrictions . Le ( AbsenceTime . PropertyName_Start , end ) ) ,
Restrictions . Eq ( AbsenceTime . PropertyName_Start , start )
) , Restrictions . And ( Restrictions . Le ( AbsenceTime . PropertyName_Start , start ) , Restrictions . IsNull ( AbsenceTime . PropertyName_End ) )
) , Restrictions . And ( Restrictions . Lt ( AbsenceTime . PropertyName_Start , start ) , Restrictions . Gt ( AbsenceTime . PropertyName_End , start ) ) )
)
. Add ( Restrictions . In ( nameof ( AbsenceTime . EmployeeOid ) , employeeOids ) ) ;
return criteria . List < AbsenceTime > ( ) ;
}
public List < Customer > FindAllCustomersForEmployee ( long? employeeOid , CustomerFilterEnum customerFilter )
{
ApplicationUser user ;
if ( employeeOid . HasValue )
{
var employee = CreateCriteria < Employee > ( ) . Add ( Restrictions . Eq ( nameof ( Employee . Oid ) , employeeOid ) ) . UniqueResult < Employee > ( ) ;
user = FindUserForEmployee ( employee ) ;
}
else
{
user = LoggedInUserOperationContextExt . Current ? . User ! = null ? LoggedInUserOperationContextExt . Current . User : SessionFacade . LoggedInUser ;
}
var criteria = CreateCriteria < Customer > ( ) ;
// Der ApplicationUser darf alles sehen
var viewAllRights = new List < UserRightType > { UserRightType . CustomerView_View } ;
if ( user . CheckForAtLeastOneRight ( viewAllRights ) & & customerFilter = = CustomerFilterEnum . All )
{
return criteria . List < Customer > ( ) . ToList ( ) ;
}
var ownCustomerOids = user . Employee ? . Employee2CustomerList . Where ( employee2Customer = > employee2Customer . Customer . Oid . HasValue ) . Select ( employee2Customer = > employee2Customer . Customer . Oid . Value ) . Distinct ( ) . ToList ( ) ? ? new List < long > ( ) ;
var customerOids = new List < long > ( ) ;
// Der ApplicationUser darf die Klienten seiner Teams sehen
if ( user . CheckForRight ( UserRightType . Customer_ViewMyTeams ) & & ( customerFilter = = CustomerFilterEnum . TeamCustomer | | customerFilter = = CustomerFilterEnum . All ) & & ( user . Employee ? . Oid . HasValue ? ? false ) )
{
var teams = FindAllActiveTeamsOfEmployee ( user . Employee . Oid . Value ) ;
teams . DoForEach ( team = >
{
if ( team . Oid is null )
{
return ;
}
var customer = FindCustomerOfTeam ( team . Oid . Value ) ;
customerOids . AddRangeIfElementsNotIn ( customer . Where ( w = > w . Oid . HasValue ) . Select ( c = > c . Oid . Value ) ) ;
} ) ;
}
// Der ApplicationUser darf seine eigenen Klienten sehen.
if ( user . CheckForRight ( UserRightType . Customer_ViewMyCustomers ) & & ( customerFilter = = CustomerFilterEnum . All | | customerFilter = = CustomerFilterEnum . MyCustomer ) )
{
customerOids . AddRangeIfElementsNotIn ( ownCustomerOids ) ;
}
var visibleCustomers = criteria . Add ( Restrictions . In ( nameof ( Customer . Oid ) , customerOids . ToArray ( ) ) ) . List < Customer > ( ) . ToList ( ) ;
return visibleCustomers ;
}
public IList < Employee > FindAllEmployeesForEmployee ( long? employeeOid )
{
ApplicationUser user ;
if ( employeeOid . HasValue )
{
var employee = CreateCriteria < Employee > ( ) . Add ( Restrictions . Eq ( nameof ( Employee . Oid ) , employeeOid ) ) . UniqueResult < Employee > ( ) ;
user = FindUserForEmployee ( employee ) ;
}
else
{
if ( LoggedInUserOperationContextExt . Current ! = null & & LoggedInUserOperationContextExt . Current . User ! = null )
{
user = LoggedInUserOperationContextExt . Current . User ;
}
else
{
user = SessionFacade . LoggedInUser ;
}
}
if ( user . Employee . Oid = = null )
{
return new List < Employee > ( ) ;
}
var rights = new List < UserRightType > ( ) ;
user . UserGroups . DoForEach ( s = > s . Rights . DoForEach ( right = > rights . AddIfNotIn ( right . RightType ) ) ) ;
var criteria = CreateCriteria < Employee > ( ) ;
if ( rights . Contains ( UserRightType . EmployeeView_View ) )
{
return criteria . List < Employee > ( ) . ToList ( ) ;
}
var result = new List < Employee > ( ) ;
if ( rights . Contains ( UserRightType . Employee_AllowViewOwnEmployees ) )
{
result . AddIfNotIn ( user . Employee ) ;
}
if ( rights . Contains ( UserRightType . Employee_AllowViewOwnTeam ) )
{
var leadingTeams = user . Employee . LeadingTeams ;
leadingTeams . DoForEach ( team = >
{
result . AddIfNotIn ( team . Leader ) ;
result . AddRangeIfElementsNotIn ( team . MemberList ) ;
} ) ;
var teams = FindTeamsOfEmployee ( user . Employee . Oid . Value ) ;
teams . DoForEach ( team = >
{
result . AddIfNotIn ( team . Leader ) ;
result . AddRangeIfElementsNotIn ( team . MemberList ) ;
} ) ;
}
return result ;
}
2023-01-26 12:55:56 +01:00
public List < SchedulerAppointment > LoadAppointmentsWithServiceRecords ( List < long > serviceRecordOids )
{
var c = CreateCriteria < SchedulerAppointment > ( )
. CreateAlias ( nameof ( SchedulerAppointment . ServiceRecordList ) , "sr" , JoinType . InnerJoin )
. Add ( Restrictions . In ( $"sr.{nameof(BeWoEntityBase.Oid)}" , serviceRecordOids . ToArray ( ) ) )
. SetResultTransformer ( new DistinctRootEntityResultTransformer ( ) ) ;
return c . List < SchedulerAppointment > ( ) . ToList ( ) ;
}
2016-11-16 15:46:13 +01:00
}
2016-06-27 01:45:38 +02:00
}