no message
This commit is contained in:
@@ -227,28 +227,59 @@ public function GenerateInvoices()
|
|||||||
return floatval(GetValue($varId));
|
return floatval(GetValue($varId));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
||||||
{
|
{
|
||||||
$start = $this->GetValueAt($meter['var_consumption'], $from);
|
$startVal = $this->GetValueAt($meter['var_consumption'], $from);
|
||||||
$end = $this->GetValueAt($meter['var_consumption'], $to);
|
$endVal = $this->GetValueAt($meter['var_consumption'], $to);
|
||||||
if ($start === null || $end === null) return ['row' => '', 'value' => 0];
|
if ($startVal === null || $endVal === null) return ['row' => '', 'value' => 0];
|
||||||
|
|
||||||
$diff = max(0, $end - $start);
|
$totalDiff = max(0, $endVal - $startVal);
|
||||||
$tariffRp = $this->GetTariff($tariffs, $type, $from, $to);
|
if ($totalDiff <= 0) return ['row' => '', 'value' => 0];
|
||||||
$cost = ($tariffRp / 100) * $diff;
|
|
||||||
|
|
||||||
$row = "
|
$rows = '';
|
||||||
<tr>
|
$totalCost = 0.0;
|
||||||
<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>";
|
|
||||||
|
|
||||||
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