<?php require('header.php');
if(isset($_SESSION['payment_id']) && !empty($_SESSION['payment_id'])){ ?>
<section class="inner-section single-banner">
	<div class="container">
		<h2>Order Complete</h2>
		<ol class="breadcrumb">
			<li class="breadcrumb-item"><a href="<?=base_url();?>">Home</a></li>
			<li class="breadcrumb-item active" aria-current="page">Order Complete</li>
		</ol>
	</div>
</section>

    <section class="class="inner-section invoice-part"">
         <div class="container">
            <div class="row">
               <div class="col-sm-12">
                        <div class="account-card">
                           <div class="account-title">
                              <h4 class="mb-0">order recieved</h4>
                           </div>
                           <div class="account-content">
                                 <div class="text-center">
                                    <div class="col-lg-12 col-md-12 mx-auto order-done">
                                       <i class="fa fa-5x fa-check-circle text-success"></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 = $this->db->query("SELECT * FROM applied_delivery_address WHERE payment_id = ?",array($_SESSION['payment_id']));
                        $result222 = $statement2222->result_array();
                        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 = $this->db->query("SELECT * FROM applied_coupon WHERE payment_id = ?",array($_SESSION['payment_id']));
                        $result222 = $statement2222->result_array();
                        foreach ($result222 as $row222) {
                            $coupon_id = $row222['coupon_id'];
                        }
                        
                        // select coupon details for this order
                        $statement2222 = $this->db->query("SELECT * FROM tbl_coupon WHERE coupon_id = ?",array($coupon_id));
                        $result222 = $statement2222->result_array();
                        foreach ($result222 as $row222) {
                            $percentage = $row222['percentage'];
                        }
                    ?>
                <div class="col-12"><br></div>
               <div class="col-sm-6 col-12">
                        <div class="account-card">
                           <div class="account-title">
                              <h4>Delivery Address</h4>
                           </div>
                           <div class="account-content">
                                 <div class="text-left">
                                    <div class="col-lg-12 col-md-12 mx-auto order-done">
                                        <div class="profile-card address active">
                                            <h6><?=$SH_name.',<br>';?></h6>
                                            <p><?=$SH_address.', '.$SH_district.', '.$SH_state.', '.$SH_pin_code.' <br>+91 '.$SH_phone;?></p>
                                        </div>
                                    </div>
                                 </div>
                              </div>
                        </div>
                    </div>
                     <?php
                        $shipping_cost = $percentage = $total = $total1 = $total2 = $total21 = 0;
                        $statement1 = $this->db->query("SELECT * FROM tbl_order WHERE payment_id=?",array($_SESSION['payment_id']));
                        $result1 = $statement1->result_array();
                        foreach ($result1 as $row1) {
                            $total=($row1['unit_price'])*($row1['quantity']);
                            $total1+=$total;
                            $total2=($row1['mrp_price'])*($row1['quantity']);
                            $total21+=$total2;
                        }
                        if(isset($percentage)){
                        $cp = ($total1/100)*$percentage;
                        }
                        else
                        {
                            $cp=0.00;
                        }
                        $shipping_cost=0;
                        $statement1 = $this->db->query("SELECT * FROM applied_shipping_cost WHERE payment_id=?",array($_SESSION['payment_id']));
                        $result1 = $statement1->result_array();
                        foreach ($result1 as $row1) {
                            $shipping_cost = $row1['shipping_cost'];
                            
                        }
                        if(empty($shipping_cost)){
                        $shipping_cost="FREE";
                        }
                    ?>
                    <div class="col-sm-6 col-12">
                        <div class="account-card">
                           <div class="account-title">
                              <h4>Payment Details</h4>
                           </div>
                           <div class="account-content">
                                 <div class="text-left">
                                    <div class="col-lg-12 col-md-12 mx-auto order-done">
                                      <p>MRP Total <strong class="float-end"><?=LANG_VALUE_1.' '.number_format($total21,2);?></strong></p>
                                      <p>Discount <strong class="float-end"><?=LANG_VALUE_1.' '.number_format($total21-$total1,2);?></strong></p>
                                      <p>Sub Total <strong class="float-end"><?=LANG_VALUE_1.' '.number_format($total1,2);?></strong></p>
                                      <p>Shopping Cost <strong class="float-end"><?=$shipping_cost;?></strong></p>
                                      <p>Coupon Discount <strong class="float-end"><?=LANG_VALUE_1.' '.number_format($cp,2);?></strong></p>
                                      <p><b>Total Amount</b> <strong class="float-end"><?=LANG_VALUE_1.' '.number_format($total1-$cp+$shipping_cost,2);?></strong></p>
                                      <p class="pb-4"> <strong class="text-success float-end">You Save <?=LANG_VALUE_1.' '.number_format($total21-$total1,2);?></strong></p>
                                    </div>
                                 </div>
                              </div>
                        </div>
                    </div>
                    <div class="col-12"><br></div>
                </div>
            <div class="row">
                <div class="col-sm-12 col-12 text-center mt-2">
                    <a class="btn btn-inline" href="<?=base_url('orderlist');?>"><span>Go to Order List</span></a>
                    <a class="btn" href="<?=base_url();?>"><span>Return to store</span></a>
                </div>
                <div class="col-12"><br></div>
                <div class="col-12"><br></div>
            </div>
         </div>
    </section>
    
      <!-- Footer -->
<?php require('footer.php'); }else{ header('location: index.php');  } ?>