<?php
session_start();
include("../cls_conexion.php");$CNN=new ClsMySQL();include("../conexion23.php");
///////////////////////////////////////////////////////+++
if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("../login.php");	return;}
///////////////////////////////////////////////////////++
$HW=$_SESSION['SYS_HW'];
$StrGT="";$LStrMsg="";$LStrFoc="";$LStrMM="";
$LStrPag=V($_POST['TxtPag']);
//++++++
$HOR_ID=0;
include("ventas_autogenerar_fun.php");
//++++++
$VP_RegXPag=6;
$LStrTR=gn("count(*)","vis_ventas_lotes","ID>0");
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);	
$TI=0;
?>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Autogenerar ventas</title>
<!--INI_SCRIPT------------------------------------------------------------------------------>
<?php AddJs(); ?>
<script type="text/javascript" src="e3/funciones.js"></script>
<script type="text/javascript" src="e3/ventas_autogenerar.js"></script>
<!--FIN_SCRIPT------------------------------------->
<link rel="stylesheet" type="text/css" href="e2/estiloss.css"  />
<link rel="stylesheet" type="text/css" href="e2/basic.css"  />
<style type="text/css">
.cF {height:600px;width:1000px;position:relative;top:0px}
</style>
<script>
$(document).ready(function(){  
   Inicializar();
});
</script>
</head>

<body  <?php echo $LStrMsg;?>  >
<div align="center">

<div Id="DivFRM"  class="cF" style="background-color:#FFFFFF;" >
<form id="Frm" name="Frm" method="post" action="ventas_autogenerar.php" autocomplete="off" >
<!--INI_TITULO-->
<div id="DivT" class="dT" >
<img src="../png/vi_ventas_internas.png" class="iT" />
<div class="tT">AUTOGENERAR VENTAS</div>
</div>
<!--FIN_TITULO-->

<?php if(strlen($Cod)==0)$Cod="***";?>
<div class="s10" style="left:35px; top: 122px; width: 50px; height: 18px;"> CODIGO
</div>
<input name="Cod"  type="text" 
class="roi"  id="Cod" style="left:35px; top: 139px; width: 53px;"
tabindex="<?php echo ++$TI;?>"
value="<?php echo $Cod;?>"  />


<div class="s10" style="left:99px; top:122px; width: 85px; height: 18px;">
EMPRESA</div>
<select name="Emp" id="Emp"  onChange="SM('SEL_EMP')"
class="lt" style="left:99px; top:139px; width: 80px;"
tabindex="<?php echo ++$TI;?>">
<?php
echo FCBO("emp_nomc","empresas","id_emp>0",$Emp,"N","S");
?>
</select>

<div class="s10" style="left:192px; top:122px; width: 98px; height: 18px;"> TIENDA
</div>
<select name="Tie" id="Tie" 
class="lt" style="left:191px; top:139px; width: 100px;"
tabindex="<?php echo ++$TI;?>">
<?php
echo FCBO("ANC","vis_almacenes","IDA>0 AND ENC='$Emp'",$Tie,"N","S");
?>
</select>


<div class="s10" style="left:303px; top:122px; width: 85px; height: 18px;">
COMPROBANTE</div>
<select name="Com" id="Com" 
class="lt" style="left:303px; top:139px; width: 86px;"
tabindex="<?php echo ++$TI;?>">
<?php
echo FCBO_("com_nombre","comprobantes",
		   "id_comprobante>0 AND com_nombre IN ('FACT. ELEC.','BOL. ELEC.')",$Com,"N","S");
?>
</select>

<div class="s10" style="left:398px; top: 122px; width: 50px; height: 18px;">
SERIE</div>
<input name="Ser"  type="text" 
class="nei"  id="Ser" style="left:396px; top: 139px; width: 50px;"
tabindex="<?php echo ++$TI;?>" maxlength="4"
value="<?php echo $Ser;?>"  />

<?php if(strlen($Fec)==0)$Fec=date("d-m-y");?>
<div class="s10" style="left:456px; top: 122px; width: 65px; height: 18px;"> FECHA
</div>
<input name="Fec"  type="text" 
class="fe tcal"  id="Fec" style="left:455px; top: 139px; width: 70px;"
tabindex="<?php echo ++$TI;?>"
value="<?php echo $Fec;?>"  />

<div class="s10" style="left:535px; top: 105px; width: 82px; height: 35px;"> TOTAL MONTO A GENERAR</div>
<input name="Tot"  type="text" 
class="ndd"  id="Tot" style="left:535px; top: 138px; width: 65px;"
tabindex="<?php echo ++$TI;?>"
value="<?php echo $Tot;?>"  />

<div class="s10" style="left:631px; top: 105px; width: 133px; height: 18px;">
MONTOS A GENERAR</div>

<div class="s10" style="left:610px; top: 122px; width: 49px; height: 18px;"> MINIMO</div>
<input name="Min"  type="text" 
class="ndd"  id="Min" style="left:610px; top: 139px; width: 69px;"
tabindex="<?php echo ++$TI;?>"
value="<?php echo $Min?>"  />

<div class="s10" style="left:689px; top: 122px; width: 49px; height: 18px;"> MAXIMO</div>
<input name="Max"  type="text" 
class="ndd"  id="Max" style="left:689px; top: 139px; width: 69px;"
tabindex="<?php echo ++$TI;?>"
value="<?php echo $Max;?>"  />

<div class="s10" style="left:769px; top:122px; width: 108px; height: 18px;"> TIPO DE CLIENTE
</div>
<select name="Tdc" id="Tdc" 
class="lt" style="left:769px; top:139px; width: 94px;"
tabindex="<?php echo ++$TI;?>">
<?php
echo FCBO("aux_des","auxiliares","aux_tip='RND_CLI'",$Tdc,"N","S");
?>
</select>

<div class="s10" style="left:872px; top: 122px; width: 106px; height: 18px;"> DNI / RUC</div>
<input name="Ndi"  type="text" 
class="nei"  id="Ndi" style="left:872px; top: 139px; width: 93px;"
tabindex="<?php echo ++$TI;?>"
value="<?php echo $Ndi;?>"  />

<script>
function fCalVen(){
	var cod=gv("TxtId");
	if(jVal(cod)==0){
		alert("No se puede determinar el id del registro activo");
		return;
	}
	Ow("../ventas_generar_funciones.php?ACC=PASO_01&COD="+cod,600,300);
}
function fGenVen(){
	var cod=gv("TxtId");
	if(jVal(cod)==0){
		alert("No se puede determinar el id del registro activo");
		return;
	}
	Ow("../ventas_generar_funciones.php?ACC=PASO_02&COD="+cod,600,300);
}
function fGenCE(){
	var cod=gv("TxtId");
	if(jVal(cod)==0){
		alert("No se puede determinar el id del registro activo");
		return;
	}
	Ow("../ventas_generar_funciones.php?ACC=PASO_03&COD="+cod,600,300);
}
function fVerEstado(){
	var cod=gv("TxtId");
	if(jVal(cod)==0){
		alert("No se puede determinar el id del registro activo");
		return;
	}
	Ow("ventas_resumen.php?ACC=PASO_03&COD="+cod,450,600);
	
}
</script>
<input name="CmdCalVen" id="CmdCalVen" type="button" 
onClick="fCalVen();" value="Paso 01 - Calcular ventas"
style="position:absolute; left:35px; top:192px; width: 181px;">

<input name="CmdGenVen" id="CmdGenVen" type="button" 
onClick="fGenVen();" value="Paso 02 - Generar ventas"
style="position:absolute; left:227px; top:192px; width: 165px;">

<input name="CmdGenCE" id="CmdGenCE" type="button" 
onClick="fGenCE();" value="Paso 03 - Generar comprobante electronico"
style="position:absolute; left:401px; top:192px; width: 280px;">

<input name="CmdResumen" id="CmdResumen" type="button" 
onClick="fVerEstado();" value="Ver estado / avance"
style="position:absolute; left:693px; top:192px; width: 274px;">

<!--INI_BOTONES----->
<?php 
	//$BUSCAR="ventas_autogenerar_b.php";
	$F_N="flNuevo()";
?>
<?php include("botones.php");?>;
<!--FIN_BOTONES-->
<!--INI_TABLA----->
<div class="datagrid" 
style="position:absolute; left: 35px; top: 231px; width: 931px; height: 337px;">
<table width="75%">
<thead>
<tr>
<td colspan="10" height="18" align="center">
<?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?></td>
</tr>
<tr>
<th width="7%">CODIGO</th>
<th width="15%">EMPRESA</th>
<th width="12%">TIENDA</th>
<th width="35%">COMPROBANTE</th>
<th width="11%">SERIE</th>
<th width="9%">FECHA</th>
<th width="8%">T.GENERAR</th>
<th width="3%">&nbsp;</th>
</tr>
</thead>
<tbody>
<?php
$s="SELECT * FROM vis_ventas_lotes WHERE ID>0 ORDER BY ID DESC ";
$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);	  				
$rs=grs($s);
while($r=$rs->fetch_assoc()){
?>
	<tr onDblClick="fActivar(<?php echo $r['ID'];?>);">
	<!----------------------------------------------->
    <td ><?php echo $r['NRO'];?></td>
	<td ><?php echo $r['EMP_NC'];?></td>
    <td ><?php echo $r['TIE_NC'];?></td>
    <td ><?php echo $r['COM'];?></td>
    <td ><?php echo $r['SER'];?></td>
    <td ><?php echo $r['FEC_'];?></td>
    <td ><?php echo $r['TOT_A_GEN'];?></td>
	<!----------------------------------------------->
	<td bgcolor="#FFFFFF" align="center">
	<a href="javascript:void(0)" onClick="fActivar(<?php echo $r['ID'];?>);">
	<img src="../img/b_edit.png"  border="0"/></a></td>
	</tr>
<?php
}
?>
</tbody>
</table>
</div>

<!--FIN_TABLA----->
<!--INI_OCULTOS-------------------------------->
<?php include("ocultos.php");?>
<!--FIN_OCULTOS-------------------------------->
</form>
</div>
</div>
</body>
</html>
