$items * @return array */ protected function sortEntries(array $items): array { usort($items, function (InvoiceItem $item1, InvoiceItem $item2) { return $item1->getBegin() <=> $item2->getBegin(); }); return $items; } abstract public function getId(): string; public function setModel(InvoiceModel $model): void { $this->model = $model; } public function getSubtotal(): float { $amount = 0.00; foreach ($this->model->getEntries() as $entry) { $amount += $entry->getRate(); } return round($amount, 2); } /** * @deprecated use getTaxRows() instead */ public function getVat(): float { return $this->model->getTemplate()->getVat() ?? 0.00; } /** * @return array */ public function getTaxRows(): array { $rows = []; foreach ($this->model->getTemplate()->getTaxRates() as $taxRate) { $rows[] = new TaxRow($taxRate, $this->getSubtotal()); } return $rows; } public function getTax(): float { $tax = 0.00; foreach ($this->getTaxRows() as $row) { $tax += $row->getAmount(); } return round($tax, 2); } public function getTotal(): float { return $this->getSubtotal() + $this->getTax(); } /** * Returns the total amount of worked time in seconds. */ public function getTimeWorked(): int { $time = 0; foreach ($this->model->getEntries() as $entry) { if (null !== $entry->getDuration()) { $time += $entry->getDuration(); } } return $time; } }