<!doctype html>
<script>
function clientelist(con,fi,ff,x)
{ 
c=1;
e="";
//while(document.getElementById("clientelist"+c)){if(c!=x){ $("#clientelist"+c).html("");} c++;}

$.post("clientelistaff.php",{ id:x,con:con,fi:fi,ff:ff},function(data,status){
$("#clientelist"+x).html(data);
});
}

</script>
<?

$fi=$_GET["fechaini"];
$ff=$_GET["fechafin"];
//require("../conectar.php");
//require("funciones.php");
?>	
<table class="ocupacion" border="1">
  <tr>
    <td>Concepto </td>
    <td>No. de Clientes</td>
    <td>Cantidad en dolares</td>
    <td>Cantidad en pesos</td>
  </tr>
  <?
    $sql="SELECT concepto, count( DISTINCT id_concepto) as con from pagos  where(fecha between '$fi' and '$ff') and valadmon='s' group by concepto ";  
	$query=mysql_query($sql);
	$mayor=0;
		while($pago=mysql_fetch_array($query))
		{
		 $x++;
		 $concepto=$pago["concepto"];
	
		 $rand = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
		 $color = '#'.$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)];
 ?><tr>
 <input name="ultimon" type="hidden" id="ultimon" >
    <td>

    <input name="concepto<?echo$x?>" type="hidden" id="concepto<?echo$x?>" value="<?echo$concepto;?>" ><? if($concepto=="DEPOSITO"){echo"DEPOSITOS EN GARANTIA";}elseif($concepto=="IMPUESTOS"){echo$concepto."(IVA)";}else{echo$concepto;}?></td>
	<input name="color<?echo$x?>" type="hidden" id="color<?echo$x?>" value="<?echo$color;?>" >
    <td><? $totalclientes=$totalclientes+$pago["con"]; if($mayor<$pago["con"])$mayor=$pago["con"];?>
    <input name="cliente<?echo$x?>"  type="hidden" id="cliente<?echo$x?>" value="<?echo$pago["con"];?>"><font color="blue"><a onclick="clientelist('<?echo"p.concepto=/$concepto/"?>','<?echo$fi?>','<?echo$ff?>','<?echo$x?>');" ><?echo$pago["con"]?></a></font>
	<div id="clientelist<?echo$x;?>" > </div></td>
    <td>
	
	<?$sql="SELECT sum(monto) as monto, sum(monto*divisa) as montoconv from pagos  where (fecha between '$fi' and '$ff') and tipo_moneda='USD' and concepto='$concepto' and valadmon='s' group by concepto ";  
	$query1=mysql_query($sql); 
	$montous=mysql_fetch_array($query1);
	echo moneda($montous["monto"]);
	$totaldolarp=$totaldolarp+($montous["montoconv"]);
	$totaldolar=$totaldolar+$montous["monto"];?></td>
    <td><?$sql="SELECT sum(monto) as monto from pagos  where (fecha between '$fi' and '$ff') and tipo_moneda='MXN' and concepto='$concepto' and valadmon='s' group by concepto ";  

	$query1=mysql_query($sql); 

	$montopes=mysql_fetch_array($query1);

	echo moneda($montopes["monto"]);
	$totalpesos=$totalpesos+$montopes["monto"];
	?></td>

  </tr>

  <?
    if($montous['monto']==""){$usd="0";}else{$usd=$montous['monto'];}
    $tipos=array('CLIENTES','USD','MXN');
	$conc=$conc.",^$concepto^";
	$totgg3=$totgg3.",^$concepto^";
    $val=$val.",".$pago["con"];
	
	$vali=$vali.",".$pago['con'];
	$valiusd=$valiusd.",".$usd;
	$valimxn=$valimxn.",".round($montopes['monto'],2);
		
	$lc=strlen($val);
	$lc=$lc-1;
	$val=substr($val,-$lc);
		
	$totg=",{name:^$concepto^,data:[$val]}";
	$totgg=$totgg.$totg;
	
	$val="";
  }
    $ltg=strlen($totgg);
	$ltg=$ltg-1;
    $datacl=substr($totgg,-$ltg);
	
    $ltg3=strlen($conc);
	$ltg3=$ltg3-1;
    $conc3=substr($conc,-$ltg3);	
	
	$lc2=strlen($vali);
	$lc2=$lc2-1;
	$vali=substr($vali,-$lc2);
    
	$lc3=strlen($valiusd);
	$lc3=$lc3-1;
	$valiusd=substr($valiusd,-$lc3);

	$lc4=strlen($valimxn);
	$lc4=$lc4-1;
	$valimxn=substr($valimxn,-$lc4);
	
	$graficausdpesos="{name:^Clientes^,data:[$vali]},{name:^USD^,data:[$valiusd]},{name:^MXN^,data:[$valimxn]}";
	?>

  <tr>

    <td>Total</td>

    <td><?$mayor=$mayor+5;?>

    <!--<input name="total" type="text" id="total" value="<?echo $mayor;?>" readonly></td>-->
	<input name="total" type="text" id="total" value="<?echo $totalclientes;?>" readonly></td>
    <td><?echo moneda($totaldolar);?></td>

    <td><?echo moneda($totalpesos);?></td>

    <input name="ancho" type="hidden" id="ancho" value="<?echo$x;?>" >

  </tr>
  <tr>
    <th></th>
    <th></th>
    <th>Gran total</th>
    <th><?echo moneda($totalpesos+$totaldolarp);?></th>

    <input name="ancho" type="hidden" id="ancho" value="<?echo$x;?>" >

  </tr>
  <tr><th colspan="4">&nbsp;</th></tr>
  <tr>
  <th colspan="4">  
  <a href="graficas/xconcepto.php?val=<?echo $datacl?>" target="_blank" onclick="window.open(this.href ,this.target,'toolbar=no,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,top=0,left=0,width=1170,height=550'); return false;"><div class="boton"><font class="db">GRAFICA X CONCEPTO</font></div></a>
    <a href="graficas/xconceptousdpesos.php?val=<?echo$graficausdpesos;?>&nom=<?echo$conc3;?>" target="_blank" onclick="window.open(this.href ,this.target,'toolbar=no,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,top=0,left=0,width=1170,height=550');return false;"><div class="boton"><font class="db">GRAFICA X CONCEPTO CLIENTES/USD/MXN</font></div></a>
	</th>
  </tr>
</table>
