<?php
include("funciones/funciones_backup.php");
include("conexion/conexion.php");
include("Menu/menu_inicio.php");
include("Usuarios/mensajeros.php");
unset($titulos);
unset($query_expor);
unset($_SESSION['cadena_csv']);
unset($_SESSION['nombcsv']);
$fecha_actual = date("Y-m-d");
$_SESSION['cadena_csv']= "ID;NOMBRE;CC;PLANILLADAS;ENTREGADAS;DEVOLUCION;PENDIENTES";
$_SESSION['cadena_csv'] = substr($_SESSION['cadena_csv'], 0, -1);
$_SESSION['cadena_csv'] .=chr(13).chr(10);
$_SESSION['nombcsv']='ConsultaMensajeros_' . $fecha_actual . '.csv';


$conexionObj2 = new conexion();
$conexionObj2->conectarse();
$nombrepagina = "GENERAL DE MENSAJEROS";
encabezado($target);
$user = $_SESSION['validar'];
$tamano_pagina = 20;
$_SESSION['tam'] = $tamano_pagina;
$pagina = $_GET["pagina"];
if (!$pagina) {
    $inicio = 0;
    $_SESSION['inicio'] = $inicio;
    $pagina = 1;
} else {
    $inicio = ($pagina - 1) * $tamano_pagina;
    $_SESSION['inicio'] = $inicio;
}
$filas = 1;
if ($filas == 1) {

    class llamado {

        var $menuObj;

        function validar1($id_user, $id_sucursal) {
            $this->menuObj = new menu_inicio();
            $this->menuObj->menu2($id_user, $id_sucursal);
        }

    }

    $llamadoObj = new llamado();
    $llamadoObj->validar1($_GET['id_user'], $_GET['suc']);
    entrada($user, $_GET['id_user'], $_GET['suc']);
    echo"</td>";
    echo"<td width=79% background=\"imagenes/bg3.jpg\" valign=top>";
    mostrar_cabeza_trabajo($nombrepagina);
    
    $perfil = $_SESSION['perfil'];
    
    if($f1==$f2){
        $add = "WHERE date(r.F13)='" . $f1 . "'";
    }else{
        $add = "WHERE date(r.F13)>='" . $f1 . "' AND date(r.F13)<='" . $f2 . "' ";
    }

    class filas {

        var $rowsobj;

        function cantidad($sql_consulta) {
            $this->userObj = new select_zonas();
            $cant = $this->userObj->get_filas($sql_consulta);
            return $cant;
        }

        function arreglo($sql_consulta) {
            $this->userObj = new select_zonas();
            $array = $this->userObj->get_array($sql_consulta);
            return $array;
        }

        function eliminar($perfil, $f1, $f2, $tabla) {
            $tamano_pagina = $_SESSION['tam'];
            $inicio = $_SESSION['inicio'];
            $this->userObj = new select_zonas();
            $this->userObj->lista_mensajero_p($inicio, $tamano_pagina, $_GET['suc'], $perfil, $f1, $f2, $tabla);
        }

    }

    $filasobj = new filas();
    ?>
    <form action="" method="POST" name="backup">
        <CENTER>
            <table width="400" border="0" class="primaria">
                <tr class=miTable_tr>
                    <td colspan="10" class=miTable_th1><div align="center">..:: Mensajeros ::..</div></td>
                </tr>
<tr class=miTable_tr>
    <td colspan="10" class=miTable_td><center><a href='pendientes_general.php?id_user=<?echo $_GET['id_user']?>&suc=<?echo $_GET['suc']?>' class='mainlevel'><b>REGRESAR</b></a></center></td>
</tr>
                <tr class=miTable_tr>
                    <td colspan="9" class=miTable_th1 valign="middle">Desde: <? echo $f1; ?> Hasta: <? echo $f2; ?>
                    </td>
                </tr>
            
                    <tr class="miTable_tr" align="center">
                    <td colspan='10' class="miTable_td">
                <center>
                    <a href='guarda_csv.php' title='Exportar CSV'>Exportar Csv<img src='imagenes/txt_icon.gif'></a>
                </center>
                </td>
                </table>
                <div style='overflow-x:scroll;overflow-y:scroll;width:720px;height:400px'>
                <table border='0' width='720' class='primaria'>
                <tr class="miTable_tr">
                    <td valign=top class=miTable_th1 width="30">Id</td>
                    <td valign=top class=miTable_th1 width="210">Nombre</td>
                    <td valign=top class=miTable_th1 width="80">C.C.</td>
                    <td valign=top class=miTable_th1  width="80">Planilladas</td>
                    <td valign=top class=miTable_th1  width="80">Entregadas</td>
                    <td valign=top class=miTable_th1  width="80">Devolucion</td>
                    <td valign=top class=miTable_th1  width="80">Pendientes</td>
                </tr>
                <?
                $rst_select_lotes = $conexionObj2->consultar("SELECT SQL_CALC_FOUND_ROWS m.id_mensajero, m.nombre, m.identificacion, count(g.guia)
			  			FROM guias_proceso as g 
						inner join mensajeros as m on (g.id_mensajero=m.id_mensajero)
						inner join rastreo_guias as r on (g.guia=r.guia) 
						$add group by g.id_mensajero");
                $rsTotal = $conexionObj2->consultar("SELECT FOUND_ROWS() as total");
                $rowTotal = mysql_fetch_assoc($rsTotal);                
                $cant = $rowTotal["total"];
                $x=1;
                $total_paginas = ceil($cant / $tamano_pagina);

                ?>
                 <form name="<? echo $Nform; ?>" method="POST" action='ver_pendiente_general.php' target="_blank">
                          <input type='hidden' value="0" name='id_est'>                                                            
                        <a href='javascript:document.<? echo $Nform; ?>.submit();'>                            
                        </a>                                    
                    </form>        
<?
                while ($row_select_lotes = mysql_fetch_array($rst_select_lotes)) {
                    $x++;
                    echo "<tr class=miTable_tr>";
                    echo "<td valign=top class=miTable_td>" . $row_select_lotes[0] . "</td>";
                    echo "<td valign=top class=miTable_td nowrap>" . $row_select_lotes[1] . "</td>";
                    echo "<td valign=top class=miTable_td>" . $row_select_lotes[2] . "</td>";
                    echo "<td valign=top class=miTable_td>";
                    $TotPl = $TotPl + $row_select_lotes[3];
                    $Nform="Plan_".$x;
                    $_SESSION['cadena_csv'].=$row_select_lotes[0].';'.$row_select_lotes[1].';'.$row_select_lotes[2].';'.$row_select_lotes[3].';';
                    ?>
<!--                    <form name="<? echo $Nform; ?>" method="POST" action='ver_pendiente_general.php' target="_blank">
                        <input type='hidden' value="<? echo $_GET['id_user']; ?>" name='id_user'>
                        <input type='hidden' value="<? echo $_GET['suc']; ?>" name='suc'>
                        <input type='hidden' value="<? echo $row_select_lotes[0]; ?>" name='id_mens'>
                        <input type='hidden' value="<? echo $row_select_lotes[1]; ?>" name='nom_mens'>                                    
                        <input type='hidden' value="<? echo $f1; ?>" name='f1'>                                    
                        <input type='hidden' value="<? echo $f2; ?>" name='f2'>                                    
                        <input type='hidden' value="0" name='id_est'>                                                            
                        <a href='javascript:document.<? echo $Nform; ?>.submit();'>-->
                            <? echo $row_select_lotes[3]; ?>
<!--                        </a>                                    
                    </form>                                                            -->
                    <?
                    echo "</td>";
                    ///////////////Entregas
                    $IdMsj = $row_select_lotes[0];
                    $StrSql = "select count(*) from guias_proceso as a inner join rastreo_guias as r on a.guia=r.guia
                        $add and a.id_mensajero='" . $IdMsj . "' and a.id_estado in(14,15)";
                    $rst_entregas = $conexionObj2->consultar($StrSql);
                    $row_entregas = mysql_fetch_array($rst_entregas);
                    echo "<td valign=top class=miTable_td>";
                    $TotEnt = $TotEnt + $row_entregas[0];
                    $_SESSION['cadena_csv'].=$row_entregas[0].';';
                    $Nform="Ent_".$x;
                    ?>
<!--                        <form name="<? echo $Nform; ?>" method="POST" action='ver_pendiente_general.php' target="_blank">
                        <input type='hidden' value="<? echo $_GET['id_user']; ?>" name='id_user'>
                        <input type='hidden' value="<? echo $_GET['suc']; ?>" name='suc'>
                        <input type='hidden' value="<? echo $row_select_lotes[0]; ?>" name='id_mens'>
                        <input type='hidden' value="<? echo $row_select_lotes[1]; ?>" name='nom_mens'>                                    
                        <input type='hidden' value="<? echo $f1; ?>" name='f1'>                                    
                        <input type='hidden' value="<? echo $f2; ?>" name='f2'>                                    
                        <input type='hidden' value="14" name='id_est'>                                                            
                        <a href='javascript:document.<? echo $Nform; ?>.submit();'>-->
                            <? echo $row_entregas[0]; ?>
<!--                        </a>                                    
                    </form>                                                            -->
                    <?
                    echo "</td>";
                    /////////////////////Devoluciones                
                    $StrSql = "select count(*) from guias_proceso as a inner join rastreo_guias as r on a.guia=r.guia
                        $add and a.id_mensajero='" . $IdMsj . "' and a.id_estado='16'";
                    $rst_devol = $conexionObj2->consultar($StrSql);
                    $row_devol = mysql_fetch_array($rst_devol);
                    $TotDev = $TotDev + $row_devol[0];
                    $_SESSION['cadena_csv'].=$row_devol[0].';';
                    echo "<td valign=top class=miTable_td>";
                    $Nform="Devol_".$x;
                    ?>                    
<!--                        <form name="<? echo $Nform; ?>" method="POST" action='ver_pendiente_general.php' target="_blank">
                        <input type='hidden' value="<? echo $_GET['id_user']; ?>" name='id_user'>
                        <input type='hidden' value="<? echo $_GET['suc']; ?>" name='suc'>
                        <input type='hidden' value="<? echo $row_select_lotes[0]; ?>" name='id_mens'>
                        <input type='hidden' value="<? echo $row_select_lotes[1]; ?>" name='nom_mens'>                                    
                        <input type='hidden' value="<? echo $f1; ?>" name='f1'>                                    
                        <input type='hidden' value="<? echo $f2; ?>" name='f2'>                                    
                        <input type='hidden' value="16" name='id_est'>                                                            
                        <a href='javascript:document.<? echo $Nform; ?>.submit();'>-->
                            <? echo $row_devol[0]; ?>
<!--                        </a>                                    
                    </form>                    -->
        <?
        echo "</td>";
        /////////////////////////Pendientes                
        $StrSql = "select count(*) from guias_proceso as a inner join rastreo_guias as r on a.guia=r.guia
                $add and a.id_mensajero='" . $IdMsj . "' and a.id_estado='13'";
        $rst_pen = $conexionObj2->consultar($StrSql);
        $row_pen = mysql_fetch_array($rst_pen);
        $TotPen = $TotPen + $row_pen[0];
        $_SESSION['cadena_csv'].=$row_pen[0].';';
        $Nform="Pendientes_".$x;
        echo "<td valign=top class=miTable_td>";
        ?>
<!--                    <form name="<? echo $Nform; ?>" method="POST" action='ver_pendiente_general.php' target="_blank">
                        <input type='hidden' value="<? echo $_GET['id_user']; ?>" name='id_user'>
                        <input type='hidden' value="<? echo $_GET['suc']; ?>" name='suc'>
                        <input type='hidden' value="<? echo $row_select_lotes[0]; ?>" name='id_mens'>
                        <input type='hidden' value="<? echo $row_select_lotes[1]; ?>" name='nom_mens'>                                    
                        <input type='hidden' value="<? echo $f1; ?>" name='f1'>                                    
                        <input type='hidden' value="<? echo $f2; ?>" name='f2'>                                    
                        <input type='hidden' value="13" name='id_est'>                                                            
                        <a href='javascript:document.<? echo $Nform; ?>.submit();'>-->
                            <? echo $row_pen[0]; ?>
<!--                        </a>                                    
                    </form>-->
        <?
        echo "</td>";
        $_SESSION['cadena_csv'] = substr($_SESSION['cadena_csv'], 0, -1);
        $_SESSION['cadena_csv'] .=chr(13).chr(10);        
    }
    ?>
                </tr>
                <tr class=miTable_tr>
                    <td class=miTable_th1 colspan="8">
                        <!--<div align="right"> Total: </div>
                        </td>
                        <td class=miTable_th1>
                        <? echo $TotPl; ?>
                        </td>
                        
                        <td class=miTable_th1>
    <? echo $TotEnt; ?>
                        </td>
                        
                        <td class=miTable_th1>
                            <? echo $TotDev; ?>
                        </td>
                        
                        <td class=miTable_th1>
                            <? echo $TotPen; ?>
                        </td>-->


                </tr>
<!--                <tr class=miTable_tr>
                    <td class=miTable_td colspan="9">
                        <div align="center">
                            <?
                            $id_user = $_GET['id_user'];
                            $id_sucursal = $_GET['suc'];
                            if ($total_paginas > 1) {
                                echo "Paginas:";
                                $start = ( $pagina - 5 > 0 ? $pagina - 5 : 1 );
                                if ($start > 1) {
                                    print "&nbsp;<a href='pendientes_mensajeros.php?pagina=" . ($start - 1) . "&id_user=$id_user&suc=$id_sucursal&tabla=$tabla&f1=$f1&f2=$f2'> << </A>";
                                }
                                for ($i = 0; $i < 10 && $total_paginas >= $start + $i; $i++) {
                                    if ($pagina == $start + $i) {
                                        print "&nbsp;&nbsp;" . ($start + $i);
                                    } else {
                                        print "&nbsp;&nbsp;<a href='pendientes_mensajeros.php?pagina=" . ($start + $i) . "&id_user=$id_user&suc=$id_sucursal&tabla=$tabla&f1=$f1&f2=$f2'>" . ($start + $i) . " </A>";
                                    }
                                }
                                if ($start + $i < $total_paginas) {
                                    print "&nbsp;&nbsp;<a href='pendientes_mensajeros.php?pagina=" . ($start + $i) . "&id_user=$id_user&suc=$id_sucursal&tabla=$tabla&f1=$f1&f2=$f2'> >> </A>";
                                }
                            }
                            ?>
                        </div>
                    </td>
                </tr>-->
<!--                <tr class=miTable_tr>
                    <td class=miTable_th1 colspan="9">
                        <DIV align="center">
                            Ir a la pagina
                            <input type='text' name='pagina' value='' size="5" class="inputbox">
                            <input type='hidden' name='id_user' value='<? echo $id_user ?>'>
                            <input type='hidden' name='suc' value='<? echo $id_sucursal ?>'>
                            <input type='hidden' name='tabla' value='<? echo $tabla ?>'>
                            <input type='hidden' name='f1' value='<? echo $f1 ?>'>
                            <input type='hidden' name='f2' value='<? echo $f2 ?>'>
                            <input type='submit' name='' value='Ir' class="inputbox">
                        </DIV>
                    </td>
                </tr>-->
            </table>

            <?
            mostrar_pie();
        }
        echo"</td>";
        echo"</tr>";
        echo"</table>";
        echo"<table width=503 border=0 align=center cellpadding=0 cellspacing=0>";
        echo"<tbody><tr>";
        echo"<td></td>";
        echo"</tr>";
        echo"<tr>";
        echo"<td height=7 background=imagenes/lineas_pie.jpg><img src=index2_files/spacer.html width=1 height=15></td>";
        echo"</tr>";
        echo"<tr>";
        ?><td><center>
<? pie_de_pagina(); ?>
        </center></td>
<?php
echo"</tr>";
echo"</tbody></table>";
echo"</center>";
echo"</body>";
echo"</html>";
?>
    </CENTER>
</form>
