text: -- MySQL Script generated by MySQL Workbench
  -- Fri Oct  2 14:00:41 2020
  -- Model: New Model    Version: 1.0
  -- MySQL Workbench Forward Engineering
  
  SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
  SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
  SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
  
  -- -----------------------------------------------------
  -- Schema sia
  -- -----------------------------------------------------
  
  -- -----------------------------------------------------
  -- Schema sia
  -- -----------------------------------------------------
  CREATE SCHEMA IF NOT EXISTS `sia` DEFAULT CHARACTER SET utf8 ;
  USE `sia` ;
  
  -- -----------------------------------------------------
  -- Table `sia`.`TipoGranja`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`TipoGranja` (
    `idTipGra` INT NOT NULL AUTO_INCREMENT,
    `nomTipGra` VARCHAR(45) NOT NULL,
    PRIMARY KEY (`idTipGra`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`Estado`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`Estado` (
    `idEst` INT NOT NULL AUTO_INCREMENT,
    `nomEst` VARCHAR(45) NOT NULL,
    PRIMARY KEY (`idEst`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`GrupoGranja`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`GrupoGranja` (
    `idGruGra` INT NOT NULL AUTO_INCREMENT,
    `nomGruGra` VARCHAR(45) NOT NULL,
    `fecCreGruGra` DATETIME NOT NULL COMMENT 'fecha de creacion del grupo',
    `obsGruGra` VARCHAR(150) NULL COMMENT 'observacion del grupo\n',
    `idEstPer` INT NOT NULL,
    PRIMARY KEY (`idGruGra`),
    INDEX `fk_GrupoGranja_Estado1_idx` (`idEstPer` ASC),
    CONSTRAINT `fk_GrupoGranja_Estado1`
      FOREIGN KEY (`idEstPer`)
      REFERENCES `sia`.`Estado` (`idEst`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`Granja`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`Granja` (
    `idGra` INT NOT NULL AUTO_INCREMENT,
    `ubiGra` VARCHAR(45) NOT NULL,
    `nomGra` VARCHAR(150) NULL,
    `idTipGraPer` INT NOT NULL,
    `idGruGraPer` INT NOT NULL,
    PRIMARY KEY (`idGra`),
    INDEX `fk_Granja_TipoGranja1_idx` (`idTipGraPer` ASC) ,
    INDEX `fk_Granja_GrupoGranja1_idx` (`idGruGraPer` ASC),
    CONSTRAINT `fk_Granja_TipoGranja1`
      FOREIGN KEY (`idTipGraPer`)
      REFERENCES `sia`.`TipoGranja` (`idTipGra`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_Granja_GrupoGranja1`
      FOREIGN KEY (`idGruGraPer`)
      REFERENCES `sia`.`GrupoGranja` (`idGruGra`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`Unidades`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`Unidades` (
    `idUni` VARCHAR(3) NOT NULL,
    `nomUni` VARCHAR(45) NOT NULL,
    PRIMARY KEY (`idUni`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`AreaCultivo`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`AreaCultivo` (
    `idAreCul` INT NOT NULL AUTO_INCREMENT,
    `nomAre` VARCHAR(150) NULL,
    `ubiAreCul` VARCHAR(45) NOT NULL,
    `areAreCul` DECIMAL(5,2) NOT NULL,
    `obsAreCul` VARCHAR(150) NULL COMMENT 'observaciones del area de cultivo',
    `idGraPer` INT NOT NULL,
    `idUniPer` VARCHAR(3) NOT NULL,
    PRIMARY KEY (`idAreCul`),
    INDEX `fk_AreaCultivo_Granja_idx` (`idGraPer` ASC) ,
    INDEX `fk_AreaCultivo_Unidades1_idx` (`idUniPer` ASC) ,
    CONSTRAINT `fk_AreaCultivo_Granja`
      FOREIGN KEY (`idGraPer`)
      REFERENCES `sia`.`Granja` (`idGra`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_AreaCultivo_Unidades1`
      FOREIGN KEY (`idUniPer`)
      REFERENCES `sia`.`Unidades` (`idUni`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`Perfiles`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`Perfiles` (
    `idPer` INT NOT NULL AUTO_INCREMENT,
    `nomPer` VARCHAR(45) NOT NULL,
    PRIMARY KEY (`idPer`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`PersonalGranja`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`PersonalGranja` (
    `cedPerGra` VARCHAR(10) NOT NULL,
    `nomPerGra` VARCHAR(45) NOT NULL,
    `apeAgri` VARCHAR(45) NOT NULL,
    `fecNacPerGra` VARCHAR(45) NOT NULL,
    `carEcoPerGra` INT NULL COMMENT 'cargas economicas del personal de granja',
    `telPerGra` VARCHAR(10) NOT NULL,
    `emaAgri` VARCHAR(45) NULL,
    `usuPerGraSiNo` TINYINT NOT NULL COMMENT 'indica si la personal registrado tiene o no un usuario y contraseña para ingresar en el sistema',
    `idGraPer` INT NOT NULL,
    `idPerPer` INT NOT NULL,
    PRIMARY KEY (`cedPerGra`),
    INDEX `fk_Agricultor_Granja1_idx` (`idGraPer` ASC) ,
    INDEX `fk_PersonalGranja_Perfiles1_idx` (`idPerPer` ASC) ,
    CONSTRAINT `fk_Agricultor_Granja1`
      FOREIGN KEY (`idGraPer`)
      REFERENCES `sia`.`Granja` (`idGra`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_PersonalGranja_Perfiles1`
      FOREIGN KEY (`idPerPer`)
      REFERENCES `sia`.`Perfiles` (`idPer`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`Usuario`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`Usuario` (
    `idUsu` INT NOT NULL AUTO_INCREMENT,
    `conUsu` VARCHAR(45) NOT NULL,
    `nomUsu` VARCHAR(45) NOT NULL,
    `emaUsu` VARCHAR(45) NOT NULL,
    `fecCreUsu` DATETIME NOT NULL,
    `idGraPer` INT NOT NULL,
    `idPerPer` INT NOT NULL,
    PRIMARY KEY (`idUsu`),
    INDEX `fk_Usuario_Granja1_idx` (`idGraPer` ASC) ,
    UNIQUE INDEX `emaUsu_UNIQUE` (`emaUsu` ASC) ,
    INDEX `fk_Usuario_Perfiles1_idx` (`idPerPer` ASC) ,
    CONSTRAINT `fk_Usuario_Granja1`
      FOREIGN KEY (`idGraPer`)
      REFERENCES `sia`.`Granja` (`idGra`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_Usuario_Perfiles1`
      FOREIGN KEY (`idPerPer`)
      REFERENCES `sia`.`Perfiles` (`idPer`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`TipoCultivo`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`TipoCultivo` (
    `idTipCul` INT NOT NULL AUTO_INCREMENT,
    `nomTipCul` VARCHAR(45) NOT NULL,
    `perTipCul` DATETIME NOT NULL COMMENT 'periodo de plantacion de cada tipo de cultivo',
    PRIMARY KEY (`idTipCul`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`TipoSuelo`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`TipoSuelo` (
    `idTipSue` INT NOT NULL AUTO_INCREMENT,
    `nomTipSue` VARCHAR(45) NOT NULL,
    PRIMARY KEY (`idTipSue`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`TipoRendimiento`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`TipoRendimiento` (
    `idTipRen` INT NOT NULL AUTO_INCREMENT,
    `nomTipRen` VARCHAR(45) NOT NULL COMMENT 'Produccion Integrada\nProduccion Organica\nProduccion Convencional',
    PRIMARY KEY (`idTipRen`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`UnidadPlantacion`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`UnidadPlantacion` (
    `idUniPla` INT NOT NULL AUTO_INCREMENT,
    `nomUniPla` VARCHAR(45) NOT NULL COMMENT 'Peso\nPiezas(plantas)',
    PRIMARY KEY (`idUniPla`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`CentroCosto`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`CentroCosto` (
    `idCenCos` VARCHAR(20) NOT NULL,
    `lotCenCos` VARCHAR(45) NOT NULL,
    `idAreCulPer` INT NOT NULL,
    `fecIniCulCenCos` DATETIME NOT NULL,
    `idTipCulPer` INT NOT NULL,
    `idTipSuePer` INT NOT NULL,
    `idTipRenPer` INT NOT NULL,
    `idUniPlaPer` INT NOT NULL,
    `idEstPer` INT NOT NULL,
    PRIMARY KEY (`idCenCos`, `lotCenCos`, `idAreCulPer`),
    INDEX `fk_CentroCosto_AreaCultivo1_idx` (`idAreCulPer` ASC) ,
    INDEX `fk_CentroCosto_TipoCultivo1_idx` (`idTipCulPer` ASC) ,
    INDEX `fk_CentroCosto_TipoSuelo1_idx` (`idTipSuePer` ASC) ,
    INDEX `fk_CentroCosto_TipoRendimiento1_idx` (`idTipRenPer` ASC) ,
    INDEX `fk_CentroCosto_Estado1_idx` (`idEstPer` ASC) ,
    INDEX `fk_CentroCosto_UnidadPlantacion1_idx` (`idUniPlaPer` ASC) ,
    CONSTRAINT `fk_CentroCosto_AreaCultivo1`
      FOREIGN KEY (`idAreCulPer`)
      REFERENCES `sia`.`AreaCultivo` (`idAreCul`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_CentroCosto_TipoCultivo1`
      FOREIGN KEY (`idTipCulPer`)
      REFERENCES `sia`.`TipoCultivo` (`idTipCul`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_CentroCosto_TipoSuelo1`
      FOREIGN KEY (`idTipSuePer`)
      REFERENCES `sia`.`TipoSuelo` (`idTipSue`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_CentroCosto_TipoRendimiento1`
      FOREIGN KEY (`idTipRenPer`)
      REFERENCES `sia`.`TipoRendimiento` (`idTipRen`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_CentroCosto_Estado1`
      FOREIGN KEY (`idEstPer`)
      REFERENCES `sia`.`Estado` (`idEst`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_CentroCosto_UnidadPlantacion1`
      FOREIGN KEY (`idUniPlaPer`)
      REFERENCES `sia`.`UnidadPlantacion` (`idUniPla`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`TipoAnalisis`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`TipoAnalisis` (
    `idTipAna` INT NOT NULL,
    `nomTipAna` VARCHAR(45) NOT NULL,
    PRIMARY KEY (`idTipAna`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`Laboratorios`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`Laboratorios` (
    `idLab` VARCHAR(10) NOT NULL,
    `nomLab` VARCHAR(45) NOT NULL,
    `idEstPer` INT NOT NULL,
    PRIMARY KEY (`idLab`),
    INDEX `fk_Laboratorios_Estado1_idx` (`idEstPer` ASC) ,
    CONSTRAINT `fk_Laboratorios_Estado1`
      FOREIGN KEY (`idEstPer`)
      REFERENCES `sia`.`Estado` (`idEst`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`AnalisisLaboratorio`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`AnalisisLaboratorio` (
    `idAnaLab` INT NOT NULL AUTO_INCREMENT,
    `nomAnaLab` VARCHAR(45) NOT NULL,
    `fecAnaLab` DATETIME NOT NULL,
    `docAnaLab` BLOB NULL,
    `idTipAnaPer` INT NOT NULL,
    `idLabPer` VARCHAR(10) NULL,
    `idGraPer` INT NOT NULL,
    PRIMARY KEY (`idAnaLab`),
    INDEX `fk_Laboratorio_TipoExamen1_idx` (`idTipAnaPer` ASC) ,
    INDEX `fk_AnalisisLaboratorio_Laboratorios1_idx` (`idLabPer` ASC) ,
    INDEX `fk_AnalisisLaboratorio_Granja1_idx` (`idGraPer` ASC) ,
    CONSTRAINT `fk_Laboratorio_TipoExamen1`
      FOREIGN KEY (`idTipAnaPer`)
      REFERENCES `sia`.`TipoAnalisis` (`idTipAna`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_AnalisisLaboratorio_Laboratorios1`
      FOREIGN KEY (`idLabPer`)
      REFERENCES `sia`.`Laboratorios` (`idLab`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_AnalisisLaboratorio_Granja1`
      FOREIGN KEY (`idGraPer`)
      REFERENCES `sia`.`Granja` (`idGra`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`ActividadCultivo`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`ActividadCultivo` (
    `idActCul` INT NOT NULL AUTO_INCREMENT,
    `actCul` VARCHAR(150) NOT NULL,
    `fecIniAct` DATETIME NOT NULL,
    `fecFinAct` DATETIME NULL,
    `notActCul` TINYINT NOT NULL COMMENT 'activa o desactiva la notificacion de la actividad',
    `idCenCosPer` VARCHAR(20) NOT NULL,
    `idAnaLabPer` INT NULL,
    PRIMARY KEY (`idActCul`),
    INDEX `fk_ActividadCultivo_CentroCosto1_idx` (`idCenCosPer` ASC) ,
    INDEX `fk_ActividadCultivo_Laboratorio1_idx` (`idAnaLabPer` ASC) ,
    CONSTRAINT `fk_ActividadCultivo_CentroCosto1`
      FOREIGN KEY (`idCenCosPer`)
      REFERENCES `sia`.`CentroCosto` (`idCenCos`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_ActividadCultivo_Laboratorio1`
      FOREIGN KEY (`idAnaLabPer`)
      REFERENCES `sia`.`AnalisisLaboratorio` (`idAnaLab`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`ResponsableActividad`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`ResponsableActividad` (
    `idResAct` INT NOT NULL AUTO_INCREMENT,
    `valHorResAct` DECIMAL(5,2) NULL COMMENT 'valor por cada hora de la actividad',
    `idActCulPer` INT NOT NULL,
    `cedulaPer` VARCHAR(10) NOT NULL,
    PRIMARY KEY (`idResAct`),
    INDEX `fk_ResponsableActividad_ActividadCultivo1_idx` (`idActCulPer` ASC) ,
    INDEX `fk_ResponsableActividad_PersonalGranja1_idx` (`cedulaPer` ASC) ,
    CONSTRAINT `fk_ResponsableActividad_ActividadCultivo1`
      FOREIGN KEY (`idActCulPer`)
      REFERENCES `sia`.`ActividadCultivo` (`idActCul`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_ResponsableActividad_PersonalGranja1`
      FOREIGN KEY (`cedulaPer`)
      REFERENCES `sia`.`PersonalGranja` (`cedPerGra`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`TipoRecurso`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`TipoRecurso` (
    `idTipRec` INT NOT NULL AUTO_INCREMENT,
    `nomTipRec` VARCHAR(45) NOT NULL COMMENT 'nombre del tipo del recurso',
    PRIMARY KEY (`idTipRec`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`Recursos`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`Recursos` (
    `idRec` INT NOT NULL AUTO_INCREMENT,
    `nomRec` VARCHAR(45) NOT NULL,
    `cosRec` DECIMAL(5,2) NOT NULL,
    `modRec` VARCHAR(45) NOT NULL COMMENT 'modelo del recurso',
    `marRec` VARCHAR(45) NOT NULL COMMENT 'marca del recurso',
    `plaRec` VARCHAR(45) NULL COMMENT 'placa de recurso',
    `idTipRecPer` INT NOT NULL,
    `idUniPer` VARCHAR(3) NOT NULL,
    `idGraPer` INT NOT NULL,
    PRIMARY KEY (`idRec`),
    INDEX `fk_Recursos_Unidades1_idx` (`idUniPer` ASC) ,
    INDEX `fk_Recursos_TipoRecurso1_idx` (`idTipRecPer` ASC) ,
    INDEX `fk_Recursos_Granja1_idx` (`idGraPer` ASC) ,
    CONSTRAINT `fk_Recursos_Unidades1`
      FOREIGN KEY (`idUniPer`)
      REFERENCES `sia`.`Unidades` (`idUni`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_Recursos_TipoRecurso1`
      FOREIGN KEY (`idTipRecPer`)
      REFERENCES `sia`.`TipoRecurso` (`idTipRec`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_Recursos_Granja1`
      FOREIGN KEY (`idGraPer`)
      REFERENCES `sia`.`Granja` (`idGra`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`Almacen`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`Almacen` (
    `idAlm` VARCHAR(10) NOT NULL,
    `nomAlm` VARCHAR(45) NOT NULL,
    `actAlm` TINYINT NOT NULL COMMENT 'si esta activo o no el almacen',
    `idEstPer` INT NOT NULL,
    `idGraPer` INT NOT NULL,
    PRIMARY KEY (`idAlm`),
    INDEX `fk_Almacen_Estado1_idx` (`idEstPer` ASC) ,
    INDEX `fk_Almacen_Granja1_idx` (`idGraPer` ASC) ,
    CONSTRAINT `fk_Almacen_Estado1`
      FOREIGN KEY (`idEstPer`)
      REFERENCES `sia`.`Estado` (`idEst`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_Almacen_Granja1`
      FOREIGN KEY (`idGraPer`)
      REFERENCES `sia`.`Granja` (`idGra`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`TipoDocumento`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`TipoDocumento` (
    `idTipDoc` VARCHAR(3) NOT NULL,
    `nomTipDoc` VARCHAR(45) NOT NULL,
    PRIMARY KEY (`idTipDoc`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`EntradaSalida`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`EntradaSalida` (
    `idEntSal` INT NOT NULL AUTO_INCREMENT,
    `idTipDocPer` VARCHAR(3) NOT NULL,
    `nomEntSal` VARCHAR(45) NOT NULL,
    `fecEntSal` DATETIME NOT NULL,
    `idActCulPer` INT NOT NULL,
    `idAlmPer` VARCHAR(10) NOT NULL,
    `idEstPer` INT NOT NULL,
    PRIMARY KEY (`idEntSal`, `idTipDocPer`),
    INDEX `fk_EntradaSalida_ActividadCultivo1_idx` (`idActCulPer` ASC) ,
    INDEX `fk_EntradaSalida_Almacen1_idx` (`idAlmPer` ASC) ,
    INDEX `fk_EntradaSalida_TipoDocumento1_idx` (`idTipDocPer` ASC) ,
    INDEX `fk_EntradaSalida_Estado1_idx` (`idEstPer` ASC) ,
    CONSTRAINT `fk_EntradaSalida_ActividadCultivo1`
      FOREIGN KEY (`idActCulPer`)
      REFERENCES `sia`.`ActividadCultivo` (`idActCul`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_EntradaSalida_Almacen1`
      FOREIGN KEY (`idAlmPer`)
      REFERENCES `sia`.`Almacen` (`idAlm`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_EntradaSalida_TipoDocumento1`
      FOREIGN KEY (`idTipDocPer`)
      REFERENCES `sia`.`TipoDocumento` (`idTipDoc`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_EntradaSalida_Estado1`
      FOREIGN KEY (`idEstPer`)
      REFERENCES `sia`.`Estado` (`idEst`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`MovimientoLote`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`MovimientoLote` (
    `idMovLot` INT NOT NULL AUTO_INCREMENT,
    `fecMovLot` DATETIME NOT NULL COMMENT 'fecha que se realizo el movimiento del lote',
    `canMovLot` INT NOT NULL COMMENT 'cantidad del movimiento',
    `cosMovLot` DECIMAL(5,2) NULL COMMENT 'costo del movimiento (unitario)',
    `cosComMovLot` DECIMAL(5,2) NULL COMMENT 'costo compra del movimiento (unitario)',
    `entMovLot` TINYINT NOT NULL COMMENT 'indica si es entrada o salida del movimiento',
    `desMovLot` VARCHAR(80) NULL COMMENT 'descripcion del movimiento lote',
    `impMovLot` DECIMAL(10,2) NULL COMMENT 'impuesto o valor del iva',
    `porMovLot` DECIMAL(10) NULL COMMENT 'porcentaje del iva',
    `arrRecMovLot` TINYINT NOT NULL COMMENT 'campo de si o no de si se arrienda un recurso',
    `idRecPer` INT NULL,
    `idEntSalPer` INT NOT NULL,
    `idTipDocPer` VARCHAR(3) NOT NULL,
    PRIMARY KEY (`idMovLot`),
    INDEX `fk_MovimientoLote_Recursos1_idx` (`idRecPer` ASC) ,
    INDEX `fk_MovimientoLote_EntradaSalida1_idx` (`idEntSalPer` ASC, `idTipDocPer` ASC) ,
    CONSTRAINT `fk_MovimientoLote_Recursos1`
      FOREIGN KEY (`idRecPer`)
      REFERENCES `sia`.`Recursos` (`idRec`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_MovimientoLote_EntradaSalida1`
      FOREIGN KEY (`idEntSalPer` , `idTipDocPer`)
      REFERENCES `sia`.`EntradaSalida` (`idEntSal` , `idTipDocPer`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`PlantasVariedades`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`PlantasVariedades` (
    `idPlaVar` INT NOT NULL AUTO_INCREMENT,
    `tipPlaVar` VARCHAR(45) NOT NULL,
    `idTipCulPer` INT NOT NULL,
    PRIMARY KEY (`idPlaVar`),
    INDEX `fk_PlantasVariedades_TipoCultivo1_idx` (`idTipCulPer` ASC) ,
    CONSTRAINT `fk_PlantasVariedades_TipoCultivo1`
      FOREIGN KEY (`idTipCulPer`)
      REFERENCES `sia`.`TipoCultivo` (`idTipCul`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`Plantacion`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`Plantacion` (
    `idPla` INT NOT NULL AUTO_INCREMENT,
    `numPlaPla` INT NULL COMMENT 'numero de plantas',
    `numFilPla` INT NULL COMMENT 'numero de filasa de la plantacion',
    `numPlaFil` INT NULL COMMENT 'numero de plantas por fila de la plantacion',
    `supPla` DECIMAL(5,2) NULL,
    `disFilPla` DECIMAL(5,2) NULL COMMENT 'distancia entre filas de la plantacion',
    `fecIniPla` DATETIME NOT NULL COMMENT 'Fecha de la plantacion',
    `fecFinPla` DATETIME NULL,
    `obsPlan` VARCHAR(150) NULL,
    `idCenCosPer` VARCHAR(20) NOT NULL,
    `lotCenCosPer` VARCHAR(45) NOT NULL,
    `idAreCulPer` INT NOT NULL,
    `idPlaVarPer` INT NOT NULL,
    `idEstPer` INT NOT NULL,
    PRIMARY KEY (`idPla`),
    INDEX `fk_Plantacion_CentroCosto1_idx` (`idCenCosPer` ASC, `lotCenCosPer` ASC, `idAreCulPer` ASC) ,
    INDEX `fk_Plantacion_PlantasVariedades1_idx` (`idPlaVarPer` ASC) ,
    INDEX `fk_Plantacion_Estado1_idx` (`idEstPer` ASC) ,
    CONSTRAINT `fk_Plantacion_CentroCosto1`
      FOREIGN KEY (`idCenCosPer` , `lotCenCosPer` , `idAreCulPer`)
      REFERENCES `sia`.`CentroCosto` (`idCenCos` , `lotCenCos` , `idAreCulPer`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_Plantacion_PlantasVariedades1`
      FOREIGN KEY (`idPlaVarPer`)
      REFERENCES `sia`.`PlantasVariedades` (`idPlaVar`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_Plantacion_Estado1`
      FOREIGN KEY (`idEstPer`)
      REFERENCES `sia`.`Estado` (`idEst`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`DetalleRendimientoEsperado`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`DetalleRendimientoEsperado` (
    `idDetRenEsp` INT NOT NULL AUTO_INCREMENT,
    `nomDetRenEsp` VARCHAR(60) NOT NULL COMMENT 'nombre de la tarea',
    `desDetRenEsp` VARCHAR(300) NULL COMMENT 'descripcion del tiopo de rendimiento',
    `idTipRenPer` INT NOT NULL,
    `idTipAnaPer` INT NOT NULL,
    `idGraPer` INT NOT NULL,
    PRIMARY KEY (`idDetRenEsp`),
    INDEX `fk_TareasTipoRendimiento_TipoRendimiento1_idx` (`idTipRenPer` ASC) ,
    INDEX `fk_TareasTipoRendimiento_TipoAnalisis1_idx` (`idTipAnaPer` ASC) ,
    INDEX `fk_DetalleRendimientoEsperado_Granja1_idx` (`idGraPer` ASC) ,
    CONSTRAINT `fk_TareasTipoRendimiento_TipoRendimiento1`
      FOREIGN KEY (`idTipRenPer`)
      REFERENCES `sia`.`TipoRendimiento` (`idTipRen`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_TareasTipoRendimiento_TipoAnalisis1`
      FOREIGN KEY (`idTipAnaPer`)
      REFERENCES `sia`.`TipoAnalisis` (`idTipAna`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_DetalleRendimientoEsperado_Granja1`
      FOREIGN KEY (`idGraPer`)
      REFERENCES `sia`.`Granja` (`idGra`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`Rendimiento`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`Rendimiento` (
    `idRen` INT NOT NULL AUTO_INCREMENT,
    `renRen` INT NOT NULL COMMENT 'Rendimiento Esperado',
    `preRen` DECIMAL(5,2) NOT NULL COMMENT 'precio del rendimiento',
    `ingRen` DECIMAL(5,2) NULL COMMENT 'ingreso del rendimiento',
    `obsRen` VARCHAR(150) NULL,
    `idPlaVarPer` INT NOT NULL,
    `idUniPer` VARCHAR(3) NOT NULL,
    `idEstPer` INT NOT NULL,
    PRIMARY KEY (`idRen`),
    INDEX `fk_Rendimiento_PlantasVariedades1_idx` (`idPlaVarPer` ASC) ,
    INDEX `fk_Rendimiento_Unidades1_idx` (`idUniPer` ASC) ,
    INDEX `fk_Rendimiento_Estado1_idx` (`idEstPer` ASC) ,
    CONSTRAINT `fk_Rendimiento_PlantasVariedades1`
      FOREIGN KEY (`idPlaVarPer`)
      REFERENCES `sia`.`PlantasVariedades` (`idPlaVar`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_Rendimiento_Unidades1`
      FOREIGN KEY (`idUniPer`)
      REFERENCES `sia`.`Unidades` (`idUni`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_Rendimiento_Estado1`
      FOREIGN KEY (`idEstPer`)
      REFERENCES `sia`.`Estado` (`idEst`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`DetalleLaboratorio`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`DetalleLaboratorio` (
    `idDetLab` INT NOT NULL AUTO_INCREMENT,
    `resDetLab` VARCHAR(150) NOT NULL COMMENT 'resultado del examen del laboratorio',
    `nitDetLab` INT NULL COMMENT 'nitrogeno del resultado',
    `hpDetLab` DECIMAL(5,2) NULL COMMENT 'hp del resultado',
    `humDetLab` DECIMAL(5,2) NULL COMMENT 'humus del resultado del laboratorio en porcentaje',
    `p2o5DetLab` VARCHAR(20) NULL COMMENT 'p205 del resultado',
    `k2oDetLab` VARCHAR(20) NULL COMMENT 'k2o del resultado',
    `docDetLab` BLOB NULL COMMENT 'documento (subir)  del resultado',
    `idAnaLabPer` INT NOT NULL,
    PRIMARY KEY (`idDetLab`),
    INDEX `fk_DetalleLaboratorio_Laboratorio1_idx` (`idAnaLabPer` ASC) ,
    CONSTRAINT `fk_DetalleLaboratorio_Laboratorio1`
      FOREIGN KEY (`idAnaLabPer`)
      REFERENCES `sia`.`AnalisisLaboratorio` (`idAnaLab`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`MedidasAmbientales`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`MedidasAmbientales` (
    `idMedAmb` INT NOT NULL AUTO_INCREMENT,
    `nomMedAmb` VARCHAR(60) NOT NULL COMMENT 'temperatura\nhumedad\nviento\n',
    `uniMedAmb` VARCHAR(45) NOT NULL COMMENT 'unidades de las medidas hambientales:\ngrados centigrados\nhpa\nkm/h',
    PRIMARY KEY (`idMedAmb`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`InformacionAmbiental`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`InformacionAmbiental` (
    `idInfAmb` INT NOT NULL AUTO_INCREMENT,
    `fecInfAmb` DATETIME NOT NULL COMMENT 'fecha de toma de la informacion',
    `valInfAmb` DECIMAL(5,2) NOT NULL COMMENT 'valor de la informacion hambiental',
    `desInfAmb` VARCHAR(150) NULL COMMENT 'descripcion o observacion de la informacion hambiental',
    `idPlaPer` INT NULL,
    `idMedAmbPer` INT NOT NULL,
    `idActCulPer` INT NOT NULL,
    PRIMARY KEY (`idInfAmb`),
    INDEX `fk_InformacionHambiental_MedidasHambientales1_idx` (`idMedAmbPer` ASC) ,
    INDEX `fk_InformacionAmbiental_Plantacion1_idx` (`idPlaPer` ASC) ,
    INDEX `fk_InformacionAmbiental_ActividadCultivo1_idx` (`idActCulPer` ASC) ,
    CONSTRAINT `fk_InformacionHambiental_MedidasHambientales1`
      FOREIGN KEY (`idMedAmbPer`)
      REFERENCES `sia`.`MedidasAmbientales` (`idMedAmb`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_InformacionAmbiental_Plantacion1`
      FOREIGN KEY (`idPlaPer`)
      REFERENCES `sia`.`Plantacion` (`idPla`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_InformacionAmbiental_ActividadCultivo1`
      FOREIGN KEY (`idActCulPer`)
      REFERENCES `sia`.`ActividadCultivo` (`idActCul`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`Periodicidad`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`Periodicidad` (
    `idPer` INT NOT NULL AUTO_INCREMENT,
    `nomPer` VARCHAR(45) NOT NULL COMMENT 'nombre de la periodicidad para la notificacion',
    `perPer` INT NOT NULL COMMENT 'periodo en dias de la notificacion',
    `idActCulPer` INT NOT NULL,
    PRIMARY KEY (`idPer`),
    INDEX `fk_Periodicidad_ActividadCultivo1_idx` (`idActCulPer` ASC) ,
    CONSTRAINT `fk_Periodicidad_ActividadCultivo1`
      FOREIGN KEY (`idActCulPer`)
      REFERENCES `sia`.`ActividadCultivo` (`idActCul`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`ImagenPlantacion`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`ImagenPlantacion` (
    `idImaPla` INT NOT NULL,
    `fecImaPla` DATETIME NOT NULL,
    `imaImaPla` BLOB NULL COMMENT 'imagen de la plantacion',
    `obsImaPla` VARCHAR(150) NULL,
    `idActCulPer` INT NOT NULL AUTO_INCREMENT,
    `idPlaPer` INT NOT NULL,
    PRIMARY KEY (`idImaPla`),
    INDEX `fk_ImagenPlantacion_ActividadCultivo1_idx` (`idActCulPer` ASC) ,
    INDEX `fk_ImagenPlantacion_Plantacion1_idx` (`idPlaPer` ASC) ,
    CONSTRAINT `fk_ImagenPlantacion_ActividadCultivo1`
      FOREIGN KEY (`idActCulPer`)
      REFERENCES `sia`.`ActividadCultivo` (`idActCul`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION,
    CONSTRAINT `fk_ImagenPlantacion_Plantacion1`
      FOREIGN KEY (`idPlaPer`)
      REFERENCES `sia`.`Plantacion` (`idPla`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`TipoParametro`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`TipoParametro` (
    `idTipPar` VARCHAR(3) NOT NULL,
    `nomTipPar` VARCHAR(45) NOT NULL,
    PRIMARY KEY (`idTipPar`))
  ENGINE = InnoDB;
  
  
  -- -----------------------------------------------------
  -- Table `sia`.`ParametrosSistema`
  -- -----------------------------------------------------
  CREATE TABLE IF NOT EXISTS `sia`.`ParametrosSistema` (
    `idParSis` INT NOT NULL AUTO_INCREMENT,
    `nomParSis` VARCHAR(45) NULL,
    `valParSis` DECIMAL(18,4) NULL COMMENT 'valor del parametro',
    `desParSis` VARCHAR(150) NULL,
    `idTipParPer` VARCHAR(3) NOT NULL,
    `actParSis` TINYINT NULL COMMENT 'peimte saber si el campo esta activo o no',
    PRIMARY KEY (`idParSis`),
    INDEX `fk_ParametrosSistema_TipoParametro1_idx` (`idTipParPer` ASC) ,
    CONSTRAINT `fk_ParametrosSistema_TipoParametro1`
      FOREIGN KEY (`idTipParPer`)
      REFERENCES `sia`.`TipoParametro` (`idTipPar`)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION)
  ENGINE = InnoDB;
  
  
  SET SQL_MODE=@OLD_SQL_MODE;
  SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
  SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
  