<?php

function vtas_tot()
{
require('../cfg/res.php');
require('../cfg/cfg.php');	
	
$xacceso=0;
$sql_acce='select * from usrdoc1 where docu like "FC%" and info="1" and user="'.$_SESSION['user_vcrx_id'].'" ';
$res_acce=mysql_query($sql_acce,$link_vcrx);
if (mysql_num_rows($res_acce)!=0){$xacceso=1;}
if (mb_stristr('sist.supe',$_SESSION['user_vcrx_tipo'])){$xacceso=1;}
if ($xacceso==0){echo '<font size="8" color="red"><b>';die('No tiene acceso a Informe de Ventas ' );}	

	
mysql_query("SET NAMES 'utf8'");
$fecha1 = date('Y-m-j');
$nuevafecha = strtotime ( '-1 month' , strtotime ( $fecha1 ) ) ;
$xfecha1 = date ( 'Y-m-j' , $nuevafecha );
$xfecha1= date('Y-m-'.'01');
$xfecha2= date('Y-m-d');

$xfgrou='D';	
$xforde='D';
$xfcodi='1';
	
?>

<!-- 
<script language="JavaScript" type="text/javascript" src="http://micnt.com.ec/cntapp/guia104/php/funciones/libreria.js">
</script>
 -->
<script type="text/javascript">
<?php include('../../_js/busca_maes3.js');?>
<?php include('../../_js/lista_maes3.js');?>
<?php include('../../_js/fecha_format.js');?>
<?php //include('http://micnt.com.ec/cntapp/guia104/php/funciones/libreria.js');?>


function _fecha(e,idfec)
{
//if(e.keyCode==9 || e.keyCode==13)
	if(e.keyCode==13)
	{
		var fn=document.getElementById(idfec).value;
		fn=fecha_format(fn);
		document.getElementById(idfec).value=fn;
	}
}


function vtast1d(grupox,idnumx,obj)
{
	
	
	var obj2=obj.parentNode;
	var obj3=obj2.parentNode;	
	for(i=0;i<=document.getElementsByClassName('filax').length-1;i++)
	{
		document.getElementsByClassName('filax').item(i).style.background='#fff';
	}
       obj3.style.background='#09c';

document.getElementById('vtastot2').innerHTML='Cargando...';
$.ajax({
		cache:false,
		url:'../lib/vrvtast1d.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{grupo:grupox,idnum:idnumx,fini:document.getElementById('fecha_ini').value,ffin:document.getElementById('fecha_fin').value},
    	beforeSend: function(jqXHR, textStatus)
		{
	
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
			 console.log(dato);
			 document.getElementById('vtastot2').innerHTML=dato;
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if (jqXHR.status === 0) {
              document.getElementById('vtastot2').innerHTML='Not connect: Verify Network.';
           } else if (jqXHR.status == 404) {
               document.getElementById('vtastot2').innerHTML='Requested page not found [404]';
           } else if (jqXHR.status == 500) {
               document.getElementById('vtastot2').innerHTML='Internal Server Error [500].';
           } else if (exception === 'parsererror') {
               document.getElementById('vtastot2').innerHTML='Requested JSON parse failed.';
           } else if (exception === 'timeout') {
               //console.log('Time out error.');
			   document.getElementById('vtastot2').innerHTML='Servidor no Responde';
           } else if (exception === 'abort') {
               document.getElementById('vtastot2').innerHTML='Ajax request aborted.';
           } else {
               document.getElementById('vtastot2').innerHTML='Uncaught Error: ' + jqXHR.responseText;
           }

		}, 
	    complete:function(jqXHR, textStatus)
    	{
			
			if(textStatus==='success')
	        {
 
			}           
		},
		timeout:60000
	});

}



function redireccionar(xmodi) 
{
var docu=document.getElementById('docu').value;
var enti=document.getElementById('enti').value;
var item=document.getElementById('item').value;
var ptov=document.getElementById('ptov').value;
var fzsub=document.getElementById('fzsub').value;
var flsub=document.getElementById('flsub').value;
var fcdad=document.getElementById('fcdad').value;
var frcdd=document.getElementById('frcdd').value;
var fvndd=document.getElementById('fvndd').value;
var fctlg=document.getElementById('fctlg').value;

var fecha_ini=document.getElementById('fecha_ini').value;
var fecha_fin=document.getElementById('fecha_fin').value;
fecha_ini=fecha_format(fecha_ini);
if(fecha_ini=='error'){alert('formato de fecha incorrecta'); document.getElementById('fecha_ini').focus();return false;}
fecha_fin=fecha_format(fecha_fin);
if(fecha_fin=='error'){alert('formato de fecha incorrecta'); document.getElementById('fecha_fin').focus();return false;}
var fgroud=document.getElementById('fgroud').checked;
var fgroue=document.getElementById('fgroue').checked;
var fgroui=document.getElementById('fgroui').checked;
var fgroum=document.getElementById('fgroum').checked;
var fgrous=document.getElementById('fgrous').checked;
var fgrouf=document.getElementById('fgrouf').checked;
var fgrour=document.getElementById('fgrour').checked;
var fgroup=document.getElementById('fgroup').checked;
var fgrouv=document.getElementById('fgrouv').checked;
var fgrouz=document.getElementById('fgrouz').checked;
var fgroul=document.getElementById('fgroul').checked;
var fgrouc=document.getElementById('fgrouc').checked;

var fcodis=document.getElementById('fcodis').checked;
var fcodia=document.getElementById('fcodia').checked;
var fcodie=document.getElementById('fcodie').checked;


var fordec=document.getElementById('fordec').checked;
var forded=document.getElementById('forded').checked;
var fordet=document.getElementById('fordet').checked;

var fvence=document.getElementById('xvence').checked;

var fgrou='D';
var forde='D';
var fcodi='1';

if (fcodis){fcodi='1';}
if (fcodia){fcodi='2';}
if (fcodie){fcodi='3';}
	
	
if (fgroud){fgrou='D';}
if (fgroue){fgrou='E';}
if (fgroui){fgrou='I';}
if (fgroum){fgrou='M';}
if (fgrous){fgrou='S';}
if (fgrouf){fgrou='F';}
if (fgrour){fgrou='R';}
if (fgroup){fgrou='P';}
if (fgrouv){fgrou='V';}
if (fgrouz){fgrou='Z';}
if (fgroul){fgrou='L';}
if (fgrouc){fgrou='C';}

if (fordec){forde='C';}
if (forded){forde='D';}
if (fordet){forde='T';}



// pagina="?opt=<?php echo $_GET['opt']?>" 
// +"&fecha_ini="+fecha_ini 
// +"&fecha_fin="+fecha_fin 
// +"&fgrou="+fgrou
// +"&fcodi="+fcodi
// +"&forde="+forde
// +"&docu="+docu
// +"&enti="+enti
// +"&item="+item
// +"&ptov="+ptov
// +"&fcdad="+fcdad 
// +"&fzsub="+fzsub 
// +"&flsub="+flsub 
// +"&fvndd="+fvndd
// +"&frcdd="+frcdd
// +"&fctlg="+fctlg;



		document.getElementById('vtastot1').innerHTML='Cargando datos...';
		$.ajax({
		cache:false,
		url:'vrvtast2.php',
		datatype: "text",
	    async:true,
		type:'POST',
		data:{opt:"<?php echo $_GET['opt']?>",
		fecha_ini:fecha_ini,
		fecha_fin:fecha_fin,
		fgrou:fgrou,
		fcodi:fcodi,
		forde:forde,
		docu:docu,
		enti:enti,
		item:item,
		ptov:ptov,
		fcdad:fcdad,
		fzsub:fzsub,
		flsub:flsub,
		fvndd:fvndd,
		frcdd:frcdd,
		fvence:fvence,
		fctlg:fctlg,
		xmodi:xmodi},	
    	beforeSend: function(jqXHR, textStatus)
		{
		}, 
		success:function(dato, textStatus, jqXHR)
		{
			document.getElementById('vtastot1').innerHTML=dato;
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
				if (jqXHR.status === 0) {
	              console.log('Not connect: Verify Network.');
		           } else if (jqXHR.status == 404) {
	               console.log('Requested page not found [404]');
		           } else if (jqXHR.status == 500) {
	               console.log('Internal Server Error [500].');
		           } else if (exception === 'parsererror') {
	               console.log('Requested JSON parse failed.');
		           } else if (exception === 'timeout') {
	               alert('Servidor no Responde');
		           } else if (exception === 'abort') {
	               console.log('Ajax request aborted.');
		           } else {
	               console.log('Uncaught Error: ' + jqXHR.responseText);
           			}
			
			
		   

		}, 
		complete:function(jqXHR, textStatus)
    	{
			if(textStatus==='success')
	        {
				    				    	
			}
		},
		timeout:300000
	});



//location.href=pagina;
} 



//function imprimirlista(entix,entid) 

function imprimirlista() 
{

var docu=document.getElementById('docu').value;
var enti=document.getElementById('enti').value;
var item=document.getElementById('item').value;
var ptov=document.getElementById('ptov').value;

var flsub=document.getElementById('flsub').value;
var fzsub=document.getElementById('fzsub').value;
var fcdad=document.getElementById('fcdad').value;
var frcdd=document.getElementById('frcdd').value;
var fvndd=document.getElementById('fvndd').value;
var fctlg=document.getElementById('fctlg').value;

var fvence=document.getElementById('xvence').value;
	
	
var fecha_ini=document.getElementById('fecha_ini').value;
var fecha_fin=document.getElementById('fecha_fin').value;

fecha_ini=fecha_format(fecha_ini);
if(fecha_ini=='error'){alert('formato de fecha incorrecta'); document.getElementById('fecha_ini').focus();return false;}
fecha_fin=fecha_format(fecha_fin);
if(fecha_fin=='error'){alert('formato de fecha incorrecta'); document.getElementById('fecha_fin').focus();return false;}


var fgroud=document.getElementById('fgroud').checked;
var fgroue=document.getElementById('fgroue').checked;
var fgroui=document.getElementById('fgroui').checked;
var fgroum=document.getElementById('fgroum').checked;
var fgrous=document.getElementById('fgrous').checked;
var fgrouf=document.getElementById('fgrouf').checked;
var fgrour=document.getElementById('fgrour').checked;
var fgroup=document.getElementById('fgroup').checked;
var fgrouv=document.getElementById('fgrouv').checked;
var fgrouz=document.getElementById('fgrouz').checked;
var fgroul=document.getElementById('fgroul').checked;
var fgrouc=document.getElementById('fgrouc').checked;

var fordec=document.getElementById('fordec').checked;
var forded=document.getElementById('forded').checked;
var fordet=document.getElementById('fordet').checked;

var fcodis=document.getElementById('fcodis').checked;
var fcodia=document.getElementById('fcodia').checked;
var fcodie=document.getElementById('fcodie').checked;

var fgrou='D';
var forde='D';
var fcodi='1';

if (fcodis){fcodi='1';}
if (fcodia){fcodi='2';}
if (fcodie){fcodi='3';}


if (fgroud){fgrou='D';}
if (fgroue){fgrou='E';}
if (fgroui){fgrou='I';}
if (fgroum){fgrou='M';}
if (fgrous){fgrou='S';}
if (fgrouf){fgrou='F';}
if (fgroup){fgrou='P';}
if (fgrouv){fgrou='V';}
if (fgrour){fgrou='R';}
if (fgrouz){fgrou='Z';}
if (fgroul){fgrou='L';}
if (fgrouc){fgrou='C';}

if (fordec){forde='C';}
if (forded){forde='D';}
if (fordet){forde='T';}



pagina="../lib/impr_vtast0.php?"
+"&fecha_ini="+fecha_ini 
+"&fecha_fin="+fecha_fin 
+"&fgrou="+fgrou
+"&fcodi="+fcodi
+"&forde="+forde
+"&fdocu="+docu
+"&fenti="+enti
+"&fitem="+item
+"&fptov="+ptov
+"&fcdad="+fcdad 
+"&fzsub="+fzsub 
+"&flsub="+flsub 
+"&fvndd="+fvndd
+"&frcdd="+frcdd
+"&fvence="+fvence
+"&fctlg="+fctlg;


window.open(pagina);
} 


function _enti(e)
{
// 	if(e.keyCode==9 || e.keyCode==13)
	if(e.keyCode==13)
	{
		busca_maes2('enti',document.getElementById('enti').value,'enti','descri','');
	}
}

function _item(e)
{
// 	if(e.keyCode==9 || e.keyCode==13)
	if(e.keyCode==13)
	{
			busca_maes2('item',document.getElementById('item').value,'item','descri','');
	}
}

function _modi1(idnum)
{
	var plazo=document.getElementById('plazo_'+idnum).value;
	var atrz=document.getElementById('atrz_'+idnum).value;

	$.ajax({
		cache:false,
		url:'vrmvtas1.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{
				idnum:idnum,
				atrz:atrz,
				plazo:plazo
			}, 
    	beforeSend: function(jqXHR, textStatus)
		{}, 
		success:function(dato, textStatus, jqXHR)
		{
			document.getElementById('error_'+idnum).innerHTML=dato;
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if (jqXHR.status === 0) {console.log('Not connect: Verify Network.');}
						else if (jqXHR.status == 404) {console.log('Requested page not found [404]');}
						else if (jqXHR.status == 500) {console.log('Internal Server Error [500].');}
						else if (exception === 'parsererror') {console.log('Requested JSON parse failed.');}
						else if (exception === 'timeout') {alert('Servidor no Responde');}
						else if (exception === 'abort') {console.log('Ajax request aborted.');}
						else {console.log('Uncaught Error: ' + jqXHR.responseText);}

		}, 
	    complete:function(jqXHR, textStatus)
    	{
			if(textStatus==='success'){}           
		},
		timeout:30000
	});

	
}
	
	
	
	
	
</script>


<div style=" max-height:200px; overflow-y:scroll; margin-top:5px;">





<table id="tabla_filtros" width="100%" border="0" cellspacing="0" cellpadding="2" style="border-collapse:collapse;font-size:12px; border:#000000 solid 1px;">
<tr align="left" valign="top">

<th>
<table><caption>FECHAS</caption>	
	<tr>
		<?php $pcaption='inicial';  $pidtxt='fecha_ini'; $pdefa=$xfecha1; $pobj=3; include('vrgetfec.php'); ?>
</tr>
	<tr>
		<?php $pcaption='final';  $pidtxt='fecha_fin'; $pdefa=$xfecha2; $pobj=3; include('vrgetfec.php'); ?>
</tr>


<tr style="<?php if($empr_codigo=='jore') {echo 'display:block;';}else{echo 'display:none;';} ?>">
	<td>
	</td>
	<td>
		<?php $pcaption='X Vencimiento';  $pidtxt='xvence';  include('vrchkbox.php'); ?>
	</td>
</tr>

</table>
	
<!-- <div align="center">
FECHAS
</div>
<div align="right">
<span>Inicial</span> <input type="text" id="fecha_ini" placeholder="aaaa-mm-dd" size="6" onkeydown="_fecha(event,'fecha_ini');" value="<?php echo $xfecha1;?>" /> 
</div>
<div align="right">
<span>Final</span> <input type="text" id="fecha_fin" placeholder="aaaa-mm-dd" size="6" onkeydown="_fecha(event,'fecha_fin');" value="<?php echo $xfecha2;?>" /> 
</div> -->
</th>



<th style ="border-left:solid 1px;">
<div align="center">
<span>AGRUPADO X</span>
</div>
</th>

<th>	
<input type="radio" id="fgroud" name="fgroup" <?php if($xfgrou=='D'){echo 'checked';}?>/><span>Documento</span> <br/>
<input type="radio" id="fgroup" name="fgroup" <?php if($xfgrou=='P'){echo 'checked';}?>/><span>PtoEmision</span> <br/>
<input type="radio" id="fgrouc" name="fgroup" <?php if($xfgrou=='C'){echo 'checked';}?>/><span>Comp.Elect.</span> <br/>
</th>

<th>
<input type="radio" id="fgrouz" name="fgroup" <?php if($xfgrou=='Z'){echo 'checked';}?>/><span>Zonas</span> <br/>
<input type="radio" id="fgroue" name="fgroup" <?php if($xfgrou=='E'){echo 'checked';}?>/><span>Cliente</span> <br/>
</th>

<th>
<input type="radio" id="fgroul" name="fgroup" <?php if($xfgrou=='L'){echo 'checked';}?>/><span>Lineas</span> <br/>
<input type="radio" id="fgroui" name="fgroup" <?php if($xfgrou=='I'){echo 'checked';}?>/><span>Item</span> <br/>
<input type="radio" id="fgrour" name="fgroup" <?php if($xfgrou=='R'){echo 'checked';}?>/><span>Cod.Ret.</span> <br/>
</th>

<th>
<input type="radio" id="fgrouv" name="fgroup" <?php if($xfgrou=='V'){echo 'checked';}?>/><span>Vendedor</span> <br/>
<input type="radio" id="fgrouc" name="fgroup" <?php if($xfgrou=='C'){echo 'checked';}?>/><span>Ciudad</span> <br/>
</th>
	
<th>
<div>
<input type="radio" id="fgroum" name="fgroup" <?php if($xfgrou=='M'){echo 'checked';}?>/><span>Mensual</span> <br/>
<input type="radio" id="fgrous" name="fgroup" <?php if($xfgrou=='S'){echo 'checked';}?>/><span>Semanal</span> <br/>
<input type="radio" id="fgrouf" name="fgroup" <?php if($xfgrou=='F'){echo 'checked';}?>/><span>Diario</span> <br/>
</div>
</th>

<th style ="border-left:solid 1px;">
<div align="center">
<span>ORDENADO X</span>
</div>
<div>
		<?php $pname="forder"; $pidtxt='forded'; $pcaption='Nombre'; if($xforde=='D'){$pdefa='checked';}; include('vrradio.php'); ?>	
		<?php $pname="forder"; $pidtxt='fordec'; $pcaption='Codigo'; if($xforde=='C'){$pdefa='checked';}; include('vrradio.php'); ?>	
		<?php $pname="forder"; $pidtxt='fordet'; $pcaption='Totales'; if($xforde=='T'){$pdefa='checked';}; include('vrradio.php'); ?>	
</div>
</th>

<th style ="border-left:solid 1px;">
<div align="center">
<span>CODIGOS</span>
</div>
<div>
<!-- <input type="radio" id="fcodis" name="tcodi" <?php if($xfcodi=='1'){echo 'checked';}?>/><span>Sistema</span> <br/>
<input type="radio" id="fcodia" name="tcodi" <?php if($xfcodi=='2'){echo 'checked';}?>/><span>Auxiliar</span> <br/>
<input type="radio" id="fcodie" name="tcodi" <?php if($xfcodi=='3'){echo 'checked';}?>/><span>EAN (Barras)</span> <br/> -->
						<?php $pname="tcodi"; $pidtxt='fcodis'; $pcaption='Sistema'; if($xfcodi=='1'){$pdefa='checked';}; include('vrradio.php'); ?>	
						<?php $pname="tcodi"; $pidtxt='fcodia'; $pcaption='Auxiliar'; if($xfcodi=='2'){$pdefa='checked';}; include('vrradio.php'); ?>	
						<?php $pname="tcodi"; $pidtxt='fcodie'; $pcaption='EAN(Barras)'; if($xfcodi=='3'){$pdefa='checked';}; include('vrradio.php'); ?>	

</div>
</th>

<th align="center" style ="border-left:solid 1px;">
<?php $pcaption='Consultar';  $ponclick="redireccionar();" ;include('vrbutton.php'); ?>
<br>
<?php $pcaption='Imprimir';  $ponclick="imprimirlista();" ;include('vrbutton.php'); ?>
</th>

	</tr>
	</table>
<table id="tabla_filtros2" width="100%" border="0" cellspacing="0" cellpadding="2" style="border-collapse:collapse;font-size:12px; border:#000000 solid 1px;">
<tr>
<th>FILTROS</th>
<th style ="border-left:solid 1px;">
<table>
	<tr>
		<?php $pcaption='Docu';  $ptabla='docu'; $pidtxt='docu'; $pdefa=$xfdocu; $pnotob=1; include('vrgetcod.php'); ?>
	</tr>
	<tr>
		<?php $pcaption='Pto.Vta.';  $ptabla='ptov'; $pidtxt='ptov'; $pdefa=$xfptov; $pnotob=1; include('vrgetcod.php'); ?>
	</tr>
</table>	
</th>
<th style ="border-left:solid 1px;">
<table>
	<tr>
		<?php $pcaption='Zona';  $ptabla='zsub'; $pidtxt='fzsub'; $pdefa=$xfzsub; $pnotob=1; include('vrgetcod.php'); ?>
	</tr>
	<tr>
		<?php $pcaption='Cliente';  $ptabla='enti'; $pidtxt='enti'; $pdefa=$xfenti; $pnotob=1; include('vrgetcod.php'); ?>
	</tr>
</table>	

	
</div>
</th>

<th>
<div>
<!--     <div align="right">
	    <span>Documento</span> 
	    <input type="text" id="docu" placeholder="docu" size="10" value="<?php echo $xfdocu;?>" /> 
        <span id="docu_descri" style="font-weight:bold; height:25px; display:none;"></span>
	</div>
    <div align="right">
	    <span>Pto.Vta.</span> 
	    <input type="text" id="ptov" placeholder="ptov" size="10" value="<?php echo $xfptov;?>" /> 
	</div>
 -->
<!-- 
    	<div align="right">
	    <span>Zona</span> 
	    <input type="text" id="fzsub" placeholder="zona" size="10" value="<?php echo $xfzsub;?>" /> 
	</div>
    	<div align="right">
	    <span>Linea</span> 
	    <input type="text" id="flsub" placeholder="linea" size="10" value="<?php echo $xflsub;?>" />  -->
	</div>
</div>
</th>

<th style ="border-left:solid 1px;">
<table>
	<tr>
		<?php $pcaption='Linea';  $ptabla='lsub'; $pidtxt='flsub'; $pdefa=$xflsub; $pnotob=1; include('vrgetcod.php'); ?>
	</tr>
	<tr>
		<?php $pcaption='Item';  $ptabla='item'; $pidtxt='item'; $pdefa=$xfitem; $pnotob=1; include('vrgetcod.php'); ?>
	</tr>
</table>
</th>

<th style ="border-left:solid 1px;">
<table>
	<tr>
		<?php $pcaption='Ciudad';  $ptabla='cdad'; $pidtxt='fcdad'; $pdefa=$xfcdad; $pnotob=1; include('vrgetcod.php'); ?>
	</tr>
	<tr>
		<?php $pcaption='Vendedor';  $ptabla='vndd'; $pidtxt='fvndd'; $pdefa=$xfvndd; $pnotob=1; include('vrgetcod.php'); ?>
	</tr>
</table>
</th>

<th style ="border-left:solid 1px;">
<table>
	<tr>
		<?php $pcaption='Recaudador';  $ptabla='rcdd'; $pidtxt='frcdd'; $pdefa=$xfrcdd; $pnotob=1; include('vrgetcod.php'); ?>
	</tr>
	<tr>
		<?php $pcaption='Catalogo';   $pidtxt='fctlg'; $pdefa=$xfenti; $plong=4; include('vrgettxt.php'); ?>
	</tr>
</table>
</th>

<th align="center" style ="border-left:none 1px;">
<?php $pcaption='Modif.Cab.';  $ponclick="redireccionar('1');" ; include('vrbutton.php'); ?>
	<br>
<?php //$pcaption='Modif.Det.';  $ponclick="redireccionar('2');" ;include('vrbutton.php'); ?>
</th>


</tr>
</table>
</div>

<hr/>


<div id="vtastot1" style="overflow-y:scroll; height:300px;"></div>

<br>
<div id="vtastot2"></div>

<?php		
// $xwidth=40;	
require('lista_car.php');
?>	
<!-- 
<div id="lista_temporal_contenedor" style=" display:none; padding:0px; margin:0px; background: #666; opacity:0.5; width:100%; min-height: 100%; height:auto !important;position: fixed;top:0;left:0; z-index:1;" ></div>
<div id="lista_cargador" style=" display:none; background:#FFF;position: fixed; top:50px;z-index:10;" ><img src="../img/ajax-loader.gif" /></div>    
<div id="lista_temporal" style=" display:none; background:#FFF;position: fixed; top:50px;z-index:10; overflow-y:scroll; min-height:50px; max-height:400px; width:100%;" ><img src="../img/ajax-loader.gif" /></div>    
 -->



<?php }?>