<?php
session_start();
include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
//
if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("inicio.php");	return;}
//++
$StrGT="";$LStrMsg="";$LStrFoc="";$LStrMM="";
//++
$StrId=V($_POST['TxtId']);
$StrCmd=V($_POST['TxtAc']);
$LStrPag=V($_POST['TxtPag']);
//
$IdU=vbval(V($_SESSION['SYS_USER_ID']));
$StrHWND_V=V($_SESSION['SYS_USER_ID']."_V");//++++++
include("ventas_fun.php");
$POL_USU_EV=gs("ev","usuarios","id_usuario=$IdU");
$POL_USU_MV=gs("mv","usuarios","id_usuario=$IdU");
$POL_USU_AV=gs("av","usuarios","id_usuario=$IdU");	
$POL_USU_MP=vbval(gs("mp","usuarios","id_usuario=$IdU"));
$POL_USU_OPC=vbval(gs("opc","usuarios","id_usuario=$IdU"));
//
$VP_RegXPag=10;
$LStrTR=gn("count(*)","marcas","id_marca>0");
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);	
$TI=0;
//
$IdUsu=vbval(V($_SESSION['SYS_USER_ID']));
$AT=gs("at","usuarios","id_usuario=$IdUsu");
//
$VEN_TR=gn("count(*)","ventas","id_venta>0");
//++
?>
<html >
<head>
<title>Ventas</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!--INI_SCRIPT------------------------------------------------------------------------------>
<?php AddJs(); ?>
<script type="text/javascript" src="ja/funciones.js"></script>
<script type="text/javascript" src="ja/ventaz6.js"></script>
<!--FIN_SCRIPT------------------------------------->

<!--
<link href="css/bootstrap.css" rel="stylesheet">
--->
<link href="css/bootstrap.css" rel="stylesheet">
<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;}
.cmd{
	margin-top:1rem; margin-right:0.5rem;width:8rem;
}


.grx{
	background-color:#FFCC00; 
	layer-background-color:#FFCC00; 
	border: 1px none #000000;
	border-radius: 0.25rem;
	padding-top:2px;
}
</style>

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

function ParseFrm(){
	var width = document.body.clientWidth;
	var height = document.body.clientHeight;
	/*if(width<500){
		document.getElementById("TdCod").style.width="40%";
	}else{
		document.getElementById("TdCod").style.width="25%";
	}*/
}

var FOCO=0;
var myVar=window.setInterval(function(){myTimer()},500);
var myVarC=window.setInterval(function(){myTimerC()},500);


function myTimer(){
	t=GetHora();
	tt=document.getElementById("TxtHora").value;	
	if(tt>0 && document.getElementById("ChN_BAR").checked==false){
		if(t-tt>=1){
			document.getElementById("TxtHora").value=0;
			fGetTabla();			
		}
	}

}

function myTimerC(){
	t=GetHora();
	tt=gv("TxtHoraC");	
	if(tt>0){
		if(t-tt>=1){
			sv("TxtHoraC","0");
			fGetTabla2();	
		}
	}
}

function myStopFunction(){
	clearInterval(myVar);
	clearInterval(myVarC);
}



$(document).keydown(function(e){
	var AT=gv("TxtAT");
	
	if(e.which==71 && e.altKey){		
		if(AT=="1"){	
		document.getElementById("CmdG").click();
		return;
		}
	}
	
	if(e.which==78 && e.altKey){
		if(AT=="1"){
		document.getElementById("CmdC").click();
		return;
		}
	}
	
	if(e.which==75 && e.altKey){
		if(AT=="1"){	
		document.getElementById("CmdE").click();
		return;
		}
	}

	if(e.which==66 && e.altKey){
		if(AT=="1"){	
		document.getElementById("CmdB").click();
		return;
		}
	}

	if(e.which==77 && e.altKey){
		if(AT=="1"){
		document.getElementById("CmdZ").click();
		return;
		}
	}
  
});
//
//
function KeyFoco(e){	
	var k;
	k=(document.all) ? e.keyCode :e.which;

	if(k==13){
		var Tip=gv("CboTdp");
		if(Tip=="CONTADO"){			
			document.getElementById("CboTar").value="";
			document.getElementById("CboTar").disabled=true;
			document.getElementById("CboBancos").value="";
			document.getElementById("CboBancos").disabled=true;
			document.getElementById("TxtPagarCon").disabled=false;
			document.getElementById("TxtPagarCon").value=document.getElementById("T_TO").value;
			document.getElementById("CboMon").disabled=false;
			document.getElementById("CboMon").value="SOLES";
			jF("TxtPagarCon");
		}		
		if(Tip=="CREDITO"){			
			document.getElementById("CboTar").value="";
			document.getElementById("CboTar").disabled=true;
			document.getElementById("CboBancos").value="";
			document.getElementById("CboBancos").disabled=true;
			document.getElementById("TxtPagarCon").disabled=true;
			document.getElementById("TxtPagarCon").value="0.0";
			document.getElementById("CboMon").disabled=false;
			document.getElementById("CboMon").value="SOLES";
			jF("CboMon");
		}
		if(Tip=="TARJETA"){	
			document.getElementById("CboTar").value="";
			document.getElementById("CboTar").disabled=false;
			document.getElementById("CboBancos").value="";
			document.getElementById("CboBancos").disabled=false;
			document.getElementById("TxtPagarCon").disabled=true;
			document.getElementById("TxtPagarCon").value="0.0";
			document.getElementById("CboMon").disabled=true;
			document.getElementById("CboMon").value="SOLES";											
			document.getElementById("CboTar").focus();
		}
		if(Tip=="DEPOSITO"){	
			document.getElementById("CboTar").value="";
			document.getElementById("CboTar").disabled=true;
			document.getElementById("CboBancos").value="";
			document.getElementById("CboBancos").disabled=false;
			document.getElementById("TxtPagarCon").disabled=true;
			document.getElementById("TxtPagarCon").value="0.0";
			document.getElementById("CboMon").disabled=true;
			document.getElementById("CboMon").value="SOLES";											
			document.getElementById("CboBancos").focus();
		}
		event.preventDefault();
		return true;
	}
}
//
function fFOCO(e,FOC){	
	var k;
	k=(document.all) ? e.keyCode :e.which;

	if(k==13){
		if(FOC=="P"){
			jF("CboMon");
		}
	
		if(FOC=="M"){
			fGuardar();
		}
		
		if(FOC=="B"){
			var Tip=gv("CboTdp");
			if(Tip=="DEPOSITO"){
				jF("TxtOpe");
			}
			if(Tip=="TARJETA"){
				fGuardar();
			}
			
		}		
		
		if(FOC=="O"){
			fGuardar();
		}
		
		if(FOC=="T"){
			jF("CboBancos");
		}

		
		event.preventDefault();
		return true;
	}
	
}


function InsBan(){
	Ow("bancos_p.php",480*ZO(),240*ZO());
}

function fBancos(){
	R=fLista("ban_nombre","bancos","id_banco>=0");
	FCBO('CboBancos',R);
	jF("CboBancos");
}

function fSelCliente(){
	var Alm=gv("CboAlm");
	//alert(Alm);
	//IdA=AX("gs","id_almacen","almacenes","alm_nombre='"+Alm+"'");	
	
	Ow("pro_sel_ex.php?IdA=1",800,800);
}

function fEditarRes(lpIndex){
	var hw=document.getElementById("TxtHW").value;
	OpenWin("ven_re_editar.php?I="+lpIndex+"&H="+hw,800,800);	
}
</script>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<body style="background-color:#999" onResize="ParseFrm()">

<div class="container" style="background-color:#FFF; padding-bottom:30px; max-width:95% ">
<form id="Frm" name="Frm" action="ventas_respon.php" method="post" autocomplete="off">
<!--INI_TITULO--------------------------------->
<div class="form-row" style="margin:0 0 0 0; padding: 0 0 0 0;">
    <div style="width:100%; background-color:#2E4994; min-height:60px;">
        <table width="100%" border="0">
        <tr>
        <td width="15px">&nbsp;</td>
        <td width="48px"><img src="img/ventas2.png" width="48" height="48" longdesc="../sales.png"></td>
        <td style="color:#FFF"><b>VENTAS</b></td>
        <td >&nbsp;</td>
        </tr>
        </table>
    </div>
</div>

<div class="form-row d-flex justify-content-start" style="text-align:left; margin-left:15px; margin-right:15px">    
<div class="form-group col-sm-12"  >
<input name="CmdB" type="button" id="CmdG" class="btn btn-primary cmd"
<?php
if(strlen($StrId)==0){
echo "value=\"Guardar\"";
}else{
echo " value=\"Modificar\" ";
$_YA="";
$StrAnu=gs("anu","ventas","id_venta=$StrId");
if($StrAnu=="S"){
echo " disabled=\"disabled\"";
$_YA="S";
}
//
$StrCan=gs("ven_cancelado","ventas","id_venta=$StrId");
if($StrCan=="S" && strlen($_YA)==0){
echo " disabled=\"disabled\"";
$_YA="S";
}
//
if($POL_USU_AV=="0" && strlen($_YA)==0){
echo " disabled=\"disabled\"";
}
}
?>
onclick="fGuardar();"  
tabindex="<?php echo ++$TI;?>"/>

<input name="CmdB" type="button" id="CmdC" class="btn btn-primary cmd"
value="Nuevo" onClick="fCancelarPHP();"  
tabindex="<?php echo ++$TI;?>"/>


<input name="CmdB" type="button" id="CmdA" class="btn btn-primary cmd"
value="Anular" onClick="flAnular();"
<?php
if(strlen($StrId)==0){
echo " disabled=\"disabled\"";
}else{
$_YA="";
$StrAnu=gs("anu","ventas","id_venta=$StrId");
if($StrAnu=="S"){
echo " disabled=\"disabled\"";
$_YA="S";
}
//
$StrCan=gs("ven_cancelado","ventas","id_venta=$StrId");
if($StrCan=="S" && strlen($_YA)==0){
echo " disabled=\"disabled\"";
$_YA="S";
}
//
if($POL_USU_AV=="0" && strlen($_YA)==0){
echo " disabled=\"disabled\"";
}		
}
?>
tabindex="<?php echo ++$TI;?>"/>

<input name="CmdB" type="button" id="CmdE" class="btn btn-primary cmd"
value="Eliminar" onClick="flEliminar();"
<?php
if(strlen($StrId)==0){
echo " disabled=\"disabled\"";
}else{
$_YA="";
$StrAnu=gs("anu","ventas","id_venta=$StrId");
if($StrAnu=="S"){
echo " disabled=\"disabled\"";
$_YA="S";
}
//
$StrCan=gs("ven_cancelado","ventas","id_venta=$StrId");
if($StrCan=="S" && strlen($_YA)==0){
echo " disabled=\"disabled\"";
$_YA="S";
}
//
if($POL_USU_EV=="0" && strlen($_YA)==0){
echo " disabled=\"disabled\"";
}

}
?>
tabindex="<?php echo ++$TI;?>"/>

<input name="CmdB" type="button" id="CmdE" class="btn btn-primary cmd"
value="Env.por.Email" onClick="fEnviarPDF();" style="display:none"
<?php
if(strlen($StrId)==0){
echo "disabled=\"disabled\"";
}else{
$StrAnu=gs("anu","cotizaciones","id_cotizacion=$StrId");
if($StrAnu=="S"){
    echo " disabled=\"disabled\"";
}
}
?>
tabindex="<?php echo ++$TI;?>"/>



<input name="CmdB" type="button" id="CmdB" class="btn btn-primary cmd"
value="Buscar" onClick="fBuscar('ventas_br.php');"  
tabindex="<?php echo ++$TI;?>"/>

<input name="CmdB" type="button" id="CmdB" class="btn btn-primary cmd"
value="Bus. Det" onClick="fBuscar('ventas_br_det.php');"  
tabindex="<?php echo ++$TI;?>"/>

<input name="CmdB" type="button" id="CmdB" class="btn btn-primary cmd"
value="Salir" onClick="fBuscar('inicio.php');"  
tabindex="<?php echo ++$TI;?>"/>
</div>
</div>

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

    <div class="form-row" style=" margin-left:15px; margin-right:15px">    
    	<div class="form-group col-sm-12" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>
        <td>
        <?php if(strlen($Fec)==0)$Fec=date("d-m-y");?>
        <label style="text-align:left">TIPO DE CAMBIO
          <input type="text" class="form-control roi" id="TxtTC" name="TxtTC" 
        value="<?php echo $StrTC;?>"  tabindex="<?php echo ++$TI;?>" >
        </label>
        </td>
        </tr>
        </table> 
        </div>       
	</div>
    
    <div class="form-row" style=" margin-left:15px; margin-right:15px">    
    	<div class="form-group col-sm-12" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>        
        <td width="35%">
        <label >COD.BARRAS</label>        
        <input name="ChN_BAR" tabindex="<?php echo ++$TI;?>"
        type="checkbox" id="ChN_BAR"class="lt" 
        value="1"  onchange="ChN_BAR_OnChange();"
        <?php if($StrN_BAR=="1"){echo "checked=\"checked\"";}?>/>
        </td>
        
        <td width="65%">
        <label >AUTO AGREGAR</label>        
        <input name="ChN_AUT" tabindex="<?php echo ++$TI;?>"
        type="checkbox" id="ChN_AUT"
        class="lt" value="1"  onchange="ChN_BAR_OnChange();"
        <?php if($StrN_AUT=="1"){echo "checked=\"checked\"";}?>/> 
        </td>
 
        
        </tr>
        </table> 
        </div>       
	</div>
    
    <div class="form-row" style=" margin-left:15px; margin-right:15px">    
    	<div class="form-group col-sm-4" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>
        <td>&nbsp;</td>        
        </tr>
        </table> 
        </div>     
	</div>
    
    <div class="form-row" style=" margin-left:15px; margin-right:15px">        
        <div class="form-group col-sm-4" style="margin:0 0 0 0; padding: 0 0 0 0;">
            <table style="margin:0 0 0 0; padding: 0 0 0 0;min-width:95%">
            <tr>
            
            <td width="60%"> 
            <label >ALMACEN</label>          
            <select name="CboAlm" id="CboAlm" 
            class="form-control lt" tabindex="<?php echo ++$TI;?>">
            <?php echo ListALM($StrAlm); ?>
            </select>
            </td>
            
            <td width="40%">
            <label >FECHA</label>
            <input type="text" class="form-control fe" id="TxtFec" name="TxtFec"
            value="<?php echo $StrFec;?>" tabindex="<?php echo ++$TI;?>">
            </td>
            </tr>
            </table>                 
        </div>        
	</div>

    <div class="form-row" style=" margin-left:15px; margin-right:15px">    
    	<div class="form-group col-sm-4" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>
        <td>&nbsp;</td>        
        </tr>
        </table> 
        </div>     
	</div>

    <div class="form-row" style=" margin-left:15px; margin-right:15px">    
    	<div class="form-group col-sm-4" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>
        <td  width="30%" >
            <label >CODIGO</label>
			<em style="color:#FFF; font-size:15px">--</em>
            <input type="text" class="form-control roi" name="TxtCod" id="TxtCod" 
            value="<?php echo $StrCod;?>"
			tabindex="<?php echo ++$TI;?>">      
        </td>
        </tr>
        </table> 
        </div>   
        

        
        <div class="form-group col-sm-8" style="margin:0 0 0 0; padding: 0 0 0 0;">
            <table style="margin:0 0 0 0; padding: 0 0 0 0;min-width:95%">
            <tr>            
            <td width="95%"> 
            <label>DESCRIPCION</label>
            <b style="color:#FFF;">----</b>
			<b style="color:#900; font-size:13px">Pre.Com : <b id="TxtPreC" style="color:#900; font-size:15px">00.0</b></b>
            
            <b style="color:#FFF;">----</b>
            <b style="color:#00F; font-size:13px">Pre.Ven : <b id="TxtPreM" style="color:#00F; font-size:15px">00.0</b></b>
            
            <b style="color:#FFF;">---</b>
            <b style="color:#096; font-size:13px">Stock : <b id="TxtSTOCK" style="color:#096; font-size:15px">00.0</b></b>       
           
            <input type="text" class="form-control roi" name="TxtDes" id="TxtDes" 
            value="<?php echo $StrDes;?>"
			tabindex="<?php echo ++$TI;?>">
            </td>

            <td valign="bottom" width="5%">
            <button type="button" id="CmdSelPro" class="btnp" 
            style="width:100%; background-color:#F90" onClick="fSelCliente()">...</button>
            </td>
            
            </tr>
            </table>                 
        </div>                    
	</div>

    <div class="form-row" style=" margin-left:15px; margin-right:15px">    
    	<div class="form-group col-sm-9" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>
        <td  width="30%">
        <label >S/ PRECIO</label>
        <input type="text" class="form-control lt" name="TxtPre" id="TxtPre" 
        value="<?php echo $StrPre;?>"
        onkeyup="fImporte();" onFocus="selecciona_value(this);"
        <?php 
        if($POL_USU_MP==0){
            echo "readonly=\"readonly\" ";
        }
        ?>
        tabindex="<?php echo ++$TI;?>">
        </td>
        
        <td>
        <label >CANT</label>
        <input type="text" class="form-control lt" name="TxtCant" id="TxtCant" 
        value="<?php echo $StrCant;?>"
        onkeyup="fImporte();" onFocus="selecciona_value(this);"
        tabindex="<?php echo ++$TI;?>">
        </td>
        
        <td>
        <label >S/ IMPORTE</label>
        <input type="text" style="text-align:right" class="form-control rod" name="TxtImp" id="TxtImp" 
        value="<?php echo $StrImp;?>"
        tabindex="<?php echo ++$TI;?>">
        </td>
        
        </tr>
        </table> 
        </div>   
        
        <div class="form-group col-sm-3" style="margin:0 0 0 0; padding: 0 0 0 0;">
            <table style="margin:0 0 0 0; padding: 0 0 0 0;min-width:95%">
            <tr>            
            <td>
            <label style="color:#FFF" >AGREGAR</label>
            <input type="button" name="CmdAdd" style="width:100%" 
            id="CmdAdd" value="Agregar" onClick="fAgregar();" 
            tabindex="<?php echo ++$TI;?>"/>
            </td>

            <td>
            <label style="color:#FFF">LIMPIAR</label>
            <input type="button" name="CmdLim" style="width:100%" 
            id="CmdLim" value="X" onClick="fLimpiar();" 
            tabindex="<?php echo ++$TI;?>"/>
            </td>
            
            </tr>
            </table>                 
        </div>              
	</div>
    

    <div id="GriVen" class="tableFixHead" style="height: 197px; overflow: auto; border: solid 1px #A9A9A9; margin-left:15px; margin-right:15px">
    <table width="100%" style="font-family:Arial, Helvetica, sans-serif; font-size:11px">
    <thead>
    <tr>
    <th width="17">#</th>
    <th width="133">CODIGO</th>
    <th width="541">DESCRIPCION</th>
    <th width="207" >MARCA</th>
    <th width="54" align="right">PRECIO</th>
    <th width="51" align="right">CANT</th>
    <th width="91" align="right">IMPORTE</th>
    <th width="24">&nbsp;</th>
    <th width="20">&nbsp;</th>
    </tr>
    </thead>
    <tbody>
    
    <?php
    $ZX=0;
    $s="SELECT * FROM temp_compras WHERE cod_temc='$StrHWND_V' ORDER BY temc_index";
    $result = grs($s);
    $X_IMPORTE=0;
    $X_ST=0;
    $X_IG=0;
    $X_TO=0;
    while ($row = $result->fetch_row()){
        $X_ID=$row[1];
        $X_CO=$row[6];
        $X_DE=$row[7];
        $X_MA=VV(gs("MARCA","vproductos","ID=$X_ID"));
        $X_CA=$row[2];	
        $X_PR=$row[3];	
        $X_IM=$row[4];	
        $X_IMPORTE=$X_IMPORTE+$X_IM;
        $X_IM=number_format($X_IM,2,'.','');
        $ZX++;
        $CSS="";
        if($ZX%2==0)$CSS=" style=\"background-color:#CCC\" ";
    ?>
    <tr <?php echo $CSS;?>>
    <td width="17" ><?php echo $ZX;;?></td>
    <td width="133" ><?php echo VV($X_CO);?></td>
    <td width="541" ><?php echo VV($X_DE);?></td>
    <td width="207" ><?php echo VV($X_MA);?></td>
    <td width="54" align="right"><?php echo VV($X_PR);?></td>
    <td width="51" align="right"><?php echo VV($X_CA);?></td>
    <td width="91" align="right"><?php echo VV($X_IM);?></td>
    <td width="24" align="center"><a href="javascript:void(0)" onClick="fKiller('<?php echo $row[5];?>');" ><img src="img/eliminar.png" width="16" height="16" /></a></td>
    <td width="20" align="center"><a href="javascript:void(0)" onClick="fEditarRes('<?php echo $row[5];?>');"><img src="img/b_edit.png"  border="0"/></a></td>
    </tr>
    <?php
    }
    $X_IMPORTE=round($X_IMPORTE,1);
    //
    if($StrN_INC=="1"){
        $X_ST=$X_IMPORTE;
        $X_IG=round($X_ST * 0.18,2);
        $X_TO=$X_ST + $X_IG;		
    }else{
        $X_UNO=$X_IMPORTE / 118;
        $X_IG=round($X_UNO * 18,2);
        $X_ST=$X_IMPORTE - $X_IG;
        $X_TO=$X_ST + $X_IG;	
    }
    ?>
    
    </tbody>
    </table>
    
    
  
 <div class="form-row" style="visibility:hidden; margin-left: 15px; margin-right: 15px; top: 609px; left: 2px;">    
    <div class="form-group col-sm-12" style="margin:0 0 0 0; padding: 0 0 0 0;">
    <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
    <tr>
    <td  width="100%">
    
    <div id="TAB_AJAX" class="datagrid" style="visibility:hidden; border: 1px none #000000;">
    
    </div>
    
    <div id="TAB_CAPTION" class="datagrid" style="visibility:hidden; border: 1px none #000000;" align="left">
    </td>     
    </tr>
    </table> 
    </div>           
</div>
  
    
    
    </div>

    <div class="s1" style="left: 807px; top: 402px; width: 75px;display:none">
    <b>SUB TOTAL</b></div>
    <input name="T_ST" type="text" id="T_ST" 
    class="rod" style="left: 886px; top: 398px; width:75px; height:25px; border:none; padding-right:5px; display:none"
    value="<?php echo number_format($X_ST,2,'.','');?>" />
    
    <div class="s1" style="left: 974px; top: 402px; width: 28px;display:none">
    <b>IGV</b></div>
    <input name="T_IG" type="text" id="T_IG" 
    class="rod" style="left: 1004px; top: 398px; width:70px; height:25px;border:none; padding-right:5px;display:none"
    value="<?php echo number_format($X_IG,2,'.','');?>" />

    <div class="form-row" style=" margin-left:15px; margin-right:15px">    
    	<div class="form-group col-sm-12" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>
        <td  width="70%" style="text-align:right" >
        <label >TOTAL</label>
        </td>
        <td  width="30%">    
        <input type="text" class="form-control rod" name="T_TO" id="T_TO" 
        value="<?php echo number_format($X_TO,2,'.','');?>" style="text-align:right"
        tabindex="<?php echo ++$TI;?>">
        </td>
        </tr>
        </table> 
        </div>           
	</div>

    <div class="form-row" style=" margin-left:15px; margin-right:15px">    
    	<div class="form-group col-sm-7" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>
        <td  width="60%">&nbsp;
        		
        </td>
        
        <td width="40%">
		<?php
        if($VEN_TR>0){
            $StrN_AUTO=1;
        }
        ?>
        <input name="ChN_AUTO" type="checkbox"
        class="lt" id="ChN_AUTO"  
        onClick="AutoNumeracion(document.getElementById('ChN_AUTO').checked);fVenTR();" value="1"
        <?php if($StrN_AUTO=="1"){echo "checked=\"checked\"";}?>
        />
        <label >NUM.AUTOMATICA</label>  
        </td>
        </tr>
        </table> 
        </div>
        
    	<div class="form-group col-sm-5" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>
        <td  width="100%">&nbsp;
        		
        </td>
        </tr>
        </table> 
        </div>   
	</div>
    
    <div class="form-row" style=" margin-left:15px; margin-right:15px">    
    	<div class="form-group col-sm-7" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>
        <td  width="60%">
        <label >COMPROBANTE</label>        
        <select name="CboCom" id="CboCom" 
        class="form-control lt" tabindex="<?php echo ++$TI;?>">
        <?php 
        echo FCBO_("com_nombre","comprobantes","id_comprobante>0 AND com_nombre IN('NOTA DE VENTA')",$StrCom,"","");?>
        </select>
        </td>
        
        <td  width="20%">
        <label >SERIE</label>             
        <input name="TxtSer" type="text" id="TxtSer" 
        class="form-control lt" style="left: 0px; <?php if($VEN_TR>0) echo "background-color:#CCC"; ?>" 
        value="<?php echo $StrSer;?>"  onBlur="fcSer()"
        <?php if($VEN_TR>0) echo " readonly "; ?>
        tabindex="<?php echo ++$TI;?>"/>
        </td>
        
        <td  width="20%">
        <label >NUMERO</label>             
        <input name="TxtNum" type="text" id="TxtNum" 
        class="form-control lt" style="left: 0px;<?php if($VEN_TR>0) echo "background-color:#CCC"; ?>" 
        <?php if($VEN_TR>0) echo " readonly "; ?> onBlur="fcNum()"
        value="<?php echo $StrNum;?>"
        tabindex="<?php echo ++$TI;?>"/>
        </td>
        
        </tr>
        </table> 
        </div> 
        
    	<div class="form-group col-sm-5" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>
        <td  width="50%">
        <label >RUC</label>        
        <input name="TxtRuc" type="text" id="TxtRuc" 
        class="form-control lt" value="<?php echo $StrRuc;?>" maxlength="11" 
        onkeydown="return KeyRuc(event);"
        tabindex="<?php echo ++$TI;?>"/>
        </td>
        
        <td  width="50%">
        <label >DNI</label>             
        <input name="TxtDni" type="text" id="TxtDni" 
        class="form-control lt" value="<?php echo $StrDni;?>" maxlength="15"  
        onkeydown="return KeyDni(event);"
        tabindex="<?php echo ++$TI;?>"/>
        </td>
        
        </tr>
        </table> 
        </div>          
	</div>

    <div class="form-row" style=" margin-left:15px; margin-right:15px">    
    	<div class="form-group col-sm-6" style="margin:0 0 0 0; padding: 0 0 0 0;">        
        <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>
        
        <td valign="bottom" width="5%">
        <button type="button" id="CmdSelPro" class="btnp" 
        style="width:100%; background-color:#F90" onClick="Ow('cli_ven_sel.php',800,800)">...</button>
        </td>
        
        <td valign="bottom" width="5%">
        <button type="button" id="CmdSelPro" class="btnp" 
        style="width:100%; background-color:#F90"  onclick="fCls();">X</button>
        </td>
         
        <td  width="90%">
        <label >CLIENTE / RAZON SOCIAL</label>        
        <input type="text" name="TxtCliente" id="TxtCliente" 
        class="form-control lt" value="<?php echo $StrCliente;?>" 
        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 style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>        
        <td  width="100%">
        <label >DIRECCION</label>        
        <input name="TxtDIR" type="text" id="TxtDIR" 
        class="form-control lt" value="<?php echo $StrDIR;?>"  
        tabindex="<?php echo ++$TI;?>"/>
        </td>
               
        </tr>
        </table>
        </div>     
	</div>

    <div class="form-row" style=" margin-left:15px; margin-right:15px">    
    	<div class="form-group col-sm-8" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>
        
        <td  width="20%">
        <label >TELEFONO</label>             
        <input name="TxtTel" type="text" id="TxtTel" 
        class="form-control lt" value="<?php echo $StrTel;?>"   maxlength="12"
        tabindex="<?php echo ++$TI;?>"/>
        </td>        

        <td  width="80%">
        <label >EMAIL</label>        
        <input name="TxtEma" type="text" id="TxtEma" 
        class="form-control lt" value="<?php echo $StrEma;?>"  
        tabindex="<?php echo ++$TI;?>"/>
        </td>
        </tr>
        </table> 
        </div> 
        
    	<div class="form-group col-sm-4" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>
        <td  width="100%">
        <label >VENDEDOR</label>        
        <select name="CboVend" id="CboVend" 
        class="form-control lt" tabindex="<?php echo ++$TI;?>">
        <?php 
            echo FCBO_("per_nombre","personal","id_personal>0",$CboVend,"","S");
        ?>
        </select>
        </td>       
        </tr>
        </table> 
        </div>          
	</div>
    
    <div class="form-row" style=" margin-left:15px; margin-right:15px">    
    	<div class="form-group col-sm-7" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>
        <td  width="35%">
        <label >COSTO DE ENVIO</label>        
        <input name="TxtEnv" type="text" id="TxtEnv" 
        class="form-control ndd" value="<?php echo $StrEnv;?>"
        onkeyup="f_CAL_IMP_TOT();" 
        onFocus="selecciona_value(this);"
        tabindex="<?php echo ++$TI;?>"/>
        </td>
		<?php
        $StrTOT_IMP=round(vbval($StrEnv)+$X_TO,2);
        ?>
        <td  width="25%">
        <label >IMP.TOTAL</label>             
        <input name="TXT_TOT_IMP" type="text" 
        id="TXT_TOT_IMP" 
        class="form-control ndd" style="background-color:#CCC" 
        value="<?php echo $StrTOT_IMP;?>" readonly />
        </td>  
        
        <td  width="40%">
        <label >TIPO DE PAGO *</label> 
        <select name="CboTdp" id="CboTdp" class="form-control lt"        
        tabindex="<?php echo ++$TI;?>" onkeydown="return KeyFoco(event);"
        onchange="TDP();">
        <?php
        echo FCBO("tipp_nombre","tipos_pagos","",$StrTdp,"N","N");
        ?>
        </select>
        </td>       
        </tr>
        </table> 
        </div> 
        
    	<div class="form-group col-sm-5" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>
        <td  width="35%">
        <label >TARJETA</label>        
        <select name="CboTar" id="CboTar" class="form-control lt" 
        onkeydown="return fFOCO(event,'T'); ">
        <?php
        if($StrTdp=="CONTADO" || $StrTdp=="DEPOSITO"  || $StrTdp=="CREDITO"){
        echo "disabled=\"disabled\"";
        }
        ?>
        >
        <?php
        $s="SELECT tar_nombre FROM tarjetas ORDER BY id_tarjeta";
        $result = grs($s);
        while ($row = $result->fetch_row()){
        if($StrTar==$row[0]){
        echo "<option value=\"$row[0]\" selected=\"selected\">$row[0]</option>";
        }else{
        echo "<option value=\"$row[0]\" >$row[0]</option>";
        }
        }
        ?>
        </select>
        </td>
        
        <td  width="35%">
        <label >BANCO</label>        
        <select name="CboBancos" id="CboBancos" class="form-control lt" 
        onkeydown="return fFOCO(event,'B'); ">
        <?php
        if($StrTdp=="CONTADO" || $StrTdp=="CREDITO"){
            echo "disabled=\"disabled\"";
        }
        ?>
        >
        <?php
            echo FCBO("ban_nombre","bancos","ban_nombre>=0",$StrBan,"N","N");
        ?>
        </select>
        </td>
        
        </tr>
        </table> 
        </div>          
	</div>
        
    <div class="form-row" style=" margin-left:15px; margin-right:15px">    
    	<div class="form-group col-sm-6" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>
        <td  width="50%">
        <label >NRO.OPERACION</label>        
        <input type="text" name="TxtOpe" id="TxtOpe" class="form-control lt" 
        onkeydown="return fFOCO(event,'O'); "
        <?php
        if($StrTdp=="CONTADO" || $StrTdp=="CREDITO"){
            echo " readonly=\"readonly\" ";
        }
        ?>
        onfocus="selecciona_value(this);" 
        value="<?php echo $StrOpe;?>"/>
        </td> 
        
        <td  width="50%">
        <label >PAGAR CON</label>        
        <input type="text" name="TxtPagarCon" id="TxtPagarCon" class="form-control lt" 
        onkeyup="VUELTO();" onKeyDown="return fFOCO(event,'P'); "
        value="<?php echo $StrPagarCon;?>" 
        <?php
        if($StrTdp!="CONTADO"){
            echo "readonly=\"readonly\"";
        }
        ?>
        />
        </td>  
        
        </tr>
        </table> 
        </div> 
        
    	<div class="form-group col-sm-6" style="margin:0 0 0 0; padding: 0 0 0 0;">
        <table style="margin:0 0 0 0; padding: 0 0 0 0; ">
        <tr>

        
        <td  width="60%">
        <label >MONEDA</label>        
        <select name="CboMon" id="CboMon" class="form-control lt"  
        onchange="VUELTO();" onkeydown="return fFOCO(event,'M'); "
        <?php
        if($StrTdp!="CONTADO"){
        echo "disabled=\"disabled\"";
        }
        
        ?>
        >        
        <?php
        if($StrTdp!="CONTADO" ){
        $StrMon="SOLES";
        }
        $s="SELECT mon_nombre FROM monedas WHERE id_moneda<>'X' ORDER BY mon_nombre DESC";
        $result = grs($s);
        while ($row = $result->fetch_row()){
        if($StrMon==$row[0]){
        echo "<option value=\"$row[0]\" selected=\"selected\">$row[0]</option>";
        }else{
        echo "<option value=\"$row[0]\" >$row[0]</option>";
        }
        }
        ?>
        </select>
        </td>
        
        <td  width="40%">
        <label >VUELTO S/.</label>        
        <input type="text" name="TxtVuelto" id="TxtVuelto"  
        class="form-control rod"
        value="<?php echo $StrVuelto;?>"/>
        </td>     
        </tr>
        </table> 
        </div>          
	</div>
<div class="form-row d-flex justify-content-start" style="text-align:left; margin-left:15px; margin-right:15px">    
<div class="form-group col-sm-12"  >



<script>
function js_imprimir(){
	var id=gv("TxtId");
	if(jVal(id)==0){
		alert("No se puede determinar el id del registro activo");
		return;
	}
	document.getElementById("LnkPrint").href="ventas_print.php?ID="+id;
	document.getElementById("LnkPrint").click();
}
</script>
<a href="ventas_print.php" target="_blank" style="display:none" id="LnkPrint"></a>
<input name="CmdB" type="button" id="CmdPrint" class="btn btn-primary cmd"
value="Imprimir" onClick="js_imprimir()"
<?php
if(strlen($StrId)==0){
	echo " disabled=\"disabled\" ";
}else{
	$StrAnu=gs("anu","ventas","id_venta=$StrId");
	if($StrAnu=="S"){
		echo " disabled=\"disabled\" ";
	}
}
?>
tabindex="<?php echo ++$TI;?>"/>

<input name="CmdB" type="button" id="CmdE" class="btn btn-primary cmd"
value="Env.por.Email" onClick="fEnviarPDF();" style="display:none"
<?php
if(strlen($StrId)==0){
echo "disabled=\"disabled\"";
}else{
$StrAnu=gs("anu","cotizaciones","id_cotizacion=$StrId");
if($StrAnu=="S"){
    echo " disabled=\"disabled\"";
}
}
?>
tabindex="<?php echo ++$TI;?>"/>

<a href="ventas_vista_previa.php" target="_blank" style="display:none" id="LnkVP"></a>
<input name="CmdB" type="button" id="CmdVP" class="btn btn-primary cmd"
value="Vista previa" onClick="vista_previa()"
tabindex="<?php echo ++$TI;?>"/>


</div>
</div>
<!--INI_OCULTOS-------------------------------->
<?php include("ocultos.php");?>
<div >
<input name="TxtHora" type="hidden" id="TxtHora" value="0" />
<input name="VEN_TR" type="hidden" id="VEN_TR" value="<?php echo $VEN_TR;?>" />
<input name="TxtHoraC" type="hidden" id="TxtHoraC" value="0" />
<input name="TxtRuc_" type="hidden" id="TxtRuc_"  />        
<input name="TxtIdCliente" type="hidden" id="TxtIdCliente" value="<?php echo $StrIdCliente; ?>"   />        
<input name="TxtHW" type="hidden" id="TxtHW" value="<?php echo $StrHWND_V;?>"/>
<input name="PRO_ID" type="hidden" value="" id="PRO_ID">
<input name="FBan" type="hidden" id="FBan" onClick="fBancos();" />
</div>

<div id="DivDatosProd">
<input name="Pro_TxtId" type="hidden" id="Pro_TxtId" value=""/>
<input name="Pro_TxtDes" type="hidden" id="Pro_TxtDes" value=""/>
<input name="Pro_TxtPre" type="hidden" id="Pro_TxtPre" value=""/>
<input name="Pro_TxtPreM" type="hidden" id="Pro_TxtPreM" value=""/>
<input name="Pro_TxtCod" type="hidden" id="Pro_TxtCod" value=""/>
<input name="Pro_TxtMarca" type="hidden" id="Pro_TxtMarca" value=""/>
<input name="TXT_PXU" id="TXT_PXU" type="hidden" value="" />
<input name="TXT_PXC" id="TXT_PXC" type="hidden" value="" />
<input name="TXT_PXM" id="TXT_PXM" type="hidden" value="" />
</div>
<!--FIN_OCULTOS-------------------------------->


<input type="button" name="CmdUP" id="CmdUP" value="UP" 
onclick="fLoad();" 
style="left: 0px; top: 121px; width: 49px; visibility: hidden"
tabindex="3" />


<?php
if(strlen($StrId)>0){
	$StrCan=gs("ven_cancelado","ventas","id_venta=$StrId");
	if($StrCan=="S"){
		$StrIdCob=gn("cv_id_cobro","cobros_ventas","cv_id_venta=$StrId");
$s="<div 
style=\"position:absolute; left: 16px; top: 115px; width: 410px; ".
"background-color: #FFCC00; ".
"layer-background-color: #FFCC00; border: 1px none #000000; height: 17px;\">
<div  align=\"center\" class=\"EstA\">VENTA AL CREDITO CANCELADA 
<a target=\"_blank\" href=\"clientes_edc.php?Id=".$StrIdCob."&Pag=0\">VER COBRO</a>
</div>
</div>";
		echo $s;
	}
}
?>
<input name="TXT_OPC" type="hidden" id="TXT_OPC" value="<?php echo $POL_USU_OPC;?>">
	
</form>
</div>

</body>
</html>
