120 lines
4.0 KiB
C#
120 lines
4.0 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using BeWo.Data.Access;
|
|||
|
|
using BeWo.Data.Entities;
|
|||
|
|
using BeWo.Service.DCEntityMapper;
|
|||
|
|
using BeWo.Service.ServiceImplementations;
|
|||
|
|
using BS.Shared.DataContracts;
|
|||
|
|
using BS.Shared.Extensions;
|
|||
|
|
using BS.Shared;
|
|||
|
|
using BeWo.Service.Invoicing;
|
|||
|
|
using BeWo.Data;
|
|||
|
|
using BeWo.Service.Plugins;
|
|||
|
|
using BS.Shared.Core;
|
|||
|
|
using BS.Shared.DataContracts.Compact;
|
|||
|
|
using BS.Shared.Services;
|
|||
|
|
using BeWo.Report.ReportObjects;
|
|||
|
|
|
|||
|
|
namespace BeWoDarmstadt
|
|||
|
|
{
|
|||
|
|
public class CustomFinanceRO : FinanceRO
|
|||
|
|
{
|
|||
|
|
public static FinanceRO Create(DateTime? start, DateTime? end, bool splitByServiceCategory, bool onlyNotApproved)
|
|||
|
|
{
|
|||
|
|
Dictionary<string, MonatsZeile> monat2Zeile = new Dictionary<string, MonatsZeile>();
|
|||
|
|
|
|||
|
|
DateTime monat = new DateTime(this.BewilligtStart.Year, this.BewilligtStart.Month, this.BewilligtStart.Day);
|
|||
|
|
|
|||
|
|
while (monat <= this.BewilligtEnde)
|
|||
|
|
{
|
|||
|
|
String key = String.Format("{0:MM.yyyy}", monat);
|
|||
|
|
|
|||
|
|
var zeile = new BudgetnachweisMonatsZeile();
|
|||
|
|
zeile.ServiceRecords = new List<ServiceRecordDC>();
|
|||
|
|
zeile.Monat = monat;
|
|||
|
|
zeile.SummeMinuten = 0;
|
|||
|
|
zeile.SummeFehlkontakte = 0;
|
|||
|
|
|
|||
|
|
foreach (var e in this.Entgeltzeitraeume)
|
|||
|
|
{
|
|||
|
|
if (e.Start <= monat && monat <= e.Ende)
|
|||
|
|
{
|
|||
|
|
zeile.Entgeltzeitraum = e.Index;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (monat.Day != 1)
|
|||
|
|
monat = new DateTime(monat.Year, monat.Month, 1);
|
|||
|
|
monat = monat.AddMonths(1);
|
|||
|
|
|
|||
|
|
monat2Zeile.Add(key, zeile);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var groupBookingDict = new Dictionary<long, bool>();
|
|||
|
|
foreach (var sr in serviceRecords)
|
|||
|
|
{
|
|||
|
|
if (sr.ServiceDescription.ServiceCategory.IsBillable && (!sr.GroupOid.HasValue || !groupBookingDict.ContainsKey(sr.GroupOid.Value)))
|
|||
|
|
{
|
|||
|
|
if (sr.GroupOid.HasValue)
|
|||
|
|
{
|
|||
|
|
groupBookingDict.Add(sr.GroupOid.Value, true);
|
|||
|
|
}
|
|||
|
|
var srDc = MapperFactory.ServiceRecordDC_ServiceRecord.MapToNewDC(sr);
|
|||
|
|
String key = String.Format("{0:MM.yyyy}", sr.Start);
|
|||
|
|
|
|||
|
|
if (monat2Zeile.ContainsKey(key))
|
|||
|
|
{
|
|||
|
|
if (monat2Zeile[key].Monat <= sr.Start.Value.Date)
|
|||
|
|
{
|
|||
|
|
monat2Zeile[key].ServiceRecords.Add(srDc);
|
|||
|
|
|
|||
|
|
decimal minuten = sr.RoundedDuration;
|
|||
|
|
decimal prozent = sr.ServiceDescription.ServiceCategory.ProzentAbrechnung;
|
|||
|
|
|
|||
|
|
if (sr.ServiceDescription.ProzentAbrechnung.HasValue)
|
|||
|
|
{
|
|||
|
|
prozent = sr.ServiceDescription.ProzentAbrechnung.Value;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
minuten *= (prozent / 100);
|
|||
|
|
if (sr.ServiceDescription.Name.ToLower().Contains("fehlkontakt"))
|
|||
|
|
{
|
|||
|
|
monat2Zeile[key].SummeFehlkontakte += Math.Round(minuten / 60, 2, MidpointRounding.AwayFromZero);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
monat2Zeile[key].SummeMinuten += minuten;
|
|||
|
|
|
|||
|
|
|
|||
|
|
foreach (var e in this.Entgeltzeitraeume)
|
|||
|
|
{
|
|||
|
|
if (e.Start <= sr.Start.Value.Date && sr.Start.Value.Date <= e.Ende)
|
|||
|
|
{
|
|||
|
|
e.ServiceRecords.Add(srDc);
|
|||
|
|
if (sr.ServiceDescription.Name.ToLower().Contains("fehlkontakt"))
|
|||
|
|
{
|
|||
|
|
e.SummeFehlkontakte += Math.Round(minuten / 60, 2, MidpointRounding.AwayFromZero);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
e.SummeFLMinuten += minuten;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
this.MonatsZeilen.AddRange(monat2Zeile.Values.OrderBy(m => m.Monat));
|
|||
|
|
|
|||
|
|
public class MonatsZeile
|
|||
|
|
{
|
|||
|
|
public List<ServiceRecordDC> ServiceRecords { get; set; }
|
|||
|
|
public DateTime Monat { get; set; }
|
|||
|
|
public decimal? SummeMinuten { get; set; }
|
|||
|
|
public decimal? SummeFehlkontakte { get; set; }
|
|||
|
|
public int Entgeltzeitraum { get; set; }
|
|||
|
|
public decimal? Betrag { get; set; }
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|