336 lines
12 KiB
C#
336 lines
12 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? SelectedServiceCategoryConceptOid { 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 => false; //MobileSessionFacade.CheckForUserRight(UserRightType.TextbausteineAlleAnsehen) || MobileSessionFacade.CheckForUserRight(UserRightType.TextbausteineNurEigeneAnsehen);
|
|
|
|
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<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<SelectListItem> SelectedSupportConceptListItemsForGroupBooking
|
|
{
|
|
get
|
|
{
|
|
var selectedSCs = new List<SelectListItem>();
|
|
|
|
if(SelectedSupportConcepts != null)
|
|
{
|
|
foreach(var sc in SelectedSupportConcepts.OrderBy(sc => sc.Customer.LastName))
|
|
{
|
|
selectedSCs.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 selectedSCs;
|
|
}
|
|
}
|
|
|
|
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
|
|
{
|
|
var result = new List<SelectListItem> { new SelectListItem {Value = "-1:0", Text = "" }};
|
|
|
|
foreach(var item in GroupsOfPeople)
|
|
{
|
|
var relOids = "";
|
|
|
|
for(var i = 0; i < item.SupportConceptList.Count; i++)
|
|
{
|
|
relOids += item.SupportConceptList.ElementAt(i).CostBearerRelOids.First().ToString();
|
|
|
|
if(i != item.SupportConceptList.Count - 1)
|
|
{
|
|
relOids += ",";
|
|
}
|
|
}
|
|
|
|
result.Add(new SelectListItem { Value = $"{item.GroupOfPeopleOid.Value}:{relOids}", Text = item.Name });
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
[Display(Name = "Textbaustein")]
|
|
public long? SelectedTextbausteinOid { get; set; }
|
|
|
|
public IEnumerable<SelectListItem> TextbausteinListItems
|
|
{
|
|
get
|
|
{
|
|
var result = new List<SelectListItem>();
|
|
|
|
if (Textbausteine != null)
|
|
{
|
|
result.AddRange(Textbausteine.Select(item => new SelectListItem { Value = item.TextModuleOid.Value.ToString(), Text = item.Name }).ToList());
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
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 { get; set; }
|
|
|
|
public CompactEmployeeDC SelectedEmployee { get; set; }
|
|
|
|
public List<GroupOfPeopleDC> GroupsOfPeople { get; set; }
|
|
|
|
[Display(Name = "Gruppen")]
|
|
public string SelectedGroupInfo { get; set; }
|
|
|
|
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)}).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<CompactEmployeeDC> SelectedEmployees { get; set; } = new List<CompactEmployeeDC>();
|
|
|
|
public List<long> SelectedCostbearer2SupportConceptOids { get; set; } = new List<long>();
|
|
|
|
[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;
|
|
}
|
|
}
|
|
} |