
<style>
    @media print { 
        @page{
            font-family:Verdana, Geneva, sans-serif;
            size:letter; 
            marks: none;
            margin-left: 1cm;
            margin-right: 1.5cm;
            margin-top: 10mm;
            margin-bottom: 5mm;
        }
    }

</style>
<?php
# General Acaweb 
$dtsFecha = fechaTexto(date("Y-m-d"), true);

$tmplEncabezado = '<table align="center" class="print-encabezado" cellspacing="0" cellpadding="0"  style="font-size:12px !important;  font-family:arial,tahoma,verdana">'
        . '<tr>'
        . '<td width="20%" rowspan="5"><img src="../images/logo_colegio.png" width="{ancho}" height="{alto}" ></td>'
        . '<td align="center"  width="60%" style="font-size:12pt;" ><b>{nom_colegio}</b></td><td   width="20%" rowspan="5"></td>'
        . '</tr>'
        . '<tr>
            <td align="center" >Reconocimiento Oficial {decreto}</td><td></td></tr>'
        . '<tr>
            <td align="center"  >CODIGO DANE: {dane}</td><td></td></tr>'
        . '<tr>
            <td align="center" >{educacol}</td><td></td></tr>'
        . '<tr>
            <td align="center" >Putumayo - Colombia</td><td></td></tr>'
        . '</table>';

$cabestudiante = '<div  style="font-size:12pt; font-family:arial,tahoma,verdana">'
        . '<p align="center" style="font-size:15pt; font-family:arial"><b>REGISTRO ACADEMICO</b></p>'
        . '<p align="center" style="font-size:14pt; ">AÑO ESCOLAR ' . $anio . '</p>';

$infoEst = '<table class="table-print font-size-12" style="font-family:copperplate_gothic_lightRg, verdana">';
$infoEst.= '<tr class="alto-30">'
        . '<td class="font-size-10" width="190px" >APELLIDOS Y NOMBRES</td>'
        . '<td class="font-size-12" colspan="4" style="font-family: algerian, verdana">{estudiante}</td>'
        . '</TR>'
        . '<tr class ="alto-30">'
        . '<td class="font-size-10">IDENTIFICACION</td>'
        . '<td class="font-size-12" colspan="2">{abrev_tipo_ident} {numero_documento} de {lug_expedicion}</td>'
        . '<td class="font-size-10">GRADO</td>'
        . '<td class="font-size-12" >{grado}</td>'
        . '</tr></table><br>';

$sqlAdm = 'SELECT CONCAT_WS(" ",no1_adtivo, no2_adtivo, ape1_adtivo, ape2_adtivo) AS nom_apes FROM   adm_administrativos   WHERE cod_cargo=3 LIMIT 1';

$academia->instruccion($sqlAdm);
$regAdm = $academia->extraer_registro();
$academia->liberar();
$nomSec = !empty($regAdm['nom_apes']) ? $regAdm['nom_apes'] : '';
$sql = "CALL SP_CERTIFICADOS_NOTAS('$codigosest',$grupo,'" . uniqid() . "')";

if ($sesion->get('ac_usuario') == 'prointel') {
    echo '<div style="visibility: hidden;">' . $sql . '</div>';
}

$academia->instruccion($sql);
$i = 1;

$parse = new CI_Parser();
$nomColegio = mb_strtoupper($sesion->getVar('info_colegio.nombre'));
$educacol = mb_strtoupper($sesion->getVar('info_colegio.educacion'));
$decreto = strtoupper($sesion->getVar('info_colegio.decreto'));
$nit = strtoupper($sesion->getVar('info_colegio.nit'));
$rector = mb_strtoupper($sesion->getVar('info_colegio.rector'));
$trato = $sesion->getVar('info_colegio.trato');
$dane = strtoupper($sesion->getVar('info_colegio.dane'));
$pie = $sesion->getVar('info_colegio.pie');

$fotter = $dtsLang['project']['nom_soft'] . ' ' . $dtsLang['project']['ver_soft'] . ' ' . $dtsLang['project']['footertext'];
$pie_pagina = getFotter('&nbsp;', $pie, $fotter);

$codMateria = -1;
$dtsEncabezado = array(
    'nom_colegio' => $nomColegio,
    'educacol' => $educacol,
    'decreto' => $decreto,
    'nit' => $nit,
    'dane' => $dane,
    'alto' => $alto,
    'ancho' => $ancho,
);
$encabezadoOficio = $parse->parse($tmplEncabezado, $dtsEncabezado, true);

while ($reg = $academia->extraer_registro()) {
    $estudiante = json_decode($reg['estudiante'], true);
    $notas = json_decode($reg['notas'], true);
    $disciplina = json_decode($reg['disciplina'], true);
    $observa = json_decode($reg['observa'], true);
    $faltas = json_decode($reg['faltas'], true);

    $dtsEsquema = array(
        'estudiante' => formatoPalabras($estudiante['no_est'], $formato_nombres),
        'genero' => $estudiante['genero'],
        'tipo_documento' => $estudiante['tipo_iden'],
        'numero_documento' => $estudiante['numdoc'],
        'lug_expedicion' => $estudiante['expedida'],
        'grado' => $nomgrado,
        'educacion' => ucwords($educacion),
        'decreto' => mb_strtolower($decreto),
        'nom_colegio' => $nomColegio,
        'abrev_tipo_ident' => $estudiante['abrev_tipo_iden'],
    );
    echo $encabezadoOficio;
    echo $cabestudiante;
    echo $parse->parse($infoEst, $dtsEsquema, true);
#echo json_encode($notas,true);
    echo '<table class="table-print font-size-12" style="font-family: verdana">';
    echo '<tr class="alto-30"  style="text-align: center">'
    . '<th class="font-size-10" ROWSPAN="3">ASIGNATURA</th>'
    . '<th class="font-size-10" COLSPAN="8">PERIODOS</th>'
    . '<th class="font-size-10" COLSPAN="2">FINAL</th>'
    . '<th class="font-size-10" COLSPAN="8">INASISTENCIAS</th>'
    . '<th class="font-size-10" COLSPAN="2">TOTAL</th>'
    . '<tr style="text-align: center">'
    . '<td COLSPAN="2">1</td>'
    . '<td COLSPAN="2">2</td>'
    . '<td COLSPAN="2">3</td>'
    . '<td COLSPAN="2">4</td>'
    . '<td ROWSPAN="2">N</td>'
    . '<td ROWSPAN="2">D</td>'
    . '<td COLSPAN="2">1</td>'
    . '<td COLSPAN="2">2</td>'
    . '<td COLSPAN="2">3</td>'
    . '<td COLSPAN="2">4</td>'
    . '<td ROWSPAN="2">J</td>'
    . '<td ROWSPAN="2">I</td>'
    . '</tr>'
    . '<tr style="text-align: center">'
    . '<td>N</td><td>D</td>'
    . '<td>N</td><td>D</td>'
    . '<td>N</td><td>D</td>'
    . '<td>N</td><td>D</td>'
    . '<td>J</td><td>I</td>'
    . '<td>J</td><td>I</td>'
    . '<td>J</td><td>I</td>'
    . '<td>J</td><td>I</td>'
    . '</tr>';



    foreach ($notas as $info) {
        foreach ($info['materias'] as $materia) {
            echo '<tr style="text-align: center">'
            . '<td class="alto-20"  style="text-align: left">' . formatoPalabras(mb_strtolower($materia['no_asi'], 'UTF-8'), $formato_materias) . '</td>';
            foreach ($materia['Historicos'] as $notaPerido) {
                $notaPerido = explode("|", $notaPerido);

                echo '<td>' . numberFormat($notaPerido[0], 1) . '</td>';
                echo '<td>' . (!empty($notaPerido[1]) ? $notaPerido[1] : '') . '</td>';
            }

            echo '<td align="center" style="font-family:copperplate_gothic_lightRg, verdana">' . numberFormat($materia['definitiva']) . '</td>'
            . '<td align="center" style="font-family:copperplate_gothic_lightRg, verdana">' . $materia['definitivalet'] . '</td>';
            $i = 1;
            $tinjus=0;
            $tjus=0;
            foreach ($materia['Historicos'] as $notaPerido) {
                $faltas = $materia['Inasistencias'];
                $jus = $faltas['Justificadas'];
                $injus = $faltas['Injustificadas'];
                $nro = '';
                echo '<td>' . (isset($jus['p' . $i]) ? $jus['p' . $i] : '') . '</td>';
                echo '<td>' . (isset($injus['p' . $i]) ? $injus['p' . $i] : '') . '</td>';
                $tinjus+=(isset($injus['p' . $i]) ? $injus['p' . $i] : 0);
                $tjus+=(isset($jus['p' . $i]) ? $jus['p' . $i] : 0);
                $i++;
            }

            echo '<td>'.$tjus.'</td>'
            . '<td>'.$tinjus.'</td>'
            . '</tr>';
        }
    }
//    echo '<tr>'
//            . '<td class="alto-20">Comportamiento Social</td>'
//            . '<td align="center" colspan="3">' . $disciplina['notadisletra'] . '</td>'
//            . '</tr>';
    echo '</table>';
    
    echo '<br><table class="table-print font-size-12">';
    echo '<tr><td><b>OBSERVACIONES:</b></td>';
    echo '</tr>';
    echo '<tr><td>' . $observa['observaciones'] . "<br></td></tr></table>";
    ?>
    <br>
    <b>Convensiones:</b> <b>N</b> = Nota  <b>D</b> = Desempeño  <b>F</b> = Final  <b>J</b> = Justificada  <b>I</b> = Injustificado <br>
    <table>
        <tr>
            <td>
                <table>
                    <tr>
                        <td>PROMOVIDO AL GRADO</td>
                        <td style="border: 1px solid #000;  width: 50px"></td>
                    </tr>
                </table>
            </td>
            <td>
                <table>
                    <tr>
                        <td>REPROBADO</td>
                        <td style="border: 1px solid #000; width: 30px"></td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>

    <?php
    


    echo '<br><br><br><br>';
    ?>
    <table width="100%" style="width: 100%">
        <tr>
            <td style="text-align: center; width: 50%">
                _______________________________<br>
                <?php echo $rector . "<br>" . $trato ?>

            </td>
            <td style="text-align: center; width: 50%">
                _______________________________<br>
                <?php echo $nomSec . "<br>" . Secretaria ?>
            </td>
        </tr>
    </table>
    <?php
#    Falta poner la firma de la secretaria

    echo '</div>';
    echo $pie_pagina
    . '<div id="salto" class="salto"></div>'; //hace que al imprimir salga en hojas apartes
}
$academia->liberar();
$academia->cerrar();
