ldc-bogt/app/Console/Commands/MajEleveurs.php
2020-01-29 13:55:31 +01:00

69 lines
1.6 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)->get();
if($mobas && count($mobas) > 0){
foreach ($mobas as $moba) {
if($moba->ean13 == ""){
$moba->ean13 = $ean13;
$moba->save();
}
}
}
echo $line."\n\r";
}
}
}
}
}