  <?php
    $this->load->view('templates/header');
    $action                     = (isset($_GET['action'])) ? $_GET['action'] : "";
    $search_value_stock_id      = (isset($_REQUEST['search_value_stock_id'])) ? $_REQUEST['search_value_stock_id'] : 0;
    // $search_value_supplier_id      = (isset($_REQUEST['search_value_supplier_id'])) ? $_REQUEST['search_value_supplier_id'] : 0;
    $search_value_size            = (isset($_REQUEST['search_value_size'])) ? $_REQUEST['search_value_size'] : 0;
    $search_value_cpd            = (isset($_REQUEST['search_value_cpd'])) ? $_REQUEST['search_value_cpd'] : 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_from_pc_amt   = (isset($_REQUEST['search_value_from_pc_amt'])) ? $_REQUEST['search_value_from_pc_amt'] : '';
    $search_value_to_pc_amt    = (isset($_REQUEST['search_value_to_pc_amt'])) ? $_REQUEST['search_value_to_pc_amt'] : '';

    $search_value_from_dollar_amt   = (isset($_REQUEST['search_value_from_dollar_amt'])) ? $_REQUEST['search_value_from_dollar_amt'] : '';
    $search_value_to_dollar_amt     = (isset($_REQUEST['search_value_to_dollar_amt'])) ? $_REQUEST['search_value_to_dollar_amt'] : '';

    // $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_suspense   = (isset($_REQUEST['search_value_suspense'])) ? $_REQUEST['search_value_suspense'] : 0;

    $search_value_category   = (isset($_REQUEST['search_value_category'])) ? $_REQUEST['search_value_category'] : '';
  ?>
    <script>
        var link = "report";
        var sub_link = "stock";
    </script>
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        STOCK
        <small>REPORT</small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">Stock Report</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/stock_report/')?>" 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['supplier_id_drop_down'], $search_value_supplier_id,'id="search_value_supplier_id" name="search_value_supplier_id[]" class="form-control floating-select" multiple ');?>
                                        <label>SUPPLIER</label>
                                    </div> -->

                                    <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['size_drop_down'],$search_value_size,'id="search_value_size" name="search_value_size[]" class="form-control floating-select" multiple');?>
                                        <label>SIZE</label>
                                    </div>

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <?php echo form_dropdown('', $data['cpd_drop_down'],$search_value_cpd,'id="search_value_cpd" name="search_value_cpd[]" class="form-control floating-select" multiple');?>
                                        <label>CPD</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>SHAPE</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 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>CLAR.</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>FLUR.</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_ppc" value="<?php echo $search_value_from_ppc ?>" id="search_value_from_ppc" step="0.01" class="form-control floating-input">
                                        <label>FROM PRICE/CT</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/CT</label>
                                    </div>

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

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <input type="number" name="search_value_to_pc_amt" value="<?php echo $search_value_to_pc_amt ?>" id="search_value_to_pc_amt" step="0.01" class="form-control floating-input">
                                        <label>TO PC AMT</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/CT</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/CT</label>
                                    </div>

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

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <input type="number" name="search_value_to_dollar_amt" value="<?php echo $search_value_to_dollar_amt ?>" id="search_value_to_dollar_amt" step="0.01" class="form-control floating-input">
                                        <label>TO DOLLAR AMT</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-sm-2 floating-label">
                                        <?php echo form_dropdown('', $data['party_drop_down'], $search_value_party,'id="search_value_party" name="search_value_party" class="form-control floating-select flexselect" ');?>
                                        <label>PARTY</label>
                                    </div> -->

                                    <!-- <div class="col-md-2 col-sm-2 floating-label">
                                        <?php echo form_dropdown('', $data['broker_drop_down'], $search_value_broker,'id="search_value_broker" name="search_value_broker" class="form-control floating-select flexselect" ');?>
                                        <label>BROKER</label>
                                    </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 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('report/Reportctrl/stock_report?action=view'); ?>" class="btn btn-primary"><i class="fa fa-undo" aria-hidden="true"></i>
                                            Reset
                                        </a>
                                    </div>

                                    <div class="col-md-1 col-sm-1">
                                        <?php
                                            $url = $_SERVER['QUERY_STRING'];
                                        ?>
                                        <a target="_blank" href="<?php echo base_url('report/Reportctrl/stock_report_print?'.$url); ?>" class="btn btn-primary"><i class="fa fa-print" aria-hidden="true"></i>
                                            Print
                                        </a>
                                    </div>

                                    <div class="col-md-1 col-sm-1">

                                    <!-- <a target="_blank" href="<?php echo base_url('report/Reportctrl/diamond_master_excel?submit=excel&'.$url); ?>" 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-2 col-sm-2 ">
                                        <label for="inputEmail3" class="col-sm-1 control-label control-label_custom" style="width:100%;">
                                            Search Count :
                                            <span id="count_reload">
                                                <i id="total_rows"><?php echo $total_rows;?></i>
                                            </span>
                                        </label>
                                    </div>
                                </div>
                            </div>
                            <!-- <div class="panel panel-body remove-bottom">
                                <div class="form-group floating-form">
                                    <div class="col-md-2 col-sm-2 ">
                                        <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 >Return: <?php echo $data['return_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 >Issue: <?php echo $data['issue_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 >Hold: <?php echo $data['hold_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 class="col-md-1 col-sm-1 ">
                                        <label for="inputEmail3" class="col-sm-1 control-label control-label_custom" style="width:100%;">
                                            <i >Total: <?php echo $data['total_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 table-responsive" id="table_reload">
                        <table class="table table-bordered table-striped">
                            <thead>
                                <tr>
                                    <th width="3%">#</th>
                                    <!-- <th width="5%">SUPPLIER</th> -->
                                    <th width="6%">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%">STOCK IN</th>
                                    <th width="10%">STOCK OUT</th>
                                    <th width="10%">BALANCE</th>
                                    <!-- <th width="10%">RAP</th>
                                    <th width="10%">SUSPENSE STOCK</th> -->
                                </tr>
                            </thead>
                            <tbody>
                        <?php
                            $sub_total      = 0;
                            $disc           = 0;
                            $disc_amt       = 0;
                            $total_dollar   = 0;
                            $price_dm_crt  = 0;
                            
                            if(!empty($data['diamond_data'])):
                            $sr_no = $count + 1;
                            // Initialize grand totals
                            $grand_price_ct     = 0;
                            $grand_pc_amt       = 0;
                            $grand_dollar_ct    = 0;
                            $grand_dollar_amt   = 0;
                            $grand_qty          = 0;
                            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 = '';
                                }

                                 // Individual row totals
                                $qty              = !empty($value['dm_carat']) ? $value['dm_carat'] : 0;
                                $total_pc_amt     = !empty($value['dm_pc_amt']) ? $value['dm_pc_amt'] : 0;
                                $total_price_ct   = !empty($value['dm_price_ct']) ? $value['dm_price_ct'] : 0;
                                $total_dollar     = !empty($value['dm_dollar']) ? $value['dm_dollar'] : 0;
                                $total_dollar_amt = !empty($value['dm_dollar_amt']) ? $value['dm_dollar_amt'] : 0;

                                $stock_balance = $value['dm_stock_in'] - $value['dm_stock_out'];

                                // Add to grand totals
                                $grand_pc_amt     += $total_pc_amt;
                                $grand_qty        += $qty;
                                // $grand_qty        += $stock_balance;

                                $grand_price_ct   = ($grand_qty > 0) ? ($grand_pc_amt / $grand_qty) : 0;

                                $grand_dollar_amt += $total_dollar_amt;

                                $grand_dollar_ct  = ($grand_qty > 0) ? ($grand_dollar_amt / $grand_qty) : 0;

                                ?>
                                <?php echo $tr;?>
                                <td><?php echo $sr_no?></td>
                                <!-- <td><?php echo $value['supplier_name'];?></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($qty) ? $qty : ''; ?></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> -->
                                <td><?php echo $value['dm_stock_in']?></td>
                                <td><?php echo $value['dm_stock_out']?></td>
                                <td><?php echo $stock_balance; ?></td>

                               </tr>
                          <?php
                            $sr_no++;
                            endforeach;
                            ?>

                            <!-- ✅ Grand Total Row -->
                            <tr style="background:#f2f2f2; font-weight:bold;">
                                <td colspan="3" align="right">GRAND TOTAL:</td>
                                <td><?php echo number_format($grand_price_ct, 2); ?></td>
                                <td><?php echo number_format($grand_pc_amt, 2); ?></td>
                                <td><?php echo number_format($grand_dollar_ct, 2); ?></td>
                                <td><?php echo number_format($grand_dollar_amt, 2); ?></td>
                                <td colspan="6"></td>
                                <td><?php echo $grand_qty; ?></td>
                                
                                <td colspan="14"></td>
                            </tr>
                        <?php
                            else:
                          ?>
                            <tr>
                                <td colspan="35" 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" >
        $(document).ready(function(){
            $('#search_value_stock_id, #search_value_size, #search_value_cpd, #search_value_supplier_id, #search_value_sh, #search_value_wt, #search_value_col, #search_value_cla, #search_value_cut, #search_value_pol, #search_value_sym, #search_value_fl, #search_value_lab, #search_value_category').multiselect({
            nonSelectedText: 'Select',
            enableFiltering: true,
            enableCaseInsensitiveFiltering: true,
            buttonWidth:'100px',
            maxHeight:'450',
            includeSelectAllOption: true
            });

            disable_enable_background(false)
        });
   </script>