no message
This commit is contained in:
@@ -217,7 +217,7 @@ public function GenerateInvoices()
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
private function GetValueAt(int $varId, int $timestamp, bool $nearestAfter = false)
|
||||
private function GetValueAt(int $varId, int $timestamp, bool $nearestAfter = true)
|
||||
{
|
||||
$archiveID = @IPS_GetInstanceListByModuleID('{43192F0B-135B-4CE7-A0A7-1475603F3060}')[0];
|
||||
if (!$archiveID || !IPS_VariableExists($varId)) {
|
||||
@@ -226,21 +226,30 @@ private function GetValueAt(int $varId, int $timestamp, bool $nearestAfter = fal
|
||||
}
|
||||
|
||||
if ($nearestAfter) {
|
||||
// Endwert: erster Wert >= Timestamp
|
||||
$values = @AC_GetLoggedValues($archiveID, $varId, $timestamp, $timestamp + 864000, 1);
|
||||
if ($values && count($values) > 0) return floatval($values[0]['Value']);
|
||||
// 🔹 Suche den ersten Wert nach dem gegebenen Zeitpunkt
|
||||
$values = @AC_GetLoggedValues($archiveID, $varId, $timestamp, $timestamp + 7 * 86400, 1000);
|
||||
if (!empty($values)) {
|
||||
foreach ($values as $v) {
|
||||
if ($v['TimeStamp'] >= $timestamp) {
|
||||
return floatval($v['Value']);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Startwert: letzter Wert <= Timestamp
|
||||
$values = @AC_GetLoggedValues($archiveID, $varId, 0, $timestamp, 1);
|
||||
if ($values && count($values) > 0) return floatval($values[count($values)-1]['Value']);
|
||||
// 🔹 Suche den letzten Wert vor dem gegebenen Zeitpunkt
|
||||
$values = @AC_GetLoggedValues($archiveID, $varId, $timestamp - 7 * 86400, $timestamp, 1000);
|
||||
if (!empty($values)) {
|
||||
return floatval($values[count($values) - 1]['Value']);
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback auf aktuellen Wert
|
||||
$current = floatval(GetValue($varId));
|
||||
IPS_LogMessage('Abrechnung', "⚠ Kein Archivwert für $varId gefunden, nehme aktuellen Wert: $current");
|
||||
return $current;
|
||||
// Fallback – aktuellen Variablenwert nehmen
|
||||
$fallback = floatval(GetValue($varId));
|
||||
IPS_LogMessage('Abrechnung', "⚠ Kein Archivwert für $varId gefunden, nutze aktuellen Wert ($fallback)");
|
||||
return $fallback;
|
||||
}
|
||||
|
||||
|
||||
private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
||||
{
|
||||
$rows = '';
|
||||
|
||||
Reference in New Issue
Block a user