no message

This commit is contained in:
dh
2025-11-05 14:12:12 +01:00
parent dfcac3543b
commit f96a505cb9
+37 -38
View File
@@ -123,17 +123,6 @@ class Abrechnung extends IPSModule
$res = $this->AddMeterToPDFRow($m, $tariffs, $from, $to, 'Strombezug'); $res = $this->AddMeterToPDFRow($m, $tariffs, $from, $to, 'Strombezug');
$stromRows .= $res['row']; $stromRows .= $res['row'];
$stromTotal += $res['value']; $stromTotal += $res['value'];
foreach ($tariffs as $t) {
if (strtolower($t['unit_type']) == 'strombezug') {
$sTs = $this->toUnixTs($t['start'], false);
$eTs = $this->toUnixTs($t['end'], true);
if ($sTs && $eTs) {
$period = date('d.m.Y', $sTs) . ' - ' . date('d.m.Y', $eTs);
$stromTariffsUsed[$period] = number_format(floatval($t['price']), 2);
}
}
}
} }
// ---------- Nebenkosten ---------- // ---------- Nebenkosten ----------
@@ -143,29 +132,36 @@ class Abrechnung extends IPSModule
$res = $this->AddMeterToPDFRow($m, $tariffs, $from, $to, $type); $res = $this->AddMeterToPDFRow($m, $tariffs, $from, $to, $type);
$nebenRows .= $res['row']; $nebenRows .= $res['row'];
$nebenTotal += $res['value']; $nebenTotal += $res['value'];
}
// ---------- Alle Tarife gruppieren ----------
$tariffGroups = [];
foreach ($tariffs as $t) { foreach ($tariffs as $t) {
$u = strtolower($t['unit_type'] ?? ''); $type = ucfirst(strtolower($t['unit_type'] ?? 'Unbekannt'));
if (in_array($u, ['warmwasser', 'kaltwasser', 'wärme'])) {
$sTs = $this->toUnixTs($t['start'], false); $sTs = $this->toUnixTs($t['start'], false);
$eTs = $this->toUnixTs($t['end'], true); $eTs = $this->toUnixTs($t['end'], true);
if ($sTs && $eTs) { if ($sTs && $eTs) {
$period = date('d.m.Y', $sTs) . ' - ' . date('d.m.Y', $eTs); $period = date('d.m.Y', $sTs) . ' – ' . date('d.m.Y', $eTs);
$nebenTariffsUsed[$period] = number_format(floatval($t['price']), 2); $price = number_format(floatval($t['price']), 2);
} $tariffGroups[$type][] = "{$period}: {$price} Rp";
}
} }
} }
// ---------- Gesamtsummen ----------
$gesamtTotal = $stromTotal + $nebenTotal; $gesamtTotal = $stromTotal + $nebenTotal;
$tableStyle = "border-collapse:collapse;width:100%;font-size:8px;";
$cellStyle = "border:0.3px solid #999;padding:2px;";
// ---------- Tabellenstil ----------
$tableStyle = "border-collapse:collapse;width:100%;font-size:8px;";
$cellStyle = "border:0.3px solid #bbb;padding:3px;vertical-align:middle;";
// ---------- Kopfbereich ----------
$html = " $html = "
<h2 style='text-align:center;'>Rechnung für {$user['name']}</h2> <h2 style='text-align:center;'>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> <p><b>Abrechnungszeitraum:</b> " . date('d.m.Y', $from) . " – " . date('d.m.Y', $to) . "</p>";
// ---------- Stromkosten ----------
$html .= "
<h3 style='margin-top:10px;color:#004085;'>⚡ Stromkosten</h3> <h3 style='margin-top:10px;color:#004085;'>⚡ Stromkosten</h3>
<table style='{$tableStyle}'> <table style='{$tableStyle}'>
<tr style='background-color:#e0e0e0;text-align:center;'> <tr style='background-color:#e0e0e0;text-align:center;'>
@@ -180,20 +176,13 @@ class Abrechnung extends IPSModule
<th style='{$cellStyle}'>Kosten (CHF)</th> <th style='{$cellStyle}'>Kosten (CHF)</th>
</tr> </tr>
{$stromRows} {$stromRows}
<tr style='border-top:1px solid black;font-weight:bold;'> <tr style='border-top:1px solid black;font-weight:bold;background-color:#f8f9fa;'>
<td colspan='8' style='text-align:right;{$cellStyle}'>Total Stromkosten:</td> <td colspan='8' style='text-align:right;{$cellStyle}'>Total Stromkosten:</td>
<td style='{$cellStyle}'>" . number_format($stromTotal, 2) . "</td> <td style='{$cellStyle}text-align:right;'>" . number_format($stromTotal, 2) . "</td>
</tr> </tr>
</table>"; </table>";
if (!empty($stromTariffsUsed)) { // ---------- Nebenkosten ----------
$html .= "<p style='font-size:7px;'><b>Angewendete Tarife:</b><br>";
foreach ($stromTariffsUsed as $period => $price) {
$html .= "&nbsp;&nbsp;{$period}: {$price} Rp/kWh<br>";
}
$html .= "</p>";
}
$html .= " $html .= "
<h3 style='margin-top:15px;color:#6c757d;'>💧 Nebenkosten (Wasser & Wärme)</h3> <h3 style='margin-top:15px;color:#6c757d;'>💧 Nebenkosten (Wasser & Wärme)</h3>
<table style='{$tableStyle}'> <table style='{$tableStyle}'>
@@ -209,25 +198,34 @@ class Abrechnung extends IPSModule
<th style='{$cellStyle}'>Kosten (CHF)</th> <th style='{$cellStyle}'>Kosten (CHF)</th>
</tr> </tr>
{$nebenRows} {$nebenRows}
<tr style='border-top:1px solid black;font-weight:bold;'> <tr style='border-top:1px solid black;font-weight:bold;background-color:#f8f9fa;'>
<td colspan='8' style='text-align:right;{$cellStyle}'>Total Nebenkosten:</td> <td colspan='8' style='text-align:right;{$cellStyle}'>Total Nebenkosten:</td>
<td style='{$cellStyle}'>" . number_format($nebenTotal, 2) . "</td> <td style='{$cellStyle}text-align:right;'>" . number_format($nebenTotal, 2) . "</td>
</tr> </tr>
</table>"; </table>";
if (!empty($nebenTariffsUsed)) { // ---------- Tarife (alle Typen) ----------
$html .= "<p style='font-size:7px;'><b>Angewendete Tarife:</b><br>"; if (!empty($tariffGroups)) {
foreach ($nebenTariffsUsed as $period => $price) { $html .= "<h4 style='margin-top:15px;'>📋 Angewendete Tarife</h4><table style='{$tableStyle}'>";
$html .= "&nbsp;&nbsp;{$period}: {$price} Rp/m³ oder kWh<br>"; foreach ($tariffGroups as $type => $entries) {
$html .= "<tr><td colspan='2' style='{$cellStyle}background-color:#efefef;'><b>{$type}</b></td></tr>";
foreach ($entries as $line) {
$html .= "<tr><td colspan='2' style='{$cellStyle}border-top:none;'>{$line}</td></tr>";
} }
$html .= "</p>"; }
$html .= "</table>";
} }
$html .= "<h3 style='text-align:right;margin-top:10px;'>💰 <u>Gesamttotal:</u> " . number_format($gesamtTotal, 2) . " CHF</h3>"; // ---------- Gesamttotal ----------
$html .= "
<h3 style='text-align:right;margin-top:15px;background-color:#f1f1f1;padding:6px;border:0.5px solid #aaa;'>
💰 <u>Gesamttotal:</u> " . number_format($gesamtTotal, 2) . " CHF
</h3>";
return $html; return $html;
} }
// =========================================================== // ===========================================================
// 🧮 Datumskonvertierung – robust für JSON, String, Timestamp // 🧮 Datumskonvertierung – robust für JSON, String, Timestamp
// =========================================================== // ===========================================================
@@ -290,6 +288,7 @@ class Abrechnung extends IPSModule
return floatval(GetValue($varId)); return floatval(GetValue($varId));
} }
private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type) private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
{ {
$rows = ''; $rows = '';