-- -----------------------------------------------------
-- Table `report_card`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `report_card` (
  `serial_rcd` INT(11) NOT NULL AUTO_INCREMENT,
  `name_rcd` TEXT NULL DEFAULT NULL,
  `route_rcd` TEXT NULL DEFAULT NULL,
  `controller_rcd` TEXT NULL DEFAULT NULL,
  `method_rcd` TEXT NULL DEFAULT NULL,
  `status_rcd` ENUM('ACTIVE', 'INACTIVE') NULL DEFAULT NULL,
  PRIMARY KEY (`serial_rcd`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `level_section_year_report_card`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `level_section_year_report_card` (
  `serial_lrc` INT NOT NULL AUTO_INCREMENT,
  `serial_lvl` INT(11) NOT NULL,
  `serial_scy` INT(11) NOT NULL,
  `serial_set` INT(11) NOT NULL,
  `serial_rcd` INT(11) NOT NULL,
  `type_lrc` ENUM('SUBPERIOD', 'PERIOD', 'YEAR') NULL,
  `status_lrc` ENUM('ACTIVE', 'INACTIVE') NULL,
  PRIMARY KEY (`serial_lrc`),
  INDEX `fk_level_section_year_has_report_card_report_card1_idx` (`serial_rcd` ASC),
  INDEX `fk_level_section_year_has_report_card_level_section_year1_idx` (`serial_lvl` ASC, `serial_scy` ASC, `serial_set` ASC),
  CONSTRAINT `fk_level_section_year_has_report_card_level_section_year1`
    FOREIGN KEY (`serial_lvl` , `serial_scy` , `serial_set`)
    REFERENCES `level_section_year` (`serial_lvl` , `serial_scy` , `serial_set`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_level_section_year_has_report_card_report_card1`
    FOREIGN KEY (`serial_rcd`)
    REFERENCES `report_card` (`serial_rcd`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;

insert into allowed_pages_by_process values ((select serial_prc from process where link_prc ='laravel/public/gradeReport' order by serial_prc  limit 1),'gradereportscontroller@getreportcardmethod' );
insert into allowed_pages_by_process values ((select serial_prc from process where link_prc ='laravel/public/gradeReport' order by serial_prc  desc limit 1),'gradereportscontroller@getreportcardmethod' );
insert into allowed_pages_by_process values ((select serial_prc from process where link_prc ='laravel/public/gradeReport' order by serial_prc  desc limit 1),'methodsgradereporcontroller@postbaseperiodreportcard' );
insert into allowed_pages_by_process values ((select serial_prc from process where link_prc ='laravel/public/cron' order by serial_prc  limit 1),'coursecontroller@getstudents');

-- Configuración predeterminada para todos los colegios excepto colegio einstein

update school_setup set options='SHOW_PERIOD_REPORT_CARD';
INSERT INTO `report_card` (`serial_rcd`,`name_rcd`,`route_rcd`,`controller_rcd`,`method_rcd`,`status_rcd`) VALUES (1,'Quimestral',NULL,'MethodsGradeReporController','postBasePeriodReportCard','ACTIVE');
insert into level_section_year_report_card select null as serial_lrc,serial_lvl,serial_scy,serial_set, 1 as serial_rcd, 'PERIOD' as type_lrc, 'ACTIVE' as status_lrc from level_section_year where status_lsy='ACTIVE';


-- Configuración predeterminada para olegio einstein
update school_setup set options='SHOW_PERIOD_REPORT_CARD,SHOW_SUBPERIOD_REPORT_CARD';
INSERT INTO `report_card` (`serial_rcd`,`name_rcd`,`route_rcd`,`controller_rcd`,`method_rcd`,`status_rcd`) VALUES (1,'Quimestral',NULL,'GradeReportsController','postStudentAveragesByPeriod','ACTIVE');
insert into level_section_year_report_card select null as serial_lrc,serial_lvl,serial_scy,serial_set, 1 as serial_rcd, 'PERIOD' as type_lrc, 'ACTIVE' as status_lrc from level_section_year where status_lsy='ACTIVE';
