<?php 
session_start();  
header("Content-type: application/x-msexcel; charset=utf-8");

header("Content-Type: plain/text"); 
//header("Content-Disposition: attachment; filename=celectop_".date('Y-m-d-H-i').".txt"); 
header("Content-Disposition: attachment; filename=_".date('ymd_His').".xls"); 

header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);


require('../cfg/res.php');

$req_ce = '../../_lib/vrcelec1.php';

if(!mb_stristr('clie.prov',substr($_SESSION['user_vcrx_tipo'],0,4)))
{	

		if($_GET['formato']==4)
		{
			if (mb_stristr('CH',substr($_GET['docu'],0,2)) ){$req_ce='../../_lib/'.strtolower(substr($_GET['docu'],0,2)).'_formato.php';}
		}

	if($_GET['formato']!=3)
	{
		if (mb_stristr('OP.FC.NC.GR.RP.CH',substr($_GET['docu'],0,2)) )
		{
			$req_cp='../../_lib/'.strtolower(substr($_GET['docu'],0,2)).'_'.$_SESSION['user_vcrx_empr'].'.php';
			if(file_exists($req_cp)){$req_ce = $req_cp;}
		}

		if (mb_stristr('FP11',substr($_GET['docu'],0,4)) )
		{
			$req_cp='../../_lib/'.strtolower(substr($_GET['docu'],0,4)).'_'.$_SESSION['user_vcrx_empr'].'.php';
			if(file_exists($req_cp)){$req_ce = $req_cp;}
		}

	}
}






class vrcelec1
{
	
	function vrcelec1($docu,$idnum,$formato)
	{
// 		formatos
// 			1 - general
// 			2 - diario contable (directo de la tabla cont1)
// 			3 - diario contable (desde el modulo a cont.idfrom)
//			5 - egreso detallado
		
		require('../cfg/res.php');
		require('../../_lib/vrnumlet2.php');
		require('../../_lib/vr_contab.php');
// 		require('../../_lib/vr_invedocu.php');

// mysql_query('alter table docu0 add column docu_doble char(1)',$link_vcrx);
// mysql_query('alter table enti0 add column enti_adrs int(5)',$link_vcrx);
// mysql_query('alter table clie1 add column adrs int(5)',$link_vcrx);

		
mysql_query('update ctab0 set ctab_bcos="-" where ctab_bcos="" or ctab_bcos is null',$link_vcrx);

		$xcelec='vtas.comp.guia.retc.retp.cont';
		$xcelec1='vtas.retp.guia';
		$xcelec2='comp.retc';

		$usertipo=$_SESSION['user_vcrx_tipo'];
// 		$usertipo='clie';

		
// 		$sql_tabla='update enti0 set enti_descri=concat(enti_ape1," ",enti_ape2," ",enti_nom1," ",enti_nom2) where enti_descri is null and enti_ape1!=""';
// 		$res_tabla=mysql_query($sql_tabla,$link_vcrx);

		$xfontsize='font size:14px;';
// 		$xfontsize='font size:20px;';
		if (mb_stristr('apri.emar.emun',$_SESSION['user_vcrx_empr']))
		{$xfontsize='font size:18px;';}
		
		if (mb_stristr('pcs1.prs1.idm1.idmt',$_SESSION['user_vcrx_empr']))
		{$xfontsize='font size:20px;';}
		
		
		
		if (mb_stristr('cont',$docu)){$formato=2;}	

		if (mb_stristr('vtas.comp.clie.prov.inve.nomi.rolp.caja.bcos.cjte.cont',$docu))
		{
			$tabla=$docu;
			$sql_tabla='select * from '.$docu.'1 where idnum1="'.$idnum.'"';
			$res_tabla=mysql_query($sql_tabla,$link_vcrx);
			$docu = mysql_result($res_tabla,0,'docu');
		}	
		

		$sql_tabla='select * from docu0 where docu_codigo="'.$docu.'"';
		$res_tabla=mysql_query($sql_tabla,$link_vcrx);
		$tabla=mysql_result($res_tabla,0,'docu_tabla');
		$doble=mysql_result($res_tabla,0,'docu_doble');
		$tabla=strtolower($tabla);
		$cdoble=1;
		if ($doble==1) {$cdoble=2;}
				
		if ($formato==2){$tabla='cont';}

		if ($formato==3)
		{
			$sql_tabla='select * from cont1 where docu="'.$docu.'" and idfrom="'.$idnum.'" and status!="X" and status!="O" order by idnum1';
			$res_tabla=mysql_query($sql_tabla,$link_vcrx);
			if(mysql_num_rows($res_tabla)==0)
			{
				$contab=new vrcontab($docu,$idnum);
				$res_tabla=mysql_query($sql_tabla,$link_vcrx);
			}
			$idnum=mysql_result($res_tabla,0,'idnum1');
			$tabla='cont';
		}

		$xtitulo='C O M P R O B A N T E  ';
		
		if (mb_stristr($xcelec,$tabla))
		{$xtitulo='C O M P R O B A N T E  -  E L E C T R O N I C O ';}
		
		if (mb_stristr('cont',$tabla))
		{$xtitulo='D I A R I O  -  C O N T A B L E';}
		

		if (mb_stristr('clie',substr($usertipo,0,4)))
		{
			$tabla='';
			if (substr($docu,0,1)=='O')	{$tabla='clie';}
			if (substr($docu,0,1)=='F')	{$tabla='vtas';}
			if (substr($docu,0,1)=='N')	{$tabla='vtas';}
		}

		if (mb_stristr('prov',substr($usertipo,0,4)))
		{
			$tabla='';
			if (substr($docu,0,1)=='O')	{$tabla='prov';}
			if (substr($docu,0,1)=='F')	{$tabla='comp';}
			if (substr($docu,0,1)=='R')	{$tabla='retp';}
		}

		
		$sql_tran1='select *from '.$tabla.'11 where idnum1="'.$idnum.'"';

// 		if (mb_stristr('caja.bcos.cjte',$tabla))
		if (mb_stristr('vtas.clie',$tabla))
		{$sql_tran1='select *from '.$tabla.'11 left join adrs0 on adrs=adrs_codigo where idnum1="'.$idnum.'"';}
		
		if (mb_stristr('clie.prov',substr($usertipo,0,4)))
		{
// 			$sql_tran1.=' and (enti like "'.$_SESSION['user_vcrx_id'].'" or iuser like "'.$_SESSION['user_vcrx_id'].'" )';
		}

// 		echo $sql_tran1;
		$res_tran1=mysql_query($sql_tran1,$link_vcrx);
		$docu_descri=mysql_result($res_tran1,0,'docu_descri');
				
		$sql_tran2='select * from '.$tabla.'12 where idnum1="'.$idnum.'" order by item_nctlg desc, item_pctlg, item ';

		if (mb_stristr('cont',$tabla))
		{$sql_tran2='select *from '.$tabla.'12 where idnum1="'.$idnum.'" order by iddet ';}
		
		if (mb_stristr('caja.bcos.cjte',$tabla))
		{$sql_tran2='select *from '.$tabla.'12 where idnum1="'.$idnum.'" order by iddet ';}

		$nemple=0;
		if (mb_stristr('nomi.rolp',$tabla))
		{
			$sql_tran2='select *from '.$tabla.'12 where idnum1="'.$idnum.'" order by enti_descri,enti2,nvdd_posi,nvdd ';
			$sql_enti2='select distinct enti2 from '.$tabla.'2 where idnum2="'.$idnum.'"';
			$res_enti2=mysql_query($sql_enti2,$link_vcrx);
			$nemple= mysql_num_rows($res_enti2);
		}

		if (mb_stristr('retc.retp',$tabla))
		{
			$xdocu=mysql_result($res_tran1,0,'docu');
			$xptoe=mysql_result($res_tran1,0,'ptoe');
			$xnume=mysql_result($res_tran1,0,'numero');
			$xenti=mysql_result($res_tran1,0,'enti');
			$sql_tran1='select *, sum(abs(total)) as ttotal from '.$tabla.'11 where docu like "'.substr($xdocu,0,2).'%" and ptoe="'.$xptoe.'" and numero="'.$xnume.'" and enti="'.$xenti.'" order by idnum1 ';
			$res_tran1=mysql_query($sql_tran1,$link_vcrx);
			$sql_tran2='select * from '.$tabla.'12 where docu like "'.substr($xdocu,0,2).'%" and ptoe="'.$xptoe.'" and numero="'.$xnume.'" and enti="'.$xenti.'" order by idnum2, iddet ';
			$docu_descri='RETENCION';
// 			echo $sql_tran;
		}
		
		if (mb_stristr('bcos',$tabla) && $formato==5)
		{
			$sql_comp1='select docu as docum,docu_descri as docum_descri,ptonumero as ptonumer,fecha,fechadmy,total,concepto,status from comp11 where status!="O" and concat(docu,ptoe,numero,enti) in (select concat(docum,ptoem,numer,enti) as clave from '.$tabla.'12 where idnum1="'.$idnum.'" )';
			$sql_caja1='select docu as docum,docu_descri as docum_descri,ptonumero as ptonumer,fecha,fechadmy,tcant as total,concat(concepto," /",detalle) as concepto,status from caja12 where status!="O" and concat(docum,ptoem,numer,enti) in (select concat(docum,ptoem,numer,enti) as clave from '.$tabla.'12 where idnum1="'.$idnum.'" )';
			$sql_bcos1='select docu as docum,docu_descri as docum_descri,ptonumero as ptonumer,fecha,fechadmy,tcant as total,concat(concepto," /",detalle) as concepto,status from bcos12 where status!="O" and concat(docum,ptoem,numer,enti) in (select concat(docum,ptoem,numer,enti) as clave from '.$tabla.'12 where idnum1="'.$idnum.'" )';
			$sql_retp1='select docu as docum,docu_descri as docum_descri,ptonumero as ptonumer,fecha,fechadmy,tcant as total,concat(concepto," /",detalle) as concepto,status from retp12 where status!="O" and concat(docum,ptoem,numer,enti) in (select concat(docum,ptoem,numer,enti) as clave from '.$tabla.'12 where idnum1="'.$idnum.'" )';

			$sql_tran2=$sql_comp1.' union '.$sql_retp1.' union '.$sql_bcos1.' union '.$sql_caja1.' order by fecha';
		}
		
		$sql_tran3='select * from '.$tabla.'12 where idnum1="'.$idnum.'" and item like "%TRAN%"';
		$res_tran3=mysql_query($sql_tran3,$link_vcrx);
		$xenvioa=1;


		$xadrs="";
		if (mb_stristr('vtas.clie',$tabla))
		{$xadrs=mysql_result($res_tran1,0,'adrs');}
		
			$sql_adrs='select *from adrs0 where adrs_codigo="'.$xadrs.'"';
			$res_adrs=mysql_query($sql_adrs,$link_vcrx);

		if (mb_stristr('vtas.clie',$tabla))
		{
		if(mysql_num_rows($res_adrs)==0)
		{
			$sql_adrs='select *from adrs0 where adrs_codigo="'.mysql_result($res_tran1,0,'enti_adrs').'"';
			$res_adrs=mysql_query($sql_adrs,$link_vcrx);
		}
		}
		
		if(mysql_num_rows($res_adrs)==0)
		{
			$sql_adrs='select *from adrs0 where adrs_enti="'.mysql_result($res_tran1,0,'enti').'" order by adrs_defa desc';
			$res_adrs=mysql_query($sql_adrs,$link_vcrx);
		}

		if(mysql_num_rows($res_adrs)==0)
		{
			$sql_adrs='select *from enti0 where enti_codigo="'.mysql_result($res_tran1,0,'enti').'"';
			$res_adrs=mysql_query($sql_adrs,$link_vcrx);
		}
		
		if (mb_stristr('apri.emar.emun',$_SESSION['user_vcrx_empr']))
		{
		$bldn=mysql_result($res_tran1,0,'bldn');
		$sql_bldn='select * from bldn00 where bldn_codigo like "'.$bldn.'"';
		$res_bldn=mysql_query($sql_bldn,$link_vcrx);
		}
		
		if (mb_stristr('gnya.leie',$_SESSION['user_vcrx_empr']))
		{
		if (mb_stristr('vtas.clie',$tabla))
		{
                        //echo '<input type="hidden" id="hdd_tran" value="'.$sql_tran2.'">';
			$res_tran2=mysql_query($sql_tran2,$link_vcrx);
			if(mysql_num_rows($res_tran2)!=0)
			{$xdrtr=mysql_result($res_tran2,0,'drtr');}
			else{$xdrtr="";}

			if (!empty($xdrtr))
			{
			$sql_drtr='select *from enti00 where enti_codigo="'.$xdrtr.'"';
                        //echo '<input type="hidden" id="drtr" value="'.$sql_drtr.'" >';
			$res_drtr=mysql_query($sql_drtr,$link_vcrx);
                         if(mysql_num_rows($res_drtr)!=0)
                         {$xdrtr=mysql_result($res_drtr,0,'enti_descri');}
			
			}
		}
		}		

		if(mysql_num_rows($res_tran3)!=0)
		{
			$xtran=mysql_result($res_tran3,0,'puni');
			if($xtran==1)
			{
				$xenvioa=2;
				$entienvio=mysql_result($res_tran1,0,'enti_referidox');
				
			}
			else
			{
				
				$xenvioa=3;
				$entienvio=mysql_result($res_tran1,0,'enti');

			}
			if (empty($xentienvio))
			{$entienvio=mysql_result($res_tran1,0,'drtr');}
			
			$sql_envioa='select *from enti00 where enti_codigo="'.$entienvio.'"';
			$res_envioa=mysql_query($sql_envioa,$link_vcrx);
			
      if(mysql_num_rows($res_envioa)!=0)
			{
				$envio_descri=mysql_result($res_envioa,0,'enti_descri');
				$envio_ciudad=mysql_result($res_envioa,0,'prvc_descri').' /'.mysql_result($res_envioa,0,'cdad_descri');
// 				$envio_direcc=trim(mysql_result($res_envioa,0,'enti_direccion')) .' /'.trim(mysql_result($res_envioa,0,'enti_calle1')) .' /'.trim(mysql_result($res_envioa,0,'enti_callen')) .' /'.trim(mysql_result($res_envioa,0,'enti_calle2')) .' /'.trim(mysql_result($res_envioa,0,'enti_calle3'));
				$envio_direcc=trim(mysql_result($res_envioa,0,'enti_direccion'));
				if (trim(mysql_result($res_envioa,0,'enti_calle1'))!="")
				{$envio_direcc=trim(mysql_result($res_envioa,0,'enti_calle1')) .' /'.trim(mysql_result($res_envioa,0,'enti_callen')) .' /'.trim(mysql_result($res_envioa,0,'enti_calle2')) .' /'.trim(mysql_result($res_envioa,0,'enti_calle3'));}
				
				$envio_tlfn=mysql_result($res_envioa,0,'enti_telefono');
			}
			else
			{
				$envio_descri='-';
				$envio_ciudad='-';
				$envio_direcc='-';
				$envio_tlfn='-';
				
			}


		}

// 		$res_tran1=mysql_query($sql_tran1,$link_vcrx);

		$sql_emis='select * from empr1';
		$res_emis=mysql_query($sql_emis,$link_vcrx);
				
		$sql_enti='select *from enti00 where enti_codigo="'.mysql_result($res_tran1,0,'enti').'"';
		$res_enti=mysql_query($sql_enti,$link_vcrx);
		
		$lblruc1='E M I S O R';
		$lblruc2='A D Q U I R I E N T E';

		if (mb_stristr('comp.retc',$tabla))
		{
		$res_emis=mysql_query($sql_enti,$link_vcrx);
		$res_enti=mysql_query($sql_emis,$link_vcrx);
		}

		if (mb_stristr('FP11',substr($docu,0,4)))
		{
		$lblruc2='P R O V E E D O R';
		$res_emis=mysql_query($sql_emis,$link_vcrx);
		$res_enti=mysql_query($sql_enti,$link_vcrx);
		}
		
		
		if (mb_stristr('IE.IC.IV.DC',substr($docu,0,2)))
		{
// 		$res_emis=mysql_query($sql_enti,$link_vcrx);
// 		$res_enti=mysql_query($sql_emis,$link_vcrx);
		$lblruc2='C L I E N T E';
		}

		if (mb_stristr('EE.CH.DP',substr($docu,0,2)))
		{
// 		$res_emis=mysql_query($sql_enti,$link_vcrx);
// 		$res_enti=mysql_query($sql_emis,$link_vcrx);
		$lblruc2='P R O V E E D O R';
		}

		
		if($nemple>1)
		{
		$res_enti=mysql_query($sql_emis,$link_vcrx);
		}

		if (mb_stristr('retp',$tabla) or mb_stristr('CH',substr($docu,0,2)))
		{
		$lblruc2='P R O V E E D O R';
		}

		if (mb_stristr('prod',$tabla))
		{
		$lblruc2='T A L L E R';
		}

		if (mb_stristr('nomi.rolp',$tabla))
		{
		$lblruc2='E M P L E A D O';
		}
		
		//echo $sql_enti;
		
		$drtr=0;
		$sql_drtr='select *from drtr0 where left(enti_codigo,10) like "'.$_SESSION['user_vcrx_id'].'%"';
		$res_drtr=mysql_query($sql_drtr,$link_vcrx);
	
		if (mb_stristr('gnya.leie',substr($_SESSION['user_vcrx_empr'],0,4)))
		{
			if (mysql_num_rows($res_drtr)!=0)
			{
			$drtr=1;
			}
		}

		$referidox=mysql_result($res_enti,0,'enti_referidox');
		if($referidox!="")
		{
		$sql_drtr='select *from enti0 where enti_codigo="'.$referidox.'"';
		$res_drtr=mysql_query($sql_drtr,$link_vcrx);
		}

		if (mb_stristr($xcelec1.$xcelec2,$tabla))
		{$html1 = "../celec1/".mysql_result($res_tran1,0,'claveacc').".html"  ;}
		else
		{$html1 = "../celec1/".$tabla.mysql_result($res_tran1,0,'idnum1').".html"  ;}

		ob_start();		

?>




<html>

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


	
<?php 
	for($xcont=1;$xcont<=$cdoble;$xcont++)
	{
?>
	
	
<div style="height:50px;"></div>
<!-- <div align="center"> -->
<div align="center" style="width:1150px; font-size:12px;">
<div align="center" style=" border:#000 solid 1px; background: #F7F7F7; margin:2px; <?php echo $xfontsize; ?>">
	<strong><?php echo $xtitulo;?></strong>
	</div>
<table width="100%" cellspacing="0" cellpadding="2">
<tr valign="top">
<td width="50%">
<!----++++++++++------>
<table border="1" width="100%" cellpadding="2" cellspacing="0" style="border-collapse:collapse;<?php echo $xfontsize; ?>;">
<tr>
	<th  style="background: #F7F7F7;" colspan="2"><?php echo $lblruc1; ?></th>
<!-- 	<th></th> -->
</tr>
<tr>
	<?php if (strlen(mysql_result($res_emis,0,'enti_codigo'))==10) { ?>
	<td width="30%">CEDULA</td>
	<?php }else{ ?>
	<td width="30%">RUC</td>
	<?php }?>
	<td><?php echo mysql_result($res_emis,0,'enti_codigo');?></td>
</tr>
<tr>
	<td>RAZON SOCIAL</td>
	<td><?php echo mysql_result($res_emis,0,'enti_razsoc');?></td>
</tr>
<tr>
	<td>NOMBRE COMERCIAL</td>
	<td><?php echo mysql_result($res_emis,0,'enti_nomcom');?></td>
</tr>
<tr>
	<td>MATRIZ</td>
	<td><?php echo mysql_result($res_emis,0,'enti_calle1').' /'.mysql_result($res_emis,0,'enti_callen').' /'.mysql_result($res_emis,0,'enti_calle2');?></td>
</tr>
<tr>
	<td>TELEFONO</td>
	<td><?php echo mysql_result($res_emis,0,'enti_telefono');?></td>
</tr>
<tr>
	<td>E-MAIL</td>
	<td><a href="mailto:<?php echo mysql_result($res_emis,0,'enti_email');?>?subject=<?php echo mysql_result($res_tran1,0,'docu').'-'.mysql_result($res_tran1,0,'ptonumero');?>">
	<?php echo mysql_result($res_emis,0,'enti_email');?></a>
    </td>
</tr>
<?php if(mysql_result($res_emis,0,'enti_pcont')=="1") {	?>
<tr>
	<td>OBLIG.CONTABIL.</td>
	<td><?php if(mysql_result($res_emis,0,'enti_pcont')=="1"){echo 'SI';}else{echo 'NO';};?></td>
</tr>
<?php } ?>	
</table>




<!----++++++++++------>
</td>
<td>
<!----++++++++++------>
<table border="1" width="100%" cellspacing="0" cellpadding="2" style="border-collapse:collapse;<?php echo $xfontsize; ?>">
<tr>
	<th width="60%"  style="background: #F7F7F7;" colspan="2">DATOS DEL COMPROBANTE</th>
<!-- 	<th></th>     -->
</tr>
<tr>
	<td align="right"   >TIPO :</td>
	<td><?php echo $docu_descri;?></td>
</tr>


<tr>
	<td align="right"><strong>NUMERO :</strong></td>
	<td><strong><?php echo mysql_result($res_tran1,0,'ptoe').'-'.mysql_result($res_tran1,0,'numero');?></strong></td>
</tr>
<tr>
	<td align="right">FECHA :</td>
	<td><?php echo mysql_result($res_tran1,0,'fechadmy');?></td>
</tr>


<?php
if (mb_stristr('vtas.clie.comp.prov',$tabla))
{
?>
<tr>
	<td align="right">VENCE:</td>
    <td><?php echo mysql_result($res_tran1,0,'vencedmy');?></td>
</tr>
<?php
}
?>

<?php
if (mb_stristr('inve.prod',$tabla))
{
$sql_bode='select * from bode0 where bode_codigo="'.mysql_result($res_tran1,0,'bode').'"';
$res_bode=mysql_query($sql_bode,$link_vcrx);
$xbode1=mysql_result($res_bode,0,'bode_descri');

?>
<tr>
	<td align="right">BODEGA:</td>
    <td><?php echo mysql_result($res_tran1,0,'bode')." - ".$xbode1;?></td>
</tr>
<?php
}
?>

<?php
if (mb_stristr('inve',$tabla))
{
$sql_bode='select * from bode0 where bode_codigo="'.mysql_result($res_tran1,0,'tobode').'"';
$res_bode=mysql_query($sql_bode,$link_vcrx);
if(mysql_num_rows($res_bode)!=0)
{$xbode2=mysql_result($res_bode,0,'bode_descri');}
?>
<tr>
	<?php
	if (substr($docu,0,1)=='I')
	{ 	
	?>
	<td align="right">DESDE:</td>
	<?php
	}else{
	?>
	<td align="right">PARA :</td>
	<?php } ?>
    <td><?php echo mysql_result($res_tran1,0,'tobode')." - ".$xbode2;?></td>
</tr>
<?php
}
?>
	
	
<?php
if (mb_stristr('caja',$tabla))
{
?>
<tr>
		<td align="right">CAJA :</td>
    <td><?php echo mysql_result($res_tran1,0,'caja').'-'.mysql_result($res_tran1,0,'caja_descri');?></td>
</tr>
<?php
}
?>
	
<?php
if (mb_stristr('bcos',$tabla))
{
?>
<tr>
		<td align="right">CTA. BANCARIA :</td>
    <td><?php echo mysql_result($res_tran1,0,'ctab').'-'.mysql_result($res_tran1,0,'ctab_descri');?></td>
</tr>
<?php
}
?>
	



<?php if(mb_stristr($xcelec1.$xcelec2,$tabla)) {	?>
<?php if(mysql_result($res_tran1,0,'claveacc').mysql_result($res_tran1,0,'atrznume')!=''){ ?>
<tr>
	<td align="right">CLAVE DE ACCESO :</td>
	<td><?php echo mysql_result($res_tran1,0,'claveacc');?></td>
</tr>
<tr>
	<td align="right">AUTORIZACION :</td>
	<td><?php echo mysql_result($res_tran1,0,'atrznume');?></td>
</tr>
<tr>
	<td align="right">VALIDADOR :</td>
	<td>
       <a href="https://declaraciones.sri.gob.ec/comprobantes-electronicos-internet/publico/validezComprobantes.jsf" target="_blank"> PORTAL SRI</a>
    </td>
</tr>
<?php }?>
<?php }?>

<tr>
	<td align="right">STATUS :</td>
	<td><?php if(mb_stristr('XO',mysql_result($res_tran1,0,'status'))){echo '<font color="red" size="6" >'.'<strong>';} ?><?php echo mysql_result($res_tran1,0,'stat_descri');?></td>
</tr>

<?php
if (mb_stristr('sist.supe.admi',$usertipo))
{
?>	
<tr>
	<td align="right">ID :</td>
	<td><?php echo $idnum;?></td>
</tr>
<?php
}
?>


</table>
<!----++++++++++------>
</td>
</tr>

<tr valign="top">

<?php
$xdireccion=trim(mysql_result($res_enti,0,'enti_direccion'));
if(mysql_result($res_enti,0,'enti_calle1')!="")
{$xdireccion=mysql_result($res_enti,0,'enti_calle1').' /'.mysql_result($res_enti,0,'enti_callen').' /'.mysql_result($res_enti,0,'enti_calle2').' /'.mysql_result($res_enti,0,'enti_calle3');}

$xemail=mysql_result($res_enti,0,'enti_email');	 
$xcontacto=mysql_result($res_enti,0,'enti_contacto');	 
?>
	
	
<td>
<!----++++++++++------>

<?php if (mb_stristr('vtas.clie.prod.retp.comp.caja.bcos',$tabla) || mb_stristr('CH',substr($docu,0,2))) { ?>
<table border="1" width="100%" cellspacing="0" cellpadding="2" style="border-collapse:collapse;<?php echo $xfontsize; ?>">
<tr align="center">
	<th  style="background: #F7F7F7;" colspan="2"><?php echo $lblruc2; ?></th>
<!-- 	<th></th> -->
</tr>
<tr>
	<?php if (strlen(mysql_result($res_enti,0,'enti_codigo'))==10) { ?>
	<td width="30%">CEDULA</td>
	<?php }else{ ?>
	<td width="30%">RUC</td>
	<?php }?>
	
	<td>
	<?php 
		if(mysql_result($res_enti,0,'enti_struc')=='A')
		{echo substr(mysql_result($res_enti,0,'enti_codigo'),0,10).'001';}
		else
		{echo mysql_result($res_enti,0,'enti_codigo');}
	?>
	</td>
</tr>
<tr>
	<?php	if (mysql_result($res_enti,0,'enti_razsoc')!="")	{	?>
		<td>RAZON SOCIAL</td>
		<td><?php echo mysql_result($res_enti,0,'enti_razsoc');?></td>
	<?php	}	else	{	?>
		<td>RAZON SOCIAL</td>
		<td><?php echo mysql_result($res_enti,0,'enti_descri');?></td>
	<?php	}	?>


</tr>
<?php if(mysql_result($res_enti,0,'enti_nomcom')<>""){?>
<tr>
	<td>NOMBRE COMERCIAL</td>
	<td><?php echo mysql_result($res_enti,0,'enti_nomcom');?></td>
</tr>
<?php }?>

<?php if (mb_stristr('vtas.clie.prod.retp',$tabla) || mb_stristr('CH',substr($docu,0,2)) || mb_stristr('FP11',substr($docu,0,4))){?>

<tr>
	<td>PROV /CIUDAD</td>
	<td><?php echo mysql_result($res_enti,0,'prvc_descri').' /'.mysql_result($res_enti,0,'cdad_descri');?></td>
</tr>
<tr>
	<td>DIRECCION</td>
	<td>
	<?php echo $xdireccion;?>
	</td>
</tr>
<tr>
	<td>TELEFONO</td>
	<td><?php echo mysql_result($res_enti,0,'enti_telefono');?></td>
</tr>
<?php if ($xemail!=""){?>	
<tr>
	<td>E-MAIL</td>
	<td><?php echo mysql_result($res_enti,0,'enti_email');?></td>
</tr>
<?php }?>
<?php if ($xcontacto!=""){?>	
<tr>
	<td>CONTACTO</td>
	<td><?php echo $xcontacto;?></td>
</tr>
<?php }?>

<?php }?>
	
	
	
</table>
<br/>
<!----++++++++++------>
<?php } ?>

<?php if (mb_stristr('nomi.rolp',$tabla) ) { ?>
<table border="1" width="100%" cellspacing="0" cellpadding="2" style="border-collapse:collapse;<?php echo $xfontsize; ?>">
<tr align="center">
	<th width="40%" style="background: #F7F7F7;"><?php echo $lblruc2; ?></th>
	<th></th>
</tr>
<tr>
	<td>C.I.</td>
	<td>
	<?php 
	echo mysql_result($res_enti,0,'enti_codigo');
	?>
	</td>
</tr>
<tr>
	<td>NOMBRE</td>
	<td>
	<?php 
	echo mysql_result($res_enti,0,'enti_descri');
	?>
	</td>
</tr>
<!-- 
<tr>
	<td>PROV /CIUDAD</td>
	<td><?php echo mysql_result($res_enti,0,'prvc_descri').' /'.mysql_result($res_enti,0,'cdad_descri');?></td>
</tr>
 -->
<tr>
	<td>DIRECCION</td>
	<td>
	<?php echo $xdireccion; ?>	
	<?php 
// 	echo  trim(mysql_result($res_enti,0,'enti_direccion')).' /'.mysql_result($res_enti,0,'enti_calle1').' /'.mysql_result($res_enti,0,'enti_callen').' /'.mysql_result($res_enti,0,'enti_calle2').' /'.mysql_result($res_enti,0,'enti_calle3');
		?>
	</td>
</tr>
<tr>
	<td>TELEFONO</td>
	<td><?php echo mysql_result($res_enti,0,'enti_telefono');?></td>
</tr>
<tr>
	<td>E-MAIL</td>
	<td><?php echo mysql_result($res_enti,0,'enti_email');?></td>
</tr>
<!-- 
<tr>
	<td>CONTACTO</td>
	<td><?php echo mysql_result($res_enti,0,'enti_contacto');?></td>
</tr>
 -->
</table>
<br/>
<!----++++++++++------>
<?php } ?>

<!----++++++++++------>
	
<table border="1" width="100%" cellspacing="0" cellpadding="2" style="border-collapse:collapse;<?php echo $xfontsize; ?>">
<tr align="center">
	<th  style="background: #F7F7F7;" colspan="2" >INFORMACION ADICIONAL</th>
<!-- 	<th></th> -->
</tr>

<?php
if (mb_stristr('comp.prov',$tabla))
{
if(mysql_result($res_tran1,0,'suco')!="")
{	
?>
	<tr style="font-size:12px;">
	<td>SUSTENTO DE COMPROBANTE</td>
	<td style="font-size:10px;"><?php echo mysql_result($res_tran1,0,'suco').' -'.mysql_result($res_tran1,0,'suco_descri');?></td>
	<tr/>
<?php
}
}	
?>

<?php if (mb_stristr('cont',$tabla)) { ?>
	<tr>
	<td>ENTIDAD</td>
	<td><?php echo mysql_result($res_tran1,0,'enti_descri');?></td>
	<tr/>
<?php } ?>
	
<?php if(mysql_result($res_tran1,0,'concepto')!="") { ?>
	<tr>
	<td>CONCEPTO</td>
	<td><?php echo mysql_result($res_tran1,0,'concepto');?></td>
	<tr/>
<?php } ?>

<?php
if(mb_stristr('bcos',$tabla))	
{	
if(mysql_result($res_tran1,0,'benefic')!="")
{
?>
	<tr>
	<td>BENEFICIARIO</td>
	<td><?php echo mysql_result($res_tran1,0,'benefic');?></td>
	<tr/>
<?php
}}
?>

<?php if (mb_stristr('apri.emar.emun',$_SESSION['user_vcrx_empr'])){ ?>
<?php if (mb_stristr('vtas.comp.bcos',$tabla)) {?>
<?php	if (mysql_num_rows($res_bldn)!=0){ ?>
<?php 
			$sql_nave='select * from nave0 where nave_codigo="'.mysql_result($res_bldn,0,'bldn_nave1').'"';
			$res_nave=mysql_query($sql_nave,$link_vcrx);
			$nave1 = mysql_result($res_nave,0,'nave_descri');

			$sql_port='select * from port0 where port_codigo="'.mysql_result($res_bldn,0,'bldn_port1').'"';
			$res_port=mysql_query($sql_port,$link_vcrx);
			$port1 = mysql_result($res_port,0,'port_descri');

			$sql_port='select * from port0 where port_codigo="'.mysql_result($res_bldn,0,'bldn_port2').'"';
			$res_port=mysql_query($sql_port,$link_vcrx);
			$port2 = mysql_result($res_port,0,'port_descri');
	?>

		<tr>
		<td>NUMERO B/L</td>
		<td ><?php echo mysql_result($res_bldn,0,'bldn_master').'/'.mysql_result($res_bldn,0,'bldn_house');?></td>
		</tr>
		<tr>
		<td>CONSIGNATARIO</td>
		<td ><?php echo mysql_result($res_bldn,0,'enti_descri');?></td>
		</tr>
		<tr>
		<tr>
		<td>JOB</td>
		<td ><?php echo mysql_result($res_bldn,0,'bldn_job');?></td>
		</tr>
		<tr>
		<td>NAVE</td>
<!-- 		<td ><?php echo mysql_result($res_bldn,0,'bldn_nave1').'/'.mysql_result($res_bldn,0,'bldn_viaje');?></td> -->
		<td ><?php echo $nave1.'/'.mysql_result($res_bldn,0,'bldn_viaje');?></td>
		</tr>
		<tr>
		<td>ARRIBO</td>
		<td ><?php echo mysql_result($res_bldn,0,'bldn_fecha2');?></td>
		</tr>
		<tr>
		<td>PTO. ORIGEN</td>
		<td ><?php echo $port1;?></td>
		</tr>
		<tr>
		<td>PTO. DESTINO</td>
		<td ><?php echo $port2;?></td>
		</tr>
		<tr>
		<td>MERCADERIA</td>
		<td ><?php echo mysql_result($res_bldn,0,'bldn_carga');?></td>
		</tr>
		<tr>
		<td>PESO</td>
		<td ><?php echo number_format(mysql_result($res_bldn,0,'bldn_peso'),2).' KG';?></td>
		</tr>
<?php } ?>
<?php } ?>
<?php } ?>
	
	
	
<?php if (mb_stristr('gnya',$_SESSION['user_vcrx_empr'])) { ?>
<?php if (mb_stristr('vtas.clie',$tabla)) { ?>
	
<?php if($xenvioa==1) { ?>
<tr>
	<td>DIRECTOR:</td>
    <td><?php echo $xdrtr;?></td>
</tr>
<?php	} ?>

<?php	if($xenvioa!=1) { ?>
<tr>
	<td width="30%">ENVIAR A DIRECTOR:</td>
    <td><?php echo $envio_descri;?></td>
</tr>
<tr>
	<td>CIUDAD ENVIO:</td>
    <td><?php echo $envio_ciudad;?></td>
</tr>
<tr>
	<td>DIRECCION ENVIO:</td>
    <td><?php echo $envio_direcc;?></td>
</tr>
<tr>
	<td>TELEFONO ENVIO:</td>
    <td><?php echo $envio_tlfn;?></td>
</tr>
<?php	} ?>

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


</table>
<!----++++++++++------>
	
	
</td>




<td>
<!----++++++++++------>
<table border="1" width="100%" cellspacing="0" cellpadding="2" style="border-collapse:collapse;<?php echo $xfontsize; ?>">
<tr align="center">
	<th width="70%"   style="background: #F7F7F7;" colspan="2">R E S U M E N</th>
<!-- 	<th></th> -->
</tr>


<?php
if (mb_stristr('vtas.clie',$tabla))
{
?>
<tr align="right">
	<td>UNIDADES :</td>
	<td><?php echo abs(mysql_result($res_tran1,0,'tbien'));?></td>
</tr>
<?php
}
?>

<?php
if (mb_stristr('comp.prov.inve.prod',$tabla))
{
?>
<tr align="right">
	<td>UNIDADES :</td>
	<td><?php echo abs(mysql_result($res_tran1,0,'tcant'));?></td>
</tr>
<?php
}
?>


<?php
if (mb_stristr('vtas.clie.comp.prov',$tabla))
{
?>

<tr align="right">
	<td>SUBTOTAL :</td>
	<td><?php echo number_format(mysql_result($res_tran1,0,'tsubt'),2);?></td>
</tr>



<?php
if(mysql_result($res_tran1,0,'tdcto')!=0)
{
?>

<tr align="right">
	<td>DESCUENTO <?php echo number_format(mysql_result($res_tran1,0,'dcto'),2);?>%:</td>
	<td><?php echo number_format(mysql_result($res_tran1,0,'tdcto'),2);?></td>
</tr>
<?php
}
?>



<?php
if(mysql_result($res_tran1,0,'tsubtice')>0)
{
?>
<tr align="right">
	<td>SUBTOTAL ICE <?php echo number_format(mysql_result($res_tran1,0,'ice'),0);?>%:</td>
	<td><?php echo number_format(mysql_result($res_tran1,0,'tsubtice'),2);?></td>
</tr>
<tr align="right">
	<td>ICE :</td>
	<td><?php echo number_format(mysql_result($res_tran1,0,'tice'),2);?></td>
</tr>

<?php } ?>

<tr align="right">
	<td>SUBTOTAL IVA 0% :</td>
	<td><?php echo number_format(mysql_result($res_tran1,0,'tsubtiva0'),2);?></td>
</tr>

<?php
if(mysql_result($res_tran1,0,'tiva')>0)
{ ?>
<tr align="right">
	<td>SUBTOTAL IVA <?php echo number_format(mysql_result($res_tran1,0,'iva'),0);?>% :</td>
	<td><?php echo number_format(mysql_result($res_tran1,0,'tsubtiva'),2);?></td>
</tr>
<tr align="right">
	<td>IVA <?php echo number_format(mysql_result($res_tran1,0,'iva'),0);?>% :</td>
	<td><?php echo number_format(mysql_result($res_tran1,0,'tiva'),2);?></td>
</tr>
<?php } ?>

<?php
if(mysql_result($res_tran1,0,'tirbp')>0)
{ ?>
<tr align="right">
	<td>IRBP :</td>
	<td><?php echo number_format(mysql_result($res_tran1,0,'tirbp'),2);?></td>
</tr>
<?php } ?>


<?php } ?>

<?php if (mb_stristr('cont',$tabla)) { ?>
<tr align="right">
	<td><strong><font size="4">
		<?php 
 			if (mysql_result($res_tran1,0,'diferencia')==0)
			{echo 'VALOR TOTAL :';}
			else{echo 'DIFERENCIA :';}
		?>
		</font>
	</strong></td>
	<td><strong><font size="4">
		<?php 
 			if (mysql_result($res_tran1,0,'diferencia')==0)
			{echo number_format(abs(mysql_result($res_tran1,0,'total')/2),2);}
			else{echo '<font color="red">'.number_format(abs(mysql_result($res_tran1,0,'total')),2).'</font>';}
		?>
		</font>
	</strong></td>
</tr>
<?php } ?>

	
<?php
if (mb_stristr('vtas.clie.comp.prov.inve.prod',$tabla))
{ ?>
<tr align="right">
	<td><strong><font size="4">VALOR TOTAL :</strong></td>
	<td><strong><font size="4"><?php echo number_format(abs(mysql_result($res_tran1,0,'total')),2);?></strong></td>
</tr>
<?php }?>

<?php
if (mb_stristr('caja.bcos',$tabla))
{ ?>
<tr align="right">
	<td><strong><font size="4">VALOR :</strong></td>
	<td><strong><font size="4"><?php echo number_format(abs(mysql_result($res_tran1,0,'total')),2);?></strong></td>
</tr>
<?php }?>

<?php
if (mb_stristr('retc.retp',$tabla))
{ ?>
<tr align="right">
	<td><strong><font size="4">VALOR TOTAL :</strong></td>
	<td><strong><font size="4"><?php echo number_format(abs(mysql_result($res_tran1,0,'ttotal')),2);?></strong></td>
</tr>
<?php }?>

<?php
if (mb_stristr('nomi.rolp',$tabla))
{ ?>
<tr align="right">
	<td>INGRESOS :</td>
	<td><?php echo number_format(abs(mysql_result($res_tran1,0,'tingreso')),2);?></td>
</tr>
<tr align="right">
	<td>EGRESOS :</strong></td>
	<td><?php echo number_format(abs(mysql_result($res_tran1,0,'tegreso')),2);?></td>
</tr>
<tr align="right">
	<td><strong><font size="4">TOTAL :</strong></td>
	<td><strong><font size="4"><?php echo number_format(abs(mysql_result($res_tran1,0,'total')),2);?></strong></td>
</tr>
<?php }?>

	

<?php
//if (mysql_num_rows($res_tran1)!=0)
if (mb_stristr('vtas.clie',$tabla))
	{if (mysql_result($res_tran1,0,'tcomi')!=0 )
		{if(mb_stristr('gnya.leie',$_SESSION['user_vcrx_empr']) && ($drtr==1 || mb_stristr('admi',substr($usertipo,0,4))))
			{?>
			<tr><td></td></tr>
			<tr align="right">
			<td>DCTO.DIRECTOR : <?php echo number_format(mysql_result($res_tran1,0,'comi'),0);?>%:</td>
			<td><?php echo number_format(mysql_result($res_tran1,0,'tcomi'),2);?></td>
			</tr>
			<tr align="right">
			<td><strong><font size="4">VALOR A DEPOSITAR: </td>
			<td><strong><font size="4"><?php echo number_format(mysql_result($res_tran1,0,'total')-mysql_result($res_tran1,0,'tcomi'),2);?></td>
			</tr>
		<?php
			}	
		}
	}
	?>

<?php if (mb_stristr('CH',substr($docu,0,2)) && ($formato==1 || $formato==5) ) { ?>
	<tr class="no-print">
	<td></td>
	<td align="right">
		<a href="../lib/celectop1.php?docu=<?php echo $docu; ?>&idnum=<?php echo $idnum; ?>&formato=4" target="_blank">
			<?php echo '<span title="Imprimir">IMPRIMIR CHEQUE</span>';?>
		</a>
	</td>
	</tr>
	<?php	if ($formato!=5)	{	?>
	<tr class="no-print">
	<td></td>
	<td align="right">
		<a href="../lib/celectop1.php?docu=<?php echo $docu; ?>&idnum=<?php echo $idnum; ?>&formato=5" target="_blank">
			<?php echo '<span title="Imprimir">EGRESO DETALLADO</span>';?>
		</a>
	</td>
	</tr>
	<?php } ?>
<?php } ?>

</table>

<!----++++++++++------>
</td>
</tr>
<tr valign="top">
<td>
<!----++++++++++------>
<!----++++++++++------>
</td>

<td>
<!----++++++++++------>
<!-- 
<table border="1" width="100%" cellspacing="0" cellpadding="2" style="border-collapse:collapse">
<tr align="center">
	<th width="40%" style="background: #F7F7F7;">OTROS</th>
	<th></th>
</tr>
</table>	
	 -->
</td>



	
</tr>
</table>

<br>
<table border="1" width="100%" cellpadding="2" cellspacing="0" style="border-collapse:collapse;<?php echo $xfontsize; ?>">
<tr align="center">
	<th width="200" style="background: #F7F7F7;">D E T A L L E</th>
	<th></th>
</tr>
</table>
<table border="0" width="100%" cellpadding="2" cellspacing="0" style="border-collapse:collapse;<?php echo $xfontsize; ?>">
<tr align="center" style="background: #F7F7F7; border-top:solid 1px#000;border-bottom:solid 1px#000">


	
<?php
if (mb_stristr('cont',$tabla))
{
?>

	<th>CUENTA</th>
	<th>DESCRIPCION</th>
	<th>DEBITO</th>
	<th>CREDITO</th>
	<th>CENTRO.S</th>
	<th>DETALLE</th>
	<th><?php if (mb_stristr('FP.RP.RC',substr($docu,0,2)) ) {echo 'CAIR';}?></th>
	<th><?php if (mb_stristr('RO',substr($docu,0,2)) ) {echo 'ENTIDAD';}?></th>
	<th><?php if (mb_stristr('FC.FP.IB.EB',substr($docu,0,2)) ) {echo 'ITEM';}?></th>

	
<?php }?>

	
	
	
<?php
if (mb_stristr('vtas.clie.comp.prov.inve.prod',$tabla))
{
?>
	<th><?php if(mb_stristr('admi',substr($usertipo,0,4))){echo 'Pag';}?></th>	
	<th>ITEM</th>
	<th>DESCRIPCION</th>

	<th>CANT.</th>
	<th>UNIT.</th>
	<th>SUBT.</th>

	
	
	
<?php
if (mb_stristr('vtas.clie.comp.prov',$tabla))
{
?>

<?php
if(mysql_result($res_tran1,0,'tdcto')>0)
{
?>
	<th>DESC.</th>
<?php }?>	
<?php
if(mysql_result($res_tran1,0,'tice')>0)
{
?>
	<th>ICE</th>
<?php }?>
	
	<th>IVA</th>

<?php
if(mysql_result($res_tran1,0,'tirbp')>0)
{
?>
	<th>IRBP</th>
<?php }?>
<?php }?>
	
	<th>TOTAL</th>
	<th>DETALLE</th>

<?php
if (mb_stristr('comp.prov',$tabla))
{
?>
	<th>CAIR</th>
	<th>CUENTA</th>
<?php
}
?>

<?php }?>

	
	
<?php
if (mb_stristr('caja.bcos',$tabla))
{
?>

	<th>DOCU</th>
	<th>DESCRIPCION</th>
	<th >NUMERO</th>
	<th >FECHA</th>
	<th >VALOR</th>
	<th >CONCEPTO</th>

<?php }?>
	
	
<?php
if (mb_stristr('retc.retp',$tabla))
{
?>

	<th>DOCU</th>
	<th>DESCRIPCION</th>
	<th width="180px">NUMERO</th>
	<th width="50px">AÑO</th>
	<th width="180px">BASE</th>
	<th width="50px">CAIR</th>
	<th width="50px">%</th>
	<th width="180px">VALOR</th>

<?php }?>
	
<?php
if (mb_stristr('nomi.rolp',$tabla))
{
?>

	<th>C.I.</th>
	<th>NOMBRE</th>
	<th>NVDD</th>
	<th>DESCRIPCION</th>
	<th>CANT</th>
	<th>V.UNIT.</th>
	<th>INGRESO</th>
	<th>EGRESO</th>
	<th>PROV 1</th>
	<th>PROV 2</th>

<?php }?>
	
</tr>


<?php
$filax=0;
$res_tran2=mysql_query($sql_tran2,$link_vcrx);
$duni=2;
// 	echo $sql_tran2;	
while($r_tran2=mysql_fetch_assoc($res_tran2))
{
$duni=$r_tran2['item_duni'];
?>
<tr valign="top" style=" <?php if($filax==3){echo 'border-top:dotted 1px #000;';$filax=1;}else{$filax++;} ?>" >

<?php
if (mb_stristr('cont',$tabla))
{
?>
	<td align="left"><?php echo $r_tran2['ctas'];?></td>
	<td align="left"><?php echo $r_tran2['ctas_descri'];?></td>
	<td align="right"><?php echo number_format($r_tran2['tdebito'],2);?></td>
	<td align="right"><?php echo number_format($r_tran2['tcredito'],2);?></td>
	<td align="left"><?php echo $r_tran2['csub'];?></td>
	<td align="left">&nbsp;<?php echo $r_tran2['detalle'];?></td>
	<td align="center"><?php echo $r_tran2['cair'];?></td>
	<td align="center"><?php //if (mb_stristr('FP.RP.RC',substr($docu,0,2)) ) {echo 'CAIR';}?></td>
	
	<td align="left">
		<?php if (mb_stristr('RO',substr($docu,0,2)) ) {echo $r_tran2['enti_descri'];}?>
		<?php //echo $r_tran2['enti_descri'];?>
	</td>
	<td align="left"><?php echo $r_tran2['item_descri'];?></td>
<?php
}?>
	
	
	
<?php
if (mb_stristr('vtas.clie.comp.prov.inve.prod',$tabla))
{
?>

    	<td align="center"><?php if(mb_stristr('admi',substr($usertipo,0,4))){ echo $r_tran2['item_pctlg']; }?></td>	
	<td><?php echo $r_tran2['item_codigov'];?></td>
	<td><?php echo $r_tran2['item_descri'];?></td>
	
	
	<?php
		if ($r_tran2['cant']==0 && substr($r_tran2['docu'],0,2)=='OP')
		{
		?>
			<td align="right"><?php echo '*N/D* '.number_format($r_tran2['cantio'],$duni);?></td>
		<?php
		}
		else
		{
		?>
			<td align="right"><?php echo number_format($r_tran2['cant'],$duni);?></td>
		<?php
		}
		?>
	
	
	<td align="right"><?php echo number_format($r_tran2['puni'],2);?></td>
	<td align="right"><?php echo number_format(abs($r_tran2['tsubt']),2);?></td>


	
<?php
if (mb_stristr('vtas.clie.comp.prov',$tabla))
{
?>
<?php
if(mysql_result($res_tran1,0,'tdcto')>0)
{
?>
	<td align="right"><?php echo number_format($r_tran2['tdcto'],2);?></td>
<?php
}
?>	
<?php
if(mysql_result($res_tran1,0,'tice')>0)
{
?>
	<td align="right"><?php echo number_format($r_tran2['tice'],2);?></td>
<?php } ?>	

	<td align="right"><?php echo number_format($r_tran2['tiva'],2);?></td>

<?php
if(mysql_result($res_tran1,0,'tirbp')>0)
{
?>
	<td align="right"><?php echo number_format($r_tran2['tirbp'],2);?></td>
<?php } ?>	
<?php }?>
	
	
	
	<td align="right"><?php echo number_format(abs($r_tran2['total']),2);?></td>
	<td>&nbsp;<?php echo $r_tran2['detalle'].'/'.$r_tran2['cambio'];?></td>

		<?php
		if (mb_stristr('comp.prov',$tabla))
		{
		?>
			<td align="center"><?php echo $r_tran2['cair'];?></td>
			<td align="left"><?php echo $r_tran2['ctas'].' - '. $r_tran2['ctas_descri'];?></td>
		<?php
		}
		?>
	
	
	<?php
}?>

	
<?php
if (mb_stristr('caja.bcos',$tabla))
{
?>

	<td align="center"><?php echo $r_tran2['docum'];?></td>
	<td><?php echo $r_tran2['docum_descri'];?></td>
	<td align="center"><?php echo $r_tran2['ptonumer'];?></td>
	<td align="center"><?php echo $r_tran2['fechadmy'];?></td>
	<td align="right"><?php echo number_format(abs($r_tran2['total']),2);?></td>
	<td align="left"><?php echo $r_tran2['concepto'];?></td>
	
<?php }?>

	
	
<?php
if (mb_stristr('retc.retp',$tabla))
{
?>

	<td align="center"><?php echo $r_tran2['docum'];?></td>
	<td><?php echo $r_tran2['docum_descri'];?></td>
	<td align="center"><?php echo $r_tran2['ptonumer'];?></td>
	<td align="center"><?php echo $r_tran2['fanio'];?></td>
	<td align="right"><?php echo number_format($r_tran2['cant'],2);?></td>
	<td align="center"><?php echo $r_tran2['cair'];?></td>
	<td align="right"><?php echo number_format($r_tran2['puni'],2);?></td>
	<td align="right"><?php echo number_format(abs($r_tran2['total']),2);?></td>
	
<?php }?>

<?php
if (mb_stristr('nomi.rolp',$tabla))
{
?>

	<td align="center"><?php echo $r_tran2['enti2'];?></td>
	<td><?php echo $r_tran2['enti_descri'];?></td>
	<td align="center"><?php echo $r_tran2['nvdd'];?></td>
	<td><?php echo $r_tran2['nvdd_descri'];?></td>
	<td align="right"><?php echo number_format($r_tran2['cant'],2);?></td>
	<td align="right"><?php echo number_format($r_tran2['puni'],2);?></td>
	<td align="right"><?php echo number_format($r_tran2['tingreso'],2);?></td>
	<td align="right"><?php echo number_format($r_tran2['tegreso'],2);?></td>
	<td align="right"><?php echo number_format($r_tran2['tprovi1'],2);?></td>
	<td align="right"><?php echo number_format($r_tran2['tprovi2'],2);?></td>
	
<?php }?>

</tr>

<?php }?>

<tr align="right" style="font-weight:bolder;border-top:solid 1px#000">


<?php
if (mb_stristr('cont',$tabla))
{
?>
	<td></td>
	<td align="center">T O T A L E S</td>
	<td>&nbsp;<?php echo number_format(mysql_result($res_tran1,0,'tdebito'),2);?></td>
	<td>&nbsp;<?php echo number_format(mysql_result($res_tran1,0,'tcredito'),2);?></td>

<?php } ?>

<?php
if (mb_stristr('vtas.clie.comp.prov',$tabla))
{
?>

	<td></td>
	<td></td>
	<td align="center">T O T A L E S</td>
	<td>&nbsp;<?php echo number_format(mysql_result($res_tran1,0,'tcant'),$duni);?></td>
	<td></td>
	<td>&nbsp;<?php echo number_format(mysql_result($res_tran1,0,'tsubt'),2);?></td>

<?php
if(mysql_result($res_tran1,0,'tdcto')>0)
{
?>
	<td>&nbsp;<?php echo number_format(mysql_result($res_tran1,0,'tdcto'),2);?></td>
<?php
}
?>
<?php
if(mysql_result($res_tran1,0,'tice')>0)
{
?>
	<td>&nbsp;<?php echo number_format(mysql_result($res_tran1,0,'tice'),2);?></td>
<?php } ?>

	<td>&nbsp;<?php echo number_format(mysql_result($res_tran1,0,'tiva'),2);?></td>

<?php
if(mysql_result($res_tran1,0,'tirbp')>0)
{
?>
	<td>&nbsp;<?php echo number_format(mysql_result($res_tran1,0,'tirbp'),2);?></td>
<?php } ?>
	<td>&nbsp;<?php echo number_format(mysql_result($res_tran1,0,'total'),2);?></td>
<?php } ?>
<!-- 	<td></td> -->

<?php
if (mb_stristr('inve.prod',$tabla))
{
?>

	<td></td>
	<td></td>
	<td align="center">T O T A L E S</td>
	<td>&nbsp;<?php echo number_format(abs(mysql_result($res_tran1,0,'tcant')),$duni);?></td>
	<td></td>
	<td>&nbsp;<?php echo number_format(abs(mysql_result($res_tran1,0,'tsubt')),2);?></td>


	<td>&nbsp;<?php echo number_format(abs(mysql_result($res_tran1,0,'total')),2);?></td>
<?php } ?>
	
<?php
if (mb_stristr('retc.retp',$tabla))
{
?>
	<td></td>
	<td></td>
	<td align="right">TOTAL RETENIDO</td>
	<td></td>
	<td></td>
	<td></td>
	<td></td>
	<td align="right">&nbsp;<?php echo number_format(mysql_result($res_tran1,0,'ttotal'),2);?></td>
<?php } ?>

<?php
if (mb_stristr('caja.bcos',$tabla) && $formato!=5)
{
?>
	<td></td>
	<td align="right">TOTAL </td>
	<td></td>
	<td></td>
	<td align="right">&nbsp;<?php echo number_format(abs(mysql_result($res_tran1,0,'total')),2);?></td>
	<td></td>
<?php } ?>
	

<?php
if (mb_stristr('nomi.rolp',$tabla) && $formato!=5)
{
?>
	<td></td>
	<td></td>
	<td></td>
	<td align="right">TOTALES </td>
	<td></td>
	<td></td>
	<td align="right">&nbsp;<?php echo number_format(mysql_result($res_tran1,0,'tingreso'),2);?></td>
	<td align="right">&nbsp;<?php echo number_format(mysql_result($res_tran1,0,'tegreso'),2);?></td>
	<td align="right">&nbsp;<?php echo number_format(mysql_result($res_tran1,0,'tprovi1'),2);?></td>
	<td align="right">&nbsp;<?php echo number_format(mysql_result($res_tran1,0,'tprovi2'),2);?></td>

	<td></td>
<?php } ?>
	
	
</tr>

<tr>
</tr>


<tr>
<td><br></td>

</tr>
</table>

<table align="right" border="0" width="50%" style="font-size:18px">
<tr>
<td align="right"><b>
<?php 
if (mb_stristr('vtas.comp.clie.prov.inve.nomi.prod.caja.bcos',$tabla))
{echo 'SON: '.numtoletras(abs(mysql_result($res_tran1,0,'total')));}

if (mb_stristr('cont',$tabla))
{echo 'SON: '.numtoletras(abs(mysql_result($res_tran1,0,'total'))/2);}
if (mb_stristr('retc.retp',$tabla))
{echo 'SON: '.numtoletras(number_format(abs(mysql_result($res_tran1,0,'ttotal')),2));}
?>
</td>
</tr>
</table>

<table align="left" border="0" width="50%" style="border-collapse:collapse;<?php echo $xfontsize; ?>">
<tr align="center" font bgcolor=#DDDDDD style="border-top: thin solid;border-bottom:thin solid">
<td><b><font size="2">N O T A S</b></td>
</tr>

	<?php
	if (mb_stristr('gnya',$_SESSION['user_vcrx_empr']) && mb_stristr('OP',substr($docu,0,2)))
	{
	?>
	<tr>
	<td><font size="2">Realice su deposito o transferencia a:
	<tr><td>Bco. Pichincha - Cta.Ahorro #3596139400 </tr>
	<tr><td>(Germanya / Juan Carlos Illesca)</tr>
	<tr><td><br>
	</td>
	</tr>
	<?php
	}
	?>



	<?php
	if (mb_stristr($xcelec1,$tabla))
	{
	?>
	<tr>
	<td><font size="2">ESTA IMPRESION SOLO TIENE FINES INFORMATIVOS Y DE CONSULTA</td>
	</tr>
	<tr>
	<td><font size="2">ESTA IMPRESION NO TIENE VALIDEZ TRIBUTARIA</td>
	</tr>
	<tr>
	<td><font size="2">VALIDADOR : <a href="https://declaraciones.sri.gob.ec/comprobantes-electronicos-internet/publico/validezComprobantes.jsf">https://declaraciones.sri.gob.ec/comprobantes-electronicos-internet/publico/validezComprobantes.jsf</a></td>
	</tr>
	<tr>
	<td><font size="2">Mas informacion en : <a href="http://www.sri.gob.ec/web/10138/145">http://www.sri.gob.ec/web/10138/145 </a></td>
	</tr>
	<?php
	}
	?>
</table>

<?php if(mb_stristr('CH',substr($docu,0,2))){ ?>

<table width =100%>
<tr ></tr>
<td heigth="200px"><br><br><br><br></td>
<tr>
<td width="5%"></td>	
<td width="20%" style="border-top:solid 1px" align="center">ELABORADO POR</td>	
<td width="15%"></td>	
<td width="20%" style="border-top:solid 1px" align="center">APROBADO POR</td>	
<td width="15%"></td>	
<td width="20%" style="border-top:solid 1px" align="center">RECIBI  CONFORME</td>	
<td width="10%"></td>	
</tr>	
</table>	
<?php } ?>
	
</div>
<!-- </div> -->
<?php		
}
?>


<?php		

}
}




$ce=new vrcelec1($_GET['docu'],$_GET['idnum'],$_GET['formato']);
?>