  <?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'] : 0;
    $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-Y');    
    $search_value_end_date      = (isset($_REQUEST['search_value_end_date'])) ? date('d-m-Y', strtotime($_REQUEST['search_value_end_date'])) : date('d-m-Y');    
  ?>
    <script>
        var link = "report";
        var sub_link = "diamond_summery";
    </script>
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        Diamond
        <small>Summery</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 Summery</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <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('report/reportctrl/diamond_summery/')?>" method="post">
                            <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>
                                <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 ">
                                        <button type="submit" class="btn btn-primary"><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('report/reportctrl/diamond_summery'); ?>" 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 href="<?php echo base_url('report/reportctrl/diamond_summery?action=add'); ?>" class="btn btn-primary">Add New</a>
                                    </div> -->
                                    <div class="col-md-1 col-sm-1 ">
                                        <label for="inputEmail3" class="col-sm-1 control-label control-label_custom" style="width:100%;">
                                            <i >Available:<?php echo $data['available_data'];?></i>
                                        </label>                                        
                                    </div> 
                                    <div class="col-md-1 col-sm-1 ">
                                        <label for="inputEmail3" class="col-sm-1 control-label control-label_custom" style="width:100%;">
                                            <i >Sold:<?php echo $data['sold_data'];?></i>
                                        </label>                                        
                                    </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">
                            <thead>
                                <tr>
                                    <th width="3%">#</th>
                                    <th width="6%">STOCK ID</th>
                                    <th width="3%">SH</th>    
                                    <th width="3%">WT</th>    
                                    <th width="3%">COL</th>    
                                    <th width="3%">CLA</th>    
                                    <th width="3%">CUT</th>    
                                    <th width="3%">POL</th>    
                                    <th width="3%">SYM</th>    
                                    <th width="3%">FL</th>    
                                    <th width="3%">LAB</th>    
                                    <th width="4%">DISC</th>    
                                    <th width="5%">RAP</th>    
                                    <th width="8%">TOTAL DOLLAR</th>    
                                    <th width="4%">PRICE/CRT</th>    
                                    <th>DIAMOND IMAGE & VIDEO</th>    
                                    <th width="4%">STATUS</th>    
                                    <th width="7%">UPLOADED DATE</th>    
                                    <th width="6%">NO OF DAYS</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'])):
                            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';
                                }

                                if(strtoupper($value['dm_lab']) == 'GIA')
                                {
                                    $sub_total = $value['dm_wt'] * $value['dm_rap'];
                                    
                                    $disc = explode('-', $value['dm_disc']);
                                    if(empty($disc[0]))
                                    {
                                        $disc = $disc[1];
                                    }
                                    else
                                    {
                                        $disc = $disc[0];
                                    }

                                    $disc_amt = ($sub_total * $disc)/100;
                                    $total_dollar = $sub_total - $disc_amt;
                                    $price_per_crt = $total_dollar / $value['dm_wt'];


                                }
                                elseif(strtoupper($value['dm_lab']) == 'IGI' || strtoupper($value['dm_lab']) == 'HRD')
                                {
                                    $sub_total = $value['dm_wt'] * $value['dm_rap'];
                                    
                                    $disc = explode('-', $value['dm_disc']);
                                    if(empty($disc[0]))
                                    {
                                        $disc = $disc[1];
                                    }
                                    else
                                    {
                                        $disc = $disc[0];
                                    }

                                    $disc_amt = ($sub_total * $disc)/100;
                                    $total_dollar = $sub_total - $disc_amt;

                                    $disc_amt = ($total_dollar * 2) / 100;
                                    $total_dollar = $total_dollar - $disc_amt;
                                    $price_per_crt = $total_dollar / $value['dm_wt'];
                                }
                                else
                                {
                                    $total_dollar = 0;
                                    $price_per_crt = 0;
                                }
                                // 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));
                        ?>
                            <tr>
                                <td><?php echo $key+1?></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 $value['dm_sh']?></td>
                                <td><?php echo $value['dm_wt']?></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_lab']?></td>
                                <td><?php echo $value['dm_disc']?></td>
                                <td><?php echo number_format($value['dm_rap'], 2) ?></td>
                                <td><?php echo number_format($total_dollar,2); ?></td>
                                <td><?php echo number_format($price_per_crt,2);?></td>
                                <td><a href="<?php echo $value['dm_link']?>" style="cursor: pointer;" title="Click here" target="_blank"><?php echo $value['dm_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><span class="glyphicon glyphicon-trash" onClick="delete_report_item(<?php echo $value['dm_id']?>,'diamond_delete');"></span></td> -->
                            </tr> 
                        <?php
                            endforeach;
                            else:
                        ?>
                            <tr>
                                <td colspan="19" align="center" style="color: red;">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 type="text/javascript" src="<?php echo assets('js/report.js')?>"></script> 