Created
January 8, 2020 12:02
-
-
Save cygeorgel/3a45281ddd9df50041e206c5ae50dc2d 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
public function handle() | |
{ | |
$path = 'import'; | |
$filename = 'sepa.csv'; | |
$content = Storage::disk('ftp')->get($path . '/' . $filename); | |
Storage::disk('local')->makeDirectory($path); | |
Storage::disk('local')->put($path . '/' . $filename, $content); | |
$file = fopen(storage_path('app/' . $path . '/' . $filename), 'r'); | |
while (($data = fgetcsv($file, 5000, ';')) !== false) { | |
if ($data[0] != 'NUM_CLIENT') { | |
$customerAccounts = explode('/', $data[0]); | |
foreach ($customerAccounts as $customerAccount) { | |
$count = Customer::where('customerAccount', $customerAccount)->count(); | |
if ($count) { | |
$customer = Customer::where('customerAccount', $customerAccount)->first(); | |
if ($customer) { | |
$DtOfSgntr = \Carbon\Carbon::createFromFormat('d/m/Y', $data[4]); | |
$cbd = CustomerBankDetails::create([ | |
'fileable_type' => 'App\Customer', | |
'fileable_id' => $customer->id, | |
'user_id' => 1, | |
'IBAN' => $data[10], | |
'BIC' => $data[11], | |
'mandateIdentification' => $data[2], | |
'DtOfSgntr' => $DtOfSgntr, | |
'active' => true, | |
'forbidden' => false, | |
]); | |
$this->info('create customer bank details' . $cbd->id); | |
foreach ($customer->files as $file) { | |
$file->customer_bank_details_id = $cbd->id; | |
$file->mandateIdentification = $data[2]; | |
$file->mandateSignatureDate = $DtOfSgntr; | |
$file->save(); | |
$this->info('apply customer bank details ' . $cbd->id . ' to file ' . $file->id); | |
} | |
} | |
} else { | |
$this->warn('customer ' . $customerAccount . ' not found'); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment