Created
February 19, 2020 11:14
-
-
Save cygeorgel/9dc41b82ec738c6375b62abe4cc7d166 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Console\Commands; | |
use App\CustomerContact; | |
use App\Validation; | |
use Illuminate\Console\Command; | |
use Illuminate\Support\Facades\Storage; | |
class Fix10Command extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'fix10:run'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Command description'; | |
/** | |
* Create a new command instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function handle() | |
{ | |
CustomerContact::truncate(); | |
$data = Storage::disk('ftp')->get('routing/file0.csv'); | |
$lines = explode("\n", $data); | |
foreach ($lines as $line) { | |
$values = str_getcsv($line, ',', '"'); | |
if ( ! empty ($values[2])) { | |
$contacts = []; | |
for ($i = 3; $i <= 11; $i++) { | |
if ( ! empty ($values[$i])) { | |
array_push($contacts, phoneNumberFormat($values[$i])); | |
} | |
} | |
CustomerContact::create([ | |
'customerAccount' => 'CL3142', | |
'code' => $values[0], | |
'companyName' => $values[1], | |
'destination1' => $values[2], | |
'contacts' => implode(',', $contacts), | |
]); | |
} | |
} | |
$data = Storage::disk('ftp')->get('routing/file1.csv'); | |
$lines = explode("\n", $data); | |
foreach ($lines as $line) { | |
$values = str_getcsv($line, ',', '"'); | |
if ( ! empty ($values[1])) { | |
$contacts = []; | |
for ($i = 2; $i <= 3; $i++) { | |
if ( ! empty ($values[$i])) { | |
array_push($contacts, phoneNumberFormat($values[$i])); | |
} | |
} | |
$code = '1001'; | |
$destination1 = '6006'; | |
CustomerContact::create([ | |
'customerAccount' => 'CL3142', | |
'code' => $code, | |
'companyName' => $values[1], | |
'destination1' => $destination1, | |
'contacts' => implode(',', $contacts), | |
]); | |
} | |
} | |
$data = Storage::disk('ftp')->get('routing/file2.csv'); | |
$lines = explode("\n", $data); | |
foreach ($lines as $line) { | |
$values = str_getcsv($line, ',', '"'); | |
if ( ! empty ($values[1])) { | |
$contacts = []; | |
for ($extension = $values[3]; $extension <= $values[4]; $extension++) { | |
array_push($contacts, phoneNumberFormat($extension)); | |
} | |
$code = '2002'; | |
$destination1 = '6007'; | |
CustomerContact::create([ | |
'customerAccount' => 'CL3142', | |
'code' => $code, | |
'companyName' => $values[0] . ' ' . $values[1], | |
'destination1' => $destination1, | |
'contacts' => implode(',', $contacts), | |
]); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment