ldc-bogt/app/Console/Commands/MajEleveurs.php
Vincent BRIDIER 69a2aed8b9 - clean routes
- update bo route
- add translations
- set timezone and locale
- Add Handler
- Bump to Laravel 8.x
- update .env.example
2022-01-13 18:53:54 +01:00

66 lines
1.4 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Moba;
class MajEleveurs extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'maj:moba';
/**
* 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()
{
setlocale(LC_CTYPE, 'en_US.utf8');
$path = base_path("resources/flux_in/maj/*.csv");
foreach (glob($path) as $file) {
$flag = true;
$line = 0;
if (($handle = fopen($file, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 50000, ";", '"')) !== FALSE) {
if ($flag) {
$flag = false;
continue;
}
$line++;
$code_boite = $data[0];
$ean13 = $data[7];
$mobas = Moba::where('code_boite', '=', $code_boite)->andWhere('ean13', '=', '')->update(['ean13' => $data[7]]);
echo $line . "\n\r";
}
}
}
return 0;
}
}