From 0d1b82e70860d50ba51525e58b6710dbdd94d8dd Mon Sep 17 00:00:00 2001 From: Thomas Hirter <15847494+Memurame@users.noreply.github.com> Date: Fri, 21 Jun 2024 07:40:24 +0200 Subject: [PATCH] fix customer cron with empty address (#122) --- app/Controllers/CronController.php | 6 ++++-- app/Controllers/CustomersController.php | 4 ++-- app/Entities/Customer.php | 2 ++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/Controllers/CronController.php b/app/Controllers/CronController.php index cd4a456..f06d910 100644 --- a/app/Controllers/CronController.php +++ b/app/Controllers/CronController.php @@ -523,8 +523,10 @@ public function abacusSync(){ } $customer->syncWithAbacus(); - - model('CustomerModel')->save($customer); + if($customer->hasChanged()){ + model('CustomerModel')->save($customer); + } + } } } \ No newline at end of file diff --git a/app/Controllers/CustomersController.php b/app/Controllers/CustomersController.php index 9afe61c..5991a9b 100644 --- a/app/Controllers/CustomersController.php +++ b/app/Controllers/CustomersController.php @@ -30,8 +30,8 @@ public function addAbacus($addressnumber){ return redirect()->route("customer.index")->with("msg_error", "Kein Abacus Eintrag zu dieser Nummer gefunden. Erstellen eines Kunden kann nicht ausgeführt werden."); } - $customer = $customerModel->where('addressnumber', $address->abacus)->first(); - if($customer){ + $checkCustomer = $customerModel->where('addressnumber', $address->abacus)->first(); + if($checkCustomer){ return redirect()->route("customer.index")->with("msg_error", "Es existiert bereits ein Kunde mit dieser Adressnumer."); } diff --git a/app/Entities/Customer.php b/app/Entities/Customer.php index 195b13f..db79138 100644 --- a/app/Entities/Customer.php +++ b/app/Entities/Customer.php @@ -95,6 +95,8 @@ public function syncwithAbacus($addressnumber = null){ $address = model('AbaAddressModel') ->where('abacus', $this->addressnumber) ->first(); + if(!$address) return; + $name = $address->lastname; if($address->firstname) $name .= ' ' . $address->firstname;