2025-06-27 13:11:10 +02:00
using BeWo.Data.Access ;
using BeWo.Data.Entities ;
using BeWo.Service.DCEntityMapper ;
2023-02-23 11:48:41 +01:00
using BeWo.Service.Plugins ;
2020-12-16 21:49:47 +01:00
using BeWo.View.Navigation.Filter ;
2016-06-27 01:45:38 +02:00
using BeWoPlanerMobil.Models ;
using BeWoPlanerMobil.Service ;
2018-04-18 14:33:21 +02:00
using BeWoPlanerMobil.Util ;
2016-06-27 01:45:38 +02:00
using BS.Shared ;
using BS.Shared.Core ;
using BS.Shared.DataContracts ;
using BS.Shared.DataContracts.Compact ;
2018-01-29 12:57:10 +01:00
using BS.Shared.Extensions ;
2018-04-18 14:33:21 +02:00
using BS.Shared.Services ;
2023-03-03 21:54:36 +01:00
using DevExpress.XtraScheduler ;
using DevExpress.XtraScheduler.Compatibility ;
2020-02-07 15:21:36 +01:00
using Newtonsoft.Json ;
2025-06-27 13:11:10 +02:00
using System ;
using System.Collections.Generic ;
using System.Drawing ;
using System.Linq ;
using System.Net ;
using System.Net.Sockets ;
using System.Text ;
using System.Web.Mvc ;
using System.Windows.Forms ;
using static BeWoPlanerMobil . Util . MobileUtils ;
2018-12-10 23:40:38 -04:00
using static BS . Shared . ServiceRecordValidationResult ;
2020-04-02 13:19:14 +02:00
using FormCollection = System . Web . Mvc . FormCollection ;
2023-07-13 13:39:41 +02:00
using GoalRating = BeWoPlanerMobil . Util . GoalRating ;
using Image = System . Drawing . Image ;
2018-11-30 16:47:57 -04:00
using ServiceRecordDC = BS . Shared . DataContracts . ServiceRecordDC ;
2018-01-29 12:57:10 +01:00
2024-09-12 14:55:35 +02:00
/ *
2024-11-12 18:37:23 +01:00
* ToDo : Bug , wenn man auf "bearbeiten" bei einem Eintrag klickt , wird die Leistung nicht geladen
2024-09-12 14:55:35 +02:00
* ToDo : Hat man vor dem Anlegen einer Mehrfachbuchung einen Hilfeplan ausgewählt , wird der nicht richtig nach dem Anlegen geladen und die Intervallauswahl ist nicht sichtbar .
* /
2016-06-27 01:45:38 +02:00
namespace BeWoPlanerMobil.Controllers
{
public class MainController : AbstractBaseController
{
2025-07-15 14:26:03 +02:00
public MainController ( )
{
int test = 0 ;
}
2018-01-29 12:57:10 +01:00
private MainModel _Model ;
2025-07-15 14:26:03 +02:00
public bool SkipModelInitialization { get ; set ; }
2016-06-27 01:45:38 +02:00
public MainModel Model
{
get
{
2018-04-18 14:33:21 +02:00
if ( ! MobileSessionFacade . IsUserLoggedIn ( ) )
2016-06-27 01:45:38 +02:00
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
return null ;
}
2025-06-27 13:11:10 +02:00
if ( _Model is null )
2016-06-27 01:45:38 +02:00
{
2025-07-15 14:26:03 +02:00
var sw = new System . Diagnostics . Stopwatch ( ) ;
sw . Start ( ) ;
2025-06-11 22:56:25 +02:00
_Model = new MainModel ( ) ;
InitModel ( _Model ) ;
2025-07-15 14:26:03 +02:00
if ( ! SkipModelInitialization )
{
InitViewModel ( ) ;
}
sw . Stop ( ) ;
System . Diagnostics . Debug . WriteLine ( $"MainModel Initialisierung in: {sw.ElapsedMilliseconds} ms" ) ;
2016-06-27 01:45:38 +02:00
}
2018-01-29 12:57:10 +01:00
return _Model ;
2016-06-27 01:45:38 +02:00
}
}
2018-01-29 12:57:10 +01:00
private Dictionary < long , ValueListEntryDC > _ParentGoals ;
2016-06-27 01:45:38 +02:00
2025-01-31 15:15:40 +01:00
private static readonly List < ValueListEntryType > _GoalTypes = new List < ValueListEntryType > { ValueListEntryType . SupportConceptGoalCategoryType , ValueListEntryType . SupportConceptIndividualGoalCategoryType } ;
private static readonly List < ValueListEntryType > _MeasureTypes = new List < ValueListEntryType > { ValueListEntryType . SupportConceptGoalType , ValueListEntryType . SupportConceptIndividualGoalType } ;
2016-06-27 01:45:38 +02:00
2025-06-11 22:56:25 +02:00
public void InitViewModel ( )
{
InitSettings ( ) ;
2020-08-04 12:45:46 +02:00
2025-07-15 14:26:03 +02:00
CreateModelSupportConceptListObjects ( false ) ;
2025-06-11 22:56:25 +02:00
Model . GroupsOfPeople = EmployeeService . GetAllGroups ( LoggedInEmployee . EmployeeOid ) . OrderBy ( gop = > gop . Name ) . ToList ( ) ;
Model . Dokutypes = ValueListService . GetAllValueListEntrysByType ( ValueListEntryType . DocumentType ) ;
2025-07-18 19:37:01 +02:00
if ( Model . Dokutypes ! = null )
2025-06-11 22:56:25 +02:00
{
Model . Dokutypes = Model . Dokutypes . OrderBy ( s = > s . ValueListEntryOid ) . ToArray ( ) ;
}
//Load Employees
2025-07-18 19:37:01 +02:00
if ( Model . AllEmployees is null )
2025-06-11 22:56:25 +02:00
{
2025-07-15 14:26:03 +02:00
Model . AllEmployees = EmployeeService . GetAllCompactEmployees ( ) . Where ( e = > e . ActivationType = = ActivationTypeId . Active ) . OrderBy ( e = > e . LastName ) . ToList ( ) ;
2025-06-11 22:56:25 +02:00
}
2025-07-18 19:37:01 +02:00
if ( Model . EmployeesForGroupAndMultiBooking is null )
2025-06-11 22:56:25 +02:00
{
2025-07-15 14:26:03 +02:00
Model . EmployeesForGroupAndMultiBooking = Model . AllEmployees ;
2025-06-11 22:56:25 +02:00
}
2025-07-18 19:37:01 +02:00
if ( LoggedInUser . HasRight ( UserRightType . ServiceRecord_AllowCreationForOtherEmployees ) )
2025-06-11 22:56:25 +02:00
{
Model . Employees = Model . AllEmployees ;
}
2025-07-18 19:37:01 +02:00
else if ( LoggedInUser . HasRight ( UserRightType . ServiceRecord_AllowCreationForOtherTeamMember ) & & Model . LoggedInEmployee . EmployeeOid ! = null )
2025-06-11 22:56:25 +02:00
{
Model . Employees = EmployeeService . GetAllTeamMember ( LoggedInUser . Employee ) . Where ( e = > e . ActivationType = = ActivationTypeId . Active ) . ToList ( ) ;
}
else
{
Model . Employees = new List < CompactEmployeeDC > { LoggedInUser . Employee } ;
}
Model . Employees = Model . Employees . OrderBy ( e = > e . LastName ) . ThenBy ( e = > e . FirstName ) . ToList ( ) ;
2025-07-15 14:26:03 +02:00
Model . GroupBookingSelectedCostBearerSupportConcepts = new List < SupportConceptCostBearerRelDC > ( ) ;
2025-06-11 22:56:25 +02:00
Model . GoalRatingTypes = OperationsService . GetAllRatingTypes ( ) . OrderBy ( o = > o . Position ) . ToList ( ) ;
SetSelectedObjects ( ) ;
2025-07-15 14:26:03 +02:00
}
public void CreateModelSupportConceptListObjects ( bool forceReload )
{
//Load SupportConcepts
2025-07-18 19:37:01 +02:00
if ( Model . SupportConceptListObjects is null | | Model . SupportConceptListObjects . Count = = 0 | | forceReload | | ( Model . SelectedCostBearerSupportConceptOid . HasValue & & Model . SelectedCostBearerSupportConceptOid . Value ! = - 1 ) )
2025-07-15 14:26:03 +02:00
{
2025-07-18 19:37:01 +02:00
if ( Model . LoggedInEmployee ? . EmployeeOid . HasValue ? ? false )
2025-07-15 14:26:03 +02:00
{
//Model.SupportConcepts = new List<CompactSupportConceptDC>();
var test = OperationsService . GetAllActiveSupportConceptCostbearer ( false , true , Model . LoggedInEmployee . EmployeeOid . Value ) ;
Model . SupportConcepts = test ;
}
else
{
Model . SupportConcepts = new List < CompactSupportConceptDC > ( ) ;
}
2025-07-18 19:37:01 +02:00
if ( Model . ShowExpiredSupportConcepts = = false )
2025-07-15 14:26:03 +02:00
{
2025-07-18 19:37:01 +02:00
Model . SupportConcepts = Model . SupportConcepts . Where ( sc = > sc . EndDate is null | | sc . EndDate . Value > = DateTime . Now . Date ) . ToList ( ) ;
2025-07-15 14:26:03 +02:00
}
2025-07-18 19:37:01 +02:00
foreach ( var supportConcept in Model . SupportConcepts )
2025-07-15 14:26:03 +02:00
{
2025-07-18 19:37:01 +02:00
if ( supportConcept . Goals is null )
2025-07-15 14:26:03 +02:00
{
2025-07-18 19:37:01 +02:00
supportConcept . Goals = new List < ValueListEntryDC > ( ) ;
2025-07-15 14:26:03 +02:00
}
}
//Einfachbuchung
var allCostBearerRelationsSingleBooking = new List < MokSupportConceptListObject > {
new MokSupportConceptListObject ( - 1 , - 1 , false , false )
{
NameAndDateOfBirth = "Hilfeplan auswählen"
} ,
new MokSupportConceptListObject ( - 2 , - 2 , false , false )
{
NameAndDateOfBirth = "Ohne Hilfeplan"
} } ;
var allCostBearerRelationsMultiBooking = new List < MokSupportConceptListObject > ( ) ;
BS . Shared . Settings . ApplicationSettings . SupportConceptExpirationLimitInMonths = Model . MokSettings . SupportConceptExpirationLimitInMonths ;
foreach ( var sc in Model . SupportConcepts . OrderBy ( sc = > sc . Customer . LastName ) )
{
foreach ( var cb in sc . CostBearerList )
{
2025-07-18 19:37:01 +02:00
var customerName = $"{sc.Customer.SimpleDescription} {(sc.Customer.DateOfBirth.HasValue ? " * " + sc.Customer.DateOfBirth.Value.ToString(" dd . MM . yyyy ") : string.Empty)}" ;
var scNameSingle = $"{cb.Bezeichnung} {sc.StartDate?.ToShortDateString().Remove(6, 2) ?? string.Empty}-{sc.EndDate?.ToShortDateString().Remove(6, 2) ?? string.Empty} {cb.OrganisationName}" ; // {Model.GetIsNotApproved(sc)}";
2025-07-15 14:26:03 +02:00
scNameSingle = sc . CostBearer ;
allCostBearerRelationsMultiBooking . Add ( new MokSupportConceptListObject ( sc . SupportConceptOid , sc . CostBearerRelOids [ 0 ] , sc . IsAboutToExpire , sc . ExpiresIn3MonthOrLess )
{
NameAndDateOfBirth = customerName ,
SupportConceptTimeSpan = scNameSingle
} ) ;
}
}
allCostBearerRelationsSingleBooking . AddRange ( allCostBearerRelationsMultiBooking ) ;
Model . SupportConceptListObjects = allCostBearerRelationsSingleBooking ;
Model . SupportConceptListObjectsForGroupBooking = allCostBearerRelationsMultiBooking ;
}
if ( Model . SupportConceptListObjectsForGroupBooking = = null & & Model . SupportConceptListObjects ! = null )
{
Model . SupportConceptListObjectsForGroupBooking = Model . SupportConceptListObjects . Where ( s = > s . CostBearer2SupportConceptOid > 0 ) . ToList ( ) ;
}
2025-06-11 22:56:25 +02:00
}
private void SetSelectedObjects ( )
2016-06-27 01:45:38 +02:00
{
2025-06-27 13:11:10 +02:00
Model . SelectedEmployee = Model . SelectedEmployeeOid . HasValue ?
Model . AllEmployees . First ( f = > f . EmployeeOid . Equals ( Model . SelectedEmployeeOid . Value ) ) :
LoggedInUser . Employee ;
2025-06-11 22:56:25 +02:00
var isInList = Model . SelectedCostBearerSupportConceptOid . HasValue & & Model . SupportConceptListObjects . Exists ( s = > s . CostBearer2SupportConceptOid = = Model . SelectedCostBearerSupportConceptOid ) ;
if ( ! Model . SelectedCostBearerSupportConceptOid . HasValue | | ! isInList )
{
if ( Model . SelectedCostBearerSupportConceptOid . HasValue & & ! isInList )
2017-08-22 14:05:09 +02:00
{
2025-06-11 22:56:25 +02:00
Log . Info ( $"Model.SelectedCostBearerSupportConceptOid = {Model.SelectedCostBearerSupportConceptOid} is not in list !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" ) ;
2020-05-27 18:15:54 +02:00
2025-06-11 22:56:25 +02:00
var sb = new StringBuilder ( ) ;
foreach ( var o in Model . SupportConceptListObjects )
2020-05-27 18:15:54 +02:00
{
2025-06-11 22:56:25 +02:00
if ( sb . Length > 0 )
{
sb . Append ( ", " ) ;
}
sb . Append ( o . CostBearer2SupportConceptOid ) ;
2020-05-27 18:15:54 +02:00
}
2025-06-11 22:56:25 +02:00
Log . Info ( $"Model.SupportConceptListObjects Oids = {sb}" ) ;
2017-08-22 14:05:09 +02:00
}
2016-06-27 01:45:38 +02:00
2025-07-15 14:26:03 +02:00
Model . SelectedSupportConceptListObject = Model . SupportConceptListObjects . FirstOrDefault ( f = > f . CostBearer2SupportConceptOid = = - 1 ) ? ? Model . SupportConceptListObjects . First ( ) ;
2025-06-11 22:56:25 +02:00
Model . SelectedCostBearerSupportConceptOid = - 1 ;
2023-06-18 17:11:35 +02:00
2025-07-16 12:38:01 +02:00
2025-06-11 22:56:25 +02:00
}
else
{
2025-07-15 14:26:03 +02:00
Model . SelectedSupportConceptListObject = Model . SupportConceptListObjects . FirstOrDefault ( f = > f . CostBearer2SupportConceptOid = = Model . SelectedCostBearerSupportConceptOid ) ? ? Model . SupportConceptListObjects . First ( ) ;
2025-06-11 22:56:25 +02:00
}
2023-06-21 00:25:33 +02:00
2025-07-16 12:38:01 +02:00
Model . HasAnyRatingTypes = Model . HasRightToRateGoals & & Model . GoalRatingTypes . Any ( ) ;
2023-07-13 13:39:41 +02:00
2025-07-18 19:37:01 +02:00
if ( Model . GroupBookingSelectedCostBearerSupportConceptOids . Count > 0 )
2025-06-11 22:56:25 +02:00
{
2025-07-15 14:26:03 +02:00
Model . GroupBookingSelectedCostBearerSupportConcepts = CustomerService . GetSupportConceptCostBearerRelationsById ( Model . GroupBookingSelectedCostBearerSupportConceptOids ) ;
2025-06-11 22:56:25 +02:00
}
2023-07-13 13:39:41 +02:00
2025-06-11 22:56:25 +02:00
Model . GroupBookingSelectedEmployees = Model . AllEmployees . Where ( employee = > Model . GroupBookingSelectedEmployeeOids . Contains ( employee . EmployeeOid ) ) . ToList ( ) ;
2023-07-13 13:39:41 +02:00
2025-07-18 19:37:01 +02:00
if ( Model . SelectedCostBearerSupportConceptOid . HasValue & & Model . SelectedCostBearerSupportConceptOid ! = - 1 )
2025-06-11 22:56:25 +02:00
{
2025-07-15 14:26:03 +02:00
LoadSupportConceptThings ( Model . SelectedCostBearerSupportConceptOid , true ) ;
2025-06-11 22:56:25 +02:00
LoadPaginatedServiceRecordsToModel ( Model . CurrentPage ) ;
}
2025-07-18 19:37:01 +02:00
else if ( Model . IsInGroupBookingMode | | Model . IsInMultiBookingMode )
2025-06-17 13:06:29 +02:00
{
2025-07-15 14:26:03 +02:00
LoadSupportConceptThings ( null , true ) ;
2025-06-17 13:06:29 +02:00
}
2025-07-15 14:26:03 +02:00
2025-07-18 19:37:01 +02:00
if ( Model . AllGoals ! = null )
2025-06-11 22:56:25 +02:00
{
2025-07-17 16:26:07 +02:00
if ( Model . SelectedGoals . Count = = 0 & & Model . SelectedGoalOids . Count > 0 ) // Diese Abfrage muss bleiben, sonst werden vorher gewählte Bewertungen überschrieben
{
Model . SelectedGoals = DcToMokMapper . CreateZiele ( Model . AllGoals . Where ( g = > Model . SelectedGoalOids . Contains ( g . ValueListEntryOid . Value ) ) ) ;
}
2025-06-11 22:56:25 +02:00
}
2025-07-18 19:37:01 +02:00
if ( Model . IsInEditingMode & & Model . SelectedServiceRecordOid . HasValue )
2025-07-04 00:30:36 +02:00
{
2025-07-17 16:26:07 +02:00
Model . SelectedServiceRecord = Model . ServiceRecords . FirstOrDefault ( sr = > sr . ServiceRecordOid . Equals ( Model . SelectedServiceRecordOid . Value ) ) ;
2025-07-04 00:30:36 +02:00
}
2025-06-11 22:56:25 +02:00
}
2020-12-16 21:49:47 +01:00
2025-06-11 22:56:25 +02:00
private void InitSettings ( )
{
//Mandator Settings
Model . ShowBetrag = UserSettingsUtils . GetSettingValueAsBool ( Model . Mandator . Settings , SettingsKeys . ShowBetrag ) ;
Model . ShowMarker = UserSettingsUtils . GetSettingValueAsBool ( Model . Mandator . Settings , SettingsKeys . ShowMarker ) ;
Model . EinheitZeiterfassung = UserSettingsUtils . GetSettingValueAsInteger ( Model . Mandator . Settings , SettingsKeys . EinheitZeiterfassung ) ;
2023-05-02 13:03:46 +02:00
2025-06-11 22:56:25 +02:00
/ *
* Minuten : 0
* Stunden : 1
* Min & Std : 2
* /
if ( Model . EinheitZeiterfassung = = 1 )
{
Model . IsShowingDurationInHours = true ;
}
2023-05-15 11:54:13 +02:00
2025-06-11 22:56:25 +02:00
Model . FilterGroupServiceCategories = UserSettingsUtils . GetSettingValueAsBool ( Model . Mandator . Settings , SettingsKeys . FilterGroupServiceCategories ) ;
Model . SetStartTimeToEndTimeAfterSave = UserSettingsUtils . GetSettingValueAsBool ( Model . Mandator . Settings , SettingsKeys . SetStartTimeToEndTimeAfterSave ) ;
2024-06-05 14:45:33 +02:00
2025-06-11 22:56:25 +02:00
Model . MokSettings = new MokSettings ( ) ;
2022-09-07 13:19:08 +02:00
2025-06-11 22:56:25 +02:00
Model . MokSettings . SupportConceptExpirationLimitInMonths = UserSettingsUtils . GetSettingValueAsInteger ( Model . Mandator . Settings , SettingsKeys . HilfeplanAuslaufAuswahl , 3 ) ;
Model . MokSettings . AnzTageZeiterfassErfolgt = UserSettingsUtils . GetSettingValueAsInteger ( Model . Mandator . Settings , SettingsKeys . AnzTageZeiterfassErfolgt ) ;
Model . MokSettings . MaxDaysEditServiceRecordsAllowed = UserSettingsUtils . GetSettingValueAsInteger ( Model . Mandator . Settings , SettingsKeys . MaxDaysEditServiceRecordsAllowed ) ;
Model . MokSettings . TimeUntilUILock = UserSettingsUtils . GetSettingValueAsInteger ( Model . Mandator . Settings , SettingsKeys . TimeUntilUILock ) ;
Model . MokSettings . ServiceRecordAllowChangeHours = UserSettingsUtils . GetSettingValueAsInteger ( Model . Mandator . Settings , SettingsKeys . ServiceRecordAllowChangeHours ) ;
2021-03-17 18:44:40 +01:00
2025-06-11 22:56:25 +02:00
Model . ShowServiceRecordInsertedOn = ! UserSettingsUtils . GetSettingValueAsBool ( Model . Mandator . Settings , SettingsKeys . HideServiceRecordInsertedByAndInsertedOn ) ;
2021-03-17 18:44:40 +01:00
2025-06-11 22:56:25 +02:00
Model . ShowSignature = UserSettingsUtils . GetSettingValueAsBool ( Model . Mandator . Settings , SettingsKeys . ShowSignature ) & & Model . HasRightToProvideSingleSignature ;
2020-08-04 12:45:46 +02:00
2025-06-11 22:56:25 +02:00
Model . ShowDistanceField = UserSettingsUtils . GetSettingValueAsBool ( Model . Mandator . Settings , SettingsKeys . ShowDistanceFields ) ;
2020-04-02 13:19:14 +02:00
2025-06-11 22:56:25 +02:00
var settingsValue = GetSettingValue ( Model . Mandator . Settings , SettingsKeys . IsServiceRecordNoticeMandatory ) ;
2024-03-14 17:18:35 +01:00
2025-06-11 22:56:25 +02:00
Model . IsServiceRecordNoticeMandatory = settingsValue is null | | ! settingsValue . Equals ( "0" ) ;
2020-05-27 18:15:54 +02:00
2025-06-11 22:56:25 +02:00
//User Settings
var user = LoggedInUser ;
var userSettings = user ? . Settings . FirstOrDefault ( f = > f . Type . Equals ( SettingsType . ApplicationSettings ) ) ? . Value ;
2020-05-27 18:15:54 +02:00
2025-06-11 22:56:25 +02:00
Model . ShowExpiredSupportConcepts = UserSettingsUtils . GetSettingValueAsBool ( userSettings , SettingsKeys . ShowExpiredSupportConcepts ) ;
Model . ShowOnlyOwnSupportConcepts = UserSettingsUtils . GetSettingValueAsBool ( userSettings , SettingsKeys . ShowOnlyMySupportConcepts ) ;
Model . IsOnlyYearMonthVisible = UserSettingsUtils . GetSettingValueAsBool ( userSettings , SettingsKeys . IsOnlyYearMonthVisible ) ;
2022-10-11 16:48:36 +02:00
2025-06-11 22:56:25 +02:00
Model . LastSelectedServiceRecordMonth = UserSettingsUtils . GetSettingValueAsDateTime ( userSettings , SettingsKeys . LastSelectedServiceRecordMonth ) ? ? DateTime . Today ;
2017-02-01 13:53:59 +01:00
2025-06-11 22:56:25 +02:00
//int zeitraum;
var serviceRecordTimeInterval = UserSettingsUtils . GetSettingValueAsEnum ( userSettings , SettingsKeys . LastSelectedServiceRecordTimeInterval , ServiceRecordTimeInterval . LastWeek ) ;
2017-02-01 13:53:59 +01:00
2025-06-11 22:56:25 +02:00
Model . ServiceRecordTimeInterval = serviceRecordTimeInterval ;
2018-02-02 14:43:40 +01:00
2025-06-11 22:56:25 +02:00
if ( serviceRecordTimeInterval = = ServiceRecordTimeInterval . ZeitraumWaehlen & & ( Model . SelectedZeitraum ? . StartDate is null | | Model . SelectedZeitraum . EndDate is null ) )
{
var today = DateTime . Today ;
Model . SelectedZeitraum = new NullableDateTimeSpan ( today . GetFirstOfMonth ( ) , today ) ;
}
2017-02-01 13:53:59 +01:00
2025-06-11 22:56:25 +02:00
Model . LastSelectedServiceRecordTimeIntervalDays = UserSettingsUtils . GetSettingValueAsInteger ( userSettings , SettingsKeys . LastSelectedServiceRecordTimeIntervalDays ) ;
2016-06-27 01:45:38 +02:00
2025-06-11 22:56:25 +02:00
if ( Model . ServiceRecordTimeInterval = = ServiceRecordTimeInterval . Monatsauswahl )
{
Model . SelectedZeitraum = new NullableDateTimeSpan ( Model . LastSelectedServiceRecordMonth . Date . GetFirstOfMonth ( ) , Model . LastSelectedServiceRecordMonth . Date . GetLastOfMonth ( ) ) ;
}
2023-03-31 12:32:08 +02:00
2025-06-11 22:56:25 +02:00
CalculateSelectedDayCount ( Model . LastSelectedServiceRecordTimeIntervalDays , Model . LastSelectedServiceRecordMonth , Model . SelectedZeitraum ? . StartDate , Model . SelectedZeitraum ? . EndDate , null ) ;
2016-06-27 01:45:38 +02:00
2025-06-11 22:56:25 +02:00
var customerFilter = MobileUserSettingsUtils . GetSettingValueAsEnum ( userSettings , SettingsKeys . CustomerFilterInZeiterfassung , CustomerFilterEnum . MyCustomer ) ;
2022-02-10 11:06:03 +01:00
2025-06-11 22:56:25 +02:00
if ( customerFilter ! = CustomerFilterEnum . MyCustomer & & ! Model . IsAllowedToSeeSupportConceptFilter )
{
customerFilter = CustomerFilterEnum . MyCustomer ;
}
//if (Model.SelectedSupportConceptFilter == null)
Model . SelectedSupportConceptFilter = customerFilter ;
Model . IsEndDateVisible = UserSettingsUtils . GetSettingValueAsBool ( Model . Mandator . Settings , SettingsKeys . IsEndDateVisible ) ;
if ( Model . IsZeiterfassungInStdMin )
{
var letzteZeiterfassungsdauer = UserSettingsUtils . GetSettingValueAsInteger ( userSettings , SettingsKeys . LetzteZeiterfassungsDauer ) ;
Model . IsShowingDurationInHours = letzteZeiterfassungsdauer = = 1 ;
}
}
2025-07-15 14:26:03 +02:00
private void LoadSupportConceptThings ( long? cb2ScOid , bool loadTextModules )
{
Model . SelectedCostBearerSupportConceptOid = cb2ScOid ;
bool istEinzelBuchung = ! Model . IsInGroupBookingMode & & ! Model . IsInMultiBookingMode ;
if ( istEinzelBuchung )
{
Model . SelectedSupportConcept = Model . SupportConcepts . FirstOrDefault ( sc = > sc . CostBearerRelOids . Any ( a = > a . Equals ( Model . SelectedCostBearerSupportConceptOid ) ) ) ;
}
if ( istEinzelBuchung & & ( ( ! cb2ScOid . HasValue ) | | cb2ScOid . Value = = - 1 ) )
{
// Im Einzelmodus entweder nichts oder "Hilfeplan auswählen" (-1) ausgewählt.
Model . Categories2Descriptions = new Dictionary < ServiceCategoryDC , List < ServiceDescriptionDC > > ( ) ;
Model . SelectedGoalOids = new List < long > ( ) ;
}
else
{
var allC2SOids = new List < long > ( ) ;
if ( ! istEinzelBuchung )
{
allC2SOids = Model . GroupBookingSelectedCostBearerSupportConceptOids ;
}
else if ( cb2ScOid . HasValue & & cb2ScOid . Value > 0 )
{
allC2SOids . Add ( cb2ScOid . Value ) ;
}
var scOids = Model . SupportConceptListObjects . Where ( sc = > allC2SOids . Contains ( sc . CostBearer2SupportConceptOid ) ) . Select ( s = > s . SupportConceptOid ) . ToList ( ) ;
var infos = OperationsService . GetSupportConceptTreeNodeDetailInfos ( scOids ) ;
LoadServiceCategoriesToModel ( infos ) ;
LoadGoals ( infos ) ;
if ( istEinzelBuchung & & Model . SelectedSupportConcept ! = null & & infos . Count = = 1 )
{
Model . SelectedSupportConcept . Goals = infos [ 0 ] . SupportConceptGoals ;
}
2025-07-16 12:38:01 +02:00
if ( Model . SupportConcepts ! = null )
{
foreach ( var info in infos )
{
var sc = Model . SupportConcepts . FirstOrDefault ( s = > s . SupportConceptOid = = info . SupportConceptOid ) ;
if ( sc ! = null )
{
sc . Goals = info . SupportConceptGoals ;
}
}
}
2025-07-15 14:26:03 +02:00
}
// Ist der Klient abwesend, wird dies wie im FaC angezeigt
if ( Model . SelectedSupportConcept ? . Customer ? . AbsenceTimes ? . Any ( ) ? ? false )
{
foreach ( var absenceTime in Model . SelectedSupportConcept . Customer . AbsenceTimes )
{
if ( absenceTime . Start . HasValue & & DateTime . Now > absenceTime . Start . Value & & ( absenceTime . End is null | | DateTime . Now < absenceTime . End . Value ) )
{
Model . IsCustomerAbsence = true ;
Model . CustomerAbsenceInfo = $"{absenceTime.Reason.Description} von {absenceTime.Start:dd.MM.yyyy} bis {(absenceTime.End.HasValue ? absenceTime.End.Value.ToString(" dd . MM . yyyy ") : " unbekannt ")}" ;
break ;
}
Model . IsCustomerAbsence = false ;
Model . CustomerAbsenceInfo = null ;
}
}
else
{
Model . IsCustomerAbsence = false ;
Model . CustomerAbsenceInfo = null ;
}
if ( loadTextModules )
{
LoadTextModules ( ) ;
}
}
2025-06-11 22:56:25 +02:00
public void LoadTextModules ( )
{
Model . TextModules . Clear ( ) ;
if ( Model . SelectedServiceCategoryOid . HasValue & & ( Model . LoggedInEmployee ? . EmployeeOid . HasValue ? ? false ) )
{
var allTextModules = OperationsService . GetTextModules ( Model . HasRightToSeeGlobalTextModules , Model . LoggedInEmployee . EmployeeOid . Value , Model . HasRightToSeeGlobalTextModules , false ) ;
foreach ( var tm in allTextModules . Where ( textModule = > textModule . IsParent = = false ) )
2016-06-27 01:45:38 +02:00
{
2025-06-11 22:56:25 +02:00
if ( string . IsNullOrWhiteSpace ( tm . Text ) )
{
tm . Text = tm . Name ;
}
2016-06-27 01:45:38 +02:00
}
2025-06-11 22:56:25 +02:00
Model . AllTextModules = allTextModules . Where ( tb = > tb . TextModuleOid . HasValue ) . Select ( tb = > new TextbausteinDisplayItem ( tb . Name , tb . Text , tb . Parent ? . TextModuleOid , tb . TextModuleOid . Value , tb . IsExpanded ) ) . ToList ( ) ;
var x = allTextModules . Where (
w = > ( w . ServiceCategory is null | | w . ServiceCategory . ServiceCategoryOid = = Model . SelectedServiceCategoryOid . Value )
& & ! string . IsNullOrEmpty ( w . Text )
& & ( w . IsOnlyForEmployee & & w . Employee . EmployeeOid . Equals ( Model . LoggedInEmployee . EmployeeOid ) | | ! w . IsOnlyForEmployee ) ) . OrderBy ( t = > t . Text ) . ToList ( ) ;
x . AddRangeIfElementsNotIn ( BS . Shared . Core . Utils . GetParentTextModules ( x ) ) ;
var textModuleDisplayItems = x . Where ( tb = > tb . TextModuleOid . HasValue ) . Select ( tb = > new TextbausteinDisplayItem ( tb . Name , tb . Text , tb . Parent ? . TextModuleOid , tb . TextModuleOid . Value , tb . IsExpanded ) ) . ToList ( ) ;
foreach ( var item in textModuleDisplayItems )
2018-02-28 12:42:23 +01:00
{
2025-06-11 22:56:25 +02:00
if ( item . ParentOid is null )
2018-02-28 12:42:23 +01:00
{
2025-06-11 22:56:25 +02:00
continue ;
}
2018-02-28 12:42:23 +01:00
2025-06-11 22:56:25 +02:00
var parent = textModuleDisplayItems . FirstOrDefault ( p = > p . Oid = = item . ParentOid ) ;
2018-02-28 12:42:23 +01:00
2025-06-11 22:56:25 +02:00
parent ? . Children . AddIfNotIn ( item ) ;
2019-03-29 14:04:12 +01:00
}
2022-12-30 16:28:23 +01:00
2025-06-11 22:56:25 +02:00
Model . TextModules = textModuleDisplayItems . Where ( item = > item . ParentOid is null ) . OrderBy ( item = > item . Name ) . ToList ( ) ;
}
}
2018-12-10 23:40:38 -04:00
2025-07-15 14:26:03 +02:00
private IList < CompactSupportConceptDC > GetSelectedGroupBookingSupportConcepts ( )
{
if ( Model . SupportConcepts = = null | | Model . SupportConcepts . Count = = 0 )
{
CreateModelSupportConceptListObjects ( true ) ;
}
var list = Model . SupportConcepts . Where ( sc = > sc . CostBearerRelOids . Count > 0 & & Model . GroupBookingSelectedCostBearerSupportConceptOids . Contains ( sc . CostBearerRelOids [ 0 ] ) ) . ToList ( ) ;
return list ;
}
2025-07-17 16:26:07 +02:00
public ServiceRecordDC GetServiceRecordDC ( long serviceRecordOid , bool getCompact )
{
ServiceRecordDC dc = null ;
if ( _Model ! = null )
{
dc = _Model . FindServiceRecord ( serviceRecordOid ) ;
}
if ( dc = = null )
{
var sr = DAOFactory . GenericDAO . LoadByID < ServiceRecord > ( serviceRecordOid ) ;
if ( getCompact )
{
dc = new ServiceRecordDC ( )
{
Betrag = sr . Betrag ,
CostBearer2SupportConceptOid = sr . CostBearer2SupportConceptOid ,
DistanceInMeter = ( int? ) sr . DistanceInMeter ,
DistanceInMeterDecimal = sr . DistanceInMeter ,
DurationInStunden = sr . DurationInStunden ,
End = sr . End ,
GroupEmployeeCount = sr . GroupEmployeeCount ,
GroupOid = sr . GroupOid ,
GroupPersonCount = sr . GroupPersonCount ,
GroupRoundedDuration = sr . GroupRoundedDuration ,
InsertedOn = sr . InsTs ,
InsUser = sr . InsUser ,
Notice = sr . Notice ,
Notice2 = sr . Notice2 ,
Notice3 = sr . Notice3 ,
Notice4 = sr . Notice4 ,
Notice5 = sr . Notice5 ,
Relevance = sr . Relevance ,
RoundedDuration = sr . RoundedDuration ,
ServiceRecordFormat = sr . ServiceRecordFormat ,
ServiceRecordType = sr . ServiceRecordType ? ? ServiceRecordTypeId . DefaultActivity ,
ServiceRecordVersion = sr . Version ,
SignatureOid = sr . SignatureOid ,
WohnheimbuchungsOid = sr . WohnheimbuchungsOid ,
ServiceRecordOid = sr . Oid ,
Start = sr . Start
} ;
return dc ;
}
dc = MapperFactory . ServiceRecordDC_ServiceRecord . MapToNewDC ( sr ) ;
}
return dc ;
}
2025-06-11 22:56:25 +02:00
[Authorize]
public ActionResult Main ( )
{
try
{
if ( ! MobileSessionFacade . IsUserLoggedIn ( ) | | Request . Browser . Browser . Equals ( "InternetExplorer" ) )
2018-12-10 23:40:38 -04:00
{
2025-06-11 22:56:25 +02:00
var isNewSession = Session . IsNewSession ;
if ( isNewSession )
{
TempData [ TempDataConstants . AutoEndOfSessionLogoutMessageKey ] = "Sie wurden automatisch abgemeldet, da Ihre Session abgelaufen ist." ;
}
return Logout ( ) ;
2018-12-10 23:40:38 -04:00
}
2018-12-12 14:27:40 -04:00
2025-06-27 13:11:10 +02:00
if ( ! Model . SessionInitialized )
2025-06-11 22:56:25 +02:00
{
Model . SessionInitialized = true ;
var mokSessionTimeout = UserSettingsUtils . GetSettingValueAsInteger ( Model . Mandator . Settings , SettingsKeys . MoKSessionTimeout , 20 ) ;
2024-06-05 14:45:33 +02:00
2025-06-11 22:56:25 +02:00
Session . Timeout = mokSessionTimeout ;
2019-07-19 17:13:57 +02:00
2025-06-11 22:56:25 +02:00
Model . IsPasswordSecurityEnabled = UserSettingsUtils . GetSettingValueAsBool ( Model . Mandator . Settings , SettingsKeys . IsPasswordSecurityActiv ) ;
2020-04-02 13:19:14 +02:00
2025-06-11 22:56:25 +02:00
if ( Model . IsPasswordSecurityEnabled )
2021-04-12 20:32:10 +02:00
{
2025-06-11 22:56:25 +02:00
var tempDataValue = string . Empty ;
2021-04-12 20:32:10 +02:00
2025-06-11 22:56:25 +02:00
switch ( MobileSessionFacade . PasswordStrength )
2021-04-12 20:32:10 +02:00
{
2025-06-11 22:56:25 +02:00
case 0 :
tempDataValue = "Sie benutzen ein sehr schwaches Passwort.<br><br>Bitte ändern Sie Ihr Passwort, indem Sie im Menü auf 'Password ändern' klicken." ;
break ;
case 1 :
tempDataValue = "Sie benutzen ein schwaches Passwort.<br><br>Bitte ändern Sie Ihr Passwort, indem Sie im Menü auf 'Password ändern' klicken." ;
break ;
2021-04-12 20:32:10 +02:00
}
2025-06-11 22:56:25 +02:00
if ( ! string . IsNullOrEmpty ( tempDataValue ) )
{
TempData [ TempDataConstants . ShowPwChPopupKey ] = tempDataValue ;
}
2021-04-12 20:32:10 +02:00
}
2019-07-19 17:13:57 +02:00
}
2016-06-27 01:45:38 +02:00
}
2022-08-10 14:13:29 +02:00
catch ( Exception e )
2016-06-27 01:45:38 +02:00
{
2020-01-15 16:14:39 +01:00
Log . Error ( e . Message , e ) ;
2016-06-27 01:45:38 +02:00
}
return View ( Model ) ;
}
2023-09-04 16:57:20 +02:00
[Authorize]
private void UpdateSettings ( string key , string value )
{
if ( Model is null )
{
return ;
}
2025-06-11 22:56:25 +02:00
var loggedInUser = LoggedInUser ;
2023-09-04 16:57:20 +02:00
if ( loggedInUser ? . UserOid is null )
{
return ;
}
var userSettings = loggedInUser . Settings ;
UserSettingsUtils . SetSettingValue ( SettingsType . ApplicationSettings , key , value , userSettings ) ;
UserService . UpdateUserSettings ( loggedInUser . UserOid . Value , userSettings ) ;
2022-12-30 16:28:23 +01:00
}
2024-09-12 14:55:35 +02:00
[HttpPost]
[Authorize]
public ActionResult SetShowExpiredSupportConcepts ( FormCollection pCollection )
{
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return Logout ( ) ;
}
var newValue = "true,false" = = pCollection [ FormCollectionConstants . ShowExpiredSupportConceptsKey ] ;
Model . ShowExpiredSupportConcepts = newValue ;
return UpdateApplicationSettings ( SettingsKeys . ShowExpiredSupportConcepts , newValue ? "1" : "0" ) ;
}
[HttpPost]
public new ActionResult Logout ( )
{
return base . Logout ( ) ;
}
2016-06-27 01:45:38 +02:00
[Authorize]
2021-06-16 15:11:39 +02:00
public string RateSelectedGoal ( long? ratingTypeOid , long? goalOid )
2016-06-27 01:45:38 +02:00
{
2025-06-11 22:56:25 +02:00
if ( Model is null | | ratingTypeOid is null | | goalOid is null | | ! Model . HasRightToRateGoals )
2020-04-02 13:19:14 +02:00
{
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2020-04-02 13:19:14 +02:00
}
2024-06-26 12:29:22 +02:00
var rating = Model . GoalRatingTypes . FirstOrDefault ( ratingType = > ratingType . RatingTypeOid = = ratingTypeOid ) ;
var allGoals = new List < ValueListEntryDC > ( ) ;
if ( Model . IsInGroupBookingMode )
2020-04-02 13:19:14 +02:00
{
2025-07-15 14:26:03 +02:00
var list = GetSelectedGroupBookingSupportConcepts ( ) ;
list . DoForEach ( sc = > { allGoals . AddRangeIfElementsNotIn ( sc . Goals ) ; } ) ;
2024-06-26 12:29:22 +02:00
}
else if ( ! Model . IsInGroupBookingMode )
{
allGoals = GetAllGoalsForSelectedSupportConcept ( ) ;
}
2020-04-02 13:19:14 +02:00
2024-06-26 12:29:22 +02:00
var goal = allGoals . FirstOrDefault ( g = > g . ValueListEntryOid ? . Equals ( goalOid . Value ) ? ? false ) ;
2024-09-12 14:55:35 +02:00
2024-06-26 12:29:22 +02:00
if ( goal ! = null )
{
if ( ! Model . SelectedGoals . Any ( a = > a . ValueListEntryOid . HasValue & & a . ValueListEntryOid . Value = = goal . ValueListEntryOid ) )
2022-08-10 14:13:29 +02:00
{
2025-07-15 14:26:03 +02:00
Model . SelectedGoals . AddIfNotIn ( DcToMokMapper . CreateZiel ( goal ) ) ;
2022-08-10 14:13:29 +02:00
}
2024-06-26 12:29:22 +02:00
goal . RatingTypeOid = ratingTypeOid ;
var selectedGoal = Model . SelectedGoals . FirstOrDefault ( a = > a . ValueListEntryOid . HasValue & & a . ValueListEntryOid . Value = = goal . ValueListEntryOid ) ;
if ( ! ( selectedGoal is null ) )
{
selectedGoal . RatingTypeOid = ratingTypeOid ;
}
2021-06-16 15:11:39 +02:00
}
2020-04-02 13:19:14 +02:00
2024-06-26 12:29:22 +02:00
return SerializeObject ( new GoalRating ( rating ? . DisplayName ? ? string . Empty , goal ? . ValueListEntryOid ? ? 0 ) ) ;
2021-06-16 15:11:39 +02:00
}
2020-04-02 13:19:14 +02:00
2025-07-15 14:26:03 +02:00
2022-12-30 16:28:23 +01:00
private List < ValueListEntryDC > _AllGoals ;
private List < ValueListEntryDC > GetAllGoalsForSelectedSupportConcept ( )
{
if ( Model ? . SelectedSupportConcept ? . Goals is null )
{
return new List < ValueListEntryDC > ( ) ;
}
if ( _AllGoals is null )
{
_AllGoals = new List < ValueListEntryDC > ( Model . SelectedSupportConcept . Goals ) ;
}
LoadParentGoals ( Model . SelectedSupportConcept . Goals ) ;
return _AllGoals ;
}
private void LoadParentGoals ( IEnumerable < ValueListEntryDC > goals )
{
var parentGoalOids = goals . Where ( goal = > goal . ParentOid . HasValue ) . Select ( goal = > goal . ParentOid . Value ) . Distinct ( ) . ToList ( ) ;
var parentGoals = CustomerService . GetSupportConceptGoalParents ( parentGoalOids ) ;
_AllGoals . AddRangeIfElementsNotIn ( parentGoals ) ;
var nextParentGoalOids = parentGoals . Where ( goal = > goal . ParentOid . HasValue ) . Select ( goal = > goal . ParentOid . Value ) . Distinct ( ) . ToList ( ) ;
if ( nextParentGoalOids . Any ( ) )
{
LoadParentGoals ( parentGoals ) ;
}
}
2025-06-11 22:56:25 +02:00
2025-07-15 14:26:03 +02:00
private void LoadGoals ( List < SupportConceptTreeNodeDetailInfoDC > infos )
2020-04-02 13:19:14 +02:00
{
2024-06-05 14:45:33 +02:00
try
2016-06-27 01:45:38 +02:00
{
2024-06-26 12:29:22 +02:00
2024-06-05 14:45:33 +02:00
var selectedGoals = new List < ValueListEntryDC > ( ) ;
2025-07-15 14:26:03 +02:00
foreach ( var item in infos )
2024-06-05 14:45:33 +02:00
{
2025-07-15 14:26:03 +02:00
selectedGoals . AddRange ( item . SupportConceptGoals ) ;
2024-06-05 14:45:33 +02:00
}
2016-06-27 01:45:38 +02:00
2025-07-15 14:26:03 +02:00
//if(Model.IsInGroupBookingMode)
//{
// var supportConcepts = GetSelectedGroupBookingSupportConcepts();
2016-06-27 01:45:38 +02:00
2025-07-15 14:26:03 +02:00
// supportConcepts.DoForEach(sc => { selectedGoals.AddRangeIfElementsNotIn(sc.Goals); });
//}
//else
//{
// if(Model.SelectedCostBearerSupportConceptOid is null)
// {
// return;
// }
2021-06-16 15:11:39 +02:00
2025-07-15 14:26:03 +02:00
// var supportConcept = Model.SupportConcepts.FirstOrDefault(sc => sc.CostBearerRelOids.Any(c2sOid => c2sOid.Equals(Model.SelectedCostBearerSupportConceptOid.Value)));
2016-06-27 01:45:38 +02:00
2025-07-15 14:26:03 +02:00
// if(supportConcept is null)
// {
// if (Model.SelectedCostBearerSupportConceptOid.Value > 0)
// {
// Log.Info($"Hilfeplan von Bewilligung mit Oid {Model.SelectedCostBearerSupportConceptOid} nicht gefunden beim Laden der Ziele (LoadGoals).");
// }
// return;
// }
// Model.SelectedSupportConcept = supportConcept;
// selectedGoals = supportConcept.Goals;
//}
2024-06-05 14:45:33 +02:00
var missingParents = selectedGoals . Where ( w = > w . ParentOid ! = null & & false = = selectedGoals . Any ( a = > a . ValueListEntryOid . Equals ( w . ParentOid ) ) ) . Select ( s = > s . ParentOid ) . ToList ( ) ;
_ParentGoals = new Dictionary < long , ValueListEntryDC > ( ) ;
foreach ( var oid in missingParents )
2022-08-10 14:13:29 +02:00
{
2024-06-05 14:45:33 +02:00
if ( oid . HasValue )
{
LoadMissingParents ( oid . Value ) ;
}
2022-08-10 14:13:29 +02:00
}
2016-06-27 01:45:38 +02:00
2024-06-05 14:45:33 +02:00
var allGoals = selectedGoals . Union ( _ParentGoals . Values ) . ToList ( ) ;
2025-06-11 22:56:25 +02:00
Model . AllGoals = allGoals ;
2025-07-15 14:26:03 +02:00
Model . GoalTree = BuildGoalTree ( Model . AllGoals ) ;
2024-06-05 14:45:33 +02:00
}
catch ( Exception exception )
{
Log . Error ( exception ) ;
}
2016-06-27 01:45:38 +02:00
}
2024-09-12 14:55:35 +02:00
2021-06-16 15:11:39 +02:00
private List < GoalTreeItem > BuildGoalTree ( IReadOnlyCollection < ValueListEntryDC > goals )
2016-06-27 01:45:38 +02:00
{
2025-01-31 15:15:40 +01:00
var ziele = goals . Where ( w = > _GoalTypes . Contains ( w . Type ) ) . OrderBy ( s = > s . DisplayName ) . ToList ( ) ;
var massnahmen = goals . Where ( w = > _MeasureTypes . Contains ( w . Type ) ) . OrderBy ( s = > s . DisplayName ) . ToList ( ) ;
2016-06-27 01:45:38 +02:00
var goalTree = new List < GoalTreeItem > ( ) ;
var goalTreeDic = new Dictionary < long , GoalTreeItem > ( ) ;
2024-07-24 16:45:56 +02:00
var goalsWithRating = Model . SelectedServiceRecord ? . Goals ? . Where ( goal = > goal . RatingTypeOid . HasValue ) . ToList ( ) ? ? new List < ValueListEntryDC > ( ) ;
2021-06-16 15:11:39 +02:00
var ratingTypes = OperationsService . GetRatingTypesByOids ( goalsWithRating . Where ( goal = > goal . RatingTypeOid . HasValue ) . Select ( goal = > goal . RatingTypeOid . Value ) . Distinct ( ) . ToList ( ) ) ;
2016-06-27 01:45:38 +02:00
2024-07-24 16:45:56 +02:00
foreach ( var ziel in ziele )
2016-06-27 01:45:38 +02:00
{
2024-07-24 16:45:56 +02:00
if ( ziel . ValueListEntryOid is null )
{
continue ;
}
2024-06-05 14:45:33 +02:00
var treeItem = new GoalTreeItem ( true , ziel . Type )
2024-02-20 14:42:04 +01:00
{
2024-09-12 14:55:35 +02:00
Children = new List < GoalTreeItem > ( ) ,
Header = ziel . DisplayName ? ? string . Empty ,
ParentOid = ziel . ParentOid ,
2024-02-20 14:42:04 +01:00
ValueListEntryOid = ziel . ValueListEntryOid
} ;
2024-09-12 14:55:35 +02:00
2020-04-02 13:19:14 +02:00
goalTreeDic . Add ( ziel . ValueListEntryOid . Value , treeItem ) ;
2016-06-27 01:45:38 +02:00
2022-08-10 14:13:29 +02:00
if ( ziel . ParentOid is null )
2016-06-27 01:45:38 +02:00
{
goalTree . Add ( treeItem ) ;
}
}
2021-03-17 18:44:40 +01:00
foreach ( var zielMitEltern in goalTreeDic . Values . Where ( zielMitEltern = > zielMitEltern . ParentOid ! = null ) )
2016-06-27 01:45:38 +02:00
{
2024-07-24 16:45:56 +02:00
if ( zielMitEltern . ParentOid is null )
{
continue ;
}
2016-06-27 01:45:38 +02:00
goalTreeDic [ zielMitEltern . ParentOid . Value ] . Children . Add ( zielMitEltern ) ;
}
2018-02-02 14:43:40 +01:00
foreach ( var ziel in massnahmen )
2016-06-27 01:45:38 +02:00
{
2021-06-16 15:11:39 +02:00
var ratingName = Model . HasAnyRatingTypes ? "Bewerten" : string . Empty ;
var goalWithRating = goalsWithRating . FirstOrDefault ( g = > g . ValueListEntryOid = = ziel . ValueListEntryOid ) ;
if ( Model . HasAnyRatingTypes & & Model . IsInEditingMode & & goalWithRating ! = null & & ratingTypes . Any ( ) )
{
var ratingType = ratingTypes . FirstOrDefault ( rt = > rt . RatingTypeOid = = goalWithRating . RatingTypeOid ) ;
if ( ratingType ! = null )
{
ratingName = ratingType . DisplayName ;
}
}
2024-06-05 14:45:33 +02:00
var kind = new GoalTreeItem ( false , ziel . Type )
2024-02-20 14:42:04 +01:00
{
2024-09-12 14:55:35 +02:00
Children = new List < GoalTreeItem > ( ) ,
Header = ziel . DisplayName ? ? string . Empty ,
IsLeaf = true ,
ValueListEntryOid = ziel . ValueListEntryOid ,
2024-02-20 14:42:04 +01:00
RatingName = ratingName ,
ParentOid = ziel . ParentOid
} ;
2023-01-26 12:55:56 +01:00
if ( ziel . ParentOid is null | | ! goalTreeDic . ContainsKey ( ziel . ParentOid . Value ) )
2016-06-27 01:45:38 +02:00
{
2023-01-26 12:55:56 +01:00
continue ;
2016-06-27 01:45:38 +02:00
}
2023-01-26 12:55:56 +01:00
kind . ParentOid = goalTreeDic [ ziel . ParentOid . Value ] . ParentOid ;
goalTreeDic [ ziel . ParentOid . Value ] . Children . Add ( kind ) ;
2016-06-27 01:45:38 +02:00
}
2024-07-24 16:45:56 +02:00
foreach ( var item in goalTreeDic . Values . Where ( item = > item . Children . Count = = 0 ) )
2020-04-02 13:19:14 +02:00
{
2024-07-24 16:45:56 +02:00
item . IsLeaf = true ;
2020-04-02 13:19:14 +02:00
}
2022-08-10 14:13:29 +02:00
goalTree = goalTree . OrderBy ( o = > o . ValueListEntryOid ) . ToList ( ) ;
foreach ( var item in goalTree )
{
SortGoals ( item ) ;
}
2016-06-27 01:45:38 +02:00
return goalTree ;
}
2022-09-07 13:19:08 +02:00
private static void SortGoals ( GoalTreeItem goalTreeItem )
2022-08-10 14:13:29 +02:00
{
goalTreeItem . Children = goalTreeItem . Children . OrderBy ( s = > s . ValueListEntryOid ) . ToList ( ) ;
foreach ( var test in goalTreeItem . Children )
{
SortGoals ( test ) ;
}
}
2016-06-27 01:45:38 +02:00
private void LoadMissingParents ( long pParentOid )
{
2018-02-02 14:43:40 +01:00
while ( true )
2016-06-27 01:45:38 +02:00
{
var parentDC = ValueListService . GetValueListEntryByOid ( pParentOid ) ;
2024-07-24 16:45:56 +02:00
if ( parentDC ? . ValueListEntryOid is null )
{
continue ;
}
2018-02-02 14:43:40 +01:00
if ( ! _ParentGoals . ContainsKey ( parentDC . ValueListEntryOid . Value ) )
2016-06-27 01:45:38 +02:00
{
2018-01-29 12:57:10 +01:00
_ParentGoals . Add ( parentDC . ValueListEntryOid . Value , parentDC ) ;
2016-06-27 01:45:38 +02:00
2018-02-02 14:43:40 +01:00
if ( parentDC . ParentOid ! = null )
2016-06-27 01:45:38 +02:00
{
pParentOid = parentDC . ParentOid . Value ;
continue ;
}
}
break ;
}
}
2025-06-11 22:56:25 +02:00
2024-09-12 14:55:35 +02:00
2018-01-29 12:57:10 +01:00
[Authorize]
2016-06-27 01:45:38 +02:00
public string LoadStatistics ( long oid )
{
try
{
2022-08-10 14:13:29 +02:00
if ( Model is null )
2016-06-27 01:45:38 +02:00
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
2021-05-17 14:01:06 +02:00
var isLoaded = false ;
foreach ( var supportConcept in Model . SupportConcepts )
{
2025-07-15 14:26:03 +02:00
if ( supportConcept . CostBearerRelOids . Any ( c2sOid = > c2sOid = = oid ) )
2021-05-17 14:01:06 +02:00
{
isLoaded = true ;
}
if ( isLoaded )
{
break ;
}
}
if ( ! isLoaded )
{
return null ;
}
2021-04-13 19:45:21 +02:00
var statisticsInfo = OperationsService . GetServiceRecordStatisticInfo ( oid , DateTime . Now ) ;
2016-06-27 01:45:38 +02:00
2021-04-13 19:45:21 +02:00
var supportConceptStatisticsData = new SupportConceptStatisticsData ( ) ;
if ( statisticsInfo ! = null )
2019-09-17 17:44:57 +02:00
{
2021-04-13 19:45:21 +02:00
var count = 0 ;
supportConceptStatisticsData . ShowDiagram = false ;
foreach ( var period in statisticsInfo . PeriodStatisticInfos )
{
var statisticPeriod = new StatisticPeriod ( ) ;
for ( var i = 0 ; i < period . LeftValues . Length ; i + + )
{
var skipFirstHeader = count > 0 & & i = = 0 ;
var left = period . LeftValues [ i ] ? ? string . Empty ;
var right = period . RightValues [ i ] ? ? string . Empty ;
var seperator = ! string . IsNullOrWhiteSpace ( left ) & & ! string . IsNullOrWhiteSpace ( right ) ? "/" : string . Empty ;
var value = $"{left}{seperator}{right}" ;
2019-09-17 17:44:57 +02:00
2021-04-13 19:45:21 +02:00
var header = skipFirstHeader ? value : statisticsInfo . Header [ i ] ;
value = header = = value ? string . Empty : value ;
statisticPeriod . Header2Values . AddIfNotIn ( new Header2Values ( header , value ) ) ;
}
supportConceptStatisticsData . StatisticPeriods . Add ( statisticPeriod ) ;
count + + ;
}
2019-09-17 17:44:57 +02:00
}
2021-04-13 19:45:21 +02:00
else
{
var supportConceptStatistics = OperationsService . CreateSupportConceptStatistics ( oid , DateTime . Now ) ;
var provided = supportConceptStatistics . MinutesProvidedThisWeek / 60 ;
var approved = supportConceptStatistics . MinutesApprovedPerWeek / 60 ;
var freePerWeek = supportConceptStatistics . MinutesFreePerWeekAverage / 60 ;
var providedTotal = supportConceptStatistics . MinutesProvidedTotalRounded / 60 ;
var approvedTotal = supportConceptStatistics . MinutesApprovedTotal / 60 ;
2021-04-28 12:51:55 +02:00
var freePerWeekTotal = ( approvedTotal - providedTotal ) ;
2021-04-13 19:45:21 +02:00
decimal percentage = 0 ;
if ( approvedTotal > 0 )
{
percentage = providedTotal / approvedTotal * 100 ;
}
if ( percentage > 100 )
{
percentage = 100 ;
}
supportConceptStatisticsData . Percentage = percentage ;
var statisticPeriod = new StatisticPeriod ( ) ;
2021-10-15 19:18:15 +02:00
if ( supportConceptStatistics . PeriodStatistics . Count ! = 1 )
{
statisticPeriod . Header2Values . AddIfNotIn ( new Header2Values ( "Bewilligungszeitraum:" , "Gesamt" ) ) ;
statisticPeriod . Header2Values . AddIfNotIn ( new Header2Values ( "Geleistet diese Woche/gesamt:" , $"{provided:0.00}/{providedTotal:0.00}" ) ) ;
statisticPeriod . Header2Values . AddIfNotIn ( new Header2Values ( "Bewilligt pro Woche/gesamt:" , $"{approved:0.00}/{approvedTotal:0.00}" ) ) ;
statisticPeriod . Header2Values . AddIfNotIn ( new Header2Values ( "Frei pro Woche(Ø)/gesamt:" , $"{freePerWeek:0.00}/{freePerWeekTotal:0.00}" ) ) ;
2021-04-13 19:45:21 +02:00
2021-10-15 19:18:15 +02:00
supportConceptStatisticsData . StatisticPeriods . Add ( statisticPeriod ) ;
}
2021-04-13 19:45:21 +02:00
foreach ( var periodStatistics in supportConceptStatistics . PeriodStatistics )
{
provided = periodStatistics . MinutesProvidedThisWeek / 60 ;
approved = periodStatistics . MinutesApprovedPerWeek / 60 ;
freePerWeek = periodStatistics . MinutesFreePerWeek / 60 ;
2021-04-08 19:21:14 +02:00
2021-04-13 19:45:21 +02:00
providedTotal = periodStatistics . MinutesProvidedTotalRounded / 60 ;
approvedTotal = periodStatistics . MinutesApprovedTotal / 60 ;
2021-04-28 12:51:55 +02:00
freePerWeekTotal = ( approvedTotal - providedTotal ) ;
2021-04-13 19:45:21 +02:00
2021-04-29 15:11:56 +02:00
var supportConceptApprovalPeriodSpan = periodStatistics . SupportConceptApprovalPeriod . Span ;
2021-04-29 15:33:01 +02:00
var minVal = DateTime . Now . AddYears ( - 50 ) ;
var maxVal = DateTime . Now . AddYears ( 50 ) ;
2021-04-29 15:11:56 +02:00
var sd = supportConceptApprovalPeriodSpan . StartDate ;
var ed = supportConceptApprovalPeriodSpan . EndDate ;
2021-04-29 15:33:01 +02:00
var start = sd > minVal & & sd < maxVal ? $"{sd:dd.MM.yy} " : string . Empty ;
var end = ed > minVal & & ed < maxVal ? $" {ed:dd.MM.yy}" : string . Empty ;
2021-04-29 15:11:56 +02:00
2021-04-29 15:33:01 +02:00
var span = $"{start}-{end}" ;
2021-04-28 12:51:55 +02:00
var serviceCategoryName = periodStatistics . SupportConceptApprovalPeriod . ServiceCategory ! = null ? periodStatistics . SupportConceptApprovalPeriod . ServiceCategory . Name + ":" : "Bewilligungszeitraum:" ;
2021-04-13 19:45:21 +02:00
statisticPeriod = new StatisticPeriod ( ) ;
statisticPeriod . Header2Values . AddIfNotIn ( new Header2Values ( serviceCategoryName , span ) ) ;
statisticPeriod . Header2Values . AddIfNotIn ( new Header2Values ( "Geleistet diese Woche/gesamt:" , $"{provided:0.00}/{providedTotal:0.00}" ) ) ;
statisticPeriod . Header2Values . AddIfNotIn ( new Header2Values ( "Bewilligt pro Woche/gesamt:" , $"{approved:0.00}/{approvedTotal:0.00}" ) ) ;
statisticPeriod . Header2Values . AddIfNotIn ( new Header2Values ( "Frei pro Woche(Ø)/gesamt:" , $"{freePerWeek:0.00}/{freePerWeekTotal:0.00}" ) ) ;
supportConceptStatisticsData . StatisticPeriods . Add ( statisticPeriod ) ;
}
}
return SerializeObject ( supportConceptStatisticsData ) ;
2016-06-27 01:45:38 +02:00
}
catch ( Exception e )
{
2020-01-15 16:14:39 +01:00
Log . Error ( e . Message , e ) ;
2016-06-27 01:45:38 +02:00
return SerializeObject ( "Fehler 560" ) ;
}
}
[Authorize]
2025-01-17 16:21:58 +01:00
public ActionResult SaveSignature ( FormCollection formCollection )
2016-06-27 01:45:38 +02:00
{
2025-07-04 00:30:36 +02:00
try
2016-06-27 01:45:38 +02:00
{
2025-07-04 00:30:36 +02:00
var blob = formCollection [ FormCollectionConstants . ServiceRecordSignatureBlobKey ] ;
var date = DateTime . Parse ( formCollection [ FormCollectionConstants . ServiceRecordSignatureDateKey ] ) ;
long . TryParse ( formCollection [ FormCollectionConstants . ServiceRecordSignatureRecordOidKey ] , out var serviceRecordOid ) ;
2025-01-17 16:21:58 +01:00
2025-07-04 00:30:36 +02:00
var serviceRecord = Model . ServiceRecords . FirstOrDefault ( sr = > sr . ServiceRecordOid . HasValue & & sr . ServiceRecordOid . Value . Equals ( serviceRecordOid ) ) ;
if ( serviceRecordOid < 1 | | serviceRecord is null )
2025-01-17 16:21:58 +01:00
{
2025-07-04 00:30:36 +02:00
var message2Log = string . Empty ;
2016-06-27 01:45:38 +02:00
2025-07-04 00:30:36 +02:00
if ( serviceRecordOid < 1 )
{
message2Log = $"Einzelunterschrift konnte nicht gespeichert werden, da die ServiceRecordOid {serviceRecordOid} ungültig ist." ;
}
else if ( serviceRecord is null )
{
message2Log = "Einzelunterschrift konnte nicht gespeichert werden, da der Zeiterfassungseintrag im Model nicht gefunden werden konnte." ;
}
2024-01-12 17:16:52 +01:00
2025-07-04 00:30:36 +02:00
Log . Error ( message2Log ) ;
2019-11-21 19:39:32 +01:00
2025-07-04 00:30:36 +02:00
TempData [ TempDataConstants . ErrorMessageKey ] = "Beim Speichern der Unterschrift ist ein Fehler aufgetreten. Bitte wenden Sie sich an Ihren Administrator." ;
return RedirectToActionPermanent ( "Main" , "Main" ) ;
}
2016-06-27 01:45:38 +02:00
2025-07-04 00:30:36 +02:00
long? oid ;
2020-04-02 13:19:14 +02:00
2025-07-04 00:30:36 +02:00
using ( var signatureBitmap = SignatureUtils . Base64StringToBitmap ( blob . Split ( ',' ) [ 1 ] ) )
2025-01-17 16:21:58 +01:00
{
2025-07-04 00:30:36 +02:00
var isValid = SignatureUtils . ValidateSignature ( signatureBitmap ) ;
if ( ! isValid )
{
TempData [ TempDataConstants . ErrorMessageKey ] = "Das Unterschriftenfeld darf nicht leer sein." ;
return RedirectToActionPermanent ( "Main" , "Main" ) ;
}
oid = OperationsService . InsertSignature ( new SignatureDC
{
DataBild = blob ,
Zeitstempel = date ,
ServiceRecordOid = serviceRecordOid
} ) . SignatureOid ;
2020-04-02 13:19:14 +02:00
}
2018-12-13 20:59:05 -04:00
2025-07-04 00:30:36 +02:00
if ( oid is null )
2025-01-17 16:21:58 +01:00
{
2025-07-04 00:30:36 +02:00
TempData [ TempDataConstants . ErrorMessageKey ] = "Beim Speichern der Unterschrift ist ein Fehler aufgetreten. Bitte wenden Sie sich an Ihren Administrator." ;
}
else
{
TempData [ TempDataConstants . InfoMessageKey ] = $"Die Unterschrift von {serviceRecord.Customer} für den Eintrag vom {MainModel.GetServiceRecordTimeHeader(serviceRecord, false)} wurde erfolgreich gespeichert." ;
}
2016-06-27 01:45:38 +02:00
}
2025-07-04 00:30:36 +02:00
catch ( Exception ex )
2025-01-17 16:21:58 +01:00
{
2025-07-04 00:30:36 +02:00
Log . Error ( "Fehler beim Speichern der Einzelunterschrift: " + ex . Message , ex ) ;
2025-01-17 16:21:58 +01:00
}
2025-07-04 00:30:36 +02:00
2025-01-17 16:21:58 +01:00
return RedirectToActionPermanent ( "Main" , "Main" ) ;
2020-04-02 13:19:14 +02:00
}
2019-11-21 19:39:32 +01:00
2021-05-17 14:01:06 +02:00
[Authorize]
2021-02-17 16:59:26 +01:00
public static string ApplyWatermark ( string blob , string watermarkImagePath )
2020-04-02 13:19:14 +02:00
{
2021-02-17 16:59:26 +01:00
if ( string . IsNullOrWhiteSpace ( blob ) )
2019-11-21 19:39:32 +01:00
{
2021-02-17 16:59:26 +01:00
return null ;
2019-11-21 19:39:32 +01:00
}
2021-02-17 16:59:26 +01:00
var watermarkImage = Image . FromFile ( watermarkImagePath ) ;
2019-11-21 19:39:32 +01:00
2021-02-17 16:59:26 +01:00
var signatureImage = SignatureUtils . Base64StringToBitmap ( blob ) ;
2019-11-21 19:39:32 +01:00
2021-02-17 16:59:26 +01:00
var hasTransparentBackground = SignatureUtils . HasTransparentBackground ( blob ) ;
2019-11-21 19:39:32 +01:00
2021-02-17 16:59:26 +01:00
if ( hasTransparentBackground )
2019-11-21 19:39:32 +01:00
{
2020-04-02 13:19:14 +02:00
signatureImage = SignatureUtils . AddBackgroundToBitmap ( signatureImage , Color . White ) ;
2019-11-21 19:39:32 +01:00
}
2020-04-02 13:19:14 +02:00
var watermarker = new Watermarker ( signatureImage ) ;
2019-11-21 19:39:32 +01:00
2020-04-02 13:19:14 +02:00
for ( var y = 0 ; y < signatureImage . Height ; y + + )
2016-06-27 01:45:38 +02:00
{
2021-02-17 16:59:26 +01:00
for ( var x = 0 ; x < signatureImage . Width ; x + + )
2016-06-27 01:45:38 +02:00
{
2020-04-02 13:19:14 +02:00
watermarker . Position = WatermarkPosition . Absolute ;
watermarker . PositionX = x ;
watermarker . PositionY = y ;
watermarker . Margin = new Padding ( 20 ) ;
watermarker . Opacity = . 1f ;
watermarker . TransparentColor = Color . White ;
watermarker . DrawImage ( watermarkImage ) ;
x + = watermarkImage . Width ;
2016-06-27 01:45:38 +02:00
}
2018-11-30 16:47:57 -04:00
2020-04-02 13:19:14 +02:00
y + = watermarkImage . Height ;
2016-06-27 01:45:38 +02:00
}
2020-04-02 13:19:14 +02:00
2021-02-17 16:59:26 +01:00
return "data:image/png;base64," + SignatureUtils . ConvertImageToBase64String ( watermarker . Image ) ;
2016-06-27 01:45:38 +02:00
}
2018-01-29 12:57:10 +01:00
[Authorize]
2022-08-19 13:53:32 +02:00
public string LoadCompleteTextbausteinByOid ( long pTextbausteinOid )
2017-04-26 14:57:32 +02:00
{
2022-08-19 13:53:32 +02:00
if ( Model is null )
2018-12-10 23:40:38 -04:00
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2018-12-10 23:40:38 -04:00
}
2022-08-19 13:53:32 +02:00
var textModule = Model . AllTextModules . FirstOrDefault ( f = > f . Oid = = pTextbausteinOid ) ;
return textModule is null ? null : string . IsNullOrWhiteSpace ( textModule . Text ) ? textModule . Name : textModule . Text ;
}
[Authorize]
public ActionResult LoadUpToDateTextModules ( )
{
2025-07-15 14:26:03 +02:00
if ( ! IsUserLoggedIn ( ) )
2017-04-26 14:57:32 +02:00
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return PartialView ( "TextModulePartial" ) ;
2022-08-19 13:53:32 +02:00
}
2025-07-15 14:26:03 +02:00
2025-06-11 22:56:25 +02:00
//Wird alles im InitViewModel gemacht:
2022-08-19 13:53:32 +02:00
2025-06-11 22:56:25 +02:00
//Model.TextModules.Clear();
2022-08-19 13:53:32 +02:00
2025-06-11 22:56:25 +02:00
//if(Model.SelectedServiceCategoryOid.HasValue && (Model.LoggedInEmployee?.EmployeeOid.HasValue ?? false))
//{
// var allTextModules = OperationsService.GetTextModules(Model.HasRightToSeeGlobalTextModules, Model.LoggedInEmployee.EmployeeOid.Value, Model.HasRightToSeeGlobalTextModules, false);
2022-08-19 13:53:32 +02:00
2025-06-11 22:56:25 +02:00
// foreach(var tm in allTextModules.Where(textModule => textModule.IsParent == false))
// {
// if(string.IsNullOrWhiteSpace(tm.Text))
// {
// tm.Text = tm.Name;
// }
// }
2020-02-10 12:02:59 +01:00
2025-06-11 22:56:25 +02:00
// Model.AllTextModules = allTextModules.Where(tb => tb.TextModuleOid.HasValue).Select(tb => new TextbausteinDisplayItem(tb.Name, tb.Text, tb.Parent?.TextModuleOid, tb.TextModuleOid.Value, tb.IsExpanded)).ToList();
2017-04-26 14:57:32 +02:00
2025-06-11 22:56:25 +02:00
// var x = allTextModules.Where(
// w => (w.ServiceCategory is null || w.ServiceCategory.ServiceCategoryOid == Model.SelectedServiceCategoryOid.Value)
// && !string.IsNullOrEmpty(w.Text)
// && (w.IsOnlyForEmployee && w.Employee.EmployeeOid.Equals(Model.LoggedInEmployee.EmployeeOid) || !w.IsOnlyForEmployee)).OrderBy(t => t.Text).ToList();
2018-01-31 17:52:28 +01:00
2025-06-11 22:56:25 +02:00
// x.AddRangeIfElementsNotIn(BS.Shared.Core.Utils.GetParentTextModules(x));
2020-11-09 17:55:01 +01:00
2025-06-11 22:56:25 +02:00
// var textModuleDisplayItems = x.Where(tb => tb.TextModuleOid.HasValue).Select(tb => new TextbausteinDisplayItem(tb.Name, tb.Text, tb.Parent?.TextModuleOid, tb.TextModuleOid.Value, tb.IsExpanded)).ToList();
2022-08-19 13:53:32 +02:00
2025-06-11 22:56:25 +02:00
// foreach(var item in textModuleDisplayItems)
// {
// if(item.ParentOid is null)
// {
// continue;
// }
2023-03-29 15:49:20 +02:00
2025-06-11 22:56:25 +02:00
// var parent = textModuleDisplayItems.FirstOrDefault(p => p.Oid == item.ParentOid);
2023-03-29 15:49:20 +02:00
2025-06-11 22:56:25 +02:00
// parent?.Children.AddIfNotIn(item);
// }
2020-11-20 23:28:09 +01:00
2025-06-11 22:56:25 +02:00
// Model.TextModules = textModuleDisplayItems.Where(item => item.ParentOid is null).OrderBy(item => item.Name).ToList();
//}
2018-12-10 23:40:38 -04:00
2022-08-19 13:53:32 +02:00
return PartialView ( "TextModulePartial" , Model ) ;
2017-04-26 14:57:32 +02:00
}
2016-06-27 01:45:38 +02:00
2020-04-08 14:44:20 +02:00
[HttpPost]
[Authorize]
public ActionResult CreateOrUpdateServiceRecord ( FormCollection collection )
{
try
{
2022-08-10 14:13:29 +02:00
if ( Model is null )
2020-04-08 14:44:20 +02:00
{
2025-06-11 22:56:25 +02:00
Log . Info ( $"Model ist null bei CreateOrUpdateServiceRecord; User: {LoggedInUser.UserOid} {LoggedInUser.LoginName} ({LoggedInUser.Employee})" ) ;
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2020-10-07 19:42:17 +02:00
return Logout ( ) ;
2020-04-08 14:44:20 +02:00
}
2024-03-14 17:18:35 +01:00
// Falls ein Termin in die Zeiterfassung übernommen werden soll
2025-06-11 22:56:25 +02:00
SchedulerAppointmentDC appointmentPrototype = null ;
2023-03-03 21:54:36 +01:00
2025-06-27 13:11:10 +02:00
if ( Model . TransferringAppointmentOid . HasValue & & Model . LoggedInEmployee . EmployeeOid . HasValue )
2023-03-03 21:54:36 +01:00
{
2025-06-27 13:11:10 +02:00
var app = DAOFactory . GenericDAO . LoadByID < SchedulerAppointment > ( Model . TransferringAppointmentOid . Value ) ;
2025-06-11 22:56:25 +02:00
appointmentPrototype = MapperFactory . SchedulerAppointmentDCSchedulerAppointment . MapToNewDC ( app ) ;
2023-03-03 21:54:36 +01:00
}
2023-07-31 15:29:16 +02:00
var marker = "on" = = collection [ FormCollectionConstants . MarkerKey ] ;
2020-04-08 14:44:20 +02:00
string doku1 ;
2020-11-09 17:55:01 +01:00
if ( Model . Dokutypes ! = null & & Model . Dokutypes . Length > 0 )
2020-04-08 14:44:20 +02:00
{
2020-09-21 11:57:10 +02:00
doku1 = collection [ FormCollectionConstants . Dokumentation1Key ] ;
2020-04-08 14:44:20 +02:00
}
else
{
2020-09-21 11:57:10 +02:00
doku1 = collection [ FormCollectionConstants . Dokumentation6Key ] ;
2020-04-08 14:44:20 +02:00
}
2024-09-12 14:55:35 +02:00
decimal? betrag = null ;
var betragAsString = collection [ FormCollectionConstants . BetragKey ] ? . Replace ( '.' , ',' ) ;
if ( decimal . TryParse ( betragAsString , out var betragAsDecimal ) )
{
betrag = betragAsDecimal ;
}
2025-07-04 00:30:36 +02:00
Log . Info ( $"CreateOrUpdateServiceRecord: datum:{collection[FormCollectionConstants.DateKey]}; start:{collection[FormCollectionConstants.StartKey]}; ende:{collection[FormCollectionConstants.EndKey]}; dauer:{collection[FormCollectionConstants.DurationKey]}; aktion:{(Model.IsInEditingMode ? " Speichern " : " Anlegen ")}" ) ;
2020-04-08 14:44:20 +02:00
2020-09-21 11:57:10 +02:00
if ( string . IsNullOrEmpty ( collection [ FormCollectionConstants . DateKey ] ) )
2020-04-08 14:44:20 +02:00
{
2025-05-21 19:34:42 +02:00
Log . Info ( $"CreateOrUpdateServiceRecord: Das Startdatum ist null. Breche das {(Model.IsInEditingMode ? " Speichern " : " Anlegen ")} ab." ) ;
2020-04-08 14:44:20 +02:00
return View ( "Main" , Model ) ;
}
2020-09-21 11:57:10 +02:00
var distanz = collection [ FormCollectionConstants . DistanceKey ] ;
2023-05-23 13:56:22 +02:00
decimal? distanceInMeters = null ;
2020-04-08 14:44:20 +02:00
if ( ! string . IsNullOrEmpty ( distanz ) )
{
2023-05-23 13:56:22 +02:00
if ( decimal . TryParse ( distanz , out var parsedDistance ) )
2020-04-08 14:44:20 +02:00
{
distanceInMeters = parsedDistance ;
}
}
2025-06-11 22:56:25 +02:00
var selectedCostbearerScRelOid = Model . SelectedCostBearerSupportConceptOid < 1 ? null : Model . SelectedCostBearerSupportConceptOid ;
2020-09-21 11:57:10 +02:00
var datum = Convert . ToDateTime ( collection [ FormCollectionConstants . DateKey ] ) ;
2020-04-08 14:44:20 +02:00
var enddatum = datum ;
2021-02-17 16:59:26 +01:00
var endDateString = collection [ FormCollectionConstants . EndDateKey ] ;
2024-03-19 19:10:13 +01:00
if ( endDateString ? . Length > 0 )
2021-02-17 16:59:26 +01:00
{
enddatum = Convert . ToDateTime ( endDateString ) ;
}
2020-09-21 11:57:10 +02:00
var start = collection [ FormCollectionConstants . StartKey ] ;
var ende = collection [ FormCollectionConstants . EndKey ] ;
2023-06-21 19:19:56 +02:00
var dauer = 0 m ;
2020-04-08 14:44:20 +02:00
if ( datum > enddatum )
{
enddatum = datum ;
}
2023-06-21 19:19:56 +02:00
var durationAsString = collection [ FormCollectionConstants . DurationKey ] ;
2024-03-14 17:18:35 +01:00
durationAsString = durationAsString ? . Replace ( '.' , ',' ) ;
2023-06-21 19:19:56 +02:00
if ( ! string . IsNullOrEmpty ( durationAsString ) )
2020-04-08 14:44:20 +02:00
{
2023-06-21 19:19:56 +02:00
decimal . TryParse ( durationAsString , out dauer ) ;
2020-04-08 14:44:20 +02:00
}
2023-06-12 17:27:53 +02:00
// Wenn die Dauer in Stunden ist
if ( Model . SelectedDurationUnit = = "Stunden" | | Model . EinheitZeiterfassung = = 1 )
{
2023-06-21 19:19:56 +02:00
dauer * = 60 m ;
2023-06-12 17:27:53 +02:00
}
2023-03-14 16:12:52 +01:00
var doku2 = collection [ FormCollectionConstants . Dokumentation2Key ] ? . RemoveUppercaseEsszett ( ) ;
var doku3 = collection [ FormCollectionConstants . Dokumentation3Key ] ? . RemoveUppercaseEsszett ( ) ;
var doku4 = collection [ FormCollectionConstants . Dokumentation4Key ] ? . RemoveUppercaseEsszett ( ) ;
var doku5 = collection [ FormCollectionConstants . Dokumentation5Key ] ? . RemoveUppercaseEsszett ( ) ;
2020-04-08 14:44:20 +02:00
var zeitenFeld = new DateTime [ 2 ] ;
if ( start = = string . Empty & & ende = = string . Empty )
{
zeitenFeld [ 0 ] = new DateTime ( datum . Year , datum . Month , datum . Day , 0 , 0 , 1 ) ;
if ( enddatum = = datum )
{
2023-06-21 19:19:56 +02:00
zeitenFeld [ 1 ] = new DateTime ( datum . Year , datum . Month , datum . Day , 0 , 0 , 1 ) . AddMinutes ( Convert . ToDouble ( dauer ) ) ;
2020-04-08 14:44:20 +02:00
}
else
{
2023-06-21 19:19:56 +02:00
zeitenFeld [ 1 ] = new DateTime ( enddatum . Year , enddatum . Month , enddatum . Day , 0 , 0 , 1 ) . AddMinutes ( Convert . ToDouble ( dauer ) ) ;
2020-04-08 14:44:20 +02:00
}
}
else
{
2023-06-21 19:19:56 +02:00
zeitenFeld = enddatum = = datum ? ConvertRecordTimes ( start , ende , datum , Convert . ToDouble ( dauer ) ) : ConvertRecordTimesWithEndDate ( start , ende , datum , enddatum , Convert . ToDouble ( dauer ) ) ;
2020-04-08 14:44:20 +02:00
}
if ( dauer = = 0 | | zeitenFeld [ 1 ] ! = zeitenFeld [ 0 ] )
{
dauer = ( int ) ( zeitenFeld [ 1 ] - zeitenFeld [ 0 ] ) . TotalMinutes ;
}
if ( Model . IsInEditingMode )
{
var selectedRecordOid = Model . SelectedServiceRecordOid ? ? Model . SelectedServiceRecord . ServiceRecordOid ;
2025-07-17 16:26:07 +02:00
Model . NewServiceRecord = GetServiceRecordDC ( selectedRecordOid . Value , false ) ;
2020-04-08 14:44:20 +02:00
}
2022-08-10 14:13:29 +02:00
if ( Model . NewServiceRecord is null )
2020-04-08 14:44:20 +02:00
{
2025-05-21 19:34:42 +02:00
Log . Info ( "CreateOrUpdateServiceRecord: NewServiceRecord ist null. Breche ab." ) ;
2020-04-08 14:44:20 +02:00
return RedirectToActionPermanent ( "Main" ) ;
}
Model . NewServiceRecord . IP = Request . UserHostAddress ;
2025-07-15 14:26:03 +02:00
Model . NewServiceRecord . Goals = CreateValueListEntriesFromMokZiele ( Model . SelectedGoals ) ;
2020-04-08 14:44:20 +02:00
Model . NewServiceRecord . Start = zeitenFeld [ 0 ] ;
Model . NewServiceRecord . End = zeitenFeld [ 1 ] ;
2024-09-12 14:55:35 +02:00
Model . NewServiceRecord . Betrag = betrag ;
2024-03-14 17:18:35 +01:00
Model . NewServiceRecord . ServiceRecordType = marker ? ServiceRecordTypeId . Content : ServiceRecordTypeId . DefaultActivity ;
2023-09-19 14:44:52 +02:00
Model . NewServiceRecord . DistanceInMeter = null ;
2023-05-23 13:56:22 +02:00
Model . NewServiceRecord . DistanceInMeterDecimal = distanceInMeters ;
2020-04-08 14:44:20 +02:00
2025-06-11 22:56:25 +02:00
if ( Model . LoggedInEmployee . EmployeeOid . HasValue )
2020-04-08 14:44:20 +02:00
{
if ( ! Model . IsInEditingMode )
{
2025-06-11 22:56:25 +02:00
Model . NewServiceRecord . Employee = Model . SelectedEmployee ? ? LoggedInUser . Employee ;
2020-04-08 14:44:20 +02:00
}
else
{
2022-09-07 13:19:08 +02:00
if ( ! ( Model . SelectedEmployee is null ) )
2020-04-08 14:44:20 +02:00
{
Model . NewServiceRecord . Employee = Model . SelectedEmployee ;
}
}
2025-07-17 16:26:07 +02:00
var sclo = Model . SupportConceptListObjects . FirstOrDefault ( a = > a . CostBearer2SupportConceptOid . Equals ( selectedCostbearerScRelOid ) ) ;
2020-04-08 14:44:20 +02:00
2025-07-16 12:38:01 +02:00
if ( ! ( sclo is null ) )
2020-04-08 14:44:20 +02:00
{
2025-07-17 16:26:07 +02:00
var sc = GetCompactSupportConcept ( sclo . SupportConceptOid ) ;
2025-07-16 12:38:01 +02:00
Model . NewServiceRecord . SupportConcept = sc ;
2025-07-15 14:26:03 +02:00
2020-04-08 14:44:20 +02:00
Model . NewServiceRecord . Customer = sc . Customer ;
2025-07-15 14:26:03 +02:00
var costBearer = sc . CostBearerList . FirstOrDefault ( ) ;
Model . NewServiceRecord . CostBearer = costBearer ? . Organisation ;
2020-04-08 14:44:20 +02:00
var intervall = Model . NewServiceRecord . CostBearer . ActualMinuteIntervall ;
if ( intervall > 0 )
{
Model . NewServiceRecord . RoundedDuration = dauer % intervall ! = 0 ? dauer + ( intervall - dauer % intervall ) : dauer ;
}
else
{
Model . NewServiceRecord . RoundedDuration = dauer ;
}
2024-06-26 12:29:22 +02:00
Model . NewServiceRecord . CostBearer2SupportConceptOid = selectedCostbearerScRelOid ;
2020-04-08 14:44:20 +02:00
}
else
{
Model . NewServiceRecord . RoundedDuration = dauer ;
}
}
2022-12-30 16:28:23 +01:00
Model . NewServiceRecord . DurationInStunden = Model . IsShowingDurationInHours ? ZeiterfassungsDauer . Stunden : ZeiterfassungsDauer . Minuten ;
2020-04-08 14:44:20 +02:00
Model . NewServiceRecord . ServiceRecordFormat = ServiceRecordFormate . OriginaleZeiterfassung ;
2022-12-30 16:28:23 +01:00
if ( Model . IsEndDateVisible )
{
Model . NewServiceRecord . ServiceRecordFormat = ServiceRecordFormate . ZeiterfassungMitEndDatum ;
}
2023-03-14 16:12:52 +01:00
Model . NewServiceRecord . Notice = string . IsNullOrEmpty ( doku1 ) ? null : doku1 ? . RemoveUppercaseEsszett ( ) ;
2020-04-08 14:44:20 +02:00
2023-03-14 16:12:52 +01:00
Model . NewServiceRecord . Notice2 = string . IsNullOrEmpty ( doku2 ) ? null : doku2 ? . RemoveUppercaseEsszett ( ) ;
Model . NewServiceRecord . Notice3 = string . IsNullOrEmpty ( doku3 ) ? null : doku3 ? . RemoveUppercaseEsszett ( ) ;
Model . NewServiceRecord . Notice4 = string . IsNullOrEmpty ( doku4 ) ? null : doku4 ? . RemoveUppercaseEsszett ( ) ;
Model . NewServiceRecord . Notice5 = string . IsNullOrEmpty ( doku5 ) ? null : doku5 ? . RemoveUppercaseEsszett ( ) ;
2020-04-08 14:44:20 +02:00
var serviceDescOid = 0L ;
2020-09-21 11:57:10 +02:00
if ( ! string . IsNullOrEmpty ( collection [ FormCollectionConstants . ServiceDescriptionKey ] ) )
2020-04-08 14:44:20 +02:00
{
2020-09-21 11:57:10 +02:00
serviceDescOid = Convert . ToInt64 ( collection [ FormCollectionConstants . ServiceDescriptionKey ] ) ;
2020-04-08 14:44:20 +02:00
}
else if ( Model . SelectedServiceDescriptionOid . HasValue )
{
serviceDescOid = Model . SelectedServiceDescriptionOid . Value ;
}
if ( serviceDescOid > 0 )
{
Model . NewServiceRecord . ServiceDescription = OperationsService . GetServiceDescription ( serviceDescOid ) ;
}
if ( Model . NewServiceRecord . RoundedDuration = = 0 )
{
Model . NewServiceRecord . RoundedDuration = dauer ;
}
Model . NewServiceRecord . IP = Request . UserHostAddress ;
Model . NewServiceRecord . InsertedOn = DateTime . Now ;
2025-06-11 22:56:25 +02:00
Model . NewServiceRecord . InsUser = MobileSessionFacade . EmployeeFullname ;
2020-04-08 14:44:20 +02:00
Model . NewServiceRecord . IsCreatedInMobileClient = true ;
2025-07-15 14:26:03 +02:00
if ( Model . IsInGroupBookingMode & & Model . GroupBookingSelectedCostBearerSupportConceptOids . Count > 1 )
2020-04-08 14:44:20 +02:00
{
return Model . NewServiceRecord . ServiceRecordOid . HasValue ? SaveGroupBooking ( ) : UpdateGroupBooking ( ) ;
}
if ( ! Model . IsInEditingMode )
{
var oidList = OperationsService . InsertNewServiceRecords ( new List < ServiceRecordDC > { Model . NewServiceRecord } ) ;
2025-06-11 22:56:25 +02:00
Model . LastCreatedServiceRecordOid = oidList [ 0 ] ;
2020-11-11 14:21:29 +01:00
2021-01-14 20:39:33 +01:00
if ( Model . NewServiceRecord . CostBearer ! = null & & Model . ShowSignature )
2020-11-11 14:21:29 +01:00
{
2023-03-03 21:54:36 +01:00
TempData [ TempDataConstants . ShowSignatureSuggestionPopup ] = true ;
}
2025-06-27 13:11:10 +02:00
if ( appointmentPrototype is object )
2023-03-03 21:54:36 +01:00
{
2025-06-11 22:56:25 +02:00
var isRecurring = ! ( appointmentPrototype . RecurrenceInfo is null ) ;
2023-03-03 21:54:36 +01:00
2025-06-11 22:56:25 +02:00
if ( isRecurring & & appointmentPrototype . Type ! = ( int ) AppointmentType . ChangedOccurrence )
2023-03-03 21:54:36 +01:00
{
2025-06-11 22:56:25 +02:00
var id = appointmentPrototype . RecurrenceIdReference ;
2023-03-03 21:54:36 +01:00
var recurrenceInfo = new RecurrenceInfo ( ) ;
2025-06-11 22:56:25 +02:00
recurrenceInfo . FromXml ( appointmentPrototype . RecurrenceInfo ) ;
2023-03-03 21:54:36 +01:00
var occurrenceCalculator = OccurrenceCalculator . CreateInstance ( recurrenceInfo ) ;
var pattern = StaticAppointmentFactory . CreateAppointment ( AppointmentType . Pattern ) ;
2025-06-11 22:56:25 +02:00
pattern . RecurrenceInfo . FromXml ( appointmentPrototype . RecurrenceInfo ) ;
2023-03-03 21:54:36 +01:00
pattern . Start = pattern . RecurrenceInfo . Start ;
pattern . End = pattern . RecurrenceInfo . End ;
2025-06-11 22:56:25 +02:00
var occurrence = occurrenceCalculator . CalcOccurrences ( new TimeInterval ( appointmentPrototype . StartDate . Value , appointmentPrototype . EndDate . Value ) , pattern ) . FirstOrDefault ( ) ;
2023-03-03 21:54:36 +01:00
if ( ! ( occurrence is null ) )
{
var index = occurrence . RecurrenceIndex ;
2025-06-11 22:56:25 +02:00
appointmentPrototype = SchedulerController . CloneAppointment ( appointmentPrototype , $"<RecurrenceInfo Id=\" { id } \ " Index=\"{index}\" />" , ( int ) AppointmentType . ChangedOccurrence ) ;
2023-03-03 21:54:36 +01:00
}
else
{
2025-06-11 22:56:25 +02:00
appointmentPrototype = null ;
2023-03-03 21:54:36 +01:00
}
}
2025-06-27 13:11:10 +02:00
if ( appointmentPrototype is object )
2023-03-03 21:54:36 +01:00
{
2025-06-11 22:56:25 +02:00
var serviceRecord = OperationsService . GetServiceRecordById ( Model . LastCreatedServiceRecordOid ) ;
2023-03-03 21:54:36 +01:00
2025-06-11 22:56:25 +02:00
appointmentPrototype . ServiceRecordList . AddIfNotIn ( serviceRecord ) ;
2023-03-03 21:54:36 +01:00
2025-06-11 22:56:25 +02:00
if ( appointmentPrototype . SchedulerAppointmentOid . HasValue )
2023-03-03 21:54:36 +01:00
{
2025-06-11 22:56:25 +02:00
KalenderService . UpdateSchedulerAppointments ( new List < SchedulerAppointmentDC > { appointmentPrototype } ) ;
2023-03-03 21:54:36 +01:00
}
else
{
2025-06-11 22:56:25 +02:00
KalenderService . InsertSchedulerAppointments ( new List < SchedulerAppointmentDC > { appointmentPrototype } ) ;
2023-03-03 21:54:36 +01:00
}
}
2020-11-11 14:21:29 +01:00
}
2020-04-08 14:44:20 +02:00
}
else
{
OperationsService . UpdateServiceRecords ( new List < ServiceRecordDC > { Model . NewServiceRecord } ) ;
}
2022-09-07 13:19:08 +02:00
if ( Model . SetStartTimeToEndTimeAfterSave )
{
var previousStartDate = Model . IsInEditingMode ? Model . SelectedServiceRecord ? . Start : Model . NewServiceRecord ? . Start ;
var previousEndDate = Model . IsInEditingMode ? Model . SelectedServiceRecord ? . End : Model . NewServiceRecord ? . End ;
if ( ! ( previousStartDate is null ) & & ! ( previousEndDate is null ) )
{
var duration = ( previousEndDate - previousStartDate ) . Value . TotalMinutes ;
Model . NewStartDate = previousEndDate ;
Model . NewEndDate = previousEndDate . Value . AddMinutes ( duration ) ;
}
}
2020-04-08 14:44:20 +02:00
Model . NewServiceRecord = new ServiceRecordDC ( ) ;
}
catch ( Exception e )
{
Log . Error ( e . Message , e ) ;
}
2025-06-17 13:06:29 +02:00
if ( ! Model . IsInGroupBookingMode & & ! Model . IsInMultiBookingMode )
{
//Setze den zuletzt ausgewählten HP zurück, sonst springt die Anzeige dorthin
Model . PreviouslySelectedCostbearer2SupportConceptOid = null ;
}
2020-04-08 14:44:20 +02:00
2025-06-17 13:06:29 +02:00
//Wenn nicht im Editing Mode, dann behalte die zuletzt ausgewählte Leistung bei, die im Reset zurückgesetzt wird
long? oldCatOid = null ;
long? oldDescOid = null ;
if ( ! Model . IsInEditingMode )
{
oldCatOid = Model . SelectedServiceCategoryOid ;
oldDescOid = Model . SelectedServiceDescriptionOid ;
}
2022-12-30 16:28:23 +01:00
ResetBookingMode ( Model . IsInGroupBookingMode ? BookingMode . GroupBookingMode : BookingMode . SingleBookingMode ) ;
2020-11-20 23:28:09 +01:00
2025-06-17 13:06:29 +02:00
var result = ResetEditingMode ( ) ;
if ( oldCatOid . HasValue & & oldDescOid . HasValue )
{
Model . SelectedServiceCategoryOid = oldCatOid ;
Model . SelectedServiceDescriptionOid = oldDescOid ;
}
return result ;
2020-04-08 14:44:20 +02:00
}
2025-07-15 14:26:03 +02:00
private List < ValueListEntryDC > CreateValueListEntriesFromMokZiele ( IList < MokZiel > ziele )
{
var vleList = new List < ValueListEntryDC > ( ) ;
foreach ( var ziel in ziele )
{
var vleDc = Model . AllGoals . FirstOrDefault ( g = > g . ValueListEntryOid = = ziel . ValueListEntryOid ) ;
if ( vleDc ! = null )
{
vleDc . RatingTypeOid = ziel . RatingTypeOid ;
vleList . Add ( vleDc ) ;
}
}
return vleList ;
}
2021-05-17 14:01:06 +02:00
[Authorize]
2018-04-27 14:11:21 +02:00
private ActionResult SaveGroupBooking ( )
2018-04-18 14:33:21 +02:00
{
2024-06-26 12:29:22 +02:00
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return Logout ( ) ;
}
2022-12-30 16:28:23 +01:00
var employeeCount = Model . GroupBookingSelectedEmployees . Count ;
2025-07-15 14:26:03 +02:00
var personCount = Model . GroupBookingSelectedCostBearerSupportConceptOids . Count ;
var cb2ScOids = Model . GroupBookingSelectedCostBearerSupportConceptOids ;
2018-04-18 14:33:21 +02:00
2020-04-02 13:19:14 +02:00
var list = CalculateGroupBookingDuration ( employeeCount , personCount , cb2ScOids ) ;
2018-04-27 14:11:21 +02:00
var newDCList = new List < ServiceRecordDC > ( ) ;
foreach ( var dc in list )
{
2022-12-30 16:28:23 +01:00
foreach ( var emp in Model . GroupBookingSelectedEmployees )
2018-04-27 14:11:21 +02:00
{
2022-12-30 16:28:23 +01:00
var newDC = CloneServiceRecord ( dc ) ;
2018-04-27 14:11:21 +02:00
newDC . Employee = emp ;
newDC . InsertedOn = DateTime . Now ;
newDCList . Add ( newDC ) ;
}
}
if ( newDCList . Count > 0 )
{
if ( newDCList . Count = = 1 )
{
OperationsService . InsertNewServiceRecords ( newDCList ) ;
}
else
{
var groupDC = new ServiceRecordGroupDC
{
EmployeeCount = employeeCount ,
CustomerCount = personCount ,
StartDate = Model . NewServiceRecord . Start ,
EndDate = Model . NewServiceRecord . End ,
2023-03-14 16:12:52 +01:00
Notice = Model . NewServiceRecord . Notice ? . RemoveUppercaseEsszett ( ) ,
Notice2 = Model . NewServiceRecord . Notice2 ? . RemoveUppercaseEsszett ( ) ,
Notice3 = Model . NewServiceRecord . Notice3 ? . RemoveUppercaseEsszett ( ) ,
Notice4 = Model . NewServiceRecord . Notice4 ? . RemoveUppercaseEsszett ( ) ,
Notice5 = Model . NewServiceRecord . Notice5 ? . RemoveUppercaseEsszett ( ) ,
2018-04-27 14:11:21 +02:00
ServiceRecordList = newDCList
} ;
if ( Model . NewServiceRecord . GroupRoundedDuration ! = null )
{
groupDC . RoundedDuration = Model . NewServiceRecord . GroupRoundedDuration . Value ;
}
2023-03-03 21:54:36 +01:00
groupDC = OperationsService . InsertNewServiceRecordGroup ( groupDC ) ;
var serviceRecords = groupDC . ServiceRecordList ;
2025-06-27 13:11:10 +02:00
if ( Model . TransferringAppointmentOid . HasValue & & Model . LoggedInEmployee . EmployeeOid . HasValue )
2023-03-03 21:54:36 +01:00
{
2025-06-27 13:11:10 +02:00
var app = DAOFactory . GenericDAO . LoadByID < SchedulerAppointment > ( Model . TransferringAppointmentOid . Value ) ;
2025-06-11 22:56:25 +02:00
var appointment = MapperFactory . SchedulerAppointmentDCSchedulerAppointment . MapToNewDC ( app ) ;
2023-03-03 21:54:36 +01:00
appointment . ServiceRecordList . AddRange ( serviceRecords ) ;
KalenderService . UpdateSchedulerAppointments ( new List < SchedulerAppointmentDC > { appointment } ) ;
}
2018-04-27 14:11:21 +02:00
}
}
2020-12-16 21:49:47 +01:00
return ResetEditingMode ( ) ;
2018-04-27 14:11:21 +02:00
}
2020-12-07 13:08:55 +01:00
2021-05-17 14:01:06 +02:00
[Authorize]
2018-04-27 14:11:21 +02:00
private ActionResult UpdateGroupBooking ( )
{
2024-06-26 12:29:22 +02:00
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2024-06-26 18:53:59 +02:00
return Logout ( ) ;
2024-06-26 12:29:22 +02:00
}
2018-04-27 14:11:21 +02:00
var dc = Model . SelectedServiceRecord ;
var group = OperationsService . GetServiceRecordGroup ( dc . GroupOid . Value ) ;
UpdateServiceRecordGroup ( group ) ;
2022-12-30 16:28:23 +01:00
var employeeCount = Model . GroupBookingSelectedEmployees . Count ;
2025-07-15 14:26:03 +02:00
var customerCount = Model . GroupBookingSelectedCostBearerSupportConceptOids . Count ;
2018-04-27 14:11:21 +02:00
group . EmployeeCount = employeeCount ;
group . CustomerCount = customerCount ;
var roundDuration = true ;
var minuteInterval = 0 ;
CompactOrganisationDC org = null ;
2020-04-02 13:19:14 +02:00
var cb2ScOids = new List < long > ( ) ;
2018-04-27 14:11:21 +02:00
2025-07-15 14:26:03 +02:00
foreach ( var scdc in GetSelectedGroupBookingSupportConcepts ( ) )
2018-04-27 14:11:21 +02:00
{
2025-07-15 14:26:03 +02:00
if ( scdc . CostBearerRelOids . Count > 0 )
2018-04-27 14:11:21 +02:00
{
2025-07-15 14:26:03 +02:00
cb2ScOids . Add ( scdc . CostBearerRelOids [ 0 ] ) ;
2018-04-27 14:11:21 +02:00
2025-07-15 14:26:03 +02:00
if ( org is null )
2018-04-27 14:11:21 +02:00
{
2025-07-15 14:26:03 +02:00
org = scdc . CostBearerList [ 0 ] . Organisation ;
2018-04-27 14:11:21 +02:00
if ( org ! = null )
{
minuteInterval = org . ActualMinuteIntervall ;
}
}
else
{
2025-07-15 14:26:03 +02:00
if ( scdc . CostBearerList [ 0 ] is null | | ! org . Equals ( scdc . CostBearerList [ 0 ] . Organisation ) )
2018-04-27 14:11:21 +02:00
{
roundDuration = false ;
}
}
}
}
var duration = ( decimal ) ( Model . NewServiceRecord . End . Value - Model . NewServiceRecord . Start . Value ) . TotalMinutes ;
var lRoundedDuration = duration ;
decimal groupDuration ;
decimal roundedDuration ;
2020-04-02 13:19:14 +02:00
var gd = OperationsService . CalculateGroupDuration2 ( customerCount , employeeCount , duration , cb2ScOids . ToArray ( ) ) ;
2018-04-27 14:11:21 +02:00
if ( gd ! = null )
{
groupDuration = gd . TotalDuration ;
roundedDuration = gd . SingleDuration ;
}
else
{
if ( minuteInterval > 0 & & roundDuration )
{
lRoundedDuration = duration % minuteInterval ! = 0 ? duration + ( minuteInterval - duration % minuteInterval ) : duration ;
}
groupDuration = lRoundedDuration ;
2025-07-15 14:26:03 +02:00
roundedDuration = Math . Round ( groupDuration / Model . GroupBookingSelectedCostBearerSupportConceptOids . Count , 0 , MidpointRounding . AwayFromZero ) ;
2018-04-27 14:11:21 +02:00
}
Model . NewServiceRecord . RoundedDuration = roundedDuration ;
Model . NewServiceRecord . GroupRoundedDuration = groupDuration ;
2023-03-14 16:12:52 +01:00
group . Notice = Model . NewServiceRecord . Notice ? . RemoveUppercaseEsszett ( ) ;
group . Notice2 = Model . NewServiceRecord . Notice2 ? . RemoveUppercaseEsszett ( ) ;
group . Notice3 = Model . NewServiceRecord . Notice3 ? . RemoveUppercaseEsszett ( ) ;
group . Notice4 = Model . NewServiceRecord . Notice4 ? . RemoveUppercaseEsszett ( ) ;
group . Notice5 = Model . NewServiceRecord . Notice5 ? . RemoveUppercaseEsszett ( ) ;
2018-04-27 14:11:21 +02:00
group . RoundedDuration = groupDuration ;
group . StartDate = Model . NewServiceRecord . Start ;
group . EndDate = Model . NewServiceRecord . End ;
foreach ( var item in group . ServiceRecordList )
{
2024-06-26 12:29:22 +02:00
item . Goals = Model . NewServiceRecord . Goals ;
2023-03-14 16:12:52 +01:00
item . Notice = Model . NewServiceRecord . Notice ? . RemoveUppercaseEsszett ( ) ;
item . Notice2 = Model . NewServiceRecord . Notice2 ? . RemoveUppercaseEsszett ( ) ;
item . Notice3 = Model . NewServiceRecord . Notice3 ? . RemoveUppercaseEsszett ( ) ;
item . Notice4 = Model . NewServiceRecord . Notice4 ? . RemoveUppercaseEsszett ( ) ;
item . Notice5 = Model . NewServiceRecord . Notice5 ? . RemoveUppercaseEsszett ( ) ;
2018-04-27 14:11:21 +02:00
item . End = Model . NewServiceRecord . End ;
item . Start = Model . NewServiceRecord . Start ;
item . RoundedDuration = roundedDuration ;
2023-05-23 13:56:22 +02:00
item . DistanceInMeterDecimal = Model . NewServiceRecord . DistanceInMeterDecimal ;
2018-04-27 14:11:21 +02:00
item . ServiceDescription = Model . NewServiceRecord . ServiceDescription ;
item . ServiceRecordFormat = Model . NewServiceRecord . ServiceRecordFormat ;
item . DurationInStunden = Model . NewServiceRecord . DurationInStunden ;
item . ServiceDescription = item . ServiceDescription ? ? Model . NewServiceRecord . ServiceDescription ;
item . GroupEmployeeCount = group . EmployeeCount ;
item . GroupPersonCount = group . CustomerCount ;
item . GroupOid = Model . NewServiceRecord . GroupOid ;
item . GroupRoundedDuration = groupDuration ;
2024-09-12 14:55:35 +02:00
item . Betrag = Model . NewServiceRecord . Betrag ;
2018-04-27 14:11:21 +02:00
2022-08-10 14:13:29 +02:00
if ( item . CostBearer ! = null & & item . CostBearer . CostBearerOid is null & & item . SupportConcept ! = null & & item . SupportConcept . CostBearerList . Count > 0 )
2018-04-27 14:11:21 +02:00
{
item . CostBearer . CostBearerOid = item . SupportConcept . CostBearerList [ 0 ] . CostBearerOid ;
}
}
if ( Model . NewServiceRecord . GroupOid . HasValue )
{
OperationsService . UpdateServiceRecordGroup ( group ) ;
}
Model . NewServiceRecord = null ;
Model . SelectedServiceRecord = null ;
2025-06-11 22:56:25 +02:00
Model . SelectedServiceRecordOid = null ;
2022-12-30 16:28:23 +01:00
Model . GroupBookingSelectedEmployees = new List < CompactEmployeeDC > ( ) ;
2018-04-27 14:11:21 +02:00
2022-12-30 16:28:23 +01:00
ResetBookingMode ( BookingMode . SingleBookingMode ) ;
2018-11-30 16:47:57 -04:00
Model . IsInEditingMode = false ;
2018-04-27 14:11:21 +02:00
2020-12-16 21:49:47 +01:00
return ResetEditingMode ( ) ;
2018-04-27 14:11:21 +02:00
}
2021-05-17 14:01:06 +02:00
[Authorize]
2018-04-27 14:11:21 +02:00
private IEnumerable < ServiceRecordDC > CalculateGroupBookingDuration ( int pEmployeeCount , int pCustomerCount , ICollection < long > cb2ScOids )
{
2025-07-15 14:26:03 +02:00
var compactSupportConcepts = GetSelectedGroupBookingSupportConcepts ( ) ;
2018-04-18 14:33:21 +02:00
2025-07-15 14:26:03 +02:00
var nodes = ( from supportConcept in compactSupportConcepts let cb = supportConcept . CostBearerList . FirstOrDefault ( ) let sc = compactSupportConcepts . FirstOrDefault ( f = > f . SupportConceptOid = = supportConcept . SupportConceptOid ) where cb ! = null & & sc ! = null select SupportConceptService . CreateFlatSupportConceptItem ( sc , CustomerService . LoadOrganisationCompact ( cb . Organisation . OrganisationOid ) ) ) . ToList ( ) ;
2018-04-18 14:33:21 +02:00
var list = new List < ServiceRecordDC > ( ) ;
foreach ( var node in nodes )
{
2022-12-30 16:28:23 +01:00
var sc = CloneServiceRecord ( Model . NewServiceRecord ) ;
2018-04-18 14:33:21 +02:00
if ( Model . NewServiceRecord . RoundedDuration = = 0 )
{
if ( Model . NewServiceRecord . Start . HasValue & & Model . NewServiceRecord . End . HasValue )
{
var minutes = Model . NewServiceRecord . End . Value . Subtract ( Model . NewServiceRecord . Start . Value ) . TotalMinutes ;
2018-04-27 14:11:21 +02:00
Model . NewServiceRecord . RoundedDuration = ( decimal ) minutes ;
2018-04-18 14:33:21 +02:00
}
}
2018-04-27 14:11:21 +02:00
sc . GroupRoundedDuration = Model . NewServiceRecord . RoundedDuration ;
2018-04-18 14:33:21 +02:00
sc . CostBearer2SupportConceptOid = node . SupportConceptTreeNodeDC . SupportConceptCostBearerRelDC . CostBearer2SupportConceptOid ;
sc . SupportConcept = node . SupportConceptTreeNodeDC . SupportConcept ;
2018-04-27 14:11:21 +02:00
2018-04-18 14:33:21 +02:00
sc . CostBearer = node . SupportConceptTreeNodeDC . CostBearer ;
sc . Customer = node . SupportConceptTreeNodeDC . Customer ;
2018-04-27 14:11:21 +02:00
sc . GroupEmployeeCount = pEmployeeCount ;
sc . GroupPersonCount = pCustomerCount ;
2018-04-18 14:33:21 +02:00
list . Add ( sc ) ;
}
var roundDuration = false ;
var minuteInterval = 0 ;
string calcdId = null ;
var lastMinuteInterval = - 1 ;
2018-11-26 13:27:16 -04:00
if ( Model . SelectedServiceDescriptionOid . HasValue & & IsBillable ( Model . SelectedServiceDescriptionOid . Value , Model . GetServiceDesctiptions ( ) ) )
2018-04-18 14:33:21 +02:00
{
roundDuration = true ;
2025-07-15 14:26:03 +02:00
foreach ( var org in from dc in compactSupportConcepts where dc . CostBearerList . Count > 0 select dc . CostBearerList . First ( ) . Organisation )
2018-04-18 14:33:21 +02:00
{
if ( org ! = null )
{
minuteInterval = org . ActualMinuteIntervall ;
if ( lastMinuteInterval = = - 1 )
{
lastMinuteInterval = minuteInterval ;
calcdId = org . CostBearerID ;
}
else if ( lastMinuteInterval ! = minuteInterval )
{
roundDuration = false ;
}
}
else if ( minuteInterval > = 0 )
{
roundDuration = false ;
}
else
{
minuteInterval = 0 ;
}
}
}
var duration = Model . NewServiceRecord . RoundedDuration ;
var totalDuration = duration ;
2018-04-27 14:11:21 +02:00
var groupDuration = OperationsService . CalculateGroupDuration2 ( pCustomerCount , pEmployeeCount , Model . NewServiceRecord . RoundedDuration , nodes . Select ( s = > s . SupportConceptTreeNodeDC . SupportConceptCostBearerRelDC . CostBearer2SupportConceptOid . Value ) . ToArray ( ) ) ;
2018-04-18 14:33:21 +02:00
if ( groupDuration ! = null )
{
Model . NewServiceRecord . GroupRoundedDuration = groupDuration . TotalDuration ;
Model . NewServiceRecord . RoundedDuration = groupDuration . SingleDuration ;
}
else
{
if ( minuteInterval > 0 & & roundDuration )
{
var calc = Calculations . GetInstance ( calcdId ) ;
totalDuration = calc . GetRoundedDuration ( minuteInterval , duration ) ;
}
2018-04-27 14:11:21 +02:00
Model . NewServiceRecord . RoundedDuration = Math . Round ( totalDuration / pCustomerCount , 0 , MidpointRounding . AwayFromZero ) ;
2018-04-18 14:33:21 +02:00
Model . NewServiceRecord . GroupRoundedDuration = totalDuration ;
}
2018-04-27 14:11:21 +02:00
return list ;
}
2018-11-26 13:27:16 -04:00
private void UpdateServiceRecordGroup ( ServiceRecordGroupDC pGroupDC )
2018-04-27 14:11:21 +02:00
{
var newCount = 0 ;
2018-04-18 14:33:21 +02:00
2018-11-26 13:27:16 -04:00
foreach ( var serviceRecord in pGroupDC . ServiceRecordList )
2018-04-18 14:33:21 +02:00
{
2018-04-27 14:11:21 +02:00
if ( ! serviceRecord . ServiceRecordOid . HasValue )
2018-04-18 14:33:21 +02:00
{
2018-04-27 14:11:21 +02:00
newCount + + ;
2018-04-18 14:33:21 +02:00
}
}
2018-11-26 13:27:16 -04:00
if ( newCount = = pGroupDC . ServiceRecordList . Count )
2018-04-18 14:33:21 +02:00
{
2018-04-27 14:11:21 +02:00
return ;
}
var dcsToChange = new List < ServiceRecordDC > ( ) ;
2021-05-17 14:01:06 +02:00
var oldSCs = new Dictionary < long , CompactSupportConceptDC > ( ) ;
var oldEmps = new Dictionary < long , CompactEmployeeDC > ( ) ;
var newKeys = new Dictionary < string , string > ( ) ;
2018-04-27 14:11:21 +02:00
2025-07-15 14:26:03 +02:00
foreach ( var sc in GetSelectedGroupBookingSupportConcepts ( ) )
2018-04-27 14:11:21 +02:00
{
2024-06-26 12:29:22 +02:00
if ( sc ? . SupportConceptOid is null )
{
continue ;
}
2025-07-15 14:26:03 +02:00
var costBearerRelation = Model . GroupBookingSelectionObject . SelectedRelations . FirstOrDefault ( f = > f . SupportConceptOid . HasValue & & f . SupportConceptOid . Value . Equals ( sc . SupportConceptOid ) ) ;
2024-06-26 12:29:22 +02:00
2022-12-30 16:28:23 +01:00
foreach ( var emp in Model . GroupBookingSelectedEmployees )
2018-04-18 14:33:21 +02:00
{
2018-04-27 14:11:21 +02:00
var key = emp . EmployeeOid + "_" + sc . SupportConceptOid ;
2025-07-15 14:26:03 +02:00
if ( costBearerRelation ? . CostBearer2SupportConceptOid ! = null )
2018-04-18 14:33:21 +02:00
{
2025-07-15 14:26:03 +02:00
var costBearer2SupportConceptOid = sc . CostBearerRelOids [ 0 ] ;
2018-04-27 14:11:21 +02:00
if ( costBearer2SupportConceptOid ! = null )
{
2024-06-26 12:29:22 +02:00
key + = "_" + costBearerRelation . CostBearer2SupportConceptOid . Value ;
2018-04-27 14:11:21 +02:00
}
newKeys . Add ( key , key ) ;
2018-04-18 14:33:21 +02:00
}
}
2018-04-27 14:11:21 +02:00
}
2018-11-26 13:27:16 -04:00
foreach ( var item in pGroupDC . ServiceRecordList )
2018-04-27 14:11:21 +02:00
{
var key = item . Employee . EmployeeOid + "_" + item . SupportConcept . SupportConceptOid ;
if ( item . CostBearer2SupportConceptOid . HasValue )
{
key + = "_" + item . CostBearer2SupportConceptOid . Value ;
}
if ( newKeys . ContainsKey ( key ) )
{
newKeys . Remove ( key ) ;
}
2018-04-18 14:33:21 +02:00
else
{
2018-04-27 14:11:21 +02:00
dcsToChange . Add ( item ) ;
}
2018-04-18 14:33:21 +02:00
2018-04-27 14:11:21 +02:00
if ( ! oldEmps . ContainsKey ( item . Employee . EmployeeOid ) )
{
oldEmps . Add ( item . Employee . EmployeeOid , item . Employee ) ;
}
2018-04-18 14:33:21 +02:00
2018-04-27 14:11:21 +02:00
if ( ! oldSCs . ContainsKey ( item . SupportConcept . SupportConceptOid ) )
{
oldSCs . Add ( item . SupportConcept . SupportConceptOid , item . SupportConcept ) ;
}
}
if ( newKeys . Count ! = 0 | | dcsToChange . Count ! = 0 )
{
if ( newKeys . Count > 0 )
{
2025-07-15 14:26:03 +02:00
foreach ( var sc in GetSelectedGroupBookingSupportConcepts ( ) )
2018-04-18 14:33:21 +02:00
{
2022-12-30 16:28:23 +01:00
foreach ( var emp in Model . GroupBookingSelectedEmployees )
2018-04-27 14:11:21 +02:00
{
var key = emp . EmployeeOid + "_" + sc . SupportConceptOid ;
2025-07-15 14:26:03 +02:00
if ( sc . CostBearerRelOids ! = null & & sc . CostBearerRelOids . Count > 0 )
2018-04-27 14:11:21 +02:00
{
2025-07-15 14:26:03 +02:00
key + = "_" + sc . CostBearerRelOids . ElementAt ( 0 ) ;
2018-04-27 14:11:21 +02:00
}
if ( ! newKeys . ContainsKey ( key ) )
{
continue ;
}
ServiceRecordDC newServiceRecord ;
if ( dcsToChange . Count > 0 )
{
newServiceRecord = dcsToChange [ 0 ] ;
dcsToChange . Remove ( newServiceRecord ) ;
}
else
{
2022-12-30 16:28:23 +01:00
newServiceRecord = CloneServiceRecord ( Model . NewServiceRecord ) ;
2018-11-26 13:27:16 -04:00
pGroupDC . ServiceRecordList . Add ( newServiceRecord ) ;
2018-04-27 14:11:21 +02:00
}
2021-05-17 14:01:06 +02:00
newServiceRecord . Employee = emp ;
2025-07-17 16:26:07 +02:00
newServiceRecord . SupportConcept = GetCompactSupportConcept ( sc . SupportConceptOid ) ;
2025-07-15 14:26:03 +02:00
newServiceRecord . CostBearer = sc . CostBearerList . ElementAt ( 0 ) . Organisation ;
2021-05-17 14:01:06 +02:00
newServiceRecord . Customer = sc . Customer ;
2025-07-15 14:26:03 +02:00
newServiceRecord . CostBearer2SupportConceptOid = sc . CostBearerRelOids . ElementAt ( 0 ) ;
2018-04-27 14:11:21 +02:00
}
2018-04-18 14:33:21 +02:00
}
}
2018-04-27 14:11:21 +02:00
foreach ( var item in dcsToChange )
{
2018-11-26 13:27:16 -04:00
pGroupDC . ServiceRecordList . Remove ( item ) ;
2018-04-27 14:11:21 +02:00
}
2018-04-18 14:33:21 +02:00
}
}
2020-04-02 13:19:14 +02:00
[HttpPost]
2018-02-07 14:14:08 +01:00
[Authorize]
2020-04-02 13:19:14 +02:00
public ActionResult SelectSupportConcept ( FormCollection formCollection )
2016-06-27 01:45:38 +02:00
{
2021-03-11 12:09:38 +01:00
try
2016-06-27 01:45:38 +02:00
{
2025-07-15 14:26:03 +02:00
SkipModelInitialization = true ; //Verhindere mehrfache Initialisierung, weil später sowieso zur Main Action geleitet wird
2025-06-11 22:56:25 +02:00
if ( Model is null )
2021-03-11 12:09:38 +01:00
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2021-03-11 12:09:38 +01:00
return Logout ( ) ;
}
2016-06-27 01:45:38 +02:00
2021-03-11 12:09:38 +01:00
long? cb2ScOid = Convert . ToInt64 ( formCollection [ FormCollectionConstants . CostBearer2SupportConceptOidKey ] ) ;
2025-07-15 14:26:03 +02:00
if ( Model . SelectedCostBearerSupportConceptOid . HasValue & & Model . SelectedCostBearerSupportConceptOid ! = cb2ScOid )
{
Model . SelectedGoalOids = new List < long > ( ) ;
Model . SelectedGoals = new List < MokZiel > ( ) ;
}
2016-06-27 01:45:38 +02:00
2025-06-11 22:56:25 +02:00
Model . SelectedCostBearerSupportConceptOid = cb2ScOid ;
2025-06-17 13:06:29 +02:00
Model . CurrentPage = 1 ;
2025-03-25 17:36:15 +01:00
return RedirectToActionPermanent ( "Main" ) ; //ResetEditingMode();
2021-03-11 12:09:38 +01:00
}
catch ( Exception e )
{
2021-05-17 14:01:06 +02:00
Log . Error ( $"ERROR SelectSupportConcept: {e.Message}\n{e.StackTrace}" ) ;
2021-03-11 12:09:38 +01:00
throw ;
}
2020-04-02 13:19:14 +02:00
}
2016-06-27 01:45:38 +02:00
2025-07-15 14:26:03 +02:00
private void LoadServiceCategoriesToModel ( List < SupportConceptTreeNodeDetailInfoDC > infos )
2020-04-02 13:19:14 +02:00
{
2025-07-15 14:26:03 +02:00
Model . Categories2Descriptions = new Dictionary < ServiceCategoryDC , List < ServiceDescriptionDC > > ( ) ;
2025-07-18 19:37:01 +02:00
if ( infos is null )
{
infos = new List < SupportConceptTreeNodeDetailInfoDC > ( ) ;
}
if ( infos . Count > 0 )
2020-04-02 13:19:14 +02:00
{
2025-07-15 14:26:03 +02:00
Model . Categories2Descriptions = CreateServiceCategory2ServiceDescription ( infos ) ;
2016-06-27 01:45:38 +02:00
}
2025-07-15 14:26:03 +02:00
else
2016-06-27 01:45:38 +02:00
{
2025-07-15 14:26:03 +02:00
//Sonst ohne Hilfeplan
2024-06-05 14:45:33 +02:00
var allServiceDescriptions = OperationsService . GetAllServiceDescriptions ( ) ;
2025-07-15 14:26:03 +02:00
2024-06-05 14:45:33 +02:00
allServiceDescriptions . AsParallel ( ) . DoForEach ( serviceDescription = >
{
2025-07-15 14:26:03 +02:00
if ( serviceDescription . Category . ActivationType = = ActivationTypeId . Active & & ( ! serviceDescription . Category . OhneHilfeplan . HasValue | | serviceDescription . Category . OhneHilfeplan = = AccountingvisibilityType . Beides | | serviceDescription . Category . OhneHilfeplan = = AccountingvisibilityType . NichtKlientenbezogen ) )
2024-06-05 14:45:33 +02:00
{
Model . Categories2Descriptions . AddOrUpdateValueInDictionary ( serviceDescription . Category , serviceDescription ) ;
}
} ) ;
2016-06-27 01:45:38 +02:00
}
2025-07-15 14:26:03 +02:00
2024-06-26 12:29:22 +02:00
SelectFirstServiceDescription ( ) ;
}
private void SelectFirstServiceDescription ( )
{
2025-07-18 19:37:01 +02:00
if ( Model ? . Categories2Descriptions is null | | Model . Categories2Descriptions . Count = = 0 )
2024-06-26 12:29:22 +02:00
{
2025-06-11 22:56:25 +02:00
UpdateSelectedServiceCategorieAndDescription ( null , null ) ;
2024-06-26 12:29:22 +02:00
return ;
}
2025-06-11 22:56:25 +02:00
//Nur, wenn Kategorie und Leistung null sind oder nicht in der Liste alle Kategorien enthalten sind, soll weiter unten die erste Leistung in der Liste gesetzt werden
2025-07-18 19:37:01 +02:00
if ( Model . SelectedServiceCategoryOid . HasValue & & Model . SelectedServiceDescriptionOid . HasValue )
2025-06-11 22:56:25 +02:00
{
2025-07-18 19:37:01 +02:00
var cat = Model . Categories2Descriptions . Keys . FirstOrDefault ( c = > c . ServiceCategoryOid = = Model . SelectedServiceCategoryOid ) ;
if ( cat ! = null )
2025-06-11 22:56:25 +02:00
{
2025-07-18 19:37:01 +02:00
var desc = Model . Categories2Descriptions [ cat ] . FirstOrDefault ( d = > d . ServiceDescriptionOid = = Model . SelectedServiceDescriptionOid ) ;
2025-06-11 22:56:25 +02:00
2025-07-18 19:37:01 +02:00
if ( desc ! = null )
2025-06-11 22:56:25 +02:00
{
//Setzte Objekte im Model, sonst wird unten die erste Leistung gesetzt
Model . SelectedServiceCategory = cat ;
Model . SelectedServiceDescription = desc ;
return ;
}
}
}
2024-06-26 12:29:22 +02:00
var firstServiceCategory2ServiceDescriptions = Model . Categories2Descriptions . OrderBy ( c2d = > c2d . Key . Position ) . ThenBy ( c2d = > c2d . Key . ServiceCategoryOid ) . FirstOrDefault ( c2d = > c2d . Value . Any ( ) ) ;
2024-07-24 16:45:56 +02:00
if ( firstServiceCategory2ServiceDescriptions . Key is null )
2024-06-26 12:29:22 +02:00
{
2025-06-11 22:56:25 +02:00
UpdateSelectedServiceCategorieAndDescription ( null , null ) ;
2024-07-24 16:45:56 +02:00
return ;
2024-06-26 12:29:22 +02:00
}
2024-07-24 16:45:56 +02:00
var serviceDescription = firstServiceCategory2ServiceDescriptions . Value . OrderBy ( sd = > sd . Position ) . ThenBy ( sd = > sd . ServiceDescriptionOid ) . First ( ) ;
2025-06-11 22:56:25 +02:00
UpdateSelectedServiceCategorieAndDescription ( serviceDescription . Category , serviceDescription ) ;
2020-04-02 13:19:14 +02:00
}
2016-06-27 01:45:38 +02:00
2025-06-11 22:56:25 +02:00
private void UpdateSelectedServiceCategorieAndDescription ( ServiceCategoryDC cat , ServiceDescriptionDC desc )
{
Model . SelectedServiceCategory = cat ;
Model . SelectedServiceDescription = desc ;
Model . SelectedServiceCategoryOid = Model . SelectedServiceCategory ? . ServiceCategoryOid ;
Model . SelectedServiceDescriptionOid = Model . SelectedServiceDescription ? . ServiceDescriptionOid ;
}
2025-07-15 14:26:03 +02:00
private Dictionary < ServiceCategoryDC , List < ServiceDescriptionDC > > CreateServiceCategory2ServiceDescription ( List < SupportConceptTreeNodeDetailInfoDC > nodes )
2024-06-05 14:45:33 +02:00
{
var result = new Dictionary < ServiceCategoryDC , List < ServiceDescriptionDC > > ( ) ;
2024-06-26 12:29:22 +02:00
var firstNode = nodes . FirstOrDefault ( ) ;
if ( firstNode is null )
2024-06-05 14:45:33 +02:00
{
2024-06-26 12:29:22 +02:00
return result ;
}
2024-06-05 14:45:33 +02:00
2024-06-26 12:29:22 +02:00
if ( nodes . Count = = 1 )
{
firstNode . ServiceAccountings . DoForEach ( serviceAccounting = > result . AddOrUpdateValueInDictionary ( serviceAccounting . ServiceDescription . Category , serviceAccounting . ServiceDescription ) ) ;
}
2024-07-24 16:45:56 +02:00
2024-06-26 12:29:22 +02:00
foreach ( var serviceAccounting in firstNode . ServiceAccountings )
{
var serviceDescription = serviceAccounting . ServiceDescription ;
var serviceCategory = serviceDescription . Category ;
2024-06-05 14:45:33 +02:00
2024-06-26 12:29:22 +02:00
if ( nodes . All ( node = > node . ServiceAccountings . Any ( accounting = > accounting . ServiceDescription . Equals ( serviceDescription ) ) ) )
{
result . AddOrUpdateValueInDictionary ( serviceCategory , serviceDescription ) ;
}
2024-06-05 14:45:33 +02:00
}
2024-08-02 12:11:53 +02:00
if ( firstNode . ServiceAccountings . Count = = 0 | | result . Count = = 0 )
2024-07-24 16:45:56 +02:00
{
2025-03-25 17:36:15 +01:00
var allServiceDescriptions = OperationsService . GetAllServiceDescriptions ( ) . Where ( sd = > sd . Category . ActivationType = = ActivationTypeId . Active & & sd . ActivationType = = ActivationTypeId . Active & & sd . Category . OhneHilfeplan ! = AccountingvisibilityType . NichtKlientenbezogen ) . ToList ( ) ;
2024-07-24 16:45:56 +02:00
foreach ( var serviceDescription in allServiceDescriptions )
{
result . AddOrUpdateValueInDictionary ( serviceDescription . Category , serviceDescription ) ;
}
}
return result . OrderBy ( kvp = > kvp . Key . Position ) . ToDictionary ( category2Descriptions = > category2Descriptions . Key , category2Descriptions = > category2Descriptions . Value . OrderBy ( serviceDescription = > serviceDescription . Position ) . ToList ( ) ) ;
2024-06-05 14:45:33 +02:00
}
2016-06-27 01:45:38 +02:00
[HttpPost]
[Authorize]
2018-11-30 16:47:57 -04:00
public ActionResult DeleteServiceRecord ( FormCollection formCollection )
2016-06-27 01:45:38 +02:00
{
2025-03-25 17:36:15 +01:00
if ( Model is null )
2016-06-27 01:45:38 +02:00
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2020-10-07 19:42:17 +02:00
return Logout ( ) ;
2016-06-27 01:45:38 +02:00
}
2020-09-21 11:57:10 +02:00
Model . ServiceRecordOidToDelete = long . Parse ( formCollection [ FormCollectionConstants . ServiceRecordOidHolderKey ] ) ;
2018-11-30 16:47:57 -04:00
2025-06-11 22:56:25 +02:00
if ( Model . ServiceRecordOidToDelete ! = null & & Model . ServiceRecordOidToDelete > 0 & & LoggedInUser . UserGroups . Any ( a = > a . Rights . Any ( f = > f . Equals ( UserRightType . ServiceRecordView_Delete ) ) ) )
2016-06-27 01:45:38 +02:00
{
var serviceRecordDC = Model . ServiceRecords . FirstOrDefault ( f = > f . ServiceRecordOid ! = null & & f . ServiceRecordOid . Value . Equals ( Model . ServiceRecordOidToDelete ) ) ;
2018-01-29 12:57:10 +01:00
var version = serviceRecordDC ? . ServiceRecordVersion ;
2025-05-21 19:34:42 +02:00
if ( version ! = null & & Model . IsAllowedToDeleteServiceRecord ( serviceRecordDC ) )
2016-06-27 01:45:38 +02:00
{
2018-01-29 12:57:10 +01:00
OperationsService . DeleteServiceRecord ( Model . ServiceRecordOidToDelete . Value , version . Value ) ;
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
Model . ServiceRecords = Model . ServiceRecords . Where ( sr = > sr . ServiceRecordOid ! = null & & ! sr . ServiceRecordOid . Value . Equals ( serviceRecordDC . ServiceRecordOid ) ) . ToList ( ) ;
2016-06-27 01:45:38 +02:00
}
}
2025-05-21 19:34:42 +02:00
return ResetEditingMode ( ) ;
2016-06-27 01:45:38 +02:00
}
2025-06-11 22:56:25 +02:00
//[Authorize]
//public ActionResult ReloadGoalRatings()
//{
// if(Model is null)
// {
// TempData[TempDataConstants.DoLogoutKey] = true;
// return PartialView("GoalRatingPopupContentPartial");
// }
2024-06-26 12:29:22 +02:00
2025-06-11 22:56:25 +02:00
// return PartialView("GoalRatingPopupContentPartial", Model);
//}
2024-06-26 12:29:22 +02:00
2021-05-17 14:01:06 +02:00
[Authorize]
2019-07-19 17:13:57 +02:00
public string UpdateGoals ( string pGoalOids )
2016-06-27 01:45:38 +02:00
{
2022-08-10 14:13:29 +02:00
if ( Model is null )
2016-06-27 01:45:38 +02:00
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
2024-07-24 16:45:56 +02:00
return "0" ;
2016-06-27 01:45:38 +02:00
}
var sc = Model . SelectedSupportConcept ;
2024-06-26 12:29:22 +02:00
if ( ! Model . IsInGroupBookingMode & & sc is null )
2018-01-29 12:57:10 +01:00
{
2024-07-24 16:45:56 +02:00
return "0" ;
2018-01-29 12:57:10 +01:00
}
2016-06-27 01:45:38 +02:00
2019-07-25 14:56:11 +02:00
if ( string . IsNullOrEmpty ( pGoalOids ) )
{
Model . SelectedGoals . Clear ( ) ;
2024-07-24 16:45:56 +02:00
return "0" ;
2019-07-25 14:56:11 +02:00
}
2020-04-02 13:19:14 +02:00
var splitOids = pGoalOids . Trim ( ';' ) . Split ( ';' ) ;
2019-07-19 17:13:57 +02:00
var selectedGoalOids = splitOids . Select ( long . Parse ) . ToList ( ) ;
2016-06-27 01:45:38 +02:00
2024-06-26 12:29:22 +02:00
var allGoals = new List < ValueListEntryDC > ( ) ;
2025-07-17 16:26:07 +02:00
if ( Model . IsInGroupBookingMode | | Model . IsInMultiBookingMode )
2024-06-26 12:29:22 +02:00
{
2025-07-15 14:26:03 +02:00
var supportConcepts = GetSelectedGroupBookingSupportConcepts ( ) ;
2025-07-17 16:26:07 +02:00
LoadSupportConceptThings ( null , false ) ;
2024-06-26 12:29:22 +02:00
supportConcepts . DoForEach ( supportConcept = > { allGoals . AddRangeIfElementsNotIn ( supportConcept . Goals ) ; } ) ;
}
else if ( ! Model . IsInGroupBookingMode )
{
allGoals = sc . Goals ;
}
2022-12-30 16:28:23 +01:00
var parents = CustomerService . GetSupportConceptGoalParents ( allGoals . Where ( w = > w . ParentOid . HasValue ) . Select ( s = > s . ParentOid . Value ) . ToList ( ) ) ;
allGoals . AddRangeIfElementsNotIn ( parents ) ;
var goals = allGoals . Where ( w = > w . ValueListEntryOid . HasValue & & selectedGoalOids . Contains ( w . ValueListEntryOid . Value ) ) . ToList ( ) ;
2024-07-24 16:45:56 +02:00
2022-08-10 14:13:29 +02:00
var stillSelectedGoals = Model . SelectedGoals . Where ( s = > goals . Any ( a = > a . ValueListEntryOid . HasValue & & a . ValueListEntryOid . Value = = s . ValueListEntryOid ) ) . ToList ( ) ;
Model . SelectedGoals = stillSelectedGoals ;
2025-07-15 14:26:03 +02:00
Model . SelectedGoals . AddRangeIfElementsNotIn ( DcToMokMapper . CreateZiele ( goals ) ) ;
2025-06-11 22:56:25 +02:00
Model . SelectedGoalOids = Model . SelectedGoals . Select ( g = > g . ValueListEntryOid . Value ) . ToList ( ) ;
2018-12-13 20:59:05 -04:00
2024-07-24 16:45:56 +02:00
return Model . SelectedGoals ? . Count . ToString ( ) ? ? "0" ;
2016-06-27 01:45:38 +02:00
}
2021-05-17 14:01:06 +02:00
[Authorize]
2018-11-30 16:47:57 -04:00
public string SetServiceDescription ( long pServiceDescriptionOid )
2016-06-27 01:45:38 +02:00
{
2022-08-10 14:13:29 +02:00
if ( Model is null )
2016-06-27 01:45:38 +02:00
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
2024-06-26 18:53:59 +02:00
var serviceDescription = OperationsService . GetServiceDescription ( pServiceDescriptionOid ) ;
Model . SelectedServiceDescription = serviceDescription ;
2025-06-11 22:56:25 +02:00
Model . SelectedServiceDescriptionOid = pServiceDescriptionOid ;
2024-06-26 18:53:59 +02:00
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
[HttpPost]
[Authorize]
public ActionResult LoadServiceRecords ( FormCollection formCollection )
{
2022-12-30 16:28:23 +01:00
if ( Model is null )
2016-06-27 01:45:38 +02:00
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2020-10-07 19:42:17 +02:00
return Logout ( ) ;
2016-06-27 01:45:38 +02:00
}
2022-12-30 16:28:23 +01:00
int . TryParse ( formCollection [ "day-count-number" ] , out var dayCountNumber ) ;
var successfullStartParsing = DateTime . TryParse ( formCollection [ "von" ] , out var parsedVon ) ;
var successfullEndParsing = DateTime . TryParse ( formCollection [ "bis" ] , out var parsedBis ) ;
int . TryParse ( formCollection [ "month-select" ] , out var month ) ;
int . TryParse ( formCollection [ "year-select" ] , out var year ) ;
var lastSelectedServiceRecordMonth = new DateTime ( year , month , 1 ) ;
if ( Model . ServiceRecordTimeInterval = = ServiceRecordTimeInterval . ZeitraumWaehlen )
2018-01-29 12:57:10 +01:00
{
2022-12-30 16:28:23 +01:00
if ( ! successfullStartParsing )
{
parsedVon = DateTime . Today . GetFirstOfMonth ( ) ;
}
if ( ! successfullEndParsing )
{
parsedBis = DateTime . Today ;
}
if ( parsedVon > parsedBis )
{
( parsedVon , parsedBis ) = ( parsedBis , parsedVon ) ;
}
Model . SelectedZeitraum = new NullableDateTimeSpan ( parsedVon , parsedBis ) ;
2018-01-29 12:57:10 +01:00
}
2022-12-30 16:28:23 +01:00
var serviceRecordTimeInterval = ( ServiceRecordTimeInterval ) int . Parse ( formCollection [ FormCollectionConstants . RecordsKey ] ) ;
Model . ServiceRecordTimeInterval = serviceRecordTimeInterval ;
2016-06-27 01:45:38 +02:00
2023-09-04 16:57:20 +02:00
CalculateSelectedDayCount ( dayCountNumber , lastSelectedServiceRecordMonth , parsedVon , parsedBis , serviceRecordTimeInterval ) ;
2016-06-27 01:45:38 +02:00
return RedirectToActionPermanent ( "Main" ) ;
}
2024-09-12 14:55:35 +02:00
[Authorize]
public ActionResult LoadServiceRecordsNonPost ( int dayCountNumber , string start , string end , int month , int year , int recordsKey )
{
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return PartialView ( "ServiceRecordListPartial" ) ;
}
var lastSelectedServiceRecordMonth = new DateTime ( year , month , 1 ) ;
var isValidStart = DateTime . TryParse ( start , out var parsedStart ) ;
var isValidEnd = DateTime . TryParse ( end , out var parsedEnd ) ;
if ( Model . ServiceRecordTimeInterval = = ServiceRecordTimeInterval . ZeitraumWaehlen )
{
if ( ! isValidStart )
{
parsedStart = DateTime . Today . GetFirstOfMonth ( ) ;
}
if ( ! isValidEnd )
{
parsedEnd = DateTime . Today ;
}
if ( parsedStart > parsedEnd )
{
( parsedStart , parsedEnd ) = ( parsedEnd , parsedStart ) ;
}
Model . SelectedZeitraum = new NullableDateTimeSpan ( parsedStart , parsedEnd ) ;
}
var serviceRecordTimeInterval = ( ServiceRecordTimeInterval ) recordsKey ;
Model . ServiceRecordTimeInterval = serviceRecordTimeInterval ;
CalculateSelectedDayCount ( dayCountNumber , lastSelectedServiceRecordMonth , parsedStart , parsedEnd , serviceRecordTimeInterval ) ;
2025-06-11 22:56:25 +02:00
if ( Model . SelectedCostBearerSupportConceptOid . HasValue & & Model . SelectedCostBearerSupportConceptOid ! = - 1 )
2024-09-12 14:55:35 +02:00
{
LoadPaginatedServiceRecordsToModel ( Model . CurrentPage ) ;
}
return PartialView ( "ServiceRecordListPartial" , Model ) ;
}
2023-09-04 16:57:20 +02:00
private void CalculateSelectedDayCount ( int? dayCountNumber , DateTime ? lastSelectedServiceRecordMonth , DateTime ? von , DateTime ? bis , ServiceRecordTimeInterval ? serviceRecordTimeInterval )
2022-12-30 16:28:23 +01:00
{
if ( dayCountNumber is null )
{
dayCountNumber = 0 ;
}
if ( lastSelectedServiceRecordMonth is null )
{
lastSelectedServiceRecordMonth = DateTime . Today . AddMonths ( - 1 ) ;
}
if ( von is null | | bis is null )
{
von = DateTime . Today . GetFirstOfMonth ( ) ;
bis = DateTime . Today ;
}
Model . SelectedDayCount = 0 ;
switch ( Model . ServiceRecordTimeInterval )
{
case ServiceRecordTimeInterval . LastWeek :
Model . SelectedDayCount = 7 ;
break ;
case ServiceRecordTimeInterval . LastMonth :
Model . SelectedDayCount = 30 ;
break ;
case ServiceRecordTimeInterval . Last3Month :
Model . SelectedDayCount = 90 ;
break ;
case ServiceRecordTimeInterval . XTage :
Model . SelectedDayCount = dayCountNumber . Value ;
Model . LastSelectedServiceRecordTimeIntervalDays = dayCountNumber . Value ;
UpdateUserSettingsWithoutReload ( SettingsKeys . LastSelectedServiceRecordTimeIntervalDays , dayCountNumber . ToString ( ) ) ;
break ;
case ServiceRecordTimeInterval . Monatsauswahl :
Model . LastSelectedServiceRecordMonth = lastSelectedServiceRecordMonth . Value ;
Model . SelectedDayCount = lastSelectedServiceRecordMonth . Value . Date . GetDaysInMonth ( ) ;
2024-11-12 18:37:23 +01:00
Model . SelectedZeitraum = new NullableDateTimeSpan ( lastSelectedServiceRecordMonth . Value . Date . GetFirstOfMonth ( ) , lastSelectedServiceRecordMonth . Value . Date . GetLastOfMonth ( ) ) ;
2022-12-30 16:28:23 +01:00
UpdateUserSettingsWithoutReload ( SettingsKeys . LastSelectedServiceRecordMonth , lastSelectedServiceRecordMonth . Value . ToString ( "dd.MM.yyyy HH:mm:ss" ) ) ;
break ;
case ServiceRecordTimeInterval . ZeitraumWaehlen :
Model . SelectedZeitraum = new NullableDateTimeSpan ( von . Value , bis . Value ) ;
break ;
}
2023-09-04 16:57:20 +02:00
if ( serviceRecordTimeInterval is null )
{
return ;
}
UpdateSettings ( SettingsKeys . LastSelectedServiceRecordTimeInterval , ( ( int ) serviceRecordTimeInterval . Value ) . ToString ( ) ) ;
2022-12-30 16:28:23 +01:00
}
2020-04-02 13:19:14 +02:00
[HttpPost]
[Authorize]
public ActionResult SelectRecordToEdit ( FormCollection formCollection )
2016-06-27 01:45:38 +02:00
{
2025-07-15 14:26:03 +02:00
if ( ! IsUserLoggedIn ( ) )
2016-06-27 01:45:38 +02:00
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2020-10-07 19:42:17 +02:00
return Logout ( ) ;
2016-06-27 01:45:38 +02:00
}
2025-07-15 14:26:03 +02:00
SkipModelInitialization = true ;
2020-09-21 11:57:10 +02:00
var oidString = formCollection [ FormCollectionConstants . ServiceRecordOidHolder2Key ] ;
2018-12-13 20:59:05 -04:00
2020-04-02 13:19:14 +02:00
var wasSuccessful = long . TryParse ( oidString , out var serviceRecordOid ) ;
2016-06-27 01:45:38 +02:00
2024-07-24 16:45:56 +02:00
if ( ! wasSuccessful )
2018-04-18 14:33:21 +02:00
{
2021-05-17 14:01:06 +02:00
return RedirectToActionPermanent ( "Main" ) ;
2018-04-18 14:33:21 +02:00
}
2020-04-02 13:19:14 +02:00
Model . SelectedServiceRecordOid = serviceRecordOid ;
2018-04-27 14:11:21 +02:00
2025-07-17 16:26:07 +02:00
var selectedServiceRecord = GetServiceRecordDC ( serviceRecordOid , false ) ;
2021-05-17 14:01:06 +02:00
2022-08-10 14:13:29 +02:00
if ( selectedServiceRecord is null )
2021-05-17 14:01:06 +02:00
{
return RedirectToActionPermanent ( "Main" ) ;
}
2018-04-18 14:33:21 +02:00
2025-07-15 14:26:03 +02:00
Model . SelectedGoalOids = selectedServiceRecord . Goals . Select ( g = > g . ValueListEntryOid . Value ) . ToList ( ) ;
2025-07-17 16:26:07 +02:00
Model . SelectedGoals = DcToMokMapper . CreateZiele ( selectedServiceRecord . Goals ) ;
2018-04-18 14:33:21 +02:00
2024-06-26 12:29:22 +02:00
var selectedServiceDescription = selectedServiceRecord . ServiceDescription ;
var selectedServiceCategory = selectedServiceDescription . Category ;
2025-06-11 22:56:25 +02:00
Model . SelectedServiceDescriptionOid = selectedServiceDescription ? . ServiceDescriptionOid ;
Model . SelectedServiceCategoryOid = selectedServiceCategory ? . ServiceCategoryOid ;
2018-11-30 16:47:57 -04:00
2025-06-11 22:56:25 +02:00
Model . PreviouslySelectedEmployeeOid = Model . SelectedEmployee ? . EmployeeOid ;
Model . SelectedEmployeeOid = selectedServiceRecord . Employee ? . EmployeeOid ;
2018-04-18 14:33:21 +02:00
2020-04-02 13:19:14 +02:00
Model . IsInEditingMode = true ;
2018-04-18 14:33:21 +02:00
2025-06-17 13:06:29 +02:00
//Model.PreviouslySelectedSupportConceptOid = Model.SelectedSupportConcept?.SupportConceptOid;
2025-06-11 22:56:25 +02:00
Model . PreviouslySelectedCostbearer2SupportConceptOid = Model . SelectedCostBearerSupportConceptOid ;
2020-12-16 21:49:47 +01:00
2024-06-26 12:29:22 +02:00
// Gruppenbuchung
if ( selectedServiceRecord . GroupOid . HasValue )
2020-04-02 13:19:14 +02:00
{
Model . IsInGroupBookingMode = true ;
2018-04-18 14:33:21 +02:00
2025-06-17 13:06:29 +02:00
//Model.SelectedSupportConceptOid = null;
2025-06-11 22:56:25 +02:00
Model . SelectedEmployeeOid = null ;
2018-04-18 14:33:21 +02:00
2020-04-02 13:19:14 +02:00
var group = OperationsService . GetServiceRecordGroup ( selectedServiceRecord . GroupOid . Value ) ;
2020-12-01 12:29:12 +01:00
var employees = group . ServiceRecordList . Select ( serviceRecord = > serviceRecord . Employee ) . Distinct ( ) . ToList ( ) ;
2025-06-11 22:56:25 +02:00
Model . GroupBookingSelectedEmployeeOids = employees . Select ( e = > e . EmployeeOid ) . ToList ( ) ;
2020-04-02 13:19:14 +02:00
var cb2ScOids = group . ServiceRecordList . Where ( w = > w . CostBearer2SupportConceptOid . HasValue ) . Select ( s = > s . CostBearer2SupportConceptOid . Value ) . ToList ( ) ;
2018-04-18 14:33:21 +02:00
2025-06-11 22:56:25 +02:00
//Model.SelectedConceptCostBearerRelations.AddRangeIfElementsNotIn(OperationsService.GetSupportConceptCostBearerRelDCsByOids(cb2ScOids));
2025-07-15 14:26:03 +02:00
Model . GroupBookingSelectedCostBearerSupportConceptOids = cb2ScOids ;
2020-11-20 23:28:09 +01:00
2025-06-11 22:56:25 +02:00
//var selectedSupportConcepts = new List<SupportConceptDC>();
//selectedSupportConcepts.AddRangeIfElementsNotIn(OperationsService.GetSupportConceptsById(group.ServiceRecordList.Select(s => s.SupportConcept.SupportConceptOid)));
//Model.GroupBookingSelectedSupportConcepts = selectedSupportConcepts;
2020-11-20 23:28:09 +01:00
2025-07-15 14:26:03 +02:00
//Model.GroupBookingSelectedSupportConceptOids = group.ServiceRecordList.Select(s => s.SupportConcept.SupportConceptOid).ToList();
2020-04-02 13:19:14 +02:00
}
2018-04-18 14:33:21 +02:00
2025-06-11 22:56:25 +02:00
2018-04-18 14:33:21 +02:00
return RedirectToActionPermanent ( "Main" ) ;
}
2021-05-17 14:01:06 +02:00
[Authorize]
2017-04-26 14:57:32 +02:00
public string GetSelectedRecordInformation ( )
2016-06-27 01:45:38 +02:00
{
2024-07-24 16:45:56 +02:00
if ( Model is null )
2018-12-10 23:40:38 -04:00
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2018-12-10 23:40:38 -04:00
}
2023-02-09 20:47:52 +01:00
var result = LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
2024-07-24 16:45:56 +02:00
if ( Model . SelectedServiceRecordOid . HasValue )
2016-06-27 01:45:38 +02:00
{
result = SerializeObject ( Model . ServiceRecords . First ( f = > f . ServiceRecordOid = = Model . SelectedServiceRecordOid ) ) ;
}
return result ;
}
2021-05-17 14:01:06 +02:00
[Authorize]
2017-04-26 14:57:32 +02:00
public string GetSelectedRecordInformationWithOid ( long oid )
2016-06-27 01:45:38 +02:00
{
2023-05-02 13:03:46 +02:00
if ( Model is null )
2018-12-10 23:40:38 -04:00
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2018-12-10 23:40:38 -04:00
}
2023-05-02 13:03:46 +02:00
var serviceRecord = Model . ServiceRecords . FirstOrDefault ( f = > f . ServiceRecordOid . HasValue & & f . ServiceRecordOid . Value . Equals ( oid ) ) ? ? OperationsService . GetServiceRecordById ( oid ) ;
2016-06-27 01:45:38 +02:00
2023-06-19 16:03:55 +02:00
if ( serviceRecord ? . ServiceRecordOid is null )
2023-06-18 17:11:35 +02:00
{
return null ;
}
2023-06-19 16:03:55 +02:00
var hasMonatsunterschrift = OperationsService . CheckForConfirmationReceiptSignatureForServiceRecord ( serviceRecord . ServiceRecordOid . Value , SignatureType . Customer ) ;
2023-06-18 17:11:35 +02:00
var serviceRecord2Monatsunterschrift = new ServiceRecord2Monatsunterschrift ( serviceRecord , hasMonatsunterschrift ) ;
return SerializeObject ( serviceRecord2Monatsunterschrift ) ;
2016-06-27 01:45:38 +02:00
}
2018-12-10 23:40:38 -04:00
[Authorize]
2024-03-14 17:18:35 +01:00
[HttpPost]
public ActionResult ValidateServiceRecord ( FormCollection formCollection )
{
2024-06-26 12:29:22 +02:00
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return Logout ( ) ;
}
2024-03-14 17:18:35 +01:00
var inEditMode = Model . IsInEditingMode ;
2024-04-18 16:14:20 +02:00
var von = formCollection [ FormCollectionConstants . DateKey ] ;
var bis = formCollection [ FormCollectionConstants . EndDateKey ] ;
var start = formCollection [ FormCollectionConstants . StartKey ] ;
var end = formCollection [ FormCollectionConstants . EndKey ] ;
2024-03-14 17:18:35 +01:00
var durationRaw = formCollection [ FormCollectionConstants . DurationKey ] ;
2024-09-12 14:55:35 +02:00
var betragRaw = formCollection [ FormCollectionConstants . BetragKey ] ;
2024-03-14 17:18:35 +01:00
var distanceRaw = formCollection [ FormCollectionConstants . DistanceKey ] ;
var doku1 = formCollection [ FormCollectionConstants . Dokumentation1Key ] ? . RemoveUppercaseEsszett ( ) ;
var doku2 = formCollection [ FormCollectionConstants . Dokumentation2Key ] ? . RemoveUppercaseEsszett ( ) ;
var doku3 = formCollection [ FormCollectionConstants . Dokumentation3Key ] ? . RemoveUppercaseEsszett ( ) ;
var doku4 = formCollection [ FormCollectionConstants . Dokumentation4Key ] ? . RemoveUppercaseEsszett ( ) ;
var doku5 = formCollection [ FormCollectionConstants . Dokumentation5Key ] ? . RemoveUppercaseEsszett ( ) ;
var formId = formCollection [ FormCollectionConstants . FormIdKey ] ;
2016-06-27 01:45:38 +02:00
2025-01-22 16:42:02 +01:00
var markerRaw = formCollection [ FormCollectionConstants . MarkerKey ] ;
var marker = "on" = = markerRaw ;
2024-03-14 17:18:35 +01:00
var serviceDescription = formCollection [ FormCollectionConstants . ServiceDescriptionKey ] ;
2016-06-27 01:45:38 +02:00
2024-03-14 17:18:35 +01:00
var startHoursDt = ConvertTimeStringToDateTime ( start ) ;
var endHoursDt = ConvertTimeStringToDateTime ( end ) ;
2016-06-27 01:45:38 +02:00
2021-02-17 16:59:26 +01:00
if ( ! DateTime . TryParse ( von , out var startDate ) )
2016-06-27 01:45:38 +02:00
{
2021-02-17 16:59:26 +01:00
startDate = DateTime . Now . Date ;
2016-06-27 01:45:38 +02:00
}
2021-02-17 16:59:26 +01:00
if ( ! DateTime . TryParse ( bis , out var endDate ) )
{
endDate = DateTime . Now . Date ;
}
var startDt = startDate . AddHours ( startHoursDt . Hour ) . AddMinutes ( startHoursDt . Minute ) ;
var endDt = endDate . AddHours ( endHoursDt . Hour ) . AddMinutes ( endHoursDt . Minute ) ;
2016-06-27 01:45:38 +02:00
2024-03-14 17:18:35 +01:00
var dauer = ( int ) ( endDt - startDt ) . TotalMinutes ;
2024-03-19 19:10:13 +01:00
if ( dauer = = 0 | | start = = string . Empty & & end = = string . Empty )
2016-06-27 01:45:38 +02:00
{
startDt = startDt . AddSeconds ( 1 ) ;
endDt = endDt . AddSeconds ( 1 ) ;
}
2020-04-02 13:19:14 +02:00
var checkServiceRecord = new ServiceRecordDC ( ) ;
2023-12-19 10:58:34 +01:00
if ( inEditMode )
2016-06-27 01:45:38 +02:00
{
2020-04-02 13:19:14 +02:00
checkServiceRecord = Model . ServiceRecords . FirstOrDefault ( f = > f . ServiceRecordOid . HasValue & & f . ServiceRecordOid . Value . Equals ( Model . SelectedServiceRecordOid ) ) ;
2016-06-27 01:45:38 +02:00
}
2023-12-19 10:58:34 +01:00
if ( checkServiceRecord is null )
2016-06-27 01:45:38 +02:00
{
2020-04-02 13:19:14 +02:00
checkServiceRecord = new ServiceRecordDC ( ) ;
2016-06-27 01:45:38 +02:00
}
2025-01-22 16:42:02 +01:00
checkServiceRecord . ServiceRecordType = marker ? ServiceRecordTypeId . Content : ServiceRecordTypeId . DefaultActivity ;
2023-12-19 10:58:34 +01:00
checkServiceRecord . Notice = doku1 ;
checkServiceRecord . Notice2 = doku2 ;
checkServiceRecord . Notice3 = doku3 ;
checkServiceRecord . Notice4 = doku4 ;
checkServiceRecord . Notice5 = doku5 ;
2025-03-25 17:36:15 +01:00
if ( betragRaw is object & & decimal . TryParse ( betragRaw , out var betrag ) )
2024-09-12 14:55:35 +02:00
{
checkServiceRecord . Betrag = betrag ;
}
2025-07-15 14:26:03 +02:00
checkServiceRecord . Goals = CreateValueListEntriesFromMokZiele ( Model . SelectedGoals ) ;
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
checkServiceRecord . Start = startDt ;
checkServiceRecord . End = endDt ;
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
checkServiceRecord . IP = Request . UserHostAddress ;
2018-12-10 23:40:38 -04:00
2020-04-02 13:19:14 +02:00
checkServiceRecord . ServiceDescription = OperationsService . GetServiceDescription ( Model . SelectedServiceDescriptionOid . Value ) ;
2018-12-10 23:40:38 -04:00
2025-06-11 22:56:25 +02:00
checkServiceRecord . Employee = Model . SelectedEmployee ? ? LoggedInUser . Employee ;
2018-12-10 23:40:38 -04:00
2024-03-14 17:18:35 +01:00
// Mitarbeiter ausgewählt und Einzelbuchung
if ( Model . SelectedEmployee ! = null & & ! Model . IsInGroupBookingMode & & ! Model . IsInMultiBookingMode )
2016-06-27 01:45:38 +02:00
{
2025-07-15 14:26:03 +02:00
var supportConcept = Model . SupportConcepts . FirstOrDefault ( fod = > fod . CostBearerRelOids . Any ( a = > a . Equals ( Model . SelectedCostBearerSupportConceptOid ) ) ) ;
2016-06-27 01:45:38 +02:00
2024-03-14 17:18:35 +01:00
if ( supportConcept ! = null )
2016-06-27 01:45:38 +02:00
{
2024-03-14 17:18:35 +01:00
if ( supportConcept . SupportConceptOid ! = null )
2016-06-27 01:45:38 +02:00
{
2025-07-17 16:26:07 +02:00
checkServiceRecord . SupportConcept = GetCompactSupportConcept ( supportConcept . SupportConceptOid ) ;
2016-06-27 01:45:38 +02:00
}
2024-03-14 17:18:35 +01:00
checkServiceRecord . Customer = supportConcept . Customer ;
2025-07-15 14:26:03 +02:00
var costbearer = supportConcept . CostBearerList . FirstOrDefault ( ) ;
checkServiceRecord . CostBearer = costbearer . Organisation ;
2020-04-02 13:19:14 +02:00
var intervall = checkServiceRecord . CostBearer . ActualMinuteIntervall ;
2016-06-27 01:45:38 +02:00
2024-03-14 17:18:35 +01:00
if ( intervall > 0 )
2016-06-27 01:45:38 +02:00
{
2020-04-02 13:19:14 +02:00
checkServiceRecord . RoundedDuration = dauer % intervall ! = 0 ? dauer + ( intervall - dauer % intervall ) : dauer ;
2016-06-27 01:45:38 +02:00
}
2025-06-11 22:56:25 +02:00
checkServiceRecord . CostBearer2SupportConceptOid = Model . SelectedCostBearerSupportConceptOid ;
2016-06-27 01:45:38 +02:00
}
}
2025-01-29 01:13:44 +01:00
var mandator = MobileSessionFacade . Mandator ;
2020-04-08 14:44:20 +02:00
2024-03-14 17:18:35 +01:00
var maxDaysEditSRsAllowedString = GetSettingValue ( mandator . Settings , SettingsKeys . MaxDaysEditServiceRecordsAllowed ) ;
2021-05-17 14:01:06 +02:00
var limitFuerZeiterfassungString = GetSettingValue ( mandator . Settings , SettingsKeys . AnzTageZeiterfassErfolgt ) ;
2020-04-08 14:44:20 +02:00
2024-03-14 17:18:35 +01:00
if ( ! int . TryParse ( maxDaysEditSRsAllowedString , out var maxDaysEditSRsAllowed ) )
2020-04-08 14:44:20 +02:00
{
maxDaysEditSRsAllowed = 0 ;
}
2021-05-17 14:01:06 +02:00
if ( ! int . TryParse ( limitFuerZeiterfassungString , out var limitFuerZeiterfassung ) )
2020-04-08 14:44:20 +02:00
{
limitFuerZeiterfassung = 0 ;
}
2018-12-10 23:40:38 -04:00
2025-06-11 22:56:25 +02:00
if ( LoggedInUser . HasRight ( UserRightType . ServiceRecord_AllowEditAfterMaxDaysInNextMonth ) )
2018-12-10 23:40:38 -04:00
{
maxDaysEditSRsAllowed = - 1 ;
}
2016-06-27 01:45:38 +02:00
SupportConceptStatisticsDC stats = null ;
2018-01-29 12:57:10 +01:00
2025-06-11 22:56:25 +02:00
if ( Model . SelectedCostBearerSupportConceptOid ! = null & & Model . SelectedCostBearerSupportConceptOid > 0 )
2016-06-27 01:45:38 +02:00
{
2025-06-11 22:56:25 +02:00
stats = OperationsService . CreateSupportConceptStatistics ( Model . SelectedCostBearerSupportConceptOid . Value , DateTime . Now ) ;
2016-06-27 01:45:38 +02:00
}
2024-03-14 17:18:35 +01:00
var employeeOids = new List < long > { checkServiceRecord . Employee . EmployeeOid } ;
2018-11-30 16:47:57 -04:00
2018-12-10 23:40:38 -04:00
var validationResults = new List < ServiceRecord2Validation > ( ) ;
2020-04-02 13:19:14 +02:00
checkServiceRecord . ServiceRecordFormat = ServiceRecordFormate . OriginaleZeiterfassung ;
2022-12-30 16:28:23 +01:00
if ( Model . IsEndDateVisible )
{
checkServiceRecord . ServiceRecordFormat = ServiceRecordFormate . ZeiterfassungMitEndDatum ;
}
checkServiceRecord . DurationInStunden = Model . IsShowingDurationInHours ? ZeiterfassungsDauer . Stunden : ZeiterfassungsDauer . Minuten ;
2018-11-30 16:47:57 -04:00
2018-12-12 14:27:40 -04:00
string dateRangeString = null ;
2018-12-03 19:14:35 -04:00
2024-03-14 17:18:35 +01:00
// Gruppenbuchung
2018-11-30 16:47:57 -04:00
if ( Model . IsInGroupBookingMode )
2016-06-27 01:45:38 +02:00
{
2023-10-25 21:52:23 +02:00
ServiceRecordGroupDC serviceRecordGroup = null ;
2024-03-14 17:18:35 +01:00
if ( checkServiceRecord . GroupOid . HasValue )
2018-11-30 16:47:57 -04:00
{
2023-10-25 21:52:23 +02:00
serviceRecordGroup = OperationsService . GetServiceRecordGroup ( checkServiceRecord . GroupOid . Value ) ;
2018-11-30 16:47:57 -04:00
2022-12-30 16:28:23 +01:00
serviceRecordGroup . ServiceRecordList . DoForEach ( sr = > employeeOids . AddIfNotIn ( sr . Employee . EmployeeOid ) ) ;
2018-11-30 16:47:57 -04:00
}
else
{
2022-12-30 16:28:23 +01:00
Model . GroupBookingSelectedEmployees . DoForEach ( e = > employeeOids . AddIfNotIn ( e . EmployeeOid ) ) ;
2018-11-30 16:47:57 -04:00
}
2016-06-27 01:45:38 +02:00
2025-07-15 14:26:03 +02:00
var costBearer2SupportConceptOids = Model . GroupBookingSelectedCostBearerSupportConceptOids ;
2023-10-25 21:52:23 +02:00
var relations = CustomerService . GetSupportConceptCostBearerRelationsById ( costBearer2SupportConceptOids ) ;
2018-11-30 16:47:57 -04:00
2023-10-25 21:52:23 +02:00
var isNew = checkServiceRecord . ServiceRecordOid is null ;
2018-11-30 16:47:57 -04:00
2023-10-25 21:52:23 +02:00
if ( isNew )
2018-11-30 16:47:57 -04:00
{
2024-03-14 17:18:35 +01:00
foreach ( var rel in relations )
2023-10-25 21:52:23 +02:00
{
var sr = CloneServiceRecord ( checkServiceRecord ) ;
2018-11-30 16:47:57 -04:00
2023-10-25 21:52:23 +02:00
sr . SupportConcept = rel . SupportConcept ;
sr . CostBearer = rel . CostBearer ;
sr . CostBearer2SupportConceptOid = rel . CostBearer2SupportConceptOid ;
2025-04-02 17:44:39 +02:00
sr . Customer = rel . SupportConcept ? . Customer ;
2024-03-14 17:18:35 +01:00
2023-10-25 21:52:23 +02:00
var result = OperationsService . ValidateServiceRecord ( sr , null , maxDaysEditSRsAllowed , employeeOids , costBearer2SupportConceptOids ) ;
dateRangeString = rel . DateRangeString ;
2025-04-11 18:02:24 +02:00
validationResults . AddIfNotIn ( new ServiceRecord2Validation ( sr , result , dateRangeString ) ) ;
2023-10-25 21:52:23 +02:00
}
}
else if ( serviceRecordGroup ! = null )
{
foreach ( var serviceRecord in serviceRecordGroup . ServiceRecordList )
{
var sr = CloneServiceRecord ( checkServiceRecord ) ;
sr . ServiceRecordOid = serviceRecord . ServiceRecordOid ;
sr . SupportConcept = serviceRecord . SupportConcept ;
sr . CostBearer = serviceRecord . CostBearer ;
sr . CostBearer2SupportConceptOid = serviceRecord . CostBearer2SupportConceptOid ;
2025-04-02 17:44:39 +02:00
sr . Customer = serviceRecord . SupportConcept ? . Customer ;
2018-12-03 19:14:35 -04:00
2023-10-25 21:52:23 +02:00
var result = OperationsService . ValidateServiceRecord ( sr , null , maxDaysEditSRsAllowed , employeeOids , costBearer2SupportConceptOids ) ;
2025-07-17 16:26:07 +02:00
var node = CreateFlatSupportConceptItem ( GetCompactSupportConcept ( sr . SupportConcept . SupportConceptOid ) , null ) ;
2023-10-25 21:52:23 +02:00
dateRangeString = node ? . SupportConceptTreeNodeDC ! = null ? node . SupportConceptTreeNodeDC . SupportConceptCostBearerRelDC . DateRangeString : string . Empty ;
2025-04-11 18:02:24 +02:00
validationResults . AddIfNotIn ( new ServiceRecord2Validation ( sr , result , dateRangeString ) ) ;
2023-10-25 21:52:23 +02:00
}
2018-11-30 16:47:57 -04:00
}
2024-03-14 17:18:35 +01:00
} // Einzelbuchung
2022-12-30 16:28:23 +01:00
else if ( ! Model . IsInMultiBookingMode )
2018-11-30 16:47:57 -04:00
{
2024-03-14 17:18:35 +01:00
if ( Model . SelectedSupportConcept ! = null )
2018-12-12 14:27:40 -04:00
{
2025-07-17 16:26:07 +02:00
var node = CreateFlatSupportConceptItem ( GetCompactSupportConcept ( Model . SelectedSupportConcept . SupportConceptOid ) , null ) ;
2018-12-12 14:27:40 -04:00
dateRangeString = node ? . SupportConceptTreeNodeDC ! = null ? node . SupportConceptTreeNodeDC . SupportConceptCostBearerRelDC . DateRangeString : "" ;
}
2018-12-03 19:14:35 -04:00
2024-07-24 16:45:56 +02:00
var result = OperationsService . ValidateServiceRecord ( checkServiceRecord , stats , maxDaysEditSRsAllowed , null , null ) ;
2025-04-11 18:02:24 +02:00
validationResults . AddIfNotIn ( new ServiceRecord2Validation ( checkServiceRecord , result , dateRangeString ? ? "" ) ) ;
2024-03-14 17:18:35 +01:00
} // Mehrfachbuchung
2022-12-30 16:28:23 +01:00
else if ( Model . IsInMultiBookingMode & & ! Model . IsInGroupBookingMode )
{
2025-07-15 14:26:03 +02:00
employeeOids . AddRangeIfElementsNotIn ( Model . GroupBookingSelectedEmployees . Select ( e = > e . EmployeeOid ) ) ;
2022-12-30 16:28:23 +01:00
2025-07-15 14:26:03 +02:00
var cb2ScOids = Model . GroupBookingSelectedCostBearerSupportConceptOids ;
2022-12-30 16:28:23 +01:00
var relations = CustomerService . GetSupportConceptCostBearerRelationsById ( cb2ScOids ) ;
foreach ( var costBearer2SupportConceptRel in relations )
{
dateRangeString = costBearer2SupportConceptRel . DateRangeString ? ? string . Empty ;
2024-03-14 17:18:35 +01:00
var prototype = CloneServiceRecord ( checkServiceRecord ) ;
prototype . Customer = costBearer2SupportConceptRel . SupportConcept . Customer ;
prototype . SupportConcept = costBearer2SupportConceptRel . SupportConcept ;
prototype . CostBearer = costBearer2SupportConceptRel . CostBearer ;
2022-12-30 16:28:23 +01:00
prototype . CostBearer2SupportConceptOid = costBearer2SupportConceptRel . CostBearer2SupportConceptOid ;
var organisation = CustomerService . LoadOrganisationCompact ( costBearer2SupportConceptRel . CostBearer . OrganisationOid ) ;
if ( ! ( organisation is null ) )
{
var calculations = Calculations . GetInstance ( organisation . CostBearerID ) ;
prototype . RoundedDuration = calculations . GetRoundedDuration ( organisation , dauer ) ;
}
var multiBookingValidationResults = OperationsService . ValidateServiceRecord ( prototype , null , maxDaysEditSRsAllowed , employeeOids , cb2ScOids ) ;
2025-04-11 18:02:24 +02:00
validationResults . AddIfNotIn ( new ServiceRecord2Validation ( prototype , multiBookingValidationResults , dateRangeString ) ) ;
2022-12-30 16:28:23 +01:00
}
}
2018-11-30 16:47:57 -04:00
2025-06-11 22:56:25 +02:00
var user = LoggedInUser ;
var allowOverlappingFls = user . HasRight ( UserRightType . ServiceRecord_AllowCreateOverlappingFLS ) ;
var allowOverlappingFlsForEmployee = user . HasRight ( UserRightType . ServiceRecord_AllowCreateOverlappingFLSForEmployee ) ;
var allowMoreFlsThanApproved = user . HasRight ( UserRightType . ServiceRecord_AllowCreateMoreFLSThanApproved ) ;
var bookAfterSettlementInvoice = user . HasRight ( UserRightType . BookServiceRecordAfterSettlementInvoice ) ;
var bookServiceRecordOutOfSupportConcept = user . HasRight ( UserRightType . BookServiceRecordOutOfSupportConcept ) ;
var allowCreateAfterEmployeeSignature = user . HasRight ( UserRightType . ServiceRecord_AllowCreateAfterEmployeeSignature ) ;
var allowEditAfterEmployeeSignature = user . HasRight ( UserRightType . ServiceRecord_AllowEditAfterEmployeeSignature ) ;
2020-10-20 21:07:26 +02:00
2025-06-11 22:56:25 +02:00
var allowCreateAll = user . HasRight ( UserRightType . CreateAll ) ;
var allowEditAll = user . HasRight ( UserRightType . CreateAll ) ;
2020-10-01 11:45:48 +02:00
2018-12-10 23:40:38 -04:00
var newResult = new ValidationResult ( ) ;
2024-03-14 17:18:35 +01:00
var exitLoop = false ;
2020-10-20 21:07:26 +02:00
if ( Model . SelectedSupportConcept ! = null & & Model . SelectedSupportConcept . Goals . Any ( ) & & Model . SelectedGoals . Count = = 0 )
{
2020-11-09 17:55:01 +01:00
newResult . Message + = "Es wurden keine Ziele zugeordnet.<br/><br/>" ;
newResult . KannTrotzdemGespeichertWerden = true ;
exitLoop = false ;
2020-10-20 21:07:26 +02:00
}
2024-03-14 17:18:35 +01:00
foreach ( var sr2V in validationResults )
2018-12-10 23:40:38 -04:00
{
if ( exitLoop )
{
break ;
}
2024-03-14 17:18:35 +01:00
foreach ( var vr in sr2V . ValidationResults )
2018-12-10 23:40:38 -04:00
{
2024-03-14 17:18:35 +01:00
if ( exitLoop )
2018-12-10 23:40:38 -04:00
{
break ;
}
switch ( vr . ResultType )
{
case ServiceRecordOverlapping :
2024-03-14 17:18:35 +01:00
newResult . Message = $"An dem gewählten Datum {von:dd.MM.yyyy} existiert bereits ein Eintrag ({vr.Message} bei Klient/in {vr.CustomerName}).<br /><br />" ;
2025-01-31 15:15:40 +01:00
newResult . KannTrotzdemGespeichertWerden = allowOverlappingFls ;
2024-03-14 17:18:35 +01:00
2025-01-31 15:15:40 +01:00
exitLoop = ! allowOverlappingFls ;
2019-03-29 14:04:12 +01:00
2018-12-10 23:40:38 -04:00
break ;
case EmployeeOverlapping :
2024-03-14 17:18:35 +01:00
newResult . Message + = $"An dem gewählten Datum {von:dd.MM.yyyy} existiert bereits ein Eintrag von {vr.EmployeeName} ({vr.Message}).<br /><br />" ;
2025-01-31 15:15:40 +01:00
newResult . KannTrotzdemGespeichertWerden = allowOverlappingFlsForEmployee ;
exitLoop = ! allowOverlappingFlsForEmployee ;
2024-03-14 17:18:35 +01:00
2018-12-10 23:40:38 -04:00
break ;
case OutsideOfSupportConcept :
2024-03-14 17:18:35 +01:00
newResult . Message + = $"Das gewählte Datum {von:dd.MM.yyyy} liegt außerhalb des Zeitraumes des gewählten Hilfeplans ({sr2V.HilfePlanZeitraum}).<br /><br />" ;
2020-04-02 13:19:14 +02:00
newResult . KannTrotzdemGespeichertWerden = bookServiceRecordOutOfSupportConcept ;
2024-03-14 17:18:35 +01:00
2020-04-02 13:19:14 +02:00
exitLoop = ! bookServiceRecordOutOfSupportConcept ;
2024-03-14 17:18:35 +01:00
2018-12-10 23:40:38 -04:00
break ;
case ApprovedFLSOverspending :
var klient = "diesen Hilfeplan" ;
2024-03-14 17:18:35 +01:00
if ( ! string . IsNullOrEmpty ( vr . CustomerName ) )
2018-12-10 23:40:38 -04:00
{
klient = "Klient/in " + vr . CustomerName ;
}
2023-03-31 12:32:08 +02:00
var msg = "Die für " + klient + " genehmigten FLS (" + vr . ApprovedHours + ") werden mit diesem Eintrag überschritten. (" + vr . HoursNew + ")." ;
2024-03-14 17:18:35 +01:00
2019-03-29 14:04:12 +01:00
newResult . Message + = msg + "<br /><br />" ;
2025-01-31 15:15:40 +01:00
newResult . KannTrotzdemGespeichertWerden = allowMoreFlsThanApproved ;
2018-12-10 23:40:38 -04:00
2025-01-31 15:15:40 +01:00
exitLoop = ! allowMoreFlsThanApproved ;
2024-03-14 17:18:35 +01:00
2018-12-10 23:40:38 -04:00
break ;
case OutOfEditLimit :
2023-03-31 12:32:08 +02:00
newResult . Message + = "Sie k&oml;nnen keine neuen Leistungen für den " + von + " dokumentieren, da bereits der " + maxDaysEditSRsAllowed + ". des nachfolgenden Monats überschritten ist.<br /><br />" ;
2018-12-10 23:40:38 -04:00
exitLoop = true ;
newResult . KannTrotzdemGespeichertWerden = false ;
break ;
2025-07-24 10:21:01 +02:00
case ServiceRecordValidationResult . Error :
2018-12-12 14:27:40 -04:00
newResult . Message + = "Beim Speichern ist ein Fehler aufgetreten.<br /><br />" ;
2018-12-10 23:40:38 -04:00
exitLoop = true ;
newResult . KannTrotzdemGespeichertWerden = false ;
break ;
case SettlementInvoiceAlreadyExisting :
var klient2 = "diesen Hilfeplan" ;
if ( ! string . IsNullOrEmpty ( vr . CustomerName ) )
{
klient2 = "Klient/in " + vr . CustomerName ;
}
2019-03-29 14:04:12 +01:00
newResult . KannTrotzdemGespeichertWerden = bookAfterSettlementInvoice ;
exitLoop = ! bookAfterSettlementInvoice ;
2024-03-14 17:18:35 +01:00
if ( bookAfterSettlementInvoice )
2018-12-10 23:40:38 -04:00
{
2023-03-31 12:32:08 +02:00
newResult . Message + = "Es existiert bereits eine Spitzabrechnung für " + klient2 + ". Um diesen Eintrag zu berücksichtigen, muss eventuell eine neue Spitzabrechnung erstellt werden.<br /><br />" ;
2018-12-10 23:40:38 -04:00
}
else
{
2023-03-31 12:32:08 +02:00
newResult . Message + = "Sie können den Eintrag nicht bearbeiten, da bereits eine Spitzabrechnung für " + klient2 + "<br /><br />" ;
2018-12-10 23:40:38 -04:00
}
2025-03-25 17:36:15 +01:00
break ;
2018-12-10 23:40:38 -04:00
case FristAbgelaufen :
var intervall = "einem Tag" ;
2024-03-14 17:18:35 +01:00
if ( limitFuerZeiterfassung ! = 1 )
2018-12-10 23:40:38 -04:00
{
intervall = "" + limitFuerZeiterfassung + " Tagen" ;
}
2025-06-11 22:56:25 +02:00
if ( ! LoggedInUser . HasRight ( UserRightType . ServiceRecordAllowEditAfterMindays ) )
2024-07-24 16:45:56 +02:00
{
if ( limitFuerZeiterfassung = = 1 )
{
newResult . Message + = $"Sie können keine neuen Leistungen für den {von} dokumentieren, da die Zeiterfassung innerhalb von einem Tag erfolgen muss.<br /><br />" ;
}
else
{
newResult . Message + = $"Sie können keine neuen Leistungen für den {von} dokumentieren, da die Zeiterfassung innerhalb von {intervall} erfolgen muss.<br /><br />" ;
}
2025-02-06 12:42:27 +01:00
newResult . KannTrotzdemGespeichertWerden = false ;
2024-07-24 16:45:56 +02:00
exitLoop = true ;
}
2025-03-25 17:36:15 +01:00
break ;
2018-12-10 23:40:38 -04:00
case Custom :
2018-12-12 14:27:40 -04:00
newResult . Message + = vr . Message + "<br /><br />" ;
2018-12-10 23:40:38 -04:00
exitLoop = true ;
2023-09-13 14:21:52 +02:00
newResult . KannTrotzdemGespeichertWerden = vr . Allow ;
2018-12-10 23:40:38 -04:00
break ;
2023-07-12 11:38:39 +02:00
case SignatureExists :
2025-04-02 17:44:39 +02:00
var klient3 = "diesem Hilfeplan" ;
if ( ! string . IsNullOrEmpty ( vr . CustomerName ) )
{
klient3 = "Klient " + vr . CustomerName ;
}
2025-04-11 18:02:24 +02:00
newResult . Message + = $"Für den ausgewählten Zeitraum existiert bereits eine Monatsunterschrift bei {klient3}, die mit dem Anlegen dieses Eintrags verfällt und neu geleistet werden muss.<br /><br />" ;
2025-04-02 17:44:39 +02:00
2023-07-12 11:38:39 +02:00
exitLoop = false ;
newResult . KannTrotzdemGespeichertWerden = true ;
break ;
2018-12-10 23:40:38 -04:00
}
}
}
2016-06-27 01:45:38 +02:00
2021-07-05 18:05:43 +02:00
var signatureValidationResult = OperationsService . CheckForExistingSignature ( checkServiceRecord ) ;
if ( signatureValidationResult ! = null & & newResult . KannTrotzdemGespeichertWerden )
{
newResult . Message + = $"<br />{signatureValidationResult.Message}<br /><br />" ;
}
2024-03-14 17:18:35 +01:00
if ( ! string . IsNullOrEmpty ( newResult . Message ) )
2018-12-12 14:27:40 -04:00
{
2025-04-02 17:44:39 +02:00
newResult . Message + = newResult . KannTrotzdemGespeichertWerden ? newResult . Message . Contains ( "Möchten Sie trotzdem speichern?" ) ? string . Empty : "<br />Möchten Sie trotzdem speichern?<br /><br />" : "<br />Speichern nicht möglich.<br /><br />" ;
2024-03-14 17:18:35 +01:00
Model . SelectedServiceRecord = checkServiceRecord ;
2018-12-12 14:27:40 -04:00
}
2016-06-27 01:45:38 +02:00
Model . NewServiceRecord = new ServiceRecordDC ( ) ;
2024-03-14 17:18:35 +01:00
if ( newResult ? . Message ! = null )
{
TempData [ TempDataServiceRecordValidationKey ] = newResult ;
TempData [ TempDataFormIdKey ] = formId ;
}
else
{
var formCollection2 = new FormCollection
{
[FormCollectionConstants.DateKey] = von ,
[FormCollectionConstants.EndDateKey] = bis ,
[FormCollectionConstants.StartKey] = start ,
[FormCollectionConstants.EndKey] = end ,
[FormCollectionConstants.DurationKey] = durationRaw ,
[FormCollectionConstants.DistanceKey] = distanceRaw ,
2024-09-12 14:55:35 +02:00
[FormCollectionConstants.BetragKey] = betragRaw ,
2025-01-22 16:42:02 +01:00
[FormCollectionConstants.MarkerKey] = markerRaw ,
2024-03-14 17:18:35 +01:00
[FormCollectionConstants.ServiceDescriptionKey] = serviceDescription ,
[FormCollectionConstants.Dokumentation1Key] = doku1 ,
[FormCollectionConstants.Dokumentation2Key] = doku2 ,
[FormCollectionConstants.Dokumentation3Key] = doku3 ,
[FormCollectionConstants.Dokumentation4Key] = doku4 ,
[FormCollectionConstants.Dokumentation5Key] = doku5 ,
[FormCollectionConstants.Dokumentation6Key] = Model . Dokutypes ! = null & & Model . Dokutypes . Length = = 0 ? doku1 : null
} ;
TempData [ TempDataConstants . AfterValidationStateKey ] = null ;
if ( Model . IsInGroupBookingMode )
{
return CreateOrUpdateGroupBooking ( formCollection2 ) ;
}
return Model . IsInMultiBookingMode ? CreateMultiBooking ( formCollection2 ) : CreateOrUpdateServiceRecord ( formCollection2 ) ;
}
if ( decimal . TryParse ( distanceRaw , out var distanceInMeters ) & & Model . SelectedServiceRecord ! = null )
{
Model . SelectedServiceRecord . DistanceInMeterDecimal = distanceInMeters ;
}
2024-03-20 16:41:05 +01:00
if ( decimal . TryParse ( durationRaw , out var duration ) & &
Model . SelectedServiceRecord ! = null & &
Model . SelectedServiceRecord . RoundedDuration = = 0 )
2024-03-14 17:18:35 +01:00
{
2024-03-21 10:29:12 +01:00
Model . SelectedServiceRecord . RoundedDuration = Model . SelectedDurationUnit = = "Stunden" | | Model . EinheitZeiterfassung = = 1 ? duration * 60 : duration ;
2024-03-14 17:18:35 +01:00
}
2025-06-11 22:56:25 +02:00
Model . SelectedServiceRecordOid = Model . SelectedServiceRecord ? . ServiceRecordOid ;
2024-03-14 17:18:35 +01:00
TempData [ TempDataConstants . AfterValidationStateKey ] = true ;
return View ( "Main" , Model ) ;
2016-06-27 01:45:38 +02:00
}
2020-10-20 21:07:26 +02:00
[Authorize]
public string ValidateServiceRecordDeletion ( string serviceRecordOidString )
{
2025-07-17 16:26:07 +02:00
SkipModelInitialization = true ;
if ( ! IsUserLoggedIn ( ) )
2020-10-20 21:07:26 +02:00
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2020-10-20 21:07:26 +02:00
}
var isSuccessful = long . TryParse ( serviceRecordOidString , out var serviceRecordOid ) ;
if ( ! isSuccessful )
{
return "Error" ;
}
var newResult = new ValidationResult ( ) ;
2025-07-17 16:26:07 +02:00
var serviceRecord = GetServiceRecordDC ( serviceRecordOid , true ) ;
2021-05-17 14:01:06 +02:00
2022-08-10 14:13:29 +02:00
if ( serviceRecord is null )
2021-05-17 14:01:06 +02:00
{
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2021-05-17 14:01:06 +02:00
}
2020-10-20 21:07:26 +02:00
2025-06-11 22:56:25 +02:00
var validationResultList = OperationsService . ValidateServiceRecordDeletion ( serviceRecord , Model . LoggedInEmployee . EmployeeOid . Value ) ;
2023-07-24 17:57:14 +02:00
2020-10-20 21:07:26 +02:00
if ( validationResultList . Count > 0 )
{
foreach ( var result in validationResultList )
{
switch ( result . ResultType )
{
case Custom :
newResult . KannTrotzdemGespeichertWerden = true ;
2023-07-24 17:57:14 +02:00
2025-05-23 15:57:18 +02:00
newResult . Message + = RemoveConfirmationFromValidationResultMessage ( result . Message ) + "<br><br>" ;
2020-10-20 21:07:26 +02:00
break ;
}
}
2023-07-24 17:57:14 +02:00
if ( newResult . Message ? . Length > 0 )
{
newResult . Message + = "Möchten Sie ihn trotzdem löschen?<br/><br/>" ;
}
2020-10-20 21:07:26 +02:00
return SerializeObject ( newResult ) ;
}
2020-11-09 17:55:01 +01:00
return serviceRecord . GroupOid ! = null
2025-05-23 15:57:18 +02:00
? SerializeObject ( new ValidationResult { KannTrotzdemGespeichertWerden = true , Message = "ACHTUNG, wenn Sie fortfahren, löschen Sie die gesamte Gruppenbuchung.<br>Wenn Sie nur einzelne Klienten aus der Gruppe entfernen möchten, editieren Sie die Gruppe und entfernen den Klienten aus der Liste der Hilfepläne.<br/>Sind Sie sicher, dass Sie den gesamten Gruppeneintrag löschen möchten?<br><br>" } )
2020-11-09 17:55:01 +01:00
: SerializeObject ( new ValidationResult { KannTrotzdemGespeichertWerden = true , Message = null } ) ;
2020-10-20 21:07:26 +02:00
}
2023-07-24 17:57:14 +02:00
private static string RemoveConfirmationFromValidationResultMessage ( string resultMessage )
{
if ( resultMessage is null )
{
return string . Empty ;
}
var confirmation = "Möchten Sie ihn trotzdem löschen?" ;
if ( resultMessage . Contains ( confirmation ) )
{
var length = resultMessage . Length - confirmation . Length ;
if ( length > 0 )
{
resultMessage = resultMessage . Substring ( 0 , length ) ;
}
}
return resultMessage ;
}
2021-05-17 14:01:06 +02:00
[Authorize]
2020-04-02 13:19:14 +02:00
public string SetServiceRecordEmployee ( long employeeOid )
2016-06-27 01:45:38 +02:00
{
2020-04-02 13:19:14 +02:00
try
2016-06-27 01:45:38 +02:00
{
2024-07-24 16:45:56 +02:00
if ( Model is null )
2020-04-02 13:19:14 +02:00
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2020-04-02 13:19:14 +02:00
}
2016-06-27 01:45:38 +02:00
2022-12-30 16:28:23 +01:00
Model . SelectedEmployee = Model . AllEmployees . First ( f = > f . EmployeeOid . Equals ( employeeOid ) ) ;
2025-06-11 22:56:25 +02:00
Model . SelectedEmployeeOid = Model . SelectedEmployee ? . EmployeeOid ;
2024-09-12 14:55:35 +02:00
return Model . SelectedEmployee ? . DetailDescription ? ? LeerzeichenFuerGetMethoden ;
2020-04-02 13:19:14 +02:00
}
2024-07-24 16:45:56 +02:00
catch ( Exception e )
2020-04-02 13:19:14 +02:00
{
Log . Info ( "Error in SetServiceRecordEmployee:" ) ;
Log . Error ( e . Message , e ) ;
2020-04-24 19:08:09 +02:00
2023-01-04 19:55:12 +01:00
if ( Model ? . AllEmployees is null )
2020-04-02 13:19:14 +02:00
{
2023-01-04 19:55:12 +01:00
Log . Info ( "Weitere Infos: Model oder AllEmployees = null!" ) ;
2020-04-02 13:19:14 +02:00
}
else
{
2022-12-30 16:28:23 +01:00
Log . Info ( $"Weitere Infos: AllEmployees enthält {Model.AllEmployees.Count} Elemente: " ) ;
2020-04-24 19:08:09 +02:00
var stringBuilder = new StringBuilder ( ) ;
2022-12-30 16:28:23 +01:00
foreach ( var ce in Model . AllEmployees )
2020-04-02 13:19:14 +02:00
{
2020-04-24 19:08:09 +02:00
if ( stringBuilder . Length > 0 )
2020-04-02 13:19:14 +02:00
{
2020-04-24 19:08:09 +02:00
stringBuilder . Append ( "," ) ;
2020-04-02 13:19:14 +02:00
}
2016-06-27 01:45:38 +02:00
2020-04-24 19:08:09 +02:00
stringBuilder . Append ( ce . EmployeeOid ) ;
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
}
2020-04-24 19:08:09 +02:00
Log . Info ( stringBuilder . ToString ( ) ) ;
2020-04-02 13:19:14 +02:00
}
2020-04-24 19:08:09 +02:00
2020-04-02 13:19:14 +02:00
throw e ;
2018-01-29 12:57:10 +01:00
}
2020-04-02 13:19:14 +02:00
}
2016-06-27 01:45:38 +02:00
2021-05-17 14:01:06 +02:00
[Authorize]
2020-04-02 13:19:14 +02:00
public string CheckToken ( string token )
{
if ( token ! = null & & token . Equals ( "abcd" ) )
2018-01-29 12:57:10 +01:00
{
2020-04-02 13:19:14 +02:00
return SerializeObject ( "localhost;demo" ) ;
2018-01-29 12:57:10 +01:00
}
2016-06-27 01:45:38 +02:00
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2020-04-02 13:19:14 +02:00
}
2016-06-27 01:45:38 +02:00
2024-01-12 17:16:52 +01:00
#region Menü
2020-04-08 14:44:20 +02:00
// Menünavigation
2020-09-14 19:07:23 +02:00
[Authorize]
2020-04-02 13:19:14 +02:00
public ActionResult RedirectToScheduler ( )
{
return RedirectToActionPermanent ( "Scheduler" , "Scheduler" ) ;
}
2016-06-27 01:45:38 +02:00
2020-09-14 19:07:23 +02:00
[Authorize]
2020-04-02 13:19:14 +02:00
public ActionResult RedirectToCustomer ( )
{
if ( Model ? . SelectedSupportConcept ? . Customer ? . Oid . HasValue ? ? false )
2018-01-29 12:57:10 +01:00
{
2023-11-13 11:33:08 +01:00
return RedirectToActionPermanent ( "Customer" , "Customer" , new { id = Model . SelectedSupportConcept . Customer . Oid } ) ;
2020-04-02 13:19:14 +02:00
}
2016-06-27 01:45:38 +02:00
2025-06-11 22:56:25 +02:00
//if(Model?.SelectedSupportConcept is null && (CustomerModel)Session[ModelSessionConstants.CustomerModelKey] != null)
//{
// var customerModel = (CustomerModel) Session[ModelSessionConstants.CustomerModelKey];
// customerModel.SelectedCustomerOid = null;
// customerModel.SelectedCustomer = null;
//}
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
return RedirectToActionPermanent ( "Customer" , "Customer" ) ;
}
2016-06-27 01:45:38 +02:00
2020-09-14 19:07:23 +02:00
[Authorize]
public ActionResult RedirectToReportView ( )
{
2025-06-11 22:56:25 +02:00
return Model . HasRightToViewQuittierungsbelege ? RedirectToAction ( "InitReports" , "Report" ) : RedirectToMain ( ) ;
2020-09-14 19:07:23 +02:00
}
2023-03-16 13:57:04 +01:00
[Authorize]
public ActionResult RedirectToReportViewer ( )
{
return RedirectToActionPermanent ( "ReportViewer" , "ReportViewer" ) ;
}
2020-04-02 13:19:14 +02:00
public ActionResult RedirectToMain ( )
{
return RedirectToActionPermanent ( "Main" , "Main" ) ;
}
2019-07-29 19:40:14 +02:00
2021-08-19 17:22:04 +02:00
[Authorize]
public ActionResult RedirectToDevExpressScheduler ( )
{
#if DEBUG
return RedirectToActionPermanent ( "DevExpressScheduler" , "DevExpressScheduler" ) ;
#endif
return RedirectToMain ( ) ;
}
2025-03-25 17:36:15 +01:00
[Authorize]
2025-07-18 19:37:01 +02:00
public ActionResult RedirectToDevTools ( )
2025-03-25 17:36:15 +01:00
{
#if DEBUG
2025-07-18 19:37:01 +02:00
return RedirectToActionPermanent ( "DevTools" , "DevTools" ) ;
2025-03-25 17:36:15 +01:00
#endif
return RedirectToMain ( ) ;
}
2024-01-12 17:16:52 +01:00
#endregion
2021-08-19 17:22:04 +02:00
2019-03-29 14:04:12 +01:00
// Gruppenbuchungen
2018-04-18 14:33:21 +02:00
[HttpPost]
[Authorize]
public ActionResult SetGroupBookingMode ( FormCollection pFormCollection )
{
2025-07-15 14:26:03 +02:00
SkipModelInitialization = true ;
if ( ! IsUserLoggedIn ( ) )
2018-12-03 19:14:35 -04:00
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2020-10-07 19:42:17 +02:00
return Logout ( ) ;
2018-12-03 19:14:35 -04:00
}
2025-06-27 13:11:10 +02:00
Model . TransferringAppointmentOid = null ;
Model . IsInTransferMode = false ;
2023-03-03 21:54:36 +01:00
2022-12-30 16:28:23 +01:00
var bookingMode = "true,false" = = pFormCollection [ FormCollectionConstants . IsInGroupBookingModeKey ] ? BookingMode . GroupBookingMode : BookingMode . SingleBookingMode ;
2018-04-18 14:33:21 +02:00
2022-12-30 16:28:23 +01:00
ResetBookingMode ( bookingMode ) ;
2018-04-18 14:33:21 +02:00
2018-11-30 16:47:57 -04:00
return RedirectToAction ( "Main" ) ;
}
2020-08-04 12:45:46 +02:00
/// <summary>
/// Setzt die getroffenen Auswahlen zurück
/// </summary>
2023-01-04 19:55:12 +01:00
/// <param name="bookingMode">
2025-03-25 17:36:15 +01:00
/// Einzelbuchung, Gruppenbuchung oder Mehrfachbuchung wie im FaC
2023-01-04 19:55:12 +01:00
/// </param>
2022-12-30 16:28:23 +01:00
private void ResetBookingMode ( BookingMode bookingMode )
2018-11-30 16:47:57 -04:00
{
2024-07-24 16:45:56 +02:00
if ( Model is null )
2018-12-03 19:14:35 -04:00
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
2018-12-03 19:14:35 -04:00
return ;
}
2023-03-14 16:12:52 +01:00
ResetModel ( ) ;
2022-12-30 16:28:23 +01:00
Model . IsInGroupBookingMode = bookingMode = = BookingMode . GroupBookingMode ;
Model . IsInMultiBookingMode = bookingMode = = BookingMode . MultiBookingMode ;
2018-11-30 16:47:57 -04:00
2022-12-30 16:28:23 +01:00
if ( bookingMode = = BookingMode . GroupBookingMode )
2018-04-18 14:33:21 +02:00
{
2022-12-30 16:28:23 +01:00
ResetMultiBookingMode ( ) ;
2025-06-11 22:56:25 +02:00
Model . PreviouslySelectedEmployeeOid = Model . SelectedEmployeeOid ;
2025-06-17 13:06:29 +02:00
//Model.PreviouslySelectedSupportConceptOid = Model.SelectedSupportConceptOid;
2025-06-11 22:56:25 +02:00
Model . PreviouslySelectedCostbearer2SupportConceptOid = Model . SelectedCostBearerSupportConceptOid ;
2020-04-02 13:19:14 +02:00
2025-06-17 13:06:29 +02:00
//Model.SelectedSupportConceptOid = null;
2025-06-11 22:56:25 +02:00
Model . SelectedCostBearerSupportConceptOid = null ;
Model . SelectedEmployeeOid = null ;
2018-04-18 14:33:21 +02:00
2025-06-11 22:56:25 +02:00
Model . GroupBookingSelectedEmployeeOids . AddIfNotIn ( LoggedInUser . Employee . EmployeeOid ) ;
2020-04-24 19:08:09 +02:00
2021-05-17 14:01:06 +02:00
Model . IsInEditingMode = false ;
2025-06-11 22:56:25 +02:00
Model . SelectedServiceRecordOid = null ;
2018-04-18 14:33:21 +02:00
}
2022-12-30 16:28:23 +01:00
if ( bookingMode = = BookingMode . MultiBookingMode )
2018-04-18 14:33:21 +02:00
{
2022-12-30 16:28:23 +01:00
ResetGroupBookingMode ( ) ;
2020-04-02 13:19:14 +02:00
2025-06-11 22:56:25 +02:00
Model . PreviouslySelectedEmployeeOid = Model . SelectedEmployeeOid ;
2025-06-17 13:06:29 +02:00
//Model.PreviouslySelectedSupportConceptOid = Model.SelectedSupportConceptOid;
2025-06-11 22:56:25 +02:00
Model . PreviouslySelectedCostbearer2SupportConceptOid = Model . SelectedCostBearerSupportConceptOid ;
2022-12-30 16:28:23 +01:00
2024-03-14 17:18:35 +01:00
2025-06-17 13:06:29 +02:00
//Model.SelectedSupportConceptOid = null;
2025-06-11 22:56:25 +02:00
Model . SelectedCostBearerSupportConceptOid = null ;
Model . SelectedEmployeeOid = null ;
2022-12-30 16:28:23 +01:00
2025-06-11 22:56:25 +02:00
2025-07-15 14:26:03 +02:00
Model . GroupBookingSelectedEmployeeOids . AddIfNotIn ( LoggedInUser . Employee . EmployeeOid ) ;
2022-12-30 16:28:23 +01:00
Model . IsInEditingMode = false ;
2025-06-11 22:56:25 +02:00
Model . SelectedServiceRecordOid = null ;
2022-12-30 16:28:23 +01:00
}
if ( bookingMode = = BookingMode . SingleBookingMode )
{
ResetMultiBookingMode ( ) ;
2025-06-11 22:56:25 +02:00
Model . SelectedEmployeeOid = Model . PreviouslySelectedEmployeeOid ? ? LoggedInUser . Employee . EmployeeOid ;
2024-03-14 17:18:35 +01:00
2025-06-17 13:06:29 +02:00
//if (Model.PreviouslySelectedSupportConceptOid.HasValue)
//{
// Model.SelectedSupportConceptOid = Model.PreviouslySelectedSupportConceptOid;
//}
2025-06-11 22:56:25 +02:00
if ( Model . PreviouslySelectedCostbearer2SupportConceptOid . HasValue )
{
Model . SelectedCostBearerSupportConceptOid = Model . PreviouslySelectedCostbearer2SupportConceptOid ;
}
2022-12-30 16:28:23 +01:00
ResetGroupBookingMode ( ) ;
2025-06-17 13:06:29 +02:00
ResetMultiBookingMode ( ) ;
2018-11-30 16:47:57 -04:00
}
2024-07-24 16:45:56 +02:00
2025-06-17 13:06:29 +02:00
//Model.SelectedSupportConceptOid = Model.SelectedSupportConcept?.SupportConceptOid;
2025-06-11 22:56:25 +02:00
Model . SelectedEmployeeOid = Model . SelectedEmployee ? . EmployeeOid ;
Model . SelectedServiceRecordOid = Model . SelectedServiceRecord ? . ServiceRecordOid ;
2018-04-18 14:33:21 +02:00
}
2022-12-30 16:28:23 +01:00
private void ResetMultiBookingMode ( )
{
2024-07-24 16:45:56 +02:00
Model . Categories2Descriptions . Clear ( ) ;
2025-06-11 22:56:25 +02:00
2025-07-04 00:30:36 +02:00
//Model.MultiBookingSelectedConceptCostBearerRelations.Clear();
2025-07-15 14:26:03 +02:00
Model . GroupBookingSelectedCostBearerSupportConceptOids . Clear ( ) ;
Model . GroupBookingSelectedCostBearerSupportConcepts . Clear ( ) ;
Model . GroupBookingSelectedEmployeeOids . Clear ( ) ;
Model . GroupBookingSelectedEmployees . Clear ( ) ;
Model . GroupBookingSelectedGroupOfPeopleOids . Clear ( ) ;
2022-12-30 16:28:23 +01:00
}
private void ResetGroupBookingMode ( )
{
2024-07-24 16:45:56 +02:00
Model . Categories2Descriptions . Clear ( ) ;
2025-07-15 14:26:03 +02:00
Model . GroupBookingSelectedCostBearerSupportConceptOids . Clear ( ) ;
Model . GroupBookingSelectedCostBearerSupportConcepts . Clear ( ) ;
2025-06-11 22:56:25 +02:00
Model . GroupBookingSelectedEmployeeOids . Clear ( ) ;
2025-07-15 14:26:03 +02:00
Model . GroupBookingSelectedEmployees . Clear ( ) ;
Model . GroupBookingSelectedGroupOfPeopleOids . Clear ( ) ;
2022-12-30 16:28:23 +01:00
}
2024-03-14 17:18:35 +01:00
[HttpPost]
[Authorize]
public ActionResult ResetSingleBookingForm ( )
{
2024-06-26 12:29:22 +02:00
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return Logout ( ) ;
}
2024-03-14 17:18:35 +01:00
ResetBookingMode ( BookingMode . SingleBookingMode ) ;
2025-07-15 14:26:03 +02:00
LoadSupportConceptThings ( Model . SelectedCostBearerSupportConceptOid , false ) ;
2024-07-24 16:45:56 +02:00
2024-03-14 17:18:35 +01:00
return View ( "Main" , Model ) ;
}
[HttpPost]
[Authorize]
public ActionResult ResetGroupBookingForm ( )
{
2024-06-26 12:29:22 +02:00
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
}
2024-03-14 17:18:35 +01:00
ResetBookingMode ( BookingMode . GroupBookingMode ) ;
return View ( "Main" , Model ) ;
}
[HttpPost]
[Authorize]
public ActionResult ResetMultiBookingForm ( )
{
2024-06-26 12:29:22 +02:00
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return Logout ( ) ;
}
2025-06-17 13:06:29 +02:00
//if(Model.PreviouslySelectedSupportConceptOid != null && Model.SelectedSupportConceptOid is null)
if ( Model . PreviouslySelectedCostbearer2SupportConceptOid ! = null & & Model . SelectedCostBearerSupportConceptOid is null )
2024-03-14 17:18:35 +01:00
{
2025-06-17 13:06:29 +02:00
//Model.SelectedSupportConceptOid = Model.PreviouslySelectedSupportConceptOid;
2025-06-11 22:56:25 +02:00
Model . SelectedCostBearerSupportConceptOid = Model . PreviouslySelectedCostbearer2SupportConceptOid ;
2024-03-14 17:18:35 +01:00
}
ResetModel ( ) ;
return View ( "Main" , Model ) ;
}
2018-04-18 14:33:21 +02:00
[HttpPost]
[Authorize]
2020-12-16 21:49:47 +01:00
public ActionResult ResetEditingMode ( )
2018-04-18 14:33:21 +02:00
{
2025-07-15 14:26:03 +02:00
if ( ! IsUserLoggedIn ( ) )
2018-12-03 19:14:35 -04:00
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2020-10-07 19:42:17 +02:00
return Logout ( ) ;
2018-12-03 19:14:35 -04:00
}
2025-07-15 14:26:03 +02:00
SkipModelInitialization = true ;
2023-03-03 21:54:36 +01:00
ResetModel ( ) ;
2025-06-27 13:11:10 +02:00
Model . TransferringAppointmentOid = null ;
Model . IsInTransferMode = false ;
2023-03-03 21:54:36 +01:00
return RedirectToActionPermanent ( "Main" ) ;
}
[Authorize]
[HttpPost]
public ActionResult ResetTransferMode ( )
{
if ( Model is null )
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2023-03-03 21:54:36 +01:00
return Logout ( ) ;
}
2025-06-27 13:11:10 +02:00
Model . TransferringAppointmentOid = null ;
Model . IsInTransferMode = false ;
2023-03-03 21:54:36 +01:00
ResetModel ( ) ;
return RedirectToScheduler ( ) ;
}
[Authorize]
private void ResetModel ( )
{
if ( Model is null )
{
return ;
}
2024-03-14 17:18:35 +01:00
TempData [ TempDataConstants . AfterValidationStateKey ] = null ;
2023-03-03 21:54:36 +01:00
2025-06-11 22:56:25 +02:00
Model . NewServiceRecord = new ServiceRecordDC ( ) ;
Model . SelectedServiceRecordOid = null ;
2023-03-03 21:54:36 +01:00
Model . IsInEditingMode = false ;
2025-06-11 22:56:25 +02:00
Model . SelectedEmployeeOid = LoggedInUser . Employee . EmployeeOid ;
2025-07-15 14:26:03 +02:00
Model . GroupBookingSelectedCostBearerSupportConceptOids . Clear ( ) ;
Model . GroupBookingSelectedCostBearerSupportConcepts . Clear ( ) ;
2022-12-30 16:28:23 +01:00
Model . GroupBookingSelectedGroupOfPeopleOids . Clear ( ) ;
2025-06-11 22:56:25 +02:00
Model . GroupBookingSelectedEmployeeOids = new List < long > { LoggedInUser . Employee . EmployeeOid } ;
2023-03-03 21:54:36 +01:00
Model . IsInMultiBookingMode = false ;
2025-06-11 22:56:25 +02:00
Model . SelectedGoalOids . Clear ( ) ;
2025-07-17 16:26:07 +02:00
Model . SelectedGoals . Clear ( ) ;
2025-06-11 22:56:25 +02:00
Model . SelectedServiceCategoryOid = null ;
Model . SelectedServiceDescriptionOid = null ;
2020-08-04 12:45:46 +02:00
2025-06-11 22:56:25 +02:00
//LoadServiceCategoriesToModel(Model.SelectedCostBearerSupportConceptOid);
2024-06-26 12:29:22 +02:00
2025-06-11 22:56:25 +02:00
//Model.MainSessionModel.ResetValues();
2016-06-27 01:45:38 +02:00
}
2023-03-03 21:54:36 +01:00
2018-11-24 14:28:46 -04:00
[Authorize]
2024-06-05 14:45:33 +02:00
public ActionResult AddScCbRelsToGroupBooking ( string [ ] relOids , string [ ] groupOids )
2017-04-26 14:57:32 +02:00
{
2025-07-15 14:26:03 +02:00
SkipModelInitialization = true ;
if ( ! IsUserLoggedIn ( ) )
2024-06-26 12:29:22 +02:00
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return PartialView ( "GroupBookingScCbRelList" ) ;
}
2024-06-05 14:45:33 +02:00
var singleRels = new List < long > ( ) ;
var groupRels = new List < long > ( ) ;
var groups = new List < GroupOfPeopleDC > ( ) ;
if ( groupOids is null )
2018-12-03 19:14:35 -04:00
{
2024-06-05 14:45:33 +02:00
groupOids = Array . Empty < string > ( ) ;
2018-12-03 19:14:35 -04:00
}
2024-06-05 14:45:33 +02:00
if ( relOids is null )
{
relOids = Array . Empty < string > ( ) ;
}
relOids . DoForEach ( relOid = >
{
if ( long . TryParse ( relOid , out var singleRelOid ) )
{
singleRels . AddIfNotIn ( singleRelOid ) ;
}
} ) ;
groupOids . DoForEach ( groupOid = >
{
if ( long . TryParse ( groupOid , out var g ) )
{
groupRels . AddIfNotIn ( g ) ;
}
} ) ;
2018-01-29 12:57:10 +01:00
2022-12-30 16:28:23 +01:00
Model . GroupBookingSelectedGroupOfPeopleOids . Clear ( ) ;
2018-02-07 14:14:08 +01:00
2024-06-05 14:45:33 +02:00
groupRels . DoForEach ( groupOid = >
2018-11-24 14:28:46 -04:00
{
2024-06-05 14:45:33 +02:00
var group = Model . GroupsOfPeople . FirstOrDefault ( f = > f . GroupOfPeopleOid . HasValue & & f . GroupOfPeopleOid . Value . Equals ( groupOid ) ) ;
2022-08-10 14:13:29 +02:00
if ( group is null )
2018-11-24 14:28:46 -04:00
{
2019-03-29 14:04:12 +01:00
return ;
2018-11-24 14:28:46 -04:00
}
2024-06-05 14:45:33 +02:00
2019-03-29 14:04:12 +01:00
groups . AddIfNotIn ( group ) ;
2024-06-05 14:45:33 +02:00
group . SupportConceptList . DoForEach ( f = > singleRels . AddRangeIfElementsNotIn ( f . CostBearerRelOids ) ) ;
2019-03-29 14:04:12 +01:00
} ) ;
2018-11-24 14:28:46 -04:00
2025-07-15 14:26:03 +02:00
Model . GroupBookingSelectedCostBearerSupportConcepts . Clear ( ) ;
2025-06-11 22:56:25 +02:00
2018-11-24 14:28:46 -04:00
2025-07-15 14:26:03 +02:00
Model . GroupBookingSelectedCostBearerSupportConceptOids . Clear ( ) ;
Model . GroupBookingSelectedCostBearerSupportConceptOids . AddRangeIfElementsNotIn ( singleRels ) ;
2024-06-05 14:45:33 +02:00
2025-07-15 14:26:03 +02:00
//var selectedSupportConcepts = CustomerService.GetSupportConceptsByCostbearer2SupportConceptRelOids(singleRels);
2018-11-24 14:28:46 -04:00
2025-07-15 14:26:03 +02:00
//var groupCostBearerRelations = CustomerService.GetSupportConceptCostBearerRelationsById(singleRels);
2018-11-24 14:28:46 -04:00
2025-07-15 14:26:03 +02:00
2023-01-04 19:55:12 +01:00
foreach ( var gruppe in groups . Where ( g = > g . GroupOfPeopleOid . HasValue ) )
2018-11-24 14:28:46 -04:00
{
var groupRelOids = new List < long > ( ) ;
gruppe . SupportConceptList . ForEach ( f = > groupRelOids . AddRange ( f . CostBearerRelOids ) ) ;
2024-06-05 14:45:33 +02:00
if ( ! gruppe . GroupOfPeopleOid . HasValue )
2018-11-24 14:28:46 -04:00
{
continue ;
}
var groupOid = gruppe . GroupOfPeopleOid . Value ;
2024-06-05 14:45:33 +02:00
if ( singleRels . ContainsItems ( groupRelOids ) )
2018-11-24 14:28:46 -04:00
{
2022-12-30 16:28:23 +01:00
Model . GroupBookingSelectedGroupOfPeopleOids . AddIfNotIn ( groupOid ) ;
2018-11-24 14:28:46 -04:00
}
2023-01-04 19:55:12 +01:00
else if ( Model . GroupBookingSelectedGroupOfPeopleOids . Contains ( groupOid ) )
2018-11-24 14:28:46 -04:00
{
2022-12-30 16:28:23 +01:00
Model . GroupBookingSelectedGroupOfPeopleOids . Remove ( groupOid ) ;
2018-11-24 14:28:46 -04:00
}
}
2025-07-15 14:26:03 +02:00
//Model.SelectedConceptCostBearerRelationOids = Model.SelectedConceptCostBearerRelations.Select(s => s.CostBearer2SupportConceptOid.Value).ToList();
//Model.GroupBookingSelectedSupportConceptOids = Model.GroupBookingSelectedSupportConcepts.Select(s => s.SupportConceptOid.Value).ToList();
CreateModelSupportConceptListObjects ( false ) ;
2025-07-17 16:26:07 +02:00
LoadSupportConceptThings ( null , true ) ;
2025-06-11 22:56:25 +02:00
2024-06-05 14:45:33 +02:00
return PartialView ( "GroupBookingScCbRelList" , Model ) ;
}
[Authorize]
public ActionResult RemoveSupportConceptCostbearerRel ( string relOid )
{
2024-06-26 12:29:22 +02:00
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return PartialView ( "GroupBookingSelectionPartial" ) ;
}
2025-07-15 14:26:03 +02:00
if ( ! long . TryParse ( relOid , out var c2sOid ) )
2024-06-05 14:45:33 +02:00
{
2024-06-26 12:29:22 +02:00
return PartialView ( "GroupBookingSelectionPartial" , Model ) ;
2024-06-05 14:45:33 +02:00
}
2025-07-15 14:26:03 +02:00
RemoveRelOidFromGroupBooking ( c2sOid ) ;
2025-06-11 22:56:25 +02:00
2024-06-26 12:29:22 +02:00
return PartialView ( "GroupBookingSelectionPartial" , Model ) ;
2018-02-07 14:14:08 +01:00
}
2018-11-30 16:47:57 -04:00
[Authorize]
2024-06-26 12:29:22 +02:00
public ActionResult ReloadGroupBookingForm ( )
2018-11-30 16:47:57 -04:00
{
2022-08-10 14:13:29 +02:00
if ( Model is null )
2018-12-03 19:14:35 -04:00
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
}
else
{
2025-07-16 12:38:01 +02:00
//LoadServiceCategoriesToModel(null);
2018-12-03 19:14:35 -04:00
}
2024-06-26 12:29:22 +02:00
return PartialView ( "GroupBookingSelectionPartial" , Model ) ;
2019-03-29 14:04:12 +01:00
}
[Authorize]
public string AddEmployeesToGroupBooking ( string pEmployeeOids )
{
2022-08-10 14:13:29 +02:00
if ( Model is null )
2019-03-29 14:04:12 +01:00
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2019-03-29 14:04:12 +01:00
}
if ( string . IsNullOrEmpty ( pEmployeeOids ) )
{
2022-12-30 16:28:23 +01:00
Model . GroupBookingSelectedEmployees . Clear ( ) ;
2025-06-11 22:56:25 +02:00
Model . GroupBookingSelectedEmployeeOids . Clear ( ) ;
2022-12-30 16:28:23 +01:00
return JsonConvert . SerializeObject ( Model . GroupBookingSelectedEmployees . Count ) ;
2019-03-29 14:04:12 +01:00
}
var rawEmployeeOids = pEmployeeOids . Split ( ',' ) ;
var oids = new List < long > ( ) ;
rawEmployeeOids . DoForEach ( s = > oids . AddIfNotIn ( long . Parse ( s ) ) ) ;
2023-03-31 12:32:08 +02:00
var employees = Model . EmployeesForGroupAndMultiBooking . Where ( w = > oids . Contains ( w . EmployeeOid ) ) ;
2019-03-29 14:04:12 +01:00
2022-12-30 16:28:23 +01:00
Model . GroupBookingSelectedEmployees . Clear ( ) ;
Model . GroupBookingSelectedEmployees . AddRangeIfElementsNotIn ( employees ) ;
2025-06-11 22:56:25 +02:00
Model . GroupBookingSelectedEmployeeOids = Model . GroupBookingSelectedEmployees . Select ( e = > e . EmployeeOid ) . ToList ( ) ;
2020-08-04 12:45:46 +02:00
2022-12-30 16:28:23 +01:00
return JsonConvert . SerializeObject ( Model . GroupBookingSelectedEmployees . Count ) ;
2025-06-11 22:56:25 +02:00
2018-11-30 16:47:57 -04:00
}
2019-04-17 17:01:37 +02:00
[Authorize]
2021-04-13 19:45:21 +02:00
public string GetSignatureImage ( long serviceRecordOid , long signatureOid )
2019-04-17 17:01:37 +02:00
{
2025-07-17 16:26:07 +02:00
SkipModelInitialization = true ;
if ( ! IsUserLoggedIn ( ) )
2019-04-17 17:01:37 +02:00
{
2021-04-13 19:45:21 +02:00
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2019-04-17 17:01:37 +02:00
}
2025-07-17 16:26:07 +02:00
var signatureServiceRecord = GetServiceRecordDC ( serviceRecordOid , true ) ;
2021-04-13 19:45:21 +02:00
var signatureServiceRecordHeader = MainModel . GetServiceRecordTimeHeader ( signatureServiceRecord , false ) ;
2019-04-17 17:01:37 +02:00
2021-04-13 19:45:21 +02:00
var signatureImage = OperationsService . GetSignature ( signatureOid ) . DataBild ;
2022-08-11 15:10:01 +02:00
return signatureServiceRecordHeader + ";" + ApplyWatermark ( signatureImage , Server . MapPath ( "../Content/images/bewoplaner_by_ownsoft_logo_mok.png" ) ) ;
2019-04-17 17:01:37 +02:00
}
2021-04-19 04:38:29 +02:00
[HttpPost]
public ActionResult LogOutAfterSessionTimeout ( )
{
Logout ( ) ;
return RedirectToActionPermanent ( "Index" , "Login" , new { isSessionTimedOut = true } ) ;
}
2019-07-25 14:56:11 +02:00
2020-04-02 13:19:14 +02:00
[HttpPost]
[Authorize]
2021-04-19 04:38:29 +02:00
public ActionResult SetSupportConceptFilter ( FormCollection formCollection )
2019-07-25 14:56:11 +02:00
{
2022-08-10 14:13:29 +02:00
if ( Model is null )
2019-07-25 14:56:11 +02:00
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2021-04-19 04:38:29 +02:00
return Logout ( ) ;
}
2020-04-02 13:19:14 +02:00
2021-04-19 04:38:29 +02:00
var selectedSupportConceptFilter = formCollection [ nameof ( Model . SelectedSupportConceptFilter ) ] ;
2020-04-02 13:19:14 +02:00
2021-04-19 04:38:29 +02:00
if ( ! Enum . TryParse ( selectedSupportConceptFilter , out CustomerFilterEnum customerFilter ) )
{
customerFilter = CustomerFilterEnum . MyCustomer ;
}
2021-05-17 14:01:06 +02:00
2022-09-07 13:19:08 +02:00
UpdateApplicationSettings ( SettingsKeys . CustomerFilterInZeiterfassung , customerFilter . ToString ( ) ) ;
2020-04-02 13:19:14 +02:00
2021-04-19 04:38:29 +02:00
return RedirectToActionPermanent ( "Main" ) ;
}
2020-04-02 13:19:14 +02:00
2021-04-19 04:38:29 +02:00
[Authorize]
[HttpPost]
public ActionResult CreateOrUpdateGroupBooking ( FormCollection formCollection )
{
2022-08-10 14:13:29 +02:00
if ( Model is null )
2021-04-19 04:38:29 +02:00
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2021-04-19 04:38:29 +02:00
return Logout ( ) ;
}
2020-04-02 13:19:14 +02:00
2021-04-19 04:38:29 +02:00
try
{
if ( ! Model . IsInEditingMode )
2020-04-02 13:19:14 +02:00
{
2025-07-15 14:26:03 +02:00
if ( Model . GroupBookingSelectedCostBearerSupportConceptOids . Count = = 1 )
2020-04-02 13:19:14 +02:00
{
2025-07-15 14:26:03 +02:00
Model . SelectedCostBearerSupportConceptOid = Model . GroupBookingSelectedCostBearerSupportConceptOids . FirstOrDefault ( ) ;
2020-04-02 13:19:14 +02:00
}
}
2021-04-19 04:38:29 +02:00
else
2020-04-02 13:19:14 +02:00
{
2021-04-19 04:38:29 +02:00
var selectedRecordOid = Model . SelectedServiceRecordOid ? ? Model . SelectedServiceRecord . ServiceRecordOid ;
Model . NewServiceRecord = OperationsService . GetServiceRecordById ( selectedRecordOid . Value ) ;
2020-04-02 13:19:14 +02:00
}
string doku1 ;
2019-07-25 14:56:11 +02:00
2020-04-02 13:19:14 +02:00
if ( Model . Dokutypes ! = null & & Model . Dokutypes . Length > 0 )
{
2020-09-21 11:57:10 +02:00
doku1 = formCollection [ FormCollectionConstants . Dokumentation1Key ] ;
2020-04-02 13:19:14 +02:00
}
else
{
2020-09-21 11:57:10 +02:00
doku1 = formCollection [ FormCollectionConstants . Dokumentation6Key ] ;
2020-04-02 13:19:14 +02:00
}
2019-07-25 14:56:11 +02:00
2021-04-19 04:38:29 +02:00
// Wenn kein Datum angegeben wurde, wird die Main-Seite geladen und abgebrochen
2020-09-21 11:57:10 +02:00
if ( string . IsNullOrEmpty ( formCollection [ FormCollectionConstants . DateKey ] ) )
2020-04-02 13:19:14 +02:00
{
return View ( "Main" , Model ) ;
}
2024-03-14 17:18:35 +01:00
// Marker
2023-07-31 15:29:16 +02:00
var marker = "on" = = formCollection [ FormCollectionConstants . MarkerKey ] ;
2024-09-12 14:55:35 +02:00
decimal? betrag = null ;
var betragAsString = formCollection [ FormCollectionConstants . BetragKey ] ? . Replace ( '.' , ',' ) ;
if ( decimal . TryParse ( betragAsString , out var betragAsDecimal ) )
{
betrag = betragAsDecimal ;
}
2024-03-14 17:18:35 +01:00
// Distanz
2020-09-21 11:57:10 +02:00
var distanz = formCollection [ FormCollectionConstants . DistanceKey ] ;
2023-05-23 13:56:22 +02:00
decimal? distanceInMeters = null ;
2020-04-02 13:19:14 +02:00
if ( ! string . IsNullOrEmpty ( distanz ) )
{
2023-05-23 13:56:22 +02:00
if ( decimal . TryParse ( distanz , out var parsedDistance ) )
2020-04-02 13:19:14 +02:00
{
distanceInMeters = parsedDistance ;
}
}
2024-03-14 17:18:35 +01:00
// Kostenträger-Hilfeplan-Relation
2025-06-11 22:56:25 +02:00
var selectedCostbearer2SupportConceptRelOid = Model . SelectedCostBearerSupportConceptOid < 1 ? null : Model . SelectedCostBearerSupportConceptOid ;
2024-03-14 17:18:35 +01:00
// Datumsteil des Startdatums
2020-09-21 11:57:10 +02:00
var datum = Convert . ToDateTime ( formCollection [ FormCollectionConstants . DateKey ] ) ;
2020-04-02 13:19:14 +02:00
2024-03-14 17:18:35 +01:00
// Enddatum wird der gleiche Tag wie vom Start
2020-04-02 13:19:14 +02:00
var enddatum = datum ;
2024-03-14 17:18:35 +01:00
// Es wird geprüft, ob es das Enddatumsfeld gibt (das haben nicht alle Kunden)
2020-09-21 11:57:10 +02:00
var endDateString = formCollection [ FormCollectionConstants . EndDateKey ] ;
2024-03-19 19:10:13 +01:00
if ( endDateString ? . Length > 0 )
2020-04-02 13:19:14 +02:00
{
enddatum = Convert . ToDateTime ( endDateString ) ;
}
2024-03-14 17:18:35 +01:00
// Start- und Endzeit zur Dauerberechnung
2020-09-21 11:57:10 +02:00
var start = formCollection [ FormCollectionConstants . StartKey ] ;
var ende = formCollection [ FormCollectionConstants . EndKey ] ;
2023-06-21 19:19:56 +02:00
var dauer = 0 m ;
2020-04-02 13:19:14 +02:00
if ( datum > enddatum )
{
enddatum = datum ;
}
2023-06-21 19:19:56 +02:00
var durationAsString = formCollection [ FormCollectionConstants . DurationKey ] ;
durationAsString = durationAsString . Replace ( '.' , ',' ) ;
if ( ! string . IsNullOrEmpty ( durationAsString ) )
2020-04-02 13:19:14 +02:00
{
2023-06-21 19:19:56 +02:00
decimal . TryParse ( durationAsString , out dauer ) ;
}
// Wenn die Dauer in Stunden ist
if ( Model . SelectedDurationUnit = = "Stunden" | | Model . EinheitZeiterfassung = = 1 )
{
dauer * = 60 m ;
2020-04-02 13:19:14 +02:00
}
2024-03-14 17:18:35 +01:00
// Dokumentation
2020-09-21 11:57:10 +02:00
var doku2 = formCollection [ FormCollectionConstants . Dokumentation2Key ] ;
var doku3 = formCollection [ FormCollectionConstants . Dokumentation3Key ] ;
var doku4 = formCollection [ FormCollectionConstants . Dokumentation4Key ] ;
var doku5 = formCollection [ FormCollectionConstants . Dokumentation5Key ] ;
2020-04-02 13:19:14 +02:00
2024-06-26 12:29:22 +02:00
// Ziele und Maßnahmen
2024-03-14 17:18:35 +01:00
// Start- und Endstrings werden in DateTime-Objekte konvertiert
2020-04-02 13:19:14 +02:00
var zeitenFeld = new DateTime [ 2 ] ;
if ( start = = string . Empty & & ende = = string . Empty )
{
zeitenFeld [ 0 ] = new DateTime ( datum . Year , datum . Month , datum . Day , 0 , 0 , 1 ) ;
if ( enddatum = = datum )
{
2023-06-21 19:19:56 +02:00
zeitenFeld [ 1 ] = new DateTime ( datum . Year , datum . Month , datum . Day , 0 , 0 , 1 ) . AddMinutes ( Convert . ToDouble ( dauer ) ) ;
2020-04-02 13:19:14 +02:00
}
else
{
2023-06-21 19:19:56 +02:00
zeitenFeld [ 1 ] = new DateTime ( enddatum . Year , enddatum . Month , enddatum . Day , 0 , 0 , 1 ) . AddMinutes ( Convert . ToDouble ( dauer ) ) ;
2020-04-02 13:19:14 +02:00
}
}
else
{
2023-06-21 19:19:56 +02:00
zeitenFeld = enddatum = = datum ? ConvertRecordTimes ( start , ende , datum , Convert . ToDouble ( dauer ) ) : ConvertRecordTimesWithEndDate ( start , ende , datum , enddatum , Convert . ToDouble ( dauer ) ) ;
2020-04-02 13:19:14 +02:00
}
if ( dauer = = 0 | | zeitenFeld [ 1 ] ! = zeitenFeld [ 0 ] )
{
dauer = ( int ) ( zeitenFeld [ 1 ] - zeitenFeld [ 0 ] ) . TotalMinutes ;
}
2022-08-10 14:13:29 +02:00
if ( Model . NewServiceRecord is null )
2020-04-02 13:19:14 +02:00
{
return RedirectToActionPermanent ( "Main" ) ;
}
Model . NewServiceRecord . IP = Request . UserHostAddress ;
2025-07-15 14:26:03 +02:00
Model . NewServiceRecord . Goals = CreateValueListEntriesFromMokZiele ( Model . SelectedGoals ) ;
2020-04-02 13:19:14 +02:00
Model . NewServiceRecord . Start = zeitenFeld [ 0 ] ;
Model . NewServiceRecord . End = zeitenFeld [ 1 ] ;
2024-09-12 14:55:35 +02:00
Model . NewServiceRecord . Betrag = betrag ;
2020-04-02 13:19:14 +02:00
2023-07-31 15:29:16 +02:00
if ( marker )
{
Model . NewServiceRecord . ServiceRecordType = ServiceRecordTypeId . Content ;
}
2023-05-23 13:56:22 +02:00
Model . NewServiceRecord . DistanceInMeterDecimal = distanceInMeters ;
2020-04-02 13:19:14 +02:00
2025-06-11 22:56:25 +02:00
if ( Model . LoggedInEmployee . EmployeeOid . HasValue )
2020-04-02 13:19:14 +02:00
{
2020-07-15 14:37:43 +02:00
2024-03-14 17:18:35 +01:00
if ( Model . SelectedEmployee ! = null )
2020-04-02 13:19:14 +02:00
{
Model . NewServiceRecord . Employee = Model . SelectedEmployee ;
}
2025-07-16 12:38:01 +02:00
2025-07-17 16:26:07 +02:00
var sclo = Model . SupportConceptListObjects . FirstOrDefault ( a = > a . CostBearer2SupportConceptOid . Equals ( selectedCostbearer2SupportConceptRelOid ) ) ;
2025-07-16 12:38:01 +02:00
if ( sclo ! = null )
2020-04-02 13:19:14 +02:00
{
2025-07-17 16:26:07 +02:00
var sc = GetCompactSupportConcept ( sclo . SupportConceptOid ) ;
2025-07-16 12:38:01 +02:00
Model . NewServiceRecord . SupportConcept = sc ;
Model . NewServiceRecord . Customer = sc . Customer ;
2020-04-02 13:19:14 +02:00
2025-07-16 12:38:01 +02:00
var cb2ScRel = sc . CostBearerList . FirstOrDefault ( ) ;
2025-07-15 14:26:03 +02:00
Model . NewServiceRecord . CostBearer = cb2ScRel . Organisation ;
2020-04-02 13:19:14 +02:00
var intervall = Model . NewServiceRecord . CostBearer . ActualMinuteIntervall ;
if ( intervall > 0 )
{
Model . NewServiceRecord . RoundedDuration = dauer % intervall ! = 0 ? dauer + ( intervall - dauer % intervall ) : dauer ;
}
else
{
Model . NewServiceRecord . RoundedDuration = dauer ;
}
2020-04-24 19:08:09 +02:00
Model . NewServiceRecord . CostBearer2SupportConceptOid = selectedCostbearer2SupportConceptRelOid ;
2020-04-02 13:19:14 +02:00
}
else
{
Model . NewServiceRecord . RoundedDuration = dauer ;
}
}
2022-12-30 16:28:23 +01:00
Model . NewServiceRecord . DurationInStunden = Model . IsZeiterfassungInStdMin ? ZeiterfassungsDauer . Stunden : ZeiterfassungsDauer . Minuten ;
2020-04-02 13:19:14 +02:00
Model . NewServiceRecord . ServiceRecordFormat = ServiceRecordFormate . OriginaleZeiterfassung ;
2022-12-30 16:28:23 +01:00
if ( Model . IsEndDateVisible )
{
Model . NewServiceRecord . ServiceRecordFormat = ServiceRecordFormate . ZeiterfassungMitEndDatum ;
}
2020-04-02 13:19:14 +02:00
Model . NewServiceRecord . Notice = string . IsNullOrEmpty ( doku1 ) ? null : doku1 ;
Model . NewServiceRecord . Notice2 = string . IsNullOrEmpty ( doku2 ) ? null : doku2 ;
Model . NewServiceRecord . Notice3 = string . IsNullOrEmpty ( doku3 ) ? null : doku3 ;
Model . NewServiceRecord . Notice4 = string . IsNullOrEmpty ( doku4 ) ? null : doku4 ;
Model . NewServiceRecord . Notice5 = string . IsNullOrEmpty ( doku5 ) ? null : doku5 ;
var serviceDescOid = 0L ;
2020-09-21 11:57:10 +02:00
if ( ! string . IsNullOrEmpty ( formCollection [ FormCollectionConstants . ServiceDescriptionKey ] ) )
2020-04-02 13:19:14 +02:00
{
2020-09-21 11:57:10 +02:00
serviceDescOid = Convert . ToInt64 ( formCollection [ FormCollectionConstants . ServiceDescriptionKey ] ) ;
2020-07-15 14:37:43 +02:00
}
else if ( Model . SelectedServiceDescriptionOid . HasValue )
2020-04-02 13:19:14 +02:00
{
serviceDescOid = Model . SelectedServiceDescriptionOid . Value ;
}
if ( serviceDescOid > 0 )
{
Model . NewServiceRecord . ServiceDescription = OperationsService . GetServiceDescription ( serviceDescOid ) ;
}
if ( Model . NewServiceRecord . RoundedDuration = = 0 )
{
Model . NewServiceRecord . RoundedDuration = dauer ;
}
Model . NewServiceRecord . InsertedOn = DateTime . Now ;
2025-06-11 22:56:25 +02:00
Model . NewServiceRecord . InsUser = MobileSessionFacade . EmployeeFullname ;
2020-04-02 13:19:14 +02:00
Model . NewServiceRecord . IsCreatedInMobileClient = true ;
2022-09-07 13:19:08 +02:00
if ( Model . SetStartTimeToEndTimeAfterSave )
{
var previousStartDate = Model . IsInEditingMode ? Model . SelectedServiceRecord ? . Start : Model . NewServiceRecord ? . Start ;
var previousEndDate = Model . IsInEditingMode ? Model . SelectedServiceRecord ? . End : Model . NewServiceRecord ? . End ;
2025-06-27 13:11:10 +02:00
if ( previousStartDate . HasValue & & previousEndDate . HasValue )
2022-09-07 13:19:08 +02:00
{
var duration = ( previousEndDate - previousStartDate ) . Value . TotalMinutes ;
Model . NewStartDate = previousEndDate ;
Model . NewEndDate = previousEndDate . Value . AddMinutes ( duration ) ;
}
}
2021-04-19 04:38:29 +02:00
2022-08-19 13:53:32 +02:00
return Model . IsInEditingMode ? UpdateGroupBooking ( ) : SaveGroupBooking ( ) ;
2020-04-02 13:19:14 +02:00
}
2021-04-19 04:38:29 +02:00
catch ( Exception exception )
2020-04-02 13:19:14 +02:00
{
2021-04-19 04:38:29 +02:00
Log . Error ( exception . Message , exception ) ;
2020-04-02 13:19:14 +02:00
}
2020-12-16 21:49:47 +01:00
return ResetEditingMode ( ) ;
2019-07-25 14:56:11 +02:00
}
2022-09-07 13:19:08 +02:00
2025-07-17 16:26:07 +02:00
private CompactSupportConceptDC GetCompactSupportConcept ( long supportConceptOid )
{
CompactSupportConceptDC sc = null ;
if ( Model . SupportConcepts ! = null )
{
//sc = Model.SupportConcepts.FirstOrDefault(s => s.SupportConceptOid == supportConceptOid);
}
if ( sc = = null )
{
sc = CustomerService . LoadCompactSupportConceptDC ( supportConceptOid , Model . LoggedInEmployee . EmployeeOid ) ;
}
return sc ;
}
2022-09-07 13:19:08 +02:00
[Authorize]
public string ToggleDurationUnit ( bool isInHoursMode )
{
if ( Model is null )
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2022-09-07 13:19:08 +02:00
}
Model . IsShowingDurationInHours = isInHoursMode ;
UpdateUserSettingsWithoutReload ( SettingsKeys . LetzteZeiterfassungsDauer , Model . IsShowingDurationInHours ? "1" : "0" ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2022-09-07 13:19:08 +02:00
}
2022-12-30 16:28:23 +01:00
2025-06-11 22:56:25 +02:00
2023-02-23 11:48:41 +01:00
2023-03-29 15:49:20 +02:00
/// <summary>
/// Bereitet die Übernahme eines Termins in die Zeiterfassung vor. Wird im SchedulerController aufgerufen.
/// </summary>
2025-06-27 13:11:10 +02:00
/// <returns>Main.cshtml</returns>
2023-02-23 11:48:41 +01:00
[Authorize]
public ActionResult PrepareServiceRecordInsert ( )
{
if ( Model is null )
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2023-02-23 11:48:41 +01:00
return Logout ( ) ;
}
2025-06-27 13:11:10 +02:00
Model . TransferringAppointmentOid = TempData [ TempDataConstants . AppointmentOidKey ] as long? ;
2023-03-03 21:54:36 +01:00
2025-06-27 13:11:10 +02:00
if ( Model . TransferringAppointmentOid . HasValue & & Model . LoggedInEmployee . EmployeeOid . HasValue )
{
var app = DAOFactory . GenericDAO . LoadByID < SchedulerAppointment > ( Model . TransferringAppointmentOid . Value ) ;
2025-06-11 22:56:25 +02:00
var appointment = MapperFactory . SchedulerAppointmentDCSchedulerAppointment . MapToNewDC ( app ) ;
2023-02-23 11:48:41 +01:00
var start = appointment . StartDate ;
var end = appointment . EndDate ;
var customerOids = appointment . CustomerList . Select ( customer = > customer . CustomerOid ) . ToList ( ) ;
var employeeOids = appointment . EmployeeList . Select ( e2a = > e2a . Employee . EmployeeOid ) . ToList ( ) ;
2023-03-03 21:54:36 +01:00
if ( appointment . AllDay & & start . HasValue & & end . HasValue )
2023-02-23 11:48:41 +01:00
{
2023-03-03 21:54:36 +01:00
start = start . Value . MergeDateWithHoursMinutesSeconds ( 0 , 0 , 1 ) ;
end = end . Value . MergeDateWithHoursMinutesSeconds ( 0 , 0 , 1 ) ;
}
if ( employeeOids . Count = = 0 )
{
2025-06-11 22:56:25 +02:00
employeeOids . Add ( Model . LoggedInEmployee . EmployeeOid . Value ) ;
2023-02-23 11:48:41 +01:00
}
2023-03-03 21:54:36 +01:00
var notice = appointment . Description ;
2023-02-23 11:48:41 +01:00
var customerService = PluginLoader . FindClass < CustomerService > ( ) ;
2025-06-11 22:56:25 +02:00
var supportConcepts = customerService . GetAllActiveSupportConceptCostbearer ( false , true , Model . LoggedInEmployee . EmployeeOid . Value ) ;
2023-02-23 11:48:41 +01:00
supportConcepts = supportConcepts . Where ( sc = > customerOids . Contains ( sc . Customer . CustomerOid ) & & sc . StartDate . HasValue & & sc . EndDate . HasValue & & start . Value . AreInBetweenDates ( end . Value , sc . StartDate . Value , sc . EndDate . Value ) ) . ToList ( ) ;
var supportConceptList = new List < CompactSupportConceptDC > ( ) ;
foreach ( var customerOid in customerOids )
{
var supportConcept = supportConcepts . FirstOrDefault ( sc = > sc . Customer . CustomerOid . Equals ( customerOid ) ) ;
if ( supportConcept is null )
{
continue ;
}
supportConceptList . AddIfNotIn ( supportConcept ) ;
}
// Ohne Hilfeplan
if ( supportConceptList . Count = = 0 )
{
2023-03-03 21:54:36 +01:00
ResetBookingMode ( BookingMode . SingleBookingMode ) ;
2025-06-11 22:56:25 +02:00
Model . SelectedEmployee = Model . AllEmployees . FirstOrDefault ( e = > e . EmployeeOid . Equals ( Model . LoggedInEmployee . EmployeeOid . Value ) ) ;
2023-02-23 11:48:41 +01:00
2025-07-15 14:26:03 +02:00
LoadSupportConceptThings ( - 2 , false ) ;
2023-02-23 11:48:41 +01:00
2024-07-24 16:45:56 +02:00
if ( Model . SelectedServiceDescription ! = null )
2023-02-23 11:48:41 +01:00
{
2024-07-24 16:45:56 +02:00
Model . SelectedServiceCategory = Model . SelectedServiceDescription . Category ;
2023-02-23 11:48:41 +01:00
var serviceRecord = CreateServiceRecordFromScratch ( start . Value , end . Value , null , Model . SelectedEmployee , notice ) ;
2024-07-24 16:45:56 +02:00
serviceRecord . ServiceDescription = Model . SelectedServiceDescription ;
2023-02-23 11:48:41 +01:00
Model . SelectedServiceRecord = serviceRecord ;
}
2024-07-24 16:45:56 +02:00
}
2023-02-23 11:48:41 +01:00
// Einzelbuchung
2024-07-24 16:45:56 +02:00
else
2023-02-23 11:48:41 +01:00
{
2024-07-24 16:45:56 +02:00
var availableRelOids = new List < long > ( ) ;
Model . SupportConceptListObjects . DoForEach ( sclo = >
{
2025-06-11 22:56:25 +02:00
availableRelOids . AddIfNotIn ( sclo . CostBearer2SupportConceptOid ) ;
2024-07-24 16:45:56 +02:00
} ) ;
2023-03-03 21:54:36 +01:00
2024-07-24 16:45:56 +02:00
if ( supportConceptList . Count = = 1 & & employeeOids . Count = = 1 )
{
ResetBookingMode ( BookingMode . SingleBookingMode ) ;
2023-02-23 11:48:41 +01:00
2024-07-24 16:45:56 +02:00
Model . SelectedEmployee = Model . AllEmployees . FirstOrDefault ( e = > e . EmployeeOid . Equals ( employeeOids . FirstOrDefault ( ) ) ) ;
2023-02-23 11:48:41 +01:00
2024-07-24 16:45:56 +02:00
var compactSupportConcept = supportConceptList . First ( ) ;
2025-07-15 14:26:03 +02:00
var supportConcept = Model . SupportConcepts . FirstOrDefault ( f = > f . SupportConceptOid . Equals ( compactSupportConcept . SupportConceptOid ) ) ;
2023-02-23 11:48:41 +01:00
2024-07-24 16:45:56 +02:00
var serviceRecord = CreateServiceRecordFromScratch ( start . Value , end . Value , supportConcept ? . Customer , Model . SelectedEmployee , notice ) ;
2023-03-03 21:54:36 +01:00
2025-07-15 14:26:03 +02:00
var costBearer = supportConcept ? . CostBearerList . FirstOrDefault ( ) ;
2023-03-03 21:54:36 +01:00
2025-07-15 14:26:03 +02:00
var cb2ScOid = supportConcept ? . CostBearerRelOids . FirstOrDefault ( cbOid = > availableRelOids . Contains ( cbOid ) ) ;
2023-02-23 11:48:41 +01:00
2025-07-15 14:26:03 +02:00
LoadSupportConceptThings ( cb2ScOid ? ? - 2 , false ) ;
serviceRecord . CostBearer = costBearer ? . Organisation ;
serviceRecord . CostBearer2SupportConceptOid = cb2ScOid ;
2024-07-24 16:45:56 +02:00
serviceRecord . ServiceDescription = Model . SelectedServiceDescription ;
2023-03-03 21:54:36 +01:00
2024-07-24 16:45:56 +02:00
if ( Model . SelectedServiceDescription ! = null )
{
Model . SelectedServiceRecord = serviceRecord ;
}
2023-03-03 21:54:36 +01:00
}
2024-07-24 16:45:56 +02:00
else // Gruppenbuchung
{
ResetBookingMode ( BookingMode . GroupBookingMode ) ;
2023-03-03 21:54:36 +01:00
2024-07-24 16:45:56 +02:00
Model . GroupBookingSelectedEmployees = Model . AllEmployees . Where ( w = > employeeOids . Contains ( w . EmployeeOid ) ) . ToList ( ) ;
2023-03-03 21:54:36 +01:00
2024-07-24 16:45:56 +02:00
var roundedDuration = ( int ) ( ( end - start ) ? . TotalMinutes ? ? 0 ) ;
2023-03-03 21:54:36 +01:00
2024-07-24 16:45:56 +02:00
Model . SelectedServiceRecord = new ServiceRecordDC ( )
{
Start = start ,
End = end ,
RoundedDuration = roundedDuration ,
Notice = notice ,
ServiceDescription = Model . GetSelectedOrFirstServiceDescription ( )
} ;
2023-03-03 21:54:36 +01:00
2025-07-15 14:26:03 +02:00
var supportConceptsForGroupBooking = Model . SupportConcepts . Where ( sc = > supportConceptList . Any ( csc = > csc . SupportConceptOid . Equals ( sc . SupportConceptOid ) ) ) . ToList ( ) ;
2023-03-03 21:54:36 +01:00
2024-07-24 16:45:56 +02:00
var costBearer2SupportConceptOids = new List < long > ( ) ;
2025-07-15 14:26:03 +02:00
2024-07-24 16:45:56 +02:00
foreach ( var supportConcept in supportConceptsForGroupBooking )
2023-03-03 21:54:36 +01:00
{
2025-07-15 14:26:03 +02:00
var cb2ScOid = supportConcept ? . CostBearerRelOids . FirstOrDefault ( cbOid = > availableRelOids . Contains ( cbOid ) ) ;
2024-07-24 16:45:56 +02:00
2025-07-15 14:26:03 +02:00
if ( cb2ScOid is null )
2024-07-24 16:45:56 +02:00
{
continue ;
}
2025-07-15 14:26:03 +02:00
costBearer2SupportConceptOids . AddIfNotIn ( cb2ScOid . Value ) ;
2023-03-03 21:54:36 +01:00
}
2024-07-24 16:45:56 +02:00
if ( costBearer2SupportConceptOids . Any ( ) )
{
2025-07-15 14:26:03 +02:00
Model . GroupBookingSelectedCostBearerSupportConceptOids = costBearer2SupportConceptOids ;
//Model.SelectedConceptCostBearerRelations = costBearer2SupportConcepts;
//Model.GroupBookingSelectedSupportConcepts = supportConceptsForGroupBooking;
2024-07-24 16:45:56 +02:00
}
2023-03-03 21:54:36 +01:00
2025-07-15 14:26:03 +02:00
LoadSupportConceptThings ( null , false ) ;
2023-03-03 21:54:36 +01:00
}
2023-02-23 11:48:41 +01:00
}
2023-03-03 21:54:36 +01:00
2025-06-11 22:56:25 +02:00
Model . SelectedServiceRecordOid = Model . SelectedServiceRecord ? . ServiceRecordOid ;
2025-06-27 13:11:10 +02:00
Model . TransferringAppointmentOid = appointment . SchedulerAppointmentOid ;
Model . IsInTransferMode = true ;
2023-02-23 11:48:41 +01:00
}
return View ( "Main" , Model ) ;
}
private ServiceRecordDC CreateServiceRecordFromScratch ( DateTime start , DateTime end , CompactCustomerDC customer , CompactEmployeeDC employee , string notice )
{
var serviceRecord = new ServiceRecordDC
{
Employee = employee ,
Customer = customer ,
2023-03-14 16:12:52 +01:00
Notice = notice ? . RemoveUppercaseEsszett ( ) ,
2023-02-23 11:48:41 +01:00
InsertedOn = DateTime . Now ,
InsUser = employee ? . ToString ( ) ,
IsCreatedInMobileClient = true
} ;
if ( start . Date ! = end . Date )
{
serviceRecord . Start = end ;
serviceRecord . End = end ;
serviceRecord . RoundedDuration = 0 ;
}
else
{
serviceRecord . Start = start ;
serviceRecord . End = end ;
serviceRecord . RoundedDuration = ( decimal ) end . Subtract ( start ) . TotalMinutes ;
}
if ( Model . IsEndDateVisible )
{
serviceRecord . ServiceRecordFormat = ServiceRecordFormate . ZeiterfassungMitEndDatum ;
}
else if ( Model . IsOnlyYearMonthVisible )
{
serviceRecord . ServiceRecordFormat = ServiceRecordFormate . ZeiterfassungMitMonatJahr ;
}
else
{
serviceRecord . ServiceRecordFormat = ServiceRecordFormate . OriginaleZeiterfassung ;
}
serviceRecord . DurationInStunden = Model . IsShowingDurationInHours ? ZeiterfassungsDauer . Stunden : ZeiterfassungsDauer . Minuten ;
return serviceRecord ;
}
2022-12-30 16:28:23 +01:00
2023-06-18 17:11:35 +02:00
[HttpPost]
[Authorize]
public ActionResult DeleteSignature ( FormCollection formCollection )
{
2025-07-17 16:26:07 +02:00
SkipModelInitialization = true ;
if ( ! IsUserLoggedIn ( ) )
2023-06-18 17:11:35 +02:00
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2023-06-18 17:11:35 +02:00
return Logout ( ) ;
}
try
{
if ( long . TryParse ( formCollection [ "sr-signature-to-del-oid" ] , out var signatureOid ) & & long . TryParse ( formCollection [ "sr-sig-to-del-record-oid" ] , out var serviceRecordOid ) )
{
OperationsService . DeleteSignature ( signatureOid , serviceRecordOid ) ;
}
}
catch ( Exception exception )
{
Log . Error ( exception . Message , exception ) ;
}
return RedirectToActionPermanent ( "Main" ) ;
}
2022-12-30 16:28:23 +01:00
#region Mehrfachbuchung
2024-06-26 12:29:22 +02:00
[Authorize]
public ActionResult ReloadMultiBookingForm ( )
{
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
}
else
{
2025-07-16 12:38:01 +02:00
//LoadServiceCategoriesToModel(null);
2024-06-26 12:29:22 +02:00
}
return PartialView ( "MultiBookingSelectionPartial" , Model ) ;
}
[Authorize]
public ActionResult AddScCbRelsToMultiBooking ( string [ ] relOids , string [ ] groupOids )
{
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return PartialView ( "MultiBookingScCbRelList" ) ;
}
var singleRels = new List < long > ( ) ;
var groupRels = new List < long > ( ) ;
var groups = new List < GroupOfPeopleDC > ( ) ;
if ( groupOids is null )
{
groupOids = Array . Empty < string > ( ) ;
}
if ( relOids is null )
{
relOids = Array . Empty < string > ( ) ;
}
relOids . DoForEach ( relOid = >
{
if ( long . TryParse ( relOid , out var singleRelOid ) )
{
singleRels . AddIfNotIn ( singleRelOid ) ;
}
} ) ;
groupOids . DoForEach ( groupOid = >
{
if ( long . TryParse ( groupOid , out var g ) )
{
groupRels . AddIfNotIn ( g ) ;
}
} ) ;
2025-07-15 14:26:03 +02:00
Model . GroupBookingSelectedGroupOfPeopleOids . Clear ( ) ;
2024-06-26 12:29:22 +02:00
groupRels . DoForEach ( groupOid = >
{
var group = Model . GroupsOfPeople . FirstOrDefault ( f = > f . GroupOfPeopleOid . HasValue & & f . GroupOfPeopleOid . Value . Equals ( groupOid ) ) ;
if ( group is null )
{
return ;
}
groups . AddIfNotIn ( group ) ;
group . SupportConceptList . DoForEach ( f = > singleRels . AddRangeIfElementsNotIn ( f . CostBearerRelOids ) ) ;
} ) ;
2025-07-15 14:26:03 +02:00
//Model.MultiBookingSelectedSupportConcepts.Clear();
2024-06-26 12:29:22 +02:00
2025-07-15 14:26:03 +02:00
Model . GroupBookingSelectedCostBearerSupportConceptOids . Clear ( ) ;
Model . GroupBookingSelectedCostBearerSupportConceptOids . AddRangeIfElementsNotIn ( singleRels ) ;
2024-06-26 12:29:22 +02:00
2025-07-15 14:26:03 +02:00
//var selectedSupportConcepts = CustomerService.GetSupportConceptsByCostbearer2SupportConceptRelOids(singleRels);
2024-06-26 12:29:22 +02:00
2025-07-15 14:26:03 +02:00
//var groupCostBearerRelations = CustomerService.GetSupportConceptCostBearerRelationsById(singleRels);
2024-06-26 12:29:22 +02:00
2025-07-15 14:26:03 +02:00
//Model.MultiBookingSelectedSupportConcepts.AddRangeIfElementsNotIn(selectedSupportConcepts);
2024-06-26 12:29:22 +02:00
foreach ( var gruppe in groups . Where ( g = > g . GroupOfPeopleOid . HasValue ) )
{
var groupRelOids = new List < long > ( ) ;
gruppe . SupportConceptList . ForEach ( f = > groupRelOids . AddRange ( f . CostBearerRelOids ) ) ;
if ( ! gruppe . GroupOfPeopleOid . HasValue )
{
continue ;
}
var groupOid = gruppe . GroupOfPeopleOid . Value ;
if ( singleRels . ContainsItems ( groupRelOids ) )
{
2025-07-15 14:26:03 +02:00
Model . GroupBookingSelectedGroupOfPeopleOids . AddIfNotIn ( groupOid ) ;
2024-06-26 12:29:22 +02:00
}
2025-07-15 14:26:03 +02:00
else if ( Model . GroupBookingSelectedGroupOfPeopleOids . Contains ( groupOid ) )
2024-06-26 12:29:22 +02:00
{
2025-07-15 14:26:03 +02:00
Model . GroupBookingSelectedGroupOfPeopleOids . Remove ( groupOid ) ;
2024-06-26 12:29:22 +02:00
}
}
2025-07-17 16:26:07 +02:00
CreateModelSupportConceptListObjects ( false ) ;
LoadSupportConceptThings ( null , true ) ;
2025-07-15 14:26:03 +02:00
//Model.SelectedConceptCostBearerRelationOids = Model.SelectedConceptCostBearerRelations.Select(s => s.CostBearer2SupportConceptOid.Value).ToList();
//Model.MultiBookingSelectedSupportConceptOids = Model.MultiBookingSelectedSupportConcepts.Select(s => s.SupportConceptOid.Value).ToList();
2025-07-04 00:30:36 +02:00
2024-06-26 12:29:22 +02:00
return PartialView ( "MultiBookingScCbRelList" , Model ) ;
}
[Authorize]
public ActionResult RemoveSupportConceptCostbearerRelFromMultiBooking ( string relOid )
{
2025-07-04 00:30:36 +02:00
//das funktioniert hier noch nicht mit dem letzten Eintrag
2024-06-26 12:29:22 +02:00
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return PartialView ( "MultiBookingSelectionPartial" ) ;
}
2025-07-15 14:26:03 +02:00
if ( ! long . TryParse ( relOid , out var c2sOid ) )
2024-06-26 12:29:22 +02:00
{
return PartialView ( "MultiBookingSelectionPartial" , Model ) ;
}
2025-07-15 14:26:03 +02:00
RemoveRelOidFromGroupBooking ( c2sOid ) ;
return PartialView ( "MultiBookingSelectionPartial" , Model ) ;
}
2024-06-26 12:29:22 +02:00
2025-07-15 14:26:03 +02:00
private void RemoveRelOidFromGroupBooking ( long c2sOid )
{
var list = GetSelectedGroupBookingSupportConcepts ( ) ;
2025-07-16 12:38:01 +02:00
LoadSupportConceptThings ( null , false ) ;
2025-07-15 14:26:03 +02:00
var supportConcept2Remove = list . FirstOrDefault ( f = > f . CostBearerRelOids . Any ( a = > a = = c2sOid ) ) ;
if ( supportConcept2Remove ! = null )
2024-06-26 12:29:22 +02:00
{
2025-07-15 14:26:03 +02:00
var supportConcepts = list . Where ( supportConcept = > supportConcept . SupportConceptOid . Equals ( supportConcept2Remove . SupportConceptOid ) = = false ) . ToList ( ) ;
2024-06-26 12:29:22 +02:00
// Ziele, die bei den verbleibenden Hilfeplänen nicht vorhanden sind, werden aus der Auswahl entfernt.
2025-07-15 14:26:03 +02:00
var remainingGoals = new List < long > ( ) ;
2024-06-26 12:29:22 +02:00
2025-07-15 14:26:03 +02:00
foreach ( var supportConcept in supportConcepts )
2024-06-26 12:29:22 +02:00
{
2025-07-15 14:26:03 +02:00
foreach ( var goal in supportConcept . Goals )
2024-06-26 12:29:22 +02:00
{
2025-07-15 14:26:03 +02:00
remainingGoals . AddIfNotIn ( goal . ValueListEntryOid . Value ) ;
2024-06-26 12:29:22 +02:00
}
}
2025-07-15 14:26:03 +02:00
Model . SelectedGoals = Model . SelectedGoals . Where ( goal = > remainingGoals . Contains ( goal . ValueListEntryOid . Value ) ) . ToList ( ) ;
2024-06-26 12:29:22 +02:00
}
2025-07-15 14:26:03 +02:00
Model . GroupBookingSelectedCostBearerSupportConceptOids . Remove ( c2sOid ) ;
2024-06-26 12:29:22 +02:00
2025-07-16 12:38:01 +02:00
var c2s2Remove = Model . GroupBookingSelectedCostBearerSupportConcepts . FirstOrDefault ( c = > c . CostBearer2SupportConceptOid = = c2sOid ) ;
if ( c2s2Remove ! = null )
{
Model . GroupBookingSelectedCostBearerSupportConcepts . Remove ( c2s2Remove ) ;
}
2025-07-15 14:26:03 +02:00
//Model.GroupBookingSelectedSupportConcepts.Remove(supportConcept2Remove);
//Model.SelectedConceptCostBearerRelations.Remove(relation2Remove);
2024-06-26 12:29:22 +02:00
2025-07-15 14:26:03 +02:00
var selectedGroups = Model . GroupsOfPeople . Where ( group = > group . GroupOfPeopleOid . HasValue & & Model . GroupBookingSelectedGroupOfPeopleOids . Contains ( group . GroupOfPeopleOid . Value ) ) . ToList ( ) ;
var groups = selectedGroups . Where ( group = > group . SupportConceptList . All ( a = > Model . GroupBookingSelectedCostBearerSupportConceptOids . Contains ( a . CostBearerRelOids [ 0 ] ) ) ) ;
2024-06-26 12:29:22 +02:00
2025-07-15 14:26:03 +02:00
Model . GroupBookingSelectedGroupOfPeopleOids = groups . Where ( group = > group . GroupOfPeopleOid . HasValue ) . Select ( group = > group . GroupOfPeopleOid . Value ) . ToList ( ) ;
2024-06-26 12:29:22 +02:00
2025-07-16 12:38:01 +02:00
LoadSupportConceptThings ( null , true ) ;
2024-06-26 12:29:22 +02:00
2025-07-15 14:26:03 +02:00
if ( Model . SelectedServiceCategory ! = null & & ! Model . Categories2Descriptions . Keys . Contains ( Model . SelectedServiceCategory ) )
2024-06-26 12:29:22 +02:00
{
var firstCategory2ServiceDescriptions = Model . Categories2Descriptions . FirstOrDefault ( ) ;
var firstServiceCategory = firstCategory2ServiceDescriptions . Key ;
2025-07-15 14:26:03 +02:00
var firstServiceDescription = firstCategory2ServiceDescriptions . Value ? . FirstOrDefault ( ) ;
2024-06-26 12:29:22 +02:00
Model . SelectedServiceCategory = firstServiceCategory ;
Model . SelectedServiceDescription = firstServiceDescription ;
}
2025-07-15 14:26:03 +02:00
2025-07-04 00:30:36 +02:00
Model . SelectedGoalOids = Model . SelectedGoals . Select ( g = > g . ValueListEntryOid . Value ) . ToList ( ) ;
2025-07-15 14:26:03 +02:00
//Model.GroupBookingSelectedSupportConceptOids = Model.GroupBookingSelectedSupportConcepts.Select(g => g.SupportConceptOid.Value).ToList();
//Model.SelectedConceptCostBearerRelationOids = Model.SelectedConceptCostBearerRelations.Select(g => g.CostBearer2SupportConceptOid.Value).ToList();
2025-07-04 00:30:36 +02:00
Model . SelectedServiceCategoryOid = Model . SelectedServiceCategory ? . ServiceCategoryOid ;
Model . SelectedServiceDescriptionOid = Model . SelectedServiceDescription ? . ServiceDescriptionOid ;
2025-07-15 14:26:03 +02:00
2024-06-26 12:29:22 +02:00
}
2022-12-30 16:28:23 +01:00
[Authorize]
[HttpPost]
public ActionResult SetMultiBookingMode ( FormCollection formCollection )
{
2025-07-15 14:26:03 +02:00
SkipModelInitialization = true ;
if ( ! IsUserLoggedIn ( ) )
2022-12-30 16:28:23 +01:00
{
return Logout ( ) ;
}
2025-06-27 13:11:10 +02:00
Model . IsInTransferMode = false ;
Model . TransferringAppointmentOid = null ;
2023-03-14 16:12:52 +01:00
2022-12-30 16:28:23 +01:00
try
{
var isInMultiBookingMode = "true,false" = = formCollection [ FormCollectionConstants . IsInMultiBookingModeKey ] ;
Model . IsInMultiBookingMode = isInMultiBookingMode ;
ResetBookingMode ( isInMultiBookingMode ? BookingMode . MultiBookingMode : BookingMode . SingleBookingMode ) ;
}
catch ( Exception exception )
{
Log . Error ( exception . Message , exception ) ;
}
return RedirectToAction ( "Main" ) ;
}
[Authorize]
[HttpPost]
public ActionResult CreateMultiBooking ( FormCollection formCollection )
{
if ( Model is null )
{
return Logout ( ) ;
}
try
{
string doku1 ;
if ( Model . Dokutypes ! = null & & Model . Dokutypes . Length > 0 )
{
2023-03-31 12:32:08 +02:00
doku1 = formCollection [ FormCollectionConstants . Dokumentation1Key ] ? . RemoveUppercaseEsszett ( ) ;
2022-12-30 16:28:23 +01:00
}
else
{
2023-03-31 12:32:08 +02:00
doku1 = formCollection [ FormCollectionConstants . Dokumentation6Key ] ? . RemoveUppercaseEsszett ( ) ;
2022-12-30 16:28:23 +01:00
}
// Wenn kein Datum angegeben wurde, wird die Main-Seite geladen und abgebrochen
if ( string . IsNullOrEmpty ( formCollection [ FormCollectionConstants . DateKey ] ) )
{
return View ( "Main" , Model ) ;
}
2023-07-31 15:29:16 +02:00
var marker = "on" = = formCollection [ FormCollectionConstants . MarkerKey ] ;
2024-09-12 14:55:35 +02:00
decimal? betrag = null ;
var betragAsString = formCollection [ FormCollectionConstants . BetragKey ] ? . Replace ( '.' , ',' ) ;
if ( decimal . TryParse ( betragAsString , out var betragAsDecimal ) )
{
betrag = betragAsDecimal ;
}
2022-12-30 16:28:23 +01:00
var distanz = formCollection [ FormCollectionConstants . DistanceKey ] ;
2023-05-23 13:56:22 +02:00
decimal? distanceInMeters = null ;
2022-12-30 16:28:23 +01:00
if ( ! string . IsNullOrEmpty ( distanz ) )
{
2023-05-23 13:56:22 +02:00
if ( decimal . TryParse ( distanz , out var parsedDistance ) )
2022-12-30 16:28:23 +01:00
{
distanceInMeters = parsedDistance ;
}
}
2025-06-11 22:56:25 +02:00
var selectedCostbearer2SupportConceptRelOid = Model . SelectedCostBearerSupportConceptOid < 1 ? null : Model . SelectedCostBearerSupportConceptOid ;
2022-12-30 16:28:23 +01:00
var datum = Convert . ToDateTime ( formCollection [ FormCollectionConstants . DateKey ] ) ;
var enddatum = datum ;
var endDateString = formCollection [ FormCollectionConstants . EndDateKey ] ;
2024-03-19 19:10:13 +01:00
if ( endDateString ? . Length > 0 )
2022-12-30 16:28:23 +01:00
{
enddatum = Convert . ToDateTime ( endDateString ) ;
}
var start = formCollection [ FormCollectionConstants . StartKey ] ;
var ende = formCollection [ FormCollectionConstants . EndKey ] ;
2023-06-21 19:19:56 +02:00
var dauer = 0 m ;
2022-12-30 16:28:23 +01:00
if ( datum > enddatum )
{
enddatum = datum ;
}
2023-06-21 19:19:56 +02:00
var durationAsString = formCollection [ FormCollectionConstants . DurationKey ] ;
durationAsString = durationAsString . Replace ( '.' , ',' ) ;
if ( ! string . IsNullOrEmpty ( durationAsString ) )
{
decimal . TryParse ( durationAsString , out dauer ) ;
}
if ( Model . SelectedDurationUnit = = "Stunden" | | Model . EinheitZeiterfassung = = 1 )
2022-12-30 16:28:23 +01:00
{
2023-06-21 19:19:56 +02:00
dauer * = 60 m ;
2022-12-30 16:28:23 +01:00
}
2023-03-31 12:32:08 +02:00
var doku2 = formCollection [ FormCollectionConstants . Dokumentation2Key ] ? . RemoveUppercaseEsszett ( ) ;
var doku3 = formCollection [ FormCollectionConstants . Dokumentation3Key ] ? . RemoveUppercaseEsszett ( ) ;
var doku4 = formCollection [ FormCollectionConstants . Dokumentation4Key ] ? . RemoveUppercaseEsszett ( ) ;
var doku5 = formCollection [ FormCollectionConstants . Dokumentation5Key ] ? . RemoveUppercaseEsszett ( ) ;
2022-12-30 16:28:23 +01:00
var zeitenFeld = new DateTime [ 2 ] ;
if ( start = = string . Empty & & ende = = string . Empty )
{
zeitenFeld [ 0 ] = new DateTime ( datum . Year , datum . Month , datum . Day , 0 , 0 , 1 ) ;
if ( enddatum = = datum )
{
2023-06-21 19:19:56 +02:00
zeitenFeld [ 1 ] = new DateTime ( datum . Year , datum . Month , datum . Day , 0 , 0 , 1 ) . AddMinutes ( Convert . ToDouble ( dauer ) ) ;
2022-12-30 16:28:23 +01:00
}
else
{
2023-06-21 19:19:56 +02:00
zeitenFeld [ 1 ] = new DateTime ( enddatum . Year , enddatum . Month , enddatum . Day , 0 , 0 , 1 ) . AddMinutes ( Convert . ToDouble ( dauer ) ) ;
2022-12-30 16:28:23 +01:00
}
}
else
{
2023-06-21 19:19:56 +02:00
zeitenFeld = enddatum = = datum ? ConvertRecordTimes ( start , ende , datum , Convert . ToDouble ( dauer ) ) : ConvertRecordTimesWithEndDate ( start , ende , datum , enddatum , Convert . ToDouble ( dauer ) ) ;
2022-12-30 16:28:23 +01:00
}
if ( dauer = = 0 | | zeitenFeld [ 1 ] ! = zeitenFeld [ 0 ] )
{
dauer = ( int ) ( zeitenFeld [ 1 ] - zeitenFeld [ 0 ] ) . TotalMinutes ;
}
var serviceRecordsToInsert = new List < ServiceRecordDC > ( ) ;
2025-07-15 14:26:03 +02:00
if ( Model . GroupBookingSelectedCostBearerSupportConceptOids . Any ( ) & & Model . GroupBookingSelectedEmployees . Any ( ) )
2022-12-30 16:28:23 +01:00
{
2025-07-15 14:26:03 +02:00
foreach ( var sc2cbRel in Model . GroupBookingSelectedCostBearerSupportConcepts )
2022-12-30 16:28:23 +01:00
{
var roundedDuration = dauer ;
var organisation = CustomerService . LoadOrganisationCompact ( sc2cbRel . CostBearer . OrganisationOid ) ;
if ( ! ( organisation is null ) )
{
var calculations = Calculations . GetInstance ( organisation . CostBearerID ) ;
roundedDuration = calculations . GetRoundedDuration ( organisation , dauer ) ;
}
// ToDo: Validierungsergebnisse treten mehrfach auf
2025-07-15 14:26:03 +02:00
foreach ( var employee in Model . GroupBookingSelectedEmployees )
2022-12-30 16:28:23 +01:00
{
var newServiceRecord = new ServiceRecordDC
{
IP = Request . UserHostAddress ,
Start = zeitenFeld [ 0 ] ,
End = zeitenFeld [ 1 ] ,
2023-05-23 13:56:22 +02:00
DistanceInMeterDecimal = distanceInMeters ,
2022-12-30 16:28:23 +01:00
RoundedDuration = roundedDuration ,
SupportConcept = sc2cbRel . SupportConcept ,
CostBearer2SupportConceptOid = sc2cbRel . CostBearer2SupportConceptOid ,
CostBearer = sc2cbRel . CostBearer ,
DurationInStunden = Model . IsShowingDurationInHours ? ZeiterfassungsDauer . Stunden : ZeiterfassungsDauer . Minuten ,
Customer = sc2cbRel . SupportConcept . Customer ,
2023-03-31 12:32:08 +02:00
Notice = doku1 ? ? string . Empty ,
Notice2 = doku2 ? ? string . Empty ,
Notice3 = doku3 ? ? string . Empty ,
Notice4 = doku4 ? ? string . Empty ,
Notice5 = doku5 ? ? string . Empty ,
2022-12-30 16:28:23 +01:00
InsertedOn = DateTime . Now ,
2025-06-11 22:56:25 +02:00
InsUser = MobileSessionFacade . EmployeeFullname ,
2022-12-30 16:28:23 +01:00
IsCreatedInMobileClient = true ,
Employee = employee ,
ServiceRecordFormat = ServiceRecordFormate . OriginaleZeiterfassung ,
2024-09-12 14:55:35 +02:00
ServiceDescription = OperationsService . GetServiceDescription ( Model . SelectedServiceDescriptionOid . Value ) ,
Betrag = betrag
2022-12-30 16:28:23 +01:00
} ;
2023-07-31 15:29:16 +02:00
if ( marker )
{
newServiceRecord . ServiceRecordType = ServiceRecordTypeId . Content ;
}
2022-12-30 16:28:23 +01:00
if ( Model . IsEndDateVisible )
{
newServiceRecord . ServiceRecordFormat = ServiceRecordFormate . ZeiterfassungMitEndDatum ;
}
serviceRecordsToInsert . Add ( newServiceRecord ) ;
}
}
OperationsService . InsertNewServiceRecords ( serviceRecordsToInsert ) ;
}
}
catch ( Exception exception )
{
Log . Error ( exception . Message , exception ) ;
}
return ResetEditingMode ( ) ;
}
[Authorize]
public string AddEmployeesToMultiBooking ( string pEmployeeOids )
{
if ( Model is null )
{
Logout ( ) ;
2023-02-09 20:47:52 +01:00
return LeerzeichenFuerGetMethoden ;
2022-12-30 16:28:23 +01:00
}
if ( string . IsNullOrEmpty ( pEmployeeOids ) )
{
2025-07-15 14:26:03 +02:00
Model . GroupBookingSelectedEmployees . Clear ( ) ;
return JsonConvert . SerializeObject ( Model . GroupBookingSelectedEmployees . Count ) ;
2022-12-30 16:28:23 +01:00
}
var rawEmployeeOids = pEmployeeOids . Split ( ',' ) ;
var oids = new List < long > ( ) ;
rawEmployeeOids . DoForEach ( s = > oids . AddIfNotIn ( long . Parse ( s ) ) ) ;
2023-03-31 12:32:08 +02:00
var employees = Model . EmployeesForGroupAndMultiBooking . Where ( w = > oids . Contains ( w . EmployeeOid ) ) ;
2022-12-30 16:28:23 +01:00
2025-07-15 14:26:03 +02:00
Model . GroupBookingSelectedEmployees . Clear ( ) ;
Model . GroupBookingSelectedEmployees . AddRangeIfElementsNotIn ( employees ) ;
2022-12-30 16:28:23 +01:00
2025-07-15 14:26:03 +02:00
return JsonConvert . SerializeObject ( Model . GroupBookingSelectedEmployees . Count ) ;
2022-12-30 16:28:23 +01:00
}
2024-06-26 12:29:22 +02:00
// Veraltet
2022-12-30 16:28:23 +01:00
[Authorize]
public string MultiBookingHasSelectedSupportConcepts ( )
{
try
{
2025-07-15 14:26:03 +02:00
return JsonConvert . SerializeObject ( Model . GroupBookingSelectedCostBearerSupportConceptOids . Any ( ) ) ;
2022-12-30 16:28:23 +01:00
}
catch ( Exception exception )
{
Log . Error ( exception . Message , exception ) ;
}
return JsonConvert . SerializeObject ( false ) ;
}
[Authorize]
public string MultiBookingHasSelectedEmployees ( )
{
try
{
2025-07-15 14:26:03 +02:00
return JsonConvert . SerializeObject ( Model . GroupBookingSelectedEmployees . Any ( ) ) ;
2022-12-30 16:28:23 +01:00
}
catch ( Exception exception )
{
Log . Error ( exception . Message , exception ) ;
}
return JsonConvert . SerializeObject ( false ) ;
}
#endregion
2023-06-21 19:19:56 +02:00
[HttpPost]
[Authorize]
public ActionResult ChangePassword ( FormCollection formCollection )
{
2025-06-11 22:56:25 +02:00
if ( Model is null | | ! MobileSessionFacade . IsUserLoggedIn ( ) | | LoggedInUser . UserVersion is null )
2023-06-21 19:19:56 +02:00
{
2024-06-26 12:29:22 +02:00
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2023-06-21 19:19:56 +02:00
return Logout ( ) ;
}
var oldPassword = formCollection [ "old-password" ] ;
var newPassword = formCollection [ "new-password" ] ;
var passwordConfirmation = formCollection [ "confirm-new-password" ] ;
if ( false = = newPassword . Equals ( passwordConfirmation ) )
{
2024-03-14 17:18:35 +01:00
TempData [ TempDataConstants . PwChErrKey ] = "Die Passwörter stimmen nicht überein!" ;
2023-06-21 19:19:56 +02:00
return RedirectToActionPermanent ( "Main" ) ;
}
2023-07-13 13:39:41 +02:00
var passwordUtils = new PasswordUtils ( ) ;
if ( passwordUtils . EvaluatePasswordStrength ( newPassword ) < 2 )
{
2025-06-11 22:56:25 +02:00
var checkResult = UserService . CheckPassword ( LoggedInUser . UserOid . Value , oldPassword , newPassword ) ;
2023-07-13 13:39:41 +02:00
if ( ! ( checkResult is null ) )
{
2024-03-14 17:18:35 +01:00
TempData [ TempDataConstants . PwChErrKey ] = checkResult ;
2023-07-13 13:39:41 +02:00
return RedirectToActionPermanent ( "Main" ) ;
}
}
2025-06-11 22:56:25 +02:00
var userName = LoggedInUser . LoginName ;
var userVersion = LoggedInUser . UserVersion . Value ;
2023-06-21 19:19:56 +02:00
2023-06-28 17:38:14 +02:00
UserService . ChangePassword ( userName , userVersion , oldPassword , newPassword ) ;
2023-06-21 19:19:56 +02:00
return RedirectToActionPermanent ( "Main" ) ;
}
2024-01-12 17:16:52 +01:00
#region ServiceRecord - Pagination
[Authorize]
public ActionResult LoadServiceRecordPage ( int selectedPage )
{
if ( Model . SelectedZeitraum ? . StartDate is null | | Model . SelectedZeitraum . EndDate is null )
{
Model . SelectedZeitraum = new NullableDateTimeSpan ( DateTime . Today . GetFirstOfMonth ( ) , DateTime . Today ) ;
}
LoadPaginatedServiceRecordsToModel ( selectedPage ) ;
return PartialView ( "ServiceRecordListPartial" , Model ) ;
}
private void LoadPaginatedServiceRecordsToModel ( int selectedPage )
{
var records = new List < ServiceRecordDC > ( ) ;
if ( selectedPage < 1 )
{
selectedPage = 1 ;
}
var selectedDayCount = ( long? ) ( Model . SelectedDayCount = = 0 ? null : ( int? ) Model . SelectedDayCount ) ;
Model . CurrentPage = selectedPage ;
int totalServiceRecords ;
var firstResult = ( selectedPage - 1 ) * Model . MaxResults ;
2025-06-11 22:56:25 +02:00
var selectedEmployeeOid = Model . SelectedEmployee ? . EmployeeOid ? ? Model . LoggedInEmployee . EmployeeOid . Value ;
2024-01-12 17:16:52 +01:00
// Ohne Hilfeplan
2025-06-11 22:56:25 +02:00
if ( Model . SelectedCostBearerSupportConceptOid is null | | Model . SelectedCostBearerSupportConceptOid < 1 )
2024-01-12 17:16:52 +01:00
{
records = Model . ServiceRecordTimeInterval = = ServiceRecordTimeInterval . ZeitraumWaehlen | | Model . ServiceRecordTimeInterval = = ServiceRecordTimeInterval . Monatsauswahl ?
//Zeitraum oder Monat gewählt
2024-09-12 14:55:35 +02:00
OperationsService . GetEmployeesServiceRecordsWithStartEndDatePaginated ( selectedEmployeeOid , Model . SelectedZeitraum . StartDate . Value , Model . SelectedZeitraum . EndDate . Value , firstResult , Model . MaxResults , out totalServiceRecords ) . ToList ( ) :
OperationsService . GetEmployeesServiceRecords2Paginated ( selectedEmployeeOid , selectedDayCount , firstResult , Model . MaxResults , out totalServiceRecords ) . ToList ( ) ;
2024-01-12 17:16:52 +01:00
}
else
{
records = Model . ServiceRecordTimeInterval = = ServiceRecordTimeInterval . ZeitraumWaehlen | | Model . ServiceRecordTimeInterval = = ServiceRecordTimeInterval . Monatsauswahl ?
//Zeitraum oder Monat gewählt
2025-04-02 17:44:39 +02:00
OperationsService
. GetCustomerServiceRecordsWithStartEndDatePaginated (
Model . SelectedSupportConcept . Customer . CustomerOid ,
2025-06-11 22:56:25 +02:00
Model . SelectedCostBearerSupportConceptOid . Value ,
2025-04-02 17:44:39 +02:00
Model . SelectedZeitraum . StartDate . Value ,
Model . SelectedZeitraum . EndDate . Value ,
firstResult , Model . MaxResults ,
out totalServiceRecords ) :
2025-06-11 22:56:25 +02:00
OperationsService . FindServiceRecordsForLastDaysPaginated ( Model . SelectedCostBearerSupportConceptOid , Model . SelectedDayCount , Model . LoggedInEmployee ? . EmployeeOid , firstResult , Model . MaxResults , out totalServiceRecords ) . ToList ( ) ;
2024-01-12 17:16:52 +01:00
}
var pages = Math . DivRem ( totalServiceRecords , Model . MaxResults , out var remainder ) ;
if ( remainder > 0 )
{
pages + + ;
}
Model . ServiceRecordCount = totalServiceRecords ;
Model . ServiceRecordPageCount = pages ;
var recordsOhneDuplikate = new List < ServiceRecordDC > ( ) ;
foreach ( var r in records . Where ( r = > ! recordsOhneDuplikate . Any ( a = > a . GroupOid . HasValue & & a . GroupOid . Value . Equals ( r . GroupOid ) ) ) )
{
recordsOhneDuplikate . Add ( r ) ;
}
2024-06-05 14:45:33 +02:00
var serviceRecords = recordsOhneDuplikate . Where ( serviceRecord = > serviceRecord . Start . HasValue & & serviceRecord . End . HasValue )
2024-01-12 17:16:52 +01:00
. OrderBy ( serviceRecord = > serviceRecord . Start . Value . Date )
. ThenBy ( serviceRecord = > serviceRecord . Start . Value . Hour )
. ThenBy ( serviceRecord = > serviceRecord . Start . Value . Minute )
. ThenBy ( serviceRecord = > serviceRecord . End . Value . Date )
. ThenBy ( serviceRecord = > serviceRecord . End . Value . Hour )
. ThenBy ( serviceRecord = > serviceRecord . End . Value . Minute )
. ThenByDescending ( serviceRecord = > serviceRecord . InsertedOn . Value ) . ToList ( ) ;
2024-06-05 14:45:33 +02:00
var serviceRecordOids2GoalHeaders = new Dictionary < long , List < string > > ( ) ;
var goalOids = new List < long > ( ) ;
2025-05-16 19:24:16 +02:00
//var measures = new List<ValueListEntryDC>();
2024-06-05 14:45:33 +02:00
serviceRecords . DoForEach ( serviceRecord = >
{
2025-05-16 19:24:16 +02:00
//measures.AddRangeIfElementsNotIn(serviceRecord.Goals);
2024-06-05 14:45:33 +02:00
goalOids . AddRangeIfElementsNotIn ( serviceRecord . Goals . Where ( goal = > goal . ParentOid . HasValue ) . Select ( goal = > goal . ParentOid . Value ) ) ;
} ) ;
var goalCategories = ValueListService . GetGoalCategoriesByOids ( goalOids ) ;
2025-05-16 19:24:16 +02:00
//serviceRecords.DoForEach(serviceRecord =>
//{
// if(serviceRecord.ServiceRecordOid is null)
// {
// return;
// }
// serviceRecord.Goals.OrderBy(vle => $"{vle.Abbreviation}-{vle.TypeDescription}").DoForEach(goal =>
// {
// var goalCategory = goalCategories.FirstOrDefault(g => g.ValueListEntryOid.HasValue && goal.ValueListEntryOid.HasValue && g.ValueListEntryOid.Value.Equals(goal.ValueListEntryOid.Value) || (g.ValueListEntryOid.HasValue && goal.ParentOid.HasValue && g.ValueListEntryOid.Value.Equals(goal.ParentOid.Value)));
// if(goalCategory != null)
// {
// serviceRecordOids2GoalHeaders.AddOrUpdateValueInDictionary(serviceRecord.ServiceRecordOid.Value, new List<string> { goalCategory.DisplayName });
// }
// });
//});
Model . ServiceRecordOids2GoalHeader = GetServiceRecordOids2GoalHeaders ( serviceRecords , goalCategories ) ;
Model . ServiceRecords = serviceRecords ;
}
[Authorize]
public static Dictionary < long , List < string > > GetServiceRecordOids2GoalHeaders ( List < ServiceRecordDC > serviceRecords , List < ValueListEntryDC > goalCategories )
{
var serviceRecordOids2GoalHeaders = new Dictionary < long , List < string > > ( ) ;
2024-06-05 14:45:33 +02:00
serviceRecords . DoForEach ( serviceRecord = >
{
if ( serviceRecord . ServiceRecordOid is null )
{
return ;
}
serviceRecord . Goals . OrderBy ( vle = > $"{vle.Abbreviation}-{vle.TypeDescription}" ) . DoForEach ( goal = >
{
var goalCategory = goalCategories . FirstOrDefault ( g = > g . ValueListEntryOid . HasValue & & goal . ValueListEntryOid . HasValue & & g . ValueListEntryOid . Value . Equals ( goal . ValueListEntryOid . Value ) | | ( g . ValueListEntryOid . HasValue & & goal . ParentOid . HasValue & & g . ValueListEntryOid . Value . Equals ( goal . ParentOid . Value ) ) ) ;
if ( goalCategory ! = null )
{
serviceRecordOids2GoalHeaders . AddOrUpdateValueInDictionary ( serviceRecord . ServiceRecordOid . Value , new List < string > { goalCategory . DisplayName } ) ;
}
} ) ;
} ) ;
2025-05-16 19:24:16 +02:00
return serviceRecordOids2GoalHeaders ;
2024-01-12 17:16:52 +01:00
}
[Authorize]
public ActionResult GoToFirstPage ( )
{
return LoadServiceRecordPage ( 1 ) ;
}
[Authorize]
public ActionResult GoToLastPage ( )
{
return LoadServiceRecordPage ( Model . ServiceRecordPageCount ) ;
}
#endregion
2024-04-18 16:14:20 +02:00
#region Einmal - Link für die Unterschrift
[Authorize]
public ActionResult GenerateOneTimeLinkForSignature ( long serviceRecordOid )
{
2024-04-23 17:24:14 +02:00
var token = BeWo . Service . Security . SecurityUtils . CreateExternalSignatureToken ( serviceRecordOid ) ;
2024-04-30 12:18:38 +02:00
var server = "https://" + LoginController . GetServerFromTenant ( MobileSessionFacade . Tenant ) ;
2024-04-18 16:14:20 +02:00
#if DEBUG
2024-04-30 12:18:38 +02:00
server = "http://" + GetLocalIPAddress ( ) + "/BeWoPlanerMobil" ;
2024-04-18 16:14:20 +02:00
#endif
2024-04-30 12:18:38 +02:00
var link = $"{server}/ExternalSignature/ExternalSignature/{token}" ;
2024-04-18 16:14:20 +02:00
Model . OneTimeLink = link ;
2025-07-17 16:26:07 +02:00
var serviceRecord = GetServiceRecordDC ( serviceRecordOid , false ) ;
2024-04-18 16:14:20 +02:00
2025-07-15 14:26:03 +02:00
var hilfeplan = Model . SelectedSupportConceptListObject . NameAndDateOfBirth + " | " + Model . SelectedSupportConceptListObject . SupportConceptTimeSpan ;
2024-04-30 12:18:38 +02:00
var leistung = serviceRecord . ServiceDescription . Name ;
var kategorie = serviceRecord . ServiceDescription . Category ;
var employee = $"{serviceRecord.Employee.FirstName} {serviceRecord.Employee.LastName}" ;
2024-04-18 16:14:20 +02:00
var datumUhrzeit = MainModel . GetServiceRecordTimeString ( serviceRecord ) ;
Model . OneTimeLinkText = $"Hilfeplan: {hilfeplan}<br />Kategorie: {kategorie}<br />Leistung: {leistung}<br />Mitarbeiter: {employee}<br />Datum / Uhrzeit: {datumUhrzeit}<br /><br />" ;
2024-04-30 12:18:38 +02:00
Model . ShareDetails = $"Unterschrift für erbrachte Leistung am {datumUhrzeit}" ;
2024-04-23 17:24:14 +02:00
2024-04-18 16:14:20 +02:00
return PartialView ( "OneTimeLinkCreationPartial" , Model ) ;
}
[Authorize]
public ActionResult CancelLinkCreation ( )
{
Model . OneTimeLink = null ;
2024-05-03 14:35:33 +02:00
Model . OneTimeLinkText = null ;
Model . ShareDetails = null ;
2024-04-18 16:14:20 +02:00
return PartialView ( "OneTimeLinkCreationPartial" , Model ) ;
}
#endregion
2024-04-30 12:18:38 +02:00
2024-09-12 14:55:35 +02:00
private static string GetLocalIPAddress ( )
2024-04-30 12:18:38 +02:00
{
var host = Dns . GetHostEntry ( Dns . GetHostName ( ) ) ;
foreach ( var ip in host . AddressList )
{
if ( ip . AddressFamily = = AddressFamily . InterNetwork )
{
return ip . ToString ( ) ;
}
}
throw new Exception ( "No network adapters with an IPv4 address in the system!" ) ;
}
2024-06-05 14:45:33 +02:00
[Authorize]
public ActionResult ReloadGoals ( )
{
2025-07-15 14:26:03 +02:00
SkipModelInitialization = true ;
if ( ! IsUserLoggedIn ( ) )
2024-06-26 12:29:22 +02:00
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
}
2025-07-15 14:26:03 +02:00
//LoadGoals();
2024-06-05 14:45:33 +02:00
2025-07-17 16:26:07 +02:00
CreateModelSupportConceptListObjects ( false ) ;
LoadSupportConceptThings ( null , true ) ;
2024-06-05 14:45:33 +02:00
return PartialView ( "GoalTreePartial" , Model ) ;
}
[Authorize]
public ActionResult SetSelectedServiceCategory ( string categoryOidStr )
{
2024-06-26 12:29:22 +02:00
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
2024-07-24 16:45:56 +02:00
return PartialView ( "Category2ServiceDescriptionPartial" ) ;
2024-06-26 12:29:22 +02:00
}
2024-06-05 14:45:33 +02:00
if ( long . TryParse ( categoryOidStr , out var categoryOid ) )
{
Model . SelectedServiceCategory = Model . Categories2Descriptions . FirstOrDefault ( f = > f . Key ? . ServiceCategoryOid ! = null & & f . Key . ServiceCategoryOid . Value . Equals ( categoryOid ) ) . Key ;
2024-06-26 12:29:22 +02:00
Model . SelectedServiceDescription = null ;
if ( Model . SelectedServiceCategory is null )
{
return PartialView ( "Category2ServiceDescriptionPartial" , Model ) ;
}
var selectedServiceDescription = Model . Categories2Descriptions [ Model . SelectedServiceCategory ] . OrderBy ( sd = > sd . Position ) . ThenBy ( sd = > sd . ServiceDescriptionOid ) . FirstOrDefault ( ) ;
Model . SelectedServiceDescription = selectedServiceDescription ;
2025-06-11 22:56:25 +02:00
Model . SelectedServiceCategoryOid = Model . SelectedServiceCategory ? . ServiceCategoryOid ;
Model . SelectedServiceDescriptionOid = Model . SelectedServiceDescription ? . ServiceDescriptionOid ;
2024-06-05 14:45:33 +02:00
}
return PartialView ( "Category2ServiceDescriptionPartial" , Model ) ;
}
2024-06-26 12:29:22 +02:00
[Authorize]
public string CheckSession ( )
{
return ( Model is null ) . ToString ( ) ;
}
[HttpPost]
public ActionResult ZombieLogout ( )
{
#if DEBUG
TempData [ TempDataConstants . ErrorMessageKey ] = "Der Browser wurde aus der Versenkung zurückgeholt und das Model ist jetzt null!" ;
#endif
return base . Logout ( ) ;
}
2025-03-25 17:36:15 +01:00
[Authorize]
public override string SaveCollapsibleStatus ( bool isOpen , string identifier )
{
2025-05-21 19:34:42 +02:00
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return LeerzeichenFuerGetMethoden ;
}
2025-03-25 17:36:15 +01:00
Model . Collapsibles2IsShown [ identifier ] = isOpen ;
return LeerzeichenFuerGetMethoden ;
}
2018-02-07 14:14:08 +01:00
}
2023-06-18 17:11:35 +02:00
public class ServiceRecord2Monatsunterschrift
{
public ServiceRecordDC ServiceRecord { get ; }
public bool HasMonatsunterschrift { get ; }
public ServiceRecord2Monatsunterschrift ( ServiceRecordDC serviceRecord , bool hasMonatsunterschrift )
{
ServiceRecord = serviceRecord ;
HasMonatsunterschrift = hasMonatsunterschrift ;
}
}
2016-06-27 01:45:38 +02:00
}