<?php
	session_start();
	include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
	if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("login.php");	return;}
	//-------------------------
	$StrId=V($_POST['TxtId']);
	$StrCmd=V($_POST['TxtAc']);
	//-------------------------
	$StrAlm=V($_POST['CboAlm']);		
	$StrCom=V($_POST['CboCom']);		
	$StrSer=V($_POST['TxtSer']);		
	$StrDex=V($_POST['TxtDex']);		
	$StrTdp=V($_POST['CboTdp']);
	if(strlen($StrDex)==0)$StrDex=date("d-m-y");
	
	//-------------------------
	if($_SESSION['SYS_USER_ALM']=="%"){
		if(strlen($StrAlm)==0)$StrAlm=GetSO("alm_nombre","almacenes","","alm_nombre");
	}else{
		$StrAlm=$_SESSION['SYS_USER_ALM'];
	}
	if(strlen($StrCom)==0) $StrCom="TODOS";	
	if(strlen($StrTdp)==0) $StrTdp=GetSO("tipp_nombre","tipos_pagos","","tipp_nombre");	
	//-------------------------
	if($StrCom=="TODOS"){
		$StrCom_="%";
	}else{
		$StrCom_=$StrCom;
	}
	$StrNum_=$StrNum."%";
	$StrSer_=$StrSer."%";
	$StrTdp_=substr($StrTdp,0,2);
	if(strlen($StrDex)==0){
		$StrDex_="2000-01-01";
	}else{
		$StrDex_=ToDate($StrDex);
	}
	$StrHax_=$StrDex_;
	$StrPro_=$StrPro."%";
	//-------------------------
	$LStrTR=gn("count(*)","vventas",
							"ID>0 AND 
							ALM LIKE '$StrAlm' AND 
							COM LIKE '$StrCom_' AND 
							NUM LIKE '$StrNum_' AND 
							SER LIKE '$StrSer_' AND 
							FEC >= '$StrDex_' AND 
							FEC <= '$StrHax_' AND TDP LIKE '$StrTdp_' AND 
							CLI LIKE '$StrPro_' AND ANU='N'");
$LStrPag=V($_POST['TxtPag']);	
if($StrCmd=="F"){$LStrPag="1";}
$VP_RegXPag=10;	
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);			
	//-------------------------
	if($StrCmd=="PDF"){	
		//
		$TI="REPORTE DE VENTAS DEL DIA :: ALMACEN : $StrAlm";
		$s="SELECT COM,CONCAT(SER,'-',NUM),DATE_FORMAT(FEC,'%d-%m-%y'),CLI,TOT
			FROM vventas 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_' AND ANU='N' AND TDP LIKE '$StrTdp_' AND 
			CLI LIKE '$StrPro_' ORDER BY ALM,COM,ISER,INUM,FEC,CLI ";
		$T="COMPROB.,NUMERO,FECHA,CLIENTE,TOTAL";
		$E="10, 10, 8,44,10";
		$A=" 0, 0, 0, 0,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;			
	}	
?>
<!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=iso-8859-1" />
<title>Reporte de ventas del dia</title>
<script type="text/javascript" src="funciones.js"></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:800px;
	height:600px;
	position:absolute;
	left:50%;
	top:50%;
	background-color:#006699;
	margin:-300px 0 0 -400px;
}
#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;
}
.Estilo2 {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;}
.Estilo4 {color: #000099}
.Estilo5 {color: #000000}

-->
</style>

</head>
<body  <?php echo $StrMsg;?>>
<form id="Frm" name="Frm" method="post" action="rep_ventas_xdia.php">
<center> 
  <div Id="DivFRM"  class="centrarFrm" >
    <div id="layer5" style="position:absolute; left: 116px; top: 50px; width: 85px; height: 28px;">
      <div align="left" class="Estilo2">
        <input name="CmdV" type="button" id="CmdV" 
        value="Volver" onclick="fVolver('menu.php');" />
        <input type="hidden" name="TxtAc" id="TxtAc" />
        <input name="TxtPag" id="TxtPag" type="hidden" value="<?php echo $LStrPag; ?>" />
      </div>
  </div>
    <div id="layer3" style="position:absolute; left: 60px; top: 138px; width: 683px; height: 428px;">
      <div align="left" class="Estilo2">
        <table width="682" height="19" border="1" cellpadding="0" cellspacing="0">
        <tr  >
            <td height="18" colspan="6" bgcolor="#666666" align="center">
<?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?>     </td>
           
          </tr>
          <tr>
            <td width="93" bgcolor="#999999"><span class="Estilo4">ALMACEN</span></td>
            <td width="93" bgcolor="#999999"><span class="Estilo4">COMPROBANTE</span></td>
            <td width="75" bgcolor="#999999"><span class="Estilo4">NUMERO</span></td>
            <td width="84" bgcolor="#999999"><span class="Estilo4">FECHA</span></td>
            <td width="248" bgcolor="#999999"><span class="Estilo4">CLIENTE</span></td>
            <td width="75" bgcolor="#999999" 
            style="text-align:right"><span class="Estilo4">TOTAL</span></td>
          </tr>
		  <?php	
		  		$TOTAL=0; 				  		
				$s="SELECT ID,ALM,COM,CONCAT(SER,'-',NUM),DATE_FORMAT(FEC,'%d-%m-%y'),CLI,TOT
				     FROM vventas 
					 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_' AND ANU='N' AND TDP LIKE '$StrTdp_' AND 
					 CLI LIKE '$StrPro_' ORDER BY ALM,COM,ISER,INUM,FEC,CLI ";
		  					
				$X1="<td bgcolor=\"#FFFFFF\"><span class=\"Estilo5\">";
				$X2="</span></td>";
				$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);
				$result = grs($s);				
				while ($row = $result->fetch_row()){
					echo "<tr>";
					echo $X1.$row[1].$X2;
					echo $X1.$row[2].$X2;
					echo $X1.$row[3].$X2;
					echo $X1.$row[4].$X2;
					echo $X1.$row[5].$X2;
					echo "<td bgcolor=\"#FFFFFF\" 
					style=\"text-align:right\">
					<span class=\"Estilo5\">".$row[6].$X2;					
					echo "</tr>";
					$TOTAL=$TOTAL + $row[6];
				}

		  ?>		  
          <tr  >
            <td bgcolor="#FFFFFF">&nbsp;</td>
            <td bgcolor="#FFFFFF">&nbsp;</td>
            <td bgcolor="#FFFFFF" >nbsp;</td>
            <td bgcolor="#FFFFFF" >nbsp;</td>
            <td bgcolor="#FFFFFF" style="text-align:right; color: #000;">TOTAL</td>
            <td  bgcolor="#FFFFFF" style="text-align:right; color: #000;" ><?php echo $TOTAL;?></td>
          </tr>
         
        </table>
      </div>
    </div>
    <div id="layer" style="position:absolute; left: 116px; top: 30px; width: 622px; height: 20px;">
      <div align="left" class="Estilo1">REPORTE DE VENTAS DEL DIA</div>
    </div>
    <div id="LblTit" style="position:absolute; left: 57px; top: 25px; width: 64px;">
      <div align="left" class="Estilo1"><img src="img/buscar.png" width="57" height="60" /></div>
</div>	
    <div id="layer4" style="position:absolute; left: 583px; top: 109px; width: 57px; height: 26px;">
      <div align="left" class="Estilo2">
        <input name="CmdB" type="button" id="CmdB" value="Filtrar" onclick="fFiltrar();" />
      </div>
    </div>
    <div id="layer7" style="position:absolute; left: 399px; top: 89px; width: 45px;">
      <div align="left" class="Estilo2">FECHA</div>
    </div>
    <div id="layer8" style="position:absolute; left: 397px; top: 109px; width: 73px; height: 25px;">
      <div align="left" class="Estilo2">
        <input name="TxtDex" type="text" id="TxtDex" 
        style="width:75px" value="<?php echo $StrDex;?>"  
        onkeydown="return SoloFec(this,event,'CboTdp');"
        tabindex="1" />
      </div>
    </div>
    <div id="layer29" style="position:absolute; left: 176px; top: 109px; width: 138px; height: 25px;">
      <div align="left" class="Estilo2">
        <select name="CboCom" id="CboCom" 
        style="width:130px" 
onkeydown="return SoloTextoEx(event,'TxtSer');">
<?php
if($StrCom=="TODOS"){
	echo "<option value=\"TODOS\" selected=\"selected\">TODOS</option>";
}else{
	echo "<option value=\"TODOS\">TODOS</option>";
}
$s="SELECT com_nombre FROM comprobantes WHERE id_comprobante> 0 ORDER BY com_nombre";
$result = grs($s);
while ($row = $result->fetch_row()){
if($StrCom==$row[0]){
echo "<option value=\"$row[0]\" selected=\"selected\">$row[0]</option>";
}else{
echo "<option value=\"$row[0]\" >$row[0]</option>";
}
}
?>
        </select>
      </div>
  </div>
    <div id="layer13" style="position:absolute; left: 177px; top: 89px; width: 102px;">
      <div align="left" class="Estilo2">COMPROBANTE</div>
    </div>
    <div id="layer26" style="position:absolute; left: 59px; top: 109px; width: 109px; height: 25px;">
      <div align="left" class="Estilo2">
        <select name="CboAlm" id="CboAlm" style="width:110px" 
onkeydown="return SoloTextoEx(event,'CboCom');">
         <?php echo ListALM($StrAlm); ?>
        </select>
      </div>
    </div>
    <div id="layer14" style="position:absolute; left: 61px; top: 89px; width: 102px;">
      <div align="left" class="Estilo2">ALMACEN</div>
    </div>
    <div id="layer15" style="position:absolute; left: 316px; top: 89px; width: 46px;">
      <div align="left" class="Estilo2">SERIE</div>
    </div>
    <div id="layer16" style="position:absolute; left: 314px; top: 109px; width: 79px; height: 25px;">
      <div align="left" class="Estilo2">
        <input name="TxtSer" type="text" id="TxtSer" 
          style="width:70px" value="<?php echo $StrSer;?>"  
          onkeydown="return SoloTextoEx(event,'TxtDex');"
          tabindex="1" />
      </div>
    </div>
    <div id="layer11" style="position:absolute; left: 484px; top: 109px; width: 90px; height: 25px;">
      <div align="left" class="Estilo2">
        <select name="CboTdp" id="CboTdp" style="width:90px" 
onkeydown="return SoloTextoEx(event,'CmdB');" tabindex="9">
          <?php
	$s="SELECT tipp_nombre FROM tipos_pagos ORDER BY tipp_nombre";
	$result = grs($s);
	while ($row = $result->fetch_row()){
	if($StrTdp==$row[0]){
		echo "<option value=\"$row[0]\" selected=\"selected\">$row[0]</option>";
	}else{
		echo "<option value=\"$row[0]\" >$row[0]</option>";
	}
	}
?>
        </select>
      </div>
    </div>
    <div id="layer2" style="position:absolute; left: 487px; top: 89px; width: 87px;">
      <div align="left" class="Estilo2">TIPO DE PAGO</div>
    </div>
    <div id="layer6" style="position:absolute; left: 638px; top: 109px; width: 57px; height: 26px;">
<div align="left" class="Estilo2">
<input name="CmdB" type="button" id="CmdB" value="Imprimir" onclick="fPDF();" />
</div>
    </div>
  </div>
</center>	
</form>
</body>
</html>
