diff --git a/ReportImp/AidsHilfeDuisburg/Invoicing/SettlementInvoiceCreation.cs b/ReportImp/AidsHilfeDuisburg/Invoicing/SettlementInvoiceCreation.cs index d3a126356..3c0654e3d 100644 --- a/ReportImp/AidsHilfeDuisburg/Invoicing/SettlementInvoiceCreation.cs +++ b/ReportImp/AidsHilfeDuisburg/Invoicing/SettlementInvoiceCreation.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using BeWo.Data.Access; using BeWo.Data.Entities; using BeWo.Service.DCEntityMapper; using BeWo.Service.Invoicing; @@ -70,5 +71,67 @@ namespace AidsHilfeDuisburg.Invoicing } } } + + public override List CreateInvoiceItemsForAccountingPeriods(Settlement2DC si, List accountingPeriods, + List costRatePeriods, Calculations calc) + { + Dictionary oid2Scap = new Dictionary(); + List invoiceItems = new List(); + var cb2sc = MapperFactory.SupportConceptCostBearerRelDC_CostBearer2SupportConcept.MapToNewDC(DAOFactory.GenericDAO.GetByID(si.CostBearer2SupportConceptOid.Value)); + foreach (var ap in accountingPeriods) + { + if (ap.ServiceCategory.Name.Contains("Assistenz")) + continue; + + InvoiceItemDC ii = CreateInvoiceItemForAccountingPeriod(ap); + invoiceItems.Add(ii); + + var scap = ap.SupportConceptApprovalPeriod; + SupportConceptApprovalPeriodDC scapHelper = null; + + if (scap != null) + { + if (oid2Scap.ContainsKey(scap.SupportConceptApprovalPeriodOid.Value)) + scapHelper = oid2Scap[scap.SupportConceptApprovalPeriodOid.Value]; + else + { + scapHelper = new SupportConceptApprovalPeriodDC(); + scapHelper.ApprovedBETotal = scap.ApprovedBETotal; + if (!scapHelper.ApprovedBETotal.HasValue) + scapHelper.ApprovedBETotal = calc.GetApprovedBETotal(scap, costRatePeriods); + + oid2Scap[scap.SupportConceptApprovalPeriodOid.Value] = scapHelper; + } + } + + if (!si.ApprovedFLS.HasValue) + { + if (scapHelper.ApprovedBETotal.HasValue && ii.UnitCount.HasValue) + { + if (scapHelper.ApprovedBETotal >= ii.UnitCount.Value) + { + scapHelper.ApprovedBETotal -= ii.UnitCount.Value; + ii.MaxApprovedUnitCount = null; + } + else + { + ii.MaxApprovedUnitCount = scapHelper.ApprovedBETotal; + } + } + + CalculateInvoiceItemAmounts(ii); + } + + if (ii.UnitCount.HasValue) + { + si.RecordedBillableFLSBrutto = (si.RecordedBillableFLSBrutto ?? 0) + ii.UnitCount; + si.RecordedBillableFLSNetto = si.RecordedBillableFLSBrutto ?? 0; + } + + var list = CreateAdditionalInvoiceItems(ap); + invoiceItems.AddRange(list); + } + return invoiceItems; + } } }