<?php
/* @var $this ReportescontablesController */

//TOMAMOS TODAS LAS VARIABLES QUE VIENEN DE LA PANTALLA
$filtro_id_cuenta_desde = $model->id_cuenta_desde;
$filtro_id_cuenta_hasta = $model->id_cuenta_hasta;
$filtro_fecha_desde = $model->fecha_desde;
$filtro_fecha_hasta = $model->fecha_hasta;
$filtro_nivel = $model->nivel;
$filtro_sin_ceros = $model->sin_ceros;
//echo $filtro_sin_ceros; exit;

//Vamos a buscar los dias primero y ultimo de dicho rango (trimestre)
//if ($filtro_trimestre==1):
//
//    $filtro_trimestre_ant = 4; //trimestre anterior
//    $filtro_anyo_ant = $filtro_anyo-1; //año del trimestre anterior
//else:
//    $filtro_trimestre_ant = $filtro_trimestre-1;
//    $filtro_anyo_ant = $filtro_anyo;
//endif;
//
//$mes_ultimo_trimestre = $filtro_trimestre*3;
//$mes_primero_trimestre = ($mes_ultimo_trimestre - 3)+1;
//
//$mes_ultimo_trimestre_ant = $filtro_trimestre_ant*3;
//$mes_primero_trimestre_ant = ($mes_ultimo_trimestre_ant-3)+1;
//
//$fecha_hasta_trimestre = date('Y-m-t', strtotime($filtro_anyo.'-'.$mes_ultimo_trimestre.'-01'));
//$fecha_desde_trimestre = $filtro_anyo.'-'.$mes_primero_trimestre.'-01';
//
//$fecha_hasta_trimestre_ant = date('Y-m-t', strtotime($filtro_anyo_ant.'-'.$mes_ultimo_trimestre_ant.'-01'));
//$fecha_desde_trimestre_ant = $filtro_anyo_ant.'-'.$mes_primero_trimestre_ant.'-01';
//
//if ($filtro_trimestre==5):
//    $fecha_desde_trimestre = $filtro_anyo.'-01-01';
//    $fecha_hasta_trimestre = date('Y-m-d', strtotime($filtro_anyo.'-12-31'));
//    $fecha_hasta_trimestre_ant = date('Y-m-d', strtotime('2014-01-01'));
//    $fecha_desde_trimestre_ant = '2014-12-31';
//endif;

//echo "Primer trimestre: " . $fecha_desde_trimestre_ant . " - " . $fecha_hasta_trimestre_ant;
//////echo "<br/> Trimestre anterior: " . $fecha_desde_trimestre_ant . " - " . $fecha_hasta_trimestre_ant;
//exit();

//echo "<pre>".print_r($model,true)."</pre>"; die();

if ($filtro_id_cuenta_desde != null && $filtro_id_cuenta_hasta != null):
    //$where_cuenta = " AND id BETWEEN $filtro_id_cuenta_desde AND $filtro_id_cuenta_hasta ";
    $where_cuenta = " AND cuenta BETWEEN '${filtro_id_cuenta_desde}' AND '${filtro_id_cuenta_hasta}' AND titulo_mov = 2 OR (titulo_mov = 1 AND cuenta BETWEEN '1' AND '${filtro_id_cuenta_hasta}')";
    $where_total_cuenta = " AND cuenta BETWEEN '${filtro_id_cuenta_desde}' AND '${filtro_id_cuenta_hasta}' ";
//    echo $where_cuenta; die();
endif;

if ($filtro_fecha_desde != null && $filtro_fecha_hasta != null):
    //$where_cuenta = " AND id BETWEEN $filtro_id_cuenta_desde AND $filtro_id_cuenta_hasta ";
    $where_fecha = " AND fecha_comprobante BETWEEN '${filtro_fecha_desde}' AND '${filtro_fecha_hasta}' ";
    //$where_total_cuenta = " AND cuenta BETWEEN '$filtro_id_cuenta_desde' AND '$filtro_id_cuenta_hasta' ";
    //echo $where_fecha; die();
endif;

if ($filtro_fecha_desde != null):
    //$where_cuenta = " AND id BETWEEN $filtro_id_cuenta_desde AND $filtro_id_cuenta_hasta ";
    $where_fecha_ant = " AND fecha_comprobante < '${filtro_fecha_desde}' ";
    //$where_total_cuenta = " AND cuenta BETWEEN '$filtro_id_cuenta_desde' AND '$filtro_id_cuenta_hasta' ";
    //echo $where_fecha; die();
endif;

//echo "<pre>El valor es: ".$filtro_nivel."</pre>"; die();

if ($filtro_nivel != null):
    $where_nivel = ' AND nivel <= '.$filtro_nivel.' ';
endif;

if ($model->excluir_movimiento_cierre) {
    $movimiento_cierre = ' AND id_tipo_comprobante=1';
} else {
    $movimiento_cierre = ' AND (id_tipo_comprobante=1 OR id_tipo_comprobante=3)';
}

//'nivel'=>'digitos'
$config_contable = ['0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 5, '5' => 7, '6' => 9, '7' => 11];

$pdf = Yii::createComponent('application.extensions.mpdf60.mpdf');

ob_start();
?>
<style type="text/css">
     
    .cabecera{
        text-align: center; 
        font-weight: bold;
        font-size: 10px;   
        width: 100%;
    }
    
    .titulo{
        text-align: center; 
        font-weight: bold;
        border: 1px solid black;
    }
    
    .cuenta_alto_nivel{
        text-transform: uppercase;
        font-weight: bold;
        border-top: 1px solid black;
        border-bottom: 1px solid black;
        padding-top: 10px;
    }
    
    .listado{
        font-size: 10px;     
    }
    .listado td{
        padding-left: 8px;
        padding-right: 8px;
    }
    
    .total{
        font-size: 10px;
        font-weight: bold;
        background-color: Gainsboro;
    }
    
    @media print {
        thead { display: table-header-group; }
    }
    
    table.firmas{

        width: 100%;
        border-spacing: 20px;
    }

    .firmas th{

        text-align: center;
    }

    .firmas tr td.lineas{

        border-bottom: 1px solid #000;
        padding-top: 30px;
    }

    .firmas tr td.info_lineas{

        text-align: center;
        font-size: 12px;
    }
    
</style>


<table class="listado" style="width: 100%;" border="0" cellpadding="0" cellspacing="0">
    
    <!--tr>
        <td style="width: 12%;"></td>
        <td style="width: 40%;"></td>
        <td style="width: 12%;"></td>
        <td style="width: 12%;"></td>
        <td style="width: 12%;"></td>
        <td style="width: 12%;"></td>
    </tr-->
    <!--tr>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
    </tr-->
    
    <?php
   //$model_plan_cuentas = CuentasConsolidada2015::model()->findAll(array('order'=>'cuenta ASC')); //Traemos el plan de cuentas contable
    $model_plan_cuentas = CuentasConsolidada::model()->findAll([
        //'select'=>'sum(monto_debe) as total_debe , sum(monto_haber) as total_haber, sum(monto_debe)-sum(monto_haber) as total_saldo ',
        'condition' => " blnborrado = FALSE AND SUBSTRING(cuenta from 1 for 1) IN ('4','5')  ".$where_cuenta.''.$where_nivel,
        'order' => 'cuenta ASC',
        //'params'=>array(':idcuenta'=>$cuenta->id,)
    ]);
//    echo "<pre>"; print_r($model_plan_cuentas); exit;
    ?>
    <thead>
        <tr>
            <th class="titulo" style="width: 16%;">Código</th>
            <th class="titulo" style="width: 36%;">Cuenta</th>
            <th class="titulo" style="width: 20%;">Anterior a <?=date('d-m-Y', strtotime($filtro_fecha_desde)); ?></th>
            <th class="titulo" style="width: 20%;"><?=date('d-m-Y', strtotime($filtro_fecha_desde)); ?> <br/><?=date('d-m-Y', strtotime($filtro_fecha_hasta)); ?></th>
            <th class="titulo" style="width: 16%;">Variación</th>
        </tr>
    </thead>
    <tbody>
   <?php

    $acum_total_anterior = 0;
    $acum_total_actual = 0;
    $acum_variacion = 0;

    foreach ($model_plan_cuentas as $cuenta): //Imprimimos cada cuenta
       if (($cuenta->cuenta[0] == 4 or $cuenta->cuenta[0] == 5) && $cuenta->nivel <= $filtro_nivel):
        //Buscamos el detalle de cada cuenta
        $ejercicio = EjerciciosContables::model()->find('activo=1');

         if ($filtro_trimestre == 1):
            //El detalle del trimestre anterior
            $model_total_anterior = DetalleAnalitico::model()->find([
                'select' => 'coalesce(sum(monto_debe), 0) - coalesce(sum(monto_haber), 0) as total_monto_anterior ',
                'condition' => "SUBSTRING('{$cuenta->cuenta}' from 1 for {$config_contable[$cuenta->nivel]}) = SUBSTRING(cuenta from 1 for {$config_contable[$cuenta->nivel]})
                                AND estatus_contab=1
                                AND activo=1
                                AND clvejercicio={$ejercicio->id}
                                AND blnborrado=FALSE
                                AND id_tipo_comprobante=2
                                {$where_total_cuenta}",
            ]);
         else:
            //El detalle del trimestre anterior
            $model_total_anterior = DetalleAnalitico::model()->find([
                'select' => 'coalesce(sum(monto_debe), 0) - coalesce(sum(monto_haber), 0) as total_monto_anterior ',
                'condition' => "SUBSTRING('{$cuenta->cuenta}' from 1 for {$config_contable[$cuenta->nivel]}) = SUBSTRING(cuenta from 1 for {$config_contable[$cuenta->nivel]})
                                AND estatus_contab=1
                                AND activo=1
                                AND clvejercicio={$ejercicio->id}
                                AND blnborrado = FALSE
                                {$movimiento_cierre}
                                {$where_total_cuenta}
                                {$where_fecha_ant}",
            ]);
         endif;

        //El detalle del trimestre actual
        $model_total = DetalleAnalitico::model()->find([
            'select' => "(select COALESCE(sum(monto_debe), 0) - COALESCE(sum(monto_haber), 0)
                            FROM contable.vsw_detalle_analitico t
                            where SUBSTRING('{$cuenta->cuenta}' from 1 for {$config_contable[$cuenta->nivel]}) = SUBSTRING(cuenta from 1 for {$config_contable[$cuenta->nivel]})
                                AND estatus_contab=1
                                AND activo=1
                                AND clvejercicio={$ejercicio->id}
                                AND blnborrado = FALSE
                                {$movimiento_cierre}
                                {$where_total_cuenta}
                                {$where_fecha_ant}
                            LIMIT 1)
                            + coalesce(sum(monto_debe), 0) - coalesce(sum(monto_haber), 0) as total_monto_actual",
            'condition' => "SUBSTRING('{$cuenta->cuenta}' from 1 for {$config_contable[$cuenta->nivel]}) = SUBSTRING(cuenta from 1 for {$config_contable[$cuenta->nivel]})
                            AND estatus_contab=1
                            AND activo=1
                            AND clvejercicio={$ejercicio->id}
                            AND blnborrado = FALSE
                            {$movimiento_cierre}
                            {$where_total_cuenta}
                            {$where_fecha}",
        ]);

        //REEMPLAZAR LOS NOMNRES DE LOS QUERY HECHOS ARRIBA PARA ANTERIOR Y ACTUAL
        //SACAR VARIACION
        //REFACTOR VARIABLES

        //Vamos a  buscar el saldo total sumandolo a la apertura
        $monto_anterior = ($model_total_anterior->total_monto_anterior) ? $model_total_anterior->total_monto_anterior : 0;
        $monto_actual = ($model_total->total_monto_actual) ? $model_total->total_monto_actual : 0;
        $monto_variacion = $monto_actual - $monto_anterior;

        //Verificamos si a la cuenta se le hacen movimientos
        $cta_mov = DetalleComprobante::model()->findByAttributes(['id_cuenta' => $cuenta->id]);

        if ($cta_mov != null): //Si es una cuenta de movimiento si sumo para el total del balance
            $acum_total_anterior += $monto_anterior;
            $acum_total_actual += $monto_actual;
            $acum_variacion += $monto_variacion;
        endif;

        //total de los activos
        if (trim($cuenta->cuenta[0]) == '4' && $cuenta->nivel == 1):
            $acum_ingresos_anterior += $monto_anterior;
            $acum_ingresos_actual += $monto_actual;
            $acum_ingresos_variacion += $monto_variacion;
        endif;

        //total de los pasivos
        if (trim($cuenta->cuenta[0]) == '5' && $cuenta->nivel == 1):
            $acum_egresos_anterior += $monto_anterior;
            $acum_egresos_actual += $monto_actual;
            $acum_egresos_variacion += $monto_variacion;
        endif;

        //formateo de la presentacion
        if ($model_total_anterior->total_monto_anterior < 0):
            $monto_anterior_f = number_format(($model_total_anterior->total_monto_anterior) * -1, 2, ',', '.');
            $monto_anterior_f = '('.$monto_anterior_f.')';
        else:
            $monto_anterior_f = number_format($model_total_anterior->total_monto_anterior, 2, ',', '.');
        endif;
        if ($model_total->total_monto_actual < 0):
            $monto_actual_f = number_format(($model_total->total_monto_actual) * -1, 2, ',', '.');
            $monto_actual_f = '('.$monto_actual_f.')';
        else:
            $monto_actual_f = number_format($model_total->total_monto_actual, 2, ',', '.');
        endif;
        if ($monto_variacion < 0):
            $monto_variacion_f = number_format(($monto_variacion) * -1, 2, ',', '.');
            $monto_variacion_f = '('.$monto_variacion_f.')';
        else:
            $monto_variacion_f = number_format($monto_variacion, 2, ',', '.');
        endif;

        //Si son los 3 primeros niveles la presentacion debe ser en mayusculas y negrita
        if (in_array($cuenta->nivel, [1, 2, 3])):
           $clase_cuenta = 'cuenta_alto_nivel';
           $cuenta->cuenta = strtoupper($cuenta->cuenta);
        else:
           $clase_cuenta = '';
        endif;

        if ($filtro_sin_ceros): //Cuentas sin movimiento (no mostrar = true)
            if (($monto_anterior + $monto_actual) == 0):
                $mostrar = false;
            else:
                $mostrar = true;
            endif;
        else:
            $mostrar = true;
        endif;
        if ($mostrar):
        ?>
            <tr>
                <td class="<?=$clase_cuenta; ?>" style="<?= $cuenta->titulo_mov == 1 ? 'font-weight: bold;' : ''; ?>"><?=$cuenta->cuenta; ?></td>
                <td class="<?=$clase_cuenta; ?>" style="<?= $cuenta->titulo_mov == 1 ? 'font-weight: bold;' : ''; ?>"><?=$cuenta->descripcion; ?></td>
                <td style="text-align: right; <?= $cuenta->titulo_mov == 1 ? 'font-weight: bold;' : ''; ?>" class="<?=$clase_cuenta; ?>"><?=$monto_anterior_f; ?></td>
                <td style="text-align: right; <?= $cuenta->titulo_mov == 1 ? 'font-weight: bold;' : ''; ?>" class="<?=$clase_cuenta; ?>"><?=$monto_actual_f; ?></td>
                <td style="text-align: right; <?= $cuenta->titulo_mov == 1 ? 'font-weight: bold;' : ''; ?>" class="<?=$clase_cuenta; ?>"><?=$monto_variacion_f; ?></td>
            </tr>   
        <?php
        endif;
      endif;
    endforeach;

    //formateo de la presentacion
    $total_anterior = number_format($acum_total_anterior, 2, ',', '.');
    $total_actual = number_format($acum_total_actual, 2, ',', '.');
    $total_variacion = number_format($acum_variacion, 2, ',', '.');

    //Obtenemos el patrimonio:
    $total_utilidad_anterior = $acum_ingresos_anterior - $acum_egresos_anterior * -1;
    $total_utilidad_actual = $acum_ingresos_actual - $acum_egresos_actual * -1;
    $total_utilidad_variacion = -$total_utilidad_anterior - $total_utilidad_actual * -1;
    ?>
    <tr>
        <td class="totalx" style="width: 16%; text-align: left;"><b>&nbsp;</b></td>
        <td class="totalx"  style="width: 36%; text-align: left;">&nbsp;</td>
        <td class="totalx"  style="width: 16%; text-align: right; ">&nbsp;</td>
        <td class="totalx"  style="width: 16%; text-align: right;">&nbsp;</td>
        <td class="totalx"  style="width: 16%; text-align: right;">&nbsp;</td>
    </tr>
       <?php
           // formateo ingresos
           if ($acum_ingresos_anterior < 0):
                    $acum_ingresos_anterior_f = '('.number_format($acum_ingresos_anterior * -1, 2, ',', '.').')';
                else:
                    $acum_ingresos_anterior_f = number_format($acum_ingresos_anterior * -1, 2, ',', '.');
               endif;
               if ($acum_ingresos_actual < 0):
                    $acum_ingresos_actual_f = '('.number_format($acum_ingresos_actual * -1, 2, ',', '.').')';
                else:
                    $acum_ingresos_actual_f = number_format($acum_ingresos_actual, 2, ',', '.');
               endif;
               if ($acum_ingresos_variacion < 0):
                    $acum_ingresos_variacion_f = '('.number_format($acum_ingresos_variacion * -1, 2, ',', '.').')';
                else:
                    $acum_ingresos_variacion_f = number_format($acum_ingresos_variacion, 2, ',', '.');
               endif;
           // formateo egresos
           if ($acum_egresos_anterior < 0):
                    $acum_egresos_anterior_f = '('.number_format($acum_egresos_anterior * -1, 2, ',', '.').')';
                else:
                    $acum_egresos_anterior_f = number_format($acum_egresos_anterior, 2, ',', '.');
               endif;
               if ($acum_egresos_actual < 0):
                    $acum_egresos_actual_f = '('.number_format($acum_egresos_actual * -1, 2, ',', '.').')';
                else:
                    $acum_egresos_actual_f = number_format($acum_egresos_actual, 2, ',', '.');
               endif;
               if ($acum_egresos_variacion < 0):
                    $acum_egresos_variacion_f = '('.number_format($acum_egresos_variacion * -1, 2, ',', '.').')';
                else:
                    $acum_egresos_variacion_f = number_format($acum_egresos_variacion, 2, ',', '.');
               endif;
           // formateo totales
           if ($total_utilidad_anterior < 0):
                    $total_utilidad_anterior_f = '('.number_format($total_utilidad_anterior * -1, 2, ',', '.').')';
                else:
                    $total_utilidad_anterior_f = number_format($total_utilidad_anterior, 2, ',', '.');
               endif;
               if ($total_utilidad_actual < 0):
                    $total_utilidad_actual_f = '('.number_format($total_utilidad_actual * -1, 2, ',', '.').')';
                else:
                    $total_utilidad_actual_f = number_format($total_utilidad_actual, 2, ',', '.');
               endif;
               if ($total_utilidad_variacion < 0):
                    $total_utilidad_variacion_f = '('.number_format($total_utilidad_variacion * -1, 2, ',', '.').')';
                else:
                    $total_utilidad_variacion_f = number_format($total_utilidad_variacion, 2, ',', '.');
               endif;
      ?>
      
      <tr>
        <td class="totalx" colspan="2" style="width: 16%; text-align: left;"><b>TOTAL INGRESOS</b></td>
        <td class="totalx"  style="width: 16%; text-align: right; "><?=$acum_ingresos_anterior_f; ?></td>
        <td class="totalx"  style="width: 16%; text-align: right;"><?=$acum_ingresos_actual_f; ?></td>
        <td class="totalx"  style="width: 16%; text-align: right;"><?=$acum_ingresos_variacion_f; ?></td>
      </tr>
      <tr>
          <td class="totalx" colspan="2" style="width: 16%; text-align: left;"><b>TOTAL EGRESOS</b></td>
        <td class="totalx"  style="width: 16%; text-align: right; "><?=$acum_egresos_anterior_f; ?></td>
        <td class="totalx"  style="width: 16%; text-align: right;"><?=$acum_egresos_actual_f; ?></td>
        <td class="totalx"  style="width: 16%; text-align: right;"><?=$acum_egresos_variacion_f; ?></td>
      </tr>

      <tr>
        <td class="total" colspan="2" style="width: 16%; text-align: left;"><b>RESULTADO DEL EJERCICIO</b></td>
        <td class="total"  style="width: 16%; text-align: right; "><?=$total_utilidad_anterior_f; ?></td>
        <td class="total"  style="width: 16%; text-align: right;"><?=$total_utilidad_actual_f; ?></td>
        <td class="total"  style="width: 16%; text-align: right;"><?=$total_utilidad_variacion_f; ?></td>
      </tr>
      <tr>
        <td class="total" style="width: 16%; text-align: left;"><b>&nbsp;</b></td>
        <td class="total"  style="width: 36%; text-align: left;">&nbsp;</td>
        <td class="total"  style="width: 16%; text-align: right;">============</td>
        <td class="total"  style="width: 16%; text-align: right;">============</td>
        <td class="total"  style="width: 16%; text-align: right;">============</td>
      </tr>
     
    </tbody>
</table>
<?php
$contenido = ob_get_clean();

//cabecera pagina
ob_start();
$modelEmpresa = Empresa::model()->find();
$ruta_logo = dirname(Yii::app()->getBasePath()).'/images/'.$modelEmpresa->logo;
?>
<div class="cabecera">
    (FORMA "B")<br/>
    <?=Empresa::RazonSocial(); ?>
    <br/>
    <?='RIF: '.Empresa::Rif(); ?>
    <br/>
    <?='SECTOR: '.Empresa::Sector().'&nbsp;&nbsp;&nbsp; NÚMERO DE REGISTRO: '.Empresa::RegistroSUDECA(); ?>
    <br/>
    <?='ESTADO DE RESULTADOS DESDE  '.date('d-m-Y', strtotime($filtro_fecha_desde)).' HASTA '.date('d-m-Y', strtotime($filtro_fecha_hasta)); ?>
    <br/>
    <?='(EXPRESADO EN Bs.)'; ?>
<br/><br/>   
</div>
<?php
$cabecera = ob_get_clean();

$mpdf = new mPDF('win-1252', 'LETTER', '', '', 9, 9, 30, 10, 5, 5);
$arr = [
    'L' => [
        'content' => (empty($modelEmpresa->logo)) ? '<img src='.dirname(Yii::app()->getBasePath())."/images/logo.png alt='Logo' width ='40px' heigth='40px'/>" : "<img src='".$ruta_logo."' alt='Logo' width ='60px' heigth='60px'/>",
    ],

    'C' => [
        'content' => $cabecera,
        'font-style' => 'BI',
        'font-family' => 'serif',
        'color' => '#000000',
    ],

    'line' => 0,
];
$mpdf->setHeader($arr, 'O');
date_default_timezone_set('America/Caracas');
$mpdf->SetFooter('Emitido: '.date('d/m/Y h:i:s a').' - Página {PAGENO} de {nb}');
$mpdf->WriteHTML($contenido);
if (! empty($datos_firma)):
$mpdf->AddPage();
ob_start();

?>
<br/><br/>
    <?php foreach ($datos_firma as $departamento => $funcionario): ?>          
        <table class="firmas">
            <thead>
                <tr>
                    <th colspan="3"><?php echo $departamento; ?></th>
                </tr>
            </thead>
            <tbody>
                <?php 
                    $breakloop = 0;
                    $indice_fe = 0;
                    $fin_ciclo = 0;

                    $breakloop_1 = 0;
                    $indice_fe_1 = 0;

                    if (count($funcionario) > 0):
                ?>
                    <?php do {
                    ?>
                        <tr>
                            <td>
                                <tr>
                                    <?php foreach ($funcionario as $funci => $dat): ?>
                                        <?php if ($funci == $indice_fe_1): ?>                                    
                                                <td class="lineas" width="33%"></td>
                                        <?php 
                                            $breakloop_1++;
                    $indice_fe_1++;

                    if ($breakloop_1 === 3) {
                        break;
                    }

                    endif; ?>
                                    <?php endforeach; ?>
                                </tr>
                                <tr>
                                    <?php foreach ($funcionario as $func => $datos): ?>
                                        <?php if ($func == $indice_fe): ?>
                                                <td class="info_lineas" width="33%"><?php echo $datos['nombre_apellido']; ?><br/><?php echo $datos['cedula']; ?><br/><?php echo $datos['cargo']; ?></td>
                                        <?php 
                                            $breakloop++;
                    $indice_fe++;
                    $fin_ciclo++;

                    if ($breakloop === 3) {
                        break;
                    }

                    endif; ?>
                                    <?php endforeach; ?>
                                </tr>
                            </td>                    
                        </tr>                        
                    <?php
                } while ($fin_ciclo < count($funcionario)); ?>
                <?php endif; ?>
            </tbody>
        </table>
        <br/><br/>
    <?php endforeach; ?>
<br/><br/>

<?php
$firmas = ob_get_clean();
$mpdf->WriteHTML($firmas);
endif;
$mpdf->Output('SAICA_estado_resultado.pdf', 'D');
exit;
?>
