function view()
 {
     if (!VAR3) {
         die("Error del sistema 404");
     }
     $this->expediente = new tab_expediente();
     $rows = $this->expediente->dbselectByField("exp_id", VAR3);
     $row = $rows[0];
     $this->registry->template->exp_id = $row->exp_id;
     $this->registry->template->ser_id = $row->ser_id;
     $series = new series();
     $uni_id = $series->obtenerSeccionIdSerie($row->ser_id);
     $this->registry->template->series = $series->obtenerSelectSeccionDefaultEdit($_SESSION['USU_ID'], $uni_id, $row->ser_id);
     $this->registry->template->ser_codigo = $series->obtenerCodigoSerie($row->ser_id);
     $this->registry->template->ser_corr = $series->obtenerTipoCorrSerie($row->ser_id);
     $this->registry->template->uni_descripcion = $series->obtenerSeccionSerie($row->ser_id);
     $this->registry->template->exp_codigo = $row->exp_codigo;
     // Dynamic fields
     $expcampo = new expcampo();
     $this->registry->template->expcampo = $expcampo->obtenerSelectCamposEdit($row->ser_id, VAR3);
     $sopfisico = new sopfisico();
     $this->registry->template->sof_id = $sopfisico->obtenerSelect($row->sof_id);
     $this->registry->template->exp_lugar = $row->exp_lugar;
     $this->registry->template->exp_nrofoj = $row->exp_nrofoj;
     $this->registry->template->exp_tomovol = $row->exp_tomovol;
     $this->registry->template->exp_nroejem = $row->exp_nroejem;
     $this->registry->template->exp_nrocaj = $row->exp_nrocaj;
     $this->registry->template->exp_sala = $row->exp_sala;
     $expediente = new expediente();
     $this->registry->template->exp_estante = $expediente->obtenerSelectEstante($row->exp_estante);
     $this->registry->template->exp_cuerpo = $row->exp_cuerpo;
     $this->registry->template->exp_balda = $row->exp_balda;
     $this->registry->template->exp_obs = $row->exp_obs;
     $this->registry->template->exp_ori = $row->exp_ori;
     $this->registry->template->exp_cop = $row->exp_cop;
     $this->registry->template->exp_fot = $row->exp_fot;
     // Validate keywords
     $palclave = new palclave();
     $sis_palclave = $palclave->obtenerSisPalclave();
     if ($sis_palclave == "RECORDAR") {
         $this->registry->template->exp_descripcion = $palclave->listaPCFile2($row->exp_id);
     } else {
         $this->registry->template->exp_descripcion = $palclave->listaPCFile2($row->exp_id);
     }
     // Automatic register
     if ($row->exp_corr == 'AUTO') {
         $this->registry->template->exp_corr = "<OPTION selected>AUTO</OPTION><OPTION>MANUAL</OPTION>";
     } else {
         $this->registry->template->exp_corr = "<OPTION>AUTO</OPTION><OPTION selected>MANUAL</OPTION>";
     }
     // isadg
     $expisadg = new tab_expisadg();
     $rows2 = $expisadg->dbselectByField("exp_id", VAR3);
     $row2 = $rows2[0];
     $this->registry->template->exp_titulo = $row2->exp_titulo;
     $this->registry->template->exp_fecha_exi = $row2->exp_fecha_exi;
     $this->registry->template->exp_mesi = $expediente->obtenerSelectMes($row2->exp_mesi);
     $this->registry->template->exp_anioi = $expediente->obtenerSelectAnio($row2->exp_anioi);
     $this->registry->template->exp_fecha_exf = $row2->exp_fecha_exf;
     $this->registry->template->exp_mesf = $expediente->obtenerSelectMes($row2->exp_mesf);
     $this->registry->template->exp_aniof = $expediente->obtenerSelectAnio($row2->exp_aniof);
     $this->registry->template->exp_volsop = $row2->exp_volsop;
     $this->registry->template->exp_nomprod = $row2->exp_nomprod;
     $this->registry->template->exp_hisins = $row2->exp_hisins;
     $this->registry->template->exp_hisarc = $row2->exp_hisarc;
     $this->registry->template->exp_foring = $row2->exp_foring;
     $this->registry->template->exp_alccon = $row2->exp_alccon;
     $this->registry->template->exp_vaseel = $row2->exp_vaseel;
     $this->registry->template->exp_nueing = $row2->exp_nueing;
     $this->registry->template->exp_org = $row2->exp_org;
     $this->registry->template->exp_conacc = $row2->exp_conacc;
     $this->registry->template->exp_conrep = $row2->exp_conrep;
     $idioma = new idioma();
     $this->registry->template->idi_id = $idioma->obtenerSelect($row2->idi_id);
     $this->registry->template->exp_carfis = $expediente->obtenerSelectEstado($row2->exp_carfis);
     $this->registry->template->exp_insdes = $row2->exp_insdes;
     $this->registry->template->exp_exloor = $row2->exp_exloor;
     $this->registry->template->exp_exloco = $row2->exp_exloco;
     $this->registry->template->exp_underel = $row2->exp_underel;
     $this->registry->template->exp_notpub = $row2->exp_notpub;
     $this->registry->template->exp_notas = $row2->exp_notas;
     $this->registry->template->exp_notarc = $row2->exp_notarc;
     $this->registry->template->exp_regnor = $row2->exp_regnor;
     $this->registry->template->exp_fecdes = $row2->exp_fecdes;
     $eus = new Tab_expusuario();
     $row_eus = $eus->dbselectBy2Field("exp_id", VAR3, "eus_estado", 1);
     $usu_id = $_SESSION['USU_ID'];
     if (!is_null($row_eus) && count($row_eus) > 0) {
         $usu_id = $row_eus[0]->usu_id;
     }
     // Keywords
     //        $palclave = new palclave();
     //        $this->registry->template->pac_nombre = $palclave->listaPC();
     $this->registry->template->pac_nombre = "";
     if (VAR4) {
         if (VAR4 == 0) {
             $msm = "HUBO ERROR AL REGISTRAR EL EXPEDIENTE!";
         } else {
             if (VAR4 == 1) {
                 $msm = "SE GUARDO CORRECTAMENTE EL EXPEDIENTE!";
             } else {
                 $msm = "";
             }
         }
     } else {
         $msm = "";
     }
     $this->registry->template->msm = $msm;
     $this->registry->template->PATH_WEB = PATH_WEB;
     $this->registry->template->PATH_DOMAIN = PATH_DOMAIN;
     $this->registry->template->PATH_EVENT = "update";
     $this->registry->template->GRID_SW = "true";
     $this->registry->template->PATH_J = "jquery-1.4.1";
     $this->registry->template->titulo = "HOJA DE TRABAJO - Editar";
     $this->menu = new menu();
     $this->liMenu = $this->menu->imprimirMenu(VAR1, $_SESSION['USU_ID']);
     $this->registry->template->men_titulo = $this->liMenu;
     $this->registry->template->show('headerG');
     $this->registry->template->show('expediente/tab_expediente.tpl');
     $this->registry->template->show('footer');
 }
 function linkTree($exp_id, $tra_id, $cue_id)
 {
     $expediente = new tab_expediente();
     $tab_expediente = $expediente->dbselectById($exp_id);
     $tab_expisadg = new tab_expisadg();
     $expisadg = $tab_expisadg->dbselectById($exp_id);
     $serie = new series();
     $tab_tramite = new Tab_tramite();
     $tab_tramite = $tab_tramite->dbselectById($tra_id);
     $tab_cuerpo = new Tab_cuerpos();
     $tab_cuerpo = $tab_cuerpo->dbselectById($cue_id);
     $flecha = "<img src='" . PATH_DOMAIN . "/web/img/arrow.png' width=\"12px\" height=\"12px\"/>";
     $serie_des = utf8_decode($serie->getTitle($tab_expediente->getSer_id()));
     $exp_des = utf8_decode($expisadg->getExp_titulo());
     $tramite = utf8_decode($tab_tramite->getTra_descripcion());
     $cuerpo = utf8_decode($tab_cuerpo->getCue_descripcion());
     return "<a href='" . PATH_DOMAIN . "/estrucDocumental/'> {$serie_des}</a> {$flecha}\r\n                <a href='" . PATH_DOMAIN . "/estrucDocumental/viewTree/" . $exp_id . "/'> {$exp_des}</a> {$flecha}\r\n                <a href='" . PATH_DOMAIN . "/estrucDocumental/viewTree/" . $exp_id . "/'> {$tramite} </a> {$flecha}\r\n                <a href='" . PATH_DOMAIN . "/estrucDocumental/viewTree/{$exp_id}/'> {$cuerpo} </a> ";
 }
 function Migrar()
 {
     $msg = "";
     set_time_limit(1024);
     ini_set("memory_limit", "1024M");
     if ($_FILES["archivo"]) {
         $Size = $_FILES["archivo"]['size'];
         $Type = $_FILES["archivo"]['type'];
         $File = $_FILES["archivo"]['name'];
         if ($File != '') {
             $dominio = PATH_FTPDIR_EXCEL;
             $Dir = $dominio . "/" . $File;
             if (copy($_FILES['archivo']['tmp_name'], $Dir)) {
                 $status = "Correcto";
             } else {
                 $status = "Error";
             }
         } else {
             $status = "Error";
         }
     }
     $tipoformato = $_POST['tiporeporte'];
     require_once $dominio . '/PHPExcel/IOFactory.php';
     $objPHPExcel = PHPExcel_IOFactory::load("web/" . $File);
     foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
         $worksheetTitle = $worksheet->getTitle();
         $highestRow = $worksheet->getHighestRow();
         // e.g. 10
         $highestColumn = $worksheet->getHighestColumn();
         // e.g 'F'
         $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
         $nrColumns = ord($highestColumn) - 64;
     }
     $id_serie = "";
     $id_seccion = "";
     //obtener datos de la base de  datos like
     $fechadocAnioInicial = "";
     $fechadocMesInicial = "";
     if ($tipoformato == 1) {
         //GNT-SCT
         $cantidaddoc = $highestRow - 37;
         $fondo = $objPHPExcel->getActiveSheet()->getCell("E8")->getValue();
         $subfondo = $objPHPExcel->getActiveSheet()->getCell("E9")->getValue();
         $seccion = $objPHPExcel->getActiveSheet()->getCell("E10")->getValue();
         $subseccion = $objPHPExcel->getActiveSheet()->getCell("E11")->getValue();
         $serie = $objPHPExcel->getActiveSheet()->getCell("E13")->getValue();
         $tituloexpediente = $objPHPExcel->getActiveSheet()->getCell("E14")->getValue();
         $fechasExtremas = $objPHPExcel->getActiveSheet()->getCell("O13")->getValue();
         $ml = $objPHPExcel->getActiveSheet()->getCell("D16")->getValue();
         $objHoja = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
         $objWorksheet = $objPHPExcel->getActiveSheet();
         $tituloserie = explode("\n", $serie);
         $cantidaserie = count($tituloserie);
         if ($cantidaserie > 1) {
             $msg = "<font color='red'>Error, Elimine los saltos de linea del T&iacute;tulo de la Serie</font><br>";
             unlink($Dir);
             $this->index($msg);
             exit;
         }
         $tituloexp = explode("\n", $tituloexpediente);
         $cantidaexpediente = count($tituloexp);
         if ($cantidaexpediente > 1) {
             $msg = "<font color='red'>Error, Elimine los saltos de linea en T&iacute;tulo de Expediente </font><br>";
             unlink($Dir);
             $this->index($msg);
             exit;
         }
         if ($highestColumn != "Q") {
             $msg = "<font color='red'>FORMATO GNT - SCT NO ES CORRECTO</font>";
             unlink($Dir);
             $this->index($msg);
             exit;
         }
         //$msg= '<table border="1">' . "\n";
         //foreach ($objWorksheet->getRowIterator() as $row) {
         //$msg= '<tr>' . "\n";
         //
         //$cellIterator = $row->getCellIterator();
         //$cellIterator->setIterateOnlyExistingCells(false); // This loops all cells,
         //foreach ($cellIterator as $cell) {
         //$msg= '<td>' . htmlentities($cell->getValue(), ENT_IGNORE, 'utf-8') . '</td>' . "\n";
         //}
         //
         //$msg= '</tr>' . "\n";
         //}
         //$msg= '</table>' . "\n";
         //if(trim($subseccion)=="SUBGERENCIA DE CONSERVACION VIAL"){
         //    $subseccion="PROYECTOS DE CONSERVACION VIAL";
         //}
         $tab_fondo = new Tab_fondo();
         $tab_unidad = new Tab_unidad();
         $tab_series = new Tab_series();
         //obtener fondo y subfondo
         $sql = "select* from tab_fondo where fon_descripcion LIKE '%{$fondo}%'";
         $sql2 = "select* from tab_fondo where fon_descripcion LIKE '%{$subfondo}%'";
         $resultado = $tab_fondo->dbSelectBySQL($sql);
         $resultado2 = $tab_fondo->dbSelectBySQL($sql2);
         $id_fondo = $resultado[0]->fon_id;
         $id_subfondo = $resultado2[0]->fon_id;
         $ubicacion = $resultado2[0]->fon_codigo;
         switch ($ubicacion) {
             case "ON":
                 $ubicacion = "LA PAZ";
                 break;
             case "LP":
                 $ubicacion = "LA PAZ";
                 break;
             case "SC":
                 $ubicacion = "SANTA CRUZ";
                 break;
             case "PT":
                 $ubicacion = "POTOSI";
                 break;
             case "BN":
                 $ubicacion = "BENI";
                 break;
             case "PN":
                 $ubicacion = "PANDO";
                 break;
             case "CB":
                 $ubicacion = "COCHABAMBA";
                 break;
             case "OR":
                 $ubicacion = "ORURO";
                 break;
             case "CH":
                 $ubicacion = "CHUQUISACA";
                 break;
             case "TJ":
                 $ubicacion = "TARIJA";
                 break;
         }
         if ($seccion == "DIRECCION GENERAL TECNICA") {
             if ($id_subfondo == 3) {
                 $seccion = "TECNICA-OPERATIVA";
             } else {
                 $seccion = "AREA TECNICA";
             }
         }
         //obtener el fon_id
         $subseccion = trim($subseccion);
         if ($subseccion == "") {
             $sql3 = "SELECT\r\ntab_unidad.uni_id,\r\nf.fon_id,\r\ntab_unidad.uni_descripcion\r\nFROM tab_fondo as f\r\nINNER JOIN tab_unidad ON f.fon_id = tab_unidad.fon_id\r\nWHERE\r\nf.fon_id = {$id_subfondo} and tab_unidad.uni_descripcion LIKE'%{$seccion}%'";
         } else {
             $sql3 = "SELECT\r\ntab_unidad.uni_id,\r\nf.fon_id,\r\ntab_unidad.uni_descripcion\r\nFROM tab_fondo as f\r\nINNER JOIN tab_unidad ON f.fon_id = tab_unidad.fon_id\r\nWHERE\r\nf.fon_id = {$id_subfondo} and tab_unidad.uni_descripcion LIKE'%{$subseccion}%'";
         }
         $resultado3 = $tab_unidad->dbSelectBySQL($sql3);
         foreach ($resultado3 as $rowseccion) {
             $id_seccion = $rowseccion->uni_id;
         }
         //obtengo la serie
         $sql4 = "SELECT\r\ntab_series.ser_categoria,\r\ntab_series.ser_id\r\nFROM\r\ntab_fondo\r\nINNER JOIN tab_unidad ON tab_fondo.fon_id = tab_unidad.fon_id\r\nINNER JOIN tab_series ON tab_unidad.uni_id = tab_series.uni_id\r\nWHERE\r\ntab_fondo.fon_id = {$id_subfondo} AND tab_series.ser_categoria LIKE '%{$serie}%'";
         $resultado4 = $tab_series->dbSelectBySQL($sql4);
         foreach ($resultado4 as $rowserie) {
             $id_serie = $rowserie->ser_id;
         }
         $ml = $objPHPExcel->getActiveSheet()->getCell("D16")->getValue();
         if ($id_serie == "") {
             $msg = "<font color='red'>Error, No existe la Serie Asignada</font><br>";
             unlink($Dir);
             $this->index($msg);
             exit;
         } else {
             if ($id_subfondo == "") {
                 $msg = "<font color='red'>Error, No existe el Subfondo</font><br>";
                 unlink($Dir);
                 $this->index($msg);
                 exit;
             } else {
                 if ($id_seccion == "") {
                     $msg = "<font color='red'>Error, No existe la Secci&oacute;n</font><br>";
                     unlink($Dir);
                     $this->index($msg);
                     exit;
                 }
             }
         }
         if ($highestColumn == "Q") {
             if ($ml == "ML") {
                 $i = 1;
                 $ct = 18;
                 $t = 0;
                 $expsadg = new Tab_expisadg();
                 $resulall = $expsadg->dbselectByField("exp_titulo", strtoupper($tituloexpediente));
                 foreach ($resulall as $list) {
                     $t++;
                 }
                 $fechafinal = '';
                 $fechainicial = '';
                 $exp_fechas = explode("-", $fechasExtremas);
                 if (!empty($exp_fechas[1])) {
                     $fechafinal = trim($exp_fechas[1]);
                 }
                 if (!empty($exp_fechas[0])) {
                     $fechainicial = trim($exp_fechas[0]);
                 }
                 if ($t > 0) {
                     $msg = "<font color='red'>Error! existe otro nombre duplicado</font>";
                     unlink($Dir);
                     $this->index($msg);
                     exit;
                 }
                 $expediente = new expediente();
                 $hoy = date("Y-m-d");
                 $this->expediente = new tab_expediente();
                 //        $this->expediente->setRequest2Object($_REQUEST);
                 $this->expediente->setExp_id('');
                 $this->expediente->setSer_id($id_serie);
                 // Generation code
                 $this->expediente->setExp_codigo($expediente->generaCodigo($id_serie));
                 $this->expediente->setExp_lugar($ubicacion);
                 $this->expediente->setSof_id(1);
                 $this->expediente->setExp_ori(0);
                 $this->expediente->setExp_cop(0);
                 $this->expediente->setExp_fot(0);
                 $this->expediente->setExp_obs('');
                 $this->expediente->setExp_corr('AUTO');
                 $this->expediente->setExp_estado(1);
                 $this->expediente->setExp_migrarexcel(1);
                 $exp_id = $this->expediente->insert2();
                 // Update count
                 //        if ($_REQUEST['ser_corr'] == 'AUTO') {
                 //            // Auto
                 //            $tseries = new tab_series();
                 //            $row2 = $tseries->dbselectByField("ser_id", $_REQUEST['ser_id']);
                 //            $row2 = $row2[0];
                 //            $tseries->setSer_id($_REQUEST['ser_id']);
                 //            $ser_exp = $row2->ser_exp + 1;
                 //            $tseries->setSer_exp($ser_exp);
                 //            $tseries->update();
                 //        } else {
                 //            // Manual
                 //            $tseries = new tab_series();
                 //            $tseries->setSer_id($_REQUEST['ser_id']);
                 //            $tseries->setSer_exp($_REQUEST['exp_codigo']);
                 //            $tseries->update();
                 //        }
                 //$this->expisadg->setTrm_id(1);
                 //        $expisadg = new tab_expisadg();
                 //        $expisadg->setExp_id($exp_id);
                 //        $expisadg->setExp_titulo($expediente);
                 //        $expisadg->setExp_nomprod($fondo);
                 //        $expisadg->setExp_fecha_exi(date('Y-m-d'));
                 //        $expisadg->setExp_fecha_exf(date('Y-m-d'));
                 //        $expisadg->setExp_anioi($fechainicial);
                 //        $expisadg->setExp_aniof($fechafinal);
                 //        $expisadg->setIdi_id(1);
                 //        $expisadg->setExp_estado(1);
                 //        $eig_id = $expisadg->insert();
                 $fechahoy = date('Y-m-d');
                 $expisadg = new tab_expisadg();
                 $expisadg->setExp_id($exp_id);
                 $expisadg->setExp_titulo($tituloexpediente);
                 $expisadg->setExp_fecha_exi($fechahoy);
                 //        $expisadg->setExp_mesi('');
                 $expisadg->setExp_anioi($fechainicial);
                 $expisadg->setExp_fecha_exf($fechahoy);
                 //        $expisadg->setExp_mesf('');
                 $expisadg->setExp_aniof($fechafinal);
                 $expisadg->setExp_nivdes('EXPEDIENTE');
                 //        $expisadg->setExp_volsop('');
                 $expisadg->setExp_nomprod($fondo);
                 //        $expisadg->setExp_hisins('');
                 //        $expisadg->setExp_hisarc('');
                 $expisadg->setExp_foring('TRANSFERENCIA');
                 //        $expisadg->setExp_alccon('');
                 //        $expisadg->setExp_vaseel('');
                 //        $expisadg->setExp_nueing('');
                 $expisadg->setExp_org('LOS DOCUMENTOS DEL PROYECTO FUERON IDENTIFICADOS, CLASIFICADOS Y ORDENADOS EN LAS CAJAS DE ACUERDO AL CHECK LIST DE LA SERIE A LA QUE CORRESPONDEN.');
                 $expisadg->setExp_conacc('EL ACCESO ESTA SUJETO A LO QUE ESTABLECE LA CONSTITUCION POLITICA DEL ESTADO Y EL ARTICULO 18 DE LA LEY 2341 SOBRE PROCESOS ADMINISTRATIVOS.');
                 //        $expisadg->setExp_conrep('');
                 $expisadg->setIdi_id(1);
                 $expisadg->setExp_carfis('BUENO');
                 //        $expisadg->setExp_insdes('');
                 //        $expisadg->setExp_exloor('');
                 //        $expisadg->setExp_exloco('');
                 //        $expisadg->setExp_underel('');
                 //        $expisadg->setExp_notpub('');
                 //        $expisadg->setExp_notas('');
                 //        $expisadg->setExp_notarc('');
                 $expisadg->setExp_regnor('ISAD-G, ISAAR(CPF), RCAA');
                 $expisadg->setExp_fecdes(date('Y-m-d'));
                 $expisadg->setExp_estado(1);
                 $eig_id = $expisadg->insert();
                 // Save expfondo data
                 $texf = new Tab_expfondo();
                 $texf->setExp_id($exp_id);
                 $usuario = new usuario();
                 $fon_id = $usuario->getFon_id($_SESSION['USU_ID']);
                 $nomUsuario = $usuario->obtenerNombre($_SESSION['USU_ID']);
                 $texf->setExf_fecha_exi($fechahoy);
                 $texf->setFon_id($fon_id);
                 $texf->setExf_estado('1');
                 $texf->insert();
                 // Save expusuario data
                 $this->expusuario = new expusuario();
                 $this->expusuario->saveExp($exp_id, $_SESSION['USU_ID']);
                 //        // Save expcontenedor data
                 //        $con = new expcontenedor();
                 //        $con->saveExpCont($_REQUEST['con_id'], $_REQUEST['suc_id'], $exp_id);
                 //        // Save proyecto list data (tramos)
                 //        if (isset($_REQUEST['lista_tramo'])) {
                 //            $proyectos = $_REQUEST['lista_tramo'];
                 //            foreach ($proyectos as $proyecto) {
                 //                $exp = new tab_expproyecto();
                 //                $exp->setExp_id($exp_id);
                 //                $exp->setPry_id($proyecto);
                 //                $exp->setEpp_estado(1);
                 //                $exp->insert();
                 //            }
                 //        }
                 // Save data dynamic
                 $c = 0;
                 $caj = "";
                 $cnt = 0;
                 //insert usuario serie
                 $tab_usu_serie = new Tab_usu_serie();
                 $sqlususerie = "select* from tab_usu_serie\r\n            where usu_id='" . $_SESSION['USU_ID'] . "'\r\n            and ser_id='" . $id_serie . "'\r\n            and use_estado=1";
                 $comprobar_usu_serie = $tab_usu_serie->dbSelectBySQL($sqlususerie);
                 $cnt = count($comprobar_usu_serie);
                 if ($cnt == 0) {
                     $tab_usu_serie->setUse_id('');
                     $tab_usu_serie->setUsu_id($_SESSION['USU_ID']);
                     $tab_usu_serie->setSer_id($id_serie);
                     $tab_usu_serie->setUse_estado(1);
                     $tab_usu_serie->insert();
                 }
                 while ($i <= $cantidaddoc) {
                     $caja = $objPHPExcel->getActiveSheet()->getCell("A" . $ct)->getValue();
                     $filnroejem = $objPHPExcel->getActiveSheet()->getCell("C" . $ct)->getValue();
                     $correlativo = $objPHPExcel->getActiveSheet()->getCell("E" . $ct)->getValue();
                     $titledoc = $objPHPExcel->getActiveSheet()->getCell("F" . $ct)->getValue();
                     $subtitledoc = $objPHPExcel->getActiveSheet()->getCell("G" . $ct)->getValue();
                     $productor = $objPHPExcel->getActiveSheet()->getCell("H" . $ct)->getValue();
                     $contrato = $objPHPExcel->getActiveSheet()->getCell("I" . $ct)->getValue();
                     $fecha = trim($objPHPExcel->getActiveSheet()->getCell("J" . $ct)->getValue());
                     $tomovol = $objPHPExcel->getActiveSheet()->getCell("K" . $ct)->getValue();
                     $sopfis = $objPHPExcel->getActiveSheet()->getCell("L" . $ct)->getValue();
                     $sala = $objPHPExcel->getActiveSheet()->getCell("M" . $ct)->getValue();
                     $estante = $objPHPExcel->getActiveSheet()->getCell("N" . $ct)->getValue();
                     $cuerpo = $objPHPExcel->getActiveSheet()->getCell("O" . $ct)->getValue();
                     $balda = $objPHPExcel->getActiveSheet()->getCell("P" . $ct)->getValue();
                     $obs = $objPHPExcel->getActiveSheet()->getCell("Q" . $ct)->getValue();
                     //todavia en trabajo
                     if ($titledoc != "") {
                         if ($fecha != "s/f") {
                             $extfe = explode("\n", $fecha);
                             $cantidadfecha = count($extfe);
                             if ($cantidadfecha > 1) {
                                 $fechadocAnioInicial = $extfe[0];
                                 $fechadocMesInicial = $extfe[1];
                             } else {
                                 $fechadocAnioInicial = $extfe[0];
                                 $fechadocMesInicial = "";
                                 if ($fechadocAnioInicial > 30000) {
                                     $fe = date("m-y", (int) $fechadocAnioInicial);
                                     $extraer = explode("-", $fe);
                                     $fechadocAnioInicial = $extraer[1];
                                     $fechadocMesInicial = $extraer[0];
                                 }
                             }
                         }
                         // exit();
                         if ($caja == "") {
                         } else {
                             $extraercaj = explode(" ", trim($caja));
                             $caj = $extraercaj[1];
                         }
                         $id_exp = $exp_id;
                         $this->archivo = new tab_archivo();
                         $this->archivo->setFil_id('');
                         // Generation code max fil_nro
                         $maxFil = new Tab_archivo();
                         $sql2 = "SELECT\r\n                    MAX(tab_archivo.fil_nro) AS maxnro\r\n                    FROM\r\n                    tab_expediente\r\n                    INNER JOIN tab_exparchivo ON tab_exparchivo.exp_id = tab_expediente.exp_id\r\n                    INNER JOIN tab_archivo ON tab_archivo.fil_id = tab_exparchivo.fil_id\r\n                    WHERE\r\n                    tab_expediente.exp_id = {$id_exp} AND\r\n                    tab_expediente.exp_estado = 1";
                         $cant_max = $maxFil->dbSelectBySQL($sql2);
                         foreach ($cant_max as $lismax) {
                             $max3 = $lismax->maxnro;
                         }
                         if ($max3 == "") {
                             $max3 = 0;
                         }
                         $max3 = $max3 + 1;
                         $this->archivo->setFil_nro($max3);
                         $this->archivo->setFil_titulo(strtoupper($titledoc));
                         $this->archivo->setFil_subtitulo(strtoupper($subtitledoc));
                         $this->archivo->setFil_fecha($fechahoy);
                         $this->archivo->setIdi_id(1);
                         $this->archivo->setFil_proc($fondo);
                         $this->archivo->setFil_firma($nomUsuario);
                         $this->archivo->setFil_cargo('');
                         $this->archivo->setFil_alccon('');
                         $sqlsopfis = new tab_sopfisico();
                         if ($sopfis != "AP" || $sopfis != "EM" || $sopfis != "LG" || $sopfis != "AN" || $sopfis != "MM" || $sopfis != "CP") {
                             $sopfis = "LG";
                         }
                         $result = $sqlsopfis->dbselectByField("sof_codigo", $sopfis);
                         $this->archivo->setSof_id($result[0]->sof_id);
                         $this->archivo->setFil_codigo(2);
                         $this->archivo->setFil_nrofoj('');
                         $this->archivo->setFil_tomovol($tomovol);
                         $this->archivo->setFil_nroejem($filnroejem);
                         $this->archivo->setFil_nrocaj($caj);
                         $this->archivo->setFil_nropaq('');
                         $this->archivo->setFil_sala(strtoupper($sala));
                         $this->archivo->setFil_estante(strtoupper($estante));
                         $this->archivo->setFil_cuerpo(strtoupper($cuerpo));
                         $this->archivo->setFil_balda(strtoupper($balda));
                         $this->archivo->setFil_tipoarch('TEC');
                         $this->archivo->setFil_mrb('BUENO');
                         $this->archivo->setFil_mes($fechadocMesInicial);
                         $this->archivo->setFil_anio($fechadocAnioInicial);
                         $this->archivo->setFil_cantpaq('');
                         $this->archivo->setFil_cantcaj('');
                         $this->archivo->setFil_confidencialidad(1);
                         $this->archivo->setFil_obs(strtoupper($obs));
                         $this->archivo->setFil_estado('1');
                         $fil_id = $this->archivo->insert();
                         $this->archivo2 = new tab_archivo();
                         $this->archivo2->setFil_id($fil_id);
                         $this->archivo2->setFil_codigo($fil_id);
                         $this->archivo2->setFil_estado('1');
                         $this->archivo2->update();
                         $this->exparchivo = new tab_exparchivo();
                         $this->exparchivo->setExa_id('');
                         $this->exparchivo->setFil_id($fil_id);
                         $this->exparchivo->setExp_id($exp_id);
                         $archivo_digital = new tab_archivo_digital();
                         $archivo_digital->setFid_id('');
                         $archivo_digital->setFil_id($fil_id);
                         $archivo_digital->insert();
                         $seriet = new Tab_serietramite();
                         $this->series = new series();
                         $ser_codigo = $this->series->obtenerCodigoSerie($id_serie);
                         //insert grupos documentales y tipos documentales
                         $this->tramite = new tab_tramite();
                         $tramitecc = new tab_tramitecuerpos();
                         $sqltramite = "SELECT\r\n        tab_tramite.tra_descripcion,\r\n        tab_tramite.tra_id\r\n        FROM\r\n        tab_series\r\n        INNER JOIN tab_serietramite ON tab_series.ser_id = tab_serietramite.ser_id\r\n        INNER JOIN tab_tramite ON tab_tramite.tra_id = tab_serietramite.tra_id\r\n        WHERE\r\n        tab_series.ser_id = {$id_serie}";
                         $rows = $seriet->dbSelectBySQL($sqltramite);
                         $v = 0;
                         foreach ($rows as $row) {
                             if ($row->tra_descripcion == 'GRUPO DOCUMENTAL COMPUESTA') {
                                 $v++;
                                 $tra_id = $row->tra_id;
                                 $obtenerColumnCueId = $tramitecc->dbselectByField("tra_id", $tra_id);
                                 $cue_id = $obtenerColumnCueId[0]->cue_id;
                             }
                         }
                         if ($v == 0) {
                             $this->tramite->setTra_orden(1);
                             $this->tramite->setTra_codigo(1);
                             $this->tramite->setTra_descripcion("GRUPO DOCUMENTAL COMPUESTA");
                             $this->tramite->setTra_fecha_crea(date("Y-m-d"));
                             $this->tramite->setTra_usuario_crea($_SESSION['USU_ID']);
                             $this->tramite->setTra_estado(1);
                             $tra_id = $this->tramite->insert();
                             $seriet->setSer_id($id_serie);
                             $seriet->setTra_id($tra_id);
                             $seriet->setSts_fecha_crea(date("Y-m-d"));
                             $seriet->setSts_fecha_reg(date("Y-m-d"));
                             $seriet->setSts_usuario_crea($_SESSION['USU_ID']);
                             $seriet->setSts_usu_reg($_SESSION['USU_ID']);
                             $seriet->setVer_id('0');
                             $seriet->setSts_estado(1);
                             $seriet->insert();
                             $this->tramite = new tramite();
                             $tra_codigo = $this->tramite->obtenerCodigoTramite($tra_id);
                             $tcuerpos = new tab_cuerpos();
                             $tcuerpos->setCue_id('');
                             $tcuerpos->setCue_orden(1);
                             $tcuerpos->setCue_codigo(1);
                             $tcuerpos->setCue_descripcion("UNIDAD DOCUMENTAL SIMPLE");
                             $tcuerpos->setCue_fecha_crea(date("Y-m-d"));
                             $tcuerpos->setCue_usuario_crea($_SESSION['USU_ID']);
                             $tcuerpos->setCue_estado(1);
                             $cue_id = $tcuerpos->insert();
                             // Last code
                             //$tramitecc = new tab_tramitecuerpos();
                             $tramitecc->setCue_id($cue_id);
                             $tramitecc->setTra_id($tra_id);
                             $tramitecc->setTrc_estado(1);
                             $tramitecc->insert();
                         }
                         //insert
                         $this->exparchivo->setTra_id($tra_id);
                         $this->exparchivo->setCue_id($cue_id);
                         $this->exparchivo->setExa_condicion('1');
                         $this->exparchivo->setExa_estado(1);
                         $this->exparchivo->insert();
                         //Fin del archivo
                     }
                     $i++;
                     $ct++;
                 }
             } else {
                 $msg = "<font color='red'>FORMATO GNT - SCT NO ES CORRECTO</font>";
                 unlink($Dir);
                 $this->index($msg);
                 exit;
             }
             $msg .= "<b style='color:green'>SE GUARDO CORRECTAMENTE</b><br>";
             $msg .= "<a href='" . PATH_DOMAIN . "/nuevoExpediente/index/'>Ver registro</a>";
             unlink($Dir);
             $this->index($msg);
             exit;
         } else {
             $msg = "<font color='red'>FORMATO GNT - SCT NO ES CORRECTO</font>";
             unlink($Dir);
             $this->index($msg);
             exit;
         }
     } else {
         if ($tipoformato == 2) {
             //GNT-SCV
             //    $msg= $highestColumn; exit();
             $cantidaddoc = $highestRow - 18;
             $fondo = $objPHPExcel->getActiveSheet()->getCell("F8")->getValue();
             $subfondo = $objPHPExcel->getActiveSheet()->getCell("F9")->getValue();
             $seccion = $objPHPExcel->getActiveSheet()->getCell("F10")->getValue();
             $subseccion = $objPHPExcel->getActiveSheet()->getCell("F11")->getValue();
             $serie = $objPHPExcel->getActiveSheet()->getCell("F13")->getValue();
             $tituloexpediente = $objPHPExcel->getActiveSheet()->getCell("F14")->getValue();
             $fechasExtremas = $objPHPExcel->getActiveSheet()->getCell("S13")->getValue();
             $ml = $objPHPExcel->getActiveSheet()->getCell("D17")->getValue();
             $objHoja = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
             $objWorksheet = $objPHPExcel->getActiveSheet();
             //if(trim($subseccion)=="SUBGERENCIA DE CONSERVACION VIAL"){
             //    $subseccion="PROYECTOS DE CONSERVACION VIAL";
             //}
             $tituloserie = explode("\n", $serie);
             $cantidaserie = count($tituloserie);
             if ($cantidaserie > 1) {
                 $msg = "<font color='red'>Error, Elimine los saltos de linea del T&iacute;tulo de la Serie</font><br>";
                 unlink($Dir);
                 $this->index($msg);
                 exit;
             }
             $tituloexp = explode("\n", $tituloexpediente);
             $cantidaexpediente = count($tituloexp);
             if ($cantidaexpediente > 1) {
                 $msg = "<font color='red'>Error, Elimine los saltos de linea en T&iacute;tulo de Expediente </font><br>";
                 unlink($Dir);
                 $this->index($msg);
                 exit;
             }
             if ($highestColumn != "U") {
                 $msg = "<font color='red'>FORMATO GNT - SCV NO ES CORRECTO</font>";
                 unlink($Dir);
                 $this->index($msg);
                 exit;
             }
             //
             //$msg= $fondo."<br>";
             //$msg= $subfondo."<br>";
             //$msg= $seccion."<br>";
             //$msg= $subseccion."<br>";
             //$msg= $serie."<br>";
             //$msg= $tituloexpediente."<br>";
             //$msg= $fechasExtremas."<br>";
             //$msg= $ml."<br>";
             //
             //$msg= '<table border="1">' . "\n";
             //foreach ($objWorksheet->getRowIterator() as $row) {
             //$msg= '<tr>' . "\n";
             //
             //$cellIterator = $row->getCellIterator();
             //$cellIterator->setIterateOnlyExistingCells(false); // This loops all cells,
             //foreach ($cellIterator as $cell) {
             //$msg= '<td>' . htmlentities($cell->getValue(), ENT_IGNORE, 'utf-8') . '</td>' . "\n";
             //}
             //$msg= '</tr>' . "\n";
             //}
             //$msg= '</table>' . "\n";
             //
             //    exit();
             $tab_fondo = new Tab_fondo();
             $tab_unidad = new Tab_unidad();
             $tab_series = new Tab_series();
             //obtener fondo y subfondo
             $sql = "select* from tab_fondo where fon_descripcion LIKE '%{$fondo}%'";
             $sql2 = "select* from tab_fondo where fon_descripcion LIKE '%{$subfondo}%'";
             $resultado = $tab_fondo->dbSelectBySQL($sql);
             $resultado2 = $tab_fondo->dbSelectBySQL($sql2);
             $id_fondo = $resultado[0]->fon_id;
             $id_subfondo = $resultado2[0]->fon_id;
             $ubicacion = $resultado2[0]->fon_codigo;
             switch ($ubicacion) {
                 case "ON":
                     $ubicacion = "LA PAZ";
                     break;
                 case "LP":
                     $ubicacion = "LA PAZ";
                     break;
                 case "SC":
                     $ubicacion = "SANTA CRUZ";
                     break;
                 case "PT":
                     $ubicacion = "POTOSI";
                     break;
                 case "BN":
                     $ubicacion = "BENI";
                     break;
                 case "PN":
                     $ubicacion = "PANDO";
                     break;
                 case "CB":
                     $ubicacion = "COCHABAMBA";
                     break;
                 case "OR":
                     $ubicacion = "ORURO";
                     break;
                 case "CH":
                     $ubicacion = "CHUQUISACA";
                     break;
                 case "TJ":
                     $ubicacion = "TARIJA";
                     break;
             }
             if ($seccion == "DIRECCION GENERAL TECNICA") {
                 if ($id_subfondo == 3) {
                     $seccion = "TECNICA-OPERATIVA";
                 } else {
                     $seccion = "AREA TECNICA";
                 }
             }
             //obtener el fon_id
             $subseccion = trim($subseccion);
             if ($subseccion == "") {
                 $sql3 = "SELECT\r\ntab_unidad.uni_id,\r\nf.fon_id,\r\ntab_unidad.uni_descripcion\r\nFROM tab_fondo as f\r\nINNER JOIN tab_unidad ON f.fon_id = tab_unidad.fon_id\r\nWHERE\r\nf.fon_id = {$id_subfondo} and tab_unidad.uni_descripcion LIKE'%{$seccion}%'";
             } else {
                 $sql3 = "SELECT\r\ntab_unidad.uni_id,\r\nf.fon_id,\r\ntab_unidad.uni_descripcion\r\nFROM tab_fondo as f\r\nINNER JOIN tab_unidad ON f.fon_id = tab_unidad.fon_id\r\nWHERE\r\nf.fon_id = {$id_subfondo} and tab_unidad.uni_descripcion LIKE'%{$subseccion}%'";
             }
             $resultado3 = $tab_unidad->dbSelectBySQL($sql3);
             foreach ($resultado3 as $rowseccion) {
                 $id_seccion = $rowseccion->uni_id;
             }
             //obtengo la serie
             $sql4 = "SELECT\r\ntab_series.ser_categoria,\r\ntab_series.ser_id\r\nFROM\r\ntab_fondo\r\nINNER JOIN tab_unidad ON tab_fondo.fon_id = tab_unidad.fon_id\r\nINNER JOIN tab_series ON tab_unidad.uni_id = tab_series.uni_id\r\nWHERE\r\ntab_fondo.fon_id = {$id_subfondo} AND tab_series.ser_categoria LIKE '%{$serie}%'";
             $resultado4 = $tab_series->dbSelectBySQL($sql4);
             foreach ($resultado4 as $rowserie) {
                 $id_serie = $rowserie->ser_id;
             }
             $ml = $objPHPExcel->getActiveSheet()->getCell("D17")->getValue();
             //$msg= $id_serie."<br>";
             //$msg= $id_fondo."<br>";
             //$msg= $id_subfondo."<br>";
             //$msg= $id_seccion."<br>";
             if ($id_serie == "") {
                 $msg = "<font color='red'>Error, No existe la Serie Asignada</font><br>";
                 unlink($Dir);
                 $this->index($msg);
                 exit;
             } else {
                 if ($id_subfondo == "") {
                     $msg = "<font color='red'>Error, No existe el Subfondo</font><br>";
                     unlink($Dir);
                     $this->index($msg);
                     exit;
                 } else {
                     if ($id_seccion == "") {
                         $msg = "<font color='red'>Error, No existe la Secci&oacute;n</font><br>";
                         unlink($Dir);
                         $this->index($msg);
                         exit;
                     }
                 }
             }
             if ($highestColumn == "U") {
                 if ($ml == "ML") {
                     $i = 1;
                     $ct = 18;
                     $t = 0;
                     $expsadg = new Tab_expisadg();
                     $resulall = $expsadg->dbselectByField("exp_titulo", strtoupper($tituloexpediente));
                     foreach ($resulall as $list) {
                         $t++;
                     }
                     $fechafinal = '';
                     $fechainicial = '';
                     $exp_fechas = explode("-", $fechasExtremas);
                     if (!empty($exp_fechas[1])) {
                         $fechafinal = trim($exp_fechas[1]);
                     }
                     if (!empty($exp_fechas[0])) {
                         $fechainicial = trim($exp_fechas[0]);
                     }
                     if ($t > 0) {
                         $msg = "<font color='red'>Error! existe otro nombre duplicado</font>";
                         unlink($Dir);
                         $this->index($msg);
                         exit;
                     }
                     $expediente = new expediente();
                     $hoy = date("Y-m-d");
                     $this->expediente = new tab_expediente();
                     //        $this->expediente->setRequest2Object($_REQUEST);
                     $this->expediente->setExp_id('');
                     $this->expediente->setSer_id($id_serie);
                     // Generation code
                     $this->expediente->setExp_codigo($expediente->generaCodigo($id_serie));
                     $this->expediente->setExp_lugar($ubicacion);
                     $this->expediente->setSof_id(1);
                     $this->expediente->setExp_ori(0);
                     $this->expediente->setExp_cop(0);
                     $this->expediente->setExp_fot(0);
                     $this->expediente->setExp_obs('');
                     $this->expediente->setExp_corr('AUTO');
                     $this->expediente->setExp_estado(1);
                     $this->expediente->setExp_migrarexcel(1);
                     $exp_id = $this->expediente->insert2();
                     // Update count
                     //        if ($_REQUEST['ser_corr'] == 'AUTO') {
                     //            // Auto
                     //            $tseries = new tab_series();
                     //            $row2 = $tseries->dbselectByField("ser_id", $_REQUEST['ser_id']);
                     //            $row2 = $row2[0];
                     //            $tseries->setSer_id($_REQUEST['ser_id']);
                     //            $ser_exp = $row2->ser_exp + 1;
                     //            $tseries->setSer_exp($ser_exp);
                     //            $tseries->update();
                     //        } else {
                     //            // Manual
                     //            $tseries = new tab_series();
                     //            $tseries->setSer_id($_REQUEST['ser_id']);
                     //            $tseries->setSer_exp($_REQUEST['exp_codigo']);
                     //            $tseries->update();
                     //        }
                     //$this->expisadg->setTrm_id(1);
                     //        $expisadg = new tab_expisadg();
                     //        $expisadg->setExp_id($exp_id);
                     //        $expisadg->setExp_titulo($expediente);
                     //        $expisadg->setExp_nomprod($fondo);
                     //        $expisadg->setExp_fecha_exi(date('Y-m-d'));
                     //        $expisadg->setExp_fecha_exf(date('Y-m-d'));
                     //        $expisadg->setExp_anioi($fechainicial);
                     //        $expisadg->setExp_aniof($fechafinal);
                     //        $expisadg->setIdi_id(1);
                     //        $expisadg->setExp_estado(1);
                     //        $eig_id = $expisadg->insert();
                     $fechahoy = date('Y-m-d');
                     $expisadg = new tab_expisadg();
                     $expisadg->setExp_id($exp_id);
                     $expisadg->setExp_titulo($tituloexpediente);
                     $expisadg->setExp_fecha_exi($fechahoy);
                     //        $expisadg->setExp_mesi('');
                     $expisadg->setExp_anioi($fechainicial);
                     $expisadg->setExp_fecha_exf($fechahoy);
                     //        $expisadg->setExp_mesf('');
                     $expisadg->setExp_aniof($fechafinal);
                     $expisadg->setExp_nivdes('EXPEDIENTE');
                     //        $expisadg->setExp_volsop('');
                     $expisadg->setExp_nomprod($fondo);
                     //        $expisadg->setExp_hisins('');
                     //        $expisadg->setExp_hisarc('');
                     $expisadg->setExp_foring('TRANSFERENCIA');
                     //        $expisadg->setExp_alccon('');
                     //        $expisadg->setExp_vaseel('');
                     //        $expisadg->setExp_nueing('');
                     $expisadg->setExp_org('LOS DOCUMENTOS DEL PROYECTO FUERON IDENTIFICADOS, CLASIFICADOS Y ORDENADOS EN LAS CAJAS DE ACUERDO AL CHECK LIST DE LA SERIE A LA QUE CORRESPONDEN.');
                     $expisadg->setExp_conacc('EL ACCESO ESTA SUJETO A LO QUE ESTABLECE LA CONSTITUCION POLITICA DEL ESTADO Y EL ARTICULO 18 DE LA LEY 2341 SOBRE PROCESOS ADMINISTRATIVOS.');
                     //        $expisadg->setExp_conrep('');
                     $expisadg->setIdi_id(1);
                     $expisadg->setExp_carfis('BUENO');
                     //        $expisadg->setExp_insdes('');
                     //        $expisadg->setExp_exloor('');
                     //        $expisadg->setExp_exloco('');
                     //        $expisadg->setExp_underel('');
                     //        $expisadg->setExp_notpub('');
                     //        $expisadg->setExp_notas('');
                     //        $expisadg->setExp_notarc('');
                     $expisadg->setExp_regnor('ISAD-G, ISAAR(CPF), RCAA');
                     $expisadg->setExp_fecdes(date('Y-m-d'));
                     $expisadg->setExp_estado(1);
                     $eig_id = $expisadg->insert();
                     // Save expfondo data
                     $texf = new Tab_expfondo();
                     $texf->setExp_id($exp_id);
                     $usuario = new usuario();
                     $fon_id = $usuario->getFon_id($_SESSION['USU_ID']);
                     $nomUsuario = $usuario->obtenerNombre($_SESSION['USU_ID']);
                     $texf->setExf_fecha_exi($fechahoy);
                     $texf->setFon_id($fon_id);
                     $texf->setExf_estado('1');
                     $texf->insert();
                     // Save expusuario data
                     $this->expusuario = new expusuario();
                     $this->expusuario->saveExp($exp_id, $_SESSION['USU_ID']);
                     //        // Save expcontenedor data
                     //        $con = new expcontenedor();
                     //        $con->saveExpCont($_REQUEST['con_id'], $_REQUEST['suc_id'], $exp_id);
                     //        // Save proyecto list data (tramos)
                     //        if (isset($_REQUEST['lista_tramo'])) {
                     //            $proyectos = $_REQUEST['lista_tramo'];
                     //            foreach ($proyectos as $proyecto) {
                     //                $exp = new tab_expproyecto();
                     //                $exp->setExp_id($exp_id);
                     //                $exp->setPry_id($proyecto);
                     //                $exp->setEpp_estado(1);
                     //                $exp->insert();
                     //            }
                     //        }
                     // Save data dynamic
                     $c = 0;
                     $caj = "";
                     $cnt = 0;
                     //insert usuario serie
                     $tab_usu_serie = new Tab_usu_serie();
                     $sqlususerie = "select* from tab_usu_serie\r\n            where usu_id='" . $_SESSION['USU_ID'] . "'\r\n            and ser_id='" . $id_serie . "'\r\n            and use_estado=1";
                     $comprobar_usu_serie = $tab_usu_serie->dbSelectBySQL($sqlususerie);
                     $cnt = count($comprobar_usu_serie);
                     if ($cnt == 0) {
                         $tab_usu_serie->setUse_id('');
                         $tab_usu_serie->setUsu_id($_SESSION['USU_ID']);
                         $tab_usu_serie->setSer_id($id_serie);
                         $tab_usu_serie->setUse_estado(1);
                         $tab_usu_serie->insert();
                     }
                     while ($i <= $cantidaddoc) {
                         $caja = $objPHPExcel->getActiveSheet()->getCell("A" . $ct)->getValue();
                         $filnroejem = $objPHPExcel->getActiveSheet()->getCell("C" . $ct)->getValue();
                         $correlativo = $objPHPExcel->getActiveSheet()->getCell("E" . $ct)->getValue();
                         $titledoc = $objPHPExcel->getActiveSheet()->getCell("H" . $ct)->getValue();
                         $subtitledoc = $objPHPExcel->getActiveSheet()->getCell("I" . $ct)->getValue();
                         //   $productor=$objPHPExcel->getActiveSheet()->getCell("J".$ct)->getValue();
                         $contrato = $objPHPExcel->getActiveSheet()->getCell("K" . $ct)->getValue();
                         $fecha = trim($objPHPExcel->getActiveSheet()->getCell("N" . $ct)->getValue());
                         $tomovol = $objPHPExcel->getActiveSheet()->getCell("O" . $ct)->getValue();
                         $sopfis = $objPHPExcel->getActiveSheet()->getCell("P" . $ct)->getValue();
                         $sala = $objPHPExcel->getActiveSheet()->getCell("Q" . $ct)->getValue();
                         $estante = $objPHPExcel->getActiveSheet()->getCell("R" . $ct)->getValue();
                         $cuerpo = $objPHPExcel->getActiveSheet()->getCell("S" . $ct)->getValue();
                         $balda = $objPHPExcel->getActiveSheet()->getCell("T" . $ct)->getValue();
                         $obs = $objPHPExcel->getActiveSheet()->getCell("U" . $ct)->getValue();
                         //todavia en trabajo
                         if ($titledoc != "") {
                             if ($fecha != "s/f") {
                                 $extfe = explode("\n", $fecha);
                                 $cantidadfecha = count($extfe);
                                 if ($cantidadfecha > 1) {
                                     $fechadocAnioInicial = $extfe[0];
                                     $fechadocMesInicial = $extfe[1];
                                 } else {
                                     $fechadocAnioInicial = $extfe[0];
                                     $fechadocMesInicial = "";
                                     if ($fechadocAnioInicial > 30000) {
                                         $fe = date("m-y", (int) $fechadocAnioInicial);
                                         $extraer = explode("-", $fe);
                                         $fechadocAnioInicial = $extraer[1];
                                         $fechadocMesInicial = $extraer[0];
                                     }
                                 }
                             }
                             // exit();
                             if ($caja == "") {
                             } else {
                                 $extraercaj = explode(" ", trim($caja));
                                 $caj = $extraercaj[1];
                             }
                             $id_exp = $exp_id;
                             $this->archivo = new tab_archivo();
                             $this->archivo->setFil_id('');
                             // Generation code max fil_nro
                             $maxFil = new Tab_archivo();
                             $sql2 = "SELECT\r\n                    MAX(tab_archivo.fil_nro) AS maxnro\r\n                    FROM\r\n                    tab_expediente\r\n                    INNER JOIN tab_exparchivo ON tab_exparchivo.exp_id = tab_expediente.exp_id\r\n                    INNER JOIN tab_archivo ON tab_archivo.fil_id = tab_exparchivo.fil_id\r\n                    WHERE\r\n                    tab_expediente.exp_id = {$id_exp} AND\r\n                    tab_expediente.exp_estado = 1";
                             $cant_max = $maxFil->dbSelectBySQL($sql2);
                             foreach ($cant_max as $lismax) {
                                 $max3 = $lismax->maxnro;
                             }
                             if ($max3 == "") {
                                 $max3 = 0;
                             }
                             $max3 = $max3 + 1;
                             $this->archivo->setFil_nro($max3);
                             $this->archivo->setFil_titulo(strtoupper($titledoc));
                             $this->archivo->setFil_codigo(2);
                             $this->archivo->setFil_subtitulo(strtoupper($subtitledoc));
                             $this->archivo->setFil_fecha($fechahoy);
                             $this->archivo->setIdi_id(1);
                             $this->archivo->setFil_proc($fondo);
                             $this->archivo->setFil_firma($nomUsuario);
                             $this->archivo->setFil_cargo('');
                             $this->archivo->setFil_alccon('');
                             $sqlsopfis = new tab_sopfisico();
                             if ($sopfis != "AP" || $sopfis != "EM" || $sopfis != "LG" || $sopfis != "AN" || $sopfis != "MM" || $sopfis != "CP") {
                                 $sopfis = "LG";
                             }
                             $result = $sqlsopfis->dbselectByField("sof_codigo", $sopfis);
                             $this->archivo->setSof_id($result[0]->sof_id);
                             $this->archivo->setFil_nrofoj('');
                             $this->archivo->setFil_tomovol($tomovol);
                             $this->archivo->setFil_nroejem($filnroejem);
                             $this->archivo->setFil_nrocaj($caj);
                             $this->archivo->setFil_nropaq('');
                             $this->archivo->setFil_sala(strtoupper($sala));
                             $this->archivo->setFil_estante(strtoupper($estante));
                             $this->archivo->setFil_cuerpo(strtoupper($cuerpo));
                             $this->archivo->setFil_balda(strtoupper($balda));
                             $this->archivo->setFil_tipoarch('TEC');
                             $this->archivo->setFil_mrb('BUENO');
                             $this->archivo->setFil_mes($fechadocMesInicial);
                             $this->archivo->setFil_anio($fechadocAnioInicial);
                             $this->archivo->setFil_cantpaq('');
                             $this->archivo->setFil_cantcaj('');
                             $this->archivo->setFil_confidencialidad(1);
                             $this->archivo->setFil_obs(strtoupper($obs));
                             $this->archivo->setFil_estado('1');
                             $fil_id = $this->archivo->insert();
                             $this->archivo2 = new tab_archivo();
                             $this->archivo2->setFil_id($fil_id);
                             $this->archivo2->setFil_codigo($fil_id);
                             $this->archivo2->setFil_estado('1');
                             $this->archivo2->update();
                             $this->exparchivo = new tab_exparchivo();
                             $this->exparchivo->setExa_id('');
                             $this->exparchivo->setFil_id($fil_id);
                             $this->exparchivo->setExp_id($exp_id);
                             $archivo_digital = new tab_archivo_digital();
                             $archivo_digital->setFid_id('');
                             $archivo_digital->setFil_id($fil_id);
                             $archivo_digital->insert();
                             $seriet = new Tab_serietramite();
                             $this->series = new series();
                             $ser_codigo = $this->series->obtenerCodigoSerie($id_serie);
                             //insert grupos documentales y tipos documentales
                             $this->tramite = new tab_tramite();
                             $tramitecc = new tab_tramitecuerpos();
                             $sqltramite = "SELECT\r\n        tab_tramite.tra_descripcion,\r\n        tab_tramite.tra_id\r\n        FROM\r\n        tab_series\r\n        INNER JOIN tab_serietramite ON tab_series.ser_id = tab_serietramite.ser_id\r\n        INNER JOIN tab_tramite ON tab_tramite.tra_id = tab_serietramite.tra_id\r\n        WHERE\r\n        tab_series.ser_id = {$id_serie}";
                             $rows = $seriet->dbSelectBySQL($sqltramite);
                             $v = 0;
                             foreach ($rows as $row) {
                                 if ($row->tra_descripcion == 'GRUPO DOCUMENTAL COMPUESTA') {
                                     $v++;
                                     $tra_id = $row->tra_id;
                                     $obtenerColumnCueId = $tramitecc->dbselectByField("tra_id", $tra_id);
                                     $cue_id = $obtenerColumnCueId[0]->cue_id;
                                 }
                             }
                             if ($v == 0) {
                                 $this->tramite->setTra_orden(1);
                                 $this->tramite->setTra_codigo(1);
                                 $this->tramite->setTra_descripcion("GRUPO DOCUMENTAL COMPUESTA");
                                 $this->tramite->setTra_fecha_crea(date("Y-m-d"));
                                 $this->tramite->setTra_usuario_crea($_SESSION['USU_ID']);
                                 $this->tramite->setTra_estado(1);
                                 $tra_id = $this->tramite->insert();
                                 $seriet->setSer_id($id_serie);
                                 $seriet->setTra_id($tra_id);
                                 $seriet->setSts_fecha_crea(date("Y-m-d"));
                                 $seriet->setSts_fecha_reg(date("Y-m-d"));
                                 $seriet->setSts_usuario_crea($_SESSION['USU_ID']);
                                 $seriet->setSts_usu_reg($_SESSION['USU_ID']);
                                 $seriet->setVer_id('0');
                                 $seriet->setSts_estado(1);
                                 $seriet->insert();
                                 $this->tramite = new tramite();
                                 $tra_codigo = $this->tramite->obtenerCodigoTramite($tra_id);
                                 $tcuerpos = new tab_cuerpos();
                                 $tcuerpos->setCue_id('');
                                 $tcuerpos->setCue_orden(1);
                                 $tcuerpos->setCue_codigo(1);
                                 $tcuerpos->setCue_descripcion("UNIDAD DOCUMENTAL SIMPLE");
                                 $tcuerpos->setCue_fecha_crea(date("Y-m-d"));
                                 $tcuerpos->setCue_usuario_crea($_SESSION['USU_ID']);
                                 $tcuerpos->setCue_estado(1);
                                 $cue_id = $tcuerpos->insert();
                                 // Last code
                                 //$tramitecc = new tab_tramitecuerpos();
                                 $tramitecc->setCue_id($cue_id);
                                 $tramitecc->setTra_id($tra_id);
                                 $tramitecc->setTrc_estado(1);
                                 $tramitecc->insert();
                             }
                             //insert
                             $this->exparchivo->setTra_id($tra_id);
                             $this->exparchivo->setCue_id($cue_id);
                             $this->exparchivo->setExa_condicion('1');
                             $this->exparchivo->setExa_estado(1);
                             $this->exparchivo->insert();
                             //Fin del archivo
                         }
                         $i++;
                         $ct++;
                     }
                 } else {
                     $msg = "<font color='red'>FORMATO GNT - SCV NO ES CORRECTO</font>";
                     unlink($Dir);
                     $this->index($msg);
                     exit;
                 }
                 $msg .= "<b style='color:green'>SE GUARDO CORRECTAMENTE</b><br>";
                 $msg .= "<a href='" . PATH_DOMAIN . "/nuevoExpediente/index/'>Ver registro</a>";
                 unlink($Dir);
                 $this->index($msg);
                 exit;
             } else {
                 $msg = "<font color='red'>FORMATO GNT - SCV NO ES CORRECTO</font>";
                 unlink($Dir);
                 $this->index($msg);
             }
         } else {
             if ($tipoformato == 3) {
                 //GNT-SSA
                 $cantidaddoc = $highestRow - 38;
                 $fondo = $objPHPExcel->getActiveSheet()->getCell("E8")->getValue();
                 $subfondo = $objPHPExcel->getActiveSheet()->getCell("E9")->getValue();
                 $seccion = $objPHPExcel->getActiveSheet()->getCell("E10")->getValue();
                 $subseccion = $objPHPExcel->getActiveSheet()->getCell("E11")->getValue();
                 $serie = $objPHPExcel->getActiveSheet()->getCell("E13")->getValue();
                 $tituloexpediente = $objPHPExcel->getActiveSheet()->getCell("E14")->getValue();
                 $fechasExtremas = $objPHPExcel->getActiveSheet()->getCell("P13")->getValue();
                 //if(trim($subseccion)=="SUBGERENCIA DE CONSERVACION VIAL"){
                 //    $subseccion="PROYECTOS DE CONSERVACION VIAL";
                 //}
                 $tituloserie = explode("\n", $serie);
                 $cantidaserie = count($tituloserie);
                 if ($cantidaserie > 1) {
                     $msg = "<font color='red'>Error, Elimine los saltos de linea del T&iacute;tulo de la Serie</font><br>";
                     unlink($Dir);
                     $this->index($msg);
                     exit;
                 }
                 $tituloexp = explode("\n", $tituloexpediente);
                 $cantidaexpediente = count($tituloexp);
                 if ($cantidaexpediente > 1) {
                     $msg = "<font color='red'>Error, Elimine los saltos de linea en T&iacute;tulo de Expediente </font><br>";
                     unlink($Dir);
                     $this->index($msg);
                     exit;
                 }
                 $ml = $objPHPExcel->getActiveSheet()->getCell("D16")->getValue();
                 if ($highestColumn != "Q") {
                     $msg = "<font color='red'>FORMATO GNT - SSA NO ES CORRECTO</font>";
                     unlink($Dir);
                     $this->index($msg);
                     exit;
                 }
                 $tab_fondo = new Tab_fondo();
                 $tab_unidad = new Tab_unidad();
                 $tab_series = new Tab_series();
                 //obtener fondo y subfondo
                 $sql = "select* from tab_fondo where fon_descripcion LIKE '%{$fondo}%'";
                 $sql2 = "select* from tab_fondo where fon_descripcion LIKE '%{$subfondo}%'";
                 $resultado = $tab_fondo->dbSelectBySQL($sql);
                 $resultado2 = $tab_fondo->dbSelectBySQL($sql2);
                 $id_fondo = $resultado[0]->fon_id;
                 $id_subfondo = $resultado2[0]->fon_id;
                 $ubicacion = $resultado2[0]->fon_codigo;
                 switch ($ubicacion) {
                     case "ON":
                         $ubicacion = "LA PAZ";
                         break;
                     case "LP":
                         $ubicacion = "LA PAZ";
                         break;
                     case "SC":
                         $ubicacion = "SANTA CRUZ";
                         break;
                     case "PT":
                         $ubicacion = "POTOSI";
                         break;
                     case "BN":
                         $ubicacion = "BENI";
                         break;
                     case "PN":
                         $ubicacion = "PANDO";
                         break;
                     case "CB":
                         $ubicacion = "COCHABAMBA";
                         break;
                     case "OR":
                         $ubicacion = "ORURO";
                         break;
                     case "CH":
                         $ubicacion = "CHUQUISACA";
                         break;
                     case "TJ":
                         $ubicacion = "TARIJA";
                         break;
                 }
                 if ($seccion == "DIRECCION GENERAL TECNICA") {
                     if ($id_subfondo == 3) {
                         $seccion = "TECNICA-OPERATIVA";
                     } else {
                         $seccion = "AREA TECNICA";
                     }
                 }
                 //obtener el fon_id
                 $subseccion = trim($subseccion);
                 if ($subseccion == "") {
                     $sql3 = "SELECT\r\ntab_unidad.uni_id,\r\nf.fon_id,\r\ntab_unidad.uni_descripcion\r\nFROM tab_fondo as f\r\nINNER JOIN tab_unidad ON f.fon_id = tab_unidad.fon_id\r\nWHERE\r\nf.fon_id = {$id_subfondo} and tab_unidad.uni_descripcion LIKE'%{$seccion}%'";
                 } else {
                     $sql3 = "SELECT\r\ntab_unidad.uni_id,\r\nf.fon_id,\r\ntab_unidad.uni_descripcion\r\nFROM tab_fondo as f\r\nINNER JOIN tab_unidad ON f.fon_id = tab_unidad.fon_id\r\nWHERE\r\nf.fon_id = {$id_subfondo} and tab_unidad.uni_descripcion LIKE'%{$subseccion}%'";
                 }
                 $resultado3 = $tab_unidad->dbSelectBySQL($sql3);
                 foreach ($resultado3 as $rowseccion) {
                     $id_seccion = $rowseccion->uni_id;
                 }
                 //obtengo la serie
                 $sql4 = "SELECT\r\ntab_series.ser_categoria,\r\ntab_series.ser_id\r\nFROM\r\ntab_fondo\r\nINNER JOIN tab_unidad ON tab_fondo.fon_id = tab_unidad.fon_id\r\nINNER JOIN tab_series ON tab_unidad.uni_id = tab_series.uni_id\r\nWHERE\r\ntab_fondo.fon_id = {$id_subfondo} AND tab_series.ser_categoria LIKE '%{$serie}%'";
                 $resultado4 = $tab_series->dbSelectBySQL($sql4);
                 foreach ($resultado4 as $rowserie) {
                     $id_serie = $rowserie->ser_id;
                 }
                 if ($id_serie == "") {
                     $msg = "<font color='red'>Error, No existe la Serie Asignada</font><br>";
                     unlink($Dir);
                     $this->index($msg);
                     exit;
                 } else {
                     if ($id_subfondo == "") {
                         $msg = "<font color='red'>Error, No existe el Subfondo</font><br>";
                         unlink($Dir);
                         $this->index($msg);
                         exit;
                     } else {
                         if ($id_seccion == "") {
                             $msg = "<font color='red'>Error, No existe la Secci&oacute;n</font><br>";
                             unlink($Dir);
                             $this->index($msg);
                             exit;
                         }
                     }
                 }
                 if ($highestColumn == "Q") {
                     if ($ml == "ML") {
                         $i = 1;
                         $ct = 18;
                         $t = 0;
                         $expsadg = new Tab_expisadg();
                         $resulall = $expsadg->dbselectByField("exp_titulo", strtoupper($tituloexpediente));
                         foreach ($resulall as $list) {
                             $t++;
                         }
                         $fechafinal = '';
                         $fechainicial = '';
                         $exp_fechas = explode("-", $fechasExtremas);
                         if (!empty($exp_fechas[1])) {
                             $fechafinal = trim($exp_fechas[1]);
                         }
                         if (!empty($exp_fechas[0])) {
                             $fechainicial = trim($exp_fechas[0]);
                         }
                         if ($t > 0) {
                             $msg = "<font color='red'>Error! existe otro nombre duplicado</font>";
                             unlink($Dir);
                             $this->index($msg);
                             exit;
                         }
                         $expediente = new expediente();
                         $hoy = date("Y-m-d");
                         $this->expediente = new tab_expediente();
                         //        $this->expediente->setRequest2Object($_REQUEST);
                         $this->expediente->setExp_id('');
                         $this->expediente->setSer_id($id_serie);
                         // Generation code
                         $this->expediente->setExp_codigo($expediente->generaCodigo($id_serie));
                         $this->expediente->setExp_lugar($ubicacion);
                         $this->expediente->setSof_id(1);
                         $this->expediente->setExp_ori(0);
                         $this->expediente->setExp_cop(0);
                         $this->expediente->setExp_fot(0);
                         $this->expediente->setExp_obs('');
                         $this->expediente->setExp_corr('AUTO');
                         $this->expediente->setExp_estado(1);
                         $this->expediente->setExp_migrarexcel(1);
                         $exp_id = $this->expediente->insert2();
                         // Update count
                         //        if ($_REQUEST['ser_corr'] == 'AUTO') {
                         //            // Auto
                         //            $tseries = new tab_series();
                         //            $row2 = $tseries->dbselectByField("ser_id", $_REQUEST['ser_id']);
                         //            $row2 = $row2[0];
                         //            $tseries->setSer_id($_REQUEST['ser_id']);
                         //            $ser_exp = $row2->ser_exp + 1;
                         //            $tseries->setSer_exp($ser_exp);
                         //            $tseries->update();
                         //        } else {
                         //            // Manual
                         //            $tseries = new tab_series();
                         //            $tseries->setSer_id($_REQUEST['ser_id']);
                         //            $tseries->setSer_exp($_REQUEST['exp_codigo']);
                         //            $tseries->update();
                         //        }
                         //$this->expisadg->setTrm_id(1);
                         //        $expisadg = new tab_expisadg();
                         //        $expisadg->setExp_id($exp_id);
                         //        $expisadg->setExp_titulo($expediente);
                         //        $expisadg->setExp_nomprod($fondo);
                         //        $expisadg->setExp_fecha_exi(date('Y-m-d'));
                         //        $expisadg->setExp_fecha_exf(date('Y-m-d'));
                         //        $expisadg->setExp_anioi($fechainicial);
                         //        $expisadg->setExp_aniof($fechafinal);
                         //        $expisadg->setIdi_id(1);
                         //        $expisadg->setExp_estado(1);
                         //        $eig_id = $expisadg->insert();
                         $fechahoy = date('Y-m-d');
                         $expisadg = new tab_expisadg();
                         $expisadg->setExp_id($exp_id);
                         $expisadg->setExp_titulo($tituloexpediente);
                         $expisadg->setExp_fecha_exi($fechahoy);
                         //        $expisadg->setExp_mesi('');
                         $expisadg->setExp_anioi($fechainicial);
                         $expisadg->setExp_fecha_exf($fechahoy);
                         //        $expisadg->setExp_mesf('');
                         $expisadg->setExp_aniof($fechafinal);
                         $expisadg->setExp_nivdes('EXPEDIENTE');
                         //        $expisadg->setExp_volsop('');
                         $expisadg->setExp_nomprod($fondo);
                         //        $expisadg->setExp_hisins('');
                         //        $expisadg->setExp_hisarc('');
                         $expisadg->setExp_foring('TRANSFERENCIA');
                         //        $expisadg->setExp_alccon('');
                         //        $expisadg->setExp_vaseel('');
                         //        $expisadg->setExp_nueing('');
                         $expisadg->setExp_org('LOS DOCUMENTOS DEL PROYECTO FUERON IDENTIFICADOS, CLASIFICADOS Y ORDENADOS EN LAS CAJAS DE ACUERDO AL CHECK LIST DE LA SERIE A LA QUE CORRESPONDEN.');
                         $expisadg->setExp_conacc('EL ACCESO ESTA SUJETO A LO QUE ESTABLECE LA CONSTITUCION POLITICA DEL ESTADO Y EL ARTICULO 18 DE LA LEY 2341 SOBRE PROCESOS ADMINISTRATIVOS.');
                         //        $expisadg->setExp_conrep('');
                         $expisadg->setIdi_id(1);
                         $expisadg->setExp_carfis('BUENO');
                         $expisadg->setExp_regnor('ISAD-G, ISAAR(CPF), RCAA');
                         $expisadg->setExp_fecdes(date('Y-m-d'));
                         $expisadg->setExp_estado(1);
                         $eig_id = $expisadg->insert();
                         // Save expfondo data
                         $texf = new Tab_expfondo();
                         $texf->setExp_id($exp_id);
                         $usuario = new usuario();
                         $fon_id = $usuario->getFon_id($_SESSION['USU_ID']);
                         $nomUsuario = $usuario->obtenerNombre($_SESSION['USU_ID']);
                         $texf->setExf_fecha_exi($fechahoy);
                         $texf->setFon_id($fon_id);
                         $texf->setExf_estado('1');
                         $texf->insert();
                         // Save expusuario data
                         $this->expusuario = new expusuario();
                         $this->expusuario->saveExp($exp_id, $_SESSION['USU_ID']);
                         //        // Save expcontenedor data
                         //        $con = new expcontenedor();
                         //        $con->saveExpCont($_REQUEST['con_id'], $_REQUEST['suc_id'], $exp_id);
                         //        // Save proyecto list data (tramos)
                         //        if (isset($_REQUEST['lista_tramo'])) {
                         //            $proyectos = $_REQUEST['lista_tramo'];
                         //            foreach ($proyectos as $proyecto) {
                         //                $exp = new tab_expproyecto();
                         //                $exp->setExp_id($exp_id);
                         //                $exp->setPry_id($proyecto);
                         //                $exp->setEpp_estado(1);
                         //                $exp->insert();
                         //            }
                         //        }
                         // Save data dynamic
                         $c = 0;
                         $caj = "";
                         $cnt = 0;
                         //insert usuario serie
                         $tab_usu_serie = new Tab_usu_serie();
                         $sqlususerie = "select* from tab_usu_serie\r\n            where usu_id='" . $_SESSION['USU_ID'] . "'\r\n            and ser_id='" . $id_serie . "'\r\n            and use_estado=1";
                         $comprobar_usu_serie = $tab_usu_serie->dbSelectBySQL($sqlususerie);
                         $cnt = count($comprobar_usu_serie);
                         if ($cnt == 0) {
                             $tab_usu_serie->setUse_id('');
                             $tab_usu_serie->setUsu_id($_SESSION['USU_ID']);
                             $tab_usu_serie->setSer_id($id_serie);
                             $tab_usu_serie->setUse_estado(1);
                             $tab_usu_serie->insert();
                         }
                         while ($i <= $cantidaddoc) {
                             $caja = $objPHPExcel->getActiveSheet()->getCell("A" . $ct)->getValue();
                             $filnroejem = $objPHPExcel->getActiveSheet()->getCell("C" . $ct)->getValue();
                             $correlativo = $objPHPExcel->getActiveSheet()->getCell("E" . $ct)->getValue();
                             $titledoc = $objPHPExcel->getActiveSheet()->getCell("F" . $ct)->getValue();
                             $subtitledoc = $objPHPExcel->getActiveSheet()->getCell("G" . $ct)->getValue();
                             $productor = $objPHPExcel->getActiveSheet()->getCell("H" . $ct)->getValue();
                             $contrato = $objPHPExcel->getActiveSheet()->getCell("I" . $ct)->getValue();
                             $fecha = trim($objPHPExcel->getActiveSheet()->getCell("J" . $ct)->getValue());
                             $tomovol = $objPHPExcel->getActiveSheet()->getCell("K" . $ct)->getValue();
                             $sopfis = $objPHPExcel->getActiveSheet()->getCell("L" . $ct)->getValue();
                             $sala = $objPHPExcel->getActiveSheet()->getCell("M" . $ct)->getValue();
                             $estante = $objPHPExcel->getActiveSheet()->getCell("N" . $ct)->getValue();
                             $cuerpo = $objPHPExcel->getActiveSheet()->getCell("O" . $ct)->getValue();
                             $balda = $objPHPExcel->getActiveSheet()->getCell("P" . $ct)->getValue();
                             $obs = $objPHPExcel->getActiveSheet()->getCell("Q" . $ct)->getValue();
                             //todavia en trabajo
                             if ($titledoc != "") {
                                 if ($fecha != "s/f") {
                                     $extfe = explode("\n", $fecha);
                                     $cantidadfecha = count($extfe);
                                     if ($cantidadfecha > 1) {
                                         $fechadocAnioInicial = $extfe[0];
                                         $fechadocMesInicial = $extfe[1];
                                     } else {
                                         $fechadocAnioInicial = $extfe[0];
                                         $fechadocMesInicial = "";
                                         if ($fechadocAnioInicial > 30000) {
                                             $fe = date("m-y", (int) $fechadocAnioInicial);
                                             $extraer = explode("-", $fe);
                                             $fechadocAnioInicial = $extraer[1];
                                             $fechadocMesInicial = $extraer[0];
                                         }
                                     }
                                 }
                                 if ($caja == "") {
                                 } else {
                                     $extraercaj = explode(" ", trim($caja));
                                     $caj = $extraercaj[1];
                                 }
                                 $id_exp = $exp_id;
                                 $this->archivo = new tab_archivo();
                                 $this->archivo->setFil_id('');
                                 // Generation code max fil_nro
                                 $maxFil = new Tab_archivo();
                                 $sql2 = "SELECT\r\n                    MAX(tab_archivo.fil_nro) AS maxnro\r\n                    FROM\r\n                    tab_expediente\r\n                    INNER JOIN tab_exparchivo ON tab_exparchivo.exp_id = tab_expediente.exp_id\r\n                    INNER JOIN tab_archivo ON tab_archivo.fil_id = tab_exparchivo.fil_id\r\n                    WHERE\r\n                    tab_expediente.exp_id = {$id_exp} AND\r\n                    tab_expediente.exp_estado = 1";
                                 $cant_max = $maxFil->dbSelectBySQL($sql2);
                                 foreach ($cant_max as $lismax) {
                                     $max3 = $lismax->maxnro;
                                 }
                                 if ($max3 == "") {
                                     $max3 = 0;
                                 }
                                 $max3 = $max3 + 1;
                                 $this->archivo->setFil_nro($max3);
                                 $this->archivo->setFil_titulo(strtoupper($titledoc));
                                 $this->archivo->setFil_codigo(2);
                                 $this->archivo->setFil_subtitulo(strtoupper($subtitledoc));
                                 $this->archivo->setFil_fecha($fechahoy);
                                 $this->archivo->setIdi_id(1);
                                 $this->archivo->setFil_proc($fondo);
                                 $this->archivo->setFil_firma($nomUsuario);
                                 $this->archivo->setFil_cargo('');
                                 $this->archivo->setFil_alccon('');
                                 $sqlsopfis = new tab_sopfisico();
                                 if ($sopfis != "AP" || $sopfis != "EM" || $sopfis != "LG" || $sopfis != "AN" || $sopfis != "MM" || $sopfis != "CP") {
                                     $sopfis = "LG";
                                 }
                                 $result = $sqlsopfis->dbselectByField("sof_codigo", $sopfis);
                                 $this->archivo->setSof_id($result[0]->sof_id);
                                 $this->archivo->setFil_nrofoj('');
                                 $this->archivo->setFil_tomovol($tomovol);
                                 $this->archivo->setFil_nroejem($filnroejem);
                                 $this->archivo->setFil_nrocaj($caj);
                                 $this->archivo->setFil_nropaq('');
                                 $this->archivo->setFil_sala(strtoupper($sala));
                                 $this->archivo->setFil_estante(strtoupper($estante));
                                 $this->archivo->setFil_cuerpo(strtoupper($cuerpo));
                                 $this->archivo->setFil_balda(strtoupper($balda));
                                 $this->archivo->setFil_tipoarch('TEC');
                                 $this->archivo->setFil_mrb('BUENO');
                                 $this->archivo->setFil_mes($fechadocMesInicial);
                                 $this->archivo->setFil_anio($fechadocAnioInicial);
                                 $this->archivo->setFil_cantpaq('');
                                 $this->archivo->setFil_cantcaj('');
                                 $this->archivo->setFil_confidencialidad(1);
                                 $this->archivo->setFil_obs(strtoupper($obs));
                                 $this->archivo->setFil_estado('1');
                                 $fil_id = $this->archivo->insert();
                                 $this->archivo2 = new tab_archivo();
                                 $this->archivo2->setFil_id($fil_id);
                                 $this->archivo2->setFil_codigo($fil_id);
                                 $this->archivo2->setFil_estado('1');
                                 $this->archivo2->update();
                                 $this->exparchivo = new tab_exparchivo();
                                 $this->exparchivo->setExa_id('');
                                 $this->exparchivo->setFil_id($fil_id);
                                 $this->exparchivo->setExp_id($exp_id);
                                 $archivo_digital = new tab_archivo_digital();
                                 $archivo_digital->setFid_id('');
                                 $archivo_digital->setFil_id($fil_id);
                                 $archivo_digital->insert();
                                 $seriet = new Tab_serietramite();
                                 $this->series = new series();
                                 $ser_codigo = $this->series->obtenerCodigoSerie($id_serie);
                                 //insert grupos documentales y tipos documentales
                                 $this->tramite = new tab_tramite();
                                 $tramitecc = new tab_tramitecuerpos();
                                 $sqltramite = "SELECT\r\n        tab_tramite.tra_descripcion,\r\n        tab_tramite.tra_id\r\n        FROM\r\n        tab_series\r\n        INNER JOIN tab_serietramite ON tab_series.ser_id = tab_serietramite.ser_id\r\n        INNER JOIN tab_tramite ON tab_tramite.tra_id = tab_serietramite.tra_id\r\n        WHERE\r\n        tab_series.ser_id = {$id_serie}";
                                 $rows = $seriet->dbSelectBySQL($sqltramite);
                                 $v = 0;
                                 foreach ($rows as $row) {
                                     if ($row->tra_descripcion == 'GRUPO DOCUMENTAL COMPUESTA') {
                                         $v++;
                                         $tra_id = $row->tra_id;
                                         $obtenerColumnCueId = $tramitecc->dbselectByField("tra_id", $tra_id);
                                         $cue_id = $obtenerColumnCueId[0]->cue_id;
                                     }
                                 }
                                 if ($v == 0) {
                                     $this->tramite->setTra_orden(1);
                                     $this->tramite->setTra_codigo(1);
                                     $this->tramite->setTra_descripcion("GRUPO DOCUMENTAL COMPUESTA");
                                     $this->tramite->setTra_fecha_crea(date("Y-m-d"));
                                     $this->tramite->setTra_usuario_crea($_SESSION['USU_ID']);
                                     $this->tramite->setTra_estado(1);
                                     $tra_id = $this->tramite->insert();
                                     $seriet->setSer_id($id_serie);
                                     $seriet->setTra_id($tra_id);
                                     $seriet->setSts_fecha_crea(date("Y-m-d"));
                                     $seriet->setSts_fecha_reg(date("Y-m-d"));
                                     $seriet->setSts_usuario_crea($_SESSION['USU_ID']);
                                     $seriet->setSts_usu_reg($_SESSION['USU_ID']);
                                     $seriet->setVer_id('0');
                                     $seriet->setSts_estado(1);
                                     $seriet->insert();
                                     $this->tramite = new tramite();
                                     $tra_codigo = $this->tramite->obtenerCodigoTramite($tra_id);
                                     $tcuerpos = new tab_cuerpos();
                                     $tcuerpos->setCue_id('');
                                     $tcuerpos->setCue_orden(1);
                                     $tcuerpos->setCue_codigo(1);
                                     $tcuerpos->setCue_descripcion("UNIDAD DOCUMENTAL SIMPLE");
                                     $tcuerpos->setCue_fecha_crea(date("Y-m-d"));
                                     $tcuerpos->setCue_usuario_crea($_SESSION['USU_ID']);
                                     $tcuerpos->setCue_estado(1);
                                     $cue_id = $tcuerpos->insert();
                                     // Last code
                                     //$tramitecc = new tab_tramitecuerpos();
                                     $tramitecc->setCue_id($cue_id);
                                     $tramitecc->setTra_id($tra_id);
                                     $tramitecc->setTrc_estado(1);
                                     $tramitecc->insert();
                                 }
                                 //insert
                                 $this->exparchivo->setTra_id($tra_id);
                                 $this->exparchivo->setCue_id($cue_id);
                                 $this->exparchivo->setExa_condicion('1');
                                 $this->exparchivo->setExa_estado(1);
                                 $this->exparchivo->insert();
                                 //Fin del archivo
                             }
                             $i++;
                             $ct++;
                         }
                     } else {
                         $msg = "<font color='red'>FORMATO GNT - SSA NO ES CORRECTO</font>";
                         unlink($Dir);
                         $this->index($msg);
                         exit;
                     }
                     $msg .= "<b style='color:green'>SE GUARDO CORRECTAMENTE</b><br>";
                     $msg .= "<a href='" . PATH_DOMAIN . "/nuevoExpediente/index/'>Ver registro</a>";
                     unlink($Dir);
                     $this->index($msg);
                     exit;
                 } else {
                     $msg = "<font color='red'>FORMATO GNT - SSA NO ES CORRECTO</font>";
                     unlink($Dir);
                     $this->index($msg);
                 }
                 //end
             } else {
                 if ($tipoformato == 4) {
                     //CONTRATACIONES
                     $cantidaddoc = $highestRow - 38;
                     $fondo = $objPHPExcel->getActiveSheet()->getCell("E8")->getValue();
                     $subfondo = $objPHPExcel->getActiveSheet()->getCell("E9")->getValue();
                     $seccion = $objPHPExcel->getActiveSheet()->getCell("E10")->getValue();
                     $subseccion = $objPHPExcel->getActiveSheet()->getCell("E11")->getValue();
                     $serie = $objPHPExcel->getActiveSheet()->getCell("E13")->getValue();
                     $tituloexpediente = $objPHPExcel->getActiveSheet()->getCell("E14")->getValue();
                     $fechasExtremas = $objPHPExcel->getActiveSheet()->getCell("U13")->getValue();
                     $ml = $objPHPExcel->getActiveSheet()->getCell("D16")->getValue();
                     $objHoja = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
                     $objWorksheet = $objPHPExcel->getActiveSheet();
                     $tituloserie = explode("\n", $serie);
                     $cantidaserie = count($tituloserie);
                     if ($cantidaserie > 1) {
                         $msg = "<font color='red'>Error, Elimine los saltos de linea del T&iacute;tulo de la Serie</font><br>";
                         unlink($Dir);
                         $this->index($msg);
                         exit;
                     }
                     $tituloexp = explode("\n", $tituloexpediente);
                     $cantidaexpediente = count($tituloexp);
                     if ($cantidaexpediente > 1) {
                         $msg = "<font color='red'>Error, Elimine los saltos de linea en T&iacute;tulo de Expediente </font><br>";
                         unlink($Dir);
                         $this->index($msg);
                         exit;
                     }
                     if ($highestColumn != "W") {
                         $msg = "<font color='red'>FORMATO CONTRATACIONES NO ES CORRECTO</font>";
                         unlink($Dir);
                         $this->index($msg);
                         exit;
                     }
                     //$msg= $cantidaddoc; exit();
                     //$msg= $fondo."<br>";
                     //$msg= $subfondo."<br>";
                     //$msg= $seccion."<br>";
                     //$msg= $subseccion."<br>";
                     //$msg= $serie."<br>";
                     //$msg= $tituloexpediente."<br>";
                     //$msg= $fechasExtremas."<br>";
                     //$msg= $ml."<br>";
                     //$msg= $nrColumns;
                     //exit();
                     //$l=0;
                     //$msg= '<table border="1">' . "\n";
                     //foreach ($objWorksheet->getRowIterator() as $row) {
                     //$msg= '<tr>' . "\n";
                     // $l++;
                     //$cellIterator = $row->getCellIterator();
                     //$cellIterator->setIterateOnlyExistingCells(false); // This loops all cells,
                     //foreach ($cellIterator as $cell) {
                     //$msg= '<td>' . htmlentities($cell->getValue(), ENT_IGNORE, 'utf-8') . '</td>' . "\n";
                     //}
                     //
                     //$msg= '</tr>' . "\n";
                     //
                     //}
                     //$msg= '</table>' . "\n";
                     //$msg= "la cantidad e:".$cantidaddoc;
                     //exit();
                     if (trim($subseccion) == "SUBGERENCIA DE CONSERVACION VIAL") {
                         $subseccion = "PROYECTOS DE CONSERVACION VIAL";
                     }
                     $tab_fondo = new Tab_fondo();
                     $tab_unidad = new Tab_unidad();
                     $tab_series = new Tab_series();
                     //obtener fondo y subfondo
                     $sql = "select* from tab_fondo where fon_descripcion LIKE '%{$fondo}%'";
                     $sql2 = "select* from tab_fondo where fon_descripcion LIKE '%{$subfondo}%'";
                     $resultado = $tab_fondo->dbSelectBySQL($sql);
                     $resultado2 = $tab_fondo->dbSelectBySQL($sql2);
                     $id_fondo = $resultado[0]->fon_id;
                     $id_subfondo = $resultado2[0]->fon_id;
                     $ubicacion = $resultado2[0]->fon_codigo;
                     switch ($ubicacion) {
                         case "ON":
                             $ubicacion = "LA PAZ";
                             break;
                         case "LP":
                             $ubicacion = "LA PAZ";
                             break;
                         case "SC":
                             $ubicacion = "SANTA CRUZ";
                             break;
                         case "PT":
                             $ubicacion = "POTOSI";
                             break;
                         case "BN":
                             $ubicacion = "BENI";
                             break;
                         case "PN":
                             $ubicacion = "PANDO";
                             break;
                         case "CB":
                             $ubicacion = "COCHABAMBA";
                             break;
                         case "OR":
                             $ubicacion = "ORURO";
                             break;
                         case "CH":
                             $ubicacion = "CHUQUISACA";
                             break;
                         case "TJ":
                             $ubicacion = "TARIJA";
                             break;
                     }
                     if ($seccion == "DIRECCION GENERAL TECNICA") {
                         if ($id_subfondo == 3) {
                             $seccion = "TECNICA-OPERATIVA";
                         } else {
                             $seccion = "AREA TECNICA";
                         }
                     }
                     //obtener el fon_id
                     $subseccion = trim($subseccion);
                     if ($subseccion == "") {
                         $sql3 = "SELECT\r\ntab_unidad.uni_id,\r\nf.fon_id,\r\ntab_unidad.uni_descripcion\r\nFROM tab_fondo as f\r\nINNER JOIN tab_unidad ON f.fon_id = tab_unidad.fon_id\r\nWHERE\r\nf.fon_id = {$id_subfondo} and tab_unidad.uni_descripcion LIKE'%{$seccion}%'";
                     } else {
                         $sql3 = "SELECT\r\ntab_unidad.uni_id,\r\nf.fon_id,\r\ntab_unidad.uni_descripcion\r\nFROM tab_fondo as f\r\nINNER JOIN tab_unidad ON f.fon_id = tab_unidad.fon_id\r\nWHERE\r\nf.fon_id = {$id_subfondo} and tab_unidad.uni_descripcion LIKE'%{$subseccion}%'";
                     }
                     $resultado3 = $tab_unidad->dbSelectBySQL($sql3);
                     foreach ($resultado3 as $rowseccion) {
                         $id_seccion = $rowseccion->uni_id;
                     }
                     //obtengo la serie
                     $sql4 = "SELECT\r\ntab_series.ser_categoria,\r\ntab_series.ser_id\r\nFROM\r\ntab_fondo\r\nINNER JOIN tab_unidad ON tab_fondo.fon_id = tab_unidad.fon_id\r\nINNER JOIN tab_series ON tab_unidad.uni_id = tab_series.uni_id\r\nWHERE\r\ntab_fondo.fon_id = {$id_subfondo} AND tab_series.ser_categoria LIKE '%{$serie}%'";
                     $resultado4 = $tab_series->dbSelectBySQL($sql4);
                     foreach ($resultado4 as $rowserie) {
                         $id_serie = $rowserie->ser_id;
                     }
                     //$ml=$objPHPExcel->getActiveSheet()->getCell("D16")->getValue();
                     if ($id_serie == "") {
                         $msg = "<font color='red'>Error, No existe la Serie Asignada</font><br>";
                         unlink($Dir);
                         $this->index($msg);
                         exit;
                     } else {
                         if ($id_subfondo == "") {
                             $msg = "<font color='red'>Error, No existe el Subfondo</font><br>";
                             unlink($Dir);
                             $this->index($msg);
                             exit;
                         } else {
                             if ($id_seccion == "") {
                                 $msg = "<font color='red'>Error, No existe la Secci&oacute;n</font><br>";
                                 unlink($Dir);
                                 $this->index($msg);
                                 exit;
                             }
                         }
                     }
                     //$msg= $nrColumns;
                     //exit();
                     if ($highestColumn == "W") {
                         if ($ml == "ML") {
                             $i = 1;
                             $ct = 19;
                             $t = 0;
                             $expsadg = new Tab_expisadg();
                             $resulall = $expsadg->dbselectByField("exp_titulo", strtoupper($tituloexpediente));
                             foreach ($resulall as $list) {
                                 $t++;
                             }
                             $fechafinal = '';
                             $fechainicial = '';
                             $exp_fechas = explode("-", $fechasExtremas);
                             if (!empty($exp_fechas[1])) {
                                 $fechafinal = trim($exp_fechas[1]);
                             }
                             if (!empty($exp_fechas[0])) {
                                 $fechainicial = trim($exp_fechas[0]);
                             }
                             if ($t > 0) {
                                 $msg = "<font color='red'>Error! existe otro nombre duplicado</font>";
                                 unlink($Dir);
                                 $this->index($msg);
                                 exit;
                             }
                             $expediente = new expediente();
                             $hoy = date("Y-m-d");
                             $this->expediente = new tab_expediente();
                             //        $this->expediente->setRequest2Object($_REQUEST);
                             $this->expediente->setExp_id('');
                             $this->expediente->setSer_id($id_serie);
                             // Generation code
                             $this->expediente->setExp_codigo($expediente->generaCodigo($id_serie));
                             $this->expediente->setExp_lugar($ubicacion);
                             $this->expediente->setSof_id(1);
                             $this->expediente->setExp_ori(0);
                             $this->expediente->setExp_cop(0);
                             $this->expediente->setExp_fot(0);
                             $this->expediente->setExp_obs('');
                             $this->expediente->setExp_corr('AUTO');
                             $this->expediente->setExp_estado(1);
                             $this->expediente->setExp_migrarexcel(1);
                             $exp_id = $this->expediente->insert2();
                             // Update count
                             //        if ($_REQUEST['ser_corr'] == 'AUTO') {
                             //            // Auto
                             //            $tseries = new tab_series();
                             //            $row2 = $tseries->dbselectByField("ser_id", $_REQUEST['ser_id']);
                             //            $row2 = $row2[0];
                             //            $tseries->setSer_id($_REQUEST['ser_id']);
                             //            $ser_exp = $row2->ser_exp + 1;
                             //            $tseries->setSer_exp($ser_exp);
                             //            $tseries->update();
                             //        } else {
                             //            // Manual
                             //            $tseries = new tab_series();
                             //            $tseries->setSer_id($_REQUEST['ser_id']);
                             //            $tseries->setSer_exp($_REQUEST['exp_codigo']);
                             //            $tseries->update();
                             //        }
                             //$this->expisadg->setTrm_id(1);
                             //        $expisadg = new tab_expisadg();
                             //        $expisadg->setExp_id($exp_id);
                             //        $expisadg->setExp_titulo($expediente);
                             //        $expisadg->setExp_nomprod($fondo);
                             //        $expisadg->setExp_fecha_exi(date('Y-m-d'));
                             //        $expisadg->setExp_fecha_exf(date('Y-m-d'));
                             //        $expisadg->setExp_anioi($fechainicial);
                             //        $expisadg->setExp_aniof($fechafinal);
                             //        $expisadg->setIdi_id(1);
                             //        $expisadg->setExp_estado(1);
                             //        $eig_id = $expisadg->insert();
                             $fechahoy = date('Y-m-d');
                             $expisadg = new tab_expisadg();
                             $expisadg->setExp_id($exp_id);
                             $expisadg->setExp_titulo($tituloexpediente);
                             $expisadg->setExp_fecha_exi($fechahoy);
                             //        $expisadg->setExp_mesi('');
                             $expisadg->setExp_anioi($fechainicial);
                             $expisadg->setExp_fecha_exf($fechahoy);
                             //        $expisadg->setExp_mesf('');
                             $expisadg->setExp_aniof($fechafinal);
                             $expisadg->setExp_nivdes('EXPEDIENTE');
                             //        $expisadg->setExp_volsop('');
                             $expisadg->setExp_nomprod($fondo);
                             //        $expisadg->setExp_hisins('');
                             //        $expisadg->setExp_hisarc('');
                             $expisadg->setExp_foring('TRANSFERENCIA');
                             //        $expisadg->setExp_alccon('');
                             //        $expisadg->setExp_vaseel('');
                             //        $expisadg->setExp_nueing('');
                             $expisadg->setExp_org('LOS DOCUMENTOS DEL PROYECTO FUERON IDENTIFICADOS, CLASIFICADOS Y ORDENADOS EN LAS CAJAS DE ACUERDO AL CHECK LIST DE LA SERIE A LA QUE CORRESPONDEN.');
                             $expisadg->setExp_conacc('EL ACCESO ESTA SUJETO A LO QUE ESTABLECE LA CONSTITUCION POLITICA DEL ESTADO Y EL ARTICULO 18 DE LA LEY 2341 SOBRE PROCESOS ADMINISTRATIVOS.');
                             //        $expisadg->setExp_conrep('');
                             $expisadg->setIdi_id(1);
                             $expisadg->setExp_carfis('BUENO');
                             //        $expisadg->setExp_insdes('');
                             //        $expisadg->setExp_exloor('');
                             //        $expisadg->setExp_exloco('');
                             //        $expisadg->setExp_underel('');
                             //        $expisadg->setExp_notpub('');
                             //        $expisadg->setExp_notas('');
                             //        $expisadg->setExp_notarc('');
                             $expisadg->setExp_regnor('ISAD-G, ISAAR(CPF), RCAA');
                             $expisadg->setExp_fecdes(date('Y-m-d'));
                             $expisadg->setExp_estado(1);
                             $eig_id = $expisadg->insert();
                             // Save expfondo data
                             $texf = new Tab_expfondo();
                             $texf->setExp_id($exp_id);
                             $usuario = new usuario();
                             $fon_id = $usuario->getFon_id($_SESSION['USU_ID']);
                             $nomUsuario = $usuario->obtenerNombre($_SESSION['USU_ID']);
                             $texf->setExf_fecha_exi($fechahoy);
                             $texf->setFon_id($fon_id);
                             $texf->setExf_estado('1');
                             $texf->insert();
                             // Save expusuario data
                             $this->expusuario = new expusuario();
                             $this->expusuario->saveExp($exp_id, $_SESSION['USU_ID']);
                             //        // Save expcontenedor data
                             //        $con = new expcontenedor();
                             //        $con->saveExpCont($_REQUEST['con_id'], $_REQUEST['suc_id'], $exp_id);
                             //        // Save proyecto list data (tramos)
                             //        if (isset($_REQUEST['lista_tramo'])) {
                             //            $proyectos = $_REQUEST['lista_tramo'];
                             //            foreach ($proyectos as $proyecto) {
                             //                $exp = new tab_expproyecto();
                             //                $exp->setExp_id($exp_id);
                             //                $exp->setPry_id($proyecto);
                             //                $exp->setEpp_estado(1);
                             //                $exp->insert();
                             //            }
                             //        }
                             // Save data dynamic
                             $c = 0;
                             $caj = "";
                             $cnt = 0;
                             //insert usuario serie
                             $tab_usu_serie = new Tab_usu_serie();
                             $sqlususerie = "select* from tab_usu_serie\r\n            where usu_id='" . $_SESSION['USU_ID'] . "'\r\n            and ser_id='" . $id_serie . "'\r\n            and use_estado=1";
                             $comprobar_usu_serie = $tab_usu_serie->dbSelectBySQL($sqlususerie);
                             $cnt = count($comprobar_usu_serie);
                             if ($cnt == 0) {
                                 $tab_usu_serie->setUse_id('');
                                 $tab_usu_serie->setUsu_id($_SESSION['USU_ID']);
                                 $tab_usu_serie->setSer_id($id_serie);
                                 $tab_usu_serie->setUse_estado(1);
                                 $tab_usu_serie->insert();
                             }
                             while ($i <= $cantidaddoc) {
                                 $caja = $objPHPExcel->getActiveSheet()->getCell("A" . $ct)->getValue();
                                 $filnroejem = $objPHPExcel->getActiveSheet()->getCell("C" . $ct)->getValue();
                                 $correlativo = $objPHPExcel->getActiveSheet()->getCell("E" . $ct)->getValue();
                                 $subtitledoc = $objPHPExcel->getActiveSheet()->getCell("F" . $ct)->getValue();
                                 $subtitledoc2 = $objPHPExcel->getActiveSheet()->getCell("I" . $ct)->getValue();
                                 $unidadsolicitante = $objPHPExcel->getActiveSheet()->getCell("J" . $ct)->getValue();
                                 $titledoc = $objPHPExcel->getActiveSheet()->getCell("H" . $ct)->getValue();
                                 $financiamiento = $objPHPExcel->getActiveSheet()->getCell("L" . $ct)->getValue();
                                 $contrato = $objPHPExcel->getActiveSheet()->getCell("N" . $ct)->getValue();
                                 $nrofojas = $objPHPExcel->getActiveSheet()->getCell("Q" . $ct)->getValue();
                                 $fecha = trim($objPHPExcel->getActiveSheet()->getCell("O" . $ct)->getValue());
                                 $tomovol = $objPHPExcel->getActiveSheet()->getCell("P" . $ct)->getValue();
                                 $sopfis = $objPHPExcel->getActiveSheet()->getCell("R" . $ct)->getValue();
                                 $sala = $objPHPExcel->getActiveSheet()->getCell("S" . $ct)->getValue();
                                 $estante = $objPHPExcel->getActiveSheet()->getCell("T" . $ct)->getValue();
                                 $cuerpo = $objPHPExcel->getActiveSheet()->getCell("U" . $ct)->getValue();
                                 $balda = $objPHPExcel->getActiveSheet()->getCell("V" . $ct)->getValue();
                                 $obs = $objPHPExcel->getActiveSheet()->getCell("W" . $ct)->getValue();
                                 //todavia en trabajo
                                 $subtitledoc = $subtitledoc . " " . $subtitledoc2;
                                 if ($titledoc != "") {
                                     //$msg= $caja."<br>";
                                     //$msg= $filnroejem."<br>";
                                     //$msg= $correlativo."<br>";
                                     //$msg= $titledoc."<br>";
                                     //$msg= $subtitledoc."<br>";
                                     ////$msg= $productor."<br>";
                                     //$msg= $contrato."<br>";
                                     //$msg= $fecha."<br>";
                                     //$msg= $tomovol."<br>";
                                     //$msg= $sopfis."<br>";
                                     //$msg= $sala."<br>";
                                     //$msg= $estante."<br>";
                                     //$msg= $cuerpo."<br>";
                                     //$msg= $balda."<br>";
                                     //$msg= $obs."<br>";
                                     //exit();
                                     if ($fecha != "s/f") {
                                         $extfe = explode("\n", $fecha);
                                         $cantidadfecha = count($extfe);
                                         if ($cantidadfecha > 1) {
                                             $fechadocAnioInicial = $extfe[0];
                                             $fechadocMesInicial = $extfe[1];
                                         } else {
                                             $fechadocAnioInicial = $extfe[0];
                                             $fechadocMesInicial = "";
                                             if ($fechadocAnioInicial > 30000) {
                                                 $fe = date("m-y", (int) $fechadocAnioInicial);
                                                 $extraer = explode("-", $fe);
                                                 $fechadocAnioInicial = $extraer[1];
                                                 $fechadocMesInicial = $extraer[0];
                                             }
                                         }
                                     }
                                     //exit();
                                     if ($caja == "") {
                                     } else {
                                         $extraercaj = explode(" ", trim($caja));
                                         $caj = $extraercaj[1];
                                     }
                                     $id_exp = $exp_id;
                                     $this->archivo = new tab_archivo();
                                     $this->archivo->setFil_id('');
                                     // Generation code max fil_nro
                                     $maxFil = new Tab_archivo();
                                     $sql2 = "SELECT\r\n                    MAX(tab_archivo.fil_nro) AS maxnro\r\n                    FROM\r\n                    tab_expediente\r\n                    INNER JOIN tab_exparchivo ON tab_exparchivo.exp_id = tab_expediente.exp_id\r\n                    INNER JOIN tab_archivo ON tab_archivo.fil_id = tab_exparchivo.fil_id\r\n                    WHERE\r\n                    tab_expediente.exp_id = {$id_exp} AND\r\n                    tab_expediente.exp_estado = 1";
                                     $cant_max = $maxFil->dbSelectBySQL($sql2);
                                     foreach ($cant_max as $lismax) {
                                         $max3 = $lismax->maxnro;
                                     }
                                     if ($max3 == "") {
                                         $max3 = 0;
                                     }
                                     $max3 = $max3 + 1;
                                     $this->archivo->setFil_nro($max3);
                                     $this->archivo->setFil_codigo(2);
                                     $this->archivo->setFil_titulo(strtoupper($titledoc));
                                     $this->archivo->setFil_subtitulo(strtoupper($subtitledoc));
                                     $this->archivo->setFil_fecha($fechahoy);
                                     $this->archivo->setIdi_id(1);
                                     $this->archivo->setFil_proc($fondo);
                                     $this->archivo->setFil_firma($nomUsuario);
                                     $this->archivo->setFil_cargo($unidadsolicitante);
                                     $this->archivo->setFil_alccon($financiamiento);
                                     $sqlsopfis = new tab_sopfisico();
                                     if ($sopfis != "AP" || $sopfis != "EM" || $sopfis != "LG" || $sopfis != "AN" || $sopfis != "MM" || $sopfis != "CP") {
                                         $sopfis = "LG";
                                     }
                                     $result = $sqlsopfis->dbselectByField("sof_codigo", $sopfis);
                                     $this->archivo->setSof_id($result[0]->sof_id);
                                     $this->archivo->setFil_nrofoj($nrofojas);
                                     $this->archivo->setFil_tomovol($tomovol);
                                     $this->archivo->setFil_nroejem($filnroejem);
                                     $this->archivo->setFil_nrocaj($caj);
                                     $this->archivo->setFil_nropaq('');
                                     $this->archivo->setFil_sala(strtoupper($sala));
                                     $this->archivo->setFil_estante(strtoupper($estante));
                                     $this->archivo->setFil_cuerpo(strtoupper($cuerpo));
                                     $this->archivo->setFil_balda(strtoupper($balda));
                                     $this->archivo->setFil_tipoarch('TEC');
                                     $this->archivo->setFil_mrb('BUENO');
                                     $this->archivo->setFil_mes($fechadocMesInicial);
                                     $this->archivo->setFil_anio($fechadocAnioInicial);
                                     $this->archivo->setFil_cantpaq('');
                                     $this->archivo->setFil_cantcaj('');
                                     $this->archivo->setFil_confidencialidad(1);
                                     $this->archivo->setFil_obs(strtoupper($obs));
                                     $this->archivo->setFil_estado('1');
                                     $fil_id = $this->archivo->insert();
                                     $this->archivo2 = new tab_archivo();
                                     $this->archivo2->setFil_id($fil_id);
                                     $this->archivo2->setFil_codigo($fil_id);
                                     $this->archivo2->setFil_estado('1');
                                     $this->archivo2->update();
                                     $this->exparchivo = new tab_exparchivo();
                                     $this->exparchivo->setExa_id('');
                                     $this->exparchivo->setFil_id($fil_id);
                                     $this->exparchivo->setExp_id($exp_id);
                                     $archivo_digital = new tab_archivo_digital();
                                     $archivo_digital->setFid_id('');
                                     $archivo_digital->setFil_id($fil_id);
                                     $archivo_digital->insert();
                                     $seriet = new Tab_serietramite();
                                     $this->series = new series();
                                     $ser_codigo = $this->series->obtenerCodigoSerie($id_serie);
                                     //insert grupos documentales y tipos documentales
                                     $this->tramite = new tab_tramite();
                                     $tramitecc = new tab_tramitecuerpos();
                                     $sqltramite = "SELECT\r\n        tab_tramite.tra_descripcion,\r\n        tab_tramite.tra_id\r\n        FROM\r\n        tab_series\r\n        INNER JOIN tab_serietramite ON tab_series.ser_id = tab_serietramite.ser_id\r\n        INNER JOIN tab_tramite ON tab_tramite.tra_id = tab_serietramite.tra_id\r\n        WHERE\r\n        tab_series.ser_id = {$id_serie}";
                                     $rows = $seriet->dbSelectBySQL($sqltramite);
                                     $v = 0;
                                     foreach ($rows as $row) {
                                         if ($row->tra_descripcion == 'GRUPO DOCUMENTAL COMPUESTA') {
                                             $v++;
                                             $tra_id = $row->tra_id;
                                             $obtenerColumnCueId = $tramitecc->dbselectByField("tra_id", $tra_id);
                                             $cue_id = $obtenerColumnCueId[0]->cue_id;
                                         }
                                     }
                                     if ($v == 0) {
                                         $this->tramite->setTra_orden(1);
                                         $this->tramite->setTra_codigo(1);
                                         $this->tramite->setTra_descripcion("GRUPO DOCUMENTAL COMPUESTA");
                                         $this->tramite->setTra_fecha_crea(date("Y-m-d"));
                                         $this->tramite->setTra_usuario_crea($_SESSION['USU_ID']);
                                         $this->tramite->setTra_estado(1);
                                         $tra_id = $this->tramite->insert();
                                         $seriet->setSer_id($id_serie);
                                         $seriet->setTra_id($tra_id);
                                         $seriet->setSts_fecha_crea(date("Y-m-d"));
                                         $seriet->setSts_fecha_reg(date("Y-m-d"));
                                         $seriet->setSts_usuario_crea($_SESSION['USU_ID']);
                                         $seriet->setSts_usu_reg($_SESSION['USU_ID']);
                                         $seriet->setVer_id('0');
                                         $seriet->setSts_estado(1);
                                         $seriet->insert();
                                         $this->tramite = new tramite();
                                         $tra_codigo = $this->tramite->obtenerCodigoTramite($tra_id);
                                         $tcuerpos = new tab_cuerpos();
                                         $tcuerpos->setCue_id('');
                                         $tcuerpos->setCue_orden(1);
                                         $tcuerpos->setCue_codigo(1);
                                         $tcuerpos->setCue_descripcion("UNIDAD DOCUMENTAL SIMPLE");
                                         $tcuerpos->setCue_fecha_crea(date("Y-m-d"));
                                         $tcuerpos->setCue_usuario_crea($_SESSION['USU_ID']);
                                         $tcuerpos->setCue_estado(1);
                                         $cue_id = $tcuerpos->insert();
                                         // Last code
                                         //$tramitecc = new tab_tramitecuerpos();
                                         $tramitecc->setCue_id($cue_id);
                                         $tramitecc->setTra_id($tra_id);
                                         $tramitecc->setTrc_estado(1);
                                         $tramitecc->insert();
                                     }
                                     //insert
                                     $this->exparchivo->setTra_id($tra_id);
                                     $this->exparchivo->setCue_id($cue_id);
                                     $this->exparchivo->setExa_condicion('1');
                                     $this->exparchivo->setExa_estado(1);
                                     $this->exparchivo->insert();
                                     //Fin del archivo
                                 }
                                 $i++;
                                 $ct++;
                             }
                         } else {
                             $msg = "<font color='red'>EL FORMATO CONTRATACIONES NO ES CORRECTO</font>";
                             unlink($Dir);
                             $this->index($msg);
                             exit;
                         }
                         $msg .= "<b style='color:green'>SE GUARDO CORRECTAMENTE</b><br>";
                         $msg .= "<a href='" . PATH_DOMAIN . "/nuevoExpediente/index/'>Ver registro</a>";
                         unlink($Dir);
                         $this->index($msg);
                         exit;
                     } else {
                         $msg = "<font color='red'>FORMATO CONTRATACIONES No ES CORRECTO</font>";
                         unlink($Dir);
                         $this->index($msg);
                     }
                 } else {
                     if ($tipoformato == 5) {
                         //CORRESPONDENCIA
                         $cantidaddoc = $highestRow - 34;
                         $fondo = $objPHPExcel->getActiveSheet()->getCell("E8")->getValue();
                         $subfondo = $objPHPExcel->getActiveSheet()->getCell("E9")->getValue();
                         $seccion = $objPHPExcel->getActiveSheet()->getCell("E10")->getValue();
                         $subseccion = $objPHPExcel->getActiveSheet()->getCell("E11")->getValue();
                         $serie = $objPHPExcel->getActiveSheet()->getCell("E13")->getValue();
                         $tituloexpediente = $objPHPExcel->getActiveSheet()->getCell("E14")->getValue();
                         $fechasExtremas = $objPHPExcel->getActiveSheet()->getCell("M13")->getValue();
                         $ml = $objPHPExcel->getActiveSheet()->getCell("D16")->getValue();
                         $objHoja = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
                         $objWorksheet = $objPHPExcel->getActiveSheet();
                         $tituloserie = explode("\n", $serie);
                         $cantidaserie = count($tituloserie);
                         if ($cantidaserie > 1) {
                             $msg = "<font color='red'>Error, Elimine los saltos de linea del T&iacute;tulo de la Serie</font><br>";
                             unlink($Dir);
                             $this->index($msg);
                             exit;
                         }
                         $tituloexp = explode("\n", $tituloexpediente);
                         $cantidaexpediente = count($tituloexp);
                         if ($cantidaexpediente > 1) {
                             $msg = "<font color='red'>Error, Elimine los saltos de linea en T&iacute;tulo de Expediente </font><br>";
                             unlink($Dir);
                             $this->index($msg);
                             exit;
                         }
                         //$msg= $fondo."<br>";
                         //$msg= $subfondo."<br>";
                         //$msg= $seccion."<br>";
                         //$msg= $subseccion."<br>";
                         //$msg= $serie."<br>";
                         //$msg= $tituloexpediente."<br>";
                         //$msg= $fechasExtremas."<br>";
                         //$msg= $ml."<br>";
                         //exit();
                         //$msg= '<table border="1">' . "\n";
                         //foreach ($objWorksheet->getRowIterator() as $row) {
                         //$msg= '<tr>' . "\n";
                         //$cellIterator = $row->getCellIterator();
                         //$cellIterator->setIterateOnlyExistingCells(false); // This loops all cells,
                         //foreach ($cellIterator as $cell) {
                         //$msg= '<td>' . htmlentities($cell->getValue(), ENT_IGNORE, 'utf-8') . '</td>' . "\n";
                         //}
                         //$msg= '</tr>' . "\n";
                         //}
                         //$msg= '</table>' . "\n";
                         if ($highestColumn != "O") {
                             $msg = "<font color='red'>EL FORMATO DE CORRESPONDENCIA NO ES CORRECTO</font>";
                             unlink($Dir);
                             $this->index($msg);
                             exit;
                         }
                         $tab_fondo = new Tab_fondo();
                         $tab_unidad = new Tab_unidad();
                         $tab_series = new Tab_series();
                         //obtener fondo y subfondo
                         $sql = "select* from tab_fondo where fon_descripcion LIKE '%{$fondo}%'";
                         $sql2 = "select* from tab_fondo where fon_descripcion LIKE '%{$subfondo}%'";
                         $resultado = $tab_fondo->dbSelectBySQL($sql);
                         $resultado2 = $tab_fondo->dbSelectBySQL($sql2);
                         $id_fondo = $resultado[0]->fon_id;
                         $id_subfondo = $resultado2[0]->fon_id;
                         $ubicacion = $resultado2[0]->fon_codigo;
                         switch ($ubicacion) {
                             case "ON":
                                 $ubicacion = "LA PAZ";
                                 break;
                             case "LP":
                                 $ubicacion = "LA PAZ";
                                 break;
                             case "SC":
                                 $ubicacion = "SANTA CRUZ";
                                 break;
                             case "PT":
                                 $ubicacion = "POTOSI";
                                 break;
                             case "BN":
                                 $ubicacion = "BENI";
                                 break;
                             case "PN":
                                 $ubicacion = "PANDO";
                                 break;
                             case "CB":
                                 $ubicacion = "COCHABAMBA";
                                 break;
                             case "OR":
                                 $ubicacion = "ORURO";
                                 break;
                             case "CH":
                                 $ubicacion = "CHUQUISACA";
                                 break;
                             case "TJ":
                                 $ubicacion = "TARIJA";
                                 break;
                         }
                         if ($seccion == "DIRECCION GENERAL TECNICA") {
                             if ($id_subfondo == 3) {
                                 $seccion = "TECNICA-OPERATIVA";
                             } else {
                                 $seccion = "AREA TECNICA";
                             }
                         }
                         //obtener el fon_id
                         $subseccion = trim($subseccion);
                         if ($subseccion == "") {
                             $sql3 = "SELECT\r\ntab_unidad.uni_id,\r\nf.fon_id,\r\ntab_unidad.uni_descripcion\r\nFROM tab_fondo as f\r\nINNER JOIN tab_unidad ON f.fon_id = tab_unidad.fon_id\r\nWHERE\r\nf.fon_id = {$id_subfondo} and tab_unidad.uni_descripcion LIKE'%{$seccion}%'";
                         } else {
                             $sql3 = "SELECT\r\ntab_unidad.uni_id,\r\nf.fon_id,\r\ntab_unidad.uni_descripcion\r\nFROM tab_fondo as f\r\nINNER JOIN tab_unidad ON f.fon_id = tab_unidad.fon_id\r\nWHERE\r\nf.fon_id = {$id_subfondo} and tab_unidad.uni_descripcion LIKE'%{$subseccion}%'";
                         }
                         $resultado3 = $tab_unidad->dbSelectBySQL($sql3);
                         foreach ($resultado3 as $rowseccion) {
                             $id_seccion = $rowseccion->uni_id;
                         }
                         //obtengo la serie
                         $sql4 = "SELECT\r\ntab_series.ser_categoria,\r\ntab_series.ser_id\r\nFROM\r\ntab_fondo\r\nINNER JOIN tab_unidad ON tab_fondo.fon_id = tab_unidad.fon_id\r\nINNER JOIN tab_series ON tab_unidad.uni_id = tab_series.uni_id\r\nWHERE\r\ntab_fondo.fon_id = {$id_subfondo} AND tab_series.ser_categoria LIKE '%{$serie}%'";
                         $resultado4 = $tab_series->dbSelectBySQL($sql4);
                         foreach ($resultado4 as $rowserie) {
                             $id_serie = $rowserie->ser_id;
                         }
                         $ml = $objPHPExcel->getActiveSheet()->getCell("D16")->getValue();
                         if ($id_serie == "") {
                             $msg = "<font color='red'>Error, No existe la Serie Asignada</font><br>";
                             unlink($Dir);
                             $this->index($msg);
                             exit;
                         } else {
                             if ($id_subfondo == "") {
                                 $msg = "<font color='red'>Error, No existe el Subfondo</font><br>";
                                 unlink($Dir);
                                 $this->index($msg);
                                 exit;
                             } else {
                                 if ($id_seccion == "") {
                                     $msg = "<font color='red'>Error, No existe la Secci&oacute;n</font><br>";
                                     unlink($Dir);
                                     $this->index($msg);
                                     exit;
                                 }
                             }
                         }
                         //$msg= $id_seccion."<br>";
                         //$msg= $id_subfondo."<br>";
                         //$msg= $nrColumns."<br>";
                         //exit();
                         if ($highestColumn == "O") {
                             if ($ml == "ML") {
                                 $i = 1;
                                 $ct = 18;
                                 $t = 0;
                                 $expsadg = new Tab_expisadg();
                                 $resulall = $expsadg->dbselectByField("exp_titulo", strtoupper($tituloexpediente));
                                 foreach ($resulall as $list) {
                                     $t++;
                                 }
                                 $fechafinal = '';
                                 $fechainicial = '';
                                 $exp_fechas = explode("-", $fechasExtremas);
                                 if (!empty($exp_fechas[1])) {
                                     $fechafinal = trim($exp_fechas[1]);
                                 }
                                 if (!empty($exp_fechas[0])) {
                                     $fechainicial = trim($exp_fechas[0]);
                                 }
                                 if ($t > 0) {
                                     $msg = "<font color='red'>Error! existe otro nombre duplicado</font>";
                                     unlink($Dir);
                                     $this->index($msg);
                                     exit;
                                 }
                                 $expediente = new expediente();
                                 $hoy = date("Y-m-d");
                                 $this->expediente = new tab_expediente();
                                 //        $this->expediente->setRequest2Object($_REQUEST);
                                 $this->expediente->setExp_id('');
                                 $this->expediente->setSer_id($id_serie);
                                 // Generation code
                                 $this->expediente->setExp_codigo($expediente->generaCodigo($id_serie));
                                 $this->expediente->setExp_lugar($ubicacion);
                                 $this->expediente->setSof_id(1);
                                 $this->expediente->setExp_ori(0);
                                 $this->expediente->setExp_cop(0);
                                 $this->expediente->setExp_fot(0);
                                 $this->expediente->setExp_obs('');
                                 $this->expediente->setExp_corr('AUTO');
                                 $this->expediente->setExp_estado(1);
                                 $this->expediente->setExp_migrarexcel(1);
                                 $exp_id = $this->expediente->insert2();
                                 // Update count
                                 //        if ($_REQUEST['ser_corr'] == 'AUTO') {
                                 //            // Auto
                                 //            $tseries = new tab_series();
                                 //            $row2 = $tseries->dbselectByField("ser_id", $_REQUEST['ser_id']);
                                 //            $row2 = $row2[0];
                                 //            $tseries->setSer_id($_REQUEST['ser_id']);
                                 //            $ser_exp = $row2->ser_exp + 1;
                                 //            $tseries->setSer_exp($ser_exp);
                                 //            $tseries->update();
                                 //        } else {
                                 //            // Manual
                                 //            $tseries = new tab_series();
                                 //            $tseries->setSer_id($_REQUEST['ser_id']);
                                 //            $tseries->setSer_exp($_REQUEST['exp_codigo']);
                                 //            $tseries->update();
                                 //        }
                                 //$this->expisadg->setTrm_id(1);
                                 //        $expisadg = new tab_expisadg();
                                 //        $expisadg->setExp_id($exp_id);
                                 //        $expisadg->setExp_titulo($expediente);
                                 //        $expisadg->setExp_nomprod($fondo);
                                 //        $expisadg->setExp_fecha_exi(date('Y-m-d'));
                                 //        $expisadg->setExp_fecha_exf(date('Y-m-d'));
                                 //        $expisadg->setExp_anioi($fechainicial);
                                 //        $expisadg->setExp_aniof($fechafinal);
                                 //        $expisadg->setIdi_id(1);
                                 //        $expisadg->setExp_estado(1);
                                 //        $eig_id = $expisadg->insert();
                                 $fechahoy = date('Y-m-d');
                                 $expisadg = new tab_expisadg();
                                 $expisadg->setExp_id($exp_id);
                                 $expisadg->setExp_titulo($tituloexpediente);
                                 $expisadg->setExp_fecha_exi($fechahoy);
                                 //        $expisadg->setExp_mesi('');
                                 $expisadg->setExp_anioi($fechainicial);
                                 $expisadg->setExp_fecha_exf($fechahoy);
                                 //        $expisadg->setExp_mesf('');
                                 $expisadg->setExp_aniof($fechafinal);
                                 $expisadg->setExp_nivdes('EXPEDIENTE');
                                 //        $expisadg->setExp_volsop('');
                                 $expisadg->setExp_nomprod($fondo);
                                 //        $expisadg->setExp_hisins('');
                                 //        $expisadg->setExp_hisarc('');
                                 $expisadg->setExp_foring('TRANSFERENCIA');
                                 //        $expisadg->setExp_alccon('');
                                 //        $expisadg->setExp_vaseel('');
                                 //        $expisadg->setExp_nueing('');
                                 $expisadg->setExp_org('LOS DOCUMENTOS DEL PROYECTO FUERON IDENTIFICADOS, CLASIFICADOS Y ORDENADOS EN LAS CAJAS DE ACUERDO AL CHECK LIST DE LA SERIE A LA QUE CORRESPONDEN.');
                                 $expisadg->setExp_conacc('EL ACCESO ESTA SUJETO A LO QUE ESTABLECE LA CONSTITUCION POLITICA DEL ESTADO Y EL ARTICULO 18 DE LA LEY 2341 SOBRE PROCESOS ADMINISTRATIVOS.');
                                 //        $expisadg->setExp_conrep('');
                                 $expisadg->setIdi_id(1);
                                 $expisadg->setExp_carfis('BUENO');
                                 //        $expisadg->setExp_insdes('');
                                 //        $expisadg->setExp_exloor('');
                                 //        $expisadg->setExp_exloco('');
                                 //        $expisadg->setExp_underel('');
                                 //        $expisadg->setExp_notpub('');
                                 //        $expisadg->setExp_notas('');
                                 //        $expisadg->setExp_notarc('');
                                 $expisadg->setExp_regnor('ISAD-G, ISAAR(CPF), RCAA');
                                 $expisadg->setExp_fecdes(date('Y-m-d'));
                                 $expisadg->setExp_estado(1);
                                 $eig_id = $expisadg->insert();
                                 // Save expfondo data
                                 $texf = new Tab_expfondo();
                                 $texf->setExp_id($exp_id);
                                 $usuario = new usuario();
                                 $fon_id = $usuario->getFon_id($_SESSION['USU_ID']);
                                 $nomUsuario = $usuario->obtenerNombre($_SESSION['USU_ID']);
                                 $texf->setExf_fecha_exi($fechahoy);
                                 $texf->setFon_id($fon_id);
                                 $texf->setExf_estado('1');
                                 $texf->insert();
                                 // Save expusuario data
                                 $this->expusuario = new expusuario();
                                 $this->expusuario->saveExp($exp_id, $_SESSION['USU_ID']);
                                 //        // Save expcontenedor data
                                 //        $con = new expcontenedor();
                                 //        $con->saveExpCont($_REQUEST['con_id'], $_REQUEST['suc_id'], $exp_id);
                                 //        // Save proyecto list data (tramos)
                                 //        if (isset($_REQUEST['lista_tramo'])) {
                                 //            $proyectos = $_REQUEST['lista_tramo'];
                                 //            foreach ($proyectos as $proyecto) {
                                 //                $exp = new tab_expproyecto();
                                 //                $exp->setExp_id($exp_id);
                                 //                $exp->setPry_id($proyecto);
                                 //                $exp->setEpp_estado(1);
                                 //                $exp->insert();
                                 //            }
                                 //        }
                                 // Save data dynamic
                                 $c = 0;
                                 $caj = "";
                                 $cnt = 0;
                                 //        insert usuario serie
                                 $tab_usu_serie = new Tab_usu_serie();
                                 $sqlususerie = "select* from tab_usu_serie\r\n            where usu_id='" . $_SESSION['USU_ID'] . "'\r\n            and ser_id='" . $id_serie . "'\r\n            and use_estado=1";
                                 $comprobar_usu_serie = $tab_usu_serie->dbSelectBySQL($sqlususerie);
                                 $cnt = count($comprobar_usu_serie);
                                 if ($cnt == 0) {
                                     $tab_usu_serie->setUse_id('');
                                     $tab_usu_serie->setUsu_id($_SESSION['USU_ID']);
                                     $tab_usu_serie->setSer_id($id_serie);
                                     $tab_usu_serie->setUse_estado(1);
                                     $tab_usu_serie->insert();
                                 }
                                 $y = 1;
                                 while ($i <= $cantidaddoc) {
                                     $caja = $objPHPExcel->getActiveSheet()->getCell("A" . $ct)->getValue();
                                     $filnroejem = $objPHPExcel->getActiveSheet()->getCell("C" . $ct)->getValue();
                                     $correlativo = $objPHPExcel->getActiveSheet()->getCell("E" . $ct)->getValue();
                                     $titledoc = $objPHPExcel->getActiveSheet()->getCell("F" . $ct)->getValue();
                                     $subtitledoc = $objPHPExcel->getActiveSheet()->getCell("G" . $ct)->getValue();
                                     //     $productor=$objPHPExcel->getActiveSheet()->getCell("H".$ct)->getValue();
                                     //     $contrato=$objPHPExcel->getActiveSheet()->getCell("I".$ct)->getValue();
                                     $fecha = trim($objPHPExcel->getActiveSheet()->getCell("H" . $ct)->getValue());
                                     $tomovol = $objPHPExcel->getActiveSheet()->getCell("I" . $ct)->getValue();
                                     $sopfis = $objPHPExcel->getActiveSheet()->getCell("J" . $ct)->getValue();
                                     $sala = $objPHPExcel->getActiveSheet()->getCell("K" . $ct)->getValue();
                                     $estante = $objPHPExcel->getActiveSheet()->getCell("L" . $ct)->getValue();
                                     $cuerpo = $objPHPExcel->getActiveSheet()->getCell("M" . $ct)->getValue();
                                     $balda = $objPHPExcel->getActiveSheet()->getCell("N" . $ct)->getValue();
                                     $obs = $objPHPExcel->getActiveSheet()->getCell("O" . $ct)->getValue();
                                     //todavia en trabajo
                                     if ($titledoc != "") {
                                         $vector[$i] = $titledoc;
                                         if ($i > 1) {
                                             if ($vector[$i - 1] == $titledoc) {
                                                 $y++;
                                             } else {
                                                 $y = 1;
                                             }
                                         }
                                         if ($y > 1) {
                                             $titledoc = "{$titledoc} Nro" . $y;
                                         }
                                         //
                                         //$msg= $caja."<br>";
                                         //$msg= $filnroejem."<br>";
                                         //$msg= $correlativo."<br>";
                                         //$msg= $titledoc."<br>";
                                         //$msg= $subtitledoc."<br>";
                                         //
                                         //$msg= $fecha."<br>";
                                         //$msg= $tomovol."<br>";
                                         //$msg= $sopfis."<br>";
                                         //$msg= $sala."<br>";
                                         //$msg= $estante."<br>";
                                         //$msg= $cuerpo."<br>";
                                         //$msg= $balda."<br>";
                                         //$msg= $obs."<br>";
                                         //exit();
                                         if ($fecha != "s/f") {
                                             $extfe = explode("\n", $fecha);
                                             $cantidadfecha = count($extfe);
                                             if ($cantidadfecha > 1) {
                                                 $fechadocAnioInicial = $extfe[0];
                                                 $fechadocMesInicial = $extfe[1];
                                             } else {
                                                 $fechadocAnioInicial = $extfe[0];
                                                 $fechadocMesInicial = "";
                                                 if ($fechadocAnioInicial > 30000) {
                                                     $fe = date("m-y", (int) $fechadocAnioInicial);
                                                     $extraer = explode("-", $fe);
                                                     $fechadocAnioInicial = $extraer[1];
                                                     $fechadocMesInicial = $extraer[0];
                                                 }
                                             }
                                         }
                                         // exit();
                                         if ($caja == "") {
                                         } else {
                                             $extraercaj = explode(" ", trim($caja));
                                             $caj = $extraercaj[1];
                                         }
                                         $id_exp = $exp_id;
                                         $this->archivo = new tab_archivo();
                                         $this->archivo->setFil_id('');
                                         // Generation code max fil_nro
                                         $maxFil = new Tab_archivo();
                                         $sql2 = "SELECT\r\n                    MAX(tab_archivo.fil_nro) AS maxnro\r\n                    FROM\r\n                    tab_expediente\r\n                    INNER JOIN tab_exparchivo ON tab_exparchivo.exp_id = tab_expediente.exp_id\r\n                    INNER JOIN tab_archivo ON tab_archivo.fil_id = tab_exparchivo.fil_id\r\n                    WHERE\r\n                    tab_expediente.exp_id = {$id_exp} AND\r\n                    tab_expediente.exp_estado = 1";
                                         $cant_max = $maxFil->dbSelectBySQL($sql2);
                                         foreach ($cant_max as $lismax) {
                                             $max3 = $lismax->maxnro;
                                         }
                                         if ($max3 == "") {
                                             $max3 = 0;
                                         }
                                         $max3 = $max3 + 1;
                                         //        $titledoc="$titledoc Nro ".$i;
                                         $this->archivo->setFil_nro($max3);
                                         $this->archivo->setFil_titulo(strtoupper($titledoc));
                                         $this->archivo->setFil_subtitulo(strtoupper($subtitledoc));
                                         $this->archivo->setFil_fecha($fechahoy);
                                         $this->archivo->setIdi_id(1);
                                         $this->archivo->setFil_proc($fondo);
                                         $this->archivo->setFil_firma($nomUsuario);
                                         $this->archivo->setFil_cargo('');
                                         $this->archivo->setFil_alccon('');
                                         $sqlsopfis = new tab_sopfisico();
                                         if ($sopfis != "AP" || $sopfis != "EM" || $sopfis != "LG" || $sopfis != "AN" || $sopfis != "MM" || $sopfis != "CP") {
                                             $sopfis = "LG";
                                         }
                                         $result = $sqlsopfis->dbselectByField("sof_codigo", $sopfis);
                                         $this->archivo->setSof_id($result[0]->sof_id);
                                         $this->archivo->setFil_nrofoj('');
                                         $this->archivo->setFil_codigo(2);
                                         $this->archivo->setFil_tomovol($tomovol);
                                         $this->archivo->setFil_nroejem($filnroejem);
                                         $this->archivo->setFil_nrocaj($caj);
                                         $this->archivo->setFil_nropaq('');
                                         $this->archivo->setFil_sala(strtoupper($sala));
                                         $this->archivo->setFil_estante(strtoupper($estante));
                                         $this->archivo->setFil_cuerpo(strtoupper($cuerpo));
                                         $this->archivo->setFil_balda(strtoupper($balda));
                                         $this->archivo->setFil_tipoarch('TEC');
                                         $this->archivo->setFil_mrb('BUENO');
                                         $this->archivo->setFil_mes($fechadocMesInicial);
                                         $this->archivo->setFil_anio($fechadocAnioInicial);
                                         $this->archivo->setFil_cantpaq('');
                                         $this->archivo->setFil_cantcaj('');
                                         $this->archivo->setFil_confidencialidad(1);
                                         $this->archivo->setFil_obs(strtoupper($obs));
                                         $this->archivo->setFil_estado('1');
                                         $fil_id = $this->archivo->insert();
                                         $this->archivo2 = new tab_archivo();
                                         $this->archivo2->setFil_id($fil_id);
                                         $this->archivo2->setFil_codigo($fil_id);
                                         $this->archivo2->setFil_estado('1');
                                         $this->archivo2->update();
                                         $this->exparchivo = new tab_exparchivo();
                                         $this->exparchivo->setExa_id('');
                                         $this->exparchivo->setFil_id($fil_id);
                                         $this->exparchivo->setExp_id($exp_id);
                                         $archivo_digital = new tab_archivo_digital();
                                         $archivo_digital->setFid_id('');
                                         $archivo_digital->setFil_id($fil_id);
                                         $archivo_digital->insert();
                                         $seriet = new Tab_serietramite();
                                         $this->series = new series();
                                         $ser_codigo = $this->series->obtenerCodigoSerie($id_serie);
                                         //insert grupos documentales y tipos documentales
                                         $this->tramite = new tab_tramite();
                                         $tramitecc = new tab_tramitecuerpos();
                                         $sqltramite = "SELECT\r\n        tab_tramite.tra_descripcion,\r\n        tab_tramite.tra_id\r\n        FROM\r\n        tab_series\r\n        INNER JOIN tab_serietramite ON tab_series.ser_id = tab_serietramite.ser_id\r\n        INNER JOIN tab_tramite ON tab_tramite.tra_id = tab_serietramite.tra_id\r\n        WHERE\r\n        tab_series.ser_id = {$id_serie}";
                                         $rows = $seriet->dbSelectBySQL($sqltramite);
                                         $v = 0;
                                         foreach ($rows as $row) {
                                             if ($row->tra_descripcion == 'GRUPO DOCUMENTAL COMPUESTA') {
                                                 $v++;
                                                 $tra_id = $row->tra_id;
                                                 $obtenerColumnCueId = $tramitecc->dbselectByField("tra_id", $tra_id);
                                                 $cue_id = $obtenerColumnCueId[0]->cue_id;
                                             }
                                         }
                                         if ($v == 0) {
                                             $this->tramite->setTra_orden(1);
                                             $this->tramite->setTra_codigo(1);
                                             $this->tramite->setTra_descripcion("GRUPO DOCUMENTAL COMPUESTA");
                                             $this->tramite->setTra_fecha_crea(date("Y-m-d"));
                                             $this->tramite->setTra_usuario_crea($_SESSION['USU_ID']);
                                             $this->tramite->setTra_estado(1);
                                             $tra_id = $this->tramite->insert();
                                             $seriet->setSer_id($id_serie);
                                             $seriet->setTra_id($tra_id);
                                             $seriet->setSts_fecha_crea(date("Y-m-d"));
                                             $seriet->setSts_fecha_reg(date("Y-m-d"));
                                             $seriet->setSts_usuario_crea($_SESSION['USU_ID']);
                                             $seriet->setSts_usu_reg($_SESSION['USU_ID']);
                                             $seriet->setVer_id('0');
                                             $seriet->setSts_estado(1);
                                             $seriet->insert();
                                             $this->tramite = new tramite();
                                             $tra_codigo = $this->tramite->obtenerCodigoTramite($tra_id);
                                             $tcuerpos = new tab_cuerpos();
                                             $tcuerpos->setCue_id('');
                                             $tcuerpos->setCue_orden(1);
                                             $tcuerpos->setCue_codigo(1);
                                             $tcuerpos->setCue_descripcion("UNIDAD DOCUMENTAL SIMPLE");
                                             $tcuerpos->setCue_fecha_crea(date("Y-m-d"));
                                             $tcuerpos->setCue_usuario_crea($_SESSION['USU_ID']);
                                             $tcuerpos->setCue_estado(1);
                                             $cue_id = $tcuerpos->insert();
                                             // Last code
                                             //$tramitecc = new tab_tramitecuerpos();
                                             $tramitecc->setCue_id($cue_id);
                                             $tramitecc->setTra_id($tra_id);
                                             $tramitecc->setTrc_estado(1);
                                             $tramitecc->insert();
                                         }
                                         //insert
                                         $this->exparchivo->setTra_id($tra_id);
                                         $this->exparchivo->setCue_id($cue_id);
                                         $this->exparchivo->setExa_condicion('1');
                                         $this->exparchivo->setExa_estado(1);
                                         $this->exparchivo->insert();
                                         //Fin del archivo
                                     }
                                     $i++;
                                     $ct++;
                                 }
                             } else {
                                 $msg = "<font color='red'>EL FORMATO CORRESPONDENCIA NO ES CORRECTO</font>";
                                 unlink($Dir);
                                 $this->index($msg);
                                 exit;
                             }
                             $msg .= "<b style='color:green'>SE GUARDO CORRECTAMENTE</b><br>";
                             $msg .= "<a href='" . PATH_DOMAIN . "/nuevoExpediente/index/'>Ver registro</a>";
                             unlink($Dir);
                             $this->index($msg);
                             exit;
                         } else {
                             $msg = "<font color='red'>EL FORMATO CORRESPONDENCIA NO ES CORRECTO</font>";
                             unlink($Dir);
                             $this->index($msg);
                         }
                     } else {
                         if ($tipoformato == 6) {
                             //CONTABILIDAD
                             $cantidaddoc = $highestRow - 30;
                             $fondo = $objPHPExcel->getActiveSheet()->getCell("E8")->getValue();
                             $subfondo = $objPHPExcel->getActiveSheet()->getCell("E9")->getValue();
                             $seccion = $objPHPExcel->getActiveSheet()->getCell("E10")->getValue();
                             $subseccion = $objPHPExcel->getActiveSheet()->getCell("E11")->getValue();
                             $serie = $objPHPExcel->getActiveSheet()->getCell("E12")->getValue();
                             $tituloexpediente = $objPHPExcel->getActiveSheet()->getCell("E13")->getValue();
                             $fechasExtremas = $objPHPExcel->getActiveSheet()->getCell("N12")->getValue();
                             $ml = $objPHPExcel->getActiveSheet()->getCell("D15")->getValue();
                             $objHoja = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
                             $objWorksheet = $objPHPExcel->getActiveSheet();
                             $tituloserie = explode("\n", $serie);
                             $cantidaserie = count($tituloserie);
                             if ($cantidaserie > 1) {
                                 $msg = "<font color='red'>Error, Elimine los saltos de linea del T&iacute;tulo de la Serie</font><br>";
                                 unlink($Dir);
                                 $this->index($msg);
                                 exit;
                             }
                             $tituloexp = explode("\n", $tituloexpediente);
                             $cantidaexpediente = count($tituloexp);
                             if ($cantidaexpediente > 1) {
                                 $msg = "<font color='red'>Error, Elimine los saltos de linea en T&iacute;tulo de Expediente </font><br>";
                                 unlink($Dir);
                                 $this->index($msg);
                                 exit;
                             }
                             //$msg= $fondo."<br>";
                             //$msg= $subfondo."<br>";
                             //$msg= $seccion."<br>";
                             //$msg= $subseccion."<br>";
                             //$msg= $serie."<br>";
                             //$msg= $tituloexpediente."<br>";
                             //$msg= $fechasExtremas."<br>";
                             //$msg= $ml."<br>";
                             //exit();
                             //$msg= '<table border="1">' . "\n";
                             //foreach ($objWorksheet->getRowIterator() as $row) {
                             //$msg= '<tr>' . "\n";
                             //
                             //$cellIterator = $row->getCellIterator();
                             //$cellIterator->setIterateOnlyExistingCells(false);
                             //foreach ($cellIterator as $cell) {
                             //$msg= '<td>' . htmlentities($cell->getValue(), ENT_IGNORE, 'utf-8') . '</td>' . "\n";
                             //}
                             //$msg= '</tr>' . "\n";
                             //}
                             //$msg= '</table>' . "\n";
                             //$msg= "la cantidad es:"; exit();
                             if ($highestColumn != "O") {
                                 $msg = "<font color='red'>EL FORMATO DE CONTABILIDAD NO ES CORRECTO!</font>";
                                 unlink($Dir);
                                 $this->index($msg);
                                 exit;
                             }
                             //15-1-17
                             $tab_fondo = new Tab_fondo();
                             $tab_unidad = new Tab_unidad();
                             $tab_series = new Tab_series();
                             //obtener fondo y subfondo
                             $sql = "select* from tab_fondo where fon_descripcion LIKE '%{$fondo}%'";
                             $sql2 = "select* from tab_fondo where fon_descripcion LIKE '%{$subfondo}%'";
                             $resultado = $tab_fondo->dbSelectBySQL($sql);
                             $resultado2 = $tab_fondo->dbSelectBySQL($sql2);
                             $id_fondo = $resultado[0]->fon_id;
                             $id_subfondo = $resultado2[0]->fon_id;
                             $ubicacion = $resultado2[0]->fon_codigo;
                             switch ($ubicacion) {
                                 case "ON":
                                     $ubicacion = "LA PAZ";
                                     break;
                                 case "LP":
                                     $ubicacion = "LA PAZ";
                                     break;
                                 case "SC":
                                     $ubicacion = "SANTA CRUZ";
                                     break;
                                 case "PT":
                                     $ubicacion = "POTOSI";
                                     break;
                                 case "BN":
                                     $ubicacion = "BENI";
                                     break;
                                 case "PN":
                                     $ubicacion = "PANDO";
                                     break;
                                 case "CB":
                                     $ubicacion = "COCHABAMBA";
                                     break;
                                 case "OR":
                                     $ubicacion = "ORURO";
                                     break;
                                 case "CH":
                                     $ubicacion = "CHUQUISACA";
                                     break;
                                 case "TJ":
                                     $ubicacion = "TARIJA";
                                     break;
                             }
                             if ($seccion == "DIRECCION GENERAL TECNICA") {
                                 if ($id_subfondo == 3) {
                                     $seccion = "TECNICA-OPERATIVA";
                                 } else {
                                     $seccion = "AREA TECNICA";
                                 }
                             }
                             //obtener el fon_id
                             $subseccion = trim($subseccion);
                             if ($subseccion == "") {
                                 $sql3 = "SELECT\r\ntab_unidad.uni_id,\r\nf.fon_id,\r\ntab_unidad.uni_descripcion\r\nFROM tab_fondo as f\r\nINNER JOIN tab_unidad ON f.fon_id = tab_unidad.fon_id\r\nWHERE\r\nf.fon_id = {$id_subfondo} and tab_unidad.uni_descripcion LIKE'%{$seccion}%'";
                             } else {
                                 $sql3 = "SELECT\r\ntab_unidad.uni_id,\r\nf.fon_id,\r\ntab_unidad.uni_descripcion\r\nFROM tab_fondo as f\r\nINNER JOIN tab_unidad ON f.fon_id = tab_unidad.fon_id\r\nWHERE\r\nf.fon_id = {$id_subfondo} and tab_unidad.uni_descripcion LIKE'%{$subseccion}%'";
                             }
                             $resultado3 = $tab_unidad->dbSelectBySQL($sql3);
                             foreach ($resultado3 as $rowseccion) {
                                 $id_seccion = $rowseccion->uni_id;
                             }
                             //obtengo la serie
                             $sql4 = "SELECT\r\ntab_series.ser_categoria,\r\ntab_series.ser_id\r\nFROM\r\ntab_fondo\r\nINNER JOIN tab_unidad ON tab_fondo.fon_id = tab_unidad.fon_id\r\nINNER JOIN tab_series ON tab_unidad.uni_id = tab_series.uni_id\r\nWHERE\r\ntab_fondo.fon_id = {$id_subfondo} AND (tab_series.ser_categoria LIKE '%{$serie}%' or tab_series.ser_categoria LIKE '{$serie}%' )";
                             $resultado4 = $tab_series->dbSelectBySQL($sql4);
                             foreach ($resultado4 as $rowserie) {
                                 $id_serie = $rowserie->ser_id;
                             }
                             if ($id_serie == "") {
                                 $msg = "<font color='red'>Error, No existe la Serie Asignada</font><br>";
                                 unlink($Dir);
                                 $this->index($msg);
                                 exit;
                             } else {
                                 if ($id_subfondo == "") {
                                     $msg = "<font color='red'>Error, No existe el Subfondo</font><br>";
                                     unlink($Dir);
                                     $this->index($msg);
                                     exit;
                                 } else {
                                     if ($id_seccion == "") {
                                         $msg = "<font color='red'>Error, No existe la Secci&oacute;n</font><br>";
                                         unlink($Dir);
                                         $this->index($msg);
                                         exit;
                                     }
                                 }
                             }
                             //$msg= $id_seccion."<br>";
                             //$msg= $id_subfondo."<br>";
                             //$msg= $id_serie."<br>";
                             //exit();
                             if ($highestColumn == "O") {
                                 if ($ml == "ML") {
                                     $i = 1;
                                     $ct = 17;
                                     $t = 0;
                                     $expsadg = new Tab_expisadg();
                                     $resulall = $expsadg->dbselectByField("exp_titulo", strtoupper($tituloexpediente));
                                     foreach ($resulall as $list) {
                                         $t++;
                                     }
                                     $fechafinal = '';
                                     $fechainicial = '';
                                     $exp_fechas = explode("-", $fechasExtremas);
                                     if (!empty($exp_fechas[1])) {
                                         $fechafinal = trim($exp_fechas[1]);
                                     }
                                     if (!empty($exp_fechas[0])) {
                                         $fechainicial = trim($exp_fechas[0]);
                                     }
                                     if ($t > 0) {
                                         $msg = "<font color='red'>Error! existe otro nombre duplicado</font>";
                                         unlink($Dir);
                                         $this->index($msg);
                                         exit;
                                     }
                                     $expediente = new expediente();
                                     $hoy = date("Y-m-d");
                                     $this->expediente = new tab_expediente();
                                     //        $this->expediente->setRequest2Object($_REQUEST);
                                     $this->expediente->setExp_id('');
                                     $this->expediente->setSer_id($id_serie);
                                     // Generation code
                                     $this->expediente->setExp_codigo($expediente->generaCodigo($id_serie));
                                     $this->expediente->setExp_lugar($ubicacion);
                                     $this->expediente->setSof_id(1);
                                     $this->expediente->setExp_ori(0);
                                     $this->expediente->setExp_cop(0);
                                     $this->expediente->setExp_fot(0);
                                     $this->expediente->setExp_obs('');
                                     $this->expediente->setExp_corr('AUTO');
                                     $this->expediente->setExp_estado(1);
                                     $this->expediente->setExp_migrarexcel(1);
                                     $exp_id = $this->expediente->insert2();
                                     // Update count
                                     //        if ($_REQUEST['ser_corr'] == 'AUTO') {
                                     //            // Auto
                                     //            $tseries = new tab_series();
                                     //            $row2 = $tseries->dbselectByField("ser_id", $_REQUEST['ser_id']);
                                     //            $row2 = $row2[0];
                                     //            $tseries->setSer_id($_REQUEST['ser_id']);
                                     //            $ser_exp = $row2->ser_exp + 1;
                                     //            $tseries->setSer_exp($ser_exp);
                                     //            $tseries->update();
                                     //        } else {
                                     //            // Manual
                                     //            $tseries = new tab_series();
                                     //            $tseries->setSer_id($_REQUEST['ser_id']);
                                     //            $tseries->setSer_exp($_REQUEST['exp_codigo']);
                                     //            $tseries->update();
                                     //        }
                                     //$this->expisadg->setTrm_id(1);
                                     //        $expisadg = new tab_expisadg();
                                     //        $expisadg->setExp_id($exp_id);
                                     //        $expisadg->setExp_titulo($expediente);
                                     //        $expisadg->setExp_nomprod($fondo);
                                     //        $expisadg->setExp_fecha_exi(date('Y-m-d'));
                                     //        $expisadg->setExp_fecha_exf(date('Y-m-d'));
                                     //        $expisadg->setExp_anioi($fechainicial);
                                     //        $expisadg->setExp_aniof($fechafinal);
                                     //        $expisadg->setIdi_id(1);
                                     //        $expisadg->setExp_estado(1);
                                     //        $eig_id = $expisadg->insert();
                                     $fechahoy = date('Y-m-d');
                                     $expisadg = new tab_expisadg();
                                     $expisadg->setExp_id($exp_id);
                                     $expisadg->setExp_titulo($tituloexpediente);
                                     $expisadg->setExp_fecha_exi($fechahoy);
                                     //        $expisadg->setExp_mesi('');
                                     $expisadg->setExp_anioi($fechainicial);
                                     $expisadg->setExp_fecha_exf($fechahoy);
                                     //        $expisadg->setExp_mesf('');
                                     $expisadg->setExp_aniof($fechafinal);
                                     $expisadg->setExp_nivdes('EXPEDIENTE');
                                     //        $expisadg->setExp_volsop('');
                                     $expisadg->setExp_nomprod($fondo);
                                     //        $expisadg->setExp_hisins('');
                                     //        $expisadg->setExp_hisarc('');
                                     $expisadg->setExp_foring('TRANSFERENCIA');
                                     //        $expisadg->setExp_alccon('');
                                     //        $expisadg->setExp_vaseel('');
                                     //        $expisadg->setExp_nueing('');
                                     $expisadg->setExp_org('LOS DOCUMENTOS DEL PROYECTO FUERON IDENTIFICADOS, CLASIFICADOS Y ORDENADOS EN LAS CAJAS DE ACUERDO AL CHECK LIST DE LA SERIE A LA QUE CORRESPONDEN.');
                                     $expisadg->setExp_conacc('EL ACCESO ESTA SUJETO A LO QUE ESTABLECE LA CONSTITUCION POLITICA DEL ESTADO Y EL ARTICULO 18 DE LA LEY 2341 SOBRE PROCESOS ADMINISTRATIVOS.');
                                     //        $expisadg->setExp_conrep('');
                                     $expisadg->setIdi_id(1);
                                     $expisadg->setExp_carfis('BUENO');
                                     //        $expisadg->setExp_insdes('');
                                     //        $expisadg->setExp_exloor('');
                                     //        $expisadg->setExp_exloco('');
                                     //        $expisadg->setExp_underel('');
                                     //        $expisadg->setExp_notpub('');
                                     //        $expisadg->setExp_notas('');
                                     //        $expisadg->setExp_notarc('');
                                     $expisadg->setExp_regnor('ISAD-G, ISAAR(CPF), RCAA');
                                     $expisadg->setExp_fecdes(date('Y-m-d'));
                                     $expisadg->setExp_estado(1);
                                     $eig_id = $expisadg->insert();
                                     // Save expfondo data
                                     $texf = new Tab_expfondo();
                                     $texf->setExp_id($exp_id);
                                     $usuario = new usuario();
                                     $fon_id = $usuario->getFon_id($_SESSION['USU_ID']);
                                     $nomUsuario = $usuario->obtenerNombre($_SESSION['USU_ID']);
                                     $texf->setExf_fecha_exi($fechahoy);
                                     $texf->setFon_id($fon_id);
                                     $texf->setExf_estado('1');
                                     $texf->insert();
                                     // Save expusuario data
                                     $this->expusuario = new expusuario();
                                     $this->expusuario->saveExp($exp_id, $_SESSION['USU_ID']);
                                     //        // Save expcontenedor data
                                     //        $con = new expcontenedor();
                                     //        $con->saveExpCont($_REQUEST['con_id'], $_REQUEST['suc_id'], $exp_id);
                                     //        // Save proyecto list data (tramos)
                                     //        if (isset($_REQUEST['lista_tramo'])) {
                                     //            $proyectos = $_REQUEST['lista_tramo'];
                                     //            foreach ($proyectos as $proyecto) {
                                     //                $exp = new tab_expproyecto();
                                     //                $exp->setExp_id($exp_id);
                                     //                $exp->setPry_id($proyecto);
                                     //                $exp->setEpp_estado(1);
                                     //                $exp->insert();
                                     //            }
                                     //        }
                                     // Save data dynamic
                                     $c = 0;
                                     $caj = "";
                                     $cnt = 0;
                                     //        insert usuario serie
                                     $tab_usu_serie = new Tab_usu_serie();
                                     $sqlususerie = "select* from tab_usu_serie\r\n            where usu_id='" . $_SESSION['USU_ID'] . "'\r\n            and ser_id='" . $id_serie . "'\r\n            and use_estado=1";
                                     $comprobar_usu_serie = $tab_usu_serie->dbSelectBySQL($sqlususerie);
                                     $cnt = count($comprobar_usu_serie);
                                     if ($cnt == 0) {
                                         $tab_usu_serie->setUse_id('');
                                         $tab_usu_serie->setUsu_id($_SESSION['USU_ID']);
                                         $tab_usu_serie->setSer_id($id_serie);
                                         $tab_usu_serie->setUse_estado(1);
                                         $tab_usu_serie->insert();
                                     }
                                     $y = 1;
                                     while ($i <= $cantidaddoc) {
                                         $caja = $objPHPExcel->getActiveSheet()->getCell("A" . $ct)->getValue();
                                         $filnroejem = $objPHPExcel->getActiveSheet()->getCell("C" . $ct)->getValue();
                                         $correlativo = $objPHPExcel->getActiveSheet()->getCell("E" . $ct)->getValue();
                                         $titledoc = $objPHPExcel->getActiveSheet()->getCell("F" . $ct)->getValue();
                                         $subtitledoc = $objPHPExcel->getActiveSheet()->getCell("G" . $ct)->getValue();
                                         //    $productor=$objPHPExcel->getActiveSheet()->getCell("H".$ct)->getValue();
                                         //    $contrato=$objPHPExcel->getActiveSheet()->getCell("I".$ct)->getValue();
                                         $fecha = trim($objPHPExcel->getActiveSheet()->getCell("H" . $ct)->getValue());
                                         $tomovol = $objPHPExcel->getActiveSheet()->getCell("I" . $ct)->getValue();
                                         $sopfis = $objPHPExcel->getActiveSheet()->getCell("J" . $ct)->getValue();
                                         $sala = $objPHPExcel->getActiveSheet()->getCell("K" . $ct)->getValue();
                                         $estante = $objPHPExcel->getActiveSheet()->getCell("L" . $ct)->getValue();
                                         $cuerpo = $objPHPExcel->getActiveSheet()->getCell("M" . $ct)->getValue();
                                         $balda = $objPHPExcel->getActiveSheet()->getCell("N" . $ct)->getValue();
                                         $obs = $objPHPExcel->getActiveSheet()->getCell("O" . $ct)->getValue();
                                         //todavia en trabajo
                                         if ($titledoc != "") {
                                             $vector[$i] = $titledoc;
                                             if ($i > 1) {
                                                 if ($vector[$i - 1] == $titledoc) {
                                                     $y++;
                                                 } else {
                                                     $y = 1;
                                                 }
                                             }
                                             if ($y > 1) {
                                                 $titledoc = "{$titledoc} Nro " . $y;
                                             }
                                             if ($fecha != "s/f") {
                                                 $extfe = explode("\n", $fecha);
                                                 $cantidadfecha = count($extfe);
                                                 if ($cantidadfecha > 1) {
                                                     $fechadocAnioInicial = $extfe[0];
                                                     $fechadocMesInicial = $extfe[1];
                                                 } else {
                                                     $fechadocAnioInicial = $extfe[0];
                                                     $fechadocMesInicial = "";
                                                     if ($fechadocAnioInicial > 30000) {
                                                         $fe = date("m-y", (int) $fechadocAnioInicial);
                                                         $extraer = explode("-", $fe);
                                                         $fechadocAnioInicial = $extraer[1];
                                                         $fechadocMesInicial = $extraer[0];
                                                     }
                                                 }
                                             }
                                             // exit();
                                             if ($caja == "") {
                                             } else {
                                                 $extraercaj = explode(" ", trim($caja));
                                                 $caj = $extraercaj[1];
                                             }
                                             $id_exp = $exp_id;
                                             $this->archivo = new tab_archivo();
                                             $this->archivo->setFil_id('');
                                             // Generation code max fil_nro
                                             $maxFil = new Tab_archivo();
                                             $sql2 = "SELECT\r\n                    MAX(tab_archivo.fil_nro) AS maxnro\r\n                    FROM\r\n                    tab_expediente\r\n                    INNER JOIN tab_exparchivo ON tab_exparchivo.exp_id = tab_expediente.exp_id\r\n                    INNER JOIN tab_archivo ON tab_archivo.fil_id = tab_exparchivo.fil_id\r\n                    WHERE\r\n                    tab_expediente.exp_id = {$id_exp} AND\r\n                    tab_expediente.exp_estado = 1";
                                             $cant_max = $maxFil->dbSelectBySQL($sql2);
                                             foreach ($cant_max as $lismax) {
                                                 $max3 = $lismax->maxnro;
                                             }
                                             if ($max3 == "") {
                                                 $max3 = 0;
                                             }
                                             $max3 = $max3 + 1;
                                             //        $titledoc="$titledoc Nro ".$i;
                                             $this->archivo->setFil_nro($max3);
                                             $this->archivo->setFil_titulo(strtoupper($titledoc));
                                             $this->archivo->setFil_codigo(2);
                                             $this->archivo->setFil_subtitulo(strtoupper($subtitledoc));
                                             $this->archivo->setFil_fecha($fechahoy);
                                             $this->archivo->setIdi_id(1);
                                             $this->archivo->setFil_proc($fondo);
                                             $this->archivo->setFil_firma($nomUsuario);
                                             $this->archivo->setFil_cargo('');
                                             $this->archivo->setFil_alccon('');
                                             $sqlsopfis = new tab_sopfisico();
                                             if ($sopfis != "AP" || $sopfis != "EM" || $sopfis != "LG" || $sopfis != "AN" || $sopfis != "MM" || $sopfis != "CP") {
                                                 $sopfis = "LG";
                                             }
                                             $result = $sqlsopfis->dbselectByField("sof_codigo", $sopfis);
                                             $this->archivo->setSof_id($result[0]->sof_id);
                                             $this->archivo->setFil_nrofoj('');
                                             $this->archivo->setFil_tomovol($tomovol);
                                             $this->archivo->setFil_nroejem($filnroejem);
                                             $this->archivo->setFil_nrocaj($caj);
                                             $this->archivo->setFil_nropaq('');
                                             $this->archivo->setFil_sala(strtoupper($sala));
                                             $this->archivo->setFil_estante(strtoupper($estante));
                                             $this->archivo->setFil_cuerpo(strtoupper($cuerpo));
                                             $this->archivo->setFil_balda(strtoupper($balda));
                                             $this->archivo->setFil_tipoarch('TEC');
                                             $this->archivo->setFil_mrb('BUENO');
                                             $this->archivo->setFil_mes($fechadocMesInicial);
                                             $this->archivo->setFil_anio($fechadocAnioInicial);
                                             $this->archivo->setFil_cantpaq('');
                                             $this->archivo->setFil_cantcaj('');
                                             $this->archivo->setFil_confidencialidad(1);
                                             $this->archivo->setFil_obs(strtoupper($obs));
                                             $this->archivo->setFil_estado('1');
                                             $fil_id = $this->archivo->insert();
                                             $this->archivo2 = new tab_archivo();
                                             $this->archivo2->setFil_id($fil_id);
                                             $this->archivo2->setFil_codigo($fil_id);
                                             $this->archivo2->setFil_estado('1');
                                             $this->archivo2->update();
                                             $this->exparchivo = new tab_exparchivo();
                                             $this->exparchivo->setExa_id('');
                                             $this->exparchivo->setFil_id($fil_id);
                                             $this->exparchivo->setExp_id($exp_id);
                                             $archivo_digital = new tab_archivo_digital();
                                             $archivo_digital->setFid_id('');
                                             $archivo_digital->setFil_id($fil_id);
                                             $archivo_digital->insert();
                                             $seriet = new Tab_serietramite();
                                             $this->series = new series();
                                             $ser_codigo = $this->series->obtenerCodigoSerie($id_serie);
                                             //insert grupos documentales y tipos documentales
                                             $this->tramite = new tab_tramite();
                                             $tramitecc = new tab_tramitecuerpos();
                                             $sqltramite = "SELECT\r\n        tab_tramite.tra_descripcion,\r\n        tab_tramite.tra_id\r\n        FROM\r\n        tab_series\r\n        INNER JOIN tab_serietramite ON tab_series.ser_id = tab_serietramite.ser_id\r\n        INNER JOIN tab_tramite ON tab_tramite.tra_id = tab_serietramite.tra_id\r\n        WHERE\r\n        tab_series.ser_id = {$id_serie}";
                                             $rows = $seriet->dbSelectBySQL($sqltramite);
                                             $v = 0;
                                             foreach ($rows as $row) {
                                                 if ($row->tra_descripcion == 'GRUPO DOCUMENTAL COMPUESTA') {
                                                     $v++;
                                                     $tra_id = $row->tra_id;
                                                     $obtenerColumnCueId = $tramitecc->dbselectByField("tra_id", $tra_id);
                                                     $cue_id = $obtenerColumnCueId[0]->cue_id;
                                                 }
                                             }
                                             if ($v == 0) {
                                                 $this->tramite->setTra_orden(1);
                                                 $this->tramite->setTra_codigo(1);
                                                 $this->tramite->setTra_descripcion("GRUPO DOCUMENTAL COMPUESTA");
                                                 $this->tramite->setTra_fecha_crea(date("Y-m-d"));
                                                 $this->tramite->setTra_usuario_crea($_SESSION['USU_ID']);
                                                 $this->tramite->setTra_estado(1);
                                                 $tra_id = $this->tramite->insert();
                                                 $seriet->setSer_id($id_serie);
                                                 $seriet->setTra_id($tra_id);
                                                 $seriet->setSts_fecha_crea(date("Y-m-d"));
                                                 $seriet->setSts_fecha_reg(date("Y-m-d"));
                                                 $seriet->setSts_usuario_crea($_SESSION['USU_ID']);
                                                 $seriet->setSts_usu_reg($_SESSION['USU_ID']);
                                                 $seriet->setVer_id('0');
                                                 $seriet->setSts_estado(1);
                                                 $seriet->insert();
                                                 $this->tramite = new tramite();
                                                 $tra_codigo = $this->tramite->obtenerCodigoTramite($tra_id);
                                                 $tcuerpos = new tab_cuerpos();
                                                 $tcuerpos->setCue_id('');
                                                 $tcuerpos->setCue_orden(1);
                                                 $tcuerpos->setCue_codigo(1);
                                                 $tcuerpos->setCue_descripcion("UNIDAD DOCUMENTAL SIMPLE");
                                                 $tcuerpos->setCue_fecha_crea(date("Y-m-d"));
                                                 $tcuerpos->setCue_usuario_crea($_SESSION['USU_ID']);
                                                 $tcuerpos->setCue_estado(1);
                                                 $cue_id = $tcuerpos->insert();
                                                 // Last code
                                                 //$tramitecc = new tab_tramitecuerpos();
                                                 $tramitecc->setCue_id($cue_id);
                                                 $tramitecc->setTra_id($tra_id);
                                                 $tramitecc->setTrc_estado(1);
                                                 $tramitecc->insert();
                                             }
                                             //insert
                                             $this->exparchivo->setTra_id($tra_id);
                                             $this->exparchivo->setCue_id($cue_id);
                                             $this->exparchivo->setExa_condicion('1');
                                             $this->exparchivo->setExa_estado(1);
                                             $this->exparchivo->insert();
                                             //Fin del archivo
                                         }
                                         $i++;
                                         $ct++;
                                     }
                                 } else {
                                     $msg = "<font color='red'>EL FORMATO DE CONTABILIDAD NO ES CORRECTO</font>";
                                     unlink($Dir);
                                     $this->index($msg);
                                     exit;
                                 }
                                 $msg .= "<b style='color:green'>SE GUARDO CORRECTAMENTE</b><br>";
                                 $msg .= "<a href='" . PATH_DOMAIN . "/nuevoExpediente/index/'>Ver registro</a>";
                                 unlink($Dir);
                                 $this->index($msg);
                                 exit;
                             } else {
                                 $msg = "<font color='red'>EL FORMATO DE CONTABILIDAD NO ES CORRECTO</font>";
                                 unlink($Dir);
                                 $this->index($msg);
                             }
                         }
                     }
                 }
             }
         }
     }
     //otro modelo
     //$objHoja=$objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
     //
     //foreach($objHoja as $iIndice=>$objCelda) {
     //$msg= $objCelda['A'].$objCelda['B'];
     //}
     //$objWorksheet = $objPHPExcel->getActiveSheet();
     //
     //$msg= '<table border="1">' . "\n";
     //foreach ($objWorksheet->getRowIterator() as $row) {
     //$msg= '<tr>' . "\n";
     //
     //$cellIterator = $row->getCellIterator();
     //$cellIterator->setIterateOnlyExistingCells(false); // This loops all cells,
     //foreach ($cellIterator as $cell) {
     //$msg= '<td>' . htmlentities($cell->getValue(), ENT_IGNORE, 'utf-8') . '</td>' . "\n";
     //}
     //
     //$msg= '</tr>' . "\n";
     //}
     //$msg= '</table>' . "\n";
     //foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
     //$worksheetTitle     = $worksheet->getTitle();
     //$highestRow         = $worksheet->getHighestRow(); // e.g. 10
     //$highestColumn      = $worksheet->getHighestColumn(); // e.g 'F'
     //$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
     //$nrColumns = ord($highestColumn) - 64;
     ////$msg= "<br>The worksheet ".$worksheetTitle." has ";
     ////$msg= $nrColumns . ' columns (A-' . $highestColumn . ') ';
     ////$msg= ' and ' . $highestRow . ' row.';
     //$msg= '<br><table border="1"><tr>';
     //for ($row = 1; $row <= $highestRow; ++ $row) {
     //$msg= '<tr>';
     //for ($col = 0; $col < $highestColumnIndex; ++ $col) {
     //$cell = $worksheet->getCellByColumnAndRow($col, $row);
     //$val = $cell->getValue();
     //$dataType = PHPExcel_Cell_DataType::dataTypeForValue($val);
     //$msg= '<td>' . $val . '</td>';
     //}
     //$msg= '</tr>';
     //}
     //$msg= '</table>';
     //}
     unlink($Dir);
     exit;
     //
     //if( !isset($_FILES['archivo']) ){
     //  $msg= 'Ha habido un error, tienes que elegir un archivo<br/>';
     //  $msg= '<a href="index.html">Subir archivo</a>';
     //}else{
     //
     //  $nombre = $_FILES['archivo']['name'];
     //  $nombre_tmp = $_FILES['archivo']['tmp_name'];
     //  $tipo = $_FILES['archivo']['type'];
     //  $tamano = $_FILES['archivo']['size'];
     //
     //  $ext_permitidas = array('xls','jpeg','xlsx','png');
     //  $partes_nombre = explode('.', $nombre);
     //  $extension = end( $partes_nombre );
     //  $ext_correcta = in_array($extension, $ext_permitidas);
     //
     //  $tipo_correcto = preg_match('/^image\/(pjpeg|jpeg|gif|png|xls|xlsx)$/', $tipo);
     //
     //  $limite = 500 * 1024;
     //
     //  if( $ext_correcta  && $tamano <= $limite ){
     //    if( $_FILES['archivo']['error'] > 0 ){
     //      $msg= 'Error: ' . $_FILES['archivo']['error'] . '<br/>';
     //    }else{
     //      $msg= 'Nombre: ' . $nombre . '<br/>';
     //      $msg= 'Tipo: ' . $tipo . '<br/>';
     //      $msg= 'Tama&ntilde;o: ' . ($tamano / 1024) . ' Kb<br/>';
     //      $msg= 'Guardado en: ' . $nombre_tmp;
     //
     //      $nombreDirectorio = "";
     //        $tsistema = new tab_sistema ();
     //        $sql = "SELECT *
     //                FROM tab_sistema";
     //        $rows2 = $tsistema->dbselectBySQL($sql);
     //        if (count($rows2) >= 1) {
     //            $sis_tipcarga = $rows2 [0]->sis_tipcarga;
     //            $sis_tammax = $rows2 [0]->sis_tammax;
     //            $nombreDirectorio = $rows2 [0]->sis_ruta;
     //        }
     //
     //      if( file_exists( 'subidas/'.$nombre) ){
     //        $msg= '<br/>El archivo ya existe: ' . $nombre;
     //      }else{
     //        move_uploaded_file($nombre_tmp,
     //          "subidas/" . $nombre);
     //
     //        $msg= "<br/>Guardado en: " . "subidas/" . $nombre;
     //      }
     //    }
     //  }else{
     //    $msg= 'Archivo inv&aacute;lido';
     //  }
     //}
     exit;
 }
 function view()
 {
     $exp_id = VAR3;
     $fil_id = VAR4;
     $this->archivo = new tab_archivo();
     $rows = $this->archivo->dbselectByField("fil_id", $fil_id);
     $row = $rows[0];
     // Tab_archivo
     // Tab_doccorr
     $tab_doccorr = new Tab_doccorr();
     $sql = "SELECT *\r\n                FROM tab_doccorr\r\n                WHERE fil_id='" . $row->fil_id . "'";
     $doccorr = $tab_doccorr->dbSelectBySQL($sql);
     if ($doccorr) {
         $doccorr = $doccorr[0];
         // Nur
         $hojas_ruta = new hojas_ruta();
         $this->registry->template->dco_id = $doccorr->dco_id;
         $this->registry->template->fil_cite = $hojas_ruta->obtenerSelect($doccorr->fil_cite);
         $seguimientos = new seguimientos();
         $this->registry->template->fil_nur_s = $seguimientos->obtenerSelect($doccorr->fil_nur_s);
         $this->registry->template->fil_nur = $doccorr->fil_nur;
         $this->registry->template->fil_asunto = $doccorr->fil_asunto;
         $this->registry->template->fil_sintesis = $doccorr->fil_sintesis;
         $this->registry->template->fil_nur_tipo = "";
     } else {
         // Nur
         $this->registry->template->dco_id = "";
         $this->registry->template->fil_cite = "";
         $this->registry->template->fil_nur_s = "";
         $this->registry->template->fil_nur = $_SESSION["codigo"];
         $this->registry->template->fil_asunto = "";
         $this->registry->template->fil_sintesis = "";
         $this->registry->template->fil_nur_tipo = "";
     }
     // Tab_exparchivo
     $sql = "SELECT *\r\n                FROM tab_exparchivo\r\n                WHERE fil_id='" . $row->fil_id . "'";
     $exa_rows = $this->archivo->dbSelectBySQL($sql);
     $exa_row = $exa_rows[0];
     $this->registry->template->exp_id = $exp_id;
     $this->registry->template->tra_id = $exa_row->tra_id;
     $this->registry->template->cue_id = $exa_row->cue_id;
     $this->registry->template->exa_id = $exa_row->exa_id;
     // Tab_archivo
     $this->registry->template->fil_id = $fil_id;
     $this->registry->template->fil_codigo = $row->fil_codigo;
     $expediente = new expediente();
     $this->registry->template->exp_codigo = $expediente->obtenerCodigo(VAR3);
     $this->registry->template->exp_nombre = "";
     $this->registry->template->exp_corr = $expediente->obtenerTipoCorrExpediente(VAR3);
     $this->registry->template->fil_nro = $row->fil_nro;
     $this->registry->template->fil_titulo = $row->fil_titulo;
     $this->registry->template->fil_subtitulo = $row->fil_subtitulo;
     $this->registry->template->fil_fecha = $row->fil_fecha;
     $this->registry->template->fil_mes = $expediente->obtenerSelectMes($row->fil_mes);
     $this->registry->template->fil_anio = $expediente->obtenerSelectAnio($row->fil_anio);
     $this->registry->template->fil_mesf = $expediente->obtenerSelectMes($row->fil_mesf);
     $this->registry->template->fil_aniof = $expediente->obtenerSelectAnio($row->fil_aniof);
     $idioma = new idioma();
     $this->registry->template->idi_id = $idioma->obtenerSelect($row->idi_id);
     $this->registry->template->fil_proc = $row->fil_proc;
     $this->registry->template->fil_firma = $row->fil_firma;
     $this->registry->template->fil_cargo = $row->fil_cargo;
     $this->registry->template->fil_alccon = $row->fil_alccon;
     // Find ser_id
     $texpediente = new tab_expediente();
     $tab_expediente = $texpediente->dbselectById(VAR3);
     $ser_id = $tab_expediente->getSer_id();
     // Include dynamic fields
     $expcampo = new expcampo();
     $this->registry->template->filcampo = $expcampo->obtenerSelectCampos($ser_id);
     $sopfisico = new sopfisico();
     $this->registry->template->sof_id = $sopfisico->obtenerSelect($row->sof_id);
     $this->registry->template->fil_nrofoj = $row->fil_nrofoj;
     $this->registry->template->fil_tomovol = $row->fil_tomovol;
     $this->registry->template->fil_nroejem = $row->fil_nroejem;
     $this->registry->template->fil_nrocaj = $row->fil_nrocaj;
     $this->registry->template->fil_nropaq = $row->fil_nropaq;
     $this->registry->template->fil_cantpaq = $row->fil_cantpaq;
     $this->registry->template->fil_cantcaj = $row->fil_cantcaj;
     $this->registry->template->fil_sala = $row->fil_sala;
     $archivo = new archivo();
     $this->registry->template->fil_estante = $archivo->obtenerSelectEstante($row->fil_estante);
     $this->registry->template->fil_cuerpo = $row->fil_cuerpo;
     $this->registry->template->fil_balda = $row->fil_balda;
     $this->registry->template->fil_tipoarch = $row->fil_tipoarch;
     $this->registry->template->fil_mrb = $row->fil_mrb;
     if ($row->fil_ori) {
         $this->registry->template->fil_ori = $row->fil_ori;
     } else {
         $this->registry->template->fil_ori = '0';
     }
     if ($row->fil_cop) {
         $this->registry->template->fil_cop = $row->fil_cop;
     } else {
         $this->registry->template->fil_cop = '0';
     }
     if ($row->fil_fot) {
         $this->registry->template->fil_fot = $row->fil_fot;
     } else {
         $this->registry->template->fil_fot = '0';
     }
     $this->registry->template->fil_confidencilidad = $row->fil_confidencialidad;
     $this->registry->template->fil_obs = $row->fil_obs;
     $this->registry->template->required_archivo = "";
     // Validate keywords
     $palclave = new palclave();
     $sis_palclave = $palclave->obtenerSisPalclave();
     if ($sis_palclave == "RECORDAR") {
         $this->registry->template->fil_descripcion = $palclave->listaPCFile($row->fil_id);
         $this->registry->template->pac_nombre = "";
     } else {
         $this->registry->template->fil_descripcion = "";
         $this->registry->template->pac_nombre = "";
     }
     $tab_serie = new tab_series();
     $row1 = $tab_serie->dbselectById($ser_id);
     $expisadg = new tab_expisadg();
     $row2 = $expisadg->dbselectById(VAR3);
     $expediente2 = new expediente();
     $this->registry->template->detExpediente = "";
     $this->registry->template->detExpediente = $expediente2->getDetalles(VAR3);
     $this->registry->template->ubicacion = $expediente2->getUbicacion(VAR3);
     $this->registry->template->ser_id = $row1->ser_id;
     $this->registry->template->serie = $row1->ser_categoria;
     $this->registry->template->exp_fecha_exi = $row2->exp_fecha_exi;
     $this->registry->template->exp_fecha_exf = $row2->exp_fecha_exf;
     if (VAR5) {
         if (VAR5 == 0) {
             $msm = "HUBO ERROR AL REGISTRAR EL DOCUMENTO!";
         } else {
             if (VAR5 == 1) {
                 $msm = "SE GUARDO CORRECTAMENTE EL DOCUMENTO!";
             } else {
                 $msm = "";
             }
         }
     } else {
         $msm = "";
     }
     $this->registry->template->msm = $msm;
     $exp = new expediente();
     $this->registry->template->linkTree = $exp->linkTree($exp_id, $exa_row->tra_id, $exa_row->cue_id);
     $arc = new archivo();
     $this->registry->template->confidencialidad = $arc->loadConfidencialidad('1');
     $this->registry->template->PATH_WEB = PATH_WEB;
     $this->registry->template->PATH_DOMAIN = PATH_DOMAIN;
     $this->registry->template->PATH_EVENT = "update";
     $this->registry->template->controller = VAR1;
     $this->registry->template->GRID_SW = "true";
     $this->registry->template->PATH_J = "jquery-1.4.1";
     $this->registry->template->tituloEstructura = "<div class='titulo' align='center'>ESTRUCTURA DOCUMENTAL</div>";
     $this->menu = new menu();
     $liMenu = $this->menu->imprimirMenu(VAR1, $_SESSION['USU_ID']);
     $this->registry->template->men_titulo = $liMenu;
     $this->registry->template->show('headerG');
     //        $this->registry->template->show('archivo/exp_detallesView.tpl');
     $this->registry->template->show('archivo/tab_archivo.tpl');
     $this->registry->template->show('footer');
 }