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