<?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;}

$StrId=V($_POST['TxtId']);
$StrCmd=V($_POST['TxtAc']);
//-------------------------
$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']);
//++
$IdUsu=vbval(V($_SESSION['SYS_USER_ID']));
//-------------------------
if($_SESSION['SYS_USER_ALM']=="%"){
	if(strlen($StrAlm)==0)$StrAlm=T($StrAlm);//$StrAlm=GetSO("alm_nombre","almacenes","","alm_nombre");
}else{
	$StrAlm=$_SESSION['SYS_USER_ALM'];
}
$StrAlm=T($StrAlm);
if(strlen($StrCom)==0) $StrCom="TODOS";	
//-------------------------
if($StrCom=="TODOS"){
	$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_="2020-12-01";
}else{
	$StrHax_=ToDate($StrHax);
}
$StrPro_=$StrPro."%";
//--------------------------
$FF="ID>0
	AND NUM LIKE '$StrNum_' 
	AND SER LIKE '$StrSer_'
	AND DES LIKE '$StrPro_' ";
if($IdUsu>0){
	$FF=$FF." AND IDU=".$IdUsu;
}
//-------------------------
$VP_RegXPag=50;	
$LStrPag=V($_POST['TxtPag']);	
if($StrCmd=="F"){$LStrPag="1";}
$LStrTR=gn("count(*)","vventas_det",$FF);
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);	
$TI=0;
?>
<html>
<head>
<title>Buscar Ventas Detallado</title> 
<meta charset="utf-8">
<meta name="viewport" content="target-densitydpi=device-dpi, initial-scale=1.0, user-scalable=no" />
<?php
AddJs();
?>
<link href="css/bootstrap.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="funciones.js" type="text/javascript"></script>
<style>
.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; }
.tdx{
	padding-top:5px;
	padding-bottom:5px;
}
</style>

<script>
$(document).ready(function(){  
   Inicializar();
   jF("Ser");
});
function ParseFrm(){
	var width = document.body.clientWidth;
	var height = document.body.clientHeight;
	//document.getElementById("Cli").value=width;
	width=width -10;
	document.getElementById("DivT").style.width=width+"px";
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<?php
$CX=0;
?>
<body style="background-color:#FFF;padding: 0 0 0 0; margin:0 0 0 0;overflow:hidden;"  onLoad="ParseFrm();" onResize="ParseFrm();">
<form id="Frm" style="padding: 0 0 0 0; margin:0 0 0 0"  method="post" action="ventas_br_det.php" autocomplete="off">
<input name="TxtId" type="hidden" id="TxtId" value="<?php echo $StrId;?>"/>
<input name="TxtAc" type="hidden" id="TxtAc" value="" />
<input name="TxtPag" type="hidden" id="TxtPag" value="<?php echo $LStrPag; ?>" />
<div class="container" style="max-width:95%; margin:0 0 0 0; padding:0 0 0 0">   
    <div  style="height:100vh;">  
       <table id="Tab"  border="0" cellspacing="0" cellpadding="0" style="background-color:#FFF; height:100%; width:98%">
       
       <tr style="height:5%;">
       <td valign="top">
       <div style="height:100%; width:100%; background-color:#2E4994; min-height:50px; vertical-align:middle" >
            <table width="90%" border="0" height="100%" style="margin:0 0 0 0; padding: 0 0 0 0">
            <tr>
            <td width="15px">&nbsp;</td>
            <td width="48px"><img src="b.png" width="48" height="48" longdesc="../sales.png"></td>
            <td style="color:#FFF"><b>VENTAS BUSQUEDA DETALLADA</b></td>
            <td >&nbsp;</td>
            </tr>
            </table>
       </div>
       </td>
       </tr>
       
       <tr style="height:5%;">
       <td valign="top">
       <div style="height:100%; width:100%; background-color:#FFF; min-height:50px; vertical-align:middle" >
            <table width="90%" border="0" height="100%" style="margin:0 0 0 0; padding: 0 0 0 0">
            <tr>
            <td width="15%">
            <label >SERIE</label>
            <input type="number" class="form-control nei" id="Ser" 
            value="<?php echo $Ser;?>" name="Ser" tabindex="<?php echo ++$TI;?>">
            </td>            
            <td width="10%">
            <label >NUMERO</label>
            <input type="number" class="form-control nei" id="Num" 
            value="<?php echo $Num;?>" name="Num" tabindex="<?php echo ++$TI;?>">
            </td>
            <td width="35%">
            <label >DESCRIPCION / PRODUCTO</label>
            <input name="TxtPro" type="text" id="TxtPro" 
            class="form-control lt" value="<?php echo $StrPro;?>"  
            tabindex="<?php echo ++$TI;?>"/>
            </td>            
           
            </tr>
            
            <tr>            
            <td colspan="2" >
                <button type="submit"  tabindex="<?php echo ++$TI;?>" class="btn btn-primary cmd" 
                style="height:calc(1em + 0.70rem + 2px); width:100%"><i class="fa fa-search"></i></button>
            </td>  
            <td valign="bottom" width="10%">
              <button  type="button" class="btn btn-primary cmd" 
              onClick="fBuscar('ventas_respon.php?CmdX=X')" tabindex="<?php echo ++$TI;?>" 
              style="height:calc(1em + 0.70rem + 2px); width:100%"><i class="fa fa-close"></i></button>
              
            </td>            
            </tr>
            </table>
       </div>
       </td>
       </tr>
       <tr>
       <td align="center">
       <?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?>
       </td>
       </tr>
       
       <tr style="height:90%">
       <td valign="top">
       <div class="tableFixHead" id="DivT" style="border:1px solid; border-color:#666;height:100%;background-color:#FFF;overflow:auto;">
            <table  style="font-size:0.9rem;" >
            <thead>
            <tr>
            <th style="text-align:center;">#</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>         
            <th style="text-align:center;">#</th>
            </tr>
            </thead>
			<?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\" ";
                    }
                ?>	
                <td align="center">
                <a href="#" onClick="location.href='ventas_respon.php?Id=<?php echo $row[0];?>&Pag=0'">
                <img src="c.png" width="16" height="16">
                </a>
                </td>  
                              
                <!----------------------------------------------->
                <td class="tdx" >
                <input value="<?php echo $row[2];?>" type="text" style="background-color:transparent; border:none; width:6rem">				
                </td>
                <td class="tdx" >
                <input value="<?php echo $row[3];?>" type="text" style="background-color:transparent; border:none; width:5rem">				
                </td>
                <td class="tdx" >
                <input value="<?php echo $row[4];?>" type="text" style="background-color:transparent; border:none; width:100%">				
                </td>
                <td class="tdx" >
                <input value="<?php echo $row[5];?>" type="text" style="background-color:transparent; border:none; width:100%">				
                </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>
                <!----------------------------------------------->
                <td class="tdx" align="center">
                <a href="#" onClick="location.href='ventas_respon.php?Id=<?php echo $row[0];?>&Pag=0'">
                <img src="c.png" width="16" height="16">
                </a>
                </td>
                </tr>
                <?php	
                $ST=$ST+$row[8];
                }
            ?>
            </table>
       </div>
       </td>
       </tr>   
       </table>
    </div>
</div>
</form>
</body>
</html>