<?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
	
    $fecha1 =$_POST['fecha_i'];

  $fecha2 =$_POST['fecha_f'];
$totvou=0;
$totres=0;
$tot0=0;
$tot1=0;
$tot2=0;
$tot15=0;
$tot20=0;
$tot30=0;
$q2 = "SELECT idv, id_inver, nombre, appat, apmat, idcd, total ,restante, status, voucher.referencia, observaciones, fecha_cre FROM voucher join inversionista on inversionista.id_inver=voucher.id_inv WHERE fecha_cre between \"$fecha1\" and \"$fecha2\" order by status asc";
  
  $c2 = mysqli_query($conexion, $q2) or die ('Error en la consulta' . mysqli_error($conexion));
  echo"<center><font size=\"5\"><b>Vouchers realizados en el periodo</b><br><br></font><table border=\"1\"> <tr>
			<th>Id Voucher</th><th>Id Inver</th><th>Nombre</th><th>CD</th><th>Total</th><th>Restante</th><th>Status</th><th>Referencia</th><th>Observaciones</th><th>Fecha</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];
	  
switch ($a8) {
    case 0:
        $tot0+=$a7;
        break;
    case 1:
        $tot1+=$a6;
        break;
    case 2:
        $tot2+=$a6;
        break;
        case 15:
        $tot15+=$a6;
        break;
        case 20:
        $tot20+=$a6;
        break;
        case 30:
        $tot30+=$a6;
        break;
}
	  $totvou+=$a6;
	 $totres+=$a7;
	  
	 // $tot."".$a8=$a6;
	  
echo"<tr><td>$a0</td><td>$a1</td><td>$a2 $a3 $a4</td><td>$a5</td><td>$a6</td><td>$a7</td><td>$a8</td><td>$a9</td><td>$a10</td><td>$a11</td><td><form name=\"busca\" action=\"infovou2.php\" target=\"_blank\" method=\"post\">

			<input type=hidden name=voucher value=$a0 />
<input type=\"submit\" name=\"buscar\" id=\"continuar\" value=\"Ver info\" /></form></td>
</tr>";
	}
	echo"</table><br><br>
	<table border=\"1\"> <tr>
        <th>Por Pagar</th><th>Pagado</th><th>Abono</th><th>No solicitado</th><th>Anticipo</th><th>Vencido</th></tr>
	<tr><td align=\"center\">$tot0 </td><td>$tot1 </td><td>$tot2 </td><td>$tot15 </td><td>$tot20 </td><td>$tot30 </td></tr></table><br><br>Total generado $totvou<br><br> Total Restante $totres";
	

     

	 //$status="";

   

	?>
	