Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
122 kB
2
Indexable
Never
var ADMIN_HOTEL_EXTEND = {

    init: function () {
        Number.prototype.formatCurrency = function(){
            return this.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
         };

        $(document).ready(function () {
            $("#tlb-list-room-price .btn-show-detail").on("click", function (e) {
                $('.box-form-update-room-price-by-calendar').removeClass('hidden');
                window.scrollTo({ top: 280, left: 0, behavior: "smooth" });
                if (!$(this).hasClass("on-detail")) { // check popup and popup active not show
                    $(this).removeClass("on-detail").addClass("on-detail")
                    $('#popup-detail-rp').css('display', 'block')
                    const hotel_id = $(this).attr("hotel_id");
                    const rname = $(this).attr("rname")
                    const rtypename = $(this).attr("rtypename")
                    let priceStock = parseInt($(this).attr("rprice"));
                    const room_id = $(this).attr("room_id")
                    $('.price-one-night').text(`${priceStock.toLocaleString('en-US')} VND/ 1 đêm`) // show roomprice in popup
                    $('.price-one-night-hidden').text(priceStock); // show price stock of room
                    $('.rp-name').text(rname); // show name of room
                    $('.price-input-change-date').removeAttr('value').attr('value', Intl.NumberFormat().format(priceStock)) // set value price stock to get when you need
                    $('.button-view-by-price').addClass('button-view-by-active');
                    $('.calendar-container-note-by-price').css('display', 'flex')
                    $('.calendar-container-note-by-rule').css('display', 'none');
                    $('.button-view-by-rule').removeClass('button-view-by-active')
                    const urlChangeHotelPrices = URL_DATA_JSON + 'hotel/' + hotel_id + "/hotel_change_prices.json"; // fetch changed prices in file json
                    
                    const urlHotelPrices = URL_DATA_JSON + 'hotel/' + hotel_id + "/hotel_prices.json"; // fetch room prices in file json
                    fetchData(urlHotelPrices, urlChangeHotelPrices)
                        .then(function ([dataHotelPrices, dataChangeJson]) {
                            function formatDate(date) { // Format form dd/mm/yyyy -> yyy-mm-dd
                                let dateFormat = date.split('/');
                                return `${dateFormat[2]}-${dateFormat[1]}-${dateFormat[0]}`;
                            }

                            function formatDate_dd_mm_yyyy(date) { // Format form dd/mm/yyyy -> yyy-mm-dd
                                let dateFormat = date.split('-');
                                return `${dateFormat[2]}-${dateFormat[1]}-${dateFormat[0]}`;
                            }
                            const sourceObj = dataHotelPrices?.[rname]?.[rtypename] || {};
                            let arrData = [];
                            let listCondition = []
                            colorArr = ['#E57C23', '#47A992', '#482121']; // order: rule, promo, voucher
                            colorArrLoop = ['#a95c1c', '#2a695a', '#7b3e3e']; // order: rule, promo, voucher

                            sourceObj && Object.keys(sourceObj).length > 0 && Object.keys(sourceObj).map((itemType, indexType) => {
                                let objSelect = sourceObj[itemType];
                                objSelect && Object.keys(objSelect).length && Object.keys(objSelect).map((item, index) => {
                                    let objSelectItem = objSelect[item];
                                    listCondition.push({ id: objSelectItem.id, name: objSelectItem.name });
                                    objSelectItem.single?.length > 0 && objSelectItem.single.map((item2, index2) => { // handle single 
                                        let temp = {}
                                        let itemEnd = new Date(formatDate(item2.d_end));
                                        let itemEndNext = new Date(itemEnd.getFullYear(), itemEnd.getMonth(), itemEnd.getDate() + 2);
                                        temp.title = `⇌ ${item}`;
                                        temp.start = formatDate(item2.d_start);
                                        temp.end = itemEndNext.toISOString().split('T')[0];
                                        temp.priceObj = objSelectItem.discount;
                                        temp.type = itemType;
                                        temp.backgroundColor = colorArr[indexType];
                                        temp.isLoop = 'single';
                                        temp.typeId = objSelectItem.id;
                                        arrData.push(temp)
                                    })

                                    objSelectItem.loop?.length > 0 && objSelectItem.loop.map((item3, index3) => { //handle loop
                                        let arr = [];
                                        let currentDate = new Date(formatDate(item3.d_start));
                                        let targetDate = new Date(formatDate(item3.d_end));
                                        while (currentDate <= targetDate) {
                                            if (currentDate.getDay() === (parseInt(item3.day_of_week) - 1) || currentDate.getDay() === (parseInt(item3.day_of_week) - 8)) { // SUNDAY in vera sys = 8
                                                // arr.push(currentDate)
                                                let temp = {}
                                                temp.title = `↺ ${item}`;
                                                temp.start = new Date(currentDate).toISOString().split('T')[0];
                                                temp.end = new Date(currentDate.setDate(currentDate.getDate() + 1)).toISOString().split('T')[0];
                                                temp.priceObj = objSelectItem.discount;
                                                temp.type = itemType;
                                                temp.backgroundColor = colorArrLoop[indexType];
                                                temp.isLoop = 'loop';
                                                temp.typeId = objSelectItem.id;
                                                arrData.push(temp)
                                            }
                                            currentDate.setDate(currentDate.getDate() + 1);
                                        }
                                    })

                                    objSelectItem.special?.length > 0 && objSelectItem.special.map((item4, index3) => { //handle loop
                                        let temp = {}
                                        temp.title = `↝ ${item}`;
                                        temp.priceObj = objSelectItem.discount;
                                        temp.type = itemType;
                                        temp.backgroundColor = colorArrLoop[indexType];
                                        temp.isLoop = 'special';
                                        temp.typeId = objSelectItem.id;
                                        temp.specialObj = item4;
                                        arrData.push(temp)
                                    })
                                })
                            })


                            let htmlListCondition = '';
                            listCondition.map((item, index) => {
                                htmlListCondition += `<input type="checkbox" id="${item.id}"></input>
                        <label for="${item.id}">${item.name}</label><br/>`
                            })
                            function formatPriceWithDot(price) {
                                const priceInt = parseInt(price);
                                return priceInt.formatCurrency();
                                // return priceInt.toLocaleString('en-US', { currency: 'VND' });
                            }

                            function formatPriceRemoveDot(price) {
                                return parseInt(price.replaceAll(',', ''));
                            }

                            function checkMonthLoaded(data, dataNext) {
                                const map = new Set();
                                data.map((item) => {
                                    if (!map.has[item.end]) {
                                        map.add(item.end);
                                    }
                                })
                                for (let i = 0; i < dataNext.length; i++) {
                                    if (map.has(dataNext[i].end)) {
                                        return true;
                                    }
                                }
                                // if(data[data.length-1].id == dataNext[dataNext.length-1].id) {
                                //     return true
                                // }
                                return false
                            }

                            function refeshDataCalendar(className, data, currentMonth = "") {
                                $(className).fullCalendar("destroy");
                                $(className).fullCalendar({
                                  themeSystem: "bootstrap4",
                                  height: 700,
                                  locale: "vi",
                                  header: { left: "prev, next", center: "title", right: "today" },
                                  defaultDate: new Date(currentMonth),
                                  events: data || [], //result arrData
                                  eventClick: function (info) 
                                  {
                                      
                                    var obj_this_room = $(this);
                                    let hotelPricesInfo = "";
                                    const isClosed = info.isClosed ? "checked" : "";
                                    const hotel_is_included_fee =
                                      dataHotelPrices.hotel_is_included_fee;
                                    hotelPricesInfo += `
                                                  <div class='sbold'>Trạng thái phòng:</div>
                                                  <input type='checkbox' id='isClosed' ${isClosed} disabled value='1' name='isClosed'></input>
                                                  <label style="transform: translateY(-3px);" for='isClosed'>Đóng phòng</label><br/>
                                                  <div class='sbold'>Điều kiện giá phòng:</div>
                                                  `;
                                    let isUnchecked = (valueUnchecked = "");
                                    info.detail?.map((item, index) => {
                                      if (item.isUnchecked == true) return;
                                      isUnchecked = item.isUnchecked ? "" : "checked";
                                      valueUnchecked = item.isUnchecked
                                        ? 'value="0"'
                                        : 'value="1"';
                                      if (item.type == "rule") {
                                        if (item.priceObj.suffix == "VND") {
                                          hotelPricesInfo += `<input type='checkbox' id='${
                                            item.typeId
                                          }_${index}' ${isUnchecked} disabled ${valueUnchecked} name='${
                                            item.type
                                          }|${item.isLoop}|${item.typeId}'></input>
                                                      <input type='hidden' class="input-hidden" data-suffix='VND' data-type='${
                                                        item.priceObj?.type
                                                      }' data-price_vnd='${
                                            item.priceObj?.price_vnd
                                          }' data-condition='rule' ${valueUnchecked} name='${
                                            item.type
                                          }|${item.isLoop}|${item.typeId}'></input>
                                                      <label style="transform: translateY(-3px);" for='${
                                                        item.typeId
                                                      }_${index}'>${item.title}: ${
                                            item.priceObj?.type
                                          }${formatPriceWithDot(
                                            item.priceObj?.price_vnd
                                          )} VNĐ</label><br/>`;
                                        } else {
                                          hotelPricesInfo += `<input type='checkbox' id='${item.typeId}_${index}' ${isUnchecked} disabled ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'> </input>
                                                      <input type='hidden' class="input-hidden" data-suffix='%' data-type='${item.priceObj?.type}' data-price_percent='${item.priceObj?.price_percent}' data-condition='rule' ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'> </input>
                                                      <label style="transform: translateY(-3px);" for='${item.typeId}_${index}'>${item.title}: ${item.priceObj?.type}${item.priceObj?.price_percent}%</label><br/>`;
                                        }
                                      } else if (item.type == "promo") {
                                        // Process promo % only
                                        hotelPricesInfo += `<input type='checkbox' id='${item.typeId}_${index}' ${isUnchecked} disabled ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'></input>
                                                      <input type='hidden' class="input-hidden"  data-price_percent='${item.priceObj?.price_percent}' data-condition='promo' ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'></input>
                                                      <label style="transform: translateY(-3px);" for='${item.typeId}_${index}'> ${item.title}: -${item.priceObj?.price_percent} %</label><br/>`;
                                      } else {
                                        if (item.priceObj.voucher_type == 1) {
                                          hotelPricesInfo += `<input type='checkbox' id='${
                                            item.typeId
                                          }_${index}' ${isUnchecked} disabled ${valueUnchecked} name='${
                                            item.type
                                          }|${item.isLoop}|${item.typeId}'> </input>
                                                      <input type='hidden' class="input-hidden" data-voucher_price='${
                                                        item.priceObj?.voucher_price
                                                      }' data-voucher_type='1' data-condition='voucher' ${valueUnchecked} name='${
                                            item.type
                                          }|${item.isLoop}|${item.typeId}'></input>
                                                      <label style="transform: translateY(-3px);" for='${
                                                        item.typeId
                                                      }_${index}'>${
                                            item.title
                                          }: -${formatPriceWithDot(
                                            item.priceObj?.voucher_price
                                          )} VNĐ</label><br/>`;
                                        } else {
                                          hotelPricesInfo += `<input type='checkbox' id='${item.typeId}_${index}' ${isUnchecked} disabled ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'></input>
                                                      <input type='hidden' class="input-hidden" data-voucher_percent='${item.priceObj?.voucher_percent}' data-voucher_type='2' data-condition='voucher' ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'></input>
                                                      <label style="transform: translateY(-3px);" for='${item.typeId}_${index}'> ${item.title}: -${item.priceObj?.voucher_percent} %</label><br/>`;
                                        }
                                      }
                                    });
                                    if (info.detail.length == 0) {
                                      hotelPricesInfo += "Chưa có điều kiện giá phòng nào.<br/>";
                                    }
                                    if (dataHotelPrices.hotel_is_included_fee == "0") {
                                      hotelPricesInfo += `Giá đã bao gồm hoa hồng. (${dataHotelPrices.hotel_fee}%)`;
                                    }
                                    $(".info-prices-title").html(
                                      "Giá sau khi thay đổi (theo đêm):"
                                    ); //set title
                                    $(".info-prices-price").html(info.title); // set gia
                                    $(".info-prices-price-hidden").html(info.price); // set gia
                                    $(".list-change-price")
                                      .html(hotelPricesInfo)
                                      .addClass("show-list-change-price");
                                    $(".list-checkbox-change-price").html(hotelPricesInfo); // set
                                    $(".custom-edit-price").addClass("show-custom-edit-price");
                                    $(".current-date-selected").val(info.start._i);
                                    $(".display-current-date-selected").text(
                                      `Ngày đang chọn: ${formatDate_dd_mm_yyyy(info.start._i)}`
                                    );
                                    obj_this_room.addClass(formatDate_dd_mm_yyyy(info.start._i));
                            
                                    if (info.inputChange) {
                                      const inputChange = parseInt(
                                        info.inputChange.replace(",", "").replace(",", "")
                                      );
                                      $(".price-input-change-date")
                                        .css("display", "none")
                                        .val(Intl.NumberFormat().format(inputChange));
                                      $(".reset-change-by-date").css("display", "inline");
                                    } else {
                                      $(".price-input-change-date")
                                        .css("display", "none")
                                        .val(Intl.NumberFormat().format(priceStock));
                                      $(".reset-change-by-date").css("display", "none");
                                    }
                  
                                    if (info.price) {
                                      $(".price-input-change-final").val(
                                        Intl.NumberFormat().format(info.price)
                                      );
                                    } else {
                                      $(".price-input-change-final").val(
                                        Intl.NumberFormat().format(priceStock)
                                      );
                                    }
                  
                                    $(".form-hotel-id").val(hotel_id);
                                    $(".form-room-id").val(room_id);
                                    $(".form-room-index").val(rtypename);
                                    $("#form-change-by-date").removeClass("show-form-change");
                                    $(".info-price-and-edit").css("display", "block");
                                    $(".form-price-change-rule").val(0);
                                    $(".form-price-change-promo").val(0);
                                    $(".form-price-change-voucher").val(0);
                                    $(".form-price-change-rose").val(0);
                                    $(".info-price-rose-container").css("display", "none");
                                    // $('.price-input-change-final').removeAttr("value")
                                    setDisplayPriceAfterChange(info.price);
                                  },
                                });
                              }

                            function refeshDataCalendar_by_rule(classname, data, dataPrice, currentMonth = '') {
                                $('#calendar_detail').fullCalendar("destroy");
                                $(classname).fullCalendar("destroy");
                                $(classname).fullCalendar({
                                    themeSystem: 'bootstrap4',
                                    height: 700,
                                    locale: 'vi',
                                    header: { left: "prev, next", center: "title", right: "today" },
                                    // editable: !0,
                                    defaultDate: new Date(currentMonth),
                                    events: data || [],
                                    eventClick: function (itemEvent) {
                                        switch (itemEvent.type) {
                                            case "condition":
                                                let info_rule = '';
                                                itemEvent.detail?.map((item) => {
                                                    if (item.type == 'rule') {
                                                        if (item.priceObj.suffix == 'VND') {
                                                            info_rule += `
                                                    <div class="sbold">Rule giá phòng:</div>
                                                    <label>${item.title}: ${item.priceObj?.type}${formatPriceWithDot(item.priceObj?.price_vnd)} VNĐ</label><br/>`
                                                        } else {
                                                            info_rule += `<div class="sbold">Rule giá phòng:</div>
                                                    <label>${item.title}: ${item.priceObj?.type}${item.priceObj?.price_percent}%</label><br/>`
                                                        }
                                                    } else if (item.type == 'promo') {
                                                        // Process promo % only
                                                        info_rule += `<div class="sbold">Promo:</div>
                                                    <label> ${item.title}: -${item.priceObj?.price_percent} %</label><br/>`
                                                    } else {
                                                        if (item.priceObj.voucher_type == 1) {
                                                            info_rule += `<div class="sbold">Voucher:</div>
                                                    <label'>${item.title}: -${formatPriceWithDot(item.priceObj?.voucher_price)} VNĐ</label><br/>`;
                                                        } else {
                                                            info_rule += `<div class="sbold">Voucher:</div>
                                                    <label> ${item.title}: -${item.priceObj?.voucher_percent} %</label><br/>`;
                                                        }
                                                    }
                                                })
                                                if (info_rule == '') info_rule = 'Ngày không bị ảnh hưởng bởi điều kiện nào.';
                                                $('.calendar-container-notification').empty();
                                                $('.info-show-info-rule').html(info_rule);
                                                $('.popup-info-show-info-rule').css('display', 'block')
                                                $('.display-current-date-selected').text(`Ngày đang chọn: ${formatDate_dd_mm_yyyy(itemEvent.start._i)}`)
                                                $('.info-price-and-edit').css('display', 'none');
                                                $('.list-change-price').removeClass('show-list-change-price').empty();

                                                break;

                                            case "price":
                                                let hotelPricesInfo = '';
                                                const isClosed = itemEvent.isClosed ? 'checked' : '';
                                                hotelPricesInfo += `
                                                <div class='sbold'>Trạng thái phòng:</div>
                                                <input type='checkbox' id='isClosed' ${isClosed} disabled value='1' name='isClosed'></input>
                                                <label style="transform: translateY(-3px);" for='isClosed'>Đóng phòng</label><br/>
                                                <div class='sbold'>Điều kiện giá phòng:</div>
                                                `;
                                                itemEvent.detail?.map((item, index) => {
                                                    if(item.isUnchecked == true) return;
                                                    const isUnchecked = item.isUnchecked ? '' : 'checked'
                                                    const valueUnchecked = item.isUnchecked ? 'value="0"' : 'value="1"'
                                                    if (item.type == 'rule') {
                                                        if (item.priceObj.suffix == 'VND') {
                                                            hotelPricesInfo += `<input type='checkbox' id='${item.typeId}_${index}' ${isUnchecked} disabled ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'></input>
                                                    <input type='hidden' class="input-hidden" data-suffix='VND' data-type='${item.priceObj?.type}' data-price_vnd='${item.priceObj?.price_vnd}' data-condition='rule' ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'></input>
                                                    <label style="transform: translateY(-3px);" for='${item.typeId}_${index}'>${item.title}: ${item.priceObj?.type}${formatPriceWithDot(item.priceObj?.price_vnd)} VNĐ</label><br/>`
                                                        } else {
                                                            hotelPricesInfo += `<input type='checkbox' id='${item.typeId}_${index}' ${isUnchecked} disabled ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'> </input>
                                                    <input type='hidden' class="input-hidden" data-suffix='%' data-type='${item.priceObj?.type}' data-price_percent='${item.priceObj?.price_percent}' data-condition='rule' ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'> </input>
                                                    <label style="transform: translateY(-3px);" for='${item.typeId}_${index}'>${item.title}: ${item.priceObj?.type}${item.priceObj?.price_percent}%</label><br/>`
                                                        }
                                                    } else if (item.type == 'promo') {
                                                        // Process promo % only
                                                        hotelPricesInfo += `<input type='checkbox' id='${item.typeId}_${index}' ${isUnchecked} disabled ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'></input>
                                                    <input type='hidden' class="input-hidden"  data-price_percent='${item.priceObj?.price_percent}' data-condition='promo' ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'></input>
                                                    <label style="transform: translateY(-3px);" for='${item.typeId}_${index}'> ${item.title}: -${item.priceObj?.price_percent} %</label><br/>`
                                                    } else {
                                                        if (item.priceObj.voucher_type == 1) {
                                                            hotelPricesInfo += `<input type='checkbox' id='${item.typeId}_${index}' ${isUnchecked} disabled ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'> </input>
                                                    <input type='hidden' class="input-hidden" data-voucher_price='${item.priceObj?.voucher_price}' data-voucher_type='1' data-condition='voucher' ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'></input>
                                                    <label style="transform: translateY(-3px);" for='${item.typeId}_${index}'>${item.title}: -${formatPriceWithDot(item.priceObj?.voucher_price)} VNĐ</label><br/>`;
                                                        } else {
                                                            hotelPricesInfo += `<input type='checkbox' id='${item.typeId}_${index}' ${isUnchecked} disabled ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'></input>
                                                    <input type='hidden' class="input-hidden" data-voucher_percent='${item.priceObj?.voucher_percent}' data-voucher_type='2' data-condition='voucher' ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'></input>
                                                    <label style="transform: translateY(-3px);" for='${item.typeId}_${index}'> ${item.title}: -${item.priceObj?.voucher_percent} %</label><br/>`;
                                                        }
                                                    }
                                                })
                                                // kiem tra ngay dang cho co data hay khong
                                                $('.info-show-info-rule').empty();
                                                $('.popup-info-show-info-rule').css('display', 'none')
                                                $('.calendar-container-notification').empty();
                                                $('.info-prices-title').html('Giá sau khi thay đổi (theo đêm):') //set title
                                                $('.info-prices-price').html(itemEvent?.titlePrice) // set gia
                                                $('.info-prices-price-hidden').html(itemEvent?.price) // set gia
                                                $('.list-change-price').html(hotelPricesInfo).addClass("show-list-change-price");
                                                $('.list-checkbox-change-price').html(hotelPricesInfo); // set 
                                                $('.custom-edit-price').addClass('show-custom-edit-price');
                                                $('.current-date-selected').val(itemEvent?.start);
                                                $('.display-current-date-selected').text(`Ngày đang chọn: ${formatDate_dd_mm_yyyy(itemEvent.start._i)}`)
                                                // $('.price-input-change-date').css('display', 'none').val(priceStock);
                                                if (itemEvent.inputChange) {
                                                    const inputChange = parseInt((itemEvent.inputChange).replaceAll(',', ''));
                                                    $('.price-input-change-date').css('display', 'none').val(Intl.NumberFormat().format(inputChange));
                                                    $('.reset-change-by-date').css('display', 'inline');
                                                } else {
                                                    $('.price-input-change-date').css('display', 'none').val(Intl.NumberFormat().format(priceStock));
                                                    $('.reset-change-by-date').css('display', 'none');
                                                }
                                                $('.form-hotel-id').val(hotel_id);
                                                $('.form-room-id').val(room_id);
                                                $('.form-room-index').val(rtypename);
                                                $('#form-change-by-date').removeClass('show-form-change')
                                                $('.info-price-and-edit').css('display', 'block');
                                                $('.form-price-change-rule').val(0);
                                                $('.form-price-change-promo').val(0);
                                                $('.form-price-change-voucher').val(0);
                                                $('.form-price-change-rose').val(0);
                                                break;
                                            default:
                                                break;
                                        }
                                    },
                                    dayClick: function (date, allDay, jsEvent, view) {
                                        const dateFormat = (date._d).toISOString().split('T')[0];
                                        const dataDayClicked = dataPrice.find((item) => {
                                            if (item.start == dateFormat) {
                                                return item;
                                            }
                                        });
                                        let hotelPricesInfo = '';
                                        dataDayClicked?.detail?.map((item, index) => {
                                            const isUnchecked = item.isUnchecked ? '' : 'checked'
                                            const valueUnchecked = item.isUnchecked ? 'value="0"' : 'value="1"'
                                            if (item.type == 'rule') {
                                                if (item.priceObj.suffix == 'VND') {
                                                    hotelPricesInfo += `<input type='checkbox' id='${item.typeId}_${index}' ${isUnchecked} disabled ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'></input>
                                            <input type='hidden' class="input-hidden" data-suffix='VND' data-type='${item.priceObj?.type}' data-price_vnd='${item.priceObj?.price_vnd}' data-condition='rule' ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'></input>
                                            <label style="transform: translateY(-3px);" for='${item.typeId}_${index}'>${item.title}: ${item.priceObj?.type}${formatPriceWithDot(item.priceObj?.price_vnd)} VNĐ</label><br/>`
                                                } else {
                                                    hotelPricesInfo += `<input type='checkbox' id='${item.typeId}_${index}' ${isUnchecked} disabled ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'> </input>
                                            <input type='hidden' class="input-hidden" data-suffix='%' data-type='${item.priceObj?.type}' data-price_percent='${item.priceObj?.price_percent}' data-condition='rule' ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'> </input>
                                            <label style="transform: translateY(-3px);" for='${item.typeId}_${index}'>${item.title}: ${item.priceObj?.type}${item.priceObj?.price_percent}%</label><br/>`
                                                }
                                            } else if (item.type == 'promo') {
                                                // Process promo % only
                                                hotelPricesInfo += `<input type='checkbox' id='${item.typeId}_${index}' ${isUnchecked} disabled ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'></input>
                                            <input type='hidden' class="input-hidden"  data-price_percent='${item.priceObj?.price_percent}' data-condition='promo' ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'></input>
                                            <label style="transform: translateY(-3px);" for='${item.typeId}_${index}'> ${item.title}: -${item.priceObj?.price_percent} %</label><br/>`
                                            } else {
                                                if (item.priceObj.voucher_type == 1) {
                                                    hotelPricesInfo += `<input type='checkbox' id='${item.typeId}_${index}' ${isUnchecked} disabled ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'> </input>
                                            <input type='hidden' class="input-hidden" data-voucher_price='${item.priceObj?.voucher_price}' data-voucher_type='1' data-condition='voucher' ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'></input>
                                            <label style="transform: translateY(-3px);" for='${item.typeId}_${index}'>${item.title}: -${formatPriceWithDot(item.priceObj?.voucher_price)} VNĐ</label><br/>`;
                                                } else {
                                                    hotelPricesInfo += `<input type='checkbox' id='${item.typeId}_${index}' ${isUnchecked} disabled ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'></input>
                                            <input type='hidden' class="input-hidden" data-voucher_percent='${item.priceObj?.voucher_percent}' data-voucher_type='2' data-condition='voucher' ${valueUnchecked} name='${item.type}|${item.isLoop}|${item.typeId}'></input>
                                            <label style="transform: translateY(-3px);" for='${item.typeId}_${index}'> ${item.title}: -${item.priceObj?.voucher_percent} %</label><br/>`;
                                                }
                                            }
                                        })
                                        // kiem tra ngay dang cho co data hay khong
                                        $('.info-show-info-rule').empty();
                                        if (dataDayClicked) {
                                            $('.calendar-container-notification').empty();
                                            $('.info-prices-title').html('Giá sau khi thay đổi (theo đêm):') //set title
                                            $('.info-prices-price').html(dataDayClicked?.title) // set gia
                                            $('.info-prices-price-hidden').html(dataDayClicked?.price) // set gia
                                            $('.list-change-price').html(hotelPricesInfo).addClass("show-list-change-price");
                                            $('.list-checkbox-change-price').html(hotelPricesInfo); // set 
                                            $('.custom-edit-price').addClass('show-custom-edit-price');
                                            $('.current-date-selected').val(dataDayClicked?.start);
                                            $('.display-current-date-selected').text(`Ngày đang chọn: ${formatDate_dd_mm_yyyy(dataDayClicked?.start)}`)
                                            $('.price-input-change-date').css('display', 'none').val(Intl.NumberFormat().format(priceStock));
                                            $('.form-hotel-id').val(hotel_id);
                                            $('.form-room-id').val(room_id);
                                            $('.form-room-index').val(rtypename);
                                            $('#form-change-by-date').removeClass('show-form-change')
                                            $('.info-price-and-edit').css('display', 'block');
                                        } else {
                                            $('.info-price-and-edit').css('display', 'none') // an gia cua ngay do
                                            $('.list-change-price').removeClass('show-list-change-price').css('display', 'none') // an list rule cua ngay trc
                                            $('.calendar-container-notification').text("Ngày vừa chọn đang thuộc tháng chưa được tải dữ liệu lên. Về chế độ xem theo giá để tải.")
                                        }
                                    }
                                })
                            }

                            function convert_date_vn_to_en(dateString) {
                                const [, monthIndex, year] = dateString.split(" ");
                                const monthName = new Date(year, parseInt(monthIndex) - 1).toLocaleString('en', { month: 'long' });

                                return `${monthName} ${year}`;
                            }

                            function calendarRecursive(firstDay, lastDay, data, price) {
                                let priceStock = parseInt(price)
                                let result = [];
                                if (firstDay <= lastDay) {
                                    let temp = {};
                                    let listType = [];
                                    let totalPrice = priceStock;
                                    let priceRoomByRule = totalPrice;
                                    let isClosed = false;
                                    firstDay.setDate(firstDay.getDate() + 1);
                                    let encodedFirstDay = firstDay.toISOString().split('T')[0];
                                    let count = 0;
                                    let exitRule = false;
                                    let checkPromo = false;
                                    let checkVoucher = false;
                                    let checkPromoShow = false;
                                    let checkVoucherShow = false;
                                    let priceTemp = 0;
                                    let ruleQueue = [];
                                    let priceRuleTemp = 0;
                                    let priceCheckColor = 0;
                                    if (data.length > 0) { // co bat ky dieu kien gia
                                        data.map((item, index) => {
                                            const key = `${room_id}|${rtypename}|${encodedFirstDay}`
                                            if (item.isLoop == "special" || item.start == encodedFirstDay || ((encodedFirstDay > item.start && firstDay <= new Date(item.end)))) {
                                                if (!!dataChangeJson && dataChangeJson[key]) { // trường hợp ngày custom giá
                                                    temp.inputChange = dataChangeJson[key]['price_change_by_date'] ? dataChangeJson[key]['price_change_by_date'] : null;
                                                    isClosed = dataChangeJson[key]['isClosed'] ? true : false;
                                                    isClosed ? temp.backgroundColor = '#C8C6C6' : temp.backgroundColor = "#85b5cd";
                                                    totalPrice = parseInt(dataChangeJson[key]['price_final']);
                                                    isClosed = dataChangeJson[key]['isClosed'] ? true : false;
                                                    const itemType = item.type;
                                                    const itemTypeId = item.typeId;
                                                    const datadataChangeJsonKey = dataChangeJson[key];
                                                    const listOfType = datadataChangeJsonKey[itemType] ? datadataChangeJsonKey[itemType] : undefined;
                                                    const listChecking = (listOfType && listOfType.idx) ? listOfType.idx : [];
                                                    let itemClone = {};
                                                    if (!listOfType || (listChecking.length > 0 && listChecking.includes(itemTypeId) === false)) {
                                                        itemClone = structuredClone(item);
                                                        itemClone.isUnchecked = true;
                                                        listType.push(itemClone);
                                                        itemClone = {};
                                                    }
                                                    else {
                                                        itemClone = structuredClone(item);
                                                        itemClone.isUnchecked = false;
                                                        listType.push(itemClone);
                                                        itemClone = {};
                                                    }
                                                    count = -1;
                                                } else { // trường hợp ngày chưa custom giá
                                                    let itemClone = structuredClone(item);
                                                    itemClone.isUnchecked = false;
                                                    // listType.push(itemClone);
                                                    switch (itemClone.type) {
                                                        case 'rule':
                                                        listType.push(itemClone);
                                                        break;
                                                        case 'promo':
                                                            if (!checkPromoShow) {
                                                                    listType.push(itemClone);
                                                                    checkPromoShow = true;
                                                                }
                                                            break;
                                                        case 'voucher': 
                                                        if (!checkVoucherShow) {
                                                            listType.push(itemClone);
                                                            checkVoucherShow = true;
                                                        }
                                                        break;
                                                            default:
                                                            break;
                                                    }
                                                    // trường họp type là rule
                                                    if(item.type === 'rule') {
                                                        priceRuleTemp = totalPrice;
                                                        ruleQueue.push(item);
                                                        totalPrice += calculatePrices(totalPrice, priceStock, item.priceObj, item.type);
                                                        priceCheckColor = totalPrice;
                                                    } else {
                                                        if (item.type == 'promo') {
                                                            if (!checkPromo) {
                                                                if(priceRuleTemp !== 0) {
                                                                    totalPrice = priceRuleTemp
                                                                }
                                                                totalPrice += calculatePrices(priceRoomByRule, priceStock, item.priceObj, item.type);
                                                                priceTemp = totalPrice;
                                                                checkPromo = true;
                                                                if (dataHotelPrices && dataHotelPrices.hotel_is_included_fee == "0") {
                                                                    const hotel_fee = parseInt(dataHotelPrices.hotel_fee);
                                                                    priceCheckColor = totalPrice;
                                                                    if(ruleQueue.length > 0) {
                                                                        let priceCalRule = 0;
                                                                        priceCalRule = totalPrice/(100+hotel_fee)*100;
                                                                        totalPrice = priceCalRule;
                                                                        priceCheckColor = priceCalRule;
                                                                        ruleQueue.map(item1 => {
                                                                            totalPrice += calculatePrices(priceCalRule, priceStock, item1.priceObj, item1.type);
                                                                        })
                                                                    } else {
                                                                        priceCheckColor = totalPrice/(100+hotel_fee)*100;
                                                                    }
                                                                } else {
                                                                    priceCheckColor = totalPrice;
                                                                    if(ruleQueue.length > 0) {
                                                                        ruleQueue.map(item1 => {
                                                                            totalPrice += calculatePrices(totalPrice, priceStock, item1.priceObj, item1.type);
                                                                        })
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        if(item.type == 'voucher') {
                                                            if (item.isLoop === 'loop' || item.isLoop === "single") {
                                                                if (!checkVoucher) {
                                                                    if (dataHotelPrices && dataHotelPrices.hotel_is_included_fee == "0") {
                                                                        let priceToCalVoucher;
                                                                        const hotel_fee = parseInt(dataHotelPrices.hotel_fee)
                                                                        if(priceTemp !== 0 ) {
                                                                            totalPrice = priceTemp;
                                                                        }
                                                                        if( priceTemp == 0 && priceRuleTemp !== 0) {
                                                                            totalPrice = priceRuleTemp;
                                                                        }
                                                                        priceToCalVoucher = totalPrice/(100+hotel_fee)*100;
                                                                        if(priceCheckColor !== 0) {
                                                                            priceCheckColor = priceToCalVoucher;
                                                                        }
                                                                        let priceToCalVoucherWithRule = 0;
                                                                        if(ruleQueue.length > 0) {
                                                                            ruleQueue.map(item => {
                                                                                totalPrice = priceToCalVoucher;
                                                                                totalPrice += calculatePrices(priceToCalVoucher, priceStock, item.priceObj, item.type);
                                                                                priceToCalVoucherWithRule = totalPrice;
                                                                            })
                                                                            totalPrice += calculatePrices(priceToCalVoucherWithRule, priceStock, item.priceObj, item.type);
                                                                            totalPrice = totalPrice + totalPrice/100*hotel_fee;
                                                                        } else {
                                                                            totalPrice = priceToCalVoucher;
                                                                            totalPrice += calculatePrices(totalPrice, priceStock, item.priceObj, item.type);
                                                                            totalPrice += totalPrice/100*hotel_fee
                                                                            checkVoucher = true;
                                                                        }
                                                                        
                                                                    } else {
                                                                        let currentPrice = totalPrice;
                                                                        totalPrice += calculatePrices(currentPrice, priceStock, item.priceObj, item.type);
                                                                    }
                                                                }
                                                            }
                                                            else {
                                                                if (!checkVoucher) {
                                                                    if (item.isLoop === 'special' && priceRoomByRule > formatPriceRemoveDot(item.specialObj?.v_price)) {
                                                                        let currentPrice = totalPrice;
                                                                        totalPrice += calculatePrices(currentPrice, priceStock, item.priceObj, item.type);
                                                                    }
                                                                }
                                                            }
                                                            checkVoucher = true;
                                                        }
                                                        // promo vs voucher vai tro nhu nhau nen tinh theo gia cua phong theo rule
                                                        exitRule = true; // lan sau khong cong gia hoa hong vao nua
                                                        count = -1; // da cong hoa hong thi ben duoi k can cong nua
                                                    }
                                                }
                                                temp.start = encodedFirstDay;
                                                temp.end = encodedFirstDay;
                                                temp.type = item.title;
                                                temp.isLoop = item.isLoop;
                                                temp.typeId = item.typeId;
                                                // listType.push(item);
                                            }
                                            else { // truong hop co rule nhung khong thuoc ngay trong data change
                                                if (!!dataChangeJson && dataChangeJson[key]) {
                                                    totalPrice = parseInt(dataChangeJson[key]['price_final']);
                                                    count = -1;
                                                    isClosed = dataChangeJson[key]['isClosed'] ? true : false;
                                                    isClosed ? temp.backgroundColor = '#C8C6C6' : temp.backgroundColor = "#85b5cd";
                                                    temp.inputChange = dataChangeJson[key]['price_change_by_date'] ? dataChangeJson[key]['price_change_by_date'] : null;
                                                }
                                            }
                                            return result;
                                        })
                                    } else { // khong co bat ky dieu kien gia
                                        count = -1;
                                        const key = `${room_id}|${rtypename}|${encodedFirstDay}`
                                        if (dataChangeJson && dataChangeJson[key]) {
                                            totalPrice = parseInt(dataChangeJson[key]['price_final']);
                                            isClosed = dataChangeJson[key]['isClosed'] ? true : false;
                                            isClosed ? temp.backgroundColor = '#C8C6C6' : temp.backgroundColor = "#85b5cd";
                                            temp.inputChange = dataChangeJson[key]['price_change_by_date'] ? dataChangeJson[key]['price_change_by_date'] : null;
                                        }
                                    }

                                    if (count == 0) {
                                        if (dataHotelPrices && dataHotelPrices.hotel_is_included_fee == "0") {
                                            const hotel_fee = parseInt(dataHotelPrices.hotel_fee)
                                            totalPrice = totalPrice + totalPrice / 100 * hotel_fee;
                                        }
                                    }
                                    count = 0;

                                    if (temp.backgroundColor === undefined) {
                                        if (totalPrice > priceCheckColor) {
                                            temp.backgroundColor = '#b34c60'
                                        }
                                        else temp.backgroundColor = '#53B987';

                                        if (isClosed) temp.backgroundColor = '#C8C6C6';
                                    }
                                    temp.start = encodedFirstDay;
                                    temp.end = encodedFirstDay;
                                    temp.title = isClosed ? 'Tạm đóng' : `${Math.round(totalPrice).toLocaleString('en-US', { currency: 'VND' })} VND`;
                                    temp.isClosed = isClosed;
                                    temp.price = totalPrice;
                                    temp.detail = listType;
                                    result.push(temp);
                                    totalPrice = priceStock;
                                    temp = {};
                                    listType = [];

                                    result.push(...calendarRecursive(firstDay, lastDay, data, price));
                                }
                                return result;
                            }

                            function calendarForRuleRecursive(firstDay, lastDay, data, price) {
                                let priceStock = parseInt(price)
                                let result = [];
                                if (firstDay <= lastDay) {
                                    let temp = {};
                                    let tempRule = {};
                                    let listType = [];
                                    let isClosed = false;
                                    let totalPrice = priceStock;
                                    let priceRoomByRule = totalPrice;
                                    let count = 0;
                                    let priceTemp = 0;
                                    let priceRuleTemp = 0;
                                    let checkPromo = false;
                                    let checkVoucher = false;
                                    let checkPromoShow = false;
                                    let checkVoucherShow = false;
                                    let exitRule = false;
                                    let ruleQueue = [];
                                    let priceCheckColor = 0;
                                    firstDay.setDate(firstDay.getDate() + 1);
                                    let encodedFirstDay = firstDay.toISOString().split('T')[0];
                                    if (data.length > 0) {
                                        data.map((item, index) => {
                                            const key = `${room_id}|${rtypename}|${encodedFirstDay}`
                                            if (item.isLoop == "special" || item.start == encodedFirstDay || ((encodedFirstDay > item.start && firstDay <= new Date(item.end)))) {
                                                if (!!dataChangeJson && dataChangeJson[key]) {
                                                    temp.inputChange = dataChangeJson[key]['price_change_by_date'] ? dataChangeJson[key]['price_change_by_date'] : null;
                                                    totalPrice = parseInt(dataChangeJson[key]['price_final']);
                                                    isClosed = dataChangeJson[key]['isClosed'] ? true : false;
                                                    const itemType = item.type;
                                                    const itemTypeId = item.typeId;
                                                    const datadataChangeJsonKey = dataChangeJson[key];
                                                    const listOfType = datadataChangeJsonKey[itemType];
                                                    const listChecking = (listOfType && listOfType.idx) ? listOfType.idx : [];
                                                    if (listOfType == undefined || (listChecking.length !== 0 && listChecking.includes(itemTypeId) === false)) {
                                                        let itemClone = structuredClone(item);
                                                        itemClone.isUnchecked = true;
                                                        isClosed ? temp.backgroundColor = '#C8C6C6' : temp.backgroundColor = "#85b5cd";
                                                        listType.push(itemClone);
                                                    }
                                                    else {
                                                        let itemClone = structuredClone(item);
                                                        itemClone.isUnchecked = false;
                                                        listType.push(itemClone);
                                                    }
                                                    count = -1;
                                                } else {
                                                    // item.isUnchecked = false;
                                                    let itemClone = structuredClone(item);
                                                    itemClone.isUnchecked = false;
                                                    // listType.push(itemClone);
                                                    switch (itemClone.type) {
                                                        case 'rule':
                                                        listType.push(itemClone);
                                                        break;
                                                        case 'promo':
                                                            if (!checkPromoShow) {
                                                                    listType.push(itemClone);
                                                                    checkPromoShow = true;
                                                                }
                                                            break;
                                                        case 'voucher': 
                                                        if (!checkVoucherShow) {
                                                            listType.push(itemClone);
                                                            checkVoucherShow = true;
                                                        }
                                                        break;
                                                            default:
                                                            break;
                                                    }

                                                if(item.type === 'rule') {
                                                    priceRuleTemp = totalPrice;
                                                    ruleQueue.push(item);
                                                    totalPrice += calculatePrices(totalPrice, priceStock, item.priceObj, item.type);
                                                    priceCheckColor = totalPrice;
                                                } else {
                                                    if (item.type == 'promo') {
                                                        if (!checkPromo) {
                                                            if(priceRuleTemp !== 0) {
                                                                totalPrice = priceRuleTemp
                                                            }
                                                            totalPrice += calculatePrices(priceRoomByRule, priceStock, item.priceObj, item.type);
                                                            priceTemp = totalPrice;
                                                            checkPromo = true;
                                                            if (dataHotelPrices && dataHotelPrices.hotel_is_included_fee == "0") {
                                                                const hotel_fee = parseInt(dataHotelPrices.hotel_fee);
                                                                priceCheckColor = totalPrice;
                                                                if(ruleQueue.length > 0) {
                                                                    let priceCalRule = 0;
                                                                    priceCalRule = totalPrice/(100+hotel_fee)*100;
                                                                    totalPrice = priceCalRule;
                                                                    priceCheckColor = priceCalRule;
                                                                    ruleQueue.map(item1 => {
                                                                        totalPrice += calculatePrices(priceCalRule, priceStock, item1.priceObj, item1.type);
                                                                    })
                                                                } else {
                                                                    priceCheckColor = totalPrice/(100+hotel_fee)*100;
                                                                }
                                                            } else {
                                                                priceCheckColor = totalPrice;
                                                                if(ruleQueue.length > 0) {
                                                                    ruleQueue.map(item1 => {
                                                                        totalPrice += calculatePrices(totalPrice, priceStock, item1.priceObj, item1.type);
                                                                    })
                                                                }
                                                            }
                                                        }
                                                    }

                                                        else {
                                                            if (item.isLoop === 'loop' || item.isLoop === "single") {
                                                                if (!checkVoucher) {
                                                                    if (dataHotelPrices && dataHotelPrices.hotel_is_included_fee == "0") {
                                                                        let priceToCalVoucher;
                                                                        const hotel_fee = parseInt(dataHotelPrices.hotel_fee)
                                                                        if(priceTemp !== 0 ) {
                                                                            totalPrice = priceTemp;
                                                                        }
                                                                        if( priceTemp == 0 && priceRuleTemp !== 0) {
                                                                            totalPrice = priceRuleTemp;
                                                                        }
                                                                        priceToCalVoucher = totalPrice/(100+hotel_fee)*100;
                                                                        if(priceCheckColor !== 0) {
                                                                            priceCheckColor = priceToCalVoucher;
                                                                        }
                                                                        let priceToCalVoucherWithRule = 0;
                                                                        if(ruleQueue.length > 0) {
                                                                            ruleQueue.map(item => {
                                                                                totalPrice = priceToCalVoucher;
                                                                                totalPrice += calculatePrices(priceToCalVoucher, priceStock, item.priceObj, item.type);
                                                                                priceToCalVoucherWithRule = totalPrice;
                                                                            })
                                                                            totalPrice += calculatePrices(priceToCalVoucherWithRule, priceStock, item.priceObj, item.type);
                                                                            totalPrice = totalPrice + totalPrice/100*hotel_fee;
                                                                        } else {
                                                                            totalPrice = priceToCalVoucher;
                                                                            totalPrice += calculatePrices(totalPrice, priceStock, item.priceObj, item.type);
                                                                            totalPrice += totalPrice/100*hotel_fee
                                                                            checkVoucher = true;
                                                                        }
                                                                        
                                                                    } else {
                                                                        let currentPrice = totalPrice;
                                                                        totalPrice += calculatePrices(currentPrice, priceStock, item.priceObj, item.type);
                                                                    }
                                                                }
                                                            }
                                                            else {
                                                                if (!checkVoucher) {
                                                                    if (item.isLoop === 'special' && priceRoomByRule > formatPriceRemoveDot(item.specialObj?.v_price)) {
                                                                        let currentPrice = totalPrice;
                                                                        totalPrice += calculatePrices(currentPrice, priceStock, item.priceObj, item.type);
                                                                        checkVoucher = true;
                                                                    }
                                                                }
                                                            }
                                                        }

                                                        // promo vs voucher vai tro nhu nhau nen tinh theo gia cua phong theo rule
                                                        exitRule = true; // lan sau khong cong gia hoa hong vao nua
                                                        count = -1; // da cong hoa hong thi ben duoi k can cong nua
                                                    }
                                                }
                                                temp.start = encodedFirstDay;
                                                temp.end = encodedFirstDay;
                                                temp.type = item.title;
                                                temp.isLoop = item.isLoop;
                                                temp.typeId = item.typeId;
                                                // listType.push(item);
                                            }
                                            return result;
                                        })
                                    }
                                    else { // khong co bat ky dieu kien gia
                                        count = -1;
                                        const key = `${room_id}|${rtypename}|${encodedFirstDay}`
                                        if (dataChangeJson && dataChangeJson[key]) {
                                            totalPrice = parseInt(dataChangeJson[key]['price_final']);
                                            isClosed = dataChangeJson[key]['isClosed'] ? true : false;
                                            isClosed ? temp.backgroundColor = '#C8C6C6' : temp.backgroundColor = "#85b5cd";
                                            temp.inputChange = dataChangeJson[key]['price_change_by_date'] ? dataChangeJson[key]['price_change_by_date'] : null;
                                        }
                                    }

                                    if (count == 0) {
                                        if (dataHotelPrices && dataHotelPrices.hotel_is_included_fee == "0") {
                                            const hotel_fee = parseInt(dataHotelPrices.hotel_fee)
                                            totalPrice = totalPrice + totalPrice / 100 * hotel_fee;
                                        }
                                        count = 0;
                                    }

                                    if (temp.backgroundColor === undefined) {
                                        if (totalPrice > priceCheckColor) {
                                            temp.backgroundColor = '#b34c60'
                                        }
                                        else temp.backgroundColor = '#53B987';

                                        if (isClosed) temp.backgroundColor = '#C8C6C6';
                                    }

                                    temp.start = encodedFirstDay;
                                    temp.end = encodedFirstDay;
                                    temp.title = isClosed ? 'Tạm đóng' : `Giá`;
                                    temp.titlePrice = `${Math.round(totalPrice).toLocaleString('en-US', { currency: 'VND' })} VND`
                                    temp.isClosed = isClosed;
                                    // if(isClosed) temp.backgroundColor = "#C8C6C6";
                                    temp.price = totalPrice;
                                    temp.detail = listType;
                                    temp.type = 'price';

                                    tempRule.start = encodedFirstDay;
                                    tempRule.end = encodedFirstDay;
                                    tempRule.title = `Điều kiện (${listType.length})`;
                                    tempRule.type = 'condition'
                                    tempRule.detail = listType;
                                    tempRule.backgroundColor = '#213555';
                                    result.push(tempRule);
                                    result.push(temp);
                                    totalPrice = priceStock;
                                    temp = {};
                                    tempRule = {}
                                    listType = [];

                                    result.push(...calendarForRuleRecursive(firstDay, lastDay, data, price));
                                }
                                return result;
                            }



                            function setDisplayPriceAfterChange(price) {
                                $('.info-prices-price-hidden').text(price);
                                $('.form-price-final').val(price);
                                $('.info-prices-price').text(`${Math.round(price).toLocaleString('en-US', { currency: 'VND' })} VND`);
                            }

                            function setViewPriceAfterChange(price, inputprice) {
                                $('.info-prices-price-hidden').text(price);
                                $('.form-price-final').val(price);
                                $('.info-prices-price').text(`${Math.round(inputprice).toLocaleString('en-US', { currency: 'VND' })} VND`);
                            }

                            function checkExistPromoVoucher(type) {
                                let count = 0;
                                if(type == 'rule') {
                                    return false;
                                }
                                else {
                                    const arrChecked = $('input[type=hidden].input-hidden');
                                    arrChecked.map((item, index) => {
                                        const elementItem = index;
                                        if (elementItem.getAttribute('type') == "hidden" && index.dataset.condition == type && elementItem.value == '1') {
                                            count++;
                                        }
                                    })
                                    if(count == 0) {
                                    return false;
                                    } 
                                    else { 
                                        return true; 
                                    }
                                }
                                
                            }

                            function update_price() {
                                const inputPrice = parseInt($('.price-input-change-date').val().replace(',', '').replace(',', ''));
                                let arrElementChecked = $('input[type=hidden].input-hidden');
                                let totalPrice = inputPrice; // gia cua input
                                let priceRoomByRule = totalPrice;
                                let checkAddFee = false;
                                let totalChangeRule = 0;
                                arrElementChecked.map(function () {
                                    if (this.value === '1') {
                                        let priceObj = {};
                                        priceObj.suffix = this.getAttribute('data-suffix') || undefined;
                                        priceObj.price_vnd = this.getAttribute('data-price_vnd') || undefined;
                                        priceObj.price_percent = this.getAttribute('data-price_percent') || undefined;
                                        priceObj.voucher_price = this.getAttribute('data-voucher_price') || undefined;
                                        priceObj.voucher_percent = this.getAttribute('data-voucher_percent') || undefined;
                                        priceObj.voucher_type = this.getAttribute('data-voucher_type') || undefined;
                                        priceObj.condition = this.getAttribute('data-condition') || undefined;
                                        priceObj.type = this.getAttribute('data-type') || undefined;
                                        if (priceObj.condition === 'rule') {
                                            totalPrice += calculatePrices(totalPrice, inputPrice, priceObj, priceObj.condition);
                                            totalChangeRule += calculatePrices(totalPrice, inputPrice, priceObj, priceObj.condition);
                                            $('.form-price-change-rule').val(totalChangeRule)
                                            priceRoomByRule = totalPrice
                                        }
                                        else { // promo vs voucher vai tro nhu nhau nen tinh theo gia cua phong theo rule
                                            if (!checkAddFee) {
                                                if (dataHotelPrices && dataHotelPrices.hotel_is_included_fee == "0") {
                                                    const hotel_fee = parseInt(dataHotelPrices.hotel_fee)
                                                    const priceRose = totalPrice / 100 * hotel_fee;
                                                    totalPrice = totalPrice + totalPrice / 100 * hotel_fee;
                                                    $('.form-price-change-rose').val(priceRose);
                                                    priceRoomByRule = totalPrice
                                                } 
                                                if (dataHotelPrices && dataHotelPrices.hotel_is_included_fee == "1") {
                                                    $('.form-price-change-rose').val(0);
                                                }
                                                if(priceObj.condition === 'promo') {
                                                    totalPrice += calculatePrices(priceRoomByRule, priceStock, priceObj, priceObj.condition);
                                                    $('.form-price-change-promo').val(calculatePrices(priceRoomByRule, priceStock, priceObj, priceObj.condition))
                                                }
                                                if(priceObj.condition === 'voucher') {
                                                    totalPrice += calculatePrices(priceRoomByRule, priceStock, priceObj, priceObj.condition);
                                                    $('.form-price-change-voucher').val(calculatePrices(priceRoomByRule, priceStock, priceObj, priceObj.condition))
                                                }
                                                checkAddFee = true;
                                                
                                            } else {
                                                if(priceObj.condition === 'promo') {
                                                    totalPrice += calculatePrices(priceRoomByRule, priceStock, priceObj, priceObj.condition);
                                                    $('.form-price-change-promo').val(calculatePrices(priceRoomByRule, priceStock, priceObj, priceObj.condition))
                                                }
                                                if(priceObj.condition === 'voucher') {
                                                    totalPrice += calculatePrices(priceRoomByRule, priceStock, priceObj, priceObj.condition);
                                                    $('.form-price-change-voucher').val(calculatePrices(priceRoomByRule, priceStock, priceObj, priceObj.condition))
                                                } 
                                            }
                                        }
                                    }
                                })

                                if (!checkAddFee) {
                                    if (dataHotelPrices && dataHotelPrices.hotel_is_included_fee == "0") {
                                        const hotel_fee = parseInt(dataHotelPrices.hotel_fee)
                                        totalPrice = totalPrice + totalPrice / 100 * hotel_fee;
                                    }
                                }
                                return setDisplayPriceAfterChange(totalPrice);
                            }

                            function update_price_final() {
                                const inputPrice = parseInt($('.price-input-change-final').val().replace(',', '').replace(',', ''));
                                let arrElementChecked = $('input[type=hidden].input-hidden');
                                let totalPrice = inputPrice;
                                let inputPriceShow = inputPrice;
                                if (dataHotelPrices && dataHotelPrices.hotel_is_included_fee == "0") {
                                    const hotel_fee = parseInt(dataHotelPrices.hotel_fee)
                                    inputPriceShow = inputPriceShow + inputPriceShow/100*hotel_fee;
                                    totalPrice = inputPriceShow;
                                }
                                 // gia cua input
                                let priceRoomByRule = totalPrice;
                                let checkAddFee = false;
                                let totalChangeRule = 0;
                                let voucherByPercent = false;
                                let voucherPercentSave = 0;
                                let hasPromo = false;
                                let hasRule = false;
                                if(arrElementChecked.length == 0) {
                                    if (dataHotelPrices && dataHotelPrices.hotel_is_included_fee == "0") {
                                        $('.form-price-standard').val(totalPrice)
                                        const hotel_fee = parseInt(dataHotelPrices.hotel_fee)
                                        totalPrice = (totalPrice * 100) / (100 + hotel_fee);
                                        const priceRose = totalPrice / 100 * hotel_fee;
                                        const roundedPriceRose = Math.round(priceRose);
                                        $('.form-price-change-rose').val(roundedPriceRose);
                                    }
                                } else {
                                    for (let i = arrElementChecked.length - 1; i >= 0; i--) {
                                        let priceObj = {};
                                        priceObj.suffix = arrElementChecked[i].getAttribute('data-suffix') || undefined;
                                        priceObj.price_vnd = arrElementChecked[i].getAttribute('data-price_vnd') || undefined;
                                        priceObj.price_percent = arrElementChecked[i].getAttribute('data-price_percent') || undefined;
                                        priceObj.voucher_price = arrElementChecked[i].getAttribute('data-voucher_price') || undefined;
                                        priceObj.voucher_percent = arrElementChecked[i].getAttribute('data-voucher_percent') || undefined;
                                        priceObj.voucher_type = arrElementChecked[i].getAttribute('data-voucher_type') || undefined;
                                        priceObj.condition = arrElementChecked[i].getAttribute('data-condition') || undefined;
                                        priceObj.type = arrElementChecked[i].getAttribute('data-type') || undefined;
                                        if(priceObj.condition == 'voucher' && priceObj.voucher_type !== '1') {
                                            voucherByPercent = true;
                                            voucherPercentSave = parseInt(priceObj.voucher_percent);
                                        }
                                        if(priceObj.condition == 'voucher' && priceObj.voucher_type == '1') {
                                            totalPrice += parseInt(priceObj.voucher_price);
                                            voucherPercentSave = 0;
                                            $('.form-price-change-voucher').val(Math.round(parseInt(priceObj.voucher_price)))
                                        }
                                        if(priceObj.condition == 'promo') {
                                            const promoPercent = parseInt(priceObj.price_percent)
                                            if(voucherByPercent) {
                                                totalPrice = (totalPrice / (100 - promoPercent - voucherPercentSave)) * 100;
                                                const priceChangeVoucher = totalPrice * voucherPercentSave / 100;
                                                const priceChangrPromo = totalPrice * promoPercent / 100;
                                                $('.form-price-change-voucher').val(Math.round(-priceChangeVoucher));
                                                $('.form-price-change-promo').val(Math.round(-priceChangrPromo));
                                            } else {
                                                const totalAfterPromo = totalPrice;
                                                totalPrice = (totalPrice / (100 - promoPercent)) * 100;
                                                $('.form-price-change-promo').val(Math.round(totalPrice - totalAfterPromo))
                                            }
                                            hasPromo = true;
                                        }
                                        if(priceObj.condition == 'rule') {
                                            $('.form-price-standard').val(totalPrice)
                                            if (dataHotelPrices && dataHotelPrices.hotel_is_included_fee == "0") {
                                                const hotel_fee = parseInt(dataHotelPrices.hotel_fee)
                                                totalPrice = (totalPrice * 100) / (100 + hotel_fee);
                                                const priceRose = totalPrice / 100 * hotel_fee;
                                                const roundedPriceRose = Math.round(priceRose);
                                                $('.form-price-change-rose').val(roundedPriceRose);
                                            }
                                            totalPrice += calculatePricesBack(totalPrice, totalPrice, priceObj, priceObj.condition)
                                            totalChangeRule += calculatePricesBack(totalPrice, totalPrice, priceObj, priceObj.condition)
                                            $('.form-price-change-rule').val(Math.round(-totalChangeRule));
                                            hasRule = true
                                        }
                                    }

                                    if(!hasRule) {
                                        $('.form-price-standard').val(totalPrice)
                                        if (dataHotelPrices && dataHotelPrices.hotel_is_included_fee == "0") {
                                            const hotel_fee = parseInt(dataHotelPrices.hotel_fee)
                                            totalPrice = (totalPrice * 100) / (100 + hotel_fee);
                                            const priceRose = totalPrice / 100 * hotel_fee;
                                            const roundedPriceRose = Math.round(priceRose);
                                            $('.form-price-change-rose').val(roundedPriceRose);
                                        }
                                    }
                                }
                                const roundedPrice = Math.round(totalPrice);
                                if (dataHotelPrices && dataHotelPrices.hotel_is_included_fee == "0") {
                                    const hotel_fee = parseInt(dataHotelPrices.hotel_fee)
                                    const priceWithRose = inputPrice + inputPrice/100*hotel_fee;
                                    // $('.info-price-rose-price').text(priceWithRose)
                                    $('.info-price-rose-container').css('display', 'block')
                                    $('.info-price-rose-price').text(`${formatPriceWithDot(priceWithRose)} VND` )
                                }
                                $('.price-input-change-date').val(roundedPrice.formatCurrency())
                                // return setDisplayPriceAfterChange(inputPriceShow);
                                return setViewPriceAfterChange(inputPriceShow, inputPrice)
                            }


                            function calculatePrices(currentPrice, priceStock, priceObj, condition) {
                                let caculatedPrice = 0;
                                // Gia se duoc tinh theo thu tu rule --> promo  ==== voucher
                                // Process rule
                                if (condition === 'rule') {
                                    const priceVnd = parseInt(priceObj.price_vnd)
                                    const pricePercent = parseInt(priceObj.price_percent)
                                    if (priceObj.suffix === 'VND') // suffix VND
                                    {
                                        if (priceObj.type === '+') {
                                            caculatedPrice = priceVnd
                                        } else {
                                            caculatedPrice = -priceVnd;
                                        }
                                    } else { // suffix %
                                        let caculatedPricePercent = (currentPrice * pricePercent) / 100;
                                        if (priceObj.type === '+') {
                                            caculatedPrice = caculatedPricePercent;
                                        } else {
                                            caculatedPrice = -caculatedPricePercent;
                                        }
                                    }
                                }

                                // Process promo
                                if (condition === 'promo') {
                                    const promoPercent = parseInt(priceObj.price_percent)
                                    const pricePercent = (currentPrice * promoPercent) / 100;
                                    caculatedPrice = -pricePercent;
                                }

                                // Process voucher
                                if (condition === 'voucher') {
                                    const voucherPrice = priceObj.voucher_price
                                    const voucherPercent = priceObj.voucher_percent
                                    if (priceObj.voucher_type == 1) {
                                        caculatedPrice = -voucherPrice;
                                    } else {
                                        let pricePercent = (currentPrice * voucherPercent) / 100;
                                        caculatedPrice = -pricePercent;
                                    }
                                }
                                return caculatedPrice;
                            }

                            function calculatePricesBack(currentPrice, priceStock, priceObj, condition) {
                                let caculatedPrice = 0;
                                if (condition === 'rule') {
                                    const priceVnd = parseInt(priceObj.price_vnd)
                                    const pricePercent = parseInt(priceObj.price_percent)
                                    if (priceObj.suffix === 'VND') // suffix VND
                                    {
                                        if (priceObj.type === '+') {
                                            caculatedPrice = -priceVnd
                                        } else {
                                            caculatedPrice = priceVnd;
                                        }
                                    } else { // suffix %
                                        let caculatedPricePercent = (currentPrice / (100- pricePercent) * 100);
                                        if (priceObj.type === '+') {
                                            caculatedPrice = -caculatedPricePercent;
                                        } else {
                                            caculatedPrice = +caculatedPricePercent;
                                        }
                                    }
                                }
                                return caculatedPrice;
                            }

                            let nowDay = new Date();
                            let startDay = new Date();
                            let firstDay = new Date(nowDay.getFullYear(), nowDay.getMonth(), 1);
                            let lastDay = new Date(firstDay.getFullYear(), firstDay.getMonth() + 1, 0);
                            // lastDay = new Date(firstDay.setDate(firstDay.getDate() + 30));  
                            let dataFilter = calendarRecursive(firstDay, lastDay, arrData, priceStock);
                            let firstDay2 = new Date(nowDay.getFullYear(), nowDay.getMonth(), 1);
                            let lastDay2 = new Date(firstDay2.getFullYear(), firstDay2.getMonth() + 1, 0);
                            let dataFilterRule = calendarForRuleRecursive(firstDay2, lastDay2, arrData, priceStock)

                            $('body').on('click', 'button.fc-prev-button', function () { // handle click prev month
                                let currentMonth = $('.fc-toolbar .fc-center').text();
                                currentMonth = convert_date_vn_to_en(currentMonth);
                                let startDayOfMonth = new Date(currentMonth);
                                let startDayNext = new Date(startDayOfMonth.getFullYear(), startDayOfMonth.getMonth(), 1);
                                let lastDayNext = new Date(startDayOfMonth.getFullYear(), startDayOfMonth.getMonth() + 1, 0);
                                let dataFilterNext = [];
                                if ($('.button-view-by-price').hasClass('button-view-by-active')) {

                                    dataFilterNext = calendarRecursive(startDayNext, lastDayNext, arrData, priceStock);
                                    if (!checkMonthLoaded(dataFilter, dataFilterNext)) {
                                        let dataFilterNew = dataFilter.concat(dataFilterNext);
                                        dataFilter = dataFilterNew;
                                    }
                                    refeshDataCalendar("#calendar_detail", dataFilter, currentMonth);
                                }
                                if ($('.button-view-by-rule').hasClass('button-view-by-active')) {
                                    dataFilterNext = calendarForRuleRecursive(startDayNext, lastDayNext, arrData, priceStock);
                                    if (!checkMonthLoaded(dataFilterRule, dataFilterNext)) {
                                        let dataFilterNew = dataFilterRule.concat(dataFilterNext);
                                        dataFilterRule = dataFilterNew;
                                    }
                                    refeshDataCalendar_by_rule("#calendar_detail_by_rule", dataFilterRule, dataFilter, currentMonth);
                                }
                            });

                            $('body').on('click', 'button.fc-next-button', function () { // handle click next month
                                let currentMonth = $('.fc-toolbar .fc-center').text();
                                currentMonth = convert_date_vn_to_en(currentMonth);
                                let startDayOfMonth = new Date(currentMonth);
                                let startDayNext = startDayOfMonth;
                                let lastDayNext = new Date(startDayOfMonth.getFullYear(), startDayOfMonth.getMonth() + 1, 0);
                                let dataFilterNext = [];
                                if ($('.button-view-by-price').hasClass('button-view-by-active')) {
                                    dataFilterNext = calendarRecursive(startDayNext, lastDayNext, arrData, priceStock);
                                    if (!checkMonthLoaded(dataFilter, dataFilterNext)) {
                                        let dataFilterNew = dataFilter.concat(dataFilterNext);
                                        dataFilter = dataFilterNew;
                                    }
                                    refeshDataCalendar("#calendar_detail", dataFilter, currentMonth);
                                }
                                if ($('.button-view-by-rule').hasClass('button-view-by-active')) {
                                    dataFilterNext = calendarForRuleRecursive(startDayNext, lastDayNext, arrData, priceStock);
                                    if (!checkMonthLoaded(dataFilterRule, dataFilterNext)) {
                                        let dataFilterNew = dataFilterRule.concat(dataFilterNext);
                                        dataFilterRule = dataFilterNew;
                                    }
                                    refeshDataCalendar_by_rule("#calendar_detail_by_rule", dataFilterRule, dataFilter, currentMonth);
                                }
                            });

                            // handle click icon close form
                            $('.close-form-change-price').on('click', function () {
                                $('#form-change-by-date').removeClass('show-form-change');
                                $('.list-change-price').addClass('show-list-change-price');
                                $('.box-form-update-room-price-by-calendar input[type=checkbox]').attr('disabled', true);
                                $('.info-price-and-edit').css('display', 'block');
                                $('.list-change-price').css('display', 'block')
                            })

                            $('.custom-edit-price').on('click', function () {
                                // $('.price-input-change-date').css('display', 'block');
                                $('.price-input-change-date').css('display', 'none');
                                // $('.box-form-update-room-price-by-calendar input[type=checkbox]').removeAttr('disabled');
                                $('.box-form-update-room-price-by-calendar input[type=checkbox]#isClosed').removeAttr('disabled');
                                $('#form-change-by-date').addClass('show-form-change');
                                $('.list-change-price').removeClass('show-list-change-price');
                                $('.list-change-price').css('display', 'none').empty();
                            })

                            $('.close-popup-info-show-info-rule').on('click', function () {
                                $('.popup-info-show-info-rule').css('display', 'none')
                            })

                            $('.submit-change-by-date').on('click', function () {
                                // update_price();
                                Swal.fire({
                                    title: 'Bạn có chắc muốn cập nhật giá phòng ?',
                                    icon: 'warning',
                                    showCancelButton: true,
                                    confirmButtonColor: '#3085d6',
                                    cancelButtonColor: '#d33',
                                    confirmButtonText: 'Đồng ý',
                                    cancelButtonText: 'Hủy',
                                }).then(function (result) {
                                    if (result.value) {
                                        const form_data = $('form').serialize();
                                        let obj_data_list = { action: 'admin_hotel_room_price_change_from_calendar', data: form_data };
                                        var is_finished_data = false;
                                        $('.submit-change-by-date').html("<i class='fa fa-spin fa-spinner'></i>")
                                        $.post(adminurl, obj_data_list, function () {
                                            //success
                                        })
                                            .done(function () { is_finished_data = true; })
                                            .fail(function (data_results) { is_finished_data = false; })
                                            .always(function (data_results) {
                                                if (is_finished_data) {
                                                    var str_date_selected = $(".current-date-selected").val();
                                                    var str_date_selected_format = formatDate_dd_mm_yyyy(str_date_selected);
                                                    var str_price_final_format = $('.info-prices-price').text();
                                                    $(".fc-event-container a.fc-day-grid-event."+str_date_selected_format+" .fc-content .fc-title").text(str_price_final_format);
                                                    $(".fc-event-container a.fc-day-grid-event."+str_date_selected_format).css({background:'#85b5cd'});
                                                    Swal.fire('Cập nhật thành công', '', 'success')
                                                }
                                                $('.submit-change-by-date').text("Lưu")
                                            });
                                    }
                                });
                            })


                            $('.reset-change-by-date').on('click', function () {
                                update_price();
                                Swal.fire({
                                    title: 'Bạn có chắc muốn đặt giá phòng về ban đầu không ?',
                                    icon: 'warning',
                                    showCancelButton: true,
                                    confirmButtonColor: '#3085d6',
                                    cancelButtonColor: '#d33',
                                    confirmButtonText: 'Đồng ý',
                                    cancelButtonText: 'Hủy',
                                }).then(function (result) {
                                    if (result.value) {
                                        const form_data = $('form').serialize();
                                        let obj_data_list = { action: 'admin_hotel_room_price_reset_change_from_calendar', data: form_data };
                                        var is_finished_data = false;
                                        $('.reset-change-by-date').html("<i class='fa fa-spin fa-spinner'></i>")
                                        $.post(adminurl, obj_data_list, function () {
                                        })
                                        .done(function () { is_finished_data = true; })
                                        .fail(function (data_results) { is_finished_data = false; })
                                        .always(function (data_results) {
                                            if (is_finished_data) {
                                                Swal.fire('Đặt lại giá phòng thành công', '', 'success')
                                                    .then(function () { $('.closeButton').click() })
                                            }
                                            $('.reset-change-by-date').text("Đặt lại giá")
                                        });
                                    }
                                });
                            })
                            
                            // Change input edit price
                            $('body').on('change', '.price-input-change-date', function () {
                                update_price();
                            })

                            // Change input edit price final
                            $('body').on('change', '.price-input-change-final', function () {
                                update_price_final();
                            })

                            // check/uncheck rule, promo, voucher
                            $('#form-change-by-date').on('change', '.list-checkbox-change-price input[type=checkbox]', function () {
                                let check = false;
                                const nameThis = $(this).attr('name');
                                const hiddenInput = $('input[type="hidden"][name="' + nameThis + '"]')
                                if (this.checked) {
                                    $(this).val('1')
                                    const dataChecked =  hiddenInput.data('condition');
                                    check = checkExistPromoVoucher(dataChecked);
                                    if(!check) {
                                        hiddenInput.attr("value","1")
                                        update_price();
                                    } else {
                                        hiddenInput.attr('value', '0')
                                        $(this).val('0').removeAttr('checked');
                                        this.checked = false;
                                        Swal.fire({
                                            icon: 'error',
                                            title: 'Thông báo',
                                            text: 'Giá chỉ được áp dụng duy nhất một Promo và Voucher!, nếu có lỗi không mong muốn hãy chọn lại ngày và thử lại!',
                                        })
                                    }
                                } else {
                                    $(this).val('0')
                                    $(this).removeAttr('checked');
                                    hiddenInput.attr('value','0')
                                    update_price();
                                }
                                // $(this).off('change')
                            })

                            $('.button-view-by-rule').on('click', function () {
                                $('.list-change-price').empty();
                                $('.info-prices-title').empty();
                                $('.info-prices-price').empty();
                                $('.display-current-date-selected').empty();
                                $('.calendar-container-notification').empty();
                                $('.custom-edit-price').removeClass('show-custom-edit-price');
                                refeshDataCalendar_by_rule('#calendar_detail_by_rule', dataFilterRule, dataFilter, nowDay);
                                $('.button-view-by-price').removeClass('button-view-by-active')
                                $(this).addClass('button-view-by-active')
                                $('.calendar-container-note-by-price').css('display', 'none')
                                $('.calendar-container-note-by-rule').css('display', 'flex')
                            })

                            $('.button-view-by-price').on('click', function () {
                                $('#calendar_detail_by_rule').fullCalendar("destroy");
                                refeshDataCalendar("#calendar_detail", dataFilter, nowDay);
                                $('.button-view-by-rule').removeClass('button-view-by-active')
                                $(this).addClass('button-view-by-active');
                                $('.list-change-price').html("Chọn ngày để xem chi tiết về thay đổi giá phòng.");
                                $('.info-show-info-rule').empty();
                                $('.calendar-container-notification').empty();
                                $('.display-current-date-selected').empty();
                                $('.calendar-container-note-by-price').css('display', 'flex')
                                $('.calendar-container-note-by-rule').css('display', 'none');
                                $('.popup-info-show-info-rule').css('display', 'none')
                            })

                            refeshDataCalendar("#calendar_detail", dataFilter, nowDay) // init calendar current
                        })
                        .catch(function (error) {
                            // Handle the error if needed
                            console.error('Error');
                        });
                }
                else if ($(this).hasClass("on-detail")) {
                    $(this).removeClass("on-detail");
                    $("#calendar_detail").fullCalendar('destroy');
                    $('.list-change-price').html("Chọn ngày để xem chi tiết về thay đổi giá phòng.");
                    $('.info-prices-title').empty();
                    $('.info-prices-price').empty();
                    $('.display-current-date-selected').empty();
                    $('#form-change-by-date').removeClass('show-form-change');
                    $('.custom-edit-price').removeClass('show-custom-edit-price');
                    $('.button-view-by-rule').removeClass('button-view-by-active');
                    $('#popup-detail-rp').css('display', 'none');
                }
                else {
                    e.preventDefault();
                }
            });
        });
    },
    close_popup_button: function () {
        $('#form-change-by-date').off('change', '.list-checkbox-change-price input[type=checkbox]')
        $(".info-price-and-edit").css('display', 'none');
        $('#calendar_detail').fullCalendar("destroy");
        $('#calendar_detail_by_rule').fullCalendar("destroy");
        $('.info-show-info-rule').empty();
        $('.display-current-date-selected').empty();
        $('.list-checkbox-change-price').empty();
        $('.list-change-price').empty();
        $('.close-form-change-price').click();
        $('.list-change-price').removeClass('show-list-change-price');
        $('.list-checkbox-change-price input[type=checkbox]').off("change")
        $('.btn-show-detail').removeClass('on-detail');
        $('#popup-detail-rp').css('display', 'none');
        $('.info-price-and-edit').css('display', 'none');
    }
}

ADMIN_HOTEL_EXTEND.init();


async function fetchData(urlHotelPrices, urlChangeHotelPrices) {
    let dataChangeHotelPrices;
    let dataHotelPrices;
    try {
        $('#calendar_detail').html("<i class='fa fa-spin fa-spinner fa-2x'></i>")
        const response1 = await fetch(urlHotelPrices, {
            headers: {
                'Cache-Control': 'no-cache'
            }
        });
        const text1 = await response1.text();
        dataHotelPrices = text1 !== '' ? JSON.parse(text1) : null;

        const response2 = await fetch(urlChangeHotelPrices, {
            headers: {
                'Cache-Control': 'no-cache'
            }
        });
        if (!response2.redirected) {
            const text2 = await response2.text();
            dataChangeHotelPrices = !!text2 ? JSON.parse(text2) : null;
        }
        else {
            dataChangeHotelPrices = {}
        }
        $('#calendar_detail').empty();
        return [dataHotelPrices, dataChangeHotelPrices];
    } catch (error) {
        console.error("Data change price not exist...")
        dataChangeHotelPrices = {};
        return [dataHotelPrices, dataChangeHotelPrices]
    }
}