@ -148,8 +148,9 @@ function ImportaAstEventosDacs($dbcon) {
function ImportaAstBilhetes($dbcon) {
global $numBilhetes;
$query = "drop table if exists tb_parametros;
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;
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;
-- 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;
@ -166,10 +167,8 @@ select (select min(id) mun_padrao from pbx_municipios where to_ascii(nome_local
when(33)then (select mun_padrao from tb_parametros)
when(34)then (select min(id) from tb_municipios where codigo_ddd = ast.prefixo)
else 0 end
end as id_municipio
from (
select *,
end as id_municipio
from ( select *,
case prf.tipo_chamada
when(21)then strtoint(((select prm_ddd_padrao::text from tb_parametros) || substring(prf.dst,1,4)))
@ -183,10 +182,10 @@ select (select min(id) mun_padrao from pbx_municipios where to_ascii(nome_local
0
end as prefixo,
strtoint(substring(prf.dst,'....$')) as sufixo, case when(exists(select '' from ast_eventos_dacs where uid2 = prf.uniqueid))then 'S' else 'N' end as flag_fila
from (
from (
select id_bilhetes, direcao,
case direcao
when('E')then sonumero(src)
when('E')then sonumero(src)
when('S')then sonumero(dst)
else
'-'
@ -195,24 +194,23 @@ select (select min(id) mun_padrao from pbx_municipios where to_ascii(nome_local