
<?php include("conn.php");
$page='Todays Sales';?>
<!DOCTYPE html>
<html lang="en">
<?php include("common/head.php");
if ($analytics=='none') {
    echo"<script>alert('You are not allow to access this page, contact your admintrator'); window.location.href='login'</script>";
  }
?>
<body >
<?php include("common/menu.php")?>
<!---side nav bar end-->
<?php include("common/tittle.php")?>
          

            <!--Main body Start-->
            <div class="col-sm-12 mt-2">
            
               <!--search section start-->


               <center>
                <?php include('button.php')?>
              </center>   
                       
      <hr class="bg-success">
                <!--search section end-->
                <!--Orders start-->


                
                
            <?php 
            $today= date("F j, Y");
            $yesterday=date('F j, Y',strtotime("-1 days"));
            $sql2="SELECT * FROM currency ";
            $result2 = mysqli_query($conn,$sql2)or die( mysqli_error($conn));
            $row2=mysqli_fetch_array($result2) ;
            $currency=$row2['curency'];
            
            /*order today*/
        $sql1="select  SUM(amount) from orders_details where status='1'and date='$today' ";
        $result1 = mysqli_query($conn,$sql1)or die( mysqli_error($conn));
        $row1=mysqli_fetch_array($result1);
        $amount=$row1['SUM(amount)'];

         /*order yesterday*/
         $sqls="select  SUM(amount) from orders_details where date='$yesterday' ";
         $results = mysqli_query($conn,$sqls)or die( mysqli_error($conn));
         $rows=mysqli_fetch_array($results);
         $amount_yesturday=$rows['SUM(amount)'];
         if($amount_yesturday<=0){
            $amount_yesturday=1;
        }

         /*bar earnings today*/
        $sql5="select  SUM(total)from orders where date='$today' and status='0' and location='Bar' ";
        $result5 = mysqli_query($conn,$sql5)or die( mysqli_error($conn));
        $row5=mysqli_fetch_array($result5);
        $bar_total=$row5['SUM(total)'];

        /*bar earnings yesterday*/
        $sql55="select  SUM(total)from orders where date='$yesterday' and status='0' and location='Bar' ";
        $result55 = mysqli_query($conn,$sql55)or die( mysqli_error($conn));
        $row55=mysqli_fetch_array($result55);
        $bar_total_yesterday=$row55['SUM(total)'];
        
        if($bar_total_yesterday<=0){
            $bar_total_yesterday=1;
        }
       
         $bar_percent=0;
         if (empty( $bar_total)) {
          $bar_total=1;
         }

          $bar_diff=$bar_total-$bar_total_yesterday;
          $bar_dec=$bar_diff/$bar_total_yesterday;
          $bar_percent=$bar_dec*100;
 
 
 if ($bar_percent<=0) {
    $sing='';
    $fa='<i class="fa fa-long-arrow-down" aria-hidden="true"></i>';
    $color='warning';

   
 }
 else {
   
   $sing='+';
   $fa='<i class="fa fa-long-arrow-up" aria-hidden="true"></i>';
   $color='';

 }
         
  if ($bar_total<70) {
    $bg='bg-primary';
  } 
  elseif ($bar_total>70) {
    $bg='bg-success';
  } 
  elseif ($bar_total<50) {
    $bg='bg-warning';
  }    
//Restaurant earning today
        $sql6="select  SUM(total) from orders where date='$today' and status='0' and location='Restaurant' ";
        $result6 = mysqli_query($conn,$sql6)or die( mysqli_error($conn));
        $row6=mysqli_fetch_array($result6);
        $restaurant_total=$row6['SUM(total)'];
       
        //Restaurant earning yesterday
        $sql6y="select  SUM(total) from orders where date='$yesterday' and status='0' and location='Restaurant' ";
        $result6y = mysqli_query($conn,$sql6y)or die( mysqli_error($conn));
        $row5y=mysqli_fetch_array($result6y);
        $restaurant_total_yesterday=$row5y['SUM(total)'];
        if($restaurant_total_yesterday<=0){
            $restaurant_total_yesterday=1;
        }
       
          $res_diff=$restaurant_total-$restaurant_total_yesterday;
          $res_dec=$res_diff/$restaurant_total_yesterday;
          $res_percent=$res_dec*100;
        if ($res_percent<=0) {
          $singr='';
          $far='<i class="fa fa-long-arrow-down" aria-hidden="true"></i>';
          $colorr='warning';
          
         
       }
       else {
         
         $singr='+';
         $far='<i class="fa fa-long-arrow-up" aria-hidden="true"></i>';
         $colorr='';
        
       }
               
        if ($restaurant_total<70) {
          $bgr='bg-primary';
        } 
        elseif ($restaurant_total>70) {
          $bgr='bg-success';
        } 
        elseif ($restaurant_total<50) {
          $bgr='bg-warning';
        } 



        $sql2="select * from orders_details where status='0' and date='$today' ";
        $result2 = mysqli_query($conn,$sql2)or die( mysqli_error($conn));
        $total_orders = mysqli_num_rows($result2) ;

        $sql3="select * from orders_details where   date='$today' ";
        $result3 = mysqli_query($conn,$sql3)or die( mysqli_error($conn));
        $total_orders = mysqli_num_rows($result3) ;

        $sql4="select * from customers where  date='$today' ";
        $result4 = mysqli_query($conn,$sql4)or die( mysqli_error($conn));
        $new_cus = mysqli_num_rows($result4) ;
 


        if (empty( $total_day_earning)) {
          $total_day_earning=0;
         }

      $total_day_earning=$amount;
      $total_yesterday_earning=$amount_yesturday;

      $total_earning_diff=$total_day_earning-$total_yesterday_earning;
      $total_dec=$total_earning_diff/$total_yesterday_earning;
      $total_percent=$total_dec*100;


if ($total_percent<=0) {
$singt='';
$fat='<i class="fa fa-long-arrow-down" aria-hidden="true"></i>';
$color='warning';


}
else {

$singt='+';
$fat='<i class="fa fa-long-arrow-up" aria-hidden="true"></i>';
$color='';

}
     
if ($total_day_earning<70) {
$bgt='bg-primary';
} 
elseif ($total_day_earning>70) {
$bgt='bg-success';
} 
elseif ($total_day_earning<50) {
$bgt='bg-warning';
}    
            ?>
                <div id="myList" class="menu-analytics row no-gutters m-0">
                
                    <div class="daily-report text-white  col-sm-12  m-0 ">
                        

                    <div class="col-sm-3 col-6 revenue">
                <div class="first-item">
                  <div class="item-label p-2">
                    <h6><?php echo $currency."". number_format($total_day_earning,2)?> <i style="float: right;" class="fa fa-money fa-lg fa-icon"></i></h6>
                    <div class="progress">
                      <div class="progress-bar progress-bar-striped <?php echo $bgt?> active" role="progressbar"
                      aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width:<?php echo $total_percent?>%">
                      </div>
                    </div>
                    <p style="font-size: 10px;" title="Yesterday sales was <?php echo  $currency."".  number_format($total_yesterday_earning,2) ?> " class="my-1">Today Earnings  <span style="float: right; font-size: 10px;"><?php echo $singt?><?php echo round($total_percent,1) ?>% <?php echo $fat?></span></p>
                  </div>
                </div>
              </div>

              <div class="col-sm-3  col-6  revenue ">
                <div class="first-item5">
                  <div class="item-label p-2">
                    <h6> <?php echo $total_orders?><i style="float: right;" class="fa fa-handshake-o fa-lg fa-icon"></i></h6>
                    <div class="progress">
                      <div class="progress-bar progress-bar-striped active" role="progressbar"
                      aria-valuenow="80" aria-valuemin="0" aria-valuemax="100" style="width:80%">
                      </div>
                    </div>
                    <p style="font-size: 10px;" class="my-1">Order Completed <span style="float: right;"></span></p>
                  </div>
                </div>
              </div>

              <div class="col-sm-3  col-6  revenue ">
                <div class="first-item4">
                  <div class="item-label p-2">
                    <h6><?php echo  $currency."".  number_format($bar_total,2)?> <i style="float: right;" class="fa fa-money  fa-lg fa-icon"></i></h6>
                    <div class="progress">
                      <div class="progress-bar progress-bar-striped <?php echo $bg?> active" role="progressbar"
                      aria-valuenow="70" aria-valuemin="0" aria-valuemax="100" style="width:<?php echo $bar_percent?>%;">
                      </div>
                    </div>
                    <p style="font-size: 10px;" title="Yesterday sales was <?php echo  $currency."".  number_format($bar_total_yesterday,2) ?> " class="my-1">Bar Earnings  <span style="float: right;"><?php echo $sing?><?php echo round($bar_percent,1) ?>% <?php echo $fa?> </span></p>
                  </div>
                </div>
              </div>

              <div class="col-sm-3  col-6 revenue ">
                <div class="first-item6">
                  <div class="item-label p-2">
                    <h6><?php echo  $currency."".  number_format($restaurant_total,2)?> <i style="float: right;" class="fa fa-money fa-lg fa-icon"></i></h6>
                    <div class="progress">
                      <div class="progress-bar progress-bar-striped <?php echo $bgr?> active" role="progressbar"
                      aria-valuenow="80" aria-valuemin="0" aria-valuemax="100" style="width:<?php echo $res_percent?>%">
                      </div>
                    </div>
                    <p style="font-size: 10px;"title="Yesterday sales was <?php echo  $currency."".  number_format($restaurant_total_yesterday,2) ?> "class="my-1">Restaurant Earnings  <span style="float: right;"><?php echo $singr?><?php echo round($res_percent,1) ?>% <?php echo $far?></span></p>
                  </div>
                </div>
              </div>

              <div class="col-sm-3 m-1  col-6 revenue ">
                <div class="first-item5">
                  <div class="item-label p-2">
                    <h6><?php echo $new_cus?><i style="float: right;" class="fa fa-handshake-o fa-lg fa-icon"></i></h6>
                    <div class="progress">
                      <div class="progress-bar progress-bar-striped active" role="progressbar"
                      aria-valuenow="80" aria-valuemin="0" aria-valuemax="100" style="width:80%">
                      </div>
                    </div>
                    <p style="font-size: 10px;" class="my-1">New Customers <span style="float: right;"></span></p>
                  </div>
                </div>
              </div>
                    <!---revanue section end ----->    
                    </div>

                    <div class="chart  col-sm-12">
                    <h5 class="text-center">Statistics Today</h5>
                      <div class="d-flex flex-wrap">
                      <div class="m-1 chart "id="myChart" style=" max-width:100%; height:300px;"></div>
                      <div class="m-1 chart"id="myChart1" style=" max-width:100%; height:300px;"></div>
                       <div class="m-1 chart"  id="myChart2" style=" margin-top: 10px; max-width:100%; height:300px;"></div>
</div>
                      </div>





                    <!-- <div id="chart_div" style="width: 100%; height: 500px;"></div>--->
        
                </div>

         
              
            </div>
            <!--Main body end-->

          

           
            <!--Invoice Section end-->

           
        </div>

    </div>
    
    <!--  isotope plugin cdn  -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.isotope/3.0.6/isotope.pkgd.min.js" integrity="sha256-CBrpuqrMhXwcLLUd5tvQ4euBHCdh7wGlDfNz8vbu/iI=" crossorigin="anonymous"></script>
    <script src="js/script.js"></script>
    <!--  isotope plugin cdn  -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.isotope/3.0.6/isotope.pkgd.min.js" integrity="sha256-CBrpuqrMhXwcLLUd5tvQ4euBHCdh7wGlDfNz8vbu/iI=" crossorigin="anonymous"></script>
    <script src="js/script.js"></script>
 
 
     <!-- jQuery Datatable js -->
     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" ></script>
     <script src="https://cdn.datatables.net/2.0.5/js/dataTables.js"></script>
     <script src="https://cdn.datatables.net/buttons/3.0.2/js/dataTables.buttons.js"></script>
     <script src="https://cdn.datatables.net/buttons/3.0.2/js/buttons.dataTables.js"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js"></script>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js"></script>
     <script src="https://cdn.datatables.net/buttons/3.0.2/js/buttons.html5.min.js"></script>
     <script src="https://cdn.datatables.net/buttons/3.0.2/js/buttons.print.min.js"></script>
     <script>
         $(document).ready( function () {
        new DataTable('#example_table', {
            order:[[2,"asc"]],
            autoFill: true,
            pageLength : 20,
    lengthMenu: [[5, 10, 20, -1], [5, 10, 20, 'Todos']],
    layout: {
        topStart: {
            buttons: ['copy', 'csv', 'excel', 'pdf', 'print']
        }
    }
});
       } );
       </script>
<!--auto refresh--->
<script>

   $(document).ready(function(){
setInterval(function(){
      $(".refreeshmes").load(window.location.href + " .refreeshmes" );
}, 3000);
});
 
</script>


    <!--google graph-->
   
 <?php 
  $query = "SELECT item_name, sum(quantity) FROM orders where date='$today' and location='Bar' group by item_name ";
  $res = $conn->query($query);
 ?>
<!--- bar grap --->
<script>

    
    google.charts.load('current', {'packages':['corechart']});
    google.charts.setOnLoadCallback(drawChart);
    
    function drawChart() {
    
    // Set Data
    const data = google.visualization.arrayToDataTable([
      ['Menu', 'Mhl'],
      <?php 
while($row00=$res->fetch_assoc())
{
    echo "['".$row00['item_name']."',".$row00['sum(quantity)']."],";
}

          ?>
    ]);
    
    // Set Options
    const options = {
      title:'  Bar demand forecasting ',
      is3D:true
    };
    
    // Draw
    const chart = new google.visualization.PieChart(document.getElementById('myChart'));
    chart.draw(data, options);
    
    }
    </script>
<!--restaurant graph--->
</script>


    <!--google graph-->
   
 <?php 
  $query = "SELECT item_name, sum(quantity) FROM orders where date='$today' and location='Restaurant' group by item_name ";
  $res = $conn->query($query);
 ?>

<script>

    
    google.charts.load('current', {'packages':['corechart']});
    google.charts.setOnLoadCallback(drawChart);
    
    function drawChart() {
    
    // Set Data
    const data = google.visualization.arrayToDataTable([
      ['Menu', 'Mhl'],
      <?php 
while($row00=$res->fetch_assoc())
{
    echo "['".$row00['item_name']."',".$row00['sum(quantity)']."],";
}

          ?>
    ]);
    
    // Set Options
    const options = {
      title:'  Restuarant demand forecasting ',
      is3D:true
    };
    
    // Draw
    const chart = new google.visualization.PieChart(document.getElementById('myChart1'));
    chart.draw(data, options);
    
    }
    </script>





<?php 
while($row80=$res->fetch_assoc())
{
   
}

          ?>

<script>
    google.charts.load('current', {'packages':['corechart']});
    google.charts.setOnLoadCallback(drawChart);
    
    function drawChart() {
    
    // Set Data
    const data = google.visualization.arrayToDataTable([
      ['Revenue', 'GHC'],
      <?php

$sql80="select date , SUM(total)  FROM orders GROUP BY date ORDER BY date desc LIMIT 7 ";
$result80 = mysqli_query($conn,$sql80)or die( mysqli_error($conn));
while ($row80=mysqli_fetch_array($result80)) {
 $date=$row80['date'];
$rtotal=$row80['SUM(total)'];

$dates = $date;
date('d', strtotime($dates));
$day=date('l', strtotime($dates));
$sql9="select SUM(amount)  FROM pole where date='$date' ";
$result9 = mysqli_query($conn,$sql9)or die( mysqli_error($conn));
$row9=mysqli_fetch_array($result9);
$amount=$row9['SUM(amount)'];

$sql10="select SUM(amount)  FROM pole_leason where date='$date' ";
$result10 = mysqli_query($conn,$sql10)or die( mysqli_error($conn));
$row10=mysqli_fetch_array($result10);
$amountp=$row10['SUM(amount)'];

$sql11="select SUM(amount)  FROM pole_leason where date='$date' ";
$result11 = mysqli_query($conn,$sql11)or die( mysqli_error($conn));
$row11=mysqli_fetch_array($result11);
$amountf=$row11['SUM(amount)'];

$sql6="select SUM(total)  FROM orders where location='Bar' and date='$date' ";
$result6= mysqli_query($conn,$sql6)or die( mysqli_error($conn));
$row6=mysqli_fetch_array($result6);
$amountb=$row6['SUM(total)'];

$sql7="select SUM(total)  FROM orders where location='Restaurant' and date='$date' ";
$result7= mysqli_query($conn,$sql7)or die( mysqli_error($conn));
$row7=mysqli_fetch_array($result7);
$amountr=$row7['SUM(total)'];

$total_earn=$rtotal+ $amount + $amountp+$amountf;


echo "['".$day."',".$total_earn."],";
}


?>
     
    ]);
    
    // Set Options
    const options = {
      title:'Daily  Revenue'
    };
    
    // Draw
    const chart = new google.visualization.BarChart(document.getElementById('myChart2'));
    chart.draw(data, options);
    
    }
    </script>


</body>

</html>