From 0f55bbc362c967b4edc5d2077d6f78455752d337 Mon Sep 17 00:00:00 2001
From: Henning Leutz <leutz@pcsg.de>
Date: Tue, 10 Sep 2024 05:27:18 +0200
Subject: [PATCH] fix: check customer data for customer init

---
 src/QUI/ERP/Accounting/Invoice/InvoiceTemporary.php | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/QUI/ERP/Accounting/Invoice/InvoiceTemporary.php b/src/QUI/ERP/Accounting/Invoice/InvoiceTemporary.php
index 0bef586..752d76c 100644
--- a/src/QUI/ERP/Accounting/Invoice/InvoiceTemporary.php
+++ b/src/QUI/ERP/Accounting/Invoice/InvoiceTemporary.php
@@ -239,7 +239,17 @@ public function __construct($id, Handler $Handler)
 
         $this->setAttributes($data);
 
-        if (!$this->getCustomer()) {
+        if ((!$this->getCustomer() || $this->getCustomer() === null) && !empty($data['customer_data'])) {
+            $customer = json_decode($data['customer_data'], true);
+
+            if (!empty($customer['uuid'])) {
+                $this->setAttribute('customer_id', $customer['uuid']);
+            } elseif (!empty($customer['id'])) {
+                $this->setAttribute('customer_id', $customer['id']);
+            }
+        }
+
+        if (!$this->getCustomer() || $this->getCustomer() === null) {
             $this->setAttribute('invoice_address', false);
             $this->setAttribute('customer_id', false);
         } else {
-- 
GitLab