no message
This commit is contained in:
+114
-36
@@ -127,45 +127,123 @@ public function GenerateInvoices()
|
|||||||
$pdf->SetAutoPageBreak(true, 20);
|
$pdf->SetAutoPageBreak(true, 20);
|
||||||
$pdf->SetFont('dejavusans', '', 10);
|
$pdf->SetFont('dejavusans', '', 10);
|
||||||
|
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
IPS_LogMessage('Abrechnung', '→ Erstelle Seite für Benutzer: ' . $user['name']);
|
IPS_LogMessage('Abrechnung', '→ Erstelle Seite für Benutzer: ' . $user['name']);
|
||||||
$pdf->AddPage();
|
$pdf->AddPage();
|
||||||
|
|
||||||
// 🔽 Hier fügst du den neuen HTML-Block ein:
|
$html = "
|
||||||
$html = "
|
<h2 style='text-align:center;'>Rechnung für {$user['name']}</h2>
|
||||||
<h2>Rechnung für {$user['name']}</h2>
|
<p>{$user['address']}<br>{$user['city']}</p>
|
||||||
<p>{$user['address']}<br>{$user['city']}</p>
|
<p><b>Abrechnungszeitraum:</b> " . date('d.m.Y', $from) . " – " . date('d.m.Y', $to) . "</p>
|
||||||
<table border='1' cellpadding='2' style='font-size:6px;'>
|
";
|
||||||
<tr style='background-color:#e0e0e0;'>
|
|
||||||
<th>Zähler</th>
|
|
||||||
<th>Typ</th>
|
|
||||||
<th>Startzeit</th>
|
|
||||||
<th>Endzeit</th>
|
|
||||||
<th>Zählerstand Start</th>
|
|
||||||
<th>Zählerstand Ende</th>
|
|
||||||
<th>Verbrauch</th>
|
|
||||||
<th>Tarif (Rp)</th>
|
|
||||||
<th>Kosten (CHF)</th>
|
|
||||||
</tr>
|
|
||||||
";
|
|
||||||
|
|
||||||
$total = 0.0;
|
$stromRows = '';
|
||||||
foreach ($power as $m) {
|
$stromTotal = 0.0;
|
||||||
if ($m['user_id'] != $user['id']) continue;
|
$stromTariffsUsed = [];
|
||||||
$cost = $this->AddMeterToPDFRow($m, $tariffs, $from, $to, 'Strombezug');
|
|
||||||
$html .= $cost['row'];
|
$nebenRows = '';
|
||||||
$total += $cost['value'];
|
$nebenTotal = 0.0;
|
||||||
|
$nebenTariffsUsed = [];
|
||||||
|
|
||||||
|
// --- Stromkosten ---
|
||||||
|
foreach ($power as $m) {
|
||||||
|
if ($m['user_id'] != $user['id']) continue;
|
||||||
|
$res = $this->AddMeterToPDFRow($m, $tariffs, $from, $to, 'Strombezug');
|
||||||
|
$stromRows .= $res['row'];
|
||||||
|
$stromTotal += $res['value'];
|
||||||
|
|
||||||
|
// relevante Tarife sammeln
|
||||||
|
foreach ($tariffs as $t) {
|
||||||
|
if (strtolower($t['unit_type']) == 'strombezug') {
|
||||||
|
$s = is_numeric($t['start']) ? date('d.m.Y', $t['start']) : date('d.m.Y', strtotime($t['start']));
|
||||||
|
$e = is_numeric($t['end']) ? date('d.m.Y', $t['end']) : date('d.m.Y', strtotime($t['end']));
|
||||||
|
$stromTariffsUsed[$s . ' - ' . $e] = number_format(floatval($t['price']), 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Nebenkosten (Wasser/Wärme) ---
|
||||||
|
foreach ($water as $m) {
|
||||||
|
if ($m['user_id'] != $user['id']) continue;
|
||||||
|
$type = $m['meter_type'] ?? 'Warmwasser';
|
||||||
|
$res = $this->AddMeterToPDFRow($m, $tariffs, $from, $to, $type);
|
||||||
|
$nebenRows .= $res['row'];
|
||||||
|
$nebenTotal += $res['value'];
|
||||||
|
|
||||||
|
// relevante Tarife sammeln
|
||||||
|
foreach ($tariffs as $t) {
|
||||||
|
if (in_array(strtolower($t['unit_type']), ['warmwasser', 'kaltwasser', 'wärme'])) {
|
||||||
|
$s = is_numeric($t['start']) ? date('d.m.Y', $t['start']) : date('d.m.Y', strtotime($t['start']));
|
||||||
|
$e = is_numeric($t['end']) ? date('d.m.Y', $t['end']) : date('d.m.Y', strtotime($t['end']));
|
||||||
|
$nebenTariffsUsed[$s . ' - ' . $e] = number_format(floatval($t['price']), 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tabellenstil mit Linien
|
||||||
|
$tableStyle = "border-collapse:collapse;width:100%;font-size:8px;";
|
||||||
|
$cellStyle = "border:0.3px solid #999;padding:2px;";
|
||||||
|
|
||||||
|
// ---------- Stromkosten ----------
|
||||||
|
$html .= "<h3 style='margin-top:15px;color:#004085;'>⚡ Stromkosten</h3>";
|
||||||
|
$html .= "<table style='{$tableStyle}'>
|
||||||
|
<tr style='background-color:#e0e0e0;text-align:center;'>
|
||||||
|
<th style='{$cellStyle}'>Zähler</th>
|
||||||
|
<th style='{$cellStyle}'>Typ</th>
|
||||||
|
<th style='{$cellStyle}'>Startzeit</th>
|
||||||
|
<th style='{$cellStyle}'>Endzeit</th>
|
||||||
|
<th style='{$cellStyle}'>Zählerstart</th>
|
||||||
|
<th style='{$cellStyle}'>Zählerende</th>
|
||||||
|
<th style='{$cellStyle}'>Verbrauch</th>
|
||||||
|
<th style='{$cellStyle}'>Tarif (Rp)</th>
|
||||||
|
<th style='{$cellStyle}'>Kosten (CHF)</th>
|
||||||
|
</tr>{$stromRows}
|
||||||
|
<tr style='border-top:1px solid black;font-weight:bold;'>
|
||||||
|
<td colspan='8' style='text-align:right;{$cellStyle}'>Total Stromkosten:</td>
|
||||||
|
<td style='{$cellStyle}'>" . number_format($stromTotal, 2) . "</td>
|
||||||
|
</tr></table>";
|
||||||
|
|
||||||
|
if (!empty($stromTariffsUsed)) {
|
||||||
|
$html .= "<p style='font-size:7px;'><b>Angewendete Tarife:</b><br>";
|
||||||
|
foreach ($stromTariffsUsed as $period => $price) {
|
||||||
|
$html .= " {$period}: {$price} Rp/kWh<br>";
|
||||||
|
}
|
||||||
|
$html .= "</p>";
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- Nebenkosten ----------
|
||||||
|
$html .= "<h3 style='margin-top:15px;color:#6c757d;'>💧 Nebenkosten (Wasser & Wärme)</h3>";
|
||||||
|
$html .= "<table style='{$tableStyle}'>
|
||||||
|
<tr style='background-color:#e0e0e0;text-align:center;'>
|
||||||
|
<th style='{$cellStyle}'>Zähler</th>
|
||||||
|
<th style='{$cellStyle}'>Typ</th>
|
||||||
|
<th style='{$cellStyle}'>Startzeit</th>
|
||||||
|
<th style='{$cellStyle}'>Endzeit</th>
|
||||||
|
<th style='{$cellStyle}'>Zählerstart</th>
|
||||||
|
<th style='{$cellStyle}'>Zählerende</th>
|
||||||
|
<th style='{$cellStyle}'>Verbrauch</th>
|
||||||
|
<th style='{$cellStyle}'>Tarif (Rp)</th>
|
||||||
|
<th style='{$cellStyle}'>Kosten (CHF)</th>
|
||||||
|
</tr>{$nebenRows}
|
||||||
|
<tr style='border-top:1px solid black;font-weight:bold;'>
|
||||||
|
<td colspan='8' style='text-align:right;{$cellStyle}'>Total Nebenkosten:</td>
|
||||||
|
<td style='{$cellStyle}'>" . number_format($nebenTotal, 2) . "</td>
|
||||||
|
</tr></table>";
|
||||||
|
|
||||||
|
if (!empty($nebenTariffsUsed)) {
|
||||||
|
$html .= "<p style='font-size:7px;'><b>Angewendete Tarife:</b><br>";
|
||||||
|
foreach ($nebenTariffsUsed as $period => $price) {
|
||||||
|
$html .= " {$period}: {$price} Rp/m³ oder kWh<br>";
|
||||||
|
}
|
||||||
|
$html .= "</p>";
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- Gesamttotal ----------
|
||||||
|
$gesamtTotal = $stromTotal + $nebenTotal;
|
||||||
|
$html .= "<h3 style='text-align:right;margin-top:10px;'>💰 <u>Gesamttotal:</u> " . number_format($gesamtTotal, 2) . " CHF</h3>";
|
||||||
|
|
||||||
|
$pdf->writeHTML($html);
|
||||||
}
|
}
|
||||||
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'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$html .= "</table><h3>Gesamtsumme: " . number_format($total, 2) . " CHF</h3>";
|
|
||||||
$pdf->writeHTML($html);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user