<?php
function modi_doc1($docu_tipo,$docu_enti)
//function ver_doc1($docu_tipo)
{
	session_start();
		require('lista_car.php');
	
require('../cfg/res.php');	
mysql_query("SET NAMES 'utf8'");

$xacceso=0;
$sql_acce='select * from usrdoc1 where docu like "'.trim($docu_tipo).'%" and modi="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 (mb_stristr('clie',$_SESSION['user_vcrx_tipo']) and mb_stristr('OP.FC',substr($docu_tipo,1,2))){$xacceso=1;}
// if (mb_stristr('prov',$_SESSION['user_vcrx_tipo']) and mb_stristr('FP.RP',substr($docu_tipo,1,2))){$xacceso=1;}
if ($xacceso==0){echo '<font size="8" color="red"><b>';die('No tiene acceso a consultar :'.$docu_tipo );}	

$xaccesom=0;
$sql_acce='select * from usrdoc1 where docu like "'.trim($docu_tipo).'%" and modi="1" and user="'.$_SESSION['user_vcrx_id'].'" ';
$res_acce=mysql_query($sql_acce,$link_vcrx);
if (mysql_num_rows($res_acce)!=0){$xaccesom=1;}
if (mb_stristr('sist.supe',$_SESSION['user_vcrx_tipo'])){$xaccesom=1;}
		

	
	
$xcelec="FC.NC.GR.RP";
$sql_docu='select *from docu0 where docu_codigo like "'.$docu_tipo.'%"';
$res_docu=mysql_query($sql_docu,$link_vcrx);

$descri_docu='';
$tabla='';
if (mysql_num_rows($res_docu)!=0)
{
$descri_docu=mysql_result($res_docu,0,'docu_descri');
$tabla=strtolower(mysql_result($res_docu,0,'docu_tabla'));
}



if (mb_stristr('CXCO.CXPA',$docu_tipo))
{
	$tabla=strtolower($docu_tipo);
}


if (mb_stristr('clie.prov',substr($_SESSION['user_vcrx_tipo'],0,4)))
{
	if (substr($docu_tipo,0,1)=='O')
	{$tabla='clie';}
	
	if (substr($docu_tipo,0,1)=='F')
	{$tabla='vtas';}

	if (substr($docu_tipo,0,3)=='CXP')
	{$tabla='cxco';}
	
	if (substr($docu_tipo,0,3)=='CXC')
	{$tabla='cxpa';}
}


$sql_drtr='select *from drtr0 where left(enti_codigo,10) like "'.$_SESSION['user_vcrx_id'].'%"';
$res_drtr=mysql_query($sql_drtr,$link_vcrx);
$drtr=0;

if (mb_stristr('gnya.leie',substr($_SESSION['user_vcrx_empr'],0,4)))
{
	if (mysql_num_rows($res_drtr)!=0)
	{$drtr=1;}
}

if (mb_stristr('admi.supe.sist',substr($_SESSION['user_vcrx_tipo'],0,4)))
{
//$drtr=0;
}

if (mb_stristr('clie.prov',substr($_SESSION['user_vcrx_tipo'],0,4)))
{$docu_enti='M';}
//echo $drtr;

?>
<script type="text/javascript">

<?php include('../../_js/busca_maes3.js');?>
<?php include('../../_js/lista_maes3.js');?>
<?php include('../../_js/fecha_format.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 mpedido_d(indxd,tabla)
{
	for(i=0;i<=document.getElementsByClassName('pdc_t1').length-1;i++)
	{
		document.getElementsByClassName('pdc_t1').item(i).style.background='none';
		document.getElementsByName('btn_ped_c').item(i).disabled=true;
		document.getElementsByName('btn_ped_c').item(i).style.cursor='progress';
	}
	document.getElementById(indxd).style.background='#eee';
	document.getElementById('mpedido_d').innerHTML='<img src="../img/loader.gif" width="40" />';
	document.body.style.cursor='progress';
	$.ajax({
		url:'../lib/verdoc2.php',
		type:'POST',
		data:{indx:indxd,tabla:tabla},
		success: function(dato)
		{
			document.getElementById('mpedido_d').innerHTML='';
			document.getElementById('mpedido_d').innerHTML=dato;
			document.body.style.cursor='auto';
			for(i=0;i<=document.getElementsByClassName('pdc_t1').length-1;i++)
			{
				document.getElementsByName('btn_ped_c').item(i).disabled=false;
				document.getElementsByName('btn_ped_c').item(i).style.cursor='auto';
			}
		}			
	});
}


function modideta(docu,idnum,c,d)
{
	
	for(i=0;i<=document.getElementsByClassName('pdc_t1').length-1;i++)
	{
		document.getElementsByClassName('pdc_t1').item(i).style.background='none';
		document.getElementsByName('btn_ped_c').item(i).disabled=true;
		document.getElementsByName('btn_ped_c').item(i).style.cursor='progress';
	}

	document.getElementById(idnum).style.background='#eee';
	//document.getElementById('modideta').innerHTML='<img src="../img/loader.gif" width="40" />';
	//document.body.style.cursor='progress';

	$.ajax({
		cache:false,
		url:'../lib/vrnewreg10.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{docu:docu,idnumx:idnum},
    	beforeSend: function(jqXHR, textStatus)
		{
		}, 
		success:function(dato, textStatus, jqXHR)
		{
			//console.log(dato);
			//document.getElementById('mpedido_d').innerHTML='';
			document.getElementById('mpedido_d').innerHTML=dato;
			//document.body.style.cursor='auto';
			//for(i=0;i<=document.getElementsByClassName('pdc_t1').length-1;i++)
			//{
			//	document.getElementsByName('btn_ped_c').item(i).disabled=false;
			//	document.getElementsByName('btn_ped_c').item(i).style.cursor='auto';
			//}



		},
		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') {
               //console.log('Time out error.');
			   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:60000
	});
}


function status_ox(docu,id,idt,stox)
{
	if (stox=='O')
	{msgconfir='Desea Anular la Transaccion ?'}
	if (stox=='X')
	{msgconfir='Desea Eliminar la Transaccion ?'}
	
	if (confirm(msgconfir)) 
	{
                if(document.getElementById('e_pedido'))
                {
                   document.getElementById('e_pedido').disabled=false;
                }
               
                if(document.getElementById('a_pedido'))
                {
                   document.getElementById('a_pedido').disabled=false;
                }
		
		$.ajax({
			url:'../lib/vranula.php',
			type:'POST',
			data:{docu:docu,id:id,idt:idt,stox:stox},
			success: function(dato)
			{
				console.log(dato);
				window.location.reload();
				alert(dato);
			},
			error: function(objeto)
			{
				console.log(objeto);
			}
		});
		
               if(document.getElementById('e_pedido'))
                {
                   //document.getElementById('e_pedido').disabled=true;
                }
               
                if(document.getElementById('a_pedido'))
                {
                   //document.getElementById('a_pedido').disabled=true;
                }
	}
}



function status_nuevo(docu,id,idt,stox)
{
	if (stox=='-')
	{msgconfir='Desea Reactivar STATUS ?'}
	
	if (confirm(msgconfir)) 
	{
		document.getElementById('e_pedido').disabled=false;
		$.ajax({
			url:'../lib/vrstatnew.php',
			type:'POST',
			data:{docu:docu,id:id,idt:idt,stox:stox},
			success: function(dato)
			{
				console.log(dato);
				window.location.reload();
				//alert('Pedido Eliminado');
			},
			error: function(objeto)
			{
				console.log(objeto);
			}
		});
		document.getElementById('e_pedido').disabled=true;
	}
}




function redireccionar() 
{
var fstat=document.getElementById('fstat').value;

var fdocu='';
if(document.getElementById('fdocu'))
{fdocu=document.getElementById('fdocu').value;}

var fzsub='';
if(document.getElementById('fzsub'))
{fzsub=document.getElementById('fzsub').value;}

var fptov='';
if(document.getElementById('fptov'))
{ fptov=document.getElementById('fptov').value;}

var fbode='';
if(document.getElementById('fbode'))
{ fbode=document.getElementById('fbode').value;}




var fenti=document.getElementById('fenti').value;
var fdrtr=document.getElementById('fdrtr').value;
var fcontra=document.getElementById('fcontra').value;
var fecha_ini=document.getElementById('fecha_ini').value;
var fecha_fin=document.getElementById('fecha_fin').value;
var fnum1=document.getElementById('fnum1').value;
var fnum2=document.getElementById('fnum2').value;
var total_min=document.getElementById('total_min').value;
var total_max=document.getElementById('total_max').value;


//pagina="?opt=<?php echo $_GET['opt']?>&tipo=<?php echo $_GET['tipo']?>" +"&fecha_ini="+fecha_ini+"&fecha_fin="+fecha_fin;

pagina="?opt=<?php echo $_GET['opt']?>" 
+"&tipo=<?php echo $_GET['tipo']?>" 
+"&enti=<?php echo $_GET['enti']?>" 
+"&fstat="+fstat
+"&fptov="+fptov 
+"&fdocu="+fdocu 
+"&fzsub="+fzsub 
+"&fenti="+fenti 
+"&fnum1="+fnum1
+"&fnum2="+fnum2
+"&fecha_ini="+fecha_ini 
+"&fecha_fin="+fecha_fin 
+"&total_min="+total_min 
+"&total_max="+total_max
+"&fcontra="+fcontra
+"&fbode="+fbode
+"&fdrtr="+fdrtr ;

//	if (confirm(pagina)) {};


location.href=pagina;
} 



function imprimirlista() 
{
var fstat=document.getElementById('fstat').value;
var fdocu='';
if(document.getElementById('fdocu'))
{fdocu=document.getElementById('fdocu').value;}
var fptov='';
if(document.getElementById('fptov'))
{fptov=document.getElementById('fptov').value;}
var fzsub='';
if(document.getElementById('fzsub'))
{fzsub=document.getElementById('fzsub').value;}
var fenti=document.getElementById('fenti').value;
var fdrtr=document.getElementById('fdrtr').value;
var fcontra=document.getElementById('fcontra').value;
var fnum1=document.getElementById('fnum1').value;
var fnum2=document.getElementById('fnum2').value;
var fecha_ini=document.getElementById('fecha_ini').value;
var fecha_fin=document.getElementById('fecha_fin').value;
var total_min=document.getElementById('total_min').value;
var total_max=document.getElementById('total_max').value;

//../lib/celectop1.php?docu

pagina="../lib/impr_list1.php?"
+"&docu=<?php echo $_GET['tipo']?>" 
+"&enti=<?php echo $_GET['enti']?>" 
+"&fstat="+fstat
+"&fzsub="+fzsub
+"&fdocu="+fdocu
+"&fptov="+fptov
+"&fenti="+fenti 
+"&fnum1="+fnum1 
+"&fnum2="+fnum2 
+"&fecha_ini="+fecha_ini 
+"&fecha_fin="+fecha_fin 
+"&total_min="+total_min 
+"&total_max="+total_max
+"&fcontra="+fcontra
+"&fdrtr="+fdrtr ;

window.open(pagina);
} 


//		url:'../lib/vrcexml1.php',
//		url:'../lib/vrcemail1.php',

function cemail(facdocu,facidnu,facid)
{
	$.ajax({
		cache:false,
		url:'../lib/vrcexml1.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{facdocu:facdocu,facidnu:facidnu},
    	beforeSend: function(jqXHR, textStatus)
		{
			
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
		//console.log(dato);
		pagina="../lib/celectop1.php?"
		+"&docu=FC10" 
		+"&idnum="+dato 
		+"&formato=1";
		//window.open(pagina);

			dato=dato.trim();
			if(dato!='0')
			{
				//console.log(dato.trim());
				//alert('Ocurrio un error al Facturar');
				//return false;
			}
			
		},
		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') {
               //console.log('Time out error.');
			   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:60000
	});

	
	





}





function facturar(facdocu,facidnu,facid)
{
	$.ajax({
		cache:false,
		url:'../lib/fact_docu.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{facdocu:facdocu,facidnu:facidnu},
    	beforeSend: function(jqXHR, textStatus)
		{
			
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
		//console.log(dato);
		pagina="../lib/celectop1.php?"
		+"&docu=FC10" 
		+"&idnum="+dato 
		+"&formato=1";
		window.open(pagina);

			dato=dato.trim();
			if(dato!='0')
			{
				//console.log(dato.trim());
				//alert('Ocurrio un error al Facturar');
				//return false;
			}
			
		},
		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') {
               //console.log('Time out error.');
			   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:60000
	});

	
	





}


function factdrtr(facdocu,facidnu,facid)
{
	$.ajax({
		cache:false,
		url:'../lib/fact_drtr.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{facdocu:facdocu,facidnu:facidnu},
    	beforeSend: function(jqXHR, textStatus)
		{
			
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
		//console.log(dato);
		pagina="../lib/celectop1.php?"
		+"&docu=NV13" 
		+"&idnum="+dato 
		+"&formato=1";
		window.open(pagina);

			dato=dato.trim();
			if(dato!='0')
			{
				//console.log(dato.trim());
				//alert('Ocurrio un error al Facturar');
				//return false;
			}
			
		},
		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') {
               //console.log('Time out error.');
			   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:60000
	});

	
	





}





function cobrar(cobdocu,cobidnu,cobid)
{
	
	document.getElementById('status'+cobidnu).innerHTML='C';
	/*
	if(confirm('Realizar cobro en Efectivo?'))
	{
	$.ajax({
		cache:false,
		url:'../lib/cobro1.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{cobdocu:cobdocu,cobidnu:cobidnu}, 
    	beforeSend: function(jqXHR, textStatus)
		{
	
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
			console.log(dato);
			document.getElementById('status'+cobidnu).innerHTML='C';
		},
		error:function(jqXHR,textStatus,errorThrown )
		{
           if (jqXHR.status === 0) {
              alert('Sin conexion: Verifique Red.');
           } 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') {
               //console.log('Time out error.');
			   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
	});
	}*/

}
function confirmadk(docucor,idxconfir,idconfir,acticonfir)
{
	
	var accion='';
	if(acticonfir=='C')
	{
		
		document.getElementById('status'+idxconfir).innerHTML='A';
		accion='A'
//++++++

	$.ajax({
		cache:false,
		url:'../lib/vrdk2dc0.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{idxnoti:idxconfir},
    	beforeSend: function(jqXHR, textStatus)
		{
			
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
			dato=dato.trim();
			if(dato!='0')
			{
				console.log(dato.trim());
				alert('Ocurrio un error al Registrar');
				return false;
			}
			
		},
		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') {
               //console.log('Time out error.');
			   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:60000
	});

//++++++		
		
		
		
	}
	
	if(acticonfir=='R')
	{
		
		document.getElementById('status'+idxconfir).innerHTML='R';
		accion='R'
	}
	
	document.getElementById('i_confirmadk'+idxconfir).style.display='none';
	document.getElementById('i_rechazadk'+idxconfir).style.display='none';
	$.ajax({
		cache:false,
		url:'../lib/dcnotifica4.php',
		datatype: "text",
	    async:false,
		type:'POST',
		data:{idxnoti:idxconfir,accion:accion},
    	beforeSend: function(jqXHR, textStatus)
		{
			
		}, 
		
		success:function(dato, textStatus, jqXHR)
		{
			dato=dato.trim();
			if(dato!='0')
			{
				console.log(dato.trim());
				alert('Ocurrio un error al Eliminar');
				return false;
			}
			
		},
		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') {
               //console.log('Time out error.');
			   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:60000
	});

//++++++ test

/*

*/
//++++++


	
	
}
	
function numbloq(e,e2)
{
	var xnumbloq=document.getElementById(e2).value.toUpperCase();
	var	xvnum='0123456789';
	var	xnum='';
	var xcar='';
		for (i=0; i<xnumbloq.length;i++)
			{
				xcar=xnumbloq.substring(i,i+1);	
				if (xvnum.indexOf(xcar)>=0){xnum+=xcar;}
			}
		 	document.getElementById(e2).value=xnum;
}

function valbloq(e,e2)
{
	var xnumbloq=document.getElementById(e2).value.toUpperCase();
	var	xvnum='0123456789.-';
	var	xnum='';
	var xcar='';
		for (i=0; i<xnumbloq.length;i++)
			{
				xcar=xnumbloq.substring(i,i+1);	
				if (xvnum.indexOf(xcar)>=0){xnum+=xcar;}
				if (xcar=='.'){xvnum=xvnum.replace('.','');}
				if (xcar=='-'){xvnum=xvnum.replace('-','');}
			}
		 	document.getElementById(e2).value=xnum;
}
	
	
<?php require('../../_js/deledeta.js');?>

</script>
<div align="center" style="padding:5px;">


<?php
$xfstat='';
$xfzsub='';
$xfdocu='';
$xfptov='';
$xfenti='';
$xfdrtr='';
$xfbode='';
$xfcontra='';
$xfnum1=0;
$xfnum2=999999999;
//$xfecha1=jdtojulian(juliantojd(date('m'),date('d'),date('Y'))-30);

$fecha1 = date('Y-m-j');
$nuevafecha = strtotime ( '-1 month' , strtotime ( $fecha1 ) ) ;
$xfecha1 = date ( 'Y-m-j' , $nuevafecha );
$xfecha2 = date('Y-m-d');
$xtotal1=0;
$xtotal2=999999999.99;
// $xnumero1='0';
// $xnumero2='999999999';
// $sql_ped='select *from '.$tabla.'11 where docu like "'.$docu_tipo.'%"';
$sql_ped='select *from '.$tabla.'12 where docu like "'.$docu_tipo.'%"';

if (substr($docu_tipo,0,2)=='CX')
{
$sql_ped='select *from '.$tabla.'11 where docu!=""';
}


if(isset($_GET['fstat']) && !empty($_GET['fstat']))
{
	$sql_ped.=' and  (status like "'.$_GET['fstat'].'" ) ';
	$xfstat=$_GET['fstat'];
}


if(isset($_GET['fdocu']) && !empty($_GET['fdocu']))
{
	$sql_ped.=' and  (docu like "'.$_GET['fdocu'].'%" ) ';
	$xfdocu=$_GET['fdocu'];
}

if(isset($_GET['fzsub']) && !empty($_GET['fzsub']))
{
	$sql_ped.=' and  (zsub like "'.$_GET['fzsub'].'%" ) ';
	$xfzsub=$_GET['fzsub'];
}

if(isset($_GET['fptov']) && !empty($_GET['fptov']))
{
	$sql_ped.=' and  (ptov like "'.$_GET['fptov'].'" or ptov_descri like "%'.$_GET['fptov'].'%" or ptoe like "'.$_GET['fptov'].'%" ) ';
	$xfptov=$_GET['fptov'];
}


if(isset($_GET['fenti']) && !empty($_GET['fenti']))
{
	$sql_ped.=' and  (enti like "'.trim($_GET['fenti']).'%" or enti_descri like "%'.trim($_GET['fenti']).'%") ';
	$xfenti=$_GET['fenti'];
}



if(isset($_GET['fnum1']) && !empty($_GET['fnum1']) && isset($_GET['fnum2']) && !empty($_GET['fnum2']))
{
	$xfnum1=$_GET['fnum1'];
	$xfnum2=$_GET['fnum2'];
	if($xfnum2==0){$xfnum2=999999999;}
	$sql_ped.=' and  numero>="'.$xfnum1.'" and numero<="'.$xfnum2.'"';
}
else
{
	$sql_ped.=' and  numero BETWEEN "'.$xfnum1.'" and "'.$xfnum2.'"';
}


if(isset($_GET['fecha_ini']) && !empty($_GET['fecha_ini']) && isset($_GET['fecha_fin']) && !empty($_GET['fecha_fin']))
{
	$sql_ped.=' and  fecha BETWEEN "'.$_GET['fecha_ini'].'" and "'.$_GET['fecha_fin'].'"';
	$xfecha1=$_GET['fecha_ini'];
	$xfecha2=$_GET['fecha_fin'];
}
else
{
	$sql_ped.=' and  fecha BETWEEN "'.$xfecha1.'" and "'.$xfecha2.'"';
}

//if(isset($_GET['total_min']) && !empty($_GET['total_min']) && isset($_GET['total_max']) && !empty($_GET['total_max']))

if(isset($_GET['total_min'])  && isset($_GET['total_max']) && !empty($_GET['total_max']))
{
// 	$sql_ped.=' and  abs(total) BETWEEN '.$_GET['total_min'].' and '.$_GET['total_max'].' ';
	$xtotal1=$_GET['total_min'];
	$xtotal2=$_GET['total_max'];
	if($xtotal2==0){$xtotal2=999999999999;}
	$sql_ped.=' and abs(total) >='.$xtotal1.' and abs(total) <= '.$xtotal2.' ';
}
else
{
	$sql_ped.=' and  abs(total) BETWEEN '.$xtotal1.' and '.$xtotal2.' ';
}


if(isset($_GET['fcontra']) && !empty($_GET['fcontra']))
{
	$sql_ped.=' and  (contrato like "%'.$_GET['fcontra'].'%")';
	$xfcontra=$_GET['fcontra'];
}

if(isset($_GET['fdrtr']) && !empty($_GET['fdrtr']))
{
	$sql_ped.=' and  (drtr like "'.$_GET['fdrtr'].'%")';
	$xfdrtr=$_GET['fdrtr'];
}
if(isset($_GET['fbode']) && !empty($_GET['fbode']))
{
	$sql_ped.=' and  (bode like "'.$_GET['fbode'].'%")';
	$xfbode=$_GET['fbode'];
}
	
// echo $sql_ped;


//echo 'MIS PEDIDOS';
if ($docu_enti=='M')
{
	if ($drtr==0)
	{$sql_ped.=' and (left(enti,10) like "' .$_SESSION['user_vcrx_id'].'%")';}
	else
	{$sql_ped.=' and (left(enti,10) like "'.$_SESSION['user_vcrx_id'].'%" or left(drtr,10) like "'.$_SESSION['user_vcrx_id'].'%")';}
}


$xorder=' order by fecha desc, idnum1 desc';

if (mb_stristr('RC.RP',$docu_tipo))
{$xorder=' order by fecha desc, numero desc, enti, idnum1 desc';}

if(mb_stristr('caja.bcos.cjte',$tabla))
{$xorder=' order by fecha desc, caja, ctab, numero desc, enti, idnum1 desc';}

$sql_ped.=$xorder;
// echo $sql_ped;



?>

<div style=" max-height:100px; 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>
	</table>
	
<!-- <div align="center">
FECHAS
</div>
<div align="right">
<span>Inicial</span> <input type="text" id="fecha_ini" placeholder="aaaa-mm-dd" size="6" onkeypress="_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" onkeypress="_fecha(event,'fecha_fin');" value="<?php echo $xfecha2;?>" />
</div> -->
</th>

<th style ="border-left:solid 1px;">
	<table><caption>NUMEROS</caption>	
	<tr>
		<?php $pcaption='Desde';  $pidtxt='fnum1'; $pdefa=$xfnum1; $pobj=3; include('vrgetnum.php'); ?>
</tr>
	<tr>
		<?php $pcaption='Hasta';  $pidtxt='fnum2'; $pdefa=$xfnum2; $pobj=3; include('vrgetnum.php'); ?>
</tr>
	</table>
<!-- <div align="center">
NUMEROS
</div>
<div align="right">
<span>Desde</span> <input type="text" id="fnum1" placeholder="999999999" size="10" maxlength="9" value="<?php echo $xfnum1;?>" style="text-align:right;" onkeyup="numbloq(event,'fnum1')" /> 
</div>
<div align="right">
<span>Hasta</span> <input type="text" id="fnum2" placeholder="999999999" size="10" maxlength="9" value="<?php echo $xfnum2;?>" style="text-align:right;" onkeyup="numbloq(event,'fnum2')"/>
</div> -->
</th>

	
	
<th style ="border-left:solid 1px;">
<table><caption>TOTALES</caption>	
	<tr>
		<?php $pcaption='Minimo';  $pidtxt='total_min'; $pdefa=$xtotal1;  include('vrgetval.php'); ?>
</tr>
	<tr>
		<?php $pcaption='Maximo';  $pidtxt='total_max'; $pdefa=$xtotal2;  include('vrgetval.php'); ?>
</tr>
	</table>
<!-- <div align="center">
TOTALES
</div>
<div align="right">
<span>Minimo</span> <input type="text" id="total_min" placeholder="999,999,999.99" size="10" maxlength="12" value="<?php echo $xtotal1;?>" style="text-align:right;" onkeyup="valbloq(event,'total_min')" /> 
</div>
<div align="right">
<span>Maximo</span> <input type="text" id="total_max" placeholder="999,999,999.99" size="10" maxlength="12" value="<?php echo $xtotal2;?>" style="text-align:right;" onkeyup="valbloq(event,'total_max')"/>
</div> -->
</th>


<th style ="border-left:solid 1px;">
FILTROS
</th>
<th>
<table>
	<tr>
		<?php $pcaption='Documento';  $ptabla='docu'; $pidtxt='fdocu'; $pdefa=$xfdocu; $pnotob=1; include('vrgetcod.php'); ?>
	</tr>
	<?php if(mb_stristr('vtas',$tabla)){?>
	<tr>
		<?php $pcaption='Pto.Vta.';  $ptabla='ptov'; $pidtxt='fptov'; $pdefa=$xfptov; $pnotob=1; include('vrgetcod.php'); ?>
	</tr>
	<?php } ?>
</table>
</th>
<th>	
<table>

	<?php if(mb_stristr('vtas.clie',$tabla)){?>
	<tr>
		<?php $pcaption='Zona';  $ptabla='zsub'; $pidtxt='fzsub'; $pdefa=$xfzsub; $pnotob=1; include('vrgetcod.php'); ?>
	</tr>
	<tr>
		<?php $pcaption='Cliente';  $ptabla='enti'; $pidtxt='fenti'; $pdefa=$xfenti; $pnotob=1; include('vrgetcod.php'); ?>
	</tr>
	<?php } ?>

	
	<?php if(mb_stristr('cjte',$tabla)){?>
	<tr>
		<?php $pcaption='Cliente';  $ptabla='enti'; $pidtxt='fenti'; $pdefa=$xfenti; $pnotob=1; include('vrgetcod.php'); ?>
	</tr>
	<?php } ?>

	<?php if(mb_stristr('comp.prov',$tabla)){?>
	<tr>
		<?php $pcaption='Proveedor';  $ptabla='enti'; $pidtxt='fenti'; $pdefa=$xfenti; $pnotob=1; include('vrgetcod.php'); ?>
	</tr>
	<tr>
		<?php $pcaption='Tipo';  $ptabla='tpro'; $pidtxt='ftpro'; $pdefa=$xftpro; include('vrgetcod.php'); ?>
	</tr>
	<?php } ?>

	<?php if(mb_stristr('inve',$tabla)){?>
	<tr>
		<?php $pcaption='Bodega';  $ptabla='bode'; $pidtxt='fbode'; $pdefa=$xfbode; include('vrgetcod.php'); ?>
	</tr>
	<tr>
		<?php $pcaption='Entidad';  $ptabla='enti'; $pidtxt='fenti'; $pdefa=$xfenti; $pnotob=1; include('vrgetcod.php'); ?>
	</tr>
	<?php } ?>

	</table>	
    <?php
    switch($tabla)
    {
   	case "inve":
    ?>  
<!-- 	<div align="right"><span>Bodega</span> <input type="text" id="fbode" placeholder="bodega" size="10" value="<?php echo $xfbode;?>" /> </div> -->
	<?php
	break;

	case "vtas":
    ?>  
<!--     	<div align="right">
	    <span>Pto.Vta.</span> 
	    <input type="text" id="fptov" placeholder="ptov" size="10" value="<?php echo $xfptov;?>" /> 
    	</div>
    	<div align="right">
	    <span>Zona-Sub</span> 
	    <input type="text" id="fzsub" placeholder="zona" size="10" value="<?php echo $xfzsub;?>" /> 
		</div> -->
	<div align="right">
<!--     <span>Cliente</span>  -->
    <?php
	    break;

		case "clie":
    ?>  
<!--     	<div align="right">
	    <span>Zona-Sub</span> 
	    <input type="text" id="fzsub" placeholder="zona" size="10" value="<?php echo $xfzsub;?>" /> 
    	</div> -->
	<div align="right">
<!-- 	    <span>Cliente</span>  -->
    <?php
	    break;
    	case "comp":
    ?>  
	<div align="right">
<!-- 	    <span>Proveedor</span>  -->
    <?php
    	    break;
    	case "prov":
    ?>  
	<div align="right">
<!-- 	    <span>Proveedor</span>  -->
    <?php
    	    break;
    	case "nomi":
    ?>  
	<div align="right">
<!-- 	    <span>Empleado</span>  -->
    <?php
	    break;

    	default;
    ?>  
	<div align="right">
<!-- 	    <span>Entidad</span>  -->

    <?php
    	
    }
    ?>  
<!-- <input type="text" id="fenti" placeholder="c.i. o nombre" size="10" value="<?php echo $xfenti;?>" />  -->
</div>
</th>



<th>
<?php $pcaption='Status';  $ptabla='stat'; $pidtxt='fstat'; $pdefa=$xfstat; $pnotob=1; include('vrgetcod.php'); ?>
<!-- <span>Status</span> <input type="text" id="fstat" placeholder="A" size="1" value="<?php echo $xfstat;?>" />  -->
</th>


<th style ="border-left:solid 1px;"> 
<table>
	<tr style="
			<?php if(mb_stristr('gnya.leie',substr($_SESSION['user_vcrx_empr'],0,4))
		  			&& mb_stristr('admi.supe.sist',substr($_SESSION['user_vcrx_tipo'],0,4))
							){}else{echo 'display:none;';}?>">
						 
		<?php $pcaption='Director';  $ptabla='enti'; $pidtxt='fdrtr';  $pdefa=$xfdrtr; $pnotob=1; include('vrgetcod.php'); ?>
	</tr>

	<tr style="
			<?php if(mb_stristr('rcsa',substr($_SESSION['user_vcrx_empr'],0,4))
		  			&& mb_stristr('admi.supe.sist',substr($_SESSION['user_vcrx_tipo'],0,4))
							){}else{echo 'display:none;';}?>">
						 
		<?php $pcaption='Siniestro';  $ptabla='sntr'; $pidtxt='fsntr'; $pdefa=$xfdrtr; include('vrgetcod.php'); ?>
	</tr>
	<tr style="
			<?php if(mb_stristr('rcsa',substr($_SESSION['user_vcrx_empr'],0,4))
		  			&& mb_stristr('admi.supe.sist',substr($_SESSION['user_vcrx_tipo'],0,4))
							){}else{echo 'display:none;';}?>">
						 
		<?php $pcaption='Vehiculo';  $ptabla='vhcl'; $pidtxt='fvhcl'; $pdefa=$xfdrtr; include('vrgetcod.php'); ?>
	</tr>
</table>
</th>
		
<?php
if (mb_stristr('gnya.leie',substr($_SESSION['user_vcrx_empr'],0,4)) && mb_stristr('admi.supe.sist',substr($_SESSION['user_vcrx_tipo'],0,4)) )
{
?>
<th style ="border-left:solid 1px;">
<!-- 	<div align="right">
	<span>Director</span> <input type="text" id="fdrtr" placeholder="c.i." size="10" value="<?php echo $xfdrtr;?>" /> 
	</div> -->
	</th>
<?php
}
else
{
?>
	<th>
	<div>
<!-- 	<input type="hidden" id="fdrtr" value=""> -->
	</div>
	</th>
<?php
}
?>

<?php
if (mb_stristr('tcor.vrfa',substr($_SESSION['user_vcrx_empr'],0,4)) && mb_stristr('admi.supe.sist',substr($_SESSION['user_vcrx_tipo'],0,4)) )
{
?>
<th style ="border-left:solid 1px;">
	<div align="right">
	<span>Contrato</span> <input type="text" id="fcontra" placeholder="123456789" size="10" value="<?php echo $xfcontra;?>" /> 
	</div>
	</th>
<?php
}
else
{
?>
	<th>
	<div>
	<input type="hidden" id="fcontra" value="">
	</div>
	</th>
<?php
}
?>

<th align="center" style ="border-left:solid 1px;">
<div>
<input type="button" value="Consultar" onclick="redireccionar();"  />
</div>
<br>

<div>
<input type="button" value="Imprimir" onclick="imprimirlista();"  />
</div>
<?php if($_GET['tipo']=='FP' && ($_SESSION['user_vcrx_id']=='0913534061' ||  $_SESSION['user_vcrx_id']== '0915379374')){ ?>
<div>
<input type="button"    value="Subir XML" onclick="uploadAjax('xml_','','');"/>
<input type="file"   id="xml_" />

</div>

<script type="text/javascript">

function uploadAjax(archivo,rut,cod){
	
	if(document.getElementById(archivo).value=='')
	{
		alert('No ha elegido ningun archivo');
		return false;
	}

var inputFileImage = document.getElementById(archivo);
var file = inputFileImage.files[0];

var data = new FormData();
data.append('archivo',file);
//document.getElementById('foto').disabled=true;
//document.getElementById('btn_dper').disabled=true;

$.ajax({
	url:'../lib/vruplce1.php', 
	async:false,
	type:'POST',
	contentType:false,
	data:data,
	processData:false,
	cache:false,
	success: function(dato)
	{	
		console.log(dato);
		if(dato=='1')
		{
		   alert('Error: Se ha cerrado su sesion, salga y vuelva a ingresar');
		}
		else if(dato=='2')
		{
		   alert('Error: no se pudo subir el archivo');
		}
		else if(dato=='3')
		{
		 alert('Solo se aceptan xml');
		}

	        else
		{
		 alert(dato);
                 

		}
                document.getElementById(archivo).value='';
		
	},
	error:function(jqXHR,textStatus,errorThrown )
	{
           if (jqXHR.status === 0) {
              alert('Not connect: Verify Network.');
           } else if (jqXHR.status == 404) {
              alert('Requested page not found [404]');
           } else if (jqXHR.status == 500) {
               alert('Internal Server Error [500].');
           } else if (exception === 'parsererror') {
               alert('Requested JSON parse failed.');
           } else if (exception === 'timeout') {
               alert('Servidor no Responde');
           } else if (exception === 'abort') {
               alert('Ajax request aborted.');
           } else {
               alert('Uncaught Error: ' + jqXHR.responseText);
           }
		}, 
	    complete:function(jqXHR, textStatus)
    	{
			
		if(textStatus==='success')
	        {

		}
			           
		},
		timeout:90000
});
}
</script>

<?php } ?>

</th>

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

<hr/>

<?php
$res_ped=mysql_query($sql_ped,$link_vcrx);
//echo $sql_ped;
if(mysql_num_rows($res_ped)!=0)
{
$docu=mysql_result($res_ped,0,'docu');
$res_ped=mysql_query($sql_ped,$link_vcrx);
?> 

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

<table id="tabla_cab_ped" width="100%" border="0" cellspacing="0" cellpadding="2" style="border-collapse:collapse;font-size:12px; border:#000000 solid 1px;">
	
    <tr style="border-bottom:#000000 solid 2px; ">
    <th ></th>
    <th ></th>
    <th ></th>

    <?php
    switch($tabla)
    {
    	case "vtas":
    ?>  
	    <th>CLIENTE</th>
    <?php
	    break;
    	case "clie":
    ?>  
	    <th>CLIENTE</th>
    <?php
	    break;
    	case "comp":
    ?>  
	    <th>PROVEEDOR</th>
    <?php
    	    break;
    	case "prov":
    ?>  
	    <th>PROVEEDOR</th>
    <?php
    	    break;
    	case "nomi":
    ?>  
	    <th>EMPLEADO</th>
    <?php
    	    break;
    	case "cont":
    ?>  
	    <th>CONCEPTO</th>
	    <th>DOCU</th>
    <?php
	    break;
    	default;
    ?>  
	    <th>ENTIDAD</th>
    <?php
    	
    }
    ?>  
  
    <th>NUMERO</th>
    <th>FECHA</th>
    <?php
    if(mb_stristr('vtas.clie.comp.prov.clte',$tabla))
    {
    ?>
    <th>CANT</th>
    <th>SUBT</th>
    <th>DSCTO</th>
    <th>
    	<?php if(mb_stristr('tcor',substr($_SESSION['user_vcrx_empr'],0,4))){echo '<span>ICE/</span><span>IVA</span>';}else{echo 'IVA';} ?>
    </th>
    
    <th>TOTAL</th>
    <?php } ?>

    <?php
    if(mb_stristr('caja.cjte',$tabla))
    {
    ?>
    <th>CAJA </th>
    <th>CANT</th>
    <?php } ?>


    <?php
    if(mb_stristr('.bcos.',$tabla))
    {
    ?>
    <th>BANCO</th>
    <th>CANT</th>
    <?php } ?>




    <?php
    if(mb_stristr('retc.retp',$tabla))
    {
    ?>
    <th>CAIR</th>
    <th>B.RTA</th>
    <th>%</th>
    <th>R.RTA</th>
    <th>B.IVA</th>
    <th>%</th>
    <th>R.IVA</th>
    <th>TOTAL</th>
    <?php } ?>



    <?php
    if(mb_stristr('inve.prod',$tabla))
    {
    ?>
    <th>BODEGA</th>
				<?php if (substr($docu_tipo,0,1)=='I'){	?>
				<th>DESDE</th>
				<?php }else{?>
				<th>PARA</th>
				<?php } ?>
    <th>ITEM</th>
    <th>CANT</th>
    <th>P.UNIT</th>
    <?php } ?>

    <?php
    if(mb_stristr('cxco.cxpa',$tabla))
    {
    ?>
    <th>VENCE</th>
    <th>VALOR</th>
    <th>ABONO</th>
    <th>SALDO</th>
    <?php } ?>

    <?php
    if(mb_stristr('cont',$tabla))
    {
    ?>
    <th>DEBITOS</th>
    <th>CREDITOS</th>
    <th>DIFEREN.</th>
    <?php } ?>
		


    <th>ST</th>

    <th>
    	<?php if(mb_stristr('gnya.leie',substr($_SESSION['user_vcrx_empr'],0,4))
    	&& mb_stristr('vtas.clie',$tabla)
    	&& ($drtr==1 || mb_stristr('admi.supe.sist',substr($_SESSION['user_vcrx_tipo'],0,4))))
    	{echo 'Comi';} ?>

    	<?php if(mb_stristr('tcor',substr($_SESSION['user_vcrx_empr'],0,4))
    	&& mb_stristr('vtas.clie',$tabla))
    	{echo 'Contrato';} ?>

    </th>
    <th></th>
    <th></th>
    </tr>


	<?php
	$filax=1;
	$idcont=0;
	while($r_ped=mysql_fetch_assoc($res_ped))
	{
		$idcont++;
	?>
	<tr class="pdc_t1" id="<?php echo $r_ped['idnum1']; ?>" align="center" style=" <?php if($filax==3){echo 'border-bottom:dotted 1px #000;';$filax=1;}else{$filax++;} ?>" >
    <td>
    <a href="../lib/celectop1.php?docu=<?php echo $r_ped['docu']; ?>&idnum=<?php echo $r_ped['idnum1']; ?>&formato=1" target="_blank"><img src="../img/print2.png" width="20"  title="Documento:<?php echo $r_ped['docu'];?>-<?php echo $r_ped['numero'];?>"  /></a>

			<?php	if (mb_stristr('sist.supe',substr($_SESSION['user_vcrx_tipo'],0,4))): ?>
		<?php	if(mb_stristr('vtas.comp.nomi.inve.caja.bcos.afij',$tabla)): ?>
    <a href="../lib/celectop1.php?docu=<?php echo $r_ped['docu']; ?>&idnum=<?php echo $r_ped['idnum1']; ?>&formato=3" target="_blank"><img src="../img/print2.png" width="20"  title="Diario:<?php echo $r_ped['docu'];?>-<?php echo $r_ped['numero'];?>"  /></a>
		<?php endif; ?>
		<?php endif; ?>
		</td>

		<td>
    <input type="image" onclick="mpedido_d('<?php echo $r_ped['idnum1']; ?>','<?php echo $tabla;?>');" src="../img/hpedido.png" width="20" class="btn_ped_c" name="btn_ped_c" title="Ver Detalle  <?php echo $r_ped['docu'];?>-<?php echo $r_ped['numero'];?>"/>
    </td>
		
			

<td>
    <?php
    if (mb_stristr($xcelec,substr($r_ped['docu'],0,2)))
    {if (mb_stristr('admi.sist',substr($_SESSION['user_vcrx_tipo'],0,4)))
    {if ($r_ped['enti_email']!="")
    { ?>
    <input type="image" id="id_cemail<?php echo $r_ped['idnum1'];?>" src="http://vcrxol.com/_img/ico_cemail.png" width="20" name="btn_ped_c" title="Enviar e-mail  <?php echo $r_ped['docu'];?>-<?php echo $r_ped['numero'];?>-<?php echo $r_ped['enti_email'];?>" onclick="if(confirm('Enviar e-mail a  <?php echo $r_ped['enti_descri'];?>-<?php echo $r_ped['enti_email'];?>'))cemail('<?php echo $r_ped['docu']; ?>','<?php echo $r_ped['idnum1'];?>',this.id);"  />
    <?php }}}  ?> 

    <?php
    if (mb_stristr($xcelec,substr($r_ped['docu'],0,2)))
    {if (mb_stristr('admi.sist.clie.prov',substr($_SESSION['user_vcrx_tipo'],0,4)))
    {if ($r_ped['claveacc']!="")
    { ?>
    <input type="image" id="id_xml1<?php echo $r_ped['idnum1'];?>" src="http://vcrxol.com/_img/ico_xml1.png" width="20" name="btn_ped_c" title="Descargar XML  <?php echo $r_ped['docu'];?>-<?php echo $r_ped['numero'];?>" onclick="downxml1('<?php echo $r_ped['docu']; ?>','<?php echo $r_ped['idnum1'];?>',this.id);"  />
    <?php }}}  ?> 

</td>

	<?php
    if(mb_stristr('cont',$tabla))
	{
	?>
    <td align="left" style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;">
		<?php echo '<span title="'.$r_ped['enti_descri'].'">'.$r_ped['concepto'].'</span>';?>
    </td>
    <td align="center" style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;">
		<?php echo '<span title="'.$r_ped['docu_descri'].'">'.$r_ped['docu'].'</span>';?>
    </td>
	<?php } else { ?>
    <td align="left" style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;">
		<?php echo '<span title="'.$r_ped['enti'].'">'.$r_ped['enti_descri'].'</span>';?>
    </td>
	<?php } ?>
		
		
		
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" onclick="mpedido_d('<?php echo $r_ped['idnum1']; ?>','<?php echo $tabla;?>');">
		<?php 
// 		echo '<span title="'.$r_ped['docu_descri'].'-'.$r_ped['ptonumero'].' : '.$r_ped['idnum1'].'">'.$r_ped['numero'].'</span>';
    if(mb_stristr('cont',$tabla))
			{echo '<span title="'.$r_ped['docu_descri'].'-'.$r_ped['ptonumero'].' : '.$r_ped['idnum1'].'">'.$r_ped['numero'].'</span>';}
    if(mb_stristr('vtas.clie.comp.prov.clte',$tabla))
			{echo '<span title="'.$r_ped['docu_descri'].'-'.$r_ped['ptonumero'].' : '.$r_ped['idnum1'].'">'.$r_ped['ptonumero'].'</span>';}
    if(mb_stristr('inve.prod',$tabla))
			{echo '<span title="'.$r_ped['docu_descri'].'-'.$r_ped['ptonumero'].' : '.$r_ped['idnum1'].'">'.$r_ped['docu'].'-'.$r_ped['numero'].'</span>';}
    if(mb_stristr('caja.bcos.cjte',$tabla))
			{echo '<span title="'.$r_ped['docu_descri'].'-'.$r_ped['ptonumero'].' : '.$r_ped['idnum1'].'">'.$r_ped['docu'].'-'.$r_ped['numero'].'</span>';}
		?>
    </td>
    <td>
	<?php echo '<span title="Fecha Reg : '.date_format(date_create($r_ped['idate']),'d/M/y H:m').'">'.$r_ped['fechadmy'].'</span>';?>
    </td>



    <?php
    if(mb_stristr('vtas.clie.comp.prov.clte',$tabla))
    {
    ?>
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="right">
    	<?php echo number_format($r_ped['tcant'],2);?>
    </td>
    <td align="right">
    	<?php echo number_format($r_ped['tsubt'],2);?>
    </td>
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="right">
	<?php echo '<span title="'.number_format($r_ped['pdcto'],2).'%">'.number_format($r_ped['tdcto'],2).'</span>';?>
    </td>
    <td align="right">
	<?php
	if($r_ped['tice']!=0){echo '<span title="'.number_format($r_ped['pice'],2).'%">'.number_format($r_ped['tice'],2).' /</span> '; } 
	else{}
	echo '<span title="'.number_format($r_ped['piva'],2).'%">'.number_format($r_ped['tiva'],2).'</span>';
	?>
    </td>
    <td style="border-left:#000000 solid 1px;" align="right">
    	<?php echo number_format($r_ped['total'],2);?>
    	
    </td>

    <?php
    }
    ?>


    <?php
    if(mb_stristr('caja.bcos.cjte',$tabla))
    {
    ?>
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="center">
	<?php
	if($r_ped['caja']!=""){echo '<span title="'.$r_ped['caja'].'">'.$r_ped['caja_descri'].' </span> '; } 
	if($r_ped['ctab']!=""){echo '<span title="'.$r_ped['ctab'].'">'.$r_ped['ctab_descri'].' </span> '; } 
	?>
    </td>
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="right">
    	<?php echo number_format($r_ped['tcant'],2);?>
    </td>
    <?php
    }
    ?>

    <?php
    if(mb_stristr('retc.retp',$tabla))
    {
    ?>
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="center">
	<?php echo '<span title="'.$r_ped['cair'].'">'.$r_ped['cret'].'</span>';?>
    </td>
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="right">
	<?php echo '<span title="'.$r_ped['brta'].'">'.number_format($r_ped['brta'],2).'</span>';?>
    </td>
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="center">
	<?php echo '<i><span title="'.$r_ped['prta'].'">'.number_format($r_ped['prta'],2).'</span>';?>
    </td>
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="right">
	<?php echo '<span title="'.$r_ped['rrta'].'">'.number_format($r_ped['rrta'],2).'</span>';?>
    </td>
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="right">
	<?php echo '<span title="'.$r_ped['biva'].'">'.number_format($r_ped['biva'],2).'</span>';?>
    </td>
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="center">
	<?php echo '<i><span title="'.$r_ped['piva'].'">'.number_format($r_ped['piva'],2).'</span>';?>
    </td>
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="right">
	<?php echo '<span title="'.$r_ped['riva'].'">'.number_format($r_ped['riva'],2).'</span>';?>
    </td>
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="right">
	<?php echo '<span title="'.abs($r_ped['total']).'">'.number_format(abs($r_ped['total']),2).'</span>';?>
    </td>
    <?php } ?>



    <?php if(mb_stristr('inve.prod',$tabla)) {  ?>
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="center">
    	<?php echo $r_ped['bode'];?>
    </td>
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="center">
    	<?php echo $r_ped['tobode'];?>
    </td>
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="left">
			<span title="<?php echo $r_ped['item_descri'];?>"> 
    	<?php echo $r_ped['item_descri'];?>
			</span>	
    </td>
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="right">
    	<?php echo number_format($r_ped['tcant'],2);?>
    </td>
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="right">
    	<?php echo number_format($r_ped['puni'],2);?>
    </td>
    <?php } ?>

    <?php
    if(mb_stristr('cxco.cxpa',$tabla))
    {
    ?>
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="center">
    <?php if($r_ped['saldo']>=1 && $r_ped['vence']<date('Y-m-d')) {echo '<font color="red">';} ?> <?php echo $r_ped['vencedmy'];?>
    </td>
    
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="right">
    	<?php echo number_format($r_ped['total'],2);?>
    </td>
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="right">
    	<?php echo number_format($r_ped['abono'],2);?>
    </td>
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="right">
    	<?php echo number_format($r_ped['saldo'],2);?>
    </td>


    <?php } ?>

    <?php
    if(mb_stristr('cont',$tabla))
    {
    ?>
    
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="right">
    	<?php echo number_format($r_ped['tdebito'],2);?>
    </td>
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="right">
    	<?php echo number_format($r_ped['tcredito'],2);?>
    </td>
    <td style="border-left:#000000 solid 1px; border-right:#000000 solid 1px;" align="right">
		<?php if($r_ped['diferencia']<0){echo '<font color="red">';} ?>
    	<?php echo number_format($r_ped['diferencia'],2);?>
    </td>

    <?php } ?>




    
    <td style="border-left:#000000 solid 1px;">
	<?php echo '<span id="status'.$r_ped['idnum1'].'" title="'.$r_ped['stat_descri'].'">'.$r_ped['status'].'</span>';?>
    	
    </td>

	<td style="border-left:#000000 solid 1px;" align="right">
   
	<?php
	if (mb_stristr('gnya.leie',substr($_SESSION['user_vcrx_empr'],0,4)) && mb_stristr('vtas.clie',$tabla) )
	{
	if (($drtr==1 && mb_stristr($r_ped['enti'].'-'.$r_ped['drtr'],$_SESSION['user_vcrx_id'])) ||  (mb_stristr('admi.sist',substr($_SESSION['user_vcrx_tipo'],0,4))))
	{
	?>
	<?php echo '<span title="'.number_format($r_ped['comi'],2).'%">'.number_format($r_ped['tcomi'],2).'</span>';?>
	<?php }} ?>

	<?php
	if (mb_stristr('tcor',substr($_SESSION['user_vcrx_empr'],0,4)) && mb_stristr('vtas.clie',$tabla) )
	{
	?>
	<?php echo '<span>'.$r_ped['zsub'].'/'.$r_ped['contrato'].'</span>';?>
	<?php } ?>

	</td>

<?php
$xfec1 = date('Y-m-j');
//$xfec1 = strtotime ( '-10 day' , strtotime ( $xfec1 ) ) ;
$xfec1 = strtotime ( '-30 day' , strtotime ( $xfec1 ) ) ;
if (mb_stristr('clie',$tabla))
{}
//$xfec1 = date ( 'Y-m-j', $xfec1);
//$xfec2= date ( 'Y-m-j' , strtotime($r_ped['idate']) );

$xfec1= date ( 'Y-m-d', $xfec1);
$xfec2= date ( 'Y-m-d' , strtotime($r_ped['idate']) );
$xstat = $r_ped['status'];
$xmodif = 0;
if ($xaccesom==1)
{
if ($xfec2>=$xfec1 && $xstat=="-"){$xmodif=1;}
if (mb_stristr('caja.bcos.cxjte',$tabla)){$xmodif=1;}
}
if (mb_stristr('vtas',$tabla)){$xmodif=0;}
if(mb_stristr('DK',substr($r_ped['docu'],0,2))){$xmodif=0;}

	

?>
    
    <td align="center" style="border-left:#000000 solid 1px;">
    	<?php 
	if(!mb_stristr('OoXx',$r_ped['status']) && mb_stristr('admi.supe.sist',substr($_SESSION['user_vcrx_tipo'],0,4)) )
	{
	?>

	    	<?php 
		if(!mb_stristr('RF',$r_ped['status']) && mb_stristr('clie',$tabla) && mb_stristr('OP1',substr($r_ped['docu'],0,3)))
		{
		?>
	       	<input type="image" id="id_factura<?php echo $r_ped['idnum1'];?>" src="http://vcrxol.com/_img/ico_factura.png" width="25" title="Facturar <?php echo $r_ped['docu'];?>-<?php echo $r_ped['numero'];?>"     onclick="if(confirm('Desea Facturar ?<?php echo $r_ped['docu'];?>-<?php echo $r_ped['numero'];?>'))facturar('<?php echo $r_ped['docu'];?>','<?php echo $r_ped['idnum1'];?>',this.id,'F');"  />
        	<?php } ?>

	    	<?php 
		if(mb_stristr('FC',substr($r_ped['docu'],0,2)) && mb_stristr('vtas',$tabla)  )
		{
		?>
		    	<?php 
			if (mb_stristr('gnya',substr($_SESSION['user_vcrx_empr'],0,4)))
			{
			?>

		    	<?php 
			if(!mb_stristr('FCROX',$r_ped['status']))
			{
			?>
		    	<?php 
			if($r_ped['drtr']!="")
			{
			?>

		       	<input type="image" id="id_factdrtr<?php echo $r_ped['idnum1'];?>" src="http://vcrxol.com/_img/ico_cxcdir.png" width="25" title="Facturar a Director <?php echo $r_ped['docu'];?>-<?php echo $r_ped['numero'];?>"     onclick="if(confirm('Cobrar a Director ? <?php echo $r_ped['docu'];?>-<?php echo $r_ped['numero'];?>'))factdrtr('<?php echo $r_ped['docu'];?>','<?php echo $r_ped['idnum1'];?>',this.id,'F');"  />

	        	<?php } ?>
	        	<?php } ?>
	        	<?php } ?>

        	<?php } ?>

	    	<?php 
		if(mb_stristr('DK',substr($r_ped['docu'],0,2)) && mb_stristr('cjte',$tabla)  )
		{
		?>
	    	<?php 
		if(!mb_stristr('ANROX',$r_ped['status']))
		{
		?>
	       	<input type="image" id="i_confirmadk<?php echo $r_ped['idnum1'];?>" src="http://vcrxol.com/_img/ico_aprobar.png" width="25" title="Confirmar <?php echo $r_ped['docu'];?>-<?php echo $r_ped['numero'];?>"     onclick="if(confirm('Desea Confirmar ? <?php echo $r_ped['docu'];?>-<?php echo $r_ped['numero'];?>'))confirmadk('<?php echo $docu;?>','<?php echo $r_ped['idnum1'];?>',this.id,'C');"  />
	       	<input type="image" id="i_rechazadk<?php echo $r_ped['idnum1'];?>" src="http://vcrxol.com/_img/ico_rechazar.png" width="25" title="Rechazar<?php echo $r_ped['docu'];?>-<?php echo $r_ped['numero'];?>"     onclick="if(confirm('Desea Rechazar ? <?php echo $r_ped['docu'];?>-<?php echo $r_ped['numero'];?>'))confirmadk('<?php echo $docu;?>','<?php echo $r_ped['idnum1'];?>',this.id,'R');"  />
        	<?php } ?>
        	<?php } ?>


	    	<?php 
		if(mb_stristr('FC.NV',substr($r_ped['docu'],0,2)) && mb_stristr('vtas.cxco',$tabla)  )
		{
		?>
                <a target="_blank" href="../lib/vrcobro0.php?idnum=<?php echo $r_ped['idnum1'];?>&numero=0" title="Cobrar <?php echo $r_ped['docu'];?>-<?php echo $r_ped['numero'];?>">
                <img src="http://vcrxol.com/_img/ico_cash.png" /></a>
		<?php } ?>


	    	<?php 
		if(mb_stristr('FP.AP',substr($r_ped['docu'],0,2)) && mb_stristr('comp.cxpa',$tabla)  )
		{
		?>
                <a target="_blank" href="../lib/vrpago0.php?idnum=<?php echo $r_ped['idnum1'];?>&numero=0" title="Pagar <?php echo $r_ped['docu'];?>-<?php echo $r_ped['numero'];?>">
                <img src="http://vcrxol.com/_img/ico_pagar.png" /></a>
		<?php } ?>

	   	<?php 
		if ($xmodif==1)
		{?>
	       	<input type="image" id="modideta" src="http://vcrxol.com/_img/ico_modify.png" width="25" title="Modificar Det.<?php echo $r_ped['docu'];?>-<?php echo $r_ped['numero'];?>"  onclick="modideta('<?php echo $docu;?>','<?php echo $r_ped['idnum1'];?>','','O');"  />
	        <?php } ?>

	
       	<?php } ?>



    </td>    

    <td align="right" style="border-left:#000000 solid 1px;">


    	<?php 
	if (!mb_stristr('CXCO.CXPA',$docu_tipo))
	{
	?>


    	<?php 
	if(!mb_stristr('CFROX',$r_ped['status']))
	{
	?>
	    	<?php 
		if(!(mb_stristr('DK',substr($r_ped['docu'],0,2)) && mb_stristr('A',$r_ped['status'])) )
		{
		?>
	       	<input type="image" id="a_pedido" src="http://vcrxol.com/_img/ico_anula.png" width="25" title="Anular <?php echo $r_ped['docu'];?>-<?php echo $r_ped['numero'];?>"  onclick="status_ox('<?php echo $docu;?>','<?php echo $r_ped['idnum1'];?>','','O');"  />
        	<?php } ?>
        <?php } ?>



    	<?php 
	if(mb_stristr('Oo',$r_ped['status']))
	{
	?>
        	<input type="image" id="e_pedido" src="http://vcrxol.com/_img/ico_elimina.png" width="25" title="Eliminar <?php echo $r_ped['docu'];?>-<?php echo $r_ped['numero'];?>"  onclick="status_ox('<?php echo $docu;?>','<?php echo $r_ped['idnum1'];?>','','X');"  />
        <?php } ?>

        <?php } ?>


	    	<?php 
		if(mb_stristr('RF',$r_ped['status']) && mb_stristr('clie',$tabla) && mb_stristr('OP1',substr($r_ped['docu'],0,3) ))
		{
		?>

		<?php		

		$xfec1r = date('Y-m-j');
		$xfec1r = strtotime ( '-3 day' , strtotime ( $xfec1r ) ) ;
		$xfec1r = date ( 'Y-m-j', $xfec1r);
		//$xfec2 = $r_ped['fecha'];
		//$xfec2= date ( 'Y-m-j' , strtotime($r_ped['idate']) );

		if ($xfec2>=$xfec1r)
		{
		?>
        	<input type="image" id="n_pedido<?php echo $r_ped['idnum1'];?>" src="http://vcrxol.com/_img/ico_statusnew.png" width="25" title="Reactivar <?php echo $r_ped['docu'];?>-<?php echo $r_ped['numero'];?>"  onclick="status_nuevo('<?php echo $docu;?>','<?php echo $r_ped['idnum1'];?>','','-');"  />
		<?php } ?>
        	
        	<?php } ?>



    </td>    
    


	<td>
	<?php $pidtxt='puni_'.$idcont; $pdefa=$r_ped['puni']; $plong=10; $pobj=1; include('vrgetval.php');?>
	</td>

    
    
    </tr>

	<?php } ?>
</table>
</div>
<?php	
}
else
{
echo '<h2>NO EXISTEN TRANSACCIONES</h2>';
}
?>

<?php	
//$sql_docu='update user0 set user_descri="GABRIEL OCTAVIO ESPINOZA ESPINOZA" where user_cedula="0913534061"';
//$res_docu=mysql_query($sql_docu,$link_vcrx);
?>


<div id="mpedido_d" style="padding-top:10px; "></div>
</div>

	
<?php } ?>