bimestre.plsql
4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
**********************************************************************************
* *
* @package URBEM CNM - Soluções em Gestão Pública *
* @copyright (c) 2013 Confederação Nacional de Municípos *
* @author Confederação Nacional de Municípios *
* *
* O URBEM CNM é um software livre; você pode redistribuí-lo e/ou modificá-lo sob *
* os termos da Licença Pública Geral GNU conforme publicada pela Fundação do *
* Software Livre (FSF - Free Software Foundation); na versão 2 da Licença. *
* *
* Este programa é distribuído na expectativa de que seja útil, porém, *
* SEM NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU *
* ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral do GNU *
* para mais detalhes. *
* *
* Você deve ter recebido uma cópia da Licença Pública Geral do GNU "LICENCA.txt" *
* com este programa; se não, escreva para a Free Software Foundation Inc., *
* no endereço 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
* *
**********************************************************************************
*/
/*
* Script de função PLPGSQL
*
* URBEM Soluções de Gestão Pública Ltda
* www.urbem.cnm.org.br
*
* $Revision: 26695 $
* $Name$
* $Author: domluc $
* $Date: 2007-11-09 12:07:22 -0200 (Sex, 09 Nov 2007) $
*
* Casos de uso: uc-01.01.00
*/
/*
$Log$
Revision 1.2 2007/01/22 12:22:17 gris
-- Inclusão tag framework.
Revision 1.1 2006/08/09 18:12:26 rodrigo
*** empty log message ***
*/
CREATE OR REPLACE FUNCTION deleta_bimestre() RETURNS VOID AS $$
DECLARE
stsql varchar;
varAchouArr VARCHAR;
BEGIN
SELECT proname
INTO varAchouArr
from pg_proc
where proname ilike 'bimestre';
IF FOUND THEN
begin
DROP FUNCTION publico.bimestre(integer,integer);
exception
when others then
end;
begin
DROP FUNCTION publico.bimestre(varchar,integer);
exception
when others then
end;
END IF;
END
$$
language 'plpgsql';
SELECT deleta_bimestre();
DROP FUNCTION deleta_bimestre();
CREATE OR REPLACE FUNCTION publico.bimestre(integer,integer) RETURNS VARCHAR[] AS $$
DECLARE
inExercicioPar ALIAS FOR $1;
inBimestrePar ALIAS FOR $2;
inExercicio INTEGER;
inBimestre INTEGER;
stDataInicial VARCHAR := '''';
stDataFinal VARCHAR := '''';
arDatas VARCHAR[];
reRegistro RECORD;
BEGIN
IF length(inExercicioPar::VARCHAR)=4 THEN
inExercicio := inExercicioPar;
inBimestre := inBimestrePar;
ELSE
inExercicio := inBimestrePar;
inBimestre := inExercicioPar;
END IF;
IF inBimestre = 1 THEN
arDatas[0] := '01/01/'||inExercicio;
arDatas[1] := to_char((to_date('01/03/'||inExercicio,'dd/mm/yyyy')-1),'dd/mm/yyyy');
ELSIF inBimestre = 2 THEN
arDatas[0] := '01/03/'||inExercicio;
arDatas[1] := '30/04/'||inExercicio;
ELSIF inBimestre = 3 THEN
arDatas[0] := '01/05/'||inExercicio;
arDatas[1] := '30/06/'||inExercicio;
ELSIF inBimestre = 4 THEN
arDatas[0] := '01/07/'||inExercicio;
arDatas[1] := '31/08/'||inExercicio;
ELSIF inBimestre = 5 THEN
arDatas[0] := '01/09/'||inExercicio;
arDatas[1] := '31/10/'||inExercicio;
ELSIF inBimestre = 6 THEN
arDatas[0] := '01/11/'||inExercicio;
arDatas[1] := '31/12/'||inExercicio;
END IF;
RETURN arDatas;
END;
$$ language plpgsql;
CREATE OR REPLACE FUNCTION publico.bimestre(varchar,integer) RETURNS VARCHAR[] AS $$
DECLARE
inExercicioPar ALIAS FOR $1;
inBimestrePar ALIAS FOR $2;
BEGIN
RETURN publico.bimestre( CAST(inExercicioPar as INTEGER), inBimestrePar );
END;
$$ language plpgsql;