no message

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

View File

@@ -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,9 +163,20 @@ class Abrechnung extends IPSModule
<td align='right'>" . number_format($total, 2) . "</td>
</tr></table><br>";
// 👇 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)
@@ -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,6 +204,16 @@ class Abrechnung extends IPSModule
<td align='right'>" . number_format($total, 2) . "</td>
</tr></table><br>";
// 👇 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];
}
@@ -196,9 +223,10 @@ class Abrechnung extends IPSModule
{
$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,9 +292,9 @@ 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 ======================