From 092e98a456f4945876f7eb5505485bef4332f9cd Mon Sep 17 00:00:00 2001 From: ale Date: Wed, 13 Aug 2025 00:01:53 -0300 Subject: [PATCH] Agregado metodo para notas de barrio --- app/Producto.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/app/Producto.php b/app/Producto.php index 0deffa6..475a60f 100644 --- a/app/Producto.php +++ b/app/Producto.php @@ -103,4 +103,32 @@ class Producto extends Model $filePath = 'csv/exports/notas-por-barrio-' . $fecha . '.csv'; CsvHelper::generarCsv($filePath, $planilla, $headers); } + + /** + * @throws InvalidArgument + * @throws CannotInsertRecord + */ + static public function planillaNotasBarrio($gdc) { + $headers = ['Producto']; + $barrios = [$gdc->nombre]; + $headers = array_merge($headers, $barrios); + + $notasPorBarrio = self::notasPorBarrio(); + $planilla = []; + + foreach ($notasPorBarrio as $producto => $notasGrupo) { + $fila = [$producto]; + foreach ($barrios as $barrio) { + $notas = $notasGrupo->where('barrio', $barrio) + ->pluck('notas') + ->implode('; '); + $fila[] = $notas ?: ''; + } + $planilla[] = $fila; + } + + $fecha = now()->format('Y-m-d'); + $filePath = 'csv/exports/notas-de-' . $gdc->nombre . '-' . $fecha . '.csv'; + CsvHelper::generarCsv($filePath, $planilla, $headers); + } }