<section class="content-header">
    <h1><i class='fa-fw fa fa-star' style="color: gold"></i><?php if($action =='edit'){ echo $_translator->_getTranslation('Editar Cliente rewards');}else{echo $_translator->_getTranslation('Cliente rewards');} ?></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('Clientes rewards');?></li>
    </ol>
</section>
<section class="content">
<div class="box">
    <div class='flashmessenger'><?php $flashmessenger->showMessage();?></div>
    <div class="box-header with-border">          
        <div class="box-tools"></div><!-- /.box-tools -->
    </div><!-- /.box-header -->
    <div class="box-body">
        <div class="card">
            <ul class="nav nav-tabs" role="tablist">
                <li role="presentation" class="active"><a href="#general" aria-controls="home" role="tab" data-toggle="tab"><?php echo $_translator->_getTranslation('Cliente rewards') ?></a></li>
                <li role="presentation" class="<?php echo $showTabRewardsRecord?>"><a href="#rewards_record" aria-controls="home" role="tab" data-toggle="tab"><?php echo $_translator->_getTranslation('Registro de operacions rewards') ?></a></li>                            
            </ul>
            <!-- Tab panes -->
            <div class="tab-content m-t-3">
                <div role="tabpanel" class="tab-pane active" id="general">
                    <div class="col-lg-12">  
                        <br/>
                        <?php 
                            echo $_formCustomer->openForm();
                            echo $_formCustomer->showActionController();
                            echo $_formCustomer->showId();
                            ?>
                       <div class="col-lg-6">
                            <div><?php echo $_formCustomer->showElement('phone');?></div>
                            <div><?php echo $_formCustomer->showElement('name');?></div>
                            <div><?php echo $_formCustomer->showElement('last_name');?></div>
                            <div><?php echo $_formCustomer->showElement('date_of_birth');?></div>
                            <div><?php echo $_formCustomer->showElement('email');?></div>
                            <div><?php echo $_formCustomer->showElement('contact_type');?></div>
                        </div>
                        <div class="col-lg-6">                                                        
                            <div><?php echo $_formCustomer->showElement('register_store');?></div>            
                            <div><?php echo $_formCustomer->showElement('creado_fecha');?></div>
                            <div><?php echo $_formCustomer->showElement('rewards_total');?></div>
                            <div><?php echo $_formCustomer->showElement('rewards');?></div>
                            <div><?php echo $_formCustomer->showElement('acumulated_amount');?></div>          
                            <div><?php echo $_formCustomer->showElement('status');?></div>
                            <div class="text-right">
                                <?php $element = $_formCustomer->getElement('send'); echo $_formCustomer->createOnlyElement($element);?>
                                <?php $element = $_formCustomer->getElement('cancelar'); echo $_formCustomer->createOnlyElement($element);?>                               
                            </div>
                        </div>        
                        <?php echo $_formCustomer->closeForm();?>
                    </div>
                </div>
                <div role="tabpanel" class="tab-pane" id="rewards_record">
                    <div class="col-lg-12">  
                    <br/>
                    <p><?php echo $_translator->_getTranslation('Lista de movimientos Rewards') ?></p>
                    <div class='table-responsive'>
                        <table id="tblRewardsRecord" class="table table-striped table-hover table-condensed">
                            <thead>                                                       
                            <th class="text-center col-md-2"><?php echo $_translator->_getTranslation('Sucursal');?></th>
                            <th class="text-center"><?php echo $_translator->_getTranslation('Venta');?></th>
                            <th class="text-center"><?php echo $_translator->_getTranslation('Fecha');?></th>
                            <th class="text-center"><?php echo $_translator->_getTranslation('Productos');?></th>
                            <th class="text-center"><?php echo $_translator->_getTranslation('Total venta');?></th>
                            <th class="text-center"><?php echo $_translator->_getTranslation('Operacion');?></th>
                            <th class="text-center"><?php echo $_translator->_getTranslation('Puntos');?></th>
                            <th class="text-center"><?php echo $_translator->_getTranslation('Monto');?></th>
                            <!--<th class="text-center col-md-1">Ticket</th> -->
                            </thead>
                            <tfoot>
                            <th class="filter"><?php echo $_translator->_getTranslation('Sucursal');?></th>
                            <th class="filter"><?php echo $_translator->_getTranslation('Venta');?></th>
                            <th class="filter"><?php echo $_translator->_getTranslation('Fecha');?></th>                     
                            <th class="filter"><?php echo $_translator->_getTranslation('Productos');?></th>
                            <th class="filter"><?php echo $_translator->_getTranslation('Total venta');?></th>
                            <th class="filter"><?php echo $_translator->_getTranslation('Operacion');?></th>
                            <th class="filter"><?php echo $_translator->_getTranslation('Puntos');?></th>
                            <th class="filter"><?php echo $_translator->_getTranslation('Monto');?></th>
                            <!--<th></th>-->
                            </tfoot>
                            <tbody>
                            <?php 
                                if($_rewardRecordList){                                               
                                    foreach($_rewardRecordList as $record){?>
                                        <tr>                                            
                                            <td class="text-center"><?php echo $record['store_name']?></td>
                                            <td class="text-center" style="white-space: nowrap"><?php echo $record['num_venta']?></td>
                                            <td class="text-center"><?php echo $record['fecha']?></td>
                                            <td class="text-center"><?php echo $record['products']?></td>
                                            <td class="text-center">$ <?php echo number_format($record['total_venta'],2)?></td>
                                            <td class="text-center"><?php echo $record['operation']?></td>
                                            <td class="text-center"><?php echo number_format($record['points'],0)?></td>
                                            <td class="text-center">$ <?php echo number_format($record['amount'],2)?></td>                                                        
                                            <!--<td class="text-center" style="white-space: nowrap">                                                            
                                                <span onclick="javascript: void window.open('http://lpcgus/View/Tickets/viewTicketVenta.php?id=<?php echo $record['sales_id']?>','','width=700,height=500,status=1,scrollbars=1,resizable=1')"><i class="fa fa-list btn btn-sm btn-default"></i></span>                                                            
                                            </td>-->
                                        </tr><?php
                                    }                   
                                }?>
                            </tbody>
                        </table>
                    </div>
                    </div>
                </div>
            </div>
        </div>  
        <div class="col-md-12">
        <hr/>
        <p><?php echo $_translator->_getTranslation('Lista de clientes rewards') ?></p>
        <div class="pull-right">                  
            <span class="btn btn-default _advancedSearch"><i class='fa fa-search-plus'></i> <?php echo $_translator->_getTranslation('Busqueda avanzada')?></span>
        </div>               
        <div class="clear" ></div>                              
        <div class='table-responsive'>
        <table id="tblCustomersRewards" class="table table-striped table-hover table-condensed">
            <thead>                                                       
           <th class="text-center col-md-2"><?php echo $_translator->_getTranslation('Sucursal');?></th>
            <th class="text-center col-md-2"><?php echo $_translator->_getTranslation('Nombre');?></th>
            <th class="text-center"><?php echo $_translator->_getTranslation('Telefono');?></th>
            <th class="text-center"><?php echo $_translator->_getTranslation('Fecha nacimiento');?></th>
            <th class="text-center"><?php echo $_translator->_getTranslation('Email');?></th>
            <th class="text-center"><?php echo $_translator->_getTranslation('Fecha registro');?></th>
            <th class="text-center"><?php echo $_translator->_getTranslation('Total puntos');?></th>
            <th class="text-center"><?php echo $_translator->_getTranslation('Puntos disponibles');?></th>
            <th class="text-center"><?php echo $_translator->_getTranslation('Monto disponible');?></th>
            <th class="text-center"><?php echo $_translator->_getTranslation('Status');?></th>
            <th class="text-center col-md-1">Accion</th> 
            </thead>
            <tfoot>
            <th class="filter"><?php echo $_translator->_getTranslation('Sucursal');?></th>
            <th class="filter"><?php echo $_translator->_getTranslation('Nombre');?></th>
            <th class="filter"><?php echo $_translator->_getTranslation('Telefono');?></th>
            <th class="filter"><?php echo $_translator->_getTranslation('Fecha nacimiento');?></th>                     
            <th class="filter"><?php echo $_translator->_getTranslation('Email');?></th>            
            <th class="filter"><?php echo $_translator->_getTranslation('Fecha registro');?></th>
            <th class="filter"><?php echo $_translator->_getTranslation('Total puntos');?></th>
            <th class="filter"><?php echo $_translator->_getTranslation('Puntos disponibles');?></th>
            <th class="filter"><?php echo $_translator->_getTranslation('Monto disponible');?></th>
            <th class="filter"><?php echo $_translator->_getTranslation('Status');?></th>
            <th></th>
            </tfoot>
            <tbody>
            <?php 
                if($_customerList){
                    $contactType = array(''=>'','1'=>'sms','2'=>'email','3'=>'sms / email');                                    
                    foreach($_customerList as $cliente){
                        $medioDeContacto = $contactType[$cliente['contact_type']];?>
                        <tr>                                            
                            <td class="text-center"><?php echo $cliente['register_store_name'];?></td>
                            <td class="text-center"><?php echo $cliente['name'].' '.$cliente['last_name']?></td>
                            <td class="text-center" style="white-space: nowrap"><?php echo $cliente['phone']?></td>
                            <td class="text-center"><?php echo $cliente['formated_date_of_birth']?></td>
                            <td class="text-center"><?php echo $cliente['email']?></td>
                            
                            <td class="text-center"><?php echo $cliente['formated_creado_fecha']?></td>
                            <td class="text-center"><?php echo number_format($cliente['rewards_total'],0)?></td>
                            <td class="text-center"><?php echo number_format($cliente['rewards'],0)?></td>
                            <td class="text-center">$ <?php echo number_format($cliente['acumulated_amount'],2)?></td>
                            <td class="text-center"><?php echo $cliente['status_name']?></td>
                            <td class="text-center" style="white-space: nowrap">
                                <a href="CustomerRewards.php?action=edit&id=<?php echo $cliente['id']?>"><i class="fa fa-pencil btn btn-sm btn-default"></i></a>
                                <span class='btn btn-sm btn-default _emailing' data-operationname="rewards_default" data-operationid='<?php echo $cliente['id']?>' title='Enviar por correo'><i class='fa fa-envelope'></i></span>
                            </td>
                        </tr><?php
                    }                   
                }?>
            </tbody>
        </table>
        </div>
        </div>
  </div><!-- /.box-body -->
</div><!-- /.box -->
</section>
<?php include ROOT."/Rewards/View/Modal/emailing.php"; ?>
<?php  include ROOT."/Rewards/View/Modal/advancedSearch.php"; ?>
<style>
     tfoot {
        display: table-header-group;
    }
</style>
<script type="text/javascript" language="javascript">
        $("#date_of_birth,#creado_fecha").datetimepicker({format: "MM/DD/YYYY"});     
        $("#date_of_birth_start,#date_of_birth_end").datetimepicker({format: "MM/DD"});
        $("#creado_fecha_inicio,#creado_fecha_fin").datetimepicker({format: "MM/DD/YYYY"});
      
        <?php if($login->getRole() == '1'){$Bfrtip = 'Bfrtip';}else{$Bfrtip = '';} ?>
        var table = $('#tblCustomersRewards').DataTable( {
            paginate:false,
            filter:true,
            aaSorting:[],
            dom: '<?php echo $Bfrtip?>',
            buttons: [{ 
                extend: 'excelHtml5', 
                text: 'Descargar en excel',
                exportOptions: {
                    columns: [0,1,2,3,4,5,6,7,8,9]
                }
            }]
        });
        $('#tblCustomersRewards').removeClass( 'display' ).addClass('table table-striped table-bordered');
        $('#tblCustomersRewards tfoot th.filter').each(function() {
            $(this).html('<input type="text" class="text-center" placeholder="<?php echo $_translator->_getTranslation('Buscar') ?>"style="width:100%" />');
        });   
        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();
                }
            });
        });
        $('#tblCustomersRewards_filter').hide();
        
        
        var table = $('#tblRewardsRecord').DataTable( {
            paginate:false,
            filter:true,
            aaSorting:[],
            dom: '<?php echo $Bfrtip?>',
            buttons: [{ 
                    extend: 'excelHtml5', 
                    text: 'Descargar en excel',
                    exportOptions: {
                        columns: [0,1,2,3,4,5,6,7]
                    }
            }]
        });
        $('#tblRewardsRecord').removeClass( 'display' ).addClass('table table-striped table-bordered');
        $('#tblRewardsRecord tfoot th.filter').each(function() {
            $(this).html('<input type="text" class="text-center" placeholder="<?php echo $_translator->_getTranslation('Buscar') ?>"style="width:100%" />');
        });   
        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();
                }
            });
        });
        $('#tblRewardsRecord_filter').hide();
</script>