<section class="content-header">
    <h1><i class='fa-fw fa fa-bookmark'></i> <?php echo $_translator->_getTranslation('Lista de pedidos de sucursal');?></small></h1>
    <ol class="breadcrumb">
        <li><a href="<?php echo ROOT_HOST?>/Controller/Home.php"><i class="fa fa-dashboard"></i><?php echo $_translator->_getTranslation('Inicio')?></a></li>
        <li class="active"><?php echo $_translator->_getTranslation('Lista de ordenes especiales');?></li>
    </ol>
</section>
<section class="content">
<form><?php /* Lo puse para que no se autollenen campos con usuario*/?>
<div class="box">
  <div class="box-header with-border">
    <h3 class="box-title"></h3>
    <div class="box-tools pull-right">   
        <a href="StoreRequest.php" class="btn btn-default"><i class='fa fa-plus'></i> <?php echo $_translator->_getTranslation('Agregar pedido de sucursal')?></a> 
        <span class="btn btn-default _advancedSearch"><i class="fa fa-search-plus"></i> <?php echo $_translator->_getTranslation('Busqueda avanzada')?></span> 
    </div><!-- /.box-tools -->
  </div><!-- /.box-header -->
  <div class="box-body">
    <div class='flashmessenger'><?php $flashmessenger->showMessage();?></div>
    <span class="btn btn-github btn_filter_status" data-value=""><?php echo $_translator->_getTranslation('Todo');?></span>    
    <span class="btn bg-primary btn_filter_status" data-value="1"><?php echo $_translator->_getTranslation('Activo');?></span>
    <span class="btn bg-warning btn_filter_status" data-value="3"><?php echo $_translator->_getTranslation('Revisado');?></span>
    <span class="btn bg-success btn_filter_status" data-value="4"><?php echo $_translator->_getTranslation('Enviado');?></span>
    <span class="btn bg-danger btn_filter_status" data-value="2"><?php echo $_translator->_getTranslation('Cancelado');?></span>
    <div class="clear"></div>
    <div class='table-responsive'>
        <table id="tblStoreRequest" class="table table-bordered table-striped table-hover table-condensed datatable_whit_filter_column">
            <thead>
            <th class="col-lg-1 text-center"><?php echo $_translator->_getTranslation('No.');?></th>
            <th class="col-lg-1 text-center"><?php echo $_translator->_getTranslation('Fecha de pedido');?></th>                     
            <th class="col-lg-1 text-center"><?php echo $_translator->_getTranslation('Fecha de entrega');?></th>                     
            <th class="col-lg-1 text-center"><?php echo $_translator->_getTranslation('Sucursal');?></th>
            <th class="col-lg-1 text-center"><?php echo $_translator->_getTranslation('Area');?></th>            
            <th class="col-lg-2 text-center"><?php echo $_translator->_getTranslation('Usuario');?></th>
            <th class="col-lg-1 text-center"><?php echo $_translator->_getTranslation('Status');?></th>
            <th class="col-lg-1 text-center"><?php echo $_translator->_getTranslation('Accion');?></th>
            </thead>
            <tfoot>
            <th class="filter"><?php echo $_translator->_getTranslation('No.');?></th>
            <th class="filter"><?php echo $_translator->_getTranslation('Fecha de pedido');?></th>                     
            <th class="filter"><?php echo $_translator->_getTranslation('Fecha de entrega');?></th>                     
            <th class="filter"><?php echo $_translator->_getTranslation('Sucursal');?></th>
            <th class="filter"><?php echo $_translator->_getTranslation('Area');?></th>            
            <th class="filter"><?php echo $_translator->_getTranslation('Usuario');?></th>
            <th class="filter"><?php echo $_translator->_getTranslation('Status');?></th>
            <th></th>
            </tfoot>
            <tbody>
            <?php 
            if($_listStoreRequests){
                $statusClass = array('1'=>'primary','2'=>'danger','3'=>'warning','4'=>'success');
                
                foreach($_listStoreRequests as $requisicion){?>
                    <tr>
                        <td class="text-center"><?php echo $requisicion['id']?></td> 
                        <td class="text-center"><?php echo $requisicion['formatedDate']?></td>  
                        <td class="text-center"><?php echo $requisicion['formatedDeliveryDate']?></td>  
                        <td class="text-center"><?php echo $requisicion['storeName']?></td>
                        <td class="text-center"><?php echo $requisicion['areaName']?></td>
                        <td class="text-center"><?php echo $requisicion['created_by']?></td>
                        <td class="text-center status_<?php echo $requisicion['id'] ?>" data-filter="<?php echo $requisicion['status'] ?>">                            
                            <span style='padding: 7px; display: inline-block' class="bg-<?php echo $statusClass[$requisicion['status']] ?>"> <?php echo $requisicion['statusName']?> </span>                            
                        </td>                        
                        <td class="text-center" style="white-space: nowrap">
                            <a href="StoreRequest.php?action=edit&id=<?php echo $requisicion['id']?>" class="btn btn-sm btn-default"><i class="fa fa-pencil fa-"></i></a>
                            <span class="btn btn-sm btn-default _print" data-id="<?php echo $requisicion['id'] ?>" onclick="javascript: void window.open('StoreRequest.php?action=export&format=pdf&flag=store_request&id=<?php echo $requisicion['id']?>','','width=700,height=500,status=1,scrollbars=1,resizable=1')"><i class="fa fa-file-pdf-o fa-"></i></span>                                                                              
                            <?php 
                            if($requisicion['status'] == '1' || $requisicion['status'] == '3'){?>
                            <span href="#" class="btn btn-sm btn-default" data-id="<?php echo $requisicion['id'] ?>" onclick="generateShipment(this)"><i class="fa fa-truck"></i> </span>
                    <?php   }else{?>
                                <a href="#" class="btn btn-sm btn-default disabled"><i class="fa fa-truck"></i> </a>
                    <?php   } ?>  
                                
                            <a class="btn btn-sm btn-default _tooltip_created" data-html="true" title="<?php echo "Creado por: ".$requisicion['created_by']."<br/>Creado fecha: ".$requisicion['created_date']; if($requisicion['last_modification_by'] != ''){echo "<br/>Ultima mod por: ".$requisicion['last_modification_by']."<br/>Ultima mod fecha: ".$requisicion['last_modification_date']; } ?>" ><i class="fa fa-commenting-o"></i></a>
                            <a class="btn btn-sm btn-danger" onclick="return confirmDelete('<?php echo $_translator->_getTranslation('Esta seguro de cancelar este registro ?')?>',this)" href="StoreRequest.php?action=delete&id=<?php echo $requisicion['id']?>"><i class="fa fa-trash"></i></a>
                        </td>                        
                    </tr><?php
                }                   
            }?>
            </tbody>
        </table>
    </div>
  </div><!-- /.box-body -->
</div><!-- /.box -->
</form>
</section>
<?php  include ROOT."/View/Modal/advancedSearch.php"; ?>
<script type="text/javascript" language="javascript">
    $('._searchSpecialRequest').on('click',function(){$('#modalBusquedaAvanzadaSR').modal('show');});    
    $('#tblStoreRequest').DataTable({paginate:false,filter:true,aaSorting:[]});
    
    $('.btn_filter_status').on( 'click', function () { 
        var table = $('#tblStoreRequest').DataTable();      
        table.search('');
        table.columns().search('').draw();
        table.columns(5).search($(this).data('value')).draw();
    });
    
    $('._print').on('click',function(){
        var elem = this;
        $.post('/Controller/StoreRequest.php', {
            action: 'ajax',
            request: 'markAsReviewed',
            id: $(this).data('id')
        }, function(data) {
            if (data.response){                                 
               $('.status_'+$(elem).data('id')).html('<span style="padding: 7px; display: inline-block" class="bg-warning">Revisado</span>');
            }                         
        }, 'json');
    });
    
    $('._tooltip').tooltip();
    $('._tooltip_created').tooltip({template: '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner _tootip_type"></div></div>'});
    
</script>