/*1*/ ALTER TABLE `pobocka`
	DROP COLUMN `analyticky_ucet`;
/*2*/ ALTER TABLE `zamestnanec`
	ADD COLUMN `analyticky_ucet` VARCHAR(255) NULL DEFAULT NULL AFTER `archiv`;

/*3*/ UPDATE `form_element` SET `form_group_id`='21001', `db_table`='zamestnanec', `column_title`='Analytický účet', `position`='60' WHERE  `id`=50;

/*4*/ ALTER TABLE `zmluva`
	ADD COLUMN `datum_zverejnenia` DATETIME NULL DEFAULT NULL AFTER `stav_zmluvy_id`;

/*6*/ CREATE TABLE `polozka_zmluvy_sluzba` (
	`polozka_zmluvy_id` INT(11) UNSIGNED NOT NULL,
	`sluzba_id` INT(11) UNSIGNED NOT NULL,
	PRIMARY KEY (`polozka_zmluvy_id`, `sluzba_id`),
	INDEX `sluzba` (`sluzba_id`),
	CONSTRAINT `FK_polozka_zmluvy_polozka_zmluvy` FOREIGN KEY (`polozka_zmluvy_id`) REFERENCES `osoba` (`id`),
	CONSTRAINT `FK_polozka_zmluvy_sluzba_sluzba` FOREIGN KEY (`sluzba_id`) REFERENCES `sluzba` (`id`)
)
COLLATE='utf8_bin'
ENGINE=InnoDB
;
/*7*/ INSERT INTO `form_element` (`id`, `form_group_id`, `form_element_type_id`, `db_table`, `db_column`, `column_title`, `position`, `direct_to_db`, `css_class`, `direct_multi_label`, `direct_multi_data`) VALUES ('64', '13', '9', 'polozka_zmluvy', 'sluzba_id', 'Služby', '40', '1', 'select2', '1', '1');
/*8*/ UPDATE `form_element` SET `db_multi_table`='sluzba' WHERE  `id`=64;
/*9*/ INSERT INTO `menu` (`id`, `menu_id`, `nazov`, `page`, `poradie`, `level`, `visibility_type`) VALUES ('13', '2', 'Percentuálne pokrytie služieb', 'zmluva_sluzba', '50', '3', '1');

ALTER TABLE `pobocka`
	CHANGE COLUMN `id` `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT FIRST;

CREATE TABLE `pokrytie_sluzby_pobockou` (
	`zmluva_id` INT(11) UNSIGNED NOT NULL,
	`sluzba_id` INT(11) UNSIGNED NOT NULL,
	`pobocka_id` INT(11) UNSIGNED NOT NULL,
	`hodnota` INT(11) NOT NULL DEFAULT '0',
	PRIMARY KEY (`pobocka_id`, `zmluva_id`, `sluzba_id`),
	INDEX `IDX_pokrytie_sluzby_pobockou_zmluva_id` (`zmluva_id`),
	INDEX `FK_pokrytie_sluzby_pobockou_sluzba_id` (`sluzba_id`),
	CONSTRAINT `FK_pokrytie_sluzby_pobockou_pobocka_id` FOREIGN KEY (`pobocka_id`) REFERENCES `pobocka` (`id`),
	CONSTRAINT `FK_pokrytie_sluzby_pobockou_sluzba_id` FOREIGN KEY (`sluzba_id`) REFERENCES `sluzba` (`id`),
	CONSTRAINT `FK_pokrytie_sluzby_pobockou_zmluva_id` FOREIGN KEY (`zmluva_id`) REFERENCES `zmluva` (`id`)
)
	ENGINE=InnoDB
;

CREATE TABLE `pokrytie_sluzby_zamestnancom` (
	`zmluva_id` INT(11) UNSIGNED NOT NULL,
	`sluzba_id` INT(11) UNSIGNED NOT NULL,
	`pobocka_id` INT(11) UNSIGNED NOT NULL,
	`zamestnanec_id` INT(11) UNSIGNED NOT NULL,
	`hodnota` INT(11) NOT NULL DEFAULT '0',
	PRIMARY KEY (`pobocka_id`, `zmluva_id`, `sluzba_id`, `zamestnanec_id`),
	INDEX `IDX_pokrytie_sluzby_zamestnancom_zmluva_id` (`zmluva_id`),
	INDEX `FK_pokrytie_sluzby_zamestnancom_sluzba_id` (`sluzba_id`),
	CONSTRAINT `FK_pokrytie_sluzby_zamestnancom_pobocka_id` FOREIGN KEY (`pobocka_id`) REFERENCES `pobocka` (`id`),
	CONSTRAINT `FK_pokrytie_sluzby_zamestnancom_sluzba_id` FOREIGN KEY (`sluzba_id`) REFERENCES `sluzba` (`id`),
	CONSTRAINT `FK_pokrytie_sluzby_zamestnancom_zmluva_id` FOREIGN KEY (`zmluva_id`) REFERENCES `zmluva` (`id`),
	CONSTRAINT `FK_pokrytie_sluzby_zamestnancom_zamestnanec_id` FOREIGN KEY (`zamestnanec_id`) REFERENCES `zamestnanec` (`id`)
)
	ENGINE=InnoDB
;
