Agregado metodo para exportar pedido de ollas a csv
This commit is contained in:
parent
59cefc8233
commit
2ef4d77e4f
2 changed files with 42 additions and 0 deletions
|
@ -128,6 +128,31 @@ class PedidosExportHelper
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidArgument
|
||||
* @throws CannotInsertRecord
|
||||
* @throws Exception
|
||||
*/
|
||||
static public function pedidoOllasDeBarrio(GrupoDeCompra $grupo)
|
||||
{
|
||||
$filePath = "csv/exports/" . $grupo->nombre . "-ollas-" . now()->format('Y-m-d') . ".csv";
|
||||
$tipo_olla = self::getTipoId('olla');
|
||||
|
||||
$falsoBarrio = new GrupoDeCompra(['nombre' => 'Total']);
|
||||
$falsoBarrio->id = $grupo->id;
|
||||
$header = collect([$falsoBarrio]);
|
||||
|
||||
self::exportarCSV(
|
||||
$filePath,
|
||||
$header,
|
||||
self::generarContenidoCSV(
|
||||
$header,
|
||||
fn($grupoId) => "subpedidos.grupo_de_compra_id = $grupoId
|
||||
AND subpedidos.tipo_pedido_id = $tipo_olla"
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidArgument
|
||||
* @throws CannotInsertRecord
|
||||
|
|
|
@ -60,4 +60,21 @@ class AdminController extends Controller
|
|||
|
||||
return response()->download($files[0]);
|
||||
}
|
||||
|
||||
public function exportarPedidoOllasACSV(GrupoDeCompra $gdc)
|
||||
{
|
||||
try {
|
||||
PedidosExportHelper::pedidoOllasDeBarrio($gdc);
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['message' => $e->getMessage()]);
|
||||
}
|
||||
$pattern = storage_path('csv/exports/'. $gdc->nombre . '-*.csv');
|
||||
$files = glob($pattern);
|
||||
|
||||
usort($files, function ($a, $b) {
|
||||
return filemtime($b) <=> filemtime($a);
|
||||
});
|
||||
|
||||
return response()->download($files[0]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue