From 8b7a1c0ea96b3e47ff24ea9e37c6c82ed7279762 Mon Sep 17 00:00:00 2001 From: Lucas D'Avila Date: Wed, 6 Mar 2013 18:20:53 -0300 Subject: [PATCH] Alterado simple search pessoa, para quando informado, exibir após o nome da pessoa a data de nascimento e o RG. Alterado cadastro de pessoa fisica, para obrigar informar o RG dos pais do aluno. Incluido no cadastro de aluno campo RG e Data nascimento. --- ieducar/intranet/atendidos_cad.php | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++------------------ ieducar/lib/Portabilis/View/Helper/Input/Date.php | 23 ++++++++++++++++++++++- ieducar/modules/Api/Views/PessoaController.php | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- ieducar/modules/Cadastro/Assets/Javascripts/Aluno.js | 4 ++-- ieducar/modules/Cadastro/Assets/Javascripts/PessoaFisica.js | 16 ---------------- ieducar/modules/Cadastro/Views/AlunoController.php | 19 +++++++------------ ieducar/modules/Portabilis/Assets/Version.php | 2 +- 7 files changed, 136 insertions(+), 53 deletions(-) diff --git a/ieducar/intranet/atendidos_cad.php b/ieducar/intranet/atendidos_cad.php index e3fd977..f751d69 100755 --- a/ieducar/intranet/atendidos_cad.php +++ b/ieducar/intranet/atendidos_cad.php @@ -170,11 +170,27 @@ class indice extends clsCadastro $this->campoOculto('cod_pessoa_fj', $this->cod_pessoa_fj); $this->campoTexto('nm_pessoa', 'Nome', $this->nm_pessoa, '50', '255', TRUE); + + // ao cadastrar pessoa do pai ou mãe apartir do cadastro de outra pessoa, + // é enviado o tipo de cadastro (pai ou mae). + $parentType = isset($_REQUEST['parent_type']) ? $_REQUEST['parent_type'] : ''; + + // sexo + $sexo = $this->sexo; + + // sugere sexo quando cadastrando o pai ou mãe + + if (! $sexo && $parentType == 'pai') + $sexo = 'M'; + elseif (! $sexo && $parentType == 'mae') + $sexo = 'F'; + + $options = array( 'label' => 'Sexo / Estado civil', - 'value' => $this->sexo, + 'value' => $sexo, 'resources' => array( '' => 'Sexo', 'M' => 'Masculino', @@ -187,14 +203,15 @@ class indice extends clsCadastro // estado civil - $this->inputsHelper()->estadoCivil(array('label' => '')); + $this->inputsHelper()->estadoCivil(array('label' => '', 'required' => empty($parentType))); // data nascimento $options = array( 'label' => 'Data nascimento', - 'value' => $this->data_nasc + 'value' => $this->data_nasc, + 'required' => empty($parentType) ); $this->inputsHelper()->date('data_nasc', $options); @@ -214,14 +231,22 @@ class indice extends clsCadastro // rg + // o rg é obrigatorio ao cadastrar pai ou mãe, exceto se configurado como opcional. + + $required = (! empty($parentType)); + + if ($required && $GLOBALS['coreExt']['Config']->app->rg_pessoa_fisica_pais_opcional) { + $required = false; + } + $options = array( - 'required' => false, - 'label' => 'RG / Data emissão', + 'required' => $required, + 'label' => 'RG / Data emissão', 'placeholder' => 'Documento identidade', - 'value' => $documentos['rg'], - 'max_length' => 20, - 'size' => 27, - 'inline' => true + 'value' => $documentos['rg'], + 'max_length' => 20, + 'size' => 27, + 'inline' => true ); $this->inputsHelper()->integer('rg', $options); @@ -570,6 +595,10 @@ class indice extends clsCadastro $this->campoOculto('id_cidade', $this->cidade); + // o endereçamento é opcional ao cadastrar pai ou mãe. + $enderecamentoObrigatorio = empty($parentType); + + // considera como endereço localizado por CEP quando alguma das variaveis de instancia // idbai (bairro) ou idlog (logradouro) estão definidas, neste caso desabilita a edição // dos campos definidos via CEP. @@ -579,7 +608,7 @@ class indice extends clsCadastro 'cep_', 'CEP', $this->cep, - TRUE, + $enderecamentoObrigatorio, '-', " ');\">", $desativarCamposDefinidosViaCep @@ -592,7 +621,8 @@ class indice extends clsCadastro 'label' => 'Estado / Cidade', 'value' => $this->sigla_uf, 'disabled' => $desativarCamposDefinidosViaCep, - 'inline' => true + 'inline' => true, + 'required' => $enderecamentoObrigatorio ); $helperOptions = array( @@ -609,7 +639,8 @@ class indice extends clsCadastro 'placeholder' => 'Cidade', 'value' => $this->cidade, 'max_length' => 60, - 'disabled' => $desativarCamposDefinidosViaCep + 'disabled' => $desativarCamposDefinidosViaCep, + 'required' => $enderecamentoObrigatorio ); $this->inputsHelper()->text('cidade', $options); @@ -623,7 +654,8 @@ class indice extends clsCadastro 'value' => $this->bairro, 'max_length' => 40, 'disabled' => $desativarCamposDefinidosViaCep, - 'inline' => true + 'inline' => true, + 'required' => $enderecamentoObrigatorio ); $this->inputsHelper()->text('bairro', $options); @@ -640,7 +672,8 @@ class indice extends clsCadastro 'placeholder' => 'Zona localização', 'value' => $this->zona_localizacao, 'disabled' => $desativarCamposDefinidosViaCep, - 'resources' => $zonas + 'resources' => $zonas, + 'required' => $enderecamentoObrigatorio ); $this->inputsHelper()->select('zona_localizacao', $options); @@ -652,7 +685,8 @@ class indice extends clsCadastro 'label' => 'Tipo / Logradouro', 'value' => $this->idtlog, 'disabled' => $desativarCamposDefinidosViaCep, - 'inline' => true + 'inline' => true, + 'required' => $enderecamentoObrigatorio ); $helperOptions = array( @@ -669,7 +703,8 @@ class indice extends clsCadastro 'placeholder' => 'Logradouro', 'value' => $this->logradouro, 'max_length' => 150, - 'disabled' => $desativarCamposDefinidosViaCep + 'disabled' => $desativarCamposDefinidosViaCep, + 'required' => $enderecamentoObrigatorio ); $this->inputsHelper()->text('logradouro', $options); @@ -777,8 +812,8 @@ class indice extends clsCadastro // after change pessoa pai / mae - if (isset($_REQUEST['parent_type'])) - $this->inputsHelper()->hidden('parent_type', array('value' => $_REQUEST['parent_type'])); + if ($parentType) + $this->inputsHelper()->hidden('parent_type', array('value' => $parentType)); $styles = array( diff --git a/ieducar/lib/Portabilis/View/Helper/Input/Date.php b/ieducar/lib/Portabilis/View/Helper/Input/Date.php index c96863c..5895e15 100644 --- a/ieducar/lib/Portabilis/View/Helper/Input/Date.php +++ b/ieducar/lib/Portabilis/View/Helper/Input/Date.php @@ -59,7 +59,10 @@ class Portabilis_View_Helper_Input_Date extends Portabilis_View_Helper_Input_Cor 'label_hint' => '', 'inline' => false, 'callback' => false, - 'disabled' => false); + 'disabled' => false, + + // opcoes suportadas pelo elemento, mas não pelo helper ieducar + 'size' => 9); $inputOptions = $this->mergeOptions($options['options'], $defaultInputOptions); @@ -70,5 +73,23 @@ class Portabilis_View_Helper_Input_Date extends Portabilis_View_Helper_Input_Cor call_user_func_array(array($this->viewInstance, 'campoData'), $inputOptions); $this->fixupPlaceholder($inputOptions); + + // implementado fixup via js, pois algumas opções não estão sendo verificadas pelo helper ieducar. + $this->fixupOptions($inputOptions); + } + + protected function fixupOptions($inputOptions) { + $id = $inputOptions['id']; + + $sizeFixup = "\$input.attr('size', " . $inputOptions['size'] . ");"; + $disableFixup = $inputOptions['disabled'] ? "\$input.attr('disabled', 'disabled');" : ''; + + $script = " + var \$input = \$j('#" . $id . "'); + $sizeFixup + $disableFixup + "; + + Portabilis_View_Helper_Application::embedJavascript($this->viewInstance, $script, $afterReady = true); } } diff --git a/ieducar/modules/Api/Views/PessoaController.php b/ieducar/modules/Api/Views/PessoaController.php index 94e3f78..e2d0d1d 100644 --- a/ieducar/modules/Api/Views/PessoaController.php +++ b/ieducar/modules/Api/Views/PessoaController.php @@ -35,6 +35,7 @@ require_once 'lib/Portabilis/Controller/ApiCoreController.php'; require_once 'lib/Portabilis/Array/Utils.php'; require_once 'lib/Portabilis/String/Utils.php'; +require_once 'lib/Portabilis/Date/Utils.php'; class PessoaController extends ApiCoreController { @@ -70,7 +71,8 @@ class PessoaController extends ApiCoreController $sql = "select cod_aluno as id from pmieducar.aluno where ref_idpes = $1"; $id = $this->fetchPreparedQuery($sql, $pessoaId, false, 'first-field'); - // when not exists, returns an empty array that causes error on loadDetails + // caso um array vazio seja retornado, seta resultado como null, + // evitando erro em loadDetails if (empty($id)) $id = null; @@ -104,7 +106,8 @@ class PessoaController extends ApiCoreController protected function loadDetails($pessoaId = null) { $alunoId = $this->tryLoadAlunoId($pessoaId); - $sql = "select cpf, idpes_pai as pai_id, idpes_mae as mae_id, idpes_responsavel as responsavel_id, + $sql = "select cpf, data_nasc as data_nascimento, idpes_pai as pai_id, + idpes_mae as mae_id, idpes_responsavel as responsavel_id, coalesce((select nome from cadastro.pessoa where idpes = fisica.idpes_pai), (select nm_pai from pmieducar.aluno where cod_aluno = $1)) as nome_pai, coalesce((select nome from cadastro.pessoa where idpes = fisica.idpes_mae), @@ -115,7 +118,7 @@ class PessoaController extends ApiCoreController $details = $this->fetchPreparedQuery($sql, array($alunoId, $pessoaId), false, 'first-row'); - $attrs = array('cpf', 'rg', 'pai_id', 'mae_id', 'responsavel_id', 'nome_pai', 'nome_mae', 'nome_responsavel'); + $attrs = array('cpf', 'rg', 'data_nascimento', 'pai_id', 'mae_id', 'responsavel_id', 'nome_pai', 'nome_mae', 'nome_responsavel'); $details = Portabilis_Array_Utils::filter($details, $attrs); $details['aluno_id'] = $alunoId; @@ -123,6 +126,8 @@ class PessoaController extends ApiCoreController $details['nome_pai'] = $this->toUtf8($details['nome_pai'], array('transform' => true)); $details['nome_responsavel'] = $this->toUtf8($details['nome_responsavel'], array('transform' => true)); + $details['data_nascimento'] = Portabilis_Date_Utils::pgSQLToBr($details['data_nascimento']); + return $details; } @@ -143,6 +148,28 @@ class PessoaController extends ApiCoreController return $_deficiencias; } + protected function loadRg($pessoaId) { + $sql = "select rg from cadastro.documento where idpes = $1"; + $rg = $this->fetchPreparedQuery($sql, $pessoaId, false, 'first-field'); + + // caso um array vazio seja retornado, seta resultado como null + if (empty($rg)) + $rg = null; + + return $rg; + } + + protected function loadDataNascimento($pessoaId) { + $sql = "select data_nasc from cadastro.fisica where idpes = $1"; + $nascimento = $this->fetchPreparedQuery($sql, $pessoaId, false, 'first-field'); + + // caso um array vazio seja retornado, seta resultado como null + if (empty($nascimento)) + $nascimento = null; + + return $nascimento; + } + // search @@ -167,6 +194,27 @@ class PessoaController extends ApiCoreController return $sqls; } + // subscreve formatResourceValue para adicionar o rg da pessoa, ao final do valor, + // " - (RG: )", ex: "1 - Lucas D'Avila (RG: 1234567)" + protected function formatResourceValue($resource) { + $nome = $this->toUtf8($resource['name'], array('transform' => true)); + $rg = $this->loadRg($resource['id']); + $nascimento = $this->loadDataNascimento($resource['id']); + + // Quando informado, inclui detalhes extra sobre a pessoa, como RG e Data nascimento. + $details = array(); + + if ($nascimento) + $details[] = 'Nascimento: ' . Portabilis_Date_Utils::pgSQLToBr($nascimento); + + if ($rg) + $details[] = "RG: $rg"; + + $details = $details ? ' (' . implode(', ', $details) . ')' : ''; + + return $resource['id'] . " - $nome$details"; + } + // api responders protected function get() { diff --git a/ieducar/modules/Cadastro/Assets/Javascripts/Aluno.js b/ieducar/modules/Cadastro/Assets/Javascripts/Aluno.js index 8e9c8a3..3e0575e 100644 --- a/ieducar/modules/Cadastro/Assets/Javascripts/Aluno.js +++ b/ieducar/modules/Cadastro/Assets/Javascripts/Aluno.js @@ -104,8 +104,8 @@ var handleGetPersonDetails = function(dataResponse) { if (dataResponse.responsavel_id) nomeResponsavel = dataResponse.responsavel_id + ' - ' + nomeResponsavel; - //$j('#rg').val(dataResponse.rg); - //$j('#cpf').val(dataResponse.cpf); + $j('#data_nascimento').val(dataResponse.data_nascimento); + $j('#rg').val(dataResponse.rg); $j('#pai').val(nomePai); $j('#mae').val(nomeMae); diff --git a/ieducar/modules/Cadastro/Assets/Javascripts/PessoaFisica.js b/ieducar/modules/Cadastro/Assets/Javascripts/PessoaFisica.js index ef166bc..2ed22e6 100644 --- a/ieducar/modules/Cadastro/Assets/Javascripts/PessoaFisica.js +++ b/ieducar/modules/Cadastro/Assets/Javascripts/PessoaFisica.js @@ -190,22 +190,6 @@ $j(document).ready(function() { $j('#tr_uf_emissao_certidao_civil td').removeClass('formmdtd'); $j('#tr_carteira_trabalho td').removeClass('formlttd').addClass('formmdtd'); - - // remove obrigatoriedade de determinados campos, ao criar pessoa pai ou mãe - // para agilizar o cadastro do filho; - - if ($j.inArray($j('#parent_type').val(), ['pai', 'mae']) > -1) { - var $elements = $j('#sexo, #estado_civil_id, #data_nasc, #cep_, #sigla_uf, #cidade, #bairro,\ - #zona_localizacao, #idtlog, #logradouro').filter('[value=]'); - - $elements.addClass('skip-presence-validation'); - - // remove '*' obrigatório ao lado do label. - $elements.each(function(index, element) { - $j(element).closest('tr').find('.campo_obrigatorio').hide(); - }); - } - // bind events checkTipoNacionalidade(); diff --git a/ieducar/modules/Cadastro/Views/AlunoController.php b/ieducar/modules/Cadastro/Views/AlunoController.php index ddfefb1..b3b0e73 100644 --- a/ieducar/modules/Cadastro/Views/AlunoController.php +++ b/ieducar/modules/Cadastro/Views/AlunoController.php @@ -50,12 +50,7 @@ class AlunoController extends Portabilis_Controller_Page_EditController ), 'rg' => array( - 'label' => 'Documento de identidade (rg)', - 'help' => '', - ), - - 'cpf' => array( - 'label' => 'CPF', + 'label' => 'Documento de identidade (RG)', 'help' => '', ), @@ -143,13 +138,13 @@ class AlunoController extends Portabilis_Controller_Page_EditController $options = array('label' => $this->_getLabel('pessoa'), 'size' => 68); $this->inputsHelper()->simpleSearchPessoa('nome', $options); - // rg - //$options = array('label' => $this->_getLabel('rg'), 'disabled' => true, 'required' => false); - //$this->inputsHelper()->text('aluno', 'rg', $options); + // data nascimento + $options = array('label' => 'Data nascimento', 'disabled' => true, 'required' => false, 'size' => 25, 'placeholder' => ''); + $this->inputsHelper()->date('data_nascimento', $options); - // cpf - //$options = array('label' => $this->_getLabel('cpf'), 'disabled' => true, 'required' => false); - //$this->inputsHelper()->text('aluno', 'cpf', $options); + // rg + $options = array('label' => $this->_getLabel('rg'), 'disabled' => true, 'required' => false, 'size' => 25); + $this->inputsHelper()->integer('rg', $options); // pai $options = array('label' => $this->_getLabel('pai'), 'disabled' => true, 'required' => false, 'size' => 68); diff --git a/ieducar/modules/Portabilis/Assets/Version.php b/ieducar/modules/Portabilis/Assets/Version.php index 401ae83..41d09d0 100644 --- a/ieducar/modules/Portabilis/Assets/Version.php +++ b/ieducar/modules/Portabilis/Assets/Version.php @@ -4,7 +4,7 @@ usado pelo metodos loadJavascript e loadStylesheet do helper Portabilis_View_Helper_Application */ class Portabilis_Assets_Version { - const VERSION = "0_0_0_1008"; + const VERSION = "0_0_0_1009"; } ?> -- libgit2 0.21.2