-- MySQL Workbench Forward Engineering

-- -----------------------------------------------------
-- Table `budgets_products`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `budgets_products` ;

CREATE TABLE IF NOT EXISTS `budgets_products` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `budget_id` INT UNSIGNED NOT NULL,
  `product_id` INT NOT NULL,
  `table_id` INT NOT NULL,
  `amount` DECIMAL(10,2) NOT NULL,
  `cost` DECIMAL(10,2) NOT NULL,
  `sale` DECIMAL(10,2) NOT NULL,
  `total` DECIMAL(10,2) NOT NULL,
  `formula` JSON NULL,
  `kit` TINYINT NULL,
  `kitId` INT NULL,
  `kitOrder` INT(2) NULL,
  PRIMARY KEY (`id`, `budget_id`, `product_id`),
  CONSTRAINT `fk_products_has_budget_product_table`
    FOREIGN KEY (`product_id`)
    REFERENCES `products` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_products_has_budget_budget_table`
    FOREIGN KEY (`budget_id`)
    REFERENCES `budgets` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_budgets_product_budget_table_table`
    FOREIGN KEY (`table_id`)
    REFERENCES `budget_tables` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_budgets_product_budget_product_table`
    FOREIGN KEY (`kitId`)
    REFERENCES `budgets_products` (`id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

CREATE INDEX `fk_products_has_budget_budget_table_idx` ON `budgets_products` (`budget_id` ASC);

CREATE INDEX `fk_products_has_budget_product_table_idx` ON `budgets_products` (`product_id` ASC);

CREATE INDEX `fk_budgets_product_budget_table_table_idx` ON `budgets_products` (`table_id` ASC);

CREATE INDEX `fk_budgets_product_budget_product_table_idx` ON `budgets_products` (`kitId` ASC);


-- -----------------------------------------------------
-- Data for table `budget_table_categories`
-- -----------------------------------------------------
START TRANSACTION;
INSERT INTO `budget_table_categories` (`id`, `description`) VALUES (1, 'Cortinado');
INSERT INTO `budget_table_categories` (`id`, `description`) VALUES (2, 'Tela');
INSERT INTO `budget_table_categories` (`id`, `description`) VALUES (3, 'Bebedouro');
INSERT INTO `budget_table_categories` (`id`, `description`) VALUES (4, 'Armazenagem e Ração');
INSERT INTO `budget_table_categories` (`id`, `description`) VALUES (5, 'Comedouro');
INSERT INTO `budget_table_categories` (`id`, `description`) VALUES (6, 'Outros');
INSERT INTO `budget_table_categories` (`id`, `description`) VALUES (7, 'Elétrica');
INSERT INTO `budget_table_categories` (`id`, `description`) VALUES (8, 'Pisos');

COMMIT;


-- -----------------------------------------------------
-- Data for table `budget_tables`
-- -----------------------------------------------------
START TRANSACTION;
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (1, 'Cortina Externa', 1);
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (2, 'Forração', 1);
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (3, 'Outras Cortinas', 1);
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (4, 'Cortina Interna', 1);
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (5, 'Tela', 2);
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (6, 'Equipamentos Complementares', 2);
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (7, 'Bebedouro', 3);
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (8, 'Equipamentos Complementares', 3);
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (9, 'Silo e Sistema de Arraçoamento', 4);
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (10, 'Carrinho para Ração', 4);
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (11, 'CJ Descarregador Suíno', 4);
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (12, 'Silo Big', 4);
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (13, 'Sistema de Arraçoamento', 4);
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (14, 'Comedouro', 5);
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (15, 'Equipamentos Complementares', 5);
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (16, 'Bombas / Nebolização', 6);
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (17, 'Cabeceira', 6);
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (18, 'Lavação', 6);
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (19, 'Lona Esterqueira', 6);
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (20, 'Aquecimento', 6);
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (21, 'Elétrica', 7);
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (22, 'Outros Elétrica', 7);
INSERT INTO `budget_tables` (`id`, `description`, `category_id`) VALUES (23, 'Pisos', 8);

COMMIT;


SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
