<?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;
}
//
	$IdU=vbval($_SESSION['SYS_USER_ID']);
	$PRO_ID_ALM=gn("pro_id_alm","usuarios","id_usuario=$IdU");
	//
	$StrId=V($_POST['TxtId']);
	$StrCmd=V($_POST['TxtAc']);
	//-------------------------
	$StrEmp=V($_POST['CboEmp']);		
	$StrAlm=V($_POST['CboAlm']);			
	$StrCom=V($_POST['CboCom']);		
	$StrSer=V($_POST['TxtSer']);		
	$StrNum=V($_POST['TxtNum']);		
	$StrDex=V($_POST['TxtDex']);		
	$StrHax=V($_POST['TxtHax']);			
	$StrCod=V($_POST['TxtCod']);				
	$StrPro=V($_POST['TxtPro']);				
	$StrPse=V($_POST['TxtPse']);				
	$StrPnu=V($_POST['TxtPnu']);				
	//
	if($PRO_ID_ALM==0){
		if(strlen($StrEmp)==0)$StrEmp=GE("S");
		if(strlen($StrAlm)==0)$StrAlm=GA($StrEmp,"S");	
	}else{
		$StrEmp=gs("ENC","vis_almacenes","IDA=$PRO_ID_ALM");
		$StrAlm=gs("ANC","vis_almacenes","IDA=$PRO_ID_ALM");
	}
	/*
	if(strlen($StrDex)==0)$StrDex=HOY();
	if(strlen($StrHax)==0)$StrHax=HOY();
	*/
	$StrEmp_=LIKE($StrEmp);
	$StrAlm_=LIKE($StrAlm);
	//-------------------------
	if($StrCom=="TODOS" || strlen($StrCom)==0){
		$StrCom_="%";
	}else{
		$StrCom_=$StrCom;
	}
	$StrNum_=$StrNum."%";
	$StrSer_=$StrSer."%";
	if(strlen($StrDex)==0){
		$StrDex_="2000-01-01";
	}else{
		$StrDex_=ToDate($StrDex);
	}
	if(strlen($StrHax)==0){
		$StrHax_="2030-12-01";//
	}else{
		$StrHax_=ToDate($StrHax);
	}
	$StrCod_=$StrCod."%";
	$StrPro_=$StrPro."%";
	$StrPse_="%".$StrPse;
	$StrPnu_="%".$StrPnu;
	//-------------------------
	$FF="ID>0 AND EMPC LIKE '$StrEmp_' AND ALM LIKE '$StrAlm_' AND COM LIKE '$StrCom_' AND
		 NUM LIKE '$StrNum_' AND SER LIKE '$StrSer_' AND 
		 FEC >= '$StrDex_' AND FEC <= '$StrHax_' AND ".
		 "DES LIKE '$StrPro_' AND COD LIKE '$StrCod_' AND ".
		 "COT_SER LIKE '$StrPse_' AND COT_NUM LIKE '$StrPnu_' ";
	//-------------------------
	$LStrTR=gn("count(*)","vventas_det",$FF);
	//-------------------------
$LStrPag=V($_POST['TxtPag']);
if($StrCmd=="F"){$LStrPag="1";}
$VP_RegXPag=1000;	
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$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>Reporte de ventas detallado</title>
<link rel="stylesheet" type="text/css" href="estiloss.css"  />
<link rel="stylesheet" type="text/css" href="basic.css"  />
<?php AddJs();?>
<script type="text/javascript" src="fe/funcionez.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>
<script>
$(document).ready(function(){
$("#TxtDex").mask("99-99-99");
$("#TxtHax").mask("99-99-99");
});
function EM_OC(){	
	var Emp=gv("CboEmp");	
	var r=AX("03",Emp);
	if(r=="X"){
		CBO_CLS("CboAlm",1);
	}else{
		CBO_FILL("CboAlm",r,0);
	}
}

</script>
<style type="text/css">
<!--
body {
	background-color: #CCC;
}
#Layer1 {
	position:absolute;
	left:345px;
	top:115px;
	width:123px;
	height:35px;
	z-index:1;
}
.centrarFrm{
	width:1200px;
	height:600px;
	position:absolute;
	left:<?php echo "50%";?>;
	top:<?php echo "50%";?>;
	background-color:#006699;
	margin:<?php echo "-300px";?> 0 0 <?php echo "-600px";?>;
}
#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;}
.s4 {color: #000099}
.Estilo5 {color: #000000}

-->
</style>

</head>
<body  <?php echo $StrMsg;?>>
<div Id="DivFRM"  class="centrarFrm" >
<form id="Frm" name="Frm" method="post" action="ventas_det.php">

<input name="TxtAc" id="TxtAc" type="hidden" value="" />
<input name="TxtPag" id="TxtPag" type="hidden" value="<?php echo $LStrPag; ?>" />
<input name="FEC_SERVER" type="hidden" id="FEC_SERVER" value="<?php echo date("d-m-y");?>"/> 

  
    <div id="layer6" style="position:absolute; left: 401px; top: 104px; width: 74px;">
      <div align="left" class="f2">NUMERO</div>
    </div>
    
        <input name="CmdV" type="button" id="CmdV" 
        style="position:absolute; left: 79px; top: 50px; width: 85px;"
 		value="Volver" onclick="fVolver('ventas.php?TxtAc=X');" />
    
<div id="layer3" style="position:absolute; left: 25px; top: 150px; width: 1150px; height: 419px; overflow:auto">
<div align="left" class="f2">
        <table id="Exportar_a_Excel" width="1128" height="19" border="1" cellpadding="0" cellspacing="0">
<tr  >
<td height="18" colspan="9" bgcolor="#666666" align="center">
<?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?>
</td>
</tr>
<tr>
<td width="144" bgcolor="#999999" style="color:#000">COMPROBANTE</td>
<td width="88" bgcolor="#999999" style="color:#000">NUMERO</td>
<td width="103" bgcolor="#999999" style="color:#000">FECHA</td>
<td width="100" bgcolor="#999999" style="color:#000">CODIGO</td>
<td width="375" bgcolor="#999999" style="color:#000">DESCRIPCION</td>            
<td width="61" bgcolor="#999999" style="color:#000" align="right">CANT</td>
<td width="52" bgcolor="#999999" style="color:#000" align="right">PRECIO</td>
<td width="79" bgcolor="#999999" style="color:#000" align="right">IMPORTE</td>
<td width="106" bgcolor="#999999" style="color:#000" >PROFOR../..CONTENE..</td>
</tr>
<?php		  		
	$StrPR="";
	$_TP=0;
	$s="SELECT ID,COM,CONCAT(SER,'-',NUM),DATE_FORMAT(FEC,'%d-%m-%y'),COD,
		SUBSTRING(DES,1,44),CA,ROUND(PR,1),ROUND(IM,1),
		VEN_ID_VEN,COT_SER,COT_NUM,COM_REF 
		FROM vventas_det WHERE ".$FF." ORDER BY ID,COD ";
	//echo $s;
	$X1="<td bgcolor=\"#FFFFFF\"><span class=\"Estilo5\">";
	$X1B="<td bgcolor=\"#FFFFFF\" align=\"right\"><span class=\"Estilo5\">";
	$X2="</span></td>";	
	$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);
	//echo $s."<br>";
	$result = grs($s);				
	while ($row = $result->fetch_row()){
		if($row[9]==0){
			$StrPR="";
		}else{
			$StrPR=substr($row[12],0,1)." ".$row[10]."-".$row[11];
		}
		echo "<tr 
			  ondblclick=\"location.href='ventas.php?Id=$row[0]&Pag=0';\">";
		echo $X1.$row[1].$X2;
		//echo $X1.$row[2].$X2;
		echo "<td bgcolor=\"#FFFFFF\"><a target=\"_blank\" href=\"ventas.php?Id=$row[0]\">'$row[2]</a></td>";
		echo $X1.$row[3].$X2;
		echo $X1.$row[4].$X2;
		echo $X1.$row[5].$X2;
		echo $X1B.$row[6].$X2;
		echo $X1B.NF3($row[7]).$X2;
		echo $X1B.NF3($row[8]).$X2;
		echo $X1.$StrPR.$X2;
		echo "</tr>";
		$_TP=$_TP + $row[6];
	}

?>		  
<tr>
<td width="144" bgcolor="#999999" style="color:#000">&nbsp;</td>
<td width="88" bgcolor="#999999" style="color:#000">&nbsp;</td>
<td width="103" bgcolor="#999999" style="color:#000">&nbsp;</td>
<td width="100" bgcolor="#999999" style="color:#000">&nbsp;</td>
<td width="375" bgcolor="#999999" style="color:#000">TOTAL CAJAS</td>            
<td width="61" bgcolor="#999999" style="color:#000" align="right"><?php echo NF4($_TP);?></td>
<td width="52" bgcolor="#999999" style="color:#000" align="right">&nbsp;</td>
<td width="79" bgcolor="#999999" style="color:#000" align="right">&nbsp;</td>
<td width="106" bgcolor="#999999" style="color:#000" >&nbsp;</td>
</tr>
</table>
      </div>
    </div>
    <div id="layer" style="position:absolute; left: 79px; top: 30px; width: 412px; height: 24px;">
      <div align="left" class="Estilo1">REPORTE DE VENTAS DETALLADO</div>
    </div>
            
<input name="TxtNum" type="text" id="TxtNum" 
style="left: 402px; top: 121px; width: 60px;" 
onblur="_N(this);"
value="<?php echo $StrNum;?>"   maxlength="6"
onkeydown="return SoloTextoEx(event,'TxtDex');"
tabindex="1" />
   
    <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: 1076px; top: 121px; width: 76px;" value="Filtrar" onclick="fFiltrar();" />
     
    <div id="layer7" style="position:absolute; left: 473px; top: 88px; width: 62px;">
      <div align="left" class="f2">DESDE</div>
    </div>
    <div class="EV" style="left: 472px; top: 104px; width: 88px; color:#FF0"><u><a onclick="fFecServer('TxtDex')">(dd-mm-yy) +</a></u></div>

<input name="TxtDex" type="text" id="TxtDex" 
style="position:absolute; left: 473px; top: 121px; width: 69px;" value="<?php echo $StrDex;?>"  
onkeydown="return SoloFec(this,event,'TxtHax');"
tabindex="1" />


<input name="TxtCod" type="text" id="TxtCod" 
style="position:absolute; left: 628px; top: 121px; width: 77px;" value="<?php echo $StrCod;?>"  
onkeydown="return SoloTextoEx(event,'TxtPro');" 
tabindex="1" />

<input name="TxtPro" type="text" id="TxtPro" 
style="position:absolute; left: 712px; top: 121px; width: 212px;" value="<?php echo $StrPro;?>"  
onkeydown="return SoloTextoEx(event,'TxtPse');" 
tabindex="1" />

<div class="s1" style="left: 932px; top: 88px;">PROFORMA / CONTENEDOR</div>

<div class="s1" style="left: 932px; top: 103px;">SERIE</div>    
<input name="TxtPse" type="text" id="TxtPse" 
style="left:932px; top: 121px; width: 52px;" 
onblur="_S(this);"
value="<?php echo $StrPse;?>"  
onkeydown="return SoloTextoEx(event,'TxtPnu');"
tabindex="1" />

<div class="s1" style="left: 993px; top: 103px;">NUMERO</div>    
<input name="TxtPnu" type="text" id="TxtPnu" 
style="left: 993px; top: 121px; width: 67px;" 
onblur="_N(this);"
value="<?php echo $StrPnu;?>"  
onkeydown="return SoloTextoEx(event,'CmdB');"
tabindex="1" />

<div id="layer10" style="position:absolute; left: 628px; top: 104px; width: 176px;">
<div align="left" class="f2">CODIGO</div>
</div>

<div id="layer10" style="position:absolute; left: 712px; top: 104px; width: 101px;">
<div align="left" class="f2">DESCRIPCION</div>
</div>
<div id="layer11" style="position:absolute; left: 552px; top: 88px; width: 60px;">
<div align="left" class="f2">HASTA</div>
</div>
   <div class="EV" style="left: 547px; top: 104px; width: 88px; color:#FF0"><u><a onclick="fFecServer('TxtHax')">(dd-mm-yy) +</a></u></div> 
    <input name="TxtHax" type="text" id="TxtHax" 
        style="position:absolute; left: 551px; top: 121px; width: 69px;" 
        value="<?php echo $StrHax;?>"  
        onkeydown="return SoloFec(this,event,'TxtCod');"
        tabindex="1" />
      
<select name="CboCom" id="CboCom" 
style="position:absolute; left: 242px; top: 121px; width: 97px;" 
onkeydown="return SoloTextoEx(event,'TxtSer');">
<?php
echo FCBO_("com_nombre","comprobantes","id_comprobante>0",$StrCom,"S","N");
?>
    </select>
<div id="layer13" style="position:absolute; left: 242px; top: 104px; width: 102px;">
<div align="left" class="f2">COMPROBANTE</div>
</div>
<div class="s1" style="left: 25px; top: 104px;">EMPRESA</div>
<select name="CboEmp" id="CboEmp" 
style="position:absolute; left:25px; top:121px; width: 94px;" 
onchange="EM_OC();"
onkeydown="return SoloTextoEx(event,'CboAlm');" tabindex="1">
<?php 
	echo LE($StrEmp,"S","N"); 
?>
</select>

<div class="s1" style="left: 126px; top: 104px;">ALMACEN</div>
<select name="CboAlm" id="CboAlm" style="position:absolute; left: 124px; top: 121px; width: 109px;" 
onkeydown="return SoloTextoEx(event,'CboCom');">
<?php
	echo LA($StrEmp,$StrAlm,"S","N");
?>
</select>

<div id="layer15" style="position:absolute; left: 347px; top: 104px; width: 46px;">
<div align="left" class="f2">SERIE</div>
</div>
<input name="TxtSer" type="text" id="TxtSer" 
style="left: 348px; top: 122px; width: 45px;"  maxlength="4"
onblur="_S(this);"
value="<?php echo $StrSer;?>"  
onkeydown="return SoloTextoEx(event,'TxtNum');"
tabindex="1" />

</form>

<form action="ficheroExcel.php" method="post" target="_blank" id="FormularioExportacion" >
<div style="position:absolute; left: 184px; top: 50px; 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>
</body>
</html>
