<?php
session_start();
include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
include("phpmnu_fun.php");
//
if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("login.php");	return;}
//
$IdUsu=vbval(V($_SESSION['SYS_USER_ID']));
include("deos_ventas_det_bx.php");
?>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ventas - busqueda detallada</title>
<!----------------------------------------->
<?php AddJs(); ?>
<script type="text/javascript" src="ja/funciones.js"></script>

<!----------------------------------------->
<link rel="stylesheet" type="text/css" href="css/estiloss.css"  />
<link rel="stylesheet" type="text/css" href="css/basic.css"  />
<link rel="stylesheet" type="text/css" href="css/mnu.css"  />
<!----------------------------------------->
<style type="text/css">
.tableFixHead          { overflow-y: auto; }
.tableFixHead thead th { position: sticky; top: 0; }

table  {border-collapse:collapse;width:100%;}
th, td {padding: 3px 3px;}
th     {background:#666;}

.cF {height:600px;width:1250px;position:relative;top:0px}
.mM {height:34px;width:1250px;position:relative;top:0px;background-color:#09C; z-index:500;}
</style>

<!----------------------------------------->
<script>
$(document).ready(function(){  
   Inicializar();
   jF("CboAlm");
});


function fGenPDF(){
	var CboAlm=document.getElementById("CboAlm").value;
	if(CboAlm=="TODOS"){
		alert("Seleccione un Almacen");
		document.getElementById("CboAlm").focus();
		return;
	}
	document.getElementById("TxtAc").value="GEN_PDF";
	document.getElementById("Frm").submit();
}

function fGenPDF_2(){
	var CboAlm=document.getElementById("CboAlm").value;
	if(CboAlm=="TODOS"){
		alert("Seleccione un Almacen");
		document.getElementById("CboAlm").focus();
		return;
	}
	document.getElementById("TxtAc").value="GEN_PDF_2";
	document.getElementById("Frm").submit();
}

</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>
<!----------------------------------------->
<body  <?php echo $LStrMsg;?>  >
<div align="center">

<div class="mM" align="left" style="font-size:12px">
<?php
//$HTM=file_get_contents("http://inversionessounduniversal.com/ventas/phpmnu.php?USER_ID=$IdUsu");
echo GEN_MENU(vbval(V($_SESSION['SYS_USER_ID'])));
?>
</div>

<div Id="DivFRM"  class="cF" style="background-color:#FFFFFF;" >
<form id="Frm" name="Frm" method="post" action="ventas_det.php" 
autocomplete="off"
style="margin:0px; padding:0px; display:inline;" onSubmit="return false;">

<!----------------------------------------->
<div id="DivT" class="dT"  style="width:1250px;">
<img src="b.png" class="iT" />
<div class="tT">VENTAS - BUSQUEDA DETALLADA</div>
</div>

<!----------------------------------------->

<div class="s1" style="left: 35px; top: 121px; width: 102px;">
ALMACEN</div>
<select name="CboAlm" id="CboAlm" 
class="lt" style="left: 35px; top: 138px; width: 156px" 
tabindex="<?php echo ++$TI;?>">
<?php 
	if($IdUsu>=1  && V($_SESSION['SYS_USER_ALM'])!="%"){
		echo ListALM($StrAlm); 
	}else{
    	echo FCBO("alm_nombre","almacenes","id_almacen>0",$StrAlm,"S","N");
    }
?>
</select>

<div class="s1" style="left: 197px; top: 121px; width: 102px;">
COMPROBANTE</div>
<select name="CboCom" id="CboCom"
class="lt" style="left: 197px; top: 138px; width: 131px;"
tabindex="<?php echo ++$TI;?>">
<?php 
echo FCBO("com_nombre",
		  "comprobantes",
		  "id_comprobante>0 AND com_nombre IN ('NOTA DE VENTA')",$StrCom,"S","N");?>
</select>

<div class="s1" style="left: 336px; top: 121px; width: 46px;">
SERIE</div>
<input name="TxtSer" type="text" id="TxtSer" 
class="lt" style="left: 336px; top: 138px; width: 55px;" 
value="<?php echo $StrSer;?>" 
tabindex="<?php echo ++$TI;?>"/>

<div class="s1" style="left: 400px; top: 121px; width: 46px;">
NUMERO</div>
<input name="TxtNum" type="text" id="TxtNum" 
class="lt" style="left: 400px; top: 138px; width: 71px;" 
value="<?php echo $StrNum;?>"  
tabindex="<?php echo ++$TI;?>"/>


<div class="s1" style="left: 480px; top: 121px; width: 45px;">
DESDE</div>
<input name="TxtDex"  type="text" id="TxtDex"
class="fe" style="left: 480px; top: 138px; width:100px;" 
value="<?php echo $StrDex;?>" 
tabindex="<?php echo ++$TI;?>"/>

<div class="s1" style="left: 589px; top: 121px; width: 60px;">
HASTA</div>
<input name="TxtHax"  type="text" id="TxtHax"
class="fe" style="left: 590px; top: 138px; width:100px;" 
value="<?php echo $StrHax;?>" 
tabindex="<?php echo ++$TI;?>"/>

<div class="s1" style="left: 701px; top: 121px; width: 259px;">
DESCRIPCION / PRODUCTO</div>
<input name="TxtPro" type="text" id="TxtPro" 
class="lt" style="left: 701px; top: 138px; width: 514px" 
value="<?php echo $StrPro;?>"  
tabindex="<?php echo ++$TI;?>"/>
    
<!----------------------------------------->
<div id="DivBtn" align="left" style="position:absolute; left:35px; top: 71px; width: 551px; height: 26px;">
<input name="CmdB" type="button" id="CmdB" class="btm"
value="Buscar" onClick="fFiltrar();"  
tabindex="<?php echo ++$TI;?>" />

<input name="CmdB" type="button" id="CmdZ" class="btm"
value="Volver" onClick="fBuscar('ventas.php?TxtAc=X');"  
tabindex="<?php echo ++$TI;?>" />

<input name="CmdPDF" type="button" id="CmdPDF" class="btm" 
value="Generar PDF" onClick="fGenPDF_2();" style="display:none"
tabindex="<?php echo ++$TI;?>" />

<input name="CmdPDF" type="button" id="CmdPDF" class="btm" 
value="PDF.Det" onClick="fGenPDF();" style="display:none"
tabindex="<?php echo ++$TI;?>" />
</div>

<div  style="position:absolute; top:165px; left:35px; height:27px; background-color:#FFF; width: 1180px;">
<table width="100%" style="font-family:Arial, Helvetica, sans-serif; font-size:11px" border="0">
<tr>
<td align="center">
	<?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?>
</td>
</tr>
</table>
</div> 
    
<!----------------------------------------->
<div class="tableFixHead" style="position: absolute; left: 35px; top: 195px; width: 1180px; height: 379px; overflow:auto; border:solid 1px #363636">
<table id="Exportar_a_Excel" width="100%" style="font-family:Arial, Helvetica, sans-serif; font-size:11px;">
<thead>
<tr>
<th width="122" style="text-align:left; background:#999">COMPROBANTE</th>
<th width="77" style="text-align:left; background:#999">NUMERO</th>
<th width="91"  style="text-align:left; background:#999">FECHA</th>
<th width="72"  style="text-align:left; background:#999">CODIGO</th>
<th width="604" style="text-align:left; background:#999">DESCRIPCION</th>
<th width="40" style="text-align:right; background:#999">CAN</th>
<th width="77" style="text-align:right; background:#999">PRE</th>
<th width="59" style="text-align:right; background:#999">IMP</th>
</tr>
</thead>
<tbody>

<?php
	$i=0; 
	$s="SELECT ID,COM,CONCAT(SER,'-',NUM),DATE_FORMAT(FEC,'%d-%m-%y'),COD,DES,CA,PR,IM
		FROM vventas_det 
		WHERE ".$FF." 
		ORDER BY COM,SER,NUM,FEC,DES";
	$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);	
	$result = grs($s);				
	while ($row = $result->fetch_row()){
		$i++;
		$CSS="";
		if($i%2==0){
			$CSS=" style=\"background-color:#E2E2E2\" ";
		}
	?>	
	<tr onDblClick="location.href='ventas.php?Id=<?php echo $row[0];?>&Pag=0'" <?php echo $CSS;?>>
	<!----------------------------------------------->
	<td><?php echo $row[1];?></td>
    <td><a target="_blank" href="ventas.php?Id=<?php echo $row[0];?>">'<?php echo $row[2];?></a></td>  
    <td style="text-align:left;"><?php echo $row[3];?></td> 
    <td>'<?php echo $row[4];?></td>
    <td><?php echo vbl($row[5],70);?></td> 
	<td style="text-align:right"><?php echo $row[6];?></td>
    <td style="text-align:right"><?php echo NF2($row[7],1);?></td>
    <td style="text-align:right"><?php echo NF2($row[8],1);?></td>
	<!----------------------------------------------->
	</tr>
	<?php	
	$ST=$ST+$row[8];
	}
?>		  
       
</tbody>
</table>
</div>


<div class="s1" style="left: 1041px; top:577px; width: 74px;">
<b>TOTAL :</b></div>

<div class="s1" style="left: 1101px; top:577px; width: 110px; text-align:right">
<b><?php echo  NF2($ST,1);?></b></div>
<!----------------------------------------->
<?php include("ocultos.php");?>

<div class="s1" style="left: 33px; top: 579px; width: 426px;">
Doble Click sobre el registro para activar Actualizacion</div>
</form>


<form action="ficheroExcel.php" 
	method="post" target="_blank" id="FormularioExportacion" >

<div style="position: absolute; left: 408px; top: 71px; width: 45px; height: 15px;">  
    <input name="" type="button" class="botonExcel btm" value="Exportar" />
    <input type="hidden" id="datos_a_enviar" name="datos_a_enviar" />
</div>
</form>

<?php
if($StrCmd=="GEN_PDF_2"){
	$_PDF=GEN_PDF_2($FF,$StrAlm,$StrCom,$StrSer,$StrNum,$StrDex,$StrHax,$StrPro);
	$StrDES_2=$_PDF;
}

function GEN_PDF_2($FF,$StrAlm,$StrCom,$StrSer,$StrNum,$StrDex,$StrHax,$StrPro){
$_CxL=90;
$_S=10;	

$pdf = new PDF('P','mm',A4);
$pdf->AddPage();$pdf->SetFont('courier','',10);
$pdf->Cell(0,4,"",0,1);	
$pdf->Cell(0,4,"VENTAS",0,1);	
$pdf->Cell(0,4,"",0,1);	
//------------------------------------------

if(strlen($StrAlm)>0){
$_ENC=vbl("ALMACEN".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrAlm.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrCom)>0){
$_ENC=vbl("COMPROBANTE".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrCom.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrSer)>0){
$_ENC=vbl("SERIE".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrNum.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrNum)>0){
$_ENC=vbl("NUMERO".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrNum.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrDex)>0){
$_ENC=vbl("DESDE".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrDex.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrHax)>0){
$_ENC=vbl("HASTA".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrHax.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrPro)>0){
$_ENC=vbl("DESCRIPCION".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrPro.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}
$pdf->Cell(0,4,"",0,1);
$pdf->Cell(0,4,"",0,1);
//------------------------------------------
$P=0;
$P++;	$T[$P]=8;	$_ENC=vbl("COMPROB".vbfill(" ",$T[$P]),$T[$P]);
$P++;	$T[$P]=10;	$_ENC=$_ENC." ".vbl("NUMERO".vbfill(" ",$T[$P]),$T[$P]);
$P++;	$T[$P]=8;	$_ENC=$_ENC." ".vbl("FECHA".vbfill(" ",$T[$P]),$T[$P]);
$P++;	$T[$P]=8;	$_ENC=$_ENC." ".vbl("CODIGO".vbfill(" ",$T[$P]),$T[$P]);
$P++;	$T[$P]=29;	$_ENC=$_ENC." ".vbl("DESCIPCION".vbfill(" ",$T[$P]),$T[$P]);
$P++;	$T[$P]=4;	$_ENC=$_ENC." ".vbr(vbfill(" ",$T[$P])."CAN",$T[$P]);
$P++;	$T[$P]=8;	$_ENC=$_ENC." ".vbr(vbfill(" ",$T[$P])."PRE",$T[$P]);
$P++;	$T[$P]=8;	$_ENC=$_ENC." ".vbr(vbfill(" ",$T[$P])."IMP",$T[$P]);
$pdf->Cell(0,4,$_ENC,0,1);
$pdf->Cell(0,4,vbfill("-",$_CxL),0,1);	

$s="SELECT ID,COM,CONCAT(SER,'-',NUM),DATE_FORMAT(FEC,'%d-%m-%y'),COD,
	DES,CA,PR,IM
	FROM vventas_det WHERE ".$FF." ORDER BY COM,SER,NUM,FEC,DES";

$result = grs($s);
while ($row = $result->fetch_row()){	
	$P=0;
	$P++;	$_ENC=vbl($row[1].vbfill(" ",$T[$P]),$T[$P]);
	$P++;	$_ENC=$_ENC." ".vbl($row[2].vbfill(" ",$T[$P]),$T[$P]);
	$P++;	$_ENC=$_ENC." ".vbl($row[3].vbfill(" ",$T[$P]),$T[$P]);
	$P++;	$_ENC=$_ENC." ".vbl($row[4].vbfill(" ",$T[$P]),$T[$P]);
	$P++;	$_ENC=$_ENC." ".vbl($row[5].vbfill(" ",$T[$P]),$T[$P]);
	$P++;	$_ENC=$_ENC." ".vbr(vbfill(" ",$T[$P]).$row[6],$T[$P]);
	$P++;	$_ENC=$_ENC." ".vbr(vbfill(" ",$T[$P]).NF2($row[7],1),$T[$P]);
	$P++;	$_ENC=$_ENC." ".vbr(vbfill(" ",$T[$P]).NF2($row[8],1),$T[$P]);
	$pdf->Cell(0,4,$_ENC,0,1);
	$TOT=$TOT+$row[8];
}

$pdf->Cell(0,4,vbfill("-",$_CxL),0,1);	
$_TI=vbr(vbfill(" ",75)."TOTAL :",75);
$_TD=vbr(vbfill(" ",14).NF2($TOT,1),14);
$pdf->Cell(0,4,$_TI." ".$_TD,0,1);	

$_S=20;
$pdf->Cell(0,4,"",0,1);	
$pdf->Cell(0,4,"",0,1);	
//
$PDF_NAME="Ventas.pdf";
$pdf->Output($PDF_NAME);
return $PDF_NAME;
}
?>



<?php
if($StrCmd=="GEN_PDF"){
	$_PDF=GEN_PDF($FF,$StrAlm,$StrCom,$StrSer,$StrNum,$StrDex,$StrHax,$StrPro);
	$StrDESCARGAR=$_PDF;
}

function GEN_PDF($FF,$StrAlm,$StrCom,$StrSer,$StrNum,$StrDex,$StrHax,$StrPro){
$_CxL=90;
$_S=10;	

$pdf = new PDF('P','mm',A4);
$pdf->AddPage();$pdf->SetFont('courier','',10);
$pdf->Cell(0,4,"",0,1);	
$pdf->Cell(0,4,"VENTAS DETALLADO",0,1);	
$pdf->Cell(0,4,"",0,1);	
//
if(strlen($StrAlm)>0){
$_ENC=vbl("ALMACEN".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrAlm.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrCom)>0){
$_ENC=vbl("COMPROBANTE".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrCom.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrSer)>0){
$_ENC=vbl("SERIE".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrNum.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrNum)>0){
$_ENC=vbl("NUMERO".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrNum.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrDex)>0){
$_ENC=vbl("DESDE".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrDex.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrHax)>0){
$_ENC=vbl("HASTA".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrHax.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

if(strlen($StrPro)>0){
$_ENC=vbl("DESCRIPCION".vbfill(" ",15),15)." ".vbl(":".vbfill(" ",1),1);
$_ENC=$_ENC." ".vbl($StrPro.vbfill(" ",30),30);
$pdf->Cell(0,4,$_ENC,0,1);	
}

$pdf->Cell(0,4,"",0,1);
$pdf->Cell(0,4,"",0,1);	
//
$s="SELECT ID,COM,CONCAT(SER,'-',NUM),DATE_FORMAT(FEC,'%d-%m-%y'),COD,
	DES,CA,PR,IM
	FROM vventas_det WHERE ".$FF." GROUP BY ID ORDER BY COM,SER,NUM,FEC,DES";

$result = grs($s);
while ($row = $result->fetch_row()){
	$_ENC=vbl("COM: ".$row[1].vbfill(" ",20),20);
	$_ENC=$_ENC." ".vbl("NUM: ".$row[2].vbfill(" ",20),20);
	$_ENC=$_ENC." ".vbl("FEC: ".$row[3].vbfill(" ",20),20);
	$pdf->Cell(0,4,$_ENC,0,1);

	$P=0;
	$P++; $T[$P]=20;	$_ENC=vbl("CODIGO".vbfill(" ",$T[$P]),$T[$P]);
	$P++; $T[$P]=36;	$_ENC=$_ENC." ".vbl("DESCRIPCION".vbfill(" ",$T[$P]),$T[$P]);
	$P++; $T[$P]=10;	$_ENC=$_ENC." ".vbr(vbfill(" ",$T[$P])."CAN",$T[$P]);
	$P++; $T[$P]=10;	$_ENC=$_ENC." ".vbr(vbfill(" ",$T[$P])."PRE",$T[$P]);
	$P++; $T[$P]=10;	$_ENC=$_ENC." ".vbr(vbfill(" ",$T[$P])."IMP",$T[$P]);
	$pdf->Cell(0,4,$_ENC,0,1);
	$pdf->Cell(0,4,vbfill("-",$_CxL),0,1);	

	$TOT=0;

	$sS="SELECT ID,COD,DES,CA,PR,IM
		FROM vventas_det WHERE ID=$row[0] ORDER BY COM,SER,NUM,FEC,DES";

	$resultS = grs($sS);
	while ($rowS = $resultS->fetch_row()){	
	$P=0;
	$P++; $_ENC=vbl($rowS[1].vbfill(" ",$T[$P]),$T[$P]);
	$P++; $_ENC=$_ENC." ".vbl($rowS[2].vbfill(" ",$T[$P]),$T[$P]);
	$P++; $_ENC=$_ENC." ".vbr(vbfill(" ",$T[$P]).$rowS[3],$T[$P]);
	$P++; $_ENC=$_ENC." ".vbr(vbfill(" ",$T[$P]).NF2($rowS[4],1),$T[$P]);
	$P++; $_ENC=$_ENC." ".vbr(vbfill(" ",$T[$P]).NF2($rowS[5],1),$T[$P]);
	$pdf->Cell(0,4,$_ENC,0,1);	
	$TOT=$TOT+$rowS[5];
	}
	$pdf->Cell(0,4,vbfill("-",$_CxL),0,1);
	$_TI=vbr(vbfill(" ",75)."TOTAL :",75);
	$_TD=vbr(vbfill(" ",14).NF2($TOT,1),14);
	$pdf->Cell(0,4,$_TI." ".$_TD,0,1);	
	//
	$pdf->Cell(0,4,"",0,1);	
	$pdf->Cell(0,4,"",0,1);	
}

$_S=20;
$pdf->Cell(0,4,"",0,1);	
$pdf->Cell(0,4,"",0,1);	
//
$PDF_NAME="Ventas_Detallado.pdf";
$pdf->Output($PDF_NAME);
return $PDF_NAME;
}
?>


<?php
if(strlen($StrDES_2)>0){
echo "<div id=\"layer51\" 
	  style=\"position:absolute; left: 221px; top: 102px; 
	  width: 89px; background-color: #FFCC00; layer-background-color: #FFCC00; 
	  border: 1px none #000000; height: 17px;\">";
echo "<div align=\"center\" class=\"Estilo2\"> ";
echo " <a href=\"$StrDES_2\" download>Desc.PDF</a> ";
echo "</div>";
echo "</div>";
}
?>

<?php
if(strlen($StrDESCARGAR)>0){
echo "<div id=\"layer51\" 
	  style=\"position:absolute; left: 315px; top: 102px; 
	  width: 88px; background-color: #FFCC00; layer-background-color: #FFCC00; 
	  border: 1px none #000000; height: 17px;\">";
echo "<div align=\"center\" class=\"Estilo2\"> ";
echo " <a href=\"$StrDESCARGAR\" download>Desc.PDF</a> ";
echo "</div>";
echo "</div>";
}
?>

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