diff --git a/Abrechnung/module.php b/Abrechnung/module.php
index 9b72b9d..3bd6c76 100644
--- a/Abrechnung/module.php
+++ b/Abrechnung/module.php
@@ -127,39 +127,45 @@ public function GenerateInvoices()
$pdf->SetAutoPageBreak(true, 20);
$pdf->SetFont('dejavusans', '', 10);
- foreach ($users as $user) {
- $pdf->AddPage();
- $pdf->writeHTML("
Rechnung für {$user['name']}
");
- $pdf->writeHTML("{$user['address']}
{$user['city']}
");
- $pdf->Ln(4);
+ foreach ($users as $user) {
+ IPS_LogMessage('Abrechnung', '→ Erstelle Seite für Benutzer: ' . $user['name']);
+ $pdf->AddPage();
- $pdf->writeHTML("
-
- | Zähler |
- Typ |
- Start |
- Ende |
- Verbrauch |
- Tarif (Rp) |
- Kosten (CHF) |
-
");
+ // 🔽 Hier fügst du den neuen HTML-Block ein:
+ $html = "
+ Rechnung für {$user['name']}
+ {$user['address']}
{$user['city']}
+
+
+ | Zähler |
+ Typ |
+ Start |
+ Ende |
+ Verbrauch |
+ Tarif (Rp) |
+ Kosten (CHF) |
+
+ ";
- $total = 0.0;
+ $total = 0.0;
+ foreach ($power as $m) {
+ if ($m['user_id'] != $user['id']) continue;
+ $cost = $this->AddMeterToPDFRow($m, $tariffs, $from, $to, 'Strombezug');
+ $html .= $cost['row'];
+ $total += $cost['value'];
+ }
+ foreach ($water as $m) {
+ if ($m['user_id'] != $user['id']) continue;
+ $type = $m['meter_type'] ?? 'Warmwasser';
+ $cost = $this->AddMeterToPDFRow($m, $tariffs, $from, $to, $type);
+ $html .= $cost['row'];
+ $total += $cost['value'];
+ }
- foreach ($power as $m) {
- if ($m['user_id'] != $user['id']) continue;
- $total += $this->AddMeterToPDF($pdf, $m, $tariffs, $from, $to, 'Strombezug');
- }
+ $html .= "
Gesamtsumme: " . number_format($total, 2) . " CHF
";
+ $pdf->writeHTML($html);
+ }
- foreach ($water as $m) {
- if ($m['user_id'] != $user['id']) continue;
- $type = $m['meter_type'] ?? 'Warmwasser';
- $total += $this->AddMeterToPDF($pdf, $m, $tariffs, $from, $to, $type);
- }
-
- $pdf->writeHTML("
");
- $pdf->Ln(5);
- $pdf->writeHTML("Gesamtsumme: " . number_format($total, 2) . " CHF
");
}
IPS_LogMessage('Abrechnung', '✅ PDF-Daten fertiggestellt');
@@ -220,4 +226,29 @@ public function GenerateInvoices()
}
return floatval(GetValue($varId));
}
-}
+
+ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
+ {
+ $start = $this->GetValueAt($meter['var_consumption'], $from);
+ $end = $this->GetValueAt($meter['var_consumption'], $to);
+ if ($start === null || $end === null) return ['row' => '', 'value' => 0];
+
+ $diff = max(0, $end - $start);
+ $tariffRp = $this->GetTariff($tariffs, $type, $from, $to);
+ $cost = ($tariffRp / 100) * $diff;
+
+ $row = "
+
+ | {$meter['name']} |
+ $type |
+ $start |
+ $end |
+ $diff |
+ $tariffRp |
+ " . number_format($cost, 2) . " |
+
";
+
+ return ['row' => $row, 'value' => $cost];
+ }
+
+}
\ No newline at end of file