no message
This commit is contained in:
@@ -243,8 +243,8 @@ 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
|
$startValTotal = $this->GetValueAt($meter['var_consumption'], $from, false);
|
||||||
$endValTotal = $this->GetValueAt($meter['var_consumption'], $to, true); // erster Wert ≥ Ende
|
$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");
|
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 = '';
|
$rows = '';
|
||||||
$totalCost = 0.0;
|
$totalCost = 0.0;
|
||||||
|
$foundTariff = false;
|
||||||
|
|
||||||
foreach ($tariffs as $t) {
|
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']);
|
$tariffStart = strtotime($t['start']);
|
||||||
$tariffEnd = strtotime($t['end']);
|
$tariffEnd = strtotime($t['end']);
|
||||||
|
|
||||||
// Überschneidung mit Abrechnungszeitraum
|
// Überschneidung
|
||||||
$sectionStart = max($from, $tariffStart);
|
$sectionStart = max($from, $tariffStart);
|
||||||
$sectionEnd = min($to, $tariffEnd);
|
$sectionEnd = min($to, $tariffEnd);
|
||||||
if ($sectionEnd <= $sectionStart) continue;
|
if ($sectionEnd <= $sectionStart) continue;
|
||||||
|
|
||||||
// Verbrauch anteilig
|
|
||||||
$sectionFraction = ($sectionEnd - $sectionStart) / ($to - $from);
|
$sectionFraction = ($sectionEnd - $sectionStart) / ($to - $from);
|
||||||
$sectionDiff = $totalDiff * $sectionFraction;
|
$sectionDiff = $totalDiff * $sectionFraction;
|
||||||
|
|
||||||
// Start-/Endwert für diese Tarifzeit berechnen
|
|
||||||
$sectionStartVal = $startValTotal + $totalDiff * (($sectionStart - $from) / ($to - $from));
|
$sectionStartVal = $startValTotal + $totalDiff * (($sectionStart - $from) / ($to - $from));
|
||||||
$sectionEndVal = $sectionStartVal + $sectionDiff;
|
$sectionEndVal = $sectionStartVal + $sectionDiff;
|
||||||
|
|
||||||
$tariffRp = floatval($t['price']);
|
$tariffRp = floatval($t['price']); // Preis in Rappen pro Einheit
|
||||||
$costCHF = ($tariffRp / 100) * $sectionDiff;
|
$costCHF = ($tariffRp / 100) * $sectionDiff;
|
||||||
|
|
||||||
$rows .= "
|
$rows .= "
|
||||||
@@ -292,10 +296,11 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
</tr>";
|
</tr>";
|
||||||
|
|
||||||
$totalCost += $costCHF;
|
$totalCost += $costCHF;
|
||||||
|
$foundTariff = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback, falls kein Tarif passt
|
// Falls kein passender Tarif gefunden
|
||||||
if ($rows === '') {
|
if (!$foundTariff) {
|
||||||
$rows .= "
|
$rows .= "
|
||||||
<tr>
|
<tr>
|
||||||
<td>{$meter['name']}</td>
|
<td>{$meter['name']}</td>
|
||||||
|
|||||||
Reference in New Issue
Block a user