diff --git a/Abrechnung/module.php b/Abrechnung/module.php index 9c88539..9b996cb 100644 --- a/Abrechnung/module.php +++ b/Abrechnung/module.php @@ -157,7 +157,7 @@ class Abrechnung extends IPSModule
|
- Zählpunkte: "; + Zählpunkte: "; // Alle Zählerpunkte des Users auflisten foreach ($power as $m) { @@ -219,7 +219,7 @@ class Abrechnung extends IPSModule $grandTotal = $totalPower + $totalAdditional; $html .= " - Gesamttotal: CHF " . number_format($grandTotal, 2) . ".- + Gesamttotal: CHF " . number_format($grandTotal, 2) . ".-"; @@ -305,32 +305,45 @@ class Abrechnung extends IPSModule $expTotal += $expDelta; } } - - // Überspringe Fälle, in denen kein Stromverbrauch und keine Einspeisung vorhanden ist + + // Logging der Eingangswerte + IPS_LogMessage("KostenModul", "impTotal: $impTotal | expTotal: $expTotal"); + + // Fall 1: Weder Import noch Export -> nichts zu berechnen if ($impTotal == 0.0 && $expTotal == 0.0) { - $ratio = 0.0; - $pvCoversAll = true; // Kein Verbrauch => PV deckt "alles" - } else { - // Verhältnis PV / Netz pro User - if ($impTotal == 0.0) { - // Kein Import, nur Export vorhanden - $ratio = 0.0; - $pvCoversAll = true; // PV deckt alles - } elseif ($expTotal == 0.0) { - // Kein Export, nur Import vorhanden - $ratio = 0.0; - $pvCoversAll = false; // PV deckt nichts - } elseif ($impTotal <= $expTotal) { - // PV deckt mehr als Import - $ratio = $impTotal / $expTotal; - $pvCoversAll = true; - } else { - // PV deckt weniger als Import - $ratio = $expTotal / $impTotal; - $pvCoversAll = false; - } + IPS_LogMessage("KostenModul", "Beide Werte sind 0 -> continue()"); + continue; } + // Verhältnis PV / Netz pro User + if ($impTotal == 0.0 && $expTotal > 0.0) { + // Kein Import, aber Export → PV deckt alles + $ratio = 0.0; + $pvCoversAll = true; + IPS_LogMessage("KostenModul", "Fall: impTotal=0, expTotal>0 -> PV deckt alles"); + + } elseif ($expTotal == 0.0 && $impTotal > 0.0) { + // Kein Export, aber Import → Netz deckt alles + $ratio = 0.0; + $pvCoversAll = false; + IPS_LogMessage("KostenModul", "Fall: expTotal=0, impTotal>0 -> Netz deckt alles"); + + } elseif ($impTotal <= $expTotal) { + // PV produziert genug oder mehr + $ratio = $expTotal > 0 ? ($impTotal / $expTotal) : 0.0; + $pvCoversAll = true; + IPS_LogMessage("KostenModul", "Fall: impTotal <= expTotal -> PV deckt genug"); + + } else { + // Import ist größer als Export → Netz deckt den Rest + $ratio = $impTotal > 0 ? ($expTotal / $impTotal) : 0.0; + $pvCoversAll = false; + IPS_LogMessage("KostenModul", "Fall: impTotal > expTotal -> Netz deckt den Rest"); + } + + IPS_LogMessage("KostenModul", "Ergebnis ratio=$ratio | pvCoversAll=" . ($pvCoversAll ? "true" : "false")); + + // Werte pro Zähler verteilen foreach ($slot as $name => $v) { $imp = $v['imp']; |