Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @extends('frontend.layouts.default')
- @section('content')
- <!-- Banner -->
- @include('frontend.partials.bookingBannerHero')
- <!-- Breadcrumb -->
- @include('frontend.partials.breadcrumb')
- <div class="page-content page-booking">
- <a name="bookingSteps"></a>
- <form id="bookingForm" action="/" method="post" class="booking-form form-steps">
- @csrf
- <div id="wizard" class="booking-form__content">
- <h2>Select Class</h2>
- <section class="custom-container side-padding w-100 m-auto">
- @include('frontend.partials.step1')
- </section>
- <h2>Select Date</h2>
- <section class="custom-container side-padding w-100 m-auto">
- @include('frontend.partials.step2')
- </section>
- <h2>Register & Payment</h2>
- <section class="custom-container side-padding w-100 m-auto">
- @include('frontend.partials.step3')
- </section>
- <div class="booking-system-message custom-container m-auto side-padding w-100"> </div>
- <!-- Booking voucher section -->
- @include('frontend.partials.voucherCodeSection')
- <!-- Booking overview -->
- @include('frontend.partials.bookingOverview')
- </div>
- </form>
- </div>
- @endsection
- @section('scripts')
- <!-- Monent js -->
- <script src={{ URL::asset('vendors/momentjs/moment.min.js') }}></script>
- <!--<script src="{{-- url('js/bookingStateHandler.js') --}}"></script>-->
- <script src={{ URL::asset(mix('js/booking.js')) }}></script>
- <script type="text/javascript">
- sessionStorage.clear();
- // Init steps
- $("#wizard").steps({
- headerTag: "h2",
- bodyTag: "section",
- transitionEffect: "slideLeft",
- autoFocus: true
- });
- // Fake next
- $("#continueNext").on('click', function(e) {
- // Stripe mount
- let totalAmountAfterVoucher = parseInt(JSON.parse(sessionStorage.getItem("bookingData")).totalAmountAfterVoucher);
- if(totalAmountAfterVoucher > 0) {
- card.mount('#card-element');
- }
- document.querySelector(".voucher-code-section").classList.remove("d-none");
- // Declare sessionData here
- let sessionData = JSON.parse(sessionStorage.getItem('bookingData'));
- // Get steps state
- let currStep = $("#wizard").steps("getCurrentStep", 0, {});
- // (Step 1)
- if(currStep.title == 'Select Class') {
- // Validation step 1
- if(
- ( sessionData.single > 0 || sessionData.shared > 0 )
- ) {
- $("#wizard").steps("next", 0, {});
- } else {
- helpers.setSystemMessage('Please select single and or shared stills.', 'error-message');
- }
- }
- // (Step 2)
- if (currStep.title == 'Select Date') {
- //console.log('select a date');
- // If next is clicked while inside step 2, going to step 3 hide voucher code section
- document.querySelector('.voucher-code-section').classList.add("d-none");
- if(
- ( sessionData.single > 0 || sessionData.shared > 0 ) &&
- ( sessionData.newdate!==null && sessionData.newdate!=="0000-00-00" )
- ) {
- $("#wizard").steps("next", 0, {});
- } else {
- helpers.setSystemMessage('Please select date from the field.', 'error-message');
- }
- document.querySelector(".voucher-code-section").classList.add("d-none");
- }
- // (Step 3)
- if(currStep.title == 'Register & Payment') {
- //console.log('Submitting ...', JSON.parse(sessionStorage.getItem('bookingData')));
- if (
- ( sessionData.single > 0 || sessionData.shared > 0 ) &&
- ( sessionData.fname!=="" && sessionData.lname!=="" && sessionData.email!=="" && sessionData.mobile!=="" ) &&
- ( sessionData.bookingAgree!==null && sessionData.bookingSummaryAgree!==null ) &&
- moment(sessionData.birthdate, 'YYYY-MM-DD').isValid()
- ) {
- if( sessionData.newdate==null || sessionData.newdate=="0000-00-00" ) {
- helpers.setSystemMessage('Please select date on step 2.', 'error-message');
- return false;
- }
- if(sessionData.totalAmountAfterVoucher > 0) {
- if(
- ( typeof(document.querySelector('.StripeElement--complete')) == 'undefined') ||
- ( document.querySelector('.StripeElement--complete') == null) ||
- ( sessionData.cardholderName=="" )
- ) {
- helpers.setSystemMessage('Please complete payment details.', 'error-message');
- return false;
- }
- }
- //console.log('pass');
- // Show loading if data id complete
- let bookingSummary = '<h2 class="mb-3">Booking Details</h2>';
- bookingSummary += '<div class="text-left w-75 mx-auto my-3">';
- bookingSummary += '<div class="row"><div class="col-4">Date: </div><div class="col-8">'+ moment(sessionData.newdate).format('dddd Do MMMM YYYY') +'</div></div>';
- bookingSummary += '<div class="row"><div class="col-4">Stills: </div><div class="col-8">'+sessionData.totalStills+'x 70cl bottle of Gin or Vodka</div></div>';
- bookingSummary += '<div class="row"><div class="col-4">Total Amount: </div><div class="col-8 font-weight-bold">'+sessionData.totalAmountAfterVoucher.toLocaleString("en-GB", {
- style: "currency",
- currency: "GBP"
- })+'</div></div>';
- bookingSummary += '</div>';
- bookingSummary += '<button id="processBooking" class="btn btn-lg btn--brown my-5">Pay now!</button>';
- /**
- * Dont remove setTimeout or the event will not fint the dynamically generated DOM button - find a fix
- */
- setTimeout(function() {
- document.querySelector('.custom-modal').classList.add("custom-modal--show");
- document.querySelector('.custom-modal #content').innerHTML = bookingSummary;
- }, 300);
- //console.log('pass 2');
- // Process booking
- $(document).on('click', '#processBooking', function(){
- //console.log('process booking');
- // Immediately remove button when processBooking is clicked
- document.querySelector('.custom-modal').classList.add("custom-modal--show");
- document.querySelector('.custom-modal #content').innerHTML = '<p>Loading ...</p>';
- var cardHolderName = document.getElementById('card-holder-name').value;
- $.ajax({
- type: "POST",
- url: "{{ route('bookingSubmitUserCheck') }}",
- data: {
- "_token": "{{ csrf_token() }}",
- data: JSON.parse(sessionStorage.getItem('bookingData'))
- },
- success: function(response) {
- //console.log('Response: ', response);
- //User Exist
- document.querySelector('.custom-modal').classList.add("custom-modal--show");
- document.querySelector('.custom-modal #content').innerHTML = '<p>Loading ...</p>';
- var usrQuery1 = response[3];
- var paymentIntentSecret = response[1];
- var paymentIntentID = response[4];
- var userId = response[5];
- if (response === "false") {
- ////////////////////////////////////////////////////////////
- // User Exist will not continue, must login
- ////////////////////////////////////////////////////////////
- document.querySelector('.custom-modal').classList.remove("custom-modal--show");
- document.querySelector("#wizard").innerHTML = ``;
- helpers.setSystemMessage(`User <strong>${sessionData.email}</strong> already exist. Please <a href="{{ URL::to('login') }}">login</a>.`);
- } else if (response[0] === "true") { //user doesn't exist
- if(sessionData.totalAmountAfterVoucher > 0) {
- //proceed to 2nd controller
- stripe.handleCardPayment(
- paymentIntentSecret, card, {
- payment_method_data: {
- billing_details: { name: cardHolderName }
- }
- }
- ).then(function(result) {
- if (result.error) {
- // Display error.message in your UI.
- //console.log(result.error);
- ////////////////////////////////////////////////////////////
- // Decline
- ////////////////////////////////////////////////////////////
- document.querySelector('.custom-modal').classList.add("custom-modal--show");
- document.querySelector('.custom-modal #content').innerHTML = `${result.error.message}`;
- // alert(result.error.code);
- } else {
- // fullfill the payment
- $.ajax({
- type: "POST",
- url: "{{ route('bookingSubmitCharge') }}",
- data: {
- "_token": "{{ csrf_token() }}",
- data: JSON.parse(sessionStorage.getItem('bookingData')),
- paymentIntentID: paymentIntentID,
- userId: userId
- },
- success: function(x) {
- if (x === "true") {
- //console.log('test success');
- document.querySelector('.custom-modal').classList.remove("custom-modal--show");
- document.querySelector("#wizard").innerHTML = ``;
- helpers.setSystemMessage(`Payment success! A confirmation email will be sent to ${JSON.parse(sessionStorage.getItem('bookingData')).email} with your booking details.`);
- // Remove all sesion Data
- document.querySelector("#continueNext").classList.add("disabled");
- sessionStorage.clear();
- } else {
- //console.log('x',x)
- }
- },
- error: function() {
- let errorMessage = "Oops, a technical error occured please contact admin.";
- helpers.setSystemMessage(errorMessage);
- document.querySelector('.custom-modal').classList.add("custom-modal--show");
- document.querySelector('.custom-modal #content').innerHTML = `
- <p>
- ${errorMessage}
- </p>
- `;
- }
- });
- }
- });
- }
- }
- },
- error: function(xhr, status, error) {
- setTimeout(function() {
- document.querySelector('.custom-modal').classList.add("custom-modal--show");
- document.querySelector('.custom-modal #content').innerHTML = `
- <div class="text-wrap">
- <p class="text-wrap">Error Message: Failed communication with bookingSubmitUserCheck.</p>
- </div>
- `;
- }, 300)
- }
- });
- });
- // $('#processBooking').on('click', function {
- // console.log('test');
- // });
- } else {
- //console.log('failed');
- helpers.setSystemMessage('Please confirm and fill in the required details to proceed with your class booking.', 'error-message');
- }
- }
- });
- // Helpers
- // Helpers
- const helpers = {
- setSystemMessage: function (mess, type=null) {
- let systemMessageEl = document.querySelector('.booking-system-message');
- systemMessageEl.innerHTML = mess ? `<div class="${type || ``} custom-container w-100 ml-auto mr-auto side-padding alert alert-warning"><i class="fas fa-bell mr-2 color-dark"></i> ${mess}</div>` : null;
- }
- }
- </script>
- <script type="text/javascript">
- $('#date').on("change", function() {
- setTimeout(function() {
- let totalStills = JSON.parse(sessionStorage.getItem('bookingData')).totalStills;
- var courseDate = $('#date').val();
- $.ajax({
- type: "POST",
- url: "{{ route('fetchBookings') }}",
- data: {
- "_token": "{{ csrf_token() }}",
- courseDate: courseDate
- },
- success: function(response) {
- let dates = JSON.parse(response);
- //console.log(dates)
- if(dates.length < 1) {
- //console.log('update inner with blank', document.querySelector("#carouselBookingDates"))
- document.querySelector("#carouselBookingDates").innerHTML = `
- <div class="carousel-inner">
- <div class="carousel-item active">
- <div class="p-5 text-center">
- No available booking/class as of the moment.
- </div>
- </div>
- </div>
- `;
- } else {
- // Loop data response
- let items=`
- <div class="carousel-inner">
- <div class="carousel-item active">
- <div class="btn-group btn-group-toggle" data-toggle="buttons">
- `;
- for( let i = 0; i < dates.length; i++ ) {
- //console.log('DATES: ', dates[i].fakeDate ? dates[i].fakeDate : 'excess');
- //console.log(`CHECK THIS --- ${totalStills} > ${dates[i].partyCheck}`)
- if(dates[i].description=='Course full.' || $dates[$i]['description']=='Course Full' || dates[i].description=='Booking Done' || totalStills > dates[i].partyCheck) {
- items +=`<div class="date-scroll-item d-inline" key="${i}-${dates[i].xDate}" >
- <div class="p-3 text-black-50 h-100">
- <input type="radio" name="newdate" class="newdate" value="${dates[i].xDate}" data-course-id="${dates[i].courseID}" ${dates[i].description=='Course full.' ? `disabled` : ``}>
- <div class="mb-2 pb-2 d-flex align-items-center justify-content-center">${dates[i].fakeDate}</div>
- <div class="description d-flex align-items-center justify-content-center">${dates[i].description}</div>
- </div>
- </div>`;
- } else {
- items +=`<div class="date-scroll-item d-inline" key="${i}-${dates[i].xDate}" >
- <label class="btn btn-secondary p-3 event-dates" data-current-stills="${dates[i].partyCheck}" ${dates[i].description=='Course full.' ? `disabled` : ``}>
- <input type="radio" name="newdate" class="newdate" value="${dates[i].xDate}" data-course-id="${dates[i].courseID}" ${dates[i].description=='Course full.' ? `disabled` : ``}>
- <div class="mb-2 pb-2 d-flex align-items-center justify-content-center">${dates[i].fakeDate}</div>
- <div class="description color-brown font-weight-bold d-flex align-items-center justify-content-center">${dates[i].description}</div>
- </label>
- </div>`;
- }
- if( (i+1) % 7 == 0 ) {
- items +=`
- </div>
- </div>
- <div class="carousel-item">
- <div class="btn-group btn-group-toggle" data-toggle="buttons">
- `;
- }
- }
- items+=`
- </div>
- </div>
- </div>
- `;
- if(dates.length>7) {
- items+=`
- <a class="carousel-control-prev" href="#carouselBookingDates" role="button" data-slide="prev">
- <span class="carousel-control-prev-icon" aria-hidden="true"></span>
- <span class="sr-only">Previous</span>
- </a>
- <a class="carousel-control-next" href="#carouselBookingDates" role="button" data-slide="next">
- <span class="carousel-control-next-icon" aria-hidden="true"></span>
- <span class="sr-only">Next</span>
- </a>`;
- }
- document.querySelector("#carouselBookingDates").innerHTML = items;
- }
- }
- });
- }, 300);
- });
- $('.booking__step1 label').on("click", function() {
- setTimeout(function() {
- let totalStills = JSON.parse(sessionStorage.getItem('bookingData')).totalStills;
- var courseDate = $('#date').val();
- $.ajax({
- type: "POST",
- url: "{{ route('fetchBookings') }}",
- data: {
- "_token": "{{ csrf_token() }}",
- courseDate: courseDate
- },
- success: function(response) {
- let dates = JSON.parse(response);
- //console.log(dates)
- if(dates.length < 1) {
- //console.log('update inner with blank', document.querySelector("#carouselBookingDates"))
- document.querySelector("#carouselBookingDates").innerHTML = `
- <div class="carousel-inner">
- <div class="carousel-item active">
- <div class="p-5 text-center">
- No available booking/class as of the moment.
- </div>
- </div>
- </div>
- `;
- } else {
- // Loop data response
- let items=`
- <div class="carousel-inner">
- <div class="carousel-item active">
- <div class="btn-group btn-group-toggle" data-toggle="buttons">
- `;
- for( let i = 0; i < dates.length; i++ ) {
- //console.log('DATES: ', dates[i].fakeDate ? dates[i].fakeDate : 'excess');
- //console.log(`CHECK THIS --- ${totalStills} > ${dates[i].partyCheck}`)
- if(dates[i].description=='Course full.' || dates[i].description=='Course Full' || dates[i].description=='Booking Done' || totalStills > dates[i].partyCheck) {
- items +=`<div class="date-scroll-item d-inline" key="${i}-${dates[i].xDate}" >
- <div class="p-3 text-black-50 h-100">
- <input type="radio" name="newdate" class="newdate" value="${dates[i].xDate}" data-course-id="${dates[i].courseID}" ${dates[i].description=='Course full.' ? `disabled` : ``}>
- <div class="mb-2 pb-2 d-flex align-items-center justify-content-center">${dates[i].fakeDate}</div>
- <div class="description d-flex align-items-center justify-content-center">${dates[i].description}</div>
- </div>
- </div>`;
- } else {
- items +=`<div class="date-scroll-item d-inline" key="${i}-${dates[i].xDate}" >
- <label class="btn btn-secondary p-3 event-dates" data-current-stills="${dates[i].partyCheck}" ${dates[i].description=='Course full.' ? `disabled` : ``}>
- <input type="radio" name="newdate" class="newdate" value="${dates[i].xDate}" data-course-id="${dates[i].courseID}" ${dates[i].description=='Course full.' ? `disabled` : ``}>
- <div class="mb-2 pb-2">${dates[i].fakeDate}</div>
- <div class="description color-brown font-weight-bold d-flex align-items-center justify-content-center">${dates[i].description}</div>
- </label>
- </div>`;
- }
- if( (i+1) % 7 == 0 ) {
- items +=`
- </div>
- </div>
- <div class="carousel-item">
- <div class="btn-group btn-group-toggle" data-toggle="buttons">
- `;
- }
- }
- items+=`
- </div>
- </div>
- </div>
- `;
- if(dates.length>7) {
- items+=`
- <a class="carousel-control-prev" href="#carouselBookingDates" role="button" data-slide="prev">
- <span class="carousel-control-prev-icon" aria-hidden="true"></span>
- <span class="sr-only">Previous</span>
- </a>
- <a class="carousel-control-next" href="#carouselBookingDates" role="button" data-slide="next">
- <span class="carousel-control-next-icon" aria-hidden="true"></span>
- <span class="sr-only">Next</span>
- </a>`;
- }
- document.querySelector("#carouselBookingDates").innerHTML = items;
- }
- }
- });
- }, 310);
- });
- </script>
- <script>
- $('#btnVoucherApply').on('click', function() {
- let sessionVoucherPrice = JSON.parse(sessionStorage.getItem('bookingData')).voucherDiscount.toLocaleString("en-GB", {
- style: "currency",
- currency: "GBP"
- });
- if(!document.querySelector('#vouchercode').value) {
- //console.log('no value')
- document.querySelector('.discountAmount').innerHTML = `Please enter valid code.`;
- //document.querySelector('.voucher-code-message__amount').innerHTML = sessionVoucherPrice;
- return false;
- }
- var code = $('#vouchercode').val();
- $.ajax({
- type: "post",
- url: "{{ route('validateVoucher') }}",
- data: {
- "_token": "{{ csrf_token() }}",
- code: code
- },
- success: function(response) {
- //console.log(response);
- //sessionStorage.removeItem("voucherCode");
- //sessionStorage.removeItem("voucherCodeData");
- if(response=="false"){
- sessionStorage.setItem('voucherCodeData', 0)
- document.querySelector('.discountAmount').innerHTML = `<p>To redeem your voucher, please go to: <a href="/redeem-old-voucher">Redeem Voucher</a>.</p><p>If you have any questions or concerns during your booking, you may contact us at <a href="mailto:enquiries@nelsonsdistillery.co.uk">enquiries@nelsonsdistillery.co.uk</a>.</p>`;
- let bookingData = JSON.parse(sessionStorage.getItem("bookingData"));
- bookingData.voucherDiscount = 0;
- bookingData.VoucherCheck =false;
- sessionStorage.setItem("bookingData", JSON.stringify(bookingData));
- document.querySelector("#totalAmountAfterVoucher").innerHTML = `${(bookingData.totalAmount - 0).toLocaleString("en-GB", {
- style: "currency",
- currency: "GBP"
- })}`;
- } else {
- // console.log('VALID: ', JSON.parse(response)[1])
- let bookingData = JSON.parse(sessionStorage.getItem("bookingData"));
- bookingData.voucherDiscount = parseInt(JSON.parse(response)[1]);
- bookingData.VoucherCheck = true;
- sessionStorage.setItem("bookingData", JSON.stringify(bookingData));
- let newAmount = (bookingData.totalAmount - parseInt(JSON.parse(response)[1])) > 0 ? bookingData.totalAmount - parseInt(JSON.parse(response)[1]) : 0;
- document.querySelector("#totalAmountAfterVoucher").innerHTML = `${newAmount.toLocaleString("en-GB", {
- style: "currency",
- currency: "GBP"
- })}`;
- sessionStorage.setItem('voucherCodeData', parseInt(JSON.parse(response)[1]));
- sessionStorage.setItem('voucherCode', $('#vouchercode').val());
- document.querySelector('.voucher-code-message__amount').innerHTML = `Voucher Code Discount <span class="color-green">-${JSON.parse(response)[1].toLocaleString("en-GB", {
- style: "currency",
- currency: "GBP"
- })}</span>.`;
- document.querySelector('.discountAmount').innerHTML = `<span class="color-green">- ${JSON.parse(response)[1].toLocaleString("en-GB", {
- style: "currency",
- currency: "GBP"
- })} Voucher Code Applied.</span>`;
- }
- },
- error: function() {
- helpers.setSystemMessage('Error Message: System can not confirm voucher, please contact admin.', 'error-message');
- }
- });
- });
- </script>
- <script>
- $('#date').on("change", function() {
- var courseDate = $('#date').val();
- $.ajax({
- type: "POST",
- url: "{{ route('fetchBookings') }}",
- data: {
- "_token": "{{ csrf_token() }}",
- courseDate: courseDate
- },
- success: function(response) {
- let dates = JSON.parse(response);
- //console.log(dates)
- if(dates.length < 1) {
- //console.log('update inner with blank', document.querySelector("#carouselBookingDates"))
- document.querySelector("#carouselBookingDates").innerHTML = `
- <div class="carousel-inner">
- <div class="carousel-item active">
- <div class="p-5 text-center">
- No available booking/class as of the moment.
- </div>
- </div>
- </div>
- `;
- } else {
- // Loop data response
- let items=`
- <div class="carousel-inner">
- <div class="carousel-item active">
- <div class="btn-group btn-group-toggle" data-toggle="buttons">
- `;
- for( let i = 0; i < dates.length; i++ ) {
- //console.log('DATES: ', dates[i].fakeDate ? dates[i].fakeDate : 'excess');
- if(dates[i].description=='Course full.' || dates[i].description=='Course Full' || dates[i].description=='Booking Done') {
- items +=`<div class="date-scroll-item d-inline" key="${i}-${dates[i].xDate}" >
- <div class="p-3 text-black-50">
- <input type="radio" name="newdate" class="newdate" value="${dates[i].xDate}" data-course-id="${dates[i].courseID}" ${dates[i].description=='Course full.' ? `disabled` : ``}>
- <div class="mb-2 pb-2">${dates[i].fakeDate}</div>
- <div class="description">${dates[i].description}</div>
- </div>
- </div>`;
- } else {
- items +=`<div class="date-scroll-item d-inline" key="${i}-${dates[i].xDate}" >
- <label class="btn btn-secondary p-3 event-dates" data-current-stills="${dates[i].partyCheck}" ${dates[i].description=='Course full.' ? `disabled` : ``}>
- <input type="radio" name="newdate" class="newdate" value="${dates[i].xDate}" data-course-id="${dates[i].courseID}" ${dates[i].description=='Course full.' ? `disabled` : ``}>
- <div class="mb-2 pb-2">${dates[i].fakeDate}</div>
- <div class="description mt-2 color-brown font-weight-bold">${dates[i].description}</div>
- </label>
- </div>`;
- }
- if( (i+1) % 7 == 0 ) {
- items +=`
- </div>
- </div>
- <div class="carousel-item">
- <div class="btn-group btn-group-toggle" data-toggle="buttons">
- `;
- }
- }
- items+=`
- </div>
- </div>
- </div>
- `;
- if(dates.length>7) {
- items+=`
- <a class="carousel-control-prev" href="#carouselBookingDates" role="button" data-slide="prev">
- <span class="carousel-control-prev-icon" aria-hidden="true"></span>
- <span class="sr-only">Previous</span>
- </a>
- <a class="carousel-control-next" href="#carouselBookingDates" role="button" data-slide="next">
- <span class="carousel-control-next-icon" aria-hidden="true"></span>
- <span class="sr-only">Next</span>
- </a>`;
- }
- document.querySelector("#carouselBookingDates").innerHTML = items;
- }
- }
- })
- console.log($('#date').val());
- });
- </script>
- @endsection
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement