<style>
    .nopadding{
        padding:0;
    }
    .box_head{
        font-size:20px;
    }
    
    .table>thead>tr>th, .table>tbody>tr>th, .table>tfoot>tr>th, .table>thead>tr>td, .table>tbody>tr>td, .table>tfoot>tr>td {
        display: table-cell !important;
        text-align: center !important;
    }
    @media print{
        .table-bordered>thead>tr>th, .table-bordered>tbody>tr>th, .table-bordered>tfoot>tr>th, .table-bordered>thead>tr>td, .table-bordered>tbody>tr>td, .table-bordered>tfoot>tr>td {
            border-right: 1px solid #ddd !important;
            -webkit-print-color-adjust: exact !important;
        }
        .table>thead>tr>th, .table>tbody>tr>th, .table>tfoot>tr>th, .table>thead>tr>td, .table>tbody>tr>td, .table>tfoot>tr>td {
            display: table-cell !important;
            text-align: center !important;
        }
    }
</style>
<link href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css" rel="stylesheet"/>

<!--<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>-->
<script type="text/javascript" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function() {
    $('#example').DataTable( {
        "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
        "footerCallback": function ( row, data, start, end, display ) {
            var api = this.api(), data;
    
            // Remove the formatting to get integer data for summation
            var intVal = function ( i ) {
                return typeof i === 'string' ?
                    i.replace(/[\$,]/g, '')*1 :
                    typeof i === 'number' ?
                        i : 0;
            };
 
            // Total over all pages
            total = api
                .column( 4 )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
            totale = api
                .column( 5 )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
            totales = api
                .column( 6 )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
 
 
            // Total over this page
            pageTotal = api
                .column( 4, { page: 'current'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
 
            pageTotale = api
                .column( 5, { page: 'current'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
             pageTotales = api
                .column( 6, { page: 'current'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
            
 
            // Update footer
            $( api.column(4 ).footer() ).html(
                'SAR'+pageTotal +''
            );
             // Update footer
            $( api.column(5 ).footer() ).html(
                ' '+pageTotale +''
            );
           $( api.column(6 ).footer() ).html(
                'SAR'+pageTotales +''
            );
        }
    } );
} );
</script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#form').hide();
        $('.toggle_down').click(function () {
            $("#form").slideDown();
            return false;
        });
        $('.toggle_up').click(function () {
            $("#form").slideUp();
            return false;
        });

    });
</script>
<div class="box">
    <div class="box-header">
        <h2 class="blue"><i class="fa-fw fa fa-money"></i><?= lang('stock_counts'); ?></h2>
        
        <div class="box-icon">
            <ul class="btn-tasks">
                <li class="dropdown">
                    <a href="#" class="toggle_up tip" title="<?= lang('hide_form') ?>">
                        <i class="icon fa fa-toggle-up"></i>
                    </a>
                </li>
                <li class="dropdown">
                    <a href="#" class="toggle_down tip" title="<?= lang('show_form') ?>">
                        <i class="icon fa fa-toggle-down"></i>
                    </a>
                </li>
            </ul>
        </div>
    </div><?php //print_r($product);die();?>
    
    <div class="box-content">
        <div class="row">
            <div class="col-lg-12">
                <div class="pull-right">
                    <button type="button" class="no-print btn btn-primary" onclick="window.print();">Print</button>
                </div>
            </div>
            <div class="col-lg-12 nopadding box_head">
                <span class="col-md-4 text-left"><b>Route: </b></span>
                <?php 
                if($warehouse_product){
                $warehouse_name = $this->db->get_where('warehouses',array('id'=>$warehouse_product))->row()->name;
                
                ?>
                <span class="col-md-4 text-center"><b>Warehouse:<?= $warehouse_name?></b></span>
                <?php } 
                else {
                    ?>
                     <span class="col-md-4 text-center"><b>Warehouse:</b></span>
                    <?php 
                }?>
                <span class="col-md-4 text-right"><b>Date:<?php if ($this->input->post('start_date')) {
                echo "From " . $this->input->post('start_date') . " to " . $this->input->post('end_date');
            }?> </b></span>
            </div>
            <div class="col-lg-6 upper_portion">
              
            </div>
            <div class="col-lg-6 upper_portion">
            
               
            </div>
            <div class="col-lg-12">
                <div id="form">

                    <?php echo admin_form_open("reports/daily_sales_product"); ?>
                    <div class="row">
                       
                       
                        <div class="col-sm-4">
                            <div class="form-group">
                                <label class="control-label" for="warehouse"><?= lang("warehouse"); ?></label>
                                <?php
                                $wh[""] = lang('select').' '.lang('warehouse');
                                foreach ($warehouses as $warehouse) {
                                    $wh[$warehouse->id] = $warehouse->name;
                                }
                                echo form_dropdown('warehouse', $wh, (isset($_POST['warehouse']) ? $_POST['warehouse'] : ""), 'class="form-control" id="warehouse" data-placeholder="' . $this->lang->line("select") . " " . $this->lang->line("warehouse") . '"');
                                ?>
                            </div>
                        </div>
                        
                      <div class="col-sm-4">
                            <div class="form-group">
                                <?= lang("start_date", "start_date"); ?>
                                <?php echo form_input('start_date', (isset($_POST['start_date']) ? $_POST['start_date'] : ""), 'class="form-control datetime" id="start_date"'); ?>
                            </div>
                        </div>
                        <div class="col-sm-4">
                            <div class="form-group">
                                <?= lang("end_date", "end_date"); ?>
                                <?php echo form_input('end_date', (isset($_POST['end_date']) ? $_POST['end_date'] : ""), 'class="form-control datetime" id="end_date"'); ?>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <div
                            class="controls"> <?php echo form_submit('submit_report', $this->lang->line("submit"), 'class="btn btn-primary"'); ?> </div>
                    </div>
                    <?php echo form_close(); ?>

                </div>
                <?php if (!empty($warehouse_product)){?>
                <div class="table-responsive text-center">
                  <table id="example1" class="table table-bordered display" style="width:100%">
                       <thead>
                           <th>#</th>
                           <th style="display: tebel-cell !important;">Item</th>
                           <th>Op Stock</th>
                           <th>SR</th>
                           <th>Bal Stock</th>
                           <th>SR</th>
                           <th>Sale</th>
                           <th>Purchase</th>
                           <th>Total</th>
                       </thead>
                       <tbody>
                         <?php 
                         $cdare = date('Y-m-d');
                         $this->db->select('*');
        $this->db->where('compare_date', $cdare);
        $prodtsw = $this->db->get('daily_stock');
        $productsw =  $prodtsw->result();
                         if($productsw){ //print_r($products_sale);die();
                             $count=1;
                            
                         foreach($productsw as $row){  
                            $quantity=0;
                        ?>
                        <?php if(($row->unit_price) > 250 && ($row->unit_price) <= 300 &&  ($row->brand)!= 0 ){?>
                           <tr>
                               <td><?= $count++;?></td>
                             <?php  $product_details 	= $this->site->getProductByID($row->product_id);?>
                               <td><?php echo $product_details->name;?></td>
                             
                                 <td></td>
                                 <td></td>
                                  <td></td>
                                 <td></td>
                                 
                                 <td></td>
                                
                           </tr>
                           <?php }}?>
                           <tr>
                               <td>
                                   
                               </td>
                               <td>
                                   
                               </td>
                           </tr>
               <?php  foreach($productsw as $row1){ ?>
               <?php if(($row1->unit_price) > 200 && ($row1->unit_price) <= 250 &&  ($row1->brand)!= 0 ){?>
                           <tr>
                               <td><?= $count++;?></td>
                             
                                 <?php  $product_details 	= $this->site->getProductByID($row1->product_id);?>
                               <td><?php echo $product_details->name;?></td>
                             
                              
                           </tr>
                           <?php }}?>
                           <tr>
                               <td>
                                   
                               </td>
                               <td>
                                   
                               </td>
                           </tr>
               <?php  foreach($productsw as $row2){ ?>
               <?php if(($row2->unit_price) > 195 && ($row2->unit_price) <= 200 &&  ($row2->brand)!= 0 ){?>
                           <tr>
                               <td><?= $count++;?></td>
                             
                                 <?php  $product_details 	= $this->site->getProductByID($row2->product_id);?>
                               <td><?php echo $product_details->name;?></td>
                             
                              
                           </tr>
                           <?php }}?>
                           <tr>
                               <td>
                                   
                               </td>
                               <td>
                                   
                               </td>
                           </tr>
                           <?php  foreach($productsw as $row3){ ?>
               <?php if(($row3->unit_price) > 190 && ($row3->unit_price) <= 195 &&  ($row3->brand)!= 0 ){?>
                           <tr>
                               <td><?= $count++;?></td>
                             
                                  <?php  $product_details 	= $this->site->getProductByID($row3->product_id);?>
                               <td><?php echo $product_details->name;?></td>
                             
                              
                           </tr>
                           <?php }}?>
                           <tr>
                               <td>
                                   
                               </td>
                               <td>
                                   
                               </td>
                           </tr>
                            <?php  foreach($productsw as $row4){ ?>
               <?php if(($row4->unit_price) > 160 && ($row4->unit_price) <= 190 &&  ($row4->brand)!= 0 ){?>
                           <tr>
                               <td><?= $count++;?></td>
                             
                               <   <?php  $product_details 	= $this->site->getProductByID($row4->product_id);?>
                               <td><?php echo $product_details->name;?></td>
                             
                              
                           </tr>
                           <?php }}?>
                           <tr>
                               <td>
                                   
                               </td>
                               <td>
                                   
                               </td>
                           </tr>
                            <?php  foreach($productsw as $row5){ ?>
               <?php if(($row5->unit_price) > 150 && ($row5->unit_price) <= 160 &&  ($row5->brand)!= 0 ){?>
                           <tr>
                               <td><?= $count++;?></td>
                             
                               <td><?php echo $row5->name;?></td>
                              
                           </tr>
                           <?php }}?>
                           <tr>
                               <td>
                                   
                               </td>
                               <td>
                                   
                               </td>
                           </tr>
                           <?php  foreach($productsw as $row6){ ?>
               <?php if(($row6->unit_price) > 147 && ($row6->unit_price) <= 148 &&  ($row6->brand)!= 0 ){?>
                           <tr>
                               <td><?= $count++;?></td>
                             
                               <td><?php echo $row6->name;?></td>
                              
                           </tr>
                           <?php }}?>
                           <tr>
                               <td>
                                   
                               </td>
                               <td>
                                   
                               </td>
                           </tr>
                            <?php  foreach($productsw as $row7){ ?>
               <?php if(($row7->unit_price) > 146 && ($row7->unit_price) <= 147 &&  ($row7->brand)!= 0 ){?>
                           <tr>
                               <td><?= $count++;?></td>
                             
                               <td><?php echo $row7->name;?></td>
                              
                           </tr>
                           <?php }}?>
                           <tr>
                               <td>
                                   
                               </td>
                               <td>
                                   
                               </td>
                           </tr>
                           <?php  foreach($productsw as $row8){ ?>
               <?php if(($row8->unit_price) > 135 && ($row8->unit_price) <= 146 &&  ($row8->brand)!= 0 ){?>
                           <tr>
                               <td><?= $count++;?></td>
                             
                               <td><?php echo $row8->name;?></td>
                              
                           </tr>
                           <?php }}?>
                           <tr>
                               <td>
                                   
                               </td>
                               <td>
                                   
                               </td>
                           </tr>
                           <?php  foreach($productsw as $row9){ ?>
               <?php if(($row9->unit_price) > 125 && ($row9->unit_price) <= 135 &&  ($row9->brand)!= 0 ){?>
                           <tr>
                               <td><?= $count++;?></td>
                             
                               <td><?php echo $row9->name;?></td>
                              
                           </tr>
                           <?php }}?>
                           <tr>
                               <td>
                                   
                               </td>
                               <td>
                                   
                               </td>
                           </tr>
                            <?php  foreach($productsw as $row10){ ?>
               <?php if(($row10->unit_price) > 115 && ($row10->unit_price) <= 125 &&  ($row10->brand)!= 0 ){?>
                           <tr>
                               <td><?= $count++;?></td>
                             
                               <td><?php echo $row10->name;?></td>
                              
                           </tr>
                           <?php }}?>
                           <tr>
                               <td>
                                   
                               </td>
                               <td>
                                   
                               </td>
                           </tr>
                           <?php  foreach($productsw as $row11){ ?>
               <?php if(($row11->unit_price) > 110 && ($row11->unit_price) <= 115 &&  ($row11->brand)!= 0 ){?>
                           <tr>
                               <td><?= $count++;?></td>
                             
                               <td><?php echo $row11->name;?></td>
                              
                           </tr>
                           <?php }}?>
                           <tr>
                               <td>
                                   
                               </td>
                               <td>
                                   
                               </td>
                           </tr>
                             <?php  foreach($productsw as $row12){ ?>
               <?php if(($row12->unit_price) > 105 && ($row12->unit_price) <= 110 &&  ($row12->brand)!= 0 ){?>
                           <tr>
                               <td><?= $count++;?></td>
                             
                               <td><?php echo $row12->name;?></td>
                              
                           </tr>
                           <?php }}?>
                           <tr>
                               <td>
                                   
                               </td>
                               <td>
                                   
                               </td>
                           </tr>
                           <?php  foreach($productsw as $row13){ ?>
               <?php if(($row13->unit_price) > 0 && ($row13->unit_price) <= 105 &&  ($row13->brand)!= 0 ){?>
                           <tr>
                               <td><?= $count++;?></td>
                             
                               <td><?php echo $row13->name;?></td>
                              
                           </tr>
                           <?php }}?>
                           <tr>
                               <td>
                                   
                               </td>
                               <td>
                                   
                               </td>
                           </tr>
                            <?php  foreach($productsw as $row14){ ?>
               <?php if(($row14->unit_price) > 0 && ($row14->unit_price) <= 100 &&  ($row14->brand)== 0 ){?>
                           <tr>
                               <td><?= $count++;?></td>
                             
                               <td><?php echo $row14->name;?></td>
                              
                           </tr>
                            <tr>
                               <td>
                                   
                               </td>
                               <td>
                                   
                               </td>
                           </tr>
                           <?php }}?>
                          
                          
              
              <?php
                       
                        
                         }
              ?>
                       </tbody>
                    </table>
                  
                </div>
                <?php } 
                else {
                    ?>
                    <div class="table-responsive text-center">
                   <table id="example1" class="table table-bordered display" style="width:100%">
                       <thead>
                           <td>#</td>
                           <th style="display: tebel-cell !important;">Item</th>
                           <th>Op Stock</th>
                           <th>SR</th>
                           <th>Bal Stock</th>
                           <th>SR</th>
                           <th>Sale</th>
                           <th>Purchase</th>
                           <th>Total</th>
                       </thead>
                       <tbody>
                         
                           <tr>
                               <td colspan="9">NO WAREHOUSE WERE SELECTED</td>
                           </tr>
                          
                           </tbody>
                           </table>
                           </div>
                    <?php 
                }?>
            </div>
        </div>
    </div>
</div>