<?php session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<?php
require('../cfg/res.php');	

$fecha1 = date('Y-m-j');
$nuevafecha = strtotime ( '-1 month' , strtotime ( $fecha1 ) ) ;
$xfecha1 = date ( 'Y/m/j' , $nuevafecha );
$xfecha1 = date('Y/m/'.'1');
$xfecha2 = date('Y/m/d');

$sql_datesp='SET lc_time_names = "es_UY"';
$res_datesp=mysql_query($sql_datesp,$link_vcrx);

$sql_vtast='select *,
	sum(tcant) as ttcant,
	sum(tsubt) as ttsubt,
	sum(tdcto*-1) as ttdcto,
	sum(tsubtice) as ttsubtice,
	sum(tice) as ttice,
	sum(tsubtiva0) as ttsubtiva0,
	sum(tsubtiva) as ttsubtiva,
	sum(tiva) as ttiva,
	sum(tirbp) as ttirbp,
	sum(total) as ttotal
	from vtas12 where ';

$xfgrou='D';
if(isset($_GET['fgrou']) && !empty($_GET['fgrou']))
{$xfgrou=$_GET['fgrou'];}

$xfcodi='1';
if (mb_stristr('elco',substr($_SESSION['user_vcrx_empr'],0,4)))
{$xfcodi='2';}


if(isset($_GET['fcodi']) && !empty($_GET['fcodi']))
{
	$xfcodi=$_GET['fcodi'];
}
switch ($xfcodi)
{
	case '1': $item_codi='item';break;
	case '2': $item_codi='item_codigov';break;
	case '3': $item_codi='item_ean';break;
	default : $item_codi='item';break;
}


$sql_vtast.='(';

if(isset($_GET['fecha_ini']) && !empty($_GET['fecha_ini']) && isset($_GET['fecha_fin']) && !empty($_GET['fecha_fin']))
{
	$xfecha1=$_GET['fecha_ini'];
	$xfecha2=$_GET['fecha_fin'];
}

$sql_vtasf='select min(fecha) as fecha from vtas1 where status!="X" and status!="O" and fecha>="'.$xfecha1.'"';
$res_vtasf=mysql_query($sql_vtasf,$link_vcrx);
$xfecha1b=mysql_result($res_vtasf,0,'fecha');

$sql_vtasf='select max(fecha) as fecha from vtas1 where status!="X" and status!="O" and fecha<="'.$xfecha2.'"';
$res_vtasf=mysql_query($sql_vtasf,$link_vcrx);
$xfecha2b=mysql_result($res_vtasf,0,'fecha');



	$xanios=date('Y',strtotime($xfecha2b))-date('Y',strtotime($xfecha1b))+1;
	$xanio1=date('Y',strtotime($xfecha1b));
	$xanio2=date('Y',strtotime($xfecha2b));

	$dias=intval(strtotime($xfecha2b) - strtotime($xfecha1b))/60/60/24;
    $anios=date('Y',strtotime($xfecha2))-date('Y',strtotime($xfecha1));
	switch ($xfgrou)
	{
	case 'M':
		$xfecha1=date('Y/m/'.'1',strtotime($xfecha1));
		
		if($dias<=31)
		{$xfecha1=date('Y/m/'.'1',strtotime('-2 month',strtotime($xfecha1)));}

		//if($dias>360)
		//{$xfecha1=date('Y/'.'1/1',strtotime($xfecha1));}

		//if($anios!=0)
		//{$xfecha1=date('Y/'.'1/1',strtotime($xfecha1));}
		
		$xfecha2=date('Y/m/t',strtotime($xfecha2));
		break;

	case 'S':
		if($dias<=7)
		{$xfecha1=date('Y/m/d',strtotime('-1 month',strtotime($xfecha1)));}
		
		$xfecha1=date('Y/m/d',strtotime('-'.date('w',strtotime($xfecha1)).' day',strtotime($xfecha1)));
		$xfecha2=date('Y/m/d',strtotime('+'.(6-date('w',strtotime($xfecha2))).' day',strtotime($xfecha2)));

		break;
	}

	$sql_vtast.='fecha BETWEEN "'.$xfecha1.'" and "'.$xfecha2.'"';
	$sql_vtast.='and fanio BETWEEN "'.$xanio1.'" and "'.$xanio2.'"';



$sql_vtast.=')';
//echo $sql_vtast;


$sql_vtast=str_replace(')(',')||(',$sql_vtast);

if(isset($_GET['fdocu']) && !empty($_GET['fdocu']))
{
	//$sql_vtast.=' and  (docu like "'.$_GET['fdocu'].'%" or docu_descri like "%'.$_GET['fdocu'].'%" ) ';
	$sql_vtast.=' and  (docu like "'.$_GET['fdocu'].'%"  ) ';
	$xfdocu=$_GET['fdocu'];
}



if(isset($_GET['fenti']) && !empty($_GET['fenti']))
{
	$sql_vtast.=' and  (enti like "'.$_GET['fenti'].'%" or enti_descri like "%'.$_GET['fenti'].'%" ) ';
	$xfenti=$_GET['fenti'];
}

if(isset($_GET['fitem']) && !empty($_GET['fitem']))
{
	$sql_vtast.=' and  (item like "'.$_GET['fitem'].'%" or item_descri like "%'.$_GET['fitem'].'%" ) ';
	$xfitem=$_GET['fitem'];
}



if(isset($_GET['fcdad']) && !empty($_GET['fcdad']))
{
	$sql_vtast.=' and  (prvc_descri like "%'.$_GET['fcdad'].'%" or enti_cdad like "'.$_GET['fcdad'].'%" or cdad_descri like "%'.$_GET['fcdad'].'%"  ) ';
	$xfcdad=$_GET['fcdad'];
}

if(isset($_GET['fzsub']) && !empty($_GET['fzsub']))
{
	$sql_vtast.=' and  (enti_zsub like "'.$_GET['fzsub'].'%" or zsub_descri like "%'.$_GET['fzsub'].'%" ) ';
	$xfzsub=$_GET['fzsub'];
}

if(isset($_GET['flsub']) && !empty($_GET['flsub']))
{
	$sql_vtast.=' and  (item_lsub like "'.$_GET['flsub'].'%" or lsub_descri like "%'.$_GET['flsub'].'%" ) ';
	$xflsub=$_GET['flsub'];
}


if(isset($_GET['fvndd']) && !empty($_GET['fvndd']))
{
	$sql_vtast.=' and  (vndd like "'.$_GET['fvndd'].'%" ) ';
	$xfvndd=$_GET['fvndd'];
}

if(isset($_GET['frcdd']) && !empty($_GET['frcdd']))
{
	//$sql_vtast.=' and  (enti like "%'.$_GET['frcdd'].'%" ) ';
	$xfrcdd=$_GET['frcdd'];
}




if(isset($_GET['fctlg']) && !empty($_GET['fctlg']))
{
	//$sql_vtast.=' and  (enti_nctlg ='.$_GET['fctlg'].' )';
	$xfctlg=$_GET['fctlg'];
}

	$sql_vtast.=' and(status!="X") ';
if($xfgrou!="D")
{$sql_vtast.=' and(status!="O") ';}

if (mb_stristr('gnya',$_SESSION['user_vcrx_empr']))
{$sql_vtast.=' and(docu!="NV13") ';}



$xforde='D';
if(isset($_GET['forde']) && !empty($_GET['forde']))
{$xforde=$_GET['forde'];}

switch ($xfgrou)
{
	case 'D':$xgroup='docu,ptoe,numero,idnum1 ';break;
	case 'E':$xgroup='enti_zsub,enti_descri,enti ';break;
	case 'I':$xgroup='item_lsub,item_descri,item  ';break;

	case 'P':$xgroup='ptoe ';break;
	case 'V':$xgroup='vndd ';break;
	case 'Z':$xgroup='zsub ';break;
	case 'L':$xgroup='item_lsub ';break;
	case 'R':$xgroup='item_at10 ';break;
	case 'C':$xgroup='cdad ';break;

	case 'A':$xgroup='fanio ';break;
	case 'M':$xgroup='fanio,fmes ';break;
	case 'S':$xgroup='fanio,fsema ';break;
	case 'F':$xgroup='fecha ';break;

	default :$xgroup='';break;
}



switch ($xforde)
{
	case 'D':$xorder=$xgroup;break;
	case 'C':$xorder=str_replace('_descri','',$xgroup);
			$xorder=str_replace(',item',','.$item_codi.',item_descri,item',$xorder);break;
	case 'T':$xorder='ttotal desc, '.str_replace('_descri','',$xgroup);break;

	default :$xorder=$xgroup;break;
}

//$xorder=str_replace('_codigo','',$xorder)


$res_vtastt=mysql_query($sql_vtast,$link_vcrx);
$xttdcto=mysql_result($res_vtastt,0,'ttdcto');
$xttice=mysql_result($res_vtastt,0,'ttice');
$xttiva=mysql_result($res_vtastt,0,'ttiva');
$xttirbp=mysql_result($res_vtastt,0,'ttirbp');



$sql_vtast.=' group by '.$xgroup;

$sql_vtast.=' order by '.$xorder;
//echo $sql_vtast;
$res_vtast=mysql_query($sql_vtast,$link_vcrx);
$totreg = mysql_num_rows($res_vtast);


switch ($xfgrou)
{
	case 'D':$xgroup='DOCUMENTO ';break;
	case 'E':$xgroup='ZONA / CLIENTE ';break;
	case 'I':$xgroup='LINEA / ITEM';break;

	case 'P':$xgroup='PTO.EMISION ';break;
	case 'V':$xgroup='VENDEDOR ';break;
	case 'Z':$xgroup='ZONAS ';break;
	case 'L':$xgroup='LINEAS ';break;
	case 'R':$xgroup='COD.RET. ';break;
	case 'C':$xgroup='CIUDAD ';break;

	case 'A':$xgroup='ANIO ';break;
	case 'M':$xgroup='MESES ';break;
	case 'S':$xgroup='SEMANAS';break;
	case 'F':$xgroup='FECHA ';break;

	default :$xgroup='';break;
}



switch ($xforde)
{
	case 'D':$xorder='NOMBRE ';break;
	case 'C':$xorder='CODIGO ';break;
	case 'T':$xorder='TOTALES';break;

	default :$xorder='';break;
}





?>


<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>Ventas Totales (Cliente)</title>
<style type="text/css">
body{ font-family:"Courier New", Courier, monospace;}
H1.SaltoDePagina{PAGE-BREAK-BEFORE: always}

</style>





</head>
<body>

<div align="center">
<div align="center" style="width:1100px; font-size:12px;">
<div align="center" style="font-size:18px; border:#000 solid 1px; background: #F7F7F7; margin:2px; font-weight: bold;">VENTAS TOTALES</div>

<table width="100%" cellspacing="0" cellpadding="2">
<tr valign="top">
<td width="50%">

<table border="1" width="100%" cellpadding="2" cellspacing="0" style="border-collapse:collapse">
<tr>
	<th width="30%" style="background: #F7F7F7;">PARAMETROS</th>
	<th></th>
</tr>

<tr>
    	<td style="font-weight:bolder;">FECHA</td>
	<td><?php echo date_format(date_create($xfecha1),'d/M/Y').' - '.date_format(date_create($xfecha2),'d/M/Y');?></td>
</tr>

<?php	
if(isset($_GET['fenti']) && !empty($_GET['fenti']))
{
$sql_descri='select * from enti0 where enti_codigo like "'.$_GET['fenti'].'%"';
$res_descri=mysql_query($sql_descri,$link_vcrx);
$enti_descri=mysql_result($res_descri,0,'enti_descri');	
?>
	<tr>
    	<td style="font-weight:bolder;">CLIENTE</td>
    	<td><?php echo $_GET['fenti'].'-'.$enti_descri;?></td>
    </tr>
<?php	
}
?>
	
<?php	
if(isset($_GET['fitem']) && !empty($_GET['fitem']))
{
$sql_descri='select * from item0 where item_codigo like "'.$_GET['fitem'].'%"';
$res_descri=mysql_query($sql_descri,$link_vcrx);
$item_descri=mysql_result($res_descri,0,'item_descri');	
?>
	<tr>
    	<td style="font-weight:bolder;">ITEM</td>
    	<td><?php echo $_GET['fitem'].'-'.$item_descri;?></td>
    </tr>
<?php	
}
?>
	
	<tr>
    	<td style="font-weight:bolder;">AGRUPADO X</td>
    	<td><?php echo $xgroup;?></td>
    </tr>

	<tr>
    	<td style="font-weight:bolder;">ORDENADO X</td>
    	<td><?php echo $xorder;?></td>
    </tr>



</table>




<td>
<!----++++++++++------>
<table border="1" width="100%" cellspacing="0" cellpadding="2" style="border-collapse:collapse">
<tr>
	<th width="30%"  style="background: #F7F7F7;">I N F O</th>
	<th></th>    
</tr>

<?php
$sql_empr='select * from empr0';
$res_empr=mysql_query($sql_empr,$link_vcrx);
?>
<tr>
	<td align="right">EMPRESA:</td>
	<td><?php echo mysql_result($res_empr,0,'empr_descri');?></td>
</tr>

<tr>
	<td align="right">USUARIO:</td>
	<td><?php echo $_SESSION['user_vcrx_id'].' / '.$_SESSION['user_vcrx_descri'];?></td>
</tr>
<tr>
	<td align="right">FECHA / HORA :</td>
	<td><?php echo date('d/M/Y H:i:s');?></td>
</tr>
</table>
<!----++++++++++------>
</td>




</tr>
</table>
<!----++++++++++------>


<hr/>

<table border="0" width="100%" cellpadding="2" cellspacing="0" style="border-collapse:collapse">

<thead>
<tr align="center" style="background: #F7F7F7; border-top:solid 1px#000;border-bottom:solid 1px#000">
<?php
switch ($xfgrou)
{
	case 'D':
?>
	<th>DOCU</th>
	<th>PTO/NUMERO</th>
	<th>FECHA</th>
	<th>NOMBRE</th>
	<th></th>


<?php	
	break;
	case 'E':
?>

	<th></th>
	<th>ZONA</th>
	<th>CLIENTE</th>
	<th>NOMBRE</th>
	<th></th>


<?php	
	break;
	case 'I':
?>
	<th></th>
	<th>LINEA</th>
	<th>ITEM</th>
	<th>NOMBRE</th>
	<th>CANT</th>


<?php	
	break;
	case 'M':
?>
	<th></th>
	<th>ANIO</th>
	<th>MES</th>
	<th>NOMBRE</th>
	<th></th>
<?php	
	break;
	case 'S':
?>
	<th></th>
	<th>ANIO</th>
	<th>SEMA</th>
	<th></th>
	<th></th>
<?php	
	break;
	case 'F':
?>
	<th></th>
	<th>ANIO</th>
	<th>MES</th>
	<th>FECHA</th>
	<th></th>

<?php	
	break;
	case 'P':
?>
	<th></th>
	<th>PTO/EMI</th>
	<th></th>
	<th></th>
	<th></th>

<?php	
	break;
	case 'V':
?>
	<th></th>
	<th>VNDD</th>
	<th>NOMBRE</th>
	<th></th>
	<th></th>

<?php	
	break;
	case 'Z':
?>
	<th></th>
	<th>ZONA</th>
	<th>NOMBRE</th>
	<th></th>
	<th></th>

<?php	
	break;
	case 'L':
?>
	<th></th>
	<th>LINEA</th>
	<th>NOMBRE</th>
	<th></th>
	<th></th>

<?php	
	break;
	case 'R':
?>
	<th></th>
	<th>COD.RET.</th>
	<th>NOMBRE</th>
	<th></th>
	<th></th>


<?php } ?>

	<th>SUBT</th>

<?php if($xttdcto!=0){ ?>	
	<th>DCTO</th>
<?php } ?>

<?php if ($xttice!=0){ ?>	
	<th>ICE</th>
<?php } ?>

	<th>ST-IVA 0</th>

<?php if ($xttiva!=0){ ?>	
	<th>ST-IVA</th>
	<th>IVA</th>
<?php } ?>

<?php if ($xttirbp!=0){ ?>	
	<th>IRBP</th>
<?php } ?>

	<th>TOTAL</th>

<?php
switch ($xfgrou)
{
	case 'D':
?>
	<th>CRE</th>
	<th>PROVINCIA /CIUDAD</th>
	<th>VENDEDOR</th>

<?php	
	break;
	case 'E':
?>
	<th>PROVINCIA /CIUDAD</th>
	<th>VENDEDOR</th>

<?php	
	break;
	case 'I':
?>
	<th>MARCA/MODELO</th>
	<th></th>
<?php } ?>



</tr>


  </thead>


<!-- </tr> -->

<?php 
$filax=0;
//$urcdd='';
//$res_vtast=mysql_query($sql_vtast,$link_vcrx);

while($r_vtast=mysql_fetch_assoc($res_vtast))
{
$duni=$r_vtast['item_duni'];
?>

<tr class="filax" id="<?php echo $r_ped['idnum1']; ?>" align="center" style=" <?php if($filax>=4){echo 'border-top:dotted 1px #000;';$filax=1;}else{$filax++;} ?>" >

<?php
switch ($xfgrou)
{
	case 'D':
?>

        <td align="center"><?php echo'<span title="'.$r_vtast['docu'].'">'.$r_vtast['docu'].'</span>';?></td>
	<td align="center"><?php echo '<span title="'.$r_vtast['ptonumero'].'">'.$r_vtast['ptonumero'].'</span>';?></a> </td>
	<td align="center"><?php echo'<span title="'.$r_vtast['fechadmy'].'">'.$r_vtast['fechadmy'].'</span>';?></td>
	<td align="left"><?php echo'<span title="'.$r_vtast['enti'].'">'.$r_vtast['enti_descri'].'</span>';?></td>
	<td></td>


<?php	
	break;
	case 'E':
?>
	<td></td>
        <td align="center"><?php echo'<span title="'.$r_vtast['enti_zsub'].'">'.$r_vtast['zsub_descri'].'</span>';?></td>
	<td align="left"><?php echo '<span title="'.$r_vtast['enti'].'">'.$r_vtast['enti'].'</span>';?></a> </td>
	<td align="left"><?php echo'<span title="'.$r_vtast['enti_direccion'].'">'.$r_vtast['enti_descri'].'</span>';?></td>
	<td></td>


<?php	
	break;
	case 'I':
?>
	<td></td>
        <td align="center"><?php echo'<span title="'.$r_vtast['item_lsub'].'">'.$r_vtast['lsub_descri'].'</span>';?></td>
	<td align="left"><?php echo '<span title="'.$r_vtast['item'].'">'.$r_vtast[$item_codi].'</span>';?></a> </td>
	<td align="left"><?php echo'<span title="'.$r_vtast['item_mrca'].'">'.$r_vtast['item_descri'].'</span>';?></td>
   	<td align="right"><?php echo number_format($r_vtast['ttcant'],$duni);?></td>


<?php	
	break;
	case 'M':
?>
	<td></td>
        <td align="center"><?php echo'<span title="'.$r_vtast['fanio'].'">'.$r_vtast['fanio'].'</span>';?></td>
	<td align="center"><?php echo '<span title="'.$r_vtast['fmes'].'">'.$r_vtast['fmes'].'</span>';?></a> </td>
	<td align="center"><?php echo'<span title="'.$r_vtast['fmesn'].'">'.$r_vtast['fmesn'].'</span>';?></td>
	<td></td>

<?php	
	break;
	case 'S':
?>
	<td></td>
        <td align="center"><?php echo'<span title="'.$r_vtast['fanio'].'">'.$r_vtast['fanio'].'</span>';?></td>
	<td align="center"><?php echo '<span title="'.$r_vtast['fsema'].'">'.$r_vtast['fsema'].'</span>';?></a> </td>
	<td align="left"></td>
	<td></td>

<?php	
	break;
	case 'F':
?>
	<td></td>
        <td align="center"><?php echo'<span title="'.$r_vtast['fanio'].'">'.$r_vtast['fanio'].'</span>';?></td>
	<td align="center"><?php echo'<span title="'.$r_vtast['fmesn'].'">'.$r_vtast['fmesn'].'</span>';?></td>
	<td align="center"><?php echo '<span title="'.$r_vtast['fechadmy'].'">'.$r_vtast['fdian'].'-'.$r_vtast['fdia'].'</span>';?></a> </td>
	<td></td>

<?php	
	break;
	case 'P':
?>
	<td></td>
	<td align="left"><?php echo '<span title="'.$r_vtast['ptoe'].'">'.$r_vtast['ptoe'].'</span>';?></a> </td>
	<td align="left"></td>
	<td align="left"></td>
	<td></td>

<?php	
	break;
	case 'V':
?>
	<td></td>
        <td align="center"><?php echo'<span title="'.$r_vtast['vndd'].'">'.$r_vtast['vndd'].'</span>';?></td>
	<td align="left"><?php echo '<span title="'.$r_vtast['vndd_descri'].'">'.$r_vtast['vndd_descri'].'</span>';?></a> </td>
	<td align="left"></td>
	<td></td>

<?php	
	break;
	case 'Z':
?>
	<td></td>
        <td align="center"><?php echo'<span title="'.$r_vtast['zsub'].'">'.$r_vtast['zsub'].'</span>';?></td>
	<td align="left"><?php echo '<span title="'.$r_vtast['zsub_descri'].'">'.$r_vtast['zsub_descri'].'</span>';?></a> </td>
	<td align="left"></td>
	<td></td>

<?php	
	break;
	case 'L':
?>
	<td></td>
        <td align="center"><?php echo'<span title="'.$r_vtast['item_lsub'].'">'.$r_vtast['item_lsub'].'</span>';?></td>
	<td align="left"><?php echo '<span title="'.$r_vtast['lsub_descri'].'">'.$r_vtast['lsub_descri'].'</span>';?></a> </td>
	<td align="left"></td>
	<td></td>

<?php	
	break;
	case 'R':
?>
	<td></td>
        <td align="center"><?php echo'<span title="'.$r_vtast['item_at10'].'">'.$r_vtast['item_at10'].'</span>';?></td>
	<td align="left"><?php echo '<span title="'.$r_vtast['at10_descri'].'">'.$r_vtast['at10_descri'].'</span>';?></a> </td>
	<td align="left"></td>
	<td></td>



<?php }?>



   	<td align="right"><?php echo number_format($r_vtast['ttsubt'],2);?></td>


<?php if($xttdcto!=0){ ?>	
   	<td align="right"><?php echo '<i>'.number_format($r_vtast['ttdcto'],2);?></td>
<?php } ?>

<?php if ($xttice!=0){ ?>	
   	<td align="right"><?php echo number_format($r_vtast['ttice'],2);?></td>
<?php } ?>

   	<td align="right"><?php echo number_format($r_vtast['ttsubtiva0'],2);?></td>

<?php if ($xttiva!=0){ ?>	
   	<td align="right"><?php echo number_format($r_vtast['ttsubtiva'],2);?></td>
   	<td align="right"><?php echo number_format($r_vtast['ttiva'],2);?></td>
<?php } ?>

<?php if ($xttirbp!=0){ ?>	
   	<td align="right"><?php echo number_format($r_vtast['ttirbp'],2);?></td>
<?php } ?>

   	<td align="right"><?php echo '<b>'.number_format($r_vtast['ttotal'],2);?></td>




<?php
switch ($xfgrou)
{
	case 'D':
?>
        <td align="center"><?php if($r_vtast['plazo']>0){echo "S";}else{echo "N";};?></td>
        <td align="center"><?php echo'<span title="'.$r_vtast['cdad_descri'].'">'.$r_vtast['cdad_descri'].'</span>';?></td>
	<td align="center"><?php echo'<span title="'.$r_vtast['vndd'].'">'.$r_vtast['vndd'].'</span>';?></td>

<?php	
	break;
	case 'E':
?>

	<td align="center"><?php echo'<span title="'.$r_vtast['enti_telefono'].'">'.$r_vtast['prvc_descri'].' /'.$r_vtast['cdad_descri'].'</span>';?></td>
	<td align="center"><?php echo'<span title="'.$r_vtast['vndd'].'">'.$r_vtast['vndd'].'</span>';?></td>

<?php	
	break;
	case 'I':
?>
	<td align="center"><?php echo'<span title="'.$r_vtast['item_mrca'].'">'.$r_vtast['item_mrca'].' /'.$r_vtast['item_modelo'].'</span>';?></td>
	<td align="center"></td>
<?php }?>





</tr>
<?php }?>

<tr align="center" style="background: #F7F7F7; border-top:solid 1px#000;border-bottom:solid 1px#000">
	<th></th>
	<th></th>
	<th></th>
	<th>TOTALES</th>
	<th align="right">&nbsp;<?php echo number_format(mysql_result($res_vtastt,0,'ttcant'),2);?></th>
	<th align="right">&nbsp;<?php echo number_format(mysql_result($res_vtastt,0,'ttsubt'),2);?></th>
	
<?php if($xttdcto!=0){ ?>	
	<th align="right">&nbsp;<?php echo '<i>'.number_format(mysql_result($res_vtastt,0,'ttdcto'),2);?></th>
<?php } ?>

<?php if ($xttice!=0){ ?>	
	<th align="right">&nbsp;<?php echo number_format(mysql_result($res_vtastt,0,'ttice'),2);?></th>
<?php } ?>

	<th align="right">&nbsp;<?php echo number_format(mysql_result($res_vtastt,0,'ttsubtiva0'),2);?></th>

<?php if ($xttiva!=0){ ?>	
	<th align="right">&nbsp;<?php echo number_format(mysql_result($res_vtastt,0,'ttsubtiva'),2);?></th>
	<th align="right">&nbsp;<?php echo number_format(mysql_result($res_vtastt,0,'ttiva'),2);?></th>
<?php } ?>

<?php if ($xttirbp!=0){ ?>	
	<th align="right">&nbsp;<?php echo number_format(mysql_result($res_vtastt,0,'ttirbp'),2);?></th>
<?php } ?>

	<th align="right">&nbsp;<?php echo number_format(mysql_result($res_vtastt,0,'ttotal'),2);?></th>
</tr>
<tr align="center" style="background: #F7F7F7; border-top:solid 1px#000;border-bottom:solid 1px#000">
	<th></th>
	<th></th>
	<th></th>
	<th>PROMEDIOS</th>
	<th align="right"><?php echo number_format(mysql_result($res_vtastt,0,'ttcant')/$totreg,2);?></th>
	<th align="right"><?php echo number_format(mysql_result($res_vtastt,0,'ttsubt')/$totreg,2);?></th>
	
<?php if($xttdcto!=0){ ?>	
	<th align="right"><?php echo '<i>'.number_format(mysql_result($res_vtastt,0,'ttdcto')/$totreg,2);?></th>
<?php } ?>

<?php if ($xttice!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_vtastt,0,'ttice')/$totreg,2);?></th>
<?php } ?>

	<th align="right"><?php echo number_format(mysql_result($res_vtastt,0,'ttsubtiva0')/$totreg,2);?></th>

<?php if ($xttiva!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_vtastt,0,'ttsubtiva')/$totreg,2);?></th>
	<th align="right"><?php echo number_format(mysql_result($res_vtastt,0,'ttiva')/$totreg,2);?></th>
<?php } ?>

<?php if ($xttirbp!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_vtastt,0,'ttirbp')/$totreg,2);?></th>
<?php } ?>

	<th align="right"><?php echo number_format(mysql_result($res_vtastt,0,'ttotal')/$totreg,2);?></th>
</tr>




</table>
<br />





<?php 
if (mb_stristr('L.Z',$_GET['fgrou']))
//if($_GET['fgrou']=='L')
{
?>
<H1 class=SaltoDePagina> </H1>
<?php 
for($vu=1;$vu<=2;$vu++)
{
$sql_empr='select * from empr0';
$res_empr=mysql_query($sql_empr,$link_vcrx);

$valtot=mysql_result($res_vtastt,0,'ttsubtiva0')+mysql_result($res_vtastt,0,'ttsubtiva');
if ($vu==2){$valtot=mysql_result($res_vtastt,0,'ttcant');}
	
$sql_vtast=str_replace('group by item_lsub','group by left(item_lsub,4)',$sql_vtast);
$sql_vtast=str_replace('order by','order by ttotal desc,',$sql_vtast);
$columna= mysql_num_rows($res_vtast);
$colini=0;
//echo  $sql_vtast;
$ancho=1000;
$alto=600;
$lienzo = imagecreatetruecolor($ancho, $alto);

$rosa = imagecolorallocate($lienzo, 255, 105, 180);
$rojo = imagecolorallocate($lienzo, 255, 0, 0);
$negro = imagecolorallocate($lienzo, 0, 0, 0);
$blanco = imagecolorallocate($lienzo, 255, 255, 255);
$verde = imagecolorallocate($lienzo, 180, 255, 180);
$azul = imagecolorallocate($lienzo, 0, 0, 255);
$azul = imagecolorallocate($lienzo, 102, 102, 255);
$celeste = imagecolorallocate($lienzo, 77, 195, 246);
$amarillo = imagecolorallocate($lienzo, 255, 255, 102);
$gris = imagecolorallocate($lienzo, 100, 100, 100);
$fondo=imagecolorallocate($lienzo,255,255,255);

ImageFill($lienzo,50,50,$fondo);

$archivo_fuente = '../../_css/cour.ttf';

$x1=intval($ancho*.6);
$y1=intval($alto*.6);

$r1=450;
$x1=($r1*.5)+50;
$y1=($alto*.5)+50;

imagefttext($lienzo, 15, 0, 40, 40 , $negro, $archivo_fuente,'Ventas Totales X Linea');
imagefttext($lienzo, 15, 0, 40, 40 , $negro, $archivo_fuente,'Ventas Totales X Linea');
imagefttext($lienzo, 10, 0, 40, 60 , $negro, $archivo_fuente,'Fechas :'.date_format(date_create($xfecha1),'d/M/Y').' - '.date_format(date_create($xfecha2),'d/M/Y'));

$empresa=mysql_result($res_empr,0,'empr_descri');
$empr_codigo=mysql_result($res_empr,0,'empr_codigo');
imagefttext($lienzo, 15, 0, $ancho-strlen($empresa)*15-45, 40 , $negro, $archivo_fuente,$empresa);
imagefttext($lienzo, 15, 0, $ancho-strlen($empresa)*15-45, 40 , $negro, $archivo_fuente,$empresa);

$diez=10;
$mil=$valmax;


$res_vtast=mysql_query($sql_vtast,$link_vcrx);
$xcol=0;
$ames=0;
$umes=0;
$uanio=0;
$canio=0;

$x2=0;
$y2=0;
//$columna=20;

$colora=array($celeste,$amarillo,$rojo,$verde,$azul,$rosa,$gris);

while($r_vtast=mysql_fetch_assoc($res_vtast))
{
$color=$colora[$xcol%7];
$xcol++;
if ($xcol>=$colini)
{
	$tope = (($r_vtast['ttsubtiva0']+$r_vtast['ttsubtiva'])/$valtot);
	if ($vu==2){$tope = (($r_vtast['ttcant'])/$valtot);}
	$y2=$x2+(360*$tope);
//	$y2=$x2+360*((100/$columna)/100);
	imagefilledarc($lienzo, $x1, $y1, $r1, $r1, $x2, $y2, $color,IMG_ARC_PIE);

	$x2=$y2;
	imagefilledrectangle($lienzo, $r1+150, 100+($xcol*40),  $r1+180, (100+($xcol*40))+30, $color);

	imagefttext($lienzo, 10, 0, $r1+190, 100+($xcol*40)+15 , $negro, $archivo_fuente,str_pad(number_format($tope*100,2).'%',7,' ',STR_PAD_LEFT).' '.$r_vtast['lsub_descri']);
	imagefttext($lienzo, 10, 0, $r1+190, 100+($xcol*40)+15 , $negro, $archivo_fuente,str_pad(number_format($tope*100,2).'%',7,' ',STR_PAD_LEFT).' '.$r_vtast['lsub_descri']);


}
}

$x2=0;
$y2=0;

$res_vtast=mysql_query($sql_vtast,$link_vcrx);
while($r_vtast=mysql_fetch_assoc($res_vtast))
{
$xcol++;
if ($xcol>=$colini)
{
	$tope = ($r_vtast['ttsubtiva0']+$r_vtast['ttsubtiva'])/$valtot;
	if ($vu==2){$tope = ($r_vtast['ttcant'])/$valtot;}
	$y2=$x2+(360*$tope);
//	$y2=$x2+360*((100/$columna)/100);

	$y2b=$x2+($y2-$x2)/2;
	$x3=(cos(deg2rad($y2b)));
	$y3=(sin(deg2rad($y2b)));

	$y2b=360-$y2b;

	if($y2b>90 && $y2b<270)
	{
	$y2b=$y2b-180;
	$x3=$x1+($r1*.49*$x3);
	$y3=$y1+($r1*.49*$y3);
	}
	else
	{
	$x3=$x1+($r1*.35*$x3);
	$y3=$y1+($r1*.35*$y3);
	}
	
	$xsizef=15;
	if ($tope<.50){$xsizef=10;}
	if ($tope<.01){$xsizef=7;}
	
	imagefttext($lienzo, $xsizef, $y2b, $x3, $y3, $negro, $archivo_fuente,$r_vtast['item_lsub'].' '.number_format($tope*100,2).'%');
	imagefttext($lienzo, $xsizef, $y2b, $x3, $y3, $negro, $archivo_fuente,$r_vtast['item_lsub'].' '.number_format($tope*100,2).'%');
	$x2=$y2;
}
}


$gfile=$empr_codigo.date("is").$vu.".png";
	
$im = imagecreatetruecolor(300, 100);
$rojo = imagecolorallocate($im, 0xFF, 0x00, 0x00);
$negro = imagecolorallocate($im, 0x00, 0x00, 0x00);
imagefilledrectangle($im, 0, 0, 299, 99, $rosa);
// imagejpeg($lienzo,"demo".$vu.".png");
imagejpeg($lienzo,$gfile);
imagedestroy($lienzo); 
?>
<img src="<?php echo $gfile;?>" style="border:solid 1px #000;" align="center" />
<br></br>
<?php
}
?>
<!-- <img src="demo1.png" style="border:solid 1px #000;" align="center" />
<br></br> -->
<!-- <img src="demo2.png" style="border:solid 1px #000;" align="center"/> -->
<?php
if ($xfitem>"")
{
?>
<?php
}
}
?>






<?php 
if($_GET['fgrou']=='M')
{
?>
<H1 class=SaltoDePagina> </H1>

<?php
	
for($vu=1;$vu<=2;$vu++)
{

$sql_empr='select * from empr0';
$res_empr=mysql_query($sql_empr,$link_vcrx);

$valtot=mysql_result($res_vtastt,0,'ttsubtiva0')+mysql_result($res_vtastt,0,'ttsubtiva');
if ($vu==2){$valtot=mysql_result($res_vtastt,0,'ttcant');}	
//echo '-'.$valtot;
	
$valpro=$valtot/$totreg;	
	
$sql_vtast1=str_replace('order by','order by ttotal desc,',$sql_vtast);
$res_vtast1=mysql_query($sql_vtast1,$link_vcrx);
$valmax=mysql_result($res_vtast1,0,'ttsubtiva0')+mysql_result($res_vtast1,0,'ttsubtiva');
if ($vu==2){$valmax=mysql_result($res_vtast1,0,'ttcant');}

$divisor=1;
if ($valmax>=100){$divisor=10;}
if ($valmax>=1000){$divisor=100;}
if ($valmax>=10000){$divisor=1000;}
if ($valmax>=100000){$divisor=10000;}
$valmax=intval($valmax/$divisor)+1;
$valmax2=$valmax*$divisor+$divisor;

$compara=0;
$xanios=date('Y',strtotime($xfecha2b))-date('Y',strtotime($xfecha1b))+1;
$xanio1=date('Y',strtotime($xfecha1b));
$xanio2=date('Y',strtotime($xfecha2b));

$sql_vtast=str_replace('order by','order by fanio,fmes,',$sql_vtast);
$columna= mysql_num_rows($res_vtast);
$colini=0;

$ancho=1000;
$alto=600;
$btop=100;
$bbot=100;
$alto2=$alto-$btop-$bbot;


$lienzo = imagecreatetruecolor($ancho, $alto);

$rosa = imagecolorallocate($lienzo, 255, 105, 180);
$rojo = imagecolorallocate($lienzo, 255, 0, 0);
$negro = imagecolorallocate($lienzo, 0, 0, 0);
$gris = imagecolorallocate($lienzo, 100, 100, 100);
$blanco = imagecolorallocate($lienzo, 255, 255, 255);
$verde = imagecolorallocate($lienzo, 180, 255, 180);
$azul = imagecolorallocate($lienzo, 0, 0, 255);
$azul = imagecolorallocate($lienzo, 102, 102, 255);
$celeste = imagecolorallocate($lienzo, 77, 195, 246);
$amarillo = imagecolorallocate($lienzo, 255, 255, 102);
$gris = imagecolorallocate($lienzo, 100, 100, 100);
$fondo=imagecolorallocate($lienzo,255,255,255);

//if ($alto<500){$alto=500;}


$colmax=48;
if($columna>12){$compara=1;}
if($columna>$colmax){$colini=$columna-$colmax+1;}
if($columna>$colmax){$columna=$colmax;}
if($colini<0){$colini=0;}

//$compara=0;

$barra=intval(($ancho-50)/($columna*2));

$x1=40;
$xt=190;
$x2=$x1;
if($compara==1)
{
$sql_vtast=str_replace('order by fanio,fmes','order by fmes,fanio',$sql_vtast);
$colini=0;
$barra=intval(($ancho-50)/($columna+12));
}

if($barra>40){$barra=40;}
if($barra<12){$barra=12;}

if($compara==1)
{$x2=$x2-($barra*.7*.3);}


ImageFill($lienzo,50,50,$fondo);
$archivo_fuente = '../../_css/cour.ttf';
imagefttext($lienzo, 15, 0, 40, 40 , $negro, $archivo_fuente,'Ventas Totales X Mes');
imagefttext($lienzo, 15, 0, 40, 40 , $negro, $archivo_fuente,'Ventas Totales X Mes');

if ($vu==1)
{imagefttext($lienzo, 10, 0, 40, 60 , $negro, $archivo_fuente,'(X $'.number_format($divisor,0).')');}
	
if ($vu==2)
{imagefttext($lienzo, 10, 0, 40, 60 , $negro, $archivo_fuente,'(X '.number_format($divisor,0).' UNDS.)');}

$empresa=mysql_result($res_empr,0,'empr_descri');
$empr_codigo=mysql_result($res_empr,0,'empr_codigo');
	
imagefttext($lienzo, 15, 0, $ancho-strlen($empresa)*15-45, 40 , $negro, $archivo_fuente,$empresa);
imagefttext($lienzo, 15, 0, $ancho-strlen($empresa)*15-45, 40 , $negro, $archivo_fuente,$empresa);

imageline($lienzo,48,$btop,48,$alto-$bbot,$negro);//linea y

$diez=($alto-$btop-$bbot)/10;
$mil=$valmax2/$divisor;
$mild=$mil/10;

//echo $valmax2;	
	
for($i=1;$i<=11;$i++)
{
	$y1=$i*$diez+60;
	for ($j=45;$j<=950;$j=$j+10)
	{imageline($lienzo,$j,$y1,$j+5,$y1,$gris);	}
	//imageline($lienzo,45,$y1,950,$y1,$negro);
	imagefttext($lienzo, 9, 0, 10, $y1 , $negro, $archivo_fuente,str_pad(number_format($mil,1),4,"  ",STR_PAD_LEFT));
	$mil=abs($mil-$mild);
}
imageline($lienzo,45,$y1,950,$y1,$negro);

//echo $sql_vtast;
$res_vtast=mysql_query($sql_vtast,$link_vcrx);
$xcol=0;
$ames=0;
$umes=0;

while($r_vtast=mysql_fetch_assoc($res_vtast))
{
	$color=$celeste;
	if($r_vtast['fanio']==$xanio2-1){$color=$verde;}
	if($r_vtast['fanio']==$xanio2-2){$color=$rosa;}
	if($r_vtast['fanio']==$xanio2-3){$color=$amarillo;}
	if($r_vtast['fanio']<=$xanio2-4){$color=$azul;}

$xcol++;
if ($xcol>=$colini)
{
	if($compara==1)
	{
		$x1=$x2;
		if($r_vtast['fmes']>$umes)
		{
		$x1=$x2+$barra*.7;
		$umes=$r_vtast['fmes'];
		imagefttext($lienzo, 10, 0, $x1+0, $alto-$bbot+30, $negro, $archivo_fuente,$r_vtast['fmesn']);
		}
		imagefttext($lienzo, $barra/2.5, 0, $x1+0, $alto-$bbot+45, $negro, $archivo_fuente,'/'.substr($r_vtast['fanio'],2,2));
	}
	else
	{
		$x1=$x2+intval($barra/2);
		imagefttext($lienzo, 10, 0, $x1+0, $alto-$bbot+30, $negro, $archivo_fuente,$r_vtast['fmesn']);
		imagefttext($lienzo, 10, 0, $x1+0, $alto-$bbot+45, $negro, $archivo_fuente,'/'.substr($r_vtast['fanio'],2,2));
	}

	$x2=$x1+$barra;

	$b3d=$barra/2;
	$b3d=0;
	
	$tope = ($r_vtast['ttsubtiva0']+$r_vtast['ttsubtiva'])/$valmax2*$alto2;
	if($vu==2){$tope = ($r_vtast['ttcant'])/$valmax2*$alto2;}
	
	imagefilledrectangle($lienzo, $x1+1, $alto-$bbot-1, $x2+1, $alto-$bbot-$tope-1, $gris);
	for ($x3d=$b3d-1;$x3d>0;$x3d--)
	{imagefilledrectangle($lienzo, $x1+$x3d, $alto-100-$x3d, $x2+$x3d, $alto-100-$tope-$x3d, $gris);}
	imagefilledrectangle($lienzo, $x1, $alto-$bbot, $x2, $alto-$bbot-$tope, $color);

	$tope = ($r_vtast['ttsubtiva'])/$valmax2*$alto2;
	if ($vu==2){$tope = ($r_vtast['ttcant'])/$valmax2*$alto2;}
	imagefilledrectangle($lienzo, $x1+1, $alto-$bbot-1, $x2-0, $alto-$bbot-$tope-1, $gris);
	imagefilledrectangle($lienzo, $x1, $alto-$bbot, $x2-1, $alto-$bbot-$tope, $color);

	$tope = ($r_vtast['ttsubtiva0']+$r_vtast['ttsubtiva'])/$valmax2*$alto2;
	if($vu==2){$tope = ($r_vtast['ttcant'])/$valmax2*$alto2;}
	
	$valt=number_format(($r_vtast['ttsubtiva0']+$r_vtast['ttsubtiva'])/$divisor,2);
	if($vu==2){$valt=number_format(($r_vtast['ttcant'])/$divisor,2);}
	
	$wt=35;
	if($valt>=10){$wt=40;}
	if($valt>=100){$wt=45;}
	$wt=45;
	$yt=$alto-$bbot-$tope+$wt;
	if($yt>$alto-100){$yt=$alto-100;}
	imagefttext($lienzo, 8, 90, $x1+10, $yt , $negro, $archivo_fuente,str_pad($valt,6,' ',STR_PAD_LEFT));
	imagefttext($lienzo, 8, 90, $x1+10, $yt , $negro, $archivo_fuente,str_pad($valt,6,' ',STR_PAD_LEFT));

}
}

$tope = $valpro/$valmax2*$alto2;
$y2=$alto-$bbot-$tope;
imageline($lienzo,45,$y2,950,$y2,$negro);
imageline($lienzo,45,$y2,950,$y2,$negro);
imagefttext($lienzo, 8, 0, 950, $y2 , $negro, $archivo_fuente,number_format($valpro/$divisor,2));

	
$gfile=$empr_codigo.date("is").$vu.".png";
	
$im = imagecreatetruecolor(300, 100);
$rojo = imagecolorallocate($im, 0xFF, 0x00, 0x00);
$negro = imagecolorallocate($im, 0x00, 0x00, 0x00);
imagefilledrectangle($im, 0, 0, 299, 99, $rosa);
// imagejpeg($lienzo,"demo".$vu.".png");
imagejpeg($lienzo,$gfile);
imagedestroy($lienzo); 
?>
<img src="<?php echo $gfile;?>" style="border:solid 1px #000;" />
<br></br>

<?php
}
// imprimir unidades solo si $xfitem	!=""
?>
<!-- <img src="demo1.png" style="border:solid 1px #000;" /> -->
<?php
if ($xfitem>"")
{
?>
<!-- <br></br>
<img src="demo2.png" style="border:solid 1px #000;" /> -->
<?php
}
}
?>




<?php 
if (mb_stristr('S.D',$_GET['fgrou']))
{
?>
<H1 class=SaltoDePagina> </H1>

<?php
for($vu=1;$vu<=2;$vu++)
{

$sql_empr='select * from empr0';
$res_empr=mysql_query($sql_empr,$link_vcrx);

$valtot=mysql_result($res_vtastt,0,'ttsubtiva0')+mysql_result($res_vtastt,0,'ttsubtiva');
$valpro=$valtot/$totreg;
	
	
$sql_vtast1=str_replace('order by','order by ttotal desc,',$sql_vtast);
$res_vtast1=mysql_query($sql_vtast1,$link_vcrx);

$valmax=mysql_result($res_vtast1,0,'ttsubtiva0')+mysql_result($res_vtast1,0,'ttsubtiva');

$divisor=1;
if ($valmax>=100){$divisor=10;}
if ($valmax>=1000){$divisor=100;}
if ($valmax>=10000){$divisor=1000;}
if ($valmax>=100000){$divisor=10000;}
$valmax=intval($valmax/$divisor)+1;
$valmax2=$valmax*$divisor+$divisor;

$compara=0;
$xanios=date('Y',strtotime($xfecha2b))-date('Y',strtotime($xfecha1b))+1;
$xanio1=date('Y',strtotime($xfecha1b));
$xanio2=date('Y',strtotime($xfecha2b));
	
$sql_vtast=str_replace('order by','order by fanio,fsema,',$sql_vtast);
$sql_vtast=str_replace('where','where (fanio between '.$xanio1.' and '.$xanio2.')and ',$sql_vtast);
$columna= mysql_num_rows($res_vtast);
$colini=0;

$ancho=1000;
$alto=600;
$btop=100;
$bbot=100;
$alto2=$alto-$btop-$bbot;

$lienzo = imagecreatetruecolor($ancho, $alto);

$rosa = imagecolorallocate($lienzo, 255, 105, 180);
$rojo = imagecolorallocate($lienzo, 255, 0, 0);
$negro = imagecolorallocate($lienzo, 0, 0, 0);
$blanco = imagecolorallocate($lienzo, 255, 255, 255);
$verde = imagecolorallocate($lienzo, 180, 255, 180);
$azul = imagecolorallocate($lienzo, 0, 0, 255);
$azul = imagecolorallocate($lienzo, 102, 102, 255);
$celeste = imagecolorallocate($lienzo, 77, 195, 246);
$amarillo = imagecolorallocate($lienzo, 255, 255, 102);
$gris = imagecolorallocate($lienzo, 100, 100, 100);
$fondo=imagecolorallocate($lienzo,255,255,255);

$colmax=104;
if($columna>$colmax || $xanios>2){$compara=1;}
if($columna>$colmax){$colini=$columna-$colmax+1;}
if($columna>$colmax){$columna=$colmax;}
if($colini<0){$colini=0;}

//$compara=0;

$barra=intval(($ancho-50)/$columna);
if($barra>40){$barra=40;}
if($barra<8){$barra=8;}

if($compara==1)
{
$colini=0;
$barra=17;
}
 

$x1=60-$barra;
$xt=190;
$x2=$x1+$barra;

$y1=$alto-90;
$y2=0;

ImageFill($lienzo,50,50,$fondo);
$archivo_fuente = '../../_css/cour.ttf';
imagefttext($lienzo, 15, 0, 40, 40 , $negro, $archivo_fuente,'Ventas Totales X Semana');
imagefttext($lienzo, 15, 0, 40, 40 , $negro, $archivo_fuente,'Ventas Totales X Semana');
imagefttext($lienzo, 10, 0, 40, 60 , $negro, $archivo_fuente,'(X $'.number_format($divisor,0).')');


$empresa=mysql_result($res_empr,0,'empr_descri');
$empr_codigo=mysql_result($res_empr,0,'empr_codigo');
imagefttext($lienzo, 15, 0, $ancho-strlen($empresa)*15-45, 40 , $negro, $archivo_fuente,$empresa);
imagefttext($lienzo, 15, 0, $ancho-strlen($empresa)*15-45, 40 , $negro, $archivo_fuente,$empresa);
imageline($lienzo,48,$btop,48,$alto-$bbot,$negro);//linea x


$diez=($alto-$btop-$bbot)/10;
$mil=$valmax2/$divisor;
$mild=$mil/10;
for($i=1;$i<=11;$i++)
{
	$y1=$i*$diez+60;
	for ($j=45;$j<=950;$j=$j+10)
	{imageline($lienzo,$j,$y1,$j+5,$y1,$gris);	}
	//imageline($lienzo,45,$y1,950,$y1,$negro);
	imagefttext($lienzo, 9, 0, 10, $y1 , $negro, $archivo_fuente,str_pad(number_format($mil,1),4,"  ",STR_PAD_LEFT));
	$mil=abs($mil-$mild);
}
imageline($lienzo,45,$y1,950,$y1,$negro);
	
	
	
	
	
//echo $sql_vtast;
$res_vtast=mysql_query($sql_vtast,$link_vcrx);
$xcol=0;
$ames=0;
$umes=0;
$uanio=0;
$canio=0;
//echo $colini;
while($r_vtast=mysql_fetch_assoc($res_vtast))
{

$color=$celeste;
if($r_vtast['fanio']==$xanio2-1){$color=$verde;}
if($r_vtast['fanio']==$xanio2-2){$color=$rosa;}
if($r_vtast['fanio']==$xanio2-3){$color=$amarillo;}
if($r_vtast['fanio']<=$xanio2-4){$color=$azul;}

$xcol++;
if ($xcol>=$colini)
{
	$x1=$x2;
	if($compara==1)
	{$x2=50+$barra*$r_vtast['fsema'];
	//if($r_vtast['fanio']>$uanio){$x1=50;}
	}
	else
	{$x2=$x1+$barra;}
	
	if($r_vtast['fanio']>$uanio)
	{
		if($compara==1)
		{
			$x1=50;
			imagefttext($lienzo, 10, 0, $canio*200+50, $alto-$bbot+75, $negro, $archivo_fuente,$r_vtast['fanio']);
			imageline($lienzo,$canio*200+50, $alto-$bbot+80,$canio*200+150, $alto-$bbot+80,$color);
		}
		else
		{
			imagefttext($lienzo, 10, 0, $x1+$barra+50, $alto-25, $negro, $archivo_fuente,$r_vtast['fanio']);
			imageline($lienzo,$x1+$barra+50, $alto-$bbot+80,$x1+$barra+150, $alto-$bbot+80,$color);
		}
		$uanio=$r_vtast['fanio'];
		$canio++;
		$umes=0;
	}

	if($r_vtast['fmes']>$umes)
	{
	$umes=$r_vtast['fmes'];
	imagefttext($lienzo, 6, 0, $x1+$barra, $alto-$bbot+50, $negro, $archivo_fuente,$r_vtast['fmesn']);
	imagefttext($lienzo, 6, 0, $x1+$barra, $alto-$bbot+50, $negro, $archivo_fuente,$r_vtast['fmesn']);
	}
	
	if($r_vtast['fsema']%5==0 && $r_vtast['fsema']>0)
	{imagefttext($lienzo, 6, 0, $x1+$barra, $alto-$bbot+30, $negro, $archivo_fuente,$r_vtast['fsema']);}
	else
	{imagefttext($lienzo, 6, 0, $x1+$barra, $alto-$bbot+30, $negro, $archivo_fuente,'|');}

	$tope = ($r_vtast['ttsubtiva0']+$r_vtast['ttsubtiva'])/$valmax2*$alto2;
	$y2=$alto-$bbot-$tope;

	if ($x1!=50)
	{imageline($lienzo,$x1,$y1,$x2,$y2,$color);}
	imagefilledrectangle($lienzo, $x2-2, $y2-2, $x2+2, $y2+2, $color);
	$x1=$x2;
	$y1=$y2;


}
}
//echo $y2;


	
$tope = $valpro/$valmax2*$alto2;
$y2=$alto-$bbot-$tope;
imageline($lienzo,45,$y2,950,$y2,$negro);
imageline($lienzo,45,$y2,950,$y2,$negro);
imagefttext($lienzo, 8, 0, 950, $y2 , $negro, $archivo_fuente,number_format($valpro/$divisor,2));
	

	
	
$gfile=$empr_codigo.date("is").$vu.".png";
	
$im = imagecreatetruecolor(300, 100);
$rojo = imagecolorallocate($im, 0xFF, 0x00, 0x00);
$negro = imagecolorallocate($im, 0x00, 0x00, 0x00);
imagefilledrectangle($im, 0, 0, 299, 99, $rosa);
// imagejpeg($lienzo,"demo".$vu.".png");
imagejpeg($lienzo,$gfile);
imagedestroy($lienzo); 
?>
<img src="<?php echo $gfile;?>" style="border:solid 1px #000;" />
<br></br>
<?php
}
?>
	
<?php
if ($xfitem>"")
{
?>
<!-- <br></br> -->
<!-- <img src="demo2.png" style="border:solid 1px #000;" /> -->
<?php
}
}
?>




</div>
</div>
<br>

<div id="vtastot2"></div>
</body>
</html>