From cc6fe6878a26e3a3522d2cb3b1b3c820c479d8c8 Mon Sep 17 00:00:00 2001 From: ale Date: Tue, 8 Jul 2025 22:46:09 -0300 Subject: [PATCH] Agregada cantidad de ollas a planilla de ollas --- app/Helpers/PedidosExportHelper.php | 37 ++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/app/Helpers/PedidosExportHelper.php b/app/Helpers/PedidosExportHelper.php index 7e4fd6d..b8672f2 100644 --- a/app/Helpers/PedidosExportHelper.php +++ b/app/Helpers/PedidosExportHelper.php @@ -3,6 +3,7 @@ namespace App\Helpers; use App\GrupoDeCompra; +use App\TipoPedido; use Closure; use Illuminate\Database\Query\Expression; use Illuminate\Support\Collection; @@ -43,18 +44,42 @@ class PedidosExportHelper { $filePath = "csv/exports/pedidos-de-ollas-" . now()->format('Y-m-d') . ".csv"; $barrios = GrupoDeCompra::barriosMenosPrueba()->get(); + + $contenido = self::generarContenidoCSV($barrios, + fn($grupoId) => "subpedidos.grupo_de_compra_id = $grupoId + AND subpedidos.tipo_pedido_id = 2"); + $ollas = self::cantidadDeOllasParaCSV($barrios, $contenido); + self::exportarCSV( $filePath, $barrios, - self::generarContenidoCSV( - $barrios, - fn ($grupoId) => - "subpedidos.grupo_de_compra_id = $grupoId - AND subpedidos.tipo_pedido_id = 2" - ) + $contenido->concat([$ollas]) ); } + /** + * @throws Exception + */ + public static function cantidadDeOllasParaCSV(Collection $barrios, Collection $contenido) + { + $tipo_olla = TipoPedido::where('nombre', 'olla')->first()->id; + + $parametros = collect(CsvHelper::getRecords(resource_path("csv/parametros.csv"), "No se pudo leer el archivo.")); + $fila = [ + "producto" => "Cantidad de ollas", + "precio" => $parametros->where('id','monto-olla')->pluck('valor')->first(), + "paga_transporte" => false, + "fila" => $contenido->last()->fila + 1, + ]; + + foreach ($barrios as $barrio) { + $pedido = $barrio->subpedidos()->where('tipo_pedido_id', $tipo_olla)->first(); + $fila[$barrio->nombre] = $pedido->cantidad_ollas; + } + + return (object) $fila; + } + /** * @throws InvalidArgument * @throws CannotInsertRecord