Agregada fecha a nombre de archivos exportados (csv y pdf)

This commit is contained in:
Alejandro Tasistro 2025-06-14 15:55:56 -03:00
parent a38bceab82
commit 17148d73f8
4 changed files with 44 additions and 14 deletions

View file

@ -111,7 +111,8 @@ class GrupoDeCompra extends Model
public function exportarPedidosAPdf()
{
$subpedidos = $this->pedidosAprobados();
PdfHelper::exportarPedidos($this->nombre . '.pdf', $subpedidos);
$fecha = now()->format('Y-m-d');
PdfHelper::exportarPedidos($this->nombre . '-' . $fecha . '.pdf', $subpedidos);
}
function pedidoParaPdf(): array
@ -144,7 +145,8 @@ class GrupoDeCompra extends Model
public static function exportarPedidosBarrialesAPdf()
{
$barrios = GrupoDeCompra::barriosMenosPrueba()->get();
PdfHelper::exportarPedidos('pedidos_por_barrio.pdf', $barrios);
$fecha = now()->format('Y-m-d');
PdfHelper::exportarPedidos('pedidos_por_barrio-' . $fecha . '.pdf', $barrios);
}
static function filaVacia(string $product, int $columns): array
@ -178,7 +180,8 @@ class GrupoDeCompra extends Model
{
$records = $this->generarColumnaCantidades();
CsvHelper::generarCsv('csv/exports/' . $this->nombre . '.csv', $records);
$fecha = now()->format('Y-m-d');
CsvHelper::generarCsv('csv/exports/' . $this->nombre . '-' . $fecha . '.csv', $records);
}
public function generarColumnaCantidades(): array
@ -235,7 +238,8 @@ class GrupoDeCompra extends Model
}
array_splice($records, 0, 0, array($nucleos));
CsvHelper::generarCsv('csv/exports/' . $this->nombre . '-completo.csv', $records);
$fecha = now()->format('Y-m-d');
CsvHelper::generarCsv('csv/exports/' . $this->nombre . '-completo-' . $fecha . '.csv', $records);
}
public function agregarCantidad($pedido, $id, array $records, $fila, int $i): array

View file

@ -23,14 +23,26 @@ class AdminController extends Controller
public function exportarPedidoACSV(GrupoDeCompra $gdc): BinaryFileResponse
{
$gdc->exportarPedidoEnCSV();
$file = storage_path('csv/exports/'.$gdc->nombre.'.csv');
return response()->download($file);
$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]);
}
public function exportarPedidoConNucleosACSV(GrupoDeCompra $gdc): BinaryFileResponse
{
$gdc->exportarPedidoConNucleosEnCSV();
$file = storage_path('csv/exports/'.$gdc->nombre.'-completo.csv');
return response()->download($file);
$pattern = storage_path('csv/exports/'.$gdc->nombre.'-completo-*.csv');
$files = glob($pattern);
usort($files, function ($a, $b) {
return filemtime($b) <=> filemtime($a);
});
return response()->download($files[0]);
}
}

View file

@ -21,15 +21,27 @@ class ComisionesController
public function descargarPedidos(): BinaryFileResponse
{
Producto::planillaTotales();
$file = storage_path('csv/exports/pedidos-por-barrio.csv');
return response()->download($file);
$pattern = storage_path('csv/exports/pedidos-por-barrio-*.csv');
$files = glob($pattern);
usort($files, function ($a, $b) {
return filemtime($b) <=> filemtime($a);
});
return response()->download($files[0]);
}
public function descargarNotas(): BinaryFileResponse
{
Producto::planillaNotas();
$file = storage_path('csv/exports/notas-por-barrio.csv');
return response()->download($file);
$pattern = storage_path('csv/exports/notas-por-barrio-*.csv');
$files = glob($pattern);
usort($files, function ($a, $b) {
return filemtime($b) <=> filemtime($a);
});
return response()->download($files[0]);
}
public function pdf() {

View file

@ -109,7 +109,8 @@ class Producto extends Model
$planilla[$filaTransporte][] = $cantidad;
}
CsvHelper::generarCsv('csv/exports/pedidos-por-barrio.csv', $planilla, $headers);
$fecha = now()->format('Y-m-d');
CsvHelper::generarCsv('csv/exports/pedidos-por-barrio- ' . $fecha . '.csv', $planilla, $headers);
}
public static function notasPorBarrio(): Collection
@ -146,6 +147,7 @@ class Producto extends Model
$planilla[] = $fila;
}
CsvHelper::generarCsv('csv/exports/notas-por-barrio.csv', $planilla, $headers);
$fecha = now()->format('Y-m-d');
CsvHelper::generarCsv('csv/exports/notas-por-barrio-' . $fecha . '.csv', $planilla, $headers);
}
}