Files
api/services/nginx/app/routes/pdfGeneratorRoute.php
T
Jepp9350 45328a6b72 Add PDF generation module with HTML2PDF integration.
This commit introduces a new PDF generation module leveraging the HTML2PDF library. The module generates PDFs from HTML templates, supports customization through styles and templates, and integrates with Minio for storage and retrieval. A test route is added for generating and serving PDFs dynamically.
2025-03-14 14:56:55 +01:00

72 lines
2.7 KiB
PHP

<?php
namespace routes;
use classes\pdf_generator;
use classes\response;
use classes\router;
use objects\logs_o;
use traits\route_t;
class pdfGeneratorRoute
{
use route_t;
public function run(): void
{
global /** @var response $response */
/** @var router $router */
$router, $response;
/** PDF Generator > GET */
$this->get('/modules/pdf-generator/test', function () {
global $response;
//self::requirePermission('modules_pdf_generator_test');
if (true) {
//(new logs_o())->add('orderInvoices', 'global', 1, $user->id, 'LIST_COLLECTED_INVOICES', 'User accessed the list of collected order invoices');
$pdf_generator = new pdf_generator();
$pdf_generator->add_html($pdf_generator->templates->getTemplate('wash_certificate')
->setCompany([
'name' => 'Truck Wash',
'address' => 'Letland Allé 2',
'zip' => 2630,
'city' => 'Taastrup',
'phone_prefix' => 45,
'phone' => 43717886,
'email' => 'cph@truckwash.dk',
'website' => 'www.truckwash.dk',
'images' => [
'logo' => '/truckwash-banner-png.png',
'banner' => '/truckwash-banner-png.png',
'signature' => '/truckwash-underskrift.png',
],
])
->addData([
'seal_number' => 123456,
'reg_1' => 'EC21233',
'reg_2' => 'FB1703',
'date' => '2023-10-01',
'time' => '12:00',
'carried_out_by' => 'John Doe',
'department_id' => 1,
'customer_name' => 'Customer Name',
'type' => 'Interior Cleaning',
])
->getHtml()
);
$pdf_path = $pdf_generator->generate_pdf();
$response->success([
'pdf_path' => $pdf_path,
'message' => 'PDF generated successfully'
]);
} else {
(new logs_o())->add('orderInvoices', 'global', 0, 0, 'LIST_COLLECTED_INVOICES', 'User tried to access the list of collected order invoices without a valid session');
$response->error('Invalid session', 400);
}
},
[
'list_collected_invoices' => 'List ALL collected order invoices. This is a superuser-only route.'
]
);
}
}