From 0ecff9ae680920eda2c2a10a95732ea60e16d47e Mon Sep 17 00:00:00 2001 From: ale Date: Sun, 14 Sep 2025 12:12:44 -0300 Subject: [PATCH] =?UTF-8?q?Agregada=20l=C3=B3gica=20para=20faltantes=20y?= =?UTF-8?q?=20sobrantes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Helpers/PedidosExportHelper.php | 37 +++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/app/Helpers/PedidosExportHelper.php b/app/Helpers/PedidosExportHelper.php index c8a16dc..1be6ff7 100644 --- a/app/Helpers/PedidosExportHelper.php +++ b/app/Helpers/PedidosExportHelper.php @@ -35,6 +35,7 @@ class PedidosExportHelper ) ); } + /** * @throws InvalidArgument * @throws CannotInsertRecord @@ -43,16 +44,16 @@ class PedidosExportHelper static public function pedidosDeOllas() { $filePath = "csv/exports/pedidos-de-ollas-" . now()->format('Y-m-d') . ".csv"; + $tipo_olla = self::getTipoId('olla'); $barrios = GrupoDeCompra::barriosMenosPrueba() - ->whereHas('subpedidos', function ($query) { - $tipo_olla = self::getTipoId('olla'); + ->whereHas('subpedidos', function ($query) use ($tipo_olla) { $query->where('tipo_pedido_id', $tipo_olla); }) ->get(); $contenido = self::generarContenidoCSV($barrios, fn($grupoId) => "subpedidos.grupo_de_compra_id = $grupoId - AND subpedidos.tipo_pedido_id = 2"); + AND subpedidos.tipo_pedido_id = $tipo_olla"); $ollas = self::cantidadDeOllasParaCSV($barrios, $contenido); self::exportarCSV( @@ -128,6 +129,32 @@ class PedidosExportHelper ); } + /** + * @throws InvalidArgument + * @throws CannotInsertRecord + * @throws Exception + */ + static public function faltantesYSobrantes() + { + $filePath = "csv/exports/faltantes-y-sobrantes-" . now()->format('Y-m-d') . ".csv"; + $tipoPedidoId = self::getTipoId('faltantes_y_sobrantes'); + $barrios = GrupoDeCompra::barriosMenosPrueba() + ->whereHas('subpedidos', function ($query) use ($tipoPedidoId) { + $query->where('tipo_pedido_id', $tipoPedidoId); + }) + ->get(); + + $contenido = self::generarContenidoCSV($barrios, + fn($grupoId) => "subpedidos.grupo_de_compra_id = $grupoId + AND subpedidos.tipo_pedido_id = $tipoPedidoId"); + + self::exportarCSV( + $filePath, + $barrios, + $contenido + ); + } + /** * @throws InvalidArgument * @throws CannotInsertRecord @@ -252,7 +279,7 @@ class PedidosExportHelper */ public static function getTipoId(string $tipo) { - $tipo_olla = TipoPedido::where('nombre', $tipo)->first()->id; - return $tipo_olla; + $tipoPedido = TipoPedido::where('nombre', $tipo)->first()->id; + return $tipoPedido; } }