<?php
include ('php_gene1.php');
$pnumpla=strtoupper(str_replace('-','',$_POST['pnumero']));

return get_vhcl0($pnumpla);

?>

<?php session_start();?>

<?php

$pnumpla=strtoupper(str_replace('-','',$_POST['pnumero']));

// $url = 'https://declaraciones.sri.gob.ec/facturacion-internet/consultas/publico/ruc-datos2.jspa?ruc='.$pnumpla;
$url = 'https://declaraciones.sri.gob.ec/mat-vehicular-internet/reportes/general/buscarVehiculoValoresPagar.jspa?placaCamv='.$pnumpla;

$page = file_get_contents($url);
// echo $url;

if(mb_stristr($page,$pnumpla) && !mb_stristr($page,'No existe el'))
{
  require('../cfg/cfg.php');
  require('../cfg/res.php');
//   echo $page;
	$sql_pla1='insert into vhcl0(vhcl_codigo,vhcl_descri,vhcl_status,vhcl_idate,vhcl_iuser)';
	$sql_pla1.='value("'.$pnumpla.'","NUEVO VHCL","-",now(),"'.$_SESSION['user_vcrx_id'].'")';
	$res_pla1=mysql_query($sql_pla1,$link_vcrx);
// 	echo $sql_pla1;
  
  $page2=$page;
  $page2=substr($page2,strpos($page2,"Marca:"),250);
  $page2=substr($page2,strpos($page2,"<td>")+4,250);
  $xmrca=trim(substr($page2,0,strpos($page2,"</td>")));
	
  $page2=$page;
  $page2=substr($page2,strpos($page2,"País:"),250);
  $page2=substr($page2,strpos($page2,"<td>")+4,250);
  $xpais=trim(substr($page2,0,strpos($page2,"</td>")));

  $page2=$page;
  $page2=substr($page2,strpos($page2,"Cilindraje:"),250);
  $page2=substr($page2,strpos($page2,"<td>")+4,250);
  $xcilindro=trim(substr($page2,0,strpos($page2,"</td>")));

  $page2=$page;
  $page2=substr($page2,strpos($page2,"Color 1:"),250);
  $page2=substr($page2,strpos($page2,"<td>")+4,250);
  $xclor1=trim(substr($page2,0,strpos($page2,"</td>")));

  $page2=$page;
  $page2=substr($page2,strpos($page2,"Color 2:"),250);
  $page2=substr($page2,strpos($page2,"<td>")+4,250);
  $xclor2=trim(substr($page2,0,strpos($page2,"</td>")));

  $page2=$page;
  $page2=substr($page2,strpos($page2,"Modelo:"),250);
  $page2=substr($page2,strpos($page2,"<td>")+4,250);
  $xmodelo=trim(substr($page2,0,strpos($page2,"</td>")));

  $page2=$page;
  $page2=substr($page2,strpos($page2,"Clase:"),250);
  $page2=substr($page2,strpos($page2,"<td>")+4,250);
  $xclase=trim(substr($page2,0,strpos($page2,"</td>")));

  $page2=$page;
  $page2=substr($page2,strpos($page2,"Modelo:"),500);
  $page2=substr($page2,strpos($page2,"textos")+8,250);
  $xanio=trim(substr($page2,0,strpos($page2,"</td>")));
	
	$xdescri='';
	$xdescri.=' '.$xmrca;
	$xdescri.=' /'.$xmodelo;
	$xdescri.=' /'.$xanio;
	$xdescri.=' /'.$xclor1;
	$xdescri=trim($xdescri);
	
 	$sql_pla1='select * from mrca0 where trim(mrca_descri) like "'.$xmrca.'"';
	$res_pla1=mysql_query($sql_pla1,$link_vcrx);
	if(mysql_num_rows($res_pla1)!=0)
	{$xmrca =  mysql_result($res_pla1,0,'mrca_codigo');}
	else
	{
		//insertar marca
	}
	
	
 	$sql_pla1='update vhcl0 set vhcl_descri="'.$xdescri.'" where vhcl_codigo like "'.$pnumpla.'"';
	$res_pla1=mysql_query($sql_pla1,$link_vcrx);

 	$sql_pla1='update vhcl0 set vhcl_mrca="'.$xmrca.'" where vhcl_codigo like "'.$pnumpla.'"';
	$res_pla1=mysql_query($sql_pla1,$link_vcrx);

	$sql_pla1='update vhcl0 set vhcl_clor="'.$xclor1.'" where vhcl_codigo like "'.$pnumpla.'"';
	$res_pla1=mysql_query($sql_pla1,$link_vcrx);

	$sql_pla1='update vhcl0 set vhcl_clor2="'.$xclor2.'" where vhcl_codigo like "'.$pnumpla.'"';
	$res_pla1=mysql_query($sql_pla1,$link_vcrx);

	$sql_pla1='update vhcl0 set vhcl_tipo="'.$xclase.'" where vhcl_codigo like "'.$pnumpla.'"';
	$res_pla1=mysql_query($sql_pla1,$link_vcrx);

	$sql_pla1='update vhcl0 set vhcl_cilindro="'.$xcilindro.'" where vhcl_codigo like "'.$pnumpla.'"';
	$res_pla1=mysql_query($sql_pla1,$link_vcrx);

	$sql_pla1='update vhcl0 set vhcl_anio='.$xanio.' where vhcl_codigo like "'.$pnumpla.'"';
	$res_pla1=mysql_query($sql_pla1,$link_vcrx);

	$xnumpla=true;

}
else
{$xnumpla=false;}

echo $xnumpla;

// aqui insertar en enti

?>

