no message

This commit is contained in:
2025-11-05 14:41:33 +01:00
parent 9cad56c283
commit 1cd8eb9f60

View File

@@ -139,8 +139,8 @@ class Abrechnung extends IPSModule
// ====================== Stromkosten ======================
private function CalculatePowerCosts($powerMeters, $tariffs, $userId, $from, $to)
{
private function CalculatePowerCosts($powerMeters, $tariffs, $userId, $from, $to)
{
$html = "<table border='1' cellspacing='0' cellpadding='3' width='100%' style='font-size:8px;'>
<tr style='background-color:#f0f0f0;'>
<th>Zähler</th><th>Typ</th><th>Start</th><th>Ende</th>
@@ -148,11 +148,14 @@ class Abrechnung extends IPSModule
</tr>";
$total = 0.0;
$usedTariffs = [];
foreach ($powerMeters as $m) {
if ($m['user_id'] != $userId) continue;
$cost = $this->AddMeterToPDFRow($m, $tariffs, $from, $to, 'Strombezug');
$html .= $cost['row'];
$total += $cost['value'];
$usedTariffs = array_merge($usedTariffs, $cost['tariffs']);
}
$html .= "<tr style='background-color:#f9f9f9; font-weight:bold;'>
@@ -160,13 +163,24 @@ class Abrechnung extends IPSModule
<td align='right'>" . number_format($total, 2) . "</td>
</tr></table><br>";
return ['html' => $html, 'sum' => $total];
// 👇 Tarifliste anhängen
if (!empty($usedTariffs)) {
$html .= "<p><strong>Angewendete Stromtarife:</strong></p><ul>";
foreach ($usedTariffs as $t) {
$html .= "<li>" . date('d.m.Y', $t['start']) . " " . date('d.m.Y', $t['end']) . ": " .
number_format($t['price'], 2) . " Rp/kWh</li>";
}
$html .= "</ul><br>";
}
return ['html' => $html, 'sum' => $total];
}
// ====================== Nebenkosten ======================
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:8px;'>
<tr style='background-color:#f0f0f0;'>
<th>Zähler</th><th>Typ</th><th>Start</th><th>Ende</th>
@@ -174,12 +188,15 @@ class Abrechnung extends IPSModule
</tr>";
$total = 0.0;
$usedTariffs = [];
foreach ($waterMeters as $m) {
if ($m['user_id'] != $userId) continue;
$type = $m['meter_type'] ?? 'Warmwasser';
$cost = $this->AddMeterToPDFRow($m, $tariffs, $from, $to, $type);
$html .= $cost['row'];
$total += $cost['value'];
$usedTariffs = array_merge($usedTariffs, $cost['tariffs']);
}
$html .= "<tr style='background-color:#f9f9f9; font-weight:bold;'>
@@ -187,18 +204,29 @@ class Abrechnung extends IPSModule
<td align='right'>" . number_format($total, 2) . "</td>
</tr></table><br>";
return ['html' => $html, 'sum' => $total];
// 👇 Tarifliste anhängen
if (!empty($usedTariffs)) {
$html .= "<p><strong>Angewendete Nebenkostentarife:</strong></p><ul>";
foreach ($usedTariffs as $t) {
$html .= "<li>" . date('d.m.Y', $t['start']) . " " . date('d.m.Y', $t['end']) . ": " .
number_format($t['price'], 2) . " Rp</li>";
}
$html .= "</ul><br>";
}
return ['html' => $html, 'sum' => $total];
}
// ====================== Kernberechnung ======================
private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
{
private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
{
$rows = '';
$totalCost = 0.0;
$usedTariffs = []; // 👈 neu: Liste der verwendeten Tarife
$varId = $meter['var_consumption'];
if (!IPS_VariableExists($varId)) return ['row' => '', 'value' => 0];
if (!IPS_VariableExists($varId)) return ['row' => '', 'value' => 0, 'tariffs' => []];
$filteredTariffs = array_filter($tariffs, fn($t) =>
strtolower(trim($t['unit_type'] ?? '')) === strtolower(trim($type))
@@ -228,6 +256,16 @@ class Abrechnung extends IPSModule
$tariffEnd = intval($activeTariff['end_ts']);
$tariffPrice = floatval($activeTariff['price']);
// 👇 Tarif in Liste aufnehmen (nur wenn noch nicht drin)
$key = $activeTariff['start_ts'] . '-' . $activeTariff['end_ts'] . '-' . $tariffPrice;
if (!isset($usedTariffs[$key])) {
$usedTariffs[$key] = [
'start' => $activeTariff['start_ts'],
'end' => $activeTariff['end_ts'],
'price' => $tariffPrice
];
}
$startValue = $this->GetValueAt($varId, $currentStart, true);
$segmentEnd = ($tariffEnd < $to) ? $tariffEnd : $to;
$endValue = $this->GetValueAt($varId, $segmentEnd, true);
@@ -254,10 +292,10 @@ class Abrechnung extends IPSModule
else break;
}
if ($rows === '') return ['row' => '', 'value' => 0];
if ($rows === '') return ['row' => '', 'value' => 0, 'tariffs' => []];
return ['row' => $rows, 'value' => $totalCost];
}
return ['row' => $rows, 'value' => $totalCost, 'tariffs' => array_values($usedTariffs)];
}
// ====================== Hilfsfunktionen ======================