<?php include("conn.php");
$page='today Online 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
          if (isset($_POST['submit'])) {
            $id1=base64_decode($_POST['id']);

            $sql = "UPDATE `orders_details` SET `payment_status`='1' WHERE orderid='$id1'";
		if(mysqli_query($conn,$sql)){

      echo"<script>alert('Payment Confirmed')</script>";
		}
		else{
		  echo 'Error: '.mysqli_error($conn);
		}
              }

              if (isset($_POST['submits'])) {
                
                $id1=base64_decode($_POST['id']);
                $payment=$_POST['payment'];
                $payment_status=$_POST['payment_status'];

                if ($payment=='no' && $payment_status==0) {
                  echo"<script>alert('Confirmed Payment First')</script>";
                  
                }
                
             


                else{

                  $sql = "UPDATE `orders_details` SET `payment_status`='1' , `delivery_status`='1' WHERE orderid='$id1'";
                  if(mysqli_query($conn,$sql)){
              
                    echo"<script>alert('Delivery Confirmed')</script>";
                  }
                  else{
                    echo 'Error: '.mysqli_error($conn);
                  }
                
              }
                  }
     
      
    ?>    
<div class="action">

<?php
   $sql2="select * from orders_details where order_type=1 and 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_completed = mysqli_num_rows($result2) ;

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

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

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

<h5 class="text-center text-uppercase"> Today Online Orders History</h5>
<button class="btn btn-secondary m-1">Total Inprogress <b><?php echo $total_orders?></b></button>
  <button class="btn btn-success m-1">Total Completed <b><?php echo $total_completed?></b></button>
  <button class="btn btn-warning m-1">Total Canceled <b><?php echo $total_cancel?></b></button>
  <button class="btn btn-info m-1">Total On Delivery <b><?php echo $total_on_delivery?></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 " >
             
                <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>Payment Status</th>
                            <th>Delivery Status</th>
                            <th>Order Date</th>
                            <th>print</th>
                            <th>Details</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php

$sql2="SELECT * FROM currency ";
$result2 = mysqli_query($conn,$sql2)or die( mysqli_error($conn));
$row2=mysqli_fetch_array($result2) ;
$currency=$row2['curency'];

$sql="select * from orders_details where order_type=1 and date='$date' ";
$result = mysqli_query($conn,$sql)or die( mysqli_error($conn));
while ($row=mysqli_fetch_array($result)) {
  $id=$row['id'];
 $data=$row['orderid'];
   $customer_name=$row['costomer_name'];
   $price=$row['amount'];
   $status=$row['status'];
   $payment_status=$row['payment_status'];
   $delivery_status=$row['delivery_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);   

 $link="delete/del_blog.php?id=".urlencode(base64_encode($data));
 $edit_user="edit/edit_user.php?id=".urlencode(base64_encode($data));
 $activate="edit/user_status.php?id=".urlencode(base64_encode($data));
 $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'];
              $time=$row1['time'];
              $text='';
              $text_payment='';
             
             
              if ($payment_status==='1') {
                 $text_payment='Payment Confirmed';
                 $read_payment='badge-success';
               }
               else{
                 $text_payment='Confirm payment';
                 $read_payment='badge-secondary';
                 $btn_pay='view_data';
               }
             
              if ($status==1 && $delivery_status==0) {
                $text='Ready for delivery';
                $read='badge-info';
                $btn_deli='view_datase';
                $de='deactivate';
                $sta=0;
              }
             elseif ($status==0 && $delivery_status==0) {
                 $text='Cocking';
                 $read='badge-primary';
             }
             elseif ($status==2 && $delivery_status==0) {
                 $text='Cancelled';
                 $read='badge-warning';
             }
             elseif ($status==='1'&& $delivery_status=1) {
               $text='Delivery Completed';
               $read='badge-success';
             }
$link="print_receipt?p=online_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><input  type="button" name="view" value="<?php echo $text_payment ?>" id="<?php echo $row["orderid"]; ?>" class="btn <?php echo $read_payment ?> btn-sm <?php echo $btn_pay?>" /></td>
                            <td><input  type="button" name="view" value="<?php echo $text ?>" id="<?php echo $row["orderid"]; ?>" class="btn <?php echo $read ?> btn-sm <?php echo $btn_deli?>" /></td>
                            <td><?php echo $date." ".$time ?></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>Payment Status</th>
                            <th>Delivery Status</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>

<!-- Large modal -->
<div id="dataModals" 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 ">
    <div  id="employee_details" class="modal-content text-dark">
      
     
    
    </div>
  </div>
</div>

<!-- Large modal -->
<div id="dataModal" 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 ">
    <div  id="employee_detail" class="modal-content text-dark">
      
     
    
    </div>
  </div>
</div>

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

      
        </div>

    </div>
    
  <!--  isotope plugin cdn  -->
 
    <script src="js/script.js"></script>
     <!-- jQuery js-->
   <!-- jQuery Datatable js -->
   <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', {
          columnDefs: [ { type: 'date', 'targets': [4] } ],
          order: [[ 4, 'desc' ]],
            autoFill: true,
            pageLength : 10,
    lengthMenu: [[5, 10, 20, -1], [5, 10, 30, 'Todos']],
    layout: {
        topStart: {
            buttons: ['copy', 'csv', 'excel', 'pdf', 'print']
        }
    }
});
       } );
</script>
     <script>
       $(document).ready(function(){  
      $('.view_datas').click(function(){  
           var employee_ids = $(this).attr("id");  
           $.ajax({  
                url:"order_by_customer_ajax.php",  
                method:"post",  
                data:{employee_ids:employee_ids},  
                success:function(data){  
                     $('#employee_detail1').html(data);  
                     $('#dataModal1').modal("show");  
                }  
           });  
      });  
 });  
</script>
<script>
       $(document).ready(function(){  
      $('.view_datase').click(function(){  
           var employee_ids = $(this).attr("id");
            var page = "today_online_history";
           $.ajax({  
                url:"delivery_confirmation_ajax.php",  
                method:"post",  
                data:{employee_ids:employee_ids,page:page},  
                success:function(data){  
                     $('#employee_details').html(data);  
                     $('#dataModals').modal("show");  
                }  
           });  
      });  
 });  
</script>
<script>
       $(document).ready(function(){  
      $('.view_data').click(function(){  
           var employee_ids = $(this).attr("id");  
           var page = "today_online_history";
           $.ajax({  
                url:"payment_confirmation_ajax.php",  
                method:"post",  
                data:{employee_ids:employee_ids,page:page},  
                success:function(data){  
                     $('#employee_detail').html(data);  
                     $('#dataModal').modal("show");  
                }  
           });  
      });  
 });  
</script>
</body>

</html>