Commit bed644ad authored by Alfonso Rafael Solis Rangel's avatar Alfonso Rafael Solis Rangel
Browse files

Implementacion del pdf

parent 89a7c9fd
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@
use Illuminate\Http\Request;

use App\Exports\ContactosExport;
use Barryvdh\DomPDF\Facade\Pdf;
use Maatwebsite\Excel\Facades\Excel;

class ReporteController extends Controller
@@ -88,7 +89,6 @@ public function export(Request $request)
            return response()->json(['Error, No seleccionaste un archivo de exportación valido.'], 400);
        }

        // TODO: Traer datos de todos los contactos
        $contactIds = array_column($request->input('contactos', []), 'id');
        $extraFields = $request->input('exportar', []);
        $filters = [
@@ -101,8 +101,16 @@ public function export(Request $request)
            'diaFin' => $request->input('diaFin'),
        ];
        // TODO: Crear archivos de exportacion: PDF, Excel
        $export = new ContactosExport($contactIds, $extraFields, $filters);
        if($request->archivo == 'excel'){
            return Excel::download($export, 'contactos.xlsx');
        }else if($request->archivo == 'pdf'){
            $pdf = Pdf::loadView('adminGen.contactos.contactos_pdf', ['contactos' => $export->collection()])->setPaper('A1', 'landscape');;
            return $pdf->download('contactos.pdf');
        }else{
            return Excel::download(new ContactosExport($contactIds, $extraFields, $filters), 'contactos.xlsx');
        }
    }

    public function getSubgrupos(Int $id)
    {
+1 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
    "license": "MIT",
    "require": {
        "php": "^8.2",
        "barryvdh/laravel-dompdf": "^3.1",
        "laravel/framework": "^11.9",
        "laravel/jetstream": "^5.1",
        "laravel/sanctum": "^4.0",
+365 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@
        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
        "This file is @generated automatically"
    ],
    "content-hash": "43505f151f7ef0c372d5c440872d788e",
    "content-hash": "3fae89651502cd60092c646a3b720c5a",
    "packages": [
        {
            "name": "bacon/bacon-qr-code",
@@ -60,6 +60,83 @@
            },
            "time": "2024-10-01T13:55:55+00:00"
        },
        {
            "name": "barryvdh/laravel-dompdf",
            "version": "v3.1.0",
            "source": {
                "type": "git",
                "url": "https://github.com/barryvdh/laravel-dompdf.git",
                "reference": "8d698b4aec2be91fe1e47ba71ba258acbf23357d"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/barryvdh/laravel-dompdf/zipball/8d698b4aec2be91fe1e47ba71ba258acbf23357d",
                "reference": "8d698b4aec2be91fe1e47ba71ba258acbf23357d",
                "shasum": ""
            },
            "require": {
                "dompdf/dompdf": "^3.0",
                "illuminate/support": "^9|^10|^11",
                "php": "^8.1"
            },
            "require-dev": {
                "larastan/larastan": "^2.7.0",
                "orchestra/testbench": "^7|^8|^9",
                "phpro/grumphp": "^2.5",
                "squizlabs/php_codesniffer": "^3.5"
            },
            "type": "library",
            "extra": {
                "laravel": {
                    "aliases": {
                        "PDF": "Barryvdh\\DomPDF\\Facade\\Pdf",
                        "Pdf": "Barryvdh\\DomPDF\\Facade\\Pdf"
                    },
                    "providers": [
                        "Barryvdh\\DomPDF\\ServiceProvider"
                    ]
                },
                "branch-alias": {
                    "dev-master": "3.0-dev"
                }
            },
            "autoload": {
                "psr-4": {
                    "Barryvdh\\DomPDF\\": "src"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Barry vd. Heuvel",
                    "email": "barryvdh@gmail.com"
                }
            ],
            "description": "A DOMPDF Wrapper for Laravel",
            "keywords": [
                "dompdf",
                "laravel",
                "pdf"
            ],
            "support": {
                "issues": "https://github.com/barryvdh/laravel-dompdf/issues",
                "source": "https://github.com/barryvdh/laravel-dompdf/tree/v3.1.0"
            },
            "funding": [
                {
                    "url": "https://fruitcake.nl",
                    "type": "custom"
                },
                {
                    "url": "https://github.com/barryvdh",
                    "type": "github"
                }
            ],
            "time": "2025-01-21T20:24:00+00:00"
        },
        {
            "name": "brick/math",
            "version": "0.12.1",
@@ -563,6 +640,161 @@
            ],
            "time": "2024-02-05T11:56:58+00:00"
        },
        {
            "name": "dompdf/dompdf",
            "version": "v3.1.0",
            "source": {
                "type": "git",
                "url": "https://github.com/dompdf/dompdf.git",
                "reference": "a51bd7a063a65499446919286fb18b518177155a"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/dompdf/dompdf/zipball/a51bd7a063a65499446919286fb18b518177155a",
                "reference": "a51bd7a063a65499446919286fb18b518177155a",
                "shasum": ""
            },
            "require": {
                "dompdf/php-font-lib": "^1.0.0",
                "dompdf/php-svg-lib": "^1.0.0",
                "ext-dom": "*",
                "ext-mbstring": "*",
                "masterminds/html5": "^2.0",
                "php": "^7.1 || ^8.0"
            },
            "require-dev": {
                "ext-gd": "*",
                "ext-json": "*",
                "ext-zip": "*",
                "mockery/mockery": "^1.3",
                "phpunit/phpunit": "^7.5 || ^8 || ^9 || ^10 || ^11",
                "squizlabs/php_codesniffer": "^3.5",
                "symfony/process": "^4.4 || ^5.4 || ^6.2 || ^7.0"
            },
            "suggest": {
                "ext-gd": "Needed to process images",
                "ext-gmagick": "Improves image processing performance",
                "ext-imagick": "Improves image processing performance",
                "ext-zlib": "Needed for pdf stream compression"
            },
            "type": "library",
            "autoload": {
                "psr-4": {
                    "Dompdf\\": "src/"
                },
                "classmap": [
                    "lib/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "LGPL-2.1"
            ],
            "authors": [
                {
                    "name": "The Dompdf Community",
                    "homepage": "https://github.com/dompdf/dompdf/blob/master/AUTHORS.md"
                }
            ],
            "description": "DOMPDF is a CSS 2.1 compliant HTML to PDF converter",
            "homepage": "https://github.com/dompdf/dompdf",
            "support": {
                "issues": "https://github.com/dompdf/dompdf/issues",
                "source": "https://github.com/dompdf/dompdf/tree/v3.1.0"
            },
            "time": "2025-01-15T14:09:04+00:00"
        },
        {
            "name": "dompdf/php-font-lib",
            "version": "1.0.1",
            "source": {
                "type": "git",
                "url": "https://github.com/dompdf/php-font-lib.git",
                "reference": "6137b7d4232b7f16c882c75e4ca3991dbcf6fe2d"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/dompdf/php-font-lib/zipball/6137b7d4232b7f16c882c75e4ca3991dbcf6fe2d",
                "reference": "6137b7d4232b7f16c882c75e4ca3991dbcf6fe2d",
                "shasum": ""
            },
            "require": {
                "ext-mbstring": "*",
                "php": "^7.1 || ^8.0"
            },
            "require-dev": {
                "symfony/phpunit-bridge": "^3 || ^4 || ^5 || ^6"
            },
            "type": "library",
            "autoload": {
                "psr-4": {
                    "FontLib\\": "src/FontLib"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "LGPL-2.1-or-later"
            ],
            "authors": [
                {
                    "name": "The FontLib Community",
                    "homepage": "https://github.com/dompdf/php-font-lib/blob/master/AUTHORS.md"
                }
            ],
            "description": "A library to read, parse, export and make subsets of different types of font files.",
            "homepage": "https://github.com/dompdf/php-font-lib",
            "support": {
                "issues": "https://github.com/dompdf/php-font-lib/issues",
                "source": "https://github.com/dompdf/php-font-lib/tree/1.0.1"
            },
            "time": "2024-12-02T14:37:59+00:00"
        },
        {
            "name": "dompdf/php-svg-lib",
            "version": "1.0.0",
            "source": {
                "type": "git",
                "url": "https://github.com/dompdf/php-svg-lib.git",
                "reference": "eb045e518185298eb6ff8d80d0d0c6b17aecd9af"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/dompdf/php-svg-lib/zipball/eb045e518185298eb6ff8d80d0d0c6b17aecd9af",
                "reference": "eb045e518185298eb6ff8d80d0d0c6b17aecd9af",
                "shasum": ""
            },
            "require": {
                "ext-mbstring": "*",
                "php": "^7.1 || ^8.0",
                "sabberworm/php-css-parser": "^8.4"
            },
            "require-dev": {
                "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5"
            },
            "type": "library",
            "autoload": {
                "psr-4": {
                    "Svg\\": "src/Svg"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "LGPL-3.0-or-later"
            ],
            "authors": [
                {
                    "name": "The SvgLib Community",
                    "homepage": "https://github.com/dompdf/php-svg-lib/blob/master/AUTHORS.md"
                }
            ],
            "description": "A library to read, parse and export to PDF SVG files.",
            "homepage": "https://github.com/dompdf/php-svg-lib",
            "support": {
                "issues": "https://github.com/dompdf/php-svg-lib/issues",
                "source": "https://github.com/dompdf/php-svg-lib/tree/1.0.0"
            },
            "time": "2024-04-29T13:26:35+00:00"
        },
        {
            "name": "dragonmantank/cron-expression",
            "version": "v3.4.0",
@@ -2613,6 +2845,73 @@
            },
            "time": "2022-12-02T22:17:43+00:00"
        },
        {
            "name": "masterminds/html5",
            "version": "2.9.0",
            "source": {
                "type": "git",
                "url": "https://github.com/Masterminds/html5-php.git",
                "reference": "f5ac2c0b0a2eefca70b2ce32a5809992227e75a6"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/Masterminds/html5-php/zipball/f5ac2c0b0a2eefca70b2ce32a5809992227e75a6",
                "reference": "f5ac2c0b0a2eefca70b2ce32a5809992227e75a6",
                "shasum": ""
            },
            "require": {
                "ext-dom": "*",
                "php": ">=5.3.0"
            },
            "require-dev": {
                "phpunit/phpunit": "^4.8.35 || ^5.7.21 || ^6 || ^7 || ^8 || ^9"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "2.7-dev"
                }
            },
            "autoload": {
                "psr-4": {
                    "Masterminds\\": "src"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Matt Butcher",
                    "email": "technosophos@gmail.com"
                },
                {
                    "name": "Matt Farina",
                    "email": "matt@mattfarina.com"
                },
                {
                    "name": "Asmir Mustafic",
                    "email": "goetas@gmail.com"
                }
            ],
            "description": "An HTML5 parser and serializer.",
            "homepage": "http://masterminds.github.io/html5-php",
            "keywords": [
                "HTML5",
                "dom",
                "html",
                "parser",
                "querypath",
                "serializer",
                "xml"
            ],
            "support": {
                "issues": "https://github.com/Masterminds/html5-php/issues",
                "source": "https://github.com/Masterminds/html5-php/tree/2.9.0"
            },
            "time": "2024-03-31T07:05:07+00:00"
        },
        {
            "name": "mobiledetect/mobiledetectlib",
            "version": "4.8.06",
@@ -4194,6 +4493,71 @@
            ],
            "time": "2024-04-27T21:32:50+00:00"
        },
        {
            "name": "sabberworm/php-css-parser",
            "version": "v8.7.0",
            "source": {
                "type": "git",
                "url": "https://github.com/MyIntervals/PHP-CSS-Parser.git",
                "reference": "f414ff953002a9b18e3a116f5e462c56f21237cf"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/MyIntervals/PHP-CSS-Parser/zipball/f414ff953002a9b18e3a116f5e462c56f21237cf",
                "reference": "f414ff953002a9b18e3a116f5e462c56f21237cf",
                "shasum": ""
            },
            "require": {
                "ext-iconv": "*",
                "php": "^5.6.20 || ^7.0.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0"
            },
            "require-dev": {
                "phpunit/phpunit": "5.7.27 || 6.5.14 || 7.5.20 || 8.5.40"
            },
            "suggest": {
                "ext-mbstring": "for parsing UTF-8 CSS"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-main": "9.0.x-dev"
                }
            },
            "autoload": {
                "psr-4": {
                    "Sabberworm\\CSS\\": "src/"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Raphael Schweikert"
                },
                {
                    "name": "Oliver Klee",
                    "email": "github@oliverklee.de"
                },
                {
                    "name": "Jake Hotson",
                    "email": "jake.github@qzdesign.co.uk"
                }
            ],
            "description": "Parser for CSS Files written in PHP",
            "homepage": "https://www.sabberworm.com/blog/2010/6/10/php-css-parser",
            "keywords": [
                "css",
                "parser",
                "stylesheet"
            ],
            "support": {
                "issues": "https://github.com/MyIntervals/PHP-CSS-Parser/issues",
                "source": "https://github.com/MyIntervals/PHP-CSS-Parser/tree/v8.7.0"
            },
            "time": "2024-10-27T17:38:32+00:00"
        },
        {
            "name": "spatie/laravel-permission",
            "version": "6.10.1",
+48 −0
Original line number Diff line number Diff line
<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Exportación de Contactos</title>
    <style>
        body { font-family: Arial, sans-serif; font-size: 14px; }
        table { width: 100%; border-collapse: collapse; margin-top: 10px; }
        th, td { border: 1px solid black; padding: 8px; text-align: left; }
        th { background-color: #f2f2f2; }
    </style>
</head>
<body>
    <h2>Listado de Contactos</h2>
    <table>
        <thead>
            <tr>
                <th>Profesión</th>
                <th>Nombre</th>
                <th>Apellido Paterno</th>
                <th>Apellido Materno</th>
                <th>Cargo</th>
                @if (!empty($contactos))
                    @foreach (array_keys(collect($contactos[0])->except(['Profesión', 'Nombre', 'Apellido Paterno', 'Apellido Materno', 'Cargo'])->toArray()) as $campo)
                        <th>{{ $campo }}</th>
                    @endforeach
                @endif
            </tr>
        </thead>
        <tbody>
            @foreach ($contactos as $contacto)
                <tr>
                    <td>{{ $contacto['Profesión'] }}</td>
                    <td>{{ $contacto['Nombre'] }}</td>
                    <td>{{ $contacto['Apellido Paterno'] }}</td>
                    <td>{{ $contacto['Apellido Materno'] }}</td>
                    <td>{{ $contacto['Cargo'] }}</td>
                    
                    @foreach (array_keys(collect($contacto)->except(['Profesión', 'Nombre', 'Apellido Paterno', 'Apellido Materno', 'Cargo'])->toArray()) as $campo)
                        <td>{{ $contacto[$campo] ?? '' }}</td>
                    @endforeach
                </tr>
            @endforeach
        </tbody>
    </table>
</body>
</html>
+33 −20
Original line number Diff line number Diff line
@@ -271,21 +271,34 @@ function logData() {
                        throw err;
                    });
                }
                    return response.blob(); // Procesar como Blob (archivo binario)

                const contentDisposition = response.headers.get('Content-Disposition');
                let filename = "contactos_report.xlsx"; // Nombre por defecto

                if (contentDisposition) {
                    const match = contentDisposition.match(/filename="?([^"]+)"?/);
                    if (match && match[1]) {
                        filename = match[1];
                    }
                }

                return response.blob().then(blob => ({ blob, filename }));
            })
                .then(blob => {
                    const url = window.URL.createObjectURL(blob); // Crear URL temporal para el archivo
                    const link = document.createElement('a'); // Crear un elemento <a> dinámicamente
            .then(({ blob, filename }) => {
                const url = window.URL.createObjectURL(blob);
                const link = document.createElement('a');
                link.href = url;
                    link.download = 'contactos_report.xlsx'; // Nombre del archivo
                    document.body.appendChild(link); // Añadir el enlace al DOM
                    link.click(); // Simular clic para iniciar descarga
                    link.remove(); // Remover el enlace del DOM
                    window.URL.revokeObjectURL(url); // Liberar el URL temporal
                link.download = filename;
                document.body.appendChild(link);
                link.click();
                link.remove();
                window.URL.revokeObjectURL(url);
            })
            .catch(err => {
                console.error("Error al descargar el archivo:", err);
                showToast(err.message || 'Error al descargar el archivo', 'Error', 'error');
            });

        }

        async function cargarSubgrupos(grupoId) {