2016-06-27 01:45:38 +02:00
using System ;
using System.Collections.Generic ;
2018-04-27 14:11:21 +02:00
using System.Diagnostics ;
2019-11-21 19:39:32 +01:00
using System.Drawing ;
using System.IO ;
2016-06-27 01:45:38 +02:00
using System.Linq ;
2018-10-08 11:57:16 +02:00
using System.Text ;
2016-06-27 01:45:38 +02:00
using System.Web.Mvc ;
2018-12-10 23:40:38 -04:00
2018-04-18 14:33:21 +02:00
using BeWo.Service.ServiceImplementations ;
2018-11-26 13:27:16 -04:00
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 ;
2020-02-07 15:21:36 +01:00
using Newtonsoft.Json ;
2018-12-10 23:40:38 -04:00
using static BS . Shared . ServiceRecordValidationResult ;
2018-11-30 16:47:57 -04:00
using ServiceRecordDC = BS . Shared . DataContracts . ServiceRecordDC ;
2018-01-29 12:57:10 +01:00
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 ;
}
2018-04-18 14:33:21 +02:00
if ( ( ( MainModel ) Session [ MainModelSessionKey ] ) ? . Employee = = null )
2016-06-27 01:45:38 +02:00
{
2018-01-29 12:57:10 +01:00
_Model = new MainModel { Employee = MobileSessionFacade . LoggedInEmployee } ;
Session [ MainModelSessionKey ] = _Model ;
2016-06-27 01:45:38 +02:00
}
else
{
2019-07-25 14:56:11 +02:00
_Model = ( MainModel ) Session [ MainModelSessionKey ] ;
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
}
}
2017-04-26 14:57:32 +02:00
private const string MainModelSessionKey = "MainModel" ;
2018-01-29 12:57:10 +01:00
private Dictionary < long , ValueListEntryDC > _ParentGoals ;
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
private static readonly List < ValueListEntryType > _Zieltypen = new List < ValueListEntryType > { ValueListEntryType . SupportConceptGoalCategoryType , ValueListEntryType . SupportConceptIndividualGoalCategoryType } ;
private static readonly List < ValueListEntryType > _Massnahmentypen = new List < ValueListEntryType > { ValueListEntryType . SupportConceptGoalType , ValueListEntryType . SupportConceptIndividualGoalType } ;
2016-06-27 01:45:38 +02:00
[Authorize]
public ActionResult Main ( )
{
try
{
2017-08-22 14:05:09 +02:00
ViewData [ "ValidationError" ] = string . Empty ;
2016-06-27 01:45:38 +02:00
2020-01-15 16:14:39 +01:00
var value = TempData [ TempDataLoginStateKey ] ;
2018-02-28 12:42:23 +01:00
if ( ! MobileSessionFacade . IsUserLoggedIn ( ) | | Request . Browser . Browser . Equals ( "InternetExplorer" ) )
2017-08-22 14:05:09 +02:00
{
2018-02-07 14:14:08 +01:00
return RedirectToActionPermanent ( "Index" , "Login" ) ;
2017-08-22 14:05:09 +02:00
}
2016-06-27 01:45:38 +02:00
2018-02-28 12:42:23 +01:00
Model . ShowExpiredSupportConcepts = GetUserSettingValue ( "ShowExpiredSupportConcepts" ) = = "1" ;
Model . ShowOnlyOwnSupportConcepts = GetUserSettingValue ( "ShowOnlyMySupportConcepts" ) = = "1" ;
2019-07-19 19:50:15 +02:00
var mandator = OperationsService . GetMandator ( ) ;
var supportConceptExpirationLimitInMonths = MobileUtils . GetSettingValue ( mandator . Settings , "HilfeplanAuslaufAuswahl" ) ;
2019-08-08 14:47:53 +02:00
var anzTageZeiterfassErfolgt = MobileUtils . GetSettingValue ( mandator . Settings , "AnzTageZeiterfassErfolgt" ) ;
var maxDaysEditServiceRecordsAllowed = MobileUtils . GetSettingValue ( mandator . Settings , "MaxDaysEditServiceRecordsAllowed" ) ;
2019-07-19 19:50:15 +02:00
BS . Shared . Settings . ApplicationSettings . SupportConceptExpirationLimitInMonths = supportConceptExpirationLimitInMonths = = null ? 3 : int . Parse ( supportConceptExpirationLimitInMonths ) ;
2019-08-08 14:47:53 +02:00
BS . Shared . Settings . ApplicationSettings . AnzTageZeiterfassErfolgt = anzTageZeiterfassErfolgt = = null ? 0 : int . Parse ( anzTageZeiterfassErfolgt ) ;
BS . Shared . Settings . ApplicationSettings . MaxDaysEditServiceRecordsAllowed = maxDaysEditServiceRecordsAllowed = = null ? 0 : int . Parse ( maxDaysEditServiceRecordsAllowed ) ;
2017-02-01 13:53:59 +01:00
var unter = GetSettingValue ( "ShowSignature" ) ;
Model . ShowSignature = unter = = "1" ;
2018-10-10 16:43:11 +02:00
#if DEBUG
Model . ShowSignature = true ;
#endif
2018-04-27 14:11:21 +02:00
Model . GroupsOfPeople = EmployeeService . GetAllGroups ( GetUser ( ) . Employee . EmployeeOid ) ;
2017-02-01 13:53:59 +01:00
Model . SelectedGoals = null ;
2018-02-02 14:43:40 +01:00
Model . ShowDistanceField = "1" = = GetSettingValue ( "ShowDistanceFields" ) ;
2017-02-01 13:53:59 +01:00
Model . Dokutypes = ValueListService . GetAllValueListEntrysByType ( ValueListEntryType . DocumentType ) ;
if ( Model . Dokutypes ! = null )
{
Model . Dokutypes = Model . Dokutypes . OrderBy ( s = > s . ValueListEntryOid ) . ToArray ( ) ;
}
2018-02-02 14:43:40 +01:00
if ( MainModel . AllEmployees = = null )
2016-06-27 01:45:38 +02:00
{
2018-10-08 11:57:16 +02:00
MainModel . AllEmployees = EmployeeService . GetAllActiveEmployeesCompact ( ) . OrderBy ( e = > e . LastName ) . ToList ( ) ;
2016-06-27 01:45:38 +02:00
}
var myRelatedCustomers = Model . Employee = = null ? new List < CustomerEmployeeRelationDC > ( ) : Model . Employee . RelatedCustomers ;
2019-09-27 15:55:01 +02:00
var relatedCustomerOids = myRelatedCustomers . Select ( employee2customer = > employee2customer . Customer . CustomerOid ) . ToList ( ) ;
if ( Model . Employee ? . EmployeeOid ! = null )
{
2019-11-27 18:03:35 +01:00
//relatedCustomerOids.AddRangeIfElementsNotIn(EmployeeService.LoadTeamsRelatedCustomerOids(Model.Employee.EmployeeOid.Value));
2019-09-27 15:55:01 +02:00
}
2016-06-27 01:45:38 +02:00
2019-07-25 14:56:11 +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
{
Model . Employees = EmployeeService . GetAllTeamMember ( MobileSessionFacade . LoggedInCompactEmployee ) ;
}
else
{
Model . Employees = new List < CompactEmployeeDC > { MobileSessionFacade . LoggedInCompactEmployee } ;
}
2018-02-02 14:43:40 +01:00
if ( Model . ShowOnlyOwnSupportConcepts = = false & & MobileSessionFacade . CheckForUserRight ( UserRightType . SupportConcept_ViewAllSupportConcepts ) )
2016-06-27 01:45:38 +02:00
{
Model . SupportConcepts = CustomerService . GetAllActiveSupportConcepts ( ) ;
}
else
{
2019-09-27 15:55:01 +02:00
Model . SupportConcepts = CustomerService . GetAllActiveSupportConceptsByCustomers ( relatedCustomerOids ) ;
2016-06-27 01:45:38 +02:00
}
2018-02-28 12:42:23 +01:00
if ( ! Model . ShowExpiredSupportConcepts )
{
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
return endDate = = null | | endDate . Value > = DateTime . Now ;
} ) . ToList ( ) ;
}
if ( Model . ServiceCategories = = null )
2016-06-27 01:45:38 +02:00
{
Model . ServiceCategories = new List < ServiceCategoryModel > ( ) ;
}
2019-03-29 14:04:12 +01:00
if ( Model . SelectedConceptCostBearerRelations = = null )
{
Model . SelectedConceptCostBearerRelations = new List < SupportConceptCostBearerRelDC > ( ) ;
}
2016-06-27 01:45:38 +02:00
if ( Model . CostBearer2SupportConceptOid ! = null )
{
LoadRecordsToModel ( ) ;
}
2018-12-10 23:40:38 -04:00
if ( Model . SelectedEmployee = = null )
{
Model . SelectedEmployee = MobileSessionFacade . LoggedInCompactEmployee ;
}
2018-12-12 14:27:40 -04:00
2019-11-25 21:19:07 +01:00
var isServiceRecordNoticeMandatorySetting = GetSettingValue ( "IsServiceRecordNoticeMandatory" ) ;
if ( isServiceRecordNoticeMandatorySetting ! = null & & isServiceRecordNoticeMandatorySetting = = "0" )
2018-12-12 14:27:40 -04:00
{
Model . IsServiceRecordNoticeMandatory = false ;
}
else
{
Model . IsServiceRecordNoticeMandatory = true ;
}
2019-07-19 17:13:57 +02:00
if ( Model . SelectedSupportConceptListObject = = null )
{
Model . SelectedSupportConceptListObject = Model . SupportConceptListObjects . First ( ) ;
}
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 View ( Model ) ;
}
[HttpPost]
[Authorize]
public ActionResult SetShowOnlyOwnSupportConcepts ( FormCollection collection )
{
2018-12-10 23:40:38 -04:00
if ( Model = = null )
{
return RedirectToActionPermanent ( "Index" , "Login" ) ;
}
2018-02-28 12:42:23 +01:00
var newValue = "true,false" = = collection [ "ShowOnlyOwnSupportConcepts" ] ;
Model . ShowOnlyOwnSupportConcepts = newValue ;
2018-03-02 16:33:39 +01:00
return UpdateSettings ( "ShowOnlyMySupportConcepts" , newValue ? "1" : "0" ) ; ;
}
2018-02-28 12:42:23 +01:00
2018-03-02 16:33:39 +01:00
[HttpPost]
[Authorize]
public ActionResult SetShowExpiredSupportConcepts ( FormCollection pCollection )
{
2018-12-10 23:40:38 -04:00
if ( Model = = null )
{
return RedirectToActionPermanent ( "Index" , "Login" ) ;
}
2018-03-02 16:33:39 +01:00
var newValue = "true,false" = = pCollection [ "ShowExpiredSupportConcepts" ] ;
2016-06-27 01:45:38 +02:00
2018-03-02 16:33:39 +01:00
Model . ShowExpiredSupportConcepts = newValue ;
return UpdateSettings ( "ShowExpiredSupportConcepts" , newValue ? "1" : "0" ) ;
}
2018-12-13 20:59:05 -04:00
[Authorize]
2018-03-02 16:33:39 +01:00
public ActionResult UpdateSettings ( string pKey , string pValue )
{
2018-12-10 23:40:38 -04:00
if ( Model = = null )
{
2018-12-13 20:59:05 -04:00
return RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-10 23:40:38 -04:00
}
2018-03-02 16:33:39 +01:00
var userSettings = GetUser ( ) . Settings ;
UserSettingsUtils . SetSettingValue ( SettingsType . ApplicationSettings , pKey , pValue , userSettings ) ;
UserService . UpdateUserSettings ( GetUser ( ) . UserOid . Value , userSettings ) ;
return RedirectToAction ( "Main" ) ;
2016-06-27 01:45:38 +02:00
}
[HttpPost]
public new ActionResult Logout ( )
2017-03-06 14:45:35 +01:00
{
2016-06-27 01:45:38 +02:00
return base . Logout ( ) ;
}
[Authorize]
2017-04-26 14:57:32 +02:00
public string LoadGoals ( long pCostbearer2SupportConceptOid )
2016-06-27 01:45:38 +02:00
{
if ( Model = = null )
{
2018-12-10 23:40:38 -04:00
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return " " ;
2016-06-27 01:45:38 +02:00
}
var sc = Model . SupportConcepts . FirstOrDefault ( f = > f . CostBearerRelations . Any ( cbr = > cbr . CostBearer2SupportConceptOid . HasValue & & cbr . CostBearer2SupportConceptOid . Value . Equals ( pCostbearer2SupportConceptOid ) ) ) ;
if ( sc = = null )
2018-01-29 12:57:10 +01:00
{
2018-12-12 14:27:40 -04:00
return " " ;
2018-01-29 12:57:10 +01:00
}
2016-06-27 01:45:38 +02:00
Model . SelectedSupportConcept = sc ;
var selectedGoals = sc . Goals ;
var missingParents = selectedGoals . Where ( w = > w . ParentOid ! = null & & false = = selectedGoals . Any ( a = > a . ValueListEntryOid . Equals ( w . ParentOid ) ) ) . Select ( s = > s . ParentOid ) . ToList ( ) ;
2018-01-29 12:57:10 +01:00
_ParentGoals = new Dictionary < long , ValueListEntryDC > ( ) ;
2016-06-27 01:45:38 +02:00
foreach ( var oid in missingParents )
{
LoadMissingParents ( oid . Value ) ;
}
2018-05-22 17:19:56 +02:00
var goalTree = BuildGoalTree ( selectedGoals . Union ( _ParentGoals . Values ) . ToList ( ) ) ;
return SerializeObject ( goalTree ) ;
2016-06-27 01:45:38 +02:00
}
private static List < GoalTreeItem > BuildGoalTree ( List < ValueListEntryDC > goals )
{
2018-01-29 12:57:10 +01:00
var ziele = goals . Where ( w = > _Zieltypen . Contains ( w . Type ) ) . OrderBy ( s = > s . TypeDescription ) . ToList ( ) ;
var massnahmen = goals . Where ( w = > _Massnahmentypen . Contains ( w . Type ) ) . OrderBy ( s = > s . TypeDescription ) . ToList ( ) ;
2016-06-27 01:45:38 +02:00
var goalTree = new List < GoalTreeItem > ( ) ;
var goalTreeDic = new Dictionary < long , GoalTreeItem > ( ) ;
2018-02-02 14:43:40 +01:00
foreach ( var ziel in ziele )
2016-06-27 01:45:38 +02:00
{
var treeItem = new GoalTreeItem { Children = new List < GoalTreeItem > ( ) , Header = ziel . TypeDescription , ParentOid = ziel . ParentOid , ValueListEntryOid = ziel . ValueListEntryOid } ;
goalTreeDic . Add ( ziel . ValueListEntryOid . Value , treeItem ) ;
2018-02-02 14:43:40 +01:00
if ( ziel . ParentOid = = null )
2016-06-27 01:45:38 +02:00
{
goalTree . Add ( treeItem ) ;
}
}
2018-02-02 14:43:40 +01:00
foreach ( var zielMitEltern in goalTreeDic . Values . Where ( w = > w . ParentOid ! = null ) )
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
{
var kind = new GoalTreeItem { Children = new List < GoalTreeItem > ( ) , Header = ziel . TypeDescription , IsLeaf = true , ValueListEntryOid = ziel . ValueListEntryOid } ;
2018-02-02 14:43:40 +01:00
if ( ziel . ParentOid ! = null & & goalTreeDic . ContainsKey ( ziel . ParentOid . Value ) )
2016-06-27 01:45:38 +02:00
{
kind . ParentOid = goalTreeDic [ ziel . ParentOid . Value ] . ParentOid ;
goalTreeDic [ ziel . ParentOid . Value ] . Children . Add ( kind ) ;
}
}
2018-02-02 14:43:40 +01:00
foreach ( var item in goalTreeDic . Values )
2016-06-27 01:45:38 +02:00
{
2018-06-13 14:38:35 +02:00
if ( item . Children . Count = = 0 )
2018-02-02 14:43:40 +01:00
{
item . IsLeaf = true ;
}
2016-06-27 01:45:38 +02:00
}
2018-06-13 14:38:35 +02:00
2016-06-27 01:45:38 +02:00
return goalTree ;
}
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 ) ;
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 ;
}
}
2018-12-10 23:40:38 -04:00
[Authorize]
2016-06-27 01:45:38 +02:00
public string LoadBWPSettings ( )
{
2018-12-10 23:40:38 -04:00
if ( Model = = null )
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2018-12-10 23:40:38 -04:00
}
2016-06-27 01:45:38 +02:00
var m = OperationsService . GetMandator ( ) ;
2018-11-24 14:28:46 -04:00
var time = MobileUtils . GetSettingValue ( m . Settings , "TimeUntilUILock" ) ;
2016-06-27 01:45:38 +02:00
return SerializeObject ( time ) ;
}
2018-12-13 20:59:05 -04:00
[Authorize]
2018-11-24 14:28:46 -04:00
public string CheckEndDate ( )
{
2018-12-10 23:40:38 -04:00
if ( Model = = null )
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2018-12-10 23:40:38 -04:00
}
2016-06-27 01:45:38 +02:00
var m = OperationsService . GetMandator ( ) ;
2018-11-24 14:28:46 -04:00
var endtime = MobileUtils . GetSettingValue ( m . Settings , "IsEndDateVisible" ) ;
2016-06-27 01:45:38 +02:00
return SerializeObject ( endtime ) ;
}
2018-12-13 20:59:05 -04:00
[Authorize]
2017-01-16 16:13:19 +01:00
public string CheckOnlyYearMonth ( )
{
2018-12-10 23:40:38 -04:00
if ( Model = = null )
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2018-12-10 23:40:38 -04:00
}
2017-01-16 16:13:19 +01:00
var m = OperationsService . GetMandator ( ) ;
2018-11-24 14:28:46 -04:00
var yearMonth = MobileUtils . GetSettingValue ( m . Settings , "IsOnlyYearMonthVisible" ) ;
2017-01-16 16:13:19 +01:00
return SerializeObject ( yearMonth ) ;
}
2017-01-19 17:02:07 +01:00
2018-12-13 20:59:05 -04:00
[Authorize]
2017-01-19 17:02:07 +01:00
public string CheckIsZeiterfassDateNormal ( )
{
2018-12-10 23:40:38 -04:00
if ( Model = = null )
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2018-12-10 23:40:38 -04:00
}
2017-01-19 17:02:07 +01:00
var m = OperationsService . GetMandator ( ) ;
2018-11-24 14:28:46 -04:00
var normal = MobileUtils . GetSettingValue ( m . Settings , "IsZeiterfassDateNormal" ) ;
2017-01-19 17:02:07 +01:00
return SerializeObject ( normal ) ;
}
2018-12-13 20:59:05 -04:00
[Authorize]
2017-01-19 17:02:07 +01:00
public string CheckIsZeiterfassungInStdMin ( )
{
2018-12-10 23:40:38 -04:00
if ( Model = = null )
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2018-12-10 23:40:38 -04:00
}
2017-01-19 17:02:07 +01:00
var m = OperationsService . GetMandator ( ) ;
2018-11-24 14:28:46 -04:00
var zeiterInStdMin = MobileUtils . GetSettingValue ( m . Settings , "IsZeiterfassungInStdMin" ) ;
2017-01-19 17:02:07 +01:00
return SerializeObject ( zeiterInStdMin ) ;
}
2016-06-27 01:45:38 +02:00
2018-12-13 20:59:05 -04:00
[Authorize]
2017-02-01 13:53:59 +01:00
public string CheckDokuReiter ( )
{
2018-12-10 23:40:38 -04:00
if ( Model = = null )
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2018-12-10 23:40:38 -04:00
}
2017-02-01 13:53:59 +01:00
return SerializeObject ( Model . Dokutypes ) ;
2016-06-27 01:45:38 +02:00
}
2018-02-28 12:42:23 +01:00
private static string GetUserSettingValue ( string key )
{
var user = MobileSessionFacade . LoggedInUser ;
var settings = user ? . SettingList . FirstOrDefault ( f = > f . Type . Equals ( SettingsType . ApplicationSettings ) ) ;
2018-11-24 14:28:46 -04:00
return settings ! = null ? MobileUtils . GetSettingValue ( settings . Value , key ) : null ;
2018-02-28 12:42:23 +01:00
}
2017-02-01 13:53:59 +01:00
private string GetSettingValue ( string key )
{
var man = OperationsService . GetMandator ( ) ;
2018-11-24 14:28:46 -04:00
return MobileUtils . GetSettingValue ( man . Settings , key ) ;
2018-02-07 14:14:08 +01:00
}
2018-01-29 12:57:10 +01:00
[Authorize]
2016-06-27 01:45:38 +02:00
public string LoadStatistics ( long oid )
{
try
{
2018-12-10 23:40:38 -04:00
if ( Model = = null )
2016-06-27 01:45:38 +02:00
{
2018-12-10 23:40:38 -04:00
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
2019-09-17 17:44:57 +02:00
var supportConceptStatistics = OperationsService . CreateSupportConceptStatistics ( oid , DateTime . Now ) ;
2016-06-27 01:45:38 +02:00
2019-09-17 17:44:57 +02:00
if ( supportConceptStatistics . PeriodStatistics ! = null & &
2019-11-15 00:39:46 +01:00
supportConceptStatistics . PeriodStatistics . Count = = 1 )
2019-09-17 17:44:57 +02:00
{
}
2018-02-23 14:42:53 +01:00
return SerializeObject ( supportConceptStatistics ) ;
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]
2018-12-13 20:59:05 -04:00
public string SaveUnterschrift ( string blob , string zeitstempel , long? ServiceRecord )
2016-06-27 01:45:38 +02:00
{
try
{
if ( Model = = null )
{
2018-12-10 23:40:38 -04:00
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
2019-11-21 19:39:32 +01:00
// TODO: Prüfen, ob nicht transparente Pixel vorhanden sind. Wenn nein, dann Meldung zurückgeben und anzeigen!
var isValid = ValidateSignature ( blob . Split ( ',' ) [ 1 ] ) ;
if ( ! isValid )
{
return SerializeObject ( "Das Unterschriftenfeld darf nicht leer sein." ) ;
}
2016-06-27 01:45:38 +02:00
var date = DateTime . Parse ( zeitstempel ) ;
OperationsService . InsertSignature ( new SignatureDC
{
DataBild = blob ,
Zeitstempel = date ,
ServiceRecordOid = ServiceRecord
} ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
catch ( Exception e )
{
2020-01-15 16:14:39 +01:00
Log . Error ( e . Message , e ) ;
2018-12-13 20:59:05 -04:00
return SerializeObject ( "Fehler 540" ) ;
2016-06-27 01:45:38 +02:00
}
}
2019-11-21 19:39:32 +01:00
private static bool ValidateSignature ( string base64String )
{
var bitmap = Base64StringToBitmap ( base64String ) ;
if ( bitmap = = null )
{
return false ;
}
var nonTransparentPixelCount = 0 ;
for ( var i = 0 ; i < bitmap . Width ; i + + )
{
for ( var j = 0 ; j < bitmap . Height ; j + + )
{
var pixel = bitmap . GetPixel ( i , j ) ;
if ( pixel . A ! = 0 | | pixel . R ! = 0 | | pixel . G ! = 0 | | pixel . B ! = 0 )
{
nonTransparentPixelCount + + ;
}
if ( nonTransparentPixelCount = = 20 )
{
return true ;
}
}
}
return false ;
}
private static Bitmap Base64StringToBitmap ( string base64String )
{
Bitmap bitmap = null ;
try
{
var byteBuffer = Convert . FromBase64String ( base64String ) ;
using ( var memoryStream = new MemoryStream ( byteBuffer ) )
{
memoryStream . Position = 0 ;
bitmap = ( Bitmap ) Image . FromStream ( memoryStream ) ;
byteBuffer = null ;
}
return bitmap ;
}
catch ( Exception exception )
{
2020-01-15 16:14:39 +01:00
Log . Error ( exception . Message , exception ) ;
2019-11-21 19:39:32 +01:00
}
return bitmap ;
}
2018-12-13 20:59:05 -04:00
[Authorize]
2018-11-30 16:47:57 -04:00
public string SetSaveSignature ( bool save )
2016-06-27 01:45:38 +02:00
{
try
{
if ( Model = = null )
{
2018-12-10 23:40:38 -04:00
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
2018-11-30 16:47:57 -04:00
Model . SaveSignature = save ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
catch ( Exception e )
{
2020-01-15 16:14:39 +01:00
Log . Error ( e . Message , e ) ;
2018-11-30 16:47:57 -04:00
return SerializeObject ( "Fehler 777: Fail Error Compilation" ) ;
2016-06-27 01:45:38 +02:00
}
}
2018-12-13 20:59:05 -04:00
[Authorize]
2016-06-27 01:45:38 +02:00
public string LoadServiceCategories ( long pServiceCategoryOid )
{
2018-12-10 23:40:38 -04:00
if ( Model = = null )
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2018-12-10 23:40:38 -04:00
}
try
2018-04-27 14:11:21 +02:00
{
var scm = Model ? . ServiceCategories . FirstOrDefault ( s = > s . ServiceCategoryOid . Value = = pServiceCategoryOid ) ;
2020-02-07 15:21:36 +01:00
if ( scm ! = null )
{
Model . SelectedServiceCategoryOid = scm . ServiceCategoryOid ;
}
2018-04-27 14:11:21 +02:00
return SerializeObject ( scm ! = null ? scm . ServiceDescriptions : new List < ServiceDescriptionDC > ( ) ) ;
}
catch ( Exception exception )
{
Debug . WriteLine ( exception ) ;
throw ;
}
2016-06-27 01:45:38 +02:00
}
2017-04-26 14:57:32 +02:00
2018-01-29 12:57:10 +01:00
[Authorize]
2017-04-26 14:57:32 +02:00
public string LoadTextbausteineForServiceCategory ( long pServiceCategoryOid )
{
2018-12-10 23:40:38 -04:00
if ( Model = = null )
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2018-12-10 23:40:38 -04:00
}
2018-04-27 14:11:21 +02:00
try
2017-04-26 14:57:32 +02:00
{
2018-04-27 14:11:21 +02:00
if ( ! MobileSessionFacade . CheckForUserRight ( UserRightType . TextbausteineNurEigeneAnsehen ) & & ! MobileSessionFacade . CheckForUserRight ( UserRightType . TextbausteineAlleAnsehen ) )
{
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2018-04-27 14:11:21 +02:00
}
2017-04-26 14:57:32 +02:00
2018-04-27 14:11:21 +02:00
var textbausteine = OperationsService . GetAllTextModules ( ) ;
2018-05-28 15:02:55 +02:00
foreach ( var tm in textbausteine )
{
if ( tm . Text = = null )
{
tm . Text = "" ;
}
}
if ( ! MobileSessionFacade . CheckForUserRight ( UserRightType . TextbausteineAlleAnsehen ) )
2018-04-27 14:11:21 +02:00
{
textbausteine = textbausteine . Where ( w = > w . Employee . EmployeeOid = = Model . Employee . EmployeeOid ) . ToList ( ) ;
}
2017-04-26 14:57:32 +02:00
2018-05-28 15:02:55 +02:00
Model . Textbausteine = textbausteine . Where ( w = > w . ServiceCategory = = null | | w . ServiceCategory . ServiceCategoryOid = = pServiceCategoryOid ) . ToList ( ) ;
2017-04-26 14:57:32 +02:00
2018-04-27 14:11:21 +02:00
Model . Textbausteine . AddRangeIfElementsNotIn ( Utils . GetParentTextModules ( Model . Textbausteine ) ) ;
2018-01-31 17:52:28 +01:00
2020-02-07 15:21:36 +01:00
var displayItems = Model . Textbausteine . Select ( s = > new TextbausteinDisplayItem ( s . Name , new List < string > { s . TextModuleOid . Value . ToString ( ) } , s . Parent ? . TextModuleOid , s . TextModuleOid . Value ) ) . ToList ( ) ;
2018-01-29 12:57:10 +01:00
2018-04-27 14:11:21 +02:00
foreach ( var item in displayItems )
2018-01-29 12:57:10 +01:00
{
2018-04-27 14:11:21 +02:00
if ( item . ParentOid ! = null )
{
var parent = displayItems . FirstOrDefault ( f = > f . Oid = = item . ParentOid ) ;
2020-02-07 15:21:36 +01:00
parent ? . nodes . AddIfNotIn ( item ) ;
2018-04-27 14:11:21 +02:00
}
2018-01-29 12:57:10 +01:00
}
2018-04-27 14:11:21 +02:00
displayItems = displayItems . Where ( w = > w . ParentOid = = null ) . ToList ( ) ;
2018-01-29 12:57:10 +01:00
2018-04-27 14:11:21 +02:00
return SerializeObject ( displayItems ) ;
}
catch ( Exception exception )
{
Debug . WriteLine ( exception ) ;
throw ;
}
2017-04-26 14:57:32 +02:00
}
2018-12-13 20:59:05 -04:00
[Authorize]
2017-04-26 14:57:32 +02:00
public string LoadCompleteTextbausteinByOid ( long pTextbausteinOid )
{
2018-12-10 23:40:38 -04:00
if ( Model = = null )
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2018-12-10 23:40:38 -04:00
}
2018-11-24 14:28:46 -04:00
var abc = Model . Textbausteine . FirstOrDefault ( f = > f . TextModuleOid . HasValue & & f . TextModuleOid . Value = = pTextbausteinOid ) ;
2017-04-26 14:57:32 +02:00
2018-11-24 14:28:46 -04:00
return abc ? . Text ;
2017-04-26 14:57:32 +02:00
}
2016-06-27 01:45:38 +02:00
2018-12-13 20:59:05 -04:00
public string ErrorZeiterfassungAnzeigen ( int errorwert )
2016-06-27 01:45:38 +02:00
{
try
{
2018-12-10 23:40:38 -04:00
if ( Model = = null )
2016-06-27 01:45:38 +02:00
{
2018-12-10 23:40:38 -04:00
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
2018-12-10 23:40:38 -04:00
Model . ErrorWert = errorwert ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
}
2016-06-27 01:45:38 +02:00
catch ( Exception e )
{
2020-01-15 16:14:39 +01:00
Log . Error ( e . Message , e ) ;
2018-12-13 20:59:05 -04:00
return SerializeObject ( "Fehler 777: Fail Error Compilation" ) ;
2016-06-27 01:45:38 +02:00
}
}
[HttpPost]
[Authorize]
public ActionResult CreateServiceRecord ( FormCollection collection )
{
try
{
2018-04-18 14:33:21 +02:00
if ( Model = = null )
2016-06-27 01:45:38 +02:00
{
return RedirectToActionPermanent ( "Index" , "Login" ) ;
}
2018-01-29 12:57:10 +01:00
string doku1 ;
2017-02-01 13:53:59 +01:00
2020-02-07 15:21:36 +01:00
if ( Model . Dokutypes ! = null & & Model . Dokutypes . Length > 0 )
2017-02-01 13:53:59 +01:00
{
doku1 = collection [ "Dokumentation" ] ;
}
else
{
doku1 = collection [ "Dokumentation6" ] ;
}
2018-02-02 14:43:40 +01:00
2020-01-15 16:14:39 +01:00
Log . Info ( $"CreateServiceRecord: datum:{collection[" Datum "]}; start:{collection[" Start "]}; ende:{collection[" Ende "]}; dauer:{collection[" Dauer "]}; doku:{doku1}; aktion:{collection[" versteckt "]}" ) ;
2018-02-02 14:43:40 +01:00
2018-04-18 14:33:21 +02:00
if ( string . IsNullOrEmpty ( collection [ "Datum" ] ) )
2016-06-27 01:45:38 +02:00
{
return View ( "Main" , Model ) ;
}
2018-02-02 14:43:40 +01:00
var distanz = collection [ "Distanz" ] ;
2018-04-18 14:33:21 +02:00
var distanceInMeters = 0 ;
2018-02-02 14:43:40 +01:00
if ( ! string . IsNullOrEmpty ( distanz ) )
{
if ( int . TryParse ( distanz , out var parsedDistance ) )
{
distanceInMeters = parsedDistance ;
}
}
2016-06-27 01:45:38 +02:00
var submitBtnVal = collection [ "versteckt" ] ;
var selectedCostbearerSCRelOid = Model . CostBearer2SupportConceptOid < 1 ? null : Model . CostBearer2SupportConceptOid ;
2018-02-07 14:45:35 +01:00
var datum = Convert . ToDateTime ( collection [ "Datum" ] ) ;
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
var enddatum = datum ;
2016-06-27 01:45:38 +02:00
var start = collection [ "Start" ] ;
var ende = collection [ "Ende" ] ;
var dauer = 0 ;
2018-04-18 14:33:21 +02:00
if ( datum > enddatum ) {
2016-06-27 01:45:38 +02:00
enddatum = datum ;
}
2018-06-13 14:38:35 +02:00
if ( ! string . IsNullOrEmpty ( collection [ "Dauer" ] ) )
2016-06-27 01:45:38 +02:00
{
2018-06-13 14:38:35 +02:00
int . TryParse ( collection [ "Dauer" ] , out dauer ) ;
2016-06-27 01:45:38 +02:00
}
2017-02-01 13:53:59 +01:00
2016-06-27 01:45:38 +02:00
var doku2 = collection [ "Dokumentation2" ] ;
var doku3 = collection [ "Dokumentation3" ] ;
var doku4 = collection [ "Dokumentation4" ] ;
var doku5 = collection [ "Dokumentation5" ] ;
var zeitenFeld = new DateTime [ 2 ] ;
2018-04-18 14:33:21 +02:00
if ( start = = string . Empty & & ende = = string . Empty )
2016-06-27 01:45:38 +02:00
{
zeitenFeld [ 0 ] = new DateTime ( datum . Year , datum . Month , datum . Day , 0 , 0 , 1 ) ;
if ( enddatum = = datum )
2018-01-29 12:57:10 +01:00
{
2016-06-27 01:45:38 +02:00
zeitenFeld [ 1 ] = new DateTime ( datum . Year , datum . Month , datum . Day , 0 , 0 , 1 ) . AddMinutes ( dauer ) ;
2018-01-29 12:57:10 +01:00
}
2016-06-27 01:45:38 +02:00
else
2018-01-29 12:57:10 +01:00
{
2016-06-27 01:45:38 +02:00
zeitenFeld [ 1 ] = new DateTime ( enddatum . Year , enddatum . Month , enddatum . Day , 0 , 0 , 1 ) . AddMinutes ( dauer ) ;
2018-01-29 12:57:10 +01:00
}
2016-06-27 01:45:38 +02:00
}
else
{
2018-01-29 12:57:10 +01:00
zeitenFeld = enddatum = = datum ? ConvertRecordTimes ( start , ende , datum , dauer ) : ConvertRecordTimesWithEndDate ( start , ende , datum , enddatum , dauer ) ;
2016-06-27 01:45:38 +02:00
}
2018-04-18 14:33:21 +02:00
if ( dauer = = 0 | | zeitenFeld [ 1 ] ! = zeitenFeld [ 0 ] )
2016-06-27 01:45:38 +02:00
{
2018-01-29 12:57:10 +01:00
dauer = ( int ) ( zeitenFeld [ 1 ] - zeitenFeld [ 0 ] ) . TotalMinutes ;
2016-06-27 01:45:38 +02:00
}
2018-01-29 12:57:10 +01:00
2018-04-18 14:33:21 +02:00
if ( submitBtnVal . Equals ( "Speichern" ) )
2016-06-27 01:45:38 +02:00
{
2018-04-27 14:11:21 +02:00
var selectedRecordOid = Model . SelectedServiceRecordOid ? ? Model . SelectedServiceRecord . ServiceRecordOid ;
2016-06-27 01:45:38 +02:00
Model . NewServiceRecord = OperationsService . GetServiceRecordById ( selectedRecordOid . Value ) ;
}
2018-04-18 14:33:21 +02:00
if ( Model . NewServiceRecord = = null )
2016-06-27 01:45:38 +02:00
{
return RedirectToActionPermanent ( "Main" ) ;
}
2018-04-18 14:33:21 +02:00
Model . NewServiceRecord . IP = Request . UserHostAddress ;
2016-06-27 01:45:38 +02:00
Model . NewServiceRecord . Goals = Model . SelectedGoals ;
Model . NewServiceRecord . Start = zeitenFeld [ 0 ] ;
Model . NewServiceRecord . End = zeitenFeld [ 1 ] ;
2018-02-02 14:43:40 +01:00
Model . NewServiceRecord . DistanceInMeter = distanceInMeters ;
2018-04-18 14:33:21 +02:00
if ( Model . Employee . EmployeeOid ! = null )
2016-06-27 01:45:38 +02:00
{
2018-04-18 14:33:21 +02:00
if ( ! submitBtnVal . Equals ( "Speichern" ) )
2016-06-27 01:45:38 +02:00
{
Model . NewServiceRecord . Employee = Model . SelectedEmployee ? ? MobileSessionFacade . LoggedInCompactEmployee ;
}
2018-10-08 11:57:16 +02:00
else
{
if ( Model . SelectedEmployee ! = null )
{
Model . NewServiceRecord . Employee = Model . SelectedEmployee ;
}
}
2018-01-29 12:57:10 +01:00
var sc = Model . SupportConcepts . FirstOrDefault ( fod = > fod . CostBearerRelations . Any ( a = > a . CostBearer2SupportConceptOid . HasValue & & a . CostBearer2SupportConceptOid . Value . Equals ( selectedCostbearerSCRelOid ) ) ) ;
2018-04-18 14:33:21 +02:00
if ( sc ! = null )
2016-06-27 01:45:38 +02:00
{
2018-04-18 14:33:21 +02:00
if ( sc . SupportConceptOid ! = null )
2016-06-27 01:45:38 +02:00
{
2018-04-18 14:33:21 +02:00
Model . NewServiceRecord . SupportConcept = CustomerService . LoadCompactSupportConceptDC ( sc . SupportConceptOid . Value , Model . Employee . EmployeeOid ) ;
2016-06-27 01:45:38 +02:00
}
Model . NewServiceRecord . Customer = sc . Customer ;
2018-01-29 12:57:10 +01:00
2018-02-07 14:14:08 +01:00
var cb2ScRel = sc . CostBearerRelations . First ( f = > f . CostBearer2SupportConceptOid . HasValue & & f . CostBearer2SupportConceptOid . Equals ( selectedCostbearerSCRelOid ) ) ;
2016-06-27 01:45:38 +02:00
Model . NewServiceRecord . CostBearer = cb2ScRel . CostBearer ;
2018-01-29 12:57:10 +01:00
2016-06-27 01:45:38 +02:00
var intervall = Model . NewServiceRecord . CostBearer . ActualMinuteIntervall ;
2018-04-18 14:33:21 +02:00
if ( intervall > 0 )
2016-06-27 01:45:38 +02:00
{
2018-02-07 14:14:08 +01:00
Model . NewServiceRecord . RoundedDuration = dauer % intervall ! = 0 ? dauer + ( intervall - dauer % intervall ) : dauer ;
2016-06-27 01:45:38 +02:00
}
else
{
Model . NewServiceRecord . RoundedDuration = dauer ;
}
Model . NewServiceRecord . CostBearer2SupportConceptOid = selectedCostbearerSCRelOid ;
}
else
{
Model . NewServiceRecord . RoundedDuration = dauer ;
}
}
2018-04-18 14:33:21 +02:00
Model . NewServiceRecord . DurationInStunden = ZeiterfassungsDauer . Minuten ;
Model . NewServiceRecord . ServiceRecordFormat = ServiceRecordFormate . OriginaleZeiterfassung ;
2018-12-10 23:40:38 -04:00
Model . NewServiceRecord . Notice = string . IsNullOrEmpty ( doku1 ) ? null : doku1 ;
2017-02-01 13:53:59 +01:00
2018-12-10 23:40:38 -04:00
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 ;
2016-06-27 01:45:38 +02:00
var serviceDescOid = 0L ;
if ( Model . SelectedServiceDescriptionOid . HasValue )
{
serviceDescOid = Model . SelectedServiceDescriptionOid . Value ;
}
2018-02-07 14:45:35 +01:00
else if ( ! string . IsNullOrEmpty ( collection [ "ServiceDescription" ] ) )
2016-06-27 01:45:38 +02:00
{
2018-02-07 14:45:35 +01:00
serviceDescOid = Convert . ToInt64 ( collection [ "ServiceDescription" ] ) ;
2016-06-27 01:45:38 +02:00
}
if ( serviceDescOid > 0 )
{
Model . NewServiceRecord . ServiceDescription = OperationsService . GetServiceDescription ( serviceDescOid ) ;
}
if ( Model . NewServiceRecord . RoundedDuration = = 0 )
2018-01-29 12:57:10 +01:00
{
2016-06-27 01:45:38 +02:00
Model . NewServiceRecord . RoundedDuration = dauer ;
2018-01-29 12:57:10 +01:00
}
2016-06-27 01:45:38 +02:00
Model . NewServiceRecord . IP = Request . UserHostAddress ;
Model . NewServiceRecord . InsertedOn = DateTime . Now ;
2018-02-02 14:43:40 +01:00
Model . NewServiceRecord . InsUser = $"{MobileSessionFacade.LoggedInEmployee.FirstName} {MobileSessionFacade.LoggedInEmployee.LastName}" ;
2016-06-27 01:45:38 +02:00
Model . NewServiceRecord . IsCreatedInMobileClient = true ;
2018-04-18 14:33:21 +02:00
if ( Model . IsInGroupBookingMode & & Model . SelectedSupportConcepts . Count > 1 )
{
2018-04-27 14:11:21 +02:00
return submitBtnVal . Equals ( "Anlegen" ) ? SaveGroupBooking ( ) : UpdateGroupBooking ( ) ;
2018-04-18 14:33:21 +02:00
}
if ( submitBtnVal . Equals ( "Anlegen" ) )
2016-06-27 01:45:38 +02:00
{
2018-01-29 12:57:10 +01:00
var oidList = OperationsService . InsertNewServiceRecords ( new List < ServiceRecordDC > { Model . NewServiceRecord } ) ;
2016-06-27 01:45:38 +02:00
2018-02-02 14:43:40 +01:00
Model . ServiceRecordOid = oidList [ 0 ] ;
2016-06-27 01:45:38 +02:00
}
else
{
OperationsService . UpdateServiceRecords ( new List < ServiceRecordDC > { Model . NewServiceRecord } ) ;
}
Model . NewServiceRecord = new ServiceRecordDC ( ) ;
2018-04-18 14:33:21 +02:00
if ( selectedCostbearerSCRelOid . HasValue )
2016-06-27 01:45:38 +02:00
{
Model . ServiceRecords = OperationsService . FindServiceRecordsForLastDays ( selectedCostbearerSCRelOid , Model . Zeitraum , Model . Employee . EmployeeOid ) . ToList ( ) ;
}
}
catch ( Exception e )
{
2020-01-15 16:14:39 +01:00
Log . Error ( e . Message , e ) ;
2016-06-27 01:45:38 +02:00
}
2019-07-12 17:13:38 +02:00
Model . SaveSignature = Model . ShowSignature & & Model . SelectedSupportConcept ! = null ;
2016-06-27 01:45:38 +02:00
return RedirectToActionPermanent ( "Main" ) ;
}
2018-04-27 14:11:21 +02:00
private ActionResult SaveGroupBooking ( )
2018-04-18 14:33:21 +02:00
{
var employeeCount = Model . SelectedEmployees . Count ;
var personCount = Model . SelectedSupportConcepts . Count ;
2018-11-26 13:27:16 -04:00
var cb2SCOids = ( from scDc in Model . SelectedSupportConcepts where scDc . CostBearerRelations ! = null & & scDc . CostBearerRelations . Count > 0 let costBearer2SupportConceptOid = scDc . CostBearerRelations [ 0 ] . CostBearer2SupportConceptOid where costBearer2SupportConceptOid ! = null select costBearer2SupportConceptOid . Value ) . ToList ( ) ;
2018-04-18 14:33:21 +02:00
2018-11-26 13:27:16 -04: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 )
{
foreach ( var emp in Model . SelectedEmployees )
{
var newDC = CloneServiceRecordForGroupBooking ( dc ) ;
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 ,
Notice = Model . NewServiceRecord . Notice ,
Notice2 = Model . NewServiceRecord . Notice2 ,
Notice3 = Model . NewServiceRecord . Notice3 ,
Notice4 = Model . NewServiceRecord . Notice4 ,
Notice5 = Model . NewServiceRecord . Notice5 ,
ServiceRecordList = newDCList
} ;
if ( Model . NewServiceRecord . GroupRoundedDuration ! = null )
{
groupDC . RoundedDuration = Model . NewServiceRecord . GroupRoundedDuration . Value ;
}
OperationsService . InsertNewServiceRecordGroup ( groupDC ) ;
}
}
2019-03-29 14:04:12 +01:00
Model . SelectedSupportConcepts . Clear ( ) ;
Model . SelectedConceptCostBearerRelations . Clear ( ) ;
Model . SelectedCostbearerRelOids . Clear ( ) ;
Model . SelectedGroupOfPeopleOids . Clear ( ) ;
Model . SelectedEmployees = new List < CompactEmployeeDC > { MobileSessionFacade . LoggedInCompactEmployee } ;
2018-04-27 14:11:21 +02:00
return RedirectToActionPermanent ( "Main" ) ;
}
private ActionResult UpdateGroupBooking ( )
{
var dc = Model . SelectedServiceRecord ;
var group = OperationsService . GetServiceRecordGroup ( dc . GroupOid . Value ) ;
UpdateServiceRecordGroup ( group ) ;
var employeeCount = Model . SelectedEmployees . Count ;
var customerCount = Model . SelectedSupportConcepts . Count ;
group . EmployeeCount = employeeCount ;
group . CustomerCount = customerCount ;
var roundDuration = true ;
var minuteInterval = 0 ;
CompactOrganisationDC org = null ;
var cb2scOids = new List < long > ( ) ;
foreach ( var scdc in Model . SelectedSupportConcepts )
{
if ( scdc . CostBearerRelations . Count > 0 )
{
cb2scOids . Add ( scdc . CostBearerRelations . ElementAt ( 0 ) . CostBearer2SupportConceptOid . Value ) ;
if ( org = = null )
{
org = scdc . CostBearerRelations . ElementAt ( 0 ) . CostBearer ;
if ( org ! = null )
{
minuteInterval = org . ActualMinuteIntervall ;
}
}
else
{
if ( scdc . CostBearerRelations . ElementAt ( 0 ) . CostBearer = = null | | ! org . Equals ( scdc . CostBearerRelations . ElementAt ( 0 ) . CostBearer ) )
{
roundDuration = false ;
}
}
}
}
var duration = ( decimal ) ( Model . NewServiceRecord . End . Value - Model . NewServiceRecord . Start . Value ) . TotalMinutes ;
var lRoundedDuration = duration ;
decimal groupDuration ;
decimal roundedDuration ;
var gd = OperationsService . CalculateGroupDuration2 ( customerCount , employeeCount , duration , cb2scOids . ToArray ( ) ) ;
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 ;
roundedDuration = Math . Round ( groupDuration / Model . SelectedSupportConcepts . Count , 0 , MidpointRounding . AwayFromZero ) ;
}
Model . NewServiceRecord . RoundedDuration = roundedDuration ;
Model . NewServiceRecord . GroupRoundedDuration = groupDuration ;
group . Notice = Model . NewServiceRecord . Notice ;
group . Notice2 = Model . NewServiceRecord . Notice2 ;
group . Notice3 = Model . NewServiceRecord . Notice3 ;
group . Notice4 = Model . NewServiceRecord . Notice4 ;
group . Notice5 = Model . NewServiceRecord . Notice5 ;
group . RoundedDuration = groupDuration ;
group . StartDate = Model . NewServiceRecord . Start ;
group . EndDate = Model . NewServiceRecord . End ;
foreach ( var item in group . ServiceRecordList )
{
item . Notice = Model . NewServiceRecord . Notice ;
item . Notice2 = Model . NewServiceRecord . Notice2 ;
item . Notice3 = Model . NewServiceRecord . Notice3 ;
item . Notice4 = Model . NewServiceRecord . Notice4 ;
item . Notice5 = Model . NewServiceRecord . Notice5 ;
item . End = Model . NewServiceRecord . End ;
item . Start = Model . NewServiceRecord . Start ;
item . RoundedDuration = roundedDuration ;
item . DistanceInMeter = Model . NewServiceRecord . DistanceInMeter ;
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 ;
if ( item . CostBearer ! = null & & item . CostBearer . CostBearerOid = = null & & item . SupportConcept ! = null & & item . SupportConcept . CostBearerList . Count > 0 )
{
item . CostBearer . CostBearerOid = item . SupportConcept . CostBearerList [ 0 ] . CostBearerOid ;
}
}
if ( Model . NewServiceRecord . GroupOid . HasValue )
{
OperationsService . UpdateServiceRecordGroup ( group ) ;
}
Model . NewServiceRecord = null ;
Model . SelectedServiceRecord = null ;
Model . SelectedSupportConcepts = new List < SupportConceptDC > ( ) ;
Model . SelectedEmployees = new List < CompactEmployeeDC > ( ) ;
2018-11-30 16:47:57 -04:00
ResetGroupBookingMode ( false ) ;
Model . IsInEditingMode = false ;
2018-04-27 14:11:21 +02:00
return RedirectToActionPermanent ( "Main" ) ;
}
private IEnumerable < ServiceRecordDC > CalculateGroupBookingDuration ( int pEmployeeCount , int pCustomerCount , ICollection < long > cb2ScOids )
{
2018-04-18 14:33:21 +02:00
var compactSupportConcepts = CustomerServiceImp . GetCompactSupportConcepts ( ( from sc in Model . SelectedSupportConcepts where sc . SupportConceptOid ! = null select sc . SupportConceptOid . Value ) . ToList ( ) , GetUser ( ) . Employee . EmployeeOid ) ;
2018-04-27 14:11:21 +02:00
var nodes = ( from supportConcept in Model . SelectedSupportConcepts 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 )
{
var sc = CloneServiceRecordForGroupBooking ( Model . NewServiceRecord ) ;
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 ;
foreach ( var org in from dc in Model . SelectedSupportConcepts where dc . CostBearerRelations . Count > 0 select dc . CostBearerRelations . First ( ) . CostBearer )
{
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 > ( ) ;
var oldSCs = new Dictionary < long , CompactSupportConceptDC > ( ) ;
var oldEmps = new Dictionary < long , CompactEmployeeDC > ( ) ;
var newKeys = new Dictionary < string , string > ( ) ;
foreach ( var sc in Model . SelectedSupportConcepts )
{
foreach ( var emp in Model . SelectedEmployees )
2018-04-18 14:33:21 +02:00
{
2018-04-27 14:11:21 +02:00
var key = emp . EmployeeOid + "_" + sc . SupportConceptOid ;
if ( sc . CostBearerRelations ! = null & & sc . CostBearerRelations . Count > 0 )
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 )
{
key + = "_" + costBearer2SupportConceptOid . Value ;
}
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 )
{
foreach ( var sc in Model . SelectedSupportConcepts )
2018-04-18 14:33:21 +02:00
{
2018-04-27 14:11:21 +02:00
foreach ( var emp in Model . SelectedEmployees )
{
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
{
newServiceRecord = CloneServiceRecordForGroupBooking ( Model . NewServiceRecord ) ;
2018-11-26 13:27:16 -04:00
pGroupDC . ServiceRecordList . Add ( newServiceRecord ) ;
2018-04-27 14:11:21 +02:00
}
newServiceRecord . Employee = emp ;
newServiceRecord . SupportConcept = CustomerService . LoadCompactSupportConceptDC ( sc . SupportConceptOid . Value , null ) ;
newServiceRecord . CostBearer = sc . CostBearerRelations . ElementAt ( 0 ) . CostBearer ;
newServiceRecord . Customer = sc . Customer ;
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
}
}
2018-02-07 14:14:08 +01:00
[Authorize]
public ActionResult SaveZeiterfassungAfterCrash ( string pDatum , string pStartDate , string pEndDate , string pDuration , string pNotice , string pServiceDescription , string pNotice2 , string pNotice3 , string pNotice4 , string pNotice5 , string pEndDate2 )
2016-06-27 01:45:38 +02:00
{
try
{
if ( Model = = null )
{
return RedirectToActionPermanent ( "Index" , "Login" ) ;
}
2020-01-15 16:14:39 +01:00
Log . Info ( $"saveZeiterfassungAfterCrash: datum:{pDatum};start:{pStartDate};ende:{pEndDate};dauer:{pDuration};doku:{pNotice};doku2:{pNotice2};doku3:{pNotice3};doku4:{pNotice4};doku5:{pNotice5};pEndDate2:{pEndDate2}" ) ;
2016-06-27 01:45:38 +02:00
2018-02-07 14:14:08 +01:00
if ( string . IsNullOrEmpty ( pDatum ) )
2016-06-27 01:45:38 +02:00
{
return View ( "Main" , Model ) ;
}
var selectedCostbearerSCRelOid = Model . CostBearer2SupportConceptOid < 1 ? null : Model . CostBearer2SupportConceptOid ;
2018-02-07 14:14:08 +01:00
var datum = Convert . ToDateTime ( pDatum ) ;
var start = pStartDate ;
var ende = pEndDate ;
2016-06-27 01:45:38 +02:00
var dauer = 0 ;
2018-02-07 14:14:08 +01:00
var enddatum = pEndDate2 ! = "" ? Convert . ToDateTime ( pEndDate2 ) : datum ;
2016-06-27 01:45:38 +02:00
if ( datum > enddatum )
{
enddatum = datum ;
}
2018-02-07 14:14:08 +01:00
if ( ! string . IsNullOrEmpty ( pDuration ) )
2016-06-27 01:45:38 +02:00
{
2018-02-07 14:14:08 +01:00
int . TryParse ( pDuration , out dauer ) ;
2016-06-27 01:45:38 +02:00
}
2018-02-07 14:14:08 +01:00
var doku = pNotice ;
var doku2 = pNotice2 ;
var doku3 = pNotice3 ;
var doku4 = pNotice4 ;
var doku5 = pNotice5 ;
2016-06-27 01:45:38 +02:00
var zeitenFeld = new DateTime [ 2 ] ;
2018-01-29 12:57:10 +01:00
if ( start = = string . Empty & & ende = = string . Empty )
2016-06-27 01:45:38 +02:00
{
zeitenFeld [ 0 ] = new DateTime ( datum . Year , datum . Month , datum . Day , 0 , 0 , 1 ) ;
if ( enddatum = = datum )
2018-01-29 12:57:10 +01:00
{
2016-06-27 01:45:38 +02:00
zeitenFeld [ 1 ] = new DateTime ( datum . Year , datum . Month , datum . Day , 0 , 0 , 1 ) . AddMinutes ( dauer ) ;
2018-01-29 12:57:10 +01:00
}
2016-06-27 01:45:38 +02:00
else
2018-01-29 12:57:10 +01:00
{
zeitenFeld [ 1 ] = new DateTime ( enddatum . Year , enddatum . Month , enddatum . Day , 0 , 0 , 1 ) . AddMinutes ( dauer ) ;
}
2016-06-27 01:45:38 +02:00
}
else
{
2018-01-29 12:57:10 +01:00
zeitenFeld = enddatum = = datum ? ConvertRecordTimes ( start , ende , datum , dauer ) : ConvertRecordTimesWithEndDate ( start , ende , datum , enddatum , dauer ) ;
2016-06-27 01:45:38 +02:00
}
if ( dauer = = 0 | | zeitenFeld [ 1 ] ! = zeitenFeld [ 0 ] )
{
dauer = ( int ) ( zeitenFeld [ 1 ] - zeitenFeld [ 0 ] ) . TotalMinutes ;
}
if ( Model . NewServiceRecord = = null )
{
return RedirectToActionPermanent ( "Main" ) ;
}
Model . NewServiceRecord . Goals = Model . SelectedGoals ;
Model . NewServiceRecord . Start = zeitenFeld [ 0 ] ;
Model . NewServiceRecord . End = zeitenFeld [ 1 ] ;
if ( Model . Employee . EmployeeOid ! = null )
{
2018-01-29 12:57:10 +01:00
Model . NewServiceRecord . Employee = Model . SelectedEmployee ? ? MobileSessionFacade . LoggedInCompactEmployee ;
2016-06-27 01:45:38 +02:00
2018-02-07 14:14:08 +01:00
var sc = Model . SupportConcepts . FirstOrDefault ( fod = > fod . CostBearerRelations . Any ( a = > a . CostBearer2SupportConceptOid . HasValue & & a . CostBearer2SupportConceptOid . Value . Equals ( selectedCostbearerSCRelOid ) ) ) ;
2016-06-27 01:45:38 +02:00
if ( sc ! = null )
{
if ( sc . SupportConceptOid ! = null )
{
Model . NewServiceRecord . SupportConcept = CustomerService . LoadCompactSupportConceptDC ( sc . SupportConceptOid . Value , Model . Employee . EmployeeOid ) ;
}
Model . NewServiceRecord . Customer = sc . Customer ;
var cb2ScRel = sc . CostBearerRelations . First ( f = > f . CostBearer2SupportConceptOid . HasValue & & f . CostBearer2SupportConceptOid . Equals ( selectedCostbearerSCRelOid ) ) ;
Model . NewServiceRecord . CostBearer = cb2ScRel . CostBearer ;
var intervall = Model . NewServiceRecord . CostBearer . ActualMinuteIntervall ;
if ( intervall > 0 )
{
2018-01-29 12:57:10 +01:00
Model . NewServiceRecord . RoundedDuration = dauer % intervall ! = 0 ? dauer + ( intervall - dauer % intervall ) : dauer ;
2016-06-27 01:45:38 +02:00
}
else
{
Model . NewServiceRecord . RoundedDuration = dauer ;
}
Model . NewServiceRecord . CostBearer2SupportConceptOid = selectedCostbearerSCRelOid ;
}
else
{
Model . NewServiceRecord . RoundedDuration = dauer ;
}
}
Model . NewServiceRecord . Notice = doku ;
if ( doku2 ! = "" )
2018-01-29 12:57:10 +01:00
{
2016-06-27 01:45:38 +02:00
Model . NewServiceRecord . Notice2 = doku2 ;
2018-01-29 12:57:10 +01:00
}
2016-06-27 01:45:38 +02:00
if ( doku3 ! = "" )
2018-01-29 12:57:10 +01:00
{
2016-06-27 01:45:38 +02:00
Model . NewServiceRecord . Notice3 = doku3 ;
2018-01-29 12:57:10 +01:00
}
2016-06-27 01:45:38 +02:00
if ( doku4 ! = "" )
2018-01-29 12:57:10 +01:00
{
2016-06-27 01:45:38 +02:00
Model . NewServiceRecord . Notice4 = doku4 ;
2018-01-29 12:57:10 +01:00
}
2016-06-27 01:45:38 +02:00
if ( doku5 ! = "" )
2018-01-29 12:57:10 +01:00
{
2016-06-27 01:45:38 +02:00
Model . NewServiceRecord . Notice5 = doku5 ;
2018-01-29 12:57:10 +01:00
}
2016-06-27 01:45:38 +02:00
var serviceDescOid = 0L ;
if ( Model . SelectedServiceDescriptionOid . HasValue )
{
serviceDescOid = Model . SelectedServiceDescriptionOid . Value ;
}
2018-02-07 14:14:08 +01:00
else if ( ! string . IsNullOrEmpty ( pServiceDescription ) )
2016-06-27 01:45:38 +02:00
{
2018-02-07 14:14:08 +01:00
serviceDescOid = Convert . ToInt64 ( pServiceDescription ) ;
2016-06-27 01:45:38 +02:00
}
if ( serviceDescOid > 0 )
{
Model . NewServiceRecord . ServiceDescription = OperationsService . GetServiceDescription ( serviceDescOid ) ;
}
Model . NewServiceRecord . IP = Request . UserHostAddress ;
Model . NewServiceRecord . InsertedOn = DateTime . Now ;
2018-01-29 12:57:10 +01:00
Model . NewServiceRecord . InsUser = $"{MobileSessionFacade.LoggedInEmployee.FirstName} {MobileSessionFacade.LoggedInEmployee.LastName}" ;
2016-06-27 01:45:38 +02:00
Model . NewServiceRecord . IsCreatedInMobileClient = true ;
OperationsService . InsertNewServiceRecords ( new List < ServiceRecordDC > { Model . NewServiceRecord } ) ;
Model . NewServiceRecord = new ServiceRecordDC ( ) ;
if ( selectedCostbearerSCRelOid . HasValue )
{
Model . ServiceRecords = OperationsService . FindServiceRecordsForLastDays ( selectedCostbearerSCRelOid , Model . Zeitraum , Model . Employee . EmployeeOid ) . ToList ( ) ;
}
}
catch ( Exception e )
{
2020-01-15 16:14:39 +01:00
Log . Error ( e . Message , e ) ;
2016-06-27 01:45:38 +02:00
Model . ErrorWert = 2 ;
//log.Error(e.Message, e);
}
return RedirectToActionPermanent ( "Main" ) ;
}
[HttpPost]
[Authorize]
public ActionResult SelectSupportConcept ( FormCollection formCollection )
{
2018-04-18 14:33:21 +02:00
if ( Model = = null )
2016-06-27 01:45:38 +02:00
{
return RedirectToActionPermanent ( "Index" , "Login" ) ;
}
long? cb2scOid = Convert . ToInt64 ( formCollection [ "CostBearer2SupportConceptOid" ] ) ;
Model . CostBearer2SupportConceptOid = cb2scOid ;
Model . SelectedSupportConcept =
Model . SupportConcepts . FirstOrDefault (
f = >
f . CostBearerRelations . Any (
a = >
a . CostBearer2SupportConceptOid . HasValue & &
a . CostBearer2SupportConceptOid . Value . Equals ( Model . CostBearer2SupportConceptOid ) ) ) ;
2018-04-18 14:33:21 +02:00
if ( Model . SelectedSupportConcept ! = null )
2019-07-19 17:13:57 +02:00
{
Model . SelectedSupportConceptListObject = Model . SupportConceptListObjects . First ( f = > long . Parse ( f . CostBearer2SupportConceptOid ) = = cb2scOid ) ;
2018-04-18 14:33:21 +02:00
var details = OperationsService . GetSupportConceptTreeNodeDetailInfo ( Model . SelectedSupportConcept . Customer . CustomerOid , Model . SelectedSupportConcept . SupportConceptOid , Model . CostBearer2SupportConceptOid ) ;
2016-06-27 01:45:38 +02:00
Model . ServiceCategories = details . ServiceAccountings . Count > 0
2018-02-07 14:45:35 +01:00
? CreateServiceCategoryModels ( details . ServiceAccountings . Select ( sa = > sa . ServiceDescription ) . ToList ( ) )
: CreateServiceCategoryModels ( OperationsService . GetAllServiceDescriptions ( ) ) ;
2016-06-27 01:45:38 +02:00
Model . ServiceCategories = Model . ServiceCategories . Where ( c = > ! c . OhneHilfeplan . HasValue | | c . OhneHilfeplan . Value = = AccountingvisibilityType . Beides | | c . OhneHilfeplan . Value = = AccountingvisibilityType . NurKlientenbezogen ) . ToList ( ) ;
}
2018-04-18 14:33:21 +02:00
else if ( cb2scOid = = - 2 )
2019-07-19 17:13:57 +02:00
{
Model . SelectedSupportConceptListObject = Model . SupportConceptListObjects . First ( f = > f . CostBearer2SupportConceptOid . Equals ( cb2scOid . ToString ( ) ) ) ;
2016-06-27 01:45:38 +02:00
Model . ServiceCategories = CreateServiceCategoryModels ( OperationsService . GetAllServiceDescriptions ( ) ) ;
Model . ServiceCategories = Model . ServiceCategories . Where ( c = > ! c . OhneHilfeplan . HasValue | | c . OhneHilfeplan . Value = = AccountingvisibilityType . Beides | | c . OhneHilfeplan . Value = = AccountingvisibilityType . NichtKlientenbezogen ) . ToList ( ) ;
}
2018-04-18 14:33:21 +02:00
else if ( cb2scOid = = - 1 )
2016-06-27 01:45:38 +02:00
{
2019-07-19 17:13:57 +02:00
Model . SelectedSupportConceptListObject = Model . SupportConceptListObjects . First ( f = > f . CostBearer2SupportConceptOid . Equals ( cb2scOid . ToString ( ) ) ) ;
Model . ServiceCategories . Clear ( ) ;
2016-06-27 01:45:38 +02:00
}
Model . Zeitraum = 7 ;
LoadRecordsToModel ( ) ;
return RedirectToActionPermanent ( "Main" ) ;
}
[HttpPost]
[Authorize]
2018-11-30 16:47:57 -04:00
public ActionResult DeleteServiceRecord ( FormCollection formCollection )
2016-06-27 01:45:38 +02:00
{
if ( Model = = null )
{
return RedirectToActionPermanent ( "Index" , "Login" ) ;
}
2018-11-30 16:47:57 -04:00
Model . ServiceRecordOidToDelete = long . Parse ( formCollection [ "serviceRecordOidHolder" ] ) ;
2016-06-27 01:45:38 +02:00
if ( Model . ServiceRecordOidToDelete ! = null & & Model . ServiceRecordOidToDelete > 0 & & MobileSessionFacade . LoggedInUser . UserGroups . Any ( a = > a . Rights . Any ( f = > f . RightType . Equals ( UserRightType . ServiceRecordView_Delete ) ) ) )
{
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 ;
if ( version ! = null )
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
}
}
2018-11-30 16:47:57 -04:00
ResetGroupBookingMode ( false ) ;
2018-05-22 17:19:56 +02:00
return RedirectToActionPermanent ( "Main" ) ;
2016-06-27 01:45:38 +02:00
}
2018-12-13 20:59:05 -04:00
public string SetRecordOidToDelete ( long serviceRecordOid )
2016-06-27 01:45:38 +02:00
{
if ( Model = = null )
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
Model . ServiceRecordOidToDelete = serviceRecordOid ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
2019-07-19 17:13:57 +02:00
public string UpdateGoals ( string pGoalOids )
2016-06-27 01:45:38 +02:00
{
if ( Model = = null )
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
var sc = Model . SelectedSupportConcept ;
2018-01-29 12:57:10 +01:00
if ( sc = = null )
{
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
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 ( ) ;
return _LeerzeichenFuerGetMethoden ;
}
2019-07-19 17:13:57 +02:00
var splitOids = pGoalOids . Split ( ';' ) ;
var selectedGoalOids = splitOids . Select ( long . Parse ) . ToList ( ) ;
2016-06-27 01:45:38 +02:00
2019-07-19 17:13:57 +02:00
var goals = sc . Goals . Where ( w = > w . ValueListEntryOid . HasValue & & selectedGoalOids . Contains ( w . ValueListEntryOid . Value ) ) . ToList ( ) ;
Model . SelectedGoals = goals ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
2018-11-30 16:47:57 -04:00
public string SetServiceDescription ( long pServiceDescriptionOid )
2016-06-27 01:45:38 +02:00
{
if ( Model = = null )
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
Model . SelectedServiceDescriptionOid = pServiceDescriptionOid ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
[HttpPost]
[Authorize]
public ActionResult LoadServiceRecords ( FormCollection formCollection )
{
if ( Model = = null )
{
return RedirectToActionPermanent ( "Index" , "Login" ) ;
}
var zeitraum = int . Parse ( formCollection [ "Records" ] ) ;
if ( zeitraum < 0 )
2018-01-29 12:57:10 +01:00
{
2016-06-27 01:45:38 +02:00
zeitraum = 7 ;
2018-01-29 12:57:10 +01:00
}
2016-06-27 01:45:38 +02:00
Model . Zeitraum = zeitraum ;
LoadRecordsToModel ( ) ;
return RedirectToActionPermanent ( "Main" ) ;
}
private void LoadRecordsToModel ( )
{
2018-12-10 23:40:38 -04:00
if ( Model = = null )
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
return ;
}
if ( Model . Zeitraum < 0 | | Model . CostBearer2SupportConceptOid . HasValue & & Model . CostBearer2SupportConceptOid . Value = = - 1 )
2016-06-27 01:45:38 +02:00
{
Model . ServiceRecords = new List < ServiceRecordDC > ( ) ;
return ;
}
var records = OperationsService . FindServiceRecordsForLastDays ( Model . CostBearer2SupportConceptOid < 1 ? null : Model . CostBearer2SupportConceptOid , Model . Zeitraum , Model . Employee . EmployeeOid ) ;
var recordsOhneDuplikate = new List < ServiceRecordDC > ( ) ;
2018-02-02 14:43:40 +01:00
foreach ( var r in records . Where ( r = > ! recordsOhneDuplikate . Any ( a = > a . GroupOid . HasValue & & a . GroupOid . Value . Equals ( r . GroupOid ) ) ) )
2016-06-27 01:45:38 +02:00
{
recordsOhneDuplikate . Add ( r ) ;
}
Model . ServiceRecords = recordsOhneDuplikate ;
}
2018-12-13 20:59:05 -04:00
public string SetSelectedServiceRecord ( long? recordOid )
2016-06-27 01:45:38 +02:00
{
if ( Model = = null )
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
Model . SelectedServiceRecordOid = recordOid ;
if ( recordOid = = null )
{
Model . SelectedGoals = new List < ValueListEntryDC > ( ) ;
}
else
{
var serviceRecordDC = Model . ServiceRecords . FirstOrDefault ( f = > f . ServiceRecordOid . HasValue & & f . ServiceRecordOid . Value . Equals ( Model . SelectedServiceRecordOid ) ) ;
if ( serviceRecordDC ! = null )
2018-01-29 12:57:10 +01:00
{
2018-12-13 20:59:05 -04:00
Model . SelectedServiceRecord = serviceRecordDC ;
2016-06-27 01:45:38 +02:00
Model . SelectedGoals = serviceRecordDC . Goals ;
2018-01-29 12:57:10 +01:00
}
2016-06-27 01:45:38 +02:00
}
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
2018-04-18 14:33:21 +02:00
[HttpPost]
[Authorize]
public ActionResult SetSelectedGroupServiceRecord ( FormCollection pFormCollection )
{
if ( Model = = null )
{
return RedirectToActionPermanent ( "Index" , "Login" ) ;
}
long . TryParse ( pFormCollection [ "hiddenElement" ] , out var recordOid ) ;
2018-04-27 14:11:21 +02:00
Model . SelectedServiceRecordOid = recordOid ;
2018-04-18 14:33:21 +02:00
Model . IsInGroupBookingMode = true ;
Model . IsInEditingMode = true ;
var serviceRecord = Model . ServiceRecords . FirstOrDefault ( f = > f . ServiceRecordOid = = recordOid ) ;
var supportConcepts = new List < SupportConceptDC > ( ) ;
var employees = new List < CompactEmployeeDC > ( ) ;
Model . SelectedServiceRecord = serviceRecord ;
2018-11-26 13:27:16 -04:00
Model . SelectedSupportConcepts . Clear ( ) ;
Model . SelectedEmployees . Clear ( ) ;
2018-11-30 16:47:57 -04:00
Model . SelectedCostbearerRelOids . Clear ( ) ;
2019-03-29 14:04:12 +01:00
Model . SelectedConceptCostBearerRelations . Clear ( ) ;
2018-11-30 16:47:57 -04:00
var relationOids = new List < long > ( ) ;
2018-04-18 14:33:21 +02:00
2018-11-26 13:27:16 -04:00
if ( serviceRecord ? . GroupOid ! = null )
2018-04-18 14:33:21 +02:00
{
var serviceRecordGroup = OperationsService . GetServiceRecordGroup ( serviceRecord . GroupOid . Value ) ;
if ( serviceRecordGroup ! = null )
{
employees . AddRangeIfElementsNotIn ( serviceRecordGroup . ServiceRecordList . Select ( s = > s . Employee ) ) ;
2018-11-30 16:47:57 -04:00
relationOids = serviceRecordGroup . ServiceRecordList . Select ( s = > s . CostBearer2SupportConceptOid . Value ) . ToList ( ) ;
2018-04-18 14:33:21 +02:00
var costBearerRelations = CustomerService . GetSupportConceptCostBearerRelationsById ( relationOids ) ;
2019-03-29 14:04:12 +01:00
Model . SelectedConceptCostBearerRelations . AddRangeIfElementsNotIn ( costBearerRelations ) ;
2018-04-18 14:33:21 +02:00
foreach ( var rel in costBearerRelations )
{
var sc = CustomerService . LoadSupportConcept ( rel . SupportConcept . SupportConceptOid ) ;
var oid = sc . SupportConceptOid ;
if ( ! supportConcepts . Any ( a = > a . SupportConceptOid . Equals ( oid ) ) )
{
supportConcepts . Add ( sc ) ;
}
}
}
}
2018-11-30 16:47:57 -04:00
Model . SelectedCostbearerRelOids . AddRangeIfElementsNotIn ( relationOids ) ;
2018-04-18 14:33:21 +02:00
Model . SelectedSupportConcepts = supportConcepts ;
Model . SelectedEmployees = employees ;
2018-11-26 13:27:16 -04:00
Model . ServiceCategories = CreateServiceCategoryModels ( OperationsService . GetAllServiceDescriptions ( ) ) ;
2018-04-18 14:33:21 +02:00
return RedirectToActionPermanent ( "Main" ) ;
}
2017-04-26 14:57:32 +02:00
public string GetSelectedRecordInformation ( )
2016-06-27 01:45:38 +02:00
{
2018-12-10 23:40:38 -04:00
if ( Model = = null )
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2018-12-10 23:40:38 -04:00
}
2018-12-13 20:59:05 -04:00
var result = _LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
if ( Model . SelectedServiceRecordOid . HasValue )
{
result = SerializeObject ( Model . ServiceRecords . First ( f = > f . ServiceRecordOid = = Model . SelectedServiceRecordOid ) ) ;
}
return result ;
}
2017-04-26 14:57:32 +02:00
public string GetSelectedRecordInformationWithOid ( long oid )
2016-06-27 01:45:38 +02:00
{
2018-12-10 23:40:38 -04:00
if ( Model = = null )
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2018-12-10 23:40:38 -04:00
}
2016-06-27 01:45:38 +02:00
LoadRecordsToModel ( ) ;
2018-01-29 12:57:10 +01:00
return SerializeObject ( Model . ServiceRecords . First ( f = > f . ServiceRecordOid = = oid ) ) ;
2016-06-27 01:45:38 +02:00
}
2018-12-10 23:40:38 -04:00
[Authorize]
2017-08-22 14:05:09 +02:00
public string CheckRights ( string von , string bis , bool inEditMode , string dateString , string startString , string endString )
2018-12-10 23:40:38 -04:00
{
2016-06-27 01:45:38 +02:00
if ( Model = = null )
{
2018-12-10 23:40:38 -04:00
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
2020-01-15 16:14:39 +01:00
Log . Info ( $"CheckRights: von:{von};bis:{bis};inEditMode:{inEditMode};dateString:{dateString};startString:{startString};endString:{endString}" ) ;
2016-06-27 01:45:38 +02:00
var startHoursDt = ConvertTimeStringToDateTime ( startString ) ;
var endHoursDt = ConvertTimeStringToDateTime ( endString ) ;
2018-01-29 12:57:10 +01:00
if ( ! DateTime . TryParse ( dateString , out var date ) )
2016-06-27 01:45:38 +02:00
{
date = DateTime . Now . Date ;
}
var startDt = date . AddHours ( startHoursDt . Hour ) . AddMinutes ( startHoursDt . Minute ) ;
var endDt = date . AddHours ( endHoursDt . Hour ) . AddMinutes ( endHoursDt . Minute ) ;
if ( startDt > endDt )
{
return "StartGreaterEnd" ;
}
var dauer = ( int ) ( endDt - startDt ) . TotalMinutes ;
if ( dauer = = 0 )
{
startDt = startDt . AddSeconds ( 1 ) ;
endDt = endDt . AddSeconds ( 1 ) ;
}
var checkSR = new ServiceRecordDC ( ) ;
if ( inEditMode )
{
checkSR = Model . ServiceRecords . FirstOrDefault ( f = > f . ServiceRecordOid . HasValue & & f . ServiceRecordOid . Value . Equals ( Model . SelectedServiceRecordOid ) ) ;
}
if ( checkSR = = null )
{
checkSR = new ServiceRecordDC ( ) ;
}
checkSR . Goals = Model . SelectedGoals ;
checkSR . Start = startDt ;
checkSR . End = endDt ;
2018-12-10 23:40:38 -04:00
checkSR . IP = Request . UserHostAddress ;
checkSR . ServiceDescription = OperationsService . GetServiceDescription ( Model . SelectedServiceDescriptionOid . Value ) ;
checkSR . Employee = Model . SelectedEmployee ? ? MobileSessionFacade . LoggedInCompactEmployee ;
if ( Model . SelectedEmployee ! = null & & ! Model . IsInGroupBookingMode )
2016-06-27 01:45:38 +02:00
{
var sc = Model . SupportConcepts . FirstOrDefault ( fod = > fod . CostBearerRelations . Any ( a = > a . CostBearer2SupportConceptOid . HasValue & & a . CostBearer2SupportConceptOid . Value . Equals ( Model . CostBearer2SupportConceptOid ) ) ) ;
if ( sc ! = null )
{
if ( sc . SupportConceptOid ! = null )
{
checkSR . SupportConcept = CustomerService . LoadCompactSupportConceptDC ( sc . SupportConceptOid . Value , Model . Employee . EmployeeOid ) ;
}
checkSR . Customer = sc . Customer ;
var cb2ScRel = sc . CostBearerRelations . First ( f = > f . CostBearer2SupportConceptOid . HasValue & & f . CostBearer2SupportConceptOid . Equals ( Model . CostBearer2SupportConceptOid ) ) ;
checkSR . CostBearer = cb2ScRel . CostBearer ;
var intervall = checkSR . CostBearer . ActualMinuteIntervall ;
if ( intervall > 0 )
{
2018-12-10 23:40:38 -04:00
checkSR . RoundedDuration = dauer % intervall ! = 0 ? dauer + ( intervall - dauer % intervall ) : dauer ;
2016-06-27 01:45:38 +02:00
}
checkSR . CostBearer2SupportConceptOid = Model . CostBearer2SupportConceptOid ;
}
}
2019-03-29 14:04:12 +01:00
var mandator = OperationsService . GetMandator ( ) ;
var settings = mandator . Settings ? ? string . Empty ;
var splitSettings = settings . Split ( ';' ) ;
var maxDaysEditSRsAllowedSetting = splitSettings . ToList ( ) . FirstOrDefault ( f = > f . Contains ( "MaxDaysEditServiceRecordsAllowed" ) ) ;
var maxDaysEditSRsAllowed = maxDaysEditSRsAllowedSetting ! = null ? int . Parse ( maxDaysEditSRsAllowedSetting . Split ( '=' ) [ 1 ] ) : 0 ;
2018-12-03 19:14:35 -04:00
var limitFuerZeiterfassungSetting = splitSettings . ToList ( ) . FirstOrDefault ( f = > f . Contains ( "AnzTageZeiterfassErfolgt" ) ) ;
2019-03-29 14:04:12 +01:00
var limitFuerZeiterfassung = limitFuerZeiterfassungSetting ! = null ? int . Parse ( limitFuerZeiterfassungSetting . Split ( '=' ) [ 1 ] ) : 0 ;
2018-12-10 23:40:38 -04:00
if ( MobileSessionFacade . CheckForUserRight ( UserRightType . ServiceRecord_AllowEditAfterMaxDaysInNextMonth ) )
{
maxDaysEditSRsAllowed = - 1 ;
}
2016-06-27 01:45:38 +02:00
SupportConceptStatisticsDC stats = null ;
2018-01-29 12:57:10 +01:00
2016-06-27 01:45:38 +02:00
if ( Model . CostBearer2SupportConceptOid ! = null & & Model . CostBearer2SupportConceptOid > 0 )
{
stats = OperationsService . CreateSupportConceptStatistics ( Model . CostBearer2SupportConceptOid . Value , DateTime . Now ) ;
}
2018-11-30 16:47:57 -04:00
var employees = new List < long > { checkSR . Employee . EmployeeOid } ;
2018-12-10 23:40:38 -04:00
var validationResults = new List < ServiceRecord2Validation > ( ) ;
checkSR . ServiceRecordFormat = ServiceRecordFormate . OriginaleZeiterfassung ;
checkSR . DurationInStunden = 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
2018-11-30 16:47:57 -04:00
if ( Model . IsInGroupBookingMode )
2016-06-27 01:45:38 +02:00
{
2018-11-30 16:47:57 -04:00
if ( checkSR . GroupOid . HasValue )
{
var serviceRecordGroup = OperationsService . GetServiceRecordGroup ( checkSR . GroupOid . Value ) ;
serviceRecordGroup . ServiceRecordList . DoForEach ( sr = > employees . AddIfNotIn ( sr . Employee . EmployeeOid ) ) ;
}
else
{
Model . SelectedEmployees . DoForEach ( e = > employees . AddIfNotIn ( e . EmployeeOid ) ) ;
}
2016-06-27 01:45:38 +02:00
2018-11-30 16:47:57 -04:00
var cb2scOids = ( from scDc in Model . SelectedSupportConcepts where scDc . CostBearerRelations ! = null & & scDc . CostBearerRelations . Count > 0 select scDc . CostBearerRelations [ 0 ] . CostBearer2SupportConceptOid . Value ) . ToList ( ) ;
2018-12-10 23:40:38 -04:00
var relations = CustomerService . GetSupportConceptCostBearerRelationsById ( cb2scOids ) ;
2018-11-30 16:47:57 -04:00
2018-12-10 23:40:38 -04:00
foreach ( var rel in relations )
2018-11-30 16:47:57 -04:00
{
2018-12-10 23:40:38 -04:00
var sr = CloneServiceRecordForGroupBooking ( checkSR ) ;
2018-11-30 16:47:57 -04:00
2018-12-10 23:40:38 -04:00
sr . SupportConcept = rel . SupportConcept ;
sr . CostBearer = rel . CostBearer ;
sr . CostBearer2SupportConceptOid = rel . CostBearer2SupportConceptOid ;
2018-11-30 16:47:57 -04:00
2018-12-10 23:40:38 -04:00
var result = OperationsService . ValidateServiceRecord ( sr , null , maxDaysEditSRsAllowed , employees , cb2scOids ) ;
dateRangeString = rel . DateRangeString ;
2018-12-03 19:14:35 -04:00
2018-12-10 23:40:38 -04:00
validationResults . Add ( new ServiceRecord2Validation ( sr , result , dateRangeString ) ) ;
2018-11-30 16:47:57 -04:00
}
}
else
{
2018-12-12 14:27:40 -04:00
if ( Model . SelectedSupportConcept ! = null )
{
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
2018-11-30 16:47:57 -04:00
var result = OperationsService . ValidateServiceRecordEntry ( checkSR , stats , maxDaysEditSRsAllowed , checkSR . GroupOid . HasValue , employees ) ;
2018-12-12 14:27:40 -04:00
validationResults . Add ( new ServiceRecord2Validation ( checkSR , result , dateRangeString ? ? "" ) ) ;
2018-11-30 16:47:57 -04:00
}
2019-03-29 14:04:12 +01:00
var allowOverlappingFLS = MobileSessionFacade . CheckForUserRight ( UserRightType . ServiceRecord_AllowCreateOverlappingFLS ) ;
2018-12-12 14:27:40 -04:00
var allowOverlappingFLSForEmployee = MobileSessionFacade . CheckForUserRight ( UserRightType . ServiceRecord_AllowCreateOverlappingFLSForEmployee ) ;
2019-03-29 14:04:12 +01:00
var allowMoreFLSThanApproved = MobileSessionFacade . CheckForUserRight ( UserRightType . ServiceRecord_AllowCreateMoreFLSThanApproved ) ;
var bookAfterSettlementInvoice = MobileSessionFacade . CheckForUserRight ( UserRightType . BookServiceRecordAfterSettlementInvoice ) ;
2018-12-10 23:40:38 -04:00
var newResult = new ValidationResult ( ) ;
2019-03-29 14:04:12 +01:00
var exitLoop = false ;
2018-12-10 23:40:38 -04:00
foreach ( var sr2v in validationResults )
{
if ( exitLoop )
{
break ;
}
foreach ( var vr in sr2v . ValidationResults )
{
if ( exitLoop )
{
break ;
}
switch ( vr . ResultType )
{
case ServiceRecordOverlapping :
2019-03-29 14:04:12 +01:00
newResult . Message + = "An dem gewählten Datum '" + von + "' existiert bereits ein Eintrag (" + vr . Message + " bei Klient/in " + vr . CustomerName + ").<br /><br />" ;
newResult . KannTrotzdemGespeichertWerden = allowOverlappingFLS ;
exitLoop = ! allowOverlappingFLS ;
2018-12-10 23:40:38 -04:00
break ;
case EmployeeOverlapping :
2019-03-29 14:04:12 +01:00
newResult . Message + = "An dem gewählten Datum " + von + " existiert bereits ein Eintrag von " + vr . EmployeeName + " (" + vr . Message + ").<br /><br />" ;
newResult . KannTrotzdemGespeichertWerden = allowOverlappingFLSForEmployee ;
exitLoop = ! allowOverlappingFLSForEmployee ;
2018-12-10 23:40:38 -04:00
break ;
case OutsideOfSupportConcept :
2018-12-12 14:27:40 -04:00
newResult . Message + = "Das gewählte Datum " + von . Substring ( 0 , 10 ) + " liegt außerhalb des Zeitraumes des gewählten Hilfeplans (" + sr2v . HilfePlanZeitraum + ").<br /><br />" ;
2018-12-10 23:40:38 -04:00
newResult . KannTrotzdemGespeichertWerden = false ;
2019-03-29 14:04:12 +01:00
2018-12-10 23:40:38 -04:00
exitLoop = true ;
2019-03-29 14:04:12 +01:00
2018-12-10 23:40:38 -04:00
break ;
case ApprovedFLSOverspending :
var klient = "diesen Hilfeplan" ;
if ( ! string . IsNullOrEmpty ( vr . CustomerName ) )
{
klient = "Klient/in " + vr . CustomerName ;
}
var msg = "Die für " + klient + " genehmigten FLS (" + vr . ApprovedHours + ") werden mit diesem Eintrag überschritten. (" + vr . HoursNew + ")." ;
2019-03-29 14:04:12 +01:00
newResult . Message + = msg + "<br /><br />" ;
newResult . KannTrotzdemGespeichertWerden = allowMoreFLSThanApproved ;
2018-12-10 23:40:38 -04:00
2019-03-29 14:04:12 +01:00
exitLoop = ! allowMoreFLSThanApproved ;
2018-12-10 23:40:38 -04:00
break ;
case OutOfEditLimit :
2018-12-12 14:27:40 -04:00
newResult . Message + = "Sie kö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 ;
2018-12-10 23:40:38 -04:00
if ( bookAfterSettlementInvoice )
{
2018-12-12 14:27:40 -04: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
{
2018-12-12 14:27:40 -04: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
}
break ;
case FristAbgelaufen :
var intervall = "einem Tag" ;
if ( limitFuerZeiterfassung ! = 1 )
{
intervall = "" + limitFuerZeiterfassung + " Tagen" ;
}
2018-12-12 14:27:40 -04:00
newResult . Message + = "Sie können keine neuen Leistungen für den " + von + " dokumentieren, da die Zeiterfassung innerhalb von " + intervall + " erfolgen muss.<br /><br />" ;
2018-12-10 23:40:38 -04:00
exitLoop = true ;
newResult . KannTrotzdemGespeichertWerden = false ;
break ;
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 ;
newResult . KannTrotzdemGespeichertWerden = false ;
break ;
}
}
}
2016-06-27 01:45:38 +02:00
2018-12-12 14:27:40 -04:00
if ( ! string . IsNullOrEmpty ( newResult . Message ) )
{
newResult . Message + = newResult . KannTrotzdemGespeichertWerden ? "<br />Möchten Sie trotzdem speichern?<br /><br />" : "<br />Speichern nicht möglich.<br /><br />" ;
}
2016-06-27 01:45:38 +02:00
Model . NewServiceRecord = new ServiceRecordDC ( ) ;
2018-11-30 16:47:57 -04:00
return SerializeObject ( newResult ) ;
2016-06-27 01:45:38 +02:00
}
2017-08-22 14:05:09 +02:00
public bool CheckRightsAfterCrash ( string von , string bis , bool inEditMode , string dateString , string startString , string endString , long costbearerOId , string leistung )
2016-06-27 01:45:38 +02:00
{
if ( Model = = null )
{
return false ;
}
2020-01-15 16:14:39 +01:00
Log . Info ( $"CheckRightsAfterCrash: von:{von};bis:{bis};inEditMode:{inEditMode};dateString:{dateString};startString:{startString};endString:{endString}" ) ;
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
var date = DateTime . Now . Date ;
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
var startHoursDt = ConvertTimeStringToDateTime ( startString ) ;
var endHoursDt = ConvertTimeStringToDateTime ( endString ) ;
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
if ( ! DateTime . TryParse ( dateString , out date ) )
{
date = DateTime . Now . Date ;
}
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
var startDt = date . AddHours ( startHoursDt . Hour ) . AddMinutes ( startHoursDt . Minute ) ;
var endDt = date . AddHours ( endHoursDt . Hour ) . AddMinutes ( endHoursDt . Minute ) ;
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
if ( startDt > endDt )
{
Model . ErrorWert = 5 ;
return false ;
}
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
var dauer = ( int ) ( endDt - startDt ) . TotalMinutes ;
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
if ( dauer = = 0 )
{
startDt = startDt . AddSeconds ( 1 ) ;
endDt = endDt . AddSeconds ( 1 ) ;
}
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
var checkSR = new ServiceRecordDC
{
Goals = Model . SelectedGoals ,
Start = startDt ,
End = endDt
} ;
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
if ( Model . Employee . EmployeeOid ! = null )
{
checkSR . Employee = MobileSessionFacade . LoggedInCompactEmployee ;
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
_Model . CostBearer2SupportConceptOid = costbearerOId ;
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
var sc = 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
2018-01-29 12:57:10 +01:00
if ( sc ! = null )
{
if ( sc . SupportConceptOid ! = null )
{
checkSR . SupportConcept = CustomerService . LoadCompactSupportConceptDC ( sc . SupportConceptOid . Value , Model . Employee . EmployeeOid ) ;
}
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
checkSR . Customer = sc . Customer ;
var cb2ScRel = sc . CostBearerRelations . First ( f = > f . CostBearer2SupportConceptOid . HasValue & & f . CostBearer2SupportConceptOid . Equals ( Model . CostBearer2SupportConceptOid ) ) ;
checkSR . CostBearer = cb2ScRel . CostBearer ;
var intervall = checkSR . CostBearer . ActualMinuteIntervall ;
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
if ( intervall > 0 )
2016-06-27 01:45:38 +02:00
{
2018-01-29 12:57:10 +01:00
checkSR . RoundedDuration = dauer % intervall ! = 0 ? dauer + ( intervall - ( dauer % intervall ) ) : dauer ;
}
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
checkSR . CostBearer2SupportConceptOid = Model . CostBearer2SupportConceptOid ;
}
}
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
checkSR . IP = Request . UserHostAddress ;
checkSR . InsertedOn = DateTime . Now ;
checkSR . InsUser = $"{MobileSessionFacade.LoggedInEmployee.FirstName} {MobileSessionFacade.LoggedInEmployee.LastName}" ;
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
if ( leistung ! = null | | leistung = = "" )
{
Model . SelectedServiceDescriptionOid = Convert . ToInt64 ( leistung ) ;
}
else
{
Model . SelectedServiceDescriptionOid = 6 ;
}
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
checkSR . ServiceDescription = OperationsService . GetServiceDescription ( Model . SelectedServiceDescriptionOid . Value ) ;
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
var man = OperationsService . GetMandator ( ) ;
var s = man . Settings ? ? string . Empty ;
var einzeln = s . Split ( ';' ) ;
var g = einzeln . ToList ( ) . FirstOrDefault ( f = > f . Contains ( "MaxDaysEditServiceRecordsAllowed" ) ) ;
var t = g ! = null ? int . Parse ( g . Split ( '=' ) [ 1 ] ) : 0 ;
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
SupportConceptStatisticsDC stats = null ;
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
if ( Model . CostBearer2SupportConceptOid ! = null & & Model . CostBearer2SupportConceptOid > 0 )
{
stats = OperationsService . CreateSupportConceptStatistics ( Model . CostBearer2SupportConceptOid . Value , DateTime . Now ) ;
}
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
var result = OperationsService . ValidateServiceRecordEntry ( checkSR , stats , t , false , new List < long > { checkSR . Employee . EmployeeOid } ) ;
if ( result . Count ! = 0 )
{
if ( result [ 0 ] . EndDate . Day < = date . Day & & result [ 0 ] . EndDate . Year < = date . Year & & result [ 0 ] . EndDate . Month < = date . Month | |
result [ 0 ] . EndDate . Day > = date . Day & & result [ 0 ] . EndDate . Year < = date . Year & & result [ 0 ] . EndDate . Month < = date . Month | |
result [ 0 ] . EndDate . Day < = date . Day & & result [ 0 ] . EndDate . Year < = date . Year & & result [ 0 ] . EndDate . Month > = date . Month | |
result [ 0 ] . EndDate . Day > = date . Day & & result [ 0 ] . EndDate . Year < = date . Year & & result [ 0 ] . EndDate . Month > = date . Month )
2016-06-27 01:45:38 +02:00
{
2018-01-29 12:57:10 +01:00
Model . ErrorWert = 4 ;
return false ;
2016-06-27 01:45:38 +02:00
}
2018-01-29 12:57:10 +01:00
Model . ErrorWert = 3 ;
return false ;
}
2016-06-27 01:45:38 +02:00
2018-01-29 12:57:10 +01:00
Model . ErrorWert = 1 ;
return true ;
2016-06-27 01:45:38 +02:00
}
2018-12-13 20:59:05 -04:00
public string SetViewMode ( )
2016-06-27 01:45:38 +02:00
{
if ( Model = = null )
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
2017-04-26 14:57:32 +02:00
public string GetSelectedSupportConceptCustomer ( )
2016-06-27 01:45:38 +02:00
{
return Model . SelectedSupportConcept = = null ? "NoSupportConceptSelected" : SerializeObject ( Model . SelectedSupportConcept . Customer . CustomerOid ) ;
}
2018-12-13 20:59:05 -04:00
public string SetServiceRecordEmployee ( long employeeOid )
2016-06-27 01:45:38 +02:00
{
2018-06-26 17:18:59 +02:00
try
2016-06-27 01:45:38 +02:00
{
2018-06-26 17:18:59 +02:00
if ( Model = = null )
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2018-06-26 17:18:59 +02:00
}
Model . SelectedEmployee = MainModel . AllEmployees . First ( f = > f . EmployeeOid . Equals ( employeeOid ) ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2018-06-26 17:18:59 +02:00
}
catch ( Exception e )
{
2020-01-15 16:14:39 +01:00
Log . Info ( "Error in SetServiceRecordEmployee:" ) ;
Log . Error ( e . Message , e ) ;
2018-10-08 11:57:16 +02:00
if ( MainModel . AllEmployees = = null )
{
2020-01-15 16:14:39 +01:00
Log . Info ( "Weitere Infos: AllEmployees = null!" ) ;
2018-10-08 11:57:16 +02:00
}
else
{
2020-01-15 16:14:39 +01:00
Log . Info ( $"Weitere Infos: AllEmployees enthält {MainModel.AllEmployees.Count} Elemente: " ) ;
2018-10-08 11:57:16 +02:00
StringBuilder sb = new StringBuilder ( ) ;
foreach ( var ce in MainModel . AllEmployees )
{
if ( sb . Length > 0 )
{
sb . Append ( "," ) ;
}
sb . Append ( ce . EmployeeOid ) ;
}
2020-01-15 16:14:39 +01:00
Log . Info ( sb . ToString ( ) ) ;
2018-10-08 11:57:16 +02:00
}
2018-06-26 17:18:59 +02:00
throw e ;
2016-06-27 01:45:38 +02:00
}
}
public string CheckToken ( string token )
{
if ( token ! = null & & token . Equals ( "abcd" ) )
{
return SerializeObject ( "localhost;demo" ) ;
}
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
2018-03-12 12:07:53 +01:00
2019-07-25 14:56:11 +02:00
public ActionResult RedirectToScheduler ( )
{
return RedirectToActionPermanent ( "Scheduler" , "Scheduler" ) ;
}
public ActionResult RedirectToCustomer ( )
{
2019-11-21 19:39:32 +01:00
// TODO: eventuell ausgewählten Klienten übergeben
2019-11-23 16:46:34 +01:00
if ( Model ? . SelectedSupportConcept ? . Customer ? . Oid . HasValue ? ? false )
{
return RedirectToActionPermanent ( "PreselectCustomer" , "Customer" , new { Model . SelectedSupportConcept . Customer . CustomerOid } ) ;
}
if ( Model ? . SelectedSupportConcept = = null & & ( CustomerModel ) Session [ CustomerController . CustomerModelModelSessionKey ] ! = null )
{
var customerModel = ( CustomerModel ) Session [ CustomerController . CustomerModelModelSessionKey ] ;
customerModel . SelectedCustomerOid = null ;
customerModel . SelectedCustomer = null ;
}
2019-07-25 14:56:11 +02:00
return RedirectToActionPermanent ( "Customer" , "Customer" ) ;
}
2019-07-29 19:40:14 +02:00
public ActionResult RedirectToMain ( )
{
return RedirectToActionPermanent ( "Main" , "Main" ) ;
}
2019-03-29 14:04:12 +01:00
// Gruppenbuchungen
2018-04-18 14:33:21 +02:00
[HttpPost]
[Authorize]
public ActionResult SetGroupBookingMode ( FormCollection pFormCollection )
{
2018-12-03 19:14:35 -04:00
if ( Model = = null )
{
return RedirectToActionPermanent ( "Index" , "Login" ) ;
}
2018-04-18 14:33:21 +02:00
var isInGroupBookingMode = "true,false" = = pFormCollection [ "IsInGroupBookingMode" ] ;
2018-11-30 16:47:57 -04:00
ResetGroupBookingMode ( isInGroupBookingMode ) ;
2018-04-18 14:33:21 +02:00
2018-11-30 16:47:57 -04:00
return RedirectToAction ( "Main" ) ;
}
private void ResetGroupBookingMode ( bool pIsInGroupBookingMode )
{
2018-12-03 19:14:35 -04:00
if ( Model = = null )
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
return ;
}
2018-11-30 16:47:57 -04:00
Model . IsInGroupBookingMode = pIsInGroupBookingMode ;
if ( pIsInGroupBookingMode )
2018-04-18 14:33:21 +02:00
{
Model . SelectedSupportConcept = null ;
Model . SelectedEmployee = null ;
2018-11-24 14:28:46 -04:00
Model . ServiceCategories = CreateServiceCategoryModels ( OperationsService . GetAllServiceDescriptions ( ) ) ;
2018-11-30 16:47:57 -04:00
Model . SelectedEmployees . Add ( MobileSessionFacade . LoggedInCompactEmployee ) ;
2018-04-18 14:33:21 +02:00
}
2018-11-24 14:28:46 -04:00
else
2018-04-18 14:33:21 +02:00
{
2018-11-24 14:28:46 -04:00
Model . ServiceCategories . Clear ( ) ;
2018-11-30 16:47:57 -04:00
Model . SelectedCostbearerRelOids . Clear ( ) ;
Model . SelectedEmployees . Clear ( ) ;
Model . SelectedSupportConcepts . Clear ( ) ;
2019-03-29 14:04:12 +01:00
Model . SelectedConceptCostBearerRelations . Clear ( ) ;
2018-04-18 14:33:21 +02:00
2018-12-10 23:40:38 -04:00
Model . SelectedEmployee = MobileSessionFacade . LoggedInCompactEmployee ;
2018-11-30 16:47:57 -04:00
if ( Model . SelectedSupportConcept ! = null )
{
var details = OperationsService . GetSupportConceptTreeNodeDetailInfo ( Model . SelectedSupportConcept . Customer . CustomerOid , Model . SelectedSupportConcept . SupportConceptOid , Model . CostBearer2SupportConceptOid ) ;
Model . ServiceCategories = details . ServiceAccountings . Count > 0
? CreateServiceCategoryModels ( details . ServiceAccountings . Select ( sa = > sa . ServiceDescription ) . ToList ( ) )
: CreateServiceCategoryModels ( OperationsService . GetAllServiceDescriptions ( ) ) ;
Model . ServiceCategories = Model . ServiceCategories . Where ( c = > ! c . OhneHilfeplan . HasValue | | c . OhneHilfeplan . Value = = AccountingvisibilityType . Beides | | c . OhneHilfeplan . Value = = AccountingvisibilityType . NurKlientenbezogen ) . ToList ( ) ;
}
else if ( Model . CostBearer2SupportConceptOid = = - 2 )
{
Model . ServiceCategories = CreateServiceCategoryModels ( OperationsService . GetAllServiceDescriptions ( ) ) ;
Model . ServiceCategories = Model . ServiceCategories . Where ( c = > ! c . OhneHilfeplan . HasValue | | c . OhneHilfeplan . Value = = AccountingvisibilityType . Beides | | c . OhneHilfeplan . Value = = AccountingvisibilityType . NichtKlientenbezogen ) . ToList ( ) ;
}
}
2018-04-18 14:33:21 +02:00
}
[HttpPost]
[Authorize]
public ActionResult ResetEditingMode ( FormCollection pFormCollection )
{
2018-12-03 19:14:35 -04:00
if ( Model = = null )
{
return RedirectToActionPermanent ( "Index" , "Login" ) ;
}
2018-04-18 14:33:21 +02:00
Model . NewServiceRecord = new ServiceRecordDC ( ) ;
Model . SelectedServiceRecord = null ;
Model . SelectedSupportConcepts . Clear ( ) ;
Model . SelectedEmployees . Clear ( ) ;
Model . IsInGroupBookingMode = false ;
Model . IsInEditingMode = false ;
return RedirectToActionPermanent ( "Main" ) ;
}
2018-04-27 14:11:21 +02:00
2018-04-18 14:33:21 +02:00
public string LoadCategoryAndDescription ( )
{
2018-12-03 19:14:35 -04:00
if ( Model = = null )
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2018-12-03 19:14:35 -04:00
}
2018-11-30 16:47:57 -04:00
if ( Model . SelectedServiceRecord = = null )
{
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2018-11-30 16:47:57 -04:00
}
2018-04-18 14:33:21 +02:00
var serviceDescriptionOid = Model . SelectedServiceRecord . ServiceDescription . ServiceDescriptionOid . ToString ( ) ;
var serviceCategoryOid = Model . SelectedServiceRecord . ServiceDescription . Category . ServiceCategoryOid . ToString ( ) ;
2018-03-12 12:07:53 +01:00
2018-04-18 14:33:21 +02:00
return $"{serviceDescriptionOid}/{serviceCategoryOid}" ;
2018-03-12 12:07:53 +01:00
}
2016-06-27 01:45:38 +02:00
2018-11-24 14:28:46 -04:00
[Authorize]
2019-03-29 14:04:12 +01:00
public string ResetGroupBookingModeViaGET ( )
2016-06-27 01:45:38 +02:00
{
2018-11-24 14:28:46 -04:00
if ( Model = = null )
2016-06-27 01:45:38 +02:00
{
2019-03-29 14:04:12 +01:00
RedirectToActionPermanent ( "Index" , "Login" ) ;
return _LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
2019-03-29 14:04:12 +01:00
Model . IsInGroupBookingMode = false ;
Model . SelectedCostbearerRelOids . Clear ( ) ;
2018-11-24 14:28:46 -04:00
Model . SelectedEmployees . Clear ( ) ;
2019-03-29 14:04:12 +01:00
Model . SelectedSupportConcepts . Clear ( ) ;
Model . SelectedConceptCostBearerRelations . Clear ( ) ;
2018-11-24 14:28:46 -04:00
2019-11-21 19:39:32 +01:00
return AbstractModel . IsEmployeeSelectionVisible . ToString ( ) ;
2016-06-27 01:45:38 +02:00
}
2017-04-26 14:57:32 +02:00
2018-11-24 14:28:46 -04:00
[Authorize]
2019-03-29 14:04:12 +01:00
public string AddSupportConceptCostBearerRelationsToGroupBooking ( string pRelOids , string pGroupOids )
2017-04-26 14:57:32 +02:00
{
2019-03-29 14:04:12 +01:00
if ( Model = = null )
2018-12-03 19:14:35 -04:00
{
2019-03-29 14:04:12 +01:00
RedirectToActionPermanent ( "Index" , "Login" ) ;
return _LeerzeichenFuerGetMethoden ;
2018-12-03 19:14:35 -04:00
}
2019-03-29 14:04:12 +01:00
var rawRelOids = string . IsNullOrEmpty ( pRelOids ) ? new string [ 0 ] : pRelOids . Split ( ',' ) ;
var rawGroupOids = string . IsNullOrEmpty ( pGroupOids ) ? new string [ 0 ] : pGroupOids . Split ( ',' ) ;
2018-11-24 14:28:46 -04:00
var relOids = new List < long > ( ) ;
var groups = new List < GroupOfPeopleDC > ( ) ;
2018-01-29 12:57:10 +01:00
2019-03-29 14:04:12 +01:00
rawRelOids . DoForEach ( s = > relOids . AddIfNotIn ( long . Parse ( s ) ) ) ;
2018-11-24 14:28:46 -04:00
Model . SelectedGroupOfPeopleOids . Clear ( ) ;
2018-02-07 14:14:08 +01:00
2019-03-29 14:04:12 +01:00
rawGroupOids . DoForEach ( s = >
2018-11-24 14:28:46 -04:00
{
2019-03-29 14:04:12 +01:00
var group = Model . GroupsOfPeople . FirstOrDefault ( f = > f . GroupOfPeopleOid . HasValue & & f . GroupOfPeopleOid . Value . Equals ( long . Parse ( s ) ) ) ;
if ( group = = 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
}
2019-03-29 14:04:12 +01:00
groups . AddIfNotIn ( group ) ;
group . SupportConceptList . DoForEach ( f = > relOids . AddRangeIfElementsNotIn ( f . CostBearerRelOids ) ) ;
} ) ;
2018-11-24 14:28:46 -04:00
Model . SelectedSupportConcepts . Clear ( ) ;
Model . SelectedCostbearerRelOids . Clear ( ) ;
Model . SelectedCostbearerRelOids . AddRangeIfElementsNotIn ( relOids ) ;
var selectedSupportConcepts = Model . SupportConcepts . Where ( w = > w ! = null & & w . CostBearerRelations . Any ( a = > a . CostBearer2SupportConceptOid . HasValue & & relOids . Contains ( a . CostBearer2SupportConceptOid . Value ) ) ) . ToList ( ) ;
2019-03-29 14:04:12 +01:00
var groupCostBearerRelations = CustomerService . GetSupportConceptCostBearerRelationsById ( relOids ) ;
Model . SelectedConceptCostBearerRelations . Clear ( ) ;
Model . SelectedConceptCostBearerRelations . AddRangeIfElementsNotIn ( groupCostBearerRelations ) ;
2018-11-24 14:28:46 -04:00
Model . SelectedSupportConcepts . 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 ( relOids . ContainsItems ( groupRelOids ) )
{
Model . SelectedGroupOfPeopleOids . AddIfNotIn ( groupOid ) ;
}
else if ( Model . SelectedGroupOfPeopleOids . Contains ( groupOid ) )
{
Model . SelectedGroupOfPeopleOids . Remove ( groupOid ) ;
}
}
2019-03-29 14:04:12 +01:00
return SerializeObject ( Model . SelectedRelations . ToArray ( ) ) ;
2018-02-07 14:14:08 +01:00
}
2018-11-30 16:47:57 -04:00
[Authorize]
2019-03-29 14:04:12 +01:00
public string RemoveSupportConceptCostBearerRelationFromGroupBooking ( string pRelOid )
2018-11-30 16:47:57 -04:00
{
2019-03-29 14:04:12 +01:00
if ( Model = = null )
2018-12-03 19:14:35 -04:00
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2018-12-03 19:14:35 -04:00
}
2019-03-29 14:04:12 +01:00
long . TryParse ( pRelOid , out var supportConceptCostBearerRelationOid ) ;
2018-11-30 16:47:57 -04:00
2019-03-29 14:04:12 +01:00
var supportConcept = Model . SelectedSupportConcepts . FirstOrDefault ( f = > f . CostBearerRelations . Any ( a = > a . CostBearer2SupportConceptOid = = supportConceptCostBearerRelationOid ) ) ;
var relation = Model . SelectedConceptCostBearerRelations . FirstOrDefault ( f = > f . CostBearer2SupportConceptOid = = supportConceptCostBearerRelationOid ) ;
Model . SelectedSupportConcepts . Remove ( supportConcept ) ;
Model . SelectedConceptCostBearerRelations . Remove ( relation ) ;
return _LeerzeichenFuerGetMethoden ;
}
[Authorize]
public string AddEmployeesToGroupBooking ( string pEmployeeOids )
{
if ( Model = = null )
{
RedirectToActionPermanent ( "Index" , "Login" ) ;
return _LeerzeichenFuerGetMethoden ;
}
if ( string . IsNullOrEmpty ( pEmployeeOids ) )
{
Model . SelectedEmployees . Clear ( ) ;
return _LeerzeichenFuerGetMethoden ;
}
var rawEmployeeOids = pEmployeeOids . Split ( ',' ) ;
var oids = new List < long > ( ) ;
rawEmployeeOids . DoForEach ( s = > oids . AddIfNotIn ( long . Parse ( s ) ) ) ;
var employees = Model . Employees . Where ( w = > oids . Contains ( w . EmployeeOid ) ) ;
Model . SelectedEmployees . Clear ( ) ;
Model . SelectedEmployees . AddRangeIfElementsNotIn ( employees ) ;
return _LeerzeichenFuerGetMethoden ;
2018-11-30 16:47:57 -04:00
}
2019-04-17 17:01:37 +02:00
[HttpPost]
[Authorize]
public ActionResult LoadSignatureImage ( FormCollection pFormCollection )
{
if ( Model = = null )
{
return RedirectToActionPermanent ( "Index" , "Login" ) ;
}
var isParsingSuccessful = long . TryParse ( pFormCollection [ "signatureOidHolder" ] , out var signatureOid ) ;
if ( isParsingSuccessful )
{
Model . SignatureImage = OperationsService . GetSignature ( signatureOid ) . DataBild ;
}
return RedirectToActionPermanent ( "Main" ) ;
}
[Authorize]
public string ResetSignatureImage ( )
{
if ( Model = = null )
{
return _LeerzeichenFuerGetMethoden ;
}
Model . SignatureImage = null ;
return _LeerzeichenFuerGetMethoden ;
}
2019-07-25 14:56:11 +02:00
public string SetDropdownHeight ( string pRawHeight )
{
if ( pRawHeight = = null | | pRawHeight . Length < 2 )
{
return _LeerzeichenFuerGetMethoden ;
}
var height = pRawHeight . Substring ( 0 , pRawHeight . Length - 2 ) ;
AbstractModel . DropdownHeight = int . Parse ( height ) ;
return _LeerzeichenFuerGetMethoden ;
}
2018-02-07 14:14:08 +01:00
}
2016-06-27 01:45:38 +02:00
}