✨ feat(ContratPdfService): Ajoute la génération de code-barres Code 39 aux contrats PDF.
This commit is contained in:
@@ -22,6 +22,45 @@ class ContratPdfService extends Fpdf
|
||||
|
||||
$this->AliasNbPages();
|
||||
$this->SetAutoPageBreak(true, 35);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Génère un code-barres Code 39
|
||||
*/
|
||||
private function Code39($xpos, $ypos, $code, $baseline = 0.5, $height = 5)
|
||||
{
|
||||
$wide = $baseline * 2.25;
|
||||
$narrow = $baseline;
|
||||
$gap = $narrow;
|
||||
|
||||
$barChar = [
|
||||
'0' => 'nnnwwnwnn', '1' => 'wnnwnnnnw', '2' => 'nnwwnnnnw', '3' => 'wnwwnnnnn',
|
||||
'4' => 'nnnwwnnnw', '5' => 'wnnwwnnnn', '6' => 'nnwwnwnnn', '7' => 'nnnwnnwnw',
|
||||
'8' => 'wnnwnnwnn', '9' => 'nnwwnnwnn', 'A' => 'wnnnnwnnw', 'B' => 'nnwnnwnnw',
|
||||
'C' => 'wnwnnwnnn', 'D' => 'nnnnwwnnw', 'E' => 'wnnnwwnnn', 'F' => 'nnwnwwnnn',
|
||||
'G' => 'nnnnnwwnw', 'H' => 'wnnnnwwnn', 'I' => 'nnwnnwwnn', 'J' => 'nnnnwwwnn',
|
||||
'K' => 'wnnnnnnww', 'L' => 'nnwnnnnww', 'M' => 'wnwnnnnwn', 'N' => 'nnnnwnnww',
|
||||
'O' => 'wnnnwnnwn', 'P' => 'nnwnwnnwn', 'Q' => 'nnnnnnwww', 'R' => 'wnnnnnwwn',
|
||||
'S' => 'nnwnnnwwn', 'T' => 'nnnnwnwwn', 'U' => 'wwnnnnnnw', 'V' => 'nwwnnnnnw',
|
||||
'W' => 'wwwnnnnnn', 'X' => 'nwnnwnnnw', 'Y' => 'wwnnwnnnn', 'Z' => 'nwwnwnnnn',
|
||||
'-' => 'nwnnnnwnw', '.' => 'wwnnnnwnn', ' ' => 'nwwnnnwnn', '*' => 'nwnnwnwnn',
|
||||
'$' => 'nwnwnwnnn', '/' => 'nwnwnnnwn', '+' => 'nwnnnwnwn', '%' => 'nnnwnwnwn'
|
||||
];
|
||||
|
||||
$this->SetFillColor(0);
|
||||
$code = '*' . strtoupper($code) . '*';
|
||||
for ($i = 0; $i < strlen($code); $i++) {
|
||||
$char = $code[$i];
|
||||
if (!isset($barChar[$char])) continue;
|
||||
$seq = $barChar[$char];
|
||||
for ($bar = 0; $bar < 9; $bar++) {
|
||||
if ($seq[$bar] == 'n') $lineWidth = $narrow; else $lineWidth = $wide;
|
||||
if ($bar % 2 == 0) $this->Rect($xpos, $ypos, $lineWidth, $height, 'F');
|
||||
$xpos += $lineWidth;
|
||||
}
|
||||
$xpos += $gap;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,6 +111,12 @@ class ContratPdfService extends Fpdf
|
||||
$this->SetTextColor(37, 99, 235);
|
||||
$this->Cell(0, 10, $this->clean('Contrat de location N° ' . $this->contrats->getNumReservation()), 0, 1, 'L');
|
||||
|
||||
|
||||
// Paramètres : X=160 (à droite), Y=42, Code=Numéro, Largeur barre=0.3, Hauteur=8
|
||||
$this->Code39(155, 41, $this->contrats->getNumReservation(), 0.3, 8);
|
||||
|
||||
$this->Ln(10); // Retour à la ligne après le titre et le barcode
|
||||
|
||||
$this->SetDrawColor(37, 99, 235);
|
||||
$this->SetLineWidth(0.5);
|
||||
$this->Line(10, $this->GetY(), 200, $this->GetY());
|
||||
|
||||
Reference in New Issue
Block a user