83 lines
2.3 KiB
C#
83 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Service.DCEntityMapper;
|
|
using BeWo.Service.Invoicing;
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Extensions;
|
|
using BS.Shared.Services;
|
|
|
|
namespace BeWo.SprungbrettTheresia
|
|
{
|
|
|
|
public class CustomSettlementInvoiceCreation : LWLSettlementInvoiceCreation
|
|
{
|
|
public override List<InvoiceItemDC> CreateInvoiceItems(Settlement2DC si, IList<ApprovalPeriod> apList, bool schneideBeiMaxAb)
|
|
{
|
|
|
|
List<InvoiceItemDC> iiList = new List<InvoiceItemDC>();
|
|
var apsByHourlyRate = new Dictionary<String, IList<ApprovalPeriod>>();
|
|
apList = apList.Where(a => String.IsNullOrEmpty(a.Notice) || (!String.IsNullOrEmpty(a.Notice) && a.Notice != "Fehlkontakte")).ToList();
|
|
foreach (var ap in apList)
|
|
{
|
|
IList<ApprovalPeriod> list = null;
|
|
String key = String.Format("{0}_{1}_{2:ddMMyyy}", ap.AmountPerUnit, ap.RateFactor, ap.PeriodStartDate);
|
|
|
|
if (apsByHourlyRate.ContainsKey(key))
|
|
{
|
|
list = apsByHourlyRate[key];
|
|
}
|
|
else
|
|
{
|
|
list = new List<ApprovalPeriod>();
|
|
apsByHourlyRate[key] = list;
|
|
}
|
|
|
|
list.Add(ap);
|
|
}
|
|
|
|
decimal maxApprovedFls = si.ApprovedFLS ?? 0;
|
|
foreach (var key in apsByHourlyRate.Keys)
|
|
{
|
|
IList<ApprovalPeriod> list = apsByHourlyRate[key];
|
|
var ii = new InvoiceItemDC();
|
|
|
|
DateTime start = DateTime.MaxValue;
|
|
DateTime end = DateTime.MinValue;
|
|
|
|
decimal rf = si.RateFactor ?? 0;
|
|
|
|
foreach (var approvalPeriod in list)
|
|
{
|
|
ii.UnitCount = approvalPeriod.ApprovedTotal;
|
|
ii.UnitCountBudget = ii.UnitCount;
|
|
ii.AmountPerUnit = approvalPeriod.AmountPerUnit;
|
|
ii.AmountTotal = approvalPeriod.ApprovedAmountTotal;
|
|
|
|
if (approvalPeriod.PeriodStartDate < start)
|
|
start = approvalPeriod.PeriodStartDate;
|
|
if (approvalPeriod.PeriodEndDate > end)
|
|
end = approvalPeriod.PeriodEndDate;
|
|
if (approvalPeriod.RateFactor.HasValue)
|
|
{
|
|
rf = approvalPeriod.RateFactor.Value;
|
|
}
|
|
}
|
|
ii.ItemPeriodStart = start;
|
|
ii.ItemPeriodEnd = end;
|
|
ii.RateFactor = rf;
|
|
//ii.AmountTotal = Math.Round(hr * hours, 2, MidpointRounding.AwayFromZero);
|
|
ii.GrossAmountTotal = ii.AmountTotal;
|
|
|
|
iiList.Add(ii);
|
|
}
|
|
|
|
return iiList.OrderBy(ii => ii.ItemPeriodStart).ToList();
|
|
}
|
|
}
|
|
}
|