<?php
$target = 'pagina';
include("funciones/funciones_backup.php");
include("conexion/conexion.php");
include("Menu/menu_inicio.php");
include("Ordenes/ordenes.php");
include("logos.php");

$nombrepagina = "REPORTE DE REENVIOS";
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;

        //var
        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 (!empty($f2))
        $f2 = $fec_lim = sumaDia($f2, 1);
    if ($perfil == 1) {
        $add = "where date(F17)>='" . $f1 . "' and date(F17)<='" . $f2 . "' group by t.guia ORDER BY t.orden DESC";
    } else {
        $add = "where date(F17)>='" . $f1 . "' and date(F17)<='" . $f2 . "' group by t.guia ORDER BY t.orden DESC";
        ////pendiente filtrar por sucursal.
    }

    $sql_reenvios = "SELECT *FROM guias_proceso as t inner join reenvio as b on (t.guia=b.guia)" . "$add";

    $_SESSION['header'] = 'GUIA;ORDEN;FECHA CARGUE;DESTINATARIO;DIRECCION;FECHA ENTREGA;CIUDAD';
    $_SESSION['campos_consulta'] = "trim(t.guia) as guia,trim(t.orden) as orden,fecha_cargue,trim(t.destinatario) as destinatario,trim(t.direccion) as direccion,
                especial5,trim(t.ciudad)as ciudad ";
    $_SESSION['sadd1'] = "as t inner join reenvio as r on t.guia=r.guia " . $add;

    
    class filas {

        var $rowsobj;

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

    }

    $filasobj = new filas();
    $filas = $filasobj->cantidad($sql_reenvios);
    $total_paginas = ceil($filas / $tamano_pagina);
    ?>
    <style type="text/css">
        td.comment{
            padding:0pt;
            padding-bottom:0pt;
            margin:0pt;  
        }

        .comment{

            margin:0pt;	

            width:700px;
            height:auto !important;
            overflow:scroll !important;

        }

    </style>
    <form action=" " method="GET" name="backup">
        <CENTER>
            <table width="780" border="0" class="primaria">

                <tr class=miTable_tr>
                    <!--<td colspan="11" class=miTable_td><a href='xls_alfa.php'>Exportar a Excel <img src='imagenes/xls_icon.gif'/></a></td>-->
    <? $nombcsv = 'Reenvios_' . "_" . date('Ymd'); ?>
                <a href='export_csv_query.php?nomcsv=<? echo $nombcsv; ?>&registro=2&estado=T&dev=6' title='Exportar CSV'>Exportar Csv<img src='imagenes/txt_icon.gif'></a>
                </tr>
                
                
                <tr class=miTable_tr>
                    <td colspan="12" class=miTable_th1><div align="center">..:: Guias con Reenvios ::..</div></td>
                </tr>
            </table>
            <table width="667"  border="0" class="primaria">
                <tr class="miTable_tr">

                    <td valign=top class=miTable_th1 width="40"><? echo $Tguia ?></td>
                    <td valign=top class=miTable_th1 width='65'><? echo $Trastreo ?></td>
                    <td valign=top class=miTable_th1 width="40"><? echo $Testado ?></td>
                    <td valign=top class=miTable_th1 width="40"><? echo $Torden ?></td>
                    <td valign=top class=miTable_th1  nowrap>FECHA CARGUE</td>                    
                    <td valign=top class=miTable_th1 width="170"><? echo $Tdestinatario ?></td>
                    <td valign=top class=miTable_th1 width="60"><? echo $Tdireccion ?></td>
                    <td valign=top class=miTable_th1 nowrap><? echo $Tespecial5 ?></td>                    
                    <td valign=top class=miTable_th1 width="200"><? echo $Tciudad ?></td>                   
                    <?
//if(!empty($Tespecial1)){
//	echo "<td valign=top class=miTable_th1 width='65'>".$Tespecial1."</td>";
//}
//if(!empty($Tespecial2)){
//	echo "<td valign=top class=miTable_th1 width='65'>".$Tespecial2."</td>";
//}
//if(!empty($Tespecial3)){
//	echo "<td valign=top class=miTable_th1 width='65'>".$Tespecial3."</td>";
//}
//if(!empty($Tespecial4)){
//	echo "<td valign=top class=miTable_th1 width='65'>".$Tespecial4."</td>";
//}
//if(!empty($Tespecial5)){
//	echo "<td valign=top class=miTable_th1 width='65'>".$Tespecial5."</td>";
//}
                    echo "</tr>";

                    class elimina {

                        var $userObj;

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

                    }

                    $eliminaObj = new elimina();
                    $eliminaObj->eliminar($orden, $tabla, $campo, $f1, $f2);
                    ?>
                </tr>
                <tr class=miTable_tr>
                    <td class=miTable_td colspan="12">
                        <div align="center">
                            <?
                            $id_user = $_GET['id_user'];
                            $id_sucursal = $_GET['suc'];
                            if ($total_paginas > 1) {
                                echo "Paginas:";
                                //echo "&nbsp;&nbsp;"; 
                                $start = ( $pagina - 5 > 0 ? $pagina - 5 : 1 );
                                if ($start > 1) {
                                    print "&nbsp;<a href=ver_reenvios.php?pagina=" . ($start - 1) . "&id_user=$id_user&suc=$id_sucursal&orden=$orden&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='ver_reenvios.php?pagina=" . ($start + $i) . "&id_user=$id_user&suc=$id_sucursal&orden=$orden&tabla=$tabla&f1=$f1&f2=$f2'>" . ($start + $i) . " </A>";
                                    }
                                }
                                if ($start + $i < $total_paginas) {
                                    print "&nbsp;&nbsp;<a href='ver_reenvios.php?pagina=" . ($start + $i) . "&id_user=$id_user&suc=$id_sucursal&orden=$orden&tabla=$tabla&f1=$f1&f2=$f2'> >> </A>";
                                }
                            }
                            ?>

                    </td>
                </tr>
                <tr class=miTable_tr>
                    <td class=miTable_th1 colspan="12">
                        <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='orden' value='<? echo $orden ?>'>
                            <input type='hidden' name='tabla' value='<? echo $tabla ?>'>
                            <input type='submit' name='' value='Ir' class="inputbox">
                        </DIV>
                    </td>
                </tr>
            </table>
            </div>

            <?
            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>