From 797f70689539add5d9a891f8234a29b29a79cf3d Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Mon, 13 Apr 2026 21:57:37 +0000
Subject: [PATCH] Synchronize client's email & phone
---
src/InvoiceQrCodeSynchronizer.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/src/InvoiceQrCodeSynchronizer.php b/src/InvoiceQrCodeSynchronizer.php
new file mode 100644
index 0000000..4d6ec9d
--- /dev/null
+++ b/src/InvoiceQrCodeSynchronizer.php
@@ -0,0 +1,46 @@
+<?php
+
+namespace SIPL\UCRM\wFirma;
+
+class InvoiceQrCodeSynchronizer {
+ protected UcrmHelper $helper;
+
+ public function __construct(UcrmHelper $helper) {
+ $this->helper = $helper;
+ }
+
+ public function synchronize(string $ucrmInvoiceId, array $previousEntity = []): void {
+ $ksefUrlAttribute = $this->helper->getAttributes()->getIdForCode('ksef-url');
+ $qrCodeGenUrlAttribute = $this->helper->getAttributes()->getIdForCode('qr-code-gen-url');
+
+ $invoice = $this->helper->getApi()->get('/invoices/' . $ucrmInvoiceId);
+ $currentKsefUrl = '';
+ $currentQrCodeGenUrl = '';
+ foreach ($invoice['attributes'] ?? [] as $attribute) {
+ if ($attribute['customAttributeId'] == $ksefUrlAttribute) {
+ $currentKsefUrl = $attribute['value'];
+ }
+ if ($attribute['customAttributeId'] == $qrCodeGenUrlAttribute) {
+ $currentQrCodeGenUrl = $attribute['value'];
+ }
+ }
+
+ $newQrCodeGenUrl = null;
+ $expectedQrCodeGenUrl = $this->helper->getSelfUrl() . '_plugins/wfirma/public.php?barcode=';
+ if ($currentQrCodeGenUrl != $expectedQrCodeGenUrl) {
+ $newQrCodeGenUrl = $expectedQrCodeGenUrl;
+ }
+
+ if ($newQrCodeGenUrl != null) {
+ $this->helper->getApi()->patch('/invoices/' . $ucrmInvoiceId, [
+ 'attributes' => [
+ [
+ 'customAttributeId' => $qrCodeGenUrlAttribute,
+ 'value' => $newQrCodeGenUrl,
+ ],
+ ],
+ ]);
+ $this->helper->getApi()->patch('/invoices/' . $ucrmInvoiceId . '/regenerate-pdf', []);
+ }
+ }
+}
--
Gitblit v1.10.0