PflegedienstWessel/Invoicing/CustomInvoiceCreation aufgesetzt
This commit is contained in:
212
ReportImp/PflegedienstWessel/Invoicing/CustomInvoiceCreation.cs
Normal file
212
ReportImp/PflegedienstWessel/Invoicing/CustomInvoiceCreation.cs
Normal file
@@ -0,0 +1,212 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using BeWo.Data.Access;
|
||||
using BeWo.Data.Entities;
|
||||
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 PflegedienstWessel.Invoicing
|
||||
{
|
||||
|
||||
public class CustomAlltagsunterstuetzungsInvoiceCreation : InvoiceCreation
|
||||
{
|
||||
private DateTime? accountingPeriodStart = null;
|
||||
private DateTime? accountingPeriodEnd = null;
|
||||
|
||||
// public override void SetInvoiceId(ServiceInvoice invoice)
|
||||
//{
|
||||
// invoice.InvoiceBase.InvoiceId = "Alltag";
|
||||
// invoice.InvoiceBase.InvoiceTypeText = "Alltagsunterstützung";
|
||||
//}
|
||||
public override List<ServiceInvoiceDC> GenerateServiceInvoices(long costBearerOid, DateTimeSpan invoicePeriod, Dictionary<CompactSupportConceptDC, List<ServiceRecordDC>> supportConcepts2ServiceRecords)
|
||||
{
|
||||
//bei den weiteren Kostenträgern (außer Persönliches Budget 24 Stunden) wird je eine Rechnung pro Leistungskategorie benötigt
|
||||
// -> es werden für jeden Kunden pro Kostenträger Rechnungen erstellt und hintereinandergefügt
|
||||
var invoiceList = new List<ServiceInvoice>();
|
||||
var invoiceCounter = 0;
|
||||
var sortedScs = supportConcepts2ServiceRecords.Keys.OrderBy(s => s.Customer.LastNameFirstName).ToList();
|
||||
|
||||
foreach (var sc in sortedScs)
|
||||
{
|
||||
var serviceRecords = supportConcepts2ServiceRecords[sc];
|
||||
serviceRecords = serviceRecords.Where(s => !s.ServiceDescription.CategoryName.Contains("Fachleistung")).ToList(); // die sind in Spitzabrechnung
|
||||
if (sc.CostBearerList.Count > 0)
|
||||
{
|
||||
var costBearer = DAOFactory.GenericDAO.LoadByID<CostBearer>(sc.CostBearerList[0].CostBearerOid);
|
||||
Dictionary<string, List<ServiceRecordDC>> srDict = new Dictionary<string, List<ServiceRecordDC>>();
|
||||
|
||||
foreach (var sr in serviceRecords)
|
||||
{
|
||||
String key = sr.ServiceDescription.CategoryName;
|
||||
|
||||
if (!srDict.ContainsKey(key))
|
||||
srDict.Add(key, new List<ServiceRecordDC>());
|
||||
|
||||
srDict[key].Add(sr);
|
||||
}
|
||||
|
||||
foreach (var catName in srDict.Keys)
|
||||
{
|
||||
var list = srDict[catName];
|
||||
var invoice = CreateSingleInvoice(invoiceCounter, costBearer, invoicePeriod, sc, list);
|
||||
|
||||
if (invoice != null)
|
||||
{
|
||||
invoice.InvoiceBase.InvoiceId = "Service";
|
||||
invoiceList.Add(invoice);
|
||||
invoiceCounter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var result = invoiceList.Select(item => MapperFactory.ServiceInvoiceDC_ServiceInvoice.MapToNewDC(item)).ToList();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public override ServiceInvoice CreateSingleInvoice(int invoiceCounter, CostBearer costBearer, DateTimeSpan invoicePeriod, CompactSupportConceptDC supportConcept, List<ServiceRecordDC> serviceRecords)
|
||||
{
|
||||
var i = base.CreateSingleInvoice(invoiceCounter, costBearer, invoicePeriod, supportConcept, serviceRecords);
|
||||
|
||||
if (i != null)
|
||||
{
|
||||
var claim = i.GetTotalClaim();
|
||||
|
||||
if (!claim.HasValue || claim.Value == 0)
|
||||
return null;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
public override void SetInvoiceBaseData(int invoiceCounter, ServiceInvoice invoice, CostBearer costBearer, DateTimeSpan invoicePeriod,
|
||||
IList<CompactSupportConceptDC> supportConceptList)
|
||||
{
|
||||
if (invoicePeriod != null)
|
||||
{
|
||||
accountingPeriodStart = invoicePeriod.StartDate;
|
||||
accountingPeriodEnd = invoicePeriod.EndDate;
|
||||
}
|
||||
base.SetInvoiceBaseData(invoiceCounter, invoice, costBearer, invoicePeriod, supportConceptList);
|
||||
}
|
||||
|
||||
public override void SetRecipientInformation(ServiceInvoice serviceInvoice, CostBearer costBearer)
|
||||
{
|
||||
if (costBearer.Organisation.Name.ToLower().Contains("persönliches Budget"))
|
||||
{
|
||||
serviceInvoice.InvoiceBase.RecipientDivision = costBearer.Organisation.Name2;
|
||||
serviceInvoice.InvoiceBase.RecipientOrganisationOid = costBearer.Organisation.Oid;
|
||||
serviceInvoice.InvoiceBase.RecipientOrganisation = costBearer.Organisation.Name;
|
||||
serviceInvoice.InvoiceBase.RecipientContacts = costBearer.Organisation.Contacts.Select(i => i.CopyToNew()).ToList();
|
||||
serviceInvoice.InvoiceBase.RecipientCostBearerOid = costBearer.Oid;
|
||||
|
||||
if (serviceInvoice.InvoiceBase.CostBearer2SupportConcept != null)
|
||||
{
|
||||
var cust = serviceInvoice.InvoiceBase.CostBearer2SupportConcept.SupportConcept.Customer;
|
||||
|
||||
if (cust.Person.InvoiceAddress != null)
|
||||
{
|
||||
serviceInvoice.InvoiceBase.RecipientAddress = cust.Person.InvoiceAddress.CopyToNew();
|
||||
}
|
||||
else if (cust.Person.Address != null)
|
||||
{
|
||||
serviceInvoice.InvoiceBase.RecipientAddress = cust.Person.Address.CopyToNew();
|
||||
}
|
||||
|
||||
if (cust.Person.InvoiceAddress != null && cust.Person.InvoiceAddress.AddressLine1 != null)
|
||||
{
|
||||
serviceInvoice.InvoiceBase.RecipientPersonFirstName = cust.Person.InvoiceAddress.AddressLine1;
|
||||
serviceInvoice.InvoiceBase.RecipientPersonLastName = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
serviceInvoice.InvoiceBase.RecipientPersonFirstName = cust.Person.FirstName;
|
||||
serviceInvoice.InvoiceBase.RecipientPersonLastName = cust.Person.LastName;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (costBearer.Organisation.InvoiceAddress != null)
|
||||
{
|
||||
serviceInvoice.InvoiceBase.RecipientAddress = costBearer.Organisation.InvoiceAddress.CopyToNew();
|
||||
}
|
||||
else if (costBearer.Organisation.Address != null)
|
||||
{
|
||||
serviceInvoice.InvoiceBase.RecipientAddress = costBearer.Organisation.Address.CopyToNew();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetServiceInvoicePeriods(ServiceInvoice invoice, CostBearer2SupportConcept costBearer2SupportConcept,
|
||||
DateTimeSpan invoicePeriod, List<ServiceRecordDC> serviceRecords)
|
||||
{
|
||||
var invoiceAccountingPeriodSpan = new DateTimeSpan
|
||||
{
|
||||
StartDateTime = invoice.InvoiceBase.AccountingPeriodStart.Value,
|
||||
EndDateTime = invoice.InvoiceBase.AccountingPeriodEnd.Value
|
||||
};
|
||||
|
||||
foreach (SupportConceptApprovalPeriod iPeriod in costBearer2SupportConcept.ApprovalPeriodList)
|
||||
{
|
||||
SupportConceptApprovalPeriodDC approvalPeriodDC = MapperFactory.SupportConceptApprovalPeriodDC_SupportConceptApprovalPeriod.MapToNewDC(iPeriod);
|
||||
|
||||
|
||||
if (approvalPeriodDC.Span.EndDateTime < invoiceAccountingPeriodSpan.StartDateTime || approvalPeriodDC.Span.StartDateTime > invoiceAccountingPeriodSpan.EndDate)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ServiceInvoicePeriod serviceInvoicePeriod = CreateServiceInvoicePeriod(approvalPeriodDC, invoiceAccountingPeriodSpan);
|
||||
serviceInvoicePeriod.SupportConceptApprovalPeriod = iPeriod;
|
||||
serviceInvoicePeriod.Customer = costBearer2SupportConcept.SupportConcept.Customer;
|
||||
|
||||
CostBearer costBearer = costBearer2SupportConcept.CostBearer;
|
||||
List<CostRatePeriodDC> costRates = MapperFactory.CostRatePeriodDC_CostRatePeriod.MapToNewDCs(costBearer.CostRatePeriods);
|
||||
|
||||
CostRatePeriodDC serviceUnit = costRates.GetCostRatePeriodForDate(CostRatePeriodType.MinutesPerServiceUnit, DateTime.Now);
|
||||
serviceInvoicePeriod.ServiceUnitName = serviceUnit.UnitName;
|
||||
|
||||
SetInvoiceItems(invoice, serviceInvoicePeriod, approvalPeriodDC, costBearer2SupportConcept, invoicePeriod, serviceRecords);
|
||||
|
||||
if (serviceInvoicePeriod.InvoiceItemList.Count > 0)
|
||||
invoice.ServiceInvoicePeriodList.Add(serviceInvoicePeriod);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override InvoiceItem CreateInvoiceItem(ServiceRecordDC iServiceRecord, SupportConceptApprovalPeriod scap, Calculations calc)
|
||||
{
|
||||
if (iServiceRecord.ServiceDescription.CategoryName.Contains("Fachleistung"))
|
||||
return null;
|
||||
|
||||
var ii = base.CreateInvoiceItem(iServiceRecord, scap, calc);
|
||||
DateTime start = ii.ItemPeriodStart.Value;
|
||||
decimal preisLeistung = 0;
|
||||
string catName = iServiceRecord.ServiceDescription.CategoryName.ToString();
|
||||
|
||||
var cat = DAOFactory.SearchDAO.FindServiceCategoryByName(catName);
|
||||
if (cat != null)
|
||||
{
|
||||
var crps = MapperFactory.CostRatePeriodDC_CostRatePeriod.MapToNewDCs(cat.CostRatePeriods);
|
||||
var cp = crps.GetCostRatePeriodForDate(CostRatePeriodType.AmountOfMoney, start);
|
||||
if (cp != null && cp.CostRateValue.HasValue)
|
||||
preisLeistung = (decimal)cp.CostRateValue;
|
||||
ii.AmountPerUnit = preisLeistung;
|
||||
ii.RateFactor = null;
|
||||
ii.AmountTotal = preisLeistung * ii.UnitCount;
|
||||
ii.GrossAmountTotal = preisLeistung * ii.UnitCount;
|
||||
ii.ItemDescription = catName;
|
||||
}
|
||||
return ii;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BeWo.Service.Invoicing;
|
||||
using BS.Shared.DataContracts;
|
||||
using BS.Shared.DataContracts.Compact;
|
||||
|
||||
namespace PflegedienstWessel.Invoicing
|
||||
{
|
||||
public class CustomInvoiceFactory : InvoiceFactory
|
||||
{
|
||||
public override InvoiceCreation CreateInvoiceCreator(string specificId, string tenant, Dictionary<CompactSupportConceptDC, List<ServiceRecordDC>> supportConcepts2ServiceRecords)
|
||||
{
|
||||
foreach (var list in supportConcepts2ServiceRecords.Values)
|
||||
{
|
||||
foreach (var sr in list)
|
||||
{
|
||||
if (sr.CostBearer.Name.ToLower().Contains("persönliches budget 24")) // nochmal checken beim deployen wie der Name der Orga ist und Faktor auf FLS in Sammelrechnung?
|
||||
{
|
||||
return new CustomPersBudget24InvoiceCreation();
|
||||
}
|
||||
else
|
||||
{
|
||||
var sd = sr.ServiceDescription.Category;
|
||||
var ic = GetInvoiceCreatorForCategory(sd);
|
||||
if (ic != null)
|
||||
return ic;
|
||||
}
|
||||
}
|
||||
}
|
||||
return base.CreateInvoiceCreator(specificId, tenant, supportConcepts2ServiceRecords);
|
||||
}
|
||||
|
||||
private InvoiceCreation GetInvoiceCreatorForCategory(ServiceCategoryDC sd)
|
||||
{
|
||||
if (sd != null && !String.IsNullOrEmpty(sd.Name))
|
||||
{
|
||||
String cat = sd.Name.ToLower().Trim();
|
||||
if (!cat.Contains("fachleistung"))
|
||||
{
|
||||
return new CustomInvoiceCreation();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using BeWo.Data.Access;
|
||||
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 PflegedienstWessel.Invoicing
|
||||
{
|
||||
|
||||
public class CustomPersBudget24InvoiceCreation : InvoiceCreation
|
||||
{
|
||||
public override void SetInvoiceId(ServiceInvoice invoice)
|
||||
{
|
||||
invoice.InvoiceBase.InvoiceId = "PersBudget";
|
||||
invoice.InvoiceBase.InvoiceTypeText = "PersBudget24";
|
||||
}
|
||||
|
||||
public override void SetAmountAdvancePayments(ServiceInvoice invoice)
|
||||
{
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public override void SetAmountEquityContribution(ServiceInvoice invoice)
|
||||
{
|
||||
//do nothing
|
||||
}
|
||||
|
||||
public override InvoiceItem CreateInvoiceItem(ServiceRecordDC iServiceRecord, SupportConceptApprovalPeriod scap, Calculations calc)
|
||||
{
|
||||
// Anders als bei anderen Kostenträger zahlen die Selbstzahler im Persönlichen Budget 24 Stunden alle Leistungen monatlich aus einer Rechnung
|
||||
|
||||
//if (!iServiceRecord.ServiceDescription.CategoryName.Contains("Assistenz"))
|
||||
// return null;
|
||||
|
||||
var ii = base.CreateInvoiceItem(iServiceRecord, scap, calc);
|
||||
DateTime start = ii.ItemPeriodStart.Value;
|
||||
decimal preisAssistenz = 0;
|
||||
|
||||
//Achtung je nach Preisgestaltung wird jetzt bei FLS kein Faktor gezogen!
|
||||
string catName = iServiceRecord.ServiceDescription.CategoryName.ToString();
|
||||
|
||||
var cat = DAOFactory.SearchDAO.FindServiceCategoryByName(catName);
|
||||
if (cat != null)
|
||||
{
|
||||
var crps = MapperFactory.CostRatePeriodDC_CostRatePeriod.MapToNewDCs(cat.CostRatePeriods);
|
||||
var cp = crps.GetCostRatePeriodForDate(CostRatePeriodType.AmountOfMoney, start);
|
||||
if (cp != null && cp.CostRateValue.HasValue)
|
||||
preisAssistenz = (decimal)cp.CostRateValue;
|
||||
ii.AmountPerUnit = preisAssistenz;
|
||||
ii.RateFactor = null;
|
||||
ii.AmountTotal = preisAssistenz * ii.UnitCount;
|
||||
ii.GrossAmountTotal = preisAssistenz * ii.UnitCount;
|
||||
}
|
||||
return ii;
|
||||
}
|
||||
|
||||
public override IList<InvoiceItem> CreateSummaryInvoiceItems(IList<InvoiceItem> itemList, DateTimeSpan invoicePeriod, SupportConceptApprovalPeriod scap,
|
||||
Calculations calc, bool summaryPerMonth, bool addRateFactorToUnitCount)
|
||||
{
|
||||
return base.CreateSummaryInvoiceItems(itemList, invoicePeriod, scap, calc, true, true);
|
||||
}
|
||||
|
||||
public override void SetRecipientInformation(ServiceInvoice serviceInvoice, CostBearer costBearer)
|
||||
{
|
||||
serviceInvoice.InvoiceBase.RecipientDivision = costBearer.Organisation.Name2;
|
||||
serviceInvoice.InvoiceBase.RecipientOrganisationOid = costBearer.Organisation.Oid;
|
||||
serviceInvoice.InvoiceBase.RecipientOrganisation = costBearer.Organisation.Name;
|
||||
serviceInvoice.InvoiceBase.RecipientContacts = costBearer.Organisation.Contacts.Select(i => i.CopyToNew()).ToList();
|
||||
serviceInvoice.InvoiceBase.RecipientCostBearerOid = costBearer.Oid;
|
||||
|
||||
if (serviceInvoice.InvoiceBase.CostBearer2SupportConcept != null)
|
||||
{
|
||||
var cust = serviceInvoice.InvoiceBase.CostBearer2SupportConcept.SupportConcept.Customer;
|
||||
|
||||
if (cust.Person.InvoiceAddress != null)
|
||||
{
|
||||
serviceInvoice.InvoiceBase.RecipientAddress = cust.Person.InvoiceAddress.CopyToNew();
|
||||
}
|
||||
else if (cust.Person.Address != null)
|
||||
{
|
||||
serviceInvoice.InvoiceBase.RecipientAddress = cust.Person.Address.CopyToNew();
|
||||
}
|
||||
|
||||
if (cust.Person.InvoiceAddress != null && cust.Person.InvoiceAddress.AddressLine1 != null)
|
||||
{
|
||||
serviceInvoice.InvoiceBase.RecipientPersonFirstName = cust.Person.InvoiceAddress.AddressLine1;
|
||||
serviceInvoice.InvoiceBase.RecipientPersonLastName = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
serviceInvoice.InvoiceBase.RecipientPersonFirstName = cust.Person.FirstName;
|
||||
serviceInvoice.InvoiceBase.RecipientPersonLastName = cust.Person.LastName;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (costBearer.Organisation.InvoiceAddress != null)
|
||||
{
|
||||
serviceInvoice.InvoiceBase.RecipientAddress = costBearer.Organisation.InvoiceAddress.CopyToNew();
|
||||
}
|
||||
else if (costBearer.Organisation.Address != null)
|
||||
{
|
||||
serviceInvoice.InvoiceBase.RecipientAddress = costBearer.Organisation.Address.CopyToNew();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
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 PflegedienstWessel.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.Contains("Fachleistung"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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.Contains("Fachleistung"))
|
||||
{
|
||||
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("Fachleistung")).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,6 +69,10 @@
|
||||
<Compile Include="Fahrtkosten.Designer.cs">
|
||||
<DependentUpon>Fahrtkosten.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Invoicing\CustomInvoiceCreation.cs" />
|
||||
<Compile Include="Invoicing\CustomPersBudget24InvoiceCreation.cs" />
|
||||
<Compile Include="Invoicing\CustomInvoiceFactory.cs" />
|
||||
<Compile Include="Invoicing\SettlementInvoiceCreation.cs" />
|
||||
<Compile Include="KilometerauswertungsListReport.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
|
||||
Reference in New Issue
Block a user