<div class="box-header"> 
    <h3><i class='fa-fw fa fa-shopping-basket'></i><?php echo $_translator->_getTranslation(ucfirst($_reporte->getTituloReporte()));?></h3>
    <div class='box-icon dropdown'>
        <i class='icon fa fa-tasks' id="moreOptions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"></i>
        <ul class="dropdown-menu dropdown-menu-right" aria-labelledby="moreOptions">
            <li><a href="<?php echo $_reporte->getStringToSendGET().'&action=create&output=excel' ?>"><i class="fa fa-file-excel-o"></i><?php echo $_translator->_getTranslation('Exportar a excel')?></a></li>
            <li><a href="<?php echo $_reporte->getStringToSendGET().'&enviarPorMail' ?>" class="linkSendMail" data-toggle='modal' data-target='#modalSendReportToMail'>
                    <i class="fa fa-envelope"></i><?php echo $_translator->_getTranslation('Enviar por correo')?>
                </a>
            </li>
        </ul>
    </div>
</div>
<div class='box-content'>
    <div class='row'>
        <div class="col-lg-12">
            <?php
            $data = $_reporte->getReporte();
            if($data == null){
                echo "There is no information";
                exit;
            }
            $sucursales = $data['sucursales'];
            $data = $data['data'];
            ?>
            <div class="table-responsive">
            <table id="tblReport" class="table table-striped table-bordered table-condensed table-hover">
            <thead class="table-header">
            <tr>
                <td class="text-center"><?php echo $_translator->_getTranslation('Codigo');?></td>
                <td class="text-center"><?php echo $_translator->_getTranslation('Descripcion');?></td>
                <td class="text-center"><?php echo $_translator->_getTranslation('Categoria');?></td>
                <?php foreach($sucursales as $key => $sucursal){?>                       
                    <td class="text-right"><?php echo $sucursal;?></td>
                <?php }?>                
            </tr>
            </thead>
            <tfoot>                        
                <th class="filter text-center"><?php echo $_translator->_getTranslation('Codigo');?></th>
                <th class="filter text-center"><?php echo $_translator->_getTranslation('Descripcion');?></th>
                <th class="filter text-center"><?php echo $_translator->_getTranslation('Categoria');?></th>
                 <?php foreach($sucursales as $key => $sucursal){?>                       
                    <th class="filter text-center"><?php echo $sucursal;?></th>
                <?php }?> 
            </tfoot>
            <tbody>
            <?php 
            $login = new Login();
            $currentSucursal = $login->getSucursal();
            foreach($data as $row){?>
                <tr >
                <td class="text-center"><?php echo $row['codigo'];?></td>
                <td class="text-center"><?php echo $row['descripcion'];?></td>
                <td class="text-center"><?php echo $row['categoria'];?></td>      
                <?php
                foreach($sucursales as $idSucursal => $sucursal){
                    $class = '';
                    if($currentSucursal == $idSucursal || $login->getRole() == '1'){$class = 'editInventory';}?>                       
                    <td id="<?php echo $row['id_product'].'_'.$idSucursal?>" 
                        class="<?php echo $class; ?>  text-right" 
                        data-idproduct="<?php echo $row['id_product'] ?>" 
                        data-productname="<?php echo $row['descripcion'] ?>" 
                        data-notes="<?php echo $row["notes_$idSucursal"] ?>" 
                        data-idstore="<?php echo $idSucursal;?>"
                        data-storename="<?php echo $sucursal;?>"
                        data-stock="<?php echo $row["$idSucursal"];?>"><?php echo number_format($row["$idSucursal"],2);?></td><?php                   
                }?>   
                </tr><?php  
            }?>                    
            </tbody>
            </table>
            </div>
        </div>
    </div>
</div>
<?php include ROOT."/View/Modal/editInventory.php";?>
<style>
    tfoot {
    display: table-header-group;
}
</style>
<script type="text/javascript" language="javascript">
    $('.editInventory').click(function(){
        $('#idProduct').val($(this).data('idproduct'));
        $('#idStore').val($(this).data('idstore'));
        $('#stock').val($(this).data('stock'));
        $('#notes').val($(this).data('notes'));
        $('#productName').html($(this).data('productname'));
        $('#storeName').html($(this).data('storename'));

        $('#modalEditInventory').modal('show');
    });    
    
    $('#tblReport').DataTable( {paginate:false,filter:true,aaSorting:[],iDisplayLength :50});
    $('#tblReport')
        .removeClass( 'display' )
        .addClass('table table-striped table-bordered');

    $('#tblReport tfoot th.filter').each( function () {
           $(this).html( '<input type="text" placeholder="Search" style="width:100%" />' );
       } );  

       var table = $('#tblReport').DataTable();
       // Apply the search
       table.columns().every( function () {
           var that = this; 
           $( 'input', this.footer() ).on( 'keyup change', function () {
               if ( that.search() !== this.value ) {
                   that
                       .search (this.value.replace("/;/g", "|"), true, false)
                       .draw();
               }
           } );
       } );
</script>