<%-# Fedena
#Copyright 2010 Foradian Technologies Private Limited
#
#This product includes software developed at
#Project Fedena - http://www.projectfedena.org/
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing,
#software distributed under the License is distributed on an
#"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#KIND, either express or implied.  See the License for the
#specific language governing permissions and limitations
#under the License. -%>

<div id="page-yield">

  <div class="hor_line"></div>
  <h2 align="center"><%= t('transcript_of_academic_record') %></h2>
  <div class="hor_line"></div>
  <div class="extender"> </div>
  <div class="report">
    <div id ="main_info">
      <div class="info1">
        <div class="info-left">
          <h4><%= t('name') %> : <%= @student.full_name %></h4>
        </div>
        <div class="info-right">
          <h4><%= t('adm_no') %> : <%= @student.admission_no.present? ? @student.admission_no : "-" %></h4>
        </div>
      </div>
      <div class="hor_line"></div>
      <div class="info1">
        <div class="info-left">
          <h4><%= t('course_text') %> : <%= @student.batch.course.course_name %></h4>
        </div>
        <div class="hor_line"></div>
      </div>
      <div id="pdf-info">
        <% reports = GroupedExamReport.find_all_by_student_id_and_score_type(@student.id,'c') %>
        <% if reports.empty? %>
          <p class="flash-msg"><%= t('grouped_exam_reports_not_generated') %></p>
        <% else %>
          <% grades = [] %>
          <% grade_type = "normal" %>
          <% grade_type = "GPA" if @student.batch.gpa_enabled? %>
          <% grade_type = "CWA" if @student.batch.cwa_enabled? %>
          <% @batches.each do|batch| %>
            <% st_mark = GroupedExamReport.find_by_batch_id_and_student_id_and_score_type(batch.id,@student.id,"c") %>
            <% unless st_mark.nil? %>
              <% general_subjects = Subject.find_all_by_batch_id(batch.id, :conditions=>"elective_group_id IS NULL AND is_deleted=false") %>
              <% student_electives = StudentsSubject.find_all_by_student_id(@student.id,:conditions=>"batch_id = #{batch.id}") %>
              <% elective_subjects = [] %>
              <% student_electives.each do |elect| %>
                <% elective_subjects.push Subject.find(elect.subject_id) %>
              <% end %>
              <% @subjects = general_subjects + elective_subjects %>
              <% @subjects.reject!{|s| (s.no_exams==true or s.no_exam_for_batch(batch.id))} %>
              <% unless @subjects.empty? %>
                <h3><%= batch.full_name %></h3>
                <% total_credits=0 %>
                <table id="pdf-table" width="100%" cellspacing="0">
                  <% c= 'even' %>
                  <tr class="table-header">
                    <td><%= t('subject_code') %></td>
                    <td><%= t('subject_title') %></td>
                    <% if grade_type=="GPA" or grade_type=="CWA" %>
                      <td><%= t('credit') %></td>
                      <td><%= t('marks') %></td>
                    <% else %>
                      <td><%= t('percentage') %>(%)</td>
                    <% end %>
                  </tr>
                  <% @subjects.each do |s| %>
                    <% subject_average = GroupedExamReport.find_by_student_id_and_subject_id_and_score_type(@student.id,s.id,"s") %>
                    <% unless subject_average.nil? %>
                      <tr class="<%= cycle(c,(["odd","even"]-[c]).first) %>">
                        <% if @student.has_retaken_exam(s.id) %>
                          <td class="col-pdf"> <%= s.code %> - <label class="infolbl"><%= t('retaken') %></label></td>
                        <% else %>
                          <td class="col-pdf"> <%= s.code %></td>
                        <% end %>
                        <td class="col-pdf"> <%= s.name %></td>
                        <% if grade_type=="GPA" or grade_type=="CWA" %>
                          <td class="col-pdf"><%= s.credit_hours %></td>
                          <% total_credits = total_credits + s.credit_hours.to_f %>
                        <% end %>
                        <td class="col-pdf"><%= subject_average.present? ? subject_average.marks : "-" %></td>
                      </tr>
                    <% end %>
                  <% end %>
                  <% if grade_type=="GPA" or grade_type=="CWA" %>
                    <tr class="table-header">
                      <td colspan="2" align="right"><%= t('total') %></td>
                      <td><%= total_credits %></td>
                      <td>-</td>
                    </tr>
                  <% end %>
                </table>
                <% unless st_mark.nil? %>
                  <% mark = st_mark.marks || 0 %>
                <% else %>
                  <% mark=0 %>
                <% end %>
                <% grades << mark %>
                <% if grade_type=="CWA" %>
                  <h5><%= t('combined_weighted_average') %> = <%= mark==0 ? "-" : mark %></h5>
                <% elsif grade_type=="GPA" %>
                  <h5><%= t('batch_wise_cumulative_grade_point_average') %> = <%= mark==0 ? "-" : mark %></h5>
                <% else %>
                  <h5><%= t('combined_percentage') %> = <%= mark==0 ? "-" : mark %></h5>
                <% end %>
              <% end %>
            <% end %>
          <% end %>
          <div class="class-designations">
            <% unless grades.count.to_f == 0 %>
              <% cgpa = (grades.sum.to_f)/(grades.count.to_f) %>
            <% else %>
              <% cgpa = 0 %>
            <% end %>
            <% if grade_type=="GPA" %>
              <% designations = ClassDesignation.find(:all,:conditions=>["cgpa <= ? AND course_id = ?",cgpa,@student.batch.course_id],:order=>"cgpa DESC") %>
              <h5 align="right"><%= t('course_wise_cumulative_grade_point') %> = <span class="high"><%= "%.2f" %(cgpa) %></span></h5>
            <% else %>
              <% designations = ClassDesignation.find(:all,:conditions=>["marks <= ? AND course_id = ?",cgpa,@student.batch.course_id],:order=>"marks DESC") %>
              <% if grade_type=="CWA" %>
                <h5 align="right"><%= t('course_wise_combined_weighted_average') %> = <span class="high"><%= "%.2f" %(cgpa) %></span></h5>
              <% else %>
                <h5 align="right"><%= t('course_wise_combined_percentage') %> = <span class="high"><%= "%.2f" %(cgpa) %></span></h5>
              <% end %>
            <% end %>
            <h5 align="right"><%= t('class_designations_text') %> : <span class="high"><%= designations.empty? ? "-" : designations.first.name %></span></h5>
          </div>
        <% end %>
      </div>
    </div>
  </div>