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 ;
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 ;
2020-04-02 13:19:14 +02:00
using System.Windows.Forms ;
2018-04-18 14:33:21 +02:00
using BeWo.Service.ServiceImplementations ;
2020-12-16 21:49:47 +01:00
using BeWo.View.Navigation.Filter ;
2016-06-27 01:45:38 +02:00
using BeWoPlanerMobil.Models ;
using BeWoPlanerMobil.Service ;
2018-04-18 14:33:21 +02:00
using BeWoPlanerMobil.Util ;
2018-11-26 13:27:16 -04:00
2018-11-24 14:28:46 -04:00
using static BeWoPlanerMobil . Util . MobileUtils ;
2018-01-29 12:57:10 +01:00
2016-06-27 01:45:38 +02:00
using BS.Shared ;
using BS.Shared.Core ;
using BS.Shared.DataContracts ;
using BS.Shared.DataContracts.Compact ;
2018-01-29 12:57:10 +01:00
using BS.Shared.Extensions ;
2018-04-18 14:33:21 +02:00
using BS.Shared.Services ;
2020-02-07 15:21:36 +01:00
using Newtonsoft.Json ;
2018-12-10 23:40:38 -04:00
using static BS . Shared . ServiceRecordValidationResult ;
2020-04-02 13:19:14 +02:00
using FormCollection = System . Web . Mvc . FormCollection ;
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 ;
}
2020-09-21 11:57:10 +02:00
if ( ( ( MainModel ) Session [ ModelSessionConstants . MainModelKey ] ) ? . Employee = = null )
2016-06-27 01:45:38 +02:00
{
2018-01-29 12:57:10 +01:00
_Model = new MainModel { Employee = MobileSessionFacade . LoggedInEmployee } ;
2020-09-21 11:57:10 +02:00
Session [ ModelSessionConstants . MainModelKey ] = _Model ;
2016-06-27 01:45:38 +02:00
}
else
{
2020-09-21 11:57:10 +02:00
_Model = ( MainModel ) Session [ ModelSessionConstants . MainModelKey ] ;
2016-06-27 01:45:38 +02:00
}
2018-01-29 12:57:10 +01:00
return _Model ;
2016-06-27 01:45:38 +02:00
}
}
2018-01-29 12:57:10 +01:00
private Dictionary < long , ValueListEntryDC > _ParentGoals ;
2016-06-27 01:45:38 +02:00
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
2020-08-04 12:45:46 +02:00
private MandatorDC GetMandator ( )
{
var mandator = ( MandatorDC ) HttpContext . Session [ "mandator" ] ;
if ( mandator = = null )
{
mandator = OperationsService . GetMandator ( ) ;
HttpContext . Session [ "mandator" ] = mandator ;
}
return mandator ;
}
2016-06-27 01:45:38 +02:00
[Authorize]
public ActionResult Main ( )
{
try
{
2020-04-02 13:19:14 +02:00
if ( ! MobileSessionFacade . IsUserLoggedIn ( ) | | Request . Browser . Browser . Equals ( "InternetExplorer" ) | | ! AbstractModel . HasRightToSeeServiceRecords )
2017-08-22 14:05:09 +02:00
{
2020-05-27 18:15:54 +02:00
var isNewSession = Session . IsNewSession ;
if ( isNewSession )
{
TempData [ "ein_schluessel" ] = "Sie wurden automatisch abgemeldet, da Ihre Session abgelaufen ist." ;
}
2020-04-02 13:19:14 +02:00
return Logout ( ) ;
2017-08-22 14:05:09 +02:00
}
2016-06-27 01:45:38 +02:00
2018-02-28 12:42:23 +01:00
Model . ShowExpiredSupportConcepts = GetUserSettingValue ( "ShowExpiredSupportConcepts" ) = = "1" ;
Model . ShowOnlyOwnSupportConcepts = GetUserSettingValue ( "ShowOnlyMySupportConcepts" ) = = "1" ;
2020-11-11 14:21:29 +01:00
2020-12-16 21:49:47 +01:00
var customerFilterRaw = GetUserSettingValue ( "CustomerFilterInZeiterfassung" ) ;
if ( ! Enum . TryParse ( customerFilterRaw , out CustomerFilterEnum customerFilter ) )
{
customerFilter = CustomerFilterEnum . MyCustomer ;
}
Model . SelectedSupportConceptFilter = customerFilter ;
2018-02-28 12:42:23 +01:00
2020-08-04 12:45:46 +02:00
var mandator = GetMandator ( ) ;
2020-04-02 13:19:14 +02:00
var supportConceptExpirationLimitInMonths = GetSettingValue ( mandator . Settings , "HilfeplanAuslaufAuswahl" ) ;
var anzTageZeiterfassErfolgt = GetSettingValue ( mandator . Settings , "AnzTageZeiterfassErfolgt" ) ;
var maxDaysEditServiceRecordsAllowed = 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 ) ;
2020-04-02 13:19:14 +02:00
2020-05-27 18:15:54 +02:00
var timeUntilUILock = GetSettingValue ( mandator . Settings , "TimeUntilUILock" ) ;
BS . Shared . Settings . ApplicationSettings . TimeUntilUILock = timeUntilUILock = = null ? 0 : int . Parse ( timeUntilUILock ) ;
2020-04-02 13:19:14 +02:00
var unter = GetSettingValue ( mandator . Settings , "ShowSignature" ) ;
2017-02-01 13:53:59 +01:00
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
2020-04-02 13:19:14 +02:00
if ( ! Model . IsInEditingMode )
{
Model . SelectedGoals . Clear ( ) ;
}
Model . ShowDistanceField = "1" = = GetSettingValue ( mandator . Settings , "ShowDistanceFields" ) ;
2018-02-02 14:43:40 +01:00
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
}
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 } ;
}
2020-12-16 21:49:47 +01:00
if ( Model ? . Employee ? . EmployeeOid . HasValue ? ? false )
2016-06-27 01:45:38 +02:00
{
2020-12-16 21:49:47 +01:00
Model . SupportConcepts = EmployeeService . GetActiveSupportConceptsForEmployee ( Model . Employee . EmployeeOid , Model . SelectedSupportConceptFilter ) ;
2016-06-27 01:45:38 +02:00
}
else
{
2020-12-16 21:49:47 +01:00
Model . SupportConcepts = new List < SupportConceptDC > ( ) ;
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
2020-12-01 12:29:12 +01:00
return endDate = = null | | endDate . Value > = DateTime . Now . Date ;
2018-02-28 12:42:23 +01:00
} ) . 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 > ( ) ;
}
2018-12-10 23:40:38 -04:00
if ( Model . SelectedEmployee = = null )
{
Model . SelectedEmployee = MobileSessionFacade . LoggedInCompactEmployee ;
}
2018-12-12 14:27:40 -04:00
2020-04-02 13:19:14 +02:00
var isServiceRecordNoticeMandatorySetting = GetSettingValue ( mandator . Settings , "IsServiceRecordNoticeMandatory" ) ;
2019-11-25 21:19:07 +01:00
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
2020-04-02 13:19:14 +02:00
var isInList = Model . SelectedSupportConceptListObject ! = null & & Model . SupportConceptListObjects . Contains ( Model . SelectedSupportConceptListObject ) ;
if ( Model . SelectedSupportConceptListObject = = null | | ! isInList )
{
Model . SelectedSupportConceptListObject = Model . SupportConceptListObjects . FirstOrDefault ( f = > f . CostBearer2SupportConceptOid = = "-1" ) ? ? Model . SupportConceptListObjects . First ( ) ;
Model . CostBearer2SupportConceptOid = - 1 ;
}
if ( Model . CostBearer2SupportConceptOid ! = null )
2019-07-19 17:13:57 +02:00
{
2020-04-02 13:19:14 +02:00
LoadRecordsToModel ( ) ;
2019-07-19 17:13:57 +02:00
}
2020-04-02 13:19:14 +02:00
var endtime = GetSettingValue ( mandator . Settings , "IsEndDateVisible" ) ;
Model . IsEndDateVisible = Equals ( endtime , "1" ) ;
var isDurationMinHoursSwitchableSetting = GetSettingValue ( mandator . Settings , "IsZeiterfassungInStdMin" ) ;
Model . IsZeiterfassungInStdMin = Equals ( isDurationMinHoursSwitchableSetting , "1" ) ;
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 ) ;
}
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 )
{
2020-10-07 19:42:17 +02:00
return Logout ( ) ;
2018-12-10 23:40:38 -04:00
}
2020-09-21 11:57:10 +02:00
var newValue = "true,false" = = pCollection [ FormCollectionConstants . ShowExpiredSupportConceptsKey ] ;
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 )
{
2020-10-07 19:42:17 +02:00
return Logout ( ) ;
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]
2020-04-02 13:19:14 +02:00
public string LoadGoalTreeItems ( )
2016-06-27 01:45:38 +02:00
{
2020-05-12 14:20:58 +02:00
if ( ! Model . CostBearer2SupportConceptOid . HasValue | | Model . CostBearer2SupportConceptOid . Value > 0 | | Model . SelectedSupportConcept = = null )
2020-04-02 13:19:14 +02:00
{
return null ;
}
var goals = Model . SelectedSupportConcept . Goals ;
var missingParentElements = goals . Where ( w = > w . ParentOid . HasValue & & ! goals . Any ( a = > a . ValueListEntryOid . Equals ( w . ParentOid ) ) ) . Select ( s = > s . ParentOid ) . ToList ( ) ;
_ParentGoals = new Dictionary < long , ValueListEntryDC > ( ) ;
foreach ( var oid in missingParentElements )
{
LoadMissingParents ( oid . Value ) ;
}
goals . AddRangeIfElementsNotIn ( _ParentGoals . Values ) ;
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 ( ) ;
var parentItems = goals . Where ( w = > w . ValueListEntryOid . HasValue & & goals . Any ( a = > a . ParentOid . HasValue & & a . ParentOid . Equals ( w . ValueListEntryOid ) ) ) . ToList ( ) ;
2020-06-29 19:24:24 +02:00
var goalTree = new List < BootstrapTreeViewItem > ( ) ;
var goalTreeDic = new Dictionary < long , BootstrapTreeViewItem > ( ) ;
2020-04-02 13:19:14 +02:00
foreach ( var ziel in ziele . Where ( ziel = > ziel . ValueListEntryOid . HasValue ) )
{
2020-06-29 19:24:24 +02:00
var treeItem = new BootstrapTreeViewItem ( ziel . TypeDescription , ziel . ParentOid , ziel . ValueListEntryOid . Value , parentItems . Contains ( ziel ) ) ;
2020-04-02 13:19:14 +02:00
goalTreeDic . Add ( ziel . ValueListEntryOid . Value , treeItem ) ;
if ( ziel . ParentOid = = null )
{
goalTree . Add ( treeItem ) ;
}
}
foreach ( var zielMitEltern in goalTreeDic . Values . Where ( w = > w . ParentOid ! = null ) )
{
2020-06-29 19:24:24 +02:00
goalTreeDic [ zielMitEltern . ParentOid . Value ] . Nodes . Add ( zielMitEltern ) ;
2020-04-02 13:19:14 +02:00
}
foreach ( var ziel in massnahmen )
{
2020-06-29 19:24:24 +02:00
var node = new BootstrapTreeViewItem ( ziel . TypeDescription , ziel . ParentOid , ziel . ValueListEntryOid . Value , parentItems . Contains ( ziel ) ) ;
2020-04-02 13:19:14 +02:00
if ( ziel . ParentOid ! = null & & goalTreeDic . ContainsKey ( ziel . ParentOid . Value ) )
{
node . ParentOid = goalTreeDic [ ziel . ParentOid . Value ] . ParentOid ;
2020-06-29 19:24:24 +02:00
goalTreeDic [ ziel . ParentOid . Value ] . Nodes . Add ( node ) ;
2020-04-02 13:19:14 +02:00
}
}
2020-05-12 14:20:58 +02:00
2020-04-02 13:19:14 +02:00
return JsonConvert . SerializeObject ( goalTree , Formatting . None , new JsonSerializerSettings
{
NullValueHandling = NullValueHandling . Ignore
} ) ;
}
[Authorize]
public string LoadGoals ( )
{
if ( ( ! Model . CostBearer2SupportConceptOid . HasValue | | Model . CostBearer2SupportConceptOid . Value > 0 ) & & Model . SelectedSupportConcept = = null )
2016-06-27 01:45:38 +02:00
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
2020-04-02 13:19:14 +02:00
return null ;
2016-06-27 01:45:38 +02:00
}
2020-04-02 13:19:14 +02:00
var supportConcept = Model . SupportConcepts . FirstOrDefault ( sc = > sc . CostBearerRelations . Any ( sc2Cb = > sc2Cb . CostBearer2SupportConceptOid . HasValue & & sc2Cb . CostBearer2SupportConceptOid . Value . Equals ( Model . CostBearer2SupportConceptOid . Value ) ) ) ;
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
if ( supportConcept = = null )
2018-01-29 12:57:10 +01:00
{
2020-04-02 13:19:14 +02:00
return null ;
2018-01-29 12:57:10 +01:00
}
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
Model . SelectedSupportConcept = supportConcept ;
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
var selectedGoals = supportConcept . Goals ;
2016-06-27 01:45:38 +02:00
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
}
2020-04-02 13:19:14 +02:00
2020-08-04 12:45:46 +02:00
private static List < GoalTreeItem > BuildGoalTree ( IReadOnlyCollection < ValueListEntryDC > goals )
2016-06-27 01:45:38 +02:00
{
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 > ( ) ;
2020-04-02 13:19:14 +02:00
2018-02-02 14:43:40 +01:00
foreach ( var ziel in ziele )
2016-06-27 01:45:38 +02:00
{
2020-04-02 13:19:14 +02:00
var treeItem = new GoalTreeItem { Children = new List < GoalTreeItem > ( ) , Header = ziel . TypeDescription , ParentOid = ziel . ParentOid , ValueListEntryOid = ziel . ValueListEntryOid } ;
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
goalTreeDic . Add ( ziel . ValueListEntryOid . Value , treeItem ) ;
2016-06-27 01:45:38 +02:00
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
{
2020-04-02 13:19:14 +02:00
var kind = new GoalTreeItem { Children = new List < GoalTreeItem > ( ) , Header = ziel . TypeDescription , IsLeaf = true , ValueListEntryOid = ziel . ValueListEntryOid } ;
2016-06-27 01:45:38 +02:00
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 ) ;
}
}
2020-04-02 13:19:14 +02:00
foreach ( var item in goalTreeDic . Values )
{
if ( item . Children . Count = = 0 )
{
item . IsLeaf = true ;
}
}
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-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 ) ) ;
2020-10-07 19:42:17 +02:00
return settings ! = null ? GetSettingValue ( settings . Value , key ) : null ;
2018-02-28 12:42:23 +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
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
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]
2020-04-02 13:19:14 +02:00
public string SaveUnterschrift ( string blob , string timeStamp , long? serviceRecordOid )
2016-06-27 01:45:38 +02:00
{
try
{
if ( Model = = null )
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
2020-04-02 13:19:14 +02:00
using ( var signatureBitmap = SignatureUtils . Base64StringToBitmap ( blob . Split ( ',' ) [ 1 ] ) )
2019-11-21 19:39:32 +01:00
{
2020-04-02 13:19:14 +02:00
var isValid = SignatureUtils . ValidateSignature ( signatureBitmap ) ;
2019-11-21 19:39:32 +01:00
2020-04-02 13:19:14 +02:00
if ( ! isValid )
{
return SerializeObject ( "Das Unterschriftenfeld darf nicht leer sein." ) ;
}
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
var date = DateTime . Parse ( timeStamp ) ;
OperationsService . InsertSignature ( new SignatureDC
{
DataBild = blob ,
Zeitstempel = date ,
ServiceRecordOid = serviceRecordOid
} ) ;
}
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2016-06-27 01:45:38 +02:00
}
catch ( Exception e )
{
2020-04-02 13:19:14 +02: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
}
2020-04-02 13:19:14 +02:00
}
2019-11-21 19:39:32 +01:00
2020-04-02 13:19:14 +02:00
private void ApplyWatermark ( )
{
if ( Model = = null | | string . IsNullOrWhiteSpace ( Model . SignatureImage ) )
2019-11-21 19:39:32 +01:00
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
2020-04-02 13:19:14 +02:00
return ;
2019-11-21 19:39:32 +01:00
}
2020-04-02 13:19:14 +02:00
var watermarkImage = Image . FromFile ( Server . MapPath ( "../Content/images/bewoplaner_logo_big.png" ) ) ;
2019-11-21 19:39:32 +01:00
2020-04-02 13:19:14 +02:00
var signatureImage = SignatureUtils . Base64StringToBitmap ( Model . SignatureImage ) ;
2019-11-21 19:39:32 +01:00
2020-04-02 13:19:14 +02:00
var hasTransparentBackground = SignatureUtils . HasTransparentBackground ( Model . SignatureImage ) ;
2019-11-21 19:39:32 +01:00
2020-04-02 13:19:14 +02:00
if ( hasTransparentBackground )
2019-11-21 19:39:32 +01:00
{
2020-04-02 13:19:14 +02:00
signatureImage = SignatureUtils . AddBackgroundToBitmap ( signatureImage , Color . White ) ;
2019-11-21 19:39:32 +01:00
}
2020-04-02 13:19:14 +02:00
var watermarker = new Watermarker ( signatureImage ) ;
2019-11-21 19:39:32 +01:00
2020-04-02 13:19:14 +02:00
for ( var y = 0 ; y < signatureImage . Height ; y + + )
2016-06-27 01:45:38 +02:00
{
2020-04-02 13:19:14 +02:00
for ( var x = 0 ; x < signatureImage . Width ; x + + )
2016-06-27 01:45:38 +02:00
{
2020-04-02 13:19:14 +02:00
watermarker . Position = WatermarkPosition . Absolute ;
watermarker . PositionX = x ;
watermarker . PositionY = y ;
watermarker . Margin = new Padding ( 20 ) ;
watermarker . Opacity = . 1f ;
watermarker . TransparentColor = Color . White ;
watermarker . DrawImage ( watermarkImage ) ;
x + = watermarkImage . Width ;
2016-06-27 01:45:38 +02:00
}
2018-11-30 16:47:57 -04:00
2020-04-02 13:19:14 +02:00
y + = watermarkImage . Height ;
2016-06-27 01:45:38 +02:00
}
2020-04-02 13:19:14 +02:00
Model . SignatureImage = "data:image/png;base64," + SignatureUtils . ConvertImageToBase64String ( watermarker . Image ) ;
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 )
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
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 ;
}
2020-07-13 16:25:43 +02:00
return SerializeObject ( scm ! = null ? scm . ServiceDescriptions . OrderBy ( serviceDescription = > serviceDescription . Position ) . ToList ( ) : new List < ServiceDescriptionDC > ( ) ) ;
2018-04-27 14:11:21 +02:00
}
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 )
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
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 )
{
2020-10-07 19:42:17 +02:00
if ( string . IsNullOrWhiteSpace ( tm . Text ) )
2018-05-28 15:02:55 +02:00
{
2020-02-06 18:44:35 +01:00
tm . Text = tm . Name ;
2018-05-28 15:02:55 +02:00
}
}
2020-02-10 12:02:59 +01:00
2018-05-28 15:02:55 +02:00
if ( ! MobileSessionFacade . CheckForUserRight ( UserRightType . TextbausteineAlleAnsehen ) )
2018-04-27 14:11:21 +02:00
{
2020-04-02 13:19:14 +02:00
textbausteine = textbausteine . Where ( w = > w . Employee . EmployeeOid = = Model . Employee . EmployeeOid & & w . IsOnlyForEmployee ) . ToList ( ) ;
2018-04-27 14:11:21 +02:00
}
2017-04-26 14:57:32 +02:00
2020-12-05 15:47:00 +01:00
Model . Textbausteine = textbausteine . Where ( w = > ( w . ServiceCategory = = null | | w . ServiceCategory . ServiceCategoryOid = = pServiceCategoryOid ) & & ! String . IsNullOrEmpty ( w . Text ) ) . 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-11-09 17:55:01 +01:00
var newItems = Model . Textbausteine . Where ( tb = > tb . TextModuleOid . HasValue ) . Select ( tb = > new TextbausteinDisplayItem ( tb . Name , tb . Text , tb . Parent ? . TextModuleOid , tb . TextModuleOid . Value , tb . IsExpanded ) ) . ToList ( ) ;
foreach ( var item in newItems )
{
if ( item . ParentOid ! = null )
{
var parent = newItems . FirstOrDefault ( p = > p . Oid = = item . ParentOid ) ;
parent ? . Children . AddIfNotIn ( item ) ;
}
}
2020-11-20 23:28:09 +01:00
var test = newItems . Where ( item = > item . ParentOid = = null ) . ToList ( ) ;
2020-11-09 17:55:01 +01:00
2020-11-20 23:28:09 +01:00
if ( test . Count = = 0 )
2018-01-29 12:57:10 +01:00
{
2020-11-20 23:28:09 +01:00
return _LeerzeichenFuerGetMethoden ;
}
2020-02-10 12:02:59 +01:00
2020-11-20 23:28:09 +01:00
_TextModuleTreeHtml = "<div class=\"list-group\">" ;
2020-02-10 12:02:59 +01:00
2020-11-20 23:28:09 +01:00
foreach ( var item in test )
{
BuildTextModuleTreeBranch ( item ) ;
2018-01-29 12:57:10 +01:00
}
2020-11-20 23:28:09 +01:00
_TextModuleTreeHtml + = "</div>" ;
2018-01-29 12:57:10 +01:00
2020-11-20 23:28:09 +01:00
return _TextModuleTreeHtml ;
2018-04-27 14:11:21 +02:00
}
catch ( Exception exception )
{
Debug . WriteLine ( exception ) ;
throw ;
}
2017-04-26 14:57:32 +02:00
}
2020-11-20 23:28:09 +01:00
private string _TextModuleTreeHtml = "" ;
private void BuildTextModuleTreeBranch ( TextbausteinDisplayItem textModuleItem )
{
if ( textModuleItem . IsParent )
{
_TextModuleTreeHtml + = $"<a href=\" # \ " class=\"list-group-item list-group-item-action mx-0 px-1\" onclick=\"textCategoryOnClick('{textModuleItem.Oid}')\">" +
$"<span id=\" { textModuleItem . Oid } - icon - span \ " class=\"fas fa-angle-up mr-1\"></span>" +
$"{textModuleItem.Name}" +
"</a>" +
$"<div id=\" { textModuleItem . Oid } - children - container \ " style=\"display: none;\" class=\"list-group list-group-item mx-0 px-1\">" ;
foreach ( var child in textModuleItem . Children )
{
BuildTextModuleTreeBranch ( child ) ;
}
_TextModuleTreeHtml + = "</div>" ;
}
else
{
_TextModuleTreeHtml + = $"<a href=\" # \ " id=\"{textModuleItem.Oid}\" class=\"list-group-item list-group-item-action mx-0 px-1\" onclick=\"textModuleOnClick('{textModuleItem.Oid}')\">{textModuleItem.Name}</a>" ;
}
}
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 )
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
2018-12-13 20:59:05 -04:00
return _LeerzeichenFuerGetMethoden ;
2018-12-10 23:40:38 -04:00
}
2020-04-02 13:19:14 +02:00
var textModule = Model . Textbausteine . FirstOrDefault ( f = > f . TextModuleOid . HasValue & & f . TextModuleOid . Value = = pTextbausteinOid ) ;
2017-04-26 14:57:32 +02:00
2020-04-02 13:19:14 +02:00
return textModule = = null ? null : string . IsNullOrWhiteSpace ( textModule . Text ) ? textModule . Name : textModule . Text ;
2017-04-26 14:57:32 +02:00
}
2016-06-27 01:45:38 +02:00
2020-04-08 14:44:20 +02:00
[HttpPost]
[Authorize]
public ActionResult CreateOrUpdateServiceRecord ( FormCollection collection )
{
try
{
if ( Model = = null )
{
2020-10-07 19:42:17 +02:00
return Logout ( ) ;
2020-04-08 14:44:20 +02:00
}
string doku1 ;
2020-11-09 17:55:01 +01:00
if ( Model . Dokutypes ! = null & & Model . Dokutypes . Length > 0 )
2020-04-08 14:44:20 +02:00
{
2020-09-21 11:57:10 +02:00
doku1 = collection [ FormCollectionConstants . Dokumentation1Key ] ;
2020-04-08 14:44:20 +02:00
}
else
{
2020-09-21 11:57:10 +02:00
doku1 = collection [ FormCollectionConstants . Dokumentation6Key ] ;
2020-04-08 14:44:20 +02:00
}
2020-09-21 11:57:10 +02:00
Log . Info ( $"CreateOrUpdateServiceRecord: datum:{collection[FormCollectionConstants.DateKey]}; start:{collection[FormCollectionConstants.StartKey]}; ende:{collection[FormCollectionConstants.EndKey]}; dauer:{collection[FormCollectionConstants.DurationKey]}; doku:{doku1}; aktion:{(Model.IsInEditingMode ? " Speichern " : " Anlegen ")}" ) ;
2020-04-08 14:44:20 +02:00
2020-09-21 11:57:10 +02:00
if ( string . IsNullOrEmpty ( collection [ FormCollectionConstants . DateKey ] ) )
2020-04-08 14:44:20 +02:00
{
return View ( "Main" , Model ) ;
}
2020-09-21 11:57:10 +02:00
var distanz = collection [ FormCollectionConstants . DistanceKey ] ;
2020-04-08 14:44:20 +02:00
var distanceInMeters = 0 ;
if ( ! string . IsNullOrEmpty ( distanz ) )
{
if ( int . TryParse ( distanz , out var parsedDistance ) )
{
distanceInMeters = parsedDistance ;
}
}
var selectedCostbearerSCRelOid = Model . CostBearer2SupportConceptOid < 1 ? null : Model . CostBearer2SupportConceptOid ;
2020-09-21 11:57:10 +02:00
var datum = Convert . ToDateTime ( collection [ FormCollectionConstants . DateKey ] ) ;
2020-04-08 14:44:20 +02:00
var enddatum = datum ;
2020-09-21 11:57:10 +02:00
var start = collection [ FormCollectionConstants . StartKey ] ;
var ende = collection [ FormCollectionConstants . EndKey ] ;
2020-04-08 14:44:20 +02:00
var dauer = 0 ;
if ( datum > enddatum )
{
enddatum = datum ;
}
2020-09-21 11:57:10 +02:00
if ( ! string . IsNullOrEmpty ( collection [ FormCollectionConstants . DurationKey ] ) )
2020-04-08 14:44:20 +02:00
{
2020-09-21 11:57:10 +02:00
int . TryParse ( collection [ FormCollectionConstants . DurationKey ] , out dauer ) ;
2020-04-08 14:44:20 +02:00
}
2020-09-21 11:57:10 +02:00
var doku2 = collection [ FormCollectionConstants . Dokumentation2Key ] ;
var doku3 = collection [ FormCollectionConstants . Dokumentation3Key ] ;
var doku4 = collection [ FormCollectionConstants . Dokumentation4Key ] ;
var doku5 = collection [ FormCollectionConstants . Dokumentation5Key ] ;
2020-04-08 14:44:20 +02:00
var zeitenFeld = new DateTime [ 2 ] ;
if ( start = = string . Empty & & ende = = string . Empty )
{
zeitenFeld [ 0 ] = new DateTime ( datum . Year , datum . Month , datum . Day , 0 , 0 , 1 ) ;
if ( enddatum = = datum )
{
zeitenFeld [ 1 ] = new DateTime ( datum . Year , datum . Month , datum . Day , 0 , 0 , 1 ) . AddMinutes ( dauer ) ;
}
else
{
zeitenFeld [ 1 ] = new DateTime ( enddatum . Year , enddatum . Month , enddatum . Day , 0 , 0 , 1 ) . AddMinutes ( dauer ) ;
}
}
else
{
zeitenFeld = enddatum = = datum ? ConvertRecordTimes ( start , ende , datum , dauer ) : ConvertRecordTimesWithEndDate ( start , ende , datum , enddatum , dauer ) ;
}
if ( dauer = = 0 | | zeitenFeld [ 1 ] ! = zeitenFeld [ 0 ] )
{
dauer = ( int ) ( zeitenFeld [ 1 ] - zeitenFeld [ 0 ] ) . TotalMinutes ;
}
if ( Model . IsInEditingMode )
{
var selectedRecordOid = Model . SelectedServiceRecordOid ? ? Model . SelectedServiceRecord . ServiceRecordOid ;
Model . NewServiceRecord = OperationsService . GetServiceRecordById ( selectedRecordOid . Value ) ;
}
if ( Model . NewServiceRecord = = null )
{
return RedirectToActionPermanent ( "Main" ) ;
}
Model . NewServiceRecord . IP = Request . UserHostAddress ;
Model . NewServiceRecord . Goals = Model . SelectedGoals ;
Model . NewServiceRecord . Start = zeitenFeld [ 0 ] ;
Model . NewServiceRecord . End = zeitenFeld [ 1 ] ;
Model . NewServiceRecord . DistanceInMeter = distanceInMeters ;
if ( Model . Employee . EmployeeOid ! = null )
{
if ( ! Model . IsInEditingMode )
{
Model . NewServiceRecord . Employee = Model . SelectedEmployee ? ? MobileSessionFacade . LoggedInCompactEmployee ;
}
else
{
if ( Model . SelectedEmployee ! = null )
{
Model . NewServiceRecord . Employee = Model . SelectedEmployee ;
}
}
var sc = Model . SupportConcepts . FirstOrDefault ( fod = > fod . CostBearerRelations . Any ( a = > a . CostBearer2SupportConceptOid . HasValue & & a . CostBearer2SupportConceptOid . Value . Equals ( selectedCostbearerSCRelOid ) ) ) ;
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 )
{
Model . NewServiceRecord . RoundedDuration = dauer % intervall ! = 0 ? dauer + ( intervall - dauer % intervall ) : dauer ;
}
else
{
Model . NewServiceRecord . RoundedDuration = dauer ;
}
Model . NewServiceRecord . CostBearer2SupportConceptOid = selectedCostbearerSCRelOid ;
}
else
{
Model . NewServiceRecord . RoundedDuration = dauer ;
}
}
Model . NewServiceRecord . DurationInStunden = ZeiterfassungsDauer . Minuten ;
Model . NewServiceRecord . ServiceRecordFormat = ServiceRecordFormate . OriginaleZeiterfassung ;
Model . NewServiceRecord . Notice = string . IsNullOrEmpty ( doku1 ) ? null : doku1 ;
Model . NewServiceRecord . Notice2 = string . IsNullOrEmpty ( doku2 ) ? null : doku2 ;
Model . NewServiceRecord . Notice3 = string . IsNullOrEmpty ( doku3 ) ? null : doku3 ;
Model . NewServiceRecord . Notice4 = string . IsNullOrEmpty ( doku4 ) ? null : doku4 ;
Model . NewServiceRecord . Notice5 = string . IsNullOrEmpty ( doku5 ) ? null : doku5 ;
var serviceDescOid = 0L ;
2020-09-21 11:57:10 +02:00
if ( ! string . IsNullOrEmpty ( collection [ FormCollectionConstants . ServiceDescriptionKey ] ) )
2020-04-08 14:44:20 +02:00
{
2020-09-21 11:57:10 +02:00
serviceDescOid = Convert . ToInt64 ( collection [ FormCollectionConstants . ServiceDescriptionKey ] ) ;
2020-04-08 14:44:20 +02:00
}
else if ( Model . SelectedServiceDescriptionOid . HasValue )
{
serviceDescOid = Model . SelectedServiceDescriptionOid . Value ;
}
if ( serviceDescOid > 0 )
{
Model . NewServiceRecord . ServiceDescription = OperationsService . GetServiceDescription ( serviceDescOid ) ;
}
if ( Model . NewServiceRecord . RoundedDuration = = 0 )
{
Model . NewServiceRecord . RoundedDuration = dauer ;
}
Model . NewServiceRecord . IP = Request . UserHostAddress ;
Model . NewServiceRecord . InsertedOn = DateTime . Now ;
Model . NewServiceRecord . InsUser = $"{MobileSessionFacade.LoggedInEmployee.FirstName} {MobileSessionFacade.LoggedInEmployee.LastName}" ;
Model . NewServiceRecord . IsCreatedInMobileClient = true ;
if ( Model . IsInGroupBookingMode & & Model . SelectedSupportConcepts . Count > 1 )
{
return Model . NewServiceRecord . ServiceRecordOid . HasValue ? SaveGroupBooking ( ) : UpdateGroupBooking ( ) ;
}
if ( ! Model . IsInEditingMode )
{
var oidList = OperationsService . InsertNewServiceRecords ( new List < ServiceRecordDC > { Model . NewServiceRecord } ) ;
Model . ServiceRecordOid = oidList [ 0 ] ;
2020-11-11 14:21:29 +01:00
2021-01-14 20:39:33 +01:00
if ( Model . NewServiceRecord . CostBearer ! = null & & Model . ShowSignature )
2020-11-11 14:21:29 +01:00
{
TempData [ FormCollectionConstants . ShowSignatureSuggestionPopup ] = true ;
}
2020-04-08 14:44:20 +02:00
}
else
{
OperationsService . UpdateServiceRecords ( 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 )
{
Log . Error ( e . Message , e ) ;
}
2020-12-07 13:08:55 +01:00
ResetGroupBookingMode ( Model . IsInGroupBookingMode ) ;
2020-11-20 23:28:09 +01:00
2020-12-16 21:49:47 +01:00
return ResetEditingMode ( ) ;
2020-04-08 14:44:20 +02:00
}
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 ;
2020-04-08 14:44:20 +02: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
2020-04-02 13:19:14 +02:00
var list = CalculateGroupBookingDuration ( employeeCount , personCount , cb2ScOids ) ;
2018-04-27 14:11:21 +02:00
var newDCList = new List < ServiceRecordDC > ( ) ;
foreach ( var dc in list )
{
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 ) ;
}
}
2020-12-16 21:49:47 +01:00
return ResetEditingMode ( ) ;
2018-04-27 14:11:21 +02:00
}
2020-12-07 13:08:55 +01:00
2018-04-27 14:11:21 +02:00
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 ;
2020-04-02 13:19:14 +02:00
var cb2ScOids = new List < long > ( ) ;
2018-04-27 14:11:21 +02:00
foreach ( var scdc in Model . SelectedSupportConcepts )
{
if ( scdc . CostBearerRelations . Count > 0 )
{
2020-04-02 13:19:14 +02:00
cb2ScOids . Add ( scdc . CostBearerRelations . ElementAt ( 0 ) . CostBearer2SupportConceptOid . Value ) ;
2018-04-27 14:11:21 +02:00
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 ;
2020-04-02 13:19:14 +02:00
var gd = OperationsService . CalculateGroupDuration2 ( customerCount , employeeCount , duration , cb2ScOids . ToArray ( ) ) ;
2018-04-27 14:11:21 +02:00
if ( gd ! = null )
{
groupDuration = gd . TotalDuration ;
roundedDuration = gd . SingleDuration ;
}
else
{
if ( minuteInterval > 0 & & roundDuration )
{
lRoundedDuration = duration % minuteInterval ! = 0 ? duration + ( minuteInterval - duration % minuteInterval ) : duration ;
}
groupDuration = lRoundedDuration ;
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
2020-12-16 21:49:47 +01:00
return ResetEditingMode ( ) ;
2018-04-27 14:11:21 +02:00
}
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
}
}
2020-04-02 13:19:14 +02:00
[HttpPost]
2018-02-07 14:14:08 +01:00
[Authorize]
2020-04-02 13:19:14 +02:00
public ActionResult SelectSupportConcept ( FormCollection formCollection )
2016-06-27 01:45:38 +02:00
{
2020-04-02 13:19:14 +02:00
if ( Model = = null )
2016-06-27 01:45:38 +02:00
{
2020-10-07 19:42:17 +02:00
return Logout ( ) ;
2020-04-02 13:19:14 +02:00
}
2016-06-27 01:45:38 +02:00
2020-09-21 11:57:10 +02:00
long? cb2ScOid = Convert . ToInt64 ( formCollection [ FormCollectionConstants . CostBearer2SupportConceptOidKey ] ) ;
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
LoadServiceCategoriesToModel ( cb2ScOid ) ;
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
Model . Zeitraum = 7 ;
LoadRecordsToModel ( ) ;
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
LoadGoalTreeItems ( ) ;
2016-06-27 01:45:38 +02:00
2020-12-16 21:49:47 +01:00
return ResetEditingMode ( ) ;
2020-04-02 13:19:14 +02:00
}
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
private void LoadServiceCategoriesToModel ( long? cb2ScOid )
{
2020-08-04 12:45:46 +02:00
if ( cb2ScOid = = null & & Model . IsInGroupBookingMode )
{
Model . ServiceCategories = CreateServiceCategoryModels ( OperationsService . GetAllServiceDescriptions ( ) ) ;
return ;
}
2020-04-02 13:19:14 +02:00
Model . CostBearer2SupportConceptOid = cb2ScOid ;
Model . SelectedSupportConcept =
Model . SupportConcepts . FirstOrDefault (
f = >
f . CostBearerRelations . Any (
a = >
a . CostBearer2SupportConceptOid . HasValue & &
a . CostBearer2SupportConceptOid . Value . Equals ( Model . CostBearer2SupportConceptOid ) ) ) ;
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
if ( Model . SelectedSupportConcept ! = null )
{
Model . SelectedSupportConceptListObject = Model . SupportConceptListObjects . First ( f = > long . Parse ( f . CostBearer2SupportConceptOid ) = = cb2ScOid ) ;
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
var details = OperationsService . GetSupportConceptTreeNodeDetailInfo ( Model . SelectedSupportConcept . Customer . CustomerOid , Model . SelectedSupportConcept . SupportConceptOid , Model . CostBearer2SupportConceptOid ) ;
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
Model . ServiceCategories = details . ServiceAccountings . Count > 0
? CreateServiceCategoryModels ( details . ServiceAccountings . Select ( sa = > sa . ServiceDescription ) . ToList ( ) )
: CreateServiceCategoryModels ( OperationsService . GetAllServiceDescriptions ( ) ) ;
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
Model . ServiceCategories = Model . ServiceCategories . Where ( c = > ! c . OhneHilfeplan . HasValue | | c . OhneHilfeplan . Value = = AccountingvisibilityType . Beides | | c . OhneHilfeplan . Value = = AccountingvisibilityType . NurKlientenbezogen ) . ToList ( ) ;
2016-06-27 01:45:38 +02:00
}
2020-04-02 13:19:14 +02:00
else if ( cb2ScOid = = - 2 )
2016-06-27 01:45:38 +02:00
{
2020-04-02 13:19:14 +02:00
Model . SelectedSupportConceptListObject = Model . SupportConceptListObjects . First ( f = > f . CostBearer2SupportConceptOid . Equals ( cb2ScOid . ToString ( ) ) ) ;
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 ( ) ;
2016-06-27 01:45:38 +02:00
}
2020-04-02 13:19:14 +02:00
else if ( cb2ScOid = = - 1 )
2019-07-19 17:13:57 +02:00
{
2020-04-02 13:19:14 +02:00
Model . SelectedSupportConceptListObject = Model . SupportConceptListObjects . First ( f = > f . CostBearer2SupportConceptOid . Equals ( cb2ScOid . ToString ( ) ) ) ;
2019-07-19 17:13:57 +02:00
Model . ServiceCategories . Clear ( ) ;
2020-04-02 13:19:14 +02:00
}
2020-07-13 16:25:43 +02:00
if ( Model . ServiceCategories ! = null )
{
Model . ServiceCategories = Model . ServiceCategories . OrderBy ( serviceCategory = > serviceCategory . Position ) . ToList ( ) ;
}
2020-04-02 13:19:14 +02:00
}
2016-06-27 01:45:38 +02:00
[HttpPost]
[Authorize]
2018-11-30 16:47:57 -04:00
public ActionResult DeleteServiceRecord ( FormCollection formCollection )
2016-06-27 01:45:38 +02:00
{
if ( Model = = null )
{
2020-10-07 19:42:17 +02:00
return Logout ( ) ;
2016-06-27 01:45:38 +02:00
}
2020-09-21 11:57:10 +02:00
Model . ServiceRecordOidToDelete = long . Parse ( formCollection [ FormCollectionConstants . ServiceRecordOidHolderKey ] ) ;
2018-11-30 16:47:57 -04:00
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
}
}
2020-12-16 21:49:47 +01:00
ResetEditingMode ( ) ;
2018-11-30 16:47:57 -04:00
2018-05-22 17:19:56 +02:00
return RedirectToActionPermanent ( "Main" ) ;
2016-06-27 01:45:38 +02:00
}
2019-07-19 17:13:57 +02:00
public string UpdateGoals ( string pGoalOids )
2016-06-27 01:45:38 +02:00
{
if ( Model = = null )
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
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 ;
}
2020-04-02 13:19:14 +02:00
var splitOids = pGoalOids . Trim ( ';' ) . Split ( ';' ) ;
2019-07-19 17:13:57 +02:00
var selectedGoalOids = splitOids . Select ( long . Parse ) . ToList ( ) ;
2016-06-27 01:45:38 +02:00
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 )
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
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 )
{
2020-10-07 19:42:17 +02:00
return Logout ( ) ;
2016-06-27 01:45:38 +02:00
}
2020-09-21 11:57:10 +02:00
var zeitraum = int . Parse ( formCollection [ FormCollectionConstants . RecordsKey ] ) ;
2016-06-27 01:45:38 +02:00
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 )
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
2018-12-10 23:40:38 -04:00
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 ) ;
}
2020-08-04 12:45:46 +02:00
Model . ServiceRecords = recordsOhneDuplikate . Where ( serviceRecord = > serviceRecord . Start . HasValue & & serviceRecord . End . HasValue )
. OrderBy ( serviceRecord = > serviceRecord . Start . Value . Date )
. ThenBy ( serviceRecord = > serviceRecord . Start . Value . Hour )
. ThenBy ( serviceRecord = > serviceRecord . Start . Value . Minute )
. ThenBy ( serviceRecord = > serviceRecord . End . Value . Date )
. ThenBy ( serviceRecord = > serviceRecord . End . Value . Hour )
2020-11-09 17:55:01 +01:00
. ThenBy ( serviceRecord = > serviceRecord . End . Value . Minute )
. ThenByDescending ( serviceRecord = > serviceRecord . InsertedOn . Value ) . ToList ( ) ;
2016-06-27 01:45:38 +02:00
}
2020-04-02 13:19:14 +02:00
[HttpPost]
[Authorize]
public ActionResult SelectRecordToEdit ( FormCollection formCollection )
2016-06-27 01:45:38 +02:00
{
2020-04-02 13:19:14 +02:00
if ( Model = = null )
2016-06-27 01:45:38 +02:00
{
2020-10-07 19:42:17 +02:00
return Logout ( ) ;
2016-06-27 01:45:38 +02:00
}
2020-09-21 11:57:10 +02:00
var oidString = formCollection [ FormCollectionConstants . ServiceRecordOidHolder2Key ] ;
2018-12-13 20:59:05 -04:00
2020-04-02 13:19:14 +02:00
var wasSuccessful = long . TryParse ( oidString , out var serviceRecordOid ) ;
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
if ( ! wasSuccessful )
2018-04-18 14:33:21 +02:00
{
2020-04-02 13:19:14 +02:00
RedirectToActionPermanent ( "Main" ) ;
2018-04-18 14:33:21 +02:00
}
2020-04-02 13:19:14 +02:00
Model . SelectedServiceRecordOid = serviceRecordOid ;
2018-04-27 14:11:21 +02:00
2020-04-02 13:19:14 +02:00
var selectedServiceRecord = OperationsService . GetServiceRecordById ( serviceRecordOid ) ;
2018-04-18 14:33:21 +02:00
2020-04-02 13:19:14 +02:00
Model . SelectedServiceRecord = selectedServiceRecord ;
Model . SelectedGoals = selectedServiceRecord . Goals ;
2018-04-18 14:33:21 +02:00
2020-04-02 13:19:14 +02:00
Model . SelectedServiceDescriptionOid = selectedServiceRecord . ServiceDescription . ServiceDescriptionOid ;
Model . SelectedServiceCategoryOid = selectedServiceRecord . ServiceDescription . Category . ServiceCategoryOid ;
2018-11-30 16:47:57 -04:00
2020-12-16 21:49:47 +01:00
Model . PreviouslySelectedEmployee = Model . SelectedEmployee ;
2020-04-02 13:19:14 +02:00
Model . SelectedEmployee = selectedServiceRecord . Employee ;
2018-04-18 14:33:21 +02:00
2020-04-02 13:19:14 +02:00
Model . IsInEditingMode = true ;
2018-04-18 14:33:21 +02:00
2020-12-16 21:49:47 +01:00
Model . PreviouslySelectedSupportConcept = Model . SelectedSupportConcept ;
2020-04-02 13:19:14 +02:00
if ( selectedServiceRecord . GroupOid . HasValue )
{
Model . IsInGroupBookingMode = true ;
2018-04-18 14:33:21 +02:00
2020-04-02 13:19:14 +02:00
Model . SelectedSupportConcept = null ;
Model . SelectedEmployee = null ;
2018-04-18 14:33:21 +02:00
2020-04-02 13:19:14 +02:00
Model . ServiceCategories = CreateServiceCategoryModels ( OperationsService . GetAllServiceDescriptions ( ) ) ;
2018-04-18 14:33:21 +02:00
2020-04-02 13:19:14 +02:00
var group = OperationsService . GetServiceRecordGroup ( selectedServiceRecord . GroupOid . Value ) ;
2020-12-01 12:29:12 +01:00
var employees = group . ServiceRecordList . Select ( serviceRecord = > serviceRecord . Employee ) . Distinct ( ) . ToList ( ) ;
Model . SelectedEmployees = employees ;
2020-04-02 13:19:14 +02:00
var cb2ScOids = group . ServiceRecordList . Where ( w = > w . CostBearer2SupportConceptOid . HasValue ) . Select ( s = > s . CostBearer2SupportConceptOid . Value ) . ToList ( ) ;
2018-04-18 14:33:21 +02:00
2020-04-02 13:19:14 +02:00
Model . SelectedConceptCostBearerRelations . AddRangeIfElementsNotIn ( OperationsService . GetSupportConceptCostBearerRelDCsByOids ( cb2ScOids ) ) ;
2020-11-20 23:28:09 +01:00
var selectedSupportConcepts = new List < SupportConceptDC > ( ) ;
selectedSupportConcepts . AddRangeIfElementsNotIn ( OperationsService . GetSupportConceptsById ( group . ServiceRecordList . Select ( s = > s . SupportConcept . SupportConceptOid ) ) ) ;
Model . SelectedSupportConcepts = selectedSupportConcepts ;
2020-04-02 13:19:14 +02:00
}
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 )
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
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 )
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
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 )
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
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 ) ;
}
2020-04-02 13:19:14 +02:00
var checkServiceRecord = new ServiceRecordDC ( ) ;
2016-06-27 01:45:38 +02:00
if ( inEditMode )
{
2020-04-02 13:19:14 +02:00
checkServiceRecord = Model . ServiceRecords . FirstOrDefault ( f = > f . ServiceRecordOid . HasValue & & f . ServiceRecordOid . Value . Equals ( Model . SelectedServiceRecordOid ) ) ;
2016-06-27 01:45:38 +02:00
}
2020-04-02 13:19:14 +02:00
if ( checkServiceRecord = = null )
2016-06-27 01:45:38 +02:00
{
2020-04-02 13:19:14 +02:00
checkServiceRecord = new ServiceRecordDC ( ) ;
2016-06-27 01:45:38 +02:00
}
2020-04-02 13:19:14 +02:00
checkServiceRecord . Goals = Model . SelectedGoals ;
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
checkServiceRecord . Start = startDt ;
checkServiceRecord . End = endDt ;
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
checkServiceRecord . IP = Request . UserHostAddress ;
2018-12-10 23:40:38 -04:00
2020-04-02 13:19:14 +02:00
checkServiceRecord . ServiceDescription = OperationsService . GetServiceDescription ( Model . SelectedServiceDescriptionOid . Value ) ;
2018-12-10 23:40:38 -04:00
2020-04-02 13:19:14 +02:00
checkServiceRecord . Employee = Model . SelectedEmployee ? ? MobileSessionFacade . LoggedInCompactEmployee ;
2018-12-10 23:40:38 -04:00
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 )
{
2020-04-02 13:19:14 +02:00
checkServiceRecord . SupportConcept = CustomerService . LoadCompactSupportConceptDC ( sc . SupportConceptOid . Value , Model . Employee . EmployeeOid ) ;
2016-06-27 01:45:38 +02:00
}
2020-04-02 13:19:14 +02:00
checkServiceRecord . Customer = sc . Customer ;
2016-06-27 01:45:38 +02:00
var cb2ScRel = sc . CostBearerRelations . First ( f = > f . CostBearer2SupportConceptOid . HasValue & & f . CostBearer2SupportConceptOid . Equals ( Model . CostBearer2SupportConceptOid ) ) ;
2020-04-02 13:19:14 +02:00
checkServiceRecord . CostBearer = cb2ScRel . CostBearer ;
var intervall = checkServiceRecord . CostBearer . ActualMinuteIntervall ;
2016-06-27 01:45:38 +02:00
if ( intervall > 0 )
{
2020-04-02 13:19:14 +02:00
checkServiceRecord . RoundedDuration = dauer % intervall ! = 0 ? dauer + ( intervall - dauer % intervall ) : dauer ;
2016-06-27 01:45:38 +02:00
}
2020-04-02 13:19:14 +02:00
checkServiceRecord . CostBearer2SupportConceptOid = Model . CostBearer2SupportConceptOid ;
2016-06-27 01:45:38 +02:00
}
}
2020-08-04 12:45:46 +02:00
var mandator = GetMandator ( ) ;
2020-04-08 14:44:20 +02:00
var maxDaysEditSRsAllowedString = GetSettingValue ( mandator . Settings , "MaxDaysEditServiceRecordsAllowed" ) ;
var limitFuerZeiterfassungString = GetSettingValue ( mandator . Settings , "AnzTageZeiterfassErfolgt" ) ;
var isSuccessful1 = int . TryParse ( maxDaysEditSRsAllowedString , out var maxDaysEditSRsAllowed ) ;
if ( ! isSuccessful1 )
{
maxDaysEditSRsAllowed = 0 ;
}
var isSuccessful2 = int . TryParse ( limitFuerZeiterfassungString , out var limitFuerZeiterfassung ) ;
if ( ! isSuccessful2 )
{
limitFuerZeiterfassung = 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 ) ;
}
2020-04-02 13:19:14 +02:00
var employees = new List < long > { checkServiceRecord . Employee . EmployeeOid } ;
2018-11-30 16:47:57 -04:00
2018-12-10 23:40:38 -04:00
var validationResults = new List < ServiceRecord2Validation > ( ) ;
2020-04-02 13:19:14 +02:00
checkServiceRecord . ServiceRecordFormat = ServiceRecordFormate . OriginaleZeiterfassung ;
checkServiceRecord . 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
{
2020-04-02 13:19:14 +02:00
if ( checkServiceRecord . GroupOid . HasValue )
2018-11-30 16:47:57 -04:00
{
2020-04-02 13:19:14 +02:00
var serviceRecordGroup = OperationsService . GetServiceRecordGroup ( checkServiceRecord . GroupOid . Value ) ;
2018-11-30 16:47:57 -04:00
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
2020-11-09 17:55:01 +01:00
var cb2ScOids = Model . SelectedConceptCostBearerRelations . Where ( w = > w . CostBearer2SupportConceptOid . HasValue ) . Select ( s = > s . CostBearer2SupportConceptOid . Value ) . ToList ( ) ;
2018-11-30 16:47:57 -04:00
2020-04-02 13:19:14 +02: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
{
2020-04-02 13:19:14 +02:00
var sr = CloneServiceRecordForGroupBooking ( checkServiceRecord ) ;
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
2020-04-02 13:19:14 +02:00
var result = OperationsService . ValidateServiceRecord ( sr , null , maxDaysEditSRsAllowed , employees , cb2ScOids ) ;
2018-12-10 23:40:38 -04:00
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
2020-04-02 13:19:14 +02:00
var result = OperationsService . ValidateServiceRecordEntry ( checkServiceRecord , stats , maxDaysEditSRsAllowed , checkServiceRecord . GroupOid . HasValue , employees ) ;
validationResults . Add ( new ServiceRecord2Validation ( checkServiceRecord , 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 ) ;
2020-04-02 13:19:14 +02:00
var bookServiceRecordOutOfSupportConcept = MobileSessionFacade . CheckForUserRight ( UserRightType . BookServiceRecordOutOfSupportConcept ) ;
2020-10-20 21:07:26 +02:00
var allowCreateAfterEmployeeSignature = MobileSessionFacade . CheckForUserRight ( UserRightType . ServiceRecord_AllowCreateAfterEmployeeSignature ) ;
var allowEditAfterEmployeeSignature = MobileSessionFacade . CheckForUserRight ( UserRightType . ServiceRecord_AllowEditAfterEmployeeSignature ) ;
var allowCreateAll = MobileSessionFacade . CheckForUserRight ( UserRightType . CreateAll ) ;
var allowEditAll = MobileSessionFacade . CheckForUserRight ( UserRightType . CreateAll ) ;
2020-10-01 11:45:48 +02:00
2018-12-10 23:40:38 -04:00
var newResult = new ValidationResult ( ) ;
2019-03-29 14:04:12 +01:00
var exitLoop = false ;
2020-10-20 21:07:26 +02:00
if ( Model . SelectedSupportConcept ! = null & & Model . SelectedSupportConcept . Goals . Any ( ) & & Model . SelectedGoals . Count = = 0 )
{
2020-11-09 17:55:01 +01:00
newResult . Message + = "Es wurden keine Ziele zugeordnet.<br/><br/>" ;
newResult . KannTrotzdemGespeichertWerden = true ;
exitLoop = false ;
2020-10-20 21:07:26 +02:00
}
2020-04-02 13:19:14 +02:00
foreach ( var sr2V in validationResults )
2018-12-10 23:40:38 -04:00
{
if ( exitLoop )
{
break ;
}
2020-04-02 13:19:14 +02:00
foreach ( var vr in sr2V . ValidationResults )
2018-12-10 23:40:38 -04:00
{
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 :
2020-04-02 13:19:14 +02:00
newResult . Message + = "Das gewählte Datum " + von . Substring ( 0 , 10 ) + " liegt außerhalb des Zeitraumes des gewählten Hilfeplans (" + sr2V . HilfePlanZeitraum + ").<br /><br />" ;
newResult . KannTrotzdemGespeichertWerden = bookServiceRecordOutOfSupportConcept ;
2019-03-29 14:04:12 +01:00
2020-04-02 13:19:14 +02:00
exitLoop = ! bookServiceRecordOutOfSupportConcept ;
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 ;
2020-10-20 21:07:26 +02:00
break ;
case HasEmployeeSignature :
if ( checkServiceRecord . ServiceRecordOid . HasValue )
{
if ( ! allowEditAll & & ! allowEditAfterEmployeeSignature )
{
newResult . Message + = "Sie können den Eintrag nicht speichern, da bereits eine Mitarbeiterunterschrift geleistet wurde.<br/><br/>" ;
exitLoop = true ;
newResult . KannTrotzdemGespeichertWerden = false ;
}
else
{
newResult . Message + = "Es existiert bereits eine Mitarbeiterunterschrift. Möchten Sie trotzdem speichern?<br/><br/>" ;
exitLoop = false ;
newResult . KannTrotzdemGespeichertWerden = true ;
}
}
else
{
if ( ! allowCreateAll & & ! allowCreateAfterEmployeeSignature )
{
newResult . Message + = "Sie können den Eintrag nicht speichern, da bereits eine Mitarbeiterunterschrift geleistet wurde.<br/><br/>" ;
exitLoop = true ;
newResult . KannTrotzdemGespeichertWerden = false ;
}
else
{
newResult . Message + = "Es existiert bereits eine Mitarbeiterunterschrift. Möchten Sie trotzdem speichern?<br/><br/>" ;
exitLoop = false ;
newResult . KannTrotzdemGespeichertWerden = true ;
}
}
2018-12-10 23:40:38 -04:00
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
}
2020-10-20 21:07:26 +02:00
[Authorize]
public string ValidateServiceRecordDeletion ( string serviceRecordOidString )
{
if ( Model = = null )
{
Logout ( ) ;
return _LeerzeichenFuerGetMethoden ;
}
var isSuccessful = long . TryParse ( serviceRecordOidString , out var serviceRecordOid ) ;
if ( ! isSuccessful )
{
return "Error" ;
}
var newResult = new ValidationResult ( ) ;
var serviceRecord = OperationsService . GetServiceRecordById ( serviceRecordOid ) ;
var allowDeleteAfterEmployeeSignature = MobileSessionFacade . CheckForUserRight ( UserRightType . ServiceRecord_AllowDeleteAfterEmployeeSignature ) ;
var allowDeleteAll = MobileSessionFacade . CheckForUserRight ( UserRightType . CreateAll ) ;
var validationResultList = OperationsService . ValidateServiceRecordDeletion ( serviceRecord , Model . Employee . EmployeeOid . Value ) ;
if ( validationResultList . Count > 0 )
{
var exitLoop = false ;
foreach ( var result in validationResultList )
{
switch ( result . ResultType )
{
case Custom :
newResult . KannTrotzdemGespeichertWerden = true ;
newResult . Message + = "Dieser Eintrag wurde bereits unterschrieben.<br/>Möchten Sie ihn trotzdem löschen?<br/><br/>" ;
break ;
case HasEmployeeSignature :
if ( ! allowDeleteAll & & ! allowDeleteAfterEmployeeSignature )
{
exitLoop = true ;
newResult . KannTrotzdemGespeichertWerden = false ;
newResult . Message + = "Sie können den Eintrag nicht löschen, da bereits eine Mitarbeiterunterschrift geleistet wurde.<br/><br/>" ;
}
else
{
newResult . KannTrotzdemGespeichertWerden = true ;
newResult . Message + = "Es existiert bereits eine Mitarbeiterunterschrift.<br/>Möchten Sie ihn trotzdem löschen?<br/><br/>" ;
}
break ;
}
if ( exitLoop )
{
break ;
}
}
return SerializeObject ( newResult ) ;
}
2020-11-09 17:55:01 +01:00
return serviceRecord . GroupOid ! = null
2020-12-17 13:26:40 +01:00
? SerializeObject ( new ValidationResult { KannTrotzdemGespeichertWerden = true , Message = "ACHTUNG, wenn Sie fortfahren, löschen Sie die gesamte Gruppenbuchung.<br/>Wenn Sie nur einzelne Klienten aus der Gruppe entfernen möchten, editieren Sie die Gruppe und entfernen den Klienten aus der Liste der Hilfepläne.<br/>Sind Sie sicher, dass Sie den gesamten Gruppeneintrag löschen möchten?<br/><br/>" } )
2020-11-09 17:55:01 +01:00
: SerializeObject ( new ValidationResult { KannTrotzdemGespeichertWerden = true , Message = null } ) ;
2020-10-20 21:07:26 +02:00
}
2020-04-02 13:19:14 +02:00
public string SetServiceRecordEmployee ( long employeeOid )
2016-06-27 01:45:38 +02:00
{
2020-04-02 13:19:14 +02:00
try
2016-06-27 01:45:38 +02:00
{
2020-04-02 13:19:14 +02:00
if ( Model = = null )
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
2020-04-02 13:19:14 +02:00
return _LeerzeichenFuerGetMethoden ;
}
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
Model . SelectedEmployee = MainModel . AllEmployees . First ( f = > f . EmployeeOid . Equals ( employeeOid ) ) ;
return _LeerzeichenFuerGetMethoden ;
}
catch ( Exception e )
{
Log . Info ( "Error in SetServiceRecordEmployee:" ) ;
Log . Error ( e . Message , e ) ;
2020-04-24 19:08:09 +02:00
2020-04-02 13:19:14 +02:00
if ( MainModel . AllEmployees = = null )
{
Log . Info ( "Weitere Infos: AllEmployees = null!" ) ;
}
else
{
Log . Info ( $"Weitere Infos: AllEmployees enthält {MainModel.AllEmployees.Count} Elemente: " ) ;
2020-04-24 19:08:09 +02:00
var stringBuilder = new StringBuilder ( ) ;
2020-04-02 13:19:14 +02:00
foreach ( var ce in MainModel . AllEmployees )
{
2020-04-24 19:08:09 +02:00
if ( stringBuilder . Length > 0 )
2020-04-02 13:19:14 +02:00
{
2020-04-24 19:08:09 +02:00
stringBuilder . Append ( "," ) ;
2020-04-02 13:19:14 +02:00
}
2016-06-27 01:45:38 +02:00
2020-04-24 19:08:09 +02:00
stringBuilder . Append ( ce . EmployeeOid ) ;
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
}
2020-04-24 19:08:09 +02:00
Log . Info ( stringBuilder . ToString ( ) ) ;
2020-04-02 13:19:14 +02:00
}
2020-04-24 19:08:09 +02:00
2020-04-02 13:19:14 +02:00
throw e ;
2018-01-29 12:57:10 +01:00
}
2020-04-02 13:19:14 +02:00
}
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
public string CheckToken ( string token )
{
if ( token ! = null & & token . Equals ( "abcd" ) )
2018-01-29 12:57:10 +01:00
{
2020-04-02 13:19:14 +02:00
return SerializeObject ( "localhost;demo" ) ;
2018-01-29 12:57:10 +01:00
}
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
return _LeerzeichenFuerGetMethoden ;
}
2016-06-27 01:45:38 +02:00
2020-04-08 14:44:20 +02:00
// Menünavigation
2020-09-14 19:07:23 +02:00
[Authorize]
2020-04-02 13:19:14 +02:00
public ActionResult RedirectToScheduler ( )
{
return RedirectToActionPermanent ( "Scheduler" , "Scheduler" ) ;
}
2016-06-27 01:45:38 +02:00
2020-09-14 19:07:23 +02:00
[Authorize]
2020-04-02 13:19:14 +02:00
public ActionResult RedirectToCustomer ( )
{
if ( Model ? . SelectedSupportConcept ? . Customer ? . Oid . HasValue ? ? false )
2018-01-29 12:57:10 +01:00
{
2020-04-02 13:19:14 +02:00
return RedirectToActionPermanent ( "PreselectCustomer" , "Customer" , new { Model . SelectedSupportConcept . Customer . CustomerOid } ) ;
}
2016-06-27 01:45:38 +02:00
2020-09-21 11:57:10 +02:00
if ( Model ? . SelectedSupportConcept = = null & & ( CustomerModel ) Session [ ModelSessionConstants . CustomerModelKey ] ! = null )
2018-01-29 12:57:10 +01:00
{
2020-09-21 11:57:10 +02:00
var customerModel = ( CustomerModel ) Session [ ModelSessionConstants . CustomerModelKey ] ;
2020-04-02 13:19:14 +02:00
customerModel . SelectedCustomerOid = null ;
customerModel . SelectedCustomer = null ;
}
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
return RedirectToActionPermanent ( "Customer" , "Customer" ) ;
}
2016-06-27 01:45:38 +02:00
2020-09-14 19:07:23 +02:00
[Authorize]
public ActionResult RedirectToReportView ( )
{
2021-01-14 16:30:28 +01:00
return AbstractModel . IsAllowedToSeeBills ? RedirectToActionPermanent ( "InitReports" , "Report" ) : RedirectToMain ( ) ;
2020-09-14 19:07:23 +02:00
}
2020-04-02 13:19:14 +02:00
public ActionResult RedirectToMain ( )
{
return RedirectToActionPermanent ( "Main" , "Main" ) ;
}
2019-07-29 19:40:14 +02:00
2020-12-16 21:49:47 +01:00
[Authorize]
public ActionResult RedirectToDevelopment ( )
{
#if DEBUG
return RedirectToActionPermanent ( "Development" , "Development" ) ;
#endif
return RedirectToMain ( ) ;
}
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 )
{
2020-10-07 19:42:17 +02:00
return Logout ( ) ;
2018-12-03 19:14:35 -04:00
}
2020-09-21 11:57:10 +02:00
var isInGroupBookingMode = "true,false" = = pFormCollection [ FormCollectionConstants . IsInGroupBookingModeKey ] ;
2018-04-18 14:33:21 +02:00
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" ) ;
}
2020-08-04 12:45:46 +02:00
/// <summary>
/// Setzt die getroffenen Auswahlen zurück
/// </summary>
/// <param name="pIsInGroupBookingMode">
/// Wenn true, wird davon ausgegangen, dass man von der Einzelbuchung in eine Gruppenbuchung wechselt und es wird sich der vorher ausgewählte Mitarbeiter und Hilfeplan gemerkt.
/// Bei false wird davon ausgegangen, dass man von der Gruppenbuchung in eine Einzelbuchung wechselt und der vorher ausgewählte Mitarbeiter und Hilfeplan wird automatisch ausgewählt.</param>
2018-11-30 16:47:57 -04:00
private void ResetGroupBookingMode ( bool pIsInGroupBookingMode )
{
2018-12-03 19:14:35 -04:00
if ( Model = = null )
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
2018-12-03 19:14:35 -04:00
return ;
}
2018-11-30 16:47:57 -04:00
Model . IsInGroupBookingMode = pIsInGroupBookingMode ;
if ( pIsInGroupBookingMode )
2018-04-18 14:33:21 +02:00
{
2020-04-02 13:19:14 +02:00
Model . PreviouslySelectedEmployee = Model . SelectedEmployee ;
Model . PreviouslySelectedSupportConcept = Model . SelectedSupportConcept ;
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
2020-11-11 14:21:29 +01:00
Model . SelectedEmployees . AddIfNotIn ( MobileSessionFacade . LoggedInCompactEmployee ) ;
2020-04-24 19:08:09 +02:00
2020-04-08 14:44:20 +02:00
Model . IsInEditingMode = false ;
Model . SelectedServiceRecord = null ;
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
{
2020-04-02 13:19:14 +02:00
Model . SelectedEmployee = Model . PreviouslySelectedEmployee ;
Model . SelectedSupportConcept = Model . PreviouslySelectedSupportConcept ;
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]
2020-12-16 21:49:47 +01:00
public ActionResult ResetEditingMode ( )
2018-04-18 14:33:21 +02:00
{
2018-12-03 19:14:35 -04:00
if ( Model = = null )
{
2020-10-07 19:42:17 +02:00
return Logout ( ) ;
2018-12-03 19:14:35 -04:00
}
2018-04-18 14:33:21 +02:00
Model . NewServiceRecord = new ServiceRecordDC ( ) ;
Model . SelectedServiceRecord = null ;
Model . IsInEditingMode = false ;
2020-07-15 14:37:43 +02:00
Model . SelectedSupportConcepts . Clear ( ) ;
Model . SelectedConceptCostBearerRelations . Clear ( ) ;
Model . SelectedCostbearerRelOids . Clear ( ) ;
Model . SelectedGroupOfPeopleOids . Clear ( ) ;
Model . SelectedEmployees = new List < CompactEmployeeDC > { MobileSessionFacade . LoggedInCompactEmployee } ;
2020-04-02 13:19:14 +02:00
Model . SelectedEmployee = MobileSessionFacade . LoggedInCompactEmployee ;
2020-08-04 12:45:46 +02:00
2021-01-07 19:40:15 +01:00
//Model.ServiceCategories = CreateServiceCategoryModels(OperationsService.GetAllServiceDescriptions());
LoadServiceCategoriesToModel ( Model . CostBearer2SupportConceptOid ) ;
2020-08-04 12:45:46 +02:00
2020-04-02 13:19:14 +02:00
var serviceDescriptions = Model . GetServiceDesctiptions ( ) ;
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
if ( Model . ServiceCategories . Any ( ) & & serviceDescriptions . Any ( ) )
2016-06-27 01:45:38 +02:00
{
2020-04-02 13:19:14 +02:00
var firstServiceDescription = serviceDescriptions . First ( ) ;
2016-06-27 01:45:38 +02:00
2020-04-02 13:19:14 +02:00
Model . SelectedServiceDescriptionOid = firstServiceDescription . ServiceDescriptionOid ;
Model . SelectedServiceCategoryOid = firstServiceDescription . Category . ServiceCategoryOid ;
}
2018-11-24 14:28:46 -04:00
2020-04-02 13:19:14 +02:00
return RedirectToActionPermanent ( "Main" ) ;
2016-06-27 01:45:38 +02:00
}
2020-04-02 13:19:14 +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
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
2019-03-29 14:04:12 +01:00
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 ) ;
}
}
2020-04-02 13:19:14 +02:00
return SerializeObject ( Model . GroupBookingSelectionObject ) ;
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
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
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 ) ;
2020-04-02 13:19:14 +02:00
var selectedGroups = Model . GroupsOfPeople . Where ( group = > group . GroupOfPeopleOid . HasValue & & Model . SelectedGroupOfPeopleOids . Contains ( group . GroupOfPeopleOid . Value ) ) . ToList ( ) ;
var groups = selectedGroups . Where ( group = > group . SupportConceptList . All ( a = > Model . SelectedSupportConcepts . Where ( w = > w . SupportConceptOid . HasValue ) . Select ( s = > s . SupportConceptOid . Value ) . Contains ( a . SupportConceptOid ) ) ) ;
Model . SelectedGroupOfPeopleOids = groups . Where ( group = > group . GroupOfPeopleOid . HasValue ) . Select ( group = > group . GroupOfPeopleOid . Value ) . ToList ( ) ;
return SerializeObject ( Model . GroupBookingSelectionObject ) ;
2019-03-29 14:04:12 +01:00
}
[Authorize]
public string AddEmployeesToGroupBooking ( string pEmployeeOids )
{
if ( Model = = null )
{
2020-10-07 19:42:17 +02:00
Logout ( ) ;
2019-03-29 14:04:12 +01:00
return _LeerzeichenFuerGetMethoden ;
}
if ( string . IsNullOrEmpty ( pEmployeeOids ) )
{
Model . SelectedEmployees . Clear ( ) ;
2020-08-04 12:45:46 +02:00
return JsonConvert . SerializeObject ( Model . SelectedEmployees . Count ) ;
2019-03-29 14:04:12 +01:00
}
var rawEmployeeOids = pEmployeeOids . Split ( ',' ) ;
var oids = new List < long > ( ) ;
rawEmployeeOids . DoForEach ( s = > oids . AddIfNotIn ( long . Parse ( s ) ) ) ;
var employees = Model . Employees . Where ( w = > oids . Contains ( w . EmployeeOid ) ) ;
Model . SelectedEmployees . Clear ( ) ;
Model . SelectedEmployees . AddRangeIfElementsNotIn ( employees ) ;
2020-08-04 12:45:46 +02:00
return JsonConvert . SerializeObject ( Model . SelectedEmployees . Count ) ;
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 )
{
2020-10-07 19:42:17 +02:00
return Logout ( ) ;
2019-04-17 17:01:37 +02:00
}
2020-09-21 11:57:10 +02:00
var isParsingSuccessful2 = long . TryParse ( pFormCollection [ FormCollectionConstants . ServiceRecordOidHolder2Key ] , out var serviceRecordOid ) ;
var isParsingSuccessful = long . TryParse ( pFormCollection [ FormCollectionConstants . SignatureOidHolderKey ] , out var signatureOid ) ;
2020-04-02 13:19:14 +02:00
if ( isParsingSuccessful & & isParsingSuccessful2 )
2019-04-17 17:01:37 +02:00
{
2020-04-02 13:19:14 +02:00
var signatureServiceRecord = Model . ServiceRecords . FirstOrDefault ( serviceRecord = > serviceRecord . ServiceRecordOid . Equals ( serviceRecordOid ) ) ;
Model . SignatureServiceRecordHeader = MainModel . GetServiceRecordTimeHeader ( signatureServiceRecord , false ) ;
2019-04-17 17:01:37 +02:00
Model . SignatureImage = OperationsService . GetSignature ( signatureOid ) . DataBild ;
2020-04-02 13:19:14 +02:00
ApplyWatermark ( ) ;
2019-04-17 17:01:37 +02:00
}
return RedirectToActionPermanent ( "Main" ) ;
}
[Authorize]
public string ResetSignatureImage ( )
{
if ( Model = = null )
{
return _LeerzeichenFuerGetMethoden ;
}
Model . SignatureImage = null ;
2020-04-02 13:19:14 +02:00
Model . SignatureServiceRecordHeader = null ;
2019-04-17 17:01:37 +02:00
return _LeerzeichenFuerGetMethoden ;
}
2019-07-25 14:56:11 +02:00
2020-04-02 13:19:14 +02:00
[HttpPost]
[Authorize]
public ActionResult CreateGroupBooking ( FormCollection formCollection )
2019-07-25 14:56:11 +02:00
{
2020-04-02 13:19:14 +02:00
try
2019-07-25 14:56:11 +02:00
{
2020-04-02 13:19:14 +02:00
if ( Model = = null )
{
2020-10-07 19:42:17 +02:00
return Logout ( ) ;
2020-04-02 13:19:14 +02:00
}
2020-04-08 14:44:20 +02:00
if ( Model . SelectedConceptCostBearerRelations . Count = = 1 )
{
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 ( ) ;
var cb2ScOidsCount = cb2ScOids . Count ;
if ( cb2ScOidsCount = = 1 )
{
Model . CostBearer2SupportConceptOid = cb2ScOids [ 0 ] ;
}
else
{
return RedirectToActionPermanent ( "Main" ) ;
}
}
2020-04-02 13:19:14 +02:00
string doku1 ;
if ( Model . Dokutypes ! = null & & Model . Dokutypes . Length > 0 )
{
2020-09-21 11:57:10 +02:00
doku1 = formCollection [ FormCollectionConstants . Dokumentation1Key ] ;
2020-04-02 13:19:14 +02:00
}
else
{
2020-09-21 11:57:10 +02:00
doku1 = formCollection [ FormCollectionConstants . Dokumentation6Key ] ;
2020-04-02 13:19:14 +02:00
}
2020-09-21 11:57:10 +02:00
Log . Info ( $"CreateServiceRecord: datum:{formCollection[FormCollectionConstants.DateKey]}; start:{formCollection[FormCollectionConstants.StartKey]}; ende:{formCollection[FormCollectionConstants.EndKey]}; dauer:{formCollection[FormCollectionConstants.DurationKey]}; doku:{doku1}; aktion:{formCollection[FormCollectionConstants.HiddenInputKey]}" ) ;
2020-04-02 13:19:14 +02:00
2020-09-21 11:57:10 +02:00
if ( string . IsNullOrEmpty ( formCollection [ FormCollectionConstants . DateKey ] ) )
2020-04-02 13:19:14 +02:00
{
return View ( "Main" , Model ) ;
}
2020-09-21 11:57:10 +02:00
var distanz = formCollection [ FormCollectionConstants . DistanceKey ] ;
2020-04-02 13:19:14 +02:00
var distanceInMeters = 0 ;
if ( ! string . IsNullOrEmpty ( distanz ) )
{
if ( int . TryParse ( distanz , out var parsedDistance ) )
{
distanceInMeters = parsedDistance ;
}
}
var selectedCostbearerScRelOid = Model . CostBearer2SupportConceptOid < 1 ? null : Model . CostBearer2SupportConceptOid ;
2020-09-21 11:57:10 +02:00
var datum = Convert . ToDateTime ( formCollection [ FormCollectionConstants . DateKey ] ) ;
2020-04-02 13:19:14 +02:00
var enddatum = datum ;
2020-09-21 11:57:10 +02:00
var endDateString = formCollection [ FormCollectionConstants . EndDateKey ] ;
2020-04-02 13:19:14 +02:00
if ( endDateString ! = null )
{
enddatum = Convert . ToDateTime ( endDateString ) ;
}
2020-09-21 11:57:10 +02:00
var start = formCollection [ FormCollectionConstants . StartKey ] ;
var ende = formCollection [ FormCollectionConstants . EndKey ] ;
2020-04-02 13:19:14 +02:00
var dauer = 0 ;
if ( datum > enddatum )
{
enddatum = datum ;
}
2020-09-21 11:57:10 +02:00
if ( ! string . IsNullOrEmpty ( formCollection [ FormCollectionConstants . DurationKey ] ) )
2020-04-02 13:19:14 +02:00
{
2020-09-21 11:57:10 +02:00
int . TryParse ( formCollection [ FormCollectionConstants . DurationKey ] , out dauer ) ;
2020-04-02 13:19:14 +02:00
}
2020-09-21 11:57:10 +02:00
var doku2 = formCollection [ FormCollectionConstants . Dokumentation2Key ] ;
var doku3 = formCollection [ FormCollectionConstants . Dokumentation3Key ] ;
var doku4 = formCollection [ FormCollectionConstants . Dokumentation4Key ] ;
var doku5 = formCollection [ FormCollectionConstants . Dokumentation5Key ] ;
2020-04-02 13:19:14 +02:00
var zeitenFeld = new DateTime [ 2 ] ;
if ( start = = string . Empty & & ende = = string . Empty )
{
zeitenFeld [ 0 ] = new DateTime ( datum . Year , datum . Month , datum . Day , 0 , 0 , 1 ) ;
if ( enddatum = = datum )
{
zeitenFeld [ 1 ] = new DateTime ( datum . Year , datum . Month , datum . Day , 0 , 0 , 1 ) . AddMinutes ( dauer ) ;
}
else
{
zeitenFeld [ 1 ] = new DateTime ( enddatum . Year , enddatum . Month , enddatum . Day , 0 , 0 , 1 ) . AddMinutes ( dauer ) ;
}
}
else
{
zeitenFeld = enddatum = = datum ? ConvertRecordTimes ( start , ende , datum , dauer ) : ConvertRecordTimesWithEndDate ( start , ende , datum , enddatum , dauer ) ;
}
if ( dauer = = 0 | | zeitenFeld [ 1 ] ! = zeitenFeld [ 0 ] )
{
dauer = ( int ) ( zeitenFeld [ 1 ] - zeitenFeld [ 0 ] ) . TotalMinutes ;
}
if ( Model . NewServiceRecord = = null )
{
return RedirectToActionPermanent ( "Main" ) ;
}
Model . NewServiceRecord . IP = Request . UserHostAddress ;
Model . NewServiceRecord . Goals = Model . SelectedGoals ;
Model . NewServiceRecord . Start = zeitenFeld [ 0 ] ;
Model . NewServiceRecord . End = zeitenFeld [ 1 ] ;
Model . NewServiceRecord . DistanceInMeter = distanceInMeters ;
if ( Model . Employee . EmployeeOid ! = null )
{
if ( Model . SelectedEmployee ! = null )
{
Model . NewServiceRecord . Employee = Model . SelectedEmployee ;
}
var sc = Model . SupportConcepts . FirstOrDefault ( fod = > fod . CostBearerRelations . Any ( a = > a . CostBearer2SupportConceptOid . HasValue & & a . CostBearer2SupportConceptOid . Value . Equals ( selectedCostbearerScRelOid ) ) ) ;
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 )
{
Model . NewServiceRecord . RoundedDuration = dauer % intervall ! = 0 ? dauer + ( intervall - dauer % intervall ) : dauer ;
}
else
{
Model . NewServiceRecord . RoundedDuration = dauer ;
}
Model . NewServiceRecord . CostBearer2SupportConceptOid = selectedCostbearerScRelOid ;
}
else
{
Model . NewServiceRecord . RoundedDuration = dauer ;
}
}
Model . NewServiceRecord . DurationInStunden = ZeiterfassungsDauer . Minuten ;
Model . NewServiceRecord . ServiceRecordFormat = ServiceRecordFormate . OriginaleZeiterfassung ;
Model . NewServiceRecord . Notice = string . IsNullOrEmpty ( doku1 ) ? null : doku1 ;
Model . NewServiceRecord . Notice2 = string . IsNullOrEmpty ( doku2 ) ? null : doku2 ;
Model . NewServiceRecord . Notice3 = string . IsNullOrEmpty ( doku3 ) ? null : doku3 ;
Model . NewServiceRecord . Notice4 = string . IsNullOrEmpty ( doku4 ) ? null : doku4 ;
Model . NewServiceRecord . Notice5 = string . IsNullOrEmpty ( doku5 ) ? null : doku5 ;
var serviceDescOid = 0L ;
2020-09-21 11:57:10 +02:00
if ( ! string . IsNullOrEmpty ( formCollection [ FormCollectionConstants . ServiceDescriptionKey ] ) )
2020-04-02 13:19:14 +02:00
{
2020-09-21 11:57:10 +02:00
serviceDescOid = Convert . ToInt64 ( formCollection [ FormCollectionConstants . ServiceDescriptionKey ] ) ;
2020-04-02 13:19:14 +02:00
}
else if ( Model . SelectedServiceDescriptionOid . HasValue )
{
serviceDescOid = Model . SelectedServiceDescriptionOid . Value ;
}
if ( serviceDescOid > 0 )
{
Model . NewServiceRecord . ServiceDescription = OperationsService . GetServiceDescription ( serviceDescOid ) ;
}
if ( Model . NewServiceRecord . RoundedDuration = = 0 )
{
Model . NewServiceRecord . RoundedDuration = dauer ;
}
Model . NewServiceRecord . IP = Request . UserHostAddress ;
Model . NewServiceRecord . InsertedOn = DateTime . Now ;
Model . NewServiceRecord . InsUser = $"{MobileSessionFacade.LoggedInEmployee.FirstName} {MobileSessionFacade.LoggedInEmployee.LastName}" ;
Model . NewServiceRecord . IsCreatedInMobileClient = true ;
if ( Model . IsInGroupBookingMode & & Model . SelectedSupportConcepts . Count > 1 )
{
2020-11-20 23:28:09 +01:00
// ResetGroupBookingMode(true);
2020-08-04 12:45:46 +02:00
2020-04-02 13:19:14 +02:00
return SaveGroupBooking ( ) ;
}
var oidList = OperationsService . InsertNewServiceRecords ( new List < ServiceRecordDC > { Model . NewServiceRecord } ) ;
Model . ServiceRecordOid = oidList [ 0 ] ;
Model . NewServiceRecord = new ServiceRecordDC ( ) ;
}
catch ( Exception e )
{
Log . Error ( e . Message , e ) ;
2019-07-25 14:56:11 +02:00
}
2020-12-16 21:49:47 +01:00
return ResetEditingMode ( ) ;
2020-04-02 13:19:14 +02:00
}
[HttpPost]
[Authorize]
public ActionResult EditServiceRecord ( FormCollection formCollection )
{
2020-07-15 14:37:43 +02:00
if ( Model = = null )
2020-04-02 13:19:14 +02:00
{
2020-10-07 19:42:17 +02:00
return Logout ( ) ;
2020-04-02 13:19:14 +02:00
}
2020-07-15 14:37:43 +02:00
try
{
2020-04-02 13:19:14 +02:00
string doku1 ;
2019-07-25 14:56:11 +02:00
2020-04-02 13:19:14 +02:00
if ( Model . Dokutypes ! = null & & Model . Dokutypes . Length > 0 )
{
2020-09-21 11:57:10 +02:00
doku1 = formCollection [ FormCollectionConstants . Dokumentation1Key ] ;
2020-04-02 13:19:14 +02:00
}
else
{
2020-09-21 11:57:10 +02:00
doku1 = formCollection [ FormCollectionConstants . Dokumentation6Key ] ;
2020-04-02 13:19:14 +02:00
}
2019-07-25 14:56:11 +02:00
2020-09-21 11:57:10 +02:00
Log . Info ( $"EditServiceRecord: datum:{formCollection[FormCollectionConstants.DateKey]}; start:{formCollection[FormCollectionConstants.StartKey]}; ende:{formCollection[FormCollectionConstants.EndKey]}; dauer:{formCollection[FormCollectionConstants.DurationKey]}; doku:{doku1}; aktion:Speichern" ) ;
2020-04-02 13:19:14 +02:00
2020-09-21 11:57:10 +02:00
if ( string . IsNullOrEmpty ( formCollection [ FormCollectionConstants . DateKey ] ) )
2020-04-02 13:19:14 +02:00
{
return View ( "Main" , Model ) ;
}
2020-09-21 11:57:10 +02:00
var distanz = formCollection [ FormCollectionConstants . DistanceKey ] ;
2020-04-02 13:19:14 +02:00
var distanceInMeters = 0 ;
if ( ! string . IsNullOrEmpty ( distanz ) )
{
if ( int . TryParse ( distanz , out var parsedDistance ) )
{
distanceInMeters = parsedDistance ;
}
}
2020-04-24 19:08:09 +02:00
var selectedCostbearer2SupportConceptRelOid = Model . CostBearer2SupportConceptOid < 1 ? null : Model . CostBearer2SupportConceptOid ;
2020-09-21 11:57:10 +02:00
var datum = Convert . ToDateTime ( formCollection [ FormCollectionConstants . DateKey ] ) ;
2020-04-02 13:19:14 +02:00
var enddatum = datum ;
2020-09-21 11:57:10 +02:00
var endDateString = formCollection [ FormCollectionConstants . EndDateKey ] ;
2020-04-02 13:19:14 +02:00
if ( endDateString ! = null )
{
enddatum = Convert . ToDateTime ( endDateString ) ;
}
2020-09-21 11:57:10 +02:00
var start = formCollection [ FormCollectionConstants . StartKey ] ;
var ende = formCollection [ FormCollectionConstants . EndKey ] ;
2020-04-02 13:19:14 +02:00
var dauer = 0 ;
if ( datum > enddatum )
{
enddatum = datum ;
}
2020-09-21 11:57:10 +02:00
if ( ! string . IsNullOrEmpty ( formCollection [ FormCollectionConstants . DurationKey ] ) )
2020-04-02 13:19:14 +02:00
{
2020-09-21 11:57:10 +02:00
int . TryParse ( formCollection [ FormCollectionConstants . DurationKey ] , out dauer ) ;
2020-04-02 13:19:14 +02:00
}
2020-09-21 11:57:10 +02:00
var doku2 = formCollection [ FormCollectionConstants . Dokumentation2Key ] ;
var doku3 = formCollection [ FormCollectionConstants . Dokumentation3Key ] ;
var doku4 = formCollection [ FormCollectionConstants . Dokumentation4Key ] ;
var doku5 = formCollection [ FormCollectionConstants . Dokumentation5Key ] ;
2020-04-02 13:19:14 +02:00
var zeitenFeld = new DateTime [ 2 ] ;
if ( start = = string . Empty & & ende = = string . Empty )
{
zeitenFeld [ 0 ] = new DateTime ( datum . Year , datum . Month , datum . Day , 0 , 0 , 1 ) ;
if ( enddatum = = datum )
{
zeitenFeld [ 1 ] = new DateTime ( datum . Year , datum . Month , datum . Day , 0 , 0 , 1 ) . AddMinutes ( dauer ) ;
}
else
{
zeitenFeld [ 1 ] = new DateTime ( enddatum . Year , enddatum . Month , enddatum . Day , 0 , 0 , 1 ) . AddMinutes ( dauer ) ;
}
}
else
{
zeitenFeld = enddatum = = datum ? ConvertRecordTimes ( start , ende , datum , dauer ) : ConvertRecordTimesWithEndDate ( start , ende , datum , enddatum , dauer ) ;
}
if ( dauer = = 0 | | zeitenFeld [ 1 ] ! = zeitenFeld [ 0 ] )
{
dauer = ( int ) ( zeitenFeld [ 1 ] - zeitenFeld [ 0 ] ) . TotalMinutes ;
}
var selectedRecordOid = Model . SelectedServiceRecordOid ? ? Model . SelectedServiceRecord . ServiceRecordOid ;
Model . NewServiceRecord = OperationsService . GetServiceRecordById ( selectedRecordOid . Value ) ;
if ( Model . NewServiceRecord = = null )
{
return RedirectToActionPermanent ( "Main" ) ;
}
Model . NewServiceRecord . IP = Request . UserHostAddress ;
Model . NewServiceRecord . Goals = Model . SelectedGoals ;
Model . NewServiceRecord . Start = zeitenFeld [ 0 ] ;
Model . NewServiceRecord . End = zeitenFeld [ 1 ] ;
Model . NewServiceRecord . DistanceInMeter = distanceInMeters ;
if ( Model . Employee . EmployeeOid ! = null )
{
2020-07-15 14:37:43 +02:00
2020-04-02 13:19:14 +02:00
if ( Model . SelectedEmployee ! = null )
{
Model . NewServiceRecord . Employee = Model . SelectedEmployee ;
}
2020-04-24 19:08:09 +02:00
var sc = Model . SupportConcepts . FirstOrDefault ( fod = > fod . CostBearerRelations . Any ( a = > a . CostBearer2SupportConceptOid . HasValue & & a . CostBearer2SupportConceptOid . Value . Equals ( selectedCostbearer2SupportConceptRelOid ) ) ) ;
2020-04-02 13:19:14 +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 ;
2020-04-24 19:08:09 +02:00
var cb2ScRel = sc . CostBearerRelations . First ( f = > f . CostBearer2SupportConceptOid . HasValue & & f . CostBearer2SupportConceptOid . Equals ( selectedCostbearer2SupportConceptRelOid ) ) ;
2020-04-02 13:19:14 +02:00
Model . NewServiceRecord . CostBearer = cb2ScRel . CostBearer ;
var intervall = Model . NewServiceRecord . CostBearer . ActualMinuteIntervall ;
if ( intervall > 0 )
{
Model . NewServiceRecord . RoundedDuration = dauer % intervall ! = 0 ? dauer + ( intervall - dauer % intervall ) : dauer ;
}
else
{
Model . NewServiceRecord . RoundedDuration = dauer ;
}
2020-04-24 19:08:09 +02:00
Model . NewServiceRecord . CostBearer2SupportConceptOid = selectedCostbearer2SupportConceptRelOid ;
2020-04-02 13:19:14 +02:00
}
else
{
Model . NewServiceRecord . RoundedDuration = dauer ;
}
}
Model . NewServiceRecord . DurationInStunden = ZeiterfassungsDauer . Minuten ;
Model . NewServiceRecord . ServiceRecordFormat = ServiceRecordFormate . OriginaleZeiterfassung ;
Model . NewServiceRecord . Notice = string . IsNullOrEmpty ( doku1 ) ? null : doku1 ;
Model . NewServiceRecord . Notice2 = string . IsNullOrEmpty ( doku2 ) ? null : doku2 ;
Model . NewServiceRecord . Notice3 = string . IsNullOrEmpty ( doku3 ) ? null : doku3 ;
Model . NewServiceRecord . Notice4 = string . IsNullOrEmpty ( doku4 ) ? null : doku4 ;
Model . NewServiceRecord . Notice5 = string . IsNullOrEmpty ( doku5 ) ? null : doku5 ;
var serviceDescOid = 0L ;
2020-09-21 11:57:10 +02:00
if ( ! string . IsNullOrEmpty ( formCollection [ FormCollectionConstants . ServiceDescriptionKey ] ) )
2020-04-02 13:19:14 +02:00
{
2020-09-21 11:57:10 +02:00
serviceDescOid = Convert . ToInt64 ( formCollection [ FormCollectionConstants . ServiceDescriptionKey ] ) ;
2020-07-15 14:37:43 +02:00
}
else if ( Model . SelectedServiceDescriptionOid . HasValue )
2020-04-02 13:19:14 +02:00
{
serviceDescOid = Model . SelectedServiceDescriptionOid . Value ;
}
if ( serviceDescOid > 0 )
{
Model . NewServiceRecord . ServiceDescription = OperationsService . GetServiceDescription ( serviceDescOid ) ;
}
if ( Model . NewServiceRecord . RoundedDuration = = 0 )
{
Model . NewServiceRecord . RoundedDuration = dauer ;
}
Model . NewServiceRecord . IP = Request . UserHostAddress ;
Model . NewServiceRecord . InsertedOn = DateTime . Now ;
Model . NewServiceRecord . InsUser = $"{MobileSessionFacade.LoggedInEmployee.FirstName} {MobileSessionFacade.LoggedInEmployee.LastName}" ;
Model . NewServiceRecord . IsCreatedInMobileClient = true ;
if ( Model . IsInGroupBookingMode & & Model . SelectedSupportConcepts . Count > 1 )
{
return UpdateGroupBooking ( ) ;
}
OperationsService . UpdateServiceRecords ( new List < ServiceRecordDC > { Model . NewServiceRecord } ) ;
Model . NewServiceRecord = new ServiceRecordDC ( ) ;
2020-04-24 19:08:09 +02:00
if ( selectedCostbearer2SupportConceptRelOid . HasValue )
2020-04-02 13:19:14 +02:00
{
2020-04-24 19:08:09 +02:00
Model . ServiceRecords = OperationsService . FindServiceRecordsForLastDays ( selectedCostbearer2SupportConceptRelOid , Model . Zeitraum , Model . Employee . EmployeeOid ) . ToList ( ) ;
2020-04-02 13:19:14 +02:00
}
}
2020-07-15 14:37:43 +02:00
catch ( Exception e )
2020-04-02 13:19:14 +02:00
{
Log . Error ( e . Message , e ) ;
}
2020-12-16 21:49:47 +01:00
return ResetEditingMode ( ) ;
2019-07-25 14:56:11 +02:00
}
2020-05-27 18:15:54 +02:00
[HttpPost]
public ActionResult LogOutAfterSessionTimeout ( )
{
Logout ( ) ;
return RedirectToActionPermanent ( "Index" , "Login" , new { isSessionTimedOut = true } ) ;
}
2020-12-16 21:49:47 +01:00
[HttpPost]
[Authorize]
public ActionResult SetSupportConceptFilter ( FormCollection formCollection )
{
if ( Model = = null )
{
return Logout ( ) ;
}
var selectedSupportConceptFilter = formCollection [ nameof ( Model . SelectedSupportConceptFilter ) ] ;
if ( ! Enum . TryParse ( selectedSupportConceptFilter , out CustomerFilterEnum customerFilter ) )
{
customerFilter = CustomerFilterEnum . MyCustomer ;
}
UpdateSettings ( "CustomerFilterInZeiterfassung" , customerFilter . ToString ( ) ) ;
return RedirectToActionPermanent ( "Main" ) ;
}
2018-02-07 14:14:08 +01:00
}
2016-06-27 01:45:38 +02:00
}