no message
This commit is contained in:
@@ -144,8 +144,11 @@ private function CalculatePowerCosts($powerMeters, $tariffs, $userId, $from, $to
|
||||
$acc = [];
|
||||
$meters = [];
|
||||
|
||||
// Alle Stromzähler des Users vorbereiten
|
||||
foreach ($powerMeters as $m) {
|
||||
if ($m['user_id'] != $userId) continue;
|
||||
if ($m['user_id'] != $userId) {
|
||||
continue;
|
||||
}
|
||||
$name = $m['name'];
|
||||
$meters[$name] = [
|
||||
'name' => $name,
|
||||
@@ -153,33 +156,40 @@ private function CalculatePowerCosts($powerMeters, $tariffs, $userId, $from, $to
|
||||
'exp' => $m['var_export'] ?? null
|
||||
];
|
||||
$acc[$name] = [
|
||||
'imp'=>0.0,'exp'=>0.0,
|
||||
'solar_bezug'=>0.0,'netz_bezug'=>0.0,
|
||||
'solareinspeisung'=>0.0,'solarverkauf'=>0.0,
|
||||
'cost_solar'=>0.0,'cost_grid'=>0.0,
|
||||
'rev_feedin'=>0.0
|
||||
'imp' => 0.0,
|
||||
'exp' => 0.0,
|
||||
'solar_bezug' => 0.0,
|
||||
'netz_bezug' => 0.0,
|
||||
'solareinspeisung' => 0.0,
|
||||
'solarverkauf' => 0.0,
|
||||
'cost_solar' => 0.0,
|
||||
'cost_grid' => 0.0,
|
||||
'rev_feedin' => 0.0
|
||||
];
|
||||
}
|
||||
|
||||
if (empty($meters)) {
|
||||
$html .= "<tr><td colspan='11' align='center'>Keine Stromzähler für diesen Benutzer</td></tr></table><br>";
|
||||
return ['html'=>$html, 'sum'=>0.0];
|
||||
return ['html' => $html, 'sum' => 0.0];
|
||||
}
|
||||
|
||||
// 15-Minuten-Schritte
|
||||
for ($ts = $from; $ts < $to; $ts += 900) {
|
||||
$slotEnd = min($to, $ts + 900);
|
||||
|
||||
$pGrid = $this->getTariffPriceAt($tariffs, ['Netztarif'], $ts);
|
||||
$pSolar = $this->getTariffPriceAt($tariffs, ['Solartarif'], $ts);
|
||||
// Tarife je Intervall (Rp/kWh)
|
||||
$pGrid = $this->getTariffPriceAt($tariffs, ['Netztarif'], $ts);
|
||||
$pSolar = $this->getTariffPriceAt($tariffs, ['Solartarif'], $ts);
|
||||
$pFeed = $this->getTariffPriceAt($tariffs, ['Einspeisetarif'], $ts);
|
||||
|
||||
$impTotal = 0.0;
|
||||
$expTotal = 0.0;
|
||||
$slot = [];
|
||||
$slot = [];
|
||||
|
||||
// Deltas pro Zähler für dieses Intervall holen
|
||||
foreach ($meters as $name => $mm) {
|
||||
$impDelta = $expDelta = 0.0;
|
||||
$impDelta = 0.0;
|
||||
$expDelta = 0.0;
|
||||
|
||||
if (!empty($mm['imp']) && IPS_VariableExists((int)$mm['imp'])) {
|
||||
$impDelta = $this->readDelta((int)$mm['imp'], $ts, $slotEnd);
|
||||
@@ -195,7 +205,7 @@ private function CalculatePowerCosts($powerMeters, $tariffs, $userId, $from, $to
|
||||
}
|
||||
}
|
||||
|
||||
// 🧠 --- AB HIER gezieltes Debug-Logging ---
|
||||
// Debug-Logging (bei Bedarf auskommentieren)
|
||||
IPS_LogMessage('Abrechnung', sprintf(
|
||||
"INTERVALL %s – %s | impTotal=%.5f expTotal=%.5f grid=%.3f solar=%.3f feed=%.3f",
|
||||
date('H:i', $ts), date('H:i', $slotEnd),
|
||||
@@ -203,7 +213,9 @@ private function CalculatePowerCosts($powerMeters, $tariffs, $userId, $from, $to
|
||||
$pGrid ?? 0, $pSolar ?? 0, $pFeed ?? 0
|
||||
));
|
||||
|
||||
if ($impTotal == 0 && $expTotal == 0) continue;
|
||||
if ($impTotal == 0 && $expTotal == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($impTotal <= $expTotal && $expTotal > 0) {
|
||||
$ratio = $impTotal / $expTotal;
|
||||
@@ -212,26 +224,45 @@ private function CalculatePowerCosts($powerMeters, $tariffs, $userId, $from, $to
|
||||
$ratio = $expTotal / $impTotal;
|
||||
IPS_LogMessage('Abrechnung', sprintf("→ Fall 2 (imp>exp) ratio=%.4f", $ratio));
|
||||
} else {
|
||||
$ratio = 0;
|
||||
$ratio = 0.0;
|
||||
}
|
||||
|
||||
// Zuweisung auf die einzelnen Zähler
|
||||
foreach ($slot as $name => $v) {
|
||||
$imp = $v['imp'];
|
||||
$exp = $v['exp'];
|
||||
|
||||
// ❗ NEU: Import/Export aufsummieren (bisher wurden sie nie erhöht!)
|
||||
$acc[$name]['imp'] += $imp;
|
||||
$acc[$name]['exp'] += $exp;
|
||||
|
||||
if ($impTotal <= $expTotal) {
|
||||
$acc[$name]['solar_bezug'] += $imp;
|
||||
$acc[$name]['solareinspeisung']+= (1 - $ratio) * $exp;
|
||||
$acc[$name]['solarverkauf'] += $ratio * $exp;
|
||||
if ($pSolar !== null) $acc[$name]['cost_solar'] += ($imp * $pSolar) / 100;
|
||||
if ($pFeed !== null) $acc[$name]['rev_feedin'] += ((1 - $ratio) * $exp * $pFeed) / 100;
|
||||
// PV deckt alles (oder mehr als Verbrauch)
|
||||
$acc[$name]['solar_bezug'] += $imp;
|
||||
$acc[$name]['solareinspeisung'] += (1 - $ratio) * $exp;
|
||||
$acc[$name]['solarverkauf'] += $ratio * $exp;
|
||||
|
||||
if ($pSolar !== null) {
|
||||
$acc[$name]['cost_solar'] += ($imp * $pSolar) / 100.0;
|
||||
}
|
||||
if ($pFeed !== null) {
|
||||
$acc[$name]['rev_feedin'] += ((1 - $ratio) * $exp * $pFeed) / 100.0;
|
||||
}
|
||||
} else {
|
||||
$acc[$name]['solar_bezug'] += $ratio * $imp;
|
||||
$acc[$name]['netz_bezug'] += (1 - $ratio) * $imp;
|
||||
$acc[$name]['solarverkauf'] += $exp;
|
||||
if ($pGrid !== null) $acc[$name]['cost_grid'] += ((1 - $ratio) * $imp * $pGrid) / 100;
|
||||
if ($pSolar !== null) $acc[$name]['cost_solar'] += ($ratio * $imp * $pSolar) / 100;
|
||||
if ($pFeed !== null) $acc[$name]['rev_feedin'] += ($exp * $pFeed) / 100;
|
||||
// Teilweise Netzbezug nötig
|
||||
$acc[$name]['solar_bezug'] += $ratio * $imp;
|
||||
$acc[$name]['netz_bezug'] += (1 - $ratio) * $imp;
|
||||
$acc[$name]['solarverkauf'] += $exp;
|
||||
|
||||
if ($pGrid !== null) {
|
||||
$acc[$name]['cost_grid'] += ((1 - $ratio) * $imp * $pGrid) / 100.0;
|
||||
}
|
||||
if ($pSolar !== null) {
|
||||
$acc[$name]['cost_solar'] += ($ratio * $imp * $pSolar) / 100.0;
|
||||
}
|
||||
if ($pFeed !== null) {
|
||||
$acc[$name]['rev_feedin'] += ($exp * $pFeed) / 100.0;
|
||||
}
|
||||
}
|
||||
|
||||
IPS_LogMessage('Abrechnung', sprintf(
|
||||
@@ -273,6 +304,7 @@ private function CalculatePowerCosts($powerMeters, $tariffs, $userId, $from, $to
|
||||
return ['html' => $html, 'sum' => $sum];
|
||||
}
|
||||
|
||||
|
||||
private function CalculateAdditionalCosts($waterMeters, $tariffs, $userId, $from, $to)
|
||||
{
|
||||
$html = "<table border='1' cellspacing='0' cellpadding='3' width='100%' style='font-size:8px;'>
|
||||
|
||||
Reference in New Issue
Block a user