diff --git a/Abrechnung/module.php b/Abrechnung/module.php index 195dcda..5625c2c 100644 --- a/Abrechnung/module.php +++ b/Abrechnung/module.php @@ -6,15 +6,16 @@ include_once __DIR__ . '/libs/vendor/autoload.php'; // TCPDF via Composer /** * Eigene TCPDF-Klasse mit Logo im Header und Text in der Fusszeile */ + class InvoicePDF extends TCPDF { public $logoFile = null; public $footerText = ''; + public $printFooterText = true; // Neu: Steuert ob die Fusszeile gedruckt wird public function Header() { if ($this->logoFile !== null && file_exists($this->logoFile)) { - // x, y, width in mm $this->Image($this->logoFile, 15, 10, 40); $this->SetY(28); } else { @@ -24,6 +25,9 @@ class InvoicePDF extends TCPDF public function Footer() { + if (!$this->printFooterText) { + return; // Auf QR-Seite keine Rechnungs-Fusszeile drucken! + } $this->SetY(-15); $this->SetFont('dejavusans', '', 8); $this->Cell(0, 10, $this->footerText, 0, 0, 'C'); @@ -144,11 +148,12 @@ class Abrechnung extends IPSModule $pdf->SetFont('dejavusans', '', 8); foreach ($users as $user) { + $pdf->printFooterText = true; // Fusszeile für die Rechnung aktivieren $pdf->AddPage(); - // Hole das berechnete Total aus der Rechnung + $grandTotal = $this->BuildUserInvoice($pdf, $user, $power, $water, $tariffs, $from, $to); - // Generiere den Einzahlungsschein, wenn eine IBAN vorhanden ist + $pdf->printFooterText = false; // Fusszeile für den QR-Schein deaktivieren $this->BuildQRBill($pdf, $user, $grandTotal); } @@ -240,11 +245,10 @@ class Abrechnung extends IPSModule // ====================== QR-Einzahlungsschein (Schweiz) ====================== - private function BuildQRBill($pdf, $user, $amount) + private function BuildQRBill($pdf, $user, $amount) { $iban = str_replace(' ', '', $this->ReadPropertyString('BankIBAN')); - // Kein Einzahlungsschein, wenn IBAN leer ist oder Betrag <= 0 if (empty($iban) || $amount <= 0) { return; } @@ -252,11 +256,12 @@ class Abrechnung extends IPSModule $pdf->AddPage(); $pdf->SetAutoPageBreak(false); - // Position des Einzahlungsscheins unten auf A4 (Höhe 105mm) + // Wir nutzen Helvetica für den QR-Schein (Standard gemäss Richtlinien) + $font = 'helvetica'; $yStart = 192; - // Trennlinien zeichnen - $pdf->SetLineStyle(['dash' => '2,2', 'color' => [0, 0, 0]]); + // Trennlinien zeichnen (Scherensymbol) + $pdf->SetLineStyle(['dash' => '2,2', 'color' => [0, 0, 0], 'width' => 0.1]); $pdf->Line(0, $yStart, 210, $yStart); // Horizontal $pdf->Line(62, $yStart, 62, 297); // Vertikal $pdf->SetLineStyle(['dash' => 0, 'color' => [0, 0, 0]]); // Reset @@ -265,87 +270,97 @@ class Abrechnung extends IPSModule $creditorCity = $this->ReadPropertyString('CreditorCity'); $bankIBAN_formatted = wordwrap($iban, 4, ' ', true); - // --- LINKER TEIL: Empfangsschein --- - $pdf->SetFont('dejavusans', 'B', 11); + // --- LINKER TEIL: Empfangsschein (0-62mm) --- + $pdf->SetFont($font, 'B', 11); $pdf->SetXY(5, $yStart + 5); $pdf->Cell(52, 5, 'Empfangsschein', 0, 1); - $pdf->SetFont('dejavusans', 'B', 6); + $pdf->SetFont($font, 'B', 6); $pdf->SetXY(5, $yStart + 12); $pdf->Cell(52, 3, 'Konto / Zahlbar an', 0, 1); - $pdf->SetFont('dejavusans', '', 6); + $pdf->SetFont($font, '', 8); $pdf->SetX(5); $pdf->Cell(52, 3, $bankIBAN_formatted, 0, 1); $pdf->SetX(5); $pdf->Cell(52, 3, $creditorName, 0, 1); $pdf->SetX(5); $pdf->Cell(52, 3, $creditorCity, 0, 1); - $pdf->SetFont('dejavusans', 'B', 6); + $pdf->SetFont($font, 'B', 6); $pdf->SetXY(5, $yStart + 35); $pdf->Cell(52, 3, 'Zahlbar durch', 0, 1); - $pdf->SetFont('dejavusans', '', 6); + $pdf->SetFont($font, '', 8); $pdf->SetX(5); $pdf->Cell(52, 3, $user['name'] ?? '', 0, 1); $pdf->SetX(5); $pdf->Cell(52, 3, $user['address'] ?? '', 0, 1); $pdf->SetX(5); $pdf->Cell(52, 3, $user['city'] ?? '', 0, 1); - $pdf->SetFont('dejavusans', 'B', 6); - $pdf->SetXY(5, $yStart + 60); + // Währung und Betrag unten Links + $pdf->SetFont($font, 'B', 6); + $pdf->SetXY(5, $yStart + 65); $pdf->Cell(15, 3, 'Währung', 0, 0); $pdf->Cell(20, 3, 'Betrag', 0, 1); - $pdf->SetFont('dejavusans', '', 8); + $pdf->SetFont($font, '', 8); $pdf->SetX(5); $pdf->Cell(15, 4, 'CHF', 0, 0); - $pdf->Cell(20, 4, number_format($amount, 2, '.', ''), 0, 1); + $pdf->Cell(20, 4, number_format($amount, 2, '.', ' '), 0, 1); // Leerzeichen bei Tausender + + // Annahmestelle + $pdf->SetFont($font, 'B', 6); + $pdf->SetXY(38, $yStart + 85); + $pdf->Cell(19, 3, 'Annahmestelle', 0, 1, 'R'); + // --- RECHTER TEIL: Zahlteil --- - $pdf->SetFont('dejavusans', 'B', 11); - $pdf->SetXY(118, $yStart + 5); + $pdf->SetFont($font, 'B', 11); + $pdf->SetXY(67, $yStart + 5); $pdf->Cell(50, 5, 'Zahlteil', 0, 1); - // QR Code String generieren & rendern (46x46mm) + // QR Code rendern $qrString = $this->GenerateQRString($iban, $amount, $user); $style = ['border' => false, 'padding' => 0, 'fgcolor' => [0, 0, 0], 'bgcolor' => false]; $pdf->write2DBarcode($qrString, 'QRCODE,M', 67, $yStart + 17, 46, 46, $style, 'N'); -// Schweizer Kreuz über den QR Code zeichnen (Spezifikation: 7x7mm inkl. weissem Rand) + // Schweizer Kreuz über den QR Code zeichnen (Spezifikation: 7x7mm inkl. weissem Rand) $cX = 67 + 23; // Zentrum X des QR Codes (Position 67 + Hälfte von 46) $cY = $yStart + 17 + 23; // Zentrum Y des QR Codes (Position 17 + Hälfte von 46) - // 1. Weisser Hintergrund (Rand) - 7x7 mm $pdf->SetFillColor(255, 255, 255); $pdf->Rect($cX - 3.5, $cY - 3.5, 7, 7, 'F'); - - // 2. Schwarzes Quadrat - ca. 6x6 mm (ergibt ringsum 0.5mm weissen Rand) $pdf->SetFillColor(0, 0, 0); $pdf->Rect($cX - 3, $cY - 3, 6, 6, 'F'); - - // 3. Weisses Schweizer Kreuz (Balkenbreite ca. 1.2mm, Länge ca. 4mm) $pdf->SetFillColor(255, 255, 255); - $pdf->Rect($cX - 0.6, $cY - 2, 1.2, 4, 'F'); // Vertikaler Balken - $pdf->Rect($cX - 2, $cY - 0.6, 4, 1.2, 'F'); // Horizontaler Balken + $pdf->Rect($cX - 0.6, $cY - 2, 1.2, 4, 'F'); + $pdf->Rect($cX - 2, $cY - 0.6, 4, 1.2, 'F'); - $pdf->SetFont('dejavusans', 'B', 8); - $pdf->SetXY(118, $yStart + 17); + // Währung und Betrag unter dem QR Code + $pdf->SetFont($font, 'B', 8); + $pdf->SetXY(67, $yStart + 68); + $pdf->Cell(15, 4, 'Währung', 0, 0); + $pdf->Cell(20, 4, 'Betrag', 0, 1); + $pdf->SetFont($font, '', 10); + $pdf->SetX(67); + $pdf->Cell(15, 5, 'CHF', 0, 0); + $pdf->Cell(20, 5, number_format($amount, 2, '.', ' '), 0, 1); + + // --- RECHTE TEXTSPALTE (ab 118mm) --- + $pdf->SetFont($font, 'B', 8); + $pdf->SetXY(118, $yStart + 5); $pdf->Cell(80, 4, 'Konto / Zahlbar an', 0, 1); - $pdf->SetFont('dejavusans', '', 8); + $pdf->SetFont($font, '', 10); $pdf->SetX(118); $pdf->Cell(80, 4, $bankIBAN_formatted, 0, 1); $pdf->SetX(118); $pdf->Cell(80, 4, $creditorName, 0, 1); $pdf->SetX(118); $pdf->Cell(80, 4, $creditorCity, 0, 1); - $pdf->SetFont('dejavusans', 'B', 8); - $pdf->SetXY(118, $yStart + 40); + $pdf->SetFont($font, 'B', 8); + $pdf->SetXY(118, $yStart + 26); + $pdf->Cell(80, 4, 'Zusätzliche Informationen', 0, 1); + $pdf->SetFont($font, '', 10); + $pdf->SetX(118); $pdf->Cell(80, 4, 'Abrechnung Liegenschaft', 0, 1); + + $pdf->SetFont($font, 'B', 8); + $pdf->SetXY(118, $yStart + 43); $pdf->Cell(80, 4, 'Zahlbar durch', 0, 1); - $pdf->SetFont('dejavusans', '', 8); + $pdf->SetFont($font, '', 10); $pdf->SetX(118); $pdf->Cell(80, 4, $user['name'] ?? '', 0, 1); $pdf->SetX(118); $pdf->Cell(80, 4, $user['address'] ?? '', 0, 1); $pdf->SetX(118); $pdf->Cell(80, 4, $user['city'] ?? '', 0, 1); - - $pdf->SetFont('dejavusans', 'B', 8); - $pdf->SetXY(67, $yStart + 68); - $pdf->Cell(15, 4, 'Währung', 0, 0); - $pdf->Cell(20, 4, 'Betrag', 0, 1); - $pdf->SetFont('dejavusans', '', 10); - $pdf->SetX(67); - $pdf->Cell(15, 5, 'CHF', 0, 0); - $pdf->Cell(20, 5, number_format($amount, 2, '.', ''), 0, 1); } private function GenerateQRString($iban, $amount, $user)