74 lines
2.0 KiB
PHP
74 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\UI\Faktura;
|
|
|
|
use App\UI\BasePresenter;
|
|
use App\Model\Facade\FakturaFacade;
|
|
|
|
class FakturaPresenter extends BasePresenter
|
|
{
|
|
/** @persistent */
|
|
public int $rok;
|
|
|
|
/** @persistent */
|
|
public string $mesic = '';
|
|
|
|
public function __construct(
|
|
private FakturaFacade $fakturaFacade
|
|
) {
|
|
parent::__construct();
|
|
$this->rok = (int) date('Y');
|
|
}
|
|
|
|
public function renderDefault(): void
|
|
{
|
|
// RLS v databázi se postará o filtraci podle firmy,
|
|
// fasáda vrátí seřazené faktury s dopočítanou sumou.
|
|
$faktury = $this->fakturaFacade->getFiltered($this->rok, $this->mesic);
|
|
|
|
// Agregace pro přehledové karty nad aktuálním výběrem
|
|
$celkemSum = 0;
|
|
$neuhrazenoCount = 0;
|
|
|
|
foreach ($faktury as $f) {
|
|
$celkemSum += (float) ($f->CASTKA_CELKEM ?? 0);
|
|
if ($f->STAV !== 'PAID') {
|
|
$neuhrazenoCount++;
|
|
}
|
|
}
|
|
|
|
$this->template->faktury = $faktury;
|
|
$this->template->celkemSum = $celkemSum;
|
|
$this->template->neuhrazenoCount = $neuhrazenoCount;
|
|
$this->template->selectedRok = $this->rok ?? (int) date('Y'); // <--- PŘIDÁNO
|
|
$this->template->selectedMesic = $this->mesic ?? ''; // <--- PŘIDÁNO
|
|
}
|
|
|
|
/**
|
|
* Přepnutí stavu zaplaceno / neuhrazeno
|
|
*/
|
|
public function handleUhradit(int $id): void
|
|
{
|
|
$novyStav = $this->fakturaFacade->toggleUhrada($id);
|
|
|
|
if ($novyStav !== '') {
|
|
$this->flashMessage(
|
|
$novyStav === 'PAID' ? 'Faktura byla označena jako zaplacená.' : 'Stav faktury byl změněn na neuhrazeno.',
|
|
'success'
|
|
);
|
|
}
|
|
|
|
$this->redirect('this');
|
|
}
|
|
|
|
/**
|
|
* Smazání faktury
|
|
*/
|
|
public function handleDelete(int $id): void
|
|
{
|
|
$this->fakturaFacade->delete($id);
|
|
$this->flashMessage('Faktura byla smazána.', 'info');
|
|
|
|
$this->redirect('this');
|
|
}
|
|
} |