Agregado metodo para notas de barrio

This commit is contained in:
Alejandro Tasistro 2025-08-13 00:01:53 -03:00
parent 56e1a94ee7
commit 092e98a456

View file

@ -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);
}
}