no message
This commit is contained in:
@@ -89,7 +89,7 @@ class Abrechnung extends IPSModule
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stromkosten einmal für alle User berechnen
|
// Stromkosten einmal für alle User berechnen (15-Minuten-Logik)
|
||||||
$this->CalculateAllPowerCosts($power, $tariffs, $from, $to);
|
$this->CalculateAllPowerCosts($power, $tariffs, $from, $to);
|
||||||
|
|
||||||
$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
|
$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
|
||||||
@@ -119,7 +119,7 @@ class Abrechnung extends IPSModule
|
|||||||
$html .= "<h3>⚡ Stromkosten</h3>" . $powerResult['html'];
|
$html .= "<h3>⚡ Stromkosten</h3>" . $powerResult['html'];
|
||||||
$totalPower = $powerResult['sum'];
|
$totalPower = $powerResult['sum'];
|
||||||
|
|
||||||
// Nebenkosten (Wasser/Wärme)
|
// Nebenkosten (Wasser/Wärme) – einfache Differenz von Beginn bis Ende
|
||||||
$additionalResult = $this->CalculateAdditionalCosts($water, $tariffs, $user['id'], $from, $to);
|
$additionalResult = $this->CalculateAdditionalCosts($water, $tariffs, $user['id'], $from, $to);
|
||||||
$html .= "<h3>💧 Nebenkosten (Wasser/Wärme)</h3>" . $additionalResult['html'];
|
$html .= "<h3>💧 Nebenkosten (Wasser/Wärme)</h3>" . $additionalResult['html'];
|
||||||
$totalAdditional = $additionalResult['sum'];
|
$totalAdditional = $additionalResult['sum'];
|
||||||
@@ -216,14 +216,14 @@ class Abrechnung extends IPSModule
|
|||||||
|
|
||||||
// Verhältnis PV / Netz pro User
|
// Verhältnis PV / Netz pro User
|
||||||
if ($impTotal <= $expTotal && $expTotal > 0.0) {
|
if ($impTotal <= $expTotal && $expTotal > 0.0) {
|
||||||
$ratio = $impTotal / $expTotal;
|
$ratio = $impTotal / $expTotal;
|
||||||
$pvCoversAll = true;
|
$pvCoversAll = true;
|
||||||
} elseif ($impTotal > 0.0) {
|
} elseif ($impTotal > 0.0) {
|
||||||
$ratio = $expTotal / $impTotal;
|
$ratio = $expTotal / $impTotal;
|
||||||
$pvCoversAll = false;
|
$pvCoversAll = false;
|
||||||
} else {
|
} else {
|
||||||
$ratio = 0.0;
|
$ratio = 0.0;
|
||||||
$pvCoversAll = true;
|
$pvCoversAll = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Werte pro Zähler verteilen
|
// Werte pro Zähler verteilen
|
||||||
@@ -359,62 +359,75 @@ class Abrechnung extends IPSModule
|
|||||||
return ['html' => $html, 'sum' => $total];
|
return ['html' => $html, 'sum' => $total];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
||||||
{
|
{
|
||||||
$varId = $meter['var_consumption'];
|
$rows = '';
|
||||||
|
$totalCost = 0.0;
|
||||||
|
$usedTariffs = [];
|
||||||
|
$varId = $meter['var_consumption'];
|
||||||
|
|
||||||
if (!IPS_VariableExists($varId)) {
|
if (!IPS_VariableExists($varId)) {
|
||||||
return ['row' => '', 'value' => 0, 'tariffs' => []];
|
return ['row' => '', 'value' => 0, 'tariffs' => []];
|
||||||
}
|
|
||||||
|
|
||||||
// ---- 1) Start- und Endwerte direkt holen ----
|
|
||||||
$startValue = $this->GetValueAt($varId, $from, false); // letzter Wert VOR dem Start
|
|
||||||
$endValue = $this->GetValueAt($varId, $to, true); // erster Wert NACH dem Ende
|
|
||||||
|
|
||||||
if ($startValue === null || $endValue === null) {
|
|
||||||
return ['row' => '', 'value' => 0, 'tariffs' => []];
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- 2) Verbrauch simple Differenz ----
|
|
||||||
$verbrauch = max(0, $endValue - $startValue);
|
|
||||||
|
|
||||||
// ---- 3) passenden Tarif suchen ----
|
|
||||||
$tariffPrice = 0.0;
|
|
||||||
foreach ($tariffs as $t) {
|
|
||||||
if (strtolower(trim($t['unit_type'] ?? '')) === strtolower(trim($type))) {
|
|
||||||
$tariffPrice = floatval($t['price']);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Relevante Tarife nach Typ filtern
|
||||||
|
$filteredTariffs = array_filter($tariffs, fn($t) =>
|
||||||
|
strtolower(trim($t['unit_type'] ?? '')) === strtolower(trim($type))
|
||||||
|
);
|
||||||
|
|
||||||
|
$activeTariff = null;
|
||||||
|
foreach ($filteredTariffs as $t) {
|
||||||
|
$startTs = $this->toUnixTs($t['start'], false);
|
||||||
|
$endTs = $this->toUnixTs($t['end'], true);
|
||||||
|
if ($startTs === null || $endTs === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Tarif überlappt den Abrechnungszeitraum
|
||||||
|
if ($endTs < $from || $startTs > $to) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$activeTariff = [
|
||||||
|
'start' => $startTs,
|
||||||
|
'end' => $endTs,
|
||||||
|
'price' => (float)$t['price']
|
||||||
|
];
|
||||||
|
$usedTariffs[] = $activeTariff;
|
||||||
|
break; // erster passender Tarif reicht
|
||||||
|
}
|
||||||
|
|
||||||
|
$tariffPrice = $activeTariff ? $activeTariff['price'] : 0.0;
|
||||||
|
|
||||||
|
// Verbrauch = letzter Wert vor/gleich "to" minus letzter Wert vor/gleich "from"
|
||||||
|
$startValue = $this->GetValueAt($varId, $from, false);
|
||||||
|
$endValue = $this->GetValueAt($varId, $to, false);
|
||||||
|
|
||||||
|
if ($startValue === null || $endValue === null) {
|
||||||
|
return ['row' => '', 'value' => 0, 'tariffs' => []];
|
||||||
|
}
|
||||||
|
|
||||||
|
$verbrauch = max(0, $endValue - $startValue);
|
||||||
|
$kosten = round(($tariffPrice / 100) * $verbrauch, 2);
|
||||||
|
$totalCost = $kosten;
|
||||||
|
|
||||||
|
$rows .= "<tr>
|
||||||
|
<td>{$meter['name']}</td>
|
||||||
|
<td>{$type}</td>
|
||||||
|
<td align='center'>" . date('d.m.Y', $from) . "</td>
|
||||||
|
<td align='center'>" . date('d.m.Y', $to) . "</td>
|
||||||
|
<td align='right'>" . number_format($startValue, 2) . "</td>
|
||||||
|
<td align='right'>" . number_format($endValue, 2) . "</td>
|
||||||
|
<td align='right'>" . number_format($verbrauch, 2) . "</td>
|
||||||
|
<td align='right'>" . number_format($tariffPrice, 2) . "</td>
|
||||||
|
<td align='right'>" . number_format($kosten, 2) . "</td>
|
||||||
|
</tr>";
|
||||||
|
|
||||||
|
if ($rows === '') {
|
||||||
|
return ['row' => '', 'value' => 0, 'tariffs' => []];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['row' => $rows, 'value' => $totalCost, 'tariffs' => array_values($usedTariffs)];
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- 4) Kosten (Rp → CHF) ----
|
|
||||||
$kosten = round(($tariffPrice / 100) * $verbrauch, 2);
|
|
||||||
|
|
||||||
// ---- 5) Tabellenzeile ----
|
|
||||||
$row = "<tr>
|
|
||||||
<td>{$meter['name']}</td>
|
|
||||||
<td>{$type}</td>
|
|
||||||
<td align='center'>" . date('d.m.Y', $from) . "</td>
|
|
||||||
<td align='center'>" . date('d.m.Y', $to) . "</td>
|
|
||||||
<td align='right'>" . number_format($startValue, 2) . "</td>
|
|
||||||
<td align='right'>" . number_format($endValue, 2) . "</td>
|
|
||||||
<td align='right'>" . number_format($verbrauch, 2) . "</td>
|
|
||||||
<td align='right'>" . number_format($tariffPrice, 2) . "</td>
|
|
||||||
<td align='right'>" . number_format($kosten, 2) . "</td>
|
|
||||||
</tr>";
|
|
||||||
|
|
||||||
return [
|
|
||||||
'row' => $row,
|
|
||||||
'value' => $kosten,
|
|
||||||
'tariffs' => [[
|
|
||||||
'start' => $from,
|
|
||||||
'end' => $to,
|
|
||||||
'price' => $tariffPrice
|
|
||||||
]]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ====================== Hilfsfunktionen ======================
|
// ====================== Hilfsfunktionen ======================
|
||||||
|
|
||||||
private function GetValueAt($varId, $timestamp, $nearestAfter = true)
|
private function GetValueAt($varId, $timestamp, $nearestAfter = true)
|
||||||
|
|||||||
Reference in New Issue
Block a user