<?php include('header.php');?>
<?php
unset($_SESSION['order_cod']);

// Check if the customer is logged in or not
if(!isset($_SESSION['customer'])) {
    header('location: '.BASE_URL.'logout.php');
    exit;
} else {
    // If customer is logged in, but admin make him inactive, then force logout this user.
    $statement = $pdo->prepare("SELECT * FROM tbl_customer WHERE cust_id=? AND cust_status=?");
    $statement->execute(array($_SESSION['customer']['cust_id'],0));
    $total = $statement->rowCount();
    if($total) {
        header('location: '.BASE_URL.'logout.php');
        exit;
    }
}
?>

                          
        <section class="account-page section-padding">
         <div class="container">
            <div class="row">
               <div class="col-lg-10 mx-auto">
                  <div class="row no-gutters">
                     <div class="col-md-4">
                        <div class="card account-left">
                           <div class="user-profile-header">
                              <img alt="logo" src="assets/uploads/user.PNG">
                              <h5 class="mb-1 text-secondary"><strong>Hi </strong> <?php echo $_SESSION['customer']['cust_name']; ?></h5>
                              <p><?php echo $_SESSION['customer']['cust_phone']; ?></p>
                           </div>
                           <div class="list-group">
                              <a href="my-profile.php" class="list-group-item list-group-item-action"><i aria-hidden="true" class="mdi mdi-account-outline"></i>  My Profile</a>
                              <a href="orderlist.php" class="list-group-item list-group-item-action active"><i aria-hidden="true" class="mdi mdi-format-list-bulleted"></i>  Order List</a> 
                              <a href="customer-password-update.php" class="list-group-item list-group-item-action"><i aria-hidden="true" class="mdi mdi-key"></i>  Password Update</a> 
                              <a href="logout.php" class="list-group-item list-group-item-action"><i aria-hidden="true" class="mdi mdi-lock"></i>  Logout</a> 
                           </div>
                        </div>
                     </div>
                     <div class="col-md-8">
                        <div class="card card-body account-right">
                           <div class="widget">
                              <div class="section-header">
                                 <h5 class="heading-design-h5">
                                    Order List
                                 </h5>
                              </div>
                              <div class="order-list-tabel-main table-responsive">
                                 <table class="datatabel table table-striped table-bordered order-list-tabel"  style="width:100%;min-width:1050px;" cellspacing="0">
                                    <thead>
                                       <tr>
                                          <th>Order Id</th>
                                          <th>Product Details</th>
                                          <th>Total</th>
                                          <th>Shipping Cost</th>
                                          <th>Discount</th>
                                          <th>Final Total</th>
										   <th>Order Date</th>
                                          <th>Status</th>
                                          <th>Action</th>
										</tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                            $statement = $pdo->prepare("SELECT * FROM tbl_payment WHERE customer_email=? ORDER BY id DESC");
                                            $statement->execute(array($_SESSION['customer']['cust_email']));
                                            $result = $statement->fetchAll(PDO::FETCH_ASSOC);
                                            foreach ($result as $row) {
                                        $tip++;
                                        ?>
                                        <tr>
                                        <td>#<?php echo $row['payment_id'];?></td>
                                        <td style="width:500px;">
                                            <?php
                                            
                                            $q=0;
                                            $statement1 = $pdo->prepare("SELECT * FROM tbl_order WHERE payment_id=?");
                                            $statement1->execute(array($row['payment_id']));
                                            $result1 = $statement1->fetchAll(PDO::FETCH_ASSOC);
                                            foreach ($result1 as $row1) {
                                                
                                            $q++;
                                                echo '<strong>'.$q.'. '.$row1['product_name'].'</strong><br>';
												
												 if($row1['size']!=null){
                                                echo $row1['size'].',  &nbsp;';
												 }
												 if($row1['color']!=null){
                                                echo $row1['color'].'<br>';
												 }
                                                echo 'Qty : '.$row1['quantity'].',&nbsp;';
                                                echo 'Rate : ' .LANG_VALUE_1.'&nbsp;'.number_format($row1['unit_price'],2).', ';
                                               echo 'Total : ' .LANG_VALUE_1.'&nbsp;'.number_format($row1['quantity']*$row1['unit_price'],2).'<hr>';
											   
											  $xx += $row1['quantity']*$row1['unit_price'];
                                            }
                                            ?>
                                        </td>
										<td><?php echo LANG_VALUE_1.'&nbsp;'.number_format($xx,2);?></td>
										<td><?php
										
										    $statement5 = $pdo->prepare("SELECT * FROM applied_shipping_cost WHERE payment_id=? AND user_id=?");
                                            $statement5->execute(array($row['payment_id'],$_SESSION['customer']['cust_id']));
                                            $result5 = $statement5->fetchAll(PDO::FETCH_ASSOC);
                                            foreach ($result5 as $row5) 
                                            {
                                                $shipping_cost = $row5['shipping_cost'];
                                            }
                                            if($shipping_cost){
                                                $shipping_cost2 = LANG_VALUE_1.' '.$shipping_cost;
                                            }
                                            else{
                                                $shipping_cost2='FREE';
                                            }
										$xx = $xx+$shipping_cost;
										echo $shipping_cost2;
										?></td>
                                        <td>
                                        <?php 
                                        
                                            $statement5 = $pdo->prepare("SELECT * FROM applied_coupon WHERE payment_id=? AND user_id=?");
                                            $statement5->execute(array($row['payment_id'],$_SESSION['customer']['cust_id']));
                                            $result5 = $statement5->fetchAll(PDO::FETCH_ASSOC);
                                            foreach ($result5 as $row5) 
                                            {
                                                $coupon_id = $row5['coupon_id'];
                                            }
                                        
                                            $statement5 = $pdo->prepare("SELECT * FROM tbl_coupon WHERE coupon_id=?");
                                            $statement5->execute(array($coupon_id));
                                            $result5 = $statement5->fetchAll(PDO::FETCH_ASSOC);
                                            foreach ($result5 as $row5)
                                            {
                                                $discount_percentage = $row5['percentage'];
                                            }
                                        
                                        
                                        $ddd =  ($xx/100)*$discount_percentage;
                                        echo LANG_VALUE_1.'&nbsp;'.$ddd; 
                                        
                                        ?></td>
                                        <td><?php
                                        
                                        $fgh = $xx-$ddd;
                                        echo LANG_VALUE_1.'&nbsp;'.$fgh;
                                        
                                        ?></td>
                                        <td><?php echo date('d M Y h:i:s A',strtotime($row['payment_date'])); ?></td>
                                    
                                      
                                   
                                      
                                            
                                            
                                            
                                            
                                             <td>
                                                 <strong>
                            <?php
                        if($row['shipping_status']=='Pending'){ ?>
						
					Deliver whithin 90 Minut to 12 hour
							
					<?php	}
						else{
							echo $row['shipping_status'];
						}
							?></strong>
                            </td>
                            
                            <td>
                                 <?php
                                 
                                 if($row['shipping_status']=='Pending'){
                                 
                                 ?>
						
                                <form action="#order_cancle.php" method="post">
                                    <input type="hidden" name="order_id" value="" />
                                    <button type="submit" class="btn btn-sm btn-danger">Cancle Order</button>
                                </form>
                                
                                <?php 
                                     
                                 }
                                 else
                                 {
                                     ?>
                                     
                                     
                                <form action="order_return.php" method="post">
                                    <input type="hidden" name="order_id" value="" />
                                    <button type="submit" class="btn btn-sm btn-warning">Return Order</button>
                                </form>
                                
                                <button type="submit" class="btn btn-sm btn-info"> Order Delivered</button>
                                <?php
                                 }
                                ?>
                            </td>
                                    </tr>
                                    <?php
									$xx=0;
                                }
                                ?>                               
                                
                                       
                                    </tbody>
                                 </table>
                              </div>
                           </div>
                        </div>
                     </div>
                  </div>
               </div>
            </div>
         </div>
      </section>
      
      
	  
     <?php require('footer.php');?>