function verRpteExcel()
 {
     $id = VAR3;
     $where = "";
     $tab_extransferencia = new tab_exptransferencia();
     $result = $tab_extransferencia->dbSelectBySQL("select* from tab_exptransferencia where str_id={$id}");
     $cantidad = count($result);
     $valor3 = "";
     $t = 1;
     foreach ($result as $row) {
         $valor3 .= "tab_expediente.exp_id={$row->exp_id}";
         if ($t < $cantidad) {
             $valor3 .= " or ";
         }
         $t++;
     }
     $where .= " AND {$valor3} ";
     $sql = "SELECT\r\n            f.fon_codigo,\r\n            f.fon_cod,\r\n            (SELECT fon_codigo from tab_fondo WHERE fon_id=f.fon_par) ||'.'|| f.fon_codigo ||'.'||tab_unidad.uni_cod ||'.'|| tab_tipocorr.tco_codigo ||'.'||tab_series.ser_codigo||'.'||\r\n            tab_expediente.exp_codigo AS codigo,\r\n            (NULLIF(tab_expediente.exp_codigo,'')::int) as cantidad,\r\n            tab_soltransferencia.str_id,\r\n            tab_soltransferencia.str_fecha,\r\n            tab_soltransferencia.uni_id,\r\n            tab_soltransferencia.unid_id,\r\n            tab_soltransferencia.str_nrocajas,\r\n            tab_soltransferencia.str_totpzas,\r\n            tab_soltransferencia.str_totml,\r\n            tab_soltransferencia.str_nroreg,\r\n            tab_soltransferencia.str_fecini,\r\n            tab_soltransferencia.str_fecfin,\r\n            tab_soltransferencia.str_estado,\r\n            tab_soltransferencia.usu_id,\r\n            tab_soltransferencia.usud_id,\r\n            tab_soltransferencia.str_direccion,\r\n            tab_soltransferencia.str_telefono,\r\n            tab_expisadg.exp_fecha_exi,\r\n            tab_expisadg.exp_fecha_exf,\r\n            tab_expisadg.exp_anioi,\r\n            tab_expisadg.exp_aniof,\r\n            tab_expisadg.exp_titulo,\r\n            tab_series.ser_codigo,\r\n            tab_unidad.uni_codigo,\r\n            tab_unidad.uni_id,\r\n            tab_unidad.uni_par,\r\n            tab_unidad.uni_cod,\r\n            tab_unidad.uni_descripcion,\r\n            f.fon_cod,\r\n            tab_series.ser_categoria,\r\n            tab_expisadg.exp_titulo,\r\n            tab_expediente.exp_obs,\r\n            tab_series.ser_id,\r\n            tab_series.ser_par,\r\n            tab_expediente.exp_id\r\n            FROM\r\n            tab_unidad\r\n            INNER JOIN tab_fondo as f ON tab_unidad.fon_id = f.fon_id\r\n            INNER JOIN tab_series ON tab_series.uni_id = tab_unidad.uni_id\r\n            INNER JOIN tab_expediente ON tab_expediente.ser_id = tab_series.ser_id\r\n            INNER JOIN tab_expisadg ON tab_expisadg.exp_id = tab_expediente.exp_id\r\n            INNER JOIN tab_exptransferencia ON tab_expediente.exp_id = tab_exptransferencia.exp_id\r\n            INNER JOIN tab_soltransferencia ON tab_soltransferencia.str_id = tab_exptransferencia.str_id\r\n            INNER JOIN tab_tipocorr ON tab_tipocorr.tco_id = tab_series.tco_id\r\n            WHERE\r\n            tab_soltransferencia.str_estado = 2 AND\r\n            tab_expediente.exp_estado = 1 {$where} order by tab_expediente.exp_id ";
     $usua = new usuario();
     $subfondo = new fondo();
     $seccion = new unidad();
     $expedientes = new expediente();
     $archivo = new tab_archivo();
     $archivo2 = new tab_archivo();
     $query = $archivo->dbSelectBySQL($sql);
     $query2 = $archivo2->dbSelectBySQL($sql);
     foreach ($query2 as $ids) {
         $usu_id = $ids->usu_id;
         $uni_id = $ids->uni_id;
         $uni_par = $ids->uni_par;
         $uni_cod = $ids->uni_cod;
         $str_telefono = $ids->str_telefono;
         $str_id = $ids->str_id;
         $str_fecha = $ids->str_fecha;
         $str_direccion = $ids->str_direccion;
         $uni_descripcion = $ids->uni_descripcion;
     }
     $usuarioOrigen = $usua->obtenerNombre($usu_id);
     $usuarioDestino = $usua->obtenerNombre($usu_id);
     $fond = $subfondo->obtenerfon($usu_id);
     $ob_seccion = $seccion->obtenerSeccion($uni_id);
     $cadena = "";
     $cadena = "<br/><br/><br/><br/><br/><br/><br/>";
     $cadena .= '<table width="740" border="1">';
     $cadena .= '<tr>';
     $cadena .= '<td colspan="10" align="center" ><b>';
     $cadena .= 'FORMULARIO DE RELACION DE TRANSFERENCIAS</b><br /></td>';
     $cadena .= '</tr>';
     $cadena .= '<tr>';
     $cadena .= '<td colspan="9" align="right" style=border:none ><b>';
     $cadena .= 'Nº de transferencia:</b></td><td align="center">' . $str_id . '</td>';
     $cadena .= '</tr>';
     //    $cadena.='<tr>';
     //  $cadena.='<td colspan="10" align="right" ><b>';
     //  $cadena.='<b>Nº de transferencia:</b> '.$str_id.'</td>';
     //  $cadena.='</tr>';
     $cadena .= '<tr>';
     $cadena .= '<td colspan="5"><blockquote>';
     $cadena .= '<b>Subfondo:</b> ' . $fond . '<br />';
     $cadena .= '<b>Secci&oacute;n:</b> ';
     $explode = explode(".", $uni_cod);
     $contado = count($explode);
     $codigo = "";
     for ($t = 0; $t < $contado - 1; $t++) {
         $codigo .= $explode[$t];
         if ($t < $contado - 2) {
             $codigo .= ".";
         }
     }
     $codigo2 = $codigo;
     if (strlen($codigo) == 1) {
         $codigo = $codigo . ".0";
     } else {
         $estraer_codigo = explode(".", $codigo);
         $codigo = $estraer_codigo[0] . ".0";
     }
     $tab_unidad = new Tab_unidad();
     $unidad = new unidad();
     $sqlUni2 = "SELECT\r\n                    tab_unidad.uni_descripcion\r\n                    FROM\r\n                    tab_unidad\r\n                    WHERE\r\n                    tab_unidad.uni_cod = '{$codigo}'";
     $codigoss = explode(".", $codigo2);
     $cantcodigo2 = count($codigoss);
     if ($cantcodigo2 == 1) {
         $codigo2 = "{$codigo2}.1";
     }
     $sqlUni1 = "SELECT\r\n                    tab_unidad.uni_descripcion\r\n                    FROM\r\n                    tab_unidad\r\n                    WHERE\r\n                    tab_unidad.uni_cod = '{$codigo2}'";
     $resultadott = $tab_unidad->dbSelectBySQL($sqlUni2);
     $resultadott1 = $tab_unidad->dbSelectBySQL($sqlUni1);
     $ca1 = "";
     foreach ($resultadott1 as $rowss2) {
         $ca1 = $rowss2->uni_descripcion;
     }
     foreach ($resultadott as $rowss) {
         $ca = $rowss->uni_descripcion;
     }
     $variable = $ca;
     $excluirparent = explode("(", $variable);
     if ($excluirparent[1] == "") {
         $ca = $ca;
     } else {
         $excluirultimoparent = $excluirparent[1] . "x";
         $imprimir_descripcion = explode(")", $excluirultimoparent);
         $ca = $imprimir_descripcion[0];
     }
     $ca = $unidad->obtenerPadre($uni_par, $uni_descripcion);
     $cadena .= $ca;
     $cadena .= '<br><b>Subsecci&oacute;n:</b> ';
     $cadena .= $ca1;
     $cadena .= '</blockquote></td>';
     //$cadena.='<td colspan="5"  ><blockquote><b>Unidad:</b> '.$uni_descripcion;
     $cadena .= '<td colspan="5"  ><blockquote>';
     $cadena .= '<br /><b>Tel&eacute;fono:</b> ' . $str_telefono . '</blockquote></td>';
     $cadena .= '</tr>';
     $cadena .= '<tr>';
     $cadena .= '<td width="20" rowspan="2" align="center" bgcolor="#CCCCCC"><strong>Nº</strong></td>';
     $cadena .= '<td width="105" rowspan="2" style="text-align:center" bgcolor="#CCCCCC"><strong>Serie</strong></td>';
     $cadena .= '<td width="120" rowspan="2" style="text-align:center" bgcolor="#CCCCCC"><strong>Subserie</strong></td>';
     $cadena .= '<td width="125" rowspan="2" style="text-align:center" bgcolor="#CCCCCC"><strong>T&iacute;tulo del Expediente</strong></td>';
     $cadena .= '<td width="80" rowspan="2" style="text-align:center" bgcolor="#CCCCCC"><strong>C&oacute;digo de Referencia</strong></td>';
     $cadena .= '<td colspan="2" width="130" style="text-align:center" bgcolor="#CCCCCC"><strong>Fechas extremas</strong></td>';
     $cadena .= '<td width="30" rowspan="2" bgcolor="#CCCCCC" style="font-size:25px"><strong >NºDoc.</strong></td>';
     $cadena .= '<td width="30" rowspan="2" bgcolor="#CCCCCC"><strong>Cajas</strong></td>';
     $cadena .= '<td width="100" rowspan="2" style="text-align:center" bgcolor="#CCCCCC"><p><strong>Observ.</strong></p></td>';
     $cadena .= '</tr>';
     $cadena .= '<tr>';
     $cadena .= '<td width="65" style="text-align:center" bgcolor="#CCCCCC"><strong>Inicio</strong></td>';
     $cadena .= '<td width="65" style="text-align:center" bgcolor="#CCCCCC"><strong>Final</strong></td>';
     $cadena .= '</tr>';
     $sum = 0;
     $i = 1;
     $cant = 0;
     foreach ($query as $row) {
         $tabserie = new tab_series();
         if ($row->exp_fecha_exi == "") {
             $fei = "";
         } else {
             $fechainicial = explode("-", $row->exp_fecha_exi);
             $fei = $fechainicial[2] . "/" . $fechainicial[1] . "/" . $fechainicial[0];
         }
         if ($row->exp_fecha_exf == "") {
             $fef = "";
         } else {
             $fechafinal = explode("-", $row->exp_fecha_exf);
             $fef = $fechafinal[2] . "/" . $fechafinal[1] . "/" . $fechafinal[0];
         }
         $lugar = "";
         $cadena .= '<tr>';
         $cadena .= '<td align="center">' . $i . '</td>';
         $cadena .= '<td style="font-size:22px">';
         $tab_serie = new Tab_series();
         $lugar2 = "";
         if ($row->ser_par != -1) {
             $rowsdb = $tab_serie->dbselectByField("ser_id", $row->ser_par);
             foreach ($rowsdb as $fila) {
                 $ser_par = $fila->ser_par;
                 $ser_categoria = $fila->ser_categoria;
             }
             if ($ser_par != -1) {
                 $cadena .= $ser_categoria;
             } else {
                 $cadena .= $row->ser_categoria;
                 $lugar = $row->ser_categoria;
             }
         } else {
             $cadena .= $row->ser_categoria;
             $lugar2 = $row->ser_categoria;
         }
         $cadena .= '</td>';
         $cadena .= '<td style="font-size:22px">';
         if ($lugar2 != $row->ser_categoria && $row->ser_categoria != $lugar) {
             $cadena .= $row->ser_categoria;
         }
         $expsum = $expedientes->cantidadExpedientes($row->exp_id);
         //     $cajas=$expedientes->cantidadCajas($row->exp_id);
         $cant = $cant + $expsum;
         //     $sum=$sum+$cajas;
         $cadena .= '</td>';
         $cadena .= '<td align="left" style="font-size:22px">' . htmlentities($row->exp_titulo, ENT_COMPAT, 'utf-8') . '</td>';
         $cadena .= '<td align="center" style="font-size:22px">' . $row->codigo . '</td>';
         $cadena .= '<td align="center" style="font-size:22px">' . $row->exp_anioi . '</td>';
         $cadena .= '<td align="center"  style="font-size:22px">' . $row->exp_aniof . '</td>';
         $cadena .= '<td align="center" style="font-size:22px">' . $expsum . '</td>';
         $cadena .= '<td align="center"></td>';
         $cadena .= '<td style="font-size:22px">' . $row->exp_obs . '</td>';
         $cadena .= '</tr>';
         $i++;
     }
     $cadena .= '<tr>';
     $cadena .= '<td colspan="6" align="right" >TOTAL</td>';
     $cadena .= '<td align="center"></td>';
     $cadena .= '<td align="center">' . $cant . '</td>';
     $cadena .= '<td></td>';
     $cadena .= '<td>&nbsp;</td>';
     $cadena .= '</tr>';
     $cadena .= '</table>';
     $fecha = explode("-", $str_fecha);
     $anio = $fecha[0];
     $mes = $fecha[1];
     $dia = $fecha[2];
     switch ($mes) {
         case 1:
             $mes = "Enero";
             break;
         case 2:
             $mes = "Enero";
             break;
         case 3:
             $mes = "Enero";
             break;
         case 4:
             $mes = "Enero";
             break;
         case 5:
             $mes = "Enero";
             break;
         case 6:
             $mes = "Enero";
             break;
         case 7:
             $mes = "Enero";
             break;
         case 8:
             $mes = "Enero";
             break;
         case 9:
             $mes = "Enero";
             break;
         case 10:
             $mes = "Enero";
             break;
         case 11:
             $mes = "Enero";
             break;
         case 12:
             $mes = "Enero";
             break;
     }
     $cadena .= '<b>Lugar y fecha de la transferencia:</b> ' . $str_direccion . '  ' . $dia . ' de ' . $mes . ' de ' . $anio;
     $cadena .= '<br/>';
     require_once 'tcpdf/config/lang/eng.php';
     require_once 'tcpdf/tcpdf.php';
     $pdf = new TCPDF('L', PDF_UNIT, 'LETTER', true, 'UTF-8', false);
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->setFontSubsetting(FALSE);
     $pdf->SetAuthor("Castellon");
     $pdf->SetTitle('Reporte de Transferencia');
     $pdf->SetSubject('Reporte de Transferencia');
     //        aumentado
     $pdf->SetKeywords('Castellon, TEAM DIGITAL');
     // set default header data
     $pdf->SetHeaderData('logo2.png', 20, 'MPD', 'ADMINISTRADORA BOLIVIANA DE CARRETERAS (MPD)');
     // set header and footer fonts
     $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
     //        $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
     //
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     $pdf->SetMargins(5, 30, 10);
     $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     //        $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     //set auto page breaks
     $pdf->SetAutoPageBreak(TRUE, 14);
     //        $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     //set some language-dependent strings
     $pdf->setLanguageArray($l);
     $pdf->SetFont('helvetica', '', 10);
     // add a page
     $pdf->AddPage();
     //        $pdf->SetXY(110, 200);
     $pdf->Image(PATH_ROOT . '/web/img/iso.png', '255', '8', 15, 15, 'PNG', '', 'T', false, 300, '', false, false, 1, false, false, false);
     $cadena2 = "";
     $cadena2 .= "<br/><br/><br/><br/>";
     $cadena2 .= '<table width="740" border="0">';
     $cadena2 .= '<tr>';
     $cadena2 .= '<td width="100" height="65" ></td><td width="160" align="center" >';
     $cadena2 .= '<h4 style="border-top:1px solid black">Archivista Remitente<br>' . $usuarioOrigen . '</h4>';
     $cadena2 .= '</td><td width="100"></td>';
     $cadena2 .= '<td width="100" ></td><td width="150" align="center">';
     $cadena2 .= '<h4 style="border-top:1px solid black">Archivista de Recepci&oacute;n<br>' . $usuarioDestino . '</h4></td>';
     $cadena2 .= '<td width="100"></td></tr>';
     $cadena2 .= '<tr>';
     $cadena2 .= '<td width="100" height="65" ></td><td width="160" align="center" >';
     $cadena2 .= '<h4 style="border-top:1px solid black">Autoridad<br>Unidad Remitente</h4>';
     $cadena2 .= '</td><td width="100"></td>';
     $cadena2 .= '<td width="100" ></td><td width="150" align="center">';
     $cadena2 .= '<h4 style="border-top:1px solid black">SGE / DOC<br></h4></td>';
     $cadena2 .= '<td width="100"></td></tr>';
     $cadena2 .= '</table>';
     $cadena = $cadena . $cadena2;
     $pdf->writeHTML($cadena, true, false, false, false, '');
     // -----------------------------------------------------------------------------
     //Close and output PDF document
     //   $pdf->Output('reporte_transferencia.pdf', 'D');
     $pdf->Output('reporte_transferencia.pdf', 'I');
     Header("Location: " . PATH_DOMAIN . "/soltransferencia/");
 }
 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 verRpteExcel()
 {
     header("Content-type: application/vnd.ms-excel; name='excel'");
     header("Content-Disposition: filename=transferencia_expedientes.xls");
     header("Pragma: no-cache");
     header("Expires: 0");
     $id = VAR3;
     $where = "";
     $tab_extransferencia = new tab_exptransferencia();
     $result = $tab_extransferencia->dbSelectBySQL("select* from tab_exptransferencia where str_id={$id}");
     $cantidad = count($result);
     $valor3 = "";
     $t = 1;
     foreach ($result as $row) {
         $valor3 .= "tab_expediente.exp_id={$row->exp_id}";
         if ($t < $cantidad) {
             $valor3 .= " or ";
         }
         $t++;
     }
     $where .= " AND {$valor3} ";
     $sql = "SELECT\r\n            f.fon_codigo,\r\n            f.fon_cod,\r\n            (SELECT fon_codigo from tab_fondo WHERE fon_id=f.fon_par) ||'.'|| f.fon_codigo ||'.'||tab_unidad.uni_cod ||'.'|| tab_tipocorr.tco_codigo ||'.'||tab_series.ser_codigo||'.'||\r\n            tab_expediente.exp_codigo AS codigo,\r\n            (NULLIF(tab_expediente.exp_codigo,'')::int) as cantidad,\r\n            tab_soltransferencia.str_id,\r\n            tab_soltransferencia.str_fecha,\r\n            tab_soltransferencia.uni_id,\r\n            tab_soltransferencia.unid_id,\r\n            tab_soltransferencia.str_nrocajas,\r\n            tab_soltransferencia.str_totpzas,\r\n            tab_soltransferencia.str_totml,\r\n            tab_soltransferencia.str_nroreg,\r\n            tab_soltransferencia.str_fecini,\r\n            tab_soltransferencia.str_fecfin,\r\n            tab_soltransferencia.str_estado,\r\n            tab_soltransferencia.usu_id,\r\n            tab_soltransferencia.usud_id,\r\n            tab_soltransferencia.str_direccion,\r\n            tab_soltransferencia.str_telefono,\r\n            tab_expisadg.exp_fecha_exi,\r\n            tab_expisadg.exp_fecha_exf,\r\n            tab_expisadg.exp_anioi,\r\n            tab_expisadg.exp_aniof,\r\n            tab_expisadg.exp_titulo,\r\n            tab_series.ser_codigo,\r\n            tab_unidad.uni_codigo,\r\n            tab_unidad.uni_id,\r\n            tab_unidad.uni_par,\r\n            tab_unidad.uni_cod,\r\n            tab_unidad.uni_descripcion,\r\n            f.fon_cod,\r\n            tab_series.ser_categoria,\r\n            tab_expisadg.exp_titulo,\r\n            tab_expediente.exp_obs,\r\n            tab_series.ser_id,\r\n            tab_series.ser_par,\r\n            tab_expediente.exp_id\r\n            FROM\r\n            tab_unidad\r\n            INNER JOIN tab_fondo as f ON tab_unidad.fon_id = f.fon_id\r\n            INNER JOIN tab_series ON tab_series.uni_id = tab_unidad.uni_id\r\n            INNER JOIN tab_expediente ON tab_expediente.ser_id = tab_series.ser_id\r\n            INNER JOIN tab_expisadg ON tab_expisadg.exp_id = tab_expediente.exp_id\r\n            INNER JOIN tab_exptransferencia ON tab_expediente.exp_id = tab_exptransferencia.exp_id\r\n            INNER JOIN tab_soltransferencia ON tab_soltransferencia.str_id = tab_exptransferencia.str_id\r\n            INNER JOIN tab_tipocorr ON tab_tipocorr.tco_id = tab_series.tco_id\r\n            WHERE\r\n            tab_soltransferencia.str_estado = 2 \r\n            AND tab_expediente.exp_estado = 1 \r\n            {$where} \r\n            ORDER BY f.fon_cod,\r\n            tab_unidad.uni_cod,\r\n            tab_series.ser_orden, \r\n            tab_series.ser_codigo, \r\n            tab_expediente.exp_codigo::int ";
     $usua = new usuario();
     $subfondo = new fondo();
     $seccion = new unidad();
     $expedientes = new expediente();
     $archivo = new tab_archivo();
     $archivo2 = new tab_archivo();
     $query = $archivo->dbSelectBySQL($sql);
     $query2 = $archivo2->dbSelectBySQL($sql);
     $usu_id = "";
     $usud_id = "";
     $uni_id = "";
     foreach ($query2 as $ids) {
         $usu_id = $ids->usu_id;
         $usud_id = $ids->usud_id;
         $uni_id = $ids->uni_id;
         $uni_par = $ids->uni_par;
         $uni_cod = $ids->uni_cod;
         $str_telefono = $ids->str_telefono;
         $str_id = $ids->str_id;
         $str_fecha = $ids->str_fecha;
         $str_direccion = $ids->str_direccion;
         $uni_descripcion = $ids->uni_descripcion;
     }
     $usuarioOrigen = $usua->obtenerNombre($usu_id);
     $usuarioDestino = $usua->obtenerNombre($usud_id);
     $fond = $subfondo->obtenerfon($usu_id);
     $ob_seccion = $seccion->obtenerSeccion($uni_id);
     $cadena = "";
     $cadena .= '<table width="740" border="1">';
     $cadena .= '<tr>';
     $cadena .= '<td colspan="10" align="center" ><b>';
     $cadena .= 'FORMULARIO DE RELACION DE TRANSFERENCIAS</b><br /></td>';
     $cadena .= '</tr>';
     $cadena .= '<tr>';
     $cadena .= '<td colspan="9" align="right" style=border:none ><b>';
     $cadena .= 'Nro. de transferencia:</b></td><td align="center">' . $str_id . '</td>';
     $cadena .= '</tr>';
     $cadena .= '<tr>';
     $cadena .= '<td colspan="5">';
     $cadena .= '<b>Subfondo:</b> ' . $fond . '<br />';
     $cadena .= '<b>Secci&oacute;n:</b> ';
     $explode = explode(".", $uni_cod);
     $contado = count($explode);
     $codigo = "";
     for ($t = 0; $t < $contado - 1; $t++) {
         $codigo .= $explode[$t];
         if ($t < $contado - 2) {
             $codigo .= ".";
         }
     }
     $codigo2 = $codigo;
     if (strlen($codigo) == 1) {
         $codigo = $codigo . ".0";
     } else {
         $estraer_codigo = explode(".", $codigo);
         $codigo = $estraer_codigo[0] . ".0";
     }
     $tab_unidad = new Tab_unidad();
     $unidad = new unidad();
     $sqlUni2 = "SELECT\r\n                    tab_unidad.uni_descripcion\r\n                    FROM\r\n                    tab_unidad\r\n                    WHERE\r\n                    tab_unidad.uni_cod = '{$codigo}'";
     $codigoss = explode(".", $codigo2);
     $cantcodigo2 = count($codigoss);
     if ($cantcodigo2 == 1) {
         $codigo2 = "{$codigo2}.1";
     }
     $sqlUni1 = "SELECT\r\n                    tab_unidad.uni_descripcion\r\n                    FROM\r\n                    tab_unidad\r\n                    WHERE\r\n                    tab_unidad.uni_cod = '{$codigo2}'";
     $resultadott = $tab_unidad->dbSelectBySQL($sqlUni2);
     $resultadott1 = $tab_unidad->dbSelectBySQL($sqlUni1);
     $ca1 = "";
     foreach ($resultadott1 as $rowss2) {
         $ca1 = $rowss2->uni_descripcion;
     }
     foreach ($resultadott as $rowss) {
         $ca = $rowss->uni_descripcion;
     }
     $variable = $ca;
     $excluirparent = explode("(", $variable);
     if ($excluirparent[1] == "") {
         $ca = $ca;
     } else {
         $excluirultimoparent = $excluirparent[1] . "x";
         $imprimir_descripcion = explode(")", $excluirultimoparent);
         $ca = $imprimir_descripcion[0];
     }
     $ca = $unidad->obtenerPadre($uni_par, $uni_descripcion);
     $cadena .= $ca;
     $cadena .= '<br><b>Subsecci&oacute;n:</b> ';
     $cadena .= $ca1;
     $cadena .= '</td>';
     $cadena .= '<td colspan="5"  >';
     $cadena .= '<br /><b>Tel&eacute;fono:</b> ' . $str_telefono . '</td>';
     $cadena .= '</tr>';
     $cadena .= '<tr>';
     $cadena .= '<td width="20" rowspan="2" align="center" bgcolor="#CCCCCC"><strong>Nro.</strong></td>';
     $cadena .= '<td width="125" colspan="2" rowspan="2" style="text-align:center" bgcolor="#CCCCCC"><strong>Serie/Subserie</strong></td>';
     $cadena .= '<td width="225" rowspan="2" style="text-align:center" bgcolor="#CCCCCC"><strong>T&iacute;tulo del Expediente</strong></td>';
     $cadena .= '<td width="90" rowspan="2" style="text-align:center" bgcolor="#CCCCCC"><strong>C&oacute;digo de Referencia</strong></td>';
     $cadena .= '<td width="100" colspan="2" style="text-align:center" bgcolor="#CCCCCC"><strong>Fechas extremas</strong></td>';
     $cadena .= '<td width="40" rowspan="2" bgcolor="#CCCCCC" style="font-size:25px"><strong >Nro.Doc.</strong></td>';
     $cadena .= '<td width="40" rowspan="2" bgcolor="#CCCCCC"><strong>Cajas</strong></td>';
     $cadena .= '<td width="100" rowspan="2" style="text-align:center" bgcolor="#CCCCCC"><p><strong>Obs.</strong></p></td>';
     $cadena .= '</tr>';
     $cadena .= '<tr>';
     $cadena .= '<td width="50" style="text-align:center" bgcolor="#CCCCCC"><strong>Inicio</strong></td>';
     $cadena .= '<td width="50" style="text-align:center" bgcolor="#CCCCCC"><strong>Final</strong></td>';
     $cadena .= '</tr>';
     $sum = 0;
     $i = 1;
     $cant = 0;
     foreach ($query as $row) {
         $tabserie = new tab_series();
         if ($row->exp_fecha_exi == "") {
             $fei = "";
         } else {
             $fechainicial = explode("-", $row->exp_fecha_exi);
             $fei = $fechainicial[2] . "/" . $fechainicial[1] . "/" . $fechainicial[0];
         }
         if ($row->exp_fecha_exf == "") {
             $fef = "";
         } else {
             $fechafinal = explode("-", $row->exp_fecha_exf);
             $fef = $fechafinal[2] . "/" . $fechafinal[1] . "/" . $fechafinal[0];
         }
         $cadena .= '<tr>';
         $cadena .= '<td align="center">' . $i . '</td>';
         $cadena .= '<td colspan="2" style="font-size:22px">';
         $cadena .= $row->ser_categoria;
         $expsum = $expedientes->cantidadExpedientes($row->exp_id);
         $cant = $cant + $expsum;
         $cadena .= '</td>';
         $cadena .= '<td align="left" style="font-size:22px">' . htmlentities($row->exp_titulo, ENT_COMPAT, 'utf-8') . '</td>';
         $cadena .= '<td align="center" style="font-size:22px">' . $row->codigo . '</td>';
         $cadena .= '<td align="center" style="font-size:22px">' . $row->exp_anioi . '</td>';
         $cadena .= '<td align="center"  style="font-size:22px">' . $row->exp_aniof . '</td>';
         $cadena .= '<td align="center" style="font-size:22px">' . $expsum . '</td>';
         $cadena .= '<td align="center"></td>';
         $cadena .= '<td style="font-size:22px">' . $row->exp_obs . '</td>';
         $cadena .= '</tr>';
         $i++;
     }
     $cadena .= '<tr>';
     $cadena .= '<td colspan="6" align="right" >TOTAL</td>';
     $cadena .= '<td align="center"></td>';
     $cadena .= '<td align="center">' . $cant . '</td>';
     $cadena .= '<td></td>';
     $cadena .= '<td>&nbsp;</td>';
     $cadena .= '</tr>';
     $cadena .= '</table>';
     $fecha = explode("-", $str_fecha);
     $anio = $fecha[0];
     $mes = $fecha[1];
     $dia = $fecha[2];
     switch ($mes) {
         case 1:
             $mes = "Enero";
             break;
         case 2:
             $mes = "Febrero";
             break;
         case 3:
             $mes = "Marzo";
             break;
         case 4:
             $mes = "Abril";
             break;
         case 5:
             $mes = "Mayo";
             break;
         case 6:
             $mes = "Junio";
             break;
         case 7:
             $mes = "Julio";
             break;
         case 8:
             $mes = "Agosto";
             break;
         case 9:
             $mes = "Septiembre";
             break;
         case 10:
             $mes = "Octubre";
             break;
         case 11:
             $mes = "Noviembre";
             break;
         case 12:
             $mes = "Diciembre";
             break;
     }
     $cadena .= '<b>Lugar y fecha de la transferencia:</b> ' . $str_direccion . '  ' . $dia . ' de ' . $mes . ' de ' . $anio;
     $cadena2 = "";
     $cadena2 .= '<table width="740" border="0">';
     $cadena2 .= '<tr>';
     $cadena2 .= '<td width="100" height="65" ></td><td width="160" align="center" >';
     $cadena2 .= '<h4 style="border-top:1px solid black">Archivista Remitente<br>' . $usuarioOrigen . '</h4>';
     $cadena2 .= '</td><td width="100"></td>';
     $cadena2 .= '<td width="100" ></td><td width="150" align="center">';
     $cadena2 .= '<h4 style="border-top:1px solid black">Archivista de Recepci&oacute;n<br>' . $usuarioDestino . '</h4></td>';
     $cadena2 .= '<td width="100"></td></tr>';
     $cadena2 .= '<tr>';
     $cadena2 .= '<td width="100" height="65" ></td><td width="160" align="center" >';
     $cadena2 .= '<h4 style="border-top:1px solid black">Autoridad<br>Unidad Remitente</h4>';
     $cadena2 .= '</td><td width="100"></td>';
     $cadena2 .= '<td width="100" ></td><td width="150" align="center">';
     $cadena2 .= '<h4 style="border-top:1px solid black">SGE / DOC<br></h4></td>';
     $cadena2 .= '<td width="100"></td></tr>';
     $cadena2 .= '</table>';
     $cadena = $cadena . $cadena2;
     echo $cadena;
 }
 function viewPaquetesBACK()
 {
     $ini = $_REQUEST['nro_inicial'];
     $fin = $_REQUEST['nro_final'];
     if ($fin == NULL) {
         $fin = $ini;
     }
     $fondo2 = new Tab_fondo();
     $texp = new Tab_etiquetas();
     $usuario = new usuario();
     $sql = "SELECT\r\n                tab_fondo.fon_cod,\r\n                u.uni_cod,\r\n                tab_tipocorr.tco_codigo,\r\n                tab_series.ser_codigo,\r\n                tab_expediente.exp_codigo,\r\n                tab_fondo.fon_descripcion,\r\n                (SELECT uni_descripcion from tab_unidad WHERE tab_unidad.uni_id=u.uni_par) AS uni_par_cod,\r\n                u.uni_codigo,\r\n                u.uni_descripcion,\r\n                tab_series.ser_categoria,\r\n                tab_expisadg.exp_titulo,\r\n                tab_expisadg.exp_anioi,\r\n                tab_expisadg.exp_aniof,\r\n                tab_expisadg.exp_fecha_exi,\r\n                (tab_expisadg.exp_fecha_exi +\r\n                        (SELECT tab_retensiondoc.red_prearc * INTERVAL '1 year'\r\n                        FROM tab_retensiondoc\r\n                        WHERE tab_retensiondoc.red_id = tab_series.red_id)) ::DATE AS exp_fecha_exf,\r\n                tab_expediente.exp_nroejem,\r\n                tab_expediente.exp_tomovol,\r\n                tab_expediente.exp_nrocaj,\r\n                (SELECT sof_nombre FROM tab_sopfisico WHERE sof_id=tab_expediente.sof_id AND tab_sopfisico.sof_estado = '1' ) AS sof_nombre,\r\n                tab_expediente.exp_sala,\r\n                tab_expediente.exp_estante,\r\n                tab_expediente.exp_cuerpo,\r\n                tab_expediente.exp_balda,\r\n                tab_expediente.exp_obs\r\n                FROM\r\n                tab_fondo\r\n                INNER JOIN tab_unidad as u ON tab_fondo.fon_id = u.fon_id\r\n                INNER JOIN tab_series ON u.uni_id = tab_series.uni_id\r\n                INNER JOIN tab_tipocorr ON tab_tipocorr.tco_id = tab_series.tco_id\r\n                INNER JOIN tab_expediente ON tab_series.ser_id = tab_expediente.ser_id\r\n                INNER JOIN tab_expisadg ON tab_expediente.exp_id = tab_expisadg.exp_id\r\n                WHERE\r\n                tab_fondo.fon_estado = 1 AND\r\n                u.uni_estado = 1 AND\r\n                tab_tipocorr.tco_estado = 1 AND\r\n                tab_series.ser_estado = 1 AND\r\n                tab_expediente.exp_estado = 1 AND\r\n                tab_expisadg.exp_estado = 1 AND\r\n                tab_expediente.exp_id = '" . $_REQUEST['exp_id'] . "' ";
     $rows = $texp->dbSelectBySQL($sql);
     $expediente = new Tab_expediente();
     $ser_id = $expediente->dbselectByField("exp_id", $_REQUEST['exp_id']);
     $ser_id = $ser_id[0];
     $sql = "SELECT\r\n                tab_fondo.fon_cod,\r\n                tab_unidad.uni_cod,\r\n                tab_tipocorr.tco_codigo,\r\n                tab_series.ser_codigo\r\n                FROM\r\n                tab_fondo\r\n                INNER JOIN tab_unidad ON tab_fondo.fon_id = tab_unidad.fon_id\r\n                INNER JOIN tab_series ON tab_unidad.uni_id = tab_series.uni_id\r\n                INNER JOIN tab_tipocorr ON tab_tipocorr.tco_id = tab_series.tco_id\r\n                WHERE tab_fondo.fon_estado = 1\r\n                AND tab_unidad.uni_estado = 1\r\n                AND tab_tipocorr.tco_estado = 1\r\n                AND tab_series.ser_estado = 1\r\n                AND tab_series.ser_id ='" . $ser_id->ser_id . "'";
     $tabfondo = new Tab_fondo();
     $cuerpo = $tabfondo->dbSelectBySQL($sql);
     foreach ($cuerpo as $idlistado) {
         $tco_codigo = $idlistado->tco_codigo;
     }
     // Include the main TCPDF library (search for installation path).
     //require_once('tcpdf/tcpdf_include.php');
     require_once 'tcpdf/tcpdf.php';
     // create new PDF document
     $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     // set document information
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->SetAuthor('Castellon S.R.L.');
     $pdf->SetTitle('Etiquetado de Cajas');
     $pdf->SetSubject('Etiquetado de Cajas');
     $pdf->SetKeywords('Etiquetado, Cajas, cajas, caratulas, folders');
     // set default header data
     //  $pdf->SetHeaderData('logo2.png', 25, 'ADMINISTRADORA BOLIVIANA DE CARRETERA', 'IMPRESI&Oacute;N DE CAJAS');
     //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 048', PDF_HEADER_STRING);
     // set header and footer fonts
     $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
     $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
     // set default monospaced font
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     // set margins
     $pdf->SetMargins(PDF_MARGIN_LEFT, 5, PDF_MARGIN_RIGHT);
     $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     // set auto page breaks
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     // set image scale factor
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     // set some language-dependent strings (optional)
     if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {
         require_once dirname(__FILE__) . '/lang/eng.php';
         $pdf->setLanguageArray($l);
     }
     // ---------------------------------------------------------
     // set font
     $pdf->SetFont('helvetica', 'B', 8);
     // add a page
     $pdf->AddPage();
     $pdf->Write(0, '', '', 0, 'L', true, 0, false, false, 0);
     $pdf->SetFont('helvetica', '', 8);
     $st = "";
     // -----------------------------------------------------------------------------
     $id_exp = $_REQUEST['exp_id'];
     $cantMin = "";
     $cantMax = "";
     for ($i = $ini; $i <= $fin; $i++) {
         $expediente = new expediente();
         foreach ($rows as $value) {
             if ($tco_codigo == "I") {
                 $obteneCaja = $expediente->obtenerCajaCorrespondecia($_REQUEST['exp_id']);
                 $cantMin = strlen($obteneCaja->minimo);
                 $cantMax = strlen($obteneCaja->maximo);
             } else {
                 $obteneCaja = $expediente->obtenerCaja($i, $_REQUEST['exp_id']);
                 $cantMin = strlen($obteneCaja->minimo);
                 $cantMax = strlen($obteneCaja->maximo);
             }
             $expe = new Tab_expediente();
             $sqlcaja = "SELECT\r\n                            tab_archivo.fil_sala,\r\n                            tab_archivo.fil_estante,\r\n                            tab_archivo.fil_balda,\r\n                            tab_archivo.fil_cuerpo\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 = '" . $_REQUEST['exp_id'] . "' AND\r\n                            tab_expediente.exp_estado=1 AND\r\n                            tab_archivo.fil_nropaq='{$i}'";
             $cajaresult = $expe->dbSelectBySQL($sqlcaja);
             foreach ($cajaresult as $rowscaja) {
                 $sala = $rowscaja->fil_sala;
                 $estante = $rowscaja->fil_estante;
                 $balda = $rowscaja->fil_balda;
                 $cuerpo = $rowscaja->fil_cuerpo;
             }
             $exptransferencia = new tab_exptransferencia();
             $sql = "SELECT\r\n                        tab_soltransferencia.str_fecha,\r\n                        tab_soltransferencia.str_id\r\n                        FROM\r\n                        tab_exptransferencia\r\n                        INNER JOIN tab_soltransferencia ON tab_soltransferencia.str_id = tab_exptransferencia.str_id\r\n                        WHERE\r\n                        tab_exptransferencia.exp_id ={$id_exp}";
             $datos = $exptransferencia->dbSelectBySQL($sql);
             $strfecha = "";
             $strid = "";
             foreach ($datos as $listr) {
                 $strfecha = $listr->str_fecha;
                 $strid = $listr->str_id;
             }
             $st .= '<br><br>';
             $st .= '<table border="1" style="width: 100%">';
             $st .= '<tr>';
             $st .= '<td style="border-right:2px solid white;">';
             $st .= '<img src="' . PATH_ROOT . '/web/img/escudo.png" width="50" height="50" border="0" />';
             $st .= '</td><td align="right"><img src="' . PATH_ROOT . '/web/img/iso.png" width="50" height="50" border="0" />';
             $st .= '</td>';
             $st .= '</tr>';
             $st .= '<tr>';
             $st .= '<td colspan="2">';
             $st .= '<table border="1" style="width: 100%; text-align: center">';
             $st .= '<tr>';
             //$st.='<td colspan="11">'.$value->fon_cod . "-" . $value->uni_cod. '</td>';
             $st .= '<th colspan="11" height="20" style="font-size:70px"><b>' . $value->fon_cod . DELIMITER . $value->uni_cod . DELIMITER . $value->tco_codigo . DELIMITER . $value->ser_codigo . DELIMITER . $value->exp_codigo . '</b></th>';
             $st .= '</tr>';
             if ($value->uni_par_cod) {
                 $st .= '<tr>';
                 $st .= '<td colspan="11" height="20" style="font-size:30px"><b>' . $value->uni_par_cod . '</b></td>';
                 $st .= '</tr>';
             } else {
                 $st .= '<tr>';
                 $st .= '<td colspan="11" height="20" style="font-size:30px"><b>' . $value->uni_descripcion . '</b></td>';
                 $st .= '</tr>';
             }
             $st .= '<tr>';
             $st .= '<td colspan="11" height="20" style="font-size:35px"><b>' . $value->ser_categoria . '</b></td>';
             $st .= '</tr>';
             $st .= '<tr>';
             $st .= '<td colspan="11" height="20" style="font-size:48px"><b>' . $value->exp_titulo . '</b></td>';
             $st .= '</tr>';
             $pdf->SetFont('helvetica', '', 8);
             $st .= '<tr>';
             $st .= '<td colspan="2" height="20" bgcolor="#CCCCCC" style="font-size:40px" width="232">FECHAS EXTREMAS:</td>';
             $st .= '<td colspan="9" bgcolor="#CCCCCC" width="420" style="font-size:40px">CODIGOS:</td>';
             $st .= '</tr>';
             $st .= '<tr>';
             $st .= '<td colspan="2" height="20" style="font-size:45px"><b>' . $value->exp_anioi . "-" . $value->exp_aniof . '</b></td>';
             $st .= '<th colspan="9" rowspan="3" style="text-align:left;font-size:45px;padding:15px">';
             $sqlcodigos = "SELECT\r\n                            tab_fondo.fon_cod,\r\n                            u.uni_cod,\r\n                            tab_tipocorr.tco_codigo,\r\n                            tab_series.ser_codigo,\r\n                            tab_expediente.exp_codigo,\r\n                            (SELECT uni_descripcion from tab_unidad WHERE tab_unidad.uni_id=u.uni_par) AS uni_par_cod,\r\n                            u.uni_codigo,\r\n                            (SELECT sof_nombre FROM tab_sopfisico WHERE sof_id=tab_expediente.sof_id AND tab_sopfisico.sof_estado = '1' ) AS sof_nombre\r\n                            FROM\r\n                            tab_fondo\r\n                            INNER JOIN tab_unidad AS u ON tab_fondo.fon_id = u.fon_id\r\n                            INNER JOIN tab_series ON u.uni_id = tab_series.uni_id\r\n                            INNER JOIN tab_tipocorr ON tab_tipocorr.tco_id = tab_series.tco_id\r\n                            INNER JOIN tab_expediente ON tab_series.ser_id = tab_expediente.ser_id\r\n                            WHERE\r\n                            tab_fondo.fon_estado = 1 AND\r\n                            u.uni_estado = 1 AND\r\n                            tab_tipocorr.tco_estado = 1 AND\r\n                            tab_series.ser_estado = 1 AND\r\n                            tab_expediente.exp_estado = 1 AND\r\n                            tab_expediente.exp_id ='" . $_REQUEST['exp_id'] . "'";
             $idexp = $_REQUEST['exp_id'];
             $sqlarchivo = "SELECT fil_nro,fil_fot 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 = {$idexp} AND\r\n                                tab_archivo.fil_nropaq = '{$i}' AND\r\n                                tab_expediente.exp_estado = 1 ORDER BY fil_nro";
             $cod_fil_nro = $expe->dbSelectBySQL($sqlarchivo);
             $codigoDocument = $fondo2->dbSelectBySQL($sqlcodigos);
             $codigoDocument = $codigoDocument[0];
             $cant1 = 0;
             $codigo_paquetes = $codigoDocument->fon_cod . DELIMITER . $codigoDocument->uni_cod . DELIMITER . $codigoDocument->tco_codigo . DELIMITER . $codigoDocument->ser_codigo . DELIMITER . $codigoDocument->exp_codigo;
             foreach ($cod_fil_nro as $filnro) {
                 $st .= $codigo_paquetes . DELIMITER . $filnro->fil_nro;
                 $st .= "  (" . $filnro->fil_fot . ")";
                 $cant1 = $cant1 + $filnro->fil_fot;
                 $st .= "<br>";
             }
             $st .= '</th>';
             $st .= '</tr>';
             $cant = $cant1;
             $st .= '<tr>';
             $st .= '<td colspan="4" height="20" bgcolor="#CCCCCC" width="232">NRO. DE PAQUETE</td>';
             //  $st.='<td colspan="7" bgcolor="#CCCCCC" >ML</td>';
             $st .= '</tr>';
             //width="420"
             $st .= '<tr>';
             $st .= '<td height="20" colspan="4" rowspan="3" style="font-size:190px">' . $i . '</td>';
             //                    $st.='<td colspan="7" height="20" style="font-size:70px" >0,32</td>';
             $st .= '</tr>';
             $st .= '<tr>';
             $st .= '<td colspan="5" bgcolor="#CCCCCC" height="20" width="218">NRO. DE PIEZAS</td>';
             $st .= '<td colspan="2" bgcolor="#CCCCCC" width="201">Nº DE TRANSFERENCIA</td>';
             $st .= '</tr>';
             $st .= '<tr>';
             $st .= '<td colspan="5" height="20" style="font-size:60px"><b>' . $cant . '</b></td>';
             if ($strid == "") {
                 $st .= '<td colspan="2"></td>';
             } else {
                 $st .= '<td colspan="2">' . $strid . '</td>';
             }
             $st .= '</tr>';
             $st .= '<tr>';
             $st .= '<td colspan="4" bgcolor="#CCCCCC" height="20" width="232">UBICACI&Oacute;N TOPOGRAFICA:</td>';
             $st .= '<td colspan="5" bgcolor="#CCCCCC" height="20"  width="218">FECHA DE TRANSFERENCIA DOCUMENTAL</td>';
             $st .= '<td colspan="2" bgcolor="#CCCCCC" width="201">ELABORADO POR:</td>';
             $st .= '</tr>';
             $st .= '<tr>';
             $st .= '<td height="20" bgcolor="#CCCCCC">SALA</td>';
             $st .= '<td height="20" bgcolor="#CCCCCC">ESTANTE</td>';
             $st .= '<td height="20" bgcolor="#CCCCCC">BALDA</td>';
             $st .= '<td height="20" bgcolor="#CCCCCC">CUERPO</td>';
             $st .= '<td colspan="5" rowspan="2">';
             if ($strfecha != "") {
                 $fechastr = explode("-", $strfecha);
                 $fett = $fechastr[2] . '-' . $fechastr[1] . '-' . $fechastr[0];
                 $st .= $fett;
             }
             $st .= '</td>';
             $st .= '<td colspan="2" rowspan="2">' . $usuario->obtenerNombre($_SESSION['USU_ID']) . '</td>';
             $st .= '</tr>';
             $st .= '<tr>';
             $st .= '<td height="20" style="font-size:35px"></td>';
             $st .= '<td height="20" style="font-size:35px"></td>';
             $st .= '<td height="20" style="font-size:35px"></td>';
             $st .= '<td height="20" style="font-size:35px"></td>';
             $sala = "";
             $estante = "";
             $balda = "";
             $cuerpo = "";
             $st .= '</tr>';
             /*
              $st.='<tr>';
              $st.='<td height="20">' . $value->exp_sala . '</td>';
              $st.='<td>' . $value->exp_estante . '</td>';
              $st.='<td>' . $value->exp_cuerpo . '</td>';
              $st.='<td>' . $value->exp_balda . '</td>';
              $st.='<td colspan="5"></td>';
              $st.='<td colspan="2"></td>';
              $st.='</tr>';
             */
             $st .= '</table>';
             $st .= '</td>';
             $st .= '</tr>';
             $st .= '</table>';
             $st .= '';
             //EOD;
         }
         $pdf->writeHTML($st, true, false, false, false, '');
         $st = "";
     }
     // -----------------------------------------------------------------------------
     //Close and output PDF document
     $pdf->Output('reporte_paquetes.pdf', 'I');
     //============================================================+
     // END OF FILE
     //============================================================+
 }
 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 VerRTransferencia()
 {
     $filtro_serie = $_REQUEST['filtro_serie'];
     $filtro_unidad = $_REQUEST['filtro_unidad'];
     $filtro_funcionario = $_REQUEST['filtro_funcionario'];
     $f_prestdesde = $_REQUEST['f_prestdesde'];
     $f_presthasta = $_REQUEST['f_presthasta'];
     $where = "";
     $tab_extransferencia = new tab_exptransferencia();
     $result = $tab_extransferencia->dbSelectBySQL("select DISTINCT(exp_id) from tab_exptransferencia");
     $cantidad = count($result);
     $valor3 = "";
     $t = 1;
     foreach ($result as $row) {
         $valor3 .= "tab_expediente.exp_id={$row->exp_id}";
         if ($t < $cantidad) {
             $valor3 .= " or ";
         }
         $t++;
     }
     $where .= " AND {$valor3} ";
     if ($filtro_serie != "") {
         $where .= " AND tab_series.ser_id=" . $filtro_serie;
     }
     if ($filtro_unidad != "") {
         $where .= " AND tab_soltransferencia.uni_id=" . $filtro_unidad;
     }
     if ($filtro_funcionario != "") {
         $where .= " AND tab_soltransferencia.usu_id=" . $filtro_funcionario;
     }
     $sql = "SELECT\r\ntab_fondo.fon_codigo,\r\ntab_expediente.exp_codigo,\r\ntab_soltransferencia.str_id,\r\ntab_soltransferencia.str_fecha,\r\ntab_soltransferencia.uni_id,\r\ntab_soltransferencia.unid_id,\r\ntab_soltransferencia.str_nrocajas,\r\ntab_soltransferencia.str_totpzas,\r\ntab_soltransferencia.str_totml,\r\ntab_soltransferencia.str_nroreg,\r\ntab_soltransferencia.str_fecini,\r\ntab_soltransferencia.str_fecfin,\r\ntab_soltransferencia.str_estado,\r\ntab_soltransferencia.usu_id,\r\ntab_soltransferencia.usud_id,\r\ntab_soltransferencia.str_direccion,\r\ntab_soltransferencia.str_telefono,\r\ntab_expisadg.exp_fecha_exi,\r\ntab_expisadg.exp_fecha_exf,\r\ntab_series.ser_codigo,\r\ntab_unidad.uni_codigo,\r\ntab_fondo.fon_cod,\r\ntab_series.ser_categoria,\r\ntab_expisadg.exp_titulo,\r\ntab_expediente.exp_obs,\r\ntab_series.ser_id,\r\ntab_series.ser_par,\r\ntab_expediente.exp_id\r\nFROM\r\ntab_unidad\r\nINNER JOIN tab_fondo ON tab_unidad.fon_id = tab_fondo.fon_id\r\nINNER JOIN tab_series ON tab_series.uni_id = tab_unidad.uni_id\r\nINNER JOIN tab_expediente ON tab_expediente.ser_id = tab_series.ser_id\r\nINNER JOIN tab_expisadg ON tab_expisadg.exp_id = tab_expediente.exp_id\r\nINNER JOIN tab_exptransferencia ON tab_expediente.exp_id = tab_exptransferencia.exp_id\r\nINNER JOIN tab_soltransferencia ON tab_soltransferencia.str_id = tab_exptransferencia.str_id\r\nWHERE\r\ntab_soltransferencia.str_estado = 2 AND\r\ntab_expediente.exp_estado = 1 " . $where . " ORDER BY tab_soltransferencia.str_id";
     $usua = new usuario();
     $subfondo = new fondo();
     $seccion = new unidad();
     $expedientes = new expediente();
     $archivo = new tab_archivo();
     $archivo2 = new tab_archivo();
     $query = $archivo->dbSelectBySQL($sql);
     $query2 = $archivo2->dbSelectBySQL($sql);
     $query2 = $query2[0];
     $usuarioOrigen = $usua->obtenerNombre($query2->usu_id);
     $usuarioDestino = $usua->obtenerNombre($query2->usud_id);
     $fond = $subfondo->obtenerfon($query2->usu_id);
     $cadena = "";
     $cadena = "<br/><br/><br/><br/><br/><br/><br/>";
     $cadena .= '<b>Cuadro 8. Formulario Normalizado de Transferencias</b>';
     $cadena .= '<br/><br/>';
     $cadena .= '<table width="740" border="1">';
     $cadena .= '<tr>';
     $cadena .= '<td colspan="10" align="center"><b>ADMINISTRADORA BOLIVIANA DE CARRETERAS</b><br />';
     $cadena .= 'Formulario de Relacion de Transferencias<br /></td>';
     $cadena .= '</tr></table>';
     $i = 1;
     foreach ($query as $row) {
         $tabserie = new tab_series();
         $cadena .= '<table border="1" width="740"><tr>';
         $cadena .= '<td colspan="5"><blockquote>';
         $cadena .= '<b>Subfondo:</b> ' . $fond . '<br />';
         $cadena .= '<b>Secci&oacute;n:</b> ';
         $ob_seccion = $seccion->obtenerSeccion($row->usu_id);
         if ($ob_seccion->tab_sec == "") {
             $cadena .= $ob_seccion->uni_descripcion . '<br />';
         } else {
             $cadena .= $ob_seccion->tab_sec . '<br />';
         }
         $cadena .= '<b>Subsecci&oacute;n:</b> ';
         if ($ob_seccion->tab_sec != "") {
             $cadena .= $ob_seccion->uni_descripcion;
         }
         $cadena .= '</blockquote></td>';
         $cadena .= '<td colspan="5"  ><blockquote><b>Nº de transferencia:</b> ' . $row->str_id;
         $cadena .= '<br /><b>Direcci&oacute;n  y Tel&eacute;fono:</b> ' . $row->str_direccion . ' ' . $row->str_telefono . '</blockquote></td>';
         $cadena .= '</tr>';
         $cadena .= '<tr>';
         $cadena .= '<td width="20" rowspan="2" align="center"><strong>Nº</strong></td>';
         $cadena .= '<td width="140" rowspan="2"><strong>Serie</strong></td>';
         $cadena .= '<td width="120" rowspan="2"><strong>Subserie</strong></td>';
         $cadena .= '<td width="80" rowspan="2"><strong>C&oacute;digo de Referencia</strong></td>';
         $cadena .= '<td colspan="2" width="130"><strong>Fechas extremas</strong></td>';
         $cadena .= '<td width="30" rowspan="2"><strong>Nº Piezas Docum.</strong></td>';
         $cadena .= '<td width="30" rowspan="2"><strong>Cajas</strong></td>';
         $cadena .= '<td width="30" rowspan="2"><strong>M.L.</strong></td>';
         $cadena .= '<td width="160" rowspan="2"><p><strong>Observ.</strong></p></td>';
         $cadena .= '</tr>';
         $cadena .= '<tr>';
         $cadena .= '<td width="65"><strong>Inicio</strong></td>';
         $cadena .= '<td width="65"><strong>Final</strong></td>';
         $cadena .= '</tr>';
         $sum = 0;
         $sum2 = 0;
         if ($row->exp_fecha_exi == "") {
             $fei = "";
         } else {
             $fechainicial = explode("-", $row->exp_fecha_exi);
             $fei = $fechainicial[2] . "/" . $fechainicial[1] . "/" . $fechainicial[0];
         }
         if ($row->exp_fecha_exf == "") {
             $fef = "";
         } else {
             $fechafinal = explode("-", $row->exp_fecha_exf);
             $fef = $fechafinal[2] . "/" . $fechafinal[1] . "/" . $fechafinal[0];
         }
         if ($row->ser_par == "") {
             $ser_id = 0;
         } else {
             $ser_id = $row->ser_par;
         }
         $obtenerSubserie = $tabserie->dbselectByField("ser_id", $ser_id);
         $u = 0;
         foreach ($obtenerSubserie as $ver) {
             $u++;
             $cte = $ver->ser_categoria;
         }
         $cadena .= '<tr>';
         $cadena .= '<td align="center">' . $i . '</td>';
         $cadena .= '<td>';
         if ($u == 0) {
             $cadena .= $row->ser_categoria;
         } else {
             $cadena .= $cte;
         }
         $cadena .= '</td>';
         $cadena .= '<td>';
         if ($u != 0) {
             $cadena .= $row->ser_categoria;
         }
         $sum = $sum + $expedientes->cantidadExpedientes($row->exp_id);
         $sum2 = $sum2 + $row->str_nrocajas;
         $cadena .= '</td>';
         $cadena .= '<td align="center">' . $row->fon_codigo . DELIMITER . $row->uni_codigo . DELIMITER . $row->ser_codigo . DELIMITER . $row->exp_codigo . '</td>';
         $cadena .= '<td align="center">' . $fei . '</td>';
         $cadena .= '<td align="center">' . $fef . '</td>';
         $cadena .= '<td align="center">' . $expedientes->cantidadExpedientes($row->exp_id) . '</td>';
         $cadena .= '<td align="center">' . $row->str_nrocajas . '</td>';
         $cadena .= '<td align="center">' . $row->str_totml . '</td>';
         $cadena .= '<td>' . $row->exp_obs . '</td>';
         $cadena .= '</tr>';
         $i++;
         $cadena .= '</table><br><br>';
     }
     require_once 'tcpdf/config/lang/eng.php';
     require_once 'tcpdf/tcpdf.php';
     $pdf = new TCPDF('L', PDF_UNIT, 'LETTER', true, 'UTF-8', false);
     $pdf->SetCreator(PDF_CREATOR);
     $pdf->setFontSubsetting(FALSE);
     $pdf->SetAuthor("Castellon");
     $pdf->SetTitle('Reporte de Transferencia');
     $pdf->SetSubject('Reporte de Transferencia');
     //        aumentado
     $pdf->SetKeywords('Castellon, TEAM DIGITAL');
     // set default header data
     $pdf->SetHeaderData('logo2.png', 20, 'MPD', 'ADMINISTRADORA BOLIVIANA DE CARRETERAS (MPD)');
     // set header and footer fonts
     $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
     //        $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
     //
     $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
     $pdf->SetMargins(5, 30, 10);
     $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
     //        $pdf->setPrintHeader(false);
     $pdf->setPrintFooter(false);
     //set auto page breaks
     $pdf->SetAutoPageBreak(TRUE, 14);
     //        $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     //set some language-dependent strings
     $pdf->setLanguageArray($l);
     $pdf->SetFont('helvetica', '', 10);
     // add a page
     $pdf->AddPage();
     //        $pdf->SetXY(110, 200);
     $pdf->Image(PATH_ROOT . '/web/img/iso.png', '255', '8', 15, 15, 'PNG', '', 'T', false, 300, '', false, false, 1, false, false, false);
     $cadena = $cadena;
     $pdf->writeHTML($cadena, true, false, false, false, '');
     // -----------------------------------------------------------------------------
     //Close and output PDF document
     //   $pdf->Output('reporte_transferencia.pdf', 'D');
     $pdf->Output('reporte_transferencia.pdf', 'I');
 }
 function loadExp()
 {
     $id_trans = VAR3;
     $usuario = $_SESSION['USU_ID'];
     $this->series = new series();
     $this->expediente = new tab_expediente();
     $this->expediente->setRequest2Object($_REQUEST);
     $this->usuario = new usuario();
     $page = $_REQUEST['page'];
     $rp = $_REQUEST['rp'];
     $sortname = $_REQUEST['sortname'];
     $sortorder = $_REQUEST['sortorder'];
     if (!$sortname) {
         $sortname = ' tab_fondo.fon_cod,
             tab_unidad.uni_cod,
             tab_series.ser_orden, 
             tab_series.ser_codigo,
             tab_expediente.exp_codigo::int ';
     }
     if (!$sortorder) {
         $sortorder = 'desc';
     }
     $sort = "ORDER BY {$sortname} {$sortorder} ";
     if (!$page) {
         $page = 1;
     }
     if (!$rp) {
         $rp = 15;
     }
     $start = ($page - 1) * $rp;
     $limit = "LIMIT {$rp} OFFSET {$start} ";
     $query = utf8_encode($_REQUEST['query']);
     $qtype = $_REQUEST['qtype'];
     $where = "";
     if ($query != "") {
         if ($qtype == 'exp_id') {
             $where .= " and tab_expediente.exp_id LIKE '{$query}' ";
         } elseif ($qtype == 'ser_categoria') {
             if ($query == 'TODOS') {
                 $where .= "";
             } else {
                 $where .= " and tab_series.ser_categoria LIKE '%{$query}%' ";
             }
         } elseif ($qtype == 'custodio') {
             $nomArray = explode(" ", $query);
             foreach ($nomArray as $nom) {
                 $where .= " and (tab_usuario.usu_nombres LIKE '%{$nom}%' OR tab_usuario.usu_apellidos LIKE '%{$nom}%') ";
             }
         } else {
             if ($query == 'TODOS') {
                 $where .= "";
             } else {
                 $where .= " and {$qtype} LIKE '%{$query}%' ";
             }
         }
     }
     $tab_expusuario = new tab_expusuario();
     $tab_extransferencia = new tab_exptransferencia();
     $result = $tab_extransferencia->dbSelectBySQL("select* from tab_exptransferencia where str_id={$id_trans}");
     $cantidad = count($result);
     $valor3 = "";
     $t = 1;
     foreach ($result as $row) {
         $nuevo = $tab_expusuario->dbSelectBySQL("select* from tab_expusuario where exp_id=" . $row->exp_id . " and usu_id={$usuario} and eus_estado=2");
         foreach ($nuevo as $list) {
             $valor3 .= "tab_expusuario.eus_id=" . $list->eus_id . "";
             if ($t < $cantidad) {
                 $valor3 .= " or ";
             }
             $t++;
         }
     }
     $where .= " AND {$valor3} ";
     if ($_SESSION["ROL_COD"] != 'AA') {
         $where .= " AND tab_expusuario.usu_id ='" . $_SESSION['USU_ID'] . "' ";
     }
     $sql = "SELECT\r\n                tab_fondo.fon_cod,\r\n                tab_unidad.uni_cod,\r\n                tab_tipocorr.tco_codigo,\r\n                tab_series.ser_codigo,\r\n                tab_expediente.exp_codigo,\r\n                tab_unidad.uni_id,\r\n                tab_series.ser_id,\r\n                tab_expediente.exp_id,\r\n                tab_series.ser_categoria,\r\n                tab_expisadg.exp_titulo,\r\n                tab_expisadg.exp_fecha_exi,\r\n                (tab_expisadg.exp_fecha_exi + \r\n                    (SELECT tab_retensiondoc.red_prearc * INTERVAL '1 year' \r\n                    FROM tab_retensiondoc \r\n                    WHERE tab_retensiondoc.red_id = tab_series.red_id)) ::DATE AS exp_fecha_exf,\r\n                tab_usuario.usu_nombres,\r\n                tab_usuario.usu_apellidos,\r\n                tab_expfondo.exf_estado\r\n                FROM\r\n                tab_unidad\r\n                INNER JOIN tab_series ON tab_unidad.uni_id = tab_series.uni_id\r\n                INNER JOIN tab_expediente ON tab_series.ser_id = tab_expediente.ser_id\r\n                INNER JOIN tab_expfondo ON tab_expediente.exp_id = tab_expfondo.exp_id\r\n                INNER JOIN tab_expusuario ON tab_expediente.exp_id = tab_expusuario.exp_id\r\n                INNER JOIN tab_expisadg ON tab_expediente.exp_id = tab_expisadg.exp_id\r\n                INNER JOIN tab_fondo ON tab_fondo.fon_id = tab_unidad.fon_id\r\n                INNER JOIN tab_tipocorr ON tab_tipocorr.tco_id = tab_series.tco_id\r\n                INNER JOIN tab_usuario ON tab_usuario.usu_id = tab_expusuario.usu_id\r\n                WHERE                \r\n                tab_series.ser_estado = 1\r\n                AND tab_expediente.exp_estado = 1\r\n                AND tab_usuario.usu_estado = 1\r\n                AND tab_expfondo.exf_estado = 1                \r\n                AND tab_expusuario.eus_estado = 2\r\n                {$where} \r\n                {$sort} \r\n                {$limit}";
     // tab_expusuario.usu_id = " . $_SESSION['USU_ID'] . "
     $expediente = new expediente();
     $result = $this->expediente->dbselectBySQL($sql);
     $total = $this->expediente->countBySQL("SELECT COUNT(tab_fondo.fon_cod)\r\n                                                FROM\r\n                                                tab_unidad\r\n                                                INNER JOIN tab_series ON tab_unidad.uni_id = tab_series.uni_id\r\n                                                INNER JOIN tab_expediente ON tab_series.ser_id = tab_expediente.ser_id\r\n                                                INNER JOIN tab_expfondo ON tab_expediente.exp_id = tab_expfondo.exp_id\r\n                                                INNER JOIN tab_expusuario ON tab_expediente.exp_id = tab_expusuario.exp_id\r\n                                                INNER JOIN tab_expisadg ON tab_expediente.exp_id = tab_expisadg.exp_id\r\n                                                INNER JOIN tab_fondo ON tab_fondo.fon_id = tab_unidad.fon_id\r\n                                                INNER JOIN tab_tipocorr ON tab_tipocorr.tco_id = tab_series.tco_id\r\n                                                INNER JOIN tab_usuario ON tab_usuario.usu_id = tab_expusuario.usu_id\r\n                                                WHERE                \r\n                                                tab_series.ser_estado = 1\r\n                                                AND tab_expediente.exp_estado = 1\r\n                                                AND tab_usuario.usu_estado = 1\r\n                                                AND tab_expfondo.exf_estado = 1                \r\n                                                AND tab_expusuario.eus_estado = 2\r\n                                                {$where}");
     header("Content-type: text/x-json");
     $json = "";
     $json .= "{\n";
     $json .= "page: {$page},\n";
     $json .= "total: {$total},\n";
     $json .= "rows: [";
     $rc = false;
     $i = 0;
     $j = 1;
     $si = 0;
     foreach ($result as $un) {
         $chk = "<input id=\"chk_" . $un->exp_id . "\" restric=\"" . $un->exp_id . "\" class=\"fil_chk" . $j . "\"   checked=\"checked\" type=\"checkbox\" value=\"" . $un->exp_id . "\"   />";
         if ($rc) {
             $json .= ",";
         }
         $json .= "\n{";
         $json .= "id:'" . $un->exp_id . "',";
         $json .= "cell:['" . $un->exp_id . "'";
         $json .= ",'" . $chk . "'";
         $json .= ",'" . addslashes($un->fon_cod . DELIMITER . $un->uni_cod . DELIMITER . $un->tco_codigo . DELIMITER . $un->ser_codigo . DELIMITER . $un->exp_codigo) . "'";
         $json .= ",'" . addslashes($un->ser_categoria) . "'";
         $json .= ",'" . addslashes($un->exp_titulo) . "'";
         $json .= ",'" . addslashes($un->exp_fecha_exi) . "'";
         $json .= ",'" . addslashes($un->exp_fecha_exf) . "'";
         $json .= ",'" . addslashes($expediente->obtenerCustodios($un->exp_id)) . "'";
         $json .= "]}";
         $rc = true;
         $i++;
         $j++;
     }
     $json .= "]\n";
     $json .= "}";
     echo $json;
 }
 function getDetalles($id)
 {
     $expediente = new expediente();
     $det = "";
     $tab_expediente = new Tab_expediente();
     $rows = $tab_expediente->dbselectByField("exp_id", $id);
     if (count($rows) == 1) {
         $tab_expediente = $rows[0];
         // Expediente ISAD-G
         $tab_expisadg = new Tab_expisadg();
         $rows2 = $tab_expisadg->dbselectByField("exp_id", $id);
         $tab_expisadg = $rows2[0];
         // Include dynamic fields
         $expcampo = new expcampo();
         $expadicional = $expcampo->obtenerSelectCamposMostrar($tab_expediente->ser_id, $tab_expediente->exp_id);
         $det .= '<tr><td><strong>C&oacute;digo:</strong></td><td colspan="3">' . $expediente->obtenerCodigo($id) . '</td></tr>';
         $det .= '<tr><td><strong>Fecha Inicial:</strong></td><td colspan="3">' . $tab_expisadg->exp_mesi . '/' . $tab_expisadg->exp_anioi . '</td></tr>';
         $det .= '<tr><td><strong>Fecha Final:</strong></td><td colspan="3">' . $tab_expisadg->exp_mesf . '/' . $tab_expisadg->exp_aniof . '</td></tr>';
         if ($tab_expediente->exp_sala || $tab_expediente->exp_estante || $tab_expediente->exp_cuerpo || $tab_expediente->exp_balda) {
             $det .= '<tr><td>Unidad de instalaci&oacute;n:</td><td colspan="3"></td></tr>';
         }
         if ($tab_expediente->exp_sala) {
             $det .= '<tr><td><strong>Sala:</strong></td><td colspan="3">' . $tab_expediente->exp_sala . '</td></tr>';
         }
         if ($tab_expediente->exp_estante) {
             $det .= '<tr><td><strong>Estante:</strong></td><td colspan="3">' . $tab_expediente->exp_estante . '</td></tr>';
         }
         if ($tab_expediente->exp_cuerpo) {
             $det .= '<tr><td><strong>Cuerpo:</strong></td><td colspan="3">' . $tab_expediente->exp_cuerpo . '</td></tr>';
         }
         if ($tab_expediente->exp_balda) {
             $det .= '<tr><td><strong>Balda:</strong></td><td colspan="3">' . $tab_expediente->exp_balda . '</td></tr>';
         }
         if ($expadicional) {
             $det .= '<tr><td>Datos adicionales:</td><td colspan="3"></td></tr>' . $expadicional;
         }
     }
     return $det;
 }
 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');
 }