diff --git a/gestion/lib/Service/InvoiceGroupPdfHandler/InvoiceGroupPdfHandler.php b/gestion/lib/Service/InvoiceGroupPdfHandler/InvoiceGroupPdfHandler.php index 3489319..c58e3a8 100644 --- a/gestion/lib/Service/InvoiceGroupPdfHandler/InvoiceGroupPdfHandler.php +++ b/gestion/lib/Service/InvoiceGroupPdfHandler/InvoiceGroupPdfHandler.php @@ -27,7 +27,7 @@ declare(strict_types=1); namespace OCA\Gestion\Service\InvoiceGroupPdfHandler; use DateTime; -use \FPDF; +use FPDF; use OCA\Gestion\Helpers\FileExportHelpers; use OCA\Gestion\Helpers\PriceHelpers; @@ -54,11 +54,11 @@ class InvoiceGroupPdfHandler extends FPDF public $additionalArticlesLineBasedOnMultiline = 0; public $interLigneHeader = 5; - function Header() + public function Header() { if ($this->logo != "nothing") { $this->Image($this->logoPath . "logo.png", 4, 2, 50, 35); - $this->AddWatermark(); + //$this->AddWatermark(); } else { $this->Cell(55, 30, ''); } @@ -66,7 +66,7 @@ class InvoiceGroupPdfHandler extends FPDF $this->DrawInvoiceCompanyAndClientInfo(); $this->DrawInvoiceInfoTable(); } - function AddWatermark() + public function AddWatermark() { try { $this->SetAlpha(0.2); @@ -74,29 +74,29 @@ class InvoiceGroupPdfHandler extends FPDF $imagePath = $this->logoPath . "filigrane_pdf.png"; list($originalWidth, $originalHeight) = getimagesize($imagePath); - // Convertir les dimensions de pixels à mm (1 pixel = 0.264583 mm) - // Convertir les dimensions de pixels à mm (1 pixel = 0.264583 mm) + // Convertir les dimensions de pixels à mm (1 pixel = 0.264583 mm) + // Convertir les dimensions de pixels à mm (1 pixel = 0.264583 mm) $originalWidth = $originalWidth * 0.264583; $originalHeight = $originalHeight * 0.264583; - // Augmenter l'échelle, par exemple, 1.5 pour 150% de la taille d'origine + // Augmenter l'échelle, par exemple, 1.5 pour 150% de la taille d'origine $scale = 1.7; $width = $originalWidth * $scale; $height = $originalHeight * $scale; - // Calculer la position pour centrer l'image - $x = (210 - $width) / 2 + 15; // Décalage à droite de 15 mm - $y = ((297 - $height) / 2) + 21; // 297 mm est la hauteur d'une page A4 + // Calculer la position pour centrer l'image + $x = (210 - $width) / 2 + 15; // Décalage à droite de 15 mm + $y = ((297 - $height) / 2) + 21; // 297 mm est la hauteur d'une page A4 - // Ajouter l'image en filigrane - $this->Image($imagePath, $x, $y, $width, $height); // Chemin, position x, position y, largeur, hauteur - $this->SetAlpha(0.1); // Définir l'opacité + // Ajouter l'image en filigrane + $this->Image($imagePath, $x, $y, $width, $height); // Chemin, position x, position y, largeur, hauteur + $this->SetAlpha(0.1); // Définir l'opacité } catch (\Throwable $th) { } - + } - function SetAlpha($alpha) + public function SetAlpha($alpha) { // Appliquer la transparence au document $this->SetFillColor(255, 255, 255, $alpha * 255); @@ -111,7 +111,7 @@ class InvoiceGroupPdfHandler extends FPDF } - function Footer() + public function Footer() { $this->SetY(-34); $this->SetFont('Arial', '', 7); @@ -300,7 +300,7 @@ class InvoiceGroupPdfHandler extends FPDF // les traits verticaux colonnes $additionalMargRight = 1; $endingLine = 233 + $additionnalheight; - $this->Line( 27 + $additionalMargRight, $this->startingYOfArticlesTable, 27 + $additionalMargRight, $endingLine); + $this->Line(27 + $additionalMargRight, $this->startingYOfArticlesTable, 27 + $additionalMargRight, $endingLine); $this->Line(142 + $additionalMargRight, $this->startingYOfArticlesTable, 142 + $additionalMargRight, $endingLine); $this->Line(164 + $additionalMargRight, $this->startingYOfArticlesTable, 164 + $additionalMargRight, $endingLine); $this->Line(182 + $additionalMargRight, $this->startingYOfArticlesTable, 182 + $additionalMargRight, $endingLine); @@ -330,7 +330,7 @@ class InvoiceGroupPdfHandler extends FPDF public function DrawArticlesTableValue() { - // Set espacement avant de continue + // Set espacement avant de continue $this->SetFont('Arial', '', 10); $devisData = $this->factureData['devis']; @@ -340,7 +340,7 @@ class InvoiceGroupPdfHandler extends FPDF $totalTva = 0; $yValue = $this->startingYOfArticlesTable + 13; // $maxDescriptionWidth = 102; - $maxDescriptionWidth = 104.3; + $maxDescriptionWidth = 104.3; // $maxDescriptionWidth = 51; $currentIndexPosition = $this->currentIndexPosition; for ($currentIndexPosition; $currentIndexPosition < ($this->initialIndexPosition + $this->devisCountToGet); $currentIndexPosition++) { @@ -358,7 +358,7 @@ class InvoiceGroupPdfHandler extends FPDF $totalTtc += $valueTtc; $productDescription = $product["produit_description"] ?? ""; $currentDevisDefuntName = $currentDevis["defunt_nom"] ?? ""; - + $dateValue = ""; $dateAndDefuntName = ""; if ($productIncrement == 0) { @@ -407,9 +407,9 @@ class InvoiceGroupPdfHandler extends FPDF $productIncrement++; } $yValue += 6; - $isLastLigneDevis = $currentIndexPosition == (($this->initialIndexPosition + $this->devisCountToGet) -1); + $isLastLigneDevis = $currentIndexPosition == (($this->initialIndexPosition + $this->devisCountToGet) - 1); if (!$isLastLigneDevis) { - $this->Line(3, $yValue , 207, $yValue); + $this->Line(3, $yValue, 207, $yValue); } } $this->currentIndexPosition = $currentIndexPosition; @@ -467,7 +467,7 @@ class InvoiceGroupPdfHandler extends FPDF $this->DrawBankAndTotalPriceInfo(); } - function MultiAlignCell($w, $h, $text, $border = 0, $ln = 0, $align = 'L', $fill = false) + public function MultiAlignCell($w, $h, $text, $border = 0, $ln = 0, $align = 'L', $fill = false) { // Store reset values for (x,y) positions $x = $this->GetX() + $w; @@ -482,19 +482,22 @@ class InvoiceGroupPdfHandler extends FPDF } } - function NbLines($w, $txt) + public function NbLines($w, $txt) { // Compute the number of lines a MultiCell of width w will take - if (!isset($this->CurrentFont)) + if (!isset($this->CurrentFont)) { $this->Error('No font has been set'); + } $cw = $this->CurrentFont['cw']; - if ($w == 0) + if ($w == 0) { $w = $this->w - $this->rMargin - $this->x; + } $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; $s = str_replace("\r", '', (string) $txt); $nb = strlen($s); - if ($nb > 0 && $s[$nb - 1] == "\n") + if ($nb > 0 && $s[$nb - 1] == "\n") { $nb--; + } $sep = -1; $i = 0; $j = 0; @@ -510,21 +513,25 @@ class InvoiceGroupPdfHandler extends FPDF $nl++; continue; } - if ($c == ' ') + if ($c == ' ') { $sep = $i; + } $l += $cw[$c]; if ($l > $wmax) { if ($sep == -1) { - if ($i == $j) + if ($i == $j) { $i++; - } else + } + } else { $i = $sep + 1; + } $sep = -1; $j = $i; $l = 0; $nl++; - } else + } else { $i++; + } } return $nl; } @@ -534,38 +541,42 @@ class InvoiceGroupPdfHandler extends FPDF { $k = $this->k; $hp = $this->h; - if ($style == 'F') + if ($style == 'F') { $op = 'f'; - elseif ($style == 'FD' || $style == 'DF') + } elseif ($style == 'FD' || $style == 'DF') { $op = 'B'; - else + } else { $op = 'S'; + } $MyArc = 4 / 3 * (sqrt(2) - 1); $this->_out(sprintf('%.2F %.2F m', ($x + $r) * $k, ($hp - $y) * $k)); $xc = $x + $w - $r; $yc = $y + $r; $this->_out(sprintf('%.2F %.2F l', $xc * $k, ($hp - $y) * $k)); - if (strpos($corners, '2') === false) + if (strpos($corners, '2') === false) { $this->_out(sprintf('%.2F %.2F l', ($x + $w) * $k, ($hp - $y) * $k)); - else + } else { $this->_Arc($xc + $r * $MyArc, $yc - $r, $xc + $r, $yc - $r * $MyArc, $xc + $r, $yc); + } $xc = $x + $w - $r; $yc = $y + $h - $r; $this->_out(sprintf('%.2F %.2F l', ($x + $w) * $k, ($hp - $yc) * $k)); - if (strpos($corners, '3') === false) + if (strpos($corners, '3') === false) { $this->_out(sprintf('%.2F %.2F l', ($x + $w) * $k, ($hp - ($y + $h)) * $k)); - else + } else { $this->_Arc($xc + $r, $yc + $r * $MyArc, $xc + $r * $MyArc, $yc + $r, $xc, $yc + $r); + } $xc = $x + $r; $yc = $y + $h - $r; $this->_out(sprintf('%.2F %.2F l', $xc * $k, ($hp - ($y + $h)) * $k)); - if (strpos($corners, '4') === false) + if (strpos($corners, '4') === false) { $this->_out(sprintf('%.2F %.2F l', ($x) * $k, ($hp - ($y + $h)) * $k)); - else + } else { $this->_Arc($xc - $r * $MyArc, $yc + $r, $xc - $r, $yc + $r * $MyArc, $xc - $r, $yc); + } $xc = $x + $r; $yc = $y + $r; @@ -573,8 +584,9 @@ class InvoiceGroupPdfHandler extends FPDF if (strpos($corners, '1') === false) { $this->_out(sprintf('%.2F %.2F l', ($x) * $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->_out($op); } diff --git a/gestion/lib/Service/InvoicePdfHandler.php b/gestion/lib/Service/InvoicePdfHandler.php index c7a0278..797bd4f 100644 --- a/gestion/lib/Service/InvoicePdfHandler.php +++ b/gestion/lib/Service/InvoicePdfHandler.php @@ -27,7 +27,7 @@ declare(strict_types=1); namespace OCA\Gestion\Service; use DateTime; -use \FPDF; +use FPDF; use OCA\Gestion\Constants\MultipleFactureTypeConstant; use OCA\Gestion\Helpers\DateHelpers; use OCA\Gestion\Helpers\FileExportHelpers; @@ -35,7 +35,6 @@ use OCA\Gestion\Helpers\PriceHelpers; class InvoicePdfHandler extends FPDF { - private $multipleFactureData = []; private $factureData = []; private $logo = null; @@ -49,17 +48,17 @@ class InvoicePdfHandler extends FPDF private $articleTablesHeight = 130; public $interLigneHeader = 5; - function Header() + public function Header() { if ($this->logo != "nothing") { $this->Image($this->logoPath . "logo.png", 4, 2, 50, 35); - $this->AddWatermark(); + //$this->AddWatermark(); } else { $this->Cell(55, 30, ''); } } - function AddWatermark() + public function AddWatermark() { try { $this->SetAlpha(0.2); @@ -67,29 +66,29 @@ class InvoicePdfHandler extends FPDF $imagePath = $this->logoPath . "filigrane_pdf.png"; list($originalWidth, $originalHeight) = getimagesize($imagePath); - // Convertir les dimensions de pixels à mm (1 pixel = 0.264583 mm) - // Convertir les dimensions de pixels à mm (1 pixel = 0.264583 mm) + // Convertir les dimensions de pixels à mm (1 pixel = 0.264583 mm) + // Convertir les dimensions de pixels à mm (1 pixel = 0.264583 mm) $originalWidth = $originalWidth * 0.264583; $originalHeight = $originalHeight * 0.264583; - // Augmenter l'échelle, par exemple, 1.5 pour 150% de la taille d'origine + // Augmenter l'échelle, par exemple, 1.5 pour 150% de la taille d'origine $scale = 1.7; $width = $originalWidth * $scale; $height = $originalHeight * $scale; - // Calculer la position pour centrer l'image - $x = (210 - $width) / 2 + 15; // Décalage à droite de 15 mm - $y = ((297 - $height) / 2) + 21; // 297 mm est la hauteur d'une page A4 + // Calculer la position pour centrer l'image + $x = (210 - $width) / 2 + 15; // Décalage à droite de 15 mm + $y = ((297 - $height) / 2) + 21; // 297 mm est la hauteur d'une page A4 - // Ajouter l'image en filigrane - $this->Image($imagePath, $x, $y, $width, $height); // Chemin, position x, position y, largeur, hauteur - $this->SetAlpha(0.1); // Définir l'opacité + // Ajouter l'image en filigrane + $this->Image($imagePath, $x, $y, $width, $height); // Chemin, position x, position y, largeur, hauteur + $this->SetAlpha(0.1); // Définir l'opacité } catch (\Exception $e) { - + } - + } - function SetAlpha($alpha) + public function SetAlpha($alpha) { // Appliquer la transparence au document $this->SetFillColor(255, 255, 255, $alpha * 255); @@ -98,7 +97,7 @@ class InvoicePdfHandler extends FPDF } - function Footer() + public function Footer() { $this->SetY(-34); $this->SetFont('Arial', '', 7); @@ -278,7 +277,7 @@ class InvoicePdfHandler extends FPDF $this->Line(3, $this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName, 207, $this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName); // les traits verticaux colonnes $additionalMargRight = 1; - $endingLine = $this->thereIsOrderOrCaseNumber ? 231 : 230; // mois +1 pour le groupe + $endingLine = $this->thereIsOrderOrCaseNumber ? 231 : 230; // mois +1 pour le groupe $this->Line(27 + $additionalMargRight, $this->startingYOfArticlesTable, 27 + $additionalMargRight, $endingLine); $this->Line(142 + $additionalMargRight, $this->startingYOfArticlesTable, 142 + $additionalMargRight, $endingLine); $this->Line(164 + $additionalMargRight, $this->startingYOfArticlesTable, 164 + $additionalMargRight, $endingLine); @@ -331,20 +330,20 @@ class InvoicePdfHandler extends FPDF if ($product === reset($products)) { $dateValue = $devisDate; // $productDescription .= " de " . FileExportHelpers::GetSexeLabel($this->factureData['defunt_sexe']) . ' ' . $this->factureData["defunt_nom"]; - $this->SetXY(70, $yValue); + $this->SetXY(70, $yValue); $this->Cell(5, 6, $this->factureData["defunt_nom"], 0, 0); } $yValue += 3; $tvaAmount = $valueTtc - $valueHt; $this->SetXY(5, $yValue + 5); $this->Cell(5, 6, $dateValue, 0, 0); - - $this->SetXY(30, $yValue +5); + + $this->SetXY(30, $yValue + 5); $this->MultiAlignCell($maxDescriptionWidth, 6, utf8_decode(html_entity_decode($productDescription)), 0, '0', ); - $this->SetXY(144, $yValue +5); + $this->SetXY(144, $yValue + 5); $this->Cell(20, 6, number_format($valueHt, 2, '.', '') . chr(128), 0, 0, 'C'); $this->SetXY(165, $yValue + 5); @@ -421,7 +420,7 @@ class InvoicePdfHandler extends FPDF $this->DrawBankAndTotalPriceInfo($totalPriceValue); } - function MultiAlignCell($w, $h, $text, $border = 0, $ln = 0, $align = 'L', $fill = false) + public function MultiAlignCell($w, $h, $text, $border = 0, $ln = 0, $align = 'L', $fill = false) { // Store reset values for (x,y) positions $x = $this->GetX() + $w; @@ -436,19 +435,22 @@ class InvoicePdfHandler extends FPDF } } - function NbLines($w, $txt) + public function NbLines($w, $txt) { // Compute the number of lines a MultiCell of width w will take - if (!isset($this->CurrentFont)) + if (!isset($this->CurrentFont)) { $this->Error('No font has been set'); + } $cw = $this->CurrentFont['cw']; - if ($w == 0) + if ($w == 0) { $w = $this->w - $this->rMargin - $this->x; + } $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; $s = str_replace("\r", '', (string) $txt); $nb = strlen($s); - if ($nb > 0 && $s[$nb - 1] == "\n") + if ($nb > 0 && $s[$nb - 1] == "\n") { $nb--; + } $sep = -1; $i = 0; $j = 0; @@ -464,21 +466,25 @@ class InvoicePdfHandler extends FPDF $nl++; continue; } - if ($c == ' ') + if ($c == ' ') { $sep = $i; + } $l += $cw[$c]; if ($l > $wmax) { if ($sep == -1) { - if ($i == $j) + if ($i == $j) { $i++; - } else + } + } else { $i = $sep + 1; + } $sep = -1; $j = $i; $l = 0; $nl++; - } else + } else { $i++; + } } return $nl; }