153 lines
6.0 KiB
C#
153 lines
6.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Service.DCEntityMapper;
|
|
using BeWo.Service.Plugins;
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Extensions;
|
|
using BS.Shared.Services;
|
|
using DevExpress.XtraCharts;
|
|
|
|
namespace SHKService.Calculation
|
|
{
|
|
public class CustomCalculations : BS.Shared.Services.Calculations
|
|
{
|
|
|
|
public override BillingData GetBillingData(ServiceRecordDC record)
|
|
{
|
|
BillingData data = new BillingData();
|
|
data.BillingPeriodStart = record.Start;
|
|
data.BillingPeriodEnd = record.End;
|
|
|
|
CostRatePeriodDC hourlyRate = null;
|
|
CostRatePeriodDC flatRate = null;
|
|
|
|
bool useRatefactor = true;
|
|
if (record.ServiceDescription.Category.IsBillable)
|
|
{
|
|
var crpList = record.ServiceDescription.CostRatePeriods;
|
|
var ai = record.ServiceDescription.AccountingInterval;
|
|
|
|
if (crpList.Count(c => c.CostRateValue.HasValue) == 0)
|
|
{
|
|
crpList = record.ServiceDescription.Category.CostRatePeriods;
|
|
ai = record.ServiceDescription.Category.AccountingInterval;
|
|
}
|
|
if (ai == null)
|
|
{
|
|
ai = AccountingIntervalType.Hourly;
|
|
}
|
|
if (crpList.Count(c => c.CostRateValue.HasValue) > 0)
|
|
{
|
|
CostRatePeriodDC crp = crpList.GetCostRatePeriodForDate(CostRatePeriodType.AmountOfMoney,
|
|
record.Start.Value);
|
|
|
|
if (ai.HasValue)
|
|
{
|
|
if (ai.Value == AccountingIntervalType.Hourly)
|
|
hourlyRate = crp;
|
|
else if (ai.Value == AccountingIntervalType.FlatRate)
|
|
flatRate = crp;
|
|
else if (ai.Value == AccountingIntervalType.Daily)
|
|
{
|
|
double days = 0;
|
|
|
|
if (data.BillingPeriodStart.HasValue && data.BillingPeriodEnd.HasValue)
|
|
{
|
|
days = data.BillingPeriodEnd.Value.Subtract(data.BillingPeriodStart.Value).Days + 1;
|
|
}
|
|
data.UnitCount = (decimal)days;
|
|
data.AmountPerUnit = crp.CostRateValue ?? 0;
|
|
data.AmountTotal = data.UnitCount * data.AmountPerUnit;
|
|
data.AccountingInterval = AccountingIntervalType.Daily;
|
|
data.GrossAmountTotal = data.AmountTotal;
|
|
|
|
return data;
|
|
}
|
|
else if (ai.Value == AccountingIntervalType.Monthly)
|
|
{
|
|
|
|
|
|
AnzahlMonate am = null;
|
|
data.UnitCount = 1;
|
|
if (data.BillingPeriodStart.HasValue && data.BillingPeriodEnd.HasValue)
|
|
{
|
|
am = DateTimeUtils.GetTotalMonths(data.BillingPeriodStart.Value, data.BillingPeriodEnd.Value);
|
|
decimal monate = Math.Ceiling(am.AnzahlMonateGesamt);
|
|
if (monate > data.UnitCount)
|
|
{
|
|
data.UnitCount = monate;
|
|
}
|
|
}
|
|
|
|
|
|
data.AmountPerUnit = crp.CostRateValue ?? 0;
|
|
data.AmountTotal = data.UnitCount * data.AmountPerUnit;
|
|
data.AccountingInterval = AccountingIntervalType.Monthly;
|
|
data.GrossAmountTotal = data.AmountTotal;
|
|
|
|
return data;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (hourlyRate != null || flatRate != null)
|
|
useRatefactor = false;
|
|
|
|
if (flatRate != null)
|
|
{
|
|
if (record.DistanceInMeterDecimal.HasValue && record.DistanceInMeterDecimal.Value > 0)
|
|
{
|
|
data.UnitCount = record.DistanceInMeterDecimal.Value;
|
|
}
|
|
else
|
|
{
|
|
data.UnitCount = 1;
|
|
}
|
|
data.AmountPerUnit = flatRate.CostRateValue;
|
|
data.AmountTotal = data.UnitCount * data.AmountPerUnit;
|
|
data.AccountingInterval = AccountingIntervalType.FlatRate;
|
|
}
|
|
else
|
|
{
|
|
if (hourlyRate == null)
|
|
hourlyRate = this.GetHourlyRatePeriodForServiceRecord(record);
|
|
|
|
decimal rdMinutes = this.GetBillableDurationInMinutes(record, true);
|
|
data.UnitCount = rdMinutes / 60m;
|
|
|
|
|
|
if (hourlyRate != null)
|
|
data.AmountPerUnit = hourlyRate.CostRateValue;
|
|
|
|
data.AmountTotal = data.AmountPerUnit * data.UnitCount;
|
|
data.AccountingInterval = AccountingIntervalType.Hourly;
|
|
|
|
}
|
|
|
|
if (useRatefactor)
|
|
{
|
|
var rateFactor =
|
|
record.CostBearer.CostRatePeriods.GetCostRatePeriodForDate(CostRatePeriodType.RateFactor,
|
|
record.Start.Value);
|
|
if (rateFactor != null && rateFactor.CostRateValue.HasValue)
|
|
{
|
|
data.RateFactor = rateFactor.CostRateValue;
|
|
data.GrossAmountTotal = data.AmountTotal + (data.AmountTotal * rateFactor.CostRateValue / 100);
|
|
}
|
|
}
|
|
if (!data.GrossAmountTotal.HasValue)
|
|
data.GrossAmountTotal = data.AmountTotal;
|
|
|
|
|
|
return data;
|
|
}
|
|
}
|
|
}
|