INSERT INTO `form` (`id`, `nazov`, `code`) VALUES (260, 'Obchodný partner', 'obchodny_partner');
INSERT INTO `form` (`id`, `nazov`, `code`) VALUES (261, 'Kategória obchodného partnera', 'kategoria_obchodneho_partnera');

INSERT INTO `form_group` (`id`, `form_id`, `nazov`, `code`, `position`, `poznamka`, `group_type`) VALUES (26000, 260, 'Základné informácie', 'obchodny_partner_zakladne_informacie', 10, NULL, 1);
INSERT INTO `form_group` (`id`, `form_id`, `nazov`, `code`, `position`, `poznamka`, `group_type`) VALUES (26100, 261, 'Základné informácie', 'kategoria_obchodneho_partnera_zakladne_informacie', 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 (26000, 26000, 1, 'obchodny_partner', 'nazov', NULL, NULL, 'Názov', 10, NULL, NULL, NULL, NULL, NULL, 1, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '<vlvalidator name="customObchodnyPartner" type="custom" function="vdaemonObchodnyPartner" />', NULL, NULL, NULL, NULL);
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 (26001, 26000, 5, 'obchodny_partner', 'typ_obchodneho_partnera_id', 'typ_obchodneho_partnera', NULL, 'Typ', 20, NULL, NULL, NULL, NULL, NULL, 1, 1, NULL, NULL, NULL, NULL, 'select2', NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
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 (26002, 26000, 1, 'obchodny_partner', 'ulica', NULL, NULL, 'Ulica', 30, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
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 (26003, 26000, 1, 'obchodny_partner', 'obec', NULL, NULL, 'Obec', 40, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
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 (26004, 26000, 1, 'obchodny_partner', 'psc', NULL, NULL, 'PSČ', 50, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
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 (26005, 26000, 5, 'obchodny_partner', 'stat_id', 'stat', NULL, 'Štát', 60, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, 'select2', NULL, 1, NULL, '1', NULL, 1, NULL, NULL, NULL);
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 (26006, 26000, 1, 'obchodny_partner', 'ico', NULL, NULL, 'IČO', 70, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
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 (26007, 26000, 1, 'obchodny_partner', 'dic', NULL, NULL, 'DIČ', 80, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
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 (26008, 26000, 1, 'obchodny_partner', 'ic_dph', NULL, NULL, 'IČ DPH', 90, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
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 (26009, 26000, 3, 'obchodny_partner', 'platca_dph', NULL, NULL, 'Platca DPH', 100, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
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 (26010, 26000, 9, 'obchodny_partner', 'kategoria_obchodneho_partnera_id', 'kategoria_obchodneho_partnera', NULL, 'Kategória', 110, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, 'select2', NULL, 1, 1, NULL, NULL, NULL, NULL, NULL, NULL);
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 (26100, 26100, 1, 'kategoria_obchodneho_partnera', 'nazov', NULL, NULL, 'Názov', 10, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

CREATE TABLE `kategoria_obchodneho_partnera` (
	`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
	`nazov` VARCHAR(45) NULL DEFAULT NULL,
	`visibility_type` TINYINT(1) NULL DEFAULT NULL,
	PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=8
;

INSERT INTO `log_type` (`id`, `nazov`, `code`, `primary_table`) VALUES (26000, 'Pridanie obchodného partnera', 'obchodny_partner_pridaj', NULL);
INSERT INTO `log_type` (`id`, `nazov`, `code`, `primary_table`) VALUES (26001, 'Editovanie obchodného partnera', 'obchodny_partner_edituj', NULL);
INSERT INTO `log_type` (`id`, `nazov`, `code`, `primary_table`) VALUES (26002, 'Zmazanie obchodného partnera', 'obchodny_partner_zmaz', NULL);
INSERT INTO `log_type` (`id`, `nazov`, `code`, `primary_table`) VALUES (26100, 'Pridanie kategórie obchodného partnera', 'kategoria_obchodneho_partnera_pridaj', NULL);
INSERT INTO `log_type` (`id`, `nazov`, `code`, `primary_table`) VALUES (26101, 'Editovanie kategórie obchodného partnera', 'kategoria_obchodneho_partnera_edituj', NULL);
INSERT INTO `log_type` (`id`, `nazov`, `code`, `primary_table`) VALUES (26102, 'Zmazanie kategórie obchodného partnera', 'kategoria_obchodneho_partnera_zmaz', NULL);

INSERT INTO `menu` (`id`, `menu_id`, `nazov`, `page`, `poradie`, `level`, `visibility_type`) VALUES (26000, NULL, 'Obchodní partneri', 'obchodny_partner', 20, 1, 1);
INSERT INTO `menu` (`id`, `menu_id`, `nazov`, `page`, `poradie`, `level`, `visibility_type`) VALUES (26001, 26000, 'Výpis obchodných partnerov', 'obchodny_partner_vypis', 10, 2, 1);
INSERT INTO `menu` (`id`, `menu_id`, `nazov`, `page`, `poradie`, `level`, `visibility_type`) VALUES (26002, 26000, 'Pridanie obchodného partnera', 'obchodny_partner_pridaj', 20, 2, 1);
INSERT INTO `menu` (`id`, `menu_id`, `nazov`, `page`, `poradie`, `level`, `visibility_type`) VALUES (26003, 26001, 'Detail obchodného partnera', 'obchodny_partner_view', 10, 3, 1);
INSERT INTO `menu` (`id`, `menu_id`, `nazov`, `page`, `poradie`, `level`, `visibility_type`) VALUES (26004, 26001, 'Editovanie obchodného partnera', 'obchodny_partner_edituj', 20, 3, 1);
INSERT INTO `menu` (`id`, `menu_id`, `nazov`, `page`, `poradie`, `level`, `visibility_type`) VALUES (26005, 26001, 'Zmazanie obchodného partnera', 'obchodny_partner_zmaz', 30, 3, 0);
INSERT INTO `menu` (`id`, `menu_id`, `nazov`, `page`, `poradie`, `level`, `visibility_type`) VALUES (26100, 26000, 'Výpis kategórií obchodného partnera', 'kategoria_obchodneho_partnera_vypis', 30, 2, 1);
INSERT INTO `menu` (`id`, `menu_id`, `nazov`, `page`, `poradie`, `level`, `visibility_type`) VALUES (26101, 26000, 'Pridanie kategórie obchodného partnera', 'kategoria_obchodneho_partnera_pridaj', NULL, 2, 0);
INSERT INTO `menu` (`id`, `menu_id`, `nazov`, `page`, `poradie`, `level`, `visibility_type`) VALUES (26102, 26100, 'Editovanie kategórie obchodného partnera', 'kategoria_obchodneho_partnera_edituj', 20, 3, 1);
INSERT INTO `menu` (`id`, `menu_id`, `nazov`, `page`, `poradie`, `level`, `visibility_type`) VALUES (26103, 26100, 'Zmazanie kategórie obchodného partnera', 'kategoria_obchodneho_partnera_zmaz', NULL, 3, 0);
INSERT INTO `menu` (`id`, `menu_id`, `nazov`, `page`, `poradie`, `level`, `visibility_type`) VALUES (26104, 26100, 'Detail kategórie obchodných partnerov', 'kategoria_obchodneho_partnera_view', 10, 3, 1);

CREATE TABLE `typ_obchodneho_partnera` (
	`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
	`nazov` VARCHAR(45) NOT NULL COMMENT 'FO-podnikatel\\nFO-nepodnikatel\\nPO',
	`code` VARCHAR(45) NULL DEFAULT NULL,
	PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=4
;

INSERT INTO `typ_obchodneho_partnera` (`id`, `nazov`, `code`) VALUES (1, 'Fyzická osoba - nepodnikateľ', 'fo_nepodnikatel');
INSERT INTO `typ_obchodneho_partnera` (`id`, `nazov`, `code`) VALUES (2, 'Fyzická osoba - podnikateľ', 'fo_podnikatel');
INSERT INTO `typ_obchodneho_partnera` (`id`, `nazov`, `code`) VALUES (3, 'Právnická osoba', 'po');

CREATE TABLE `obchodny_partner` (
	`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
	`nazov` VARCHAR(255) NOT NULL,
	`ulica` VARCHAR(255) NULL DEFAULT NULL,
	`obec` VARCHAR(255) NULL DEFAULT NULL,
	`psc` VARCHAR(10) NULL DEFAULT NULL,
	`ico` VARCHAR(45) NULL DEFAULT NULL,
	`dic` VARCHAR(45) NULL DEFAULT NULL,
	`ic_dph` VARCHAR(45) NULL DEFAULT NULL,
	`typ_obchodneho_partnera_id` INT(11) NOT NULL,
	`stat_id` INT(10) UNSIGNED NOT NULL,
	`platca_dph` TINYINT(1) NULL DEFAULT NULL,
	`visibility_type` TINYINT(1) NULL DEFAULT NULL,
	PRIMARY KEY (`id`),
	INDEX `fk_zakaznik_typ_zakaznika1_idx` (`typ_obchodneho_partnera_id`),
	INDEX `fk_zakaznik_stat1_idx` (`stat_id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=12
;

CREATE TABLE `obchodny_partner_kategoria_obchodneho_partnera` (
	`obchodny_partner_id` INT(10) UNSIGNED NOT NULL,
	`kategoria_obchodneho_partnera_id` INT(10) UNSIGNED NOT NULL,
	PRIMARY KEY (`obchodny_partner_id`, `kategoria_obchodneho_partnera_id`),
	INDEX `fk_zakaznik_has_kategoria_zakaznika_kategoria_zakaznika1_idx` (`kategoria_obchodneho_partnera_id`),
	INDEX `fk_zakaznik_has_kategoria_zakaznika_zakaznik1_idx` (`obchodny_partner_id`),
	CONSTRAINT `fk_zakaznik_has_kategoria_zakaznika_kategoria_zakaznika1` FOREIGN KEY (`kategoria_obchodneho_partnera_id`) REFERENCES `kategoria_obchodneho_partnera` (`id`) ON UPDATE NO ACTION ON DELETE NO ACTION,
	CONSTRAINT `fk_zakaznik_has_kategoria_zakaznika_zakaznik1` FOREIGN KEY (`obchodny_partner_id`) REFERENCES `obchodny_partner` (`id`) ON UPDATE NO ACTION ON DELETE NO ACTION
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
;
