<?php
namespace App\Controller;
use Dompdf\Dompdf;
use Dompdf\Options;
use Knp\Snappy\Pdf;
use App\Repository\RoomRepository;
use App\Repository\OfficeRepository;
use App\Repository\CustomerRepository;
use App\Repository\DocumentRepository;
use App\Repository\RoomBookingRepository;
use App\Repository\OfficeBookingRepository;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use ContainerII4VBkZ\getDocumentRepositoryService;
use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class HomeController extends AbstractController
{
private $officeRepository;
private $roomRepository;
private $customerRepository;
private $roomBookingRepository;
private $documentRepository;
private $officeBookingRepository;
public function __construct(
OfficeRepository $officeRepository,
RoomRepository $roomRepository,
CustomerRepository $customerRepository,
RoomBookingRepository $roomBookingRepository,
DocumentRepository $documentRepository,
OfficeBookingRepository $officeBookingRepository
)
{
$this->officeRepository = $officeRepository;
$this->roomRepository = $roomRepository;
$this->customerRepository = $customerRepository;
$this->roomBookingRepository = $roomBookingRepository;
$this->documentRepository = $documentRepository;
$this->officeBookingRepository = $officeBookingRepository;
}
#[Route(path: '/', name: 'homepage')]
public function index(): Response
{
$team = $this->getUser()->getTeam();
$alertOfficeBookings = $this->officeBookingRepository->getAlertPaymentTransfert($team) + $this->officeBookingRepository->getAlertPaymentCheck($team);
$alertRoomBookings = $this->roomBookingRepository->getAlertPaymentTransfert($team) + $this->roomBookingRepository->getAlertPaymentCheck($team);
return $this->render('dashboard.html.twig', [
'menu' => 'homepage',
'office' => $this->officeRepository->getNumberOffice($team),
'room' => $this->roomRepository->getNumberRoom($team),
'domicilliationCustomer' => 0,
'customers' => $this->customerRepository->getNumberCustomer($team),
'domicilliationCustomerRedirection' => 0,
'domiciliationCustomerScanPro' => 0,
'alertOfficeCheck' => $this->officeBookingRepository->getAlertPaymentCheck($team),
'alertOfficeBookings' => $alertOfficeBookings,
'alertRoomBookings' => $alertRoomBookings
]);
}
#[Route(path: '/dom-pdf', name: 'dom_pdf')]
public function pdfExempleDom(Pdf $pdf)
{
// Configure Dompdf according to your needs
$pdfOptions = new Options();
$pdfOptions->setDefaultFont('Roboto');
$pdfOptions->setIsPhpEnabled(true);
$pdfOptions->setIsRemoteEnabled(true);
// Instantiate Dompdf with our options
$dompdf = new Dompdf($pdfOptions);
// Retrieve the HTML generated in our twig file
$html = $this->renderView('pdf/exemple.html.twig', [
'title' => "Welcome to our PDF Test"
]);
// Load HTML to Dompdf
$dompdf->loadHtml($html);
// (Optional) Setup the paper size and orientation 'portrait' or 'portrait'
$dompdf->setPaper('A4', 'portrait');
// Render the HTML as PDF
$dompdf->render();
try {
// Output the generated PDF to Browser (inline view)
$dompdf->stream("mypdf.pdf", [
"Attachment" => false
]);
} catch (\Throwable $th) {
throw $th;
}
}
#[Route(path: '/exemple-pdf', name: 'exemple_pdf')]
public function pdfExemple(Pdf $pdf)
{
$header = $this->renderView('pdf/header.html.twig', [
'invoice' => "aaaa",
'date' => 'aaa',
'status' => 'aaa',
'title' => 'test'
]);
$footer = $this->renderView('pdf/footer.html.twig');
$html = $this->renderView('pdf/exemple.html.twig', array(
'some' => 'aa',
));
$pdf->setOption('footer-center','Page [page]/[topage]');
$options = [
'header-html' => $header,
'margin-top' => 43,
'margin-right' => 0,
'margin-bottom' => 10,
'margin-left' => 0,
];
$filename = 'test';
$pdfFolder = $this->getParameter('invoice_directory');
$pdf->generateFromHtml(
$html,
$pdfFolder.'/'.$filename,
$options
);
return $this->file($pdfFolder.'/'.$filename);
//return new PdfResponse($pdf->getOutputFromHtml($html, $options), 'file.pdf', );
}
}