<?php
class vrcelec1
{
	function vrcelec1($docu,$idnum,$formato)
	{
		require('../cfg/res.php');

require('../../_lib/vrnumlet2.php');
//numtoletras($var);

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


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

		$sql_tabla='select *from docu0 where docu_codigo="'.$docu.'"';
		$res_tabla=mysql_query($sql_tabla,$link_vcrx);
		
		$docu_tabla=mysql_result($res_tabla,0,'docu_tabla');
		$docu_tabla=strtolower($docu_tabla);

		if (mb_stristr('clie',substr($_SESSION['user_vcrx_tipo'],0,4)))
		{
			if (substr($docu,0,1)=='O')
			{$docu_tabla='clie';}
	
			if (substr($docu,0,1)=='F')
			{$docu_tabla='vtas';}

			if (substr($docu,0,1)=='N')
			{$docu_tabla='vtas';}
		}

		if (mb_stristr('prov',substr($_SESSION['user_vcrx_tipo'],0,4)))
		{
			if (substr($docu,0,1)=='O')
			{$docu_tabla='prov';}
	
			if (substr($docu,0,1)=='F')
			{$docu_tabla='comp';}
	
			
			if (substr($docu,0,1)=='R')
			{$docu_tabla='retp';}
		}

		
// 		$sql_tran1='select *from '.$docu_tabla.'11 where idnum1="'.$idnum.'"';
		$sql_tran1='select *from '.$docu_tabla.'11 left join sntr0 on sntr=sntr_codigo left join vhcl0 on vhcl=vhcl_codigo where idnum1="'.$idnum.'"';
		if (mb_stristr('clie.prov',substr($_SESSION['user_vcrx_empr'],0,4)))
		{
			$sql_tran1.='and enti like "'.$_SESSION['user_vcrx_empr'].'%"';
		}
		$res_tran1=mysql_query($sql_tran1,$link_vcrx);

// 		$xsntr=mysql_result($res_tran1,0,'sntr')		
// 		$xvhcl=mysql_result($res_tran1,0,'vhcl')		

// 		$sql_sntr='select *from sntr0 where sntr_codigo="'.$xsntr.'"';
// 		$res_sntr=mysql_query($sql_sntr,$link_vcrx);
	
// 		$sql_vhcl='select *from vhcl0 where vhcl_codigo="'.$xvhcl.'"';
// 		$res_vhcl=mysql_query($sql_vhcl,$link_vcrx);
	
			
		//$xtdcto=mysql_result($res_tran1,0,'tdcto');
		//$xtice=mysql_result($res_tran1,0,'tice');
		//$xtiva=mysql_result($res_tran1,0,'tiva');
		//$xtirbp=mysql_result($res_tran1,0,'tirbp');

		//$sql_tran2='select *from '.$docu_tabla.'12 where idnum1="'.$idnum.'" order by item_codigov, item ';
		$sql_tran2='select *from '.$docu_tabla.'12 where idnum1="'.$idnum.'" order by item_nctlg desc, item_pctlg, item ';
		//echo $sql_tran2.'ABC';
    $res_tran2=mysql_query($sql_tran2,$link_vcrx);
		
		$sql_tran3='select * from '.$docu_tabla.'12 where idnum1="'.$idnum.'" and item like "%TRAN%"';
		$res_tran3=mysql_query($sql_tran3,$link_vcrx);
		$xenvioa=1;


		if (mb_stristr('gnya',$_SESSION['user_vcrx_empr']))
		{
		if (mb_stristr('vtas.clie',$docu_tabla))
		{
                        //echo $sql_tran2;
			$res_tran2=mysql_query($sql_tran2,$link_vcrx);
			if(mysql_num_rows($res_tran2)!=0)
			{$xdrtr=mysql_result($res_tran2,0,'drtr');}
			else{$xdrtr="";}

			if (!empty($xdrtr))
			{
			$sql_drtr='select *from enti00 where enti_codigo="'.$xdrtr.'"';
			$res_drtr=mysql_query($sql_drtr,$link_vcrx);
			$xdrtr=mysql_result($res_drtr,0,'enti_descri');
			}
		}
		}		

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

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


// 		}

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

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

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

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

		
		//echo $sql_enti;
		
// 		$drtr=0;
// 		$sql_drtr='select *from drtr0 where left(enti_codigo,10) like "'.$_SESSION['user_vcrx_id'].'%"';
// 		$res_drtr=mysql_query($sql_drtr,$link_vcrx);
	
// 		if (mb_stristr('gnya',substr($_SESSION['user_vcrx_empr'],0,4)))
// 		{
// 			if (mysql_num_rows($res_drtr)!=0)
// 			{
// 			$drtr=1;
// 			}
// 		}


// 		$sql_drtr='select *from enti0 where enti_codigo="'.mysql_result($res_enti,0,'enti_referidox').'"';
// 		$res_drtr=mysql_query($sql_drtr,$link_vcrx);


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

		ob_start();		

?>




<html>

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

<style type="text/css">
BODY{font-family: courier new;}
@page {
/*    size: 7in 9.25in; */
/* 	 top left bott right */
     size: 215mm 297mm; 
    margin: 0mm 5mm 0mm 0mm; */
}
	
</style>
</head>

<body>

<div style="height:220px;"></div>

<div align="left">
<div align="left" style="width:1000px; font-size:12px;">
<table border="0" width="100%" cellspacing="0" cellpadding="2" style ="font-size:18px;">
<tr valign="top">
<td width="66%">
<!----++++++++++------>
	
<?php
if (mb_stristr('vtas.clie.prod',$docu_tabla))
{
?>

<table border="0" width="100%" cellspacing="0" cellpadding="2" style="border-collapse:collapse;">
<tr height="40px">
		<td width ="100px"></td>
	<?php
	if (mysql_result($res_enti,0,'enti_razsoc')!="")
	{
	?>
		<td><?php echo mysql_result($res_enti,0,'enti_razsoc');?></td>
	<?php
	}
	else
	{
	?>
		<td><?php echo mysql_result($res_enti,0,'enti_descri');?></td>
	<?php
	}
	?>
</tr>

<tr height="40px">
	<td></td>
	<td>
	<?php 
		if(mysql_result($res_enti,0,'enti_struc')=='A')
		{echo substr(mysql_result($res_enti,0,'enti_codigo'),0,10).'001';}
		else
		{echo mysql_result($res_enti,0,'enti_codigo');}
	?>
	</td>
</tr>



<tr height="40px">
	<td></td>
	<td>
	<?php 
	echo mysql_result($res_enti,0,'prvc_descri').' /'.mysql_result($res_enti,0,'cdad_descri');
	//echo  trim(mysql_result($res_enti,0,'enti_direccion')).' /'.mysql_result($res_enti,0,'enti_calle1').' /'.mysql_result($res_enti,0,'enti_callen').' /'.mysql_result($res_enti,0,'enti_calle2').' /'.mysql_result($res_enti,0,'enti_calle3');
	?>
	</td>
</tr>
<tr height="40px">
	<td></td>
	<td><?php echo mysql_result($res_enti,0,'enti_telefono');?></td>
</tr>
</table>

<!----++++++++++------>

<?php
}
?>




<!----++++++++++------>
</td>
<td>
<!----++++++++++------>
<table border="0" width="100%" cellspacing="0" cellpadding="2" style="border-collapse:collapse">

<tr height="40px">
	<td align="right" width="120px"><strong></strong></td>
	<td><strong><?php echo mysql_result($res_tran1,0,'numero');?></strong></td>
</tr>
<tr height="40px">
	<td align="right"></td>
	<td><?php echo mysql_result($res_tran1,0,'fechadmy');?></td>
</tr>


<?php
if (mb_stristr('vtas.clie.comp.prov',$docu_tabla))
{
?>
<tr height="40px">
	<td ></td>
    <td><?php 
 	if (mysql_result($res_tran1,0,'plazo')==0)
	{echo 'CONTADO';}
	else{echo 'CREDITO';}
		?></td>
</tr>
<?php
}
?>

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

<div style="height:50px;"></div>

<div style="height:680px">

<table border="0" width="100%" cellpadding="0" cellspacing="0" style=" width:1000px; border-collapse:collapse;font-size:18px;">

<?php
$filax=1;
$res_tran2=mysql_query($sql_tran2,$link_vcrx);
$duni=2;
while($r_tran2=mysql_fetch_assoc($res_tran2))
{
$duni=$r_tran2['item_duni'];
?>
<tr style=" <?php if($filax==999){echo 'border-bottom:dotted 1px #000;';$filax=1;}else{$filax++;} ?>" >
 	<td width="50px" align="right"><?php echo number_format($r_tran2['cant'],$duni);?></td>
	<td width="150px" align="center"><?php echo $r_tran2['item'];?></td>
	<td width="500px" style="max-width:500px"><?php echo $r_tran2['item_descri'];?></td>
	<td  align="right"><?php echo number_format($r_tran2['puni'],2);?></td>
	<td  align="right"><?php echo number_format($r_tran2['tsubt'],2);?></td>
</tr>

<?php }?>

<tr align="right" style="border-top:none 1px#000">
	<td></td>
	<td></td>

	<td align="left">

	<br/>
<table border="0" align="left"cellspacing="0" cellpadding="3" style="border-collapse:collapse">
<tr align="center">
	<th align="center" style="background: #F7F7F7;" colspan=2>INFORMACION ADICIONAL</th>
</tr>

<?php if(mysql_result($res_tran1,0,'concepto')!="") { ?>
	<tr>
	<td >CONCEPTO:</td>
	<td><?php echo mysql_result($res_tran1,0,'concepto');?></td>
	<tr/>
<?php } ?>
<?php if(mysql_result($res_tran1,0,'sntr')!="") { ?>
	<tr>
	<td align="right">SINIESTRO:</td>
	<td><?php echo mysql_result($res_tran1,0,'sntr_numero');?></td>
	<tr/>
	<?php if(mysql_result($res_tran1,0,'sntr_entrega')!="") { ?>
		<tr>
		<td align="right">TALLER:</td>
		<td><?php echo mysql_result($res_tran1,0,'sntr_entrega');?></td>
		<tr/>
	<?php } ?>
<?php } ?>
<?php if(mysql_result($res_tran1,0,'vhcl')!="") { ?>
	<tr>
	<td align="right">PLACA:</td>
	<td><?php echo mysql_result($res_tran1,0,'vhcl');?></td>
	<tr/>
	<tr>
	<?php if(mysql_result($res_tran1,0,'vhcl_mrca')!="") { ?>
		<tr>
		<td align="right">MARCA:</td>
		<td><?php echo mysql_result($res_tran1,0,'vhcl_mrca');?></td>
		<tr/>
	<?php } ?>
	<?php if(mysql_result($res_tran1,0,'vhcl_mdlo')!="") { ?>
		<tr>
		<td align="right">MODELO:</td>
		<td><?php echo mysql_result($res_tran1,0,'vhcl_mdlo');?></td>
		<tr/>
	<?php } ?>
	<?php if(mysql_result($res_tran1,0,'vhcl_anio')!="") { ?>
		<tr>
		<td align="right">AÑO:</td>
		<td><?php echo mysql_result($res_tran1,0,'vhcl_anio');?></td>
		<tr/>
	<?php } ?>
	<?php if(mysql_result($res_tran1,0,'vhcl_motor')!="") { ?>
		<tr>
		<td align="right">MOTOR:</td>
		<td><?php echo mysql_result($res_tran1,0,'vhcl_motor');?></td>
		<tr/>
	<?php } ?>
	<?php if(mysql_result($res_tran1,0,'vhcl_vinn')!="") { ?>
		<tr>
		<td align="right">VINN:</td>
		<td><?php echo mysql_result($res_tran1,0,'vhcl_vinn');?></td>
		<tr/>
	<?php } ?>
<?php } ?>

</table>
</td>
	<td></td>

	<td></td>
</tr>

</table>

</div>

	
<table border="0" width="1000px" cellpadding="0" cellspacing="0" style="border-collapse:collapse;font-size:16px;"  >
<tr>
<td width="100px">
</td>	

<td align="left">
<div style="height:50px">
</div>	
	<b><?php echo numtoletras(mysql_result($res_tran1,0,'total'));?>
</td>
	
<td width="200px">
</td>	

<td width="200px" align="right">
<?php echo '$'.number_format(mysql_result($res_tran1,0,'tsubtiva'),2);?>
<br><br>	
<?php echo '$'.number_format(mysql_result($res_tran1,0,'tsubtiva0'),2);?>
<br><br>	
<?php echo '$'.number_format(mysql_result($res_tran1,0,'tiva'),2);?>
<br><br>	
<b><?php echo '$'.number_format(mysql_result($res_tran1,0,'total'),2);?></b>		
</td>	
	
</tr>
</table>
	
	
</div>
</div>




<?php		

//file_put_contents($html1, ob_get_contents());
		
	}
}
?>
</html>