Пример #1
0
    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&aacute;ginas: </span><strong><?php 
                echo $total_pages;
                ?>
</strong> | 
            
            <span for="toPage">Ir a P&aacute;gina:</span>
            <select id="toPage">
                <?php 
                for ($p = 1; $p <= $total_pages; $p++) {
                    ?>
                <option <?php 
                    echo $p == $page ? 'selected="selected"' : '';
                    ?>
 value="<?php 
                    echo $p;
                    ?>
">&nbsp;&nbsp;<?php 
                    echo $p;
                    ?>
 </option>
                <?php 
                }
                ?>
            </select>
             |  
            <?php 
                if ($page > 1) {
                    ?>
            <a href="" class="1" >&laquo; Primera</a> 
            <a href="" class="<?php 
                    echo $page - 1;
                    ?>
">&laquo; Anterior</a> 
            <?php 
                }
                ?>
            <strong class="active">[P&aacute;gina <?php 
                echo $page;
                ?>
]</strong>
            <?php 
                if ($page < $total_pages) {
                    ?>
            <a href="" class="<?php 
                    echo $page + 1;
                    ?>
">Siguiente &gt</a> 
            <a href="" class="<?php 
                    echo $total_pages;
                    ?>
">Ultima &raquo;</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 
        }
    }