123 lines
5.1 KiB
C#
123 lines
5.1 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 AidshilfeFulda.Invoicing
|
|
{
|
|
public class CollectiveInvoiceCreation : InvoiceCreation
|
|
{
|
|
private DateTime? accountingPeriodStart = null;
|
|
private DateTime? accountingPeriodEnd = null;
|
|
private decimal AMOUNT_PER_KMQA = 0.0217m;
|
|
|
|
|
|
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, "Fahrtpauschale QA", (DateTime)accountingPeriodStart);
|
|
if (pauschVar != 0)
|
|
{
|
|
AMOUNT_PER_KMQA = 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
|
|
};
|
|
if (supportConceptApprovalPeriod.ServiceCategory.Name.Contains("Fahrzeit"))
|
|
{
|
|
ii.AmountPerUnit = supportConceptApprovalPeriod.ApprovedBEPerInterval * AMOUNT_PER_KMQA;
|
|
ii.ItemDescription = "Fahrzeiten QA";
|
|
}
|
|
else
|
|
{
|
|
ii.AmountPerUnit = supportConceptApprovalPeriod.ApprovedBEPerInterval / 60 * data[0].AmountTotal;
|
|
ii.ItemDescription = "Qualifizierte Assistenz";
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|