Gruppenbuchung im Mobilklienten -> Validierung serverseitig fertig. Die Meldungen im JavaScript müssen noch angepasst werden.

This commit is contained in:
Lyndon Jetten
2018-11-30 16:47:57 -04:00
parent 78492b8edc
commit f49f833db3
9 changed files with 388 additions and 218 deletions

View File

@@ -4,7 +4,7 @@ using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using BeWo.Service.DCEntityMapper;
using BeWo.Service.ServiceImplementations;
using BeWoPlanerMobil.Models;
@@ -23,6 +23,7 @@ using BS.Shared.Services;
using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.Compatibility;
using ServiceRecordDC = BS.Shared.DataContracts.ServiceRecordDC;
namespace BeWoPlanerMobil.Controllers
{
@@ -623,23 +624,22 @@ namespace BeWoPlanerMobil.Controllers
}
}
public void SetSaveSignature(bool save)
public string SetSaveSignature(bool save)
{
try
{
if (Model == null)
{
SerializeObject("SessionTimeout");
}
else
{
Model.SaveSignature = save;
return SerializeObject("SessionTimeout");
}
Model.SaveSignature = save;
return " ";
}
catch (Exception e)
{
log.Error(e.Message, e);
SerializeObject("Fehler 777: Fail Error Compilation");
return SerializeObject("Fehler 777: Fail Error Compilation");
}
}
@@ -1137,8 +1137,8 @@ namespace BeWoPlanerMobil.Controllers
Model.SelectedSupportConcepts = new List<SupportConceptDC>();
Model.SelectedEmployees = new List<CompactEmployeeDC>();
//TODO: Die Dauer neuberechnen und die einzelnen ServiceRecords an die Änderungen, die gemacht wurden, anpassen. (Model.SelectedServiceRecord)
//TODO: Fast alle Eigenschaften von Model.NewServiceRecord kopieren
ResetGroupBookingMode(false);
Model.IsInEditingMode = false;
return RedirectToActionPermanent("Main");
}
@@ -1621,13 +1621,15 @@ namespace BeWoPlanerMobil.Controllers
[HttpPost]
[Authorize]
public ActionResult DeleteServiceRecord()
public ActionResult DeleteServiceRecord(FormCollection formCollection)
{
if (Model == null)
{
return RedirectToActionPermanent("Index", "Login");
}
Model.ServiceRecordOidToDelete = long.Parse(formCollection["serviceRecordOidHolder"]);
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));
@@ -1641,6 +1643,8 @@ namespace BeWoPlanerMobil.Controllers
}
}
ResetGroupBookingMode(false);
return RedirectToActionPermanent("Main");
}
@@ -1690,15 +1694,16 @@ namespace BeWoPlanerMobil.Controllers
}
}
public void SetServiceDescription(long pServiceDescriptionOid)
public string SetServiceDescription(long pServiceDescriptionOid)
{
if (Model == null)
{
RedirectToActionPermanent("Index", "Login");
return;
return " ";
}
Model.SelectedServiceDescriptionOid = pServiceDescriptionOid;
return " ";
}
[HttpPost]
@@ -1789,6 +1794,9 @@ namespace BeWoPlanerMobil.Controllers
Model.SelectedServiceRecord = serviceRecord;
Model.SelectedSupportConcepts.Clear();
Model.SelectedEmployees.Clear();
Model.SelectedCostbearerRelOids.Clear();
var relationOids = new List<long>();
if (serviceRecord?.GroupOid != null)
{
@@ -1797,7 +1805,7 @@ namespace BeWoPlanerMobil.Controllers
if(serviceRecordGroup != null)
{
employees.AddRangeIfElementsNotIn(serviceRecordGroup.ServiceRecordList.Select(s => s.Employee));
var relationOids = serviceRecordGroup.ServiceRecordList.Select(s => s.CostBearer2SupportConceptOid.Value).ToList();
relationOids = serviceRecordGroup.ServiceRecordList.Select(s => s.CostBearer2SupportConceptOid.Value).ToList();
var costBearerRelations = CustomerService.GetSupportConceptCostBearerRelationsById(relationOids);
foreach(var rel in costBearerRelations)
@@ -1812,12 +1820,12 @@ namespace BeWoPlanerMobil.Controllers
}
}
}
Model.SelectedCostbearerRelOids.AddRangeIfElementsNotIn(relationOids);
Model.SelectedSupportConcepts = supportConcepts;
Model.SelectedEmployees = employees;
// TODO: Wie bei SetGroupBooking
//LoadServiceCategoriesForGroupBooking();
Model.ServiceCategories = CreateServiceCategoryModels(OperationsService.GetAllServiceDescriptions());
return RedirectToActionPermanent("Main");
@@ -1923,11 +1931,11 @@ namespace BeWoPlanerMobil.Controllers
checkSR.ServiceDescription = OperationsService.GetServiceDescription(Model.SelectedServiceDescriptionOid.Value);
var man = OperationsService.GetMandator();
var s = man.Settings ?? string.Empty;
var einzeln = s.Split(';');
var g = einzeln.ToList().FirstOrDefault(f => f.Contains("MaxDaysEditServiceRecordsAllowed"));
var t = g != null ? int.Parse(g.Split('=')[1]) : 0;
var mandator = OperationsService.GetMandator();
var settings = mandator.Settings ?? string.Empty;
var splitSettings = settings.Split(';');
var maxDaysEditSRsAllowedSetting = splitSettings.ToList().FirstOrDefault(f => f.Contains("MaxDaysEditServiceRecordsAllowed"));
var maxDaysEditSRsAllowed = maxDaysEditSRsAllowedSetting != null ? int.Parse(maxDaysEditSRsAllowedSetting.Split('=')[1]) : 0;
SupportConceptStatisticsDC stats = null;
@@ -1936,21 +1944,69 @@ namespace BeWoPlanerMobil.Controllers
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()
};
var employees = new List<long> {checkSR.Employee.EmployeeOid};
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))));
var newResult = new ValidationResult();
//if (checkSR.GroupOid.HasValue)
if(Model.IsInGroupBookingMode)
{
if (checkSR.GroupOid.HasValue)
{
var serviceRecordGroup = OperationsService.GetServiceRecordGroup(checkSR.GroupOid.Value);
serviceRecordGroup.ServiceRecordList.DoForEach(sr => employees.AddIfNotIn(sr.Employee.EmployeeOid));
}
else
{
Model.SelectedEmployees.DoForEach(e => employees.AddIfNotIn(e.EmployeeOid));
}
var cb2scOids = (from scDc in Model.SelectedSupportConcepts where scDc.CostBearerRelations != null && scDc.CostBearerRelations.Count > 0 select scDc.CostBearerRelations[0].CostBearer2SupportConceptOid.Value).ToList();
var nodes = new List<FlatSupportConceptTreeNodeDC>();
foreach (var sc in CustomerService.LoadCompactSupportConceptsById(Model.SelectedSupportConcepts.Select(s => s.SupportConceptOid.Value)))
{
nodes.Add(CreateFlatSupportConceptItem(sc, null));
}
foreach (var node in nodes)
{
if (node?.SupportConceptTreeNodeDC != null)
{
var scDc = node.SupportConceptTreeNodeDC.SupportConcept;
var cbDc = node.SupportConceptTreeNodeDC.CostBearer;
var relDc = node.SupportConceptTreeNodeDC.SupportConceptCostBearerRelDC;
checkSR.SupportConcept = scDc;
checkSR.CostBearer = cbDc;
if (relDc != null)
{
checkSR.CostBearer2SupportConceptOid = relDc.CostBearer2SupportConceptOid;
}
}
var result = OperationsService.ValidateServiceRecord(checkSR, stats, maxDaysEditSRsAllowed, employees, cb2scOids);
newResult.ServiceRecord2Validations.Add(new ServiceRecord2Validation(checkSR, result));
}
}
else
{
var result = OperationsService.ValidateServiceRecordEntry(checkSR, stats, maxDaysEditSRsAllowed, checkSR.GroupOid.HasValue, employees);
newResult.ServiceRecord2Validations.Add(new ServiceRecord2Validation(checkSR, result));
}
newResult.Rights = new Dictionary<int, bool>();
newResult.MaxDaysEditServiceRecordsAllowed = maxDaysEditSRsAllowed.ToString();
newResult.Rights.Add(0, MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.ServiceRecord_AllowCreateOverlappingFLS))));
newResult.Rights.Add(1, MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.ServiceRecord_AllowCreateMoreFLSThanApproved))));
newResult.Rights.Add(2, MobileSessionFacade.LoggedInUser.UserGroups.Any(a => a.Rights.Any(f => f.RightType.Equals(UserRightType.BookServiceRecordAfterSettlementInvoice))));
Model.NewServiceRecord = new ServiceRecordDC();
return SerializeObject(valStruct);
return SerializeObject(newResult);
}
public bool CheckRightsAfterCrash(string von, string bis, bool inEditMode, string dateString, string startString, string endString, long costbearerOId, string leistung)
@@ -2074,13 +2130,6 @@ namespace BeWoPlanerMobil.Controllers
return true;
}
private struct ValidationStruct
{
public List<ServiceRecordValidationResultDC> ValidationResults { get; set; }
public Dictionary<int, bool> Rights { get; set; }
public string MaxDaysEditServiceRecordsAllowed { get; set; }
}
public void SetViewMode()
{
if (Model == null)
@@ -2170,22 +2219,48 @@ namespace BeWoPlanerMobil.Controllers
{
var isInGroupBookingMode = "true,false" == pFormCollection["IsInGroupBookingMode"];
Model.IsInGroupBookingMode = isInGroupBookingMode;
ResetGroupBookingMode(isInGroupBookingMode);
if(isInGroupBookingMode)
return RedirectToAction("Main");
}
private void ResetGroupBookingMode(bool pIsInGroupBookingMode)
{
Model.IsInGroupBookingMode = pIsInGroupBookingMode;
if (pIsInGroupBookingMode)
{
Model.SelectedSupportConcept = null;
Model.SelectedEmployee = null;
Model.SelectedEmployeeOid = null;
Model.ServiceCategories = CreateServiceCategoryModels(OperationsService.GetAllServiceDescriptions());
Model.SelectedEmployees.Add(MobileSessionFacade.LoggedInCompactEmployee);
}
else
{
Model.ServiceCategories.Clear();
}
Model.SelectedCostbearerRelOids.Clear();
Model.SelectedEmployees.Clear();
Model.SelectedSupportConcepts.Clear();
return RedirectToAction("Main");
if (Model.SelectedSupportConcept != null)
{
var details = OperationsService.GetSupportConceptTreeNodeDetailInfo(Model.SelectedSupportConcept.Customer.CustomerOid, Model.SelectedSupportConcept.SupportConceptOid, Model.CostBearer2SupportConceptOid);
Model.ServiceCategories = details.ServiceAccountings.Count > 0
? CreateServiceCategoryModels(details.ServiceAccountings.Select(sa => sa.ServiceDescription).ToList())
: CreateServiceCategoryModels(OperationsService.GetAllServiceDescriptions());
Model.ServiceCategories = Model.ServiceCategories.Where(c => !c.OhneHilfeplan.HasValue || c.OhneHilfeplan.Value == AccountingvisibilityType.Beides || c.OhneHilfeplan.Value == AccountingvisibilityType.NurKlientenbezogen).ToList();
}
else if (Model.CostBearer2SupportConceptOid == -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();
}
}
}
[HttpPost]
@@ -2204,6 +2279,11 @@ namespace BeWoPlanerMobil.Controllers
public string LoadCategoryAndDescription()
{
if (Model.SelectedServiceRecord == null)
{
return null;
}
var serviceDescriptionOid = Model.SelectedServiceRecord.ServiceDescription.ServiceDescriptionOid.ToString();
var serviceCategoryOid = Model.SelectedServiceRecord.ServiceDescription.Category.ServiceCategoryOid.ToString();
@@ -2297,5 +2377,16 @@ namespace BeWoPlanerMobil.Controllers
return RedirectToAction("Main");
}
[Authorize]
public string ResetGroupBookingModeViaGET()
{
Model.IsInGroupBookingMode = false;
Model.SelectedCostbearerRelOids.Clear();
Model.SelectedEmployees.Clear();
Model.SelectedSupportConcepts.Clear();
return MainModel.IsEmployeeSelectionVisible.ToString();
}
}
}