INSERT INTO `form` (`id`, `nazov`, `code`)
VALUES
  (4, 'Zmluva', 'zmluva'),
  (5, 'Položka zmluvy', 'polozka_zmluvy');

INSERT INTO `form_group` (`id`, `form_id`, `nazov`, `code`, `position`, `poznamka`, `group_type`)
VALUES
  (11, 4, 'Základné informácie', 'zmluva_zakladne_informacie', 10, NULL, 1),
  (12, 4, 'Rozšírené informácie', 'zmluva_rozsirene_informacie', 20, NULL, 1),
  (13, 5, 'Položka zmluvy', 'polozka_zmluvy', 10, NULL, 1);

INSERT INTO `form_element` (`id`, `form_group_id`, `form_element_type_id`, `db_table`, `db_column`, `db_multi_table`, `db_multivalue_table`, `column_title`, `position`, `attribute`, `width`, `height`, `help`, `example`, `direct_to_db`, `required`, `number`, `float_number`, `email`, `css_style`, `css_class`, `javascript`, `direct_multi_label`, `direct_multi_data`, `default_val`, `vdaemon`, `add_empty_option`, `html`, `lang_code`, `read_only`)
VALUES
  (52, 11, 1, 'zmluva', 'cislo', NULL, NULL, 'Číslo', 10, NULL, NULL, NULL, NULL, NULL, 1, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '<vlvalidator name=\"customCislo\" type=\"custom\" function=\"vdaemonCislo\" />', NULL, NULL, NULL, NULL),
  (53, 11, 5, 'zmluva', 'obchodny_partner_id', 'obchodny_partner', NULL, 'Obchodný partner', 20, NULL, NULL, NULL, NULL, NULL, 1, 1, NULL, NULL, NULL, NULL, 'select2', NULL, 1, NULL, NULL, NULL, 1, NULL, NULL, NULL),
  (54, 11, 5, 'zmluva', 'vytvoril_id', 'zamestnanec', NULL, 'Vytvoril', 30, NULL, NULL, NULL, NULL, NULL, 0, 1, NULL, NULL, NULL, NULL, 'select2', NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, 1),
  (55, 11, 4, 'zmluva', 'datum_vytvorenia', NULL, NULL, 'Dátum vytvorenia', 40, NULL, NULL, NULL, NULL, NULL, 1, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'NOW', NULL, NULL, NULL, NULL, NULL),
  (56, 11, 4, 'zmluva', 'platnost_od', NULL, NULL, 'Dátum platnosti od', 50, NULL, NULL, NULL, NULL, NULL, 1, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
  (57, 11, 4, 'zmluva', 'platnost_do', NULL, NULL, 'Dátum platnosti do', 60, NULL, NULL, NULL, NULL, NULL, 1, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
  (58, 11, 5, 'zmluva', 'stav_zmluvy_id', 'stav_zmluvy', NULL, 'Stav zmluvy', 70, NULL, NULL, NULL, NULL, NULL, 1, 1, NULL, NULL, NULL, NULL, 'select2', NULL, 1, NULL, '1', NULL, NULL, NULL, NULL, NULL),
  (59, 12, 5, 'zmluva', 'perioda_fakturacie_id', 'perioda_opakovania', NULL, 'Periodicita fakturácie', 10, NULL, NULL, NULL, NULL, NULL, 1, 1, NULL, NULL, NULL, NULL, 'select2', NULL, 1, NULL, NULL, NULL, 1, NULL, NULL, NULL),
  (60, 12, 9, 'zmluva', 'pobocka_id', 'pobocka', NULL, 'Pobočka', 20, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, 'select2', NULL, 1, 1, NULL, NULL, NULL, NULL, NULL, NULL),
  (61, 13, 13, 'polozka_zmluvy', 'zmluva_id', NULL, NULL, 'Zmluva', 10, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
  (62, 13, 1, 'polozka_zmluvy', 'nazov', NULL, NULL, 'Názov', 20, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
  (63, 13, 2, 'polozka_zmluvy', 'popis', NULL, NULL, 'Popis', 30, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

INSERT INTO `log_type` (`id`, `nazov`, `code`, `primary_table`)
VALUES
  (41, 'Pridanie zmluvy', 'zmluva_pridaj', NULL),
  (42, 'Editovanie zmluvy', 'zmluva_edituj', NULL),
  (43, 'Zmazanie zmluvy', 'zmluva_zmaz', NULL),
  (44, 'Pridanie položky zmluvy', 'polozka_zmluvy_pridaj', NULL),
  (45, 'Editovanie položky zmluvy', 'polozka_zmluvy_edituj', NULL),
  (46, 'Zmazanie položky zmluvy', 'polozka_zmluvy_zmaz', NULL);

CREATE TABLE `stav_zmluvy` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `nazov` varchar(45) DEFAULT NULL,
  `code` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

INSERT INTO `stav_zmluvy` (`id`, `nazov`, `code`)
VALUES
  (1, 'Rozpracovaná', 'rozpracovana'),
  (2, 'Aktívna', 'aktivna'),
  (3, 'Zrušená', 'zrusena');

CREATE TABLE `zmluva` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `obchodny_partner_id` int(11) unsigned DEFAULT NULL,
  `nazov` varchar(255) DEFAULT NULL,
  `cislo` int(11) DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  `visibility_type` tinyint(1) DEFAULT NULL,
  `vytvoril_id` int(11) DEFAULT NULL,
  `datum_vytvorenia` date DEFAULT NULL,
  `platnost_od` date DEFAULT NULL,
  `platnost_do` date DEFAULT NULL,
  `perioda_fakturacie_id` int(11) DEFAULT NULL,
  `stav_zmluvy_id` int(11) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `FK1_obchodny_partner_id` (`obchodny_partner_id`),
  KEY `FK1_perioda_fakturacie_id` (`perioda_fakturacie_id`),
  KEY `FK_stav_zmluvy_id` (`stav_zmluvy_id`),
  CONSTRAINT `FK1_obchodny_partner_id` FOREIGN KEY (`obchodny_partner_id`) REFERENCES `obchodny_partner` (`id`),
  CONSTRAINT `FK1_perioda_fakturacie_id` FOREIGN KEY (`perioda_fakturacie_id`) REFERENCES `perioda_opakovania` (`id`),
  CONSTRAINT `FK_stav_zmluvy_id` FOREIGN KEY (`stav_zmluvy_id`) REFERENCES `stav_zmluvy` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;

CREATE TABLE `polozka_zmluvy` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `zmluva_id` int(11) unsigned DEFAULT NULL,
  `visibility_type` tinyint(1) DEFAULT NULL,
  `nazov` varchar(255) DEFAULT NULL,
  `popis` text,
  PRIMARY KEY (`id`),
  KEY `FK1_zmluva_id` (`zmluva_id`),
  CONSTRAINT `FK1_zmluva_id` FOREIGN KEY (`zmluva_id`) REFERENCES `zmluva` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8;

CREATE TABLE `zmluva_pobocka` (
  `zmluva_id` int(11) NOT NULL,
  `pobocka_id` int(11) NOT NULL,
  PRIMARY KEY (`zmluva_id`,`pobocka_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `menu` (`id`, `menu_id`, `nazov`, `page`, `poradie`, `level`, `visibility_type`)
VALUES
  (1, NULL, 'Zmluvy', 'zmluva', 110, 1, 1),
  (2, 1, 'Výpis zmlúv', 'zmluva_vypis', 10, 2, 1),
  (3, 1, 'Pridanie zmluvy', 'zmluva_pridaj', 20, 2, 1),
  (4, 2, 'Detail zmluvy', 'zmluva_view', 10, 3, 1),
  (5, 2, 'Editovanie zmluvy', 'zmluva_edituj', 20, 3, 1),
  (6, 2, 'Zmazanie zmluvy', 'zmluva_zmaz', 30, 3, 0),
  (7, 2, 'Editovanie položky zmluvy', 'polozka_zmluvy_edituj', 0, 3, 0),
  (8, 2, 'Zmazanie položky zmluvy', 'polozka_zmluvy_zmaz', 0, 3, 0),
  (9, 2, 'Pridanie položky zmluvy', 'polozka_zmluvy_pridaj', 0, 3, 0);

/* 06:20:04 */ INSERT INTO `menu` (`id`, `menu_id`, `nazov`, `page`, `poradie`, `level`, `visibility_type`) VALUES ('11', '26001', 'Zmluvy', 'obchodny_partner_zmluva', '50', '3', '1');
/* 06:26:48 */ INSERT INTO `menu` (`id`, `menu_id`, `nazov`, `page`, `poradie`, `level`, `visibility_type`) VALUES ('12', '2', 'Súbory', 'zmluva_subor', '40', '3', '1');
/* 06:30:52 */ INSERT INTO `priradenie_suboru` (`id`, `nazov`, `code`) VALUES ('2', 'Zmluva', 'zmluva');

/* 08:53:10 */ INSERT INTO `form_element` (`id`, `form_group_id`, `form_element_type_id`, `db_table`, `db_column`, `db_multi_table`, `db_multivalue_table`, `column_title`, `position`, `attribute`, `width`, `height`, `help`, `example`, `direct_to_db`, `required`, `number`, `float_number`, `email`, `css_style`, `css_class`, `javascript`, `direct_multi_label`, `direct_multi_data`, `default_val`, `vdaemon`, `add_empty_option`, `html`, `lang_code`, `read_only`) VALUES ('65', '33001', '9', 'uloha', 'zmluva_id', 'zmluva', NULL, 'Zmluva', '30', NULL, NULL, NULL, NULL, NULL, '1', NULL, NULL, NULL, NULL, NULL, 'select2', NULL, '1', '1', NULL, NULL, NULL, NULL, NULL, NULL);
CREATE TABLE `uloha_zmluva` (
  `uloha_id` int(11) unsigned NOT NULL,
  `zmluva_id` int(11) unsigned NOT NULL,
  PRIMARY KEY (`uloha_id`,`zmluva_id`),
  KEY `FK1_uloha_zmluva` (`zmluva_id`),
  CONSTRAINT `FK1_uloha_zmluva` FOREIGN KEY (`zmluva_id`) REFERENCES `zmluva` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;