This commit is contained in:
Tiavina 2025-06-02 15:07:56 +03:00
parent 0e4a019145
commit 235da11fe3

View File

@ -31,7 +31,8 @@ use \FPDF;
use OCA\Gestion\Helpers\FileExportHelpers; use OCA\Gestion\Helpers\FileExportHelpers;
use OCA\Gestion\Helpers\PriceHelpers; use OCA\Gestion\Helpers\PriceHelpers;
class InvoiceGroupPdfHandler extends FPDF { class InvoiceGroupPdfHandler extends FPDF
{
public $factureData = []; public $factureData = [];
public $logo = null; public $logo = null;
@ -58,8 +59,7 @@ class InvoiceGroupPdfHandler extends FPDF {
if ($this->logo != "nothing") { if ($this->logo != "nothing") {
$this->Image($this->logoPath . "logo.png", 2, 10, 75, 25); $this->Image($this->logoPath . "logo.png", 2, 10, 75, 25);
$this->AddWatermark(); $this->AddWatermark();
} } else {
else{
$this->Cell(55, 30, ''); $this->Cell(55, 30, '');
} }
$this->SetMargins(3, 0, 3); $this->SetMargins(3, 0, 3);
@ -99,7 +99,8 @@ class InvoiceGroupPdfHandler extends FPDF {
$this->SetDrawColor(0, 0, 0, $alpha * 255); $this->SetDrawColor(0, 0, 0, $alpha * 255);
} }
public function DrawInvoiceCompanyAndClientInfo(){ public function DrawInvoiceCompanyAndClientInfo()
{
$this->DrawInvoiceCompanyInfo(); $this->DrawInvoiceCompanyInfo();
$this->DrawInvoiceClientInfo(); $this->DrawInvoiceClientInfo();
@ -122,7 +123,8 @@ class InvoiceGroupPdfHandler extends FPDF {
$this->Cell(0, 10, utf8_decode(html_entity_decode($this->factureData['configuration']->legal_one)), 0, 0, 'C'); $this->Cell(0, 10, utf8_decode(html_entity_decode($this->factureData['configuration']->legal_one)), 0, 0, 'C');
} }
public function InvoicePdfFactory(array $factureData,$logo = null){ public function InvoicePdfFactory(array $factureData, $logo = null)
{
$this->factureData = $factureData; $this->factureData = $factureData;
$this->productsCount = $this->factureData["productsCount"]; $this->productsCount = $this->factureData["productsCount"];
$this->devisCount = count($this->factureData['devis']); $this->devisCount = count($this->factureData['devis']);
@ -132,19 +134,22 @@ class InvoiceGroupPdfHandler extends FPDF {
$this->logo = $logo; $this->logo = $logo;
} }
public function GetInvoiceFilename(){ public function GetInvoiceFilename()
{
$factureNum = $this->factureData['num']; $factureNum = $this->factureData['num'];
$factureNum = str_replace('/', '-', $factureNum); $factureNum = str_replace('/', '-', $factureNum);
$clientName = str_replace(' ', ' ', $this->factureData['group_name'] ?? ''); $clientName = str_replace(' ', ' ', $this->factureData['group_name'] ?? '');
return 'FACTURE' . '_' . $factureNum . '_' . mb_strtoupper($clientName, 'UTF-8'); return 'FACTURE' . '_' . $factureNum . '_' . mb_strtoupper($clientName, 'UTF-8');
} }
public function DrawPageNumbersText($pageNumber,$pageCount){ public function DrawPageNumbersText($pageNumber, $pageCount)
{
$this->SetXY(120, 5); $this->SetXY(120, 5);
$this->Cell(160, 8, $pageNumber . '/' . $pageCount, 0, 0, 'C'); $this->Cell(160, 8, $pageNumber . '/' . $pageCount, 0, 0, 'C');
} }
public function DrawArticlesTable(){ public function DrawArticlesTable()
{
$pageCount = ceil($this->devisCount / $this->maxArticlePerPage); $pageCount = ceil($this->devisCount / $this->maxArticlePerPage);
$pageNumber = 1; $pageNumber = 1;
while ($pageNumber <= $pageCount) { while ($pageNumber <= $pageCount) {
@ -159,7 +164,8 @@ class InvoiceGroupPdfHandler extends FPDF {
} }
} }
public function DrawInvoiceCompanyInfo(){ public function DrawInvoiceCompanyInfo()
{
$this->SetY(40); $this->SetY(40);
$this->SetFont('ComicSans', '', 10); $this->SetFont('ComicSans', '', 10);
$this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport($this->factureData['configuration']->entreprise), 0, 1); $this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport($this->factureData['configuration']->entreprise), 0, 1);
@ -168,7 +174,8 @@ class InvoiceGroupPdfHandler extends FPDF {
$this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport('Tél : ') . FileExportHelpers::FormatTextForExport($this->factureData['configuration']->telephone), 0, 1); $this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport('Tél : ') . FileExportHelpers::FormatTextForExport($this->factureData['configuration']->telephone), 0, 1);
$this->Cell(0, $this->interLigneHeader, 'Mail : ' . $this->factureData['configuration']->mail, 0, 1); $this->Cell(0, $this->interLigneHeader, 'Mail : ' . $this->factureData['configuration']->mail, 0, 1);
} }
public function DrawInvoiceClientInfo(){ public function DrawInvoiceClientInfo()
{
$this->SetFont('ComicSans', '', 10); $this->SetFont('ComicSans', '', 10);
$clientName = $this->factureData['group_name']; $clientName = $this->factureData['group_name'];
$clientInfoXAxis = 135; $clientInfoXAxis = 135;
@ -207,8 +214,7 @@ class InvoiceGroupPdfHandler extends FPDF {
$modulo = (int) round($gapBetweenAddressLines / $this->interLigneHeader); $modulo = (int) round($gapBetweenAddressLines / $this->interLigneHeader);
$clientInfoYAxis += $modulo * $this->interLigneHeader; $clientInfoYAxis += $modulo * $this->interLigneHeader;
} }
} } else {
else{
$clientInfoYAxis += $this->interLigneHeader; $clientInfoYAxis += $this->interLigneHeader;
} }
@ -237,9 +243,10 @@ class InvoiceGroupPdfHandler extends FPDF {
$clientInfoYAxis += $this->interLigneHeader; $clientInfoYAxis += $this->interLigneHeader;
} }
} }
$this->SetXY($clientInfoXAxis, $clientInfoYAxis);
$this->Cell(0, $this->interLigneHeader, trim(FileExportHelpers::FormatTextForExport($this->factureData['client_adress_city']))); $this->Cell(0, $this->interLigneHeader, trim(FileExportHelpers::FormatTextForExport($this->factureData['client_adress_city'])));
if ($this->factureData['siret']) { if ($this->factureData['siret']) {
$clientInfoYAxis += $this->interLigneHeader;
$this->SetXY($clientInfoXAxis, $clientInfoYAxis); $this->SetXY($clientInfoXAxis, $clientInfoYAxis);
$this->Cell(0, $this->interLigneHeader, 'Siret: ' . $this->factureData['siret']); $this->Cell(0, $this->interLigneHeader, 'Siret: ' . $this->factureData['siret']);
} }
@ -247,7 +254,8 @@ class InvoiceGroupPdfHandler extends FPDF {
public function DrawInvoiceInfoTable(){ public function DrawInvoiceInfoTable()
{
$startInvoiceInfoTable = 70; $startInvoiceInfoTable = 70;
$this->setY($startInvoiceInfoTable); $this->setY($startInvoiceInfoTable);
@ -273,7 +281,8 @@ class InvoiceGroupPdfHandler extends FPDF {
$this->startingYOfArticlesTable = $startInvoiceInfoTable + 20; $this->startingYOfArticlesTable = $startInvoiceInfoTable + 20;
} }
public function DrawArticlesTableRect(){ public function DrawArticlesTableRect()
{
$this->SetLineWidth(0.2); $this->SetLineWidth(0.2);
$gapBetweenStartingOfArticlesTableAndColumnName = 7; $gapBetweenStartingOfArticlesTableAndColumnName = 7;
@ -292,7 +301,8 @@ class InvoiceGroupPdfHandler extends FPDF {
$this->Line(182 + $additionalMargRight, $this->startingYOfArticlesTable, 182 + $additionalMargRight, $endingLine); $this->Line(182 + $additionalMargRight, $this->startingYOfArticlesTable, 182 + $additionalMargRight, $endingLine);
} }
public function DrawArticlesTableHeader(){ public function DrawArticlesTableHeader()
{
$additionalMargRight = 1; $additionalMargRight = 1;
$tvaValue = $this->factureData["configuration"]->tva_default; $tvaValue = $this->factureData["configuration"]->tva_default;
$columnNameY = $this->startingYOfArticlesTable - 1.5; $columnNameY = $this->startingYOfArticlesTable - 1.5;
@ -313,7 +323,8 @@ class InvoiceGroupPdfHandler extends FPDF {
$this->Cell(20, 10, "Prix Uni. TTC", 0, 0, 'C'); $this->Cell(20, 10, "Prix Uni. TTC", 0, 0, 'C');
} }
public function DrawArticlesTableValue(){ public function DrawArticlesTableValue()
{
// Set espacement avant de continue // Set espacement avant de continue
$this->SetFont('ComicSans', '', 10); $this->SetFont('ComicSans', '', 10);
@ -390,7 +401,8 @@ class InvoiceGroupPdfHandler extends FPDF {
} }
public function DrawBankAndTotalPriceInfo(){ public function DrawBankAndTotalPriceInfo()
{
$startOfYAfterMainTable = 239; $startOfYAfterMainTable = 239;
$this->SetY($startOfYAfterMainTable); $this->SetY($startOfYAfterMainTable);
$this->SetFont('ComicSans', '', 8); $this->SetFont('ComicSans', '', 8);
@ -428,7 +440,8 @@ class InvoiceGroupPdfHandler extends FPDF {
} }
} }
public function SetFactureContent(){ public function SetFactureContent()
{
$this->AddPage(); $this->AddPage();
$this->SetMargins(2, 0, 3); $this->SetMargins(2, 0, 3);
$this->DrawArticlesTable(); $this->DrawArticlesTable();
@ -445,8 +458,7 @@ class InvoiceGroupPdfHandler extends FPDF {
$this->MultiCell($w, $h, $text, $border, $align, $fill); $this->MultiCell($w, $h, $text, $border, $align, $fill);
// Reset the line position to the right, like in Cell // Reset the line position to the right, like in Cell
if( $ln==0 ) if ($ln == 0) {
{
$this->SetXY($x, $y); $this->SetXY($x, $y);
} }
} }
@ -469,11 +481,9 @@ class InvoiceGroupPdfHandler extends FPDF {
$j = 0; $j = 0;
$l = 0; $l = 0;
$nl = 1; $nl = 1;
while($i<$nb) while ($i < $nb) {
{
$c = $s[$i]; $c = $s[$i];
if($c=="\n") if ($c == "\n") {
{
$i++; $i++;
$sep = -1; $sep = -1;
$j = $i; $j = $i;
@ -484,21 +494,17 @@ class InvoiceGroupPdfHandler extends FPDF {
if ($c == ' ') if ($c == ' ')
$sep = $i; $sep = $i;
$l += $cw[$c]; $l += $cw[$c];
if($l>$wmax) if ($l > $wmax) {
{ if ($sep == -1) {
if($sep==-1)
{
if ($i == $j) if ($i == $j)
$i++; $i++;
} } else
else
$i = $sep + 1; $i = $sep + 1;
$sep = -1; $sep = -1;
$j = $i; $j = $i;
$l = 0; $l = 0;
$nl++; $nl++;
} } else
else
$i++; $i++;
} }
return $nl; return $nl;
@ -545,12 +551,10 @@ class InvoiceGroupPdfHandler extends FPDF {
$xc = $x + $r; $xc = $x + $r;
$yc = $y + $r; $yc = $y + $r;
$this->_out(sprintf('%.2F %.2F l', ($x) * $k, ($hp - $yc) * $k)); $this->_out(sprintf('%.2F %.2F l', ($x) * $k, ($hp - $yc) * $k));
if (strpos($corners, '1')===false) if (strpos($corners, '1') === false) {
{
$this->_out(sprintf('%.2F %.2F l', ($x) * $k, ($hp - $y) * $k)); $this->_out(sprintf('%.2F %.2F l', ($x) * $k, ($hp - $y) * $k));
$this->_out(sprintf('%.2F %.2F l', ($x + $r) * $k, ($hp - $y) * $k)); $this->_out(sprintf('%.2F %.2F l', ($x + $r) * $k, ($hp - $y) * $k));
} } else
else
$this->_Arc($xc - $r, $yc - $r * $MyArc, $xc - $r * $MyArc, $yc - $r, $xc, $yc - $r); $this->_Arc($xc - $r, $yc - $r * $MyArc, $xc - $r * $MyArc, $yc - $r, $xc, $yc - $r);
$this->_out($op); $this->_out($op);
} }
@ -558,7 +562,14 @@ class InvoiceGroupPdfHandler extends FPDF {
private function _Arc($x1, $y1, $x2, $y2, $x3, $y3) private function _Arc($x1, $y1, $x2, $y2, $x3, $y3)
{ {
$h = $this->h; $h = $this->h;
$this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $x1*$this->k, ($h-$y1)*$this->k, $this->_out(sprintf(
$x2*$this->k, ($h-$y2)*$this->k, $x3*$this->k, ($h-$y3)*$this->k)); '%.2F %.2F %.2F %.2F %.2F %.2F c ',
$x1 * $this->k,
($h - $y1) * $this->k,
$x2 * $this->k,
($h - $y2) * $this->k,
$x3 * $this->k,
($h - $y3) * $this->k
));
} }
} }