diff --git a/app/helpers/assertions_pdf_helper.rb b/app/helpers/assertions_pdf_helper.rb index 0decf59b..36ee4cdc 100644 --- a/app/helpers/assertions_pdf_helper.rb +++ b/app/helpers/assertions_pdf_helper.rb @@ -20,11 +20,10 @@ def replace_placeholders(template, values, records = []) record_template = template.scan(/<% records.each do \|record\| %>(.*?)<% end %>/m).flatten.first unless record_template.nil? - record_template = template.scan(/<% records.each do \|record\| %>(.*?)<% end %>/m).flatten.first record_text = records.map do |record| record_content = record_template.dup record.each do |key, value| - record_content.gsub!("<%= var('#{key}') %>", value.to_s) + record_content.gsub!("<%= record['#{key}'] %>", value.to_s) end record_content end.join("") diff --git a/db/migrate/20241220124937_add_query_and_assertion_for_external_participant.rb b/db/migrate/20241220124937_add_query_and_assertion_for_external_participant.rb new file mode 100644 index 00000000..8c969c4f --- /dev/null +++ b/db/migrate/20241220124937_add_query_and_assertion_for_external_participant.rb @@ -0,0 +1,64 @@ +class AddQueryAndAssertionForExternalParticipant < ActiveRecord::Migration[7.0] + def up + execute <<-SQL + INSERT INTO queries (name, sql, description, created_at, updated_at) + VALUES ( + 'DECLARAÇÃO - Participante externo em defesa de tese', + 'SELECT + s.name as nome_aluno, + l.name as nivel_aluno, + e.thesis_defense_date as data, + p.name as nome_professor + FROM + thesis_defense_committee_participations tdcp, enrollments e, students s, professors p, levels l + WHERE + tdcp.enrollment_id = e.id AND + e.student_id = s.id AND + tdcp.professor_id = p.id AND + e.level_id = l.id AND + e.enrollment_number = :matricula_aluno AND + p.cpf = :cpf_professor', + 'Declaração de participante externo em defesa de dissertação.', + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP + ); + SQL + + query_id = execute("SELECT last_insert_rowid()").first['last_insert_rowid()'] + + execute <<-SQL + INSERT INTO query_params (query_id, name, default_value, value_type, created_at, updated_at) + VALUES + (#{query_id}, 'matricula_aluno', NULL, 'String', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), + (#{query_id}, 'cpf_professor', NULL, 'String', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); + SQL + + execute <<-SQL + INSERT INTO assertions (name, query_id, assertion_template, created_at, updated_at) + VALUES ( + 'Declaração de participante externo em defesa de tese', + #{query_id}, + 'A quem possa interessar, Declaramos que o professor <%= var(''nome_professor'') %> participou da banca de defesa da dissertação de <%= var(''nivel_aluno'') %> de <%= var(''nome_aluno'') %>, no dia <%= var(''data'') %>.', + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP + ); + SQL + end + + def down + execute <<-SQL + DELETE FROM assertions + WHERE name = 'Declaração de participante externo em defesa de tese'; + SQL + + execute <<-SQL + DELETE FROM query_params + WHERE query_id = (SELECT id FROM queries WHERE name = 'DECLARAÇÃO - Participante externo em defesa de tese'); + SQL + + execute <<-SQL + DELETE FROM queries + WHERE name = 'DECLARAÇÃO - Participante externo em defesa de tese'; + SQL + end +end \ No newline at end of file diff --git a/db/migrate/20241220144358_add_query_and_assertion_for_examining_board.rb b/db/migrate/20241220144358_add_query_and_assertion_for_examining_board.rb new file mode 100644 index 00000000..0a363c18 --- /dev/null +++ b/db/migrate/20241220144358_add_query_and_assertion_for_examining_board.rb @@ -0,0 +1,69 @@ +class AddQueryAndAssertionForExaminingBoard < ActiveRecord::Migration[7.0] + def up + execute <<-SQL + INSERT INTO queries (name, sql, description, created_at, updated_at) + VALUES ( + 'DECLARAÇÃO - Banca examinadora de defesa', + 'SELECT + s.name as nome_aluno, + l.name as nivel_aluno, + e.thesis_title as titulo_tese, + e.thesis_defense_date as data, + p.name as nome_professor, + i.code as codigo_instituicao + FROM + thesis_defense_committee_participations tdcp, enrollments e, students s, professors p, levels l, institutions i + WHERE + tdcp.enrollment_id = e.id AND + e.student_id = s.id AND + tdcp.professor_id = p.id AND + e.level_id = l.id AND + i.id = p.institution_id AND + e.enrollment_number = :matricula_aluno', + 'Recupera informações necessárias para a declaração de banca examinadora de defesa de um determinado aluno', + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP + ); + SQL + + query_id = execute("SELECT last_insert_rowid()").first['last_insert_rowid()'] + + execute <<-SQL + INSERT INTO query_params (query_id, name, default_value, value_type, created_at, updated_at) + VALUES + (#{query_id}, 'matricula_aluno', NULL, 'String', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); + SQL + + execute <<-SQL + INSERT INTO assertions (name, query_id, assertion_template, created_at, updated_at) + VALUES ( + 'Declaração da ata de defesa', + #{query_id}, + 'Declaro, para os devidos fins, que a Banca Examinadora da Defesa de Dissertação de Mestrado intitulada “<%= var(''titulo_tese'') %>”, apresentada pelo aluno <%= var(''nome_aluno'') %>, no dia <%= var(''data'') %>, no no Instituto de Computação da Universidade Federal Fluminense, foi composta pelos seguintes membros: + + <% records.each do |record| %> + - Prof. <%= record[''nome_professor''] %>, <%= record[''codigo_instituicao''] %> + <% end %>', + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP + ); + SQL + end + + def down + execute <<-SQL + DELETE FROM assertions + WHERE name = 'Declaração da ata de defesa'; + SQL + + execute <<-SQL + DELETE FROM query_params + WHERE query_id = (SELECT id FROM queries WHERE name = 'DECLARAÇÃO - Banca examinadora de defesa'); + SQL + + execute <<-SQL + DELETE FROM queries + WHERE name = 'DECLARAÇÃO - Banca examinadora de defesa'; + SQL + end +end \ No newline at end of file diff --git a/db/migrate/20241220150416_add_query_and_assertion_for_avulso_student.rb b/db/migrate/20241220150416_add_query_and_assertion_for_avulso_student.rb new file mode 100644 index 00000000..38f37431 --- /dev/null +++ b/db/migrate/20241220150416_add_query_and_assertion_for_avulso_student.rb @@ -0,0 +1,80 @@ +class AddQueryAndAssertionForAvulsoStudent < ActiveRecord::Migration[7.0] + def up + execute <<-SQL + INSERT INTO queries (name, sql, description, created_at, updated_at) + VALUES ( + 'DECLARAÇÃO - Disciplinas de aluno avulso', + 'SELECT + s.name as nome_aluno, + s.cpf as cpf_aluno, + c.name as nome_disciplina, + c.workload as carga_horaria, + cs.year as ano_disciplina, + cs.semester as semestre_disciplina, + ce.grade as nota, + ce.situation as situacao + FROM + course_classes cs, class_enrollments ce, enrollments e, courses c, students s + WHERE + cs.id = ce.course_class_id AND + ce.enrollment_id = e.id AND + c.id = cs.course_id AND + e.student_id = s.id AND + cs.year = :ano_semestre_busca AND + cs.semester = :numero_semestre_busca AND + e.enrollment_number = :matricula_aluno', + 'Recupera as notas das disciplinas que um avulso obteve num determinado ano/semestre.', + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP + ); + SQL + + query_id = execute("SELECT last_insert_rowid()").first['last_insert_rowid()'] + + execute <<-SQL + INSERT INTO query_params (query_id, name, default_value, value_type, created_at, updated_at) + VALUES + (#{query_id}, 'matricula_aluno', NULL, 'String', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), + (#{query_id}, 'ano_semestre_busca', NULL, 'Integer', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP), + (#{query_id}, 'numero_semestre_busca', NULL, 'Integer', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); + SQL + + execute <<-SQL + INSERT INTO assertions (name, query_id, assertion_template, created_at, updated_at) + VALUES ( + 'Declaração de relatório de disciplinas para aluno avulso', + #{query_id}, + 'DECLARAÇÃO + + Declaro, para os devidos fins, que <%= var(''nome_aluno'') %> cursou como Aluno Avulso as seguintes disciplinas do Programa de Pós-Graduação em Computação, nos termos do Art. 15 do Regulamento dos Programas de Pós-Graduação Stricto Sensu da Universidade Federal Fluminense. + + <% records.each do |record| %> + <%= record[''counter''] %>. Nome da disciplina: "<%= record[''nome_disciplina''] %>" + Carga horaria total: <%= record[''carga_horaria''] %> + Período: <%= var(''ano_disciplina'') %>/<%= var(''semestre_disciplina'') %> + Nota: <%= record[''nota''] %> + Situação final: <%= record[''situacao''] %> + <% end %>', + CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP + ); + SQL + end + + def down + execute <<-SQL + DELETE FROM assertions + WHERE name = 'Declaração de relatório de disciplinas para aluno avulso'; + SQL + + execute <<-SQL + DELETE FROM query_params + WHERE query_id = (SELECT id FROM queries WHERE name = 'DECLARAÇÃO - Disciplinas de aluno avulso'); + SQL + + execute <<-SQL + DELETE FROM queries + WHERE name = 'DECLARAÇÃO - Disciplinas de aluno avulso'; + SQL + end +end \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index f7f2ba91..37165c50 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_12_09_223145) do +ActiveRecord::Schema[7.0].define(version: 2024_12_20_150416) do create_table "accomplishments", force: :cascade do |t| t.integer "enrollment_id" t.integer "phase_id"