From b7cc847692e950c4ed06cb3703c82822111d0625 Mon Sep 17 00:00:00 2001 From: bruno Date: Thu, 10 Aug 2023 11:24:27 -0400 Subject: [PATCH] inserir coluna pa_fixo na tabela pbx_usuarios --- projeto/base/schema/createSchema.sql | 145 ++++++++++++++------------- 1 file changed, 73 insertions(+), 72 deletions(-) diff --git a/projeto/base/schema/createSchema.sql b/projeto/base/schema/createSchema.sql index f35720a6..d0b4d6e1 100644 --- a/projeto/base/schema/createSchema.sql +++ b/projeto/base/schema/createSchema.sql @@ -30,30 +30,30 @@ SET search_path = public, pg_catalog; CREATE FUNCTION areacornubada(fone character varying, mun_origem character varying DEFAULT ''::character varying, uf_origem character DEFAULT ''::bpchar) RETURNS character varying LANGUAGE plpgsql - AS $$ - DECLARE prefix char(6); - DECLARE sufixo char(4); - DECLARE uf_numero char(2); - DECLARE mun_numero character varying(50); - DECLARE result integer; - BEGIN - if(length(fone) < 10)then return fone; end if; - if(mun_origem = '')then mun_numero = (select min(prm_mun_padrao) from pbx_parametros); else mun_numero = mun_origem; end if; - if(uf_origem = '')then uf_numero = coalesce((select min(prm_uf_padrao) from pbx_parametros), 'MT'); else uf_numero = uf_origem; end if; - prefix = substring(fone, 1, 6); - sufixo = substring(fone, 7, 4); - - result = ( - select count(*) - from pbx_municipios - where sigla_area_local = coalesce( (select min(sigla_area_local) from pbx_municipios where to_ascii( nome_municipio, 'LATIN1') = to_ascii(upper(mun_numero), 'LATIN1') and uf = upper(uf_numero))::text, '') - and uf = uf_numero - and "prefixo" = prefix::int - and faixa_inicial <= sufixo::int - and faixa_final >= sufixo::int)::int; - - if(result > 0)then return substring(fone,3,8); else return fone; end if; - END; + AS $$ + DECLARE prefix char(6); + DECLARE sufixo char(4); + DECLARE uf_numero char(2); + DECLARE mun_numero character varying(50); + DECLARE result integer; + BEGIN + if(length(fone) < 10)then return fone; end if; + if(mun_origem = '')then mun_numero = (select min(prm_mun_padrao) from pbx_parametros); else mun_numero = mun_origem; end if; + if(uf_origem = '')then uf_numero = coalesce((select min(prm_uf_padrao) from pbx_parametros), 'MT'); else uf_numero = uf_origem; end if; + prefix = substring(fone, 1, 6); + sufixo = substring(fone, 7, 4); + + result = ( + select count(*) + from pbx_municipios + where sigla_area_local = coalesce( (select min(sigla_area_local) from pbx_municipios where to_ascii( nome_municipio, 'LATIN1') = to_ascii(upper(mun_numero), 'LATIN1') and uf = upper(uf_numero))::text, '') + and uf = uf_numero + and "prefixo" = prefix::int + and faixa_inicial <= sufixo::int + and faixa_final >= sufixo::int)::int; + + if(result > 0)then return substring(fone,3,8); else return fone; end if; + END; $$; @@ -65,10 +65,10 @@ ALTER FUNCTION public.areacornubada(fone character varying, mun_origem character CREATE FUNCTION dias_nummes(integer, integer) RETURNS integer LANGUAGE sql - AS $_$ -select - extract(day from (date (trim(to_char($2, '0000'))||'-'||trim(to_char($1, -'00'))||'-01') + interval '1 month') - interval '1 day')::integer; + AS $_$ +select + extract(day from (date (trim(to_char($2, '0000'))||'-'||trim(to_char($1, +'00'))||'-01') + interval '1 month') - interval '1 day')::integer; $_$; @@ -377,24 +377,24 @@ ALTER FUNCTION public.formata_segundos(double precision) OWNER TO contacte; CREATE FUNCTION get_descricao_chamada(cod integer) RETURNS character varying LANGUAGE plpgsql - AS $$ -BEGIN - - if(cod = 1)then return 'Interna'; - elseif(cod = 4)then return 'Emergência'; - elseif(cod = 5)then return 'Gratuita'; - elseif(cod = 21)then return 'Local Fixo'; - elseif(cod = 22)then return 'Interurbano Fixo'; - elseif(cod = 23)then return 'Local Móvel'; - elseif(cod = 24)then return 'Interurbano Móvel'; - elseif(cod = 25)then return 'Internacional'; - elseif(cod = 31)then return 'Local Fixo'; - elseif(cod = 32)then return 'Interurbano Fixo'; - elseif(cod = 33)then return 'Local Móvel'; - elseif(cod = 34)then return 'Interurbano Móvel'; - elseif(cod = 35)then return 'Internacional'; - else return 'NI'; end if; -END; + AS $$ +BEGIN + + if(cod = 1)then return 'Interna'; + elseif(cod = 4)then return 'Emergência'; + elseif(cod = 5)then return 'Gratuita'; + elseif(cod = 21)then return 'Local Fixo'; + elseif(cod = 22)then return 'Interurbano Fixo'; + elseif(cod = 23)then return 'Local Móvel'; + elseif(cod = 24)then return 'Interurbano Móvel'; + elseif(cod = 25)then return 'Internacional'; + elseif(cod = 31)then return 'Local Fixo'; + elseif(cod = 32)then return 'Interurbano Fixo'; + elseif(cod = 33)then return 'Local Móvel'; + elseif(cod = 34)then return 'Interurbano Móvel'; + elseif(cod = 35)then return 'Internacional'; + else return 'NI'; end if; +END; $$; @@ -641,11 +641,11 @@ ALTER FUNCTION public.laststr(substr character, str character varying) OWNER TO CREATE FUNCTION remove_acentos(p_texto text) RETURNS text LANGUAGE sql - AS $_$ - Select translate($1, - 'áàâãäåaaaÁÂÃÄÅAAAÀéèêëeeeeeEEEÉEEÈìíîïìiiiÌÍÎÏÌIIIóôõöoooòÒÓÔÕÖOOOùúûüuuuuÙÚÛÜUUUUçÇñÑýÝ', - 'aaaaaaaaaAAAAAAAAAeeeeeeeeeEEEEEEEiiiiiiiiIIIIIIIIooooooooOOOOOOOOuuuuuuuuUUUUUUUUcCnNyY' - ); + AS $_$ + Select translate($1, + 'áàâãäåaaaÁÂÃÄÅAAAÀéèêëeeeeeEEEÉEEÈìíîïìiiiÌÍÎÏÌIIIóôõöoooòÒÓÔÕÖOOOùúûüuuuuÙÚÛÜUUUUçÇñÑýÝ', + 'aaaaaaaaaAAAAAAAAAeeeeeeeeeEEEEEEEiiiiiiiiIIIIIIIIooooooooOOOOOOOOuuuuuuuuUUUUUUUUcCnNyY' + ); $_$; @@ -698,21 +698,21 @@ ALTER FUNCTION public.retornaopcao(str character varying) OWNER TO contacte; CREATE FUNCTION reversestr(str character varying) RETURNS character varying LANGUAGE plpgsql - AS $$ -declare -rev text; -tam integer; -BEGIN - tam := length(str); - rev := ''; - WHILE (tam > 0) LOOP - rev := rev || substring(str,tam,1); - tam := tam - 1; - END LOOP; - - return rev; - -END; + AS $$ +declare +rev text; +tam integer; +BEGIN + tam := length(str); + rev := ''; + WHILE (tam > 0) LOOP + rev := rev || substring(str,tam,1); + tam := tam - 1; + END LOOP; + + return rev; + +END; $$; @@ -754,11 +754,11 @@ ALTER FUNCTION public.sonumero(str character varying) OWNER TO contacte; CREATE FUNCTION strtoint(txt character varying, def integer DEFAULT 0) RETURNS bigint LANGUAGE plpgsql - AS $_$ -BEGIN - - return case when((coalesce(txt, '') ~ E'^(\\-|\\+)?\\d+$')) then txt::bigint else def::bigint end; -END; + AS $_$ +BEGIN + + return case when((coalesce(txt, '') ~ E'^(\\-|\\+)?\\d+$')) then txt::bigint else def::bigint end; +END; $_$; @@ -1503,7 +1503,8 @@ CREATE TABLE pbx_usuarios ( termo_uso_privacidade integer DEFAULT 0 NOT NULL, termo_uso_privacidade_log character varying(1024), termo_uso_log character varying(255), - user_system integer DEFAULT 0 NOT NULL + user_system integer DEFAULT 0 NOT NULL, + pa_fixo interger DEFAULT 0 );