no message
This commit is contained in:
@@ -252,64 +252,81 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
return ['row' => '', 'value' => 0];
|
return ['row' => '', 'value' => 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filtere Tarife für diesen Typ (z. B. "Strombezug" oder "Warmwasser")
|
// Tarife für den passenden Typ herausfiltern
|
||||||
$tariffs = array_filter($tariffs, function ($t) use ($type) {
|
$filteredTariffs = array_filter($tariffs, function ($t) use ($type) {
|
||||||
return strtolower($t['unit_type']) == strtolower($type);
|
return strtolower($t['unit_type']) == strtolower($type);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (empty($tariffs)) {
|
if (empty($filteredTariffs)) {
|
||||||
IPS_LogMessage('Abrechnung', "⚠ Keine passenden Tarife für $type gefunden");
|
IPS_LogMessage('Abrechnung', "⚠ Keine passenden Tarife für $type gefunden");
|
||||||
return ['row' => '', 'value' => 0];
|
return ['row' => '', 'value' => 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sortiere Tarife chronologisch
|
// Nach Startdatum sortieren
|
||||||
usort($tariffs, function ($a, $b) {
|
usort($filteredTariffs, function ($a, $b) {
|
||||||
return strtotime($a['start']) <=> strtotime($b['start']);
|
return strtotime($a['start']) <=> strtotime($b['start']);
|
||||||
});
|
});
|
||||||
|
|
||||||
$current = $from;
|
$current = $from;
|
||||||
|
|
||||||
while ($current < $to) {
|
while ($current < $to) {
|
||||||
// passenden Tarif für aktuellen Zeitpunkt finden
|
|
||||||
$activeTariff = null;
|
$activeTariff = null;
|
||||||
foreach ($tariffs as $t) {
|
$segmentStart = $current;
|
||||||
|
$segmentEnd = $to;
|
||||||
|
|
||||||
|
// Passenden Tarif finden, der den aktuellen Zeitpunkt abdeckt
|
||||||
|
foreach ($filteredTariffs as $t) {
|
||||||
$tariffStart = strtotime($t['start']);
|
$tariffStart = strtotime($t['start']);
|
||||||
$tariffEnd = strtotime($t['end']);
|
$tariffEnd = strtotime($t['end']);
|
||||||
if ($current >= $tariffStart && $current < $tariffEnd) {
|
|
||||||
|
// Tarif ist aktiv, wenn er sich mit dem Abrechnungszeitraum überschneidet
|
||||||
|
if ($tariffEnd > $segmentStart && $tariffStart < $to) {
|
||||||
|
if ($tariffStart > $segmentStart) {
|
||||||
|
// Tarif beginnt später – setze Ende bis Tarifbeginn
|
||||||
|
$segmentEnd = min($tariffStart, $to);
|
||||||
|
$activeTariff = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tarif deckt diesen Bereich ab
|
||||||
|
$segmentEnd = min($tariffEnd, $to);
|
||||||
$activeTariff = $t;
|
$activeTariff = $t;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// wenn kein aktiver Tarif gefunden → Nulltarif bis nächster Start oder Rechnungsende
|
// Wenn kein Tarif aktiv ist, dann Nulltarif bis zum nächsten bekannten Start
|
||||||
if ($activeTariff === null) {
|
if ($activeTariff === null) {
|
||||||
$nextTariffStart = $to;
|
$nextStart = $to;
|
||||||
foreach ($tariffs as $t) {
|
foreach ($filteredTariffs as $t) {
|
||||||
$ts = strtotime($t['start']);
|
$ts = strtotime($t['start']);
|
||||||
if ($ts > $current && $ts < $nextTariffStart) {
|
if ($ts > $segmentStart && $ts < $nextStart) {
|
||||||
$nextTariffStart = $ts;
|
$nextStart = $ts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$segmentStart = $current;
|
$segmentEnd = min($nextStart, $to);
|
||||||
$segmentEnd = min($nextTariffStart, $to);
|
$tariffPrice = 0.0;
|
||||||
$segmentTariff = 0.0;
|
$tariffLabel = 'kein Tarif';
|
||||||
} else {
|
} else {
|
||||||
$segmentStart = $current;
|
$tariffPrice = floatval($activeTariff['price']);
|
||||||
$segmentEnd = min(strtotime($activeTariff['end']), $to);
|
$tariffLabel = number_format($tariffPrice, 2);
|
||||||
$segmentTariff = floatval($activeTariff['price']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Zählerstände direkt aus Archiv
|
// Archivwerte holen
|
||||||
$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 Werte im Archiv gefunden für {$meter['name']} ($type)");
|
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;
|
$current = $segmentEnd + 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$diff = max(0, $endVal - $startVal);
|
$diff = max(0, $endVal - $startVal);
|
||||||
$costCHF = ($segmentTariff / 100) * $diff;
|
$costCHF = ($tariffPrice / 100) * $diff;
|
||||||
|
|
||||||
|
// Log und Zeile schreiben
|
||||||
|
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}");
|
||||||
|
|
||||||
$rows .= "
|
$rows .= "
|
||||||
<tr>
|
<tr>
|
||||||
@@ -320,19 +337,20 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
<td>" . number_format($startVal, 2) . "</td>
|
<td>" . number_format($startVal, 2) . "</td>
|
||||||
<td>" . number_format($endVal, 2) . "</td>
|
<td>" . number_format($endVal, 2) . "</td>
|
||||||
<td>" . number_format($diff, 2) . "</td>
|
<td>" . number_format($diff, 2) . "</td>
|
||||||
<td>" . number_format($segmentTariff, 2) . "</td>
|
<td>" . number_format($tariffPrice, 2) . "</td>
|
||||||
<td>" . number_format($costCHF, 2) . "</td>
|
<td>" . number_format($costCHF, 2) . "</td>
|
||||||
</tr>";
|
</tr>";
|
||||||
|
|
||||||
$totalCost += $costCHF;
|
$totalCost += $costCHF;
|
||||||
$current = $segmentEnd;
|
$current = $segmentEnd + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Falls gar keine Zeilen zustande kommen
|
||||||
if ($rows == '') {
|
if ($rows == '') {
|
||||||
// Falls keine Tarifzeile ermittelt wurde
|
|
||||||
$startVal = $this->GetValueAt($varId, $from, false);
|
$startVal = $this->GetValueAt($varId, $from, false);
|
||||||
$endVal = $this->GetValueAt($varId, $to, true);
|
$endVal = $this->GetValueAt($varId, $to, true);
|
||||||
$diff = max(0, $endVal - $startVal);
|
$diff = max(0, $endVal - $startVal);
|
||||||
|
|
||||||
$rows .= "
|
$rows .= "
|
||||||
<tr>
|
<tr>
|
||||||
<td>{$meter['name']}</td>
|
<td>{$meter['name']}</td>
|
||||||
|
|||||||
Reference in New Issue
Block a user