From 8a0f8fbe139f40d2c806be2d372fd19f51cf857e Mon Sep 17 00:00:00 2001 From: ale Date: Mon, 9 Dec 2024 20:58:56 -0300 Subject: [PATCH] Hueco para transporte --- app/Producto.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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'); + } }