<?php include("conn.php");
$page='Today Order History';?>
<!DOCTYPE html>
<html lang="en">
<?php include("common/head.php")?>
<body>
<?php include("common/menu.php")?>
<!---side nav bar end-->
<?php include("common/tittle.php")?>
            <!--Main body Start-->
            <div id="accordions" class="col-sm-12  mt-2">
  
                <!--search section end-->
                <!--Orders start-->

                <!--order-items-->
                <!--order-items-one-->
            
                   <!--order-items-two-->
                   <?php
   $sql2="select * from orders_details where  status='0' and date='$date' ";
   $result2 = mysqli_query($conn,$sql2)or die( mysqli_error($conn));
   $total_orders = mysqli_num_rows($result2) ;

   $sql2="select * from orders_details where order_type=1 and status='1' and delivery_status=1 and date='$date'  ";
   $result2 = mysqli_query($conn,$sql2)or die( mysqli_error($conn));
   $total_online_completed = mysqli_num_rows($result2) ;

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

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

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

   $sql6="select SUM(amount)  FROM orders_details where order_type=1 and payment_status=1 and status=1 and date='$date'  ";
$result6= mysqli_query($conn,$sql6)or die( mysqli_error($conn));
$row6=mysqli_fetch_array($result6);
$amount_online=$row6['SUM(amount)'];

$sql6="select SUM(amount)  FROM orders_details where order_type=0 and payment_status=1  and  status=1 and date='$date'  ";
$result6= mysqli_query($conn,$sql6)or die( mysqli_error($conn));
$row6=mysqli_fetch_array($result6);
$amount_in_store=$row6['SUM(amount)'];

$sql6="select SUM(amount)  FROM orders_details where  payment_status=1 and status=1 and date='$date'  ";
$result6= mysqli_query($conn,$sql6)or die( mysqli_error($conn));
$row6=mysqli_fetch_array($result6);
$amountb=$row6['SUM(amount)'];
?>
               <!--order-items-three-->
<div class="action">
<button class="btn btn-secondary m-1">Total Inprogress <b><?php echo $total_orders?></b></button>
  <button class="btn btn-success m-1">Total online completed <b><?php echo $total_online_completed?></b></button>
  <button class="btn btn-success m-1">Total in store completed <b><?php echo $total_in_store_completed?></b></button>
  <button class="btn btn-warning m-1">Total cancelled <b><?php echo $total_cancel?></b></button>
  <button class="btn btn-info m-1">Total online Earning <b><?php echo $currency ." ". number_format($amount_online,2) ?></b></button>
  <button class="btn btn-info m-1">Total In-store Earning <b><?php echo $currency ." ". number_format($amount_in_store,2) ?></b></button>
  <button class="btn btn-info m-1">Total Earn <b><?php echo $currency ." ". number_format($amountb,2) ?></b></button>
</div>

               <!--order-items-three-->
               <div   style="overflow: scroll; height:100vh;" class="orders " >
                <h5 class="text-center text-uppercase"> Today Orders History</h5>
                <table id="example_table" class="table-customer table-striped   w-100 table-bordered">
                        <thead>
                        <tr>
                            <th>Id</th>
                            <th>Customer name</th>
                            <th >Amount</th>
                            <th>Order type</th>
                            <th>Order Date</th>
                            <th>print</th>
                            <th>Details</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php


$date=date("F j, Y");
$sql="select * from orders_details where date='$date' order by id desc";
$result = mysqli_query($conn,$sql)or die( mysqli_error($conn));
while ($row=mysqli_fetch_array($result)) {
 $data=$row['orderid'];
   $customer_name=$row['costomer_name'];
   $price=$row['amount'];
   $status=$row['status'];
   $order_type=$row['order_type'];
   
if ($order_type==1) {
 $order_type='Online Order';
}
else{
  $order_type='In Store Order';
}

   $real_id=substr($data,-2);
$ord = sprintf('%03d',$real_id);   


 $dat=$data;
 $sql1="select * from orders_details where orderid='$data' ";
              $result1 = mysqli_query($conn,$sql1)or die( mysqli_error($conn));
              $row1=mysqli_fetch_array($result1);

              $date=$row1['date'];
 $text='';

 if ($status==='1') {
   $text='Deliverd';
   $read='btn-success';
   $de='deactivate';
   $sta=0;
 }
elseif ($status==='0') {
    $text='Inprogress';
    $read='btn-warning';
}
elseif ($status==='2') {
    $text='Cancelled';
    $read='btn-danger';
}
$link="print_receipt?p=today_order_history&item=".urlencode(base64_encode($data));
?>
                        <tr>
                            <td>#<?php echo $ord ?></td>
                            <td><?php echo $customer_name ?></td>
                            <td><?php echo $currency ."". number_format($price,2) ?></td>
                            <td><?php echo $order_type ?></td>
                            <td><?php echo $date ?></td>
                            <td><a href="<?=$link; ?>" class="btn btn-success btn-sm me-1"><i class="fa fa-print"></i></a></td>
                            <td >
                            

                            <input  type="button" name="view" value="View" id="<?php echo $row["orderid"]; ?>" class="btn  btn-success btn-sm view_datas" />


                        </tr>
                        <?php } ?>
                        <thead>
                        <th>Id</th>
                            <th>Customer name</th>
                            <th >Amount</th>
                            <th>Order type</th>
                            <th>Order Date</th>
                            <th>print</th>
                            <th>Details</th>
                    </tbody>
                    </table>


            </div>

          


       <!--modal delete-->
<!-- Large modal -->
<div id="dataModal1" class="modal fade bd-example-modal-lg" tabindex="-1" data-backdrop="static" data-keyboard="false" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div  id="employee_detail1" class="modal-content text-dark">
      
     
    
    </div>
  </div>
</div>

         
                <!--Order end-->
            </div>
            <!--Main body 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 js-->
   <!-- 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 : 10,
    lengthMenu: [[5, 10, 20, -1], [5, 10, 20, 'Todos']],
    layout: {
        topStart: {
            buttons: ['copy', 'csv', 'excel', 'pdf', 'print']
        }
    }
});
       } );
</script>
     <script>
       $(document).ready(function(){  
      $('.view_datas').click(function(){  
           var employee_ids = $(this).attr("id");  
           var page = "today_order_history";
           $.ajax({  
                url:"order_by_customer_ajax.php",  
                method:"post",  
                data:{employee_ids:employee_ids,page:page},  
                success:function(data){  
                     $('#employee_detail1').html(data);  
                     $('#dataModal1').modal("show");  
                }  
           });  
      });  
 });  
</script>
</body>

</html>