Commit aeec990ff1c40064657af9d74f411d9d491da6e9

Authored by Eriksen Costa
1 parent 7a5c388b
Exists in master

Refactoring para coding standards

ieducar/intranet/include/pessoa/clsPessoaFisica.inc.php
1 1 <?php
2   -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3   -* *
4   -* @author Prefeitura Municipal de Itajaí *
5   -* @updated 29/03/2007 *
6   -* Pacote: i-PLB Software Público Livre e Brasileiro *
7   -* *
8   -* Copyright (C) 2006 PMI - Prefeitura Municipal de Itajaí *
9   -* ctima@itajai.sc.gov.br *
10   -* *
11   -* Este programa é software livre, você pode redistribuí-lo e/ou *
12   -* modificá-lo sob os termos da Licença Pública Geral GNU, conforme *
13   -* publicada pela Free Software Foundation, tanto a versão 2 da *
14   -* Licença como (a seu critério) qualquer versão mais nova. *
15   -* *
16   -* Este programa é distribuído na expectativa de ser útil, mas SEM *
17   -* QUALQUER GARANTIA. Sem mesmo a garantia implícita de COMERCIALI- *
18   -* ZAÇÃO ou de ADEQUAÇÃO A QUALQUER PROPÓSITO EM PARTICULAR. Con- *
19   -* sulte a Licença Pública Geral GNU para obter mais detalhes. *
20   -* *
21   -* Você deve ter recebido uma cópia da Licença Pública Geral GNU *
22   -* junto com este programa. Se não, escreva para a Free Software *
23   -* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA *
24   -* 02111-1307, USA. *
25   -* *
26   -* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
27   -require_once ("include/clsBanco.inc.php");
28   -require_once ("include/Geral.inc.php");
29 2  
  3 +/**
  4 + * i-Educar - Sistema de gestão escolar
  5 + *
  6 + * Copyright (C) 2006 Prefeitura Municipal de Itajaí
  7 + * <ctima@itajai.sc.gov.br>
  8 + *
  9 + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo
  10 + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free
  11 + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério)
  12 + * qualquer versão posterior.
  13 + *
  14 + * Este programa é distribuí­do na expectativa de que seja útil, porém, SEM
  15 + * NENHUMA GARANTIA; nem mesmo a garantia implí­cita de COMERCIABILIDADE OU
  16 + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral
  17 + * do GNU para mais detalhes.
  18 + *
  19 + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto
  20 + * com este programa; se não, escreva para a Free Software Foundation, Inc., no
  21 + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
  22 + *
  23 + * @author Prefeitura Municipal de Itajaí <ctima@itajai.sc.gov.br>
  24 + * @category i-Educar
  25 + * @license @@license@@
  26 + * @package iEd_Cadastro
  27 + * @since Arquivo disponível desde a versão 1.0.0
  28 + * @version $Id$
  29 + */
  30 +
  31 +require_once 'include/clsBanco.inc.php';
  32 +require_once 'include/Geral.inc.php';
  33 +
  34 +/**
  35 + * clsPessoaFisica class.
  36 + *
  37 + * @author Prefeitura Municipal de Itajaí <ctima@itajai.sc.gov.br>
  38 + * @category i-Educar
  39 + * @license @@license@@
  40 + * @package iEd_Cadastro
  41 + * @since Classe disponível desde a versão 1.0.0
  42 + * @version @@package_version@@
  43 + */
30 44 class clsPessoaFisica extends clsPessoaFj
31 45 {
32   - var $idpes;
33   - var $data_nasc;
34   - var $sexo;
35   - var $idpes_mae;
36   - var $idpes_pai;
37   - var $idpes_responsavel;
38   - var $idesco;
39   - var $ideciv;
40   - var $idpes_con;
41   - var $data_uniao;
42   - var $data_obito;
43   - var $nacionalidade;
44   - var $idpais_estrangeiro;
45   - var $data_chagada_brasil;
46   - var $idmun_nascimento;
47   - var $ultima_empresa;
48   - var $idocup;
49   - var $nome_mae;
50   - var $nome_pai;
51   - var $nome_conjuge;
52   - var $nome_responsavel;
53   - var $justificativa_provisorio;
54   - var $cpf;
55   - var $ref_cod_religiao;
56   - var $tipo_endereco;
57   -
58   - var $banco = 'pmi';
59   - var $schema_cadastro = "cadastro";
60   -
61   - function clsPessoaFisica($int_idpes = false, $numeric_cpf = false, $date_data_nasc = false, $str_sexo = false, $int_idpes_mae =false, $int_idpes_pai = false)
62   - {
63   - $this->idpes = $int_idpes;
64   - $this->cpf = $numeric_cpf;
65   - }
66   -
67   -
68   - function lista_simples($str_nome =false, $numeric_cpf =false, $inicio_limite=false, $qtd_registros = false, $str_orderBy = false, $int_ref_cod_sistema = false)
69   - {
70   - $whereAnd = "";
71   - $where = "";
72   - if( is_string( $str_nome ) && $str_nome != '' )
73   - {
74   - $str_nome = str_replace(" ", "%", $str_nome);
75   - $where .= "{$whereAnd} nome ILIKE '%{$str_nome}%' ";
76   - $whereAnd = " AND ";
77   - }
78   -
79   - if( is_string( $numeric_cpf ) )
80   - {
81   - $where .= "{$whereAnd} cpf ILIKE '%{$numeric_cpf}%' ";
82   - }
83   -
84   - if( is_numeric( $int_ref_cod_sistema ) )
85   - {
86   - $where .= "{$whereAnd} (ref_cod_sistema = '{$int_ref_cod_sistema}' OR cpf is not null )";
87   - }
88   -
89   -
90   - if( $inicio_limite !== false && $qtd_registros )
91   - {
92   - $limite = "LIMIT $qtd_registros OFFSET $inicio_limite ";
93   - }
94   -
95   -
96   - $orderBy = " ORDER BY ";
97   - if( $str_orderBy )
98   - {
99   - $orderBy .= "$str_orderBy ";
100   - }
101   - else
102   - {
103   - $orderBy .= "nome ";
104   - }
105   - if($where)
106   - {
107   - $where = "WHERE ".$where;
108   - }
109   - $db = new clsBanco($this->banco);
110   -
111   - $total = $db->UnicoCampo("Select count(0) FROM cadastro.fisica $where");
112   -
113   - $db->Consulta("Select idpes, nome, cpf FROM cadastro.v_pessoa_fisica $where $orderBy $limite");
114   - $resultado = array();
115   - while ($db->ProximoRegistro())
116   - {
117   - $tupla = $db->Tupla();
118   - $tupla['nome'] = transforma_minusculo($tupla['nome']);
119   - $tupla['total']= $total;
120   - $resultado[] = $tupla;
121   - }
122   - if(count($resultado) > 0)
123   - {
124   - return $resultado;
125   - }
126   - return false;
127   - }
128   -
129   -
130   - function lista($str_nome =false, $numeric_cpf =false, $inicio_limite=false, $qtd_registros = false, $str_orderBy = false, $int_ref_cod_sistema = false, $int_idpes = false)
131   - {
132   - $whereAnd = "";
133   - $where = "";
134   - if( is_string( $str_nome ) && $str_nome != '' )
135   - {
136   - $str_nome = str_replace(" ", "%", $str_nome);
137   - $where .= "{$whereAnd} nome ILIKE '%{$str_nome}%' ";
138   - $whereAnd = " AND ";
139   - }
140   -
141   - if( is_string( $numeric_cpf ) )
142   - {
143   - $where .= "{$whereAnd} cpf ILIKE '%{$numeric_cpf}%' ";
144   - $whereAnd = " AND ";
145   - }
146   - if( is_numeric( $int_ref_cod_sistema ) )
147   - {
148   - $where .= "{$whereAnd} (ref_cod_sistema = '{$int_ref_cod_sistema}' OR cpf is not null )";
149   - $whereAnd = " AND ";
150   - }
151   - if( is_numeric( $int_idpes ) )
152   - {
153   - $where .= "{$whereAnd} idpes = '$int_idpes'";
154   - $whereAnd = " AND ";
155   - }
156   -
157   - if(is_numeric($this->tipo_endereco))
158   - {
159   - if($this->tipo_endereco == 1)
160   - {
161   - //interno
162   - $where .= "{$whereAnd} idpes IN (SELECT idpes FROM cadastro.endereco_pessoa)";
163   - $whereAnd = " AND ";
164   - }
165   - elseif ($this->tipo_endereco == 2)
166   - {
167   - //externo
168   - $where .= "{$whereAnd} idpes IN (SELECT idpes FROM cadastro.endereco_externo)";
169   - $whereAnd = " AND ";
170   - }
171   - }
172   -
173   -
174   - if( $inicio_limite !== false && $qtd_registros )
175   - {
176   - $limite = "LIMIT $qtd_registros OFFSET $inicio_limite ";
177   - }
178   -
179   -
180   - $orderBy = " ORDER BY ";
181   - if( $str_orderBy )
182   - {
183   - $orderBy .= "$str_orderBy ";
184   - }
185   - else
186   - {
187   - $orderBy .= "nome ";
188   - }
189   -
190   -
191   - $db = new clsBanco();
192   - $dba = new clsBanco();
193   -
194   -
195   - if($where)
196   - {
197   - $where = "WHERE ".$where;
198   - }
199   - if(!$where)
200   - {
201   - $total = $db->CampoUnico("Select count(0) FROM cadastro.fisica $where");
202   - }else
203   - {
204   - $total = $db->CampoUnico("Select count(0) FROM cadastro.v_pessoa_fisica $where");
205   - }
206   -
207   -
208   - $db->Consulta("Select idpes, nome, url,'F' as tipo, email, cpf FROM cadastro.v_pessoa_fisica $where $orderBy $limite");
209   -
210   - $resultado = array();
211   - while ($db->ProximoRegistro())
212   - {
213   - $tupla = $db->Tupla();
214   - $tupla['nome'] = transforma_minusculo($tupla['nome']);
215   - $tupla['total']= $total;
216   -
217   - $dba->Consulta("Select ddd_1, fone_1, ddd_2, fone_2, ddd_mov, fone_mov, ddd_fax, fone_fax from cadastro.v_fone_pessoa where idpes ={$tupla['idpes']}");
218   - if($dba->ProximoRegistro())
219   - {
220   - $tupla_fone = $dba->Tupla();
221   - }else
222   - {
223   - $tupla_fone = "";
224   - }
225   -
226   - $tupla['ddd_1'] = $tupla_fone['ddd_1'];
227   - $tupla['fone_1'] = $tupla_fone['fone_1'];
228   - $tupla['ddd_2'] = $tupla_fone['ddd_2'];
229   - $tupla['fone_2'] = $tupla_fone['fone_2'];
230   - $tupla['ddd_mov'] = $tupla_fone['ddd_mov'];
231   - $tupla['fone_mov'] = $tupla_fone['fone_mov'];
232   - $tupla['ddd_fax'] = $tupla_fone['ddd_fax'];
233   - $tupla['fone_fax'] = $tupla_fone['fone_fax'];
234   -
235   - $resultado[] = $tupla;
236   -
237   - }
238   - if(count($resultado) > 0)
239   - {
240   - return $resultado;
241   - }
242   - return false;
243   - }
244   -
245   - function detalhe()
246   - {
247   - if($this->idpes)
248   - {
249   - $tupla = parent::detalhe();
250   -
251   - $objFisica = new clsFisica($this->idpes);
252   - $detalhe_fisica = $objFisica->detalhe();
253   - if($detalhe_fisica)
254   - {
255   - $this->data_nasc = $detalhe_fisica['data_nasc'];
256   - $this->sexo = $detalhe_fisica['sexo'];
257   - $this->idpes_mae = $detalhe_fisica['idpes_mae'];
258   - $this->idpes_pai = $detalhe_fisica['idpes_pai'];
259   - $this->idpes_responsavel = $detalhe_fisica['idpes_responsavel'];
260   - $this->idesco = $detalhe_fisica['idesco'];
261   - $this->ideciv = $detalhe_fisica['ideciv'];
262   - $this->idpes_con = $detalhe_fisica['idpes_con'];
263   - $this->data_uniao = $detalhe_fisica['data_uniao'];
264   - $this->data_obito = $detalhe_fisica['data_obito'];
265   - $this->nacionalidade = $detalhe_fisica['nacionalidade'];
266   - $this->idpais_estrangeiro = $detalhe_fisica['idpais_estrangeiro'];
267   - $this->data_chagada_brasil = $detalhe_fisica['data_chagada_brasil'];
268   - $this->idmun_nascimento = $detalhe_fisica['idmun_nascimento'];
269   - $this->ultima_empresa = $detalhe_fisica['ultima_empresa'];
270   - $this->idocup = $detalhe_fisica['idocup'];
271   - $this->nome_mae = $detalhe_fisica['nome_mae'];
272   - $this->nome_pai = $detalhe_fisica['nome_pai'];
273   - $this->nome_conjuge = $detalhe_fisica['nome_conjuge'];
274   - $this->nome_responsavel = $detalhe_fisica['nome_responsavel'];
275   - $this->justificativa_provisorio = $detalhe_fisica['justificativa_provisorio'];
276   - $this->cpf = $detalhe_fisica['cpf'];
277   - $this->ref_cod_religiao = $detalhe_fisica['ref_cod_religiao'];
278   -
279   - $tupla['idpes' ]= $this->idpes;
280   - $tupla[] = &$tupla['idpes' ];
281   - $tupla['cpf' ]= $this->cpf;
282   - $tupla[] = &$tupla['cpf'];
283   - $tupla['ref_cod_religiao' ]= $this->ref_cod_religiao;
284   - $tupla[] = &$tupla['ref_cod_religiao'];
285   - $tupla['data_nasc'] = $this->data_nasc;
286   - $tupla[] = &$tupla['data_nasc'];
287   - $tupla['sexo'] = $this->sexo;
288   - $tupla[] = &$tupla['sexo'];
289   - $tupla['idpes_mae'] = $this->idpes_mae;
290   - $tupla[] = &$tupla['idpes_mae'];
291   - $tupla['idpes_pai'] = $this->idpes_pai;
292   - $tupla[] = &$tupla['idpes_pai'];
293   - $tupla['idpes_responsavel'] = $this->idpes_responsavel;
294   - $tupla[] = &$tupla['idpes_responsavel'];
295   - $tupla['idesco'] = $this->idesco;
296   - $tupla[] = &$tupla['idesco'];
297   - $tupla['ideciv'] = $this->ideciv;
298   - $tupla[] = &$tupla['ideciv'];
299   - $tupla['idpes_con'] = $this->idpes_con;
300   - $tupla[] = &$tupla['idpes_con'];
301   - $tupla['data_uniao'] = $this->data_uniao;
302   - $tupla[] = &$tupla['data_uniao'];
303   - $tupla['data_obito'] = $this->data_obito;
304   - $tupla[] = &$tupla['data_obito'];
305   - $tupla['nacionalidade'] = $this->nacionalidade;
306   - $tupla[] = &$tupla['nacionalidade'];
307   - $tupla['idpais_estrangeiro'] = $this->idpais_estrangeiro;
308   - $tupla[] = &$tupla['idpais_estrangeiro'];
309   - $tupla['data_chagada_brasil'] = $this->data_chagada_brasil;
310   - $tupla[] = &$tupla['data_chagada_brasil'];
311   - $tupla['idmun_nascimento'] = $this->idmun_nascimento;
312   - $tupla[] = &$tupla['idmun_nascimento'];
313   - $tupla['ultima_empresa'] = $this->ultima_empresa;
314   - $tupla[] = &$tupla['ultima_empresa'];
315   - $tupla['idocup'] = $this->idocup;
316   - $tupla[] = &$tupla['idocup'];
317   - $tupla['nome_mae'] = $this->nome_mae;
318   - $tupla[] = &$tupla['nome_mae'];
319   - $tupla['nome_pai'] = $this->nome_pai;
320   - $tupla[] = &$tupla['nome_pai'];
321   - $tupla['nome_conjuge'] = $this->nome_conjuge;
322   - $tupla[] = &$tupla['nome_conjuge'];
323   - $tupla['nome_responsavel'] = $this->nome_responsavel;
324   - $tupla[] = &$tupla['nome_responsavel'];
325   - $tupla['justificativa_provisorio'] = $this->justificativa_provisorio;
326   - $tupla[] = &$tupla['justificativa_provisorio'];
327   -
328   - return $tupla;
329   - }
330   - }
331   - elseif ( $this->cpf )
332   - {
333   -
334   -
335   - $tupla = parent::detalhe();
336   -
337   - $objFisica = new clsFisica();
338   - $lista = $objFisica->lista(false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,$this->cpf);
339   - $this->idpes = $lista[0]['idpes'];
340   -
341   - if( $this->idpes)
342   - {
343   - $objFisica = new clsFisica($this->idpes);
344   - $detalhe_fisica = $objFisica->detalhe();
345   - if($detalhe_fisica)
346   - {
347   - $this->data_nasc = $detalhe_fisica['data_nasc'];
348   - $this->sexo = $detalhe_fisica['sexo'];
349   - $this->idpes_mae = $detalhe_fisica['idpes_mae'];
350   - $this->idpes_pai = $detalhe_fisica['idpes_pai'];
351   - $this->idpes_responsavel = $detalhe_fisica['idpes_responsavel'];
352   - $this->idesco = $detalhe_fisica['idesco'];
353   - $this->ideciv = $detalhe_fisica['ideciv'];
354   - $this->idpes_con = $detalhe_fisica['idpes_con'];
355   - $this->data_uniao = $detalhe_fisica['data_uniao'];
356   - $this->data_obito = $detalhe_fisica['data_obito'];
357   - $this->nacionalidade = $detalhe_fisica['nacionalidade'];
358   - $this->idpais_estrangeiro = $detalhe_fisica['idpais_estrangeiro'];
359   - $this->data_chagada_brasil = $detalhe_fisica['data_chagada_brasil'];
360   - $this->idmun_nascimento = $detalhe_fisica['idmun_nascimento'];
361   - $this->ultima_empresa = $detalhe_fisica['ultima_empresa'];
362   - $this->idocup = $detalhe_fisica['idocup'];
363   - $this->nome_mae = $detalhe_fisica['nome_mae'];
364   - $this->nome_pai = $detalhe_fisica['nome_pai'];
365   - $this->nome_conjuge = $detalhe_fisica['nome_conjuge'];
366   - $this->nome_responsavel = $detalhe_fisica['nome_responsavel'];
367   - $this->justificativa_provisorio = $detalhe_fisica['justificativa_provisorio'];
368   - $this->cpf = $detalhe_fisica['cpf'];
369   -
370   - $tupla['idpes' ]= $this->idpes;
371   - $tupla[] = &$tupla['idpes' ];
372   - $tupla['cpf' ]= $this->cpf;
373   - $tupla[] = &$tupla['cpf' ];
374   - $tupla['data_nasc'] = $this->data_nasc;
375   - $tupla[] = &$tupla['data_nasc'];
376   - $tupla['sexo'] = $this->sexo;
377   - $tupla[] = &$tupla['sexo'];
378   - $tupla['idpes_mae'] = $this->idpes_mae;
379   - $tupla[] = &$tupla['idpes_mae'];
380   - $tupla['idpes_pai'] = $this->idpes_pai;
381   - $tupla[] = &$tupla['idpes_pai'];
382   - $tupla['idpes_responsavel'] = $this->idpes_responsavel;
383   - $tupla[] = &$tupla['idpes_responsavel'];
384   - $tupla['idesco'] = $this->idesco;
385   - $tupla[] = &$tupla['idesco'];
386   - $tupla['ideciv'] = $this->ideciv;
387   - $tupla[] = &$tupla['ideciv'];
388   - $tupla['idpes_con'] = $this->idpes_con;
389   - $tupla[] = &$tupla['idpes_con'];
390   - $tupla['data_uniao'] = $this->data_uniao;
391   - $tupla[] = &$tupla['data_uniao'];
392   - $tupla['data_obito'] = $this->data_obito;
393   - $tupla[] = &$tupla['data_obito'];
394   - $tupla['nacionalidade'] = $this->nacionalidade;
395   - $tupla[] = &$tupla['nacionalidade'];
396   - $tupla['idpais_estrangeiro'] = $this->idpais_estrangeiro;
397   - $tupla[] = &$tupla['idpais_estrangeiro'];
398   - $tupla['data_chagada_brasil'] = $this->data_chagada_brasil;
399   - $tupla[] = &$tupla['data_chagada_brasil'];
400   - $tupla['idmun_nascimento'] = $this->idmun_nascimento;
401   - $tupla[] = &$tupla['idmun_nascimento'];
402   - $tupla['ultima_empresa'] = $this->ultima_empresa;
403   - $tupla[] = &$tupla['ultima_empresa'];
404   - $tupla['idocup'] = $this->idocup;
405   - $tupla[] = &$tupla['idocup'];
406   - $tupla['nome_mae'] = $this->nome_mae;
407   - $tupla[] = &$tupla['nome_mae'];
408   - $tupla['nome_pai'] = $this->nome_pai;
409   - $tupla[] = &$tupla['nome_pai'];
410   - $tupla['nome_conjuge'] = $this->nome_conjuge;
411   - $tupla[] = &$tupla['nome_conjuge'];
412   - $tupla['nome_responsavel'] = $this->nome_responsavel;
413   - $tupla[] = &$tupla['nome_responsavel'];
414   - $tupla['justificativa_provisorio'] = $this->justificativa_provisorio;
415   - $tupla[] = &$tupla['justificativa_provisorio'];
416   -
417   - return $tupla;
418   - }
419   - }
420   - }
421   - return false;
422   - }
423   -
424   -
425   - function queryRapida($int_idpes)
426   - {
427   - $this->idpes = $int_idpes;
428   - $this->detalhe();
429   - $resultado = array();
430   - $pos = 0;
431   - for ($i = 1; $i< func_num_args(); $i++ ) {
432   - $campo = func_get_arg($i);
433   - $resultado[$pos] = ($this->$campo) ? $this->$campo : "";
434   - $resultado[$campo] = &$resultado[$pos];
435   - $pos++;
436   -
437   - }
438   - if(count($resultado) > 0)
439   - {
440   - return $resultado;
441   - }
442   - return false;
443   - }
444   -
445   - function queryRapidaCPF( $int_cpf )
446   - {
447   - $this->cpf = $int_cpf + 0;
448   - $this->detalhe();
449   - $resultado = array();
450   - $pos = 0;
451   - for ($i = 1; $i< func_num_args(); $i++ ) {
452   - $campo = func_get_arg($i);
453   - $resultado[$pos] = ($this->$campo) ? $this->$campo : "";
454   - $resultado[$campo] = &$resultado[$pos];
455   - $pos++;
456   -
457   - }
458   - if(count($resultado) > 0)
459   - {
460   - return $resultado;
461   - }
462   - return false;
463   - }
464   -
465   - function excluir()
466   - {
467   - if($this->idpes)
468   - {
469   - $db = new clsBanco();
470   -
471   - $obj = new clsFuncionario($this->idpes);
472   - if(!$obj->detalhe())
473   - {
474   - $db->Consulta("Delete FROM cadastro.fone_pessoa WHERE idpes = $this->idpes");
475   - $db->Consulta("Delete FROM cadastro.fisica WHERE idpes = $this->idpes");
476   - $db->Consulta("Delete FROM cadastro.documento WHERE idpes = $this->idpes");
477   - $db->Consulta("Delete FROM cadastro.endereco_pessoa WHERE idpes = $this->idpes");
478   - $db->Consulta("Delete FROM cadastro.endereco_externo WHERE idpes = $this->idpes");
479   - $db->Consulta("Delete FROM cadastro.documento WHERE idpes = $this->idpes");
480   - $db->Consulta("Delete FROM cadastro.documento WHERE idpes = $this->idpes");
481   - $db->Consulta("Delete FROM cadastro.pessoa WHERE idpes = $this->idpes");
482   - }
483   -
484   - }
485   - }
486   - function setTipoEndereco($endereco)
487   - {
488   - if(is_numeric($endereco))
489   - {
490   - $this->tipo_endereco = $endereco;
491   - }
492   - }
493   -
494   -}
495   -?>
  46 + var $idpes;
  47 + var $data_nasc;
  48 + var $sexo;
  49 + var $idpes_mae;
  50 + var $idpes_pai;
  51 + var $idpes_responsavel;
  52 + var $idesco;
  53 + var $ideciv;
  54 + var $idpes_con;
  55 + var $data_uniao;
  56 + var $data_obito;
  57 + var $nacionalidade;
  58 + var $idpais_estrangeiro;
  59 + var $data_chagada_brasil;
  60 + var $idmun_nascimento;
  61 + var $ultima_empresa;
  62 + var $idocup;
  63 + var $nome_mae;
  64 + var $nome_pai;
  65 + var $nome_conjuge;
  66 + var $nome_responsavel;
  67 + var $justificativa_provisorio;
  68 + var $cpf;
  69 + var $ref_cod_religiao;
  70 + var $tipo_endereco;
  71 +
  72 + var $banco = 'pmi';
  73 + var $schema_cadastro = 'cadastro';
  74 +
  75 + /**
  76 + * Construtor.
  77 + */
  78 + function clsPessoaFisica($int_idpes = FALSE, $numeric_cpf = FALSE,
  79 + $date_data_nasc = FALSE, $str_sexo = FALSE, $int_idpes_mae = FALSE,
  80 + $int_idpes_pai = FALSE)
  81 + {
  82 + $this->idpes = $int_idpes;
  83 + $this->cpf = $numeric_cpf;
  84 + }
  85 +
  86 + function lista_simples($str_nome = FALSE, $numeric_cpf = FALSE,
  87 + $inicio_limite = FALSE, $qtd_registros = FALSE, $str_orderBy = FALSE,
  88 + $int_ref_cod_sistema = FALSE)
  89 + {
  90 + $whereAnd = '';
  91 + $where = '';
  92 +
  93 + if (is_string($str_nome) && $str_nome != '') {
  94 + $str_nome = str_replace(' ', '%', $str_nome);
  95 + $where .= "{$whereAnd} nome ILIKE '%{$str_nome}%' ";
  96 + $whereAnd = ' AND ';
  97 + }
  98 +
  99 + if (is_string($numeric_cpf)) {
  100 + $where .= "{$whereAnd} cpf ILIKE '%{$numeric_cpf}%' ";
  101 + }
  102 +
  103 + if (is_numeric($int_ref_cod_sistema)) {
  104 + $where .= "{$whereAnd} (ref_cod_sistema = '{$int_ref_cod_sistema}' OR cpf is not null )";
  105 + }
  106 +
  107 + if ($inicio_limite !== FALSE && $qtd_registros) {
  108 + $limite = "LIMIT $qtd_registros OFFSET $inicio_limite ";
  109 + }
  110 +
  111 + $orderBy = ' ORDER BY ';
  112 +
  113 + if ($str_orderBy) {
  114 + $orderBy .= $str_orderBy . ' ';
  115 + }
  116 + else {
  117 + $orderBy .= 'nome ';
  118 + }
  119 +
  120 + if ($where) {
  121 + $where = 'WHERE ' . $where;
  122 + }
  123 +
  124 + $db = new clsBanco($this->banco);
  125 +
  126 + $total = $db->UnicoCampo('SELECT COUNT(0) FROM cadastro.fisica ' . $where);
  127 +
  128 + $db->Consulta(sprintf(
  129 + 'SELECT idpes, nome, cpf FROM cadastro.v_pessoa_fisica %s %s %s ', $where, $orderBy, $limite
  130 + ));
  131 +
  132 + $resultado = array();
  133 +
  134 + while ($db->ProximoRegistro()) {
  135 + $tupla = $db->Tupla();
  136 + $tupla['nome'] = transforma_minusculo($tupla['nome']);
  137 + $tupla['total'] = $total;
  138 + $resultado[] = $tupla;
  139 + }
  140 +
  141 + if (count($resultado) > 0) {
  142 + return $resultado;
  143 + }
  144 +
  145 + return FALSE;
  146 + }
  147 +
  148 + function lista($str_nome = FALSE, $numeric_cpf = FALSE, $inicio_limite = FALSE,
  149 + $qtd_registros = FALSE, $str_orderBy = FALSE, $int_ref_cod_sistema = FALSE,
  150 + $int_idpes = FALSE
  151 + ) {
  152 + $whereAnd = '';
  153 + $where = '';
  154 +
  155 + if (is_string($str_nome) && $str_nome != '') {
  156 + $str_nome = str_replace(' ', '%', $str_nome);
  157 + $where .= "{$whereAnd} nome ILIKE '%{$str_nome}%' ";
  158 + $whereAnd = ' AND ';
  159 + }
  160 +
  161 + if (is_string($numeric_cpf)) {
  162 + $where .= "{$whereAnd} cpf ILIKE '%{$numeric_cpf}%' ";
  163 + $whereAnd = ' AND ';
  164 + }
  165 +
  166 + if (is_numeric($int_ref_cod_sistema)) {
  167 + $where .= "{$whereAnd} (ref_cod_sistema = '{$int_ref_cod_sistema}' OR cpf is not null )";
  168 + $whereAnd = ' AND ';
  169 + }
  170 +
  171 + if (is_numeric($int_idpes)) {
  172 + $where .= "{$whereAnd} idpes = '$int_idpes'";
  173 + $whereAnd = ' AND ';
  174 + }
  175 +
  176 + if (is_numeric($this->tipo_endereco)) {
  177 + if ($this->tipo_endereco == 1) {
  178 + // Interno
  179 + $where .= "{$whereAnd} idpes IN (SELECT idpes FROM cadastro.endereco_pessoa)";
  180 + $whereAnd = ' AND ';
  181 + }
  182 + elseif ($this->tipo_endereco == 2) {
  183 + // Externo
  184 + $where .= "{$whereAnd} idpes IN (SELECT idpes FROM cadastro.endereco_externo)";
  185 + $whereAnd = ' AND ';
  186 + }
  187 + }
  188 +
  189 + if ($inicio_limite !== FALSE && $qtd_registros) {
  190 + $limite = "LIMIT $qtd_registros OFFSET $inicio_limite ";
  191 + }
  192 +
  193 + $orderBy = ' ORDER BY ';
  194 +
  195 + if ($str_orderBy) {
  196 + $orderBy .= $str_orderBy . ' ';
  197 + }
  198 + else {
  199 + $orderBy .= 'nome ';
  200 + }
  201 +
  202 + $db = new clsBanco();
  203 + $dba = new clsBanco();
  204 +
  205 + if ($where) {
  206 + $where = "WHERE ".$where;
  207 + }
  208 +
  209 + if (! $where) {
  210 + $total = $db->CampoUnico('SELECT COUNT(0) FROM cadastro.fisica ' . $where);
  211 + }
  212 + else {
  213 + $total = $db->CampoUnico('SELECT COUNT(0) FROM cadastro.v_pessoa_fisica ' . $where);
  214 + }
  215 +
  216 + $db->Consulta(sprintf(
  217 + 'SELECT idpes, nome, url, \'F\' AS tipo, email, cpf FROM cadastro.v_pessoa_fisica %s %s %s',
  218 + $where, $orderBy, $limite
  219 + ));
  220 +
  221 + $resultado = array();
  222 +
  223 + while ($db->ProximoRegistro())
  224 + {
  225 + $tupla = $db->Tupla();
  226 + $tupla['nome'] = transforma_minusculo($tupla['nome']);
  227 + $tupla['total'] = $total;
  228 +
  229 + $dba->Consulta(sprintf(
  230 + "SELECT
  231 + ddd_1, fone_1, ddd_2, fone_2, ddd_mov, fone_mov, ddd_fax, fone_fax
  232 + FROM
  233 + cadastro.v_fone_pessoa
  234 + WHERE idpes = %d", $tupla['idpes']
  235 + ));
  236 +
  237 + if ($dba->ProximoRegistro()) {
  238 + $tupla_fone = $dba->Tupla();
  239 + }
  240 + else {
  241 + $tupla_fone = '';
  242 + }
  243 +
  244 + $tupla['ddd_1'] = $tupla_fone['ddd_1'];
  245 + $tupla['fone_1'] = $tupla_fone['fone_1'];
  246 + $tupla['ddd_2'] = $tupla_fone['ddd_2'];
  247 + $tupla['fone_2'] = $tupla_fone['fone_2'];
  248 + $tupla['ddd_mov'] = $tupla_fone['ddd_mov'];
  249 + $tupla['fone_mov'] = $tupla_fone['fone_mov'];
  250 + $tupla['ddd_fax'] = $tupla_fone['ddd_fax'];
  251 + $tupla['fone_fax'] = $tupla_fone['fone_fax'];
  252 +
  253 + $resultado[] = $tupla;
  254 + }
  255 +
  256 + if (count($resultado) > 0) {
  257 + return $resultado;
  258 + }
  259 +
  260 + return FALSE;
  261 + }
  262 +
  263 + function detalhe()
  264 + {
  265 + if ($this->idpes) {
  266 + $tupla = parent::detalhe();
  267 +
  268 + $objFisica = new clsFisica($this->idpes);
  269 + $detalhe_fisica = $objFisica->detalhe();
  270 +
  271 + if ($detalhe_fisica) {
  272 + $this->data_nasc = $detalhe_fisica['data_nasc'];
  273 + $this->sexo = $detalhe_fisica['sexo'];
  274 + $this->idpes_mae = $detalhe_fisica['idpes_mae'];
  275 + $this->idpes_pai = $detalhe_fisica['idpes_pai'];
  276 + $this->idpes_responsavel = $detalhe_fisica['idpes_responsavel'];
  277 + $this->idesco = $detalhe_fisica['idesco'];
  278 + $this->ideciv = $detalhe_fisica['ideciv'];
  279 + $this->idpes_con = $detalhe_fisica['idpes_con'];
  280 + $this->data_uniao = $detalhe_fisica['data_uniao'];
  281 + $this->data_obito = $detalhe_fisica['data_obito'];
  282 + $this->nacionalidade = $detalhe_fisica['nacionalidade'];
  283 + $this->idpais_estrangeiro = $detalhe_fisica['idpais_estrangeiro'];
  284 + $this->data_chagada_brasil = $detalhe_fisica['data_chagada_brasil'];
  285 + $this->idmun_nascimento = $detalhe_fisica['idmun_nascimento'];
  286 + $this->ultima_empresa = $detalhe_fisica['ultima_empresa'];
  287 + $this->idocup = $detalhe_fisica['idocup'];
  288 + $this->nome_mae = $detalhe_fisica['nome_mae'];
  289 + $this->nome_pai = $detalhe_fisica['nome_pai'];
  290 + $this->nome_conjuge = $detalhe_fisica['nome_conjuge'];
  291 + $this->nome_responsavel = $detalhe_fisica['nome_responsavel'];
  292 + $this->justificativa_provisorio = $detalhe_fisica['justificativa_provisorio'];
  293 + $this->cpf = $detalhe_fisica['cpf'];
  294 + $this->ref_cod_religiao = $detalhe_fisica['ref_cod_religiao'];
  295 +
  296 + $tupla['idpes'] = $this->idpes;
  297 + $tupla[] = & $tupla['idpes'];
  298 +
  299 + $tupla['cpf'] = $this->cpf;
  300 + $tupla[] = & $tupla['cpf'];
  301 +
  302 + $tupla['ref_cod_religiao'] = $this->ref_cod_religiao;
  303 + $tupla[] = & $tupla['ref_cod_religiao'];
  304 +
  305 + $tupla['data_nasc'] = $this->data_nasc;
  306 + $tupla[] = & $tupla['data_nasc'];
  307 +
  308 + $tupla['sexo'] = $this->sexo;
  309 + $tupla[] = & $tupla['sexo'];
  310 +
  311 + $tupla['idpes_mae'] = $this->idpes_mae;
  312 + $tupla[] = & $tupla['idpes_mae'];
  313 +
  314 + $tupla['idpes_pai'] = $this->idpes_pai;
  315 + $tupla[] = & $tupla['idpes_pai'];
  316 +
  317 + $tupla['idpes_responsavel'] = $this->idpes_responsavel;
  318 + $tupla[] = & $tupla['idpes_responsavel'];
  319 +
  320 + $tupla['idesco'] = $this->idesco;
  321 + $tupla[] = & $tupla['idesco'];
  322 +
  323 + $tupla['ideciv'] = $this->ideciv;
  324 + $tupla[] = & $tupla['ideciv'];
  325 +
  326 + $tupla['idpes_con'] = $this->idpes_con;
  327 + $tupla[] = & $tupla['idpes_con'];
  328 +
  329 + $tupla['data_uniao'] = $this->data_uniao;
  330 + $tupla[] = & $tupla['data_uniao'];
  331 +
  332 + $tupla['data_obito'] = $this->data_obito;
  333 + $tupla[] = & $tupla['data_obito'];
  334 +
  335 + $tupla['nacionalidade'] = $this->nacionalidade;
  336 + $tupla[] = & $tupla['nacionalidade'];
  337 +
  338 + $tupla['idpais_estrangeiro'] = $this->idpais_estrangeiro;
  339 + $tupla[] = & $tupla['idpais_estrangeiro'];
  340 +
  341 + $tupla['data_chagada_brasil'] = $this->data_chagada_brasil;
  342 + $tupla[] = & $tupla['data_chagada_brasil'];
  343 +
  344 + $tupla['idmun_nascimento'] = $this->idmun_nascimento;
  345 + $tupla[] = & $tupla['idmun_nascimento'];
  346 +
  347 + $tupla['ultima_empresa'] = $this->ultima_empresa;
  348 + $tupla[] = & $tupla['ultima_empresa'];
  349 +
  350 + $tupla['idocup'] = $this->idocup;
  351 + $tupla[] = & $tupla['idocup'];
  352 +
  353 + $tupla['nome_mae'] = $this->nome_mae;
  354 + $tupla[] = & $tupla['nome_mae'];
  355 +
  356 + $tupla['nome_pai'] = $this->nome_pai;
  357 + $tupla[] = & $tupla['nome_pai'];
  358 +
  359 + $tupla['nome_conjuge'] = $this->nome_conjuge;
  360 + $tupla[] = & $tupla['nome_conjuge'];
  361 +
  362 + $tupla['nome_responsavel'] = $this->nome_responsavel;
  363 + $tupla[] = & $tupla['nome_responsavel'];
  364 +
  365 + $tupla['justificativa_provisorio'] = $this->justificativa_provisorio;
  366 + $tupla[] = & $tupla['justificativa_provisorio'];
  367 +
  368 + return $tupla;
  369 + }
  370 + }
  371 + elseif ($this->cpf) {
  372 + $tupla = parent::detalhe();
  373 +
  374 + $objFisica = new clsFisica();
  375 + $lista = $objFisica->lista(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
  376 + FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
  377 + FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
  378 + FALSE, FALSE, FALSE, FALSE, $this->cpf);
  379 +
  380 + $this->idpes = $lista[0]['idpes'];
  381 +
  382 + if ($this->idpes) {
  383 + $objFisica = new clsFisica($this->idpes);
  384 + $detalhe_fisica = $objFisica->detalhe();
  385 +
  386 + if ($detalhe_fisica) {
  387 + $this->data_nasc = $detalhe_fisica['data_nasc'];
  388 + $this->sexo = $detalhe_fisica['sexo'];
  389 + $this->idpes_mae = $detalhe_fisica['idpes_mae'];
  390 + $this->idpes_pai = $detalhe_fisica['idpes_pai'];
  391 + $this->idpes_responsavel = $detalhe_fisica['idpes_responsavel'];
  392 + $this->idesco = $detalhe_fisica['idesco'];
  393 + $this->ideciv = $detalhe_fisica['ideciv'];
  394 + $this->idpes_con = $detalhe_fisica['idpes_con'];
  395 + $this->data_uniao = $detalhe_fisica['data_uniao'];
  396 + $this->data_obito = $detalhe_fisica['data_obito'];
  397 + $this->nacionalidade = $detalhe_fisica['nacionalidade'];
  398 + $this->idpais_estrangeiro = $detalhe_fisica['idpais_estrangeiro'];
  399 + $this->data_chagada_brasil = $detalhe_fisica['data_chagada_brasil'];
  400 + $this->idmun_nascimento = $detalhe_fisica['idmun_nascimento'];
  401 + $this->ultima_empresa = $detalhe_fisica['ultima_empresa'];
  402 + $this->idocup = $detalhe_fisica['idocup'];
  403 + $this->nome_mae = $detalhe_fisica['nome_mae'];
  404 + $this->nome_pai = $detalhe_fisica['nome_pai'];
  405 + $this->nome_conjuge = $detalhe_fisica['nome_conjuge'];
  406 + $this->nome_responsavel = $detalhe_fisica['nome_responsavel'];
  407 + $this->justificativa_provisorio = $detalhe_fisica['justificativa_provisorio'];
  408 + $this->cpf = $detalhe_fisica['cpf'];
  409 +
  410 + $tupla['idpes'] = $this->idpes;
  411 + $tupla[] = & $tupla['idpes'];
  412 +
  413 + $tupla['cpf'] = $this->cpf;
  414 + $tupla[] = & $tupla['cpf'];
  415 +
  416 + $tupla['data_nasc'] = $this->data_nasc;
  417 + $tupla[] = & $tupla['data_nasc'];
  418 +
  419 + $tupla['sexo'] = $this->sexo;
  420 + $tupla[] = & $tupla['sexo'];
  421 +
  422 + $tupla['idpes_mae'] = $this->idpes_mae;
  423 + $tupla[] = & $tupla['idpes_mae'];
  424 +
  425 + $tupla['idpes_pai'] = $this->idpes_pai;
  426 + $tupla[] = & $tupla['idpes_pai'];
  427 +
  428 + $tupla['idpes_responsavel'] = $this->idpes_responsavel;
  429 + $tupla[] = & $tupla['idpes_responsavel'];
  430 +
  431 + $tupla['idesco'] = $this->idesco;
  432 + $tupla[] = & $tupla['idesco'];
  433 +
  434 + $tupla['ideciv'] = $this->ideciv;
  435 + $tupla[] = & $tupla['ideciv'];
  436 +
  437 + $tupla['idpes_con'] = $this->idpes_con;
  438 + $tupla[] = & $tupla['idpes_con'];
  439 +
  440 + $tupla['data_uniao'] = $this->data_uniao;
  441 + $tupla[] = & $tupla['data_uniao'];
  442 +
  443 + $tupla['data_obito'] = $this->data_obito;
  444 + $tupla[] = & $tupla['data_obito'];
  445 +
  446 + $tupla['nacionalidade'] = $this->nacionalidade;
  447 + $tupla[] = & $tupla['nacionalidade'];
  448 +
  449 + $tupla['idpais_estrangeiro'] = $this->idpais_estrangeiro;
  450 + $tupla[] = & $tupla['idpais_estrangeiro'];
  451 +
  452 + $tupla['data_chagada_brasil'] = $this->data_chagada_brasil;
  453 + $tupla[] = & $tupla['data_chagada_brasil'];
  454 +
  455 + $tupla['idmun_nascimento'] = $this->idmun_nascimento;
  456 + $tupla[] = & $tupla['idmun_nascimento'];
  457 +
  458 + $tupla['ultima_empresa'] = $this->ultima_empresa;
  459 + $tupla[] = & $tupla['ultima_empresa'];
  460 +
  461 + $tupla['idocup'] = $this->idocup;
  462 + $tupla[] = & $tupla['idocup'];
  463 +
  464 + $tupla['nome_mae'] = $this->nome_mae;
  465 + $tupla[] = & $tupla['nome_mae'];
  466 +
  467 + $tupla['nome_pai'] = $this->nome_pai;
  468 + $tupla[] = & $tupla['nome_pai'];
  469 +
  470 + $tupla['nome_conjuge'] = $this->nome_conjuge;
  471 + $tupla[] = & $tupla['nome_conjuge'];
  472 +
  473 + $tupla['nome_responsavel'] = $this->nome_responsavel;
  474 + $tupla[] = & $tupla['nome_responsavel'];
  475 +
  476 + $tupla['justificativa_provisorio'] = $this->justificativa_provisorio;
  477 + $tupla[] = & $tupla['justificativa_provisorio'];
  478 +
  479 + return $tupla;
  480 + }
  481 + }
  482 + }
  483 +
  484 + return FALSE;
  485 + }
  486 +
  487 + function queryRapida($int_idpes)
  488 + {
  489 + $this->idpes = $int_idpes;
  490 + $this->detalhe();
  491 +
  492 + $resultado = array();
  493 + $pos = 0;
  494 +
  495 + for ($i = 1; $i< func_num_args(); $i++ ) {
  496 + $campo = func_get_arg($i);
  497 +
  498 + $resultado[$pos] = $this->$campo ? $this->$campo : '';
  499 + $resultado[$campo] = & $resultado[$pos];
  500 +
  501 + $pos++;
  502 + }
  503 +
  504 + if (count($resultado) > 0) {
  505 + return $resultado;
  506 + }
  507 +
  508 + return FALSE;
  509 + }
  510 +
  511 + function queryRapidaCPF($int_cpf)
  512 + {
  513 + $this->cpf = $int_cpf + 0;
  514 + $this->detalhe();
  515 +
  516 + $resultado = array();
  517 + $pos = 0;
  518 +
  519 + for ($i = 1; $i< func_num_args(); $i++ ) {
  520 + $campo = func_get_arg($i);
  521 + $resultado[$pos] = $this->$campo ? $this->$campo : '';
  522 + $resultado[$campo] = & $resultado[$pos];
  523 + $pos++;
  524 + }
  525 +
  526 + if (count($resultado) > 0) {
  527 + return $resultado;
  528 + }
  529 +
  530 + return FALSE;
  531 + }
  532 +
  533 + function excluir()
  534 + {
  535 + if ($this->idpes) {
  536 + $db = new clsBanco();
  537 + $obj = new clsFuncionario($this->idpes);
  538 +
  539 + if (! $obj->detalhe()) {
  540 + $db->Consulta('DELETE FROM cadastro.fone_pessoa WHERE idpes = ' . $this->idpes);
  541 + $db->Consulta('DELETE FROM cadastro.fisica WHERE idpes = ' . $this->idpes);
  542 + $db->Consulta('DELETE FROM cadastro.documento WHERE idpes = ' . $this->idpes);
  543 + $db->Consulta('DELETE FROM cadastro.endereco_pessoa WHERE idpes = ' . $this->idpes);
  544 + $db->Consulta('DELETE FROM cadastro.endereco_externo WHERE idpes = ' . $this->idpes);
  545 + $db->Consulta('DELETE FROM cadastro.documento WHERE idpes = ' . $this->idpes);
  546 + $db->Consulta('DELETE FROM cadastro.documento WHERE idpes = ' . $this->idpes);
  547 + $db->Consulta('DELETE FROM cadastro.pessoa WHERE idpes = ' . $this->idpes);
  548 + }
  549 + }
  550 + }
  551 +
  552 + function setTipoEndereco($endereco)
  553 + {
  554 + if (is_numeric($endereco)) {
  555 + $this->tipo_endereco = $endereco;
  556 + }
  557 + }
  558 +}
496 559 \ No newline at end of file
... ...