diff --git a/database/seeds/ImportarProductoSeeder.php b/database/seeds/CanastaSeeder.php similarity index 93% rename from database/seeds/ImportarProductoSeeder.php rename to database/seeds/CanastaSeeder.php index d929371..f9a5756 100644 --- a/database/seeds/ImportarProductoSeeder.php +++ b/database/seeds/CanastaSeeder.php @@ -4,7 +4,7 @@ use Illuminate\Database\Seeder; use League\Csv\Reader; use App\Proveedor; -class ImportarProductoSeeder extends Seeder +class CanastaSeeder extends Seeder { const FILA_HEADER = "Tipo"; const ULTIMA_FILA = "TOTAL"; @@ -21,14 +21,14 @@ class ImportarProductoSeeder extends Seeder $iHeader = $this->obtenerIndiceDeHeader($csv); $csv->setHeaderOffset($iHeader); $registros = $csv->getRecords(); - + $toInsert = []; $categoria = ''; foreach($registros as $i => $registro){ //filas que están arriba del header if ($i <= $iHeader){ continue; - } + } //finalizar if ($registro[$this::FILA_HEADER] == $this::ULTIMA_FILA){ @@ -39,7 +39,7 @@ class ImportarProductoSeeder extends Seeder if (!Arr::has($registro,$this::FILA_HEADER)|| trim($registro[$this::FILA_HEADER]) == ''){ var_dump("no hay tipo en la fila " . $i); continue; - } + } //saltear bono de transporte if ($registro[$this::FILA_HEADER] == "T"){ @@ -51,7 +51,7 @@ class ImportarProductoSeeder extends Seeder //es la pregunta de la copa? if (Str::contains($registro[$this::FILA_HEADER],"¿")) { continue; } $categoria = $registro[$this::FILA_HEADER]; - continue; + continue; } //completar producto @@ -65,9 +65,9 @@ class ImportarProductoSeeder extends Seeder ]; } - foreach (array_chunk($toInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk) + foreach (array_chunk($toInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk) { - DB::table('productos')->insert($chunk); + DB::table('productos')->insert($chunk); } } diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index 1e8ec0e..b71ca5a 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -12,7 +12,6 @@ class DatabaseSeeder extends Seeder */ public function run() { - $this->call(GrupoDeCompraSeeder::class); - $this->call(ImportarProductoSeeder::class); + $this->call(CanastaSeeder::class); } } diff --git a/database/seeds/ProductoSeeder.php b/database/seeds/ProductoSeeder.php deleted file mode 100644 index 95cab3e..0000000 --- a/database/seeds/ProductoSeeder.php +++ /dev/null @@ -1,40 +0,0 @@ -setDelimiter("|"); - $csv->setEnclosure("'"); - $csv->setHeaderOffset(0); - $registros = $csv->getRecords(); - $toInsert = []; - - foreach($registros as $registro){ - $toInsert[] = [ - 'categoria' => $registro['categoria'], - 'nombre' => $registro['producto'], - 'precio' => $registro['precio'], - 'proveedor_id' => isset($registro['proveedor']) ? Proveedor::firstOrCreate([ - 'nombre' => $registro['proveedor'] - ])->id : null, - 'bono' => $registro['categoria'] == 'BONOS Y FINANCIAMIENTO SORORO' - ]; - } - - foreach (array_chunk($toInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk) - { - DB::table('productos')->insert($chunk); - } - } -}