<?php
   include("funciones/funciones_backup.php");   
   include("conexion/conexion.php");
   include("Menu/menu_inicio.php");
   include("logos.php"); 
   encabezado2($target);  
 	$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;
		  		}

class paginar{
function tam($orden, $id_mens, $tabla, $f1, $f2){
			if (!empty($f1) and !empty($f2)) $sql_add=" AND r.F13>='".$f1."' AND r.F13<'".$f2."' ";
			$this->userObj=new select_zonas();
			$sql="SELECT g.guia, g.orden, o.producto, g.empresa, g.destinatario, 
			  g.direccion, g.telefono, g.ciudad, date(o.fecha_creacion) as fecha_creacion  
			  FROM $tabla as g ";
			$add="  inner join rastreo_guias as r on (g.guia=r.guia)
				inner join ordenes as o on (g.orden=o.orden)
				inner join clientes as c on (o.id_cliente=c.id_cliente) 
				where g.orden = '$orden' AND 
				g.id_mensajero = '$id_mens'				
				".$sql_add." ";
			$row_paginar=$this->userObj->get_tam($sql,$add);
			return $row_paginar;
}

}
$paginarObj=new paginar();
$row_paginar=$paginarObj->tam($orden, $id_mens, $tabla, $f1, $f2);
$total_paginas= ceil($row_paginar/$tamano_pagina);

		unset($titulos);
		unset($query_nomina);
		$titulos[]="GUIA";
		$titulos[]="ODS";
		$titulos[]="FECHA";
		$titulos[]="PRODUCTO";
		$titulos[]="EMPRESA";
		$titulos[]="DESTINATARIO";
		$titulos[]="DIRECCION";
		$titulos[]="TELEFONO";
		$titulos[]="CIUDAD";
				
		if (!empty($f1) and !empty($f2)) $sql_add=" AND r.F13>='".$f1."' AND r.F13<'".$f2."' ";
		$query_pen_men="SELECT trim(g.guia), trim(g.orden), date(o.fecha_creacion), trim(o.producto), trim(g.empresa), trim(g.destinatario), 
			  trim(g.direccion), trim(g.telefono), trim(g.ciudad) 
			  FROM $tabla as g 
			    inner join rastreo_guias as r on (g.guia=r.guia)
				inner join ordenes as o on (g.orden=o.orden)
				inner join clientes as c on (o.id_cliente=c.id_cliente) 
				where o.tp_digita=1 and
				g.orden = '$orden' AND 
				g.id_mensajero = '$id_mens' AND 
				g.id_estado = '13' 
				".$sql_add." ";
		//echo $query_pen_men;
		$_SESSION['sql_nomina']=$query_pen_men;
		$_SESSION['titulos']=$titulos;

$paginanombre='VER DETALLE DE PENDIENTES DE LA ORDEN No '.$orden;

?>
<CENTER>
<table width="700" border="0" class="primaria">
<tr class=miTable_tr>
<td colspan="9" class=miTable_th1><div align="center">..:: <? echo $paginanombre;?> ::..</div></td>
</tr>
<tr class=miTable_tr>
<td colspan="9" class=miTable_th1><a href='xls_alfa.php'><img src='imagenes/xls_icon.gif'></a></td>
</tr>
<?
class pendiente_ods{

function detalle_guia($inicio,$tamano_pagina,$tabla,$orden,$id_mens,$f1,$f2){
    include("logos.php");
	 		  if (!empty($f1) and !empty($f2)) $sql_add=" AND r.F13>='".$f1."' AND r.F13<'".$f2."' ";
			  $this->conexionObj2=new conexion();
			  $this->conexionObj2->conectarse();
			  $rst_select_lotes=$this->conexionObj2->consultar("SELECT g.guia, g.orden, o.producto, g.empresa, g.destinatario, 
			  g.direccion, g.telefono, g.ciudad, date(o.fecha_creacion) as fecha_creacion 
			  FROM $tabla as g 
			    inner join rastreo_guias as r on (g.guia=r.guia)
				inner join ordenes as o on (g.orden=o.orden)
				inner join clientes as c on (o.id_cliente=c.id_cliente) 
				where o.tp_digita=1 and
				g.orden = '$orden' AND 
				g.id_mensajero = '$id_mens' AND 
				g.id_estado = '13' 
				".$sql_add."
				LIMIT $inicio,$tamano_pagina");
				
		  
			  echo "<tr class=miTable_tr>";
					echo "<td width=60 valign=top class=miTable_th1> $Tguia </td>";
					echo "<td width=60 valign=top class=miTable_th1>$Torden</td>";
					echo "<td width=60 valign=top class=miTable_th1>FECHA</td>";
					echo "<td width=140 valign=top class=miTable_th1>$Tdestinatario</td>";
					echo "<td width=140 valign=top class=miTable_th1>$Tdireccion</td>";
					echo "<td width=60 valign=top class=miTable_th1>$Ttelefono</td>";
					echo "<td width=80 valign=top class=miTable_th1>$Tciudad</td>";
					echo "<td width=100 valign=top class=miTable_th1>$Tproducto</td>";
					echo "<td width=140 valign=top class=miTable_th1>$Tempresa</td></tr>";
					
			  while($row_select_lotes=mysql_fetch_array($rst_select_lotes)){
			  		echo "<tr class=miTable_tr>";
					echo "<td valign=top class=miTable_td>".$row_select_lotes['guia']."</td>";
					echo "<td valign=top class=miTable_td>".$row_select_lotes['orden']."</td>";
					echo "<td valign=top class=miTable_td>".$row_select_lotes['fecha_creacion']."</td>";
					echo "<td valign=top class=miTable_td>".$row_select_lotes['destinatario']."</td>";
					echo "<td valign=top class=miTable_td>".$row_select_lotes['direccion']."</td>";
					echo "<td valign=top class=miTable_td>".$row_select_lotes['telefono']."</td>";
					echo "<td valign=top class=miTable_td>".$row_select_lotes['ciudad']."</td>";
					echo "<td valign=top class=miTable_td>".$row_select_lotes[2]."</td>";
					echo "<td valign=top class=miTable_td>".$row_select_lotes['empresa']."</td></tr>";

			  }
			  
	 }
}
$pendiente_odsObj=new pendiente_ods();
$pendiente_odsObj->detalle_guia($inicio,$tamano_pagina,$tabla,$orden,$id_mens,$f1,$f2);
?>
<tr><td valign=top class=miTable_td colspan=9>
<div align="center">
<?
if($total_paginas>1)
		{   echo "Paginas:";
			$start = ( $pagina-5 > 0 ? $pagina-5  : 1 );
			if ($start > 1 ){
				print "&nbsp;<a href='accion_pendientes.php?pagina=".($start-1)."&tabla=$tabla&orden=$orden&id_mens=$id_mens&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='accion_pendientes.php?pagina=".($start+$i)."&tabla=$tabla&orden=$orden&id_mens=$id_mens&f1=$f1&f2=$f2'>". ($start+$i)." </A>";
				}
		   	}
			if($start+$i < $total_paginas){
			    print "&nbsp;&nbsp;<a href='accion_pendientes.php?pagina=".($start+$i)."&tabla=$tabla&orden=$orden&id_mens=$id_mens&f1=$f1&f2=$f2'> >> </A>";

			}
		 
		 }
?>
</div>
</td></tr>
<tr><td valign=top class=miTable_th1 colspan=9></td></tr>
</table>
</CENTER>
<?
	echo"<table width=300 border=0 align=center cellpadding=0 cellspacing=0>";
    echo"<tbody><tr>";
    echo"<td></td>";
    echo"</tr>";
	echo"<tr>";
?>
<td>
<CENTER>
<?
        pie_de_pagina();
        ?>
</CENTER>
</td>
	<?php
   echo"</tr>";
   echo"</tbody></table>";
   echo"</body>";
   echo"</html>";
?>