From 989f5c9210dd0669d248b078f652b178ed777ad9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 24 Mar 2022 19:55:57 +1100 Subject: [PATCH] Refactor client country assignment --- app/Factory/ClientFactory.php | 2 +- app/Repositories/ClientRepository.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Factory/ClientFactory.php b/app/Factory/ClientFactory.php index 35b600618c87..b27d0101a9c2 100644 --- a/app/Factory/ClientFactory.php +++ b/app/Factory/ClientFactory.php @@ -28,7 +28,7 @@ class ClientFactory $client->public_notes = ''; $client->balance = 0; $client->paid_to_date = 0; - $client->country_id = 840; + $client->country_id = null; $client->is_deleted = 0; $client->client_hash = Str::random(40); $client->settings = ClientSettings::defaults(); diff --git a/app/Repositories/ClientRepository.php b/app/Repositories/ClientRepository.php index cd2bd9bff13d..811b43edaacf 100644 --- a/app/Repositories/ClientRepository.php +++ b/app/Repositories/ClientRepository.php @@ -58,11 +58,11 @@ class ClientRepository extends BaseRepository return $client; } - if(!$client->id && auth()->user() && auth()->user()->company() && (!array_key_exists('country_id', $data) || empty($data['country_id']))){ - $data['country_id'] = auth()->user()->company()->settings->country_id; - } - $client->fill($data); + + if(!$client->country_id) + $client->country_id = auth()->user()->company()->settings->country_id; + $client->save(); if (!isset($client->number) || empty($client->number) || strlen($client->number) == 0) {