1 function Booking_App_Calendar(weekName, dateFormat, positionOfWeek, positionTimeDate, startOfWeek, i18n, debug) { 2 3 var object = this; 4 this._console = {}; 5 this._console.log = console.log; 6 if (debug != null && typeof debug.getConsoleLog == 'function') { 7 8 this._console.log = debug.getConsoleLog(); 9 10 } 11 12 this._clock = 24; 13 this._i18n = null; 14 this._stopToCreateCalendar = false; 15 this._startOfWeek = parseInt(startOfWeek); 16 if (typeof i18n == 'object') { 17 18 this._i18n = i18n; 19 20 } 21 22 this._weekClassName = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']; 23 //this.setWeekNameList(weekName); 24 this._weekName = weekName; 25 if (dateFormat != null) { 26 27 this._dateFormat = dateFormat; 28 29 } else { 30 31 this._dateFormat = 0; 32 33 } 34 35 if (positionOfWeek == null) { 36 37 this._positionOfWeek = "before"; 38 39 } else { 40 41 this._positionOfWeek = positionOfWeek; 42 43 } 44 45 if (positionTimeDate == null) { 46 47 this._positionTimeDate = "dateTime"; 48 49 } else { 50 51 this._positionTimeDate = positionTimeDate; 52 53 } 54 55 this._shortWeekNameBool = false; 56 this._shortMonthNameBool = false; 57 this._element = new Booking_Package_Elements(debug); 58 59 }; 60 61 Booking_App_Calendar.prototype.setClock = function(clock) { 62 63 this._clock = clock; 64 65 }; 66 67 Booking_App_Calendar.prototype.setStopToCreateCalendar = function(bool){ 68 69 this._stopToCreateCalendar = bool; 70 71 }; 72 73 Booking_App_Calendar.prototype.setShortWeekNameBool = function(bool){ 74 75 this._shortWeekNameBool = bool; 76 77 }; 78 79 Booking_App_Calendar.prototype.setShortMonthNameBool = function(bool){ 80 81 this._shortMonthNameBool = bool; 82 83 }; 84 85 Booking_App_Calendar.prototype.setWeekNameList = function(weekName){ 86 87 this._weekName = weekName; 88 89 }; 90 91 Booking_App_Calendar.prototype.getWeekNameList = function(startOfWeek){ 92 93 var object = this; 94 var weekClassName = [] 95 var weekName = []; 96 for (var i = 0; i < this._weekName.length; i++) { 97 98 weekClassName[i] = this._weekClassName[i]; 99 weekName[i] = this._weekName[i]; 100 101 } 102 //Object.assign(weekName, this._weekName); 103 for (var i = 0; i < startOfWeek; i++) { 104 105 weekClassName.push(weekClassName[i]); 106 weekName.push(weekName[i]); 107 108 } 109 110 for (var i = 0; i < startOfWeek; i++) { 111 112 weekClassName.shift(); 113 weekName.shift(); 114 115 } 116 117 object._console.log(weekName); 118 return {weekName: weekName, weekClassName: weekClassName}; 119 120 }; 121 122 Booking_App_Calendar.prototype.createHeader = function(month, year, enableFixCalendar, subMonth) { 123 124 var object = this; 125 object._console.log(year + "/" + month); 126 var datePanel = object._element.create('div', object.formatBookingDate(month, null, year, null, null, null, null, 'text'), null, 'current_date_in_header', null, 'calendarData', null); 127 128 var retrunMonth = document.createElement('span'); 129 if (month == 1) { 130 131 retrunMonth.textContent = object.formatBookingDate(12, null, null, null, null, null, null, 'text'); 132 133 } else { 134 135 retrunMonth.textContent = object.formatBookingDate((parseInt(month) - 1), null, null, null, null, null, null, 'text'); 136 137 } 138 var arrowRight = object._element.create('div', 'keyboard_arrow_left', null, null, "font-family: 'Material Icons' !important;", 'material-icons arrowFont', null); 139 var returnLabel = object._element.create('label', null, [arrowRight, retrunMonth], 'change_calendar_return', null, 'arrowLeft', {action: 'return'} ); 140 141 var nextMonth = document.createElement('span'); 142 if (month == 12) { 143 144 nextMonth.textContent = object.formatBookingDate(1, null, null, null, null, null, null, 'text'); 145 146 } else { 147 148 nextMonth.textContent = object.formatBookingDate((parseInt(month) + 1), null, null, null, null, null, null, 'text'); 149 150 } 151 var arrowLeft = object._element.create('div', 'keyboard_arrow_right', null, null, "font-family: 'Material Icons' !important;", 'material-icons arrowFont', null); 152 var nextLabel = object._element.create('label', null, [nextMonth, arrowLeft], 'change_calendar_next', null, 'arrowRight', {action: 'next'} ); 153 154 if (subMonth === false) { 155 156 retrunMonth.textContent = null; 157 nextMonth.textContent = null; 158 159 } 160 161 if (enableFixCalendar == 1) { 162 163 returnLabel.textContent = null; 164 nextLabel.textContent = null; 165 166 } 167 168 var calendarHeaderPanel = object._element.create('div', null, [returnLabel, datePanel, nextLabel], null, null, 'calendarHeader', null); 169 return calendarHeaderPanel; 170 171 }; 172 173 Booking_App_Calendar.prototype.create = function(calendarPanel, calendarData, month, day, year, permission, callback){ 174 175 var object = this; 176 var dayHeight = parseInt(calendarPanel.clientWidth / 7); 177 var nationalHoliday = {}; 178 if (calendarData.nationalHoliday != null && calendarData.nationalHoliday.calendar) { 179 180 nationalHoliday = calendarData.nationalHoliday.calendar; 181 182 } 183 184 var weekNamePanel = object._element.create('div', null, null, null, null, 'calendar', null); 185 var getWeekNameList = this.getWeekNameList(this._startOfWeek); 186 var weekName = getWeekNameList.weekName; 187 var weekClassName = getWeekNameList.weekClassName; 188 for (var i = 0; i < 7; i++) { 189 190 var dayPanel = object._element.create('div', this._i18n.get(weekName[i]), null, null, null, "week_slot " + weekClassName[i].toLowerCase(), null); 191 weekNamePanel.insertAdjacentElement("beforeend", dayPanel); 192 193 } 194
195 calendarPanel.insertAdjacentElement("beforeend", weekNamePanel); 196 if (calendarData['date']['lastDay'] == null || calendarData['date']['startWeek'] == null || calendarData['date']['lastWeek'] == null) { 197 198 window.alert("There is not enough information to create a calendar."); 199 return null; 200 201 } 202 203 var lastDay = parseInt(calendarData['date']['lastDay']); 204 var startWeek = parseInt(calendarData['date']['startWeek']); 205 var lastWeek = parseInt(calendarData['date']['lastWeek']); 206 207 var weekCount = 0; 208 var calendar = calendarData.calendar; 209 var scheduleList = calendarData.schedule; 210 211 var weekLine = Object.keys(calendar).length / 7; 212 object._console.log(calendarData); 213 object._console.log(calendar); 214 var index = 0; 215 for (var key in calendar) { 216 var className = 'day_slot'; 217 var dataKey = parseInt(calendar[key].year + ("0" + calendar[key].month).slice(-2) + ("0" + calendar[key].day).slice(-2)); 218 var bool = 1; 219 220 var textPanel = object._element.create('div', calendar[key].day, null, null, null, 'dateField', null); 221 var dayPanel = object._element.create('div', null, [textPanel], "booking-package-day-" + index, null, className + ' ' + weekName[parseInt(calendar[key].week)], {select: 1, day: calendar[key].day, month: calendar[key].month, year: calendar[key].year, key: key, week: weekCount} ); 222 if (calendar[key].week != null) { 223 224 dayPanel.setAttribute("data-week", calendar[key].week); 225 226 } 227 weekNamePanel.insertAdjacentElement("beforeend", dayPanel); 228 229 var data = {key: dataKey, week: parseInt(calendar[key].week), month: calendar[key].month, day: calendar[key].day, year: calendar[key].year, eventPanel: dayPanel, status: true, stop: 0, count: i, bool: bool, index: index, publishingDate: null}; 230 231 if (calendar[dataKey].status != null) { 232 233 data.status = calendar[dataKey].status; 234 235 } 236 237 if (calendar[key].stop != null) { 238 239 data.stop = calendar[key].stop; 240 241 } 242 243 if (calendar[key].publishingDate != null) { 244 245 data.publishingDate = calendar[key].publishingDate; 246 247 } 248 249 if (scheduleList != null) { 250 251 (function(data, schedule){ 252 253 var capacity = 0; 254 var remainder = 0; 255 for (var key in schedule) { 256 257 capacity += parseInt(schedule[key].capacity); 258 remainder += parseInt(schedule[key].remainder); 259 260 } 261 262 data.capacity = capacity; 263 data.remainder = remainder; 264 265 })(data, scheduleList[key]); 266 267 } 268 269 if (this._stopToCreateCalendar == true) { 270 271 break; 272 273 } 274 275 if (calendarData.calendar[dataKey] != null || (calendarData.reservation != null && calendarData.reservation[dataKey])) { 276 277 var weekClass = ""; 278 if (calendar[key].week != null) { 279 280 weekClass = this._weekClassName[parseInt(calendar[key].week)].toLowerCase() 281 282 } 283 284 if (nationalHoliday[key] != null && parseInt(nationalHoliday[key].status) == 1) { 285 286 weekClass += " nationalHoliday"; 287 288 } 289 290 dayPanel.setAttribute("class", "day_slot available_day " + weekClass); 291 292 data.status = true; 293 if (calendar[dataKey].status != null) { 294 295 data.status = calendar[dataKey].status; 296 297 } 298 callback(data); 299 300 } else { 301 302 dayPanel.setAttribute("class", "day_slot closeDay"); 303 304 if (parseInt(weekLine) == 1) { 305 306 dayPanel.setAttribute("class", "border_bottom_width day_slot closeDay"); 307 308 } 309 310 data.status = false;
311 if (calendar[dataKey].status != null) { 312 313 data.status = calendar[dataKey].status; 314 315 } 316 callback(data); 317 318 } 319 320 if (weekCount == 6) { 321 322 var style = dayPanel.getAttribute("style"); 323 if (style == null) { 324 325 style = ""; 326 327 } 328 329 } 330 331 if (weekCount == 6) { 332 333 weekCount = 0; 334 weekLine--; 335 336 } else { 337 338 weekCount++; 339 340 } 341 342 index++; 343 344 } 345 346 return true; 347 348 }; 349 350 Booking_App_Calendar.prototype.getExpressionsCheck = function(calendarAccount, customizeLabelsBool) { 351 352 /** 353 var i18n = new I18n(this._i18n._locale); 354 i18n.setDictionary(this._i18n._dictionary); 355 **/ 356 357 var expressionsCheck = parseInt(calendarAccount.expressionsCheck); 358 359 var response = { 360 arrival: this._i18n.get("Arrival (Check-in)"), 361 chooseArrival: this._i18n.get("Select a Date"), 362 departure: this._i18n.get("Departure (Check-out)"), 363 chooseDeparture: this._i18n.get("Select a Date"), 364 365 }; 366 367 if (expressionsCheck == 1) { 368 369 response.arrival = this._i18n.get("Arrival"); 370 response.departure = this._i18n.get("Departure"); 371 response.chooseArrival = this._i18n.get("Select a Date"); 372 response.chooseDeparture = this._i18n.get("Select a Date"); 373 374 } else if (expressionsCheck == 2) { 375 376 response.arrival = this._i18n.get("Check-in"); 377 response.departure = this._i18n.get("Check-out"); 378 response.chooseArrival = this._i18n.get("Select a Date"); 379 response.chooseDeparture = this._i18n.get("Select a Date"); 380 381 } 382 383 if (parseInt(calendarAccount.customizeLabelsBool) === 1 && customizeLabelsBool === true) { 384 385 response = { 386 arrival: calendarAccount.customizeLabels['Check-in'], 387 chooseArrival: calendarAccount.customizeLabels['Select a Date'], 388 departure: calendarAccount.customizeLabels['Check-out'], 389 chooseDeparture: calendarAccount.customizeLabels['Select a Date'], 390 } 391 392 } 393 394 return response; 395 396 }; 397 398 Booking_App_Calendar.prototype.getDateKey = function(month, day, year){ 399 400 var key = year + ("0" + month).slice(-2) + ("0" + day).slice(-2); 401 return key; 402 403 }; 404 405 Booking_App_Calendar.prototype.formatBookingDate = function(month, day, year, hour, min, title, week, responseType){ 406 407 var object = this; 408 var i18n = this._i18n; 409 var dateFormat = this._dateFormat; 410 var print_am_pm = ""; 411 if (typeof title == "string") { 412 413 title = title.replace(/\\/g, ""); 414 415 } 416 object._console.log("dateFormat = " + dateFormat + " month = " + month + " day = " + day + " year = " + year + " hour = " + hour + " min = " + min + " week = " + week); 417 if (month != null) { 418 419 month = ("0" + month).slice(-2); 420 421 } 422 423 if (day != null) { 424 425 day = ("0" + day).slice(-2); 426 427 } 428 429 if (hour != null) { 430 431 if (object._clock == "12a.m.p.m") { 432 433 print_am_pm = " a.m."; 434 if (hour > 12) { 435 436 print_am_pm = " p.m."; 437 hour -= 12; 438 439 } else if (hour == 12) { 440 441 print_am_pm = " p.m."; 442 hour = 12; 443 444 } else if (hour == 0) { 445 446 hour = 12; 447 448 } 449 450 } else if (object._clock == "12ampm") { 451 452 print_am_pm = " am"; 453 if (hour > 12) { 454 455 print_am_pm = " pm"; 456 hour -= 12; 457 458 } else if (hour == 12) { 459 460 print_am_pm = " pm"; 461 hour = 12; 462 463 } else if (hour == 0) { 464 465 hour = 12; 466 467 } 468 469 } else if (object._clock == "12AMPM") { 470 471 print_am_pm = " AM"; 472 if (hour > 12) { 473 474 print_am_pm = " PM"; 475 hour -= 12; 476 477 } else if (hour == 12) { 478 479 print_am_pm = " PM"; 480 hour = 12; 481 482 } else if (hour == 0) { 483 484 hour = 12; 485 486 } 487 488 } 489 490 hour = ("0" + hour).slice(-2); 491 492 } 493 494 if (min != null) { 495 496 min = ("0" + min).slice(-2); 497 498 } 499 500 if (week != null) { 501 502 week = parseInt(week); 503 504 } 505 506 if (month != null && day == null && year == null) { 507 508 date = month; 509 if (dateFormat == 2 || dateFormat == 5 || dateFormat == 9 || dateFormat == 10 || dateFormat == 11 || dateFormat == 12) { 510 511 var monthShortName = ['', i18n.get('Jan'), i18n.get('Feb'), i18n.get('Mar'), i18n.get('Apr'), i18n.get('May'), i18n.get('Jun'), i18n.get('Jul'), i18n.get('Aug'), i18n.get('Sep'), i18n.get('Oct'), i18n.get('Nov'), i18n.get('Dec')]; 512 date = monthShortName[parseInt(month)]; 513 514 } 515 return date; 516 517 } 518 519 //var weekName = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; 520 var weekName = [i18n.get('Sunday'), i18n.get('Monday'), i18n.get('Tuesday'), i18n.get('Wednesday'), i18n.get('Thursday'), i18n.get('Friday'), i18n.get('Saturday')]; 521 //weekName = this._weekName; 522 if (this._shortWeekNameBool == true) { 523 524 weekName = [i18n.get('Sun'), i18n.get('Mon'), i18n.get('Tue'), i18n.get('Wed'), i18n.get('Thu'), i18n.get('Fri'), i18n.get('Sat')]; 525 526 } 527 var monthFullName = ['', i18n.get('January'), i18n.get('February'), i18n.get('March'), i18n.get('April'), i18n.get('May'), i18n.get('June'), i18n.get('July'), i18n.get('August'), i18n.get('September'), i18n.get('October'), i18n.get('November'), i18n.get('December')]; 528 if (this._shortMonthNameBool == true) { 529 530 monthFullName = ['', i18n.get('Jan'), i18n.get('Feb'), i18n.get('Mar'), i18n.get('Apr'), i18n.get('May'), i18n.get('Jun'), i18n.get('Jul'), i18n.get('Aug'), i18n.get('Sep'), i18n.get('Oct'), i18n.get('Nov'), i18n.get('Dec')]; 531 532 } 533 534 var date = monthFullName[parseInt(month)] + " " + day + ", " + year + " "; 535 536 if (dateFormat == 0) { 537 538 date = month + "/" + day + "/" + year + " "; 539 if (day == null) { 540 541 date = month + "/" + year; 542 543 } 544 545 } else if (dateFormat == 1) { 546 547 date = month + "-" + day + "-" + year + " "; 548 if (day == null) { 549 550 date = month + "-" + year; 551 552 } 553 554 } else if (dateFormat == 2) { 555 556 date = monthFullName[parseInt(month)] + " " + day + ", " + year + ""; 557 if (day == null) { 558 559 date = monthFullName[parseInt(month)] + ", " + year; 560 561 } 562 563 } else if (dateFormat == 3) { 564 565 date = day + "/" + month + "/" + year + " "; 566 if (day == null) { 567 568 date = month + "/" + year; 569 570 } 571 572 } else if (dateFormat == 4) { 573 574 date = day + "-" + month + "-" + year + " "; 575 if (day == null) { 576 577 date = month + "-" + year; 578 579 } 580 581 } else if (dateFormat == 5) { 582 583 date = day + " " + monthFullName[parseInt(month)] + ", " + year + ""; 584 if (day == null) { 585 586 date = monthFullName[parseInt(month)] + ", " + year; 587 588 } 589 590 } else if (dateFormat == 6) { 591 592 date = year + "/" + month + "/" + day + " "; 593 if (day == null) { 594 595 date = year + "/" + month; 596 597 } 598 599 } else if (dateFormat == 7) { 600 601 date = year + "-" + month + "-" + day + " "; 602 if (day == null) { 603 604 date = year + "-" + month; 605 606 } 607 608 } else if (dateFormat == 8) { 609 610 date = day + "." + month + "." + year + " "; 611 if (day == null) { 612 613 date = month + "." + year; 614 615 } 616 617 } else if (dateFormat == 9) { 618 619 date = day + "." + month + "." + year + " "; 620 if (day == null) { 621 622 date = monthFullName[parseInt(month)] + "." + year; 623 624 } 625 626 } else if (dateFormat == 10) { 627 628 date = day + "." + monthFullName[parseInt(month)] + "." + year + " "; 629 if (day == null) { 630 631 date = monthFullName[parseInt(month)] + "." + year; 632 633 } 634 635 } else if (dateFormat == 11) { 636 637 date = monthFullName[parseInt(month)] + " " + day + " " + year + ""; 638 if (day == null) { 639 640 date = monthFullName[parseInt(month)] + " " + year; 641 642 } 643 644 } else if (dateFormat == 12) { 645 646 date = day + " " + monthFullName[parseInt(month)] + " " + year + ""; 647 if (day == null) { 648 649 date = monthFullName[parseInt(month)] + " " + year; 650 651 } 652 653 } else if (dateFormat == 13) { 654 655 date = day + "." + month + "." + year + ""; 656 if (day == null) { 657 658 date = monthFullName[parseInt(month)] + " " + year; 659 660 } 661 662 } else if (dateFormat == 14) { 663 664 date = day + "." + monthFullName[parseInt(month)] + "." + year + ""; 665 if (day == null) { 666 667 date = monthFullName[parseInt(month)] + " " + year; 668 669 } 670 671 } else if (dateFormat == 15) { 672 673 date = year + "å¹´" + month + "æ" + day + "æ¥ "; 674 //date = year + i18n.get('Year') + month + i18n.get('Month') + day + i18n.get('Day') + ' '; 675 if (day == null) { 676 677 date = year + "å¹´" + month + "æ"; 678 //date = year + i18n.get('Year') + month + i18n.get('Month'); 679 680 } 681 682 } else { 683 684 } 685 686 if (month == null && day != null && year == null) { 687 688 date = day; 689 690 } 691 692 if (this._positionOfWeek == 'before') { 693 694 if (dateFormat != 2 && week != null) { 695 696 date = this._i18n.get(weekName[week]) + " " + date; 697 698 } else if (dateFormat == 2 && week != null) { 699 700 date = this._i18n.get(weekName[week]) + " " + date; 701 702 } 703 704 } else { 705 706 if (dateFormat != 2 && week != null) { 707 708 date = date + " " + this._i18n.get(weekName[week]) + ""; 709 710 } else if (dateFormat == 2 && week != null) { 711 712 date = date + " " + this._i18n.get(weekName[week]) + ""; 713 714 } 715 716 } 717 718 if (responseType == 'elements') { 719 720 var dateLabel = object._element.create('span', date, null, null, null, 'bookingDate', null); 721 var timeLabel = object._element.create('span', i18n.get("%s:%s" + print_am_pm, [hour, min]), null, null, null, 'bookingTime', null); 722 var bookingSubtitleLabel = object._element.create('span', null, null, null, null, 'bookingSubtitle', null); 723 if (title != null) { 724 725 bookingSubtitleLabel.textContent = ' ' + title + ' '; 726 727 } 728 729 var bookingDateAndTime = object._element.create('div', null, null, null, null, null, null); 730 if (object._positionTimeDate == 'dateTime') { 731 732 dateLabel.textContent = date + ', ' 733 bookingDateAndTime.appendChild(dateLabel); 734 bookingDateAndTime.appendChild(timeLabel); 735 bookingDateAndTime.appendChild(bookingSubtitleLabel); 736 737 } else { 738 739 bookingDateAndTime.appendChild(timeLabel); 740 bookingDateAndTime.appendChild(bookingSubtitleLabel); 741 bookingSubtitleLabel.textContent = null; 742 if (title != null && title.length > 0) { 743 744 bookingSubtitleLabel.textContent = ' ' + title + ', '; 745 746 } else { 747 748 bookingSubtitleLabel.textContent = ', ' 749 750 } 751 bookingDateAndTime.appendChild(dateLabel); 752 753 } 754 755 756 return {date: dateLabel, time: timeLabel, dateAndTime: bookingDateAndTime}; 757 758 } else { 759 760 if (object._positionTimeDate == 'dateTime') { 761 762 if (hour != null && min != null) { 763 764 date += i18n.get(", %s:%s " + print_am_pm, [hour, min]); 765 766 } 767 768 if (title != null) { 769 770 date += title; 771 772 } 773 774 } else { 775 776 if (title != null && title.length > 0) { 777 778 title = ' ' + title; 779 780 } 781 782 if (hour != null && min != null) { 783 784 date = i18n.get("%s:%s" + print_am_pm, [hour, min]) + title + ', ' + date; 785 786 } 787 788 } 789 790 return date; 791 792 } 793 794 }; 795 796 Booking_App_Calendar.prototype.getPrintTime = function(hour, min) { 797 798 var object = this; 799 var time = hour + ":" + min; 800 if (object._clock == '12a.m.p.m') { 801 802 hour = parseInt(hour); 803 var print_am_pm = "a.m."; 804 if (hour > 12) { 805 806 print_am_pm = "p.m."; 807 hour -= 12; 808 809 } else if (hour == 12) { 810 811 print_am_pm = "p.m."; 812 hour = 12; 813 814 } else if (hour == 0) { 815 816 hour
816 = 12; 817 818 } 819 820 hour = ("0" + hour).slice(-2); 821 time = object._i18n.get("%s:%s " + print_am_pm, [hour, min]); 822 823 } else if (object._clock == '12ampm') { 824 825 hour = parseInt(hour); 826 var print_am_pm = "am"; 827 if (hour > 12) { 828 829 print_am_pm = "pm"; 830 hour -= 12; 831 832 } else if (hour == 12) { 833 834 print_am_pm = "pm"; 835 hour = 12; 836 837 } else if (hour == 0) { 838 839 hour = 12; 840 841 } 842 843 hour = ("0" + hour).slice(-2); 844 time = object._i18n.get("%s:%s " + print_am_pm, [hour, min]); 845 846 } else if (object._clock == '12AMPM') { 847 848 hour = parseInt(hour); 849 var print_am_pm = "AM"; 850 if (hour > 12) { 851 852 print_am_pm = "PM"; 853 hour -= 12; 854 855 } else if (hour == 12) { 856 857 print_am_pm = "PM"; 858 hour = 12; 859 860 } else if (hour == 0) { 861 862 hour = 12; 863 864 } 865 866 hour = ("0" + hour).slice(-2); 867 time = object._i18n.get("%s:%s " + print_am_pm, [hour, min]); 868 869 } 870 871 object._console.log(time); 872 return time; 873 874 875 } 876 877 Booking_App_Calendar.prototype.adjustmentSchedules = function(calendarData, calendarKey, i, courseTime, rejectionTime, preparationTime){ 878 879 var object = this; 880 (function(schedule, key, courseTime, rejectionTime, preparationTime, callback){ 881 882 object._console.log(key); 883 var stopUnixTime = parseInt(schedule[key].unixTime); 884 if (schedule[key].stop == 'false') { 885 886 stopUnixTime += preparationTime * 60; 887 888 } 889 object._console.log("stopUnixTime = " + stopUnixTime); 890 891 for(var i = 0; i < schedule.length; i++){ 892 893 var time = parseInt(schedule[i]["hour"]) * 60 + parseInt(schedule[i]["min"]); 894 if (time > rejectionTime && i < key) { 895 896 object._console.log("i = " + i + " hour = " + schedule[i]["hour"] + " min = " + schedule[i]["min"]); 897 callback(i); 898 899 } else if (parseInt(schedule[i].unixTime) <= stopUnixTime && i > key) { 900 901 object._console.log("i = " + i + " hour = " + schedule[i]["hour"] + " min = " + schedule[i]["min"]); 902 callback(i); 903 904 } else if (parseInt(schedule[i].unixTime) >= stopUnixTime) { 905 906 break; 907 908 } 909 910 } 911 912 })(calendarData['schedule'][calendarKey], i, courseTime, rejectionTime, preparationTime, function(key){ 913 914 object._console.log("callback key = " + key); 915 calendarData['schedule'][calendarKey][key]["select"] = false; 916 917 }); 918 919 } 920 921 Booking_App_Calendar.prototype.holidayPanel = function(mode, holidayPanel, calendarPanel, month, year, regularHolidays, callback) { 922 923 var object = this; 924 object._console.log("holidayPanel"); 925 calendarPanel.textContent = null; 926 calendarPanel.classList.remove("hidden_panel"); 927 holidayPanel.classList.remove("hidden_panel"); 928 929 var dayHeight = parseInt(calendarPanel.clientWidth / 7); 930 object._console.log("dayHeight = " + dayHeight); 931 932 var returnLabel = document.createElement("label"); 933 var nextLabel = document.createElement("label"); 934 var topPanel = object.createHeader(month, year, 0, true); 935 if (topPanel.querySelector('#change_calendar_return') != null) { 936 937 returnLabel = topPanel.querySelector('#change_calendar_return'); 938 939 } 940 941 if (topPanel.querySelector('#change_calendar_next') != null) { 942 943 nextLabel = topPanel.querySelector('#change_calendar_next'); 944 945 } 946 947 calendarPanel.appendChild(topPanel); 948 949 object.create(calendarPanel, regularHolidays, month, 1, year, '', function(callbackOnDay){ 950 951 object._console.log(callbackOnDay); 952 var key = callbackOnDay.key; 953 var holiday = regularHolidays.calendar[key]; 954 if (parseInt(holiday.status) == 1) { 955 956 callbackOnDay.eventPanel.classList.add("selected_day_slot"); 957 958 } 959 960 callbackOnDay.eventPanel.onclick = function(){ 961 962 var dayPanel = this; 963 var key = dayPanel.getAttribute("data-key"); 964 var holiday = regularHolidays.calendar[key]; 965 object._console.log(key); 966 object._console.log(regularHolidays.calendar); 967 object._console.log(holiday); 968 var postData = {mode: 'updateRegularHolidays', /**nonce: object._nonce, action: object._action,**/ accountKey: mode, day: holiday.day, month: holiday.month, year: holiday.year, month_calendar: regularHolidays.date.month, year_calendar: regularHolidays.date.year, status: 0}; 969 if (parseInt(holiday.status) == 0) { 970 971 postData.status = 1; 972 973 } 974 object._console.log(postData); 975 var loadingPanel = document.getElementById("loadingPanel"); 976 loadingPanel.classList.remove("hidden_panel"); 977 callback(postData, function(status, regularHolidays) { 978 979 object._console.log(close); 980 if (status === true) { 981 982 loadingPanel.classList.add("hidden_panel"); 983 object.holidayPanel(mode, holidayPanel, calendarPanel, month, year, regularHolidays, callback); 984 985 } 986 987 }); 988 989 }; 990 991 }); 992 993 returnLabel.onclick = function(){ 994 995 if (month == 1) { 996 997 year--;
998 month = 12; 999 1000 } else { 1001 1002 month--; 1003 1004 } 1005 1006 var postData = {mode: 'getRegularHolidays', /**nonce: object._nonce, action: object._action,**/ accountKey: mode, month: month, year: year}; 1007 var loadingPanel = document.getElementById("loadingPanel"); 1008 loadingPanel.classList.remove("hidden_panel"); 1009 callback(postData, function(status, regularHolidays) { 1010 1011 object._console.log(close); 1012 if (status === true) { 1013 1014 loadingPanel.classList.add("hidden_panel"); 1015 object.holidayPanel(mode, holidayPanel, calendarPanel, month, year, regularHolidays, callback); 1016 1017 } 1018 1019 }); 1020 1021 }; 1022 1023 nextLabel.onclick = function(){ 1024 1025 if (month == 12) { 1026 1027 year++; 1028 month = 1; 1029 1030 } else { 1031 1032 month++; 1033 1034 } 1035 1036 var postData = {mode: 'getRegularHolidays', /**nonce: object._nonce, action: object._action,**/ accountKey: mode, month: month, year: year}; 1037 var loadingPanel = document.getElementById("loadingPanel"); 1038 loadingPanel.classList.remove("hidden_panel"); 1039 callback(postData, function(status, regularHolidays) { 1040 1041 object._console.log(close); 1042 if (status === true) { 1043 1044 loadingPanel.classList.add("hidden_panel"); 1045 object.holidayPanel(mode, holidayPanel, calendarPanel, month, year, regularHolidays, callback); 1046 1047 } 1048 1049 }); 1050 1051 }; 1052 1053 } 1054 1055 Booking_App_Calendar.prototype.createCalendarData = function(month, year) { 1056 1057 //month = 1; 1058 month--; 1059 var object = this; 1060 var nextMonthDate = new Date(year, month + 1, 0); 1061 var lastDay = nextMonthDate.getDate(); 1062 var date = new Date(year, month, 1); 1063 var startWeek = date.getDay(); 1064 date = new Date(year, month, lastDay); 1065 var lastWeek = date.getDay(); 1066 object._console.log(year + ' ' + month + ' ' + 1); 1067 var calendarData = { 1068 date: { 1069 startDay: 1, 1070 month: month + 1, 1071 year: year, 1072 lastDay: lastDay, 1073 startWeek: startWeek, 1074 lastWeek: lastWeek, 1075 }, 1076 calendar: {}, 1077 }; 1078 1079 var lastMonth = month; 1080 var lastYear = year; 1081 if (lastMonth === 0) { 1082 1083 lastMonth = 12; 1084 lastYear--; 1085 1086 } 1087 1088 var lasttMonthDate = new Date(lastYear, lastMonth, 0); 1089 var lastMonthDay = lasttMonthDate.getDate(); 1090 //startWeek = 1; 1091 for (var i = startWeek; i > 0; i--) { 1092 1093 var day = (parseInt(lastMonthDay) - i) + 1; 1094 var lastDate = new Date(lastYear, lastMonth - 1, day); 1095 //var startWeek = lastDate.getDay(); 1096 var key = lastYear + ('0' + (lastMonth)).slice(-2) + ('0' + day).slice(-2); 1097 calendarData.calendar[key] = { 1098 month: lastMonth, 1099 day: day, 1100 year: lastYear, 1101 week: lastDate.getDay(), 1102 accountKey: 0, 1103 count: null, 1104 status: 1, 1105 1106 } 1107 1108 } 1109 1110 for (var i = 1; i <= lastDay; i++) { 1111 1112 var date = new Date(year, month, i); 1113 var key = year + ('0' + (month + 1)).slice(-2) + ('0' + i).slice(-2); 1114 calendarData.calendar[key] = { 1115 month: month + 1, 1116 day: i, 1117 year: year, 1118 week: date.getDay(), 1119 accountKey: 0, 1120 count: null, 1121 status: 1, 1122 1123 } 1124 1125 } 1126 1127 var nextMonth = month + 1; 1128 var nextYear = year; 1129 if (nextMonth === 12) { 1130 1131 nextMonth = 0; 1132 nextYear++; 1133 1134 } 1135 1136 var nextMonthDate = new Date(nextYear, nextMonth + 1, 0); 1137 var nextMonthDay = nextMonthDate.getDate(); 1138 var nextDay = 0; 1139 for (var i = lastWeek; i < 6; i++) { 1140 1141 nextDay++; 1142 var lastDate = new Date(nextYear, nextMonth, nextDay); 1143 //var startWeek = lastDate.getDay(); 1144 var key = nextYear + ('0' + (nextMonth + 1)).slice(-2) + ('0' + (nextDay)).slice(-2); 1145 calendarData.calendar[key] = { 1146 month: nextMonth + 1, 1147 day: nextDay, 1148 year: nextYear, 1149 week: lastDate.getDay(), 1150 accountKey: 0, 1151 count: null, 1152 status: 1, 1153 1154 } 1155 1156 } 1157 1158 object._console.log(calendarData); 1159 return calendarData; 1160 1161 }; 1162 1163 function Booking_App_ObjectsControl(data, booking_package_dictionary, numberFormatter,
1163currency_info) { 1164 1165 this._data = data; 1166 this._prefix = data.prefix; 1167 this._debug = new Booking_Package_Console(data.debug); 1168 this._console = {}; 1169 this._console.log = this._debug.getConsoleLog(); 1170 this._console.error = this._debug.getConsoleError(); 1171 this._i18n = new I18n(data.locale); 1172 this._i18n.setDictionary(booking_package_dictionary); 1173 this._services = data.courseList; 1174 this._nationalHoliday = {}; 1175 this._weekName = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; 1176 this._calendar = new Booking_App_Calendar(this._weekName, this._data.dateFormat, this._data.positionOfWeek, this._data.positionTimeDate, this._data.startOfWeek, this._i18n, this._debug); 1177 this._expirationDate = 0; 1178 this._expirationDateForService = 0; 1179 this._element = new Booking_Package_Elements(0); 1180 this._numberFormatter = false; 1181 if (parseInt(data.numberFormatter) === 1) { 1182 1183 this._numberFormatter = true; 1184 1185 } 1186 this._locale = data.locale; 1187 this._currency = data.currency; 1188 this._currencies = data.currencies; 1189 this._currency_info = {locale: this._locale, currency: this._currency, info: this._currencies[this._currency]}; 1190 this._format = new FORMAT_COST(this._i18n, this._debug, this._numberFormatter, this._currency_info); 1191 1192 1193 }; 1194 1195 Booking_App_ObjectsControl.prototype.setServices = function(services) { 1196 1197 this._services = services; 1198 1199 }; 1200 1201 Booking_App_ObjectsControl.prototype.setExpirationDate = function(expirationDate) { 1202 1203 this._expirationDate = expirationDate; 1204 1205 }; 1206 1207 Booking_App_ObjectsControl.prototype.getExpirationDate = function() { 1208 1209 return this._expirationDate; 1210 1211 }; 1212 1213 Booking_App_ObjectsControl.prototype.setNationalHoliday = function(nationalHoliday) { 1214 1215 this._nationalHoliday = nationalHoliday; 1216 1217 }; 1218 1219 Booking_App_ObjectsControl.prototype.invalidService = function(schedules, bookedServices, service, durationTime, day, month, year) { 1220 1221 var object = this; 1222 object._console.log('invalidServices'); 1223 object._console.log(schedules); 1224 object._console.log(bookedServices); 1225 object._console.log(service); 1226 object._console.log(durationTime); 1227 1228 if (service.stopServiceUnderFollowingConditions == "isNotEqual") { 1229 1230 var startKey = 0; 1231 for (var i = 0; i < schedules.length; i++) { 1232 1233 var schedule = schedules[i]; 1234 //object._console.log(schedule); 1235 if (schedule.select == true && parseInt(schedule.remainder) >= 0) { 1236 1237 if (service.stopServiceUnderFollowingConditions == "isNotEqual") { 1238 1239 if (parseInt(schedule.capacity) != parseInt(schedule.remainder)) { 1240 1241 schedule.select = false; 1242 var startUnixTime = parseInt(schedule.unixTime) - (durationTime * 60); 1243 var endUnixTime = parseInt(schedule.unixTime); 1244 (function(schedules, startKey, endKey, startUnixTime, endUnixTime, service, callback) { 1245 1246 object._console.log('startKey = ' + startKey); 1247 object._console.log(schedules[startKey]); 1248 object._console.log(startUnixTime); 1249 object._console.log(endUnixTime); 1250 if (startKey == null) { 1251 1252 return false; 1253 1254 } 1255 1256 for (var i = startKey; i < endKey; i++) { 1257 1258 if (parseInt(schedules[i].unixTime) > startUnixTime && parseInt(schedules[i].unixTime) < endUnixTime) { 1259 1260 object._console.log(schedules[i]); 1261 callback(i); 1262 1263 } 1264 1265 } 1266 1267 }) (schedules, startKey, i, startUnixTime, endUnixTime, service, function(key) { 1268 1269 schedules[key].select = false;
1270 1271 }); 1272 1273 startKey = null; 1274 1275 } else { 1276 1277 if (startKey == null) { 1278 1279 startKey = i; 1280 1281 } 1282 1283 } 1284 1285 if (service.stopServiceUnderFollowingConditions == "isNotEqual" && service.doNotStopServiceAsException == "sameServiceIsNotStopped") { 1286 1287 var bookedServicesOnDay = bookedServices[parseInt(schedule.ymd)]; 1288 var time = ("0" + schedule.hour).slice(-2) + ("0" + schedule.min).slice(-2); 1289 if (bookedServicesOnDay != null && bookedServicesOnDay[time] != null) { 1290 1291 if (bookedServicesOnDay[time][service.key] != null && bookedServicesOnDay[time][service.key].count != null && parseInt(bookedServicesOnDay[time][service.key].count) > 0) { 1292 1293 object._console.log("time = " + time); 1294 object._console.log(bookedServicesOnDay[time]); 1295 object._console.log(bookedServicesOnDay[time][service.key]); 1296 schedules[i].select = true; 1297 1298 } 1299 1300 } 1301 1302 } 1303 1304 } 1305 1306 } 1307 1308 } 1309 1310 } else if (service.stopServiceUnderFollowingConditions == "isEqual") { 1311 1312 for (var i = 0; i < schedules.length; i++) { 1313 1314 var schedule = schedules[i]; 1315 if (schedule.select == true && parseInt(schedule.remainder) >= 0) { 1316 1317 if (parseInt(schedule.capacity) != parseInt(schedule.remainder)) { 1318 1319 var time = ("0" + schedule.hour).slice(-2) + ("0" + schedule.min).slice(-2); 1320 var startSec = (((parseInt(schedule.hour) * 60) + parseInt(schedule.min)) * 60) /** - (durationTime * 60) **/; 1321 var endSec = (((parseInt(schedule.hour) * 60) + parseInt(schedule.min)) * 60) + (durationTime * 60); 1322 object._console.log(schedule); 1323 (function(schedules, time, service, startSec, endSec, callback) { 1324 1325 object._console.log(time); 1326 object._console.log(service); 1327 object._console.log('startSec = ' + startSec); 1328 object._console.log('endSec = ' + endSec); 1329 var block = false; 1330 var blockScedules = {}; 1331 for (var i = 0; i < schedules.length; i++) { 1332 1333 var schedule = schedules[i]; 1334 var scheduleTime = ("0" + schedule.hour).slice(-2) + ("0" + schedule.min).slice(-2) 1335 var sec = ((parseInt(schedule.hour) * 60) + parseInt(schedule.min)) * 60; 1336 1337 if (sec >= startSec && sec < endSec) { 1338 1339 blockScedules[i] = schedule; 1340 if (parseInt(schedule.capacity) == parseInt(schedule.remainder)) { 1341 1342 block = true; 1343 break; 1344 1345 } 1346 1347 } 1348 1349 } 1350 1351 if (block === true) { 1352 1353 for (var key in blockScedules) { 1354 1355 var schedule = blockScedules[key]; 1356 object._console.log(schedule.hour + ' : ' + schedule.min); 1357 callback(key, false); 1358 1359 } 1360 1361 } 1362 1363 }) (schedules, time, service, startSec, endSec, function(key, bool) { 1364 1365 schedules[key].select = bool; 1366 1367 }); 1368 1369 } else { 1370 1371 schedule.select = false;
1372 1373 } 1374 1375 } 1376 1377 } 1378 /** 1379 for (var i = 0; i < schedules.length; i++) { 1380 1381 var schedule = schedules[i]; 1382 if (schedule.select === true) { 1383 1384 object._console.error(schedule.hour + ' : ' + schedule.min); 1385 1386 } 1387 1388 } 1389 **/ 1390 1391 } else if (service.stopServiceUnderFollowingConditions == "specifiedNumberOfTimes") { 1392 1393 if (service.stopServiceForDayOfTimes == 'startTimeSlot') { 1394 1395 for (var i = 0; i < schedules.length; i++) { 1396 1397 var schedule = schedules[i]; 1398 if (schedule.select == true && parseInt(schedule.remainder) >= 0) { 1399 1400 if (parseInt(schedule.capacity) != parseInt(schedule.remainder)) { 1401 1402 var bookedServicesOnDay = bookedServices[parseInt(schedule.ymd)]; 1403 var time = ("0" + schedule.hour).slice(-2) + ("0" + schedule.min).slice(-2); 1404 if (bookedServicesOnDay != null && bookedServicesOnDay[time] != null) { 1405 console.log('StartTime' + time); 1406 var bookedServicesTimes = bookedServicesOnDay[time]; 1407 object._console.error(bookedServicesTimes); 1408 if (bookedServicesTimes[service.key] != null) { 1409 1410 var startSec = (((parseInt(schedule.hour) * 60) + parseInt(schedule.min)) * 60) - (durationTime * 60); 1411 /** 1412 var startHour = Math.floor(startSec / 3600); 1413 var startMin = Math.floor(startSec % 3600 / 60); 1414 var startTime = ("0" + startHour).slice(-2) + ("0" + startMin).slice(-2); 1415 **/ 1416 1417 var endSec = (((parseInt(schedule.hour) * 60) + parseInt(schedule.min)) * 60) + (bookedServicesTimes[service.key].maximumDurationTime * 60); 1418 /** 1419 var endHour = Math.floor(endSec / 3600); 1420 var endMin = Math.floor(endSec % 3600 / 60); 1421 var endTime = ("0" + endHour).slice(-2) + ("0" + endMin).slice(-2); 1422 **/ 1423 1424 (function(schedules, time, service, bookedServicesTimes, startSec, endSec, callback) { 1425 1426 object._console.log(time); 1427 object._console.log(service); 1428 object._console.log(bookedServicesTimes); 1429 object._console.log('startSec = ' + startSec); 1430 object._console.log('endSec = ' + endSec); 1431 for (var i = 0; i < schedules.length; i++) { 1432 1433 var schedule = schedules[i]; 1434 var scheduleTime = ("0" + schedule.hour).slice(-2) + ("0" + schedule.min).slice(-2); 1435 var sec = ((parseInt(schedule.hour) * 60) + parseInt(schedule.min)) * 60; 1436 if (sec > startSec && sec < endSec) { 1437 1438 console.log('調æ»å¯¾è±¡' + scheduleTime); 1439 if (scheduleTime == time && bookedServicesTimes.count < parseInt(service.stopServiceForSpecifiedNumberOfTimes)) { 1440 1441 1442 callback(i, true); 1443 1444 } else { 1445 1446 console.log(time); 1447 callback(i, false); 1448 1449 } 1450 1451 } 1452 1453 } 1454 1455 }) (schedules, time, service, bookedServicesTimes[service.key], startSec, endSec, function(key, bool) { 1456 1457 schedules[key].select = bool; 1458 1459 }); 1460 1461 object._console.log(bookedServicesOnDay); 1462 1463 } 1464 1465 } 1466 1467 } 1468 1469 } 1470 1471 } 1472 1473 1474 for (var i = 0; i < schedules.length; i++) { 1475 1476 var schedule = schedules[i]; 1477 var scheduleTime = ("0" + schedule.hour).slice(-2) + ("0" + schedule.min).slice(-2); 1478 console.log(scheduleTime + ' ' + schedule.select); 1479 1480 } 1481 1482 } else if (service.stopServiceForDayOfTimes == 'timeSlot') { 1483 1484 function findSlotsCorrected(timeSlots, duration, threshold) { 1485 1486 if (typeof threshold !== 'number' || typeof duration !== 'number' || duration < 0) { 1487 console.error("ã¨ã©ã¼: threshold 㨠duration ã¯é©åã
1487ªæ°å¤ã§ããå¿ è¦ãããã¾ãã"); 1488 return []; 1489 } 1490 1491 const sortedKeys = Object.keys(timeSlots).sort((a, b) => parseInt(String(a).padStart(4, '0'), 10) - parseInt(String(b).padStart(4, '0'), 10)); 1492 const keysAboveThreshold = sortedKeys.filter(key => timeSlots[key] >= threshold); 1493 const resultKeys = new Set(); 1494 function timeToMinutes(timeKey) { 1495 1496 const timeString = String(timeKey).padStart(4, '0'); 1497 const hours = parseInt(timeString.substring(0, 2), 10); 1498 const minutes = parseInt(timeString.substring(2, 4), 10); 1499 if (isNaN(hours) || isNaN(minutes) || timeString.length !== 4) { 1500 1501 return NaN; 1502 1503 } 1504 return hours * 60 + minutes; 1505 1506 } 1507 1508 for (let i = 0; i < keysAboveThreshold.length - 1; i++) { 1509 1510 const key1 = keysAboveThreshold[i]; 1511 const key2 = keysAboveThreshold[i + 1]; 1512 1513 const time1 = timeToMinutes(key1); 1514 const time2 = timeToMinutes(key2); 1515 if (isNaN(time1) || isNaN(time2)) { 1516 1517 continue; 1518 1519 } 1520 1521 const timeDifference = time2 - time1; 1522 if (timeDifference <= duration) { 1523 1524 const startIndex = sortedKeys.indexOf(key1); 1525 const endIndex = sortedKeys.indexOf(key2); 1526 if (startIndex !== -1 && endIndex !== -1 && startIndex < endIndex) { 1527 1528 for (let j = startIndex + 1; j < endIndex; j++) { 1529 1530 const intermediateKey = sortedKeys[j]; 1531 if (timeSlots.hasOwnProperty(intermediateKey) && timeSlots[intermediateKey] < threshold) { 1532 1533 resultKeys.add(String(intermediateKey).padStart(4, '0')); 1534 1535 } 1536 1537 } 1538 1539 } 1540 1541 } 1542 1543 } 1544 1545 return Array.from(resultKeys).sort(); 1546 1547 } 1548 1549 const ymd = year + ("0" + month).slice(-2) + ("0" + day).slice(-2); 1550 let minutes = []; 1551 for (var i = 0; i < 1440; i++) { 1552 1553 minutes.push(0); 1554 1555 } 1556 var bookedServicesOnDay = bookedServices[parseInt(ymd)]; 1557 1558 console.log(ymd); 1559 console.log(schedules); 1560 console.log(minutes); 1561 console.log(bookedServices); 1562 if (bookedServicesOnDay != null) { 1563 1564 1565 const keys = Object.keys(bookedServicesOnDay); 1566 keys.sort((a, b) => { 1567 1568 return parseInt(a, 10) - parseInt(b, 10); 1569 1570 }); 1571 console.log(keys); 1572 console.log(bookedServicesOnDay); 1573 1574 //for (var time in bookedServicesOnDay) { 1575 for (let i = 0; i < keys.length; i++) { 1576 1577 let time = keys[i]; 1578 var bookedServicesTimes = bookedServicesOnDay[time]; 1579 if (bookedServicesTimes[service.key] != null) { 1580 1581 console.log(time); 1582 console.log(bookedServicesTimes[service.key]); 1583 //const startMin = ( (parseInt(time.substring(0, 2)) * 60) + parseInt(time.substring(2, 4)) ) - (bookedServicesTimes[service.key].maximumDurationTime); 1584 let startMin = ( (parseInt(time.substring(0, 2)) * 60) + parseInt(time.substring(2, 4)) ); 1585 let endMin = ( (parseInt(time.substring(0, 2)) * 60) + parseInt(time.substring(2, 4)) ) + (bookedServicesTimes[service.key].maximumDurationTime); 1586 console.log(startMin); 1587 console.log(endMin); 1588 minutes = (function(minutes, startMin, endMin) { 1589 1590 console.log('startMin = ' + minutes[startMin]); 1591 for (let i = startMin; i < endMin; i++) { 1592 1593 //minutes[i]++; 1594 minutes[i] += bookedServicesTimes[service.key].count; 1595 if (i === 690) { 1596 1597 console.error(i); 1598 1599 } 1600 1601 } 1602 1603 if (minutes[startMin] >= parseInt(service.stopServiceForSpecifiedNumberOfTimes)) { 1604 1605 console.log('Limit = ' + minutes[startMin]); 1606 const blockMin = startMin - bookedServicesTimes[service.key].maximumDurationTime + 1; 1607 console.error(blockMin); 1608 for (let i = blockMin; i < startMin; i++) { 1609 1610 minutes[i] = parseInt(service.stopServiceForSpecifiedNumberOfTimes); 1611 1612 } 1613 1614 } 1615 1616 return minutes; 1617 1618 })(minutes, startMin, endMin); 1619 1620 } 1621 1622 } 1623 1624 } 1625 console.log(minutes); 1626 1627 1628 for (var i = 0; i < schedules.length; i++) { 1629 1630 var schedule = schedules[i]; 1631 if (parseInt(schedule.remainder) >= 0) { 1632 1633 var scheduleTime = ("0" + schedule.hour).slice(-2) + ("0" + schedule.min).slice(-2);
1634 const key = (parseInt(schedule.hour) * 60) + parseInt(schedule.min); 1635 if (minutes[key] >= parseInt(service.stopServiceForSpecifiedNumberOfTimes)) { 1636 1637 schedule.select = false; 1638 1639 } 1640 1641 } 1642 1643 } 1644 1645 /** 1646 let timeSlots = {}; 1647 for (var i = 0; i < schedules.length; i++) { 1648 1649 var schedule = schedules[i]; 1650 if (parseInt(schedule.remainder) >= 0) { 1651 1652 let count = 0; 1653 if (parseInt(schedule.capacity) != parseInt(schedule.remainder)) { 1654 1655 var bookedServicesOnDay = bookedServices[parseInt(schedule.ymd)]; 1656 var time = ("0" + schedule.hour).slice(-2) + ("0" + schedule.min).slice(-2); 1657 if (bookedServicesOnDay != null && bookedServicesOnDay[time] != null) { 1658 console.log('StartTime' + time); 1659 var bookedServicesTimes = bookedServicesOnDay[time]; 1660 object._console.error(bookedServicesTimes); 1661 if (bookedServicesTimes[service.key] != null) { 1662 1663 var startSec = (((parseInt(schedule.hour) * 60) + parseInt(schedule.min)) * 60) - (durationTime * 60); 1664 var startServiceSec = (((parseInt(schedule.hour) * 60) + parseInt(schedule.min)) * 60); 1665 var endSec = (((parseInt(schedule.hour) * 60) + parseInt(schedule.min)) * 60) + (bookedServicesTimes[service.key].maximumDurationTime * 60); 1666 1667 (function(schedules, timeSlots, time, service, bookedServicesOnDay, bookedServicesTimes, startServiceSec, startSec, endSec, callback) { 1668 1669 let count = parseInt(bookedServicesTimes.count); 1670 object._console.log(time); 1671 object._console.log(service); 1672 object._console.log(bookedServicesTimes); 1673 object._console.log('startSec = ' + startSec); 1674 object._console.log('endSec = ' + endSec); 1675 1676 console.log('startSec = ' + startSec); 1677 console.log('endSec = ' + endSec); 1678 1679 for (var i = 0; i < schedules.length; i++) { 1680 1681 var schedule = schedules[i]; 1682 var scheduleTime = ("0" + schedule.hour).slice(-2) + ("0" + schedule.min).slice(-2); 1683 var sec = ((parseInt(schedule.hour) * 60) + parseInt(schedule.min)) * 60; 1684 if (sec > startSec && sec < endSec) { 1685 1686 console.log(time); 1687 console.log('調æ»å¯¾è±¡' + scheduleTime); 1688 if (timeSlots[scheduleTime] == null) { 1689 1690 timeSlots[scheduleTime] = bookedServicesTimes.count; 1691 1692 } else { 1693 1694 console.error(scheduleTime); 1695 timeSlots[scheduleTime] += bookedServicesTimes.count; 1696 } 1697 1698 console.log(timeSlots[scheduleTime]); 1699 console.log(bookedServicesTimes.count); 1700 1701 1702 //if (scheduleTime == time && bookedServicesTimes.count < parseInt(service.stopServiceForSpecifiedNumberOfTimes)) { 1703 if (timeSlots[scheduleTime] < parseInt(service.stopServiceForSpecifiedNumberOfTimes)) { 1704 1705 callback(i, true); 1706 1707 } else { 1708 1709 callback(i, false); 1710 1711 } 1712 1713 } 1714 1715 } 1716 1717 }) (schedules, timeSlots, time, service, bookedServicesOnDay, bookedServicesTimes[service.key], startServiceSec, startSec, endSec, function(key, bool) { 1718 1719 schedules[key].select = bool; 1720 1721 }); 1722 1723 object._console.log(bookedServicesOnDay); 1724 1725 } 1726 1727 } 1728 1729 } 1730 1731 } 1732 1733 } 1734 console.log(schedules); 1735 console.log(timeSlots); 1736 **/ 1737 1738 /** 1739 let stopTimeSlots = findSlotsCorrected(timeSlots, durationTime, parseInt(service.stopServiceForSpecifiedNumberOfTimes)); 1740 console.log(stopTimeSlots); 1741 for (var i = 0; i < stopTimeSlots.length; i++) { 1742 1743 const time = stopTimeSlots[i]; 1744 console.log(time);
1745 (function(stopTimeSlot, schedules, callback) { 1746 1747 for (var i = 0; i < schedules.length; i++) { 1748 1749 let schedule = schedules[i]; 1750 var scheduleTime = ("0" + schedule.hour).slice(-2) + ("0" + schedule.min).slice(-2); 1751 if (stopTimeSlot === scheduleTime) { 1752 1753 console.log(schedule); 1754 callback(i, true); 1755 break; 1756 1757 } 1758 1759 } 1760 1761 })(stopTimeSlots[i], schedules, function(key, bool) { 1762 1763 console.log(key); 1764 console.log(bool); 1765 schedules[key].select = false; 1766 1767 }); 1768 1769 } 1770 **/ 1771 1772 for (var i = 0; i < schedules.length; i++) { 1773 1774 var schedule = schedules[i]; 1775 var scheduleTime = ("0" + schedule.hour).slice(-2) + ("0" + schedule.min).slice(-2); 1776 console.log(scheduleTime + ' ' + schedule.select); 1777 1778 } 1779 1780 } else if (service.stopServiceForDayOfTimes == 'day') { 1781 1782 var count = 0; 1783 var schedule = schedules[0]; 1784 var bookedServicesOnDay = bookedServices[parseInt(schedule.ymd)]; 1785 object._console.log(bookedServicesOnDay); 1786 for (var time in bookedServicesOnDay) { 1787 1788 var bookedServices = bookedServicesOnDay[time]; 1789 if (bookedServices[parseInt(service.key)] != null) { 1790 1791 count += bookedServices[parseInt(service.key)].count; 1792 object._console.log(bookedServices[parseInt(service.key)]); 1793 1794 } 1795 1796 } 1797 1798 object._console.log('count = ' + count); 1799 if (count >= parseInt(service.stopServiceForSpecifiedNumberOfTimes)) { 1800 1801 for (var i = 0; i < schedules.length; i++) { 1802 1803 schedules[i].select = false; 1804 1805 } 1806 1807 } 1808 1809 } 1810 1811 } 1812 1813 return schedules; 1814 1815 }; 1816 1817 Booking_App_ObjectsControl.prototype.validExpirationDate = function(expirationDate, expirationDateFrom, expirationDateTo, name) { 1818 1819 var object = this; 1820 var isBooking = true; 1821 1822 if (expirationDateFrom <= expirationDate) { 1823 1824 object._console.error('1 expirationDateFrom = ' + expirationDateFrom + ' ' + name); 1825 1826 } 1827 1828 if (expirationDateTo <= expirationDate) { 1829 1830 object._console.error('1 expirationDateTo = ' + expirationDateTo + ' ' + name); 1831 1832 } 1833 1834 if (expirationDateFrom >= expirationDate) { 1835 1836 object._console.error('2 expirationDateFrom = ' + expirationDateFrom + ' ' + name); 1837 1838 } 1839 1840 if (expirationDateTo >= expirationDate) { 1841 1842 object._console.error('2 expirationDateTo = ' + expirationDateTo + ' ' + name); 1843 1844 } 1845 1846 if (expirationDateFrom != 0 && expirationDateTo != 0 && ((expirationDateFrom <= expirationDate && expirationDateTo < expirationDate) || (expirationDateFrom > expirationDate && expirationDateTo >= expirationDate))) { 1847 1848 isBooking = false; 1849 1850 } 1851 1852 return isBooking; 1853 1854 }; 1855 1856 Booking_App_ObjectsControl.prototype.getSelectedBoxOfGuest = function(guestsList, selectBox) { 1857 1858 var selectedGuestsKey = selectBox.parentElement.getAttribute("data-guset"); 1859 var guests = guestsList[selectedGuestsKey]; 1860 return guests; 1861 1862 } 1863 1864 Booking_App_ObjectsControl.prototype.getSelectedGuestTotalAmount = function(guestsList) { 1865 1866 var object = this; 1867 const response = {totalAmount: 0, labeles: []}; 1868 for (var i = 0; i < guestsList.length; i++) { 1869 1870 const guest = guestsList[i]; 1871 const index = guest.index; 1872 let list = guest.json;
1873 if (typeof guest.json == 'string') { 1874 1875 list = JSON.parse(guest.json); 1876 1877 } 1878 1879 let label = guest.name + ': ' + list[index].name; 1880 if (parseInt(list[index].price) > 0) { 1881 1882 label += ' ' + object._format.formatCost( parseInt( list[index]. price ) , object._currency); 1883 response.totalAmount += parseInt(list[index].price); 1884 //console.log('totalAmount = ' + response.totalAmount); 1885 1886 } 1887 1888 if (index > 0) { 1889 1890 response.labeles.push(label); 1891 1892 } 1893 1894 } 1895 1896 return response; 1897 1898 } 1899 1900 Booking_App_ObjectsControl.prototype.getSelectedGuest = function(guestsList, selectBox, multipleApplicantCountList) { 1901 1902 var object = this; 1903 object._console.log(selectBox); 1904 var selectedGuestsKey = selectBox.parentElement.getAttribute("data-guset"); 1905 1906 var index = parseInt(selectBox.selectedIndex); 1907 var guests = guestsList[selectedGuestsKey]; 1908 var option = selectBox.options[index]; 1909 var optionKey = parseInt(option.getAttribute('data-optionsKey')); 1910 object._console.log(option); 1911 var parentPanel = document.getElementById(object._prefix + 'guests_' + guests.key); 1912 parentPanel.classList.remove('error_empty_value'); 1913 var values = guests.values; 1914 var list = guests.json; 1915 if (typeof guests.json == 'string') { 1916 1917 list = JSON.parse(guests.json); 1918 1919 } 1920 //guests.index = index; 1921 guests.index = optionKey; 1922 guests.selectedName = values[optionKey]; 1923 1924 object._console.log(guests); 1925 object._console.log(values); 1926 object._console.log(selectedGuestsKey); 1927 object._console.log(index); 1928 guests.number = parseInt(list[optionKey].number); 1929 if (guests.guestsInCapacity == 'included') { 1930 1931 object._console.log(values[index]); 1932 object._console.log(list[optionKey]); 1933 multipleApplicantCountList[selectedGuestsKey] = parseInt(list[optionKey].number); 1934 1935 } 1936 1937 var multipleApplicantCount = multipleApplicantCountList.reduce(function(a, b) { 1938 1939 return a + b; 1940 1941 }); 1942 1943 return multipleApplicantCount; 1944 1945 } 1946 1947 Booking_App_ObjectsControl.prototype.excessGuests = function(guests, limit, type) { 1948 1949 var object = this; 1950 object._console.log('excessGuests'); 1951 object._console.log('limit = ' + limit); 1952 var response = {isGuests: false, elements: null}; 1953 var messagePanel = object._element.create('span', object._i18n.get('The total number of guests must be %s or less.', [limit]), null, null, null, null, null); 1954 var olPanel = object._element.create('ol', null, null, null, null, null, null); 1955 var excessGuestsPanel = object._element.create('div', null, [messagePanel, olPanel], null, null, 'excessGuestsPanel', null); 1956 for (var key in guests) { 1957 1958 if (guests[key].guestsInCapacity == 'included') { 1959 1960 var liPanel = object._element.create('li', guests[key].name, null, null, null, null, null); 1961 olPanel.appendChild(liPanel); 1962 1963 } 1964 1965 } 1966 1967 object._console.log(excessGuestsPanel); 1968 response.elements = excessGuestsPanel; 1969 return response; 1970 1971 } 1972 1973 Booking_App_ObjectsControl.prototype.verifyToLimitGuests = function(requestGuests, limitNumberOfGuests, type) { 1974 1975 var object = this; 1976 object._console.log(requestGuests); 1977 object._console.log(limitNumberOfGuests); 1978 var response = {isGuests: true, errorMessage: null}; 1979 if (type == 'day') { 1980 1981 var minimumGuests = limitNumberOfGuests.minimumGuests; 1982 if (minimumGuests.enabled == 1 && minimumGuests.number > 0) { 1983 1984 if (minimumGuests.included == 1 && minimumGuests.number > (requestGuests.requiredTotalNumberOfGuests + requestGuests.unrequiredTotalNumberOfGuests)) { 1985 1986 response.isGuests = false;
1987 response.errorMessage = object._i18n.get('The total number of people must be %s or more.', [minimumGuests.number]); 1988 1989 } else if (minimumGuests.number > requestGuests.requiredTotalNumberOfGuests) { 1990 1991 response.isGuests = false; 1992 response.errorMessage = object._i18n.get('The required total number of people must be %s or more.', [minimumGuests.number]); 1993 1994 } 1995 1996 if (response.isGuests === false) { 1997 1998 return response; 1999 2000 } 2001 2002 } 2003 2004 var maximumGuests = limitNumberOfGuests.maximumGuests; 2005 if (maximumGuests.enabled == 1 && maximumGuests.number > 0) { 2006 2007 if (maximumGuests.included == 1 && maximumGuests.number < (requestGuests.requiredTotalNumberOfGuests + requestGuests.unrequiredTotalNumberOfGuests)) { 2008 2009 response.isGuests = false; 2010 response.errorMessage = object._i18n.get('The total number of people must be %s or less.', [maximumGuests.number]); 2011 2012 } else if (maximumGuests.number < requestGuests.requiredTotalNumberOfGuests) { 2013 2014 response.isGuests = false; 2015 response.errorMessage = object._i18n.get('The required total number of people must be %s or less.', [maximumGuests.number]); 2016 2017 } 2018 2019 } 2020 2021 } 2022 2023 return response; 2024 2025 }; 2026 2027 Booking_App_ObjectsControl.prototype.getCostsInService = function(service, guests, isGuests, isExtensionsValid) { 2028 2029 var object = this; 2030 object._console.log(service); 2031 object._console.log('isGuests = ' + isGuests); 2032 var hasMultipleCosts = false; 2033 var hasReflectService = false; 2034 if (service.cost_1 == null) { 2035 2036 service.cost_1 = service.cost; 2037 service.cost_2 = service.cost; 2038 service.cost_3 = service.cost; 2039 service.cost_4 = service.cost; 2040 service.cost_5 = service.cost; 2041 service.cost_6 = service.cost; 2042 2043 } 2044 2045 //var costs = [parseInt(service.cost_1), parseInt(service.cost_2), parseInt(service.cost_3), parseInt(service.cost_4), parseInt(service.cost_5), parseInt(service.cost_6)]; 2046 var costsWithKey = {cost_1: parseInt(service.cost_1), cost_2: parseInt(service.cost_2), cost_3: parseInt(service.cost_3), cost_4: parseInt(service.cost_4), cost_5: parseInt(service.cost_5), cost_6: parseInt(service.cost_6)}; 2047 var costs = []; 2048 if (isGuests == 1 && guests != null && guests.length > 0) { 2049 2050 for (var key in guests) { 2051 2052 var guest = guests[key]; 2053 object._console.log(guest); 2054 var costInServices = guest.costInServices; 2055 if (costsWithKey[costInServices] != null && parseInt(guest.reflectService) == 1) { 2056 2057 costs.push(costsWithKey[costInServices]); 2058 2059 } 2060 2061 if (parseInt(guest.reflectService) == 1) { 2062 2063 hasReflectService = true; 2064 2065 } 2066 2067 } 2068 2069 } else { 2070 2071 costs.push(parseInt(service.cost_1)); 2072 2073 } 2074 2075 if (hasReflectService === false) { 2076 2077 costs.push(parseInt(service.cost_1)); 2078 2079 } 2080 2081 object._console.log(costs); 2082 const arrayMax = function (a, b) {return Math.max(a, b);} 2083 const arrayMin = function (a, b) {return Math.min(a, b);} 2084 var max = costs.reduce(arrayMax); 2085 var min = costs.reduce(arrayMin); 2086 if (hasReflectService === false) { 2087 2088 max = service.cost_1; 2089 min = service.cost_1; 2090 2091 } 2092 2093 /** 2094 if (min == 0) { 2095 2096 var sortCosts = [parseInt(service.cost_1), parseInt(service.cost_2), parseInt(service.cost_3), parseInt(service.cost_4), parseInt(service.cost_5), parseInt(service.cost_6)]; 2097 sortCosts.sort(function (a, b) { 2098 2099 return a - b; 2100 2101 }); 2102 2103 for (var i = 0; i < sortCosts.length; i++) { 2104 2105 if (sortCosts[i] > 0) { 2106 2107 min = sortCosts[i]; 2108 break; 2109 2110 } 2111 2112 } 2113 2114 } 2115 **/ 2116 2117 if (max != min && isExtensionsValid == 1) { 2118 2119 hasMultipleCosts = true; 2120 2121 } 2122 2123 if (isExtensionsValid != 1) { 2124 2125 max = costs[0]; 2126 2127 } 2128 2129 var response = {hasMultipleCosts: hasMultipleCosts, max: max, min: min, costs: costs, costsWithKey: costsWithKey}; 2130 return response; 2131 2132 } 2133 2134 Booking_App_ObjectsControl.prototype.getValueReflectGuests = function(guestsList) { 2135 2136 var object = this; 2137 var costs = {cost_1: 0, cost_2: 0, cost_3: 0, cost_4: 0, cost_5: 0, cost_6: 0}; 2138 var response = {totalNumberOfGuests: 0, requiredTotalNumberOfGuests: 0, unrequiredTotalNumberOfGuests: 0, reflectService: 0, reflectAdditional: 0, totalNumberOfGuestsTitle: 0, reflectServiceTitle: null, reflectAdditionalTitle: null, costs: costs}; 2139 for (var key in guestsList) { 2140 2141 var guest = guestsList[key]; 2142 object._console.log(guest); 2143 if (guest.index != null) { 2144 2145 //var selectBox = document.getElementById('booking_package_input_' + guest.id); 2146 //object._console.log(selectBox); 2147 var list = guest.json;
2148 if (typeof guest.json == 'string') { 2149 2150 list = JSON.parse(guest.json); 2151 2152 } 2153 2154 //var option = selectBox.options[guest.index]; 2155 //object._console.log(option); 2156 //var index = parseInt(option.getAttribute('data-optionsKey')) 2157 var selected = list[guest.index]; 2158 //var selected = list[index]; 2159 object._console.log(selected); 2160 var costInServices = guest.costInServices; 2161 response.totalNumberOfGuests += parseInt(selected.number); 2162 if (parseInt(guest.required) == 1) { 2163 2164 response.requiredTotalNumberOfGuests += parseInt(selected.number); 2165 2166 } else { 2167 2168 response.unrequiredTotalNumberOfGuests += parseInt(selected.number); 2169 2170 } 2171 2172 if (parseInt(guest.reflectService) == 1 && parseInt(selected.number) > 0) { 2173 2174 response.reflectService += parseInt(selected.number); 2175 response.costs[costInServices] += parseInt(selected.number); 2176 2177 } 2178 2179 if (parseInt(guest.reflectAdditional) == 1 && parseInt(selected.number) > 0) { 2180 2181 response.reflectAdditional += parseInt(selected.number); 2182 2183 } 2184 2185 } 2186 2187 } 2188 2189 if (response.totalNumberOfGuests == 1) { 2190 2191 response.totalNumberOfGuestsTitle = object._i18n.get('%s guest', [response.totalNumberOfGuests]); 2192 2193 } else if (response.totalNumberOfGuests > 1) { 2194 2195 response.totalNumberOfGuestsTitle = object._i18n.get('%s guests', [response.totalNumberOfGuests]); 2196 2197 } 2198 2199 if (response.reflectService == 1) { 2200 2201 response.reflectServiceTitle = object._i18n.get('%s guest', [response.reflectService]); 2202 2203 } else if (response.reflectService > 1) { 2204 2205 response.reflectServiceTitle = object._i18n.get('%s guests', [response.reflectService]); 2206 2207 } 2208 2209 if (response.reflectAdditional == 1) { 2210 2211 response.reflectAdditionalTitle = object._i18n.get('%s guest', [response.reflectAdditional]); 2212 2213 } else if (response.reflectAdditional > 1) { 2214 2215 response.reflectAdditionalTitle = object._i18n.get('%s guests', [response.reflectAdditional]); 2216 2217 } 2218 2219 if (response.reflectService == 0) { 2220 2221 response.reflectService = 1; 2222 if (response.reflectService == 1) { 2223 2224 response.reflectServiceTitle = object._i18n.get('%s guest', [response.reflectService]); 2225 2226 } else if (response.reflectService > 1) { 2227 2228 response.reflectServiceTitle = object._i18n.get('%s guests', [response.reflectService]); 2229 2230 } 2231 2232 } 2233 2234 if (response.reflectAdditional == 0) { 2235 2236 response.reflectAdditional = 1; 2237 if (response.reflectAdditional == 1) { 2238 2239 response.reflectAdditionalTitle = object._i18n.get('%s guest', [response.reflectAdditional]); 2240 2241 } else if (response.reflectAdditional > 1) { 2242 2243 response.reflectAdditionalTitle = object._i18n.get('%s guests', [response.reflectAdditional]); 2244 2245 } 2246 2247 } 2248 2249 return response; 2250 2251 }; 2252 2253 Booking_App_ObjectsControl.prototype.validateServices = function(month, day, year, week, changeSelected, expiration) { 2254 2255 var object = this; 2256 var isBooking = {status: true, services: {}}; 2257 object._console.log('validateServices'); 2258 object._console.error('expiration = ' + expiration); 2259 object._console.log(object._services); 2260 object._console.log('month = ' + month + ' day = ' + day + ' year = ' + year); 2261 if (month != null && day != null && year != null && week != null) { 2262 2263 var calendarKey = object._calendar.getDateKey(month, day, year); 2264 object._console.log(object._nationalHoliday[calendarKey]); 2265 var nationalHoliday = false;
2266 if (object._nationalHoliday[calendarKey] != null && parseInt(object._nationalHoliday[calendarKey].status) == 1) { 2267 2268 nationalHoliday = true; 2269 week = 7; 2270 2271 } 2272 object._console.log('week = ' + week); 2273 2274 } else { 2275 2276 week = null; 2277 2278 } 2279 2280 //var expirationDate = year + ("0" + month).slice(-2) + ("0" + day).slice(-2); 2281 var expirationDate = object._calendar.getDateKey(month, day, year); 2282 if (typeof expirationDate == 'string') { 2283 2284 expirationDate = parseInt(expirationDate); 2285 2286 } 2287 object._console.log('expirationDate = ' + expirationDate); 2288 object.setExpirationDate(expirationDate); 2289 2290 for (var key in object._services) { 2291 2292 object._console.log(object._services[key]); 2293 object._services[key].closed = 0; 2294 /** 2295 object._services[key].service = 1; 2296 object._services[key].selected = 0; 2297 object._services[key].selectedOptionsList = []; 2298 **/ 2299 var timeToProvide = object._services[key].timeToProvide; 2300 if (week != null && timeToProvide != null && 0 < timeToProvide.length) { 2301 2302 object._console.log('week = ' + week); 2303 var times = timeToProvide[parseInt(week)]; 2304 object._console.log(times); 2305 var closed = (function(times){ 2306 2307 var closed = 1; 2308 for (var key in times) { 2309 2310 var time = parseInt(times[key]); 2311 if (time == 1) { 2312 2313 closed = 0; 2314 break; 2315 2316 } 2317 2318 } 2319 2320 return closed; 2321 2322 })(times); 2323 object._services[key].closed = closed; 2324 object._console.log('closed = ' + closed); 2325 if (parseInt(object._services[key].selected) == 1 && closed == 1) { 2326 2327 if (isBooking.status === true) { 2328 2329 isBooking.status = false; 2330 2331 } 2332 isBooking.services[key] = object._services[key]; 2333 2334 } 2335 2336 } 2337 2338 if (parseInt(object._services[key].expirationDateStatus) == 1) { 2339 2340 var expirationDateFrom = parseInt(object._services[key].expirationDateFrom); 2341 var expirationDateTo = parseInt(object._services[key].expirationDateTo); 2342 var expirationDate = object.getExpirationDate(); 2343 object._console.log(expirationDate); 2344 if (object._services[key].expirationDateTrigger != 'dateBooked') { 2345 2346 2347 2348 } 2349 2350 if (object.validExpirationDate(expirationDate, expirationDateFrom, expirationDateTo, object._services[key].name) === false) { 2351 2352 object._console.error(object._services[key]); 2353 if (isBooking.status === true && (expiration === true || parseInt(object._services[key].selected) == 1)) { 2354 2355 isBooking.status = false; 2356 2357 } 2358 object._services[key].closed = 1; 2359 isBooking.services[key] = object._services[key]; 2360 2361 } 2362 2363 } 2364 2365 } 2366 2367 if (isBooking.status === false && changeSelected === true) { 2368 2369 for (var key in object._services) { 2370 2371 object._services[key].selected = 0; 2372 var checkBox = document.getElementById('service_checkBox_' + key); 2373 if (checkBox != null) { 2374 2375 checkBox.checked = false;
2376 2377 } 2378 2379 } 2380 2381 } 2382 2383 return isBooking; 2384 2385 }; 2386 2387 Booking_App_ObjectsControl.prototype.sendbookingVerificationCode = function(url, action, nonce, wp_rest_nonce, plugin_name, prefix, post, bookingVerificationCode, callback) { 2388 2389 var object = this; 2390 if (bookingVerificationCode === true) { 2391 2392 post.mode = prefix + 'sendVerificationCode'; 2393 if (wp_rest_nonce != null) { 2394 2395 post.booking_package_wp_rest_nonce = wp_rest_nonce; 2396 2397 } 2398 object._console.log(post); 2399 var bookingBlockPanel = document.getElementById("bookingBlockPanel"); 2400 bookingBlockPanel.classList.remove("hidden_panel"); 2401 new Booking_App_XMLHttp(url, post, false, function(response){ 2402 2403 object._console.log(response); 2404 const verificationHashCode = response.verificationHashCode; 2405 if (verificationHashCode == null) { 2406 2407 response.status = false; 2408 2409 } 2410 //object._console.log('verificationHashCode = ' + verificationHashCode); 2411 bookingBlockPanel.classList.add("hidden_panel"); 2412 if (response.status === true) { 2413 2414 var verificationCodePanel = document.getElementById(prefix + 'verificationCodePanel'); 2415 verificationCodePanel.classList.remove('hidden_panel'); 2416 2417 var verificationCodeContent = document.getElementById(prefix + 'verificationCodeContent'); 2418 var inputCode = verificationCodeContent.getElementsByTagName('input')[0]; 2419 inputCode.value = null; 2420 var sendButton = verificationCodeContent.getElementsByTagName('button')[0]; 2421 var address = verificationCodeContent.getElementsByClassName('address')[0]; 2422 address.textContent = response.notifications; 2423 2424 sendButton.onclick = function() { 2425 2426 var sendButton = this; 2427 sendButton.disabled = true; 2428 var verificationCode = inputCode.value; 2429 object._console.log('onclick'); 2430 object._console.log(typeof verificationCode); 2431 object._console.log(Number(verificationCode)); 2432 object._console.log(isNaN(Number(verificationCode))); 2433 if (verificationCode.length == 6 && isNaN(Number(verificationCode)) === false) { 2434 2435 var checkVerificationCodePost = {booking_package_nonce: nonce, plugin_name: plugin_name, action: action, mode: prefix + 'checkVerificationCode', verificationCode: verificationCode}; 2436 if (wp_rest_nonce != null) { 2437 2438 checkVerificationCodePost.booking_package_wp_rest_nonce = wp_rest_nonce; 2439 2440 } 2441 object._console.log(checkVerificationCodePost); 2442 var bookingBlockPanel = document.getElementById("bookingBlockPanel"); 2443 bookingBlockPanel.classList.remove("hidden_panel"); 2444 new Booking_App_XMLHttp(url, checkVerificationCodePost, false, function(response) { 2445 2446 object._console.log(response); 2447 if (verificationHashCode == response.verificationHashCode) { 2448 2449 verificationCodePanel.classList.add('hidden_panel'); 2450 callback(true); 2451 2452 } else { 2453 2454 window.alert(response.error_message); 2455 bookingBlockPanel.classList.add("hidden_panel"); 2456 2457 } 2458 2459 sendButton.disabled = false;
2460 //bookingBlockPanel.classList.add("hidden_panel"); 2461 2462 }); 2463 2464 } else { 2465 2466 sendButton.disabled = false; 2467 2468 } 2469 2470 }; 2471 2472 } else { 2473 2474 callback(false); 2475 window.alert(response.message); 2476 2477 } 2478 2479 2480 }); 2481 2482 } else { 2483 2484 callback(true); 2485 2486 } 2487 2488 }; 2489 2490 2491 function FORMAT_COST(i18n, debug, numberFormatter, currency_info) { 2492 2493 this._i18n = null; 2494 if(typeof i18n == 'object'){ 2495 2496 this._i18n = i18n; 2497 2498 } 2499 this._console = {}; 2500 this._console.log = console.log; 2501 this._numberFormatter = numberFormatter; 2502 this._currency_info = currency_info; 2503 if (debug != null && typeof debug.getConsoleLog == 'function') { 2504 2505 this._console.log = debug.getConsoleLog(); 2506 2507 } 2508 2509 this._element = new Booking_Package_Elements(debug); 2510 2511 } 2512 2513 FORMAT_COST.prototype.formatCost = function(cost, currency){ 2514 2515 var object = this; 2516 if (cost === null) { 2517 2518 cost = 0; 2519 2520 } 2521 2522 if (object._numberFormatter === true) { 2523 2524 let locale = object._currency_info.locale; 2525 if (locale.length >= 5) { 2526 2527 locale = locale.replace('_', '-'); 2528 2529 } 2530 2531 if (object._currency_info.info.ISOdigits !== 0) { 2532 2533 let digits = object._currency_info.info.ISOdigits; 2534 var costString = cost.toString(); 2535 cost = costString.slice(0, -digits) + '.' + costString.slice(-digits); 2536 2537 } 2538 2539 var locale_cost = new Intl.NumberFormat(locale, {style: 'currency', currency: currency} ).format(cost); 2540 return locale_cost; 2541 2542 } 2543 2544 var format = function(cost, symbol, currency){ 2545 2546 if (symbol == 'comma') { 2547 2548 cost = String(cost).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1,'); 2549 2550 } else if (symbol == 'dot') { 2551 2552 cost = String(cost).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1.'); 2553 2554 } else if (symbol == 'space') { 2555 2556 cost = String(cost).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1 '); 2557 2558 } 2559 2560 return cost; 2561 2562 } 2563 2564 if (currency.toLocaleUpperCase() == 'USD') { 2565 2566 cost = Number(cost) / 100; 2567 cost = cost.toFixed(2); 2568 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2569 cost = "US$" + cost; 2570 2571 } else if (currency.toLocaleUpperCase() == "EUR") { 2572 2573 cost = Number(cost) / 100; 2574 cost = cost.toFixed(2); 2575 cost = cost.replace('.', ','); 2576 cost = format(cost, 'dot', currency.toLocaleUpperCase()); 2577 cost = cost + " â¬"; 2578 2579 } else if (currency.toLocaleUpperCase() == 'JPY') { 2580 2581 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2582 cost = "Â¥" + cost; 2583 2584 } else if (currency.toLocaleUpperCase() == 'TRY') { 2585 2586 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2587 cost = cost + "âº"; 2588 2589 } else if (currency.toLocaleUpperCase() == 'KRW') { 2590 2591 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2592 cost = "â©" + cost; 2593 2594 } else if (currency.toLocaleUpperCase() == 'HUF') { 2595 2596 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2597 cost = "HUF " + cost; 2598 2599 } else if (currency.toLocaleUpperCase() == 'DKK') { 2600 2601 cost = Number(cost) / 100; 2602 cost = cost.toFixed(2); 2603 cost = format(cost, 'comma', currency.toLocaleUpperCase()) + "kr"; 2604 2605 } else if (currency.toLocaleUpperCase() == "CNY") { 2606 2607 cost = Number(cost) / 100; 2608 cost = cost.toFixed(2); 2609 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2610 cost = "CNÂ¥" + cost; 2611 2612 } else if (currency.toLocaleUpperCase() == 'TWD') { 2613 2614 cost = Number(cost) / 100; 2615 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2616 cost = "NT$" + cost; 2617 2618 } else if (currency.toLocaleUpperCase() == 'THB') { 2619 2620 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2621 cost = "TH฿" + cost; 2622 2623 } else if (currency.toLocaleUpperCase() == 'COP') { 2624 2625 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2626 cost = "COP" + cost; 2627 2628 } else if (currency.toLocaleUpperCase() == 'CAD') { 2629 2630 cost = Number(cost) / 100; 2631 cost = cost.toFixed(2); 2632 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2633 cost = "$" + cost; 2634 2635 } else if (currency.toLocaleUpperCase() == 'AUD') { 2636 2637 cost = Number(cost) / 100; 2638 cost = cost.toFixed(2); 2639 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2640 cost = "$" + cost; 2641 2642 } else if (currency.toLocaleUpperCase() == 'GBP') { 2643 2644 cost = Number(cost) / 100; 2645 cost = cost.toFixed(2); 2646 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2647 cost = "£" + cost; 2648 2649 } else if (currency.toLocaleUpperCase() == 'PHP') { 2650 2651 cost = Number(cost) / 100; 2652 cost = cost.toFixed(2); 2653 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2654 cost = "PHP " + cost; 2655 2656 } else if (currency.toLocaleUpperCase() == 'CHF') { 2657 2658 cost = Number(cost) / 100; 2659 cost = cost.toFixed(2); 2660 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2661 cost = "CHF " + cost; 2662 2663 } else if (currency.toLocaleUpperCase() == 'CZK') { 2664 2665 cost = Number(cost) / 100; 2666 cost = cost.toFixed(2); 2667 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2668 cost = "KÄ" + cost; 2669 2670 } else if (currency.toLocaleUpperCase() == 'RUB') { 2671 2672 cost = Number(cost) / 100; 2673 cost = cost.toFixed(2); 2674 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2675 cost = cost + "â½"; 2676 2677 } else if (currency.toLocaleUpperCase() == 'NZD') { 2678 2679 cost = Number(cost) / 100; 2680 cost = cost.toFixed(2); 2681 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2682 cost = "NZ$" + cost; 2683 2684 } else if (currency.toLocaleUpperCase() == 'HRK') { 2685 2686 cost = Number(cost) / 100; 2687 cost = cost.toFixed(2); 2688 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2689 cost = cost + " Kn"; 2690 2691 } else if (currency.toLocaleUpperCase() == 'UAH') { 2692 2693 cost = Number(cost) / 100; 2694 cost = cost.toFixed(2); 2695 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2696 cost = cost + "гÑн."; 2697 2698 } else if (currency.toLocaleUpperCase() == 'BRL') { 2699 2700 cost = Number(cost) / 100; 2701 cost = cost.toFixed(2); 2702 cost = cost.replace('.', ','); 2703 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2704 cost = "R$" + cost; 2705 2706 } else if (currency.toLocaleUpperCase() == 'AED') { 2707 2708 cost = Number(cost) / 100; 2709 cost = cost.toFixed(2); 2710 cost = cost.replace('.', ','); 2711 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2712 cost = cost + " AED"; 2713 2714 } else if (currency.toLocaleUpperCase() == 'GTQ') { 2715 2716 cost = Number(cost) / 100; 2717 cost = cost.toFixed(2); 2718 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2719 cost = "Q" + cost; 2720 2721 } else if (currency.toLocaleUpperCase() == 'MXN') { 2722 2723 cost = Number(cost) / 100; 2724 cost = cost.toFixed(2); 2725 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2726 cost = "$" + cost + " MXN"; 2727 2728 } else if (currency.toLocaleUpperCase() == 'ARS') { 2729 2730 cost = format(cost, 'dot', currency.toLocaleUpperCase()); 2731 cost = "$" + cost; 2732 2733 } else if (currency.toLocaleUpperCase() == 'ZAR') { 2734 2735 cost = Number(cost) / 100; 2736 cost = cost.toFixed(2); 2737 cost = format(cost, 'comma', currency.toLocaleUpperCase());
2738 cost = "R" + cost; 2739 2740 } else if (currency.toLocaleUpperCase() == 'SEK') { 2741 2742 cost = Number(cost) / 100; 2743 cost = cost.toFixed(2); 2744 cost = format(cost, 'space', currency.toLocaleUpperCase()) + " kr"; 2745 2746 } else if (currency.toLocaleUpperCase() == 'RON') { 2747 2748 cost = Number(cost) / 100; 2749 cost = cost.toFixed(2); 2750 cost = cost.replace('.', ','); 2751 //cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2752 cost = cost + ' lei'; 2753 2754 } else if (currency.toLocaleUpperCase() == 'INR') { 2755 2756 cost = Number(cost) / 1000; 2757 cost = cost.toFixed(3); 2758 var parts = cost.toString().split("."); 2759 if (parseInt(parts) > 0) { 2760 2761 var formattedIntegerPart = parts[0].replace(/\B(?=(\d{2})+(?!\d))/g, " "); 2762 cost = formattedIntegerPart + (parts[1] ? "." + parts[1] : ""); 2763 cost = cost.replace('.', ' '); 2764 2765 } else { 2766 2767 cost = parts[1]; 2768 2769 } 2770 2771 cost = 'â¹' + cost; 2772 2773 } else if (currency.toLocaleUpperCase() == 'SGD') { 2774 2775 cost = Number(cost) / 100; 2776 cost = cost.toFixed(2); 2777 cost = format(cost, 'comma', currency.toLocaleUpperCase()); 2778 cost = "$ " + cost; 2779 2780 } else if (currency.toLocaleUpperCase() == 'IDR') { 2781 2782 cost = format(cost, 'dot', currency.toLocaleUpperCase()); 2783 cost = "Rp " + cost; 2784 2785 } 2786 2787 //toString().replace(/\B(?=(\d{3})+(?!\d))/g, " "); 2788 2789 //new Intl.NumberFormat({ style: 'currency', currency: 'BRL' }).format(cost) 2790 2791 object._console.log("currency = " + currency + " cost = " + cost); 2792 return cost; 2793 2794 } 2795
2796 function TAXES(i18n, currency, debug, numberFormatter, currency_info) { 2797 2798 this._i18n = null; 2799 this._applicantCount = 1; 2800 this._currency = currency; 2801 this._numberFormatter = numberFormatter; 2802 this._currency_info = currency_info; 2803 this._taxes = []; 2804 this._prefix = 'booking_package_'; 2805 this._visitorsDetails = {}; 2806 this._servicesControl = null; 2807 if(typeof i18n == 'object'){ 2808 2809 this._i18n = i18n; 2810 2811 } 2812 this._element = new Booking_Package_Elements(debug); 2813 this._debug = null; 2814 this._console = {}; 2815 this._console.log = console.log; 2816 if (debug != null && typeof debug.getConsoleLog == 'function') { 2817 2818 this._debug = debug; 2819 this._console.log = debug.getConsoleLog(); 2820 2821 } 2822 2823 }; 2824 2825 TAXES.prototype.setPrefix = function(prefix) { 2826 2827 this._prefix = prefix; 2828 2829 }; 2830 2831 TAXES.prototype.setBooking_App_ObjectsControl = function(servicesControl) { 2832 2833 this._servicesControl = servicesControl; 2834 2835 }; 2836 2837 TAXES.prototype.setApplicantCount = function(applicantCount) { 2838 2839 this._applicantCount = parseInt(applicantCount); 2840 this._console.log('_applicantCount = ' + this._applicantCount); 2841 2842 }; 2843 2844 TAXES.prototype.setTaxes = function(taxes) { 2845 2846 this._taxes = taxes; 2847 2848 } 2849 2850 TAXES.prototype.getTaxes = function() { 2851 2852 return this._taxes; 2853 2854 } 2855 2856 TAXES.prototype.setVisitorsDetails = function(visitorsDetails) { 2857 2858 this._visitorsDetails = visitorsDetails; 2859 2860 } 2861 2862 TAXES.prototype.getVisitorsDetails = function() { 2863 2864 return this._visitorsDetails; 2865 2866 } 2867 2868 TAXES.prototype.getTaxValue = function(taxKey, type, visitorsDetails) { 2869 2870 var object = this; 2871 object._console.log(visitorsDetails); 2872 var taxes = this._taxes; 2873 if (taxes[taxKey] == null) { 2874 2875 return 0; 2876 2877 } else { 2878 2879 var tax = taxes[taxKey]; 2880 var taxValue = 0; 2881 object._console.log(tax); 2882 var value = parseInt(tax.value); 2883 if (tax.method == 'multiplication') { 2884 2885 value = parseFloat(tax.value); 2886 2887 } 2888 2889 object._console.log(value); 2890 2891 if (parseInt(tax.generation) === 1) { 2892 2893 if (type == 'day') { 2894 2895 if (tax.method == 'multiplication') { 2896 2897 taxValue = (tax.value / 100) * visitorsDetails.amount; 2898 if (tax.tax == 'tax_inclusive') { 2899 2900 taxValue = visitorsDetails.amount * (parseInt(tax.value) / (100 + parseInt(tax.value))); 2901 taxValue = Math.floor(taxValue); 2902 2903 } 2904 tax.taxValue = parseInt(taxValue); 2905 2906 } else { 2907 2908 tax.taxValue = parseInt(tax.value); 2909 taxValue = parseInt(tax.value); 2910 2911 } 2912 2913 } else if (type == 'hotel') { 2914 2915 var applicantCount = object._applicantCount; 2916 var person = 0; 2917 var additionalFee = 0; 2918 var personAmount = 0; 2919 var optionsAmount = 0; 2920 var nights = visitorsDetails.nights; 2921 var rooms = visitorsDetails.rooms; 2922 for (var roomKey in visitorsDetails.rooms) { 2923 2924 var room = visitorsDetails.rooms[roomKey]; 2925 object._console.log(room); 2926 person += room.person; 2927 additionalFee += room.additionalFee; 2928 personAmount += room.personAmount; 2929 if (isNaN(parseInt(room.optionsAmount)) === false) { 2930 2931 optionsAmount+= room.optionsAmount; 2932 2933 } 2934 2935 } 2936 object._console.log('personAmount = ' + personAmount); 2937 object._console.log('optionsAmount = ' + optionsAmount); 2938 object._console.log('nights = ' + nights); 2939 if (parseInt(tax.expirationDateStatus) == 1 && typeof object._servicesControl.validExpirationDate == 'function') { 2940 2941 if (tax.expirationDateTrigger != 'dateBooked') { 2942 2943 2944 2945 } else { 2946 2947 var count = 0; 2948 var list = visitorsDetails.list; 2949 for (var key in visitorsDetails.list) { 2950 2951 var schedule = visitorsDetails.list[key]; 2952 object._console.log(schedule); 2953 var expirationDate = parseInt(schedule.ymd); 2954 var isBooking = object._servicesControl.validExpirationDate(expirationDate, parseInt(tax.expirationDateFrom), parseInt(tax.expirationDateTo), tax.name); 2955 object._console.log(isBooking); 2956 if (isBooking === false || parseInt(expirationDate) == 0) { 2957 2958 count++; 2959 object._console.log(schedule); 2960 2961 } 2962 2963 } 2964 2965 if (nights == count) { 2966 2967 applicantCount = 0; 2968 2969 } 2970 2971 nights -= count; 2972 object._console.log('nights = ' + nights); 2973 2974 } 2975 2976 } 2977 2978 if (tax.target == 'room') { 2979 2980 if (tax.scope == 'day') { 2981 2982 if (tax.method == 'addition') { 2983 2984 taxValue = (nights * applicantCount) * value; 2985 2986 2987 } else if (tax.method == 'multiplication') { 2988 2989 //taxValue = (value / 100) * ((visitorsDetails.amount * applicantCount) + (additionalFee * nights) + optionsAmount); 2990 taxValue = (value / 100) * ((visitorsDetails.amount * applicantCount) + personAmount + optionsAmount); 2991 if (personAmount > 0) { 2992 2993 taxValue = (value / 100) * ((visitorsDetails.amount * applicantCount) + personAmount + optionsAmount); 2994 2995 } 2996 2997 if (tax.type == 'tax' && tax.tax == 'tax_inclusive') { 2998 2999 var amount = 0; 3000 for (var i in visitorsDetails.list) { 3001 3002 amount += parseInt(visitorsDetails.list[i].cost) * applicantCount; 3003 3004 } 3005 3006 //taxValue = (amount + optionsAmount + (additionalFee * nights)) * (value / (100 + value)); 3007 taxValue = (visitorsDetails.amount + personAmount + optionsAmount) * (value / (100 + value)); 3008 if (personAmount > 0) { 3009 3010 taxValue = (visitorsDetails.amount + personAmount + optionsAmount) * (value / (100 + value)); 3011 3012 } 3013 taxValue = Math.floor(taxValue); 3014 3015 } 3016 3017 } 3018 3019 } else if (tax.scope == 'booking') { 3020 3021 if (tax.method == 'addition') { 3022 3023 taxValue = applicantCount * value; 3024 3025 } else if (tax.method == 'multiplication') { 3026 3027 taxValue = (value / 100) * applicantCount; 3028 3029 } 3030 3031 } else if (tax.scope == 'bookingEachGuests') { 3032 3033 if (tax.method == 'addition') { 3034 3035 taxValue = (person * nights) * value; 3036 3037 } else if (tax.method == 'multiplication') { 3038 3039 taxValue = (value / 100) * (person * nights); 3040 3041 } 3042 3043 } 3044 3045 if (tax.method == 'addition' && tax.type == 'tax' && tax.tax == 'tax_inclusive') { 3046 3047 visitorsDetails.amount -= taxValue; 3048 3049 } 3050 3051 } else if (tax.target == 'guest') { 3052 3053 if (tax.scope == 'day') { 3054 3055 if (tax.method == 'addition') { 3056 3057 taxValue = (nights * person) * value; 3058 3059 } else if (tax.method == 'multiplication') { 3060 3061 taxValue = (value / 100) * additionalFee; 3062 if (personAmount > 0) { 3063 3064 taxValue = (value / 100) * personAmount; 3065 3066 } 3067 3068 if (tax.type == 'tax' && tax.tax == 'tax_inclusive') { 3069 3070 taxValue = additionalFee * (value / (100 + value)); 3071 if (personAmount > 0) { 3072 3073 taxValue = personAmount * (value / (100 + value)); 3074 3075 } 3076 taxValue = Math.floor(taxValue); 3077 3078 } 3079 3080 } 3081 3082 } else if (tax.scope == 'booking') { 3083 3084 if (tax.method == 'addition') { 3085 3086 taxValue = 1 * value; 3087 3088 } else if (tax.method == 'multiplication') { 3089 3090 taxValue = (value / 100) * 1; 3091 3092 } 3093 3094 } else if (tax.scope == 'bookingEachGuests') { 3095 3096 if (tax.method == 'addition') { 3097 3098 taxValue = (person * nights) * value; 3099 3100 } else if (tax.method == 'multiplication') { 3101 3102 taxValue = (value / 100) * (person * nights); 3103 3104 } 3105 3106 } 3107 3108 } 3109 3110 } 3111 3112 } else if (parseInt((tax.generation)) === 2) { 3113 3114 if (type == 'day') { 3115 3116 taxValue = 0; 3117 if (tax.type === 'tax') { 3118 3119 object._console.log(visitorsDetails.extraChargeAmount); 3120 taxValue = (tax.value / 100) * (visitorsDetails.amount + visitorsDetails.extraChargeAmount); 3121 if (tax.tax == 'tax_inclusive') { 3122 3123 taxValue = (visitorsDetails.amount + visitorsDetails.extraChargeAmount) * ( parseInt(tax.value) / ( 100 + parseInt(tax.value) ) ); 3124 taxValue = Math.floor(taxValue); 3125 3126 } 3127 tax.taxValue = parseInt(taxValue); 3128 3129 } else if (tax.type === 'surcharge') { 3130 3131 tax.taxValue = parseInt(tax.value); 3132 taxValue = parseInt(tax.value); 3133 3134 } 3135 3136 } else if (type == 'hotel') { 3137 3138 var applicantCount = object._applicantCount; 3139 var person = 0; 3140 var additionalFee = 0; 3141 var personAmount = 0; 3142 var optionsAmount = 0; 3143 var nights = visitorsDetails.nights; 3144 var totalNumberOfRooms = 0; 3145 var rooms = visitorsDetails.rooms; 3146 object._console.log(rooms);
3147 for (var roomKey in visitorsDetails.rooms) { 3148 3149 var room = visitorsDetails.rooms[roomKey]; 3150 object._console.log(room); 3151 person += room.person; 3152 additionalFee += room.additionalFee; 3153 personAmount += room.personAmount; 3154 totalNumberOfRooms++; 3155 if (isNaN(parseInt(room.optionsAmount)) === false) { 3156 3157 optionsAmount+= room.optionsAmount; 3158 3159 } 3160 3161 } 3162 object._console.log('personAmount = ' + personAmount); 3163 object._console.log('optionsAmount = ' + optionsAmount); 3164 object._console.log('nights = ' + nights); 3165 object._console.log('totalNumberOfRooms = ' + totalNumberOfRooms); 3166 if (parseInt(tax.expirationDateStatus) == 1 && typeof object._servicesControl.validExpirationDate == 'function') { 3167 3168 if (tax.expirationDateTrigger != 'dateBooked') { 3169 3170 3171 3172 } else { 3173 3174 var count = 0; 3175 var list = visitorsDetails.list; 3176 for (var key in visitorsDetails.list) { 3177 3178 var schedule = visitorsDetails.list[key]; 3179 object._console.log(schedule); 3180 var expirationDate = parseInt(schedule.ymd); 3181 var isBooking = object._servicesControl.validExpirationDate(expirationDate, parseInt(tax.expirationDateFrom), parseInt(tax.expirationDateTo), tax.name); 3182 object._console.log(isBooking); 3183 if (isBooking === false || parseInt(expirationDate) == 0) { 3184 3185 count++; 3186 object._console.log(schedule); 3187 3188 } 3189 3190 } 3191 3192 if (nights == count) { 3193 3194 applicantCount = 0; 3195 3196 } 3197 3198 nights -= count; 3199 object._console.log('nights = ' + nights); 3200 3201 } 3202 3203 } 3204 3205 3206 if (tax.type === 'tax') { 3207 3208 if (tax.method === 'multiplication' && tax.tax === 'tax_inclusive') { 3209 3210 taxValue = ((visitorsDetails.amount * applicantCount) + (visitorsDetails.extraChargeAmount * applicantCount) + personAmount + optionsAmount) * (value / (100 + value)); 3211 3212 } else if (tax.method === 'multiplication' && tax.tax === 'tax_exclusive') { 3213 3214 taxValue = (value / 100) * ((visitorsDetails.amount * applicantCount) + (visitorsDetails.extraChargeAmount * applicantCount) + personAmount + optionsAmount); 3215 3216 } else if (tax.method === 'addition' && tax.target === 'room') { 3217 3218 taxValue = (totalNumberOfRooms * nights) * value; 3219 3220 } else if (tax.method === 'addition' && tax.target === 'guest') { 3221 3222 taxValue = (person * nights) * value; 3223 3224 } 3225 3226 } else if (tax.type === 'surcharge') { 3227 3228 if (tax.scope === 'day' && tax.target === 'room') { 3229 3230 taxValue = (totalNumberOfRooms * nights) * value; 3231 3232 } else if (tax.scope === 'day' && tax.target === 'guest') { 3233 3234 taxValue = (person * nights) * value; 3235 3236 3237 } else if (tax.scope === 'booking' && tax.target === 'room') { 3238 3239 taxValue = totalNumberOfRooms * value; 3240 3241 3242 } else if (tax.scope === 'booking' && tax.target === 'guest') { 3243 3244 taxValue = person * value; 3245 3246 } 3247 3248 } 3249 3250 } 3251 3252 } 3253 3254 3255 3256 return parseInt(taxValue); 3257 3258 } 3259 3260 } 3261 3262 TAXES.prototype.reflectTaxesInTotalCost = function(responseTaxes, goodsList, applicantCount) { 3263 3264 var deleteKeys = []; 3265 for (var key in goodsList) { 3266 3267 var goods = goodsList[key]; 3268 if (goods.type == 'tax' || goods.type == 'surcharge') { 3269 3270 key = parseInt(key); 3271 deleteKeys.push(key); 3272 3273 } 3274 3275 } 3276 3277 deleteKeys.sort(function(a, b) { 3278 3279 return b - a; 3280 3281 }); 3282 3283 for (var key in deleteKeys) { 3284 3285 var deleteKey = deleteKeys[key]; 3286 goodsList.splice(deleteKey, 1); 3287 3288 } 3289 3290 var totalCost = 0; 3291 for (var key in responseTaxes) { 3292 3293 var tax = responseTaxes[key]; 3294 if (tax.active != 'true' || tax.status == 0) { 3295 3296 continue; 3297 3298 } 3299 3300 if ((tax.type == 'tax' && tax.tax == 'tax_exclusive') || tax.type == 'surcharge') { 3301 3302 var cost = parseInt(tax.taxValue); 3303 var goods = {id: tax.key, label: tax.name, amount: cost, applicantCount: 1, type: tax.type}; 3304 if (tax.type == 'surcharge') { 3305 3306 cost *= applicantCount; 3307 goods = {id: tax.key, label: tax.name, amount: cost, applicantCount: applicantCount, type: tax.type}; 3308 3309 } 3310 totalCost += cost; 3311 goodsList.push(goods); 3312 3313 } 3314 3315 } 3316 3317 /** 3318 for (var key in goodsList) { 3319 3320 var goods = goodsList[key]; 3321 console.log(goods); 3322 3323 } 3324 **/ 3325 3326 return totalCost; 3327 3328 } 3329 3330 TAXES.prototype.createExtraChargesAndTaxesElement = function(id) { 3331 3332 var object = this; 3333 var extraChargeName = object._element.create('div', null, null, null, null, 'name', null); 3334 var extraChargeValues = object._element.create('div', null, null, null, null, 'value', null); 3335 var taxName = object._element.create('div', null, null, null, null, 'name', null); 3336 var taxValues = object._element.create('div', null, null, null, null, 'value', null); 3337 var extraChargesAndTaxesPanel = object._element.create('div', null, [extraCh
3337argeName, extraChargeValues, taxName, taxValues], id, null, 'row', null); 3338 3339 return extraChargesAndTaxesPanel; 3340 3341 } 3342 3343 TAXES.prototype.taxesDetails = function(amount, formPanel, surchargePanel, taxePanel, reflectGuests) { 3344 3345 var object = this; 3346 var isTaxes = false; 3347 object._console.log(typeof object._servicesControl); 3348 var expirationDate = object._servicesControl.getExpirationDate(); 3349 object._console.log(expirationDate); 3350 object._console.log(reflectGuests); 3351 var reflectAdditional = 1; 3352 var reflectAdditionalTitle = null; 3353 if (reflectGuests != null) { 3354 3355 reflectAdditional = reflectGuests.reflectAdditional; 3356 reflectAdditionalTitle = reflectGuests.reflectAdditionalTitle; 3357 object._console.log(reflectAdditional); 3358 object._console.log(reflectAdditionalTitle); 3359 3360 } 3361 3362 3363 var currency = this._currency 3364 var taxes = this._taxes; 3365 object._console.log(taxes); 3366 var surchargeList = []; 3367 var taxList = []; 3368 var visitorsDetails = {amount: amount, additionalFee: 0, extraChargeAmount: 0, nights: 0, person: 0, list: []}; 3369 for (var key in taxes) { 3370 3371 var tax = taxes[key]; 3372 tax.status = 1; 3373 if (tax.active != 'true') { 3374 3375 continue; 3376 3377 } 3378 3379 if (parseInt(tax.expirationDateStatus) == 1 && typeof object._servicesControl.validExpirationDate == 'function') { 3380 3381 if (tax.expirationDateTrigger != 'dateBooked') { 3382 3383 3384 3385 } 3386 3387 var isBooking = object._servicesControl.validExpirationDate(expirationDate, parseInt(tax.expirationDateFrom), parseInt(tax.expirationDateTo), tax.name); 3388 object._console.log(isBooking); 3389 if (isBooking === false || parseInt(expirationDate) == 0) { 3390 3391 tax.status = 0; 3392 continue; 3393 3394 } 3395 3396 } 3397 3398 var taxValue = object.getTaxValue(key, 'day', visitorsDetails); 3399 object._console.log("name = " + tax.name + " taxValue = " + taxValue); 3400 if (tax.type == 'surcharge') { 3401 3402 if (parseInt(tax.generation) === 2) { 3403 3404 visitorsDetails.extraChargeAmount += taxValue * reflectAdditional; 3405 3406 } 3407 3408 surchargeList.push(tax); 3409 3410 } else { 3411 3412 taxList.push(tax); 3413 3414 } 3415 3416 } 3417 3418 var format = new FORMAT_COST(this._i18n, this._debug, this._numberFormatter, this._currency_info); 3419 if (surchargeList.length > 0 || taxList.length > 0) { 3420 3421 if (surchargeList.length > 0) { 3422 3423 var namePanel = surchargePanel.getElementsByClassName("name")[0]; 3424 namePanel.textContent = this._i18n.get("Extra Charges"); 3425 namePanel.classList.add("surcharge"); 3426 3427 } else { 3428 3429 var namePanel = surchargePanel.getElementsByClassName("name")[0]; 3430 namePanel.classList.add('hidden_panel'); 3431 var valuePanel = surchargePanel.getElementsByClassName("value")[0]; 3432 valuePanel.classList.add('hidden_panel'); 3433 3434 } 3435 3436 var extraChargeValuePanel = surchargePanel.getElementsByClassName("value")[0]; 3437 extraChargeValuePanel.textContent = null; 3438 for (var i = 0; i < surchargeList.length; i++) { 3439 3440 var surcharge = surchargeList[i]; 3441 var nameSpan = object._element.create('span', surcharge.name, null, null, null, 'planName', null); 3442 var costSpan = object._element.create('span', null, null, null, null, 'planPrice serviceCost', null); 3443 if (parseInt(surcharge.taxValue) > 0) { 3444 3445 costSpan.textContent = format.formatCost( (surcharge.taxValue * reflectAdditional), currency); 3446 3447 } 3448 3449 var reflectAdditionalPanel = object._element.create('span', null, null, null, null, null, null); 3450 var addPanel = object._element.create('div', null, [nameSpan, costSpan, reflectAdditionalPanel], null, null, 'mainPlan', null); 3451 extraChargeValuePanel.appendChild(addPanel); 3452 if (reflectAdditional > 1) { 3453 3454 reflectAdditionalPanel.classList.add('reflectPanel'); 3455 var breakdownPanel = object._element.create('div', reflectAdditionalTitle + ' * ' + format.formatCost(surcharge.taxValue, currency), null, null, null, 'hidden_panel breakdownPanel breakdownPanel_' + i, null); 3456 extraChargeValuePanel.appendChild(breakdownPanel); 3457 addPanel.setAttribute('data-breakdownKey', i);
3458 addPanel.id = object._prefix + 'extra_charge_details_label'; 3459 addPanel.classList.add('extraCharge_click'); 3460 addPanel.onclick = function() { 3461 3462 var breakdownKey = this.getAttribute('data-breakdownKey'); 3463 var breakdownPanel = extraChargeValuePanel.getElementsByClassName('breakdownPanel_' + breakdownKey)[0]; 3464 if (breakdownPanel.classList.contains('hidden_panel') === true) { 3465 3466 breakdownPanel.classList.remove('hidden_panel'); 3467 3468 } else { 3469 3470 breakdownPanel.classList.add('hidden_panel'); 3471 3472 } 3473 3474 }; 3475 3476 } 3477 3478 3479 3480 //formPanel.appendChild(surchargePanel); 3481 isTaxes = true; 3482 3483 } 3484 3485 if (taxList.length > 0) { 3486 3487 var namePanel = surchargePanel.getElementsByClassName("name")[1]; 3488 namePanel.textContent = this._i18n.get("Taxes"); 3489 namePanel.classList.add("tax"); 3490 3491 } else { 3492 3493 var namePanel = surchargePanel.getElementsByClassName("name")[1]; 3494 namePanel.classList.add('hidden_panel'); 3495 var valuePanel = surchargePanel.getElementsByClassName("value")[1]; 3496 valuePanel.classList.add('hidden_panel'); 3497 3498 } 3499 3500 var taxValuePanel = surchargePanel.getElementsByClassName("value")[1]; 3501 taxValuePanel.textContent = null; 3502 for (var i = 0; i < taxList.length; i++) { 3503 3504 var surcharge = taxList[i]; 3505 object._console.log(surcharge); 3506 var nameSpan = object._element.create('span', surcharge.name, null, null, null, 'planName', null); 3507 var costSpan = object._element.create('span', null, null, null, null, 'planPrice', null); 3508 if (parseInt(surcharge.taxValue) >= 0) { 3509 3510 costSpan.textContent = format.formatCost(surcharge.taxValue, currency); 3511 3512 } 3513 3514 var addPanel = object._element.create('div', null, [nameSpan, costSpan], null, null, 'mainPlan', null); 3515 taxValuePanel.appendChild(addPanel); 3516 isTaxes = true; 3517 3518 } 3519 3520 } 3521 3522 return {isTaxes: isTaxes, surchargePanel: surchargePanel}; 3523 3524 } 3525 3526 function Booking_Package_Console(debug) { 3527 3528 this._debug = parseInt(debug); 3529 this._consoleExt = {}; 3530 this._consoleExt.originalConsoleLog = console.log; 3531 this._console = {}; 3532 this._console.log = console.log; 3533 this._console.error = console.error; 3534 if (this._debug == 0) { 3535 3536 //console.log = function(message){}; 3537 3538 } 3539 3540 } 3541 3542 Booking_Package_Console.prototype.getConsoleLog = function() { 3543 3544 if (this._debug == 0) { 3545 3546 this._console.log = function(message){}; 3547 3548 } 3549 3550 return this._console.log; 3551 3552 } 3553 3554 Booking_Package_Console.prototype.getConsoleError = function() { 3555 3556 if (this._debug == 0) { 3557 3558 this._console.error = function(message){}; 3559 3560 } 3561 3562 return this._console.error; 3563 3564 } 3565 3566 function Booking_Package_Elements (debug) { 3567 3568 this._debug = new Booking_Package_Console(debug); 3569 this._console = {}; 3570 this._console.log = this._debug.getConsoleLog(); 3571 3572 } 3573 3574 Booking_Package_Elements.prototype.create = function(elementType, text, childElements, id, style, className, data_x) { 3575 3576 var object = this; 3577 var panel = document.createElement(elementType); 3578 if (text != null) { 3579 3580 panel.textContent = text; 3581 3582 } 3583 3584 if (childElements != null && typeof childElements == 'object') { 3585 3586 for (var i = 0; i < childElements.length; i++) { 3587 3588 if (childElements[i] != null) { 3589 3590 panel.appendChild(childElements[i]); 3591 3592 } 3593 3594 } 3595 3596 } 3597 3598 if (id != null) { 3599 3600 panel.id = id; 3601 3602 } 3603 3604 if (style != null) { 3605 3606 panel.setAttribute("style", style); 3607 3608 } 3609 3610 if (className != null) { 3611 3612 panel.setAttribute("class", className); 3613 3614 } 3615 3616 if (data_x != null && typeof data_x == 'object') { 3617 3618 for (var key in data_x) { 3619 3620 if (data_x[key] != null) { 3621 3622 panel.setAttribute("data-" + key, data_x[key]); 3623 3624 } 3625 3626 } 3627 3628 } 3629 3630 return panel; 3631 3632 }; 3633 3634 Booking_Package_Elements.prototype.createButtonPanel = function(id, style, className, buttons) { 3635 3636 var buttonPanel = document.createElement("div"); 3637 if (id != null) { 3638 3639 buttonPanel.id = id; 3640 3641 } 3642 3643 if (style != null) { 3644 3645 buttonPanel.setAttribute("style", style); 3646 3647 } 3648 3649 if (className != null) { 3650 3651 buttonPanel.setAttribute("class", className); 3652 3653 } 3654 3655 for (var i = 0; i < buttons.length; i++) { 3656 3657 buttonPanel.appendChild(buttons[i]); 3658 3659 } 3660 return buttonPanel; 3661 3662 }; 3663 3664 Booking_Package_Elements.prototype.createButton = function(id, style, className, data_x, text) { 3665 3666 var object = this; 3667 var button = document.createElement("button"); 3668 button.textContent = text; 3669 if (id != null) { 3670 3671 button.id = id; 3672 3673 } 3674 3675 if (style != null) { 3676 3677 button.setAttribute("style", style); 3678 3679 } 3680 3681 if (className != null) { 3682 3683 button.setAttribute("class", className); 3684 3685 } 3686 3687 if (data_x != null && typeof data_x == 'object') { 3688 3689 for (var key in data_x) { 3690 3691 if (data_x[key] != null) { 3692 3693 button.setAttribute("data-" + key, data_x[key]); 3694 3695 } 3696 3697 } 3698 3699 } 3700 3701 return button; 3702 3703 }; 3704 3705 Booking_Package_Elements.prototype.createInputElement = function(tagName, type, name, value, text, disabled, id, style, className, data_x) { 3706 3707 var object = this; 3708 var input = document.createElement(tagName); 3709 if (tagName === 'input') { 3710 3711 input.type = type; 3712 3713 } 3714 3715 if (name != null) { 3716 3717 input.name = name; 3718 3719 } 3720 3721 if (value != null) { 3722 3723 input.value = value; 3724 3725 } 3726 3727 if (text != null) { 3728 3729 input.textContent = text; 3730 3731 } 3732 3733 if (disabled != null) { 3734 3735 input.disabled = disabled; 3736 3737 } 3738 3739 if (id != null) { 3740 3741 input.id = id; 3742 3743 } 3744 3745 if (style != null) { 3746 3747 input.setAttribute("style", style); 3748 3749 } 3750 3751 if (className != null) { 3752 3753 input.setAttribute("class", className); 3754 3755 } 3756 3757 if (data_x != null && typeof data_x == 'object') { 3758 3759 for (var key in data_x) { 3760 3761 if (data_x[key] != null) { 3762 3763 input.setAttribute("data-" + key, data_x[key]); 3764 3765 } 3766 3767 } 3768 3769 } 3770 3771 return input; 3772 3773 }; 3774 3775 function Booking_Package_sessionStorage (debug, prefix) { 3776 3777 this._debug = new Booking_Package_Console(debug); 3778 this._prefix = prefix; 3779 this._console = {}; 3780 this._console.log = console.log; 3781 if (debug != null && typeof debug.getConsoleLog == 'function') { 3782 3783 this._console.log = debug.getConsoleLog(); 3784 3785 } 3786 3787 } 3788 3789 3790 Booking_Package_sessionStorage.prototype.setObject = function(name, value) { 3791 3792 sessionStorage.setItem(this._prefix + name, JSON.stringify(value)); 3793 3794 } 3795 3796 Booking_Package_sessionStorage.prototype.getObject = function(name) { 3797 3798 var value = sessionStorage.getItem(this._prefix + name); 3799 if (value) { 3800 3801 value = JSON.parse(value); 3802 3803 } 3804 return value; 3805 3806 } 3807 3808 Booking_Package_sessionStorage.prototype.removeItem = function(name) { 3809 3810 sessionStorage.removeItem(this._prefix + name); 3811 3812 } 3813 3814 Booking_Package_sessionStorage.prototype.clear = function() { 3815 3816 sessionStorage.clear(); 3817 3818 } 3819 3820 Booking_Package_sessionStorage.prototype.setHTML = function(name, html) { 3821 3822 sessionStorage.setItem(this._prefix + name, html.outerHTML); 3823 3824 } 3825 3826 Booking_Package_sessionStorage.prototype.getHTML = function(name) { 3827 3828 this._console.log(name); 3829 const savedHtml = sessionStorage.getItem(this._prefix + name); 3830 this._console.log(savedHtml); 3831 if (savedHtml) { 3832 3833 const parser = new DOMParser(); 3834 const doc = parser.parseFromString(savedHtml, 'text/html'); 3835 const restoredElement = doc.body.firstChild; 3836 this._console.log(doc); 3837 this._console.log(restoredElement); 3838 return restoredElement; 3839 3840 } 3841 3842 return null; 3843 3844 }
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.