Refactor client country assignment

This commit is contained in:
David Bomba 2022-03-24 19:55:57 +11:00
parent ce2ad45015
commit 989f5c9210
2 changed files with 5 additions and 5 deletions

View File

@ -28,7 +28,7 @@ class ClientFactory
$client->public_notes = ''; $client->public_notes = '';
$client->balance = 0; $client->balance = 0;
$client->paid_to_date = 0; $client->paid_to_date = 0;
$client->country_id = 840; $client->country_id = null;
$client->is_deleted = 0; $client->is_deleted = 0;
$client->client_hash = Str::random(40); $client->client_hash = Str::random(40);
$client->settings = ClientSettings::defaults(); $client->settings = ClientSettings::defaults();

View File

@ -58,11 +58,11 @@ class ClientRepository extends BaseRepository
return $client; 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); $client->fill($data);
if(!$client->country_id)
$client->country_id = auth()->user()->company()->settings->country_id;
$client->save(); $client->save();
if (!isset($client->number) || empty($client->number) || strlen($client->number) == 0) { if (!isset($client->number) || empty($client->number) || strlen($client->number) == 0) {