This commit is contained in:
2025-12-12 09:42:23 +01:00
parent 422ea912b0
commit 1b20b2e637

View File

@@ -399,26 +399,64 @@ class Abrechnung extends IPSModule
} }
private function GetCalculatedPowerCosts($userId) private function GetCalculatedPowerCosts($userId)
{ {
// Inline-styles + TCPDF-kompatible Struktur
$html = " $html = "
<table width='100%' cellpadding='4' cellspacing='0' style='font-size:10px; border-collapse: collapse;'> <style>
table.powercost {
width: 100%;
border-collapse: collapse;
font-size: 10px;
}
table.powercost th {
background-color: #444;
color: white;
padding: 4px;
text-align: center;
font-weight: bold;
border: 1px solid #777;
}
table.powercost td {
padding: 3px 4px;
border: 1px solid #ccc;
}
.row-even { background-color: #f7f7f7; }
.row-odd { background-color: #ffffff; }
.row-empty { background-color: #e0e0e0; height: 5px; }
/* Neue Formatierungen */
.num {
text-align: right;
font-family: monospace;
width: 90px;
}
.subtotal-row {
border-top: 1px solid black;
font-weight: bold;
}
.total-row {
border-top: 3px double black;
font-weight: bold;
background-color: #ddd;
}
</style>
<table class='powercost'>
<tr> <tr>
<th style='background-color:#444; color:#fff; padding:6px; border:1px solid #777; text-align:left;'>ID</th> <th>ID</th>
<th style='background-color:#444; color:#fff; padding:6px; border:1px solid #777; text-align:right;'>Import (kWh)</th> <th>Import (kWh)</th>
<th style='background-color:#444; color:#fff; padding:6px; border:1px solid #777; text-align:right;'>Export (kWh)</th> <th>Export (kWh)</th>
<th style='background-color:#444; color:#fff; padding:6px; border:1px solid #777; text-align:right;'>ZEV-Haus (kWh)</th> <th>ZEV-Haus (kWh)</th>
<th style='background-color:#444; color:#fff; padding:6px; border:1px solid #777; text-align:right;'>Netz-Haus (kWh)</th> <th>Netz-Haus (kWh)</th>
<th style='background-color:#444; color:#fff; padding:6px; border:1px solid #777; text-align:right;'>Solar-Netz (kWh)</th> <th>Solar-Netz (kWh)</th>
<th style='background-color:#444; color:#fff; padding:6px; border:1px solid #777; text-align:right;'>Solar-ZEV (kWh)</th> <th>Solar-ZEV (kWh)</th>
<th style='background-color:#444; color:#fff; padding:6px; border:1px solid #777; text-align:right;'>Kauf Solar (CHF)</th> <th>Kauf Solar (CHF)</th>
<th style='background-color:#444; color:#fff; padding:6px; border:1px solid #777; text-align:right;'>Kauf Netz (CHF)</th> <th>Kauf Netz (CHF)</th>
<th style='background-color:#444; color:#fff; padding:6px; border:1px solid #777; text-align:right;'>Verkauf Netz (CHF)</th> <th>Verkauf Netz (CHF)</th>
<th style='background-color:#444; color:#fff; padding:6px; border:1px solid #777; text-align:right;'>Verkauf ZEV (CHF)</th> <th>Verkauf ZEV (CHF)</th>
<th style='background-color:#444; color:#fff; padding:6px; border:1px solid #777; text-align:right;'>Total CHF</th> <th>Total CHF</th>
</tr>"; </tr>";
if (empty($this->powerCostCache) || !isset($this->powerCostCache[$userId])) { if (empty($this->powerCostCache) || !isset($this->powerCostCache[$userId])) {
$html .= "<tr><td colspan='12' align='center' style='padding:10px;'>Keine Stromzähler für diesen Benutzer</td></tr></table>"; $html .= "<tr><td colspan='12' align='center'>Keine Stromzähler für diesen Benutzer</td></tr></table>";
return ['html' => $html, 'sum' => 0.0]; return ['html' => $html, 'sum' => 0.0];
} }
@@ -430,94 +468,45 @@ private function GetCalculatedPowerCosts($userId)
$subtotal = $a['cost_grid'] + $a['cost_solar'] - ($a['rev_feedin'] + $a['rev_zev']); $subtotal = $a['cost_grid'] + $a['cost_solar'] - ($a['rev_feedin'] + $a['rev_zev']);
$sum += $subtotal; $sum += $subtotal;
// Alternierende Hintergrundfarbe (einfach über inline style) $rowClass = ($rowIndex % 2 === 0) ? "row-even" : "row-odd";
$bg = ($rowIndex % 2 === 0) ? '#f7f7f7' : '#ffffff';
$rowIndex++; $rowIndex++;
// Funktion zum formatieren mit monospace-alignment (Breite anpassen falls nötig) // Datenzeile
$fmtKwh = function($v) { return number_format($v, 3, '.', "'"); }; // Tausendertrenner ' optional $html .= "<tr class='{$rowClass}'>
$fmtChf = function($v) { return number_format($v, 2, '.', "'"); }; <td>{$a['name']}</td>
<td class='num'>" . number_format($a['imp'], 3) . "</td>
$html .= "<tr style='background-color:{$bg};'> <td class='num'>" . number_format($a['exp'], 3) . "</td>
<td style='border:1px solid #ccc; padding:6px; vertical-align:top;'>{$a['name']}</td> <td class='num'>" . number_format($a['solar_bezug'], 3) . "</td>
<td class='num'>" . number_format($a['netz_bezug'], 3) . "</td>
<td style='border:1px solid #ccc; padding:6px; text-align:right; vertical-align:top;'> <td class='num'>" . number_format($a['solareinspeisung'], 3) . "</td>
<span style='font-family:Courier, monospace; display:inline-block; min-width:90px;'>" . $fmtKwh($a['imp']) . "</span> <td class='num'>" . number_format($a['solarverkauf'], 3) . "</td>
</td> <td class='num'>" . number_format($a['cost_solar'], 2) . "</td>
<td class='num'>" . number_format($a['cost_grid'], 2) . "</td>
<td style='border:1px solid #ccc; padding:6px; text-align:right; vertical-align:top;'> <td class='num'>" . number_format($a['rev_feedin'], 2) . "</td>
<span style='font-family:Courier, monospace; display:inline-block; min-width:90px;'>" . $fmtKwh($a['exp']) . "</span> <td class='num'>" . number_format($a['rev_zev'], 2) . "</td>
</td> <td class='num'>" . number_format($subtotal, 2) . "</td>
<td style='border:1px solid #ccc; padding:6px; text-align:right; vertical-align:top;'>
<span style='font-family:Courier, monospace; display:inline-block; min-width:90px;'>" . $fmtKwh($a['solar_bezug']) . "</span>
</td>
<td style='border:1px solid #ccc; padding:6px; text-align:right; vertical-align:top;'>
<span style='font-family:Courier, monospace; display:inline-block; min-width:90px;'>" . $fmtKwh($a['netz_bezug']) . "</span>
</td>
<td style='border:1px solid #ccc; padding:6px; text-align:right; vertical-align:top;'>
<span style='font-family:Courier, monospace; display:inline-block; min-width:90px;'>" . $fmtKwh($a['solareinspeisung']) . "</span>
</td>
<td style='border:1px solid #ccc; padding:6px; text-align:right; vertical-align:top;'>
<span style='font-family:Courier, monospace; display:inline-block; min-width:90px;'>" . $fmtKwh($a['solarverkauf']) . "</span>
</td>
<td style='border:1px solid #ccc; padding:6px; text-align:right; vertical-align:top;'>
<span style='font-family:Courier, monospace; display:inline-block; min-width:90px;'>" . $fmtChf($a['cost_solar']) . "</span>
</td>
<td style='border:1px solid #ccc; padding:6px; text-align:right; vertical-align:top;'>
<span style='font-family:Courier, monospace; display:inline-block; min-width:90px;'>" . $fmtChf($a['cost_grid']) . "</span>
</td>
<td style='border:1px solid #ccc; padding:6px; text-align:right; vertical-align:top;'>
<span style='font-family:Courier, monospace; display:inline-block; min-width:90px;'>" . $fmtChf($a['rev_feedin']) . "</span>
</td>
<td style='border:1px solid #ccc; padding:6px; text-align:right; vertical-align:top;'>
<span style='font-family:Courier, monospace; display:inline-block; min-width:90px;'>" . $fmtChf($a['rev_zev']) . "</span>
</td>
<td style='border:1px solid #ccc; padding:6px; text-align:right; vertical-align:top;'>
<span style='font-family:Courier, monospace; display:inline-block; min-width:90px;'>" . $fmtChf($subtotal) . "</span>
</td>
</tr>"; </tr>";
// Leerzeile zwischen Zählern (leichter grauer Hintergrund) // Leerzeile
$html .= "<tr><td colspan='12' style='background-color:#e9e9e9; height:8px; padding:0; border:none;'></td></tr>"; $html .= "<tr class='row-empty'><td colspan='12'></td></tr>";
} }
// Subtotal - einzeilige obere Linie (in gleicher Spalte wie subtotal) // Gesamttotal
$html .= " $html .= "
<tr> <tr class='total-row'>
<td colspan='11' style='text-align:right; padding:6px; border-top:1px solid #000; font-weight:bold;'>Subtotal</td> <td colspan='11' align='right'><b>Total</b></td>
<td style='text-align:right; padding:6px; border-top:1px solid #000; font-weight:bold;'> <td align='right'></td>
<span style='font-family:Courier, monospace; display:inline-block; min-width:90px;'>" . number_format($sum, 2, '.', "'") . "</span> <td align='right'></td>
</td> <td align='right'></td>
</tr>"; <td align='right'></td>
<td align='right'></td>
// Doppel-Linie: wir fügen eine sehr dünne Linie und direkt darunter eine dickere Linie ein, <td align='right'></td>
// da 'double' nicht immer zuverlässig in TCPDF gerendert wird. <td align='right'></td>
$html .= " <td align='right'></td>
<tr> <td align='right'></td>
<td colspan='12' style='padding:0; border:none;'> <td class='num'><b>" . number_format($sum, 2) . "</b></td>
<div style='height:4px; border-top:1px solid #000;'></div> </tr>
<div style='height:4px; border-top:3px solid #000; margin-top:-3px;'></div> </table>";
</td>
</tr>";
// Gesamttotal-Zeile (gleich Spalte wie Subtotal)
$html .= "
<tr>
<td colspan='11' style='text-align:right; padding:6px; font-weight:bold;'>Gesamttotal</td>
<td style='text-align:right; padding:6px; font-weight:bold;'>
<span style='font-family:Courier, monospace; display:inline-block; min-width:90px;'>" . number_format($sum, 2, '.', "'") . "</span>
</td>
</tr>
</table>";
return ['html' => $html, 'sum' => $sum]; return ['html' => $html, 'sum' => $sum];
} }