<?php
$this->load->view("top");
$discountAmt = $discount_amount = $this->session->userdata('discount_amount');
$cart = $this->cart->contents();
$payableAmount = $totalAmount = $origAmount = $discountAmt = $total_shipping = 0;
$i = 1;
foreach ($cart as $items) {
  //trace($items);
  $shipping = 0;
  $url = $this->db->query("SELECT friendly_url FROM wps_products WHERE products_id = '" . $items['pid'] . "'")->row_array();
  $totalAmount += ($items['price'] * $items['qty']);
  $price = $items['price'];
}
//$percent = $items['options']['GST'];
// $gst_amount = $totalAmount-($totalAmount*(100/(100+$percent)));
// $withoutgst = number_format(($totalAmount - $gst_amount),2);
//$gst = gst($totalAmount,2);
$deliveryCharge = delivery_charge(0,$totalAmount);

$payableAmount = ($totalAmount - $discount_amount)+$deliveryCharge;
$posted_data = $this->session->userdata('posted_data');
// print_r($posted_data);
?>
<section class="banner_category" style="background-image: url('<?php echo theme_url();?>images/listing-banner.jpg');">
    <div class="container">

        <h1 class="banner_title">Payment Options</h1>
    </div>
</section>
<div class="page_breadcrumbs">
    <div class="container">
        <ul>
            <li><a href="<?= site_url(); ?>" title="Home">Home</a></li>
            <li>Payment Options</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>Payment Options</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"><span>1</span>Login or Signup <span class="pull-right"><i class="fa fa-check-square"></i></span></a>
                            </h4>
                        </section>

                        <!-- checkout-step-02  -->
                        <section class="panel panel-default checkout-step-02">
                            <h4 class="checkout_title"><a data-toggle="collapse" href="javascript:void(0);"><span>2</span>Delivery Address <span class="pull-right"><i class="fa fa-check-square"></i></span></a></h4>
                        </section>

                        <!-- checkout-step-03  -->
                        <div class="panel panel-default checkout-step-03">
                            <h4 class="checkout_title">
                                <a class="collapse" href="<?php echo site_url(); ?>cart/view_order_review"><span>3</span>Order Summary <button class="change" style="color: #fff;border: 1px solid #fff;">View Order</button></a>
                            </h4>
                        </div>

                        <!-- checkout-step-04  -->
                        <div class="panel panel-default checkout-step-04">
                            <h4 class="checkout_title">
                                <a data-toggle="collapse" class="collapsed" href="javascript:void(0);">
                                    <span>4</span>Payment Options</a>
                            </h4>
                            <div id="collapseFour" class="panel-collapse collapse show">
                                <div class="panel-body">
                                    <div class="payment_option">
                                        <?php
                    echo form_open('', 'name="payment" id="payment_form" action="post"');
                    ?>
                                        <!-- <label class="radio">
                      Credit / Debit / ATM Card
                      <input name="pay" type="radio" value="paytm" class="payone" checked> 
                      <span class="checkround"></span>
                    </label> -->
                                        <!--   <div class="payonediv" hidden="hidden">
                      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
                      <img src="<?php echo theme_url(); ?>images/ccavenue.png"> 
                      <img src="<?php echo theme_url(); ?>images/ccavenue.png"> 
                      <img src="<?php echo theme_url(); ?>images/ccavenue.png">
                    </div> -->
                                        <!-- <label class="radio">PhonePe / BHIM UPI
                      <input name="pay" type="radio" value="paytm" class="paytwo"/>
                      <span class="checkround"></span>
                    </label>
                    <label class="radio">Net Banking
                      <input type="radio" name="pay" value="paytm" class="paythree">
                      <span class="checkround"></span>
                    </label>
                     <label class="radio">Paypal
                      <input type="radio" name="pay" value="Paypal" class="payfour">
                      <span class="checkround"></span>
                    </label> -->
                                        <label class="radio">RazorPay
                                            <input type="radio" name="pay" value="RazorPay" class="payfour" id="payfour" required checked onclick="$('.confrmorder').html('Pay <?php echo display_price($payableAmount); ?>');">
                                            <span class="checkround"></span>
                                        </label>

                                        <label class="radio">Cash on Delivery
                                            <input type="radio" name="pay" value="COD" class="payfive" id="payfive" id="checkcity" required onclick="myvv();">
                                            <span class="checkround"></span>
                                        </label>
                                        <input type="hidden" id="city" value="<?=strtolower(@$posted_data['city']);?>" />
                                        <input type="hidden" name="key" value="B9vclA" />
                                        <input type="hidden" name="hash" value="" />
                                        <input type="hidden" name="amount" value="<?php echo $payableAmount; ?>" />
                                        <input type="hidden" name="firstname" value="<?php echo $posted_data['name']; ?>" />
                                        <input type="hidden" name="email" value="<?php if ($this->session->userdata('user_id') > 0) { echo $this->session->userdata['username']; } else { echo $this->session->userdata['username']; } ?>" />
                                        <input type="hidden" name="productinfo" value="Clothing" />
                                        <input type="hidden" name="service_provider" value="payu_paisa" />
                                        <input type="hidden" name="phone" value="<?php echo $posted_data['mobile']; ?>" />
                                        <div class="form-control cb-style">
                                            <input type="checkbox" id="checkTerms" name="agreement" value="agreement" checked required>

                                            <label for="agreement">I have read and agreed to the Website's <a href="<?php echo base_url();?>privacy-policy" title="Returns and Refund Policy"><b>Return and Refund Policy</b></a>
                                            </label><br />


                                        </div>
                                        <div id="checkerror" style="color: #ab1d05;
    font-size: 15px;
    font-weight: 600;"></div>
                                        <button class="confrmorder" type="submit" name="confrmorder" id="">Pay <?php echo display_price($payableAmount); ?></button>
                                        <?php echo form_close(); ?>
                                    </div>
                                </div>
                            </div>
                        </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 } ?>
                            <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>

                </div>
            </div>

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

<?php $this->load->view("bottom"); ?>
<script type="text/javascript">
    $(document).ready(function() {
       
        $('.confrmorder').click(function(e) {
            e.preventDefault();
            if ($("#checkTerms").is(':checked')) {
                $('#payment_form').submit();
            } else {
                $('#checkerror').html('Please click on the "Check Box" to proceed further');
                //swal('Please Check to agree Terms & Conditions.');
            }
        });
    });

   
    // function myvv(){
    //     if ($('#city').val().localeCompare('delhi')==0) {
    //             swal({title:'Currently Cash on Delivery Available Only in Delhi',confirmButtonColor: "rgb(11 33 22)",confirmButtonText: "Ok",});
    //             document.getElementById('payfour').checked = false;
    //             document.getElementById('payfive').checked = true;
    //             $('.confrmorder').html('Place Order');
    //         } else {
    //             // $('#checkcierror').html('Please click on the "Check Box" to proceed further');
    //             swal({title:'Currently Cash on Delivery Available Only in Delhi',confirmButtonColor: "rgb(11 33 22)",confirmButtonText: "Exit",});
    //             document.getElementById('payfour').checked = true;
    //             document.getElementById('payfive').checked = false;
    //         }
    // }


    function myvv(){
        if ($('#city').val().localeCompare('delhi')==0) {
            swal({
  title: "Currently Cash on Delivery Available Only in Delhi",
  type: "warning",
  showCancelButton: true,
  confirmButtonClass: "btn-success",
  confirmButtonText: "Ok",
  cancelButtonText: "cancel!",
  closeOnConfirm: false,
  closeOnCancel: false
},
function(isConfirm) {
  if (isConfirm) {
    swal("Order Conform", "Thank You For Purchase:)", "success");
        document.getElementById('payfour').checked = false;
        document.getElementById('payfive').checked = true;
        $('#payment_form').submit();
  } else {
    location.reload();
  }
});
 } else {
 swal({
  title: "Currently Cash on Delivery Available Only in Delhi",
  type: "warning",
  showCancelButton: true,
  confirmButtonClass: "btn-success",
  cancelButtonText: "Cancel",
  confirmButtonText: "Ok",
  closeOnConfirm: false,
  reverseButtons: true,
  closeOnCancel: false
},
function(isConfirm) {
  if (isConfirm) {
    document.getElementById('payfour').checked = true;
    document.getElementById('payfive').checked = false;
    $('#payment_form').submit();
  } else {
    location.reload();
  }
});
 }
    }

</script>