<?php
session_start();
include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("inicio.php");	return;}
$IdA=V($_POST['IdA']);
if(strlen($IdA)==0){$IdA=V($_GET['IdA']);}
$IdU=vbval(V($_SESSION['SYS_USER_ID']));
$POL_USU_OPC=vbval(gs("opc","usuarios","id_usuario=$IdU"));
?>
<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: 1px 1px 1px 1px;  }
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,Sto){

	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;
	window.opener.document.getElementById("TxtSTOCK").innerHTML=Sto;
	
	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_ex.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="25%" style=" padding-left:0.5rem">
            <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="55%" style=" padding-left:0.5rem; padding-right:0.5rem">
            <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="10%">
            <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="10%">
            <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:2%;">
       <td valign="top" 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 width="92%" align="center">PRODUCTOS</th>                    
            <th width="1%">#</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");
				//
				if($POL_USU_OPC==1){
					$MO="";
					$PC="*.**";
				}
				//
				$FN="Zet('".$ID."','".$CO."','".$DE."','".$PC."','".$PV."','".$MO."','".$Sto."')";
				$CSS="";
				if($CX%2==0){
					$CSS=" style=\"background-color:#CCC\" ";
				}
				
			?>
                <tr <?php echo $CSS; ?> >
                <td style="padding-left:0.5rem">
                  <table width="100%" border="0" cellpadding="0" cellspacing="0" >
                  <tr>
                    <td width="42%" style="font-size:0.7rem; margin:0 0 0 0 ">CODIGO</td>
                    <td width="58%" style="font-size:0.7rem;  margin:0 0 0 0 ">LINEA</td>
                  </tr>
                  <tr>
                    <td style="font-weight:bold; color:#383838"><?php echo $r['COD'];?></td>
                    <td style="font-weight:bold; color:#383838"><?php echo $r['TIP'];?></td>
                  </tr>
                  <tr>
                    <td colspan="2" style="font-size:0.7rem">DESCRIPCION</td>
                    </tr>
                  <tr>
                    <td colspan="2">
                    <input type="text" value="<?php echo $r['DES'];?>" 
                    style="width:100%; background-color:transparent; border:none; font-weight:bold; font-size:1.1rem ">
                    </td>
                    </tr>
                  <tr>
                    <td style="font-size:0.7rem; color:#383838">MARCA</td>
                    <td style="font-size:0.7rem; color:#383838">PRECIO VENTA</td>
                  </tr>
                  <tr>
                    <td style="font-weight:bold; color:#383838"><?php echo $r['MAR'];?></td>
                    <td style="font-weight:bold; font-size:1.1rem"><?php echo $r['PVE'];?></td>
                  </tr>
                  <tr>
                    <td style="font-size:0.7rem">STOCK</td>
                    <td style="font-size:0.7rem">PRECIO DE COMPRA</td>
                  </tr>
                  <tr>
                    <td style="font-weight:bold; color:#383838"><?php echo $Sto;?></td>
                    <td style="font-weight:bold; color:#383838"><?php echo $MO." ".$PC;?></td>
                  </tr>
                </table>
                
                </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;?>" />
<input name="TXT_OPC" type="hidden" id="TXT_OPC" value="<?php echo $POL_USU_OPC;?>">
</form>
</body>
</html>
