THANASOFT-HFC/gestion/lib/Service/Devis/DevisPdfLayoutManager.php

156 lines
5.7 KiB
PHP

<?php
namespace OCA\Gestion\Service\Devis;
use OCP\Files\IRootFolder;
class DevisPdfLayoutManager
{
/** @var IRootFolder */
private $rootFolder;
private $defaultImagePath = "/var/www/html/data/admin/files/.gestion/";
public const DEFAULT_NEXTCLOUD_ADMIN = 'admin';
public function __construct(IRootFolder $rootFolder)
{
$this->rootFolder = $rootFolder;
}
public function addPageHeader($pdf, $config, $address, $city)
{
if ($this->doesLogoExist()) {
$pdf->Image($this->defaultImagePath."logo.png", 10, 10, 75, 25);
}
$this->addCompanyInfo($pdf, $config, $address, $city);
}
public function addPageNumber($pdf, $currentPage, $totalPages)
{
if ($totalPages > 1) {
$pdf->SetXY(120, 5);
$pdf->SetFont("Arial", "B", 9);
$pdf->Cell(160, 8, $currentPage . '/' . $totalPages, 0, 0, 'C');
}
}
public function addClientInfoSection($pdf, $clientInfo, $firstDevis)
{
$date_temp = date("t-m-Y", strtotime($firstDevis['devis_date']));
$formatter = new \IntlDateFormatter('fr_FR', \IntlDateFormatter::LONG, \IntlDateFormatter::NONE);
$date_formated = $formatter->format(\DateTime::createFromFormat('d-m-Y', $date_temp));
$this->addClientInfo($pdf, $clientInfo, $date_formated);
}
public function addDocumentTitle($pdf, $firstDevis, $year)
{
$date_temp = date("t-m-Y", strtotime($firstDevis['devis_date']));
$formatter = new \IntlDateFormatter('fr_FR', \IntlDateFormatter::LONG, \IntlDateFormatter::NONE);
$date_formated = $formatter->format(\DateTime::createFromFormat('d-m-Y', $date_temp));
$pdf->SetFont("Arial", "B", 14);
$pdf->SetXY(10, 90);
$pdf->Cell(
0,
10,
"RECAPITULATIF DEVIS " .
strtoupper(\OCA\Gestion\Helpers\FileExportHelpers::ConvertSpecialChar(explode(' ', $date_formated)[1])) . " " . $year,
0,
0,
'C'
);
}
public function addLegalFooter($pdf, $config)
{
$y0 = 260;
$pageWidth = $pdf->GetPageWidth();
$pdf->SetFont('Arial', '', 6);
$pdf->SetXY(1, $y0 + 4);
$pdf->Cell($pageWidth, 5, mb_convert_encoding(html_entity_decode($config->legal_one), 'ISO-8859-1', 'UTF-8'), 0, 0, 'C');
$pdf->SetXY(1, $y0 + 8);
$pdf->Cell($pageWidth, 5, mb_convert_encoding(html_entity_decode($config->legal_two), 'ISO-8859-1', 'UTF-8'), 0, 0, 'C');
$pdf->SetXY(1, $y0 + 12);
$pdf->Cell($pageWidth, 5, mb_convert_encoding(html_entity_decode($config->telephone), 'ISO-8859-1', 'UTF-8'), 0, 0, 'C');
}
private function addCompanyInfo($pdf, $config, $address, $city)
{
$companyInfoXAxis = 10;
$companyInfoYAxis = 40;
$pdf->SetFont('Arial', '', 11);
$pdf->SetXY($companyInfoXAxis, $companyInfoYAxis);
$pdf->Cell(0, 7, \OCA\Gestion\Helpers\FileExportHelpers::FormatTextForExport($config->entreprise));
$companyInfoYAxis += 7;
$pdf->SetXY($companyInfoXAxis, $companyInfoYAxis);
$pdf->Cell(0, 7, \OCA\Gestion\Helpers\FileExportHelpers::FormatTextForExport($address));
$companyInfoYAxis += 7;
$pdf->SetXY($companyInfoXAxis, $companyInfoYAxis);
$pdf->Cell(0, 7, \OCA\Gestion\Helpers\FileExportHelpers::FormatTextForExport($city));
$companyInfoYAxis += 7;
$pdf->SetXY($companyInfoXAxis, $companyInfoYAxis);
$pdf->Cell(0, 7, mb_convert_encoding(html_entity_decode('Tél : '), 'ISO-8859-1', 'UTF-8') . \OCA\Gestion\Helpers\FileExportHelpers::FormatTextForExport($config->telephone));
$companyInfoYAxis += 7;
$pdf->SetXY($companyInfoXAxis, $companyInfoYAxis);
$pdf->Cell(0, 7, 'Mail : ' . $config->mail);
}
private function addClientInfo($pdf, $clientInfo, $dateFormatted)
{
$clientInfoXAxis = 125;
$clientInfoYAxis = 40;
$pdf->SetFont('Arial', '', 11);
$pdf->SetXY($clientInfoXAxis, $clientInfoYAxis);
$pdf->Cell(0, 7, mb_convert_encoding($clientInfo['name'], 'ISO-8859-1', 'UTF-8'));
$clientInfoYAxis += 7;
$pdf->SetXY($clientInfoXAxis, $clientInfoYAxis);
$pdf->SetMargins(0, 0, 10);
$pdf->MultiCell(0, 7, trim(\OCA\Gestion\Helpers\FileExportHelpers::FormatTextForExport($clientInfo['address'])));
$pdf->SetMargins(0, 0, 0);
$clientInfoYAxis += 14;
$pdf->SetXY($clientInfoXAxis, $clientInfoYAxis);
$pdf->Cell(0, 7, trim(mb_convert_encoding(html_entity_decode($clientInfo['city']), 'ISO-8859-1', 'UTF-8')));
if (!empty($clientInfo['siret'])) {
$clientInfoYAxis += 7;
$pdf->SetXY($clientInfoXAxis, $clientInfoYAxis);
$pdf->Cell(0, 7, 'Siret: ' . \OCA\Gestion\Helpers\FileExportHelpers::FormatTextForExport($clientInfo['siret']));
}
if (!empty($clientInfo['email'])) {
$clientInfoYAxis += 7;
$pdf->SetXY($clientInfoXAxis, $clientInfoYAxis);
$pdf->Cell(0, 7, 'Email: ' . mb_convert_encoding(html_entity_decode($clientInfo['email']), 'ISO-8859-1', 'UTF-8'));
}
$clientInfoYAxis += 7;
$pdf->SetXY($clientInfoXAxis, $clientInfoYAxis);
$pdf->Cell(0, 7, "le " . mb_convert_encoding($dateFormatted, 'ISO-8859-1', 'UTF-8'));
}
private function doesLogoExist()
{
$storage = $this->rootFolder->getUserFolder(self::DEFAULT_NEXTCLOUD_ADMIN);
try {
if (isset($storage)) {
$storage->get('/.gestion/logo.png');
return true;
}
return false;
} catch (\OCP\Files\NotFoundException $e) {
return false;
}
}
}