Files
BeWoPlaner/ReportImp/FeidPartnerReports/Invoicing/CollectiveInvoiceCreationOld.cs

143 lines
5.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
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;
using FeidPartnerReports.Calculation;
namespace FeidPartnerReports.Invoicing
{
public class CollectiveInvoiceCreationOld : InvoiceCreation
{
private DateTime? accountingPeriodStart = null;
private DateTime? accountingPeriodEnd = null;
public override List<ServiceInvoiceDC> GenerateServiceInvoices(long costBearerOid, DateTimeSpan invoicePeriod, Dictionary<CompactSupportConceptDC, List<ServiceRecordDC>> supportConcepts2ServiceRecords)
{
var newSc2SrList = new Dictionary<CompactSupportConceptDC, List<ServiceRecordDC>>();
foreach (var key in supportConcepts2ServiceRecords.Keys)
{
if (key.IsApproved)
{
newSc2SrList.Add(key, supportConcepts2ServiceRecords[key]);
}
}
return base.GenerateServiceInvoices(costBearerOid, invoicePeriod, newSc2SrList);
}
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)
{
CreateFixedAmounts(serviceInvoicePeriod, supportConceptApprovalPeriod, cb2sc);
}
public override void CreateFixedAmounts(ServiceInvoicePeriod serviceInvoicePeriod, SupportConceptApprovalPeriodDC scap, CostBearer2SupportConcept cb2sc)
{
var calc = new CustomCalculations();
var c2s = MapperFactory.SupportConceptCostBearerRelDC_CostBearer2SupportConcept.MapToNewDC(cb2sc);
DateTime start = accountingPeriodStart.Value;
DateTime end = accountingPeriodEnd.Value;
if (scap.StartDate > start)
{
start = scap.StartDate.Value;
}
if (scap.EndDate < end)
{
end = scap.EndDate.Value;
}
var monate = DateTimeUtils.GetTotalMonths(start, end);
var stundenProMonat = calc.GetApprovedHoursForPeriod(c2s, scap, null, new DateTime(start.Year, start.Month, 1), new DateTime(start.Year, start.Month, 1).AddMonths(1).AddDays(-1), false) ?? 0;
var hours = monate.GanzeMonate * stundenProMonat;
if (monate.RestTageAnfang > 0)
{
if (start.Day > 15)
{
hours += stundenProMonat / 2;
}
else if (start.Day > 1)
{
hours += stundenProMonat;
}
}
if (monate.RestTageEnde > 0)
{
if (end.Day > 15)
{
hours += stundenProMonat;
}
else
{
hours += stundenProMonat / 2;
}
}
//var hours = calc.GetApprovedHoursForPeriod(c2s, scap, null, accountingPeriodStart, accountingPeriodEnd, false) ?? 0;
hours = Math.Round(hours, 2, MidpointRounding.AwayFromZero);
decimal hourlyRate = 0;
if (accountingPeriodStart.HasValue)
{
var crp = c2s.CostBearer.CostRatePeriods.GetCostRatePeriodForDate(CostRatePeriodType.HourlyRate,
accountingPeriodStart.Value);
if (crp != null && crp.CostRateValue.HasValue)
{
hourlyRate = crp.CostRateValue.Value;
}
}
var ii = new InvoiceItem
{
ItemPeriodStart = accountingPeriodStart,
ItemPeriodEnd = accountingPeriodEnd,
AccountingInterval = AccountingIntervalType.Monthly,
AmountPerUnit = hourlyRate,
UnitCount = hours
};
ii.AmountTotal = ii.UnitCount * ii.AmountPerUnit;
ii.GrossAmountTotal = ii.AmountTotal;
serviceInvoicePeriod.InvoiceItemList.Add(ii);
}
public override IList<InvoiceItem> CreateInvoiceItems(List<ServiceRecordDC> serviceRecordsInPeriod, DateTimeSpan invoicePeriod, SupportConceptApprovalPeriod scap,
Calculations calc)
{
return base.CreateInvoiceItems(serviceRecordsInPeriod, invoicePeriod, scap, calc);
}
}
}