<?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;
$id_cd=$sesion->id;
   extract($_POST);
	
           $lafecha=$_POST['fecha'];        
     $qp = "select  month(curdate()), year(curdate())";
$cp = mysql_query($qp) or die ('Error (Registro No Encontrado): ' . mysql_error());
                 while($rDG = mysql_fetch_row($cp)) 
                     {
                $elmes = $rDG[0];
                $elano = $rDG[1];

               };
                   
         if($elmes==13){$elmes=1; $elano=$elano+1;}



	$qPP = "SELECT idreg, inversionista.nombre as elnombre, appat, apmat, `calificados`,`total`,`apagar`,`fechap`, impuestos, pagado, estampa, cd, banco.nombre as elbanco, nocuenta, status, cd, rfc FROM `regs2` join inversionista on 
    inversionista.id_inver=regs2.id_inver left join banco on banco.idbanco=inversionista.banco_idbanco WHERE fechap between '$elano-$elmes-01' and '$elano-$elmes-31' and `status`=0 order by apagar desc";
   
	

 $totalin = 0;
  $totalin2 = 0;

$rPP = mysql_query($qPP) or die ('ErrPP: '. mysql_error());
  

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




echo "<html>
			<body>
			
			<br>
			<center><font size=\"+3\" color=\"#594106\"><b>REGALIAS POR PAGAR</b></font>
			
			<br><br>

	        <table cellpadding=\"1\" align=\"center\">
	 ";
	
	
echo " <tr bgcolor=\"#594106\"><th><font color=\"#FFFFFF\">CD</font></th><th><font color=\"#FFFFFF\">rfc</font></th><th><font color=\"#FFFFFF\">Nombre</font></th><th><font color=\"#FFFFFF\">Calificados</font></th><th><font color=\"#FFFFFF\">Generado</font></th>
<th><font color=\"#FFFFFF\">A pagar</font></th><th></th><th></th><th></th></tr>";

while (($objetoPP=mysql_fetch_object($rPP)) )
{$totalin+=$objetoPP->apagar; $stat=$objetoPP->status;

$idrega=openssl_encrypt($objetoPP->idreg, "CAST5-OFB", "maraxilla", 0, "00001111");


	echo "<tr bgcolor=\"#ece3bb\">
			<td>$objetoPP->cd</td><td>$objetoPP->rfc</td><td>$objetoPP->elnombre $objetoPP->appat $objetoPP->apmat</td><td>$objetoPP->calificados</td>
			 <td>$objetoPP->apagar</td><td>$objetoPP->pagado</td>";
             
			
       

            echo"<td><form name=\"pagar\" action=\"crearvoucher.php\" method=\"post\">
            <input type=hidden name=id_regalia value=$idrega>
            <input type=\"submit\" value=\"CREAR VOUCHER\" name=\"pago\"></form></td>";
         
echo"
                 
	
		  </tr> 
		 ";
   
}
echo "</table><br>
El total de regalias por pagar $ $totalin<br>"; 

/*echo"$id_cd";
	
	$qPP = "SELECT idreg, nombre, appat, apmat, `calificados`,`total`,`apagar`,`fechap` FROM `regs2` join inversionista on inversionista.id_inver=regs2.id_inver WHERE `status`=0 and cd='".$id_cd."'";

 $totalin = 0;
  $totalin2 = 0;

$rPP = mysql_query($qPP) or die ('ErrPP: '. mysql_error());


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




echo "<html>
			<body>
			
			<br>
			<center><b>REGALIAS POR PAGAR</b>
			
			<br>

	        <table border=\"1\" align=\"center\">
	 ";
	
	
echo " <th>ID</th><th>Fecha</th><th>Nombre</th><th>Calificados</th><th>Generado</th>
<th>A pagar</th>";

while (($objetoPP=mysql_fetch_object($rPP)) )
{$totalin+=$objetoPP->apagar; 
	echo "<tr>
			 <td>$objetoPP->idreg</td><td>$objetoPP->fechap</td><td>$objetoPP->nombre $objetoPP->appat $objetoPP->apmat</td><td>$objetoPP->calificados</td>
			 <td>$objetoPP->total</td><td>$objetoPP->apagar</td>";
			
			echo"<td><form name=\"pagar\" action=\"detalle_regs.php\" method=\"post\">
			<input type=hidden name=id_regalia value=$objetoPP->idreg>
			<input type=\"submit\" value=\"VER MAS\" name=\"pago\"></form></td>";
            echo"<td><form name=\"pagar\" action=\"crearvoucher.php\" method=\"post\">
            <input type=hidden name=id_regalia value=$objetoPP->idreg>
            <input type=\"submit\" value=\"CREAR VOUCHER\" name=\"pago\"></form></td>";
            echo"<td><form name=\"pagar\" action=\"reciboregs.php\" method=\"post\">
            <input type=hidden name=id_regalia value=$objetoPP->idreg>
            <input type=\"submit\" value=\"PAGO EFECTIVO\" name=\"pago\"></form></td>";

			echo"</tr> ";
   
}
echo "<br>
El total de regalias por pagar $ $totalin<br>"; 
   
 /*  $qPP2 = "SELECT nombre, appat, apmat, `calificados`,`primera`,`segunda`,`tercera`,`cuarta`,`total`,`apagar`,`fechap` FROM `regs2` join inversionista on inversionista.id_inver=regs2.id_inver WHERE `status`=0 and cd='".$id_cd."'";



$rPP2 = mysql_query($qPP2) or die ('ErrPP: '. mysql_error());

   			echo"
			
			
			

	        <table border=\"1\" align=\"center\">
	 ";
	
	
echo " <th>Nombre</th><th>Calificados</th><th>1ra Gen</th><th>2da Gen</th><th>3ra Gen</th><th>4ta Gen</th><th>Tipo de pago</th><th>Observaciones</th>";

while (($objetoPP=mysql_fetch_object($rPP2)) )
{$totalin2+=$objetoPP->pagar;
	echo "<tr>
			 <td>$objetoPP->rfc</td><td>$ $objetoPP->pagar</td><td>$objetoPP->fechap</td><td>$objetoPP->tipop</td>  <td>$objetoPP->observaciones</td> <td>
			
			</td>
                 
	
		  </tr> 
		 ";
   
}
echo "<br><b>REGALIAS PAGADAS</b><br><br>
El total de regalias pagadas $ $totalin2<br>"; /*/
?>