handl client adress on simple pdf generation

This commit is contained in:
narindraezway 2025-06-05 10:55:32 +03:00
parent 235da11fe3
commit 6acbb67351

View File

@ -166,30 +166,45 @@ class InvoicePdfHandler extends FPDF
$clientInfoXAxis = 125; $clientInfoXAxis = 125;
$clientAddress = $this->factureData['client_real_adress']; $clientAddress = $this->factureData['client_real_adress'];
$clientAdressWidth = $this->GetStringWidth($clientAddress);
$maxWidth = $this->GetPageWidth(); $maxWidth = $this->GetPageWidth();
$availableWidhtForClientInfo = $maxWidth - 10 - $clientInfoXAxis; $availableWidhtForClientInfo = $maxWidth - 2 - $clientInfoXAxis;
$clientAdressIsMultiline = $clientAdressWidth > $availableWidhtForClientInfo; $address = FileExportHelpers::FormatTextForExport(trim($clientAddress));
$addressWidth = $this->GetStringWidth($address);
$addressWidthGreaterThanMaxWidth = $addressWidth > $availableWidhtForClientInfo;
$addressIsMoreThanTwoLines = ($addressWidth / $availableWidhtForClientInfo) > 2;
$clientInfoYAxis = $clientAdressIsMultiline ? 35 : 40; $clientInfoYAxis = $addressIsMoreThanTwoLines ? 35 : 35;// the old is ? 35 : 39 but not working
$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;
$this->SetXY($clientInfoXAxis, $clientInfoYAxis); $clientAddresses = explode(",", $clientAddress);
$this->MultiCell(0, $this->interLigneHeader, trim(FileExportHelpers::FormatTextForExport($clientAddress))); foreach ($clientAddresses as $address) {
if ($clientAdressIsMultiline) { $address = FileExportHelpers::FormatTextForExport(trim($address));
$clientAdressIsMoreThanTwoLines = $clientAdressWidth > ($availableWidhtForClientInfo * 2); $addressWidth = $this->GetStringWidth($address);
if($clientAdressIsMoreThanTwoLines){ $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; $clientInfoYAxis += $this->interLigneHeader;
} }
$clientInfoYAxis += $this->interLigneHeader;
$this->SetXY($clientInfoXAxis, $clientInfoYAxis); $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'])));
$clientInfoYAxis += $this->interLigneHeader; $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,'Siret6: ' . $this->factureData['siret']);
$clientInfoYAxis += $this->interLigneHeader; $clientInfoYAxis += $this->interLigneHeader;
$this->SetXY($clientInfoXAxis, $clientInfoYAxis); $this->SetXY($clientInfoXAxis, $clientInfoYAxis);
$this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport('Mail : ') . $this->factureData['client_mail']); $this->Cell(0, $this->interLigneHeader, FileExportHelpers::FormatTextForExport('Mail : ') . $this->factureData['client_mail']);