diff --git a/ReportImp/Inkomm/Invoicing/CustomInvoiceFactory.cs b/ReportImp/Inkomm/Invoicing/CustomInvoiceFactory.cs index 1aa989ea1..dc7941c3a 100644 --- a/ReportImp/Inkomm/Invoicing/CustomInvoiceFactory.cs +++ b/ReportImp/Inkomm/Invoicing/CustomInvoiceFactory.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using BeWo.Data.Entities; using BeWo.Service.Invoicing; using BS.Shared.DataContracts; using BS.Shared.DataContracts.Compact; @@ -8,8 +9,12 @@ namespace Inkomm.Invoicing { public class CustomInvoiceFactory : InvoiceFactory { - - public override InvoiceCreation CreateInvoiceCreator(string specificId, string tenant, Dictionary> supportConcepts2ServiceRecords) + public override SettlementInvoiceCreation CreateSettlementInvoiceCreator(string costbearerId, string tenant, CostBearer2SupportConcept lCb2Sc) + { + return new CustomSettlementInvoiceCreation(); + } + + public override InvoiceCreation CreateInvoiceCreator(string specificId, string tenant, Dictionary> supportConcepts2ServiceRecords) { //foreach (var list in supportConcepts2ServiceRecords.Values) diff --git a/ReportImp/Inkomm/Invoicing/SettlementInvoiceCreation.cs b/ReportImp/Inkomm/Invoicing/SettlementInvoiceCreation.cs index 79762bbe2..cffc1d791 100644 --- a/ReportImp/Inkomm/Invoicing/SettlementInvoiceCreation.cs +++ b/ReportImp/Inkomm/Invoicing/SettlementInvoiceCreation.cs @@ -16,14 +16,56 @@ namespace Inkomm.Invoicing public class CustomSettlementInvoiceCreation : SettlementInvoiceCreation { - - public override bool IsServiceRecordBillable(ServiceRecord iRecord) - { - if (iRecord.ServiceDescription.ServiceCategory.Name.Contains("Fachleistung")) - { - return true; - } - return false; - } - } + public override void CalculateInvoiceItemAmounts(Settlement2DC si) + { + decimal maxApprovedFls = si.ApprovedFLS ?? 0; + + foreach (var ii in si.InvoiceItems) + { + if (ii.UnitCount.HasValue) + { + var uc = Math.Round(ii.UnitCount ?? 0, 2, MidpointRounding.AwayFromZero); + if (maxApprovedFls < uc) + uc = maxApprovedFls; + + maxApprovedFls -= uc; + + ii.UnitCount = uc; + + if (ii.AmountPerUnit.HasValue) + { + ii.AmountTotal = ii.UnitCount.Value * ii.AmountPerUnit.Value; + if (ii.RateFactor.HasValue && ii.RateFactor.Value != 0 && ii.ItemDescription != null && !ii.ItemDescription.Contains("Assistenz")) + ii.GrossAmountTotal = Math.Round(ii.AmountTotal.Value * ((100m + ii.RateFactor.Value) / 100m), 2, + MidpointRounding.AwayFromZero); + else + ii.GrossAmountTotal = ii.AmountTotal; + + } + if (ii.MaxApprovedUnitCount < ii.UnitCount) + { + ii.MaxApprovedUnitCount = ii.UnitCount; + } + } + } + } + + public override InvoiceItemDC CreateInvoiceItemForAccountingPeriod(AccountingPeriod accountingPeriod) + { + var item = base.CreateInvoiceItemForAccountingPeriod(accountingPeriod); + if (accountingPeriod.ServiceCategory != null && accountingPeriod.ServiceCategory.Name.StartsWith("Assistenz")) + item.RateFactor = 0; + return item; + } + + //public override bool IsServiceRecordBillable(ServiceRecord iRecord) + // { + // if (iRecord.ServiceDescription.ServiceCategory.Name.Contains("Fachleistung") || iRecord.ServiceDescription.ServiceCategory.Name.Contains("Assistenz")) + // { + // return true; + // } + // return false; + // } + + } }