diff --git a/ReportImp/LebenshilfeBadKreuznach/Invoicing/CustomCalculations.cs b/ReportImp/LebenshilfeBadKreuznach/Invoicing/CustomCalculations.cs new file mode 100644 index 000000000..eab4c27b6 --- /dev/null +++ b/ReportImp/LebenshilfeBadKreuznach/Invoicing/CustomCalculations.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; +using BeWo.Data.Access; +using BeWo.Data.Entities; +using BeWo.Service.DCEntityMapper; +using BeWo.Service.Plugins; +using BS.Shared; +using BS.Shared.Core; +using BS.Shared.DataContracts; +using BS.Shared.Extensions; +using BS.Shared.Services; + +namespace LebenshilfeBadKreuznach.Invoicing +{ + public class CustomCalculations : BS.Shared.Services.Calculations + { + public override decimal GetHoursNotBillableDueToAbsenceTimes(SupportConceptApprovalPeriodDC scap, + List costRates, + List records, + Dictionary absenceTimes, + bool doRemoveFromRecordsList, + bool doCrop) + { + if (scap.ApprovedFixedAmount.HasValue) + { + return 0m; + } + + var hoursNotBillableAbsence = 0m; + foreach (var iRecord in records.ToList()) + { + //if (!iRecord.Start.Value.InBetween(scap.Span, true)) + //{ + // if (doRemoveFromRecordsList) + // { + // records.Remove(iRecord); + // } + + // continue; + //} + + var absenceSpan = absenceTimes.FirstOrDefault(i => iRecord.Start.Value.InBetween(i.Key, true)).Key; + + if (absenceSpan != null) + { + var rd = base.GetBillableDurationInMinutes(iRecord, false); + + if (absenceTimes[absenceSpan] == 0) + { + if (doRemoveFromRecordsList) + { + records.Remove(iRecord); + } + + hoursNotBillableAbsence += rd / 60m; + continue; + } + + if (absenceTimes[absenceSpan] - rd >= 0) + { + absenceTimes[absenceSpan] -= rd; + continue; + } + + hoursNotBillableAbsence += (rd - absenceTimes[absenceSpan]) / 60; + + if (!doCrop) + { + if (doRemoveFromRecordsList) + { + records.Remove(iRecord); + } + + continue; + } + + hoursNotBillableAbsence += (rd - absenceTimes[absenceSpan]) / 60; + iRecord.End = iRecord.Start.Value.AddMinutes(Convert.ToDouble(absenceTimes[absenceSpan])); + + var minuteInterval = costRates.GetCostRatePeriodForDate(CostRatePeriodType.MinutesIntervall, iRecord.Start.Value); + var duration = Convert.ToDecimal((iRecord.End - iRecord.Start).Value.TotalMinutes); + + //###CB 5min + if (minuteInterval != null && minuteInterval.CostRateValue.HasValue && minuteInterval.CostRateValue.Value > 0) + { + iRecord.RoundedDuration = GetRoundedDuration((int)minuteInterval.CostRateValue.Value, duration); + } + + absenceTimes[absenceSpan] = 0; + } + } + + return hoursNotBillableAbsence; + } + } +}