136 lines
5.2 KiB
C#
136 lines
5.2 KiB
C#
using BeWo.Data.Entities;
|
|
using BeWo.Service.Invoicing;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Services;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ProIntegra.Invoicing
|
|
{
|
|
public class CustomSettlementInvoiceCreation : SettlementInvoiceCreation
|
|
{
|
|
public override bool CanCreateInvoiceTheOldWay(Settlement2DC si, CostBearer2SupportConcept c2s)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public override InvoiceItemDC CreateInvoiceItemForAccountingPeriod(AccountingPeriod accountingPeriod)
|
|
{
|
|
var item = base.CreateInvoiceItemForAccountingPeriod(accountingPeriod);
|
|
var mins = accountingPeriod.CostRatesInPeriod.FirstOrDefault(p => p.CostRateType == BS.Shared.CostRatePeriodType.MinutesPerServiceUnit);
|
|
|
|
if (mins != null && mins.CostRateValue != null)
|
|
{
|
|
item.UnitCount *= 60 / mins.CostRateValue;
|
|
item.UnitCountBudget *= 60 / mins.CostRateValue;
|
|
}
|
|
|
|
return item;
|
|
}
|
|
|
|
public override List<InvoiceItemDC> CreateInvoiceItemsForAccountingPeriods(Settlement2DC si, List<AccountingPeriod> accountingPeriods,
|
|
List<CostRatePeriodDC> costRatePeriods, Calculations calc)
|
|
{
|
|
Dictionary<long, SupportConceptApprovalPeriodDC> oid2Scap = new Dictionary<long, SupportConceptApprovalPeriodDC>();
|
|
List<InvoiceItemDC> invoiceItems = new List<InvoiceItemDC>();
|
|
|
|
foreach (var ap in accountingPeriods)
|
|
{
|
|
InvoiceItemDC ii = CreateInvoiceItemForAccountingPeriod(ap);
|
|
invoiceItems.Add(ii);
|
|
|
|
// ANPASSUNG
|
|
if (si.RecipientOrganisation.ToLower().Contains("neu"))
|
|
{
|
|
InvoiceItemDC pauschalenItem = CreateKontaktpauschalenItem(ap, si.RecipientOrganisation);
|
|
if (pauschalenItem != null)
|
|
invoiceItems.Add(pauschalenItem);
|
|
}
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
private static InvoiceItemDC CreateKontaktpauschalenItem(AccountingPeriod accountingPeriod, string recipientOrganisation)
|
|
{
|
|
InvoiceItemDC invoiceItem = null;
|
|
decimal unitCount = 0;
|
|
|
|
foreach (var sr in accountingPeriod.ServiceRecordsInPeriod)
|
|
{
|
|
if (sr.ServiceDescription.Name.ToLower().Contains("face to face") || sr.ServiceDescription.Name.ToLower().Contains("face to face"))
|
|
{
|
|
unitCount++;
|
|
}
|
|
}
|
|
|
|
if (unitCount > 0)
|
|
{
|
|
decimal pauschale = PauschalenHelper.PAUSCHALE;
|
|
|
|
invoiceItem = new InvoiceItemDC()
|
|
{
|
|
UnitCount = unitCount,
|
|
ItemDescription = "Kontaktpauschale",
|
|
UnitDescription = "Pauschale pro direktem Kontakt",
|
|
AmountPerUnit = pauschale,
|
|
AmountTotal = pauschale * unitCount,
|
|
GrossAmountTotal = pauschale * unitCount * accountingPeriod.RateFactor,
|
|
ItemPeriodStart = accountingPeriod.PeriodStart,
|
|
ItemPeriodEnd = accountingPeriod.PeriodEnd,
|
|
};
|
|
}
|
|
|
|
return invoiceItem;
|
|
}
|
|
}
|
|
}
|