  <?php
    $this->load->view('templates/header');
    $search_value_stock_id      = (isset($_REQUEST['search_value_stock_id'])) ? $_REQUEST['search_value_stock_id'] : 0;
    $search_value_sh            = (isset($_REQUEST['search_value_sh'])) ? $_REQUEST['search_value_sh'] : 0;
    $search_value_wt            = (isset($_REQUEST['search_value_wt'])) ? $_REQUEST['search_value_wt'] : '';
    $search_value_col           = (isset($_REQUEST['search_value_col'])) ? $_REQUEST['search_value_col'] : 0;
    $search_value_cla           = (isset($_REQUEST['search_value_cla'])) ? $_REQUEST['search_value_cla'] : 0;
    $search_value_cut           = (isset($_REQUEST['search_value_cut'])) ? $_REQUEST['search_value_cut'] : 0;
    $search_value_pol           = (isset($_REQUEST['search_value_pol'])) ? $_REQUEST['search_value_pol'] : 0;
    $search_value_sym           = (isset($_REQUEST['search_value_sym'])) ? $_REQUEST['search_value_sym'] : 0;
    $search_value_fl            = (isset($_REQUEST['search_value_fl'])) ? $_REQUEST['search_value_fl'] : 0;
    $search_value_lab           = (isset($_REQUEST['search_value_lab'])) ? $_REQUEST['search_value_lab'] : 0;
    $search_value_status        = (isset($_REQUEST['search_value_status'])) ? $_REQUEST['search_value_status'] : 0;
    $search_value_start_date    = (isset($_REQUEST['search_value_start_date'])) ? date('d-m-Y', strtotime($_REQUEST['search_value_start_date'])) : date('01-06-2019');
    $search_value_end_date      = (isset($_REQUEST['search_value_end_date'])) ? date('d-m-Y', strtotime($_REQUEST['search_value_end_date'])) : date('d-m-Y');

    $search_value_from_dollar   = (isset($_REQUEST['search_value_from_dollar'])) ? $_REQUEST['search_value_from_dollar'] : '';
    $search_value_to_dollar     = (isset($_REQUEST['search_value_to_dollar'])) ? $_REQUEST['search_value_to_dollar'] : '';

    $search_value_from_ppc   = (isset($_REQUEST['search_value_from_ppc'])) ? $_REQUEST['search_value_from_ppc'] : '';
    $search_value_to_ppc     = (isset($_REQUEST['search_value_to_ppc'])) ? $_REQUEST['search_value_to_ppc'] : '';

    $search_value_key2sym    = (isset($_REQUEST['search_value_key2sym'])) ? $_REQUEST['search_value_key2sym'] : 0;
    $search_value_r2net      = (isset($_REQUEST['search_value_r2net'])) ? $_REQUEST['search_value_r2net'] : 0;
    $search_value_category   = (isset($_REQUEST['search_value_category'])) ? $_REQUEST['search_value_category'] : '';

    $search_value_suspense   = (isset($_REQUEST['search_value_suspense'])) ? $_REQUEST['search_value_suspense'] : 0;

    // echo "<pre>"; print_r($search_value_stock_id); exit();
  ?>
    <script>
        var link = "master";
        var sub_link = "diamond";
    </script>
    <style>
        .switch
        {
          position: relative;
          display: inline-block;
          width: 60px;
          height: 34px;
        }
        .switch input {
          opacity: 0;
          width: 0;
          height: 0;
        }
        .slider {
          position: absolute;
          cursor: pointer;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          background-color: #ccc;
          -webkit-transition: .4s;
          transition: .4s;
        }
        .slider:before {
          position: absolute;
          content: "";
          height: 26px;
          width: 26px;
          left: 4px;
          bottom: 4px;
          background-color: white;
          -webkit-transition: .4s;
          transition: .4s;
        }
        input:checked + .slider {
          background-color: #2196F3;
        }

        input:focus + .slider {
          box-shadow: 0 0 1px #2196F3;
        }

        input:checked + .slider:before {
          -webkit-transform: translateX(26px);
          -ms-transform: translateX(26px);
          transform: translateX(26px);
        }

        /* Rounded sliders */
        .slider.round {
          border-radius: 34px;
        }

        .slider.round:before {
          border-radius: 50%;
        }

        .add-btn {
            padding: 6px 12px;
            border-radius: 8px;
            font-weight: 500;
            background: linear-gradient(135deg, #28a745, #218838);
            border: none;
            color: #fff;
            transition: 0.25s ease-in-out;
            box-shadow: 0 3px 6px rgba(0,0,0,0.2);
        }

        .add-btn:hover {
            background: linear-gradient(135deg, #1f7a33, #19692c);
            transform: translateY(-2px);
        }
    </style>
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        Diamond
        <small>Master</small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li><a href="#">Forms</a></li>
        <li class="active">Diamond Master</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <form class="form-horizontal" id="search_form" action="<?php echo base_url('master/masterctrl/diamond_master/')?>" method="post">
        <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"> -->
                       
                            <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['stock_id_drop_down'], $search_value_stock_id,'id="search_value_stock_id" name="search_value_stock_id[]" class="form-control floating-select" multiple ');?>
                                        <label>STOCK ID</label>
                                    </div>

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <?php echo form_dropdown('', $data['shape_drop_down'],$search_value_sh,'id="search_value_sh" name="search_value_sh[]" class="form-control floating-select" multiple ');?>
                                        <label>SH</label>
                                    </div>

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <?php echo form_dropdown('', $data['weight_drop_down'],$search_value_wt,'id="search_value_wt" name="search_value_wt[]" class="form-control floating-select" multiple ');?>
                                        <label>WT</label>
                                    </div>

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <?php echo form_dropdown('', $data['color_drop_down'],$search_value_col,'id="search_value_col" name="search_value_col[]" class="form-control floating-select" multiple ');?>
                                        <label>COL</label>
                                    </div>

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <?php echo form_dropdown('', $data['clarity_drop_down'], $search_value_cla,'id="search_value_cla" name="search_value_cla[]" class="form-control floating-select" multiple ');?>
                                        <label>CLA</label>
                                    </div>

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <?php echo form_dropdown('', $data['cut_drop_down'], $search_value_cut,'id="search_value_cut" name="search_value_cut[]" class="form-control floating-select" multiple ');?>
                                        <label>CUT</label>
                                    </div>

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <?php echo form_dropdown('', $data['pol_drop_down'], $search_value_pol,'id="search_value_pol" name="search_value_pol[]" class="form-control floating-select" multiple ');?>
                                        <label>POL</label>
                                    </div>

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <?php echo form_dropdown('', $data['sym_drop_down'], $search_value_sym,'id="search_value_sym" name="search_value_sym[]" class="form-control floating-select" multiple ');?>
                                        <label>SYM</label>
                                    </div>

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <?php echo form_dropdown('', $data['fl_drop_down'], $search_value_fl,'id="search_value_fl" name="search_value_fl[]" class="form-control floating-select" multiple ');?>
                                        <label>FL</label>
                                    </div>

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <?php echo form_dropdown('', $data['lab_drop_down'], $search_value_lab,'id="search_value_lab" name="search_value_lab[]" class="form-control floating-select" multiple ');?>
                                        <label>LAB</label>
                                    </div>
                                    <div class="col-md-1 col-sm-1">
                                        <a href="<?php echo uploads('format/diamond_master_new.xlsx'); ?>" data-toggle="tooltip" title="DIAMOND FILE FORMAT" class="fa fa-paperclip" aria-hidden="true" style="cursor: pointer;" download></a>
                                    </div>

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <?php 
                                            echo form_dropdown(
                                                '',
                                                [
                                                    2 => 'ALL',
                                                    0 => 'NON-CERTIFIED',
                                                    1 => 'CERTIFIED'
                                                ],
                                                $search_value_category,
                                                'id="search_value_category" name="search_value_category" class="form-control floating-select"'
                                            );
                                        ?>
                                        <label>CATEGORY</label>
                                    </div>
                                </div>
                                <div class="form-group floating-form">
                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <?php echo form_dropdown('', [0=>'ALL', 1=>'AVAILABLE', 2=>'ISSUE', 3=>'HOLD', 4=>'SOLD'], $search_value_status,'id="search_value_status" name="search_value_status" class="form-control floating-select flexselect" ');?>
                                        <label>STATUS</label>
                                    </div>

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <input type="text" name="search_value_start_date" value="<?php echo $search_value_start_date ?>" id="search_value_start_date" class="form-control floating-input">
                                        <label>START DATE</label>
                                    </div>

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <input type="text" name="search_value_end_date" value="<?php echo $search_value_end_date ?>" id="search_value_end_date" class="form-control floating-input">
                                        <label>END DATE</label>
                                    </div>

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <input type="number" name="search_value_from_dollar" value="<?php echo $search_value_from_dollar ?>" id="search_value_from_dollar" step="0.01" class="form-control floating-input">
                                        <label>FROM DOLLAR</label>
                                    </div>

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <input type="number" name="search_value_to_dollar" value="<?php echo $search_value_to_dollar ?>" id="search_value_to_dollar" step="0.01" class="form-control floating-input">
                                        <label>TO DOLLAR</label>
                                    </div>

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <input type="number" name="search_value_from_ppc" value="<?php echo $search_value_from_ppc ?>" id="search_value_from_ppc" step="0.01" class="form-control floating-input">
                                        <label>FRM PRICE/CERT</label>
                                    </div>

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <input type="number" name="search_value_to_ppc" value="<?php echo $search_value_to_ppc ?>" id="search_value_to_ppc" step="0.01" class="form-control floating-input">
                                        <label>TO PRICE/CERT</label>
                                    </div>

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <?php echo form_dropdown('', $data['key2sym_drop_down'], $search_value_key2sym,'id="search_value_key2sym" name="search_value_key2sym" class="form-control floating-select flexselect" ');?>
                                        <label>KEY2SYMBOL</label>
                                    </div>
                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <?php echo form_dropdown('', [0=>'ALL', 1=>'NO', 2=>'YES'], $search_value_r2net,'id="search_value_r2net" name="search_value_r2net" class="form-control floating-select"');?>
                                        <label>RAPNET</label>
                                    </div>

                                    <div class="col-md-2 col-sm-2 floating-label">
                                        <?php echo form_dropdown('', [0=>'ALL', 1=>'NO', 2=>'YES'], $search_value_suspense,'id="search_value_suspense" name="search_value_suspense" class="form-control floating-select"');?>
                                        <label>SUSPENSE STOCK</label>
                                    </div>

                                </div>
                                <div class="form-group floating-form">
                                    <div class="col-md-2 col-md-offset-5 col-sm-1 col-sm-offset-5 ">
                                        <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 class="col-md-1 col-sm-1 ">
                                        <button type="submit" name="submit" value="search" class="btn btn-primary" id="search_btn"><i class="fa fa-search" aria-hidden="true"></i>Search</button>
                                    </div>

                                    <div class="col-md-1 col-sm-1">
                                        <a href="<?php echo base_url('master/masterctrl/diamond_master'); ?>" class="btn btn-primary"><i class="fa fa-undo" aria-hidden="true"></i>
                                            Reset
                                        </a>
                                    </div>

                                     <div class="col-md-1 col-sm-1">
                                        <a onclick="import_diamond_stock()" class="btn btn-primary">Import</a>
                                    </div>

                                    <div class="col-md-1 col-sm-1">
                                        <!-- <a href="<?php echo base_url('master/masterctrl/r2net_report_excel'); ?>" target="_blank" class="btn btn-primary"><i class="fa fa-file-excel-o" aria-hidden="true"></i>
                                            Export
                                        </a> -->
                                        <button type="submit" name="submit" value="excel" class="btn btn-primary" id="search_btn"><i class="fa fa-file-excel-o" aria-hidden="true"></i>Export</button>
                                    </div>

                                    <div class="col-md-1 col-sm-1">
                                        <button type="button" class="btn btn-sm btn-success add-btn"
                                            onclick="add_update_diamond_popup(0)">
                                            <i class="fa fa-plus"></i> Add
                                        </button>
                                    </div>
                                </div>
                            </div>
                       <!--  </form> -->

                    <!-- </div> -->
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <div class="box">
                    <div class="box-body table-responsive" id="table_reload">
                        <table class="table table-bordered table-striped">
                            <thead>
                                <tr>
                                    <th width="3%"></th>
                                    <th width="3%">#</th>
                                    <th width="3%">DATE</th>
                                    <th width="3%">STOCK ID</th>
                                    <th width="3%">PRICE/CT</th>
                                    <!-- <th width="3%">PC AMT</th> -->
                                    <th width="3%">DOLLAR/CT</th>
                                    <!-- <th width="3%">DOLLAR AMT</th> -->
                                    <th width="3%">SIZE</th>
                                    <!-- <th width="3%">PCS</th>
                                    <th width="3%">CPD</th> -->
                                    <th width="3%">SHAPE</th>
                                    <th width="3%">LAB</th>
                                    <th width="3%">CERT. NO.</th>
                                    <th width="3%">CARAT</th>
                                    <th width="3%">COL</th>
                                    <th width="3%">CLAR.</th>
                                    <th width="3%">CUT</th>
                                    <th width="3%">POL</th>
                                    <th width="3%">SYM</th>
                                    <th width="3%">FLUR.</th>
                                    <!-- <th width="4%">LENGTH</th>
                                    <th width="5%">WIDTH</th> -->
                                    <!--<th width="8%">TOTAL DOLLAR</th>-->
                                    <!-- <th width="4%">HEIGHT</th> -->
                                    <th width="8%">NAT/LAB GROWN</th>
                                    <th width="10%">DISC</th>
                                    <th width="10%">RAP</th>
                                    <th width="10%">DIAMOND IMAGE AND VIDEO</th>
                                    <!-- <th width="4%">STATUS</th> -->
                                    <!-- <th width="7%">UPLOADED DATE</th> -->
                                    <th width="6%">NO OF DAYS</th>
                                    <!-- <th width="6%">Key2Symbol</th> -->
                                    <th width="6%">RAPNET</th>
                                    <th width="6%">Suspense Stock</th>
                                    <th width="6%">Label Print</th>
                                    <th width="5%">Edit</th>
                                    <th>Delete</th>  
                                </tr>
                            </thead>
                            <tbody>
                        <?php
                            $sub_total      = 0;
                            $disc           = 0;
                            $disc_amt       = 0;
                            $total_dollar   = 0;
                            $price_per_crt  = 0;
                            if(!empty($data['diamond_data'])):
                            $sr_no = $count + 1;
                            foreach ($data['diamond_data'] as $key => $value):
                                $status = '';
                                if($value['dm_status'] == 1)
                                {
                                    $status = 'Issue';
                                }
                                else if($value['dm_status'] == 2)
                                {
                                    $status = 'Hold';
                                }
                                else if($value['dm_status'] == 3)
                                {
                                    $status = 'Sold';
                                }
                                else
                                {
                                    $status = 'Available';
                                }

                                // echo "<pre>"; print_r($disc); exit;
                                $uploaded_date  = strtotime($value['dm_date_create']);
                                $current_date   = time();
                                $nod            = $current_date - $uploaded_date;
                                $nod            = round($nod/(60*60*24));
                                if($nod < 60)
                                {
                                   $tr ='<tr style="background-color:lightgreen;">';
                                }
                                elseif($nod > 60 && $nod < 365)
                                {
                                   $tr = '<tr style="background-color:#FFD580;">';
                                }
                                elseif($nod > 365 )
                                {
                                    $tr ='<tr style="background-color:#FF7F7F;">';
                                }
                                else
                                {
                                    $tr = '';
                                }
                                ?>
                                <?php echo $tr;?>
                                <td><input type="checkbox" name="check_flag[]" id="check_flag_<?php echo $value['dm_id'] ?>" onclick="get_checkbox_val(<?php echo $value['dm_id'] ?>)" value="0"></td>
                                <td><?php echo $sr_no?></td>
                                <td>
                                    <?php 
                                        if (!empty($value['dm_date']) && $value['dm_date'] != "0000-00-00") {
                                            $formatted_date = date('d-m-Y', strtotime($value['dm_date']));
                                            echo ($formatted_date != "01-01-1970") ? $formatted_date : '';
                                        } else {
                                            echo '';
                                        }
                                    ?>
                                </td>

                                <td>
                                    <?php if(!empty($value['dm_link'])): ?>
                                    <a href="<?php echo $value['dm_link'] ?>" title="Click here" target="_blank"><?php echo $value['dm_code']?></a>
                                    <?php else: ?>
                                    <?php echo $value['dm_code']?>
                                    <?php endif; ?>
                                </td>
                                <td><?php echo number_format($value['dm_price_ct'],2);?></td>
                                <!-- <td><?php echo !empty($value['dm_pc_amt']) ? $value['dm_pc_amt'] : ''; ?></td> -->
                                <td><?php echo number_format($value['dm_dollar'],2); ?></td>
                                <!-- <td><?php echo !empty($value['dm_dollar_amt']) ? $value['dm_dollar_amt'] : ''; ?></td> -->
                                <td><?php echo !empty($value['dm_size']) ? $value['dm_size'] : ''; ?></td>
                                <!-- <td><?php echo !empty($value['dm_pcs']) ? $value['dm_pcs'] : ''; ?></td> -->
                                <!-- <td><?php echo !empty($value['dm_cpd']) ? $value['dm_cpd'] : ''; ?></td> -->
                                <td><?php echo $value['dm_sh']?></td>
                                <td><?php echo $value['dm_lab']?></td>
                                <td><?php echo !empty($value['dm_cert_no']) ? $value['dm_cert_no'] : ''; ?></td>
                                <td><?php echo !empty($value['dm_carat']) ? $value['dm_carat'] : ''; ?></td>
                                <td><?php echo $value['dm_col']?></td>
                                <td><?php echo $value['dm_cla']?></td>
                                <td><?php echo $value['dm_cut']?></td>
                                <td><?php echo $value['dm_pol']?></td>
                                <td><?php echo $value['dm_sym']?></td>
                                <td><?php echo $value['dm_fl']?></td>
                                <!-- <td><?php echo $value['dm_len']?></td> -->
                                <!-- <td><?php echo $value['dm_wid']?></td> -->
                                <!-- <td><?php echo $value['dm_hei']?></td> -->
                                <td><?php echo !empty($value['dm_nat_lab_grown']) ? $value['dm_nat_lab_grown'] : ''; ?></td>
                                <td><?php echo $value['dm_disc']?></td>
                                <td><?php echo number_format($value['dm_rap'], 2) ?></td>

                                 <?php
                                    // $per = $value['dm_rap'] * ($value['dm_disc']/100);
                                    // $ppc = $value['dm_rap'] + $per;  
                                    ?>
                                <!-- <td><?php //echo number_format($ppc,2); ?></td>
                                <td><?php //$dollar = $ppc * $value['dm_wt']; echo number_format($dollar,2); ?></td> -->
                                 
                                <td><a href="<?php echo $value['dm_video_link']?>" style="cursor: pointer;" title="Click here" target="_blank"><?php echo $value['dm_video_link']?></a></td>
                                <!-- <td>
                                    <?php if($value['dm_status'] == 1): ?>
                                        <a onclick="get_challan_data(<?php echo $value['dm_id']; ?>, <?php echo $value['dm_ct_id']; ?>)" style="cursor: pointer;"><?php echo $status; ?></a>
                                    <?php elseif($value['dm_status'] == 2 || $value['dm_status'] == 3): ?>
                                        <a onclick="get_challan_return_data(<?php echo $value['dm_id']; ?>, <?php echo $value['dm_crt_id']; ?>)" style="cursor: pointer;"><?php echo $status; ?></a>
                                    <?php else: ?>
                                        <?php echo $status; ?>
                                    <?php endif; ?>
                                </td> -->
                                <!-- <td><?php echo date('d-m-Y', strtotime($value['dm_date_create'])); ?></td> -->
                                <td><?php echo $nod; ?></td>
                                <!-- <td>
                                    <?php //echo strtoupper($value['dm_key2sym']); ?>
                                </td> -->
                                <td>
                                    <label class="switch">
                                      <input type="checkbox" <?php echo $value['dm_r2net'] == 0 ? '' : 'checked'; ?> onchange="set_r2net(<?php echo $value['dm_id'] ?>, <?php echo $value['dm_r2net']; ?>)">
                                        <?php if($value['dm_r2net'] == 0): ?>
                                            <span class="slider round" data-toggle="tooltip" title="UNHIDE"></span>
                                        <?php else: ?>
                                            <span class="slider round" data-toggle="tooltip" title="HIDE"></span>
                                        <?php endif; ?>
                                    </label>
                                </td>
                                <td>
                                    <label class="switch">
                                      <input type="checkbox" <?php echo $value['dm_suspense'] == 0 ? '' : 'checked'; ?> onchange="set_suspense(<?php echo $value['dm_id'] ?>, <?php echo $value['dm_suspense'] ?>)">
                                      <?php if($value['dm_suspense'] == 0): ?>
                                            <span class="slider round" data-toggle="tooltip" title="UNHIDE"></span>
                                        <?php else: ?>
                                            <span class="slider round" data-toggle="tooltip" title="HIDE"></span>
                                        <?php endif; ?>
                                    </label>
                                </td>
                                <td>
                                    <a href="<?php echo base_url()."master/masterctrl/label_print/".$value['dm_id'] ?>" target="_blank"><i class="fa fa-print"></i></a>
                                </td>
                                <?php if($value['is_exists'] > 0){ ?>
                                    <td><i class="fa fa-ban"></i></td>
                                    <td><i class="fa fa-ban"></i></td>
                                <?php }else{ ?>
                                    <td>
                                        <span class="glyphicon glyphicon-pencil" style="cursor:pointer;" onClick="add_update_diamond_popup(<?php echo $value['dm_id']?>)"></span>
                                    </td>

                                    <td>
                                        <button type="button" onclick="delete_diamond(<?php echo $value['dm_id'] ?>)"  style="color: red;"><i class="fa fa-trash"></i></button>
                                    </td>
                                <?php } ?>
                                
                               </tr>
                          <?php
                            $sr_no++;
                            endforeach;
                            else:
                          ?>
                            <tr>
                                <td colspan="35" align="center" style="color: red;">No Record Found!</td>
                            </tr>
                        <?php
                            endif;
                        ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
         </form>
        <div class="row">
            <div class="text-right">
                <?= $this->pagination->create_links(); ?>
            </div>
        </div>
    </section>

  <?php
    $this->load->view('templates/footer');
   ?>
   <script type="text/javascript" src="<?php echo assets('js/master.js')?>"></script>