<?php
session_start();

   include_once("../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("1")){ /*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
extract($_POST);
   $id_cd=$sesion->id;



if($continua==2){
 	$qPP = "SELECT idreg, inversionista.nombre as elnombre, appat, apmat, pagado, cd, banco.nombre as elbanco, nocuenta, status FROM `regs2` join inversionista on 
    inversionista.id_inver=regs2.id_inver left join banco on banco.idbanco=inversionista.banco_idbanco WHERE `status`=10 ORDER BY $listacd DESC";


}
    else{
  	$qPP = "SELECT idreg, inversionista.nombre as elnombre, appat, apmat, pagado, cd, banco.nombre as elbanco, nocuenta, status FROM `regs2` join inversionista on 
    inversionista.id_inver=regs2.id_inver left join banco on banco.idbanco=inversionista.banco_idbanco WHERE `status`=10";
    
    
    }
	

 $totalin = 0;
  $totalin2 = 0;

$rPP = mysqli_query($conexion, $qPP) or die ('ErrPP: '. mysqli_error($conexion));

 echo"<br><form name=\"Agrega3\" action=\"enruta.php\" method=\"post\">
  Ordenar Depositos por:<select name = \"listacd\">
   <option value=\"elbanco\">Banco</option>
<option value=\"pagado\">Cantidad</option>
<option value=\"appat\">Apellido P.</option>
<option value=\"idreg\">ID Regalia</option>
  <option value=\"cd\">Centro Dist</option>

 </select>

  <input type=hidden name=continua value=\"2\" />

  <input type=\"submit\" name=\"lista2\"  value=\"Continuar\" />
  
  
  
  </form>";


   
if(!mysqli_affected_rows($conexion))
{
	echo "<center>No hay Regalias en Transito por el momento.</center><br>";
    exit;
}




echo "<html>
			<body>
			
			
			<center><b>REGALIAS EN RUTA</b>
			
			<br>

	        <table border=\"1\" align=\"center\">
	 ";
	
	
echo " <th></th><th>Estatus</th><th>ID</th><th>Nombre</th><th>A Depositar</th><th>CD</th><th>Banco</th><th>Cuenta</th><th>Pagar</th><th>Regresar a</th>";

while (($objetoPP=mysqli_fetch_object($rPP)) )
{$totalin+=$objetoPP->pagado;  

	echo "<tr>";
	if($objetoPP->status==10){echo"<td></td><td>En ruta</td>";}else{echo"<td><input type=checkbox name=regas[] value=$objetoPP->idreg ></td><td>Pendiente</td>";}
	
	echo"
			 <td>$objetoPP->idreg</td><td>$objetoPP->elnombre $objetoPP->appat $objetoPP->apmat</td><td>$objetoPP->pagado</td><td>$objetoPP->cd</td>
             <td>$objetoPP->elbanco</td><td>$objetoPP->nocuenta</td>
             <td><form name=\"pagar\" action=\"pago_regs.php\" method=\"post\"><input type=hidden name=id_regalia value=$objetoPP->idreg><input type=\"submit\" value=\"PAGAR\" name=\"pago\"></form></td>
             <td><form name=\"pagar\" action=\"regresaregalia.php\" method=\"post\"><input type=hidden name=id_regalia value=$objetoPP->idreg><input type=\"submit\" value=\"POR PAGAR\" name=\"pago\"></form></td>
             ";
             
		
            
		
                 
	echo"
		  </tr> 
		 ";
   
}
echo "</table>
El total de regalias a depsitar $ $totalin<br><br><br>"; 
   

?>