Files
BeWoPlaner/BeWoPlanerMobil/Models/MainModel.cs
Lyndon Jetten ee68e7879a Bugs im Kalender behoben (noch nicht alle)
Mitarbeiter wird nicht mehr automatisch bei Gruppenbuchungen hinzugefügt, wenn es nicht erwünscht IsTask
Hilfepläne, die heute ablaufen, werden noch als nicht abgelaufen angezeigt wie im Fat-Client
2020-12-01 12:29:12 +01:00

557 lines
21 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web.Mvc;
using BeWoPlanerMobil.Service;
using BeWoPlanerMobil.Util;
using BS.Shared;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using BS.Shared.Extensions;
using BS.Shared.Settings;
namespace BeWoPlanerMobil.Models
{
public class MainModel : AbstractModel
{
[Display(Name = "Nur meine Hilfepläne anzeigen")]
public bool ShowOnlyOwnSupportConcepts { get; set; }
[Display(Name = "Abgelaufene Hilfepläne anzeigen")]
public bool ShowExpiredSupportConcepts { get; set; }
[Display(Name = "Hilfeplan")]
public long? CostBearer2SupportConceptOid { get; set; }
[Display(Name = "Kategorie")]
public long? SelectedServiceCategoryOid { get; set; }
public long? SelectedServiceDescriptionOid { get; set; }
public long? SelectedServiceRecordOid { get; set; }
public static bool IsAllowedToDeleteServiceRecord(ServiceRecordDC serviceRecord)
{
var allowed = false;
if(MobileSessionFacade.CheckForUserRight(UserRightType.ServiceRecordView_Delete))
{
allowed = true;
}
else if(MobileSessionFacade.CheckForUserRight(UserRightType.ServiceRecord_AllowChangeWithin24Hours))
{
if(serviceRecord.InsertedOn.HasValue)
{
if(DateTime.Now < serviceRecord.InsertedOn.Value.AddDays(1))
{
allowed = true;
}
}
}
if(allowed && ApplicationSettings.MaxDaysEditServiceRecordsAllowed > 0)
{
if(!MobileSessionFacade.CheckForUserRight(UserRightType.ServiceRecord_AllowEditAfterMaxDaysInNextMonth))
{
if(serviceRecord.Start.HasValue)
{
var dateTime = new DateTime(serviceRecord.Start.Value.Year, serviceRecord.Start.Value.Month, 1);
dateTime = dateTime.AddMonths(1);
dateTime = dateTime.AddDays(ApplicationSettings.MaxDaysEditServiceRecordsAllowed);
if(DateTime.Now >= dateTime)
{
allowed = false;
}
}
}
}
if (allowed && ApplicationSettings.AnzTageZeiterfassErfolgt > 0)
{
if (!MobileSessionFacade.CheckForUserRight(UserRightType.ServiceRecordAllowEditAfterMindays))
{
if (serviceRecord.Start != null)
{
var dt = new DateTime(serviceRecord.Start.Value.Year, serviceRecord.Start.Value.Month, serviceRecord.Start.Value.Day);
dt = dt.AddDays(ApplicationSettings.AnzTageZeiterfassErfolgt + 1);
if (DateTime.Now >= dt)
{
allowed = false;
}
}
}
}
if(allowed && !MobileSessionFacade.CheckForUserRight(UserRightType.ServiceRecord_AllowEditForOtherEmployees))
{
if(MobileSessionFacade.LoggedInEmployee.EmployeeOid != serviceRecord.Employee.EmployeeOid)
{
allowed = false;
}
}
if(allowed && serviceRecord.GroupOid.HasValue)
{
if(!MobileSessionFacade.CheckForUserRight(UserRightType.ServiceRecord_AllowCreatingGroupBooking))
{
allowed = false;
}
}
return allowed;
}
public ServiceRecordDC SelectedServiceRecord { get; set; }
public SupportConceptDC SelectedSupportConcept { get; set; }
public int Zeitraum { get; set; }
public bool SaveSignature { get; set; }
public int ErrorWert { get; set; }
public bool ShowSignature { get; set; }
public long ServiceRecordOid { get; set; }
public List<SupportConceptDC> SupportConcepts { get; set; }
public List<ServiceCategoryModel> ServiceCategories { get; set; }
public List<TextModuleDC> Textbausteine { get; set; } = new List<TextModuleDC>();
private List<ServiceRecordDC> _ServiceRecords;
public List<ServiceRecordDC> ServiceRecords
{
get
{
if(_ServiceRecords == null)
{
return _ServiceRecords = new List<ServiceRecordDC>();
}
return _ServiceRecords.OrderByDescending(sr => sr.Start).ToList();
}
set => _ServiceRecords = value;
}
private List<ValueListEntryDC> _SelectedGoals;
public List<ValueListEntryDC> SelectedGoals
{
get => _SelectedGoals ?? new List<ValueListEntryDC>();
set => _SelectedGoals = value;
}
public ServiceRecordDC NewServiceRecord { get; set; }
public long? ServiceRecordOidToDelete { get; set; }
public bool ShowDistanceField { get; set; }
public MainModel()
{
NewServiceRecord = new ServiceRecordDC();
ShowOnlyOwnSupportConcepts = true;
Zeitraum = -1;
ErrorWert = 1;
}
public IEnumerable<SupportConceptListObject> SupportConceptListObjects
{
get
{
var allCostBearerRelations = new List<SupportConceptListObject> {new SupportConceptListObject("Hilfeplan auswählen", "", "-1", false, false), new SupportConceptListObject("Ohne Hilfeplan", "", "-2", false, false) };
foreach(var sc in SupportConcepts.OrderBy(sc => sc.Customer.LastName))
{
allCostBearerRelations.AddRange(sc.CostBearerRelations.Where(w => ShowExpiredSupportConcepts || w.EndDate == null || w.EndDate.Value >= DateTime.Now.Date).Select(
cb => new SupportConceptListObject(
$"{sc.Customer.LastNameFirstName} {(sc.Customer.DateOfBirth.HasValue ? "*" + sc.Customer.DateOfBirth.Value.ToString("dd.MM.yyyy") : string.Empty)}",
$"{cb.StartDate?.ToShortDateString().Remove(6, 2) ?? string.Empty}-{cb.EndDate?.ToShortDateString().Remove(6, 2) ?? string.Empty} {cb.CostBearer.Name}",
cb.CostBearer2SupportConceptOid.ToString(),
cb.SupportConcept.IsAboutToExpire,
cb.SupportConcept.ExpiresIn3MonthOrLess))
);
}
return allCostBearerRelations;
}
}
public SupportConceptListObject SelectedSupportConceptListObject { get; set; }
public List<SupportConceptCostBearerRelDC> SelectedConceptCostBearerRelations { get; set; }
public GroupBookingSelectionObject GroupBookingSelectionObject => new GroupBookingSelectionObject(SelectedConceptCostBearerRelations, SelectedGroupOfPeopleOids);
public IEnumerable<SupportConceptListObject> SupportConceptListObjectsForGroupBooking
{
get
{
var allCostbearerRelations = new List<SupportConceptListObject>();
foreach(var sc in SupportConcepts.OrderBy(sc => sc.Customer.LastName))
{
allCostbearerRelations.AddRange(sc.CostBearerRelations.Where(w => ShowExpiredSupportConcepts || w.EndDate == null || w.EndDate.Value >= DateTime.Now).Select(
cb => new SupportConceptListObject(
$"{sc.Customer.LastNameFirstName} {(sc.Customer.DateOfBirth.HasValue ? "*" + sc.Customer.DateOfBirth.Value.ToString("dd.MM.yyyy") : string.Empty)}",
$"{cb.StartDate?.ToShortDateString().Remove(6, 2) ?? string.Empty}-{cb.EndDate?.ToShortDateString().Remove(6, 2) ?? string.Empty} {cb.CostBearer.Name}",
cb.CostBearer2SupportConceptOid.ToString(),
cb.SupportConcept.IsAboutToExpire,
cb.SupportConcept.ExpiresIn3MonthOrLess))
);
}
return allCostbearerRelations;
}
}
public IEnumerable<SelectListItem> ServiceCategoryListItems
{
get
{
var result = new List<SelectListItem>();
result.AddRange(ServiceCategories.Select(item => new SelectListItem {Value = item.ServiceCategoryOid.Value.ToString(), Text = item.Name}).ToList());
return result;
}
}
public IEnumerable<SelectListItem> GroupOfPeopleListItems
{
get
{
return GroupsOfPeople.Select(group => new SelectListItem {Value = $"{group.GroupOfPeopleOid.Value}", Text = group.Name}).ToList();
}
}
public List<CompactEmployeeDC> Employees { get; set; }
public static List<CompactEmployeeDC> AllEmployees { get; set; }
[Display(Name = "Mitarbeiter")]
public long? SelectedEmployeeOid => SelectedEmployee?.EmployeeOid;
public CompactEmployeeDC SelectedEmployee { get; set; }
public List<GroupOfPeopleDC> GroupsOfPeople { get; set; } = new List<GroupOfPeopleDC>();
public List<long> SelectedGroupOfPeopleOids { get; set; } = new List<long>();
public IEnumerable<SelectListItem> EmployeeListItems
{
get
{
var result = new List<SelectListItem>();
result.AddRange(Employees.Select(item => new SelectListItem {Value = item.EmployeeOid.ToString(), Text = $"{item.LastName}, {item.FirstName}", Selected = item.Equals(MobileSessionFacade.LoggedInCompactEmployee)}).OrderBy(s => s.Text).ToList());
return result;
}
}
public ValueListEntryDC[] Dokutypes { get; set; }
public int NumberOfDokuTypes => Dokutypes?.Length ?? 0;
public static DateTime? GetEndDateOfSupportConcept(SupportConceptDC pSupportConcept)
{
DateTime? maxDate = null;
foreach(var relation in pSupportConcept.CostBearerRelations)
{
var end = relation.ApprovedEndDate ?? relation.RequestedEndDate;
if(maxDate == null || end != null && end.Value > maxDate.Value)
{
maxDate = end;
}
}
return maxDate;
}
public List<SupportConceptDC> SelectedSupportConcepts { get; set; } = new List<SupportConceptDC>();
public List<long> SelectedCostbearerRelOids { get; set; } = new List<long>();
public List<CompactEmployeeDC> SelectedEmployees { get; set; } = new List<CompactEmployeeDC>();
[Display(Name = "Gruppenbuchung")]
public bool IsInGroupBookingMode
{
get => _IsInGroupBookingMode;
set
{
_IsInGroupBookingMode = value;
if(!_IsInGroupBookingMode)
{
SelectedSupportConcepts?.Clear();
SelectedEmployees?.Clear();
}
}
}
private bool _IsInGroupBookingMode;
public bool IsInEditingMode { get; set; }
public List<ServiceDescriptionDC> GetServiceDesctiptions()
{
var result = new List<ServiceDescriptionDC>();
foreach(var serviceCategoryModel in ServiceCategories)
{
foreach(var serviceDescription in serviceCategoryModel.ServiceDescriptions)
{
result.AddIfNotIn(serviceDescription);
}
}
return result;
}
public bool IsServiceRecordNoticeMandatory { get; set; } = true;
public string SignatureImage { get; set; }
public string SignatureServiceRecordHeader { get; set; }
public CompactEmployeeDC PreviouslySelectedEmployee { get; set; }
public SupportConceptDC PreviouslySelectedSupportConcept { get; set; }
public bool IsEndDateVisible { get; set; }
public static string GetServiceRecordTimeHeader(ServiceRecordDC serviceRecord, bool isForServiceRecordsList)
{
if (serviceRecord?.Start == null || serviceRecord.End == null)
{
return string.Empty;
}
var start = serviceRecord.Start.Value;
var end = serviceRecord.End.Value;
var gruppenInfo = string.Empty;
var signatureToken = serviceRecord.SignatureOid.HasValue && isForServiceRecordsList ? "✔" : string.Empty;
if(serviceRecord.GroupOid.HasValue)
{
gruppenInfo = $"Gruppe ({serviceRecord.GroupPersonCount} Teilnehmer, {serviceRecord.GroupEmployeeCount} Betreuer) Dauer: {(end - start).TotalMinutes} {signatureToken}";
}
if(start.Second == 0)
{
return start.Date != end.Date ?
$"{start.ToShortDateString()} {start.ToShortTimeString()} - {end.ToShortDateString()} {end.ToShortTimeString()} {gruppenInfo} {signatureToken}" :
$"{start.ToShortDateString()} {start.ToShortTimeString()} - {end.ToShortTimeString()} {gruppenInfo} {signatureToken}";
}
return $"{start.ToShortDateString()} {gruppenInfo} {signatureToken}";
}
public bool HasRightToEditServiceRecord(ServiceRecordDC serviceRecord)
{
var allowed = false;
if(MobileSessionFacade.CheckForUserRight(UserRightType.ServiceRecordView_Edit))
{
allowed = true;
}
else if(MobileSessionFacade.CheckForUserRight(UserRightType.ServiceRecord_AllowChangeWithin24Hours))
{
if(serviceRecord.InsertedOn != null)
{
if(DateTime.Now < serviceRecord.InsertedOn.Value.AddDays(1))
{
allowed = true;
}
}
}
if(allowed && ApplicationSettings.MaxDaysEditServiceRecordsAllowed > 0)
{
if(!MobileSessionFacade.CheckForUserRight(UserRightType.ServiceRecord_AllowEditAfterMaxDaysInNextMonth))
{
if(serviceRecord.Start != null)
{
var date = new DateTime(serviceRecord.Start.Value.Year, serviceRecord.Start.Value.Month, 1);
date = date.AddMonths(1);
date = date.AddDays(ApplicationSettings.MaxDaysEditServiceRecordsAllowed);
if(DateTime.Now >= date)
{
allowed = false;
}
}
}
}
if(allowed && !MobileSessionFacade.CheckForUserRight(UserRightType.ServiceRecord_AllowEditForOtherEmployees))
{
if(MobileSessionFacade.LoggedInEmployee.EmployeeOid != serviceRecord.Employee.EmployeeOid)
{
allowed = false;
}
}
if(allowed && serviceRecord.GroupOid.HasValue)
{
if(!MobileSessionFacade.CheckForUserRight(UserRightType.ServiceRecord_AllowCreatingGroupBooking))
{
allowed = false;
}
}
if(allowed && ApplicationSettings.AnzTageZeiterfassErfolgt > 0)
{
if(!MobileSessionFacade.CheckForUserRight(UserRightType.ServiceRecordAllowEditAfterMindays))
{
if(serviceRecord.Start != null)
{
var date = new DateTime(serviceRecord.Start.Value.Year, serviceRecord.Start.Value.Month, serviceRecord.Start.Value.Day);
date = date.AddDays(ApplicationSettings.AnzTageZeiterfassErfolgt + 1);
if(DateTime.Now >= date)
{
allowed = false;
}
}
}
}
return allowed;
}
public bool IsZeiterfassungInStdMin { get; set; }
public string StartDateToEdit => SelectedServiceRecord?.Start?.ToShortDateString() ?? DateTime.Today.ToShortDateString();
public string EndDateToEdit => SelectedServiceRecord?.End?.ToShortDateString() ?? DateTime.Today.ToShortDateString();
public string StartTimeToEdit
{
get
{
var start = SelectedServiceRecord?.Start;
if(start != null && !(start.Value.GetServiceRecordNoDateTimeDate().Equals(start)))
{
return start.Value.ToString("HH:mm");
}
return string.Empty;
}
}
public string EndTimeToEdit
{
get
{
var end = SelectedServiceRecord?.End;
if(end != null && !end.Value.GetServiceRecordNoDateTimeDate().Equals(end))
{
return end.Value.ToString("HH:mm");
}
return string.Empty;
}
}
public string DurationToEdit => SelectedServiceRecord?.RoundedDuration.ToString() ?? string.Empty;
public string DistanceToEdit => SelectedServiceRecord?.DistanceInMeter.ToString() ?? string.Empty;
public string NoticeToEdit => SelectedServiceRecord?.NoticeList.FirstOrDefault() ?? string.Empty;
public List<string> NoticeListToEdit => SelectedServiceRecord != null ? SelectedServiceRecord.NoticeList : new List<string> {string.Empty, string.Empty, string.Empty, string.Empty, string.Empty};
public string SubmitButtonValue => IsInEditingMode || IsInGroupBookingMode ? "Speichern" : "Anlegen";
public long SelectedServiceRecordsServiceDescriptionOid => SelectedServiceRecord?.ServiceDescription.ServiceDescriptionOid ?? 0L;
}
public class CustomSelectListItem
{
public string Text1 { get; }
public string Text2 { get; }
public string Value { get; }
public string TextColor { get; }
public CustomSelectListItem(string pText1, string pText2, string pValue, string pTextColor)
{
Text1 = pText1;
Text2 = pText2;
Value = pValue;
TextColor = pTextColor;
}
}
public class SupportConceptListObject
{
public string NameAndDateOfBirth { get; }
public string SupportConceptTimeSpan { get; }
public string CostBearer2SupportConceptOid { get; }
public string CostBearer2SupportConceptOidName { get; }
public bool IsAboutToExpire { get; }
public bool ExpiresInThreeMonthsOrLess { get; }
public SupportConceptListObject(string pNameAndDateOfBirth, string pSupportConceptTimeSpan, string pCostBearer2SupportConceptOid, bool isAboutToExpire, bool expiresIn3MonthOrLess)
{
NameAndDateOfBirth = pNameAndDateOfBirth;
SupportConceptTimeSpan = pSupportConceptTimeSpan;
CostBearer2SupportConceptOid = pCostBearer2SupportConceptOid;
CostBearer2SupportConceptOidName = "OidHolder_" + CostBearer2SupportConceptOid;
IsAboutToExpire = isAboutToExpire;
ExpiresInThreeMonthsOrLess = expiresIn3MonthOrLess;
}
public override bool Equals(object obj)
{
if (!(obj is SupportConceptListObject))
{
return false;
}
var obj2 = (SupportConceptListObject) obj;
var areEqual = Equals(NameAndDateOfBirth, obj2.NameAndDateOfBirth)
&& Equals(SupportConceptTimeSpan, obj2.SupportConceptTimeSpan)
&& Equals(CostBearer2SupportConceptOid, obj2.CostBearer2SupportConceptOid)
&& Equals(CostBearer2SupportConceptOidName, obj2.CostBearer2SupportConceptOidName)
&& Equals(IsAboutToExpire, obj2.IsAboutToExpire)
&& Equals(ExpiresInThreeMonthsOrLess, obj2.ExpiresInThreeMonthsOrLess);
return areEqual;
}
public override int GetHashCode()
{
unchecked
{
const int hashingBase = (int)2166136261;
const int hashingMultiplier = 16777619;
var hash = hashingBase;
hash = (hash * hashingMultiplier) ^ (NameAndDateOfBirth?.GetHashCode() ?? 0);
hash = (hash * hashingMultiplier) ^ (SupportConceptTimeSpan?.GetHashCode() ?? 0);
hash = (hash * hashingMultiplier) ^ (CostBearer2SupportConceptOid?.GetHashCode() ?? 0);
hash = (hash * hashingMultiplier) ^ IsAboutToExpire.GetHashCode();
hash = (hash * hashingMultiplier) ^ ExpiresInThreeMonthsOrLess.GetHashCode();
return hash;
}
}
}
}