DomizielAnsbach Sammelrechnung
This commit is contained in:
175
ReportImp/DomizielAnsbach/Invoicing/StationaerInvoiceCreation.cs
Normal file
175
ReportImp/DomizielAnsbach/Invoicing/StationaerInvoiceCreation.cs
Normal file
@@ -0,0 +1,175 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BeWo.Data.Access;
|
||||
using BeWo.Data.Entities;
|
||||
using BeWo.Service.DCEntityMapper;
|
||||
using BeWo.Service.Invoicing;
|
||||
using BS.Shared.Core;
|
||||
using BS.Shared.DataContracts;
|
||||
using BS.Shared.DataContracts.Compact;
|
||||
using BS.Shared.Extensions;
|
||||
using BS.Shared.Services;
|
||||
|
||||
|
||||
namespace DomizielAnsbach.Invoicing
|
||||
{
|
||||
public class StationaerInvoiceCreation : InvoiceCreation
|
||||
{
|
||||
private const decimal TAGESPAUSCHALE = 129.55m;
|
||||
private const decimal FREIHALTEGEBUEHR = 103.64m;
|
||||
|
||||
private DateTime? accountingPeriodStart = null;
|
||||
private DateTime? accountingPeriodEnd = null;
|
||||
|
||||
public override void SetInvoiceId(ServiceInvoice invoice)
|
||||
{
|
||||
invoice.InvoiceBase.InvoiceId = "RgBezirkDetail";
|
||||
invoice.InvoiceBase.InvoiceTypeText = "Sammelrechnung Bezirk";
|
||||
}
|
||||
|
||||
public override List<ServiceInvoiceDC> GenerateServiceInvoices(long costBearerOid,
|
||||
DateTimeSpan invoicePeriod,
|
||||
Dictionary<CompactSupportConceptDC, List<ServiceRecordDC>> supportConcepts2ServiceRecords)
|
||||
{
|
||||
var costBearer = DAOFactory.GenericDAO.LoadByID<CostBearer>(costBearerOid);
|
||||
var invoiceList = new List<ServiceInvoice>();
|
||||
ServiceInvoice invoice;
|
||||
|
||||
invoice = CreateCollectiveBilling2(costBearer, invoicePeriod, supportConcepts2ServiceRecords);
|
||||
if (invoice != null)
|
||||
invoiceList.Add(invoice);
|
||||
|
||||
var result = invoiceList.Select(item => MapperFactory.ServiceInvoiceDC_ServiceInvoice.MapToNewDC(item)).ToList();
|
||||
return result.Count > 1 ? result.OrderBy(i => i.InvoiceBase.CustomerLastName).ToList() : result;
|
||||
}
|
||||
|
||||
private ServiceInvoice CreateCollectiveBilling2(CostBearer costBearer, DateTimeSpan invoicePeriod, Dictionary<CompactSupportConceptDC, List<ServiceRecordDC>> supportConcepts2ServiceRecords)
|
||||
{
|
||||
var invoice = new ServiceInvoice();
|
||||
var newDict = new Dictionary<CompactSupportConceptDC, List<ServiceRecordDC>>();
|
||||
|
||||
foreach (var sc2sr in supportConcepts2ServiceRecords)
|
||||
{
|
||||
if (sc2sr.Key.IsApproved)
|
||||
newDict.Add(sc2sr.Key, sc2sr.Value);
|
||||
}
|
||||
|
||||
SetRecipientInformation(invoice, costBearer);
|
||||
SetSenderInformation(invoice);
|
||||
SetInvoiceBaseData(0, invoice, costBearer, invoicePeriod, newDict.Keys.ToList());
|
||||
SetCollectiveBillingBaseData(0, invoice, costBearer, invoicePeriod, newDict);
|
||||
SetCollectiveBillingServiceInvoicePeriods(invoice, invoicePeriod, newDict);
|
||||
SetServiceInvoicePeriodAmounts(invoice);
|
||||
|
||||
SetAmountAdvancePayments(invoice);
|
||||
|
||||
return invoice;
|
||||
}
|
||||
|
||||
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 SetInvoiceItems(ServiceInvoice invoice,
|
||||
ServiceInvoicePeriod serviceInvoicePeriod,
|
||||
SupportConceptApprovalPeriodDC supportConceptApprovalPeriod,
|
||||
CostBearer2SupportConcept cb2sc,
|
||||
DateTimeSpan invoicePeriod,
|
||||
List<ServiceRecordDC> serviceRecords)
|
||||
{
|
||||
var itemList = CreateInvoiceItems(null, invoicePeriod, serviceInvoicePeriod.SupportConceptApprovalPeriod, null);
|
||||
serviceInvoicePeriod.InvoiceItemList.AddRange(itemList);
|
||||
}
|
||||
|
||||
public override IList<InvoiceItem> CreateInvoiceItems(List<ServiceRecordDC> serviceRecordsInPeriod, DateTimeSpan invoicePeriod, SupportConceptApprovalPeriod scap,
|
||||
Calculations calc)
|
||||
{
|
||||
IList<InvoiceItem> ergebnis = new List<InvoiceItem>();
|
||||
var customer = scap.CostBearer2SupportConcept.SupportConcept.Customer;
|
||||
DateTime start;
|
||||
DateTime ende;
|
||||
if (scap.StartDate <= invoicePeriod.StartDate)
|
||||
start = invoicePeriod.StartDate;
|
||||
else
|
||||
start = (DateTime)scap.StartDate;
|
||||
if (scap.EndDate >= invoicePeriod.EndDate)
|
||||
ende = invoicePeriod.EndDate;
|
||||
else
|
||||
ende = (DateTime)scap.EndDate;
|
||||
var monate = DateTimeUtils.GetTotalMonths(start, ende);
|
||||
|
||||
while (start <= ende)
|
||||
{
|
||||
var tage = invoicePeriod.EndDate.Subtract(invoicePeriod.StartDate).Days + 1;
|
||||
DateTime monatStart = new DateTime(start.Year, start.Month, 1);
|
||||
DateTime monatEnde = monatStart.AddMonths(1);
|
||||
var tageMonat = monatEnde.Subtract(monatStart).Days;
|
||||
int tageAbwesendImMonat = 0;
|
||||
decimal? sumCustomerMonth = 0;
|
||||
foreach (var at in customer.AbsenceTimes)
|
||||
{
|
||||
if (at.Start.HasValue && at.Start.Value < monatEnde &&
|
||||
(!at.End.HasValue || at.End.Value >= monatStart))
|
||||
{
|
||||
DateTime dt = at.Start.Value;
|
||||
DateTime dtEnde = monatEnde.AddMonths(1); // nächstenMonat mit berücksichtigen um Abwesenheiten zu prüfen, die in den nächsten Monat mit hineingehen
|
||||
|
||||
if (at.End.HasValue && at.End.Value < monatEnde)
|
||||
{
|
||||
while (dt <= at.End.Value)
|
||||
{
|
||||
tageAbwesendImMonat++;
|
||||
dt = dt.AddDays(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var ii = new InvoiceItem();
|
||||
ii.UnitCount = tageMonat - tageAbwesendImMonat;
|
||||
ii.AmountPerUnit = TAGESPAUSCHALE;
|
||||
ii.AmountTotal = ii.UnitCount * ii.AmountPerUnit;
|
||||
ii.GrossAmountTotal = ii.AmountTotal;
|
||||
sumCustomerMonth += ii.AmountTotal;
|
||||
ii.MaxApprovedAmount = null;
|
||||
ii.ItemDescription = "Klientenname";
|
||||
ii.UnitDescription = "Vergütung";
|
||||
ii.ItemPeriodStart = monatStart;
|
||||
ii.Notice = monatStart.ToString("MMMM");
|
||||
ii.SupportConceptApprovalPeriodOid = scap.Oid;
|
||||
|
||||
ergebnis.Add(ii);
|
||||
|
||||
|
||||
ii = new InvoiceItem();
|
||||
ii.UnitCount = tageAbwesendImMonat;
|
||||
ii.AmountPerUnit = FREIHALTEGEBUEHR;
|
||||
ii.AmountTotal = ii.UnitCount * ii.AmountPerUnit;
|
||||
ii.GrossAmountTotal = ii.AmountTotal;
|
||||
sumCustomerMonth += ii.AmountTotal;
|
||||
ii.MaxApprovedAmount = sumCustomerMonth;
|
||||
ii.ItemDescription = "Klientenname";
|
||||
ii.UnitDescription = "Platzfreihaltegeb.";
|
||||
ii.ItemPeriodStart = monatStart;
|
||||
ii.Notice = monatStart.ToString("MMMM");
|
||||
ii.SupportConceptApprovalPeriodOid = scap.Oid;
|
||||
|
||||
ergebnis.Add(ii);
|
||||
|
||||
start = start.AddMonths(1);
|
||||
start = new DateTime(start.Year, start.Month, 1);
|
||||
}
|
||||
|
||||
return ergebnis;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user