2698 lines
107 KiB
C#
2698 lines
107 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using System.Web.Mvc;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Service.ServiceImplementations;
|
|
using BeWoPlanerMobil.Models;
|
|
using BeWoPlanerMobil.Service;
|
|
using BeWoPlanerMobil.Util;
|
|
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.Compact;
|
|
using BS.Shared.Extensions;
|
|
using BS.Shared.Services;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using DevExpress.XtraScheduler;
|
|
using DevExpress.XtraScheduler.Compatibility;
|
|
|
|
namespace BeWoPlanerMobil.Controllers
|
|
{
|
|
public class MainController : AbstractBaseController
|
|
{
|
|
private MainModel _Model;
|
|
public MainModel Model
|
|
{
|
|
get
|
|
{
|
|
if(!MobileSessionFacade.IsUserLoggedIn())
|
|
{
|
|
RedirectToActionPermanent("Index", "Login");
|
|
return null;
|
|
}
|
|
|
|
if(((MainModel) Session[MainModelSessionKey])?.Employee == null)
|
|
{
|
|
_Model = new MainModel { Employee = MobileSessionFacade.LoggedInEmployee };
|
|
Session[MainModelSessionKey] = _Model;
|
|
}
|
|
else
|
|
{
|
|
_Model = (MainModel)Session[MainModelSessionKey];
|
|
}
|
|
|
|
return _Model;
|
|
}
|
|
}
|
|
|
|
private const string MainModelSessionKey = "MainModel";
|
|
|
|
private Dictionary<long, ValueListEntryDC> _ParentGoals;
|
|
|
|
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 };
|
|
|
|
[Authorize]
|
|
public ActionResult Main()
|
|
{
|
|
try
|
|
{
|
|
ViewData["ValidationError"] = string.Empty;
|
|
|
|
if(!MobileSessionFacade.IsUserLoggedIn() || Request.Browser.Browser.Equals("InternetExplorer"))
|
|
{
|
|
return RedirectToActionPermanent("Index", "Login");
|
|
}
|
|
|
|
Model.ShowExpiredSupportConcepts = GetUserSettingValue("ShowExpiredSupportConcepts") == "1";
|
|
Model.ShowOnlyOwnSupportConcepts = GetUserSettingValue("ShowOnlyMySupportConcepts") == "1";
|
|
|
|
var unter = GetSettingValue("ShowSignature");
|
|
Model.ShowSignature = unter == "1";
|
|
|
|
Model.GroupsOfPeople = EmployeeService.GetAllGroups(GetUser().Employee.EmployeeOid);
|
|
|
|
Model.SelectedGoals = null;
|
|
|
|
Model.ShowDistanceField = "1" == GetSettingValue("ShowDistanceFields");
|
|
|
|
Model.Dokutypes = ValueListService.GetAllValueListEntrysByType(ValueListEntryType.DocumentType);
|
|
if (Model.Dokutypes != null)
|
|
{
|
|
Model.Dokutypes = Model.Dokutypes.OrderBy(s => s.ValueListEntryOid).ToArray();
|
|
}
|
|
|
|
if(MainModel.AllEmployees == null)
|
|
{
|
|
MainModel.AllEmployees = EmployeeService.GetAllActiveEmployeesCompact();
|
|
}
|
|
|
|
var myRelatedCustomers = Model.Employee == null ? new List<CustomerEmployeeRelationDC>() : Model.Employee.RelatedCustomers;
|
|
|
|
if (MobileSessionFacade.CheckForUserRight(UserRightType.CustomerView_View))
|
|
{
|
|
Model.Customers = CustomerService.GetAllActiveCompactCustomers().OrderBy(k => k.LastName).ToList();
|
|
}
|
|
else if(MobileSessionFacade.CheckForUserRight(UserRightType.Customer_ViewMyCustomers))
|
|
{
|
|
Model.Customers = CustomerService.GetCompactCustomersById(myRelatedCustomers.Select(c => c.Customer.CustomerOid).ToList()).OrderBy(k => k.LastName).ToList();
|
|
}
|
|
else
|
|
{
|
|
Model.Customers = new List<CompactCustomerDC>();
|
|
}
|
|
|
|
if(MobileSessionFacade.CheckForUserRight(UserRightType.ServiceRecord_AllowCreationForOtherEmployees))
|
|
{
|
|
Model.Employees = EmployeeService.GetAllActiveEmployeesCompact();
|
|
}
|
|
else if(MobileSessionFacade.CheckForUserRight(UserRightType.ServiceRecord_AllowCreationForOtherTeamMember) && Model.Employee?.EmployeeOid != null)
|
|
{
|
|
Model.Employees = EmployeeService.GetAllTeamMember(MobileSessionFacade.LoggedInCompactEmployee);
|
|
}
|
|
else
|
|
{
|
|
Model.Employees = new List<CompactEmployeeDC> { MobileSessionFacade.LoggedInCompactEmployee };
|
|
}
|
|
|
|
if(Model.ShowOnlyOwnSupportConcepts == false && MobileSessionFacade.CheckForUserRight(UserRightType.SupportConcept_ViewAllSupportConcepts))
|
|
{
|
|
Model.SupportConcepts = CustomerService.GetAllActiveSupportConcepts();
|
|
}
|
|
else
|
|
{
|
|
Model.SupportConcepts = CustomerService.GetAllActiveSupportConceptsByCustomers(myRelatedCustomers.Select(c => c.Customer.CustomerOid));
|
|
}
|
|
|
|
var test = Model.ServiceRecords.Any(a => a.GroupPersonCount != null && a.IsCreatedInMobileClient);
|
|
|
|
if(!Model.ShowExpiredSupportConcepts)
|
|
{
|
|
Model.SupportConcepts = Model.SupportConcepts.Where(w =>
|
|
{
|
|
var endDate = MainModel.GetEndDateOfSupportConcept(w);
|
|
|
|
return endDate == null || endDate.Value >= DateTime.Now;
|
|
}).ToList();
|
|
}
|
|
|
|
if(Model.ServiceCategories == null)
|
|
{
|
|
Model.ServiceCategories = new List<ServiceCategoryModel>();
|
|
}
|
|
|
|
if (Model.CostBearer2SupportConceptOid != null)
|
|
{
|
|
LoadRecordsToModel();
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.Error(e.Message, e);
|
|
}
|
|
|
|
return View(Model);
|
|
}
|
|
|
|
[HttpPost]
|
|
[Authorize]
|
|
public ActionResult SetShowOnlyOwnSupportConcepts(FormCollection collection)
|
|
{
|
|
var newValue = "true,false" == collection["ShowOnlyOwnSupportConcepts"];
|
|
|
|
Model.ShowOnlyOwnSupportConcepts = newValue;
|
|
|
|
return UpdateSettings("ShowOnlyMySupportConcepts", newValue ? "1" : "0"); ;
|
|
}
|
|
|
|
[HttpPost]
|
|
[Authorize]
|
|
public ActionResult SetShowExpiredSupportConcepts(FormCollection pCollection)
|
|
{
|
|
var newValue = "true,false" == pCollection["ShowExpiredSupportConcepts"];
|
|
|
|
Model.ShowExpiredSupportConcepts = newValue;
|
|
|
|
return UpdateSettings("ShowExpiredSupportConcepts", newValue ? "1" : "0");
|
|
}
|
|
|
|
public ActionResult UpdateSettings(string pKey, string pValue)
|
|
{
|
|
var userSettings = GetUser().Settings;
|
|
|
|
UserSettingsUtils.SetSettingValue(SettingsType.ApplicationSettings, pKey, pValue, userSettings);
|
|
|
|
UserService.UpdateUserSettings(GetUser().UserOid.Value, userSettings);
|
|
|
|
return RedirectToAction("Main");
|
|
}
|
|
|
|
[HttpPost]
|
|
public new ActionResult Logout()
|
|
{
|
|
return base.Logout();
|
|
}
|
|
|
|
[Authorize]
|
|
public string LoadGoals(long pCostbearer2SupportConceptOid)
|
|
{
|
|
if (Model == null)
|
|
{
|
|
return "SessionTimeout";
|
|
}
|
|
|
|
var sc = Model.SupportConcepts.FirstOrDefault(f => f.CostBearerRelations.Any(cbr => cbr.CostBearer2SupportConceptOid.HasValue && cbr.CostBearer2SupportConceptOid.Value.Equals(pCostbearer2SupportConceptOid)));
|
|
|
|
if (sc == null)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
Model.SelectedSupportConcept = sc;
|
|
|
|
var selectedGoals = sc.Goals;
|
|
var missingParents = selectedGoals.Where(w => w.ParentOid != null && false == selectedGoals.Any(a => a.ValueListEntryOid.Equals(w.ParentOid))).Select(s => s.ParentOid).ToList();
|
|
|
|
_ParentGoals = new Dictionary<long, ValueListEntryDC>();
|
|
foreach (var oid in missingParents)
|
|
{
|
|
LoadMissingParents(oid.Value);
|
|
}
|
|
|
|
var goalTree = BuildGoalTree(selectedGoals.Union(_ParentGoals.Values).ToList());
|
|
|
|
return SerializeObject(goalTree);
|
|
}
|
|
|
|
private static List<GoalTreeItem> BuildGoalTree(List<ValueListEntryDC> goals)
|
|
{
|
|
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 goalTree = new List<GoalTreeItem>();
|
|
var goalTreeDic = new Dictionary<long, GoalTreeItem>();
|
|
|
|
|
|
foreach(var ziel in ziele)
|
|
{
|
|
var treeItem = new GoalTreeItem {Children = new List<GoalTreeItem>(), Header = ziel.TypeDescription, ParentOid = ziel.ParentOid, ValueListEntryOid = ziel.ValueListEntryOid};
|
|
|
|
goalTreeDic.Add(ziel.ValueListEntryOid.Value, treeItem);
|
|
|
|
if(ziel.ParentOid == null)
|
|
{
|
|
goalTree.Add(treeItem);
|
|
}
|
|
}
|
|
|
|
foreach(var zielMitEltern in goalTreeDic.Values.Where(w => w.ParentOid != null))
|
|
{
|
|
goalTreeDic[zielMitEltern.ParentOid.Value].Children.Add(zielMitEltern);
|
|
}
|
|
|
|
foreach(var ziel in massnahmen)
|
|
{
|
|
var kind = new GoalTreeItem {Children = new List<GoalTreeItem>(), Header = ziel.TypeDescription, IsLeaf = true, ValueListEntryOid = ziel.ValueListEntryOid};
|
|
|
|
if(ziel.ParentOid != null && goalTreeDic.ContainsKey(ziel.ParentOid.Value))
|
|
{
|
|
kind.ParentOid = goalTreeDic[ziel.ParentOid.Value].ParentOid;
|
|
goalTreeDic[ziel.ParentOid.Value].Children.Add(kind);
|
|
}
|
|
}
|
|
|
|
foreach(var item in goalTreeDic.Values)
|
|
{
|
|
if(item.Children.Count == 0 && item.ParentOid.HasValue)
|
|
{
|
|
item.IsLeaf = true;
|
|
}
|
|
}
|
|
|
|
return goalTree;
|
|
}
|
|
|
|
private void LoadMissingParents(long pParentOid)
|
|
{
|
|
while(true)
|
|
{
|
|
var parentDC = ValueListService.GetValueListEntryByOid(pParentOid);
|
|
|
|
if(!_ParentGoals.ContainsKey(parentDC.ValueListEntryOid.Value))
|
|
{
|
|
_ParentGoals.Add(parentDC.ValueListEntryOid.Value, parentDC);
|
|
|
|
if(parentDC.ParentOid != null)
|
|
{
|
|
pParentOid = parentDC.ParentOid.Value;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
public string LoadBWPSettings()
|
|
{
|
|
var m = OperationsService.GetMandator();
|
|
var time = GetSettingValue(m.Settings, "TimeUntilUILock");
|
|
|
|
return SerializeObject(time);
|
|
}
|
|
|
|
public string CheckEndDate() {
|
|
|
|
var m = OperationsService.GetMandator();
|
|
var endtime = GetSettingValue(m.Settings, "IsEndDateVisible");
|
|
|
|
return SerializeObject(endtime);
|
|
}
|
|
|
|
public string CheckOnlyYearMonth()
|
|
{
|
|
|
|
var m = OperationsService.GetMandator();
|
|
var yearMonth = GetSettingValue(m.Settings, "IsOnlyYearMonthVisible");
|
|
|
|
return SerializeObject(yearMonth);
|
|
}
|
|
|
|
public string CheckIsZeiterfassDateNormal()
|
|
{
|
|
|
|
var m = OperationsService.GetMandator();
|
|
var normal = GetSettingValue(m.Settings, "IsZeiterfassDateNormal");
|
|
|
|
return SerializeObject(normal);
|
|
}
|
|
|
|
public string CheckIsZeiterfassungInStdMin()
|
|
{
|
|
|
|
var m = OperationsService.GetMandator();
|
|
var zeiterInStdMin = GetSettingValue(m.Settings, "IsZeiterfassungInStdMin");
|
|
|
|
return SerializeObject(zeiterInStdMin);
|
|
}
|
|
|
|
public string CheckDokuReiter()
|
|
{
|
|
return SerializeObject(Model.Dokutypes);
|
|
}
|
|
|
|
private static string GetUserSettingValue(string key)
|
|
{
|
|
var user = MobileSessionFacade.LoggedInUser;
|
|
|
|
var settings = user?.SettingList.FirstOrDefault(f => f.Type.Equals(SettingsType.ApplicationSettings));
|
|
|
|
return settings != null ? GetSettingValue(settings.Value, key) : null;
|
|
}
|
|
|
|
private string GetSettingValue(string key)
|
|
{
|
|
var man = OperationsService.GetMandator();
|
|
return GetSettingValue(man.Settings, key);
|
|
}
|
|
|
|
private static string GetSettingValue(string settings, string key)
|
|
{
|
|
if (!string.IsNullOrEmpty(settings))
|
|
{
|
|
if (settings.IndexOf(";") == -1 && settings.IndexOf("=") == -1)
|
|
{
|
|
return settings;
|
|
}
|
|
|
|
var keyValuePairs = settings.Split(';');
|
|
|
|
return (from pair in keyValuePairs select pair.Split('=') into keyValuePair where keyValuePair.Length == 2 where keyValuePair[0] == key select keyValuePair[1]).FirstOrDefault();
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
private static RecurrenceInformation GetOccurrenceId(string pRecurrenceInfoString)
|
|
{
|
|
var regex = new Regex("Index=\"[0-9]+\"");
|
|
|
|
var match = regex.Match(pRecurrenceInfoString);
|
|
|
|
var recurrenceInfo = new RecurrenceInfo();
|
|
recurrenceInfo.FromXml(pRecurrenceInfoString);
|
|
|
|
var index = 0;
|
|
|
|
if(!match.Value.IsNullOrEmpty())
|
|
{
|
|
index = int.Parse(match.Value.Split('"')[1]);
|
|
}
|
|
|
|
return new RecurrenceInformation(recurrenceInfo.Id.ToString(), index);
|
|
}
|
|
|
|
[Authorize]
|
|
public string LoadAppointments(string newtoday)
|
|
{
|
|
try
|
|
{
|
|
if (Model == null)
|
|
{
|
|
return "SessionTimeout";
|
|
}
|
|
|
|
var date = DateTime.ParseExact(newtoday, "dd.MM.yyyy", null);
|
|
|
|
var appointments = KalenderService.LoadFilteredAppointments(true, Model.Employee.EmployeeOid.Value, date.Date, date.Date.AddDays(1), new List<long>(), new List<long>(), new List<long>(), false, false, false, false, true).ToList();
|
|
|
|
var holySweetFlyingFuck = appointments.Where(w => w.StartDate.HasValue && w.EndDate.HasValue && ((date.InBetween(w.StartDate.Value, w.EndDate.Value, false) || date.CompareShortDates(w.StartDate.Value)) && w.RecurrenceInfo == null ||
|
|
w.RecurrenceInfo != null && (w.Type == 3 || w.Type == 4) && (date.InBetween(w.StartDate.Value, w.EndDate.Value, false) ||
|
|
date.CompareShortDates(w.StartDate.Value)))).ToList();
|
|
|
|
var deletedOccurrences = holySweetFlyingFuck.Where(w => w.Type == 4).Select(s => GetOccurrenceId(s.RecurrenceInfo)).ToList();
|
|
var changedOccurrences = holySweetFlyingFuck.Where(w => w.Type == 3).Select(s => GetOccurrenceId(s.RecurrenceInfo)).ToList();
|
|
|
|
holySweetFlyingFuck = holySweetFlyingFuck.Where(w => w.Type != 4).ToList();
|
|
|
|
foreach(var appointment in appointments)
|
|
{
|
|
if(appointment.RecurrenceInfo != null && appointment.Type == 1)
|
|
{
|
|
var recurrenceInfo = new RecurrenceInfo();
|
|
recurrenceInfo.FromXml(appointment.RecurrenceInfo);
|
|
var occurrenceCalculator = OccurrenceCalculator.CreateInstance(recurrenceInfo);
|
|
|
|
var pattern = StaticAppointmentFactory.CreateAppointment(AppointmentType.Pattern);
|
|
pattern.RecurrenceInfo.FromXml(appointment.RecurrenceInfo);
|
|
pattern.Start = pattern.RecurrenceInfo.Start;
|
|
pattern.End = pattern.RecurrenceInfo.End;
|
|
var patternId = pattern.RecurrenceInfo.Id.ToString();
|
|
|
|
var interval = new TimeInterval(date, date.AddDays(1));
|
|
|
|
var occurrences = occurrenceCalculator.CalcOccurrences(interval, pattern);
|
|
|
|
if(occurrences.Count > 0)
|
|
{
|
|
foreach(var termin in occurrences.GetAppointments(interval))
|
|
{
|
|
var index = termin.RecurrenceIndex;
|
|
|
|
var duration = (appointment.EndDate.Value - appointment.StartDate.Value).TotalMinutes;
|
|
|
|
if(!date.InBetween(termin.Start.GetShortDateTime(), termin.Start.AddMinutes(duration), true) || changedOccurrences.Any(a => a.PatternId.Equals(patternId) && a.Index == index) || deletedOccurrences.Any(a => a.PatternId.Equals(patternId) && a.Index == index))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
holySweetFlyingFuck.AddIfNotIn(new SchedulerAppointmentDC
|
|
{
|
|
AllDay = appointment.AllDay,
|
|
CustomerList = appointment.CustomerList,
|
|
Description = appointment.Description,
|
|
EmployeeList = appointment.EmployeeList,
|
|
EndDate = termin.Start.AddMinutes(duration),
|
|
FormerBookingSequenceOid = appointment.FormerBookingSequenceOid,
|
|
IsPrivate = appointment.IsPrivate,
|
|
LabelId = appointment.LabelId,
|
|
Location = appointment.Location,
|
|
Originator = appointment.Originator,
|
|
RecurrenceInfo = termin.RecurrenceInfo.ToXml(),
|
|
ReminderInfo = appointment.ReminderInfo,
|
|
ResourceList = appointment.ResourceList,
|
|
StartDate = termin.Start,
|
|
Subject = appointment.Subject ?? "",
|
|
Type = appointment.Type
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return SerializeObject(holySweetFlyingFuck.OrderBy(x => x.StartDate.Value.Hour));
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.Error(e.Message, e);
|
|
return SerializeObject("Fehler 510");
|
|
}
|
|
}
|
|
|
|
[Authorize]
|
|
public string LoadStatistics(long oid)
|
|
{
|
|
try
|
|
{
|
|
if(Model == null)
|
|
{
|
|
return "SessionTimeout";
|
|
}
|
|
|
|
var supportConceptStatistics = OperationsService.CreateSupportConceptStatistics(oid, DateTime.Now);
|
|
|
|
return SerializeObject(supportConceptStatistics);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.Error(e.Message, e);
|
|
return SerializeObject("Fehler 560");
|
|
}
|
|
}
|
|
|
|
[Authorize]
|
|
public void UpdateAppointment(long oid, string betreff, string notice, string startZeit, string endZeit, string day, string endDate)
|
|
{
|
|
try
|
|
{
|
|
if (Model == null)
|
|
{
|
|
SerializeObject("SessionTimeout");
|
|
}
|
|
|
|
var date = DateTime.Parse(day);
|
|
var end = DateTime.Parse(endDate);
|
|
var zeit = ConvertRecordTimesWithEndDate(startZeit, endZeit, date, end, 0);
|
|
|
|
var b1 = KalenderService.GetSchedulerAppointmentByid(oid);
|
|
|
|
b1.EndDate = zeit[1];
|
|
b1.StartDate = zeit[0];
|
|
b1.Subject = betreff;
|
|
b1.Description = notice;
|
|
|
|
KalenderService.UpdateSchedulerAppointments(new List<SchedulerAppointmentDC>{b1});
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.Error(e.Message, e);
|
|
SerializeObject("Fehler 550: Internal Server Error");
|
|
}
|
|
}
|
|
|
|
[Authorize]
|
|
public void InsertAppointment(string pStartDate, string pStartTime, string pEndTime, string pSubject, string pNotice, string pEndDate)
|
|
{
|
|
try
|
|
{
|
|
if (Model == null)
|
|
{
|
|
SerializeObject("SessionTimeout");
|
|
}
|
|
|
|
var date = DateTime.Parse(pStartDate);
|
|
var end = DateTime.Parse(pEndDate);
|
|
var zeit = ConvertRecordTimesWithEndDate(pStartTime, pEndTime, date, end, 0);
|
|
var a1 = new List<SchedulerAppointmentDC> {
|
|
new SchedulerAppointmentDC
|
|
{
|
|
EmployeeList = new List<Employee2SchedulerAppointmentDC>(),
|
|
CustomerList = new List<CompactCustomerDC>(),
|
|
ResourceList = new List<ResourceDC>(),
|
|
EndDate = zeit[1],
|
|
StartDate = zeit[0],
|
|
Subject = pSubject,
|
|
Description = pNotice,
|
|
Originator = MobileSessionFacade.LoggedInCompactEmployee
|
|
}
|
|
};
|
|
|
|
KalenderService.InsertSchedulerAppointments(a1);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.Error(e.Message, e);
|
|
SerializeObject("Fehler 520");
|
|
}
|
|
}
|
|
|
|
[Authorize]
|
|
public string LoadBeWoTasks(string newtoday)
|
|
{
|
|
try
|
|
{
|
|
if (Model == null)
|
|
{
|
|
return "SessionTimeout";
|
|
}
|
|
|
|
var date = DateTime.ParseExact(newtoday, "dd.MM.yyyy", null);
|
|
|
|
var tasks = AnalysisService.GetTasksForEmployeeByDate(Model.Employee.EmployeeOid.Value, date);
|
|
|
|
return SerializeObject(tasks);
|
|
}
|
|
|
|
catch (Exception e)
|
|
{
|
|
log.Error(e.Message, e);
|
|
return SerializeObject("Fehler 530");
|
|
}
|
|
}
|
|
|
|
[Authorize]
|
|
public void SaveUnterschrift(string breitengrad, string langengrad, string blob, string zeitstempel, long? ServiceRecord)
|
|
{
|
|
try
|
|
{
|
|
if (Model == null)
|
|
{
|
|
SerializeObject("SessionTimeout");
|
|
}
|
|
|
|
var date = DateTime.Parse(zeitstempel);
|
|
|
|
OperationsService.InsertSignature(new SignatureDC
|
|
{
|
|
DataBild = blob,
|
|
Latitute = breitengrad,
|
|
Longitute = langengrad,
|
|
Zeitstempel = date,
|
|
ServiceRecordOid = ServiceRecord
|
|
});
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.Error(e.Message, e);
|
|
SerializeObject("Fehler 540");
|
|
}
|
|
}
|
|
|
|
public void SetSaveSignature(bool save)
|
|
{
|
|
try
|
|
{
|
|
if (Model == null)
|
|
{
|
|
SerializeObject("SessionTimeout");
|
|
}
|
|
else
|
|
{
|
|
Model.SaveSignature = save;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.Error(e.Message, e);
|
|
SerializeObject("Fehler 777: Fail Error Compilation");
|
|
}
|
|
}
|
|
|
|
public string LoadServiceCategories(long pServiceCategoryOid)
|
|
{
|
|
try
|
|
{
|
|
var scm = Model?.ServiceCategories.FirstOrDefault(s => s.ServiceCategoryOid.Value == pServiceCategoryOid);
|
|
|
|
return SerializeObject(scm != null ? scm.ServiceDescriptions : new List<ServiceDescriptionDC>());
|
|
}
|
|
catch(Exception exception)
|
|
{
|
|
Debug.WriteLine(exception);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[Authorize]
|
|
public string LoadTextbausteineForServiceCategory(long pServiceCategoryOid)
|
|
{
|
|
try
|
|
{
|
|
if (!MobileSessionFacade.CheckForUserRight(UserRightType.TextbausteineNurEigeneAnsehen) && !MobileSessionFacade.CheckForUserRight(UserRightType.TextbausteineAlleAnsehen))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var textbausteine = OperationsService.GetAllTextModules();
|
|
foreach (var tm in textbausteine)
|
|
{
|
|
if (tm.Text == null)
|
|
{
|
|
tm.Text = "";
|
|
}
|
|
}
|
|
if(!MobileSessionFacade.CheckForUserRight(UserRightType.TextbausteineAlleAnsehen))
|
|
{
|
|
textbausteine = textbausteine.Where(w => w.Employee.EmployeeOid == Model.Employee.EmployeeOid).ToList();
|
|
}
|
|
|
|
Model.Textbausteine = textbausteine.Where(w => w.ServiceCategory == null || w.ServiceCategory.ServiceCategoryOid == pServiceCategoryOid).ToList();
|
|
|
|
Model.Textbausteine.AddRangeIfElementsNotIn(Utils.GetParentTextModules(Model.Textbausteine));
|
|
|
|
var displayItems = Model.Textbausteine.Select(s => new TextbausteinDisplayItem(s.TextModuleOid.Value, s.Name, s.Parent?.TextModuleOid, s.IsParent, s.Text)).ToList();
|
|
|
|
foreach(var item in displayItems)
|
|
{
|
|
if(item.ParentOid != null)
|
|
{
|
|
var parent = displayItems.FirstOrDefault(f => f.Oid == item.ParentOid);
|
|
parent?.Children.AddIfNotIn(item);
|
|
}
|
|
}
|
|
|
|
displayItems = displayItems.Where(w => w.ParentOid == null).ToList();
|
|
|
|
return SerializeObject(displayItems);
|
|
}
|
|
catch(Exception exception)
|
|
{
|
|
Debug.WriteLine(exception);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public string LoadCompleteTextbausteinByOid(long pTextbausteinOid)
|
|
{
|
|
var abc = Model.Textbausteine.FirstOrDefault(f => f.TextModuleOid.Value == pTextbausteinOid);
|
|
|
|
return abc.Text;
|
|
}
|
|
|
|
// Ajax-Aufruf zum anzeigen, ob beim Speichern ein Fehler aufgetreten ist.
|
|
public void ErrorZeiterfassungAnzeigen(int errorwert)
|
|
{
|
|
try
|
|
{
|
|
if (Model == null)
|
|
{
|
|
SerializeObject("SessionTimeout");
|
|
}
|
|
else
|
|
{
|
|
Model.ErrorWert = errorwert;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.Error(e.Message, e);
|
|
SerializeObject("Fehler 777: Fail Error Compilation");
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
[Authorize]
|
|
public ActionResult CreateServiceRecord(FormCollection collection)
|
|
{
|
|
try
|
|
{
|
|
if(Model == null)
|
|
{
|
|
return RedirectToActionPermanent("Index", "Login");
|
|
}
|
|
|
|
string doku1;
|
|
|
|
if(Model.Dokutypes != null && Model.Dokutypes.Length > 1)
|
|
{
|
|
doku1 = collection["Dokumentation"];
|
|
}
|
|
else
|
|
{
|
|
doku1 = collection["Dokumentation6"];
|
|
}
|
|
|
|
log.Info($"CreateServiceRecord: datum:{collection["Datum"]}; start:{collection["Start"]}; ende:{collection["Ende"]}; dauer:{collection["Duration"]}; doku:{doku1}; aktion:{collection["versteckt"]}");
|
|
|
|
if(string.IsNullOrEmpty(collection["Datum"]))
|
|
{
|
|
return View("Main", Model);
|
|
}
|
|
|
|
var distanz = collection["Distanz"];
|
|
var distanceInMeters = 0;
|
|
|
|
if(!string.IsNullOrEmpty(distanz))
|
|
{
|
|
if(int.TryParse(distanz, out var parsedDistance))
|
|
{
|
|
distanceInMeters = parsedDistance;
|
|
}
|
|
}
|
|
|
|
var submitBtnVal = collection["versteckt"];
|
|
var selectedCostbearerSCRelOid = Model.CostBearer2SupportConceptOid < 1 ? null : Model.CostBearer2SupportConceptOid;
|
|
var datum = Convert.ToDateTime(collection["Datum"]);
|
|
|
|
var enddatum = datum;
|
|
|
|
var start = collection["Start"];
|
|
var ende = collection["Ende"];
|
|
var dauer = 0;
|
|
|
|
if(datum > enddatum) {
|
|
enddatum = datum;
|
|
}
|
|
|
|
if(!string.IsNullOrEmpty(collection["Duration"]))
|
|
{
|
|
int.TryParse(collection["Duration"], out dauer);
|
|
}
|
|
|
|
var doku2 = collection["Dokumentation2"];
|
|
var doku3 = collection["Dokumentation3"];
|
|
var doku4 = collection["Dokumentation4"];
|
|
var doku5 = collection["Dokumentation5"];
|
|
|
|
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(submitBtnVal.Equals("Speichern"))
|
|
{
|
|
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(!submitBtnVal.Equals("Speichern"))
|
|
{
|
|
Model.NewServiceRecord.Employee = Model.SelectedEmployee ?? MobileSessionFacade.LoggedInCompactEmployee;
|
|
}
|
|
|
|
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 = doku1 == string.Empty ? null : doku1;
|
|
|
|
Model.NewServiceRecord.Notice2 = doku2 == string.Empty ? null : doku2;
|
|
Model.NewServiceRecord.Notice3 = doku3 == string.Empty ? null : doku3;
|
|
Model.NewServiceRecord.Notice4 = doku4 == string.Empty ? null : doku4;
|
|
Model.NewServiceRecord.Notice5 = doku5 == string.Empty ? null : doku5;
|
|
|
|
var serviceDescOid = 0L;
|
|
|
|
if (Model.SelectedServiceDescriptionOid.HasValue)
|
|
{
|
|
serviceDescOid = Model.SelectedServiceDescriptionOid.Value;
|
|
}
|
|
else if (!string.IsNullOrEmpty(collection["ServiceDescription"]))
|
|
{
|
|
serviceDescOid = Convert.ToInt64(collection["ServiceDescription"]);
|
|
}
|
|
|
|
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 submitBtnVal.Equals("Anlegen") ? SaveGroupBooking() : UpdateGroupBooking();
|
|
}
|
|
|
|
if(submitBtnVal.Equals("Anlegen"))
|
|
{
|
|
var oidList = OperationsService.InsertNewServiceRecords(new List<ServiceRecordDC> { Model.NewServiceRecord });
|
|
|
|
Model.ServiceRecordOid = oidList[0];
|
|
}
|
|
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);
|
|
}
|
|
|
|
Model.SaveSignature = Model.ShowSignature;
|
|
|
|
return RedirectToActionPermanent("Main");
|
|
}
|
|
|
|
private ActionResult SaveGroupBooking()
|
|
{
|
|
var employeeCount = Model.SelectedEmployees.Count;
|
|
var personCount = Model.SelectedSupportConcepts.Count;
|
|
|
|
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 list = CalculateGroupBookingDuration(employeeCount, personCount, cb2scOids);
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
Model.SelectedSupportConcepts = new List<SupportConceptDC>();
|
|
Model.SelectedEmployees = new List<CompactEmployeeDC>();
|
|
|
|
return RedirectToActionPermanent("Main");
|
|
}
|
|
|
|
private ActionResult UpdateGroupBooking()
|
|
{
|
|
var dc = Model.SelectedServiceRecord;
|
|
|
|
var group = OperationsService.GetServiceRecordGroup(dc.GroupOid.Value);
|
|
|
|
UpdateServiceRecordGroup(group);
|
|
var employeeCount = Model.SelectedEmployees.Count;
|
|
var customerCount = Model.SelectedSupportConcepts.Count;
|
|
|
|
group.EmployeeCount = employeeCount;
|
|
group.CustomerCount = customerCount;
|
|
|
|
var roundDuration = true;
|
|
var minuteInterval = 0;
|
|
|
|
CompactOrganisationDC org = null;
|
|
|
|
Calculations calc = null;
|
|
var cb2scOids = new List<long>();
|
|
|
|
foreach(var scdc in Model.SelectedSupportConcepts)
|
|
{
|
|
if(scdc.CostBearerRelations.Count > 0)
|
|
{
|
|
cb2scOids.Add(scdc.CostBearerRelations.ElementAt(0).CostBearer2SupportConceptOid.Value);
|
|
|
|
if(org == null)
|
|
{
|
|
org = scdc.CostBearerRelations.ElementAt(0).CostBearer;
|
|
if(org != null)
|
|
{
|
|
minuteInterval = org.ActualMinuteIntervall;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(scdc.CostBearerRelations.ElementAt(0).CostBearer == null || !org.Equals(scdc.CostBearerRelations.ElementAt(0).CostBearer))
|
|
{
|
|
roundDuration = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
var duration = (decimal) (Model.NewServiceRecord.End.Value - Model.NewServiceRecord.Start.Value).TotalMinutes;
|
|
|
|
var lRoundedDuration = duration;
|
|
decimal groupDuration;
|
|
decimal roundedDuration;
|
|
|
|
var gd = OperationsService.CalculateGroupDuration2(customerCount, employeeCount, duration, cb2scOids.ToArray());
|
|
|
|
if(gd != null)
|
|
{
|
|
groupDuration = gd.TotalDuration;
|
|
roundedDuration = gd.SingleDuration;
|
|
}
|
|
else
|
|
{
|
|
if(minuteInterval > 0 && roundDuration)
|
|
{
|
|
lRoundedDuration = duration % minuteInterval != 0 ? duration + (minuteInterval - duration % minuteInterval) : duration;
|
|
}
|
|
|
|
groupDuration = lRoundedDuration;
|
|
roundedDuration = Math.Round(groupDuration / Model.SelectedSupportConcepts.Count, 0 , MidpointRounding.AwayFromZero);
|
|
}
|
|
|
|
Model.NewServiceRecord.RoundedDuration = roundedDuration;
|
|
Model.NewServiceRecord.GroupRoundedDuration = groupDuration;
|
|
|
|
group.Notice = Model.NewServiceRecord.Notice;
|
|
group.Notice2 = Model.NewServiceRecord.Notice2;
|
|
group.Notice3 = Model.NewServiceRecord.Notice3;
|
|
group.Notice4 = Model.NewServiceRecord.Notice4;
|
|
group.Notice5 = Model.NewServiceRecord.Notice5;
|
|
group.RoundedDuration = groupDuration;
|
|
group.StartDate = Model.NewServiceRecord.Start;
|
|
group.EndDate = Model.NewServiceRecord.End;
|
|
|
|
foreach(var item in group.ServiceRecordList)
|
|
{
|
|
item.Notice = Model.NewServiceRecord.Notice;
|
|
item.Notice2 = Model.NewServiceRecord.Notice2;
|
|
item.Notice3 = Model.NewServiceRecord.Notice3;
|
|
item.Notice4 = Model.NewServiceRecord.Notice4;
|
|
item.Notice5 = Model.NewServiceRecord.Notice5;
|
|
item.End = Model.NewServiceRecord.End;
|
|
item.Start = Model.NewServiceRecord.Start;
|
|
item.RoundedDuration = roundedDuration;
|
|
item.DistanceInMeter = Model.NewServiceRecord.DistanceInMeter;
|
|
item.ServiceDescription = Model.NewServiceRecord.ServiceDescription;
|
|
|
|
item.ServiceRecordFormat = Model.NewServiceRecord.ServiceRecordFormat;
|
|
item.DurationInStunden = Model.NewServiceRecord.DurationInStunden;
|
|
|
|
item.ServiceDescription = item.ServiceDescription ?? Model.NewServiceRecord.ServiceDescription;
|
|
|
|
item.GroupEmployeeCount = group.EmployeeCount;
|
|
item.GroupPersonCount = group.CustomerCount;
|
|
item.GroupOid = Model.NewServiceRecord.GroupOid;
|
|
item.GroupRoundedDuration = groupDuration;
|
|
|
|
if(item.CostBearer != null && item.CostBearer.CostBearerOid == null && item.SupportConcept != null && item.SupportConcept.CostBearerList.Count > 0)
|
|
{
|
|
item.CostBearer.CostBearerOid = item.SupportConcept.CostBearerList[0].CostBearerOid;
|
|
}
|
|
}
|
|
|
|
if(Model.NewServiceRecord.GroupOid.HasValue)
|
|
{
|
|
OperationsService.UpdateServiceRecordGroup(group);
|
|
}
|
|
|
|
Model.NewServiceRecord = null;
|
|
Model.SelectedServiceRecord = null;
|
|
Model.SelectedSupportConcepts = new List<SupportConceptDC>();
|
|
Model.SelectedEmployees = new List<CompactEmployeeDC>();
|
|
|
|
//TODO: Die Dauer neuberechnen und die einzelnen ServiceRecords an die Änderungen, die gemacht wurden, anpassen. (Model.SelectedServiceRecord)
|
|
//TODO: Fast alle Eigenschaften von Model.NewServiceRecord kopieren
|
|
|
|
return RedirectToActionPermanent("Main");
|
|
}
|
|
|
|
private IEnumerable<ServiceRecordDC> CalculateGroupBookingDuration(int pEmployeeCount, int pCustomerCount, ICollection<long> cb2ScOids)
|
|
{
|
|
var compactSupportConcepts = CustomerServiceImp.GetCompactSupportConcepts((from sc in Model.SelectedSupportConcepts where sc.SupportConceptOid != null select sc.SupportConceptOid.Value).ToList(), GetUser().Employee.EmployeeOid);
|
|
|
|
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();
|
|
|
|
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;
|
|
|
|
Model.NewServiceRecord.RoundedDuration = (decimal)minutes;
|
|
}
|
|
}
|
|
|
|
sc.GroupRoundedDuration = Model.NewServiceRecord.RoundedDuration;
|
|
|
|
sc.CostBearer2SupportConceptOid = node.SupportConceptTreeNodeDC.SupportConceptCostBearerRelDC.CostBearer2SupportConceptOid;
|
|
|
|
sc.SupportConcept = node.SupportConceptTreeNodeDC.SupportConcept;
|
|
|
|
sc.CostBearer = node.SupportConceptTreeNodeDC.CostBearer;
|
|
|
|
sc.Customer = node.SupportConceptTreeNodeDC.Customer;
|
|
|
|
sc.GroupEmployeeCount = pEmployeeCount;
|
|
|
|
sc.GroupPersonCount = pCustomerCount;
|
|
|
|
list.Add(sc);
|
|
}
|
|
|
|
var roundDuration = false;
|
|
var minuteInterval = 0;
|
|
string calcdId = null;
|
|
var lastMinuteInterval = -1;
|
|
|
|
if(MobileUtils.IsBillable(Model.SelectedServiceDescriptionOid.Value, Model.GetServiceDesctiptions()))
|
|
{
|
|
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;
|
|
|
|
var groupDuration = OperationsService.CalculateGroupDuration2(pCustomerCount, pEmployeeCount, Model.NewServiceRecord.RoundedDuration, nodes.Select(s => s.SupportConceptTreeNodeDC.SupportConceptCostBearerRelDC.CostBearer2SupportConceptOid.Value).ToArray());
|
|
|
|
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);
|
|
}
|
|
|
|
Model.NewServiceRecord.RoundedDuration = Math.Round(totalDuration / pCustomerCount, 0, MidpointRounding.AwayFromZero);
|
|
Model.NewServiceRecord.GroupRoundedDuration = totalDuration;
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
private void UpdateServiceRecordGroup(ServiceRecordGroupDC groupDC)
|
|
{
|
|
var newCount = 0;
|
|
|
|
foreach(var serviceRecord in groupDC.ServiceRecordList)
|
|
{
|
|
if(!serviceRecord.ServiceRecordOid.HasValue)
|
|
{
|
|
newCount++;
|
|
}
|
|
}
|
|
|
|
if(newCount == groupDC.ServiceRecordList.Count)
|
|
{
|
|
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)
|
|
{
|
|
var key = emp.EmployeeOid + "_" + sc.SupportConceptOid;
|
|
if(sc.CostBearerRelations != null && sc.CostBearerRelations.Count > 0)
|
|
{
|
|
var costBearer2SupportConceptOid = sc.CostBearerRelations.ElementAt(0).CostBearer2SupportConceptOid;
|
|
if(costBearer2SupportConceptOid != null)
|
|
{
|
|
key += "_" + costBearer2SupportConceptOid.Value;
|
|
}
|
|
|
|
newKeys.Add(key, key);
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach(var item in groupDC.ServiceRecordList)
|
|
{
|
|
var key = item.Employee.EmployeeOid + "_" + item.SupportConcept.SupportConceptOid;
|
|
if(item.CostBearer2SupportConceptOid.HasValue)
|
|
{
|
|
key += "_" + item.CostBearer2SupportConceptOid.Value;
|
|
}
|
|
|
|
if(newKeys.ContainsKey(key))
|
|
{
|
|
newKeys.Remove(key);
|
|
}
|
|
else
|
|
{
|
|
dcsToChange.Add(item);
|
|
}
|
|
|
|
if(!oldEmps.ContainsKey(item.Employee.EmployeeOid))
|
|
{
|
|
oldEmps.Add(item.Employee.EmployeeOid, item.Employee);
|
|
}
|
|
|
|
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)
|
|
{
|
|
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);
|
|
groupDC.ServiceRecordList.Add(newServiceRecord);
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach(var item in dcsToChange)
|
|
{
|
|
groupDC.ServiceRecordList.Remove(item);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static ServiceRecordDC CloneServiceRecordForGroupBooking(ServiceRecordDC pOriginal)
|
|
{
|
|
var m = pOriginal;
|
|
|
|
var clone = new ServiceRecordDC
|
|
{
|
|
CostBearer = m.CostBearer,
|
|
CostBearer2SupportConceptOid = m.CostBearer2SupportConceptOid,
|
|
Customer = m.Customer,
|
|
Employee = m.Employee,
|
|
End = m.End,
|
|
Goals = m.Goals,
|
|
GroupEmployeeCount = m.GroupEmployeeCount,
|
|
GroupOid = m.GroupOid,
|
|
SignatureOid = m.SignatureOid,
|
|
GroupPersonCount = m.GroupPersonCount,
|
|
GroupRoundedDuration = m.GroupRoundedDuration,
|
|
InsUser = m.InsUser,
|
|
InsertedOn = m.InsertedOn,
|
|
Notice = m.Notice,
|
|
Notice2 = m.Notice2,
|
|
Notice3 = m.Notice3,
|
|
Notice4 = m.Notice4,
|
|
Notice5 = m.Notice5,
|
|
RTFNotice1 = m.RTFNotice1,
|
|
RTFNotice2 = m.RTFNotice2,
|
|
RTFNotice3 = m.RTFNotice3,
|
|
RTFNotice4 = m.RTFNotice4,
|
|
RTFNotice5 = m.RTFNotice5,
|
|
RoundedDuration = m.RoundedDuration,
|
|
ServiceDescription = m.ServiceDescription,
|
|
Start = m.Start,
|
|
SupportConcept = m.SupportConcept,
|
|
ServiceRecordType = m.ServiceRecordType,
|
|
DistanceInMeter = m.DistanceInMeter,
|
|
IP = m.IP,
|
|
Relevance = m.Relevance,
|
|
IsCreatedInMobileClient = true,
|
|
WohnheimbuchungsOid = m.WohnheimbuchungsOid,
|
|
DurationInStunden = m.DurationInStunden,
|
|
ServiceRecordFormat = m.ServiceRecordFormat
|
|
};
|
|
|
|
return clone;
|
|
}
|
|
|
|
[Authorize]
|
|
public ActionResult SaveZeiterfassungAfterCrash(string pDatum, string pStartDate, string pEndDate, string pDuration, string pNotice, string pServiceDescription, string pNotice2, string pNotice3, string pNotice4, string pNotice5, string pEndDate2)
|
|
{
|
|
try
|
|
{
|
|
if (Model == null)
|
|
{
|
|
return RedirectToActionPermanent("Index", "Login");
|
|
}
|
|
|
|
log.Info($"saveZeiterfassungAfterCrash: datum:{pDatum};start:{pStartDate};ende:{pEndDate};dauer:{pDuration};doku:{pNotice};doku2:{pNotice2};doku3:{pNotice3};doku4:{pNotice4};doku5:{pNotice5};pEndDate2:{pEndDate2}");
|
|
|
|
if (string.IsNullOrEmpty(pDatum))
|
|
{
|
|
return View("Main", Model);
|
|
}
|
|
|
|
var selectedCostbearerSCRelOid = Model.CostBearer2SupportConceptOid < 1 ? null : Model.CostBearer2SupportConceptOid;
|
|
var datum = Convert.ToDateTime(pDatum);
|
|
var start = pStartDate;
|
|
var ende = pEndDate;
|
|
var dauer = 0;
|
|
|
|
var enddatum = pEndDate2 != "" ? Convert.ToDateTime(pEndDate2) : datum;
|
|
|
|
if (datum > enddatum)
|
|
{
|
|
enddatum = datum;
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(pDuration))
|
|
{
|
|
int.TryParse(pDuration, out dauer);
|
|
}
|
|
|
|
var doku = pNotice;
|
|
var doku2 = pNotice2;
|
|
var doku3 = pNotice3;
|
|
var doku4 = pNotice4;
|
|
var doku5 = pNotice5;
|
|
|
|
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.Goals = Model.SelectedGoals;
|
|
Model.NewServiceRecord.Start = zeitenFeld[0];
|
|
Model.NewServiceRecord.End = zeitenFeld[1];
|
|
|
|
if (Model.Employee.EmployeeOid != null)
|
|
{
|
|
Model.NewServiceRecord.Employee = Model.SelectedEmployee ?? MobileSessionFacade.LoggedInCompactEmployee;
|
|
|
|
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.Notice = doku;
|
|
|
|
if (doku2 != "")
|
|
{
|
|
Model.NewServiceRecord.Notice2 = doku2;
|
|
}
|
|
if (doku3 != "")
|
|
{
|
|
Model.NewServiceRecord.Notice3 = doku3;
|
|
}
|
|
if (doku4 != "")
|
|
{
|
|
Model.NewServiceRecord.Notice4 = doku4;
|
|
}
|
|
if (doku5 != "")
|
|
{
|
|
Model.NewServiceRecord.Notice5 = doku5;
|
|
}
|
|
|
|
var serviceDescOid = 0L;
|
|
|
|
if (Model.SelectedServiceDescriptionOid.HasValue)
|
|
{
|
|
serviceDescOid = Model.SelectedServiceDescriptionOid.Value;
|
|
}
|
|
else if (!string.IsNullOrEmpty(pServiceDescription))
|
|
{
|
|
serviceDescOid = Convert.ToInt64(pServiceDescription);
|
|
}
|
|
|
|
if (serviceDescOid > 0)
|
|
{
|
|
Model.NewServiceRecord.ServiceDescription = OperationsService.GetServiceDescription(serviceDescOid);
|
|
}
|
|
|
|
Model.NewServiceRecord.IP = Request.UserHostAddress;
|
|
Model.NewServiceRecord.InsertedOn = DateTime.Now;
|
|
Model.NewServiceRecord.InsUser = $"{MobileSessionFacade.LoggedInEmployee.FirstName} {MobileSessionFacade.LoggedInEmployee.LastName}";
|
|
Model.NewServiceRecord.IsCreatedInMobileClient = true;
|
|
|
|
OperationsService.InsertNewServiceRecords(new List<ServiceRecordDC> { Model.NewServiceRecord });
|
|
|
|
Model.NewServiceRecord = new ServiceRecordDC();
|
|
|
|
if (selectedCostbearerSCRelOid.HasValue)
|
|
{
|
|
Model.ServiceRecords = OperationsService.FindServiceRecordsForLastDays(selectedCostbearerSCRelOid, Model.Zeitraum, Model.Employee.EmployeeOid).ToList();
|
|
}
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.Error(e.Message, e);
|
|
Model.ErrorWert = 2;
|
|
//log.Error(e.Message, e);
|
|
}
|
|
|
|
return RedirectToActionPermanent("Main");
|
|
}
|
|
|
|
[HttpPost]
|
|
[Authorize]
|
|
public ActionResult SelectSupportConcept(FormCollection formCollection)
|
|
{
|
|
if(Model == null)
|
|
{
|
|
return RedirectToActionPermanent("Index", "Login");
|
|
}
|
|
|
|
long? cb2scOid = Convert.ToInt64(formCollection["CostBearer2SupportConceptOid"]);
|
|
|
|
Model.CostBearer2SupportConceptOid = cb2scOid;
|
|
Model.SelectedSupportConcept =
|
|
Model.SupportConcepts.FirstOrDefault(
|
|
f =>
|
|
f.CostBearerRelations.Any(
|
|
a =>
|
|
a.CostBearer2SupportConceptOid.HasValue &&
|
|
a.CostBearer2SupportConceptOid.Value.Equals(Model.CostBearer2SupportConceptOid)));
|
|
|
|
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(cb2scOid == -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();
|
|
}
|
|
else if(cb2scOid == -1)
|
|
{
|
|
Model.ServiceCategories.Clear();
|
|
}
|
|
|
|
Model.Zeitraum = 7;
|
|
LoadRecordsToModel();
|
|
|
|
return RedirectToActionPermanent("Main");
|
|
}
|
|
|
|
private static List<ServiceCategoryModel> CreateServiceCategoryModels(IEnumerable<ServiceDescriptionDC> serviceDescriptions)
|
|
{
|
|
var catOid2ModelDict = new Dictionary<long, ServiceCategoryModel>();
|
|
foreach (var sd in serviceDescriptions)
|
|
{
|
|
if (!catOid2ModelDict.ContainsKey(sd.Category.ServiceCategoryOid.Value))
|
|
{
|
|
catOid2ModelDict[sd.Category.ServiceCategoryOid.Value] = new ServiceCategoryModel
|
|
{
|
|
Name = sd.Category.Name,
|
|
IsDefault = sd.Category.IsDefault,
|
|
Percentage = sd.Category.Percentage,
|
|
Position = sd.Category.Position,
|
|
OhneHilfeplan = sd.Category.OhneHilfeplan,
|
|
ServiceCategoryOid = sd.Category.ServiceCategoryOid,
|
|
ServiceDescriptions = new List<ServiceDescriptionDC>()
|
|
};
|
|
}
|
|
|
|
catOid2ModelDict[sd.Category.ServiceCategoryOid.Value].ServiceDescriptions.Add(sd);
|
|
}
|
|
|
|
var list = catOid2ModelDict.Values.ToList();
|
|
|
|
list.Sort((s1, s2) =>
|
|
{
|
|
if (s1.IsDefault)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
return s1.Position != s2.Position ? s1.Position.CompareTo(s2.Position) : s1.ServiceCategoryOid.Value.CompareTo(s2.ServiceCategoryOid.Value);
|
|
});
|
|
|
|
return list;
|
|
}
|
|
|
|
[HttpPost]
|
|
[Authorize]
|
|
public ActionResult DeleteServiceRecord()
|
|
{
|
|
if (Model == null)
|
|
{
|
|
return RedirectToActionPermanent("Index", "Login");
|
|
}
|
|
|
|
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));
|
|
var version = serviceRecordDC?.ServiceRecordVersion;
|
|
|
|
if (version != null)
|
|
{
|
|
OperationsService.DeleteServiceRecord(Model.ServiceRecordOidToDelete.Value, version.Value);
|
|
|
|
Model.ServiceRecords = Model.ServiceRecords.Where(sr => sr.ServiceRecordOid != null && !sr.ServiceRecordOid.Value.Equals(serviceRecordDC.ServiceRecordOid)).ToList();
|
|
}
|
|
}
|
|
|
|
return RedirectToActionPermanent("Main");
|
|
}
|
|
|
|
public void SetRecordOidToDelete(long serviceRecordOid)
|
|
{
|
|
if (Model == null)
|
|
{
|
|
RedirectToActionPermanent("Index", "Login");
|
|
return;
|
|
}
|
|
|
|
Model.ServiceRecordOidToDelete = serviceRecordOid;
|
|
}
|
|
|
|
public void UpdateGoals(long pGoalOid)
|
|
{
|
|
if (Model == null)
|
|
{
|
|
RedirectToActionPermanent("Index", "Login");
|
|
return;
|
|
}
|
|
|
|
var sc = Model.SelectedSupportConcept;
|
|
if (sc == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var goal = sc.Goals.FirstOrDefault(first => first.ValueListEntryOid.HasValue && first.ValueListEntryOid.Value.Equals(pGoalOid));
|
|
|
|
if (Model.SelectedGoals == null)
|
|
{
|
|
Model.SelectedGoals = new List<ValueListEntryDC> { goal };
|
|
return;
|
|
}
|
|
|
|
if (Model.SelectedGoals.Contains(goal))
|
|
{
|
|
Model.SelectedGoals.Remove(goal);
|
|
}
|
|
else
|
|
{
|
|
Model.SelectedGoals.Add(goal);
|
|
}
|
|
}
|
|
|
|
public class GoalTreeItem
|
|
{
|
|
public string Header { get; set; }
|
|
public bool IsLeaf { get; set; }
|
|
public List<GoalTreeItem> Children { get; set; }
|
|
public long? ParentOid { get; set; }
|
|
public long? ValueListEntryOid { get; set; }
|
|
}
|
|
|
|
public void SetServiceDescription(long pServiceDescriptionOid)
|
|
{
|
|
if (Model == null)
|
|
{
|
|
RedirectToActionPermanent("Index", "Login");
|
|
return;
|
|
}
|
|
|
|
Model.SelectedServiceDescriptionOid = pServiceDescriptionOid;
|
|
}
|
|
|
|
[HttpPost]
|
|
[Authorize]
|
|
public ActionResult LoadServiceRecords(FormCollection formCollection)
|
|
{
|
|
if (Model == null)
|
|
{
|
|
return RedirectToActionPermanent("Index", "Login");
|
|
}
|
|
|
|
var zeitraum = int.Parse(formCollection["Records"]);
|
|
if (zeitraum < 0)
|
|
{
|
|
zeitraum = 7;
|
|
}
|
|
|
|
Model.Zeitraum = zeitraum;
|
|
|
|
LoadRecordsToModel();
|
|
|
|
return RedirectToActionPermanent("Main");
|
|
}
|
|
|
|
private void LoadRecordsToModel()
|
|
{
|
|
if(Model.Zeitraum < 0 || Model.CostBearer2SupportConceptOid.HasValue && Model.CostBearer2SupportConceptOid.Value == -1)
|
|
{
|
|
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>();
|
|
|
|
foreach(var r in records.Where(r => !recordsOhneDuplikate.Any(a => a.GroupOid.HasValue && a.GroupOid.Value.Equals(r.GroupOid))))
|
|
{
|
|
recordsOhneDuplikate.Add(r);
|
|
}
|
|
|
|
Model.ServiceRecords = recordsOhneDuplikate;
|
|
}
|
|
|
|
public void SetSelectedServiceRecord(long? recordOid)
|
|
{
|
|
if (Model == null)
|
|
{
|
|
RedirectToActionPermanent("Index", "Login");
|
|
return;
|
|
}
|
|
|
|
Model.SelectedServiceRecordOid = recordOid;
|
|
|
|
if (recordOid == null)
|
|
{
|
|
Model.SelectedGoals = new List<ValueListEntryDC>();
|
|
}
|
|
else
|
|
{
|
|
var serviceRecordDC = Model.ServiceRecords.FirstOrDefault(f => f.ServiceRecordOid.HasValue && f.ServiceRecordOid.Value.Equals(Model.SelectedServiceRecordOid));
|
|
if (serviceRecordDC != null)
|
|
{
|
|
Model.SelectedGoals = serviceRecordDC.Goals;
|
|
}
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
[Authorize]
|
|
public ActionResult SetSelectedGroupServiceRecord(FormCollection pFormCollection)
|
|
{
|
|
if(Model == null)
|
|
{
|
|
return RedirectToActionPermanent("Index", "Login");
|
|
}
|
|
|
|
long.TryParse(pFormCollection["hiddenElement"], out var recordOid);
|
|
|
|
Model.SelectedServiceRecordOid = recordOid;
|
|
|
|
Model.IsInGroupBookingMode = true;
|
|
Model.IsInEditingMode = true;
|
|
|
|
var serviceRecord = Model.ServiceRecords.FirstOrDefault(f => f.ServiceRecordOid == recordOid);
|
|
var supportConcepts = new List<SupportConceptDC>();
|
|
var employees = new List<CompactEmployeeDC>();
|
|
|
|
Model.SelectedServiceRecord = serviceRecord;
|
|
|
|
if(serviceRecord?.GroupOid != null)
|
|
{
|
|
var serviceRecordGroup = OperationsService.GetServiceRecordGroup(serviceRecord.GroupOid.Value);
|
|
|
|
if(serviceRecordGroup != null)
|
|
{
|
|
employees.AddRangeIfElementsNotIn(serviceRecordGroup.ServiceRecordList.Select(s => s.Employee));
|
|
var relationOids = serviceRecordGroup.ServiceRecordList.Select(s => s.CostBearer2SupportConceptOid.Value).ToList();
|
|
var costBearerRelations = CustomerService.GetSupportConceptCostBearerRelationsById(relationOids);
|
|
|
|
foreach(var rel in costBearerRelations)
|
|
{
|
|
var sc = CustomerService.LoadSupportConcept(rel.SupportConcept.SupportConceptOid);
|
|
var oid = sc.SupportConceptOid;
|
|
|
|
if(!supportConcepts.Any(a => a.SupportConceptOid.Equals(oid)))
|
|
{
|
|
supportConcepts.Add(sc);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Model.SelectedSupportConcepts = supportConcepts;
|
|
Model.SelectedEmployees = employees;
|
|
|
|
LoadServiceCategoriesForGroupBooking();
|
|
|
|
return RedirectToActionPermanent("Main");
|
|
}
|
|
|
|
public string GetSelectedRecordInformation()
|
|
{
|
|
var result = string.Empty;
|
|
|
|
if (Model.SelectedServiceRecordOid.HasValue)
|
|
{
|
|
result = SerializeObject(Model.ServiceRecords.First(f => f.ServiceRecordOid == Model.SelectedServiceRecordOid));
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public string GetSelectedRecordInformationWithOid(long oid)
|
|
{
|
|
LoadRecordsToModel();
|
|
|
|
return SerializeObject(Model.ServiceRecords.First(f => f.ServiceRecordOid == oid));
|
|
}
|
|
|
|
private static string SerializeObject(object obj)
|
|
{
|
|
return JsonConvert.SerializeObject(obj, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new ShouldSerializeContractResolver(), ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
|
|
}
|
|
|
|
private static DateTime[] ConvertRecordTimes(string start, string ende, DateTime datum, int dauer)
|
|
{
|
|
var result = new DateTime[2];
|
|
var startDate = datum.Date;
|
|
var endDate = datum.Date;
|
|
|
|
|
|
var dateTemp = ConvertTimeStringToDateTime(start);
|
|
startDate = startDate.AddHours(dateTemp.Hour).AddMinutes(dateTemp.Minute);
|
|
|
|
dateTemp = ConvertTimeStringToDateTime(ende);
|
|
endDate = endDate.AddHours(dateTemp.Hour).AddMinutes(dateTemp.Minute);
|
|
|
|
if (string.IsNullOrEmpty(start) && !string.IsNullOrEmpty(ende))
|
|
{
|
|
startDate = endDate.AddMinutes(-1 * dauer);
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(ende) && !string.IsNullOrEmpty(start))
|
|
{
|
|
endDate = startDate.AddMinutes(dauer);
|
|
}
|
|
|
|
if (endDate < startDate)
|
|
{
|
|
endDate = startDate;
|
|
}
|
|
|
|
result[0] = startDate;
|
|
result[1] = endDate;
|
|
|
|
return result;
|
|
}
|
|
|
|
private static DateTime[] ConvertRecordTimesWithEndDate(string start, string ende, DateTime datum, DateTime enddatum, int dauer)
|
|
{
|
|
var result = new DateTime[2];
|
|
var startDate = datum;
|
|
var endDate = enddatum;
|
|
|
|
var h = 0;
|
|
var m = 0;
|
|
|
|
if (!string.IsNullOrEmpty(start) && (start.Contains(":") || start.Contains(".") || start.Contains(",")))
|
|
{
|
|
var seperator = ':';
|
|
|
|
if (start.Contains("."))
|
|
{
|
|
seperator = '.';
|
|
}
|
|
else if (start.Contains(","))
|
|
{
|
|
seperator = ',';
|
|
}
|
|
|
|
var hm = start.Split(seperator);
|
|
|
|
h = Convert.ToInt32(hm[0]);
|
|
m = Convert.ToInt32(hm[1]);
|
|
}
|
|
else if (!string.IsNullOrEmpty(start))
|
|
{
|
|
m = Convert.ToInt32(start.Substring(start.Length - 2, 2));
|
|
h = Convert.ToInt32(start.Substring(0, start.Length - 2));
|
|
}
|
|
|
|
startDate = startDate.AddHours(h);
|
|
startDate = startDate.AddMinutes(m);
|
|
|
|
if (!string.IsNullOrEmpty(ende) && (ende.Contains(":") || ende.Contains(".") || ende.Contains(",")))
|
|
{
|
|
var seperator2 = ':';
|
|
|
|
if (ende.Contains("."))
|
|
{
|
|
seperator2 = '.';
|
|
}
|
|
else if (ende.Contains(","))
|
|
{
|
|
seperator2 = ',';
|
|
}
|
|
|
|
var hm = ende.Split(seperator2);
|
|
|
|
h = Convert.ToInt32(hm[0]);
|
|
m = Convert.ToInt32(hm[1]);
|
|
}
|
|
else if (!string.IsNullOrEmpty(ende))
|
|
{
|
|
m = Convert.ToInt32(ende.Substring(ende.Length - 2, 2));
|
|
h = Convert.ToInt32(ende.Substring(0, ende.Length - 2));
|
|
}
|
|
|
|
endDate = endDate.AddHours(h);
|
|
endDate = endDate.AddMinutes(m);
|
|
|
|
if (string.IsNullOrEmpty(start) && !string.IsNullOrEmpty(ende))
|
|
{
|
|
startDate = endDate.AddMinutes(-1 * dauer);
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(ende) && !string.IsNullOrEmpty(start))
|
|
{
|
|
endDate = startDate.AddMinutes(dauer);
|
|
}
|
|
|
|
if (endDate < startDate)
|
|
{
|
|
endDate = startDate;
|
|
}
|
|
|
|
if (dauer == 0 || endDate == startDate)
|
|
{
|
|
dauer = (int)(endDate - startDate).TotalMinutes;
|
|
}
|
|
|
|
result[0] = startDate;
|
|
result[1] = endDate;
|
|
|
|
return result;
|
|
}
|
|
|
|
public string CheckRights(string von, string bis, bool inEditMode, string dateString, string startString, string endString)
|
|
{
|
|
if (Model == null)
|
|
{
|
|
return "SessionTimeout";
|
|
}
|
|
|
|
log.Info($"CheckRights: von:{von};bis:{bis};inEditMode:{inEditMode};dateString:{dateString};startString:{startString};endString:{endString}");
|
|
|
|
var startHoursDt = ConvertTimeStringToDateTime(startString);
|
|
var endHoursDt = ConvertTimeStringToDateTime(endString);
|
|
|
|
if (!DateTime.TryParse(dateString, out var date))
|
|
{
|
|
date = DateTime.Now.Date;
|
|
}
|
|
|
|
var startDt = date.AddHours(startHoursDt.Hour).AddMinutes(startHoursDt.Minute);
|
|
var endDt = date.AddHours(endHoursDt.Hour).AddMinutes(endHoursDt.Minute);
|
|
|
|
if (startDt > endDt)
|
|
{
|
|
return "StartGreaterEnd";
|
|
}
|
|
var dauer = (int)(endDt - startDt).TotalMinutes;
|
|
|
|
if (dauer == 0)
|
|
{
|
|
startDt = startDt.AddSeconds(1);
|
|
endDt = endDt.AddSeconds(1);
|
|
}
|
|
|
|
var checkSR = new ServiceRecordDC();
|
|
if (inEditMode)
|
|
{
|
|
checkSR = Model.ServiceRecords.FirstOrDefault(f => f.ServiceRecordOid.HasValue && f.ServiceRecordOid.Value.Equals(Model.SelectedServiceRecordOid));
|
|
}
|
|
|
|
if (checkSR == null)
|
|
{
|
|
checkSR = new ServiceRecordDC();
|
|
}
|
|
|
|
checkSR.Goals = Model.SelectedGoals;
|
|
|
|
checkSR.Start = startDt;
|
|
checkSR.End = endDt;
|
|
|
|
if (Model.Employee.EmployeeOid != null)
|
|
{
|
|
checkSR.Employee = MobileSessionFacade.LoggedInCompactEmployee;
|
|
|
|
var sc = Model.SupportConcepts.FirstOrDefault(fod => fod.CostBearerRelations.Any(a => a.CostBearer2SupportConceptOid.HasValue && a.CostBearer2SupportConceptOid.Value.Equals(Model.CostBearer2SupportConceptOid)));
|
|
|
|
if (sc != null)
|
|
{
|
|
if (sc.SupportConceptOid != null)
|
|
{
|
|
checkSR.SupportConcept = CustomerService.LoadCompactSupportConceptDC(sc.SupportConceptOid.Value, Model.Employee.EmployeeOid);
|
|
}
|
|
|
|
checkSR.Customer = sc.Customer;
|
|
var cb2ScRel = sc.CostBearerRelations.First(f => f.CostBearer2SupportConceptOid.HasValue && f.CostBearer2SupportConceptOid.Equals(Model.CostBearer2SupportConceptOid));
|
|
checkSR.CostBearer = cb2ScRel.CostBearer;
|
|
var intervall = checkSR.CostBearer.ActualMinuteIntervall;
|
|
|
|
if (intervall > 0)
|
|
{
|
|
checkSR.RoundedDuration = dauer % intervall != 0 ? dauer + (intervall - (dauer % intervall)) : dauer;
|
|
}
|
|
|
|
checkSR.CostBearer2SupportConceptOid = Model.CostBearer2SupportConceptOid;
|
|
}
|
|
}
|
|
|
|
checkSR.IP = Request.UserHostAddress;
|
|
checkSR.InsertedOn = DateTime.Now;
|
|
checkSR.InsUser = $"{MobileSessionFacade.LoggedInEmployee.FirstName} {MobileSessionFacade.LoggedInEmployee.LastName}";
|
|
|
|
checkSR.ServiceDescription = OperationsService.GetServiceDescription(Model.SelectedServiceDescriptionOid.Value);
|
|
|
|
var man = OperationsService.GetMandator();
|
|
var s = man.Settings ?? string.Empty;
|
|
var einzeln = s.Split(';');
|
|
var g = einzeln.ToList().FirstOrDefault(f => f.Contains("MaxDaysEditServiceRecordsAllowed"));
|
|
var t = g != null ? int.Parse(g.Split('=')[1]) : 0;
|
|
|
|
SupportConceptStatisticsDC stats = null;
|
|
|
|
if (Model.CostBearer2SupportConceptOid != null && Model.CostBearer2SupportConceptOid > 0)
|
|
{
|
|
stats = OperationsService.CreateSupportConceptStatistics(Model.CostBearer2SupportConceptOid.Value, DateTime.Now);
|
|
}
|
|
|
|
var result = OperationsService.ValidateServiceRecordEntry(checkSR, stats, t, false, new List<long> { checkSR.Employee.EmployeeOid });
|
|
var valStruct = new ValidationStruct
|
|
{
|
|
ValidationResults = result,
|
|
Rights = new Dictionary<int, bool>(),
|
|
MaxDaysEditServiceRecordsAllowed = t.ToString()
|
|
};
|
|
|
|
valStruct.Rights.Add(0, MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.ServiceRecord_AllowCreateOverlappingFLS))));
|
|
valStruct.Rights.Add(1, MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.ServiceRecord_AllowCreateMoreFLSThanApproved))));
|
|
valStruct.Rights.Add(2, MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.BookServiceRecordAfterSettlementInvoice))));
|
|
|
|
Model.NewServiceRecord = new ServiceRecordDC();
|
|
|
|
return SerializeObject(valStruct);
|
|
}
|
|
|
|
public bool CheckRightsAfterCrash(string von, string bis, bool inEditMode, string dateString, string startString, string endString, long costbearerOId, string leistung)
|
|
{
|
|
if (Model == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
log.Info($"CheckRightsAfterCrash: von:{von};bis:{bis};inEditMode:{inEditMode};dateString:{dateString};startString:{startString};endString:{endString}");
|
|
|
|
var date = DateTime.Now.Date;
|
|
|
|
var startHoursDt = ConvertTimeStringToDateTime(startString);
|
|
var endHoursDt = ConvertTimeStringToDateTime(endString);
|
|
|
|
if (!DateTime.TryParse(dateString, out date))
|
|
{
|
|
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)
|
|
{
|
|
Model.ErrorWert = 5;
|
|
return false;
|
|
}
|
|
|
|
var dauer = (int)(endDt - startDt).TotalMinutes;
|
|
|
|
if (dauer == 0)
|
|
{
|
|
startDt = startDt.AddSeconds(1);
|
|
endDt = endDt.AddSeconds(1);
|
|
}
|
|
|
|
var checkSR = new ServiceRecordDC
|
|
{
|
|
Goals = Model.SelectedGoals,
|
|
Start = startDt,
|
|
End = endDt
|
|
};
|
|
|
|
if (Model.Employee.EmployeeOid != null)
|
|
{
|
|
checkSR.Employee = MobileSessionFacade.LoggedInCompactEmployee;
|
|
|
|
_Model.CostBearer2SupportConceptOid = costbearerOId;
|
|
|
|
var sc = Model.SupportConcepts.FirstOrDefault(fod => fod.CostBearerRelations.Any(a => a.CostBearer2SupportConceptOid.HasValue && a.CostBearer2SupportConceptOid.Value.Equals(Model.CostBearer2SupportConceptOid)));
|
|
|
|
if (sc != null)
|
|
{
|
|
if (sc.SupportConceptOid != null)
|
|
{
|
|
checkSR.SupportConcept = CustomerService.LoadCompactSupportConceptDC(sc.SupportConceptOid.Value, Model.Employee.EmployeeOid);
|
|
}
|
|
|
|
checkSR.Customer = sc.Customer;
|
|
var cb2ScRel = sc.CostBearerRelations.First(f => f.CostBearer2SupportConceptOid.HasValue && f.CostBearer2SupportConceptOid.Equals(Model.CostBearer2SupportConceptOid));
|
|
checkSR.CostBearer = cb2ScRel.CostBearer;
|
|
var intervall = checkSR.CostBearer.ActualMinuteIntervall;
|
|
|
|
if (intervall > 0)
|
|
{
|
|
checkSR.RoundedDuration = dauer % intervall != 0 ? dauer + (intervall - (dauer % intervall)) : dauer;
|
|
}
|
|
|
|
checkSR.CostBearer2SupportConceptOid = Model.CostBearer2SupportConceptOid;
|
|
}
|
|
}
|
|
|
|
checkSR.IP = Request.UserHostAddress;
|
|
checkSR.InsertedOn = DateTime.Now;
|
|
checkSR.InsUser = $"{MobileSessionFacade.LoggedInEmployee.FirstName} {MobileSessionFacade.LoggedInEmployee.LastName}";
|
|
|
|
if (leistung != null || leistung == "")
|
|
{
|
|
Model.SelectedServiceDescriptionOid = Convert.ToInt64(leistung);
|
|
}
|
|
else
|
|
{
|
|
Model.SelectedServiceDescriptionOid = 6;
|
|
}
|
|
|
|
checkSR.ServiceDescription = OperationsService.GetServiceDescription(Model.SelectedServiceDescriptionOid.Value);
|
|
|
|
var man = OperationsService.GetMandator();
|
|
var s = man.Settings ?? string.Empty;
|
|
var einzeln = s.Split(';');
|
|
var g = einzeln.ToList().FirstOrDefault(f => f.Contains("MaxDaysEditServiceRecordsAllowed"));
|
|
var t = g != null ? int.Parse(g.Split('=')[1]) : 0;
|
|
|
|
SupportConceptStatisticsDC stats = null;
|
|
|
|
if (Model.CostBearer2SupportConceptOid != null && Model.CostBearer2SupportConceptOid > 0)
|
|
{
|
|
stats = OperationsService.CreateSupportConceptStatistics(Model.CostBearer2SupportConceptOid.Value, DateTime.Now);
|
|
}
|
|
|
|
var result = OperationsService.ValidateServiceRecordEntry(checkSR, stats, t, false, new List<long> { checkSR.Employee.EmployeeOid });
|
|
|
|
if (result.Count != 0)
|
|
{
|
|
if (result[0].EndDate.Day <= date.Day && result[0].EndDate.Year <= date.Year && result[0].EndDate.Month <= date.Month ||
|
|
result[0].EndDate.Day >= date.Day && result[0].EndDate.Year <= date.Year && result[0].EndDate.Month <= date.Month ||
|
|
result[0].EndDate.Day <= date.Day && result[0].EndDate.Year <= date.Year && result[0].EndDate.Month >= date.Month ||
|
|
result[0].EndDate.Day >= date.Day && result[0].EndDate.Year <= date.Year && result[0].EndDate.Month >= date.Month)
|
|
{
|
|
Model.ErrorWert = 4;
|
|
return false;
|
|
}
|
|
|
|
Model.ErrorWert = 3;
|
|
return false;
|
|
}
|
|
|
|
Model.ErrorWert = 1;
|
|
return true;
|
|
}
|
|
|
|
private static DateTime ConvertTimeStringToDateTime(string timeString)
|
|
{
|
|
var dt = DateTime.Now.Date;
|
|
|
|
if (string.IsNullOrEmpty(timeString))
|
|
{
|
|
timeString = "0000";
|
|
}
|
|
|
|
var numberString = Regex.Replace(timeString, "[^0-9]", "");
|
|
|
|
if (numberString.Length < 3)
|
|
{
|
|
if (numberString.Length < 2)
|
|
{
|
|
numberString = "0" + numberString;
|
|
}
|
|
while (numberString.Length < 4)
|
|
{
|
|
numberString = numberString + "0";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
while (numberString.Length < 4)
|
|
{
|
|
numberString = "0" + numberString;
|
|
}
|
|
}
|
|
|
|
if (numberString.Length > 4)
|
|
{
|
|
numberString = numberString.Substring(0, 4);
|
|
}
|
|
|
|
var hours = Convert.ToInt32(numberString.Substring(0, 2));
|
|
var minutes = Convert.ToInt32(numberString.Substring(2, 2));
|
|
|
|
dt = dt.AddHours(hours);
|
|
dt = dt.AddMinutes(minutes);
|
|
|
|
return dt;
|
|
}
|
|
|
|
private struct ValidationStruct
|
|
{
|
|
public List<ServiceRecordValidationResultDC> ValidationResults { get; set; }
|
|
public Dictionary<int, bool> Rights { get; set; }
|
|
public string MaxDaysEditServiceRecordsAllowed { get; set; }
|
|
}
|
|
|
|
public void SetViewMode()
|
|
{
|
|
if (Model == null)
|
|
{
|
|
RedirectToActionPermanent("Index", "Login");
|
|
return;
|
|
}
|
|
|
|
Model.SelectedCustomer = null;
|
|
Model.SelectedCustomerOid = null;
|
|
}
|
|
|
|
public string GetSelectedSupportConceptCustomer()
|
|
{
|
|
return Model.SelectedSupportConcept == null ? "NoSupportConceptSelected" : SerializeObject(Model.SelectedSupportConcept.Customer.CustomerOid);
|
|
}
|
|
|
|
public string GetSelectedCustomer(long customerOid)
|
|
{
|
|
if (Model == null)
|
|
{
|
|
return "SessionTimeout";
|
|
}
|
|
|
|
Model.SelectedCustomer = CustomerService.LoadCustomer(customerOid);
|
|
Model.SelectedCustomerOid = customerOid;
|
|
|
|
|
|
return SerializeObject(GetJSONCustomer(Model.SelectedCustomer));
|
|
}
|
|
|
|
private static JSONCustomer GetJSONCustomer(CustomerDC pCustomer)
|
|
{
|
|
return new JSONCustomer(pCustomer);
|
|
}
|
|
|
|
public void SetServiceRecordEmployee(long employeeOid)
|
|
{
|
|
if (Model == null)
|
|
{
|
|
RedirectToActionPermanent("Index", "Login");
|
|
return;
|
|
}
|
|
|
|
Model.SelectedEmployee = MainModel.AllEmployees.First(f => f.EmployeeOid.Equals(employeeOid));
|
|
}
|
|
|
|
public string CheckToken(string token)
|
|
{
|
|
if(token != null && token.Equals("abcd"))
|
|
{
|
|
return SerializeObject("localhost;demo");
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public void AddSupportConceptToGruppenbuchung(long pCostBearer2SupportConceptOid)
|
|
{
|
|
var selectedSupportConcept = Model.SupportConcepts.FirstOrDefault(
|
|
f =>
|
|
f.CostBearerRelations.Any(
|
|
a =>
|
|
a.CostBearer2SupportConceptOid.HasValue &&
|
|
a.CostBearer2SupportConceptOid.Value.Equals(pCostBearer2SupportConceptOid)));
|
|
|
|
if(selectedSupportConcept != null)
|
|
{
|
|
if(Model.SelectedSupportConcepts == null)
|
|
{
|
|
Model.SelectedSupportConcepts = new List<SupportConceptDC>();
|
|
}
|
|
|
|
Model.SelectedSupportConcepts.AddIfNotIn(selectedSupportConcept);
|
|
}
|
|
}
|
|
|
|
public void AddEmployeeToGruppenbuchung(long pEmployeeOid)
|
|
{
|
|
var selectedEmployee = Model.Employees.FirstOrDefault(f => f.EmployeeOid == pEmployeeOid);
|
|
|
|
if(Model.SelectedEmployees == null)
|
|
{
|
|
Model.SelectedEmployees = new List<CompactEmployeeDC> {selectedEmployee};
|
|
}
|
|
else
|
|
{
|
|
Model.SelectedEmployees.AddIfNotIn(selectedEmployee);
|
|
}
|
|
}
|
|
|
|
public void RemoveEmployeeFromGruppenbuchung(long pEmployeeOid)
|
|
{
|
|
var selectedEmployee = Model.Employees.FirstOrDefault(f => f.EmployeeOid == pEmployeeOid);
|
|
|
|
Model.SelectedEmployees?.Remove(selectedEmployee);
|
|
}
|
|
|
|
[HttpPost]
|
|
[Authorize]
|
|
public ActionResult RemoveSupportConceptFromGruppenbuchung(FormCollection pFormCollection)
|
|
{
|
|
var selectedCostBearer2SupportConceptOid = long.Parse(pFormCollection["elementToBeRemoved"]);
|
|
|
|
var selectedSupportConcept = Model.SelectedSupportConcepts.FirstOrDefault(
|
|
f =>
|
|
f.CostBearerRelations.Any(
|
|
a =>
|
|
a.CostBearer2SupportConceptOid.HasValue &&
|
|
a.CostBearer2SupportConceptOid.Value.Equals(selectedCostBearer2SupportConceptOid)));
|
|
|
|
if(selectedSupportConcept != null)
|
|
{
|
|
Model.SelectedSupportConcepts?.Remove(selectedSupportConcept);
|
|
Model.SelectedCostbearer2SupportConceptOids.Remove(selectedCostBearer2SupportConceptOid);
|
|
}
|
|
|
|
return RedirectToAction("Main");
|
|
}
|
|
|
|
private void LoadServiceCategoriesForGroupBooking()
|
|
{
|
|
if(Model?.SelectedSupportConcepts == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var allServiceDescriptions = new List<List<ServiceDescriptionDC>>();
|
|
|
|
foreach(var supportConcept in Model.SelectedSupportConcepts)
|
|
{
|
|
foreach(var costBearer2SupportConcept in supportConcept.CostBearerRelations)
|
|
{
|
|
var details = OperationsService.GetSupportConceptTreeNodeDetailInfo(supportConcept.Customer.CustomerOid, supportConcept.SupportConceptOid, costBearer2SupportConcept.CostBearer2SupportConceptOid);
|
|
|
|
var serviceDescriptions = details.ServiceAccountings.Select(serviceAccounting => serviceAccounting.ServiceDescription).ToList();
|
|
|
|
allServiceDescriptions.Add(serviceDescriptions);
|
|
}
|
|
}
|
|
|
|
var result = allServiceDescriptions.Count == 0 ? new List<ServiceDescriptionDC>() : allServiceDescriptions.ElementAt(0);
|
|
result = allServiceDescriptions.Aggregate(result, (current, list) => current.Intersect(list).ToList());
|
|
|
|
if(result.Count == 0)
|
|
{
|
|
allServiceDescriptions.DoForEach(result.AddRangeIfElementsNotIn);
|
|
}
|
|
|
|
Model.ServiceCategories = CreateServiceCategoryModels(result);
|
|
}
|
|
|
|
[HttpPost]
|
|
[Authorize]
|
|
public ActionResult SetGroupBookingMode(FormCollection pFormCollection)
|
|
{
|
|
var isInGroupBookingMode = "true,false" == pFormCollection["IsInGroupBookingMode"];
|
|
|
|
Model.IsInGroupBookingMode = isInGroupBookingMode;
|
|
|
|
if(isInGroupBookingMode)
|
|
{
|
|
Model.SelectedSupportConcept = null;
|
|
Model.SelectedEmployee = null;
|
|
Model.SelectedEmployeeOid = null;
|
|
}
|
|
|
|
return RedirectToAction("Main");
|
|
}
|
|
|
|
[HttpPost]
|
|
[Authorize]
|
|
public ActionResult SelectSupportConceptForGroupBooking(FormCollection pFormCollection)
|
|
{
|
|
var costBearer2SupportConceptOid = long.Parse(pFormCollection["CostBearer2SupportConceptOid"]);
|
|
|
|
if(Model.SelectedCostbearer2SupportConceptOids == null)
|
|
{
|
|
Model.SelectedCostbearer2SupportConceptOids = new List<long>();
|
|
}
|
|
|
|
if(Model.SelectedSupportConcepts == null)
|
|
{
|
|
Model.SelectedSupportConcepts = new List<SupportConceptDC>();
|
|
}
|
|
|
|
Model.SelectedCostbearer2SupportConceptOids.Add(costBearer2SupportConceptOid);
|
|
|
|
var suppenKonzert = Model.SupportConcepts.FirstOrDefault(f => f.CostBearerRelations.Any(a => a.CostBearer2SupportConceptOid == costBearer2SupportConceptOid));
|
|
|
|
Model.SelectedSupportConcepts.AddIfNotIn(suppenKonzert);
|
|
|
|
LoadServiceCategoriesForGroupBooking();
|
|
|
|
return RedirectToAction("Main");
|
|
}
|
|
|
|
[HttpPost]
|
|
[Authorize]
|
|
public ActionResult RemoveEmployeeFromGruppenbuchung(FormCollection pFormCollection)
|
|
{
|
|
var selectedEmployeeOid = long.Parse(pFormCollection["employeeToRemove"]);
|
|
var selectedEmployee = Model.SelectedEmployees.FirstOrDefault(f => f.EmployeeOid == selectedEmployeeOid);
|
|
|
|
if(selectedEmployee != null)
|
|
{
|
|
Model.SelectedEmployees?.Remove(selectedEmployee);
|
|
}
|
|
|
|
return RedirectToAction("Main");
|
|
}
|
|
|
|
[HttpPost]
|
|
[Authorize]
|
|
public ActionResult SelectEmployeeForGroupBooking(FormCollection pFormCollection)
|
|
{
|
|
var employeeOid = long.Parse(pFormCollection["SelectedEmployeeOid"]);
|
|
|
|
var selectedEmployee = Model.Employees.FirstOrDefault(f => f.EmployeeOid == employeeOid);
|
|
|
|
if(selectedEmployee != null)
|
|
{
|
|
Model.SelectedEmployees.AddIfNotIn(selectedEmployee);
|
|
}
|
|
|
|
return RedirectToAction("Main");
|
|
}
|
|
|
|
[HttpPost]
|
|
[Authorize]
|
|
public ActionResult ResetEditingMode(FormCollection pFormCollection)
|
|
{
|
|
Model.NewServiceRecord = new ServiceRecordDC();
|
|
Model.SelectedServiceRecord = null;
|
|
Model.SelectedSupportConcepts.Clear();
|
|
Model.SelectedEmployees.Clear();
|
|
Model.IsInGroupBookingMode = false;
|
|
Model.IsInEditingMode = false;
|
|
|
|
return RedirectToActionPermanent("Main");
|
|
}
|
|
|
|
[HttpPost]
|
|
[Authorize]
|
|
public ActionResult SelectSupportConceptGroup(FormCollection pFormCollection)
|
|
{
|
|
var groupOid2RelationOidsRaw1 = pFormCollection["SelectedGroupInfo"];
|
|
|
|
var groupOid2RelationOidsRaw2 = groupOid2RelationOidsRaw1.Split(":");
|
|
|
|
var relationOids = new List<long>();
|
|
|
|
groupOid2RelationOidsRaw2[1].Split(",").DoForEach(d => relationOids.AddIfNotIn(long.Parse(d)));
|
|
|
|
var supportConcepts = CustomerService.GetSupportConceptsById(CustomerService.GetSupportConceptCostBearerRelationsById(relationOids).Select(s => s.SupportConcept).Select(s => s.SupportConceptOid));
|
|
|
|
var newOids = supportConcepts.Select(s => s.SupportConceptOid.Value).ToList();
|
|
var oldOids = Model.SelectedSupportConcepts.Select(s => s.SupportConceptOid.Value).ToList();
|
|
|
|
Model.SelectedCostbearer2SupportConceptOids.AddRangeIfElementsNotIn(relationOids);
|
|
Model.SelectedSupportConcepts.AddRangeIfElementsNotIn(supportConcepts);
|
|
|
|
LoadServiceCategoriesForGroupBooking();
|
|
|
|
return RedirectToActionPermanent("Main");
|
|
}
|
|
|
|
public string LoadCategoryAndDescription()
|
|
{
|
|
var serviceDescriptionOid = Model.SelectedServiceRecord.ServiceDescription.ServiceDescriptionOid.ToString();
|
|
var serviceCategoryOid = Model.SelectedServiceRecord.ServiceDescription.Category.ServiceCategoryOid.ToString();
|
|
|
|
return $"{serviceDescriptionOid}/{serviceCategoryOid}";
|
|
}
|
|
}
|
|
|
|
internal class JSONCustomer
|
|
{
|
|
public string Vorname { get; set; }
|
|
public string Nachname { get; set; }
|
|
public string Geburtstag { get; set; }
|
|
public string Geschlecht { get; set; }
|
|
|
|
public string Adresszusatz { get; set; }
|
|
public string Strasse { get; set; }
|
|
public string Postleitzahl { get; set; }
|
|
public string Ort { get; set; }
|
|
|
|
public string RechnungsadresseName { get; set; }
|
|
public string RechnungsadresseStrasse { get; set; }
|
|
public string RechnungsadressePostleitzahl { get; set; }
|
|
public string RechnungsadresseOrt { get; set; }
|
|
|
|
public string EMail { get; set; }
|
|
public string Fax { get; set; }
|
|
public string Telefon { get; set; }
|
|
public string Handy { get; set; }
|
|
|
|
public List<Umfeldsperson> Umfeldpersonen { get; set; }
|
|
|
|
public JSONCustomer(CustomerDC init)
|
|
{
|
|
Vorname = init.FirstName;
|
|
Nachname = init.LastName;
|
|
Geburtstag = init.DateOfBirth?.ToShortDateString() ?? String.Empty;
|
|
Geschlecht = init.Sex == Sex.Male ? "Männlich" : "Weiblich";
|
|
|
|
Adresszusatz = init.AddressLine1;
|
|
Strasse = init.Street;
|
|
Postleitzahl = init.PostalCode;
|
|
Ort = init.Town;
|
|
|
|
RechnungsadresseName = init.InvoiceAddressLine1;
|
|
RechnungsadresseStrasse = init.InvoiceAddressStreet;
|
|
RechnungsadressePostleitzahl = init.InvoiceAddressPostalCode;
|
|
RechnungsadresseOrt = init.InvoiceAddressTown;
|
|
|
|
foreach (var iContactDC in init.ContactInformations)
|
|
{
|
|
switch(iContactDC.ContactType)
|
|
{
|
|
case ContactType.business_Mail:
|
|
EMail = iContactDC.ContactValue;
|
|
break;
|
|
case ContactType.business_Fax:
|
|
Fax = iContactDC.ContactValue;
|
|
break;
|
|
case ContactType.business_Phone:
|
|
Telefon = iContactDC.ContactValue;
|
|
break;
|
|
case ContactType.business_MobilePhone:
|
|
Handy = iContactDC.ContactValue;
|
|
break;
|
|
}
|
|
}
|
|
|
|
Umfeldpersonen = new List<Umfeldsperson>();
|
|
|
|
foreach (var rel in init.EnvironmentPersons)
|
|
{
|
|
Umfeldpersonen.Add(new Umfeldsperson(rel));
|
|
}
|
|
}
|
|
}
|
|
|
|
internal class Umfeldsperson
|
|
{
|
|
public string Vorname { get; set; }
|
|
public string Nachname { get; set; }
|
|
public string StrNameNr { get; set; }
|
|
public string PLZOrt { get; set; }
|
|
public string TelNr { get; set; }
|
|
public string Mobil { get; set; }
|
|
public string EMail { get; set; }
|
|
public string Fax { get; set; }
|
|
public string Rolle { get; set; }
|
|
public string Titel { get; set; }
|
|
|
|
public Umfeldsperson(CustomerPersonRelationDC umfeldspersonDC)
|
|
{
|
|
var person = umfeldspersonDC.Person;
|
|
|
|
Rolle = person.Function ?? "";
|
|
Vorname = person.FirstName ?? "";
|
|
Nachname = person.LastName ?? "";
|
|
StrNameNr = person.Street ?? "";
|
|
PLZOrt = $"{person.PostalCode} {person.Town}" ?? "";
|
|
TelNr = person.Communication1 ?? "";
|
|
Mobil = person.Communication2 ?? "";
|
|
EMail = person.Communication3 ?? "";
|
|
Fax = person.Communication4 ?? "";
|
|
Titel = person.Title ?? "";
|
|
}
|
|
}
|
|
|
|
internal class TextbausteinDisplayItem
|
|
{
|
|
public string Name { get; set; }
|
|
public long Oid { get; set; }
|
|
public long? ParentOid { get; set; }
|
|
public bool IsParent { get; set; }
|
|
public string Text { get; set; }
|
|
public List<TextbausteinDisplayItem> Children { get; set; }
|
|
|
|
public TextbausteinDisplayItem(long pOid, string pName, long? pParentOid, bool pIsParent, string pText)
|
|
{
|
|
Oid = pOid;
|
|
Name = pName;
|
|
ParentOid = pParentOid;
|
|
IsParent = pIsParent;
|
|
Text = pText;
|
|
|
|
Children = new List<TextbausteinDisplayItem>();
|
|
}
|
|
}
|
|
|
|
internal class RecurrenceInformation
|
|
{
|
|
public string PatternId { get; set; }
|
|
public int Index { get; set; }
|
|
|
|
public RecurrenceInformation(string pPatternId, int pIndex)
|
|
{
|
|
PatternId = pPatternId;
|
|
Index = pIndex;
|
|
}
|
|
}
|
|
}
|