CREATE TABLE `forma_uhrady` (
	`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
	`nazov` VARCHAR(255) NULL DEFAULT NULL,
	`code` VARCHAR(50) NULL DEFAULT NULL,
	PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
;

INSERT INTO `forma_uhrady` (`id`, `nazov`, `code`) VALUES (1, 'Prevodný príkaz', 'pp');
INSERT INTO `forma_uhrady` (`id`, `nazov`, `code`) VALUES (2, 'Hotovosť', 'hotovost');
INSERT INTO `forma_uhrady` (`id`, `nazov`, `code`) VALUES (3, 'Dobierka', 'dobierka');

CREATE TABLE `priradenie_platby` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `nazov` VARCHAR(45) NULL DEFAULT NULL,
  `code` VARCHAR(45) NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
)
  COLLATE='utf8_general_ci'
  ENGINE=InnoDB
;

INSERT INTO `priradenie_platby` (`id`, `nazov`, `code`) VALUES (60, 'Faktúra', 'faktura');
INSERT INTO `priradenie_platby` (`id`, `nazov`, `code`) VALUES (300, 'Zákazka', 'zakazka');

CREATE TABLE `platba` (
	`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
	`suma` FLOAT(10,2) NULL DEFAULT NULL,
	`datum` DATE NULL DEFAULT NULL,
	`poznamka` TEXT NULL,
	`nazov` VARCHAR(255) NULL DEFAULT NULL,
	`priradenie_platby_id` INT(10) UNSIGNED NULL DEFAULT NULL,
	`priradenie_primary_id` INT(10) UNSIGNED NULL DEFAULT NULL,
	`visibility_type` TINYINT(1) NULL DEFAULT NULL,
	`forma_uhrady_id` INT(10) UNSIGNED NULL DEFAULT NULL,
	PRIMARY KEY (`id`),
	INDEX `fk_platba_priradenie_platby1_idx` (`priradenie_platby_id`),
	INDEX `fk_platba_forma_uhrady1_idx` (`forma_uhrady_id`),
	CONSTRAINT `fk_platba_forma_uhrady1` FOREIGN KEY (`forma_uhrady_id`) REFERENCES `forma_uhrady` (`id`) ON UPDATE NO ACTION ON DELETE NO ACTION,
	CONSTRAINT `fk_platba_priradenie_platby1` FOREIGN KEY (`priradenie_platby_id`) REFERENCES `priradenie_platby` (`id`) ON UPDATE NO ACTION ON DELETE NO ACTION
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
;


INSERT INTO `form` (`id`, `nazov`, `code`) VALUES (310, 'Platba', 'platba');
INSERT INTO `form_group` (`id`, `form_id`, `nazov`, `code`, `position`, `poznamka`, `group_type`) VALUES (31000, 310, 'Základné informácie', 'platba_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 (31000, 31000, 4, 'platba', 'datum', NULL, NULL, 'Dátum platby', 20, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'NOW', 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 (31001, 31000, 1, 'platba', 'nazov', NULL, NULL, 'Názov', 10, NULL, NULL, NULL, NULL, 'číslo daňového dokladu, bankového výpisu, alebo iné', 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 (31002, 31000, 1, 'platba', 'suma', NULL, NULL, 'Suma', 30, NULL, NULL, NULL, NULL, NULL, 1, 1, NULL, 1, 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 (31003, 31000, 5, 'platba', 'forma_uhrady_id', 'forma_uhrady', NULL, 'Forma úhrady', 40, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, 'select2', NULL, 1, NULL, NULL, 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 (31004, 31000, 2, 'platba', 'poznamka', NULL, NULL, 'Poznámka', 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 (31005, 31000, 13, 'platba', 'priradenie_platby_id', NULL, NULL, 'Priradenie platby', NULL, 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 (31006, 31000, 13, 'platba', 'priradenie_primary_id', NULL, NULL, 'Primary id', NULL, 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 (310, 'Pridanie platby', 'platba_pridaj', NULL);
INSERT INTO `log_type` (`id`, `nazov`, `code`, `primary_table`) VALUES (311, 'Editovanie platba', 'platba_edituj', NULL);
INSERT INTO `log_type` (`id`, `nazov`, `code`, `primary_table`) VALUES (312, 'Zmazanie platby', 'platba_zmaz', NULL);
