<div id="Exportar_a_Excel">
    <h1 align="center">Informe General de Causación y Recaudo de Ingresos</h1>
    <h2 align="center">Control de Bancos</h2>
    <p ><?php
        $arr = explode(";;", $filtrote);
        foreach ($arr as $a) {
            echo $a . "<br>";
        }
        ?> </p>

    <table border='1' class='reporte'  style='width: 800px;'>
        <thead>
            <tr>
                <td align='center' style="text-align: center;width:  15%;background-color: #AACCEE "><b></b></td>
                <td align='center ' style="text-align: center;width:  20%;background-color: #AACCEE "><b>GRUPO </b></td>
                <td align='center' style="text-align: center;width:  6%;background-color: #AACCEE "><b>BRUTO</b></td>
                <td align='center' style="text-align: center;width:  6%;background-color: #AACCEE "><b>IVA</b></td>
                <td align='center' style="text-align: center;width:  6%;background-color: #AACCEE "><b>CAUSADO</b></td>
                <td align='center' style="text-align: center;width:  6%;background-color: #AACCEE "><b>RECAUDO</b></td>
            </tr>
        </thead>
        <tbody> 
            <?php
            $bar = 0;
            $ban = 0;
            $su = 0;
            $total = 0;
            $tr = 0;
            $su1 = 0;
            $total1 = 0;
            $tr1 = 0;
            $su2 = 0;
            $total2 = 0;
            $tr2 = 0;
            $su3 = 0;
            $total3 = 0;
            $tr3 = 0;

            foreach ($consultas as $con):
                ?>
                <?
                if ($con['ESTADO'] == " " || $con['ESTADO'] == null):
                    if ($ban == 0) {
                        $rub = $con['CLASE'];
                        $val = $con['CODGRU'];
                        $inf = $con['DESGRU'];
                        $ban = 1;
                    }
//Compara rubro
                    ?>

        <? if ($bar == 0) { ?>

                        <tr>
                            <td style="text-align: left;width:15%"  ><b><?php echo "   " . $rub . " " ?></b></td>
                            <td style="text-align: left;width:20%"  ></td>
                            <td style="text-align: right;width:6%"><b><? ?></b></td>
                            <td style="text-align: right;width:6%"><b><? ?></b></td>
                            <td style="text-align: right;width:6%"><b><? ?></b></td>
                            <td style="text-align: right;width:6%"><b><? ?></b></td>

                        </tr>
                        <?
                    }
                    ?>


        <?
//Se compara si el valor que llega en el concepto es diferente para hacer la subtotalizacion
        if ($val != $con['CODGRU']) {
            ?>
                        <tr>   <td style="text-align: left;width:15%"  ></td>
                            <td style="text-align: left;width:20%"  ><?php echo " " . $val . " " . $inf ?></td>
                            <td style="text-align: right;width:6%"><? echo number_format($su, 2, '.', ','); ?></td>
                            <td style="text-align: right;width:6%"><? echo number_format($su1, 2, '.', ','); ?></td>
                            <td style="text-align: right;width:6%"><? echo number_format($su2, 2, '.', ','); ?></td>
                            <td style="text-align: right;width:6%"><? echo number_format($su3, 2, '.', ','); ?></td>

                            <?
                            $su = 0;
                            $su1 = 0;
                            $su2 = 0;
                            $su3 = 0;
                            $val = $con['CODGRU'];
                            $inf = $con['DESGRU'];
                        } else {
                            
                        }
                        if ($rub != $con['CLASE']) {
                            ?>

                        <tr>
                            <td style="text-align: left;width:15%"  ><b><?php echo " TOTAL CLASE " . $rub . " " ?></b></td>
                            <td style="text-align: left;width:20%"  ></td>
                            <td style="text-align: right;width:6%"><b><? echo number_format($tr, 2, '.', ','); ?></b></td>
                            <td style="text-align: right;width:6%"><b><? echo number_format($tr1, 2, '.', ','); ?></b></td>
                            <td style="text-align: right;width:6%"><b><? echo number_format($tr2, 2, '.', ','); ?></b></td>
                            <td style="text-align: right;width:6%"><b><? echo number_format($tr3, 2, '.', ','); ?></b></td>

                        </tr>
                        <?
                        $rub = $con['CLASE'];

                        $tr = 0;
                        $tr1 = 0;
                        $tr2 = 0;
                        $tr3 = 0;

                        $bar = 0;
                    } else {
                        $bar = 1;
                    }
                    ?>
                    <?php
                    $total+= $con['VALOR'];
                    $su +=$con['VALOR'];
                    $tr +=$con['VALOR'];
                    $total1+= $con['IVA'];
                    $su1 +=$con['IVA'];
                    $tr1 +=$con['IVA'];
                    $total2+= $con['CAUSADO'];
                    $su2 +=$con['CAUSADO'];
                    $tr2 +=$con['CAUSADO'];
                    $total3+= $con['RECAUDO'];
                    $su3 +=$con['RECAUDO'];
                    $tr3 +=$con['RECAUDO'];
                    ?>


    <?php endif;
endforeach; ?>

            <tr>   <td style="text-align: left;width:15%"  ></td>
                <td style="text-align: left;width:20%"  ><?php echo "  " . $val . " " . $inf ?></td>
                <td style="text-align: right;width:6%"><? echo number_format($su, 2, '.', ','); ?></td>
                <td style="text-align: right;width:6%"><? echo number_format($su1, 2, '.', ','); ?></td>
                <td style="text-align: right;width:6%"><? echo number_format($su2, 2, '.', ','); ?></td>
                <td style="text-align: right;width:6%"><? echo number_format($su3, 2, '.', ','); ?></td>

            </tr>
            <tr>
                <td style="text-align: left;width:15%"  ><b><?php echo " TOTAL CLASE " . $rub . " " ?></b></td> <td style="text-align: left;width:20%"  ></td>
                <td style="text-align: right;width:6%"><b><? echo number_format($tr, 2, '.', ','); ?></b></td>
                <td style="text-align: right;width:6%"><b><? echo number_format($tr1, 2, '.', ','); ?></b></td>
                <td style="text-align: right;width:6%"><b><? echo number_format($tr2, 2, '.', ','); ?></b></td>
                <td style="text-align: right;width:6%"><b><? echo number_format($tr3, 2, '.', ','); ?></b></td>

            </tr>
            <tr>
                <td style="text-align: left;width:15%"  ></td>
                <td style="text-align: left;width:20%"  ><? echo "TOTAL "; ?></td>
                <td style="text-align: right;width:6%"><? echo number_format($total, 2) ?></td>
                <td style="text-align: right;width:6%"><? echo number_format($total1, 2) ?></td>
                <td style="text-align: right;width:6%"><? echo number_format($total2, 2) ?></td>
                <td style="text-align: right;width:6%"><? echo number_format($total3, 2) ?></td>

            </tr>
        </tbody>
        </tbody>
    </table>
</div>


<table>
    <tr>
        <td>
            <!-- Botón para PDF -->
            <form action="<?php echo url_for('ts_inf_mov/pdf2') ?>" method="post" target="_blank" id="FormularioExportacionPDF">
<? echo image_tag('pdf', 'title="PDF" class="botonPDF"') ?> <!-- La clase botonPDF es la que recibe los datos para enviar-->
                <input type="hidden" id="datos_a_enviar_pdf" name="datos_a_enviar_pdf" class="datosPDF" />
            </form>
        </td>
        <td>
            <!-- Botón para Excel -->
            <form action="<?php echo url_for('ts_inf_pagos_gral/excel?nombre=informe_ing_grup.xls') ?>" method="post" target="_blank" id="FormularioExportacionEXCEL">
<? echo image_tag('icono-excel.gif', 'title="excel" class="botonExcel"') ?> <!-- La clase botonExcel es la que recibe los datos para enviar-->
                <input type="hidden" id="datos_a_enviar" name="datos_a_enviar" class="datosXLS"/>
            </form>
        </td>
    </tr>
</table>
<script language="javascript">
    $(document).ready(function () {
        $(".botonPDF").click(function (event) {
            $(".datosPDF").val($("<div>").append($("#Exportar_a_Excel").eq(0).clone()).html());
            $("#FormularioExportacionPDF").submit();
        });
        $(".botonExcel").click(function (event) {
            $(".datosXLS").val($("<div>").append($("#Exportar_a_Excel").eq(0).clone()).html());
            $("#FormularioExportacionEXCEL").submit();
        });
    });
</script>
<table>
    <tr>
        <td><a href="<?php echo url_for('inf_ingresos/index2') ?>"><?php echo image_tag('back', 'title="Volver"') ?></a></td>
    </tr>
</table>
