CREATE TABLE IF NOT EXISTS `#__calcbuilder_field` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `class` tinyint(4) DEFAULT NULL COMMENT '0-producto\n1-utilidad\n2-personal producto',
  `mandatory` tinyint(4) NOT NULL DEFAULT '0',
  `idobj` int(11) DEFAULT NULL,
  `type` int(11) DEFAULT NULL COMMENT '0-numero\n1-fecha\n2-lista opciones\n3-boolean\n4-texto\n5-fichero',
  `decimal` int(11) DEFAULT NULL,
  `order` int(11) DEFAULT NULL,
  `css` varchar(500) DEFAULT NULL,
  `var` varchar(500) DEFAULT NULL,
  `name` varchar(500) DEFAULT NULL,
  `limit0` varchar(500) DEFAULT NULL,
  `limit1` varchar(500) DEFAULT NULL,
  `placeholder` varchar(500) DEFAULT NULL,
  `mask` varchar(500) DEFAULT NULL,
  `combodependantfield` varchar(500) DEFAULT NULL,
  `multivalue` longtext,
  `defaulttext` longtext,
  `sqltext` longtext,
  `combodependantsql` longtext,
  `inlineevent` tinyint(4) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
)  AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_general_ci ;

CREATE TABLE IF NOT EXISTS `#__calcbuilder_field_multivalue` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `idfield` int(11) NOT NULL,
  `idobj` int(11) NOT NULL,
  `ord` int(11) NOT NULL,
  `name` varchar(500) DEFAULT NULL,
  `value` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`id`)
)  AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_general_ci;

CREATE TABLE IF NOT EXISTS `#__calcbuilder_matrix` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `class` tinyint(4) DEFAULT NULL COMMENT '0-product;1-utility',
  `main` tinyint(4) DEFAULT '0' COMMENT '0:normal\n1:salida',
  `idobj` int(11) DEFAULT NULL,
  `name` varchar(500) DEFAULT NULL,
  `var` varchar(500) DEFAULT NULL,
  `value` longtext,
  PRIMARY KEY (`id`)
)  AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_general_ci;

CREATE TABLE IF NOT EXISTS `#__calcbuilder_section` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `idutility` int(11) NOT NULL,
  `name` varchar(450) DEFAULT NULL,
  `addbutton` tinyint(4) NOT NULL DEFAULT '0',
  `defaultsections` int(11) NOT NULL DEFAULT '0',
  `limitsections` int(11) NOT NULL DEFAULT '-1',
  `layout` longtext,
  `delinlineevent` tinyint(4) NOT NULL DEFAULT '0',
  `addinlineevent` tinyint(4) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
)  AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_general_ci;

CREATE TABLE IF NOT EXISTS `#__calcbuilder_section_field` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `idsection` int(11) NOT NULL,
  `idfield` int(11) NOT NULL,
  PRIMARY KEY (`id`)
)  AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_general_ci;

CREATE TABLE IF NOT EXISTS `#__calcbuilder_stats` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `idrequest` int(11) NOT NULL,
  `idobj` int(11) NOT NULL,
  `field` varchar(500) DEFAULT NULL,
  `value` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`id`)
)  AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_general_ci ;

CREATE TABLE IF NOT EXISTS `#__calcbuilder_userdata` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `iduser` int(11) NOT NULL,
  `idutility` int(11) NOT NULL,
  `data` longtext,
  PRIMARY KEY (`id`)
)  AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_general_ci;

CREATE TABLE IF NOT EXISTS `#__calcbuilder_utility` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `layout_preference` tinyint(4) NOT NULL DEFAULT '0',
  `reset_button` tinyint(4) NOT NULL DEFAULT '0',
  `info_img` tinyint(4) NOT NULL DEFAULT '0',
  `pdf_orientation` tinyint(4) NOT NULL DEFAULT '0',
  `front_email` tinyint(4) NOT NULL DEFAULT '0',
  `front_excel` tinyint(4) NOT NULL DEFAULT '0',
  `front_pdf` tinyint(4) NOT NULL DEFAULT '0',
  `calculateonfly` tinyint(4) NOT NULL DEFAULT '0',
  `resultpopup` tinyint(4) NOT NULL DEFAULT '0',
  `up_prefix` tinyint(4) NOT NULL DEFAULT '0',
  `vm_product_type` tinyint(4) NOT NULL DEFAULT '0',
  `up_maxuploadfiles` int(11) DEFAULT '100',
  `up_filesize` int(11) DEFAULT '8',
  `popupwidth` int(11) NOT NULL DEFAULT '250',
  `name` varchar(500) DEFAULT NULL,
  `thousand_number_format` varchar(500) NOT NULL DEFAULT ',',
  `decimal_number_format` varchar(500) NOT NULL DEFAULT '.',
  `date_frontend_format` varchar(500) NOT NULL DEFAULT '%d-%m-%Y',
  `sendemailform` varchar(500) DEFAULT NULL,
  `up_extensions` varchar(500) DEFAULT NULL,
  `up_mimetypes` varchar(500) DEFAULT NULL,
  `up_folder` varchar(150) DEFAULT NULL,
  `info` longtext,
  `code` longtext,
  `preformhtml` longtext,
  `precalcprint` longtext,
  `poscalcprint` longtext,
  `layout` longtext,
  `exitlayout` longtext,
  `js_functions` longtext,
  `js_pre_calc_button` longtext,
  `js_reset_button` longtext,
  `js_post_calc_button` longtext,
  `js_event_code` longtext,
  `import_bootstrap` tinyint(4) NOT NULL DEFAULT '1',
  `datasave` tinyint(4) NOT NULL DEFAULT '-1',
  `calculate_button_text` varchar(500) NOT NULL DEFAULT '',
  `include_input` tinyint(4) NOT NULL DEFAULT '0',
  `include_result` tinyint(4) NOT NULL DEFAULT '0',
  `mail_subject` varchar(500) DEFAULT NULL,
  `calc_on_init` TINYINT NOT NULL DEFAULT 0,
  `layout_position` TINYINT NOT NULL DEFAULT 0,
  `form_layout_width` VARCHAR(45) NOT NULL DEFAULT '100%',
  `sendemailcc` varchar(500) DEFAULT NULL,
  `sendemailbcc` varchar(500) DEFAULT NULL,
  `mc_api` varchar(500) DEFAULT NULL,
  `mc_email` varchar(500) DEFAULT NULL,
  `mc_list` varchar(500) DEFAULT NULL,
  `mc_apply` tinyint(4) NOT NULL DEFAULT '0',
  `mc_email_name` varchar(200) DEFAULT NULL,
  `mc_email_lastname` varchar(200) DEFAULT NULL,
  `sectionaddposition` TINYINT NOT NULL DEFAULT 0,
  `precalcprintpdf` longtext,
  `poscalcprintpdf` longtext,
  `include_input_pdf` tinyint(4) NOT NULL DEFAULT '0',
  `include_result_pdf` tinyint(4) NOT NULL DEFAULT '0',
  `emailaddpdf` tinyint(4) NOT NULL DEFAULT '0',
  `sectionposition` tinyint(4) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
)  AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_general_ci;

CREATE TABLE IF NOT EXISTS `#__calcbuilder_vm_products` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `idobj` int(11) NOT NULL,
  `idvmproduct` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) AUTO_INCREMENT=1 CHARACTER SET utf8 COLLATE utf8_general_ci;

CREATE TABLE IF NOT EXISTS `#__calcbuilder_excel` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `idobj` INT NOT NULL,
  `excelfile` VARCHAR(250) NULL,
  `excelexec` TINYINT NOT NULL DEFAULT 0,
  `cache` TINYINT NOT NULL DEFAULT 0,
  `htmloutput` TINYINT NOT NULL DEFAULT 0,
  `pdfoutput` TINYINT NOT NULL DEFAULT 0,
  `htmloutputpage` INT NOT NULL DEFAULT 0,
  `pdfoutputpage` INT NOT NULL DEFAULT 0,  
  `exceloutput` TINYINT NOT NULL DEFAULT 0,
  `locale` VARCHAR(10) NOT NULL DEFAULT 'en_us',
  PRIMARY KEY (`id`)
) CHARACTER SET utf8 COLLATE utf8_general_ci;

CREATE TABLE IF NOT EXISTS `#__calcbuilder_excel_mapping` (
	`id` INT NOT NULL AUTO_INCREMENT,
	`idexcel` INT NOT NULL,
	`type` TINYINT NOT NULL,
	`sheet` VARCHAR(150) NULL,
	`cell` VARCHAR(45) NULL,
	`phpvar` VARCHAR(150) NULL,
	PRIMARY KEY (`id`) ) CHARACTER SET utf8 COLLATE utf8_general_ci;
