no message
This commit is contained in:
@@ -109,23 +109,77 @@ class Abrechnung extends IPSModule
|
||||
{
|
||||
$pdf->AddPage();
|
||||
|
||||
// Kopfbereich
|
||||
$html = "
|
||||
<h2>Rechnung für {$user['name']}</h2>
|
||||
<p>{$user['address']}<br>{$user['city']}</p>
|
||||
<p><strong>Zeitraum:</strong> " . date('d.m.Y', $from) . " – " . date('d.m.Y', $to) . "</p><br>";
|
||||
<h1 style='text-align:center; margin-bottom:0;'>Elektro- und Nebenkostenabrechnung</h1>
|
||||
<hr>
|
||||
<table width='100%' style='font-size:10px; margin-top:5px;'>
|
||||
<tr>
|
||||
<td width='60%'>
|
||||
<strong>Zählpunkte:</strong><br>";
|
||||
|
||||
// Alle Zählerpunkte des Users auflisten
|
||||
foreach ($power as $m) {
|
||||
if ($m['user_id'] == $user['id']) {
|
||||
$html .= htmlspecialchars($m['name']) . "<br>";
|
||||
}
|
||||
}
|
||||
foreach ($water as $m) {
|
||||
if ($m['user_id'] == $user['id']) {
|
||||
$html .= htmlspecialchars($m['name']) . "<br>";
|
||||
}
|
||||
}
|
||||
|
||||
$html .= "
|
||||
</td>
|
||||
<td width='40%'>
|
||||
<strong>Rechnungsadresse:</strong><br>
|
||||
{$user['name']}<br>
|
||||
{$user['address']}<br>
|
||||
{$user['city']}<br>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p style='font-size:10px; margin-top:10px;'>
|
||||
<strong>Abrechnungszeitraum:</strong> " . date('d.m.Y', $from) . " – " . date('d.m.Y', $to) . "
|
||||
</p>
|
||||
<br>
|
||||
";
|
||||
|
||||
// ========================= Elektrizität =========================
|
||||
$html .= "<h2 style='margin-bottom:3px;'>Elektrizität</h2>";
|
||||
|
||||
// Stromkosten (aus globaler Berechnung)
|
||||
$powerResult = $this->GetCalculatedPowerCosts($user['id']);
|
||||
$html .= "<h3>⚡ Stromkosten</h3>" . $powerResult['html'];
|
||||
$html .= $powerResult['html'];
|
||||
$totalPower = $powerResult['sum'];
|
||||
|
||||
// Nebenkosten (Wasser/Wärme) – einfache Differenz von Beginn bis Ende
|
||||
// ========== Stromtarife anzeigen ==========
|
||||
$appliedTariffs = $this->CollectTariffsForUser($tariffs, ['Netztarif','Solartarif','Einspeisetarif']);
|
||||
if (!empty($appliedTariffs)) {
|
||||
$html .= "<p style='font-size:8px; margin-top:4px;'><strong>Angewendete Elektrizitätstarife:</strong></p><ul style='font-size:7px;'>";
|
||||
foreach ($appliedTariffs as $t) {
|
||||
$html .= "<li>"
|
||||
. date('d.m.Y', $t['start']) . "–" . date('d.m.Y', $t['end'])
|
||||
. " — <strong>" . number_format($t['price'], 2) . " Rp/kWh</strong>"
|
||||
. "</li>";
|
||||
}
|
||||
$html .= "</ul><br>";
|
||||
}
|
||||
|
||||
// ========================= Nebenkosten =========================
|
||||
$html .= "<h2 style='margin-bottom:3px;'>Nebenkosten</h2>";
|
||||
|
||||
$additionalResult = $this->CalculateAdditionalCosts($water, $tariffs, $user['id'], $from, $to);
|
||||
$html .= "<h3>💧 Nebenkosten (Wasser/Wärme)</h3>" . $additionalResult['html'];
|
||||
$html .= $additionalResult['html'];
|
||||
$totalAdditional = $additionalResult['sum'];
|
||||
|
||||
// ========================= Gesamttotal =========================
|
||||
$grandTotal = $totalPower + $totalAdditional;
|
||||
$html .= "<h3 style='text-align:right;'>Gesamttotal: <strong>" . number_format($grandTotal, 2) . " CHF</strong></h3>";
|
||||
$html .= "
|
||||
<h2 style='text-align:right; margin-top:10px;'>
|
||||
Gesamttotal: <strong>" . number_format($grandTotal, 2) . " CHF</strong>
|
||||
</h2>
|
||||
";
|
||||
|
||||
$pdf->writeHTML($html, true, false, true, false, '');
|
||||
}
|
||||
@@ -269,21 +323,23 @@ class Abrechnung extends IPSModule
|
||||
|
||||
private function GetCalculatedPowerCosts($userId)
|
||||
{
|
||||
$html = "<table border='1' cellspacing='0' cellpadding='3' width='100%' style='font-size:6px;'>
|
||||
$html = "
|
||||
<table border='1' cellspacing='0' cellpadding='2' width='100%' style='font-size:6px;'>
|
||||
<tr style='background-color:#f0f0f0;'>
|
||||
<th>Zähler</th>
|
||||
<th>Import (kWh)</th>
|
||||
<th>Export (kWh)</th>
|
||||
<th>Solarbezug (kWh)</th>
|
||||
<th>Netzbezug (kWh)</th>
|
||||
<th>Solareinspeisung (kWh)</th>
|
||||
<th>Solarverkauf (kWh)</th>
|
||||
<th>Kosten Solar (CHF)</th>
|
||||
<th>Kosten Netz (CHF)</th>
|
||||
<th>Ertrag Einspeisung (CHF)</th>
|
||||
<th>Summe (CHF)</th>
|
||||
<th>Import</th>
|
||||
<th>Export</th>
|
||||
<th>Solarbez.</th>
|
||||
<th>Netzbez.</th>
|
||||
<th>Solar Eins.</th>
|
||||
<th>Solarverk.</th>
|
||||
<th>Solar CHF</th>
|
||||
<th>Netz CHF</th>
|
||||
<th>Einspeis. CHF</th>
|
||||
<th>Total CHF</th>
|
||||
</tr>";
|
||||
|
||||
|
||||
if (empty($this->powerCostCache) || !isset($this->powerCostCache[$userId])) {
|
||||
$html .= "<tr><td colspan='11' align='center'>Keine Stromzähler für diesen Benutzer</td></tr></table><br>";
|
||||
return ['html' => $html, 'sum' => 0.0];
|
||||
@@ -306,13 +362,13 @@ class Abrechnung extends IPSModule
|
||||
<td align='right'>" . number_format($a['cost_solar'], 2) . "</td>
|
||||
<td align='right'>" . number_format($a['cost_grid'], 2) . "</td>
|
||||
<td align='right'>" . number_format($a['rev_feedin'], 2) . "</td>
|
||||
<td align='right'><b>" . number_format($subtotal, 2) . "</b></td>
|
||||
<td align='right'><b>" . number_format($subtotal, 2) . " CHF</b></td>
|
||||
</tr>";
|
||||
}
|
||||
|
||||
$html .= "<tr style='background-color:#f9f9f9; font-weight:bold;'>
|
||||
<td colspan='10' align='right'>Total Stromkosten:</td>
|
||||
<td align='right'>" . number_format($sum, 2) . "</td>
|
||||
<td colspan='10' align='right'><b>Total Elektrizität:</b></td>
|
||||
<td align='right'><b>" . number_format($sum, 2) . " CHF</b></td>
|
||||
</tr></table><br>";
|
||||
|
||||
return ['html' => $html, 'sum' => $sum];
|
||||
@@ -322,12 +378,21 @@ class Abrechnung extends IPSModule
|
||||
|
||||
private function CalculateAdditionalCosts($waterMeters, $tariffs, $userId, $from, $to)
|
||||
{
|
||||
$html = "<table border='1' cellspacing='0' cellpadding='3' width='100%' style='font-size:6px;'>
|
||||
$html = "
|
||||
<table border='1' cellspacing='0' cellpadding='2' width='100%' style='font-size:6px;'>
|
||||
<tr style='background-color:#f0f0f0;'>
|
||||
<th>Zähler</th><th>Typ</th><th>Start</th><th>Ende</th>
|
||||
<th>Zähler Start</th><th>Zähler Ende</th><th>Verbrauch</th><th>Tarif (Rp)</th><th>Kosten (CHF)</th>
|
||||
<th>Zähler</th>
|
||||
<th>Typ</th>
|
||||
<th>Start</th>
|
||||
<th>Ende</th>
|
||||
<th>Stand Start</th>
|
||||
<th>Stand Ende</th>
|
||||
<th>Verbrauch</th>
|
||||
<th>Tarif</th>
|
||||
<th>Kosten CHF</th>
|
||||
</tr>";
|
||||
|
||||
|
||||
$total = 0.0;
|
||||
$usedTariffs = [];
|
||||
|
||||
@@ -343,8 +408,9 @@ class Abrechnung extends IPSModule
|
||||
}
|
||||
|
||||
$html .= "<tr style='background-color:#f9f9f9; font-weight:bold;'>
|
||||
<td colspan='8' align='right'>Total Nebenkosten:</td>
|
||||
<td align='right'>" . number_format($total, 2) . "</td>
|
||||
<td colspan='8' align='right'><b>Total Nebenkosten:</b></td>
|
||||
<td align='right'><b>" . number_format($total, 2) . " CHF</b></td>
|
||||
|
||||
</tr></table><br>";
|
||||
|
||||
if (!empty($usedTariffs)) {
|
||||
@@ -578,5 +644,27 @@ class Abrechnung extends IPSModule
|
||||
}
|
||||
return end($cands);
|
||||
}
|
||||
private function CollectTariffsForUser($tariffs, $types)
|
||||
{
|
||||
$result = [];
|
||||
$wanted = array_map('strtolower', $types);
|
||||
|
||||
foreach ($tariffs as $t) {
|
||||
$type = strtolower(trim($t['unit_type'] ?? ''));
|
||||
if (!in_array($type, $wanted)) continue;
|
||||
|
||||
$start = $this->toUnixTs($t['start'], false);
|
||||
$end = $this->toUnixTs($t['end'], true);
|
||||
|
||||
$result[] = [
|
||||
'start' => $start,
|
||||
'end' => $end,
|
||||
'price' => (float)$t['price']
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user