<?php
   include("funciones/funciones_backup.php");   
   include("conexion/conexion.php");
   include("Menu/menu_inicio.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_suc, $tabla, $f1, $f2){
			$this->userObj=new select_zonas();
			$sql="SELECT g.guia, g.orden, o.producto, g.empresa, g.destinatario, g.direccion, g.telefono, g.ciudad, o.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 sucursales as s on (o.id_sucursal=s.id_sucursal)
				inner join clientes as c on o.id_cliente=c.id_cliente
				WHERE g.orden = '$orden' AND g.id_sucursal = '$id_suc' AND g.id_estado = '13'
				AND r.F13>='$f1' AND r.F13<'$f2'";
			//echo $sql.$add;
			echo "<br>";
			$row_paginar=$this->userObj->get_tam($sql,$add);
			return $row_paginar;
}

}
$paginarObj=new paginar();
$row_paginar=$paginarObj->tam($orden, $id_suc, $tabla,$f1,$f2);			
$total_paginas= ceil($row_paginar/$tamano_pagina);
$paginanombre='VER DETALLE DE PENDIENTES DE LA ORDEN No '.$orden;

		unset($titulos);
		unset($query_nomina);
		$titulos[]="GUIA";
		$titulos[]="ODS";
		$titulos[]="FECHA";
		$titulos[]="EMPRESA";
		$titulos[]="DESTINATARIO";
		$titulos[]="DIRECCION";
		$titulos[]="TELEFONO";
		$titulos[]="CIUDAD";
		$titulos[]="PRODUCTO";
		
		
		$query_pen="SELECT g.guia, g.orden, o.fecha_creacion , g.empresa, g.destinatario, g.direccion, g.telefono, 
					g.ciudad, o.producto
				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 sucursales as s on (o.id_sucursal=s.id_sucursal)
				inner join clientes as c on o.id_cliente=c.id_cliente  
				WHERE g.orden = '$orden' AND g.id_sucursal = '$id_suc' AND g.id_estado = '13' AND
				r.F13>='$f1' AND r.F13<'$f2' ";
		$_SESSION['sql_nomina']=$query_pen;
		$_SESSION['titulos']=$titulos;
?>
<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_suc,$f1,$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, o.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 sucursales as s on (o.id_sucursal=s.id_sucursal)
				inner join clientes as c on o.id_cliente=c.id_cliente  
				WHERE g.orden = '$orden' AND g.id_sucursal = '$id_suc' AND g.id_estado = '13' AND
				r.F13>='$f1' AND r.F13<='$f2' LIMIT $inicio,$tamano_pagina");
			  echo "<tr class=miTable_tr>";
					echo "<td width=60 valign=top class=miTable_th1>GUIA</td>";
					echo "<td width=60 valign=top class=miTable_th1>ODS</td>";
					echo "<td width=60 valign=top class=miTable_th1>FECHA</td>";
					echo "<td width=140 valign=top class=miTable_th1>EMPRESA</td>";
					echo "<td width=140 valign=top class=miTable_th1>DESTINATARIO</td>";
					echo "<td width=140 valign=top class=miTable_th1>DIRECCION</td>";
					echo "<td width=60 valign=top class=miTable_th1>TELEFONO</td>";
					echo "<td width=80 valign=top class=miTable_th1>CIUDAD</td>";
					echo "<td width=100 valign=top class=miTable_th1>PRODUCTO</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['empresa']."</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['producto']."</td></tr>";

			  }
	 }
}
$pendiente_odsObj=new pendiente_ods();
$pendiente_odsObj->detalle_guia($inicio,$tamano_pagina,$tabla,$orden,$id_suc,$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_suc.php?pagina=".($start-1)."&tabla=$tabla&orden=$orden&id_suc=$id_suc&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_suc.php?pagina=".($start+$i)."&tabla=$tabla&orden=$orden&id_suc=$id_suc&f1=$f1&f2=$f2'>". ($start+$i)." </A>";
				}
		   	}
			if($start+$i < $total_paginas){
			    print "&nbsp;&nbsp;<a href='accion_pendientes_suc.php?pagina=".($start+$i)."&tabla=$tabla&orden=$orden&id_suc=$id_suc&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>";
?>