fakturaFacade->getById($id); if (!$faktura) { $this->error('Faktura nebyla nalezena.', 404); } $pdf = $this->fakturaPdf->render($faktura, $this->fakturaFacade->getPolozky($id), $tisk); $fileName = FakturaPdf::fileName((string) $faktura->CISLO); $disposition = $tisk ? 'inline' : 'attachment'; $this->sendResponse(new CallbackResponse(function ($httpRequest, $httpResponse) use ($pdf, $fileName, $disposition): void { $httpResponse->setContentType('application/pdf'); $httpResponse->setHeader( 'Content-Disposition', $disposition . '; filename="' . $fileName . '"' ); echo $pdf; })); } public function renderDefault(int $id): void { $faktura = $this->fakturaFacade->getById($id); if (!$faktura) { $this->flashMessage('Faktura nebyla nalezena.', 'danger'); $this->redirect('Faktura:default'); } $polozky = $this->fakturaFacade->getPolozky($id); // Výpočet celkové částky $celkem = 0; foreach ($polozky as $p) { $celkem += (float) $p->CENA; } $this->template->faktura = $faktura; $this->template->polozky = $polozky; $this->template->celkem = $celkem; } }