no message
This commit is contained in:
+37
-31
@@ -267,7 +267,6 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
$tariffType = strtolower(trim($t['unit_type'] ?? ''));
|
$tariffType = strtolower(trim($t['unit_type'] ?? ''));
|
||||||
$typeNorm = strtolower(trim($type));
|
$typeNorm = strtolower(trim($type));
|
||||||
|
|
||||||
// Mapping-Tabelle für Synonyme
|
|
||||||
$map = [
|
$map = [
|
||||||
'strombezug' => ['strom', 'strombezug', 'stromzähler', 'stromverbrauch'],
|
'strombezug' => ['strom', 'strombezug', 'stromzähler', 'stromverbrauch'],
|
||||||
'warmwasser' => ['warmwasser', 'wasser', 'hww'],
|
'warmwasser' => ['warmwasser', 'wasser', 'hww'],
|
||||||
@@ -280,10 +279,9 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 🪵 Logging zur Kontrolle
|
|
||||||
IPS_LogMessage('Abrechnung', "🔍 Suche Tarife für Typ '$type': gefunden " . count($filteredTariffs) . " Treffer");
|
IPS_LogMessage('Abrechnung', "🔍 Suche Tarife für Typ '$type': gefunden " . count($filteredTariffs) . " Treffer");
|
||||||
foreach ($filteredTariffs as $t) {
|
foreach ($filteredTariffs as $t) {
|
||||||
IPS_LogMessage('Abrechnung', " Tarif '{$t['unit_type']}' von {$t['start']} bis {$t['end']} | {$t['price']} Rp");
|
IPS_LogMessage('Abrechnung', " Tarif '{$t['unit_type']}' von " . json_encode($t['start']) . " bis " . json_encode($t['end']) . " | {$t['price']} Rp");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($filteredTariffs)) {
|
if (empty($filteredTariffs)) {
|
||||||
@@ -291,10 +289,30 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
return ['row' => '', 'value' => 0];
|
return ['row' => '', 'value' => 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nach Startdatum sortieren
|
// 🔹 Datumsfelder sicher umwandeln
|
||||||
usort($filteredTariffs, function ($a, $b) {
|
foreach ($filteredTariffs as &$t) {
|
||||||
return strtotime($a['start']) <=> strtotime($b['start']);
|
if (is_array($t['start'])) {
|
||||||
});
|
$t['start_ts'] = mktime(0, 0, 0, $t['start']['month'], $t['start']['day'], $t['start']['year']);
|
||||||
|
} else {
|
||||||
|
$t['start_ts'] = strtotime($t['start'] . ' 00:00:00');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($t['end'])) {
|
||||||
|
$t['end_ts'] = mktime(23, 59, 59, $t['end']['month'], $t['end']['day'], $t['end']['year']);
|
||||||
|
} else {
|
||||||
|
$t['end_ts'] = strtotime($t['end'] . ' 23:59:59');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($t['start_ts'] === false || $t['end_ts'] === false) {
|
||||||
|
IPS_LogMessage('Abrechnung', "❌ Ungültiges Tarifdatum nach Umwandlung: " . json_encode($t));
|
||||||
|
} else {
|
||||||
|
IPS_LogMessage('Abrechnung', "✅ Tarifzeitraum erkannt: " . date('d.m.Y', $t['start_ts']) . " - " . date('d.m.Y', $t['end_ts']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset($t);
|
||||||
|
|
||||||
|
// Nach Startzeit sortieren
|
||||||
|
usort($filteredTariffs, fn($a, $b) => $a['start_ts'] <=> $b['start_ts']);
|
||||||
|
|
||||||
$current = $from;
|
$current = $from;
|
||||||
|
|
||||||
@@ -303,38 +321,27 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
$segmentStart = $current;
|
$segmentStart = $current;
|
||||||
$segmentEnd = $to;
|
$segmentEnd = $to;
|
||||||
|
|
||||||
// Passenden Tarif für aktuellen Zeitpunkt finden
|
// passenden Tarif finden
|
||||||
foreach ($filteredTariffs as $t) {
|
foreach ($filteredTariffs as $t) {
|
||||||
$tariffStart = is_array($t['start']) ? IPS_MakeTimeStamp($t['start']) : strtotime($t['start'] . ' 00:00:00');
|
if ($t['end_ts'] > $segmentStart && $t['start_ts'] < $to) {
|
||||||
$tariffEnd = is_array($t['end']) ? IPS_MakeTimeStamp($t['end']) + 86399 : strtotime($t['end'] . ' 23:59:59');
|
if ($t['start_ts'] > $segmentStart) {
|
||||||
|
$segmentEnd = min($t['start_ts'], $to);
|
||||||
|
|
||||||
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 ($tariffStart > $segmentStart) {
|
|
||||||
$segmentEnd = min($tariffStart, $to);
|
|
||||||
$activeTariff = null;
|
$activeTariff = null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$segmentEnd = min($tariffEnd, $to);
|
$segmentEnd = min($t['end_ts'], $to);
|
||||||
$activeTariff = $t;
|
$activeTariff = $t;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kein aktiver Tarif -> Nulltarif bis zum nächsten Start
|
// Kein aktiver Tarif gefunden
|
||||||
if ($activeTariff === null) {
|
if ($activeTariff === null) {
|
||||||
$nextStart = $to;
|
$nextStart = $to;
|
||||||
foreach ($filteredTariffs as $t) {
|
foreach ($filteredTariffs as $t) {
|
||||||
$ts = strtotime($t['start'] . ' 00:00:00');
|
if ($t['start_ts'] > $segmentStart && $t['start_ts'] < $nextStart) {
|
||||||
if ($ts > $segmentStart && $ts < $nextStart) {
|
$nextStart = $t['start_ts'];
|
||||||
$nextStart = $ts;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$segmentEnd = min($nextStart, $to);
|
$segmentEnd = min($nextStart, $to);
|
||||||
@@ -345,12 +352,12 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
$tariffLabel = number_format($tariffPrice, 2);
|
$tariffLabel = number_format($tariffPrice, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 🔹 Archivwerte lesen
|
// 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) von " . date('d.m.Y H:i', $segmentStart) . " bis " . date('d.m.Y H:i', $segmentEnd));
|
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));
|
||||||
$current = $segmentEnd + 1;
|
$current = $segmentEnd + 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -358,10 +365,8 @@ 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;
|
||||||
|
|
||||||
// 🪵 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>
|
||||||
@@ -379,7 +384,7 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
$current = $segmentEnd + 1;
|
$current = $segmentEnd + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Falls keine Zeile zustande kam
|
// Fallback, falls keine Zeile entstand
|
||||||
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);
|
||||||
@@ -404,4 +409,5 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user