<?php

class ReportesController extends ApplicationController{

	public function initialize(){
		$this->setTemplateAfter(Session::get("layout"));
		$this->setPersistance(true);
	}

	public function indexAction(){
        parent::beforeFilter();
        $session = Session::getData('AUTH_IDENTITY');
        $usuarios = $this->Usuarios->findFirst("documento = '".$session['documento']."' AND tipo_usuario_id='".$session['tipo_usuario_id']."'");
        $this->setParamToView('usuarios',$usuarios);
        $this->setParamToView("title","Hoja de vida");

	}

	public function traerEstudiosAction(){
		try{
			$this->setResponse("ajax");
			$session = Session::getData('AUTH_IDENTITY');
			$data = $this->Estudios->find("documento = '".$session['documento']."' AND tipo_usuario_id='".$session['tipo_usuario_id']."'");
			$html = "";
			$html .= '<thead>';
			$html .= '<tr>';
			$html .= '<th>Institucion</th>';
			$html .='<th class="text-right">Actions</th>';
			$html .= '</tr>';
			$html .= '</thead>';
			$html .= '<tbody>';
			foreach($data as $reg){
				$html .= "<tr>";
				$html .= "<td>{$reg->getInstitucion()}</td>";
				$html .='<td class="td-actions text-right">';
				$html .='<a rel="tooltip" title="" class="btn btn-success btn-link btn-xs" data-original-title="Editar"  onclick="editarEst('.$reg->getId().')" >';
				$html .='<i class="fa fa-edit"></i>';
				$html .='</a>';
				$html .='<a rel="tooltip" title="" class="btn btn-danger btn-link btn-xs" data-original-title="Eliminar" onclick="borrarEst('.$reg->getId().')">';
				$html .='<i class="fa fa-times"></i>';
				$html .='</a>';
				$html .="</td>";
				$html .= "</tr>";
			}
			$html .= '</tbody>';
			$response["flag"] = true;
			$response["data"] = $html;
		}catch(DbException $e){
			$response["flag"] = false;
			$response["msg"] = "Error inesperado";
		}
		$this->renderText($this->jsonEncode($response));
	}

	public function traerLaboralAction(){
		try{
			$this->setResponse("ajax");
			$session = Session::getData('AUTH_IDENTITY');
			$data = $this->Laboral->find("documento = '".$session['documento']."' AND tipo_usuario_id='".$session['tipo_usuario_id']."'");
			$html = "";
			$html .='<thead>';
			$html .='<tr>';
			$html .='<th>Nombre Empresa</th>';
			$html .='<th>Fecha Ingreso</th>';
			$html .='<th>Fecha Salida</th>';
			$html .='<th class="text-right">Actions</th>';
			$html .='</tr>';
			$html .='</thead>';
			$html .='<tbody>';
			foreach($data as $reg){
				$html .= "<tr>";
				$html .= "<td>{$reg->getRazsoc()}</td>";
				$html .= "<td>{$reg->getFecini()}</td>";
				$html .= "<td>{$reg->getFecfin()}</td>";
				$html .='<td class="td-actions text-right">';
				$html .='<a rel="tooltip" title="" class="btn btn-success btn-link btn-xs" data-original-title="Editar"  onclick="editarLab('.$reg->getId().')" >';
				$html .='<i class="fa fa-edit"></i>';
				$html .='</a>';
				$html .='<a rel="tooltip" title="" class="btn btn-danger btn-link btn-xs" data-original-title="Eliminar" onclick="borrarLab('.$reg->getId().')">';
				$html .='<i class="fa fa-times"></i>';
				$html .='</a>';
				$html .="</td>";
				$html .= "</tr>";
			}
			$html .='</tbody>';
			$response["flag"] = true;
			$response["data"] = $html;
		}catch(DbException $e){
			$response["flag"] = false;
			$response["msg"] = "Error inesperado";
		}
		$this->renderText($this->jsonEncode($response));
	}

    public function traerReferenciasAction(){
        try{
            $this->setResponse("ajax");
            $session = Session::getData('AUTH_IDENTITY');
            $data = $this->Referencias->find("documento = '".$session['documento']."' AND tipo_usuario_id='".$session['tipo_usuario_id']."' AND tipref='P'");
            $html = "";
            $html .= '<thead>';
            $html .= '<tr>';
            $html .= '<th>Nombre</th>';
            $html .= '<th>Parentesco</th>';
            $html .='<th class="text-right">Actions</th>';
            $html .= '</tr>';
            $html .= '</thead>';
            $html .= '<tbody>';
            foreach($data as $reg){
                $html .= "<tr>";
                $html .= "<td>{$reg->getNomref()}</td>";
                $html .= "<td>{$reg->getParent()}</td>";
                $html .='<td class="td-actions text-right">';
                $html .='<a rel="tooltip" title="" class="btn btn-success btn-link btn-xs" data-original-title="Editar"  onclick="editarRef('.$reg->getId().')" >';
                $html .='<i class="fa fa-edit"></i>';
                $html .='</a>';
                $html .='<a rel="tooltip" title="" class="btn btn-danger btn-link btn-xs" data-original-title="Eliminar" onclick="borrarRef('.$reg->getId().')">';
                $html .='<i class="fa fa-times"></i>';
                $html .='</a>';
                $html .="</td>";
                $html .= "</tr>";
            }
            $html .= '</tbody>';
            $response["flag"] = true;
            $response["data"] = $html;
        }catch(DbException $e){
            $response["flag"] = false;
            $response["msg"] = "Error inesperado";
        }
        $this->renderText($this->jsonEncode($response));
    }

    public function traerReferenciasLabAction(){
        try{
            $this->setResponse("ajax");
            $session = Session::getData('AUTH_IDENTITY');
            $data = $this->Referencias->find("documento = '".$session['documento']."' AND tipo_usuario_id='".$session['tipo_usuario_id']."' AND tipref='L'");
            $html = "";
            $html .= '<thead>';
            $html .= '<tr>';
            $html .= '<th>Nombre</th>';
            $html .= '<th class="text-right">Actions</th>';
            $html .= '</tr>';
            $html .= '</thead>';
            $html .= '<tbody>';
            foreach($data as $reg){
                $html .= "<tr>";
                $html .= "<td>{$reg->getNomref()}</td>";
                $html .='<td class="td-actions text-right">';
                $html .='<a rel="tooltip" title="" class="btn btn-success btn-link btn-xs" data-original-title="Editar"  onclick="editarRefLab('.$reg->getId().')" >';
                $html .='<i class="fa fa-edit"></i>';
                $html .='</a>';
                $html .='<a rel="tooltip" title="" class="btn btn-danger btn-link btn-xs" data-original-title="Eliminar" onclick="borrarRefLab('.$reg->getId().')">';
                $html .='<i class="fa fa-times"></i>';
                $html .='</a>';
                $html .="</td>";
                $html .= "</tr>";
            }
            $html .= '</tbody>';
            $response["flag"] = true;
            $response["data"] = $html;
        }catch(DbException $e){
            $response["flag"] = false;
            $response["msg"] = "Error inesperado";
        }
        $this->renderText($this->jsonEncode($response));
    }

    public function traerAdjuntosAction(){
        try{
            $this->setResponse("ajax");
            $session = Session::getData('AUTH_IDENTITY');
            $data = $this->Adjuntos->find("documento = '".$session['documento']."' AND tipo_usuario_id='".$session['tipo_usuario_id']."'");
            $html = "";
            $html .= '<thead>';
            $html .= '<tr>';
            $html .= '<th>Adjunto</th>';
            $html .= '<th class="text-right">Actions</th>';
            $html .= '</tr>';
            $html .= '</thead>';
            $html .= '<tbody>';
            foreach($data as $reg){
		        $archivos = $this->Archivos->findFirst("id='".$reg->getTipaju()."'");
                if($archivos == FALSE)$archivos = New Archivos();
                $html .= "<tr>";
                $html .= "<td>{$archivos->getDetalle()}</td>";
                $html .='<td class="td-actions text-right">';
                $html .='<a rel="tooltip" title="" class="btn btn-success btn-link btn-xs" data-original-title="Eliminar" onclick="window.open('."'../".$reg->getAdjunto()."'".','."'_blank'".')">';
                $html .='<i class="fa fa-eye"></i>';
                $html .='</a>';
                $html .='<a rel="tooltip" title="" class="btn btn-danger btn-link btn-xs" data-original-title="Eliminar" onclick="borrarAdj('.$reg->getId().')">';
                $html .='<i class="fa fa-times"></i>';
                $html .='</a>';
                $html .="</td>";
                $html .= "</tr>";
            }
            $html .= '</tbody>';
            $response["flag"] = true;
            $response["data"] = $html;
        }catch(DbException $e){
            $response["flag"] = false;
            $response["msg"] = "Error inesperado";
            $response["log"] = $e->getMessage();
        }
        $this->renderText($this->jsonEncode($response));
    }

    public function hojaVidaAction(){
        try{
            $this->setResponse("ajax");
            $session = Session::getData('AUTH_IDENTITY');
            $documento = $session['documento'];
            $tipo = $session['tipo_usuario_id'];
            $usuarios = $this->Usuarios->findFirst("documento = '".$session['documento']."' AND tipo_usuario_id='".$session['tipo_usuario_id']."'");
            $estudios = $this->Estudios->find("documento = '".$session['documento']."' AND tipo_usuario_id='".$session['tipo_usuario_id']."'");
            $laboral = $this->Laboral->find("documento = '".$session['documento']."' AND tipo_usuario_id='".$session['tipo_usuario_id']."'");
            $referenciasP = $this->Referencias->find("documento = '".$session['documento']."' AND tipo_usuario_id='".$session['tipo_usuario_id']."' AND tipref='P'");
            $referenciasL = $this->Referencias->find("documento = '".$session['documento']."' AND tipo_usuario_id='".$session['tipo_usuario_id']."' AND tipref='L'");
            $adjuntos = $this->Adjuntos->find("documento = '".$session['documento']."' AND tipo_usuario_id='".$session['tipo_usuario_id']."'");
            $color = array("0","92","133");
            //$color = array("1","124","115");
            //$color = array("69","76","87");
            //$color = array("0","0","0");
            //$color = array("170","170","170");
            $r = $color[0];
            $g = $color[1];
            $b = $color[2];
            /* Inicio Datos */
            $nombres = $usuarios->getPrinom()." ".$usuarios->getSegnom();
            $apellidos = $usuarios->getPriape()." ".$usuarios->getSegape();
            $profesion = $usuarios->getProfesion();
            $correo = $usuarios->getEmail();
            $linked = $usuarios->getLinked();
            $twitter = $usuarios->getTwitter();
            /* Fin Datos */
            $resumen = $usuarios->getAbout();
            /* Inicio habilidades */
            $skills = array("Salesforce","Salesforce");
            $rate = "";
            $desskill = "Prueba";
            /* Fin habilidades */
            $pdf = new FPDF('P','mm','A4');
            $pdf->AddPage();
            $pdf->SetAutoPageBreak(true,-1);
            $pdf->SetTextColor($r,$g,$b);
            $pdf->SetFont('Arial','B','24');
            $pdf->SetFillColor($r,$g,$b);
            $pdf->SetLeftMargin(0);
            $pdf->SetY(0);
            $pdf->Cell(40,8,"",0,1,'L',1);
            $pdf->Cell(40,8,"",0,0,'L',1);
            $pdf->Cell(5,7,"",0,0,'L',0);
            $pdf->Cell(170,8,$nombres." ".$apellidos,0,1,'L',0);
            $pdf->SetFont('Arial','','13');
            $pdf->SetFillColor($r,$g,$b);
            $pdf->Cell(40,10,"",0,0,'L',1);
            $pdf->Cell(5,7,"",0,0,'L',0);
            $pdf->Cell(170,10,$profesion,0,1,'L',0);
            $pdf->SetFont('Arial','','8');
            $pdf->SetTextColor(0);
            $pdf->Cell(40,7,"",0,0,'L',1);
            $pdf->Cell(5,7,"",0,0,'L',0);
            $pdf->Cell(70,7,"Email: ".$correo,0,0,'L',0);
            $pdf->Cell(100,7,"Linked: ".$linked,0,1,'L',0);
            $pdf->Cell(40,7,"",0,0,'L',1);
            $pdf->Cell(5,7,"",0,0,'L',0);
            $pdf->Cell(70,7,"",0,0,'L',0);
            $pdf->Cell(100,7,"Twitter: ".$twitter,0,1,'L',0);
            $pdf->Cell(0,0.3,"",0,1,'L',0);
            $pdf->Cell(40,250,"",0,1,'L',1);
            if($usuarios->getFotohj()!=null && $usuarios->getFotohj()!=""){
                $pdf->Image("public/img/Tesis/FotosHj/".$usuarios->getFotohj(),5,5,30,30);
            }else{
                $pdf->Image("public/img/Tesis/usuario.jpg",5,5,30,30);
            }
            $pdf->SetY(40.3);
            $pdf->Cell(40,7,"",0,0,'L',1);
            $pdf->Cell(5,7,"",0,0,'L',0);
            $pdf->MultiCell(155,5,utf8_decode($resumen),0,'L',0);
            $pdf->Cell(40,10,"",0,0,'L',1);
            $pdf->Cell(5,10,"",0,0,'L',0);
            $pdf->SetTextColor($r,$g,$b);
            $pdf->SetFont('Arial','B','11');
            $pdf->Cell(155,10,"Experiencia",0,1,'L',0);
            $pdf->SetTextColor(0);
            foreach($laboral as $lab){
                $pdf->SetTextColor(255);
                $pdf->SetFont('Arial','B','8');
                $pdf->Cell(40,5,$lab->getFecini()." - ".$lab->getFecfin(),0,0,'R',1);
                $pdf->SetFont('Arial','B','10');
                $pdf->SetTextColor(0);
                $pdf->Cell(5,5,"",0,0,'L',0);
                $pdf->Cell(155,5,"Empresa: ".$lab->getRazsoc(),0,1,'L',0);
                $pdf->SetFont('Arial','','8');
                $pdf->Cell(40,5,"",0,0,'L',1);
                $pdf->Cell(7,5,"",0,0,'L',0);
                $pdf->Cell(155,5,"Cargo: ".$lab->getCargo(),0,1,'L',0);
                $pdf->Cell(40,5,"",0,0,'L',1);
                $pdf->Cell(7,5,"",0,0,'L',0);
                $pdf->SetFont('Arial','B','8');
                $pdf->Cell(155,5,"Responsabilidad",0,1,'L',0);
                $pdf->SetFont('Arial','','8');
                $pdf->Cell(40,5,"",0,0,'L',1);
                $pdf->Cell(10,5,"",0,0,'L',0);
                $pdf->MultiCell(150,5,utf8_decode($lab->getResponsabilidad()),0,'L',0);
            }
            $pdf->Cell(40,10,"",0,0,'L',1);
            $pdf->Cell(5,10,"",0,0,'L',0);
            $pdf->SetTextColor($r,$g,$b);
            $pdf->SetFont('Arial','B','11');
            $pdf->Cell(155,10,"Educacion",0,1,'L',0);
            foreach($estudios as $est){
                $pdf->SetTextColor(255);
                $pdf->SetFont('Arial','B','8');
                $pdf->Cell(40,5,$est->getFecini()." - ".$est->getFecfin(),0,0,'R',1);
                $pdf->SetFont('Arial','B','10');
                $pdf->SetTextColor(0);
                $pdf->Cell(7,5,"",0,0,'L',0);
                $pdf->Cell(155,5,"Institucion ".utf8_decode($est->getInstitucion()),0,1,'L',0);
                $pdf->SetFont('Arial','','8');
                $pdf->Cell(40,5,"",0,0,'L',1);
                $pdf->Cell(10,5,"",0,0,'L',0);
                $pdf->MultiCell(150,5,utf8_decode($est->getDescripcion()),0,'L',0);
            }
            $pdf->Cell(40,10,"",0,0,'L',1);
            $pdf->Cell(5,10,"",0,0,'L',0);
            $pdf->SetTextColor($r,$g,$b);
            $pdf->SetFont('Arial','B','11');
            $pdf->Cell(155,10,"Referencias personales",0,1,'L',0);
            $pdf->SetFont('Arial','','8');
            $pdf->SetTextColor(0);
            foreach($referenciasP as $refp){
                $pdf->SetTextColor(255);
                $pdf->SetFont('Arial','B','8');
                $pdf->Cell(40,5,"",0,0,'R',1);
                $pdf->SetFont('Arial','B','10');
                $pdf->SetTextColor(0);
                $pdf->Cell(7,5,"",0,0,'L',0);
                $pdf->Cell(155,5,utf8_decode($refp->getNomref()),0,1,'L',0);
                $pdf->SetFont('Arial','','8');
                $pdf->Cell(40,4,"",0,0,'L',1);
                $pdf->Cell(10,4,"",0,0,'L',0);
                $pdf->Cell(150,4,"Documento: ".$refp->getDocref(),0,1,'L',0);
                $pdf->Cell(40,4,"",0,0,'L',1);
                $pdf->Cell(10,4,"",0,0,'L',0);
                $pdf->Cell(150,4,"Celular: ".$refp->getCelref(),0,1,'L',0);
                $pdf->Cell(40,4,"",0,0,'L',1);
                $pdf->Cell(10,4,"",0,0,'L',0);
                $pdf->Cell(150,4,"Parentesco: ".utf8_decode($refp->getParent()),0,1,'L',0);
                $pdf->Ln();
            }
            $pdf->Cell(40,10,"",0,0,'L',1);
            $pdf->Cell(5,10,"",0,0,'L',0);
            $pdf->SetTextColor($r,$g,$b);
            $pdf->SetFont('Arial','B','11');
            $pdf->Cell(155,10,"Referencias laborales",0,1,'L',0);
            $pdf->SetFont('Arial','','8');
            $pdf->SetTextColor(0);
            foreach($referenciasL as $refl){
                $pdf->SetTextColor(255);
                $pdf->SetFont('Arial','B','8');
                $pdf->Cell(40,5,"",0,0,'R',1);
                $pdf->SetFont('Arial','B','10');
                $pdf->SetTextColor(0);
                $pdf->Cell(7,5,"",0,0,'L',0);
                $pdf->Cell(155,5,utf8_decode($refl->getNomref()),0,1,'L',0);
                $pdf->SetFont('Arial','','8');
                $pdf->Cell(40,4,"",0,0,'L',1);
                $pdf->Cell(10,4,"",0,0,'L',0);
                $pdf->Cell(150,4,"Documento: ".$refl->getDocref(),0,1,'L',0);
                $pdf->Cell(40,4,"",0,0,'L',1);
                $pdf->Cell(10,4,"",0,0,'L',0);
                $pdf->Cell(150,4,"Celular: ".$refl->getCelref(),0,1,'L',0);
                $pdf->Cell(40,4,"",0,0,'L',1);
                $pdf->Cell(10,4,"",0,0,'L',0);
                $pdf->Cell(150,4,"Cargo: ".utf8_decode($refl->getParent()),0,1,'L',0);
                $pdf->Ln();
            }
            foreach($adjuntos as $adj){
                $pdf->AddPage();
                $pdf->Image($adj->getAdjunto());
            }
            ob_clean();
            $file = "public/files/hojaDeVida-".$session['documento']."-".$session['tipo_usuario_id'].".pdf";
            $pdf->Output($file,"F");
            $response["flag"] = true;
            $response["data"] = $file;
        }catch(DbException $e){
            $response["flag"] = false;
            $response["msg"] = "Error inesperado";
        }
        $this->renderText($this->jsonEncode($response));
    }

    public function personalAction(){
        /*try{
            try{
            */
                $this->setResponse("ajax");
                $transaction = TransactionManager::getUserTransaction();
                $this->Usuarios->setTransaction($transaction);
                $session = Session::getData('AUTH_IDENTITY');
                $documento = $session['documento'];
                $tipo = $session['tipo_usuario_id'];
                $email = $this->getPostParam("email");
                $linked = $this->getPostParam("linked");
                $twitter = $this->getPostParam("twitter");
                $profesion = $this->getPostParam("profesion");
                $about = $this->getPostParam("about");
                $nomarc = "";
                if(isset($_FILES['fotohj'])){
                    $_FILES["fotohj"]['name'] = $documento."_".$tipo."_foto".substr($_FILES["fotohj"]['name'],-4);
                    if($_FILES["fotohj"]['size'] != 0){
                        $path = "public/img/Tesis/FotosHj/";
                        $this->uploadFile("fotohj",getcwd()."/$path/");
                        $dd = pathinfo($_FILES["fotohj"]["name"]);
                        $archivo_nombre = $path.$dd['basename'];
                        $nomarc = $dd['basename'];
                    }
                }
                $usuarios = $this->Usuarios->findFirst("documento = '$documento' AND tipo_usuario_id='{$tipo}'");
                if($usuarios == FALSE){
                    $response["flag"] = false;
                    $response["msg"] = 'Se presento algo, por favor comunicarse con el encargado';
                }
                $usuarios->setTransaction($transaction);
                $usuarios->setEmail($email);
                $usuarios->setTwitter($twitter);
                $usuarios->setLinked($linked);
                $usuarios->setProfesion($profesion);
                $usuarios->setAbout($about);
                if($nomarc != ""){ $usuarios->setFotohj($nomarc); }
                if(!$usuarios->save()){
                    foreach($usuarios->getMessages() as $msg){
                        $this->setLogger($msg->getMessage());
                    }
                    $transaction->rollback();
                }
                $transaction->commit();
                $response["flag"] = true;
                $response["msg"] = 'Registro guardado satisfactoriamente.';
            /*}catch(DbException $e){
                $response["flag"] = false;
                $response["msg"] = 'Registro no pudo ser guardado.';
            }
        }catch(TransactionFailed $tf){
            $response["flag"] = false;
            $response["msg"] = 'Registro no pudo ser guardado.';
        }*/
        $this->renderText($this->jsonEncode($response));
    }

    public function laboralAction(){
        try{
            try{
                $this->setResponse("ajax");
                $transaction = TransactionManager::getUserTransaction();
                $this->Laboral->setTransaction($transaction);
                $session = Session::getData('AUTH_IDENTITY');
                $documento = $session['documento'];
                $tipo = $session['tipo_usuario_id'];
                $id = $this->getPostParam("id");
                $razsoc = $this->getPostParam("razsoc");
                $cargo = $this->getPostParam("cargo");
                $fecini = $this->getPostParam("fecini");
                $fecfin = $this->getPostParam("fecfin");
                $responsabilidad = $this->getPostParam("responsabilidad");
                $laboral = $this->Laboral->findFirst("id  = '$id'");
                if($laboral == FALSE){
                    $laboral = New Laboral();
                }
                $laboral->setTransaction($transaction);
                $laboral->setDocumento($documento);
                $laboral->setTipoUsuarioId($tipo);
                $laboral->setRazsoc($razsoc);
                $laboral->setCargo($cargo);
                $laboral->setFecini($fecini);
                $laboral->setFecfin($fecfin);
                $laboral->setResponsabilidad($responsabilidad);
                if(!$laboral->save()){
                    foreach($laboral->getMessages() as $msg){
                        $this->setLogger($msg->getMessage());
                    }
                    $transaction->rollback();
                }
                $transaction->commit();
                $response["flag"] = true;
                $response["msg"] = 'Registro guardado satisfactoriamente.';
            }catch(DbException $e){
                $this->setLogger($e->getMessage());
                $response["flag"] = false;
                $response["msg"] = 'Registro no pudo ser guardado.';
            }
        }catch(TransactionFailed $tf){
            $response["flag"] = false;
            $response["msg"] = 'Registro no pudo ser guardado.';
        }
        $this->renderText($this->jsonEncode($response));
    }

    public function estudiosAction(){
        try{
            try{
                $this->setResponse("ajax");
                $transaction = TransactionManager::getUserTransaction();
                $this->Laboral->setTransaction($transaction);
                $session = Session::getData('AUTH_IDENTITY');
                $documento = $session['documento'];
                $tipo = $session['tipo_usuario_id'];
                $id = $this->getPostParam("id");
                $institucion = $this->getPostParam("institucion");
                $fecini = $this->getPostParam("fecini");
                $fecfin = $this->getPostParam("fecfin");
                $descripcion = $this->getPostParam("descripcion");
                $estudios = $this->Estudios->findFirst("id  = '$id'");
                if($estudios == FALSE){
                    $estudios = New Estudios();
                }
                $estudios->setTransaction($transaction);
                $estudios->setDocumento($documento);
                $estudios->setTipoUsuarioId($tipo);
                $estudios->setInstitucion($institucion);
                $estudios->setFecini($fecini);
                $estudios->setFecfin($fecfin);
                $estudios->setDescripcion($descripcion);
                if(!$estudios->save()){
                    foreach($estudios->getMessages() as $msg){
                        $this->setLogger($msg->getMessage());
                    }
                    $transaction->rollback();
                }
                $transaction->commit();
                $response["flag"] = true;
                $response["msg"] = 'Registro guardado satisfactoriamente.';
            }catch(DbException $e){
                $this->setLogger($e->getMessage());
                $response["flag"] = false;
                $response["msg"] = 'Registro no pudo ser guardado.';
            }
        }catch(TransactionFailed $tf){
            $response["flag"] = false;
            $response["msg"] = 'Registro no pudo ser guardado.';
        }
        $this->renderText($this->jsonEncode($response));
    }

	public function editarEstAction(){
        try{
		    $this->setResponse("ajax");
            $id = $this->getPostParam("id");
            $estudios = $this->Estudios->findFirst("id = '$id'");
            if($estudios != FALSE){
                $response["flag"] = true;
                $response["data"] = $estudios->getArray();
            }else{
                $response["flag"] = false;
                $response["data"] = "Error inesperado";
            }
        }catch(DbException $e){
            $this->setLogger($e->getMessages());
            $response["flag"] = false;
            $response["msg"] = "Error inesperado";
        }
        $this->renderText($this->jsonEncode($response));
    }

	public function borrarEstAction(){
        try{
            try{
                $this->setResponse("ajax");
                $id = $this->getPostParam("id");
                $transaction = TransactionManager::getUserTransaction();
                $this->Estudios->setTransaction($transaction);
                if(!$this->Estudios->delete("id = '$id'")){
                    foreach($this->estudios->getMessages() as $msg){
                        $this->setLogger($msg->getMessage());
                    }
                    $transaction->rollback();
                }
                $response["flag"] = true;
                $response["msg"] = 'Registro borrado satisfactoriamente.';
                $transaction->commit();
            }catch(DbException $e){
                $this->setLogger($e->getMessage());
                if($e->getCode()==1451){
                    $response["flag"] = false;
                    $response["msg"] = 'El registro se encuentra referenciado, no puede ser borrado.';
                }else{
                    $response["flag"] = false;
                    $response["msg"] = 'El registro no puede ser borrado.';
                }
            }
        }catch(TransactionFailed $tf){
            $response["flag"] = false;
            $response["msg"] = 'El registro no puede ser borrado.';
        }
        $this->renderText($this->jsonEncode($response));
    }

	public function editarLabAction(){
        try{
		    $this->setResponse("ajax");
            $id = $this->getPostParam("id");
            $laboral = $this->Laboral->findFirst("id = '$id'");
            if($laboral != FALSE){
                $response["flag"] = true;
                $response["data"] = $laboral->getArray();
            }else{
                $response["flag"] = false;
                $response["data"] = "Error inesperado";
            }
        }catch(DbException $e){
            $this->setLogger($e->getMessages());
            $response["flag"] = false;
            $response["msg"] = "Error inesperado";
        }
        $this->renderText($this->jsonEncode($response));
    }

	public function borrarLabAction(){
        try{
            try{
                $this->setResponse("ajax");
                $id = $this->getPostParam("id");
                $transaction = TransactionManager::getUserTransaction();
                $this->Laboral->setTransaction($transaction);
                if(!$this->Laboral->delete("id = '$id'")){
                    foreach($this->laboral->getMessages() as $msg){
                        $this->setLogger($msg->getMessage());
                    }
                    $transaction->rollback();
                }
                $response["flag"] = true;
                $response["msg"] = 'Registro borrado satisfactoriamente.';
                $transaction->commit();
            }catch(DbException $e){
                $this->setLogger($e->getMessage());
                if($e->getCode()==1451){
                    $response["flag"] = false;
                    $response["msg"] = 'El registro se encuentra referenciado, no puede ser borrado.';
                }else{
                    $response["flag"] = false;
                    $response["msg"] = 'El registro no puede ser borrado.';
                }
            }
        }catch(TransactionFailed $tf){
            $response["flag"] = false;
            $response["msg"] = 'El registro no puede ser borrado.';
        }
        $this->renderText($this->jsonEncode($response));
    }
    public function referenciasAction(){
        try{
            try{
                $this->setResponse("ajax");
                $transaction = TransactionManager::getUserTransaction();
                $this->Referencias->setTransaction($transaction);
                $session = Session::getData('AUTH_IDENTITY');
                $documento = $session['documento'];
                $tipo = $session['tipo_usuario_id'];
                $id = $this->getPostParam("id");
                $tipref = $this->getPostParam("tipref");
                $nomref = $this->getPostParam("nomref");
                $docref = $this->getPostParam("docref");
                $celref = $this->getPostParam("celref");
                $parent = $this->getPostParam("parent");
                $descripcion = $this->getPostParam("descripcion");
                $referencias = $this->Referencias->findFirst("id  = '$id'");
                if($referencias == FALSE){
                    $referencias = New Referencias();
                }
                $referencias->setTransaction($transaction);
                $referencias->setDocumento($documento);
                $referencias->setTipoUsuarioId($tipo);
                $referencias->setTipref($tipref);
                $referencias->setNomref($nomref);
                $referencias->setDocref($docref);
                $referencias->setCelref($celref);
                $referencias->setParent($parent);
                $referencias->setDescripcion($descripcion);
                if(!$referencias->save()){
                    foreach($referencias->getMessages() as $msg){
                        $this->setLogger($msg->getMessage());
                    }
                    $transaction->rollback();
                }
                $transaction->commit();
                $response["flag"] = true;
                $response["msg"] = 'Registro guardado satisfactoriamente.';
            }catch(DbException $e){
                $this->setLogger($e->getMessage());
                $response["flag"] = false;
                $response["msg"] = 'Registro no pudo ser guardado.';
            }
        }catch(TransactionFailed $tf){
            $response["flag"] = false;
            $response["msg"] = 'Registro no pudo ser guardado.';
        }
        $this->renderText($this->jsonEncode($response));
    }

	public function editarRefAction(){
        try{
		    $this->setResponse("ajax");
            $id = $this->getPostParam("id");
            $referencias = $this->Referencias->findFirst("id = '$id'");
            if($referencias != FALSE){
                $response["flag"] = true;
                $response["data"] = $referencias->getArray();
            }else{
                $response["flag"] = false;
                $response["data"] = "Error inesperado";
            }
        }catch(DbException $e){
            $this->setLogger($e->getMessages());
            $response["flag"] = false;
            $response["msg"] = "Error inesperado";
        }
        $this->renderText($this->jsonEncode($response));
    }

	public function borrarRefAction(){
        try{
            try{
                $this->setResponse("ajax");
                $id = $this->getPostParam("id");
                $transaction = TransactionManager::getUserTransaction();
                $this->Referencias->setTransaction($transaction);
                if(!$this->Referencias->delete("id = '$id'")){
                    foreach($this->estudios->getMessages() as $msg){
                        $this->setLogger($msg->getMessage());
                    }
                    $transaction->rollback();
                }
                $response["flag"] = true;
                $response["msg"] = 'Registro borrado satisfactoriamente.';
                $transaction->commit();
            }catch(DbException $e){
                $this->setLogger($e->getMessage());
                if($e->getCode()==1451){
                    $response["flag"] = false;
                    $response["msg"] = 'El registro se encuentra referenciado, no puede ser borrado.';
                }else{
                    $response["flag"] = false;
                    $response["msg"] = 'El registro no puede ser borrado.';
                }
            }
        }catch(TransactionFailed $tf){
            $response["flag"] = false;
            $response["msg"] = 'El registro no puede ser borrado.';
        }
        $this->renderText($this->jsonEncode($response));
    }

    public function referenciasLabAction(){
        try{
            try{
                $this->setResponse("ajax");
                $transaction = TransactionManager::getUserTransaction();
                $this->Referencias->setTransaction($transaction);
                $session = Session::getData('AUTH_IDENTITY');
                $documento = $session['documento'];
                $tipo = $session['tipo_usuario_id'];
                $id = $this->getPostParam("id");
                $tipref = $this->getPostParam("tipref");
                $nomref = $this->getPostParam("nomref");
                $docref = $this->getPostParam("docref");
                $celref = $this->getPostParam("celref");
                $parent = $this->getPostParam("parent");
                $descripcion = $this->getPostParam("descripcion");
                $referencias = $this->Referencias->findFirst("id  = '$id'");
                if($referencias == FALSE){
                    $referencias = New Referencias();
                }
                $referencias->setTransaction($transaction);
                $referencias->setDocumento($documento);
                $referencias->setTipoUsuarioId($tipo);
                $referencias->setTipref($tipref);
                $referencias->setNomref($nomref);
                $referencias->setDocref($docref);
                $referencias->setCelref($celref);
                $referencias->setParent($parent);
                $referencias->setDescripcion($descripcion);
                if(!$referencias->save()){
                    foreach($referencias->getMessages() as $msg){
                        $this->setLogger($msg->getMessage());
                    }
                    $transaction->rollback();
                }
                $transaction->commit();
                $response["flag"] = true;
                $response["msg"] = 'Registro guardado satisfactoriamente.';
            }catch(DbException $e){
                $this->setLogger($e->getMessage());
                $response["flag"] = false;
                $response["msg"] = 'Registro no pudo ser guardado.';
            }
        }catch(TransactionFailed $tf){
            $response["flag"] = false;
            $response["msg"] = 'Registro no pudo ser guardado.';
        }
        $this->renderText($this->jsonEncode($response));
    }

	public function editarRefLabAction(){
        try{
		    $this->setResponse("ajax");
            $id = $this->getPostParam("id");
            $referencias = $this->Referencias->findFirst("id = '$id'");
            if($referencias != FALSE){
                $response["flag"] = true;
                $response["data"] = $referencias->getArray();
            }else{
                $response["flag"] = false;
                $response["data"] = "Error inesperado";
            }
        }catch(DbException $e){
            $this->setLogger($e->getMessages());
            $response["flag"] = false;
            $response["msg"] = "Error inesperado";
        }
        $this->renderText($this->jsonEncode($response));
    }

	public function borrarRefLabAction(){
        try{
            try{
                $this->setResponse("ajax");
                $id = $this->getPostParam("id");
                $transaction = TransactionManager::getUserTransaction();
                $this->Referencias->setTransaction($transaction);
                if(!$this->Referencias->delete("id = '$id'")){
                    foreach($this->estudios->getMessages() as $msg){
                        $this->setLogger($msg->getMessage());
                    }
                    $transaction->rollback();
                }
                $response["flag"] = true;
                $response["msg"] = 'Registro borrado satisfactoriamente.';
                $transaction->commit();
            }catch(DbException $e){
                $this->setLogger($e->getMessage());
                if($e->getCode()==1451){
                    $response["flag"] = false;
                    $response["msg"] = 'El registro se encuentra referenciado, no puede ser borrado.';
                }else{
                    $response["flag"] = false;
                    $response["msg"] = 'El registro no puede ser borrado.';
                }
            }
        }catch(TransactionFailed $tf){
            $response["flag"] = false;
            $response["msg"] = 'El registro no puede ser borrado.';
        }
        $this->renderText($this->jsonEncode($response));
    }

    public function adjuntosAction(){
        try{
            try{
                $this->setResponse("ajax");
                $transaction = TransactionManager::getUserTransaction();
                $this->Adjuntos->setTransaction($transaction);
                $session = Session::getData('AUTH_IDENTITY');
                $documento = $session['documento'];
                $tipo = $session['tipo_usuario_id'];
                $id = $this->getPostParam("id");
                $tipaju = $this->getPostParam("tipaju");
                $adjunto = $this->getPostParam("adjunto");
				$_FILES["archivo"]['name'] = $documento."_".$tipo."_".$tipaju.substr($_FILES["archivo"]['name'],-4);
				if($_FILES["archivo"]['size'] == 0){
            		$response["flag"] = false;
            		$response["msg"] = 'Registro no pudo ser guardado.';
        			return $this->renderText($this->jsonEncode($response));
				}
				$path = "public/files/adjuntos/";
				$this->uploadFile("archivo",getcwd()."/$path/");
				$dd = pathinfo($_FILES["archivo"]["name"]);
				$archivo_nombre = $path.$dd['basename'];
                $adjuntos = $this->Adjuntos->findFirst("id  = '$id'");
                if($adjuntos == FALSE){
                    $adjuntos = New Adjuntos();
                }
                $adjuntos->setTransaction($transaction);
                $adjuntos->setDocumento($documento);
                $adjuntos->setTipoUsuarioId($tipo);
                $adjuntos->setTipaju($tipaju);
                $adjuntos->setAdjunto($archivo_nombre);
                if(!$adjuntos->save()){
                    foreach($adjuntos->getMessages() as $msg){
                        $this->setLogger($msg->getMessage());
                    }
                    $transaction->rollback();
                }
                $transaction->commit();
                $response["flag"] = true;
                $response["msg"] = 'Registro guardado satisfactoriamente.';
            }catch(DbException $e){
                $this->setLogger($e->getMessage());
                $response["flag"] = false;
                $response["msg"] = 'Registro no pudo ser guardado.';
            }
        }catch(TransactionFailed $tf){
            $response["flag"] = false;
            $response["msg"] = 'Registro no pudo ser guardado.';
        }
        $this->renderText($this->jsonEncode($response));
    }

	public function editarAdjAction(){
        try{
		    $this->setResponse("ajax");
            $id = $this->getPostParam("id");
            $adjuntos = $this->Adjuntos->findFirst("id = '$id'");
            if($adjuntos != FALSE){
                $response["flag"] = true;
                $response["data"] = $adjuntos->getArray();
            }else{
                $response["flag"] = false;
                $response["data"] = "Error inesperado";
            }
        }catch(DbException $e){
            $this->setLogger($e->getMessages());
            $response["flag"] = false;
            $response["msg"] = "Error inesperado";
        }
        $this->renderText($this->jsonEncode($response));
    }

	public function borrarAdjAction(){
        try{
            try{
                $this->setResponse("ajax");
                $id = $this->getPostParam("id");
                $transaction = TransactionManager::getUserTransaction();
                $this->Adjuntos->setTransaction($transaction);
                if(!$this->Adjuntos->delete("id = '$id'")){
                    foreach($this->estudios->getMessages() as $msg){
                        $this->setLogger($msg->getMessage());
                    }
                    $transaction->rollback();
                }
                $response["flag"] = true;
                $response["msg"] = 'Registro borrado satisfactoriamente.';
                $transaction->commit();
            }catch(DbException $e){
                $this->setLogger($e->getMessage());
                if($e->getCode()==1451){
                    $response["flag"] = false;
                    $response["msg"] = 'El registro se encuentra referenciado, no puede ser borrado.';
                }else{
                    $response["flag"] = false;
                    $response["msg"] = 'El registro no puede ser borrado.';
                }
            }
        }catch(TransactionFailed $tf){
            $response["flag"] = false;
            $response["msg"] = 'El registro no puede ser borrado.';
        }
        $this->renderText($this->jsonEncode($response));
    }

    public function consultaXls_viewAction(){
        $this->setParamToView("title","Reporte por fechas");
    }

    public function consultaXlsAction(){
        $fecini = $this->getPostParam("fecini");
        $fecfin = $this->getPostParam("fecfin");
        $fecha = new Date();
        $file = "public/temp/"."reportRanFec-".$fecha->getUsingFormatDefault().".xls";
        $excels = new Spreadsheet_Excel_Writer($file);
        $excel = $excels->addWorksheet();
        $column_title = $excels->addFormat(array('fontfamily' => 'Verdana',
                    'size' => 12,
                    'fgcolor' => 15,
                    'border' => 1,
                    'bordercolor' => 'black',
                    'halign' => 'center'
                    ));
        $title = $excels->addFormat(array(   'fontfamily' => 'Verdana',
                    'size' => 13,
                    'border' => 0,
                    'bordercolor' => 'black',
                    'halign' => 'center'
                    ));
        $column_style = $excels->addFormat(array(   'fontfamily' => 'Verdana',
                    'size' => 11,
                    'border' => 1,
                    'bordercolor' => 'black',
                    ));
        $excel->write(0,1,"Reporte de simulaciones ",$title);
        $columns = array('No.','Documento','Nombre','Tipo usuario','Calificacion','Carrera','Area','Ciudad','Fecha');
        $excel->setColumn(0,0,10);
        $excel->setColumn(1,1,30);
        $excel->setColumn(2,2,70);
        $excel->setColumn(3,9,30);
        $excel->write(1,1,"FECHA INICIAL: $fecini - FECHA FINAL: $fecfin",$title);
        $i = 0;
        $j = 2;
        $x = 0;
        $l = 1;
        foreach($columns as $column){
            $value = $column;
            $excel->setMerge($j,$i,($j+1),$i);
            $excel->write($j, $i++, $value, $column_title);
        }
        $j += 2;
        $condi = "";
        if($fecini != '' && $fecfin != ''){
            $condi = " AND fecha between '$fecini' AND '$fecfin'";
        }
        foreach($this->Cuestionario->findAllBySql("select cuestionario.* from cuestionario,usuarios where cuestionario.documento=usuarios.documento AND cuestionario.tipo_usuario_id=usuarios.tipo_usuario_id $condi") as $cuestionario){
            $usuarios = $this->Usuarios->findFirst("documento = '{$cuestionario->getDocumento()}' AND tipo_usuario_id='{$cuestionario->getTipoUsuarioId()}'");
            if($usuarios == FALSE){ continue; }
            $tipoUsuario = $this->TipoUsuario->findFirst("id='{$cuestionario->getTipoUsuarioId()}'");
            if($tipoUsuario == FALSE){ $tipoUsuario = New TipoUsuario(); }
            $ciudades = $this->Ciudades->findFirst("id='{$usuarios->getCiudad()}'");
            if($ciudades == FALSE){ $ciudades = New Ciudades(); }
            $detalleCuestionario = $this->DetalleCuestionario->findFirst("cuestionario_id = '{$cuestionario->getId()}'");
            if($detalleCuestionario == FALSE){
                $detalleCuestionario = New DetalleCuestionario();
            }
            $preguntas = $this->Preguntas->findBySql("select preguntas.*, tipo_pregunta.detalle as encabezado from preguntas,tipo_pregunta where preguntas.id = '{$detalleCuestionario->getPreguntasId()}' AND tipo_pregunta.id=preguntas.tipo_pregunta_id limit 1");
            if($preguntas == FALSE){
                $preguntas = New Preguntas();
            }
            $i=0;
            $excel->write($j, $i++, $l++, $column_style);
            $excel->write($j, $i++, $cuestionario->getDocumento(), $column_style);
            $excel->write($j, $i++, $usuarios->getNombre(), $column_style);
            $excel->write($j, $i++, $tipoUsuario->getDetalle(), $column_style);
            $excel->write($j, $i++, $cuestionario->getCalificacion(), $column_style);
            $excel->write($j, $i++, $usuarios->getProfesion(), $column_style);
            $excel->write($j, $i++, $preguntas->getEncabezado(), $column_style);
            $excel->write($j, $i++, $ciudades->getDetalle(), $column_style);
            $excel->write($j, $i++, $cuestionario->getFecha(), $column_style);
            $j++;
            $x++;
        }
        if($x == 0){
            $this->setParamToView("res",array("msg"=>"No hay datos en este rango de fechas.","type"=>"error"));
            return $this->routeTo("action: consultaXls_view");
        }
        $excels->close();
        header("location: ".Core::getInstancePath()."/{$file}");
        $this->routeTo("action: consultaXls_view");
    }

    public function consultaGrupos_viewAction(){
    }

    public function consultaGruposAction(){
        $fecini = $this->getPostParam("fecini");
        $fecfin = $this->getPostParam("fecfin");
        $fecha = new Date();
        $file = "public/temp/"."reportGrupos-".$fecha->getUsingFormatDefault().".xls";
        require_once "Library/Excel/Main.php";
        $excels = new Spreadsheet_Excel_Writer($file);
        $excel = $excels->addWorksheet();
        $column_title = $excels->addFormat(array('fontfamily' => 'Verdana',
                    'size' => 12,
                    'fgcolor' => 15,
                    'border' => 1,
                    'bordercolor' => 'black',
                    'halign' => 'center'
                    ));
        $title = $excels->addFormat(array(   'fontfamily' => 'Verdana',
                    'size' => 13,
                    'border' => 0,
                    'bordercolor' => 'black',
                    'halign' => 'center'
                    ));
        $column_style = $excels->addFormat(array(   'fontfamily' => 'Verdana',
                    'size' => 11,
                    'border' => 1,
                    'bordercolor' => 'black',
                    ));
        $excel->write(0,1,"Reporte de simulaciones",$title);
        $columns = array('No.','Grupo','Cantidad de veces por grupo');
        $excel->setColumn(0,0,10);
        $excel->setColumn(1,1,30);
        $excel->setColumn(2,2,70);
        $excel->write(1,1,"FECHA INICIAL: $fecini - FECHA FINAL: $fecfin",$title);
        $i = 0;
        $j = 2;
        $x = 0;
        $l = 1;
        foreach($columns as $column){
            $value = $column;
            $excel->setMerge($j,$i,($j+1),$i);
            $excel->write($j, $i++, $value, $column_title);
        }
        $j += 2;
        $condi = "";
        if($fecini == '' || $fecfin == ''){
            if($fecini != ''){
                $condi = " AND fecha > '$fecini'";
            }else if($fecfin != ''){
                $condi = " AND fecha < '$fecfin'";
            }
        }else if($fecini != '' && $fecfin != ''){
            $condi = " AND fecha between '$fecini' AND '$fecfin'";
        }
        foreach($this->Grupos->findAllBySql("select grupos.detalle, count(*) as id from cuestionario,usuarios,grupos where cuestionario.documento=usuarios.documento AND cuestionario.tipo_usuario_id=usuarios.tipo_usuario_id AND grupos.id=usuarios.grupo $condi group by usuarios.grupo") as $tabla){
            $i=0;
            $excel->write($j, $i++, $l++, $column_style);
            $excel->write($j, $i++, $tabla->getDetalle(), $column_style);
            $excel->write($j, $i++, $tabla->getId(), $column_style);
            $j++;
            $x++;
        }
        if($x == 0){
            Message::info("No hay datos en este rango de fechas.");
            return $this->routeTo("action: consultaGrupos_view");
        }
        $excels->close();
        header("location: ".Core::getInstancePath()."/{$file}");
        $this->routeTo("action: consultaGrupos_view");
    }

    public function consultaCiuins_viewAction(){
    }
    public function consultaCiuinsAction(){
        $fecini = $this->getPostParam("fecini");
        $fecfin = $this->getPostParam("fecfin");
        $fecha = new Date();
        $file = "public/temp/"."reportCiuins-".$fecha->getUsingFormatDefault().".xls";
        require_once "Library/Excel/Main.php";
        $excels = new Spreadsheet_Excel_Writer($file);
        $excel = $excels->addWorksheet();
        $column_title = $excels->addFormat(array('fontfamily' => 'Verdana',
                    'size' => 12,
                    'fgcolor' => 15,
                    'border' => 1,
                    'bordercolor' => 'black',
                    'halign' => 'center'
                    ));
        $title = $excels->addFormat(array(   'fontfamily' => 'Verdana',
                    'size' => 13,
                    'border' => 0,
                    'bordercolor' => 'black',
                    'halign' => 'center'
                    ));
        $column_style = $excels->addFormat(array(   'fontfamily' => 'Verdana',
                    'size' => 11,
                    'border' => 1,
                    'bordercolor' => 'black',
                    ));
        $excel->write(0,1,"Reporte de simulaciones",$title);
        $columns = array('No.','Ciudad de institucion','Cantidad de veces por ciudad');
        $excel->setColumn(0,0,10);
        $excel->setColumn(1,1,30);
        $excel->setColumn(2,2,70);
        $excel->write(1,1,"FECHA INICIAL: $fecini - FECHA FINAL: $fecfin",$title);
        $i = 0;
        $j = 2;
        $x = 0;
        $l = 1;
        foreach($columns as $column){
            $value = $column;
            $excel->setMerge($j,$i,($j+1),$i);
            $excel->write($j, $i++, $value, $column_title);
        }
        $j += 2;
        $condi = "";
        if($fecini == '' || $fecfin == ''){
            if($fecini != ''){
                $condi = " AND fecha > '$fecini'";
            }else if($fecfin != ''){
                $condi = " AND fecha < '$fecfin'";
            }
        }else if($fecini != '' && $fecfin != ''){
            $condi = " AND fecha between '$fecini' AND '$fecfin'";
        }
        foreach($this->Grupos->findAllBySql("select ciudades.detalle, count(*) as id from cuestionario,usuarios,ciudades where cuestionario.documento=usuarios.documento AND cuestionario.tipo_usuario_id=usuarios.tipo_usuario_id AND ciudades.id=usuarios.ciuins $condi group by usuarios.ciuins") as $tabla){
            $i=0;
            $excel->write($j, $i++, $l++, $column_style);
            $excel->write($j, $i++, $tabla->getDetalle(), $column_style);
            $excel->write($j, $i++, $tabla->getId(), $column_style);
            $j++;
            $x++;
        }
        if($x == 0){
            Message::info("No hay datos en este rango de fechas.");
            return $this->routeTo("action: consultaCiuins_view");
        }
        $excels->close();
        header("location: ".Core::getInstancePath()."/{$file}");
        $this->routeTo("action: consultaCiuins_view");
    }

}
