diff --git a/Abrechnung/form.json b/Abrechnung/form.json index 04d47c5..68f389e 100644 --- a/Abrechnung/form.json +++ b/Abrechnung/form.json @@ -5,17 +5,15 @@ "caption": "🧾 Abrechnungseinstellungen" }, { - "type": "Image", - "name": "Logo", - "caption": "Firmenlogo" + "type": "SelectMedia", + "name": "LogoMediaID", + "caption": "Logo auswählen" }, { "type": "ValidationTextBox", "name": "FooterText", "caption": "Fusszeile" }, - - { "type": "List", diff --git a/Abrechnung/module.php b/Abrechnung/module.php index 340239c..423a4bd 100644 --- a/Abrechnung/module.php +++ b/Abrechnung/module.php @@ -3,19 +3,33 @@ declare(strict_types=1); include_once __DIR__ . '/libs/vendor/autoload.php'; // TCPDF via Composer - -class PDFWithFooter extends TCPDF { +/** + * Eigene TCPDF-Klasse mit Logo im Header und Text in der Fusszeile + */ +class InvoicePDF extends TCPDF +{ + public $logoFile = null; public $footerText = ''; - public function Footer() { + 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 { + $this->SetY(15); + } + } + + public function Footer() + { $this->SetY(-15); $this->SetFont('dejavusans', '', 8); $this->Cell(0, 10, $this->footerText, 0, 0, 'C'); } } - - class Abrechnung extends IPSModule { public function Create() @@ -26,7 +40,7 @@ class Abrechnung extends IPSModule $this->RegisterPropertyString('PowerMeters', '[]'); $this->RegisterPropertyString('WaterMeters', '[]'); $this->RegisterPropertyString('Tariffs', '[]'); - $this->RegisterPropertyString('Logo', ''); + $this->RegisterPropertyInteger('LogoMediaID', 0); $this->RegisterPropertyString('FooterText', 'Belevo AG • 6122 Menznau • www.belevo.ch'); $this->RegisterVariableInteger('FromDate', 'Startdatum', '~UnixTimestamp', 1); @@ -107,53 +121,53 @@ class Abrechnung extends IPSModule // Stromkosten einmal für alle User berechnen (15-Minuten-Logik) $this->CalculateAllPowerCosts($power, $tariffs, $from, $to); - $pdf = new PDFWithFooter('P', 'mm', 'A4', true, 'UTF-8', false); - $pdf->footerText = $this->ReadPropertyString('FooterText'); + // Logo & Fusszeile vorbereiten + $logoFile = $this->GetLogoFile(); + $footerText = $this->ReadPropertyString('FooterText'); + + // PDF-Objekt + $pdf = new InvoicePDF('P', 'mm', 'A4', true, 'UTF-8', false); + $pdf->logoFile = $logoFile; + $pdf->footerText = $footerText; + $pdf->SetCreator('IPSymcon Abrechnung'); - $pdf->SetMargins(15, 15, 15); + // Oben mehr Platz für Logo lassen + $pdf->SetMargins(15, 35, 15); $pdf->SetAutoPageBreak(true, 20); - $pdf->SetFont('dejavusans', '', 9); + $pdf->SetFont('dejavusans', '', 8); foreach ($users as $user) { + $pdf->AddPage(); $this->BuildUserInvoice($pdf, $user, $power, $water, $tariffs, $from, $to); } return $pdf->Output('Abrechnung.pdf', 'S'); } -private function BuildUserInvoice($pdf, $user, $power, $water, $tariffs, $from, $to) -{ - $logoData = $this->ReadPropertyString('Logo'); -if ($logoData !== '') { - $img = base64_decode($logoData); - $pdf->Image('@' . $img, 15, 10, 40); - $pdf->Ln(25); -} - - $pdf->AddPage(); - - // Kopfbereich - $html = " + private function BuildUserInvoice($pdf, $user, $power, $water, $tariffs, $from, $to) + { + // Kopfbereich + $html = "
|
Zählpunkte: "; - // Alle Zählerpunkte des Users auflisten - foreach ($power as $m) { - if ($m['user_id'] == $user['id']) { - $html .= htmlspecialchars($m['name']) . " "; + // Alle Zählerpunkte des Users auflisten + foreach ($power as $m) { + if ($m['user_id'] == $user['id']) { + $html .= htmlspecialchars($m['name']) . " "; + } } - } - foreach ($water as $m) { - if ($m['user_id'] == $user['id']) { - $html .= htmlspecialchars($m['name']) . " "; + foreach ($water as $m) { + if ($m['user_id'] == $user['id']) { + $html .= htmlspecialchars($m['name']) . " "; + } } - } - $html .= " + $html .= " |
Rechnungsadresse: @@ -163,49 +177,50 @@ if ($logoData !== '') { |
+
Abrechnungszeitraum: " . date('d.m.Y', $from) . " – " . date('d.m.Y', $to) . "
Angewendete Elektrizitätstarife:
Angewendete Elektrizitätstarife:
+| Zähler | @@ -362,7 +377,6 @@ $html = "Total CHF | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Keine Stromzähler für diesen Benutzer | ||||||||||
| Zähler | @@ -415,7 +429,6 @@ $html = "Kosten CHF | |||||||
|---|---|---|---|---|---|---|---|---|
| Total Nebenkosten: | " . number_format($total, 2) . " CHF | -|||||||