no message
This commit is contained in:
+14
-33
@@ -254,14 +254,14 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
{
|
{
|
||||||
$rows = '';
|
$rows = '';
|
||||||
$totalCost = 0.0;
|
$totalCost = 0.0;
|
||||||
|
|
||||||
$varId = $meter['var_consumption'];
|
$varId = $meter['var_consumption'];
|
||||||
|
|
||||||
if (!IPS_VariableExists($varId)) {
|
if (!IPS_VariableExists($varId)) {
|
||||||
IPS_LogMessage('Abrechnung', "❌ Variable {$varId} für {$meter['name']} nicht gefunden");
|
IPS_LogMessage('Abrechnung', "❌ Variable {$varId} für {$meter['name']} nicht gefunden");
|
||||||
return ['row' => '', 'value' => 0];
|
return ['row' => '', 'value' => 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 🧩 Einheitstyp tolerant abgleichen
|
// --- Einheitstyp tolerant abgleichen ---
|
||||||
$filteredTariffs = [];
|
$filteredTariffs = [];
|
||||||
foreach ($tariffs as $t) {
|
foreach ($tariffs as $t) {
|
||||||
$tariffType = strtolower(trim($t['unit_type'] ?? ''));
|
$tariffType = strtolower(trim($t['unit_type'] ?? ''));
|
||||||
@@ -280,16 +280,8 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
|
||||||
IPS_LogMessage('Abrechnung', " Tarif '{$t['unit_type']}' von " . json_encode($t['start']) . " bis " . json_encode($t['end']) . " | {$t['price']} Rp");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($filteredTariffs)) {
|
// --- Datumsfelder aus Symcon-Formular umwandeln ---
|
||||||
IPS_LogMessage('Abrechnung', "⚠ Keine passenden Tarife für $type gefunden");
|
|
||||||
return ['row' => '', 'value' => 0];
|
|
||||||
}
|
|
||||||
|
|
||||||
// 🔹 Datumsfelder sicher umwandeln
|
|
||||||
foreach ($filteredTariffs as &$t) {
|
foreach ($filteredTariffs as &$t) {
|
||||||
if (is_array($t['start'])) {
|
if (is_array($t['start'])) {
|
||||||
$t['start_ts'] = mktime(0, 0, 0, $t['start']['month'], $t['start']['day'], $t['start']['year']);
|
$t['start_ts'] = mktime(0, 0, 0, $t['start']['month'], $t['start']['day'], $t['start']['year']);
|
||||||
@@ -298,46 +290,36 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($t['end'])) {
|
if (is_array($t['end'])) {
|
||||||
|
// Ende immer auf 23:59:59 setzen, sonst endet der Tarif zu früh
|
||||||
$t['end_ts'] = mktime(23, 59, 59, $t['end']['month'], $t['end']['day'], $t['end']['year']);
|
$t['end_ts'] = mktime(23, 59, 59, $t['end']['month'], $t['end']['day'], $t['end']['year']);
|
||||||
} else {
|
} else {
|
||||||
$t['end_ts'] = strtotime($t['end'] . ' 23:59:59');
|
$t['end_ts'] = strtotime($t['end'] . ' 23:59:59');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($t['start_ts'] === false || $t['end_ts'] === false) {
|
IPS_LogMessage('Abrechnung', "✅ Tarif '{$t['unit_type']}' von " . date('d.m.Y H:i', $t['start_ts']) . " bis " . date('d.m.Y H:i', $t['end_ts']) . " | {$t['price']} Rp");
|
||||||
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);
|
unset($t);
|
||||||
|
|
||||||
// Nach Startzeit sortieren
|
// Sortieren
|
||||||
usort($filteredTariffs, fn($a, $b) => $a['start_ts'] <=> $b['start_ts']);
|
usort($filteredTariffs, fn($a, $b) => $a['start_ts'] <=> $b['start_ts']);
|
||||||
|
|
||||||
$current = $from;
|
$current = $from;
|
||||||
|
|
||||||
while ($current < $to) {
|
while ($current < $to) {
|
||||||
$activeTariff = null;
|
$activeTariff = null;
|
||||||
$segmentStart = $current;
|
$segmentStart = $current;
|
||||||
$segmentEnd = $to;
|
$segmentEnd = $to;
|
||||||
|
|
||||||
// passenden Tarif finden
|
// Tarif finden, der diesen Zeitpunkt abdeckt
|
||||||
foreach ($filteredTariffs as $t) {
|
foreach ($filteredTariffs as $t) {
|
||||||
if ($t['end_ts'] > $segmentStart && $t['start_ts'] < $to) {
|
if ($t['end_ts'] > $segmentStart && $t['start_ts'] <= $segmentStart) {
|
||||||
if ($t['start_ts'] > $segmentStart) {
|
|
||||||
$segmentEnd = min($t['start_ts'], $to);
|
|
||||||
$activeTariff = null;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$segmentEnd = min($t['end_ts'], $to);
|
|
||||||
$activeTariff = $t;
|
$activeTariff = $t;
|
||||||
|
$segmentEnd = min($t['end_ts'], $to);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kein aktiver Tarif gefunden
|
|
||||||
if ($activeTariff === null) {
|
if ($activeTariff === null) {
|
||||||
|
// kein Tarif aktiv – nutze Nulltarif bis zum nächsten Start
|
||||||
$nextStart = $to;
|
$nextStart = $to;
|
||||||
foreach ($filteredTariffs as $t) {
|
foreach ($filteredTariffs as $t) {
|
||||||
if ($t['start_ts'] > $segmentStart && $t['start_ts'] < $nextStart) {
|
if ($t['start_ts'] > $segmentStart && $t['start_ts'] < $nextStart) {
|
||||||
@@ -346,13 +328,11 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
}
|
}
|
||||||
$segmentEnd = min($nextStart, $to);
|
$segmentEnd = min($nextStart, $to);
|
||||||
$tariffPrice = 0.0;
|
$tariffPrice = 0.0;
|
||||||
$tariffLabel = 'kein Tarif';
|
|
||||||
} else {
|
} else {
|
||||||
$tariffPrice = floatval($activeTariff['price']);
|
$tariffPrice = floatval($activeTariff['price']);
|
||||||
$tariffLabel = number_format($tariffPrice, 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Archivwerte lesen
|
// --- Archivdaten auslesen ---
|
||||||
$startVal = $this->GetValueAt($varId, $segmentStart, false);
|
$startVal = $this->GetValueAt($varId, $segmentStart, false);
|
||||||
$endVal = $this->GetValueAt($varId, $segmentEnd, true);
|
$endVal = $this->GetValueAt($varId, $segmentEnd, true);
|
||||||
|
|
||||||
@@ -365,8 +345,9 @@ 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;
|
||||||
|
|
||||||
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 {$tariffPrice} Rp | Verbrauch {$diff}");
|
||||||
|
|
||||||
|
// --- Tabellenzeile hinzufügen ---
|
||||||
$rows .= "
|
$rows .= "
|
||||||
<tr>
|
<tr>
|
||||||
<td>{$meter['name']}</td>
|
<td>{$meter['name']}</td>
|
||||||
@@ -384,7 +365,6 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
$current = $segmentEnd + 1;
|
$current = $segmentEnd + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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);
|
||||||
@@ -410,4 +390,5 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user