Metodo para obtener id de tipo_pedido y arreglada query de pedidos de ollas para levantar solo los barrios con pedidos de ollas

This commit is contained in:
Alejandro Tasistro 2025-08-03 11:01:15 -03:00
parent 66298228e3
commit bcc4f4a28a

View file

@ -43,7 +43,12 @@ 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";
$barrios = GrupoDeCompra::barriosMenosPrueba()->get(); $barrios = GrupoDeCompra::barriosMenosPrueba()
->whereHas('subpedidos', function ($query) {
$tipo_olla = self::getTipoId('olla');
$query->where('tipo_pedido_id', $tipo_olla);
})
->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
@ -62,7 +67,7 @@ class PedidosExportHelper
*/ */
public static function cantidadDeOllasParaCSV(Collection $barrios, Collection $contenido) public static function cantidadDeOllasParaCSV(Collection $barrios, Collection $contenido)
{ {
$tipo_olla = TipoPedido::where('nombre', 'olla')->first()->id; $tipo_olla = self::getTipoId('olla');
$parametros = collect(CsvHelper::getRecords(resource_path("csv/parametros.csv"), "No se pudo leer el archivo.")); $parametros = collect(CsvHelper::getRecords(resource_path("csv/parametros.csv"), "No se pudo leer el archivo."));
$fila = [ $fila = [
@ -241,4 +246,13 @@ class PedidosExportHelper
} }
return $transporte; return $transporte;
} }
/**
* @return mixed
*/
public static function getTipoId(string $tipo)
{
$tipo_olla = TipoPedido::where('nombre', $tipo)->first()->id;
return $tipo_olla;
}
} }