115 lines
3.8 KiB
C#
115 lines
3.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Service.DCEntityMapper;
|
|
using BeWo.Service.Invoicing;
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Extensions;
|
|
using BS.Shared.Services;
|
|
|
|
namespace Inkomm.Invoicing
|
|
{
|
|
|
|
public class CustomSettlementInvoiceCreation : SettlementInvoiceCreation
|
|
{
|
|
public override bool CanCreateInvoiceTheOldWay(Settlement2DC si, CostBearer2SupportConcept c2s)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public override bool IsServiceRecordBillable(ServiceRecord iRecord)
|
|
{
|
|
if (iRecord.ServiceDescription.ServiceCategory.Name.ToLower().Contains("assistenz"))
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public override void CalculateSettlementInvoiceApprovedAmounts(Settlement2DC si, SupportConceptCostBearerRelDC relDC, Calculations calc)
|
|
{
|
|
si.ApprovedFLSWeekly = 0;
|
|
si.ApprovedFLS = 0;
|
|
foreach (var sp in relDC.ApprovalPeriodList)
|
|
{
|
|
if (sp.ServiceCategory == null || !sp.ServiceCategory.Name.ToLower().Contains("assistenz"))
|
|
{
|
|
si.ApprovedFLSWeekly += calc.GetApprovedHoursPerWeek(sp, relDC.CostBearer.CostRatePeriods) ?? 0m;
|
|
|
|
decimal flsTotal = calc.GetApprovedHoursTotal(sp, relDC.CostBearer.CostRatePeriods) ?? 0m;
|
|
flsTotal = Math.Round(flsTotal, 2, MidpointRounding.AwayFromZero);
|
|
|
|
si.ApprovedFLS += flsTotal;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public override IList<ServiceRecord> GetBillableServiceRecords(CostBearer2SupportConcept c2s)
|
|
{
|
|
return c2s.ServiceRecords.OrderBy(s => s.Start).Where(s => !s.ServiceDescription.ServiceCategory.Name.ToLower().Contains("assistenz")).ToList();
|
|
}
|
|
|
|
public override void CalculateInvoiceItemAmounts(Settlement2DC si)
|
|
{
|
|
decimal flsAufgebraucht = 0;
|
|
decimal flsBudgetGesamt = si.ApprovedFLS ?? 0;
|
|
|
|
foreach (var ii in si.InvoiceItems)
|
|
{
|
|
if (ii.UnitCount.HasValue)
|
|
{
|
|
if (ii.UnitCount > 0)
|
|
{
|
|
// dieser Abschnitt prueft und kappt ggf. Stunden bei Ueberschreitung Budget - unter Beruecksichtigung ProzentBudget in Leistung(skategorien)
|
|
var unitCountBudget = Math.Round(ii.UnitCountBudget ?? ii.UnitCount ?? 0, 2, MidpointRounding.AwayFromZero);
|
|
ii.UnitCount = Math.Round(ii.UnitCount.Value, 2, MidpointRounding.AwayFromZero);
|
|
var relation = unitCountBudget / ii.UnitCount.Value;
|
|
var gewichteteStunden = ii.UnitCount * relation;
|
|
if (gewichteteStunden > flsBudgetGesamt - flsAufgebraucht)
|
|
{
|
|
gewichteteStunden = flsBudgetGesamt - flsAufgebraucht;
|
|
ii.UnitCount = gewichteteStunden / relation;
|
|
}
|
|
flsAufgebraucht += ii.UnitCount.Value * relation;
|
|
}
|
|
|
|
if (ii.AmountPerUnit.HasValue)
|
|
{
|
|
if (!String.IsNullOrEmpty(ii.ItemDescription) && ii.ItemDescription.ToLower().Contains("fehlkontakt") && ii.ProzentAbrechenbar.HasValue)
|
|
{
|
|
ii.AmountPerUnit = ii.AmountPerUnit * ii.ProzentAbrechenbar / 100;
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
}
|