Commit dadb586fa5e9a1e3f885a0d45b74b63a9137122d
1 parent
5bbbe610
Exists in
master
Criado função de cópia de notas para transf.
Ao realizar uma transferência interna a função de cópia de notas é chamada e notas, faltas e pareceres são copiados para nova matrícula; portabilis/ieducar#88
Showing
2 changed files
with
171 additions
and
0 deletions
Show diff stats
ieducar/intranet/educar_matricula_cad.php
... | ... | @@ -457,6 +457,11 @@ class indice extends clsCadastro |
457 | 457 | |
458 | 458 | $det_matricula = $obj_matricula->detalhe(); |
459 | 459 | |
460 | + // Se a matrícula anterior estava em andamento, copia as notas/faltas/pareceres | |
461 | + if ($det_matricula['aprovado'] == 3){ | |
462 | + $db->Consulta(" SELECT modules.copia_notas_transf({$det_matricula['cod_matricula']},{$cod_matricula})"); | |
463 | + } | |
464 | + | |
460 | 465 | // Caso a solicitação seja para uma mesma série |
461 | 466 | if ($det_matricula['ref_ref_cod_serie'] == $this->ref_cod_serie) { |
462 | 467 | $ref_cod_transferencia = $transferencia['cod_transferencia_solicitacao']; | ... | ... |
ieducar/misc/database/deltas/portabilis/60_cria_funcao_copia_notas_trasnf.sql
0 → 100644
... | ... | @@ -0,0 +1,166 @@ |
1 | + -- // | |
2 | + -- @author Lucas Schmoeller da Silva <lucas@portabilis.com.br> | |
3 | + -- @author Isac da Silva Borgert <isac@portabilis.com.br> | |
4 | + -- @license @@license@@ | |
5 | + -- @version $Id$ | |
6 | + | |
7 | + CREATE OR REPLACE FUNCTION modules.copia_notas_transf(old_matricula_id integer, new_matricula_id integer) | |
8 | + RETURNS VARCHAR AS | |
9 | + $BODY$ | |
10 | + DECLARE | |
11 | + cur_comp RECORD; | |
12 | + cur_comp_media RECORD; | |
13 | + cur_falta_geral RECORD; | |
14 | + cur_falta_comp RECORD; | |
15 | + cur_parecer_geral RECORD; | |
16 | + cur_parecer_comp RECORD; | |
17 | + v_tipo_nota integer; | |
18 | + v_tipo_parecer integer; | |
19 | + v_tipo_falta integer; | |
20 | + v_nota_id integer; | |
21 | + v_old_nota_id integer; | |
22 | + v_falta_id integer; | |
23 | + v_old_falta_id integer; | |
24 | + v_parecer_id integer; | |
25 | + v_old_parecer_id integer; | |
26 | + begin | |
27 | + | |
28 | + /* VERIFICA SE AS MATRICULAS FAZEM PARTE DO MESMO ANO LETIVO*/ | |
29 | + IF ((SELECT eal.ano FROM pmieducar.escola_ano_letivo eal | |
30 | + INNER JOIN pmieducar.matricula mat ON (mat.ref_ref_cod_escola = eal.ref_cod_escola) | |
31 | + WHERE mat.cod_matricula = old_matricula_id and eal.andamento = 1 limit 1) = (SELECT eal.ano FROM pmieducar.escola_ano_letivo eal | |
32 | + INNER JOIN pmieducar.matricula mat ON (mat.ref_ref_cod_escola = eal.ref_cod_escola) | |
33 | + WHERE mat.cod_matricula = new_matricula_id and eal.andamento = 1 limit 1) ) THEN | |
34 | + | |
35 | + | |
36 | + IF ( | |
37 | + ( CASE WHEN (select padrao_ano_escolar from pmieducar.curso | |
38 | + where cod_curso = (select ref_cod_curso from pmieducar.matricula | |
39 | + where cod_matricula = new_matricula_id)) = 1 | |
40 | + THEN (select max(sequencial) as qtd_etapa from pmieducar.ano_letivo_modulo mod | |
41 | + inner join pmieducar.matricula mat on (mat.ref_ref_cod_escola = mod.ref_ref_cod_escola) | |
42 | + where mat.cod_matricula = new_matricula_id) | |
43 | + ELSE (select count(ref_cod_modulo) from pmieducar.turma_modulo | |
44 | + where ref_cod_turma = (select ref_cod_turma from pmieducar.matricula_turma | |
45 | + where ref_cod_matricula = new_matricula_id)) | |
46 | + END | |
47 | + ) = (CASE WHEN (select padrao_ano_escolar from pmieducar.curso | |
48 | + where cod_curso = (select ref_cod_curso from pmieducar.matricula | |
49 | + where cod_matricula = old_matricula_id)) = 1 | |
50 | + THEN (select max(sequencial) as qtd_etapa from pmieducar.ano_letivo_modulo mod | |
51 | + inner join pmieducar.matricula mat on (mat.ref_ref_cod_escola = mod.ref_ref_cod_escola) | |
52 | + where mat.cod_matricula = old_matricula_id) | |
53 | + ELSE (select count(ref_cod_modulo) from pmieducar.turma_modulo | |
54 | + where ref_cod_turma = (select ref_cod_turma from pmieducar.matricula_turma | |
55 | + where ref_cod_matricula = old_matricula_id)) | |
56 | + END | |
57 | + ) | |
58 | + ) THEN | |
59 | + | |
60 | + -- IF (TRUE) THEN | |
61 | + /* VERIFICA SE UTILIZAM A MESMA REGRA DE AVALIAÇÃO*/ | |
62 | + IF ((SELECT id FROM modules.regra_avaliacao rg | |
63 | + INNER JOIN pmieducar.serie s ON (rg.id = s.regra_avaliacao_id) | |
64 | + INNER JOIN pmieducar.matricula m ON (s.cod_serie = m.ref_ref_cod_serie) | |
65 | + where m.cod_matricula = old_matricula_id ) = | |
66 | + (SELECT id FROM modules.regra_avaliacao rg | |
67 | + INNER JOIN pmieducar.serie s ON (rg.id = s.regra_avaliacao_id) | |
68 | + INNER JOIN pmieducar.matricula m ON (s.cod_serie = m.ref_ref_cod_serie) | |
69 | + where m.cod_matricula = new_matricula_id ) ) THEN | |
70 | + | |
71 | + | |
72 | + v_tipo_nota := (SELECT tipo_nota FROM modules.regra_avaliacao rg | |
73 | + INNER JOIN pmieducar.serie s ON (rg.id = s.regra_avaliacao_id) | |
74 | + INNER JOIN pmieducar.matricula m ON (s.cod_serie = m.ref_ref_cod_serie) | |
75 | + where m.cod_matricula = old_matricula_id); | |
76 | + | |
77 | + v_tipo_falta := (SELECT tipo_presenca FROM modules.regra_avaliacao rg | |
78 | + INNER JOIN pmieducar.serie s ON (rg.id = s.regra_avaliacao_id) | |
79 | + INNER JOIN pmieducar.matricula m ON (s.cod_serie = m.ref_ref_cod_serie) | |
80 | + where m.cod_matricula = old_matricula_id); | |
81 | + | |
82 | + v_tipo_parecer := (SELECT parecer_descritivo FROM modules.regra_avaliacao rg | |
83 | + INNER JOIN pmieducar.serie s ON (rg.id = s.regra_avaliacao_id) | |
84 | + INNER JOIN pmieducar.matricula m ON (s.cod_serie = m.ref_ref_cod_serie) | |
85 | + where m.cod_matricula = old_matricula_id); | |
86 | + /* SE A REGRA UTILIZAR NOTA, COPIA AS NOTAS*/ | |
87 | + IF (v_tipo_nota >0) THEN | |
88 | + | |
89 | + INSERT INTO modules.nota_aluno (matricula_id)VALUES (new_matricula_id); | |
90 | + v_nota_id := (SELECT max(id) FROM modules.nota_aluno WHERE matricula_id = new_matricula_id); | |
91 | + | |
92 | + v_old_nota_id := (SELECT max(id) FROM modules.nota_aluno WHERE matricula_id = old_matricula_id); | |
93 | + | |
94 | + FOR cur_comp IN (SELECT * FROM modules.nota_componente_curricular where nota_aluno_id = v_old_nota_id) LOOP | |
95 | + INSERT INTO modules.nota_componente_curricular (nota_aluno_id,componente_curricular_id,nota,nota_arredondada,etapa) | |
96 | + VALUES(v_nota_id,cur_comp.componente_curricular_id,cur_comp.nota,cur_comp.nota_arredondada,cur_comp.etapa); | |
97 | + END LOOP; | |
98 | + | |
99 | + FOR cur_comp_media IN (SELECT * FROM modules.nota_componente_curricular_media where nota_aluno_id = v_old_nota_id) LOOP | |
100 | + INSERT INTO modules.nota_componente_curricular_media (nota_aluno_id,componente_curricular_id,media,media_arredondada,etapa) | |
101 | + VALUES(v_nota_id,cur_comp_media.componente_curricular_id,cur_comp_media.media,cur_comp_media.media_arredondada,cur_comp_media.etapa); | |
102 | + END LOOP; | |
103 | + END IF; | |
104 | + | |
105 | + IF (v_tipo_falta = 1) THEN | |
106 | + | |
107 | + INSERT INTO modules.falta_aluno (matricula_id, tipo_falta) VALUES (new_matricula_id,1); | |
108 | + v_falta_id = (SELECT max(id) FROM modules.falta_aluno WHERE matricula_id = new_matricula_id); | |
109 | + v_old_falta_id := (SELECT max(id) FROM modules.falta_aluno WHERE matricula_id = old_matricula_id); | |
110 | + | |
111 | + FOR cur_falta_geral IN (SELECT * FROM modules.falta_geral where falta_aluno_id = v_old_falta_id) LOOP | |
112 | + INSERT INTO modules.falta_geral (falta_aluno_id,quantidade,etapa) | |
113 | + VALUES(v_falta_id,cur_falta_geral.quantidade, cur_falta_geral.etapa); | |
114 | + END LOOP; | |
115 | + END IF; | |
116 | + | |
117 | + IF (v_tipo_falta = 2) THEN | |
118 | + | |
119 | + INSERT INTO modules.falta_aluno (matricula_id, tipo_falta) VALUES (new_matricula_id,2); | |
120 | + v_falta_id = (SELECT max(id) FROM modules.falta_aluno WHERE matricula_id = new_matricula_id); | |
121 | + v_old_falta_id := (SELECT max(id) FROM modules.falta_aluno WHERE matricula_id = old_matricula_id); | |
122 | + | |
123 | + FOR cur_falta_comp IN (SELECT * FROM modules.falta_componente_curricular where falta_aluno_id = v_old_falta_id) LOOP | |
124 | + INSERT INTO modules.falta_componente_curricular (falta_aluno_id,componente_curricular_id,quantidade,etapa) | |
125 | + VALUES(v_falta_id,cur_falta_comp.componente_curricular_id,cur_falta_comp.quantidade, cur_falta_comp.etapa); | |
126 | + END LOOP; | |
127 | + END IF; | |
128 | + | |
129 | + IF (v_tipo_parecer = 2) THEN | |
130 | + | |
131 | + INSERT INTO modules.parecer_aluno (matricula_id, parecer_descritivo)VALUES (new_matricula_id,2); | |
132 | + v_parecer_id := (SELECT max(id) FROM modules.parecer_aluno WHERE matricula_id = new_matricula_id); | |
133 | + v_old_parecer_id := (SELECT max(id) FROM modules.parecer_aluno WHERE matricula_id = old_matricula_id); | |
134 | + | |
135 | + FOR cur_parecer_comp IN (SELECT * FROM modules.parecer_componente_curricular where parecer_aluno_id = v_old_parecer_id) LOOP | |
136 | + INSERT INTO modules.parecer_componente_curricular (parecer_aluno_id,componente_curricular_id,parecer,etapa) | |
137 | + VALUES(v_parecer_id,cur_parecer_comp.componente_curricular_id,cur_parecer_comp.parecer, cur_parecer_comp.etapa); | |
138 | + END LOOP; | |
139 | + END IF; | |
140 | + | |
141 | + IF (v_tipo_parecer = 3) THEN | |
142 | + | |
143 | + INSERT INTO modules.parecer_aluno (matricula_id, parecer_descritivo)VALUES (new_matricula_id,3); | |
144 | + v_parecer_id := (SELECT max(id) FROM modules.parecer_aluno WHERE matricula_id = new_matricula_id); | |
145 | + v_old_parecer_id := (SELECT max(id) FROM modules.parecer_aluno WHERE matricula_id = old_matricula_id); | |
146 | + | |
147 | + FOR cur_parecer_geral IN (SELECT * FROM modules.parecer_geral where parecer_aluno_id = v_old_parecer_id) LOOP | |
148 | + INSERT INTO modules.parecer_geral (parecer_aluno_id,parecer,etapa) | |
149 | + VALUES(v_parecer_id,cur_parecer_geral.parecer, cur_parecer_geral.etapa); | |
150 | + END LOOP; | |
151 | + END IF; | |
152 | + | |
153 | + ELSE RETURN 'REGRA AVALIACAO DIFERENTE'; END IF; | |
154 | + ELSE RETURN 'ETAPA DIFERENTE'; END IF; | |
155 | + RETURN ''; | |
156 | + END IF; | |
157 | + | |
158 | + end;$BODY$ | |
159 | + LANGUAGE plpgsql VOLATILE; | |
160 | + ALTER FUNCTION modules.copia_notas_transf(integer, integer) | |
161 | + OWNER TO ieducar; | |
162 | + | |
163 | + | |
164 | + -- UNDO | |
165 | + | |
166 | + DROP FUNCTION modules.copia_notas_transf(old_matricula_id integer, new_matricula_id integer); | |
0 | 167 | \ No newline at end of file | ... | ... |