<?php include("conn.php");?>
<?php include("common/head.php");?>
<?php
 if(isset($_POST["employee_ids"]))  
 {  
      $data=$_POST['employee_ids'];
       $page=$_POST['page'];
  
      $sql = "SELECT * FROM orders_details WHERE orderid = '".$_POST["employee_ids"]."'";  
      $result = mysqli_query($conn, $sql);  
      while ($row=mysqli_fetch_array($result)) {
        $data=$row['orderid'];
        $contact=$row['contact'];
        $customer_name=$row['costomer_name'];
        $price=$row['amount'];
        $status=$row['status'];
        $date=$row['date'];
        $payment_method=$row['payment_method'];
        $by=$row['by'];
        $total=$row['amount'];
         $delivery_status=$row['delivery_status'];

        $sql1="select * from users where id='$id_user' ";
        $result1 = mysqli_query($conn,$sql1)or die( mysqli_error($conn));
        $row1=mysqli_fetch_array($result1);
        $fname=$row1['fname'];
        $sname=$row1['sname'];
        
        $sql10="select * from delivery_details where orderid='".$_POST["employee_ids"]."' ";
        $result10 = mysqli_query($conn,$sql10)or die( mysqli_error($conn));
        $row10=mysqli_fetch_array($result10);
        $receicer_contact=$row10['receiver'];
        $receiver_address=$row10['address'];

        $real_id=substr($data,-2);
     $ord = sprintf('%03d',$real_id);   
     
      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';
             }

      }}
?>
<div class="reciept-title text-center">
                       <p style="font-size:20px;">Order Details</p>
                   
                   <p>Order Id: <?php echo $ord ?></p>
                   <p>Date: <?php echo $date ?></p>
<p>Customer Name: <?php echo $customer_name ?></p>
<p>Customer Number: <?php echo $contact ?></p>
<p>Payment Method: <?php echo $payment_method?></p>
<p>Bill Prepared By: <?php echo $fname." ".$sname ?></p>
<p>Delivery Address: <?php echo $receiver_address?> </p>
<p>Receivers Contact: <?php echo $receicer_contact?> </p>

</div>
<div class="activate-itme text-center m-5">

<table class="table">
  <thead>
    <tr>
      <th scope="col">#id</th>
      <th scope="col">Quantity</th>
      <th scope="col">Item</th>
      <th scope="col">Price</th>
      <th scope="col">Total</th>
      <th scope="col">Status</th>
    </tr>
  </thead>
  <tbody>
 
  <?php 
  
include("conn.php"); 
$sql2="SELECT * FROM currency ";
$result2 = mysqli_query($conn,$sql2)or die( mysqli_error($conn));
$row2=mysqli_fetch_array($result2) ;
$currency=$row2['curency'];
 
      $sql3 = "SELECT * FROM orders WHERE orderid ='$data'";  
      $result3 = mysqli_query($conn, $sql3);  
      while ($row3=mysqli_fetch_array($result3)) {
        $data=$row3['orderid'];
        $itme_name=$row3['item_name'];
        $itme_id=$row3['item_id'];
        $quantity=$row3['quantity'];
        $price=$row3['price'];
        $status=$row3['status'];
          $text='';
          $text='';

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

          $amount='';
          $amount=$price*$quantity;
          
          $sql4 = "SELECT * FROM orders_details WHERE orderid ='$data'";  
      $result4 = mysqli_query($conn, $sql4);
      $row4=mysqli_fetch_array($result4);
       $delivery_status=$row4['delivery_status'];
       $status=$row4['status'];
      
       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';
             }

 ?>
    <tr>
      <th scope="row"><?php echo $itme_id ?></th>
      <td><?php echo $quantity?></td>
      <td><?php echo $itme_name ?></td>
      <td><?php echo $currency."". number_format($price,2) ?></td>
      <td><?php echo $currency."". number_format($amount,2) ?></td>
      <td><?php echo $text ?></td>
    </tr>
<?php } ?>
<tr>
                                        <th scope="row" colspan="4" class="border-0 ">Total</th>
                                        <td class="border-0 "><b class="m-0 fw-semibold"><?php echo $currency ?><?php echo number_format($total,2)?></b>
                                    </td>
                                    </tr>

  </tbody>
</table>
<a href="<?php echo $page?>" class=" btn btn-secondary  m-2">Close</a>
     </div>
