2016-06-27 01:45:38 +02:00
using System ;
using System.Collections.Generic ;
2019-11-21 19:39:32 +01:00
using System.Drawing ;
2016-06-27 01:45:38 +02:00
using System.Linq ;
2024-04-30 12:18:38 +02:00
using System.Net ;
using System.Net.Sockets ;
2018-10-08 11:57:16 +02:00
using System.Text ;
2016-06-27 01:45:38 +02:00
using System.Web.Mvc ;
2020-04-02 13:19:14 +02:00
using System.Windows.Forms ;
2023-02-23 11:48:41 +01:00
using BeWo.Service.Plugins ;
2018-04-18 14:33:21 +02:00
using BeWo.Service.ServiceImplementations ;
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 ;
2018-11-26 13:27:16 -04:00
2018-11-24 14:28:46 -04:00
using static BeWoPlanerMobil . Util . MobileUtils ;
2018-01-29 12:57:10 +01:00
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 ;
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
{
2018-01-29 12:57:10 +01:00
private MainModel _Model ;
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 ;
}
2022-08-10 14:13:29 +02:00
if ( ( ( MainModel ) Session [ ModelSessionConstants . MainModelKey ] ) ? . Employee is null )
2016-06-27 01:45:38 +02:00
{
2018-01-29 12:57:10 +01:00
_Model = new MainModel { Employee = MobileSessionFacade . LoggedInEmployee } ;
2020-09-21 11:57:10 +02:00
Session [ ModelSessionConstants . MainModelKey ] = _Model ;
2016-06-27 01:45:38 +02:00
}
else
{
2020-09-21 11:57:10 +02:00
_Model = ( MainModel ) Session [ ModelSessionConstants . MainModelKey ] ;
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
2020-08-04 12:45:46 +02:00
2016-06-27 01:45:38 +02:00
[Authorize]
public ActionResult Main ( )
{
try
{
2023-09-18 19:39:18 +02:00
if ( ! MobileSessionFacade . IsUserLoggedIn ( ) | | Request . Browser . Browser . Equals ( "InternetExplorer" ) )
2017-08-22 14:05:09 +02:00
{
2020-05-27 18:15:54 +02:00
var isNewSession = Session . IsNewSession ;
if ( isNewSession )
{
2024-03-14 17:18:35 +01:00
TempData [ TempDataConstants . AutoEndOfSessionLogoutMessageKey ] = "Sie wurden automatisch abgemeldet, da Ihre Session abgelaufen ist." ;
2020-05-27 18:15:54 +02:00
}
2020-04-02 13:19:14 +02:00
return Logout ( ) ;
2017-08-22 14:05:09 +02:00
}
2016-06-27 01:45:38 +02:00
2023-05-15 11:54:13 +02:00
if ( Model . Mandator is null )
{
2025-01-29 01:13:44 +01:00
Model . Mandator = MobileSessionFacade . Mandator ;
2023-06-18 17:11:35 +02:00
2023-06-20 15:00:09 +02:00
var mokSessionTimeout = UserSettingsUtils . GetSettingValueAsInteger ( Model . Mandator . Settings , SettingsKeys . MoKSessionTimeout , 20 ) ;
2023-06-21 00:25:33 +02:00
2023-06-18 17:11:35 +02:00
Session . Timeout = mokSessionTimeout ;
2023-07-13 13:39:41 +02:00
Model . IsPasswordSecurityEnabled = UserSettingsUtils . GetSettingValueAsBool ( Model . Mandator . Settings , SettingsKeys . IsPasswordSecurityActiv ) ;
if ( Model . IsPasswordSecurityEnabled )
{
var tempDataValue = string . Empty ;
switch ( MobileSessionFacade . PasswordStrength )
{
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 ;
}
if ( ! string . IsNullOrEmpty ( tempDataValue ) )
{
2024-03-14 17:18:35 +01:00
TempData [ TempDataConstants . ShowPwChPopupKey ] = tempDataValue ;
2023-07-13 13:39:41 +02:00
}
}
2023-07-31 15:29:16 +02:00
2025-05-16 19:24:16 +02:00
AbstractModel . ShowBetrag = UserSettingsUtils . GetSettingValueAsBool ( Model . Mandator . Settings , SettingsKeys . ShowBetrag ) ;
2024-09-12 14:55:35 +02:00
2023-07-31 15:29:16 +02:00
Model . ShowMarker = UserSettingsUtils . GetSettingValueAsBool ( Model . Mandator . Settings , SettingsKeys . ShowMarker ) ;
2023-05-15 11:54:13 +02:00
}
var mandatorSettings = Model . Mandator . Settings ;
2020-12-16 21:49:47 +01:00
2023-06-20 15:00:09 +02:00
Model . EinheitZeiterfassung = UserSettingsUtils . GetSettingValueAsInteger ( mandatorSettings , SettingsKeys . EinheitZeiterfassung ) ;
2023-05-02 13:03:46 +02:00
2025-05-16 19:24:16 +02:00
/ *
* Minuten : 0
* Stunden : 1
* Min & Std : 2
* /
2023-05-15 11:54:13 +02:00
if ( Model . EinheitZeiterfassung = = 1 )
{
Model . IsShowingDurationInHours = true ;
}
2024-06-05 14:45:33 +02:00
Model . FilterGroupServiceCategories = UserSettingsUtils . GetSettingValueAsBool ( mandatorSettings , SettingsKeys . FilterGroupServiceCategories ) ;
2022-09-07 13:19:08 +02:00
Model . SetStartTimeToEndTimeAfterSave = UserSettingsUtils . GetSettingValueAsBool ( mandatorSettings , SettingsKeys . SetStartTimeToEndTimeAfterSave ) ;
2023-09-04 16:57:20 +02:00
var user = GetUser ( ) ;
var userSettings = user ? . Settings . FirstOrDefault ( f = > f . Type . Equals ( SettingsType . ApplicationSettings ) ) ? . Value ;
2021-03-17 18:44:40 +01:00
Model . ShowExpiredSupportConcepts = UserSettingsUtils . GetSettingValueAsBool ( userSettings , SettingsKeys . ShowExpiredSupportConcepts ) ;
Model . ShowOnlyOwnSupportConcepts = UserSettingsUtils . GetSettingValueAsBool ( userSettings , SettingsKeys . ShowOnlyMySupportConcepts ) ;
2023-02-23 11:48:41 +01:00
Model . IsOnlyYearMonthVisible = UserSettingsUtils . GetSettingValueAsBool ( userSettings , SettingsKeys . IsOnlyYearMonthVisible ) ;
2021-03-17 18:44:40 +01:00
2022-12-30 16:28:23 +01:00
InitializeInterval ( userSettings ) ;
2020-08-04 12:45:46 +02:00
2021-04-19 04:38:29 +02:00
var customerFilter = MobileUserSettingsUtils . GetSettingValueAsEnum ( userSettings , SettingsKeys . CustomerFilterInZeiterfassung , CustomerFilterEnum . MyCustomer ) ;
2020-04-02 13:19:14 +02:00
2024-07-24 16:45:56 +02:00
if ( customerFilter ! = CustomerFilterEnum . MyCustomer & & ! AbstractModel . IsAllowedToSeeSupportConceptFilter )
2023-06-22 21:23:09 +02:00
{
customerFilter = CustomerFilterEnum . MyCustomer ;
}
2024-03-14 17:18:35 +01:00
2021-03-17 18:44:40 +01:00
Model . SelectedSupportConceptFilter = customerFilter ;
2020-05-27 18:15:54 +02:00
2021-03-17 18:44:40 +01:00
BS . Shared . Settings . ApplicationSettings . SupportConceptExpirationLimitInMonths = UserSettingsUtils . GetSettingValueAsInteger ( mandatorSettings , SettingsKeys . HilfeplanAuslaufAuswahl , 3 ) ;
BS . Shared . Settings . ApplicationSettings . AnzTageZeiterfassErfolgt = UserSettingsUtils . GetSettingValueAsInteger ( mandatorSettings , SettingsKeys . AnzTageZeiterfassErfolgt ) ;
BS . Shared . Settings . ApplicationSettings . MaxDaysEditServiceRecordsAllowed = UserSettingsUtils . GetSettingValueAsInteger ( mandatorSettings , SettingsKeys . MaxDaysEditServiceRecordsAllowed ) ;
BS . Shared . Settings . ApplicationSettings . TimeUntilUILock = UserSettingsUtils . GetSettingValueAsInteger ( mandatorSettings , SettingsKeys . TimeUntilUILock ) ;
2024-02-20 14:42:04 +01:00
BS . Shared . Settings . ApplicationSettings . ServiceRecordAllowChangeHours = UserSettingsUtils . GetSettingValueAsInteger ( mandatorSettings , SettingsKeys . ServiceRecordAllowChangeHours ) ;
2020-05-27 18:15:54 +02:00
2022-10-11 16:48:36 +02:00
AbstractModel . ShowServiceRecordInsertedOn = ! UserSettingsUtils . GetSettingValueAsBool ( mandatorSettings , SettingsKeys . HideServiceRecordInsertedByAndInsertedOn ) ;
2023-11-13 11:33:08 +01:00
Model . ShowSignature = UserSettingsUtils . GetSettingValueAsBool ( mandatorSettings , SettingsKeys . ShowSignature ) & & AbstractModel . HasRightToProvideSingleSignature ;
2017-02-01 13:53:59 +01:00
2021-09-07 19:33:40 +02:00
Model . GroupsOfPeople = EmployeeService . GetAllGroups ( GetUser ( ) . Employee . EmployeeOid ) . OrderBy ( gop = > gop . Name ) . ToList ( ) ;
2017-02-01 13:53:59 +01:00
2025-05-16 19:24:16 +02:00
AbstractModel . ShowDistanceField = UserSettingsUtils . GetSettingValueAsBool ( mandatorSettings , SettingsKeys . ShowDistanceFields ) ;
2018-02-02 14:43:40 +01:00
2017-02-01 13:53:59 +01:00
Model . Dokutypes = ValueListService . GetAllValueListEntrysByType ( ValueListEntryType . DocumentType ) ;
2024-03-14 17:18:35 +01:00
if ( Model . Dokutypes ! = null )
2017-02-01 13:53:59 +01:00
{
Model . Dokutypes = Model . Dokutypes . OrderBy ( s = > s . ValueListEntryOid ) . ToArray ( ) ;
}
2022-12-30 16:28:23 +01:00
if ( Model . AllEmployees is null )
2016-06-27 01:45:38 +02:00
{
2022-12-30 16:28:23 +01:00
Model . AllEmployees = EmployeeService . GetAllActiveEmployeesCompact ( ) . OrderBy ( e = > e . LastName ) . ToList ( ) ;
2016-06-27 01:45:38 +02:00
}
2023-03-31 12:32:08 +02:00
if ( Model . EmployeesForGroupAndMultiBooking is null )
{
2024-08-13 11:29:40 +02:00
Model . EmployeesForGroupAndMultiBooking = EmployeeService . GetAllCompactEmployees ( ) . Where ( e = > e . ActivationType = = ActivationTypeId . Active ) . OrderBy ( e = > e . LastName ) . ToList ( ) ;
2023-03-31 12:32:08 +02:00
}
2025-05-16 19:24:16 +02:00
if ( MobileSessionFacade . CheckForUserRight ( UserRightType . ServiceRecord_AllowCreationForOtherEmployees ) )
2016-06-27 01:45:38 +02:00
{
Model . Employees = EmployeeService . GetAllActiveEmployeesCompact ( ) ;
}
2018-02-07 14:14:08 +01:00
else if ( MobileSessionFacade . CheckForUserRight ( UserRightType . ServiceRecord_AllowCreationForOtherTeamMember ) & & Model . Employee ? . EmployeeOid ! = null )
2016-06-27 01:45:38 +02:00
{
2024-08-13 11:29:40 +02:00
Model . Employees = EmployeeService . GetAllTeamMember ( MobileSessionFacade . LoggedInCompactEmployee ) . Where ( e = > e . ActivationType = = ActivationTypeId . Active ) . ToList ( ) ;
2016-06-27 01:45:38 +02:00
}
else
{
Model . Employees = new List < CompactEmployeeDC > { MobileSessionFacade . LoggedInCompactEmployee } ;
}
2022-02-10 11:06:03 +01:00
Model . Employees = Model . Employees . OrderBy ( e = > e . LastName ) . ThenBy ( e = > e . FirstName ) . ToList ( ) ;
2023-06-20 15:00:09 +02:00
if ( Model . Employee ? . EmployeeOid . HasValue ? ? false )
2016-06-27 01:45:38 +02:00
{
2020-12-16 21:49:47 +01:00
Model . SupportConcepts = EmployeeService . GetActiveSupportConceptsForEmployee ( Model . Employee . EmployeeOid , Model . SelectedSupportConceptFilter ) ;
2016-06-27 01:45:38 +02:00
}
2024-03-14 17:18:35 +01:00
else
2016-06-27 01:45:38 +02:00
{
2020-12-16 21:49:47 +01:00
Model . SupportConcepts = new List < SupportConceptDC > ( ) ;
2016-06-27 01:45:38 +02:00
}
2023-06-20 15:00:09 +02:00
if ( Model . ShowExpiredSupportConcepts = = false )
2018-02-28 12:42:23 +01:00
{
2019-09-27 15:55:01 +02:00
Model . SupportConcepts = Model . SupportConcepts . Where ( supportConcept = >
2018-02-28 12:42:23 +01:00
{
2019-09-27 15:55:01 +02:00
var endDate = MainModel . GetEndDateOfSupportConcept ( supportConcept ) ;
2018-02-28 12:42:23 +01:00
2022-08-10 14:13:29 +02:00
return endDate is null | | endDate . Value > = DateTime . Now . Date ;
2018-02-28 12:42:23 +01:00
} ) . ToList ( ) ;
}
2022-08-10 14:13:29 +02:00
if ( Model . SelectedConceptCostBearerRelations is null )
2019-03-29 14:04:12 +01:00
{
Model . SelectedConceptCostBearerRelations = new List < SupportConceptCostBearerRelDC > ( ) ;
}
2022-12-30 16:28:23 +01:00
if ( Model . MultiBookingSelectedConceptCostBearerRelations is null )
{
Model . MultiBookingSelectedConceptCostBearerRelations = new List < SupportConceptCostBearerRelDC > ( ) ;
}
2018-12-10 23:40:38 -04:00
2022-08-10 14:13:29 +02:00
if ( Model . SelectedEmployee is null )
2018-12-10 23:40:38 -04:00
{
Model . SelectedEmployee = MobileSessionFacade . LoggedInCompactEmployee ;
}
2018-12-12 14:27:40 -04:00
2024-06-05 14:45:33 +02:00
var settingsValue = GetSettingValue ( mandatorSettings , SettingsKeys . IsServiceRecordNoticeMandatory ) ;
Model . IsServiceRecordNoticeMandatory = settingsValue is null | | ! settingsValue . Equals ( "0" ) ;
2019-07-19 17:13:57 +02:00
2024-07-24 16:45:56 +02:00
var isInList = ! ( Model . SelectedCostBearer2SupportConceptRelListObject is null ) & & Model . SupportConceptListObjects . Contains ( Model . SelectedCostBearer2SupportConceptRelListObject ) ;
2020-04-02 13:19:14 +02:00
2024-07-24 16:45:56 +02:00
if ( Model . SelectedCostBearer2SupportConceptRelListObject is null | | ! isInList )
2020-04-02 13:19:14 +02:00
{
2024-07-24 16:45:56 +02:00
if ( ! ( Model . SelectedCostBearer2SupportConceptRelListObject is null ) & & ! isInList )
2021-04-12 20:32:10 +02:00
{
2024-07-24 16:45:56 +02:00
Log . Info ( $"Model.SelectedSupportConceptListObject.Oid = {Model.SelectedCostBearer2SupportConceptRelListObject.CostBearer2SupportConceptOid} is not in list !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" ) ;
2021-04-12 20:32:10 +02:00
2022-08-10 14:13:29 +02:00
var sb = new StringBuilder ( ) ;
foreach ( var o in Model . SupportConceptListObjects )
2021-04-12 20:32:10 +02:00
{
if ( sb . Length > 0 )
{
sb . Append ( ", " ) ;
}
2021-03-30 10:58:50 +02:00
2021-04-12 20:32:10 +02:00
sb . Append ( o . CostBearer2SupportConceptOid ) ;
}
2025-03-25 17:36:15 +01:00
Log . Info ( $"Model.SupportConceptListObjects Oids = {sb}" ) ;
2021-04-12 20:32:10 +02:00
}
2021-03-30 10:58:50 +02:00
2024-07-24 16:45:56 +02:00
Model . SelectedCostBearer2SupportConceptRelListObject = Model . SupportConceptListObjects . FirstOrDefault ( f = > f . CostBearer2SupportConceptOid = = "-1" ) ? ? Model . SupportConceptListObjects . First ( ) ;
2020-04-02 13:19:14 +02:00
Model . CostBearer2SupportConceptOid = - 1 ;
2021-06-16 15:11:39 +02:00
2023-01-26 12:55:56 +01:00
Model . HasAnyRatingTypes = AbstractModel . HasRightToRateGoals & & OperationsService . GetAllRatingTypes ( ) . Any ( ) ;
2020-04-02 13:19:14 +02:00
}
2022-12-30 16:28:23 +01:00
if ( ! ( Model . CostBearer2SupportConceptOid is null ) & & Model . CostBearer2SupportConceptOid ! = - 1 )
2019-07-19 17:13:57 +02:00
{
2024-01-12 17:16:52 +01:00
LoadPaginatedServiceRecordsToModel ( Model . CurrentPage ) ;
2019-07-19 17:13:57 +02:00
}
2020-04-02 13:19:14 +02:00
2021-03-17 18:44:40 +01:00
Model . IsEndDateVisible = UserSettingsUtils . GetSettingValueAsBool ( mandatorSettings , SettingsKeys . IsEndDateVisible ) ;
2020-04-02 13:19:14 +02:00
2022-09-07 13:19:08 +02:00
if ( Model . IsZeiterfassungInStdMin )
{
2023-05-15 11:54:13 +02:00
var letzteZeiterfassungsdauer = UserSettingsUtils . GetSettingValueAsInteger ( userSettings , SettingsKeys . LetzteZeiterfassungsDauer ) ;
Model . IsShowingDurationInHours = letzteZeiterfassungsdauer = = 1 ;
2022-09-07 13:19:08 +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 ) ;
}
2022-12-30 16:28:23 +01:00
[Authorize]
private void InitializeInterval ( string userSettings )
{
Model . LastSelectedServiceRecordMonth = UserSettingsUtils . GetSettingValueAsDateTime ( userSettings , SettingsKeys . LastSelectedServiceRecordMonth ) ? ? DateTime . Today ;
2023-09-04 16:57:20 +02:00
//int zeitraum;
var serviceRecordTimeInterval = UserSettingsUtils . GetSettingValueAsEnum ( userSettings , SettingsKeys . LastSelectedServiceRecordTimeInterval , ServiceRecordTimeInterval . LastWeek ) ;
Model . ServiceRecordTimeInterval = serviceRecordTimeInterval ;
2022-12-30 16:28:23 +01: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 ) ;
}
Model . LastSelectedServiceRecordTimeIntervalDays = UserSettingsUtils . GetSettingValueAsInteger ( userSettings , SettingsKeys . LastSelectedServiceRecordTimeIntervalDays ) ;
if ( Model . ServiceRecordTimeInterval = = ServiceRecordTimeInterval . Monatsauswahl )
{
Model . SelectedZeitraum = new NullableDateTimeSpan ( Model . LastSelectedServiceRecordMonth . Date . GetFirstOfMonth ( ) , Model . LastSelectedServiceRecordMonth . Date . GetLastOfMonth ( ) ) ;
}
2023-09-04 16:57:20 +02:00
CalculateSelectedDayCount ( Model . LastSelectedServiceRecordTimeIntervalDays , Model . LastSelectedServiceRecordMonth , Model . SelectedZeitraum ? . StartDate , Model . SelectedZeitraum ? . EndDate , null ) ;
}
[Authorize]
private void UpdateSettings ( string key , string value )
{
if ( Model is null )
{
return ;
}
var loggedInUser = GetUser ( ) ;
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 ( ) ;
}
#region Ziele und Maßnahmen
2018-03-02 16:33:39 +01:00
[Authorize]
2021-06-16 15:11:39 +02:00
public void LoadGoalRatings ( )
2018-03-02 16:33:39 +01:00
{
2023-01-26 12:55:56 +01:00
if ( Model is null | | ! AbstractModel . HasRightToRateGoals )
2018-12-10 23:40:38 -04:00
{
2021-06-16 15:11:39 +02:00
return ;
2018-12-10 23:40:38 -04:00
}
2025-05-16 19:24:16 +02:00
Model . GoalRatingTypes = OperationsService . GetAllRatingTypes ( ) . OrderBy ( o = > o . Position ) . ToList ( ) ;
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
{
2023-01-26 12:55:56 +01:00
if ( Model is null | | ratingTypeOid is null | | goalOid is null | | ! AbstractModel . 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
{
2024-06-26 12:29:22 +02:00
var supportConcepts = Model . GroupBookingSelectedSupportConcepts ;
2020-04-02 13:19:14 +02:00
2024-06-26 12:29:22 +02:00
supportConcepts . DoForEach ( sc = > { allGoals . AddRangeIfElementsNotIn ( sc . Goals ) ; } ) ;
}
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
{
2024-06-26 12:29:22 +02:00
Model . SelectedGoals . AddIfNotIn ( 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
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 ) ;
}
}
2020-04-02 13:19:14 +02:00
[Authorize]
2022-08-10 14:13:29 +02:00
public void LoadGoals ( )
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
if ( Model is null )
{
return ;
}
2024-06-05 14:45:33 +02:00
var selectedGoals = new List < ValueListEntryDC > ( ) ;
2016-06-27 01:45:38 +02:00
2024-06-05 14:45:33 +02:00
if ( Model . IsInGroupBookingMode )
{
var supportConcepts = Model . GroupBookingSelectedSupportConcepts ;
2016-06-27 01:45:38 +02:00
2024-06-05 14:45:33 +02:00
supportConcepts . DoForEach ( sc = > { selectedGoals . AddRangeIfElementsNotIn ( sc . Goals ) ; } ) ;
}
else
{
if ( Model . CostBearer2SupportConceptOid is null )
{
return ;
}
2016-06-27 01:45:38 +02:00
2024-06-05 14:45:33 +02:00
var supportConcept = Model . SupportConcepts . FirstOrDefault ( sc = > sc . CostBearerRelations . Any ( sc2Cb = > sc2Cb . CostBearer2SupportConceptOid . HasValue & & sc2Cb . CostBearer2SupportConceptOid . Value . Equals ( Model . CostBearer2SupportConceptOid . Value ) ) ) ;
2016-06-27 01:45:38 +02:00
2024-06-05 14:45:33 +02:00
if ( supportConcept is null )
{
return ;
}
2021-06-16 15:11:39 +02:00
2024-06-05 14:45:33 +02:00
Model . SelectedSupportConcept = supportConcept ;
2016-06-27 01:45:38 +02:00
2024-06-05 14:45:33 +02:00
selectedGoals = supportConcept . Goals ;
}
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 ( ) ;
2021-06-16 15:11:39 +02:00
2024-06-05 14:45:33 +02:00
Model . GoalTree = BuildGoalTree ( allGoals ) ;
}
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 ;
}
}
2024-09-12 14:55:35 +02:00
#endregion
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 )
{
if ( supportConcept . CostBearerRelations . Any ( supportConceptCostBearerRel = > supportConceptCostBearerRel . CostBearer2SupportConceptOid = = oid ) )
{
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-01-17 16:21:58 +01:00
var blob = formCollection [ FormCollectionConstants . ServiceRecordSignatureBlobKey ] ;
var date = DateTime . Parse ( formCollection [ FormCollectionConstants . ServiceRecordSignatureDateKey ] ) ;
long . TryParse ( formCollection [ FormCollectionConstants . ServiceRecordSignatureRecordOidKey ] , out var serviceRecordOid ) ;
var serviceRecord = Model . ServiceRecords . FirstOrDefault ( sr = > sr . ServiceRecordOid . HasValue & & sr . ServiceRecordOid . Value . Equals ( serviceRecordOid ) ) ;
if ( serviceRecordOid < 1 | | serviceRecord is null )
2016-06-27 01:45:38 +02:00
{
2025-01-17 16:21:58 +01:00
var message2Log = string . Empty ;
if ( serviceRecordOid < 1 )
2016-06-27 01:45:38 +02:00
{
2025-01-17 16:21:58 +01:00
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." ;
2016-06-27 01:45:38 +02:00
}
2025-01-17 16:21:58 +01:00
Log . Error ( message2Log ) ;
2024-01-12 17:16:52 +01:00
2025-01-17 16:21:58 +01:00
TempData [ TempDataConstants . ErrorMessageKey ] = "Beim Speichern der Unterschrift ist ein Fehler aufgetreten. Bitte wenden Sie sich an Ihren Administrator." ;
return RedirectToActionPermanent ( "Main" , "Main" ) ;
}
2019-11-21 19:39:32 +01:00
2025-01-17 16:21:58 +01:00
long? oid ;
2016-06-27 01:45:38 +02:00
2025-01-17 16:21:58 +01:00
using ( var signatureBitmap = SignatureUtils . Base64StringToBitmap ( blob . Split ( ',' ) [ 1 ] ) )
{
var isValid = SignatureUtils . ValidateSignature ( signatureBitmap ) ;
2020-04-02 13:19:14 +02:00
2025-01-17 16:21:58 +01:00
if ( ! isValid )
{
TempData [ TempDataConstants . ErrorMessageKey ] = "Das Unterschriftenfeld darf nicht leer sein." ;
return RedirectToActionPermanent ( "Main" , "Main" ) ;
2020-04-02 13:19:14 +02:00
}
2018-12-13 20:59:05 -04:00
2025-01-17 16:21:58 +01:00
oid = OperationsService . InsertSignature ( new SignatureDC
{
DataBild = blob ,
Zeitstempel = date ,
ServiceRecordOid = serviceRecordOid
} ) . SignatureOid ;
2016-06-27 01:45:38 +02:00
}
2025-01-17 16:21:58 +01:00
if ( oid is null )
2016-06-27 01:45:38 +02:00
{
2025-01-17 16:21:58 +01:00
TempData [ TempDataConstants . ErrorMessageKey ] = "Beim Speichern der Unterschrift ist ein Fehler aufgetreten. Bitte wenden Sie sich an Ihren Administrator." ;
2016-06-27 01:45:38 +02:00
}
2025-01-17 16:21:58 +01:00
else
{
TempData [ TempDataConstants . InfoMessageKey ] = $"Die Unterschrift von {serviceRecord.Customer} für den Eintrag vom {MainModel.GetServiceRecordTimeHeader(serviceRecord, false)} wurde erfolgreich gespeichert." ;
}
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 ( )
{
if ( Model is null )
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
}
Model . TextModules . Clear ( ) ;
if ( Model . SelectedServiceCategoryOid . HasValue & & ( Model . Employee ? . EmployeeOid . HasValue ? ? false ) )
{
2023-03-29 15:49:20 +02:00
var allTextModules = OperationsService . GetTextModules ( AbstractModel . HasRightToSeeGlobalTextModules , Model . Employee . EmployeeOid . Value , AbstractModel . HasRightToSeeGlobalTextModules , false ) ;
2022-08-19 13:53:32 +02:00
foreach ( var tm in allTextModules . Where ( textModule = > textModule . IsParent = = false ) )
2018-05-28 15:02:55 +02:00
{
2022-08-19 13:53:32 +02:00
if ( string . IsNullOrWhiteSpace ( tm . Text ) )
2018-05-28 15:02:55 +02:00
{
2020-02-06 18:44:35 +01:00
tm . Text = tm . Name ;
2018-05-28 15:02:55 +02:00
}
}
2020-02-10 12:02:59 +01:00
2022-08-19 13:53:32 +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
2022-08-19 13:53:32 +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 . Employee . EmployeeOid ) | | ! w . IsOnlyForEmployee ) ) . OrderBy ( t = > t . Text ) . ToList ( ) ;
2018-01-31 17:52:28 +01:00
2022-08-19 13:53:32 +02:00
x . AddRangeIfElementsNotIn ( Utils . GetParentTextModules ( x ) ) ;
2020-11-09 17:55:01 +01:00
2022-08-19 13:53:32 +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 ( ) ;
foreach ( var item in textModuleDisplayItems )
2020-11-09 17:55:01 +01:00
{
2023-03-29 15:49:20 +02:00
if ( item . ParentOid is null )
2020-11-09 17:55:01 +01:00
{
2023-03-29 15:49:20 +02:00
continue ;
2020-11-09 17:55:01 +01:00
}
2023-03-29 15:49:20 +02:00
var parent = textModuleDisplayItems . FirstOrDefault ( p = > p . Oid = = item . ParentOid ) ;
parent ? . Children . AddIfNotIn ( item ) ;
2020-11-09 17:55:01 +01:00
}
2020-11-20 23:28:09 +01:00
2023-03-03 21:54:36 +01: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
{
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
2023-03-03 21:54:36 +01:00
AppointmentListItem appointmentListItemPrototype = null ;
if ( TempData [ TempDataConstants . AppointmentListItemKey ] is AppointmentListItem appointmentListItem & & Model . Employee . EmployeeOid . HasValue )
{
appointmentListItemPrototype = appointmentListItem ;
}
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 ;
}
2020-09-21 11:57:10 +02:00
Log . Info ( $"CreateOrUpdateServiceRecord: datum:{collection[FormCollectionConstants.DateKey]}; start:{collection[FormCollectionConstants.StartKey]}; ende:{collection[FormCollectionConstants.EndKey]}; dauer:{collection[FormCollectionConstants.DurationKey]}; doku:{doku1}; 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
{
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 ;
}
}
2024-06-26 12:29:22 +02:00
var selectedCostbearerScRelOid = Model . CostBearer2SupportConceptOid < 1 ? null : Model . CostBearer2SupportConceptOid ;
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 ;
2021-05-17 14:01:06 +02:00
Model . NewServiceRecord = Model . GetServiceRecord ( selectedRecordOid . Value ) ;
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
{
return RedirectToActionPermanent ( "Main" ) ;
}
Model . NewServiceRecord . IP = Request . UserHostAddress ;
Model . NewServiceRecord . Goals = Model . SelectedGoals ;
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
2022-09-07 13:19:08 +02:00
if ( Model . Employee . EmployeeOid . HasValue )
2020-04-08 14:44:20 +02:00
{
if ( ! Model . IsInEditingMode )
{
Model . NewServiceRecord . Employee = Model . SelectedEmployee ? ? MobileSessionFacade . LoggedInCompactEmployee ;
}
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 ;
}
}
2024-06-26 12:29:22 +02:00
var sc = Model . SupportConcepts . FirstOrDefault ( fod = > fod . CostBearerRelations . Any ( a = > a . CostBearer2SupportConceptOid . HasValue & & a . CostBearer2SupportConceptOid . Value . Equals ( selectedCostbearerScRelOid ) ) ) ;
2020-04-08 14:44:20 +02:00
2022-09-07 13:19:08 +02:00
if ( ! ( sc is null ) )
2020-04-08 14:44:20 +02:00
{
2022-09-07 13:19:08 +02:00
if ( sc . SupportConceptOid . HasValue )
2020-04-08 14:44:20 +02:00
{
Model . NewServiceRecord . SupportConcept = CustomerService . LoadCompactSupportConceptDC ( sc . SupportConceptOid . Value , Model . Employee . EmployeeOid ) ;
}
Model . NewServiceRecord . Customer = sc . Customer ;
2024-06-26 12:29:22 +02:00
var cb2ScRel = sc . CostBearerRelations . First ( f = > f . CostBearer2SupportConceptOid . HasValue & & f . CostBearer2SupportConceptOid . Equals ( selectedCostbearerScRelOid ) ) ;
2020-04-08 14:44:20 +02:00
Model . NewServiceRecord . CostBearer = cb2ScRel . CostBearer ;
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 ;
Model . NewServiceRecord . InsUser = $"{MobileSessionFacade.LoggedInEmployee.FirstName} {MobileSessionFacade.LoggedInEmployee.LastName}" ;
Model . NewServiceRecord . IsCreatedInMobileClient = true ;
2022-12-30 16:28:23 +01:00
if ( Model . IsInGroupBookingMode & & Model . GroupBookingSelectedSupportConcepts . 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 } ) ;
Model . ServiceRecordOid = 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 ;
}
if ( ! ( appointmentListItemPrototype is null ) )
{
var appointment = appointmentListItemPrototype . SchedulerAppointment ;
var isRecurring = ! ( appointment . RecurrenceInfo is null ) ;
if ( isRecurring & & appointment . Type ! = ( int ) AppointmentType . ChangedOccurrence )
{
var id = appointment . RecurrenceIdReference ;
var recurrenceInfo = new RecurrenceInfo ( ) ;
recurrenceInfo . FromXml ( appointment . RecurrenceInfo ) ;
var occurrenceCalculator = OccurrenceCalculator . CreateInstance ( recurrenceInfo ) ;
var pattern = StaticAppointmentFactory . CreateAppointment ( AppointmentType . Pattern ) ;
pattern . RecurrenceInfo . FromXml ( appointment . RecurrenceInfo ) ;
pattern . Start = pattern . RecurrenceInfo . Start ;
pattern . End = pattern . RecurrenceInfo . End ;
var occurrence = occurrenceCalculator . CalcOccurrences ( new TimeInterval ( appointment . StartDate . Value , appointment . EndDate . Value ) , pattern ) . FirstOrDefault ( ) ;
if ( ! ( occurrence is null ) )
{
var index = occurrence . RecurrenceIndex ;
appointment = SchedulerController . CloneAppointment ( appointment , $"<RecurrenceInfo Id=\" { id } \ " Index=\"{index}\" />" , ( int ) AppointmentType . ChangedOccurrence ) ;
}
else
{
appointment = null ;
}
}
if ( ! ( appointment is null ) )
{
var serviceRecord = OperationsService . GetServiceRecordById ( Model . ServiceRecordOid ) ;
appointment . ServiceRecordList . AddIfNotIn ( serviceRecord ) ;
if ( appointment . SchedulerAppointmentOid . HasValue )
{
KalenderService . UpdateSchedulerAppointments ( new List < SchedulerAppointmentDC > { appointment } ) ;
}
else
{
KalenderService . InsertSchedulerAppointments ( new List < SchedulerAppointmentDC > { appointment } ) ;
}
}
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 ) ;
}
2022-12-30 16:28:23 +01:00
ResetBookingMode ( Model . IsInGroupBookingMode ? BookingMode . GroupBookingMode : BookingMode . SingleBookingMode ) ;
2020-11-20 23:28:09 +01:00
2020-12-16 21:49:47 +01:00
return ResetEditingMode ( ) ;
2020-04-08 14:44:20 +02:00
}
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 ;
var personCount = Model . GroupBookingSelectedSupportConcepts . Count ;
2023-01-18 17:13:42 +01:00
var cb2ScOids = Model . GroupBookingSelectedCostbearerRelOids ;
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 ;
2024-03-14 17:18:35 +01:00
if ( TempData [ TempDataConstants . AppointmentListItemKey ] is AppointmentListItem appointmentListItem & & Model . Employee . EmployeeOid . HasValue )
2023-03-03 21:54:36 +01:00
{
var appointment = appointmentListItem . SchedulerAppointment ;
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 ;
var customerCount = Model . GroupBookingSelectedSupportConcepts . 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
2022-12-30 16:28:23 +01:00
foreach ( var scdc in Model . GroupBookingSelectedSupportConcepts )
2018-04-27 14:11:21 +02:00
{
if ( scdc . CostBearerRelations . Count > 0 )
{
2020-04-02 13:19:14 +02:00
cb2ScOids . Add ( scdc . CostBearerRelations . ElementAt ( 0 ) . CostBearer2SupportConceptOid . Value ) ;
2018-04-27 14:11:21 +02:00
2022-08-10 14:13:29 +02:00
if ( org is null )
2018-04-27 14:11:21 +02:00
{
org = scdc . CostBearerRelations . ElementAt ( 0 ) . CostBearer ;
if ( org ! = null )
{
minuteInterval = org . ActualMinuteIntervall ;
}
}
else
{
2022-08-10 14:13:29 +02:00
if ( scdc . CostBearerRelations . ElementAt ( 0 ) . CostBearer is null | | ! org . Equals ( scdc . CostBearerRelations . ElementAt ( 0 ) . CostBearer ) )
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 ;
2022-12-30 16:28:23 +01:00
roundedDuration = Math . Round ( groupDuration / Model . GroupBookingSelectedSupportConcepts . 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 ;
2022-12-30 16:28:23 +01:00
Model . GroupBookingSelectedSupportConcepts = new List < SupportConceptDC > ( ) ;
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 )
{
2022-12-30 16:28:23 +01:00
var compactSupportConcepts = CustomerServiceImp . GetCompactSupportConcepts ( ( from sc in Model . GroupBookingSelectedSupportConcepts where sc . SupportConceptOid ! = null select sc . SupportConceptOid . Value ) . ToList ( ) , GetUser ( ) . Employee . EmployeeOid ) ;
2018-04-18 14:33:21 +02:00
2022-12-30 16:28:23 +01:00
var nodes = ( from supportConcept in Model . GroupBookingSelectedSupportConcepts let cb = supportConcept . CostBearerRelations . FirstOrDefault ( f = > cb2ScOids . Contains ( f . CostBearer2SupportConceptOid . Value ) ) let sc = compactSupportConcepts . FirstOrDefault ( f = > f . SupportConceptOid = = supportConcept . SupportConceptOid ) where cb ! = null & & sc ! = null select SupportConceptService . CreateFlatSupportConceptItem ( sc , CustomerService . LoadOrganisationCompact ( cb . CostBearer . 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 ;
2022-12-30 16:28:23 +01:00
foreach ( var org in from dc in Model . GroupBookingSelectedSupportConcepts where dc . CostBearerRelations . Count > 0 select dc . CostBearerRelations . First ( ) . CostBearer )
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
2022-12-30 16:28:23 +01:00
foreach ( var sc in Model . GroupBookingSelectedSupportConcepts )
2018-04-27 14:11:21 +02:00
{
2024-06-26 12:29:22 +02:00
if ( sc ? . SupportConceptOid is null )
{
continue ;
}
var costBearerRelation = Model . GroupBookingSelectionObject . SelectedRelations . FirstOrDefault ( f = > f . SupportConceptOid . HasValue & & f . SupportConceptOid . Value . Equals ( sc . SupportConceptOid . Value ) ) ;
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 ;
2024-06-26 12:29:22 +02:00
if ( costBearerRelation ? . CostBearer2SupportConceptOid ! = null )
2018-04-18 14:33:21 +02:00
{
2018-04-27 14:11:21 +02:00
var costBearer2SupportConceptOid = sc . CostBearerRelations . ElementAt ( 0 ) . CostBearer2SupportConceptOid ;
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 )
{
2022-12-30 16:28:23 +01:00
foreach ( var sc in Model . GroupBookingSelectedSupportConcepts )
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 ;
if ( sc . CostBearerRelations ! = null & & sc . CostBearerRelations . Count > 0 )
{
key + = "_" + sc . CostBearerRelations . ElementAt ( 0 ) . CostBearer2SupportConceptOid ;
}
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 ;
newServiceRecord . SupportConcept = CustomerService . LoadCompactSupportConceptDC ( sc . SupportConceptOid . Value , null ) ;
newServiceRecord . CostBearer = sc . CostBearerRelations . ElementAt ( 0 ) . CostBearer ;
newServiceRecord . Customer = sc . Customer ;
2018-04-27 14:11:21 +02:00
newServiceRecord . CostBearer2SupportConceptOid = sc . CostBearerRelations . ElementAt ( 0 ) . CostBearer2SupportConceptOid ;
}
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
{
2024-07-24 16:45:56 +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 ] ) ;
2016-06-27 01:45:38 +02:00
2024-07-24 16:45:56 +02:00
Model . SelectedCostBearerSupportConceptRelOid = cb2ScOid ;
2024-04-15 13:59:42 +02:00
2023-02-23 11:48:41 +01:00
LoadSupportConceptThings ( cb2ScOid ) ;
2022-08-10 14:13:29 +02:00
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
2020-04-02 13:19:14 +02:00
private void LoadServiceCategoriesToModel ( long? cb2ScOid )
{
2024-06-26 12:29:22 +02:00
if ( Model is null )
2021-03-11 12:09:38 +01:00
{
2024-06-26 12:29:22 +02:00
return ;
}
2024-06-05 14:45:33 +02:00
2024-06-26 12:29:22 +02:00
if ( Model . Categories2Descriptions is null )
{
Model . Categories2Descriptions = new Dictionary < ServiceCategoryDC , List < ServiceDescriptionDC > > ( ) ;
}
Model . Categories2Descriptions . Clear ( ) ;
Model . SelectedServiceCategory = null ;
Model . SelectedServiceDescription = null ;
if ( cb2ScOid is null & & ( Model . IsInGroupBookingMode | | Model . IsInMultiBookingMode ) )
{
var selectedSupportConcepts = Model . IsInGroupBookingMode ?
Model . GroupBookingSelectedSupportConcepts :
Model . IsInMultiBookingMode ?
Model . MultiBookingSelectedSupportConcepts :
new List < SupportConceptDC > ( ) ;
// Alle ServiceDescriptions der ausgewählten Hilfepläne laden
var nodes = OperationsService . GetSupportConceptTreeNodeDetailInfos ( selectedSupportConcepts . Where ( sc = > sc . SupportConceptOid . HasValue ) . Select ( sc = > sc . SupportConceptOid . Value ) . ToList ( ) ) ;
2024-06-05 14:45:33 +02:00
Model . Categories2Descriptions = CreateServiceCategory2ServiceDescription ( nodes , true ) ;
2024-06-26 12:29:22 +02:00
SelectFirstServiceDescription ( ) ;
2024-06-05 14:45:33 +02:00
2020-08-04 12:45:46 +02:00
return ;
}
2020-04-02 13:19:14 +02:00
Model . CostBearer2SupportConceptOid = cb2ScOid ;
Model . SelectedSupportConcept =
Model . SupportConcepts . FirstOrDefault (
2024-07-24 16:45:56 +02:00
supportConcept = >
supportConcept . CostBearerRelations . Any (
supportConceptCostBearerRel = >
supportConceptCostBearerRel . CostBearer2SupportConceptOid . HasValue & &
supportConceptCostBearerRel . CostBearer2SupportConceptOid . Value . Equals ( Model . CostBearer2SupportConceptOid ) ) ) ;
2021-03-17 18:44:40 +01:00
2020-04-02 13:19:14 +02:00
if ( Model . SelectedSupportConcept ! = null )
{
2024-07-24 16:45:56 +02:00
Model . SelectedCostBearer2SupportConceptRelListObject = Model . SupportConceptListObjects . First ( f = > long . Parse ( f . CostBearer2SupportConceptOid ) = = cb2ScOid ) ;
2016-06-27 01:45:38 +02:00
2024-06-05 14:45:33 +02:00
var node = OperationsService . GetSupportConceptTreeNodeDetailInfo ( Model . SelectedSupportConcept . Customer . CustomerOid , Model . SelectedSupportConcept . SupportConceptOid , Model . CostBearer2SupportConceptOid ) ;
2016-06-27 01:45:38 +02:00
2024-06-05 14:45:33 +02:00
Model . Categories2Descriptions = CreateServiceCategory2ServiceDescription ( new List < SupportConceptTreeNodeDetailInfoDC > { node } , false ) ;
2016-06-27 01:45:38 +02:00
}
2024-06-05 14:45:33 +02:00
else if ( cb2ScOid = = - 2 ) // Ohne Hilfeplan
2016-06-27 01:45:38 +02:00
{
2024-06-05 14:45:33 +02:00
var allServiceDescriptions = OperationsService . GetAllServiceDescriptions ( ) ;
2024-07-24 16:45:56 +02:00
Model . SelectedCostBearer2SupportConceptRelListObject = Model . SupportConceptListObjects . First ( f = > f . CostBearer2SupportConceptOid . Equals ( cb2ScOid . ToString ( ) ) ) ;
2024-06-05 14:45:33 +02:00
if ( Model . Categories2Descriptions is null )
{
Model . Categories2Descriptions = new Dictionary < ServiceCategoryDC , List < ServiceDescriptionDC > > ( ) ;
}
else
{
Model . Categories2Descriptions . Clear ( ) ;
}
allServiceDescriptions . AsParallel ( ) . DoForEach ( serviceDescription = >
{
2024-08-07 16:26:43 +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
}
2024-06-05 14:45:33 +02:00
else if ( cb2ScOid = = - 1 ) // Hilfeplan Auswählen
2019-07-19 17:13:57 +02:00
{
2024-07-24 16:45:56 +02:00
Model . SelectedCostBearer2SupportConceptRelListObject = Model . SupportConceptListObjects . First ( f = > f . CostBearer2SupportConceptOid . Equals ( cb2ScOid . ToString ( ) ) ) ;
2024-06-05 14:45:33 +02:00
if ( Model . Categories2Descriptions is null )
{
Model . Categories2Descriptions = new Dictionary < ServiceCategoryDC , List < ServiceDescriptionDC > > ( ) ;
}
else
{
Model . Categories2Descriptions . Clear ( ) ;
}
2021-03-30 10:58:50 +02:00
}
2020-07-13 16:25:43 +02:00
2024-06-05 14:45:33 +02:00
// Ist der Klient abwesend, wird dies wie im FaC angezeigt
2024-04-23 17:24:14 +02:00
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 ;
}
2024-06-26 12:29:22 +02:00
SelectFirstServiceDescription ( ) ;
}
private void SelectFirstServiceDescription ( )
{
if ( Model ? . Categories2Descriptions is null | | Model . Categories2Descriptions . Count = = 0 | | Model . SelectedServiceDescription ! = null | | Model . SelectedServiceCategory ! = null )
{
return ;
}
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
{
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 ( ) ;
Model . SelectedServiceDescription = serviceDescription ;
Model . SelectedServiceCategory = serviceDescription . Category ;
2020-04-02 13:19:14 +02:00
}
2016-06-27 01:45:38 +02:00
2024-07-24 16:45:56 +02:00
private Dictionary < ServiceCategoryDC , List < ServiceDescriptionDC > > CreateServiceCategory2ServiceDescription ( List < SupportConceptTreeNodeDetailInfoDC > nodes , bool isGroupBooking )
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-03-25 17:36:15 +01:00
if ( Model . ServiceRecordOidToDelete ! = null & & Model . ServiceRecordOidToDelete > 0 & & MobileSessionFacade . LoggedInUser . UserGroups . Any ( a = > a . Rights . Any ( f = > f . RightType . 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-03-25 17:36:15 +01:00
if ( version ! = null & & MainModel . 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
}
}
2020-12-16 21:49:47 +01:00
ResetEditingMode ( ) ;
2018-11-30 16:47:57 -04:00
2018-05-22 17:19:56 +02:00
return RedirectToActionPermanent ( "Main" ) ;
2016-06-27 01:45:38 +02:00
}
2024-06-26 12:29:22 +02:00
[Authorize]
public ActionResult ReloadGoalRatings ( )
{
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return PartialView ( "GoalRatingPopupContentPartial" ) ;
}
LoadGoalRatings ( ) ;
return PartialView ( "GoalRatingPopupContentPartial" , Model ) ;
}
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 > ( ) ;
if ( Model . IsInGroupBookingMode )
{
var supportConcepts = Model . GroupBookingSelectedSupportConcepts ;
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 ;
Model . SelectedGoals . AddRangeIfElementsNotIn ( goals ) ;
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 ;
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 ) ;
if ( Model . CostBearer2SupportConceptOid . HasValue & & Model . CostBearer2SupportConceptOid ! = - 1 )
{
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
{
2022-08-10 14:13:29 +02: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
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
2021-05-17 14:01:06 +02:00
var selectedServiceRecord = Model . GetServiceRecord ( serviceRecordOid ) ;
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
2020-04-02 13:19:14 +02:00
Model . SelectedServiceRecord = selectedServiceRecord ;
Model . SelectedGoals = 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 ;
2024-07-24 16:45:56 +02:00
Model . SelectedServiceDescription = selectedServiceDescription ;
Model . SelectedServiceCategory = selectedServiceCategory ;
2018-11-30 16:47:57 -04:00
2020-12-16 21:49:47 +01:00
Model . PreviouslySelectedEmployee = Model . SelectedEmployee ;
2020-04-02 13:19:14 +02:00
Model . SelectedEmployee = selectedServiceRecord . Employee ;
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
2020-12-16 21:49:47 +01:00
Model . PreviouslySelectedSupportConcept = Model . SelectedSupportConcept ;
2024-03-14 17:18:35 +01:00
Model . PreviouslySelectedCostbearer2SupportConceptOid = Model . CostBearer2SupportConceptOid ;
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
2020-04-02 13:19:14 +02:00
Model . SelectedSupportConcept = null ;
Model . SelectedEmployee = 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 ( ) ;
2022-12-30 16:28:23 +01:00
Model . GroupBookingSelectedEmployees = employees ;
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
2020-04-02 13:19:14 +02:00
Model . SelectedConceptCostBearerRelations . AddRangeIfElementsNotIn ( OperationsService . GetSupportConceptCostBearerRelDCsByOids ( cb2ScOids ) ) ;
2020-11-20 23:28:09 +01:00
var selectedSupportConcepts = new List < SupportConceptDC > ( ) ;
selectedSupportConcepts . AddRangeIfElementsNotIn ( OperationsService . GetSupportConceptsById ( group . ServiceRecordList . Select ( s = > s . SupportConcept . SupportConceptOid ) ) ) ;
2022-12-30 16:28:23 +01:00
Model . GroupBookingSelectedSupportConcepts = selectedSupportConcepts ;
2024-06-26 12:29:22 +02:00
LoadServiceCategoriesToModel ( null ) ;
Model . SelectedServiceDescription = selectedServiceDescription ;
Model . SelectedServiceCategory = selectedServiceCategory ;
LoadGoals ( ) ;
2020-04-02 13:19:14 +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 ;
}
2020-04-02 13:19:14 +02:00
checkServiceRecord . Goals = 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
2020-04-02 13:19:14 +02:00
checkServiceRecord . Employee = Model . SelectedEmployee ? ? MobileSessionFacade . LoggedInCompactEmployee ;
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
{
2024-03-14 17:18:35 +01:00
var supportConcept = Model . SupportConcepts . FirstOrDefault ( fod = > fod . CostBearerRelations . Any ( a = > a . CostBearer2SupportConceptOid . HasValue & & a . CostBearer2SupportConceptOid . Value . Equals ( Model . CostBearer2SupportConceptOid ) ) ) ;
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
{
2024-03-14 17:18:35 +01:00
checkServiceRecord . SupportConcept = CustomerService . LoadCompactSupportConceptDC ( supportConcept . SupportConceptOid . Value , Model . Employee . EmployeeOid ) ;
2016-06-27 01:45:38 +02:00
}
2024-03-14 17:18:35 +01:00
checkServiceRecord . Customer = supportConcept . Customer ;
var cb2ScRel = supportConcept . CostBearerRelations . First ( f = > f . CostBearer2SupportConceptOid . HasValue & & f . CostBearer2SupportConceptOid . Equals ( Model . CostBearer2SupportConceptOid ) ) ;
2020-04-02 13:19:14 +02:00
checkServiceRecord . CostBearer = cb2ScRel . CostBearer ;
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
}
2020-04-02 13:19:14 +02:00
checkServiceRecord . CostBearer2SupportConceptOid = Model . CostBearer2SupportConceptOid ;
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
2024-03-14 17:18:35 +01:00
if ( MobileSessionFacade . CheckForUserRight ( 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
2024-03-14 17:18:35 +01:00
if ( Model . CostBearer2SupportConceptOid ! = null & & Model . CostBearer2SupportConceptOid > 0 )
2016-06-27 01:45:38 +02:00
{
stats = OperationsService . CreateSupportConceptStatistics ( Model . CostBearer2SupportConceptOid . Value , DateTime . Now ) ;
}
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
2023-10-25 21:52:23 +02:00
var costBearer2SupportConceptOids = Model . SelectedConceptCostBearerRelations . Where ( w = > w . CostBearer2SupportConceptOid . HasValue ) . Select ( s = > s . CostBearer2SupportConceptOid . Value ) . ToList ( ) ;
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 ) ;
var node = CreateFlatSupportConceptItem ( CustomerService . LoadCompactSupportConceptDC ( sr . SupportConcept . SupportConceptOid , Model . SelectedEmployee . EmployeeOid ) , null ) ;
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
{
var node = CreateFlatSupportConceptItem ( CustomerService . LoadCompactSupportConceptDC ( Model . SelectedSupportConcept . SupportConceptOid . Value , Model . SelectedEmployee . EmployeeOid ) , null ) ;
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 )
{
employeeOids . AddRangeIfElementsNotIn ( Model . MultiBookingSelectedEmployees . Select ( e = > e . EmployeeOid ) ) ;
var cb2ScOids = Model . MultiBookingSelectedConceptCostBearerRelations . Where ( w = > w . CostBearer2SupportConceptOid . HasValue ) . Select ( s = > s . CostBearer2SupportConceptOid . Value ) . ToList ( ) ;
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-01-31 15:15:40 +01:00
var allowOverlappingFls = MobileSessionFacade . CheckForUserRight ( UserRightType . ServiceRecord_AllowCreateOverlappingFLS ) ;
var allowOverlappingFlsForEmployee = MobileSessionFacade . CheckForUserRight ( UserRightType . ServiceRecord_AllowCreateOverlappingFLSForEmployee ) ;
var allowMoreFlsThanApproved = MobileSessionFacade . CheckForUserRight ( UserRightType . ServiceRecord_AllowCreateMoreFLSThanApproved ) ;
2024-03-14 17:18:35 +01:00
var bookAfterSettlementInvoice = MobileSessionFacade . CheckForUserRight ( UserRightType . BookServiceRecordAfterSettlementInvoice ) ;
2020-04-02 13:19:14 +02:00
var bookServiceRecordOutOfSupportConcept = MobileSessionFacade . CheckForUserRight ( UserRightType . BookServiceRecordOutOfSupportConcept ) ;
2024-03-14 17:18:35 +01:00
var allowCreateAfterEmployeeSignature = MobileSessionFacade . CheckForUserRight ( UserRightType . ServiceRecord_AllowCreateAfterEmployeeSignature ) ;
var allowEditAfterEmployeeSignature = MobileSessionFacade . CheckForUserRight ( UserRightType . ServiceRecord_AllowEditAfterEmployeeSignature ) ;
2020-10-20 21:07:26 +02:00
var allowCreateAll = MobileSessionFacade . CheckForUserRight ( UserRightType . CreateAll ) ;
var allowEditAll = MobileSessionFacade . CheckForUserRight ( 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 ;
case 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" ;
}
2024-07-24 16:45:56 +02:00
if ( ! MobileSessionFacade . CheckForUserRight ( UserRightType . ServiceRecordAllowEditAfterMindays ) )
{
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
}
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 )
{
2022-08-10 14:13:29 +02:00
if ( Model is null )
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 ( ) ;
2021-05-17 14:01:06 +02:00
var serviceRecord = Model . GetServiceRecord ( serviceRecordOid ) ;
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
var validationResultList = OperationsService . ValidateServiceRecordDeletion ( serviceRecord , Model . Employee . 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
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
2020-12-17 13:26:40 +01: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 ) ) ;
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
2022-08-10 14:13:29 +02:00
if ( Model ? . SelectedSupportConcept is null & & ( CustomerModel ) Session [ ModelSessionConstants . CustomerModelKey ] ! = null )
2018-01-29 12:57:10 +01:00
{
2020-09-21 11:57:10 +02:00
var customerModel = ( CustomerModel ) Session [ ModelSessionConstants . CustomerModelKey ] ;
2020-04-02 13:19:14 +02:00
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 ( )
{
2023-05-31 17:54:01 +02:00
return AbstractModel . HasRightToViewQuittierungsbelege ? RedirectToActionPermanent ( "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]
public ActionResult RedirectToDebuggingTools ( )
{
#if DEBUG
return RedirectToActionPermanent ( "DebuggingTools" , "DebuggingTools" ) ;
#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 )
{
2024-07-24 16:45:56 +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 ;
2020-10-07 19:42:17 +02:00
return Logout ( ) ;
2018-12-03 19:14:35 -04:00
}
2023-03-03 21:54:36 +01:00
TempData [ TempDataConstants . IsInTransferModeKey ] = null ;
TempData [ TempDataConstants . AppointmentListItemKey ] = null ;
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 ( ) ;
2024-03-14 17:18:35 +01:00
Model . PreviouslySelectedEmployee = Model . SelectedEmployee ;
Model . PreviouslySelectedSupportConcept = Model . SelectedSupportConcept ;
Model . PreviouslySelectedCostbearer2SupportConceptOid = Model . CostBearer2SupportConceptOid ;
2020-04-02 13:19:14 +02:00
2024-03-14 17:18:35 +01:00
Model . SelectedSupportConcept = null ;
Model . CostBearer2SupportConceptOid = null ;
Model . SelectedEmployee = null ;
2018-04-18 14:33:21 +02:00
2024-06-26 12:29:22 +02:00
LoadServiceCategoriesToModel ( null ) ;
2022-12-30 16:28:23 +01:00
Model . GroupBookingSelectedEmployees . AddIfNotIn ( MobileSessionFacade . LoggedInCompactEmployee ) ;
2020-04-24 19:08:09 +02:00
2021-05-17 14:01:06 +02:00
Model . IsInEditingMode = false ;
2020-04-08 14:44:20 +02:00
Model . SelectedServiceRecord = 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
2024-03-14 17:18:35 +01:00
Model . PreviouslySelectedEmployee = Model . SelectedEmployee ;
Model . PreviouslySelectedSupportConcept = Model . SelectedSupportConcept ;
Model . PreviouslySelectedCostbearer2SupportConceptOid = Model . CostBearer2SupportConceptOid ;
2022-12-30 16:28:23 +01:00
2024-03-14 17:18:35 +01:00
Model . SelectedSupportConcept = null ;
Model . CostBearer2SupportConceptOid = null ;
Model . SelectedEmployee = null ;
2022-12-30 16:28:23 +01:00
2024-06-26 12:29:22 +02:00
LoadServiceCategoriesToModel ( null ) ;
2022-12-30 16:28:23 +01:00
Model . MultiBookingSelectedEmployees . AddIfNotIn ( MobileSessionFacade . LoggedInCompactEmployee ) ;
Model . IsInEditingMode = false ;
Model . SelectedServiceRecord = null ;
Model . GroupBookingSelectedCostbearerRelOids . Clear ( ) ;
Model . GroupBookingSelectedEmployees . Clear ( ) ;
Model . GroupBookingSelectedSupportConcepts . Clear ( ) ;
2019-03-29 14:04:12 +01:00
Model . SelectedConceptCostBearerRelations . Clear ( ) ;
2022-12-30 16:28:23 +01:00
}
if ( bookingMode = = BookingMode . SingleBookingMode )
{
ResetMultiBookingMode ( ) ;
2024-03-14 17:18:35 +01:00
Model . SelectedEmployee = Model . PreviouslySelectedEmployee ? ? MobileSessionFacade . LoggedInCompactEmployee ;
2025-03-25 17:36:15 +01:00
if ( Model . PreviouslySelectedSupportConcept is object )
2024-03-14 17:18:35 +01:00
{
Model . SelectedSupportConcept = Model . PreviouslySelectedSupportConcept ;
Model . CostBearer2SupportConceptOid = Model . PreviouslySelectedCostbearer2SupportConceptOid ;
}
2018-04-18 14:33:21 +02:00
2022-12-30 16:28:23 +01:00
ResetGroupBookingMode ( ) ;
2018-11-30 16:47:57 -04:00
}
2024-07-24 16:45:56 +02:00
2025-03-25 17:36:15 +01:00
LoadSupportConceptThings ( Model . CostBearer2SupportConceptOid ) ;
//LoadGoals();
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 ( ) ;
2022-12-30 16:28:23 +01:00
Model . MultiBookingSelectedConceptCostBearerRelations . Clear ( ) ;
Model . MultiBookingSelectedEmployees . Clear ( ) ;
Model . MultiBookingSelectedGroupOfPeopleOids . Clear ( ) ;
Model . MultiBookingSelectedCostbearerRelOids . Clear ( ) ;
Model . MultiBookingSelectedSupportConcepts . Clear ( ) ;
Model . MultiBookingSupportConceptListObjects . Clear ( ) ;
}
private void ResetGroupBookingMode ( )
{
2024-07-24 16:45:56 +02:00
Model . Categories2Descriptions . Clear ( ) ;
2022-12-30 16:28:23 +01:00
Model . GroupBookingSelectedCostbearerRelOids . Clear ( ) ;
Model . GroupBookingSelectedEmployees . Clear ( ) ;
Model . GroupBookingSelectedSupportConcepts . Clear ( ) ;
Model . SelectedConceptCostBearerRelations . Clear ( ) ;
}
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 ) ;
2024-07-24 16:45:56 +02:00
LoadServiceCategoriesToModel ( Model . SelectedCostBearerSupportConceptRelOid ) ;
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 ( ) ;
}
2024-03-14 17:18:35 +01:00
if ( Model . PreviouslySelectedSupportConcept ! = null & & Model . SelectedSupportConcept is null )
{
Model . SelectedSupportConcept = Model . PreviouslySelectedSupportConcept ;
Model . CostBearer2SupportConceptOid = Model . PreviouslySelectedCostbearer2SupportConceptOid ;
}
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
{
2023-03-03 21:54:36 +01: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 ;
2020-10-07 19:42:17 +02:00
return Logout ( ) ;
2018-12-03 19:14:35 -04:00
}
2023-03-03 21:54:36 +01:00
ResetModel ( ) ;
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 ( ) ;
}
ResetModel ( ) ;
return RedirectToScheduler ( ) ;
}
[Authorize]
private void ResetModel ( )
{
if ( Model is null )
{
return ;
}
TempData [ TempDataConstants . AppointmentListItemKey ] = null ;
TempData [ TempDataConstants . IsInTransferModeKey ] = null ;
2024-03-14 17:18:35 +01:00
TempData [ TempDataConstants . AfterValidationStateKey ] = null ;
2023-03-03 21:54:36 +01:00
Model . NewServiceRecord = new ServiceRecordDC ( ) ;
Model . SelectedServiceRecord = null ;
Model . IsInEditingMode = false ;
2022-12-30 16:28:23 +01:00
Model . GroupBookingSelectedSupportConcepts . Clear ( ) ;
2020-07-15 14:37:43 +02:00
Model . SelectedConceptCostBearerRelations . Clear ( ) ;
2022-12-30 16:28:23 +01:00
Model . GroupBookingSelectedCostbearerRelOids . Clear ( ) ;
Model . GroupBookingSelectedGroupOfPeopleOids . Clear ( ) ;
2023-03-03 21:54:36 +01:00
Model . GroupBookingSelectedEmployees = new List < CompactEmployeeDC > { MobileSessionFacade . LoggedInCompactEmployee } ;
Model . SelectedEmployee = MobileSessionFacade . LoggedInCompactEmployee ;
Model . IsInMultiBookingMode = false ;
2022-12-30 16:28:23 +01:00
Model . MultiBookingSelectedCostbearerRelOids . Clear ( ) ;
Model . MultiBookingSelectedEmployees . Clear ( ) ;
2023-01-18 20:48:27 +01:00
Model . MultiBookingSelectedConceptCostBearerRelations . Clear ( ) ;
Model . MultiBookingSelectedEmployees = new List < CompactEmployeeDC > { MobileSessionFacade . LoggedInCompactEmployee } ;
Model . MultiBookingSelectedGroupOfPeopleOids . Clear ( ) ;
Model . MultiBookingSelectedSupportConcepts . Clear ( ) ;
2024-07-24 16:45:56 +02:00
Model . SelectedGoals . Clear ( ) ;
2020-08-04 12:45:46 +02:00
2024-06-26 12:29:22 +02:00
Model . SelectedServiceCategory = null ;
Model . SelectedServiceDescription = null ;
2021-01-07 19:40:15 +01:00
LoadServiceCategoriesToModel ( Model . CostBearer2SupportConceptOid ) ;
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
{
2024-06-26 12:29:22 +02:00
if ( Model is null )
{
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
2022-12-30 16:28:23 +01:00
Model . GroupBookingSelectedSupportConcepts . Clear ( ) ;
2018-11-24 14:28:46 -04:00
2022-12-30 16:28:23 +01:00
Model . GroupBookingSelectedCostbearerRelOids . Clear ( ) ;
2024-06-05 14:45:33 +02:00
Model . GroupBookingSelectedCostbearerRelOids . AddRangeIfElementsNotIn ( singleRels ) ;
2018-11-24 14:28:46 -04:00
2024-06-05 14:45:33 +02:00
var selectedSupportConcepts = CustomerService . GetSupportConceptsByCostbearer2SupportConceptRelOids ( singleRels ) ;
var groupCostBearerRelations = CustomerService . GetSupportConceptCostBearerRelationsById ( singleRels ) ;
2018-11-24 14:28:46 -04:00
2019-03-29 14:04:12 +01:00
Model . SelectedConceptCostBearerRelations . Clear ( ) ;
Model . SelectedConceptCostBearerRelations . AddRangeIfElementsNotIn ( groupCostBearerRelations ) ;
2022-12-30 16:28:23 +01:00
Model . GroupBookingSelectedSupportConcepts . AddRangeIfElementsNotIn ( selectedSupportConcepts ) ;
2018-11-24 14:28:46 -04: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
}
}
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" ) ;
}
2024-06-05 14:45:33 +02:00
if ( ! long . TryParse ( relOid , out var supportConceptCostBearerRelationOid ) )
{
2024-06-26 12:29:22 +02:00
return PartialView ( "GroupBookingSelectionPartial" , Model ) ;
2024-06-05 14:45:33 +02:00
}
2024-06-26 12:29:22 +02:00
var supportConcept2Remove = Model . GroupBookingSelectedSupportConcepts . FirstOrDefault ( f = > f . CostBearerRelations . Any ( a = > a . CostBearer2SupportConceptOid = = supportConceptCostBearerRelationOid ) ) ;
var relation2Remove = Model . SelectedConceptCostBearerRelations . FirstOrDefault ( f = > f . CostBearer2SupportConceptOid = = supportConceptCostBearerRelationOid ) ;
if ( supportConcept2Remove ? . SupportConceptOid . HasValue ? ? false )
{
var supportConcepts = Model . GroupBookingSelectedSupportConcepts . Where ( supportConcept = > supportConcept . SupportConceptOid . HasValue & & supportConcept . SupportConceptOid . Value . Equals ( supportConcept2Remove . SupportConceptOid . Value ) = = false ) . ToList ( ) ;
// Ziele, die bei den verbleibenden Hilfeplänen nicht vorhanden sind, werden aus der Auswahl entfernt.
var remainingGoals = new List < ValueListEntryDC > ( ) ;
2024-06-05 14:45:33 +02:00
2024-06-26 12:29:22 +02:00
foreach ( var supportConcept in supportConcepts )
{
foreach ( var goal in supportConcept . Goals )
{
remainingGoals . AddIfNotIn ( goal ) ;
}
}
Model . SelectedGoals = Model . SelectedGoals . Where ( goal = > remainingGoals . Contains ( goal ) ) . ToList ( ) ;
}
2024-06-05 14:45:33 +02:00
2024-06-26 12:29:22 +02:00
Model . GroupBookingSelectedSupportConcepts . Remove ( supportConcept2Remove ) ;
Model . SelectedConceptCostBearerRelations . Remove ( relation2Remove ) ;
2024-06-05 14:45:33 +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 . GroupBookingSelectedSupportConcepts . Where ( w = > w . SupportConceptOid . HasValue ) . Select ( s = > s . SupportConceptOid . Value ) . Contains ( a . SupportConceptOid ) ) ) ;
Model . GroupBookingSelectedGroupOfPeopleOids = groups . Where ( group = > group . GroupOfPeopleOid . HasValue ) . Select ( group = > group . GroupOfPeopleOid . Value ) . ToList ( ) ;
2024-06-26 12:29:22 +02:00
LoadServiceCategoriesToModel ( null ) ;
2024-06-05 14:45:33 +02:00
2024-06-26 12:29:22 +02:00
if ( Model . SelectedServiceCategory ! = null & & ! Model . Categories2Descriptions . Keys . Contains ( Model . SelectedServiceCategory ) )
{
var firstCategory2ServiceDescriptions = Model . Categories2Descriptions . FirstOrDefault ( ) ;
var firstServiceCategory = firstCategory2ServiceDescriptions . Key ;
var firstServiceDescription = firstCategory2ServiceDescriptions . Value ? . FirstOrDefault ( ) ;
Model . SelectedServiceCategory = firstServiceCategory ;
Model . SelectedServiceDescription = firstServiceDescription ;
}
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
{
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 ( ) ;
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 ) ;
2020-08-04 12:45:46 +02:00
2022-12-30 16:28:23 +01:00
return JsonConvert . SerializeObject ( Model . GroupBookingSelectedEmployees . Count ) ;
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
{
2022-08-10 14:13:29 +02:00
if ( Model is null )
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
}
2021-04-13 19:45:21 +02:00
var signatureServiceRecord = Model . GetServiceRecord ( serviceRecordOid ) ;
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
{
2024-06-26 12:29:22 +02:00
if ( Model . GroupBookingSelectedCostbearerRelOids . Count = = 1 )
2020-04-02 13:19:14 +02:00
{
2024-06-26 12:29:22 +02:00
Model . CostBearer2SupportConceptOid = Model . GroupBookingSelectedCostbearerRelOids . 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
2020-04-24 19:08:09 +02:00
var selectedCostbearer2SupportConceptRelOid = Model . CostBearer2SupportConceptOid < 1 ? null : Model . CostBearer2SupportConceptOid ;
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 ;
Model . NewServiceRecord . Goals = Model . SelectedGoals ;
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
2022-09-07 13:19:08 +02:00
if ( Model . Employee . 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 ;
}
2024-03-14 17:18:35 +01:00
var supportConcept = Model . SupportConcepts . FirstOrDefault ( fod = > fod . CostBearerRelations . Any ( a = > a . CostBearer2SupportConceptOid . HasValue & & a . CostBearer2SupportConceptOid . Value . Equals ( selectedCostbearer2SupportConceptRelOid ) ) ) ;
2020-04-02 13:19:14 +02:00
2024-03-14 17:18:35 +01:00
if ( supportConcept ! = null )
2020-04-02 13:19:14 +02:00
{
2024-03-14 17:18:35 +01:00
if ( supportConcept . SupportConceptOid . HasValue )
2020-04-02 13:19:14 +02:00
{
2024-03-14 17:18:35 +01:00
Model . NewServiceRecord . SupportConcept = CustomerService . LoadCompactSupportConceptDC ( supportConcept . SupportConceptOid . Value , Model . Employee . EmployeeOid ) ;
2020-04-02 13:19:14 +02:00
}
2024-03-14 17:18:35 +01:00
Model . NewServiceRecord . Customer = supportConcept . Customer ;
2020-04-02 13:19:14 +02:00
2024-03-14 17:18:35 +01:00
var cb2ScRel = supportConcept . CostBearerRelations . First ( f = > f . CostBearer2SupportConceptOid . HasValue & & f . CostBearer2SupportConceptOid . Equals ( selectedCostbearer2SupportConceptRelOid ) ) ;
2020-04-02 13:19:14 +02:00
Model . NewServiceRecord . CostBearer = cb2ScRel . CostBearer ;
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 ;
Model . NewServiceRecord . InsUser = $"{MobileSessionFacade.LoggedInEmployee.FirstName} {MobileSessionFacade.LoggedInEmployee.LastName}" ;
Model . NewServiceRecord . IsCreatedInMobileClient = true ;
2024-03-14 17:18:35 +01:00
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 ) ;
}
}
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
[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
2023-02-23 11:48:41 +01:00
[Authorize]
public void LoadSupportConceptThings ( long? cb2ScOid )
{
if ( Model is null )
{
Logout ( ) ;
return ;
}
LoadServiceCategoriesToModel ( cb2ScOid ) ;
LoadGoalRatings ( ) ;
LoadGoals ( ) ;
}
2023-03-29 15:49:20 +02:00
/// <summary>
/// Bereitet die Übernahme eines Termins in die Zeiterfassung vor. Wird im SchedulerController aufgerufen.
/// </summary>
/// <returns></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 ( ) ;
}
2023-03-03 21:54:36 +01:00
if ( TempData [ TempDataConstants . AppointmentListItemKey ] is AppointmentListItem appointmentListItem & & Model . Employee . EmployeeOid . HasValue )
2023-02-23 11:48:41 +01:00
{
2023-03-03 21:54:36 +01:00
TempData [ TempDataConstants . IsInTransferModeKey ] = true ;
2023-02-23 11:48:41 +01:00
var appointment = appointmentListItem . SchedulerAppointment ;
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 )
{
employeeOids . Add ( Model . Employee . 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 > ( ) ;
var supportConcepts = customerService . GetAllActiveSupportConceptCostbearer ( false , true , Model . Employee . EmployeeOid . Value ) ;
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 ) ;
2023-02-23 11:48:41 +01:00
Model . SelectedEmployee = Model . AllEmployees . FirstOrDefault ( e = > e . EmployeeOid . Equals ( Model . Employee . EmployeeOid . Value ) ) ;
LoadSupportConceptThings ( - 2 ) ;
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 = >
{
if ( long . TryParse ( sclo . CostBearer2SupportConceptOid , out var costBearer2SupportConceptRelOid ) )
{
availableRelOids . AddIfNotIn ( costBearer2SupportConceptRelOid ) ;
}
} ) ;
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 ( ) ;
var supportConcept = Model . SupportConcepts . FirstOrDefault ( f = > f . SupportConceptOid . HasValue & & f . SupportConceptOid . Value . 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
2024-07-24 16:45:56 +02:00
var costBearer2SupportConcept = supportConcept ? . CostBearerRelations . FirstOrDefault ( cbRel = > cbRel . CostBearer2SupportConceptOid . HasValue & & availableRelOids . Contains ( cbRel . CostBearer2SupportConceptOid . Value ) ) ;
2023-03-03 21:54:36 +01:00
2024-07-24 16:45:56 +02:00
LoadSupportConceptThings ( costBearer2SupportConcept ? . CostBearer2SupportConceptOid ? ? - 2 ) ;
2023-02-23 11:48:41 +01:00
2024-07-24 16:45:56 +02:00
serviceRecord . CostBearer = costBearer2SupportConcept ? . CostBearer ;
serviceRecord . CostBearer2SupportConceptOid = costBearer2SupportConcept ? . CostBearer2SupportConceptOid ;
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
2024-07-24 16:45:56 +02:00
var supportConceptsForGroupBooking = Model . SupportConcepts . Where ( sc = > sc . SupportConceptOid . HasValue & & supportConceptList . Any ( csc = > csc . SupportConceptOid . Equals ( sc . SupportConceptOid . Value ) ) ) . ToList ( ) ;
2023-03-03 21:54:36 +01:00
2024-07-24 16:45:56 +02:00
var costBearer2SupportConceptOids = new List < long > ( ) ;
var costBearer2SupportConcepts = new List < SupportConceptCostBearerRelDC > ( ) ;
2023-03-03 21:54:36 +01:00
2024-07-24 16:45:56 +02:00
foreach ( var supportConcept in supportConceptsForGroupBooking )
2023-03-03 21:54:36 +01:00
{
2024-07-24 16:45:56 +02:00
var costBearer2SupportConcept = supportConcept ? . CostBearerRelations . FirstOrDefault ( cbRel = > cbRel . CostBearer2SupportConceptOid . HasValue & & availableRelOids . Contains ( cbRel . CostBearer2SupportConceptOid . Value ) ) ;
if ( costBearer2SupportConcept ? . CostBearer2SupportConceptOid is null )
{
continue ;
}
costBearer2SupportConceptOids . AddIfNotIn ( costBearer2SupportConcept . CostBearer2SupportConceptOid . Value ) ;
costBearer2SupportConcepts . AddIfNotIn ( costBearer2SupportConcept ) ;
2023-03-03 21:54:36 +01:00
}
2024-07-24 16:45:56 +02:00
if ( costBearer2SupportConceptOids . Any ( ) )
{
Model . GroupBookingSelectedCostbearerRelOids = costBearer2SupportConceptOids ;
Model . SelectedConceptCostBearerRelations = costBearer2SupportConcepts ;
Model . GroupBookingSelectedSupportConcepts = supportConceptsForGroupBooking ;
}
2023-03-03 21:54:36 +01:00
2024-07-24 16:45:56 +02:00
LoadServiceCategoriesToModel ( null ) ;
LoadGoals ( ) ;
2023-03-03 21:54:36 +01:00
}
2023-02-23 11:48:41 +01:00
}
2023-03-03 21:54:36 +01:00
TempData [ TempDataConstants . AppointmentListItemKey ] = appointmentListItem ;
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 )
{
if ( Model is null )
{
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
{
LoadServiceCategoriesToModel ( null ) ;
}
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 ) ;
}
} ) ;
Model . MultiBookingSelectedGroupOfPeopleOids . Clear ( ) ;
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 ) ) ;
} ) ;
Model . MultiBookingSelectedSupportConcepts . Clear ( ) ;
Model . MultiBookingSelectedCostbearerRelOids . Clear ( ) ;
Model . MultiBookingSelectedCostbearerRelOids . AddRangeIfElementsNotIn ( singleRels ) ;
var selectedSupportConcepts = CustomerService . GetSupportConceptsByCostbearer2SupportConceptRelOids ( singleRels ) ;
var groupCostBearerRelations = CustomerService . GetSupportConceptCostBearerRelationsById ( singleRels ) ;
Model . MultiBookingSelectedConceptCostBearerRelations . Clear ( ) ;
Model . MultiBookingSelectedConceptCostBearerRelations . AddRangeIfElementsNotIn ( groupCostBearerRelations ) ;
Model . MultiBookingSelectedSupportConcepts . AddRangeIfElementsNotIn ( selectedSupportConcepts ) ;
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 ) )
{
Model . MultiBookingSelectedGroupOfPeopleOids . AddIfNotIn ( groupOid ) ;
}
else if ( Model . MultiBookingSelectedGroupOfPeopleOids . Contains ( groupOid ) )
{
Model . MultiBookingSelectedGroupOfPeopleOids . Remove ( groupOid ) ;
}
}
return PartialView ( "MultiBookingScCbRelList" , Model ) ;
}
[Authorize]
public ActionResult RemoveSupportConceptCostbearerRelFromMultiBooking ( string relOid )
{
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
return PartialView ( "MultiBookingSelectionPartial" ) ;
}
if ( ! long . TryParse ( relOid , out var supportConceptCostBearerRelationOid ) )
{
return PartialView ( "MultiBookingSelectionPartial" , Model ) ;
}
var supportConcept2Remove = Model . MultiBookingSelectedSupportConcepts . FirstOrDefault ( f = > f . CostBearerRelations . Any ( a = > a . CostBearer2SupportConceptOid = = supportConceptCostBearerRelationOid ) ) ;
var relation2Remove = Model . MultiBookingSelectedConceptCostBearerRelations . FirstOrDefault ( f = > f . CostBearer2SupportConceptOid = = supportConceptCostBearerRelationOid ) ;
if ( supportConcept2Remove ? . SupportConceptOid . HasValue ? ? false )
{
var supportConcepts = Model . MultiBookingSelectedSupportConcepts . Where ( supportConcept = > supportConcept . SupportConceptOid . HasValue & & supportConcept . SupportConceptOid . Value . Equals ( supportConcept2Remove . SupportConceptOid . Value ) = = false ) . ToList ( ) ;
// Ziele, die bei den verbleibenden Hilfeplänen nicht vorhanden sind, werden aus der Auswahl entfernt.
var remainingGoals = new List < ValueListEntryDC > ( ) ;
foreach ( var supportConcept in supportConcepts )
{
foreach ( var goal in supportConcept . Goals )
{
remainingGoals . AddIfNotIn ( goal ) ;
}
}
Model . SelectedGoals = Model . SelectedGoals . Where ( goal = > remainingGoals . Contains ( goal ) ) . ToList ( ) ;
}
Model . MultiBookingSelectedSupportConcepts . Remove ( supportConcept2Remove ) ;
Model . MultiBookingSelectedConceptCostBearerRelations . Remove ( relation2Remove ) ;
var selectedGroups = Model . GroupsOfPeople . Where ( group = > group . GroupOfPeopleOid . HasValue & & Model . MultiBookingSelectedGroupOfPeopleOids . Contains ( group . GroupOfPeopleOid . Value ) ) . ToList ( ) ;
var groups = selectedGroups . Where ( group = > group . SupportConceptList . All ( a = > Model . MultiBookingSelectedSupportConcepts . Where ( w = > w . SupportConceptOid . HasValue ) . Select ( s = > s . SupportConceptOid . Value ) . Contains ( a . SupportConceptOid ) ) ) ;
Model . MultiBookingSelectedGroupOfPeopleOids = groups . Where ( group = > group . GroupOfPeopleOid . HasValue ) . Select ( group = > group . GroupOfPeopleOid . Value ) . ToList ( ) ;
LoadServiceCategoriesToModel ( null ) ;
if ( Model . SelectedServiceCategory ! = null & & ! Model . Categories2Descriptions . Keys . Contains ( Model . SelectedServiceCategory ) )
{
var firstCategory2ServiceDescriptions = Model . Categories2Descriptions . FirstOrDefault ( ) ;
var firstServiceCategory = firstCategory2ServiceDescriptions . Key ;
var firstServiceDescription = firstCategory2ServiceDescriptions . Value . FirstOrDefault ( ) ;
Model . SelectedServiceCategory = firstServiceCategory ;
Model . SelectedServiceDescription = firstServiceDescription ;
}
return PartialView ( "MultiBookingSelectionPartial" , Model ) ;
}
2022-12-30 16:28:23 +01:00
[Authorize]
[HttpPost]
public ActionResult SetMultiBookingMode ( FormCollection formCollection )
{
if ( Model is null )
{
return Logout ( ) ;
}
2023-03-14 16:12:52 +01:00
TempData [ TempDataConstants . IsInTransferModeKey ] = null ;
TempData [ TempDataConstants . AppointmentListItemKey ] = null ;
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 ;
}
}
var selectedCostbearer2SupportConceptRelOid = Model . CostBearer2SupportConceptOid < 1 ? null : Model . CostBearer2SupportConceptOid ;
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 > ( ) ;
if ( Model . MultiBookingSelectedConceptCostBearerRelations . Any ( ) & & Model . MultiBookingSelectedEmployees . Any ( ) )
{
foreach ( var sc2cbRel in Model . MultiBookingSelectedConceptCostBearerRelations )
{
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
foreach ( var employee in Model . MultiBookingSelectedEmployees )
{
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 ,
InsUser = $"{MobileSessionFacade.LoggedInEmployee.FirstName} {MobileSessionFacade.LoggedInEmployee.LastName}" ,
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 ) )
{
Model . MultiBookingSelectedEmployees . Clear ( ) ;
return JsonConvert . SerializeObject ( Model . MultiBookingSelectedEmployees . Count ) ;
}
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
Model . MultiBookingSelectedEmployees . Clear ( ) ;
Model . MultiBookingSelectedEmployees . AddRangeIfElementsNotIn ( employees ) ;
return JsonConvert . SerializeObject ( Model . MultiBookingSelectedEmployees . Count ) ;
}
2024-06-26 12:29:22 +02:00
// Veraltet
2022-12-30 16:28:23 +01:00
[Authorize]
public string MultiBookingHasSelectedSupportConcepts ( )
{
try
{
return JsonConvert . SerializeObject ( Model . MultiBookingSelectedConceptCostBearerRelations . Any ( ) ) ;
}
catch ( Exception exception )
{
Log . Error ( exception . Message , exception ) ;
}
return JsonConvert . SerializeObject ( false ) ;
}
[Authorize]
public string MultiBookingHasSelectedEmployees ( )
{
try
{
return JsonConvert . SerializeObject ( Model . MultiBookingSelectedEmployees . Any ( ) ) ;
}
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 )
{
if ( Model is null | | ! MobileSessionFacade . IsUserLoggedIn ( ) | | MobileSessionFacade . LoggedInUserDC . UserVersion is null )
{
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 )
{
var checkResult = UserService . CheckPassword ( MobileSessionFacade . LoggedInUser . Oid . Value , oldPassword , newPassword ) ;
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" ) ;
}
}
2023-06-21 19:19:56 +02:00
var userName = MobileSessionFacade . LoggedInUserDC . LoginName ;
var userVersion = MobileSessionFacade . LoggedInUserDC . UserVersion . Value ;
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 ;
2024-09-12 14:55:35 +02:00
var selectedEmployeeOid = Model . SelectedEmployee ? . EmployeeOid ? ? Model . Employee . EmployeeOid . Value ;
2024-01-12 17:16:52 +01:00
// Ohne Hilfeplan
if ( Model . CostBearer2SupportConceptOid is null | | Model . CostBearer2SupportConceptOid < 1 )
{
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 ,
Model . CostBearer2SupportConceptOid . Value ,
Model . SelectedZeitraum . StartDate . Value ,
Model . SelectedZeitraum . EndDate . Value ,
firstResult , Model . MaxResults ,
out totalServiceRecords ) :
2024-09-12 14:55:35 +02:00
OperationsService . FindServiceRecordsForLastDaysPaginated ( Model . CostBearer2SupportConceptOid , Model . SelectedDayCount , Model . Employee ? . 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 ;
var serviceRecord = Model . GetServiceRecord ( serviceRecordOid ) ;
2024-07-24 16:45:56 +02:00
var hilfeplan = Model . SelectedCostBearer2SupportConceptRelListObject . NameAndDateOfBirth + " | " + Model . SelectedCostBearer2SupportConceptRelListObject . 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 ( )
{
2024-06-26 12:29:22 +02:00
if ( Model is null )
{
TempData [ TempDataConstants . DoLogoutKey ] = true ;
}
2024-06-05 14:45:33 +02:00
LoadGoals ( ) ;
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 ;
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 )
{
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
}