<?php
include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");

$IdA=V($_POST['IdA']);
if(strlen($IdA)==0){$IdA=V($_GET['IdA']);}

?>
<html>
<head>
<title>SELECCIONA PRODUCTOS</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">
<script type="text/javascript" src="ja/funciones.js"></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; }
</style>

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

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

function Zet(id,cod,des,pco,pve,Mon){

	window.opener.document.Frm.PRO_ID.value=id;
	window.opener.document.Frm.TxtCod.value=cod;	
	window.opener.document.Frm.TxtDes.value=des;	
	window.opener.document.Frm.TxtPre.value=pve;
	window.opener.document.Frm.TxtCant.value="1";
	window.opener.document.Frm.TxtImp.value=pve;
	
	window.opener.document.Frm.Pro_TxtId.value=id;
	window.opener.document.Frm.Pro_TxtCod.value=cod;
	window.opener.document.Frm.Pro_TxtDes.value=des;
	
	if(Mon=="S"){
		Mon="S/ ";
	}else{
		Mon="$ ";
	}
	
	window.opener.document.getElementById("TxtPreC").innerHTML=Mon+pco;	
	window.opener.document.getElementById("TxtPreM").innerHTML="S/ "+pve;

	window.opener.GetCod2(id);
	
	window.opener.document.Frm.TxtCant.focus();
	window.close();
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<?php
include("pro_sel_bx.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="pro_sel.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:#09C; 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>SELECCIONAR PRODUCTOS</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 >Codigo</label>
            <input type="text" class="form-control lt" id="Cod" 
            value="<?php echo $Cod;?>" name="Cod" tabindex="<?php echo $CX++?>">
            </td>            
            <td width="65%">
            <label >Descripcion</label>
            <input type="text" class="form-control lt" id="Des" 
            value="<?php echo $Des;?>" name="Des" tabindex="<?php echo $CX++?>">
            </td>
            <td valign="bottom" width="5%">
            <button type="button" id="CmdB" name="CmdB" class="btnp" style="background-color:#F90;width:100%;" 
            onClick="SM('F');" tabindex="<?php echo $CX++?>">Buscar</button>
            </td>
            <td valign="bottom" width="5%">
            <button type="button" id="CmdX" name="CmdX" class="btnp" style="background-color:#F90;width:100%;" 
            onClick="window.close()" tabindex="<?php echo $CX++?>">Cerrar</button>
            </td>
            </tr>
            </table>
       </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="6" align="center"><?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?></td>
            </tr>
            
            <tr>
            <th>#</th>
            <th>CODIGO </th>
            <th>LINEA </th>            
            <th>DESCRIPCION</th>
            <th>MARCA</th>
            <th>PRE.VENTA</th>
            <th>STOCK</th>
            <th>PRE.COMPRA</th>         
            <th>#</th>
            </tr>
            </thead>
            <?php
			$CX=0;
			$s="SELECT * FROM viz_productos WHERE $FF ORDER BY DES";
			$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);
			$rs = grs($s);
			while ($r = $rs->fetch_assoc()){
				$CX++;
				$ID=$r['ID'];
				$CO=$r['COD'];
				$DE=$r['DES'];
				$PC=$r['PCO'];
				$PV=$r['PVE'];
				$MO=$r['MND'];
				//
				$Sto=gs("stock","stocks","id_almacen=1 AND id_producto=$ID");
				//
				//$PR=NF($r['PW'],2);
				$FN="Zet('".$ID."','".$CO."','".$DE."','".$PC."','".$PV."','".$MO."')";
				$CSS="";
				if($CX%2==0){
					$CSS=" style=\"background-color:#CCC\" ";
				}
			?>
                <tr <?php echo $CSS; ?> >
                <td><button type="button" class="btn btn-success" onClick="<?php echo $FN;?>">+</button></td>
                <td><?php echo $r['COD'];?></td>
                <td><?php echo $r['TIP'];?></td>
                <td><?php echo $r['DES'];?></td>
                <td><?php echo $r['MAR'];?></td>
                <td><?php echo $r['PVE'];?></td>
                <td><?php echo $Sto;?></td>
                <td><?php echo $MO." ".$r['PCO'];?></td>
                <td><button type="button" class="btn btn-success" onClick="<?php echo $FN;?>">+</button></td>
                </tr>
            <?php
			}
			?>
            </table>
       </div>
       </td>
       </tr>   
       </table>
    </div>
</div>
<input name="IdA" type="hidden" id="IdA" value="<?php echo $IdA;?>" />

</form>
</body>
</html>
