<?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']);			
	$StrPro=V($_POST['TxtPro']);			
	$StrSN=V($_POST['CboSN']);			
	$StrVen=V($_POST['CboVen']);			
	//+++++
	$PRO_ID_ALM=0;
	//
	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");
	}
	//
	$StrEmp_=LIKE($StrEmp);
	$StrAlm_=LIKE($StrAlm);	
	//
	if(strlen($StrDex)==0)$StrDex=HACE_UN_MES();
	if(strlen($StrHax)==0)$StrHax=HOY();
	//
	if(strlen($StrVen)==0)$StrVen="TODOS";
	if(strlen($StrCom)==0) $StrCom="TODOS";	
	if(strlen($StrSN)==0) $StrSN="NO";	
	if($StrSN=="TODOS"){
		$StrSN_="%";
	}else{
		$StrSN_=substr($StrSN,0,1);
	}
	//-------------------------
	if($StrCom=="TODOS"){
		$StrCom_="%";
	}else{
		$StrCom_=$StrCom;
	}
	$StrNum_=$StrNum."%";
	$StrSer_=$StrSer."%";
	$StrDex_=val_dex($StrDex);
	$StrHax_=val_hax($StrHax);
	$StrPro_=$StrPro."%";
	if($StrVen=="TODOS"){
		$StrVen_="%";
	}else{
		$StrVen_=$StrVen;
	}
	//-------------------------
	$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 
		 CLI LIKE '$StrPro_' 
		 AND ANU LIKE '$StrSN_' AND VEN LIKE '$StrVen_' ";
//echo $FF;
$LStrTR=gn("count(*)","vcotizaciones",$FF);
$LStrPag=V($_POST['TxtPag']);	
if($StrCmd=="F"){$LStrPag="1";}
$VP_RegXPag=20;	
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);
$TI=0;	
?>
<!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>Proformas - Buscar (X)</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/funcionez.js"></script>
<script>
$(document).ready(function(){
   $("#TxtDex").mask("99-99-99");    
   $("#TxtHax").mask("99-99-99");    
   jF("CboEmp");
});
</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();
});
});
//
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>
<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: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;}
.x4 {color: #000099}
.Estilo5 {color: #000000}

-->
</style>

</head>
<body >
<div Id="DivFRM"  class="centrarFrm" >
<form id="Frm" name="Frm" method="post" action="cotizaciones_buscar_express.php">
<div id="layer5" style="position:absolute; left: 79px; top: 50px; width: 85px; height: 28px;">
<div align="left" class="f2">
<input name="CmdV" type="button" id="CmdV" 
value="Volver" onclick="fVolver('cotizaciones.php?TxtAc=X');" />
</div>
</div>
<script>
function ver(id){
	Ow("cotizaciones_ver.php?ID="+id,1020,500);
}
</script>
<div id="layer3" 
style="position:absolute; left: 25px; top: 145px; width: 1150px; height: 423px; overflow:auto">
<div align="left" class="f2">
        <table id="Exportar_a_Excel" width="1120" height="19" border="1" cellpadding="0" cellspacing="0">
<tr>
<td height="18" colspan="8" bgcolor="#666666" align="center">
<?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?>
</td>

</tr>
<tr>
<td width="155" bgcolor="#999999"><span class="x4">EMPRESA / ALMACEN</span></td>            
<td width="81" bgcolor="#999999"><span class="x4">NUMERO</span></td>
<td width="76" bgcolor="#999999"><span class="x4">FECHA</span></td>
<td width="297" bgcolor="#999999"><span class="x4">CLIENTE</span></td>            
<td width="85" bgcolor="#999999" align="right"><span class="x4">TOTAL</span></td>
<td width="304" bgcolor="#999999"><span class="x4">VENDEDOR</span></td>            
<td width="24" bgcolor="#999999"><span class="x4">ANU</span></td>
<td width="24" bgcolor="#999999"><span class="x4">VER</span></td>
</tr>
<?php		  		
$StrTemp=$StrPag * $VP_RegXPag;
$ss="SELECT ID,ALM,COM,CONCAT(SER,'-',NUM),DATE_FORMAT(FEC,'%d-%m-%y'),
	 SUBSTRING(CLI,1,49) AS CLI,
	 ROUND(TOT_REAL,2),SUBSTRING(VEN,1,19) AS VEN,EMPC,ANU 
	 FROM vcotizaciones WHERE $FF ORDER BY ID DESC ";			
$X1="<td bgcolor=\"#FFFFFF\"><span class=\"Estilo5\">";
$X1B="<td bgcolor=\"#FFFFFF\" align=\"right\"><span class=\"Estilo5\">";
$X2="</span></td>";
$TOTAL_SUMA=0;
//echo $s."<br>";
$s=PagSql($ss,$LStrPag,$VP_RegXPag,$LStrTR);
$result = grs($s);				
while ($row = $result->fetch_row()){
?>
	<tr ondblclick="location.href='cotizaciones.php?Id=<?php echo $row[0];?>&Pag=0';">
	<td bgcolor="#FFFFFF"><span class="Estilo5"><?php echo $row[8]." / ".$row[1];?></span></td>
	<td bgcolor="#FFFFFF"><a target="_blank" href="cotizaciones.php?Id=<?php echo $row[0];?>"><?php echo $row[3];?></a></td>
	<td bgcolor="#FFFFFF"><span class="Estilo5"><?php echo $row[4];?></span></td>
	<td bgcolor="#FFFFFF"><span class="Estilo5"><?php echo $row[5];?></span></td>
	<td bgcolor="#FFFFFF" align="right"><span class="Estilo5"><?php echo NF3($row[6]);?></span></td>
    
	<td bgcolor="#FFFFFF"><span class="Estilo5"><?php echo $row[7];?></span></td>
	<td bgcolor="#FFFFFF"><span class="Estilo5"><?php echo $row[9];?></span></td>
	<td bgcolor="#FFFFFF" align="center"><img src="bng/ver.png" style="cursor:pointer" onclick="ver('<?php echo $row[0];?>')" /></td>
	</tr>
<?php
	$TOTAL_SUMA=$TOTAL_SUMA+$row[6];
}
?>		  
<tr>
<td width="155" bgcolor="#999999"><span class="x4"></span></td>            
<td width="81" bgcolor="#999999"><span class="x4"></span></td>
<td width="76" bgcolor="#999999"><span class="x4"></span></td>
  
<td width="297" bgcolor="#999999" align="right"><span class="x4">TOTAL</span></td>
<td width="85" bgcolor="#999999" align="right"><span class="x4"><?php echo NF3($TOTAL_SUMA);?></span></td> 
<td width="304" bgcolor="#999999"><span class="x4"></span></td>             
<td width="24" bgcolor="#999999"><span class="x4"></span></td>
<td width="24" bgcolor="#999999"><span class="x4"></span></td>
</tr>    
        </table>
      </div>
    </div>
    <div id="layer" style="position:absolute; left: 79px; top: 30px; width: 454px; height: 24px;">
      <div align="left" class="Estilo1">PROFORMAS - BUSCAR (X) 
        <input name="TxtId" type="hidden" id="TxtId" value="<?php echo $StrId;?>"/>
        <input name="TxtPag" type="hidden" id="TxtPag" value="<?php echo $LStrPag; ?>" />
		<input name="TxtAc" type="hidden" id="TxtAc" value="" />
<input name="FEC_SERVER" type="hidden" id="FEC_SERVER" value="<?php echo date("d-m-y");?>"/>  
      Ordenado del mas reciente</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>	


<div class="s1" style="left: 24px; top: 100px; width: 81px;">
EMPRESA</div>
<select name="CboEmp" id="CboEmp" 
style="position:absolute; left:24px; top:116px; width: 92px;" 
onchange="EM_OC();"
onkeydown="return SoloTextoEx(event,'CboAlm');" 
tabindex="<?php echo ++$TI;?>">
<?php 
	echo LE($StrEmp,"S","N"); 	
?>
</select>

<div class="s1" style="left: 136px; top: 100px; width: 81px;">
ALMACEN</div>
<select name="CboAlm" id="CboAlm" style="left: 134px; top: 116px; width: 102px;" 
onkeydown="return SoloTextoEx(event,'CboCom');" tabindex="<?php echo ++$TI;?>">
<?php
	echo LA($StrEmp,$StrAlm,"S","N");	
?>
</select>

<div class="s1" style="left: 256px; top: 100px; width: 102px;">
COMPROBANTE</div>
<select name="CboCom" id="CboCom" 
style="left: 255px; top: 116px; width: 100px;" 
onkeydown="return SoloTextoEx(event,'TxtSer');" tabindex="<?php echo ++$TI;?>">
<?php
echo FCBO_("com_nombre","comprobantes","id_comprobante>0",$StrCom,"S","N");
?>
</select>

<div class="s1" style="left: 370px; top: 100px; width: 46px;">
SERIE</div>
<input name="TxtSer" type="text" id="TxtSer" 
style="left: 370px; top: 116px; width: 56px;" 
value="<?php echo $StrSer;?>"  onblur="_S(this);" maxlength="4"
onkeydown="return SoloTextoEx(event,'TxtNum');"
tabindex="<?php echo ++$TI;?>" />

<div class="s1" style="left: 439px; top: 100px; width: 58px;">
NUMERO</div>
<input name="TxtNum" type="text" id="TxtNum" 
style="left: 439px; top: 116px; width: 89px;" 
value="<?php echo $StrNum;?>"  onblur="_N(this);" maxlength="6"
onkeydown="return SoloTextoEx(event,'TxtDex');"
tabindex="<?php echo ++$TI;?>" />

<div class="s1" style="left: 544px; top: 84px; width: 45px;">
DESDE</div>
<div class="EV" style="left: 544px; top: 99px; width: 88px; color:#FF0"><u><a onclick="fFecServer('TxtDex')">(dd-mm-yy) +</a></u></div>
<input name="TxtDex" type="text" id="TxtDex" 
style="left: 544px; top: 116px; width: 74px;" value="<?php echo $StrDex;?>"  
onkeydown="return SoloFec(this,event,'TxtHax');"
tabindex="<?php echo ++$TI;?>" />

<div class="s1" style="left: 635px; top: 84px; width: 60px;">
HASTA</div>
<div class="EV" style="left: 635px; top: 99px; width: 88px; color:#FF0"><u><a onclick="fFecServer('TxtHax')">(dd-mm-yy) +</a></u></div>
<input name="TxtHax" type="text" id="TxtHax" 
style="left: 635px; top: 116px; width: 70px;" 
value="<?php echo $StrHax;?>"  
onkeydown="return SoloFec(this,event,'TxtPro');"
tabindex="<?php echo ++$TI;?>" />

<div class="s1" style="left: 717px; top: 100px; width: 92px;">
CLIENTE</div>
<input name="TxtPro" type="text" id="TxtPro" 
style="left: 718px; top: 116px; width: 159px;" value="<?php echo $StrPro;?>"  
onkeydown="return SoloTextoEx(event,'CboSN');" 
tabindex="<?php echo ++$TI;?>" />

<div class="s1" style="left: 890px; top: 100px; width: 79px;">
ANULADO</div>
<select name="CboSN" id="CboSN" 
style="left: 892px; top: 116px; width: 79px;" 
onkeydown="return SoloTextoEx(event,'CboVen');" tabindex="<?php echo ++$TI;?>">
<?php
	echo FCBO_("au_item","auxiliar","au_tab='SI_NO'",$StrSN,"S","N");
?>
</select>

<div class="s1" style="left: 982px; top: 100px; width: 79px;">VENDEDOR</div>
<select name="CboVen" id="CboVen" 
style="position:absolute; left: 983px; top: 116px; width: 126px;"
onkeydown="return SoloTextoEx(event,'CmdB');" tabindex="<?php echo ++$TI;?>"
>
<?php
echo FCBO_("NOMBRE","vpersonal","ID>0 AND CARGO='VENDEDOR'",$StrVen,"S","N");
?>
</select>

<input name="CmdB" type="button" id="CmdB" 
style="position:absolute; left: 1122px; top: 116px; width: 55px;"  tabindex="<?php echo ++$TI;?>"
value="Filtrar" onclick="fFiltrar();" />


</form>

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