no message
This commit is contained in:
@@ -227,28 +227,59 @@ public function GenerateInvoices()
|
||||
return floatval(GetValue($varId));
|
||||
}
|
||||
|
||||
private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
||||
{
|
||||
$start = $this->GetValueAt($meter['var_consumption'], $from);
|
||||
$end = $this->GetValueAt($meter['var_consumption'], $to);
|
||||
if ($start === null || $end === null) return ['row' => '', 'value' => 0];
|
||||
private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
||||
{
|
||||
$startVal = $this->GetValueAt($meter['var_consumption'], $from);
|
||||
$endVal = $this->GetValueAt($meter['var_consumption'], $to);
|
||||
if ($startVal === null || $endVal === null) return ['row' => '', 'value' => 0];
|
||||
|
||||
$diff = max(0, $end - $start);
|
||||
$tariffRp = $this->GetTariff($tariffs, $type, $from, $to);
|
||||
$cost = ($tariffRp / 100) * $diff;
|
||||
$totalDiff = max(0, $endVal - $startVal);
|
||||
if ($totalDiff <= 0) return ['row' => '', 'value' => 0];
|
||||
|
||||
$row = "
|
||||
<tr>
|
||||
<td>{$meter['name']}</td>
|
||||
<td>$type</td>
|
||||
<td>$start</td>
|
||||
<td>$end</td>
|
||||
<td>$diff</td>
|
||||
<td>$tariffRp</td>
|
||||
<td>" . number_format($cost, 2) . "</td>
|
||||
</tr>";
|
||||
$rows = '';
|
||||
$totalCost = 0.0;
|
||||
|
||||
return ['row' => $row, 'value' => $cost];
|
||||
// Alle Tarife dieses Typs prüfen
|
||||
foreach ($tariffs as $t) {
|
||||
if (strtolower($t['unit_type']) != strtolower($type)) continue;
|
||||
|
||||
$tariffStart = strtotime($t['start']);
|
||||
$tariffEnd = strtotime($t['end']);
|
||||
|
||||
// Zeitliche Überschneidung mit Abrechnungszeitraum?
|
||||
if ($tariffEnd < $from || $tariffStart > $to) continue;
|
||||
|
||||
// Überschneidung bestimmen
|
||||
$sectionStart = max($from, $tariffStart);
|
||||
$sectionEnd = min($to, $tariffEnd);
|
||||
$sectionDuration = $sectionEnd - $sectionStart;
|
||||
$totalDuration = $to - $from;
|
||||
|
||||
if ($sectionDuration <= 0) continue;
|
||||
|
||||
// Anteil des Gesamtverbrauchs nach Zeitanteil
|
||||
$sectionFraction = $sectionDuration / $totalDuration;
|
||||
$sectionDiff = $totalDiff * $sectionFraction;
|
||||
|
||||
$tariffRp = floatval($t['price']);
|
||||
$costCHF = ($tariffRp / 100) * $sectionDiff;
|
||||
|
||||
$rows .= "
|
||||
<tr>
|
||||
<td>{$meter['name']}</td>
|
||||
<td>$type</td>
|
||||
<td>" . date('d.m.Y', $sectionStart) . "</td>
|
||||
<td>" . date('d.m.Y', $sectionEnd) . "</td>
|
||||
<td>" . number_format($sectionDiff, 2) . "</td>
|
||||
<td>" . number_format($tariffRp, 2) . "</td>
|
||||
<td>" . number_format($costCHF, 2) . "</td>
|
||||
</tr>";
|
||||
|
||||
$totalCost += $costCHF;
|
||||
}
|
||||
|
||||
return ['row' => $rows, 'value' => $totalCost];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user