From 23f4a7024eb970bba9acfaf77a4ecb4045e660a6 Mon Sep 17 00:00:00 2001 From: Lucas D'Avila Date: Thu, 31 Jan 2013 20:38:02 -0200 Subject: [PATCH] Melhorado / aplicado correções aos processos de matricula e enturmação --- ieducar/intranet/educar_matricula_cad.php | 400 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ieducar/intranet/educar_matricula_det.php | 57 +++++++++++++++++++++++++++++++++++++++------------------ ieducar/intranet/educar_matricula_lst.php | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- ieducar/intranet/educar_matricula_turma_cad.php | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------- ieducar/intranet/educar_matricula_turma_det.php | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------- ieducar/intranet/educar_matricula_turma_lst.php | 51 +++++++++++++++++++++++++++++---------------------- 6 files changed, 513 insertions(+), 314 deletions(-) diff --git a/ieducar/intranet/educar_matricula_cad.php b/ieducar/intranet/educar_matricula_cad.php index 5d68a4f..17de395 100644 --- a/ieducar/intranet/educar_matricula_cad.php +++ b/ieducar/intranet/educar_matricula_cad.php @@ -101,11 +101,11 @@ class indice extends clsCadastro $obj_aluno = new clsPmieducarAluno($this->ref_cod_aluno); if (! $obj_aluno->existe()) { - header('Location: educar_matricula_lst.php'); + header('Location: educar_aluno_lst.php'); die; } - $url = 'educar_matricula_lst.php?ref_cod_aluno=' . $this->ref_cod_aluno; + $url = 'educar_aluno_det.php?cod_aluno=' . $this->ref_cod_aluno; $obj_permissoes = new clsPermissoes(); $obj_permissoes->permissao_cadastra(578, $this->pessoa_logada, 7, $url); @@ -118,6 +118,7 @@ class indice extends clsCadastro $this->url_cancelar = $url; $this->nome_url_cancelar = 'Cancelar'; + return $retorno; } @@ -152,17 +153,13 @@ class indice extends clsCadastro 'Caso seja transfência externa por favor marque esta opção.'); } - // foreign keys - $instituicao_obrigatorio = TRUE; - $curso_obrigatorio = TRUE; - $escola_curso_obrigatorio = TRUE; - $get_escola = TRUE; - $get_curso = TRUE; - $get_escola_curso_serie = TRUE; - $get_matricula = TRUE; - $sem_padrao = TRUE; + // inputs + + $anoLetivoHelperOptions = array('situacoes' => array('em_andamento', 'nao_iniciado')); + + $this->inputsHelper()->dynamic(array('instituicao', 'escola', 'curso', 'serie')); + $this->inputsHelper()->dynamic('anoLetivo', array('label' => 'Ano destino'), $anoLetivoHelperOptions); - include 'include/pmieducar/educar_campo_lista.php'; if (is_numeric($this->ref_cod_curso)) { $obj_curso = new clsPmieducarCurso($this->ref_cod_curso); @@ -174,34 +171,124 @@ class indice extends clsCadastro } } - if ($this->ref_cod_escola) { - $this->ref_ref_cod_escola = $this->ref_cod_escola; - } + $this->acao_enviar = 'formUtils.submit()'; + } - $this->acao_enviar = 'valida()'; + protected function getCurso($id) { + $curso = new clsPmieducarCurso($id); + return $curso->detalhe(); } function Novo() { + + $this->url_cancelar = 'educar_aluno_det.php?cod_aluno=' . $this->ref_cod_aluno; + $this->nome_url_cancelar = 'Cancelar'; + @session_start(); $this->pessoa_logada = $_SESSION['id_pessoa']; @session_write_close(); $obj_permissoes = new clsPermissoes(); $obj_permissoes->permissao_cadastra(578, $this->pessoa_logada, 7, - 'educar_matricula_lst.php?ref_cod_aluno=' . $this->ref_cod_aluno); + 'educar_aluno_det.php?cod_aluno=' . $this->ref_cod_aluno); - $obj_escola_ano_letivo = new clsPmieducarEscolaAnoLetivo(); - $lst_escola_ano_letivo = $obj_escola_ano_letivo->lista($this->ref_cod_escola, - NULL, NULL, NULL,1, NULL, NULL, NULL, NULL, 1); + //novas regras matricula aluno + $this->ano = $_POST['ano']; - if (is_array($lst_escola_ano_letivo)) { - $det_escola_ano_letivo = array_shift($lst_escola_ano_letivo); - $this->ano = $det_escola_ano_letivo['ano']; + $anoLetivoEmAndamentoEscola = new clsPmieducarEscolaAnoLetivo(); + $anoLetivoEmAndamentoEscola = $anoLetivoEmAndamentoEscola->lista($this->ref_cod_escola, + $this->ano, + null, + null, + 2, /*adiciona where 0 ou 1*/ + null, + null, + null, + null, + 1 + ); + + if(is_array($anoLetivoEmAndamentoEscola)) { + require_once 'include/pmieducar/clsPmieducarSerie.inc.php'; + $db = new clsBanco(); + + $db->Consulta("select ref_ref_cod_serie, ref_cod_curso from pmieducar.matricula where ativo = 1 and ref_ref_cod_escola = $this->ref_cod_escola and ref_cod_curso = $this->ref_cod_curso and ref_cod_aluno = $this->ref_cod_aluno and aprovado not in (1,2,4,5,6,7,8,9)"); + + $db->ProximoRegistro(); + $m = $db->Tupla(); + if (is_array($m) && count($m)) { + + $curso = $this->getCurso($this->ref_cod_curso); + + if ($m['ref_ref_cod_serie'] == $this->ref_cod_serie) { + $this->mensagem .= "Este aluno já está matriculado nesta série e curso, não é possivel matricular um aluno mais de uma vez na mesma série.
"; + + return false; + } + + elseif ($curso['multi_seriado'] != 1) { + $serie = new clsPmieducarSerie($m['ref_ref_cod_serie'], null, null, $m['ref_cod_curso']); + $serie = $serie->detalhe(); + + if (is_array($serie) && count($serie)) + $nomeSerie = $serie['nm_serie']; + else + $nomeSerie = ''; + + $this->mensagem .= "Este aluno já está matriculado no(a) '$nomeSerie' deste curso e escola. Como este curso não é multi seriado, não é possivel manter mais de uma matricula em andamento para o mesmo curso.
"; + + return false; + } + } + + else + { + $db->Consulta("select ref_ref_cod_escola, ref_cod_curso, ref_ref_cod_serie from pmieducar.matricula where ativo = 1 and ref_ref_cod_escola != $this->ref_cod_escola and ref_cod_aluno = $this->ref_cod_aluno and aprovado not in (1,2,4,5,6,7,8,9) and not exists (select 1 from pmieducar.transferencia_solicitacao as ts where ts.ativo = 1 and ts.ref_cod_matricula_saida = matricula.cod_matricula)"); + + $db->ProximoRegistro(); + $m = $db->Tupla(); + if (is_array($m) && count($m)){ + require_once 'include/pmieducar/clsPmieducarEscola.inc.php'; + require_once 'include/pessoa/clsJuridica.inc.php'; + + $serie = new clsPmieducarSerie($m['ref_ref_cod_serie'], null, null, $m['ref_cod_curso']); + $serie = $serie->detalhe(); + if (is_array($serie) && count($serie)) + $serie = $serie['nm_serie']; + else + $serie = ''; + + $escola = new clsPmieducarEscola($m['ref_ref_cod_escola']); + $escola = $escola->detalhe(); + if (is_array($escola) && count($escola)) + { + $escola = new clsJuridica($escola['ref_idpes']); + $escola = $escola->detalhe(); + if (is_array($escola) && count($escola)) + $escola = $escola['fantasia']; + else + $escola = ''; + } + else + $escola = ''; + + $curso = new clsPmieducarCurso($m['ref_cod_curso']); + $curso = $curso->detalhe(); + if (is_array($curso) && count($curso)) + $curso = $curso['nm_curso']; + else + $curso = ''; + + $this->mensagem .= "Este aluno já está matriculado no(a) '$serie' do curso '$curso' na escola '$escola', para matricular este aluno na sua escola solicite transferência ao secretário(a) da escola citada.
"; + + return false; + } + } $obj_reserva_vaga = new clsPmieducarReservaVaga(); $lst_reserva_vaga = $obj_reserva_vaga->lista(NULL, $this->ref_cod_escola, - $this->ref_ref_cod_serie, NULL, NULL,$this->ref_cod_aluno, NULL, NULL, + $this->ref_cod_serie, NULL, NULL,$this->ref_cod_aluno, NULL, NULL, NULL, NULL, 1); // Verifica se existe reserva de vaga para o aluno @@ -223,7 +310,7 @@ class indice extends clsCadastro if (! $this->ref_cod_reserva_vaga) { $obj_turmas = new clsPmieducarTurma(); - $lst_turmas = $obj_turmas->lista(NULL, NULL, NULL, $this->ref_ref_cod_serie, + $lst_turmas = $obj_turmas->lista(NULL, NULL, NULL, $this->ref_cod_serie, $this->ref_cod_escola, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, TRUE); @@ -235,13 +322,13 @@ class indice extends clsCadastro } } else { - $this->mensagem = 'Série não possui turmas cadastradas.
'; + $this->mensagem = 'A série selecionada não possui turmas cadastradas.
'; return FALSE; } $obj_matricula = new clsPmieducarMatricula(); $lst_matricula = $obj_matricula->lista(NULL, NULL, $this->ref_cod_escola, - $this->ref_ref_cod_serie, NULL, NULL, NULL, 3, NULL, NULL, NULL, NULL, 1, + $this->ref_cod_serie, NULL, NULL, NULL, 3, NULL, NULL, NULL, NULL, 1, $this->ano, $this->ref_cod_curso, $this->ref_cod_instituicao, 1); if (is_array($lst_matricula)) { @@ -250,7 +337,7 @@ class indice extends clsCadastro $obj_reserva_vaga = new clsPmieducarReservaVaga(); $lst_reserva_vaga = $obj_reserva_vaga->lista(NULL, $this->ref_cod_escola, - $this->ref_ref_cod_serie, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, + $this->ref_cod_serie, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, $this->ref_cod_instituicao, $this->ref_cod_curso); if (is_array($lst_reserva_vaga)) { @@ -271,7 +358,7 @@ class indice extends clsCadastro msg += \'Deseja mesmo assim realizar a Matrícula?\'; if (! confirm(msg)) { - window.location = \'educar_matricula_lst.php?ref_cod_aluno=%d\'; + window.location = \'educar_aluno_det.php?cod_aluno=%d\'; } ', $matriculados, $reservados, $total_vagas, $this->ref_cod_aluno @@ -295,21 +382,29 @@ class indice extends clsCadastro $this->semestre = NULL; } + if (! $this->removerFlagUltimaMatricula($this->ref_cod_aluno)) { + return false; + } + $obj = new clsPmieducarMatricula(NULL, $this->ref_cod_reserva_vaga, - $this->ref_cod_escola, $this->ref_ref_cod_serie, NULL, + $this->ref_cod_escola, $this->ref_cod_serie, NULL, $this->pessoa_logada, $this->ref_cod_aluno, 3, NULL, NULL, 1, $this->ano, 1, NULL, NULL, NULL, NULL, $this->ref_cod_curso, $this->matricula_transferencia, $this->semestre); $cadastrou = $obj->cadastra(); if ($cadastrou) { + $obj_transferencia = new clsPmieducarTransferenciaSolicitacao(); - $lst_transferencia = $obj_transferencia->lista(NULL, NULL, NULL, NULL, + + + #Se encontrar solicitações de transferencia externa (com data de transferencia sem codigo de matricula de entrada), inativa estas + /*$lst_transferencia = $obj_transferencia->lista(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, $this->ref_cod_aluno, FALSE, NULL, NULL, NULL, TRUE, FALSE); - // Verifica se existe solicitação de transferência de aluno if (is_array($lst_transferencia)) { + echo 'Encontrou solicitações de transferencia externa (saida) com data de transferencia'; $det_transferencia = array_shift($lst_transferencia); $obj_transferencia = new clsPmieducarTransferenciaSolicitacao( @@ -334,14 +429,19 @@ class indice extends clsCadastro return FALSE; } } + #senão pega as solicitacoes de transferencia internas (sem data de transferencia e sem codigo de matricula de entrada) e + #seta a data de transferencia e codigo de matricula de entrada, atualiza a situacao da matricula para transferido e inativa a matricula turma else { + */ $obj_transferencia = new clsPmieducarTransferenciaSolicitacao(); $lst_transferencia = $obj_transferencia->lista(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, $this->ref_cod_aluno, FALSE, NULL, NULL, NULL, FALSE, FALSE); - // Verifica se existe solicitação de transferência do aluno + #TODO interna ? + // Verifica se existe solicitação de transferência (interna) do aluno if (is_array($lst_transferencia)) { + #echo 'Encontrou solicitações de transferencia interna (saida) com data de transferencia'; // Verifica cada solicitação de transferência do aluno foreach ($lst_transferencia as $transferencia) { $obj_matricula = new clsPmieducarMatricula( @@ -351,14 +451,14 @@ class indice extends clsCadastro $det_matricula = $obj_matricula->detalhe(); // Caso a solicitação seja para uma mesma série - if ($det_matricula['ref_ref_cod_serie'] == $this->ref_ref_cod_serie) { + if ($det_matricula['ref_ref_cod_serie'] == $this->ref_cod_serie) { $ref_cod_transferencia = $transferencia['cod_transferencia_solicitacao']; break; } // Caso a solicitação seja para a série da sequência else { $obj_sequencia = new clsPmieducarSequenciaSerie( - $det_matricula['ref_ref_cod_serie'], $this->ref_ref_cod_serie, + $det_matricula['ref_ref_cod_serie'], $this->ref_cod_serie, NULL, NULL, NULL, NULL, 1 ); @@ -397,31 +497,8 @@ class indice extends clsCadastro NULL, NULL, NULL, NULL, 1, NULL, NULL, $det_matricula['modulo'] ); - $editou_mat = $obj_matricula->edita(); - - if ($editou_mat) { - $obj_matricula_turma = new clsPmieducarMatriculaTurma(); - $lst_matricula_turma = $obj_matricula_turma->lista( - $matricula_saida, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1 - ); - - if (is_array($lst_matricula_turma)) { - $det_matricula_turma = array_shift($lst_matricula_turma); - - $obj_matricula_turma = new clsPmieducarMatriculaTurma( - $matricula_saida, $det_matricula_turma['ref_cod_turma'], - $this->pessoa_logada, NULL, NULL, NULL, 0, NULL, - $det_matricula_turma['sequencial'] - ); - - $editou_mat_turma = $obj_matricula_turma->edita(); - - if (! $editou_mat_turma) { - $this->mensagem = 'Não foi possível editar a Matrícula Turma.
'; - return FALSE; - } - } - } + if ($obj_matricula->edita() && ! $this->desativaEnturmacoesMatricula($matricula_saida)) + return false; } $obj = new clsPmieducarMatricula( @@ -442,22 +519,53 @@ class indice extends clsCadastro } } } - } + //} + #TODO set in $_SESSION['flash'] 'Aluno matriculado com sucesso' $this->mensagem .= 'Cadastro efetuado com sucesso.
'; - header('Location: educar_matricula_lst.php?ref_cod_aluno=' . $this->ref_cod_aluno); - die(); + header('Location: educar_aluno_det.php?cod_aluno=' . $this->ref_cod_aluno); + #die(); + #return true; } $this->mensagem = 'Cadastro não realizado.
'; return FALSE; } else { - $this->mensagem = 'Não foi possível encontrar o "Ano Letivo" em andamento da Escola.
'; + $this->mensagem = 'O ano (letivo) selecionado não esta em andamento na escola selecionada.
'; return FALSE; } } + + function desativaEnturmacoesMatricula($matriculaId) { + $result = true; + + $enturmacoes = new clsPmieducarMatriculaTurma(); + $enturmacoes = $enturmacoes->lista($matriculaId, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, 1); + + if ($enturmacoes) { + foreach ($enturmacoes as $enturmacao) { + $enturmacao = new clsPmieducarMatriculaTurma($matriculaId, + $enturmacao['ref_cod_turma'], + $this->pessoa_logada, null, + null, null, 0, null, + $enturmacao['sequencial']); + if ($result && ! $enturmacao->edita()) + $result = false; + } + } + + if(! $result) { + $this->mensagem = "Não foi possível desativar as " . + "enturmações da matrícula."; + } + + return $result; + } + + function Excluir() { @session_start(); @@ -466,28 +574,10 @@ class indice extends clsCadastro $obj_permissoes = new clsPermissoes(); $obj_permissoes->permissao_excluir(578, $this->pessoa_logada, 7, - 'educar_matricula_lst.php?ref_cod_aluno=' . $this->ref_cod_aluno); + 'educar_aluno_det.php?cod_aluno=' . $this->ref_cod_aluno); - $obj_matricula_turma = new clsPmieducarMatriculaTurma(); - $lst_matricula_turma = $obj_matricula_turma->lista( - $this->cod_matricula, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1 - ); - - if (is_array($lst_matricula_turma)) { - $det_matricula_turma = array_shift($lst_matricula_turma); - $obj_matricula_turma = new clsPmieducarMatriculaTurma( - $det_matricula_turma['ref_cod_matricula'], - $det_matricula_turma['ref_cod_turma'], $this->pessoa_logada, NULL, - NULL, NULL, 0, NULL, $det_matricula_turma['sequencial'] - ); - - $editou = $obj_matricula_turma->edita(); - - if (! $editou) { - $this->mensagem = 'Edição não realizada.
'; - return FALSE; - } - } + if (! $this->desativaEnturmacoesMatricula($this->cod_matricula)) + return false; $obj_matricula = new clsPmieducarMatricula( $this->cod_matricula ); $det_matricula = $obj_matricula->detalhe(); @@ -536,13 +626,32 @@ class indice extends clsCadastro if ($excluiu) { $this->mensagem .= 'Exclusão efetuada com sucesso.
'; - header('Location: educar_matricula_lst.php?ref_cod_aluno=' . $this->ref_cod_aluno); + header('Location: educar_aluno_det.php?cod_aluno=' . $this->ref_cod_aluno); die(); } $this->mensagem = 'Exclusão não realizada.
'; return FALSE; } + + protected function removerFlagUltimaMatricula($alunoId) { + $matriculas = new clsPmieducarMatricula(); + $matriculas = $matriculas->lista(NULL, NULL, NULL, NULL, NULL, NULL, $this->ref_cod_aluno, + NULL, NULL, NULL, NULL, NULL, 1, NULL, NULL, NULL, 1); + + + foreach ($matriculas as $matricula) { + $matricula = new clsPmieducarMatricula($matricula['cod_matricula'], NULL, NULL, NULL, + $this->pessoa_logada, NULL, $alunoId, NULL, NULL, + NULL, 1, NULL, 0); + if (! $matricula->edita()) { + $this->mensagem = 'Erro ao remover flag ultima matricula das matriculas anteriores.'; + return false; + } + } + + return true; + } } // Instancia objeto de página @@ -557,122 +666,3 @@ $pagina->addForm($miolo); // Gera o código HTML $pagina->MakeAll(); ?> - \ No newline at end of file diff --git a/ieducar/intranet/educar_matricula_det.php b/ieducar/intranet/educar_matricula_det.php index 72ce250..ac6b50c 100644 --- a/ieducar/intranet/educar_matricula_det.php +++ b/ieducar/intranet/educar_matricula_det.php @@ -97,7 +97,7 @@ class indice extends clsDetalhe } if (! $registro) { - header("Location: educar_matricula_lst.php?ref_cod_aluno=" . $registro['ref_cod_aluno']); + header("Location: educar_aluno_det.php?cod_aluno=" . $registro['ref_cod_aluno']); die(); } @@ -131,18 +131,6 @@ class indice extends clsDetalhe $nm_aluno = $det_aluno['nome_aluno']; } - // Nome da turma - $obj_mat_turma = new clsPmieducarMatriculaTurma(); - $det_mat_turma = $obj_mat_turma->lista($this->ref_cod_matricula, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, 1); - - if ($det_mat_turma){ - $det_mat_turma = array_shift($det_mat_turma); - $obj_turma = new clsPmieducarTurma($det_mat_turma['ref_cod_turma']); - $det_turma = $obj_turma->detalhe(); - $nm_turma = $det_turma['nm_turma']; - } - if ($registro['cod_matricula']) { $this->addDetalhe(array('Número Matrícula', $registro['cod_matricula'])); } @@ -167,9 +155,23 @@ class indice extends clsDetalhe $this->addDetalhe(array('Série', $registro['ref_ref_cod_serie'])); } - if ($nm_turma) { - $this->addDetalhe(array('Turma', $nm_turma)); + // Nome da turma + $enturmacoes = new clsPmieducarMatriculaTurma(); + $enturmacoes = $enturmacoes->lista($this->ref_cod_matricula, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, 1); + + $nomesTurmas = array(); + foreach ($enturmacoes as $enturmacao) { + $turma = new clsPmieducarTurma($enturmacao['ref_cod_turma']); + $turma = $turma->detalhe(); + $nomesTurmas[] = $turma['nm_turma']; } + $nomesTurmas = implode('
', $nomesTurmas); + + if ($nomesTurmas) + $this->addDetalhe(array('Turma', $nomesTurmas)); + else + $this->addDetalhe(array('Turma', '')); if ($registro['ref_cod_reserva_vaga']) { $this->addDetalhe(array('Número Reserva Vaga', $registro['ref_cod_reserva_vaga'])); @@ -250,7 +252,7 @@ class indice extends clsDetalhe if ($registro['aprovado'] != 4 && $registro['aprovado'] != 6) { if (is_array($lst_transferencia) && !isset($data_transferencia)) { - $this->array_botao[] = 'Cancelar Solicitação Transferência'; + $this->array_botao[] = 'Cancelar Solicitação Transferência (escola do sistema)'; $this->array_botao_url_script[] = "go(\"educar_transferencia_solicitacao_cad.php?ref_cod_matricula={$registro['cod_matricula']}&ref_cod_aluno={$registro['ref_cod_aluno']}&cancela=true\")"; } else { @@ -274,15 +276,34 @@ class indice extends clsDetalhe } } + if($registro['aprovado'] == 4 && + $this->canCancelTransferenciaExterna($registro['cod_matricula'], $registro['ref_cod_aluno'])) { + $this->array_botao[] = 'Cancelar transferência (escola externa)'; + + + # TODO ver se código, seta matricula como em andamento, ativa ultima matricula_turma for matricula, e desativa transferencia solicitacao + $this->array_botao_url_script[] = "go(\"educar_transferencia_solicitacao_cad.php?ref_cod_matricula={$registro['cod_matricula']}&ref_cod_aluno={$registro['ref_cod_aluno']}&cancela=true&reabrir_matricula=true\")"; + } + if ($registro['aprovado'] == 4 || $det_transferencia) { $this->array_botao[] = 'Imprimir Atestado Frequência'; $this->array_botao_url_script[] = "showExpansivelImprimir(400, 200, \"educar_relatorio_atestado_frequencia.php?cod_matricula={$registro['cod_matricula']}\",[], \"Relatório Atestado de Freqüência\")"; } } - $this->url_cancelar = 'educar_matricula_lst.php?ref_cod_aluno=' . $registro['ref_cod_aluno']; + $this->url_cancelar = 'educar_aluno_det.php?cod_aluno=' . $registro['ref_cod_aluno']; $this->largura = '100%'; } + + + function canCancelTransferenciaExterna($matriculaId, $alunoId) { + $sql = "select 1 from pmieducar.matricula where ativo = 1 and cod_matricula > $matriculaId and ref_cod_aluno = $alunoId limit 1"; + + $db = new clsBanco(); + $existeNovaMatricula = $db->CampoUnico($sql) == '1'; + + return ! $existeNovaMatricula; + } } // Instancia objeto de página @@ -295,4 +316,4 @@ $miolo = new indice(); $pagina->addForm($miolo); // Gera o código HTML -$pagina->MakeAll(); \ No newline at end of file +$pagina->MakeAll(); diff --git a/ieducar/intranet/educar_matricula_lst.php b/ieducar/intranet/educar_matricula_lst.php index acfc413..fd2d8d1 100644 --- a/ieducar/intranet/educar_matricula_lst.php +++ b/ieducar/intranet/educar_matricula_lst.php @@ -107,6 +107,10 @@ class indice extends clsListagem $this->addBanner( "imagens/nvp_top_intranet.jpg", "imagens/nvp_vert_intranet.jpg", "Intranet" ); $lista_busca = array( + "Ano", + "Matrícula", + "Situação", + "Turma", "Série", "Curso" ); @@ -139,7 +143,7 @@ class indice extends clsListagem $this->offset = ( $_GET["pagina_{$this->nome}"] ) ? $_GET["pagina_{$this->nome}"]*$this->limite-$this->limite: 0; $obj_matricula = new clsPmieducarMatricula(); - $obj_matricula->setOrderby( "cod_matricula ASC" ); + $obj_matricula->setOrderby('ano DESC, ref_ref_cod_serie DESC, aprovado, cod_matricula'); $obj_matricula->setLimite( $this->limite, $this->offset ); $lista = $obj_matricula->lista( @@ -214,8 +218,43 @@ class indice extends clsListagem echo ""; } + $enturmacoes = new clsPmieducarMatriculaTurma(); + $enturmacoes = $enturmacoes->lista($registro['cod_matricula'], NULL, NULL, + NULL, NULL, NULL, NULL, NULL, 1); + $nomesTurmas = array(); + foreach ($enturmacoes as $enturmacao) { + $turma = new clsPmieducarTurma($enturmacao['ref_cod_turma']); + $turma = $turma->detalhe(); + $nomesTurmas[] = $turma['nm_turma']; + } + $nomesTurmas = implode('
', $nomesTurmas); + + $situacao = $registro['aprovado']; + if ($situacao == 1) + $situacao = 'Aprovado'; + elseif ($situacao == 2) + $situacao = 'Reprovado'; + elseif ($situacao == 3) + $situacao = 'Em Andamento'; + elseif ($situacao == 4) + $situacao = 'Transferido'; + elseif ($situacao == 5) + $situacao = 'Reclassificado'; + elseif ($situacao == 6) + $situacao = 'Abandono'; + $lista_busca = array(); + $lista_busca[] = "{$registro["ano"]}"; + $lista_busca[] = "{$registro["cod_matricula"]}"; + $lista_busca[] = "$situacao"; + + if ($nomesTurmas) { + $lista_busca[] = "$nomesTurmas"; + } + else + $lista_busca[] = ""; + if ($registro["ref_ref_cod_serie"]) $lista_busca[] = "{$registro["ref_ref_cod_serie"]}"; else @@ -246,6 +285,11 @@ class indice extends clsListagem $this->addLinhas($lista_busca); } } + else + { + $this->addLinhas(array('Aluno sem matrículas em andamento na sua escola.')); + } + $this->addPaginador2( "educar_matricula_lst.php", $total, $_GET, $this->nome, $this->limite ); if( $obj_permissoes->permissao_cadastra( 578, $this->pessoa_logada, 7 ) ) { @@ -279,4 +323,4 @@ document.getElementById('ref_cod_curso').onchange = function() getEscolaCursoSerie(); } - \ No newline at end of file + diff --git a/ieducar/intranet/educar_matricula_turma_cad.php b/ieducar/intranet/educar_matricula_turma_cad.php index 88d1b63..2e5e238 100644 --- a/ieducar/intranet/educar_matricula_turma_cad.php +++ b/ieducar/intranet/educar_matricula_turma_cad.php @@ -32,6 +32,7 @@ require_once 'include/clsBase.inc.php'; require_once 'include/clsCadastro.inc.php'; require_once 'include/clsBanco.inc.php'; require_once 'include/pmieducar/geral.inc.php'; +require_once 'include/pmieducar/clsPmieducarMatricula.inc.php'; /** * clsIndexBase class. @@ -87,7 +88,7 @@ class indice extends clsCadastro $this->pessoa_logada = $_SESSION['id_pessoa']; @session_write_close(); - if (!$_POST) { + if (! $_POST) { header('Location: educar_matricula_lst.php'); die; } @@ -99,59 +100,92 @@ class indice extends clsCadastro $obj_permissoes = new clsPermissoes(); $obj_permissoes->permissao_cadastra(578, $this->pessoa_logada, 7, 'educar_matricula_lst.php'); + //nova lógica if (is_numeric($this->ref_cod_matricula)) { - if (is_numeric($this->ref_cod_turma_origem)) { - $obj_matricula_turma = new clsPmieducarMatriculaTurma(); - $lst_matricula_turma = $obj_matricula_turma->lista($this->ref_cod_matricula, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1); - - if ($lst_matricula_turma) { - foreach ($lst_matricula_turma as $matricula) { - $obj = new clsPmieducarMatriculaTurma($this->ref_cod_matricula, - $matricula['ref_cod_turma'], $this->pessoa_logada, NULL, NULL, - NULL, 0, NULL, $matricula['sequencial']); - - $registro = $obj->detalhe(); - if ($registro) { - if (!$obj->edita()) { - echo "erro ao cadastrar"; - die; - } - } - } - } - - $obj = new clsPmieducarMatriculaTurma($this->ref_cod_matricula, - $this->ref_cod_turma_destino, $this->pessoa_logada, $this->pessoa_logada, - NULL, NULL, 1); - - $cadastrou = $obj->cadastra(); - - if ($cadastrou) { - $this->mensagem .= 'Cadastro efetuado com sucesso.
'; - header('Location: educar_matricula_det.php?cod_matricula=' . $this->ref_cod_matricula); - die(); - } - } + + if ($this->ref_cod_turma_origem == 'remover-enturmacao-destino') + $this->removerEnturmacao($this->ref_cod_matricula, $this->ref_cod_turma_destino); + elseif (! is_numeric($this->ref_cod_turma_origem)) + $this->novaEnturmacao($this->ref_cod_matricula, $this->ref_cod_turma_destino); else { - $obj = new clsPmieducarMatriculaTurma($this->ref_cod_matricula, - $this->ref_cod_turma_destino, $this->pessoa_logada, $this->pessoa_logada, - NULL, NULL, 1); + $this->transferirEnturmacao($this->ref_cod_matricula, + $this->ref_cod_turma_origem, + $this->ref_cod_turma_destino); + } - $cadastrou = $obj->cadastra(); + header('Location: educar_matricula_det.php?cod_matricula=' . $this->ref_cod_matricula); + die(); + } + else { + header('Location: /intranet/educar_aluno_lst.php'); + die(); + } + } - if ($cadastrou) { - $this->mensagem .= 'Cadastro efetuado com sucesso.
'; - header('Location: educar_matricula_det.php?cod_matricula=' . $this->ref_cod_matricula); - die(); - } - } + function novaEnturmacao($matriculaId, $turmaDestinoId) { + + $enturmacaoExists = new clsPmieducarMatriculaTurma(); + $enturmacaoExists = $enturmacaoExists->lista($matriculaId, + $turmaDestinoId, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + 1); + + $enturmacaoExists = is_array($enturmacaoExists) && count($enturmacaoExists) > 0; + if (! $enturmacaoExists) { + $enturmacao = new clsPmieducarMatriculaTurma($matriculaId, + $turmaDestinoId, + $this->pessoa_logada, + $this->pessoa_logada, + NULL, + NULL, + 1); + return $enturmacao->cadastra(); } + return false; + } - header('Location: educar_matricula_lst.php'); - die; + + function transferirEnturmacao($matriculaId, $turmaOrigemId, $turmaDestinoId) { + if($this->removerEnturmacao($matriculaId, $turmaOrigemId)) + return $this->novaEnturmacao($matriculaId, $turmaDestinoId); + return false; } + + function removerEnturmacao($matriculaId, $turmaId) { + $sequencialEnturmacao = $this->getSequencialEnturmacaoByTurmaId($matriculaId, $turmaId); + $enturmacao = new clsPmieducarMatriculaTurma($matriculaId, + $turmaId, + $this->pessoa_logada, + NULL, + NULL, + NULL, + 0, + NULL, + $sequencialEnturmacao); + + return $enturmacao->edita(); + } + + + function getSequencialEnturmacaoByTurmaId($matriculaId, $turmaId) { + $db = new clsBanco(); + $sql = 'select coalesce(max(sequencial), 1) from pmieducar.matricula_turma where ativo = 1 and ref_cod_matricula = $1 and ref_cod_turma = $2'; + + if ($db->execPreparedQuery($sql, array($matriculaId, $turmaId)) != false) { + $db->ProximoRegistro(); + $sequencial = $db->Tupla(); + return $sequencial[0]; + } + return 1; + } + + function Gerar() { die; @@ -180,4 +214,4 @@ $miolo = new indice(); $pagina->addForm($miolo); // Gera o código HTML -$pagina->MakeAll(); \ No newline at end of file +$pagina->MakeAll(); diff --git a/ieducar/intranet/educar_matricula_turma_det.php b/ieducar/intranet/educar_matricula_turma_det.php index ece20f2..94c20db 100644 --- a/ieducar/intranet/educar_matricula_turma_det.php +++ b/ieducar/intranet/educar_matricula_turma_det.php @@ -94,6 +94,11 @@ class indice extends clsDetalhe $this->$key = $value; } + if (! $this->ref_cod_matricula) { + header('Location: educar_matricula_lst.php'); + die(); + } + $obj_mat_turma = new clsPmieducarMatriculaTurma(); $det_mat_turma = $obj_mat_turma->lista($this->ref_cod_matricula, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1); @@ -108,19 +113,27 @@ class indice extends clsDetalhe $this->sequencial = $det_mat_turma['sequencial']; } - $tmp_obj = new clsPmieducarMatriculaTurma( ); - $lista = $tmp_obj->lista(NULL, $this->ref_cod_turma, NULL, NULL, NULL, NULL, - NULL, NULL, 1); + // #TODO adicionar ano da matricula atual + #$tmp_obj = new clsPmieducarMatriculaTurma( ); + #$lista = $tmp_obj->lista(NULL, $this->ref_cod_turma, NULL, NULL, NULL, NULL, + # NULL, NULL, 1); - $total_alunos = 0; - if ($lista) { - $total_alunos = count($lista); - } + #$total_alunos = 0; + #if ($lista) { + # $total_alunos = count($lista); + #} $tmp_obj = new clsPmieducarTurma(); $lst_obj = $tmp_obj->lista($this->ref_cod_turma); $registro = array_shift($lst_obj); + $db = new clsBanco(); + + $ano = $db->CampoUnico("select ano from pmieducar.matricula where cod_matricula = $this->ref_cod_matricula"); + $sql = "select count(cod_matricula) as qtd_matriculas from pmieducar.matricula, pmieducar.matricula_turma, pmieducar.aluno where aluno.cod_aluno = matricula.ref_cod_aluno and ano = {$ano} and aluno.ativo = 1 and matricula.ativo = 1 and matricula_turma.ativo = matricula.ativo and cod_matricula = ref_cod_matricula and ref_cod_turma = $this->ref_cod_turma"; + + $total_alunos = $db->CampoUnico($sql); + $this->ref_cod_curso = $registro['ref_cod_curso']; if (!$registro || !$_POST) { @@ -183,7 +196,42 @@ class indice extends clsDetalhe $this->addDetalhe(array('Série', $registro['ref_ref_cod_serie'])); } - $this->addDetalhe(array('Turma atual', $this->nm_turma)); + //(enturmações) turma atual + $enturmacoes = new clsPmieducarMatriculaTurma(); + $enturmacoes = $enturmacoes->lista($this->ref_cod_matricula, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1); + + $this->possuiEnturmacao = ! empty($enturmacoes); + $this->possuiEnturmacaoTurmaDestino = false; + $this->turmaOrigemMesmaDestino = false; + + if ($this->possuiEnturmacao) { + //se possui uma enturmacao mostra o nome, se mais de uma mostra select para selecionar + if (count($enturmacoes) > 1) { + $selectEnturmacoes = ""; + } + else { + if ($enturmacoes[0]['ref_cod_turma'] == $this->ref_cod_turma) { + $this->possuiEnturmacaoTurmaDestino = true; + $this->turmaOrigemMesmaDestino = true; + } + + $selectEnturmacoes = "{$enturmacoes[0]['nm_turma']}"; + } + + $this->addDetalhe(array('Turma atual (origem)', $selectEnturmacoes)); + } + else + $this->addDetalhe(array('Turma atual (origem)', 'Sem enturmações')); + if ($registro['nm_turma']) { $this->addDetalhe(array('Turma destino' , $registro['nm_turma'])); @@ -213,30 +261,76 @@ class indice extends clsDetalhe )); if ($registro['max_aluno'] - $total_alunos <= 0) { - $msg = sprintf('Atenção! Turma sem vagas! Deseja continuar com a enturmação mesmo assim?'); - $valida = sprintf('if (!confirm("%s")) return false;', $msg); - } - else { - $valida = 'if (!confirm("Confirmar a enturmação?")) return false;'; + + $escolaSerie = $this->getEscolaSerie($det_ref_cod_escola['cod_escola'], $det_ser['cod_serie']); + + if($escolaSerie['bloquear_enturmacao_sem_vagas'] != 1) { + $msg = sprintf('Atenção! Turma sem vagas! Deseja continuar com a enturmação mesmo assim?'); + $jsEnturmacao = sprintf('if (!confirm("%s")) return false;', $msg); + } + else { + $msg = sprintf('Enturmação não pode ser realizada,\n\no limite de vagas da turma já foi atingido e para esta série e escola foi definido bloqueio de enturmação após atingir tal limite.'); + $jsEnturmacao = sprintf('alert("%s"); return false;', $msg); + } } + else + $jsEnturmacao = 'if (!confirm("Confirma a enturmação?")) return false;'; $script = sprintf(' ', $valida); + + ', $jsEnturmacao); print $script; $obj_permissoes = new clsPermissoes(); - if ($obj_permissoes->permissao_cadastra(578, $this->pessoa_logada, 7)) { - $script = "enturmar({$this->ref_cod_matricula},{$this->ref_cod_turma})"; - $this->array_botao = array('Transferir Aluno'); - $this->array_botao_url_script = array($script); + if (! $this->turmaOrigemMesmaDestino && $obj_permissoes->permissao_cadastra(578, $this->pessoa_logada, 7)) { + + if ($this->possuiEnturmacao) { + //mover enturmação + $this->array_botao = array('Transferir (turma atual) para turma destino'); + $this->array_botao_url_script = array("enturmar({$this->ref_cod_matricula}, {$this->ref_cod_turma}, \"transferir\")"); + } + + //nova enturmação + $this->array_botao[] = 'Nova enturmação (na turma destino)'; + $this->array_botao_url_script[] = "enturmar({$this->ref_cod_matricula}, {$this->ref_cod_turma}, \"nova\")"; + + if ($this->possuiEnturmacaoTurmaDestino){ + $this->array_botao[] = 'Remover enturmação (turma destino)'; + $this->array_botao_url_script[] = "removerEnturmacao({$this->ref_cod_matricula}, {$this->ref_cod_turma})"; + } } $this->array_botao[] = 'Voltar'; @@ -244,6 +338,15 @@ class indice extends clsDetalhe $this->largura = '100%'; } + + protected function getEscolaSerie($escolaId, $serieId) { + $escolaSerie = new clsPmieducarEscolaSerie(); + $escolaSerie->ref_cod_escola = $escolaId; + $escolaSerie->ref_cod_serie = $serieId; + + return $escolaSerie->detalhe(); + } + } // Instancia objeto de página @@ -256,4 +359,4 @@ $miolo = new indice(); $pagina->addForm($miolo); // Gera o código HTML -$pagina->MakeAll(); \ No newline at end of file +$pagina->MakeAll(); diff --git a/ieducar/intranet/educar_matricula_turma_lst.php b/ieducar/intranet/educar_matricula_turma_lst.php index 3279ea4..9e9a522 100644 --- a/ieducar/intranet/educar_matricula_turma_lst.php +++ b/ieducar/intranet/educar_matricula_turma_lst.php @@ -91,7 +91,7 @@ class indice extends clsListagem $this->pessoa_logada = $_SESSION['id_pessoa']; session_write_close(); - $this->titulo = 'Listagem - Selecione a turma para realizar a transferência'; + $this->titulo = 'Selecione uma turma para enturmar ou remover a enturmação'; $this->ref_cod_matricula = $_GET['ref_cod_matricula']; @@ -111,7 +111,8 @@ class indice extends clsListagem $this->addBanner('imagens/nvp_top_intranet.jpg', 'imagens/nvp_vert_intranet.jpg', 'Intranet'); $this->addCabecalhos(array( - 'Turma' + 'Turma', + 'Enturmado' )); // Busca dados da matricula @@ -146,9 +147,12 @@ class indice extends clsListagem foreach ($lista as $registro) { $opcoes[$registro['cod_turma']] = $registro['nm_turma']; } + + $this->exibirBotaoSubmit = false; + } - $this->campoLista('ref_cod_turma_', 'Turma', $opcoes, $this->ref_cod_turma); + #$this->campoLista('ref_cod_turma_', 'Turma', $opcoes, $this->ref_cod_turma); // outros filtros $this->campoOculto('ref_cod_matricula', $this->ref_cod_matricula); @@ -211,27 +215,30 @@ WHERE $total = $obj_matricula_turma->_total; } - $tmp_obj = new clsPmieducarMatriculaTurma(); - $det_obj = $tmp_obj->lista($this->ref_cod_matricula, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, 1); + $enturmacoesMatricula = new clsPmieducarMatriculaTurma(); + $enturmacoesMatricula = $enturmacoesMatricula->lista($this->ref_cod_matricula, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, 1); - if ($det_obj) { - $det_obj = array_shift($det_obj); - } + $turmasThisSerie = $lista; + // lista turmas disponiveis para enturmacao, somente lista as turmas sem enturmacao + foreach ($turmasThisSerie as $turma) { - // Monta a lista - if (is_array($lista) && count($lista)) { - foreach ($lista as $registro) { - if($registro['cod_turma'] != $det_obj['ref_cod_turma']) { - $script = sprintf('onclick="enturmar(\'%s\',\'%s\',\'%s\',\'%s\');"', - $this->ref_cod_escola, $registro['ref_ref_cod_serie'], - $this->ref_cod_matricula, $registro['cod_turma']); - - $this->addLinhas(array( - sprintf('%s', $script, $registro['nm_turma']) - )); - } + $turmaHasEnturmacao = false; + foreach ($enturmacoesMatricula as $enturmacao) { + if(! $turmaHasEnturmacao && $turma['cod_turma'] == $enturmacao['ref_cod_turma']) + $turmaHasEnturmacao = true; } + + if($turmaHasEnturmacao) + $enturmado = "Sim"; + else + $enturmado = "Não"; + + $script = sprintf('onclick="enturmar(\'%s\',\'%s\',\'%s\',\'%s\');"', + $this->ref_cod_escola, $turma['ref_ref_cod_serie'], + $this->ref_cod_matricula, $turma['cod_turma']); + + $this->addLinhas(array(sprintf('%s', $script, $turma['nm_turma']), $enturmado)); } $this->addPaginador2("educar_matricula_turma_lst.php", $total, $_GET, @@ -272,4 +279,4 @@ function enturmar(ref_cod_escola, ref_cod_serie, ref_cod_matricula, ref_cod_turm document.formcadastro.submit(); } - \ No newline at end of file + -- libgit2 0.21.2