Files
BeWoPlaner/ReportImp/AwoIntegrationsGGmbH/Service/CustomAccountingService.cs

76 lines
2.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Windows;
using BeWo.Data;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Service.DCEntityMapper;
using BeWo.Service.Invoicing;
using BeWo.Service.Plugins;
using BS.Shared;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
namespace AwoIntegrationsGGmbH.Service
{
public class CustomAccountingService : AccountingService
{
// entspricht dem Original, außer dass die Bewilligung des Hilfeplans abgelaufen sein kann
public override List<ServiceInvoiceDC> GenerateInitialServiceInvoices(long costBearerOid, long? supportConceptOid, DateTimeSpan invoicePeriod)
{
var cs = PluginLoader.FindClass<CustomerService>();
IEnumerable<CompactSupportConceptDC> supportConcepts;
// GetAllActiveSupportConceptCostbearer returns a "Flat" SupportConcept List, one for each CostBearer2SupportConcept!
if (!supportConceptOid.HasValue)
{
supportConcepts = cs.GetAllActiveSupportConceptCostbearer(false, true, 0)
.Where(i => i.CostBearerOids2CostBearerRelOids.ContainsKey(costBearerOid));
}
else
{
supportConcepts = cs.GetCompactSupportConcepts(supportConceptOid.Value, null)
.Where(i => i.CostBearerOids2CostBearerRelOids.ContainsKey(costBearerOid));
}
DateTimeSpan newSpan = null;
if (invoicePeriod != null)
{
//invoicePeriod.StartDateTime = invoicePeriod.StartDateTime.Date;
//invoicePeriod.EndDateTime = invoicePeriod.EndDateTime.Date;
newSpan = new DateTimeSpan();
newSpan.StartDateTime = invoicePeriod.StartDateTime.Date;
newSpan.EndDateTime = invoicePeriod.EndDateTime.Date.AddDays(1).AddTicks(-1);
//if (!supportConceptOid.HasValue)
//{
// supportConcepts =
// supportConcepts.Where(sc => sc.StartDate < newSpan.EndDateTime && sc.EndDate >= newSpan.StartDate);
//}
}
var supportConcepts2ServiceRecords = supportConcepts.ToDictionary(
i => i,
i => MapperFactory.ServiceRecordDC_ServiceRecord.MapToNewDCs(
DAOFactory.SearchDAO.FindServiceRecordsInSpan(i.CostBearerRelOids[0], newSpan)));
var cb = DAOFactory.GenericDAO.LoadByID<CostBearer>(costBearerOid);
String tenant = PluginLoader.Tenant;
var factory = PluginLoader.FindClass<InvoiceFactory>(cb.ID);
if (factory == null)
{
factory = InvoiceFactory.GetInstance(cb.ID, tenant);
}
var creator = factory.CreateInvoiceCreator(cb.ID, tenant, supportConcepts2ServiceRecords);
var newInvoices = creator.GenerateServiceInvoices(costBearerOid, invoicePeriod, supportConcepts2ServiceRecords);
//Prüfe ob Rechnungen neu sind oder Diff vorhanden
var differenzRechnungChecks = GetNewInvoices(newInvoices, invoicePeriod?.StartDate, invoicePeriod?.EndDate);
var resultList = ErstelleNeueRechnungen(differenzRechnungChecks);
return resultList;
}
}
}