Files
BeWoPlaner/BeWoPlanerMobil/Util/DcToMokMapper.cs
2025-06-17 13:06:29 +02:00

150 lines
4.6 KiB
C#

using BeWoPlanerMobil.Models;
using BS.Shared;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using BS.Shared.DataContracts.Invoicing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Windows.Media;
namespace BeWoPlanerMobil.Util
{
public class DcToMokMapper
{
public static MokMandator CreateMandator(MandatorDC dc)
{
return new MokMandator
{
Settings = dc.Settings
};
}
public static MokServiceRecord CreateServiceRecord(ServiceRecordDC dc, ReportModel model)
{
var s = new MokServiceRecord
{
Oid = dc.ServiceRecordOid.Value,
Start = dc.Start,
End = dc.End,
EmployeeName = dc.Employee.FirstNameLastName,
ServiceCategoryName = dc.ServiceDescription.CategoryName,
ServiceDescriptionName = dc.ServiceDescription.Name,
SignatureOid = dc.SignatureOid,
Notice = dc.Notice,
Notice2 = dc.Notice2,
Notice3 = dc.Notice3,
Notice4 = dc.Notice4,
Notice5 = dc.Notice5,
RoundedDuration = dc.RoundedDuration,
DistanceInMeterDecimal = dc.DistanceInMeterDecimal,
Betrag = dc.Betrag,
InsertedOn = dc.InsertedOn,
InsUser = dc.InsUser,
GroupOid = dc.GroupOid,
GroupPersonCount = dc.GroupPersonCount,
GroupEmployeeCount = dc.GroupEmployeeCount
};
if (s.Start.HasValue && s.End.HasValue)
{
s.HasSignatureString = s.SignatureOid.HasValue ? "JA" : "NEIN";
var start = s.Start.Value;
var end = s.End.Value;
var duration = (end - start).TotalMinutes;
var roundedDuration = MobileUtils.GetDecimalValueWithMaxDecimal(s.RoundedDuration, 2);
if (dc.ServiceDescription.Category.Percentage > 0 && dc.ServiceDescription.Category.Percentage < 100)
{
roundedDuration = roundedDuration * dc.ServiceDescription.Category.Percentage / 100;
}
s.DurationString = dc.GroupOid.HasValue ? string.Format("{0:###0.#} ({0:###0.#})", roundedDuration) : $"{duration:###0.#} ({roundedDuration:###0.#})";
s.MassnahmenString = string.Empty;
s.ZieleString = string.Empty;
if (dc.Goals != null && dc.Goals.Count > 0)
{
foreach (var goal in dc.Goals.Where(g => g.Type == ValueListEntryType.SupportConceptGoalType || g.Type == ValueListEntryType.SupportConceptIndividualGoalType))
{
if (goal.Abbreviation != null && goal.TypeDescription != null)
{
s.MassnahmenString += $"{goal.Abbreviation}: {goal.TypeDescription}";
}
else if (goal.Abbreviation is null && goal.TypeDescription != null)
{
s.MassnahmenString += goal.TypeDescription;
}
else if (goal.Abbreviation != null && goal.TypeDescription is null)
{
s.MassnahmenString += goal.Abbreviation;
}
#if DEBUG
if (goal.RatingTypeOid.HasValue)
{
var goalRating = model.GoalRatingTypes.FirstOrDefault(g => g.RatingTypeOid.HasValue && g.RatingTypeOid.Equals(goal.RatingTypeOid.Value));
if (goalRating?.DisplayName != null && goalRating.DisplayName.Length > 0)
{
s.MassnahmenString += $" <strong style='color: blue;'>({goalRating.DisplayName})</strong>";
}
}
#endif
if (dc.Goals.IndexOf(goal) < dc.Goals.Count - 1)
{
s.MassnahmenString += ", ";
}
}
if (model.ServiceRecordOids2GoalHeader.ContainsKey(s.Oid))
{
var ziele = dc.Goals.Where(g => g.Type == ValueListEntryType.SupportConceptIndividualGoalCategoryType || g.Type == ValueListEntryType.SupportConceptGoalCategoryType).ToList();
foreach (var ziel in ziele)
{
if (ziel.Abbreviation != null && ziel.TypeDescription != null)
{
s.ZieleString += $"{ziel.Abbreviation}: {ziel.TypeDescription} ";
}
else if (ziel.Abbreviation is null && ziel.TypeDescription != null)
{
s.ZieleString += ziel.TypeDescription;
}
else if (ziel.Abbreviation != null && ziel.TypeDescription is null)
{
s.ZieleString += ziel.Abbreviation;
}
#if DEBUG
if (ziel.RatingTypeOid.HasValue)
{
var zielbewertung = model.GoalRatingTypes.FirstOrDefault(goalRatingType => goalRatingType.RatingTypeOid.HasValue && goalRatingType.RatingTypeOid.Equals(ziel.RatingTypeOid.Value));
if (zielbewertung?.DisplayName != null && zielbewertung.DisplayName.Length > 0)
{
s.ZieleString += $" <strong style='color: blue;'>({zielbewertung.DisplayName})</strong>";
}
}
#endif
s.ZieleString += ", ";
}
}
s.ZieleString = s.ZieleString.TrimEnd(' ').TrimEnd(',');
}
}
return s;
}
}
}