<%-# 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. -%>

<% scholastic = @report.scholastic %>
<% cgpa=0.0 %>
<% count=0 %>
<div class="info">
  <div class="info-left">
    <div class="info1">
      <label class="field-label">Name</label>: <label class="infolbl themed_text"> <%= @student.full_name %></label>
    </div>
    <div class="info1">
      <label class="field-label">Course</label>: <label class="infolbl themed_text"> <%= @batch.course.full_name %></label>
    </div>
  </div>
  <div class="info-right">
    <div class="info1">
      <label class="field-label">Adm No.</label>: <label class="infolbl themed_text"> <%= @student.admission_no.present? ? @student.admission_no : "-" %></label>
    </div>
    <div class="info1">
      <label class="field-label">Batch</label>: <label class="infolbl themed_text"> <%= @batch.name %></label>
    </div>
  </div>
</div>
<div id="score-table">
  <div class="custom_header">
    Scholastic Areas
  </div>
  <table id="listing" width="100%">
    <% if @exam_groups.empty? %>
      <tr class="tr-head">
        <td>No Exams </td></tr>
    <% else %>
      <tr class="tr-head">
        <td>Sl no</td>
        <td></td>
        <% @exam_groups.each do |eg| %>
          <td colspan="4"><%= eg.cce_exam_category.name %></td>
        <% end %>
        <% if @exam_groups.count==2 %>
          <td colspan="4">Overall</td>
        <% end %>
      </tr>
      <tr class="tr-head">
        <td></td>
        <td>Subjects</td>
        <% @exam_groups.each_with_index do |eg,i| %>
          <td><%= "FA#{2*i+1}" %></td>
          <td><%= "FA#{2*i+2}" %></td>
          <td><%= "SA#{i+1}" %></td>
          <td><%= "FA#{2*i+1}+ FA#{2*i+2}+ SA#{i+1}" %></td>
        <% end %>
        <% if @exam_groups.count==2 %>
          <td>FA1+ FA2+ FA3+ FA4</td>
          <td>SA1+ SA2</td>
          <td>Overall</td>
          <td>Grade Point</td>
        <% end %>
      </tr>
      <% @subjects.each_with_index do |s,i| %>
        <tr class="center tr-<%= cycle('odd', 'even') %>">
          <td><%= i+1 %></td>
          <td class="left-aligned"><%= s.name %></td>
          <% sub=scholastic.find{|c| c.subject_id==s.id} %>
          <% @exam_groups.each do |eg|
            se=sub.exams.find{|g| g.exam_group_id==eg.id} if sub %>
            <% if se %>
              <td><%= se.fa[se.fa_group_ids[0]] if se.fa_group_ids[0] %></td>
              <td><%= se.fa[se.fa_group_ids[1]] if se.fa_group_ids[1] %></td>
              <td><%= se.sa %></td>
              <td><%= se.overall %></td>
            <% else %>
              <td>-</td>
              <td>-</td>
              <td>-</td>
              <td>-</td>
            <% end %>
          <% end %>
          <% if @exam_groups.count==2 %>
            <% if sub %>
              <td><%= sub.fa %></td>
              <td><%= sub.sa %></td>
              <td><%= sub.overall %></td>
              <td><%= sub.grade_point %></td>
              <% if s.elective_group_id.blank? %>
                <% cgpa += sub.grade_point.to_f %>
                <% count += 1 %>
              <% end %>
            <% else %>
              <td>-</td>
              <td>-</td>
              <td>-</td>
              <td>-</td>
            <% end %>
          <% end %>
        </tr>
      <% end %>
    <% end %>
  </table>
  <% if @exam_groups.count==2 %>
    <div class="custom_header">
      <span class="cgpa themed_text">Cumulative Grade Point Average(CGPA)  :   <%= cgpa/count unless count==0 %></span>
    </div>
  <% end %>
</div>
<% @co_hashi.keys.sort.each do |kind| %>
  <div class="custom_header">
    <%= ObservationGroup::OBSERVATION_KINDS[kind] %>
  </div>
  <% @co_hashi[kind].each do |ob_grp| %>
    <div id="score-table">
      <div class="custom_header">
        <%= @obs_groups.find{|o| o.id == ob_grp.observation_group_id}.try(:name) %>
      </div>
      <table id="listing" width="100%">
        <tr class="tr-head">
          <td class="left-aligned">Descriptive Indicators</td>
          <td class="left-aligned">Grade</td>
        </tr>
        <% ob_grp.observations.sort_by(&:sort_order).each do |o| %>
          <tr class="tr-<%= cycle('odd', 'even') %>">
            <td class="left-10"><%= o.observation_name %></td>
            <td class="left-10"><%= o.grade %></td>
          </tr>
        <% end %>
      </table>
    </div>
  <% end %>
<% end %>
<%= link_to "► PDF Report",{:action=>"student_report_pdf",:id=>@student.id,:batch_id=>@batch.id,:type=>@type},:target => '_blank', :class=> 'user_button' %>