<?php
$this->load->view("top");
$values_posted_back = (is_array($this->input->post())) ? TRUE : FALSE;
$is_same = $values_posted_back === TRUE ? $this->input->post('is_same') : '';
$titleArray = $this->config->item('titleArray');
$discount_amount = $this->session->userdata('discount_amount');
$cart = $this->cart->contents();
$posted_data = $this->session->userdata('posted_data');
foreach ($cart as $items) {
  $url = $this->db->query("SELECT friendly_url,category_id FROM wps_products WHERE products_id = '" . $items['pid'] . "'")->row_array();
}
$catid = $url['category_id'];
// trace($url);
?>
<div class="page_breadcrumbs">
    <div class="container">
      <ul>
        <li><a href="<?php echo site_url();?>">Home</a></li>
          <li><a href="<?php echo base_url();?>cart">Cart</a></li>
        <li>Checkout</li>
      </ul>
    </div>
  </div>

<section class="checkout_page">
    <div class="container">
      <div class="row">
        <div class="col-xxl-9 col-xl-9 col-lg-9 col-md-9 col-sm-12 col-12">
          <div class="cart_left">
         <h1 class="bg-title">Checkout</h1>
            <div class="panel-group checkout-steps" id="accordion">
              <!-- checkout-step-1  -->
              <div class="panel panel-default checkout-step-01">
<h4 class="checkout_title"><a data-toggle="collapse" class="collapsed complate_bg" data-parent="#accordion"><span>1</span>Login or Signup <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="pull-right" viewBox="0 0 16 16"><path d="M14 1a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h12zM2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2z"/><path d="M10.97 4.97a.75.75 0 0 1 1.071 1.05l-3.992 4.99a.75.75 0 0 1-1.08.02L4.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093 3.473-4.425a.235.235 0 0 1 .02-.022z"/></svg></a></h4>
</div>

<div class="panel panel-default checkout-step-02">
<h4 class="checkout_title">
  <a data-toggle="collapse" data-bs-parent="#accordion" href="javascript:void();"><span>2</span>Delivery Address</a></h4>
  <div id="collapseOne" class="panel-collapse collapse in active show">
    <div class="panel-body">
     <?php
                    echo form_open('cart/delivery_info', 'id="deliveryForm"');
                    echo error_message();
                    echo validation_message();
                    ?>
        <div class="row">
          <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
            <h5>Shipping Address</h5>
            <p>We will deliver your order here</p>
            <div class="form-group">
                <label class="input_label info_title">
              <input tabindex="1" type="text" name="ship_name" placeholder="Full Name *" value="<?= ($posted_data['name'] != '') ? $posted_data['name'] : $mres['name']; ?>" class="form_input" required onchange="ChangeBill(this.form);"/>
             </label>
             </div>

            <div class="form-group">
                 <label class="input_label info_title">
              <input tabindex="2" type="tel" maxlength="10" minlength="10" name="ship_mobile" placeholder="Phone No *"  value="<?= ($posted_data['mobile'] != '') ? $posted_data['mobile'] : $mres['mobile']; ?>" class="form_input" required onkeypress="return isNumberKey(event)" onchange="ChangeBill(this.form);"  />
              </label>
              
            </div>

            <div class="form-group">
                 <label class="input_label info_title">
              <textarea tabindex="5" name="ship_address" class="form_input unicase-form_input" placeholder="Your Address *" onchange="ChangeBill(this.form);" required><?= ($posted_data['address'] != '') ? $posted_data['address'] : $mres['address']; ?></textarea>
              </label>
              
            </div>   

            <div class="form-group">
                 <label class="input_label info_title">
              <input type="text" name="ship_lmark" value="<?= ($posted_data['landmark'] != '') ? $posted_data['landmark'] : $mres['landmark']; ?>"  class="form_input" placeholder="Landmark *" required onchange="ChangeBill(this.form);"/>
              </label>
            </div>

            <div class="form-group">
                 <label class="input_label info_title">
              <input type="text" name="ship_city" value="<?php echo $mres['city']; ?>" placeholder="City *" class="form_input" required onchange="ChangeBill(this.form);"/>
          </label>
            </div> 

            <div class="form-group">
                 <label class="input_label info_title">
              <input type="text" name="ship_pin" value="<?php echo $mres['zipcode']; ?>" placeholder="Pincode *" class="form_input" required onchange="ChangeBill(this.form);" onkeypress="return isNumberKey(event)"/>
             </label>
            </div>        

            <div class="form-group">
                 <label class="input_label info_title">
              <input type="text" name="ship_state"  value="<?php echo $mres['state']; ?>" placeholder="State *" class="form_input" required onchange="ChangeBill(this.form);"/>
           </label>
            
            </div>        

            <div class="form-group">
                
              <label class="input_label info_title">
              <select name="ship_country" id="ship_country" class="form_input" placeholder="Select Country *" required="" onchange="ChangeBill(this.form);">
                   <?php if($url['category_id']!=2){?>
                    <option value="India">India</option>
                    <?php } else { ?> 
                    <option value="UAE">UAE</option>
                   <option value="Kuwait">Kuwait</option>
                   <option value="Oman">Oman</option>
                   <option value="Bahrain">Bahrain</option>
                   <option value="Saudi Arabia">Saudi Arabia</option>
                   <option value="Brunei">Brunei</option>
                   <option value="United Kingdom">United Kingdom</option>
                   <option value="United States">United States</option>
                   <option value="Australia">Australia</option>
                   <option value="Canada">Canada</option>
                      <?php } ?>
                  </select>
            </label>
               </div>

          </div>

          <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
            <h5>Billing Address</h5>
         <label class="shipping"><input id="check_add" name="check_add" value="1" onclick="Check_Bill_Ship(this.form);" type="checkbox" class="isCheck" checked="checked"> Same as Shipping Address</label>
                <div class="row billingAd">
            <div class="form-group">
                  <label class="input_label info_title">
              <input type="text" name="bil_name" value="<?= ($posted_data['bil_name'] != '') ? $posted_data['bil_name'] : $mres['bil_name']; ?>" class="form_input" placeholder="Full Name"  required/>
             </label>
            </div>

            <div class="form-group">
                  <label class="input_label info_title">
              <input type="tel"  minlength="10" maxlength="10" placeholder="Phone No" name="bil_mobile" value="<?= ($posted_data['bil_mobile'] != '') ? $posted_data['bil_mobile'] : $mres['bil_mobile']; ?>" class="form_input" required onkeypress="return isNumberKey(event)"/>
              </label>
                
            </div>
            <div class="form-group">
                   <label class="input_label info_title">
              <textarea name="bil_address" class="form_input unicase-form_input" placeholder="Address" required><?= ($posted_data['bil_address'] != '') ? $posted_data['bil_address'] : $mres['bil_address']; ?></textarea>
             </label>
            </div>          

            <div class="form-group">
                   <label class="input_label info_title">
              <input type="text" name="bil_lmark"  placeholder="Landmark" value="<?= ($posted_data['bil_landmark'] != '') ? $posted_data['bil_landmark'] : $mres['bil_landmark']; ?>" class="form_input" required />
             </label>
                              
            </div>
            <div class="form-group">
                   <label class="input_label info_title">
              <input type="text" name="bil_city" value="<?php echo $mres['bil_city']; ?>" placeholder="City" class="form_input" required/>
              </label>
            
            </div> 
            <div class="form-group">
                   <label class="input_label info_title">
              <input type="text" name="bil_pin" value="<?php echo $mres['bil_zipcode']; ?>" placeholder="Pincode" class="form_input" required onkeypress="return isNumberKey(event)"/>
             </label>
               </div>

            <div class="form-group">
                   <label class="input_label info_title">
              <input type="text" name="bil_state" value="<?php echo $mres['bil_state']; ?>" placeholder="State" class="form_input" required/>
        </label>
              </div>            
            <div class="form-group"> 
                   <label class="input_label info_title">
                   <select name="bil_country" id="bil_country" class="form_input" placeholder="Select Country *" required="" onchange="ChangeBill(this.form);">
                   <?php if($url['category_id']!=2){?>
                    <option value="India">India</option>
                    <?php } else { ?> 
                    <option value="UAE">UAE</option>
                   <option value="Kuwait">Kuwait</option>
                   <option value="Oman">Oman</option>
                   <option value="Bahrain">Bahrain</option>
                   <option value="Saudi Arabia">Saudi Arabia</option>
                   <option value="Brunei">Brunei</option>
                   <option value="United Kingdom">United Kingdom</option>
                   <option value="United States">United States</option>
                   <option value="Australia">Australia</option>
                   <option value="Canada">Canada</option>
                      <?php } ?>
                  </select>
               </label> 
            </div>
          </div>
          
            </div>

          <div class="clearfix"></div>
<!--
          <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
            <div class="form-group">                
              <button onClick="goBack()" class="checkout_btn" name="Back" >Back</button>
            </div>
          </div>
-->

          <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
            <div class="form-group">
              <button class="checkout_btn pull-right" type="submit">Checkout</button>
            </div>
           
          </div>
        </div>
     <?php echo form_close(); ?>
    </div>
  </div>
</div>


<!--
<div class="panel panel-default checkout-step-03">
  <h4 class="checkout_title">
    <a data-toggle="collapse" class="collapsed" data-parent="#accordion" href="javascript:void();">
      <span>3</span>Order Summary</a></h4>
    </div>
-->
 <div class="panel panel-default checkout-step-04">
              <h4 class="checkout_title">
                <a data-bs-toggle="collapse" class="collapsed" data-parent="#accordion" href="javascript:void();">
                  <span>3</span>Payment Options</a></h4>

            </div>
  
    </div>
  </div>
</div>

<div class="col-xxl-3 col-xl-3 col-lg-3 col-md-3 col-sm-4 col-12">
        <div class="cart_right_title">Cart Details</div>
        <div class="cart_right">
          <table class="table table-totals">
            <tbody>
              <?php
              $totalAmount = $discountAmt = $total_shipping = 0;
              $i = 1;
              foreach ($cart as $items) {
                $link = ($this->session->userdata('user_id') > 0) ? 'href="' . site_url() . 'cart/add_to_wishlist/' . $items['pid'] . '"' : 'href="#" data-toggle="modal" data-target="#log-modal"';
                $pprice = ($items['discount_price'] > 0) ? $items['discount_price'] : $items['product_price'];
                $totalAmount += ($pprice * $items['qty']);
                $discountAmt += $pprice * $items['qty'];
                $url = $this->db->query("SELECT friendly_url FROM wps_products WHERE products_id = '" . $items['pid'] . "'")->row_array();
                $i++;
              }
              ?>
              <tr>
                <td>Sub Total</td>
                <td><?php if($catid==2){ echo display_price($totalAmount);} else { echo display_price_india($totalAmount); } ?></td>
              </tr>
              <?php if ($discount_amount > 0) { ?>
                <tr>
                  <td>Discount Price</td>
                  <td>- <?php if($catid==2){ echo display_price($discount_amount);} else { echo display_price_india($discount_amount); } ?></td>
                </tr>
              <?php } ?>
              <?php $deliveryCharge = 0; //delivery_charge(0, $totalAmount); 
              if($catid==2){ $deliverchargewithsymble = display_price($deliveryCharge);} else {  $deliverchargewithsymble = display_price_india($deliveryCharge); }
              ?>
              <tr>
                <td>Delivery Charges</td>
                <td class="free"><?php echo ($deliveryCharge > 0) ? $deliverchargewithsymble : 'Free'; ?></td>
              </tr>
             <!-- <tr>
                <td>GST(18%)</td>
                <td class="free"><?php
              $gst = gst($totalAmount);
              echo display_price($gst);
              ?></td>
              </tr>-->

            </tbody>
            <tfoot>
              <tr>
                <td>Amount Payable</td>
                <!--<td><?= display_price(($totalAmount - $discount_amount) + $deliveryCharge + $gst); ?></td>-->
                <td><?php if($catid==2){ echo display_price(($totalAmount - $discount_amount) + $deliveryCharge);} else { echo display_price_india(($totalAmount - $discount_amount) + $deliveryCharge); } ?></td>
              </tr>
            </tfoot>

          </table>
          <!-- <a class="order_btn" href="javascript:void()" title="Place Order">Place Order</a> -->
          <p class="safe_info"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M5.338 1.59a61.44 61.44 0 0 0-2.837.856.481.481 0 0 0-.328.39c-.554 4.157.726 7.19 2.253 9.188a10.725 10.725 0 0 0 2.287 2.233c.346.244.652.42.893.533.12.057.218.095.293.118a.55.55 0 0 0 .101.025.615.615 0 0 0 .1-.025c.076-.023.174-.061.294-.118.24-.113.547-.29.893-.533a10.726 10.726 0 0 0 2.287-2.233c1.527-1.997 2.807-5.031 2.253-9.188a.48.48 0 0 0-.328-.39c-.651-.213-1.75-.56-2.837-.855C9.552 1.29 8.531 1.067 8 1.067c-.53 0-1.552.223-2.662.524zM5.072.56C6.157.265 7.31 0 8 0s1.843.265 2.928.56c1.11.3 2.229.655 2.887.87a1.54 1.54 0 0 1 1.044 1.262c.596 4.477-.787 7.795-2.465 9.99a11.775 11.775 0 0 1-2.517 2.453 7.159 7.159 0 0 1-1.048.625c-.28.132-.581.24-.829.24s-.548-.108-.829-.24a7.158 7.158 0 0 1-1.048-.625 11.777 11.777 0 0 1-2.517-2.453C1.928 10.487.545 7.169 1.141 2.692A1.54 1.54 0 0 1 2.185 1.43 62.456 62.456 0 0 1 5.072.56z"/><path d="M10.854 5.146a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708 0l-1.5-1.5a.5.5 0 1 1 .708-.708L7.5 7.793l2.646-2.647a.5.5 0 0 1 .708 0z"/></svg> Safe and Secure Payments. Easy returns. 100% Authentic products.</p>
        </div>
      </div>

  </div>
</div>    
</section>







<?php $this->load->view("bottom"); ?>
<script type="text/javascript">
  function Check_Bill_Ship(chk) {
    console.log(chk.check_add.checked);
    if (chk.check_add.checked == 1) {

      chk.bmtitle.value = chk.mtitle.value;
      chk.bil_name.value = chk.ship_name.value;
      chk.bil_mobile.value = chk.ship_mobile.value;
      chk.bil_address.value = chk.ship_address.value;
      chk.bil_lmark.value = chk.ship_lmark.value;
      chk.bil_city.value = chk.ship_city.value;
      chk.bil_pin.value = chk.ship_pin.value;
      chk.bil_state.value = chk.ship_state.value;
      chk.bil_city.value = chk.ship_city.options[chk.ship_city.selectedIndex].value;
    }
    if (chk.check_add.checked == 0) {
     //chk.bmtitle.value = '';
      chk.bil_name.value = '';
      chk.bil_mobile.value = '';
      chk.bil_address.value = '';
      chk.bil_lmark.value = '';
      chk.bil_city.value = '';
      chk.bil_pin.value = '';
      chk.bil_state.value = '';
      chk.bil_city.value = chk.ship_city.options[0].value;
    }
  }
</script>
<script type="text/javascript">
  $(".billingAd").hide();
  $(".isCheck").click(function () {
    if ($(this).is(":checked")) {
      $(".billingAd").hide();
      $("#img_delivery").show();
    } else {
      $(".billingAd").show();
      $("#img_delivery").hide();
    }
  });
  function ChangeBill(chk) {
    //chk.bmtitle.value = chk.mtitle.value;
    chk.bil_name.value = chk.ship_name.value;
    chk.bil_mobile.value = chk.ship_mobile.value;
    chk.bil_address.value = chk.ship_address.value;
    chk.bil_lmark.value = chk.ship_lmark.value;
    chk.bil_city.value = chk.ship_city.value;
    chk.bil_pin.value = chk.ship_pin.value;
    chk.bil_state.value = chk.ship_state.value;
    chk.bil_country.value = chk.ship_country.options[chk.ship_country.selectedIndex].value;
  }
</script>