diff --git a/database/seeders/CompaniesTableSeeder.php b/database/seeders/CompaniesTableSeeder.php index f0050016..6e50c868 100644 --- a/database/seeders/CompaniesTableSeeder.php +++ b/database/seeders/CompaniesTableSeeder.php @@ -25,6 +25,7 @@ use App\Models\OldCompany; use Illuminate\Database\Seeder; use App\Models\Company; +use Illuminate\Support\Facades\App; class CompaniesTableSeeder extends Seeder { @@ -167,65 +168,69 @@ class CompaniesTableSeeder extends Seeder } - $companies = OldCompany::all(); + if(App::environment(['production'])){ + $companies = OldCompany::all(); - foreach($companies as $company){ + foreach($companies as $company){ - $marking = explode("CIEF/", $company->marking); - if(count($marking) < 2){ - continue; - } - - /** @var Company $newCompany */ - $newCompany = $this->createCompanyProcessor->execute($company->name, CompanyType::COMPANY_BUSINESS, ApprovalStatus::PENDING_SUBMISSION); - - $this->updatesCompanyStatus->execute($newCompany, ApprovalStatus::APPROVED); - - /** @var CompanyModule $companyModule */ - $companyModule = $this->createCompanyModuleProcessor->execute($newCompany, BusinessType::IMPORTER); - - $connectionObject = new CompanyConnectionObject($companyModule, 'CIEF', $marking[1]); - - $connection = $this->createsCompanyConnection->execute($connectionObject); - $this->approvesCompanyConnection->execute($connection); - - $i = 0; - foreach($company->addresses as $address){ - if($address->street_one === '' && $address->street_two === ''){ + $marking = explode("CIEF/", $company->marking); + if(count($marking) < 2){ continue; } - if(!$address->post_code){ - continue; - } + /** @var Company $newCompany */ + $newCompany = $this->createCompanyProcessor->execute($company->name, CompanyType::COMPANY_BUSINESS, ApprovalStatus::PENDING_SUBMISSION); - $district = District::where('postcode', 'like', '%'. $address->post_code .'%')->first(); + $this->updatesCompanyStatus->execute($newCompany, ApprovalStatus::APPROVED); - if(!$district) { - continue; - } + /** @var CompanyModule $companyModule */ + $companyModule = $this->createCompanyModuleProcessor->execute($newCompany, BusinessType::IMPORTER); - $street_one = str_replace($district->state->name, '',str_replace($district->name, '', $address->street_one)); - $street_two = str_replace($district->state->name, '',str_replace($district->name, '', $address->street_two)); + $connectionObject = new CompanyConnectionObject($companyModule, 'CIEF', $marking[1]); - $object = new AddressObject(str_replace(', ,', ',', str_replace(', ,', ',', $street_one)), str_replace(', ,', ',', str_replace(', ,', ',', $street_two)), $district->country_id, $district->state_id, $district->id, $address->post_code, 'Business Address'); - $this->createsAddress->execute($companyModule, $object); + $connection = $this->createsCompanyConnection->execute($connectionObject); + $this->approvesCompanyConnection->execute($connection); - $contact = preg_replace("/[^0-9.]/", "", $address->contact); - if($contact){ - $i++; - if($i === 1) { - $contactObject = new ContactObject('', $contact, $company->email, '',); - $this->createContactProcessor->execute($contactObject, $newCompany); + $i = 0; + foreach($company->addresses as $address){ + if($address->street_one === '' && $address->street_two === ''){ + continue; } + + if(!$address->post_code){ + continue; + } + + $district = District::where('postcode', 'like', '%'. $address->post_code .'%')->first(); + + if(!$district) { + continue; + } + + $street_one = str_replace($district->state->name, '',str_replace($district->name, '', $address->street_one)); + $street_two = str_replace($district->state->name, '',str_replace($district->name, '', $address->street_two)); + + $object = new AddressObject(str_replace(', ,', ',', str_replace(', ,', ',', $street_one)), str_replace(', ,', ',', str_replace(', ,', ',', $street_two)), $district->country_id, $district->state_id, $district->id, $address->post_code, 'Business Address'); + $this->createsAddress->execute($companyModule, $object); + + $contact = preg_replace("/[^0-9.]/", "", $address->contact); + if($contact){ + $i++; + if($i === 1) { + $contactObject = new ContactObject('', $contact, $company->email, '',); + $this->createContactProcessor->execute($contactObject, $newCompany); + } + } + + } + } - - - } + + } private function cleanAddress($address){