no message
This commit is contained in:
@@ -127,39 +127,45 @@ public function GenerateInvoices()
|
||||
$pdf->SetAutoPageBreak(true, 20);
|
||||
$pdf->SetFont('dejavusans', '', 10);
|
||||
|
||||
foreach ($users as $user) {
|
||||
$pdf->AddPage();
|
||||
$pdf->writeHTML("<h2>Rechnung für {$user['name']}</h2>");
|
||||
$pdf->writeHTML("<p>{$user['address']}<br>{$user['city']}</p>");
|
||||
$pdf->Ln(4);
|
||||
foreach ($users as $user) {
|
||||
IPS_LogMessage('Abrechnung', '→ Erstelle Seite für Benutzer: ' . $user['name']);
|
||||
$pdf->AddPage();
|
||||
|
||||
$pdf->writeHTML("<table border='1' cellpadding='5'>
|
||||
<tr style='background-color:#e0e0e0;'>
|
||||
<th>Zähler</th>
|
||||
<th>Typ</th>
|
||||
<th>Start</th>
|
||||
<th>Ende</th>
|
||||
<th>Verbrauch</th>
|
||||
<th>Tarif (Rp)</th>
|
||||
<th>Kosten (CHF)</th>
|
||||
</tr>");
|
||||
// 🔽 Hier fügst du den neuen HTML-Block ein:
|
||||
$html = "
|
||||
<h2>Rechnung für {$user['name']}</h2>
|
||||
<p>{$user['address']}<br>{$user['city']}</p>
|
||||
<table border='1' cellpadding='5'>
|
||||
<tr style='background-color:#e0e0e0;'>
|
||||
<th>Zähler</th>
|
||||
<th>Typ</th>
|
||||
<th>Start</th>
|
||||
<th>Ende</th>
|
||||
<th>Verbrauch</th>
|
||||
<th>Tarif (Rp)</th>
|
||||
<th>Kosten (CHF)</th>
|
||||
</tr>
|
||||
";
|
||||
|
||||
$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 .= "</table><h3>Gesamtsumme: " . number_format($total, 2) . " CHF</h3>";
|
||||
$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("</table>");
|
||||
$pdf->Ln(5);
|
||||
$pdf->writeHTML("<h3>Gesamtsumme: " . number_format($total, 2) . " CHF</h3>");
|
||||
}
|
||||
|
||||
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 = "
|
||||
<tr>
|
||||
<td>{$meter['name']}</td>
|
||||
<td>$type</td>
|
||||
<td>$start</td>
|
||||
<td>$end</td>
|
||||
<td>$diff</td>
|
||||
<td>$tariffRp</td>
|
||||
<td>" . number_format($cost, 2) . "</td>
|
||||
</tr>";
|
||||
|
||||
return ['row' => $row, 'value' => $cost];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user