no message
This commit is contained in:
+39
-47
@@ -135,7 +135,7 @@ public function GenerateInvoices()
|
|||||||
$html = "
|
$html = "
|
||||||
<h2>Rechnung für {$user['name']}</h2>
|
<h2>Rechnung für {$user['name']}</h2>
|
||||||
<p>{$user['address']}<br>{$user['city']}</p>
|
<p>{$user['address']}<br>{$user['city']}</p>
|
||||||
<table border='1' cellpadding='5'>
|
<table border='1' cellpadding='3' style='font-size:8px;'>
|
||||||
<tr style='background-color:#e0e0e0;'>
|
<tr style='background-color:#e0e0e0;'>
|
||||||
<th>Zähler</th>
|
<th>Zähler</th>
|
||||||
<th>Typ</th>
|
<th>Typ</th>
|
||||||
@@ -241,71 +241,62 @@ private function GetValueAt(int $varId, int $timestamp, bool $nearestAfter = fal
|
|||||||
|
|
||||||
private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
||||||
{
|
{
|
||||||
$startValTotal = $this->GetValueAt($meter['var_consumption'], $from, false); // letzter Wert ≤ Start
|
|
||||||
$endValTotal = $this->GetValueAt($meter['var_consumption'], $to, true); // erster Wert ≥ Ende
|
|
||||||
|
|
||||||
IPS_LogMessage('Abrechnung', "Meter {$meter['name']} ($type) von " . date('d.m.Y H:i', $from) . " bis " . date('d.m.Y H:i', $to) . ": start=$startValTotal, end=$endValTotal");
|
|
||||||
|
|
||||||
if ($startValTotal === null || $endValTotal === null) return ['row' => '', 'value' => 0];
|
|
||||||
|
|
||||||
$totalDiff = max(0, $endValTotal - $startValTotal);
|
|
||||||
if ($totalDiff <= 0) return ['row' => '', 'value' => 0];
|
|
||||||
|
|
||||||
$rows = '';
|
$rows = '';
|
||||||
$totalCost = 0.0;
|
$totalCost = 0.0;
|
||||||
|
|
||||||
foreach ($tariffs as $t) {
|
$currentTime = $from;
|
||||||
if (strtolower($t['unit_type']) != strtolower($type)) continue;
|
$startValTotal = $this->GetValueAt($meter['var_consumption'], $from, false);
|
||||||
|
|
||||||
$tariffStart = strtotime($t['start']);
|
IPS_LogMessage('Abrechnung', "Starte Abrechnung für Meter {$meter['name']} ($type) von " . date('d.m.Y H:i', $from) . " bis " . date('d.m.Y H:i', $to));
|
||||||
$tariffEnd = strtotime($t['end']);
|
|
||||||
|
|
||||||
// Überschneidung mit Abrechnungszeitraum
|
while ($currentTime < $to) {
|
||||||
$sectionStart = max($from, $tariffStart);
|
// 1. Tarif zum aktuellen Zeitpunkt ermitteln
|
||||||
$sectionEnd = min($to, $tariffEnd);
|
$activeTariff = null;
|
||||||
if ($sectionEnd <= $sectionStart) continue;
|
foreach ($tariffs as $t) {
|
||||||
|
if (strtolower($t['unit_type']) != strtolower($type)) continue;
|
||||||
|
$tStart = strtotime($t['start']);
|
||||||
|
$tEnd = strtotime($t['end']);
|
||||||
|
if ($currentTime >= $tStart && $currentTime < $tEnd) {
|
||||||
|
$activeTariff = $t;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Verbrauch anteilig
|
if ($activeTariff === null) {
|
||||||
$sectionFraction = ($sectionEnd - $sectionStart) / ($to - $from);
|
IPS_LogMessage('Abrechnung', "⚠ Kein aktiver Tarif gefunden für $type am " . date('d.m.Y H:i', $currentTime));
|
||||||
$sectionDiff = $totalDiff * $sectionFraction;
|
break; // Kein Tarif → Stop
|
||||||
|
}
|
||||||
|
|
||||||
// Start-/Endwert für diese Tarifzeit berechnen
|
// 2. Zeitraum für diesen Tarif
|
||||||
$sectionStartVal = $startValTotal + $totalDiff * (($sectionStart - $from) / ($to - $from));
|
$periodStart = $currentTime;
|
||||||
$sectionEndVal = $sectionStartVal + $sectionDiff;
|
$periodEnd = min($to, strtotime($activeTariff['end']));
|
||||||
|
|
||||||
$tariffRp = floatval($t['price']);
|
// 3. Zählerstände für diesen Zeitraum ermitteln
|
||||||
$costCHF = ($tariffRp / 100) * $sectionDiff;
|
$startVal = ($periodStart == $from) ? $startValTotal : $this->GetValueAt($meter['var_consumption'], $periodStart, false);
|
||||||
|
$endVal = $this->GetValueAt($meter['var_consumption'], $periodEnd, true);
|
||||||
|
|
||||||
|
$diff = max(0, $endVal - $startVal);
|
||||||
|
$tariffRp = floatval($activeTariff['price']);
|
||||||
|
$costCHF = ($tariffRp / 100) * $diff;
|
||||||
|
|
||||||
|
// 4. Zeile für PDF
|
||||||
$rows .= "
|
$rows .= "
|
||||||
<tr>
|
<tr>
|
||||||
<td>{$meter['name']}</td>
|
<td>{$meter['name']}</td>
|
||||||
<td>$type</td>
|
<td>$type</td>
|
||||||
<td>" . date('d.m.Y H:i', $sectionStart) . "</td>
|
<td>" . date('d.m.Y H:i', $periodStart) . "</td>
|
||||||
<td>" . date('d.m.Y H:i', $sectionEnd) . "</td>
|
<td>" . date('d.m.Y H:i', $periodEnd) . "</td>
|
||||||
<td>" . number_format($sectionStartVal, 2) . "</td>
|
<td>" . number_format($startVal, 2) . "</td>
|
||||||
<td>" . number_format($sectionEndVal, 2) . "</td>
|
<td>" . number_format($endVal, 2) . "</td>
|
||||||
<td>" . number_format($sectionDiff, 2) . "</td>
|
<td>" . number_format($diff, 2) . "</td>
|
||||||
<td>" . number_format($tariffRp, 2) . "</td>
|
<td>" . number_format($tariffRp, 2) . "</td>
|
||||||
<td>" . number_format($costCHF, 2) . "</td>
|
<td>" . number_format($costCHF, 2) . "</td>
|
||||||
</tr>";
|
</tr>";
|
||||||
|
|
||||||
$totalCost += $costCHF;
|
$totalCost += $costCHF;
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback, falls kein Tarif passt
|
// 5. Zum nächsten Tarif springen
|
||||||
if ($rows === '') {
|
$currentTime = $periodEnd;
|
||||||
$rows .= "
|
|
||||||
<tr>
|
|
||||||
<td>{$meter['name']}</td>
|
|
||||||
<td>$type</td>
|
|
||||||
<td>" . date('d.m.Y H:i', $from) . "</td>
|
|
||||||
<td>" . date('d.m.Y H:i', $to) . "</td>
|
|
||||||
<td>" . number_format($startValTotal, 2) . "</td>
|
|
||||||
<td>" . number_format($endValTotal, 2) . "</td>
|
|
||||||
<td>" . number_format($totalDiff, 2) . "</td>
|
|
||||||
<td>0</td>
|
|
||||||
<td>0.00</td>
|
|
||||||
</tr>";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ['row' => $rows, 'value' => $totalCost];
|
return ['row' => $rows, 'value' => $totalCost];
|
||||||
@@ -313,4 +304,5 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user