From 6e65ed446835e79255fcf8ff19f0a06ed69a6a1c Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Mon, 24 Nov 2025 18:48:13 +0100 Subject: [PATCH] lookup nip - migration --- .../einvoice/KSeFAdapter.java | 38 +++++++ .../src/test/resources/ksef/ksef-test04.xml | 105 ++++++++++++++++++ workflow/pl/e-invoice/templates/ksef.xml | 12 +- 3 files changed, 146 insertions(+), 9 deletions(-) create mode 100644 office-alexander-logistics-app/src/test/resources/ksef/ksef-test04.xml diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/einvoice/KSeFAdapter.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/einvoice/KSeFAdapter.java index d700733..12842c3 100644 --- a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/einvoice/KSeFAdapter.java +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/einvoice/KSeFAdapter.java @@ -52,6 +52,12 @@ import jakarta.inject.Inject; * * *

+ * NIP: The adapter needs the NIP (vat-id). If we do not find the partner.vat in + * the business object, we do a lookup on the D-Cargosoft object and try the vat + * id from there. This is because the partner.vat is a field which was not + * defined before. + * + *

* Wenn Debug = true gibt der Adapter alle einzelschritte auf der console aus * und erzeugt zusätzlich die factur-x xml und txt dateien. * @@ -202,6 +208,38 @@ public class KSeFAdapter implements SignalAdapter { throw new PluginException(this.getClass().getName(), DOCUMENT_ERROR, "Business Partner ID '" + partnerID + "' does not exist"); } + + /** + * Migration: + * If the business partner does not yet have the item "partner.vat" we try here + * to resync this information from the cargosoftkreditor object. This is needed + * because the partner.vat was not initially defined by the synch processor and + * so many partner objects do not yet provide this information. + */ + if (businessPartner.getItemValueString("partner.vat").isEmpty()) { + logger.info("│ ├── BusinessPartner " + partnerID + " does not provide vat-id - try to migrate...."); + String dNumber = businessPartner.getItemValueString("dbtr.number"); + if (!dNumber.isEmpty()) { + try { + String query = "(type:cargosoftkreditor) AND (name:" + dNumber + ")"; + List result; + result = documentService.find(query, 1, 0); + if (result != null && result.size() > 0) { + ItemCollection creditorData = result.get(0); + String vatID = creditorData.getItemValueString("_vendor_vat_registration_id"); + logger.info("│ ├── synchronize VAT Registrytion ID: " + vatID); + // update business partner + businessPartner.setItemValue("partner.vat", vatID); + documentService.saveByNewTransaction(businessPartner); + } + } catch (Exception e) { + // should not happen! + logger.info("│ ├── ⚠️ Failed to sync BusinessPartner : " + e.getMessage()); + + } + } + } + TradeParty tradeParty = new TradeParty(type); // Name ist immer die erste Zeile diff --git a/office-alexander-logistics-app/src/test/resources/ksef/ksef-test04.xml b/office-alexander-logistics-app/src/test/resources/ksef/ksef-test04.xml new file mode 100644 index 0000000..de58cca --- /dev/null +++ b/office-alexander-logistics-app/src/test/resources/ksef/ksef-test04.xml @@ -0,0 +1,105 @@ + + + + FA + 3 + 2025-11-24T18:45:31.387561092Z + Imixs eInvoice + + + + + 9552521552 + Alexander Global Logistics + + + PL + Gdanska 36 + 70-660 Szczecin + + + MBudas@alexander-logistics.com + + + + + + + + + 6621004747 + REGESTA Spolka Akcyjna + + + PL + ul. Nowowiejska 52a + 28-400 Pinczow + + + D15231 + 2 + + 2 + + + + + EUR + 2024-04-03 + + 216525 + + 2024-06-02 + + + 4128.00 + + 0.00 + + 4128.00 + + + + 2 + + 2 + + 2 + + 2 + + + 1 + + + + 1 + + + 2 + + + 1 + + + + VAT + + + 1 + 8a8458dc-5b4f-462c-a964-8848d089a0f9 + R IM-ZEL-2403-259 + szt. + 1 + 4128.00 + 4128.00 + + + \ No newline at end of file diff --git a/workflow/pl/e-invoice/templates/ksef.xml b/workflow/pl/e-invoice/templates/ksef.xml index d824f3e..aef19a5 100644 --- a/workflow/pl/e-invoice/templates/ksef.xml +++ b/workflow/pl/e-invoice/templates/ksef.xml @@ -32,8 +32,7 @@ - - #Customer Name# + @@ -59,16 +58,11 @@ - - - - 0.00 0.00 0.00 - 2 @@ -100,11 +94,11 @@ 1 - + VAT - + \ No newline at end of file