Commit 141366a8de6c0e618ba7aaed28d4bc651743afed
Committed by
GitHub
Exists in
2.9
and in
2 other branches
Merge pull request #8534 from portabilis/issue-84
Refatoração da tela de unificação de pessoas
Showing
11 changed files
with
1592 additions
and
72 deletions
Show diff stats
... | ... | @@ -0,0 +1,21 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace App\Services; | |
4 | + | |
5 | +class ValidationDataService | |
6 | +{ | |
7 | + public function verifyQuantityByKey($data, $key, $quantity): bool | |
8 | + { | |
9 | + $dataFilter = array_filter($data, fn($item) => $item[$key] === true); | |
10 | + | |
11 | + return count($dataFilter) > $quantity; | |
12 | + } | |
13 | + | |
14 | + public function verifyDataContainsDuplicatesByKey($data, $key): bool | |
15 | + { | |
16 | + $ids = array_map(fn($item) => $item[$key], $data); | |
17 | + $ids = array_unique($ids); | |
18 | + | |
19 | + return count($data) === count($ids); | |
20 | + } | |
21 | +} | ... | ... |
ieducar/intranet/educar_unifica_aluno.php
1 | 1 | <?php |
2 | 2 | |
3 | 3 | use App\Models\LogUnification; |
4 | +use App\Services\ValidationDataService; | |
4 | 5 | use iEducar\Modules\Unification\StudentLogUnification; |
5 | 6 | use Illuminate\Support\Facades\DB; |
6 | 7 | |
... | ... | @@ -8,77 +9,95 @@ return new class extends clsCadastro { |
8 | 9 | public $pessoa_logada; |
9 | 10 | public $tabela_alunos = []; |
10 | 11 | public $aluno_duplicado; |
12 | + public $alunos; | |
11 | 13 | |
12 | 14 | public function Inicializar() |
13 | 15 | { |
14 | - $retorno = 'Novo'; | |
15 | - | |
16 | - $obj_permissoes = new clsPermissoes(); | |
17 | - $obj_permissoes->permissao_cadastra( | |
18 | - 999847, | |
19 | - $this->pessoa_logada, | |
20 | - 7, | |
21 | - 'index.php' | |
22 | - ); | |
16 | + $this->validaPermissaoDaPagina(); | |
23 | 17 | |
24 | 18 | $this->breadcrumb('Cadastrar unificação', [ |
25 | 19 | url('intranet/educar_index.php') => 'Escola', |
26 | 20 | ]); |
27 | 21 | |
28 | - $this->url_cancelar = route('student-log-unification.index'); | |
29 | - $this->nome_url_cancelar = 'Cancelar'; | |
30 | - | |
31 | - return $retorno; | |
22 | + return 'Novo'; | |
32 | 23 | } |
33 | 24 | |
34 | 25 | public function Gerar() |
35 | 26 | { |
36 | - $this->inputsHelper()->dynamic('ano', ['required' => false, 'max_length' => 4]); | |
37 | - $this->inputsHelper()->dynamic('instituicao', ['required' => false, 'show-select' => true]); | |
38 | - $this->inputsHelper()->dynamic('escola', ['required' => false, 'show-select' => true, 'value' => 0]); | |
39 | - $this->inputsHelper()->simpleSearchAluno(null, ['label' => 'Aluno principal' ]); | |
40 | - $this->campoTabelaInicio('tabela_alunos', '', ['Aluno duplicado'], $this->tabela_alunos); | |
41 | - $this->campoTexto('aluno_duplicado', 'Aluno duplicado', $this->aluno_duplicado, 50, 255, false, true, false, '', '', '', 'onfocus'); | |
27 | + $this->acao_enviar = 'carregaDadosAlunos()'; | |
28 | + $this->campoTabelaInicio('tabela_alunos', '', ['Aluno duplicado', 'Campo aluno duplicado'], $this->tabela_alunos); | |
29 | + $this->campoRotulo('aluno_label', '', 'Aluno(a) a ser unificado(a) <span class="campo_obrigatorio">*</span>'); | |
30 | + $this->campoTexto('aluno_duplicado', 'Aluno duplicado', $this->aluno_duplicado, 50, 255, false, true, false, '', '', '', 'onfocus'); | |
42 | 31 | $this->campoTabelaFim(); |
32 | + | |
33 | + $styles = ['/modules/Cadastro/Assets/Stylesheets/UnificaAluno.css']; | |
34 | + Portabilis_View_Helper_Application::loadStylesheet($this, $styles); | |
35 | + $scripts = ['/modules/Portabilis/Assets/Javascripts/ClientApi.js']; | |
36 | + Portabilis_View_Helper_Application::loadJavascript($this, $scripts); | |
43 | 37 | } |
44 | 38 | |
45 | - public function Novo() | |
39 | + private function validaPermissaoDaPagina() | |
46 | 40 | { |
47 | - $obj_permissoes = new clsPermissoes(); | |
48 | - $obj_permissoes->permissao_cadastra( | |
41 | + (new clsPermissoes()) | |
42 | + ->permissao_cadastra( | |
49 | 43 | 999847, |
50 | 44 | $this->pessoa_logada, |
51 | 45 | 7, |
52 | 46 | 'index.php' |
53 | 47 | ); |
48 | + } | |
54 | 49 | |
55 | - $cod_aluno_principal = (int) $this->aluno_id; | |
50 | + private function validaDadosDaUnificacaoAluno($alunos): bool | |
51 | + { | |
52 | + foreach ($alunos as $item) { | |
53 | + if (! isset($item['codAluno'])) { | |
54 | + return false; | |
55 | + } | |
56 | 56 | |
57 | - if (!$cod_aluno_principal) { | |
58 | - return; | |
57 | + if (! isset($item['aluno_principal'])) { | |
58 | + return false; | |
59 | + } | |
59 | 60 | } |
60 | 61 | |
61 | - $cod_alunos = []; | |
62 | + return true; | |
63 | + } | |
64 | + | |
65 | + public function Novo() | |
66 | + { | |
67 | + $this->validaPermissaoDaPagina(); | |
62 | 68 | |
63 | - //Monta um array com o código dos alunos selecionados na tabela | |
64 | - foreach ($this->aluno_duplicado as $key => $value) { | |
65 | - $explode = explode(' ', $value); | |
69 | + try { | |
70 | + $alunos = json_decode($this->alunos, true, 512, JSON_THROW_ON_ERROR); | |
71 | + } catch (Exception $exception) { | |
72 | + $this->mensagem = 'Informações inválidas para unificação'; | |
73 | + return false; | |
74 | + } | |
66 | 75 | |
67 | - if ($explode[0] == $cod_aluno_principal) { | |
68 | - $this->mensagem = 'Impossivel de unificar alunos iguais.<br />'; | |
76 | + if (! $this->validaDadosDaUnificacaoAluno($alunos)) { | |
77 | + $this->mensagem = 'Dados enviados inválidos, recarregue a tela e tente novamente!'; | |
78 | + return false; | |
79 | + } | |
69 | 80 | |
70 | - return false; | |
71 | - } | |
81 | + $validationData = new ValidationDataService(); | |
72 | 82 | |
73 | - $cod_alunos[] = (int) $explode[0]; | |
83 | + if (! $validationData->verifyQuantityByKey($alunos,'aluno_principal', 0)) { | |
84 | + $this->mensagem = 'Aluno principal não informado'; | |
85 | + return false; | |
74 | 86 | } |
75 | 87 | |
76 | - if (!count($cod_alunos)) { | |
77 | - $this->mensagem = 'Informe no mínimo um aluno para unificação.<br />'; | |
88 | + if ($validationData->verifyQuantityByKey($alunos,'aluno_principal', 1)) { | |
89 | + $this->mensagem = 'Não pode haver mais de uma aluno principal'; | |
90 | + return false; | |
91 | + } | |
78 | 92 | |
93 | + if (! $validationData->verifyDataContainsDuplicatesByKey($alunos,'codAluno')) { | |
94 | + $this->mensagem = 'Erro ao tentar unificar Alunos, foi inserido cadastro duplicados'; | |
79 | 95 | return false; |
80 | 96 | } |
81 | 97 | |
98 | + $cod_aluno_principal = $this->buscaPessoaPrincipal($alunos); | |
99 | + $cod_alunos = $this->buscaIdesDasPessoasParaUnificar($alunos); | |
100 | + | |
82 | 101 | DB::beginTransaction(); |
83 | 102 | $unificationId = $this->createLog($cod_aluno_principal, $cod_alunos, $this->pessoa_logada); |
84 | 103 | App_Unificacao_Aluno::unifica($cod_aluno_principal, $cod_alunos, $this->pessoa_logada, new clsBanco(), $unificationId); |
... | ... | @@ -96,6 +115,22 @@ return new class extends clsCadastro { |
96 | 115 | $this->simpleRedirect(route('student-log-unification.index')); |
97 | 116 | } |
98 | 117 | |
118 | + private function buscaIdesDasPessoasParaUnificar($pessoas) | |
119 | + { | |
120 | + return array_values(array_map(static fn ($item) => (int) $item['codAluno'], | |
121 | + array_filter($pessoas, static fn ($pessoas) => $pessoas['aluno_principal'] === false) | |
122 | + )); | |
123 | + } | |
124 | + | |
125 | + private function buscaPessoaPrincipal($pessoas) | |
126 | + { | |
127 | + $pessoas = array_values(array_filter($pessoas, | |
128 | + static fn ($pessoas) => $pessoas['aluno_principal'] === true) | |
129 | + ); | |
130 | + | |
131 | + return (int) current($pessoas)['codAluno']; | |
132 | + } | |
133 | + | |
99 | 134 | private function createLog($mainId, $duplicatesId, $createdBy) |
100 | 135 | { |
101 | 136 | $log = new LogUnification(); | ... | ... |
ieducar/intranet/educar_unifica_pessoa.php
... | ... | @@ -2,12 +2,13 @@ |
2 | 2 | |
3 | 3 | use App\Models\Individual; |
4 | 4 | use App\Models\LogUnification; |
5 | +use App\Services\ValidationDataService; | |
5 | 6 | use iEducar\Modules\Unification\PersonLogUnification; |
6 | 7 | use Illuminate\Support\Facades\DB; |
7 | 8 | |
8 | 9 | return new class extends clsCadastro { |
10 | + public $pessoas; | |
9 | 11 | public $pessoa_logada; |
10 | - | |
11 | 12 | public $tabela_pessoas = []; |
12 | 13 | public $pessoa_duplicada; |
13 | 14 | |
... | ... | @@ -38,14 +39,19 @@ return new class extends clsCadastro { |
38 | 39 | |
39 | 40 | public function Gerar() |
40 | 41 | { |
41 | - $this->acao_enviar = 'showConfirmationMessage()'; | |
42 | - $this->inputsHelper()->dynamic('ano', ['required' => false, 'max_length' => 4]); | |
43 | - $this->inputsHelper()->simpleSearchPessoa(null, ['label' => 'Pessoa principal' ]); | |
44 | - $this->campoTabelaInicio('tabela_pessoas', '', ['Pessoa duplicada'], $this->tabela_pessoas); | |
45 | - $this->campoTexto('pessoa_duplicada', 'Pessoa duplicada', $this->pessoa_duplicada, 50, 255, false, true, false, '', '', '', 'onfocus'); | |
42 | + $this->acao_enviar = 'carregaDadosPessoas()'; | |
43 | + $this->campoTabelaInicio('tabela_pessoas', '', ['Pessoa duplicada', 'Campo Pessoa duplicada'], $this->tabela_pessoas); | |
44 | + $this->campoRotulo('pessoa_label', '', 'Pessoa física a ser unificada <span class="campo_obrigatorio">*</span>'); | |
45 | + $this->campoTexto('pessoa_duplicada', 'Pessoa duplicada', $this->pessoa_duplicada, 50, 255, false, true, false, '', '', '', 'onfocus'); | |
46 | 46 | $this->campoTabelaFim(); |
47 | + | |
48 | + $styles = ['/modules/Cadastro/Assets/Stylesheets/UnificaPessoa.css']; | |
49 | + $scripts = ['/modules/Portabilis/Assets/Javascripts/ClientApi.js']; | |
50 | + Portabilis_View_Helper_Application::loadStylesheet($this, $styles); | |
51 | + Portabilis_View_Helper_Application::loadJavascript($this, $scripts); | |
47 | 52 | } |
48 | 53 | |
54 | + | |
49 | 55 | public function Novo() |
50 | 56 | { |
51 | 57 | $obj_permissoes = new clsPermissoes(); |
... | ... | @@ -56,33 +62,47 @@ return new class extends clsCadastro { |
56 | 62 | 'index.php' |
57 | 63 | ); |
58 | 64 | |
59 | - $codPessoaPrincipal = (int) $this->pessoa_id; | |
60 | - | |
61 | - if (!$codPessoaPrincipal) { | |
62 | - return; | |
65 | + if (empty($this->pessoas)) { | |
66 | + $this->simpleRedirect('index.php'); | |
63 | 67 | } |
64 | 68 | |
65 | - $codPessoas = []; | |
69 | + try { | |
70 | + $pessoas = json_decode($this->pessoas, true, 512, JSON_THROW_ON_ERROR); | |
71 | + } catch (Exception $exception) { | |
72 | + $this->mensagem = 'Informações inválidas para unificação'; | |
73 | + return false; | |
74 | + } | |
66 | 75 | |
67 | - //Monta um array com o código dos pessoas selecionados na tabela | |
68 | - foreach ($this->pessoa_duplicada as $key => $value) { | |
69 | - $explode = explode(' ', $value); | |
76 | + if (count($pessoas) < 2) { | |
77 | + $this->mensagem = 'Informe no mínimo duas pessoas para unificação.<br />'; | |
78 | + return false; | |
79 | + } | |
70 | 80 | |
71 | - if ($explode[0] == $codPessoaPrincipal) { | |
72 | - $this->mensagem = 'Impossivel de unificar pessoas iguais.<br />'; | |
81 | + if (! $this->validaDadosDaUnificacao($pessoas)) { | |
82 | + $this->mensagem = 'Dados enviados inválidos, recarregue a tela e tente novamente!'; | |
83 | + return false; | |
84 | + } | |
73 | 85 | |
74 | - return false; | |
75 | - } | |
86 | + $validationData = new ValidationDataService(); | |
76 | 87 | |
77 | - $codPessoas[] = (int) $explode[0]; | |
88 | + if (! $validationData->verifyQuantityByKey($pessoas,'pessoa_principal', 0)) { | |
89 | + $this->mensagem = 'Pessoa principal não informada'; | |
90 | + return false; | |
78 | 91 | } |
79 | 92 | |
80 | - if (!count($codPessoas)) { | |
81 | - $this->mensagem = 'Informe no mínimo um pessoa para unificação.<br />'; | |
93 | + if ($validationData->verifyQuantityByKey($pessoas, 'pessoa_principal', 1)) { | |
94 | + $this->mensagem = 'Não pode haver mais de uma pessoa principal'; | |
95 | + return false; | |
96 | + } | |
82 | 97 | |
98 | + if (! $validationData->verifyDataContainsDuplicatesByKey($pessoas, 'idpes')) { | |
99 | + $this->mensagem = 'Erro ao tentar unificar Pessoas, foi inserido cadastro duplicados'; | |
83 | 100 | return false; |
84 | 101 | } |
85 | 102 | |
103 | + $codPessoaPrincipal = $this->buscaPessoaPrincipal($pessoas); | |
104 | + $codPessoas = $this->buscaIdesDasPessoasParaUnificar($pessoas); | |
105 | + | |
86 | 106 | DB::beginTransaction(); |
87 | 107 | |
88 | 108 | $unificationId = $this->createLog($codPessoaPrincipal, $codPessoas, $this->pessoa_logada); |
... | ... | @@ -101,6 +121,37 @@ return new class extends clsCadastro { |
101 | 121 | return true; |
102 | 122 | } |
103 | 123 | |
124 | + private function validaDadosDaUnificacao($pessoa) | |
125 | + { | |
126 | + foreach ($pessoa as $item) { | |
127 | + if (! array_key_exists('idpes',$item)) { | |
128 | + return false; | |
129 | + } | |
130 | + | |
131 | + if (! array_key_exists('pessoa_principal',$item)) { | |
132 | + return false; | |
133 | + } | |
134 | + } | |
135 | + | |
136 | + return true; | |
137 | + } | |
138 | + | |
139 | + private function buscaIdesDasPessoasParaUnificar($pessoas) | |
140 | + { | |
141 | + return array_map(static fn ($item) => (int) $item['idpes'], | |
142 | + array_filter($pessoas, static fn ($pessoas) => $pessoas['pessoa_principal'] === false) | |
143 | + ); | |
144 | + } | |
145 | + | |
146 | + private function buscaPessoaPrincipal($pessoas) | |
147 | + { | |
148 | + $pessoas = array_values(array_filter($pessoas, | |
149 | + static fn ($pessoas) => $pessoas['pessoa_principal'] === true) | |
150 | + ); | |
151 | + | |
152 | + return current($pessoas)['idpes']; | |
153 | + } | |
154 | + | |
104 | 155 | private function createLog($mainId, $duplicatesId, $createdBy) |
105 | 156 | { |
106 | 157 | $log = new LogUnification(); | ... | ... |
ieducar/intranet/scripts/extra/educar-unifica-aluno.js
1 | +adicionaMaisUmaLinhaNaTabela(); | |
2 | +ajustaTabelaDeAlunosUnificados(); | |
3 | +ajustarUiBotao(); | |
4 | +adicionaBotoesInicias(); | |
1 | 5 | |
6 | +function ajustarUiBotao () { | |
7 | + $j('#btn_add_tab_add_1').addClass('button_center'); | |
8 | + document.getElementById("btn_add_tab_add_1").lastChild.textContent = 'ADICIONAR MAIS ALUNOS'; | |
9 | +} | |
10 | + | |
11 | +$j('#btn_add_tab_add_1').click(function(){ | |
12 | + ajustaTabelaDeAlunosUnificados(); | |
13 | + $j('a[id^="link_remove["').css('font-weight', 'bold'); | |
14 | + $j('a[id^="link_remove["').css('text-decoration', 'underline'); | |
15 | +}); | |
16 | + | |
17 | +function adicionaMaisUmaLinhaNaTabela() { | |
18 | + tab_add_1.addRow(); | |
19 | +} | |
20 | + | |
21 | +function carregaDadosAlunos() { | |
22 | + let alunos_duplicados = []; | |
23 | + let message = ''; | |
24 | + | |
25 | + $j('input[id^="aluno_duplicado["').each(function(id, input) { | |
26 | + if (input.value != "") { | |
27 | + alunos_duplicados.push(input.value.split(' ')[0]); | |
28 | + } | |
29 | + }); | |
30 | + | |
31 | + let alunos_sem_duplicidade = [...new Set(alunos_duplicados)]; | |
32 | + | |
33 | + if (alunos_duplicados.length <= 1) { | |
34 | + message = 'Informe pelo menos dois alunos para unificar.' | |
35 | + defaultModal(message); | |
36 | + return; | |
37 | + } | |
38 | + | |
39 | + if (alunos_duplicados.length != alunos_sem_duplicidade.length) { | |
40 | + message = 'Selecione alunos diferentes.' | |
41 | + defaultModal(message); | |
42 | + return; | |
43 | + } | |
44 | + | |
45 | + var url = getResourceUrlBuilder.buildUrl( | |
46 | + '/module/Api/Aluno', | |
47 | + 'dadosUnificacaoAlunos', | |
48 | + { | |
49 | + alunos_ids : alunos_duplicados | |
50 | + } | |
51 | + ); | |
52 | + | |
53 | + var options = { | |
54 | + url : url, | |
55 | + dataType : 'json', | |
56 | + success : function(response) { | |
57 | + $j('#adicionar_linha').hide(); | |
58 | + listaDadosAlunosUnificados(response); | |
59 | + } | |
60 | + }; | |
61 | + | |
62 | + getResources(options); | |
63 | +} | |
64 | + | |
65 | +function listaDadosAlunosUnificados(response) { | |
66 | + modalAvisoComplementaDadosAluno(); | |
67 | + removeExclusaoDeAlunos(); | |
68 | + disabilitaSearchInputs(); | |
69 | + removeItensVazios(); | |
70 | + removeBotaoMaisPessoas(); | |
71 | + montaTabelaDadosAluno(response); | |
72 | + adicionaBotoes(); | |
73 | + adicionaCheckboxConfirmacao(); | |
74 | + uniqueCheck(); | |
75 | + desabilitaBotaoUnificar(); | |
76 | +} | |
77 | + | |
78 | +function removeBotaoMaisPessoas() { | |
79 | + $j('#tabela_alunos tr:last').remove(); | |
80 | +} | |
81 | + | |
82 | +function removeItensVazios() { | |
83 | + $j('input[id^="aluno_duplicado["').each(function(id, input) { | |
84 | + let value = input.value.split(' ')[0]; | |
85 | + if (value.length === 0) { | |
86 | + tab_add_1.removeRow(this); | |
87 | + } | |
88 | + }); | |
89 | +} | |
90 | + | |
91 | +function montaTabelaDadosAluno(response) { | |
92 | + $j('tr#lista_dados_alunos_unificados').remove().animate({}); | |
93 | + $j('tr#unifica_aluno_titulo').remove().animate({}); | |
94 | + | |
95 | + $j('<tr id="lista_dados_alunos_unificados"></tr>').insertAfter($j('.tableDetalheLinhaSeparador').first().closest('tr')).hide().show('slow'); | |
96 | + $j(` | |
97 | + <tr id="unifica_aluno_titulo"> | |
98 | + <td colspan="2"> | |
99 | + <h2 class="unifica_pessoa_h2"> | |
100 | + Selecione o(a) aluno(a) que tenha os dados relevantes mais completos. | |
101 | + </h2> | |
102 | + </td> | |
103 | + </tr> | |
104 | + `).insertAfter($j('.tableDetalheLinhaSeparador').first().closest('tr')).hide().show('slow'); | |
105 | + | |
106 | + let html = ` | |
107 | + <td colspan="2"> | |
108 | + <table id="tabela_alunos_unificados"> | |
109 | + <tr class="tr_title"> | |
110 | + <td>Principal</td> | |
111 | + <td>Código</td> | |
112 | + <td>Inep</td> | |
113 | + <td>Nome</td> | |
114 | + <td>Nascimento</td> | |
115 | + <td>CPF</td> | |
116 | + <td>RG</td> | |
117 | + <td>Pessoa Mãe</td> | |
118 | + <td>Dados escolares</td> | |
119 | + <td>Ação</td> | |
120 | + </tr> | |
121 | + `; | |
122 | +// intranet/educar_aluno_det.php?cod_aluno=26 | |
123 | + response.alunos.each(function(aluno, id) { | |
124 | + html += '<tr id="' + aluno.codigo + '" class="linha_listagem">'; | |
125 | + html += '<td><input type="checkbox" class="check_principal" id="check_principal_' + aluno.codigo + '"</td>'; | |
126 | + html += '<td><a target="_new" href="/intranet/educar_aluno_det.php?cod_aluno=' + aluno.codigo + '">'+ aluno.codigo +'</a></td>'; | |
127 | + html += '<td><a target="_new" href="/intranet/educar_aluno_det.php?cod_aluno=' + aluno.codigo + '">'+ aluno.inep +'</a></td>'; | |
128 | + html += '<td><a target="_new" href="/intranet/educar_aluno_det.php?cod_aluno=' + aluno.codigo + '">'+ aluno.nome +'</a></td>'; | |
129 | + html += '<td><a target="_new" href="/intranet/educar_aluno_det.php?cod_aluno=' + aluno.codigo + '">'+ aluno.data_nascimento +'</a></td>'; | |
130 | + html += '<td><a target="_new" href="/intranet/educar_aluno_det.php?cod_aluno=' + aluno.codigo + '">'+ addMascara(aluno.cpf) +'</a></td>'; | |
131 | + html += '<td><a target="_new" href="/intranet/educar_aluno_det.php?cod_aluno=' + aluno.codigo + '">'+ aluno.rg +'</a></td>'; | |
132 | + html += '<td><a target="_new" href="/intranet/educar_aluno_det.php?cod_aluno=' + aluno.codigo + '">'+ aluno.mae_aluno +'</a></td>'; | |
133 | + html += '<td><a onclick="visualizarDadosAlunos(' + aluno.codigo + ', \'' + aluno.nome + '\')">Visualizar</a></td>'; | |
134 | + html += '<td><a class="link_remove" onclick="removeAluno(' + aluno.codigo + ')"><b><u>EXCLUIR</u></b></a></td>'; | |
135 | + html += '</tr>'; | |
136 | + }); | |
137 | + | |
138 | + html += '</table></td>'; | |
139 | + | |
140 | + $j('#lista_dados_alunos_unificados').html(html); | |
141 | +} | |
142 | + | |
143 | +function adicionaCheckboxConfirmacao() { | |
144 | + $j('<tr id="tr_confirma_dados_unificacao"></tr>').insertBefore($j('.linhaBotoes')); | |
145 | + | |
146 | + let htmlCheckbox = '<td colspan="2">' | |
147 | + htmlCheckbox += '<input onchange="confirmaAnalise()" id="check_confirma_dados_unificacao" type="checkbox" />'; | |
148 | + htmlCheckbox += '<label for="check_confirma_dados_unificacao">Confirmo a análise de que são a mesma pessoa, levando <br> em conta a possibilidade de gêmeos cadastrados.</label>'; | |
149 | + htmlCheckbox += '</td>'; | |
150 | + | |
151 | + $j('#tr_confirma_dados_unificacao').html(htmlCheckbox); | |
152 | +} | |
153 | + | |
154 | +function confirmaAnalise() { | |
155 | + let checked = $j('#check_confirma_dados_unificacao').is(':checked'); | |
156 | + | |
157 | + if (existeAlunoPrincipal() && checked) { | |
158 | + habilitaBotaoUnificar(); | |
159 | + return; | |
160 | + } | |
161 | + | |
162 | + if (checked) { | |
163 | + desabilitaBotaoUnificar(); | |
164 | + defaultModal('Você precisa definir um(a) aluno(a) como principal.'); | |
165 | + desabilitaConfirmarDadosUnificar(); | |
166 | + return; | |
167 | + } | |
168 | + | |
169 | + desabilitaBotaoUnificar(); | |
170 | + desabilitaConfirmarDadosUnificar(); | |
171 | +} | |
172 | + | |
173 | +function desabilitaConfirmarDadosUnificar() { | |
174 | + $j('#check_confirma_dados_unificacao').prop('checked', false); | |
175 | +} | |
176 | + | |
177 | +function addMascara(value) { | |
178 | + | |
179 | + if (value === 'Não consta') { | |
180 | + return value | |
181 | + } | |
182 | + | |
183 | + if (value.length <= 10) { // Quando o CPF tem 0 na frente o i-educar remove. | |
184 | + value = String(value).padStart(11, '0'); // '0010' | |
185 | + } | |
186 | + | |
187 | + return value.replace(/^(\d{3})(\d{3})(\d{3})(\d{2})/, "$1.$2.$3-$4"); | |
188 | +} | |
189 | + | |
190 | +function existeAlunoPrincipal() { | |
191 | + let existeAlunoPrincipal = false; | |
192 | + const checkbox = document.querySelectorAll('input.check_principal') | |
193 | + checkbox.forEach(element => { | |
194 | + if (element.checked == true) { | |
195 | + existeAlunoPrincipal = true; | |
196 | + } | |
197 | + }); | |
198 | + | |
199 | + return existeAlunoPrincipal; | |
200 | +} | |
201 | + | |
202 | +function habilitaBotaoUnificar() { | |
203 | + $j('#unifica_pessoa').prop('disabled', false); | |
204 | + $j('#unifica_pessoa').addClass('btn-green'); | |
205 | + $j('#unifica_pessoa').removeClass('btn-disabled'); | |
206 | +} | |
207 | + | |
208 | +function desabilitaBotaoUnificar() { | |
209 | + $j('#unifica_pessoa').prop('disabled', true); | |
210 | + $j('#unifica_pessoa').removeClass('btn-green'); | |
211 | + $j('#unifica_pessoa').addClass('btn-disabled'); | |
212 | +} | |
213 | + | |
214 | +function uniqueCheck() { | |
215 | + const checkbox = document.querySelectorAll('input.check_principal') | |
216 | + checkbox.forEach(element => { | |
217 | + element.addEventListener('click', handleClick.bind(event,checkbox)); | |
218 | + }); | |
219 | +} | |
220 | + | |
221 | +function handleClick(checkbox, event) { | |
222 | + checkbox.forEach(element => { | |
223 | + confirmaAnalise(); | |
224 | + if (event.currentTarget.id !== element.id) { | |
225 | + element.checked = false; | |
226 | + } | |
227 | + }); | |
228 | +} | |
229 | + | |
230 | +function visualizarDadosAlunos(codAluno, nomeAluno) { | |
231 | + var url = getResourceUrlBuilder.buildUrl( | |
232 | + '/module/Api/Aluno', | |
233 | + 'dadosMatriculasHistoricosAlunos', | |
234 | + { | |
235 | + aluno_id : codAluno | |
236 | + } | |
237 | + ); | |
238 | + | |
239 | + var options = { | |
240 | + url : url, | |
241 | + dataType : 'json', | |
242 | + success : function(response) { | |
243 | + modalMatriculasEHistoricos(response, nomeAluno); | |
244 | + } | |
245 | + }; | |
246 | + | |
247 | + getResources(options); | |
248 | +} | |
249 | + | |
250 | +function removeAluno(codAluno) { | |
251 | + if ($j('#tabela_alunos_unificados tr').length === 3) { | |
252 | + makeDialog({ | |
253 | + content: 'É necessário ao menos 2 alunos para a unificação, ao confirmar o processo vai ser reiniciado. Deseja prosseguir?', | |
254 | + title: 'Atenção!', | |
255 | + maxWidth: 860, | |
256 | + width: 860, | |
257 | + close: function () { | |
258 | + $j('#dialog-container').dialog('destroy'); | |
259 | + }, | |
260 | + buttons: [{ | |
261 | + text: 'Confirmar', | |
262 | + click: function () { | |
263 | + recarregar(); | |
264 | + $j('#dialog-container').dialog('destroy'); | |
265 | + } | |
266 | + }, { | |
267 | + text: 'Cancelar', | |
268 | + click: function () { | |
269 | + $j('#dialog-container').dialog('destroy'); | |
270 | + } | |
271 | + }] | |
272 | + }); | |
273 | + return; | |
274 | + } | |
275 | + | |
276 | + desabilitaConfirmarDadosUnificar(); | |
277 | + desabilitaBotaoUnificar(); | |
278 | + removeTr(codAluno); | |
279 | +} | |
280 | + | |
281 | +function removeTr(codAluno) { | |
282 | + let trClose = $j('#' + codAluno); | |
283 | + trClose.fadeOut(400, function() { | |
284 | + trClose.remove(); | |
285 | + }); | |
286 | +} | |
287 | + | |
288 | +function adicionaBotoesInicias() { | |
289 | + let htmlBotao = '<input type="button" class="botaolistagem" onclick="voltarParaLista();" value="Voltar" autocomplete="off">'; | |
290 | + htmlBotao += '<input type="button" id="btn_enviar" name="botaolistagem" onClick="carregaDadosAlunos();" value="Carregar dados" autoComplete="off">'; | |
291 | + $j('.linhaBotoes td').html(htmlBotao); | |
292 | +} | |
293 | + | |
294 | +function adicionaBotoes() { | |
295 | + let htmlBotao = '<input type="button" class="botaolistagem" onclick="voltarParaLista();" value="Voltar" autocomplete="off">'; | |
296 | + htmlBotao += '<input type="button" class="botaolistagem" onclick="recarregar();" value="Cancelar" autocomplete="off">'; | |
297 | + htmlBotao += '<input id="unifica_pessoa" type="button" class="botaolistagem" onclick="showConfirmationMessage();" value="Unificar alunos da lista" autocomplete="off">'; | |
298 | + $j('.linhaBotoes td').html(htmlBotao); | |
299 | +} | |
300 | + | |
301 | +function voltarParaLista() { | |
302 | + document.location.href = '/unificacao-aluno' | |
303 | +} | |
304 | + | |
305 | +function recarregar() { | |
306 | + document.location.reload(true); | |
307 | +} | |
308 | + | |
309 | +function removeExclusaoDeAlunos() { | |
310 | + $j('.tr_tabela_alunos td a').each(function(id, input) { | |
311 | + input.remove(); | |
312 | + }); | |
313 | +} | |
314 | + | |
315 | +function disabilitaSearchInputs() { | |
316 | + $j('input[id^="aluno_duplicado["').prop('disabled', true); | |
317 | +} | |
318 | + | |
319 | +function modalMatriculasEHistoricos(response, nomeAluno) { | |
320 | + let content = contentMatriculasEHistoricos(response); | |
321 | + makeDialog({ | |
322 | + content: content, | |
323 | + title: 'Dados escolares do aluno ' + nomeAluno, | |
324 | + width: '90%', | |
325 | + close: function () { | |
326 | + $j('#dialog-container').dialog('destroy'); | |
327 | + }, | |
328 | + buttons: [{ | |
329 | + text: 'Ok', | |
330 | + click: function () { | |
331 | + $j('#dialog-container').dialog('destroy'); | |
332 | + } | |
333 | + },] | |
334 | + }); | |
335 | +} | |
336 | + | |
337 | +function contentMatriculasEHistoricos(response) { | |
338 | + let html = ''; | |
339 | + html += htmlTabelaMatriculas(response.matriculas); | |
340 | + html += htmlTabelaHistoricos(response.historicos); | |
341 | + | |
342 | + return html; | |
343 | +} | |
344 | + | |
345 | +function htmlTabelaMatriculas(matriculas) { | |
346 | + let html = '<h4>Matrículas</h4>'; | |
347 | + html += '<table class="tabela-modal-dados-aluno">'; | |
348 | + html += '<tr class="tabela-modal-dados-aluno-titulo">'; | |
349 | + html += '<td>Ano</td>'; | |
350 | + html += '<td>Escola</td>'; | |
351 | + html += '<td>Curso</td>'; | |
352 | + html += '<td>Série</td>'; | |
353 | + html += '<td>Turma</td>'; | |
354 | + html += '</tr>'; | |
355 | + | |
356 | + matriculas.each(function(matricula, id) { | |
357 | + html += '<tr class="linha_listagem">'; | |
358 | + html += '<td>' + matricula.ano + '</td>'; | |
359 | + html += '<td>' + matricula.escola + '</td>'; | |
360 | + html += '<td>' + matricula.curso + '</td>'; | |
361 | + html += '<td>' + matricula.serie + '</td>'; | |
362 | + html += '<td>' + matricula.turma + '</td>'; | |
363 | + html += '</tr>'; | |
364 | + }); | |
365 | + | |
366 | + html += '</table>'; | |
367 | + | |
368 | + return html; | |
369 | +} | |
370 | + | |
371 | +function htmlTabelaHistoricos(historicos) { | |
372 | + let html = '<h4>Históricos escolares</h4>'; | |
373 | + html += '<table class="tabela-modal-dados-aluno">'; | |
374 | + html += '<tr class="tabela-modal-dados-aluno-titulo">'; | |
375 | + html += '<td>Ano</td>'; | |
376 | + html += '<td>Escola</td>'; | |
377 | + html += '<td>Curso</td>'; | |
378 | + html += '<td>Serie</td>'; | |
379 | + html += '<td>Situação</td>'; | |
380 | + html += '</tr>'; | |
381 | + | |
382 | + historicos.each(function(historico, id) { | |
383 | + html += '<tr class="linha_listagem">'; | |
384 | + html += '<td>' + historico.ano + '</td>'; | |
385 | + html += '<td>' + historico.escola + '</td>'; | |
386 | + html += '<td>' + historico.curso + '</td>'; | |
387 | + html += '<td>' + historico.serie + '</td>'; | |
388 | + html += '<td>' + historico.situacao + '</td>'; | |
389 | + html += '</tr>'; | |
390 | + }); | |
391 | + | |
392 | + html += '</table>'; | |
393 | + | |
394 | + return html; | |
395 | +} | |
396 | + | |
397 | +function defaultModal(message) { | |
398 | + makeDialog({ | |
399 | + content: message, | |
400 | + title: 'Atenção!', | |
401 | + maxWidth: 400, | |
402 | + width: 400, | |
403 | + close: function () { | |
404 | + $j('#dialog-container').dialog('destroy'); | |
405 | + }, | |
406 | + buttons: [{ | |
407 | + text: 'Ok', | |
408 | + click: function () { | |
409 | + $j('#dialog-container').dialog('destroy'); | |
410 | + } | |
411 | + },] | |
412 | + }); | |
413 | +} | |
414 | + | |
415 | +function ajustaTabelaDeAlunosUnificados() { | |
416 | + $j('a[id^="link_remove["').empty().text('EXCLUIR'); | |
417 | + $j('input[id^="aluno_duplicado["').attr("placeholder", "Informe nome ou código do(a) aluno(a)"); | |
418 | +} | |
2 | 419 | |
3 | 420 | var handleSelect = function(event, ui){ |
4 | 421 | $j(event.target).val(ui.item.label); |
... | ... | @@ -14,6 +431,82 @@ |
14 | 431 | }); |
15 | 432 | }; |
16 | 433 | |
434 | +function showConfirmationMessage() { | |
435 | + makeDialog({ | |
436 | + content: 'Você está realizando uma unificação de alunos. Deseja continuar?', | |
437 | + title: 'Atenção!', | |
438 | + maxWidth: 860, | |
439 | + width: 860, | |
440 | + close: function () { | |
441 | + $j('#dialog-container').dialog('destroy'); | |
442 | + }, | |
443 | + buttons: [{ | |
444 | + text: 'Confirmar', | |
445 | + click: function () { | |
446 | + enviaDados(); | |
447 | + $j('#dialog-container').dialog('destroy'); | |
448 | + } | |
449 | + }, { | |
450 | + text: 'Cancelar', | |
451 | + click: function () { | |
452 | + $j('#dialog-container').dialog('destroy'); | |
453 | + } | |
454 | + }] | |
455 | + }); | |
456 | +} | |
457 | + | |
458 | + function enviaDados() { | |
459 | + | |
460 | + let dados = []; | |
461 | + const formData = document.createElement('form'); | |
462 | + formData.method = 'post'; | |
463 | + formData.action = 'educar_unifica_aluno.php'; | |
464 | + | |
465 | + $j('#tabela_alunos_unificados .linha_listagem').each(function(id, input) { | |
466 | + let isChecked = $j('#check_principal_'+ input.id).is(':checked'); | |
467 | + let alunoParaUnificar = {}; | |
468 | + alunoParaUnificar.codAluno = input.id; | |
469 | + alunoParaUnificar.aluno_principal = isChecked; | |
470 | + dados.push(alunoParaUnificar); | |
471 | + }); | |
472 | + | |
473 | + const acao = document.createElement('input'); | |
474 | + acao.type = 'hidden'; | |
475 | + acao.name = 'tipoacao'; | |
476 | + acao.value = 'Novo'; | |
477 | + formData.appendChild(acao); | |
478 | + | |
479 | + const hiddenField = document.createElement('input'); | |
480 | + hiddenField.type = 'hidden'; | |
481 | + hiddenField.name = 'alunos'; | |
482 | + hiddenField.value = JSON.stringify(dados); | |
483 | + formData.appendChild(hiddenField); | |
484 | + | |
485 | + document.body.appendChild(formData); | |
486 | + formData.submit(); | |
487 | + } | |
488 | + | |
489 | +function modalAvisoComplementaDadosAluno() { | |
490 | + makeDialog({ | |
491 | + content: `Para complementar os dados do(a) aluno(a) que selecionou como principal, | |
492 | + é necessário fazê-lo manualmente editando os dados do(a) mesmo(a) antes da Unificação de Alunos. | |
493 | + <b>Caso não faça essa complementação, os dados dos alunos não selecionadas como principal serão perdidos, | |
494 | + exceto matrículas e dados de histórico.<b>`, | |
495 | + title: 'Atenção!', | |
496 | + maxWidth: 860, | |
497 | + width: 860, | |
498 | + close: function () { | |
499 | + $j('#dialog-container').dialog('destroy'); | |
500 | + }, | |
501 | + buttons: [{ | |
502 | + text: 'Ok', | |
503 | + click: function () { | |
504 | + $j('#dialog-container').dialog('destroy'); | |
505 | + } | |
506 | + },] | |
507 | + }); | |
508 | +} | |
509 | + | |
17 | 510 | function setAutoComplete() { |
18 | 511 | $j.each($j('input[id^="aluno_duplicado"]'), function(index, field) { |
19 | 512 | |
... | ... | @@ -37,7 +530,26 @@ |
37 | 530 | setAutoComplete(); |
38 | 531 | }); |
39 | 532 | |
40 | - $j('#btn_enviar').val('Unificar'); | |
533 | +function makeDialog(params) { | |
534 | + params.closeOnEscape = false; | |
535 | + params.draggable = false; | |
536 | + params.modal = true; | |
537 | + | |
538 | + var container = $j('#dialog-container'); | |
41 | 539 | |
540 | + if (container.length < 1) { | |
541 | + $j('body').append('<div id="dialog-container" style="width: 500px;"></div>'); | |
542 | + container = $j('#dialog-container'); | |
543 | + } | |
42 | 544 | |
545 | + if (container.hasClass('ui-dialog-content')) { | |
546 | + container.dialog('destroy'); | |
547 | + } | |
43 | 548 | |
549 | + container.empty(); | |
550 | + container.html(params.content); | |
551 | + | |
552 | + delete params['content']; | |
553 | + | |
554 | + container.dialog(params); | |
555 | +} | ... | ... |
ieducar/intranet/scripts/extra/educar-unifica-pessoa.js
1 | +adicionaMaisUmaLinhaNaTabela(); | |
2 | +ajustaTabelaDePessoasUnificadas(); | |
3 | +ajustarUiBotao(); | |
1 | 4 | |
5 | +function ajustarUiBotao () { | |
6 | + $j('#btn_add_tab_add_1').addClass('button_center'); | |
7 | + document.getElementById("btn_add_tab_add_1").lastChild.textContent = 'ADICIONAR MAIS PESSOAS'; | |
8 | +} | |
9 | + | |
10 | +$j('#btn_add_tab_add_1').click(function() { | |
11 | + ajustaTabelaDePessoasUnificadas(); | |
12 | + $j('a[id^="link_remove["').css('font-weight', 'bold'); | |
13 | + $j('a[id^="link_remove["').css('text-decoration', 'underline'); | |
14 | +}); | |
15 | + | |
16 | +let $quantidadeDeVinculosComAlunos = 0; | |
17 | +let $quantidadeDeVinculosComServidores = 0; | |
18 | + | |
19 | +function adicionaMaisUmaLinhaNaTabela() { | |
20 | + tab_add_1.addRow(); | |
21 | +} | |
22 | + | |
23 | +function ajustaTabelaDePessoasUnificadas() { | |
24 | + $j('a[id^="link_remove["').empty().text('EXCLUIR'); | |
25 | + $j('input[id^="pessoa_duplicada["').attr("placeholder", "Informe nome, código, CPF ou RG da pessoa"); | |
26 | +} | |
27 | + | |
28 | +function carregaDadosPessoas() { | |
29 | + let pessoas_duplicadas = []; | |
30 | + | |
31 | + $j('input[id^="pessoa_duplicada["').each(function(id, input) { | |
32 | + let value = input.value.split(' ')[0]; | |
33 | + if (value.length !== 0) { | |
34 | + pessoas_duplicadas.push(value); | |
35 | + } | |
36 | + }); | |
37 | + | |
38 | + var url = getResourceUrlBuilder.buildUrl( | |
39 | + '/module/Api/Pessoa', | |
40 | + 'dadosUnificacaoPessoa', | |
41 | + { | |
42 | + pessoas_ids : pessoas_duplicadas | |
43 | + } | |
44 | + ); | |
45 | + | |
46 | + var options = { | |
47 | + url : url, | |
48 | + dataType : 'json', | |
49 | + success : function(response) { | |
50 | + if (!exiteMaisDeUmaPessoa()) { | |
51 | + modalInformeMaisPessoas(); | |
52 | + return; | |
53 | + } | |
54 | + | |
55 | + if (exitemPessoasDuplicadas()) { | |
56 | + modalAjustePessoasUnificadas(); | |
57 | + return; | |
58 | + } | |
59 | + | |
60 | + $j('#adicionar_linha').hide(); | |
61 | + listaDadosPessoasUnificadas(response); | |
62 | + } | |
63 | + }; | |
64 | + | |
65 | + getResources(options); | |
66 | +} | |
67 | + | |
68 | +function pegaPessoasDaTabela() { | |
69 | + let pessoas_duplicadas = []; | |
70 | + $j('input[id^="pessoa_duplicada["').each(function(id, input) { | |
71 | + pessoas_duplicadas.push(input.value.split(' ')[0]); | |
72 | + }); | |
73 | + | |
74 | + return pessoas_duplicadas | |
75 | +} | |
76 | + | |
77 | +function pegarPessoasParaUnificar() { | |
78 | + let pessoas_para_unificar = []; | |
79 | + $j('#tabela_pessoas_unificadas .linha_listagem').each(function(id, input) { | |
80 | + pessoas_para_unificar.push(input.id); | |
81 | + }); | |
82 | + return pessoas_para_unificar; | |
83 | +} | |
84 | + | |
85 | +function recarregaListaDePessoas(pessoas) { | |
86 | + let url = getResourceUrlBuilder.buildUrl( | |
87 | + '/module/Api/Pessoa', | |
88 | + 'dadosUnificacaoPessoa', | |
89 | + { | |
90 | + pessoas_ids : pessoas | |
91 | + } | |
92 | + ); | |
93 | + | |
94 | + let options = { | |
95 | + url : url, | |
96 | + dataType : 'json', | |
97 | + success : function(response) { | |
98 | + montaTabela(response); | |
99 | + apresentaObservacoes(response.pessoas); | |
100 | + uniqueCheck(); | |
101 | + $j('#check_confirma_dados_unificacao').prop('checked', false); | |
102 | + } | |
103 | + }; | |
104 | + | |
105 | + getResources(options); | |
106 | +} | |
107 | + | |
108 | +function exiteMaisDeUmaPessoa() { | |
109 | + let pessoas = []; | |
110 | + | |
111 | + $j('input[id^="pessoa_duplicada["').each(function(id, input) { | |
112 | + idpes = input.value.split(' ')[0]; | |
113 | + if (idpes) { | |
114 | + pessoas.push(idpes); | |
115 | + } | |
116 | + }); | |
117 | + | |
118 | + return pessoas.length > 1; | |
119 | +} | |
120 | + | |
121 | +function modalInformeMaisPessoas() { | |
122 | + makeDialog({ | |
123 | + content: 'Informe pelo menos duas pessoas para unificar.', | |
124 | + title: 'Atenção!', | |
125 | + maxWidth: 400, | |
126 | + width: 400, | |
127 | + close: function () { | |
128 | + $j('#dialog-container').dialog('destroy'); | |
129 | + }, | |
130 | + buttons: [{ | |
131 | + text: 'Ok', | |
132 | + click: function () { | |
133 | + $j('#dialog-container').dialog('destroy'); | |
134 | + } | |
135 | + },] | |
136 | + }); | |
137 | +} | |
138 | + | |
139 | +function exitemPessoasDuplicadas() { | |
140 | + let pessoas = []; | |
141 | + $j('input[id^="pessoa_duplicada["').each(function(id, input) { | |
142 | + let value = input.value.split(' ')[0]; | |
143 | + if (value.length !== 0) { | |
144 | + pessoas.push(value); | |
145 | + } | |
146 | + }); | |
147 | + | |
148 | + let pessoasSemDuplicidade = [...new Set(pessoas)]; | |
149 | + | |
150 | + return pessoas.length !== pessoasSemDuplicidade.length; | |
151 | +} | |
152 | + | |
153 | +function modalAjustePessoasUnificadas() { | |
154 | + makeDialog({ | |
155 | + content: 'Selecione pessoas diferentes.', | |
156 | + title: 'Atenção!', | |
157 | + maxWidth: 400, | |
158 | + width: 400, | |
159 | + close: function () { | |
160 | + $j('#dialog-container').dialog('destroy'); | |
161 | + }, | |
162 | + buttons: [{ | |
163 | + text: 'Ok', | |
164 | + click: function () { | |
165 | + $j('#dialog-container').dialog('destroy'); | |
166 | + } | |
167 | + },] | |
168 | + }); | |
169 | +} | |
170 | + | |
171 | +function listaDadosPessoasUnificadas(response) { | |
172 | + modalAvisoComplementaDadosPessoa(); | |
173 | + removeExclusaoDePessoas(); | |
174 | + removeItensVazios(); | |
175 | + disabilitaSearchInputs(); | |
176 | + removeBotaoMaisPessoas(); | |
177 | + montaTabela(response); | |
178 | + adicionaSeparador(); | |
179 | + apresentaObservacoes(response.pessoas); | |
180 | + adicionaCheckboxConfirmacao(); | |
181 | + adicionaBotoes(); | |
182 | + uniqueCheck(); | |
183 | + desabilitaBotaoUnificar(); | |
184 | +} | |
185 | + | |
186 | +function removeBotaoMaisPessoas() { | |
187 | + $j('#tabela_pessoas tr:last').remove(); | |
188 | +} | |
189 | + | |
190 | +function removeExclusaoDePessoas() { | |
191 | + $j('.tr_tabela_pessoas td a').each(function(id, input) { | |
192 | + input.remove(); | |
193 | + }); | |
194 | +} | |
195 | + | |
196 | +function removeItensVazios() { | |
197 | + $j('input[id^="pessoa_duplicada["').each(function(id, input) { | |
198 | + let value = input.value.split(' ')[0]; | |
199 | + if (value.length === 0) { | |
200 | + tab_add_1.removeRow(this); | |
201 | + } | |
202 | + }); | |
203 | +} | |
204 | + | |
205 | +function disabilitaSearchInputs() { | |
206 | + $j('input[id^="pessoa_duplicada["').prop('disabled', true); | |
207 | +} | |
208 | + | |
209 | +function confirmaAnalise() { | |
210 | + let checked = $j('#check_confirma_dados_unificacao').is(':checked'); | |
211 | + | |
212 | + if (existePessoaPrincipal() && checked) { | |
213 | + if ($quantidadeDeVinculosComAlunos <= 1) { | |
214 | + habilitaBotaoUnificar(); | |
215 | + } | |
216 | + | |
217 | + return; | |
218 | + } | |
219 | + | |
220 | + if (checked) { | |
221 | + desabilitaBotaoUnificar(); | |
222 | + removeCheckConfirmaDados() | |
223 | + modalExigePessoaPrincipal(); | |
224 | + return; | |
225 | + } | |
226 | + | |
227 | + desabilitaBotaoUnificar(); | |
228 | +} | |
229 | + | |
230 | +function habilitaBotaoUnificar() { | |
231 | + $j('#unifica_pessoa').prop('disabled', false); | |
232 | + $j('#unifica_pessoa').addClass('btn-green'); | |
233 | + $j('#unifica_pessoa').removeClass('btn-disabled'); | |
234 | +} | |
235 | + | |
236 | +function desabilitaBotaoUnificar() { | |
237 | + $j('#unifica_pessoa').prop('disabled', true); | |
238 | + $j('#unifica_pessoa').removeClass('btn-green'); | |
239 | + $j('#unifica_pessoa').addClass('btn-disabled'); | |
240 | +} | |
241 | + | |
242 | +function existePessoaPrincipal() { | |
243 | + let existePessoaPrincipal = false; | |
244 | + const checkbox = document.querySelectorAll('input.check_principal') | |
245 | + checkbox.forEach(element => { | |
246 | + if (element.checked == true) { | |
247 | + existePessoaPrincipal = true; | |
248 | + } | |
249 | + }); | |
250 | + | |
251 | + return existePessoaPrincipal; | |
252 | +} | |
253 | + | |
254 | +function removeCheckConfirmaDados() { | |
255 | + $j('#check_confirma_dados_unificacao').prop('checked', false); | |
256 | +} | |
257 | + | |
258 | +function modalExigePessoaPrincipal() { | |
259 | + makeDialog({ | |
260 | + content: 'Você precisa definir uma pessoa como principal.', | |
261 | + title: 'Atenção!', | |
262 | + maxWidth: 860, | |
263 | + width: 860, | |
264 | + close: function () { | |
265 | + $j('#dialog-container').dialog('destroy'); | |
266 | + }, | |
267 | + buttons: [{ | |
268 | + text: 'Ok', | |
269 | + click: function () { | |
270 | + $j('#dialog-container').dialog('destroy'); | |
271 | + } | |
272 | + },] | |
273 | + }); | |
274 | +} | |
275 | + | |
276 | +function modalAvisoComplementaDadosPessoa() { | |
277 | + makeDialog({ | |
278 | + content: `Para complementar os dados da pessoa que selecionou como principal, | |
279 | + é necessário fazê-lo manualmente editando os dados da pessoa física antes da Unificação de Pessoas. | |
280 | + <b>Caso não faça essa complementação, os dados das pessoas físicas não selecionadas como principal serão perdidos.</b>`, | |
281 | + title: 'Atenção!', | |
282 | + maxWidth: 860, | |
283 | + width: 860, | |
284 | + close: function () { | |
285 | + $j('#dialog-container').dialog('destroy'); | |
286 | + }, | |
287 | + buttons: [{ | |
288 | + text: 'Ok', | |
289 | + click: function () { | |
290 | + $j('#dialog-container').dialog('destroy'); | |
291 | + } | |
292 | + },] | |
293 | + }); | |
294 | +} | |
295 | + | |
296 | +function adicionaBotoes() { | |
297 | + let htmlBotao = '<input type="button" class="botaolistagem" onclick="voltar();" value="Voltar" autocomplete="off">'; | |
298 | + htmlBotao += '<input id="unifica_pessoa" type="button" class="botaolistagem" onclick="showConfirmationMessage();" value="Unificar pessoas da lista" autocomplete="off">'; | |
299 | + $j('.linhaBotoes td').html(htmlBotao); | |
300 | +} | |
301 | + | |
302 | +function adicionaSeparador() { | |
303 | + $j('<tr class="lista_pessoas_unificadas_hr"><td class="tableDetalheLinhaSeparador" colspan="2"></td></tr>').insertAfter($j('#lista_dados_pessoas_unificadas')); | |
304 | +} | |
305 | + | |
306 | +function adicionaCheckboxConfirmacao() { | |
307 | + $j('<tr id="tr_confirma_dados_unificacao"></tr>').insertBefore($j('.linhaBotoes')); | |
308 | + | |
309 | + let htmlCheckbox = '<td colspan="2">' | |
310 | + htmlCheckbox += '<input onchange="confirmaAnalise()" id="check_confirma_dados_unificacao" type="checkbox" />'; | |
311 | + htmlCheckbox += '<label for="check_confirma_dados_unificacao">Confirmo a análise de que são a mesma pessoa, levando <br> em conta a possibilidade de gêmeos cadastrados.</label>'; | |
312 | + htmlCheckbox += '</td>'; | |
313 | + | |
314 | + $j('#tr_confirma_dados_unificacao').html(htmlCheckbox); | |
315 | +} | |
316 | + | |
317 | +function montaTabela(response) { | |
318 | + $j('tr#lista_dados_pessoas_unificadas').remove().animate({}); | |
319 | + $j('tr#unifica_pessoa_titulo').remove().animate({}); | |
320 | + | |
321 | + $j('<tr id="lista_dados_pessoas_unificadas"></tr>').insertAfter($j('.tableDetalheLinhaSeparador').first().closest('tr')).hide().show('slow'); | |
322 | + $j(` | |
323 | + <tr id="unifica_pessoa_titulo"> | |
324 | + <td colspan="2"> | |
325 | + <h2 class="unifica_pessoa_h2"> | |
326 | + Seleciona a pessoa que tenha preferencialmente vínculo(s) e com dados relavantes mais completos. | |
327 | + </h2> | |
328 | + </td> | |
329 | + </tr> | |
330 | + `).insertAfter($j('.tableDetalheLinhaSeparador').first().closest('tr')).hide().show('slow'); | |
331 | + | |
332 | + let html = ` | |
333 | + <td colspan="2"> | |
334 | + <table id="tabela_pessoas_unificadas"> | |
335 | + <tr class="tr_title"> | |
336 | + <td>Principal</td> | |
337 | + <td>Vinculo</td> | |
338 | + <td>Nome</td> | |
339 | + <td>Nascimento</td> | |
340 | + <td>Sexo</td> | |
341 | + <td>CPF</td> | |
342 | + <td>RG</td> | |
343 | + <td>Pessoa Mãe</td> | |
344 | + <td>Ação</td> | |
345 | + </tr> | |
346 | + `; | |
347 | + | |
348 | + response.pessoas.each(function(value, id) { | |
349 | + html += '<tr id="' + value.idpes + '" class="linha_listagem">'; | |
350 | + html += '<td><input onclick="validaCheckPessoaPrincipal(this)" type="checkbox" class="check_principal" id="check_principal_' + value.idpes + '"</td>'; | |
351 | + html += '<td id="vinculo_'+ value.idpes +'"><a target="_new" href="/intranet/atendidos_det.php?cod_pessoa=' + value.idpes + '">'+ value.vinculo +'</a></td>'; | |
352 | + html += '<td><a target="_new" href="/intranet/atendidos_det.php?cod_pessoa=' + value.idpes + '">'+ value.nome +'</a></td>'; | |
353 | + html += '<td><a target="_new" href="/intranet/atendidos_det.php?cod_pessoa=' + value.idpes + '">'+ value.data_nascimento +'</a></td>'; | |
354 | + html += '<td><a target="_new" href="/intranet/atendidos_det.php?cod_pessoa=' + value.idpes + '">'+ value.sexo +'</a></td>'; | |
355 | + html += '<td><a target="_new" href="/intranet/atendidos_det.php?cod_pessoa=' + value.idpes + '">'+ addMascara(value.cpf) +'</a></td>'; | |
356 | + html += '<td><a target="_new" href="/intranet/atendidos_det.php?cod_pessoa=' + value.idpes + '">'+ value.rg +'</a></td>'; | |
357 | + html += '<td><a target="_new" href="/intranet/atendidos_det.php?cod_pessoa=' + value.idpes + '">'+ value.pessoa_mae +'</a></td>'; | |
358 | + html += '<td><a class="link_remove" onclick="removePessoa(' + value.idpes + ')"><b><u>EXCLUIR</u></b></a></td>'; | |
359 | + html += '</tr>'; | |
360 | + }); | |
361 | + | |
362 | + html += '</table></td>'; | |
363 | + | |
364 | + $j('#lista_dados_pessoas_unificadas').html(html); | |
365 | +} | |
366 | + | |
367 | +function addMascara(value) { | |
368 | + if (value === 'Não consta') { | |
369 | + return value | |
370 | + } | |
371 | + | |
372 | + if (value.length <= 10) { // Quando o CPF tem 0 na frente o i-educar remove. | |
373 | + value = String(value).padStart(11, '0'); // '0010' | |
374 | + } | |
375 | + | |
376 | + return value.replace(/^(\d{3})(\d{3})(\d{3})(\d{2})/, "$1.$2.$3-$4"); | |
377 | +} | |
378 | + | |
379 | +function uniqueCheck() { | |
380 | + const checkbox = document.querySelectorAll('input.check_principal') | |
381 | + checkbox.forEach(element => { | |
382 | + element.addEventListener('click', handleClick.bind(event,checkbox)); | |
383 | + }); | |
384 | +} | |
385 | + | |
386 | +function validaCheckPessoaPrincipal(element) { | |
387 | + let idpes = element.id.replace(/[^\d]/g, ''); | |
388 | + | |
389 | + if (! $j('#' + element.id).is(':checked')) { | |
390 | + return; | |
391 | + } | |
392 | + | |
393 | + if ($j('#vinculo_' + idpes).text() !== 'Sem vínculo') { | |
394 | + return; | |
395 | + } | |
396 | + | |
397 | + if ($quantidadeDeVinculosComAlunos > 0 || $quantidadeDeVinculosComServidores > 0) { | |
398 | + desabilitaBotaoUnificar(); | |
399 | + modalInformePessoaPrincipalComVinculo(element.id); | |
400 | + } | |
401 | +} | |
402 | + | |
403 | +function modalInformePessoaPrincipalComVinculo(checkId) { | |
404 | + makeDialog({ | |
405 | + content: 'Seleciona uma pessoa com vínculo como principal.', | |
406 | + title: 'Atenção!', | |
407 | + maxWidth: 400, | |
408 | + width: 400, | |
409 | + close: function () { | |
410 | + desabilitaBotaoUnificar(); | |
411 | + removeCheckConfirmaDados() | |
412 | + $j('#'+checkId).prop('checked', false); | |
413 | + $j('#dialog-container').dialog('destroy'); | |
414 | + }, | |
415 | + buttons: [{ | |
416 | + text: 'Ok', | |
417 | + click: function () { | |
418 | + desabilitaBotaoUnificar(); | |
419 | + removeCheckConfirmaDados() | |
420 | + $j('#'+checkId).prop('checked', false); | |
421 | + $j('#dialog-container').dialog('destroy'); | |
422 | + } | |
423 | + },] | |
424 | + }); | |
425 | +} | |
426 | + | |
427 | + | |
428 | +function handleClick(checkbox, event) { | |
429 | + checkbox.forEach(element => { | |
430 | + confirmaAnalise(); | |
431 | + if (event.currentTarget.id !== element.id) { | |
432 | + element.checked = false; | |
433 | + } | |
434 | + }); | |
435 | +} | |
436 | + | |
437 | +function removePessoa(idpes) { | |
438 | + if ($j('#tabela_pessoas_unificadas tr').length === 3) { | |
439 | + confirmaRemocaoPessoaUnificacao(); | |
440 | + return; | |
441 | + } | |
442 | + removeTr(idpes); | |
443 | +} | |
444 | + | |
445 | +function removeTr(idpes) { | |
446 | + let trClose = $j('#' + idpes); | |
447 | + trClose.fadeOut(400, function() { | |
448 | + trClose.remove(); | |
449 | + recarregaListaDePessoas(pegarPessoasParaUnificar()) | |
450 | + desabilitaConfirmarDadosUnificar(); | |
451 | + desabilitaBotaoUnificar(); | |
452 | + }); | |
453 | +} | |
454 | + | |
455 | +function confirmaRemocaoPessoaUnificacao() { | |
456 | + makeDialog({ | |
457 | + content: 'É necessário ao menos 2 pessoas para a unificação, ao confirmar o processo vai ser reiniciado. Deseja prosseguir?', | |
458 | + title: 'Atenção!', | |
459 | + maxWidth: 860, | |
460 | + width: 860, | |
461 | + close: function () { | |
462 | + $j('#dialog-container').dialog('destroy'); | |
463 | + }, | |
464 | + buttons: [{ | |
465 | + text: 'Confirmar', | |
466 | + click: function () { | |
467 | + voltar(); | |
468 | + $j('#dialog-container').dialog('destroy'); | |
469 | + } | |
470 | + }, { | |
471 | + text: 'Cancelar', | |
472 | + click: function () { | |
473 | + $j('#dialog-container').dialog('destroy'); | |
474 | + } | |
475 | + }] | |
476 | + }); | |
477 | +} | |
478 | + | |
479 | +function contabilizaVinculos(pessoas) { | |
480 | + let alunos = 0; | |
481 | + let servidores = 0; | |
482 | + | |
483 | + pessoas.each(function(value, id) { | |
484 | + let vinculos = value.vinculo.split(', '); | |
485 | + | |
486 | + if ($j.inArray('Aluno(a)',vinculos) != -1) { | |
487 | + alunos++; | |
488 | + } | |
489 | + | |
490 | + if ($j.inArray('Servidor(a)',vinculos) != -1) { | |
491 | + servidores++; | |
492 | + } | |
493 | + }); | |
494 | + | |
495 | + $quantidadeDeVinculosComAlunos = alunos; | |
496 | + $quantidadeDeVinculosComServidores = servidores; | |
497 | +} | |
498 | + | |
499 | +function apresentaObservacoes(pessoas) { | |
500 | + $j('#tr_observacoes').remove(); | |
2 | 501 | |
3 | - var handleSelect = function(event, ui){ | |
502 | + contabilizaVinculos(pessoas); | |
503 | + | |
504 | + if ($quantidadeDeVinculosComAlunos > 1) { | |
505 | + $j('<tr id="tr_observacoes"></tr>').insertAfter($j('.lista_pessoas_unificadas_hr')); | |
506 | + htmlApresentaObservacoes(); | |
507 | + return; | |
508 | + } | |
509 | +} | |
510 | + | |
511 | +function htmlApresentaObservacoes() { | |
512 | + html = ` | |
513 | + <td colspan="2"> | |
514 | + <div> | |
515 | + Consta mais de um vínculo de aluno(a) na lista de pessoas a serem unificadas, | |
516 | + <a href="/intranet/educar_unifica_aluno.php" target="_new"><b>clique aqui</b></a> para fazer a Unificação de alunos antes de unificar as pessoas físicas. | |
517 | + Após a unificação clique no botão abaixo para recarregar a listagem de pessoas. <br> | |
518 | + <a id="recarregar_lista" onclick="recarregaListaDePessoas(pegaPessoasDaTabela())"><b>Recarregar lista</br></a> | |
519 | + </div> | |
520 | + </td> | |
521 | + `; | |
522 | + | |
523 | + $j('#tr_observacoes').html(html); | |
524 | +} | |
525 | + | |
526 | +function voltar() { | |
527 | + document.location.reload(true); | |
528 | +} | |
529 | + | |
530 | +var handleSelect = function(event, ui){ | |
4 | 531 | $j(event.target).val(ui.item.label); |
5 | 532 | return false; |
6 | 533 | }; |
... | ... | @@ -37,7 +564,7 @@ |
37 | 564 | setAutoComplete(); |
38 | 565 | }); |
39 | 566 | |
40 | - $j('#btn_enviar').val('Unificar'); | |
567 | + $j('#btn_enviar').val('Carregar dados'); | |
41 | 568 | |
42 | 569 | function showConfirmationMessage() { |
43 | 570 | makeDialog({ |
... | ... | @@ -51,7 +578,7 @@ |
51 | 578 | buttons: [{ |
52 | 579 | text: 'Confirmar', |
53 | 580 | click: function () { |
54 | - acao(); | |
581 | + enviaDados(); | |
55 | 582 | $j('#dialog-container').dialog('destroy'); |
56 | 583 | } |
57 | 584 | }, { |
... | ... | @@ -63,17 +590,52 @@ |
63 | 590 | }); |
64 | 591 | } |
65 | 592 | |
593 | + function enviaDados() { | |
594 | + | |
595 | + let dados = []; | |
596 | + const formData = document.createElement('form'); | |
597 | + formData.method = 'post'; | |
598 | + formData.action = 'educar_unifica_pessoa.php'; | |
599 | + | |
600 | + $j('#tabela_pessoas_unificadas .linha_listagem').each(function(id, input) { | |
601 | + let isChecked = $j('#check_principal_'+ input.id).is(':checked'); | |
602 | + let pessoaParaUnificar = {}; | |
603 | + pessoaParaUnificar.idpes = input.id; | |
604 | + pessoaParaUnificar.pessoa_principal = isChecked; | |
605 | + dados.push(pessoaParaUnificar); | |
606 | + }); | |
607 | + | |
608 | + const acao = document.createElement('input'); | |
609 | + acao.type = 'hidden'; | |
610 | + acao.name = 'tipoacao'; | |
611 | + acao.value = 'Novo'; | |
612 | + formData.appendChild(acao); | |
613 | + | |
614 | + const hiddenField = document.createElement('input'); | |
615 | + hiddenField.type = 'hidden'; | |
616 | + hiddenField.name = 'pessoas'; | |
617 | + hiddenField.value = JSON.stringify(dados); | |
618 | + formData.appendChild(hiddenField); | |
619 | + | |
620 | + document.body.appendChild(formData); | |
621 | + formData.submit(); | |
622 | + } | |
623 | + | |
66 | 624 | function makeDialog(params) { |
67 | - var container = $j('#dialog-container'); | |
625 | + params.closeOnEscape = false; | |
626 | + params.draggable = false; | |
627 | + params.modal = true; | |
628 | + | |
629 | + let container = $j('#dialog-container'); | |
68 | 630 | |
69 | 631 | if (container.length < 1) { |
70 | - $j('body').append('<div id="dialog-container" style="width: 500px;"></div>'); | |
71 | - container = $j('#dialog-container'); | |
72 | -} | |
632 | + $j('body').append('<div id="dialog-container" style="width: 500px;"></div>'); | |
633 | + container = $j('#dialog-container'); | |
634 | + } | |
73 | 635 | |
74 | 636 | if (container.hasClass('ui-dialog-content')) { |
75 | - container.dialog('destroy'); | |
76 | -} | |
637 | + container.dialog('destroy'); | |
638 | + } | |
77 | 639 | |
78 | 640 | container.empty(); |
79 | 641 | container.html(params.content); | ... | ... |
ieducar/intranet/styles/custom.css
... | ... | @@ -900,7 +900,7 @@ table.calendario td a{ |
900 | 900 | font-stretch: normal; |
901 | 901 | color: #596066; |
902 | 902 | padding: 8px !important; |
903 | - margin-right: 4px 10px 4px 0px; | |
903 | + margin-right: 4px; | |
904 | 904 | } |
905 | 905 | |
906 | 906 | .ui-dialog label{ |
... | ... | @@ -1462,6 +1462,12 @@ a.btn-detalhes { |
1462 | 1462 | padding: 5px; |
1463 | 1463 | } |
1464 | 1464 | |
1465 | +.button_center { | |
1466 | + display: flex !important; | |
1467 | + align-items: center !important; | |
1468 | + justify-content: center !important; | |
1469 | +} | |
1470 | + | |
1465 | 1471 | .btn-disabled#btn_enviar { |
1466 | 1472 | background: rgb(233, 240, 248) !important; |
1467 | 1473 | cursor: not-allowed; | ... | ... |
ieducar/lib/App/Unificacao/Aluno.php
... | ... | @@ -10,15 +10,15 @@ class App_Unificacao_Aluno |
10 | 10 | { |
11 | 11 | self::validaParametros($codAlunoPrincipal, $codAlunos, $codPessoa); |
12 | 12 | |
13 | - $maxSequencialAlunoPrincipal = LegacySchoolHistory::query() | |
14 | - ->where('ref_cod_aluno', $codAlunoPrincipal) | |
15 | - ->max('sequencial') ?? 0; | |
16 | - | |
17 | 13 | $codAlunosString = implode(',', $codAlunos); |
18 | 14 | |
19 | 15 | self::logData($codAlunos, $unificationId); |
20 | 16 | |
21 | 17 | foreach ($codAlunos as $codAluno) { |
18 | + $maxSequencialAlunoPrincipal = LegacySchoolHistory::query() | |
19 | + ->where('ref_cod_aluno', $codAlunoPrincipal) | |
20 | + ->max('sequencial') ?? 0; | |
21 | + | |
22 | 22 | DB::statement(" |
23 | 23 | UPDATE pmieducar.historico_escolar |
24 | 24 | SET |
... | ... | @@ -34,6 +34,7 @@ class App_Unificacao_Aluno |
34 | 34 | ref_sequencial = ref_sequencial + {$maxSequencialAlunoPrincipal} |
35 | 35 | WHERE ref_ref_cod_aluno = {$codAluno}; |
36 | 36 | "); |
37 | + $maxSequencialAlunoPrincipal++; | |
37 | 38 | } |
38 | 39 | |
39 | 40 | DB::statement("UPDATE pmieducar.matricula SET ref_cod_aluno = {$codAlunoPrincipal} where ref_cod_aluno in ({$codAlunosString})"); | ... | ... |
ieducar/modules/Api/Views/AlunoController.php
... | ... | @@ -3,6 +3,8 @@ |
3 | 3 | use App\Models\Educacenso\Registro30; |
4 | 4 | use App\Models\Individual; |
5 | 5 | use App\Models\LegacyDeficiency; |
6 | +use App\Models\LegacyRegistration; | |
7 | +use App\Models\LegacySchoolHistory; | |
6 | 8 | use App\Models\LogUnification; |
7 | 9 | use iEducar\Modules\Educacenso\Validator\BirthCertificateValidator; |
8 | 10 | use iEducar\Modules\Educacenso\Validator\DeficiencyValidator; |
... | ... | @@ -2018,6 +2020,89 @@ class AlunoController extends ApiCoreController |
2018 | 2020 | return ['unificacoes' => $unificationsQuery->get(['main_id', 'duplicates_id', 'created_at', 'active'])->all()]; |
2019 | 2021 | } |
2020 | 2022 | |
2023 | + protected function dadosUnificacaoAlunos() | |
2024 | + { | |
2025 | + $alunosIds = $this->getRequest()->alunos_ids ?? 0; | |
2026 | + | |
2027 | + $sql = " | |
2028 | + SELECT | |
2029 | + a.cod_aluno AS codigo, | |
2030 | + p.nome AS nome, | |
2031 | + coalesce(eca.cod_aluno_inep::varchar, 'Não consta') AS inep, | |
2032 | + coalesce(to_char(f.data_nasc, 'dd/mm/yyyy'), 'Não consta') AS data_nascimento, | |
2033 | + coalesce(f.cpf::varchar, 'Não consta') AS cpf, | |
2034 | + coalesce(d.rg, 'Não consta') AS rg, | |
2035 | + coalesce(relatorio.get_mae_aluno(a.cod_aluno), 'Não consta') AS mae_aluno | |
2036 | + FROM pmieducar.aluno a | |
2037 | + JOIN cadastro.pessoa p ON p.idpes = a.ref_idpes | |
2038 | + JOIN cadastro.fisica f ON f.idpes = a.ref_idpes | |
2039 | + LEFT JOIN cadastro.documento d ON d.idpes = a.ref_idpes | |
2040 | + LEFT JOIN modules.educacenso_cod_aluno eca ON eca.cod_aluno = a.cod_aluno | |
2041 | + WHERE a.cod_aluno IN ($alunosIds); | |
2042 | + "; | |
2043 | + | |
2044 | + $alunos = $this->fetchPreparedQuery($sql, [], false); | |
2045 | + | |
2046 | + $attrs = [ | |
2047 | + 'codigo', | |
2048 | + 'nome', | |
2049 | + 'inep', | |
2050 | + 'data_nascimento', | |
2051 | + 'cpf', | |
2052 | + 'rg', | |
2053 | + 'mae_aluno', | |
2054 | + ]; | |
2055 | + | |
2056 | + return [ | |
2057 | + 'alunos' => Portabilis_Array_Utils::filterSet($alunos, $attrs) | |
2058 | + ]; | |
2059 | + } | |
2060 | + | |
2061 | + protected function dadosMatriculasHistoricosAlunos() | |
2062 | + { | |
2063 | + $alunoId = $this->getRequest()->aluno_id; | |
2064 | + | |
2065 | + if (empty($alunoId)) { | |
2066 | + return; | |
2067 | + } | |
2068 | + | |
2069 | + $registrations = LegacyRegistration::query() | |
2070 | + ->where('ref_cod_aluno', $alunoId) | |
2071 | + ->with('school') | |
2072 | + ->orderBy('ano') | |
2073 | + ->get() | |
2074 | + ->map(function ($registration) { | |
2075 | + return [ | |
2076 | + 'ano' => $registration->ano, | |
2077 | + 'escola' => $registration->school->name, | |
2078 | + 'curso' => $registration->course->name, | |
2079 | + 'serie' => $registration->grade->name, | |
2080 | + 'turma' => $registration->lastEnrollment->schoolClass->name, | |
2081 | + ]; | |
2082 | + }) | |
2083 | + ->toArray(); | |
2084 | + | |
2085 | + $schoolHistories = LegacySchoolHistory::query() | |
2086 | + ->where('ref_cod_aluno', $alunoId) | |
2087 | + ->get() | |
2088 | + ->map(function ($schoolHistory) { | |
2089 | + $situacao = App_Model_MatriculaSituacao::getInstance()->getValue($schoolHistory->aprovado); | |
2090 | + return [ | |
2091 | + 'ano' => $schoolHistory->ano, | |
2092 | + 'escola' => $schoolHistory->escola, | |
2093 | + 'curso' => $schoolHistory->nm_curso, | |
2094 | + 'serie' => $schoolHistory->nm_serie, | |
2095 | + 'situacao' => $situacao, | |
2096 | + ]; | |
2097 | + }) | |
2098 | + ->toArray(); | |
2099 | + | |
2100 | + return [ | |
2101 | + 'matriculas' => $registrations, | |
2102 | + 'historicos' => $schoolHistories, | |
2103 | + ]; | |
2104 | + } | |
2105 | + | |
2021 | 2106 | protected function canGetUnificacoes() |
2022 | 2107 | { |
2023 | 2108 | return $this->validatesPresenceOf('escola'); |
... | ... | @@ -2053,6 +2138,10 @@ class AlunoController extends ApiCoreController |
2053 | 2138 | $this->appendResponse($this->getNomeBairro()); |
2054 | 2139 | } elseif ($this->isRequestFor('get', 'unificacao-alunos')) { |
2055 | 2140 | $this->appendResponse($this->getUnificacoes()); |
2141 | + } elseif ($this->isRequestFor('get', 'dadosUnificacaoAlunos')) { | |
2142 | + $this->appendResponse($this->dadosUnificacaoAlunos()); | |
2143 | + } elseif ($this->isRequestFor('get', 'dadosMatriculasHistoricosAlunos')) { | |
2144 | + $this->appendResponse($this->dadosMatriculasHistoricosAlunos()); | |
2056 | 2145 | } elseif ($this->isRequestFor('get', 'deve-habilitar-campo-recursos-prova-inep')) { |
2057 | 2146 | $this->appendResponse($this->deveHabilitarCampoRecursosProvaInep()); |
2058 | 2147 | } elseif ($this->isRequestFor('get', 'deve-obrigar-laudo-medico')) { | ... | ... |
ieducar/modules/Api/Views/PessoaController.php
... | ... | @@ -654,6 +654,70 @@ class PessoaController extends ApiCoreController |
654 | 654 | return $fisica; |
655 | 655 | } |
656 | 656 | |
657 | + protected function dadosUnificacaoPessoa() | |
658 | + { | |
659 | + $pessoasIds = $this->getRequest()->pessoas_ids ?? 0; | |
660 | + | |
661 | + $sql = 'SELECT | |
662 | + p.idpes, | |
663 | + concat_ws(\', \', | |
664 | + CASE WHEN cod_aluno IS NOT NULL THEN \'Aluno(a)\' ELSE NULL end, | |
665 | + CASE WHEN responsavel.idpes IS NOT NULL THEN \'Responsável\' ELSE NULL end, | |
666 | + CASE WHEN cod_servidor IS NOT NULL THEN \'Servidor(a)\' ELSE NULL end, | |
667 | + CASE WHEN cod_usuario IS NOT NULL THEN \'Usuário(a)\' ELSE NULL end | |
668 | + ) vinculo, | |
669 | + p.nome, | |
670 | + COALESCE(to_char(f.data_nasc, \'dd/mm/yyyy\'), \'Não consta\') AS data_nascimento, | |
671 | + CASE f.sexo | |
672 | + WHEN \'M\' THEN \'Masculino\' | |
673 | + WHEN \'F\' THEN \'Feminino\' | |
674 | + ELSE \'Não consta\' | |
675 | + END AS sexo, | |
676 | + COALESCE(f.cpf::varchar, \'Não consta\') AS cpf, | |
677 | + COALESCE(d.rg, \'Não consta\') AS rg, | |
678 | + COALESCE(pm.nome, \'Não consta\') AS pessoa_mae | |
679 | + FROM cadastro.pessoa p | |
680 | + JOIN cadastro.fisica f ON f.idpes = p.idpes | |
681 | + LEFT JOIN cadastro.documento d ON d.idpes = f.idpes | |
682 | + LEFT JOIN pmieducar.aluno a ON a.ref_idpes = p.idpes AND a.ativo = 1 | |
683 | + LEFT JOIN pmieducar.servidor s ON s.cod_servidor = p.idpes AND s.ativo = 1 | |
684 | + LEFT JOIN cadastro.pessoa pm ON pm.idpes = f.idpes_mae | |
685 | + LEFT JOIN pmieducar.usuario u on u.cod_usuario = p.idpes | |
686 | + LEFT JOIN LATERAL ( | |
687 | + SELECT idpes FROM cadastro.fisica f1 WHERE exists ( | |
688 | + SELECT 1 FROM cadastro.fisica f2 WHERE f1.idpes IN (f2.idpes_pai, f2.idpes_mae, f2.idpes_responsavel) | |
689 | + ) AND f1.idpes = f.idpes | |
690 | + ) responsavel ON TRUE | |
691 | + | |
692 | + WHERE p.idpes IN (' . $pessoasIds . ') ORDER BY vinculo DESC; | |
693 | + '; | |
694 | + | |
695 | + $pessoas = $this->fetchPreparedQuery($sql, [], false); | |
696 | + | |
697 | + $attrs = [ | |
698 | + 'idpes', | |
699 | + 'vinculo', | |
700 | + 'nome', | |
701 | + 'data_nascimento', | |
702 | + 'sexo', | |
703 | + 'cpf', | |
704 | + 'rg', | |
705 | + 'pessoa_mae', | |
706 | + ]; | |
707 | + | |
708 | + $filters = Portabilis_Array_Utils::filterSet($pessoas, $attrs); | |
709 | + | |
710 | + foreach ($filters as &$item) { | |
711 | + if (isset($item['vinculo']) && empty($item['vinculo'])) { | |
712 | + $item['vinculo'] = 'Sem vínculo'; | |
713 | + } | |
714 | + } | |
715 | + | |
716 | + return [ | |
717 | + 'pessoas' => $filters | |
718 | + ]; | |
719 | + } | |
720 | + | |
657 | 721 | public function Gerar() |
658 | 722 | { |
659 | 723 | if ($this->isRequestFor('get', 'pessoa-search')) { |
... | ... | @@ -672,6 +736,8 @@ class PessoaController extends ApiCoreController |
672 | 736 | $this->appendResponse($this->loadPessoaParent()); |
673 | 737 | } elseif ($this->isRequestFor('get', 'reativarPessoa')) { |
674 | 738 | $this->appendResponse($this->reativarPessoa()); |
739 | + } elseif ($this->isRequestFor('get', 'dadosUnificacaoPessoa')) { | |
740 | + $this->appendResponse($this->dadosUnificacaoPessoa()); | |
675 | 741 | } else { |
676 | 742 | $this->notImplementedOperationError(); |
677 | 743 | } | ... | ... |
ieducar/modules/Cadastro/Assets/Stylesheets/UnificaAluno.css
0 → 100644
... | ... | @@ -0,0 +1,83 @@ |
1 | +#tr_tabela_alunos_cab { | |
2 | + display: none; | |
3 | +} | |
4 | + | |
5 | +.tabela-adicao .tr_tabela_alunos:nth-of-type(-n+4) td a { | |
6 | + display: none; | |
7 | +} | |
8 | + | |
9 | +#tabela_alunos.tabela-adicao td { | |
10 | + padding: 5px 8px !important; | |
11 | +} | |
12 | + | |
13 | +table#tabela_alunos_unificados { | |
14 | + border-spacing: 0; | |
15 | + width: 100%; | |
16 | +} | |
17 | + | |
18 | +#tabela_alunos_unificados .tr_title { | |
19 | + background-color: #ccdce6; | |
20 | + font-family: "Open Sans"; | |
21 | + font-size: 14px; | |
22 | + font-weight: bold; | |
23 | + font-style: normal; | |
24 | + font-stretch: normal; | |
25 | + line-height: 1.14; | |
26 | + color: #47728f; | |
27 | +} | |
28 | + | |
29 | +#tabela_alunos_unificados .tr_title td { | |
30 | + padding: 10px; | |
31 | +} | |
32 | + | |
33 | +tr.linha_listagem td { | |
34 | + padding: 5px 10px; | |
35 | +} | |
36 | + | |
37 | +tr.linha_listagem:nth-child(even) { | |
38 | + background-color: #f5f9fd; | |
39 | +} | |
40 | + | |
41 | +#tabela_alunos_unificados a { | |
42 | + color: #47728f; | |
43 | + cursor: pointer; | |
44 | +} | |
45 | + | |
46 | +table.tabela-modal-dados-aluno { | |
47 | + width: 100%; | |
48 | +} | |
49 | + | |
50 | +.tabela-modal-dados-aluno tr.tabela-modal-dados-aluno-titulo { | |
51 | + background-color: #ccdce6; | |
52 | + font-family: "Open Sans"; | |
53 | + font-size: 14px; | |
54 | + font-weight: bold; | |
55 | + font-style: normal; | |
56 | + font-stretch: normal; | |
57 | + line-height: 1.14; | |
58 | + color: #47728f; | |
59 | +} | |
60 | + | |
61 | +.tabela-modal-dados-aluno td { | |
62 | + padding: 5px 10px; | |
63 | +} | |
64 | + | |
65 | +.linhaBotoes td input { | |
66 | + margin: 10px 4px; | |
67 | +} | |
68 | + | |
69 | +.botaolistagem.btn-disabled { | |
70 | + background: rgb(233, 240, 248) !important; | |
71 | + cursor: not-allowed; | |
72 | +} | |
73 | + | |
74 | +#tr_confirma_dados_unificacao td { | |
75 | + text-align: center; | |
76 | + font-size: 12px; | |
77 | + padding: 20px 0px; | |
78 | +} | |
79 | + | |
80 | +tr a { | |
81 | + color: #47728f; | |
82 | + cursor: pointer; | |
83 | +} | ... | ... |
ieducar/modules/Cadastro/Assets/Stylesheets/UnificaPessoa.css
0 → 100644
... | ... | @@ -0,0 +1,94 @@ |
1 | +.unifica_pessoa_h2 { | |
2 | + font-size: 14px; | |
3 | + margin: 0; | |
4 | + padding: 8px; | |
5 | + margin-top: 20px; | |
6 | + margin-bottom: -4px; | |
7 | +} | |
8 | + | |
9 | +#tr_tabela_pessoas_cab { | |
10 | + display: none; | |
11 | +} | |
12 | + | |
13 | +.tabela-adicao .tr_tabela_pessoas:nth-of-type(-n+4) td a { | |
14 | + display: none; | |
15 | +} | |
16 | + | |
17 | +#tabela_pessoas.tabela-adicao td { | |
18 | + padding: 5px 8px !important; | |
19 | +} | |
20 | + | |
21 | +table#tabela_pessoas_unificadas { | |
22 | + border-spacing: 0; | |
23 | + width: 100%; | |
24 | +} | |
25 | + | |
26 | +#tabela_pessoas_unificadas .tr_title { | |
27 | + background-color: #ccdce6; | |
28 | + font-family: "Open Sans"; | |
29 | + font-size: 14px; | |
30 | + font-weight: bold; | |
31 | + font-style: normal; | |
32 | + font-stretch: normal; | |
33 | + line-height: 1.14; | |
34 | + color: #47728f; | |
35 | +} | |
36 | + | |
37 | +#tabela_pessoas_unificadas .tr_title td { | |
38 | + padding: 10px; | |
39 | +} | |
40 | + | |
41 | +tr.linha_listagem td { | |
42 | + padding: 5px 10px; | |
43 | +} | |
44 | + | |
45 | +tr.linha_listagem:nth-child(even) { | |
46 | + background-color: #f5f9fd; | |
47 | +} | |
48 | + | |
49 | +.link_remove { | |
50 | + cursor: pointer; | |
51 | +} | |
52 | + | |
53 | +#tr_confirma_dados_unificacao td { | |
54 | + text-align: center; | |
55 | + font-size: 12px; | |
56 | + padding: 20px 0px; | |
57 | +} | |
58 | + | |
59 | +.linhaBotoes td input { | |
60 | + margin: 0px 4px; | |
61 | +} | |
62 | + | |
63 | +.botaolistagem.btn-disabled { | |
64 | + background: rgb(233, 240, 248) !important; | |
65 | + cursor: not-allowed; | |
66 | +} | |
67 | + | |
68 | +.lista_pessoas_unificadas_hr hr { | |
69 | + | |
70 | +} | |
71 | + | |
72 | +tr a { | |
73 | + color: #47728f; | |
74 | + cursor: pointer; | |
75 | +} | |
76 | + | |
77 | +#tr_observacoes td div { | |
78 | + padding: 10px; | |
79 | + color: #FF4E4E; | |
80 | + background: #FFEEEE; | |
81 | + border-radius: 8px; | |
82 | + border: 1px solid; | |
83 | + font-size: 12px; | |
84 | + margin-top: 12px; | |
85 | +} | |
86 | + | |
87 | +#tr_observacoes td div a#recarregar_lista { | |
88 | + display: inline-block; | |
89 | + background-color: rgba(255, 78, 78, .5); | |
90 | + color: #FFF; | |
91 | + padding: 5px 10px; | |
92 | + border-radius: 4px; | |
93 | + margin-top: 10px; | |
94 | +} | |
0 | 95 | \ No newline at end of file | ... | ... |