<?php
ini_set("session.cookie_lifetime",60*60*10);
ini_set("session.gc_maxlifetime", 60*60*10);
	session_start();
	include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
	if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("login.php");	return;}
	//
if(vbval($_SESSION['SYS_USER_GI'])!=USU_GET_GI($_SESSION['SYS_USER_ID'])){
	JsDir("cerrar.php");	
	return;
}
//
	//-------------------------	
	$VP_RegXPag=20;
	//-------------------------
	$StrPag=V($_POST['TxtPag']);	
	//-------------------------
	$StrId=V($_POST['TxtId']);
	$StrCmd=V($_POST['TxtAc']);
	//-------------------------
	$StrAlm=V($_POST['CboAlm']);		
	$StrCom=V($_POST['CboCom']);		
	$StrAnio=V($_POST['CboAnio']);		
	$StrMes=V($_POST['CboMes']);			
	//-------------------------
	if($StrCmd=="F"){
		$StrPag="0";
	}
	if(strlen($StrAnio)==0)$StrAnio="TODOS";
	if(strlen($StrMes)==0)$StrMes="TODOS";
	//-------------------------
	if($_SESSION['SYS_USER_ALM']=="%"){
		if(strlen($StrAlm)==0)$StrAlm=GetSO("alm_obs","almacenes","","alm_obs");
	}else{
		$StrAlm=$_SESSION['SYS_USER_ALM'];
	}
	if(strlen($StrCom)==0) $StrCom="TODOS";	
	//-------------------------
	if($StrCom=="TODOS"){
		$StrCom_="%";
	}else{
		$StrCom_=$StrCom;
	}
	if($StrAnio=="TODOS"){
		$StrAnio1=1900;
		$StrAnio2=2100;		
	}else{
		$StrAnio1=$StrAnio;
		$StrAnio2=$StrAnio;
	}
	if($StrMes=="TODOS"){
		$StrMes1=1;
		$StrMes2=12;
	}else{
		$StrMes1=gn("id_mes","meses","mes='$StrMes'");
		$StrMes2=$StrMes1;
	}
	//-------------------------
	$SS="SELECT ANIO,MES_,ROUND(SUM(TOT),1) FROM vventas
		WHERE ID>0 AND ALM LIKE '$StrAlm' AND COM LIKE '$StrCom_' AND 
		ANIO>=$StrAnio1 AND ANIO<=$StrAnio2 AND ANU='N' AND 
		IMES>=$StrMes1 AND IMES<=$StrMes2 
		GROUP BY ANIO,MES_ ORDER BY ANIO,IMES";
	//-------------------------
	if($StrCmd=="PDF"){	
		//
		$TI="UTILIDADES DE VENTA :: ALMACEN : $StrAlm";
		$s="SELECT COM,CONCAT(SER,'-',NUM),DATE_FORMAT(FEC,'%d-%m-%y'),DES,
			CA,ROUND(PRC,1),ROUND(PRV,1),ROUND(UTI,1) 
			FROM vventas_uti WHERE ID>0 AND ALM LIKE '$StrAlm' AND 
			COM LIKE '$StrCom_' AND NUM LIKE '$StrNum_' AND 
			SER LIKE '$StrSer_' AND FEC >= '$StrDex_' AND 
			FEC <= '$StrHax_' ORDER BY ALM,COM,ISER,INUM,FEC,DES ";
		$T="COMPROB.,NUMERO,FECHA,DESCRIPCION,CANT,PRE.COM,PRE.VEN,UTIL";
		$E="12, 9, 8,22,4,6,6,9";
		$A=" 0, 0, 0, 0,1,1,1,2";		
		//
		$_ID=GenId("id","reportes");
		PDF_TIT($_ID,$TI);
		PDF_SQL($_ID,$s);
		PDF_CAM($_ID,$T);
		PDF_ESP($_ID,$E);
		PDF_ANC($_ID,$A);		
		$StrFilePDF=PDF_CREATE($_ID);	
		//
		JsDir($StrFilePDF);
		return;			
	}
	//
	if(strlen($StrPag)==0)$StrPag="0";
	if($StrCmd=="MSig")$StrPag=($StrPag+1);
	if($StrCmd=="MAnt")	$StrPag=($StrPag-1);
	if($StrCmd=="MPri")	$StrPag=0;
	if($StrCmd=="MUlt")	$StrPag=(floor($StrTR / $VP_RegXPag) );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Estadistica - Ventas por Meses</title>
<script src="jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="jquery.maskedinput.min.js" type="text/javascript"></script>
<script type="text/javascript" src="fe/funciones.js"></script>
<script language="javascript">
$(document).ready(function() {
	$(".botonExcel").click(function(event) {
		$("#datos_a_enviar").val( $("<div>").append( $("#Exportar_a_Excel").eq(0).clone()).html());
		$("#FormularioExportacion").submit();
});
});
</script>
<link rel="stylesheet" type="text/css" href="basic.css" />
<style type="text/css">
<!--
body {
	background-color: #CCC;
}
#Layer1 {
	position:absolute;
	left:345px;
	top:115px;
	width:123px;
	height:35px;
	z-index:1;
}
.centrarFrm{
	width:900px;
	height:600px;
	position:absolute;
	left:<?php echo "50%";?>;
	top:<?php echo "50%";?>;
	background-color:#006699;
	margin:<?php echo "-300px";?> 0 0 <?php echo "-450px";?>;
}
#Layer2 {
	position:absolute;
	left:409px;
	top:205px;
	width:82px;
	height:24px;
	z-index:1;
}
.Estilo1 {
	font-family: Arial, Helvetica, sans-serif;
	font-weight: bold;
	color: #FFFFFF;
}
.f2 {font-family: Arial, Helvetica, sans-serif; font-weight: bold; color: #FFFFFF; font-size: 12px; }
.Estilo3 {color: #FFFFFF; font-size: 12px; font-family: Arial, Helvetica, sans-serif;}
.eS4 {
	color: #000099;
	text-align: right;
}
.Estilo5 {color: #000000}
#Frm center #DivFRM #layer3 .f2 table {
	font-weight: normal;
}

-->
</style>

</head>
<body  <?php echo $StrMsg;?>>
<div Id="DivFRM"  class="centrarFrm" >
<form id="Frm" name="Frm" method="post" action="est_ven_x_mes.php">
<center>   
<input name="CmdV" type="button" id="CmdV" 
style="position:absolute; left: 79px; top: 50px; width:60px"
value="Volver" onclick="fVolver('menu.php');" />
<input type="hidden" name="TxtAc" id="TxtAc" />
<div 
 id="layer3" style="position:absolute; left: 25px; top: 138px; width: 725px; height: 431px;">
<div align="left" class="f2">
<table id="Exportar_a_Excel" 
width="692" height="19" border="1" cellpadding="0" cellspacing="0">
<tr  >
            <td height="18" colspan="9" bgcolor="#666666" align="center">
<?php
if($LStrTR>$VP_RegXPag){
if($LStrPag==0){
	echo "<input style=\"width:40px\" name=\"CmdNP\" type=\"button\" id=\"CmdNP\" value=\"|&lt;\"  onclick=\"fPrimero();\" disabled=\"disabled\"/>";
	echo "<input style=\"width:40px\" name=\"CmdNA\" type=\"button\" id=\"CmdNA\" value=\"<\"  onclick=\"fAnterior();\" disabled=\"disabled\" />";
}else{
	echo "<input style=\"width:40px\" name=\"CmdNP\" type=\"button\" id=\"CmdNP\" value=\"|&lt;\"  onclick=\"fPrimero();\"/>";
	echo "<input style=\"width:40px\" name=\"CmdNA\" type=\"button\" id=\"CmdNA\" value=\"<\"  onclick=\"fAnterior();\"/>";
}
if($LStrPag==(floor($LStrTR / $VP_RegXPag)) ){
	echo "<input style=\"width:40px\" name=\"CmdNS\" type=\"button\" id=\"CmdNS\" value=\">\"  onclick=\"fSiguiente();\"  disabled=\"disabled\" />";
	echo "<input style=\"width:40px\" name=\"CmdNU\" type=\"button\" id=\"CmdNU\" value=\"&gt;|\"  onclick=\"fUltimo();\"  disabled=\"disabled\"/>";				
}else{
	echo "<input style=\"width:40px\" name=\"CmdNS\" type=\"button\" id=\"CmdNS\" value=\">\"  onclick=\"fSiguiente();\" />";
	echo "<input style=\"width:40px\" name=\"CmdNU\" type=\"button\" id=\"CmdNU\" value=\"&gt;|\"  onclick=\"fUltimo();\"/>";				
}
}
?>
</td>

</tr>
<tr>
<td width="199" bgcolor="#999999"><span class="eS4">A&Ntilde;O</span></td>
<td width="205" bgcolor="#999999"><span class="eS4">MES</span></td>
<td width="159" bgcolor="#999999"><span class="eS4">TOTAL</span></td>
</tr>
<?php
	$TOT=0;		  		
	$StrTemp=$StrPag * $VP_RegXPag;
	$ss=$SS;
	if($StrTR<=$VP_RegXPag){
		$s=$ss;
	}else{
		$s=$ss." LIMIT $StrTemp,$VP_RegXPag";
	}		  				
	$X1="<td bgcolor=\"#FFFFFF\"><span class=\"Estilo5\">";
	$X1B="<td bgcolor=\"#FFFFFF\" align=\"right\"><span class=\"Estilo5\">";
	$X2="</span></td>";
	$result = grs($s);				
	while ($row = $result->fetch_row()){
		echo "<tr   >";
		echo $X1.$row[0].$X2;
		echo $X1.$row[1].$X2;
		echo $X1B.$row[2].$X2;
		$TOT=$TOT+$row[2];	
		echo "</tr>";
	}

?>		  
<tr  >
<td bgcolor="#FFFFFF">&nbsp;</td>
<td bgcolor="#FFFFFF"><span class="eS4">TOTAL</span></td>
<td bgcolor="#FFFFFF" style="text-align:right" ><span class="eS4"><?php echo NF($TOT,1);?></span></td>
</tr>
         
        </table>
      </div>
    </div>
    <div id="layer" style="position:absolute; left: 79px; top: 30px; width: 412px; height: 24px;">
      <div align="left" class="Estilo1">ESTADISTICA - VENTAS POR MESES</div>
    </div>
    <div id="LblTit" style="position:absolute; left: 20px; top: 25px; width: 64px;">
      <div align="left" class="Estilo1"><img src="img/buscar.png" width="57" height="60" /></div>
</div>	
        <input name="CmdB" type="button" id="CmdB"
style="position:absolute; left: 468px; top: 110px; width: 57px;"
 value="Filtrar" onclick="fFiltrar();" />

    <div id="layer7" style="position:absolute; left: 259px; top: 86px; width: 88px;">
      <div align="left" class="f2">A&Ntilde;O</div>
    </div>
<select name="CboCom" id="CboCom" 
style="position:absolute; left: 119px; top: 109px; width: 130px;" 
onkeydown="return SoloTextoEx(event,'CboAnio');">
<?php
echo FCBO_("com_nombre","comprobantes","id_comprobante>0",$StrCom,"S","N");
?>
</select>

<div id="layer13" style="position:absolute; left: 120px; top: 86px; width: 102px;">
<div align="left" class="f2">COMPROBANTE</div>
</div>

<select name="CboAlm" id="CboAlm" style="position:absolute; left: 24px; top: 109px; width: 88px;" 
onkeydown="return SoloTextoEx(event,'CboCom');">
<?php echo ListALM($StrAlm); ?>
</select>
 
<div id="layer14" style="position:absolute; left: 26px; top: 86px; width: 102px;">
<div align="left" class="f2">ALMACEN</div>
</div>
<select name="CboAnio" id="CboAnio" style="position:absolute; left: 259px; top: 109px; width: 82px;" 
onkeydown="return SoloTextoEx(event,'CboMes');">
<?php
echo FCBO_("ANIO","v_anios","",$StrAnio,"S","N");
?>
</select>
<div id="layer6" style="position:absolute; left: 348px; top: 86px; width: 88px;">
<div align="left" class="f2">MES</div>
</div>
<select name="CboMes" id="CboMes" style="position:absolute; left: 349px; top: 109px; width: 108px;" 
onkeydown="return SoloTextoEx(event,'CmdB');">
<?php
echo FCBO_("mes","meses","",$StrMes,"N","N");
?>
</select>
</center>	
</form>
<form action="ficheroExcel.php" 
method="post" target="_blank" 
id="FormularioExportacion" >
<div 
style="position:absolute; left: 532px; top: 111px; width: 51px; height: 14px;">  
<input name="" type="button" style="height: 23px;"  class="botonExcel" value="Exportar" />
<input type="hidden" id="datos_a_enviar" name="datos_a_enviar" />
</div>
</form>

</div>
</body>
</html>
