<?php
	include('common/header.php');
 // $d=$this->encrypt->encode('1');
 // $r=$this->encrypt->encode('2');
?>
<style>
.loader {
  border: 16px solid #f3f3f3;
  border-radius: 50%;
  border-top: 16px solid #3498db;
  width: 87px;
  height: 87px;
  margin-left: 608px;
  margin-top: 23px;
  -webkit-animation: spin 2s linear infinite; /* Safari */
  animation: spin 2s linear infinite;
}

/* Safari */
@-webkit-keyframes spin {
  0% { -webkit-transform: rotate(0deg); }
  100% { -webkit-transform: rotate(360deg); }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
</style>
<div>
  <select onchange="get_language()" name="language" id="language">
    <option>Select language</option>
    <option value="hindi">Hindi</option>
    <option value="english">English</option>
  </select>
</div>
<!-- Today Due -->
<div class="row">
  <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
     <div class="panel panel-default">
        <div class="panel-heading">
          <h3 class="panel-title">Today's Due</h3>
        </div>
        <div class="panel-body">
          <div class="table-responsive">
          <table width="100%"class="table table-bordered table-hover table-hover">
            <thead>
             <tr>
                    <th class="text-center">Customer Name</th>
                    <th class="text-center">City</th>
                    <th class="text-center">Dispenser</th>
                    <th class="text-center">Quantity</th>
                    <th class="text-center">Last refill date</th>
                    <th class="text-center">Action</th>
                </tr> 

                </thead>
                <tbody>
                  <?php 
                  $days='0';
                  $day=$this->encrypt->encode($days);
                  $count=count($todays);
                  if($count>0){
                  foreach ($todays as  $td) {
                  $dispenser_refill_id= $td['dispenser_refill_details_id'];
                  $id= $this->encrypt->encode($dispenser_refill_id);   
                    ?>
                  <tr>
                   <td class="text-center"><?php echo $td['customer_name']; ?></td>
                   <td class="text-center"><?php echo $td['city_name']; ?></td>
                   <td class="text-center"><?php echo $td['dispenser']; ?></td>
                   <td class="text-center"><?php echo ''; ?></td>
                   <td class="text-center"><?php echo get_date_dmy_format_wo_time($td['refill_date']); ?></td>
                  <td class="text-center"><a href="<?php echo base_url();?>index.php/gc/refill_sale_data/change_refill/<?php echo $id;?>/change">Change this Refill</a></td>
                </tr>
              <?php }}else{?>
                <tr>
                  <td class="text-center" colspan="12"><strong>No refill due today</strong></td>
                </tr>
              <?php } ?>
            </tbody>
          </table>
          <a href="<?php echo base_url();?>index.php/gc/refill_sale_data/list_refill_sale_data/<?php echo $day?>" style="float: right;font-size: 15px;"><strong>view all</strong></a>
           </div>
        </div>
  </div>
</div>

<!-- All Previous Due -->
 <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
     <div class="panel panel-default">
        <div class="panel-heading">
          <h3 class="panel-title">All Previous Due</h3>
        </div>
        <div class="panel-body">
          <div class="table-responsive">
                     
          <table width="100%"class="table table-bordered table-hover">
            <thead>
             <tr>
                    <th class="text-center">Customer Name</th>
                    <th class="text-center">City</th>
                    <th class="text-center">Dispenser</th>   
                    <th class="text-center">Quantity</th>                 
                    <th class="text-center">Last refill date</th>
                    <th class="text-center">Action</th>
                </tr>

                </thead>

                <tbody> 
              
                <tr>                    
                   <tbody>
                  <?php
                  $days='1';
                  $day=$this->encrypt->encode($days);
                  $count_previous=count($previous);
                  if ($count_previous>0) {
                  foreach ($previous as  $pre) {
                  $dispenser_refill_id= $pre['dispenser_refill_details_id'];
                  $id= $this->encrypt->encode($dispenser_refill_id);
                    ?>
                   <tr>
                   <td class="text-center"><?php echo $pre['customer_name']; ?></td>
                   <td class="text-center"><?php echo $pre['city_name']; ?></td>
                   <td class="text-center"><?php echo $pre['dispenser']; ?></td>
                   <td class="text-center"><?php echo ''; ?></td>
                   <td class="text-center"><?php echo get_date_dmy_format_wo_time($pre['refill_date']); ?></td>
                  <td class="text-center"><a href="<?php echo base_url();?>index.php/gc/refill_sale_data/change_refill/<?php echo $id;?>/change">Change this Refill</a></td>
                </tr>
              <?php }}else{?>
                <tr>
                  <td class="text-center" colspan="12"><strong>No refill due today</strong></td>
                </tr>
              <?php } ?>
            </tbody>
                </tr>
            </tbody>
          </table>
          <a href="<?php echo base_url();?>index.php/gc/refill_sale_data/list_refill_sale_data/<?php echo $day?>" style="float: right;font-size: 15px;"><strong>view all</strong></a>
          </div>
        </div>
  </div>
</div>
</div>
<!-- </div>
 --><!-- Today Due -->
<!-- All previous due -->
<!-- <div class="row"> -->
   
<!-- </div> -->
<!-- All previous due -->
<!-- past 7 days due -->
<div class="row">
   <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
     <div class="panel panel-default">
        <div class="panel-heading">
          <h3 class="panel-title">Next 30 Days Due</h3>
        </div>
        <div class="panel-body">
          <div class="table-responsive">
          <table width="100%"class="table table-bordered table-hover">
            <thead>
             <tr> 
                    <th class="text-center">Customer Name</th>
                    <th class="text-center">City</th>
                    <th class="text-center">Dispenser</th>
                    <th class="text-center">Quantity</th>                   
                    <th class="text-center">Last refill date</th>
                    <th class="text-center">Action</th>
                </tr>
                </thead>
                 <tbody>
                  <?php
                  $days='30';
                  $day=$this->encrypt->encode($days);
                  $count_seven=count($seven_days); 
                  if ($count_seven>0) {
                  foreach ($seven_days as  $sd) {
                  $dispenser_refill_id= $sd['dispenser_refill_details_id'];
                  $id= $this->encrypt->encode($dispenser_refill_id);
                   
                    ?>
                   <tr>
                   <td class="text-center"><?php echo $sd['customer_name']; ?></td>
                   <td class="text-center"><?php echo $sd['city_name']; ?></td>
                   <td class="text-center"><?php echo $sd['dispenser']; ?></td>
                   <td class="text-center"><?php echo ''; ?></td>
                   <td class="text-center"><?php echo get_date_dmy_format_wo_time($sd['refill_date']); ?></td>
                  <td class="text-center"><a href="<?php echo base_url();?>index.php/gc/refill_sale_data/change_refill/<?php echo $id;?>/change">Change this Refill</a></td>
                </tr>
              <?php }}else{?>
                <tr>
                  <td class="text-center" colspan="12"><strong>No refill due today</strong></td>
                </tr>
              <?php } ?>
            </tbody>
          </table>
          <a href="<?php echo base_url();?>index.php/gc/refill_sale_data/list_refill_sale_data/<?php echo $day?>" style="float: right;font-size: 15px;"><strong>view all</strong></a>
          </div>
        </div>
  </div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
     <div class="panel panel-default">
        <div class="panel-heading">
          <h3 class="panel-title"></h3>
        </div>
        <div class="panel-body">
          <div class="table-responsive">
          <table width="100%"class="table table-bordered table-hover">
            <thead>
              <tr>
                <th class="text-center">Total Customers</th>
                <th class="text-center">Total Sales Person</th>
                <th class="text-center">Total Dispenser</th>
               <!-- <th class="text-center">Total Refill</th> -->
              </tr>
              </thead>
              <tbody>
              <tr> 
                <?php
                $count_customer=count($customer);
                if($count_customer>0){?>
                   <td class="text-center"><strong><?php echo $count_customer; ?></strong></td>
               <?php }else{?>
                <td class="text-center"><strong>no data available</strong></td>
              <?php } ?>

               <?php 
               $count_user=count($user);
               if($count_user>0){ ?>
                   <td class="text-center"><strong><?php echo $count_user; ?></strong></td>
               <?php }else{?>
                <td class="text-center"><strong>no data available</strong></td>
              <?php } ?>

               <?php 
               $count_dispenser=count($dispenser);
               if($count_dispenser>0){?>
                <td class="text-center"><strong><?php echo $count_dispenser; ?></strong></td>
               <?php }else{?>
                <td class="text-center"><strong>no data available</strong></td>
              <?php } ?>
               <!--  <?php 
               $count_refill=count($refill);
               if($count_refill>0){?>
                   <td class="text-center"><strong><?php echo $count_refill; ?></strong></td>
               <?php }else{?>
                <td class="text-center"><strong>no data available</strong></td>
              <?php } ?> -->
              </tr>
         
            </tbody>
          </table>
         <!--  <a href="#" style="float: right;font-size: 15px;"><strong>view all</strong></a> -->
          </div>
        </div>
  </div>
</div>
</div>
<!-- past 7 days due -->
<!-- customer open -->
<!-- <div class="row"> -->
  
<!-- </div> -->
<!-- customer close -->
<!-- sale -->

<div class="row">
 <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
  <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title">Sales</h3>
      </div>
        <div class="panel-body">
          <div class="col-md-12" style="margin-bottom: 20px;">
            <div class="col-md-6">
              <div class="form-group">
                <label for="inputPassword3" class="col-sm-3 control-label"> From Date :</label>
                <div class="col-sm-5">
                 <div class="input-group">
                    <input class="form-control date-picker" id="date_picker2" type="text" data-date-format="dd-mm-yyyy" autocomplete="off">
                      <span class="input-group-addon">
                        <i class="fa fa-calendar bigger-110"></i>
                      </span>
                 </div>
                       
                </div>
              </div>
            </div>

            <div class="col-md-6">
              <div class="form-group">
                <label for="inputPassword3" class="col-sm-3 control-label">To Date :</label>
                <div class="col-sm-5">
                <div class="input-group">
                    <input class="form-control date-picker" id="date_picker3" type="text" data-date-format="dd-mm-yyyy" autocomplete="off">
                       <span class="input-group-addon">
                          <i class="fa fa-calendar bigger-110"></i>
                        </span>
                </div>
                      
                </div>
              </div>
            </div>
          </div>

          <div class="col-md-12" style="margin-bottom: 20px;">
            <div class="col-md-6">
              <div class="form-group">
                <label for="inputPassword3" class="col-sm-3 control-label">Branch :</label>
                <div class="col-sm-5">
                  <select class="form-control" id="branch" name="branch">
                    <option>Select Branch Name</option>
                    <?php 
                    foreach ($branch as $b) {?>
                        <option value="<?php echo $b['company_branch_id']; ?>"><?php echo $b['company_branch_name']; ?></option>
                      <?php } ?>
                  </select> 
              </div>
            </div>
            
            </div>
            
            <div class="col-md-2">
              <button class="btn btn-primary btn-md" id="go" value="go" name="go" type="button">Go</button>
            </div>
          </div>      
        

		<div class="col-xs-12">

      <div class="col-sm-3" id="loading">
         <div class="loader"></div>
      </div>
           <div class="col-md-3" id="top_customer">
           
            <div class="panel panel-default">
            <div class="panel-heading">
              <h3 class="panel-title">Top 5 Customer</h3>
            </div>                
               <div class="panel-body">
             <div class="table-responsive">
              <table width="100%"class="table table-bordered table-hover">
               <thead>
                    <th>Customer Name</th>
                    <th>Total Sales</th>
               </thead>
                <tbody id="customer">
                 
                </tbody>

              </table>
              <a href="<?php echo base_url();?>index.php/gc/customer_master/list_customer_master" style="float: right;font-size: 15px;"><strong>view all</strong></a>
                </div>
               </div>
              </div>
          
          </div>

           <div class="col-md-3" id="top_saleperson">
            <div class="panel panel-default">
            <div class="panel-heading">
              <h3 class="panel-title"> Top 5 Sales Person</h3>
            </div>                
               <div class="panel-body">
             <div class="table-responsive">
              <table width="100%"class="table table-bordered table-hover">
                <thead>
                    <th>Sales Person Name</th>
                    <th>Total Sales</th>
               </thead>
               
                <tbody id="sale_person">

                </tbody>
              </table>
              <a href="#" style="float: right;font-size: 15px;"><strong>view all</strong></a>
                </div>
               </div>
              </div>         
          </div>

          <div class="col-md-3" id="top_dispenser">
            <div class="panel panel-default">
            <div class="panel-heading">
              <h3 class="panel-title"> Top 5 Dispenser</h3>
            </div>                
               <div class="panel-body">
             <div class="table-responsive">
              <table width="100%"class="table table-bordered table-hover">
                <thead>
                    <th>Dispenser Name</th>
                    <th>Total Sales Price(INR)</th>
               </thead>
               
                <tbody id="dispenser">

                </tbody>
              </table>
               <a href="<?php echo base_url();?>index.php/gc/products/list_products/<?php echo $d; ?>" style="float: right;font-size: 15px;" style="float: right;font-size: 15px;"><strong>view all</strong></a>
                </div>
               </div>
              </div>         
          </div>

          <div class="col-md-3" id="top_refill">
            <div class="panel panel-default">
            <div class="panel-heading">
              <h3 class="panel-title"> Top 5 Refills</h3>
            </div>                
               <div class="panel-body">
             <div class="table-responsive">
              <table width="100%"class="table table-bordered table-hover">
                 <thead>
                    <th>Refill Name</th>
                    <th>Total Sales Price(INR)</th>
               </thead>
               
                  <tbody id="refill">
                  
                </tbody>

              </table>
              <a href="<?php echo base_url();?>index.php/gc/products/list_products/<?php echo $r; ?>" style="float: right;font-size: 15px;" style="float: right;font-size: 15px;"><strong>view all</strong></a>
                </div>
               </div>
              </div> 
                      
          </div>
		  </div>
		  

        </div>
      </div>
 </div> 
 <!-- <canvas id="myChart" style="max-width: 800px;"></canvas> -->
 </div>
</div>
<!-- sale close -->
<?php
	include('common/footer.php');
?>
<script>
$(document).ready(function(){
$('#loading').hide();
    $.ajax({
        url:"<?php echo base_url();?>index.php/gc/dashboard/fetch_customer",
        method:"POST",
        data:{
        },
        success:function(data){
          $('#customer').html(data);
          
        }
     });
     $.ajax({
        url:"<?php echo base_url();?>index.php/gc/dashboard/fetch_dispenser",
        method:"POST",
        data:{
        },
        success:function(data){
          $('#dispenser').html(data);
          
        }
     });
      $.ajax({
        url:"<?php echo base_url();?>index.php/gc/dashboard/fetch_refill",
        method:"POST",
        data:{
        },
        success:function(data){
          $('#refill').html(data);
          
        }
     });
      $.ajax({
        url:"<?php echo base_url();?>index.php/gc/dashboard/fetch_sale_person",
        method:"POST",
        data:{
        },
        success:function(data){
          $('#sale_person').html(data);
          
        }
     });

  $('#go').click(function(){
    
    $('#loading').show();
    $('#top_customer').hide();
    $('#top_saleperson').hide();
    $('#top_dispenser').hide();
    $('#top_refill').hide();
                    
    var branch = $('#branch').val(); 
    var date_picker2 = $('#date_picker2').val(); 
    var date_picker3 = $('#date_picker3').val(); 

        $.ajax({
        url:"<?php echo base_url();?>index.php/gc/dashboard/fetch_search_result",
        method:"POST",
        dataType: 'json',
        data:{
          branch:branch,
          date_picker2:date_picker2,
          date_picker3:date_picker3
        },
        success:function(data){   
                  $('#loading').hide();
                  $('#top_customer').show();
                  $('#top_saleperson').show();
                  $('#top_dispenser').show();
                  $('#top_refill').show();

                  $('#customer').html(data.customer); 
                  $('#sale_person').html(data.sale_person);
                  $('#dispenser').html(data.dispenser); 
                  $('#refill').html(data.refill);                 
        }
     });
  });
});
</script>
<script>
 
  $('#date_picker2,#date_picker3').datepicker({dateFormat: 'dd-mm-yy'});

  function get_language(){
    var language=$("#language").val();  
    alert(language);
    $.ajax({
        url:"<?php echo base_url();?>index.php/gc/Language",
        method:"POST",
        data:{
          language:language
        },
        success:function(data){
         
        }
     });
  }
    
</script> 
<!-- <script>
  var ctx = document.getElementById("myChart").getContext('2d');
  var myChart = new Chart(ctx, {
    type: 'bar',
    data: {
      labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
      datasets: [{
        label: 'Sales:2019',
        data: [6, 11, 14, 12, 10,9,17,15,5,6,13,19],
           
        backgroundColor: [
          'rgba(255, 99, 132, 0.2)',
          'rgba(255, 99, 132, 0.2)',
          'rgba(255, 99, 132, 0.2)',
          'rgba(255, 99, 132, 0.2)',
         'rgba(255, 99, 132, 0.2)',
          'rgba(255, 99, 132, 0.2)',
          'rgba(255, 99, 132, 0.2)',
          'rgba(255, 99, 132, 0.2)',
          'rgba(255, 99, 132, 0.2)',
          'rgba(255, 99, 132, 0.2)',
         'rgba(255, 99, 132, 0.2)',
         'rgba(255, 99, 132, 0.2)'
        ],
        borderColor: [
          'rgba(255,99,132,1)',
          'rgba(255,99,132,1)',
          'rgba(255,99,132,1)',
          'rgba(255,99,132,1)',
          'rgba(255,99,132,1)',
          'rgba(255,99,132,1)',
          'rgba(255,99,132,1)',
          'rgba(255,99,132,1)',
          'rgba(255,99,132,1)',
          'rgba(255,99,132,1)',
          'rgba(255,99,132,1)',
          'rgba(255,99,132,1)'
        ],
        borderWidth: 1
      }]
    },
    options: {
      scales: {
        yAxes: [{
          ticks: {
            beginAtZero: true
          }
        }]
      }
    }

  });

</script>
 -->

