  <?php 
    $this->load->view('templates/header');
    $action                     = (isset($_GET['action'])) ? $_GET['action'] : "";
    $search_value_type          = (isset($_GET['search_value_type'])) ? $_GET['search_value_type'] : 0;
    $search_value_clarity       = (isset($_GET['search_value_clarity'])) ? $_GET['search_value_clarity'] : 0;
    $search_value_range_from    = (isset($_GET['search_value_range_from'])) ? $_GET['search_value_range_from'] : '';
    $search_value_range_to      = (isset($_GET['search_value_range_to'])) ? $_GET['search_value_range_to'] : '';
    $search_value_color         = (isset($_GET['search_value_color'])) ? $_GET['search_value_color'] : 0;
    $search_value_result        = (isset($_GET['search_value_result'])) ? $_GET['search_value_result'] : '';

  ?>
    <script>
        var link = "master";
        var sub_link = "rapaport";
    </script>
    
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        RAPAPORT
        <small>MASTER</small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li><a href="#">Rapaport Master</a></li>
        <li class="active">View</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="alert_msg"></div>
            <div class="col-md-12 col-sm-12">
                <div class="box box-primary">
                    <!-- <div class="box-body"> -->
                        <form class="form-horizontal" id="search_form" action="<?php echo base_url('master/masterctrl/rapaport_master/')?>" method="get">
                            <div class="panel panel-body remove-bottom">
                                <div class="form-group floating-form">
                                    
                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <?php echo form_dropdown('', $data['type_drop_down'], $search_value_type,'id="search_value_type" name="search_value_type" class="form-control floating-select flexselect" ');?>
                                        <label>TYPE</label>
                                    </div>                                  
                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <?php echo form_dropdown('', $data['clarity_drop_down'], $search_value_clarity,'id="search_value_clarity" name="search_value_clarity" class="form-control floating-select flexselect" ');?>
                                        <label>CLARITY</label>
                                    </div> 

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <input type='text' class="form-control floating-input" name='search_value_range_from' value='<?php echo $search_value_range_from ?>' />
                                        <label>RANGE FROM</label>
                                    </div> 

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <input type='text' class="form-control floating-input" name='search_value_range_to' value='<?php echo $search_value_range_to ?>' />
                                        <label>RANGE To</label>
                                    </div> 

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <?php echo form_dropdown('', $data['color_drop_down'], $search_value_color,'id="search_value_color" name="search_value_color" class="form-control floating-select flexselect" ');?>
                                        <label>CLARITY</label>
                                    </div>                                 
                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <input type='number' class="form-control floating-input" name='search_value_result' value='<?php echo $search_value_result ?>' />
                                        <label>RESULT</label>
                                    </div>

                                    <div class="col-md-1 col-sm-1 ">
                                        <button type="submit" class="btn btn-primary"><i class="fa fa-search" aria-hidden="true"></i>Search</button>                                   
                                        <input type="hidden" class="form-control" id="action" name="action" value="<?php echo $action ?>" />     
                                    </div>

                                    <div class="col-md-1 col-sm-1">
                                        <a href="<?php echo base_url('master/masterctrl/rapaport_master?action=view'); ?>" class="btn btn-primary"><i class="fa fa-undo" aria-hidden="true"></i>
                                            Reset
                                        </a>
                                    </div>
                                    <div class="col-md-2 col-sm-2 ">
                                        <label for="inputEmail3" class="col-sm-1 control-label control-label_custom" style="width:90%;">
                                            Cnt :
                                            <span id="count_reload">                                                 
                                                <i id="total_rows"><?php echo $total_rows;?></i>
                                            </span>
                                        </label>                                        
                                    </div>   
                                                                       
                                </div>
                                <div class="form-group floating-form">
                                    

                                    <div class="col-md-3">
                                        <div class="upload-btn-wrapper">
                                            <button type="button" class="btn btn-success" onclick="update_rp_rate(1)">
                                                UPDATE ROUND DIAMOND PRICE
                                            </button>
                                        </div>
                                    </div>
                                    <div class="col-md-2">
                                        <button type="button" class="btn btn-success" onclick="update_rp_rate(2)">
                                            UPDATE FANCY DIAMOND PRICE
                                        </button>
                                    </div>
                                                                     
                                </div>
                            </div>
                        </form>
                    <!-- </div> -->
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">     
                <div class="box">
                    <div class="box-body" id="table_reload">
                        <table class="table table-bordered table-striped hoverTable">
                            <thead>
                                <tr>
                                    <th>#</th>
                                    <th>Diamond Type</th>
                                    <th>Clarity</th>
                                    <th>Range From</th>
                                    <th>Range To</th>
                                    <th>Color</th>
                                    <th>Result</th> 
                                </tr>
                            </thead>
                            <tbody>
                        <?php 
                                if(!empty($data['rapaport_data'])):
                                foreach ($data['rapaport_data'] as $key => $value): 
                                    $rp_id      = encrypt_decrypt("encrypt", $value['rp_id'], SECRET_KEY);
                                    $type       = $value['rp_diamond_type'] == 1 ? 'ROUND' : 'PEARS';
                                    $clarity    = strtoupper($value['rp_clarity']);
                                    $range_from = $value['rp_range_from'];
                                    $range_to   = $value['rp_range_to'];
                                    $color      = strtoupper($value['rp_color']);
                                    $result     = $value['rp_result'];
                                    
                                    
                        ?>
                            <tr>
                                <td><?php echo $key+1?></td>                                
                                <td><?php echo $type;?></td>                                
                                <td><?php echo $clarity;?></td>                                
                                <td><?php echo $range_from;?></td>                                
                                <td><?php echo $range_to;?></td>                                
                                <td><?php echo $color;?></td>                                
                                <td><?php echo $result;?></td>                                
                                
                            </tr> 
                        <?php
                            endforeach;
                            else:
                        ?>
                            <tr>
                                <td colspan="10" style="color:red;" align="center">No Record Found!</td>
                            </tr>
                        <?php
                            endif;
                        ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="text-right">
                <?= $this->pagination->create_links(); ?>
            </div>
        </div>
    </section>
    <?php 
    $this->load->view('templates/footer');
   ?>
    <script src="<?php echo assets('js/master.js')?>"></script> 
  