-- phpMyAdmin SQL Dump
-- version 4.5.1
-- http://www.phpmyadmin.net
--
-- Hostiteľ: 127.0.0.1
-- Čas generovania: Ne 15.Máj 2016, 15:12
-- Verzia serveru: 10.1.9-MariaDB
-- Verzia PHP: 5.5.30

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Databáza: `bakalarkadb`
--

DELIMITER $$
--
-- Procedúry
--
CREATE DEFINER=`root`@`localhost` PROCEDURE `skontrolujAktivitu` (IN `id_zam` INT(12))  BEGIN
    DECLARE numbAbsInv INTEGER;
    SET numbAbsInv = 0;
    SELECT COUNT(ID_REP) INTO numbAbsInv FROM report_zoznam 
    WHERE report_zoznam.id_zam=id_zam AND ((report_zoznam.Nastup LIKE CONCAT(YEAR(NOW()),"-",MONTH(NOW()),"%")) OR (report_zoznam.Nastup LIKE CONCAT(YEAR(NOW()),"-0",MONTH(NOW()),"%"))) ;    
	IF (numbAbsInv<3) THEN UPDATE zamestnanec SET zamestnanec.Status=0 WHERE zamestnanec.ID_ZAM=id_zam;
    END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `zmenNaNeaktivneho` (IN `id_zam` INT)  NO SQL
BEGIN
UPDATE zamestnanec SET zamestnanec.Status=0 WHERE zamestnanec.ID_ZAM=id_zam;
END$$

DELIMITER ;

-- --------------------------------------------------------

--
-- Štruktúra tabuľky pre tabuľku `bankove_spojenie`
--

CREATE TABLE `bankove_spojenie` (
  `ID_B_SPOJ` int(11) NOT NULL,
  `ID_ZAM` int(11) NOT NULL,
  `Cislo_uctu` int(11) NOT NULL,
  `Kod_banky` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin2 COLLATE=latin2_czech_cs;

-- --------------------------------------------------------

--
-- Štruktúra tabuľky pre tabuľku `cesty`
--

CREATE TABLE `cesty` (
  `ID_REZ` int(11) NOT NULL,
  `ID_ZAM` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin2 COLLATE=latin2_czech_cs;

-- --------------------------------------------------------

--
-- Štruktúra tabuľky pre tabuľku `hlasenie`
--

CREATE TABLE `hlasenie` (
  `ID_HLA` int(11) NOT NULL,
  `Predmet` varchar(50) COLLATE latin2_czech_cs NOT NULL,
  `Hlasenie` varchar(255) COLLATE latin2_czech_cs NOT NULL,
  `ID_ZAM` int(11) NOT NULL,
  `Datum_podania` datetime NOT NULL,
  `Status` int(4) NOT NULL,
  `Datum_vyriesenia` datetime DEFAULT NULL,
  `Vyriesil` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin2 COLLATE=latin2_czech_cs;

-- --------------------------------------------------------

--
-- Štruktúra tabuľky pre tabuľku `inventura`
--

CREATE TABLE `inventura` (
  `ID_INV` int(11) NOT NULL,
  `ID_TYP_R` int(11) NOT NULL,
  `ID_Zakaznika` int(11) NOT NULL,
  `ID_Veduci` int(11) DEFAULT NULL,
  `ID_Report` int(11) DEFAULT NULL,
  `Vzdialenost` int(11) NOT NULL,
  `Pocet_zamestnancov` int(11) NOT NULL,
  `Cas_cesty` time NOT NULL,
  `Datum_prihlasovania` datetime NOT NULL,
  `Datum_zaciatku` datetime NOT NULL,
  `Datum_konca` datetime NOT NULL,
  `Status` int(2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin2 COLLATE=latin2_czech_cs;

-- --------------------------------------------------------

--
-- Štruktúra tabuľky pre tabuľku `nastavenia`
--

CREATE TABLE `nastavenia` (
  `ID_nastavenia` int(11) NOT NULL,
  `Datum_nastavenia` datetime NOT NULL,
  `Vyplata_veduci_inventury` int(11) NOT NULL,
  `Vyplata_sofer` int(11) NOT NULL,
  `Vyplata_zamestnanec` int(11) NOT NULL,
  `Vyplata_kilometer` double NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin2 COLLATE=latin2_czech_cs;

-- --------------------------------------------------------

--
-- Štruktúra tabuľky pre tabuľku `poistovna`
--

CREATE TABLE `poistovna` (
  `ID_POIST` int(11) NOT NULL,
  `Nazov_poistovne` varchar(50) COLLATE latin2_czech_cs NOT NULL,
  `Kod_poistovne` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin2 COLLATE=latin2_czech_cs;

-- --------------------------------------------------------

--
-- Štruktúra tabuľky pre tabuľku `report`
--

CREATE TABLE `report` (
  `ID_REP` int(11) NOT NULL,
  `Vlozene` datetime NOT NULL,
  `Poznamka` varchar(255) COLLATE latin2_czech_cs NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin2 COLLATE=latin2_czech_cs;

-- --------------------------------------------------------

--
-- Štruktúra tabuľky pre tabuľku `report_zoznam`
--

CREATE TABLE `report_zoznam` (
  `ID_REP` int(11) DEFAULT NULL,
  `ID_ZAM` int(11) NOT NULL,
  `Nastup` datetime DEFAULT NULL,
  `Koniec` datetime NOT NULL,
  `Prestavka` time DEFAULT NULL,
  `Vyplatene` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin2 COLLATE=latin2_czech_cs;

-- --------------------------------------------------------

--
-- Štruktúra tabuľky pre tabuľku `rezervacia`
--

CREATE TABLE `rezervacia` (
  `ID_REZ` int(11) NOT NULL,
  `ID_INV` int(11) NOT NULL,
  `ID_VOZ` int(11) NOT NULL,
  `ID_SOF` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin2 COLLATE=latin2_czech_cs;

-- --------------------------------------------------------

--
-- Štruktúra tabuľky pre tabuľku `rozloha`
--

CREATE TABLE `rozloha` (
  `ID_TYP_R` int(11) NOT NULL,
  `Nazov_rozloha` varchar(30) COLLATE latin2_czech_cs NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin2 COLLATE=latin2_czech_cs;

-- --------------------------------------------------------

--
-- Štruktúra tabuľky pre tabuľku `typ_obchodu`
--

CREATE TABLE `typ_obchodu` (
  `ID_TYP_I` int(11) NOT NULL,
  `Nazov_typ_obchodu` varchar(30) COLLATE latin2_czech_cs NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin2 COLLATE=latin2_czech_cs;

-- --------------------------------------------------------

--
-- Štruktúra tabuľky pre tabuľku `typ_zamestnanca`
--

CREATE TABLE `typ_zamestnanca` (
  `ID_TYP_Z` int(11) NOT NULL,
  `Nazov` varchar(30) COLLATE latin2_czech_cs NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin2 COLLATE=latin2_czech_cs;

-- --------------------------------------------------------

--
-- Štruktúra tabuľky pre tabuľku `vozidlo`
--

CREATE TABLE `vozidlo` (
  `ID_VOZ` int(11) NOT NULL,
  `Nazov` varchar(50) COLLATE latin2_czech_cs NOT NULL,
  `SPZ` varchar(9) COLLATE latin2_czech_cs NOT NULL,
  `Pocet_miest` int(11) NOT NULL,
  `Status_vozidla` int(2) NOT NULL DEFAULT '1',
  `Typ_vozidla` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin2 COLLATE=latin2_czech_cs;

-- --------------------------------------------------------

--
-- Štruktúra tabuľky pre tabuľku `zakaznik`
--

CREATE TABLE `zakaznik` (
  `ID_Zakaznik` int(11) NOT NULL,
  `ID_TYP_I` int(11) NOT NULL,
  `Nazov_spolocnosti` varchar(100) COLLATE latin2_czech_cs NOT NULL,
  `Mesto` varchar(50) COLLATE latin2_czech_cs NOT NULL,
  `Ulica` varchar(50) COLLATE latin2_czech_cs NOT NULL,
  `Cislo` varchar(20) COLLATE latin2_czech_cs NOT NULL,
  `PSC` varchar(5) COLLATE latin2_czech_cs NOT NULL,
  `GPS` varchar(50) COLLATE latin2_czech_cs DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin2 COLLATE=latin2_czech_cs;

-- --------------------------------------------------------

--
-- Štruktúra tabuľky pre tabuľku `zamestnanec`
--

CREATE TABLE `zamestnanec` (
  `ID_ZAM` int(11) NOT NULL,
  `ID_TYP_Z` int(5) DEFAULT NULL,
  `ID_POIST` int(11) DEFAULT NULL,
  `Rodne_cislo` varchar(11) COLLATE latin2_czech_cs NOT NULL,
  `Meno` varchar(50) COLLATE latin2_czech_cs NOT NULL,
  `Priezvisko` varchar(50) COLLATE latin2_czech_cs NOT NULL,
  `Mesto_zamestnanca` varchar(50) COLLATE latin2_czech_cs DEFAULT NULL,
  `Ulica_zamestnanca` varchar(50) COLLATE latin2_czech_cs DEFAULT NULL,
  `Cislo_domu_zamestnanca` varchar(20) COLLATE latin2_czech_cs DEFAULT NULL,
  `PSC_zamestnanca` varchar(5) COLLATE latin2_czech_cs DEFAULT NULL,
  `Tel_cislo_zamestnanca` int(9) DEFAULT NULL,
  `Email` varchar(50) COLLATE latin2_czech_cs NOT NULL,
  `password` varchar(50) COLLATE latin2_czech_cs NOT NULL,
  `Prijaty` date DEFAULT NULL,
  `Prepusteny` date DEFAULT NULL,
  `Status` int(3) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=latin2 COLLATE=latin2_czech_cs;

-- --------------------------------------------------------

--
-- Štruktúra tabuľky pre tabuľku `zoznam_prihlasenych`
--

CREATE TABLE `zoznam_prihlasenych` (
  `ID_INV` int(11) NOT NULL,
  `ID_ZAM` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin2 COLLATE=latin2_czech_cs;

--
-- Kľúče pre exportované tabuľky
--

--
-- Indexy pre tabuľku `bankove_spojenie`
--
ALTER TABLE `bankove_spojenie`
  ADD PRIMARY KEY (`ID_B_SPOJ`),
  ADD UNIQUE KEY `ID_ZAM` (`ID_ZAM`);

--
-- Indexy pre tabuľku `cesty`
--
ALTER TABLE `cesty`
  ADD KEY `ID_REZ` (`ID_REZ`),
  ADD KEY `ID_ZAM` (`ID_ZAM`);

--
-- Indexy pre tabuľku `hlasenie`
--
ALTER TABLE `hlasenie`
  ADD PRIMARY KEY (`ID_HLA`),
  ADD KEY `ID_ZAM` (`ID_ZAM`),
  ADD KEY `Vyriesil` (`Vyriesil`);

--
-- Indexy pre tabuľku `inventura`
--
ALTER TABLE `inventura`
  ADD PRIMARY KEY (`ID_INV`),
  ADD KEY `ID_TYP_R` (`ID_TYP_R`),
  ADD KEY `ID_Zakaznika` (`ID_Zakaznika`),
  ADD KEY `ID_Veduci` (`ID_Veduci`),
  ADD KEY `ID_INV` (`ID_INV`),
  ADD KEY `ID_Report` (`ID_Report`);

--
-- Indexy pre tabuľku `nastavenia`
--
ALTER TABLE `nastavenia`
  ADD PRIMARY KEY (`ID_nastavenia`);

--
-- Indexy pre tabuľku `poistovna`
--
ALTER TABLE `poistovna`
  ADD PRIMARY KEY (`ID_POIST`),
  ADD KEY `ID_POIST` (`ID_POIST`);

--
-- Indexy pre tabuľku `report`
--
ALTER TABLE `report`
  ADD PRIMARY KEY (`ID_REP`),
  ADD UNIQUE KEY `ID_REP_2` (`ID_REP`),
  ADD KEY `ID_REP` (`ID_REP`),
  ADD KEY `ID_REP_3` (`ID_REP`),
  ADD KEY `ID_REP_4` (`ID_REP`);

--
-- Indexy pre tabuľku `report_zoznam`
--
ALTER TABLE `report_zoznam`
  ADD KEY `ID_REP` (`ID_REP`),
  ADD KEY `ID_ZAM` (`ID_ZAM`);

--
-- Indexy pre tabuľku `rezervacia`
--
ALTER TABLE `rezervacia`
  ADD PRIMARY KEY (`ID_REZ`),
  ADD KEY `ID_VOZ` (`ID_VOZ`),
  ADD KEY `ID_REZ` (`ID_REZ`),
  ADD KEY `ID_Sofer` (`ID_SOF`),
  ADD KEY `ID_INV` (`ID_INV`);

--
-- Indexy pre tabuľku `rozloha`
--
ALTER TABLE `rozloha`
  ADD PRIMARY KEY (`ID_TYP_R`),
  ADD UNIQUE KEY `ID_TYP_R` (`ID_TYP_R`),
  ADD KEY `ID_TYP_R_2` (`ID_TYP_R`);

--
-- Indexy pre tabuľku `typ_obchodu`
--
ALTER TABLE `typ_obchodu`
  ADD PRIMARY KEY (`ID_TYP_I`),
  ADD UNIQUE KEY `ID_TYP_I` (`ID_TYP_I`),
  ADD KEY `ID_TYP_I_2` (`ID_TYP_I`);

--
-- Indexy pre tabuľku `typ_zamestnanca`
--
ALTER TABLE `typ_zamestnanca`
  ADD PRIMARY KEY (`ID_TYP_Z`),
  ADD KEY `ID_TYP_Z` (`ID_TYP_Z`);

--
-- Indexy pre tabuľku `vozidlo`
--
ALTER TABLE `vozidlo`
  ADD PRIMARY KEY (`ID_VOZ`),
  ADD UNIQUE KEY `ID_Vozidlo_2` (`ID_VOZ`),
  ADD KEY `ID_Vozidlo` (`ID_VOZ`);

--
-- Indexy pre tabuľku `zakaznik`
--
ALTER TABLE `zakaznik`
  ADD PRIMARY KEY (`ID_Zakaznik`),
  ADD UNIQUE KEY `ID_zakaznik_2` (`ID_Zakaznik`),
  ADD KEY `ID_zakaznik` (`ID_Zakaznik`),
  ADD KEY `ID_TYP_I` (`ID_TYP_I`);

--
-- Indexy pre tabuľku `zamestnanec`
--
ALTER TABLE `zamestnanec`
  ADD PRIMARY KEY (`ID_ZAM`),
  ADD KEY `ID_TYP_Z` (`ID_TYP_Z`),
  ADD KEY `ID_ZAM` (`ID_ZAM`),
  ADD KEY `ID_POIST` (`ID_POIST`),
  ADD KEY `ID_POIST_2` (`ID_POIST`),
  ADD KEY `ID_POIST_3` (`ID_POIST`);

--
-- Indexy pre tabuľku `zoznam_prihlasenych`
--
ALTER TABLE `zoznam_prihlasenych`
  ADD KEY `ID_INV` (`ID_INV`),
  ADD KEY `ID_ZAM` (`ID_ZAM`);

--
-- AUTO_INCREMENT pre exportované tabuľky
--

--
-- AUTO_INCREMENT pre tabuľku `bankove_spojenie`
--
ALTER TABLE `bankove_spojenie`
  MODIFY `ID_B_SPOJ` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11;
--
-- AUTO_INCREMENT pre tabuľku `hlasenie`
--
ALTER TABLE `hlasenie`
  MODIFY `ID_HLA` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11;
--
-- AUTO_INCREMENT pre tabuľku `inventura`
--
ALTER TABLE `inventura`
  MODIFY `ID_INV` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=142;
--
-- AUTO_INCREMENT pre tabuľku `nastavenia`
--
ALTER TABLE `nastavenia`
  MODIFY `ID_nastavenia` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
--
-- AUTO_INCREMENT pre tabuľku `poistovna`
--
ALTER TABLE `poistovna`
  MODIFY `ID_POIST` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
--
-- AUTO_INCREMENT pre tabuľku `report`
--
ALTER TABLE `report`
  MODIFY `ID_REP` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=44;
--
-- AUTO_INCREMENT pre tabuľku `rezervacia`
--
ALTER TABLE `rezervacia`
  MODIFY `ID_REZ` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=178;
--
-- AUTO_INCREMENT pre tabuľku `rozloha`
--
ALTER TABLE `rozloha`
  MODIFY `ID_TYP_R` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;
--
-- AUTO_INCREMENT pre tabuľku `typ_obchodu`
--
ALTER TABLE `typ_obchodu`
  MODIFY `ID_TYP_I` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=13;
--
-- AUTO_INCREMENT pre tabuľku `vozidlo`
--
ALTER TABLE `vozidlo`
  MODIFY `ID_VOZ` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=14;
--
-- AUTO_INCREMENT pre tabuľku `zakaznik`
--
ALTER TABLE `zakaznik`
  MODIFY `ID_Zakaznik` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=74;
--
-- AUTO_INCREMENT pre tabuľku `zamestnanec`
--
ALTER TABLE `zamestnanec`
  MODIFY `ID_ZAM` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=39;
--
-- Obmedzenie pre exportované tabuľky
--

--
-- Obmedzenie pre tabuľku `bankove_spojenie`
--
ALTER TABLE `bankove_spojenie`
  ADD CONSTRAINT `bankove_spojenie_ibfk_1` FOREIGN KEY (`ID_ZAM`) REFERENCES `zamestnanec` (`ID_ZAM`);

--
-- Obmedzenie pre tabuľku `cesty`
--
ALTER TABLE `cesty`
  ADD CONSTRAINT `cesty_ibfk_1` FOREIGN KEY (`ID_REZ`) REFERENCES `rezervacia` (`ID_REZ`),
  ADD CONSTRAINT `cesty_ibfk_2` FOREIGN KEY (`ID_ZAM`) REFERENCES `zamestnanec` (`ID_ZAM`);

--
-- Obmedzenie pre tabuľku `hlasenie`
--
ALTER TABLE `hlasenie`
  ADD CONSTRAINT `hlasenie_ibfk_1` FOREIGN KEY (`ID_ZAM`) REFERENCES `zamestnanec` (`ID_ZAM`),
  ADD CONSTRAINT `hlasenie_ibfk_2` FOREIGN KEY (`Vyriesil`) REFERENCES `zamestnanec` (`ID_ZAM`);

--
-- Obmedzenie pre tabuľku `inventura`
--
ALTER TABLE `inventura`
  ADD CONSTRAINT `inventura_ibfk_1` FOREIGN KEY (`ID_Zakaznika`) REFERENCES `zakaznik` (`ID_zakaznik`),
  ADD CONSTRAINT `inventura_ibfk_2` FOREIGN KEY (`ID_Veduci`) REFERENCES `zamestnanec` (`ID_ZAM`),
  ADD CONSTRAINT `inventura_ibfk_3` FOREIGN KEY (`ID_TYP_R`) REFERENCES `rozloha` (`ID_TYP_R`),
  ADD CONSTRAINT `inventura_ibfk_4` FOREIGN KEY (`ID_Report`) REFERENCES `report` (`ID_REP`);

--
-- Obmedzenie pre tabuľku `report_zoznam`
--
ALTER TABLE `report_zoznam`
  ADD CONSTRAINT `report_zoznam_ibfk_1` FOREIGN KEY (`ID_REP`) REFERENCES `report` (`ID_REP`),
  ADD CONSTRAINT `report_zoznam_ibfk_2` FOREIGN KEY (`ID_ZAM`) REFERENCES `zamestnanec` (`ID_ZAM`);

--
-- Obmedzenie pre tabuľku `rezervacia`
--
ALTER TABLE `rezervacia`
  ADD CONSTRAINT `rezervacia_ibfk_1` FOREIGN KEY (`ID_VOZ`) REFERENCES `vozidlo` (`ID_VOZ`),
  ADD CONSTRAINT `rezervacia_ibfk_2` FOREIGN KEY (`ID_SOF`) REFERENCES `zamestnanec` (`ID_ZAM`),
  ADD CONSTRAINT `rezervacia_ibfk_3` FOREIGN KEY (`ID_INV`) REFERENCES `inventura` (`ID_INV`);

--
-- Obmedzenie pre tabuľku `zakaznik`
--
ALTER TABLE `zakaznik`
  ADD CONSTRAINT `zakaznik_ibfk_1` FOREIGN KEY (`ID_TYP_I`) REFERENCES `typ_obchodu` (`ID_TYP_I`);

--
-- Obmedzenie pre tabuľku `zamestnanec`
--
ALTER TABLE `zamestnanec`
  ADD CONSTRAINT `zamestnanec_ibfk_1` FOREIGN KEY (`ID_TYP_Z`) REFERENCES `typ_zamestnanca` (`ID_TYP_Z`),
  ADD CONSTRAINT `zamestnanec_ibfk_2` FOREIGN KEY (`ID_POIST`) REFERENCES `poistovna` (`ID_POIST`);

--
-- Obmedzenie pre tabuľku `zoznam_prihlasenych`
--
ALTER TABLE `zoznam_prihlasenych`
  ADD CONSTRAINT `zoznam_prihlasenych_ibfk_1` FOREIGN KEY (`ID_INV`) REFERENCES `inventura` (`ID_INV`),
  ADD CONSTRAINT `zoznam_prihlasenych_ibfk_2` FOREIGN KEY (`ID_ZAM`) REFERENCES `zamestnanec` (`ID_ZAM`);

DELIMITER $$
--
-- Udalosti
--
CREATE DEFINER=`root`@`localhost` EVENT `skontroluj_aktivitu` ON SCHEDULE EVERY 1 MONTH STARTS '2017-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN
DECLARE id_zam INT DEFAULT 0;
DECLARE koniec INT DEFAULT 0;
DECLARE kurzor CURSOR FOR SELECT zamestnanec.ID_ZAM FROM zamestnanec WHERE zamestnanec.ID_TYP_Z>1 AND zamestnanec.Status=1; 
DECLARE CONTINUE HANDLER FOR NOT FOUND SET koniec = 1;

OPEN kurzor;

REPEAT
	FETCH kurzor INTO id_zam;
    IF NOT koniec THEN
    	CALL skontrolujAktivitu(id_zam);
    END IF;
UNTIL koniec END REPEAT;

CLOSE kurzor;
END$$

DELIMITER ;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
