<?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']);
if(strlen($StrDex)==0)$StrDex=date("d-m-y");			
if(strlen($StrHax)==0)$StrHax=date("d-m-y");			
$StrPro=V($_POST['TxtPro']);
$StrVend=V($_POST['TxtVend']);
$Tdp=V($_POST['Tdp']);
$Tdp_=trim(vbmid(LIKE($Tdp),1,2));
$StrSN=V($_POST['CboSN']);	
$StrOpe=V($_POST['TxtOpe']);
//++
$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);
}
if(strlen($StrSN)==0 || $StrSN=="TODOS"){
$StrSN_="%";
}else{
$StrSN_=substr($StrSN,0,1);
}
$StrPro_=$StrPro."%";
$StrVend_=$StrVend."%";
$StrOpe_=$StrOpe."%";
//-------------------------
$FF="ID>0
AND NUM LIKE '$StrNum_' 
AND SER LIKE '$StrSer_'
AND CLI LIKE '$StrPro_' 
AND ANU LIKE '$StrSN_' 
AND VEND LIKE '$StrVend_' 
AND OPE LIKE '$StrOpe_' 
AND TDP LIKE '$Tdp_' ";

if($IdUsu>0){
	$FF=$FF." AND IDU=".$IdUsu;
}
//++
$LStrTR=gn("count(*)","vventas",$FF);
$LStrPag=V($_POST['TxtPag']);
if($StrCmd=="F"){$LStrPag="1";}
$VP_RegXPag=19;	
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);
$AT=gs("at","usuarios","id_usuario=$IdUsu");
?>
<html>
<head>
<title>Buscar Ventas</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
//include("ventas_bxr.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.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>BUSCAR VENTAS</b></td>
            <td >&nbsp;</td>
            </tr>
            </table>
       </div>
       </td>
       </tr>
       
       <tr style="height:5%;">
       <td valign="top">
       
     <div class="form-row" style=" margin-left:0px; margin-right:0px">    
    	<div class="form-group col-sm-6" style="margin:0 0 0 0; padding: 0 0 0 0;">
            <table width="100%" border="0" height="100%" style="margin:0 0 0 0; padding: 0 0 0 0">
            <tr>
            <td width="20%">
            <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="30%">
            <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="50%">
            <label >CLIENTE</label>
            <input type="text" class="form-control lt" id="TxtPro" 
            value="<?php echo $StrPro;?>" name="TxtPro" tabindex="<?php echo ++$TI;?>">
            </td>

            </tr>
            </table>
        </div>  
    	<div class="form-group col-sm-6" style="margin:0 0 0 0; padding: 0 0 0 0;">
            <table width="100%" border="0" height="100%" style="margin:0 0 0 0; padding: 0 0 0 0">
            <tr>
            <td width="40%">
            <label >VENDEDOR</label>
            <input type="text" class="form-control lt" id="TxtVend" 
            value="<?php echo $StrVend;?>" name="TxtVend" tabindex="<?php echo ++$TI;?>">
            </td>
            <td width="30%">
            <label >TIP.PAGO</label>
            <select name="Tdp" id="Tdp" 
            class="form-control lt" tabindex="<?php echo ++$TI;?>">
            <?php echo FCBO_("tipp_nombre","tipos_pagos","",$Tdp,"S","N");?>
            </select>
            </td>
            <td width="20%">
            <label >NRO.OPERACION</label>
            <input type="text" class="form-control lt" id="TxtOpe" 
            value="<?php echo $StrOpe;?>" name="TxtOpe" tabindex="<?php echo ++$TI;?>">
            </td>
            <td width="10%">
            <label >ANULADO</label>
           <select name="CboSN" id="CboSN" 
            class="form-control lt" onkeydown="return SoloTextoEx(event,'CmdB');" 
            tabindex="<?php echo ++$TI;?>">
            <?php
            echo FCBO("aux_nom","auxiliar","aux_des='SN'",$StrSN,"S","N");
            ?>
            </select>
            </td>

            </tr>
            </table>
        </div>           
	</div>
       
     <div class="form-row" style=" margin-left:0px; margin-right:0px">    
    	<div class="form-group col-sm-12" style="margin:0 0 0 0; padding: 0 0 0 0;">
            <table width="100%" border="0" height="100%" style="margin:0 0 0 0; padding: 0 0 0 0">
           
            <tr>
            <td colspan="2" valign="bottom" width="50%">
                <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="50%">
              <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>            
	</div>
       
       </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>
            <td colspan="12" align="center"><?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?></td>
            </tr>
            <tr>
            <th style="text-align:center;">#</th>
            <th width="30"  style="text-align:left; background:#999"">NUMERO</th>
            <th width="30"  style="text-align:left; background:#999"">FECHA</th>
            <th width="300"  style="text-align:left; background:#999"">CLIENTE</th>
            <th width="150" style="text-align:left; background:#999"">VENDEDOR</th>
            <th width="50" style="text-align:left; background:#999"">T.PAGO</th>
            <th width="138" style="text-align:left; background:#999"">NRO.OPERACION</th>
            <th width="12" style="text-align:left; background:#999"">A</th>
            <th width="65" style="text-align:right; background:#999"">TOTAL</th>
            <th width="68" style="text-align:right; background:#999"">C.ENVIO</th>
            <th width="78" style="text-align:right; background:#999"">T.FINAL</th>         
            <th style="text-align:center;">#</th>
            </tr>
            </thead>
			<?php		  		
            $i=0;
            $ST=0;
            $CE=0;
            $TF=0;
            $s="SELECT ID,ALM,COM,CONCAT(SER,'-',NUM) as SER_NUM,
            DATE_FORMAT(FEC,'%d-%m-%y') as FEX,CLI,
            VEND,ANU,TOT,OPE,TDP,COS_ENV ,IMP_TOT
            FROM vventas WHERE ".$FF." ORDER BY ALM,COM,SER,NUM,FEC,CLI ";
            $s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);
            $result = grs($s);				
            while ($row = $result->fetch_assoc()){
                $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['ID'];?>&Pag=0'">
                <img src="c.png" width="16" height="16">
                </a>
                </td>
                <!----------------------------------------------->
                <td class="tdx" >
                <input value="<?php echo $row['SER_NUM'];?>" type="text" 
                style="background-color:transparent; border:none; width:6rem">				
                </td>                
                <td class="tdx" >
                <input value="<?php echo $row['FEX'];?>" type="text" 
                style="background-color:transparent; border:none; width:5rem">				
                </td>
                <td class="tdx" >
                <input value="<?php echo $row['CLI'];?>" type="text" style="background-color:transparent; border:none; width:100%">				
                </td>
                <td class="tdx" >
                <input value="<?php echo $row['VEND'];?>" type="text" style="background-color:transparent; border:none; width:100%">				
                </td>                
                <td class="tdx"><?php echo $row['TDP'];?></td>
                <td class="tdx"><?php echo $row['OPE'];?></td>
                <td class="tdx"><?php echo $row['ANU'];?></td>
                <td style="text-align:right" class="tdx"><?php echo NF2($row['TOT'],1);?></td>
                <td style="text-align:right" class="tdx"><?php echo NF2($row['COS_ENV'],1);?></td>
                <td style="text-align:right" class="tdx"><?php echo NF2($row['IMP_TOT'],1);?></td> 
                <!----------------------------------------------->
                

                <td class="tdx" align="center">
                <a href="#" onClick="location.href='ventas_respon.php?Id=<?php echo $row['ID'];?>&Pag=0'">
                <img src="copiar.png" width="16" height="16">
                </a>
                </td>
                
                </tr>
                <?php
                $CE=$CE+$row['COS_ENV'];
                $TF=$TF+$row['IMP_TOT'];
                $ST=$ST+$row['TOT'];
                
            }
            
            ?>
            </table>
       </div>
       
       </td>
       </tr>   
       </table>
    </div>
</div>
</form>
</body>
</html>