<section class="content-header">
    <h1><i class='fa-fw fa fa-star' style="color: gold"></i><?php echo $_translator->_getTranslation('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('Rewards');?></li>
    </ol>
</section>
<section class="content">
<div class="box">
    <div class='flashmessenger'><?php $flashmessenger->showMessage();?></div>
    <div class="box-header with-border">  
        <input type="hidden" id="_tabActive" name="_tabActive" value="<?php echo $_tabActive ?>" />
        <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="#settings" aria-controls="home" role="tab" data-toggle="tab"><?php echo $_translator->_getTranslation('Opciones de puntos') ?></a></li>
                <li role="presentation"><a href="#rules" aria-controls="home" role="tab" data-toggle="tab"><?php echo $_translator->_getTranslation('Regla de puntos') ?></a></li>
                <li role="presentation"><a href="#reedem" aria-controls="home" role="tab" data-toggle="tab"><?php echo $_translator->_getTranslation('Canje de puntos') ?></a></li>                            
            </ul>
            <!-- Tab panes -->
            <div class="tab-content m-t-3">
                <div role="tabpanel" class="tab-pane active" id="settings">
                    <div class="col-md-8">
                        <br/>
                        <?php 
                        echo $_formRewards->openForm();
                        echo $_formRewards->showActionController();
                        echo $_formRewards->showId();
                        echo $_formRewards->showElement('min_amount_to_assign_points');  
                        echo $_formRewards->showElement('points_assigned_for_min_amount');
                        echo $_formRewards->showElement('value_for_each_point');  
                        echo $_formRewards->showElement('calculate_points_with_price_without_taxes');         
                        echo $_formRewards->showElement('min_point_to_reedem');                                     
                        echo $_formRewards->showElement('max_life_days_of_points');               
                        echo $_formRewards->showElement('status');
                        ?>
                        <div class="col-md-12  text-right">
                            <?php $element = $_formRewards->getElement('send'); echo $_formRewards->createOnlyElement($element);?>
                            <?php $element = $_formRewards->getElement('cancelar'); echo $_formRewards->createOnlyElement($element);?>                               
                        </div>
                        <?php echo $_formRewards->closeForm();?>
                    </div>
                </div>
                <div role="tabpanel" class="tab-pane" id="rules">                                
                    <div class="col-md-8">   
                        <br/>
                        <?php 
                        echo $_formRules->openForm();
                        echo $_formRules->showActionController();
                        echo $_formRules->showId();
                        echo $_formRules->showElement('name');  
                        echo $_formRules->showElement('type_of_points');
                        echo $_formRules->showElement('product_id');         
                        echo $_formRules->showElement('start_date');  
                        echo $_formRules->showElement('end_date');                                       
                        echo $_formRules->showElement('status');
                        ?>                                       
                        <div class="col-md-12  text-right">
                            <?php $element = $_formRules->getElement('send'); echo $_formRules->createOnlyElement($element);?>
                            <?php $element = $_formRules->getElement('cancelar'); echo $_formRules->createOnlyElement($element);?>                               
                        </div>

                        <?php echo $_formRules->closeForm();?>
                    </div>
                    <div class="col-md-12">                                     
                        <h3><?php echo $_translator->_getTranslation('Lista de reglas')?></h3>
                        <hr/>
                        <div class='table-responsive'>
                        <table id="tblRules" class="table table-striped table-hover table-condensed">
                            <thead>
                            <th class="text-center"><?php echo $_translator->_getTranslation('Nombre');?></th>
                            <th class="text-center"><?php echo $_translator->_getTranslation('Producto');?></th>
                            <th class="text-center"><?php echo $_translator->_getTranslation('Tipo de puntos');?></th>                                        
                            <th class="text-center"><?php echo $_translator->_getTranslation('Inicio');?></th>
                            <th class="text-center"><?php echo $_translator->_getTranslation('Termino');?></th>
                            <th class="text-center"><?php echo $_translator->_getTranslation('Status');?></th>
                            <th class="text-center col-md-1"><?php echo $_translator->_getTranslation('Accion');?></th>
                            </thead>
                            <tbody>
                            <?php 
                                if($_rulesList){
                                    foreach($_rulesList as $rule){?>
                                        <tr>
                                            <td class="text-center"><?php echo $rule['name']?></td>
                                            <td class="text-center"><?php echo $rule['product_name']?></td>
                                            <td class="text-center"><?php echo $rule['type_of_points']?></td>
                                            <td class="text-center"><?php echo $rule['formated_start_date']?></td>
                                            <td class="text-center"><?php echo $rule['formated_end_date']?></td>
                                            <td class="text-center"><?php echo $rule['status_name']?></td>
                                            <td class="text-center">
                                                <a href="Rewards.php?action=rules-edit&id=<?php echo $rule['id']?>&rules"><i class="fa fa-pencil btn btn-sm btn-default"></i></a>
                                                <a onclick="return deleteRegistry('Rewards.php?action=rules-delete&id=<?php echo $rule['id']?>')"  href="#"><i class="fa fa-trash btn btn-sm btn-danger"></i></a>
                                            </td>
                                        </tr><?php
                                    }                   
                                }?>
                            </tbody>
                        </table>
                        </div>
                    </div>
                </div>
                <div role="tabpanel" class="tab-pane" id="reedem">
                    <div class="col-md-8"> 
                        <br/>
                        <?php
                        echo $_formReedem->openForm();
                        echo $_formReedem->showActionController();
                        echo $_formReedem->showId();
                        echo $_formReedem->showElement('id_product');  
                        echo $_formReedem->showElement('rewards_reedem');     
                        echo $_formReedem->showElement('start_date');  
                        echo $_formReedem->showElement('end_date');                                       
                        echo $_formReedem->showElement('status');
                        ?>                                       
                        <div class="col-md-12  text-right">
                            <?php $element = $_formReedem->getElement('send'); echo $_formReedem->createOnlyElement($element);?>
                            <?php $element = $_formReedem->getElement('cancelar'); echo $_formReedem->createOnlyElement($element);?>                               
                        </div>

                        <?php echo $_formReedem->closeForm();?>
                    </div>
                    <div class="col-md-12">
                        <h3><?php echo $_translator->_getTranslation('Lista de canjes')?></h3>
                        <hr/>
                        <div class='table-responsive'>
                        <table id="tblReedems" class="table table-striped table-hover table-condensed">
                            <thead>
                            <th class="text-center"><?php echo $_translator->_getTranslation('Producto');?></th>
                            <th class="text-center"><?php echo $_translator->_getTranslation('Puntos para canje');?></th>                                        
                            <th class="text-center"><?php echo $_translator->_getTranslation('Inicia');?></th>
                            <th class="text-center"><?php echo $_translator->_getTranslation('Termina');?></th>
                            <th class="text-center"><?php echo $_translator->_getTranslation('Status');?></th>
                            <th class="text-center col-md-1"><?php echo $_translator->_getTranslation('Accion');?></th>
                            </thead>
                            <tbody>
                            <?php 
                                if($_reedemList){
                                    foreach($_reedemList as $reedem){?>
                                        <tr>
                                            <td class="text-center"><?php echo $reedem['product_name']?></td>
                                            <td class="text-center"><?php echo $reedem['rewards_reedem']?></td>
                                            <td class="text-center"><?php echo $reedem['formated_start_date']?></td>
                                            <td class="text-center"><?php echo $reedem['formated_end_date']?></td>
                                            <td class="text-center"><?php echo $reedem['status_name']?></td>
                                            <td class="text-center">
                                                <a href="Rewards.php?action=reedem-edit&id=<?php echo $rule['id']?>&reedem"><i class="fa fa-pencil btn btn-sm btn-default"></i></a>
                                                <a onclick="return deleteRegistry('Rewards.php?action=reedem-delete&id=<?php echo $rule['id']?>')"  href="#"><i class="fa fa-trash btn btn-sm btn-danger"></i></a>
                                            </td>
                                        </tr><?php
                                    }                   
                                }?>
                            </tbody>
                        </table>
                        </div>
                    </div>
                </div>
            </div>
         </div>              
  </div><!-- /.box-body -->
</div><!-- /.box -->
</section>
<script type="text/javascript">        
     $('form[name=rewards] #calculate_points_with_price_without_taxes,form[name=rewards] #status').select2();   
     
    /*RULES*/
    $('form[name=formrules] #type_of_points,form[name=formrules] #product_id').select2();
    $('#tblRules').DataTable({
        paginate:true,
        filter:true,
        pageLength: 100,
        aaSorting:[]
        });

    $('#tblRules').removeClass( 'display' ).addClass('table table-striped table-bordered');  
    
    /*REEDEMS*/
    $("#start_date,#end_date").datetimepicker({format: "MM/DD/YYYY hh:mm A "});
    $('form[name=formreedem] #id_product').select2();
    $('#tblReedems').DataTable({
        paginate:true,
        filter:true,
        pageLength: 100,
        aaSorting:[]
        });

    $('#tblReedems').removeClass( 'display' ).addClass('table table-striped table-bordered');  
   
   
    $('a[href="#'+$('#_tabActive').val()+'"]').click();
   
</script>
