diff --git a/BeWo/ViewModel/InvoiceBaseVM.cs b/BeWo/ViewModel/InvoiceBaseVM.cs index 3a6793cd6..6082dafb4 100644 --- a/BeWo/ViewModel/InvoiceBaseVM.cs +++ b/BeWo/ViewModel/InvoiceBaseVM.cs @@ -917,14 +917,14 @@ namespace BeWo.ViewModel get; set; } + public long? Oid => DataContract.InvoiceBaseOid; public string SenderStreet => DataContract.SenderStreet; public string SenderTown => DataContract.SenderTown; public string SenderPostCode => DataContract.SenderPostCode; + public StoredFileDC XRechnungStoredFile => DataContract.XRechnungStoredFile; public IList IInvoiceItems => throw new NotImplementedException(); - public long? Oid => DataContract.InvoiceBaseOid; - protected override void InitByDataContract(InvoiceBaseDC pDataContract) { _SupportConceptOid = pDataContract.SupportConceptOid; diff --git a/Data/Entities/InvoiceBase.cs b/Data/Entities/InvoiceBase.cs index cd108fc75..3ecc0a9ec 100644 --- a/Data/Entities/InvoiceBase.cs +++ b/Data/Entities/InvoiceBase.cs @@ -831,5 +831,7 @@ namespace BeWo.Data.Entities public virtual string SenderTown => SenderAddress?.Town; public virtual string SenderPostCode => SenderAddress?.PostalCode; public virtual IList IInvoiceItems => InvoiceItems.Select(x => x as IInvoiceItem).ToList(); + + public virtual StoredFile XRechnungStoredFile { get; set; } } } \ No newline at end of file diff --git a/Data/Mappings/InvoiceBase.hbm.xml b/Data/Mappings/InvoiceBase.hbm.xml index fdb59889b..0e9d8a347 100644 --- a/Data/Mappings/InvoiceBase.hbm.xml +++ b/Data/Mappings/InvoiceBase.hbm.xml @@ -50,6 +50,7 @@ + diff --git a/Host/Web.config b/Host/Web.config index 1081210ac..e8156bf59 100644 --- a/Host/Web.config +++ b/Host/Web.config @@ -388,9 +388,9 @@ - - - + + + diff --git a/Model/Changes_2025_06_23 InvoiceBase XRechnung StoredFile.txt b/Model/Changes_2025_06_23 InvoiceBase XRechnung StoredFile.txt new file mode 100644 index 000000000..af734e89e --- /dev/null +++ b/Model/Changes_2025_06_23 InvoiceBase XRechnung StoredFile.txt @@ -0,0 +1,10 @@ +ALTER TABLE `invoicebase` +ADD COLUMN `XRechnungStoredFileOid` BIGINT NULL DEFAULT NULL AFTER `StornoInvoiceBaseOid`, +ADD INDEX `FK_IN_SFILE_idx` (`XRechnungStoredFileOid` ASC) VISIBLE; +; +ALTER TABLE `invoicebase` +ADD CONSTRAINT `FK_IN_SFILE` + FOREIGN KEY (`XRechnungStoredFileOid`) + REFERENCES `storedfile` (`Oid`) + ON DELETE CASCADE + ON UPDATE CASCADE; diff --git a/Service/DCEntityMapper/InvoiceBaseDC_InvoiceBase.cs b/Service/DCEntityMapper/InvoiceBaseDC_InvoiceBase.cs index 9d1d2fea5..9de4c8721 100644 --- a/Service/DCEntityMapper/InvoiceBaseDC_InvoiceBase.cs +++ b/Service/DCEntityMapper/InvoiceBaseDC_InvoiceBase.cs @@ -152,7 +152,9 @@ namespace BeWo.Service.DCEntityMapper pDataContract.IsGkvValid = error is null; } - return pDataContract; + pDataContract.XRechnungStoredFile = MapperFactory.StoredFile.CreateOrMapToNewDC(pEntity.XRechnungStoredFile, true); + + return pDataContract; } public override InvoiceBase MergeWithEntity(InvoiceBaseDC pDataContract, InvoiceBase pEntity) diff --git a/Service/DCEntityMapper/MapperFactory.cs b/Service/DCEntityMapper/MapperFactory.cs index 44f7e7199..63e0f477a 100644 --- a/Service/DCEntityMapper/MapperFactory.cs +++ b/Service/DCEntityMapper/MapperFactory.cs @@ -811,5 +811,6 @@ namespace BeWo.Service.DCEntityMapper public static GkvAbrechnungLightDC_GkvAbrechnungLight GkvAbrechnungLight { get; } = new GkvAbrechnungLightDC_GkvAbrechnungLight(); public static GkvTransferProtokollLightDC_GkvTransferprotokollLight GkvTransferprotokollLight { get; } = new GkvTransferProtokollLightDC_GkvTransferprotokollLight(); public static OrganisationLightDC_OrganisationLight OrganisationLight { get; } = new OrganisationLightDC_OrganisationLight(); + public static StoredFileDC_StoredFile StoredFile { get; } = new StoredFileDC_StoredFile(); } } \ No newline at end of file diff --git a/Service/Plugins/XRechnungService.cs b/Service/Plugins/XRechnungService.cs index 57fe9ab08..2943fb33e 100644 --- a/Service/Plugins/XRechnungService.cs +++ b/Service/Plugins/XRechnungService.cs @@ -1,4 +1,5 @@ using BeWo.Data.Access; +using BeWo.Data.Entities; using BeWo.Service.Core; using BeWo.Service.ServiceImplementations; using BeWo.Service.ServiceProxy; @@ -26,27 +27,42 @@ namespace BeWo.Service.Plugins var lStoragePath = MergedConfig.GetSetting(WebConfigSetting.StoredTenantFilesFolderPath); var lStorage = DAOFactory.GetLocalTenantFileStorage(lStoragePath); - var lFileName = lStorage.GetXRechnungFileName(invoice_base_oid); - + var invoice_base = DAOFactory.GenericDAO.LoadByID(invoice_base_oid); + // Falls Lokal vorhanden, gebe lokale Version zurück - if(tryGetXRechnungLocal(lStorage, lFileName, out var bytes)) + if(invoice_base.XRechnungStoredFile?.FileName is string lFileName && tryGetXRechnungLocal(lStorage, lFileName, out var bytes)) return ApiResponse.SuccessResponse(bytes); // Lokal nicht vorhanden, berechne XRechnung var str = ServiceConfigReader.GetInvoiceTestJsonString(); // Erstelle Url ohne weitere Authentifizierung - var download_url = report_url + "&mode=pdf"; - var token_url = new DownloadServiceImp().CreateTemporaryUrl(download_url, false); + var token_url = GetTokenUrl(report_url); - return requestXRechnung(lStorage, lFileName, invoice_base_oid, str, token_url); + return requestXRechnung(lStorage, invoice_base, str, token_url); } - private ApiResponse requestXRechnung(LocalTenantFileStorageDAO pStorage, string pFileName, long invoice_base_oid, object obj, string token_url) + private string GetTokenUrl(string report_url) + { + string download_url; + + if (report_url.IndexOf("localhost") < 0) + download_url = report_url + "&mode=pdf"; + else + download_url = "https://app5.bewoplaner.de/service/ApiStreamService.svc/GetPdf"; + + var token_url = new DownloadServiceImp().CreateTemporaryUrl(download_url, false); + + return token_url; + } + + private ApiResponse requestXRechnung(LocalTenantFileStorageDAO pStorage, InvoiceBase invoice_base, object obj, string token_url) { // Request var response = ServiceFacade.XRechnung.Create(obj, token_url); + var lFileName = pStorage.GetXRechnungFileName(invoice_base.Oid.Value); + if (response.Success) { try @@ -54,9 +70,11 @@ namespace BeWo.Service.Plugins var bytes = response.Data; using (MemoryStream ms = new MemoryStream(bytes)) { - var file = pStorage.SaveHybridFile(BWPFeature.XRechnung, pFileName, "application/pdf", ms, TableID.InvoiceBase, invoice_base_oid); - //var msg = $"Tenant: {lStorage.Tenant}, FilePath: {file.FilePath}"; - //ServiceHelper.CoreLogger.Log(LogLevel.Info, msg, $"{nameof(LocalFileStorageDAO)}.{nameof(lStorage.SaveHybridFile)}"); + var file = pStorage.SaveHybridFile(BWPFeature.XRechnung, lFileName, "application/pdf", ms, TableID.InvoiceBase, invoice_base.Oid.Value); + + invoice_base.XRechnungStoredFile = file; + + DAOFactory.GenericDAO.Update(invoice_base); } } catch (Exception ex) diff --git a/Shared/DataContracts/InvoiceBaseDC.cs b/Shared/DataContracts/InvoiceBaseDC.cs index 5f1aa8d6b..8828404a0 100644 --- a/Shared/DataContracts/InvoiceBaseDC.cs +++ b/Shared/DataContracts/InvoiceBaseDC.cs @@ -75,6 +75,7 @@ namespace BS.Shared.DataContracts [DataMember] public InvoiceType Type { get; set; } [DataMember] public long? StornoInvoiceBaseOid { get; set; } [DataMember] public String BackgroundColor { get; set; } + [DataMember] public StoredFileDC XRechnungStoredFile { get; set; } [DataMember] public List RecipientContactInformations