<?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') : '';
$discount_amount = $this->session->userdata('discount_amount');
$cart = $this->cart->contents();
?>
<section class="banner_category" style="background-image: url('<?php echo theme_url();?>images/listing-banner.jpg');">
    <div class="container">

        <h1 class="banner_title">Checkout</h1>
    </div>
</section>
<div class="page_breadcrumbs">
    <div class="container">
        <ul>
            <li><a href="<?= site_url(); ?>" title="Home">Home</a></li>
            <li>Checkout</li>
        </ul>
    </div>
</div>
<section class="checkout_page">
    <div class="container">
        <div class="row">
            <div class="col-lg-9 col-md-9 col-sm-8  col-xs-12">
                <div class="cart_left">
                    <h1>Checkout</h1>
                    <div class="panel-group checkout-steps" id="accordion">
                        <!-- checkout-step-1  -->
                        <section class="panel panel-default checkout-step-01">
                            <h4 class="checkout_title">
                                <a data-toggle="collapse" data-parent="#accordion" href="javascript:void(0);"><span>1</span>Login or Signup </a>
                            </h4>
                            <div id="collapseOne" class="panel-collapse collapse show">
                                <div class="panel-body">
                                    <div class="row">
                                        <div class="col-md-8 col-sm-8">
                                            <?php
                      // if($this->session->flashdata()){
                      // echo $msg;}
                      echo form_open('cart/checkout', 'class="sending-form"');
                       echo error_message();
                      echo validation_message();
                      echo success_message();
                      //print_r($this->input->post('checkout_type'));
                      ?>

                                            <div class="form-group email">
                                                <input tabindex="2" type="email" name="email" class="form-control" placeholder="Enter Email ID*" value="<?php echo set_value('email'); ?>" required=""> <?php echo form_error('email'); ?>
                                            </div>

                                            <div class="form-group register_box" style="display: none;">
                                                <input tabindex="3" type="text" name="name" class="form-control" placeholder="Enter Your Name*" value="<?php echo set_value('name'); ?>">
                                            </div>
                                            <div class="form-group register_box" style="display: none;">
                                                <input tabindex="4" maxlength="10" minlength="10" type="text" name="mobile_number" class="form-control" placeholder="Enter Your Mobile No.*" value="<?php echo set_value('mobile_number'); ?>">
                                            </div>
                                            <div class="form-group register_box" style="display: none;">
                                                <input tabindex="5" type="password" name="password_register" class="form-control" placeholder="Enter Password*" value="">
                                            </div>

                                            <div class="form-group password_cont" style="display: none;">
                                                <input tabindex="5" type="password" name="password" class="form-control" placeholder="Enter Password*" value="">
                                                <!-- <a href="javascript:void(0);" onclick="window.open('<?php echo base_url('users/forgotten_password'); ?>')" target="_blank" data-toggle="modal" data-target="#forget" class="forgot-password">Forgot Password?</a> -->
                                            </div>
                                            <button type="submit" class="step_login_btn logButton gestButton">Contnue as Guest</button>

                                            <div class="row" style="margin-top:10px;">
                                                <!--
                        <div class="col-sm-4 col-xs-12">
                          <div class="row">
                           <label>
                            <div class="col-md-1">
                              <input name="checkout_type" type="radio" value="Guest" class="" checked="" onclick="$('.email').slideDown('fast');
                                  $('.password_cont').slideUp('fast');  $('.register_box').slideUp('fast')
                                  $('.gestButton').show('fast');
                                  $('.gestButton').html('Contnue as Guest');" <?php
                          if ($this->input->post('checkout_type') == 'Guest') {
                            echo 'checked';
                          }
                          ?>>
                            </div>
                            <div class="col-md-10">
                              <b>Continue as Guest</b>
                            </div>
                            </label>
                          </div>
                        </div>
-->
                                                <div class="col-sm-6 col-xs-12">
                                                    <div class="row">
                                                        <label>
                                                            <div class="col-md-1">
                                                                <input name="checkout_type" id="checkout_type_user" checked="" type="radio" value="User" class="" onclick="$('.email').slideDown('fast');
                              $('.register_box').slideUp('fast')
                                  $('.password_cont').slideDown('fast');
                                  $('.gestButton').show('fast');
                                  $('.gestButton').html('Login Now');" <?php
                          if ($this->input->post('checkout_type') == 'User') {
                            echo 'checked';
                          }
                          ?>>
                                                            </div>
                                                            <div class="col-md-10">
                                                                <b>I have an account and password</b><br>
                                                            </div>
                                                        </label>
                                                    </div>
                                                </div>
                                                <div class="col-sm-6 col-xs-12">
                                                    <div class="row">
                                                        <label>
                                                            <div class="col-md-1 col-xs-1">
                                                                <input name="checkout_type" id="checkout_type_user" type="radio" value="Register" class="" onclick="$('.register_box').slideDown('fast'); $('.password_cont').slideUp('fast');$('.gestButton').show('fast');
                                  $('.gestButton').html('Register');" <?php
                          if ($this->input->post('checkout_type') == 'Register') {
                            echo 'checked';
                          }
                          ?>>
                                                            </div>
                                                            <div class="col-md-10 col-xs-10"> <b>Register and Continue</b>
                                                            </div>
                                                        </label>
                                                    </div>
                                                </div>
                                            </div>

                                            <?php echo form_close(); ?>
                                        </div>
                                        <div class="col-md-4 col-sm-4">
                                            <div class="checkout_right">
                                                <h4>Advantages of our secure login</h4>
                                                <ul>
                                                    <li><i class="fa fa-check"></i> Easily Track Orders, Hassle free Returns</li>
                                                    <li><i class="fa fa-check"></i> Get Relevant Alerts and Recommendation</li>
                                                    <li><i class="fa fa-check"></i> Wishlist, Reviews, Ratings and more.</li>
                                                </ul>
                                            </div>
                                        </div>

                                    </div>
                                </div>
                            </div>
                        </section>
                        <!-- checkout-step-02  -->
                        <section class="panel panel-default checkout-step-02">
                            <h4 class="checkout_title"><a data-toggle="collapse" class="collapsed"><span>2</span>Enter Address</a> </h4>

                        </section>
                        <!-- checkout-step-03  -->
                        <div class="panel panel-default checkout-step-03">
                            <h4 class="checkout_title">
                                <a data-toggle="collapse" data-toggle="collapse" class="collapsed">
                                    <span>3</span>Order Summary </a>
                            </h4>

                        </div>
                        <!-- checkout-step-04  -->
                        <div class="panel panel-default checkout-step-04">
                            <h4 class="checkout_title">
                                <a data-toggle="collapse" class="collapsed">
                                    <span>4</span>Payment Options</a>
                            </h4>

                        </div>
                        <!-- checkout-step-04  -->
                    </div>
                    <!-- /.checkout-steps -->
                </div>
            </div>
            <div class="col-lg-3 col-md-3 col-sm-4  col-xs-12">
                <div class="left_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();
                         $percent = $items['options']['GST'];
                                 $gst_amount = $totalAmount-($totalAmount*(100/(100+$percent)));
                                $withoutgst = number_format(($totalAmount - $gst_amount),2);
                      $i++;
}
?>
                            <tr>
                                <td>Sub Total</td>
                                <td><?= display_price($totalAmount); ?></td>
                            </tr>
                            <?php if ($discount_amount > 0) { ?>
                            <tr>
                                <td>Discount Price</td>
                                <td>- <?= display_price($discount_amount); ?></td>
                            </tr>
                            <?php } ?>
                            <?php  
                  $deliveryCharge = delivery_charge(0,$totalAmount);  ?>
                            <tr>
                                <td>Delivery Charges</td>
                                <td class="free"><?php echo ($deliveryCharge>0)?display_price($deliveryCharge):'Excluding'; ?></td>
                            </tr>

                            <tr>
                                <td>GST(18%)</td>
                                <!--
                                <td class="free"><?php $gst = number_format($gst_amount,2); 
                               echo display_price($gst); ?></td>
-->
                                <td>Included</td>
                            </tr>

                        </tbody>
                        <tfoot>
                            <tr>
                                <td>Amount Payable</td>
                                <td><?= display_price(($totalAmount-$discount_amount)+$deliveryCharge); ?></td>
                            </tr>
                        </tfoot>
                    </table>
                    <!--  <a class="order_btn" href="javascript:void()" title="Place Order">Place Order</a> -->

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

<?php $this->load->view("bottom"); ?>
<script type="text/javascript">
    $(document).ready(function() {
        var value = $('input[name=checkout_type]:checked').val();

        if (value == 'User') {
            $(".password_cont").css('display', 'block');
            $('.gestButton').html('Login Now');
        } else if (value == 'Register') {
            $(".password_cont").css('display', 'none');
            $(".register_box").css('display', 'block');
            $('.gestButton').html('Register');
        } else {
            $('.gestButton').html('Continue as Guest');
        }
    });

</script>
