@ -149,7 +149,8 @@ function ImportaAstBilhetes($dbcon) {
global $numBilhetes;
global $numBilhetes;
$query = "drop table if exists tb_parametros;
$query = "drop table if exists tb_parametros;
create temporary table tb_parametros as
create temporary table tb_parametros as
select (select min(id) mun_padrao from pbx_municipios where to_ascii(nome_localidade) = (select to_ascii(prm_mun_padrao) from pbx_parametros) and uf = (select prm_uf_padrao from pbx_parametros)) as mun_padrao, (select prm_ddd_padrao from pbx_parametros) as prm_ddd_padrao;
select (select min(id) mun_padrao from pbx_municipios where to_ascii(nome_localidade) = (select to_ascii(prm_mun_padrao) from pbx_parametros)
and uf = (select prm_uf_padrao from pbx_parametros)) as mun_padrao, (select prm_ddd_padrao from pbx_parametros) as prm_ddd_padrao;
-- MELHOR DESEMPENHO EM PESQUISA DE MUNICIPIO PARA CELULAR
-- MELHOR DESEMPENHO EM PESQUISA DE MUNICIPIO PARA CELULAR
drop table if exists tb_municipios; create temporary table tb_municipios as select min(id) as id, codigo_ddd from pbx_municipios group by codigo_ddd;
drop table if exists tb_municipios; create temporary table tb_municipios as select min(id) as id, codigo_ddd from pbx_municipios group by codigo_ddd;
@ -167,9 +168,7 @@ select (select min(id) mun_padrao from pbx_municipios where to_ascii(nome_local
when(34)then (select min(id) from tb_municipios where codigo_ddd = ast.prefixo)
when(34)then (select min(id) from tb_municipios where codigo_ddd = ast.prefixo)
else 0 end
else 0 end
end as id_municipio
end as id_municipio
from (
from ( select *,
select *,
case prf.tipo_chamada
case prf.tipo_chamada
when(21)then strtoint(((select prm_ddd_padrao::text from tb_parametros) || substring(prf.dst,1,4)))
when(21)then strtoint(((select prm_ddd_padrao::text from tb_parametros) || substring(prf.dst,1,4)))