From 0b776f279f3204bdad112c8ec7f04d722905e368 Mon Sep 17 00:00:00 2001 From: Rene Evertz Date: Mon, 9 Dec 2024 11:16:17 +0100 Subject: [PATCH] =?UTF-8?q?Hack:=20Mehrere=20Mandatoren=20m=C3=B6glich?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dakota/Logic/DakotaInfoCreator.cs | 12 +- Dakota/Logic/DakotaManager.cs | 7 +- .../Models/Infos/InfoParameterInvoiceItem.cs | 10 +- Data/Data.csproj | 1 + Data/Models/AddressInformation.cs | 21 + .../DiakonieKKKleve/DiakonieKKKleve.csproj | 1 + .../Service/DkkkAccountingService.cs | 38 + Service/Plugins/AccountingService.cs | 1178 +++++++++-------- .../AccountingServiceImp.cs | 24 +- 9 files changed, 695 insertions(+), 597 deletions(-) create mode 100644 Data/Models/AddressInformation.cs create mode 100644 ReportImp/DiakonieKKKleve/Service/DkkkAccountingService.cs diff --git a/Dakota/Logic/DakotaInfoCreator.cs b/Dakota/Logic/DakotaInfoCreator.cs index 5cbaecaa7..c682186fd 100644 --- a/Dakota/Logic/DakotaInfoCreator.cs +++ b/Dakota/Logic/DakotaInfoCreator.cs @@ -194,16 +194,16 @@ namespace Dakota.Logic info.IKAbsender = DakotaConfig.IKAbsender; info.IKKostentrager = infoParameter.IKKostentrager; info.IKKrankenkasse = infoParameter.IKKrankenkasse; - info.IKLeistungserbringer = infoParameter.IKLeistungserbringer; + info.IKLeistungserbringer = infoParameter.AddressInformation.IKLeistungserbringer; info.Rechnungsnummer = infoParameter.InvoiceBase.InvoiceNumber; info.Rechnungsdatum = infoParameter.InvoiceBase.InvoiceDate.Value; info.Rechnungsart = SchlüsselRechnungsart.AbrechnungÜberAbrechnungsstelleOhneInkassovollmacht; - info.Name1 = infoParameter.Mandator.Name; - info.Name2 = "Rene Evertz"; - info.Name3 = "Entwickler bei ownSoft"; - info.Name4 = "dakota.exchange@ownsoft.de"; + info.Name1 = infoParameter.AddressInformation.OrganisationName; + info.Name2 = infoParameter.AddressInformation.Phone; + info.Name3 = infoParameter.AddressInformation.Mail; + info.Name4 = "Entwicklung: dakota.exchange@ownsoft.de"; return info; } @@ -215,7 +215,7 @@ namespace Dakota.Logic info.IKAbsender = DakotaConfig.IKAbsender; info.IKKostentrager = infoParameter.IKKostentrager; info.IKKrankenkasse = infoParameter.IKKrankenkasse; - info.IKLeistungserbringer = infoParameter.IKLeistungserbringer; + info.IKLeistungserbringer = infoParameter.AddressInformation.IKLeistungserbringer; info.Rechnungsnummer = infoParameter.InvoiceBase.InvoiceNumber; info.Rechnungsdatum = infoParameter.InvoiceBase.InvoiceDate.Value; diff --git a/Dakota/Logic/DakotaManager.cs b/Dakota/Logic/DakotaManager.cs index f5167c810..a101b7853 100644 --- a/Dakota/Logic/DakotaManager.cs +++ b/Dakota/Logic/DakotaManager.cs @@ -1,4 +1,5 @@ -using BS.Shared.DataContracts; +using BeWo.Data.Models; +using BS.Shared.DataContracts; using Dakota.Models.Infos; using System; using System.Collections.Generic; @@ -40,7 +41,7 @@ namespace Dakota.Logic IsSammelrechnung = isSammelrechnung; } - public void Add(ServiceInvoiceDC serviceInvoice, OrganisationDC organisation, CustomerDC customer, MandatorDC mandator, int datenaustauschreferenz, int transfernummer) + public void Add(ServiceInvoiceDC serviceInvoice, OrganisationDC organisation, CustomerDC customer, AddressInformation address, int datenaustauschreferenz, int transfernummer) { try { @@ -75,7 +76,7 @@ namespace Dakota.Logic { foreach (var invoice in peroid.InvoiceItems) { - var info_nutz_item = new InfoParameterInvoiceItem(serviceInvoice, invoice, organisation, customer, mandator); + var info_nutz_item = new InfoParameterInvoiceItem(serviceInvoice, invoice, organisation, customer, address); DakotaInfoCreator.AddInfoParameter(nutzdaten, info_nutz_item, Version); } diff --git a/Dakota/Models/Infos/InfoParameterInvoiceItem.cs b/Dakota/Models/Infos/InfoParameterInvoiceItem.cs index e9deeb7be..a21129002 100644 --- a/Dakota/Models/Infos/InfoParameterInvoiceItem.cs +++ b/Dakota/Models/Infos/InfoParameterInvoiceItem.cs @@ -1,4 +1,5 @@ -using BS.Shared.DataContracts; +using BeWo.Data.Models; +using BS.Shared.DataContracts; using Dakota.Models.Schlüssels; using System; using System.Collections.Generic; @@ -15,22 +16,21 @@ namespace Dakota.Models.Infos public ServiceInvoiceDC ServiceInvoice { get; set; } public CustomerDC Customer { get; set; } public OrganisationDC Organisation { get; set; } - public MandatorDC Mandator { get; set; } + public AddressInformation AddressInformation { get; set; } public string Abrechnungsposition { get; set; } public string IKKostentrager => Organisation.IKKostentrager; public string IKKrankenkasse => Organisation.IKKrankenkasse; - public string IKLeistungserbringer => Mandator.IKLeistungserbringer; - public InfoParameterInvoiceItem(ServiceInvoiceDC serviceInvoice, InvoiceItemDC invoiceItem, OrganisationDC organisation, CustomerDC customer, MandatorDC mandator) + public InfoParameterInvoiceItem(ServiceInvoiceDC serviceInvoice, InvoiceItemDC invoiceItem, OrganisationDC organisation, CustomerDC customer, AddressInformation addressInformation) { InvoiceItem = invoiceItem; InvoiceBase = serviceInvoice.InvoiceBase; ServiceInvoice = serviceInvoice; Customer = customer; Organisation = organisation; - Mandator = mandator; + AddressInformation = addressInformation; // Todo: Valid prüfen Abrechnungsposition = invoiceItem.UnitDescription?.Substring(6) ?? "TODO"; diff --git a/Data/Data.csproj b/Data/Data.csproj index 4cfb6b550..5465251e0 100644 --- a/Data/Data.csproj +++ b/Data/Data.csproj @@ -391,6 +391,7 @@ + diff --git a/Data/Models/AddressInformation.cs b/Data/Models/AddressInformation.cs new file mode 100644 index 000000000..071b88ca4 --- /dev/null +++ b/Data/Models/AddressInformation.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeWo.Data.Models +{ + public class AddressInformation + { + public string IKLeistungserbringer { get; set; } + public string OrganisationName { get; set; } + public string Street { get; set; } + public string PostCode { get; set; } + public string Town { get; set; } + public string Phone { get; set; } + public string Fax { get; set; } + public string Mail { get; set; } + public string Website { get; set; } + } +} diff --git a/ReportImp/DiakonieKKKleve/DiakonieKKKleve.csproj b/ReportImp/DiakonieKKKleve/DiakonieKKKleve.csproj index 4be346abf..d951f97c6 100644 --- a/ReportImp/DiakonieKKKleve/DiakonieKKKleve.csproj +++ b/ReportImp/DiakonieKKKleve/DiakonieKKKleve.csproj @@ -200,6 +200,7 @@ RechnungSoziotherapie.cs + Component diff --git a/ReportImp/DiakonieKKKleve/Service/DkkkAccountingService.cs b/ReportImp/DiakonieKKKleve/Service/DkkkAccountingService.cs new file mode 100644 index 000000000..053b30a2c --- /dev/null +++ b/ReportImp/DiakonieKKKleve/Service/DkkkAccountingService.cs @@ -0,0 +1,38 @@ +using BeWo.Data.Access; +using BeWo.Data.Entities; +using BeWo.Data.Models; +using BeWo.Service.Plugins; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DiakonieKKKleve.Service +{ + public class DkkkAccountingService : AccountingService + { + public override AddressInformation GetAddressInformation(long? customer_oid = null) + { + var info = base.GetAddressInformation(); + + if (customer_oid is null) + return info; + + var c = DAOFactory.GenericDAO.GetByID(customer_oid.Value); + + foreach (var t2c in c.Team2CustomerList) + { + if (t2c.Team.Name.Contains("Nord")) + { + info.IKLeistungserbringer = "500506341"; + info.Street = "Stechbahn 33"; + info.PostCode = "47533"; + info.Town = "Kleve"; + } + } + + return info; + } + } +} diff --git a/Service/Plugins/AccountingService.cs b/Service/Plugins/AccountingService.cs index 556a1a20a..98b2fba21 100644 --- a/Service/Plugins/AccountingService.cs +++ b/Service/Plugins/AccountingService.cs @@ -1,218 +1,221 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.ServiceModel; -using BeWo.Data.Access; -using BeWo.Data.Entities; -using BeWo.Service.Core; -using BeWo.Service.DCEntityMapper; -using BeWo.Service.Invoicing; -using BeWo.Service.ServiceContracts; -using BS.Shared; -using BS.Shared.Core; -using BS.Shared.DataContracts; -using BS.Shared.DataContracts.Compact; -using BS.Shared.Extensions; - -namespace BeWo.Service.Plugins -{ - public class AccountingService : AbstractIDSpecificDefaultClass - { - public virtual List GenerateInitialServiceInvoices(long costBearerOid, long? supportConceptOid, DateTimeSpan invoicePeriod) - { - var cs = PluginLoader.FindClass(); - IEnumerable 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(costBearerOid); - String tenant = PluginLoader.Tenant; - var factory = PluginLoader.FindClass(cb.ID); - if (factory == null) - { - factory = InvoiceFactory.GetInstance(cb.ID, tenant); - } - - var creator = factory.CreateInvoiceCreator(cb.ID, tenant, supportConcepts2ServiceRecords); +using System; +using System.Collections.Generic; +using System.Linq; +using System.ServiceModel; +using BeWo.Data.Access; +using BeWo.Data.Entities; +using BeWo.Data.Models; +using BeWo.Data.Security; +using BeWo.Service.Configuration; +using BeWo.Service.Core; +using BeWo.Service.DCEntityMapper; +using BeWo.Service.Invoicing; +using BeWo.Service.ServiceContracts; +using BS.Shared; +using BS.Shared.Core; +using BS.Shared.DataContracts; +using BS.Shared.DataContracts.Compact; +using BS.Shared.Extensions; + +namespace BeWo.Service.Plugins +{ + public class AccountingService : AbstractIDSpecificDefaultClass + { + public virtual List GenerateInitialServiceInvoices(long costBearerOid, long? supportConceptOid, DateTimeSpan invoicePeriod) + { + var cs = PluginLoader.FindClass(); + IEnumerable 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(costBearerOid); + String tenant = PluginLoader.Tenant; + var factory = PluginLoader.FindClass(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; - } - - protected virtual List ErstelleNeueRechnungen(List differenzRechnungChecks) - { - var rechnungen = new List(); - foreach (var item in differenzRechnungChecks) - { - if (item.VorhandeneRechungen.Count == 0) - { - item.NeueRechnung.InvoiceBase.NeuErstellen = true; - rechnungen.Add(item.NeueRechnung); - } - else - { - rechnungen.Add(ErstelleDifferenzRechnung(item)); - } - } - - return rechnungen; - } - - protected virtual ServiceInvoiceDC ErstelleDifferenzRechnung(DifferenzRechnungCheck item) - { - ServiceInvoiceDC diffRechnung = null; - var alterBetrag = item.VorhandeneRechungen.Sum(i => i.ClaimSum ?? 0); - - if (item.NeueRechnung.ClaimSum == alterBetrag) - { - diffRechnung = item.NeueRechnung; - diffRechnung.InvoiceBase.NeuErstellen = false; - diffRechnung.InvoiceBase.Hinweise = String.Format("Rechnung wurde bereits erstellt"); - } - else - { - diffRechnung = new ServiceInvoiceDC(); - diffRechnung.OriginalZurDifferenz = item.NeueRechnung; - diffRechnung.InvoiceBase = new InvoiceBaseDC(); - CopyInvoiceBaseDC(item.NeueRechnung.InvoiceBase, diffRechnung); - - var newItem = new InvoiceItemDC(); - newItem.ItemPeriodStart = item.NeueRechnung.InvoiceBase.AccountingPeriodStart; - newItem.ItemPeriodEnd = item.NeueRechnung.InvoiceBase.AccountingPeriodEnd; - newItem.UnitCount = 1; - newItem.AmountPerUnit = item.NeueRechnung.ClaimSum - alterBetrag; - newItem.AmountTotal = newItem.AmountPerUnit; - newItem.GrossAmountTotal = newItem.AmountTotal; - newItem.ItemDescription = String.Format("Rechnungsdifferenz zu Rechnung {0} in Höhe von {1:c}", item.VorhandeneRechungen[0].InvoiceBase.InvoiceNumber, alterBetrag); - diffRechnung.InvoiceBase.Hinweise = String.Format("Rechnungsdifferenz zu Rechnung {0} in Höhe von {1:c}", item.VorhandeneRechungen[0].InvoiceBase.InvoiceNumber, alterBetrag); - - var newSip = new ServiceInvoicePeriodDC(); - newSip.Claim = newItem.AmountTotal; - newSip.Start = item.NeueRechnung.InvoiceBase.AccountingPeriodStart; - newSip.End = item.NeueRechnung.InvoiceBase.AccountingPeriodEnd; - diffRechnung.ServiceInvoicePeriods = new List(); - diffRechnung.ServiceInvoicePeriods.Add(newSip); - newSip.InvoiceItems = new List(); - newSip.InvoiceItems.Add(newItem); - } - return diffRechnung; - } - - protected virtual List GetNewInvoices(List invoices, DateTime? start, DateTime? end) - { - List result = new List(); - var existingInvoices = DAOFactory.SearchDAO.GetInvoiceBases(start, end, false); - - foreach (var si in invoices) - { - var checkResult = new DifferenzRechnungCheck(); - result.Add(checkResult); - checkResult.NeueRechnung = si; - checkResult.VorhandeneRechungen = new List(); - - foreach (var i2 in existingInvoices.Where(i => i.Type == InvoiceType.Service)) - { - if (si.InvoiceBase.SupportConceptCostBearerRelDc != null && si.InvoiceBase.SupportConceptCostBearerRelDc.CostBearer2SupportConceptOid == i2.CostBearer2SupportConceptOid) - { - var siAlt = DAOFactory.SearchDAO.GetServiceInvoiceByInvoiceBaseOid(i2.Oid.Value); - var siDCAlt = MapperFactory.ServiceInvoiceDC_ServiceInvoice.MapToNewDC(siAlt); - - //InvoiceItems vergleichen? - //foreach (var sip in si.ServiceInvoicePeriods) - //{ - // foreach (var ii in sip.InvoiceItems) - // { - // typNeu = ii.ItemDescription; - // } - //} - - //foreach (var sip in siAlt.ServiceInvoicePeriodList) - //{ - // foreach (var ii in sip.InvoiceItemList) - // { - // typAlt = ii.ItemDescription; - // } - //} - - //if (typAlt == typNeu) - //{ - // exist = true; - //} - - checkResult.VorhandeneRechungen.Add(siDCAlt); - } - } - } - return result; - } - - public virtual List UpdateServiceInvoices(List invoices) - { - //if (!Data.Security.UserRightHelper.LoggedInUserHasRight(UserRightType.AccountingTransactionView_Create)) - //{ - // throw new FaultException(new BeWoFault("Du kommst hier nicht rein!", BeWoFaultType.CustomWithoutDetails)); - //} - var originals = DAOFactory.GenericDAO.LoadByIDs(invoices.Select(i => i.ServiceInvoiceOid.Value)); - MapperFactory.ServiceInvoiceDC_ServiceInvoice.MergeWithEntitys(invoices, originals); - DAOFactory.GenericDAO.Update(originals); - return originals.Select(e => e.Version.Value).ToList(); - } - - public virtual List GetInvoiceBases(DateTime? startDate, DateTime? endDate) - { - DateTime? end = endDate; - if (end.HasValue) - { - end = end.Value.Date.AddDays(1).AddTicks(-1); - } - var list = DAOFactory.SearchDAO.GetInvoiceBases(startDate, end); - - return MapperFactory.InvoiceBaseDC_InvoiceBase.MapToNewDCs(list); - } - - public virtual List GetInvoiceBases(DateTime? startDate, DateTime? endDate, bool filterByInvoiceDate) - { - DateTime? end = endDate; - if (end.HasValue) - { - end = end.Value.Date.AddDays(1).AddTicks(-1); - } - var list = DAOFactory.SearchDAO.GetInvoiceBases(startDate, end, filterByInvoiceDate); - - return MapperFactory.InvoiceBaseDC_InvoiceBase.MapToNewDCs(list); + + //Prüfe ob Rechnungen neu sind oder Diff vorhanden + var differenzRechnungChecks = GetNewInvoices(newInvoices, invoicePeriod?.StartDate, invoicePeriod?.EndDate); + var resultList = ErstelleNeueRechnungen(differenzRechnungChecks); + + + return resultList; + } + + protected virtual List ErstelleNeueRechnungen(List differenzRechnungChecks) + { + var rechnungen = new List(); + foreach (var item in differenzRechnungChecks) + { + if (item.VorhandeneRechungen.Count == 0) + { + item.NeueRechnung.InvoiceBase.NeuErstellen = true; + rechnungen.Add(item.NeueRechnung); + } + else + { + rechnungen.Add(ErstelleDifferenzRechnung(item)); + } + } + + return rechnungen; + } + + protected virtual ServiceInvoiceDC ErstelleDifferenzRechnung(DifferenzRechnungCheck item) + { + ServiceInvoiceDC diffRechnung = null; + var alterBetrag = item.VorhandeneRechungen.Sum(i => i.ClaimSum ?? 0); + + if (item.NeueRechnung.ClaimSum == alterBetrag) + { + diffRechnung = item.NeueRechnung; + diffRechnung.InvoiceBase.NeuErstellen = false; + diffRechnung.InvoiceBase.Hinweise = String.Format("Rechnung wurde bereits erstellt"); + } + else + { + diffRechnung = new ServiceInvoiceDC(); + diffRechnung.OriginalZurDifferenz = item.NeueRechnung; + diffRechnung.InvoiceBase = new InvoiceBaseDC(); + CopyInvoiceBaseDC(item.NeueRechnung.InvoiceBase, diffRechnung); + + var newItem = new InvoiceItemDC(); + newItem.ItemPeriodStart = item.NeueRechnung.InvoiceBase.AccountingPeriodStart; + newItem.ItemPeriodEnd = item.NeueRechnung.InvoiceBase.AccountingPeriodEnd; + newItem.UnitCount = 1; + newItem.AmountPerUnit = item.NeueRechnung.ClaimSum - alterBetrag; + newItem.AmountTotal = newItem.AmountPerUnit; + newItem.GrossAmountTotal = newItem.AmountTotal; + newItem.ItemDescription = String.Format("Rechnungsdifferenz zu Rechnung {0} in Höhe von {1:c}", item.VorhandeneRechungen[0].InvoiceBase.InvoiceNumber, alterBetrag); + diffRechnung.InvoiceBase.Hinweise = String.Format("Rechnungsdifferenz zu Rechnung {0} in Höhe von {1:c}", item.VorhandeneRechungen[0].InvoiceBase.InvoiceNumber, alterBetrag); + + var newSip = new ServiceInvoicePeriodDC(); + newSip.Claim = newItem.AmountTotal; + newSip.Start = item.NeueRechnung.InvoiceBase.AccountingPeriodStart; + newSip.End = item.NeueRechnung.InvoiceBase.AccountingPeriodEnd; + diffRechnung.ServiceInvoicePeriods = new List(); + diffRechnung.ServiceInvoicePeriods.Add(newSip); + newSip.InvoiceItems = new List(); + newSip.InvoiceItems.Add(newItem); + } + return diffRechnung; + } + + protected virtual List GetNewInvoices(List invoices, DateTime? start, DateTime? end) + { + List result = new List(); + var existingInvoices = DAOFactory.SearchDAO.GetInvoiceBases(start, end, false); + + foreach (var si in invoices) + { + var checkResult = new DifferenzRechnungCheck(); + result.Add(checkResult); + checkResult.NeueRechnung = si; + checkResult.VorhandeneRechungen = new List(); + + foreach (var i2 in existingInvoices.Where(i => i.Type == InvoiceType.Service)) + { + if (si.InvoiceBase.SupportConceptCostBearerRelDc != null && si.InvoiceBase.SupportConceptCostBearerRelDc.CostBearer2SupportConceptOid == i2.CostBearer2SupportConceptOid) + { + var siAlt = DAOFactory.SearchDAO.GetServiceInvoiceByInvoiceBaseOid(i2.Oid.Value); + var siDCAlt = MapperFactory.ServiceInvoiceDC_ServiceInvoice.MapToNewDC(siAlt); + + //InvoiceItems vergleichen? + //foreach (var sip in si.ServiceInvoicePeriods) + //{ + // foreach (var ii in sip.InvoiceItems) + // { + // typNeu = ii.ItemDescription; + // } + //} + + //foreach (var sip in siAlt.ServiceInvoicePeriodList) + //{ + // foreach (var ii in sip.InvoiceItemList) + // { + // typAlt = ii.ItemDescription; + // } + //} + + //if (typAlt == typNeu) + //{ + // exist = true; + //} + + checkResult.VorhandeneRechungen.Add(siDCAlt); + } + } + } + return result; + } + + public virtual List UpdateServiceInvoices(List invoices) + { + //if (!Data.Security.UserRightHelper.LoggedInUserHasRight(UserRightType.AccountingTransactionView_Create)) + //{ + // throw new FaultException(new BeWoFault("Du kommst hier nicht rein!", BeWoFaultType.CustomWithoutDetails)); + //} + var originals = DAOFactory.GenericDAO.LoadByIDs(invoices.Select(i => i.ServiceInvoiceOid.Value)); + MapperFactory.ServiceInvoiceDC_ServiceInvoice.MergeWithEntitys(invoices, originals); + DAOFactory.GenericDAO.Update(originals); + return originals.Select(e => e.Version.Value).ToList(); + } + + public virtual List GetInvoiceBases(DateTime? startDate, DateTime? endDate) + { + DateTime? end = endDate; + if (end.HasValue) + { + end = end.Value.Date.AddDays(1).AddTicks(-1); + } + var list = DAOFactory.SearchDAO.GetInvoiceBases(startDate, end); + + return MapperFactory.InvoiceBaseDC_InvoiceBase.MapToNewDCs(list); + } + + public virtual List GetInvoiceBases(DateTime? startDate, DateTime? endDate, bool filterByInvoiceDate) + { + DateTime? end = endDate; + if (end.HasValue) + { + end = end.Value.Date.AddDays(1).AddTicks(-1); + } + var list = DAOFactory.SearchDAO.GetInvoiceBases(startDate, end, filterByInvoiceDate); + + return MapperFactory.InvoiceBaseDC_InvoiceBase.MapToNewDCs(list); } public virtual List GetInvoiceBases(DateTime? startDate, DateTime? endDate, long costBearerOid, String invoiceId) @@ -225,369 +228,388 @@ namespace BeWo.Service.Plugins var list = DAOFactory.SearchDAO.GetInvoiceBases(startDate, end, costBearerOid, invoiceId); return MapperFactory.InvoiceBaseDC_InvoiceBase.MapToNewDCs(list); - } - - - public virtual void DeactivateInvoiceBases(List invoices) - { - ServiceLogic.SetActivationType(invoices.ToDictionary(i => i.InvoiceBaseOid.Value, i => i.InvoiceBaseVersion.Value), ActivationTypeId.Deleted); - } - - public virtual void DeactivateServiceInvoices(List invoices) - { - ServiceLogic.SetActivationType(invoices.ToDictionary(i => i.ServiceInvoiceOid.Value, i => i.ServiceInvoiceVersion.Value), ActivationTypeId.Deleted); - ServiceLogic.SetActivationType(invoices.ToDictionary(i => i.InvoiceBase.InvoiceBaseOid.Value, i => i.InvoiceBase.InvoiceBaseVersion.Value), ActivationTypeId.Deleted); - } - - public virtual void StorniereInvoiceBases(List invoices) - { - foreach (var item in invoices) - { - if (item.Type == InvoiceType.Service) - { - ErstelleStornoRechnung(item); - } - else if (item.Type == InvoiceType.Settlement) - { - //ErstelleStornoSpitzabrechnung(item); - } - else - { - ErstelleStornoAllgemeineRechnung(item); - } - } - } - - public virtual InvoiceBase ErstelleStornoAllgemeineRechnung(InvoiceBaseDC ibdc) - { - InvoiceBase newInvoice = new InvoiceBase(); - - var oldInvoice = DAOFactory.GenericDAO.LoadByID(ibdc.InvoiceBaseOid.Value); - - CopyInvoiceBase(oldInvoice, newInvoice); - SetzeStornoInfos(newInvoice); - - return newInvoice; - } - - public virtual ServiceInvoice ErstelleStornoRechnung(InvoiceBaseDC ibdc) - { - ServiceInvoice newInvoice = new ServiceInvoice(); - - var serviceInvoice = DAOFactory.SearchDAO.GetServiceInvoiceByInvoiceBaseOid(ibdc.InvoiceBaseOid.Value); - - CopyServiceInvoice(serviceInvoice, newInvoice); - SetzeStornoInfos(newInvoice); - - return newInvoice; - } - - //public virtual InvoiceBase ErstelleStornoSpitzabrechnung(InvoiceBaseDC ibdc) - //{ - // InvoiceBase newInvoice = new InvoiceBase(); - - // var oldInvoice = DAOFactory.GenericDAO.LoadByID(ibdc.InvoiceBaseOid.Value); - - // CopyInvoiceBase(oldInvoice, newInvoice); - // SetzeStornoInfos(newInvoice); - - // return newInvoice; - //} - - public virtual ServiceInvoice ErstelleStornoRechnung(ServiceInvoiceDC sidc) - { - ServiceInvoice newInvoice = new ServiceInvoice(); - - var serviceInvoice = DAOFactory.GenericDAO.LoadByID(sidc.ServiceInvoiceOid.Value); - - CopyServiceInvoice(serviceInvoice, newInvoice); - SetzeStornoInfos(newInvoice); - - return newInvoice; - } - - public virtual void SaveStornoRechnung(InvoiceBase originalInvoice, ServiceInvoice stornoInvoice) - { - DAOFactory.GenericDAO.Insert(stornoInvoice); - originalInvoice.StornoInvoiceBaseOid = stornoInvoice.Oid; - DAOFactory.GenericDAO.Update(originalInvoice); - - } - - public virtual void SetzeStornoInfos(InvoiceBase newInvoice) - { - foreach (var ii in newInvoice.InvoiceItems) - { - if (ii.AmountTotal.HasValue) - { - ii.AmountTotal *= -1; - } - - if (ii.GrossAmountTotal.HasValue) - { - ii.GrossAmountTotal *= -1; - } - } - } - - public virtual void SetzeStornoInfos(ServiceInvoice newInvoice) - { - foreach (var sip in newInvoice.ServiceInvoicePeriodList) - { - sip.HoursNotBillableAbsence = 0; - sip.HoursNotBillableNotApproved = 0; - if (sip.Claim.HasValue) - { - sip.Claim *= -1; - } - - foreach (var ii in sip.InvoiceItemList) - { - if (ii.AmountTotal.HasValue) - { - ii.AmountTotal *= -1; - } - - if (ii.GrossAmountTotal.HasValue) - { - ii.GrossAmountTotal *= -1; - } - } - } - } - - private void CopyServiceInvoice(ServiceInvoice existingInvoice, ServiceInvoice copyInvoice) - { - copyInvoice.AmountAdvancePayments = existingInvoice.AmountAdvancePayments; - copyInvoice.AmountEquityContribution = existingInvoice.AmountEquityContribution; - copyInvoice.ServiceUnitOid = existingInvoice.ServiceUnitOid; - - - CopyInvoiceBase(existingInvoice.InvoiceBase, copyInvoice.InvoiceBase); - - foreach (var sip in existingInvoice.ServiceInvoicePeriodList) - { - var copySip = new ServiceInvoicePeriod(); - copyInvoice.ServiceInvoicePeriodList.Add(copySip); - - CopyServiceInvoicePeriod(sip, copySip); - } - } - - //private void CopySettlementInvoice(SettlementInvoice existingInvoice, SettlementInvoice copyInvoice) - // { - - // CopyInvoiceBase(existingInvoice.InvoiceBase, copyInvoice.InvoiceBase); - - - // } - - private void CopyInvoiceBase(InvoiceBase existing, InvoiceBase copy) - { - copy.AccountingPeriodEnd = existing.AccountingPeriodEnd; - copy.AccountingPeriodStart = existing.AccountingPeriodStart; - copy.CostBearer2SupportConcept = existing.CostBearer2SupportConcept; - copy.CreatorFirstName = existing.CreatorFirstName; - copy.CreatorLastName = existing.CreatorLastName; - copy.CustomerReferenceNumber = existing.CustomerReferenceNumber; - copy.DueDate = existing.DueDate; - copy.DunningLetterCount = existing.DunningLetterCount; - copy.InvoiceDate = existing.InvoiceDate; - copy.InvoiceId = existing.InvoiceId; - copy.InvoiceNumber = existing.InvoiceNumber; - copy.InvoiceTitle = existing.InvoiceTitle; - copy.InvoiceTypeText = existing.InvoiceTypeText; - copy.IsPaid = existing.IsPaid; - copy.IsPrinted = existing.IsPrinted; - copy.RecipientCostBearerOid = existing.RecipientCostBearerOid; - copy.RecipientCustomerOid = existing.RecipientCustomerOid; - copy.RecipientDivision = existing.RecipientDivision; - copy.RecipientOrganisation = existing.RecipientOrganisation; - copy.RecipientOrganisationOid = existing.RecipientOrganisationOid; - copy.RecipientPersonFirstName = existing.RecipientPersonFirstName; - copy.RecipientPersonLastName = existing.RecipientPersonLastName; - copy.RecipientPersonOid = existing.RecipientPersonOid; - copy.SenderDivision = existing.SenderDivision; - copy.SenderFirstName = existing.SenderFirstName; - copy.SenderLastName = existing.SenderLastName; - copy.SenderOrganisation = existing.SenderOrganisation; - copy.SupportConceptOid = existing.SupportConceptOid; - copy.Type = existing.Type; - copy.XMLData = existing.XMLData; - - foreach (var ii in existing.InvoiceItems) - { - var copyItem = new InvoiceItem(); - copy.InvoiceItems.Add(copyItem); - - CopyInvoiceItem(ii, copyItem); - - } - - if (existing.RecipientAddress != null) - { - copy.RecipientAddress = CreateCopyAddress(existing.RecipientAddress); - } - - if (existing.RecipientContacts != null) - { - copy.RecipientContacts = new List(); - foreach (var existingContact in existing.RecipientContacts) - { - copy.RecipientContacts.Add(CreateCopyContact(existingContact)); - } - } - - if (existing.SenderAddress != null) - { - copy.SenderAddress = existing.SenderAddress; - } - - if (existing.SenderContacts != null) - { - copy.SenderContacts = new List(); - foreach (var existingContact in existing.SenderContacts) - { - copy.SenderContacts.Add(CreateCopyContact(existingContact)); - } - } - - } - - public void CopyInvoiceBaseDC(InvoiceBaseDC orgRechnung, ServiceInvoiceDC diffRechnung) - { - diffRechnung.InvoiceBase.DiffErstellen = true; - diffRechnung.InvoiceBase.AccountingPeriodStart = orgRechnung.AccountingPeriodStart; - diffRechnung.InvoiceBase.AccountingPeriodEnd = orgRechnung.AccountingPeriodEnd; - diffRechnung.InvoiceBase.CustomerLastName = orgRechnung.CustomerLastName; - diffRechnung.InvoiceBase.CustomerFirstName = orgRechnung.CustomerFirstName; - diffRechnung.InvoiceBase.CustomerReferenceNumber = orgRechnung.CustomerReferenceNumber; - diffRechnung.InvoiceBase.InvoiceBaseOid = orgRechnung.InvoiceBaseOid; - diffRechnung.InvoiceBase.InvoiceDate = orgRechnung.InvoiceDate; - diffRechnung.InvoiceBase.InvoiceId = orgRechnung.InvoiceId; - diffRechnung.InvoiceBase.InvoiceNumber = orgRechnung.InvoiceNumber; - diffRechnung.InvoiceBase.InvoiceTitle = orgRechnung.InvoiceTitle; - diffRechnung.InvoiceBase.InvoiceTypeText = orgRechnung.InvoiceTypeText; - diffRechnung.InvoiceBase.RecipientAddressLine1 = orgRechnung.RecipientAddressLine1; - diffRechnung.InvoiceBase.RecipientAddressOid = orgRechnung.RecipientAddressOid; - diffRechnung.InvoiceBase.RecipientAddressVersion = orgRechnung.RecipientAddressVersion; - diffRechnung.InvoiceBase.RecipientContactInformations = orgRechnung.RecipientContactInformations; - diffRechnung.InvoiceBase.RecipientCostBearerOid = orgRechnung.RecipientCostBearerOid; - diffRechnung.InvoiceBase.RecipientCustomerOid = orgRechnung.RecipientCustomerOid; - diffRechnung.InvoiceBase.RecipientDivision = orgRechnung.RecipientDivision; - diffRechnung.InvoiceBase.RecipientOrganisation = orgRechnung.RecipientOrganisation; - diffRechnung.InvoiceBase.RecipientOrganisationOid = orgRechnung.RecipientOrganisationOid; - diffRechnung.InvoiceBase.RecipientPersonFirstName = orgRechnung.RecipientPersonFirstName; - diffRechnung.InvoiceBase.RecipientPersonLastName = orgRechnung.RecipientPersonLastName; - diffRechnung.InvoiceBase.RecipientPersonOid = orgRechnung.RecipientPersonOid; - diffRechnung.InvoiceBase.RecipientPostCode = orgRechnung.RecipientPostCode; - diffRechnung.InvoiceBase.RecipientSalutationAddressField = orgRechnung.RecipientSalutationAddressField; - diffRechnung.InvoiceBase.RecipientStreet = orgRechnung.RecipientStreet; - diffRechnung.InvoiceBase.RecipientTown = orgRechnung.RecipientTown; - diffRechnung.InvoiceBase.SenderAddressOid = orgRechnung.SenderAddressOid; - diffRechnung.InvoiceBase.SenderAddressVersion = orgRechnung.SenderAddressVersion; - diffRechnung.InvoiceBase.SenderContactInformations = orgRechnung.SenderContactInformations; - diffRechnung.InvoiceBase.SenderDivision = orgRechnung.SenderDivision; - diffRechnung.InvoiceBase.SenderFirstName = orgRechnung.SenderFirstName; - diffRechnung.InvoiceBase.SenderLastName = orgRechnung.SenderLastName; - diffRechnung.InvoiceBase.SenderOrganisation = orgRechnung.SenderOrganisation; - diffRechnung.InvoiceBase.SenderPostCode = orgRechnung.SenderPostCode; - diffRechnung.InvoiceBase.SenderStreet = orgRechnung.SenderStreet; - diffRechnung.InvoiceBase.SenderTown = orgRechnung.SenderTown; - diffRechnung.InvoiceBase.SupportConceptCostBearerRelDc = orgRechnung.SupportConceptCostBearerRelDc; - diffRechnung.InvoiceBase.SupportConceptOid = orgRechnung.SupportConceptOid; - diffRechnung.InvoiceBase.TotalAmount = orgRechnung.TotalAmount; - diffRechnung.InvoiceBase.Type = orgRechnung.Type; - } - - private Contact CreateCopyContact(Contact existingContact) - { - Contact newContact = new Contact(); - newContact.Value = existingContact.Value; - newContact.Type = existingContact.Type; - - return newContact; - } - - private Address CreateCopyAddress(Address address) - { - Address newAddress = new Address(); - newAddress.AddressLine1 = address.AddressLine1; - newAddress.AddressLine2 = address.AddressLine2; - newAddress.Country = address.Country; - newAddress.PostalCode = address.PostalCode; - newAddress.State = address.State; - newAddress.Street = address.Street; - newAddress.Town = address.Town; - - return newAddress; - } - - private void CopyServiceInvoicePeriod(ServiceInvoicePeriod existingSip, ServiceInvoicePeriod copySip) - { - copySip.AccountingInterval = existingSip.AccountingInterval; - copySip.ApprovedAmountDefaultHourlyRate = existingSip.ApprovedAmountDefaultHourlyRate; - copySip.ApprovedBE = existingSip.ApprovedBE; - copySip.ApprovedFixedAmount = existingSip.ApprovedFixedAmount; - copySip.ApprovedHours = existingSip.ApprovedHours; - copySip.Claim = existingSip.Claim; - copySip.End = existingSip.End; - copySip.HoursNotBillableAbsence = existingSip.HoursNotBillableAbsence; - copySip.HoursNotBillableNotApproved = existingSip.HoursNotBillableNotApproved; - copySip.ServiceUnitName = existingSip.ServiceUnitName; - copySip.Start = existingSip.Start; - copySip.Notice = existingSip.Notice; - copySip.Customer = existingSip.Customer; - copySip.SupportConceptApprovalPeriod = existingSip.SupportConceptApprovalPeriod; - - foreach (var ii in existingSip.InvoiceItemList) - { - var copyItem = new InvoiceItem(); - copySip.InvoiceItemList.Add(copyItem); - - CopyInvoiceItem(ii, copyItem); - } - - } - - private void CopyInvoiceItem(InvoiceItem existingItem, InvoiceItem copyItem) - { - copyItem.AccountingInterval = existingItem.AccountingInterval; - copyItem.AmountPerUnit = existingItem.AmountPerUnit; - copyItem.AmountTotal = existingItem.AmountTotal; - copyItem.ApprovalUnit = existingItem.AccountingInterval; - copyItem.ApprovedPerUnit = existingItem.ApprovedPerUnit; - copyItem.GrossAmountTotal = existingItem.GrossAmountTotal; - copyItem.ItemDescription = existingItem.ItemDescription; - copyItem.ItemPeriodEnd = existingItem.ItemPeriodEnd; - copyItem.ItemPeriodStart = existingItem.ItemPeriodStart; - copyItem.MaxApprovedAmount = existingItem.MaxApprovedAmount; - copyItem.MaxApprovedUnitCount = existingItem.MaxApprovedUnitCount; - copyItem.RateFactor = existingItem.RateFactor; - copyItem.ReceivedAmount = existingItem.ReceivedAmount; - copyItem.SupportConceptApprovalPeriodOid = existingItem.SupportConceptApprovalPeriodOid; - copyItem.UnitCount = existingItem.UnitCount; - copyItem.UnitDescription = existingItem.UnitDescription; - copyItem.Notice = existingItem.Notice; - copyItem.ServiceRecord = existingItem.ServiceRecord; - } - - public virtual Settlement2DC ErstelleDifferenzSpitzabrechnung(Settlement2DC neueRechnung, Settlement2DC letzteRechnung) - { - var diff = neueRechnung.Claim - letzteRechnung.Claim; - var ii = new InvoiceItemDC(); - - neueRechnung.Claim = diff; - neueRechnung.InvoiceItems = new List(); - neueRechnung.InvoiceItems.Add(ii); - - return neueRechnung; - } - } - - public class DifferenzRechnungCheck - { - public ServiceInvoiceDC NeueRechnung { get; set; } - public IList VorhandeneRechungen { get; set; } - } + } + + + public virtual void DeactivateInvoiceBases(List invoices) + { + ServiceLogic.SetActivationType(invoices.ToDictionary(i => i.InvoiceBaseOid.Value, i => i.InvoiceBaseVersion.Value), ActivationTypeId.Deleted); + } + + public virtual void DeactivateServiceInvoices(List invoices) + { + ServiceLogic.SetActivationType(invoices.ToDictionary(i => i.ServiceInvoiceOid.Value, i => i.ServiceInvoiceVersion.Value), ActivationTypeId.Deleted); + ServiceLogic.SetActivationType(invoices.ToDictionary(i => i.InvoiceBase.InvoiceBaseOid.Value, i => i.InvoiceBase.InvoiceBaseVersion.Value), ActivationTypeId.Deleted); + } + + public virtual void StorniereInvoiceBases(List invoices) + { + foreach (var item in invoices) + { + if (item.Type == InvoiceType.Service) + { + ErstelleStornoRechnung(item); + } + else if (item.Type == InvoiceType.Settlement) + { + //ErstelleStornoSpitzabrechnung(item); + } + else + { + ErstelleStornoAllgemeineRechnung(item); + } + } + } + + public virtual InvoiceBase ErstelleStornoAllgemeineRechnung(InvoiceBaseDC ibdc) + { + InvoiceBase newInvoice = new InvoiceBase(); + + var oldInvoice = DAOFactory.GenericDAO.LoadByID(ibdc.InvoiceBaseOid.Value); + + CopyInvoiceBase(oldInvoice, newInvoice); + SetzeStornoInfos(newInvoice); + + return newInvoice; + } + + public virtual ServiceInvoice ErstelleStornoRechnung(InvoiceBaseDC ibdc) + { + ServiceInvoice newInvoice = new ServiceInvoice(); + + var serviceInvoice = DAOFactory.SearchDAO.GetServiceInvoiceByInvoiceBaseOid(ibdc.InvoiceBaseOid.Value); + + CopyServiceInvoice(serviceInvoice, newInvoice); + SetzeStornoInfos(newInvoice); + + return newInvoice; + } + + //public virtual InvoiceBase ErstelleStornoSpitzabrechnung(InvoiceBaseDC ibdc) + //{ + // InvoiceBase newInvoice = new InvoiceBase(); + + // var oldInvoice = DAOFactory.GenericDAO.LoadByID(ibdc.InvoiceBaseOid.Value); + + // CopyInvoiceBase(oldInvoice, newInvoice); + // SetzeStornoInfos(newInvoice); + + // return newInvoice; + //} + + public virtual ServiceInvoice ErstelleStornoRechnung(ServiceInvoiceDC sidc) + { + ServiceInvoice newInvoice = new ServiceInvoice(); + + var serviceInvoice = DAOFactory.GenericDAO.LoadByID(sidc.ServiceInvoiceOid.Value); + + CopyServiceInvoice(serviceInvoice, newInvoice); + SetzeStornoInfos(newInvoice); + + return newInvoice; + } + + public virtual void SaveStornoRechnung(InvoiceBase originalInvoice, ServiceInvoice stornoInvoice) + { + DAOFactory.GenericDAO.Insert(stornoInvoice); + originalInvoice.StornoInvoiceBaseOid = stornoInvoice.Oid; + DAOFactory.GenericDAO.Update(originalInvoice); + + } + + public virtual void SetzeStornoInfos(InvoiceBase newInvoice) + { + foreach (var ii in newInvoice.InvoiceItems) + { + if (ii.AmountTotal.HasValue) + { + ii.AmountTotal *= -1; + } + + if (ii.GrossAmountTotal.HasValue) + { + ii.GrossAmountTotal *= -1; + } + } + } + + public virtual void SetzeStornoInfos(ServiceInvoice newInvoice) + { + foreach (var sip in newInvoice.ServiceInvoicePeriodList) + { + sip.HoursNotBillableAbsence = 0; + sip.HoursNotBillableNotApproved = 0; + if (sip.Claim.HasValue) + { + sip.Claim *= -1; + } + + foreach (var ii in sip.InvoiceItemList) + { + if (ii.AmountTotal.HasValue) + { + ii.AmountTotal *= -1; + } + + if (ii.GrossAmountTotal.HasValue) + { + ii.GrossAmountTotal *= -1; + } + } + } + } + + private void CopyServiceInvoice(ServiceInvoice existingInvoice, ServiceInvoice copyInvoice) + { + copyInvoice.AmountAdvancePayments = existingInvoice.AmountAdvancePayments; + copyInvoice.AmountEquityContribution = existingInvoice.AmountEquityContribution; + copyInvoice.ServiceUnitOid = existingInvoice.ServiceUnitOid; + + + CopyInvoiceBase(existingInvoice.InvoiceBase, copyInvoice.InvoiceBase); + + foreach (var sip in existingInvoice.ServiceInvoicePeriodList) + { + var copySip = new ServiceInvoicePeriod(); + copyInvoice.ServiceInvoicePeriodList.Add(copySip); + + CopyServiceInvoicePeriod(sip, copySip); + } + } + + //private void CopySettlementInvoice(SettlementInvoice existingInvoice, SettlementInvoice copyInvoice) + // { + + // CopyInvoiceBase(existingInvoice.InvoiceBase, copyInvoice.InvoiceBase); + + + // } + + private void CopyInvoiceBase(InvoiceBase existing, InvoiceBase copy) + { + copy.AccountingPeriodEnd = existing.AccountingPeriodEnd; + copy.AccountingPeriodStart = existing.AccountingPeriodStart; + copy.CostBearer2SupportConcept = existing.CostBearer2SupportConcept; + copy.CreatorFirstName = existing.CreatorFirstName; + copy.CreatorLastName = existing.CreatorLastName; + copy.CustomerReferenceNumber = existing.CustomerReferenceNumber; + copy.DueDate = existing.DueDate; + copy.DunningLetterCount = existing.DunningLetterCount; + copy.InvoiceDate = existing.InvoiceDate; + copy.InvoiceId = existing.InvoiceId; + copy.InvoiceNumber = existing.InvoiceNumber; + copy.InvoiceTitle = existing.InvoiceTitle; + copy.InvoiceTypeText = existing.InvoiceTypeText; + copy.IsPaid = existing.IsPaid; + copy.IsPrinted = existing.IsPrinted; + copy.RecipientCostBearerOid = existing.RecipientCostBearerOid; + copy.RecipientCustomerOid = existing.RecipientCustomerOid; + copy.RecipientDivision = existing.RecipientDivision; + copy.RecipientOrganisation = existing.RecipientOrganisation; + copy.RecipientOrganisationOid = existing.RecipientOrganisationOid; + copy.RecipientPersonFirstName = existing.RecipientPersonFirstName; + copy.RecipientPersonLastName = existing.RecipientPersonLastName; + copy.RecipientPersonOid = existing.RecipientPersonOid; + copy.SenderDivision = existing.SenderDivision; + copy.SenderFirstName = existing.SenderFirstName; + copy.SenderLastName = existing.SenderLastName; + copy.SenderOrganisation = existing.SenderOrganisation; + copy.SupportConceptOid = existing.SupportConceptOid; + copy.Type = existing.Type; + copy.XMLData = existing.XMLData; + + foreach (var ii in existing.InvoiceItems) + { + var copyItem = new InvoiceItem(); + copy.InvoiceItems.Add(copyItem); + + CopyInvoiceItem(ii, copyItem); + + } + + if (existing.RecipientAddress != null) + { + copy.RecipientAddress = CreateCopyAddress(existing.RecipientAddress); + } + + if (existing.RecipientContacts != null) + { + copy.RecipientContacts = new List(); + foreach (var existingContact in existing.RecipientContacts) + { + copy.RecipientContacts.Add(CreateCopyContact(existingContact)); + } + } + + if (existing.SenderAddress != null) + { + copy.SenderAddress = existing.SenderAddress; + } + + if (existing.SenderContacts != null) + { + copy.SenderContacts = new List(); + foreach (var existingContact in existing.SenderContacts) + { + copy.SenderContacts.Add(CreateCopyContact(existingContact)); + } + } + + } + + public void CopyInvoiceBaseDC(InvoiceBaseDC orgRechnung, ServiceInvoiceDC diffRechnung) + { + diffRechnung.InvoiceBase.DiffErstellen = true; + diffRechnung.InvoiceBase.AccountingPeriodStart = orgRechnung.AccountingPeriodStart; + diffRechnung.InvoiceBase.AccountingPeriodEnd = orgRechnung.AccountingPeriodEnd; + diffRechnung.InvoiceBase.CustomerLastName = orgRechnung.CustomerLastName; + diffRechnung.InvoiceBase.CustomerFirstName = orgRechnung.CustomerFirstName; + diffRechnung.InvoiceBase.CustomerReferenceNumber = orgRechnung.CustomerReferenceNumber; + diffRechnung.InvoiceBase.InvoiceBaseOid = orgRechnung.InvoiceBaseOid; + diffRechnung.InvoiceBase.InvoiceDate = orgRechnung.InvoiceDate; + diffRechnung.InvoiceBase.InvoiceId = orgRechnung.InvoiceId; + diffRechnung.InvoiceBase.InvoiceNumber = orgRechnung.InvoiceNumber; + diffRechnung.InvoiceBase.InvoiceTitle = orgRechnung.InvoiceTitle; + diffRechnung.InvoiceBase.InvoiceTypeText = orgRechnung.InvoiceTypeText; + diffRechnung.InvoiceBase.RecipientAddressLine1 = orgRechnung.RecipientAddressLine1; + diffRechnung.InvoiceBase.RecipientAddressOid = orgRechnung.RecipientAddressOid; + diffRechnung.InvoiceBase.RecipientAddressVersion = orgRechnung.RecipientAddressVersion; + diffRechnung.InvoiceBase.RecipientContactInformations = orgRechnung.RecipientContactInformations; + diffRechnung.InvoiceBase.RecipientCostBearerOid = orgRechnung.RecipientCostBearerOid; + diffRechnung.InvoiceBase.RecipientCustomerOid = orgRechnung.RecipientCustomerOid; + diffRechnung.InvoiceBase.RecipientDivision = orgRechnung.RecipientDivision; + diffRechnung.InvoiceBase.RecipientOrganisation = orgRechnung.RecipientOrganisation; + diffRechnung.InvoiceBase.RecipientOrganisationOid = orgRechnung.RecipientOrganisationOid; + diffRechnung.InvoiceBase.RecipientPersonFirstName = orgRechnung.RecipientPersonFirstName; + diffRechnung.InvoiceBase.RecipientPersonLastName = orgRechnung.RecipientPersonLastName; + diffRechnung.InvoiceBase.RecipientPersonOid = orgRechnung.RecipientPersonOid; + diffRechnung.InvoiceBase.RecipientPostCode = orgRechnung.RecipientPostCode; + diffRechnung.InvoiceBase.RecipientSalutationAddressField = orgRechnung.RecipientSalutationAddressField; + diffRechnung.InvoiceBase.RecipientStreet = orgRechnung.RecipientStreet; + diffRechnung.InvoiceBase.RecipientTown = orgRechnung.RecipientTown; + diffRechnung.InvoiceBase.SenderAddressOid = orgRechnung.SenderAddressOid; + diffRechnung.InvoiceBase.SenderAddressVersion = orgRechnung.SenderAddressVersion; + diffRechnung.InvoiceBase.SenderContactInformations = orgRechnung.SenderContactInformations; + diffRechnung.InvoiceBase.SenderDivision = orgRechnung.SenderDivision; + diffRechnung.InvoiceBase.SenderFirstName = orgRechnung.SenderFirstName; + diffRechnung.InvoiceBase.SenderLastName = orgRechnung.SenderLastName; + diffRechnung.InvoiceBase.SenderOrganisation = orgRechnung.SenderOrganisation; + diffRechnung.InvoiceBase.SenderPostCode = orgRechnung.SenderPostCode; + diffRechnung.InvoiceBase.SenderStreet = orgRechnung.SenderStreet; + diffRechnung.InvoiceBase.SenderTown = orgRechnung.SenderTown; + diffRechnung.InvoiceBase.SupportConceptCostBearerRelDc = orgRechnung.SupportConceptCostBearerRelDc; + diffRechnung.InvoiceBase.SupportConceptOid = orgRechnung.SupportConceptOid; + diffRechnung.InvoiceBase.TotalAmount = orgRechnung.TotalAmount; + diffRechnung.InvoiceBase.Type = orgRechnung.Type; + } + + private Contact CreateCopyContact(Contact existingContact) + { + Contact newContact = new Contact(); + newContact.Value = existingContact.Value; + newContact.Type = existingContact.Type; + + return newContact; + } + + private Address CreateCopyAddress(Address address) + { + Address newAddress = new Address(); + newAddress.AddressLine1 = address.AddressLine1; + newAddress.AddressLine2 = address.AddressLine2; + newAddress.Country = address.Country; + newAddress.PostalCode = address.PostalCode; + newAddress.State = address.State; + newAddress.Street = address.Street; + newAddress.Town = address.Town; + + return newAddress; + } + + private void CopyServiceInvoicePeriod(ServiceInvoicePeriod existingSip, ServiceInvoicePeriod copySip) + { + copySip.AccountingInterval = existingSip.AccountingInterval; + copySip.ApprovedAmountDefaultHourlyRate = existingSip.ApprovedAmountDefaultHourlyRate; + copySip.ApprovedBE = existingSip.ApprovedBE; + copySip.ApprovedFixedAmount = existingSip.ApprovedFixedAmount; + copySip.ApprovedHours = existingSip.ApprovedHours; + copySip.Claim = existingSip.Claim; + copySip.End = existingSip.End; + copySip.HoursNotBillableAbsence = existingSip.HoursNotBillableAbsence; + copySip.HoursNotBillableNotApproved = existingSip.HoursNotBillableNotApproved; + copySip.ServiceUnitName = existingSip.ServiceUnitName; + copySip.Start = existingSip.Start; + copySip.Notice = existingSip.Notice; + copySip.Customer = existingSip.Customer; + copySip.SupportConceptApprovalPeriod = existingSip.SupportConceptApprovalPeriod; + + foreach (var ii in existingSip.InvoiceItemList) + { + var copyItem = new InvoiceItem(); + copySip.InvoiceItemList.Add(copyItem); + + CopyInvoiceItem(ii, copyItem); + } + + } + + private void CopyInvoiceItem(InvoiceItem existingItem, InvoiceItem copyItem) + { + copyItem.AccountingInterval = existingItem.AccountingInterval; + copyItem.AmountPerUnit = existingItem.AmountPerUnit; + copyItem.AmountTotal = existingItem.AmountTotal; + copyItem.ApprovalUnit = existingItem.AccountingInterval; + copyItem.ApprovedPerUnit = existingItem.ApprovedPerUnit; + copyItem.GrossAmountTotal = existingItem.GrossAmountTotal; + copyItem.ItemDescription = existingItem.ItemDescription; + copyItem.ItemPeriodEnd = existingItem.ItemPeriodEnd; + copyItem.ItemPeriodStart = existingItem.ItemPeriodStart; + copyItem.MaxApprovedAmount = existingItem.MaxApprovedAmount; + copyItem.MaxApprovedUnitCount = existingItem.MaxApprovedUnitCount; + copyItem.RateFactor = existingItem.RateFactor; + copyItem.ReceivedAmount = existingItem.ReceivedAmount; + copyItem.SupportConceptApprovalPeriodOid = existingItem.SupportConceptApprovalPeriodOid; + copyItem.UnitCount = existingItem.UnitCount; + copyItem.UnitDescription = existingItem.UnitDescription; + copyItem.Notice = existingItem.Notice; + copyItem.ServiceRecord = existingItem.ServiceRecord; + } + + public virtual Settlement2DC ErstelleDifferenzSpitzabrechnung(Settlement2DC neueRechnung, Settlement2DC letzteRechnung) + { + var diff = neueRechnung.Claim - letzteRechnung.Claim; + var ii = new InvoiceItemDC(); + + neueRechnung.Claim = diff; + neueRechnung.InvoiceItems = new List(); + neueRechnung.InvoiceItems.Add(ii); + + return neueRechnung; + } + + public virtual AddressInformation GetAddressInformation(long? customer_oid = null) + { + var user = UserRightHelper.GetLoggedInUser().Employee; + var mandator = AppSettings.GetMandatorEntity(); + + return new AddressInformation() + { + IKLeistungserbringer = mandator.IKLeistungserbringer, + Fax = user.Person.Contacts.FirstOrDefault(x => x.Type == ContactType.business_Fax)?.Value.ToNullIfEmpty(), + Mail = user.Person.Contacts.FirstOrDefault(x => x.Type == ContactType.business_Mail)?.Value.ToNullIfEmpty(), + Phone = user.Person.Contacts.FirstOrDefault(x => x.Type == ContactType.business_Phone)?.Value.ToNullIfEmpty(), + OrganisationName = mandator.Name, + PostCode = mandator.PostalCode, + Street = mandator.Street, + Town = mandator.Town, + Website = mandator.Website + }; + } + } + + public class DifferenzRechnungCheck + { + public ServiceInvoiceDC NeueRechnung { get; set; } + public IList VorhandeneRechungen { get; set; } + } } \ No newline at end of file diff --git a/Service/ServiceImplementations/AccountingServiceImp.cs b/Service/ServiceImplementations/AccountingServiceImp.cs index c0888801f..9e4daf50f 100644 --- a/Service/ServiceImplementations/AccountingServiceImp.cs +++ b/Service/ServiceImplementations/AccountingServiceImp.cs @@ -27,6 +27,7 @@ using BS.Shared.DataContracts.GkvAbrechnung; using BS.Shared.Extensions; using BS.Shared.Exceptions; using BS.Shared.AppSender; +using BeWo.Data.Security; namespace BeWo.Service.ServiceImplementations { @@ -1048,6 +1049,23 @@ namespace BeWo.Service.ServiceImplementations protokoll.Datenaustauschreferenz = datenaustauschreferenz; protokoll.Transfernummer = transfernummer; + var first_cost = gkvAbrechnung.InvoiceBases.First().CostBearer2SupportConcept.SupportConcept.Customer; + + var plugin = PluginLoader.FindClass(); + var addressInfo = plugin.GetAddressInformation(first_cost.Oid); + + foreach (var invoicebase in gkvAbrechnung.InvoiceBases) + { + var customer = invoicebase.CostBearer2SupportConcept.SupportConcept.Customer; + + var addressInfo2 = plugin.GetAddressInformation(customer.Oid); + + if (addressInfo.IKLeistungserbringer != addressInfo2.IKLeistungserbringer) + { + throw new GkvException($"Klient '{first_cost.Person.LastNameFirstName}' ({addressInfo.IKLeistungserbringer}) und '{customer.Person.LastNameFirstName}' ({addressInfo2.IKLeistungserbringer}) verweisen auf unterschiedliche Leistungserbringer."); + } + } + foreach (var invoicebase in gkvAbrechnung.InvoiceBases) { var service = DAOFactory.SearchDAO.GetServiceInvoiceByInvoiceBaseOid(invoicebase.Oid.Value); @@ -1061,7 +1079,7 @@ namespace BeWo.Service.ServiceImplementations Validator.ValidateCustomer(customerdc); - manager.Add(servicedc, orgadc, customerdc, mandatordc, dat_short, tra_short); + manager.Add(servicedc, orgadc, customerdc, addressInfo, dat_short, tra_short); } manager.Apply(); @@ -1070,8 +1088,6 @@ namespace BeWo.Service.ServiceImplementations { var msg = "Unerwartete Anzahl an Dakota Files berechnet."; - MailUtils.SendGkvModuleErrorMail("CreateGkvTransferProtokoll", msg, Tenant); - throw new GkvException(msg); } @@ -1096,8 +1112,6 @@ namespace BeWo.Service.ServiceImplementations { var msg = $"nutzdatendatei - Länger als 16777215: {nutzdatendatei.Length}"; - MailUtils.SendGkvModuleErrorMail("CreateGkvTransferProtokoll", msg, Tenant); - throw new GkvException(msg); }