/* * 2007-2017 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@prestashop.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA * @copyright 2007-2017 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ var current_product = null; var ajaxQueries = new Array(); $(document).ready(function() { // Init all events init(); $(document).on('click', '#view_convenience_services', function(e) { $('#convenience_services').toggle(100); $('#view_convenience_services .icon-angle-up').toggle(); $('#view_convenience_services .icon-angle-down').toggle(); }); $(document).on('click', '#view_order_tax_details', function(e) { $('#order_tax_details').toggle(100); $('#view_order_tax_details .icon-angle-up').toggle(); $('#view_order_tax_details .icon-angle-down').toggle(); }); $(document).on('click', '.delete-voucher', function(e) { if (!confirm(txt_confirm)) { e.preventDefault(); } }); $('img.js-disabled-action').css({"opacity":0.5}); // change table design for printing $(window).on('beforeprint', function() { $('#customer_cart_details thead tr th').each(function(i, val) { $('#customer_cart_details tbody td:nth-child('+(i+1)+')').each(function () { let span = $('').addClass('print-class-container') .append($('').addClass('print-class-title').html($(val).html())) .append($('').addClass('print-class-content').html( $(this).html() ) ); $(this).html($(span).html()); }); }); }); $(window).on('afterprint', function() { $('#customer_cart_details tbody td').each(function () { $(this).html($(this).find('span.print-class-content').html()); }); }); }); function stopAjaxQuery() { if (typeof(ajaxQueries) == 'undefined') ajaxQueries = new Array(); for(i = 0; i < ajaxQueries.length; i++) ajaxQueries[i].abort(); ajaxQueries = new Array(); } function updateInvoice(invoices) { // Update select on product edition line $('.edit_product_invoice').each(function() { var selected = $(this).children('option:selected').val(); $(this).children('option').remove(); for(i in invoices) { // Create new option var option = $('').attr('value', invoices[i].id); if (invoices[i].id == selected) option.attr('selected', true); $(this).append(option); } }); // Update select on product addition line $('#add_product_product_invoice').each(function() { var parent = $(this).children('optgroup.existing'); parent.children('option').remove(); for(i in invoices) { // Create new option var option = $('').attr('value', invoices[i].id); parent.append(option); } parent.children('option:first').attr('selected', true); }); // Update select on product addition line $('#payment_invoice').each(function() { $(this).children('option').remove(); for(i in invoices) { // Create new option var option = $('').attr('value', invoices[i].id); $(this).append(option); } }); } function updateDocuments(documents_html) { $('#documents_table').attr('id', 'documents_table_old'); $('#documents_table_old').after(documents_html); $('#documents_table_old').remove(); } function updateShipping(shipping_html) { $('#shipping_table').attr('id', 'shipping_table_old'); $('#shipping_table_old').after(shipping_html); $('#shipping_table_old').remove(); } function populateWarehouseList(warehouse_list) { $('#add_product_product_warehouse_area').hide(); if (warehouse_list.length > 1) { $('#add_product_product_warehouse_area').show(); } var order_warehouse_list = $('#warehouse_list').val().split(','); $('#add_product_warehouse').html(''); var warehouse_selected = false; $.each(warehouse_list, function() { if (warehouse_selected == false && $.inArray(this.id_warehouse, order_warehouse_list)) warehouse_selected = this.id_warehouse; $('#add_product_warehouse').append($('')); }); if (warehouse_selected) $('#add_product_warehouse').val(warehouse_selected); } // function editProductRefreshTotal(element) // { // element = element.parent().parent().parent(); // var element_list = []; // // Customized product // if(element.hasClass('customized')) // { // var element_list = $('.customized-' + element.find('.edit_product_id_order_detail').val()); // element = $(element_list[0]); // } // var quantity = parseInt(element.find('td .edit_product_quantity').val()); // if (quantity < 1 || isNaN(quantity)) // quantity = 1; // if (use_taxes) // var price = parseFloat(element.find('td .edit_product_price_tax_incl').val()); // else // var price = parseFloat(element.find('td .edit_product_price_tax_excl').val()) // if (price < 0 || isNaN(price)) // price = 0; // // Customized product // if (element_list.length) // { // var qty = 0; // $.each(element_list, function(i, elm) { // if($(elm).find('.edit_product_quantity').length) // { // qty += parseInt($(elm).find('.edit_product_quantity').val()); // subtotal = makeTotalProductCaculation($(elm).find('.edit_product_quantity').val(), price); // $(elm).find('.total_product').html(formatCurrency(subtotal, currency_format, currency_sign, currency_blank)); // } // }); // var total = makeTotalProductCaculation(qty, price); // element.find('td.total_product').html(formatCurrency(total, currency_format, currency_sign, currency_blank)); // element.find('td.productQuantity').html(qty); // } // else // { // var total = makeTotalProductCaculation(quantity, price); // element.find('td.total_product').html(formatCurrency(total, currency_format, currency_sign, currency_blank)); // } // } function makeTotalProductCaculation(quantity, price) { return Math.round(quantity * price * 100) / 100; } function refreshProductLineView(element, view) { var new_product_line = $(view); new_product_line.find('td').hide(); var element_list = []; if (element.parent().parent().find('.edit_product_id_order_detail').length) var element_list = $('.customized-' + element.parent().parent().find('.edit_product_id_order_detail').val()); if (!element_list.length) element_list = $(element.parent().parent()); var current_product_line = element.parent().parent(); current_product_line.replaceWith(new_product_line); element_list.remove(); new_product_line.find('td').each(function() { if (!$(this).is('.product_invoice')) $(this).fadeIn('slow'); }); } function updateAmounts(order) { $('#total_products td.amount').fadeOut('slow', function() { $(this).html(formatCurrency(parseFloat(order.total_products_wt), currency_format, currency_sign, currency_blank)); $(this).fadeIn('slow'); }); $('#total_discounts td.amount').fadeOut('slow', function() { $(this).html(formatCurrency(parseFloat(order.total_discounts_tax_incl), currency_format, currency_sign, currency_blank)); $(this).fadeIn('slow'); }); if (order.total_discounts_tax_incl > 0) $('#total_discounts').slideDown('slow'); $('#total_wrapping td.amount').fadeOut('slow', function() { $(this).html(formatCurrency(parseFloat(order.total_wrapping_tax_incl), currency_format, currency_sign, currency_blank)); $(this).fadeIn('slow'); }); if (order.total_wrapping_tax_incl > 0) $('#total_wrapping').slideDown('slow'); $('#total_shipping td.amount').fadeOut('slow', function() { $(this).html(formatCurrency(parseFloat(order.total_shipping_tax_incl), currency_format, currency_sign, currency_blank)); $(this).fadeIn('slow'); }); $('#total_order td.amount').fadeOut('slow', function() { $(this).html(formatCurrency(parseFloat(order.total_paid_tax_incl), currency_format, currency_sign, currency_blank)); $(this).fadeIn('slow'); }); $('.total_paid').fadeOut('slow', function() { $(this).html(formatCurrency(parseFloat(order.total_paid_tax_incl), currency_format, currency_sign, currency_blank)); $(this).fadeIn('slow'); }); $('.alert').slideDown('slow'); $('#product_number').fadeOut('slow', function() { var old_quantity = parseInt($(this).html()); $(this).html(old_quantity + 1); $(this).fadeIn('slow'); }); $('#shipping_table .weight').fadeOut('slow', function() { $(this).html(order.weight); $(this).fadeIn('slow'); }); } /** * This method allow to initialize all events */ function init() { $('#txt_msg').on('keyup', function(){ var length = $('#txt_msg').val().length; if (length > 600) length = '600+'; $('#nbchars').html(length+'/600'); }); $('#newMessage').unbind('click').click(function(e) { $(this).hide(); $('#message').show(); e.preventDefault(); }); $('#cancelMessage').unbind('click').click(function(e) { $('#newMessage').show(); $('#message').hide(); e.preventDefault(); }); $('select#add_product_product_attribute_id').unbind('change'); $('select#add_product_product_attribute_id').change(function() { $('#add_product_product_price_tax_incl').val(current_product.combinations[$(this).val()].price_tax_incl); $('#add_product_product_price_tax_excl').val(current_product.combinations[$(this).val()].price_tax_excl); populateWarehouseList(current_product.warehouse_list[$(this).val()]); // addProductRefreshTotal(); if (stock_management) $('#add_product_product_stock').html(current_product.combinations[$(this).val()].qty_in_stock); }); $('.edit_shipping_number_link').unbind('click').click(function(e) { $(this).parent().parent().find('.shipping_number_show').hide(); $(this).parent().find('.shipping_number_edit').show(); $(this).parent().find('.edit_shipping_number_link').hide(); $(this).parent().find('.cancel_shipping_number_link').show(); e.preventDefault(); }); $('.cancel_shipping_number_link').unbind('click').click(function(e) { $(this).parent().parent().find('.shipping_number_show').show(); $(this).parent().find('.shipping_number_edit').hide(); $(this).parent().find('.edit_shipping_number_link').show(); $(this).parent().find('.cancel_shipping_number_link').hide(); e.preventDefault(); }); $('#add_product_product_invoice').unbind('change').change(function() { if ($(this).val() == '0') $('#new_invoice').slideDown('slow'); else $('#new_invoice').slideUp('slow'); }); $('.js-set-payment').unbind('click').click(function(e) { var amount = $(this).attr('data-amount'); $('input[name=payment_amount]').val(amount); var id_invoice = $(this).attr('data-id-invoice'); $('select[name=payment_invoice] option[value='+id_invoice+']').attr('selected', true); e.preventDefault(); }); // voucher modal show and close $('#add_voucher').unbind('click').click(function(e) { e.preventDefault(); VoucherModal.show(); }); $(document).on('hidden.bs.modal', '#voucher-modal', function(){ $('#voucher-modal').remove(); }); // End: voucher modal show and close $(document).on('change','#discount_type', function(e) { // Percent type if ($(this).val() == 1) { $('#discount_value_field').show(); $('#discount_currency_sign').hide(); $('#discount_value_help').hide(); $('#discount_percent_symbol').show(); } // Amount type else if ($(this).val() == 2) { $('#discount_value_field').show(); $('#discount_percent_symbol').hide(); $('#discount_value_help').show(); $('#discount_currency_sign').show(); } // Free shipping else if ($(this).val() == 3) { $('#discount_value_field').hide(); } }); $('#discount_all_invoices').unbind('change').change(function() { if ($(this).is(':checked')) $('select[name=discount_invoice]').attr('disabled', true); else $('select[name=discount_invoice]').attr('disabled', false); }); // payment information modal show and close $('.open_payment_information').unbind('click').click(function(e) { e.preventDefault(); OrderPaymentDetailModal.show($(this)); }); $(document).on('hidden.bs.modal', '#payment-detail-modal', function(){ $('#payment-detail-modal').remove(); }); // End: payment information modal show and close initRoomEvents(); initProductEvents(); } function initProductEvents() { $('input#add_product_product_quantity').unbind('keyup').keyup(function() { if (stock_management) { var quantity = parseInt($(this).val()); if (quantity < 1 || isNaN(quantity)) quantity = 1; var stock_available = parseInt($('#add_product_product_stock').html()); // stock status update if (quantity > stock_available) $('#add_product_product_stock').css('font-weight', 'bold').css('color', 'red').css('font-size', '1.2em'); else $('#add_product_product_stock').css('font-weight', 'normal').css('color', 'black').css('font-size', '1em'); } }); $(document).on('keyup', '#add_product_product_price_tax_excl', function() { var price_tax_excl = parseFloat($(this).val()); if (price_tax_excl < 0 || isNaN(price_tax_excl)) { price_tax_excl = 0; } var tax_rate = current_product.tax_rate / 100 + 1; $('#add_product_product_price_tax_incl').val(ps_round(price_tax_excl * tax_rate, 2)); }); $(document).on('keyup', '#add_product_product_price_tax_incl', function() { var price_tax_incl = parseFloat($(this).val()); if (price_tax_incl < 0 || isNaN(price_tax_incl)) price_tax_incl = 0; var tax_rate = current_product.tax_rate / 100 + 1; $('#add_product_product_price_tax_excl').val(ps_round(price_tax_incl / tax_rate, 2)); // Update total product // addProductRefreshTotal(); }); $(document).on('keyup', '#edit_product_product_price_tax_excl', function() { var price_tax_excl = parseFloat($(this).val()); if (price_tax_excl < 0 || isNaN(price_tax_excl)) price_tax_excl = 0; var tax_rate = current_product.tax_rate / 100 + 1; $('#edit_product_product_price_tax_incl').val(ps_round(price_tax_excl * tax_rate, 2)); // Update total product // addProductRefreshTotal(); }); $(document).on('keyup', '#edit_product_product_price_tax_incl', function() { var price_tax_incl = parseFloat($(this).val()); if (price_tax_incl < 0 || isNaN(price_tax_incl)) price_tax_incl = 0; var tax_rate = current_product.tax_rate / 100 + 1; $('#edit_product_product_price_tax_excl').val(ps_round(price_tax_incl / tax_rate, 2)); // Update total product // addProductRefreshTotal(); }); $(document).on('change', '.num_occupancy', function(e) { let elementVal = parseInt($(this).val()); let current_room_occupancy = 0; $(this).closest('.occupancy_info_block').find('.num_occupancy').each(function(){ current_room_occupancy += parseInt($(this).val()); }); let max_guests_in_room = $(this).closest(".booking_occupancy_wrapper").find('.max_guests').val(); let max_allowed_for_current = (max_guests_in_room - current_room_occupancy) + parseInt($(this).val()); let haserror = false if ($(this).hasClass('num_children')) { max_child_in_room = $(this).closest(".booking_occupancy_wrapper").find('.max_children').val(); if (elementVal > max_child_in_room) { $(this).val(max_child_in_room); if (elementVal == 1) { showOccupancyError(no_children_allowed_txt, $(this).closest(".occupancy_info_block")); } else { showOccupancyError(max_children_txt, $(this).closest(".occupancy_info_block")); } } else if (elementVal > max_allowed_for_current) { $(this).val(max_allowed_for_current); showOccupancyError(max_occupancy_reached_txt, $(this).closest(".occupancy_info_block")); } } else { max_adults_in_room = $(this).closest(".booking_occupancy_wrapper").find('.max_adults').val(); if (elementVal >= max_adults_in_room) { $(this).val(max_adults_in_room); showOccupancyError(max_adults_txt, $(this).closest(".occupancy_info_block")); haserror = true; } else if (elementVal > max_allowed_for_current) { $(this).val(max_allowed_for_current); showOccupancyError(max_occupancy_reached_txt, $(this).closest(".occupancy_info_block")); haserror = true; } } if (!haserror) { if ($(this).hasClass('num_children')) { var totalChilds = $(this).closest('.occupancy_info_block').find('.guest_child_age').length; if (totalChilds < $(this).val()) { let max_child_in_room; if ($(this).closest(".booking_occupancy_wrapper").find('.max_children').val()) { max_child_in_room = $(this).closest(".booking_occupancy_wrapper").find('.max_children').val(); } else { max_child_in_room = window.max_child_in_room; } if (totalChilds < max_child_in_room) { $(this).closest('.occupancy_info_block').find('.children_age_info_block').show(); while ($(this).closest('.occupancy_info_block').find('.guest_child_age').length < $(this).val()) { var roomBlockIndex = parseInt($(this).closest('.occupancy_info_block').attr('occ_block_index')); var childAgeSelect = '

'; childAgeSelect += ''; childAgeSelect += '

'; $(this).closest('.occupancy_info_block').find('.children_ages').append(childAgeSelect); } } } else { let child = $(this).val(); $(this).closest('.occupancy_info_block').find('.guest_child_age').each(function(ind, element) { if (child <= ind) { $(element).parent().remove(); } }); if (child == 0) { $(this).closest('.occupancy_info_block').find('.children_age_info_block').hide(); } } } } setRoomTypeGuestOccupancy($(this).closest('.booking_occupancy_wrapper')); }); var errorMsgTime; $('.occupancy-input-errors').parent().hide(); function showOccupancyError(msg, occupancy_info_block) { var errorMsgBlock = $(occupancy_info_block).find('.occupancy-input-errors') $(errorMsgBlock).html(msg).parent().show('fast'); clearTimeout(errorMsgTime); errorMsgTime = setTimeout(function() { $(errorMsgBlock).parent().hide('fast'); }, 1000); } $(document).on('click', '.booking_guest_occupancy:not(.disabled)', function(e) { $(this).parent().toggleClass('open'); }); $(document).on('click', function(e) { if ($('.booking_occupancy_wrapper:visible').length) { var occupancy_wrapper = $('.booking_occupancy_wrapper:visible'); $(occupancy_wrapper).find(".occupancy_info_block").addClass('selected'); if (!($(e.target).closest(".booking_guest_occupancy").length || $(e.target).closest(".ajax_add_to_cart_button").length || $(e.target).closest(".exclusive.book_now_submit").length || $(e.target).closest(".remove-room-link").length)) { let hasErrors = 0; let adults = $(occupancy_wrapper).find(".num_adults").map(function(){return $(this).val();}).get(); let children = $(occupancy_wrapper).find(".num_children").map(function(){return $(this).val();}).get(); let child_ages = $(occupancy_wrapper).find(".guest_child_age").map(function(){return $(this).val();}).get(); // start validating above values if (!adults.length || (adults.length != children.length)) { hasErrors = 1; showErrorMessage(invalid_occupancy_txt); } else { $(occupancy_wrapper).find('.num_occupancy').removeClass('alert-danger'); // validate values of adults and children adults.forEach(function (item, index) { if (item == '' || isNaN(item) || parseInt(item) < 1) { hasErrors = 1; $(occupancy_wrapper).find(".num_adults").eq(index).closest('.occupancy_count_block').find('.num_adults').addClass('alert-danger'); } if (children[index] == '' || isNaN(children[index])) { hasErrors = 1; $(occupancy_wrapper).find(".num_children").eq(index).closest('.occupancy_count_block').find('.num_children').addClass('alert-danger'); } }); // validate values of selected child ages $(occupancy_wrapper).find('.guest_child_age').removeClass('alert-danger'); child_ages.forEach(function (age, index) { age = parseInt(age); if (isNaN(age) || (age < 0) || (age >= parseInt(max_child_age))) { hasErrors = 1; $(occupancy_wrapper).find(".guest_child_age").eq(index).addClass('alert-danger'); } }); } if (hasErrors == 0) { // Close the occupancy block only if click element is not occupancy block OR close link of the occupancy block if (!($(e.target).closest(".booking_occupancy_wrapper").length) || $(e.target).hasClass("close_occupancy_link")) { $(occupancy_wrapper).parent().removeClass('open'); $(document).trigger( "QloApps:updateRoomOccupancy", [occupancy_wrapper]); } } } } }); // Close occupancy link default redirect action prevent $(document).on('click', '.close_occupancy_link', function(e) { e.preventDefault(); }); $(document).on('click', '.booking_occupancy_wrapper .add_new_occupancy_btn', function(e) { e.preventDefault(); var booking_occupancy_wrapper = $(this).closest('.booking_occupancy_wrapper'); var roomBlockIndex = parseInt($(booking_occupancy_wrapper).find(".occupancy_info_block").last().attr('occ_block_index')); roomBlockIndex += 1; var countRooms = parseInt($(booking_occupancy_wrapper).find('.occupancy_info_block').length); countRooms += 1 var occupancy_block = ''; occupancy_block += '
'; occupancy_block += '
'; occupancy_block += '
' + remove_txt + '
'; occupancy_block += '
'; occupancy_block += '
'; occupancy_block += '
'; occupancy_block += ''; occupancy_block += ''; occupancy_block += '
'; occupancy_block += '
'; occupancy_block += ''; occupancy_block += '(' + below_txt + ' ' + max_child_age + ' ' + years_txt + ')'; occupancy_block += '
'; occupancy_block += '
'; occupancy_block += ''; occupancy_block += '
'; occupancy_block += '
'; $(booking_occupancy_wrapper).find('.booking_occupancy_inner').append(occupancy_block); setRoomTypeGuestOccupancy(booking_occupancy_wrapper); }); $(document).on('click', '.booking_occupancy_wrapper .remove-room-link', function(e) { e.preventDefault(); booking_occupancy_inner = $(this).closest('.booking_occupancy_inner'); $(this).closest('.occupancy_info_block').remove(); $(booking_occupancy_inner).find('.room_num_wrapper').each(function(key, val) { $(this).text(room_txt + ' - '+ (key+1) ); }); setRoomTypeGuestOccupancy($(booking_occupancy_inner).closest('.booking_occupancy_wrapper')); }); $('.delete_product_line').unbind('click').click(function(e) { if (!confirm(txt_confirm)) return false; var tr_product = $(this).closest('.product-line-row'); var id_order_detail = $(this).closest('.product-line-row').data('id_order_detail'); var id_service_product_order_detail = $(this).closest('.product-line-row').data('id_service_product_order_detail'); var query = 'ajax=1&action=deleteProductLine&token='+token+'&id_order_detail='+id_order_detail+'&id_order='+id_order+'&id_service_product_order_detail='+id_service_product_order_detail; var id_hotel = $(this).closest('.product-line-row').data('id_hotel'); if (id_hotel) { query += '&id_hotel='+id_hotel; } $.ajax({ type: 'POST', url: admin_order_tab_link, cache: false, dataType: 'json', data : query, success : function(data) { if (data.status) { window.location.href = admin_order_tab_link + '&conf=1&vieworder&id_order=' + id_order; } else { showErrorMessage(data.error); } } }); e.preventDefault(); }); } function initRoomEvents() { $('#cancelAddProduct').unbind('click').click(function() { if (!($('#customer_products_details tbody tr').length > 1)) { $('#customer_products_details').hide(); } }); $(document).on('click', '#submitAddRoom', function(e) { e.preventDefault(); stopAjaxQuery(); var go = true; if ($('input#add_product_product_id').val() == 0) { jAlert(txt_add_product_no_product); go = false; } if ($('input#add_product_product_quantity').val() == 0) { jAlert(txt_add_product_no_product_quantity); go = false; } if ($('input#add_product_product_price_excl').val() == 0) { jAlert(txt_add_product_no_product_price); go = false; } if (go) { if (parseInt($('input#add_product_product_quantity').val()) > parseInt($('#add_product_product_stock').html())) go = confirm(txt_add_product_stock_issue); if (go && $('select#add_product_product_invoice').val() == 0) go = confirm(txt_add_product_new_invoice); if (go) { $('.submitAddRoom').attr('disabled', true); $('#submitAddRoom').attr('disabled', true); var query = 'ajax=1&token='+token+'&action=addRoomOnOrder&id_order='+id_order+'&'; // query += $('#add_product_warehouse').serialize()+'&'; query += $('#new_room select, #new_room input ,#new_room textarea').serialize(); if ($('select#add_product_product_invoice').val() == 0) query += '&'+$('tr#new_invoice select, tr#new_invoice input').serialize(); $(".loading_overlay").show(); var ajax_query = $.ajax({ type: 'POST', url: admin_order_tab_link, cache: false, dataType: 'json', data : query, success : function(data) { if (data.result) { window.location.href = admin_order_tab_link + '&conf=3&vieworder&id_order=' + id_order; //commented by webkul /*updateAmounts(data.order); updateInvoice(data.invoices); updateDocuments(data.documents_html); updateShipping(data.shipping_html);*/ //End // $('.partial_refund_fields').hide(); } else { jAlert(data.error); $('.submitAddRoom').removeAttr('disabled'); $('#submitAddRoom').removeAttr('disabled'); } }, error : function(XMLHttpRequest, textStatus, errorThrown) { jAlert("Impossible to add the room to the cart.\n\ntextStatus: '" + textStatus + "'\nerrorThrown: '" + errorThrown + "'\nresponseText:\n" + XMLHttpRequest.responseText); }, complete: function() { $(".loading_overlay").hide(); } }); ajaxQueries.push(ajax_query); } } }); $(document).on('click', '#submitAddProduct', function(e) { e.preventDefault(); stopAjaxQuery(); var hasErrors = false; if ($('input#add_product_product_id').val() == 0) { showErrorMessage(txt_add_product_no_product); hasErrors = true; } if ($('input#add_product_product_quantity').val() == 0) { showErrorMessage(txt_add_product_no_product_quantity); hasErrors = true; } if ($('input#add_product_product_price_excl').val() == 0) { showErrorMessage(txt_add_product_no_product_price); hasErrors = true; } if (!hasErrors) { if (parseInt($('input#add_product_product_quantity').val()) > parseInt($('#add_product_product_stock').html())) { hasErrors = confirm(txt_add_product_stock_issue); } if (!hasErrors && $('select#add_product_product_invoice').val() == 0) { hasErrors = confirm(txt_add_product_new_invoice); } if (!hasErrors) { $('.submitAddProduct').attr('disabled', true); $('#submitAddProduct').attr('disabled', true); var query = 'ajax=1&token='+token+'&action=addProductOnOrder&id_order='+id_order+'&'; query += $('#new_product select, #new_product input').serialize(); if ($('select#add_product_product_invoice').val() == 0) query += '&'+$('tr#new_invoice select, tr#new_invoice input').serialize(); $(".loading_overlay").show(); var ajax_query = $.ajax({ type: 'POST', url: admin_order_tab_link, cache: false, dataType: 'json', data : query, success : function(data) { if (data.status) { // if new order is created for the stanalone product then redirect to the new order for that product // else reload the current order if (typeof(data.new_id_order) !== 'undefined' && data.new_id_order) { window.location.href = admin_order_tab_link + '&conf=3&vieworder&id_order=' + data.new_id_order; } else { window.location.href = admin_order_tab_link + '&conf=3&vieworder&id_order=' + id_order; } } else { showErrorMessage(data.error); } }, error : function(XMLHttpRequest, textStatus, errorThrown) { showErrorMessage("Impossible to add the room to the cart.\n\ntextStatus: '" + textStatus + "'\nerrorThrown: '" + errorThrown + "'\nresponseText:\n" + XMLHttpRequest.responseText); }, complete: function() { $('.submitAddProduct').removeAttr('disabled'); $('#submitAddProduct').removeAttr('disabled'); $(".loading_overlay").hide(); } }); ajaxQueries.push(ajax_query); } } }); var DeleteRoomBookingModal = { show: function(data) { $(".loading_overlay").show(); // Remove any previous modal to avoid duplicate IDs/handlers if ($('#delete-room-booking-modal').length) { $('#delete-room-booking-modal').remove(); $('.modal-backdrop').remove(); $('body').removeClass('modal-open'); } $.ajax({ type: 'POST', url: admin_order_tab_link, dataType: 'json', data: $.extend({ ajax: true, action: 'initDeleteRoomBookingModal' }, data), beforeSend: function () { $("#page-loader").show(); }, success: function (result) { if (!result.hasError && result.modalHtml) { $('#footer').next('.bootstrap').append(result.modalHtml); $('#delete-room-booking-modal').modal('show'); $('#delete-room-booking-modal').on('hidden.bs.modal', function() { $(this).remove(); }); } else if (result.error) { showErrorMessage(result.error); } }, complete: function () { $(".loading_overlay").hide(); $("#page-loader").hide(); } }); }, close: function() { $('#delete-room-booking-modal').modal('hide'); } }; $(document).off('click', '.delete_room_line').on('click', '.delete_room_line', function(e) { e.preventDefault(); var tr_product = $(this).closest('.product-line-row'); var data = { id_room : tr_product.data('id_room'), id_product : tr_product.data('id_product'), id_hotel : tr_product.data('id_hotel'), date_from : tr_product.data('date_from'), date_to : tr_product.data('date_to'), id_order_detail : tr_product.data('id_order_detail'), id_htl_booking : tr_product.data('id_htl_booking'), id_order : id_order }; DeleteRoomBookingModal.show(data); }); $(document).off('click', '#submitRoomDelete').on('click', '#submitRoomDelete', function(e) { e.preventDefault(); var remark = $('#room_remark').val().trim(); if (remark === '') { $('#remarkGroup').addClass('has-error'); $('#room_remark').focus(); return false; } var id_room = $('input[name="id_room"]').val(); var id_product = $('input[name="id_product"]').val(); var id_hotel = $('input[name="id_hotel"]').val(); var date_from = $('input[name="date_from"]').val(); var date_to = $('input[name="date_to"]').val(); var id_order_detail = $('input[name="id_order_detail"]').val(); var id_htl_booking = $('input[name="id_htl_booking"]').val(); var id_order = $('input[name="id_order"]').val(); var query = 'ajax=1&action=deleteRoomLine&token='+token+'&id_order='+id_order+'&id_htl_booking='+id_htl_booking+'&id_room='+id_room+'&id_product='+id_product+'&id_hotel='+id_hotel+'&date_from='+date_from+'&date_to='+date_to+'&id_order_detail='+id_order_detail; query += '&' + $(this).closest('.modal-content').find('input, select:visible, textarea').serialize(); $.ajax({ type: 'POST', url: admin_order_tab_link, cache: false, dataType: 'json', data: query, success: function(data) { if (data.result) { updateAmounts(data.order); updateInvoice(data.invoices); updateDocuments(data.documents_html); window.location.href = admin_order_tab_link + '&conf=1&vieworder&id_order=' + data.order.id; } else { jAlert(data.error); } } }); }); // order-payment-modal hide and show $('#add_new_payment').on('click', function(e) { e.preventDefault(); OrderPaymentModal.show(); }); $(document).on('hidden.bs.modal', '#order-payment-modal', function(){ $('#order-payment-modal').remove(); }); $('#cancle_add_payment').on('click', function(e) { e.preventDefault(); OrderPaymentModal.hide(); }); // end order-payment-modal hide and show } function setRoomTypeGuestOccupancy(booking_occupancy_wrapper) { var adults = 0; var children = 0; var rooms = $(booking_occupancy_wrapper).find('.occupancy_info_block').length; $(booking_occupancy_wrapper).find(".num_adults" ).each(function(key, val) { adults += parseInt($(this).val()); }); $(booking_occupancy_wrapper).find(".num_children" ).each(function(key, val) { children += parseInt($(this).val()); }); var guestButtonVal = parseInt(adults) + ' '; if (parseInt(adults) > 1) { guestButtonVal += adults_txt; } else { guestButtonVal += adult_txt; } if (parseInt(children) > 0) { if (parseInt(children) > 1) { guestButtonVal += ', ' + parseInt(children) + ' ' + children_txt; } else { guestButtonVal += ', ' + parseInt(children) + ' ' + child_txt; } } if (parseInt(rooms) > 1) { guestButtonVal += ', ' + parseInt(rooms) + ' ' + rooms_txt; } $(booking_occupancy_wrapper).siblings('.booking_guest_occupancy').find('span').text(guestButtonVal); } /* Refund system script */ var flagRefund = ''; // when submit from ajax from guest address controller the function will be called from the controller header function getSummary() { return; } $(document).ready(function() { // when click edit/add guest address we have to initialize fancybox $('.fancybox').fancybox({ 'type': 'iframe', 'width': '90%', 'height': '90%', afterClose: function() { location.reload(); }, }); // when changing order state to Refund, show the booking/product selection // modal first — Cancelled is no longer handled here, cancelling a booking // only happens through Room Status now $(document).on('change', '#id_order_state', function(e) { if ($(this).val() == PS_OS_REFUND) { e.preventDefault(); CancelRoomBookingModal.show(); } }); $('#desc-order-partial_refund').click(function() { $('.cancel_product_change_link:visible').trigger('click'); if (flagRefund == 'partial') { flagRefund = ''; $('.partial_refund_fields').hide(); } else { flagRefund = 'partial'; $('.product_action').hide(); $('.product_action').hide(); $('.partial_refund_fields').fadeIn(); } if (order_discount_price) actualizeRefundVoucher(); }); // click on back button on created extra service edit $(document).on('click', '#back_to_service_btn', function() { $('.room_ordered_services').show(); $('#btn_new_existing_room_service').show(); $('#btn_new_room_service').show(); $('#add_existing_room_services_form').hide(); $('#add_new_room_services_form').hide(); $('#save_service_service').hide(); $('#back_to_service_btn').hide(); }); // Start: New custom service oprations $(document).on('click', '#btn_new_existing_room_service', function() { $('#add_existing_room_services_form').show(); $('#add_new_room_services_form').hide(); $('#save_service_service').show(); $('#back_to_service_btn').show(); $('.room_ordered_services').hide(); $('#btn_new_existing_room_service').hide(); $('#btn_new_room_service').hide(); $('#add_new_room_services_form').hide(); }); // Add new custom service: Show hide new custom service form $(document).on('click', '#btn_new_room_service', function() { $('#add_existing_room_services_form').hide(); $('#add_new_room_services_form').show(); $('#add_new_room_services_form').show(); $('#back_to_service_btn').show(); $('.room_ordered_services').hide(); $('#btn_new_existing_room_service').hide(); $('#btn_new_room_service').hide(); }); $(document).on('change', '#add_new_room_services_form select[name="price_calculation_type"]', function() { if ($(this).val() == new_service_pcm_once_for_booking) { $('#new_service_pcm_days_container').hide(); } else { $('#new_service_pcm_days_container').show(); } }); // Add new custom service: change auto added option $(document).on('change', '#add_new_room_services_form input[name="new_service_auto_added"]', function() { var room_type_tax_rule_group_exist = $("#room_type_tax_rule_group_exist").val(); if ($(this).val() == 1) { $("#new_service_price_addition_type_container").show(); $("#new_service_qty_container").hide(); if (room_type_tax_rule_group_exist) { $("#new_service_price_tax_rule_container").hide(); } } else { $("#new_service_price_addition_type_container").hide(); $("#new_service_qty_container").show(); $("#new_service_price_tax_rule_container").show(); } }); // Add new custom service to the room $(document).on('submit', '#add_new_room_services_form', function(e) { e.preventDefault(); var form_data = new FormData(this); form_data.append('ajax', true); form_data.append('action', 'addNewRoomServices'); $(".loading_overlay").show(); $.ajax({ type: 'POST', headers: { "cache-control": "no-cache" }, url: admin_order_tab_link, dataType: 'JSON', cache: false, data: form_data, processData: false, contentType: false, success: function(jsonData) { if (!jsonData.hasError) { if (jsonData.service_panel) { $('#room_type_service_product_desc').replaceWith(jsonData.service_panel); initUITooltip(); } showSuccessMessage(txtExtraServiceSucc); } else { var errorHtml = error_found_txt + ':
'; errorHtml += '
    '; $.each(jsonData.errors, function(key, errorMsg) { errorHtml += '
  1. ' + errorMsg + '
  2. '; }); errorHtml += '
'; showErrorMessage(errorHtml); } }, complete: function() { $(".loading_overlay").hide(); } }); }); // End: New custom service oprations $(document).on('change', '#edit-room-booking-modal .room_ordered_services .qty', function(e) { let quantityInputField = this; let maximumQuantity = parseInt($(quantityInputField).attr('data-max-quantity')); let currentQuantity = parseInt($(quantityInputField).val()); if (currentQuantity > maximumQuantity) { $(quantityInputField).siblings('p').show(); } else { $(quantityInputField).siblings('p').hide(); } }); $(document).on('focusout', '#edit-room-booking-modal #add_existing_room_services_form .qty', function(e) { var qty_wntd = $(this).val(); if (qty_wntd == '' || !$.isNumeric(qty_wntd) || qty_wntd < 1) { $(this).val(1); } }); // Add existing available service to the room $(document).on('submit', '#add_existing_room_services_form', function(e) { e.preventDefault(); var form_data = new FormData(this); form_data.append('ajax', true); form_data.append('action', 'addExistingRoomServices'); $(".loading_overlay").show(); $.ajax({ type: 'POST', headers: { "cache-control": "no-cache" }, url: admin_order_tab_link, dataType: 'JSON', cache: false, data: form_data, processData: false, contentType: false, success: function(jsonData) { if (!jsonData.hasError) { if (jsonData.service_panel) { $('#room_type_service_product_desc').replaceWith(jsonData.service_panel); initUITooltip(); } showSuccessMessage(txtExtraServiceSucc); } else { showErrorMessage(jsonData.errors); } }, complete: function() { $(".loading_overlay").hide(); } }); }); $(document).on('submit', '#update_selected_room_services_form', function(e) { e.preventDefault(); var form_data = new FormData(this); form_data.append('ajax', true); form_data.append('action', 'updateSelectedRoomServices'); $(".loading_overlay").show(); $.ajax({ type: 'POST', headers: { "cache-control": "no-cache" }, url: admin_order_tab_link, dataType: 'JSON', cache: false, data: form_data, processData: false, contentType: false, success: function(jsonData) { if (!jsonData.hasError) { if (jsonData.service_panel) { $('#room_type_service_product_desc').replaceWith(jsonData.service_panel); } showSuccessMessage(txtExtraServiceSucc); } else { if (jsonData.errors != 'undefined' && jsonData.errors.length) { var errorHtml = error_found_txt + ':
'; errorHtml += '
    '; $.each(jsonData.errors, function(key, errorMsg) { errorHtml += '
  1. ' + errorMsg + '
  2. '; }); errorHtml += '
'; showErrorMessage(errorHtml); } } }, complete: function() { $(".loading_overlay").hide(); } }); }); $(document).on('click', '.del_room_additional_service', function(e){ e.preventDefault(); if (confirm(txt_confirm)) { var idServiceProductOrderDetail = $(this).data('id_service_product_order_detail'); $currentItem = $(this); if (idServiceProductOrderDetail) { $(".loading_overlay").show(); $.ajax({ type: 'POST', headers: { "cache-control": "no-cache" }, url: admin_order_tab_link, dataType: 'JSON', cache: false, data: { id_service_product_order_detail: idServiceProductOrderDetail, action: 'DeleteRoomAdditionalService', ajax: true }, success: function(jsonData) { if (!jsonData.hasError) { if (jsonData.service_panel) { $('#room_type_service_product_desc').replaceWith(jsonData.service_panel); } showSuccessMessage(txtExtraServiceSucc); } else { showErrorMessage(jsonData.errors); } }, complete: function() { $(".loading_overlay").hide(); } }); } else { showErrorMessage(txtInvalidDemandVal); } } }); // change advance option of extra demand $(document).on('change', '.demand_adv_option_block .id_option', function(e) { var option_selected = $(this).find('option:selected'); var extra_demand_price = option_selected.attr("optionPrice") extra_demand_price = parseFloat(extra_demand_price); // extra_demand_price = formatCurrency(extra_demand_price, currency_format, currency_sign, currency_blank); $(this).closest('.room_demand_block').find('.unit_price').val(extra_demand_price); }); $(".textarea-autosize").autosize(); var date = new Date(); var hours = date.getHours(); if (hours < 10) hours = "0" + hours; var mins = date.getMinutes(); if (mins < 10) mins = "0" + mins; var secs = date.getSeconds(); if (secs < 10) secs = "0" + secs; $('.datepicker').datetimepicker({ prevText: '', nextText: '', dateFormat: 'yy-mm-dd', timeFormat: 'hh:mm:ss', }); // open modal to show extra services of the rooms $(document).on('click', '.open_room_extra_services', function(e) { e.preventDefault(); var idProduct = $(this).attr('id_product'); var idOrder = $(this).attr('id_order'); var idRoom = $(this).attr('id_room'); var dateFrom = $(this).attr('date_from'); var dateTo = $(this).attr('date_to'); var idHtlBooking = $(this).attr('id_htl_booking'); var orderEdit = 0; $(".loading_overlay").show(); $.ajax({ type: 'POST', headers: { "cache-control": "no-cache" }, url: admin_order_tab_link, dataType: 'JSON', cache: false, data: { id_room: idRoom, id_product: idProduct, id_order: idOrder, date_from: dateFrom, date_to: dateTo, id_htl_booking: idHtlBooking, orderEdit: orderEdit, action: 'getRoomTypeBookingServices', ajax: true }, success: function(result) { if (result.hasError == 1) { showErrorMessage(txtSomeErr); } else { $('#footer').next('.bootstrap').append(result.modalHtml); $('#room-extra-services').modal('show'); } }, complete: function() { $(".loading_overlay").hide(); initUITooltip(); } }); }); // Empty extra-services-container when room-extra-services modal is closed $(document).on('hidden.bs.modal', '#room-extra-services', function(){ $('#footer').next('.bootstrap').empty(); }); $(document).on('click', '.reallocate_overbooking', function(e) { e.preventDefault(); $('#reallocate_room_' + $(this).attr('id_htl_booking')).trigger('click'); }); // BookingDocumentsModal : Room Booking Document processing $(document).on('click', '#booking-documents-modal .btn-add-new-document', function() { BookingDocumentsModal.addNew(); BookingDocumentsForm.addNew(); }); $(document).on('click', '#booking-documents-modal [data-dismiss="alert"]', function() { BookingDocumentsModal.hideErrors(); }); $(document).on('change', '.input-booking-document', function(e) { e.preventDefault(); if (!this.files.length) { $(this).remove(); return; } BookingDocumentsForm.updatePreview(); }); $(document).on('click', '#form-add-new-document .btn-add-file', function(e) { e.preventDefault(); BookingDocumentsForm.openFileChooser(); }); $(document).on('click', '#form-add-new-document .btn-group-add-new .cancel', function(e) { e.preventDefault(); BookingDocumentsForm.close(); BookingDocumentsModal.enableAddNewButton(); }); $(document).on('click', '.submitDocument', function(e) { e.preventDefault(); BookingDocumentsModal.uploadDocument(); }); $(document).on('click', '#booking-documents-modal .documents-list .btn-delete-document', function(e) { e.preventDefault(); if (confirm(txt_booking_document_delete_confirm)) { BookingDocumentsModal.deleteDocument(this); } }); // Reload when modal is closed to update the number of documents $(document).on('hidden.bs.modal', '#booking-documents-modal', function(){ location.reload(); }); // END: BookingDocumentsModal: Processes // ====================================== // Start: VoucherModal: Processes $(document).on('click', '.submitVoucher', function(e) { e.preventDefault(); VoucherModal.submit(); }); // End: VoucherModal: Processes // ====================================== // Start: OrderPaymentModal: Processes $(document).on('click', '.submitOrderPayment', function(e) { e.preventDefault(); OrderPaymentModal.submit(); }); // End: OrderPaymentModal: Processes // ====================================== // Start: DocumentNoteModal: Processes $(document).on('click', '.add_document_note', function(e) { e.preventDefault(); DocumentNoteModal.show($(this)); }); $(document).on('hidden.bs.modal', '#document-note-modal', function(){ $('#document-note-modal').remove(); }); $(document).on('click', '.submitDocumentNote', function(e) { e.preventDefault(); DocumentNoteModal.submit(); }); // End: DocumentNoteModal: Processes // ====================================== // Start: TravellerModal: Processes // for updating (Traveller) customer guest details $(document).on('click', '#edit_guest_details', function(e) { e.preventDefault(); TravellerModal.show(); }); $(document).on('hidden.bs.modal', '#traveller-modal', function(){ $('#traveller-modal').remove(); }); $(document).on('click', '.submitTravellerInfo', function(e) { e.preventDefault(); TravellerModal.submit(); }); // End: TravellerModal: Processes // ====================================== // Start: RoomStatusModal: Processes // for updating Room status // toggle date input of check-in checkout dates as per status selected $(document).on('change', '.booking_order_status', function() { var $select = $(this); var status = $select.val(); var $form = $select.closest('.room_status_info_form'); if (status == ROOM_STATUS_CHECKED_IN || status == ROOM_STATUS_CHECKED_OUT) { $form.find('.room_status_date').closest('.form-group').show(); var currentStatus = $form.data('current_status'); var hasCheckedIn = currentStatus == ROOM_STATUS_CHECKED_IN || currentStatus == ROOM_STATUS_CHECKED_OUT; var hasCheckedOut = currentStatus == ROOM_STATUS_CHECKED_OUT; if (status == ROOM_STATUS_CHECKED_OUT) { $form.find('.room_status_date').val(hasCheckedOut ? $form.data('check_out') : $form.find('[name="date_to"]').val() + ' ' + $form.data('check_out_time')); } else { $form.find('.room_status_date').val(hasCheckedIn ? $form.data('check_in') : $form.find('[name="date_from"]').val() + ' ' + $form.data('check_in_time')); } } else { $form.find('.room_status_date').closest('.form-group').hide(); } }); // open date picker for the date input of check-in checkout dates $(document).on('focus', '.room_status_date', function() { var $input = $(this); var dateFrom = $input.closest('.room_status_info_form').find('[name="date_from"]').val(); minDate = new Date(dateFrom+'T00:00:00'); var dateTo = $input.closest('.room_status_info_form').find('[name="date_to"]').val(); maxDate = new Date(dateTo+'T23:59:59'); $input.datetimepicker({ dateFormat: 'yy-mm-dd', timeFormat: 'hh:mm', minDate: minDate, maxDate: maxDate, dayNamesMin: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] }); }); $(document).on('click', '.open_room_status_form', function(e) { e.preventDefault(); RoomStatusModal.show($(this)); }); $(document).on('hidden.bs.modal', '#room-status-modal', function(){ $('#room-status-modal').remove(); }); $(document).on('click', '.submitRoomStatus', function(e) { e.preventDefault(); var status = $('#room-status-modal .booking_order_status').val(); if ((status == ROOM_STATUS_NO_SHOW || status == ROOM_STATUS_CANCELLED) && !confirm(room_status_sealed_warning_txt)) { return; } RoomStatusModal.submit(); }); // End: RoomStatusModal: Processes // ====================================== // Start: RoomAllotmentCommentModal: Processes $(document).on('click', '.manual_allotment_comment', function(e){ e.preventDefault(); RoomAllotmentCommentModal.show(this); }); $(document).on('hidden.bs.modal', '#room-allotment-comment-modal', function(){ $('#room-allotment-comment-modal').remove(); }); // End: RoomAllotmentCommentModal: Processes // ====================================== // Start: AddRoomBookingModal: Processes /*For adding rooms to the order*/ $(document).on('click', '#add_room', function(e){ e.preventDefault(); AddRoomBookingModal.show(); }); $(document).on('click', '.submitAddRoom', function(e){ e.preventDefault(); AddRoomBookingModal.submit(); }); $(document).on('shown.bs.modal', '#add-room-booking-modal', function(){ $('#new_room #add_product_product_name').focus(); }); $(document).on('show.bs.modal', '#add-room-booking-modal', function(){ if ($('#new_room #add_product_product_id').val() == 0) { $('.submitAddRoom').attr('disabled', true); } }); $(document).on('hidden.bs.modal', '#add-room-booking-modal', function(){ $('#add-room-booking-modal').remove(); }); // End: AddRoomBookingModal: Processes // ====================================== // Start: EditRoomBookingModal: Processes $(document).on('click', '.edit_room_change_link', function(e){ e.preventDefault(); EditRoomBookingModal.show(this); }); // submit room edit $(document).on('click', '#submitRoomChange', function(e) { e.preventDefault(); if (confirm(txt_confirm)) { let query = 'ajax=1&token='+token+'&action=editRoomOnOrder&'+ $('#edit_product').find('input, select ,textarea').serialize(); $(".loading_overlay").show(); $.ajax({ type: 'POST', url: admin_order_tab_link, cache: false, dataType: 'json', data : query, success : function(data) { if (data.result) { init(); window.location.href = admin_order_tab_link + '&conf=4&vieworder&id_order=' + data.order.id; } else { jAlert(data.error); } }, complete : function(data) { $(".loading_overlay").hide(); } }); } return false; }); $(document).on('hidden.bs.modal', '#edit-room-booking-modal', function(){ location.reload(); }); // End: EditRoomBookingModal: Processes // ====================================== // Start: CancelRoomBookingModal: Processes $(document).on('click', '#page-header-desc-order-cancel', function(e) { e.preventDefault(); CancelRoomBookingModal.show(); }); $(document).on('hidden.bs.modal', '#cancel-room-booking-modal', function(){ $('#cancel-room-booking-modal').remove(); }); $(document).on('click', '.submitCancelBooking', function(e) { e.preventDefault(); CancelRoomBookingModal.submit(); }); $(document).on('click', '#initiateRefund', function(e) { if ($(this).data('submitted')) { return false; } if ($.trim($('.cancellation_reason').val()) == '') { $('.cancellation_reason').focus().css('border', '1px solid red'); return false; } $(this).data('submitted', true); }); // End: CancelRoomBookingModal: Processes // ====================================== // Start: AddProductModal: Processes /*For adding product to the order*/ $(document).on('click', '#add_product', function(e){ e.preventDefault(); AddProductModal.show(); }); $(document).on('click', '.submitAddProduct', function(e){ e.preventDefault(); AddProductModal.submit(); }); // $(document).on('shown.bs.modal', '#add-room-booking-modal', function(){ // $('#new_room #add_product_product_name').focus(); // }); $(document).on('show.bs.modal', '#add-product-modal', function(){ if ($('#new_room #add_product_product_id').val() == 0) { $('.submitAddProduct').attr('disabled', true); } }); $(document).on('hidden.bs.modal', '#add-product-modal', function(){ $('#add-product-modal').remove(); }); // End: AddProductModal: Processes // ====================================== // Start: EditProductModal: Processes /*For editing product to the order*/ $(document).on('click', '.edit_product_change_link', function(e){ e.preventDefault(); EditProductModal.show(this); }); $(document).on('click', '.submitEditProduct', function(e){ e.preventDefault(); if (confirm(txt_confirm)) { let query = 'ajax=1&token='+token+'&action=editProductOnOrder&'+ $('#edit_product').find('input, select').serialize(); $(".loading_overlay").show(); $.ajax({ type: 'POST', url: admin_order_tab_link, cache: false, dataType: 'json', data : query, success : function(data) { if (data.status) { window.location.href = admin_order_tab_link + '&conf=4&vieworder&id_order=' + id_order; } else { showErrorMessage(data.error); } }, complete : function(data) { $(".loading_overlay").hide(); } }); } return false; }); // submit room edit $(document).on('click', '#submitProduct', function(e) { e.preventDefault(); if (confirm(txt_confirm)) { // let query = 'ajax=1&token='+token+'&action=editRoomOnOrder&'+ // $('#edit_product').find('input, select').serialize(); // $(".loading_overlay").show(); // $.ajax({ // type: 'POST', // url: admin_order_tab_link, // cache: false, // dataType: 'json', // data : query, // success : function(data) { // if (data.result) { // init(); // window.location.href = admin_order_tab_link + '&conf=4&vieworder&id_order=' + data.order.id; // } else { // jAlert(data.error); // } // }, // complete : function(data) { // $(".loading_overlay").hide(); // } // }); } return false; }); $(document).on('hidden.bs.modal', '#edit-product-modal', function(){ location.reload(); }); // End: EditProductModal: Processes // ====================================== }); // Modal object to handle booking documents processes const BookingDocumentsModal = { init: function(idHtlBooking, $this) { $(".loading_overlay").show(); $.ajax({ type: 'POST', headers: { "cache-control": "no-cache" }, url: admin_order_tab_link, dataType: 'JSON', cache: false, data: 'ajax=true&id_order='+id_order+'&action=InitBookingDocumentsModal', beforeSend: function() { $("#page-loader").show(); }, success: function(result) { if (result.hasError == 0 && result.modalHtml) { $('#footer').next('.bootstrap').append(result.modalHtml); BookingDocumentsModal.currentTr = $this; $('#booking-documents-modal .documents-list').find('[name="id_hotel_booking"]').val(idHtlBooking); BookingDocumentsForm.init(); BookingDocumentsModal.reset(); BookingDocumentsModal.show(idHtlBooking); } else { showErrorMessage(txtSomeErr); } }, complete: function() { $(".loading_overlay").hide(); $("#page-loader").hide(); } }); }, reset: function() { $('#booking-documents-modal .documents-list table tbody').html(''); }, show: function(idHtlBooking) { $('#form-add-new-document').find('[name="id_htl_booking"]').attr('value', idHtlBooking); let data = { ajax: true, action: 'getBookingDocuments', id_htl_booking: parseInt(idHtlBooking), }; $(".loading_overlay").show(); $.ajax({ url: admin_order_tab_link, data: data, type: 'POST', dataType: 'JSON', success: function(response) { if (response.status) { BookingDocumentsModal.setBodyHtml(response.html); } }, complete: function() { $(".loading_overlay").hide(); } }); $('#booking-documents-modal').modal('show'); }, setBodyHtml: function(html) { $('#booking-documents-modal .documents-list table tbody').html(html); }, close: function() { $('#booking-documents-modal').modal('hide'); }, addNew: function() { BookingDocumentsModal.hideErrors(); BookingDocumentsModal.hideAddNewButton(); }, beforeSubmit: function(cb) { BookingDocumentsModal.hideErrors(cb); }, uploadDocument: function() { BookingDocumentsModal.beforeSubmit(function() { let formData = new FormData($('form#form-add-new-document').get(0)); formData.append('ajax', true); formData.append('action', 'uploadBookingDocument'); $(".loading_overlay").show(); $.ajax({ url: admin_order_tab_link, data: formData, processData: false, contentType: false, type: 'POST', success: function(response) { let jsonResponse = JSON.parse(response); if (jsonResponse.status) { showSuccessMessage(txt_booking_document_upload_success); BookingDocumentsModal.reset(); BookingDocumentsForm.reset(); BookingDocumentsForm.resetPreview(); BookingDocumentsModal.setBodyHtml(jsonResponse.html); BookingDocumentsModal.setDocumentsCount(jsonResponse.num_checkin_documents); } else { BookingDocumentsModal.showErrors(jsonResponse.errors); } }, complete: function() { $(".loading_overlay").hide(); } }); }); }, deleteDocument: function($this) { BookingDocumentsModal.beforeSubmit(function() { let idHtlBookingDocument = parseInt($($this).attr('data-id-htl-booking-document')); let data = { ajax: true, action: 'deleteBookingDocument', id_htl_booking_document: idHtlBookingDocument, }; $(".loading_overlay").show(); $.ajax({ url: admin_order_tab_link, data: data, type: 'POST', dataType: 'JSON', success: function(response) { if (response.status) { BookingDocumentsModal.setBodyHtml(response.html); BookingDocumentsModal.setDocumentsCount(response.num_checkin_documents); showSuccessMessage(txt_booking_document_delete_success); } else { BookingDocumentsModal.showErrors(response.errors); } }, complete: function() { $(".loading_overlay").hide(); } }); }); }, showErrors: function(errors) { $('#booking-documents-modal .errors-wrap').stop().html(errors); $('#booking-documents-modal .errors-wrap').show(200); }, hideErrors: function(cb) { $('#booking-documents-modal .errors-wrap').hide(200, function() { $('#booking-documents-modal .errors-wrap').html(''); if (typeof cb === 'function') { cb(); } }); }, enableAddNewButton: function() { $('#booking-documents-modal .btn-add-new-document').show(200); }, hideAddNewButton: function() { $('#booking-documents-modal .btn-add-new-document').hide(); }, setDocumentsCount: function(count) { $(BookingDocumentsModal.currentTr).find('.count-documents').html(count); }, } // Modal object to handle booking documents form const BookingDocumentsForm = { init: function() { BookingDocumentsForm.inputHtml = ''; }, reset: function() { $('#form-add-new-document').get(0).reset(); }, resetPreview: function() { $('#form-add-new-document .file-name').val(''); }, updatePreview: function() { BookingDocumentsForm.resetPreview(); let input = $('#form-add-new-document').find('.input-file-wrap input'); let file = $(input).get(0).files[0]; $('#form-add-new-document .file-name').val(file.name); }, addNew: function() { $('#booking-documents-modal #form-add-new-document').show(200); $('#form-add-new-document').find('.input-file-wrap').html(BookingDocumentsForm.inputHtml); }, openFileChooser: function() { $('#form-add-new-document').find('.input-file-wrap').html(BookingDocumentsForm.inputHtml); $('#form-add-new-document').find('.input-file-wrap input').click(); }, close: function() { $('#booking-documents-modal #form-add-new-document').hide(200); }, } // Modal object to handle Voucher/Discount processes const VoucherModal = { show: function() { $(".loading_overlay").show(); $.ajax({ type: 'POST', headers: { "cache-control": "no-cache" }, url: admin_order_tab_link, dataType: 'JSON', cache: false, data: 'ajax=true&id_order='+id_order+'&action=InitVoucherModal', beforeSend: function() { $("#page-loader").show(); }, success: function(result) { if (result.hasError == 0 && result.modalHtml) { $('#footer').next('.bootstrap').append(result.modalHtml); $('#voucher-modal').modal('show'); } else { showErrorMessage(txtSomeErr); } }, complete: function() { $(".loading_overlay").hide(); $("#page-loader").hide(); } }); }, close: function() { $('#voucher-modal').modal('hide'); }, submit: function() { $(document).find('#submitNewVoucher').click(); } }; // Modal object to handle Add order payment processes const OrderPaymentModal = { show: function() { $(".loading_overlay").show(); $.ajax({ type: 'POST', headers: { "cache-control": "no-cache" }, url: admin_order_tab_link, dataType: 'JSON', cache: false, data: 'ajax=true&id_order='+id_order+'&action=InitOrderPaymentModal', beforeSend: function() { $("#page-loader").show(); }, success: function(result) { if (result.hasError == 0 && result.modalHtml) { $('#footer').next('.bootstrap').append(result.modalHtml); $('#order-payment-modal').modal('show'); } else { showErrorMessage(txtSomeErr); } }, complete: function() { $(".loading_overlay").hide(); $("#page-loader").hide(); } }); }, close: function() { $('#order-payment-modal').modal('hide'); }, submit: function() { $(document).find('#submitAddPayment').click(); } }; // Modal object to handle show order payment processes const OrderPaymentDetailModal = { show: function(paymentObj) { $(".loading_overlay").show(); $.ajax({ type: 'POST', headers: { "cache-control": "no-cache" }, url: admin_order_tab_link, dataType: 'JSON', cache: false, data: 'ajax=true&id_order='+id_order+'&action=InitOrderPaymentDetailModal', beforeSend: function() { $("#page-loader").show(); }, success: function(result) { if (result.hasError == 0 && result.modalHtml) { $('#footer').next('.bootstrap').append(result.modalHtml); $('#payment-detail-modal #payment_date').html(paymentObj.data('payment_date')); $('#payment-detail-modal #payment_method').html(paymentObj.data('payment_method')); $('#payment-detail-modal #payment_source').html(paymentObj.data('payment_source')); $('#payment-detail-modal #transaction_id').html(paymentObj.data('transaction_id')); $('#payment-detail-modal #card_number').html(paymentObj.data('card_number')); $('#payment-detail-modal #card_brand').html(paymentObj.data('card_brand')); $('#payment-detail-modal #card_expiration').html(paymentObj.data('card_expiration')); $('#payment-detail-modal #card_holder').html(paymentObj.data('card_holder')); $('#payment-detail-modal #amount').html(paymentObj.data('amount')); $('#payment-detail-modal #invoice_number').html(paymentObj.data('invoice_number')); $('#payment-detail-modal').modal('show'); } else { showErrorMessage(txtSomeErr); } }, complete: function() { $(".loading_overlay").hide(); $("#page-loader").hide(); } }); }, close: function() { $('#payment-detail-modal').modal('hide'); }, }; // Modal object to handle document note processes in order status section const DocumentNoteModal = { show: function(documentObj) { $(".loading_overlay").show(); $.ajax({ type: 'POST', headers: { "cache-control": "no-cache" }, url: admin_order_tab_link, dataType: 'JSON', cache: false, data: 'ajax=true&id_order='+id_order+'&action=InitOrderDocumentNoteModal', beforeSend: function() { $("#page-loader").show(); }, success: function(result) { if (result.hasError == 0 && result.modalHtml) { $('#footer').next('.bootstrap').append(result.modalHtml); $('#document-note-modal #id_order_invoice').val(documentObj.data('id_order_invoice')); $('#document-note-modal #editNote').text(documentObj.data('edit_note')); $('#document-note-modal').modal('show'); } else { showErrorMessage(txtSomeErr); } }, complete: function() { $(".loading_overlay").hide(); $("#page-loader").hide(); } }); }, close: function() { $('#document-note-modal').modal('hide'); }, submit: function() { $(document).find('#submitEditNote').click(); } }; // Modal object to handle traveller info processes const TravellerModal = { show: function() { $(".loading_overlay").show(); $.ajax({ type: 'POST', headers: { "cache-control": "no-cache" }, url: admin_order_tab_link, dataType: 'JSON', cache: false, data: 'ajax=true&id_order='+id_order+'&action=InitTravellerModal', beforeSend: function() { $("#page-loader").show(); }, success: function(result) { if (result.hasError == 0 && result.modalHtml) { $('#footer').next('.bootstrap').append(result.modalHtml); $('#traveller-modal').modal('show'); } else { showErrorMessage(txtSomeErr); } }, complete: function() { $(".loading_overlay").hide(); $("#page-loader").hide(); } }); }, close: function() { $('#traveller-modal').modal('hide'); }, submit: function() { $(".loading_overlay").show(); TravellerModal.hideErrors(); $.ajax({ type: 'POST', headers: { "cache-control": "no-cache" }, url: admin_order_tab_link, dataType: 'JSON', cache: false, data: $('#customer-guest-details-form').serialize()+'&ajax=true&id_order='+id_order+'&action=updateGuestDetails', success: function(result) { if (result.hasError == true) { TravellerModal.showErrors(result.errorsHtml); } else { if (result.msg) { showSuccessMessage(result.msg); } if (result.data.guest_name) { $('#customer-guest-details .gender_name').text(result.data.gender_name); } if (result.data.guest_name) { $('#customer-guest-details .guest_name').text(result.data.guest_name); } if (result.data.guest_email) { $('#customer-guest-details .guest_email a').attr('href', 'mailto:'+result.data.guest_email).html(' ' + result.data.guest_email); } if (result.data.guest_phone) { $('#customer-guest-details .guest_phone a').attr('href', 'tel'+result.data.guest_phone).html(' ' + result.data.guest_phone); } } }, complete: function() { $(".loading_overlay").hide(); } }); }, showErrors: function(errorsHtml) { $('#traveller-modal .errors-wrap').html(errorsHtml); $('#traveller-modal .errors-wrap').show(200); }, hideErrors: function(cb) { $('#traveller-modal .errors-wrap').hide(200); $('#traveller-modal .errors-wrap').html(''); } }; // Modal object to handle room status processes const RoomStatusModal = { show: function(roomObj) { $(".loading_overlay").show(); $.ajax({ type: 'POST', headers: { "cache-control": "no-cache" }, url: admin_order_tab_link, dataType: 'JSON', cache: false, data: 'ajax=true&id_order='+id_order+'&action=InitRoomStatusModal¤t_room_status='+roomObj.data('id_status'), beforeSend: function() { $("#page-loader").show(); }, success: function(result) { if (result.hasError == 0 && result.modalHtml) { $('#footer').next('.bootstrap').append(result.modalHtml); var currentStatus = roomObj.data('id_status'); $('#room-status-modal #room_status_id_hotel_booking_detail').val(roomObj.data('id_hotel_booking_detail')); $('#room-status-modal #room_status_date_from').val(roomObj.data('date_from')); $('#room-status-modal #room_status_date_to').val(roomObj.data('date_to')); $('#room-status-modal #room_status_id_room').val(roomObj.data('id_room')); $('#room-status-modal #room_status_id_order').val(roomObj.data('id_order')); $('#room-status-modal .booking_order_status').val(roomObj.data('id_status')); var checkIn = roomObj.data('check_in') ? String(roomObj.data('check_in')).substring(0, 16) : ''; var checkOut = roomObj.data('check_out') ? String(roomObj.data('check_out')).substring(0, 16) : ''; $('#room-status-modal .room_status_info_form').data({check_in_time: roomObj.data('check_in_time'), check_out_time: roomObj.data('check_out_time'), check_in: checkIn, check_out: checkOut, current_status: currentStatus}); if (currentStatus == result.STATUS_CHECKED_OUT) { $('.room_status_info_form .room_status_date').val(checkOut || roomObj.data('date_to') + ' ' + roomObj.data('check_out_time')); } else { $('.room_status_info_form .room_status_date').val(checkIn || roomObj.data('date_from') + ' ' + roomObj.data('check_in_time')); } $('#room-status-modal').modal('show'); } else if (result.errors) { showErrorMessage(); } }, complete: function() { $(".loading_overlay").hide(); $("#page-loader").hide(); } }); }, close: function() { $('#room-status-modal').modal('hide'); }, submit: function() { $(document).find('#submitbookingOrderStatus').click(); } }; // Modal object to handle adding rooms to order processes const AddRoomBookingModal = { show: function() { $(".loading_overlay").show(); $.ajax({ type: 'POST', headers: { "cache-control": "no-cache" }, url: admin_order_tab_link, dataType: 'JSON', cache: false, data: 'ajax=true&id_order='+id_order+'&action=initAddRoomBookingModal', beforeSend: function() { $("#page-loader").show(); }, success: function(result) { if (result.hasError == 0 && result.modalHtml) { $('#footer').next('.bootstrap').append(result.modalHtml); $('#new_room').fadeIn('fast').promise().done(function () { $('#add-room-booking-modal').modal('show'); $(document).find("#add_product_product_name").autocomplete(admin_order_tab_link, { minChars: 3, max: 10, width: 500, selectFirst: false, scroll: false, dataType: "json", highlightItem: true, formatItem: function(data, i, max, value, term) { return value; }, parse: function(data) { var products = new Array(); if (typeof(data.products) != 'undefined') for (var i = 0; i < data.products.length; i++) products[i] = { data: data.products[i], value: data.products[i].name }; return products; }, extraParams: { ajax: true, token: token, action: 'searchProducts', booking_product: 1, id_lang: id_lang, id_currency: id_currency, id_address: id_address, id_customer: id_customer, id_order: id_order, product_search: function() { return $('#add_product_product_name').val(); } } } ) .result(function(event, data, formatted) { if (!data) { $('#new_room input, #new_room select').each(function() { if ($(this).attr('id') != 'add_product_product_name') $('#new_room input, #new_room select, #new_room button').attr('disabled', true); }); } else { $('#new_room input, #new_room select, #new_room button').removeAttr('disabled'); if ($('#new_room .booking_occupancy').length) { $('#new_room .booking_guest_occupancy').removeClass('disabled'); setRoomTypeGuestOccupancy($('#new_room .booking_occupancy_wrapper')); } // Keep product variable current_product = data; $('#add_product_product_id').val(data.id_product); $('#add_product_product_name').val(data.name); $('#add_product_product_price_tax_incl').val(data.price_tax_incl); $('#add_product_product_price_tax_excl').val(data.price_tax_excl); $("#new_room .max_adults").val(data.room_type_info.max_adults); $("#new_room .max_children").val(data.room_type_info.max_children); $("#new_room .max_guests").val(data.room_type_info.max_guests); //Added by webkul to set curent date in the date fields by default var date_in = $.datepicker.formatDate('dd-mm-yy', new Date()); var date_out = $.datepicker.formatDate('dd-mm-yy', new Date(new Date().getTime()+24*60*60*1000)); $('#new_room').find("input.add_room_date_from").val(date_in); $('#new_room').find("input.add_room_date_to").val(date_out); //End // initialize datepickers AddRoomBookingModal.initDatePickers(); // addRoomRefreshTotal(); $('.add_room_fields').show(); $('.submitAddRoom').removeAttr('disabled'); } }); }); } else { showErrorMessage(txtSomeErr); } }, complete: function() { $(".loading_overlay").hide(); $("#page-loader").hide(); } }); }, initDatePickers: function () { $('.add_room_date_from').datepicker({ showOtherMonths: true, dateFormat: 'dd-mm-yy', onSelect: function(selectedDate) { let objDateToMin = $.datepicker.parseDate('dd-mm-yy', selectedDate); objDateToMin.setDate(objDateToMin.getDate() + 1); $('#new_room .add_room_date_to').datepicker('option', 'minDate', objDateToMin); AddRoomBookingModal.updateRoomPrice(); }, beforeShow : function () { if(allowBackdateOrder) { var minDate = null; } else { var minDate = new Date(); } $(this).datepicker("option", "minDate", minDate); } }); $(".add_room_date_to").datepicker( { showOtherMonths: true, dateFormat: 'dd-mm-yy', onSelect: function() { AddRoomBookingModal.updateRoomPrice(); }, beforeShow : function () { var date_from = $.datepicker.parseDate('dd-mm-yy', $(this).closest('.bookingDuration').find('.add_room_date_from').val()); date_from.setDate(date_from.getDate() + 1); $(this).datepicker("option", "minDate", date_from); } }); }, // Fetch the room price for the selected dates (advance price rules depend on stay duration) and update the price fields updateRoomPrice: function() { const dateFrom = $('#new_room .add_room_date_from').val(); const dateTo = $('#new_room .add_room_date_to').val(); const idProduct = $('#add_product_product_id').val(); if (!dateFrom || !dateTo || !parseInt(idProduct)) { return; } const objDateFrom = $.datepicker.parseDate('dd-mm-yy', dateFrom); const objDateTo = $.datepicker.parseDate('dd-mm-yy', dateTo); if (objDateTo <= objDateFrom) { return; } $.ajax({ type: 'POST', url: admin_order_tab_link, dataType: 'JSON', cache: false, data: { ajax: 1, token: token, action: 'getEditRoomPrice', id_order: id_order, id_product: idProduct, date_from: $.datepicker.formatDate('yy-mm-dd', objDateFrom), date_to: $.datepicker.formatDate('yy-mm-dd', objDateTo), }, success: function(result) { if (result.success) { $('#add_product_product_price_tax_excl').val(result.unit_price_tax_excl); $('#add_product_product_price_tax_incl').val(result.unit_price_tax_incl); } } }); }, close: function() { $('#add-room-booking-modal').modal('hide'); }, submit: function() { $('#add-room-booking-modal #submitAddRoom').click(); } }; // Modal object to handle editing rooms and services in order processes const EditRoomBookingModal = { show: function(btnEdit) { const productLineData = $(btnEdit).attr('data-product_line_data'); const jsonProductLineData = JSON.parse(productLineData); const data = { ajax: 1, action: 'initEditRoomBookingModal', id_order: parseInt(jsonProductLineData.id_order), product_line_data: productLineData, id_room: parseInt(jsonProductLineData.id_room), id_product: parseInt(jsonProductLineData.id_product), date_from: jsonProductLineData.date_from, date_to: jsonProductLineData.date_to, orderEdit: 1, }; $(".loading_overlay").show(); $.ajax({ type: 'POST', headers: { "cache-control": "no-cache" }, url: admin_order_tab_link, dataType: 'JSON', cache: false, data: data, beforeSend: function() { $("#page-loader").show(); }, success: function(result) { if (result.hasError == 0 && result.modalHtml) { $('#footer').next('.bootstrap').append(result.modalHtml); const dateFrom = $.datepicker.formatDate('dd-mm-yy', $.datepicker.parseDate('yy-mm-dd', jsonProductLineData.date_from)); const dateTo = $.datepicker.formatDate('dd-mm-yy', $.datepicker.parseDate('yy-mm-dd', jsonProductLineData.date_to)); $('#edit_product .edit_product_date_from').attr('value', dateFrom); $('#edit_product .edit_product_date_from').attr('data-min_date', dateFrom); $('#edit_product .edit_product_date_to').attr('value', dateTo); $('#edit_product .edit_product_date_to').attr('data-min_date', dateFrom); $('#edit_product .edit_product_date_from_actual').attr('value', jsonProductLineData.date_from); $('#edit_product .edit_product_date_to_actual').attr('value', jsonProductLineData.date_to); $('#edit_product .room_unit_price').val(parseFloat(jsonProductLineData.paid_unit_price_tax_excl)); // initialize datepickers EditRoomBookingModal.initDatePickers(); initUITooltip(); $('#edit_product .extra-services-container #id_htl_booking').val(jsonProductLineData.id); $('#edit-room-booking-modal').modal('show'); } else { showErrorMessage(txtSomeErr); } }, complete: function() { $(".loading_overlay").hide(); $("#page-loader").hide(); } }); }, // Fetch the room price for the selected dates (advance price rules depend on stay duration) and update the price field updateRoomPrice: function() { const dateFrom = $('#edit_product .edit_product_date_from').val(); const dateTo = $('#edit_product .edit_product_date_to').val(); if (!dateFrom || !dateTo) { return; } const objDateFrom = $.datepicker.parseDate('dd-mm-yy', dateFrom); const objDateTo = $.datepicker.parseDate('dd-mm-yy', dateTo); if (objDateTo <= objDateFrom) { return; } $.ajax({ type: 'POST', url: admin_order_tab_link, dataType: 'JSON', cache: false, data: { ajax: 1, token: token, action: 'getEditRoomPrice', id_order: $('#edit_product input[name="id_order"]').val(), id_product: $('#edit_product input[name="id_product"]').val(), id_room: $('#edit_product input[name="id_room"]').val(), date_from: $.datepicker.formatDate('yy-mm-dd', objDateFrom), date_to: $.datepicker.formatDate('yy-mm-dd', objDateTo), }, beforeSend: function() { $('#edit_product .room_unit_price').prop('readonly', true); }, success: function(result) { if (result.success) { $('#edit_product .room_unit_price').val(result.unit_price_tax_excl); } }, complete: function() { $('#edit_product .room_unit_price').prop('readonly', false); } }); }, initDatePickers: function() { $('#edit_product .edit_product_date_from').datepicker({ showOtherMonths: true, dateFormat: 'dd-mm-yy', altField: '#edit_product .edit_product_date_from_actual', onSelect: function(selectedDate) { let objDateToMin = $.datepicker.parseDate('dd-mm-yy', selectedDate); objDateToMin.setDate(objDateToMin.getDate() + 1); $('#edit_product .edit_product_date_to').datepicker('option', 'minDate', objDateToMin); EditRoomBookingModal.updateRoomPrice(); }, beforeShow : function () { if(allowBackdateOrder) { var minDate = null; } else { var minDate = new Date(Math.min($.datepicker.parseDate('dd-mm-yy', $(this).data('min_date')), new Date())); } $(this).datepicker("option", "minDate", minDate); } }); $('#edit_product .edit_product_date_to').datepicker({ showOtherMonths: true, dateFormat: 'dd-mm-yy', altField: '#edit_product .edit_product_date_to_actual', onSelect: function() { EditRoomBookingModal.updateRoomPrice(); }, beforeShow : function () { var date_from = $.datepicker.parseDate('dd-mm-yy', $(this).closest('.form-group').find('.edit_product_date_from').val()); date_from.setDate(date_from.getDate() + 1); $(this).datepicker("option", "minDate", date_from); } }); } }; // Modal object to handle cancel rooms in order processes const CancelRoomBookingModal = { show: function() { $(".loading_overlay").show(); $.ajax({ type: 'POST', headers: { "cache-control": "no-cache" }, url: admin_order_tab_link, dataType: 'JSON', cache: false, data: 'ajax=true&id_order='+id_order+'&action=initCancelRoomBookingModal', beforeSend: function() { $("#page-loader").show(); }, success: function(result) { if (result.hasError == 0 && result.modalHtml) { $('#footer').next('.bootstrap').append(result.modalHtml); $('#cancel-room-booking-modal').modal('show'); } else { showErrorMessage(txtSomeErr); } }, complete: function() { $(".loading_overlay").hide(); $("#page-loader").hide(); } }); }, close: function() { $('#cancel-room-booking-modal').modal('hide'); }, submit: function() { $('#initiateRefund').click(); } }; // Modal object to handle comment on rooms for manual cancellation const RoomAllotmentCommentModal = { show: function(element) { $(".loading_overlay").show(); let idHtlBooking = parseInt($(element).attr('data-id_hotel_booking_detail')); $.ajax({ type: 'POST', headers: { "cache-control": "no-cache" }, url: admin_order_tab_link, dataType: 'JSON', cache: false, data: 'ajax=true&id_hotel_booking='+idHtlBooking+'&action=initRoomAllotmentCommentModal', beforeSend: function() { $("#page-loader").show(); }, success: function(result) { if (result.hasError == 0 && result.modalHtml) { $('#footer').next('.bootstrap').append(result.modalHtml); $('#room-allotment-comment-modal').modal('show'); } else { showErrorMessage(txtSomeErr); } }, complete: function() { $(".loading_overlay").hide(); $("#page-loader").hide(); } }); }, close: function() { $('#room-allotment-comment-modal').modal('hide'); } }; const AddProductModal = { show: function() { $(".loading_overlay").show(); $.ajax({ type: 'POST', headers: { "cache-control": "no-cache" }, url: admin_order_tab_link, dataType: 'JSON', cache: false, data: 'ajax=true&id_order='+id_order+'&action=initAddProductModal', beforeSend: function() { $("#page-loader").show(); }, success: function(result) { if (result.hasError == 0 && result.modalHtml) { $('#footer').next('.bootstrap').append(result.modalHtml); $('#new_product').fadeIn('fast').promise().done(function () { $('#add-product-modal').modal('show'); $(document).find("#add_product_product_name").autocomplete(admin_order_tab_link, { minChars: 3, max: 10, width: 500, selectFirst: false, scroll: false, dataType: "json", highlightItem: true, formatItem: function(data, i, max, value, term) { return value; }, parse: function(data) { var products = new Array(); if (typeof(data.products) != 'undefined') for (var i = 0; i < data.products.length; i++) products[i] = { data: data.products[i], value: data.products[i].name }; return products; }, extraParams: { ajax: true, token: token, action: 'searchStandaloneProducts', id_lang: id_lang, id_currency: id_currency, id_address: id_address, id_customer: id_customer, id_order: id_order, product_search: function() { return $('#add_product_product_name').val(); } } } ) .result(function(event, data, formatted) { if (!data) { $('#new_product input, #new_product select').each(function() { if ($(this).attr('id') != 'add_product_product_name') $('#new_product input, #new_product select, #new_product button').attr('disabled', true); }); } else { $('#new_product input, #new_product select, #new_product button').removeAttr('disabled'); // Keep product variable current_product = data; $('#add_product_product_id').val(data.id_product); $('#add_product_product_name').val(data.name); $('#add_product_product_price_tax_incl').val(data.price_tax_incl); $('#add_product_product_price_tax_excl').val(data.price_tax_excl); if (parseInt(data.allow_multiple_quantity) != 0) { $('.productQuantity').show(); } else { $('.productQuantity').hide(); $('#add_product_product_quantity').val(1); } if (data.options.length) { $('#new_product #add_product_product_option').empty(); $.each(data.options, function() { $('