<?php $__env->startSection('title-page'); ?> Calificaciones <?php $__env->stopSection(); ?>



<?php $__env->startSection('aside'); ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>

<?php
function truncate_decimal($value, $precision) {
  //Casts provided value
  $value = ( string )$value;

  //Gets pattern matches
  preg_match( "/(-+)?\d+(\.\d{1,".$precision."})?/" , $value, $matches );

  //Returns the full pattern match
  return $matches[0];
}
?>
<div class="row">
  <div class="col-md-12">
    <div class="panel panel-default " id="datagrid-modulo" data-edit-row="editar">
      <div class="panel-heading"> <h3><i class="fa fa-mortar-board"></i> Calificaciones</h3> </div>
      <?php if($alumno->inscripcion != null): ?>
      <div class="panel-body " style="text-align:center">
        <h4><?php echo $alumno->inscripcion->grupo->planEstudios->Nombre; ?></h4>
      </div>
      <?php else: ?>
      <div class="panel-body " style="text-align:center">
        <h4>No tiene inscripciones disponibles</h4>
      </div>
      <?php endif; ?>
      <?php if(count($calificaciones) > 0): ?>
      <?php
        $puntero = null;
        $promedio_acumulado = 0;
        $contador_materias = 0; //EL 1 DE JUNIO DE 2018 LE CAMBIE DE 1 A 0 ME ESTABA CALCULANDO MAL EL PROMEDIO DEL ULTIMO SEMESTRE
        $promedio_general_acumulado = 0;
        $contador_semestres = 0;
       $promedio = 0;
       ?>
       <?php if($alumno->inscripcion->CveNivel == 4 ): ?>
        <?php foreach($calificaciones as $calificacion): ?>
          <?php if($puntero == null): ?>
          <table class="table">
          <thead>
            <tr >
              <th style="text-align:center" width="160px">Semestre</th><th>Asignatura</th>
              <th  style="text-align:center" width="45px">P1</th><th  style="text-align:center" width="45px">IN1</th>
              <th  style="text-align:center" width="45px">P2</th><th  style="text-align:center" width="45px">IN2</th>
              <th  style="text-align:center" width="45px">P3</th><th  style="text-align:center" width="45px">IN3</th>
              <th  style="text-align:center" width="45px">EF</th><th  style="text-align:center" width="45px">CF</th>
              <th  style="text-align:center" width="45px">INT</th><th  style="text-align:center" width="45px">EX</th>
              <th  style="text-align:center" width="45px">ATS</th>
            </tr>
          </thead>
          <tbody>
          <?php endif; ?>
          <?php if($puntero != $calificacion->Semestre && $puntero != null): ?>
            <?php
              $puntero = $calificacion->Semestre;
      	      $promedio = $promedio_acumulado / $contador_materias;
      	      $promedio = truncate_decimal($promedio, 1);
      	      $promedio = 0;
              $promedio_acumulado = 0;
              $contador_materias = 0;
              $contador_semestres++;
              $promedio_general_acumulado += $promedio;
              ?>
            <tfoot>
              <tr>
              <th colspan="9" style="text-align:right">Promedio Semestral</th>
              <th><?php echo number_format($promedio,1); ?></th>
              <th colspan="3"></th>
            </tr>
            </tfoot>

            </tbody>
            </table>
            <br>
            <table class="table">
            <thead>
              <tr >
              <th style="text-align:center" width="160px">Semestre</th><th>Asignatura</th>
              <th  style="text-align:center" width="45px">P1</th><th  style="text-align:center" width="45px">IN1</th>
              <th  style="text-align:center" width="45px">P2</th><th  style="text-align:center" width="45px">IN2</th>
              <th  style="text-align:center" width="45px">P3</th><th  style="text-align:center" width="45px">IN3</th>
              <th  style="text-align:center" width="45px">EF</th><th  style="text-align:center" width="45px">CF</th>
              <th  style="text-align:center" width="45px">INT</th><th  style="text-align:center" width="45px">EX</th>
              <th  style="text-align:center" width="45px">ATS</th>
            </tr>
            </thead>
            <tbody>
          <?php endif; ?>
            <?php
              if($calificacion->Calificacion > 6)
                $promedio_acumulado += $calificacion->Calificacion;
              else
              {
                if($calificacion->ExtraOrdinario > 5)
                  $promedio_acumulado += $calificacion->ExtraOrdinario;
                else if ($calificacion->AtituloDeSuficiencia > 5)
                  $promedio_acumulado += $calificacion->AtituloDeSuficiencia;
                else
                  $promedio_acumulado += $calificacion->Calificacion;
              }
              $puntero = $calificacion->Semestre;
              $contador_materias++;
          ?>
          <tr align="center">
            <td width="95px"><?php echo $calificacion->Semestre; ?></td>
            <td align="left"><?php echo $calificacion->Asignatura; ?></td>
            <td><?php if($calificacion->ParcialUno > 0): ?>  <?php echo number_format($calificacion->ParcialUno, 1); ?> <?php endif; ?></td>
            <td><?php echo $calificacion->InasistenciasUno; ?></td>
            <td><?php if($calificacion->ParcialDos > 0): ?> <?php echo number_format($calificacion->ParcialDos, 1); ?> <?php endif; ?></td>
            <td><?php echo $calificacion->InasistenciasDos; ?></td>
            <td><?php if($calificacion->ParcialTres > 0): ?> <?php echo number_format($calificacion->ParcialTres, 1); ?> <?php endif; ?></td>
            <td><?php echo $calificacion->InasistenciasTres; ?></td>
            <td><?php if($calificacion->ParcialTres > 0): ?> <?php echo number_format($calificacion->ExamenFinal, 1); ?> <?php endif; ?></td>
            <?php if($calificacion->Estatus == 4): ?>
            <td><strong>NP</strong></td>
            <?php else: ?>
            <td><?php echo number_format($calificacion->Calificacion, 1); ?></td>
            <?php endif; ?>
            <td><?php echo $calificacion->InasistenciasUno + $calificacion->InasistenciasDos + $calificacion->InasistenciasTres; ?></td>
            <td><?php if($calificacion->ExtraOrdinario > 0): ?> <?php echo number_format($calificacion->ExtraOrdinario, 1); ?> <?php endif; ?></td>
            <td><?php if($calificacion->AtituloDeSuficiencia > 0): ?> <?php echo number_format($calificacion->AtituloDeSuficiencia, 1); ?> <?php endif; ?></td>
          </tr>
        <?php endforeach; ?>
        <?php
          $promedio = $promedio_acumulado / $contador_materias;
          $promedio = truncate_decimal($promedio, 1);
          $contador_semestres++;
          $promedio_general_acumulado += $promedio;
          ?>
        <tfoot>
          <tr>
          <th colspan="9" style="text-align:right">Promedio Semestral</th>
          <th><?php echo number_format($promedio,1); ?></th>
          <th colspan="3"></th>
        </tr>
        </tfoot></tbody></table>
        <hr>
        <table class="table" style="font-size:1.2em">
        <tr><th style="text-align:right">Promedio General</th><th width="45px" style="text-align:center"><?php echo number_format($promedio_general_acumulado / $contador_semestres,1); ?></th><th width="135px"></th></tr>
        </table>
        <hr>
       <?php else: ?>
        <?php foreach($calificaciones as $calificacion): ?>
          <?php if($puntero == null): ?>
          <table class="table">
          <thead><tr><th style="text-align:center" width="160px">Semestre</th><th>Asignatura</th><th style="text-align:center" width="100px">Calificación</th></tr></thead>
          <tbody>
          <?php endif; ?>
          <?php if($puntero != $calificacion->Semestre && $puntero != null): ?>
            <?php
              $puntero = $calificacion->Semestre;
              $promedio = $promedio_acumulado / $contador_materias;
              $promedio = truncate_decimal($promedio, 1);
	//	$promedio = $contador_materias;
              $promedio_acumulado = 0;
              $contador_materias = 0;
              $contador_semestres++;
              $promedio_general_acumulado += $promedio;
              ?>
            <tfoot>
              <tr>
              <th colspan="2" style="text-align:right">Promedio Semestral</th>
              <th style="text-align:center"><?php echo number_format($promedio,1); ?></th>
            </tr>
            </tfoot>

            </tbody>
            </table>
            <br>
            <table class="table">
            <thead><tr><th style="text-align:center" width="160px">Semestre</th><th>Asignatura</th><th style="text-align:center" width="100px">Calificación</th></tr></thead>
            <tbody>
          <?php endif; ?>
            <?php
              $promedio_acumulado += $calificacion->Calificacion;
              $puntero = $calificacion->Semestre;
              $contador_materias++;
          ?>
        <tr align="center">
          <td><?php echo $calificacion->Semestre; ?></td>
          <td align="left"><?php echo $calificacion->Asignatura; ?></td>
          <?php if($calificacion->Estatus == 4): ?>
          <td><strong>NP</strong></td>
          <?php else: ?>
          <td><?php echo $calificacion->Calificacion; ?></td>
          <?php endif; ?>
        </tr>
        <?php endforeach; ?>
        <?php
  		$promedio = $promedio_acumulado / $contador_materias;
	?>
        <tfoot>
          <tr>
          <th colspan="2" style="text-align:right">Promedio Semestral</th>
          <th style="text-align:center"  ><?php echo number_format($promedio,1); ?></th>
          </tr>
        </tfoot></tbody></table>

        <hr>
        <table class="table" style="font-size:1.2em">
          <?php if($contador_semestres > 0): ?>
        <tr><th style="text-align:right">Promedio General</th><th width="100px" style="text-align:center"><?php echo number_format($promedio_general_acumulado / $contador_semestres,1); ?></th></tr>
          <?php endif; ?>
        </table>
        <hr>
       <?php endif; ?>


      <div class="row">
        <div class="col-md-12">
          <div style="text-align:justify; padding:1em;">
            <h5>Nomenclatura:</h5>
            <p>
              <?php if($alumno->inscripcion->CveNivel == 1): ?>
              <strong>P1</strong> 1° Parcial <strong>P2</strong> 2° Parcial <strong>P3</strong> 3° Parcial <strong>IN1</strong> Inasistencias 1° Parcial <strong>IN2</strong> Inasistencias 2° Parcial <strong>IN3</strong> Inasistencias 3° Parcial
  <strong>EF</strong> Examen Final <strong>CF</strong> Calificacion Final <strong>INT</strong> Inasistencias Totales <strong>EX</strong> Extraordinario <strong>ATS</strong> Atitulo de Suficiencia
              <?php endif; ?>
              <strong>NP</strong> No presentó
            </p>
          </div>
        </div>
      </div>

      <div class="panel-footer" style="text-align:center" >
        <div class="col-md-12" >
          <a href="<?php echo URL::to('imprimir-calificaciones'); ?>" target="_blank" class="btn btn-primary" > <i class="fa fa-print"></i> Imprimir Calificaciones</a> <br><br>
        </div>
        <small>
          <i class="fa fa-question-circle"></i> Los datos mostrados son de carácter informativo, para cualquier duda o aclaración, contactar directamente en oficinas.
        </small>
      </div>
      <?php else: ?>
      <div class="panel-body" style="text-align:center">
        No hay Calificaciones
      </div>
      <?php endif; ?>

    </div>
  </div>
</div>




<?php $__env->stopSection(); ?>


<?php $__env->startSection('modals'); ?>
@parent
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.Modulo', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>