157 lines
5.1 KiB
C#
157 lines
5.1 KiB
C#
using BeWo.Data.Entities;
|
|
using BeWo.Service.Invoicing;
|
|
using BS.Shared;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Services;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace LebenszentrumKoenigsborn.Invoicing
|
|
{
|
|
public class CustomSettlementInvoiceCreation : SettlementInvoiceCreation
|
|
{
|
|
public override bool CanCreateInvoiceTheOldWay(Settlement2DC si, CostBearer2SupportConcept c2s)
|
|
{
|
|
return false;
|
|
}
|
|
public override InvoiceItemDC CreateInvoiceItemForAccountingPeriod(AccountingPeriod accountingPeriod)
|
|
{
|
|
#region Standard
|
|
InvoiceItemDC ii = new InvoiceItemDC();
|
|
ii.AccountingInterval = accountingPeriod.AccountingInterval;
|
|
ii.ItemPeriodStart = accountingPeriod.PeriodStart;
|
|
ii.ItemPeriodEnd = accountingPeriod.PeriodEnd;
|
|
ii.RateFactor = accountingPeriod.RateFactor;
|
|
ii.AmountPerUnit = accountingPeriod.Amount;
|
|
ii.UnitDescription = accountingPeriod.UnitName;
|
|
ii.MaxApprovedAmount = accountingPeriod.MaxApprovedAmount;
|
|
ii.MaxApprovedUnitCount = accountingPeriod.MaxApprovedUnitCount;
|
|
ii.ApprovedPerUnit = accountingPeriod.ApprovedPerUnit;
|
|
ii.ApprovalUnit = accountingPeriod.ApprovalUnit;
|
|
ii.ProzentAbrechenbar = accountingPeriod.ProzentAbrechenbar;
|
|
|
|
if (accountingPeriod.ServiceCategory != null)
|
|
ii.ItemDescription = accountingPeriod.ServiceCategory.Name;
|
|
|
|
if (!String.IsNullOrEmpty(accountingPeriod.Notice))
|
|
{
|
|
ii.ItemDescription = accountingPeriod.Notice;
|
|
}
|
|
if (accountingPeriod.AccountingInterval == AccountingIntervalType.FlatRate)
|
|
{
|
|
ii.UnitCount = accountingPeriod.ServiceRecordsInPeriod.Count;
|
|
|
|
}
|
|
else if (accountingPeriod.AccountingInterval == AccountingIntervalType.Hourly)
|
|
{
|
|
decimal minutesTotal = 0;
|
|
decimal minutesTotalBudget = 0;
|
|
|
|
if (accountingPeriod.ServiceRecordsInPeriod != null)
|
|
{
|
|
#endregion
|
|
|
|
foreach (var ar in accountingPeriod.ServiceRecordsInPeriod)
|
|
{
|
|
// Standard: Zeit wird einfach aufaddiert, egal wie die Prozente sind
|
|
//minutesTotal += ar.RoundedDuration;
|
|
|
|
var prozent = ar.ServiceDescription.Category.Percentage;
|
|
if (ar.ServiceDescription.ProzentAbrechnung.HasValue)
|
|
{
|
|
prozent = ar.ServiceDescription.ProzentAbrechnung.Value;
|
|
}
|
|
ii.ProzentAbrechenbar = prozent;
|
|
// Anpassung: Prozente wirken sich darauf aus, wie viel der Zeit abrechenbar ist
|
|
minutesTotal += ar.RoundedDuration / 100 * prozent;
|
|
#region
|
|
prozent = ar.ServiceDescription.Category.ProzentBudget ?? 100;
|
|
if (ar.ServiceDescription.ProzentBudget.HasValue)
|
|
{
|
|
prozent = ar.ServiceDescription.ProzentBudget.Value;
|
|
}
|
|
minutesTotalBudget += (ar.RoundedDuration * prozent) / 100;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
ii.UnitCount = minutesTotal / 60;
|
|
ii.UnitCountBudget = minutesTotalBudget / 60;
|
|
|
|
if (String.IsNullOrEmpty(ii.UnitDescription))
|
|
ii.UnitDescription = ii.UnitCount.Value == 1 ? "Stunde" : "Stunden";
|
|
}
|
|
else if (accountingPeriod.PeriodStart > DateTime.MinValue && accountingPeriod.PeriodEnd < DateTime.MaxValue)
|
|
{
|
|
DateTime intervalStart = accountingPeriod.PeriodStart;
|
|
DateTime intervalEnd = intervalStart;
|
|
int count = 0;
|
|
while (intervalStart < accountingPeriod.PeriodEnd)
|
|
{
|
|
count++;
|
|
switch (accountingPeriod.AccountingInterval)
|
|
{
|
|
case AccountingIntervalType.Daily:
|
|
intervalEnd = intervalStart.AddDays(1);
|
|
break;
|
|
case AccountingIntervalType.Weekly:
|
|
intervalEnd = intervalStart.AddDays(7);
|
|
break;
|
|
case AccountingIntervalType.Fortnightly:
|
|
intervalEnd = intervalStart.AddDays(14);
|
|
break;
|
|
case AccountingIntervalType.Monthly:
|
|
intervalEnd = intervalStart.AddMonths(1);
|
|
break;
|
|
case AccountingIntervalType.Quarterly:
|
|
intervalEnd = intervalStart.AddMonths(3);
|
|
break;
|
|
case AccountingIntervalType.HalfYearly:
|
|
intervalEnd = intervalStart.AddMonths(6);
|
|
break;
|
|
case AccountingIntervalType.Yearly:
|
|
intervalEnd = intervalStart.AddYears(1);
|
|
break;
|
|
}
|
|
intervalStart = intervalEnd;
|
|
}
|
|
ii.UnitCount = count;
|
|
ii.UnitCountBudget = count;
|
|
|
|
switch (accountingPeriod.AccountingInterval)
|
|
{
|
|
case AccountingIntervalType.Daily:
|
|
ii.UnitDescription = count == 1 ? "Tag" : "Tage";
|
|
break;
|
|
case AccountingIntervalType.Weekly:
|
|
ii.UnitDescription = count == 1 ? "Woche" : "Wochen";
|
|
break;
|
|
case AccountingIntervalType.Fortnightly:
|
|
ii.UnitDescription = "2 Wochen";
|
|
break;
|
|
case AccountingIntervalType.Monthly:
|
|
ii.UnitDescription = count == 1 ? "Monat" : "Monate";
|
|
break;
|
|
case AccountingIntervalType.Quarterly:
|
|
ii.UnitDescription = count == 1 ? "Quartal" : "Quartale";
|
|
break;
|
|
case AccountingIntervalType.HalfYearly:
|
|
ii.UnitDescription = "Halbjährlich";
|
|
break;
|
|
case AccountingIntervalType.Yearly:
|
|
ii.UnitDescription = count == 1 ? "Jahr" : "Jahre";
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
return ii;
|
|
#endregion
|
|
}
|
|
}
|
|
}
|