<?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_ven_fun.php");
//
$VP_RegXPag=100;
if($Com=="PROFORMA")$LStrTR=gn("count(*)","z_vis_rpt_cot",$FF);
if($Com=="BOLETA")$LStrTR=gn("count(*)","z_viz_rpt_ven",$FF);
if($Com=="FACTURA")$LStrTR=gn("count(*)","z_viz_rpt_ven",$FF);

$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 vendedor</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_ven.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 VENDEDOR</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: 108px; height: 18px;">COMPROBANTE</div>
<select name="Com" id="Com" 
class="lty" style="left:35px; top:149px; width: 110px;"
tabindex="<?php echo ++$TI;?>"  >
<?php
	echo FCBOOD_("com_nombre","comprobantes",
	"com_nombre IN ('FACTURA','BOLETA','PROFORMA','FACT. ELEC.','BOL. ELEC.')",$Com,"N","N","com_nombre");
?>
</select>
<div class="ad" style="left:155px; top:132px; width: 92px; height: 18px;">VENDEDOR</div>
<select name="Ven" id="Ven" 
class="lty" style="left:155px; top:149px; width: 175px;"
tabindex="<?php echo ++$TI;?>"  >
<?php
echo FCBO("NOMBRE","vpersonal","CARGO='VENDEDOR' OR ID=0",$Ven,"S","N");
?>
</select>

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

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


<div class="ad" style="left:526px; top:129px; width: 237px; height: 18px;">CLIENTE</div>
<input name="Cli" type="text" id="Cli" 
class="lt"
style="left:526px; top: 149px; width: 310px;" value="<?php echo $Cli;?>"  
tabindex="<?php echo ++$TI;?>" />

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

<!--INI_TABLA----->
<div class="s1" style=" position:absolute; left: 35px; top: 182px; width: 1242px; z-index:100;overflow:auto;">
  <table  class="f4t" width="1223" border="1" style="border-collapse: collapse">
   <tr>
      <td colspan="8" bgcolor="#CCCCCC" height="18" align="center">
      <?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?>
      </td>
      </tr>   
    <tr>
      <td width="76" bgcolor="#CCCCCC">EMP / ALM</td>
      <td width="92" bgcolor="#CCCCCC">NUMERO</td>
      <td width="71" bgcolor="#CCCCCC">FECHA</td>
      <td width="526" bgcolor="#CCCCCC">CLIENTE</td>
      <td width="141" bgcolor="#CCCCCC">TOTAL PROF</td>
      <td width="135" bgcolor="#CCCCCC">A.CTA</td>
      <td width="135" bgcolor="#CCCCCC">POR COBRAR</td>
      <td width="135" bgcolor="#CCCCCC">VENDEDOR</td>
    </tr>   
  </table>
</div>

<div class="s1"
style="background:#ECF9FF; position:absolute; left: 35px; top: 182px; width: 1261px; height: 550px; overflow:auto;">
<div class="s1" style="left: 0px; top: 0px; width: 1242px; z-index:0; ">
  <table id="Exportar_a_Excel" class="f4t" width="1223" border="1" style="border-collapse: collapse">
   <tr>
      <td colspan="8" bgcolor="#CCCCCC" height="18" align="center">
      <?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?>
      </td>
      </tr>   
    <tr>
      <td width="76" bgcolor="#CCCCCC">EMP / ALM</td>
      <td width="92" bgcolor="#CCCCCC">NUMERO</td>
      <td width="71" bgcolor="#CCCCCC">FECHA</td>
      <td width="526" bgcolor="#CCCCCC">CLIENTE</td>
      <td width="141" bgcolor="#CCCCCC">TOTAL PROF</td>
      <td width="135" bgcolor="#CCCCCC">A.CTA</td>
      <td width="135" bgcolor="#CCCCCC">POR COBRAR</td>
      <td width="135" bgcolor="#CCCCCC">VENDEDOR</td>
    </tr>   
    <?php
		$TOT=0;
		$TOT_COB=0;
		$TOT_X_COB=0;
		$lnk="cotizaciones.php?Id=";
		if($Com=="PROFORMA"){
			$s="SELECT * FROM z_vis_rpt_cot WHERE $FF ORDER BY FEC,ID ";
		}else{
			$s="SELECT * FROM z_viz_rpt_ven WHERE $FF ORDER BY FEC,ID ";
			$lnk="ventas.php?Id=";
		}
		//echo $s;
		$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);
		$rs = grs($s);
		while ($r = $rs->fetch_assoc()){
			$TOT=$TOT+$r['TOT_REAL'];
			$TOT_COB=$TOT_COB+$r['TOT_COB'];
			$TOT_X_COB=$TOT_X_COB+$r['SALDO'];
			$L=$lnk.$r['ID'];
	?>
    <tr>
        <td><?php echo $r['E_A'];?></td>
        <td><a target="_blank" href="<?php echo $L;?>"><?php echo $r['S_N'];?></a></td>
        <td><?php echo $r['FEC_'];?></td>
        <td><?php echo $r['CLI'];?></td>
        <td align="right" class="td_n"><?php echo NF2($r['TOT_REAL'],2);?></td>
        <td align="right" class="td_n"><?php echo NF2($r['TOT_COB'],2);?></td>
        <td align="right" class="td_n"><?php echo NF2($r['SALDO'],2);?></td>         
        <td><?php echo $r['VEN'];?></td>        
    </tr>			
    <?php
		}
	?>
  </table>
</div>
</div>

<div class="adn" style="left:530px; top:750px; width: 241px; height: 18px; text-align:right">
TOTAL PROF.: <?php echo NF2($TOT,2);?> </div>
<div class="adn" style="left:796px; top:750px; width: 204px; height: 18px; text-align:right">
TOTAL A.CTA. : <?php echo NF2($TOT_COB,2);?> </div>

<div class="adn" style="left:1039px; top:750px; width: 238px; height: 18px; text-align:right">
TOTAL POR COBRAR : <?php echo NF2($TOT_X_COB,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: 703px; 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>
