diff --git a/Abrechnung/form.json b/Abrechnung/form.json
index 97aa22f..d5fc2f5 100644
--- a/Abrechnung/form.json
+++ b/Abrechnung/form.json
@@ -104,7 +104,7 @@
"caption": "Einheit",
"name": "unit_type",
"width": "20%",
- "add": "Strombezug",
+ "add": "Netztarif",
"edit": {
"type": "Select",
"options": [
diff --git a/Abrechnung/module.php b/Abrechnung/module.php
index eb56e63..e7aa366 100644
--- a/Abrechnung/module.php
+++ b/Abrechnung/module.php
@@ -141,6 +141,8 @@ class Abrechnung extends IPSModule
private function CalculatePowerCosts($powerMeters, $tariffs, $userId, $from, $to)
{
+ IPS_LogMessage('Abrechnung', "⚡ Starte Stromkostenberechnung von " . date('d.m.Y H:i', $from) . " bis " . date('d.m.Y H:i', $to));
+
$html = "
| Zähler |
@@ -158,9 +160,8 @@ private function CalculatePowerCosts($powerMeters, $tariffs, $userId, $from, $to
// Initialisierung
$acc = [];
-
- // Benutzerzähler laden
$meters = [];
+
foreach ($powerMeters as $m) {
if ($m['user_id'] != $userId) continue;
$name = $m['name'];
@@ -179,6 +180,7 @@ private function CalculatePowerCosts($powerMeters, $tariffs, $userId, $from, $to
}
if (empty($meters)) {
+ IPS_LogMessage('Abrechnung', "⚠️ Keine Stromzähler für Benutzer $userId gefunden.");
$html .= "
| Keine Stromzähler für diesen Benutzer |
";
return ['html'=>$html, 'sum'=>0.0];
}
@@ -187,12 +189,16 @@ private function CalculatePowerCosts($powerMeters, $tariffs, $userId, $from, $to
for ($ts = $from; $ts < $to; $ts += 900) {
$slotEnd = min($to, $ts + 900);
- // Tarife für diesen Zeitraum holen
+ // Tarife abrufen
$pGrid = $this->getTariffPriceAt($tariffs, ['Netztarif'], $ts);
$pSolar = $this->getTariffPriceAt($tariffs, ['Solartarif'], $ts);
$pFeed = $this->getTariffPriceAt($tariffs, ['Einspeisetarif'], $ts);
- // Deltas
+ IPS_LogMessage('Abrechnung', sprintf("⏱ %s – %s | Tarife: Netz=%.3f Rp, Solar=%.3f Rp, Einspeise=%.3f Rp",
+ date('d.m.Y H:i', $ts), date('H:i', $slotEnd),
+ $pGrid ?? 0, $pSolar ?? 0, $pFeed ?? 0
+ ));
+
$impTotal = 0.0;
$expTotal = 0.0;
$slot = [];
@@ -211,6 +217,8 @@ private function CalculatePowerCosts($powerMeters, $tariffs, $userId, $from, $to
$slot[$name] = ['imp'=>$impDelta, 'exp'=>$expDelta];
$impTotal += $impDelta;
$expTotal += $expDelta;
+
+ IPS_LogMessage('Abrechnung', sprintf(" → %s: imp=%.4f, exp=%.4f", $name, $impDelta, $expDelta));
}
if ($impTotal <= 0 && $expTotal <= 0) continue;
@@ -223,7 +231,6 @@ private function CalculatePowerCosts($powerMeters, $tariffs, $userId, $from, $to
$imp = $slot[$name]['imp'];
$exp = $slot[$name]['exp'];
- // Mengen
$acc[$name]['imp'] += $imp;
$acc[$name]['exp'] += $exp;
@@ -232,10 +239,11 @@ private function CalculatePowerCosts($powerMeters, $tariffs, $userId, $from, $to
$acc[$name]['solareinspeisung']+= (1 - $ratio) * $exp;
$acc[$name]['solarverkauf'] += $ratio * $exp;
- // Kosten / Erträge
if ($pSolar !== null) $acc[$name]['cost_solar'] += ($imp * $pSolar) / 100;
if ($pFeed !== null) $acc[$name]['rev_feedin'] += ((1 - $ratio) * $exp * $pFeed) / 100;
}
+
+ IPS_LogMessage('Abrechnung', sprintf(" ⚙️ Fall 1 (imp<=exp): ratio=%.3f", $ratio));
}
// ===== Fall 2: import > export =====
@@ -257,10 +265,12 @@ private function CalculatePowerCosts($powerMeters, $tariffs, $userId, $from, $to
if ($pSolar !== null) $acc[$name]['cost_solar'] += ($ratio * $imp * $pSolar) / 100;
if ($pFeed !== null) $acc[$name]['rev_feedin'] += ($exp * $pFeed) / 100;
}
+
+ IPS_LogMessage('Abrechnung', sprintf(" ⚙️ Fall 2 (imp>exp): ratio=%.3f", $ratio));
}
}
- // Ausgabe
+ // Ausgabe erzeugen
$grand = 0.0;
foreach ($acc as $name => $v) {
$sum = $v['cost_solar'] + $v['cost_grid'] - $v['rev_feedin'];
@@ -286,52 +296,11 @@ private function CalculatePowerCosts($powerMeters, $tariffs, $userId, $from, $to
" . number_format($grand, 2) . " |
";
+ IPS_LogMessage('Abrechnung', sprintf("✅ Stromkosten fertig: %.2f CHF total", $grand));
+
return ['html'=>$html, 'sum'=>$grand];
}
-
-
-
- // ====================== Nebenkosten ======================
-
-private function CalculateAdditionalCosts($waterMeters, $tariffs, $userId, $from, $to)
-{
- $html = "
-
- | Zähler | Typ | Start | Ende |
- Zähler Start | Zähler Ende | Verbrauch | Tarif (Rp) | Kosten (CHF) |
-
";
-
- $total = 0.0;
- $usedTariffs = [];
-
- foreach ($waterMeters as $m) {
- if ($m['user_id'] != $userId) continue;
- $type = $m['meter_type'] ?? 'Warmwasser';
- $cost = $this->AddMeterToPDFRow($m, $tariffs, $from, $to, $type);
- $html .= $cost['row'];
- $total += $cost['value'];
- $usedTariffs = array_merge($usedTariffs, $cost['tariffs']);
- }
-
- $html .= "
- | Total Nebenkosten: |
- " . number_format($total, 2) . " |
-
";
-
- // 👇 Tarifliste anhängen
- if (!empty($usedTariffs)) {
- $html .= "Angewendete Nebenkostentarife:
";
- foreach ($usedTariffs as $t) {
- $html .= "- " . date('d.m.Y', $t['start']) . " – " . date('d.m.Y', $t['end']) . ": " .
- number_format($t['price'], 2) . " Rp
";
- }
- $html .= "
";
- }
-
- return ['html' => $html, 'sum' => $total];
-}
-
// ====================== Kernberechnung ======================
private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)