<?php
session_start();
include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
//if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("login.php");	return;}
$StrId=V($_POST['TxtId']);
$StrCmd=V($_POST['TxtAc']);
$StrHW=$_SESSION['SYS_HW'];
//-------------------------
$_CLI=V($_GET['C']);
$_MON=V($_GET['M']);
if(strlen($_CLI)==0){
	$_CLI=V($_POST['TxtCLI']);
	$_MON=V($_POST['TxtMON']);
}
//-------------------------
$StrCom=V($_POST['CboCom']);		
$StrSer=V($_POST['TxtSer']);		
$StrNum=V($_POST['TxtNum']);		
$StrDex=V($_POST['TxtDex']);		
$StrHax=V($_POST['TxtHax']);			
$StrDATA=V($_POST['TxtDAT']);
//
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($StrCmd=="OK" || $StrCmd=="ADD"){
	if($StrCmd=="OK"){
		ejt("DELETE FROM cobros_ventas_t WHERE hw='$StrHW'");
	}
	$DAT = explode(',',$StrDATA);
	$i=0;
	for($i=0;$i<count($DAT);$i++){
		$StrIdVenta=$DAT[$i];
		$cx=GenId("item","cobros_ventas_t");
		$s="INSERT INTO cobros_ventas_t ".
		   "VALUES ('$StrHW',$cx,$StrIdVenta)";
		ejt($s);
	}
	$StrMsg="onload=\"window.opener.document.Frm.CmdLoad.click();window.close();\"";
	
}else{
	$FF="ID>0 AND COM LIKE '$StrCom_' AND ".
	"NUM LIKE '$StrNum_' AND SER LIKE '$StrSer_' AND ".
	"FEC >= '$StrDex_' AND FEC <= '$StrHax_' AND ".
	"ID_CLI=$_CLI AND MON='".substr($_MON,0,1)."' AND ".
	"TDP='CR' AND ANU='N'";
	//-------------------------
	$LStrTR=gn("count(*)","vventas",$FF);
	$LStrPag=V($_POST['TxtPag']);
	if($StrCmd=="F"){$LStrPag="1";}
	$VP_RegXPag=10000;	
	$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);
}
?>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ventas - Buscar</title>
<!----------------------------------------->
<?php AddJs(); ?>
<script type="text/javascript" src="ja/funciones.js"></script>

<!----------------------------------------->
<link rel="stylesheet" type="text/css" href="css/estiloss.css"  />
<link rel="stylesheet" type="text/css" href="css/basic.css"  />
<!----------------------------------------->
<style type="text/css">
.cF {height:580px;width:580px;position:relative;top:0px}
</style>

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

function SelTodos(){
	frm = document.getElementById("Frm");
	if (!frm) return;
	for(i=0; i<frm.elements.length; i++)
	{
		if (frm.elements[i].type == "checkbox")	frm.elements[i].checked=true;
	}
}
function Verificar(){
	var DATA="";
	document.getElementById("TxtDAT").value="";
	frm = document.getElementById("Frm");
	if (!frm) return;
	for(i=0; i<frm.elements.length; i++)
	{
		if (frm.elements[i].type == "checkbox")	{
			if(frm.elements[i].checked==true){
				var ok=frm.elements[i].name;
				ok=ok.substring(2,7);
				DATA=DATA+ok+",";
			}
		}
	}	
	if(jLen(DATA)==0){
		alert("Ningun registro seleccionado, seleccione un registro marcando el check correspondiente");
		return 0;
	}else{
		document.getElementById("TxtDAT").value=DATA;
		return 1;
	}
}
function Aceptar(){
	if(Verificar()==1){		
		document.getElementById("TxtAc").value="OK";
		document.getElementById("Frm").submit();	
	}
}
function Agregar(){
	if(Verificar()==1){		
		document.getElementById("TxtAc").value="ADD";
		document.getElementById("Frm").submit();	
	}
}
</script>
<!----------------------------------------->

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


<div Id="DivFRM"  class="cF" style="background-color:#FFFFFF;" >
<form id="Frm" name="Frm" method="post" action="clientes_edc_sel_ventas.php">

<!----------------------------------------->
<div id="DivT" class="dT"  style="width:580px;">
<img src="b.png" class="iT" />
<div class="tT" style="width: 448px;">SELECCIONAR VENTAS AL CREDITO POR CANCELAR</div>
</div>
<!----------------------------------------->

<div class="s1" style="left: 23px; top: 78px; width: 102px;">
COMPROBANTE</div>
<select name="CboCom" id="CboCom" 
class="lt" style="left: 23px; top: 101px; width: 107px;"
tabindex="<?php echo ++$TI;?>">
<?php echo FCBO_("com_nombre","comprobantes","id_comprobante>0",$StrCom,"S","N");?>
</select>

<div class="s1" style="left: 134px; top: 78px; width: 46px;">
SERIE</div>
<input name="TxtSer" type="text" id="TxtSer" 
class="lt" style="left: 134px; top: 101px; width: 47px;"
value="<?php echo $StrSer;?>"  
tabindex="<?php echo ++$TI;?>"/>

<div class="s1" style="left: 186px; top: 78px; width: 64px;">
NUMERO</div>
<input name="TxtNum" type="text" id="TxtNum" 
class="lt" style="left: 187px; top: 101px; width: 63px;"
value="<?php echo $StrNum;?>"  
tabindex="<?php echo ++$TI;?>"/>

<div class="s1" style="left: 258px; top: 78px; width: 55px;">
DESDE</div>
<input name="TxtDex" type="text" id="TxtDex" 
class="lt" style="left: 258px; top: 101px; width: 62px;"
value="<?php echo $StrDex;?>"  
tabindex="<?php echo ++$TI;?>"/>

<div class="s1" style="left: 328px; top: 78px; width: 60px;">
HASTA</div>
<input name="TxtHax" type="text" id="TxtHax" 
class="lt" style="left: 327px; top: 101px; width: 67px;"
value="<?php echo $StrHax;?>"  
tabindex="<?php echo ++$TI;?>"/>

<input name="CmdB" type="button" 
style="position: absolute; left: 401px; top: 101px; width: 83px;"
id="CmdB" value="Filtrar" onClick="fFiltrar();" 
tabindex="<?php echo ++$TI;?>"/>


<div class="datagrid" style="position: absolute; left: 23px; top: 130px; width: 530px; height: 380px; overflow: auto">
<table width="100%">
<thead>
<tr>
<td colspan="6" align="center"><?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?></td>
</tr>

<tr>
<th width="296">FECHA</th>
<th width="105">COMPROBANTE</th>
<th width="118">SERIE</th>
<th width="133">NUMERO</th>
<th width="30">TOTAL</th>
<th width="25"><label for="Ch"></label></th>
</tr>
</thead>
<tbody>

<?php		  		
$TOTAL=0;
if(strlen($FF)>0){
	$s="SELECT ID,DATE_FORMAT(FEC,'%d-%m-%y'),COM,SER,NUM,TOT ".
	"FROM vventas ".
	"WHERE ".$FF." ORDER BY FEC,ID ";
	$X1="<td bgcolor=\"#FFFFFF\"><span class=\"Estilo5\">";
	$X1B="<td bgcolor=\"#FFFFFF\" align=\"right\"><span class=\"Estilo5\">";
	$X2="</span></td>";
	$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);
	$result = grs($s);				
	while ($row = $result->fetch_row()){
		echo "<tr >";
		$StrCH=vbr("00000".$row[0],5);
		echo $X1.$StrCH.$X2;
		echo $X1.$row[2].$X2;
		echo $X1.$row[3].$X2;
		echo $X1.$row[4].$X2;
		echo $X1B.NF2($row[5],2).$X2;
		$TOTAL=$TOTAL + $row[5];
		echo "<td bgcolor=\"#FFFFFF\" align=\"center\">
		<input type=\"checkbox\" name=\"Ch".$StrCH."\" id=\"Ch".$StrCH."\" />
		</td>";
		echo "</tr>";
	}
}
?>		  
</tbody>
</table>
</div>

<!----------------------------------------->    
<?php include("ocultos.php");?>
<input name="TxtCLI" type="hidden" id="TxtCLI" value="<?php echo $_CLI;?>" />
<input name="TxtMON" type="hidden" id="TxtMON" value="<?php echo $_MON;?>" />


<input name="CmdB" type="button" 
style="position: absolute; left: 23px; top: 521px; width: 142px;"
id="CmdB" value="Seleccionar todos" onClick="SelTodos();" 
tabindex="<?php echo ++$TI;?>"/>

<input name="CmdB" type="button" 
style="position: absolute; left: 173px; top: 521px; width: 76px;"
id="CmdB" value="Aceptar" onClick="Aceptar();" 
tabindex="<?php echo ++$TI;?>"/>

<input name="CmdB" type="button" 
style="position: absolute; left: 258px; top: 521px; width: 76px;"
id="CmdB" value="Agregar" onClick="Agregar();" 
tabindex="<?php echo ++$TI;?>"/>


<div class="s1" style="left: 326px; top: 521px; width: 140px; text-align: right;">
TOTAL : <?php echo NF2($TOTAL,2);?></div>

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