<?php  
include("../scripts/connect.php");
   $conexion=conecta_default();
   
   include_once("../scripts/session.php");
   //Validar Session

    $sesion=new Sesion("","","");/*Se crea un objeto nuevo con el privilegio necesario para la pag. actual*/

    if(!$sesion->isValida("4")){ /*Sesion invalida*/

	 header("Location: ../index.php?err=NoSesion");

    }/*no hay sesion*/

    else{

       $dato=explode("|",$_SESSION['usuario']);
       $sesion->setDatos($dato[0],$dato[1],$dato[2]);
       $sesion->setSesion();

    }
    //fin validar session
     $id_cd=$sesion->id;
     $conti=0;
 $q2 = "SELECT cantidad, puntos, fechat, transacciones.idtransacciones, tipostr_idtipostr, consec, usuarios_ci_idusuarios_ci, status, rastreo, descripcion, web FROM transacciones join depositos on transacciones.idtransacciones=depositos.transacciones_idtransacciones join inversionista on inversionista.id_inver=transacciones.inversionista_id_inver join pagovta on transacciones.idtransacciones=pagovta.idtransacciones left join guias on guias.idtransacciones=transacciones.idtransacciones left join paqueterias on paqueterias.id_paq=guias.id_paq  WHERE cdentrega=8 and  fechat >= NOW() - INTERVAL 10 day order by usuarios_ci_idusuarios_ci, fechat desc";


  $c2 = mysql_query($q2) or die ('Error en la consulta' . mysql_error());

  echo"<center><br><label style='color:#2b385d; font-size:22px; font-weight:bold'>Agregar Gu&iacute;a a Pedidos </label><br><br><form name=\"transito\" action=\"agrega_guia.php\" method=\"post\"><center><table border=\"0\"> <tr bgcolor=\"#2b385d\">

			<th></th><th><font color=\"white\">Pedido</th><th><font color=\"white\">Fecha</th><th><font color=\"white\">Transaccion</th><th><font color=\"white\">Cantidad</th><th><font color=\"white\">Puntos</th><th><font color=\"white\">Tipo</th><th><font color=\"white\">Paqueteria</font></th><th><font color=\"white\">Rastreo</font></th>

			</tr>";

  for($i=0;$r1 = mysql_fetch_row($c2);$i++)

   {

	   $a0 = $r1[0];

	   $a1 = $r1[1];

	   $a2 = $r1[2];

	   $a3 = $r1[3];

	   $a4 = $r1[4];

	  $a5 = $r1[5];

	  $a6 = $r1[6];

	  $a7 = $r1[7];
	  
	  $a8 = $r1[8];
	  
	  $a9 = $r1[9];
	   $a10 = $r1[10];

	 	  
if($a4==10){$tipon="VENTA";$conti=1;}if($a4==11){$tipon="SALIDA";$conti=1;}
if($a4==12){$tipon="Asignacion";}if($a4==1){$tipon="Cancelada";}
	   $tot+=$a4;

/* $qPP = "select id_pedreal from pedido_real where transacciones=$a7";

$rPP = mysql_query($qPP) or die ('ErrPP: '. mysql_error());	   
if (mysql_affected_rows()){
	  */

echo"<tr bgcolor=\"#c3dfed\">";

if($conti==1){echo"<td><input type=checkbox name=guias[] value=$a3 ></td>";

echo"<td>$a6-$a5</td><td>$a2</td><td>$a3</td><td>$a0</td><td>$a1</td><td>$tipon$a4</td><td>$a9</td><td>$a8</td><td>

	<form name=\"pagar\" action=\"pedidos_masinfo.php\" target=\"_blank\" method=\"post\">

			<input type=hidden name=dist value=$id_dist>

			<input type=hidden name=pedido value=$a3>
<input type=hidden name=tipons value=$a9>
			

								 <input type=\"submit\" value=\"INFO PEDIDO\" name=\"infoped\"></form></td>";
	if(isset($a8))	{						 
								 
								echo" <td>

	<form name=\"pagar\" action=\"$a10$a8\" target=\"_blank\" method=\"post\">

			
			

								 <input type=\"submit\" value=\"Rastrear\" name=\"infoped\"></form></td>";}else{
								echo" <td>

	<form name=\"pagar\" action=\"agrega_guia.php\" target=\"_blank\" method=\"post\">
<input type=hidden name=pedsol value='1'>
			

			<input type=hidden name=pedido value=$a3>

			

								 <input type=\"submit\" value=\"Agrega Guia\" name=\"infoped\"></form></td>
								 <td>";}

								 echo"</tr>";

	}}
	//}

	echo"</table><br><br><input type=\"submit\" value=\"Agregar Guia\" name=\"pago\"></form>";
			
			
?>

