no message

This commit is contained in:
2025-11-04 17:03:21 +01:00
parent e6c6f66999
commit 374445cc62

View File

@@ -243,8 +243,8 @@ private function GetValueAt(int $varId, int $timestamp, bool $nearestAfter = fal
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
$startValTotal = $this->GetValueAt($meter['var_consumption'], $from, false);
$endValTotal = $this->GetValueAt($meter['var_consumption'], $to, true);
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");
@@ -255,27 +255,31 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
$rows = '';
$totalCost = 0.0;
$foundTariff = false;
foreach ($tariffs as $t) {
if (strtolower($t['unit_type']) != strtolower($type)) continue;
// Einheit auflösen (ignoriere Groß/Kleinschreibung, evtl. Synonyme)
$unitType = strtolower($t['unit_type']);
$meterType = strtolower($type);
if ($meterType === 'strombezug') $meterType = 'strom';
if ($meterType === 'warmwasser') $meterType = 'wasser';
if ($unitType !== $meterType) continue;
$tariffStart = strtotime($t['start']);
$tariffEnd = strtotime($t['end']);
// Überschneidung mit Abrechnungszeitraum
// Überschneidung
$sectionStart = max($from, $tariffStart);
$sectionEnd = min($to, $tariffEnd);
if ($sectionEnd <= $sectionStart) continue;
// Verbrauch anteilig
$sectionFraction = ($sectionEnd - $sectionStart) / ($to - $from);
$sectionDiff = $totalDiff * $sectionFraction;
// Start-/Endwert für diese Tarifzeit berechnen
$sectionStartVal = $startValTotal + $totalDiff * (($sectionStart - $from) / ($to - $from));
$sectionEndVal = $sectionStartVal + $sectionDiff;
$tariffRp = floatval($t['price']);
$tariffRp = floatval($t['price']); // Preis in Rappen pro Einheit
$costCHF = ($tariffRp / 100) * $sectionDiff;
$rows .= "
@@ -292,10 +296,11 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
</tr>";
$totalCost += $costCHF;
$foundTariff = true;
}
// Fallback, falls kein Tarif passt
if ($rows === '') {
// Falls kein passender Tarif gefunden
if (!$foundTariff) {
$rows .= "
<tr>
<td>{$meter['name']}</td>