Files
BeWoPlaner/BeWo/Core/Service/SupportConceptService.cs

354 lines
13 KiB
C#
Raw Normal View History

2017-12-17 17:29:07 +01:00
using System;
using System.Collections.Generic;
2016-06-27 01:45:38 +02:00
using System.Linq;
using BS.Shared;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.ClientPartials;
using BS.Shared.DataContracts.Compact;
namespace BeWo.Core.Service
{
public class SupportConceptService
{
public static List<SupportConceptGoalDC> CreateGoalTree(List<ValueListEntryDC> allGoalsAndCategories, ObservableSortCollection<ValueListEntryDC> selectedGoals)
{
var goalList = new List<SupportConceptGoalDC>();
if (allGoalsAndCategories != null)
{
2019-10-10 22:07:42 +02:00
var ziele = allGoalsAndCategories.Where(w => w.Type.Equals(ValueListEntryType.SupportConceptGoalCategoryType) || w.Type.Equals(ValueListEntryType.SupportConceptIndividualGoalCategoryType)).OrderBy(s => s.DisplayName).ToList();
var massnahmen = allGoalsAndCategories.Where(w => w.Type.Equals(ValueListEntryType.SupportConceptGoalType) || w.Type.Equals(ValueListEntryType.SupportConceptIndividualGoalType)).OrderBy(s => s.DisplayName).ToList();
2016-06-27 01:45:38 +02:00
var goalCategoryDict = new Dictionary<long, SupportConceptGoalDC>();
foreach (var goalCat in ziele)
{
var treeItem = new SupportConceptGoalDC
{
CheckRecursive = false,
2016-06-27 01:45:38 +02:00
GoalEntryDC = goalCat,
2018-11-22 14:05:45 +01:00
IsExpanded = allGoalsAndCategories.Count <= 30
2016-06-27 01:45:38 +02:00
};
if (!goalCategoryDict.ContainsKey(goalCat.ValueListEntryOid.Value))
{
goalCategoryDict.Add(goalCat.ValueListEntryOid.Value, treeItem);
}
if(goalCat.ParentOid == null)
{
goalList.Add(treeItem);
}
}
foreach (var ziel in ziele.Where(w => w.ParentOid != null))
{
if (goalCategoryDict.ContainsKey(ziel.ParentOid.Value) && goalCategoryDict.ContainsKey(ziel.ValueListEntryOid.Value))
{
goalCategoryDict[ziel.ValueListEntryOid.Value].ParentGoal = goalCategoryDict[ziel.ParentOid.Value];
}
}
var zieleMitEltern = goalCategoryDict.Values.Where(w => w.GoalEntryDC.ParentOid != null).ToList();
foreach (var ziel in zieleMitEltern)
{
if (goalCategoryDict.ContainsKey(ziel.GoalEntryDC.ParentOid.Value))
{
goalCategoryDict[ziel.GoalEntryDC.ParentOid.Value].Children.Add(ziel);
}
}
//var zieleOhneKinder = goalCategoryDict.Values.Where(w => w.Children.Count == 0).ToList();
//foreach (var ziel in zieleOhneKinder)
//{
// CheckIfSelected(ziel, selectedGoals);
//}
var alleZiele = goalCategoryDict.Values.ToList();
foreach (var ziel in alleZiele)
{
CheckIfSelected(ziel, selectedGoals);
}
2016-06-27 01:45:38 +02:00
foreach (var goal in massnahmen)
{
var kind = new SupportConceptGoalDC { GoalEntryDC = goal, CheckRecursive = false };
2016-06-27 01:45:38 +02:00
CheckIfSelected(kind, selectedGoals);
if (goal.ParentOid != null && goalCategoryDict.ContainsKey(goal.ParentOid.Value))
{
var parentItem = goalCategoryDict[goal.ParentOid.Value];
kind.ParentGoal = parentItem;
parentItem.Children.Add(kind);
}
}
}
return goalList;
}
private static void CheckIfSelected(SupportConceptGoalDC goal, ObservableSortCollection<ValueListEntryDC> selectedGoals)
{
if (selectedGoals != null)
{
foreach (ValueListEntryDC existingGoal in selectedGoals)
{
if (existingGoal.Equals(goal.GoalEntryDC))
{
goal.IsChecked = true;
goal.GoalEntryDC.RatingTypeOid = existingGoal.RatingTypeOid;
if (existingGoal.RatingTypeOid.HasValue)
{
var rdc = Cache.GetInstance().GetAllRatingTypeList()
.FirstOrDefault(r => r.RatingTypeOid == existingGoal.RatingTypeOid);
if (rdc != null)
{
goal.RatingName = rdc.DisplayName;
}
}
2016-06-27 01:45:38 +02:00
}
}
//goal.PropertyChanged += (s, e) =>
//{
// var selectedGoal = s as SupportConceptGoalDC;
// if (selectedGoal != null)
// {
// if (selectedGoal.IsChecked)
// {
// if (!selectedGoals.Contains(selectedGoal.GoalEntryDC))
// {
// selectedGoals.Add(selectedGoal.GoalEntryDC);
// }
2019-10-10 22:07:42 +02:00
// }
// else
// {
// selectedGoals.Remove(selectedGoal.GoalEntryDC);
// }
// }
//};
2016-06-27 01:45:38 +02:00
}
}
public static List<ServiceCategoryTreeItem> CreateServiceTree(IList<ServiceCategoryDC> serviceCategories, IList<ServiceDescriptionDC> serviceDescriptions, IList<ServiceAccountingDC> serviceAccountings)
{
var treeList = new List<ServiceCategoryTreeItem>();
if(serviceCategories != null && serviceDescriptions != null)
{
var sortedCategories = serviceCategories.Where(sd => !sd.OhneHilfeplan.HasValue || sd.OhneHilfeplan.Value == AccountingvisibilityType.Beides || sd.OhneHilfeplan.Value == AccountingvisibilityType.NurKlientenbezogen).OrderBy(s => s.Name).ToList();
var serviceAccountingsCopy = new List<ServiceAccountingDC>();
var descriptions = serviceDescriptions.OrderBy(s => s.Name).ToList();
if(serviceAccountings != null)
{
foreach(var serviceAccountingDc in serviceAccountings)
{
descriptions.Remove(serviceAccountingDc.ServiceDescription);
serviceAccountingsCopy.Add(serviceAccountingDc);
}
}
foreach(var serviceDescriptionDc in descriptions)
{
var accountingDc = new ServiceAccountingDC();
accountingDc.ServiceDescription = serviceDescriptionDc;
serviceAccountingsCopy.Add(accountingDc);
}
var sortedAccountings = serviceAccountingsCopy.OrderBy(acc => acc.ServiceDescription.Name).ToList();
var categoryDict = new Dictionary<long, ServiceCategoryTreeItem>();
foreach(var category in sortedCategories)
{
var treeItem = new ServiceCategoryTreeItem
{
ServiceCategory = category,
IsExpanded = true
};
categoryDict.Add(category.ServiceCategoryOid.Value, treeItem);
treeList.Add(treeItem);
}
foreach(var sa in sortedAccountings)
{
var childItem = new ServiceCategoryTreeItem {ServiceAccounting = sa};
if(sa.ServiceDescription.Category != null && categoryDict.ContainsKey(sa.ServiceDescription.Category.ServiceCategoryOid.Value))
{
var parentItem = categoryDict[sa.ServiceDescription.Category.ServiceCategoryOid.Value];
childItem.Parent = parentItem;
//if (selectedDescriptions != null)
//{
// foreach (var existingSd in selectedDescriptions)
// {
// if (existingSd.Equals(sd))
// {
// childItem.IsChecked = true;
// }
// }
// childItem.PropertyChanged += (s, e) =>
// {
// ServiceCategoryTreeItem selectedSd = s as ServiceCategoryTreeItem;
// if (selectedSd != null && selectedSd.ServiceDescription != null)
// {
// if (selectedSd.IsChecked)
// {
// selectedDescriptions.Add(selectedSd.ServiceDescription);
// }
// else
// {
// selectedDescriptions.Remove(selectedSd.ServiceDescription);
// }
// }
// };
//}
parentItem.Children.Add(childItem);
}
}
}
return treeList;
}
2016-06-27 01:45:38 +02:00
public static FlatSupportConceptTreeNodeDC CreateFlatSupportConceptItem(CompactSupportConceptDC dc, CompactOrganisationDC orga)
{
FlatSupportConceptTreeNodeDC flatNode = new FlatSupportConceptTreeNodeDC();
if (dc != null)
{
SupportConceptTreeNodeDC treeNode = new SupportConceptTreeNodeDC();
treeNode.SupportConcept = dc;
treeNode.Customer = dc.Customer;
if (dc.CostBearerList.Count > 0)
{
CompactCostBearerDC cbDC = null;
if (orga != null)
{
foreach (var item in dc.CostBearerList)
{
if (orga.Equals(item.Organisation))
{
cbDC = item;
}
}
}
if (cbDC == null)
cbDC = dc.CostBearerList[0];
CompactOrganisationDC orgDC = new CompactOrganisationDC();
SupportConceptCostBearerRelDC relDC = new SupportConceptCostBearerRelDC();
orgDC.CostBearerID = cbDC.CostBearerID;
orgDC.CostBearerOid = cbDC.CostBearerOid;
var o = orga;
if (o == null && cbDC != null)
o = cbDC.Organisation;
if (o != null)
{
orgDC.OrganisationOid = o.OrganisationOid;
orgDC.Name = o.Name;
orgDC.ActualHourlyRate = o.ActualHourlyRate;
orgDC.ActualMinuteIntervall = o.ActualMinuteIntervall;
orgDC.ActualRateFactor = o.ActualRateFactor;
orgDC.CostRatePeriods = o.CostRatePeriods;
orgDC.IsCalculatingWithFactor = o.IsCalculatingWithFactor;
}
relDC.ApprovedEndDate = cbDC.ApprovedEndDate;
relDC.ApprovedStartDate = cbDC.ApprovedStartDate;
relDC.CostBearer = orgDC;
relDC.CostBearer2SupportConceptOid = cbDC.CostBearer2SupportConceptOid;
relDC.RequestedEndDate = cbDC.RequestedEndDate;
relDC.RequestedStartDate = cbDC.RequestedStartDate;
relDC.Status = cbDC.SupportConceptStatus;
relDC.SupportConcept = dc;
2017-04-03 13:07:06 +02:00
relDC.AuswahlBezeichnung = cbDC.Bezeichnung;
2016-06-27 01:45:38 +02:00
treeNode.SupportConceptCostBearerRelDC = relDC;
treeNode.CostBearer = orgDC;
}
flatNode.SupportConceptTreeNodeDC = treeNode;
}
return flatNode;
}
2017-12-17 17:29:07 +01:00
public static ServiceRecordDC ErstelleServiceRecordDC(DateTime firstTime, DateTime lastTime, CompactCustomerDC customerCompact, List<CompactSupportConceptDC> scList)
{
var dc = new ServiceRecordDC();
//Neu Für multiselect
if (firstTime.Date != lastTime.Date)
{
dc.Start = lastTime;
dc.End = lastTime;
dc.RoundedDuration = 0;
}
else
{
dc.Start = firstTime;
dc.End = lastTime;
dc.RoundedDuration = (decimal)lastTime.Subtract(firstTime).TotalMinutes;
}
dc.Employee = MainSession.LoggedOnUser.Employee;
2017-12-17 17:29:07 +01:00
dc.Customer = customerCompact;
if (customerCompact != null)
{
dc.SupportConcept = HoleHilfeplanAusListe(scList, customerCompact, firstTime, lastTime);
}
if (MainSession.AppSettings.IsEndDateVisible)
2017-12-17 17:29:07 +01:00
{
dc.ServiceRecordFormat = ServiceRecordFormate.ZeiterfassungMitEndDatum;
}
else if (MainSession.AppSettings.IsOnlyYearMonthVisible)
2017-12-17 17:29:07 +01:00
{
dc.ServiceRecordFormat = ServiceRecordFormate.ZeiterfassungMitMonatJahr;
}
else
{
dc.ServiceRecordFormat = ServiceRecordFormate.OriginaleZeiterfassung;
}
dc.DurationInStunden = ZeiterfassungsDauer.Minuten;
return dc;
}
public static CompactSupportConceptDC HoleHilfeplanAusListe(List<CompactSupportConceptDC> scList, CompactCustomerDC customerCompact, DateTime firstTime, DateTime lastTime)
{
foreach (var sc in scList)
{
if (sc.Customer.Oid == customerCompact.Oid)
{
if (sc.StartDate.HasValue && sc.EndDate.HasValue && sc.StartDate <= lastTime &&
sc.EndDate >= firstTime)
{
return sc;
}
}
}
return null;
}
2016-06-27 01:45:38 +02:00
}
}