1/* globals Booking_App_XMLHttp */ 2/* globals Booking_App_Calendar */ 3/* globals scriptError */ 4/* globals I18n */ 5/* globals FORMAT_COST */ 6/* globals Booking_Package_Hotel */ 7/* globals TAXES */ 8/* globals Confirm */ 9/* globals Booking_Package_Console */ 10/* globals Booking_Package_Input */ 11/* globals Booking_App_ObjectsControl */ 12/* globals Booking_Package_DatabaseUpdateErrors */ 13 14var schedule_data = schedule_data; 15var booking_package_dictionary = booking_package_dictionary; 16var booking_manage = null; 17 18document.addEventListener('DOMContentLoaded', function() { 19 20 21 window.addEventListener('load', function() { 22 23 var booking_pacage_booked_customers = document.getElementById('booking_pacage_booked_customers'); 24 if (schedule_data != null && booking_package_dictionary != null && booking_pacage_booked_customers != null) { 25 26 booking_manage = new Booking_manage(schedule_data, booking_package_dictionary, false); 27 booking_manage.start(); 28 29 } 30 31 }); 32 33}); 34 35window.addEventListener('error', function(event) { 36 37 if (schedule_data != null) { 38 39 var error = new scriptError(schedule_data, booking_package_dictionary, event.message, event.filename, event.lineno, event.colno, event.error, false); 40 error.setResponseText(booking_manage.getResponseText()); 41 error.send(); 42 43 } 44 45}, false); 46 47var changeStatusForDashboard = function(button, key, cancellationToken, accountKey, status, month, day, year){ 48 49 var visitor = {key: key, cancellationToken: cancellationToken, accountKey: accountKey, status: status, date: {month: month, day: day, year: year}}; 50 booking_manage = new Booking_manage(schedule_data, booking_package_dictionary, false); 51 if (booking_manage != null) { 52 53 console.log(visitor); 54 booking_manage.changeStatusForDashboard(button, visitor); 55 56 } 57 58}; 59 60 61function Booking_manage(schedule_data, booking_package_dictionary, webApp) { 62 63 var object = this; 64 this._debug = new Booking_Package_Console(schedule_data.debug); 65 this._console = {}; 66 this._console.log = this._debug.getConsoleLog(); 67 object._console.log(booking_package_dictionary); 68 69 this._schedule_data = schedule_data; 70 this._calendarAccountList = schedule_data.calendarAccountList; 71 this._dashboardRequest = schedule_data.dashboardRequest; 72 this._webApp = webApp; 73 this._currency = schedule_data.currency; 74 this._locale = schedule_data.locale; 75 this._numberFormatter = false; 76 if (parseInt(schedule_data.numberFormatter) === 1) { 77 78 this._numberFormatter = true; 79 80 } 81 this._currencies = schedule_data.currencies; 82 this._currency_info = {locale: this._locale, currency: this._currency, info: this._currencies[this._currency]}; 83 this._i18n = new I18n(schedule_data.locale); 84 this._i18n.setDictionary(booking_package_dictionary); 85 this._format = new FORMAT_COST(this._i18n, this._debug, this._numberFormatter, this._currency_info); 86 this._hotel = null; 87 this._servicesControl = new Booking_App_ObjectsControl(schedule_data, booking_package_dictionary, this._numberFormatter, this._currency_info); 88 89 this._blockPanel = document.getElementById("blockPanel"); 90 this._loadingPanel = document.getElementById("loadingPanel"); 91 92 this._isExtensionsValid = parseInt(schedule_data.isExtensionsValid); 93 this._prefix = schedule_data.prefix; 94 this._url = schedule_data.url; 95 this._nonce = schedule_data.nonce; 96 this._nonce_download = schedule_data.nonce_download; 97 this._action = schedule_data.action; 98 this._dateFormat = schedule_data.dateFormat; 99 this._positionOfWeek = schedule_data.positionOfWeek; 100 this._positionTimeDate = schedule_data.positionTimeDate; 101 this._courseList = schedule_data.courseList; 102 this._formData = schedule_data.formData; 103 this._courseName = schedule_data.courseName; 104 this._buttonAction = null; 105 this._selectedKey = null; 106 this._visitors = {}; 107 this._emailEnableList = schedule_data.emailEnable; 108 this._startOfWeek = schedule_data.startOfWeek; 109 this._clock = "24hours"; 110 this._nationalHoliday = {}; 111 this._preparationTime = 0; 112 this._positionPreparationTime = 'before_after'; 113 this._function = {name: "root", post: {}}; 114 this._taxes = []; 115 this._calendarAccount = []; 116 this._services = []; 117 this._visitorServices = []; 118 this._leftButtonPanel = null; 119 this._rightButtonPanel = null; 120 this._responseText = ""; 121 this._userInformation = {}; 122 this._maxApplicantCount = 0; 123 this._guestsList = []; 124 this._guestForDayOfTheWeekRates = 0; 125 this._hotelOptions = []; 126 this._typeOfId = 'index'; 127 this._changeDisplayFormatBookedCustomersForHotel = 'table'; 128 this._changeDisplayFormatBookedCustomersForDay = 'list'; 129 this._mobile = parseInt(schedule_data.mobile); 130 131 if (schedule_data.guestForDayOfTheWeekRates != null) { 132 133 this._guestForDayOfTheWeekRates = parseInt(schedule_data.guestForDayOfTheWeekRates); 134 135 } 136 137 if (schedule_data.clock != null) { 138 139 this._clock = schedule_data.clock; 140 141 } 142 143 this._monthFullName = ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; 144 var weekName = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; 145 146 this._calendar = null; 147 148 this._htmlTitle = null; 149 if (document.getElementsByTagName("title") != null && document.getElementsByTagName("title").length > 0) { 150 151 this._htmlTitle = document.getElementsByTagName("title")[0]; 152 153 } 154 155 if (document.getElementById('booking_package_databaseUpdateErrors') != null) { 156 157 object._console.log(document.getElementById('booking_package_databaseUpdateErrors')); 158 var databaseUpdateErrors = new Booking_Package_DatabaseUpdateErrors(document.getElementById('booking_package_databaseUpdateErrors')); 159 160 } 161 162 if (schedule_data.bookingBool == 1) { 163 164 this._hotel = new Booking_Package_Hotel(this._currency, weekName, this._dateFormat, this._positionOfWeek, this._positionTimeDate, this._startOfWeek, this._numberFormatter, this._currency_info, booking_package_dictionary, this._debug); 165 this._hotel.setBooking_App_ObjectsControl(this._servicesControl); 166 this._hotel._guestForDayOfTheWeekRates = this._guestForDayOfTheWeekRates; 167 this._blockPanel = document.getElementById("blockPanel"); 168 this._contentPanel = document.getElementById("media_frame_reservation_content"); 169 this._editPanel = document.getElementById("editPanel"); 170 this._loadingPanel = document.getElementById("loadingPanel"); 171 this._buttonPanel = document.getElementById("buttonPanel"); 172 this._leftButtonPanel = document.getElementById("leftButtonPanel"); 173 this._rightButtonPanel = document.getElementById("rightButtonPanel"); 174 175 this._courseBool = false;
176 if(schedule_data.courseBool == 'true'){ 177 178 this._courseBool = true; 179 180 } 181 182 this._blockPanel.onclick = function(){ 183 184 object._leftButtonPanel.textContent = null; 185 object._rightButtonPanel.textContent = null; 186 object.editPanelShow(false); 187 188 }; 189 190 document.getElementById("media_modal_close").onclick = function(){ 191 192 object._leftButtonPanel.textContent = null; 193 object._rightButtonPanel.textContent = null; 194 object.editPanelShow(false); 195 196 }; 197 198 } else if (schedule_data.bookedList == 'userBookingDetails') { 199 200 this._hotel = new Booking_Package_Hotel(this._currency, weekName, this._dateFormat, this._positionOfWeek, this._positionTimeDate, this._startOfWeek, this._numberFormatter, this._currency_info, booking_package_dictionary, this._debug); 201 this._hotel.setBooking_App_ObjectsControl(this._servicesControl); 202 this._hotel._guestForDayOfTheWeekRates = this._guestForDayOfTheWeekRates; 203 204 } 205 206 if (schedule_data.bookedList == 1) { 207 208 this._hotel = new Booking_Package_Hotel(this._currency, weekName, this._dateFormat, this._positionOfWeek, this._positionTimeDate, this._startOfWeek, this._numberFormatter, this._currency_info, booking_package_dictionary, this._debug); 209 this._hotel.setBooking_App_ObjectsControl(this._servicesControl); 210 this._hotel._guestForDayOfTheWeekRates = this._guestForDayOfTheWeekRates; 211 212 } 213 214 this.start = function(){ 215 216 var object = this; 217 218 object._changeDisplayFormatBookedCustomersForDay = object.getCookie(object._prefix + 'changeDisplayFormatBookedCustomersForDay'); 219 if (object._changeDisplayFormatBookedCustomersForDay === null) { 220 221 object._changeDisplayFormatBookedCustomersForDay = 'list'; 222 object.setCookie(object._prefix + 'changeDisplayFormatBookedCustomersForDay', object._changeDisplayFormatBookedCustomersForDay, 365); 223 224 } 225 226 object._changeDisplayFormatBookedCustomersForHotel = object.getCookie(object._prefix + 'changeDisplayFormatBookedCustomersForHotel'); 227 if (object._changeDisplayFormatBookedCustomersForHotel === null) { 228 229 object._changeDisplayFormatBookedCustomersForHotel = 'table'; 230 object.setCookie(object._prefix + 'changeDisplayFormatBookedCustomersForHotel', object._changeDisplayFormatBookedCustomersForHotel, 365); 231 232 } 233 234 var accountKey = this.getCookie(this._schedule_data.prefix + "accountKey"); 235 object._console.log("accountKey = " + accountKey); 236 object._console.log(this._schedule_data); 237 if (accountKey == null) { 238 239 for (var i in this._schedule_data.calendarAccountList) { 240 241 accountKey = this._schedule_data.calendarAccountList[i].key; 242 break; 243 244 } 245 246 247 } else { 248 249 var status = false; 250 //for(var i = 0; i < this._schedule_data.calendarAccountList.length; i++){ 251 for(var i in this._schedule_data.calendarAccountList){ 252 253 var calendarAccount = this._schedule_data.calendarAccountList[i]; 254 if (accountKey == calendarAccount.key) { 255 256 status = true; 257 break; 258 259 } 260 261 } 262 263 if (status == false) { 264 265 for (var i in this._schedule_data.calendarAccountList) { 266 267 object._console.log(this._schedule_data.calendarAccountList[i]); 268 accountKey = this._schedule_data.calendarAccountList[i].key; 269 break; 270 271 } 272 273 } 274 275 } 276 277 var dashboardRequest = this._schedule_data.dashboardRequest; 278 try { 279 280 object._console.log(dashboardRequest); 281 if(dashboardRequest == null || dashboardRequest.status == null){ 282 283 throw "Error dashboardRequest";
284 285 } 286 287 if (dashboardRequest.status == 1) { 288 289 this.getReservationData(parseInt(dashboardRequest.month), parseInt(dashboardRequest.day), parseInt(dashboardRequest.year), accountKey, 1); 290 291 } else { 292 293 this.getReservationData(parseInt(this._schedule_data.month), parseInt(this._schedule_data.day), parseInt(this._schedule_data.year), accountKey, 1); 294 295 } 296 297 } catch(error) { 298 299 300 } 301 302 303 }; 304 305 this.setFunction = function(name, post){ 306 307 this._function = {name: name, post: post}; 308 309 }; 310 311 this.getFunction = function(){ 312 313 return this._function; 314 315 }; 316 317 this.getServices = function() { 318 319 return this._services; 320 321 }; 322 323 this.setHotelOptions = function(hotelOptions) { 324 325 this._hotelOptions = hotelOptions; 326 327 } 328 329 this.getHotelOptions = function() { 330 331 return this._hotelOptions; 332 333 } 334 335 this.setEmailEnableList = function(emailEnableList) { 336 337 this._emailEnableList = emailEnableList; 338 339 }; 340 341 this.lookingForServices = function(service) { 342 343 var services = this._services; 344 for (var key in services) { 345 346 if (parseInt(services[key].key) == parseInt(service.key)) { 347 348 return true; 349 350 } 351 352 } 353 354 return false; 355 356 }; 357 358 this.resetServices = function() { 359 360 this._services = []; 361 362 }; 363 364 this.setServices = function(updateServices) { 365 366 this._services = updateServices; 367 368 }; 369 370 this.addServices = function(service) { 371 372 this._services.push(service); 373 374 }; 375 376 this.resetVisitorServices = function() { 377 378 this._visitorServices = []; 379 380 }; 381 382 this.setVisitorServices = function(services) { 383 384 //this._visitorServices = []; 385 if (this._visitorServices.length == 0) { 386 387 for (var key in services) { 388 389 services[key].selectedOptionsList = services[key].options; 390 //this._visitorServices.push(services[key]); 391 392 } 393 394 } 395 396 //this._visitorServices = JSON.parse(JSON.stringify(services)); 397 object._visitorServices = services.map( list => ({...list})); 398 this._console.log(this._visitorServices); 399 400 }; 401 402 this.lookingForVisitorServices = function(target) { 403 404 var services = this._visitorServices; 405 this._console.log(this._visitorServices); 406 for (var key in services) { 407 408 if (parseInt(services[key].key) == parseInt(target.key) && parseInt(services[key].selected) == 1) { 409 410 return true; 411 412 } 413 414 } 415 416 return false; 417 418 }; 419 420 this.addVisitorServices = function(target) { 421 422 var object = this; 423 object._console.log(target); 424 if (target.selectedOptionsList == null) { 425 426 427 428 } 429 var hasService = false; 430 var services = object._visitorServices; 431 object._console.log(services); 432 for (var key in services) { 433 434 if (parseInt(services[key].key) == parseInt(target.key)) { 435 436 hasService = true; 437 //services[key] = JSON.parse(JSON.stringify(target)); 438 services[key] = target; 439 //return object._visitorServices; 440 441 } 442 443 } 444 445 if (hasService === false && target.selected == 1) { 446 447 //services.push(JSON.parse(JSON.stringify(target))); 448 services.push(target); 449 450 } 451 452 object._console.log(services); 453 object._visitorServices = services.map( list => ({...list})); 454 //services.push(target); 455 return object._visitorServices; 456 457 }; 458 459 this.getVisitorServices = function() { 460 461 this._console.log(this._visitorServices); 462 return this._visitorServices; 463 464 }; 465 466 this.setResponseText = function(responseText){ 467 468 this._responseText = responseText; 469 470 }; 471 472 this.getResponseText = function(){ 473 474 return this._responseText; 475 476 }; 477 478 this.setUserInformation = function(userInformation) { 479 480 if (userInformation == null) { 481 482 userInformation = {}; 483 484 } 485 486 this._userInformation = userInformation; 487 488 }; 489 490 this.getUserInformation = function() { 491 492 return this._userInformation; 493 494 }; 495 496 this.getGuestsList = function(){ 497 498 return this._guestsList; 499 500 }; 501 502 this.setMaxApplicantCount = function(maxApplicantCount) { 503 504 this._maxApplicantCount = maxApplicantCount; 505 506 }; 507 508 this.getMaxApplicantCount = function() { 509 510 return this._maxApplicantCount; 511 512 }; 513 514 this.getReservationData = function(month, day, year, accountKey, createSchedules, c
514allback){ 515 516 var object = this; 517 //object._startOfWeek = object._calendarAccountList[accountKey].startOfWeek; 518 object._console.log(object._loadingPanel); 519 object._loadingPanel.setAttribute("class", "loading_modal_backdrop"); 520 var post = {nonce: object._nonce, action: object._action, mode: object._prefix + 'getReservationData', year: year, month: month, day: 1, accountKey: accountKey, createSchedules: parseInt(createSchedules)}; 521 object.setFunction("getReservationData", post); 522 new Booking_App_XMLHttp(object._url, post, object._webApp, function(calendarData){ 523 524 object._loadingPanel.setAttribute("class", "hidden_panel"); 525 object._console.log( typeof calendarData); 526 if (typeof calendarData !== 'object') { 527 528 console.error(calendarData); 529 return null; 530 531 } 532 533 if (object._isExtensionsValid != 1) { 534 535 calendarData.account.maximumNights = 0; 536 calendarData.account.minimumNights = 0; 537 calendarData.hotelOptions = []; 538 539 } 540 541 object._preparationTime = parseInt(calendarData.account.preparationTime); 542 object._positionPreparationTime = calendarData.account.positionPreparationTime; 543 object._calendarAccount = calendarData.account; 544 object._hotel.setCalendarAccount(calendarData.account); 545 object._hotel.setTaxes(calendarData.taxes); 546 object._taxes = calendarData.taxes; 547 object._guestsList = calendarData.guestsList; 548 object._hotelOptions = calendarData.hotelOptions; 549 object._servicesControl.setNationalHoliday(calendarData.nationalHoliday.calendar); 550 if (object._htmlTitle != null) { 551 552 object._htmlTitle.textContent = calendarData.account.name; 553 554 } 555 object._console.log(object._hotelOptions); 556 object._console.log(object._taxes); 557 object._emailEnableList = calendarData.emailEnableList; 558 if (calendarData.courseList != null) { 559 560 for (var i = 0; i < calendarData.courseList.length; i++) { 561 562 var service = calendarData.courseList[i]; 563 if (service.stopServiceUnderFollowingConditions != "doNotStop") { 564 565 object._calendarAccount.hasMultipleServices = 0; 566 break; 567 568 } 569 570 } 571 572 object._courseList = calendarData.courseList; 573 object._servicesControl.setServices(calendarData.courseList); 574 575 } 576 577 object._courseBool = false; 578 if (parseInt(calendarData.account.courseBool) == 1) { 579 580 object._courseBool = true; 581 582 } 583 object._console.log("_courseBool = " + object._courseBool); 584 585 if (calendarData.formData != null) { 586 587 object._formData = calendarData.formData; 588 589 } 590 591 if (callback == null) { 592 593 object.createCalendar(calendarData, month, day, year, accountKey); 594 595 } else { 596 597 callback(calendarData); 598 599 } 600 601 }, function(responseText){ 602 603 //object.setResponseText(responseText); 604 605 }); 606 607 }; 608 609 this.setCookie = function(name, value, days) { 610 611 var expires = ""; 612 if (days) { 613 var date = new Date(); 614 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); 615 expires = "; expires=" + date.toUTCString(); 616 } 617 document.cookie = name + "=" + value + expires + "; path=/"; 618 619 } 620 621 this.getCookie = function (name) { 622 623 var nameEQ = name + "="; 624 var cookies = document.cookie.split(';'); 625 for(var i = 0; i < cookies.length; i++) { 626 627 var cookie = cookies[i]; 628 while (cookie.charAt(0) === ' ') { 629 630 cookie = cookie.substring(1, cookie.length); 631 632 } 633 634 if (cookie.indexOf(nameEQ) === 0) { 635 636 return cookie.substring(nameEQ.length, cookie.length); 637 638 } 639 640 } 641 642 return null; 643 644 } 645 646 this.selectCalendarAccount = function(calendarData, month, day, year, selectCalendarAccountPanel, calendarAccountList, accountKey){ 647 648 var object = this; 649 object._console.log("accountKey = " + accountKey); 650 object._console.log(calendarAccountList); 651 selectCalendarAccountPanel.id = "selectCalendarAccountPanel"; 652 var select = document.createElement("select"); 653 selectCalendarAccountPanel.appendChild(select); 654 for (var i = 0; i < calendarAccountList.length; i++) { 655 656 var calendarAccount = calendarAccountList[i]; 657 object._console.log(calendarAccount); 658 var option = document.createElement("option"); 659 option.value = calendarAccount.key; 660 option.textContent = calendarAccount.name; 661 select.appendChild(option); 662 if (accountKey == calendarAccount.key) { 663 664 select.selectedIndex = i; 665 object._startOfWeek = calendarAccount.startOfWeek; 666 object._courseBool = false;
667 if (parseInt(calendarAccount.courseBool) == 1) { 668 669 object._courseBool = true; 670 671 } 672 673 object._console.log("courseBool = " + object._courseBool); 674 object._courseName = calendarAccount.courseTitle; 675 676 } 677 678 } 679 680 select.onchange = function(){ 681 682 object._console.log("onchange = " + this.selectedIndex); 683 var key = this.selectedIndex; 684 var accountKey = this.options[key].value; 685 object._console.log("accountKey = " + accountKey); 686 object.getReservationData(month, day, year, accountKey, 1, null); 687 688 }; 689 690 }; 691 692 this.createCalendar = function(calendarData, month, day, year, accountKey) { 693 694 var object = this; 695 this.date = {month: month, day: day, year: year}; 696 var calendarPanel = document.getElementById("calendarPage"); 697 calendarPanel.textContent = null; 698 object._nationalHoliday = calendarData.nationalHoliday.calendar; 699 object._console.log("schedule_data.calendar_account = " + object._schedule_data.calendar_account); 700 var selectCalendarAccountPanel = document.createElement("div"); 701 var calendarAccount = calendarData.account; 702 object._console.log(calendarAccount); 703 704 calendarPanel.appendChild(selectCalendarAccountPanel); 705 object.selectCalendarAccount(calendarData, month, day, year, selectCalendarAccountPanel, object._schedule_data.calendarAccountList, accountKey); 706 707 var dayHeight = parseInt(calendarPanel.clientWidth / 7); 708 709 var weekName = [object._i18n.get('Sun'), object._i18n.get('Mon'), object._i18n.get('Tue'), object._i18n.get('Wed'), object._i18n.get('Thu'), object._i18n.get('Fri'), object._i18n.get('Sat')]; 710 object._calendar = new Booking_App_Calendar(weekName, object._dateFormat, object._positionOfWeek, object._positionTimeDate, object._startOfWeek, object._i18n, object._debug); 711 object._calendar.setClock(object._clock); 712 713 var returnLabel = document.createElement("label"); 714 var nextLabel = document.createElement("label"); 715 var topPanel = object._calendar.createHeader(month, year, 0, true); 716 if (topPanel.querySelector('#change_calendar_return') != null) { 717 718 returnLabel = topPanel.querySelector('#change_calendar_return'); 719 720 } 721 722 if (topPanel.querySelector('#change_calendar_next') != null) { 723 724 nextLabel = topPanel.querySelector('#change_calendar_next'); 725 726 } 727 728 calendarPanel.appendChild(topPanel); 729 730 var downloadBool = false; 731 object._calendar.create(calendarPanel, calendarData, month, day, year, '', function(callback) { 732 733 object._console.log(callback); 734 var dayPanel = callback.eventPanel; 735 var day = parseInt(callback.day); 736 var remainderPanel = document.createElement("div"); 737 remainderPanel.setAttribute("class", "remainderPanel"); 738 remainderPanel.textContent = null; 739 var approved = 0; 740 var pending = 0; 741 var canceled = 0; 742 if (calendarData.reservation[callback.key] != null) { 743 744 var userList = calendarData.reservation[callback.key]; 745 object._console.log(userList); 746 747 for (var key in calendarData.reservation[callback.key]) { 748 749 object._console.log(calendarData.reservation[callback.key][key]); 750 if (parseInt(calendarData.reservation[callback.key][key].scheduleUnixTime) >= calendarData.date.firstMonth && parseInt(calendarData.reservation[callback.key][key].scheduleUnixTime) <= calendarData.date.endMonth) { 751 752 downloadBool = true; 753 754 } 755 756 if (calendarData.reservation[callback.key][key].status == 'approved') { 757 758 approved++; 759 760 } else if (calendarData.reservation[callback.key][key].status == 'pending') { 761 762 pending++; 763 764 } else if (calendarData.reservation[callback.key][key].status == 'canceled') { 765 766 canceled++; 767 768 } 769 770 } 771 772 object._console.log("approved = " + approved + " pending = " + pending); 773 var approvedCount = document.createElement("span"); 774 approvedCount.classList.add("approvedCount"); 775 approvedCount.textContent = approved; 776 777 var pendingCount = document.createElement("span"); 778 pendingCount.classList.add("pendingCount"); 779 pendingCount.textContent = pending; 780 781 var canceledCount = document.createElement('span'); 782 canceledCount.classList.add("canceledCount"); 783 canceledCount.textContent = canceled; 784 785 if (parseInt(calendarAccount.displayDetailsOfCanceled) == 0) { 786 787 if (approved > 0) { 788 789 remainderPanel.appendChild(approvedCount); 790 791 } 792 793 if (pending > 0) { 794 795 remainderPanel.appendChild(pendingCount); 796 797 } 798 799 } else { 800 801 if (approved > 0) { 802 803 remainderPanel.appendChild(approvedCount); 804 805 } 806 807 if (pending > 0) { 808 809 remainderPanel.appendChild(pendingCount); 810 811 } 812 813 if (canceled > 0) { 814 815 remainderPanel.appendChild(canceledCount); 816 817 } 818 819 } 820 821 dayPanel.appendChild(remainderPanel); 822 823 } 824 825 var total = approved + pending + canceled; 826 if (calendarData.schedule[callback.key] != null && calendarData.schedule[callback.key].length != 0 || total != 0) { 827 828 if (calendarData.schedule[callback.key].length == 0) { 829 830 dayPanel.classList.add("closeDay"); 831 832 } 833 834 dayPanel.onclick = function(){ 835 836 var dayKey = parseInt(this.getAttribute("data-day")); 837 var monthKey = parseInt(this.getAttribute("data-month"));
838 var yearKey = parseInt(this.getAttribute("data-year")); 839 object.setUserInformation(null); 840 object._buttonAction = "reservation_users"; 841 document.getElementById("reservation_users").setAttribute("class", "media_menu_item active"); 842 document.getElementById("add_reservation").setAttribute("class", "media_menu_item"); 843 //setCalendarDate({month: month, day: dayKey, year: year}); 844 object.viewUserList(monthKey, dayKey, yearKey, calendarData, accountKey, true, function(callback){ 845 846 object._console.log("editPublicSchedule callback"); 847 848 }); 849 850 }; 851 852 } else { 853 854 object._console.log("delete class"); 855 dayPanel.classList.remove("pointer"); 856 dayPanel.classList.add("closeDay"); 857 858 } 859 860 }); 861 862 returnLabel.onclick = function(){ 863 864 if (month == 1) { 865 866 year--; 867 month = 12; 868 869 } else { 870 871 month--; 872 873 } 874 object.getReservationData(month, 1, year, accountKey, 0, null); 875 876 }; 877 878 nextLabel.onclick = function(){ 879 880 if (month == 12) { 881 882 year++; 883 month = 1; 884 885 } else { 886 887 month++; 888 889 } 890 object.getReservationData(month, 1, year, accountKey, 0, null); 891 892 }; 893 894 var timezonePanel = document.createElement("div"); 895 if (calendarAccount.timezone != 'none') { 896 897 timezonePanel.textContent = object._i18n.get("Timezone") + ": " + calendarAccount.timezone; 898 calendarPanel.appendChild(timezonePanel); 899 900 } 901 902 var form = document.createElement("form"); 903 form.id = 'downloadCsvForMonth'; 904 object.downloadCSV(month, null, year, accountKey, form, downloadBool, ''); 905 906 var footerOnCalendar = document.createElement('div'); 907 footerOnCalendar.classList.add('footerOnCalendar'); 908 footerOnCalendar.appendChild(timezonePanel); 909 footerOnCalendar.appendChild(form); 910 calendarPanel.appendChild(footerOnCalendar); 911 912 if (object._dashboardRequest.status == 1) { 913 914 object.viewUserList(object._dashboardRequest.month, object._dashboardRequest.day, object._dashboardRequest.year, calendarData, accountKey, true, function(callback){ 915 916 object._console.log("editPublicSchedule callback"); 917 918 }); 919 920 } 921 922 }; 923 924 this.viewUserList = function(month, day, year, calendarData, accountKey, index, callback){ 925 926 var object = this; 927 var weekName = [object._i18n.get('Sun'), object._i18n.get('Mon'), object._i18n.get('Tue'), object._i18n.get('Wed'), object._i18n.get('Thu'), object._i18n.get('Fri'), object._i18n.get('Sat')]; 928 object._calendar = new Booking_App_Calendar(weekName, object._dateFormat, object._positionOfWeek, object._positionTimeDate, object._startOfWeek, object._i18n, object._debug); 929 object._calendar.setClock(object._clock); 930 var calendarKey = object._calendar.getDateKey(month, day, year); 931 object._console.log(month + "/" + day + "/" + year); 932 object._console.log("buttonAction = " + object._buttonAction); 933 object._console.log(calendarData); 934 object._console.log(calendarKey); 935 936 object._hotel.resetCheckDate(); 937 938 var edit_title = document.getElementById("edit_title"); 939 edit_title.textContent = object._calendar.formatBookingDate(month, day, year, null, null, null, calendarData.calendar[calendarKey].week, 'text'); 940 var media_menu = document.getElementById("media_menu"); 941 media_menu.textContent = null; 942 943 object._contentPanel.setAttribute("class", "media_left_zero"); 944 document.getElementById("menu_panel").setAttribute("class", "media_frame_menu hidden_panel"); 945 document.getElementById("media_title").setAttribute("class", "media_left_zero"); 946 document.getElementById("media_router").setAttribute("class", "media_left_zero"); 947 document.getElementById("frame_toolbar").setAttribute("class", "media_frame_toolbar media_left_zero"); 948 949 var reservation_users_callback = function(response) { 950 951 object._console.log("reservation_users_callback"); 952 object._console.log("buttonAction = " + object._buttonAction); 953 object._console.log(response); 954 object._console.log(month + "/" + day + "/" + year); 955 if (object._buttonAction == "updateSchedule" && response.month != null && response.day != null && response.
955year != null) { 956 957 object.viewUserList(response.month, response.day, response.year, response.calendarData, accountKey, true, callback); 958 959 } else if (object._buttonAction == "updateSchedule") { 960 961 object.viewUserList(month, day, year, response, accountKey, true, callback); 962 963 } else { 964 965 if (response.updateDate != null) { 966 967 if (response.account.type == "day") { 968 969 object.viewUserList(response.updateDate.month, response.updateDate.day, response.updateDate.year, response, accountKey, true, callback); 970 971 } else { 972 973 object.viewUserList(month, day, year, response, accountKey, true, callback); 974 975 } 976 977 } else { 978 979 object.viewUserList(month, day, year, response, accountKey, true, callback); 980 981 } 982 983 } 984 985 }; 986 987 var add_reservation_callback = function(response){ 988 989 object._console.log(response); 990 object._hotel.resetCheckDate(); 991 document.getElementById("reservation_users").setAttribute("class", "media_menu_item active"); 992 document.getElementById("add_reservation").setAttribute("class", "media_menu_item"); 993 object.viewUserList(month, day, year, response, accountKey, true, callback); 994 995 }; 996 997 var changeButtonAction = function(buttonAction, mode, month, day, year, calendarData, add_reservationPanel, add_reservation_callback, callback){ 998 999 month = parseInt(month); 1000 day = parseInt(day); 1001 year = parseInt(year); 1002 //var lastDay = parseInt(calendarData.date.lastDay); 1003 var lastDay = 0; 1004 var key = parseInt(year + ("0" + month).slice(-2)); 1005 if (calendarData.calendarList[key] != null) { 1006 1007 object._console.log(calendarData.calendarList[key]); 1008 lastDay = parseInt(calendarData.calendarList[key].lastDay); 1009 1010 } 1011 var calendarChange = 0; 1012 object._hotel.resetCheckDate(); 1013 1014 object._console.log("month = " + month + " day = " + day + " year = " + year + " lastDay = " + lastDay); 1015 if (buttonAction == 'reservation_users' || buttonAction == 'add_reservation' || buttonAction == 'updateSchedule') { 1016 1017 if (mode == 0) { 1018 1019 day--; 1020 if(day == 0){ 1021 1022 calendarChange = 1; 1023 month--; 1024 day = 1; 1025 if (month == 0) { 1026 month = 12; 1027 year--; 1028 } 1029 1030 } 1031 1032 } else if (mode == 1) { 1033 1034 day++; 1035 if (day > lastDay) { 1036 1037 calendarChange = 1; 1038 month++; 1039 day = 1; 1040 if (month == 13) { 1041 month = 1; 1042 year++; 1043 } 1044 1045 } 1046 1047 } 1048 1049 object._console.log("calendarChange = " + calendarChange); 1050 if (calendarChange === 0) { 1051 1052 object.setResponseText( JSON.stringify( {month: month, day: day, year: year, buttonAction: buttonAction, calendar: calendarData.calendar} ) ); 1053 object.viewUserList(month, day, year, calendarData, accountKey, true, callback); 1054 1055 } else { 1056 1057 object._loadingPanel.setAttribute("class", "loading_modal_backdrop"); 1058 var post = {nonce: object._nonce, action: object._action, mode: object._prefix + 'getReservationData', year: year, month: month, day: 1, accountKey: accountKey}; 1059 object.setFunction("viewUserList", post); 1060 new Booking_App_XMLHttp(object._url, post, object._webApp, function(calendarData){ 1061 1062 object._loadingPanel.setAttribute("class", "hidden_panel"); 1063 object._servicesControl.setNationalHoliday(calendarData.nationalHoliday.calendar); 1064 object._console.log(calendarData); 1065 object.createCalendar(calendarData, calendarData.date.month, calendarData.date.day, calendarData.date.year, accountKey); 1066 var day = 1; 1067 if (mode === 0) {day = calendarData.date.lastDay;} 1068 object.viewUserList(month, day, year, calendarData, accountKey, true, callback); 1069 object._loadingPanel.setAttribute("class", "hidden_panel"); 1070 1071 }, function(responseText){ 1072
1073 //object.setResponseText(responseText); 1074 1075 }); 1076 1077 } 1078 1079 } else { 1080 1081 object._console.log("month = " + month + " day = " + day + " year = " + year); 1082 var calendarKey = object._calendar.getDateKey(month, day, year); 1083 object._console.log(calendarKey); 1084 object._console.log(calendarData.reservation[calendarKey]); 1085 1086 var reservationList = null; 1087 var selectedKey = null; 1088 if (calendarData.account.type == "day") { 1089 1090 selectedKey = object.getSelectedKey(); 1091 if (mode === 0) { 1092 1093 selectedKey--; 1094 if (selectedKey < 0) { 1095 1096 selectedKey = calendarData.reservation[calendarKey].length - 1; 1097 1098 } 1099 1100 } else { 1101 1102 selectedKey++; 1103 if (selectedKey == calendarData.reservation[calendarKey].length) { 1104 1105 selectedKey = 0; 1106 1107 } 1108 1109 } 1110 object.setSelectedKey(selectedKey); 1111 reservationList = calendarData.reservation[calendarKey][selectedKey]; 1112 object._console.log("selectedKey = " + selectedKey + " count = " + calendarData.reservation[calendarKey].length); 1113 1114 } else { 1115 1116 var key = object.getSelectedKey(); 1117 var visitorsList = object.getVisitors(); 1118 var visitorsArray = Object.keys(visitorsList); 1119 if (object.getTypeOfId() == 'key') { 1120 1121 object.setTypeOfId('index'); 1122 key = (function(key, visitorsArray) { 1123 1124 for (var i = 0; i < visitorsArray.length; i++) { 1125 1126 if (key === parseInt(visitorsArray[i])) { 1127 1128 return i; 1129 1130 } 1131 1132 } 1133 1134 })(key, visitorsArray); 1135 1136 } 1137 object._console.log(object.getVisitors()); 1138 object._console.log(visitorsArray); 1139 if (mode === 0) { 1140 1141 key--; 1142 if (key < 0) { 1143 1144 key = visitorsArray.length - 1; 1145 1146 } 1147 1148 } else { 1149 1150 key++; 1151 if (key == visitorsArray.length) { 1152 1153 key = 0; 1154 1155 } 1156 1157 } 1158 1159 selectedKey = visitorsArray[key]; 1160 object.setSelectedKey(key); 1161 1162 reservationList = calendarData.reservationForHotel[visitorsList[selectedKey].checkIn][selectedKey]; 1163 object._console.log("selectedKey = " + selectedKey); 1164 object._console.log(visitorsList[selectedKey]); 1165 object._console.log(calendarData.reservationForHotel[visitorsList[selectedKey].checkIn][selectedKey]); 1166 //return null; 1167 1168 } 1169 1170 object.showUserInfo(selectedKey, calendarData, reservationList, false, accountKey, reservation_users_callback); 1171 1172 } 1173 1174 }; 1175 1176 var reservation_usersPanel = null; 1177 var add_reservationPanel = null; 1178 if (document.getElementById("reservation_usersPanel") != null && document.getElementById("add_reservationPanel") != null) { 1179 1180 reservation_usersPanel = document.getElementById("reservation_usersPanel"); 1181 reservation_usersPanel.textContent = null; 1182 add_reservationPanel = document.getElementById("add_reservationPanel"); 1183 add_reservationPanel.textContent = null; 1184 1185 } else { 1186 1187 reservation_usersPanel = document.createElement("div");
1188 reservation_usersPanel.id = "reservation_usersPanel"; 1189 add_reservationPanel = document.createElement("div"); 1190 add_reservationPanel.id = "add_reservationPanel"; 1191 object._contentPanel.appendChild(reservation_usersPanel); 1192 object._contentPanel.appendChild(add_reservationPanel); 1193 1194 } 1195 1196 1197 1198 var menuTabList = {reservation_users: 'Reservation users', add_reservation: 'Add reservation'}; 1199 for (var key in menuTabList) { 1200 1201 var tabPanel = document.getElementById(key); 1202 tabPanel.setAttribute("data-key", key); 1203 tabPanel.onclick = function(){ 1204 1205 var clickKey = this.getAttribute("data-key"); 1206 for (var key in menuTabList) { 1207 1208 var link = document.getElementById(key); 1209 1210 if (clickKey == key) { 1211 1212 link.setAttribute("class", "media_menu_item active"); 1213 1214 } else { 1215 1216 link.setAttribute("class", "media_menu_item"); 1217 1218 } 1219 1220 if (clickKey == 'reservation_users') { 1221 1222 reservation_usersPanel.setAttribute("class", ""); 1223 add_reservationPanel.setAttribute("class", "hidden_panel"); 1224 object.reservation_users(reservation_usersPanel, month, day, year, calendarData, accountKey, reservation_users_callback); 1225 1226 } else if (clickKey == 'add_reservation') { 1227 1228 if (document.getElementById("userInfoPanel") != null) { 1229 1230 1231 var userPanel = document.getElementById("userInfoPanel"); 1232 userPanel.classList.add('hidden_panel'); 1233 if (userPanel.getAttribute("class") == "show_panel_for_new_booking") { 1234 1235 userPanel.setAttribute("class", "return_panel_for_new_booking"); 1236 1237 } 1238 1239 } 1240 1241 if (document.getElementById("changePanel") != null) { 1242 1243 var changePanel = document.getElementById("changePanel"); 1244 if (changePanel.getAttribute("class") == "show_change_panel" || changePanel.getAttribute("class") == "return_change_panel") { 1245 1246 changePanel.setAttribute("class", "return_panel"); 1247 1248 } 1249 1250 } 1251 1252 var blockPanelCount = object._contentPanel.getElementsByClassName("blockPanel"); 1253 for (var i = 0; i < blockPanelCount.length; i++) { 1254 1255 object._contentPanel.removeChild(blockPanelCount[i]); 1256 1257 } 1258 1259 object._hotel.reset(); 1260 reservation_usersPanel.setAttribute("class", "hidden_panel"); 1261 add_reservationPanel.setAttribute("class", ""); 1262 object.add_reservation(add_reservationPanel, month, day, year, calendarData, accountKey, add_reservation_callback); 1263 1264 1265 } 1266 1267 } 1268 1269 }; 1270 1271 } 1272 1273 if (object._buttonAction == 'reservation_users' || object._buttonAction == 'updateSchedule' || object._buttonAction == 'showUserInfo') { 1274 1275 object.reservation_users(reservation_usersPanel, month, day, year, calendarData, accountKey, reservation_users_callback); 1276 1277 } else if (object._buttonAction == 'add_reservation') { 1278 1279 object.add_reservation(add_reservationPanel, month, day, year, calendarData, accountKey, add_reservation_callback); 1280 1281 } 1282 1283 if (object._buttonAction != "updateSchedule") { 1284 1285 object._leftButtonPanel.textContent = null; 1286 var beforButton = document.createElement("button"); 1287 beforButton.id = "beforButton"; 1288 beforButton.textContent = "navigate_before"; 1289 beforButton.setAttribute("class", "material-icons button media-button button-primary button-large media-button-insert"); 1290 //beforButton.setAttribute("style", "margin-left: 10px;"); 1291 object._leftButtonPanel.appendChild(beforButton); 1292 1293 var nextButton = document.createElement("button"); 1294 nextButton.id = "nextButton"; 1295 nextButton.textContent = "navigate_next"; 1296 nextButton.setAttribute("class", "material-icons button media-button button-primary button-large media-button-insert"); 1297 nextButton.setAttribute("style", "margin-left: 10px;"); 1298 object._leftButtonPanel.appendChild(nextButton); 1299 1300 var form = document.createElement('form'); 1301 form.id = 'downloadCsvForDay'; 1302 //form.setAttribute("class", "material-icons"); 1303 object.downloadCSV(month, day, year, accountKey, form, true, ''); 1304 object._leftButtonPanel.appendChild(form); 1305 1306 var beforChangeButton = document.createElement("button"); 1307 beforChangeButton.id = "beforChangeButton"; 1308 beforChangeButton.setAttribute("class", "beforButton button media-button button-primary button-large media-button-insert hidden_panel"); 1309 object._leftButtonPanel.appendChild(beforChangeButton); 1310 1311 var nextChangeButton = document.createElement("button"); 1312 nextChangeButton.id = "nextChangeButton"; 1313 nextChangeButton.setAttribute("class", "nextButton button media-button button-primary button-large media-button-insert hidden_panel"); 1314 nextChangeButton.setAttribute("style", "margin-left: 10px;"); 1315 object._leftButtonPanel.appendChild(nextChangeButton); 1316 1317 beforButton.onclick = function() { 1318 1319 changeButtonAction(object._buttonAction, 0, month, day, year, calendarData, add_reservationPanel, add_reservation_callback, callback); 1320 1321 }; 1322 1323 nextButton.onclick = function() { 1324 1325 changeButtonAction(object._buttonAction, 1, month, day, year, calendarData, add_reservationPanel, add_reservation_callback, callback); 1326 1327 }; 1328 1329 object.editPanelShow(true); 1330 1331 } 1332 1333 1334 if (object._dashboardRequest.status == 1) { 1335 1336 reservation_usersPanel.setAttribute("class", ""); 1337 add_reservationPanel.setAttribute("class", "hidden_panel"); 1338 object.reservation_users(reservation_usersPanel, month, day, year, calendarData, accountKey, reservation_users_callback); 1339 1340 1341 } 1342 1343 1344 1345 1346 }; 1347 1348 this.changeStatusForDashboard = function(button, visitor){ 1349 1350 var object = this; 1351 object._console.log("changeStatusForDashboard"); 1352 object._console.log(visitor); 1353 if (visitor.status == 'canceled') { 1354 1355 return null; 1356 1357 } 1358 1359 object.changeStatus(visitor.accountKey, visitor, true, false, function(response){ 1360 1361 object._console.log(response); 1362 var status = null; 1363 if (response.bookingStatus.toLowerCase() == 'pending') { 1364 1365 button.setAttribute("class", "status pending"); 1366 status = "pending"; 1367 1368 } else if (response.bookingStatus.toLowerCase() == 'approved') { 1369 1370 button.setAttribute("class", "status approved"); 1371 status = "approved"; 1372 1373 } else if(response.bookingStatus.toLowerCase() == 'canceled') { 1374 1375 button.setAttribute("class", "status canceled"); 1376 status = "canceled"; 1377 1378 } 1379 1380 visitor.status = status; 1381 button.textContent = object._i18n.get(status.toUpperCase()); 1382 object._console.log(visitor); 1383 button.setAttribute("onClick", "changeStatusForDashboard(this, " + visitor.key + ", '" + visitor.cancellationToken + "', " + visitor.accountKey + ", '" + response.bookingStatus.toLowerCase() + "', " + visitor.date.month + ", " + visitor.date.day + ", " + visitor.date.year + ")"); 1384 1385 }); 1386 1387 }; 1388 1389 this.changeStatus = function(accountKey, reservation, statusClick, reload, callback){ 1390 1391 var object = this; 1392 var enable = false;
1393 var message = ""; 1394 var confirm = new Confirm(object._debug); 1395 object._console.log(object._emailEnableList); 1396 object._console.log(reservation); 1397 1398 var status = reservation.status; 1399 var approvedButton = document.createElement("div"); 1400 approvedButton.classList.add("approvedLabel"); 1401 approvedButton.textContent = object._i18n.get("approved"); 1402 approvedButton.setAttribute("data-status", "APPROVED"); 1403 approvedButton.setAttribute("data-close", 0); 1404 1405 var pendingButton = document.createElement("div"); 1406 pendingButton.classList.add("pendingLabel"); 1407 pendingButton.textContent = object._i18n.get("pending"); 1408 pendingButton.setAttribute("data-status", "PENDING"); 1409 pendingButton.setAttribute("data-close", 0); 1410 1411 var canceledButton = document.createElement("div"); 1412 canceledButton.classList.add("canceledLabel"); 1413 canceledButton.textContent = object._i18n.get("canceled"); 1414 canceledButton.setAttribute("data-status", "CANCELED"); 1415 canceledButton.setAttribute("data-close", 0); 1416 1417 var closeButton = document.createElement("div"); 1418 closeButton.classList.add("closeLabel"); 1419 closeButton.textContent = object._i18n.get("Close").toUpperCase(); 1420 closeButton.setAttribute("data-status", "CANCELED"); 1421 closeButton.setAttribute("data-close", 1); 1422 1423 var selectButtonList = [approvedButton, pendingButton, canceledButton, closeButton]; 1424 confirm.selectPanelShow(object._i18n.get("Update status"), selectButtonList, status, enable, function(newStatus){ 1425 1426 object._console.log(newStatus); 1427 if (newStatus != false) { 1428 1429 enable = true; 1430 if (newStatus.toUpperCase() == "APPROVED" && parseInt(object._emailEnableList.booking_approved_notification.enable) == 1) { 1431 1432 object._console.log("APPROVED = " + Boolean(parseInt(object._emailEnableList.booking_approved_notification.enable))); 1433 enable = false; 1434 1435 } else if (newStatus.toUpperCase() == "PENDING" && parseInt(object._emailEnableList.booking_pending_notification.enable) == 1) { 1436 1437 object._console.log("PENDING = " + Boolean(parseInt(object._emailEnableList.booking_pending_notification.enable))); 1438 enable = false; 1439 1440 } else if (newStatus.toUpperCase() == "CANCELED" && parseInt(object._emailEnableList.booking_cancellation_notification.enable) == 1) { 1441 1442 object._console.log("CANCELED = " + Boolean(parseInt(object._emailEnableList.booking_cancellation_notification.enable))); 1443 enable = false; 1444 1445 } 1446 1447 object._console.log("enable = " + enable); 1448 1449 confirm.dialogPanelShow(object._i18n.get("Attention"), object._i18n.get("Will emails be sent to both customers and admins?"), enable, 0, function(sendEmail) { 1450 1451 if (reload == true) { 1452 reload = 1; 1453 } else { 1454 reload = 0; 1455 } 1456 1457 var post = {nonce: object._nonce, action: object._action, mode: 'updateStatus', key: reservation.key, token: reservation.cancellationToken, oldStatus: status, newStatus: newStatus, month: reservation.date.month, year: reservation.date.year, sendEmail: Number(sendEmail), accountKey: reservation.accountKey, reload: reload}; 1458 object._console.log(post); 1459 object._loadingPanel.setAttribute("class", "loading_modal_backdrop"); 1460 object.setFunction("changeStatus", post); 1461 new Booking_App_XMLHttp(object._url, post, object._webApp, function(response){ 1462 1463 object._loadingPanel.setAttribute("class", "hidden_panel"); 1464 response.bookingStatus = newStatus; 1465 object._console.log(response); 1466 if(reload == true){ 1467 1468 object.createCalendar(response, response.date.month, response.date.day, response.date.year, accountKey); 1469 1470 } 1471 statusClick = false;
1472 callback(response); 1473 1474 1475 }, function(responseText){ 1476 1477 //object.setResponseText(responseText); 1478 1479 }); 1480 1481 1482 }); 1483 1484 } else { 1485 1486 callback({statusClick: false}); 1487 1488 } 1489 1490 1491 1492 }); 1493 1494 return null; 1495 1496 1497 }; 1498 1499 this.changeDisplayFormatTab = function(reservation_usersPanel, month, day, year, calendarData, accountKey, callback) { 1500 1501 const object = this; 1502 object._console.log(calendarData.account.type); 1503 if (object._buttonAction === 'reservation_users') { 1504 1505 let listButton = document.createElement('button'); 1506 listButton.classList.add('material-icons'); 1507 listButton.textContent = object._i18n.get('format_list_numbered'); 1508 listButton.setAttribute('data-value', 'list'); 1509 let tableButton = document.createElement('button'); 1510 tableButton.classList.add('material-icons'); 1511 tableButton.textContent = object._i18n.get('table_chart'); 1512 tableButton.setAttribute('data-value', 'table'); 1513 let changeDisplayFormatTab = document.createElement('div'); 1514 changeDisplayFormatTab.id = 'changeDisplayFormatTab'; 1515 changeDisplayFormatTab.appendChild(tableButton); 1516 changeDisplayFormatTab.appendChild(listButton); 1517 1518 const buttons = [tableButton, listButton]; 1519 for (var i = 0; i < buttons.length; i++) { 1520 1521 buttons[i].onclick = function(event) { 1522 1523 for (var i = 0; i < buttons.length; i++) { 1524 1525 buttons[i].classList.remove('selectedButton'); 1526 1527 } 1528 this.classList.add('selectedButton'); 1529 let value = this.getAttribute('data-value'); 1530 if (value === null) { 1531 1532 value = 'table'; 1533 1534 } 1535 1536 if (calendarData.account.type === 'hotel') { 1537 1538 object._changeDisplayFormatBookedCustomersForHotel = value; 1539 object.setCookie(object._prefix + 'changeDisplayFormatBookedCustomersForHotel', object._changeDisplayFormatBookedCustomersForHotel, 365); 1540 1541 } else { 1542 1543 object._changeDisplayFormatBookedCustomersForDay = value; 1544 object.setCookie(object._prefix + 'changeDisplayFormatBookedCustomersForDay', object._changeDisplayFormatBookedCustomersForDay, 365); 1545 1546 } 1547 1548 object.reservation_users(reservation_usersPanel, month, day, year, calendarData, accountKey, callback); 1549 1550 }; 1551 1552 } 1553 1554 if (calendarData.account.type === 'hotel') { 1555 1556 if (object._changeDisplayFormatBookedCustomersForHotel === 'table') { 1557 1558 tableButton.classList.add('selectedButton'); 1559 1560 } else { 1561 1562 listButton.classList.add('selectedButton'); 1563 1564 } 1565 object._rightButtonPanel.appendChild(changeDisplayFormatTab); 1566 1567 } else if (calendarData.account.type === 'day') { 1568 1569 if (object._changeDisplayFormatBookedCustomersForDay === 'table') { 1570 1571 tableButton.classList.add('selectedButton'); 1572 1573 } else { 1574 1575 listButton.classList.add('selectedButton'); 1576 1577 } 1578 1579 object._rightButtonPanel.appendChild(changeDisplayFormatTab); 1580 1581 } 1582 1583 } 1584 1585 }; 1586 1587 this.reservation_users = function(reservation_usersPanel, month, day, year, calendarData, accountKey, callback){ 1588 1589 var object = this; 1590 object._console.log(calendarData.account.type); 1591 object._console.log("buttonAction = " + object._buttonAction); 1592 if (object._buttonAction != "updateSchedule" && object._buttonAction != "showUserInfo") { 1593 1594 object._rightButtonPanel.textContent = null; 1595 object._buttonAction = "reservation_users"; 1596 1597 } 1598 1599 object.changeDisplayFormatTab(reservation_usersPanel, month, day, year, calendarData, accountKey, callback); 1600 1601 let toDay = new Date(year + '-' + month + '-' + day + 'T00:00:00+00:00'); 1602 let toDayDate = parseInt(year + '' + month.toString().padStart(2, '0') + '' + day.toString().padStart(2, '0')); 1603 object._console.log(toDayDate); 1604 1605 var weekName = [object._i18n.get('Sun'), object._i18n.get('Mon'), object._i18n.get('Tue'), object._i18n.get('Wed'), object._i18n.get('Thu'), object._i18n.get('Fri'), object._i18n.get('Sat')]; 1606 object._calendar = new Booking_App_Calendar(weekName, object._dateFormat, object._positionOfWeek, object._positionTimeDate, object._startOfWeek, object._i18n, object._debug); 1607 object._calendar.setClock(object._clock); 1608 var calendarKey = object._calendar.getDateKey(month, day, year); 1609 1610 var reservationList = null; 1611 if(calendarData.account.type == 'day'){ 1612 1613 reservationList = calendarData.reservation[parseInt(calendarKey)]; 1614 1615 }else{ 1616 1617 reservationList = calendarData.reservationForHotel; 1618 1619 } 1620 1621 //var reservationList = calendarData.reservation[parseInt(calendarKey)]; 1622 object._console.log(object._formData); 1623 object._console.log(reservationList); 1624 1625 reservation_usersPanel.classList.remove("hidden_panel"); 1626 reservation_usersPanel.textContent = null; 1627 1628 if (reservationList == null) { 1629 1630 var errorPanel = document.createElement("div"); 1631 errorPanel.setAttribute("class", "noReservations"); 1632 errorPanel.textContent = object._i18n.get("There are no customers."); 1633 reservation_usersPanel.appendChild(errorPanel); 1634 return null; 1635 1636 } 1637 1638 var table = document.createElement("table"); 1639 table.setAttribute("class", "wp-list-table widefat fixed striped"); 1640 reservation_usersPanel.appendChild(table); 1641 1642 var createRow = function(key, customer, table, accountKey, calendarData, reservationList) { 1643 1644 var tr = document.createElement("tr"); 1645 tr.setAttribute("valign", "top"); 1646 tr.setAttribute("data-key", key); 1647 table.appendChild(tr); 1648 1649 if (calendarData.account.type === 'day') { 1650 1651 var th = document.createElement("th"); 1652 th.setAttribute("scope", "row"); 1653 th.textContent = object._calendar.getPrintTime(customer.date.hour, customer.date.min); 1654 tr.appendChild(th); 1655 1656 } 1657 1658 var bookingId = document.createElement('div'); 1659 bookingId.textContent = customer.key; 1660 var bookingIdTd = document.createElement("td"); 1661 bookingIdTd.setAttribute("scope", "row"); 1662 bookingIdTd.appendChild(bookingId); 1663 tr.appendChild(bookingIdTd); 1664 1665 var status = document.createElement("div"); 1666 status.setAttribute("data-key", key); 1667 status.textContent = object._i18n.get(customer.status.toLowerCase()); 1668 var statusClassName = "pendingLabel"; 1669 if (customer.status.toLowerCase() == "approved") { 1670 1671 statusClassName = "approvedLabel"; 1672 1673 } else if (customer.status.toLowerCase() == "canceled") { 1674 1675 statusClassName = "canceledLabel"; 1676 1677 } 1678 status.classList.add(statusClassName); 1679 1680 var td = document.createElement("td"); 1681 td.setAttribute("scope", "row"); 1682 td.appendChild(status); 1683 tr.appendChild(td); 1684 1685 (function(formData, praivateData, callback) { 1686 1687 var sort = []; 1688 for (var i = 0; i < formData.length; i++) { 1689 1690 if (formData[i].active != 'true') { 1691 1692 continue; 1693 1694 } 1695 1696 if (praivateData != null) { 1697 1698 for (var ii = 0; ii < praivateData.length; ii++) { 1699 1700 if (formData[i].id == praivateData[ii].id) { 1701 1702 sort[i] = praivateData[ii]; 1703 break; 1704 1705 } 1706 1707 } 1708 1709 if (sort[i] == null) { 1710 1711 sort[i] = formData[i]; 1712 1713 } 1714 1715 } else { 1716 1717 break; 1718 1719 } 1720 1721 } 1722 1723 callback(sort); 1724 1725 })(object._formData, customer.praivateData, function(praivateData) { 1726 1727 object._console.log(praivateData); 1728 for (var i = 0; i < 5; i++) { 1729 1730 if (praivateData[i] != null) { 1731 1732 if (typeof praivateData[i].value == "string") { 1733 1734 praivateData[i].value = praivateData[i].value.replace(/\\/g, ""); 1735 1736 } 1737 1738 var td = document.createElement("td"); 1739 td.textContent = praivateData[i].value; 1740 tr.appendChild(td); 1741 1742 } 1743 1744 } 1745 1746 }); 1747 1748 var statusClick = false;
1749 if (customer.status != "canceled") { 1750 1751 status.onclick = function(){ 1752 1753 var key = parseInt(this.getAttribute("data-key")); 1754 object._console.log(key); 1755 object._console.log(reservationList[key]); 1756 statusClick = true; 1757 1758 object._console.log(object._emailEnableList); 1759 object._console.log("enable = " + Boolean(parseInt(object._emailEnableList.new_booking_notification.enable))); 1760 1761 object.changeStatus(accountKey, reservationList[key], statusClick, true, function(response){ 1762 1763 object._console.log(response); 1764 if(response.statusClick != null){ 1765 1766 statusClick = response.statusClick; 1767 1768 }else{ 1769 1770 callback(response); 1771 1772 } 1773 //callback 1774 1775 }); 1776 1777 }; 1778 1779 } 1780 1781 tr.onclick = function(){ 1782 1783 if(statusClick == false){ 1784 1785 var key = parseInt(this.getAttribute("data-key")); 1786 object._console.log(key); 1787 object._console.log(reservationList[key]); 1788 object.setSelectedKey(key); 1789 object.resetVisitorServices(); 1790 object.showUserInfo(key, calendarData, reservationList[key], true, accountKey, function(response){ 1791 1792 object._console.log(response); 1793 if (response.status == "returnButton") { 1794 1795 object.reservation_users(reservation_usersPanel, response.month, response.day, response.year, calendarData, accountKey, callback); 1796 1797 } else if (response.status == "closedCustomersPanel") { 1798 1799 object.changeDisplayFormatTab(reservation_usersPanel, month, day, year, calendarData, accountKey, callback); 1800 1801 } else { 1802 1803 callback(response); 1804 1805 } 1806 1807 }); 1808 1809 } 1810 1811 }; 1812 1813 return tr; 1814 1815 }; 1816 1817 if (calendarData.account.type == 'day') { 1818 1819 if (reservationList != null) { 1820 1821 if (object._changeDisplayFormatBookedCustomersForDay === 'list') { 1822 1823 for (var i = 0; i < reservationList.length; i++) { 1824 1825 let customer = reservationList[i]; 1826 object._console.log(customer); 1827 let tr = createRow(i, customer, table, accountKey, calendarData, reservationList); 1828 1829 } 1830 1831 } else { 1832 1833 let scrollFocus = 'customer'; 1834 const timeTablePanel = document.createElement('div'); 1835 timeTablePanel.classList.add('timeTablePanel'); 1836 reservation_usersPanel.appendChild(timeTablePanel); 1837 for (var i = 0; i < 24; i++) { 1838 1839 let timeSlot = document.createElement('div'); 1840 timeSlot.setAttribute('style', 'grid-row-start: ' + (i * 60) + ';'); 1841 timeSlot.classList.add('timeSlotForDay'); 1842 timeSlot.textContent = object._calendar.getPrintTime(String(i).padStart(2, '0'), '00'); 1843 let customerBox = document.createElement('div'); 1844 customerBox.setAttribute('style', 'grid-row-start: ' + (i * 60) + ';'); 1845 customerBox.classList.add('customerBoxForDay'); 1846 if (i === 0) { 1847 1848 timeSlot.setAttribute('style', 'grid-row-start: 1;'); 1849 customerBox.setAttribute('style', 'grid-row-start: 1;'); 1850 1851 } 1852 timeTablePanel.appendChild(timeSlot); 1853 timeTablePanel.appendChild(customerBox); 1854 1855 } 1856 1857 const addEmptyTimeSlots = function() { 1858 1859 let slots = {}; 1860 for (var i = 0; i < 1440; i = i + 5) { 1861 1862 slots[i] = null; 1863 1864 } 1865 1866 return slots; 1867 1868 }; 1869 1870 const addCustomerInTimeSlots = function(start, end, customer, gridCustomers) { 1871 1872 if (end > 1440) { 1873 1874 end = 1440; 1875 1876 } 1877 1878 if (start === end) { 1879 1880 end++; 1881 1882 } 1883 1884 const columns = []; 1885 var response = {status: true, columns: null}; 1886 for (var i = 0; i < gridCustomers.length; i++) { 1887 1888 const grid = gridCustomers[i]; 1889 for (var key = start; key < end; key = key + 5) { 1890 1891 if (grid[key] !== null) { 1892 1893 response.status = false;
1894 columns.push(i); 1895 break; 1896 1897 } 1898 1899 } 1900 1901 } 1902 1903 for (var i = 0; i < gridCustomers.length; i++) { 1904 1905 if (columns.includes(i) === true) { 1906 1907 continue; 1908 1909 } 1910 1911 for (var key = start; key < end; key = key + 5) { 1912 1913 response.columns = i; 1914 gridCustomers[i][key] = customer.key; 1915 response.status = true; 1916 1917 } 1918 1919 if (response.columns !== null) { 1920 1921 break; 1922 1923 } 1924 1925 } 1926 1927 response.columns++; 1928 return response; 1929 1930 }; 1931 1932 let gridCustomers = []; 1933 gridCustomers.push(addEmptyTimeSlots()); 1934 let columns = 1; 1935 for (var i = 0; i < reservationList.length; i++) { 1936 1937 let customer = reservationList[i]; 1938 object._console.log(customer); 1939 let startMinutes = parseInt(customer.date.hour) * 60 + parseInt(customer.date.min); 1940 const serviceDetails = (function(services) { 1941 1942 const serviceDetails = {time: 0, services: []}; 1943 for (var i = 0; i < services.length; i++) { 1944 1945 const service = services[i]; 1946 serviceDetails.services.push(service.name); 1947 serviceDetails.time += parseInt(service.time); 1948 const optionDetails = (function(options) { 1949 1950 const optionDetails = {time: 0, options: []}; 1951 for (var i = 0; i < options.length; i++) { 1952 1953 if (parseInt(options[i].selected) === 1) { 1954 1955 optionDetails.options.push(options[i].name); 1956 optionDetails.time += parseInt(options[i].time); 1957 1958 } 1959 1960 } 1961 return optionDetails; 1962 1963 })(service.options); 1964 1965 if (optionDetails.options.length > 0) { 1966 1967 serviceDetails.services.push( optionDetails.options.join(', ') ); 1968 1969 } 1970 1971 serviceDetails.time += optionDetails.time; 1972 1973 } 1974 1975 return serviceDetails; 1976 1977 })(customer.options); 1978 1979 const serviceTime = serviceDetails.time; 1980 let endMinutes = startMinutes + serviceTime; 1981 let result = addCustomerInTimeSlots(startMinutes, endMinutes, customer, gridCustomers); 1982 if (result.status === false) { 1983 1984 gridCustomers.push(addEmptyTimeSlots()); 1985 result = addCustomerInTimeSlots(startMinutes, endMinutes, customer, gridCustomers); 1986 1987 } 1988 if (result.columns > columns) { 1989 1990 columns = result.columns; 1991 1992 } 1993 1994 var statusClassName = "visitorPendingPanel"; 1995 if (customer.status.toLowerCase() == "approved") { 1996 1997 statusClassName = "visitorApprovedPanel"; 1998 1999 } else if (customer.status.toLowerCase() == "canceled") { 2000 2001 statusClassName = "visitorCanceledPanel"; 2002 2003 } 2004 2005 const name = (function(praivateData) { 2006 2007 var name = []; 2008 for (var i = 0; i < praivateData.length; i++) { 2009 2010 if (praivateData[i].isName == "true") { 2011 2012 name.push(praivateData[i].value); 2013 2014 } 2015 2016 } 2017 return name.join(" "); 2018 2019 })(customer.praivateData); 2020 2021 const customerInfoLabel = document.createElement('div'); 2022 customerInfoLabel.classList.add('customerInfoLabel'); 2023 customerInfoLabel.textContent = object._calendar.getPrintTime(customer.date.hour, customer.date.min) + " ID: " + customer.key + "\n" + name + "\n" + serviceDetails.services.join(', '); 2024 let style = 'grid-column-start: ' + (result.columns + 1) + '; grid-column-end: ' + (result.columns + 2) + '; grid-row-start: ' + startMinutes + '; height: ' + (serviceTime * 2) + 'px;
2024 z-index: ' + (i + 1) + ';'; 2025 if (serviceTime === 0) { 2026 2027 customerInfoLabel.textContent = object._calendar.getPrintTime(customer.date.hour, customer.date.min) + " ID: " + customer.key + "\n" + name; 2028 customerInfoLabel.setAttribute('style', 'white-space: nowrap;'); 2029 style = 'grid-column-start: ' + (result.columns + 1) + '; grid-column-end: ' + (result.columns + 2) + '; grid-row-start: ' + startMinutes + '; height: fit-content; z-index: ' + (i + 1) + ';'; 2030 2031 } 2032 2033 let customerPanel = document.createElement('div'); 2034 customerPanel.appendChild(customerInfoLabel); 2035 customerPanel.setAttribute('data-key', i); 2036 customerPanel.setAttribute('style', style); 2037 customerPanel.setAttribute('class', statusClassName + ' bookedCustomerPanel'); 2038 timeTablePanel.appendChild(customerPanel); 2039 if (i === 0 && scrollFocus === 'customer') { 2040 2041 let timer = setInterval(function(){ 2042 2043 customerPanel.scrollIntoView({ behavior: "smooth", block: "start" }); 2044 clearInterval(timer); 2045 2046 }, 300); 2047 2048 } 2049 2050 customerPanel.onclick = function(){ 2051 2052 var key = parseInt(this.getAttribute("data-key")); 2053 object._console.log(key); 2054 object._console.log(reservationList[key]); 2055 object.setSelectedKey(key); 2056 object.resetVisitorServices(); 2057 object.showUserInfo(key, calendarData, reservationList[key], true, accountKey, function(response){ 2058 2059 object._console.log(response); 2060 if (response.status == "returnButton") { 2061 2062 object.reservation_users(reservation_usersPanel, response.month, response.day, response.year, calendarData, accountKey, callback); 2063 2064 } else if (response.status == "closedCustomersPanel") { 2065 2066 object.changeDisplayFormatTab(reservation_usersPanel, month, day, year, calendarData, accountKey, callback); 2067 2068 } else { 2069 2070 callback(response); 2071 2072 } 2073 2074 }); 2075 2076 }; 2077 2078 } 2079 2080 object._console.log(gridCustomers); 2081 object._console.log('columns = ' + columns); 2082 2083 timeTablePanel.setAttribute('style', 'grid-template-columns: 80px repeat(' + columns + ', 1fr);'); 2084 var customerBoxes = timeTablePanel.querySelectorAll('.customerBoxForDay'); 2085 for (var i = 0; i < customerBoxes.length; i++) { 2086 2087 let style = customerBoxes[i].getAttribute('style'); 2088 style += ' grid-column-start: 2; grid-column-end: ' + (columns + 2) + ';'; 2089 customerBoxes[i].setAttribute('style', style); 2090 2091 } 2092 2093 } 2094 2095 2096 2097 } 2098 2099 } else { 2100 2101 var calendarArray = Object.keys(calendarData.calendar); 2102 var startKey = calendarData.calendar[calendarKey].number; 2103 var endKey = startKey + 7; 2104 2105 if(calendarArray[endKey] == null){ 2106 2107 startKey = calendarArray.length - 7; 2108 endKey = calendarArray.length; 2109 2110 } 2111 2112 //let checkOutDate = new Date(visitor.checkOut.toString().replace(/^(\d{4})(\d{2})(\d{2})$/, '$1-$2-$3')); 2113 toDay = new Date(calendarArray[startKey].toString().replace(/^(\d{4})(\d{2})(\d{2})$/, '$1-$2-$3') + 'T00:00:00+00:00'); 2114 toDayDate = parseInt(calendarArray[startKey]); 2115 //toDay = new Date(year + '-' + month + '-' + startKey); 2116 //toDayDate = parseInt(year + '' + month.toString().padStart(2, '0') + '' + startKey.toString().padStart(2, '0')); 2117 object._console.log(toDayDate); 2118 object._console.log(calendarArray[startKey].toString().replace(/^(\d{4})(\d{2})(\d{2})$/, '$1-$2-$3')); 2119 object._console.log("startKey = " + startKey + " endKey = " + endKey); 2120 object._console.log(calendarKey); 2121 object._console.log(calendarData.calendar); 2122 object._console.log(calendarArray); 2123 2124 if (object._changeDisplayFormatBookedCustomersForHotel === 'table') { 2125 2126 var tr = document.createElement("tr"); 2127 tr.setAttribute("valign", "top"); 2128 table.appendChild(tr); 2129 2130 var visitorTr = document.createElement("tr"); 2131 visitorTr.setAttribute("valign", "top"); 2132 table.appendChild(visitorTr); 2133 2134 var start = 0; 2135 var nights = 6; 2136 var end = 0; 2137 var left = 0; 2138 var visitors = {}; 2139 2140 object._calendar.setShortWeekNameBool(true); 2141 for (var i = startKey; i < endKey; i++) { 2142 2143 var key = calendarArray[i]; 2144 end = key; 2145 var calendarInfo = calendarData.calendar[key]; 2146 object._console.log("key = " + key); 2147 object._console.log(calendarInfo); 2148 2149 2150 (function(reservationList, date, start, nights, visitors) { 2151 2152 object._console.log(reservationList); 2153 object._console.log("date = " + date); 2154 object._console.log("start = " + start); 2155 2156 for (var key in reservationList) { 2157 2158 var reservation = reservationList[key]; 2159 var id = reservation.key; 2160 //object._console.log(reservation); 2161 if (visitors[id] != null) { 2162 2163 var endDay = start; 2164 2165 visitors[id].day++; 2166 visitors[id].displayNights--; 2167 visitors[id].endDay = endDay; 2168 visitors[id].accommodationDetail
2168s = reservation.accommodationDetails 2169 if (visitors[id].checkOut == date) { 2170 2171 visitors[id].checkOutBool = 1; 2172 2173 } 2174 object._console.log(visitors[id]); 2175 2176 2177 } else { 2178 2179 var name = []; 2180 for (var i = 0; i < reservation.praivateData.length; i++) { 2181 2182 var input = reservation.praivateData[i]; 2183 if (input.isName == "true") { 2184 2185 name.push(input.value); 2186 2187 } 2188 2189 } 2190 2191 name = name.join(" "); 2192 var startDay = start; 2193 if (date == parseInt(reservation.date.checkIn)) { 2194 2195 startDay = start + 0.5; 2196 2197 } 2198 2199 var endDay = start; 2200 if (date == parseInt(reservation.date.checkIn)) { 2201 2202 endDay = start - 0.5; 2203 2204 } 2205 2206 visitors[id] = {key: reservation.key, day: 0, status: reservation.status, nights: reservation.accommodationDetails.nights, displayNights: reservation.accommodationDetails.nights - start, name: name, startDay: startDay, endDay: endDay, checkIn: parseInt(reservation.date.checkIn), checkOut: parseInt(reservation.date.checkOut), checkOutBool: 0, accommodationDetails: reservation.accommodationDetails}; 2207 2208 } 2209 2210 2211 2212 } 2213 2214 })(reservationList[key], key, start, nights, visitors); 2215 start++; 2216 nights--; 2217 2218 var th = document.createElement("th"); 2219 th.classList.add("text_center"); 2220 th.setAttribute("scope", "row"); 2221 th.textContent = object._calendar.formatBookingDate(null, calendarInfo.day, null, null, null, null, calendarInfo.week, 'text'); 2222 tr.appendChild(th); 2223 object._console.log(th.clientWidth); 2224 2225 2226 var td = document.createElement("td"); 2227 td.setAttribute("data-key", key); 2228 visitorTr.appendChild(td); 2229 2230 //reservation_usersPanel 2231 var dayPanel = document.createElement("div"); 2232 dayPanel.classList.add("weekHorizotalPanel"); 2233 dayPanel.setAttribute("style", "left: " + left + "%;"); 2234 reservation_usersPanel.appendChild(dayPanel); 2235 left += 14.2; 2236 2237 } 2238 2239 object._calendar.setShortWeekNameBool(false); 2240 2241 object._console.log(visitors); 2242 object.setVisitors(visitors); 2243 object._console.log("end = " + end); 2244 2245 var visitorListPanel = document.createElement("div"); 2246 visitorListPanel.classList.add("visitorListPanel"); 2247 reservation_usersPanel.appendChild(visitorListPanel); 2248 2249 2250 var gridPostion = [ [ [], [], [], [], [], [], [], [] ] ]; 2251 for (var key in visitors) { 2252 2253 gridPostion = (function(visitor, gridPostion) { 2254 2255 //console.error(visitor);
2256 let column_start = Math.ceil(visitor.startDay) * 2; 2257 let column_end = 0; 2258 if (visitor.checkIn < toDayDate) { 2259 2260 column_start = 1; 2261 2262 } 2263 2264 let checkInDate = new Date(visitor.checkIn.toString().replace(/^(\d{4})(\d{2})(\d{2})$/, '$1-$2-$3') + 'T00:00:00+00:00'); 2265 if (visitor.checkIn < toDayDate) { 2266 2267 checkInDate = toDay; 2268 2269 } 2270 let checkOutDate = new Date(visitor.checkOut.toString().replace(/^(\d{4})(\d{2})(\d{2})$/, '$1-$2-$3') + 'T00:00:00+00:00'); 2271 let nightsDiff = checkOutDate.getTime() - checkInDate.getTime(); 2272 let nightDays = Math.ceil(nightsDiff / (1000 * 3600 * 24)); 2273 let timeDiff = checkOutDate.getTime() - toDay.getTime(); 2274 let remainingDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); 2275 //console.error("remainingDays = " + remainingDays + " nightDays = " + nightDays); 2276 if (remainingDays > 7) { 2277 2278 column_end = 15; 2279 2280 } else if (parseInt(visitor.checkOut) < toDayDate) { 2281 2282 column_end = 2; 2283 2284 } else { 2285 2286 column_end = column_start + nightDays * 2; 2287 if (visitor.checkIn < toDayDate) { 2288 2289 column_end++; 2290 2291 } 2292 2293 } 2294 2295 visitor.grid = {column_start: column_start, column_end: column_end, row_start: 0}; 2296 //console.error('column_start = ' + column_start + ' column_end = ' + column_end); 2297 let inseart = false;
2298 var addGrid = function(gridPostion, visitor) { 2299 2300 for (var i = 0; i < gridPostion.length; i++) { 2301 2302 inseart = (function(gridPostion, row, visitor) { 2303 2304 let endDay = visitor.endDay; 2305 let startDay = Math.ceil(visitor.startDay); 2306 2307 let specifiedDate = new Date(visitor.checkOut.toString().replace(/^(\d{4})(\d{2})(\d{2})$/, '$1-$2-$3') + 'T00:00:00+00:00'); 2308 let timeDiff = specifiedDate.getTime() - toDay.getTime(); 2309 let remainingDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); 2310 2311 if (remainingDays >= 7) { 2312 2313 endDay = 7; 2314 2315 } 2316 //console.error('startDay = ' + startDay + ' endDay = ' + endDay + ' remainingDays = ' + remainingDays); 2317 for (var i = startDay; i <= endDay; i++) { 2318 2319 if (gridPostion[i].length > 0) { 2320 2321 return false; 2322 2323 } 2324 2325 } 2326 2327 for (var i = startDay; i <= endDay; i++) { 2328 2329 gridPostion[i] = visitor.key; 2330 2331 } 2332 2333 visitor.grid.row_start = row + 1; 2334 return true; 2335 2336 })(gridPostion[i], i, visitor); 2337 2338 if (inseart === true) { 2339 2340 break; 2341 2342 } 2343 2344 } 2345 2346 return inseart; 2347 2348 }; 2349 2350 2351 inseart = addGrid(gridPostion, visitor); 2352 if (inseart === false) { 2353 2354 gridPostion.push([ [], [], [], [], [], [], [], [] ]); 2355 inseart = addGrid(gridPostion, visitor); 2356 2357 } 2358 2359 return gridPostion; 2360 2361 })(visitors[key], gridPostion); 2362 2363 } 2364 2365 var i = 0; 2366 for(var key in visitors){ 2367 2368 object._console.log(visitors[key]); 2369 const grid = visitors[key].grid; 2370 2371 /** 2372 var width = 14.2 * visitors[key].day; 2373 var left = 14.2 * visitors[key].startDay; 2374 2375 if(visitors[key].checkOut > end){ 2376 2377 width = 14.2 * (visitors[key].day + 0.5); 2378 2379 2380 } 2381 2382 object._console.log("key = " + key + "width = " + (width + left)); 2383 if(visitors[key].checkOutBool == 0 && visitors[key].day == 6){ 2384 2385 width = 99.4 - left; 2386 2387 }else{ 2388 2389 if(visitors[key].startDay == 0){ 2390 2391 width += 7.1; 2392 2393 } 2394 2395 } 2396 **/ 2397 2398 var visitorPanel = document.createElement("div"); 2399 //visitorPanel.setAttribute("style", "width: " + width + "%; left: " + left + "%;"); 2400 visitorPanel.setAttribute("style", "grid-column-start: " + grid.column_start + "; grid-column-end: " + grid.column_end + "; grid-row-start: " + grid.row_start); 2401 visitorPanel.setAttribute("data-index", i); 2402 visitorPanel.setAttribute("data-key", key); 2403 visitorPanel.setAttribute("data-checkIn", visitors[key].checkIn); 2404 visitorPanel.classList.add("visitorPanel"); 2405 visitorPanel.textContent = "ID: " + visitors[key].key + ' ' + visitors[key].name; 2406 visitorListPanel.appendChild(visitorPanel);
2407 if (visitors[key].status == "pending") { 2408 2409 visitorPanel.classList.add("visitorPendingPanel"); 2410 2411 } else if (visitors[key].status.toLowerCase() == "approved") { 2412 2413 visitorPanel.classList.add("visitorApprovedPanel"); 2414 2415 } else if (visitors[key].status.toLowerCase() == "canceled") { 2416 2417 visitorPanel.classList.add("visitorCanceledPanel"); 2418 2419 } 2420 2421 visitorPanel.onclick = function(){ 2422 2423 var key = this.getAttribute("data-key"); 2424 object._console.log("key = " + key); 2425 object._console.log(visitors[key]); 2426 var key = parseInt(this.getAttribute("data-key")); 2427 var checkIn = parseInt(this.getAttribute("data-checkIn")); 2428 var index = parseInt(this.getAttribute("data-index")); 2429 object.setSelectedKey(index); 2430 object._console.log(key); 2431 object._console.log(reservationList[checkIn][key]); 2432 object.showUserInfo(key, calendarData, reservationList[checkIn][key], true, accountKey, function(response){ 2433 2434 object._console.log(response); 2435 if (response.status == "returnButton") { 2436 2437 object.reservation_users(reservation_usersPanel, response.month, response.day, response.year, calendarData, accountKey, callback); 2438 2439 } else if (response.status == "closedCustomersPanel") { 2440 2441 object.changeDisplayFormatTab(reservation_usersPanel, month, day, year, calendarData, accountKey, callback); 2442 2443 } else { 2444 2445 callback(response); 2446 2447 } 2448 2449 }); 2450 2451 }; 2452 2453 i++; 2454 2455 } 2456 2457 } else { 2458 2459 let month = parseInt(calendarKey.substr(4, 2)); 2460 let day = parseInt(calendarKey.substr(6, 2)) 2461 let year = parseInt(calendarKey.substr(0, 4)); 2462 for (var key in reservationList[calendarKey]) { 2463 2464 let bookedCustomer = reservationList[calendarKey][key]; 2465 object._console.log(bookedCustomer); 2466 const checkIn = bookedCustomer.accommodationDetails.checkInSchedule; 2467 if (parseInt(checkIn.month) === month && parseInt(checkIn.day) === day && parseInt(checkIn.year) === year) { 2468 2469 let tr = createRow(key, bookedCustomer, table, accountKey, calendarData, reservationList[calendarKey]); 2470 2471 } 2472 2473 } 2474 2475 } 2476 2477 2478 2479 2480 } 2481 2482 if (object._dashboardRequest.status == 1) { 2483 2484 object._console.log(object._dashboardRequest); 2485 var key = 0; 2486 var visitorData = null; 2487 if (calendarData.account.type == "day") { 2488 2489 for (var i = 0; i < reservationList.length; i++) { 2490 2491 var userInfo = reservationList[i]; 2492 if (parseInt(userInfo.key) == parseInt(object._dashboardRequest.key)) { 2493 2494 key = i; 2495 visitorData = reservationList[key]; 2496 break; 2497 2498 } 2499 2500 } 2501 2502 object.setTypeOfId('index'); 2503 2504 } else { 2505 2506 var checkIn = object._calendar.getDateKey(object._dashboardRequest.month, object._dashboardRequest.day, object._dashboardRequest.year); 2507 object._console.log("checkIn = " + checkIn); 2508 object._console.log(reservationList[checkIn]); 2509 key = object._dashboardRequest.key; 2510 visitorData = reservationList[checkIn][object._dashboardRequest.key]; 2511 object.setTypeOfId('key'); 2512 2513 } 2514 2515 object.setSelectedKey(key); 2516 object.showUserInfo(key, calendarData, visitorData, true, accountKey, function(response){ 2517 2518 object._console.log(response); 2519 if (response.status == "returnButton") { 2520 2521 object.reservation_users(reservation_usersPanel, response.month, response.day, response.
2521year, calendarData, accountKey, callback); 2522 2523 } else if (response.status == "closedCustomersPanel") { 2524 2525 object.changeDisplayFormatTab(reservation_usersPanel, response.month, response.day, response.year, calendarData, accountKey, callback); 2526 2527 } else { 2528 2529 callback(response); 2530 2531 } 2532 2533 }); 2534 object._dashboardRequest.status = 0; 2535 object._console.log(object._dashboardRequest); 2536 2537 } 2538 2539 }; 2540 2541 this.showUserInfo = function(key, calendarData, reservationData, animation, accountKey, callback) { 2542 2543 var object = this; 2544 var options = "[]"; 2545 object._buttonAction = "showUserInfo"; 2546 object._console.log("key = " + key); 2547 object._console.log("buttonAction = " + object._buttonAction); 2548 object._console.log(calendarData); 2549 object._console.log(reservationData); 2550 if (reservationData == null) { 2551 2552 object._leftButtonPanel.textContent = null; 2553 object._rightButtonPanel.textContent = null; 2554 object.editPanelShow(false); 2555 return null; 2556 2557 } 2558 2559 var infoPanel = null; 2560 if (document.getElementById("userInfoPanel") == null) { 2561 2562 infoPanel = document.createElement("div"); 2563 infoPanel.id = "userInfoPanel"; 2564 object._contentPanel.appendChild(infoPanel); 2565 2566 } else { 2567 2568 infoPanel = document.getElementById("userInfoPanel"); 2569 2570 2571 } 2572 2573 var blockPanel = null; 2574 if (animation === true) { 2575 2576 infoPanel.setAttribute("class", "show_panel"); 2577 2578 blockPanel = document.createElement("div"); 2579 blockPanel.id = "showUserInfo_blockPanel"; 2580 blockPanel.setAttribute("class", "blockPanel"); 2581 object._contentPanel.insertBefore(blockPanel, infoPanel); 2582 2583 } 2584 2585 var deleteButton = document.createElement("button"); 2586 deleteButton.id = "deleteButton"; 2587 deleteButton.textContent = object._i18n.get("Delete", []); 2588 deleteButton.setAttribute("class", "button media-button button-primary button-large media-button-insert"); 2589 2590 var editButton = document.createElement("button"); 2591 editButton.id = "editButton"; 2592 editButton.textContent = object._i18n.get("Edit"); 2593 editButton.setAttribute("class", "button media-button button-primary button-large media-button-insert"); 2594 editButton.setAttribute("style", "margin-left: 10px;"); 2595 if (parseInt(reservationData.accountKey) != parseInt(accountKey)) { 2596 2597 editButton.classList.add('hidden_panel'); 2598 2599 } 2600 2601 object._rightButtonPanel.textContent = null; 2602 object._rightButtonPanel.appendChild(deleteButton); 2603 object._rightButtonPanel.appendChild(editButton); 2604 2605 //document.getElementById("beforButton").classList.add("hidden_panel"); 2606 2607 var weekName = [object._i18n.get('Sun'), object._i18n.get('Mon'), object._i18n.get('Tue'), object._i18n.get('Wed'), object._i18n.get('Thu'), object._i18n.get('Fri'), object._i18n.get('Sat')]; 2608 object._calendar = new Booking_App_Calendar(weekName, object._dateFormat, object._positionOfWeek, object._positionTimeDate, object._startOfWeek, object._i18n, object._debug); 2609 object._calendar.setClock(object._clock); 2610 infoPanel.textContent = null; 2611 2612 var reservationDate = reservationData.date; 2613 var date = object._calendar.formatBookingDate(reservationDate.month, reservationDate.day, reservationDate.year, reservationDate.hour, reservationDate.min, reservationData.scheduleTitle, reservationData.date.week, 'text'); 2614 2615 var month = reservationData.date.month; 2616 var day = reservationData.date.day; 2617 var year = reservationData.date.year; 2618 object._console.log(date); 2619 2620 var bookingTimeChange = document.createElement("div"); 2621 bookingTimeChange.setAttribute("data-status", "1"); 2622 bookingTimeChange.setAttribute("class", "change hidden_panel"); 2623 bookingTimeChange.textContent = object._i18n.get("Change"); 2624 2625 var courseChange = document.createElement("div"); 2626 courseChange.setAttribute("data-status", "1"); 2627 courseChange.setAttribute("class", "change hidden_panel"); 2628 courseChange.textContent = object._i18n.get("Change"); 2629 2630 var response = object.showUserDetails(key, calendarData, reservationData, accountKey, true, infoPanel, bookingTimeChange, courseChange, function(response){ 2631 2632 object._console.log(response); 2633 callback(response); 2634 2635 }); 2636 2637 var userInfoPanel = document.getElementById('userInfoPanel'); 2638 if (typeof userInfoPanel == 'object' && typeof userInfoPanel.scrollTo == 'function') { 2639 2640 userInfoPanel.scrollTo(0, 0); 2641 2642 } 2643 2644 var formPanel = response.formPanel; 2645 var formPanelList = response.formPanelList; 2646 var formData = response.formData; 2647 var totalNumberOfGuestsPanel = response.totalNumberOfGuestsPanel; 2648 2649 var cancelToEdit = function(closePanel){ 2650 2651 if (closePanel === false) { 2652 2653 callback({status: 'returnButton', month: reservationDate.month, day: reservationDate.day, year: reservationDate.year}); 2654 object.showUserInfo(key, calendarData, reservationData, animation, accountKey, callback); 2655 2656 } 2657 2658 document.getElementById("beforButton").classList.remove("hidden_panel"); 2659 document.getElementById("nextButton").classList.remove("hidden_panel"); 2660 document.getElementById('downloadCsvForDay').classList.remove('hidden_panel'); 2661 document.getElementById("beforChangeButton").classList.add("hidden_panel"); 2662 document.getElementById("nextChangeButton").classList.add("hidden_panel"); 2663 2664 return null; 2665 2666 2667 bookingTimeChange.classList.add("hidden_panel"); 2668 bookingTimeChange.setAttribute("data-status", "1"); 2669 bookingTimeChange.textContent = object._i18n.get("Change"); 2670 courseChange.classList.add("hidden_panel"); 2671 courseChange.setAttribute("data-status", "1"); 2672 courseChange.textContent = object._i18n.get("Change"); 2673 2674 2675 var date = object._calendar.formatBookingDate(reservationData.date.month, reservationData.date.day, reservationData.date.year, reservationData.date.hour, reservationData.date.min, reservationData.scheduleTitle, reservationData.date.week, 'text'); 2676 if(document.getElementById("booking_date") != null){ 2677 2678 object._console.log("date = " + date); 2679 var dateLabel = document.getElementById("booking_date"); 2680 dateLabel.setAttribute("data-key", reservationData.scheduleKey); 2681 dateLabel.setAttribute("data-unixTime", reservationData.scheduleUnixTime); 2682 dateLabel.textContent = date; 2683 2684 } 2685 2686 if(reservationData.courseKey != null && reservationData.courseTime != null && document.getElementById("booking_course") != null){ 2687 2688 object._console.log(reservationData); 2689 var courseLabel = document.getElementById("booking_course"); 2690 courseLabel.setAttribute("data-key", reservationData.courseKey); 2691 courseLabel.setAttribute("data-time", reservationData.courseTime); 2692 courseLabel.textContent = reservationData.courseName; 2693 2694 } 2695 2696 if(document.getElementById("booking_cost") != null){ 2697 2698 var cost = object._format.formatCost(reservationData.courseCost, reservationData.currency); 2699 document.getElementById("booking_cost").textContent = cost; 2700 2701 } 2702 2703 document.getElementById("beforButton").classList.remove("hidden_panel"); 2704 document.getElementById("nextButton").classList.remove("hidden_panel"); 2705 document.getElementById('downloadCsvForDay').classList.remove('hidden_panel'); 2706 document.getElementById("beforChangeButton").classList.add("hidden_panel"); 2707 document.getElementById("nextChangeButton").classList.add("hidden_panel"); 2708 2709 var responseData = {}; 2710 if (calendarData.account.type == "hotel") { 2711 2712 /** Rooms **/ 2713 var guestsList = object._hotel.getGuestsList(); 2714 var visitorsDetails = object._hotel.verifySchedule(false);
2715 for (var roomKey in visitorsDetails.rooms) { 2716 2717 for (var key in guestsList) { 2718 2719 object._console.log(guestsList[key]); 2720 var guestsParentPanel = document.getElementById("guests_" + roomKey + '_' + key).parentElement; 2721 var guestsPanel = document.getElementById("guests_" + roomKey + '_' + key); 2722 var guestsSelectPanel = document.getElementById("select_guests_" + roomKey + '_' + key); 2723 guestsPanel.classList.remove("hidden_panel"); 2724 object._console.log(guestsSelectPanel); 2725 if (guestsSelectPanel != null) { 2726 2727 guestsParentPanel.removeChild(guestsSelectPanel); 2728 2729 } 2730 2731 } 2732 2733 } 2734 /** Rooms **/ 2735 /** 2736 var guestsList = object._hotel.getGuestsList(); 2737 for(var key in guestsList){ 2738 2739 object._console.log(guestsList[key]); 2740 var guestsParentPanel = document.getElementById("guests_" + key).parentElement; 2741 var guestsPanel = document.getElementById("guests_" + key); 2742 var guestsSelectPanel = document.getElementById("select_guests_" + key); 2743 guestsPanel.classList.remove("hidden_panel"); 2744 object._console.log(guestsSelectPanel); 2745 if(guestsSelectPanel != null){ 2746 2747 guestsParentPanel.removeChild(guestsSelectPanel); 2748 2749 } 2750 2751 } 2752 **/ 2753 2754 var totalNumberOfGuests = parseInt(reservationData.accommodationDetails.adult) + parseInt(reservationData.accommodationDetails.children); 2755 if (totalNumberOfGuestsPanel != null) { 2756 2757 totalNumberOfGuestsPanel.classList.remove("errorPanel"); 2758 document.getElementById("totalGuests").textContent = totalNumberOfGuests; 2759 2760 } 2761 2762 2763 } else { 2764 2765 var edit_title = document.getElementById("edit_title"); 2766 edit_title.textContent = object._calendar.formatBookingDate(reservationData.date.month, reservationData.date.day, reservationData.date.year, null, null, null, reservationData.date.week, 'text'); 2767 2768 } 2769 2770 object._console.log(calendarData); 2771 object._console.log(reservationData); 2772 2773 responseData = {status: "returnButton", month: month, day: day, year: year, calendarData: calendarData}; 2774 2775 }; 2776 2777 if (blockPanel != null) { 2778 2779 blockPanel.onclick = function(event){ 2780 2781 object._console.log("blockPanel click"); 2782 object._buttonAction = "reservation_users"; 2783 object._rightButtonPanel.textContent = null; 2784 if (document.getElementById("changePanel") != null) { 2785 2786 document.getElementById("changePanel").setAttribute("class", "return_panel"); 2787 2788 } 2789 infoPanel.setAttribute("class", "return_panel"); 2790 object._contentPanel.removeChild(blockPanel); 2791 2792 cancelToEdit(true); 2793 callback({status: 'closedCustomersPanel', month: month, day: day, year: year}); 2794 2795 2796 }; 2797 2798 } 2799 2800 var object = this; 2801 editButton.onclick = function(){ 2802 2803 options = reservationData.options; 2804 object.setVisitorServices(options); 2805 object._console.log(options); 2806 2807 document.getElementById("beforButton").classList.add("hidden_panel"); 2808 document.getElementById("nextButton").classList.add("hidden_panel"); 2809 document.getElementById('downloadCsvForDay').classList.add('hidden_panel'); 2810 2811 if (reservationData.status !== 'canceled') { 2812 2813 bookingTimeChange.classList.remove("hidden_panel"); 2814 courseChange.classList.remove("hidden_panel"); 2815 2816 } 2817 2818 editButton.setAttribute("class", "hidden_panel"); 2819 deleteButton.setAttribute("class", "hidden_panel"); 2820 2821 var returnButton = document.createElement("button"); 2822 returnButton.id = "returnButton"; 2823 returnButton.textContent = object._i18n.get("Return"); 2824 returnButton.setAttribute("class", "button media-button button-primary button-large media-button-insert"); 2825 returnButton.setAttribute("style", "margin-left: 10px;"); 2826 object._rightButtonPanel.appendChild(returnButton); 2827 2828 var saveButton = document.createElement("button"); 2829 saveButton.id = "saveButton"; 2830 saveButton.textContent = object._i18n.get("Update"); 2831 saveButton.setAttribute("class", "button media-button button-primary button-large media-button-insert"); 2832 saveButton.setAttribute("style", "margin-left: 10px;"); 2833 object._rightButtonPanel.appendChild(saveButton); 2834 2835 var inputPanelList = {}; 2836 var inputData = {}; 2837 var input = new Booking_Package_Input(object._debug); 2838 input.setAdmin(true); 2839 2840 if(calendarData.account.type == "hotel"){ 2841 2842 /** 2843 var value = input.createInput(i, form, inputData, null); 2844 var rowPanel = createRowPanel(form.name, value, null, form.required, null); 2845 **/ 2846 var visitorsDetails = object._hotel.verifySchedule(false); 2847 object._console.log(visitorsDetails); 2848 if(visitorsDetails.status == true){ 2849 2850 /** Rooms **/ 2851 var guestsList = object._hotel.getGuestsList(); 2852 var hotelOptions = object._hotel.getOptions(); 2853 var rooms = visitorsDetails.rooms;
2854 for (var roomKey in visitorsDetails.rooms) { 2855 2856 var room = visitorsDetails.rooms[roomKey]; 2857 var roomNumber = parseInt(roomKey) + 1; 2858 object._console.log(room); 2859 2860 /** Select options with Hotel **/ 2861 object._console.log(hotelOptions); 2862 if (Object.keys(hotelOptions).length > 0) { 2863 2864 for (var key in hotelOptions) { 2865 2866 object._console.log(key); 2867 var options = hotelOptions[key]; 2868 options.id = 'booking_package_option_' + options.key; 2869 options.description = null; 2870 hotelOptions[key].json = (function(options, selectedOption){ 2871 2872 if (selectedOption == null) { 2873 2874 return options; 2875 2876 } 2877 options = JSON.parse(options); 2878 for (var key in options) { 2879 2880 options[key].selected = 0; 2881 if (parseInt(options[key].index) == parseInt(selectedOption.index)) { 2882 2883 options[key].selected = 1; 2884 2885 } 2886 2887 } 2888 object._console.log(options); 2889 return JSON.stringify(options); 2890 2891 })(hotelOptions[key].json, room.options[key]); 2892 2893 hotelOptions[key].value = (function(selectedOption){ 2894 2895 if (selectedOption == null) { 2896 2897 return 0; 2898 2899 } else { 2900 2901 object._console.log(selectedOption.name); 2902 return selectedOption.name; 2903 2904 } 2905 2906 })(room.options[key]); 2907 2908 object._console.log(hotelOptions[key]); 2909 var value = input.createInput('booking_package_option_' + key, hotelOptions[key], {}, function(event) { 2910 2911 var key = this.parentElement.getAttribute("data-option"); 2912 var roomKey = this.parentElement.getAttribute('data-room'); 2913 var index = parseInt(this.selectedIndex); 2914 object._console.log(hotelOptions[key]); 2915 var response = object._hotel.updateSelectedOptions(key, index, roomKey, true); 2916 var feeList = object._hotel.getSubtotals(); 2917 var verifyGuests = object._hotel.verifyGuestsInRooms(response.rooms); 2918 object._console.log(verifyGuests); 2919 if (verifyGuests.booking == false || response.nights == 0 || verifyGuests.requiredGuests == false || verifyGuests.requiredOptions == false) { 2920 2921 saveButton.disabled = true; 2922 2923 } else { 2924 2925 saveButton.disabled = false;
2926 2927 } 2928 2929 }); 2930 value.id = "select_options_" + roomKey + '_' + key; 2931 value.setAttribute("data-option", key); 2932 value.setAttribute('data-room', parseInt(roomKey)); 2933 object._console.log(value); 2934 var optionsParentPanel = document.getElementById("options_" + roomKey + '_' + key).parentElement; 2935 var optionsPanel = document.getElementById("options_" + roomKey + '_' + key); 2936 optionsPanel.classList.add("hidden_panel"); 2937 optionsParentPanel.appendChild(value); 2938 object._console.log(optionsPanel); 2939 optionsPanel = value; 2940 2941 } 2942 2943 2944 } 2945 2946 2947 /** Select options with Hotel **/ 2948 2949 /** Select guests with Hotel **/ 2950 for (var key in guestsList) { 2951 2952 object._console.log(key); 2953 var guests = guestsList[key]; 2954 guests.id = 'booking_package_guest_' + guests.key; 2955 guests.description = null; 2956 guestsList[key].json = (function(guests, valueGuest){ 2957 2958 if (valueGuest == null) { 2959 2960 return guests; 2961 2962 } 2963 guests = JSON.parse(guests); 2964 for (var key in guests) { 2965 2966 guests[key].selected = 0; 2967 if (parseInt(guests[key].number) === parseInt(valueGuest.number) && guests[key].name === valueGuest.name) { 2968 2969 guests[key].selected = 1; 2970 2971 } 2972 2973 } 2974 object._console.log(guests); 2975 return JSON.stringify(guests); 2976 2977 })(guestsList[key].json, room.guests[key]); 2978 2979 guestsList[key].value = (function(valueGuest){ 2980 2981 if (valueGuest == null) { 2982 2983 return 0; 2984 2985 } else { 2986 2987 object._console.log(valueGuest.name); 2988 return valueGuest.name; 2989 2990 } 2991 2992 })(room.guests[key]); 2993 2994 object._console.log(guestsList[key]); 2995 var value = input.createInput('booking_package_guest_' + key, guestsList[key], {}, function(event) { 2996 2997 var key = this.parentElement.getAttribute("data-guset"); 2998 var roomKey = this.parentElement.getAttribute('data-room'); 2999 var index = parseInt(this.selectedIndex); 3000 var response = object._hotel.updateSelectedGuests(key, index, room
3000Key, true); 3001 /** 3002 var guestsList = object._hotel.getRoom(roomKey); 3003 var list = JSON.parse(guestsList[key].json); 3004 var selectedGuest = list[index]; 3005 guestsList[key].index = index; 3006 guestsList[key].person = parseInt(selectedGuest.number); 3007 object._console.log('roomKey = ' + roomKey); 3008 object._console.log('index = ' + index); 3009 object._console.log(selectedGuest); 3010 **/ 3011 //var response = object._hotel.setGuests(key, index, list[index].number, parseInt(roomKey)); 3012 var feeList = object._hotel.getSubtotals(); 3013 var verifyGuests = object._hotel.verifyGuestsInRooms(response.rooms); 3014 object._console.log(verifyGuests); 3015 var person = 0; 3016 for (var key in verifyGuests.rooms) { 3017 3018 person += parseInt(verifyGuests.rooms[key].person); 3019 3020 } 3021 document.getElementById("totalGuests").textContent = person; 3022 if (verifyGuests.booking == false || response.nights == 0 || verifyGuests.requiredGuests == false || verifyGuests.requiredOptions == false) { 3023 3024 saveButton.disabled = true; 3025 3026 } else { 3027 3028 saveButton.disabled = false; 3029 3030 } 3031 3032 totalNumberOfGuestsPanel.classList.remove("errorPanel"); 3033 if(verifyGuests.booking == false){ 3034 3035 totalNumberOfGuestsPanel.classList.add("errorPanel"); 3036 3037 } 3038 3039 object._console.log(totalNumberOfGuestsPanel); 3040 3041 object._console.log(response); 3042 object._console.log(this.selectedIndex); 3043 3044 }); 3045 value.id = "select_guests_" + roomKey + '_' + key; 3046 value.setAttribute("data-guset", key); 3047 value.setAttribute('data-room', parseInt(roomKey)); 3048 object._console.log(value); 3049 var guestsParentPanel = document.getElementById("guests_" + roomKey + '_' + key).parentElement; 3050 var guestsPanel = document.getElementById("guests_" + roomKey + '_' + key); 3051 guestsPanel.classList.add("hidden_panel"); 3052 guestsParentPanel.appendChild(value); 3053 object._console.log(guestsPanel); 3054 guestsPanel = value; 3055 3056 } 3057 /** Select guests with Hotel **/ 3058 3059 } 3060 /** Rooms **/ 3061 3062 } 3063 3064 } 3065 3066 3067 for(var i = 0; i < formPanelList.length; i++){ 3068 3069 //var key = parseInt(formPanelList[i].getAttribute("data-key")); 3070 var form = formData[i]; 3071 object._console.log(i + " name = " + form.name); 3072 formPanel.removeChild(formPanelList[i]); 3073 var value = input.createInput(i, form, inputData, null); 3074 var rowPanel = object.createRowPanel(form.name, value, null, form.required, null); 3075 if(form.active != 'true'){ 3076 3077 rowPanel.classList.add("hidden_panel"); 3078 3079 } 3080 inputPanelList[i] = rowPanel; 3081 //inputPanelList.push(rowPanel); 3082 formPanel.appendChild(rowPanel); 3083 3084 } 3085 3086 object._console.log(formPanelList); 3087 saveButton.onclick = function(){ 3088 3089 var date = {month: (reservationDate.month + 1), day: reservationDate.day, year: reservationDate.year}; 3090 var schedule = {key: reservationData.scheduleKey, unixTime: reservationData.scheduleUnixTime}; 3091 var course = {key: reservationData.courseKey}; 3092 if(reservationData.courseKey == null){ 3093 course = null 3094 } 3095 3096 var valueList = {}; 3097 var post = object.verifyForm("updateBooking", object._nonce, object._action, date, schedule, course, formData, inputPanelList, inputData, valueList, []); 3098 var booking_date = null; 3099 if(calendarData.account.type == "day"){ 3100 3101 booking_date = document.getElementById("booking_date").getAttribute("data-key"); 3102 3103 }else{ 3104 3105 booking_date = document.getElementById("checkIn").getAttribute("data-id"); 3106 3107 } 3108 object._console.log(booking_date); 3109 if(booking_date != reservationData.scheduleKey){ 3110 3111 post['update_booking_date'] = booking_date; 3112 3113 } 3114 3115 3116 if(calendarData.account.type == "hotel"){ 3117 3118 post.json = JSON.stringify(object._hotel.verifySchedule(false)); 3119 3120 } 3121 3122 if (document.getElementById("booking_course") != null) { 3123 3124 var booking_course = document.getElementById("booking_course").getAttribute("data-key"); 3125 object._console.log(booking_course); 3126 post['update_booking_course'] = booking_course; 3127 3128 } 3129 3130 post.month = parseInt(month); 3131 post.day = parseInt(day); 3132 post.year = year; 3133 post.sendEmail = 0; 3134 if(options == null) { 3135 3136 options = "[]"; 3137 3138 } 3139 post.options = options; 3140 object._console.log(typeof options); 3141 var visitorServices = object.getVisitorServices(); 3142 if (typeof visitorServices == "object") { 3143 3144 var services = []; 3145 for (var key in object._courseList) { 3146 3147 var service = object._courseList[key]; 3148 for (var visitorKey in visitorServices) { 3149 3150 var visitorService = visitorServices[visitorKey]; 3151 if (parseInt(service.key) == parseInt(visitorService.key) && parseInt(visitorService.selected) == 1) { 3152 3153 visitorService.options = visitorService.selectedOptionsList; 3154 object._console.log(visitorService); 3155 services.push(visitorService); 3156 3157 } 3158 3159 } 3160 3161 3162 } 3163 3164 post.options = JSON.stringify(services); 3165 3166 } 3167 object._console.log(post); 3168 //return null; 3169 3170 if (post !== false) { 3171 3172 var enable = true; 3173 if (parseInt(object._emailEnableList.booking_updated_notification.enable) == 1) { 3174 3175 object._console.log("mail_pending = " + Boolean(parseInt(object._emailEnableList.booking_updated_notification.enable))); 3176 enable = false;
3177 3178 } 3179 3180 confirm.dialogPanelShow(object._i18n.get("Attention"), object._i18n.get("Will emails be sent to both customers and admins?"), enable, 0, function(sendEmail) { 3181 3182 object._console.log(sendEmail); 3183 3184 object._loadingPanel.setAttribute("class", "loading_modal_backdrop"); 3185 post.accountKey = reservationData.accountKey; 3186 post.updateKey = reservationData.key; 3187 post.sendEmail = Number(sendEmail); 3188 object._console.log(post); 3189 new Booking_App_XMLHttp(object._url, post, object._webApp, function(response){ 3190 3191 object._console.log(response); 3192 if (response.status == "success") { 3193 3194 object._hotel.reset(); 3195 object._hotel.setCallback(null); 3196 var updateDate = {month: parseInt(month), day: parseInt(day), year: year}; 3197 response.updateDate = updateDate; 3198 3199 object._rightButtonPanel.textContent = null; 3200 response.action = 'refresh'; 3201 object._buttonAction = "reservation_users"; 3202 object.createCalendar(response, response.date.month, response.date.day, response.date.year, accountKey); 3203 callback(response); 3204 object._contentPanel.removeChild(blockPanel); 3205 infoPanel.setAttribute("class", "return_panel"); 3206 if (document.getElementById("changePanel") != null) { 3207 3208 document.getElementById("changePanel").setAttribute("class", "return_panel"); 3209 3210 } 3211 3212 } else { 3213 3214 if (response.message != null) { 3215 3216 alert(response.message); 3217 3218 } else { 3219 3220 alert(response); 3221 3222 } 3223 3224 3225 } 3226 object._loadingPanel.setAttribute("class", "hidden_panel"); 3227 3228 }, function(responseText){ 3229 3230 //object.setResponseText(responseText); 3231 3232 }); 3233 3234 }); 3235 3236 3237 3238 } 3239 3240 } 3241 3242 returnButton.onclick = function(){ 3243 3244 var edit_title = document.getElementById("edit_title"); 3245 edit_title.textContent = object._calendar.formatBookingDate(reservationData.date.month, reservationData.date.day, reservationData.date.year, null, null, null, null, 'text'); 3246 3247 if(document.getElementById("changePanel") != null && document.getElementById("changePanel").getAttribute("class") != "return_panel"){ 3248 3249 document.getElementById("changePanel").setAttribute("class", "return_change_panel"); 3250 3251 } 3252 object._contentPanel.removeChild(blockPanel); 3253 object._rightButtonPanel.removeChild(returnButton); 3254 object._rightButtonPanel.removeChild(saveButton); 3255 editButton.setAttribute("class", "button media-button button-primary button-large media-button-insert"); 3256 deleteButton.setAttribute("class", "button media-button button-primary button-large media-button-insert"); 3257 for(var key in inputPanelList){ 3258 3259 formPanel.removeChild(inputPanelList[key]); 3260 //var form = formData[i]; 3261 var rowPanel = object.createRowPanel(formData[key]['name'], formData[key]['value'], null, null, null); 3262 if(formData[key].active != 'true'){ 3263 3264 rowPanel.classList.add("hidden_panel"); 3265 3266 } 3267 formPanelList[key] = rowPanel; 3268 formPanel.appendChild(rowPanel); 3269 3270 } 3271 3272 cancelToEdit(false); 3273 object._buttonAction = "showUserInfo"; 3274 3275 } 3276 3277 3278 } 3279 3280 deleteButton.onclick = function(){ 3281 3282 object._console.log(object._emailEnableList); 3283 object._console.log("enable = " + Boolean(parseInt(object._emailEnableList.booking_deleted_notification.enable))); 3284 3285 var enable = false;
3286 if (Boolean(parseInt(object._emailEnableList.booking_deleted_notification.enable)) === false) { 3287 3288 enable = true; 3289 3290 } 3291 object._console.log("enable = " + enable); 3292 3293 var confirm = new Confirm(object._debug); 3294 var refoundBool = true; 3295 if (reservationData.payToken != null && reservationData.payToken.length != 0 && (reservationData.payMode == 'CreditCard' || reservationData.payMode == 'stripePayPay')) { 3296 3297 refoundBool = false; 3298 3299 } 3300 object._console.log(reservationData.payName); 3301 object._console.log(reservationData.payToken); 3302 confirm.dialogPanelShow(object._i18n.get("Attention"), object._i18n.get("This booking was paid via %s. Will the payment be refunded to the customer?", [reservationData.payName]), refoundBool, 0, function(refoundValue) { 3303 3304 object._console.log("refoundValue = " + refoundValue); 3305 confirm.dialogPanelShow(object._i18n.get("Attention"), object._i18n.get("Will emails be sent to both customers and admins?"), enable, 0, function(sendEmail) { 3306 3307 object._console.log("sendEmail = " + sendEmail); 3308 object._console.log("sendEmail = " + parseInt(sendEmail)); 3309 confirm.dialogPanelShow(object._i18n.get("Warning"), object._i18n.get("Are you sure you want to delete this booking?"), false, 1, function(result) { 3310 3311 object._console.log(result); 3312 if (result == true) { 3313 3314 object._loadingPanel.setAttribute("class", "loading_modal_backdrop"); 3315 var post = {nonce: object._nonce, action: object._action, mode: 'deleteBookingData', key: reservationData.key, token: reservationData.cancellationToken, sendEmail: Number(sendEmail), refound: Number(refoundValue), accountKey: reservationData.accountKey}; 3316 new Booking_App_XMLHttp(object._url, post, object._webApp, function(response) { 3317 3318 object._console.log(response); 3319 if (response.status == 'success') { 3320 3321 object._hotel.reset(); 3322 object._hotel.setCallback(null); 3323 object._rightButtonPanel.textContent = null; 3324 object._console.log(blockPanel); 3325 if (blockPanel != null) { 3326 3327 object._contentPanel.removeChild(blockPanel); 3328 3329 } 3330 3331 infoPanel.setAttribute("class", "return_panel"); 3332 if (document.getElementById("changePanel") != null) { 3333 3334 document.getElementById("changePanel").setAttribute("class", "return_panel"); 3335 3336 } 3337 object._buttonAction = "reservation_users"; 3338 object.createCalendar(response, response.date.month, response.date.day, response.date.year, accountKey); 3339 callback(response); 3340 3341 } else { 3342 3343 window.alert(response.message); 3344 3345 } 3346 object._loadingPanel.setAttribute("class", "hidden_panel"); 3347 3348 }, function(responseText){ 3349
3350 //object.setResponseText(responseText); 3351 3352 }); 3353 3354 } 3355 3356 }); 3357 3358 }); 3359 3360 }); 3361 3362 } 3363 3364 var confirm = new Confirm(object._debug); 3365 3366 bookingTimeChange.onclick = function(){ 3367 3368 options = reservationData.options; 3369 object.setVisitorServices(options); 3370 object._console.log(options); 3371 //if(typeof ExtensionsFunction != "function"){ 3372 if (object._isExtensionsValid == 0) { 3373 3374 confirm.alertPanelShow(object._i18n.get("Warning"), object._i18n.get("Paid plan subscription required."), false, null); 3375 return null; 3376 3377 } 3378 3379 var data_status = parseInt(bookingTimeChange.getAttribute("data-status")); 3380 if(data_status == 1){ 3381 3382 data_status = 0; 3383 bookingTimeChange.textContent = object._i18n.get("Change"); 3384 bookingTimeChange.classList.add('hidden_panel'); 3385 courseChange.classList.add("hidden_panel"); 3386 object.createToChangePanelForTimeOrCourse(month, day, year, reservationData, calendarData, "date", options, accountKey, function(response){ 3387 3388 object._console.log("bookingTimeChange.onclick"); 3389 object._console.log(response); 3390 if(response.status == "statusButton"){ 3391 3392 calendarData = response.calendarData; 3393 bookingTimeChange.setAttribute("data-status", response.value); 3394 bookingTimeChange.textContent = object._i18n.get("Change"); 3395 courseChange.classList.remove("hidden_panel"); 3396 document.getElementById("beforChangeButton").classList.add("hidden_panel"); 3397 document.getElementById("nextChangeButton").classList.add("hidden_panel"); 3398 3399 }else if(response.status == "statusButton"){ 3400 3401 3402 3403 }else{ 3404 3405 if(response.month != null && response.day != null && response.year != null){ 3406 3407 month = response.month; 3408 day = response.day; 3409 year = response.year; 3410 3411 } 3412 3413 calendarData = response.calendarData; 3414 callback(response); 3415 3416 } 3417 3418 3419 }); 3420 3421 }else{ 3422 3423 data_status = 1; 3424 bookingTimeChange.textContent = object._i18n.get("Change"); 3425 courseChange.classList.remove("hidden_panel"); 3426 document.getElementById("beforButton").classList.add("hidden_panel"); 3427 document.getElementById("nextButton").classList.add("hidden_panel"); 3428 document.getElementById('downloadCsvForDay').classList.add('hidden_panel'); 3429 document.getElementById("beforChangeButton").classList.remove("hidden_panel"); 3430 document.getElementById("nextChangeButton").classList.remove("hidden_panel"); 3431 document.getElementById("changePanel").setAttribute("class", "return_change_panel"); 3432 3433 } 3434 bookingTimeChange.setAttribute("data-status", data_status); 3435 3436 3437 } 3438 3439 3440 courseChange.onclick = function(){ 3441 3442 options = reservationData.options; 3443 object.setVisitorServices(options); 3444 object._console.log(options); 3445 object._console.log(object.getVisitorServices()); 3446 //if(typeof ExtensionsFunction != "function"){ 3447 if (object._isExtensionsValid == 0) { 3448 3449 confirm.alertPanelShow(object._i18n.get("Warning"), object._i18n.get("Paid plan subscription required."), false, null); 3450 return null; 3451 3452 } 3453 3454 var data_status = parseInt(courseChange.getAttribute("data-status")); 3455 if(data_status == 1){ 3456 3457 data_status = 0; 3458 courseChange.textContent = object._i18n.get("Change"); 3459 bookingTimeChange.classList.add("hidden_panel"); 3460 courseChange.classList.add("hidden_panel"); 3461 object.createToChangePanelForTimeOrCourse(month, day, year, reservationData, calendarData, "course", options, accountKey, function(response){ 3462 3463 object._console.log(response); 3464 if(response.status == "statusButton"){ 3465 3466 object._console.log(options); 3467 options = response.options; 3468 object._console.log(options); 3469 calendarData = response.calendarData; 3470 courseChange.setAttribute("data-status", response.value); 3471 courseChange.textContent = object._i18n.get("Change"); 3472 bookingTimeChange.classList.remove("hidden_panel"); 3473 3474 }else if(response.status == "statusButton"){ 3475 3476 3477 3478 }else{ 3479 3480 if(response.month != null && response.day != null && response.
3480year != null){ 3481 3482 month = response.month; 3483 day = response.day; 3484 year = response.year; 3485 3486 } 3487 3488 calendarData = response.calendarData; 3489 callback(response); 3490 3491 } 3492 3493 3494 }); 3495 3496 }else{ 3497 3498 data_status = 1; 3499 courseChange.textContent = object._i18n.get("Change"); 3500 bookingTimeChange.classList.remove("hidden_panel"); 3501 document.getElementById("beforButton").classList.add("hidden_panel"); 3502 document.getElementById("nextButton").classList.add("hidden_panel"); 3503 document.getElementById('downloadCsvForDay').classList.add('hidden_panel'); 3504 document.getElementById("changePanel").setAttribute("class", "return_change_panel"); 3505 3506 } 3507 courseChange.setAttribute("data-status", data_status); 3508 3509 } 3510 3511 } 3512 3513 this.showUserDetails = function(key, calendarData, reservationData, accountKey, showStatusForHotel, infoPanel, bookingTimeChange, courseChange, callback){ 3514 3515 var object = this; 3516 var options = "[]"; 3517 object._courseName = calendarData.account.courseTitle; 3518 object._console.log("showStatusForHotel = " + showStatusForHotel); 3519 object._console.log(object._calendarAccount); 3520 var weekName = [object._i18n.get('Sun'), object._i18n.get('Mon'), object._i18n.get('Tue'), object._i18n.get('Wed'), object._i18n.get('Thu'), object._i18n.get('Fri'), object._i18n.get('Sat')]; 3521 object._calendar = new Booking_App_Calendar(weekName, object._dateFormat, object._positionOfWeek, object._positionTimeDate, object._startOfWeek, object._i18n, object._debug); 3522 object._calendar.setClock(object._clock); 3523 infoPanel.textContent = null; 3524 3525 var reservationDate = reservationData.date; 3526 var date = object._calendar.formatBookingDate(reservationDate.month, reservationDate.day, reservationDate.year, reservationDate.hour, reservationDate.min, reservationData.scheduleTitle, reservationDate.week, 'text'); 3527 3528 var timestampDate = reservationData.timestamp; 3529 var timestamp = object._calendar.formatBookingDate(timestampDate.month, timestampDate.day, timestampDate.year, timestampDate.hour, timestampDate.min, '', timestampDate.week, 'text'); 3530 3531 var month = reservationData.date.month; 3532 var day = reservationData.date.day; 3533 var year = reservationData.date.year; 3534 var expirationDate = parseInt(reservationData.date.key); 3535 var coupon = reservationData.coupon; 3536 object._console.log(reservationData); 3537 object._console.log(date); 3538 object._console.log(timestamp); 3539 object._console.log(coupon); 3540 3541 var formPanel = document.createElement("div"); 3542 formPanel.id = "inputFormPanel"; 3543 infoPanel.appendChild(formPanel); 3544 3545 var totalNumberOfGuestsPanel = null; 3546 3547 var rowPanel = object.createRowPanel("ID", reservationData.key, null, null, null); 3548 formPanel.appendChild(rowPanel); 3549 3550 if (showStatusForHotel === true) { 3551 3552 var statusPanel = object.createRowPanel(object._i18n.get("Status"), "", "status", "false", null); 3553 formPanel.appendChild(statusPanel); 3554 var statusLabel = document.getElementById("status"); 3555 var className = "visitorApprovedPanel"; 3556 var status = "approved"; 3557 if (reservationData.status.toLowerCase() == "pending") { 3558 3559 className = "visitorPendingPanel"; 3560 status = "pending"; 3561 3562 } else if (reservationData.status.toLowerCase() == "canceled") { 3563 3564 className = "visitorCanceledPanel"; 3565 status = "canceled"; 3566 3567 } 3568 statusLabel.classList.add("visitorStatus"); 3569 statusLabel.classList.add(className); 3570 statusLabel.textContent = object._i18n.get(status); 3571 if (status.toUpperCase() != 'CANCELED') { 3572 3573 statusLabel.onclick = function(){ 3574 3575 object._console.log(this); 3576 if (reservationData.status != 'canceled') { 3577 3578 object.changeStatus(accountKey, reservationData, null, true, function(response){ 3579 3580 object._console.log(response); 3581 if (response.bookingStatus == null) { 3582 3583 return null; 3584 3585 } 3586 var className = "visitorApprovedPanel"; 3587 var status = object._i18n.get("approved"); 3588 reservationData.status = "approved"; 3589 if (response.bookingStatus.toLowerCase() == "pen
3589ding") { 3590 3591 className = "visitorPendingPanel"; 3592 status = object._i18n.get("pending"); 3593 reservationData.status = "pending"; 3594 3595 } else if (response.bookingStatus.toLowerCase() == "canceled") { 3596 3597 className = "visitorCanceledPanel"; 3598 status = object._i18n.get("canceled"); 3599 reservationData.status = "canceled"; 3600 3601 } 3602 statusLabel.setAttribute("class", "value visitorStatus " + className); 3603 statusLabel.textContent = status; 3604 3605 callback(response); 3606 3607 }); 3608 3609 } 3610 3611 }; 3612 3613 } 3614 3615 } 3616 3617 if (calendarData.account.type == "hotel") { 3618 3619 object._console.log(object._hotel); 3620 object._hotel.reset(); 3621 object._hotel.setCallback(null); 3622 object._hotel.setCalendarAccount(calendarData.account); 3623 object._hotel.setNights(parseInt(reservationData.accommodationDetails.nights)); 3624 3625 var checkInDate = parseInt(reservationData.date.checkIn); 3626 var checkOutDate = parseInt(reservationData.date.checkOut); 3627 object._console.log("checkInDate = " + checkInDate + " checkOutDate = " + checkOutDate); 3628 3629 var visitorsScheduleList = reservationData.accommodationDetails.scheduleDetails; 3630 var scheduleList = calendarData.schedule; 3631 for (var key in visitorsScheduleList) { 3632 3633 object._hotel.addSchedule(visitorsScheduleList[key]); 3634 3635 } 3636 3637 if (scheduleList[checkInDate] != null) { 3638 3639 object._hotel.setCheckIn(scheduleList[checkInDate][0]); 3640 3641 } 3642 3643 if (scheduleList[checkOutDate] != null) { 3644 3645 object._hotel.setCheckOut(scheduleList[checkOutDate][0]); 3646 3647 } 3648 3649 object._hotel.setCheckIn(reservationData.accommodationDetails.checkInSchedule); 3650 object._hotel.setCheckInKey(reservationData.accommodationDetails.checkInSchedule.key); 3651 object._hotel.setCheckOut(reservationData.accommodationDetails.checkOutSchedule); 3652 object._hotel.setCheckOutKey(reservationData.accommodationDetails.checkOutSchedule.key); 3653 3654 object._console.log(object._hotel.getCheckDate()); 3655 3656 3657 3658 var visitorsDetails = object._hotel.verifySchedule(false); 3659 object._console.log(visitorsDetails); 3660 3661 var expressionsCheck = object._calendar.getExpressionsCheck(calendarData.account, false); 3662 3663 var date = object._calendar.formatBookingDate(reservationData.date.checkIn_month, reservationData.date.checkIn_day, reservationData.date.checkIn_year, null, null, null, reservationData.date.checkIn_week, 'text'); 3664 var checkIn = object.createRowPanel(object._i18n.get('Check-in'), date, "checkIn", "false", null); 3665 formPanel.appendChild(checkIn); 3666 document.getElementById("checkIn").setAttribute("data-id", reservationData.scheduleKey); 3667 3668 date = object._calendar.formatBookingDate(reservationData.date.checkOut_month, reservationData.date.checkOut_day, reservationData.date.checkOut_year, null, null, null, reservationData.date.checkOut_week, 'text'); 3669 var checkOut = object.createRowPanel(object._i18n.get('Check-out'), date, "checkOut", "false", null); 3670 formPanel.appendChild(checkOut); 3671 3672 var nightsValue = reservationData.accommodationDetail
3672s.nights + ' ' + object._i18n.get("nights"); 3673 if (parseInt(object._calendarAccount.formatNightDay) == 1) { 3674 3675 nightsValue = object._i18n.get("%s nights %s days", [reservationData.accommodationDetails.nights, reservationData.accommodationDetails.nights + 1]); 3676 3677 } 3678 3679 if (reservationData.accommodationDetails.nights == 1) { 3680 3681 nightsValue = reservationData.accommodationDetails.nights + ' ' + object._i18n.get("night"); 3682 if (parseInt(object._calendarAccount.formatNightDay) == 1) { 3683 3684 nightsValue = object._i18n.get("%s night %s days", [reservationData.accommodationDetails.nights, reservationData.accommodationDetails.nights + 1]); 3685 3686 } 3687 3688 } 3689 var totalLengthOfStay = object.createRowPanel(object._i18n.get("Total Length of Stay"), nightsValue, null, null, null); 3690 formPanel.appendChild(totalLengthOfStay); 3691 3692 /** Rooms **/ 3693 3694 var roomListPanel = document.createElement('div'); 3695 roomListPanel.classList.add('row'); 3696 roomListPanel.classList.add('roomListPanel'); 3697 roomListPanel.id = 'roomListPanel'; 3698 formPanel.appendChild(roomListPanel); 3699 var hasOptionsAndGuestsInRoom = {options: false, guests: false}; 3700 object._console.log(reservationData.accommodationDetails); 3701 object._console.log(reservationData.accommodationDetails.rooms); 3702 for (var roomKey in reservationData.accommodationDetails.rooms) { 3703 3704 var roomNumber = parseInt(roomKey); 3705 var roomPanel = document.createElement('div'); 3706 roomPanel.id = 'roomNo_' + roomNumber; 3707 roomListPanel.appendChild(roomPanel); 3708 3709 var roomNoLabel = document.createElement('label'); 3710 roomNoLabel.classList.add('roomNoLabel'); 3711 roomNoLabel.textContent = object._i18n.get('Room') + ': ' + (roomNumber + 1); 3712 roomPanel.appendChild(roomNoLabel); 3713 3714 var room = reservationData.accommodationDetails.rooms[roomKey]; 3715 object._console.log(room); 3716 3717 var hotelOptions = room.optionsList; 3718 if (hotelOptions != null && Object.keys(hotelOptions).length > 0) { 3719 3720 hasOptionsAndGuestsInRoom.options = true; 3721 var optionsLabel = document.createElement('label'); 3722 optionsLabel.classList.add('optionsTitle'); 3723 optionsLabel.textContent = object._i18n.get('Options') + ':'; 3724 roomPanel.appendChild(optionsLabel); 3725 3726 for (var key in hotelOptions) { 3727 3728 var value = object._i18n.get('Unselected'); 3729 var list = hotelOptions[key].json; 3730 object._console.log(typeof list); 3731 if (typeof list == "string") { 3732 3733 list = JSON.parse(list); 3734 3735 } else { 3736 3737 hotelOptions[key].json = JSON.stringify(list); 3738 3739 } 3740 3741 var values = []; 3742 hotelOptions[key].type = "SELECT"; 3743 hotelOptions[key].value = 0; 3744 hotelOptions[key].index = 0; 3745 hotelOptions[key].charge = 0; 3746 hotelOptions[key].values = values; 3747 object._hotel.addOptions(key, hotelOptions[key], parseInt(roomKey)); 3748 3749 for (var i = 0; i < list.length; i++) { 3750 3751 object._console.log(list[i]); 3752 if (parseInt(list[i].selected) == 1) { 3753 3754 object._console.log(list[i]); 3755 value = list[i].name; 3756 //hotelOptions[key].value = i; 3757 var response = object._hotel.addSelectedOptions(key, list[i].index, parseInt(roomKey)); 3758 3759 } 3760 3761 values.push(list[i].name); 3762 3763 } 3764 object._console.log(hotelOptions[key]); 3765 3766 var optionsPanel = object.createRowPanel(hotelOptions[key].name, value, "options_" + roomKey + '_' + hotelOptions[key].key, "false", null); 3767 optionsPanel.setAttribute('class', 'rowRoom'); 3768 roomPanel.appendChild(optionsPanel); 3769 3770 } 3771 3772 } 3773 3774 var guestsList = room.guestsList; 3775 if (guestsList != null && Object.keys(guestsList).length > 0) { 3776 3777 hasOptionsAndGuestsInRoom.guests = true; 3778 var guestsLabel = document.createElement('label'); 3779 guestsLabel.classList.add('optionsTitle'); 3780 guestsLabel.textContent = object._i18n.get('Guests') + ':'; 3781 roomPanel.appendChild(guestsLabel); 3782 3783 for (var key in guestsList) { 3784 3785 var value = object._i18n.get('Unselected'); 3786 var list = guestsList[key].json; 3787 object._console.log(typeof list); 3788 if (typeof list == "string") { 3789 3790 list = JSON.parse(list); 3791 3792 } else { 3793 3794 guestsList[key].json = JSON.stringify(list); 3795 3796 } 3797 3798 guestsList[key].type = "SELECT"; 3799 guestsList[key].value = 0; 3800 guestsList[key].index = 0; 3801 guestsList[key].person = 0; 3802 object._hotel.addGuests(key, guestsList[key], parseInt(roomKey)); 3803 var values = []; 3804 for (var i = 0; i < list.length; i++) { 3805 3806 if (parseInt(list[i].selected) == 1) { 3807 3808 object._console.log(list[i].name) 3809 value = list[i].name; 3810 guestsList[key].value = i; 3811 guestsList[key].person = parseInt(list[i].number); 3812 var response = object._hotel.setGuests(key, i, list[i].number, parseInt(roomKey)); 3813 3814 } 3815 3816 values.push(list[i].name); 3817 3818 } 3819 3820 guestsList[key].values = values; 3821 //object._hotel.addGuests(key, guestsList[key], 1); 3822 var guestsPanel = object.createRowPanel(guestsList[key].name, value, "guests_" + roomKey + '_' + guestsList[key].key, "false", null); 3823 guestsPanel.setAttribute('class', 'rowRoom'); 3824 roomPanel.appendChild(guestsPanel); 3825 3826 } 3827 3828 } 3829 3830 } 3831 3832 if (hasOptionsAndGuestsInRoom.options === false && hasOptionsAndGuestsInRoom.guests === false) { 3833 3834 roomListPanel.classList.add('hidden_panel'); 3835 3836 } 3837 3838 /** Rooms **/ 3839 3840 object._console.log(object._hotel.getGuestsList()); 3841
3842 if(reservationData.accommodationDetails.adult != null && reservationData.accommodationDetails.children != null){ 3843 3844 var totalNumberOfGuests = parseInt(reservationData.accommodationDetails.adult) + parseInt(reservationData.accommodationDetails.children); 3845 var totalNumberOfGuestsValue = 0; 3846 if(totalNumberOfGuests > 1){ 3847 3848 //totalNumberOfGuestsValue = totalNumberOfGuests + " " + object._i18n.get("people"); 3849 totalNumberOfGuestsValue = object._i18n.get("%s guests", [totalNumberOfGuests]); 3850 3851 }else if(totalNumberOfGuests == 1){ 3852 3853 //totalNumberOfGuestsValue = totalNumberOfGuests + " " + object._i18n.get("person"); 3854 totalNumberOfGuestsValue = object._i18n.get("%s guest", [totalNumberOfGuests]); 3855 3856 } 3857 3858 totalNumberOfGuestsPanel = object.createRowPanel(object._i18n.get("Total Number of Guests"), String(totalNumberOfGuestsValue), "totalGuests", null, null); 3859 formPanel.appendChild(totalNumberOfGuestsPanel); 3860 3861 } 3862 3863 object._hotel.setTaxes(reservationData.accommodationDetails.taxes); 3864 3865 var summaryListPanel = document.createElement("div"); 3866 summaryListPanel.id = "summaryListPanel"; 3867 var summaryPanel = object.createRowPanel(object._i18n.get("Summary"), summaryListPanel, "summaryPanel", null, null); 3868 formPanel.appendChild(summaryPanel); 3869 object._hotel.showSummary(summaryListPanel, expressionsCheck); 3870 3871 var taxValue = 0; 3872 for (var i = 0; i < reservationData.taxes.length; i++) { 3873 3874 var tax = reservationData.taxes[i]; 3875 if (tax.active != 'true') { 3876 3877 continue; 3878 3879 } 3880 3881 if ((tax.type == 'tax' && tax.tax == 'tax_exclusive') || tax.type == 'surcharge') { 3882 3883 taxValue += parseInt(tax.taxValue); 3884 3885 } 3886 3887 } 3888 3889 object._console.log("taxValue = " + taxValue); 3890 3891 //var totalPrice = object._format.formatCost(reservationData.accommodationDetails.additionalFee + reservationData.accommodationDetails.accommodationFee + reservationData.accommodationDetails.taxesFee, object._currency); 3892 var totalPrice = object._format.formatCost(reservationData.accommodationDetails.totalCost, object._currency); 3893 object._console.log("totalPrice = " + totalPrice); 3894 3895 var rowPanel = object.createRowPanel(object._i18n.get("Total Amount"), totalPrice, "totalPrice", null, null); 3896 formPanel.appendChild(rowPanel); 3897 3898 /** 3899 var timestampPanel = object.createRowPanel(object._i18n.get("Submission date"), timestamp, "timestamp", null, null); 3900 formPanel.appendChild(timestampPanel); 3901 **/ 3902 3903 } else { 3904 3905 var date = object._calendar.formatBookingDate(reservationDate.month, reservationDate.day, reservationDate.year, reservationDate.hour, reservationDate.min, reservationData.scheduleTitle, reservationData.date.week, 'elements'); 3906 var rowPanel = object.createRowPanel(object._i18n.get("Booking Date"), date.dateAndTime, "booking_date", null, bookingTimeChange); 3907 formPanel.appendChild(rowPanel); 3908 document.getElementById("booking_date").setAttribute("data-key", reservationData.scheduleKey); 3909 document.getElementById("booking_date").setAttribute("data-unixTime", reservationData.scheduleUnixTime); 3910 var guests = []; 3911 if (typeof reservationData.guests.guests == 'object') { 3912 3913 guests = reservationData.guests.guests; 3914 3915 } 3916 object._console.log(guests); 3917 if (guests.length > 0) { 3918 3919 object.showGuestsPanelForDays(formPanel, guests); 3920 3921 } 3922 3923 var goodsList = []; 3924 //var responseGuests = []; 3925 var responseGuests = object._servicesControl.getValueReflectGuests(guests); 3926 object._console.log(responseGuests); 3927 var cost = 0; 3928 if(reservationData.options.length > 0){ 3929 3930 var serviceCost = 0; 3931 var hasMultipleServices = false;
3932 for (var key in reservationData.options) { 3933 3934 var service = reservationData.options[key]; 3935 if (parseInt(service.service) == 1) { 3936 3937 hasMultipleServices = true; 3938 cost += parseInt(service.cost); 3939 for (var optionKey in service.options) { 3940 3941 var option = service.options[optionKey]; 3942 if (parseInt(option.selected) == 1) { 3943 3944 cost += parseInt(option.cost); 3945 3946 } 3947 3948 } 3949 3950 } 3951 3952 } 3953 3954 if (serviceCost > 0) { 3955 3956 //reservationData.courseCost = serviceCost; 3957 3958 } 3959 3960 object._console.log("serviceCost = " + serviceCost); 3961 object._console.log("cost = " + cost); 3962 object._console.log("hasMultipleServices = " + hasMultipleServices); 3963 var courseCostPanel = null; 3964 object._console.log(parseInt(reservationData.courseCost)); 3965 if (parseInt(reservationData.courseCost) > 0) { 3966 3967 courseCostPanel = document.createElement("span"); 3968 courseCostPanel.classList.add("planPrice"); 3969 courseCostPanel.textContent = object._format.formatCost(reservationData.courseCost, reservationData.currency); 3970 3971 } 3972 3973 //var rowPanel = object.createRowPanel(object._courseName, "", "booking_course", null, courseChange); 3974 var rowPanel = object.createRowPanel(object._i18n.get('Service'), "", "booking_course", null, courseChange); 3975 var valuePanel = rowPanel.getElementsByClassName("value")[0]; 3976 valuePanel.textContent = null; 3977 3978 var coursePanel = document.createElement("div"); 3979 coursePanel.classList.add("mainPlan"); 3980 valuePanel.appendChild(coursePanel); 3981 3982 var courseNamePanel = document.createElement("span"); 3983 courseNamePanel.classList.add("planName"); 3984 courseNamePanel.textContent = reservationData.courseName; 3985 coursePanel.appendChild(courseNamePanel); 3986 if (courseCostPanel != null && hasMultipleServices === false) { 3987 3988 coursePanel.appendChild(courseCostPanel); 3989 3990 } 3991 3992 if (reservationData.options != "") { 3993 3994 if (hasMultipleServices == true) { 3995 3996 cost = 0; 3997 var services = reservationData.options; 3998 for (var key in services) { 3999 4000 services[key].selected = 1; 4001 4002 } 4003 object._console.log(services); 4004 var guestsBool = 0; 4005 if (guests.length > 0) { 4006 4007 guestsBool = 1; 4008 4009 } 4010 var response = object.createServicesPanel(coursePanel, services, "options", guests, guestsBool, goodsList, reservationData.currency, true); 4011 object._console.log(response); 4012 goodsList = response.goodsList; 4013 cost += response.totalCost; 4014 responseGuests = object._servicesControl.getValueReflectGuests(guests); 4015 object._console.log(responseGuests); 4016 4017 } else { 4018 4019 var options = reservationData.options; 4020 if (options.length > 0) { 4021 4022 var ul = document.createElement("ul"); 4023 valuePanel.appendChild(ul); 4024 for(var i = 0; i < options.length; i++){ 4025 4026 var option = options[i]; 4027 if (parseInt(option.selected) == 1) { 4028 4029 cost += parseInt(option.cost); 4030 4031 var optionNamePanel = document.createElement("span"); 4032 optionNamePanel.classList.add("planName"); 4033 optionNamePanel.textContent = option.name; 4034 4035 var optionPricePanel = document.createElement("span"); 4036 optionPricePanel.classList.add("planPrice"); 4037 if (parseInt(option.cost) > 0) { 4038 4039 optionPricePanel.textContent = object._format.formatCost(option.cost, reservationData.currency); 4040 4041 } 4042 4043 var li = document.createElement("li"); 4044 li.appendChild(optionNamePanel); 4045 li.appendChild(optionPricePanel); 4046 ul.appendChild(li); 4047 4048 } 4049 4050 } 4051 4052 } else { 4053 4054 console.error("option = " + option); 4055 4056 } 4057 4058 } 4059 4060 } 4061 4062 object._console.log(reservationData.options); 4063 formPanel.appendChild(rowPanel); 4064 document.getElementById("booking_course").setAttribute("data-key", reservationData.courseKey); 4065 document.getElementById("booking_course").setAttribute("data-time", reservationData.courseTime); 4066 if (object.getServiceOrOption(reservationData.options) == 'service') { 4067 4068 document.getElementById("booking_course").setAttribute("data-key", "multipleServices"); 4069 4070 } 4071 4072 4073 4074 } 4075 4076 4077 if(reservationData.scheduleCost != null){ 4078 4079 cost += parseInt(reservationData.scheduleCost); 4080 4081 } 4082 4083 if(reservationData.courseCost != null){ 4084 4085 cost += parseInt(reservationData.courseCost); 4086 4087 } 4088 4089 object._console.log('cost = ' + cost); 4090 if (coupon.key != null) { 4091 4092 var couponPanel = object.createRowPanel(object._i18n.get('Coupon'), "", null, null, null); 4093 formPanel.appendChild(couponPanel); 4094 4095 /** Coupon code **/ 4096 var namePanel = document.createElement('span'); 4097 namePanel.classList.add('planName'); 4098 namePanel.textContent = object._i18n.get('Coupon code'); 4099 var valuePanel = document.createElement('span'); 4100 valuePanel.classList.add('planPrice'); 4101 valuePanel.textContent = coupon.id; 4102 var couponCodePanel = document.createElement('div'); 4103 couponCodePanel.id = 'added_coupon_code'; 4104 couponCodePanel.classList.add('mainPlan'); 4105 couponCodePanel.appendChild(namePanel); 4106 couponCodePanel.appendChild(valuePanel); 4107 4108 /** Coupon name **/ 4109 var namePanel = document.createElement('span'); 4110 namePanel.classList.add('planName'); 4111 namePanel.textContent = object._i18n.get('Coupon'); 4112 var valuePanel = document.createElement('span'); 4113 valuePanel.classList.add('planPrice'); 4114 valuePanel.textContent = coupon.name; 4115 var couponNamePanel = document.createElement('div'); 4116 couponNamePanel.id = 'added_coupon_name'; 4117 couponNamePanel.classList.add('mainPlan'); 4118 couponNamePanel.appendChild(namePanel); 4119 couponNamePanel.appendChild(valuePanel); 4120 4121 /** Coupon name **/ 4122 var namePanel = document.createElement('span'); 4123 namePanel.classList.add('planName'); 4124 namePanel.textContent = object._i18n.get('Discount'); 4125 var valuePanel = document.createElement('span'); 4126 valuePanel.classList.add('planPrice'); 4127 if (coupon.method == 'subtraction') { 4128 4129 valuePanel.textContent = object._format.formatCost(coupon.value, object._currency); 4130 cost = object.getDiscountCostByCoupon(coupon, cost); 4131 4132 } else { 4133 4134 valuePanel.textContent = coupon.value + '%'; 4135 cost = object.getDiscountCostByCoupon(coupon, cost); 4136 4137 } 4138 var couponDiscountPanel = document.createElement('div'); 4139 couponDiscountPanel.id = 'added_coupon_discount'; 4140 couponDiscountPanel.classList.add('mainPlan'); 4141 couponDiscountPanel.appendChild(namePanel); 4142 couponDiscountPanel.appendChild(valuePanel); 4143 4144 couponPanel.appendChild(couponCodePanel); 4145 couponPanel.appendChild(couponNamePanel); 4146 couponPanel.appendChild(couponDiscountPanel); 4147 object._console.log('cost = ' + cost); 4148 4149 } 4150 4151 const totalAmountForGuests = object._servicesControl.getSelectedGuestTotalAmount(guests); 4152 cost += totalAmountForGuests.totalAmount; 4153 4154 var taxes = new TAXES(object._i18n, reservationData.currency, object._debug, object._numberFormatter, object._currency_info); 4155 var surchargePanel = taxes.createExtraChargesAndTaxesElement("surchargeTaxTitle"); 4156 var taxePanel = object.createRowPanel("Tax", "", null, null, null); 4157 object._servicesControl.setExpirationDate(expirationDate); 4158 4159 taxes.setBooking_App_ObjectsControl(object._servicesControl); 4160 taxes.setTaxes(reservationData.taxes); 4161 var isTaxes = taxes.taxesDetails(cost, formPanel, surchargePanel, taxePanel, responseGuests); 4162 object._console.log(isTaxes); 4163 if (isTaxes.isTaxes === true) { 4164 4165 formPanel.appendChild(isTaxes.surchargePanel); 4166 var responseTaxes = taxes.getTaxes(); 4167 var reflectAdditional = 1; 4168 if (responseGuests.reflectAdditional > 0) { 4169 4170 reflectAdditional = responseGuests.reflectAdditional; 4171 4172 } 4173 object._console.log('reflectAdditional = ' + reflectAdditional); 4174 cost += taxes.reflectTaxesInTotalCost(responseTaxes, goodsList, reflectAdditional); 4175 4176 } 4177 4178 if (cost != 0) { 4179 4180 cost = object._format.formatCost(cost, reservationData.currency); 4181 object._console.log('Total Amount = ' + cost); 4182 var rowPanel = object.createRowPanel(object._i18n.get("Total Amount"), cost, "booking_cost", null, null); 4183 formPanel.appendChild(rowPanel); 4184 4185 } 4186 4187 } 4188 4189 var paymentMethodValue = object._i18n.get('Local Payment'); 4190 if (reservationData.payId == 'stripe') { 4191 4192 paymentMethodValue = object._i18n.get('Pay with Stripe'); 4193 4194 } else if (reservationData.payId == 'stripe_konbini') { 4195 4196 paymentMethodValue = object._i18n.get('Pay at Convenience Store (via Stripe)'); 4197 4198 } else if (reservationData.payId == 'stripe_paypay') { 4199 4200 paymentMethodValue = object._i18n.get('Pay with %s', ['PayPay']); 4201 4202 } else if (reservationData.payId == 'paypal') { 4203 4204 paymentMethodValue = object._i18n.get('Pay with PayPal'); 4205 4206 } 4207 4208 var paymentMethodPanel = object.createRowPanel(object._i18n.get('Payment Method'), paymentMethodValue, "payment_method", null, null); 4209 paymentMethodPanel.classList.add('payment_method_row'); 4210 formPanel.appendChild(paymentMethodPanel); 4211 4212 if (reservationData.payId == "stripe" || reservationData.payId == "stripe_konbini" || reservationData.payId == "stripe_paypay" || reservationData.payId == "paypal") { 4213 4214 //var rowPanel = object.createRowPanel("Charge ID of " + reservationData.payName, reservationData.payToken, "booking_cost", null, null); 4215 var paymentIdPanel = object.createRowPanel(object._i18n.get('Payment ID'), reservationData.payToken, "booking_cost", null, null); 4216 formPanel.appendChild(paymentIdPanel); 4217 4218 } 4219 4220 var timestampPanel = object.createRowPanel(object._i18n.get("Submission date"), timestamp, "timestamp", null, null); 4221 formPanel.appendChild(timestampPanel); 4222 4223 var formPanelList = []; 4224 var formData = reservationData.praivateData; 4225 if (formData != null) { 4226 4227 for (var i = 0; i < formData.length; i++) { 4228 4229 var rowPanel = object.createRowPanel(formData[i]['name'], formData[i]['value'], null, null, null); 4230 rowPanel.setAttribute("data-key", i); 4231 if (formData[i].active != null && formData[i].active != 'true') { 4232 4233 //continue; 4234 rowPanel.classList.add("hidden_panel"); 4235 4236 } 4237 formPanel.appendChild(rowPanel); 4238 formPanelList.push(rowPanel); 4239 4240 } 4241 4242 } 4243 4244 return {formPanel: formPanel, formPanelList: formPanelList, totalNumberOfGuestsPanel: totalNumberOfGuestsPanel, formData: formData}; 4245 4246 } 4247 4248 this.getDiscountCostByCoupon = function(coupon, totalCost) { 4249 4250 var object = this; 4251 if (coupon.key == null) { 4252 4253 return totalCost; 4254 4255 } 4256 4257 if (coupon.method == 'subtraction') { 4258 4259 if (totalCost > parseInt(coupon.value)) { 4260 4261 totalCost -= parseInt(coupon.value); 4262 4263 } else { 4264 4265 totalCost = 0; 4266 4267 } 4268 4269 } else { 4270 4271 totalCost -= totalCost - (totalCost * (100 - parseInt(coupon.value)) / 100); 4272 4273 } 4274 4275 return parseInt(totalCost); 4276 4277 } 4278 4279 this.showGuestsPanelForDays = function(formPanel, guests) { 4280 4281 var object = this; 4282 for (var i = 0; i < guests.length; i++) { 4283 4284 var guest = guests[i]; 4285 object._console.log(guest); 4286 if (guest.index == null) { 4287 4288 continue; 4289 4290 } 4291 var value = guest.json[guest.index]; 4292 object._console.log(value); 4293 var rowPanel = object.createRowPanel(guest.name, value.name, object._prefix + guest.key, null, null); 4294 formPanel.app
4294endChild(rowPanel); 4295 4296 } 4297 //var rowPanel = object.createRowPanel(object._i18n.get("Booking Date"), date, "booking_date", null, bookingTimeChange); 4298 var responseGuests = object._servicesControl.getValueReflectGuests(guests); 4299 object._console.log(responseGuests); 4300 if (responseGuests.totalNumberOfGuests > 0) { 4301 4302 4303 4304 var totalNumberOfGuestsPanel = object.createRowPanel(object._i18n.get('Total Number of Guests'), responseGuests.totalNumberOfGuestsTitle, object._prefix + 'totalNumberOfGuests', null, null); 4305 formPanel.appendChild(totalNumberOfGuestsPanel); 4306 4307 const totalNumberOfGuestsValuePanel = document.getElementById(object._prefix + 'totalNumberOfGuests'); 4308 const totalAmountForGuests = object._servicesControl.getSelectedGuestTotalAmount(guests); 4309 const totalGuestsLabel = document.createElement('div'); 4310 totalGuestsLabel.textContent = responseGuests.totalNumberOfGuestsTitle; 4311 totalNumberOfGuestsValuePanel.textContent = null; 4312 totalNumberOfGuestsValuePanel.appendChild(totalGuestsLabel); 4313 if (totalAmountForGuests.labeles.length > 0) { 4314 4315 if (totalAmountForGuests.totalAmount > 0) { 4316 4317 const totalNumberOfGuestsLabel = document.createElement('span'); 4318 totalNumberOfGuestsLabel.classList.add('serviceName'); 4319 totalNumberOfGuestsLabel.textContent = responseGuests.totalNumberOfGuestsTitle; 4320 4321 const totalAmountGuestsLabel = document.createElement('span'); 4322 totalAmountGuestsLabel.classList.add('serviceCost'); 4323 totalAmountGuestsLabel.textContent = object._format.formatCost(totalAmountForGuests.totalAmount, object._currency); 4324 4325 totalGuestsLabel.textContent = null; 4326 totalGuestsLabel.appendChild(totalNumberOfGuestsLabel); 4327 totalGuestsLabel.appendChild(totalAmountGuestsLabel); 4328 4329 } 4330 4331 const guestsDetailsPanel = document.createElement('div'); 4332 guestsDetailsPanel.setAttribute('class', 'costPerGuests hidden_panel'); 4333 for (var i = 0; i < totalAmountForGuests.labeles.length; i++) { 4334 4335 const gusetDetailsLabel = document.createElement('div'); 4336 gusetDetailsLabel.textContent = totalAmountForGuests.labeles[i]; 4337 guestsDetailsPanel.appendChild(gusetDetailsLabel); 4338 4339 } 4340 4341 totalNumberOfGuestsValuePanel.appendChild(guestsDetailsPanel); 4342 totalGuestsLabel.classList.add('addedGuests_click'); 4343 totalGuestsLabel.onclick = function(event) { 4344 4345 if (guestsDetailsPanel.classList.contains('hidden_panel') === true) { 4346 4347 guestsDetailsPanel.classList.remove('hidden_panel'); 4348 4349 } else { 4350 4351 guestsDetailsPanel.classList.add('hidden_panel'); 4352 4353 } 4354 4355 }; 4356 4357 } 4358 4359 } 4360 4361 } 4362 4363 this.createToChangePanelForTimeOrCourse = function(month, day, year, reservationData, calendarData, changeAction, options, accountKey, callback){ 4364 4365 var object = this; 4366 var preparation = JSON.parse(reservationData.preparation); 4367 object._console.log("month = " + month + " day = " + day + " year = " + year); 4368 object._console.log(options); 4369 object._console.log(reservationData); 4370 object._console.log(reservationData.guests); 4371 object._console.log(preparation); 4372 4373 var isGuests = 0; 4374 var guests = []; 4375 if (reservationData.guests.guests != null) { 4376 4377 isGuests = 1; 4378 guests = reservationData.guests.guests; 4379 4380 } 4381 object._console.log(guests); 4382 4383 var weekName = [object._i18n.get('Sun'), object._i18n.get('Mon'), object._i18n.get('Tue'), object._i18n.get('Wed'), object._i18n.get('Thu'), object._i18n.get('Fri'), object._i18n.get('Sat')]; 4384 object._calendar = new Booking_App_Calendar(weekName, object._dateFormat, object._positionOfWeek, object._positionTimeDate, object._startOfWeek, object._i18n, object._debug); 4385 object._calendar.setClock(object._clock); 4386 let expirationDate = object._calendar.getDateKey(month, day, year); 4387 var calendarKey = object._calendar.getDateKey(month, day, year); 4388 object._nationalHoliday = calendarData.nationalHoliday.calendar; 4389 4390 var edit_title = document.getElementById("edit_title"); 4391 edit_title.textContent = object._calendar.formatBookingDate(month, day, year, null, null, null, calendarData.calendar[calendarKey].week, 'text'); 4392 4393 var changePanel = null; 4394 if (document.getElementById("changePanel") == null) { 4395 4396 changePanel = document.createElement("div"); 4397 changePanel.id = "changePanel"; 4398 object._contentPanel.appendChild(changePanel); 4399 4400 } else { 4401 4402 changePanel = document.getElementById("changePanel"); 4403 4404 } 4405 changePanel.classList.add("hidden_panel"); 4406 document.getElementById("beforButton").classList.add("hidden_panel"); 4407 document.getElementById("nextButton").classList.add("hidden_panel"); 4408 document.getElementById('downloadCsvForDay').classList.add('hidden_panel'); 4409 var beforChangeButton = document.getElementById("beforChangeButton"); 4410 var nextChangeButton = document.getElementById("nextChangeButton"); 4411 if (changeAction == "date") { 4412 4413 object._buttonAction = "updateSchedule"; 4414 beforChangeButton.classList.remove("hidden_panel"); 4415 nextChangeButton.classList.remove("hidden_panel"); 4416 4417 } else { 4418 4419 object._buttonAction = "showUserInfo"; 4420 4421 } 4422 4423 var changeButtonAction = function(mode, month, day, year, calendarData){ 4424 4425 object._console.log("mode = " + mode); 4426 object._console.log("buttonAction = " + object._buttonAction); 4427 object._console.log("changeAction = " + changeAction); 4428 object._console.log(options); 4429 if (object._buttonAction != 'updateSchedule') { 4430 4431 return null; 4432 4433 } 4434
4435 month = parseInt(month); 4436 day = parseInt(day); 4437 year = parseInt(year); 4438 var lastDay = parseInt(calendarData.date.lastDay); 4439 4440 object._console.log("month = " + month + " day = " + day + " year = " + year + " lastDay = " + lastDay); 4441 var date = object.verifyCalendar(mode, month, day, year, lastDay); 4442 if(date.calendarChange === 0){ 4443 4444 object.createToChangePanelForTimeOrCourse(date.month, date.day, date.year, reservationData, calendarData, changeAction, JSON.stringify(options), accountKey, callback); 4445 callback({month: date.month, day: date.day, year: date.year, calendarData: calendarData}); 4446 4447 }else{ 4448 4449 object._loadingPanel.setAttribute("class", "loading_modal_backdrop"); 4450 var post = {nonce: object._nonce, action: object._action, mode: object._prefix + 'getReservationData', year: date.year, month: date.month, day: 1, accountKey: accountKey}; 4451 new Booking_App_XMLHttp(object._url, post, object._webApp, function(calendarData){ 4452 4453 object._loadingPanel.setAttribute("class", "hidden_panel"); 4454 object._console.log(calendarData); 4455 object._servicesControl.setNationalHoliday(calendarData.nationalHoliday.calendar); 4456 var day = 1; 4457 if(mode === 0){day = calendarData.date.lastDay;} 4458 object.createToChangePanelForTimeOrCourse(date.month, day, date.year, reservationData, calendarData, changeAction, JSON.stringify(options), accountKey, callback); 4459 callback({month: date.month, day: day, year: date.year, calendarData: calendarData}); 4460 object._loadingPanel.setAttribute("class", "hidden_panel"); 4461 4462 }, function(responseText){ 4463 4464 //object.setResponseText(responseText); 4465 4466 }); 4467 4468 } 4469 4470 } 4471 4472 changePanel.textContent = null; 4473 changePanel.setAttribute("class", "show_change_panel"); 4474 //var day = reservationData.date.day; 4475 var dateLabel = document.getElementById("booking_date"); 4476 var courseLabel = document.getElementById("booking_course"); 4477 var selectedService = []; 4478 var courseTime = 0; 4479 var courseKey = null; 4480 if (courseLabel != null) { 4481 4482 courseKey = parseInt(courseLabel.getAttribute("data-key")); 4483 4484 } 4485 4486 if (options != null) { 4487 4488 if (options.length == 0) { 4489 4490 courseTime = 0; 4491 4492 } 4493 4494 if (object.getServiceOrOption(options) == 'service') { 4495 4496 courseTime = 0; 4497 //options = object.getVisitorServices(); 4498 4499 } 4500 4501 //var options = JSON.parse(options); 4502 object._console.log(options); 4503 object._console.log(typeof options); 4504 if (typeof options == 'string') { 4505 4506 options = JSON.parse(options); 4507 4508 } 4509 object._console.log("courseTime = " + courseTime); 4510 for (var key in options) { 4511 4512 var service = options[key]; 4513 object._console.log(service); 4514 object._console.log("courseTime = " + courseTime); 4515 if (service.service != null && parseInt(service.service) == 1) { 4516 4517 if (parseInt(service.selected) == 1) { 4518 4519 selectedService = service; 4520 /** 4521 if (courseTime == null) { 4522 4523 courseTime = parseInt(service.time); 4524 4525 } else { 4526 4527 courseTime += parseInt(service.time); 4528 4529 } 4530 **/ 4531 courseTime += parseInt(service.time); 4532 4533 if(typeof service.options == 'string') { 4534 4535 service.options = JSON.parse(service.options); 4536 4537 } 4538 4539 for (var optionKey in service.options) { 4540 4541 var option = service.options[optionKey]; 4542 object._console.log(option); 4543 if (parseInt(option.selected) == 1) { 4544 /** 4545 if (courseTime == null) { 4546 4547 courseTime = parseInt(option.time); 4548 4549 } else { 4550 4551 courseTime += parseInt(option.time); 4552 4553 } 4554 **/ 4555 courseTime += parseInt(option.time); 4556 4557 } 4558 4559 } 4560 4561 } 4562 4563 } else { 4564 4565 var option = options[key]; 4566 if (parseInt(option.selected) == 1) { 4567 /** 4568 if (courseTime == null) { 4569 4570 courseTime = parseInt(option.time); 4571 4572 } else { 4573 4574 courseTime += parseInt(option.time); 4575 4576 } 4577 **/ 4578 courseTime += parseInt(option.time); 4579 4580 } 4581 4582 } 4583 4584 } 4585 4586 4587 4588 } 4589 4590 object._console.log("courseTime = " + courseTime); 4591 4592 4593 //var extensionsFunction = new ExtensionsFunction(); 4594 //var response = extensionsFunction.preparToUpdateSchedule(reservationData, calendarData, parseInt(courseTime), changeAction); 4595 var response = object.preparToUpdateSchedule(reservationData, calendarData, parseInt(courseTime), changeAction, preparation); 4596 var updateSchedule = response.schedule; 4597 var scheduleAll = response.scheduleAll; 4598 day = parseInt(day); 4599 object._console.log(calendarData); 4600 object._console.log("day = " + parseInt(day)); 4601 object._console.log(updateSchedule); 4602 object._console.log(updateSchedule[calendarKey]); 4603 object._console.log(reservationData); 4604 var timeToProvide = []; 4605 for(var i = 0; i < object._courseList.length; i++){ 4606 4607 if(parseInt(object._courseList[i].key) == courseKey) { 4608 4609 timeToProvide = object._courseList[i].timeToProvide; 4610 break; 4611 4612 } 4613 4614 } 4615 object._console.log(timeToProvide); 4616 4617 var dateLabel = document.getElementById("booking_date"); 4618 4619 if (changeAction == "date") { 4620 4621 if (options != null) { 4622 4623 updateSchedule[calendarKey] = object._servicesControl.invalidService(updateSchedule[calendarKey], calendarData['bookedServices'], selectedService, courseTime, day, month, year); 4624 4625 } 4626 4627 if (updateSchedule[calendarKey].length == 0) { 4628 4629 var errorPanel = document.createElement("div"); 4630 errorPanel.setAttribute("class", "noSchedule"); 4631 errorPanel.textContent = object._i18n.get("There are no time slots."); 4632 changePanel.appendChild(errorPanel); 4633 4634 } 4635 4636 var calendarKey = object._calendar.getDateKey(month, day, year); 4637 object._console.log(object._nationalHoliday[calendarKey]); 4638 var nationalHoliday = false;
4639 if (object._nationalHoliday[calendarKey] != null && parseInt(object._nationalHoliday[calendarKey].status) == 1) { 4640 4641 nationalHoliday = true; 4642 4643 } 4644 4645 var userScheduleKey = dateLabel.getAttribute("data-key"); 4646 var scheduleListPanel = []; 4647 for (var i = 0; i < updateSchedule[calendarKey].length; i++) { 4648 4649 var schedule = updateSchedule[calendarKey][i]; 4650 //schedule["select"] = true; 4651 if (parseInt(schedule["remainder"]) == 0 || schedule["stop"] == 'true') { 4652 4653 schedule["select"] = false; 4654 4655 } 4656 4657 var week = parseInt(schedule.weekKey); 4658 var minutes = parseInt(schedule.hour) * 60; 4659 if (nationalHoliday == true) { 4660 4661 week = 7; 4662 4663 } 4664 4665 if (timeToProvide[week] != null && parseInt(timeToProvide[week][minutes]) == 0) { 4666 4667 schedule["select"] = false; 4668 4669 } 4670 4671 object._console.log(schedule); 4672 4673 var schedulePanel = document.createElement("div"); 4674 schedulePanel.textContent = object._calendar.getPrintTime(("0" + schedule["hour"]).slice(-2), ("0" + schedule["min"]).slice(-2)) + schedule['title']; 4675 //schedulePanel.textContent = ("0" + schedule["hour"]).slice(-2) + ":" + ("0" + schedule["min"]).slice(-2) + " " + schedule['title']; 4676 schedulePanel.setAttribute("data-key", i); 4677 scheduleListPanel.push(schedulePanel); 4678 4679 if (schedule["select"] === true) { 4680 4681 schedulePanel.setAttribute("data-status", 1); 4682 schedulePanel.setAttribute("class", "courseAndScheduleRow"); 4683 schedulePanel.onclick = function(){ 4684 4685 this.setAttribute("class", "courseAndScheduleRow courseAndScheduleRowActive"); 4686 var key = this.getAttribute("data-key"); 4687 var schedule = calendarData['schedule'][calendarKey][key]; 4688 object.unselectPanel(key, scheduleListPanel, "courseAndScheduleRow"); 4689 object._console.log(schedule); 4690 var hour = (0 + schedule["hour"]).slice(-2); 4691 var min = (0 + schedule["min"]).slice(-2); 4692 var date = object._calendar.formatBookingDate(schedule.month, schedule.day, schedule.year, hour, min, schedule.title, null, 'text'); 4693 4694 dateLabel.setAttribute("data-key", schedule.key); 4695 dateLabel.setAttribute("data-unixTime", schedule.unixTime); 4696 dateLabel.textContent = date; 4697 4698 document.getElementById("beforChangeButton").classList.add("hidden_panel"); 4699 document.getElementById("nextChangeButton").classList.add("hidden_panel"); 4700 document.getElementById("changePanel").setAttribute("class", "return_change_panel"); 4701 callback({status: "statusButton", value: "1", calendarData: calendarData}); 4702 4703 } 4704 4705 if (userScheduleKey == schedule.key) { 4706 4707 object._console.log("onClick"); 4708 schedulePanel.setAttribute("class", "courseAndScheduleRow courseAndScheduleRowActive"); 4709 object.unselectPanel(i, scheduleListPanel, "courseAndScheduleRow"); 4710 4711 } 4712 4713 } else { 4714 4715 schedulePanel.setAttribute("data-status", 0); 4716 schedulePanel.setAttribute("class", "courseAndScheduleRowError"); 4717 4718 } 4719 4720 var table_row = document.createElement("div"); 4721 table_row.appendChild(schedulePanel); 4722 4723 changePanel.appendChild(table_row); 4724 4725 } 4726 4727 } else if (changeAction == 'course') { 4728 /** 4729 updateSchedule[calendarKey] = object._servicesControl.invalidService(updateSchedule[calendarKey], calendarData['bookedServices'], selectedService, courseTime, day, month, year); 4730 console.error(calendarData['bookedServices']); 4731 console.error(selectedService); 4732 console.error(updateSchedule[calendarKey]); 4733 **/ 4734 var courseLabel = document.getElementById("booking_course"); 4735 var userCourseKey = courseLabel.getAttribute("data-key"); 4736 var userScheduleKey = dateLabel.getAttribute("data-key"); 4737 4738 object._console.log(object._courseList); 4739 var calendarKey = object._calendar.getDateKey(month, day, year); 4740 var weekKey = parseInt(calendarData.calendar[calendarKey].week); 4741 object._console.log(object._nationalHoliday[calendarKey]); 4742 if (object._nationalHoliday[calendarKey] != null && parseInt(object._nationalHoliday[calendarKey].status) == 1) { 4743 4744 weekKey = 7; 4745 4746 } 4747 4748 var minutes = 0; 4749 for (var i = 0; i < updateSchedule[calendarKey].length; i++) { 4750 4751 var schedule = updateSchedule[calendarKey][i]; 4752 if (parseInt(schedule.key) == parseInt(userScheduleKey)) { 4753 4754 object._console.log(schedule); 4755 minutes = parseInt(schedule.hour) * 60; 4756 break; 4757 4758 } 4759 4760 } 4761 4762 object._console.log("weekKey = " + weekKey); 4763 4764 for (var i = 0; i < object._courseList.length; i++) { 4765 4766 if (parseInt(object._courseList[i].key) == parseInt(userCourseKey)) { 4767 4768 timeToProvide = object._courseList[i].timeToProvide; 4769 4770 } 4771 4772 } 4773 object._console.log(timeToProvide); 4774 4775 //var start = parseInt(dateLabel.getAttribute("data-unixTime")); 4776 var time = parseInt(dateLabel.getAttribute("data-unixTime")); 4777 for (var i = 0; i < updateSchedule[calendarKey].length; i++) { 4778 4779 var schedule = updateSchedule[calendarKey][i]; 4780 if (time < parseInt(schedule.unixTime) && schedule.remainder <= 0) { 4781 4782 object._console.log(schedule); 4783 time = (schedule.unixTime - time) / 60; 4784 break; 4785 4786 } 4787 4788 } 4789 object._console.log("time = " + time); 4790 4791 if (object.getServiceOrOption(options) == "service") { 4792 4793 object.setServices(options); 4794 4795 } 4796 4797 object._console.log(object._courseList); 4798 object._console.log(object.getVisitorServices()); 4799 object._console.log('time = ' + time); 4800 var firstService = 0; 4801 var firstCheckBox = null; 4802 var checkBoxList = []; 4803 var courseListPanel = []; 4804 for (var i = 0; i < object._courseList.length; i++) { 4805 4806 object._courseList[i].service = 1; 4807 object._courseList[i].selected = 0; 4808 object._courseList[i].selectedOptionsList = []; 4809 var courseData = object._courseList[i]; 4810 if (courseData.active != 'true') { 4811 4812 checkBoxList.push(''); 4813 continue; 4814 4815 } 4816 4817 var responseCosts = object._servicesControl.getCostsInService(courseData, guests, isGuests, object._isExtensionsValid); 4818 object._console.log(responseCosts); 4819 object._console.log(courseData); 4820 courseData["select"] = true; 4821 if (time < courseData.time) { 4822 4823 courseData["select"] = false;
4824 4825 } 4826 4827 timeToProvide = courseData.timeToProvide; 4828 if (timeToProvide[weekKey] != null && parseInt(timeToProvide[weekKey][minutes]) == 0) { 4829 4830 courseData["select"] = false; 4831 4832 } 4833 4834 object._console.log(courseData); 4835 object._console.log(object.lookingForVisitorServices(courseData)); 4836 4837 var coursePanel = document.createElement("div"); 4838 //coursePanel.textContent = courseData.name; 4839 coursePanel.setAttribute("data-key", i); 4840 4841 4842 var courseNamePanel = document.createElement("span"); 4843 courseNamePanel.textContent = courseData.name; 4844 //coursePanel.appendChild(courseNamePanel); 4845 4846 var checkBox = document.createElement("input"); 4847 checkBox.setAttribute("data-key", i); 4848 checkBox.type = "checkbox"; 4849 checkBox.value = ""; 4850 if (firstService == 0) { 4851 4852 firstCheckBox = checkBox; 4853 //object._courseList[i].selected = 1; 4854 //checkBox.checked = true; 4855 4856 } 4857 4858 if (object.lookingForVisitorServices(courseData) === true) { 4859 4860 object._courseList[i].selected = 1; 4861 for (var key in options) { 4862 4863 if (parseInt(options[key].key) == parseInt(courseData.key)) { 4864 4865 //object._courseList[i].selectedOptionsList = options[key].options; 4866 break; 4867 4868 } 4869 4870 } 4871 4872 checkBox.checked = true; 4873 4874 } 4875 4876 4877 //checkBox.disabled = true; 4878 4879 checkBox.onclick = function() { 4880 4881 if (this.checked == true) { 4882 4883 this.checked = false; 4884 4885 } else { 4886 4887 this.checked = true; 4888 4889 } 4890 4891 }; 4892 4893 checkBoxList.push(checkBox); 4894 4895 var label = document.createElement("span"); 4896 label.appendChild(checkBox); 4897 label.appendChild(courseNamePanel); 4898 if (parseInt(object._calendarAccount.hasMultipleServices) == 0) { 4899 4900 checkBox.classList.add("hidden_panel"); 4901 4902 } 4903 4904 coursePanel.appendChild(label); 4905 4906 if (courseData.cost != null) { 4907 4908 var cost = object._format.formatCost(courseData.cost, reservationData.currency); 4909 var courseCostPanel = document.createElement("span"); 4910 courseCostPanel.classList.add("courseCostPanel"); 4911 courseCostPanel.textContent = cost; 4912 coursePanel.appendChild(courseCostPanel); 4913 4914 } 4915 4916 4917 courseListPanel.push(coursePanel); 4918 4919 if (courseData["select"] === true) { 4920 4921 coursePanel.setAttribute("data-status", 1); 4922 coursePanel.setAttribute("class", "courseAndScheduleRow"); 4923 coursePanel.onclick = function(){ 4924 4925 this.setAttribute("class", "courseAndScheduleRow courseAndScheduleRowActive"); 4926 var key = this.getAttribute("data-key"); 4927 var courseData = object._courseList[key]; 4928 4929 object._console.log("key = " + key); 4930 object._console.log(courseData); 4931 object._console.log(checkBoxList); 4932 object._console.log(reservationData); 4933 object._console.log(typeof reservationData.options); 4934 4935 var options = []; 4936 var checkBox = checkBoxList[parseInt(key)]; 4937 if (checkBox.checked == true) { 4938 4939 if (parseInt(object._calendarAccount.hasMultipleServices) === 1) { 4940 4941 checkBox.checked = false;
4942 4943 } else { 4944 4945 checkBox.checked = true; 4946 4947 } 4948 //checkBox.checked = false; 4949 this.setAttribute("class", "courseAndScheduleRow"); 4950 object._courseList[parseInt(key)].selected = 0; 4951 4952 } else { 4953 4954 checkBox.checked = true; 4955 this.setAttribute("class", "courseAndScheduleRow courseAndScheduleRowActive"); 4956 object._courseList[parseInt(key)].selected = 1; 4957 4958 } 4959 4960 if (parseInt(object._calendarAccount.hasMultipleServices) == 0) { 4961 4962 var selectedServices = object.getVisitorServices(); 4963 for (var i in selectedServices) { 4964 4965 selectedServices[i].selected = 0; 4966 4967 } 4968 4969 object._courseList[parseInt(key)].selected = 1; 4970 4971 } 4972 4973 var service = object._courseList[parseInt(key)]; 4974 object._console.log(service); 4975 var options = service.options; 4976 if (typeof service.options == 'string') { 4977 4978 options = JSON.parse(service.options); 4979 4980 } 4981 4982 var valuePanel = document.getElementById("booking_course"); 4983 valuePanel.textContent = null; 4984 4985 var coursePanel = document.createElement("div"); 4986 coursePanel.classList.add("mainPlan"); 4987 valuePanel.appendChild(coursePanel); 4988 4989 if (options != null && options.length > 0) { 4990 4991 if (checkBox.checked == true) { 4992 4993 var selectOptionsPanel = document.getElementById("selectOptionsPanel"); 4994 object.getOptionsPanel(courseData, options, guests, false, function(response){ 4995 4996 var selectedOptions = response.selectedOptions; 4997 object._courseList[key]["selectedOptionsList"] = selectedOptions; 4998 var selectedServices = object.addVisitorServices(object._courseList[parseInt(key)]); 4999 object._console.log(selectedServices); 5000 object.createServicesPanel(coursePanel, selectedServices, "selectedOptionsList", guests, parseInt(object._calendarAccount.guestsBool), [], reservationData.currency, true); 5001 if (response.status == "createSchedule") { 5002 5003 selectOptionsPanel.classList.add("hidden_panel"); 5004 //closeCourseWindow(key, courseListPanel, courseData, courseLabel, calendarData, selectedOptions, callback); 5005 5006 } else if (response.status == "close") { 5007 5008 selectOptionsPanel.classList.add("hidden_panel"); 5009 if (coursePanel != null) { 5010 5011 coursePanel.setAttribute("class", "courseAndScheduleRow"); 5012 5013 } 5014 5015 } 5016 5017 }); 5018 5019 } else { 5020 5021 object._console.log(object._courseList[parseInt(key)]); 5022 var selectedServices = object.addVisitorServices(object._courseList[parseInt(key)]); 5023 object._console.log(selectedServices); 5024 object.createServicesPanel(coursePanel, selectedServices, "selectedOptionsList", guests, parseInt(object._calendarAccount.guestsBool), [], reservationData.currency, true); 5025 5026 5027 } 5028 5029 } else { 5030 5031 object._console.log(service); 5032 var selectedServices = object.addVisitorServices(object._courseList[parseInt(key)]); 5033 object._console.log(selectedServices); 5034 object.createServicesPanel(coursePanel, selectedServices, "selectedOptionsList", guests, parseInt(object._calendarAccount.guestsBool), [], reservationData.currency, true); 5035 5036 } 5037 5038 object._console.log(object._courseList); 5039 5040 5041 }; 5042 5043 if (courseData.key == userCourseKey) { 5044 5045 object._console.log("onClick"); 5046 coursePanel.setAttribute("class", "courseAndScheduleRow courseAndScheduleRowActive"); 5047 object.unselectPanel(i, courseListPanel, "courseAndScheduleRow"); 5048 5049 } 5050 5051 } else { 5052 5053 coursePanel.setAttribute("data-status", 0); 5054 coursePanel.setAttribute("class", "courseAndScheduleRowError"); 5055 5056 } 5057 5058 5059 5060 var table_row = document.createElement("div"); 5061 table_row.appendChild(coursePanel); 5062 5063 changePanel.appendChild(table_row); 5064 firstService++; 5065 5066 } 5067 5068 } 5069 5070 var getSelectedServices = function() { 5071 5072 var selectedServices = []; 5073 for (var i in object._courseList) { 5074 5075 var service = object._courseList[i]; 5076 if (parseInt(service.selected) == 1) { 5077 5078 selectedServices.push(service); 5079 5080 } 5081 5082 } 5083 5084 return selectedServices; 5085 5086 }; 5087 5088 beforChangeButton.onclick = function(){ 5089 5090 object._console.log("day = " + day); 5091 changeButtonAction(0, month, day, year, calendarData); 5092 5093 } 5094 5095 nextChangeButton.onclick = function(){ 5096 5097 object._console.log("day = " + day); 5098 changeButtonAction(1, month, day, year, calendarData); 5099 5100 } 5101 5102 } 5103 5104 this.preparToUpdateSchedule = function(reservationData, calendarData, courseTime, changeAction, preparation){ 5105 5106 var object = this; 5107 object._console.log(calendarData); 5108 object._console.log("changeAction = " + changeAction); 5109 object._console.log("courseTime = " + courseTime); 5110 object._console.log(preparation); 5111 object._console.log(typeof preparation); 5112 5113 if (isNaN(courseTime) === true) { 5114 5115 courseTime = 0; 5116 5117 } 5118 5119 if (preparation == null) { 5120 5121 preparation = {position: "before_after", time: 0}; 5122 object._console.log(preparation); 5123 5124 } 5125 var planBool = true; 5126 var start = parseInt(reservationData.scheduleUnixTime); 5127 //var end = start + parseInt(reservationData.courseTime) * 60; 5128 var end = start + parseInt(courseTime) * 60; 5129 5130 if (preparation != null && preparation.time != null && preparation.position != null) { 5131 5132 if (preparation.position == 'before_after' || preparation.position == 'before') { 5133 5134 start -= preparation.time * 60; 5135 5136 } 5137 5138 if (preparation.position == 'before_after' || preparation.position == 'after') { 5139 5140 end += preparation.time * 60; 5141 5142 } 5143 5144 } 5145 5146 if (start == end) { 5147 5148 planBool = false;
5149 5150 } 5151 object._console.log("start = " + start + " end = " + end); 5152 var applicantCount = parseInt(reservationData.applicantCount); 5153 var schedule = {}; 5154 var scheduleAll = []; 5155 5156 var count = 0; 5157 for(var key in calendarData.schedule){ 5158 5159 var daySchedule = []; 5160 for(var i = 0; i < calendarData.schedule[key].length; i++){ 5161 5162 var newDate = {}; 5163 Object.assign(newDate , calendarData.schedule[key][i]); 5164 var unixTime = parseInt(newDate.unixTime); 5165 if(planBool === true && unixTime >= start && unixTime < end){ 5166 5167 newDate.remainder = parseInt(newDate.remainder) + applicantCount; 5168 object._console.log(newDate); 5169 5170 }else if(planBool === false && unixTime == start){ 5171 5172 newDate.remainder = parseInt(newDate.remainder) + applicantCount; 5173 object._console.log(newDate); 5174 5175 } 5176 5177 if(newDate.stop == "true"){ 5178 5179 newDate.remainder = 0; 5180 5181 } 5182 5183 newDate.select = true; 5184 newDate.count = count; 5185 scheduleAll.push(newDate); 5186 daySchedule.push(newDate); 5187 count++; 5188 5189 if(planBool === true && newDate.remainder <= 0){ 5190 5191 (function(scheduleAll, unixTime, courseTime, applicantCount, start, end){ 5192 5193 var endTime = parseInt(unixTime) - (parseInt(courseTime) * 60); 5194 object._console.log("unixTime = " + unixTime + " endTime = " + endTime + " courseTime = " + courseTime + " length = " + scheduleAll.length); 5195 for(var i = scheduleAll.length; i > 0; i--){ 5196 5197 var schedule = scheduleAll[(i - 1)]; 5198 var time = schedule.year + "/" + schedule.month + "/" + schedule.day + " " + schedule.hour + ":" + schedule.min + " remainder = " + schedule.remainder; 5199 if(endTime >= schedule.unixTime){ 5200 5201 break; 5202 5203 } 5204 5205 if(schedule.remainder > 0 && (unixTime <= start && unixTime > end) && changeAction == 'course'){ 5206 5207 schedule.remainder -= applicantCount; 5208 5209 } 5210 5211 if(schedule.remainder > 0 && changeAction == 'date'){ 5212 5213 //schedule.remainder -= applicantCount; 5214 schedule.remainder = 0; 5215 5216 } 5217 5218 } 5219 5220 })(scheduleAll, newDate.unixTime, courseTime, applicantCount, start, end); 5221 5222 } 5223 5224 } 5225 5226 schedule[key] = daySchedule; 5227 5228 } 5229 5230 return {schedule: schedule, scheduleAll: scheduleAll}; 5231 5232 } 5233 5234 this.add_reservation = function(add_reservationPanel, month, day, year, calendarData, accountKey, callback){ 5235 5236 var object = this; 5237 object._buttonAction = "add_reservation"; 5238 object._console.log("buttonAction = " + object._buttonAction); 5239 object._console.log(object._courseList); 5240 object._console.log(calendarData); 5241 var calendarKey = object._calendar.getDateKey(month, day, year); 5242 object._console.log(calendarKey); 5243 var week = calendarData.calendar[calendarKey].week; 5244 object._console.log('week = ' + week); 5245 add_reservationPanel.classList.remove("hidden_panel"); 5246 add_reservationPanel.textContent = null; 5247 object._rightButtonPanel.textContent = null; 5248 5249 for (var key in object._courseList) { 5250 5251 object._courseList[key].service = 1; 5252 object._courseList[key].selected = 0; 5253 object._courseList[key].selectedOptionsList = []; 5254 5255 } 5256 5257 var courseMainPanel = document.createElement("div"); 5258 courseMainPanel.setAttribute("class", "courseListPanel box_shadow"); 5259 5260 var scheduleMainPanel = document.createElement("div"); 5261 scheduleMainPanel.setAttribute("class", "scheduleListPanel courseListPanel box_shadow"); 5262 5263 var formMainPanel = document.createElement("div"); 5264 formMainPanel.setAttribute("class", "createFormPanel_return"); 5265 5266 var mainPanel = document.createElement("div"); 5267 mainPanel.setAttribute("class", "courseAndSchedulePanel"); 5268 mainPanel.appendChild(courseMainPanel); 5269 mainPanel.appendChild(scheduleMainPanel); 5270 //mainPanel.appendChild(formMainPanel); 5271 add_reservationPanel.appendChild(mainPanel); 5272 add_reservationPanel.appendChild(formMainPanel); 5273 5274 if (calendarData.account.type == 'hotel') { 5275 5276 //hotel.reset(); 5277 object._console.log(calendarData.account); 5278 object._console.log(calendarData.guestsList); 5279 mainPanel.removeChild(courseMainPanel); 5280 5281 var weekName = [object._i18n.get('Sun'), object._i18n.get('Mon'), object._i18n.get('Tue'), object._i18n.get('Wed'), object._i18n.get('Thu'), object._i18n.get('Fri'), object._i18n.get('Sat')]; 5282 var calendar = new Booking_App_Calendar(weekName, object._dateFormat, object._positionOfWeek, object._positionTimeDate, object._startOfWeek, object._i18n, object._debug); 5283 object._calendar.setClock(object._clock); 5284 var calendarKey = object._calendar.getDateKey(month, day, year); 5285 var checkDate = object._hotel.getCheckDate(); 5286 object._console.log(checkDate); 5287 if(checkDate.checkIn == null && calendarData.schedule[parseInt(calendarKey)] != null && calendarData.schedule[parseInt(calendarKey)][0] != null){ 5288 5289 checkDate.checkIn = calendarData.schedule[parseInt(calendarKey)][0]; 5290 object._console.log(object._hotel.getCheckDate()); 5291 5292 } 5293 5294 var bookingCalendar = function(calendarData){ 5295 5296 var year = parseInt(calendarData.date.year);
5297 var month = parseInt(calendarData.date.month); 5298 //hotel.verifySchedule(true); 5299 5300 scheduleMainPanel.textContent = null; 5301 scheduleMainPanel.setAttribute("style", "animation-name: unset;"); 5302 //scheduleMainPanel.setAttribute("style", "left: 0;"); 5303 scheduleMainPanel.setAttribute("class", "schedulePanel_next"); 5304 5305 5306 var dayHeight = parseInt(scheduleMainPanel.clientWidth / 7); 5307 object._console.log("dayHeight = " + dayHeight); 5308 5309 var returnLabel = document.createElement("label"); 5310 var nextLabel = document.createElement("label"); 5311 var topPanel = object._calendar.createHeader(month, year, 0, true); 5312 if (topPanel.querySelector('#change_calendar_return') != null) { 5313 5314 returnLabel = topPanel.querySelector('#change_calendar_return'); 5315 5316 } 5317 5318 if (topPanel.querySelector('#change_calendar_next') != null) { 5319 5320 nextLabel = topPanel.querySelector('#change_calendar_next'); 5321 5322 } 5323 5324 scheduleMainPanel.appendChild(topPanel); 5325 5326 var calendarKey = object._calendar.getDateKey(month, day, year); 5327 var checkDate = object._hotel.getCheckDate(); 5328 object._console.log(checkDate); 5329 /** 5330 if(checkDate.checkIn == null && calendarData.schedule[parseInt(calendarKey)] != null && calendarData.schedule[parseInt(calendarKey)][0] != null){ 5331 5332 checkDate.checkIn = calendarData.schedule[parseInt(calendarKey)][0]; 5333 object._console.log(hotel.getCheckDate()); 5334 5335 } 5336 **/ 5337 5338 var scopeOfDay = {start: null, end: null}; 5339 var dayPanelList = {}; 5340 object._calendar.create(scheduleMainPanel, calendarData, month, day, year, '', function(calendarCallback){ 5341 5342 object._console.log(calendarCallback); 5343 var key = parseInt(calendarCallback.key); 5344 var dayPanel = calendarCallback['eventPanel']; 5345 if(key > 0){ 5346 5347 dayPanelList[key] = dayPanel; 5348 object._hotel.setDayPanelList(dayPanelList); 5349 5350 } 5351 dayPanel.setAttribute("style", "height: " + (dayHeight) + "px;"); 5352 dayPanel.setAttribute("data-unixTime", 0); 5353 if(calendarData.schedule[key] != null && calendarData.schedule[key][0] != null){ 5354 5355 dayPanel.setAttribute("data-unixTime", calendarData.schedule[key][0].unixTime); 5356 5357 if(calendarData.schedule[key].length != 0){ 5358 5359 object._hotel.addSchedule(calendarData.schedule[key][0]); 5360 5361 if(checkDate.checkIn != null && checkDate.checkIn.unixTime == calendarData.schedule[key][0].unixTime && calendarData.schedule[key][0].remainder > 0){ 5362 5363 dayPanel.classList.add("selected_day_slot"); 5364 5365 } 5366 5367 if((checkDate.checkIn != null && checkDate.checkOut != null) && (checkDate.checkIn.unixTime <= calendarData.schedule[key][0].unixTime && checkDate.checkOut.unixTime >= calendarData.schedule[key][0].unixTime)){ 5368 5369 object._console.log("checkDate.checkIn.unixTime = " + checkDate.checkIn.unixTime); 5370 dayPanel.classList.add("selected_day_slot"); 5371 5372 } 5373 5374 if(parseInt(calendarData.schedule[key][0].remainder) <= 0 || calendarData.schedule[key][0].stop == 'true'){ 5375 5376 dayPanel.classList.remove("selected_day_slot"); 5377 dayPanel.classList.add("closeDay"); 5378 5379 } 5380 5381 dayPanel.onclick = function(){ 5382 5383 var dateKey = parseInt(this.getAttribute("data-key")); 5384 object._console.log("dateKey = " + dateKey); 5385 var checkIn = document.getElementById("checkIn").getAttribute("data-check"); 5386 var checkInUnixTime = parseInt(document.getElementById("checkIn").getAttribute("data-unixTime")); 5387 object._console.log("checkIn = " + checkIn + " checkInUnixTime = " + checkInUnixTime); 5388 5389 var schedule = calendarData.schedule[dateKey][0]; 5390 var checkOutUnixTime = parseInt(schedule.unixTime); 5391 var checkOutBool = true; 5392 if(checkIn == parseInt(schedule.key)){ 5393 5394 //return null; 5395 5396 } 5397 5398 var checkDate = object._hotel.getCheckDate(); 5399 object._console.log(checkDate); 5400 5401 if (checkDate.checkIn == null) { 5402 5403 if (schedule.remainder <= 0) { 5404 5405 return null; 5406 5407 } 5408 5409 object._hotel.setDayPanelList(dayPanelList); 5410 object._console.log(schedule); 5411 object._console.log(dayPanelList[dateKey]); 5412 dayPanelList[dateKey].classList.add("selected_day_slot"); 5413 object._hotel.setCheckIn(schedule); 5414 object._hotel.setCheckInKey(schedule.key); 5415 5416 var checkInClearLabel = document.getElementById("checkInClear"); 5417 checkInClearLabel.classList.remove("hidden_panel"); 5418 5419 var scheduleList = calendarData.schedule[calendarKey][0]; 5420 var date = object._calendar.formatBookingDate(schedule.month, schedule.day, schedule.year, null, null, null, schedule.weekKey, 'text'); 5421 //object._console.log("monthKey = " + monthKey + " dayKey = " + dayKey + " yearKey = " + yearKey); 5422 object._console.log(scheduleList); 5423 object._console.log(checkDate); 5424 5425 var checkInDatePanel = document.getElementById("checkIn"); 5426 checkInDatePanel.textContent = date; 5427 5428 }else{ 5429 5430 var checkInUnixTime = parseInt(checkDate.checkIn.unixTime); 5431 var checkInMonth = parseInt(checkDate.checkIn.month); 5432 var chekInDay = parseInt(checkDate.checkIn.day); 5433 var checkInYear = parseInt(checkDate.checkIn.year); 5434 5435 var verifySchedule = false;
5436 if(checkInUnixTime < checkOutUnixTime){ 5437 5438 object._hotel.setCheckOut(schedule); 5439 object._hotel.setCheckOutKey(schedule.key); 5440 verifySchedule = object._hotel.verifySchedule(true); 5441 object._console.log(verifySchedule); 5442 for(var key in dayPanelList){ 5443 5444 var checkOut = parseInt(dayPanelList[key].getAttribute("data-unixTime")); 5445 if(verifySchedule.status == true && checkInUnixTime <= checkOut && checkOutUnixTime >= checkOut){ 5446 5447 dayPanelList[key].classList.add("selected_day_slot"); 5448 5449 }else if(checkInUnixTime != checkOut){ 5450 5451 dayPanelList[key].classList.remove("selected_day_slot"); 5452 5453 } 5454 5455 } 5456 5457 } 5458 5459 var checkOut = document.getElementById("checkOut"); 5460 if(verifySchedule.status == true){ 5461 5462 checkOut.setAttribute("data-check", schedule.key); 5463 checkOut.textContent = object._calendar.formatBookingDate(schedule.month, schedule.day, schedule.year, null, null, null, schedule.weekKey, 'text'); 5464 object._hotel.setCheckOut(schedule); 5465 object._hotel.setCheckOutKey(schedule.key); 5466 5467 }else{ 5468 5469 object._hotel.setCheckOut(null); 5470 object._hotel.setCheckOutKey(null); 5471 //checkOut.setAttribute("data-check", null); 5472 //checkOut.textContent = object._i18n.get("Please choose a departure date from the calendar"); 5473 5474 } 5475 5476 object._hotel.verifySchedule(true); 5477 5478 } 5479 5480 } 5481 5482 }else{ 5483 5484 dayPanel.classList.add("closeDay"); 5485 dayPanel.classList.remove("pointer"); 5486 5487 } 5488 5489 }else{ 5490 5491 dayPanel.classList.add("closeDay"); 5492 dayPanel.classList.remove("pointer"); 5493 5494 } 5495 5496 }); 5497 5498 returnLabel.onclick = function(){ 5499 5500 if (month == 1) { 5501 5502 year--; 5503 month = 12; 5504 5505 } else { 5506 5507 month--; 5508 5509 } 5510 5511 object.getReservationData(month, 1, year, accountKey, 0, function(calendarData){ 5512 5513 object._console.log(calendarData); 5514 bookingCalendar(calendarData); 5515 5516 }); 5517 5518 } 5519 5520 nextLabel.onclick = function(){ 5521 5522 if (month == 12) { 5523 5524 year++;
5525 month = 1; 5526 5527 } else { 5528 5529 month++; 5530 5531 } 5532 5533 object.getReservationData(month, 1, year, accountKey, 0, function(calendarData){ 5534 5535 object._console.log(calendarData); 5536 bookingCalendar(calendarData); 5537 5538 }); 5539 5540 } 5541 5542 } 5543 5544 bookingCalendar(calendarData); 5545 5546 object.createForm(mainPanel, courseMainPanel, scheduleMainPanel, formMainPanel, month, day, year, calendarData, course, null, null, accountKey, function(response){ 5547 5548 if(response.action == 'refresh'){ 5549 5550 callback(response); 5551 5552 } 5553 5554 }); 5555 5556 5557 5558 } else { 5559 5560 if (object._courseBool == true) { 5561 5562 if (object._courseList.length == 0) { 5563 5564 //var errorMessage = object._i18n.get("Service is not registered. "); 5565 var errorMessage = object._i18n.get("Please create a service."); 5566 var confirm = new Confirm(object._debug); 5567 confirm.alertPanelShow(object._i18n.get("Error"), errorMessage, false, function(caalback){ 5568 5569 5570 5571 }); 5572 5573 return null; 5574 5575 } 5576 var isBooking = object._servicesControl.validateServices(month, day, year, week, true, true); 5577 object._console.log(isBooking); 5578 var animationBool = true; 5579 var checkBoxList = {}; 5580 var coursePanelList = []; 5581 var courseList = object._courseList; 5582 var firstCheckBox = null; 5583 var firstService = 0; 5584 for (var i = 0; i < object._courseList.length; i++) { 5585 5586 var course = object._courseList[i]; 5587 object._console.log(course); 5588 if (course.active != "true" || course.closed == 1) { 5589 5590 continue; 5591 5592 } 5593 5594 if (firstService == 0) { 5595 5596 var options = []; 5597 if (course.options != null) { 5598 5599 options = JSON.parse(course.options); 5600 5601 } 5602 5603 if (options.length > 0) { 5604 5605 object._console.log(options); 5606 object.createOptionsPanel(mainPanel, courseMainPanel, scheduleMainPanel, formMainPanel, coursePanel, month, day, year, calendarData, firstService, course, accountKey, function(response){ 5607 5608 object._console.log(firstService); 5609 object._console.log(course); 5610 object._console.log(response); 5611 courseList[parseInt(response.key)].selectedOptionsList = response.selectedOptions; 5612 object.createSchedule(mainPanel, courseMainPanel, scheduleMainPanel, formMainPanel, month, day, year, calendarData, courseList, response.selectedOptions, accountKey, function(response){ 5613 5614 callback(response); 5615 5616 }); 5617 //callback(response); 5618 5619 }); 5620 5621 } 5622 5623 } 5624 5625 if (typeof course["name"] == "string") { 5626 5627 course["name"] = course["name"].replace(/\\/g, ""); 5628 5629 } 5630 5631 course["status"] = true; 5632 5633 var coursePanel = document.createElement("div"); 5634 coursePanel.setAttribute("data-key", i); 5635 coursePanel.setAttribute("data-status", 1); 5636 coursePanel.setAttribute("class", "courseAndScheduleRow"); 5637 5638 5639 var courseNamePanel = document.createElement("span"); 5640 courseNamePanel.textContent = course["name"]; 5641 5642 var checkBox = document.createElement("input"); 5643 checkBox.id = 'service_checkBox_' + i; 5644 checkBox.setAttribute("data-key", i); 5645 checkBox.type = "checkbox"; 5646 checkBox.value = ""; 5647 if (firstService == 0) { 5648 5649 firstCheckBox = checkBox; 5650 object._courseList[i].selected = 1; 5651 checkBox.checked = true; 5652 5653 } 5654 //checkBox.disabled = true; 5655 5656 checkBox.onclick = function() { 5657 5658 if (this.checked == true) { 5659 5660 this.checked = false;
5661 5662 } else { 5663 5664 this.checked = true; 5665 5666 } 5667 5668 }; 5669 5670 //checkBoxList.push(checkBox); 5671 checkBoxList[i] = checkBox; 5672 5673 var label = document.createElement("span"); 5674 label.appendChild(checkBox); 5675 label.appendChild(courseNamePanel); 5676 if(parseInt(object._calendarAccount.hasMultipleServices) == 0){ 5677 5678 checkBox.classList.add("hidden_panel"); 5679 5680 } 5681 5682 coursePanel.appendChild(label); 5683 /** 5684 if(course.cost != null){ 5685 5686 var cost = object._format.formatCost(course.cost, object._currency); 5687 var courseCostPanel = document.createElement("span"); 5688 courseCostPanel.classList.add("courseCostPanel"); 5689 courseCostPanel.textContent = cost; 5690 coursePanel.appendChild(courseCostPanel); 5691 5692 } 5693 **/ 5694 var responseCosts = object._servicesControl.getCostsInService(course, calendarData.guestsList, parseInt(calendarData.account.guestsBool), object._isExtensionsValid); 5695 object._console.log(responseCosts); 5696 if (responseCosts.max != null && isNaN(parseInt(responseCosts.max)) === false && parseInt(responseCosts.max) != 0) { 5697 5698 var cost = object._format.formatCost(responseCosts.max, object._currency); 5699 if (responseCosts.hasMultipleCosts === true) { 5700 5701 //cost = object._format.formatCost(responseCosts.min, object._currency) + ' ' + object._i18n.get('to') + ' ' + object._format.formatCost(responseCosts.max, object._currency); 5702 cost = object._i18n.get('%s to %s', [object._format.formatCost(responseCosts.min, object._currency), object._format.formatCost(responseCosts.max, object._currency)]); 5703 5704 } 5705 5706 var courseCostPanel = document.createElement("span"); 5707 courseCostPanel.classList.add("courseCostPanel"); 5708 courseCostPanel.textContent = cost; 5709 coursePanel.appendChild(courseCostPanel); 5710 5711 } 5712 5713 coursePanelList.push(coursePanel); 5714 5715 var table_row = document.createElement("div"); 5716 table_row.appendChild(coursePanel); 5717 5718 courseMainPanel.appendChild(table_row); 5719 5720 coursePanel.onclick = function(){ 5721 5722 var coursePanel = this; 5723 coursePanel.setAttribute("class", "courseAndScheduleRow courseAndScheduleRowActive"); 5724 var key = coursePanel.getAttribute("data-key"); 5725 var course = object._courseList[parseInt(key)]; 5726 object.unselectPanel(key, coursePanelList, "courseAndScheduleRow"); 5727 object._console.log(course); 5728 var options = []; 5729 if (course.options != null) { 5730 5731 options = JSON.parse(course.options); 5732 5733 } 5734 object._console.log(options); 5735 5736 var checkBox = checkBoxList[parseInt(key)]; 5737 if(parseInt(object._calendarAccount.hasMultipleServices) == 0){ 5738 5739 for (var i in courseList) { 5740 5741 courseList[i].selected = 0; 5742 5743 } 5744 5745 courseList[parseInt(key)].selected = 1; 5746 checkBox.checked = true; 5747 5748 } else { 5749 5750 object._console.log(checkBox); 5751 if(checkBox.checked == true){ 5752 5753 checkBox.checked = false;
5754 this.setAttribute("class", "courseAndScheduleRow"); 5755 courseList[parseInt(key)].selected = 0; 5756 5757 }else{ 5758 5759 checkBox.checked = true; 5760 this.setAttribute("class", "courseAndScheduleRow courseAndScheduleRowActive"); 5761 courseList[parseInt(key)].selected = 1; 5762 5763 } 5764 5765 var selected = false; 5766 for (var i in courseList) { 5767 5768 if (courseList[i].selected == 1) { 5769 5770 selected = true; 5771 break; 5772 5773 } 5774 5775 } 5776 5777 if (selected === false) { 5778 5779 var key = parseInt(firstCheckBox.getAttribute("data-key")); 5780 courseList[key].selected = 1; 5781 firstCheckBox.checked = true; 5782 5783 } 5784 5785 } 5786 5787 if (options.length <= 0) { 5788 5789 object.createSchedule(mainPanel, courseMainPanel, scheduleMainPanel, formMainPanel, month, day, year, calendarData, courseList, null, accountKey, function(response){ 5790 5791 callback(response); 5792 5793 }); 5794 5795 } else { 5796 5797 var checkBox = checkBoxList[parseInt(key)]; 5798 object._console.log(checkBox); 5799 if (checkBox.checked == true) { 5800 5801 object.createOptionsPanel(mainPanel, courseMainPanel, scheduleMainPanel, formMainPanel, coursePanel, month, day, year, calendarData, key, course, accountKey, function(response){ 5802 5803 courseList[parseInt(key)].selectedOptionsList = response.selectedOptions; 5804 object.createSchedule(mainPanel, courseMainPanel, scheduleMainPanel, formMainPanel, month, day, year, calendarData, courseList, response.selectedOptions, accountKey, function(response){ 5805 5806 callback(response); 5807 5808 }); 5809 5810 }); 5811 5812 } 5813 5814 } 5815 5816 } 5817 5818 firstService++; 5819 5820 } 5821 object._console.log(coursePanelList); 5822 //coursePanelList[0].setAttribute("class", "courseAndScheduleRow courseAndScheduleRowActive"); 5823 if(coursePanelList[0] != null){ 5824 5825 coursePanelList[0].setAttribute("class", "courseAndScheduleRow courseAndScheduleRowActive"); 5826 5827 } 5828 5829 object.createSchedule(mainPanel, courseMainPanel, scheduleMainPanel, formMainPanel, month, day, year, calendarData, object._courseList , null, accountKey, function(response){ 5830 5831 callback(response); 5832 5833 }); 5834 5835 } else { 5836 5837 mainPanel.removeChild(courseMainPanel); 5838 scheduleMainPanel.setAttribute("style", "left: 0;"); 5839 scheduleMainPanel.setAttribute("class", "schedulePanel"); 5840 5841 object.createSchedule(mainPanel, courseMainPanel, scheduleMainPanel, formMainPanel, month, day, year, calendarData, null, null, accountKey, function(response){ 5842 5843 callback(response); 5844 5845 }); 5846 5847 } 5848 5849 } 5850 5851 5852 5853 5854 5855 } 5856 5857 this.getOptionsPanel = function(course, options, guestsList, closeWithClick, callback){ 5858 5859 var object = this; 5860 var selectedOptions = []; 5861 var checkBoxList = []; 5862 var disabledButton = true; 5863 //var options = JSON.parse(course.options); 5864 object._console.log(course); 5865 if (typeof options == "string") { 5866 5867 options = JSON.parse(course.options); 5868 5869 } 5870 5871 var isGuests = 0; 5872 if (guestsList != null && guestsList.length > 0) { 5873 5874 isGuests = 1; 5875 5876 } 5877 5878 var selectOptionsPanel = document.getElementById("selectOptionsPanel"); 5879 var nextButton = selectOptionsPanel.getElementsByClassName("decisionButton")[0]; 5880 var title = selectOptionsPanel.getElementsByClassName("subject")[0]; 5881 var bodyPanel = selectOptionsPanel.getElementsByClassName("body")[0]; 5882 selectOptionsPanel.classList.remove("hidden_panel"); 5883 title.textContent = course.name; 5884 bodyPanel.textContent = null; 5885 bodyPanel.setAttribute("style", "bottom: 56px;"); 5886 nextButton.classList.remove("hidden_panel"); 5887 nextButton.disabled = true; 5888 if (parseInt(course.selectOptions) == 0) { 5889 5890 bodyPanel.setAttribute("style", "bottom: 0;"); 5891 nextButton.classList.add("hidden_panel"); 5892 5893 } 5894 5895 for(var i = 0; i < options.length; i++){ 5896 5897 var option = options[i]; 5898 var responseCosts = object._servicesControl.getCostsInService(option, guestsList, isGuests, object._isExtensionsValid); 5899 object._console.log(responseCosts); 5900 object._console.log(typeof option.selected); 5901 if (option.selected == null) { 5902 5903 option.selected = 0; 5904 5905 } 5906 5907 object._console.log(option); 5908 selectedOptions.push(option); 5909 var optionPanel = document.createElement("div"); 5910 optionPanel.setAttribute("data-key", i); 5911 optionPanel.setAttribute("data-status", 1); 5912 optionPanel.setAttribute("class", "courseAndScheduleRow"); 5913 5914 var titleLabel = document.createElement("span"); 5915 titleLabel.textContent = option.name; 5916 5917 var checkBox = document.createElement("input"); 5918 checkBox.setAttribute("data-key", i); 5919 checkBox.type = "checkbox"; 5920 checkBox.value = 1; 5921 if(parseInt(option.selected) == 1){ 5922 5923 checkBox.checked = true; 5924 optionPanel.classList.add("courseAndScheduleRowActive"); 5925 disabledButton = false;
5926 5927 } 5928 checkBoxList.push(checkBox); 5929 5930 var label = document.createElement("span"); 5931 label.appendChild(checkBox); 5932 label.appendChild(titleLabel); 5933 if(parseInt(course.selectOptions) == 0){ 5934 5935 checkBox.classList.add("hidden_panel"); 5936 5937 } 5938 5939 optionPanel.appendChild(label); 5940 5941 if (responseCosts.max != null && isNaN(parseInt(responseCosts.max)) === false && parseInt(responseCosts.max) != 0) { 5942 5943 var cost = object._format.formatCost(responseCosts.max, object._currency); 5944 if (responseCosts.hasMultipleCosts === true) { 5945 5946 //cost = object._format.formatCost(responseCosts.min, object._currency) + ' ' + object._i18n.get(' to ') + ' ' + object._format.formatCost(responseCosts.max, object._currency); 5947 cost = object._i18n.get('%s to %s', [object._format.formatCost(responseCosts.min, object._currency), object._format.formatCost(responseCosts.max, object._currency)]); 5948 5949 } 5950 var optionCostPanel = document.createElement("span"); 5951 optionCostPanel.classList.add("courseCostPanel"); 5952 optionCostPanel.textContent = cost; 5953 optionPanel.appendChild(optionCostPanel); 5954 5955 } 5956 5957 bodyPanel.appendChild(optionPanel); 5958 5959 checkBox.onclick = function(event) { 5960 5961 if (this.checked == true) { 5962 5963 this.checked = false; 5964 5965 } else { 5966 5967 this.checked = true; 5968 5969 } 5970 5971 }; 5972 5973 optionPanel.onclick = function() { 5974 5975 object._console.log(course); 5976 var key = parseInt(this.getAttribute("data-key")); 5977 var option = options[key]; 5978 object._console.log(option); 5979 var checkBox = checkBoxList[key]; 5980 if (checkBox.checked == true) { 5981 5982 checkBox.checked = false; 5983 this.setAttribute("class", "courseAndScheduleRow"); 5984 selectedOptions[key].selected = 0; 5985 5986 } else { 5987 5988 checkBox.checked = true; 5989 this.setAttribute("class", "courseAndScheduleRow courseAndScheduleRowActive"); 5990 selectedOptions[key].selected = 1; 5991 5992 } 5993 5994 object._console.log(selectedOptions); 5995 nextButton.disabled = true; 5996 for (var i = 0; i < selectedOptions.length; i++) { 5997 5998 if (selectedOptions[i].selected == 1) { 5999 6000 if (parseInt(course.selectOptions) == 0) { 6001 6002 object._console.log(course); 6003 var response = {status: "createSchedule", selectedOptions: selectedOptions}; 6004 callback(response); 6005 6006 } else { 6007 6008 nextButton.disabled = false; 6009 6010 } 6011 6012 break; 6013 6014 } 6015 6016 } 6017 6018 }; 6019 6020 } 6021 6022 if (disabledButton == false) { 6023 6024 nextButton.disabled = false; 6025 6026 } 6027 nextButton.removeEventListener("check", null); 6028 nextButton.onclick = function(){ 6029 6030 var response = {status: "createSchedule", selectedOptions: selectedOptions}; 6031 callback(response); 6032 6033 }; 6034 6035 if (closeWithClick === true) { 6036 6037 selectOptionsPanel.getElementsByClassName("blockPanel")[0].onclick = function(){ 6038 6039 var response = {status: "close", selectedOptions: selectedOptions}; 6040 callback(response); 6041 6042 }; 6043 6044 } 6045 6046 6047 object._console.log(course); 6048 6049 } 6050 6051 this.createOptionsPanel = function(mainPanel, courseMainPanel, scheduleMainPanel, formMainPanel, coursePanel, month, day, year, calendarData, courseKey, course, accountKey, callback){ 6052 6053 var object = this; 6054 var selectOptionsPanel = document.getElementById("selectOptionsPanel"); 6055 object.getOptionsPanel(course, course.options, calendarData.guestsList, false, function(response){ 6056 6057 if (response.status == "createSchedule") { 6058 6059 var selectedOptions = response.selectedOptions; 6060 selectOptionsPanel.classList.add("hidden_panel"); 6061 callback({selectedOptions: selectedOptions, key: courseKey}); 6062 /** 6063 object.createSchedule(mainPanel, courseMainPanel, scheduleMainPanel, formMainPanel, month, day, year, calendarData, course, selectedOptions, accountKey, function(response){ 6064 6065 callback(response); 6066 6067 }); 6068 **/ 6069 6070 } else if (response.status == "close") { 6071 6072 selectOptionsPanel.classList.add("hidden_panel"); 6073 if (coursePanel != null) { 6074 6075 coursePanel.setAttribute("class", "courseAndScheduleRow"); 6076 6077 } 6078 6079 } 6080 6081 }); 6082 6083 } 6084 6085 this.createBookingCalendar = function(add_reservationPanel, day, calendarData, accountKey, scheduleMainPanel, callback){ 6086 6087 var object = this; 6088 var year = parseInt(calendarData.date.year);
6089 var month = parseInt(calendarData.date.month); 6090 6091 var weekName = [object._i18n.get('Sun'), object._i18n.get('Mon'), object._i18n.get('Tue'), object._i18n.get('Wed'), object._i18n.get('Thu'), object._i18n.get('Fri'), object._i18n.get('Sat')]; 6092 object._calendar = new Booking_App_Calendar(weekName, object._dateFormat, object._positionOfWeek, object._positionTimeDate, object._startOfWeek, object._i18n, object._debug); 6093 object._calendar.setClock(object._clock); 6094 var dayHeight = parseInt(scheduleMainPanel.clientWidth / 7); 6095 object._console.log("dayHeight = " + dayHeight); 6096 6097 var returnLabel = document.createElement("label"); 6098 var nextLabel = document.createElement("label"); 6099 var topPanel = object._calendar.createHeader(month, year, 0, true); 6100 if (topPanel.querySelector('#change_calendar_return') != null) { 6101 6102 returnLabel = topPanel.querySelector('#change_calendar_return'); 6103 6104 } 6105 6106 if (topPanel.querySelector('#change_calendar_next') != null) { 6107 6108 nextLabel = topPanel.querySelector('#change_calendar_next'); 6109 6110 } 6111 6112 scheduleMainPanel.appendChild(topPanel); 6113 6114 var clickPoint = {start: null, end: null}; 6115 var scopeOfDay = {start: null, end: null}; 6116 var dayPanelList = {}; 6117 object._calendar.create(scheduleMainPanel, calendarData, month, day, year, '', function(callback){ 6118 6119 object._console.log(callback); 6120 var key = parseInt(callback.day); 6121 var dayPanel = callback['eventPanel']; 6122 if(key > 0){ 6123 6124 dayPanelList[key] = dayPanel; 6125 6126 } 6127 dayPanel.setAttribute("style", "height: " + (dayHeight / 2) + "px;"); 6128 if(calendarData.schedule[key] != null && calendarData.schedule[key][0] != null){ 6129 6130 object._console.log(calendarData.schedule[key]); 6131 if(calendarData.schedule[key].length != 0){ 6132 6133 if(key == parseInt(day)){ 6134 6135 dayPanel.classList.add("selected_day_slot"); 6136 6137 } 6138 6139 if(parseInt(calendarData.schedule[key][0].remainder) <= 0){ 6140 6141 dayPanel.classList.add("closeDay"); 6142 6143 } 6144 6145 dayPanel.onclick = function(){ 6146 6147 var dateKey = parseInt(this.getAttribute("data-key")); 6148 object._console.log("dateKey = " + dateKey); 6149 var checkIn = document.getElementById("checkIn").getAttribute("data-check"); 6150 var checkInUnixTime = parseInt(document.getElementById("checkIn").getAttribute("data-unixTime")); 6151 object._console.log("checkIn = " + checkIn + " checkInUnixTime = " + checkInUnixTime); 6152 6153 var schedule = calendarData.schedule[dateKey][0]; 6154 var checkOutUnixTime = parseInt(schedule.unixTime); 6155 var checkOutBool = true; 6156 if(checkInUnixTime < checkOutUnixTime){ 6157 6158 for(var key in dayPanelList){ 6159 6160 if(day <= parseInt(key) && dateKey >= parseInt(key)){ 6161 6162 var remainder = parseInt(calendarData.schedule[key][0].remainder); 6163 if(remainder == 0 && parseInt(key) != dateKey){ 6164 6165 (function(){ 6166 6167 object._console.log("remainder = " + remainder); 6168 for(var key in dayPanelList){ 6169 6170 if(day != parseInt(key)){ 6171 6172 dayPanelList[key].classList.remove("selected_day_slot"); 6173 6174 } 6175 6176 } 6177 6178 })(); 6179 checkOutBool = false;
6180 break; 6181 } 6182 dayPanelList[key].classList.add("selected_day_slot"); 6183 6184 }else{ 6185 6186 dayPanelList[key].classList.remove("selected_day_slot"); 6187 6188 } 6189 6190 } 6191 6192 } 6193 6194 var checkOut = document.getElementById("checkOut"); 6195 if(checkOutBool == true){ 6196 6197 checkOut.setAttribute("data-check", schedule.key); 6198 checkOut.textContent = object._calendar.formatBookingDate(schedule.month, schedule.day, schedule.year, null, null, null, schedule.weekKey, 'text'); 6199 6200 }else{ 6201 6202 checkOut.setAttribute("data-check", null); 6203 checkOut.textContent = object._i18n.get("Please choose a departure date from the calendar"); 6204 6205 } 6206 6207 } 6208 6209 }else{ 6210 6211 dayPanel.classList.add("closeDay"); 6212 dayPanel.classList.remove("pointer"); 6213 6214 } 6215 6216 }else{ 6217 6218 dayPanel.classList.add("closeDay"); 6219 dayPanel.classList.remove("pointer"); 6220 6221 } 6222 6223 }); 6224 6225 } 6226 6227 this.getTotalTimeInOptions = function(options){ 6228 6229 var totalTimeInOptions = 0; 6230 if (options != null) { 6231 6232 for(var i = 0; i < options.length; i++) { 6233 6234 var option = options[i]; 6235 if (parseInt(option.selected) == 1) { 6236 6237 totalTimeInOptions += parseInt(option.time); 6238 6239 } 6240 6241 } 6242 6243 } 6244 6245 object._console.log("totalTimeInOptions = " + totalTimeInOptions); 6246 return totalTimeInOptions; 6247 6248 } 6249 6250 this.createSchedule = function(mainPanel, courseMainPanel, scheduleMainPanel, formMainPanel, month, day, year, calendarData, courseList, selectedOptions, accountKey, callback){ 6251 6252 var object = this; 6253 var weekName = [object._i18n.get('Sun'), object._i18n.get('Mon'), object._i18n.get('Tue'), object._i18n.get('Wed'), object._i18n.get('Thu'), object._i18n.get('Fri'), object._i18n.get('Sat')]; 6254 object._calendar = new Booking_App_Calendar(weekName, object._dateFormat, object._positionOfWeek, object._positionTimeDate, object._startOfWeek, object._i18n, object._debug); 6255 object._calendar.setClock(object._clock); 6256 var calendarKey = object._calendar.getDateKey(month, day, year); 6257 day = parseInt(day); 6258 object._console.log("day = " + day); 6259 object._console.log(calendarData); 6260 object._console.log(courseList); 6261 object._console.log(selectedOptions); 6262 var totalTimeInOptions = object.getTotalTimeInOptions(selectedOptions); 6263 object._console.log(calendarData['schedule'][calendarKey]); 6264 var timeToProvide = []; 6265 var course = null; 6266 var totalTimeInOptions = 0; 6267 if (object._courseBool == true) { 6268 6269 course = false; 6270 6271 } 6272 for (var key in courseList) { 6273 6274 if (courseList[key].selected == 1 && courseList[key].timeToProvide != null) { 6275 6276 course = true; 6277 timeToProvide.push(courseList[key].timeToProvide); 6278 6279 } 6280 6281 if (courseList[key].selected == 1 && courseList[key].selectedOptionsList.length > 0) { 6282 6283 totalTimeInOptions += object.getTotalTimeInOptions(courseList[key].selectedOptionsList); 6284 6285 } 6286 6287 } 6288 object._console.log(timeToProvide); 6289 6290 scheduleMainPanel.textContent = null; 6291 6292 var closeButton = document.createElement("button"); 6293 closeButton.id = "closeButton"; 6294 closeButton.textContent = object._i18n.get('Close'); 6295 closeButton.setAttribute("class", "button media-button button-primary button-large media-button-insert"); 6296 closeButton.setAttribute("style", "margin-left: 10px;"); 6297 object._rightButtonPanel.textContent = null; 6298 object._rightButtonPanel.appendChild(closeButton); 6299 closeButton.onclick = function() { 6300 6301 object._console.log("closeButton"); 6302 object._rightButtonPanel.textContent = null; 6303 object.editPanelShow(false); 6304 6305 }; 6306 6307 if (calendarData['schedule'][calendarKey].length == 0) { 6308 6309 console.error("error = schedule zero"); 6310 var errorPanel = document.createElement("div"); 6311 errorPanel.setAttribute("class", "noSchedule"); 6312 errorPanel.textContent = object._i18n.get("There are no time slots."); 6313 scheduleMainPanel.appendChild(errorPanel); 6314 return null; 6315 6316 } 6317 6318 var calendarKey = object._calendar.getDateKey(month, day, year); 6319 object._console.log(object._nationalHoliday[calendarKey]); 6320 var nationalHoliday = false;
6321 if (object._nationalHoliday[calendarKey] != null && parseInt(object._nationalHoliday[calendarKey].status) == 1) { 6322 6323 nationalHoliday = true; 6324 6325 } 6326 6327 for (var i = 0; i < calendarData['schedule'][calendarKey].length; i++) { 6328 6329 var schedule = calendarData['schedule'][calendarKey][i]; 6330 schedule["select"] = true; 6331 if (parseInt(schedule["remainder"]) == 0 || schedule["stop"] == 'true') { 6332 6333 schedule["select"] = false; 6334 6335 } 6336 6337 var week = parseInt(schedule.weekKey); 6338 var minutes = parseInt(schedule.hour) * 60; 6339 if (nationalHoliday == true) { 6340 6341 week = 7; 6342 6343 } 6344 6345 for (var key in timeToProvide) { 6346 6347 if (timeToProvide[key][week] != null && parseInt(timeToProvide[key][week][minutes]) == 0) { 6348 6349 schedule["select"] = false; 6350 6351 } 6352 6353 } 6354 6355 } 6356 6357 if (course != null || object._preparationTime > 0) { 6358 6359 var courseTime = 0; 6360 if (object._positionPreparationTime == 'before_after' || object._positionPreparationTime == 'after') { 6361 6362 courseTime = object._preparationTime; 6363 6364 } 6365 6366 if (course != null) { 6367 6368 //courseTime += parseInt(course["time"]) + totalTimeInOptions; 6369 var selectedService = []; 6370 for (var key in courseList) { 6371 6372 if (courseList[key].selected == 1) { 6373 6374 courseTime += parseInt(courseList[key].time); 6375 selectedService = courseList[key]; 6376 6377 } 6378 6379 } 6380 6381 courseTime += totalTimeInOptions; 6382 object._servicesControl.invalidService(calendarData['schedule'][calendarKey], calendarData['bookedServices'], selectedService, courseTime, day, month, year); 6383 6384 } else { 6385 6386 courseTime++; 6387 6388 } 6389 6390 var afterPreparationTime = 0; 6391 if (object._positionPreparationTime == 'before_after' || object._positionPreparationTime == 'before') { 6392 6393 afterPreparationTime = object._preparationTime; 6394 6395 } 6396 //var courseTime = parseInt(course["time"]) + totalTimeInOptions; 6397 object._console.log("courseTime = " + courseTime); 6398 for (var i = 0; i < calendarData['schedule'][calendarKey].length; i++) { 6399 6400 var schedule = calendarData['schedule'][calendarKey][i]; 6401 if (parseInt(schedule["remainder"]) == 0 || schedule["stop"] == 'true') { 6402 6403 schedule["select"] = false; 6404 var rejectionTime = (parseInt(schedule["hour"]) * 60 + parseInt(schedule["min"])) - courseTime; 6405 object._console.log("rejectionTime = " + rejectionTime); 6406 6407 (function(schedule, key, courseTime, rejectionTime, afterPreparationTime, callback){ 6408 6409 object._console.log(key); 6410 var stopUnixTime = parseInt(schedule[key].unixTime); 6411 stopUnixTime += afterPreparationTime * 60; 6412 object._console.log("stopUnixTime = " + stopUnixTime); 6413 6414 for (var i = 0; i < schedule.length; i++) { 6415 6416 var time = parseInt(schedule[i]["hour"]) * 60 + parseInt(schedule[i]["min"]); 6417 if (time > rejectionTime && i < key) { 6418 6419 object._console.log("i = " + i + " hour = " + schedule[i]["hour"] + " min = " + schedule[i]["min"]); 6420 callback(i); 6421 6422 } else if (parseInt(schedule[i].unixTime) <= stopUnixTime && i > key) { 6423 6424 object._console.log("i = " + i + " hour = " + schedule[i]["hour"] + " min = " + schedule[i]["min"]); 6425 callback(i); 6426 6427 } else if (parseInt(schedule[i].unixTime) >= stopUnixTime) { 6428 6429 break; 6430 6431 } 6432 6433 } 6434 6435 })(calendarData['schedule'][calendarKey], i, courseTime, rejectionTime, afterPreparationTime, function(key){ 6436 6437 object._console.log("callback key = " + key); 6438 calendarData['schedule'][calendarKey][key]["select"] = false;
6439 6440 }); 6441 6442 } 6443 6444 } 6445 6446 } 6447 6448 object._console.log("accountKey = " + accountKey); 6449 object._console.log(object._schedule_data.calendarAccountList); 6450 var displayRemainingCapacity = 0; 6451 var calendarAccountList = object._schedule_data.calendarAccountList; 6452 for (var i = 0; i < calendarAccountList.length; i++) { 6453 6454 if (parseInt(calendarAccountList[i].key) == parseInt(accountKey) && parseInt(calendarAccountList[i].displayRemainingCapacity) == 1) { 6455 6456 displayRemainingCapacity = 1; 6457 break; 6458 6459 } 6460 6461 } 6462 object._console.log("displayRemainingCapacity = " + displayRemainingCapacity); 6463 6464 var scheduleListPanel = []; 6465 for (var i = 0; i < calendarData['schedule'][calendarKey].length; i++) { 6466 6467 var schedule = calendarData['schedule'][calendarKey][i]; 6468 if (typeof schedule['title'] == "string") { 6469 6470 schedule['title'] = schedule['title'].replace(/\\/g, ""); 6471 6472 } 6473 object._console.log(schedule); 6474 6475 var schedulePanel = document.createElement("div"); 6476 schedulePanel.textContent = object._calendar.getPrintTime(("0" + schedule["hour"]).slice(-2), ("0" + schedule["min"]).slice(-2)) + " " + schedule['title']; 6477 //schedulePanel.textContent = ("0" + schedule["hour"]).slice(-2) + ":" + ("0" + schedule["min"]).slice(-2) + " " + schedule['title']; 6478 schedulePanel.setAttribute("data-key", i); 6479 6480 6481 if (displayRemainingCapacity == 1) { 6482 6483 var displayRemainingCapacityLabel = document.createElement("span"); 6484 displayRemainingCapacityLabel.classList.add("displayRemainingCapacityLabel"); 6485 //displayRemainingCapacityLabel.textContent = object._i18n.get("%s remaining", [schedule.remainder]); 6486 displayRemainingCapacityLabel.textContent = object._i18n.get("%s Slots Left", [schedule.remainder]); 6487 schedulePanel.appendChild(displayRemainingCapacityLabel); 6488 6489 } 6490 6491 scheduleListPanel.push(schedulePanel); 6492 6493 if (schedule["select"] === true) { 6494 6495 schedulePanel.setAttribute("data-status", 1); 6496 schedulePanel.setAttribute("class", "courseAndScheduleRow"); 6497 schedulePanel.onclick = function(){ 6498 6499 closeButton.setAttribute("class", "hidden_panel"); 6500 this.setAttribute("class", "courseAndScheduleRow courseAndScheduleRowActive"); 6501 var key = this.getAttribute("data-key"); 6502 var schedule = calendarData['schedule'][calendarKey][key]; 6503 6504 var startUnixTime = parseInt(schedule.unixTime); 6505 var endUnixTime = startUnixTime + (parseInt(courseTime) * 60); 6506 object.unselectPanel(key, scheduleListPanel, "selectPanel"); 6507 object._console.log('courseTime = ' + courseTime); 6508 object._console.log('startUnixTime = ' + startUnixTime); 6509 object._console.log('endUnixTime = ' + endUnixTime); 6510 object._console.log(courseList); 6511 if (object.getGuestsList().length > 0) { 6512 6513 var remainders = []; 6514 for (var scheduleKey in calendarData['schedule'][calendarKey]) { 6515 6516 var unixTime = parseInt(calendarData['schedule'][calendarKey][scheduleKey].unixTime); 6517 if (startUnixTime <= unixTime && endUnixTime > unixTime) { 6518 6519 remainders.push(parseInt(calendarData['schedule'][calendarKey][scheduleKey].remainder)); 6520 object._console.log(calendarData['schedule'][calendarKey][scheduleKey]); 6521 6522 } 6523 6524 6525 } 6526 object._console.log(remainders); 6527 var remainder = parseInt(schedule.remainder); 6528 if (remainders.length > 0) { 6529 6530 remainder = remainders.reduce(function(a, b) { 6531 6532 return Math.min(a, b); 6533 6534 }); 6535 6536 } 6537 6538 object._console.log('remainder = ' + remainder); 6539 object.setMaxApplicantCount(remainder); 6540 6541 } 6542 6543 6544 object.unselectPanel(key, scheduleListPanel, "courseAndScheduleRow"); 6545 object.createForm(mainPanel, courseMainPanel, scheduleMainPanel, formMainPanel, month, day, year, calendarData, courseList, schedule, selectedOptions, accountKey, function(response){ 6546 6547 if (response.action == 'return') { 6548 6549 closeButton.setAttribute("class", "button media-button button-primary button-large media-button-insert"); 6550 object._console.log(response.action); 6551 6552 } else if (response.action == 'refresh') { 6553 6554 callback(response) 6555 6556 } 6557 6558 }); 6559 6560 } 6561 6562 } else { 6563 6564 schedulePanel.setAttribute("data-status", 0); 6565 schedulePanel.setAttribute("class", "courseAndScheduleRowError"); 6566 6567 } 6568 6569 var table_row = document.createElement("div"); 6570 table_row.appendChild(schedulePanel); 6571 6572 scheduleMainPanel.appendChild(table_row); 6573 6574 } 6575 6576 return scheduleMainPanel; 6577 6578 } 6579 6580 6581 this.createForm = function(mainPanel, courseMainPanel, scheduleMainPanel, formMainPanel, month, day, year, calendarData, courseList, schedule, selectedOptions, accountKey, callback){ 6582 6583 var object = this; 6584 object._console.log("accountKey = " + accountKey); 6585 object._console.log(object._formData); 6586 object._console.log(day); 6587 object._console.log(calendarData); 6588 object._console.log(courseList); 6589 object._console.log(schedule); 6590 object._console.log(selectedOptions); 6591 6592 var targetCustomers = 'visitors'; 6593 var user = object.getUserInformation(); 6594 object._console.log(user); 6595 var totalTimeInOptions = object.getTotalTimeInOptions(selectedOptions); 6596 var input = new Booking_Package_Input(object._debug); 6597 formMainPanel.textContent = null; 6598 //buttonPanel.textContent = null; 6599 var children = object._rightButtonPanel.children; 6600 for (var i = children.length; i > 0; i--) { 6601 6602 if (children[i - 1].id != 'closeButton') { 6603 object._rightButtonPanel.removeChild(children[i - 1]); 6604 } 6605 6606 } 6607 6608 var returnButton = null; 6609 if (object._courseBool == true) { 6610 6611 mainPanel.setAttribute("class", "courseAndSchedulePanel_next"); 6612 6613 returnButton = document.createElement("button"); 6614 returnButton.id = "returnButton"; 6615 returnButton.textContent = object._i18n.get('Return'); 6616 returnButton.setAttribute("class", "button media-button button-primary button-large media-button-insert"); 6617 returnButton.setAttribute("style", "margin-left: 10px;"); 6618 object._rightButtonPanel.appendChild(returnButton); 6619 6620 6621 } else { 6622 6623 if (calendarData.account.type == "hotel") { 6624 6625 mainPanel.setAttribute("class", "courseAndSchedulePanel_next"); 6626 scheduleMainPanel.setAttribute("class", "schedulePanel_next"); 6627 6628 } else { 6629 6630 mainPanel.setAttribute("class", "courseAndSchedulePanel_next_no_course"); 6631 //scheduleMainPanel.setAttribute("class", "schedulePanel_next"); 6632 6633 } 6634 6635 } 6636 6637 //formMainPanel.setAttribute("class", "courseListPanel box_shadow show_panel"); 6638 formMainPanel.setAttribute("class", "createFormPanel_show box_shadow show_panel_for_new_booking test"); 6639 /** 6640 if(calendarData.account.type == "day"){ 6641 6642 formMainPanel.setAttribute("class", "createFormPanel_show box_shadow show_panel"); 6643 6644 }else{ 6645 6646 formMainPanel.setAttribute("class", "createFormPanel_show box_shadow"); 6647 6648 } 6649 **/ 6650 6651 var bookingButton = document.createElement("button"); 6652 bookingButton.textContent = object._i18n.get('Book Now'); 6653 bookingButton.setAttribute("class", "button media-button button-primary button-large media-button-insert"); 6654 bookingButton.setAttribute("style", "margin-left: 10px;"); 6655 object._rightButtonPanel.appendChild(bookingButton); 6656 6657 var formPanel = document.createElement("div"); 6658 formPanel.id = "inputFormPanel"; 6659 formMainPanel.appendChild(formPanel); 6660 6661 var monthFull = object._monthFullName[parseInt(calendarData.date.month)]; 6662 //var date = monthFull + " " + ("0" + day).slice(-2) + ", " + calendarData.date.year + " " + ("0" + schedule.hour).slice(-2) + ":" + ("0" + schedule.min).slice(-2) + " " + schedule.title; 6663 6664 var weekName = [object._i18n.get('Sun'), object._i18n.get('Mon'), object._i18n.get('Tue'), object._i18n.get('Wed'), object._i18n.get('Thu'), object._i18n.get('Fri'), object._i18n.get('Sat')]; 6665 object._calendar = new Booking_App_Calendar(weekName, object._dateFormat, object._positionOfWeek, object._positionTimeDate, object._startOfWeek, object._i18n, object._debug); 6666 object._calendar.setClock(object._clock); 6667 var calendarKey = object._calendar.getDateKey(month, day, year); 6668 6669 if (parseInt(object._isExtensionsValid) == 1) { 6670 6671 var lookForUserIcon = document.createElement('div'); 6672 lookForUserIcon.textContent = 'search'; 6673 6674 var lookForUserButton = document.createElement('div'); 6675 lookForUserButton.setAttribute('class', 'material-icons lookForUserButton'); 6676 //lookForUserButton.textContent = 'search supervisor_account'; 6677 lookForUserButton.appendChild(lookForUserIcon); 6678 formPanel.appendChild(lookForUserButton); 6679 lookForUserButton.onclick = function() { 6680 6681 object._console.log('onclick'); 6682 object.lookForUser(function(user) { 6683 6684 object.setUserInformation(user); 6685 object.createForm(mainPanel, courseMainPanel, scheduleMainPanel, formMainPanel, month, day, year, calendarData, courseList, schedule, selectedOptions, accountKey, callback); 6686 6687 }); 6688 6689 }; 6690 6691 } 6692 6693 var totalCost = 0; 6694 if(schedule != null){ 6695 6696 var date = object._calendar.formatBookingDate(calendarData.date.month, day, calendarData.date.year, schedule.hour, schedule.min, schedule.title, schedule.weekKey, 'text'); 6697 var rowPanel = object.createRowPanel(object._i18n.get("Booking Date"), date, null, null, null); 6698 formPanel.appendChild(rowPanel); 6699 totalCost = parseInt(schedule.cost); 6700 6701 } 6702 6703 if (user.meta != null) { 6704 6705 object._console.log(user); 6706 object._console.log(user.meta); 6707 targetCustomers = 'users'; 6708 input.setUserEmail(user.user_email); 6709 input.setUserInformation(user.meta); 6710 var usernamePanel = object.createRowPanel(object._i18n.get("Username"), user.user_login, null, null, null); 6711 var deleteUserButton = document.createElement('div'); 6712 deleteUserButton.textContent = 'close'; 6713 deleteUserButton.classList.add('material-icons'); 6714 deleteUserButton.classList.add('deleteUserButton'); 6715 deleteUserButton.onclick = function() { 6716 6717 object.setUserInformation(null); 6718 object.createForm(mainPanel, courseMainPanel, scheduleMainPanel, formMainPanel, month, day, year, calendarData, courseList, schedule, selectedOptions, accountKey, callback); 6719 6720 }; 6721 usernamePanel.insertAdjacentElement('afterbegin', deleteUserButton); 6722 formPanel.appendChild(usernamePanel); 6723 6724 } 6725 object._console.log('targetCustomers = ' + targetCustomers); 6726 6727 if (calendarData.account.type == "hotel") { 6728 6729 formMainPanel.classList.remove("show_panel"); 6730 //scheduleMainPanel.classList.remove("schedulePanel_next"); 6731 scheduleMainPanel.setAttribute("style", "animation-name: unset;"); 6732 mainPanel.setAttribute("style", "animation-name: unset;"); 6733 var schedule = calendarData.schedule[parseInt(calendarKey)][0]; 6734 if (object._hotel.getCheckDate().checkIn != null) { 6735 6736 schedule = object._hotel.getCheckDate().checkIn; 6737 6738 } 6739 object._console.log(schedule); 6740 if (schedule == null) { 6741 6742 return null; 6743 6744 } 6745 bookingButton.disabled = true; 6746 var style = null; 6747 var date = object._calendar.formatBookingDate(schedule.month, schedule.day, schedule.year, null, null, null, schedule.weekKey, 'text'); 6748 if (schedule.remainder <= 0) { 6749 6750 style = "color: red;"; 6751 date = object._i18n.get("There is no rooms to booking"); 6752 object._hotel.resetCheckDate(); 6753 6754 } else if (schedule.stop == 'true') { 6755 6756 style = "color: red;"; 6757 date = object._i18n.get("The booking reception is suspended"); 6758 object._hotel.resetCheckDate(); 6759 6760 } else { 6761 6762 object._hotel.setCheckIn(schedule); 6763 object._hotel.setCheckInKey(schedule.key); 6764 6765 } 6766 6767 var checkInClear = document.createElement("label"); 6768 checkInClear.textContent = object._i18n.get("Clear"); 6769 checkInClear.classList.add("change"); 6770 checkInClear.id = "checkInClear"; 6771 6772 var expressionsCheck = object._calendar.getExpressionsCheck(calendarData.account, false); 6773 6774 var checkIn = object.createRowPanel(expressionsCheck.arrival, date, "checkIn", "true", checkInClear); 6775 formPanel.appendChild(checkIn); 6776 document.getElementById("checkIn").setAttribute("data-check", schedule.key); 6777 document.getElementById("checkIn").setAttribute("data-unixTime", schedule.unixTime); 6778 document.getElementById("checkIn").setAttribute("style", style); 6779 6780 var checkOutClear = document.createElement("label"); 6781 checkOutClear.textContent = object._i18n.get("Clear"); 6782 checkOutClear.classList.add("change"); 6783 checkOutClear.classList.add("hidden_panel"); 6784 var checkOut = object.createRowPanel(expressionsCheck.departure, expressionsCheck.chooseDeparture, "checkOut", "true",
6784 checkOutClear); 6785 //document.getElementById("checkOut").setAttribute("data-check", ""); 6786 formPanel.appendChild(checkOut); 6787 6788 var totalLengthOfStayValue = document.createElement("div"); 6789 totalLengthOfStayValue.id = "totalLengthOfStayValue"; 6790 totalLengthOfStayValue.textContent = 0; 6791 6792 var totalLengthOfStay = object.createRowPanel(object._i18n.get("Total Length of Stay"), totalLengthOfStayValue, null, null, null); 6793 formPanel.appendChild(totalLengthOfStay); 6794 6795 var roomListPanel = document.createElement('div'); 6796 roomListPanel.id = 'roomListPanel'; 6797 roomListPanel.classList.add('roomListPanel'); 6798 formPanel.appendChild(roomListPanel); 6799 var totalNumberOfGuests = object.createRowPanel(object._i18n.get("Total Number of Guests"), "0", "totalGuests", null, null); 6800 object._console.log(calendarData.guestsList); 6801 var hotelOptions = object.getHotelOptions(); 6802 var guestsList = calendarData.guestsList; 6803 var roomPanel = object.addGuestsForRoom(guestsList, hotelOptions, input, totalNumberOfGuests, 0, object._calendarAccount.multipleRooms, false, bookingButton); 6804 roomListPanel.appendChild(roomPanel); 6805 6806 if (parseInt(object._calendarAccount.multipleRooms) == 1) { 6807 6808 roomListPanel.setAttribute('style', 'border-bottom-width: 0;'); 6809 object._console.log('multipleRooms = ' + object._calendarAccount.multipleRooms); 6810 var addRoomButton = document.createElement('label'); 6811 addRoomButton.id = 'addRoomButton'; 6812 addRoomButton.classList.add('addRoomButton'); 6813 addRoomButton.textContent = object._i18n.get('Add a new room'); 6814 addRoomButton.onclick = function(event) { 6815 6816 bookingButton.disabled = true; 6817 var visitorDetails = object._hotel.getDetails(); 6818 object._console.log(visitorDetails); 6819 if (visitorDetails.applicantCount < visitorDetails.vacancy) { 6820 6821 var roomNumber = object._hotel.getNewRoomNumber(); 6822 object._console.log('roomNumber = ' + roomNumber); 6823 var roomPanel = object.addGuestsForRoom(guestsList, hotelOptions, input, totalNumberOfGuests, roomNumber, parseInt(object._calendarAccount.multipleRooms), true, bookingButton); 6824 roomListPanel.insertAdjacentElement("beforeend", roomPanel); 6825 object._hotel.addedRoom(); 6826 object.updateRoomNumber(); 6827 6828 } 6829 6830 }; 6831 6832 var addRoomPanel = document.createElement('div'); 6833 addRoomPanel.classList.add('row'); 6834 formPanel.insertAdjacentElement("beforeend", addRoomPanel); 6835 addRoomPanel.appendChild(addRoomButton); 6836 6837 6838 } 6839 6840 var feeList = object._hotel.getSubtotals(); 6841 formPanel.appendChild(totalNumberOfGuests); 6842 6843 var summaryListPanel = document.createElement("div"); 6844 summaryListPanel.id = "summaryListPanel"; 6845 var summaryPanel = object.createRowPanel(object._i18n.get("Summary"), summaryListPanel, "summaryPanel", null, null); 6846 formPanel.appendChild(summaryPanel); 6847 6848 object._console.log("guestsList.length = " + guestsList.length); 6849 if (guestsList.length == 0) { 6850 6851 totalNumberOfGuests.classList.add("hidden_panel"); 6852 6853 } 6854 6855 var formatPrice = object._format.formatCost(0, object._currency); 6856 var rowPanel = object.createRowPanel(object._i18n.get("Total Amount"), formatPrice, "totalPrice", null, null); 6857 formPanel.appendChild(rowPanel); 6858 6859 object._hotel.setCallback(function(response){ 6860 6861 object._console.log(response); 6862 6863 var checkDate = object._hotel.getCheckDate(); 6864 object._console.log(checkDate); 6865 if (checkDate.checkIn == null) { 6866 6867 var checkIn = document.getElementById("checkIn"); 6868 checkIn.textContent = expressionsCheck.chooseArrival; 6869 6870 } 6871 6872 if (checkDate.checkOut == null) { 6873 6874 var checkOut = document.getElementById("checkOut"); 6875 checkOut.setAttribute("data-check", null); 6876 checkOut.textContent = expressionsCheck.chooseDeparture; 6877 if (checkDate.checkIn != null) { 6878 6879 var dataKey = object._calendar.getDateKey(checkDate.checkIn.month, checkDate.checkIn.day, checkDate.checkIn.year); 6880 var dayPanelList = object._hotel.getDayPanelList(); 6881 for (var key in dayPanelList) { 6882 6883 if (dataKey != key) { 6884 6885 dayPanelList[key].classList.remove("selected_day_slot"); 6886 6887 } 6888 6889 } 6890 6891 } 6892 6893 } 6894 6895 var feeList = object._hotel.getSubtotals(); 6896 totalCost = response.amount; 6897 object._hotel.showSummary(summaryListPanel, expressionsCheck); 6898 var nightsValue = response.nights + " " + object._i18n.get('nights'); 6899 if (parseInt(object._calendarAccount.formatNightDay) == 1) { 6900 6901 nightsValue = object._i18n.get("%s nights %s days", [response.nights, response.nights + 1]); 6902 6903 } 6904 6905 if (response.nights == 1) { 6906 6907 nightsValue = response.nights + " " + object._i18n.get('night'); 6908 if (parseInt(object._calendarAccount.formatNightDay) == 1) { 6909 6910 nightsValue = object._i18n.get("%s night %s days", [response.nights, response.nights + 1]); 6911 6912 } 6913 6914 } 6915 document.getElementById("totalLengthOfStayValue").textContent = nightsValue; 6916 6917 var totalNumberOfGuests = 0; 6918 var additionalFee = 0; 6919 var personAmount = 0;
6920 for (var roomKey in response.rooms) { 6921 6922 var room = response.rooms[roomKey]; 6923 totalNumberOfGuests += room.person; 6924 additionalFee += room.additionalFee; 6925 personAmount += room.personAmount; 6926 6927 } 6928 6929 var totalNumberOfGuestsValue = 0; 6930 if (totalNumberOfGuests > 1) { 6931 6932 totalNumberOfGuestsValue = totalNumberOfGuests + " " + object._i18n.get("people"); 6933 6934 } else if (totalNumberOfGuests == 1) { 6935 6936 totalNumberOfGuestsValue = totalNumberOfGuests + " " + object._i18n.get("person"); 6937 6938 } 6939 6940 document.getElementById("totalGuests").textContent = totalNumberOfGuestsValue; 6941 6942 /** 6943 var taxAmount = 0; 6944 for (var key in response.taxes) { 6945 6946 if ((response.taxes[key].type == 'tax' && response.taxes[key].tax == 'tax_exclusive') || response.taxes[key].type == 'surcharge') { 6947 //if (response.taxes[key].tax == 'tax_exclusive') { 6948 6949 taxAmount += response.taxes[key].taxValue; 6950 6951 } 6952 6953 } 6954 6955 var totalPrice = (response.amount * response.applicantCount) + taxAmount + (additionalFee * response.nights); 6956 if (personAmount > 0) { 6957 6958 object._console.log('personAmount = ' + personAmount); 6959 totalPrice = (response.amount * response.applicantCount) + taxAmount + personAmount; 6960 6961 } 6962 **/ 6963 6964 var totalPrice = object._hotel.getTotalAmount(); 6965 6966 document.getElementById("totalPrice").textContent = object._format.formatCost(totalPrice, object._currency); 6967 var verifyGuests = object._hotel.verifyGuestsInRooms(response.rooms); 6968 object._console.log(verifyGuests) 6969 if (verifyGuests.booking == false || response.nights == 0 || verifyGuests.requiredGuests == false || verifyGuests.requiredOptions == false) { 6970 6971 bookingButton.disabled = true; 6972 6973 } else { 6974 6975 bookingButton.disabled = false; 6976 6977 } 6978 6979 }); 6980 6981 checkInClear.onclick = function(){ 6982 6983 this.classList.add("hidden_panel"); 6984 var dayPanelList = object._hotel.getDayPanelList(); 6985 for (var key in dayPanelList) { 6986 6987 dayPanelList[key].classList.remove("selected_day_slot"); 6988 6989 } 6990 6991 object._hotel.setCheckIn(null); 6992 object._hotel.setCheckInKey(null) 6993 object._hotel.setCheckOut(null); 6994 object._hotel.setCheckOutKey(null); 6995 object._hotel.verifySchedule(true); 6996 6997 }; 6998 6999 checkOutClear.onclick = function(){ 7000 7001 7002 7003 }; 7004 7005 } else { 7006 7007 var goodsList = []; 7008 if (parseInt(object._calendarAccount.guestsBool) == 1) { 7009 7010 var guestRole = {multipleApplicantCountList: [], reflectService: [], reflectAdditional: []}; 7011 var multipleApplicantCount = 0; 7012 var multipleApplicantCountList = []; 7013 var maxApplicantCount = object.getMaxApplicantCount(); 7014 object._console.log(maxApplicantCount); 7015 var guestsList = object.getGuestsList(); 7016 object._console.log(guestsList); 7017 for (var key in guestsList) { 7018 7019 multipleApplicantCountList.push(0); 7020 guestRole.multipleApplicantCountList.push(0); 7021 guestRole.reflectService.push(0);
7022 guestRole.reflectAdditional.push(0); 7023 var guests = guestsList[key]; 7024 object._console.log(guests); 7025 var list = guestsList[key].json; 7026 if (typeof guestsList[key].json == 'string') { 7027 7028 list = JSON.parse(guestsList[key].json); 7029 7030 } 7031 7032 var values = {}; 7033 for (var i = 0; i < list.length; i++) { 7034 7035 if (maxApplicantCount >= parseInt(list[i].number) && guests.guestsInCapacity == 'included') { 7036 7037 //values.push(list[i].name); 7038 values[i] = list[i].name; 7039 7040 } else if (guests.guestsInCapacity != 'included') { 7041 7042 //values.push(list[i].name); 7043 values[i] = list[i].name; 7044 7045 } 7046 7047 } 7048 7049 guestsList[key].id = 'guests_' + guests.key 7050 guestsList[key].values = values; 7051 guestsList[key].type = "SELECT"; 7052 guestsList[key].value = 0; 7053 guestsList[key].index = 0; 7054 guestsList[key].number = 0; 7055 guestsList[key].person = 0; 7056 object._console.log(list); 7057 7058 var guestsInput = new Booking_Package_Input(object._debug); 7059 guestsInput.setPrefix(object._prefix); 7060 var guestsSelectPanel = guestsInput.createInput(guestsList[key]['name'].replace(/\\/g, ""), guestsList[key], {}, function(event){ 7061 7062 var selectBox = this; 7063 object._console.log(selectBox); 7064 multipleApplicantCount = object._servicesControl.getSelectedGuest(guestsList, selectBox, multipleApplicantCountList); 7065 const totalAmountForGuests = object._servicesControl.getSelectedGuestTotalAmount(guestsList, selectBox, multipleApplicantCountList); 7066 object._console.log(multipleApplicantCountList); 7067 object._console.log(multipleApplicantCount); 7068 const remainedCount = maxApplicantCount - multipleApplicantCount; 7069 for (var guestsKey in guestsList) { 7070 7071 const guest = guestsList[guestsKey]; 7072 if (guestsList[guestsKey].guestsInCapacity == 'included') { 7073 7074 document.getElementById(object._prefix + 'guests_' + guestsList[guestsKey].key).classList.remove('error_empty_value'); 7075 var select = document.getElementById(object._prefix + 'input_guests_' + guestsList[guestsKey].key); 7076 const options = JSON.parse(guest.json); 7077 const guestOptions = select.options; 7078 object._console.log(select); 7079 7080 for (let i = 0; i < guestOptions.length; i++) { 7081 7082 guestOptions[i].disabled = false; 7083 if (options[i].number > (remainedCount + parseInt(guest.number))) { 7084 7085 //console.error(guestOptions[i]); 7086 guestOptions[i].disabled = true; 7087 7088 } else { 7089 7090 guestOptions[i].disabled = false; 7091 7092 } 7093 7094 } 7095 7096 7097 7098 } 7099 7100 } 7101 if (multipleApplicantCount > maxApplicantCount && guests.guestsInCapacity == 'included') { 7102 7103 parentPanel.classList.add('error_empty_value'); 7104 7105 } 7106 7107 goodsList = []; 7108 //object.setGoodsList(goodsList); 7109 object._console.log(object._courseBool); 7110 totalCost = parseInt(schedule.cost); 7111 if (object._courseBool == true || object._calendarAccount.flowOfBooking == 'services') { 7112 7113 var coursePanel = document.getElementById(object._prefix + 'selectedServicesPanel'); 7114 coursePanel.textContent = null; 7115 //var response = object.selectedServicesPanel(course, courseList, goodsList, totalCost, coursePanel, true); 7116 var response = object.createServicesPanel(coursePanel, courseList, "selectedOptionsList", guestsList, parseInt(object._calendarAccount.guestsBool), goodsList, object._currency, true); 7117 object._console.log(response); 7118 goodsList = response.goodsList; 7119 totalCost += response.totalCost; 7120 7121 } 7122 7123 totalCost += totalAmountForGuests.totalAmount; 7124 7125 var responseGuests = object._servicesControl.getValueReflectGuests(guestsList); 7126 object._console.log(responseGuests); 7127 7128 var totalNumberOfGuestsPanel = document.getElementById(object._prefix + 'totalNumberOfGuests'); 7129 var totalNumberOfGuestsValuePanel = totalNumberOfGuestsPanel.getElementsByClassName('value')[0]; 7130 var totalNumberOfGuestsErrorPanel = totalNumberOfGuestsPanel.getElementsByClassName('errorMessage')[0]; 7131 //totalNumberOfGuestsValuePanel.textContent = responseGuests.totalNumberOfGuestsTitle; 7132 7133 const totalGuestsLabel = document.createElement('div'); 7134 totalGuestsLabel.textContent = responseGuests.totalNumberOfGuestsTitle; 7135 totalNumberOfGuestsValuePanel.textContent = null; 7136 totalNumberOfGuestsValuePanel.appendChild(totalGuestsLabel); 7137 if (totalAmountForGuests.labeles.length > 0) { 7138 7139 if (totalAmountForGuests.totalAmount > 0) { 7140 7141 const totalNumberOfGuestsLabel = document.createElement('span'); 7142 totalNumberOfGuestsLabel.classList.add('serviceName'); 7143 totalNumberOfGuestsLabel.textContent = responseGuests.totalNumberOfGuestsTitle; 7144 7145 const totalAmountGuestsLabel = document.createElement('span'); 7146 totalAmountGuestsLabel.classList.add('serviceCost'); 7147 totalAmountGuestsLabel.textContent = object._format.formatCost(totalAmountForGuests.totalAmount, object._currency); 7148 7149 totalGuestsLabel.textContent = null; 7150 totalGuestsLabel.appendChild(totalNumberOfGuestsLabel); 7151 totalGuestsLabel.appendChild(totalAmountGuestsLabel); 7152 7153 } 7154 7155 const guestsDetailsPanel = document.createElement('div'); 7156 guestsDetailsPanel.setAttribute('class', 'costPerGuests hidden_panel'); 7157 for (var i = 0; i < totalAmountForGuests.labeles.length; i++) { 7158 7159 const gusetDetailsLabel = document.createElement('div'); 7160 gusetDetailsLabel.textContent = totalAmountForGuests.labeles[i]; 7161 guestsDetailsPanel.appendChild(gusetDetailsLabel); 7162 console.log(gusetDetailsLabel); 7163 7164 } 7165 7166 totalNumberOfGuestsValuePanel.appendChild(guestsDetailsPanel); 7167 totalGuestsLabel.classList.add('addedGuests_click'); 7168 totalGuestsLabel.onclick = function(event) { 7169 7170 if (guestsDetailsPanel.classList.contains('hidden_panel') === true) { 7171 7172 guestsDetailsPanel.classList.remove('hidden_panel'); 7173 7174 } else { 7175 7176 guestsDetailsPanel.classList.add('hidden_panel'); 7177 7178 } 7179 7180 }; 7181 7182 } 7183 7184 7185 var responseLimitGuests = object._servicesControl.verifyToLimitGuests(responseGuests, object._calendarAccount.limitNumberOfGuests, object._calendarAccount.type); 7186 object._console.log(responseLimitGuests); 7187 if (responseLimitGuests.isGuests === true) { 7188 7189 totalNumberOfGuestsPanel.classList.remove('error_empty_value'); 7190 totalNumberOfGuestsErrorPanel.classList.add('hidden_panel'); 7191 totalNumberOfGuestsErrorPanel.textContent = null; 7192 7193 } else { 7194 7195 totalNumberOfGuestsPanel.classList.add('error_empty_value'); 7196 totalNumberOfGuestsErrorPanel.classList.remove('hidden_panel'); 7197 totalNumberOfGuestsErrorPanel.textContent = responseLimitGuests.errorMessage; 7198 7199 } 7200 7201 var surchargePanel = document.getElementById(object._prefix + 'surchargeTaxPanel'); 7202 var taxes = new TAXES(object._i18n, object._currency, object._debug, object._numberFormatter, object._currency_info); 7203 taxes.setBooking_App_ObjectsControl(object._servicesControl); 7204 taxes.setTaxes(object._taxes); 7205 var isTaxes = taxes.taxesDetails(totalCost, formPanel, surchargePanel, null, responseGuests); 7206 if (isTaxes.isTaxes === true) { 7207 7208 var responseTaxes = taxes.getTaxes(); 7209 var reflectAdditional = 1; 7210 if (responseGuests != null) { 7211 7212 reflectAdditional = responseGuests.reflectAdditional; 7213 7214 } 7215 object._console.log('reflectAdditional = ' + reflectAdditional); 7216 totalCost += taxes.reflectTaxesInTotalCost(responseTaxes, goodsList, reflectAdditional); 7217 7218 } 7219 object._console.log(goodsList); 7220 object._console.log('totalCost = ' + totalCost); 7221 if (totalCost > 0) { 7222 7223 var formatPrice = object._format.formatCost(totalCost, object._currency); 7224 var totalCostPanel = document.getElementById(object._prefix + 'totalCost'); 7225 totalCostPanel.classList.remove('hidden_panel'); 7226 var valuePanel = totalCostPanel.getElementsByClassName('value')[0]; 7227 valuePanel.textContent = formatPrice; 7228 7229 } else { 7230 7231 var totalCostPanel = document.getElementById(object._prefix + 'totalCost'); 7232 if (totalCostPanel != null) { 7233 7234 totalCostPanel.classList.add('hidden_panel'); 7235 7236 } 7237 7238 } 7239 7240 }); 7241 7242 guestsSelectPanel.setAttribute("data-guset", key); 7243 var rowPanel = object.createRowPanel(guests.name, guestsSelectPanel, guests.key, parseInt(guests.required), null); 7244 rowPanel.id = object._prefix + 'guests_' + guests.key; 7245 formPanel.appendChild(rowPanel); 7246 7247 } 7248 7249 var rowPanel = object.createRowPanel(this._i18n.get("Total Number of Guests"), 0, null, null, null); 7250 rowPanel.id = object._prefix + 'totalNumberOfGuests'; 7251 rowPanel.classList.add("total_amount"); 7252 var errorMessage = document.createElement('div'); 7253 errorMessage.classList.add('errorMessage'); 7254 errorMessage.classList.add('hidden_panel'); 7255 rowPanel.appendChild(errorMessage); 7256 formPanel.appendChild(rowPanel); 7257 7258 } 7259 7260 7261 if (object._courseBool == true) { 7262 7263 var rowPanel = object.createRowPanel(object._courseName, "", null, null, null); 7264 var valuePanel = rowPanel.getElementsByClassName("value")[0]; 7265 valuePanel.textContent = null; 7266 7267 var guestsList = object.getGuestsList(); 7268 var coursePanel = document.createElement("div"); 7269 coursePanel.classList.add("mainPlan"); 7270 coursePanel.id = object._prefix + 'selectedServicesPanel'; 7271 valuePanel.appendChild(coursePanel); 7272 var response = object.createServicesPanel(coursePanel, courseList, "selectedOptionsList", guestsList, parseInt(object._calendarAccount.guestsBool), goodsList, object._currency, true); 7273 object._console.log(response); 7274 goodsList = response.goodsList; 7275 totalCost += response.totalCost; 7276 formPanel.appendChild(rowPanel); 7277 7278 } 7279 7280 var taxes = new TAXES(object._i18n, object._currency, object._debug, object._numberFormatter, object._currency_info); 7281 var surchargePanel = taxes.createExtraChargesAndTaxesElement(object._prefix + "surchargeTaxPanel"); 7282 /** 7283 var surchargePanel = object.createRowPanel("Surcharge", "", null, null, null); 7284 surchargePanel.id = object._prefix + "surchargeTaxPanel";
7285 **/ 7286 var taxePanel = object.createRowPanel("Tax", "", null, null, null); 7287 7288 taxes.setBooking_App_ObjectsControl(object._servicesControl); 7289 taxes.setTaxes(object._taxes); 7290 var isTaxes = taxes.taxesDetails(totalCost, formPanel, surchargePanel, taxePanel, null); 7291 object._console.log(isTaxes); 7292 if (isTaxes.isTaxes === true) { 7293 7294 formPanel.appendChild(isTaxes.surchargePanel); 7295 var responseTaxes = taxes.getTaxes(); 7296 totalCost += taxes.reflectTaxesInTotalCost(responseTaxes, goodsList, 1); 7297 7298 } 7299 7300 object._console.log("totalCost = " + totalCost); 7301 var formatPrice = object._format.formatCost(0, object._currency); 7302 var totalCostPanel = object.createRowPanel(object._i18n.get("Total Amount"), formatPrice, "bookingFee", null, null); 7303 totalCostPanel.id = object._prefix + 'totalCost'; 7304 totalCostPanel.classList.add('hidden_panel'); 7305 formPanel.appendChild(totalCostPanel); 7306 if (totalCost != 0) { 7307 7308 totalCostPanel.classList.remove('hidden_panel'); 7309 formatPrice = object._format.formatCost(totalCost, object._currency); 7310 var valuePanel = totalCostPanel.getElementsByClassName('value')[0]; 7311 valuePanel.textContent = formatPrice; 7312 7313 } 7314 7315 } 7316 7317 var formPanelList = {}; 7318 var inputData = {}; 7319 7320 for (var i = 0; i < object._formData.length; i++) { 7321 7322 object._formData[i].active = object._formData[i].originalActive; 7323 if (targetCustomers == 'visitors' && object._formData[i].targetCustomers != null && object._formData[i].targetCustomers == 'users') { 7324 7325 object._formData[i].active = ''; 7326 7327 } else if (targetCustomers == 'users' && object._formData[i].targetCustomers != null && object._formData[i].targetCustomers == 'visitors') { 7328 7329 object._formData[i].active = ''; 7330 7331 } 7332 7333 7334 if (object._formData[i].active != 'true') { 7335 7336 continue; 7337 7338 } 7339 7340 var value = input.createInput(i, object._formData[i], inputData, null); 7341 var rowPanel = object.createRowPanel(object._formData[i]['name'], value, object._formData[i].id, object._formData[i].required, null); 7342 formPanelList[i] = rowPanel; 7343 7344 formPanel.appendChild(rowPanel); 7345 7346 } 7347 7348 7349 if(returnButton != null){ 7350 7351 returnButton.onclick = function(){ 7352 7353 object._console.log("returnButton onclick"); 7354 if(returnButton != null){object._rightButtonPanel.removeChild(returnButton);} 7355 object._rightButtonPanel.removeChild(bookingButton); 7356 mainPanel.setAttribute("class", "courseAndSchedulePanel_return"); 7357 //formMainPanel.setAttribute("class", "courseListPanel"); 7358 formMainPanel.setAttribute("class", "createFormPanel_return return_panel_for_new_booking"); 7359 callback({action: 'return'}); 7360 var timer = setInterval(function(){ 7361 7362 formMainPanel.textContent = null; 7363 clearInterval(timer); 7364 7365 }, 500); 7366 7367 }; 7368 7369 } 7370 7371 bookingButton.onclick = function(){ 7372 7373 object._console.log(object._emailEnableList); 7374 object._console.log("enable = " + Boolean(parseInt(object._emailEnableList.new_booking_notification.enable))); 7375 7376 var enable = false; 7377 if (Boolean(parseInt(object._emailEnableList.new_booking_notification.enable)) === false) { 7378 7379 enable = true; 7380 7381 } 7382 object._console.log("enable = " + enable); 7383 7384 var confirm = new Confirm(object._debug); 7385 confirm.dialogPanelShow(object._i18n.get("Attention"), object._i18n.get("Will emails be sent to both customers and admins?"), enable, 0, function(sendEmail) { 7386 7387 var valueList = {}; 7388 var post = object.verifyForm("sendBooking", object._nonce, object._action, calendarData.date, schedule, courseList, object._formData, formPanelList, inputData, valueList, object.getGuestsList()); 7389 post.sendEmail = Number(sendEmail); 7390 7391 if (user.ID != null) { 7392 7393 post.userId = parseInt(user.ID); 7394 7395 } 7396 object._console.log(post); 7397 7398 if (post !== false) { 7399 7400 post.accountKey = accountKey; 7401 if (calendarData.account.type == "hotel") { 7402 7403 var checkDate = object._hotel.getCheckDate(); 7404 post.timeKey = parseInt(checkDate.checkIn.key); 7405 post.unixTime = parseInt(checkDate.checkIn.unixTime); 7406 7407 post.json = JSON.stringify(object._hotel.verifySchedule(true)); 7408 7409 } 7410 7411 post.selectedOptions = JSON.stringify([]); 7412 if (selectedOptions != null) { 7413 7414 post.selectedOptions = JSON.stringify(selectedOptions); 7415 7416 } 7417 7418 object._loadingPanel.setAttribute("class", "loading_modal_backdrop"); 7419 new Booking_App_XMLHttp(object._url, post, object._webApp, function(response){ 7420 7421 object._console.log(response); 7422 if (response.status == "success") { 7423 7424 object._hotel.reset(); 7425 object._hotel.setCallback(null); 7426 object._rightButtonPanel.textContent = null; 7427 response.action = 'refresh'; 7428 object._buttonAction = "reservation_users"; 7429 object.createCalendar(response, response.date.month, response.date.day, response.date.year, accountKey); 7430 callback(response); 7431 7432 } else { 7433 7434 alert(response.message); 7435 7436 } 7437 object._loadingPanel.setAttribute("class", "hidden_panel"); 7438 7439 }, function(responseText){ 7440
7441 //object.setResponseText(responseText); 7442 7443 }); 7444 7445 } 7446 7447 }); 7448 7449 }; 7450 7451 } 7452 7453 this.addGuestsForRoom = function(guestsList, hotelOptions, input, totalNumberOfGuests, roomNo, multipleRooms, deleteRoom, bookingButton){ 7454 7455 var object = this; 7456 object._console.log('addGuestsForRoom'); 7457 object._console.log('multipleRooms = ' + multipleRooms); 7458 object._console.log(hotelOptions); 7459 7460 var roomPanel = document.createElement('div'); 7461 roomPanel.id = 'roomNo_' + roomNo; 7462 if (multipleRooms == 1) { 7463 7464 var roomNoLabel = document.createElement('label'); 7465 roomNoLabel.classList.add('roomNoLabel'); 7466 roomNoLabel.textContent = object._i18n.get('Room') + ': ' + (roomNo + 1); 7467 roomPanel.appendChild(roomNoLabel); 7468 7469 } 7470 7471 if (deleteRoom === true) { 7472 7473 var deleteRoomButton = document.createElement('label'); 7474 deleteRoomButton.classList.add('material-icons'); 7475 deleteRoomButton.classList.add('deleteRoomButton'); 7476 deleteRoomButton.textContent = 'delete'; 7477 deleteRoomButton.setAttribute('data-room', roomNo); 7478 roomPanel.appendChild(deleteRoomButton); 7479 deleteRoomButton.onclick = function(event) { 7480 7481 var deleteRoomButton = this; 7482 var roomNo = parseInt(deleteRoomButton.getAttribute('data-room')); 7483 object._console.log('roomNo = ' + roomNo); 7484 var rooms = object._hotel.deleteRoom(roomNo); 7485 var roomPanel = deleteRoomButton.parentElement; 7486 document.getElementById('roomListPanel').removeChild(roomPanel); 7487 object.updateRoomNumber(); 7488 var verifyGuests = object._hotel.verifyGuestsInRooms(response.rooms); 7489 if (verifyGuests.booking == false || response.nights == 0 || verifyGuests.requiredGuests == false) { 7490 7491 bookingButton.disabled = true; 7492 7493 } else { 7494 7495 bookingButton.disabled = false; 7496 7497 } 7498 7499 }; 7500 7501 } 7502 7503 /** Select options with Hotel **/ 7504 if (hotelOptions.length > 0) { 7505 7506 var optionsTitle = document.createElement('div'); 7507 optionsTitle.classList.add('optionsTitle'); 7508 optionsTitle.textContent = object._i18n.get('Options') + ':'; 7509 7510 var collectionOptionsPanel = document.createElement('div'); 7511 collectionOptionsPanel.classList.add('collectionOptionsPanel'); 7512 //collectionOptionsPanel.classList.add('row'); 7513 collectionOptionsPanel.id = 'collectionOptionsPanel_' + roomNo; 7514 collectionOptionsPanel.appendChild(optionsTitle); 7515 roomPanel.insertAdjacentElement("beforeend", collectionOptionsPanel); 7516 7517 for (var key in hotelOptions) { 7518 7519 var option = hotelOptions[key]; 7520 hotelOptions[key].id = key; 7521 object._console.log(option); 7522 var list = hotelOptions[key].json; 7523 if (typeof hotelOptions[key].json == 'string') { 7524 7525 list = JSON.parse(hotelOptions[key].json); 7526 7527 } 7528 7529 var values = []; 7530 for (var i = 0; i < list.length; i++) { 7531 7532 values.push(list[i].name); 7533 7534 } 7535 7536 hotelOptions[key].values = values; 7537 hotelOptions[key].type = "SELECT"; 7538 hotelOptions[key].value = 0; 7539 hotelOptions[key].index = 0; 7540 hotelOptions[key].charge = 0; 7541 hotelOptions[key].description = ''; 7542 object._hotel.addOptions(key, hotelOptions[key], roomNo); 7543 object._console.log(list); 7544 7545 if (list[0] != null) { 7546 7547 //hotelOptions[key].charge = parseInt(list[0].number); 7548 var response = object._hotel.addSelectedOptions(key, 0, roomNo); 7549 7550 } 7551 7552 var optionsSelectPanel = input.createInput(hotelOptions[key]['name'], hotelOptions[key], {}, function(event) { 7553 7554 var key = this.parentElement.getAttribute("data-option"); 7555 var roomNo = this.parentElement.getAttribute("data-room"); 7556 var index = parseInt(this.selectedIndex); 7557 var list = hotelOptions[key].json; 7558 if (typeof hotelOptions[key].json == 'string') { 7559 7560 list = JSON.parse(hotelOptions[key].json); 7561 7562 } 7563 object._console.log("key " + key + " index = " + index + " roomNo = " + roomNo); 7564 object._console.log(hotelOptions[key]); 7565 object._console.log(list); 7566 var response = object._hotel.addSelectedOptions(key, index, roomNo); 7567 var feeList = object._hotel.getSubtotals(); 7568 7569 var verifyGuests = object._hotel.verifyGuestsInRooms(response.rooms); 7570 object._hotel.pushCallback(); 7571 7572 totalNumberOfGuests.classList.remove("errorPanel"); 7573 if(response.booking == false){ 7574 7575 totalNumberOfGuests.classList.add("errorPanel"); 7576 7577 } 7578
7579 for (var roomKey in verifyGuests.rooms) { 7580 7581 var roomStatus = verifyGuests.rooms[roomKey]; 7582 var roomPanel = document.getElementById('roomNo_' + roomKey); 7583 object._console.log(roomStatus); 7584 object._console.log(roomPanel); 7585 /** 7586 if (roomStatus.booking === false || roomStatus.requiredGuests === false) { 7587 7588 roomPanel.classList.add('errorPanel'); 7589 7590 } else { 7591 7592 roomPanel.classList.remove('errorPanel'); 7593 7594 } 7595 **/ 7596 7597 } 7598 7599 }); 7600 7601 optionsSelectPanel.setAttribute("data-option", key); 7602 optionsSelectPanel.setAttribute("data-room", roomNo); 7603 var required = parseInt(hotelOptions[key].required); 7604 object._console.log("required = " + required); 7605 var rowPanel = object.createRowPanel(hotelOptions[key]['name'], optionsSelectPanel, null, required, null); 7606 if (multipleRooms == 1) { 7607 7608 rowPanel.setAttribute('class', 'rowRoom'); 7609 7610 } 7611 roomPanel.appendChild(rowPanel); 7612 7613 } 7614 7615 } 7616 /** Select options with Hotel **/ 7617 7618 /** Select guests with Hotel **/ 7619 if (guestsList.length > 0) { 7620 7621 var guestsTitle = document.createElement('div'); 7622 guestsTitle.classList.add('optionsTitle'); 7623 guestsTitle.textContent = object._i18n.get('Guests') + ':'; 7624 7625 var collectionGuestsPanel = document.createElement('div'); 7626 collectionGuestsPanel.classList.add('collectionOptionsPanel'); 7627 //collectionOptionsPanel.classList.add('row'); 7628 collectionGuestsPanel.id = 'collectionOptionsPanel_' + roomNo; 7629 collectionGuestsPanel.appendChild(guestsTitle); 7630 roomPanel.insertAdjacentElement("beforeend", collectionGuestsPanel); 7631 7632 for (var key in guestsList) { 7633 7634 var list = JSON.parse(guestsList[key].json); 7635 object._console.log(list); 7636 var values = []; 7637 for (var i = 0; i < list.length; i++) { 7638 7639 values.push(list[i].name); 7640 7641 } 7642 7643 object._console.log(values); 7644 guestsList[key].values = values; 7645 guestsList[key].type = "SELECT"; 7646 guestsList[key].value = 0; 7647 guestsList[key].index = 0; 7648 guestsList[key].person = 0; 7649 guestsList[key].description = ''; 7650 object._hotel.addGuests(key, guestsList[key], roomNo); 7651 if (list[0] != null) { 7652 7653 guestsList[key].person = parseInt(list[0].number); 7654 var response = object._hotel.setGuests(key, 0, list[0].number, roomNo); 7655 7656 } 7657 7658 var value = input.createInput(guestsList[key]['name'], guestsList[key], {}, function(event){ 7659 7660 var key = this.parentElement.getAttribute("data-guset"); 7661 var index = parseInt(this.selectedIndex); 7662 var roomNo = parseInt(this.parentElement.getAttribute('data-room')); 7663 var list = JSON.parse(guestsList[key].json); 7664 guestsList[key].index = index; 7665 var response = object._hotel.setGuests(key, index, list[index].number, roomNo); 7666 var feeList = object._hotel.getSubtotals(); 7667 var verifyGuests = object._hotel.verifyGuestsInRooms(response.rooms); 7668 object._hotel.pushCallback(); 7669 7670 totalNumberOfGuests.classList.remove("errorPanel"); 7671 if (response.booking == false) { 7672 7673 totalNumberOfGuests.classList.add("errorPanel"); 7674 7675 } 7676
7677 for (var roomKey in verifyGuests.rooms) { 7678 7679 var roomStatus = verifyGuests.rooms[roomKey]; 7680 var roomPanel = document.getElementById('roomNo_' + roomKey); 7681 object._console.log(roomStatus); 7682 object._console.log(roomPanel); 7683 /** 7684 if (roomStatus.booking === false || roomStatus.requiredGuests === false) { 7685 7686 roomPanel.classList.add('errorPanel'); 7687 7688 } else { 7689 7690 roomPanel.classList.remove('errorPanel'); 7691 7692 } 7693 **/ 7694 7695 } 7696 7697 object._console.log(totalNumberOfGuests); 7698 object._console.log(response); 7699 object._console.log(this.selectedIndex); 7700 object._console.log(guestsList[key]); 7701 object._console.log(list[index]); 7702 7703 }); 7704 7705 value.setAttribute("data-guset", key); 7706 value.setAttribute("data-room", roomNo); 7707 var required = parseInt(guestsList[key].required); 7708 object._console.log("required = " + required); 7709 var rowPanel = object.createRowPanel(guestsList[key]['name'], value, null, required, null); 7710 if (multipleRooms == 1) { 7711 7712 rowPanel.setAttribute('class', 'rowRoom'); 7713 7714 } 7715 roomPanel.appendChild(rowPanel); 7716 7717 } 7718 7719 } 7720 /** Select guests with Hotel **/ 7721 7722 return roomPanel; 7723 7724 }; 7725 7726 this.updateRoomNumber = function() { 7727 7728 var object = this; 7729 var roomNumberLabels = document.getElementById('roomListPanel').getElementsByClassName('roomNoLabel'); 7730 object._console.log(roomNumberLabels); 7731 for (var i = 0; i < roomNumberLabels.length; i++) { 7732 7733 var roomNoLabel = roomNumberLabels[i]; 7734 object._console.log(roomNoLabel); 7735 roomNoLabel.textContent = object._i18n.get('Room') + ': ' + (i + 1); 7736 7737 } 7738 7739 }; 7740 7741 this.lookForUser = function(callback){ 7742 7743 var object = this; 7744 object._console.log('lookForUser'); 7745 var lookForUserPanel = document.getElementById('lookForUserPanel'); 7746 lookForUserPanel.classList.remove('hidden_panel'); 7747 7748 var inputPanel = lookForUserPanel.getElementsByClassName('inputPanel')[0]; 7749 inputPanel.textContent = null; 7750 object._console.log(inputPanel); 7751 7752 var search_users_text = document.getElementById('search_users_text'); 7753 search_users_text.focus(); 7754 var search_user_button = document.getElementById('search_user_button'); 7755 7756 var load_blockPanel = document.getElementById('load_blockPanel'); 7757 load_blockPanel.classList.remove('hidden_panel'); 7758 7759 document.getElementById('lookForUserPanel_return_button').onclick = function() { 7760 7761 lookForUserPanel.classList.add('hidden_panel'); 7762 load_blockPanel.classList.add('hidden_panel'); 7763 7764 }; 7765 7766 load_blockPanel.onclick = function() { 7767 7768 lookForUserPanel.classList.add('hidden_panel'); 7769 load_blockPanel.classList.add('hidden_panel'); 7770 7771 }; 7772 7773 search_users_text.onkeydown = function(event) { 7774 7775 if (event.key != null && event.key.toLocaleLowerCase() == 'enter') { 7776 7777 getMembers(search_users_text.value); 7778 7779 } 7780 7781 }; 7782 7783 search_user_button.onclick = function() { 7784 7785 getMembers(search_users_text.value); 7786 7787 }; 7788 7789 function getMembers(text) { 7790 7791 var keywords = text; 7792 //keywords = keywords.replace(/[\u{20}\u{3000}]/ug ,' '); 7793 //keywords = keywords.replace(/[\x20\u3000]/g ,' '); 7794 keywords = keywords.trim(keywords); 7795 object._console.log(keywords.length); 7796 if (keywords.length <= 1) { 7797 7798 return null; 7799 7800 } 7801 7802 search_users_text.disabled = true; 7803 search_user_button.disabled = true; 7804 object._console.log(keywords); 7805 var post = {mode: 'getMembers', nonce: object._nonce, action: object._action, keywords: keywords, page: null, number: 20, offset: 0, authority: 'user', meta: 1}; 7806 object._console.log(post); 7807 object._loadingPanel.setAttribute("class", "loading_modal_backdrop"); 7808 object.setFunction("lookForUser", post); 7809 new Booking_App_XMLHttp(object._url, post, object._webApp, function(users){ 7810 7811 object._loadingPanel.setAttribute("class", "hidden_panel"); 7812 search_users_text.disabled = false;
7813 search_user_button.disabled = false; 7814 object._console.log(users); 7815 7816 inputPanel.textContent = null; 7817 if (users.length == 0) { 7818 7819 var noUsers = document.createElement('p'); 7820 noUsers.classList.add('noUsers'); 7821 noUsers.textContent = object._i18n.get('The user was not found.'); 7822 inputPanel.appendChild(noUsers); 7823 7824 } else { 7825 7826 var tbody = document.createElement('tbody'); 7827 tbody.id = 'member_list_tbody'; 7828 7829 var table = document.createElement('table'); 7830 table.id = 'member_list_table'; 7831 table.appendChild(tbody); 7832 table.setAttribute('class', 'wp-list-table widefat fixed striped'); 7833 inputPanel.appendChild(table); 7834 7835 for (var i = 0; i < users.length; i ++) { 7836 7837 var user = users[i]; 7838 object._console.log(user); 7839 7840 var tdUserId = document.createElement('td'); 7841 tdUserId.textContent = user.user_login; 7842 var tdEmail = document.createElement('td'); 7843 tdEmail.textContent = user.user_email; 7844 7845 var tr = document.createElement('tr'); 7846 tr.setAttribute('data-key', i); 7847 tr.classList.add('tr_user'); 7848 tr.appendChild(tdUserId); 7849 tr.appendChild(tdEmail); 7850 tbody.appendChild(tr); 7851 7852 tr.onclick = function() { 7853 7854 var key = parseInt(this.getAttribute('data-key')); 7855 var user = users[key]; 7856 var json = JSON.parse(user.value); 7857 user.meta = json; 7858 object._console.log(user); 7859 lookForUserPanel.classList.add('hidden_panel'); 7860 load_blockPanel.classList.add('hidden_panel'); 7861 callback(user); 7862 7863 7864 }; 7865 7866 } 7867 7868 } 7869 7870 }); 7871 7872 } 7873 7874 } 7875 7876 this.downloadCSV = function(month, day, year, accountKey, form, downloadBool, style){ 7877 7878 var object = this; 7879 object._console.log("month = " + month + " day = " + day + " year = " + year); 7880 form.method = "post"; 7881 form.target = "_blank"; 7882 var post = {nonce: object._nonce_download, action: object._action, mode: object._prefix + 'getDownloadCSV', year: year, month: month, accountKey: accountKey}; 7883 7884 if(day != null){ 7885 7886 post.day = day; 7887 7888 } 7889 7890 for(var key in post){ 7891 7892 var hidden = document.createElement("input"); 7893 hidden.type = "hidden"; 7894 hidden.name = key; 7895 hidden.value = post[key]; 7896 form.appendChild(hidden); 7897 7898 } 7899 7900 var submit = document.createElement("input"); 7901 submit.type = "submit"; 7902 submit.value = this._i18n.get("Download CSV"); 7903 submit.setAttribute("class", "downloadButton button media-button button-primary button-large media-button-insert"); 7904 //submit.setAttribute("style", "padding: 0 0.5em;"); 7905 if(downloadBool == false){ 7906 7907 submit.disabled = true; 7908 7909 } 7910 form.appendChild(submit); 7911 form.setAttribute("style", style); 7912 7913 } 7914 7915 this.verifyCalendar = function(mode, month, day, year, lastDay){ 7916 7917 var calendarChange = 0; 7918 if(mode == 0){ 7919 7920 day--; 7921 if(day == 0){ 7922 7923 calendarChange = 1; 7924 month--; 7925 day = 1; 7926 if(month == 0){
7927 month = 12; 7928 year--; 7929 } 7930 7931 } 7932 7933 }else if(mode == 1){ 7934 7935 day++; 7936 if(day > lastDay){ 7937 7938 calendarChange = 1; 7939 month++; 7940 day = 1; 7941 if(month == 13){ 7942 month = 1; 7943 year++; 7944 } 7945 7946 } 7947 7948 } 7949 7950 var date = {month: month, day: day, year: year, calendarChange: calendarChange}; 7951 return date; 7952 7953 } 7954 7955 this.verifyForm = function(mode, nonce, action, date, schedule, courseList, formData, formPanelList, inputData, valueList, guestsList){ 7956 7957 var object = this; 7958 object._console.log(date); 7959 object._console.log(schedule); 7960 object._console.log(courseList); 7961 var errorPanel = null; 7962 var sendBool = true; 7963 var input = new Booking_Package_Input(object._debug); 7964 for (var key in formData) { 7965 7966 object._console.log(key); 7967 object._console.log(inputData[key]); 7968 object._console.log(formData[key]); 7969 7970 if (formData[key].active != 'true') { 7971 7972 continue; 7973 7974 } 7975 7976 if (formPanelList[key] == null) { 7977 7978 continue; 7979 7980 } 7981 7982 var bool = input.inputCheck(key, formData[key], inputData[key], valueList, 'dashboard'); 7983 object._console.log("bool = " + bool); 7984 if (bool === true) { 7985 7986 formPanelList[key].removeAttribute("data-errorInput"); 7987 formPanelList[key].classList.remove("error_empty_value"); 7988 //formPanelList[key].setAttribute("class", "row"); 7989 7990 } else { 7991 7992 sendBool = false; 7993 formPanelList[key].setAttribute("data-errorInput", 1); 7994 formPanelList[key].classList.add("error_empty_value"); 7995 if (errorPanel == null) { 7996 7997 errorPanel = formPanelList[key]; 7998 7999 } 8000 8001 } 8002 8003 } 8004 8005 var postGuests = []; 8006 if (parseInt(object._calendarAccount.guestsBool) == 1) { 8007 8008 if (object._calendarAccount.type == 'day' && guestsList.length > 0) { 8009 8010 for (var key in guestsList) { 8011 8012 var guest = guestsList[key]; 8013 object._console.log(guest); 8014 var guestPanel = document.getElementById(object._prefix + guest.id); 8015 if (parseInt(guest.required) == 1 && parseInt(guest.index) == 0) { 8016 8017 sendBool = false; 8018 guestPanel.classList.add('error_empty_value'); 8019 guestPanel.setAttribute("data-errorInput", 1); 8020 if (errorPanel == null) { 8021 8022 errorPanel = guestPanel; 8023 8024 } 8025 8026 } else { 8027 8028 guestPanel.classList.remove('error_empty_value'); 8029 guestPanel.removeAttribute("data-errorInput"); 8030 var postGuest = {key: guest.key, name: guest.name, selectedName: guest.selectedName, index: guest.index}; 8031 postGuests.push(postGuest); 8032 8033 } 8034 8035 } 8036 object._console.log(postGuests); 8037 8038 var responseGuests = object._servicesControl.getValueReflectGuests(guestsList); 8039 object._console.log(responseGuests); 8040 var totalNumberOfGuestsPanel = document.getElementById(object._prefix + 'totalNumberOfGuests'); 8041 var totalNumberOfGuestsValuePanel = totalNumberOfGuestsPanel.getElementsByClassName('value')[0]; 8042 var totalNumberOfGuestsErrorPanel = totalNumberOfGuestsPanel.getElementsByClassName('errorMessage')[0]; 8043 totalNumberOfGuestsValuePanel.textContent = responseGuests.totalNumberOfGuestsTitle; 8044 var responseLimitGuests = object._servicesControl.verifyToLimitGuests(responseGuests, object._calendarAccount.limitNumberOfGuests, object._calendarAccount.type); 8045 object._console.log(responseLimitGuests); 8046 if (responseLimitGuests.isGuests === true) { 8047 8048 totalNumberOfGuestsPanel.classList.remove('error_empty_value'); 8049 totalNumberOfGuestsPanel.removeAttribute("data-errorInput"); 8050 totalNumberOfGuestsErrorPanel.classList.add('hidden_panel'); 8051 totalNumberOfGuestsErrorPanel.textContent = null; 8052 8053 } else { 8054 8055 sendBool = false;
8056 totalNumberOfGuestsPanel.classList.add('error_empty_value'); 8057 totalNumberOfGuestsPanel.setAttribute("data-errorInput", 1); 8058 totalNumberOfGuestsErrorPanel.classList.remove('hidden_panel'); 8059 totalNumberOfGuestsErrorPanel.textContent = responseLimitGuests.errorMessage; 8060 if (errorPanel == null) { 8061 8062 errorPanel = totalNumberOfGuestsPanel; 8063 8064 } 8065 8066 } 8067 8068 } 8069 8070 } 8071 8072 object._console.log(valueList); 8073 if (sendBool === true) { 8074 8075 object._console.log('_courseBool = ' + object._courseBool); 8076 var post = {nonce: nonce, action: action, mode: mode, month: date.month, day: 1, year: date.year, applicantCount: '1', permission: 'public', timeKey: schedule.key, unixTime: schedule.unixTime}; 8077 if (postGuests.length > 0) { 8078 8079 post.guests = JSON.stringify(postGuests); 8080 8081 } 8082 8083 if (object._courseBool == true && courseList != null) { 8084 8085 var selectedCourseList = []; 8086 var selectedCourseKeyList = []; 8087 for (var i in courseList) { 8088 8089 if (courseList[i].selected == 1) { 8090 8091 object._console.log(courseList[i]); 8092 object._console.log(typeof courseList[i].options); 8093 var service = {}; 8094 for (var key in courseList[i]) { 8095 8096 service[key] = courseList[i][key]; 8097 8098 } 8099 8100 8101 if (typeof courseList[i].options == 'string') { 8102 8103 var options = JSON.parse(courseList[i].options); 8104 service.options = options; 8105 8106 } 8107 8108 selectedCourseList.push(service); 8109 selectedCourseKeyList.push(service.key); 8110 post.courseKey = courseList[i].key; 8111 8112 } 8113 8114 } 8115 8116 post.selectedCourseList = JSON.stringify(selectedCourseList); 8117 post.selectedCourseKeyList = JSON.stringify(selectedCourseKeyList); 8118 //post.courseKey = course.key; 8119 8120 } 8121 8122 for (var key in valueList) { 8123 8124 object._console.log(valueList[key]); 8125 if (typeof valueList[key].join == 'function') { 8126 8127 post['form' + key] = valueList[key].join(","); 8128 8129 } else { 8130 8131 post['form' + key] = valueList[key]; 8132 8133 } 8134 8135 8136 } 8137 8138 return post; 8139 8140 } else { 8141 8142 if (errorPanel != null && typeof errorPanel.scrollIntoView == 'function') { 8143 8144 object._console.log(errorPanel); 8145 errorPanel.scrollIntoView(true); 8146 8147 } 8148 8149 return false; 8150 8151 } 8152 8153 } 8154 8155 this.unselectPanel = function(selectedKey, panelList, styleName){ 8156 8157 for(var i = 0; i < panelList.length; i++){ 8158 8159 var key = panelList[i].getAttribute("data-key"); 8160 var status = parseInt(panelList[i].getAttribute("data-status")); 8161 if(key != selectedKey && status === 1){ 8162 8163 panelList[i].setAttribute("class", styleName); 8164 8165 } 8166 8167 8168 } 8169 8170 } 8171 8172 this.createRowPanel = function(name, value, id, required, actionElement){ 8173 8174 var object = this; 8175 if (typeof name == "string") { 8176 8177 name = name.replace(/\\/g, ""); 8178 8179 } 8180 object._console.log(value); 8181 if (typeof value == "string") { 8182 8183 value = value.replace(/\\/g, ""); 8184 8185 } else if (typeof value == 'object' && typeof value.join == 'function') { 8186 8187 //value = JSON.parse(value); 8188 //object._console.log(value); 8189 value = value.join('\n'); 8190 8191 } 8192 object._console.log(value); 8193 8194 var edit = 0; 8195 if (typeof value == 'object' && typeof value.getAttribute == 'function' && value.getAttribute("data-edit") != null) { 8196 8197 edit = parseInt(value.getAttribute("data-edit")); 8198 8199 } 8200 8201 object._console.log("id = " + id); 8202 object._console.log("edit = " + edit); 8203 8204 var namePanel = document.createElement("div"); 8205 namePanel.setAttribute("class", "name"); 8206 namePanel.textContent = name; 8207 //object._console.log("typeof required = " + typeof required); 8208 if ( (typeof required == "string" && required == 'true') || (typeof required == "number" && required == 1) ) { 8209 8210 namePanel.setAttribute("class", "name required"); 8211 8212 } 8213 8214 var inputPanel = null; 8215 if (typeof value == 'string' || typeof value == 'number') { 8216 8217 inputPanel = document.createElement("div"); 8218 inputPanel.textContent = value; 8219 if (id != null) { 8220 8221 inputPanel.id = id; 8222 8223 } 8224 8225 } else { 8226 8227 inputPanel = value; 8228 if (id != null) { 8229 8230 inputPanel.id = id; 8231 8232 } 8233 8234 } 8235 inputPanel.setAttribute("class", "value"); 8236 8237 var rowPanel = document.createElement("div"); 8238 rowPanel.setAttribute("class", "row"); 8239 rowPanel.appendChild(namePanel); 8240 8241 if (edit == 1) { 8242 8243 var editButton = document.createElement("div"); 8244 editButton.setAttribute("data-id", id); 8245 editButton.classList.add("material-icons"); 8246 editButton.classList.add("editButton"); 8247 editButton.classList.add(object._prefix + "user_information_button"); 8248 editButton.setAttribute("style", "font-family: 'Material Icons' !important;"); 8249 editButton.textContent = "border_color"; 8250 rowPanel.appendChild(editButton); 8251 8252 var doneButton = document.createElement("div"); 8253 doneButton.setAttribute("data-id", id); 8254 doneButton.classList.add("material-icons"); 8255 doneButton.classList.add("editButton"); 8256 doneButton.classList.add("hidden_panel"); 8257 doneButton.classList.add(object._prefix + "user_information_button"); 8258 doneButton.textContent = "done_outline"; 8259 rowPanel.appendChild(doneButton); 8260 8261 editButton.onclick = function(){ 8262 8263 var id = editButton.getAttribute("data-id"); 8264 var valueId = "value_" + id; 8265 var inputId = "input_" + id; 8266 editButton.classList.add("hidden_panel"); 8267 doneButton.classList.remove("hidden_panel"); 8268 document.getElementById(valueId).classList.add("hidden_panel"); 8269 document.getElementById(inputId).classList.remove("hidden_panel"); 8270 8271 }; 8272 8273 doneButton.onclick = function(){ 8274 8275 var id = doneButton.getAttribute("data-id"); 8276 var valueId = "value_" + id; 8277 var inputId = "input_" + id; 8278 doneButton.classList.add("hidden_panel"); 8279 editButton.classList.remove("hidden_panel"); 8280 document.getElementById(valueId).classList.remove("hidden_panel"); 8281 document.getElementById(inputId).classList.add("hidden_panel"); 8282 8283 }; 8284 8285 } 8286 8287 8288 if (actionElement != null) { 8289 8290 rowPanel.appendChild(actionElement); 8291 8292 } 8293 rowPanel.appendChild(inputPanel); 8294 8295 return rowPanel; 8296 8297 } 8298 8299 this.editPanelShow = function(showBool){ 8300 8301 var object = this; 8302 var body = document.getElementsByTagName("body")[0]; 8303 object._console.log(body); 8304 8305 8306 if (showBool == true) { 8307 8308 body.classList.add("modal-open"); 8309 object._editPanel.setAttribute("class", "edit_modal"); 8310 object._blockPanel.setAttribute("class", "edit_modal_backdrop"); 8311 8312 } else { 8313 8314 if( document.getElementById("userInfoPanel") != null) { 8315 8316 document.getElementById("userInfoPanel").setAttribute("class", "hidden_panel"); 8317 8318 } 8319 8320 if (document.getElementById("changePanel") != null) { 8321 8322 document.getElementById("changePanel").setAttribute("class", "hidden_panel"); 8323 8324 } 8325 8326 if (object._contentPanel != null && document.getElementById("showUserInfo_blockPanel") != null) { 8327 8328 object._contentPanel.removeChild(document.getElementById("showUserInfo_blockPanel")); 8329 8330 } 8331 8332 body.classList.remove("modal-open"); 8333 object._editPanel.setAttribute("class", "hidden_panel"); 8334 object._blockPanel.setAttribute("class", "hidden_panel"); 8335 8336 } 8337 8338 } 8339 8340 this.setTypeOfId = function(_typeOfId) { 8341 8342 this._typeOfId = _typeOfId; 8343 8344 } 8345 8346 this.getTypeOfId = function() { 8347 8348 return this._typeOfId; 8349 8350 } 8351 8352 this.setSelectedKey = function(_selectedKey){ 8353 8354 this._selectedKey = _selectedKey; 8355 8356 } 8357
8358 this.getSelectedKey = function(){ 8359 8360 return this._selectedKey; 8361 8362 } 8363 8364 this.setVisitors = function(_visitors){ 8365 8366 this._visitors = _visitors; 8367 8368 } 8369 8370 this.getVisitors = function(){ 8371 8372 return this._visitors; 8373 8374 } 8375 8376 this.getServiceOrOption = function(services) { 8377 8378 var mode = "option"; 8379 for (var key in services) { 8380 8381 if (services[key].service != null && parseInt(services[key].service) == 1) { 8382 8383 return "service"; 8384 8385 } 8386 8387 } 8388 8389 return mode; 8390 8391 } 8392 8393 this.createServicesPanel = function(panel, services, optionName, guestsList, guestsBool, goodsList, currency, showAumontOnService) { 8394 8395 var object = this; 8396 var totalCost = 0; 8397 var applicantCount = 1; 8398 var reflectService = 0; 8399 var reflectAdditional = 0; 8400 var reflectServiceTitle = null; 8401 var hasReflectService = false; 8402 var defaultAmountForService = 0; 8403 var defaultAmountForOption = 0; 8404 var isGuests = 0; 8405 var courseLinePanel = document.createElement("div"); 8406 object._console.log('createServicesPanel'); 8407 object._console.log(guestsList); 8408 if (typeof guestsList == 'object' && guestsList.length > 0) { 8409 8410 isGuests = 1 8411 var response = object._servicesControl.getValueReflectGuests(guestsList); 8412 object._console.log(response); 8413 reflectService = response.reflectService; 8414 reflectServiceTitle = response.reflectServiceTitle; 8415 if (reflectService > 0) { 8416 8417 applicantCount = reflectService; 8418 8419 } 8420 8421 } 8422 8423 object._console.log('reflectService = ' + reflectService); 8424 object._console.log('reflectAdditional = ' + reflectAdditional); 8425 object._console.log(reflectServiceTitle); 8426 object._console.log('guestsBool = ' + guestsBool) 8427 8428 if (parseInt(guestsBool) == 1) { 8429 8430 for (var guestKey in guestsList) { 8431 8432 if (parseInt(guestsList[guestKey].reflectService) == 1) { 8433 8434 hasReflectService = true; 8435 break; 8436 8437 } 8438 8439 } 8440 8441 } 8442 8443 const getSelectedName = function(guest) { 8444 8445 const options = guest.json; 8446 const index = parseInt(guest.index); 8447 return options[index].name; 8448 /** 8449 for (let i = 0; i < options.length; i++) { 8450 8451 if (parseInt(options[i].number) === number) { 8452 8453 return options[i].name; 8454 8455 } 8456 8457 } 8458 **/ 8459 }; 8460 8461 if (services.length > 0) { 8462 8463 for (var key in services) { 8464 8465 var service = services[key]; 8466 object._console.log(service); 8467 8468 if (parseInt(service.selected) == 1) { 8469 8470 var responseCosts = object._servicesControl.getCostsInService(services[key], guestsList, isGuests, object._isExtensionsValid); 8471 object._console.log(responseCosts); 8472 var costsWithKey = responseCosts.costsWithKey; 8473 var costPerGuests = document.createElement('div'); 8474 costPerGuests.id = 'costPerGuests_' + key; 8475 costPerGuests.classList.add('costPerGuests'); 8476 costPerGuests.classList.add('hidden_panel'); 8477 var courseCostPanel = null; 8478 courseCostPanel = document.createElement("span"); 8479 courseCostPanel.classList.add("planPrice"); 8480 //courseCostPanel.textContent = object._format.formatCost(service.cost, currency); 8481 var cost = object._format.formatCost(responseCosts.max, object._currency); 8482 8483 if (responseCosts.hasMultipleCosts === true) { 8484 8485 //cost = object._format.formatCost(responseCosts.min, object._currency) + ' ' + object._i18n.get('to') + ' ' + object._format.formatCost(responseCosts.max, object._currency); 8486 cost = object._i18n.get('%s to %s', [object._format.formatCost(responseCosts.min, object._currency), object._format.formatCost(responseCosts.max, object._currency)]); 8487 8488 } 8489 courseCostPanel.textContent = cost; 8490 8491 var amount1 = parseInt(service.cost_1); 8492 var amount2 = parseInt(service.cost_1); 8493 if (reflectService > 0) { 8494 8495 //amount1 = 0; 8496 if (guestsBool == 1) { 8497 8498 amount1 = 0; 8499 for (var guestKey in guestsList) { 8500 8501 var guest = guestsList[guestKey]; 8502 object._console.log(guest); 8503 if (parseInt(guest.reflectService) == 1) { 8504 8505 if (guest.number == null) { 8506
8507 guest.number = parseInt(guest.json[guest.index].number); 8508 8509 } 8510 8511 if (guest.selectedName == null) { 8512 8513 guest.selectedName = getSelectedName(guest); 8514 8515 } 8516 //hasReflectService = true; 8517 amount1 += costsWithKey[guest.costInServices] * guest.number; 8518 8519 if (defaultAmountForService == 0) { 8520 8521 defaultAmountForService = costsWithKey[guest.costInServices]; 8522 8523 } 8524 8525 var costInService = document.createElement('div'); 8526 costInService.textContent = guest.name + ': ' + guest.selectedName + ' * ' + object._format.formatCost(costsWithKey[guest.costInServices], currency); 8527 if (guest.number > 0) { 8528 8529 costPerGuests.appendChild(costInService); 8530 8531 } 8532 8533 } else { 8534 8535 if (guest.number != null && guest.number > 0) { 8536 8537 if (guest.selectedName == null) { 8538 8539 guest.selectedName = getSelectedName(guest); 8540 8541 } 8542 8543 //amount2 += costsWithKey[guest.costInServices]; 8544 amount2 = costsWithKey['cost_1']; 8545 if (defaultAmountForService == 0) { 8546 8547 defaultAmountForService = costsWithKey[guest.costInServices]; 8548 8549 } 8550 var costInService = document.createElement('div'); 8551 costInService.textContent = guest.name + ': ' + /**object._format.formatCost(costsWithKey[guest.costInServices], object._currency) + ' * ' +**/ guest.selectedName; 8552 costPerGuests.appendChild(costInService); 8553 8554 } 8555 8556 } 8557 8558 } 8559 8560 } else { 8561 8562 //amount1 = costsWithKey['cost_1']; 8563 //amount2 = 0; 8564 8565 } 8566 8567 } else { 8568 8569 amount2 = 0; 8570 8571 } 8572 8573 object._console.log('hasReflectService = ' + hasReflectService); 8574 if (hasReflectService === true) { 8575 8576 amount2 = 0; 8577 8578 } 8579 8580 object._console.log('amount1 = ' + amount1); 8581 object._console.log('amount2 = ' + amount2); 8582 var goods = {label: service.name, amount: amount1 + amount2, applicantCount: applicantCount}; 8583 goodsList.push(goods); 8584 totalCost += amount1 + amount2; 8585 8586 if (showAumontOnService === false) { 8587 8588 if (isNaN(parseInt(responseCosts.max)) === false && parseInt(responseCosts.max) != 0) { 8589 8590 courseCostPanel = document.createElement("span"); 8591 courseCostPanel.classList.add("planPrice"); 8592 courseCostPanel.classList.add('maximumAndMinimum'); 8593 var cost = object._format.formatCost(responseCosts.max, currency); 8594 if (responseCosts.hasMultipleCosts === true) { 8595 8596 //cost = object._i18n.get('%s to %s', [object._format.formatCost(responseCosts.min, object._currency), object._format.formatCost(responseCosts.max, object._currency)]); 8597 cost = object._i18n.get('%s to %s', [object._format.formatCost(responseCosts.min, currency), object._format.formatCost(responseCosts.max, currency)]); 8598 courseCostPanel.textContent = cost; 8599 //object.createmMximumAndMinimumElements(responseCosts, courseCostPanel); 8600 8601 } else { 8602 8603 courseCostPanel.textContent = cost + ' '; 8604 8605 } 8606 8607 } 8608 8609 } else { 8610 8611 courseCostPanel = document.createElement("span"); 8612 courseCostPanel.classList.add("planPrice"); 8613 courseCostPanel.classList.add('maximumAndMinimum'); 8614 courseCostPanel.textContent = object._format.formatCost( (amount1 + amount2), currency); 8615 8616 } 8617 8618 8619 var courseLinePanel = document.createElement("div"); 8620 courseLinePanel.setAttribute('data-key', key); 8621 courseLinePanel.classList.add("courseLinePanel"); 8622 panel.appendChild(courseLinePanel); 8623 panel.appendChild(costPerGuests); 8624 8625 var courseNamePanel = document.createElement("span"); 8626 courseNamePanel.classList.add("planName"); 8627 courseNamePanel.textContent = service.name; 8628 courseLinePanel.appendChild(courseNamePanel); 8629 if (courseCostPanel != null) { 8630 8631 courseLinePanel.appendChild(courseCostPanel); 8632 8633 } 8634 8635 if (reflectService > 1) { 8636 8637 var reflectServicePanel = document.createElement('span'); 8638 reflectServicePanel.classList.add('reflectPanel'); 8639 //reflectServicePanel.textContent = ' * ' + reflectServiceTitle; 8640 courseLinePanel.appendChild(reflectServicePanel); 8641 courseLinePanel.classList.add('courseLinePanelInLink'); 8642 courseLinePanel.onclick = function() { 8643 8644 var key = parseInt(this.getAttribute('data-key')); 8645 var costPerGuests = document.getElementById('costPerGuests_' + key); 8646 object._console.log(costPerGuests); 8647 object._console.log(costPerGuests.classList.contains('hidden_panel')); 8648 if (costPerGuests.classList.contains('hidden_panel') === true) { 8649 8650 costPerGuests.classList.remove('hidden_panel'); 8651 8652 } else { 8653 8654 costPerGuests.classList.add('hidden_panel'); 8655 8656 } 8657 8658 }; 8659 8660 } 8661 8662 object._console.log(service);
8663 var options = service[optionName]; 8664 if (options.length > 0) { 8665 8666 var ul = document.createElement("ul"); 8667 panel.appendChild(ul); 8668 for (var i = 0; i < options.length; i++) { 8669 8670 var option = options[i]; 8671 var optionAmount = 0; 8672 var responseCosts = object._servicesControl.getCostsInService(option, guestsList, isGuests, object._isExtensionsValid); 8673 object._console.log(responseCosts); 8674 var costsWithKey = responseCosts.costsWithKey; 8675 if (parseInt(option.selected) == 1) { 8676 8677 //cost += parseInt(option.cost); 8678 8679 var optionPanel = document.createElement('div'); 8680 optionPanel.setAttribute('data-serviceKey', key); 8681 optionPanel.setAttribute('data-optionKey', i); 8682 optionPanel.classList.add('courseLinePanelInLink'); 8683 var costPerOptions = document.createElement('div'); 8684 costPerOptions.id = 'costPerOptions_' + key + '_' + i; 8685 costPerOptions.classList.add('hidden_panel'); 8686 8687 var optionNamePanel = document.createElement("span"); 8688 optionNamePanel.classList.add("planName"); 8689 optionNamePanel.textContent = option.name; 8690 8691 var optionPricePanel = document.createElement("span"); 8692 optionPricePanel.classList.add("planPrice"); 8693 optionPricePanel.textContent = object._format.formatCost(responseCosts.max, currency); 8694 if (responseCosts.hasMultipleCosts === true) { 8695 8696 //cost = object._format.formatCost(responseCosts.min, object._currency) + ' ' + object._i18n.get('to') + ' ' + object._format.formatCost(responseCosts.max, object._currency); 8697 optionPricePanel.textContent = object._i18n.get('%s to %s', [object._format.formatCost(responseCosts.min, object._currency), object._format.formatCost(responseCosts.max, object._currency)]); 8698 8699 } 8700 var amount1 = parseInt(responseCosts.max); 8701 var amount2 = 0; 8702 if (reflectService > 1) { 8703 8704 amount1 = 0; 8705 if (guestsBool == 1) { 8706 8707 for (var guestKey in guestsList) { 8708 8709 var guest = guestsList[guestKey]; 8710 if (parseInt(guest.reflectService) == 1) { 8711 8712 if (guest.selectedName == null) { 8713 8714 if (guest.number == null) { 8715
8716 guest.number = 0; 8717 8718 } 8719 8720 guest.selectedName = getSelectedName(guest); 8721 8722 } 8723 8724 if (defaultAmountForOption == 0) { 8725 8726 defaultAmountForOption = costsWithKey[guest.costInServices]; 8727 8728 } 8729 8730 amount1 += costsWithKey[guest.costInServices] * guest.number; 8731 var costInOption = document.createElement('div'); 8732 costInOption.textContent = guest.name + ': ' + object._format.formatCost(costsWithKey[guest.costInServices], object._currency) + ' * ' + guest.selectedName; 8733 if (guest.number > 0) { 8734 8735 costPerOptions.appendChild(costInOption); 8736 8737 } 8738 8739 } else { 8740 8741 if (guest.number != null && guest.number > 0) { 8742 8743 if (guest.selectedName == null) { 8744 8745 guest.selectedName = getSelectedName(guest); 8746 8747 } 8748 8749 if (defaultAmountForOption == 0) { 8750 8751 defaultAmountForOption = costsWithKey[guest.costInServices]; 8752 8753 } 8754 8755 //amount2 += costsWithKey[guest.costInServices]; 8756 amount2 = costsWithKey['cost_1']; 8757 var costInOption = document.createElement('div'); 8758 costInOption.textContent = guest.name + ': ' + /**object._format.formatCost(costsWithKey[guest.costInServices], object._currency) + ' * ' +**/ guest.selectedName; 8759 costPerOptions.appendChild(costInOption); 8760 8761 } 8762 8763 } 8764 8765 } 8766 8767 } else { 8768 8769 //amount1 = costsWithKey['cost_1']; 8770 //amount2 = 0; 8771 8772 } 8773 8774 optionPanel.onclick = function() { 8775 8776 var serviceKey = this.getAttribute('data-serviceKey'); 8777 var optionKey = this.getAttribute('data-optionKey'); 8778 var costPerOptions = document.getElementById('costPerOptions_' + serviceKey + '_' + optionKey); 8779 if (costPerOptions.classList.contains('hidden_panel') === true) { 8780 8781 costPerOptions.classList.remove('hidden_panel'); 8782 8783 } else { 8784 8785 costPerOptions.classList.add('hidden_panel'); 8786 8787 } 8788 8789 }; 8790 8791 } else { 8792 8793 amount2 = 0; 8794 8795 } 8796 8797 if (hasReflectService === true) { 8798 8799 amount2 = 0; 8800 8801 } 8802 8803 var goods = {label: option.name, amount: amount1 + amount2, applicantCount: applicantCount}; 8804 goodsList.push(goods); 8805 totalCost += amount1 + amount2; 8806 optionAmount = amount1 + amount2; 8807 8808 if (showAumontOnService === false) { 8809 8810 if (responseCosts.max != null && isNaN(parseInt(responseCosts.max)) === false && parseInt(responseCosts.max) != 0) { 8811 8812 var cost = object._format.formatCost(costsWithKey.cost_1, object._currency) + ' '; 8813 if (responseCosts.hasMultipleCosts === true) { 8814 8815 //cost = object._i18n.get('%s to %s', [object._format.formatCost(responseCosts.min, object._currency), object._format.formatCost(responseCosts.max, object._currency)]); 8816 //object.createmMximumAndMinimumElements(responseCosts, optionPricePanel); 8817 optionPricePanel.textContent = object._i18n.get('%s to %s', [object._format.formatCost(responseCosts.min, object._currency), object._format.formatCost(responseCosts.max, object._currency)]); 8818 8819 } else { 8820 8821 optionPricePanel.textContent = cost; 8822 8823 } 8824 8825 } 8826 8827 } else { 8828 8829 optionPricePanel.textContent = object._format.formatCost(optionAmount, object._currency); 8830 8831 8832 } 8833 8834 var reflectServicePanel = document.createElement('span'); 8835 reflectServicePanel.classList.add('reflectPanel'); 8836 if (reflectService > 0) { 8837 8838 //reflectServicePanel.textContent = ' * ' + reflectServiceTitle; 8839 8840 } 8841 8842 optionPanel.appendChild(optionNamePanel); 8843 optionPanel.appendChild(optionPricePanel); 8844 optionPanel.appendChild(reflectServicePanel); 8845 8846 var li = document.createElement("li"); 8847 /** 8848 li.appendChild(optionNamePanel); 8849 li.appendChild(optionPricePanel); 8850 li.appendChild(reflectServicePanel); 8851 **/ 8852 li.appendChild(optionPanel); 8853 li.appendChild(costPerOptions); 8854 ul.appendChild(li); 8855 8856 } 8857 8858 } 8859 8860 } 8861 8862 } 8863 8864 8865 } 8866 8867 } else { 8868 8869 console.error("option = " + option); 8870 8871 } 8872 8873 if (totalCost === 0) { 8874 8875 var planPrices = courseLinePanel.querySelectorAll('.planPrice'); 8876 for (var i = 0; i < planPrices.length; i++) { 8877 8878 object._console.log(planPrices[i]); 8879 planPrices[i].classList.add('hidden_panel'); 8880 8881 } 8882 8883 } 8884 8885 return {services: services, goodsList: goodsList, totalCost: totalCost}; 8886 8887 }; 8888 8889 8890 8891}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.