-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathempenhos_inss.php
executable file
·276 lines (255 loc) · 9.31 KB
/
empenhos_inss.php
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<?
/*
* E-cidade Software Publico para Gestao Municipal
* Copyright (C) 2009 DBselller Servicos de Informatica
* www.dbseller.com.br
* e-cidade@dbseller.com.br
*
* Este programa e software livre; voce pode redistribui-lo e/ou
* modifica-lo sob os termos da Licenca Publica Geral GNU, conforme
* publicada pela Free Software Foundation; tanto a versao 2 da
* Licenca como (a seu criterio) qualquer versao mais nova.
*
* Este programa e distribuido na expectativa de ser util, mas SEM
* QUALQUER GARANTIA; sem mesmo a garantia implicita de
* COMERCIALIZACAO ou de ADEQUACAO A QUALQUER PROPOSITO EM
* PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais
* detalhes.
*
* Voce deve ter recebido uma copia da Licenca Publica Geral GNU
* junto com este programa; se nao, escreva para a Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307, USA.
*
* Copia da licenca no diretorio licenca/licenca_en.txt
* licenca/licenca_pt.txt
*/
include("fpdf151/pdf.php");
include("libs/db_sql.php");
$clrotulo = new rotulocampo;
$clrotulo->label('r06_codigo');
$clrotulo->label('r06_descr');
$clrotulo->label('r06_elemen');
$clrotulo->label('r06_pd');
parse_str($HTTP_SERVER_VARS['QUERY_STRING']);
//db_postmemory($HTTP_SERVER_VARS,2);exit;
$ano = 2005;
$mes = 8;
$head3 = "EMPENHOS DO INSS";
$head5 = "PERÍODO : ".$mes." / ".$ano;
$sql = "
select
rh26_orgao,
o40_descr,
rh26_unidade,
o41_descr,
rh25_projativ,
o55_descr,
rh25_recurso,
o15_descr,
fund60,
ded60,
fund40,
ded40,
inss,
sub,
ded
from
(
select
rh26_orgao,
o41_descr,
rh26_unidade,
o40_descr,
rh25_projativ,
o55_descr,
case when rh26_orgao = 8
and rh26_unidade = 1
and rh25_recurso in (1049,1058,1004)
then 40
else rh25_recurso
end as rh25_recurso,
case when rh26_orgao = 8
and rh26_unidade = 1
and rh25_recurso in (1049,1058,1004)
then 'FMS/RECURSOS PROPRIOS'
else o15_descr
end as o15_descr,
round(sum(case when substr(r70_estrut,8,2) = '25' then inss else 0 end),2) as fund60,
round(sum(case when substr(r70_estrut,8,2) = '26' then inss else 0 end),2) as fund40,
round(sum(case when substr(r70_estrut,8,2) = '25' then ded else 0 end),2) as ded60,
round(sum(case when substr(r70_estrut,8,2) = '26' then ded else 0 end),2) as ded40,
round(sum(case when r01_padrao in ('CC07','PA57','PA58') then inss else 0 end),2) as sub,
round(sum(case when r01_padrao not in ('CC07','PA57','PA58') then inss else 0 end),2) as inss,
round(sum(case when r01_padrao not in ('CC07','PA57','PA58') then ded else 0 end),2) as ded
from
(
select r01_regist,
z01_nome,
r01_lotac,
r01_padrao,
case when r14_rubric = 'R992' then r14_valor else 0 end as inss,
case when r14_rubric = 'R919' then r14_valor else 0 end as ded
from gerfsal
inner join pessoal on r01_anousu = r14_anousu and r01_mesusu = r14_mesusu and r01_regist = r14_regist
inner join cgm on r01_numcgm = z01_numcgm
where r14_anousu = $ano
and r14_mesusu = $mes
and r14_rubric in ('R992','R919')
and r01_tbprev = 1
union
select r01_regist,
z01_nome,
r01_lotac,
r01_padrao,
case when r48_rubric = 'R992' then r48_valor else 0 end as inss,
case when r48_rubric = 'R919' then r48_valor else 0 end as ded
from gerfcom
inner join pessoal on r01_anousu = r48_anousu and r01_mesusu = r48_mesusu and r01_regist = r48_regist
inner join cgm on r01_numcgm = z01_numcgm
where r48_anousu = $ano
and r48_mesusu = $mes
and r48_rubric in ('R992','R919')
and r01_tbprev = 1
union
select r01_regist,
z01_nome,
r01_lotac,
r01_padrao,
case when r20_rubric = 'R992' then r20_valor else 0 end as inss,
case when r20_rubric = 'R919' then r20_valor else 0 end as ded
from gerfres
inner join pessoal on r01_anousu = r20_anousu and r01_mesusu = r20_mesusu and r01_regist = r20_regist
inner join cgm on r01_numcgm = z01_numcgm
where r20_anousu = $ano
and r20_mesusu = $mes
and r20_rubric in ('R992','R919')
and r01_tbprev = 1
) as x
inner join rhlota on to_number(r01_lotac,'9999') = r70_codigo
left join rhlotavinc on r70_codigo = rh25_codigo
left join rhlotaexe on r70_codigo = rh26_codigo
left join orcprojativ on o55_anousu = 2005
and o55_projativ = rh25_projativ
left join orcorgao on o40_orgao = rh26_orgao
and o40_anousu = 2005
left join orcunidade on o41_anousu = 2005
and o41_orgao = rh26_orgao
and o41_unidade = rh26_unidade
left join orctiporec on o15_codigo = rh25_recurso
group by
rh26_orgao,
o40_descr,
rh26_unidade,
o41_descr,
rh25_projativ,
rh25_recurso,
o15_descr,
o55_descr
) as xxxx
";
//echo $sql ; exit;
$result = pg_exec($sql);
//db_criatabela($result);
$xxnum = pg_numrows($result);
if ($xxnum == 0){
db_redireciona('db_erros.php?fechar=true&db_erro=Não existem Códigos cadastrados no período de '.$mes.' / '.$ano);
}
$pdf = new PDF();
$pdf->Open();
$pdf->AliasNbPages();
$total = 0;
$pdf->setfillcolor(235);
$pdf->setfont('arial','b',8);
$troca = 1;
$alt = 4;
$orgao = '';
$unidade = '';
$pdf->addpage();
$val_fgts = 0;
$val_fgts_seg = 0;
$val_fgts_pad = 0;
$val_ded = 0;
$val_pat = 0;
$pat60 = 0;
$pat40 = 0;
$pat = 0;
for($x = 0; $x < pg_numrows($result);$x++){
db_fieldsmemory($result,$x);
/*
if ($pdf->gety() > $pdf->h - 30 || $troca != 0 ){
$pdf->addpage();
$pdf->setfont('arial','b',8);
$pdf->cell(15,$alt,'CÓDIGO',1,0,"C",1);
$pdf->cell(25,$alt,'ESTRUTURAL',1,0,"C",1);
$pdf->cell(80,$alt,'DESCRIÇÃO',1,0,"C",1);
$pdf->cell(20,$alt,'REDUZ',1,1,"C",1);
$total = 0;
$troca = 0;
}
*/
$pdf->setfont('arial','B',8);
if($orgao != $rh26_orgao){
$pdf->cell(15,$alt,db_formatar($rh26_orgao,'orgao'),0,0,"C",1);
$pdf->cell(0,$alt,$o40_descr,0,1,"L",1);
$orgao = $rh26_orgao;
}
if($unidade != $rh26_orgao.$rh26_unidade){
$pdf->cell(5,$alt,'',0,0,"C",1);
$pdf->cell(15,$alt,db_formatar($rh26_orgao,'orgao').db_formatar($rh26_unidade,'orgao'),0,0,"C",1);
$pdf->cell(0,$alt,$o41_descr,0,1,"L",1);
$unidade = $rh26_orgao.$rh26_unidade;
}
if($proj != $rh25_projativ){
$pdf->cell(5,$alt,'',0,0,"C",1);
$pdf->cell(15,$alt,$rh25_projativ,0,0,"C",1);
$pdf->cell(0,$alt,$o55_descr,0,1,"L",1);
$proj= $rh25_projativ;
}
$pdf->setfont('arial','',7);
if($sub != 0){
$pat1 = $sub / 100 * 21;
$pdf->cell(10,$alt,'',0,0,"C",0);
$pdf->cell(15,$alt,$rh25_recurso,0,0,"C",0);
$pdf->cell(80,$alt,$o15_descr.' (SUBSÍDIO) ',0,0,"L",0);
$pdf->cell(20,$alt,db_formatar($sub,'f'),0,0,"R",0);
$pdf->cell(20,$alt,db_formatar($pat1,'f'),0,0,"R",0);
$pdf->cell(20,$alt,db_formatar(0,'f'),0,0,"R",0);
$pdf->cell(20,$alt,db_formatar(($pat1),'f'),0,1,"R",0);
}
$pat = $inss / 100 * 21;
$pdf->cell(10,$alt,'',0,0,"C",0);
$pdf->cell(15,$alt,$rh25_recurso,0,0,"C",0);
$pdf->cell(80,$alt,$o15_descr,0,0,"L",0);
$pdf->cell(20,$alt,db_formatar($inss,'f'),0,0,"R",0);
$pdf->cell(20,$alt,db_formatar($pat,'f'),0,0,"R",0);
$pdf->cell(20,$alt,db_formatar($ded,'f'),0,0,"R",0);
$pdf->cell(20,$alt,db_formatar(($pat - $ded),'f'),0,1,"R",0);
if($rh25_recurso == 30){
$pdf->cell(25,$alt,'',0,0,"C",0);
$pat60 = $fund60 /100 * 21;
$pdf->cell(80,$alt,'FUNDEF 60%',0,0,"L",0);
$pdf->cell(20,$alt,db_formatar($fund60,'f'),0,0,"R",0);
$pdf->cell(20,$alt,db_formatar($pat60,'f'),0,0,"R",0);
$pdf->cell(20,$alt,db_formatar($ded60,'f'),0,0,"R",0);
$pdf->cell(20,$alt,db_formatar(($pat60 - $ded60),'f'),0,1,"R",0);
$pdf->cell(25,$alt,'',0,0,"C",0);
$pat40 = $fund40 / 100 * 21;
$pdf->cell(80,$alt,'FUNDEF 40%',0,0,"L",0);
$pdf->cell(20,$alt,db_formatar($fund40,'f'),0,0,"R",0);
$pdf->cell(20,$alt,db_formatar($pat40,'f'),0,0,"R",0);
$pdf->cell(20,$alt,db_formatar($ded40,'f'),0,0,"R",0);
$pdf->cell(20,$alt,db_formatar(($pat40 - $ded40),'f'),0,1,"R",0);
}
$val_pat += (($inss+$sub)/100)*21;
$val_fgts += $inss+$sub;
$val_ded += $ded;
}
$pdf->setfont('arial','B',8);
$pdf->cell(105,$alt,'TOTAL ',0,0,"C",0);
$pdf->cell(20,$alt,db_formatar($val_fgts,'f'),0,0,"R",0);
$pdf->cell(20,$alt,db_formatar($val_pat,'f'),0,0,"R",0);
$pdf->cell(20,$alt,db_formatar($val_ded,'f'),0,0,"R",0);
$pdf->cell(20,$alt,db_formatar($val_pat - $val_ded,'f'),0,1,"R",0);
$pdf->Output();
?>