no message
This commit is contained in:
@@ -105,30 +105,84 @@ class Abrechnung extends IPSModule
|
|||||||
return $pdf->Output('Abrechnung.pdf', 'S');
|
return $pdf->Output('Abrechnung.pdf', 'S');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function BuildUserInvoice($pdf, $user, $power, $water, $tariffs, $from, $to)
|
private function BuildUserInvoice($pdf, $user, $power, $water, $tariffs, $from, $to)
|
||||||
{
|
{
|
||||||
$pdf->AddPage();
|
$pdf->AddPage();
|
||||||
|
|
||||||
$html = "
|
// Kopfbereich
|
||||||
<h2>Rechnung für {$user['name']}</h2>
|
$html = "
|
||||||
<p>{$user['address']}<br>{$user['city']}</p>
|
<h1 style='text-align:center; margin-bottom:0;'>Elektro- und Nebenkostenabrechnung</h1>
|
||||||
<p><strong>Zeitraum:</strong> " . date('d.m.Y', $from) . " – " . date('d.m.Y', $to) . "</p><br>";
|
<hr>
|
||||||
|
<table width='100%' style='font-size:10px; margin-top:5px;'>
|
||||||
|
<tr>
|
||||||
|
<td width='60%'>
|
||||||
|
<strong>Zählpunkte:</strong><br>";
|
||||||
|
|
||||||
// Stromkosten (aus globaler Berechnung)
|
// Alle Zählerpunkte des Users auflisten
|
||||||
$powerResult = $this->GetCalculatedPowerCosts($user['id']);
|
foreach ($power as $m) {
|
||||||
$html .= "<h3>⚡ Stromkosten</h3>" . $powerResult['html'];
|
if ($m['user_id'] == $user['id']) {
|
||||||
$totalPower = $powerResult['sum'];
|
$html .= htmlspecialchars($m['name']) . "<br>";
|
||||||
|
}
|
||||||
// Nebenkosten (Wasser/Wärme) – einfache Differenz von Beginn bis Ende
|
|
||||||
$additionalResult = $this->CalculateAdditionalCosts($water, $tariffs, $user['id'], $from, $to);
|
|
||||||
$html .= "<h3>💧 Nebenkosten (Wasser/Wärme)</h3>" . $additionalResult['html'];
|
|
||||||
$totalAdditional = $additionalResult['sum'];
|
|
||||||
|
|
||||||
$grandTotal = $totalPower + $totalAdditional;
|
|
||||||
$html .= "<h3 style='text-align:right;'>Gesamttotal: <strong>" . number_format($grandTotal, 2) . " CHF</strong></h3>";
|
|
||||||
|
|
||||||
$pdf->writeHTML($html, true, false, true, false, '');
|
|
||||||
}
|
}
|
||||||
|
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>";
|
||||||
|
|
||||||
|
$powerResult = $this->GetCalculatedPowerCosts($user['id']);
|
||||||
|
$html .= $powerResult['html'];
|
||||||
|
$totalPower = $powerResult['sum'];
|
||||||
|
|
||||||
|
// ========== 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 .= $additionalResult['html'];
|
||||||
|
$totalAdditional = $additionalResult['sum'];
|
||||||
|
|
||||||
|
// ========================= Gesamttotal =========================
|
||||||
|
$grandTotal = $totalPower + $totalAdditional;
|
||||||
|
$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, '');
|
||||||
|
}
|
||||||
|
|
||||||
// ====================== Stromkosten (15-Minuten, alle User) ======================
|
// ====================== Stromkosten (15-Minuten, alle User) ======================
|
||||||
|
|
||||||
@@ -269,20 +323,22 @@ class Abrechnung extends IPSModule
|
|||||||
|
|
||||||
private function GetCalculatedPowerCosts($userId)
|
private function GetCalculatedPowerCosts($userId)
|
||||||
{
|
{
|
||||||
$html = "<table border='1' cellspacing='0' cellpadding='3' width='100%' style='font-size:6px;'>
|
$html = "
|
||||||
<tr style='background-color:#f0f0f0;'>
|
<table border='1' cellspacing='0' cellpadding='2' width='100%' style='font-size:6px;'>
|
||||||
<th>Zähler</th>
|
<tr style='background-color:#f0f0f0;'>
|
||||||
<th>Import (kWh)</th>
|
<th>Zähler</th>
|
||||||
<th>Export (kWh)</th>
|
<th>Import</th>
|
||||||
<th>Solarbezug (kWh)</th>
|
<th>Export</th>
|
||||||
<th>Netzbezug (kWh)</th>
|
<th>Solarbez.</th>
|
||||||
<th>Solareinspeisung (kWh)</th>
|
<th>Netzbez.</th>
|
||||||
<th>Solarverkauf (kWh)</th>
|
<th>Solar Eins.</th>
|
||||||
<th>Kosten Solar (CHF)</th>
|
<th>Solarverk.</th>
|
||||||
<th>Kosten Netz (CHF)</th>
|
<th>Solar CHF</th>
|
||||||
<th>Ertrag Einspeisung (CHF)</th>
|
<th>Netz CHF</th>
|
||||||
<th>Summe (CHF)</th>
|
<th>Einspeis. CHF</th>
|
||||||
</tr>";
|
<th>Total CHF</th>
|
||||||
|
</tr>";
|
||||||
|
|
||||||
|
|
||||||
if (empty($this->powerCostCache) || !isset($this->powerCostCache[$userId])) {
|
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>";
|
$html .= "<tr><td colspan='11' align='center'>Keine Stromzähler für diesen Benutzer</td></tr></table><br>";
|
||||||
@@ -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_solar'], 2) . "</td>
|
||||||
<td align='right'>" . number_format($a['cost_grid'], 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'>" . 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>";
|
</tr>";
|
||||||
}
|
}
|
||||||
|
|
||||||
$html .= "<tr style='background-color:#f9f9f9; font-weight:bold;'>
|
$html .= "<tr style='background-color:#f9f9f9; font-weight:bold;'>
|
||||||
<td colspan='10' align='right'>Total Stromkosten:</td>
|
<td colspan='10' align='right'><b>Total Elektrizität:</b></td>
|
||||||
<td align='right'>" . number_format($sum, 2) . "</td>
|
<td align='right'><b>" . number_format($sum, 2) . " CHF</b></td>
|
||||||
</tr></table><br>";
|
</tr></table><br>";
|
||||||
|
|
||||||
return ['html' => $html, 'sum' => $sum];
|
return ['html' => $html, 'sum' => $sum];
|
||||||
@@ -322,11 +378,20 @@ class Abrechnung extends IPSModule
|
|||||||
|
|
||||||
private function CalculateAdditionalCosts($waterMeters, $tariffs, $userId, $from, $to)
|
private function CalculateAdditionalCosts($waterMeters, $tariffs, $userId, $from, $to)
|
||||||
{
|
{
|
||||||
$html = "<table border='1' cellspacing='0' cellpadding='3' width='100%' style='font-size:6px;'>
|
$html = "
|
||||||
<tr style='background-color:#f0f0f0;'>
|
<table border='1' cellspacing='0' cellpadding='2' width='100%' style='font-size:6px;'>
|
||||||
<th>Zähler</th><th>Typ</th><th>Start</th><th>Ende</th>
|
<tr style='background-color:#f0f0f0;'>
|
||||||
<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>
|
||||||
</tr>";
|
<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;
|
$total = 0.0;
|
||||||
$usedTariffs = [];
|
$usedTariffs = [];
|
||||||
@@ -343,8 +408,9 @@ class Abrechnung extends IPSModule
|
|||||||
}
|
}
|
||||||
|
|
||||||
$html .= "<tr style='background-color:#f9f9f9; font-weight:bold;'>
|
$html .= "<tr style='background-color:#f9f9f9; font-weight:bold;'>
|
||||||
<td colspan='8' align='right'>Total Nebenkosten:</td>
|
<td colspan='8' align='right'><b>Total Nebenkosten:</b></td>
|
||||||
<td align='right'>" . number_format($total, 2) . "</td>
|
<td align='right'><b>" . number_format($total, 2) . " CHF</b></td>
|
||||||
|
|
||||||
</tr></table><br>";
|
</tr></table><br>";
|
||||||
|
|
||||||
if (!empty($usedTariffs)) {
|
if (!empty($usedTariffs)) {
|
||||||
@@ -578,5 +644,27 @@ class Abrechnung extends IPSModule
|
|||||||
}
|
}
|
||||||
return end($cands);
|
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