no message
This commit is contained in:
+30
-44
@@ -302,7 +302,7 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
|
|
||||||
date_default_timezone_set('Europe/Zurich');
|
date_default_timezone_set('Europe/Zurich');
|
||||||
|
|
||||||
// 🔹 Tarife nach Typ filtern
|
// 🔹 Filtere relevante Tarife nach Typ
|
||||||
$filteredTariffs = array_filter($tariffs, function ($t) use ($type) {
|
$filteredTariffs = array_filter($tariffs, function ($t) use ($type) {
|
||||||
return strtolower(trim($t['unit_type'] ?? '')) === strtolower(trim($type));
|
return strtolower(trim($t['unit_type'] ?? '')) === strtolower(trim($type));
|
||||||
});
|
});
|
||||||
@@ -312,30 +312,18 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
return ['row' => '', 'value' => 0];
|
return ['row' => '', 'value' => 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 🔹 Zeitstempel normieren und sortieren
|
// 🔹 Normiere Zeiträume
|
||||||
foreach ($filteredTariffs as &$t) {
|
foreach ($filteredTariffs as &$t) {
|
||||||
$t['start_ts'] = $this->toUnixTs($t['start'], false);
|
$t['start_ts'] = $this->toUnixTs($t['start'], false);
|
||||||
$t['end_ts'] = $this->toUnixTs($t['end'], true);
|
$t['end_ts'] = $this->toUnixTs($t['end'], true);
|
||||||
|
|
||||||
if (!$t['start_ts'] || !$t['end_ts']) {
|
|
||||||
IPS_LogMessage('Abrechnung', "⚠ Ungültiger Tarifzeitraum: " . json_encode($t));
|
|
||||||
} else {
|
|
||||||
IPS_LogMessage('Abrechnung', sprintf(
|
|
||||||
" 🕓 Tarif gültig von %s bis %s @ %.3f Rp",
|
|
||||||
date('d.m.Y H:i', $t['start_ts']),
|
|
||||||
date('d.m.Y H:i', $t['end_ts']),
|
|
||||||
floatval($t['price'])
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
unset($t);
|
unset($t);
|
||||||
usort($filteredTariffs, fn($a, $b) => ($a['start_ts'] ?? 0) <=> ($b['start_ts'] ?? 0));
|
usort($filteredTariffs, fn($a, $b) => ($a['start_ts'] ?? 0) <=> ($b['start_ts'] ?? 0));
|
||||||
|
|
||||||
$currentStart = $from;
|
$currentStart = $from;
|
||||||
$segmentIndex = 1;
|
|
||||||
|
|
||||||
while ($currentStart < $to) {
|
while ($currentStart < $to) {
|
||||||
// 🔹 Aktiven Tarif finden
|
// 🔹 Aktiven Tarif suchen
|
||||||
$activeTariff = null;
|
$activeTariff = null;
|
||||||
foreach ($filteredTariffs as $t) {
|
foreach ($filteredTariffs as $t) {
|
||||||
if (($t['start_ts'] ?? 0) <= $currentStart && $currentStart <= ($t['end_ts'] ?? 0)) {
|
if (($t['start_ts'] ?? 0) <= $currentStart && $currentStart <= ($t['end_ts'] ?? 0)) {
|
||||||
@@ -345,7 +333,6 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$activeTariff) {
|
if (!$activeTariff) {
|
||||||
IPS_LogMessage('Abrechnung', "⚠ Kein Tarif aktiv bei " . date('d.m.Y H:i', $currentStart));
|
|
||||||
$activeTariff = [
|
$activeTariff = [
|
||||||
'start_ts' => $currentStart,
|
'start_ts' => $currentStart,
|
||||||
'end_ts' => $to,
|
'end_ts' => $to,
|
||||||
@@ -358,32 +345,33 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
$tariffPrice = floatval($activeTariff['price']);
|
$tariffPrice = floatval($activeTariff['price']);
|
||||||
$tariffLabel = number_format($tariffPrice, 2, ',', '');
|
$tariffLabel = number_format($tariffPrice, 2, ',', '');
|
||||||
|
|
||||||
// 🔹 Werte lesen
|
// 🔹 Werte aus Archiv lesen
|
||||||
$startValue = $this->GetValueAt($varId, $currentStart, true);
|
$startValue = $this->GetValueAt($varId, $currentStart, true);
|
||||||
$segmentEnd = ($tariffEnd < $to) ? $tariffEnd : $to;
|
$segmentEnd = ($tariffEnd < $to) ? $tariffEnd : $to;
|
||||||
$endValue = $this->GetValueAt($varId, $segmentEnd, true);
|
$endValue = $this->GetValueAt($varId, $segmentEnd, true);
|
||||||
|
|
||||||
if ($startValue === null || $endValue === null) {
|
if ($startValue === null || $endValue === null) break;
|
||||||
IPS_LogMessage('Abrechnung', "⚠ Keine Werte für {$meter['name']} im Zeitraum " . date('d.m.Y H:i', $currentStart));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$verbrauch = max(0, $endValue - $startValue);
|
$verbrauch = max(0, $endValue - $startValue);
|
||||||
$kosten = round(($tariffPrice / 100) * $verbrauch, 2);
|
$kosten = round(($tariffPrice / 100) * $verbrauch, 2);
|
||||||
$totalCost += $kosten;
|
$totalCost += $kosten;
|
||||||
|
|
||||||
// 🔹 Tabellenzeile formatiert
|
// 🔹 Kurze Datumsangaben
|
||||||
|
$startDate = date('d.m.Y', $currentStart);
|
||||||
|
$endDate = date('d.m.Y', $segmentEnd);
|
||||||
|
|
||||||
|
// 🔹 Tabellenzeile mit sichtbaren Linien
|
||||||
$rows .= "
|
$rows .= "
|
||||||
<tr style='border-bottom:0.3px solid #ccc;'>
|
<tr>
|
||||||
<td style='padding:2px;'>{$meter['name']}</td>
|
<td border='1' align='left' style='padding:2px;'>{$meter['name']}</td>
|
||||||
<td style='padding:2px;'>{$type}</td>
|
<td border='1' align='left' style='padding:2px;'>{$type}</td>
|
||||||
<td style='padding:2px; text-align:center;'>" . date('d.m.Y H:i', $currentStart) . "</td>
|
<td border='1' align='center' style='padding:2px;'>{$startDate}</td>
|
||||||
<td style='padding:2px; text-align:center;'>" . date('d.m.Y H:i', $segmentEnd) . "</td>
|
<td border='1' align='center' style='padding:2px;'>{$endDate}</td>
|
||||||
<td style='padding:2px; text-align:right;'>" . number_format($startValue, 2) . "</td>
|
<td border='1' align='right' style='padding:2px;'>" . number_format($startValue, 2) . "</td>
|
||||||
<td style='padding:2px; text-align:right;'>" . number_format($endValue, 2) . "</td>
|
<td border='1' align='right' style='padding:2px;'>" . number_format($endValue, 2) . "</td>
|
||||||
<td style='padding:2px; text-align:right;'>" . number_format($verbrauch, 2) . "</td>
|
<td border='1' align='right' style='padding:2px;'>" . number_format($verbrauch, 2) . "</td>
|
||||||
<td style='padding:2px; text-align:right;'>" . $tariffLabel . "</td>
|
<td border='1' align='right' style='padding:2px;'>" . $tariffLabel . "</td>
|
||||||
<td style='padding:2px; text-align:right;'>" . number_format($kosten, 2) . "</td>
|
<td border='1' align='right' style='padding:2px;'>" . number_format($kosten, 2) . "</td>
|
||||||
</tr>";
|
</tr>";
|
||||||
|
|
||||||
if ($tariffEnd < $to) {
|
if ($tariffEnd < $to) {
|
||||||
@@ -391,26 +379,24 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$segmentIndex++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback – kein Segment berechnet
|
// 🔹 Fallback – kein Segment gefunden
|
||||||
if ($rows === '') {
|
if ($rows === '') {
|
||||||
$startVal = $this->GetValueAt($varId, $from, false);
|
$startVal = $this->GetValueAt($varId, $from, false);
|
||||||
$endVal = $this->GetValueAt($varId, $to, true);
|
$endVal = $this->GetValueAt($varId, $to, true);
|
||||||
$verbrauch = max(0, $endVal - $startVal);
|
$verbrauch = max(0, $endVal - $startVal);
|
||||||
$rows = "
|
$rows = "
|
||||||
<tr>
|
<tr>
|
||||||
<td style='padding:2px;'>{$meter['name']}</td>
|
<td border='1' align='left'>{$meter['name']}</td>
|
||||||
<td style='padding:2px;'>{$type}</td>
|
<td border='1' align='left'>{$type}</td>
|
||||||
<td style='padding:2px;'>" . date('d.m.Y H:i', $from) . "</td>
|
<td border='1' align='center'>" . date('d.m.Y', $from) . "</td>
|
||||||
<td style='padding:2px;'>" . date('d.m.Y H:i', $to) . "</td>
|
<td border='1' align='center'>" . date('d.m.Y', $to) . "</td>
|
||||||
<td style='padding:2px; text-align:right;'>" . number_format($startVal, 2) . "</td>
|
<td border='1' align='right'>" . number_format($startVal, 2) . "</td>
|
||||||
<td style='padding:2px; text-align:right;'>" . number_format($endVal, 2) . "</td>
|
<td border='1' align='right'>" . number_format($endVal, 2) . "</td>
|
||||||
<td style='padding:2px; text-align:right;'>" . number_format($verbrauch, 2) . "</td>
|
<td border='1' align='right'>" . number_format($verbrauch, 2) . "</td>
|
||||||
<td style='padding:2px; text-align:right;'>0.00</td>
|
<td border='1' align='right'>0.00</td>
|
||||||
<td style='padding:2px; text-align:right;'>0.00</td>
|
<td border='1' align='right'>0.00</td>
|
||||||
</tr>";
|
</tr>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user