no message
This commit is contained in:
@@ -241,42 +241,38 @@ 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)
|
||||||
{
|
{
|
||||||
$startVal = $this->GetValueAt($meter['var_consumption'], $from, false); // letzter Wert ≤ Start
|
$startValTotal = $this->GetValueAt($meter['var_consumption'], $from, false); // letzter Wert ≤ Start
|
||||||
$endVal = $this->GetValueAt($meter['var_consumption'], $to, true); // erster Wert ≥ Ende
|
$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");
|
||||||
|
|
||||||
IPS_LogMessage('Abrechnung', "Meter {$meter['name']} ($type) von " . date('d.m.Y H:i', $from) . " bis " . date('d.m.Y H:i', $to) . ": start=$startVal, end=$endVal");
|
if ($startValTotal === null || $endValTotal === null) return ['row' => '', 'value' => 0];
|
||||||
|
|
||||||
if ($startVal === null || $endVal === null) return ['row' => '', 'value' => 0];
|
$totalDiff = max(0, $endValTotal - $startValTotal);
|
||||||
|
|
||||||
$totalDiff = max(0, $endVal - $startVal);
|
|
||||||
if ($totalDiff <= 0) return ['row' => '', 'value' => 0];
|
if ($totalDiff <= 0) return ['row' => '', 'value' => 0];
|
||||||
|
|
||||||
$rows = '';
|
$rows = '';
|
||||||
$totalCost = 0.0;
|
$totalCost = 0.0;
|
||||||
|
|
||||||
// Alle Tarife dieses Typs prüfen
|
|
||||||
foreach ($tariffs as $t) {
|
foreach ($tariffs as $t) {
|
||||||
if (strtolower($t['unit_type']) != strtolower($type)) continue;
|
if (strtolower($t['unit_type']) != strtolower($type)) continue;
|
||||||
|
|
||||||
$tariffStart = strtotime($t['start']);
|
$tariffStart = strtotime($t['start']);
|
||||||
$tariffEnd = strtotime($t['end']);
|
$tariffEnd = strtotime($t['end']);
|
||||||
|
|
||||||
// Überschneidung mit Abrechnungszeitraum prüfen
|
// Überschneidung mit Abrechnungszeitraum
|
||||||
if ($tariffEnd < $from || $tariffStart > $to) continue;
|
|
||||||
|
|
||||||
// Überschneidung bestimmen
|
|
||||||
$sectionStart = max($from, $tariffStart);
|
$sectionStart = max($from, $tariffStart);
|
||||||
$sectionEnd = min($to, $tariffEnd);
|
$sectionEnd = min($to, $tariffEnd);
|
||||||
$sectionDuration = $sectionEnd - $sectionStart;
|
if ($sectionEnd <= $sectionStart) continue;
|
||||||
$totalDuration = $to - $from;
|
|
||||||
|
|
||||||
if ($sectionDuration <= 0) continue;
|
// Verbrauch anteilig
|
||||||
|
$sectionFraction = ($sectionEnd - $sectionStart) / ($to - $from);
|
||||||
// Verbrauch anteilig nach Dauer
|
|
||||||
$sectionFraction = $sectionDuration / $totalDuration;
|
|
||||||
$sectionDiff = $totalDiff * $sectionFraction;
|
$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']);
|
||||||
$costCHF = ($tariffRp / 100) * $sectionDiff;
|
$costCHF = ($tariffRp / 100) * $sectionDiff;
|
||||||
|
|
||||||
@@ -286,6 +282,8 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
<td>$type</td>
|
<td>$type</td>
|
||||||
<td>" . date('d.m.Y H:i', $sectionStart) . "</td>
|
<td>" . date('d.m.Y H:i', $sectionStart) . "</td>
|
||||||
<td>" . date('d.m.Y H:i', $sectionEnd) . "</td>
|
<td>" . date('d.m.Y H:i', $sectionEnd) . "</td>
|
||||||
|
<td>" . number_format($sectionStartVal, 2) . "</td>
|
||||||
|
<td>" . number_format($sectionEndVal, 2) . "</td>
|
||||||
<td>" . number_format($sectionDiff, 2) . "</td>
|
<td>" . number_format($sectionDiff, 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>
|
||||||
@@ -302,6 +300,8 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
<td>$type</td>
|
<td>$type</td>
|
||||||
<td>" . date('d.m.Y H:i', $from) . "</td>
|
<td>" . date('d.m.Y H:i', $from) . "</td>
|
||||||
<td>" . date('d.m.Y H:i', $to) . "</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>" . number_format($totalDiff, 2) . "</td>
|
||||||
<td>0</td>
|
<td>0</td>
|
||||||
<td>0.00</td>
|
<td>0.00</td>
|
||||||
@@ -312,4 +312,5 @@ private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user