<?php
// TIRILLA WASAPP  caracteres


function prnt_docu0($docu,$idnum,$formato=1,$destino='screen')
{
include('../_cfg/config.php');
include('php_session.php');
// vrupdcol('retc1','toenti', 'varchar(13)','','');
// echo 'I0 :'.Date('H:i:s',strtotime('now'));

// if(mb_stristr('amay',$cfg_empr)){$formato=1;}
  
  
$docu=trim($docu);
$sql_docu='select * from docu0 where docu_codigo like "'.$docu.'%"';
$res_docu=mysql_query($sql_docu,$link_vcrx);
	
if(mb_stristr('DD.DT.DI',substr($docu,0,2))){$formato=1;}
$tabla=strtolower(mysql_result($res_docu,0,'docu_tabla'));	
$ppsize=mysql_result($res_docu,0,'docu_ppsize');	
$pporient=mysql_result($res_docu,0,'docu_pporient');	

$width=mysql_result($res_docu,0,'docu_width');	
$height=mysql_result($res_docu,0,'docu_height');	 
$orient=mysql_result($res_docu,0,'docu_orient');	

$doble=mysql_result($res_docu,0,'docu_doble');	
$copia=mysql_result($res_docu,0,'docu_copia');	
	
if($ppsize==''){$ppsize='A4';}
if($pporient==''){$pporient='V';}
if($width==0){$width=210;}
if($height==0){$width=297;}
if($orient==''){$orient='V';}	
if($copia==0){$copia=1;}	

if($user_codigo=='')
{
	$ppsize='A4';
	$pporient='V';
	$width=210;
	$height=297;
	$orient='V';
	$copia=1;
}	

  
//$sql_tra1='select * from '.$tabla.'11 where idnum1="'.$idnum.'"';
$sql_tra1='select * from '.$tabla.'1 where idnum1="'.$idnum.'"';
$res_tra1=mysql_query($sql_tra1,$link_vcrx);	
// echo $sql_tra1;
// echo explain_sql($sql_tra1);

// if(mb_stristr('caja.bcos',$tabla) and substr($docu,2,2)=="13")
// {gen_caba13($docu,$idnum);}
	
// if(mb_stristr('inve',$tabla) and substr($docu,2,2)=="13")
// {gen_inve13($docu,$idnum);}

// $xenti=@mysql_result($res_tra1,0,'enti_descri');
// $xenti=@mysql_result($res_tra1,0,'enti');
$xenti=@mysql_result($res_tra1,0,'enti');
$xentidesc=r_fiel('enti',$xenti);
$xptonumero=@mysql_result($res_tra1,0,'ptonumero');
$xptoe=@mysql_result($res_tra1,0,'ptoe');
$xnumero=@mysql_result($res_tra1,0,'numero');
$xstatus=@mysql_result($res_tra1,0,'status');

$filelogo=$rutalogo.$logofile2;	


$docu1=prnt_docu2($docu,$idnum,$formato,$destino);
  
// if($formato==1 and mb_stristr('FP.FC',substr($docu,0,2)))  
if($formato!=2 and substr($docu,0,2)=='FP')  
{
	$docur=prnt_docur($docu,$xptoe,$xnumero,$xenti,$destino);
	$docu1=str_replace('</footer1>','</footer1>'.$docur,$docu1);
	$docu1=str_replace('</footer1>','</footer1><br>',$docu1);
} 
  
if($formato==3 )	
{
	if(mb_stristr('retc.retp',$tabla))
	{
		$sql_rete ='select idnum1,docu,numero,fecha,enti from '.$tabla.'1';
		$sql_rete.=' where enti="'.mysql_result($res_tra1,0,'enti').'" ';
		$sql_rete.=' and numero="'.mysql_result($res_tra1,0,'numero').'" ';
		$sql_rete.=' and fecha="'.mysql_result($res_tra1,0,'fecha').'" ';
		$sql_rete.=' and status!="O" and status!="X"';
		$sql_rete.=' order by idnum1 desc';
		$res_rete=mysql_query($sql_rete,$link_vcrx);	
		$docu1=str_replace('</footer1>','</footer1><br>',$docu1);
		while($aso_rete=mysql_fetch_assoc($res_rete))
		{
			$docu2=prnt_docu2($aso_rete['docu'],$aso_rete['idnum1'],'2',$destino);
			$docu2=substr($docu2,strpos($docu2,'<detalle>'));
			$docu2=substr($docu2,0,strpos($docu2,'</detalle>')+10);
			$docu1=str_replace('</footer1>','</footer1>'.$docu2,$docu1);
		}
		$docu1=str_replace('</footer1>','</footer1><br>',$docu1);
	}
	else
	{
		$docu2=prnt_docu2($docu,$idnum,'2',$destino);
		$docu1=str_replace('</footer1>','</footer1><br>',$docu1);
		$docu2=substr($docu2,strpos($docu2,'<detalle>'));
		$docu2=substr($docu2,0,strpos($docu2,'</detalle>')+10);
		$docu1=str_replace('</footer1>','</footer1>'.$docu2,$docu1);
		$docu1=str_replace('</footer1>','</footer1><br>',$docu1);
		
	}
}

  
  
?>

  <?php $xfontsize=12; ?>
  <?php $xfontfamily='font-family:arial;';  ?>
  <?php
//     if($cfg_empr=='ecgl' and mb_stristr('FC',substr($docu,0,2)))
//     {$xfontsize+=2; $xfontfamily='font-family:Courier New; font-weight:bolder;';}
  ?>
  <?php
//     if($cfg_empr=='dly1' and mb_stristr('FC.PC',substr($docu,0,2)) and $destino!='mail' and $cdisplay==2)
//     {$xfontsize+=2; $xfontfamily='font-family:Courier New; font-weight:bolder;';$doculogo=0;}
  ?>

  <?php
    if(mb_stristr('pos.txt',$destino))
    {$xfontsize-=4; $xfontfamily='font-family:Courier New; font-weight:bolder; white-space:pre-wrap; width:55mm; ';}
  ?>

<?php ob_start(); ?>
<?php //////////////////////////////////////////////////////////	?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php //////////////////////////////////////////////////////////	?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title><?php echo $docu.'-'.$xptonumero.'-'.$xentidesc; ?></title>
	
<style type="text/css">

p.saltodepagina
{page-break-after: always;}
/* <p class="saltodepagina" /></p>	 */

  
#header
{
	display:none;
}

/* @font-face {font-family:'EanP36Tt'; src:url('../_font/EAN13_36.ttf') format('truetype');} */
@font-face {font-family:'Barcode'; src:url('/_font/BarcodeFont.ttf') format('truetype');}
	
/* ean13 {font-family:'EanP36Tt';} */
barcode {font-family:'Barcode';}
	
@media print {.noprint {display:none}}
@media screen{.noscreen {display:none}}
	
@page
{
size: <?php echo $ppsize.' '; if($pporient=='V'){echo ' portrait';}else{echo ' landscape';}; ?>
	
<?php if($copia==1) { ?>
margin: 10mm 10mm 10mm 10mm; /* 	top right bottom left */
<?php } ?>
	
<?php if($copia==2 and $pporient=='V') { ?>
margin: 10mm 5mm 10mm 5mm; /* 	top right bottom left */
<?php } ?>

<?php if($copia==2 and $pporient=='H') { ?>
margin: 10mm 10mm 10mm 10mm; /* 	top right bottom left */
<?php } ?>

<?php if($copia>=3 and $pporient=='V') { ?>
margin: 10mm 10mm 10mm 10mm; /* 	top right bottom left */
<?php } ?>

<?php if($copia>=3 and $pporient=='H') { ?>
margin: 10mm 10mm 10mm 10mm; /* 	top right bottom left */
<?php } ?>

}
</style>
<script type="text/javascript" src="http://vcrxol.com/_js/js_gene1.js"></script>

</head>
<?php //////////////////////////////////////////////////////////	?>

<?php //////////////////////////////////////////////////////////	?>
<body>
<?php //echo $docu1; ?>  
<div style="font-size:<?php echo $xfontsize; ?>;<?php echo $xfontfamily; ?>">
  
<?php if($copia==1){echo $docu1;} ?>
	
<?php
if($copia==2 and $pporient=='H')
{
?>
	<table border="0" width="100%" cellpadding="0" cellspacing="10mm" style="border-collapse:collapse;">
		<tr>
			<td width="50%" align="left"><?php echo $docu1; ?></td>
			<td width="50%" align="right"><?php echo $docu1; ?></td>
		</tr>
	</table>
<?php
}
?>
	
<?php
if($copia==2 and $pporient=='V')
{
?>
	<table border="0" width="100%" cellpadding="0" cellspacing="0" style="border-collapse:collapse;">
		<tr><td width="100%" align="center"><?php echo $docu1; ?></td></tr>
		<tr><td width="100%" align="center"><?php echo $docu1; ?></td></tr>
	</table>
<?php
}
?>

<?php
if($copia>=3)
{
?>
	<table border="0" width="100%" cellpadding="0" cellspacing="0" style="border-collapse:collapse;">
		<tr>
			<td width="50%" align="left"><?php echo $docu1; ?></td>
			<td width="50%" align="right"><?php echo $docu1; ?></td>
		</tr>
		<tr>
			<td width="50%" align="left"><?php echo $docu1; ?></td>
			<td width="50%" align="right"><?php echo $docu1; ?></td>
		</tr>
	</table>
<?php
}
?>
	
</div>	
</body>	
<?php //////////////////////////////////////////////////////////	?>

</html>

	
	
<?php	
// 		echo $expla;

$docuhtml = ob_get_clean(); 
// $docuhtml=alltrim($docuhtml);
$docu_idnum=$docu.'_'.str_pad($idnum,9,"0",STR_PAD_LEFT);	
file_put_contents($rutadoc.$docu_idnum.'.html',$docuhtml);
// if(substr($xclaveacc,10,13)==$cfg_ruc or $cfg_empr=='demo')
// {file_put_contents($rutace.$xclaveacc.'.html',$docuhtml);}


return $docuhtml;	
	
}
?>



<?php
function prnt_docu2($docu,$idnum,$formato=1,$destino='screen')
{
	
$mtime=microtime(true);
$nota1='';	
$eol="<br>";
$eol=" \r\n";  
// if($destino=='screen'){$eol="<br>";}
// if($destino=='file'){$eol=" \r\n";}
$coltxt=40;
$padtxt=' ';
$carbot='- ';
  
// ob_start();
// 		formatos
// 			1 - general
// 			2 - diario contable (directo de la tabla cont1)
// 			3 - diario contable (desde el modulo a cont.idfrom)
//			5 - egreso detallado
	
// 		destino
// 			screen
// 			mat tricial
// 			txt pos 
	
// echo sal_docu($docu,$idnum);	
	include('../_cfg/config.php');
 	include('php_session.php');
  mysql_query("SET NAMES 'utf8'");  
	
//   if($destino=='pdf')
    
//   upl_cexml('2002201804099007196900120040030000006910000069119');
// 	$empr_cont=@mysql_result($res_emis,0,'empr_cont');
	$empr_cont=r_fiel('empr',$cfg_empr,'empr_cont');

  if($formato=='2' and $empr_cont!='1'){return; }
  
	$tabla=r_fiel('docu',$docu,'tabla');

if($cfg_empr=='pcs1')
{
//   $sql_cele='update '.$tabla.'1 set stfin=null where idnum1="'.$idnum.'"';
//   $res_cele=mysql_query($sql_cele,$link_vcrx);
}  

  
	if(mb_stristr('PC.PP',substr($docu,0,2))){gen_claveacc($docu,$idnum);}
	if(mb_stristr('FC',substr($docu,0,2))){$serie_lote=get_serie_lote($idnum);}
	if(mb_stristr('FP',substr($docu,0,2))){updt_itemce($idnum);updt_ctascomp($idnum);}
	if(mb_stristr('RP.RC',substr($docu,0,2))){val_rete($docu,$idnum);}
	if(mb_stristr('DD.DT.DI',substr($docu,0,2))){$formato=1;}
	if(mb_stristr('NC.NP',substr($docu,0,2))){val_ncre($docu,$idnum);}
	if(mb_stristr('FP.RC',substr($docu,0,2))){get_atrz1($docu,$idnum);}

  if(mb_stristr('PF.OP.PC.FC',substr($docu,0,2)) and $cfg_empr=='dly1'){dly1_calc1($docu,$idnum);}
  if(mb_stristr('PF.OP.PC.FC',substr($docu,0,2)) and $cfg_empr=='ecgl'){ecgl_calc1($docu,$idnum);}
  if(mb_stristr('FC',substr($docu,0,2)) and $cfg_empr=='pcs1'){pcs1_calc1($docu,$idnum);}

  if(mb_stristr('caja.bcos',$tabla) and substr($docu,2,2)=="13"){gen_caba13($docu,$idnum);}

//   if(mb_stristr('inve',$tabla) and substr($docu,2,2)=="13"){gen_inve13($docu,$idnum);}
 
//   if($formato>=2 and $tabla!='cont'){$contab=gen_contab($docu,$idnum);}		
  if($formato==2 and $tabla!='cont'){$contab=gen_contab($docu,$idnum);}		
//   if(($formato==2 or $formato==3) and $tabla!='cont'){$contab=gen_contab($docu,$idnum);}		
  
	$sql_tra0='select * from '.$tabla.'1 where idnum1='.$idnum;
	$res_tra0=mysql_query($sql_tra0,$link_vcrx);	

  $claveacc=@mysql_result($res_tra0,0,'claveacc');
  $ambice=substr($claveacc,23,1);
  
	$ccc=0;
	$overpdf=0;	
	$docu_idnum=$docu.'_'.fillzero($idnum);	
	if($destino==''){$destino='screen';}	
	if($destino=='pdf'){$overpdf=1;}	
// 	if(mb_stristr($destino,'mail') or $destino=='pdf' or $destino=='M'){$destino='mail';}
	if(mb_stristr($destino,'mail') or $destino=='M'){$destino='mail';}

{
	$mdisplay=2;
	if(mb_stristr($destino,'mail')){$mdisplay=1; $destino='mail';}
	if(mb_stristr('pos.txt',$destino)){$mdisplay=1;}
	if($formato==2){$tabla='cont';}

	$sql_docu='select * from docu0 where docu_codigo like "'.$docu.'%"';
	$res_docu=mysql_query($sql_docu,$link_vcrx);

	$tabla=strtolower(mysql_result($res_docu,0,'docu_tabla'));	
	$ppsize=mysql_result($res_docu,0,'docu_ppsize');	
	$pporient=mysql_result($res_docu,0,'docu_pporient');	

	$width=mysql_result($res_docu,0,'docu_width');	
	$height=mysql_result($res_docu,0,'docu_height');	
	$orient=mysql_result($res_docu,0,'docu_orient');	

	$doble=mysql_result($res_docu,0,'docu_doble');	
	$copia=mysql_result($res_docu,0,'docu_copia');	

	$mindeta=@mysql_result($res_docu,0,'docu_mindeta');	
	$docupdf=@mysql_result($res_docu,0,'docu_pdf');	
	$margin_top=@mysql_result($res_docu,0,'docu_top');	
	$margin_left=@mysql_result($res_docu,0,'docu_left');
  
  if($ambice=='2'){$margin_top=0;}

	$doculogo=0;
	$firmas=0;
	$marcas=0;
	$notas=1;
	$guiaremi=0;
	if(mb_stristr('FC.OP.PC.PF.NC..GR..RP..PP..IE.IC..CH',substr($docu,0,2))){$doculogo=1;}
 	if(mb_stristr('FC.OP.PC.PF.NC..GR..RP..PP..IE.IC..CH..EB',substr($docu,0,2))){$firmas=1;}
 	if(mb_stristr('DD.RP.RC.',substr($docu,0,2))){$notas=0;}
	if(mb_stristr('GR',substr($docu,0,2))){$guiaremi=1;}
	if(mb_stristr('clie.vtas',$tabla)){$marcas=1;}
	if($destino=='mail'){$margin_top=0; $firmas=0;}
	if($margin_top>0){$doculogo=0;}
	
	if($ppsize==''){$ppsize='A4';}
	if($pporient==''){$pporient='V';}
	if($width==0){$width=210;}
	if($height==0){$height=297;}
	if($orient==''){$orient='V';}	
	if($copia==0){$copia=1;}	
  if($formato==1){$copia=1;}

  if(mb_stristr('pos.txt',$destino))
  {
    $mdisplay=1;
    $copia=1;
    $margin_top=0;
    $doculogo=0;
    $firmas=0;
  }

	if($user_codigo=='')
	{
		$ppsize='A4';
		$pporient='V';
		$width=210;
		$height=297;
		$orient='V';
		$copia=1;
	}	
	
	$xfontsize=12;
	$screensize=12;
	$printsize=12;
	if($width<=150)
	{
		$xfontsize=12;
		$screensize=12;
		$printsize=8;
	}
	if($width<=110)
	{
		$xfontsize=12;
		$screensize=12;
		$printsize=6;
	}

	// $width=70;
	$tirilla=0;	
	if($width<=90)
	{
		$tirilla=1;
		$xfontsize=12;
		$screensize=12;
		$printsize=6;
	}

	if($formato==2 and $tabla!='cont')
	{
			$sql_tra1='select * from cont1 where idfrom="'.$idnum.'" and mdfrom="'.$tabla.'"';
			$res_tra1=mysql_query($sql_tra1,$link_vcrx);
			$idnum=@mysql_result($res_tra1,0,'idnum1');
			$tabla='cont';
	}	
	
	
	if($formato>=2)
	{
		$xfontsize=12;
		$screensize=12;
		$printsize=12;
		$ppsize='A4';
		$pporient='V';
		$width=210;
		$height=297;
		$orient='V';
		$copia=1;
		$doculogo=0;
		$firmas=1;
		$marcas=0;
		$notas=0;
		$guiaremi=0;
		$xmdetalle='-';
		$margin_top=0;
	}
	
	{	
		$sql_emis='select * from empr0 left join enti00 on empr_ruc=enti_codigo limit 1';
		$res_emis=mysql_query($sql_emis,$link_vcrx);
    if(mysql_errno!=0)
    {
      $sql_emis='select * from empr0 left join enti0 on empr_ruc=enti_codigo limit 1';
      $res_emis=mysql_query($sql_emis,$link_vcrx);
    }

    {
	// 				$total_sql='select ';
					$total_sql ='max(detalle) as mdetalle, ';
					$total_sql.='sum(abs(tsubt)) as stsubt,';
					$total_sql.='sum(abs(cant)) as stcant,';
					if(mb_stristr('cont',$tabla))
					{
						$total_sql.='sum(tdebito) as stdebito,';
						$total_sql.='sum(tcredito) as stcredito,';
						$total_sql.='sum(diferencia) as sdiferencia,';
						$total_sql.='max(csub) as mcsub, ';
						$total_sql.='max(cair) as mcair, ';
						$total_sql.='max(item) as mitem, ';
					}
			
					if(mb_stristr('vtas.clie.carr.comp.prov',$tabla))
					{
            $total_sql.='sum(abs(tsubtiva0)) as stsubtiva0,';
            $total_sql.='sum(abs(tsubtiva)) as stsubtiva,';
            $total_sql.='sum(abs(tsubtice)) as stsubtice,';
            $total_sql.='sum(abs(tdcto)) as stdcto,';
            $total_sql.='sum(abs(tprop)) as stprop,';
            $total_sql.='sum(abs(tice)) as stice,';
            $total_sql.='sum(abs(tiva)) as stiva,';
            $total_sql.='sum(abs(tirbp)) as stirbp,';
            $total_sql.='sum(abs(tbien)) as stbien,';
//             $total_sql.='sum(abs(tserv)) as stserv,';

            $total_sql.='max(dcto) as pdcto,';
            $total_sql.='max(prop) as pprop,';
            $total_sql.='max(ice) as pice,';
            $total_sql.='max(iva) as piva,';
            $total_sql.='max(irbp) as pirbp,';
            
					}
			
					if(mb_stristr('comp.prov',$tabla))
					{
	// 				$total_sql.='sum(trrta) as strrta,';
	// 				$total_sql.='sum(triva) as striva,';
					$total_sql.='sum(rrta) as srrta,';
					$total_sql.='sum(riva) as sriva,';
					}

					if(mb_stristr('retc.retp',$tabla))
					{
            $total_sql.='sum(brta) as sbrta,';
            $total_sql.='max(prta) as sprta,';
            $total_sql.='sum(rrta) as srrta,';
            $total_sql.='sum(biva) as sbiva,';
            $total_sql.='max(piva) as spiva,';
            $total_sql.='sum(riva) as sriva,';
					}
			
					if(mb_stristr('vtas',$tabla) and mb_stristr('pcs1',$cfg_empr))
					{
            $total_sql.='sum(cntn) as scntn,';
            $total_sql.='max(cntn) as mcntn,';
					}
			
          if(mb_stristr('vtas.clie.prod',$tabla) and $cfg_empr=='ecgl')
          {
            $total_sql.='sum(case when item_descri like "VIDR%" then (lmns) else 0 end) as stlmn,';
            $total_sql.='sum(case when item_descri like "VIDR%" then (lmns*(mm_l*2+mm_a*2)/1000) else 0 end) as stmt1,';
            $total_sql.='sum(case when item_descri like "VIDR%" then (lmns*mm_l*mm_a/1000000) else 0 end) as stmt2,';
          }
      
					$total_sql.='sum(abs(total)) as stotal ';

					$dispcolu=1;
					if($mobile=='true'){$dispcolu=0;}
		}
		
		if(mb_stristr('retc.retp',$tabla))
		{
      if($tabla=='retc'){$sql_ret2 ='update '.$tabla.'2 set docum="FC10" where docum like "R%" and idnum2="'.$idnum.'"';}
      if($tabla=='retp'){$sql_ret2 ='update '.$tabla.'2 set docum="FP10" where docum like "R%" and idnum2="'.$idnum.'"';}
			$res_ret2=mysql_query($sql_ret2,$link_vcrx);
      
			$sql_tra1 ='select * from '.$tabla.'12 where status!="O" and status!="X" and cant>0 and ';
			$sql_tra1.='concat(numero,fecha,enti) in (select concat(numero,fecha,enti) as numero from '.$tabla.'1 where idnum1="'.$idnum.'" )';
			$sql_tra2=$sql_tra1;

			$sql_tra1=str_replace('*','*,'.$total_sql,$sql_tra1);
		}
		else
		{
			$sql_tra1='select * from '.$tabla.'12 where idnum1="'.$idnum.'"';
			$sql_tra2=$sql_tra1;

			$sql_tra1=str_replace('*','*,'.$total_sql,$sql_tra1);
		}

		if($cfg_empr=='ecgl' and mb_stristr('vtas.clie.prod',$tabla))
		{$sql_tra2.=' order by itnum,iddet ';}

		if(!mb_stristr($sql_tra2,'order by'))
    {$sql_tra2.='order by iddet ';}
		
		if(mb_stristr('cont',$tabla))
		{$sql_tra2=str_replace('order by','order by ctas,cant desc,',$sql_tra2);}
		
//     mysql_data_seek($res_tra1,0);    
    $res_tra1=mysql_query($sql_tra1,$link_vcrx);	
// 		$res_tra2=mysql_query($sql_tra2,$link_vcrx);
    
    $enti_codigo=mysql_result($res_tra1,0,'enti');
    $enti_descri=mysql_result($res_tra1,0,'enti_descri');
    $enti_razsoc=mysql_result($res_tra1,0,'enti_razsoc');
    $enti_nom1=mysql_result($res_tra1,0,'enti_nom1');
//     $enti_matriz=mysql_result($res_tra1,0,'enti_matriz');
    $enti_matriz=r_fiel('enti',$enti_codigo,'enti_matriz');
//     $enti_ciudad=r_fiel('enti',$enti_codigo,'enti_ciudad');
//     $enti_parroq= mysql_result($res_tra1,0,'enti_parroq');
    $enti_parroq= r_fiel('enti',$enti_codigo,'enti_parroq');

		if($enti_razsoc==''){reg_cedruc($enti_codigo);}
    
		if($enti_descri=='' or $enti_razsoc=='')
    {
      get_ruc1($enti_codigo);
  		$res_tra1=mysql_query($sql_tra1,$link_vcrx);	
      $enti_codigo=mysql_result($res_tra1,0,'enti');
      $enti_descri=mysql_result($res_tra1,0,'enti_descri');
      $enti_razsoc=mysql_result($res_tra1,0,'enti_razsoc');
      $enti_nom1=mysql_result($res_tra1,0,'enti_nom1');
    }
    
    if(substr($enti_codigo,2,1)<=6 and ($enti_nom1=='' or $enti_razsoc=='' or $enti_parroq==''))
    {
      get_ced1($enti_codigo);
      get_ced2($enti_codigo);
  		$res_tra1=mysql_query($sql_tra1,$link_vcrx);	
//       explain_sql($sql_tra1);
      $enti_codigo=mysql_result($res_tra1,0,'enti');
      $enti_descri=mysql_result($res_tra1,0,'enti_descri');
      $enti_razsoc=mysql_result($res_tra1,0,'enti_razsoc');
      $enti_nom1=mysql_result($res_tra1,0,'enti_nom1');
      $enti_parroq=@mysql_result($res_tra1,0,'enti_parroq');
      $enti_actividad=@r_fiel('enti',$enti_codigo,'enti_actividad');
    }
        if($enti_matriz==''){get_ruc2($enti_codigo);};
//         if($enti_matriz==''){get_ruc4($enti_codigo);};
//     if($enti_provincia==''){get_ruc4($enti_codigo);};
//     if($enti_parroq==''){get_ruc4($enti_codigo);};
//     if($enti_actividad==''){get_ruc4($enti_codigo);};

    $enti_orig=$enti_codigo;
    $sql_adqu='select * from enti00 where enti_codigo like "'.$enti_codigo.'%" order by enti_codigo desc';
		$res_adqu=mysql_query($sql_adqu,$link_vcrx);
//     explain_sql($sql_adqu);

    $xtoenti=@mysql_result($res_tra1,0,'toenti');
		$sql_toen=$sql_adqu;
		if($tabla=='comp')
		{$sql_toen='select * from enti00 where enti_codigo like "'.$xtoenti.'%" order by enti_codigo desc';}
		if($tabla=='retc')
		{$sql_toen='select * from enti00 where enti_codigo like "'.$xtoenti.'%" order by enti_codigo desc';}
		$res_toen=mysql_query($sql_toen,$link_vcrx);
//     echo '*/*/*'.$sql_toen;
		
		$xptonumero=mysql_result($res_tra1,0,'ptonumero');
		$xenti=mysql_result($res_tra1,0,'enti');
		
		$entipdf=0;
		$entipdf=@r_fiel('enti',$xenti,'pdf');

    $enticomi=0;
    if(mb_stristr('clie.vtas',$tabla))
    {$enticomi=@r_fiel('enti',$xenti,'comi');}
//     $enticomi=10;
		
		
		if(mb_stristr('clie',$tabla))
		{$xclaveacc=mysql_result($res_tra1,0,'claveacc');}
		
		if(mb_stristr('vtas.comp.retc.retp.guia',$tabla))
		{
			$xclaveacc=mysql_result($res_tra1,0,'claveacc');
			$xautornum=mysql_result($res_tra1,0,'autornum');
			$xautorfec=@mysql_result($res_tra1,0,'autorfec');
			$xatrz=mysql_result($res_tra1,0,'atrz');
			$xatrzvali=@mysql_result($res_tra1,0,'atrzvali');
		}
    
		$xstatus=mysql_result($res_tra1,0,'status');
		$xstfin=mysql_result($res_tra1,0,'stfin');
		$xambi=substr($xclaveacc,23,1);
		$docu_descri=mysql_result($res_tra1,0,'docu_descri');
		$tiporuc=mysql_result($res_tra1,0,'enti_tiporuc');
		if($tiporuc=='N'){$docupdf=0; $entipdf=0;}

		$tipo_descri='';
		if(substr($xclaveacc,8,2)=='01'){$tipo_descri='FACTURA';}
		if(substr($xclaveacc,8,2)=='04'){$tipo_descri='NOTA DE CREDITO';}
		if(substr($xclaveacc,8,2)=='06'){$tipo_descri='GUIA DE REMISION';}
		if(substr($xclaveacc,8,2)=='07'){$tipo_descri='RETENCION';}
// 		if($docu_descri=="" or $empr=="cfg_demo"){$docu_descri=$tipo_descri;}
// 		if($docu_descri=="" or $empr=="demo"){$docu_descri=$tipo_descri;}
		if($tipo_descri!=''){$docu_descri=$tipo_descri;}
		
		$xmdetalle=mysql_result($res_tra1,0,'mdetalle');
		$xmcsub=@mysql_result($res_tra1,0,'mcsub');
		$xmcair=@mysql_result($res_tra1,0,'mcair');
		$xmitem=@mysql_result($res_tra1,0,'mitem');
		$xmcntn=@mysql_result($res_tra1,0,'mcntn');

    //ecgl
    $xstlmn=@mysql_result($res_tra1,0,'stlmn');
    $xstmt1=@mysql_result($res_tra1,0,'stmt1');
		$xstmt2=@mysql_result($res_tra1,0,'stmt2');
	
    if($tirilla==1){$xmdetalle='';}



		$xtunid=0;
		$xipuni=1;
		$xideta=1;
		$xpdcto=0;
		$xpprop=0;
		$xpice=0;
		$xpiva=0;
		$xpirbp=0;
		$xtdcto=0;
		$xtprop=0;
		$xtsubtice=0;
		$xtice=0;
		$xtsubtiva0=0;
		$xtsubtiva=0;
		$xtiva=0;
		$xtirbp=0;

		
		$xtcant=mysql_result($res_tra1,0,'stcant');
		$xtsubt=mysql_result($res_tra1,0,'stsubt');
		
		if(mb_stristr('retc.retp', $tabla))
		{
		$xtrrta=mysql_result($res_tra1,0,'srrta');
		$xtriva=mysql_result($res_tra1,0,'sriva');
		}

		$xtotal=mysql_result($res_tra1,0,'stotal');
		$xconcepto=(mysql_result($res_tra1,0,'concepto'));

		if($guiaremi==1)
		{
			$motivo=@mysql_result($res_tra1,0,'motivo');
			$idfrom=mysql_result($res_tra1,0,'idfrom');
			$mdfrom=mysql_result($res_tra1,0,'mdfrom');
			
			$sql_orig='select * from '.$mdfrom.'11 where idnum1="'.$idfrom.'"';
			$res_orig=mysql_query($sql_orig,$link_vcrx);
			
			$docuorig=mysql_result($res_orig,0,'docu');
			$docuorigd=mysql_result($res_orig,0,'docu_descri');
			$numeroorig=mysql_result($res_orig,0,'ptonumero');
			$fechaorig=mysql_result($res_orig,0,'fechadmy');
			$autororig=mysql_result($res_orig,0,'claveacc');
			
			if(substr($docuorig,0,2)=='FC'){$motivo='VENTA';}
			if(substr($docuorig,0,4)=='EB10'){$motivo='VENTA';}
			if(substr($docuorig,0,4)=='EB13'){$motivo='TRANSFERENCIA';}
			
		}
			
		$xvndd='';
		$xfpag='';
		$xsuco='';

		if(mb_stristr('cont', $tabla))
		{
			$xtdebito=mysql_result($res_tra1,0,'stdebito');
			$xtcredito=mysql_result($res_tra1,0,'stcredito');
			$xdifer=mysql_result($res_tra1,0,'sdiferencia');
		}
		if(mb_stristr('vtas.clie.comp.prov.inve.prod', $tabla))
		{
			$xtunid=$xtcant;
			$xfpag=@mysql_result($res_tra1,0,'fpag');
			if(mb_stristr('vtas.clie.comp.prov', $tabla))
			{
				$xipuni=1;
				$xpdcto=mysql_result($res_tra1,0,'pdcto');
				$xpprop=mysql_result($res_tra1,0,'pprop');
				$xpice=mysql_result($res_tra1,0,'pice');
				$xpiva=mysql_result($res_tra1,0,'piva');
				$xpirbp=mysql_result($res_tra1,0,'pirbp');
				$xtdcto=mysql_result($res_tra1,0,'stdcto');
				$xtprop=mysql_result($res_tra1,0,'stprop');
				$xtsubtice=mysql_result($res_tra1,0,'stsubtice');
				$xtice=mysql_result($res_tra1,0,'stice');
				$xtsubtiva0=mysql_result($res_tra1,0,'stsubtiva0');
				$xtsubtiva=mysql_result($res_tra1,0,'stsubtiva');
				$xtiva=mysql_result($res_tra1,0,'stiva');
				$xtirbp=mysql_result($res_tra1,0,'stirbp');
			}
			if(mb_stristr('vtas.clie.carr', $tabla))
			{
				$xtbien=mysql_result($res_tra1,0,'stbien');
				$xtserv=@mysql_result($res_tra1,0,'stserv');
				$xtunid=$xtbien;
				$xvndd=mysql_result($res_tra1,0,'vndd');
				$xvndd=r_fiel('enti',mysql_result($res_tra1,0,'vndd'));
			}
			if(mb_stristr('comp.prov', $tabla))
			{
				$xsuco=mysql_result($res_tra1,0,'suco');
			}
		}

		if(mb_stristr('prod', $tabla) and $cfg_empr=='ecgl'){$xtunid=0;$xtotal=0;}
    
		$xiuser=mysql_result($res_tra1,0,'iuser');
		$xidate=mysql_result($res_tra1,0,'idate');
    if($xidate==''){$xidate=mysql_result($res_tra1,0,'fecha');}


		$lblruc1='EMISOR';
		$lblruc2='ADQUIRIENTE';

		if (mb_stristr('cont',$tabla))
		{$lblruc1='EMPRESA';}
		
		if (mb_stristr('comp.retc',$tabla))
		{
			$res_emis=mysql_query($sql_adqu,$link_vcrx);
			$res_adqu=mysql_query($sql_emis,$link_vcrx);
			if($cfg_empr =='demo')
			{$res_adqu=mysql_query($sql_toen,$link_vcrx);	}
		}

		if (mb_stristr('OP.PC.PF',substr($docu,0,2)))
		{$lblruc2='CLIENTE';}

		if (mb_stristr('IE.IC.IV.DC',substr($docu,0,2)))
		{$lblruc2='CLIENTE';}

		if (mb_stristr('EE.CH.EV.DP.RP',substr($docu,0,2)))
		{$lblruc2='PROVEEDOR';}

		if (mb_stristr('inve',$tabla))
		{$lblruc2='ENTIDAD';}

		if (mb_stristr('nomi.rolp',$tabla))
		{$lblruc2='EMPLEADO';}

		if (mb_stristr('FP11.IB10',substr($docu,0,4)))
		{
			$lblruc2='PROVEEDOR';
			$res_emis=mysql_query($sql_emis,$link_vcrx);
			$res_adqu=mysql_query($sql_adqu,$link_vcrx);
		}

				
	}	
}	
	
?>	


<?php //////////////////////////////////////////////////////////	?>
<?php
    $subdce=mk_subdce($claveacc);
  
?>

	<?php $xfontsize=$screensize; ?>
	<?php $filexml=$rutace.$xclaveacc.'.xml'; ?>
	<?php $filepdf=$rutace.$xclaveacc.'.pdf'; ?>
	<?php $filepdf2=$rutadoc.$docu_idnum.'.pdf'; ?>

	<?php $filexml=$rutace.$subdce.$xclaveacc.'.xml'; ?>
	<?php $filepdf=$rutace.$subdce.$xclaveacc.'.pdf'; ?>
	<?php $filepdf2=$rutadoc.$docu_idnum.'.pdf'; ?>


	<?php // if($destino=='mail'){ ?>
	<?php	//echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'; ?>
	<?php	//echo '<html xmlns="http://www.w3.org/1999/xhtml">'; ?>
	<?php // } ?>



<?php ob_start(); ?>
	<?php for($cdisplay=1;$cdisplay<=$mdisplay;$cdisplay++) { ?>

  <?php $xfontfamily='font-family:arial;';  ?>
  <?php
    if($cfg_empr=='ecgl' and mb_stristr('FC',substr($docu,0,2)))
    {$destino='mat';}
//     {$xfontsize+=2; $xfontfamily='font-family:Courier New; font-weight:bolder;';$doculogo=0;}
  ?>
  <?php
    if($cfg_empr=='dly1' and mb_stristr('FC.PC',substr($docu,0,2)) and $destino!='mail' and $cdisplay==2)
    {$destino='mat';}
//     {$xfontsize+=2; $xfontfamily='font-family:Courier New; font-weight:bolder;';$doculogo=0;}
  ?>
  <?php
    if(substr($destino,0,3)=='mat')
    {$xfontsize+=2; $xfontfamily='font-family:Courier New; font-weight:bolder;';$doculogo=0;}
  ?>

  <?php
    if(mb_stristr('pos.txt',$destino))
    {$xfontsize-=4; $xfontfamily='font-family:Courier New; font-weight:bolder;white-space:pre-wrap;';}
  ?>

	<?php if($cdisplay==2){?>
	<div id="border-top" style="width:10mm; height:<?php echo $margin_top;?>mm">
	</div>
	<?php } ?>
	<div id="cele<?php echo $cdisplay;?>" 
			 style="border:solid 0px; <?php echo $xfontfamily;?>; 
							<?php if($mdisplay>1){?>
							<?php if($cdisplay==1){{echo 'width:210mm;';}}else{echo 'width:'.$width.'mm;';}?>
							<?php } ?>
							font-size:<?php echo $xfontsize; ?>px;
							overflow:hidden;
							transform: scale(1);"
						 <?php  if($cdisplay==1){{echo 'class="noprint";';}}else{echo 'class="noscreen";';}?>>	
<?php //if($cdisplay==1){echo 'PANTALLA';}else{echo 'IMPRESORA';}?>	
		<?php //echo $width ; ?>
		<?php //echo $mdisplay.$destino;?>
<?php
//   $docu_pdf = new FPDF('P','mm','A4');
  $docu_pdf = new FPDF('P','mm', $ppsize);
  $docu_pdf->AddPage();
	$docu_pdf->SetTitle($docu_descri.' '.$xptonumero);
	$docu_pdf->SetAuthor('Vicente Ruiz Espinoza - 09 96030568');																									
  $docu_pdf->setFillColor(240,240,240);                                                      
  $pdf_ancho=$docu_pdf->GetPageWidth()-20;
  $pdf_centro=$docu_pdf->GetPageWidth()/2-10;
  $ffamilyPDF='Arial';  
  $fsizePDF=$xfontsize;                                              
  if(mb_stristr(strtolower($xfontfamily),'courier'))                                                        
  {
//     $ffamilyPDF='Courier';
//     $fsizePDF=$xfontsize-1;                                              
    $ffamilyPDF='Arial';  
    $fsizePDF=$xfontsize-2;                                              
  }
?>    
    
	<cabecera>
	<table border="0" width="100%" cellpadding="2" cellspacing="0" style="border-collapse:collapse;font-size:<?php echo $xfontsize; ?>px;">
			<tr style="font-weight:bolder; font-size:<?php echo $xfontsize; ?>px; 
								 border-top:solid 1px; border-bottom:solid 1px;">
				<td width="20%">
				</td>
				<td width="60%" align="center" style="letter-spacing:5pt;">
				<?php
					if($formato==2){$titulcompro= 'DIARIO - CONTABLE';}
					else
					{
            $titulcompro='COMPROBANTE';
            if($xclaveacc!="" and ($xambi!=1 or $cdisplay!=2)){$titulcompro.=' - ELECTRONICO';}
					}
          echo $titulcompro;
        ?>
				</td>
        
        <?php
          $docu_txt='';                                                        
          $docu_txt.=str_repeat('=',$coltxt).$eol;
          $docu_txt.=str_pad(''.$titulcompro.' ',$coltxt,$carbot,STR_PAD_BOTH).$eol;
          $docu_txt.=str_repeat('=',$coltxt).$eol;
				?>

        <?php 
          $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-2);
          $docu_pdf->SetFontSize($fsizePDF-2);
          $docu_pdf->Cell(0,5,$titulcompro,'TB',0,'C',false);
          $docu_pdf->ln();
          $posY1=$docu_pdf->getY()+1;                                                        
          $posY2=$docu_pdf->getY()+1;                                                        
        ?>
        
				<td width="20%" align="right" style="font-size:50%;">
					<?php if($xiuser!="" and $destino!='mail'){?>
					<?php echo 'REGISTRADO POR: ';?>
					<?php //echo r_fiel('enti',$xiuser,'nom1').' '.r_fiel('enti',$xiuser,'ape1');?>
					<?php echo r_fiel('user',$xiuser);?>
					<?php echo '<br>';?>
					<?php } ?>
					<?php echo date('d/M/y H:i:s',strtotime($xidate));?>
				</td>
			</tr>
		</table>		
	</cabecera>

		<?php $hlogo=20; if($cdisplay!=1){if($width<=150){$hlogo=15;}; if($width<=110){$hlogo=10;};} ?>
		<table border="0" width="100%" cellpadding="2" cellspacing="0" style="border-collapse:collapse;font-size:<?php echo $xfontsize; ?>px;">
			<tr>
				<?php //210*297 =62370 ?>
				<?php ///// COLUMNA IZQUIERDA ?>
				<td width="<?php if($width>=150 or 1==1){echo '60%';}else{echo '100%';}?>" <?php if($width>=150  or 1==1){}else{echo ' colspan="2"';}?> valign="top">

					<?php  ////  LOGO ?>
					<logo>
					<table border="1" width="100%" cellpadding="2" cellspacing="0" style="border-collapse:collapse;font-size:<?php echo $xfontsize; ?>px;">
						<tr>
							<?php //if (mb_stristr('FC.PF.GR.RP.IE',substr($docu,0,2)) and file_exists('../..'.$empr_logo2) and ($width<150 or 1==1)){ ?>
							<?php if ($doculogo==1 and file_exists($rutalogo.$logofile2) and ($width<150 or 1==1)){ ?>
							<td align="center" style="">
							<?php if($empr_website!=''){?>
							<a target="_blank"  href="http://<?php echo $empr_website; ?>">
							<?php }else{ ?>
								<?php if($xclaveacc!=''){?>
								<a href="<?php echo 'http://'.$cfg_empr.'.vcrxol.com/print1.php?clave='.$xclaveacc;?>">
								<?php }else{ ?>
								<a href="<?php echo 'http://'.$cfg_empr.'.vcrxol.com/print1.php?prnt1=1&docu='.$docu.'&idnum='.$idnum;?>">
								<?php } ?>
							<?php } ?>
							<img src="<?php echo 'http://vcrxol.com/_logo/'.$logofile2;?>" alt=""
									 title="<?php echo $empr_website; ?>" style="max-width:100%; max-height:<?php echo $hlogo;?>mm;">		
							</a>
							</td>
        <?php 
//           $docu_pdf->ln(5+2);
					$xsrc='http://vcrxol.com/_logo/'.$logofile2;
          $xsrc_fgc=file_get_contents($xsrc);                                                                                        
          $img_xy=getimagesizefromstring($xsrc_fgc);
          $img_w=$img_xy[0];
          $img_h=$img_xy[1];
          $img_rel=$img_w/$img_h;
          $cel_w=$pdf_ancho*.6;                                                                                        
          $cel_h=25;
          if($img_w<$cel_w){$img_w=$cel_w;}
          if($img_h<$cel_h){$img_h=$cel_h;}
          if($img_h>=$cel_h){$img_h=$cel_h; $img_w=$img_rel*$img_h;}
          if($img_w>=$cel_w){$img_w=$cel_w; $img_h=$img_rel/$img_w;}
                                                                                                  
          if(mb_stristr($img_xy['mime'],'jpeg'))                                                                                                  
          {$docu_pdf->Image($xsrc,(($cel_w-$img_w)/2)+10,$docu_pdf->getY()+(($cel_h-$img_h)/2)+3,$img_w,$img_h,'JPG');}
          if(mb_stristr($img_xy['mime'],'png'))                                                                                                  
          {$docu_pdf->Image($xsrc,(($cel_w-$img_w)/2)+10,$docu_pdf->getY()+(($cel_h-$img_h)/2)+3,$img_w,$img_h,'PNG');}
//           {$docu_pdf->Image($xsrc,(($cel_w-$img_w)/2)+10,$docu_pdf->getY()+4,$img_w,$img_h,'JPG');}
//           if(mb_stristr($img_xy['mime'],'png'))                                                                                                  
//           {$docu_pdf->Image($xsrc,(($cel_w-$img_w)/2)+10,20,$img_w,$img_h,'PNG');}
                                                                                                  
          $docu_pdf->setY($posY1);                                                                                                  
          $docu_pdf->Cell($pdf_ancho*.6,30,'','LRTB',0,'C',false);
//           $docu_pdf->Cell($pdf_ancho*.6,5,'','',0,'C',false);
          $docu_pdf->ln();                                                                                                  
          $posY1=$docu_pdf->getY()+1;
        ?>
							<?php } ?>

                
						</tr>
					</table>
					</logo>
					<div style="font-size:25%;"><br></div>

					<?php ///// BLOQUE 1 ?>
					<?php if($margin_top==0){ ?>
					<?php //{ ?>
          <emite>
					<?php $enti_codigo=@mysql_result($res_emis,0,'enti_codigo'); ?>
					<?php $enti_razsoc=@mysql_result($res_emis,0,'enti_razsoc'); ?>
					<?php $enti_nomcom=@mysql_result($res_emis,0,'enti_nomcom'); ?>
					<table border="1" width="100%" cellpadding="2" cellspacing="5"
                 style="border-collapse:collapse; border-radius:10px;font-size:<?php echo $xfontsize; ?>px;<?php echo $xfontfamily;?>">
						<tr style="border:solid 1px; font-weight:bolder; background:#F7F7F7;">
							<td align="center" colspan=3 style="letter-spacing:10px" ><?php echo $lblruc1; ?></td>
						</tr>
						<tr valign="top">
							<td width="25%">RUC/C.I.</td>
							<td width="75%"><?php echo $enti_codigo; if($enti_codigo==''){echo '*** '.$enti_orig.' ***';} ?></td>
						</tr>
						<tr valign="top">
							<td>RAZ.SOCIAL</td>
							<td><?php echo @mysql_result($res_emis,0,'enti_razsoc');?></td>
						</tr>
						<?php if(trim(@mysql_result($res_emis,0,'enti_razsoc'))!=trim(@mysql_result($res_emis,0,'enti_nomcom')) and mysql_result($res_emis,0,'enti_nomcom')!=""){?>
						<tr valign="top">
							<td>NOM.COMERCIAL</td>
							<td><?php echo mysql_result($res_emis,0,'enti_nomcom');?></td>
						</tr>
						<?php } ?>
						
						<?php if(!mb_stristr('caja.bcos.inve.prod.nomi.cont',$tabla)){?>
						<tr valign="top">
							<td>MATRIZ</td>
							<td><?php echo @mysql_result($res_emis,0,'enti_matriz');?></td>
						</tr>
						<tr valign="top">
							<td>TELEFONO</td>
							<td><?php echo @mysql_result($res_emis,0,'enti_telefono');?></td>
						</tr>
						<tr valign="top">
							<td>E-MAIL</td>
							<td><?php echo strtolower(@mysql_result($res_emis,0,'enti_email'));?></td>
						</tr>
						<?php } ?>
						
					</table>
					<div style="font-size:25%;"><br></div>
          </emite>
          <?php
                                
             $docu_txt.=str_pad($lblruc1.' ',$coltxt,$carbot,STR_PAD_BOTH).$eol;
             $docu_txt.='RUC     : '.$enti_codigo.$eol;
             $docu_txt.='RAZ.SOC.: '.@mysql_result($res_emis,0,'enti_razsoc').$eol;
             if($enti_razsoc!=$enti_nomcom and $enti_nomcom!='')
             {$docu_txt.='NOM.COM.: '.@mysql_result($res_emis,0,'enti_nomcom').$eol;}
             $docu_txt.='MATRIZ  : '.trim(@mysql_result($res_emis,0,'enti_matriz')).$eol;
             $docu_txt.='TELEF.  : '.@mysql_result($res_emis,0,'enti_telefono').$eol;
             $docu_txt.='E-MAIL  : '.trim(@mysql_result($res_emis,0,'enti_email')).$eol;
             $docu_txt.=$eol;
          ?>
            
        <?php 
//           $posY1=48;
          $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-2);
          $docu_pdf->SetY($posY1);
          $docu_pdf->Cell($pdf_ancho*.6,5,$lblruc1,'LRTB',0,'C',true);
          $docu_pdf->ln();
          $docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-3);
          $docu_pdf->Cell($pdf_ancho*.2,5,'RUC :','LRT',0,'L',false);
          $docu_pdf->MultiCell($pdf_ancho*.4,5,$enti_codigo,'LRT','L',false);

//           $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-3);
          $docu_pdf->Cell($pdf_ancho*.2,5,'RAZ. SOCIAL :','LRT',0,'L',false);
          $docu_pdf->MultiCell($pdf_ancho*.4,5,@mysql_result($res_emis,0,'enti_razsoc'),'LRT','L',false);
//           $docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-3);

          if(trim(mysql_result($res_emis,0,'enti_razsoc'))!=trim(mysql_result($res_emis,0,'enti_nomcom')) and mysql_result($res_emis,0,'enti_nomcom')!="")
          {
          $docu_pdf->Cell($pdf_ancho*.2,5,'NOM. COMERCIAL :','LRT',0,'L',false);
          $docu_pdf->MultiCell($pdf_ancho*.4,5,@mysql_result($res_emis,0,'enti_nomcom'),'LRT','L',false);
          }  
          $docu_pdf->Cell($pdf_ancho*.2,5,'MATRIZ :','LRT',0,'L',false);
          $docu_pdf->MultiCell($pdf_ancho*.4,5,utf8_decode(@mysql_result($res_emis,0,'enti_matriz')),'LRT','L',false);
          $docu_pdf->Cell($pdf_ancho*.2,5,'TELEFONO :','LRT',0,'L',false);
          $docu_pdf->MultiCell($pdf_ancho*.4,5,@mysql_result($res_emis,0,'enti_telefono'),'LRT','L',false);
          $docu_pdf->Cell($pdf_ancho*.2,5,'E-MAIL :','LRT',0,'L',false);
          $docu_pdf->SetFontSize($fsizePDF-3);
          $docu_pdf->MultiCell($pdf_ancho*.4,5,strtolower(@mysql_result($res_emis,0,'enti_email')),'LRT','L',false);
          $docu_pdf->Cell($pdf_ancho*.2,1,'','T',0,'',false);
          $docu_pdf->MultiCell($pdf_ancho*.4,1,'','T','',false);
                                
          $posY1=$docu_pdf->getY();
                                
        ?>
						
					<?php}?>

					<?php ///// BLOQUE 2 ?>
					<?php
// 					if($guiaremi==0 and $formato!=2)
					if(!mb_stristr('guia.cont',$tabla))
					{
					?>
					<recibe>
					<table border="1" width="100%" cellpadding="2" cellspacing="0" 
								 style="border-collapse:collapse;font-size:<?php echo $xfontsize; ?>px;<?php echo $xfontfamily;?>"
								 >
						<tr style="border:solid 1px; font-weight:bolder; background: #F7F7F7;">
							<td align="center" colspan=2 style="letter-spacing:10px" ><?php echo $lblruc2; ?></td>
						</tr>
						<?php $enti_codigo=mysql_result($res_adqu,0,'enti_codigo'); ?>
						<?php $enti_razsoc=mysql_result($res_adqu,0,'enti_razsoc'); ?>
						<?php $enti_nomcom=mysql_result($res_adqu,0,'enti_nomcom'); ?>
        		<?php if($enti_razsoc==''){reg_cedruc($enti_codigo);}?>
						<?php if(mysql_result($res_adqu,0,'enti_tipoid')=='P'){$enti_codigo=mysql_result($res_adqu,0,'enti_pasaporte');}; ?>
						<tr valign="top">
							<td width="25%">RUC/C.I.</td>
							<td width="75%"><?php echo $enti_codigo;?></td>
						</tr>
						<tr valign="top">
							<td>RAZ. SOCIAL</td>
							<td><?php echo mysql_result($res_adqu,0,'enti_razsoc');?></td>
						</tr>
						<?php if(trim(mysql_result($res_adqu,0,'enti_razsoc'))!=trim(mysql_result($res_adqu,0,'enti_nomcom')) and mysql_result($res_adqu,0,'enti_nomcom')!=""){?>
						<tr valign="top">
							<td>NOM. COMERCIAL</td>
							<td><?php echo mysql_result($res_adqu,0,'enti_nomcom');?></td>
						</tr>
						<?php } ?>
						<?php $matriz=mysql_result($res_adqu,0,'enti_matriz');	?>
						<?php $direccion=mysql_result($res_adqu,0,'enti_direccion');	?>
						<?php $ciudad=mysql_result($res_adqu,0,'enti_ciudad');	?>
						<?php $calle1=mysql_result($res_adqu,0,'enti_calle1');	?>
						<?php $calle2=mysql_result($res_adqu,0,'enti_calle2');	?>
						<?php $calle3=mysql_result($res_adqu,0,'enti_calle3');	?>
						<?php $callen=mysql_result($res_adqu,0,'enti_callen');	?>
						<?php $parroq=@mysql_result($res_adqu,0,'enti_parroq');	?>
            <?php $parroq=r_fiel('enti',$enti_codigo,'enti_parroq'); ?>
						<?php $adqu_email1=mysql_result($res_adqu,0,'enti_email');	?>
						<?php $adqu_email2=mysql_result($res_adqu,0,'enti_emailce');	?>

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

						<?php if ($matriz!='' or 1==1){?>
						<tr valign="top">
							<td>MATRIZ</td>
							<td><?php echo $matriz.'<br>'.$parroq;?></td>
						</tr>
						<?php } ?>
						
						<?php if ($matriz=='' and strlen(trim($direccion))>5){?>
						<tr valign="top">
							<td>DIRECCION</td>
							<td><?php echo $direccion;?></td>
						</tr>
						<?php } ?>
						
						<?php if ($calle1!=''){?>
						<tr valign="top">
							<td>DIRECCION</td>
							<td>
              <?php echo $calle1.'('.$callen.') /'.$calle2;?>
							<?php if($calle3!=''){echo '<br>Ref: '.$calle3;}?>
              </td>
						</tr>
						<?php } ?>
						
						<tr valign="top">
							<td>TELEFONO</td>
							<td><?php echo mysql_result($res_adqu,0,'enti_telefono');?></td>
						</tr>
						<tr valign="top">
							<?php
								  $adqu_email2=str_replace($adqu_email1,'',$adqu_email2);

									$adqu_email=trim($adqu_email1).';'.trim($adqu_email2);
							    $adqu_email=str_replace(';','; ',$adqu_email); 
							    $adqu_email=str_replace(',','; ',$adqu_email); 
              ?>
							<td>E-MAIL</td>
							<td><?php echo strtolower($adqu_email);?></td>
						</tr>
						<?php } ?>
						
					</table>			
          <?php
             $docu_txt.=str_pad($lblruc2.' ',$coltxt,$carbot,STR_PAD_BOTH).$eol;
             $docu_txt.='RUC     : '.$en<?php
// TIRILLA WASAPP  caracteres

function selectpdf_usage()
{
	include('../_cfg/config.php');
	include('php_session.php');
	
	$api_usage = "https://selectpdf.com/api2/usage/?key=".$selectpdfkey."&get_history=True";
// 	echo $api_usage;
	$pdf_usage=file_get_contents($api_usage);
	$obj = json_decode($pdf_usage);	
// 	echo $obj->{'limit'};
// 	echo $obj->{'used'};
// 	echo $obj->{'available'};
	return;
}


function html2pdf($urlhtml,$filepdf)
{
  return;
	include('../_cfg/config.php');
	include('php_session.php');
	
	
	$api_endpoint = "https://selectpdf.com/api2/convert/";
// 	$selectpdfkey='a08354d5-92b4-4a2b-a1a4-ab82c90a5c78';
	
	$filepdf=str_replace('.pdf','',$filepdf).'.pdf';
	$parameters = array ('key' => $selectpdfkey, 'url' => $urlhtml, 'page_size' => 'A4');
 	$result = @file_get_contents("$api_endpoint?" . http_build_query($parameters));
 
	if (!$result)
	{	
		echo "HTTP Response: " . $http_response_header[0] . "<br/>";
		$error = error_get_last();
		echo "Error Message: " . $error['message'];
	}
	else
	{file_put_contents($filepdf, $result);}	
}

function pdf_sri($docu,$idnum)
{
include('../_cfg/config.php');
include('php_session.php');
mysql_query("SET NAMES 'utf8'");  

// 	$ttfont = '../../_font/BarcodeFont.ttf';
// 	if(strlen($cadena)==13){$ttfont = '../../_font/EAN13_36.ttf';}// ean 13
	
	$tabla=r_fiel('docu',$docu,'tabla');
	$sql_docu='select * from '.$tabla.'12 where idnum1="'.$idnum.'" order by iddet';
	$res_docu=mysql_query($sql_docu,$link_vcrx);

	$sql_emis='select * from enti0 where enti_codigo="'.$cfg_ruc.'"';
	$res_emis=mysql_query($sql_emis,$link_vcrx);
//   echo $sql_emis;

	$sql_rece='select * from enti0 where enti_codigo="'.mysql_result($res_docu,0,'enti').'"';
	$res_rece=mysql_query($sql_rece,$link_vcrx);

  
  
//   $docu_descri='FACTURA';
  
	if(substr($docu,0,1)=='F')
  {
    $docu_descri='FACTURA';

//     $prov_ruc=$cfg_ruc;
//     $clie_ruc=mysql_result($res_docu,0,'enti');    
    
//     $prov_descri=r_fiel('enti',$prov_ruc,'enti_descri');
//     $prov_razsoc=r_fiel('enti',$prov_ruc,'enti_razsoc');
//     $prov_nomcom=r_fiel('enti',$prov_ruc,'enti_nomcom');
//     $prov_matriz=r_fiel('enti',$prov_ruc,'enti_matriz');
//     $prov_direcc=r_fiel('enti',$prov_ruc,'enti_matriz');
//     $prov_telefo=r_fiel('enti',$prov_ruc,'enti_telefono');
    
//     $clie_nomcom=r_fiel('enti',$clie_ruc,'enti_nomcom');
//     $clie_descri=r_fiel('enti',$clie_ruc,'enti_descri');
//     $clie_razsoc=r_fiel('enti',$clie_ruc,'enti_razsoc');
//     $clie_matriz=r_fiel('enti',$clie_ruc,'enti_matriz');
//     $clie_direcc=r_fiel('enti',$clie_ruc,'enti_matriz');
//     $clie_telefo=r_fiel('enti',$clie_ruc,'enti_telefono');
    
  }
	if(substr($docu,0,1)=='R')
  {
    $docu_descri='COMPROBANTE DE RETENCION';
    
//     $clie_ruc=$cfg_ruc;
//     $prov_ruc=mysql_result($res_docu,0,'enti');    


//     $prov_descri=r_fiel('enti',$prov_ruc,'enti_descri');
//     $prov_razsoc=r_fiel('enti',$prov_ruc,'enti_razsoc');
//     $prov_nomcom=r_fiel('enti',$prov_ruc,'enti_nomcom');
//     $prov_matriz=r_fiel('enti',$prov_ruc,'enti_matriz');
//     $prov_direcc=r_fiel('enti',$prov_ruc,'enti_matriz');
//     $prov_telefo=r_fiel('enti',$prov_ruc,'enti_telefono');
    
//     $clie_nomcom=r_fiel('enti',$clie_ruc,'enti_nomcom');
//     $clie_descri=r_fiel('enti',$clie_ruc,'enti_descri');
//     $clie_razsoc=r_fiel('enti',$clie_ruc,'enti_razsoc');
//     $clie_matriz=r_fiel('enti',$clie_ruc,'enti_matriz');
//     $clie_direcc=r_fiel('enti',$clie_ruc,'enti_matriz');
//     $clie_telefo=r_fiel('enti',$clie_ruc,'enti_telefono');
  }
	
	$concepto=(mysql_result($res_docu,0,'concepto'));
	$claveacc=@mysql_result($res_docu,0,'claveacc');
  $autorfec=@mysql_result($res_docu,0,'autorfec');
  if($autorfec=='')
  {$autorfec=@mysql_result($res_docu,0,'fecha');}
    
	$ambice=substr($claveacc,23,1);
	if($claveacc==''){return;}
	if($ambice=='1'){$ambice='PRUEBAS';}
	if($ambice=='2'){$ambice='PRODUCCION';}

// 	$enti=mysql_result($res_docu,0,'enti');
// 	$direccion=r_fiel('enti',$enti,'enti_matriz');
// 	$telefono=r_fiel('enti',$enti,'enti_telefono');
	
	
	gen_bcod($claveacc);
  $xsrc='http://vcrxol.com/_bcod/'.$claveacc.'.jpg'; 
  
  $ffamilyPDF='Arial';
//   $ffamilyPDF="'Arial'";
	
	
  $docu_pdf = new FPDF('P','mm', 'A4');
  $docu_pdf->AddPage();
  $pdf_ancho=$docu_pdf->GetPageWidth()-10;
	 
	$docu_pdf->SetFont($ffamilyPDF,'',10);
	$docu_pdf->SetLineWidth(0.1);
	
	$docu_pdf->Rect(5, 65, 							$pdf_ancho*.495, 55,'D');	
	$docu_pdf->Rect($pdf_ancho*.53, 10, $pdf_ancho*.495, 110,'D');	
	$docu_pdf->Rect(5, 125, $pdf_ancho, 15,'D');	

	$docu_pdf->SetLeftMargin(5);
	$docu_pdf->SetY(17);
	$docu_pdf->SetFont($ffamilyPDF,'B',34);
	$docu_pdf->SetTextColor(250,0,0);
	
  $xsrcl='http://vcrxol.com/_logo/'.$logofile2;
//   $xsrcl='http://vcrxol.com/_bcod/'.$claveacc.'.jpg'; 
//   if(mb_stristr(strtoupper($xsrcl),'.JP'))
  if(file_exists($xsrcl))
  {$docu_pdf->Image($xsrcl,30,20,30,0,'JPG');}
  else
  {$docu_pdf->Write(5,'NO TIENE LOGO');}
  
	$docu_pdf->SetFont($ffamilyPDF,'',8);
	$docu_pdf->SetTextColor(0,0,0);
	
	$docu_pdf->SetLeftMargin(10);
	$docu_pdf->SetY(67);
	$docu_pdf->SetFontSize(8);
	$docu_pdf->Write(5,mysql_result($res_emis,0,'enti_razsoc'));
	$docu_pdf->ln(10);
	$docu_pdf->Write(5,mysql_result($res_emis,0,'enti_nomcom'));
	$docu_pdf->ln(10);
// 	$docu_pdf->Write(5,'Dirección    '.mysql_result($res_docu,0,'enti_matriz'));
	$docu_pdf->Write(5,utf8_decode('Dirección    '.mysql_result($res_emis,0,'enti_matriz')));
	$docu_pdf->ln(3);
	$docu_pdf->Write(5,'Matriz:');
	$docu_pdf->ln(10);
	$docu_pdf->Write(5,utf8_decode('Dirección    '.mysql_result($res_emis,0,'enti_matriz')));
	$docu_pdf->ln(3);
	$docu_pdf->Write(5,'Sucursal:');
	$docu_pdf->ln(10);
  if(mysql_result($res_docu,0,'enti_obcon')=='1'){$obcon='SI';}else{$obcon='NO';}
	$docu_pdf->Write(5,'OBLIGADO A LLEVAR CONTABILIDAD : '.$obcon);
	
	$docu_pdf->SetLeftMargin($pdf_ancho*.53);
	$docu_pdf->SetY(12);
	$docu_pdf->SetFontSize(13);
	$docu_pdf->Write(5,'R.U.C.:       '.mysql_result($res_emis,0,'enti_codigo'));
	$docu_pdf->ln(10);
	$docu_pdf->SetFontSize(15);
	$docu_pdf->Write(5,$docu_descri);
	$docu_pdf->ln(10);	
	$docu_pdf->SetFontSize(8);
	$docu_pdf->Write(5,'No.         '.mysql_result($res_docu,0,'ptonumero'));
	$docu_pdf->ln(10);
	$docu_pdf->Write(5,'NUMERO DE AUTORIZACION');
	$docu_pdf->ln();	
	$docu_pdf->Write(5,mysql_result($res_docu,0,'claveacc'));
	$docu_pdf->ln(10);
	$docu_pdf->Write(5,'FECHA Y HORA DE ');
	$docu_pdf->ln(3);
// 	$docu_pdf->Write(5,'AUTORIZACION:                    '.date('d/m/y H:i:s',strtotime(@mysql_result($res_docu,0,'autorfec'))));
	$docu_pdf->Write(5,'AUTORIZACION:                    '.date('d/m/y H:i:s',strtotime($autorfec)));
	$docu_pdf->ln(10);
	$docu_pdf->Write(5,'AMBIENTE:                    	       '.$ambice);
	$docu_pdf->ln(10);
	$docu_pdf->Write(5,'EMISION:                                '.'NORMAL');
	$docu_pdf->ln(10);
	$docu_pdf->Write(5,'CLAVE DE ACCESO');
	$docu_pdf->Image($xsrc,$pdf_ancho*.54,95,$pdf_ancho*.5,20,'JPG');

	$docu_pdf->SetLeftMargin(5);
	$docu_pdf->SetY(125);
	$docu_pdf->Write(5,utf8_decode('Razón Social / Nombres y                           '.mysql_result($res_rece,0,'enti_razsoc')));
	$docu_pdf->ln();
	$docu_pdf->Write(5,utf8_decode('Identificación           '.mysql_result($res_rece,0,'enti_codigo')));
	$docu_pdf->ln();
	$docu_pdf->Write(5,'Fecha                      '.date('d/m/Y',strtotime(mysql_result($res_docu,0,'fecha'))));


  
	if(substr($docu,0,1)=='F')
  {
    $docu_pdf->SetFontSize(7);
    $posY=145;
    $posX=5;
    
    $col_width=$pdf_ancho*.068;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,'Cod. Principal','LRTB','C',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.068;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,utf8_decode('Cod. Auxiliar'),'LRTB','C',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.068;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,9,utf8_decode('Cantidad'),'LRTB','C',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.186;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,9,utf8_decode('Descripción'),'LRTB','C',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.135;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,9,utf8_decode('Detalle Adicional'),'LRTB','C',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.095;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,9,'Precio Unitario','LRTB','C',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.095;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,9,'Subsidio','LRTB','C',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.095;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,'Precio sin Subsidio','LRTB','C',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.095;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,9,'Descuento','LRTB','C',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.095;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,9,'Precio Total','LRTB','C',false);
    $posX=$posX+$col_width;

    $tsubtiva0=0;
    $tsubtiva12=0;
    $tnooiva=0;
    $texeiva=0;
    $tsinimp=0;
    $tdcto=0;
    $tice=0;
    $tiva=0;
    $tirbp=0;
    $tprop=0;
    $total=0;
    
    $docu_pdf->SetFontSize(7);
    
    $res_docu=mysql_query($sql_docu,$link_vcrx);
    while($aso_docu=mysql_fetch_assoc($res_docu))
    {
      $docum_descri=$aso_docu['docum_descri'];
      if(substr($docum_descri,0,1)=='F'){$docum_descri='FACTURA';}
      $impto_descri='IVA';
      if(@mb_stristr('3.4',substr($aso_docu['cair'],0,1))){$impto_descri='Impuesto a la Renta';}

      $docu_pdf->SetFontSize(6.5);
      $posY=$posY+9;
      $posX=5;

      $col_width=$pdf_ancho*.068;
      $docu_pdf->SetXY($posX,$posY);
      $docu_pdf->MultiCell($col_width,9,$aso_docu['item'],'LRTB','C',false);
      $posX=$posX+$col_width;

      $col_width=$pdf_ancho*.068;
      $docu_pdf->SetXY($posX,$posY);
      $docu_pdf->MultiCell($col_width,9,$aso_docu['item'],'LRTB','C',false);
      $posX=$posX+$col_width;

      $col_width=$pdf_ancho*.068;
      $docu_pdf->SetXY($posX,$posY);
      $docu_pdf->MultiCell($col_width,9,$aso_docu['cant'],'LRTB','R',false);
      $posX=$posX+$col_width;

      $col_width=$pdf_ancho*.186;
      $docu_pdf->SetXY($posX,$posY);
      $docu_pdf->MultiCell($col_width,4.5,utf8_decode($aso_docu['item_descri']),'LRTB','L',false);
      $posX=$posX+$col_width;

      $col_width=$pdf_ancho*.135;
      $docu_pdf->SetXY($posX,$posY);
      $docu_pdf->MultiCell($col_width,4.5,utf8_decode($aso_docu['detalle']),'LRTB','C',false);
      $posX=$posX+$col_width;

      $col_width=$pdf_ancho*.095;
      $docu_pdf->SetXY($posX,$posY);
      $docu_pdf->MultiCell($col_width,9,number_format($aso_docu['puni'],2,'.',''),'LRTB','R',false);
      $posX=$posX+$col_width;

      $col_width=$pdf_ancho*.095;
      $docu_pdf->SetXY($posX,$posY);
      $docu_pdf->MultiCell($col_width,9,number_format(0,2,'.',''),'LRTB','R',false);
      $posX=$posX+$col_width;

      $col_width=$pdf_ancho*.095;
      $docu_pdf->SetXY($posX,$posY);
      $docu_pdf->MultiCell($col_width,9,number_format(0,2,'.',''),'LRTB','R',false);
      $posX=$posX+$col_width;

      $col_width=$pdf_ancho*.095;
      $docu_pdf->SetXY($posX,$posY);
      $docu_pdf->MultiCell($col_width,9,number_format($aso_docu['tdcto'],2,'.',''),'LRTB','R',false);
      $posX=$posX+$col_width;

      $col_width=$pdf_ancho*.095;
      $docu_pdf->SetXY($posX,$posY);
      $docu_pdf->MultiCell($col_width,9,number_format($aso_docu['tsubt'],2,'.',''),'LRTB','R',false);
      $posX=$posX+$col_width;

      $tsubtiva0+=$aso_docu['tsubtiva0'];
      $tsubtiva12+=$aso_docu['tsubtiva12'];
      $tnooiva=0;
      $texeiva=0;
      $tsinimp=0;
      $tdcto+=$aso_docu['tdcto'];
      $tice+=$aso_docu['tice'];
      $tiva+=$aso_docu['tiva'];
      $tirbp+=$aso_docu['tirbp'];
      $tprop=0;
      $total+=$aso_docu['total'];
      
    }			

    

    $posY=$posY+10;
    $docu_pdf->SetY($posY+1);
    $docu_pdf->SetFontSize(7);
    $docu_pdf->SetLeftMargin(5);
    $docu_pdf->MultiCell($pdf_ancho*.6,5,utf8_decode('Información Adicional'),'LRTB','C',false);

    $docu_pdf->MultiCell($pdf_ancho*.6,5,utf8_decode('Descripción:                               '.$concepto),'LR','L',false);
    $docu_pdf->MultiCell($pdf_ancho*.6,5,utf8_decode('Dirección:                                    '.$direccion),'LR','L',false);
    $docu_pdf->MultiCell($pdf_ancho*.6,5,utf8_decode('Teléfono:                                     '.$telefono),'LR','L',false);
    $docu_pdf->MultiCell($pdf_ancho*.6,5,'','T','L',false);

    
    
    $posY=$posY-1;
    
    $posX=$pdf_ancho*.645;
    $col_width=$pdf_ancho*.285;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,'SUBTOTAL 12%','LRTB','L',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.095;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,number_format($tsubtiva12,2,'.',''),'LRTB','R',false);
    $posX=$posX+$col_width;
    $posY=$posY+4.5;
 
    $posX=$pdf_ancho*.645;
    $col_width=$pdf_ancho*.285;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,'SUBTOTAL 0%','LRTB','L',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.095;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,number_format($tsubtiva0,2,'.',''),'LRTB','R',false);
    $posX=$posX+$col_width;
    $posY=$posY+4.5;
 
    $posX=$pdf_ancho*.645;
    $col_width=$pdf_ancho*.285;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,'SUBTOTAL NO OBJETO DE IVA','LRTB','L',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.095;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,number_format($tnooiva,2,'.',''),'LRTB','R',false);
    $posX=$posX+$col_width;
    $posY=$posY+4.5;
 
    $posX=$pdf_ancho*.645;
    $col_width=$pdf_ancho*.285;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,'SUBTOTAL EXENTO DE IVA','LRTB','L',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.095;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,number_format($texeiva,2,'.',''),'LRTB','R',false);
    $posX=$posX+$col_width;
    $posY=$posY+4.5;
 
    $posX=$pdf_ancho*.645;
    $col_width=$pdf_ancho*.285;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,'SUBTOTAL SIN IMPUESTOS','LRTB','L',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.095;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,number_format($tsubtiva0+$tsubtiva12,2,'.',''),'LRTB','R',false);
    $posX=$posX+$col_width;
    $posY=$posY+4.5;
 
    $posX=$pdf_ancho*.645;
    $col_width=$pdf_ancho*.285;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,'TOTAL DESCUENTO','LRTB','L',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.095;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,number_format($tdcto,2,'.',''),'LRTB','R',false);
    $posX=$posX+$col_width;
    $posY=$posY+4.5;
 
    $posX=$pdf_ancho*.645;
    $col_width=$pdf_ancho*.285;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,'ICE','LRTB','L',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.095;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,number_format($tice,2,'.',''),'LRTB','R',false);
    $posX=$posX+$col_width;
    $posY=$posY+4.5;
 
    $posX=$pdf_ancho*.645;
    $col_width=$pdf_ancho*.285;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,'IVA','LRTB','L',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.095;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,number_format($tiva,2,'.',''),'LRTB','R',false);
    $posX=$posX+$col_width;
    $posY=$posY+4.5;
 
    $posX=$pdf_ancho*.645;
    $col_width=$pdf_ancho*.285;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,'IRBPNR','LRTB','L',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.095;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,number_format($tirbp,2,'.',''),'LRTB','R',false);
    $posX=$posX+$col_width;
    $posY=$posY+4.5;
 
    $posX=$pdf_ancho*.645;
    $col_width=$pdf_ancho*.285;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,'PROPINA','LRTB','L',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.095;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,number_format($tprop,2,'.',''),'LRTB','R',false);
    $posX=$posX+$col_width;
    $posY=$posY+4.5;
 
    $posX=$pdf_ancho*.645;
    $col_width=$pdf_ancho*.285;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,'TOTAL','LRTB','L',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.095;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,number_format($total,2,'.',''),'LRTB','R',false);
    $posX=$posX+$col_width;
    $posY=$posY+4.5;
 
    $posY=$posY+1;
    $posX=$pdf_ancho*.645;
    $col_width=$pdf_ancho*.285;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,'VALOR TOTAL SIN SUBSIDIO','LT','L',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.095;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,number_format(0,2,'.',''),'RT','R',false);
    $posX=$posX+$col_width;
    $posY=$posY+4.5;
 
    $posX=$pdf_ancho*.645;
    $col_width=$pdf_ancho*.285;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,'AHORRO POR SUBSIDIO','L','L',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.095;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,number_format(0,2,'.',''),'R','R',false);
    $posX=$posX+$col_width;
    $posY=$posY+4.5;
    $posX=$pdf_ancho*.645;
    $col_width=$pdf_ancho*.285;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,'Incluye IVA cuando corresponda','LB','L',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.095;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,'','RB','R',false);
    $posX=$posX+$col_width;
    $posY=$posY+4.5;
 
    
    $docu_pdf->AddPage();
  }
  
  
  
	if(substr($docu,0,1)=='R')
  {
    $posY=145;
    $posX=5;

    $col_width=$pdf_ancho*.12;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,9,'Comprobante','LRTB','C',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.1;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,9,utf8_decode('Número'),'LRTB','C',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.12;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,9,utf8_decode('Fecha Emisión'),'LRTB','C',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.08;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,'Ejercicio Fiscal','LRTB','C',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.15;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,utf8_decode('Base Imponible para la Retención'),'LRTB','C',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.18;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,9,'Impuesto','LRTB','C',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.1;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,4.5,'Porcentaje Retencion','LRTB','C',false);
    $posX=$posX+$col_width;

    $col_width=$pdf_ancho*.15;
    $docu_pdf->SetXY($posX,$posY);
    $docu_pdf->MultiCell($col_width,9,'Valor Retenido','LRTB','C',false);

    $docu_pdf->SetFontSize(7);
    $res_docu=mysql_query($sql_docu,$link_vcrx);
  // 	$docu_pdf->Cell($col_width,10,'ERROR:'.mysql_error(),0,'LRTB','C',false);
    while($aso_docu=mysql_fetch_assoc($res_docu))
    {
      $docum_descri=$aso_docu['docum_descri'];
      if(substr($docum_descri,0,1)=='F'){$docum_descri='FACTURA';}
      $impto_descri='IVA';
      if(@mb_stristr('3.4',substr($aso_docu['cair'],0,1))){$impto_descri='Impuesto a la Renta';}

      $posY=$posY+9;
      $posX=5;

      $col_width=$pdf_ancho*.12;
      $docu_pdf->SetXY($posX,$posY);
      $docu_pdf->MultiCell($col_width,9,$docum_descri,'LRTB','C',false);
      $posX=$posX+$col_width;

      $col_width=$pdf_ancho*.1;
      $docu_pdf->SetXY($posX,$posY);
      $docu_pdf->MultiCell($col_width,4.5,$aso_docu['ptoem'].$aso_docu['numer'],'LRTB','L',false);
      $posX=$posX+$col_width;

      $col_width=$pdf_ancho*.12;
      $docu_pdf->SetXY($posX,$posY);
      $docu_pdf->MultiCell($col_width,9,date('d/m/Y',strtotime($aso_docu['fecha'])),'LRTB','L',false);
      $posX=$posX+$col_width;

      $col_width=$pdf_ancho*.08;
      $docu_pdf->SetXY($posX,$posY);
      $docu_pdf->MultiCell($col_width,9,date('m/Y',strtotime($aso_docu['fecha'])),'LRTB','C',false);
      $posX=$posX+$col_width;

      $col_width=$pdf_ancho*.15;
      $docu_pdf->SetXY($posX,$posY);
      $docu_pdf->MultiCell($col_width,9,number_format($aso_docu['cant'],2,'.',''),'LRTB','C',false);
      $posX=$posX+$col_width;

      $col_width=$pdf_ancho*.18;
      $docu_pdf->SetXY($posX,$posY);
      $docu_pdf->MultiCell($col_width,9,$impto_descri,'LRTB','C',false);
      $posX=$posX+$col_width;

      $col_width=$pdf_ancho*.1;
      $docu_pdf->SetXY($posX,$posY);
      $docu_pdf->MultiCell($col_width,9,number_format($aso_docu['puni'],1,'.',''),'LRTB','C',false);
      $posX=$posX+$col_width;

      $col_width=$pdf_ancho*.15;
      $docu_pdf->SetXY($posX,$posY);
      $docu_pdf->MultiCell($col_width,9,number_format(abs($aso_docu['total']),2,'.',''),'LRTB','R',false);

    }			

    $posY=$posY+15;

    $docu_pdf->Rect(5, $posY,$pdf_ancho*.65, 45,'D');
    $docu_pdf->Rect(10, $posY+10,$pdf_ancho*.6, 20,'D');

    $docu_pdf->SetFontSize(10);
    $docu_pdf->SetY($posY+1);
    $docu_pdf->SetX(40);
    $docu_pdf->Write(5,utf8_decode('Información Adicional'));

    $docu_pdf->SetFontSize(7);
    $docu_pdf->SetY($posY+10);
    $docu_pdf->SetX(10);
    $docu_pdf->MultiCell($pdf_ancho*.6,5,utf8_decode('Información Adicional'),'B','C',false);

    $docu_pdf->SetLeftMargin(10);
    $docu_pdf->MultiCell($pdf_ancho*.6,5,utf8_decode('Descripción:                               '.$concepto),'LR','L',false);
    $docu_pdf->MultiCell($pdf_ancho*.6,5,utf8_decode('Dirección:                                    '.$direccion),'LR','L',false);
    $docu_pdf->MultiCell($pdf_ancho*.6,5,utf8_decode('Teléfono:                                     '.$telefono),'LR','L',false);
    $docu_pdf->MultiCell($pdf_ancho*.6,5,'','T','L',false);
  }

  $subdce=mk_subdce($claveacc);
  @unlink($rutace.$subdce.$claveacc.'.pdf');
  $docu_pdf->Output('F',$rutace.$subdce.$claveacc.'.pdf',true);
  	
}


function prnt_docu0($docu,$idnum,$formato=1,$destino='screen')
{
include('../_cfg/config.php');
include('php_session.php');
// vrupdcol('retc1','toenti', 'varchar(13)','','');
// echo 'I0 :'.Date('H:i:s',strtotime('now'));

// if(mb_stristr('amay',$cfg_empr)){$formato=1;}
  
  
$docu=trim($docu);
$sql_docu='select * from docu0 where docu_codigo like "'.$docu.'%"';
$res_docu=mysql_query($sql_docu,$link_vcrx);
	
if(mb_stristr('DD.DT.DI',substr($docu,0,2))){$formato=1;}
$tabla=strtolower(mysql_result($res_docu,0,'docu_tabla'));	
$ppsize=mysql_result($res_docu,0,'docu_ppsize');	
$pporient=mysql_result($res_docu,0,'docu_pporient');	

$width=mysql_result($res_docu,0,'docu_width');	
$height=mysql_result($res_docu,0,'docu_height');	 
$orient=mysql_result($res_docu,0,'docu_orient');	

$doble=mysql_result($res_docu,0,'docu_doble');	
$copia=mysql_result($res_docu,0,'docu_copia');	
	
if($ppsize==''){$ppsize='A4';}
if($pporient==''){$pporient='V';}
if($width==0){$width=210;}
if($height==0){$width=297;}
if($orient==''){$orient='V';}	
if($copia==0){$copia=1;}	

if($user_codigo=='')
{
	$ppsize='A4';
	$pporient='V';
	$width=210;
	$height=297;
	$orient='V';
	$copia=1;
}	

  
//$sql_tra1='select * from '.$tabla.'11 where idnum1="'.$idnum.'"';
$sql_tra1='select * from '.$tabla.'1 where idnum1="'.$idnum.'"';
$res_tra1=mysql_query($sql_tra1,$link_vcrx);	
// echo $sql_tra1;
// echo explain_sql($sql_tra1);

// if(mb_stristr('caja.bcos',$tabla) and substr($docu,2,2)=="13")
// {gen_caba13($docu,$idnum);}
	
// if(mb_stristr('inve',$tabla) and substr($docu,2,2)=="13")
// {gen_inve13($docu,$idnum);}

// $xenti=@mysql_result($res_tra1,0,'enti_descri');
// $xenti=@mysql_result($res_tra1,0,'enti');
$xenti=@mysql_result($res_tra1,0,'enti');
$xentidesc=r_fiel('enti',$xenti);
$xptonumero=@mysql_result($res_tra1,0,'ptonumero');
$xptoe=@mysql_result($res_tra1,0,'ptoe');
$xnumero=@mysql_result($res_tra1,0,'numero');
$xstatus=@mysql_result($res_tra1,0,'status');

$filelogo=$rutalogo.$logofile2;	


$docu1=prnt_docu2($docu,$idnum,$formato,$destino);
  
// if($formato==1 and mb_stristr('FP.FC',substr($docu,0,2)))  
if($formato!=2 and substr($docu,0,2)=='FP')  
{
	$docur=prnt_docur($docu,$xptoe,$xnumero,$xenti,$destino);
	$docu1=str_replace('</footer1>','</footer1>'.$docur,$docu1);
	$docu1=str_replace('</footer1>','</footer1><br>',$docu1);
} 
  
if($formato==3 )	
{
	if(mb_stristr('retc.retp',$tabla))
	{
		$sql_rete ='select idnum1,docu,numero,fecha,enti from '.$tabla.'1';
		$sql_rete.=' where enti="'.mysql_result($res_tra1,0,'enti').'" ';
		$sql_rete.=' and numero="'.mysql_result($res_tra1,0,'numero').'" ';
		$sql_rete.=' and fecha="'.mysql_result($res_tra1,0,'fecha').'" ';
		$sql_rete.=' and status!="O" and status!="X"';
		$sql_rete.=' order by idnum1 desc';
		$res_rete=mysql_query($sql_rete,$link_vcrx);	
		$docu1=str_replace('</footer1>','</footer1><br>',$docu1);
		while($aso_rete=mysql_fetch_assoc($res_rete))
		{
			$docu2=prnt_docu2($aso_rete['docu'],$aso_rete['idnum1'],'2',$destino);
			$docu2=substr($docu2,strpos($docu2,'<detalle>'));
			$docu2=substr($docu2,0,strpos($docu2,'</detalle>')+10);
			$docu1=str_replace('</footer1>','</footer1>'.$docu2,$docu1);
		}
		$docu1=str_replace('</footer1>','</footer1><br>',$docu1);
	}
	else
	{
		$docu2=prnt_docu2($docu,$idnum,'2',$destino);
		$docu1=str_replace('</footer1>','</footer1><br>',$docu1);
		$docu2=substr($docu2,strpos($docu2,'<detalle>'));
		$docu2=substr($docu2,0,strpos($docu2,'</detalle>')+10);
		$docu1=str_replace('</footer1>','</footer1>'.$docu2,$docu1);
		$docu1=str_replace('</footer1>','</footer1><br>',$docu1);
		
	}
}

  
  
?>

  <?php $xfontsize=12; ?>
  <?php $xfontfamily='font-family:arial;';  ?>
  <?php
//     if($cfg_empr=='ecgl' and mb_stristr('FC',substr($docu,0,2)))
//     {$xfontsize+=2; $xfontfamily='font-family:Courier New; font-weight:bolder;';}
  ?>
  <?php
//     if($cfg_empr=='dly1' and mb_stristr('FC.PC',substr($docu,0,2)) and $destino!='mail' and $cdisplay==2)
//     {$xfontsize+=2; $xfontfamily='font-family:Courier New; font-weight:bolder;';$doculogo=0;}
  ?>

  <?php
    if(mb_stristr('pos.txt',$destino))
    {$xfontsize-=4; $xfontfamily='font-family:Courier New; font-weight:bolder; white-space:pre-wrap; width:55mm; ';}
  ?>

<?php ob_start(); ?>
<?php //////////////////////////////////////////////////////////	?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php //////////////////////////////////////////////////////////	?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title><?php echo $docu.'-'.$xptonumero.'-'.$xentidesc; ?></title>
	
<style type="text/css">

p.saltodepagina
{page-break-after: always;}
/* <p class="saltodepagina" /></p>	 */

  
#header
{
	display:none;
}

/* @font-face {font-family:'EanP36Tt'; src:url('../_font/EAN13_36.ttf') format('truetype');} */
@font-face {font-family:'Barcode'; src:url('/_font/BarcodeFont.ttf') format('truetype');}
	
/* ean13 {font-family:'EanP36Tt';} */
barcode {font-family:'Barcode';}
	
@media print {.noprint {display:none}}
@media screen{.noscreen {display:none}}
	
@page
{
size: <?php echo $ppsize.' '; if($pporient=='V'){echo ' portrait';}else{echo ' landscape';}; ?>
	
<?php if($copia==1) { ?>
margin: 10mm 10mm 10mm 10mm; /* 	top right bottom left */
<?php } ?>
	
<?php if($copia==2 and $pporient=='V') { ?>
margin: 10mm 5mm 10mm 5mm; /* 	top right bottom left */
<?php } ?>

<?php if($copia==2 and $pporient=='H') { ?>
margin: 10mm 10mm 10mm 10mm; /* 	top right bottom left */
<?php } ?>

<?php if($copia>=3 and $pporient=='V') { ?>
margin: 10mm 10mm 10mm 10mm; /* 	top right bottom left */
<?php } ?>

<?php if($copia>=3 and $pporient=='H') { ?>
margin: 10mm 10mm 10mm 10mm; /* 	top right bottom left */
<?php } ?>

}
</style>
<script type="text/javascript" src="http://vcrxol.com/_js/js_gene1.js"></script>

</head>
<?php //////////////////////////////////////////////////////////	?>

<?php //////////////////////////////////////////////////////////	?>
<body>
<?php //echo $docu1; ?>  
<div style="font-size:<?php echo $xfontsize; ?>;<?php echo $xfontfamily; ?>">
  
<?php if($copia==1){echo $docu1;} ?>
	
<?php
if($copia==2 and $pporient=='H')
{
?>
	<table border="0" width="100%" cellpadding="0" cellspacing="10mm" style="border-collapse:collapse;">
		<tr>
			<td width="50%" align="left"><?php echo $docu1; ?></td>
			<td width="50%" align="right"><?php echo $docu1; ?></td>
		</tr>
	</table>
<?php
}
?>
	
<?php
if($copia==2 and $pporient=='V')
{
?>
	<table border="0" width="100%" cellpadding="0" cellspacing="0" style="border-collapse:collapse;">
		<tr><td width="100%" align="center"><?php echo $docu1; ?></td></tr>
		<tr><td width="100%" align="center"><?php echo $docu1; ?></td></tr>
	</table>
<?php
}
?>

<?php
if($copia>=3)
{
?>
	<table border="0" width="100%" cellpadding="0" cellspacing="0" style="border-collapse:collapse;">
		<tr>
			<td width="50%" align="left"><?php echo $docu1; ?></td>
			<td width="50%" align="right"><?php echo $docu1; ?></td>
		</tr>
		<tr>
			<td width="50%" align="left"><?php echo $docu1; ?></td>
			<td width="50%" align="right"><?php echo $docu1; ?></td>
		</tr>
	</table>
<?php
}
?>
	
</div>	
</body>	
<?php //////////////////////////////////////////////////////////	?>

</html>

	
	
<?php	
// 		echo $expla;

$docuhtml = ob_get_clean(); 
// $docuhtml=alltrim($docuhtml);
$docu_idnum=$docu.'_'.str_pad($idnum,9,"0",STR_PAD_LEFT);	
file_put_contents($rutadoc.$docu_idnum.'.html',$docuhtml);
// if(substr($xclaveacc,10,13)==$cfg_ruc or $cfg_empr=='demo')
// {file_put_contents($rutace.$xclaveacc.'.html',$docuhtml);}


return $docuhtml;	
	
}
?>



<?php
function prnt_docu2($docu,$idnum,$formato=1,$destino='screen')
{
	
$mtime=microtime(true);
$nota1='';	
$eol="<br>";
$eol=" \r\n";  
// if($destino=='screen'){$eol="<br>";}
// if($destino=='file'){$eol=" \r\n";}
$coltxt=40;
$padtxt=' ';
$carbot='- ';
  
// ob_start();
// 		formatos
// 			1 - general
// 			2 - diario contable (directo de la tabla cont1)
// 			3 - diario contable (desde el modulo a cont.idfrom)
//			5 - egreso detallado
	
// 		destino
// 			screen
// 			mat tricial
// 			txt pos 
	
// echo sal_docu($docu,$idnum);	
	include('../_cfg/config.php');
 	include('php_session.php');
  mysql_query("SET NAMES 'utf8'");  
	
//   if($destino=='pdf')
    
//   upl_cexml('2002201804099007196900120040030000006910000069119');
// 	$empr_cont=@mysql_result($res_emis,0,'empr_cont');
	$empr_cont=r_fiel('empr',$cfg_empr,'empr_cont');

  if($formato=='2' and $empr_cont!='1'){return; }
  
	$tabla=r_fiel('docu',$docu,'tabla');

if($cfg_empr=='pcs1')
{
//   $sql_cele='update '.$tabla.'1 set stfin=null where idnum1="'.$idnum.'"';
//   $res_cele=mysql_query($sql_cele,$link_vcrx);
}  

  
	if(mb_stristr('PC.PP',substr($docu,0,2))){gen_claveacc($docu,$idnum);}
	if(mb_stristr('FC',substr($docu,0,2))){$serie_lote=get_serie_lote($idnum);}
	if(mb_stristr('FP',substr($docu,0,2))){updt_itemce($idnum);updt_ctascomp($idnum);}
	if(mb_stristr('RP.RC',substr($docu,0,2))){val_rete($docu,$idnum);}
	if(mb_stristr('DD.DT.DI',substr($docu,0,2))){$formato=1;}
	if(mb_stristr('NC.NP',substr($docu,0,2))){val_ncre($docu,$idnum);}
	if(mb_stristr('FP.RC',substr($docu,0,2))){get_atrz1($docu,$idnum);}

  if(mb_stristr('PF.OP.PC.FC',substr($docu,0,2)) and $cfg_empr=='dly1'){dly1_calc1($docu,$idnum);}
  if(mb_stristr('PF.OP.PC.FC',substr($docu,0,2)) and $cfg_empr=='ecgl'){ecgl_calc1($docu,$idnum);}
  if(mb_stristr('FC',substr($docu,0,2)) and $cfg_empr=='pcs1'){pcs1_calc1($docu,$idnum);}

  if(mb_stristr('caja.bcos',$tabla) and substr($docu,2,2)=="13"){gen_caba13($docu,$idnum);}

//   if(mb_stristr('inve',$tabla) and substr($docu,2,2)=="13"){gen_inve13($docu,$idnum);}
 
//   if($formato>=2 and $tabla!='cont'){$contab=gen_contab($docu,$idnum);}		
  if($formato==2 and $tabla!='cont'){$contab=gen_contab($docu,$idnum);}		
//   if(($formato==2 or $formato==3) and $tabla!='cont'){$contab=gen_contab($docu,$idnum);}		
  
	$sql_tra0='select * from '.$tabla.'1 where idnum1='.$idnum;
	$res_tra0=mysql_query($sql_tra0,$link_vcrx);	

  $claveacc=@mysql_result($res_tra0,0,'claveacc');
  $ambice=substr($claveacc,23,1);
  
	$ccc=0;
	$overpdf=0;	
	$docu_idnum=$docu.'_'.fillzero($idnum);	
	if($destino==''){$destino='screen';}	
	if($destino=='pdf'){$overpdf=1;}	
// 	if(mb_stristr($destino,'mail') or $destino=='pdf' or $destino=='M'){$destino='mail';}
	if(mb_stristr($destino,'mail') or $destino=='M'){$destino='mail';}

{
	$mdisplay=2;
	if(mb_stristr($destino,'mail')){$mdisplay=1; $destino='mail';}
	if(mb_stristr('pos.txt',$destino)){$mdisplay=1;}
	if($formato==2){$tabla='cont';}

	$sql_docu='select * from docu0 where docu_codigo like "'.$docu.'%"';
	$res_docu=mysql_query($sql_docu,$link_vcrx);

	$tabla=strtolower(mysql_result($res_docu,0,'docu_tabla'));	
	$ppsize=mysql_result($res_docu,0,'docu_ppsize');	
	$pporient=mysql_result($res_docu,0,'docu_pporient');	

	$width=mysql_result($res_docu,0,'docu_width');	
	$height=mysql_result($res_docu,0,'docu_height');	
	$orient=mysql_result($res_docu,0,'docu_orient');	

	$doble=mysql_result($res_docu,0,'docu_doble');	
	$copia=mysql_result($res_docu,0,'docu_copia');	

	$mindeta=@mysql_result($res_docu,0,'docu_mindeta');	
	$docupdf=@mysql_result($res_docu,0,'docu_pdf');	
	$margin_top=@mysql_result($res_docu,0,'docu_top');	
	$margin_left=@mysql_result($res_docu,0,'docu_left');
  
  if($ambice=='2'){$margin_top=0;}

	$doculogo=0;
	$firmas=0;
	$marcas=0;
	$notas=1;
	$guiaremi=0;
	if(mb_stristr('FC.OP.PC.PF.NC..GR..RP..PP..IE.IC..CH',substr($docu,0,2))){$doculogo=1;}
 	if(mb_stristr('FC.OP.PC.PF.NC..GR..RP..PP..IE.IC..CH..EB',substr($docu,0,2))){$firmas=1;}
 	if(mb_stristr('DD.RP.RC.',substr($docu,0,2))){$notas=0;}
	if(mb_stristr('GR',substr($docu,0,2))){$guiaremi=1;}
	if(mb_stristr('clie.vtas',$tabla)){$marcas=1;}
	if($destino=='mail'){$margin_top=0; $firmas=0;}
	if($margin_top>0){$doculogo=0;}
	
	if($ppsize==''){$ppsize='A4';}
	if($pporient==''){$pporient='V';}
	if($width==0){$width=210;}
	if($height==0){$height=297;}
	if($orient==''){$orient='V';}	
	if($copia==0){$copia=1;}	
  if($formato==1){$copia=1;}

  if(mb_stristr('pos.txt',$destino))
  {
    $mdisplay=1;
    $copia=1;
    $margin_top=0;
    $doculogo=0;
    $firmas=0;
  }

	if($user_codigo=='')
	{
		$ppsize='A4';
		$pporient='V';
		$width=210;
		$height=297;
		$orient='V';
		$copia=1;
	}	
	
	$xfontsize=12;
	$screensize=12;
	$printsize=12;
	if($width<=150)
	{
		$xfontsize=12;
		$screensize=12;
		$printsize=8;
	}
	if($width<=110)
	{
		$xfontsize=12;
		$screensize=12;
		$printsize=6;
	}

	// $width=70;
	$tirilla=0;	
	if($width<=90)
	{
		$tirilla=1;
		$xfontsize=12;
		$screensize=12;
		$printsize=6;
	}

	if($formato==2 and $tabla!='cont')
	{
			$sql_tra1='select * from cont1 where idfrom="'.$idnum.'" and mdfrom="'.$tabla.'"';
			$res_tra1=mysql_query($sql_tra1,$link_vcrx);
			$idnum=@mysql_result($res_tra1,0,'idnum1');
			$tabla='cont';
	}	
	
	
	if($formato>=2)
	{
		$xfontsize=12;
		$screensize=12;
		$printsize=12;
		$ppsize='A4';
		$pporient='V';
		$width=210;
		$height=297;
		$orient='V';
		$copia=1;
		$doculogo=0;
		$firmas=1;
		$marcas=0;
		$notas=0;
		$guiaremi=0;
		$xmdetalle='-';
		$margin_top=0;
	}
	
	{	
		$sql_emis='select * from empr0 left join enti00 on empr_ruc=enti_codigo limit 1';
		$res_emis=mysql_query($sql_emis,$link_vcrx);
    if(mysql_errno!=0)
    {
      $sql_emis='select * from empr0 left join enti0 on empr_ruc=enti_codigo limit 1';
      $res_emis=mysql_query($sql_emis,$link_vcrx);
    }

    {
	// 				$total_sql='select ';
					$total_sql ='max(detalle) as mdetalle, ';
					$total_sql.='sum(abs(tsubt)) as stsubt,';
					$total_sql.='sum(abs(cant)) as stcant,';
					if(mb_stristr('cont',$tabla))
					{
						$total_sql.='sum(tdebito) as stdebito,';
						$total_sql.='sum(tcredito) as stcredito,';
						$total_sql.='sum(diferencia) as sdiferencia,';
						$total_sql.='max(csub) as mcsub, ';
						$total_sql.='max(cair) as mcair, ';
						$total_sql.='max(item) as mitem, ';
					}
			
					if(mb_stristr('vtas.clie.carr.comp.prov',$tabla))
					{
            $total_sql.='sum(abs(tsubtiva0)) as stsubtiva0,';
            $total_sql.='sum(abs(tsubtiva)) as stsubtiva,';
            $total_sql.='sum(abs(tsubtice)) as stsubtice,';
            $total_sql.='sum(abs(tdcto)) as stdcto,';
            $total_sql.='sum(abs(tprop)) as stprop,';
            $total_sql.='sum(abs(tice)) as stice,';
            $total_sql.='sum(abs(tiva)) as stiva,';
            $total_sql.='sum(abs(tirbp)) as stirbp,';
            $total_sql.='sum(abs(tbien)) as stbien,';
//             $total_sql.='sum(abs(tserv)) as stserv,';

            $total_sql.='max(dcto) as pdcto,';
            $total_sql.='max(prop) as pprop,';
            $total_sql.='max(ice) as pice,';
            $total_sql.='max(iva) as piva,';
            $total_sql.='max(irbp) as pirbp,';
            
					}
			
					if(mb_stristr('comp.prov',$tabla))
					{
	// 				$total_sql.='sum(trrta) as strrta,';
	// 				$total_sql.='sum(triva) as striva,';
					$total_sql.='sum(rrta) as srrta,';
					$total_sql.='sum(riva) as sriva,';
					}

					if(mb_stristr('retc.retp',$tabla))
					{
            $total_sql.='sum(brta) as sbrta,';
            $total_sql.='max(prta) as sprta,';
            $total_sql.='sum(rrta) as srrta,';
            $total_sql.='sum(biva) as sbiva,';
            $total_sql.='max(piva) as spiva,';
            $total_sql.='sum(riva) as sriva,';
					}
			
					if(mb_stristr('vtas',$tabla) and mb_stristr('pcs1',$cfg_empr))
					{
            $total_sql.='sum(cntn) as scntn,';
            $total_sql.='max(cntn) as mcntn,';
					}
			
          if(mb_stristr('vtas.clie.prod',$tabla) and $cfg_empr=='ecgl')
          {
            $total_sql.='sum(case when item_descri like "VIDR%" then (lmns) else 0 end) as stlmn,';
            $total_sql.='sum(case when item_descri like "VIDR%" then (lmns*(mm_l*2+mm_a*2)/1000) else 0 end) as stmt1,';
            $total_sql.='sum(case when item_descri like "VIDR%" then (lmns*mm_l*mm_a/1000000) else 0 end) as stmt2,';
          }
      
					$total_sql.='sum(abs(total)) as stotal ';

					$dispcolu=1;
					if($mobile=='true'){$dispcolu=0;}
		}
		
		if(mb_stristr('retc.retp',$tabla))
		{
      if($tabla=='retc'){$sql_ret2 ='update '.$tabla.'2 set docum="FC10" where docum like "R%" and idnum2="'.$idnum.'"';}
      if($tabla=='retp'){$sql_ret2 ='update '.$tabla.'2 set docum="FP10" where docum like "R%" and idnum2="'.$idnum.'"';}
			$res_ret2=mysql_query($sql_ret2,$link_vcrx);
      
			$sql_tra1 ='select * from '.$tabla.'12 where status!="O" and status!="X" and cant>0 and ';
			$sql_tra1.='concat(numero,fecha,enti) in (select concat(numero,fecha,enti) as numero from '.$tabla.'1 where idnum1="'.$idnum.'" )';
			$sql_tra2=$sql_tra1;

			$sql_tra1=str_replace('*','*,'.$total_sql,$sql_tra1);
		}
		else
		{
			$sql_tra1='select * from '.$tabla.'12 where idnum1="'.$idnum.'"';
			$sql_tra2=$sql_tra1;

			$sql_tra1=str_replace('*','*,'.$total_sql,$sql_tra1);
		}

		if($cfg_empr=='ecgl' and mb_stristr('vtas.clie.prod',$tabla))
		{$sql_tra2.=' order by itnum,iddet ';}

		if(!mb_stristr($sql_tra2,'order by'))
    {$sql_tra2.='order by iddet ';}
		
		if(mb_stristr('cont',$tabla))
		{$sql_tra2=str_replace('order by','order by ctas,cant desc,',$sql_tra2);}
		
//     mysql_data_seek($res_tra1,0);    
    $res_tra1=mysql_query($sql_tra1,$link_vcrx);	
// 		$res_tra2=mysql_query($sql_tra2,$link_vcrx);
    
    $enti_codigo=mysql_result($res_tra1,0,'enti');
    $enti_descri=mysql_result($res_tra1,0,'enti_descri');
    $enti_razsoc=mysql_result($res_tra1,0,'enti_razsoc');
    $enti_nom1=mysql_result($res_tra1,0,'enti_nom1');
//     $enti_matriz=mysql_result($res_tra1,0,'enti_matriz');
    $enti_matriz=r_fiel('enti',$enti_codigo,'enti_matriz');
//     $enti_ciudad=r_fiel('enti',$enti_codigo,'enti_ciudad');
//     $enti_parroq= mysql_result($res_tra1,0,'enti_parroq');
    $enti_parroq= r_fiel('enti',$enti_codigo,'enti_parroq');

		if($enti_razsoc==''){reg_cedruc($enti_codigo);}
    
		if($enti_descri=='' or $enti_razsoc=='')
    {
      get_ruc1($enti_codigo);
  		$res_tra1=mysql_query($sql_tra1,$link_vcrx);	
      $enti_codigo=mysql_result($res_tra1,0,'enti');
      $enti_descri=mysql_result($res_tra1,0,'enti_descri');
      $enti_razsoc=mysql_result($res_tra1,0,'enti_razsoc');
      $enti_nom1=mysql_result($res_tra1,0,'enti_nom1');
    }
    
    if(substr($enti_codigo,2,1)<=6 and ($enti_nom1=='' or $enti_razsoc=='' or $enti_parroq==''))
    {
      get_ced1($enti_codigo);
      get_ced2($enti_codigo);
  		$res_tra1=mysql_query($sql_tra1,$link_vcrx);	
//       explain_sql($sql_tra1);
      $enti_codigo=mysql_result($res_tra1,0,'enti');
      $enti_descri=mysql_result($res_tra1,0,'enti_descri');
      $enti_razsoc=mysql_result($res_tra1,0,'enti_razsoc');
      $enti_nom1=mysql_result($res_tra1,0,'enti_nom1');
      $enti_parroq=@mysql_result($res_tra1,0,'enti_parroq');
      $enti_actividad=@r_fiel('enti',$enti_codigo,'enti_actividad');
    }
        if($enti_matriz==''){get_ruc2($enti_codigo);};
//         if($enti_matriz==''){get_ruc4($enti_codigo);};
//     if($enti_provincia==''){get_ruc4($enti_codigo);};
//     if($enti_parroq==''){get_ruc4($enti_codigo);};
//     if($enti_actividad==''){get_ruc4($enti_codigo);};

    $enti_orig=$enti_codigo;
    $sql_adqu='select * from enti00 where enti_codigo like "'.$enti_codigo.'%" order by enti_codigo desc';
		$res_adqu=mysql_query($sql_adqu,$link_vcrx);
//     explain_sql($sql_adqu);

    $xtoenti=@mysql_result($res_tra1,0,'toenti');
		$sql_toen=$sql_adqu;
		if($tabla=='comp')
		{$sql_toen='select * from enti00 where enti_codigo like "'.$xtoenti.'%" order by enti_codigo desc';}
		if($tabla=='retc')
		{$sql_toen='select * from enti00 where enti_codigo like "'.$xtoenti.'%" order by enti_codigo desc';}
		$res_toen=mysql_query($sql_toen,$link_vcrx);
//     echo '*/*/*'.$sql_toen;
		
		$xptonumero=mysql_result($res_tra1,0,'ptonumero');
		$xenti=mysql_result($res_tra1,0,'enti');
		
		$entipdf=0;
		$entipdf=@r_fiel('enti',$xenti,'pdf');

    $enticomi=0;
    if(mb_stristr('clie.vtas',$tabla))
    {$enticomi=@r_fiel('enti',$xenti,'comi');}
//     $enticomi=10;
		
		
		if(mb_stristr('clie',$tabla))
		{$xclaveacc=mysql_result($res_tra1,0,'claveacc');}
		
		if(mb_stristr('vtas.comp.retc.retp.guia',$tabla))
		{
			$xclaveacc=mysql_result($res_tra1,0,'claveacc');
			$xautornum=mysql_result($res_tra1,0,'autornum');
			$xautorfec=@mysql_result($res_tra1,0,'autorfec');
			$xatrz=mysql_result($res_tra1,0,'atrz');
			$xatrzvali=@mysql_result($res_tra1,0,'atrzvali');
		}
    
		$xstatus=mysql_result($res_tra1,0,'status');
		$xstfin=mysql_result($res_tra1,0,'stfin');
		$xambi=substr($xclaveacc,23,1);
		$docu_descri=mysql_result($res_tra1,0,'docu_descri');
		$tiporuc=mysql_result($res_tra1,0,'enti_tiporuc');
		if($tiporuc=='N'){$docupdf=0; $entipdf=0;}

		$tipo_descri='';
		if(substr($xclaveacc,8,2)=='01'){$tipo_descri='FACTURA';}
		if(substr($xclaveacc,8,2)=='04'){$tipo_descri='NOTA DE CREDITO';}
		if(substr($xclaveacc,8,2)=='06'){$tipo_descri='GUIA DE REMISION';}
		if(substr($xclaveacc,8,2)=='07'){$tipo_descri='RETENCION';}
// 		if($docu_descri=="" or $empr=="cfg_demo"){$docu_descri=$tipo_descri;}
// 		if($docu_descri=="" or $empr=="demo"){$docu_descri=$tipo_descri;}
		if($tipo_descri!=''){$docu_descri=$tipo_descri;}
		
		$xmdetalle=mysql_result($res_tra1,0,'mdetalle');
		$xmcsub=@mysql_result($res_tra1,0,'mcsub');
		$xmcair=@mysql_result($res_tra1,0,'mcair');
		$xmitem=@mysql_result($res_tra1,0,'mitem');
		$xmcntn=@mysql_result($res_tra1,0,'mcntn');

    //ecgl
    $xstlmn=@mysql_result($res_tra1,0,'stlmn');
    $xstmt1=@mysql_result($res_tra1,0,'stmt1');
		$xstmt2=@mysql_result($res_tra1,0,'stmt2');
	
    if($tirilla==1){$xmdetalle='';}



		$xtunid=0;
		$xipuni=1;
		$xideta=1;
		$xpdcto=0;
		$xpprop=0;
		$xpice=0;
		$xpiva=0;
		$xpirbp=0;
		$xtdcto=0;
		$xtprop=0;
		$xtsubtice=0;
		$xtice=0;
		$xtsubtiva0=0;
		$xtsubtiva=0;
		$xtiva=0;
		$xtirbp=0;

		
		$xtcant=mysql_result($res_tra1,0,'stcant');
		$xtsubt=mysql_result($res_tra1,0,'stsubt');
		
		if(mb_stristr('retc.retp', $tabla))
		{
		$xtrrta=mysql_result($res_tra1,0,'srrta');
		$xtriva=mysql_result($res_tra1,0,'sriva');
		}

		$xtotal=mysql_result($res_tra1,0,'stotal');
		$xconcepto=(mysql_result($res_tra1,0,'concepto'));

		if($guiaremi==1)
		{
			$motivo=@mysql_result($res_tra1,0,'motivo');
			$idfrom=mysql_result($res_tra1,0,'idfrom');
			$mdfrom=mysql_result($res_tra1,0,'mdfrom');
			
			$sql_orig='select * from '.$mdfrom.'11 where idnum1="'.$idfrom.'"';
			$res_orig=mysql_query($sql_orig,$link_vcrx);
			
			$docuorig=mysql_result($res_orig,0,'docu');
			$docuorigd=mysql_result($res_orig,0,'docu_descri');
			$numeroorig=mysql_result($res_orig,0,'ptonumero');
			$fechaorig=mysql_result($res_orig,0,'fechadmy');
			$autororig=mysql_result($res_orig,0,'claveacc');
			
			if(substr($docuorig,0,2)=='FC'){$motivo='VENTA';}
			if(substr($docuorig,0,4)=='EB10'){$motivo='VENTA';}
			if(substr($docuorig,0,4)=='EB13'){$motivo='TRANSFERENCIA';}
			
		}
			
		$xvndd='';
		$xfpag='';
		$xsuco='';

		if(mb_stristr('cont', $tabla))
		{
			$xtdebito=mysql_result($res_tra1,0,'stdebito');
			$xtcredito=mysql_result($res_tra1,0,'stcredito');
			$xdifer=mysql_result($res_tra1,0,'sdiferencia');
		}
		if(mb_stristr('vtas.clie.comp.prov.inve.prod', $tabla))
		{
			$xtunid=$xtcant;
			$xfpag=@mysql_result($res_tra1,0,'fpag');
			if(mb_stristr('vtas.clie.comp.prov', $tabla))
			{
				$xipuni=1;
				$xpdcto=mysql_result($res_tra1,0,'pdcto');
				$xpprop=mysql_result($res_tra1,0,'pprop');
				$xpice=mysql_result($res_tra1,0,'pice');
				$xpiva=mysql_result($res_tra1,0,'piva');
				$xpirbp=mysql_result($res_tra1,0,'pirbp');
				$xtdcto=mysql_result($res_tra1,0,'stdcto');
				$xtprop=mysql_result($res_tra1,0,'stprop');
				$xtsubtice=mysql_result($res_tra1,0,'stsubtice');
				$xtice=mysql_result($res_tra1,0,'stice');
				$xtsubtiva0=mysql_result($res_tra1,0,'stsubtiva0');
				$xtsubtiva=mysql_result($res_tra1,0,'stsubtiva');
				$xtiva=mysql_result($res_tra1,0,'stiva');
				$xtirbp=mysql_result($res_tra1,0,'stirbp');
			}
			if(mb_stristr('vtas.clie.carr', $tabla))
			{
				$xtbien=mysql_result($res_tra1,0,'stbien');
				$xtserv=@mysql_result($res_tra1,0,'stserv');
				$xtunid=$xtbien;
				$xvndd=mysql_result($res_tra1,0,'vndd');
				$xvndd=r_fiel('enti',mysql_result($res_tra1,0,'vndd'));
			}
			if(mb_stristr('comp.prov', $tabla))
			{
				$xsuco=mysql_result($res_tra1,0,'suco');
			}
		}

		if(mb_stristr('prod', $tabla) and $cfg_empr=='ecgl'){$xtunid=0;$xtotal=0;}
    
		$xiuser=mysql_result($res_tra1,0,'iuser');
		$xidate=mysql_result($res_tra1,0,'idate');
    if($xidate==''){$xidate=mysql_result($res_tra1,0,'fecha');}


		$lblruc1='EMISOR';
		$lblruc2='ADQUIRIENTE';

		if (mb_stristr('cont',$tabla))
		{$lblruc1='EMPRESA';}
		
		if (mb_stristr('comp.retc',$tabla))
		{
			$res_emis=mysql_query($sql_adqu,$link_vcrx);
			$res_adqu=mysql_query($sql_emis,$link_vcrx);
			if($cfg_empr =='demo')
			{$res_adqu=mysql_query($sql_toen,$link_vcrx);	}
		}

		if (mb_stristr('OP.PC.PF',substr($docu,0,2)))
		{$lblruc2='CLIENTE';}

		if (mb_stristr('IE.IC.IV.DC',substr($docu,0,2)))
		{$lblruc2='CLIENTE';}

		if (mb_stristr('EE.CH.EV.DP.RP',substr($docu,0,2)))
		{$lblruc2='PROVEEDOR';}

		if (mb_stristr('inve',$tabla))
		{$lblruc2='ENTIDAD';}

		if (mb_stristr('nomi.rolp',$tabla))
		{$lblruc2='EMPLEADO';}

		if (mb_stristr('FP11.IB10',substr($docu,0,4)))
		{
			$lblruc2='PROVEEDOR';
			$res_emis=mysql_query($sql_emis,$link_vcrx);
			$res_adqu=mysql_query($sql_adqu,$link_vcrx);
		}

				
	}	
}	
	
?>	


<?php //////////////////////////////////////////////////////////	?>
<?php
    $subdce=mk_subdce($claveacc);
  
?>

	<?php $xfontsize=$screensize; ?>
	<?php $filexml=$rutace.$xclaveacc.'.xml'; ?>
	<?php $filepdf=$rutace.$xclaveacc.'.pdf'; ?>
	<?php $filepdf2=$rutadoc.$docu_idnum.'.pdf'; ?>

	<?php $filexml=$rutace.$subdce.$xclaveacc.'.xml'; ?>
	<?php $filepdf=$rutace.$subdce.$xclaveacc.'.pdf'; ?>
	<?php $filepdf2=$rutadoc.$docu_idnum.'.pdf'; ?>


	<?php // if($destino=='mail'){ ?>
	<?php	//echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'; ?>
	<?php	//echo '<html xmlns="http://www.w3.org/1999/xhtml">'; ?>
	<?php // } ?>



<?php ob_start(); ?>
	<?php for($cdisplay=1;$cdisplay<=$mdisplay;$cdisplay++) { ?>

  <?php $xfontfamily='font-family:arial;';  ?>
  <?php
    if($cfg_empr=='ecgl' and mb_stristr('FC',substr($docu,0,2)))
    {$destino='mat';}
//     {$xfontsize+=2; $xfontfamily='font-family:Courier New; font-weight:bolder;';$doculogo=0;}
  ?>
  <?php
    if($cfg_empr=='dly1' and mb_stristr('FC.PC',substr($docu,0,2)) and $destino!='mail' and $cdisplay==2)
    {$destino='mat';}
//     {$xfontsize+=2; $xfontfamily='font-family:Courier New; font-weight:bolder;';$doculogo=0;}
  ?>
  <?php
    if(substr($destino,0,3)=='mat')
    {$xfontsize+=2; $xfontfamily='font-family:Courier New; font-weight:bolder;';$doculogo=0;}
  ?>

  <?php
    if(mb_stristr('pos.txt',$destino))
    {$xfontsize-=4; $xfontfamily='font-family:Courier New; font-weight:bolder;white-space:pre-wrap;';}
  ?>

	<?php if($cdisplay==2){?>
	<div id="border-top" style="width:10mm; height:<?php echo $margin_top;?>mm">
	</div>
	<?php } ?>
	<div id="cele<?php echo $cdisplay;?>" 
			 style="border:solid 0px; <?php echo $xfontfamily;?>; 
							<?php if($mdisplay>1){?>
							<?php if($cdisplay==1){{echo 'width:210mm;';}}else{echo 'width:'.$width.'mm;';}?>
							<?php } ?>
							font-size:<?php echo $xfontsize; ?>px;
							overflow:hidden;
							transform: scale(1);"
						 <?php  if($cdisplay==1){{echo 'class="noprint";';}}else{echo 'class="noscreen";';}?>>	
<?php //if($cdisplay==1){echo 'PANTALLA';}else{echo 'IMPRESORA';}?>	
		<?php //echo $width ; ?>
		<?php //echo $mdisplay.$destino;?>
<?php
//   $docu_pdf = new FPDF('P','mm','A4');
  $docu_pdf = new FPDF('P','mm', $ppsize);
  $docu_pdf->AddPage();
	$docu_pdf->SetTitle($docu_descri.' '.$xptonumero);
	$docu_pdf->SetAuthor('Vicente Ruiz Espinoza - 09 96030568');																									
  $docu_pdf->setFillColor(240,240,240);                                                      
  $pdf_ancho=$docu_pdf->GetPageWidth()-20;
  $pdf_centro=$docu_pdf->GetPageWidth()/2-10;
  $ffamilyPDF='Arial';  
  $fsizePDF=$xfontsize;                                              
  if(mb_stristr(strtolower($xfontfamily),'courier'))                                                        
  {
//     $ffamilyPDF='Courier';
//     $fsizePDF=$xfontsize-1;                                              
    $ffamilyPDF='Arial';  
    $fsizePDF=$xfontsize-2;                                              
  }
?>    
    
	<cabecera>
	<table border="0" width="100%" cellpadding="2" cellspacing="0" style="border-collapse:collapse;font-size:<?php echo $xfontsize; ?>px;">
			<tr style="font-weight:bolder; font-size:<?php echo $xfontsize; ?>px; 
								 border-top:solid 1px; border-bottom:solid 1px;">
				<td width="20%">
				</td>
				<td width="60%" align="center" style="letter-spacing:5pt;">
				<?php
					if($formato==2){$titulcompro= 'DIARIO - CONTABLE';}
					else
					{
            $titulcompro='COMPROBANTE';
            if($xclaveacc!="" and ($xambi!=1 or $cdisplay!=2)){$titulcompro.=' - ELECTRONICO';}
					}
          echo $titulcompro;
        ?>
				</td>
        
        <?php
          $docu_txt='';                                                        
          $docu_txt.=str_repeat('=',$coltxt).$eol;
          $docu_txt.=str_pad(''.$titulcompro.' ',$coltxt,$carbot,STR_PAD_BOTH).$eol;
          $docu_txt.=str_repeat('=',$coltxt).$eol;
				?>

        <?php 
          $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-2);
          $docu_pdf->SetFontSize($fsizePDF-2);
          $docu_pdf->Cell(0,5,$titulcompro,'TB',0,'C',false);
          $docu_pdf->ln();
          $posY1=$docu_pdf->getY()+1;                                                        
          $posY2=$docu_pdf->getY()+1;                                                        
        ?>
        
				<td width="20%" align="right" style="font-size:50%;">
					<?php if($xiuser!="" and $destino!='mail'){?>
					<?php echo 'REGISTRADO POR: ';?>
					<?php //echo r_fiel('enti',$xiuser,'nom1').' '.r_fiel('enti',$xiuser,'ape1');?>
					<?php echo r_fiel('user',$xiuser);?>
					<?php echo '<br>';?>
					<?php } ?>
					<?php echo date('d/M/y H:i:s',strtotime($xidate));?>
				</td>
			</tr>
		</table>		
	</cabecera>

		<?php $hlogo=20; if($cdisplay!=1){if($width<=150){$hlogo=15;}; if($width<=110){$hlogo=10;};} ?>
		<table border="0" width="100%" cellpadding="2" cellspacing="0" style="border-collapse:collapse;font-size:<?php echo $xfontsize; ?>px;">
			<tr>
				<?php //210*297 =62370 ?>
				<?php ///// COLUMNA IZQUIERDA ?>
				<td width="<?php if($width>=150 or 1==1){echo '60%';}else{echo '100%';}?>" <?php if($width>=150  or 1==1){}else{echo ' colspan="2"';}?> valign="top">

					<?php  ////  LOGO ?>
					<logo>
					<table border="1" width="100%" cellpadding="2" cellspacing="0" style="border-collapse:collapse;font-size:<?php echo $xfontsize; ?>px;">
						<tr>
							<?php //if (mb_stristr('FC.PF.GR.RP.IE',substr($docu,0,2)) and file_exists('../..'.$empr_logo2) and ($width<150 or 1==1)){ ?>
							<?php if ($doculogo==1 and file_exists($rutalogo.$logofile2) and ($width<150 or 1==1)){ ?>
							<td align="center" style="">
							<?php if($empr_website!=''){?>
							<a target="_blank"  href="http://<?php echo $empr_website; ?>">
							<?php }else{ ?>
								<?php if($xclaveacc!=''){?>
								<a href="<?php echo 'http://'.$cfg_empr.'.vcrxol.com/print1.php?clave='.$xclaveacc;?>">
								<?php }else{ ?>
								<a href="<?php echo 'http://'.$cfg_empr.'.vcrxol.com/print1.php?prnt1=1&docu='.$docu.'&idnum='.$idnum;?>">
								<?php } ?>
							<?php } ?>
							<img src="<?php echo 'http://vcrxol.com/_logo/'.$logofile2;?>" alt=""
									 title="<?php echo $empr_website; ?>" style="max-width:100%; max-height:<?php echo $hlogo;?>mm;">		
							</a>
							</td>
        <?php 
//           $docu_pdf->ln(5+2);
					$xsrc='http://vcrxol.com/_logo/'.$logofile2;
          $xsrc_fgc=file_get_contents($xsrc);                                                                                        
          $img_xy=getimagesizefromstring($xsrc_fgc);
          $img_w=$img_xy[0];
          $img_h=$img_xy[1];
          $img_rel=$img_w/$img_h;
          $cel_w=$pdf_ancho*.6;                                                                                        
          $cel_h=25;
          if($img_w<$cel_w){$img_w=$cel_w;}
          if($img_h<$cel_h){$img_h=$cel_h;}
          if($img_h>=$cel_h){$img_h=$cel_h; $img_w=$img_rel*$img_h;}
          if($img_w>=$cel_w){$img_w=$cel_w; $img_h=$img_rel/$img_w;}
                                                                                                  
          if(mb_stristr($img_xy['mime'],'jpeg'))                                                                                                  
          {$docu_pdf->Image($xsrc,(($cel_w-$img_w)/2)+10,$docu_pdf->getY()+(($cel_h-$img_h)/2)+3,$img_w,$img_h,'JPG');}
          if(mb_stristr($img_xy['mime'],'png'))                                                                                                  
          {$docu_pdf->Image($xsrc,(($cel_w-$img_w)/2)+10,$docu_pdf->getY()+(($cel_h-$img_h)/2)+3,$img_w,$img_h,'PNG');}
//           {$docu_pdf->Image($xsrc,(($cel_w-$img_w)/2)+10,$docu_pdf->getY()+4,$img_w,$img_h,'JPG');}
//           if(mb_stristr($img_xy['mime'],'png'))                                                                                                  
//           {$docu_pdf->Image($xsrc,(($cel_w-$img_w)/2)+10,20,$img_w,$img_h,'PNG');}
                                                                                                  
          $docu_pdf->setY($posY1);                                                                                                  
          $docu_pdf->Cell($pdf_ancho*.6,30,'','LRTB',0,'C',false);
//           $docu_pdf->Cell($pdf_ancho*.6,5,'','',0,'C',false);
          $docu_pdf->ln();                                                                                                  
          $posY1=$docu_pdf->getY()+1;
        ?>
							<?php } ?>

                
						</tr>
					</table>
					</logo>
					<div style="font-size:25%;"><br></div>

					<?php ///// BLOQUE 1 ?>
					<?php if($margin_top==0){ ?>
					<?php //{ ?>
          <emite>
					<?php $enti_codigo=@mysql_result($res_emis,0,'enti_codigo'); ?>
					<?php $enti_razsoc=@mysql_result($res_emis,0,'enti_razsoc'); ?>
					<?php $enti_nomcom=@mysql_result($res_emis,0,'enti_nomcom'); ?>
					<table border="1" width="100%" cellpadding="2" cellspacing="5"
                 style="border-collapse:collapse; border-radius:10px;font-size:<?php echo $xfontsize; ?>px;<?php echo $xfontfamily;?>">
						<tr style="border:solid 1px; font-weight:bolder; background:#F7F7F7;">
							<td align="center" colspan=3 style="letter-spacing:10px" ><?php echo $lblruc1; ?></td>
						</tr>
						<tr valign="top">
							<td width="25%">RUC/C.I.</td>
							<td width="75%"><?php echo $enti_codigo; if($enti_codigo==''){echo '*** '.$enti_orig.' ***';} ?></td>
						</tr>
						<tr valign="top">
							<td>RAZ.SOCIAL</td>
							<td><?php echo @mysql_result($res_emis,0,'enti_razsoc');?></td>
						</tr>
						<?php if(trim(@mysql_result($res_emis,0,'enti_razsoc'))!=trim(@mysql_result($res_emis,0,'enti_nomcom')) and mysql_result($res_emis,0,'enti_nomcom')!=""){?>
						<tr valign="top">
							<td>NOM.COMERCIAL</td>
							<td><?php echo mysql_result($res_emis,0,'enti_nomcom');?></td>
						</tr>
						<?php } ?>
						
						<?php if(!mb_stristr('caja.bcos.inve.prod.nomi.cont',$tabla)){?>
						<tr valign="top">
							<td>MATRIZ</td>
							<td><?php echo @mysql_result($res_emis,0,'enti_matriz');?></td>
						</tr>
						<tr valign="top">
							<td>TELEFONO</td>
							<td><?php echo @mysql_result($res_emis,0,'enti_telefono');?></td>
						</tr>
						<tr valign="top">
							<td>E-MAIL</td>
							<td><?php echo strtolower(@mysql_result($res_emis,0,'enti_email'));?></td>
						</tr>
						<?php } ?>
						
					</table>
					<div style="font-size:25%;"><br></div>
          </emite>
          <?php
                                
             $docu_txt.=str_pad($lblruc1.' ',$coltxt,$carbot,STR_PAD_BOTH).$eol;
             $docu_txt.='RUC     : '.$enti_codigo.$eol;
             $docu_txt.='RAZ.SOC.: '.@mysql_result($res_emis,0,'enti_razsoc').$eol;
             if($enti_razsoc!=$enti_nomcom and $enti_nomcom!='')
             {$docu_txt.='NOM.COM.: '.@mysql_result($res_emis,0,'enti_nomcom').$eol;}
             $docu_txt.='MATRIZ  : '.trim(@mysql_result($res_emis,0,'enti_matriz')).$eol;
             $docu_txt.='TELEF.  : '.@mysql_result($res_emis,0,'enti_telefono').$eol;
             $docu_txt.='E-MAIL  : '.trim(@mysql_result($res_emis,0,'enti_email')).$eol;
             $docu_txt.=$eol;
          ?>
            
        <?php 
//           $posY1=48;
          $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-2);
          $docu_pdf->SetY($posY1);
          $docu_pdf->Cell($pdf_ancho*.6,5,$lblruc1,'LRTB',0,'C',true);
          $docu_pdf->ln();
          $docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-3);
          $docu_pdf->Cell($pdf_ancho*.2,5,'RUC :','LRT',0,'L',false);
          $docu_pdf->MultiCell($pdf_ancho*.4,5,$enti_codigo,'LRT','L',false);

//           $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-3);
          $docu_pdf->Cell($pdf_ancho*.2,5,'RAZ. SOCIAL :','LRT',0,'L',false);
          $docu_pdf->MultiCell($pdf_ancho*.4,5,@mysql_result($res_emis,0,'enti_razsoc'),'LRT','L',false);
//           $docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-3);

          if(trim(mysql_result($res_emis,0,'enti_razsoc'))!=trim(mysql_result($res_emis,0,'enti_nomcom')) and mysql_result($res_emis,0,'enti_nomcom')!="")
          {
          $docu_pdf->Cell($pdf_ancho*.2,5,'NOM. COMERCIAL :','LRT',0,'L',false);
          $docu_pdf->MultiCell($pdf_ancho*.4,5,@mysql_result($res_emis,0,'enti_nomcom'),'LRT','L',false);
          }  
          $docu_pdf->Cell($pdf_ancho*.2,5,'MATRIZ :','LRT',0,'L',false);
          $docu_pdf->MultiCell($pdf_ancho*.4,5,utf8_decode(@mysql_result($res_emis,0,'enti_matriz')),'LRT','L',false);
          $docu_pdf->Cell($pdf_ancho*.2,5,'TELEFONO :','LRT',0,'L',false);
          $docu_pdf->MultiCell($pdf_ancho*.4,5,@mysql_result($res_emis,0,'enti_telefono'),'LRT','L',false);
          $docu_pdf->Cell($pdf_ancho*.2,5,'E-MAIL :','LRT',0,'L',false);
          $docu_pdf->SetFontSize($fsizePDF-3);
          $docu_pdf->MultiCell($pdf_ancho*.4,5,strtolower(@mysql_result($res_emis,0,'enti_email')),'LRT','L',false);
          $docu_pdf->Cell($pdf_ancho*.2,1,'','T',0,'',false);
          $docu_pdf->MultiCell($pdf_ancho*.4,1,'','T','',false);
                                
          $posY1=$docu_pdf->getY();
                                
        ?>
						
					<?php}?>

					<?php ///// BLOQUE 2 ?>
					<?php
// 					if($guiaremi==0 and $formato!=2)
					if(!mb_stristr('guia.cont',$tabla))
					{
					?>
					<recibe>
					<table border="1" width="100%" cellpadding="2" cellspacing="0" 
								 style="border-collapse:collapse;font-size:<?php echo $xfontsize; ?>px;<?php echo $xfontfamily;?>"
								 >
						<tr style="border:solid 1px; font-weight:bolder; background: #F7F7F7;">
							<td align="center" colspan=2 style="letter-spacing:10px" ><?php echo $lblruc2; ?></td>
						</tr>
						<?php $enti_codigo=mysql_result($res_adqu,0,'enti_codigo'); ?>
						<?php $enti_razsoc=mysql_result($res_adqu,0,'enti_razsoc'); ?>
						<?php $enti_nomcom=mysql_result($res_adqu,0,'enti_nomcom'); ?>
        		<?php if($enti_razsoc==''){reg_cedruc($enti_codigo);}?>
						<?php if(mysql_result($res_adqu,0,'enti_tipoid')=='P'){$enti_codigo=mysql_result($res_adqu,0,'enti_pasaporte');}; ?>
						<tr valign="top">
							<td width="25%">RUC/C.I.</td>
							<td width="75%"><?php echo $enti_codigo;?></td>
						</tr>
						<tr valign="top">
							<td>RAZ. SOCIAL</td>
							<td><?php echo mysql_result($res_adqu,0,'enti_razsoc');?></td>
						</tr>
						<?php if(trim(mysql_result($res_adqu,0,'enti_razsoc'))!=trim(mysql_result($res_adqu,0,'enti_nomcom')) and mysql_result($res_adqu,0,'enti_nomcom')!=""){?>
						<tr valign="top">
							<td>NOM. COMERCIAL</td>
							<td><?php echo mysql_result($res_adqu,0,'enti_nomcom');?></td>
						</tr>
						<?php } ?>
						<?php $matriz=mysql_result($res_adqu,0,'enti_matriz');	?>
						<?php $direccion=mysql_result($res_adqu,0,'enti_direccion');	?>
						<?php $ciudad=mysql_result($res_adqu,0,'enti_ciudad');	?>
						<?php $calle1=mysql_result($res_adqu,0,'enti_calle1');	?>
						<?php $calle2=mysql_result($res_adqu,0,'enti_calle2');	?>
						<?php $calle3=mysql_result($res_adqu,0,'enti_calle3');	?>
						<?php $callen=mysql_result($res_adqu,0,'enti_callen');	?>
						<?php $parroq=@mysql_result($res_adqu,0,'enti_parroq');	?>
            <?php $parroq=r_fiel('enti',$enti_codigo,'enti_parroq'); ?>
						<?php $adqu_email1=mysql_result($res_adqu,0,'enti_email');	?>
						<?php $adqu_email2=mysql_result($res_adqu,0,'enti_emailce');	?>

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

						<?php if ($matriz!='' or 1==1){?>
						<tr valign="top">
							<td>MATRIZ</td>
							<td><?php echo $matriz.'<br>'.$parroq;?></td>
						</tr>
						<?php } ?>
						
						<?php if ($matriz=='' and strlen(trim($direccion))>5){?>
						<tr valign="top">
							<td>DIRECCION</td>
							<td><?php echo $direccion;?></td>
						</tr>
						<?php } ?>
						
						<?php if ($calle1!=''){?>
						<tr valign="top">
							<td>DIRECCION</td>
							<td>
              <?php echo $calle1.'('.$callen.') /'.$calle2;?>
							<?php if($calle3!=''){echo '<br>Ref: '.$calle3;}?>
              </td>
						</tr>
						<?php } ?>
						
						<tr valign="top">
							<td>TELEFONO</td>
							<td><?php echo mysql_result($res_adqu,0,'enti_telefono');?></td>
						</tr>
						<tr valign="top">
							<?php
								  $adqu_email2=str_replace($adqu_email1,'',$adqu_email2);

									$adqu_email=trim($adqu_email1).';'.trim($adqu_email2);
							    $adqu_email=str_replace(';','; ',$adqu_email); 
							    $adqu_email=str_replace(',','; ',$adqu_email); 
              ?>
							<td>E-MAIL</td>
							<td><?php echo strtolower($adqu_email);?></td>
						</tr>
						<?php } ?>
						
					</table>			
          <?php
             $docu_txt.=str_pad($lblruc2.' ',$coltxt,$carbot,STR_PAD_BOTH).$eol;
             $docu_txt.='RUC     : '.$enti_codigo.$eol;
             $docu_txt.='RAZ.SOC.: '.@mysql_result($res_adqu,0,'enti_razsoc').$eol;
             if($enti_razsoc!=$enti_nomcom and $enti_nomcom!='')
             {$docu_txt.='NOM.COM.: '.@mysql_result($res_adqu,0,'enti_nomcom').$eol;}
             $docu_txt.='MATRIZ  : '.trim(@mysql_result($res_adqu,0,'enti_matriz')).$eol;
             $docu_txt.='TELEF.  : '.@mysql_result($res_adqu,0,'enti_telefono').$eol;
             $docu_txt.='E-MAIL  : '.$adqu_email.$eol;
             $docu_txt.=$eol;
          ?>
        <?php 
//           $posY=84;
					$adqu_email=str_replace('; ',';',$adqu_email);
          $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-2);
          $docu_pdf->SetY($posY1);
          $docu_pdf->Cell($pdf_ancho*.6,5,$lblruc2,'LRTB',0,'C',true);
          $docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-3);
          $docu_pdf->ln();

          $docu_pdf->Cell($pdf_ancho*.2,5,'RUC :','LRT',0,'L',false);
          $docu_pdf->MultiCell($pdf_ancho*.4,5,$enti_codigo,'LRT','L',false);
          $docu_pdf->Cell($pdf_ancho*.2,5,'RAZ. SOCIAL :','LRT',0,'L',false);
          $docu_pdf->MultiCell($pdf_ancho*.4,5,@mysql_result($res_adqu,0,'enti_razsoc'),'LRT','L',false);
          if(trim(mysql_result($res_adqu,0,'enti_razsoc'))!=trim(mysql_result($res_adqu,0,'enti_nomcom')) and mysql_result($res_adqu,0,'enti_nomcom')!="")
          {
          $docu_pdf->Cell($pdf_ancho*.2,5,'NOM. COMERCIAL :','LRT',0,'L',false);
          $docu_pdf->MultiCell($pdf_ancho*.4,5,@mysql_result($res_adqu,0,'enti_nomcom'),'LRT','L',false);
          }
          $docu_pdf->Cell($pdf_ancho*.2,5,'MATRIZ :','LRT',0,'L',false);
          $docu_pdf->MultiCell($pdf_ancho*.4,5,utf8_decode(@mysql_result($res_adqu,0,'enti_matriz')),'LRT','L',false);
          $docu_pdf->Cell($pdf_ancho*.2,5,'TELEFONO :','LRT',0,'L',false);
          $docu_pdf->MultiCell($pdf_ancho*.4,5,@mysql_result($res_adqu,0,'enti_telefono'),'LRT','L',false);
          $docu_pdf->Cell($pdf_ancho*.2,5,'E-MAIL :','LRT',0,'L',false);
          $docu_pdf->SetFontSize($fsizePDF-3);
          $docu_pdf->MultiCell($pdf_ancho*.4,5,strtolower($adqu_email),'LRT','L',false);
          $docu_pdf->Cell($pdf_ancho*.2,1,'','T',0,'',false);
          $docu_pdf->MultiCell($pdf_ancho*.4,1,'','T','',false);
          $posY1=$docu_pdf->getY();
                                
        ?>
            
					</recibe>	
						
					<?php}?>

					<?php ///// BLOQUE 3 ?>
					<?php{?>
					<div style="font-size:25%;"><br></div>
					<table border="1" width="100%" cellpadding="2" cellspacing="0" 
                 style="border-collapse:collapse;font-size:<?php echo $xfontsize; ?>px;<?php echo $xfontfamily;?>">
						<tr style="border:solid 1px; font-weight:bolder; background: #F7F7F7;">
							<td align="center" colspan=2 ><?php echo 'INFORMACION ADICIONAL'; ?></td>
						</tr>
						<tr style="display:none;">
							<td width="30%"></td>
							<td></td>
						</tr>

						<?php if(mb_stristr('cont', $tabla)){?>
							<tr>
								<td>ENTIDAD</td>
								<td><?php echo @mysql_result($res_tra1,0,'enti_descri');?></td>
							</tr>
						<?php } ?>

						<tr style=<?php if($xconcepto==""){echo 'display:none;';}?>>
							<td>CONCEPTO</td>
							<td><?php echo $xconcepto;?></td>
						</tr>

            
          <?php
             $docu_txt.=str_pad('INFO ADICIONAL ',$coltxt,$carbot,STR_PAD_BOTH).$eol;
             if($xconcepto!='')
             {$docu_txt.='CONCEPTO : '.$xconcepto.$eol;}
             $docu_txt.=$eol;
          ?>
            
        <?php 
          $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-2);
          $docu_pdf->SetY($posY1);
          $docu_pdf->Cell($pdf_ancho*.6,5,'INFORMACION ADICIONAL','LRTB',0,'C',true);
          $docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-3);
          $docu_pdf->ln();
             
         ?>
            <?php if($xconcepto!=''){ ?>
            <?php
            $docu_pdf->Cell($pdf_ancho*.2,5,'CONCEPTO :','LRT',0,'L',false);
            $docu_pdf->MultiCell($pdf_ancho*.4,5,utf8_decode($xconcepto),'LRT','L',false);
            $posY1=$docu_pdf->getY();
            ?>
            <?php}?>
            
            <?php $drtr=@mysql_result($res_tra1,0,'drtr'); ?>
            <?php $drtr_descri=r_fiel('enti',$drtr); ?>
            <?php if($drtr!=''){ ?>
            <?php
              $docu_pdf->Cell($pdf_ancho*.2,5,'DIRECTOR :','LRT',0,'L',false);
              $docu_pdf->MultiCell($pdf_ancho*.4,5,utf8_decode($drtr_descri),'LRT','L',false);
              $posY1=$docu_pdf->getY();
            ?>
            <?php}?>
            
            <?php
              $docu_pdf->Cell($pdf_ancho*.2,1,'','T',0,'',false);
              $docu_pdf->MultiCell($pdf_ancho*.4,1,'','T','',false);
              $posY1=$docu_pdf->getY();
            ?>
            
            
						<?php if(mb_stristr('comp', $tabla)){?>
						<?php $adicionales=@mysql_result($res_tra1,0,'infoadic'); ?>
						<?php //$adicionales='<tr>'.$adicionales.'</tr>' ?>
						<?php $adicionales=str_replace('[[','',$adicionales); ?>
						<?php $adicionales=str_replace(']]',' : ',$adicionales); ?>
						<?php $adicionales=str_replace('||','<br>',$adicionales); ?>
						<?php //$adicionales=str_replace('|','|. ',$adicionales); ?>
						<?php //echo $adicionales;?>
						
						<tr style="display:none;">
							<td>ADICIONAL</td>
							<td><?php echo $adicionales;?></td>
						</tr>
						<?php } ?>

            
						<?php 
						 if(mb_stristr('vtas.clie.comp', $tabla))
						 {
							 $adicionales=@mysql_result($res_tra1,0,'infoadic'); 
							 $adicionales='<tr>'.$adicionales.'</tr>';
							 $adicionales=str_replace(',',', ',$adicionales); 
							 $adicionales=str_replace('  ',' ',$adicionales); 
							 $adicionales=str_replace('[[','<td>',$adicionales); 
							 $adicionales=str_replace(']]','</td><td>',$adicionales); 
							 $adicionales=str_replace('||','</td></tr><tr>',$adicionales); 
							 $adicionales=str_replace('|','| ',$adicionales); 
							 if(mb_stristr($adicionales,'<td>')) 
							 {echo $adicionales;}
						 } 
						?>

						<?php if(mb_stristr('comp.prov', $tabla)){?>
						<tr style="font-size:75%;<?php if($xsuco==0){echo 'display:none;';}?>" >
							<td>SUSTENT.COMP.</td>
							<td><?php echo mysql_result($res_tra1,0,'suco_descri');?></td>
						</tr>
						<?php}?>

            <?php if(mb_stristr('clie.vtas', $tabla) and $cfg_empr=='dly1'){?>
            <?php $drtr=mysql_result($res_tra1,0,'drtr'); ?>
            <?php $drtr_descri=r_fiel('enti',$drtr); ?>
						<tr style="font-size:100%;<?php if($drtr==''){echo 'display:none;';}?>" >
							<td>DIRECTOR</td>
							<td><?php echo $drtr.' /'.$drtr_descri; ?></td>
						</tr>
						<?php}?>

         </table>					
					<?php}?>

				<?php if($width>=150 or 1==1){?>					
				</td>
					
				<?php if($tirilla==1){ ?>
				</tr><tr>	
				<?php } ?>	

      
      
      
      
				<?php ///// COLUMNA DERECHA ?>
				<td width=40% valign="top">
				<?php }else{ ?>
				</tr>	
				<tr valign="top">
					<td width=50% valign="top">
				<?php } ?>
					
					<?php  //// CODEBAR ?>
					<table border="1" width="100%" cellpadding="2" cellspacing="0" 
                 style="border-collapse:collapse;font-size:<?php echo $xfontsize; ?>px;<?php echo $xfontfamily;?>">
						<tr>
							<?php if ($doculogo==1 and file_exists($rutalogo.$logofile2) and ($width<150 or 1==1)){ ?>
							<td align="center" style="" height="<?php echo $hlogo*3;?>mm"</td>
							<?php if($destino=='mail' or 1==1){ ?>
								<?php if ($xclaveacc!=""){?>
                  <?php //$subdce=mk_subdce($claveacc);?>
									<?php gen_bcod($xclaveacc);?>
<!-- 									<a href="<?php //echo 'http://'.$cfg_empr.'.vcrxol.com/print1.php?clave='.$xclaveacc;?>"> -->
									<a href="<?php echo 'http://vcrxol.com/_cel/'.$subdce.$claveacc.'.pdf'; ?>">
                  <?php $xsrc='http://vcrxol.com/_bcod/'.$xclaveacc.'.jpg'; ?>
									<img src="<?php echo $xsrc;?>" alt=""
											 title="PDF" style="max-width:100%; max-height:<?php echo $hlogo;?>mm;">		
									</a>
									<?php }else{?>
									<?php gen_bcod($cfg_ruc.'_'.$xptonumero);?>
                  <?php $xsrc='http://vcrxol.com/_bcod/'.$cfg_ruc.'_'.$xptonumero.'.jpg'; ?> 
									<img src="<?php echo $xsrc;?>" alt=""
											 title="<?php echo $xptonumero;?>" style="max-width:100%; max-height:<?php echo $hlogo;?>mm;">		
									<?php }?>
							<?php }else{ ?>
								<barcode style="font-size:28px; padding:0px; margin:1px; letter-spacing:1pt; font-weight:normal;">
								<?php if($xclaveacc!=""){echo $xclaveacc;}else{echo $cfg_ruc.' '.$xptonumero;}	?>
								</barcode>	
							<?php } ?>
							</td>
        <?php 
//           $docu_pdf->Image($xsrc,$pdf_ancho*.605+15,20,$pdf_ancho*.35,10,'JPG');
          $docu_pdf->Image($xsrc,$pdf_ancho*.605+15,16,$pdf_ancho*.35,18,'JPG');
          $docu_pdf->Link($pdf_ancho*.605+15,20,$pdf_ancho*.35,10,'http://'.$cfg_empr.'.vcrxol.com/print1.php?clave='.$xclaveacc);
          $docu_pdf->setY($posY2);
          $docu_pdf->setX($pdf_ancho*.605+10);
          $docu_pdf->Cell($pdf_ancho*.4,20,'.','LRTB',0,'R',false);
          $docu_pdf->ln();
          $posY2=$docu_pdf->getY()+1;                                                                                                  
        ?>
							<?php } ?>
            
						</tr>
					</table>
					<div style="font-size:25%;"><br></div>
						
						
						
					<?php ///// BLOQUE 1 ?>
					<datos>
					<?php { ?>
					<table border="1" width="100%" cellpadding="2" cellspacing="0" 
                 style="border-collapse:collapse;font-size:<?php echo $xfontsize; ?>px;<?php echo $xfontfamily;?>">
						<tr style="border:solid 1px; font-weight:bolder; background: #F7F7F7;">
							<td align="center" colspan=2 ><?php echo 'DATOS DEL COMPROBANTE'; ?></td>
						</tr>
						<tr style="display:none;">
							<td width="30%"></td>
							<td></td>
						</tr>
						<tr>
							<?php if(mb_stristr('retc.retp',$tabla)){$docu_descri='RETENCION';}?>
							<td align="right">TIPO:</td>
							<td><?php echo $docu_descri;?></td>
						</tr>
						<tr style="font-weight:bolder;">
							<td align="right">NUMERO:</td>
							<td><?php echo mysql_result($res_tra1,0,'ptonumero');?></td>
						</tr>
						<tr style="text-transform:uppercase">
							<td align="right">FECHA:</td>
							<td><?php echo mysql_result($res_tra1,0,'fdian').' - '.mysql_result($res_tra1,0,'fechadmy');?></td>
						</tr>
						<?php if(mb_stristr('vtas.comp.clie.prov',$tabla)){?>
							<?php if(mysql_result($res_tra1,0,'plazo')>1){?>
							<tr style="text-transform:uppercase">
								<td align="right">VENCE:</td>
								<td><?php echo mysql_result($res_tra1,0,'vencedmy');?></td>
							</tr>
							<?php}?>
							<?php if($vndd!=""){?>
							<tr style="">
								<td align="right">VENDEDOR:</td>
								<td><?php echo $xvndd;?></td>
							</tr>
							<?php}?>
						<?php }?>

						<?php if(mb_stristr('caja.bcos',$tabla)){?>
							<?php $caba=mysql_result($res_tra1,0,'caba') ;?>
							<?php $caba2=mysql_result($res_tra1,0,'caba2') ;?>
							<tr style="text-transform:uppercase">
								<td align="right">CAJA/CTAB:</td>
								<td><?php echo $caba.' - '.r_fiel('caba',$caba); ?></td>
							</tr>
							<?php if(substr($docu,2,2)=="13"){?>
							<tr style="text-transform:uppercase">
								<?php if(mb_stristr('IE.DB',substr($docu,0,2))){?>
								<td align="right">ORIGEN:</td>
								<?php}else{?>
								<td align="right">DESTINO:</td>
								<?php}?>
								<td><?php echo $caba2.' - '.r_fiel('caba',$caba2); ?></td>
							</tr>
							<?php}?>
						<?php }?>
						
						<?php if(mb_stristr('inve.prod',$tabla)){?>
							<?php $bode=mysql_result($res_tra1,0,'bode') ;?>
							<?php $bode2=mysql_result($res_tra1,0,'bode2') ;?>
							<tr style="text-transform:uppercase">
								<td align="right">BODEGA:</td>
								<td><?php echo $bode.' - '.r_fiel('bode',$bode); ?></td>
							</tr>
							<?php if(substr($docu,2,2)=="13"){?>
							<tr style="text-transform:uppercase">
								<td align="right">BODEGA 2:</td>
								<td><?php echo $bode2.' - '.r_fiel('bode',$bode2) ;?></td>
							</tr>
							<?php}?>
						<?php }?>
						
						<?php if (mb_stristr('vtas.comp.retp.retc.guia',$tabla)){?>
						<?php if($xclaveacc!=""){ ?>
            <?php if($xambi==2){$xambides='PRODUCCION';}else{$xambides='PRUEBAS';} ?>
						<tr style="font-size:80%; <?php if($xambi==1 and $cdisplay==2){ echo 'display:none;';}?>">
							<td align="right">AMBIENTE:</td>
							<td><?php echo $xambides;?></td>
						</tr>
						<?php } ?>
						<?php 

              $subdce=mk_subdce($claveacc);
                                                                  
							$filexml = $xclaveacc.'.xml';
							$filexmlb = $xclaveacc.'.xml';
// 							if(file_exists ('../../_cel/'.$xclaveacc.'b.xml')){$filexmlb = $xclaveacc.'b.xml';}
							if(file_exists ('../../_cel/'.$subdce.$xclaveacc.'b.xml')){$filexmlb = $xclaveacc.'b.xml';}
						?>
						<?php if($xclaveacc!=""){ ?>
						<tr style="font-size:70%; <?php if(($xambi==1 and $cdisplay==2)or($cdisplay==2 and $xautornum!="")){ echo 'display:none;';}?>">
							<td align="right">CLAVE ACCESO:</td>
							<td>
								<a href="<?php if($cdisplay==1){echo 'http://vcrxol.com/_cel/'.$subdce.$filexmlb;}?>" 
									 title="Descargar XML" target="_blank"
										<?php if($xautornum=="" or $destino=='mail'){ ?>
 									 download="<?php echo substr($docu,0,1).'_'.substr($xclaveacc,10,13).'_'.substr($xclaveacc,24,6).'_'.substr($xclaveacc,30,9).''; ?>" 
									 <?php } ?>
									 >
								<?php
						 			if($cdisplay==1){echo $xclaveacc;}
						 			else{echo substr($xclaveacc,0,8).'.'.substr($xclaveacc,8,2).'.'.substr($xclaveacc,10,13).'.'.substr($xclaveacc,23,1)
										.'<br>'.substr($xclaveacc,24,6).'.'.substr($xclaveacc,30,9).'.'.substr($xclaveacc,39,8).'.'.substr($xclaveacc,47,2);}
								?>
								</a>
							</td>
						</tr>
						<?php } ?>
						<?php if($xautornum!=""){ ?>
						<tr style="font-size:70%; <?php if($xambi==1 and $cdisplay==2){ echo 'display:none;';}?>">
							<td align="right">AUTORIZACION:</td>
							<td>
								<a href="<?php if($cdisplay==1){echo 'http://vcrxol.com/_cel/'.$subdce.$filexml;}?>" 
									 title="Descargar XML AUTORIZADO"
									 download="<?php echo substr($docu,0,1).'_'.substr($xclaveacc,10,13).'_'.substr($xclaveacc,24,6).'_'.substr($xclaveacc,30,9).''; ?>">
								<?php
						 			if($cdisplay==1){echo $xautornum;}
						 			else
										{
											if($xautornum==$xclaveacc)
											{
												echo substr($xautornum,0,8).'.'.substr($xautornum,8,2).'.'.substr($xautornum,10,13).'.'.substr($xautornum,23,1)
												.'<br>'.substr($xautornum,24,6).'.'.substr($xautornum,30,9).'.'.substr($xautornum,39,8).'.'.substr($xautornum,47,2);
											}
											else
											{
												echo substr($xautornum,0,8).'.'.substr($xautornum,8,3).'.'.substr($xautornum,11,6)
												.'<br>'.substr($xautornum,17,9).'.'.substr($xautornum,26,10).'.'.substr($xautornum,36,1);
											}
										}
								?>
								</a>
							</td>
						</tr>
						<?php } ?>

						<?php if($xautorfec!="" and mb_stristr('FP.RC',substr($docu,0,2))){ ?>
						<tr style="font-size:70%; <?php if($xambi==1 and $cdisplay==2){ echo 'display:none;';}?>">
							<td align="right">FECHA AUT.:</td>
							<td>
								<a href="<?php if($cdisplay==1){echo 'http://vcrxol.com/_cel/'.$subdce.$filexml;}?>" 
									 title="Descargar XML AUTORIZADO"
									 download="<?php echo substr($docu,0,1).'_'.substr($xclaveacc,10,13).'_'.substr($xclaveacc,24,6).'_'.substr($xclaveacc,30,9).''; ?>">
								<?php echo $xautorfec;	?>
								</a>
							</td>
						</tr>
						<?php } ?>

						<?php if($xatrz!="" and mb_stristr('FP.RC',substr($docu,0,2))){ ?>
						<tr>
							<td align="right">AUTORIZACION:</td>
							<td align="left" style="<?php if($xatrzvali=='X'){echo 'color:red;';}?><?php if($xatrzvali=='O'){echo 'color:yellow;';}?>">
                <?php echo $xatrz; ?>
                <?php //if($xatrzvali!='F'){ echo ' - '.$xatrzvali;}; ?>
                <?php echo ' ('.$xatrzvali.')'; ?>
              </td>
						</tr>
						<?php } ?>
            
						<?php } ?>

						<?php if (mb_stristr($filepdf,'/.pdf')){$filepdf='';}?>
						
						<?php if ($docupdf==1 or $entipdf==1){?>
						<?php if (file_exists($filepdf) or $mdisplay==1){?>
						<tr class="noprint">
						<td align="right" style="font-size:70%;">DESCARGAR</td>
						<td align="center">
							<a href="<?php if($cdisplay==1){echo 'http://vcrxol.com/_cel/'.$subdce.$xclaveacc.'.pdf';}?>" 
								 title="Descargar RIDE"
								 download="<?php echo substr($docu,0,1).'_'.substr($xclaveacc,10,13).'_'.substr($xclaveacc,24,6).'_'.substr($xclaveacc,30,9).''; ?>"
								 >Formato RIDE </a>
						</td>
						</tr>
						<?php } ?>
						<?php }?>
						
						<?php //if(mysql_result($res_tra1,0,'status')!="-"){ ?>
						<?php if($xstatus!="-" and $xstatus!=''){ ?>
						<tr>
							<td align="right">STATUS:</td>
							<td style="<?php if(mb_stristr('XO',$xstatus)){
									echo 'background-color:red;color:white;font-weight:bold;letter-spacing:5px;text-align:center;';} ?>">
								<?php echo mysql_result($res_tra1,0,'stat_descri');?></td>
						</tr>
						<?php}?>
						<?php if($xclaveacc!="" and $cdisplay==2){ ?>
						<?php } ?>
					</table>
					<?php}?>
          <?php
                                                     
             $docu_txt.=str_pad('DATOS DEL COMPROBANTE ',$coltxt,$carbot,STR_PAD_BOTH).$eol;
             $docu_txt.= 'TIPO         : '.$docu_descri.$eol;
             $docu_txt.= 'NUMERO       : '.@mysql_result($res_tra1,0,'ptonumero').$eol;
//              $docu_txt.= 'FECHA        : '.date('',strtotime(@mysql_result($res_tra1,0,'fecha'))).' '.@mysql_result($res_tra1,0,'fechadmy').$eol;
             $docu_txt.= 'FECHA        : '.@mysql_result($res_tra1,0,'fdian').' '.@mysql_result($res_tra1,0,'fechadmy').$eol;
// 						 if(mb_stristr('vtas.comp.clie.prov',$tabla) and @mysql_result($res_tra1,0,'plazo')>0)
// 						 {$docu_txt.='|VENCE : '.@mysql_result($res_tra1,0,'vencedmy').$eol;}
             if($vndd!='')
             {$docu_txt.= 'VENDEDOR     : '.$vndd.$eol;}
             if($claveacc!='')
             {
             $docu_txt.= 'AMBIENTE     : '.$xambides.$eol;
             $docu_txt.= 'CLAVE ACCESO : '.$eol;
             $docu_txt.= format_claveacc($claveacc).$eol;
             }
             $docu_txt.=$eol;
               
          ?>
        <?php 
//           $posY=48;
          $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-2);
          $docu_pdf->SetY($posY2);
          $docu_pdf->SetX($pdf_ancho*.605+10);
          $docu_pdf->Cell($pdf_ancho*.4,5,'DATOS DEL COMPROBANTE','LRTB',0,'C',true);
          $docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-3);
          $docu_pdf->ln();
          $docu_pdf->SetX($pdf_ancho*.605+10);
          $docu_pdf->Cell($pdf_ancho*.1,5,'TIPO :','LRT',0,'R',false);
          $docu_pdf->MultiCell($pdf_ancho*.3,5,$docu_descri,'LRT','L',false);
          $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-3);
          $docu_pdf->SetX($pdf_ancho*.605+10);
          $docu_pdf->Cell($pdf_ancho*.1,5,'NUMERO :','LRT',0,'R',false);
          $docu_pdf->MultiCell($pdf_ancho*.3,5,@mysql_result($res_tra1,0,'ptonumero'),'LRT','L',false);
          $docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-3);
          $docu_pdf->SetX($pdf_ancho*.605+10);
          $docu_pdf->Cell($pdf_ancho*.1,5,'FECHA :','LRT',0,'R',false);
          $docu_pdf->MultiCell($pdf_ancho*.3,5,utf8_decode(@mysql_result($res_tra1,0,'fdian')).' '.@mysql_result($res_tra1,0,'fechadmy'),'LRT','L',false);
					if(mb_stristr('vtas.comp.clie.prov',$tabla) and mysql_result($res_tra1,0,'plazo')>1 )
					{
          $docu_pdf->SetX($pdf_ancho*.605+10);
          $docu_pdf->Cell($pdf_ancho*.1,5,'VENCE :','LRT',0,'R',false);
          $docu_pdf->MultiCell($pdf_ancho*.3,5,@mysql_result($res_tra1,0,'vencedmy'),'LRT','L',false);
					}
          $docu_pdf->SetX($pdf_ancho*.605+10);
          $docu_pdf->SetFontSize($fsizePDF-4);

// 					if($xclaveacc!='')
					if($xclaveacc!='' and mb_stristr('01.04.05.06.07',substr($xclaveacc,8,2)))
					{
//             if(mb_stristr('01.04.05.06.07',substr($xclaveacc,8,2)))
            {
            $docu_pdf->Cell($pdf_ancho*.1,5,'AMBIENTE :','LRT',0,'R',false);
            $docu_pdf->MultiCell($pdf_ancho*.3,5,$xambides,'LRT','L',false);
            }

            $subdce=mk_subdce($claveacc);
            
						$docu_pdf->SetFontSize($fsizePDF-6.5);
						$docu_pdf->SetTextColor(0,0,0);
          	$docu_pdf->SetFont($ffamilyPDF,'');
						$docu_pdf->Link($pdf_ancho*.605+10,$docu_pdf->GetY(),$pdf_ancho*.4,5,'http://vcrxol.com/_cel/'.$subdce.$filexmlb);
						$docu_pdf->SetX($pdf_ancho*.605+10);
						$docu_pdf->Cell($pdf_ancho*.1,5,'CLAVE ACCESO :','LRT',0,'R',false);
						$docu_pdf->SetFont($ffamilyPDF,'U');
						$docu_pdf->SetTextColor(0,0,255);
						$docu_pdf->MultiCell($pdf_ancho*.3,5,$xclaveacc,'LRT','L',false);

//             if(mb_stristr('01.04.05.06.07',substr($xclaveacc,8,2)))
            {
						$docu_pdf->SetTextColor(0,0,0);
          	$docu_pdf->SetFont($ffamilyPDF,'');
						$docu_pdf->Link($pdf_ancho*.605+10,$docu_pdf->GetY(),$pdf_ancho*.4,5,'http://vcrxol.com/_cel/'.$subdce.$filexml);
						$docu_pdf->SetX($pdf_ancho*.605+10);
						$docu_pdf->Cell($pdf_ancho*.1,5,'AUTORIZACION :','LRT',0,'R',false);
						$docu_pdf->SetFont($ffamilyPDF,'U');
						$docu_pdf->SetTextColor(0,0,255);
						$docu_pdf->MultiCell($pdf_ancho*.3,5,$xclaveacc,'LRT','L',false);
            }

						$docu_pdf->SetTextColor(0,0,0);
          	$docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-3);
					}
																												
          $docu_pdf->SetFontSize($fsizePDF-2);
          $docu_pdf->SetX($pdf_ancho*.605+10);
          $docu_pdf->Cell($pdf_ancho*.1,1,'','T',0,'',false);
          $docu_pdf->MultiCell($pdf_ancho*.3,1,'','T','',false);

          $posY2=$docu_pdf->getY();
                                                        
        ?>

        </datos>

				<?php if($width>=150 or 1==1){?>					
					<div style="font-size:25%;"><br></div>
				<?php }else{ ?>
					</td>
					<td width=50% valign="top">
				<?php } ?>

					<?php ///// BLOQUE 2 ?>
					<resumen>
					<?php{?>
					<table border="1" width="100%" cellpadding="2" cellspacing="0" 
                 style="border-collapse:collapse;font-size:<?php echo $xfontsize; ?>px;<?php echo $xfontfamily;?>">
						<tr style="border:solid 1px; font-weight:bolder; background: #F7F7F7;">
							<td align="center" colspan=2 style="letter-spacing:5px;"><?php echo 'RESUMEN'; ?></td>
						</tr>
						<tr style="display:none;">
							<td width="70%"></td>
							<td></td>
						</tr>
						<tr align="right" style="<?php if($xtunid<=0){echo 'display:none;';} ?>">
							<td>UNIDADES:</td>
							<td><?php echo number_format($xtunid,2);?></td>
						</tr>
						<tr align="right" style="<?php if($xtserv<=0){echo 'display:none;';} ?>">
							<td>SERVICIOS:</td>
							<td><?php echo number_format($xtserv,2);?></td>
						</tr>
						<?php if(mb_stristr('guia', $tabla)){?>
						<tr>
							<td align="right">MOTIVO:</td>
							<td><?php echo $motivo;?></td>
						</tr>
						<tr>
							<td align="right">COMPROBANTE:</td>
							<td><?php echo $docuorigd;?></td>
						</tr>
						<tr>
							<td align="right">FECHA:</td>
							<td><?php echo $fechaorig;?></td>
						</tr>
						<tr>
							<td align="right">NUMERO:</td>
							<td><?php echo $numeroorig;?></td>
						</tr>
						<tr style="font-size:75%;">
							<td align="right">AUTORIZACION:</td>
							<td>
								<?php
						 			if($cdisplay==1){echo $autororig;}
						 			else
										{
											echo substr($autororig,0,8).'.'.substr($autororig,8,2).'.'.substr($autororig,10,13).'.'.substr($autororig,23,1)
											.'<br>'.substr($autororig,24,6).'.'.substr($autororig,30,9).'.'.substr($autororig,39,8).'.'.substr($autororig,47,2);
										}
								?>
							</td>
						</tr>
						<?php}?>	
						<?php if(mb_stristr('cont', $tabla)){?>
						<tr align="right">
							<td>DEBITOS</td>
							<td><?php echo number_format($xtdebito,2);?></td>
						</tr>
						<tr align="right">
							<td>CREDITOS</td>
							<td><?php echo number_format($xtcredito,2);?></td>
						</tr>
							<?php if($xdifer!=0){?>
							<tr align="right" >
								<td>DIFERENCIA</td>
								<td style="color:red;"><?php echo number_format($xdifer,2);?></td>
							</tr>
							<?php } ?>
						<?php } ?>
            <?php if(mb_stristr('clie.prod.vtas', $tabla)){?>
              <?php if($cfg_empr=='ecgl'){?>
                <tr align="right">
                  <td>LAMINAS:</td>
                  <td><?php echo number_format($xstlmn,2);?></td>
                </tr>
                <tr align="right">
                  <td>MTS:</td>
                  <td><?php echo number_format($xstmt1,2);?></td>
                </tr>
                <tr align="right">
                  <td>MT<sup>2</sup>:</td>
                  <td><?php echo number_format($xstmt2,2);?></td>
                </tr>
                <tr><td colspan="2"></td></tr>
              <?php } ?>
						<?php } ?>
            
						<?php if(mb_stristr('vtas.comp.clie.prov', $tabla)){?>
						<tr align="right">
							<td>SUB-TOTAL:</td>
							<td><?php echo number_format($xtsubt,2);?></td>
						</tr>
						<?php if($xpdcto!=0){?>
						<tr align="right" style="font-style:italic;">
							<td >DESCUENTO:</td>
							<td><?php echo number_format($xtdcto,2);?></td>
						</tr>
						<?php } ?>
						<?php if($xpprop!=0){?>
						<tr align="right" style="font-style:italic;">
							<td >PROPINA:</td>
							<td><?php echo number_format($xtprop,2);?></td>
						</tr>
						<?php } ?>
						<?php if($xpice!=0){?>
						<tr align="right" style="">
							<td >SUB-TOTAL ICE <?php echo number_format($xpice,0)?>%:</td>
							<td><?php echo number_format($xtice,2);?></td>
						</tr>
						<tr align="right" style="font-style:italic;">
							<td >ICE <?php echo number_format($xpice,0)?>%:</td>
							<td><?php echo number_format($xtice,2);?></td>
						</tr>
						<?php } ?>
						<tr align="right">
							<td >SUB-TOTAL IVA 0%:</td>
							<td><?php echo number_format($xtsubtiva0,2);?></td>
						</tr>
						<?php if($xpiva!=0){?>
						<tr align="right" style="">
							<td >SUB-TOTAL IVA <?php echo number_format($xpiva,0)?>%:</td>
							<td><?php echo number_format($xtsubtiva,2);?></td>
						</tr>
						<tr align="right" style="font-style:italic;">
							<td >IVA <?php echo number_format($xpiva,0)?>%:</td>
							<td><?php echo number_format($xtiva,2);?></td>
						</tr>
						<?php } ?>
						<?php}?>	

            
            
            
						<?php if(mb_stristr('retc.retp.', $tabla)){?>
						<tr align="right">
							<td >RET.IVA:</td>
							<td><?php echo number_format($xtriva,2);?></td>
						</tr>
						<tr align="right">
							<td >RET.RTA:</td>
							<td><?php echo number_format($xtrrta,2);?></td>
						</tr>
						<?php}?>	
						
						<?php //if($guiaremi==0){?>
						<?php if(!mb_stristr('guia.cont.',$tabla)){?>
						<tr align="right" style="font-weight:bolder;<?php if($xtotal==0){echo 'display:none;';} ?>">
							<td >TOTAL:</td>
							<td><?php echo number_format(abs($xtotal),2);?></td>
						</tr>
						<?php } ?>

            <?php if(mb_stristr('clie', $tabla)){?>
              <?php if($cfg_empr=='dly1' and $xcomi>0){?>
            
                <?php $xcomi=$xtotal* $enticomi /100; ?>
                <?php $xapagar=$xtotal-$xcomi; ?>
                <tr><td colspan="2"></td></tr>
                <tr align="right">
                  <td>COMISION:</td>
                  <td><?php echo number_format($xcomi,2);?></td>
                </tr>
                <tr align="right" style="font-weight:bolder;">
                  <td>A PAGAR:</td>
                  <td><?php echo number_format($xapagar,2);?></td>
                </tr>
                <tr><td colspan="2"></td></tr>
              <?php } ?>
						<?php } ?>
						
					</table>					
					<?php}?>
					</resumen>

          <?php
//              $colval=10;
//              $docu_txt.=str_pad('RESUMEN ',$coltxt,$carbot,STR_PAD_BOTH).$eol;
// 						 if(mb_stristr('vtas.comp.clie.prov',$tabla))
// 						 {
//                $docu_txt.= str_pad('S.TOTAL:',($coltxt-$colval),' ',STR_PAD_LEFT).str_pad(number_format($xtsubt,2),$colval,'.',STR_PAD_LEFT).$eol;
// 							 if($xtdcto>0)
//                {$docu_txt.= str_pad('DESCUENTO :',$coltxt-$colval,' ',STR_PAD_LEFT).str_pad(number_format($xtdcto,2),$colval,'.',STR_PAD_LEFT).$eol;}
//                $docu_txt.= str_pad('S.TOTAL IVA 0%:',($coltxt-$colval),' ',STR_PAD_LEFT).str_pad(number_format($xtsubtiva0,2),$colval,'.',STR_PAD_LEFT).$eol;
// 							 if($xpiva>0)
// 							 {$docu_txt.= str_pad('S.TOTAL IVA '.number_format($xpiva,0).'% :',$coltxt-$colval,' ',STR_PAD_LEFT).str_pad(number_format($xtsubtiva,2),$colval,'.',STR_PAD_LEFT).$eol;}
//                if($xtice>0)
// 							 {$docu_txt.= str_pad('ICE :',$coltxt-$colval,' ',STR_PAD_LEFT).str_pad(number_format($xtice,2),$colval,'.',STR_PAD_LEFT).$eol;}
// 							 $docu_txt.=  str_pad('IVA :',$coltxt-$colval,' ',STR_PAD_LEFT).str_pad(number_format($xtiva,2),$colval,'.',STR_PAD_LEFT).$eol;
//                if($xtirbp>0)
// 							 {$docu_txt.= str_pad('IRBP :',$coltxt-$colval,' ',STR_PAD_LEFT).str_pad(number_format($xtirbp,2),$colval,'.',STR_PAD_LEFT).$eol;}
// 						 }
// 						 $docu_txt.= str_pad('TOTAL :',$coltxt-$colval,' ',STR_PAD_LEFT).str_pad('> '.number_format($xtotal,2),$colval,' =',STR_PAD_LEFT).$eol;
//              $docu_txt.=$eol;
          ?>
        <?php 
//           $posY=48;
          $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-2);
          $docu_pdf->SetY($posY2);
          $docu_pdf->SetX($pdf_ancho*.605+10);
          $docu_pdf->Cell($pdf_ancho*.4,5,'RESUMEN','LRTB',0,'C',true);
          $docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-3);
          $docu_pdf->ln();
					if(mb_stristr('vtas.comp.clie.prov',$tabla))
					{
            
					if(mb_stristr('vtas.clie',$tabla))
          {
						if($xtunid>0)
            {
            $docu_pdf->SetX($pdf_ancho*.605+10);
						$docu_pdf->Cell($pdf_ancho*.25,5,'UNIDADES :','LRT',0,'R',false);
						$docu_pdf->MultiCell($pdf_ancho*.15,5,number_format($xtunid,2),'LRT','R',false);
            }
            
						if($xtserv>0)
            {
            $docu_pdf->SetX($pdf_ancho*.605+10);
						$docu_pdf->Cell($pdf_ancho*.25,5,'SERVICIOS :','LRT',0,'R',false);
						$docu_pdf->MultiCell($pdf_ancho*.15,5,number_format($xtserv,2),'LRT','R',false);
            }
          }
            
						$docu_pdf->SetX($pdf_ancho*.605+10);
						$docu_pdf->Cell($pdf_ancho*.25,5,'SUB-TOTAL :','LRT',0,'R',false);
						$docu_pdf->MultiCell($pdf_ancho*.15,5,number_format($xtsubt,2),'LRT','R',false);
            
						if($xtdcto>0)
            {
            $docu_pdf->SetX($pdf_ancho*.605+10);
						$docu_pdf->Cell($pdf_ancho*.25,5,'DESCUENTO :','LRT',0,'R',false);
						$docu_pdf->MultiCell($pdf_ancho*.15,5,number_format($xtdcto,2),'LRT','R',false);
            }
            
						$docu_pdf->SetX($pdf_ancho*.605+10);
						$docu_pdf->Cell($pdf_ancho*.25,5,'SUB-TOTAL IVA 0% :','LRT',0,'R',false);
						$docu_pdf->MultiCell($pdf_ancho*.15,5,number_format($xtsubtiva0,2),'LRT','R',false);
						if($xpiva>0) 
						{
						$docu_pdf->SetX($pdf_ancho*.605+10);
						$docu_pdf->Cell($pdf_ancho*.25,5,'SUB-TOTAL IVA '.number_format($xpiva,0).'%:','LRT',0,'R',false);
						$docu_pdf->MultiCell($pdf_ancho*.15,5,number_format($xtsubtiva,2),'LRT','R',false);

            $docu_pdf->SetX($pdf_ancho*.605+10);
						$docu_pdf->Cell($pdf_ancho*.25,5,'IVA :','LRT',0,'R',false);
						$docu_pdf->MultiCell($pdf_ancho*.15,5,number_format($xtiva,2),'LRT','R',false);
            }
					}
					if(mb_stristr('retc.retp',$tabla))
					{
						$docu_pdf->SetX($pdf_ancho*.605+10);
						$docu_pdf->Cell($pdf_ancho*.25,5,'RET.IVA :','LRT',0,'R',false);
						$docu_pdf->MultiCell($pdf_ancho*.15,5,number_format($xtriva,2),'LRT','R',false);
						$docu_pdf->SetX($pdf_ancho*.605+10);
						$docu_pdf->Cell($pdf_ancho*.25,5,'RET.RTA :','LRT',0,'R',false);
						$docu_pdf->MultiCell($pdf_ancho*.15,5,number_format($xtrrta,2),'LRT','R',false);
					}
          $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-3);
          $docu_pdf->SetX($pdf_ancho*.605+10);
          $docu_pdf->Cell($pdf_ancho*.25,5,'TOTAL :','LRT',0,'R',false);
          $docu_pdf->MultiCell($pdf_ancho*.15,5,number_format($xtotal,2),'LRT','R',false);
          $docu_pdf->SetX($pdf_ancho*.605+10);
          $docu_pdf->Cell($pdf_ancho*.25,1,'','T',0,'',false);
          $docu_pdf->MultiCell($pdf_ancho*.15,1,'','T','',false);
                                                        
          $posY2=$docu_pdf->getY();
        ?>
            
            
            
            
				<?php if($width>=150 or 1==1){?>					
				<?php }else{ ?>
					</td>
					</tr>
					<tr>
					<td>
				<?php } ?>
					<?php ///// BLOQUE 3 ?>
					<?php{?>
					<?php if(mb_stristr('vtas.comp', $tabla)){?>
					<div style="font-size:25%;"><br></div>
					<table border="1" width="100%" cellpadding="2" cellspacing="0" 
                 style="border-collapse:collapse;font-size:<?php echo $xfontsize; ?>px;<?php echo $xfontfamily;?>">
						<?php if(mb_stristr('NC.NP',substr($docu,0,2))){?>
						<?php
							$xtoenti=@mysql_result($res_tra1,0,'enti');
							$xtodocu=@mysql_result($res_tra1,0,'todocu');
							$xtoptoe=@mysql_result($res_tra1,0,'toptoe');
							$xtonumero=@mysql_result($res_tra1,0,'tonume');
              if(mb_stristr('FC',substr($xtodocu,0,2)))
              {$sql_todoc='select * from vtas11 where enti="'.$xtoenti.'" and docu="'.$xtodocu.'" and numero="'.$xtonumero.'" and ptoe="'.$xtoptoe.'"';}
              if(mb_stristr('FP',substr($xtodocu,0,2)))
              {$sql_todoc='select * from comp11 where enti="'.$xtoenti.'" and docu="'.$xtodocu.'" and numero="'.$xtonumero.'" and ptoe="'.$xtoptoe.'"';}
              $res_todoc=mysql_query($sql_todoc,$link_vcrx);
              if(mysql_num_rows($res_todoc)==0)
              {
                upl_cexml(mysql_result($res_tra1,0,'claveacc'));
                $res_todoc=mysql_query($sql_todoc,$link_vcrx);
                if(mysql_num_rows($res_todoc)==0)
                {
                  if(mb_stristr('FC',substr($xtodocu,0,2)))
                  {$sql_todoc='select * from vtas11 where enti="'.$xtoenti.'" and docu="'.$xtodocu.'" and numero="'.$xtonumero.'"';}
                  if(mb_stristr('FP',substr($xtodocu,0,2)))
                  {$sql_todoc='select * from comp11 where enti="'.$xtoenti.'" and docu="'.$xtodocu.'" and numero="'.$xtonumero.'"';}
                  $res_todoc=mysql_query($sql_todoc,$link_vcrx);
                }
              }
							$xtofecha=@mysql_result($res_todoc,0,'fechadmy');
						?>
						<tr style="border:solid 1px; font-weight:bolder; background: #F7F7F7;">
							<td align="center" colspan="2">MODIFICA</td>
						</tr>
						<tr>
								<td>COMPROBANTE</td>
								<td>FACTURA</td>
						</tr>
						<tr>
								<td>NUMERO</td>
								<td><?php echo $xtoptoe.'-'.$xtonumero;?></td>
						</tr>
						<tr>
								<td>FECHA</td>
								<td><?php echo $xtofecha;?></td>
						</tr>
						<?php } ?>
						<?php if(!mb_stristr('NC.NP',substr($docu,0,2))){ ?>
						<tr style="border:solid 1px; font-weight:bolder; background: #F7F7F7;<?php if($xfpag==0){echo 'display:none;';} ?>">
							<td align="center" >FORMA DE PAGO</td>
							<td></td>
						</tr>
						<tr style="<?php if($xfpag==0){echo 'display:none;';} ?>">
							<td style="font-size:70%;"><?php echo mysql_result($res_tra1,0,'fpag_descri'); ?></td>
							<td align="right"><?php echo number_format(abs($xtotal),2);?></td>
						</tr>
          <?php
             $docu_txt.=str_pad('FORMA DE PAGO ',$coltxt,$carbot,STR_PAD_BOTH).$eol;
             $docu_txt.= ''.mysql_result($res_tra1,0,'fpag_descri').$eol;
             $docu_txt.= str_pad(number_format(abs($xtotal),2),$coltxt,' ',STR_PAD_LEFT).$eol;
             $docu_txt.=$eol;
          ?>
            
        <?php 
//           $posY=48;
          $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-2);
          $docu_pdf->SetY($posY2);
          $docu_pdf->SetX($pdf_ancho*.605+10);
          $docu_pdf->Cell($pdf_ancho*.4,5,'FORMA DE PAGO','LRTB',0,'C',true);
          $docu_pdf->ln();
          $docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-6);
          $docu_pdf->SetX($pdf_ancho*.605+10);
          $docu_pdf->Cell($pdf_ancho*.3,5,mysql_result($res_tra1,0,'fpag_descri').':','LRT',0,'R',false);
          $docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-5);
          $docu_pdf->MultiCell($pdf_ancho*.1,5,number_format(abs($xtotal),2),'LRT','R',false);
          $docu_pdf->SetX($pdf_ancho*.605+10);
          $docu_pdf->Cell($pdf_ancho*.25,1,'','T',0,'',false);
          $docu_pdf->MultiCell($pdf_ancho*.15,1,'','T','',false);
                                                        
          $posY2=$docu_pdf->getY();
        ?>

            <?php } ?>
					</table>					
					<?php}?>
					<?php}?>


						
						
						
						
				<?php if($width>=150 or 1==1){?>					
				<?php }else{ ?>
					</td>
					</tr>
					
				<?php } ?>
						
						
				</td>
			</tr>
		</table>



<?php
          $docu_pdf->setY($posY1+2);
          if($posY2>$posY1){$docu_pdf->setY($posY2+2);}
          $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-2);

//           $docu_pdf->ln();
          $docu_pdf->Cell($pdf_ancho*.6,5,'DETALLE','TB',0,'L',true);
          $docu_pdf->ln();
                                                        
?>

<?php //////////////////////////////////////////////////////////	?>
<?php // DETALLE	?>
		<?php $crow=0;?>
		<?php $ccol=0;?>
		<?php $filag=5; ?>
		<?php if($cfg_empr=='ecgl' and mb_stristr('clie.vtas.prod',$tabla)){$filag=1000;} ?>
		<?php if($cfg_empr=='ecgl' and mb_stristr('clie.vtas',$tabla)){$xideta=0;} ?>
		<?php if($cfg_empr=='ecgl' and mb_stristr('prod',$tabla)){$xideta=0;} ?>
		<?php
			if(mb_stristr('OP',substr($docu,0,2)) and $cfg_empr=='ecgl')
			{
				$xipuni=0;
				$xtdcto=0;
				$xtprop=0;
				$xtiva=0;
				$xtice=0;
				$xtirbp=0;
			}
		?>
		<div style="font-size:25%;"><br></div>
		<?php if($guiaremi==1){?>
		<table border="0" width="100%" cellpadding="2" cellspacing="0" 
           style="border-collapse:collapse;font-size:<?php echo $xfontsize; ?>px;<?php echo $xfontfamily;?>">
			<tr style="background:#f7f7f7;font-weight:bolder; border-top:solid 1px; border-bottom:solid 1px; letter-spacing: 1px;">
				<td colspan="4">DATOS DEL TRANSPORTE</td></tr>
			<tr>
				<td width="24%"></td>
				<td width="25%"></td>
<!-- 				<td width="2%"></td> -->
				<td width="24%"></td>
				<td width="25%"></td>
			</tr>
			<tr>
				<td>INICIO DE TRANSPORTE :</td>
				<td><?php echo date('d/M/Y', strtotime(mysql_result($res_tra1,0,'fecha1')));?></td>
				<td>FIN DE TRANSPORTE :</td>
				<td><?php echo date('d/M/Y', strtotime(mysql_result($res_tra1,0,'fecha2')));?></td>
			</tr>
			<tr>
				<td>No.ID. CONDUCTOR :</td>
				<td><?php echo mysql_result($res_tra1,0,'cedula1').'001';?></td>
				<td>No.ID. DESTINATARIO :</td>
				<td><?php echo mysql_result($res_tra1,0,'cedula2').'001';?></td>
			</tr>
			<tr>
				<td>NOM. CONDUCTOR :</td>
				<td><?php echo mysql_result($res_tra1,0,'nombre1');?></td>
				<td>NOM. DESTINATARIO :</td>
				<td><?php echo mysql_result($res_tra1,0,'nombre2');?></td>
			</tr>
			<tr>
				<td>PLACA DEL VEHICULO :</td>
				<td><?php echo mysql_result($res_tra1,0,'placa');?></td>
				<td>RUTA :</td>
				<td><?php echo mysql_result($res_tra1,0,'ruta');?></td>
			</tr>
			<tr>
				<td>PUNTO DE PARTIDA :</td>
				<td><?php echo mysql_result($res_tra1,0,'punto1');?></td>
				<td>PUNTO DE LLEGADA :</td>
				<td><?php echo mysql_result($res_tra1,0,'punto2');?></td>
			</tr>
		</table>
		<br>
		<?php } ?>
    <?php // explain_sql($sql_tra2); ?>
		<table border="0" width="100%" cellpadding="2" cellspacing="0" 
           style="border-collapse:collapse;font-size:<?php echo $xfontsize; ?>px;<?php echo $xfontfamily;?>">
			<tr style="background:#f7f7f7;font-weight:bolder; border-top:solid 1px; letter-spacing: 10px;"><td>DETALLE</td></tr>
		</table>
		<div style="font-size:25%;"><br></div>
		<detalle>
		<table id="deta<?php echo $cdisplay;?>" class="deta<?php echo $cdisplay;?>"
					 border="0" width="100%" cellpadding="2" cellspacing="0"
					 style="border-collapse:collapse;font-size:<?php echo $xfontsize; ?>px;<?php echo $xfontfamily;?>">
		<thead>
		<tr style="background:#f7f7f7; border-top:solid 1px; border-bottom:solid 1px; cursor:pointer;" title="Reordenar">
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);" style="display:none;">L</th>
			<?php if(mb_stristr('cont',$tabla)){?>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">CUENTA</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);" width="25%" style="letter-spacing: 5px;">CONTABLE</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);" width="10%">DEBITOS</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);" width="10%">CREDITOS</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);" style="<?php if($xmcsub==""){echo 'display:none;';}?>;">C.SUB</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);" style="<?php if($xmcair==""){echo 'display:none;';}?>;">CAIR</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);" style="<?php if($xmitem==""){echo 'display:none;';}?>;">ITEM</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);" width="30%">DETALLE</th>
			<?php}?>
			<?php if(mb_stristr('guia',$tabla)){?>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">ITEM</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);"style="letter-spacing: 5px;">DESCRIPCION</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">CANT.</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">UNID.</th>
			<?php}?>
			<?php if(mb_stristr('vtas.comp.clie.prov.inve.prod',$tabla)){?>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">ITEM</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);"style="letter-spacing: 5px;">DESCRIPCION</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">CANT.</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);"></th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);" style="<?php if($xipuni==0){echo 'display:none;';}?>;">UNIT.</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);" style="<?php if($xipuni==0){echo 'display:none;';}?>;">SUBT.</th>
				<?php if(mb_stristr('vtas.comp.clie.prov',$tabla)){?>
					<th onclick="sortTable(this,<?php echo $ccol++; ?>);" style="<?php if($xipuni*$xtdcto==0){echo 'display:none;';}?>;">DESC</th>
					<th onclick="sortTable(this,<?php echo $ccol++; ?>);" style="<?php if($xipuni*$xtprop==0){echo 'display:none;';}?>;">PROP</th>
					<th onclick="sortTable(this,<?php echo $ccol++; ?>);" style="<?php if($xipuni*$xtice==0) {echo 'display:none;';}?>;">ICE</th>
					<th onclick="sortTable(this,<?php echo $ccol++; ?>);" style="<?php if($xipuni*$xtiva==0) {echo 'display:none;';}?>;">IVA</th>
					<th onclick="sortTable(this,<?php echo $ccol++; ?>);" style="<?php if($xipuni*$xtirbp==0){echo 'display:none;';}?>;">IRBP</th>
				<?php}?>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);" style="<?php if($xtotal==0){echo '';}?>;">TOTAL</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);"max-width="50%" style="<?php if($xmdetalle==""){echo 'display:none;';}?> ">DETALLE</th>

<?php
//              $docu_txt.=str_pad('DETALLE ',$coltxt,$carbot,STR_PAD_BOTH).$eol;
//              $docu_txt.=str_pad('|CODIGO',13,$padtxt,STR_PAD_RIGHT);
//              $docu_txt.=str_pad('CANT|',9,$padtxt,STR_PAD_LEFT);
//              $docu_txt.=str_pad('   ',3,$padtxt,STR_PAD_BOTH);
//              $docu_txt.=str_pad('P.UNI|',9,$padtxt,STR_PAD_LEFT);
//              $docu_txt.=str_pad('TOTAL|',15,$padtxt,STR_PAD_LEFT);
//              $docu_txt.=$eol;
                                                        
             $docu_txt.=str_pad('DETALLE ',$coltxt,$carbot,STR_PAD_BOTH).$eol;
             $docu_txt.=str_repeat('-',$coltxt).$eol;
//              $docu_txt.=str_pad('|CODIGO',13,$padtxt,STR_PAD_RIGHT);
             $docu_txt.=str_pad('COD/CANT',14,$padtxt,STR_PAD_BOTH);
             $docu_txt.=str_pad('|',1,$padtxt,STR_PAD_LEFT);
//              $docu_txt.=str_pad('   ',3,$padtxt,STR_PAD_BOTH);
             $docu_txt.=str_pad('P.UNI.|',10,$padtxt,STR_PAD_LEFT);
             $docu_txt.=str_pad('TOTAL|',10,$padtxt,STR_PAD_LEFT);
             $docu_txt.=$eol;
             $docu_txt.=str_repeat('-',$coltxt).$eol;
                                                        
?>
      <?php
          $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-3);
          $docu_pdf->Cell($pdf_ancho*.1,5,'CODIGO','TB',0,'C',true);
          $docu_pdf->Cell($pdf_ancho*.3,5,'DESCRIPCION','TB',0,'C',true);
          $docu_pdf->Cell($pdf_ancho*.1,5,'CANT.','TB',0,'C',true);
          $docu_pdf->Cell($pdf_ancho*.03,5,'','TB',0,'C',true);
          $docu_pdf->Cell($pdf_ancho*.1,5,'P.UNIT','TB',0,'C',true);
          $docu_pdf->Cell($pdf_ancho*.1,5,'SUBT.','TB',0,'C',true);
          if($xtdcto>0)
          {$docu_pdf->Cell($pdf_ancho*.07,5,'DCTO','TB',0,'C',true);}
          if($xtice>0)
          {$docu_pdf->Cell($pdf_ancho*.05,5,'ICE','TB',0,'C',true);}
          if($xtiva>0)
          {$docu_pdf->Cell($pdf_ancho*.05,5,'IVA','TB',0,'C',true);}
          $docu_pdf->Cell($pdf_ancho*.1,5,'TOTAL','TB',0,'C',true);
          $docu_pdf->ln();
        ?>
			<?php}?>

			<?php //$empr_cont=5 ;?>
			<?php if($empr_cont=='1' and $tabla=='comp'){?>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">CUENTA</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">CONTABLE</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">CAIR</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">%Rta</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">%IVA</th>
			<?php}?>
			<?php if(mb_stristr('retc.retp',$tabla)){?>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">EJERCICIO<br>FISCAL</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">BASE<br>IMPONIBLE</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);" width="30%">IMPUESTO</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">% Ret</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">VALOR<br>RETENIDO</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">COMPROBANTE</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">NUMERO</th>
      <?php
          $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-4);
          $docu_pdf->Cell($pdf_ancho*.1,10,'EJER.FISCAL','TB',0,'C',true);
          $docu_pdf->Cell($pdf_ancho*.1,10,'BASE IMP.','TB',0,'C',true);
          $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-3);
          $docu_pdf->Cell($pdf_ancho*.3,10,'IMPUESTO','TB',0,'C',true);
          $docu_pdf->Cell($pdf_ancho*.1,10,'%RET.','TB',0,'C',true);
          $docu_pdf->Cell($pdf_ancho*.1,10,'VAL.RETEN.','TB',0,'C',true);
          $docu_pdf->Cell($pdf_ancho*.15,10,'COMPROB.','TB',0,'C',true);
          $docu_pdf->Cell($pdf_ancho*.15,10,'NUMERO','TB',0,'C',true);
          $docu_pdf->ln();
        ?>
			
			<?php}?>

			<?php if(mb_stristr('caja.bcos',$tabla)){?>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">COMP.</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">NUMERO</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">VALOR</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">CUENTA</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">CONTABLE</th>
				<th onclick="sortTable(this,<?php echo $ccol++; ?>);">DETALLE</th>
			<?php}?>

      <?php if($cfg_empr=='pcs1' and substr($docu,0,2)=='FC') {?>
			<th onclick="sortTable(this,<?php echo $ccol++; ?>);" style="<?php if($xmcntn==""){echo 'display:none;';}?>;">CONTENEDOR</th>
			<th style="<?php if($xmcntn==""){echo 'display:none;';}?>;">DESDE</th>
			<th style="<?php if($xmcntn==""){echo 'display:none;';}?>;">HASTA</th>
			<?php}?>
      
		</tr>
		</thead>
		<?php $filax=0; ?>
		<?php $res_tra2=mysql_query($sql_tra2,$link_vcrx); ?>
    <?php //mysql_data_seek($res_tra2,0);?>
    <?php //echo explain_sql ($sql_tra2);?>  
		<tbody>
		<?php while($aso_tra2=mysql_fetch_assoc($res_tra2)){?>	
      <?php $mtime=microtime(true)-$mtime;?>
				<?php
				$filax++;
				$duni=$aso_tra2['item_duni'];
				$dpre=$aso_tra2['item_dpre'];
				$dval=$aso_tra2['item_dval'];
				$icodigov=$aso_tra2['item_codigov'];
				$item_codigo=$aso_tra2['item'];
				$item_descri=$aso_tra2['item_descri'];
				$ctas_descri=@$aso_tra2['ctas_descri'];
        $long_itemdes=strlen($item_descri);
        $long_ctasdes=strlen($ctas_descri);
	
				$detalle=$aso_tra2['detalle'];
        //corrige duplicidad del usuario
				$detalle=str_replace($xconcepto,'',$detalle);
				$detalle=str_replace($item_descri,'',$detalle);
        $long_detalle=strlen($detalle);                                                     
				if($item_descri!="" and $item_codigo!="-" and substr($item_codigo,0,4)!="9999" and mb_stristr('cont',$tabla))
				{$detalle.='<div style="font-size:80%;">'.' /'.$item_descri.'</div>';}
			
				if($icodigov==""){$icodigov=$aso_tra2['item'];}
                                                     
        if(substr($item_codigo,0,4)=="9999"){$item_descri=$detalle; $detalle='';}
                                                     
                                                     
				if($duni==0){$duni=2;}
				if($dpre==0){$dpre=2;}
				if($dval==0){$dval=2;}
				if(ceil($aso_tra2['cant'])!=floor($aso_tra2['cant']) and $duni==0){$duni=2;}
				?>
				<?php if($cfg_empr=='ecgl' and mb_stristr('clie.vtas.prod',$tabla) and substr($item_descri,0,4)=='VIDR'){ ?>
					<?php if($aso_tra2['itnum']>1){echo '<tr><td><br></td></tr>';}?>
          <?php
            $itsubt=0;
            $itdcto=0;
            $itiva=0;
            $itotal=0;
                                                                                                              
            if($tabla!='prod')                                                                                                             
            {                                                                                             
              $sql_itnum ='select * from '.$tabla.'12 where idnum1="'.$aso_tra2['idnum1'].'" and itnum="'.$aso_tra2['itnum'].'"';
              $res_itnum=mysql_query($sql_itnum,$link_vcrx);
              while($aso_itnum=@mysql_fetch_assoc($res_itnum))
              {
                $itsubt+=$aso_itnum['tsubt'];
                $itdcto+=$aso_itnum['tdcto'];
                $itiva+=$aso_itnum['tiva'];
                $itotal+=$aso_itnum['total'];
              }
            }
      
        ?>
					<tr style="<?php if($tabla=='prod' or 1==1){echo 'font-size:125%';} ?>">
					<td align="center" style="font-weight:bolder;"><?php echo '#'.fillzero($aso_tra2['itnum'],2);?>	</td>
					<td style="border:solid 1px; font-weight:bolder; background:#F7F7F7;">
					<?php $mm_e=substr($item_descri,strpos($item_descri,'MM')-2,2); ?>	
					<?php echo 'LAMINAS : '.$aso_tra2['lmns'];?>	
					<?php echo ' ('.$mm_e.'mm. ';?>	
					<?php echo ' X '.$aso_tra2['mm_l'].' ';?>	
					<?php echo ' X '.$aso_tra2['mm_a'].' )';?>	
					</td>
          <td align="right"><?php echo number_format($aso_tra2['lmns']);?></td>
          <td align="left">LAM.</td>
          <?php if($tabla=='prod'){ ?> 
            <?php
              $pulido='';
              $templar='';
              if($aso_tra2['puli']==1){$pulido='MATE';}
              if($aso_tra2['puli']==2){$pulido='BRILLANTE';}
              if($aso_tra2['tmpl']<=1){$templar='CRUDO';}
              if($aso_tra2['tmpl']==2){$templar='TEMPLAR';}
          
              $tsaques=number_format($aso_tra2['saqu0']+$aso_tra2['saqu1']+$aso_tra2['saqu2'],0);
              $tperfor=number_format($aso_tra2['perf0']+$aso_tra2['perf1']+$aso_tra2['perf2'],0);
              $tmts=number_format(($aso_tra2['mm_l']+$aso_tra2['mm_a'])*2/1000,2);
              $tmt2=number_format(($aso_tra2['mm_l']*$aso_tra2['mm_a'])/1000000,2);
            ?>
            <td align="center"><?php if($tsaques!=0){echo '| SAQ.: '.$tsaques.' ';}?></td>
            <td align="center"><?php if($tperfor!=0){echo '| PER.: '.$tperfor.' ';}?></td>
            <td align="center"><?php if($pulido!=''){echo '| PUL.: '.$pulido.' ';}?></td>
            <td align="right"><?php if($templar!=''){echo '| '.$templar.' |';}?></td>
          <?php }?>
          <?php if($tabla!='prod'){ ?>                                                                                                              
            <td align="right"><?php echo number_format($itsubt/$aso_tra2['lmns'],2);?></td>
            <td align="right"><?php echo number_format($itsubt,2);?></td>
            <td align="right" style="<?php if($xtdcto==0){echo 'display:none;';}?>;"><?php echo number_format($itdcto,2);?></td>
            <td align="right"><?php echo number_format($itiva,2);?></td>
            <td align="right"><?php echo number_format($itotal,2);?></td>
          <?php }?>
					</tr>	
				<?php	} ?>
      
      
			<tr valign="top" style="<?php if($filax %$filag==0){echo 'border-bottom:dotted 1px;';} ?> 
          <?php //if($cfg_empr=='ecgl' and mb_stristr('clie.vtas',$tabla)) {echo 'display:none';} ?>" >
					<td align="center" style="display:none;"><?php echo fillzero($crow++);?></td>
					
					<?php if(mb_stristr('cont',$tabla)){?>
						<td align="left"><?php echo $aso_tra2['ctas'];?></td>
						<td align="left"><?php echo $ctas_descri;?></td>
						<td align="right">
							<div style="display:none;"><?php echo fillzero($aso_tra2['tdebito'],9); ?></div>
							<?php echo number_format($aso_tra2['tdebito'],$duni);?>
						</td>
						<td align="right">
							<div style="display:none;"><?php echo fillzero($aso_tra2['tcredito'],9); ?></div>
							<?php echo number_format($aso_tra2['tcredito'],$duni);?>
						</td>
						<td align="center" style="<?php if($xmcsub==""){echo 'display:none;';}?>;"><?php echo $aso_tra2['csub'];?></td>
						<td align="center" style="<?php if($xmcair==""){echo 'display:none;';}?>;"><?php echo $aso_tra2['cair'];?></td>
						<td align="center" style="<?php if($xmitem==""){echo 'display:none;';}?>;font-size:80%;"><?php echo $aso_tra2['item'];?></td>
						<td align="left"><?php echo $detalle;?></td>
					<?php } ?>
					<?php if(mb_stristr('guia',$tabla)){?>
						<td align="left"><?php echo $aso_tra2['item'];?></td>
						<td align="left"><?php echo $item_descri;?></td>
						<td align="<?php if($duni==0){echo 'center';}else{echo 'right';}?>" >
							<div style="display:none;"><?php echo fillzero($aso_tra2['cant'],9); ?></div>
							<?php echo number_format($aso_tra2['cant'],$duni);?>
						</td>
						<td align="left"><?php echo $aso_tra2['item_umdd'];?></td>
					<?php } ?>
					<?php if(mb_stristr('vtas.comp.clie.carr.prov.inve.prod',$tabla)){?>
						<?php if(mb_stristr('vtas.clie.carr.prod',$tabla)){?>
						<td align="left"><span style="display:none;"><?php echo $aso_tra2['item'];?></span>
							<?php echo $icodigov;?></td>
						<?php }else{?>
						<td align="left"><?php echo $aso_tra2['item'];?></td>
						<?php } ?>
					<td align="left"  style="<?php if(substr($item_codigo,0,4)=='9900'){ echo 'font-size:75%;';} ?>">
						<?php echo $item_descri;?>
					</td>
					<td align="<?php if($duni==0){echo 'center';}else{echo 'right';}?>" >
						<div style="display:none;"><?php echo fillzero($aso_tra2['cant'],9); ?></div>
						<?php echo number_format($aso_tra2['cant'],$duni);?>
					</td>
					<td align="left" style="font-size:80%;">
						<?php echo ' '.$aso_tra2['item_umdd'];?>
					</td>
					<?php $xcant=$aso_tra2['cant']; ?>
					<?php $xpuni=$aso_tra2['puni']; ?>
					<?php $xsubt=$aso_tra2['tsubt']; ?>
					<?php $xdcto=$aso_tra2['tdcto']; ?>
					<?php $xprop=$aso_tra2['tprop']; ?>
					<?php $xice=$aso_tra2['tice']; ?>
					<?php $xiva=$aso_tra2['tiva']; ?>
					<?php $xirbp=$aso_tra2['tirbp']; ?>
					<?php $xttotal=$aso_tra2['total']; ?>
					<?php $xumdd=$aso_tra2['item_umdd']; ?>

<?php
             $docu_txt.=str_pad(''.$icodigov,13,$padtxt,STR_PAD_RIGHT);
             $docu_txt.=' |'.substr(str_replace($icodigov,'',$item_descri),0,$coltxt-14).$eol;
                                                                         
             $docu_txt.=str_pad(number_format($xcant,2),9,$padtxt,STR_PAD_LEFT).' '.$xumdd.'|';
             $docu_txt.=str_pad(number_format($xpuni,$dpre),9,$padtxt,STR_PAD_LEFT).'|';
//              $docu_txt.=str_pad(number_format($xsubt+$xiva,$dval),9,$padtxt,STR_PAD_LEFT).'|';
             $docu_txt.=str_pad(number_format($xttotal+$xdcto,$dval),9,$padtxt,STR_PAD_LEFT).'|';
             if($xiva>0){$docu_txt.='I';}
             $docu_txt.=$eol;
             if($xdcto>0)
             {$docu_txt.=''.str_pad('DCTO: '.number_format($xdcto,$dval),34,$padtxt,STR_PAD_LEFT);}
             $docu_txt.=$eol;
?>

        <?php
					if($filax %$filag==0){$lrtb='B';}else{$lrtb='';}																																				 

          $posY=$docu_pdf->GetY();

          $docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-4);
          if(strlen(trim($icodigov))>5){$docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-5);}                                                               
          $docu_pdf->Cell($pdf_ancho*.1,5,$icodigov,$lrtb,0,'L',false);
          $docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-5);
//           $docu_pdf->Cell($pdf_ancho*.3,5,substr(utf8_decode($item_descri),0,30),$lrtb,0,'L',false);

          $posX=$docu_pdf->GetX();
          $col_width=$pdf_ancho*.3;
          $docu_pdf->MultiCell($col_width,5,utf8_decode($item_descri),$lrtb,'L',false);
          $posYb=$docu_pdf->GetY();
          $posX=$posX+$col_width;
          $docu_pdf->SetXY($posX,$posY);
                                                                         
          $docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-4);
//           $docu_pdf->Cell($pdf_ancho*.1,5,number_format($xcant,2).' '.$xumdd,$lrtb,0,'R',false);
          $docu_pdf->Cell($pdf_ancho*.1,5,number_format($xcant,2),$lrtb,0,'R',false);
          $docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-6);
          $docu_pdf->Cell($pdf_ancho*.03,5,$xumdd,$lrtb,0,'L',false);
          $docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-4);
          $docu_pdf->Cell($pdf_ancho*.1,5,number_format($xpuni,$dpre),$lrtb,0,'R',false);
          $docu_pdf->Cell($pdf_ancho*.1,5,number_format($xsubt,$dval),$lrtb,0,'R',false);
          if($xtdcto>0)
          {$docu_pdf->Cell($pdf_ancho*.07,5,number_format($xdcto,$dval),$lrtb,0,'R',false);}
          if($xtice>0)
          {$docu_pdf->Cell($pdf_ancho*.05,5,number_format($xice,$dval),$lrtb,0,'R',false);}
          if($xtiva>0)
          {$docu_pdf->Cell($pdf_ancho*.05,5,number_format($xiva,$dval),$lrtb,0,'R',false);}
          $docu_pdf->Cell($pdf_ancho*.1,5,number_format($xttotal,$dval),$lrtb,0,'R',false);
          $docu_pdf->ln();

          $docu_pdf->SetY($posYb);
                                                                         
        ?>
        
          <?php if($xideta==1){ ?>

					<td align="right" style="<?php if($xipuni==0){echo 'display:none;';}?>">
						<div style="display:none;"><?php echo fillzero($xpuni,9); ?></div>
						<?php echo number_format($xpuni,$dpre);?></td>
					<td align="right" style="<?php if($xipuni==0){echo 'display:none;';}?>">
						<div style="display:none;"><?php echo fillzero($xsubt,15); ?></div>
						<?php echo number_format(abs($xsubt),$dval);?></td>
					<td align="right" style="<?php if($xipuni*$xtdcto==0){echo 'display:none;';}?><?php if($xdcto==0){echo 'font-size:70%;';}?>font-style: italic;" title="<?php echo number_format($aso_tra2['dcto'],$dval)."%";?>">
						<div style="display:none;"><?php echo fillzero($xdcto,9); ?></div>
						<?php echo number_format($xdcto,$dval);?></td>
					<td align="right" style="<?php if($xipuni*$xtprop==0){echo 'display:none;';}?><?php if($xprop==0){echo 'font-size:70%;';}?>font-style: italic;" title="<?php echo number_format($aso_tra2['prop'],$dval)."%";?>">
						<div style="display:none;"><?php echo fillzero($xprop,9); ?></div>
						<?php echo number_format($xprop,$dval);?></td>
					<td align="right" style="<?php if($xipuni*$xtice==0){echo 'display:none;';}?><?php if($xice==0){echo 'font-size:70%;';}?>font-style: italic;" title="<?php echo number_format($aso_tra2['ice'],$dval)."%";?>">
						<div style="display:none;"><?php echo fillzero($xice,9); ?></div>
						<?php echo number_format($xice,$dval);?></td>
					<td align="right" style="<?php if($xipuni*$xtiva==0){echo 'display:none;';}?><?php if($xiva==0){echo 'font-size:70%;';}?>font-style: italic;" title="<?php echo number_format($aso_tra2['iva'],$dval)."%";?>">
						<div style="display:none;"><?php echo fillzero($xiva,9); ?></div>
						<?php echo number_format($xiva,$dval);?></td>
					<td align="right" style="<?php if($xipuni*$xtirbp==0){echo 'display:none;';}?><?php if($xirbp==0){echo 'font-size:70%;';}?>font-style: italic;" title="<?php echo number_format($aso_tra2['irbp'],$dval)."";?>">
						<div style="display:none;"><?php echo fillzero($xirbp,9); ?></div>
						<?php echo number_format($xirbp,$dval);?></td>
					<td align="right">
						<div style="display:none;"><?php echo fillzero($aso_tra2['total'],15); ?></div>
						<?php echo number_format(abs($aso_tra2['total']),$dval);?></td>

          <?php } ?>

          <td align="left" style="<?php if($xmdetalle==""){echo 'display:none;';}?>">
						<?php if(trim($detalle)!=trim($item_descri)){echo $detalle;};?></td>

          <?php if(mb_stristr('ecgl.',$cfg_empr)  and mb_stristr('clie.prod.vtas',$tabla)  ) {?>
              <?php if(mb_stristr($aso_tra2['item_descri'],'PERFOR')) {?>
                <td align="left" colspan="5" style=""><?php echo $aso_tra2['perfor1']; ?></td>
              <?php}?>	
              <?php if(mb_stristr($aso_tra2['item_descri'],'SAQUE')) {?>
                <td align="left" colspan="5" style=""><?php echo $aso_tra2['saques1']; ?></td>
              <?php}?>	
          <?php}?>	
        

          <?php}?>	

					<?php if($empr_cont=='1' and $tabla=='comp'){?>
					<td align="left" colspan="2">
            <?php 
                echo $aso_tra2['ctas'];
                echo '<span style="font-size:75%;"><br>'.$aso_tra2['ctas_descri'].'</span>';
            ?>
          </td>
<!-- 					<td align="left"><?php //echo $aso_tra2['ctas_descri'];?></td> -->
					<td align="center"><?php echo $aso_tra2['cair'];?></td>
					<td align="center"><div style="display:none;">
						<?php echo fillzero($aso_tra2['prrta'],9); ?></div><?php echo number_format($aso_tra2['prrta'],2);?>
					</td>
					<td align="center"><div style="display:none;">
						<?php echo fillzero($aso_tra2['priva'],9); ?></div><?php echo number_format($aso_tra2['priva'],2);?>
					</td>
					<?php}?>	
					
					<?php if(mb_stristr('retc.retp',$tabla)){?>
					<td align="center"><?php echo $aso_tra2['fanio'];?></td>
					<td align="right" style="<?php if(mb_stristr('retc.retp',$tabla)){echo 'padding-right:20px;';}?>">
						<div style="display:none;"><?php echo fillzero($aso_tra2['cant'],9); ?></div>
						<?php echo number_format($aso_tra2['cant'],2);?></td>
					<?php
						$cair='('.$aso_tra2['cair'].')';
						$docum_descri=$aso_tra2['docum_descri'];
						if(substr($aso_tra2['docum_descri'],0,4)=='FACT'){$docum_descri='FACTURA';}
// 						if($aso_tra2['puni']>=30 and $cair<300)
						if($aso_tra2['biva']>0)
						{$cair_descri='IVA';}
						else
						{$cair_descri=$aso_tra2['cair_descri']; $cair='<br>'.$cair;}
					?>
					<td align="center"><?php echo $cair_descri.' '.$cair;?></td>
					<?php if(ceil($aso_tra2['puni'])==floor($aso_tra2['puni'])){$dval=0;} ?>
					<td align="center">
						<div style="display:none;"><?php echo fillzero($aso_tra2['puni'],9); ?></div>
						<?php echo number_format($aso_tra2['puni'],$dval);?>%</td>
					<td align="right" style="<?php if(mb_stristr('retc.retp',$tabla)){echo 'padding-right:20px;';}?>">
						<div style="display:none;"><?php echo fillzero($aso_tra2['total'],15); ?></div>
						<?php echo number_format(abs($aso_tra2['total']),2);?></td>
					<td align="center"><?php echo $docum_descri;?></td>
          <?php if($cdisplay==1){?>
					<?php
            if($tabla=='retc'){$tdocum='vtas1';}
            if($tabla=='retp'){$tdocum='comp1';}
            $sql_docum='select * from '.$tdocum.' where numero="'.$aso_tra2['numer'].'" and ptoe="'.$aso_tra2['ptoem'].'" and enti="'.$aso_tra2['enti'].'" and status !="O" and status!="X"';
            $res_docum=mysql_query($sql_docum,$link_vcrx);
//             echo '*/*/'.mysql_error().$sql_docum;
            $clavedocum=@mysql_result($res_docum,0,'claveacc');                    
            $idnumdocum=@mysql_result($res_docum,0,'idnum1');                                    
            $docudocum=@mysql_result($res_docum,0,'docu');                                    
          ?>	
					<td align="center">
            <?php if ($clavedocum!=""){?>
                <a href="<?php echo 'http://'.$cfg_empr.'.vcrxol.com/print1.php?clave='.$clavedocum;?>"  target="_blank" >
            <?php }else{ ?>
                <?php if ($idnumdocum!=""){?>
                <a href="<?php echo 'http://'.$cfg_empr.'.vcrxol.com/print1.php?prnt=1&docu='.$docudocum.'&idnum='.$idnumdocum;?>"  target="_blank" >
                <?php }?>
            <?php }?>
            <?php echo $aso_tra2['ptonumer'];?>
                </a>
          </td>
					<?php}else{?>	
					<td align="center"><?php echo $aso_tra2['ptonumer'];?></td>
					<?php}?>	
				<?php
					$cair=str_replace('<br>','',$cair);
					$cair_descri=str_replace('<br>','',$cair_descri);
					if($filax %$filag==0){$lrtb='B';}else{$lrtb='';}

                                                
          $posY=$docu_pdf->GetY();
          $docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-3);
          $docu_pdf->Cell($pdf_ancho*.1,5,$aso_tra2['fanio'],$lrtb,0,'C',false);
          $docu_pdf->Cell($pdf_ancho*.1,5,number_format($aso_tra2['cant'],2),$lrtb,0,'R',false);
// 					$cair_descri=str_repeat(' 2 4 6 8 0',8);
					if(strlen($cair_descri)>25)
					{$docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-4);}
					if(strlen($cair_descri)>50)
					{$docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-5);}
					if(strlen($cair_descri)>75)
					{$docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-6);}
//           $docu_pdf->Cell($pdf_ancho*.3,5,$cair_descri.' '.$cair,$lrtb,0,'C',false);

          $posX=$docu_pdf->GetX();
          $col_width=$pdf_ancho*.3;
          $docu_pdf->MultiCell($col_width,5,$cair.' '.$cair_descri,$lrtb,'C',false);
          $posYb=$docu_pdf->GetY();
          $posX=$posX+$col_width;
          $docu_pdf->SetXY($posX,$posY);
                                                
                                                
          $docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-3);
          $docu_pdf->Cell($pdf_ancho*.1,5,number_format(abs($aso_tra2['puni']),0).'%',$lrtb,0,'C',false);
          $docu_pdf->Cell($pdf_ancho*.1,5,number_format(abs($aso_tra2['total']),2),$lrtb,0,'R',false);
//           $docu_pdf->SetFont($ffamilyPDF,'',$fsizePDF-4);
          $docu_pdf->Cell($pdf_ancho*.15,5,$docum_descri,$lrtb,0,'C',false);
          $docu_pdf->Cell($pdf_ancho*.15,5,$aso_tra2['ptonumer'],$lrtb,0,'C',false);
          $docu_pdf->ln();


          $docu_pdf->SetY($posYb);
				?>
					<?php}?>	

					<?php if(mb_stristr('caja.bcos',$tabla)){?>
					<?php 	$docum_descri=$aso_tra2['docum_descri'];?>
					<td align="center"><?php echo $docum_descri;?></td>
					<td align="center"><?php echo $aso_tra2['ptonumer'];?></td>
					<td align="right" >
						<div style="display:none;"><?php echo fillzero($aso_tra2['cant'],9); ?></div>
						<?php echo number_format($aso_tra2['cant'],2);?></td>
					<td align="center"><?php echo $aso_tra2['ctas'];?></td>
					<td align="left"><?php echo $aso_tra2['ctas_descri'];?></td>
					<td align="left"><?php echo $detalle;?></td>
					<?php}?>	
        
          <?php if($cfg_empr=='pcs1' and substr($docu,0,2)=='FC' and $aso_tra2['cntn']!="") {?>
            <td align="center"><?php echo $aso_tra2['cntn'];?></td>
            <td align="center"><?php echo date('d/M/y',strtotime($aso_tra2['cntnf1']));?></td>
            <td align="center"><?php echo date('d/M/y',strtotime($aso_tra2['cntnf2']));?></td>
          <?php }?>
					
				</tr>
		<?php}?>	
			
		<?php if($marcas==1){?>
			<?php $sql_mrca='select distinct item_mrca from '.$tabla.'12 where idnum2="'.$idnum.'" and item_mrca!="" and item_mrca is not null and item_mrca!="-"';?>
			<?php $res_mrca=mysql_query($sql_mrca,$link_vcrx);	?>
			<tr id="logomarcas"><td colspan="10">
			<?php while($aso_mrca=mysql_fetch_assoc($res_mrca)){?>	
				<?php $mrcafile=strtolower('mrca'.$aso_mrca['item_mrca'].'.png');?>
				<?php if(file_exists($rutalogo.$mrcafile)){ ?>
					<?php $crow++; ?>
					<img src="<?php echo 'http://vcrxol.com/_logo/'.$mrcafile; ?>" alt=""
							 title="<?php echo ''; ?>" style="max-width:100%; max-height:10mm;">		
				<?php } ?>
			<?php}?>	
			</tr></td>
		<?php}?>	
			
			<?php $mindeta=$mindeta-$crow; ?>
			<?php for($clinbr=1;$clinbr<=$mindeta;$clinbr++){?>
			<tr><?php echo str_repeat('<td><br></td>',$ccol); ?></tr>
			<?php } ?>
		</tbody>
		<tfoot>
		<tr style="background:#f7f7f7; border-top:solid 1px; border-bottom:solid 1px; font-weight:bolder;">
			
			<?php if(mb_stristr('cont',$tabla)){?>
				<th></th>
				<th align="center" colspan=1 style="letter-spacing: 5px;">TOTAL</th>
				<th align="right"><?php echo number_format($xtdebito,2);?></th>
				<th align="right"><?php echo number_format($xtcredito,2);?></th>
			<?php}?>
			
			<?php if(mb_stristr('guia',$tabla)){?>
				<th></th>
				<th align="center" colspan=1 style="letter-spacing: 5px;">TOTAL</th>
			<?php}?>
			
			<?php if(mb_stristr('vtas.comp.clie.prov.inve.prod',$tabla)){?>
				<th></th>
				<th align="center" colspan=1 style="letter-spacing: 5px;">TOTALES</th>
				<?php if(ceil($xtcant)!=floor($xtcant)  and $duni==0){$duni=2;} ?>
				<th align="<?php if($duni==0){echo 'center';}else{echo 'right';}?>">
          <?php echo number_format($xtcant,$duni);?>
        </th>
				<th></th>
			
				<th style="<?php if($xipuni==0){echo 'display:none;';}?>"></th>
				<th align="right" style="<?php if($xipuni==0){echo 'display:none;';}?>"><?php echo number_format(abs($xtsubt),$dval);?></th>
				<?php if(mb_stristr('vtas.comp.clie.prov',$tabla)){?>
					<th align="right" style="<?php if($xipuni*$xtdcto==0){echo 'display:none;';}?>font-style: italic;"><?php echo number_format($xtdcto,$dval);?></th>
					<th align="right" style="<?php if($xipuni*$xtprop==0){echo 'display:none;';}?>font-style: italic;"><?php echo number_format($xtprop,$dval);?></th>
					<th align="right" style="<?php if($xipuni*$xtice==0) {echo 'display:none;';}?>font-style: italic;"><?php echo number_format($xtice,$dval);?></th>
					<th align="right" style="<?php if($xipuni*$xtiva==0) {echo 'display:none;';}?>font-style: italic;"><?php echo number_format($xtiva,$dval);?></th>
					<th align="right" style="<?php if($xipuni*$xtirbp==0){echo 'display:none;';}?>font-style: italic;"><?php echo number_format($xtirbp,$dval);?></th>
				<?php}?>

      <?php
          $lrtb='TB';                                                                  
          $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-4);
          $docu_pdf->Cell($pdf_ancho*.1,5,' ',$lrtb,0,'L',true);
          $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-5);
          $docu_pdf->Cell($pdf_ancho*.3,5,'TOTALES',$lrtb,0,'C',true);
          $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-4);
          $docu_pdf->Cell($pdf_ancho*.1,5,number_format($xtcant,2),$lrtb,0,'R',true);
          $docu_pdf->Cell($pdf_ancho*.03,5,'',$lrtb,0,'R',true);
          $docu_pdf->Cell($pdf_ancho*.1,5,'',$lrtb,0,'R',true);
          $docu_pdf->Cell($pdf_ancho*.1,5,number_format($xtsubt,$dval),$lrtb,0,'R',true);
          if($xtdcto>0)
          {$docu_pdf->Cell($pdf_ancho*.07,5,number_format($xtdcto,$dval),$lrtb,0,'R',true);}
          if($xtice>0)
          {$docu_pdf->Cell($pdf_ancho*.05,5,number_format($xtice,$dval),$lrtb,0,'R',true);}
          if($xtiva>0)
          {$docu_pdf->Cell($pdf_ancho*.05,5,number_format($xtiva,$dval),$lrtb,0,'R',true);}
//           $docu_pdf->Cell($pdf_ancho*.1,5,'',$lrtb,0,'R',false);
          $docu_pdf->Cell($pdf_ancho*.1,5,number_format($xtotal,$dval),$lrtb,0,'R',true);
          $docu_pdf->ln();
        ?>

			<?php}?>
			
			<?php if(mb_stristr('retc.retp',$tabla)){?>
			<?php $dval=2; ?>
			<th></th>
			<th></th>
			<th align="center" colspan=1 style="letter-spacing: 5px;">TOTALES</th>
			<th></th>
      <?php
          $lrtb='TB';                                                                  
          $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-3);
          $docu_pdf->Cell($pdf_ancho*.1,5,' ',$lrtb,0,'L',true);
          $docu_pdf->Cell($pdf_ancho*.1,5,' ',$lrtb,0,'L',true);
          $docu_pdf->Cell($pdf_ancho*.3,5,'TOTALES',$lrtb,0,'C',true);
          $docu_pdf->Cell($pdf_ancho*.1,5,'',$lrtb,0,'R',true);
          $docu_pdf->Cell($pdf_ancho*.1,5,number_format($xtotal,$dval),$lrtb,0,'R',true);
          $docu_pdf->Cell($pdf_ancho*.15,5,' ',$lrtb,0,'L',true);
          $docu_pdf->Cell($pdf_ancho*.15,5,' ',$lrtb,0,'L',true);
          $docu_pdf->ln();
        ?>
			<?php } ?>
			
			<?php if(mb_stristr('caja.bcos',$tabla)){?>
			<?php $dval=2; ?>
			<th></th>
			<th align="center" colspan=1 style="letter-spacing: 5px;">TOTAL</th>
			<?php } ?>
			
			
			<th align="right" style="<?php if(mb_stristr('retc.retp',$tabla)){echo 'padding-right:20px;';}?>">
				<?php
					if(mb_stristr('cont',$tabla))
					{
						if($xdifer!=0)
						{
							echo '<div style="color:red;">';
							echo number_format(abs($xdifer),$dval);
							echo '</div>';
						}
					}
					else{echo number_format(abs($xtotal),$dval);}
				?>
			</th>
			<th align="right" style="<?php if($xmdetalle==""){echo 'display:none;';}?>"></th>
      <?php if($cfg_empr=='pcs1' and substr($docu,0,2)=='FC' and $xmcntn!="") {?>
        <th></th>
        <th></th>
        <th></th>
      <?php } ?>
      
<!-- 			<th></th> -->
<!-- 			<th></th> -->
	
		</tr>
		</tfoot>
		</table>
		</detalle>


          <?php
             $docu_txt.=str_repeat('-',$coltxt).$eol.$eol;
             $colval=12;
             $docu_txt.=str_pad('RESUMEN ',$coltxt,$carbot,STR_PAD_BOTH).$eol;
						 if(mb_stristr('vtas.comp.clie.prov',$tabla))
						 {
               $docu_txt.= str_pad('S.TOTAL :',($coltxt-$colval),' ',STR_PAD_LEFT).str_pad(number_format($xtsubt,2),$colval,'.',STR_PAD_LEFT).$eol;
							 if($xtdcto>0)
               {$docu_txt.= str_pad('DESCUENTO :',$coltxt-$colval,' ',STR_PAD_LEFT).str_pad(number_format($xtdcto,2),$colval,'.',STR_PAD_LEFT).$eol;}
               $docu_txt.= str_pad('S.TOTAL IVA 0% :',($coltxt-$colval),' ',STR_PAD_LEFT).str_pad(number_format($xtsubtiva0,2),$colval,'.',STR_PAD_LEFT).$eol;
							 if($xpiva>0)
							 {$docu_txt.= str_pad('S.TOTAL IVA '.number_format($xpiva,0).'% :',$coltxt-$colval,' ',STR_PAD_LEFT).str_pad(number_format($xtsubtiva,2),$colval,'.',STR_PAD_LEFT).$eol;}
               if($xtice>0)
							 {$docu_txt.= str_pad('ICE :',$coltxt-$colval,' ',STR_PAD_LEFT).str_pad(number_format($xtice,2),$colval,'.',STR_PAD_LEFT).$eol;}
							 $docu_txt.=  str_pad('IVA :',$coltxt-$colval,' ',STR_PAD_LEFT).str_pad(number_format($xtiva,2),$colval,'.',STR_PAD_LEFT).$eol;
               if($xtirbp>0)
							 {$docu_txt.= str_pad('IRBP :',$coltxt-$colval,' ',STR_PAD_LEFT).str_pad(number_format($xtirbp,2),$colval,'.',STR_PAD_LEFT).$eol;}
						 }
						 $docu_txt.= str_pad('TOTAL :',$coltxt-$colval,' ',STR_PAD_LEFT).str_pad('> '.number_format($xtotal,2),$colval,' =',STR_PAD_LEFT).$eol;
             $docu_txt.=$eol;
          ?>



<?php //////////////////////////////////////////////////////////	?>
<?php // PIE DE PAGINA	?>
		<footer1>
		<div style="font-size:25%;"><br></div>
		<table border="0" width="100%" cellpadding="2" cellspacing="0" 
           style="border-collapse:collapse;font-size:<?php echo $xfontsize; ?>px;<?php echo $xfontfamily;?>">
      <tr>
				<?php ///// PIE COLUMNA IZQUIERDA ?>
				<td width=50% valign="top">
					<?php if($notas==1){?>
					<table border="0" width="100%" cellpadding="2" cellspacing="0" 
                 style="border-collapse:collapse;font-size:<?php echo $xfontsize; ?>px;<?php echo $xfontfamily;?>">
					<tr style="background:#f7f7f7; border-top:solid 1px; border-bottom:solid 1px; font-weight:bolder;">
						<th style="letter-spacing:5pt;">NOTAS</th>
					</tr>
					<tr>
						<td><?php echo $serie_lote; ?></td>
					</tr>
					<?php if($xambi==2 and $xclaveacc!='' and mb_stristr('vtas.retp',$tabla)){?>
					<tr>
						<td style="font-size:70%;">
<!-- 						ESTA IMPRESION SOLO TIENE FINES INFORMATIVOS Y DE CONSULTA<br> -->
<!-- 						ESTA IMPRESION NO TIENE VALIDEZ TRIBUTARIA<br> -->
						Mas información en :
						<?php if($cdisplay==1) {?>
						<a target="_blank" href="http://www.sri.gob.ec/web/10138/145">PORTAL S.R.I.</a> / 
						<a target="_blank" href="https://declaraciones.sri.gob.ec/comprobantes-electronicos-internet/publico/validezComprobantes.jsf">VALIDADOR S.R.I.</a>
						<?php } ?>
						<?php if($cdisplay==2) { echo ' www.sri.gob.ec';}?>
						</td>
					</tr>
					<?php}?>
					<?php if(mb_stristr('ecgl.',$cfg_empr) and mb_stristr('clie',$tabla)) {?>
					<tr>
						<td>
							FORMA DE PAGO : 70% A LA ACEPTACION DE ESTA PROFORMA
							<br>SALDO CONTRA ENTREGA
							<br>FECHA DE ENTREGA : 5 DIAS LABORABLES
						</td>
					</tr>
					<?php } ?>
					<?php if(mb_stristr('gmny.gnya',$cfg_empr) and mb_stristr('clie',$tabla)) {?>
					<tr>
						<td>
							<b>CUENTAS PARA DEPOSITO O TRANSFERENCIA:</b>
							<br>BCO. PICHINCHA - (Germania Zambrano M.)
							<br>CTA. AHORROS # 448 268 2100
							<br>
              <br>BCO. BOLIVARIANO - (Germania Zambrano M.)
							<br>CTA. AHORROS # 002 129 8665 
						</td>
					</tr>
					<?php } ?>
					</table>
					<div style="height:10mm;"></div>
					<?php } ?>
				</td>

				<?php ///// PIE COLUMNA DERECHA ?>
				<td width=50% valign="top">
					<table border="0" width="100%" cellpadding="2" cellspacing="0" 
                 style="border-collapse:collapse;font-size:<?php echo $xfontsize; ?>px;<?php echo $xfontfamily;?>">
					<?php if(!mb_stristr('guia.cont',$tabla)){?>
					<tr>
						<td align="right" style="font-weight:bolder;">
						<?php if($xtotal!=0){echo 'SON : '.num2let(round(abs($xtotal),2));}?>
						</td>
					</tr>
					<?php } ?>
					</table>
				</td>
			</tr>

			<?php
          $docu_pdf->ln();
          $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-2);
          $docu_pdf->Cell(0,5,'SON : '.num2let(round(abs($xtotal),2)),'',0,'R',false);
          $docu_pdf->ln();
      ?>
      <?php
          $docu_txt.=str_pad('NOTAS ',$coltxt,$carbot,STR_PAD_BOTH).$eol;
//           $docu_txt.=str_repeat('-',$coltxt).$eol;
          if($claveacc!='')
          {$docu_txt.='DESCARGUE SU COMPROBANTE ELECTRONICO EN : ';
          $docu_txt.=$cfg_empr.'.vcrxol.com';}
          $docu_txt.=$eol;                                                        
      ?>
    </table>
		</footer1>


<?php //if(mb_stristr('vtas.clie.retp.',$tabla) or mb_stristr('',substr($docu,0,2))){ ?>
<?php if($firmas==1){ ?>
<?php if($cdisplay==2){ ?>
	<table border="0" width="100%" cellpadding="2" cellspacing="0" 
         style="border-collapse:collapse;font-size:<?php echo $xfontsize; ?>px;<?php echo $xfontfamily;?>">
		<tr style="height:10mm;"></tr>
		<tr style="height:10mm; font-size:100%;">
			<?php if($formato==1){?>
			<?php if(mb_stristr('cont',$tabla)){?>
				<td></td>
				<td align="center" valign="top" style="width:40mm; border-top:solid 1px;">FIRMA AUTORIZADA</td>
				<td></td>
			<?php } ?>
			<?php if(mb_stristr('vtas.bcos',$tabla)){?>
				<td></td>
				<td align="center" valign="top" style="width:40mm; border-top:solid 1px;">FIRMA AUTORIZADA</td>
				<td></td>
				<td align="center" valign="top" style="width:40mm; border-top:solid 1px;">RECIBI CONFORME</td>
				<td></td>
			<?php } ?>
			<?php if(mb_stristr('guia',$tabla)){?>
				<td></td>
				<td align="center" valign="top" style="width:40mm; border-top:solid 1px;">FIRMA AUTORIZADA</td>
				<td></td>
				<td align="center" valign="top" style="width:40mm; border-top:solid 1px;">CONDUCTOR</td>
				<td></td>
				<td align="center" valign="top" style="width:40mm; border-top:solid 1px;">RECIBI CONFORME</td>
				<td></td>
			<?php } ?>
			<?php if(mb_stristr('clie.prod',$tabla)){?>
				<td></td>
				<td align="center" valign="top" style="width:40mm; border-top:solid 1px;">FIRMA AUTORIZADA</td>
				<td></td>
				<td></td>
				<td></td>
			<?php } ?>
			<?php if(mb_stristr('retp',$tabla)){?>
				<td></td>
				<td align="center" valign="top" style="width:40mm; border-top:solid 1px;">AGENTE DE RETENCION</td>
				<td></td>
				<td align="center" valign="top" style="width:40mm; border-top:solid 1px;">SUJETO RETENIDO</td>
				<td></td>
			<?php } ?>
			<?php }else{ ?>
				<td></td>
				<td align="center" valign="top" style="width:40mm; border-top:solid 1px;">FIRMA AUTORIZADA</td>
				<td></td>
			<?php } ?>
		</tr>		
	</table>
<?php } ?>
<?php } ?>


	<table border="0" width="100%" cellpadding="2" cellspacing="0" 
         style="border-collapse:collapse;font-size:<?php echo $xfontsize; ?>px;<?php echo $xfontfamily;?>">
			<tr style="font-size:50%; border-top:solid 1px; border-bottom:solid 1px;">
				<td width="33%">
				<?php echo 'ID:'.$idnum;?>
				</td>
				<td width="34%" align="center" style="font-size:150%">
<!-- 				<a target="_blank" href="http://www.vcrxol.com">WWW.VCRXOL.COM - SISTEMAS EN LINEA</a> -->
				</td>
				<td width="33%" align="right" >
				<?php if($user_codigo!="" and $destino!='mail'){ ?>
				<?php echo 'IMPRESO POR: ';?>
				<?php //echo r_fiel('enti',$user_cedula,'nom1').' '.r_fiel('enti',$user_cedula,'ape1');?>
				<?php echo r_fiel('user',$user_codigo);?>
				<?php echo '<br>'; ?>
				<?php } ?>
				<?php echo date('d/M/y H:i:s');?>
				</td>
			</tr>
		</table>
        <?php 
          $docu_pdf->ln();
          $docu_pdf->ln();
          $docu_pdf->SetFont($ffamilyPDF,'B',$fsizePDF-2);
          $docu_pdf->SetFontSize($fsizePDF-8);
          $docu_pdf->Cell($pdf_ancho*.5,5,'ID:'.$idnum,'TB',0,'L',false);
          $docu_pdf->Cell($pdf_ancho*.5,5,date('d/M/y H:i:s'),'TB',0,'R',false);
          $docu_pdf->ln();
        ?>
        <?php
             $docu_txt.=str_repeat('-',$coltxt).$eol;
//              $docu_txt.= mysql_result($res_tra1,0,'iuser');
             $docu_txt.= date('d/M/y');
             $docu_txt.= str_pad(date('H:i:s'),$coltxt-9,' ',STR_PAD_LEFT);
             $docu_txt.=$eol;
             $docu_txt.=str_repeat('-',$coltxt);
//              $docu_txt.='<p class="saltodepagina" /></p>';
                                                        
        ?>		
  <?php	if(mb_stristr('PF.OP.PC',substr($docu,0,2)) and $cfg_empr=='ecgl'){ecgl_dise1($docu,$idnum);}?>

		
	</div>	
	<br>
	<?php $xfontsize=$printsize; ?>
	<?php } ?>

	<?php // if($destino=='mail'){ ?>
	<?php	//echo '</html>'; ?>
	<?php//  } ?>
	
<?php //////////////////////////////////////////////////////////	?>

<?php	
$docuhtml = ob_get_clean(); 
$docuhtml = alltrim($docuhtml);
?>
<?php //if($cfg_empr=='ecgl' and mb_stristr('FC',substr($docu,0,2))) {$docuhtml=str_replace('<tr>','<tr style="font-weight:bold;">',$docuhtml);} ?>
<?php
// pdf_sri($docu,$idnum);
  
// if($destino=='mail')
if($formato==1 or $claveacc!='' )
{
  $subdce=mk_subdce($claveacc);
  @unlink($rutace.$subdce.$xclaveacc.'.pdf');
  $docu_pdf->Output('F',$rutace.$subdce.$xclaveacc.'.pdf',true);
}
if(mb_stristr('pos.txt',$destino))
{
//   $docu_txt.='';
  file_put_contents($rutace.$subdce.$claveacc.'.txt',$docu_txt);
//   $docu_txt.='<p class="saltodepagina" /></p>';
  return $docu_txt;
}  
// if(substr($destino,0,3)=='pdf'){return file_get_contents($rutace.$subdce.$xclaveacc.'.pdf');} 
//   echo '***'.$destino;
// if(substr($destino,0,3)=='pdf'){return 'AAA';} 
// if(substr($destino,0,3)=='pdf'){return $docu_pdf;}  
  
if($destino=='mail' and ($docupdf==1 or $entipdf==1))	
{
	file_put_contents($rutadoc.$docu_idnum.'.htm',$docuhtml);
	if($xclaveacc!="")
	{
    if (!file_exists($filepdf) or $overpdf==1 )
	  {pdf_sri($docu,$idnum);}
	}
}	
else	
{file_put_contents($rutadoc.$docu_idnum.'.html',$docuhtml);}	

//       pdf_sri($docu,$idnum);
  

return $docuhtml;	
}
?>



<?php
function prnt_docur($pdocu,$pptoe,$pnumero,$penti,$destino='screen')
{
	include('../_cfg/config.php');
  $xfontsize=12;
  ob_start();
  
  if(substr($pdocu,0,2)=='FP'){$tret='retp12'; $tdoc='comp12';}
  if(substr($pdocu,0,2)=='FC'){$tret='retc12'; $tdoc='vtas12';}
  
  $xwhere=' where docu="'.$pdocu.'" and ptoe="'.$pptoe.'" and numero="'.$pnumero.'" and enti="'.$penti.'" ';
  
  $sql_tdoc='select sum(total) as total from '.$tdoc.$xwhere;
  $res_tdoc=mysql_query($sql_tdoc,$link_vcrx);
  $total=mysql_result($res_tdoc,0,'total');
  
  $xwhere=' where docum="'.$pdocu.'" and ptoem="'.$pptoe.'" and numer="'.$pnumero.'" and enti="'.$penti.'" ';
  
  $sql_rete='select * from '.$tret.$xwhere.' order by fecha,idnum1';
  $res_rete=mysql_query($sql_rete,$link_vcrx);
  
  $sql_caja='select * from caja12 '.$xwhere.' order by fecha,idnum1';
  $res_caja=mysql_query($sql_caja,$link_vcrx);
  
  $sql_bcos='select * from bcos12 '.$xwhere.' order by fecha,idnum1';
  $res_bcos=mysql_query($sql_bcos,$link_vcrx);
  
//   echo $sql_retp;
//   $sql_retc='select * from retc12 where docum="'.$docu.'" and ptoem="'.$ptoe.'" and numer="'.$xnumero.'" and enti="'.$xenti.'" order by fecha,idnum1';
//   $res_retc=mysql_query($sql_retc,$link_vcrx);
?>
<?php
  if(mysql_num_rows($res_rete)!=0 or mysql_num_rows($res_bcos)!=0 or mysql_num_rows($res_caja)!=0)
  {
?>
    <table border="0" width="100%" cellpadding="0" cellspacing="0" 
           style="border-collapse:collapse;font-size:<?php echo $xfontsize; ?>px;<?php echo $xfontfamily;?>">
    <thead>
			<tr style="border-top:solid 1px; border-bottom:solid 1px; font-weight:bolder; background:#F7F7F7;">
      <th align="center">FECHA</th>
      <th align="center">DOCUMENTO</th>
      <th align="center">NUMERO</th>
      <th align="center">VALOR</th>
      <th align="center">CAIR</th>
      <th align="center">BASE</th>
      <th align="center">%</th>
      <th align="center">DETALLE</th>
      </tr>
    </thead>
    <tbody>
    <?php $abono=0;?>
    <?php while($aso_deta=@mysql_fetch_assoc($res_rete)){ ?>
      <tr>
      <td align="center"><?php echo $aso_deta['fechadmy']; ?></td>
      <td align="center"><?php echo $aso_deta['docu_descri']; ?></td>
      <td align="center"><?php echo $aso_deta['ptonumero']; ?></td>
      <td align="right"><?php echo number_format(abs($aso_deta['total']),2); ?></td>
      <td align="center"><?php echo $aso_deta['cair']; ?></td>
      <td align="center"><?php echo number_format(abs($aso_deta['cant']),2).''; ?></td>
      <td align="center"><?php echo number_format(abs($aso_deta['puni']),2).''; ?></td>
      </tr>
      <?php $abono+=abs($aso_deta['total']); ?>
    <?php } ?>  
    <?php while($aso_deta=@mysql_fetch_assoc($res_bcos)){ ?>
      <tr>
      <td align="center"><?php echo $aso_deta['fechadmy']; ?></td>
      <td align="center"><?php echo $aso_deta['docu_descri']; ?></td>
      <td align="center"><?php echo $aso_deta['ptonumero']; ?></td>
      <td align="right"><?php echo number_format(abs($aso_deta['total']),2); ?></td>
      <td align="center"><?php //echo $aso_deta['cair']; ?></td>
      <td align="center"><?php //echo number_format(abs($aso_deta['cant']),2).''; ?></td>
      <td align="center"><?php //echo number_format(abs($aso_deta['puni']),2).''; ?></td>
      <td align="center"><?php echo $aso_deta['detalle'].' - '.$aso_deta['benefic']; ?></td>
      </tr>
      <?php $abono+=abs($aso_deta['total']); ?>
    <?php } ?>  
    <?php while($aso_deta=@mysql_fetch_assoc($res_caja)){ ?>
      <tr>
      <td align="center"><?php echo $aso_deta['fechadmy']; ?></td>
      <td align="center"><?php echo $aso_deta['docu_descri']; ?></td>
      <td align="center"><?php echo $aso_deta['ptonumero']; ?></td>
      <td align="right"><?php echo number_format(abs($aso_deta['total']),2); ?></td>
      <td align="center"><?php //echo $aso_deta['cair']; ?></td>
      <td align="center"><?php //echo number_format(abs($aso_deta['cant']),2).''; ?></td>
      <td align="center"><?php //echo number_format(abs($aso_deta['puni']),2).''; ?></td>
      <td align="center"><?php echo $aso_deta['detalle'].' - '.$aso_deta['benefic']; ?></td>
      </tr>
      <?php $abono+=abs($aso_deta['total']); ?>
    <?php } ?>  
    </tbody>
    <tfoot>
			<tr style="border-top:solid 1px; border-bottom:solid 1px; font-weight:bolder; background:#F7F7F7;">
      <th align="center"></th>
      <th align="center"></th>
      <th align="center">TOTAL</th>
      <th align="right"><?php echo number_format($abono,2);?></th>
      <th align="center"></th>
      <th align="center"></th>
      <th align="center"></th>
      <th align="right">SALDO : <?php echo number_format($total-$abono,2);?> </th>
      </tr>
    </tfoot>
    </table>
    <br>  
<?php  } ?>
<?php  
  $docurela = ob_get_clean(); 
  $docurela=alltrim($docurela);
  return $docurela;
  
}
?>


<?php
function prnt_docut($docu,$idnum,$colu=44,$destino='screen')
{
	include('../_cfg/config.php');
 	include('php_session.php');
  
}
?>

