<?php include('header.php');?>

<!-- start main -->
<section class="inner-section single-banner">
	<div class="container">
		<h2>checkout</h2>
		<ol class="breadcrumb">
			<li class="breadcrumb-item"><a href="index.php">Home</a></li>
			<li class="breadcrumb-item active" aria-current="page">checkout</li>
		</ol>
	</div>
</section>

    <?php 
        if(isset($_SESSION['pin_code'])){
            $s_pin = $_SESSION['pin_code'];
          
          
   $query11 = $this->db->where('user_id',$_SESSION['customer']['cust_id']);
    $query11 = $this->db->get('tbl_delivery_address');
	if ($query11->num_rows() > 0)  
        {
         
            $datapin=['pin_code'=>$_SESSION['pin_code']] ;
            $this->db->where('user_id',$_SESSION['customer']['cust_id']);
            $this->db->where('status',1);
            $this->db->update('tbl_delivery_address',$datapin);
        
        }  
        }
        else {
            $s_pin = '';
        }
        

        
        $statement2222 = $this->db->query("SELECT * FROM tbl_delivery_address WHERE user_id=? AND status=?",array($_SESSION['customer']['cust_id'],1));
        $result222 = $statement2222->result_array();
        foreach ($result222 as $row222) {
            $_SESSION['SH_address_id'] = $row222['delivery_address_id'];
            $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'];
            // $SH_address = '';
            
            
            $_SESSION['SH_name'] = $SH_name ;
            $_SESSION['SH_phone'] = $SH_phone ;
            $_SESSION['SH_state'] = $SH_state ;
            $_SESSION['SH_district'] = $SH_district;
            $_SESSION['SH_pin_code'] = $SH_pin_code;
            $_SESSION['SH_address'] = $SH_address;
            // print_r($_SESSION);
            
        }
        if(isset($_SESSION['SH_name'])){
            $SH_name = $_SESSION['SH_name'];
            $SH_phone = $_SESSION['SH_phone'];
            $SH_state = $_SESSION['SH_state'];
            $SH_district = $_SESSION['SH_district'];
            $SH_pin_code = $_SESSION['SH_pin_code'];
            $SH_address = $_SESSION['SH_address'];
            
           
            
        }
        else{
            $SH_pin_code = $_SESSION['pin_code'];
        }
        
        
  
 if(isset($_SESSION['SH_address']))   
  {  
    unset($_SESSION['add_sess']);
  }  else {
      $_SESSION['add_sess'] =rand();
  }
        
?>
<section class="inner-section checkout-part">
	<div class="container" id="chekout_true">
		<div class="row" >
               <div class="col-md-8">
                   <div class="account-card" id="upd_addresss">
                            <div class="account-title">
                                <h4>delivery address</h4> 
                                <button data-bs-toggle="modal" data-bs-target="#shipping_address_modal"><?=(!isset($_SESSION['SH_district'])) ? 'add address' : 'Update address';?></button>
                            </div>
                              <div class="account-content">
                                 <!--<p>We need your phone number so that we can update you about your order.</p>-->
                                 <div class="row" >
                                        <div class="col-sm-12 col-12">
                                            <?php if(isset($_SESSION['SH_district'])){ ?>
                                                <div class="profile-card address active">
                                                    <h6><?=$_SESSION['SH_name'].',<br>';?></h6>
                                                    <p><?=$_SESSION['SH_address'].', '.$_SESSION['SH_district'].', '.$_SESSION['SH_state'].', '.$SH_pin_code.' <br>+91 '.$_SESSION['SH_phone'];?></p>
                                                    <!--<ul class="user-action">
                                                        <li><button class="edit icofont-edit" title="Edit This" data-bs-id="<?=$_SESSION['SH_address_id'];?>"  data-bs-toggle="modal" data-bs-target="#address-edit"></button></li>
                                                        <li><button class="trash icofont-ui-delete" title="Remove This" data-bs-dismiss="alert"></button></li>
                                                    </ul>-->
                                                </div>
                                            
                                            <?php } ?>
                                            
                                        </div>
                                    </div>
                              </div>
                           </div>
                    <div class="account-card">
                        <h5 class="account-title">My Cart 
                        <span class="text-secondary float-end">(
                            <span id="cart_quantity4">
                            <?php
                                if(isset($_SESSION['cart_p_id'])) {
                                    echo count($_SESSION['cart_p_id']);
                                } else {echo '0';}
                            ?>
                            </span>
                        item)
                        </span>
                        </h5>
                     <div class="account-content pt-0 pr-0 pl-0 pb-0">
                         
                        
                         <?php
                                
                                        $table_total_price = 0;
                                        $table_total_price_new=0;
                                        $i=0;
                                        if(isset($_SESSION['cart_p_id'])){
                                            foreach($_SESSION['cart_p_id'] as $key => $value)
                                            {
                                            $i++;
                                            $arr_cart_p_id[$i] = $value;
                                            }
                                        
                                        
                                        $i=0;
                                            foreach($_SESSION['cart_size_id'] as $key => $value)
                                            {
                                            $i++;
                                            $arr_cart_size_id[$i] = $value;
                                            }
                                        
                                        $i=0;
                                        foreach($_SESSION['cart_size_name'] as $key => $value)
                                        {
                                        $i++;
                                        $arr_cart_size_name[$i] = $value;
                                        }
                                        $i=0;
                                        foreach($_SESSION['cart_color_id'] as $key => $value)
                                        {
                                        $i++;
                                        $arr_cart_color_id[$i] = $value;
                                        }
                                        $i=0;
                                        foreach($_SESSION['p_pv'] as $key => $value)
                                        {
                                        $i++;
                                        $arr_p_pv[$i] = $value;
                                        }
                                        $i=0;
                                        foreach($_SESSION['cart_color_name'] as $key => $value)
                                        {
                                        $i++;
                                        $arr_cart_color_name[$i] = $value;
                                        }
                                        $i=0;
                                        foreach($_SESSION['cart_p_qty'] as $key => $value)
                                        {
                                        $i++;
                                        $arr_cart_p_qty[$i] = $value;
                                        }
                                        $i=0;
                                        foreach($_SESSION['cart_p_current_price'] as $key => $value)
                                        {
                                        $i++;
                                        $arr_cart_p_current_price[$i] = $value;
                                        }
                                        
                                        
                                        $i=0;
                                        foreach($_SESSION['cart_p_old_price'] as $key => $value)
                                        {
                                        $i++;
                                        $arr_cart_p_old_price[$i] = $value;
                                        }
                                        
                                        
                                        $i=0;
                                        foreach($_SESSION['cart_p_name'] as $key => $value)
                                        {
                                        $i++;
                                        $arr_cart_p_name[$i] = $value;
                                        }
                                        $i=0;
                                        foreach($_SESSION['cart_p_featured_photo'] as $key => $value)
                                        {
                                        $i++;
                                        $arr_cart_p_featured_photo[$i] = $value;
                                        }
                                        }
                                        ?>
                                        <?php 
                                        if(isset($arr_cart_p_id)) {
                                        for($i=1;$i<=count($arr_cart_p_id);$i++){
                                            $c_pid = $arr_cart_p_id[$i];
                                            $c_sizeid = $arr_cart_size_id[$i];
                                            $c_sizename = $arr_cart_size_name[$i];
                                            $c_colorid = $arr_cart_color_id[$i];
                                            $c_p_pv = $arr_p_pv[$i];
                                            $c_colorname = $arr_cart_color_name[$i];
                                            $c_pname = $arr_cart_p_name[$i];
                                            $c_photo = $arr_cart_p_featured_photo[$i];
                                            $c_op = $arr_cart_p_old_price[$i];
                                            $c_cp = $arr_cart_p_current_price[$i];
                                            $c_qty = $arr_cart_p_qty[$i];
                                        ?>
                                            <input type="hidden" id="s1_<?=$i;?>" value="<?=$c_pid; ?>">
                                            <input type="hidden" id="s2_<?=$i;?>" value="<?=$c_sizeid; ?>">
                                            <input type="hidden" id="s3_<?=$i;?>" value="<?=$c_colorid; ?>">
                                            <input type="hidden" id="as1_<?=$c_pid;?>" value="<?=$c_pid; ?>">
                                            <input type="hidden" id="as2_<?=$c_pid;?>" value="<?=$c_sizeid; ?>">
                                            <input type="hidden" id="as3_<?=$c_pid;?>" value="<?=$c_colorid; ?>">
                                            <input type="hidden" id="pid_<?=$i;?>" name="product_id[]" value="<?=$c_pid; ?>">
                                            <input type="hidden" id="pname_<?=$i;?>" name="product_name[]" value="<?=$c_pname; ?>">
                                            
            <div class="cart-list-product" id="cartdel_<?=$c_pid; ?><?=$c_sizeid; ?>">
                <div class="row">
                   <div class="col-4"><img class="img-fluid" src="<?=base_url('uploads/shop/product/'.$c_photo); ?>" alt="<?=$c_pname; ?>"></div>
                   <div class="col-8">
                       
                   
               <!--<span class="badge badge-success">50% OFF</span>-->
                <a class="float-end text-danger" href="javascript: void(0);" 
                    onclick="return removeItem('<?=$c_pid; ?>','<?=$c_pid; ?><?=$c_sizeid; ?><?=$c_colorid; ?>','<?=$c_sizeid; ?>');">
                    <i class="fa fa-window-close"></i>
                </a>
               <h5><a href="#"><?=$c_pname; ?></a></h5>
               <h6>
                   <strong><span class="fa fa-approval"></span> Available in</strong>
                   - <span><?=$c_sizename; ?></span>
                   <span class="badge" style="background: <?=$c_colorname; ?>;"><?=$c_colorname; ?></span>
                </h6>
               <p class="offer-price mb-0">
                    <span><?='&#8377;'.number_format($c_cp*$c_qty,2); ?> <b class="pv">(<?=number_format($c_p_pv*$c_qty,0);?> PV)</b></span>
                    <del class="text-black-50 font-weight-normal"><?='&#8377;'.number_format($c_op*$c_qty,2); ?></del>
                    <br>
                    <span class="text-success font-italic">You save <?php
                    
                    $m =  $c_op*$c_qty;
                    $n = $c_cp*$c_qty;
                    $o =  $m-$n;
                    echo '&#8377;';
                    echo number_format($o,2);
                    
                    // calculate total amount
                    $row_total_price = $m;
                    if(isset($table_total_price)){
                        $table_total_price = $table_total_price + $row_total_price;
                        $table_total_price_new = $table_total_price_new + $n;
                    }
                    else{
                        $table_total_price=$row_total_price;
                        $table_total_price_new = $n;
                    }
                    
                    if(isset($pvtotal)){
                    $pvtotal += $c_p_pv*$c_qty;
                    }
                    else{
                        $pvtotal = $c_p_pv*$c_qty;
                    }
                            
                            
                    ?></span>
                    <br>
                    <span class="text-black-50 font-weight-normal">
                        QTY : <?=$c_qty;?>
                    </span>                             
               </p>
               </div>
               </div>
            </div>
            <?php }
                                        }
                                        else
                                        {
                                            ?>
                                            <div class="col-md-12 text-center">
                                                <img src="<?=base_url('uploads/empty-cart.png');?>" class="img-fluid" />
                                            </div>
                                            <?php
                                        }
            ?>
    
                     </div>
                     <div 
                  </div>
               </div>
            </div>
                </div>
            
               <div class="col-md-4">
                  <div class="account-card">
                     <h5 class="account-title">Payment Details</h5>
                     <div class="account-content pt-0 pr-0 pl-0 pb-0">
                         
                         
                        <?php
                            $statement4 = $this->db->query("SELECT * FROM tbl_shipping_cost_all WHERE status=? AND  min_amt <= ? AND max_amt >= ?",array(1,$table_total_price,$table_total_price));
                            if(count($statement4->result_array())){
                            $result4 = $statement4->result_array();
                            foreach ($result4 as $row4) {
                                $shipping_cost = $row4['amount'];
                            }
                        
                         
                         
                                $final_total = $table_total_price_new+$shipping_cost;
                            }
                            else{
                                $final_total=$table_total_price_new;
                                $shipping_cost=0;
                            }
                        
                        
                                ?>
         
         <div class="cart-sidebar-footer">
             <div class="row"  id="audate_pincode">
                 <div class="col-sm-12">
            <div class="cart-store-details">
                
			
            <div class="form-group">
                <label class="mb-2">Do you have a coupon code?</label>
                <div id="message_c"></div>
                
                
                
                <div class="coupon-form d-flex">
                    <input type="text" placeholder="Enter your coupon code" id="enter_coupon_code" autocomplete="off">
                    
                    
                    <?php 
                       if(!isset($_SESSION['SH_address_id'])){
                            
                        ?>
                         <button onclick="sweetalert ('warning','Please Enter Delivery Address');return false;" data-bs-toggle="modal" data-bs-target="#shipping_address_modal" type="submit" ><span>apply</span></button>
                        <?php 
                        }

                        elseif(!empty($SH_pin_code)){
                            if(!empty(count($_SESSION['cart_p_id']))){ $alert = 'return true;'; }else{ $alert = "sweetalert('warning','<b>Cart is Empty.</b><br><br> Please Add Some Product to Proceed.'); return false;"; }
                        ?>
                        
                      <button type="submit" onclick="getCoupon()"><span>apply</span></button>
                      <?php 
                            
                        }
                        else{
                            
                        ?>
                         
                        <button onclick="sweetalert ('warning','Please Enter Delivery Pincode');return false;"  data-bs-toggle="modal" data-bs-target="#pin_modal" type="submit" ><span>apply</span></button>
                        <?php 
                        }
                        ?> 
                    
                    
                    
                    
                </div>
                
                
                 <div class="coupon-form d-flex d-none" id="votp">
                    <input type="text" placeholder="Enter your coupon OTP" id="enter_coupon_otp" autocomplete="off">
                    <button type="submit" onclick="verifyotp()"><span>Verify</span></button>
                </div>
            </div>
                
                <p>MRP Total - <strong class="float-end"><?=LANG_VALUE_1; ?> <?=number_format($table_total_price,2); ?></strong></p>
                <p>Discount - <strong class="float-end"><?=LANG_VALUE_1; ?> <?=$save = number_format($table_total_price-$table_total_price_new,2); ?></strong></p>
                <p>Sub Total - <strong class="float-end"><?=LANG_VALUE_1; ?> <?=number_format($table_total_price_new,2); ?></strong></p>
                
                <p>Shipping cost - <strong class="float-end"><?php if($shipping_cost==0){ echo 'FREE';}else{ echo LANG_VALUE_1.number_format($shipping_cost,2);} ?></strong></p>
                <p>Coupon Discount - 
                    <strong class="float-end"  id="discount_c">
                    <?php 
                        if(isset($_SESSION['discount_percentage'])){
                            echo LANG_VALUE_1;
                            if($_SESSION['discount_type']==1)
                            {
                            echo $ff = $_SESSION['discount_percentage'];
                            }
                            else
                            {
                                 echo $ff = ($table_total_price_new/100)*$_SESSION['discount_percentage'];
                            }
                            $gg =  $final_total-$ff-$save;
                            $ggs =  $final_total-$ff-$save;
                            $save = $save+$ff;
                        }
                        else
                        {
                            $gg=$final_total;
                            $ggs =  $final_total;
                            echo LANG_VALUE_1.'0.00';
                        } 
                        
                        if(isset($pvtotal)){
                            $save = $save+$pvtotal;
                            $gg = $gg-$pvtotal;
                            $ggs = $ggs-$pvtotal;
                        }
                    ?>
                    </strong>
                    <input type="hidden" id="final_total_c" value="<?=$table_total_price_new;?>">
                    <input type="hidden" id="shipping_cost" value="<?=$shipping_cost;?>">
                    <input type="hidden" id="total_pv_c" value="<?=$pvtotal;?>">
                </p>
                <p>Self Benefit - <strong class="float-end" id="to_pv"><?=$pvtotal; ?></strong></p>
                <p>Total Amount - <strong class="float-end" id="to_pay"><?=LANG_VALUE_1.number_format($gg,2);$gg = number_format($gg,2); ?></strong></p>
                <p><strong class="float-end text-success" id="you_save">You Save <?=LANG_VALUE_1.$save; ?></strong></p>
                <input type="hidden" id="you_save1" value="<?=$save;?>">
            </div>
            </div>
            
           
           <div class="col-sm-12">
               <hr>
                <form action="<?=base_url('Cash_on_delivery');?>" method="post" >
                
                        <input type="hidden" name="coupon_id" id="coupon_id" value="<?php if(isset($coupon_id)){echo $coupon_id; }?>">
                        <input type="hidden" name="coupon_discount" id="coupon_discount" value="<?php if(isset($ff)){echo $ff; }?>">
                        <input type="hidden" name="amount" id="amount" value="<?php if(isset($gg)){echo $gg; }?>">
                        <input type="hidden" name="shipping_address" id="shipping_address" value="<?php if(isset($_SESSION['SH_address_id'])){echo $_SESSION['SH_address_id']; }?>">
                         <input type='hidden' value='<?=$pvtotal; ?>' name='tpv' >
                        
                        <input type="hidden" name="transaction_info" class="form-control" value="This Booking By COD. At <?=date('d M Y h:i:s A').". "; if(isset($c)){echo $c; }?> ">
                        <?php 
                                                if(!isset($_SESSION['SH_address_id'])){
                            
                        ?>
                            <button  onclick="alert('Please Add Delivery Address');return false;"  data-bs-target="#shipping_address_modal" data-bs-toggle="modal"  class="btn bg-theme-color text-white w-100" name="form3">
                                <span class="float-start">
                                    <span class="fa fa-cart-outline"></span> Cash on Delivery  
                                </span>
                                <span class="float-end"><?=LANG_VALUE_1; ?> <b  id="amount2"><?=$gg; ?></b></span>
                            </button>
                        
                        <?php 
                        }

                        elseif(!empty($SH_pin_code)){
                            if(!empty(count($_SESSION['cart_p_id']))){ $alert = 'return true;'; }else{ $alert = "sweetalert('warning','<b>Cart is Empty.</b><br><br> Please Add Some Product to Proceed.'); return false;"; }
                        ?>
                        
                            <button type="submit" class="btn  bg-theme-color text-white w-100" id="final_submit" onclick="<?=$alert;?>" name="form3"><span class="float-start"><span class="fa fa-cart-outline"></span> Cash on Delivery  </span><span class="float-end"><?=LANG_VALUE_1; ?> <b  id="amount2"><?=$gg; ?></b></span></button>
                        
                           
                        
                        <?php 
                            
                        }
                        else{
                            
                        ?>
                            <button id="subpin1"  onclick="alert('Please Enter Delivery Pincode');return false;"  data-bs-target="#pin_modal" data-bs-toggle="modal"  class="btn bg-theme-color text-white w-100" name="form3">
                                <span class="float-start">
                                    <span class="fa fa-cart-outline"></span> Cash on Delivery  
                                </span>
                                <span class="float-end"><?=LANG_VALUE_1; ?> <b  id="amount2"><?=$gg; ?></b></span>
                            </button>
                            
                            
                                  <button id="subpin" style="display:none;" type="submit" class="btn  bg-theme-color text-white w-100" id="final_submit" onclick="<?=$alert;?>" name="form3"><span class="float-start"><span class="fa fa-cart-outline"></span> Cash on Delivery  </span><span class="float-end"><?=LANG_VALUE_1; ?> <b  id="amount2"><?=$gg; ?></b></span></button>
                       
                        
                        <?php 
                        }
                        ?>
                </form>
                
                
                <hr>
                
                 <form action="<?=base_url('Cash_on_deliverys/pgRedirect');?>" method="post" >
                
                        <input type="hidden" name="coupon_id" id="coupon_id1" value="<?php if(isset($coupon_id)){echo $coupon_id; }?>">
                        <input type="hidden" name="coupon_discount" id="coupon_discount1" value="<?php if(isset($ff)){echo $ff; }?>">
                        <input type="hidden" name="otp_verify" id="otp_verify" value="">
                        
                        <input type="hidden" name="discount_type" id="discount_type" value="<?php if(isset($_SESSION['discount_type'])){echo $_SESSION['discount_type']; }?>">
                        
                        <input type="hidden" name="TXN_AMOUNT" id="amount1" value="<?php if(isset($ggs)){echo $ggs; }?>">
                        <input type="hidden" name="shipping_address" id="shipping_address1" value="<?php if(isset($_SESSION['SH_address_id'])){echo $_SESSION['SH_address_id']; }?>">
                        
                        
                        
                        <input type='hidden' value='<?=$pvtotal; ?>' name='tpv' >
                        <input type="hidden" name="transaction_info" class="form-control" value="This Booking By COD. At <?=date('d M Y h:i:s A').". "; if(isset($c)){echo $c; }?> ">
                        
                      
                        
                        
                        
                <input type="hidden" id="CUST_ID"  class="form-control"  name="CUST_ID" value="<?php echo $_SESSION['customer']['cust_id'];?>">
                <input type="hidden" id="INDUSTRY_TYPE_ID"  name="INDUSTRY_TYPE_ID"  value="Retail">
                <input type="hidden" id="CHANNEL_ID" name="CHANNEL_ID"  value="WEB">
                <input  type="hidden" readonly id="ORDER_ID" tabindex="1" maxlength="20" size="20" name="ORDER_ID" class="form-control" autocomplete="off" value="<?php echo "ORDS" . rand(10000, 99999999) ?>">
           
                        
                        <?php 
                                                if(!isset($_SESSION['SH_address_id'])){
                            
                        ?>
                            <button  onclick="alert('Please Add Delivery Address');return false;"  data-bs-target="#shipping_address_modal" data-bs-toggle="modal"  class="btn bg-theme-color text-white w-100" name="form3">
                                <span class="float-start">
                                    <span class="fa fa-cart-outline"></span> Pay Online  
                                </span>
                                <span class="float-end"><?=LANG_VALUE_1; ?> <b  id="amount21"><?=$gg; ?></b></span>
                            </button>
                        
                        <?php 
                        }

                        elseif(!empty($SH_pin_code)){
                            if(!empty(count($_SESSION['cart_p_id']))){ $alert = 'return true;'; }else{ $alert = "sweetalert('warning','<b>Cart is Empty.</b><br><br> Please Add Some Product to Proceed.'); return false;"; }
                        ?>
                        
                            <button type="submit" class="btn  bg-theme-color text-white w-100" id="final_submits" onclick="<?=$alert;?>" name="form3"><span class="float-start"><span class="fa fa-cart-outline"></span> Pay Online  </span><span class="float-end"><?=LANG_VALUE_1; ?> <b  id="amount21"><?=$gg; ?></b></span></button>
                        <?php 
                            
                        }
                        else{
                            
                        ?>
                            <button id="subpin1"  onclick="alert('Please Enter Delivery Pincode');return false;"  data-bs-target="#pin_modal" data-bs-toggle="modal"  class="btn bg-theme-color text-white w-100" name="form3">
                                <span class="float-start">
                                    <span class="fa fa-cart-outline"></span> Pay Online  
                                </span>
                                <span class="float-end"><?=LANG_VALUE_1; ?> <b  id="amount2"><?=$gg; ?></b></span>
                            </button>
                            
                            
                                  <button id="subpin" style="display:none;" type="submit" class="btn  bg-theme-color text-white w-100" id="final_submits" onclick="<?=$alert;?>" name="form3"><span class="float-start"><span class="fa fa-cart-outline"></span> Pay Online  </span><span class="float-end"><?=LANG_VALUE_1; ?> <b  id="amount21"><?=$gg; ?></b></span></button>
                       
                        
                        <?php 
                        }
                        ?>
                </form>
           </div>
       </div>
         </div>
         
                         
                         
                     </div>
                     <div 
                  </div>
               </div>
            </div>
         </div>
         </div>
         </div>
      </section>
    
    
    <script>
        	
    </script> 
    <?php if(isset($_SESSION['add_sess'])) { ?>
    <div class="modal fade show" id="shipping_address_modal" style="display: block;">
        <div class="backdrop"></div>
        <?php } else {?>
        <div class="modal fade" id="shipping_address_modal"> 
       <?php } ?>
       
       
       
        <div class="modal-dialog modal-dialog-centered modal-md">
            <div class="modal-content"><button class="modal-close" data-bs-dismiss="modal"><i class="icofont-close"></i></button>
	          <form   action="<?=base_url('checkout/saveaddress');?>" method="post" class="modal-form">
                    <div class="form-title">
                        <h3><?=(!isset($_SESSION['SH_district'])) ? 'add address' : 'Update address';?></h3>
                    </div>
                        <div class="row">
                           <div class="col-12">
                              <div class="form-group">
                                 <label class="form-label">Name <span class="required">*</span></label>
                                 <input name="SH_name" id="SH_name" class="form-control border-form-control" required value="<?php if(isset($SH_name)){ echo $SH_name;}else{ echo $_SESSION['customer']['cust_name'];} ?>" placeholder="Gurdeep" type="text">
                              </div>
                           </div>
                           <div class="col-sm-6 col-12">
                              <div class="form-group">
                                 <label class="form-label">Phone <span class="required">*</span></label>
                                 <div class="input-group input-group-sm">
                                    <span class="input-group-text">+91</span>
                                    <input name="SH_phone" id="SH_phone" class="form-control border-form-control" required value="<?php if(isset($SH_phone)){ echo $SH_phone;}else{ echo $_SESSION['customer']['cust_phone'];} ?>" placeholder="0123456789" type="tel" onkeypress="return isNumberKey(event)">
                                 </div>
                              </div>
                           </div>
                           
                           
                           <div class="col-sm-6 col-12">
                              <div class="form-group">
                                 <label class="form-label">Zip Code <span class="required">*</span></label>
                                  <input name="SH_pin_code" id="SH_pin_code" class="form-control" required value="<?=$SH_pin_code; ?>" readonly onkeypress="return isNumberKey(event)" onclick="$('#pin_modal').modal('toggle');$('#shipping_address_modal').modal('toggle');$('#shipping_address_modal').modal('toggle');" placeholder="Pin Code" type="tel">
                              </div>
                           </div>
                        
						   <div class="col-sm-6 col-12">
                              <div class="form-group">
                                 <label class="form-label">State <span class="required">*</span></label>
                                        <select onchange="getdt()" required id="statef" name="SH_state" class="form-control border-form-control" style="width: 100%;">
                                            <option value="">Select State</option>
                                               <?php  
                                               $mstt='';
                                                    $statement9 = $this->db->query("SELECT * FROM tbl_state");
                                                    $result9 = $statement9->result_array();                            
                                                    foreach ($result9 as $row) {
                                                        if(!empty($SH_state)){
                                                           
                                                      ?>
                                                        
                                                      <option value="<?=$row['state']; ?>" <?php if($row['state'] == $SH_state) {  $mstt = $row['id']; echo 'selected';} ?>><?=$row['state']; ?></option>   
                                                       
                                                    <?php 
                                                        }
                                                        else
                                                        {
                                                            $mstt =  $_SESSION['customer']['cust_state'];
                                                            ?>
                                                            <option value="<?=$row['state']; ?>" <?php if($row['state'] == $_SESSION['customer']['cust_state']) { $mstt = $row['id']; echo 'selected';} ?>><?=$row['state']; ?></option>   
                                                       
                                                            <?php
                                                        }
                                                        }
                                                    ?>
                                        </select>
                        
                        
                                 
                              </div>
                           </div>
                           
                            <div class="col-sm-6 col-12">
                              <div class="form-group">
                                 <label class="form-label">District <span class="required">*</span></label>
                                    <select name="SH_district" required id="SH_district" class="form-control border-form-control" style="width: 100%;">
                                        <option value="">Select District</option>
                                        <?php  
                                        if(isset($mstt) && !empty($mstt)){
                                                    $statement91 = $this->db->query("SELECT * FROM tbl_district WHERE state=$mstt");
                                                    $result91 = $statement91->result_array();                            
                                                    foreach ($result91 as $row) {
                                                        if(!empty($SH_district)){
                                                      ?>
                                                        
                                                      <option value="<?=$row['district']; ?>" <?php if($row['district'] == $SH_district) {echo 'selected';} ?>><?=$row['district']; ?></option>   
                                                       
                                                    <?php 
                                                        }
                                                        else
                                                        {
                                                            ?>
                                                            <option value="<?=$row['district']; ?>" <?php if($row['district'] == $_SESSION['customer']['cust_district']) {echo 'selected';} ?>><?=$row['district']; ?></option>   
                                                       
                                                            <?php
                                                        }
                                                        }
                                        }
                                                    ?>
                                    </select> 
                              </div>
                           </div>
                        
                         
                        
                           <div class=" col-12">
                              <div class="form-group">
                                 <label class="form-label">Shipping Address <span class="required">*</span></label>
                                 <textarea name="SH_address" id="SH_address" required class="form-control"><?php if(isset($SH_address)){ echo $SH_address;}else{ echo $_SESSION['customer']['cust_address'];} ?></textarea>
							</div>
							</div>
                           <div class="col-12"> 
                         <!--  <button class="modal-close" data-bs-dismiss="modal"><i class="icofont-close"></i></button>-->
                          
                           </div>
                        </div>
                         <button class="form-btn" type="submit"  value="Save Address Info">Save Address Info</button>
                   </form>
                    <!--<button class="form-btn" onclick="saveaddress()" data-bs-dismiss="modal" value="Save Address Info">Save Address Info</button>-->
            </div>
        </div>
    </div>
     
      <!-- Footer -->
<?php include('footer.php');?>
    <script>
   
        //  $('#shipping_address_modal').modal('toggle');
     

    </script>
<script>
    function saveaddress()
    {
        SH_name=$("#SH_name").val();
        SH_phone=$("#SH_phone").val();
        SH_state=$("#statef").val();
        SH_district=$("#SH_district").val();
        SH_pin_code=$("#SH_pin_code").val();
        SH_address=$("#SH_address").val();

          $.ajax({
                url:"<?=base_url('checkout/saveaddress');?>",
                type:"POST",
                data:{SH_name: SH_name,SH_phone:SH_phone,SH_state:SH_state,SH_district:SH_district,SH_pin_code:SH_pin_code,SH_address:SH_address},
                // dataType: 'json',
                success:function(data)
                    {
                   $("#upd_addresss").load(location.href + " #upd_addresss");   
                     //$("#audate_pincode").load(location.href + " #audate_pincode"); 
                   
                }
            });
    }
</script>



<script>
    function verifyotp()
    {
        otp=$("#enter_coupon_otp").val();
        
          $.ajax({
                url:"<?=base_url('Functions/coupon_otp');?>",
                type:"POST",
                data:{otp: otp},
                // dataType: 'json',
                success:function(data)
                    {
                        console.log(data);
                        var obj = JSON.parse(data);
                        
                        $('#otp_verify').val(obj.succ);
                        if(obj.succ == 1){
                        sweetalert('success','OTP Verified Successfully.');   
                        
                         $("#final_submit").attr('disabled',false);
            $("#final_submits").attr('disabled',false);
                            
                        }
                        else
                        {
                             sweetalert('warning','Invalid OTP.');   
                        }
                       
                }
            });
    }
</script>
 <script>
        // <!--apply coupon script-->
        function getCoupon(){
            // alert();
            
            
            $("#final_submit").attr('disabled',true);
            $("#final_submits").attr('disabled',true);
            
          
          
            
            
            var cartitem = get_cart_item();
                if(cartitem > 0){
                    // return true;
                }
                else{
                    sweetalert('warning','Cart is Empty. Please Add Some Item To Proceed.');
                    return false;
                }
                
        var coupon = $("#enter_coupon_code").val();
        var final_total = $("#final_total_c").val();
        // alert(final_total);
        if(coupon){
            $.ajax({
                url:"<?=base_url('Functions/coupon');?>",
                type:"POST",
                data:{coupon: coupon,final_total: final_total},
                // dataType: 'json',
                success:function(data)
                    {
                        console.log(data);
                        var obj = JSON.parse(data);
                        if(obj.succ == 1){
                            sweetalert('success','Coupon Aplied Successfully. '+ obj.message);
                            var final_total = $("#final_total_c").val();
                            $("#discount_type").val(obj.type);
                             if(obj.type == 1){
                            var discount_c = parseFloat(obj.discount_percentage);
                            $("#votp").removeClass('d-none');
                             }
                             else
                             {
                                var discount_c = parseFloat(final_total/100)*parseFloat(obj.discount_percentage);  
                             }
                            var discount_c2 = discount_c;
                            var shipping_cost = $("#shipping_cost").val();
                            var total_pv_c = $("#total_pv_c").val();
                            
                            var to_pay = parseFloat(final_total)-parseFloat(discount_c)+parseFloat(shipping_cost)-parseFloat(total_pv_c);
                            var to_pay = to_pay.toFixed(2);
                            var discount_c = discount_c.toFixed(2);
                            $("#discount_c").html('&#8377; '+ discount_c);
                            $("#coupon_discount2").val(discount_c);
                            $("#coupon_id2").val(obj.coupon_id);
                            $("#coupon_discount").val(discount_c);
                            $("#coupon_discount1").val(discount_c);
                            $("#coupon_id").val(obj.coupon_id);
                            $("#coupon_id1").val(obj.coupon_id);
                            
                            
                            $("#to_pay").html('&#8377; '+ to_pay);
                            $("#amount").val(to_pay);
                            $("#amount1").val(to_pay);
                            $("#amount2").html(to_pay);
                            $("#amount21").html(to_pay);
                            var you_save = parseFloat($("#you_save1").val());
                            var vvv = you_save+discount_c2;
                            var vvv = vvv.toFixed(2);
                            $("#you_save").html('You Save &#8377;' + vvv);
                            $("#amount3").val(to_pay);
                            $("#amount4").html(to_pay);
                            // $("#success").fadeOut(3500);
                            
                        }
                        if(obj.error == 1){
                            sweetalert('warning','Invalid, Expired or Used Coupon.');
                            $("#discount_c").html('&#8377;0.00');
                            var final_total = parseFloat($("#final_total_c").val());
                            var shipping_cost = parseFloat($("#shipping_cost").val());
                            var total_pv_c = parseFloat($("#total_pv_c").val());
                            var final_total =  final_total+shipping_cost-total_pv_c;
                            $("#to_pay").html('&#8377; '+final_total.toFixed(2));4
                            
                            
                            $("#coupon_discount2").val('0.00');
                            $("#coupon_id2").val('');
                            $("#coupon_discount").val('0.00');
                            $("#coupon_discount1").val('0.00');
                            $("#coupon_id").val('');
                            $("#coupon_id1").val('');
                            
                            var you_save = parseFloat($("#you_save1").val());
                            var vvv = you_save;
                            $("#you_save").html('You Save &#8377;' + vvv);
                            
                            $("#amount").val(final_total.toFixed(2));
                            $("#amount1").val(final_total.toFixed(2));
                            $("#amount2").html(final_total.toFixed(2));
                            $("#amount21").html(final_total.toFixed(2));
                            $("#amount3").val(final_total.toFixed(2));
                            $("#amount4").html(final_total.toFixed(2));
                            // $("#error").fadeOut(3500);
                            
                        }
                }
            });
        }
        
        }
        // <!--apply coupon script end-->
     </script>
    <script>  
    function getdt(){
        var dt=$("#statef").val();
        $.ajax({
            url:"<?=base_url('get/district');?>",
            type:"POST",
            data:{dt:dt},
            // dataType: 'json',
            success:function(data)
            {
                $("#SH_district").html(data);
            }
        });
    }      
    </script> 
    <script>
        $(document).ready(function(){
            $("#final_submit").click(function(){
                var cartitem = get_cart_item();
                if(cartitem > 0){
                    return true;
                }
                sweetalert('warning','Cart is Empty. Please Add Some Item To Proceed.');
                return false;
            });
            
            $("#final_submits").click(function(){
                var cartitem = get_cart_item();
                if(cartitem > 0){
                    return true;
                }
                sweetalert('warning','Cart is Empty. Please Add Some Item To Proceed.');
                return false;
            });
        })
    </script>
