2016-06-27 01:45:38 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.ServiceModel;
|
|
|
|
|
|
using BeWo.Data;
|
|
|
|
|
|
using BeWo.Service.Plugins;
|
|
|
|
|
|
using BS.Shared.DataContracts.Compact;
|
|
|
|
|
|
using BeWo.Data.Access;
|
|
|
|
|
|
using BeWo.Data.Entities;
|
|
|
|
|
|
using BeWo.Service.Core;
|
|
|
|
|
|
using BeWo.Service.DCEntityMapper;
|
|
|
|
|
|
using BeWo.Service.ServiceContracts;
|
|
|
|
|
|
|
|
|
|
|
|
using BS.Shared;
|
|
|
|
|
|
using BS.Shared.Core;
|
|
|
|
|
|
using BS.Shared.DataContracts;
|
|
|
|
|
|
|
|
|
|
|
|
using Utils = BeWo.Service.Core.Utils;
|
|
|
|
|
|
using BeWo.Service.Invoicing;
|
2024-04-17 16:33:19 +02:00
|
|
|
|
using Dakota.Logic;
|
2024-04-23 14:50:01 +02:00
|
|
|
|
using Dakota;
|
|
|
|
|
|
using Dakota.Models;
|
2024-05-06 13:14:35 +02:00
|
|
|
|
using System.Net;
|
|
|
|
|
|
using System.Collections.Specialized;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using BS.Shared.DataContracts.GkvAbrechnung;
|
|
|
|
|
|
using BS.Shared.Extensions;
|
2016-06-27 01:45:38 +02:00
|
|
|
|
|
|
|
|
|
|
namespace BeWo.Service.ServiceImplementations
|
|
|
|
|
|
{
|
|
|
|
|
|
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)]
|
|
|
|
|
|
public class AccountingServiceImp : IAccountingService
|
|
|
|
|
|
{
|
2024-05-06 13:14:35 +02:00
|
|
|
|
|
2016-06-27 01:45:38 +02:00
|
|
|
|
public void DeactivateInvoiceBases(List<InvoiceBaseDC> invoices)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2019-02-12 19:22:22 +01:00
|
|
|
|
var s = PluginLoader.FindClass<AccountingService>();
|
|
|
|
|
|
s.DeactivateInvoiceBases(invoices);
|
|
|
|
|
|
|
2024-05-06 13:14:35 +02:00
|
|
|
|
|
2016-06-27 01:45:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-05 19:21:17 +01:00
|
|
|
|
public void StorniereInvoiceBases(List<InvoiceBaseDC> invoices)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var s = PluginLoader.FindClass<AccountingService>();
|
|
|
|
|
|
s.StorniereInvoiceBases(invoices);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-27 01:45:38 +02:00
|
|
|
|
public void DeactivateServiceInvoices(List<ServiceInvoiceDC> invoices)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2019-02-12 19:22:22 +01:00
|
|
|
|
var s = PluginLoader.FindClass<AccountingService>();
|
|
|
|
|
|
s.DeactivateServiceInvoices(invoices);
|
2016-06-27 01:45:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void DeactivateSettlementInvoice(List<Settlement2DC> invoices)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
ServiceLogic.SetActivationType<SettlementInvoice>(invoices.ToDictionary(i => i.SettlementIvoiceOid.Value, i => i.SettlementInvoiceVersion.Value), ActivationTypeId.Deleted);
|
|
|
|
|
|
ServiceLogic.SetActivationType<InvoiceBase>(invoices.ToDictionary(i => i.InvoiceBaseOid.Value, i => i.InvoiceBaseVersion.Value), ActivationTypeId.Deleted);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<ServiceInvoiceDC> GenerateInitialServiceInvoices(
|
|
|
|
|
|
long costBearerOid,
|
|
|
|
|
|
long? supportConceptOid,
|
|
|
|
|
|
DateTimeSpan invoicePeriod)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2023-12-13 12:53:20 +01:00
|
|
|
|
var acc = PluginLoader.FindClass<AccountingService>();
|
|
|
|
|
|
return acc.GenerateInitialServiceInvoices(costBearerOid, supportConceptOid, invoicePeriod);
|
2016-06-27 01:45:38 +02:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<InvoiceBaseDC> GetAllActiveInvoiceBases()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
return MapperFactory.InvoiceBaseDC_InvoiceBase.MapToNewDCs(DAOFactory.GenericDAO.GetAllActive<InvoiceBase>());
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-06 13:14:35 +02:00
|
|
|
|
public List<InvoiceBaseDC> GetInvoiceBases(DateTime? startDate, DateTime? endDate)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var s = PluginLoader.FindClass<AccountingService>();
|
2016-06-27 01:45:38 +02:00
|
|
|
|
|
2024-05-06 13:14:35 +02:00
|
|
|
|
return s.GetInvoiceBases(startDate, endDate);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-06-27 01:45:38 +02:00
|
|
|
|
|
2023-06-13 23:52:52 +02:00
|
|
|
|
public List<InvoiceBaseDC> GetInvoiceBases2(DateTime? startDate, DateTime? endDate, bool filterByInvoiceDate)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var s = PluginLoader.FindClass<AccountingService>();
|
|
|
|
|
|
|
2023-06-20 00:33:56 +02:00
|
|
|
|
return s.GetInvoiceBases(startDate, endDate, filterByInvoiceDate);
|
2023-06-13 23:52:52 +02:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-20 11:50:46 +01:00
|
|
|
|
public List<InvoiceBaseDC> GetInvoiceBasesForCostBearerAndId(DateTime? startDate, DateTime? endDate, long costBearerOid, String invoiceId)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var s = PluginLoader.FindClass<AccountingService>();
|
|
|
|
|
|
|
|
|
|
|
|
return s.GetInvoiceBases(startDate, endDate, costBearerOid, invoiceId);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-27 01:45:38 +02:00
|
|
|
|
public List<InvoiceBaseDC> GetGeneralInvoiceBasesForCustomer(long customerOid)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
return MapperFactory.InvoiceBaseDC_InvoiceBase.MapToNewDCs(DAOFactory.SearchDAO.GetInvoiceBaseByCustomerOid(InvoiceType.General, customerOid));
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<InvoiceBaseDC> GetGeneralInvoiceBasesForOrganisation(long organisationOid)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
return MapperFactory.InvoiceBaseDC_InvoiceBase.MapToNewDCs(DAOFactory.SearchDAO.GetInvoiceBaseByOrganisationOid(InvoiceType.General, organisationOid));
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<InvoiceBaseDC> GetGeneralInvoiceBasesForPerson(long personOid)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
return MapperFactory.InvoiceBaseDC_InvoiceBase.MapToNewDCs(DAOFactory.SearchDAO.GetInvoiceBaseByPersonOid(InvoiceType.General, personOid));
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<InvoiceBaseDC> GetInvoiceBasesForSupportConcept(InvoiceType type, long supportConceptOid)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
return MapperFactory.InvoiceBaseDC_InvoiceBase.MapToNewDCs(DAOFactory.SearchDAO.GetInvoiceBaseByTypeAndSupportConceptOid(type, supportConceptOid));
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ServiceInvoiceDC GetServiceInvoiceByInvoiceBaseOid(long invoiceBaseOid)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var dc = MapperFactory.ServiceInvoiceDC_ServiceInvoice.MapToNewDC(DAOFactory.SearchDAO.GetServiceInvoiceByInvoiceBaseOid(invoiceBaseOid));
|
|
|
|
|
|
|
|
|
|
|
|
SortServiceInvoicePeriods(dc);
|
|
|
|
|
|
return dc;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<ServiceInvoiceDC> GetServiceInvoices(long costBearerOid, long? supportConceptOid, DateTimeSpan period)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
List<ServiceInvoice> entities = DAOFactory.SearchDAO.GetServiceInvoices(costBearerOid, supportConceptOid, period);
|
|
|
|
|
|
entities.Sort((x, y) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (y.InvoiceBase.InvoiceDate.Value.Date.Equals(x.InvoiceBase.InvoiceDate.Value.Date))
|
|
|
|
|
|
{
|
|
|
|
|
|
return y.InvoiceBase.InvoiceNumber.CompareTo(x.InvoiceBase.InvoiceNumber);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return y.InvoiceBase.InvoiceDate.Value.Date.CompareTo(x.InvoiceBase.InvoiceDate.Value.Date);
|
|
|
|
|
|
});
|
2024-05-06 13:14:35 +02:00
|
|
|
|
|
2016-06-27 01:45:38 +02:00
|
|
|
|
var dcList = MapperFactory.ServiceInvoiceDC_ServiceInvoice.MapToNewDCs(entities);
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var serviceInvoice in dcList)
|
|
|
|
|
|
{
|
|
|
|
|
|
SortServiceInvoicePeriods(serviceInvoice);
|
|
|
|
|
|
}
|
|
|
|
|
|
return dcList;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SortServiceInvoicePeriods(ServiceInvoiceDC serviceInvoice)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (serviceInvoice.ServiceInvoicePeriods != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
serviceInvoice.ServiceInvoicePeriods.Sort((x, y) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (x.Customer != null && y.Customer != null)
|
|
|
|
|
|
return x.Customer.ToString().CompareTo(y.Customer.ToString());
|
|
|
|
|
|
else if (x.Start != null && y.Start != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
x.Start.Value.CompareTo(y.Start.Value);
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Settlement2DC GetSettlementByInvoiceBaseOid(long invoiceBaseOid)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
return MapperFactory.SettlementDC_SettlementInvoice.MapToNewDC(DAOFactory.SearchDAO.GetSettlementInvoiceByInvoiceBaseOid(invoiceBaseOid));
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<Settlement2DC> GetSettlementInvoicesForCostBearerAndPeriod(long costBearerOid, DateTime periodStart, DateTime periodEnd)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
return MapperFactory.SettlementDC_SettlementInvoice.MapToNewDCs(DAOFactory.SearchDAO.GetSettlementInvoicesForCostBearerAndPeriod(costBearerOid, periodStart, periodEnd));
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<Settlement2DC> GetSettlementInvoicesForSupportConcept(long supportConceptOid)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
return MapperFactory.SettlementDC_SettlementInvoice.MapToNewDCs(DAOFactory.SearchDAO.GetSettlementInvoiceBySupportConceptOid(supportConceptOid));
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<long> InsertNewInvoiceBases(List<InvoiceBaseDC> invoices)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2018-11-22 14:05:45 +01:00
|
|
|
|
if (invoices != null && LoggedInUserOperationContextExt.Current != null &&
|
|
|
|
|
|
LoggedInUserOperationContextExt.Current.User != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var loggedInUser = LoggedInUserOperationContextExt.Current.User;
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var ib in invoices)
|
|
|
|
|
|
{
|
|
|
|
|
|
ib.SenderContactInformations = new List<ContactDC>();
|
|
|
|
|
|
|
2024-05-06 13:14:35 +02:00
|
|
|
|
|
2018-11-22 14:05:45 +01:00
|
|
|
|
foreach (var contact in loggedInUser.Employee.Person.Contacts)
|
|
|
|
|
|
{
|
|
|
|
|
|
var newContact = new ContactDC();
|
|
|
|
|
|
newContact.ContactType = contact.Type;
|
|
|
|
|
|
newContact.ContactValue = contact.Value;
|
2024-05-06 13:14:35 +02:00
|
|
|
|
|
2018-11-22 14:05:45 +01:00
|
|
|
|
ib.SenderContactInformations.Add(newContact);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-06 13:14:35 +02:00
|
|
|
|
|
2018-11-22 14:05:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-27 01:45:38 +02:00
|
|
|
|
var newInvoices = MapperFactory.InvoiceBaseDC_InvoiceBase.MapToNewEntities(invoices);
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
2024-05-06 13:14:35 +02:00
|
|
|
|
var inc = PluginLoader.FindClass<InvoiceNumberGenerator>();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var ib in newInvoices)
|
|
|
|
|
|
{
|
2022-08-08 11:06:14 +02:00
|
|
|
|
if (ib.Type == InvoiceType.General)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var item in ib.InvoiceItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.AmountTotal = Math.Round(item.AmountTotal ?? 0, 2, MidpointRounding.AwayFromZero);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-05-06 13:14:35 +02:00
|
|
|
|
var nextNumber = inc.GetNextInvoiceNumber(count, ib);
|
|
|
|
|
|
if (!String.IsNullOrEmpty(nextNumber))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!String.IsNullOrEmpty(ib.InvoiceNumber)) // Rechnungsnummer schon vorher erzeugt oder per Hand vergeben.
|
|
|
|
|
|
{
|
|
|
|
|
|
if (ib.InvoiceNumber == nextNumber)
|
|
|
|
|
|
//Die per Hand vergebene Rechnungsnummer ist gleich der nächsten berechneten Rechnungsnummer, daher Rechnungsnummerzähler erhöhen
|
|
|
|
|
|
{
|
|
|
|
|
|
count++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
ib.InvoiceNumber = nextNumber;
|
|
|
|
|
|
count++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-01-08 22:29:10 +01:00
|
|
|
|
|
|
|
|
|
|
var factory = PluginLoader.FindClass<InvoiceFactory>();
|
|
|
|
|
|
|
|
|
|
|
|
if (factory != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var ib in newInvoices)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (ib.Type == InvoiceType.CustomerEquity)
|
|
|
|
|
|
{
|
|
|
|
|
|
var creator = factory.CreateEquityInvoiceCreator(ib);
|
|
|
|
|
|
creator.InitEquityInvoice(ib);
|
|
|
|
|
|
}
|
2022-12-15 23:16:04 +01:00
|
|
|
|
else if (ib.Type == InvoiceType.General)
|
|
|
|
|
|
{
|
|
|
|
|
|
var creator = factory.CreateGeneralInvoiceCreator(ib);
|
|
|
|
|
|
creator.InitInvoice(ib);
|
|
|
|
|
|
}
|
2018-01-08 22:29:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-06 13:14:35 +02:00
|
|
|
|
|
2018-01-08 22:29:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-06 13:14:35 +02:00
|
|
|
|
|
2018-01-08 22:29:10 +01:00
|
|
|
|
|
2016-06-27 01:45:38 +02:00
|
|
|
|
DAOFactory.GenericDAO.Insert(newInvoices);
|
2024-05-06 13:14:35 +02:00
|
|
|
|
|
2017-02-15 10:54:29 +01:00
|
|
|
|
inc.IncreaseInvoiceNumber(count, newInvoices);
|
2016-06-27 01:45:38 +02:00
|
|
|
|
|
|
|
|
|
|
return newInvoices.Select(i => i.Oid.Value).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<long> InsertNewServiceInvoices(List<ServiceInvoiceDC> invoices)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2023-12-13 12:53:20 +01:00
|
|
|
|
//Prüfe Flags
|
|
|
|
|
|
var neueRechnungen = new List<ServiceInvoiceDC>();
|
|
|
|
|
|
var diffRechnungen = invoices.Where(i => i.InvoiceBase.DiffErstellen).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
//Bei neuer Rechung prüfen, ob eine Diff Rechnung vorher generiert wurde.
|
|
|
|
|
|
foreach (var item in invoices.Where(i => i.InvoiceBase.NeuErstellen))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.OriginalZurDifferenz != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
neueRechnungen.Add(item.OriginalZurDifferenz);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
neueRechnungen.Add(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var newInvoices = MapperFactory.ServiceInvoiceDC_ServiceInvoice.MapToNewEntities(neueRechnungen);
|
|
|
|
|
|
newInvoices.AddRange(MapperFactory.ServiceInvoiceDC_ServiceInvoice.MapToNewEntities(diffRechnungen));
|
2024-05-06 13:14:35 +02:00
|
|
|
|
if (newInvoices.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
var inc = PluginLoader.FindClass<InvoiceNumberGenerator>();
|
2016-06-27 01:45:38 +02:00
|
|
|
|
|
2024-05-06 13:14:35 +02:00
|
|
|
|
foreach (var i in newInvoices)
|
|
|
|
|
|
{
|
|
|
|
|
|
var nextNumber = inc.GetNextInvoiceNumber(count, i.InvoiceBase);
|
|
|
|
|
|
if (!String.IsNullOrEmpty(nextNumber))
|
|
|
|
|
|
{
|
|
|
|
|
|
//if (!String.IsNullOrEmpty(i.InvoiceBase.InvoiceNumber) && newInvoices.Count == 1)
|
|
|
|
|
|
// // Rechnungsnummer schon vorher erzeugt oder per Hand vergeben.
|
|
|
|
|
|
//{
|
|
|
|
|
|
// if (i.InvoiceBase.InvoiceNumber == nextNumber || newInvoices.Count > 1)
|
|
|
|
|
|
// //Die per Hand vergebene Rechnungsnummer ist gleich der nächsten berechneten Rechnungsnummer, daher Rechnungsnummerzähler erhöhen
|
|
|
|
|
|
// {
|
|
|
|
|
|
// count++;
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
|
|
//else
|
|
|
|
|
|
//{
|
|
|
|
|
|
i.InvoiceBase.InvoiceNumber = nextNumber;
|
|
|
|
|
|
count++;
|
|
|
|
|
|
//}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-06-27 01:45:38 +02:00
|
|
|
|
|
2024-05-06 13:14:35 +02:00
|
|
|
|
DAOFactory.GenericDAO.Insert(newInvoices);
|
2016-06-27 01:45:38 +02:00
|
|
|
|
|
2024-05-06 13:14:35 +02:00
|
|
|
|
inc.IncreaseInvoiceNumber(count, newInvoices);
|
|
|
|
|
|
}
|
|
|
|
|
|
return newInvoices.Select(i => i.Oid.Value).ToList();
|
2016-06-27 01:45:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<long> InsertNewSettlementInvoice(List<Settlement2DC> invoices)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
var newInvoices = MapperFactory.SettlementDC_SettlementInvoice.MapToNewEntities(invoices);
|
|
|
|
|
|
int count = 0;
|
2024-05-06 13:14:35 +02:00
|
|
|
|
var inc = PluginLoader.FindClass<InvoiceNumberGenerator>();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var i in newInvoices)
|
|
|
|
|
|
{
|
|
|
|
|
|
var nextNumber = inc.GetNextInvoiceNumber(count, i.InvoiceBase);
|
|
|
|
|
|
if (!String.IsNullOrEmpty(nextNumber))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!String.IsNullOrEmpty(i.InvoiceBase.InvoiceNumber)) // Rechnungsnummer schon vorher erzeugt oder per Hand vergeben.
|
|
|
|
|
|
{
|
|
|
|
|
|
if (i.InvoiceBase.InvoiceNumber == nextNumber)
|
|
|
|
|
|
//Die per Hand vergebene Rechnungsnummer ist gleich der nächsten berechneten Rechnungsnummer, daher Rechnungsnummerzähler erhöhen
|
|
|
|
|
|
{
|
|
|
|
|
|
count++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
i.InvoiceBase.InvoiceNumber = nextNumber;
|
|
|
|
|
|
count++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-06-27 01:45:38 +02:00
|
|
|
|
|
|
|
|
|
|
DAOFactory.GenericDAO.Insert(newInvoices);
|
|
|
|
|
|
|
2017-02-15 10:54:29 +01:00
|
|
|
|
inc.IncreaseInvoiceNumber(count, newInvoices);
|
2016-06-27 01:45:38 +02:00
|
|
|
|
return newInvoices.Select(i => i.Oid.Value).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public InvoiceBaseDC LoadInvoiceBaseByOid(long invoiceBaseOid)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var r = MapperFactory.InvoiceBaseDC_InvoiceBase.MapToNewDC(
|
|
|
|
|
|
DAOFactory.GenericDAO.LoadByID<InvoiceBase>(invoiceBaseOid));
|
|
|
|
|
|
|
|
|
|
|
|
if (r.Type == InvoiceType.Settlement && r.SupportConceptOid != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
SupportConcept sc = DAOFactory.GenericDAO.LoadByID<SupportConcept>(r.SupportConceptOid.Value);
|
|
|
|
|
|
r.CustomerFirstName = sc.Customer.Person.FirstName;
|
|
|
|
|
|
r.CustomerLastName = sc.Customer.Person.LastName;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public InvoiceNumberDC LoadInvoiceNumber()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var inr = DAOFactory.GenericDAO.LoadByID<InvoiceNumber>(1);
|
|
|
|
|
|
if (inr != null)
|
2020-08-20 18:35:33 +02:00
|
|
|
|
return MapperFactory.InvoiceNumberDC_InvoiceNumber.MapToNewDC(inr);
|
2016-06-27 01:45:38 +02:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ServiceInvoiceDC LoadServiceInvoiceByOid(long serviceInvoiceOid)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var r = MapperFactory.ServiceInvoiceDC_ServiceInvoice.MapToNewDC(DAOFactory.GenericDAO.LoadByID<ServiceInvoice>(serviceInvoiceOid));
|
|
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<long> UpdateInvoiceBases(List<InvoiceBaseDC> invoices)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var originals = DAOFactory.GenericDAO.LoadByIDs<InvoiceBase>(invoices.Select(i => i.InvoiceBaseOid.Value));
|
|
|
|
|
|
MapperFactory.InvoiceBaseDC_InvoiceBase.MergeWithEntitys(invoices, originals);
|
|
|
|
|
|
DAOFactory.GenericDAO.Update(originals);
|
|
|
|
|
|
return originals.Select(e => e.Version.Value).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<long> SetInvoicePaid(List<InvoiceBaseDC> invoices, bool isPaid)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var originals = DAOFactory.GenericDAO.LoadByIDs<InvoiceBase>(invoices.Select(i => i.InvoiceBaseOid.Value));
|
|
|
|
|
|
foreach (var invoiceBase in originals)
|
|
|
|
|
|
{
|
|
|
|
|
|
invoiceBase.IsPaid = isPaid;
|
|
|
|
|
|
}
|
|
|
|
|
|
DAOFactory.GenericDAO.Update(originals);
|
|
|
|
|
|
return originals.Select(e => e.Version.Value).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public InvoiceNumberDC UpdateInvoiceNumber(InvoiceNumberDC dc)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
var old = DAOFactory.GenericDAO.LoadByID<InvoiceNumber>(1);
|
|
|
|
|
|
MapperFactory.InvoiceNumberDC_InvoiceNumber.MergeWithEntity(dc, old);
|
|
|
|
|
|
DAOFactory.GenericDAO.Update(old);
|
|
|
|
|
|
|
|
|
|
|
|
return MapperFactory.InvoiceNumberDC_InvoiceNumber.MapToNewDC(old);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<long> UpdateServiceInvoices(List<ServiceInvoiceDC> invoices)
|
|
|
|
|
|
{
|
2023-08-15 16:43:05 +02:00
|
|
|
|
var acc = PluginLoader.FindClass<AccountingService>();
|
|
|
|
|
|
return acc.UpdateServiceInvoices(invoices);
|
2016-06-27 01:45:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdateSettlementInvoice(List<Settlement2DC> invoices)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var originals = DAOFactory.GenericDAO.LoadByIDs<SettlementInvoice>(invoices.Select(i => i.SettlementIvoiceOid.Value));
|
|
|
|
|
|
MapperFactory.SettlementDC_SettlementInvoice.MergeWithEntitys(invoices, originals);
|
2024-05-06 13:14:35 +02:00
|
|
|
|
|
|
|
|
|
|
//originals.ForEach(
|
2016-06-27 01:45:38 +02:00
|
|
|
|
// i =>
|
|
|
|
|
|
// {
|
2024-05-06 13:14:35 +02:00
|
|
|
|
//i.InvoiceBase.Type = InvoiceType.Settlement;
|
|
|
|
|
|
|
|
|
|
|
|
// We´ll add an invoiceitem, so we can treat a settlement like any other invoice
|
|
|
|
|
|
//i.InvoiceBase.InvoiceItems.Clear();
|
|
|
|
|
|
//i.InvoiceBase.InvoiceItems.Add(
|
|
|
|
|
|
// new InvoiceItem
|
|
|
|
|
|
// {
|
|
|
|
|
|
// AmountTotal = i.Claim,
|
|
|
|
|
|
// ItemPeriodStart = i.InvoiceBase.AccountingPeriodStart,
|
|
|
|
|
|
// ItemPeriodEnd = i.InvoiceBase.AccountingPeriodEnd,
|
|
|
|
|
|
// ItemDescription = "Spitzabrechung"
|
|
|
|
|
|
// });
|
|
|
|
|
|
//});
|
2016-06-27 01:45:38 +02:00
|
|
|
|
DAOFactory.GenericDAO.Update(originals);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-08-20 18:35:33 +02:00
|
|
|
|
|
2024-05-06 13:14:35 +02:00
|
|
|
|
|
2020-08-20 18:35:33 +02:00
|
|
|
|
public List<InvoiceNumberDC> LoadInvoiceNumberList()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var numbers = DAOFactory.GenericDAO.GetAllActive<InvoiceNumber>();
|
2024-05-06 13:14:35 +02:00
|
|
|
|
|
2020-08-20 18:35:33 +02:00
|
|
|
|
return MapperFactory.InvoiceNumberDC_InvoiceNumber.MapToNewDCs(numbers);
|
2024-05-06 13:14:35 +02:00
|
|
|
|
|
2020-08-20 18:35:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<InvoiceNumberDC> UpdateInvoiceNumberList(List<InvoiceNumberDC> dclist)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var numbers = DAOFactory.GenericDAO.GetAllActive<InvoiceNumber>();
|
|
|
|
|
|
|
|
|
|
|
|
MapperFactory.InvoiceNumberDC_InvoiceNumber.MergeWithEntitys(dclist, numbers);
|
|
|
|
|
|
DAOFactory.GenericDAO.Update(numbers);
|
|
|
|
|
|
|
|
|
|
|
|
return MapperFactory.InvoiceNumberDC_InvoiceNumber.MapToNewDCs(numbers);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-01-25 16:07:45 +01:00
|
|
|
|
|
2024-04-17 16:33:19 +02:00
|
|
|
|
public GkvAbrechnungDC GetGkvAbrechnung(long oid)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var gkv = DAOFactory.GenericDAO.GetByID<GkvAbrechnung>(oid);
|
|
|
|
|
|
|
|
|
|
|
|
var dc = MapperFactory.GkvAbrechnungDC_GkvAbrechnung.MapToNewDC(gkv);
|
|
|
|
|
|
|
|
|
|
|
|
return dc;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<GkvAbrechnungDC> GetFilteredGkvAbrechnungen(GkvAbrechnungViewFilterDC gkvAbrechnungViewFilter)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (gkvAbrechnungViewFilter == null || !gkvAbrechnungViewFilter.FilterTime)
|
|
|
|
|
|
return GetAllGkvAbrechnungen();
|
|
|
|
|
|
|
2024-05-08 12:26:22 +02:00
|
|
|
|
var start = gkvAbrechnungViewFilter.Start;
|
|
|
|
|
|
var end = gkvAbrechnungViewFilter.End;
|
|
|
|
|
|
var filter = gkvAbrechnungViewFilter.FilterForInvoiceDate;
|
|
|
|
|
|
|
|
|
|
|
|
var entities = DAOFactory.SearchDAO.GetGkvAbrechnungen(start, end, filter);
|
2024-04-17 16:33:19 +02:00
|
|
|
|
|
|
|
|
|
|
return MapperFactory.GkvAbrechnungDC_GkvAbrechnung.MapToNewDCs(entities);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<GkvAbrechnungDC> GetAllGkvAbrechnungen()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2024-05-06 16:33:49 +02:00
|
|
|
|
var user = LoggedInUserOperationContextExt.Current?.User ?? SessionFacade.LoggedInUser;
|
2024-04-17 16:33:19 +02:00
|
|
|
|
|
2024-05-06 16:33:49 +02:00
|
|
|
|
var entries = DAOFactory.GenericDAO.GetAllActive<GkvAbrechnung>();
|
|
|
|
|
|
|
|
|
|
|
|
var dcs = MapperFactory.GkvAbrechnungDC_GkvAbrechnung.MapToNewDCs(entries);
|
|
|
|
|
|
|
2024-05-13 14:57:29 +02:00
|
|
|
|
var updateables = dcs.Where(x => x.GetState() != 5 && x.GetState() != 1
|
|
|
|
|
|
//&& x.GesendetAm.HasValue
|
|
|
|
|
|
).ToArray();
|
|
|
|
|
|
|
|
|
|
|
|
if (!updateables.Any())
|
|
|
|
|
|
return dcs;
|
2024-05-06 16:33:49 +02:00
|
|
|
|
|
|
|
|
|
|
var isUpToDate = SendApp8GetStatusRequest(updateables, user.LoginName, user.RC2EncryptedHash);
|
|
|
|
|
|
|
|
|
|
|
|
if (isUpToDate)
|
|
|
|
|
|
return dcs;
|
|
|
|
|
|
|
|
|
|
|
|
entries = DAOFactory.GenericDAO.GetAllActive<GkvAbrechnung>();
|
|
|
|
|
|
|
|
|
|
|
|
dcs = MapperFactory.GkvAbrechnungDC_GkvAbrechnung.MapToNewDCs(entries);
|
2024-04-17 16:33:19 +02:00
|
|
|
|
|
|
|
|
|
|
return dcs;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-06 16:33:49 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="updateables"></param>
|
|
|
|
|
|
/// <param name="loginName"></param>
|
|
|
|
|
|
/// <param name="hashed_password"></param>
|
|
|
|
|
|
/// <returns>Returns true, if the states are all up to date. False otherwise.</returns>
|
|
|
|
|
|
private bool SendApp8GetStatusRequest(GkvAbrechnungDC[] updateables, string loginName, string hashed_password)
|
2024-05-06 13:14:35 +02:00
|
|
|
|
{
|
2024-05-06 16:33:49 +02:00
|
|
|
|
var updateables_len = updateables.Count();
|
|
|
|
|
|
|
2024-05-08 12:26:22 +02:00
|
|
|
|
var url = "https://app8.bewoplaner.de/service/GkvAbrechnungView.aspx";
|
|
|
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
|
url = "http://localhost:3777/Host/GkvAbrechnungView.aspx";
|
|
|
|
|
|
#endif
|
2024-05-06 16:33:49 +02:00
|
|
|
|
|
|
|
|
|
|
var request = new GkvApp8GetStatusRequest
|
|
|
|
|
|
{
|
|
|
|
|
|
Username = loginName,
|
|
|
|
|
|
Password = hashed_password,
|
|
|
|
|
|
Tenant = MultitenancyOperationContextExt.Current.Tenant,
|
|
|
|
|
|
Tuples = new Tuple<GkvAbrechnungDC, long>[updateables_len]
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
for (int id = 0; id < updateables_len; id++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var gkv_abrechnung = updateables[id];
|
|
|
|
|
|
var gkv_abrechnung_oid = gkv_abrechnung.GkvAbrechnungOid.Value;
|
|
|
|
|
|
|
|
|
|
|
|
request.Tuples[id] = new Tuple<GkvAbrechnungDC, long>(gkv_abrechnung, gkv_abrechnung_oid);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-07 16:55:53 +02:00
|
|
|
|
var response_app8_str = SendApp8Request(url, JsonConvert.SerializeObject(request));
|
2024-05-06 16:33:49 +02:00
|
|
|
|
|
|
|
|
|
|
var response_app8 = JsonConvert.DeserializeObject<GkvApp8GetStatusResponse>(response_app8_str);
|
|
|
|
|
|
|
2024-05-07 16:55:53 +02:00
|
|
|
|
if (!response_app8.Success)
|
|
|
|
|
|
{
|
2024-05-08 12:26:22 +02:00
|
|
|
|
return true;
|
2024-05-07 16:55:53 +02:00
|
|
|
|
throw new NotImplementedException("App 8 Anfrage nicht erfolgreich");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-06 16:33:49 +02:00
|
|
|
|
bool allAreUpToDate = true;
|
|
|
|
|
|
for (int id = 0; id < updateables_len; id++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var gkv_abrechnung = updateables[id];
|
|
|
|
|
|
var app8_tuple = response_app8.Tuples[id];
|
|
|
|
|
|
|
|
|
|
|
|
var app8_isUpToDate = app8_tuple.Item1;
|
|
|
|
|
|
var app8_gkv_abrechnunng = app8_tuple.Item2;
|
|
|
|
|
|
|
|
|
|
|
|
if (app8_isUpToDate)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
allAreUpToDate = false;
|
|
|
|
|
|
|
2024-05-13 14:57:29 +02:00
|
|
|
|
var gkv_abrechnung_entity = DAOFactory.GenericDAO.LoadByID<GkvAbrechnung>(gkv_abrechnung.GkvAbrechnungOid.Value);
|
2024-05-06 16:33:49 +02:00
|
|
|
|
|
2024-05-13 14:57:29 +02:00
|
|
|
|
var gkv_abrechnung_new_entity = MapperFactory.GkvAbrechnungDC_GkvAbrechnung.MergeWithEntity(gkv_abrechnung, gkv_abrechnung_entity);
|
|
|
|
|
|
|
|
|
|
|
|
DAOFactory.GenericDAO.Update(gkv_abrechnung_new_entity);
|
2024-05-06 16:33:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return allAreUpToDate;
|
2024-05-06 13:14:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-23 14:50:01 +02:00
|
|
|
|
public GkvAbrechnungResponseDC CreateNewGkvAbrechnung(GkvAbrechnungRequestDC request)
|
2024-04-17 16:33:19 +02:00
|
|
|
|
{
|
2024-04-23 14:50:01 +02:00
|
|
|
|
var response = new GkvAbrechnungResponseDC();
|
|
|
|
|
|
|
2024-04-17 16:33:19 +02:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2024-04-23 14:50:01 +02:00
|
|
|
|
var gkv_abrechnung_dc = request.GkvAbrechnungDC;
|
|
|
|
|
|
|
2024-05-14 14:10:44 +02:00
|
|
|
|
if(gkv_abrechnung_dc.AbrechnungsZeitraumEnde.Value.Hour == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
gkv_abrechnung_dc.AbrechnungsZeitraumEnde = gkv_abrechnung_dc.AbrechnungsZeitraumEnde.Value.Date.AddDays(1).AddMilliseconds(-1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-24 16:05:44 +02:00
|
|
|
|
var manager = new DakotaManager();
|
2024-04-17 16:33:19 +02:00
|
|
|
|
var mandatordc = new OperationsServiceImp().GetMandator();
|
2024-04-19 12:52:57 +02:00
|
|
|
|
var loaded_invoicebases = new List<InvoiceBaseDC>();
|
|
|
|
|
|
|
2024-05-06 15:01:32 +02:00
|
|
|
|
DakotaValidator.ValidateFirstStep(mandatordc, request);
|
2024-04-23 14:50:01 +02:00
|
|
|
|
|
2024-05-06 15:01:32 +02:00
|
|
|
|
int? datenaustauschreferenz = null;
|
2024-04-23 14:50:01 +02:00
|
|
|
|
foreach (var invoicebase_oid in request.SelectedInvoiceBases)
|
2024-04-17 16:33:19 +02:00
|
|
|
|
{
|
|
|
|
|
|
var service = DAOFactory.SearchDAO.GetServiceInvoiceByInvoiceBaseOid(invoicebase_oid);
|
|
|
|
|
|
var invoicebase = DAOFactory.GenericDAO.GetByID<InvoiceBase>(invoicebase_oid);
|
|
|
|
|
|
var orga = invoicebase.CostBearer2SupportConcept.CostBearer.Organisation;
|
|
|
|
|
|
var customer = invoicebase.CostBearer2SupportConcept.SupportConcept.Customer;
|
|
|
|
|
|
|
2024-04-19 12:52:57 +02:00
|
|
|
|
var invoicebase_dc = MapperFactory.InvoiceBaseDC_InvoiceBase.MapToNewDC(invoicebase);
|
|
|
|
|
|
|
2024-05-06 15:01:32 +02:00
|
|
|
|
if(!datenaustauschreferenz.HasValue)
|
|
|
|
|
|
datenaustauschreferenz = DAOFactory.SearchDAO.GetLastDatenaustauschreferenz(orga.IKDatenannahmestelle) + 1;
|
|
|
|
|
|
|
2024-04-19 12:52:57 +02:00
|
|
|
|
loaded_invoicebases.Add(invoicebase_dc);
|
|
|
|
|
|
|
2024-04-17 16:33:19 +02:00
|
|
|
|
var servicedc = MapperFactory.ServiceInvoiceDC_ServiceInvoice.MapToNewDC(service);
|
|
|
|
|
|
var orgadc = MapperFactory.OrganisationDC_OrganisationMapper.MapToNewDC(orga);
|
|
|
|
|
|
var customerdc = MapperFactory.CustomerDC_Customer.MapToNewDC(customer);
|
|
|
|
|
|
|
2024-04-23 14:50:01 +02:00
|
|
|
|
DakotaValidator.ValidateSecondStep(orgadc, customerdc);
|
|
|
|
|
|
|
2024-05-06 15:01:32 +02:00
|
|
|
|
manager.Add(servicedc, orgadc, customerdc, mandatordc, datenaustauschreferenz.Value);
|
2024-04-17 16:33:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
manager.Apply();
|
|
|
|
|
|
|
2024-04-23 14:50:01 +02:00
|
|
|
|
if (manager.DakotaFileDict.Count != 1 || manager.DakotaFileDict.First().Value.GetKostenträgerCount() != 1)
|
2024-04-17 16:33:19 +02:00
|
|
|
|
{
|
2024-04-23 14:50:01 +02:00
|
|
|
|
throw new DakotaException("Unerwartete Anzahl an Dakota Files berechnet.");
|
2024-04-17 16:33:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var file_from_manager = manager.DakotaFileDict.First().Value;
|
|
|
|
|
|
|
|
|
|
|
|
var nutzdatendatei = file_from_manager.GetNutzdatendatei();
|
|
|
|
|
|
|
|
|
|
|
|
// https://dev.mysql.com/doc/refman/8.3/en/string-type-syntax.html
|
|
|
|
|
|
// A TEXT column with a maximum length of 65,535 (2^16 − 1) characters.
|
|
|
|
|
|
// The effective maximum length is less if the value contains multibyte
|
|
|
|
|
|
// characters. Each TEXT value is stored using a 2-byte length prefix
|
|
|
|
|
|
// that indicates the number of bytes in the value.
|
|
|
|
|
|
if (nutzdatendatei.Length > 65535)
|
|
|
|
|
|
{
|
2024-04-23 14:50:01 +02:00
|
|
|
|
throw new DakotaException($"nutzdatendatei - Länger als 65535: {nutzdatendatei.Length}");
|
2024-04-17 16:33:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-06 15:01:32 +02:00
|
|
|
|
gkv_abrechnung_dc.IKDatenannahmestelle = file_from_manager.GetIKDatenannahmestelle();
|
2024-04-23 14:50:01 +02:00
|
|
|
|
gkv_abrechnung_dc.IKKostenträger = file_from_manager.GetIKKostenträger();
|
|
|
|
|
|
gkv_abrechnung_dc.IKLeistungserbringer = file_from_manager.GetIKLeistungserbringer();
|
2024-04-17 16:33:19 +02:00
|
|
|
|
gkv_abrechnung_dc.IKVersichertenKarte = file_from_manager.GetIKVersichertenKarte();
|
|
|
|
|
|
|
|
|
|
|
|
gkv_abrechnung_dc.Auftragsdatei = file_from_manager.GetAuftragsdatei();
|
|
|
|
|
|
gkv_abrechnung_dc.Nutzdatendatei = file_from_manager.GetNutzdatendatei();
|
|
|
|
|
|
gkv_abrechnung_dc.Transfername = file_from_manager.GetTransferName();
|
2024-05-06 15:01:32 +02:00
|
|
|
|
gkv_abrechnung_dc.Datenaustauschreferenz = file_from_manager.GetDatenaustauschreferenz();
|
2024-05-13 14:57:29 +02:00
|
|
|
|
gkv_abrechnung_dc.Dateigröße = nutzdatendatei.Length;
|
2024-04-17 16:33:19 +02:00
|
|
|
|
|
|
|
|
|
|
gkv_abrechnung_dc.ErstelltAm = file_from_manager.Created;
|
|
|
|
|
|
gkv_abrechnung_dc.Betrag = file_from_manager.GetBetrag();
|
2024-04-19 12:52:57 +02:00
|
|
|
|
gkv_abrechnung_dc.InvoiceBases = loaded_invoicebases;
|
|
|
|
|
|
|
2024-04-17 16:33:19 +02:00
|
|
|
|
var gkv_abrechnung = MapperFactory.GkvAbrechnungDC_GkvAbrechnung.MapToNewEntity(gkv_abrechnung_dc);
|
|
|
|
|
|
|
|
|
|
|
|
DAOFactory.GenericDAO.Insert(gkv_abrechnung);
|
|
|
|
|
|
|
|
|
|
|
|
var new_gkv_abrechnung_dc = MapperFactory.GkvAbrechnungDC_GkvAbrechnung.MapToNewDC(gkv_abrechnung);
|
|
|
|
|
|
|
2024-04-23 14:50:01 +02:00
|
|
|
|
response.Success = true;
|
|
|
|
|
|
response.GkvAbrechnungDC = new_gkv_abrechnung_dc;
|
2024-05-06 13:14:35 +02:00
|
|
|
|
|
|
|
|
|
|
return response;
|
2024-04-23 14:50:01 +02:00
|
|
|
|
}
|
2024-05-06 13:14:35 +02:00
|
|
|
|
catch (DakotaException exc)
|
2024-04-23 14:50:01 +02:00
|
|
|
|
{
|
|
|
|
|
|
response.Error = exc.Message;
|
2024-04-17 16:33:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
2024-04-23 14:50:01 +02:00
|
|
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-26 12:39:39 +02:00
|
|
|
|
public GkvAbrechnungDC UpdateGkvAbrechnung(GkvAbrechnungDC abrechnung)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var entity = DAOFactory.GenericDAO.GetByID<GkvAbrechnung>(abrechnung.GkvAbrechnungOid.Value);
|
|
|
|
|
|
|
2024-05-14 14:10:44 +02:00
|
|
|
|
MapperFactory.GkvAbrechnungDC_GkvAbrechnung.MergeWithEntity(abrechnung, entity);
|
|
|
|
|
|
|
|
|
|
|
|
//entity.Notice = abrechnung.Notice;
|
|
|
|
|
|
//entity.Bezahlt = abrechnung.Bezahlt;
|
2024-04-26 12:39:39 +02:00
|
|
|
|
|
|
|
|
|
|
DAOFactory.GenericDAO.Update(entity);
|
|
|
|
|
|
|
|
|
|
|
|
return MapperFactory.GkvAbrechnungDC_GkvAbrechnung.MapToNewDC(entity);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-29 13:00:17 +02:00
|
|
|
|
public void DeleteGkvAbrechnung(GkvAbrechnungDC abrechnung)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
ServiceLogic.SetActivationType<GkvAbrechnung>(abrechnung.GkvAbrechnungOid.Value, abrechnung.GkvAbrechnungVersion.Value, ActivationTypeId.Deleted);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-26 12:39:39 +02:00
|
|
|
|
|
2024-01-25 16:07:45 +01:00
|
|
|
|
public List<long> InsertNewGkvAbrechnungen(List<GkvAbrechnungDC> dcList)
|
|
|
|
|
|
{
|
2024-05-06 13:14:35 +02:00
|
|
|
|
//try
|
|
|
|
|
|
//{
|
|
|
|
|
|
// var newGkvAbrechnungen = MapperFactory.GkvAbrechnungDC_GkvAbrechnung.MapToNewEntities(dcList);
|
|
|
|
|
|
|
|
|
|
|
|
// DAOFactory.GenericDAO.Insert(newGkvAbrechnungen);
|
|
|
|
|
|
|
|
|
|
|
|
// return newGkvAbrechnungen.Select(i => i.Oid.Value).ToList();
|
|
|
|
|
|
//}
|
|
|
|
|
|
//catch (Exception e)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public GkvAbrechnungSendResponseDC SendNewGkvAbrechnung(GkvAbrechnungSendRequestDC req)
|
|
|
|
|
|
{
|
|
|
|
|
|
var response = new GkvAbrechnungSendResponseDC();
|
|
|
|
|
|
|
|
|
|
|
|
response.Successful = false;
|
|
|
|
|
|
|
|
|
|
|
|
var user = LoggedInUserOperationContextExt.Current?.User ?? SessionFacade.LoggedInUser;
|
|
|
|
|
|
if (user == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
response.Message = "User unbekannt";
|
|
|
|
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-25 16:07:45 +01:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2024-05-06 13:14:35 +02:00
|
|
|
|
var oid = req.GkvAbrechnungDC.GkvAbrechnungOid.Value;
|
|
|
|
|
|
|
2024-05-06 16:33:49 +02:00
|
|
|
|
string response_app8_str = SendApp8SendNewRequest(oid, user.LoginName, user.RC2EncryptedHash);
|
2024-05-06 13:14:35 +02:00
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(response_app8_str))
|
|
|
|
|
|
{
|
|
|
|
|
|
response.Message = "App8 leere Antwort";
|
|
|
|
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-13 14:57:29 +02:00
|
|
|
|
var response_app8 = JsonConvert.DeserializeObject<GkvApp8SendNewResponse>(response_app8_str);
|
2024-05-06 13:14:35 +02:00
|
|
|
|
|
|
|
|
|
|
response.Successful = response_app8.Success;
|
|
|
|
|
|
|
2024-05-07 16:55:53 +02:00
|
|
|
|
if (response_app8.Success)
|
|
|
|
|
|
{
|
|
|
|
|
|
var entity = DAOFactory.GenericDAO.GetByID<GkvAbrechnung>(req.GkvAbrechnungDC.GkvAbrechnungOid.Value);
|
|
|
|
|
|
|
2024-05-13 14:57:29 +02:00
|
|
|
|
var child_dc = response_app8.GkvTransferProtokollDC;
|
|
|
|
|
|
var child = MapperFactory.GkvTransferProtokollDC_GkvTransferprotokoll.MapToNewEntity(child_dc);
|
|
|
|
|
|
|
|
|
|
|
|
entity.GkvTransferProtokolle.Add(child);
|
2024-05-07 16:55:53 +02:00
|
|
|
|
|
|
|
|
|
|
DAOFactory.GenericDAO.Update(entity);
|
|
|
|
|
|
|
2024-05-06 13:14:35 +02:00
|
|
|
|
response.Message = "Erfolgreich gesendet";
|
2024-05-07 16:55:53 +02:00
|
|
|
|
response.GkvAbrechnungDC = MapperFactory.GkvAbrechnungDC_GkvAbrechnung.MapToNewDC(entity);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
response.Message = response_app8.Message;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-06 13:14:35 +02:00
|
|
|
|
|
|
|
|
|
|
return response;
|
2024-01-25 16:07:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-05-06 16:33:49 +02:00
|
|
|
|
private string SendApp8SendNewRequest(long oid, string loginName, string hashed_password)
|
|
|
|
|
|
{
|
|
|
|
|
|
var entity = DAOFactory.GenericDAO.LoadByID<GkvAbrechnung>(oid);
|
|
|
|
|
|
|
|
|
|
|
|
var gkv_abrechnung_dc = MapperFactory.GkvAbrechnungDC_GkvAbrechnung.MapToNewDC(entity);
|
|
|
|
|
|
|
2024-05-08 12:26:22 +02:00
|
|
|
|
var url = "https://app8.bewoplaner.de/service/GkvAbrechnungView.aspx";
|
|
|
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
|
url = "http://localhost:3777/Host/GkvAbrechnungView.aspx";
|
|
|
|
|
|
#endif
|
2024-05-06 16:33:49 +02:00
|
|
|
|
|
|
|
|
|
|
var request_app8 = new GkvApp8SendNewRequest
|
|
|
|
|
|
{
|
|
|
|
|
|
GkvAbrechnung = gkv_abrechnung_dc,
|
|
|
|
|
|
Username = loginName,
|
|
|
|
|
|
Password = hashed_password,
|
|
|
|
|
|
Tenant = MultitenancyOperationContextExt.Current.Tenant
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return SendApp8Request(url, request_app8);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string SendApp8Request(string url, object request) => SendApp8Request(url, JsonConvert.SerializeObject(request));
|
|
|
|
|
|
private string SendApp8Request(string url, string dataString)
|
|
|
|
|
|
{
|
2024-05-07 16:55:53 +02:00
|
|
|
|
url += "?tenant=" + MultitenancyOperationContextExt.Current.Tenant;
|
|
|
|
|
|
|
2024-05-06 16:33:49 +02:00
|
|
|
|
string response_app8_str;
|
|
|
|
|
|
using (WebClient client = new WebClient())
|
|
|
|
|
|
{
|
|
|
|
|
|
client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
|
|
|
|
|
|
|
|
|
|
|
|
response_app8_str = client.UploadString(url, "POST", dataString);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return response_app8_str;
|
|
|
|
|
|
}
|
2016-06-27 01:45:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|