<?php
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;
}

$HW=$_SESSION['SYS_HW'];
$StrGT="";$LStrMsg="";$LStrFoc="";$LStrMM="";
$LStrPag=V($_POST['TxtPag']);
//
include("lq_rpt_dep_ag_fun.php");
//
$VP_RegXPag=100;
$LStrTR=100;
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);	
$TI=0;
?>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Reporte de ventas por departamento</title>
<!--INI_SCRIPT------------------------------------------------------------------------------>
<?php AddJs(); ?>
<script type="text/javascript" src="fe/funcionex.js"></script>
<!--FIN_SCRIPT------------------------------------->
<link rel="stylesheet" type="text/css" href="estilox.css"  />
<link rel="stylesheet" type="text/css" href="basix.css"  />
<style type="text/css">
.cF {height:800px;width:1300px;position:relative; <?php echo "top:0px";?>}
</style>
<script>
$(document).ready(function(){  
   Inicializar();   
});
</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>
</head>

<body  <?php echo $LStrMsg;?>  >
<div align="center">

<div Id="DivFRM"  class="cF" style="background-color:#FFFFFF;" >
<form id="Frm" name="Frm" method="post" action="lq_rpt_dep_ag.php">
<!--INI_TITULO-->
<div id="DivT" class="dT"  style="width:1300px">
<img src="img/unidades.png" class="iT" />
<div class="tT" style="width:1000px">REPORTE DE VENTAS POR DEPARTAMENTO (Agrupado)</div>
</div>
<!--FIN_TITULO-->
<div class="s1" style="left:177px; top: 114px; width: 142px; height: 18px;">
  <?php
	if(strlen($_PDF)>0){
		echo "<a href=\"$_PDF\" target=\"_new\">DESCARGAR</a>";	
	}
?>
  
</div>

<div class="ad" style="left:35px; top:132px; width: 139px; height: 18px;">DEPARTAMENTO</div>
<select name="Dep" id="Dep" 
class="lty" style="left:35px; top:149px; width: 139px;"
tabindex="<?php echo ++$TI;?>"  >
<?php
	echo FCBO("dis_nombre","distritos","id_distrito>=0",$Dep,"S","N");
?>
</select>

<div class="ad" style="left:184px; top:132px; width: 108px; height: 18px;">COMPROBANTE</div>
<select name="Com" id="Com" 
class="lty" style="left:184px; top:149px; width: 101px;"
tabindex="<?php echo ++$TI;?>"  >
<?php
	echo FCBOOD_("com_nombre","comprobantes",
	"com_nombre IN ('FACTURA','BOLETA','PROFORMA')",$Com,"N","N","com_nombre");
?>
</select>


<div class="s1" style="left:294px; top: 132px; width: 267px; height: 18px;">CLIENTE (Nombres y apellidos / Razon social)</div>
<input name="Cli"  type="text" 
class="lt"  id="Cli" 
style="left:294px; top: 149px; width: 262px;"
maxlength="150" 
tabindex="<?php echo ++$TI;?>"
value="<?php echo $Cli;?>"   />

<div class="s1" style="left:565px; top: 132px; width: 49px; height: 16px;">RUC </div>
<input name="Ruc"  type="text" 
class="nei"  id="Ruc" 
style="left:564px; top: 149px; width: 87px;"
maxlength="11" 
tabindex="<?php echo ++$TI;?>"
value="<?php echo $Ruc;?>"   />

<div class="ad" style="left:661px; top:132px; width: 82px; height: 18px;">VENDEDOR</div>
<select name="Ven" id="Ven" 
class="lty" style="left:659px; top:149px; width: 150px;"
tabindex="<?php echo ++$TI;?>"  >
<?php
echo FCBO("NOMBRE","vpersonal","CARGO='VENDEDOR' OR ID=0",$Ven,"S","N");
?>
</select>

<div class="ad" style="left:818px; top:117px; width: 82px; height: 18px;">DESDE</div>
<div class="EV" style="left: 818px; top: 131px; width: 86px;"><u><a onClick="sh('Dex')">(dd-mm-yy) +</a></u></div>
<input name="Dex" type="text" id="Dex" 
class="fe"
style="left:818px; top: 149px; width: 75px;" value="<?php echo $Dex;?>"  
tabindex="<?php echo ++$TI;?>" />

<div class="ad" style="left:906px; top:117px; width: 82px; height: 18px;">HASTA</div>
<div class="EV" style="left: 906px; top: 131px; width: 86px;"><u><a onClick="sh('Hax')">(dd-mm-yy) +</a></u></div>
<input name="Hax" type="text" id="Hax" 
class="fe"
style="left:906px; top: 149px; width: 75px;" value="<?php echo $Hax;?>"  
tabindex="<?php echo ++$TI;?>" />


<input name="CmdF" type="button" id="CmdF"  style="position:absolute; top:149px; left:990px; width: 65px;"
value="Filtrar" onClick="fFiltrar();"  
tabindex="<?php echo ++$TI;?>" />

<!--INI_TABLA----->
<div class="s1"
style="background:#ECF9FF; position:absolute; left: 35px; top: 182px; width: 550px; height: 550px; overflow:auto;">
<div class="s1" style="left: 0px; top: 0px; width: 547px; z-index:0;">
  <table id="Exportar_a_Excel" class="f4t" width="526" border="1" style="border-collapse: collapse">
   <tr>
      <td colspan="2" bgcolor="#CCCCCC" height="18" align="center">
      <?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?>
      </td>
      </tr>   
    <tr>
      <td width="358" bgcolor="#CCCCCC">DEPARTAMENTO</td>
      <td width="152" bgcolor="#CCCCCC" align="right">TOTAL</td>
    </tr>   
    <?php
		$TOT=0;
		$s="SELECT DEP,SUM(TOT_REAL) as T FROM ";
		if($Com=="PROFORMA"){
			$s=$s." z_vis_rpt_cot ";
		}else{
			$s=" z_viz_rpt_ven ";
		}
		$s=$s." WHERE $FF GROUP BY DEP ORDER BY 2 DESC ";
		$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);
		$rs = grs($s);
		while ($r = $rs->fetch_assoc()){
			$TOT=$TOT+$r['T'];
	?>
    <tr>
        <td><?php echo $r['DEP'];?></td>
        <td align="right" style="padding-right:5px"><?php echo NF2($r['T'],2);?></td>
    </tr>			
    <?php
		}
	?>
  </table>
</div>
</div>
<div class="adn" style="left:354px; top:750px; width: 230px; height: 18px; text-align:right">TOTAL : <?php echo NF2($TOT,2);?></div>
<!--FIN_TABLA----->
<!--INI_OCULTOS-------------------------------->
<?php include("ocultox.php");?>
<!--FIN_OCULTOS-------------------------------->
<!--INI_BOTONES----->
<div id="DivBtn"  align="left"
style="position:absolute; left: 33px; top: 71px; width: 180px; height: 26px;">
<input name="CmdB" type="button" id="CmdZ" class="btm"
value="Volver" onClick="fBuscar('menu.php');"  
tabindex="<?php echo ++$TI;?>" />
</div>
<!--FIN_BOTONES-->
</form>
<form action="ficheroExcel.php" method="post" target="_blank" id="FormularioExportacion" >
<div style="position:absolute; left: 149px; top: 72px; width: 45px; height: 15px;">  
<input name="" type="button" class="botonExcel" value="Exportar" />
<input type="hidden" id="datos_a_enviar" name="datos_a_enviar" />
</div>
</form>

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