diff --git a/gestion/lib/Service/InvoicePdfHandler.php b/gestion/lib/Service/InvoicePdfHandler.php index 6e0dd0d..1a274b9 100644 --- a/gestion/lib/Service/InvoicePdfHandler.php +++ b/gestion/lib/Service/InvoicePdfHandler.php @@ -166,30 +166,45 @@ class InvoicePdfHandler extends FPDF $clientInfoXAxis = 125; $clientAddress = $this->factureData['client_real_adress']; - $clientAdressWidth = $this->GetStringWidth($clientAddress); $maxWidth = $this->GetPageWidth(); - $availableWidhtForClientInfo = $maxWidth - 10 - $clientInfoXAxis; - $clientAdressIsMultiline = $clientAdressWidth > $availableWidhtForClientInfo; - - $clientInfoYAxis = $clientAdressIsMultiline ? 35 : 40; + $availableWidhtForClientInfo = $maxWidth - 2 - $clientInfoXAxis; + $address = FileExportHelpers::FormatTextForExport(trim($clientAddress)); + $addressWidth = $this->GetStringWidth($address); + $addressWidthGreaterThanMaxWidth = $addressWidth > $availableWidhtForClientInfo; + $addressIsMoreThanTwoLines = ($addressWidth / $availableWidhtForClientInfo) > 2; + + $clientInfoYAxis = $addressIsMoreThanTwoLines ? 35 : 35;// the old is ? 35 : 39 but not working $this->SetXY($clientInfoXAxis, $clientInfoYAxis); $this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport($clientName)); $clientInfoYAxis += $this->interLigneHeader; - $this->SetXY($clientInfoXAxis, $clientInfoYAxis); - $this->MultiCell(0, $this->interLigneHeader, trim(FileExportHelpers::FormatTextForExport($clientAddress))); - if ($clientAdressIsMultiline) { - $clientAdressIsMoreThanTwoLines = $clientAdressWidth > ($availableWidhtForClientInfo * 2); - if($clientAdressIsMoreThanTwoLines){ + $clientAddresses = explode(",", $clientAddress); + foreach ($clientAddresses as $address) { + $address = FileExportHelpers::FormatTextForExport(trim($address)); + $addressWidth = $this->GetStringWidth($address); + $addressWidthGreaterThanMaxWidth = $addressWidth > $availableWidhtForClientInfo; + $isMultiline = false; + $this->SetXY($clientInfoXAxis, $clientInfoYAxis); + if ($addressWidthGreaterThanMaxWidth) { + $yBefore = $this->GetY(); + $this->MultiCell($availableWidhtForClientInfo, $this->interLigneHeader, $address, 0, 'L'); + $yAfter = $this->GetY(); + $isMultiline = ($yAfter - $yBefore) > $this->interLigneHeader; + if ($isMultiline) { + $this->SetXY($this->GetX(), $yBefore); + } + } else { + $this->Cell($availableWidhtForClientInfo, $this->interLigneHeader, $address); + } + if ($isMultiline) { $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']))); $clientInfoYAxis += $this->interLigneHeader; $this->SetXY($clientInfoXAxis, $clientInfoYAxis); - $this->Cell(0, $this->interLigneHeader,'Siret: ' . $this->factureData['siret']); + $this->Cell(0, $this->interLigneHeader,'Siret6: ' . $this->factureData['siret']); $clientInfoYAxis += $this->interLigneHeader; $this->SetXY($clientInfoXAxis, $clientInfoYAxis); $this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport('Mail : ') . $this->factureData['client_mail']);