ldc-bogt/app/Console/Commands/MajEleveurs.php
2022-03-09 10:54:00 +01:00

65 lines
1.5 KiB
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\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];
$ean_13 = $data[7];
$mobas = Moba::where('code_boite', '=', $code_boite)->andWhere('ean_13', '=', '')->update(['ean_13' => $data[7]]);
echo $line . "\n\r";
}
}
}
return 0;
}
}