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;
@ -55,14 +56,13 @@ class InvoiceGroupPdfHandler extends FPDF {
function Header() function Header()
{ {
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 {
$this->Cell(55, 30, '');
} }
else{ $this->SetMargins(3, 0, 3);
$this->Cell(55,30,'');
}
$this->SetMargins(3,0,3);
$this->DrawInvoiceCompanyAndClientInfo(); $this->DrawInvoiceCompanyAndClientInfo();
$this->DrawInvoiceInfoTable(); $this->DrawInvoiceInfoTable();
} }
@ -84,7 +84,7 @@ class InvoiceGroupPdfHandler extends FPDF {
$height = $originalHeight * $scale; $height = $originalHeight * $scale;
// Calculer la position pour centrer l'image // Calculer la position pour centrer l'image
$x = (210 - $width) / 2 + 15; // Décalage à droite de 15 mm $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 $y = ((297 - $height) / 2) + 21; // 297 mm est la hauteur d'une page A4
// Ajouter l'image en filigrane // Ajouter l'image en filigrane
$this->Image($imagePath, $x, $y, $width, $height); // Chemin, position x, position y, largeur, hauteur $this->Image($imagePath, $x, $y, $width, $height); // Chemin, position x, position y, largeur, hauteur
@ -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();
@ -110,47 +111,51 @@ class InvoiceGroupPdfHandler extends FPDF {
$this->SetY(-34); $this->SetY(-34);
$this->SetFont('ComicSans', '', 7); $this->SetFont('ComicSans', '', 7);
$this->MultiCell(0,4,utf8_decode(html_entity_decode('Tout retard de paiement entraînera de plein droit une pénalité de retard de 3 fois le taux légal '))); $this->MultiCell(0, 4, utf8_decode(html_entity_decode('Tout retard de paiement entraînera de plein droit une pénalité de retard de 3 fois le taux légal ')));
$this->MultiCell(0,4,utf8_decode(html_entity_decode('(Loi 2008-776 du 4 août 2008) et une indemnité forfaitaire de 40 EUR pour frais de recouvrement sera appliquée.'))); $this->MultiCell(0, 4, utf8_decode(html_entity_decode('(Loi 2008-776 du 4 août 2008) et une indemnité forfaitaire de 40 EUR pour frais de recouvrement sera appliquée.')));
$this->Ln(1); $this->Ln(1);
$this->MultiCell(0,4,utf8_decode(html_entity_decode('Si les frais de recouvrement sont supérieurs à ce montant forfaitaire, une indemnisation complémentaire'))); $this->MultiCell(0, 4, utf8_decode(html_entity_decode('Si les frais de recouvrement sont supérieurs à ce montant forfaitaire, une indemnisation complémentaire')));
$this->MultiCell(0,4,utf8_decode(html_entity_decode('sera due sur présentation de justificatifs (articles L.441-3 et L.441-6 du code de commerce).'))); $this->MultiCell(0, 4, utf8_decode(html_entity_decode('sera due sur présentation de justificatifs (articles L.441-3 et L.441-6 du code de commerce).')));
$this->SetY(-10); $this->SetY(-10);
$this->SetFont('ComicSans', '', 7); $this->SetFont('ComicSans', '', 7);
$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']);
$this->totalPrices = $this->factureData["totalPrices"]; $this->totalPrices = $this->factureData["totalPrices"];
$this->devisCountToGet = ($this->devisCount <= $this->maxArticlePerPage ) ? $this->devisCount : $this->maxArticlePerPage; $this->devisCountToGet = ($this->devisCount <= $this->maxArticlePerPage) ? $this->devisCount : $this->maxArticlePerPage;
$this->devisList = $this->factureData['devis']; $this->devisList = $this->factureData['devis'];
$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('&nbsp;',' ',$this->factureData['group_name'] ?? ''); $clientName = str_replace('&nbsp;', ' ', $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->Cell( 160, 8, $pageNumber . '/' . $pageCount, 0, 0, 'C'); $this->SetXY(120, 5);
$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) {
if($pageNumber > 1){ if ($pageNumber > 1) {
$this->AddPage(); $this->AddPage();
$this->DrawPageNumbersText($pageNumber,$pageCount); $this->DrawPageNumbersText($pageNumber, $pageCount);
} }
$this->DrawArticlesTableRect(); $this->DrawArticlesTableRect();
$this->DrawArticlesTableHeader(); $this->DrawArticlesTableHeader();
@ -159,16 +164,18 @@ 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);
$this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport($this->factureData['configuration_adresse']), 0, 1); $this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport($this->factureData['configuration_adresse']), 0, 1);
$this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport($this->factureData['configuration_adresse_city']), 0, 1); $this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport($this->factureData['configuration_adresse_city']), 0, 1);
$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;
@ -179,80 +186,81 @@ class InvoiceGroupPdfHandler extends FPDF {
$address = FileExportHelpers::FormatTextForExport(trim($clientAddress)); $address = FileExportHelpers::FormatTextForExport(trim($clientAddress));
$addressWidth = $this->GetStringWidth($address); $addressWidth = $this->GetStringWidth($address);
$addressWidthGreaterThanMaxWidth = $addressWidth > $availableWidhtForClientInfo; $addressWidthGreaterThanMaxWidth = $addressWidth > $availableWidhtForClientInfo;
$addressIsMoreThanTwoLines = ($addressWidth/$availableWidhtForClientInfo) > 2; $addressIsMoreThanTwoLines = ($addressWidth / $availableWidhtForClientInfo) > 2;
$clientInfoYAxis =$addressIsMoreThanTwoLines ? 35 : 40; $clientInfoYAxis = $addressIsMoreThanTwoLines ? 35 : 40;
$this->SetXY($clientInfoXAxis,$clientInfoYAxis); $this->SetXY($clientInfoXAxis, $clientInfoYAxis);
$this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport($clientName)); $this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport($clientName));
$clientInfoYAxis += $this->interLigneHeader; $clientInfoYAxis += $this->interLigneHeader;
$gapBetweenAddressLines = 0; $gapBetweenAddressLines = 0;
if ( $this->factureData['group_type'] == 'single' ) { if ($this->factureData['group_type'] == 'single') {
$isMultiline = false; $isMultiline = false;
$this->SetXY($clientInfoXAxis,$clientInfoYAxis); $this->SetXY($clientInfoXAxis, $clientInfoYAxis);
if ($addressWidthGreaterThanMaxWidth) { if ($addressWidthGreaterThanMaxWidth) {
$yBefore = $this->GetY(); $yBefore = $this->GetY();
$this->MultiCell($availableWidhtForClientInfo, $this->interLigneHeader, $address,0,'L'); $this->MultiCell($availableWidhtForClientInfo, $this->interLigneHeader, $address, 0, 'L');
$yAfter = $this->GetY(); $yAfter = $this->GetY();
$gapBetweenAddressLines = $yAfter - $yBefore; $gapBetweenAddressLines = $yAfter - $yBefore;
$isMultiline = ($gapBetweenAddressLines) > $this->interLigneHeader; $isMultiline = ($gapBetweenAddressLines) > $this->interLigneHeader;
if($isMultiline){ if ($isMultiline) {
$this->SetXY($this->GetX(),$yBefore); $this->SetXY($this->GetX(), $yBefore);
} }
} else { } else {
$this->Cell($availableWidhtForClientInfo, $this->interLigneHeader, $address); $this->Cell($availableWidhtForClientInfo, $this->interLigneHeader, $address);
} }
if($isMultiline){ if ($isMultiline) {
if($gapBetweenAddressLines > 0){ if ($gapBetweenAddressLines > 0) {
$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;
} }
}else{ } else {
$clientAddresses = explode(",",$clientAddress); $clientAddresses = explode(",", $clientAddress);
foreach ($clientAddresses as $address) { foreach ($clientAddresses as $address) {
$address = FileExportHelpers::FormatTextForExport(trim($address)); $address = FileExportHelpers::FormatTextForExport(trim($address));
$addressWidth = $this->GetStringWidth($address); $addressWidth = $this->GetStringWidth($address);
$addressWidthGreaterThanMaxWidth = $addressWidth > $availableWidhtForClientInfo; $addressWidthGreaterThanMaxWidth = $addressWidth > $availableWidhtForClientInfo;
$isMultiline = false; $isMultiline = false;
$this->SetXY($clientInfoXAxis,$clientInfoYAxis); $this->SetXY($clientInfoXAxis, $clientInfoYAxis);
if ($addressWidthGreaterThanMaxWidth) { if ($addressWidthGreaterThanMaxWidth) {
$yBefore = $this->GetY(); $yBefore = $this->GetY();
$this->MultiCell($availableWidhtForClientInfo, $this->interLigneHeader, $address,0,'L'); $this->MultiCell($availableWidhtForClientInfo, $this->interLigneHeader, $address, 0, 'L');
$yAfter = $this->GetY(); $yAfter = $this->GetY();
$isMultiline = ($yAfter - $yBefore) > $this->interLigneHeader; $isMultiline = ($yAfter - $yBefore) > $this->interLigneHeader;
if($isMultiline){ if ($isMultiline) {
$this->SetXY($this->GetX(),$yBefore); $this->SetXY($this->GetX(), $yBefore);
} }
} else { } else {
$this->Cell($availableWidhtForClientInfo, $this->interLigneHeader, $address); $this->Cell($availableWidhtForClientInfo, $this->interLigneHeader, $address);
} }
if($isMultiline){ if ($isMultiline) {
$clientInfoYAxis += $this->interLigneHeader; $clientInfoYAxis += $this->interLigneHeader;
} }
$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']) {
$this->SetXY($clientInfoXAxis,$clientInfoYAxis); $clientInfoYAxis += $this->interLigneHeader;
$this->SetXY($clientInfoXAxis, $clientInfoYAxis);
$this->Cell(0, $this->interLigneHeader, 'Siret: ' . $this->factureData['siret']); $this->Cell(0, $this->interLigneHeader, 'Siret: ' . $this->factureData['siret']);
} }
} }
public function DrawInvoiceInfoTable(){ public function DrawInvoiceInfoTable()
{
$startInvoiceInfoTable = 70; $startInvoiceInfoTable = 70;
$this->setY($startInvoiceInfoTable); $this->setY($startInvoiceInfoTable);
$factureDatePaiement = $this->factureData['date_paiement']; $factureDatePaiement = $this->factureData['date_paiement'];
$factureDatePaiement = DateTime::createFromFormat('Y-m-d',$factureDatePaiement); $factureDatePaiement = DateTime::createFromFormat('Y-m-d', $factureDatePaiement);
$factureDateEcheance = $factureDatePaiement; $factureDateEcheance = $factureDatePaiement;
$factureDatePaiement = $factureDatePaiement->format('d-m-Y'); $factureDatePaiement = $factureDatePaiement->format('d-m-Y');
$factureDateEcheance->modify('last day of next month'); $factureDateEcheance->modify('last day of next month');
@ -273,26 +281,28 @@ 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;
$additionnalheight = 0.75; $additionnalheight = 0.75;
$tableHeight = $this->thereIsOrderOrCaseNumber ? (137 + $additionnalheight) : ( 137 + 6 + $additionnalheight); $tableHeight = $this->thereIsOrderOrCaseNumber ? (137 + $additionnalheight) : (137 + 6 + $additionnalheight);
$this->Rect(3, $this->startingYOfArticlesTable, 204, $tableHeight, "D"); $this->Rect(3, $this->startingYOfArticlesTable, 204, $tableHeight, "D");
// $this->RoundedRect(3, $this->startingYOfArticlesTable, 204, $tableHeight,5 ,'1234',"D"); // $this->RoundedRect(3, $this->startingYOfArticlesTable, 204, $tableHeight,5 ,'1234',"D");
// cadre titre des colonnes // cadre titre des colonnes
$this->Line(3, $this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName, 207,$this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName); $this->Line(3, $this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName, 207, $this->startingYOfArticlesTable + $gapBetweenStartingOfArticlesTableAndColumnName);
// les traits verticaux colonnes // les traits verticaux colonnes
$additionalMargRight = 1; $additionalMargRight = 1;
$endingLine = 233 + $additionnalheight; $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(142 + $additionalMargRight, $this->startingYOfArticlesTable, 142 + $additionalMargRight, $endingLine);
$this->Line(164 + $additionalMargRight, $this->startingYOfArticlesTable, 164+ $additionalMargRight , $endingLine); $this->Line(164 + $additionalMargRight, $this->startingYOfArticlesTable, 164 + $additionalMargRight, $endingLine);
$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;
@ -309,14 +319,15 @@ class InvoiceGroupPdfHandler extends FPDF {
$this->SetXY(163 + $additionalMargRight, $columnNameY); $this->SetXY(163 + $additionalMargRight, $columnNameY);
$this->Cell(20, 10, 'TVA ' . $tvaValue . '%', 0, 0, 'C'); $this->Cell(20, 10, 'TVA ' . $tvaValue . '%', 0, 0, 'C');
$this->SetXY(185 , $columnNameY); $this->SetXY(185, $columnNameY);
$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);
$devisData = $this->factureData['devis']; $devisData = $this->factureData['devis'];
$tvaValue = $this->factureData["configuration"]->tva_default; $tvaValue = $this->factureData["configuration"]->tva_default;
$totalHt = 0; $totalHt = 0;
@ -325,58 +336,58 @@ class InvoiceGroupPdfHandler extends FPDF {
$yValue = $this->startingYOfArticlesTable + 13; $yValue = $this->startingYOfArticlesTable + 13;
$maxDescriptionWidth = 102; $maxDescriptionWidth = 102;
$currentIndexPosition = $this->currentIndexPosition; $currentIndexPosition = $this->currentIndexPosition;
for($currentIndexPosition;$currentIndexPosition<($this->initialIndexPosition + $this->devisCountToGet);$currentIndexPosition++){ for ($currentIndexPosition; $currentIndexPosition < ($this->initialIndexPosition + $this->devisCountToGet); $currentIndexPosition++) {
$currentDevis = $devisData[$currentIndexPosition]; $currentDevis = $devisData[$currentIndexPosition];
$devisDate = $currentDevis['devis_date']; $devisDate = $currentDevis['devis_date'];
$devisDate = DateTime::createFromFormat('Y-m-d',$devisDate); $devisDate = DateTime::createFromFormat('Y-m-d', $devisDate);
$devisDate = $devisDate->format('d-m-Y'); $devisDate = $devisDate->format('d-m-Y');
$products = $currentDevis["products"]; $products = $currentDevis["products"];
$productIncrement = 0; $productIncrement = 0;
foreach($products as $product){ foreach ($products as $product) {
$valueHt = $product['produit_price'] * $product["quantite"]; $valueHt = $product['produit_price'] * $product["quantite"];
$valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt,$tvaValue); $valueTtc = PriceHelpers::calculPriceWithVatValue($valueHt, $tvaValue);
$totalHt+=$valueHt; $totalHt += $valueHt;
$totalTtc+=$valueTtc; $totalTtc += $valueTtc;
$productDescription = $product["produit_description"] ?? ""; $productDescription = $product["produit_description"] ?? "";
$dateValue = ""; $dateValue = "";
if($productIncrement == 0){ if ($productIncrement == 0) {
$dateValue = $devisDate; $dateValue = $devisDate;
$productDescription .= " de " . $currentDevis["defunt_nom"] ?? ""; $productDescription .= " de " . $currentDevis["defunt_nom"] ?? "";
} }
$tvaAmount = $valueTtc - $valueHt; $tvaAmount = $valueTtc - $valueHt;
$this->SetXY(4,$yValue ); $this->SetXY(4, $yValue);
$this->Cell(5, 6, $dateValue, 0,0); $this->Cell(5, 6, $dateValue, 0, 0);
$this->SetXY( 30,$yValue ); $this->SetXY(30, $yValue);
$productDescription = FileExportHelpers::FormatTextForExport($productDescription); $productDescription = FileExportHelpers::FormatTextForExport($productDescription);
$productDescriptionWidth = $this->GetStringWidth($productDescription); $productDescriptionWidth = $this->GetStringWidth($productDescription);
$productDescriptionWidthIsGreaterThanMaxWidth = $productDescriptionWidth > $maxDescriptionWidth; $productDescriptionWidthIsGreaterThanMaxWidth = $productDescriptionWidth > $maxDescriptionWidth;
$productDescriptionIsMultiline = false; $productDescriptionIsMultiline = false;
if ($productDescriptionWidthIsGreaterThanMaxWidth) { if ($productDescriptionWidthIsGreaterThanMaxWidth) {
$yBefore = $this->GetY(); $yBefore = $this->GetY();
$this->MultiCell($maxDescriptionWidth, 6, $productDescription,0,'L'); $this->MultiCell($maxDescriptionWidth, 6, $productDescription, 0, 'L');
$yAfter = $this->GetY(); $yAfter = $this->GetY();
$productDescriptionIsMultiline = ($yAfter - $yBefore) > 6; $productDescriptionIsMultiline = ($yAfter - $yBefore) > 6;
if($productDescriptionIsMultiline){ if ($productDescriptionIsMultiline) {
$this->SetXY($this->GetX(),$yBefore); $this->SetXY($this->GetX(), $yBefore);
} }
} else { } else {
$this->Cell($maxDescriptionWidth, 6, $productDescription); $this->Cell($maxDescriptionWidth, 6, $productDescription);
} }
$this->SetXY(144,$yValue ); $this->SetXY(144, $yValue);
$this->Cell(20, 6, number_format($valueHt,2,'.','').chr(128), 0, 0, 'C'); $this->Cell(20, 6, number_format($valueHt, 2, '.', '') . chr(128), 0, 0, 'C');
$this->SetXY(165,$yValue ); $this->SetXY(165, $yValue);
$this->Cell(20, 6, number_format($tvaAmount,2,'.','').chr(128), 0, 0, 'C'); $this->Cell(20, 6, number_format($tvaAmount, 2, '.', '') . chr(128), 0, 0, 'C');
$this->SetXY( 182,$yValue ); $this->SetXY(182, $yValue);
$this->Cell(25, 6, number_format($valueTtc,2,'.','').chr(128), 0, 1, 'C'); $this->Cell(25, 6, number_format($valueTtc, 2, '.', '') . chr(128), 0, 1, 'C');
$yValue += 6; $yValue += 6;
$totalTva += $tvaAmount; $totalTva += $tvaAmount;
if($productDescriptionWidthIsGreaterThanMaxWidth){ if ($productDescriptionWidthIsGreaterThanMaxWidth) {
$yValue += 6; $yValue += 6;
} }
$productIncrement++; $productIncrement++;
@ -386,20 +397,21 @@ class InvoiceGroupPdfHandler extends FPDF {
$this->initialIndexPosition = $this->currentIndexPosition; $this->initialIndexPosition = $this->currentIndexPosition;
$chargedDevisCount = $this->currentIndexPosition + 1; $chargedDevisCount = $this->currentIndexPosition + 1;
$devisLeftToGet = $this->devisCount - $chargedDevisCount; $devisLeftToGet = $this->devisCount - $chargedDevisCount;
$this->devisCountToGet = ($devisLeftToGet < $this->maxArticlePerPage) ? $devisLeftToGet + 1: $this->maxArticlePerPage; $this->devisCountToGet = ($devisLeftToGet < $this->maxArticlePerPage) ? $devisLeftToGet + 1 : $this->maxArticlePerPage;
} }
public function DrawBankAndTotalPriceInfo(){ public function DrawBankAndTotalPriceInfo()
{
$startOfYAfterMainTable = 239; $startOfYAfterMainTable = 239;
$this->SetY( $startOfYAfterMainTable); $this->SetY($startOfYAfterMainTable);
$this->SetFont('ComicSans', '', 8); $this->SetFont('ComicSans', '', 8);
$this->MultiCell(0,4,utf8_decode(html_entity_decode("Paiement à votre convenance par chèque à l'ordre de ". $this->factureData['configuration']->entreprise))); $this->MultiCell(0, 4, utf8_decode(html_entity_decode("Paiement à votre convenance par chèque à l'ordre de " . $this->factureData['configuration']->entreprise)));
$this->MultiCell(0,4,utf8_decode(html_entity_decode("en indiquant le numéro de facture, ou par virement :"))); $this->MultiCell(0, 4, utf8_decode(html_entity_decode("en indiquant le numéro de facture, ou par virement :")));
$this->Ln(1); $this->Ln(1);
//Table IBAN //Table IBAN
$startOftable = 3 ; $startOftable = 3;
$this->SetX($startOftable); $this->SetX($startOftable);
$this->SetFont('ComicSans', '', 8); $this->SetFont('ComicSans', '', 8);
$ibanWidth = 62; $ibanWidth = 62;
@ -414,66 +426,64 @@ class InvoiceGroupPdfHandler extends FPDF {
$marginRight = 3; // Marge par rapport au bord droit $marginRight = 3; // Marge par rapport au bord droit
$pageWidth = 210; // Largeur d'une page A4 en mm (portrait) $pageWidth = 210; // Largeur d'une page A4 en mm (portrait)
// Position correcte de la 2e table // Position correcte de la 2e table
$startOfArrayX = $pageWidth - $tableWidth - $marginRight ; $startOfArrayX = $pageWidth - $tableWidth - $marginRight;
$startOfArrayY = $startOfYAfterMainTable + 0.5; $startOfArrayY = $startOfYAfterMainTable + 0.5;
$this->SetFont('ComicSans', '', 10); $this->SetFont('ComicSans', '', 10);
$totalPriceArray = $this->totalPrices; $totalPriceArray = $this->totalPrices;
foreach($totalPriceArray as $label => $price){ foreach ($totalPriceArray as $label => $price) {
$this->SetXY($startOfArrayX,$startOfArrayY); $this->SetXY($startOfArrayX, $startOfArrayY);
$this->Cell(24, 6.5, $label, 1, 1, 'C'); $this->Cell(24, 6.5, $label, 1, 1, 'C');
$this->SetXY($startOfArrayX + 24,$startOfArrayY); $this->SetXY($startOfArrayX + 24, $startOfArrayY);
$this->Cell(24, 6.5, number_format($price,2,'.','').chr(128), 1, 1, 'C'); $this->Cell(24, 6.5, number_format($price, 2, '.', '') . chr(128), 1, 1, 'C');
$startOfArrayY += 6.5; $startOfArrayY += 6.5;
} }
} }
public function SetFactureContent(){ public function SetFactureContent()
{
$this->AddPage(); $this->AddPage();
$this->SetMargins(2,0,3); $this->SetMargins(2, 0, 3);
$this->DrawArticlesTable(); $this->DrawArticlesTable();
$this->DrawBankAndTotalPriceInfo(); $this->DrawBankAndTotalPriceInfo();
} }
function MultiAlignCell($w,$h,$text,$border=0,$ln=0,$align='L',$fill=false) function MultiAlignCell($w, $h, $text, $border = 0, $ln = 0, $align = 'L', $fill = false)
{ {
// Store reset values for (x,y) positions // Store reset values for (x,y) positions
$x = $this->GetX() + $w; $x = $this->GetX() + $w;
$y = $this->GetY(); $y = $this->GetY();
// Make a call to FPDF's MultiCell // Make a call to FPDF's MultiCell
$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);
} }
} }
function NbLines($w, $txt) function NbLines($w, $txt)
{ {
// Compute the number of lines a MultiCell of width w will take // 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'); $this->Error('No font has been set');
$cw = $this->CurrentFont['cw']; $cw = $this->CurrentFont['cw'];
if($w==0) if ($w == 0)
$w = $this->w-$this->rMargin-$this->x; $w = $this->w - $this->rMargin - $this->x;
$wmax = ($w-2*$this->cMargin)*1000/$this->FontSize; $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize;
$s = str_replace("\r",'',(string)$txt); $s = str_replace("\r", '', (string) $txt);
$nb = strlen($s); $nb = strlen($s);
if($nb>0 && $s[$nb-1]=="\n") if ($nb > 0 && $s[$nb - 1] == "\n")
$nb--; $nb--;
$sep = -1; $sep = -1;
$i = 0; $i = 0;
$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;
@ -481,24 +491,20 @@ class InvoiceGroupPdfHandler extends FPDF {
$nl++; $nl++;
continue; continue;
} }
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;
@ -509,56 +515,61 @@ class InvoiceGroupPdfHandler extends FPDF {
{ {
$k = $this->k; $k = $this->k;
$hp = $this->h; $hp = $this->h;
if($style=='F') if ($style == 'F')
$op='f'; $op = 'f';
elseif($style=='FD' || $style=='DF') elseif ($style == 'FD' || $style == 'DF')
$op='B'; $op = 'B';
else else
$op='S'; $op = 'S';
$MyArc = 4/3 * (sqrt(2) - 1); $MyArc = 4 / 3 * (sqrt(2) - 1);
$this->_out(sprintf('%.2F %.2F m',($x+$r)*$k,($hp-$y)*$k )); $this->_out(sprintf('%.2F %.2F m', ($x + $r) * $k, ($hp - $y) * $k));
$xc = $x+$w-$r; $xc = $x + $w - $r;
$yc = $y+$r; $yc = $y + $r;
$this->_out(sprintf('%.2F %.2F l', $xc*$k,($hp-$y)*$k )); $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 )); $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); $this->_Arc($xc + $r * $MyArc, $yc - $r, $xc + $r, $yc - $r * $MyArc, $xc + $r, $yc);
$xc = $x+$w-$r; $xc = $x + $w - $r;
$yc = $y+$h-$r; $yc = $y + $h - $r;
$this->_out(sprintf('%.2F %.2F l',($x+$w)*$k,($hp-$yc)*$k)); $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)); $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); $this->_Arc($xc + $r, $yc + $r * $MyArc, $xc + $r * $MyArc, $yc + $r, $xc, $yc + $r);
$xc = $x+$r; $xc = $x + $r;
$yc = $y+$h-$r; $yc = $y + $h - $r;
$this->_out(sprintf('%.2F %.2F l',$xc*$k,($hp-($y+$h))*$k)); $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)); $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); $this->_Arc($xc - $r * $MyArc, $yc + $r, $xc - $r, $yc + $r * $MyArc, $xc - $r, $yc);
$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
} $this->_Arc($xc - $r, $yc - $r * $MyArc, $xc - $r * $MyArc, $yc - $r, $xc, $yc - $r);
else
$this->_Arc($xc - $r, $yc - $r*$MyArc, $xc - $r*$MyArc, $yc - $r, $xc, $yc - $r);
$this->_out($op); $this->_out($op);
} }
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
));
} }
} }