Files
BeWoPlaner/Service/Plugins/ServiceRecordDurationCalculator.cs

54 lines
2.1 KiB
C#
Raw Normal View History

2017-05-18 21:48:37 +02:00
using System;
using System.Collections.Generic;
using BeWo.Data.Entities;
using BeWo.Service.DCEntityMapper;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.Services;
namespace BeWo.Service.Plugins
{
public class ServiceRecordDurationCalculator : AbstractIDSpecificDefaultClass<ServiceRecordDurationCalculator>
{
public virtual void CalculateRoundedDuration(ServiceRecord sr)
{
//Wird vor dem eigentlichen Speichern aufgerufen
if (sr.CostBearer2SupportConcept != null && sr.ServiceDescription.ServiceCategory != null &&
sr.ServiceDescription.ServiceCategory.IsBillable)
{
var duration = (decimal)sr.End.Value.Subtract(sr.Start.Value).TotalMinutes;
Calculations calc = Calculations.GetInstance(sr.CostBearer2SupportConcept.CostBearer.ID);
var cc =
MapperFactory.CompactOrganisationDC_Organisation.MapToNewDC(
sr.CostBearer2SupportConcept.CostBearer.Organisation);
2023-11-24 02:46:50 +01:00
var roundedDuration = calc.GetRoundedDuration(cc, sr.Start.Value, duration);
2017-05-18 21:48:37 +02:00
sr.RoundedDuration = roundedDuration;
}
2017-09-14 19:03:26 +02:00
else
{
sr.RoundedDuration = (decimal)sr.End.Value.Subtract(sr.Start.Value).TotalMinutes;
}
2017-05-18 21:48:37 +02:00
}
2018-10-08 11:57:16 +02:00
public virtual void CalculateRoundedDuration(ServiceRecordDC newServiceRecord)
2017-05-18 21:48:37 +02:00
{
//Wird nur für die Validierung benötigt
if (newServiceRecord.ServiceDescription.Category != null &&
newServiceRecord.ServiceDescription.Category.IsBillable && newServiceRecord.CostBearer != null)
{
var duration = (decimal)newServiceRecord.End.Value.Subtract(newServiceRecord.Start.Value).TotalMinutes;
Calculations calc = Calculations.GetInstance(newServiceRecord.CostBearer.CostBearerID);
2023-11-24 02:46:50 +01:00
var roundedDuration = calc.GetRoundedDuration(newServiceRecord.CostBearer, newServiceRecord.Start.Value, duration);
2017-05-18 21:48:37 +02:00
newServiceRecord.RoundedDuration = roundedDuration;
}
}
}
}