Files
BeWoPlaner/BeWoPlanerMobil/Controllers/MainController.cs

1892 lines
72 KiB
C#
Raw Normal View History

2016-06-27 01:45:38 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web.Mvc;
2016-06-27 01:45:38 +02:00
using BeWoPlanerMobil.Models;
using BeWoPlanerMobil.Service;
2016-06-27 01:45:38 +02:00
using BS.Shared;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using BS.Shared.Extensions;
2016-06-27 01:45:38 +02:00
using Newtonsoft.Json;
using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.Compatibility;
2016-06-27 01:45:38 +02:00
namespace BeWoPlanerMobil.Controllers
{
public class MainController : AbstractBaseController
{
private MainModel _Model;
2016-06-27 01:45:38 +02:00
public MainModel Model
{
get
{
if (!MobileSessionFacade.IsUserLoggedIn())
{
RedirectToActionPermanent("Index", "Login");
return null;
}
if (((MainModel) Session[MainModelSessionKey])?.Employee == null)
2016-06-27 01:45:38 +02:00
{
_Model = new MainModel { Employee = MobileSessionFacade.LoggedInEmployee };
Session[MainModelSessionKey] = _Model;
2016-06-27 01:45:38 +02:00
}
else
{
_Model = (MainModel)Session[MainModelSessionKey];
2016-06-27 01:45:38 +02:00
}
return _Model;
2016-06-27 01:45:38 +02:00
}
}
2017-04-26 14:57:32 +02:00
private const string MainModelSessionKey = "MainModel";
private Dictionary<long, ValueListEntryDC> _ParentGoals;
2016-06-27 01:45:38 +02:00
private static readonly List<ValueListEntryType> _Zieltypen = new List<ValueListEntryType> { ValueListEntryType.SupportConceptGoalCategoryType, ValueListEntryType.SupportConceptIndividualGoalCategoryType };
private static readonly List<ValueListEntryType> _Massnahmentypen = new List<ValueListEntryType> { ValueListEntryType.SupportConceptGoalType, ValueListEntryType.SupportConceptIndividualGoalType };
2016-06-27 01:45:38 +02:00
[Authorize]
public ActionResult Main()
{
try
{
ViewData["ValidationError"] = string.Empty;
2016-06-27 01:45:38 +02:00
if (!MobileSessionFacade.IsUserLoggedIn() || Request.Browser.Browser.Equals("InternetExplorer"))
{
return RedirectToActionPermanent("Index", "Login");
}
2016-06-27 01:45:38 +02:00
2017-02-01 13:53:59 +01:00
var unter = GetSettingValue("ShowSignature");
Model.ShowSignature = unter == "1";
var test = Model.SaveSignature;
2017-02-01 13:53:59 +01:00
Model.SelectedGoals = null;
Model.ShowDistanceField = "1" == GetSettingValue("ShowDistanceFields");
2017-02-01 13:53:59 +01:00
Model.Dokutypes = ValueListService.GetAllValueListEntrysByType(ValueListEntryType.DocumentType);
if (Model.Dokutypes != null)
{
Model.Dokutypes = Model.Dokutypes.OrderBy(s => s.ValueListEntryOid).ToArray();
}
if(MainModel.AllEmployees == null)
2016-06-27 01:45:38 +02:00
{
MainModel.AllEmployees = EmployeeService.GetAllActiveEmployeesCompact();
}
var myRelatedCustomers = Model.Employee == null ? new List<CustomerEmployeeRelationDC>() : Model.Employee.RelatedCustomers;
if (MobileSessionFacade.CheckForUserRight(UserRightType.CustomerView_View))
{
Model.Customers = CustomerService.GetAllActiveCustomers().OrderBy(k => k.LastName).ToList();
}
else if(MobileSessionFacade.CheckForUserRight(UserRightType.Customer_ViewMyCustomers))
2016-06-27 01:45:38 +02:00
{
Model.Customers = CustomerService.GetActiveCustomersById(myRelatedCustomers.Select(c => c.Customer.CustomerOid).ToList()).OrderBy(k => k.LastName).ToList();
}
else
{
Model.Customers = new List<CustomerDC>();
}
if(MobileSessionFacade.CheckForUserRight(UserRightType.ServiceRecord_AllowCreationForOtherEmployees))
2016-06-27 01:45:38 +02:00
{
Model.Employees = EmployeeService.GetAllActiveEmployeesCompact();
}
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 };
}
if(Model.ShowOnlyOwnSupportConcepts == false && MobileSessionFacade.CheckForUserRight(UserRightType.SupportConcept_ViewAllSupportConcepts))
2016-06-27 01:45:38 +02:00
{
Model.SupportConcepts = CustomerService.GetAllActiveSupportConcepts();
}
else
{
Model.SupportConcepts = CustomerService.GetAllActiveSupportConceptsByCustomers(Model.Customers.Select(c => c.CustomerOid ?? 0));
2016-06-27 01:45:38 +02:00
}
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)
{
Model.ShowOnlyOwnSupportConcepts = "true,false" == collection["ShowOnlyOwnSupportConcepts"];
return RedirectToActionPermanent("Main");
}
[HttpPost]
public new ActionResult Logout()
{
2016-06-27 01:45:38 +02:00
return base.Logout();
}
[Authorize]
2017-04-26 14:57:32 +02:00
public string LoadGoals(long pCostbearer2SupportConceptOid)
2016-06-27 01:45:38 +02:00
{
if (Model == null)
{
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;
}
2016-06-27 01:45:38 +02:00
Model.SelectedSupportConcept = sc;
var selectedGoals = sc.Goals;
var missingParents = selectedGoals.Where(w => w.ParentOid != null && false == selectedGoals.Any(a => a.ValueListEntryOid.Equals(w.ParentOid))).Select(s => s.ParentOid).ToList();
_ParentGoals = new Dictionary<long, ValueListEntryDC>();
2016-06-27 01:45:38 +02:00
foreach (var oid in missingParents)
{
LoadMissingParents(oid.Value);
}
return SerializeObject(BuildGoalTree(selectedGoals.Union(_ParentGoals.Values).ToList()));
2016-06-27 01:45:38 +02:00
}
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();
2016-06-27 01:45:38 +02:00
var goalTree = new List<GoalTreeItem>();
var goalTreeDic = new Dictionary<long, GoalTreeItem>();
foreach(var ziel in ziele)
2016-06-27 01:45:38 +02:00
{
var treeItem = new GoalTreeItem {Children = new List<GoalTreeItem>(), Header = ziel.TypeDescription, ParentOid = ziel.ParentOid, ValueListEntryOid = ziel.ValueListEntryOid};
goalTreeDic.Add(ziel.ValueListEntryOid.Value, treeItem);
if(ziel.ParentOid == null)
2016-06-27 01:45:38 +02:00
{
goalTree.Add(treeItem);
}
}
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);
}
foreach(var ziel in massnahmen)
2016-06-27 01:45:38 +02:00
{
var kind = new GoalTreeItem {Children = new List<GoalTreeItem>(), Header = ziel.TypeDescription, IsLeaf = true, ValueListEntryOid = ziel.ValueListEntryOid};
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);
}
}
foreach(var item in goalTreeDic.Values)
2016-06-27 01:45:38 +02:00
{
if(item.Children.Count == 0 && item.ParentOid.HasValue)
{
item.IsLeaf = true;
}
2016-06-27 01:45:38 +02:00
}
return goalTree;
}
private void LoadMissingParents(long pParentOid)
{
while(true)
2016-06-27 01:45:38 +02:00
{
var parentDC = ValueListService.GetValueListEntryByOid(pParentOid);
if(!_ParentGoals.ContainsKey(parentDC.ValueListEntryOid.Value))
2016-06-27 01:45:38 +02:00
{
_ParentGoals.Add(parentDC.ValueListEntryOid.Value, parentDC);
2016-06-27 01:45:38 +02:00
if(parentDC.ParentOid != null)
2016-06-27 01:45:38 +02:00
{
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);
}
2016-06-27 01:45:38 +02:00
2017-02-01 13:53:59 +01:00
public string CheckDokuReiter()
{
return SerializeObject(Model.Dokutypes);
2016-06-27 01:45:38 +02:00
}
2017-02-01 13:53:59 +01:00
private string GetSettingValue(string key)
{
var man = OperationsService.GetMandator();
return GetSettingValue(man.Settings, key);
}
2016-06-27 01:45:38 +02:00
private static string GetSettingValue(string settings, string key)
{
if (!string.IsNullOrEmpty(settings))
2016-06-27 01:45:38 +02:00
{
if (settings.IndexOf(";") == -1 && settings.IndexOf("=") == -1)
{
return settings;
}
var keyValuePairs = settings.Split(';');
2016-06-27 01:45:38 +02:00
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);
}
2016-06-27 01:45:38 +02:00
[Authorize]
public string LoadAppointments(string newtoday)
2016-06-27 01:45:38 +02:00
{
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();
2016-06-27 01:45:38 +02:00
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);
2016-06-27 01:45:38 +02:00
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));
2016-06-27 01:45:38 +02:00
}
catch (Exception e)
{
log.Error(e.Message, e);
return SerializeObject("Fehler 510");
}
}
[Authorize]
2016-06-27 01:45:38 +02:00
public string LoadStatistics(long oid)
{
try
{
if(Model == null)
2016-06-27 01:45:38 +02:00
{
return "SessionTimeout";
}
var supportConceptStatistics = OperationsService.CreateSupportConceptStatistics(oid, DateTime.Now);
2016-06-27 01:45:38 +02:00
return SerializeObject(supportConceptStatistics);
2016-06-27 01:45:38 +02:00
}
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)
2016-06-27 01:45:38 +02:00
{
try
{
if (Model == null)
{
SerializeObject("SessionTimeout");
}
var date = DateTime.Parse(day);
var end = DateTime.Parse(endDate);
var zeit = ConvertRecordTimesWithEndDate(startZeit, endZeit, date, end, 0);
2016-06-27 01:45:38 +02:00
var b1 = KalenderService.GetSchedulerAppointmentByid(oid);
b1.EndDate = zeit[1];
b1.StartDate = zeit[0];
b1.Subject = betreff;
2016-06-27 01:45:38 +02:00
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)
2016-06-27 01:45:38 +02:00
{
try
{
if (Model == null)
{
SerializeObject("SessionTimeout");
}
var date = DateTime.Parse(pStartDate);
var end = DateTime.Parse(pEndDate);
var zeit = ConvertRecordTimesWithEndDate(pStartTime, pEndTime, date, end, 0);
2016-06-27 01:45:38 +02:00
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,
2016-06-27 01:45:38 +02:00
Originator = MobileSessionFacade.LoggedInCompactEmployee
}
};
KalenderService.InsertSchedulerAppointments(a1);
}
catch (Exception e)
{
log.Error(e.Message, e);
SerializeObject("Fehler 520");
}
}
[Authorize]
public string LoadBeWoTasks(string newtoday)
2016-06-27 01:45:38 +02:00
{
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]
2017-04-26 14:57:32 +02:00
public void SaveUnterschrift(string breitengrad, string langengrad, string blob, string zeitstempel, long? ServiceRecord)
2016-06-27 01:45:38 +02:00
{
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");
}
}
2017-02-01 13:53:59 +01:00
public void SetSaveSignature(bool save)
2016-06-27 01:45:38 +02:00
{
try
{
if (Model == null)
{
SerializeObject("SessionTimeout");
}
else
{
2017-02-01 13:53:59 +01:00
Model.SaveSignature = save;
2016-06-27 01:45:38 +02:00
}
}
catch (Exception e)
{
log.Error(e.Message, e);
SerializeObject("Fehler 777: Fail Error Compilation");
}
}
public string LoadServiceCategories(long pServiceCategoryOid)
{
var scm = Model?.ServiceCategories.FirstOrDefault(s => s.ServiceCategoryOid.Value == pServiceCategoryOid);
2017-04-26 14:57:32 +02:00
return SerializeObject(scm != null ? scm.ServiceDescriptions : new List<ServiceDescriptionDC>());
2016-06-27 01:45:38 +02:00
}
2017-04-26 14:57:32 +02:00
[Authorize]
2017-04-26 14:57:32 +02:00
public string LoadTextbausteineForServiceCategory(long pServiceCategoryOid)
{
if (!MobileSessionFacade.CheckForUserRight(UserRightType.TextbausteineNurEigeneAnsehen) && !MobileSessionFacade.CheckForUserRight(UserRightType.TextbausteineAlleAnsehen))
2017-04-26 14:57:32 +02:00
{
return null;
}
var textbausteine = OperationsService.GetAllTextModules();
2017-04-26 14:57:32 +02:00
if(MobileSessionFacade.CheckForUserRight(UserRightType.TextbausteineNurEigeneAnsehen))
2017-04-26 14:57:32 +02:00
{
textbausteine = textbausteine.Where(w => w.Employee.EmployeeOid == Model.Employee.EmployeeOid).ToList();
}
Model.Textbausteine = textbausteine.Where(w => w.ServiceCategory != null && w.ServiceCategory.ServiceCategoryOid == pServiceCategoryOid).ToList();
2017-04-26 14:57:32 +02:00
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);
2017-04-26 14:57:32 +02:00
}
public string LoadCompleteTextbausteinByOid(long pTextbausteinOid)
{
var abc = Model.Textbausteine.FirstOrDefault(f => f.TextModuleOid.Value == pTextbausteinOid);
2017-04-26 14:57:32 +02:00
return abc.Text;
}
2016-06-27 01:45:38 +02:00
// Ajax-Aufruf zum anzeigen, ob beim Speichern ein Fehler aufgetreten ist.
2017-04-26 14:57:32 +02:00
public void ErrorZeiterfassungAnzeigen(int errorwert)
2016-06-27 01:45:38 +02:00
{
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;
2017-02-01 13:53:59 +01:00
if (Model.Dokutypes != null && Model.Dokutypes.Length > 1)
{
doku1 = collection["Dokumentation"];
}
else
{
doku1 = collection["Dokumentation6"];
}
2018-02-07 14:45:35 +01:00
log.Info($"CreateServiceRecord: datum:{collection["Datum"]}; start:{collection["Start"]}; ende:{collection["Ende"]}; dauer:{collection["Duration"]}; doku:{doku1}; aktion:{collection["versteckt"]}");
2018-02-07 14:45:35 +01:00
if (string.IsNullOrEmpty(collection["Datum"]))
2016-06-27 01:45:38 +02:00
{
return View("Main", Model);
}
var distanz = collection["Distanz"];
int? distanceInMeters = null;
if(!string.IsNullOrEmpty(distanz))
{
if(int.TryParse(distanz, out var parsedDistance))
{
distanceInMeters = parsedDistance;
}
}
2016-06-27 01:45:38 +02:00
var submitBtnVal = collection["versteckt"];
var selectedCostbearerSCRelOid = Model.CostBearer2SupportConceptOid < 1 ? null : Model.CostBearer2SupportConceptOid;
2018-02-07 14:45:35 +01:00
var datum = Convert.ToDateTime(collection["Datum"]);
2016-06-27 01:45:38 +02:00
var enddatum = datum;
2016-06-27 01:45:38 +02:00
var start = collection["Start"];
var ende = collection["Ende"];
var dauer = 0;
if (datum > enddatum) {
enddatum = datum;
}
2018-02-07 14:45:35 +01:00
if (!string.IsNullOrEmpty(collection["Duration"]))
2016-06-27 01:45:38 +02:00
{
2018-02-07 14:45:35 +01:00
int.TryParse(collection["Duration"], out dauer);
2016-06-27 01:45:38 +02:00
}
2017-02-01 13:53:59 +01:00
2016-06-27 01:45:38 +02:00
var doku2 = collection["Dokumentation2"];
var doku3 = collection["Dokumentation3"];
var doku4 = collection["Dokumentation4"];
var doku5 = collection["Dokumentation5"];
var zeitenFeld = new DateTime[2];
if (start == string.Empty && ende == string.Empty)
2016-06-27 01:45:38 +02:00
{
zeitenFeld[0] = new DateTime(datum.Year, datum.Month, datum.Day, 0, 0, 1);
if(enddatum == datum)
{
2016-06-27 01:45:38 +02:00
zeitenFeld[1] = new DateTime(datum.Year, datum.Month, datum.Day, 0, 0, 1).AddMinutes(dauer);
}
2016-06-27 01:45:38 +02:00
else
{
2016-06-27 01:45:38 +02:00
zeitenFeld[1] = new DateTime(enddatum.Year, enddatum.Month, enddatum.Day, 0, 0, 1).AddMinutes(dauer);
}
2016-06-27 01:45:38 +02:00
}
else
{
zeitenFeld = enddatum == datum ? ConvertRecordTimes(start, ende, datum, dauer) : ConvertRecordTimesWithEndDate(start, ende, datum, enddatum, dauer);
2016-06-27 01:45:38 +02:00
}
if (dauer == 0 || zeitenFeld[1] != zeitenFeld[0])
{
dauer = (int) (zeitenFeld[1] - zeitenFeld[0]).TotalMinutes;
2016-06-27 01:45:38 +02:00
}
2016-06-27 01:45:38 +02:00
if (submitBtnVal.Equals("Speichern"))
{
var selectedRecordOid = Model.SelectedServiceRecordOid;
Model.NewServiceRecord = OperationsService.GetServiceRecordById(selectedRecordOid.Value);
}
if (Model.NewServiceRecord == null)
{
return RedirectToActionPermanent("Main");
}
Model.NewServiceRecord.Goals = Model.SelectedGoals;
Model.NewServiceRecord.Start = zeitenFeld[0];
Model.NewServiceRecord.End = zeitenFeld[1];
Model.NewServiceRecord.DistanceInMeter = distanceInMeters;
2016-06-27 01:45:38 +02:00
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)));
2016-06-27 01:45:38 +02:00
if (sc != null)
{
if (sc.SupportConceptOid != null)
{
Model.NewServiceRecord.SupportConcept =
CustomerService.LoadCompactSupportConceptDC(sc.SupportConceptOid.Value, Model.Employee.EmployeeOid);
}
Model.NewServiceRecord.Customer = sc.Customer;
var cb2ScRel = sc.CostBearerRelations.First(f => f.CostBearer2SupportConceptOid.HasValue && f.CostBearer2SupportConceptOid.Equals(selectedCostbearerSCRelOid));
2016-06-27 01:45:38 +02:00
Model.NewServiceRecord.CostBearer = cb2ScRel.CostBearer;
2016-06-27 01:45:38 +02:00
var intervall = Model.NewServiceRecord.CostBearer.ActualMinuteIntervall;
if (intervall > 0)
{
Model.NewServiceRecord.RoundedDuration = dauer % intervall != 0 ? dauer + (intervall - dauer % intervall) : dauer;
2016-06-27 01:45:38 +02:00
}
else
{
Model.NewServiceRecord.RoundedDuration = dauer;
}
Model.NewServiceRecord.CostBearer2SupportConceptOid = selectedCostbearerSCRelOid;
}
else
{
Model.NewServiceRecord.RoundedDuration = dauer;
}
}
2017-02-01 13:53:59 +01:00
Model.NewServiceRecord.Notice = doku1;
Model.NewServiceRecord.Notice2 = doku2;
Model.NewServiceRecord.Notice3 = doku3;
Model.NewServiceRecord.Notice4 = doku4;
Model.NewServiceRecord.Notice5 = doku5;
2016-06-27 01:45:38 +02:00
var serviceDescOid = 0L;
if (Model.SelectedServiceDescriptionOid.HasValue)
{
serviceDescOid = Model.SelectedServiceDescriptionOid.Value;
}
2018-02-07 14:45:35 +01:00
else if (!string.IsNullOrEmpty(collection["ServiceDescription"]))
2016-06-27 01:45:38 +02:00
{
2018-02-07 14:45:35 +01:00
serviceDescOid = Convert.ToInt64(collection["ServiceDescription"]);
2016-06-27 01:45:38 +02:00
}
if (serviceDescOid > 0)
{
Model.NewServiceRecord.ServiceDescription = OperationsService.GetServiceDescription(serviceDescOid);
}
if (Model.NewServiceRecord.RoundedDuration == 0)
{
2016-06-27 01:45:38 +02:00
Model.NewServiceRecord.RoundedDuration = dauer;
}
2016-06-27 01:45:38 +02:00
Model.NewServiceRecord.IP = Request.UserHostAddress;
Model.NewServiceRecord.InsertedOn = DateTime.Now;
Model.NewServiceRecord.InsUser = $"{MobileSessionFacade.LoggedInEmployee.FirstName} {MobileSessionFacade.LoggedInEmployee.LastName}";
2016-06-27 01:45:38 +02:00
Model.NewServiceRecord.IsCreatedInMobileClient = true;
if (submitBtnVal.Equals("Anlegen"))
{
var oidList = OperationsService.InsertNewServiceRecords(new List<ServiceRecordDC> { Model.NewServiceRecord });
2016-06-27 01:45:38 +02:00
Model.ServiceRecordOid = oidList[0];
2016-06-27 01:45:38 +02:00
}
else
{
OperationsService.UpdateServiceRecords(new List<ServiceRecordDC> { Model.NewServiceRecord });
}
Model.NewServiceRecord = new ServiceRecordDC();
if (selectedCostbearerSCRelOid.HasValue)
{
Model.ServiceRecords = OperationsService.FindServiceRecordsForLastDays(selectedCostbearerSCRelOid, Model.Zeitraum, Model.Employee.EmployeeOid).ToList();
}
}
catch (Exception e)
{
log.Error(e.Message, e);
}
2017-02-01 13:53:59 +01:00
Model.SaveSignature = Model.ShowSignature;
2016-06-27 01:45:38 +02:00
return RedirectToActionPermanent("Main");
}
[Authorize]
public ActionResult SaveZeiterfassungAfterCrash(string pDatum, string pStartDate, string pEndDate, string pDuration, string pNotice, string pServiceDescription, string pNotice2, string pNotice3, string pNotice4, string pNotice5, string pEndDate2)
2016-06-27 01:45:38 +02:00
{
try
{
if (Model == null)
{
return RedirectToActionPermanent("Index", "Login");
}
log.Info($"saveZeiterfassungAfterCrash: datum:{pDatum};start:{pStartDate};ende:{pEndDate};dauer:{pDuration};doku:{pNotice};doku2:{pNotice2};doku3:{pNotice3};doku4:{pNotice4};doku5:{pNotice5};pEndDate2:{pEndDate2}");
2016-06-27 01:45:38 +02:00
if (string.IsNullOrEmpty(pDatum))
2016-06-27 01:45:38 +02:00
{
return View("Main", Model);
}
var selectedCostbearerSCRelOid = Model.CostBearer2SupportConceptOid < 1 ? null : Model.CostBearer2SupportConceptOid;
var datum = Convert.ToDateTime(pDatum);
var start = pStartDate;
var ende = pEndDate;
2016-06-27 01:45:38 +02:00
var dauer = 0;
var enddatum = pEndDate2 != "" ? Convert.ToDateTime(pEndDate2) : datum;
2016-06-27 01:45:38 +02:00
if (datum > enddatum)
{
enddatum = datum;
}
if (!string.IsNullOrEmpty(pDuration))
2016-06-27 01:45:38 +02:00
{
int.TryParse(pDuration, out dauer);
2016-06-27 01:45:38 +02:00
}
var doku = pNotice;
var doku2 = pNotice2;
var doku3 = pNotice3;
var doku4 = pNotice4;
var doku5 = pNotice5;
2016-06-27 01:45:38 +02:00
var zeitenFeld = new DateTime[2];
if (start == string.Empty && ende == string.Empty)
2016-06-27 01:45:38 +02:00
{
zeitenFeld[0] = new DateTime(datum.Year, datum.Month, datum.Day, 0, 0, 1);
if (enddatum == datum)
{
2016-06-27 01:45:38 +02:00
zeitenFeld[1] = new DateTime(datum.Year, datum.Month, datum.Day, 0, 0, 1).AddMinutes(dauer);
}
2016-06-27 01:45:38 +02:00
else
{
zeitenFeld[1] = new DateTime(enddatum.Year, enddatum.Month, enddatum.Day, 0, 0, 1).AddMinutes(dauer);
}
2016-06-27 01:45:38 +02:00
}
else
{
zeitenFeld = enddatum == datum ? ConvertRecordTimes(start, ende, datum, dauer) : ConvertRecordTimesWithEndDate(start, ende, datum, enddatum, dauer);
2016-06-27 01:45:38 +02:00
}
if (dauer == 0 || zeitenFeld[1] != zeitenFeld[0])
{
dauer = (int)(zeitenFeld[1] - zeitenFeld[0]).TotalMinutes;
}
if (Model.NewServiceRecord == null)
{
return RedirectToActionPermanent("Main");
}
Model.NewServiceRecord.Goals = Model.SelectedGoals;
Model.NewServiceRecord.Start = zeitenFeld[0];
Model.NewServiceRecord.End = zeitenFeld[1];
if (Model.Employee.EmployeeOid != null)
{
Model.NewServiceRecord.Employee = Model.SelectedEmployee ?? MobileSessionFacade.LoggedInCompactEmployee;
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(selectedCostbearerSCRelOid)));
2016-06-27 01:45:38 +02:00
if (sc != null)
{
if (sc.SupportConceptOid != null)
{
Model.NewServiceRecord.SupportConcept = CustomerService.LoadCompactSupportConceptDC(sc.SupportConceptOid.Value, Model.Employee.EmployeeOid);
}
Model.NewServiceRecord.Customer = sc.Customer;
var cb2ScRel = sc.CostBearerRelations.First(f => f.CostBearer2SupportConceptOid.HasValue && f.CostBearer2SupportConceptOid.Equals(selectedCostbearerSCRelOid));
Model.NewServiceRecord.CostBearer = cb2ScRel.CostBearer;
var intervall = Model.NewServiceRecord.CostBearer.ActualMinuteIntervall;
if (intervall > 0)
{
Model.NewServiceRecord.RoundedDuration = dauer % intervall != 0 ? dauer + (intervall - dauer % intervall) : dauer;
2016-06-27 01:45:38 +02:00
}
else
{
Model.NewServiceRecord.RoundedDuration = dauer;
}
Model.NewServiceRecord.CostBearer2SupportConceptOid = selectedCostbearerSCRelOid;
}
else
{
Model.NewServiceRecord.RoundedDuration = dauer;
}
}
Model.NewServiceRecord.Notice = doku;
if (doku2 != "")
{
2016-06-27 01:45:38 +02:00
Model.NewServiceRecord.Notice2 = doku2;
}
2016-06-27 01:45:38 +02:00
if (doku3 != "")
{
2016-06-27 01:45:38 +02:00
Model.NewServiceRecord.Notice3 = doku3;
}
2016-06-27 01:45:38 +02:00
if (doku4 != "")
{
2016-06-27 01:45:38 +02:00
Model.NewServiceRecord.Notice4 = doku4;
}
2016-06-27 01:45:38 +02:00
if (doku5 != "")
{
2016-06-27 01:45:38 +02:00
Model.NewServiceRecord.Notice5 = doku5;
}
2016-06-27 01:45:38 +02:00
var serviceDescOid = 0L;
if (Model.SelectedServiceDescriptionOid.HasValue)
{
serviceDescOid = Model.SelectedServiceDescriptionOid.Value;
}
else if (!string.IsNullOrEmpty(pServiceDescription))
2016-06-27 01:45:38 +02:00
{
serviceDescOid = Convert.ToInt64(pServiceDescription);
2016-06-27 01:45:38 +02:00
}
if (serviceDescOid > 0)
{
Model.NewServiceRecord.ServiceDescription = OperationsService.GetServiceDescription(serviceDescOid);
}
Model.NewServiceRecord.IP = Request.UserHostAddress;
Model.NewServiceRecord.InsertedOn = DateTime.Now;
Model.NewServiceRecord.InsUser = $"{MobileSessionFacade.LoggedInEmployee.FirstName} {MobileSessionFacade.LoggedInEmployee.LastName}";
2016-06-27 01:45:38 +02:00
Model.NewServiceRecord.IsCreatedInMobileClient = true;
OperationsService.InsertNewServiceRecords(new List<ServiceRecordDC> { Model.NewServiceRecord });
Model.NewServiceRecord = new ServiceRecordDC();
if (selectedCostbearerSCRelOid.HasValue)
{
Model.ServiceRecords = OperationsService.FindServiceRecordsForLastDays(selectedCostbearerSCRelOid, Model.Zeitraum, Model.Employee.EmployeeOid).ToList();
}
}
catch (Exception e)
{
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
2018-02-07 14:45:35 +01:00
? CreateServiceCategoryModels(details.ServiceAccountings.Select(sa => sa.ServiceDescription).ToList())
: CreateServiceCategoryModels(OperationsService.GetAllServiceDescriptions());
2016-06-27 01:45:38 +02:00
Model.ServiceCategories = Model.ServiceCategories.Where(c => !c.OhneHilfeplan.HasValue || c.OhneHilfeplan.Value == AccountingvisibilityType.Beides || c.OhneHilfeplan.Value == AccountingvisibilityType.NurKlientenbezogen).ToList();
}
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)
2016-06-27 01:45:38 +02:00
{
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);
}
2016-06-27 01:45:38 +02:00
var list = catOid2ModelDict.Values.ToList();
2016-06-27 01:45:38 +02:00
list.Sort((s1, s2) =>
{
if (s1.IsDefault)
{
return 1;
}
2016-06-27 01:45:38 +02:00
return s1.Position != s2.Position ? s1.Position.CompareTo(s2.Position) : s1.ServiceCategoryOid.Value.CompareTo(s2.ServiceCategoryOid.Value);
2016-06-27 01:45:38 +02:00
});
return list;
}
[HttpPost]
[Authorize]
public ActionResult DeleteServiceRecord()
2016-06-27 01:45:38 +02:00
{
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)
2016-06-27 01:45:38 +02:00
{
OperationsService.DeleteServiceRecord(Model.ServiceRecordOidToDelete.Value, version.Value);
2016-06-27 01:45:38 +02: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
}
}
return RedirectToActionPermanent("Main", Model);
}
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;
}
2016-06-27 01:45:38 +02:00
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))
{
2016-06-27 01:45:38 +02:00
Model.SelectedGoals.Remove(goal);
}
2016-06-27 01:45:38 +02:00
else
{
2016-06-27 01:45:38 +02:00
Model.SelectedGoals.Add(goal);
}
2016-06-27 01:45:38 +02:00
}
public class GoalTreeItem
{
2017-04-26 14:57:32 +02:00
public string Header { get; set; }
2016-06-27 01:45:38 +02:00
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)
{
2016-06-27 01:45:38 +02:00
zeitraum = 7;
}
2016-06-27 01:45:38 +02:00
Model.Zeitraum = zeitraum;
LoadRecordsToModel();
return RedirectToActionPermanent("Main");
}
private void LoadRecordsToModel()
{
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>();
foreach(var r in records.Where(r => !recordsOhneDuplikate.Any(a => a.GroupOid.HasValue && a.GroupOid.Value.Equals(r.GroupOid))))
2016-06-27 01:45:38 +02:00
{
recordsOhneDuplikate.Add(r);
}
Model.ServiceRecords = recordsOhneDuplikate;
}
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)
{
2016-06-27 01:45:38 +02:00
Model.SelectedGoals = serviceRecordDC.Goals;
}
2016-06-27 01:45:38 +02:00
}
}
2017-04-26 14:57:32 +02:00
public string GetSelectedRecordInformation()
2016-06-27 01:45:38 +02:00
{
var result = string.Empty;
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
{
LoadRecordsToModel();
return SerializeObject(Model.ServiceRecords.First(f => f.ServiceRecordOid == oid));
2016-06-27 01:45:38 +02:00
}
2017-04-26 14:57:32 +02:00
private static string SerializeObject(object obj)
2016-06-27 01:45:38 +02:00
{
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)
2016-06-27 01:45:38 +02:00
{
var result = new DateTime[2];
2017-02-01 13:53:59 +01:00
var startDate = datum.Date;
var endDate = datum.Date;
2016-06-27 01:45:38 +02:00
2017-02-01 13:53:59 +01:00
var dateTemp = ConvertTimeStringToDateTime(start);
startDate = startDate.AddHours(dateTemp.Hour).AddMinutes(dateTemp.Minute);
2016-06-27 01:45:38 +02:00
2017-02-01 13:53:59 +01:00
dateTemp = ConvertTimeStringToDateTime(ende);
endDate = endDate.AddHours(dateTemp.Hour).AddMinutes(dateTemp.Minute);
if (string.IsNullOrEmpty(start) && !string.IsNullOrEmpty(ende))
2016-06-27 01:45:38 +02:00
{
startDate = endDate.AddMinutes(-1 * dauer);
}
if (string.IsNullOrEmpty(ende) && !string.IsNullOrEmpty(start))
2016-06-27 01:45:38 +02:00
{
endDate = startDate.AddMinutes(dauer);
}
if (endDate < startDate)
{
endDate = startDate;
}
2017-02-01 13:53:59 +01:00
2016-06-27 01:45:38 +02:00
result[0] = startDate;
result[1] = endDate;
return result;
}
private static DateTime[] ConvertRecordTimesWithEndDate(string start, string ende, DateTime datum, DateTime enddatum, int dauer)
2016-06-27 01:45:38 +02:00
{
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(",")))
2016-06-27 01:45:38 +02:00
{
var seperator = ':';
if (start.Contains("."))
{
2016-06-27 01:45:38 +02:00
seperator = '.';
}
2016-06-27 01:45:38 +02:00
else if (start.Contains(","))
{
2016-06-27 01:45:38 +02:00
seperator = ',';
}
2016-06-27 01:45:38 +02:00
var hm = start.Split(seperator);
h = Convert.ToInt32(hm[0]);
m = Convert.ToInt32(hm[1]);
}
else if (!string.IsNullOrEmpty(start))
2016-06-27 01:45:38 +02:00
{
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(",")))
2016-06-27 01:45:38 +02:00
{
var seperator2 = ':';
if (ende.Contains("."))
{
2016-06-27 01:45:38 +02:00
seperator2 = '.';
}
2016-06-27 01:45:38 +02:00
else if (ende.Contains(","))
{
2016-06-27 01:45:38 +02:00
seperator2 = ',';
}
2016-06-27 01:45:38 +02:00
var hm = ende.Split(seperator2);
h = Convert.ToInt32(hm[0]);
m = Convert.ToInt32(hm[1]);
}
else if (!string.IsNullOrEmpty(ende))
2016-06-27 01:45:38 +02:00
{
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))
2016-06-27 01:45:38 +02:00
{
startDate = endDate.AddMinutes(-1 * dauer);
}
if (string.IsNullOrEmpty(ende) && !string.IsNullOrEmpty(start))
2016-06-27 01:45:38 +02:00
{
endDate = startDate.AddMinutes(dauer);
}
if (endDate < startDate)
{
endDate = startDate;
}
if (dauer == 0 || endDate == startDate)
{
dauer = (int)(endDate - startDate).TotalMinutes;
}
2016-06-27 01:45:38 +02:00
result[0] = startDate;
result[1] = endDate;
return result;
}
public string CheckRights(string von, string bis, bool inEditMode, string dateString, string startString, string endString)
2016-06-27 01:45:38 +02:00
{
if (Model == null)
{
return "SessionTimeout";
}
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);
if (!DateTime.TryParse(dateString, out var date))
2016-06-27 01:45:38 +02:00
{
date = DateTime.Now.Date;
}
var startDt = date.AddHours(startHoursDt.Hour).AddMinutes(startHoursDt.Minute);
var endDt = date.AddHours(endHoursDt.Hour).AddMinutes(endHoursDt.Minute);
if (startDt > endDt)
{
return "StartGreaterEnd";
}
var dauer = (int)(endDt - startDt).TotalMinutes;
if (dauer == 0)
{
startDt = startDt.AddSeconds(1);
endDt = endDt.AddSeconds(1);
}
var checkSR = new ServiceRecordDC();
if (inEditMode)
{
checkSR = Model.ServiceRecords.FirstOrDefault(f => f.ServiceRecordOid.HasValue && f.ServiceRecordOid.Value.Equals(Model.SelectedServiceRecordOid));
}
if (checkSR == null)
{
checkSR = new ServiceRecordDC();
}
checkSR.Goals = Model.SelectedGoals;
checkSR.Start = startDt;
checkSR.End = endDt;
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}";
2016-06-27 01:45:38 +02:00
checkSR.ServiceDescription = OperationsService.GetServiceDescription(Model.SelectedServiceDescriptionOid.Value);
var man = OperationsService.GetMandator();
var s = man.Settings ?? string.Empty;
2016-06-27 01:45:38 +02:00
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;
2016-06-27 01:45:38 +02:00
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)
2016-06-27 01:45:38 +02:00
{
if (Model == null)
{
return false;
}
log.Info($"CheckRightsAfterCrash: von:{von};bis:{bis};inEditMode:{inEditMode};dateString:{dateString};startString:{startString};endString:{endString}");
2016-06-27 01:45:38 +02:00
var date = DateTime.Now.Date;
2016-06-27 01:45:38 +02:00
var startHoursDt = ConvertTimeStringToDateTime(startString);
var endHoursDt = ConvertTimeStringToDateTime(endString);
2016-06-27 01:45:38 +02:00
if (!DateTime.TryParse(dateString, out date))
{
date = DateTime.Now.Date;
}
2016-06-27 01:45:38 +02:00
var startDt = date.AddHours(startHoursDt.Hour).AddMinutes(startHoursDt.Minute);
var endDt = date.AddHours(endHoursDt.Hour).AddMinutes(endHoursDt.Minute);
2016-06-27 01:45:38 +02:00
if (startDt > endDt)
{
Model.ErrorWert = 5;
return false;
}
2016-06-27 01:45:38 +02:00
var dauer = (int)(endDt - startDt).TotalMinutes;
2016-06-27 01:45:38 +02:00
if (dauer == 0)
{
startDt = startDt.AddSeconds(1);
endDt = endDt.AddSeconds(1);
}
2016-06-27 01:45:38 +02:00
var checkSR = new ServiceRecordDC
{
Goals = Model.SelectedGoals,
Start = startDt,
End = endDt
};
2016-06-27 01:45:38 +02:00
if (Model.Employee.EmployeeOid != null)
{
checkSR.Employee = MobileSessionFacade.LoggedInCompactEmployee;
2016-06-27 01:45:38 +02:00
_Model.CostBearer2SupportConceptOid = costbearerOId;
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)));
2016-06-27 01:45:38 +02:00
if (sc != null)
{
if (sc.SupportConceptOid != null)
{
checkSR.SupportConcept = CustomerService.LoadCompactSupportConceptDC(sc.SupportConceptOid.Value, Model.Employee.EmployeeOid);
}
2016-06-27 01:45:38 +02:00
checkSR.Customer = sc.Customer;
var cb2ScRel = sc.CostBearerRelations.First(f => f.CostBearer2SupportConceptOid.HasValue && f.CostBearer2SupportConceptOid.Equals(Model.CostBearer2SupportConceptOid));
checkSR.CostBearer = cb2ScRel.CostBearer;
var intervall = checkSR.CostBearer.ActualMinuteIntervall;
2016-06-27 01:45:38 +02:00
if (intervall > 0)
2016-06-27 01:45:38 +02:00
{
checkSR.RoundedDuration = dauer % intervall != 0 ? dauer + (intervall - (dauer % intervall)) : dauer;
}
2016-06-27 01:45:38 +02:00
checkSR.CostBearer2SupportConceptOid = Model.CostBearer2SupportConceptOid;
}
}
2016-06-27 01:45:38 +02:00
checkSR.IP = Request.UserHostAddress;
checkSR.InsertedOn = DateTime.Now;
checkSR.InsUser = $"{MobileSessionFacade.LoggedInEmployee.FirstName} {MobileSessionFacade.LoggedInEmployee.LastName}";
2016-06-27 01:45:38 +02:00
if (leistung != null || leistung == "")
{
Model.SelectedServiceDescriptionOid = Convert.ToInt64(leistung);
}
else
{
Model.SelectedServiceDescriptionOid = 6;
}
2016-06-27 01:45:38 +02:00
checkSR.ServiceDescription = OperationsService.GetServiceDescription(Model.SelectedServiceDescriptionOid.Value);
2016-06-27 01:45:38 +02:00
var man = OperationsService.GetMandator();
var s = man.Settings ?? string.Empty;
var einzeln = s.Split(';');
var g = einzeln.ToList().FirstOrDefault(f => f.Contains("MaxDaysEditServiceRecordsAllowed"));
var t = g != null ? int.Parse(g.Split('=')[1]) : 0;
2016-06-27 01:45:38 +02:00
SupportConceptStatisticsDC stats = null;
2016-06-27 01:45:38 +02:00
if (Model.CostBearer2SupportConceptOid != null && Model.CostBearer2SupportConceptOid > 0)
{
stats = OperationsService.CreateSupportConceptStatistics(Model.CostBearer2SupportConceptOid.Value, DateTime.Now);
}
2016-06-27 01:45:38 +02:00
var result = OperationsService.ValidateServiceRecordEntry(checkSR, stats, t, false, new List<long> { checkSR.Employee.EmployeeOid });
if (result.Count != 0)
{
if (result[0].EndDate.Day <= date.Day && result[0].EndDate.Year <= date.Year && result[0].EndDate.Month <= date.Month ||
result[0].EndDate.Day >= date.Day && result[0].EndDate.Year <= date.Year && result[0].EndDate.Month <= date.Month ||
result[0].EndDate.Day <= date.Day && result[0].EndDate.Year <= date.Year && result[0].EndDate.Month >= date.Month ||
result[0].EndDate.Day >= date.Day && result[0].EndDate.Year <= date.Year && result[0].EndDate.Month >= date.Month)
2016-06-27 01:45:38 +02:00
{
Model.ErrorWert = 4;
return false;
2016-06-27 01:45:38 +02:00
}
Model.ErrorWert = 3;
return false;
}
2016-06-27 01:45:38 +02:00
Model.ErrorWert = 1;
return true;
2016-06-27 01:45:38 +02:00
}
private static DateTime ConvertTimeStringToDateTime(string timeString)
2016-06-27 01:45:38 +02:00
{
var dt = DateTime.Now.Date;
if (string.IsNullOrEmpty(timeString))
2016-06-27 01:45:38 +02:00
{
timeString = "0000";
}
var numberString = Regex.Replace(timeString, "[^0-9]", "");
2017-02-01 13:53:59 +01:00
if (numberString.Length < 3)
2016-06-27 01:45:38 +02:00
{
2017-02-01 13:53:59 +01:00
if (numberString.Length < 2)
{
numberString = "0" + numberString;
}
while (numberString.Length < 4)
{
numberString = numberString + "0";
}
2016-06-27 01:45:38 +02:00
}
2017-02-01 13:53:59 +01:00
else
2016-06-27 01:45:38 +02:00
{
2017-02-01 13:53:59 +01:00
while (numberString.Length < 4)
{
numberString = "0" + numberString;
}
2016-06-27 01:45:38 +02:00
}
2017-02-01 13:53:59 +01:00
2016-06-27 01:45:38 +02:00
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;
}
2017-04-26 14:57:32 +02:00
private struct ValidationStruct
2016-06-27 01:45:38 +02:00
{
public List<ServiceRecordValidationResultDC> ValidationResults { get; set; }
public Dictionary<int, bool> Rights { get; set; }
2017-04-26 14:57:32 +02:00
public string MaxDaysEditServiceRecordsAllowed { get; set; }
2016-06-27 01:45:38 +02:00
}
public void SetViewMode()
{
if (Model == null)
{
RedirectToActionPermanent("Index", "Login");
return;
}
Model.SelectedCustomer = null;
Model.SelectedCustomerOid = null;
}
2017-04-26 14:57:32 +02:00
public string GetSelectedSupportConceptCustomer()
2016-06-27 01:45:38 +02:00
{
return Model.SelectedSupportConcept == null ? "NoSupportConceptSelected" : SerializeObject(Model.SelectedSupportConcept.Customer.CustomerOid);
}
2017-04-26 14:57:32 +02:00
public string GetSelectedCustomer(long customerOid)
2016-06-27 01:45:38 +02:00
{
if (Model == null)
{
return "SessionTimeout";
}
Model.SelectedCustomer = Model.Customers.FirstOrDefault(f => f.CustomerOid.HasValue && f.CustomerOid.Value.Equals(customerOid));
Model.SelectedCustomerOid = customerOid;
return SerializeObject(GetJSONCustomer(Model.SelectedCustomer));
2016-06-27 01:45:38 +02:00
}
private static JSONCustomer GetJSONCustomer(CustomerDC pCustomer)
2016-06-27 01:45:38 +02:00
{
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;
}
}
2017-04-26 14:57:32 +02:00
internal class JSONCustomer
2016-06-27 01:45:38 +02:00
{
2017-04-26 14:57:32 +02:00
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; }
2016-06-27 01:45:38 +02:00
public List<Umfeldsperson> Umfeldpersonen { get; set; }
public JSONCustomer(CustomerDC init)
{
Vorname = init.FirstName;
Nachname = init.LastName;
Geburtstag = init.DateOfBirth?.ToShortDateString() ?? String.Empty;
2016-06-27 01:45:38 +02:00
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)
2016-06-27 01:45:38 +02:00
{
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;
2016-06-27 01:45:38 +02:00
}
}
Umfeldpersonen = new List<Umfeldsperson>();
2016-06-27 01:45:38 +02:00
foreach (var rel in init.EnvironmentPersons)
{
Umfeldpersonen.Add(new Umfeldsperson(rel));
}
}
}
2017-04-26 14:57:32 +02:00
internal class Umfeldsperson
2016-06-27 01:45:38 +02:00
{
2017-04-26 14:57:32 +02:00
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; }
2016-06-27 01:45:38 +02:00
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}";
2016-06-27 01:45:38 +02:00
TelNr = person.Communication1;
Mobil = person.Communication2;
EMail = person.Communication3;
Fax = person.Communication4;
Titel = person.Title;
}
}
2017-04-26 14:57:32 +02:00
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; }
2017-04-26 14:57:32 +02:00
public TextbausteinDisplayItem(long pOid, string pName, long? pParentOid, bool pIsParent, string pText)
2017-04-26 14:57:32 +02:00
{
Oid = pOid;
Name = pName;
ParentOid = pParentOid;
IsParent = pIsParent;
Text = pText;
Children = new List<TextbausteinDisplayItem>();
2017-04-26 14:57:32 +02:00
}
}
internal class RecurrenceInformation
{
public string PatternId { get; set; }
public int Index { get; set; }
public RecurrenceInformation(string pPatternId, int pIndex)
{
PatternId = pPatternId;
Index = pIndex;
}
}
2016-06-27 01:45:38 +02:00
}