<?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, apagar, cd, banco.nombre as elbanco, nocuenta, status, idbanco 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, $listacd2 DESC";


}
    else{
  	$qPP = "SELECT idreg, inversionista.nombre as elnombre, appat, apmat, apagar, cd, banco.nombre as elbanco, nocuenta, status, idbanco 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> y despues por:
 <select name = \"listacd2\">
   <option value=\"pagado\">Cantidad</option>
   <option value=\"elbanco\">Banco</option>

<option value=\"appat\">Apellido P.</option>
<option value=\"idreg\">ID Regalia</option>
  <option value=\"cd\">Centro Dist</option>

 </select>
 Seleccionar:<select name = \"checks\"><option value=\"0\">Ninguno</option><option value=\"100\">Todos</option>";
  
	$qa = "SELECT * FROM banco";
																$ca = mysqli_query($conexion, $qa) or die ('Error (Registro No Encontrado): ' . mysqli_error($conexion));
	 															$j=1;
																while($reg = mysqli_fetch_array($ca))
																{
																	
			 													 echo "<option value='$j'>".$reg['nombre'].'</option>';$j++;
			 													}
	    													


  
echo"  


 </select>
 <input type=hidden name=continua value=\"2\" />
  <input type=hidden name=checkis 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\"><form name=\"Agrega4\" action=\"pagarruta.php\" method=\"post\">
	 ";
	
	
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>";

while (($objetoPP=mysqli_fetch_object($rPP)) )
{$dep=round($objetoPP->apagar*.93);
$totalin+=$dep;  

	echo "<tr>";
	if($checks==100){echo"<td><input type=checkbox name=regas[] value=$objetoPP->idreg checked></td><td>En ruta</td>";}else
	if($checks>=1){
	if($checks==$objetoPP->idbanco){echo"<td><input type=checkbox name=regas[] value=$objetoPP->idreg checked></td><td>en ruta</td>";}else{echo"<td><input type=checkbox name=regas[] value=$objetoPP->idreg ></td><td>en ruta</td>";}
	
	}else
	{echo"<td><input type=checkbox name=regas[] value=$objetoPP->idreg ></td><td>en ruta</td>";}
	
	echo"
			 <td>$objetoPP->idreg</td><td>$objetoPP->elnombre $objetoPP->appat $objetoPP->apmat</td><td>$dep</td><td>$objetoPP->cd</td>
             <td>$objetoPP->elbanco</td><td>$objetoPP->nocuenta</td>
            
             ";
             
		
            
		
                 
	echo"
		  </tr> 
		 ";
   
}
echo "</table><br>Acciones<table border=1><tr><td><input type=\"submit\" value=\"Pagar Regalias\" name=\"pago\"></td>
<td><input type=\"submit\" value=\"Cuenta Mal\" name=\"pago\"></td>
<td><input type=\"submit\" value=\"Regresar a Por Pagar\" name=\"pago\"></td></tr></table></form><br><br>
El total de regalias a depositar $ $totalin<br><br><br>"; 
   

?>