<?php require('header.php');
// if(isset($_REQUEST['suc']) && !empty($_SESSION['payment_id'])){
?>
      <section class="pt-3 pb-3 page-info section-padding border-bottom bg-white">
         <div class="container">
            <div class="row">
               <div class="col-md-12">
                  <a href="index.php"><strong><span class="mdi mdi-home"></span> Home</strong></a> <span class="mdi mdi-chevron-right"></span> <a href="#">Order Complete</a>
               </div>
            </div>
         </div>
      </section>
    <section class="checkout-page section-padding">
         <div class="container">
            <div class="row">
               <div class="col-sm-12">
                        <div class="card">
                           <div class="card-header" id="headingThree">
                              <h5 class="mb-0 heading-design-h5">
                                 Order Complete
                                 
                              </h5>
                           </div>
                           <div class="card-body">
                                 <div class="text-center">
                                    <div class="col-lg-10 col-md-10 mx-auto order-done">
                                       <i class="mdi mdi-check-circle-outline text-secondary"></i>
                                       <h4 class="text-success">Congrats! Your Order has been placed..</h4>
                                       <p>
                                           Thank You for shopping with us. W'll send a confirmation when your items ship.
                                       </p>
                                    </div>
                                 </div>
                              </div>
                        </div>
                    </div>
                    
                    <?php 
                        // select Delivery Address for this order
                        $statement2222 = $pdo->prepare("SELECT * FROM applied_delivery_address WHERE payment_id = ?");
                        $statement2222->execute(array($_SESSION['payment_id']));
                        $result222 = $statement2222->fetchAll(PDO::FETCH_ASSOC);
                        foreach ($result222 as $row222) {
                            $SH_name = $row222['name'];
                            $SH_phone = $row222['phone'];
                            $SH_state = $row222['state'];
                            $SH_district = $row222['district'];
                            $SH_pin_code = $row222['pin_code'];
                            $SH_address = $row222['address'];
                        }
                        
                        // select aplied Coupon for this order
                        $statement2222 = $pdo->prepare("SELECT * FROM applied_coupon WHERE payment_id = ?");
                        $statement2222->execute(array($_SESSION['payment_id']));
                        $result222 = $statement2222->fetchAll(PDO::FETCH_ASSOC);
                        foreach ($result222 as $row222) {
                            $coupon_id = $row222['coupon_id'];
                        }
                        
                        // select coupon details for this order
                        $statement2222 = $pdo->prepare("SELECT * FROM tbl_coupon WHERE coupon_id = ?");
                        $statement2222->execute(array($coupon_id));
                        $result222 = $statement2222->fetchAll(PDO::FETCH_ASSOC);
                        foreach ($result222 as $row222) {
                            $percentage = $row222['percentage'];
                        }
                    ?>
                <div class="col-12"><br></div>
               <div class="col-sm-12">
                        <div class="card">
                           <div class="card-header" id="headingThree">
                              <h5 class="mb-0 heading-design-h5">
                                 Delivery Address
                              </h5>
                           </div>
                           <div class="card-body">
                                 <div class="text-left">
                                    <div class="col-lg-10 col-md-10 mx-auto order-done">
                                      <p>
                                           <strong><?php echo $SH_name;?></strong>,<br>
                                           <span>
                                               <?php echo $SH_address;?>,
                                               <?php echo $SH_district;?>,
                                               <?php echo $SH_state;?>
                                               <?php echo $SH_pin_code;?>
                                           </span><br>
                                           <strong><?php echo '+91 '.$SH_phone;?></strong>
                                       </p>
                                    </div>
                                 </div>
                              </div>
                        </div>
                    </div>
                    <div class="col-12"><br></div>
                    <div class="col-12">
                        <div class="text-center">
                           <a href="index.php"><button type="submit" class="btn btn-secondary mb-2 btn-lg">Return to store</button></a> <a href="orderlist.php?suc"><button type="submit" class="btn btn-secondary mb-2 btn-lg">Go to Order List</button></a>
                        </div>
                    </div>
                    <div class="col-12"><br></div>
                    <?php
                        $statement1 = $pdo->prepare("SELECT * FROM tbl_order WHERE payment_id=?");
                        $statement1->execute(array($_SESSION['payment_id']));
                        $result1 = $statement1->fetchAll(PDO::FETCH_ASSOC);
                        foreach ($result1 as $row1) {
                            $total=($row1['unit_price'])*($row1['quantity']);
                            $total1+=$total;
                            $total2=($row1['mrp_price'])*($row1['quantity']);
                            $total21+=$total2;
                        }
                        if($percentage){
                        $cp = ($total1/100)*$percentage;
                        }
                        else
                        {
                            $cp=0.00;
                        }
                        
                        
                        
                        $statement1 = $pdo->prepare("SELECT * FROM applied_shipping_cost WHERE payment_id=?");
                        $statement1->execute(array($_SESSION['payment_id']));
                        $result1 = $statement1->fetchAll(PDO::FETCH_ASSOC);
                        foreach ($result1 as $row1) {
                            $shopping_cost=$row1['shopping_cost'];
                            
                        }
                        if(!$shopping_cost){
                        $shopping_cost="FREE";
                        }
                    ?>
                    <div class="col-sm-12">
                        <div class="card">
                           <div class="card-header" id="headingThree">
                              <h5 class="mb-0 heading-design-h5">
                                    Payment Details
                              </h5>
                           </div>
                           <div class="card-body">
                                 <div class="text-left">
                                    <div class="col-lg-10 col-md-10 mx-auto order-done">
                                      <p>MRP Total <strong class="float-right"><?php echo LANG_VALUE_1.' '.number_format($total21,2);?></strong></p>
                                      <p>Discount <strong class="float-right"><?php echo LANG_VALUE_1.' '.number_format($total21-$total1,2);?></strong></p>
                                      <p>Sub Total <strong class="float-right"><?php echo LANG_VALUE_1.' '.number_format($total1,2);?></strong></p>
                                      <p>Shopping Cost <strong class="float-right"><?php echo $shopping_cost;?></strong></p>
                                      <p>Coupon Discount <strong class="float-right"><?php echo LANG_VALUE_1.' '.number_format($cp,2);?></strong></p>
                                      <p><b>Total Amount</b> <strong class="float-right"><?php echo LANG_VALUE_1.' '.number_format($total1-$cp+$shopping_cost,2);?></strong></p>
                                      <p> <strong class="text-success float-right">You Save <?php echo LANG_VALUE_1.' '.number_format($total21-$total1,2);?></strong></p>
                                    </div>
                                 </div>
                              </div>
                        </div>
                    </div>
                </div>
         </div>
    </section>
    
      <!-- Footer -->
<?php require('footer.php'); 
// }
// else{ header('location: index.php');  }
?>