no message
This commit is contained in:
@@ -108,82 +108,144 @@ class Abrechnung extends IPSModule
|
|||||||
private function BuildUserInvoice($pdf, $user, $power, $water, $tariffs, $from, $to)
|
private function BuildUserInvoice($pdf, $user, $power, $water, $tariffs, $from, $to)
|
||||||
{
|
{
|
||||||
$pdf->AddPage();
|
$pdf->AddPage();
|
||||||
|
$pdf->SetFont('dejavusans', '', 8);
|
||||||
|
|
||||||
// Kopfbereich
|
// Titel
|
||||||
$html = "
|
$html = "
|
||||||
<h1 style='text-align:center; margin-bottom:0;'>Elektro- und Nebenkostenabrechnung</h1>
|
<h2>Elektro- und Nebenkostenabrechnung</h2>
|
||||||
<hr>
|
<p><strong>Zählpunkte:</strong><br>";
|
||||||
<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 $pm) {
|
||||||
foreach ($power as $m) {
|
if ($pm['user_id'] == $user['id']) {
|
||||||
if ($m['user_id'] == $user['id']) {
|
$html .= "• " . htmlspecialchars($pm['name']) . "<br>";
|
||||||
$html .= htmlspecialchars($m['name']) . "<br>";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($water as $m) {
|
foreach ($water as $wm) {
|
||||||
if ($m['user_id'] == $user['id']) {
|
if ($wm['user_id'] == $user['id']) {
|
||||||
$html .= htmlspecialchars($m['name']) . "<br>";
|
$html .= "• " . htmlspecialchars($wm['name']) . "<br>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$html .= "
|
$html .= "</p>
|
||||||
</td>
|
<p><strong>Rechnungsadresse:</strong><br>"
|
||||||
<td width='40%'>
|
. htmlspecialchars($user['name']) . "<br>"
|
||||||
<strong>Rechnungsadresse:</strong><br>
|
. htmlspecialchars($user['address']) . "<br>"
|
||||||
{$user['name']}<br>
|
. htmlspecialchars($user['city']) . "<br></p>
|
||||||
{$user['address']}<br>
|
<p><strong>Zeitraum:</strong> " . date('d.m.Y', $from) . " – " . date('d.m.Y', $to) . "</p>
|
||||||
{$user['city']}<br>
|
<br><h3>Elektrizität</h3>";
|
||||||
</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
|
||||||
$powerResult = $this->GetCalculatedPowerCosts($user['id']);
|
$powerResult = $this->GetCalculatedPowerCosts($user['id']);
|
||||||
$html .= $powerResult['html'];
|
$html .= $this->FormatPowerTable($powerResult);
|
||||||
$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>";
|
|
||||||
|
|
||||||
|
// Nebenkosten
|
||||||
|
$html .= "<h3>Nebenkosten</h3>";
|
||||||
$additionalResult = $this->CalculateAdditionalCosts($water, $tariffs, $user['id'], $from, $to);
|
$additionalResult = $this->CalculateAdditionalCosts($water, $tariffs, $user['id'], $from, $to);
|
||||||
$html .= $additionalResult['html'];
|
$html .= $this->FormatAdditionalTable($additionalResult);
|
||||||
$totalAdditional = $additionalResult['sum'];
|
|
||||||
|
|
||||||
// ========================= Gesamttotal =========================
|
// Gesamtsumme
|
||||||
$grandTotal = $totalPower + $totalAdditional;
|
$grand = $powerResult['sum'] + $additionalResult['sum'];
|
||||||
$html .= "
|
$html .= "
|
||||||
<h2 style='text-align:right; margin-top:10px;'>
|
<table width='100%' cellpadding='3' cellspacing='0' style='font-size:8px; margin-top:10px;'>
|
||||||
Gesamttotal: <strong>" . number_format($grandTotal, 2) . " CHF</strong>
|
<tr>
|
||||||
</h2>
|
<td width='80%' align='right'><strong>Gesamttotal:</strong></td>
|
||||||
";
|
<td width='20%' align='right'><strong>" . number_format($grand, 2) . " CHF</strong></td>
|
||||||
|
</tr>
|
||||||
|
</table>";
|
||||||
|
|
||||||
|
// Render PDF
|
||||||
$pdf->writeHTML($html, true, false, true, false, '');
|
$pdf->writeHTML($html, true, false, true, false, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ============================ STROM – SCHÖNE TABELLE ============================ */
|
||||||
|
|
||||||
|
private function FormatPowerTable($result)
|
||||||
|
{
|
||||||
|
$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>Einnahmen (CHF)</th>
|
||||||
|
<th>Total (CHF)</th>
|
||||||
|
</tr>";
|
||||||
|
|
||||||
|
foreach ($result['data'] ?? $this->powerCostCache as $user => $meters) {
|
||||||
|
foreach ($meters as $m) {
|
||||||
|
$total = $m['cost_grid'] + $m['cost_solar'] - $m['rev_feedin'];
|
||||||
|
|
||||||
|
$html .= "
|
||||||
|
<tr>
|
||||||
|
<td>{$m['name']}</td>
|
||||||
|
<td align='right'>" . number_format($m['imp'], 3) . "</td>
|
||||||
|
<td align='right'>" . number_format($m['exp'], 3) . "</td>
|
||||||
|
<td align='right'>" . number_format($m['solar_bezug'], 3) . "</td>
|
||||||
|
<td align='right'>" . number_format($m['netz_bezug'], 3) . "</td>
|
||||||
|
<td align='right'>" . number_format($m['solareinspeisung'], 3) . "</td>
|
||||||
|
<td align='right'>" . number_format($m['solarverkauf'], 3) . "</td>
|
||||||
|
<td align='right'>" . number_format($m['cost_solar'], 2) . "</td>
|
||||||
|
<td align='right'>" . number_format($m['cost_grid'], 2) . "</td>
|
||||||
|
<td align='right'>" . number_format($m['rev_feedin'], 2) . "</td>
|
||||||
|
<td align='right'><strong>" . number_format($total, 2) . "</strong></td>
|
||||||
|
</tr>";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$html .= "</table>";
|
||||||
|
|
||||||
|
// Total in separater Tabelle
|
||||||
|
$html .= "
|
||||||
|
<table width='100%' cellpadding='3' cellspacing='0' style='font-size:7px; margin-top:4px;'>
|
||||||
|
<tr>
|
||||||
|
<td width='80%' align='right'><strong>Total Elektrizität:</strong></td>
|
||||||
|
<td width='20%' align='right'><strong>" . number_format($result['sum'], 2) . " CHF</strong></td>
|
||||||
|
</tr>
|
||||||
|
</table>";
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========================== NEBENKOSTEN – SCHÖNE TABELLE ========================== */
|
||||||
|
|
||||||
|
private function FormatAdditionalTable($result)
|
||||||
|
{
|
||||||
|
$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>
|
||||||
|
</tr>
|
||||||
|
" . $result['html'] . "
|
||||||
|
</table>";
|
||||||
|
|
||||||
|
// Total
|
||||||
|
$html .= "
|
||||||
|
<table width='100%' cellpadding='3' cellspacing='0' style='font-size:7px; margin-top:4px;'>
|
||||||
|
<tr>
|
||||||
|
<td width='80%' align='right'><strong>Total Nebenkosten:</strong></td>
|
||||||
|
<td width='20%' align='right'><strong>" . number_format($result['sum'], 2) . " CHF</strong></td>
|
||||||
|
</tr>
|
||||||
|
</table>";
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ====================== Stromkosten (15-Minuten, alle User) ======================
|
// ====================== Stromkosten (15-Minuten, alle User) ======================
|
||||||
|
|
||||||
private function CalculateAllPowerCosts($powerMeters, $tariffs, $from, $to)
|
private function CalculateAllPowerCosts($powerMeters, $tariffs, $from, $to)
|
||||||
@@ -644,5 +706,27 @@ $html = "
|
|||||||
}
|
}
|
||||||
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