196 lines
8.5 KiB
C#
196 lines
8.5 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 SHKService.Invoicing
|
|
{
|
|
public class CollectiveInvoiceCreation : InvoiceCreation
|
|
{
|
|
private DateTime? accountingPeriodStart = null;
|
|
private DateTime? accountingPeriodEnd = null;
|
|
private decimal AMOUNT_PER_KMQA = 0.0231m;
|
|
private decimal AMOUNT_PER_KMKA = 0.0108m;
|
|
|
|
|
|
public override void SetInvoiceId(ServiceInvoice invoice)
|
|
{
|
|
invoice.InvoiceBase.InvoiceId = "Sammelrechnung";
|
|
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, "Fahrtkosten QAS", (DateTime)accountingPeriodStart);
|
|
if (pauschVar != 0)
|
|
{
|
|
AMOUNT_PER_KMQA = pauschVar;
|
|
}
|
|
pauschVar = 0;
|
|
pauschVar = GetPreis(preise, "Fahrtkosten KAS", (DateTime)accountingPeriodStart);
|
|
if (pauschVar != 0)
|
|
{
|
|
AMOUNT_PER_KMKA = pauschVar;
|
|
}
|
|
}
|
|
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);
|
|
|
|
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,
|
|
Notice = "keine Minuten"
|
|
};
|
|
if (supportConceptApprovalPeriod.ApprovedBEPerInterval.HasValue)
|
|
{
|
|
ii.Notice = String.Format("{0:n0}", supportConceptApprovalPeriod.ApprovedBEPerInterval.Value);
|
|
if (supportConceptApprovalPeriod.ServiceCategory.Name == "Fahrzeit")
|
|
{
|
|
if (cb2sc.SupportConcept.Customer.Person.LastNameFirstName.ToLower().Contains("(ka"))
|
|
{
|
|
ii.AmountPerUnit = supportConceptApprovalPeriod.ApprovedBEPerInterval * AMOUNT_PER_KMKA;
|
|
ii.ItemDescription = "Fahrzeiten KA";
|
|
}
|
|
else
|
|
{
|
|
ii.AmountPerUnit = supportConceptApprovalPeriod.ApprovedBEPerInterval * AMOUNT_PER_KMQA;
|
|
ii.ItemDescription = "Fahrzeiten QA";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (cb2sc.SupportConcept.Customer.Person.LastNameFirstName.ToLower().Contains("(ka"))
|
|
{
|
|
ii.AmountPerUnit = supportConceptApprovalPeriod.ApprovedBEPerInterval * (decimal)Math.Round((double)data[0].AmountTotal / 60, 4, MidpointRounding.AwayFromZero);
|
|
ii.ItemDescription = "Kompensatorische Assistenz";
|
|
}
|
|
else
|
|
{
|
|
var LG = (decimal)GetLeistungsgruppe(supportConceptApprovalPeriod.ApprovedBEPerInterval);
|
|
if (data.Count > 0 && data[0].AmountTotal != null)
|
|
{
|
|
ii.AmountPerUnit = (decimal)Math.Round((double)data[0].AmountTotal * Math.Round((double)LG / 60, 2, MidpointRounding.AwayFromZero), 2, MidpointRounding.AwayFromZero);
|
|
//ii.AmountPerUnit = LG * (decimal)Math.Round((double)data[0].AmountTotal / 60, 4, MidpointRounding.AwayFromZero);
|
|
}
|
|
ii.ItemDescription = "Qualifizierte Assistenz";
|
|
ii.Notice = LG.ToString();
|
|
}
|
|
}
|
|
|
|
ii.AmountPerUnit = Math.Round((decimal)ii.AmountPerUnit, 2, MidpointRounding.AwayFromZero);
|
|
ii.AmountTotal = ii.UnitCount * ii.AmountPerUnit;
|
|
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;
|
|
}
|
|
|
|
private object GetLeistungsgruppe(decimal? approvedBEPerInterval)
|
|
{
|
|
// alle Leistungen werden in Stufen - sogenannten Leistungsgruppen abgerechnet -
|
|
// bei der QA/KA tragen sie die tatsächlich bewilligten Minuten ein, um zu wissen wie viel sie leisten müssen - Abrechnung braucht aber LG
|
|
decimal lg = 60;
|
|
if (approvedBEPerInterval == null || approvedBEPerInterval.Value < 91)
|
|
{
|
|
lg = 60;
|
|
}
|
|
else if (approvedBEPerInterval.Value < 151)
|
|
{
|
|
lg = 120;
|
|
}
|
|
else if (approvedBEPerInterval.Value < 211)
|
|
{
|
|
lg = 180;
|
|
}
|
|
else if (approvedBEPerInterval.Value < 271)
|
|
{
|
|
lg = 240;
|
|
}
|
|
else if (approvedBEPerInterval.Value < 391)
|
|
{
|
|
lg = 330;
|
|
}
|
|
else if (approvedBEPerInterval.Value < 511)
|
|
{
|
|
lg = 450;
|
|
}
|
|
else if (approvedBEPerInterval.Value < 751)
|
|
{
|
|
lg = 630;
|
|
}
|
|
else if (approvedBEPerInterval.Value < 1051)
|
|
{
|
|
lg = 900;
|
|
}
|
|
|
|
return lg;
|
|
}
|
|
}
|
|
}
|