197 lines
9.0 KiB
C#
197 lines
9.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Report.ReportObjects;
|
|
using BeWo.Service.DCEntityMapper;
|
|
using BeWo.Service.Invoicing;
|
|
using BeWo.Service.Plugins;
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.Compact;
|
|
using BS.Shared.Extensions;
|
|
using BS.Shared.Services;
|
|
|
|
namespace KlinikumWerraMeissner.Invoicing
|
|
{
|
|
public class CollectiveInvoiceCreation : InvoiceCreation
|
|
{
|
|
private DateTime? accountingPeriodStart = null;
|
|
private DateTime? accountingPeriodEnd = null;
|
|
private decimal AMOUNT_PER_KMQA = 3.02m;
|
|
private decimal AMOUNT_PER_MIN = 0.1871m;
|
|
|
|
|
|
public override void SetInvoiceId(ServiceInvoice invoice)
|
|
{
|
|
invoice.InvoiceBase.InvoiceId = "SammelrechnungNeu";
|
|
invoice.InvoiceBase.InvoiceTypeText = "Sammelrechnung LWV";
|
|
}
|
|
|
|
public override void SetInvoiceBaseData(int invoiceCounter, ServiceInvoice invoice, CostBearer costBearer, DateTimeSpan invoicePeriod,
|
|
IList<CompactSupportConceptDC> supportConceptList)
|
|
{
|
|
if (invoicePeriod != null)
|
|
{
|
|
accountingPeriodStart = invoicePeriod.StartDate;
|
|
accountingPeriodEnd = invoicePeriod.EndDate;
|
|
var preise = DAOFactory.GenericDAO.GetAllActive<Preis>();
|
|
var pauschVar = GetPreis(preise, "Fahrtkostenwert QA", (DateTime)accountingPeriodStart);
|
|
if (pauschVar != 0)
|
|
{
|
|
AMOUNT_PER_KMQA = pauschVar;
|
|
}
|
|
if (accountingPeriodStart > new DateTime(2023, 12, 31))
|
|
{
|
|
var minPreis = GetPreis(preise, "Qualifizierte Assistenz (Altfälle)", (DateTime)accountingPeriodStart);
|
|
if (minPreis != 0)
|
|
{
|
|
AMOUNT_PER_MIN = minPreis;
|
|
}
|
|
}
|
|
}
|
|
base.SetInvoiceBaseData(invoiceCounter, invoice, costBearer, invoicePeriod, supportConceptList);
|
|
}
|
|
public override void SetInvoiceItems(ServiceInvoice invoice,
|
|
ServiceInvoicePeriod serviceInvoicePeriod,
|
|
SupportConceptApprovalPeriodDC supportConceptApprovalPeriod,
|
|
CostBearer2SupportConcept cb2sc,
|
|
DateTimeSpan invoicePeriod,
|
|
List<ServiceRecordDC> serviceRecords)
|
|
{
|
|
BS.Shared.Services.Calculations calc = PluginLoader.FindClass<BS.Shared.Services.Calculations>(_SpecificID) ?? BS.Shared.Services.Calculations.GetInstance(_SpecificID);
|
|
CreateFixedAmounts(serviceInvoicePeriod, supportConceptApprovalPeriod, cb2sc);
|
|
}
|
|
|
|
|
|
public override void CreateFixedAmounts(ServiceInvoicePeriod serviceInvoicePeriod, SupportConceptApprovalPeriodDC supportConceptApprovalPeriod, CostBearer2SupportConcept cb2sc)
|
|
{
|
|
var calc = PluginLoader.FindClass<BS.Shared.Services.Calculations>(_SpecificID) ?? BS.Shared.Services.Calculations.GetInstance(_SpecificID);
|
|
var data = calc.GetFixedBillingData(supportConceptApprovalPeriod, serviceInvoicePeriod.Start, serviceInvoicePeriod.End);
|
|
|
|
if (supportConceptApprovalPeriod.ServiceCategory != null && supportConceptApprovalPeriod.ServiceCategory.Name == "Qualifizierte Assistenz")
|
|
{
|
|
foreach (var billingData in data)
|
|
{
|
|
var ii = new InvoiceItem
|
|
{
|
|
AmountTotal = billingData.AmountTotal,
|
|
GrossAmountTotal = billingData.GrossAmountTotal,
|
|
ItemPeriodStart = billingData.BillingPeriodStart,
|
|
ItemPeriodEnd = billingData.BillingPeriodEnd,
|
|
AccountingInterval = billingData.AccountingInterval,
|
|
AmountPerUnit = billingData.AmountPerUnit,
|
|
UnitCount = billingData.UnitCount
|
|
};
|
|
|
|
if (supportConceptApprovalPeriod.ServiceCategory != null)
|
|
{
|
|
ii.ItemDescription = supportConceptApprovalPeriod.ServiceCategory.Name;
|
|
//ii.UnitCount = null;
|
|
}
|
|
if (ii.ItemPeriodStart > new DateTime(2023,12,31))
|
|
{
|
|
decimal preisTag = ii.AmountPerUnit ?? 0;
|
|
var minBew = (decimal)Math.Round((double)supportConceptApprovalPeriod.ApprovedBEPerInterval, 0);
|
|
var minBer = (decimal)Math.Round((double)(preisTag / 0.1793m), 0);
|
|
//if(Math.Abs(minBew - minBer) > 1)
|
|
//{
|
|
// var test = "Diff";
|
|
//}
|
|
ii.AmountPerUnit = (decimal)Math.Round((double)(minBer * AMOUNT_PER_MIN), 2, MidpointRounding.AwayFromZero);
|
|
ii.AmountTotal = ii.AmountPerUnit * ii.UnitCount;
|
|
ii.GrossAmountTotal = ii.AmountTotal;
|
|
}
|
|
|
|
serviceInvoicePeriod.InvoiceItemList.Add(ii);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
DateTime start = accountingPeriodStart.Value;
|
|
DateTime end = accountingPeriodEnd.Value;
|
|
if (supportConceptApprovalPeriod.StartDate > start)
|
|
{
|
|
start = supportConceptApprovalPeriod.StartDate.Value;
|
|
}
|
|
if (supportConceptApprovalPeriod.EndDate < end)
|
|
{
|
|
end = supportConceptApprovalPeriod.EndDate.Value;
|
|
}
|
|
|
|
if (supportConceptApprovalPeriod.ServiceCategory != null)
|
|
{
|
|
var ii = new InvoiceItem
|
|
{
|
|
ItemPeriodStart = serviceInvoicePeriod.Start,
|
|
ItemPeriodEnd = serviceInvoicePeriod.End,
|
|
SupportConceptApprovalPeriodOid = supportConceptApprovalPeriod.SupportConceptApprovalPeriodOid,
|
|
AccountingInterval = AccountingIntervalType.Daily,
|
|
UnitCount = (decimal)(end - start).TotalDays + 1
|
|
};
|
|
if (supportConceptApprovalPeriod.ServiceCategory.Name.Contains("Fahrtkostenwert"))
|
|
{
|
|
ii.AmountPerUnit = supportConceptApprovalPeriod.ApprovedBEPerInterval * AMOUNT_PER_KMQA;
|
|
ii.ItemDescription = "Fahrzeiten QA";
|
|
}
|
|
else if (supportConceptApprovalPeriod.ServiceCategory.Name.ToLower().Contains("besonders vorgehaltene flächen"))
|
|
{
|
|
ii.AmountPerUnit = data[0].AmountTotal;
|
|
ii.ItemDescription = "Besonders vorgehaltene Flächen";
|
|
}
|
|
else
|
|
{
|
|
ii.AmountPerUnit = data[0].AmountTotal;
|
|
ii.ItemDescription = "Qualifizierte Assistenz";
|
|
}
|
|
|
|
ii.AmountTotal = 0;
|
|
if (ii.AmountPerUnit != null)
|
|
{
|
|
ii.AmountTotal = ii.UnitCount * Math.Round((decimal)ii.AmountPerUnit, 2, MidpointRounding.AwayFromZero);
|
|
}
|
|
ii.GrossAmountTotal = ii.AmountTotal;
|
|
serviceInvoicePeriod.InvoiceItemList.Add(ii);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static decimal GetPreis(IList<Preis> allePreise, String name, DateTime datum)
|
|
{
|
|
var pausch = allePreise.Where(p => p.Name.Contains(name)).FirstOrDefault();
|
|
if (pausch != null)
|
|
{
|
|
var crlist = MapperFactory.CostRatePeriodDC_CostRatePeriod.MapToNewDCs(pausch.CostRatePeriods);
|
|
|
|
var cr = crlist.GetCostRatePeriodForDate(CostRatePeriodType.AmountOfMoney, datum);
|
|
if (cr != null && cr.CostRateValue.HasValue)
|
|
{
|
|
return cr.CostRateValue.Value;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public override void SetServiceInvoicePeriodAmounts(ServiceInvoice invoice)
|
|
{
|
|
foreach (ServiceInvoicePeriod iPeriod in invoice.ServiceInvoicePeriodList)
|
|
{
|
|
iPeriod.Claim = 0;
|
|
if (iPeriod.SupportConceptApprovalPeriod.ServiceCategory.Name != "Qualifizierte Assistenz" && iPeriod.ApprovedFixedAmount.HasValue && iPeriod.ApprovedFixedAmount.Value != 0)
|
|
iPeriod.Claim = iPeriod.ApprovedFixedAmount;
|
|
else
|
|
{
|
|
foreach (InvoiceItem item in iPeriod.InvoiceItemList)
|
|
{
|
|
if (item.GrossAmountTotal.HasValue)
|
|
iPeriod.Claim += item.GrossAmountTotal;
|
|
}
|
|
}
|
|
iPeriod.Claim = Math.Round(iPeriod.Claim.Value, 2, MidpointRounding.AwayFromZero);
|
|
}
|
|
}
|
|
}
|
|
}
|