Current Path : /data/web/virtuals/51568/virtual/www/subdom/srps/src/models/ |
Current File : /data/web/virtuals/51568/virtual/www/subdom/srps/src/models/Akce.php |
<?php namespace app\models; use app\Model; use app\Application; use app\classes\Funkce; class Akce extends Model { private $aktualniMesic; private $idAktualniRok; private $aktualniRok; public $akce; public $idrok; public $rok; public $mesic; public $id; public function __construct() { $this->aktualniMesic = date('m'); $rok = Application::$app->db->fetchOne("SELECT `id`, `rok` FROM `jak_roky` WHERE `aktualni_th`='1'"); $this->idAktualniRok = $rok->id; $this->aktualniRok = $rok->rok; $this->disabled['rok'] = true; } public function tableName(): string { return "sr_akce"; } public function primaryKey(): string { return 'id'; } public function rules(): array { $this->specialErrorMessages['mesic'][self::RULE_MINNUM] = 'měsíc je z rozsahu 1 až 12'; $this->specialErrorMessages['mesic'][self::RULE_MAXNUM] = 'měsíc je z rozsahu 1 až 12'; return [ 'akce' => [self::RULE_REQUIRED], 'mesic' => [self::RULE_REQUIRED, [self::RULE_MINNUM, 'minnum' => 1], [self::RULE_MAXNUM, 'maxnum' => 12]], 'id' => [], 'rok' => [], 'idrok' => [], ]; } public function labels(): array { return [ 'akce' => 'Důvod výběru peněz', 'rok' => 'Rok', 'mesic' => 'Měsíc', ]; } public function types(): array { return [ 'akce' => self::FIELD_INPUT, 'rok' => self::FIELD_INPUT, 'mesic' => self::FIELD_INPUT, 'id' => self::FIELD_HIDDEN, ]; } public function attributes(): array { return ['akce', 'idrok', 'mesic', 'idrok', 'id']; } public function seznamAkci() { $akce = Application::$app->db->fetchAll('SELECT `sr_akce`.`id`, `sr_akce`.`akce`, `jak_roky`.`rok`, `sr_akce`.`mesic` FROM `sr_akce` LEFT JOIN `jak_roky` on `sr_akce`.`idrok`=`jak_roky`.`id` ORDER BY `rok` desc, `mesic` desc'); return $akce; } public function akceDetail($data) { $data = json_decode($data); if ($data->id == 0){ $return = new \stdClass; $return->id = 0; $return->akce = null; $return->idrok = $this->idAktualniRok; $return->rok = $this->aktualniRok; $return->mesic = $this->aktualniMesic; } else { $return = Application::$app->db->fetchOne("SELECT `sr_akce`.`id`, `sr_akce`.`akce`, `jak_roky`.`rok`, `jak_roky`.`id` as 'idrok', `sr_akce`.`mesic` FROM `sr_akce` LEFT JOIN `jak_roky` on `sr_akce`.`idrok`=`jak_roky`.`id` WHERE `sr_akce`.`id` = :id", $data->id); } return $return; } public function akceDetailSave($data) { $data = json_decode($data); if ($data->id) { Application::$app->db->query("UPDATE `sr_akce` SET `akce` = :akce, `mesic` = :mesic WHERE `id` = :id", $data->akce, $data->mesic, $data->id); } else { Application::$app->db->query("INSERT INTO `sr_akce`(`akce`, `idrok`, `mesic`) VALUES (:akce, :idrok, :mesic)", $data->akce, $this->idAktualniRok, $data->mesic); $data->id = Application::$app->db->lastInsertId(); } return $data; } public function akceVyberyTridy() { $funkce = new Funkce; $tridy = Application::$app->db->fetchAll("SELECT distinct `trida` FROM `zaci` WHERE `idskolnirok`= :idskolnirok order by `trida`", $this->idAktualniRok); foreach ($tridy as &$trida) { $trida->tridaAnchor = $funkce->urlEncrypt($trida->trida); } return $tridy; } public function akceVyberyZaci($trida, $idakce) { $sql = "SELECT `zaci`.`id`, `zaci`.`prijmeni`, `zaci`.`jmeno`, sum(`sr_zaci_pohyby`.`castka`) as castka FROM `zaci` LEFT JOIN `sr_zaci_pohyby` on `sr_zaci_pohyby`.`idzak`= `zaci`.`id` and `sr_zaci_pohyby`.`idakce`=:idakce WHERE `zaci`.`trida`=:trida and `zaci`.`idskolnirok`=:idskolnirok and `zaci`.`aktivni`='1' GROUP BY `zaci`.`id` ORDER BY `zaci`.`prijmeni`, `zaci`.`jmeno`"; return Application::$app->db->fetchAll($sql, $idakce, $trida, $this->idAktualniRok); } public function cashPodminky($data) { $return = new \stdClass(); $sql = "SELECT `akce`, `jak_roky`.`rok`, `mesic` FROM `sr_akce` left join `jak_roky` on `jak_roky`.`id`= `sr_akce`.`idrok` WHERE `sr_akce`.`id` = :idakce"; $return->akce = Application::$app->db->fetchOne($sql, $data->idakce); $return->zak = Application::$app->db->fetchOne("SELECT `trida`, `prijmeni`, `jmeno`FROM `zaci` WHERE `id` = :id", $data->idzak); return $return; } public function zaciPohyby($data) { $return = new \stdClass(); $return->zak = Application::$app->db->fetchOne("SELECT `trida`, `prijmeni`, `jmeno`FROM `zaci` WHERE `id` = :id", $data->idzak); $sql = "SELECT `sr_zaci_pohyby`.`id`, `pohybtyp`, `sr_zaci_pohyby`.`castka`, `pridano` , `sr_vypisy_polozky`.`dattransakce`, `sr_vypisy_polozky`.`VS` FROM `sr_zaci_pohyby` LEFT JOIN `sr_vypisy_polozky` on `sr_zaci_pohyby`.`idvypisypolozky` = `sr_vypisy_polozky`.`id` WHERE `idzak` = :idzak and `idakce` = :idakce"; $return->pohyby = Application::$app->db->fetchAll($sql, $data->idzak, $data->idakce); return $return; } public function akce($idakce) { return Application::$app->db->fetchone("SELECT akce from sr_akce where id=:id", $idakce)->akce; } }