function RegistraListado($ide) { if ($ide == '') { //if($_SESSION['session'][6]){ //$where = "WHERE (d.id_estado = '3' OR d.id_estado = '13' OR d.id_estado = '12' OR d.id_estado = '11')"; //}else{ $where = "WHERE\r\n\t\t\t\t(((d.id_estado = '4' OR d.id_estado = '12' OR d.id_estado = '11' \r\n\t\t\t\tOR d.id_estado = '6' OR d.id_estado = '16' OR d.id_estado = '17' \r\n\t\t\t\tOR d.id_estado = '18' OR d.id_estado = '3' OR d.id_estado = '13' \r\n\t\t\t\tOR d.id_estado = '12')"; //} $sql_reg = "SELECT\r\n\t\t\t\thd.id_documento as id,\r\n\t\t\t\td.fecha_registro_documento as fecha,\r\n\t\t\t\td.asunto_documento as asunto,\r\n\t\t\t\td.codigo_documento as codigo,\r\n\t\t\t\ttd.nombre_tipo_documento as tipo,\r\n\t\t\t\tr.nombre_remitente as remitente,\r\n\t\t\t\thd.original_historial_documento as categoria,\r\n\t\t\t\td.numero_documento as numero,\r\n\t\t\t\td.id_estado as id_estado,\r\n\t\t\t\te.abrev_nombre_estado as estado\r\n\t\t\t\tFROM\r\n\t\t\t\thistorial_documentos AS hd\r\n\t\t\t\tInner Join documentos AS d ON d.id_documento = hd.id_documento\r\n\t\t\t\tInner Join estados AS e ON e.id_estado = d.id_estado\r\n\t\t\t\tLEFT Join remitentes AS r ON r.id_remitente = d.id_remitente\r\n\t\t\t\tLEFT Join tipos_documento AS td ON d.id_tipo_documento = td.id_tipo_documento\r\n\t\t\t\t{$where}\r\n\t\t\t\tAND hd.original_historial_documento = 1) OR hd.original_historial_documento = 2 )\r\n\t\t\t\tAND hd.id_area = '" . $_SESSION['session'][5] . "'\r\n\t\t\t\tUNION\r\n\t\t\t\tSELECT\r\n\t\t\t\tha.id_documento as id,\r\n\t\t\t\td.fecha_registro_documento as fecha,\r\n\t\t\t\td.asunto_documento as asunto,\r\n\t\t\t\td.codigo_documento as codigo,\r\n\t\t\t\ttd.nombre_tipo_documento as tipo,\r\n\t\t\t\tr.nombre_remitente as remitente,\r\n\t\t\t\tha.original_historial_atencion as categoria,\r\n\t\t\t\td.numero_documento as numero,\r\n\t\t\t\td.id_estado as id_estado,\r\n\t\t\t\te.abrev_nombre_estado as estado\t\r\n\t\t\t\tFROM\r\n\t\t\t\thistorial_atencion AS ha\r\n\t\t\t\tInner Join documentos AS d ON ha.id_documento = d.id_documento\r\n\t\t\t\tInner Join estados AS e ON d.id_estado = e.id_estado\r\n\t\t\t\tLEFT Join tipos_documento AS td ON d.id_tipo_documento = td.id_tipo_documento\r\n\t\t\t\tLEFT Join remitentes AS r ON d.id_remitente = r.id_remitente\r\n\t\t\t\t{$where}\r\n\t\t\t\tAND ha.original_historial_atencion = 1) OR ha.original_historial_atencion = 2 )\r\n AND(\r\n\t\t\t\t(ha.id_area = '" . $_SESSION['session'][5] . "' AND ha.tipo_historial_atencion=0) OR\r\n\t\t\t\t(ha.id_area_destino = '" . $_SESSION['session'][5] . "' AND ha.tipo_historial_atencion=1) OR\r\n (ha.id_area_destino = '" . $_SESSION['session'][5] . "' AND ha.tipo_historial_atencion=2)\r\n\t\t\t\t)\r\n\t\t\t\tORDER BY 1 DESC, 7 ASC"; $query_reg = new Consulta($sql_reg); } else { if ($ide == "LT") { $where = ""; } else { $where = "AND d.id_estado = {$ide} "; } $sql_reg = "SELECT\r\n\t\t\t\thd.id_documento as id,\r\n\t\t\t\td.fecha_registro_documento as fecha,\r\n\t\t\t\td.asunto_documento as asunto,\r\n\t\t\t\td.codigo_documento as codigo,\r\n\t\t\t\ttd.nombre_tipo_documento as tipo,\r\n\t\t\t\tr.nombre_remitente as remitente,\r\n\t\t\t\thd.original_historial_documento as categoria,\r\n\t\t\t\td.numero_documento as numero,\r\n\t\t\t\td.id_estado as id_estado,\r\n\t\t\t\te.abrev_nombre_estado as estado\r\n\t\t\t\tFROM\r\n\t\t\t\thistorial_documentos AS hd\r\n\t\t\t\tInner Join documentos AS d ON d.id_documento = hd.id_documento\r\n\t\t\t\tInner Join estados AS e ON e.id_estado = d.id_estado\r\n\t\t\t\tLEFT Join remitentes AS r ON r.id_remitente = d.id_remitente\r\n\t\t\t\tLEFT Join tipos_documento AS td ON d.id_tipo_documento = td.id_tipo_documento\r\n\t\t\t\tWHERE \r\n\t\t\t\thd.id_area = '" . $_SESSION['session'][5] . "' \r\n\t\t\t\t" . $where . "\r\n\t\t\t\tUNION\r\n\t\t\t\tSELECT\r\n\t\t\t\tha.id_documento as id,\t\t\t\t\r\n\t\t\t\td.fecha_registro_documento as fecha,\r\n\t\t\t\td.asunto_documento as asunto,\r\n\t\t\t\td.codigo_documento as codigo,\r\n\t\t\t\ttd.nombre_tipo_documento as tipo,\r\n\t\t\t\tr.nombre_remitente as remitente,\r\n\t\t\t\tha.original_historial_atencion as categoria,\r\n\t\t\t\td.numero_documento as numero,\r\n\t\t\t\td.id_estado as id_estado,\r\n\t\t\t\te.abrev_nombre_estado as estado\r\n\t\t\t\tFROM\r\n\t\t\t\thistorial_atencion AS ha\r\n\t\t\t\tInner Join documentos AS d ON ha.id_documento = d.id_documento\r\n\t\t\t\tInner Join estados AS e ON d.id_estado = e.id_estado\r\n\t\t\t\tLEFT Join tipos_documento AS td ON d.id_tipo_documento = td.id_tipo_documento\r\n\t\t\t\tLEFT Join remitentes AS r ON d.id_remitente = r.id_remitente\r\n\t\t\t\tWHERE\r\n\t\t\t\t(\r\n\t\t\t\t(ha.id_area = '" . $_SESSION['session'][5] . "' AND ha.tipo_historial_atencion=0) OR\r\n\t\t\t\t(ha.id_area_destino = '" . $_SESSION['session'][5] . "' AND ha.tipo_historial_atencion=1) OR\r\n (ha.id_area_destino = '" . $_SESSION['session'][5] . "' AND ha.tipo_historial_atencion=2)\r\n\t\t\t\t) " . $where . "\r\n\t\t\t\tORDER BY id DESC,categoria"; $query_reg = new Consulta($sql_reg); } //Fin de if ide ?> <div class="ui-jqgrid ui-widget ui-widget-content ui-corner-all"> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" id="tabla_despacho" class="gview_frmgrid"> <tr> <td> <table width="100%" class="ui-jqgrid-htable" cellpadding="0" cellspacing="0"> <tr bgcolor="#6699CC" class="ui-widget-header ui-th-column grid_resize"> <th width="16%" class="ui-widget-header ui-th-column grid_resize">Reg. Nro</th> <th width="26%" class="ui-widget-header ui-th-column grid_resize">Remitente</th> <th width="26%" class="ui-widget-header ui-th-column grid_resize">Documento</th> <th width="13%" class="ui-widget-header ui-th-column grid_resize">Registrado</th> <th width="5%" class="ui-widget-header ui-th-column grid_resize">Estado</th> <th width="4%" class="ui-widget-header ui-th-column grid_resize">Cat</th> <th class="ui-widget-header ui-th-column grid_resize">Ubicacion</th> </tr> </table> </td> </tr> <tr class="ui-jqgrid-bdiv"> <td> <table id="frmgrid" width="100%" class="ui-jqgrid-btable" cellpadding="0" cellspacing="0"> <?php $codigo = ""; while ($row_reg = $query_reg->ConsultaVerRegistro()) { $ids = $row_reg["id"]; $estado = $row_reg["id_estado"]; $anterior = $codigo; $codigo = $row_reg["codigo"]; $cat = $row_reg["categoria"]; $loTengo = true; if ($codigo != $anterior) { if ($cat == 1) { if ($estado == 11 && $ide == "") { //No es un filtro y esta archivado $loTengo = false; // Para no mostrarlo } else { if ($_SESSION['session'][6] && $estado != 3 && $estado != 13 && $estado != 12 && $ide == "") { $loTengo = false; } elseif (!$_SESSION['session'][6] && ($estado == 3 || $estado == 13 || $estado == 12) && $ide == "") { $loTengo = false; } elseif ($estado == 3) { //Si es un despachado no pregunto si esta en mi area $doc = new Documento($ids); if ($doc->DespachoAreaTieneOriginal()) { $loTengo = true; } else { $loTengo = false; } } elseif ($estado == 4 || $estado == 13 || $estado == 12 || $estado == 6 || $estado == 16 || $estado == 17) { $total = 10; //Un numero Mayor a 0 para que tambien lo usen los otros estados if ($estado == 16 || $estado == 17) { $total = 0; $sql_hist = "SELECT Count(ha.id_historial_atencion) AS total\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\t\t\t\thistorial_atencion AS ha\r\n\t\t\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\t\t\tha.id_documento = {$ids}"; $query_hist = new Consulta($sql_hist); $row_hist = $query_hist->ConsultaVerRegistro(); $total = $row_hist["total"]; } //Si tiene historial se muestra en el area donde se quedo el ultimo original if ($total > 0) { $loTengo = false; $sql_destino = "SELECT ha.id_historial_atencion AS ultimo, \r\n\t\t\t\t\t\t\t\t\t\tha.tipo_historial_atencion,\r\n\t\t\t\t\t\t\t\t\t\tha.id_area,\r\n\t\t\t\t\t\t\t\t\t\tha.id_area_destino\r\n\t\t\t\t\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\t\t\t\t\thistorial_atencion AS ha\r\n\t\t\t\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\t\t\t\tha.id_documento=" . $ids . " AND\r\n\t\t\t\t\t\t\t\t\t\tha.original_historial_atencion=1\r\n\t\t\t\t\t\t\t\t\t\tORDER BY\r\n\t\t\t\t\t\t\t\t\t\t`ha`.`id_historial_atencion` DESC\r\n\t\t\t\t\t\t\t\t\t\tLIMIT 1"; $query_destino = new Consulta($sql_destino); $row_destino = $query_destino->ConsultaVerRegistro(); if ($row_destino["tipo_historial_atencion"] > 0 && $row_destino["id_area_destino"] == $_SESSION['session'][5]) { $loTengo = true; } elseif ($row_destino["tipo_historial_atencion"] == 0) { if ($row_destino["id_area"] == $_SESSION['session'][5]) { $loTengo = true; } } //Fin elseif } //Fin if //Si no tiene historial anteriormente fue despacho asi que se muestra siempre ($loTengo estaba en true) } //Fin if Verificacion de estados } //Fin if estado = 11 } else { $sql_arch = "SELECT\r\n\t\t\t\t\t\ta.id_documento\r\n\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\tarchivo_copia AS a\r\n\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\ta.id_documento = {$ids} AND\r\n\t\t\t\t\t\ta.id_area_duenia = " . $_SESSION['session'][5] . " \r\n\t\t\t\t\t\tAND\r\n\t\t\t\t\t\ta.id_usuario_duenio = 0"; $query_arch = new Consulta($sql_arch); if ($query_arch->NumeroRegistros() > 0) { if ($ide == "LT" || $ide == 11) { $loTengo = true; } else { $loTengo = false; } } } //Pregunto si mi area lo tiene if ($loTengo) { $clase = "Estilo7"; if ($estado == 12) { $clase = "Estilo7 fila_finalizada"; } else { $dias_faltantes = ObtenerDiasFaltantes($ids, date('d/m/Y', strtotime($row_reg['fecha']))); if ($dias_faltantes <= 0) { $clase = "Estilo7 fila_peligro"; } elseif ($dias_faltantes > 0 && $dias_faltantes <= 3) { $clase = "Estilo7 fila_urgente"; } else { $clase = "Estilo7 fila_baja"; } } $tooltip_asunto = ""; if (!empty($row_reg['asunto'])) { $tooltip_asunto = "title ='" . $row_reg['asunto'] . "' class='tip'"; } ?> <tr class="ui-widget-content1 jqgrow <?php echo $clase; ?> "> <td width="16%" <?php echo $tooltip_asunto; ?> > <div align="center"> <?php if ($estado == 11 && $cat == 1) { ?> <?php echo $row_reg['codigo']; ?> <?php } else { ?> <a href="areas_acceso_registro.php?opcion=despachar&ids=<?php echo $ids; ?> &cat=<?php echo $row_reg['categoria']; ?> "> <?php echo $row_reg['codigo']; ?> </a> <?php } ?> </div></td> <td width="26%"><input name="Input3" value="<?php echo $row_reg['remitente']; ?> " style="width:100%"/></td> <td width="26%"><input value="<?php echo $row_reg['numero']; ?> " style="width:100%"/></td> <td width="13%"> <div align="center"> <input type="text" value="<?php echo date('d/m/Y H:i', strtotime($row_reg['fecha'])); ?> " style="text-align:center;width:100%;"/> </div></td> <?php $tooltip = ""; if ($estado == 5) { $sql_des = "SELECT\r\n\t\t\t\t\t\t\td.id_devuelto AS ultimo,\r\n\t\t\t\t\t\t\td.descripcion AS descripcion\r\n\t\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\t\tdevuelto AS d\r\n\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\td.id_documento = '" . $ids . "'\r\n\t\t\t\t\t\t\tORDER BY\r\n\t\t\t\t\t\t\td.id_devuelto DESC\r\n\t\t\t\t\t\t\tLIMIT 1"; $query_des = new Consulta($sql_des); $row_des = $query_des->ConsultaVerRegistro(); if (!empty($row_des['descripcion'])) { $tooltip = "title ='" . $row_des['descripcion'] . "' class='tip'"; } } elseif ($estado == 11) { $sql_des = "SELECT\r\n\t\t\t\t\t\t\ta.id_archivo AS ultimo,\r\n\t\t\t\t\t\t\ta.descripcion AS descripcion\r\n\t\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\t\tarchivo AS a\r\n\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\ta.id_documento = '" . $ids . "'\r\n\t\t\t\t\t\t\tORDER BY\r\n\t\t\t\t\t\t\ta.id_archivo DESC\r\n\t\t\t\t\t\t\tLIMIT 1"; $query_des = new Consulta($sql_des); $row_des = $query_des->ConsultaVerRegistro(); if (!empty($row_des['descripcion'])) { $tooltip = "title ='" . $row_des['descripcion'] . "' class='tip'"; } } elseif ($estado == 16 || $estado == 17) { $doc_d_a = new Documento($row_reg['id']); $tooltip = "title ='" . $doc_d_a->ObtenerDescripcionUltimoOriginal($estado) . "' class='tip'"; } ?> <td align="center" <?php if ($cat == 1) { echo $tooltip; } ?> width="5%"> <div align="center"> <?php if ($cat == 1) { ?> <?php if ($estado == 11) { ?> <a href="javascript:QuitarArchivado(<?php echo $row_reg['id']; ?> )" id="desarchivar"> <?php echo $row_reg['estado']; ?> </a> <?php } elseif ($estado == 12) { ?> <a href="javascript:QuitarFinalizar(<?php echo $row_reg['id']; ?> )" id="nofinalizar"> <?php echo $row_reg['estado']; ?> </a> <?php } else { ?> <input type="text" value="<?php echo $row_reg['estado']; ?> " size="3" style="text-align:center; width:100%"/> <?php } ?> <?php } else { $doc = new Documento(); $estado = $doc->ObtenerEstadoCopia($ids, 1); ?> <input type="text" value="<?php echo $estado; ?> " size="3" style="text-align:center; width:100%"/> <?php } ?> </div> </td> <td align="center" width="4%"> <div align="center"> <input type="text" value="<?php echo $row_reg['categoria'] == '1' ? 'O' : 'C'; ?> " style=" width:20PX; text-align:center"/> </div> </td> <?php $sql_data = " SELECT a.abve_nombre_area\r\n\t\t\t\t\tFROM\r\n\t\t\t\t\tareas AS a \r\n\t\t\t\t\tWHERE\r\n\t\t\t\t\ta.id_area = '" . $_SESSION['session'][5] . "' "; $query_data = new Consulta($sql_data); $data = $query_data->ConsultaVerRegistro(); ?> <td> <?php if ($row_reg['categoria'] != 1) { $doc = new Documento(); $ubic = $doc->ObtenerUbicacionCopia($ids, 1); $area = $data['abve_nombre_area']; $tooltip_ubic = ""; if (count($ubic) > 0) { $cont = 0; foreach ($ubic as $u) { if ($cont == 0) { $tooltip_ubic = $tooltip_ubic . "{$area} - " . $u["destino"]; } else { $tooltip_ubic = $tooltip_ubic . "<br/>{$area} - " . $u["destino"]; } $cont++; } if (count($ubic) == 1) { ?> <input type="text" value="<?php echo $tooltip_ubic; ?> " style="width:95%"/> <?php } else { ?> <input type="text" value="<?php echo $area . "- Varios"; ?> " style="width:95%" title ='<?php echo $tooltip_ubic; ?> ' class='tip'/> <?php } } else { ?> <input type="text" value="<?php echo $area; ?> " style="width:95%"/> <?php } } elseif ($row_reg['id_estado'] == '3' || $row_reg['id_estado'] == '12' || $row_reg['id_estado'] == '16' || $row_reg['id_estado'] == '17') { ?> <input type="text" value="<?php echo $data['abve_nombre_area']; ?> " /> <?php } elseif ($row_reg['id_estado'] == '13') { $sql_area_derivado = "SELECT ha.id_historial_atencion AS ultimo, \r\n\t\t\t\t\t\t\t\ta.id_area AS area,\r\n\t\t\t\t\t\t\t\ta.abve_nombre_area AS abreviatura\t\r\n\t\t\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\t\t\thistorial_atencion AS ha\r\n\t\t\t\t\t\t\t\tInner Join areas AS a ON a.id_area = ha.id_area_destino\r\n\t\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\t\tha.id_documento=" . $ids . " and\r\n\t\t\t\t\t\t\t\tha.tipo_historial_atencion = 1 and\r\n\t\t\t\t\t\t\t\tha.original_historial_atencion = 1\r\n\t\t\t\t\t\t\t\tORDER BY\r\n\t\t\t\t\t\t\t\tultimo DESC\r\n\t\t\t\t\t\t\t\tLIMIT 1"; $query_area_derivado = new Consulta($sql_area_derivado); $row_area_derivado = $query_area_derivado->ConsultaVerRegistro(); ?> <input name="text" type="text" value="<?php echo $row_area_derivado["abreviatura"]; ?> " /> <?php } elseif ($row_reg['id_estado'] == '4' || $row_reg['id_estado'] == '18') { $sql_usu = "SELECT\r\n\t\t\t\t\t\t\tha.id_historial_atencion AS ultimo,\r\n\t\t\t\t\t\t\ta.abve_nombre_area AS abreviatura,\r\n\t\t\t\t\t\t\tu.login_usuario\r\n\t\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\t\thistorial_atencion AS ha\r\n\t\t\t\t\t\t\tInner Join areas AS a ON a.id_area = ha.id_area\r\n\t\t\t\t\t\t\tLEFT Join usuarios AS u ON u.id_usuario = ha.id_usuario_destino\r\n\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\tha.id_documento={$ids} and\r\n\t\t\t\t\t\t\t(ha.tipo_historial_atencion = 0 \r\n\t\t\t\t\t\t\tOR ha.tipo_historial_atencion = 5 \r\n\t\t\t\t\t\t\t)and\r\n\t\t\t\t\t\t\tha.original_historial_atencion = 1\r\n\t\t\t\t\t\t\tORDER BY\r\n\t\t\t\t\t\t\tultimo DESC\r\n\t\t\t\t\t\t\tLIMIT 1"; $query_usu = new Consulta($sql_usu); $usu = $query_usu->ConsultaVerRegistro(); ?> <input type="text" value="<?php echo $usu['abreviatura'] . ' - ' . $usu['login_usuario']; ?> " /> <?php } elseif ($row_reg['id_estado'] == '6') { $sql_usu = "SELECT\r\n\t\t\t\t\t\t\ta.abve_nombre_area AS abreviatura,\r\n\t\t\t\t\t\t\tu.login_usuario AS login_usuario\r\n\t\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\t\tborradores_respuesta AS b\r\n\t\t\t\t\t\t\tInner Join usuarios AS u ON u.id_usuario = b.id_destino\r\n\t\t\t\t\t\t\tInner Join areas AS a ON a.id_area = u.id_area \t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\tb.id_documento = '" . $ids . "' AND\r\n\t\t\t\t\t\t\tb.categoria = '1'\r\n\t\t\t\t\t\t\tORDER BY\r\n\t\t\t\t\t\t\tb.fecha_borrador_respuesta DESC\r\n\t\t\t\t\t\t\tLIMIT 1"; $query_usu = new Consulta($sql_usu); $usu = $query_usu->ConsultaVerRegistro(); ?> <input type="text" value="<?php echo $usu['abreviatura'] . ' - ' . $usu['login_usuario']; ?> " /> <?php } elseif ($row_reg['id_estado'] == '11') { $sql_usu = "SELECT\r\n\t\t\t\t\t\t\tar.abve_nombre_area\r\n\t\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\t\tarchivo AS a\r\n\t\t\t\t\t\t\tInner Join areas AS ar ON a.id_area = ar.id_area\r\n\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\ta.id_documento = '" . $ids . "'\r\n\t\t\t\t\t\t\tORDER BY a.id_archivo DESC\r\n\t\t\t\t\t\t\tLIMIT 1"; $query_usu = new Consulta($sql_usu); $usu = $query_usu->ConsultaVerRegistro(); ?> <input type="text" value="<?php echo $usu['abve_nombre_area']; ?> " /> <?php } ?> </td> </tr> <?php } //Fin de if categoria = 1 } //Fin de if anterior = codigo } //Fin de While ?> </table> </td> </tr> </table> </div> <?php }
function listado($ide = '', $dias = false) { $vencidos = false; $page = isset($_GET['pag']) && is_numeric($_GET['pag']) && $_GET['pag'] > 0 ? $_GET['pag'] - 1 : 0; $rows_per_page = 20; $area_session = $_SESSION['session'][5]; $field_dias_faltantes = "\r\n DATEDIFF( \r\n ADDDATE(d.fecha_registro_documento, \r\n p.tiempo_horas_respuesta_prioridad/24 ),\r\n CURDATE() \r\n )\r\n "; $fields_hd = "\r\n hd.id_documento as id,\r\n dr.id_documento_reporte as detalle_id,\r\n dr.ubicacion,\r\n d.fecha_registro_documento as fecha,\r\n d.asunto_documento as asunto,\r\n d.codigo_documento as codigo,\r\n td.nombre_tipo_documento as tipo,\r\n r.nombre_remitente as remitente,\r\n hd.original_historial_documento as categoria,\r\n d.numero_documento as numero,\r\n d.id_estado as id_estado,\r\n e.abrev_nombre_estado as estado,\r\n {$field_dias_faltantes} AS dias_faltantes\r\n "; $fields_ha = "\r\n ha.id_documento as id,\t\t\t\r\n dr.id_documento as detalle_id,\t\r\n dr.ubicacion,\r\n d.fecha_registro_documento as fecha,\r\n d.asunto_documento as asunto,\r\n d.codigo_documento as codigo,\r\n td.nombre_tipo_documento as tipo,\r\n r.nombre_remitente as remitente,\r\n ha.original_historial_atencion as categoria,\r\n d.numero_documento as numero,\r\n d.id_estado as id_estado,\r\n e.abrev_nombre_estado as estado,\r\n {$field_dias_faltantes} AS dias_faltantes\r\n "; if ($ide == '') { $where = "WHERE\r\n (((d.id_estado = '4' OR d.id_estado = '12' OR d.id_estado = '11' \r\n OR d.id_estado = '6' OR d.id_estado = '16' OR d.id_estado = '17' \r\n OR d.id_estado = '18' OR d.id_estado = '3' OR d.id_estado = '13' \r\n OR d.id_estado = '14' OR d.id_estado = '15')"; } else { if ($ide == "LT") { $where = "WHERE "; } else { if ($ide == "atencion") { $req = (object) $_REQUEST; $where = "WHERE d.id_estado NOT IN(11) "; $areas = new Areas(); $area_session = $areas->getIDs(); if (isset($req->remitente)) { $where .= "AND ( r.abreviatura_remitente like '%{$req->remitente}%' OR r.nombre_remitente like '%{$req->remitente}%' ) "; } if (isset($req->area) && $req->area) { $area_session = $req->area; } if (isset($req->pendientes)) { if (isset($req->area)) { $area_session = $req->area; #$where .= " AND $req->area LIKE CONCAT(dr.ubicacion,'%')"; } $where .= "AND d.id_estado IN (3,4,6,13,14,15,16,17,18) \r\n AND {$field_dias_faltantes} >=0\r\n "; } if (isset($req->atendidos)) { $where .= "AND d.id_estado IN (12) "; } else { $where .= "AND d.id_estado NOT IN (12) "; } if (isset($req->vencidos)) { $where .= "\r\n AND d.id_estado NOT IN (12) \r\n AND {$field_dias_faltantes} <0\r\n "; $vencidos = true; } } else { if (is_numeric($ide)) { $where = "AND d.id_estado = {$ide} "; } } } /* Tasks. Revisar Busaqueda de documento para mostrar detalle; PaginaciĆ³n. OrdenaciĆ³n por Encabezados */ } //Fin de if ide $select_historial = "\r\n SELECT\r\n {$fields_hd}\r\n FROM\r\n historial_documentos AS hd\r\n INNER JOIN \r\n documentos AS d ON d.id_documento = hd.id_documento\r\n INNER JOIN \r\n estados AS e ON e.id_estado = d.id_estado\r\n \t\t\tINNER JOIN\r\n\t\t\t\t\t\t\t\tprioridades AS p ON p.id_prioridad = d.id_prioridad\r\n LEFT JOIN \r\n remitentes AS r ON r.id_remitente = d.id_remitente\r\n LEFT JOIN \r\n tipos_documento AS td ON d.id_tipo_documento = td.id_tipo_documento\r\n \t INNER JOIN\r\n\t\t\t\t\t\t\t\tdocumentos_reporte as dr ON hd.id_documento = dr.id_documento \t\r\n {$where}\r\n " . ($where != 'WHERE ' ? "AND" : "") . "\r\n (( hd.original_historial_documento = 1) OR hd.original_historial_documento = 2 )\r\n AND hd.id_area IN ({$area_session})\r\n \r\n GROUP BY id\r\n "; $select_atencion = "\r\n SELECT\r\n {$fields_ha}\r\n FROM\r\n historial_atencion AS ha\r\n INNER JOIN \r\n documentos AS d ON ha.id_documento = d.id_documento\r\n INNER JOIN \r\n estados AS e ON d.id_estado = e.id_estado\r\n \t\t\tINNER JOIN\r\n prioridades AS p ON p.id_prioridad = d.id_prioridad\r\n LEFT JOIN \r\n tipos_documento AS td ON d.id_tipo_documento = td.id_tipo_documento\r\n LEFT JOIN \r\n remitentes AS r ON d.id_remitente = r.id_remitente\r\n \tINNER JOIN\r\n\t\t\t\t\t\t\t\tdocumentos_reporte as dr ON ha.id_documento = dr.id_documento \t\r\n {$where}\r\n " . ($where != 'WHERE ' ? "AND" : "") . "\r\n \r\n (( ha.original_historial_atencion = 1) OR ha.original_historial_atencion = 2 )\r\n AND(\r\n (ha.id_area IN ({$area_session}) AND ha.tipo_historial_atencion=0) OR\r\n (ha.id_area_destino IN ({$area_session}) AND ha.tipo_historial_atencion=1) OR\r\n (ha.id_area_destino IN ({$area_session}) AND ha.tipo_historial_atencion=2)\r\n )\r\n \r\n GROUP BY id\r\n "; $order_limit_sql = "\r\n ORDER BY \r\n dias_faltantes DESC, categoria ASC\r\n LIMIT " . $page * $rows_per_page . ",{$rows_per_page}\r\n "; $sql_reg = "\r\n ( {$select_historial} )\r\n UNION\r\n ( {$select_atencion} ) \r\n \r\n "; $query_reg = new Consulta($sql_reg . $order_limit_sql); $total_rows_query = new Consulta(" SELECT COUNT(*) FROM ( {$sql_reg} ) as total"); #echo $query_reg->SQL; $total_rows = $total_rows_query->getRow(); ?> <?php if ($total_rows > 0) { ?> <?php ob_start(); $total_pages = ceil($total_rows / $rows_per_page); $page++; if ($total_pages > 1) { ?> <div class="pagination"> <span>Total de páginas: </span><strong><?php echo $total_pages; ?> </strong> | <span for="toPage">Ir a Página:</span> <select id="toPage"> <?php for ($p = 1; $p <= $total_pages; $p++) { ?> <option <?php echo $p == $page ? 'selected="selected"' : ''; ?> value="<?php echo $p; ?> "> <?php echo $p; ?> </option> <?php } ?> </select> | <?php if ($page > 1) { ?> <a href="" class="1" >« Primera</a> <a href="" class="<?php echo $page - 1; ?> ">« Anterior</a> <?php } ?> <strong class="active">[Página <?php echo $page; ?> ]</strong> <?php if ($page < $total_pages) { ?> <a href="" class="<?php echo $page + 1; ?> ">Siguiente ></a> <a href="" class="<?php echo $total_pages; ?> ">Ultima »</a> <?php } ?> </div> <?php } $pagination = ob_get_contents(); ob_clean(); ?> <?php echo $pagination; ?> <div class="ui-jqgrid ui-widget ui-widget-content ui-corner-all"> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" id="tabla_despacho" class="gview_frmgrid"> <tr> <td> <table width="100%" class="ui-jqgrid-htable" cellpadding="0" cellspacing="0"> <tr bgcolor="#6699CC" class="ui-widget-header ui-th-column grid_resize"> <th width="16%" class="ui-widget-header ui-th-column grid_resize">Reg. Nro</th> <th width="26%" class="ui-widget-header ui-th-column grid_resize">Remitente</th> <th width="26%" class="ui-widget-header ui-th-column grid_resize">Documento</th> <th width="13%" class="ui-widget-header ui-th-column grid_resize">Registrado</th> <th width="5%" class="ui-widget-header ui-th-column grid_resize">Estado</th> <?php if ($dias) { ?> <th width="4%" class="ui-widget-header ui-th-column grid_resize">Dias</th> <?php } else { ?> <th width="4%" class="ui-widget-header ui-th-column grid_resize">Cat</th> <?php } ?> <th class="ui-widget-header ui-th-column grid_resize">Ubicacion</th> </tr> </table> </td> </tr> <tr class="ui-jqgrid-bdiv"> <td> <table id="frmgrid" width="100%" class="ui-jqgrid-btable" cellpadding="0" cellspacing="0"> <?php $codigo = ""; $count = 0; while ($row_reg = $query_reg->ConsultaVerRegistro()) { $count++; $ids = $row_reg["id"]; $detalle_id = $row_reg["detalle_id"]; $estado = $row_reg["id_estado"]; $anterior = $codigo; $codigo = $row_reg["codigo"]; $cat = $row_reg["categoria"]; $loTengo = true; if ($codigo != $anterior) { $clase = "Estilo7"; if ($estado == 12) { $clase = "Estilo7 fila_finalizada"; } else { $dias_faltantes = $row_reg['dias_faltantes']; if ($dias_faltantes <= 0) { $clase = "Estilo7 fila_peligro"; } elseif ($dias_faltantes > 0 && $dias_faltantes <= 3) { $clase = "Estilo7 fila_urgente"; } else { $clase = "Estilo7 fila_baja"; } } $tooltip_asunto = ""; if (!empty($row_reg['asunto'])) { $tooltip_asunto = "title ='" . $row_reg['asunto'] . "' class='tip'"; } ?> <tr class="ui-widget-content1 jqgrow <?php echo $clase; ?> "> <td width="16%" <?php echo $tooltip_asunto; ?> > <div align="center"> <a target="_blank" href="detalle_documento.php?id=<?php echo $detalle_id; ?> "> <?php echo $row_reg['codigo']; ?> </a> </div> </td> <td width="26%"><input name="Input3" value="<?php echo $row_reg['remitente']; ?> " style="width:100%"/></td> <td width="26%"><input value="<?php echo $row_reg['numero']; ?> " style="width:100%"/></td> <td width="13%"> <div align="center"> <input type="text" value="<?php echo date('d/m/Y H:i', strtotime($row_reg['fecha'])); ?> " style="text-align:center;width:100%;"/> </div></td> <?php $tooltip = ""; if ($estado == 5) { $sql_des = "SELECT\r\n d.id_devuelto AS ultimo,\r\n d.descripcion AS descripcion\r\n FROM\r\n devuelto AS d\r\n WHERE\r\n d.id_documento = '" . $ids . "'\r\n ORDER BY\r\n d.id_devuelto DESC\r\n LIMIT 1"; $query_des = new Consulta($sql_des); $row_des = $query_des->ConsultaVerRegistro(); if (!empty($row_des['descripcion'])) { $tooltip = "title ='" . $row_des['descripcion'] . "' class='tip'"; } } elseif ($estado == 11) { $sql_des = "SELECT\r\n a.id_archivo AS ultimo,\r\n a.descripcion AS descripcion\r\n FROM\r\n archivo AS a\r\n WHERE\r\n a.id_documento = '" . $ids . "'\r\n ORDER BY\r\n a.id_archivo DESC\r\n LIMIT 1"; $query_des = new Consulta($sql_des); $row_des = $query_des->ConsultaVerRegistro(); if (!empty($row_des['descripcion'])) { $tooltip = "title ='" . $row_des['descripcion'] . "' class='tip'"; } } elseif ($estado == 16 || $estado == 17) { $doc_d_a = new Documento($row_reg['id']); $tooltip = "title ='" . $doc_d_a->ObtenerDescripcionUltimoOriginal($estado) . "' class='tip'"; } ?> <td align="center" <?php if ($cat == 1) { echo $tooltip; } ?> width="5%"> <div align="center"> <?php if ($cat == 1) { ?> <?php if ($estado == 11) { ?> <a href="javascript:QuitarArchivado(<?php echo $row_reg['id']; ?> )" id="desarchivar"> <?php echo $row_reg['estado']; ?> </a> <?php } elseif ($estado == 12) { ?> <a href="javascript:QuitarFinalizar(<?php echo $row_reg['id']; ?> )" id="nofinalizar"> <?php echo $row_reg['estado']; ?> </a> <?php } else { ?> <input type="text" value="<?php echo $row_reg['estado']; ?> " size="3" style="text-align:center; width:100%"/> <?php } ?> <?php } else { $doc = new Documento(); $estado = $doc->ObtenerEstadoCopia($ids, 1); ?> <input type="text" value="<?php echo $estado; ?> " size="3" style="text-align:center; width:100%"/> <?php } ?> </div> </td> <?php if ($dias) { ?> <td align="center" width="4%"> <input type="text" value="<?php echo $dias_faltantes; ?> " style="text-align:center;width:30px;" /> </td> <?php } else { ?> <td align="center" width="4%"> <div align="center"> <input type="text" value="<?php echo $row_reg['categoria'] == '1' ? 'O' : 'C'; ?> " style=" width:20PX; text-align:center"/> </div> </td> <?php } ?> <?php $sql_data = " SELECT a.nombre_area, a.abve_nombre_area\r\n FROM\r\n areas AS a \r\n WHERE\r\n a.id_area IN ({$area_session}) "; $query_data = new Consulta($sql_data); $data = $query_data->ConsultaVerRegistro(); ?> <td title="DR[<?php echo $row_reg["ubicacion"]; ?> ] - HD <?php echo $data['nombre_area']; ?> "> <?php if ($row_reg['categoria'] != 1) { $doc = new Documento(); $ubic = $doc->ObtenerUbicacionCopia($ids, 1); $area = $data['abve_nombre_area']; $tooltip_ubic = ""; if (count($ubic) > 0) { $cont = 0; foreach ($ubic as $u) { if ($cont == 0) { $tooltip_ubic = $tooltip_ubic . "{$area} - " . $u["destino"]; } else { $tooltip_ubic = $tooltip_ubic . "<br/>{$area} - " . $u["destino"]; } $cont++; } if (count($ubic) == 1) { ?> <input type="text" value="<?php echo $tooltip_ubic; ?> " style="width:95%"/> <?php } else { ?> <input type="text" value="<?php echo $area . "- Varios"; ?> " style="width:95%" title ='<?php echo $tooltip_ubic; ?> ' class='tip'/> <?php } } else { ?> <input type="text" value="<?php echo $area; ?> " style="width:95%"/> <?php } } elseif ($row_reg['id_estado'] == '3' || $row_reg['id_estado'] == '12' || $row_reg['id_estado'] == '16' || $row_reg['id_estado'] == '17') { ?> <input type="text" value="<?php echo $data['abve_nombre_area']; ?> " /> <?php } elseif ($row_reg['id_estado'] == '13') { $sql_area_derivado = "SELECT ha.id_historial_atencion AS ultimo, \r\n a.id_area AS area,\r\n a.abve_nombre_area AS abreviatura\t\r\n FROM\r\n historial_atencion AS ha\r\n Inner Join areas AS a ON a.id_area = ha.id_area_destino\r\n WHERE\r\n ha.id_documento=" . $ids . " and\r\n ha.tipo_historial_atencion = 1 and\r\n ha.original_historial_atencion = 1\r\n ORDER BY\r\n ultimo DESC\r\n LIMIT 1"; $query_area_derivado = new Consulta($sql_area_derivado); $row_area_derivado = $query_area_derivado->ConsultaVerRegistro(); ?> <input name="text" type="text" value="<?php echo $row_area_derivado["abreviatura"]; ?> " title="<?php echo isset($usu['abve_nombre_area']) ? $usu['abve_nombre_area'] : ''; ?> " /> <?php } elseif ($row_reg['id_estado'] == '4' || $row_reg['id_estado'] == '18') { $sql_usu = "SELECT\r\n ha.id_historial_atencion AS ultimo,\r\n a.abve_nombre_area AS abreviatura,\r\n u.login_usuario\r\n FROM\r\n historial_atencion AS ha\r\n Inner Join areas AS a ON a.id_area = ha.id_area\r\n LEFT Join usuarios AS u ON u.id_usuario = ha.id_usuario_destino\r\n WHERE\r\n ha.id_documento={$ids} and\r\n (ha.tipo_historial_atencion = 0 \r\n OR ha.tipo_historial_atencion = 5 \r\n )and\r\n ha.original_historial_atencion = 1\r\n ORDER BY\r\n ultimo DESC\r\n LIMIT 1"; $query_usu = new Consulta($sql_usu); $usu = $query_usu->ConsultaVerRegistro(); ?> <input type="text" value="<?php echo $usu['abreviatura'] . ' - ' . $usu['login_usuario']; ?> " /> <?php } elseif ($row_reg['id_estado'] == '6') { $sql_usu = "SELECT\r\n a.abve_nombre_area AS abreviatura,\r\n u.login_usuario AS login_usuario\r\n FROM\r\n borradores_respuesta AS b\r\n Inner Join usuarios AS u ON u.id_usuario = b.id_destino\r\n Inner Join areas AS a ON a.id_area = u.id_area \t\t\t\t\t\t\t\r\n WHERE\r\n b.id_documento = '" . $ids . "' AND\r\n b.categoria = '1'\r\n ORDER BY\r\n b.fecha_borrador_respuesta DESC\r\n LIMIT 1"; $query_usu = new Consulta($sql_usu); $usu = $query_usu->ConsultaVerRegistro(); ?> <input type="text" value="<?php echo $usu['abreviatura'] . ' - ' . $usu['login_usuario']; ?> " /> <?php } elseif ($row_reg['id_estado'] == '11') { $sql_usu = "SELECT\r\n ar.abve_nombre_area\r\n FROM\r\n archivo AS a\r\n Inner Join areas AS ar ON a.id_area = ar.id_area\r\n WHERE\r\n a.id_documento = '" . $ids . "'\r\n ORDER BY a.id_archivo DESC\r\n LIMIT 1"; $query_usu = new Consulta($sql_usu); $usu = $query_usu->ConsultaVerRegistro(); ?> <input type="text" value="<?php echo $usu['abve_nombre_area']; ?> " /> <?php } ?> </td> </tr> <?php /* <tr class="ui-widget-content1 jqgrow <?=$clase?>"> <td colspan="6"><?dump($row_reg)?></td> </tr> */ ?> <?php } //Fin de if anterior = codigo } //Fin de While ?> </table> </td> </tr> </table> </div> <?php } else { ?> <div class="no_results"> No se han encontrado documentos... </div> <?php } }