no message
This commit is contained in:
@@ -108,126 +108,124 @@ class Abrechnung extends IPSModule
|
||||
// 🧱 Layout / PDF-Aufbau pro Benutzerseite
|
||||
// ===========================================================
|
||||
private function BuildUserInvoice($user, $power, $water, $tariffs, $from, $to)
|
||||
{
|
||||
$stromRows = '';
|
||||
$stromTotal = 0.0;
|
||||
$stromTariffsUsed = [];
|
||||
{
|
||||
$stromRows = '';
|
||||
$stromTotal = 0.0;
|
||||
$stromTariffsUsed = [];
|
||||
|
||||
$nebenRows = '';
|
||||
$nebenTotal = 0.0;
|
||||
$nebenTariffsUsed = [];
|
||||
$nebenRows = '';
|
||||
$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'];
|
||||
|
||||
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 ----------
|
||||
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'];
|
||||
|
||||
foreach ($tariffs as $t) {
|
||||
$u = strtolower($t['unit_type'] ?? '');
|
||||
if (in_array($u, ['warmwasser', 'kaltwasser', 'wärme'])) {
|
||||
$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);
|
||||
$nebenTariffsUsed[$period] = number_format(floatval($t['price']), 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$gesamtTotal = $stromTotal + $nebenTotal;
|
||||
$tableStyle = "border-collapse:collapse;width:100%;font-size:8px;";
|
||||
$cellStyle = "border:0.3px solid #999;padding:2px;";
|
||||
|
||||
$html = "
|
||||
<h2 style='text-align:center;'>Rechnung für {$user['name']}</h2>
|
||||
<p>{$user['address']}<br>{$user['city']}</p>
|
||||
<p><b>Abrechnungszeitraum:</b> " . date('d.m.Y', $from) . " – " . date('d.m.Y', $to) . "</p>
|
||||
|
||||
<h3 style='margin-top:10px;color:#004085;'>⚡ Stromkosten</h3>
|
||||
<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}'>Start</th>
|
||||
<th style='{$cellStyle}'>Ende</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>";
|
||||
}
|
||||
|
||||
$html .= "
|
||||
<h3 style='margin-top:15px;color:#6c757d;'>💧 Nebenkosten (Wasser & Wärme)</h3>
|
||||
<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}'>Start</th>
|
||||
<th style='{$cellStyle}'>Ende</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>";
|
||||
}
|
||||
|
||||
$html .= "<h3 style='text-align:right;margin-top:10px;'>💰 <u>Gesamttotal:</u> " . number_format($gesamtTotal, 2) . " CHF</h3>";
|
||||
|
||||
return $html;
|
||||
// ---------- 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'];
|
||||
}
|
||||
|
||||
// ---------- Nebenkosten ----------
|
||||
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'];
|
||||
}
|
||||
|
||||
// ---------- Alle Tarife gruppieren ----------
|
||||
$tariffGroups = [];
|
||||
foreach ($tariffs as $t) {
|
||||
$type = ucfirst(strtolower($t['unit_type'] ?? 'Unbekannt'));
|
||||
$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);
|
||||
$price = number_format(floatval($t['price']), 2);
|
||||
$tariffGroups[$type][] = "{$period}: {$price} Rp";
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- Gesamtsummen ----------
|
||||
$gesamtTotal = $stromTotal + $nebenTotal;
|
||||
|
||||
// ---------- Tabellenstil ----------
|
||||
$tableStyle = "border-collapse:collapse;width:100%;font-size:8px;";
|
||||
$cellStyle = "border:0.3px solid #bbb;padding:3px;vertical-align:middle;";
|
||||
|
||||
// ---------- Kopfbereich ----------
|
||||
$html = "
|
||||
<h2 style='text-align:center;'>Rechnung für {$user['name']}</h2>
|
||||
<p>{$user['address']}<br>{$user['city']}</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>
|
||||
<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}'>Start</th>
|
||||
<th style='{$cellStyle}'>Ende</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;background-color:#f8f9fa;'>
|
||||
<td colspan='8' style='text-align:right;{$cellStyle}'>Total Stromkosten:</td>
|
||||
<td style='{$cellStyle}text-align:right;'>" . number_format($stromTotal, 2) . "</td>
|
||||
</tr>
|
||||
</table>";
|
||||
|
||||
// ---------- Nebenkosten ----------
|
||||
$html .= "
|
||||
<h3 style='margin-top:15px;color:#6c757d;'>💧 Nebenkosten (Wasser & Wärme)</h3>
|
||||
<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}'>Start</th>
|
||||
<th style='{$cellStyle}'>Ende</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;background-color:#f8f9fa;'>
|
||||
<td colspan='8' style='text-align:right;{$cellStyle}'>Total Nebenkosten:</td>
|
||||
<td style='{$cellStyle}text-align:right;'>" . number_format($nebenTotal, 2) . "</td>
|
||||
</tr>
|
||||
</table>";
|
||||
|
||||
// ---------- Tarife (alle Typen) ----------
|
||||
if (!empty($tariffGroups)) {
|
||||
$html .= "<h4 style='margin-top:15px;'>📋 Angewendete Tarife</h4><table style='{$tableStyle}'>";
|
||||
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 .= "</table>";
|
||||
}
|
||||
|
||||
// ---------- 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;
|
||||
}
|
||||
|
||||
|
||||
// ===========================================================
|
||||
// 🧮 Datumskonvertierung – robust für JSON, String, Timestamp
|
||||
// ===========================================================
|
||||
@@ -290,6 +288,7 @@ class Abrechnung extends IPSModule
|
||||
|
||||
return floatval(GetValue($varId));
|
||||
}
|
||||
|
||||
private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
||||
{
|
||||
$rows = '';
|
||||
|
||||
Reference in New Issue
Block a user