<?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

   $rfc =$_POST['rfcpr'];
   $ref =$_POST['refpr'];
   
   $promotor='';
   	function regresames($mes){

	   switch($mes) 
				{
					case '01': $mesletra="Enero"; $diaf=31; break;
					case '02': $mesletra="Febrero"; $diaf=28; break;
					case '03': $mesletra="Marzo"; $diaf=31; break;
					case '04': $mesletra="Abril"; $diaf=30; break;
					case '05': $mesletra="Mayo"; $diaf=31; break;
					case '06': $mesletra="Junio"; $diaf=30; break;
					case '07': $mesletra="Julio"; $diaf=31; break;
					case '08': $mesletra="Agosto"; $diaf=31; break;
					case '09': $mesletra="Septiembre"; $diaf=30; break;
					case '10': $mesletra="Octubre"; $diaf=31; break;
					case '11': $mesletra="Noviembre"; $diaf=30; break;
					case '12': $mesletra="Diciembre"; $diaf=31; break;

				}	

	return $mesletra;}
   
   if(isset($rfc)){
	   $qa = "SELECT inversionista.id_inver as elnv, rfc, inversionista.nombre as nom, appat, apmat, fecha_nac, ciudad, tel, tel1, tel2, referencia, email, teldist.wa as wa, estados.nombre as edo, vip, idprom, estampa FROM inversionista left join teldist on inversionista.id_inver=teldist.id_inver join estados on inversionista.estados_idestado=estados.idestado WHERE rfc = \"$rfc\"";
   $ca = mysqli_query($conexion, $qa) or die ('Error (Registro N2o Encontrado): ' . mysqli_error($conexion));

   if(mysqli_affected_rows($conexion))
   {
   	$ra = mysqli_fetch_object($ca);
	$id = $ra->elnv;
    
	$nombre = $ra->nom;
	$apat = $ra->appat;
	$tel = $ra->tel;
	$tel1 = $ra->tel1;
	$tel2 = $ra->tel2;
	$amat = $ra->apmat;
    $fechanac = $ra->fecha_nac;
    $ciudad = $ra->ciudad;
    $ref = $ra->referencia;
    $email = $ra->email;
    $wa = $ra->wa;
    $estado = $ra->edo;
      $vip = $ra->vip;
      $inscripcion = $ra->estampa;
      $promotor = $ra->idprom;
$continua=1;
   }
   
  } 
   
   if(isset($ref)){
	   	    $qa = "SELECT id_inver, rfc, inversionista.nombre as nom, appat, apmat, fecha_nac, ciudad, referencia, email, wa, estados.nombre as edo, vip, idprom, estampa FROM inversionista join estados on inversionista.estados_idestado=estados.idestado WHERE referencia = \"$ref\"";
   $ca = mysqli_query($conexion, $qa) or die ('Error (Registro N2o Encontrado): ' . mysqli_error($conexion));

   if(mysqli_affected_rows($conexion))
   {
   	$ra = mysqli_fetch_object($ca);
	$id = $ra->id_inver;
    $rfc= $ra->rfc;
	$nombre = $ra->nom;
	$apat = $ra->appat;
	$amat = $ra->apmat;
    $fechanac = $ra->fecha_nac;
    $ciudad = $ra->ciudad;
    $ref = $ra->referencia;
    $email = $ra->email;
    $wa = $ra->wa;
    $estado = $ra->edo;
    $vip = $ra->vip;
    $promotor = $ra->idprom;
    $inscripcion = $ra->estampa;
    $continua=1;
   }

   }
   
     echo "<center><table border=\"1\"><tR><th>Gen Arriba</th><th>R.F.C.</th><th>Nombre</th></tr>";
 
 $qcc1 = "SELECT rfc, nombre, appat, apmat, idprom FROM inversionista WHERE id_inver = \"$promotor\" ";
           $ccc1 = mysqli_query($conexion, $qcc1) or die ('No se pudo hacer la consulta cc1' . mysqli_error($conexion));
           $rrc = mysqli_fetch_row($ccc1);
  
          echo "<tr><td>Primera 10%</td><td>$rrc[0]</td><td> $rrc[1] $rrc[2] $rrc[3]</td></tr>"; $promotor=$rrc[4];
          
 
  $qcc1 = "SELECT rfc, nombre, appat, apmat, idprom FROM inversionista WHERE id_inver = \"$promotor\" ";
           $ccc1 = mysqli_query($conexion, $qcc1) or die ('No se pudo hacer la consulta cc1' . mysqli_error($conexion));
           $rrc = mysqli_fetch_row($ccc1);
  
          echo "<tr><td>Segunda 17%</td><td>$rrc[0]</td><td> $rrc[1] $rrc[2] $rrc[3]</td></tr>"; $promotor=$rrc[4];       
            
  $qcc1 = "SELECT rfc, nombre, appat, apmat, idprom FROM inversionista WHERE id_inver = \"$promotor\" ";
           $ccc1 = mysqli_query($conexion, $qcc1) or die ('No se pudo hacer la consulta cc1' . mysqli_error($conexion));
           $rrc = mysqli_fetch_row($ccc1);
  
          echo "<tr><td>Tercera 17%</td><td>$rrc[0]</td><td> $rrc[1] $rrc[2] $rrc[3]</td></tr>"; $promotor=$rrc[4]; 
   $qcc1 = "SELECT rfc, nombre, appat, apmat, idprom FROM inversionista WHERE id_inver = \"$promotor\" ";
           $ccc1 = mysqli_query($conexion, $qcc1) or die ('No se pudo hacer la consulta cc1' . mysqli_error($conexion));
           $rrc = mysqli_fetch_row($ccc1);
  
          echo "<tr><td>Cuarta 17%</td><td>$rrc[0]</td><td> $rrc[1] $rrc[2] $rrc[3]</td></tr>"; $promotor=$rrc[4];
   $qcc1 = "SELECT rfc, nombre, appat, apmat, idprom FROM inversionista WHERE id_inver = \"$promotor\" ";
           $ccc1 = mysqli_query($conexion, $qcc1) or die ('No se pudo hacer la consulta cc1' . mysqli_error($conexion));
           $rrc = mysqli_fetch_row($ccc1);
  
          echo "<tr><td>Quinta 1%</td><td>$rrc[0]</td><td> $rrc[1] $rrc[2] $rrc[3]</td></tr>"; $promotor=$rrc[4];
  
  echo "</table>";
   
   
   
   
   
   
      if($vip==1){echo"<center><img src=\"rrbvipbanner.png\"><br>";}else{}
   $centros_entregas="SELECT * FROM usuarios_ci where tipo_centro='1' and centro_activo='1' ";
   
   $qp3 = "SELECT count(idtransacciones) as cuenta from transacciones where inversionista_id_inver=$id";
   $cp3 = mysqli_query($conexion, $qp3) or die ('Error (Registro No Encontrado): ' . mysqli_error($conexion));
$rp3 = mysqli_fetch_object($cp3);	
	$ingreso = $rp3->cuenta;
   

   
   if($continua==1){
     $busqusr2 = "SELECT month(curdate()) as elmes, year(curdate()) as elano";

   $cons2 = mysqli_query($conexion, $busqusr2) or die ('Err0: '.mysqli_error($conexion));

   $usr2 = mysqli_fetch_object($cons2);

   $mes3 = $usr2->elmes; $ano3 = $usr2->elano; 
   $fecha1=$ano3."-".$mes3."-01";
$fecha2=$ano3."-".$mes3."-31";


 if($mes3>=2){$mes2=$mes3-1; $ano2=$ano3;}else{$mes2=12; $ano2=$ano3-1;}

    if($mes2>=2){$mes1=$mes2-1; $ano1=$ano2;}else{$mes1=12; $ano1=$ano3-1;}

	 if($mes1>=2){$mes0=$mes1-1; $ano0=$ano1;}else{$mes0=12; $ano0=$ano3-1;}

	$mes3l=regresames($mes3);

	$mes2l=regresames($mes2);

	$mes1l=regresames($mes1);
	
$mes0l=regresames($mes0);

 $vtas = "SELECT sum(puntos) FROM transacciones join depositos on transacciones.idtransacciones=depositos.transacciones_idtransacciones WHERE tipostr_idtipostr!='11' and inversionista_id_inver = \"$id\" and fechat between \"$fecha1\" and \"$fecha2\"";
           $vtas1 = mysqli_query($conexion, $vtas) or die ('No se pudo hacer la consulta cc1' . mysqli_error($conexion));
           $rr8 = mysqli_fetch_row($vtas1);
           $valin=$rr8[0]; 
           $rest=624-$valin;
           

   echo"<center>";

   echo"<label style='color:#2b385d; font-size:28px; font-weight:bold'>Informaci&oacute;n Integral de Distribuidores</label><br><br> 
   Compras del mes: $valin Estatus:";
   if($valin>=624){echo"<font color=\"green\">Calificado</font>";}else{echo"<font color=\"red\"> No Calificado</font>";}
   
   echo"<br>
   <table align='center' cellspacing=5 cellpadding=5>
   <tr bgcolor=\"#c3dfed\"><td><b>RFC</b> $rfc</td><td>$nombre $apat $amat</td><td><b>Ref </b>$ref</td><td><b>Fecha Nac</b>$fechanac</td>
   </tr>
   <tr bgcolor=\"#c3dfed\"><td><b>Whatsapp:</b> $wa</td><td><b>Correo:</b> $email</td><td>$ciudad</td><td>$estado</td>
   </tr>
   </table>Fecha de inscripci&oacute;n en la empresa $inscripcion<br>
    ";
    
   


    
    echo"<bR><table align='center' cellspacing=5 cellpadding=5>
   <tr bgcolor=\"#c3dfed\"><td>Tel NVO:</td><td> $tel</td><td> Tel1:</td><td> $tel1</td><td> Tel2:</td><td> $tel2</td>
   </tr>
   </table>";
         //--------------comentarios a distribuidores  
    $qPP = "select idcd, fechac, comentario from comentarios_dist where id_dist=$id";

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

if(mysqli_affected_rows($conexion))
{


echo "<center><bR><label style='color:#2b385d; font-size:22px; font-weight:bold'>**Comentarios**</label>

<table border=\"0\">
 <tr bgcolor=\"#2b385d\"><th><font color=\"white\">CD</th><th><font color=\"white\">Fecha - Hora</th><th><font color=\"white\">Comentario</th></tr>";


while (($objetoPP=mysqli_fetch_object($rPP)) )


{

	
	

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

	
			<td align=\"center\">$objetoPP->idcd</td> <td align=\"center\">$objetoPP->fechac</td>
			<td align=\"center\">$objetoPP->comentario</td>

		  </tr> 

		 ";
   

}echo"</tablE>";

	 }
   
   //-------reporte generacional
   echo"
<br><br><center><label style='color:#2b385d; font-size:22px; font-weight:bold'>Reporte de Regal&iacute;as</label>



<form name=\"Agrega\" action=\"super_reporte_generacional.php\" target=\"_blank\" method=\"post\">

<table border=0>

	  <tr bgcolor=\"#c3dfed\">
<td>Periodo:</td><td> <select name=\"fecha\">

      <option value=\"$ano3-$mes3-01\">$mes3l $ano3</option>

      <option value=\"$ano2-$mes2-01\">$mes2l $ano2</option>

      <option value=\"$ano1-$mes1-01\">$mes1l $ano1</option>
	   <option value=\"$ano0-$mes0-01\">$mes0l $ano0</option>

      </select>

	  
	  

	  <td><input type=\"submit\" name=\"lista1\" id=\"aceptar\" value=\"Generar Regalias\" /></td>

	</tr>

</table>
<input type=hidden name=iddist value=$id>

	  <input type=hidden name=mesnum1 value=$mes1>

	  <input type=hidden name=mesnum2 value=$mes2>

	  <input type=hidden name=mesnum3 value=$mes3>
	  <input type=hidden name=mesnum0 value=$mes0>

	  <input type=hidden name=anonum1 value=$ano1>

	  <input type=hidden name=anonum2 value=$ano2>

	  <input type=hidden name=anonum3 value=$ano3>
 <input type=hidden name=anonum0 value=$ano0></td>
</form><br>
<form name=\"Agrega\" action=\"6mesestel.php\" target=\"_blank\" method=\"post\">
<input type=hidden name=iddist value=$id><input type=\"submit\" name=\"lista1\" id=\"aceptar\" value=\"Reporte 6 meses\" />
</form>
";
/*
$qPP = "SELECT idtransacciones, usuarios_ci_idusuarios_ci as cd, consec, fechat, inversionista.id_inver as elinv, nombre, appat, apmat, statuts, retencion_obsequio.fechae as fechaent, id_cdv, id_cde, retencion_obsequio.id_inver as idprom from retencion_obsequio join transacciones on transacciones.idtransacciones=retencion_obsequio.id_transacc join inversionista on inversionista.id_inver=transacciones.inversionista_id_inver where retencion_obsequio.id_inver=$id and fechat >= NOW() - INTERVAL 2 MONTH";

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

if(mysqli_affected_rows($conexion))
{


echo "<center><label style='color:#2b385d; font-size:22px; font-weight:bold'>Obsequios por Inscripci&oacute;n</label>

<table border=\"0\">
 <tr bgcolor=\"#2b385d\"><th><font color=\"white\">Pedido</th><th><font color=\"white\">Nombre</th><th><font color=\"white\">Fecha</th>
 <th><font color=\"white\">CDV</th> <th><font color=\"white\">Estatus</th> <th><font color=\"white\">Fecha Ent</th> <th><font color=\"white\">CDE</th><th><font color=\"white\"></th></tr>";


while (($objetoPP=mysqli_fetch_object($rPP)) )
{
	$elinv=$objetoPP->id_inver;
	$comp=$objetoPP->compras;
$elstat=$objetoPP->statuts;
if($elstat==1){$statobs="Entregado";}else{$statobs="Por Entregar";}
	
	if($comp>=624){
		$calif++;echo"<tr  bgcolor=\"CCFFCC\">";
		
	}else{echo"<tr  bgcolor=\"#c3dfed\"><form name=\"pagar\" action=\"entrega_reserva_01.php\" target=\"_blank\" method=\"post\">";}
	
	
	

	echo "

	
			<td align=\"center\">$objetoPP->cd - $objetoPP->consec</td> <td align=\"center\">$objetoPP->nombre $objetoPP->appat $objetoPP->apmat</td>
			<td align=\"center\">$objetoPP->fechat</td><td align=\"center\">$objetoPP->id_cdv</td><td align=\"center\">$statobs</td><td align=\"center\">$objetoPP->fechaent</td>";
			
			if($elstat==0){
			echo"<td>
			
			<select name='cdent'>";
			
			$centros_entrega1="SELECT cde, nombre FROM cdentrega join usuarios_ci on usuarios_ci.idusuarios_ci=cdentrega.cde WHERE id_cd=0";
                    $entregas11=mysqli_query($conexion, $centros_entrega1) or die ("Error en buscar centros de entrega");
                       
                         echo "<option value='$dato[0]'> ".$dato[0]." - "."Mi centro"."</option>";
                        while ($centros_list=mysqli_fetch_array($entregas11)) {
                            echo "<option value='$centros_list[0]'> ".$centros_list[0]." - " .$centros_list[1]."</option>";

                          }
echo"</select></td>";


			
			}else{echo"<td align=\"center\">$objetoPP->id_cde</td>";}
			
			
			
			
			
			
			
			
			
			
			if($elstat==0){
			echo"<td>
			<input type=hidden name=idprom value=$objetoPP->idprom>

			<input type=hidden name=pedido value=$objetoPP->idtransacciones>

			

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

		  </tr> 

		 ";
   

}

	echo"</table>";   }



/*/


//-------------- obsequios por inscripcion
$qPP = "SELECT idtransacciones, usuarios_ci_idusuarios_ci as cd, consec, fechat, inversionista.id_inver as elinv, nombre, appat, apmat, statuts, retencion_obsequio.fechae as fechaent, id_cdv, id_cde, retencion_obsequio.id_inver as idprom, month(fechat) as meses, id_ob from retencion_obsequio join transacciones on transacciones.idtransacciones=retencion_obsequio.id_transacc join inversionista on inversionista.id_inver=transacciones.inversionista_id_inver where retencion_obsequio.id_inver=$id and fechat >= NOW() - INTERVAL 4 MONTH";

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

if(mysqli_affected_rows($conexion))
{


echo "<center><label style='color:#2b385d; font-size:22px; font-weight:bold'>Obsequios por Inscripci&oacute;n</label>

<table border=\"0\">
 <tr bgcolor=\"#2b385d\"><th><font color=\"white\">id</th><th><font color=\"white\">Pedido</th><th><font color=\"white\">Nombre</th><th><font color=\"white\">Fecha</th>
 <th><font color=\"white\">CDV</th> <th><font color=\"white\">Estatus</th> <th><font color=\"white\">Fecha Ent</th> <th><font color=\"white\">CDE</th><th><font color=\"white\"></th></tr>";


while (($objetoPP=mysqli_fetch_object($rPP)) )
{
	$elinv=$objetoPP->id_inver;
	$comp=$objetoPP->compras;
$elstat=$objetoPP->statuts;
if($elstat==1){$statobs="Entregado";}else{$statobs="Por Entregar";}
		if($elstat==0 && $objetoPP->meses!=$mes3){$statobs="Expirado";}
echo"<tr  bgcolor=\"#c3dfed\"><form name=\"pagar\" action=\"revive_reserva.php\" target=\"_blank\" method=\"post\">";
	
	
	

	echo "

	
			<td align=\"center\">$objetoPP->id_ob</td><td align=\"center\">$objetoPP->cd - $objetoPP->consec</td> <td align=\"center\">$objetoPP->nombre $objetoPP->appat $objetoPP->apmat</td>
			<td align=\"center\">$objetoPP->fechat</td><td align=\"center\">$objetoPP->id_cdv</td><td align=\"center\">$statobs</td><td align=\"center\">$objetoPP->fechaent</td>";
			
		echo"<td align=\"center\">$objetoPP->id_cde</td>";
			
			
			
			
			
			
			
			
			
			
			if($statobs="Expirado" && $elstat!=5 && $elstat!=1){
			echo"<td>
			<input type=hidden name=idprom value=$objetoPP->idprom>
<input type=hidden name=pase value=$elstat>
			<input type=hidden name=pedido value=$objetoPP->id_ob>

			

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

		  </tr> 

		 ";
   

}

	echo"</table>";   }

//fin entregar obsequio





echo"<br><label style='color:#2b385d; font-size:22px; font-weight:bold'>Pedidos Recientes</label><br>";



	 $q2 = "SELECT cantidad, puntos, fechat, transacciones.idtransacciones, tipostr_idtipostr, consec, usuarios_ci_idusuarios_ci, status, efectivo, deposito, tarjeta, voucher, regalias, porpagar 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  WHERE rfc=\"$rfc\" and  fechat >= NOW() - INTERVAL 6 MONTH order by idtransacciones";


  $c2 = mysqli_query($conexion, $q2) or die ('Error en la consulta' . mysqli_error($conexion));

	if(mysqli_affected_rows($conexion))
{
   
	   
  echo"<center><table border=\"0\"> <tr bgcolor=\"#2b385d\">

			<th><font color=\"white\">Fecha</th><th><font color=\"white\">Transaccion</th><th><font color=\"white\">Pedido</th><th><font color=\"white\">Tipo</th><th><font color=\"white\">Puntos</th><th><font color=\"white\">Cantidad</th><th><font color=\"white\">EF</font></th><th><font color=\"white\">DE</font></th><th><font color=\"white\">TA</font></th><th><font color=\"white\">VO</font></th><th><font color=\"white\">RE</font></th><th><font color=\"white\">PP</font></th>

			</tr>";

  for($i=0;$r1 = mysqli_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];
	    $a11 = $r1[11];
	     $a12 = $r1[12];
	      $a13 = $r1[13];
  switch($a4) 
				{
					case '1': $tipon="Cancel";  break;
					case '10': $tipon="Venta";  break;
					case '11': $tipon="Salida";  break;
					case '12': $tipon="Asign";  break;
case '13': $tipon="C. Adic";  break;
				

				}
	 	  

	   $tot+=$a4;

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

$rPP = mysqli_query($conexion, $qPP) or die ('ErrPP: '. mysqli_error($conexion));	   
if (mysqli_affected_rows($conexion)){
	  */

echo"<tr bgcolor=\"#c3dfed\"><td>$a2</td><td>$a3</td><td>$a6-$a5</td><td>$tipon</td><td>$a1</td><td>$a0</td><td>$a8</td><td>$a9</td><td>$a10</td><td>$a11</td><td>$a12</td><td>$a13</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>
								 <td>

	<form name=\"pagar\" action=\"cancelanota.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=\"ELIMINAR\" name=\"cancelaped\"></form></td>";
	

								 echo"</tr>";

	}
	//

	echo"</table>";
		
		}else
	{ echo "se puede eliminar <br><form name=\"pagar\" action=\"bajadist1.php\"  method=\"post\">
	<input type=hidden name=idinv value=$id>
<input type=\"submit\" value=\"Eliminar\" name=\"infoped\"></form>
	
	";    }
		
		
$calif=0;

 $q22 = "SELECT rfc, inversionista.nombre, appat, apmat, cantidad, puntos, fechat, transacciones.idtransacciones, nsalida, usuarios_ci_idusuarios_ci, consec FROM transacciones join depositos 
      on transacciones.idtransacciones=depositos.transacciones_idtransacciones join inversionista on inversionista.id_inver=transacciones.inversionista_id_inver 
      left join asignaciones on asignaciones.idtransacciones=transacciones.idtransacciones WHERE  tipostr_idtipostr='12' and rfc=\"$rfc\" and  fechat >= NOW() - INTERVAL 4 MONTH order by idtransacciones";
	 
	
  $c22 = mysqli_query($conexion, $q22) or die ('Error en la consulta' . mysqli_error($conexion));
  //
  if(mysqli_affected_rows($conexion))
   {
  echo"<center><br>Asignaciones<br><table border=\"1\" cellspacing=\"0\" cellpadding=\"1\"> <tr>
            <th>Fecha</th><th>Trans</th><th>Asigno</th><th>$</th><th>Puntos</th><th>N.S.</th>
            </tr>";
  for($i=0;$r1 = mysqli_fetch_row($c22);$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];       
      
echo"<tr><td>$a6</td><td>$a7</td><td>$a9</td><td>$a4</td><td>$a5</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=$a7>
<input type=hidden name=tipons value=$a9>
			

								 <input type=\"submit\" value=\"INFO PEDIDO\" name=\"infoped\"></form></td></tr>";
    }
    echo"</table>";
   }
	
	


$qPP2 = "SELECT regs2.idreg as regas, total, _real, apagar, month(fechap) as mesreg, status, impuestos, pagado, fechaf, observaciones, nocuenta, folio  from regs2 left join pagos on regs2.idreg=pagos.idreg where id_inver=$id and fechap >= NOW() - INTERVAL 6 MONTH";

$rPP2 = mysqli_query($conexion, $qPP2) or die ('ErrPP: '. mysqli_error($conexion));

if(mysqli_affected_rows($conexion))
{



echo "<center><br><br><label style='color:#2b385d; font-size:22px; font-weight:bold'>Regal&iacute;as Anteriores</label>

<table border=\"0\">
 <tr bgcolor=\"#2b385d\"><th><font color=\"white\">Id Reg</th><th><th><font color=\"white\">Mes</th><th><font color=\"white\">Generado</th><th><font color=\"white\">Restante</th>
 <th><font color=\"white\">Impuestos</th><th><font color=\"white\">Total</th><th><font color=\"white\">Estatus</th><th><font color=\"white\">Fecha Pago</th><th><font color=\"white\">Observaciones</th><th><font color=\"white\">No. Cuenta</th><th><font color=\"white\">Folio</th></tr>";


while (($objetoPP=mysqli_fetch_object($rPP2)) )


{
	switch($objetoPP->status) 



				{

					case '0': $elstat="Por Pagar"; break;

					case '1': $elstat="Pagado";  break;

					case '2': $elstat="Efectivo";  break;

					case '3': $elstat="Abono Adeudo";  break;

					case '4': $elstat="Producto RRB";  break;

					case '5': $elstat="Voucher";  break;

					case '6': $elstat="Voucher6";  break;

					case '7': $elstat="Retenida";  break;

					case '8': $elstat="En Transito";  break;

					case '9': $elstat="Cuenta mal";  break;

					case '10': $elstat="En ruta"; break;

					case '15': $elstat=" No cobra"; break;
					case '20': $elstat="Vencidas"; break;

				}	
	
	$mesnum=$objetoPP->mesreg-1; if($mesnum==0){$mesnum=12;}
	
	
	$lareg=$objetoPP->regas;
	$elmesreg=regresames($mesnum);

	
	if($comp>=624){
		$calif++;echo"<tr  bgcolor=\"CCFFCC\">";
		
	}else{echo"<tr  bgcolor=\"#c3dfed\">";}
	
	
	

	echo "

	
			<td align=\"center\">$lareg</td> <td align=\"center\">$elmesreg</td> <td align=\"center\">$objetoPP->_real</tD><td> $objetoPP->apagar</td><td> $objetoPP->impuestos</td>
			<td align=\"center\">$objetoPP->pagado</td><td align=\"center\">$elstat</td><td align=\"center\">$objetoPP->fechaf</td><td align=\"center\">$objetoPP->observaciones</td><td align=\"center\">$objetoPP->nocuenta</td><td align=\"center\">$objetoPP->folio</td><td><form name=\"pagar\"  target=\"_blank\" action=\"detalle_rega.php\" method=\"post\">
			<input type=hidden name=regalia value='$lareg'><input type=hidden name=elrfc value='$rfc'>
			<input type=\"submit\" value=\"VER MAS\" name=\"pago\"></form></td>

		  </tr> 

		 ";
   

}echo"</table>";

	}
	
$q2 = "SELECT idv, total, restante, status, idcd, observaciones, fecha_cre from voucher WHERE id_inv=\"$id\"  and  fecha_cre >= NOW() - INTERVAL 6 MONTH";
	
		 

$c2 = mysqli_query($conexion, $q2) or die ('ErrPP: '. mysqli_error($conexion));
  

   
if(!mysqli_affected_rows($conexion))
{
	echo "<center>No hay vouchers asociados.</center><br>";
    
}else{
echo"

<font size=\"+3\" color=\"#594106\"><br><b>Vouchers asociados</b></font>
			
			
	        <table cellpadding=\"1\" align=\"center\">
	 ";
	
	
echo " <tr bgcolor=\"#594106\"><th><font color=\"#FFFFFF\">ID</font></th><th><font color=\"#FFFFFF\">Fecha</font></th><th><font color=\"#FFFFFF\">Total</font></th><th><font color=\"#FFFFFF\">Restante</font></th><th><font color=\"#FFFFFF\">Status</font></th><th><font color=\"#FFFFFF\">CD Realizo</font></th><th><font color=\"#FFFFFF\">Observaciones</font></th><th><font color=\"#FFFFFF\"></font></th></tr>";

while (($objetoPP=mysqli_fetch_object($c2)) )
{$totalin+=$objetoPP->apagar; $stat=$objetoPP->status;$elvou=$objetoPP->idv;

switch ($stat){
	case 0:
	$elstat="Por Pagar";
	break;
	case 1 :
	$elstat="Pagado";
	break;
	case 2 :
	$elstat="Vencido";
	break;
	case 3 :
	$elstat="Desctivado";
	break;
	
}

	echo "<tr bgcolor=\"#ece3bb\">
			 <td>$objetoPP->idv</td><td>$objetoPP->fecha_cre</td><td>$objetoPP->total</td><td>$objetoPP->restante </td><td>$elstat</td>
			 <td>$objetoPP->idcd</td><td>$objetoPP->observaciones</td>            
			<td><form name=\"pagar\" action=\"infovou2.php\"  target=\"_blank\" method=\"post\">
			<input type=hidden name=voucher value='$elvou'><input type=hidden name=elrfc value='$rfc'>
			<input type=\"submit\" value=\"VER MAS\" name=\"pago\"></form></td>
  
		  </tr> 
		 ";
   
}
echo "</table><br>";
}
	

	
	
	echo"<br>";
		  //-----------------agregar comentario a distribuidor
	 echo"<form name=\"Agrega\" action=\"agregacoment.php\" method=\"post\"><input type=hidden name=cd value=0 /><input type=hidden name=dist value=$id /><br> 
	<label style='color:#2b385d; font-size:22px; font-weight:bold'>Agregar Comentario (Max 250 caracteres)</label><br><TEXTAREA NAME=\"coment\" COLS=\"80\" ROWS=\"2\" maxlength=\"250\"></TEXTAREA><br><br>
<input type=\"submit\" name=\"aceptar\" id=\"aceptar\" value=\"Agregar comentario\" /></form><br><br><br>";
/*
$qPP = "SELECT rfc, nombre, appat, apmat, referencia, id_inver, sum(puntos) as compras from inversionista join transacciones on transacciones.inversionista_id_inver=inversionista.id_inver left join depositos on (depositos.transacciones_idtransacciones=transacciones.idtransacciones and fechat between \"$fecha1\" and \"$fecha2\")  where idprom=$id  group by id_inver";

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

if(mysqli_affected_rows($conexion))
{


echo "<center><br><br><label style='color:#2b385d; font-size:22px; font-weight:bold'>Personas Directas</label>

<table border=\"0\">
 <tr bgcolor=\"#2b385d\"><th><font color=\"white\">RFC</th><th><font color=\"white\">Nombre</th><th><font color=\"white\">Referencia</th><th><font color=\"white\">Compras</th></tr>";


while (($objetoPP=mysqli_fetch_object($rPP)) )


{
	$elinv=$objetoPP->id_inver;
	$comp=$objetoPP->compras;

	
	if($comp>=624){
		$calif++;echo"<tr  bgcolor=\"CCFFCC\">";
		
	}else{echo"<tr  bgcolor=\"#c3dfed\">";}
	
	
	

	echo "

	
			<td align=\"center\">$objetoPP->rfc</td> <td align=\"center\">$objetoPP->nombre $objetoPP->appat $objetoPP->apmat</td>
			<td align=\"center\">$objetoPP->referencia</td><td align=\"center\">$comp</td>

		  </tr> 

		 ";
   

}

	echo"</table>Calificados en el mes: $calif</center>";   }
	*/ 
	 
	 
	 }else{if($ingreso!=0)echo"<br><br><center>Existe un error en los datos, intenta de nuevo.<br><br>";}
?>



