no message
This commit is contained in:
@@ -261,10 +261,30 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
return ['row' => '', 'value' => 0];
|
return ['row' => '', 'value' => 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tarife für den passenden Typ herausfiltern
|
// 🧩 Einheitstyp tolerant abgleichen
|
||||||
$filteredTariffs = array_filter($tariffs, function ($t) use ($type) {
|
$filteredTariffs = [];
|
||||||
return strtolower($t['unit_type']) == strtolower($type);
|
foreach ($tariffs as $t) {
|
||||||
});
|
$tariffType = strtolower(trim($t['unit_type'] ?? ''));
|
||||||
|
$typeNorm = strtolower(trim($type));
|
||||||
|
|
||||||
|
// Mapping-Tabelle für Synonyme
|
||||||
|
$map = [
|
||||||
|
'strombezug' => ['strom', 'strombezug', 'stromzähler', 'stromverbrauch'],
|
||||||
|
'warmwasser' => ['warmwasser', 'wasser', 'hww'],
|
||||||
|
'kaltwasser' => ['kaltwasser', 'wasser', 'kww'],
|
||||||
|
'wärme' => ['wärme', 'heizung', 'heat']
|
||||||
|
];
|
||||||
|
|
||||||
|
if (in_array($tariffType, $map[$typeNorm] ?? []) || $tariffType == $typeNorm) {
|
||||||
|
$filteredTariffs[] = $t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🪵 Logging zur Kontrolle
|
||||||
|
IPS_LogMessage('Abrechnung', "🔍 Suche Tarife für Typ '$type': gefunden " . count($filteredTariffs) . " Treffer");
|
||||||
|
foreach ($filteredTariffs as $t) {
|
||||||
|
IPS_LogMessage('Abrechnung', " Tarif '{$t['unit_type']}' von {$t['start']} bis {$t['end']} | {$t['price']} Rp");
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($filteredTariffs)) {
|
if (empty($filteredTariffs)) {
|
||||||
IPS_LogMessage('Abrechnung', "⚠ Keine passenden Tarife für $type gefunden");
|
IPS_LogMessage('Abrechnung', "⚠ Keine passenden Tarife für $type gefunden");
|
||||||
@@ -283,32 +303,35 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
$segmentStart = $current;
|
$segmentStart = $current;
|
||||||
$segmentEnd = $to;
|
$segmentEnd = $to;
|
||||||
|
|
||||||
// Passenden Tarif finden, der den aktuellen Zeitpunkt abdeckt
|
// Passenden Tarif für aktuellen Zeitpunkt finden
|
||||||
foreach ($filteredTariffs as $t) {
|
foreach ($filteredTariffs as $t) {
|
||||||
$tariffStart = strtotime($t['start'] . ' 00:00:00');
|
$tariffStart = strtotime($t['start'] . ' 00:00:00');
|
||||||
$tariffEnd = strtotime($t['end'] . ' 23:59:59');
|
$tariffEnd = strtotime($t['end'] . ' 23:59:59');
|
||||||
|
|
||||||
// Tarif ist aktiv, wenn er sich mit dem Abrechnungszeitraum überschneidet
|
if ($tariffStart === false || $tariffEnd === false) {
|
||||||
|
IPS_LogMessage('Abrechnung', "❌ Ungültiges Tarifdatum: " . json_encode($t));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tarif gilt, wenn er sich mit dem Zeitraum überschneidet
|
||||||
if ($tariffEnd > $segmentStart && $tariffStart < $to) {
|
if ($tariffEnd > $segmentStart && $tariffStart < $to) {
|
||||||
if ($tariffStart > $segmentStart) {
|
if ($tariffStart > $segmentStart) {
|
||||||
// Tarif beginnt später – setze Ende bis Tarifbeginn
|
|
||||||
$segmentEnd = min($tariffStart, $to);
|
$segmentEnd = min($tariffStart, $to);
|
||||||
$activeTariff = null;
|
$activeTariff = null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tarif deckt diesen Bereich ab
|
|
||||||
$segmentEnd = min($tariffEnd, $to);
|
$segmentEnd = min($tariffEnd, $to);
|
||||||
$activeTariff = $t;
|
$activeTariff = $t;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wenn kein Tarif aktiv ist, dann Nulltarif bis zum nächsten bekannten Start
|
// Kein aktiver Tarif -> Nulltarif bis zum nächsten Start
|
||||||
if ($activeTariff === null) {
|
if ($activeTariff === null) {
|
||||||
$nextStart = $to;
|
$nextStart = $to;
|
||||||
foreach ($filteredTariffs as $t) {
|
foreach ($filteredTariffs as $t) {
|
||||||
$ts = strtotime($t['start']);
|
$ts = strtotime($t['start'] . ' 00:00:00');
|
||||||
if ($ts > $segmentStart && $ts < $nextStart) {
|
if ($ts > $segmentStart && $ts < $nextStart) {
|
||||||
$nextStart = $ts;
|
$nextStart = $ts;
|
||||||
}
|
}
|
||||||
@@ -321,12 +344,12 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
$tariffLabel = number_format($tariffPrice, 2);
|
$tariffLabel = number_format($tariffPrice, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Archivwerte holen
|
// 🔹 Archivwerte lesen
|
||||||
$startVal = $this->GetValueAt($varId, $segmentStart, false);
|
$startVal = $this->GetValueAt($varId, $segmentStart, false);
|
||||||
$endVal = $this->GetValueAt($varId, $segmentEnd, true);
|
$endVal = $this->GetValueAt($varId, $segmentEnd, true);
|
||||||
|
|
||||||
if ($startVal === null || $endVal === null) {
|
if ($startVal === null || $endVal === null) {
|
||||||
IPS_LogMessage('Abrechnung', "⚠ Keine Archivwerte für {$meter['name']} ($type) im Zeitraum " . date('d.m.Y H:i', $segmentStart) . " - " . date('d.m.Y H:i', $segmentEnd));
|
IPS_LogMessage('Abrechnung', "⚠ Keine Archivwerte für {$meter['name']} ($type) von " . date('d.m.Y H:i', $segmentStart) . " bis " . date('d.m.Y H:i', $segmentEnd));
|
||||||
$current = $segmentEnd + 1;
|
$current = $segmentEnd + 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -334,9 +357,10 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
$diff = max(0, $endVal - $startVal);
|
$diff = max(0, $endVal - $startVal);
|
||||||
$costCHF = ($tariffPrice / 100) * $diff;
|
$costCHF = ($tariffPrice / 100) * $diff;
|
||||||
|
|
||||||
// Log und Zeile schreiben
|
// 🪵 Logausgabe pro Abschnitt
|
||||||
IPS_LogMessage('Abrechnung', "→ {$meter['name']} ($type): " . date('d.m.Y H:i', $segmentStart) . " bis " . date('d.m.Y H:i', $segmentEnd) . " | Tarif {$tariffLabel} Rp | Verbrauch {$diff}");
|
IPS_LogMessage('Abrechnung', "→ {$meter['name']} ($type): " . date('d.m.Y H:i', $segmentStart) . " bis " . date('d.m.Y H:i', $segmentEnd) . " | Tarif {$tariffLabel} Rp | Verbrauch {$diff}");
|
||||||
|
|
||||||
|
// 🔸 Zeile fürs PDF
|
||||||
$rows .= "
|
$rows .= "
|
||||||
<tr>
|
<tr>
|
||||||
<td>{$meter['name']}</td>
|
<td>{$meter['name']}</td>
|
||||||
@@ -354,7 +378,7 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
$current = $segmentEnd + 1;
|
$current = $segmentEnd + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Falls gar keine Zeilen zustande kommen
|
// Falls keine Zeile zustande kam
|
||||||
if ($rows == '') {
|
if ($rows == '') {
|
||||||
$startVal = $this->GetValueAt($varId, $from, false);
|
$startVal = $this->GetValueAt($varId, $from, false);
|
||||||
$endVal = $this->GetValueAt($varId, $to, true);
|
$endVal = $this->GetValueAt($varId, $to, true);
|
||||||
@@ -378,4 +402,5 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user