354 lines
13 KiB
C#
354 lines
13 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
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)
|
|
{
|
|
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();
|
|
var goalCategoryDict = new Dictionary<long, SupportConceptGoalDC>();
|
|
|
|
|
|
foreach (var goalCat in ziele)
|
|
{
|
|
var treeItem = new SupportConceptGoalDC
|
|
{
|
|
CheckRecursive = false,
|
|
GoalEntryDC = goalCat,
|
|
IsExpanded = allGoalsAndCategories.Count <= 30
|
|
};
|
|
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);
|
|
}
|
|
|
|
foreach (var goal in massnahmen)
|
|
{
|
|
var kind = new SupportConceptGoalDC { GoalEntryDC = goal, CheckRecursive = false };
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//goal.PropertyChanged += (s, e) =>
|
|
//{
|
|
// var selectedGoal = s as SupportConceptGoalDC;
|
|
// if (selectedGoal != null)
|
|
// {
|
|
// if (selectedGoal.IsChecked)
|
|
// {
|
|
// if (!selectedGoals.Contains(selectedGoal.GoalEntryDC))
|
|
// {
|
|
// selectedGoals.Add(selectedGoal.GoalEntryDC);
|
|
// }
|
|
|
|
// }
|
|
// else
|
|
// {
|
|
// selectedGoals.Remove(selectedGoal.GoalEntryDC);
|
|
// }
|
|
// }
|
|
//};
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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;
|
|
relDC.AuswahlBezeichnung = cbDC.Bezeichnung;
|
|
|
|
treeNode.SupportConceptCostBearerRelDC = relDC;
|
|
treeNode.CostBearer = orgDC;
|
|
}
|
|
|
|
flatNode.SupportConceptTreeNodeDC = treeNode;
|
|
}
|
|
|
|
return flatNode;
|
|
}
|
|
|
|
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;
|
|
dc.Customer = customerCompact;
|
|
if (customerCompact != null)
|
|
{
|
|
dc.SupportConcept = HoleHilfeplanAusListe(scList, customerCompact, firstTime, lastTime);
|
|
}
|
|
|
|
if (MainSession.AppSettings.IsEndDateVisible)
|
|
{
|
|
dc.ServiceRecordFormat = ServiceRecordFormate.ZeiterfassungMitEndDatum;
|
|
}
|
|
else if (MainSession.AppSettings.IsOnlyYearMonthVisible)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
} |