  <?php 
    $this->load->view('templates/header');
    $action                     = (isset($_GET['action'])) ? $_GET['action'] : "";
    $search_value_stock_id      = (isset($_GET['search_value_stock_id'])) ? $_GET['search_value_stock_id'] : 0;
    $search_value_user          = (isset($_GET['search_value_user'])) ? $_GET['search_value_user'] : 0;
    $search_value_party         = (isset($_GET['search_value_party'])) ? $_GET['search_value_party'] : 0;
    $search_value_broker        = (isset($_GET['search_value_broker'])) ? $_GET['search_value_broker'] : 0;
    $search_value_status        = (isset($_GET['search_value_status'])) ? $_GET['search_value_status'] : 0;    
    $search_value_entry_date    = (isset($_GET['search_value_entry_date'])) ? $_GET['search_value_entry_date'] : date('d-m-Y');    
    $search_value_entry_no      = (isset($_GET['search_value_entry_no'])) ? $_GET['search_value_entry_no'] : 0;    
    $search_value_cert          = (isset($_GET['search_value_cert'])) ? $_GET['search_value_cert'] : 0;    
  ?>
    <script>
        var link = "report";
        var sub_link = "group_daily";
    </script>
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        GROUP WISE DAILY REPORT
        <small>REPORT</small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">Group Wise Daily 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/group_daily_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">
                                        <input type="text" class="form-control floating-input " name="search_value_entry_date" 
                                        id="search_value_entry_date" value="<?php echo $search_value_entry_date ?>" placeholder=" " readonly="readonly" />
                                        <label>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>                                   
                                        <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/group_report_excel'); ?>" class="btn btn-primary"><i class="fa fa-file-excel-o" aria-hidden="true"></i>
                                            Export
                                        </a> -->

                                        <a href="<?php echo base_url('report/Reportctrl/group_daily_report?action=view'); ?>" class="btn btn-primary"><i class="fa fa-undo" aria-hidden="true"></i>
                                            Reset
                                        </a>   
                                    </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 >DIAMOND GROUP</th>
                                    <th >OPENING STOCK</th> 
                                    <th >NEW STONE</th>       
                                    <!-- <th >STONE IN MEMO(ISSUE)</th>     -->
                                    <th >STONE SOLD</th>    
                                    <th >CLOSING STOCK</th>    
                                    <th >TOTAL ISSUED STONE</th>    
                                    <th >CLOSING STOCK AFTER ISSUE</th>    
                                </tr>
                            </thead>
                            <tbody>
                        <?php
                            if(!empty($data['opening_data'])):
                                $closing_fancy_bal = ($data['opening_data']['total_fancy_bal'] + $data['diamond_data']['total_fancy_pur']) - ($data['diamond_data']['total_fancy_sold']);

                                $closing_300_1000_bal = ($data['opening_data']['total_300_1000_bal'] + $data['diamond_data']['total_300_1000_pur']) - ($data['diamond_data']['total_300_1000_sold']);

                                $closing_200_299_bal = ($data['opening_data']['total_200_299_bal'] + $data['diamond_data']['total_200_299_pur']) - ($data['diamond_data']['total_200_299_sold']);

                                $closing_150_199_bal = ($data['opening_data']['total_150_199_bal'] + $data['diamond_data']['total_150_199_pur']) - ($data['diamond_data']['total_150_199_sold']);

                                $closing_100_149_bal = ($data['opening_data']['total_100_149_bal'] + $data['diamond_data']['total_100_149_pur']) - ($data['diamond_data']['total_100_149_sold']);

                                $closing_90_99_bal = ($data['opening_data']['total_90_99_bal'] + $data['diamond_data']['total_90_99_pur']) - ($data['diamond_data']['total_90_99_sold']);

                                $closing_80_89_bal = ($data['opening_data']['total_80_89_bal'] + $data['diamond_data']['total_80_89_pur']) - ($data['diamond_data']['total_80_89_sold']);

                                $closing_70_79_bal = ($data['opening_data']['total_70_79_bal'] + $data['diamond_data']['total_70_79_pur']) - ($data['diamond_data']['total_70_79_sold']);

                                $closing_01_69_bal = ($data['opening_data']['total_01_69_bal'] + $data['diamond_data']['total_01_69_pur']) - ($data['diamond_data']['total_01_69_sold']);

                                $closing_non_bal = ($data['opening_data']['total_non_bal'] + $data['diamond_data']['total_non_pur']) - ($data['diamond_data']['total_non_sold']);

                                $closing_fancy      = $closing_fancy_bal - $data['opening_data']['total_fancy_issue']; 
                                $closing_300_1000   = $closing_300_1000_bal - $data['opening_data']['total_300_1000_issue']; 
                                $closing_200_299    = $closing_200_299_bal - $data['opening_data']['total_200_299_issue']; 
                                $closing_150_199    = $closing_150_199_bal - $data['opening_data']['total_150_199_issue']; 
                                $closing_100_149    = $closing_100_149_bal - $data['opening_data']['total_100_149_issue']; 
                                $closing_90_99      = $closing_90_99_bal - $data['opening_data']['total_90_99_issue']; 
                                $closing_80_89      = $closing_80_89_bal - $data['opening_data']['total_80_89_issue']; 
                                $closing_70_79      = $closing_70_79_bal - $data['opening_data']['total_70_79_issue']; 
                                $closing_01_69      = $closing_01_69_bal - $data['opening_data']['total_01_69_issue']; 
                                $closing_non        = $closing_non_bal - $data['opening_data']['total_non_issue']; 
                        ?>
                            <tr>
                                <td>FANCY (PE-PR-CU-HT-EM-OV)</td>                                
                                <td><?php echo $data['opening_data']['total_fancy_bal']; ?></td>                                
                                <td><?php echo $data['diamond_data']['total_fancy_pur']; ?></td>
                                <!-- <td><?php echo $data['diamond_data']['total_fancy_issue']; ?></td> -->
                                <td><?php echo $data['diamond_data']['total_fancy_sold']; ?></td>
                                <td><?php echo $closing_fancy_bal; ?></td>
                                <td><?php echo $data['opening_data']['total_fancy_issue']; ?></td> 
                                <td><?php echo $closing_fancy; ?></td> 
                            </tr> 
                            <tr>
                                <td>3.00 UP ( 3.00 TO 10.00)</td>    
                                <td><?php echo $data['opening_data']['total_300_1000_bal']; ?></td>                            
                                <td><?php echo $data['diamond_data']['total_300_1000_pur']; ?></td>                            
                                <!-- <td><?php echo $data['diamond_data']['total_300_1000_issue']; ?></td>  -->
                                <td><?php echo $data['diamond_data']['total_300_1000_sold']; ?></td> 
                                <td><?php echo $closing_300_1000_bal; ?></td>
                                <td><?php echo $data['opening_data']['total_300_1000_issue']; ?></td>                            
                                <td><?php echo $closing_300_1000; ?></td>
                            </tr> 
                            <tr>
                                <td>2.00 TO 2.99</td> 
                                <td><?php echo $data['opening_data']['total_200_299_bal']; ?></td>                           
                                <td><?php echo $data['diamond_data']['total_200_299_pur']; ?></td>                            
                                <!-- <td><?php echo $data['diamond_data']['total_200_299_issue']; ?></td> -->
                                <td><?php echo $data['diamond_data']['total_200_299_sold']; ?></td>
                                <td><?php echo $closing_200_299_bal; ?></td>
                                <td><?php echo $data['opening_data']['total_200_299_issue']; ?></td>
                                <td><?php echo $closing_200_299; ?></td>
                            </tr>
                            <tr>
                                <td>1.50 TO 1.99</td>  
                                <td><?php echo $data['opening_data']['total_150_199_bal']; ?></td>                           
                                <td><?php echo $data['diamond_data']['total_150_199_pur']; ?></td>                            
                                <!-- <td><?php echo $data['diamond_data']['total_150_199_issue']; ?></td> -->
                                <td><?php echo $data['diamond_data']['total_150_199_sold']; ?></td>
                                <td><?php echo $closing_150_199_bal; ?></td>
                                <td><?php echo $data['opening_data']['total_150_199_issue']; ?></td>                           
                                <td><?php echo $closing_150_199; ?></td>
                            </tr>
                            <tr>
                                <td>1.00 TO 1.49</td>   
                                <td><?php echo $data['opening_data']['total_100_149_bal']; ?></td>                            
                                <td><?php echo $data['diamond_data']['total_100_149_pur']; ?></td>                            
                                <!-- <td><?php echo $data['diamond_data']['total_100_149_issue']; ?></td> -->
                                <td><?php echo $data['diamond_data']['total_100_149_sold']; ?></td>
                                <td><?php echo $closing_100_149_bal; ?></td>
                                <td><?php echo $data['opening_data']['total_100_149_issue']; ?></td>
                                <td><?php echo $closing_100_149; ?></td>
                            </tr>
                            <tr>
                                <td>0.90 TO 0.99</td>    
                                <td><?php echo $data['opening_data']['total_90_99_bal']; ?></td>                            
                                <td><?php echo $data['diamond_data']['total_90_99_pur']; ?></td>                            
                                <!-- <td><?php echo $data['diamond_data']['total_90_99_issue']; ?></td> -->
                                <td><?php echo $data['diamond_data']['total_90_99_sold']; ?></td>
                                <td><?php echo $closing_90_99_bal; ?></td>
                                <td><?php echo $data['opening_data']['total_90_99_issue']; ?></td>
                                <td><?php echo $closing_90_99; ?></td>
                            </tr>
                            <tr>
                                <td>0.80 TO 0.89</td>     
                                <td><?php echo $data['opening_data']['total_80_89_bal']; ?></td>                           
                                <td><?php echo $data['diamond_data']['total_80_89_pur']; ?></td>                            
                                <!-- <td><?php echo $data['diamond_data']['total_80_89_issue']; ?></td> -->
                                <td><?php echo $data['diamond_data']['total_80_89_sold']; ?></td>
                                <td><?php echo $closing_80_89_bal; ?></td>
                                <td><?php echo $data['opening_data']['total_80_89_issue']; ?></td>
                                <td><?php echo $closing_80_89; ?></td>
                            </tr> 
                            <tr>
                                <td>0.70 TO 0.79</td> 
                                <td><?php echo $data['opening_data']['total_70_79_bal']; ?></td>                           
                                <td><?php echo $data['diamond_data']['total_70_79_pur']; ?></td>                            
                                <!-- <td><?php echo $data['diamond_data']['total_70_79_issue']; ?></td>                             -->
                                <td><?php echo $data['diamond_data']['total_70_79_sold']; ?></td>                            
                                <td><?php echo $closing_70_79_bal; ?></td>
                                <td><?php echo $data['opening_data']['total_70_79_issue']; ?></td>
                                <td><?php echo $closing_70_79; ?></td>
                            </tr>
                            <tr>
                                <td>0.01 TO 0.69</td>
                                <td><?php echo $data['opening_data']['total_01_69_bal']; ?></td>                           
                                <td><?php echo $data['diamond_data']['total_01_69_pur']; ?></td>                            
                                <!-- <td><?php echo $data['diamond_data']['total_01_69_issue']; ?></td>                             -->
                                <td><?php echo $data['diamond_data']['total_01_69_sold']; ?></td>                            
                                <td><?php echo $closing_01_69_bal; ?></td>
                                <td><?php echo $data['opening_data']['total_01_69_issue']; ?></td>
                                <td><?php echo $closing_01_69; ?></td>
                            </tr> 
                            <tr>
                                <td>NON - CERTS</td>
                                <td><?php echo $data['opening_data']['total_non_bal']; ?></td>                           
                                <td><?php echo $data['diamond_data']['total_non_pur']; ?></td>                            
                                <!-- <td><?php echo $data['diamond_data']['total_non_issue']; ?></td> -->
                                <td><?php echo $data['diamond_data']['total_non_sold']; ?></td>
                                <td><?php echo $closing_non_bal; ?></td>
                                <td><?php echo $data['opening_data']['total_non_issue']; ?></td>
                                <td><?php echo $closing_non; ?></td>
                            </tr> 
                            <tr>
                                <td><b>TOTAL</b></td>
                                <td>
                                    <b><?php echo $data['opening_data']['total_fancy_bal'] + $data['opening_data']['total_300_1000_bal'] + $data['opening_data']['total_200_299_bal'] + $data['opening_data']['total_150_199_bal'] + $data['opening_data']['total_100_149_bal'] + $data['opening_data']['total_90_99_bal'] + $data['opening_data']['total_80_89_bal'] + $data['opening_data']['total_70_79_bal'] + $data['opening_data']['total_01_69_bal'] + $data['opening_data']['total_non_bal']  ; ?></b>
                                </td>                           
                                <td>
                                    <b><?php echo $data['diamond_data']['total_fancy_pur'] + $data['diamond_data']['total_300_1000_pur'] + $data['diamond_data']['total_200_299_pur'] + $data['diamond_data']['total_150_199_pur'] + $data['diamond_data']['total_100_149_pur'] + $data['diamond_data']['total_90_99_pur'] + $data['diamond_data']['total_80_89_pur'] + $data['diamond_data']['total_70_79_pur'] + $data['diamond_data']['total_01_69_pur'] + $data['diamond_data']['total_non_pur']; ?></b>
                                </td>                            
                                <!-- <td>
                                    <b><?php echo $data['diamond_data']['total_fancy_issue'] + $data['diamond_data']['total_300_1000_issue'] + $data['diamond_data']['total_200_299_issue'] + $data['diamond_data']['total_150_199_issue'] + $data['diamond_data']['total_100_149_issue'] + $data['diamond_data']['total_90_99_issue'] + $data['diamond_data']['total_80_89_issue'] + $data['diamond_data']['total_70_79_issue'] + $data['diamond_data']['total_01_69_issue'] + $data['diamond_data']['total_non_issue']; ?></b>                                        
                                </td> -->
                                <td>
                                    <b><?php echo $data['diamond_data']['total_fancy_sold'] + $data['diamond_data']['total_300_1000_sold'] + $data['diamond_data']['total_200_299_sold'] + $data['diamond_data']['total_150_199_sold'] + $data['diamond_data']['total_100_149_sold'] + $data['diamond_data']['total_90_99_sold'] + $data['diamond_data']['total_80_89_sold'] + $data['diamond_data']['total_70_79_sold'] + $data['diamond_data']['total_01_69_sold'] + $data['diamond_data']['total_non_sold']; ?></b>
                                </td>
                                <td>
                                    <b><?php echo $closing_fancy_bal + $closing_300_1000_bal + $closing_200_299_bal + $closing_150_199_bal + $closing_100_149_bal + $closing_90_99_bal + $closing_80_89_bal + $closing_70_79_bal + $closing_01_69_bal + $closing_non_bal; ?></b>                                        
                                </td>
                                <td>
                                    <b><?php echo $data['opening_data']['total_fancy_issue'] + $data['opening_data']['total_300_1000_issue'] + $data['opening_data']['total_200_299_issue'] + $data['opening_data']['total_150_199_issue'] + $data['opening_data']['total_100_149_issue'] + $data['opening_data']['total_90_99_issue'] + $data['opening_data']['total_80_89_issue'] + $data['opening_data']['total_70_79_issue'] + $data['opening_data']['total_01_69_issue'] + $data['opening_data']['total_non_issue']  ; ?></b>
                                </td>
                                <td>
                                    <b><?php echo $closing_fancy + $closing_300_1000 + $closing_200_299 + $closing_150_199 + $closing_100_149 + $closing_90_99 + $closing_80_89 + $closing_70_79 + $closing_01_69 + $closing_non; ?></b>                                        
                                </td>
                            </tr> 
                        <?php
                            else:
                        ?>
                            <tr>
                                <td colspan="8" align="center" style="color: red;">No Record Found!</td>
                            </tr>
                        <?php
                            endif;
                        ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </section>
  <?php 
    $this->load->view('templates/footer');
   ?>
   <script src="<?php echo assets('js/report.js')?>"></script>  