diff --git a/app/Producto.php b/app/Producto.php index 9359bc0..861cdee 100644 --- a/app/Producto.php +++ b/app/Producto.php @@ -8,6 +8,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; use League\Csv\CannotInsertRecord; +use League\Csv\Reader; use League\Csv\Writer; class Producto extends Model @@ -91,10 +92,11 @@ class Producto extends Model $cantidadesPorBarrio = self::cantidadesPorBarrio(); $planilla = []; $ultimaFila = 1; + $filaTransporte = self::filaTransporte(); foreach ($cantidadesPorBarrio as $productoCantidades) { $fila = $productoCantidades->fila; - if ($fila - $ultimaFila > 1) { + while ($fila - $ultimaFila > 1) { $ultimaFila++; $planilla[$ultimaFila] = ['---']; } @@ -157,4 +159,17 @@ class Producto extends Model var_export($e->getRecords()); } } + + private static function filaTransporte() + { + $csv = Reader::createFromPath(resource_path('csv/productos.csv'), 'r'); + $csv->setDelimiter("|"); + $csv->setEnclosure("'"); + $registros = $csv->getRecords(); + + foreach ($registros as $key => $registro) + if ($registro[0] == 'T') return $key; + + throw new Exception('No hay bono de transporte'); + } }