/*28*/ RENAME TABLE `sluzba` TO `typ_sluzby`;
/*29*/ ALTER TABLE `typ_sluzby`
	ADD COLUMN `modul_id` INT(11) NOT NULL AFTER `icon`;
/*30*/ UPDATE `typ_sluzby` SET `modul_id`=1 WHERE  `id`=1;
/*31*/ UPDATE `typ_sluzby` SET `modul_id`=1 WHERE  `id`=2;
/*32*/ UPDATE `typ_sluzby` SET `modul_id`=1 WHERE  `id`=3;
/*33*/ UPDATE `typ_sluzby` SET `modul_id`=1 WHERE  `id`=4;
/*34*/ UPDATE `typ_sluzby` SET `modul_id`=1 WHERE  `id`=5;
/*35*/ UPDATE `typ_sluzby` SET `modul_id`=1 WHERE  `id`=6;
/*36*/ CREATE TABLE `obchodny_partner_typ_sluzby` (
	`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
	`obchodny_partner_id` INT(11) UNSIGNED NULL,
	`typ_sluzby_id` INT(11) UNSIGNED NULL,
	`datum_od` DATE NULL,
	`datum_do` DATE NULL,
	PRIMARY KEY (`id`),
	CONSTRAINT `FK1_obpts_op` FOREIGN KEY (`obchodny_partner_id`) REFERENCES `obchodny_partner` (`id`)
)
COLLATE='utf8_bin'
ENGINE=InnoDB
;
/*38*/ ALTER TABLE `clanok_sluzba`
	ALTER `sluzba_id` DROP DEFAULT;
/*40*/ ALTER TABLE `clanok_sluzba`
	ALTER `sluzba_id` DROP DEFAULT;
/*41*/ ALTER TABLE `clanok_sluzba`
	CHANGE COLUMN `sluzba_id` `typ_sluzby_id` INT(11) NOT NULL AFTER `clanok_id`;
/*42*/ ALTER TABLE `clanok_sluzba`
	ALTER `typ_sluzby_id` DROP DEFAULT;
/*43*/ ALTER TABLE `clanok_sluzba`
	CHANGE COLUMN `typ_sluzby_id` `typ_sluzby_id` INT(11) UNSIGNED NOT NULL AFTER `clanok_id`,
	DROP FOREIGN KEY `fk_clanok_has_sluzba_sluzba1`;
/*44*/ RENAME TABLE `clanok_sluzba` TO `clanok_typ_sluzby`;
/*45*/ ALTER TABLE `typ_sluzby`
	CHANGE COLUMN `id` `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT FIRST;
/*46*/ ALTER TABLE `typ_sluzby`
	ALTER `modul_id` DROP DEFAULT;
/*47*/ ALTER TABLE `typ_sluzby`
	CHANGE COLUMN `modul_id` `modul_id` INT(11) UNSIGNED NOT NULL AFTER `icon`;
/*48*/ ALTER TABLE `clanok_typ_sluzby`
	ADD CONSTRAINT `FK_clanok_typ_sluzby_typ_sluzby` FOREIGN KEY (`typ_sluzby_id`) REFERENCES `typ_sluzby` (`id`);
/*49*/ ALTER TABLE `obchodny_partner_typ_sluzby`
	ADD CONSTRAINT `FK_obchodny_partner_typ_sluzby_typ_sluzby` FOREIGN KEY (`typ_sluzby_id`) REFERENCES `typ_sluzby` (`id`);
/*50*/ ALTER TABLE `modul`
	CHANGE COLUMN `id` `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT FIRST;
/*51*/ ALTER TABLE `typ_sluzby`
	ADD CONSTRAINT `FK_typ_sluzby_modul` FOREIGN KEY (`modul_id`) REFERENCES `modul` (`id`);
	
/*1*/ INSERT INTO `typ_sluzby` (`id`, `nazov`, `poradie`, `modul_id`) VALUES (7, 'Správa majetku', 10, 2);
/*2*/ INSERT INTO `typ_sluzby` (`id`, `nazov`, `poradie`, `modul_id`) VALUES (8, 'Plánovanie', 10, 3);
/*3*/ INSERT INTO `typ_sluzby` (`id`, `nazov`, `poradie`, `modul_id`) VALUES (9, 'Zákazník', 10, 4);	

/*1*/ ALTER TABLE `obchodny_partner_typ_sluzby`
	ADD COLUMN `visibility_type` TINYINT(1) NULL AFTER `datum_do`;

INSERT INTO `form` (`id`, `nazov`, `code`) VALUES (10, 'Obchodný partner typ služby', 'obchodny_partner_typ_sluzby');


/*1*/ INSERT INTO `obchodny_partner_typ_sluzby` (`id`, `obchodny_partner_id`, `typ_sluzby_id`, `datum_od`, `datum_do`, `visibility_type`) VALUES (1, 14, 1, '2015-11-18', '2016-11-18', 1);
/*2*/ INSERT INTO `form_group` (`id`, `form_id`, `nazov`, `code`, `position`) VALUES (2, 10, 'Základné informácie', 'obchodny_partner_typ_sluzby_zakladne_informacie', 10);
/*3*/ INSERT INTO `form_element` (`id`, `form_group_id`, `form_element_type_id`, `db_table`, `db_column`, `db_multi_table`, `column_title`, `position`, `direct_to_db`, `required`, `direct_multi_label`) VALUES (3, 2, 5, 'obchodny_partner_typ_sluzby', 'obchodny_partner_id', 'obchodny_partner', 'Obchodný partner', 10, 1, 1, 1);
/*4*/ UPDATE `form_element` SET `read_only`=1 WHERE  `id`=3;
/*5*/ INSERT INTO `form_element` (`id`, `form_group_id`, `form_element_type_id`, `db_table`, `db_column`, `db_multi_table`, `column_title`, `position`, `direct_to_db`, `required`, `direct_multi_label`, `add_empty_option`) VALUES (4, 2, 5, 'obchodny_partner_typ_sluzby', 'typ_sluzby_id', 'typ_sluzby', 'Služba', 20, 1, 1, 1, 1);
/*6*/ INSERT INTO `form_element` (`id`, `form_group_id`, `form_element_type_id`, `db_table`, `db_column`, `column_title`, `position`, `direct_to_db`, `required`) VALUES (5, 2, 4, 'obchodny_partner_typ_sluzby', 'datum_od', 'Platnosť od', 30, 1, 1);
/*7*/ INSERT INTO `form_element` (`id`, `form_group_id`, `form_element_type_id`, `db_table`, `db_column`, `column_title`, `position`, `direct_to_db`, `required`) VALUES (6, 21002, 4, 'obchodny_partner_typ_sluzby', 'datum_do', 'Platnosť do', 40, 1, 1);
/*8*/ UPDATE `form_element` SET `form_group_id`=2 WHERE  `id`=6;
/*9*/ UPDATE `form_element` SET `direct_to_db`=NULL, `required`=NULL WHERE  `id`=3;
/*10*/ UPDATE `form_element` SET `vdaemon`='<vlvalidator name="customObchodnyPartnerTypSluzby" type="custom" function="vdaemonObchodnyPartnerTypSluzby" />' WHERE  `id`=5;
/*11*/ DELETE FROM `obchodny_partner_typ_sluzby` WHERE  `id`=10;
/*12*/ INSERT INTO `menu` (`id`) VALUES (101);
/*13*/ UPDATE `menu` SET `menu_id`=26000, `nazov`='Služba pridaj', `page`='obchodny_partner_typ_sluzby_pridaj', `poradie`=31, `level`=2, `visibility_type`=0 WHERE  `id`=101;
/*14*/ INSERT INTO `menu` (`id`, `menu_id`, `nazov`, `page`, `level`, `visibility_type`) VALUES (102, 26000, 'Služba zmaž', 'obchodny_partner_typ_sluzby_zmaz', 3, 0);
/*15*/ UPDATE `menu` SET `level`=2 WHERE  `id`=102;
/*16*/ INSERT INTO `menu` (`id`, `menu_id`, `nazov`, `page`, `level`, `visibility_type`) VALUES (103, 26000, 'Služba edituj', 'obchodny_partner_typ_sluzbz_edituj', 2, 0);
/*17*/ UPDATE `menu` SET `poradie`=32 WHERE  `id`=103;
/*18*/ UPDATE `menu` SET `page`='obchodny_partner_typ_sluzby_edituj' WHERE  `id`=103;

INSERT INTO `log_type` (`id`, `nazov`, `code`, `primary_table`) VALUES (4, 'Pridanie služby pre obchodného partnera', 'obchodny_partner_typ_sluzby_pridaj', NULL);
INSERT INTO `log_type` (`id`, `nazov`, `code`, `primary_table`) VALUES (5, 'Editovanie služby pre obchodného partnera', 'obchodny_partner_typ_sluzby_edituj', NULL);
INSERT INTO `log_type` (`id`, `nazov`, `code`, `primary_table`) VALUES (6, 'Zmazanie služby pre obchodného partnera', 'obchodny_partner_typ_sluzby_zmaz', NULL);
