@extends('user.app')
@section('pagetitle'){{ $cms->title }}@stop
@section('pagedescription')
@php $meta_details = trim($cms->meta_details); @endphp
<meta name="description" content="{{ $meta_details }}">
@stop
@section('pagekeywords')
@php $meta_tags = trim($cms->meta_tags); @endphp
<meta name="keywords" content="{{ $meta_tags }}">
@stop
@section('main-content')
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script>
$( function() {

//stop multiple submition
$('#checkout-form').on( 'submit', function(e) {
    $("#checkout-btn").attr('disabled','disabled');
});


$('#ship_dif').change(function () {
if ($(this).prop("checked")) {
var first_name_shipping = $("#first_name_shipping").val();
var last_name_shipping = $("#last_name_shipping").val();
var email_shipping = $("#email_shipping").val();
var mobile_no_shipping = $("#mobile_no_shipping").val();
var country_shipping = $("#country_shipping").val();
var addreess_shipping = $("#addreess_shipping").val();
var city_shipping = $("#city_shipping").val();
var state_shipping = $("#state_shipping").val();
var postcode_shipping = $("#postcode_shipping").val();
// alert(first_name_shipping);
// alert(last_name_shipping);
// alert(email_shipping);
// alert(mobile_no_shipping);
// alert(country_shipping);
// alert(addreess_shipping);
//  alert(city_shipping);
// alert(state_shipping);
// alert(postcode_shipping);
$("#first_name_billing").val(first_name_shipping);
$("#last_name_billing").val(last_name_shipping);
$("#email_billing").val(email_shipping);
$("#mobile_no_billing").val(mobile_no_shipping);
$("#country_billing").val(country_shipping);
$("#addreess_billing").val(addreess_shipping);
$("#city_billing").val(city_shipping);
$("#state_billing").val(state_shipping);
$("#postcode_billing").val(postcode_shipping);
}
});
});
</script>
<div class="banner-part">
    <img src="{{ asset('user/images/inner-ban1.jpg') }}" alt="">
    <div class="inner-ban-tx">
        <div class="container">
            <div class="row">
                <h2>CHECKOUT</h2>
            </div>
        </div>
    </div>
</div>
<section class="checkout-area ptb-100 dashbord profile-page">
    <div class="container">
        @php
        $first_name_shipping = '';
        $last_name_shipping = '';
        $email_shipping = '';
        $mobile_no_shipping = '';
        $country_shipping = '';
        $addreess_shipping = '';
        $city_shipping = '';
        $state_shipping ='';
        $postcode_shipping='';
        $first_name_billing = '';
        $last_name_billing = '';
        $email_billing = '';
        $mobile_no_billing = '';
        $country_billing = '';
        $addreess_billing  = '';
        $city_billing = '';
        $state_billing  = '';
        $postcode_billing = '';
        
        if(isset($usermeta))
        {
        if(isset($usermeta->shipping_address) && $usermeta->shipping_address!='')
        {
        $shipping_data = json_decode($usermeta->shipping_address);
        $first_name_shipping = $shipping_data->first_name_shipping;
        $last_name_shipping = $shipping_data->last_name_shipping;
        $email_shipping = $shipping_data->email_shipping;
        $mobile_no_shipping = $shipping_data->mobile_no_shipping;
        $country_shipping = $shipping_data->country_shipping;
        $addreess_shipping = $shipping_data->addreess_shipping;
        $city_shipping = $shipping_data->city_shipping;
        $state_shipping = $shipping_data->state_shipping;
        $postcode_shipping = $shipping_data->postcode_shipping;
        }
        if(isset($usermeta->billing_address) && $usermeta->billing_address!='')
        {
        $billing_data = json_decode($usermeta->billing_address);
        $first_name_billing = $billing_data->first_name_billing;
        $last_name_billing = $billing_data->last_name_billing;
        $email_billing = $billing_data->email_billing;
        $mobile_no_billing = $billing_data->mobile_no_billing;
        $country_billing = $billing_data->country_billing;
        $addreess_billing = $billing_data->addreess_billing;
        $city_billing = $billing_data->city_billing;
        $state_billing = $billing_data->state_billing;
        $postcode_billing = $billing_data->postcode_billing;
        }
        
        }
        @endphp
        {!! Form::open(array('route' => 'checkout.store','method'=>'POST', 'id' =>'checkout-form')) !!}
        <div class="row">
            <div class="col-lg-12 col-md-12">
                <div class="cart-table table-responsive">
                    @include('user/layouts/messages');
                </div>
            </div>
           

            <div class="col-md-8">
                <div class="checkout">
                    <div class="cartleft">
                        <div class="col-md-12"><h5>Order Details</h5></div>
                        @php
                        $totalprice = 0;
                        $subtotalprice = 0;
                        $coupon_code = '';
                        $coupon_discount = 0;
                        $shipping_charge = 0;
                        $shipping_charge = 0;
                        @endphp
                        @if(isset($carts))
                        @php
                            $product_count = count($carts);
                        @endphp
                        @foreach($carts as $cart)
                        @php
                        $subtotalprice =  $subtotalprice + ($cart->price * $cart->quantity);
                        $coursesimage = coursesimage($cart->product_id);
                        $coursesurl = coursesurl($cart->product_id);
                        @endphp
                        <div class="cartsec">
                            <div class="col-md-3">
                                <a href="{{ $coursesurl }}"><img src="{{ $coursesimage }}" alt="shop"></a>
                            </div>
                            <div class="col-md-9">
                                <h3><a href="{{ $coursesurl }}">{{$cart->name}}</a> X {{ $cart->quantity }}</h3>
                                <p class="tutor">By <a href="{{url('/')}}/educator/{{ coursesfacaltyurl($cart->product_id) }}" class="educatorlink">{{ coursesfacalty($cart->product_id) }}</a></p>
                                <h4 class="cross-t">
                                <del>Rs.{{coursesprice($cart->product_id) }}</del>Rs.{{ $cart->price }}
                                </h4>
                            </div>
                        </div>
                        </br>
                        @endforeach
                        @endif
                        <div class="form-group mb-0">
                            <label>Order Notes</label>
                            {{ Form::textarea('message', null, array('placeholder'=>'Notes about your order, e.g. special notes for delivery...' ,'class'=>'form-control')) }}
                        </div>
                    </div>
                </div>
                <div class="checkout">
                    <div class="cartleft">
                        <div class="col-md-12"><h5>Shipping Details</h5></div>
                        <div class="col-lg-6 col-md-6">
                            <div class="form-group">
                                <label>First Name*</label>
                                {{ Form::text('first_name_shipping', $first_name_shipping, array('required','placeholder'=>'First Name','class'=>'form-control','id'=>'first_name_shipping'  )) }}
                            </div>
                        </div>
                        <div class="col-lg-6 col-md-6">
                            <div class="form-group">
                                <label>Last Name*</label>
                                {{ Form::text('last_name_shipping',$last_name_shipping, array('required','placeholder'=>'Last Name','class'=>'form-control','id'=>'last_name_shipping'  )) }}
                            </div>
                        </div>
                        <div class="col-lg-6 col-md-6">
                            <div class="form-group">
                                <label>Email*</label>
                                {{ Form::email('email_shipping', $email_shipping , array('required', 'placeholder'=>'Email ID*' ,'id'=>'email_shipping' )) }}
                            </div>
                        </div>
                        <div class="col-lg-6 col-md-6">
                            <div class="form-group">
                                <label>Phone*</label>
                                {{ Form::text('mobile_no_shipping',$mobile_no_shipping, array('required', 'placeholder'=>'Mobile No*' ,'id'=>'mobile_no_shipping' )) }}
                            </div>
                        </div>
                        <div class="col-lg-12 col-md-12">
                            <div class="form-group">
                                <label>Country*</label>
                                {{ Form::text('country_shipping',$country_shipping, array('required', 'placeholder'=>'Country','class'=>'form-control' ,'id'=>'country_shipping' )) }}
                                
                            </div>
                        </div>
                        <div class="col-lg-12 col-md-12">
                            <div class="form-group">
                                <label>Address*</label>
                                {{ Form::text('addreess_shipping',$addreess_shipping, array('required', 'placeholder'=>'Address','class'=>'form-control' ,'id'=>'addreess_shipping' )) }}
                            </div>
                        </div>
                        <div class="col-lg-12 col-md-12">
                            <div class="form-group">
                                <label>Town/City*</label>
                                {{ Form::text('city_shipping', $city_shipping, array('required', 'placeholder'=>'City','class'=>'form-control','id'=>'city_shipping'  )) }}
                            </div>
                        </div>
                        <div class="col-lg-6 col-md-6">
                            <div class="form-group">
                                <label>State*</label>
                                {{ Form::text('state_shipping',$state_shipping, array('required', 'placeholder'=>'State','class'=>'form-control' ,'id'=>'state_shipping' )) }}
                            </div>
                        </div>
                        <div class="col-lg-6 col-md-6">
                            <div class="form-group">
                                <label>Postcode/ZIP*</label>
                                {{ Form::text('postcode_shipping',$postcode_shipping, array('required', 'placeholder'=>'Postcode','class'=>'form-control' ,'id'=>'postcode_shipping' )) }}
                            </div>
                        </div>
                    </div>
                </div>
                <div class="checkout">
                    <div class="cartleft">
                        <div class="col-md-12"><h5>Billing Details  <span>
                            <input type="checkbox" id="ship_dif">Same as Shipping Address</span></h5> </div>
                            <div class="col-lg-6 col-md-6">
                                <div class="form-group">
                                    <label>First Name*</label>
                                    {{ Form::text('first_name_billing',  $first_name_billing , array('required','placeholder'=>'First Name','class'=>'form-control','id'=>'first_name_billing' )) }}
                                </div>
                            </div>
                            
                            <div class="col-lg-6 col-md-6">
                                <div class="form-group">
                                    <label>Last Name*</label>
                                    {{ Form::text('last_name_billing', $last_name_billing, array('required','placeholder'=>'Last Name','class'=>'form-control','id'=>'last_name_billing'  )) }}
                                </div>
                            </div>
                            
                            <div class="col-lg-6 col-md-6">
                                <div class="form-group">
                                    <label>Email*</label>
                                    {{ Form::email('email_billing', $email_billing , array('required', 'placeholder'=>'Email ID*','id'=>'email_billing'  )) }}
                                </div>
                            </div>
                            
                            <div class="col-lg-6 col-md-6">
                                <div class="form-group">
                                    <label>Phone*</label>
                                    {{ Form::text('mobile_no_billing',  $mobile_no_billing , array('required', 'placeholder'=>'Mobile No*','id'=>'mobile_no_billing'  )) }}
                                </div>
                            </div>
                            
                            <div class="col-lg-12 col-md-12">
                                <div class="form-group">
                                    <label>Country*</label>
                                    {{ Form::text('country_billing',  $country_billing, array('required', 'placeholder'=>'Country','class'=>'form-control' ,'id'=>'country_billing' )) }}
                                    
                                </div>
                            </div>
                            
                            <div class="col-lg-12 col-md-12">
                                <div class="form-group">
                                    <label>Address*</label>
                                    {{ Form::text('addreess_billing',  $addreess_billing , array('required', 'placeholder'=>'Address','class'=>'form-control','id'=>'addreess_billing'  )) }}
                                </div>
                            </div>
                            <div class="col-lg-12 col-md-12">
                                <div class="form-group">
                                    <label>Town/City*</label>
                                    {{ Form::text('city_billing',  $city_billing , array('required', 'placeholder'=>'City','class'=>'form-control' ,'id'=>'city_billing' )) }}
                                </div>
                            </div>
                            
                            <div class="col-lg-6 col-md-6">
                                <div class="form-group">
                                    <label>State*</label>
                                    {{ Form::text('state_billing',  $state_billing , array('required', 'placeholder'=>'State','class'=>'form-control','id'=>'state_billing'  )) }}
                                </div>
                            </div>
                            
                            <div class="col-lg-6 col-md-6">
                                <div class="form-group">
                                    <label>Postcode/ZIP*</label>
                                    {{ Form::text('postcode_billing',  $postcode_billing , array('required', 'placeholder'=>'Postcode','class'=>'form-control' ,'id'=>'postcode_billing' )) }}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-4 floatdiv">
                    <div class="checkout">

                        
                    @if($coupon=='couponNotApplied')
                       <div class="cartright">
                            <h5>Price Details</h5>
                            @php
                            $totalprice = 0;
                            $total_dicount_amount=0;
                            $subtotalprice = 0;
                            $coupon_code = '';
                            $coupon_discount = 0;
                            $wallet_per_order = 0;
                            $product_count=0;
                            $wallet_value_for_total_product=0;
                            @endphp
                            @if(isset($carts))
                            @php
                            $product_count = count($carts);
                            @endphp
                            @foreach($carts as $cart)

                            @php
                            $subtotalprice =  $subtotalprice + ($cart->price * $cart->quantity);
                            $coursesimage = coursesimage($cart->product_id);
                            @endphp
                            @endforeach
                            <h3>Price<span>Rs.{{number_format((float)$subtotalprice, 2, '.', '')}}</span></h3>
                            {{--   {{ $wallet->wallet_per_order}}
                            {{ $usermeta->current_wallet_balance}}
                            {{$subtotalprice}}
                            --}}
                                 @php
                            $wallet_per_order = 0;

                            $total_wallet_order=$wallet->wallet_per_order*$product_count;

                            if(isset($usermeta->current_wallet_balance) && $usermeta->current_wallet_balance>=  $total_wallet_order ) {
                            if($subtotalprice > $total_wallet_order )
                            {
                            
                            $wallet_value_for_total_product=$total_wallet_order;
                            
                            @endphp
                            
                            
                            <h3>Paid from Wallet <span>Rs.{{number_format((float)$total_wallet_order, 2, '.', '')}}</span></h3>
                            
                            @php }
                            } elseif(isset($usermeta->current_wallet_balance)) {
                            if($subtotalprice >$usermeta->current_wallet_balance )
                            { 
                             $wallet_value_for_total_product =$usermeta->current_wallet_balance;

                            @endphp

                           <h3>Paid from Wallet <span>Rs.{{number_format((float)$wallet_value_for_total_product, 2, '.', '')}}</span></h3>

                            @php 
                             }
                             }
                            @endphp                  
                            @if(isset($ucart_data) && $ucart_data->coupon_code!='')
                            @php
                            $coupon_code = $ucart_data->coupon_code;
                            @endphp
                            
                            <h3>Coupon : {{$ucart_data->coupon_code}}<a href="<?php echo url('/couponremove/');?>">x</a>
                            @php
                            $coupon_discount = $ucart_data->coupon_discount;
                            @endphp
                            <span>Rs.{{number_format((float)$ucart_data->coupon_discount, 2, '.', '')}}</span>
                            </h3>
                            @endif
                            @if(isset($ucart_data))
                            <h3>Shipping and Handling
                            @php
                            $shipping_charge = $ucart_data->shipping_charge;
                            @endphp
                            <span>Rs.0.00</span>
                            </h3>
                            @endif
                            <h4>Order Total
                            @php

                            $totalprice = $subtotalprice - $wallet_value_for_total_product + $shipping_charge;
                            @endphp
                            <span>Rs.{{number_format((float)round($totalprice), 2, '.', '')}}</span>
                            </h4>
                            @endif
                            
                            <!-- <ul>
                                <li><a href="{{ url('/') }}" class="btn btn-primary">Continue Shopping</a></li>
                                <li><a href="{{ url('/checkout') }}" class="btn btn-primary">Place Order</a></li>
                            </ul> -->
                        </div>
                        @else
                          
                            <div class="cartright">
                            <h5>Price Details</h5>
                            @php
                            $total_dicount_amount=0;
                            $totalprice = 0;
                            $subtotalprice = 0;
                            $coupon_code = $coupon;
                            $coupon_discount = 0;
                            $wallet_per_order = 0;
                            $product_count=0;
                            $wallet_value_for_total_product=0;
                            @endphp
                            @if(isset($carts))
                            @php
                            $product_count = count($carts);
                            @endphp
                            @foreach($carts as $cart)

                            @php
                            $subtotalprice =  $subtotalprice + ($cart->price * $cart->quantity);
                            $coursesimage = coursesimage($cart->product_id);

                            $total_dicount_amount=$total_dicount_amount+ educator_referal_discount_subtotal($cart->product_id);
                            @endphp
                            @endforeach
                            <h3>Price<span>Rs.{{number_format((float)$subtotalprice, 2, '.', '')}}</span></h3>
                            <h3>Coupon Discount <span>Rs.{{number_format((float)round($total_dicount_amount), 2, '.', '')}}</span></h3>
                             @php
                            $wallet_per_order = 0;

                            $total_wallet_order=$wallet->wallet_per_order*$product_count;

                            if(isset($usermeta->current_wallet_balance) && $usermeta->current_wallet_balance>=  $total_wallet_order ) {
                            if($subtotalprice > $total_wallet_order )
                            {
                            
                            $wallet_value_for_total_product=$total_wallet_order;
                            
                            @endphp
                            
                            
                            <h3>Paid from Wallet <span>Rs.{{number_format((float)$total_wallet_order, 2, '.', '')}}</span></h3>
                            
                            @php }
                            } elseif(isset($usermeta->current_wallet_balance)) {
                            if($subtotalprice >$usermeta->current_wallet_balance )
                            { 
                             $wallet_value_for_total_product =$usermeta->current_wallet_balance;

                            @endphp

                           <h3>Paid from Wallet <span>Rs.{{round(number_format((float)$wallet_value_for_total_product, 2, '.', ''))}}</span></h3>

                            @php 
                             }
                             }
                            @endphp                  
                            @if(isset($ucart_data) && $ucart_data->coupon_code!='')
                            @php
                            $coupon_code = $ucart_data->coupon_code;
                            @endphp
                            
                            <h3>Coupon : {{$ucart_data->coupon_code}}<a href="<?php echo url('/couponremove/');?>">x</a>
                            @php
                            $coupon_discount = $ucart_data->coupon_discount;
                            @endphp
                            <span>Rs.{{number_format((float)$ucart_data->coupon_discount, 2, '.', '')}}</span>

                            </h3>
                            @endif
                            @if(isset($ucart_data))
                            <h3>Shipping and Handling
                            @php
                            $shipping_charge = $ucart_data->shipping_charge;
                            @endphp
                            <span>Rs.0.00</span>
                            </h3>
                            @endif
                            <h4>Order Total
                            @php
                            //if(isset($ucart_data)){
                            ///$coupon_discount = $ucart_data->coupon_discount;
                            // }
                            //$new_wallet_balance=$wallet->wallet_per_order?$wallet->wallet_per_order:'';
                            //$totalprice = $subtotalprice - $coupon_discount + $shipping_charge;

                            /**if(($subtotalprice > $wallet->wallet_per_order ) && $usermeta->current_wallet_balance>=$total_wallet_order){
                            
                             $wallet_value_for_total_product__=$total_wallet_order;

                            }elseif($subtotalprice > $wallet->wallet_per_order )
                            {
                            
                              $wallet_value_for_total_product__ =  $wallet->wallet_per_order;
                            }**/

                            $totalprice = ($subtotalprice - $wallet_value_for_total_product + $shipping_charge)-$total_dicount_amount;
                            @endphp
                            <span>Rs.{{number_format((float)round($totalprice), 2, '.', '')}}</span>
                            </h4>
                            @endif
                            
                            <!-- <ul>
                                <li><a href="{{ url('/') }}" class="btn btn-primary">Continue Shopping</a></li>
                                <li><a href="{{ url('/checkout') }}" class="btn btn-primary">Place Order</a></li>
                            </ul> -->
                        </div>

                        @endif

                    </div>
                    <div class="checkout">
                        <div class="cartright">
                            <h5>Payment Information</h5>
                            <div class="control-label place-order">
                                <input type="radio" name="payment" value="ccavenue" required />
                                
                                <label>CC-Avenue Payment</label>
                                <!--<input type="radio" name="payment" value="payu" />-->
                                <input type="radio" name="payment" value="razorpay" />
                                <label>Razorpay Payment</label>
                                <img src="http://buyonlineclasses.com/user/images/payimg.jpg" alt="">
                            </div>
                            {!! Form::hidden('user_id',Auth::user()->id ) !!}
                            {!! Form::hidden('cart_subtotal', $subtotalprice ) !!}
                            {!! Form::hidden('shipping_charge',$shipping_charge) !!}
                            {!! Form::hidden('coupon_code', $coupon_code ) !!}
                            {!! Form::hidden('coupon_discount', number_format((float)$total_dicount_amount, 2, '.', '') ) !!}
                            {!! Form::hidden('cart_total',round($totalprice)) !!}
                            {!! Form::hidden('wallet_per_order', $wallet_value_for_total_product ) !!}
                            <div class="place-order">
                                <input type="checkbox" name="terms" value="1" required/>
                                <label  class="control-label" >You have read our <a class="special" href="{{ url('/terms-offer')}}" target="_blank" role="link">Terms of offer</a>  for sale.</label>
                            </div>
                            {!! Form::submit('Place Order',array('class'=>'btn btn-primary','id'=>'checkout-btn')) !!}
                        </div>
                    </div>
                </div>
            </div>
            {!! Form::close() !!}
            <div class="clearfix"></div>
            {{-- <div class="clearfix"></div> --}}
            <!-- <div id="exTab1" class="coucont">
                <ul  class="nav nav-pills">
                    <li class="active">
                        <a  href="#1a" data-toggle="tab">Coupon</a>
                    </li>
                    <li>
                        <a href="#2a" data-toggle="tab">Wallet</a>
                    </li>
                </ul>
                <div class="tab-content clearfix">
                    <div class="tab-pane active" id="1a">
                        {!! Form::open(array('route' => 'coupon.deduct','method'=>'POST', 'class' => 'form' ,'id' =>'createroomsform')) !!}
                        {!! Form::text('coupon_code', null,array('placeholder'=>'Coupon Code')) !!}
                        {{ Form::hidden('user_id',Auth::user()->id ) }}
                        {{ Form::hidden('subtotalprice',$subtotalprice) }}
                        {{--  {{ Form::hidden('shipping_charge',$shipping_charge) }}
                        {{ Form::hidden('subtotalprice',$subtotalprice) }}
                        {{ Form::hidden('totalprice',$totalprice) }} --}}
                        {!! Form::submit('Apply Coupon', array('class'=>'add-acte')) !!}
                        {!! Form::close() !!}
                    </div>
                    <div class="tab-pane" id="2a">
                        <h3>Wallet will be implemented soon !!!</h3>
                    </div>
                </div>-->
            </div>
        </section>
        
        @endsection