From 4af753230f0f8cc2f5d0ba604853ec670d2a0f3c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 7 Jan 2023 02:52:59 +1100 Subject: [PATCH] Force primary contact on importing of client --- app/Jobs/Import/CSVIngest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/Jobs/Import/CSVIngest.php b/app/Jobs/Import/CSVIngest.php index 95085ce8682b..b4a264dd323e 100644 --- a/app/Jobs/Import/CSVIngest.php +++ b/app/Jobs/Import/CSVIngest.php @@ -106,6 +106,24 @@ class CSVIngest implements ShouldQueue $new_contact->is_primary = true; $new_contact->save(); } + + Client::with('contacts')->where('company_id', $this->company->id)->cursor()->each(function ($client){ + + $contact = $client->contacts()->first(); + $contact->is_primary = true; + $contact->save(); + + }); + + Vendor::with('contacts')->where('company_id', $this->company->id)->cursor()->each(function ($vendor){ + + $contact = $vendor->contacts()->first(); + $contact->is_primary = true; + $contact->save(); + + }); + + } private function bootEngine()