mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
82 lines
2.6 KiB
PHP
82 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Excel;
|
|
|
|
use App\Controllers\BaseController;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
|
|
|
|
class PrintGiros extends BaseController
|
|
{
|
|
public function generateExcel($factura_id = null)
|
|
{
|
|
// AQUI CREAR LAS CONSULTAS A LA BBDD, QUIZAS HAYA QUE CREARLO O COMO POST O COMO QUERY AJAX
|
|
|
|
// Crear un nuevo Spreadsheet
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
|
|
// Especificar encabezados
|
|
$headers = [
|
|
'BIC (SWIFT)*',
|
|
'FECHA FIRMA MANDATO*',
|
|
'IBAN*',
|
|
'IMPORTE*',
|
|
'NOMBRE*',
|
|
'PAIS*',
|
|
'REFERENCIA DEL ADEUDO (REFADEUDO)*',
|
|
'REFERENCIA*',
|
|
'REFERENCIA DEL MANDATO (REMANDATO)*',
|
|
'RESIDENTE*',
|
|
'TIPO DE ADEUDO*',
|
|
'FECHA DE COBRO*',
|
|
'DIAS*'
|
|
];
|
|
|
|
// Establecer los encabezados en la primera fila
|
|
$column = 'A';
|
|
foreach ($headers as $header) {
|
|
$sheet->setCellValue($column . '1', $header);
|
|
$column++;
|
|
}
|
|
|
|
// Generar datos dummy
|
|
$dummyData = [
|
|
['ABCDEF12', '2024-01-01', 'ES1234567890123456789012', 100.50, 'John Doe', 'Spain', 'REF001', '12345', 'MAND001', 'Yes', 'Type1', '2024-02-01', 30],
|
|
['GHIJKL34', '2024-02-01', 'ES9876543210987654321098', 200.75, 'Jane Smith', 'France', 'REF002', '67890', 'MAND002', 'No', 'Type2', '2024-03-01', 60],
|
|
// Añade más datos dummy según sea necesario
|
|
];
|
|
|
|
// Rellenar las filas con datos dummy
|
|
$rowNumber = 2; // Empezar en la segunda fila
|
|
foreach ($dummyData as $row) {
|
|
$column = 'A';
|
|
foreach ($row as $cell) {
|
|
$sheet->setCellValue($column . $rowNumber, $cell);
|
|
$column++;
|
|
}
|
|
$rowNumber++;
|
|
}
|
|
|
|
// Ajustar automáticamente el tamaño de las columnas
|
|
foreach (range('A', $column) as $col) {
|
|
$sheet->getColumnDimension($col)->setAutoSize(true);
|
|
}
|
|
|
|
// Crear un escritor para guardar el archivo
|
|
$writer = new Xlsx($spreadsheet);
|
|
|
|
// Configurar la respuesta para descarga
|
|
$fileName = 'giros_reporte.xlsx';
|
|
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
header('Content-Disposition: attachment;filename="' . $fileName . '"');
|
|
header('Cache-Control: max-age=0');
|
|
|
|
// Escribir el archivo a la salida
|
|
$writer->save('php://output');
|
|
exit;
|
|
|
|
}
|
|
|
|
} |