Agregada lógica para faltantes y sobrantes

This commit is contained in:
Alejandro Tasistro 2025-09-14 12:12:44 -03:00
parent ac8ee0799b
commit 0ecff9ae68

View file

@ -35,6 +35,7 @@ class PedidosExportHelper
) )
); );
} }
/** /**
* @throws InvalidArgument * @throws InvalidArgument
* @throws CannotInsertRecord * @throws CannotInsertRecord
@ -43,16 +44,16 @@ class PedidosExportHelper
static public function pedidosDeOllas() static public function pedidosDeOllas()
{ {
$filePath = "csv/exports/pedidos-de-ollas-" . now()->format('Y-m-d') . ".csv"; $filePath = "csv/exports/pedidos-de-ollas-" . now()->format('Y-m-d') . ".csv";
$tipo_olla = self::getTipoId('olla');
$barrios = GrupoDeCompra::barriosMenosPrueba() $barrios = GrupoDeCompra::barriosMenosPrueba()
->whereHas('subpedidos', function ($query) { ->whereHas('subpedidos', function ($query) use ($tipo_olla) {
$tipo_olla = self::getTipoId('olla');
$query->where('tipo_pedido_id', $tipo_olla); $query->where('tipo_pedido_id', $tipo_olla);
}) })
->get(); ->get();
$contenido = self::generarContenidoCSV($barrios, $contenido = self::generarContenidoCSV($barrios,
fn($grupoId) => "subpedidos.grupo_de_compra_id = $grupoId 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); $ollas = self::cantidadDeOllasParaCSV($barrios, $contenido);
self::exportarCSV( 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 InvalidArgument
* @throws CannotInsertRecord * @throws CannotInsertRecord
@ -252,7 +279,7 @@ class PedidosExportHelper
*/ */
public static function getTipoId(string $tipo) public static function getTipoId(string $tipo)
{ {
$tipo_olla = TipoPedido::where('nombre', $tipo)->first()->id; $tipoPedido = TipoPedido::where('nombre', $tipo)->first()->id;
return $tipo_olla; return $tipoPedido;
} }
} }