430 lines
16 KiB
C#
430 lines
16 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
|
|
using BeWoPlanerMobil.Service;
|
|
|
|
using BS.Shared;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.Compact;
|
|
using BS.Shared.Extensions;
|
|
|
|
namespace BeWoPlanerMobil.Models
|
|
{
|
|
public class MainModel
|
|
{
|
|
[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 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; }
|
|
|
|
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;
|
|
}
|
|
|
|
public List<ValueListEntryDC> SelectedGoals { get; set; }
|
|
|
|
public ServiceRecordDC NewServiceRecord { get; set; }
|
|
|
|
public long? ServiceRecordOidToDelete { get; set; }
|
|
|
|
public static bool IsEditBtnVisible
|
|
{
|
|
get { return MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.ServiceRecordView_Edit))); }
|
|
}
|
|
|
|
public static bool IsDeleteBtnVisible
|
|
{
|
|
get { return MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.ServiceRecordView_Delete))); }
|
|
}
|
|
|
|
public static bool IsAllowedToCreateOrEditRecord
|
|
{
|
|
get {
|
|
return MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.ServiceRecordView_Create))) ||
|
|
MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.ServiceRecordView_Edit)));
|
|
}
|
|
}
|
|
|
|
public static bool IsOnlyAllowedToEdit
|
|
{
|
|
get
|
|
{
|
|
return !MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.ServiceRecordView_Create))) &&
|
|
MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.ServiceRecordView_Edit)));
|
|
}
|
|
}
|
|
|
|
public static bool IsAllowedToSeeCustomers => MobileSessionFacade.CheckForUserRight(UserRightType.CustomerView_View) || MobileSessionFacade.CheckForUserRight(UserRightType.Customer_ViewMyCustomers);
|
|
|
|
public static bool IsEmployeeSelectionVisible => MobileSessionFacade.CheckForUserRight(UserRightType.ServiceRecord_AllowCreationForOtherEmployees) || MobileSessionFacade.CheckForUserRight(UserRightType.ServiceRecord_AllowCreationForOtherTeamMember);
|
|
|
|
public static bool IsTextbausteineVisible => MobileSessionFacade.CheckForUserRight(UserRightType.TextbausteineAlleAnsehen) || MobileSessionFacade.CheckForUserRight(UserRightType.TextbausteineNurEigeneAnsehen);
|
|
//public static bool IsTextbausteineVisible = false;
|
|
|
|
public static bool HasRightForGroupBookings => MobileSessionFacade.CheckForUserRight(UserRightType.ServiceRecord_AllowCreatingGroupBooking);
|
|
|
|
public bool ShowDistanceField { get; set; }
|
|
|
|
public MainModel()
|
|
{
|
|
NewServiceRecord = new ServiceRecordDC();
|
|
ShowOnlyOwnSupportConcepts = true;
|
|
Zeitraum = -1;
|
|
ErrorWert = 1;
|
|
}
|
|
|
|
public IEnumerable<SelectListItem> SupportConceptListItems
|
|
{
|
|
get
|
|
{
|
|
var allCostBearerRelations = new List<SelectListItem> { new SelectListItem { Selected = true, Value = "-1", Text = string.Empty }, new SelectListItem {Value = "-2", Text = "Ohne Hilfeplan"} };
|
|
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 SelectListItem
|
|
{
|
|
Value = cb.CostBearer2SupportConceptOid.ToString(), Text = $"{sc.Customer.LastNameFirstName} | {cb.StartDate?.ToShortDateString().Remove(6, 2) ?? string.Empty}-{cb.EndDate?.ToShortDateString().Remove(6, 2) ?? string.Empty} {cb.CostBearer.Name}"
|
|
}));
|
|
}
|
|
|
|
return allCostBearerRelations;
|
|
}
|
|
}
|
|
|
|
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).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 IEnumerable<CustomSelectListItem> SelectedRelations
|
|
{
|
|
get
|
|
{
|
|
var result = new List<CustomSelectListItem>();
|
|
|
|
foreach(var rel in SelectedConceptCostBearerRelations)
|
|
{
|
|
|
|
var text1 = $"{rel.SupportConcept.Customer.LastNameFirstName}";
|
|
var text2 = $"{rel.StartDate?.ToShortDateString() ?? string.Empty} - {rel.EndDate?.ToShortDateString()} {rel.CostBearer.Name}";
|
|
var value = rel.CostBearer2SupportConceptOid.ToString();
|
|
var textColor = "#555555";
|
|
if(rel.EndDate.HasValue)
|
|
{
|
|
var isExpired = DateTime.Now > rel.EndDate.Value;
|
|
if(isExpired)
|
|
{
|
|
textColor = "#FF0000";
|
|
}
|
|
}
|
|
|
|
var listItem = new CustomSelectListItem(text1, text2, value, textColor);
|
|
|
|
result.Add(listItem);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public IEnumerable<SelectListItem> SupporConceptListItemsForGroupBooking
|
|
{
|
|
get
|
|
{
|
|
var allCostBearerRelations = new List<SelectListItem>();
|
|
|
|
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 SelectListItem
|
|
{
|
|
Value = cb.CostBearer2SupportConceptOid.ToString(), Text = $"{sc.Customer.LastNameFirstName} | {cb.StartDate?.ToShortDateString().Remove(6, 2) ?? string.Empty}-{cb.EndDate?.ToShortDateString().Remove(6, 2) ?? string.Empty} {cb.CostBearer.Name}"
|
|
}));
|
|
}
|
|
|
|
return allCostBearerRelations;
|
|
}
|
|
}
|
|
|
|
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<CompactCustomerDC> Customers { get; set; }
|
|
|
|
public List<CompactEmployeeDC> Employees { get; set; }
|
|
|
|
public EmployeeDC Employee { get; set; }
|
|
|
|
[Display(Name = "Klient")]
|
|
public long? SelectedCustomerOid { get; set; }
|
|
|
|
public CustomerDC SelectedCustomer { get; set; }
|
|
|
|
public IEnumerable<SelectListItem> CustomerListItems
|
|
{
|
|
get
|
|
{
|
|
var result = new List<SelectListItem> {new SelectListItem {Value = "-1", Text = string.Empty}};
|
|
result.AddRange(Customers.Select(item => new SelectListItem { Value = item.CustomerOid.ToString(), Text = string.Format("{1}, {0}", item.FirstName, item.LastName) }).ToList());
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
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 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 List<SelectListItem> SelectedSupportConceptListItems
|
|
{
|
|
get
|
|
{
|
|
var allCostBearerRelations = new List<SelectListItem>();
|
|
foreach (var sc in SelectedSupportConcepts.OrderBy(sc => sc.Customer.LastName))
|
|
{
|
|
allCostBearerRelations.AddRangeIfElementsNotIn(sc.CostBearerRelations.Select(cb => new SelectListItem
|
|
{
|
|
Value = cb.CostBearer2SupportConceptOid.ToString(),
|
|
Text = $"{sc.Customer.LastNameFirstName} | {cb.StartDate?.ToShortDateString().Remove(6, 2) ?? string.Empty}-{cb.EndDate?.ToShortDateString().Remove(6, 2) ?? string.Empty} {cb.CostBearer.Name}"
|
|
}));
|
|
}
|
|
|
|
return allCostBearerRelations;
|
|
}
|
|
}
|
|
|
|
public string SignatureImage { get; set; }
|
|
}
|
|
|
|
public class CustomSelectListItem
|
|
{
|
|
public string Text1 { get; set; }
|
|
public string Text2 { get; set; }
|
|
public string Value { get; set; }
|
|
public string TextColor { get; set; }
|
|
|
|
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; set; }
|
|
|
|
public string SupportConceptTimeSpan { get; set; }
|
|
|
|
public string CostBearer2SupportConceptOid { get; set; }
|
|
|
|
public string CostBearer2SupportConceptOidName { get; set; }
|
|
|
|
public string SpanColor { get; set; } = string.Empty;
|
|
|
|
public string DisplayString
|
|
{
|
|
get
|
|
{
|
|
if(string.IsNullOrEmpty(SupportConceptTimeSpan))
|
|
{
|
|
return NameAndDateOfBirth;
|
|
}
|
|
|
|
return $"{NameAndDateOfBirth ?? string.Empty} | {SupportConceptTimeSpan}";
|
|
}
|
|
}
|
|
|
|
public SupportConceptListObject(string pNameAndDateOfBirth, string pSupportConceptTimeSpan, string pCostBearer2SupportConceptOid, bool isAboutToExpire, bool isAboutToExpireIn3MonthsOrLess)
|
|
{
|
|
NameAndDateOfBirth = pNameAndDateOfBirth;
|
|
SupportConceptTimeSpan = pSupportConceptTimeSpan;
|
|
CostBearer2SupportConceptOid = pCostBearer2SupportConceptOid;
|
|
|
|
CostBearer2SupportConceptOidName = "OidHolder_" + CostBearer2SupportConceptOid;
|
|
|
|
if(isAboutToExpire)
|
|
{
|
|
SpanColor = "style=\"color: red;\"";
|
|
}
|
|
else if(isAboutToExpireIn3MonthsOrLess)
|
|
{
|
|
SpanColor = "style=\"color: #FF9400;\"";
|
|
}
|
|
}
|
|
}
|
|
} |