Online Seat Booking System नमस्कार दोस्तो,
इस ब्लॉग में हम आपको बहुत ही सरल भाषा में बतायेगें
की किस प्रकार गुगल शीट के डेटा एवं वेब एप स्क्रीप्ट की मदद से ऑनलाईन सीट बुंकिग सिस्टम बना सकते है ा
अत- आप उक्त साफटवेयर की मदद से अपने दैनिक कार्य सरल तरिके से कर सकतें है ा
In this blog we will tell you Online Seat Booking System so read the complete blog carefully and learn Online Seat Booking System according to given guidelines. Practical For Click :- Practical Step 2 :- Click to >> Extensions >> App Script >>
Step 3 :- Create 13 file Name Given Below Code.gs
Form.html
Index.html
CSS.html
DataTable.html
JavaScript.html
createWorksheet.gs
bookingDetails.gs
specificDays.gs
funcs.gs
utils.gs
covidDialog.gs
backupcode.gs
Step 4 :- Click to Copy Below Code and Paste to Code.gs File
Copy
Step 5 :- Click to Copy Below Code and Paste to Form.html File
Copy
Step 6 :- Click to Copy Below Code and Paste to Index.html File
!= include('JavaScript'); ?>
!= include('CSS'); ?>
} ?>
!= include('DataTable'); ?>
Copy
Step 7 :- Click to Copy Below Code and Paste to CSS.html File
Copy
Step 8 :- Click to Copy Below Code and Paste to DataTable.html File
Booking Details
Copy
Step 9 :- Click to Copy Below Code and Paste to JavaScript html File
Copy
Step 10 :- Click to Copy Below Code and Paste to createWorksheet.gs File
function createWorksheet(DOBoking)
{
// var monthNames = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
// var byDay = '';
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
// var monthsToAdd = 1;
// var currentDate = new Date();
// currentDate.setMonth(currentDate.getMonth() + monthsToAdd);
// var todayDate = Utilities.formatDate(currentDate, 'Asia/Singapore', 'dd/MM/yyyy HH:mm:ss');
//Convert in to date
// var convertDate = dateFormat(DOBoking);
// var array1 = convertDate.split(" ");
// var cDate = array1[0];
// var arrDate1 = DOBoking.toString().split("-"); //Logger.log(arrDate1);
// var cDay = arrDate1[2];
// var cMon = arrDate1[1];
// var cYear = arrDate1[0];
// byDay = cDay+"-"+cMon+"-"+cYear;
//currentDate.setMonth(currentDate.getMonth());
var sheetName = DOBoking;
var sheetsArray = spreadsheet.getSheets();
var creationFlag = false;
//Logger.log(sheetsArray)
for(var itr in sheetsArray)
{
if(sheetsArray[itr].getSheetName() == sheetName)
{
creationFlag = false;
break;
}
else
creationFlag = true;
}
if(creationFlag){
spreadsheet.insertSheet(sheetName);
SpreadsheetApp.getActiveSheet().setFrozenRows(1);
SpreadsheetApp.getActiveSheet().getRange('A1').setValue('Date Of Booking');
SpreadsheetApp.getActiveSheet().getRange('B1').setValue('Booking ID');
SpreadsheetApp.getActiveSheet().getRange('C1').setValue('Name');
// SpreadsheetApp.getActiveSheet().getRange('D1').setValue('Session');
SpreadsheetApp.getActiveSheet().getRange('D1').setValue('Email');
SpreadsheetApp.getActiveSheet().getRange('E1').setValue('Phone Number');
SpreadsheetApp.getActiveSheet().getRange('F1').setValue('Person');
SpreadsheetApp.getActiveSheet().getRange('G1').setValue('Table');
SpreadsheetApp.getActiveSheet().getRange('H1').setValue('Lunch');
SpreadsheetApp.getActiveSheet().getRange('I1').setValue('Dinner');
SpreadsheetApp.getActiveSheet().getRange('J1').setValue('Arrival Time');
SpreadsheetApp.getActiveSheet().getRange('K1').setValue('Diners');
SpreadsheetApp.getActiveSheet().getRange('L1').setValue('Entry Date');
}
// if(!creationFlag)
// Logger.log("Worksheet Exists");
return sheetName;
}//createWorksheet
Copy
Step 11 :- Click to Copy Below Code and Paste to bookingDetails.gs File
function getAllData(dateDes){
var sheetName = dateDes; // '03-03-2021';
var totpax = 0;
var result = ""+
""+
""+ //Change table headings to match witht he Google Sheet
"S.No. "+
"Booking ID "+
"Table "+
" "+
" ";
// result += ""+sheetName+" ";
// result += " ";
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheetsArray = spreadsheet.getSheets();
var creationFlag = false;
//Logger.log(sheetsArray)
for(var itr in sheetsArray)
{
if(sheetsArray[itr].getSheetName() == sheetName)
{
creationFlag = false;
break;
}
else
creationFlag = true;
}
if(creationFlag){
result += "No More Record ";
}
else{
var rows = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName).getDataRange().getValues();
var filteredRows = rows.filter(function(row){
return row;
});
// Logger.log(rows);
for (var i=1;i"+ i + " "+""+ rowArray[1] + " " + ""+ rowArray[6] + " ";
// var arr1 = rowArray[6].toString().split("(");
// var pax = arr1[1].split("pax"); //Logger.log(pax);
// cntpax =
// pax = arr1[1].substring(0,1);
// totpax = totpax + parseInt(pax[0]); //Logger.log("Tpax: "+totpax);
}
}
}
}// end if
result += "
";
result += " ";
result += " ";
// result += " ";
// result += " ";
return result;
}
function getSessionData(lundin,searchDate){
var rowNo = 1;
var sheetName = searchDate; // '09-07-2021'; //
// session = 'session2';
//lundin = "Dinner";
var totpax = 0;
var cntpax = 0;
var result = ""+
""+
""+ //Change table headings to match witht he Google Sheet
"S.No. "+
"Booking ID"+lundin+" "+
"Table "+
" "+
" ";
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheetsArray = spreadsheet.getSheets();
var creationFlag = false;
//Logger.log(sheetsArray)
for(var itr in sheetsArray)
{
if(sheetsArray[itr].getSheetName() == sheetName)
{
creationFlag = false;
break;
}
else
creationFlag = true;
}
if(creationFlag){
result += "No More Record ";
}
else{
// Logger.log(sheetName);
var rows = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName).getDataRange().getValues();
var filteredRows = rows.filter(function(row){
return row;
});
//Logger.log(rows);
// if(filteredRows.length != 0){
for (var i=1;i"+ rowNo + " " +""+ rowArray[1] + " "+ rowArray[6] + " "; //Logger.log(rowArray[6])
// var arr1 = rowArray[6].toString().split("(");
// var pax = arr1[1].split("pax"); Logger.log(pax);
// cntpax =
// pax = arr1[1].substring(0,1);
// totpax = totpax + parseInt(pax[0]); //Logger.log("Tpax: "+totpax);
rowNo++;
}
else if(lundin == 'Null'){
result += ""+ rowNo + " " +""+ rowArray[1] + " "+ rowArray[6] + " "; //Logger.log(rowArray[6])
// var arr1 = rowArray[6].toString().split("(");
// var pax = arr1[1].split("pax"); Logger.log(pax);
// cntpax =
// pax = arr1[1].substring(0,1);
// totpax = totpax + parseInt(pax[0]); //Logger.log("Tpax: "+totpax);
rowNo++;
}
else{}
}
}
}
if(lundin != 'Null'){
var fMsg = "";
var bkMsg = "";
bkMsg += "Booking Date: " + searchDate+ " ";
var BKval = getBookedTablePax(sheetName,lundin);
var Mtval = getTablePax();
if(BKval >= Mtval){
bkMsg += "Fully Booked, Please select other date. Thank you.
";
fMsg = "Full";
}
result += " Total Seat "+ BKval +" ";
result += "
";
result += " ";
result += " ";
result += " ";
// result += " ";
result += "For Cancel booking, Please contact 1234567890
";
}
// }
// else
// {
// result += "No more data";
// }
} // end if ## creationFlag ##
Logger.log(result);
return bkMsg + result;
}
function getTablePax() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var lovSheet = ss.getSheetByName("TCDetails");
var getLastRow = lovSheet.getLastRow();
var masterPax = [];
var sum = 0;
var data = lovSheet.getRange(3, 2, getLastRow , 1).getValues();
for(var i = data.length - 1 ; i >= 0 ; i--){
if (data[i][0] != null && data[i][0] != ""){
sum += data[i][0];
}
}
console.log(sum);
return sum;
}
function getBookedTablePax(sheetName,lundin) {
// sheetName = "27-08-2021";
//lundin = "Dinner";
var bktotpax = 0;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheetsArray = ss.getSheets();
var creationFlag = false;
//Logger.log(sheetsArray)
for(var itr in sheetsArray)
{
if(sheetsArray[itr].getSheetName() == sheetName)
{
creationFlag = false;
break;
}
else
creationFlag = true;
}
console.log(creationFlag);
if(creationFlag == false){
var lovSheet = ss.getSheetByName(sheetName);
var getLastRow = lovSheet.getLastRow();
var rowArray = lovSheet.getRange(1, 7, getLastRow , 3).getValues();
// console.log(rowArray.length);
for (var i=1;i
Copy
Step 12 :- Click to Copy Below Code and Paste to specificDays.gs File
function specificDays(searchDate) {
var sDate = searchDate; // "27-08-2021";//
var arrDate1 = sDate.toString().split("-");
var cMon = arrDate1[1];
var cYear = arrDate1[2];
// set Month names
var monthNames = ["January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December"
];
var dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saterday"];
var dayName = 'Friday';
var monthName = monthNames[Number(cMon)];
var year = Number(cYear);
var data = [];
// change string to index of array
var day = dayNames.indexOf(dayName);
var month = monthNames.indexOf(monthName);
//console.log(month+":"+day+":"+year);
// determine the number of days in month
var daysinMonth = new Date(year, month, 0).getDate();
// set counter
var sumDays=0;
// iterate over the days and compare to day
for(var i=1; i<=daysinMonth; i++) {
var checkDay = new Date(year, month-1, parseInt(i)).getDay();
var dVals = new Date(year, month-1, parseInt(i));
var tDate = Utilities.formatDate(dVals, 'Asia/Singapore', 'yyyy-MM-dd');
if(day == checkDay) {
sumDays ++;
data.push(tDate);
// console.log("Dates:"+dVals);
}
} // end of for loop
// console.log(data);
// Dinner Message
var dinnerMsg = getDinnerType();
var displayif = "";
// displayif += " ";
// displayif += "Lunch ";
// displayif += " ";
// var displayelse = "";
// displayelse += " "; // "+item[0]+"
// displayelse += "Lunch ";
var lenVal = data.length - 1;
var dataDate = "";
console.log("LenVal: "+lenVal);
for(var j=0; j<=lenVal; j++)
{
if(bdateFormat(data[1]) == sDate)
{
displayif += "Select Lunch/Dinner * ";
displayif += ""
displayif += " --Select-- ";
displayif += " Lunch ";
displayif += " Dinner " + dinnerMsg[0][0]+" ";
displayif += " ";
displayif += " ";
console.log(displayif);
return displayif;
}
else if(j == lenVal){
dataDate = bdateFormat(data[j]);
//console.log("if J="+dataDate); //bdateFormat
if(dataDate == sDate)
{
displayif += "Select Lunch/Dinner * ";
displayif += ""
displayif += " --Select-- ";
displayif += " Lunch ";
displayif += " Dinner " + dinnerMsg[1][0]+" ";
displayif += " ";
displayif += " ";
console.log(displayif);
return displayif;
}
else
{
displayif += "Select Lunch/Dinner * ";
displayif += ""
displayif += " --Select-- ";
displayif += " Lunch ";
displayif += " Dinner ";
displayif += " ";
displayif += " ";
console.log(displayif);
return displayif;
}
}
}
// var bkMsg = "";
// var BKval = getBookedTablePax(sDate);
// var Mtval = getTablePax();
// bkMsg += "Booking Date: " + sDate+ " ";
// if(BKval >= Mtval){
// bkMsg += "Fully Booked, Please select other date. Thank you.
";
// }
}
// Auto Sort the Table column
function autoSort(sheetName) {
var ss= SpreadsheetApp.getActiveSpreadsheet();
var ws = ss.getSheetByName(sheetName);
var getLRow = ws.getLastRow();
// getRange(row, column, numRows, numColumns)
var range = ws.getRange(2,1,getLRow,12);
range.sort({column: 7, ascending: true});
//Logger.log(getLastRow);
//return data;
}
function daFormat(sDate)
{
// sDate = "Fri Jul 09 2021 00:00:00 GMT+0800 (Hong Kong Standard Time)";
var startDate = new Date(sDate);
// var weekDay;
switch (startDate.getDay()) {
case 0: weekDay = "Sun"; break;
case 1: weekDay = "Mon"; break;
case 2: weekDay = "Tue"; break;
case 3: weekDay = "Wed"; break;
case 4: weekDay = "Thu"; break;
case 5: weekDay = "Fri"; break;
case 6: weekDay = "Sat"; break;
}
var month;
switch (startDate.getMonth()) {
case 0: month = "01"; break;
case 1: month = "02"; break;
case 2: month = "03"; break;
case 3: month = "04"; break;
case 4: month = "05"; break;
case 5: month = "06"; break;
case 6: month = "07"; break;
case 7: month = "08"; break;
case 8: month = "09"; break;
case 9: month = "10"; break;
case 10: month = "11"; break;
case 11: month = "12"; break;
}
var formattedDate = startDate.getDate() + "-" + month + "-" + startDate.getFullYear();
//var formattedDate = weekDay + " " + month + " " + startDate.getDate() + " " + startDate.getFullYear();
/* var mon = '';
var splitDate = sDate.toString().split(" ");
var arr = ["Jan","Feb","Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
arr.forEach(function (element, index)
{
if(splitDate[1] == element)
{
mon = index + 1;
}
});
if(splitDate.length <= 2){
var d = sDate;
}
else{
var d =splitDate[2] + '-' + mon + '-' + splitDate[3];
} */
console.log(formattedDate);
return formattedDate;
}
Copy
Step 13 :- Click to Copy Below Code and Paste to funcs.gs File
/* @Process Form */
function processForm(formObject) {
var DOBoking = formObject.dateOfBooking; // "2021-02-27"; // "07-07-2021"; //
var name = formObject.name; // "Test1"; //
// var session = formObject.session; // "session1"; //
var email = formObject.email; // "test@gmail.com"; //
var person = formObject.person; // "2 Person"; //
var phone = formObject.phone; // "12345678"; //
var tChair = formObject.tableChair; // "Table 3(4pax)";
var diners = formObject.diners; // "Table 3(4pax)";
var lundin = formObject.sltlundin; // "Lunch"; //
var arrivalTime = formObject.ArrivalTime;
var displayValue = "Null";
if (lundin == "Lunch") {
var lundinVal = "Lunch";
var dinnerVal = "";
var displayValue = "Lunch";
}
else {
var lundinVal = "";
var dinnerVal = "Dinner";
var displayValue = "Dinner";
}
var curMon_sheetName = createWorksheet(DOBoking);
//current date and time by the timezone
var curDate = new Date();
var todayDate = Utilities.formatDate(curDate, 'Asia/Singapore', 'dd/MM/yyyy HH:mm:ss');
// Logger.log(todayDate);
var url = "Paste Google Sheet Link";
var ss = SpreadsheetApp.openByUrl(url);
var ws = ss.getSheetByName(curMon_sheetName);
var bookID = getBookID(DOBoking);
//Convert in to date
var cDate = dateFormat(todayDate);
// getDialogMsg(bookID,DOBoking,name);
ws.appendRow([DOBoking, bookID, name, email, phone, person, tChair, lundinVal, dinnerVal, arrivalTime, diners, cDate]);
autoSort(curMon_sheetName);
return "Successfully submitted Your Booking ID: " + bookID + " " + getSessionData(displayValue,DOBoking);
}
function dateFormat(sDate) {
var mon = '';
var splitDate = sDate.toString().split(" ");
// Logger.log(splitDate);
var arr = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
arr.forEach(function (element, index) {
if (splitDate[1] == element) {
mon = index + 1;
}
});
if (splitDate.length <= 2) {
var d = sDate;
}
else {
var d = mon + '/' + splitDate[2] + '/' + splitDate[3] + " " + splitDate[4];
}
return d;
}
function bdateFormat(bDate) {
//var bDate = "2021-02-27";
var byDay = '';
var arrDate1 = bDate.toString().split("-");
var cDay = arrDate1[2];
var cMon = arrDate1[1];
var cYear = arrDate1[0];
byDay = cDay + "-" + cMon + "-" + cYear; Logger.log(byDay);
return byDay;
}
function getListOfTable() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var lovSheet = ss.getSheetByName("TCDetails");
var getLastRow = lovSheet.getLastRow();
var data = [];
for (var i = 2; i <= getLastRow; i++) {
if (data.indexOf(lovSheet.getRange(i, 1).getValue()) === -1) {
data.push(lovSheet.getRange(i, 1).getValue());
}
}
//Logger.log(data);
return data;
}
function getTableList(lundin,searchDate) {// (){//
var sheetName = searchDate; // '09-07-2021'; //
console.log("searchDate: " + sheetName);
//var lundin = "Lunch";
// var session = 'session1';
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheetsArray = spreadsheet.getSheets();
var creationFlag = false;
//Logger.log(sheetsArray)
for (var itr in sheetsArray) {
console.log(sheetName);
if (sheetsArray[itr].getSheetName() == sheetName) {
creationFlag = false;
break;
}
else
creationFlag = true;
}
if (creationFlag) {
var tcDataArr = getListOfTable(); //console.log("if"+tcDataArr);
return tcDataArr;
}
else {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var lovSheet = ss.getSheetByName(sheetName);
var getLastRow = lovSheet.getLastRow();
var existingDataArr = [];
for (var i = 2; i <= getLastRow; i++) {
// Logger.log(lovSheet.getRange(i, 8).getValue());
if(lundin == "Lunch"){
Logger.log(lovSheet.getRange(i, 8).getValue());
if(lovSheet.getRange(i, 8).getValue() === lundin) {
existingDataArr.push(lovSheet.getRange(i, 7).getValue());
}
}
else{
Logger.log(lovSheet.getRange(i, 9).getValue());
if(lovSheet.getRange(i, 9).getValue() === lundin) {
existingDataArr.push(lovSheet.getRange(i, 7).getValue());
}
}
}
Logger.log("Exist:" + existingDataArr);
var tcDataArr = getListOfTable();
//filtering an array based on another array in google apps script
var res = [];
res = tcDataArr.filter(f => !existingDataArr.includes(f));
console.log("else" + res);
return res;
}
}
function getArrival(sltlundin){
// sltlundin = "Lunch";
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ldSheet = ss.getSheetByName("TCDetails");
var getLastRow = ldSheet.getLastRow();
// getRange(row, column, numRows, numColumns)
if(sltlundin == "Lunch"){
var data = ldSheet.getRange(2, 13, getLastRow - 1, 1).getValues();
} else if(sltlundin == "Dinner"){
var data = ldSheet.getRange(2, 14, getLastRow - 1, 1).getValues();
}
Logger.log(data);
return data;
}
function getBookID(DOBoking) {
// DOBoking = "19-04-2021";
// session = "session1";
var bDay = '';
var arrDate1 = DOBoking.toString().split("-");
var cDay = arrDate1[0];
var cMon = arrDate1[1];
var ss = 'B';
var rowCount = '';
var sNo = '';
// if(session == "session1")
// ss = "S1";
// else
// ss = "S2";
//get no of rows
var rows = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(DOBoking).getDataRange().getValues();
var filteredRows = rows.filter(function (row) {
if (row != 0) {
rowCount = row;
}
else
rowCount = '1';
return row;
});
sNo = filteredRows.length; // Logger.log("RC:" + rowCount);
Logger.log(sNo);
// bDay = ss+"-"+cDay+cMon+"-"+sNo;
bDay = ss + "-" + cDay + cMon + "-" + sNo;
return bDay;
}
function getPictures() {
//Sort Worksheet Tabs in Alphabetical Order in Google sheet Please don't delete "sortSheets" funcion
sortSheets();
var destination_id = '15C1HFYAk-2uKAGaMvKmerSRGigAaLKw8';// ID OF GOOGLE DRIVE DIRECTORY;
var destination = DriveApp.getFolderById(destination_id);
var files = destination.getFiles();
var file_array = [];
while (files.hasNext()) {
var file = files.next();
file_array.push(file.getId());
}
return file_array;
}
function getSessions() {
sortSheets();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var psSheet = ss.getSheetByName("TCDetails");
var getLastRow = psSheet.getLastRow();
// getRange(row, column, numRows, numColumns)
var data = psSheet.getRange(2, 4, getLastRow - 1, 2).getValues();
// Logger.log(data);
return data;
// Logger.log( psSheet.getRange(2, 4, getLastRow -1, 2).getValues());
}
function getPersons() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var psSheet = ss.getSheetByName("TCDetails");
var getLastRow = psSheet.getLastRow();
// Logger.log( psSheet.getRange(2, 7, getLastRow -1, 2).getValues());
// Logger.log(data);
return psSheet.getRange(2, 7, getLastRow - 1, 2).getValues();
}
function getDiners() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var psSheet = ss.getSheetByName("TCDetails");
var getLastRow = psSheet.getLastRow();
// Logger.log( psSheet.getRange(2, 7, getLastRow -1, 2).getValues());
// Logger.log(data);
return psSheet.getRange(2, 10, getLastRow - 1, 2).getValues();
}
function getDinnerType() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var dtSheet = ss.getSheetByName("Event_Holidays");
var getLastRow = dtSheet.getLastRow();
//console.log(dtSheet.getRange(2, 4, getLastRow - 1, 2).getValues());
return dtSheet.getRange(2, 4, getLastRow - 1, 2).getValues();
}
function getHDate() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var HDSheet = ss.getSheetByName("Event_Holidays");
var getHDLastRow = HDSheet.getLastRow();
var data_array = [];
var dateArr = [];
for (var i = 2; i <= getHDLastRow; i++) {
if (data_array.indexOf(HDSheet.getRange(i, 1).getValue()) === -1) {
data_array.push(HDSheet.getRange(i, 1).getValue());
}
}
//Logger.log(data_array);
for (var i = 0; i < data_array.length; i++) {
var mon = '';
var arr = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var dateVal = data_array[i]; //Logger.log(dateVal);
var splitDate1 = dateVal.toString().split("-");
var splitDate2 = dateVal.toString().split(" ");
arr.forEach(function (element, index) {
if (splitDate2[1] == element) {
mon = index + 1;
}
});
if (splitDate1.length == 3) {
var dtvals = splitDate1[0] + '-' + splitDate1[1] + '-' + splitDate1[2];
dateArr.push(dtvals);
Logger.log(dtvals);
}
else {
var dtvals = mon + '-' + splitDate2[2] + '-' + splitDate2[3];
dateArr.push(dtvals);
// Logger.log("else: "+dtvals);
}
} // end for loop
Logger.log(dateArr);
return dateArr;
}
function getHolidayDates() {
var dataDates = [];
var rowsValue = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Holidays").getDataRange().getValues();
//Logger.log(rowsValue.length);
for (var i = 0; i < rowsValue.length; i++) {
var mon = '';
var arr = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var dateVal = rowsValue[i];
var splitDate1 = dateVal.toString().split("-");
var splitDate2 = dateVal.toString().split(" ");
arr.forEach(function (element, index) {
if (splitDate2[1] == element) {
mon = index + 1;
}
});
if (splitDate1.length == 3) {
dataDates = dateVal;
// Logger.log(dataDates);
}
else {
var dtvals = mon + '-' + splitDate2[2] + '-' + splitDate2[3];
dataDates = dtvals;
// Logger.log("else: "+dataDates);
}
} // end for loop
/* var ss= SpreadsheetApp.getActiveSpreadsheet();
var hdSheet = ss.getSheetByName("Holidays");
var getLastRow = hdSheet.getLastRow();
// getRange(row, column, numRows, numColumns)
var data = hdSheet.getRange(2, 1, getLastRow -1, 1).getValues().toString();
Logger.log(data);
var dataDates = [];
var getNoRows = data.length;
var monD = '';
for(var i = 2; i <= getNoRows; i++)
{
// Logger.log(getNoRows);
Logger.log(data[i]); */
// var splitDate = data[i].split("-");
// dataDates = new Date( splitDate[2], splitDate[1], splitDate[0]).getTime(); Logger.log(dataDates[i]);
// var splitDate = Utilities.formatDate(data[i], 'Asia/Singapore', 'dd-MM-yy HH:mm:ss');
// Logger.log(data[i]);
// var arr = ["Jan","Feb","Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
// arr.forEach(function (element, index)
// {
// if(splitDate[1] == element)
// {
// monD = index + 1;
// }
// });
//
// if(splitDate.length <= 2){
// dataDates = data[i];
// }
// else{
// dataDates = monD + '-' + splitDate[2] + '-' + splitDate[3] ;
// }
// }
Logger.log(dataDates);
return dataDates;
}
/*function sortSheets () {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheetNameArray = [];
var sheetMap = {};
var sheets = ss.getSheets();
for (var i = 0; i < sheets.length; i++) {
sheetNameArray.push(sheets[i].getName());
sheetMap[sheets[i].getName()] = sheets[i]
}
sheetNameArray.sort();
for( var j = 0; j < sheets.length; j++ ) {
//ss.setActiveSheet(ss.getSheetByName(sheetNameArray[j]));
ss.setActiveSheet(sheetMap[sheetNameArray[j]]);
ss.moveActiveSheet(j + 1);
}
}*/
function sortSheets() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheets = ss.getSheets();
var obj = sheets.map(function (s) {
var sheetName = s.getSheetName();
var date = 0;
if (sheetName != "GUI") {
var ar = sheetName.split("-"); Logger.log(ar);
date = new Date(ar[2], ar[1], ar[0]).getTime(); Logger.log(date);
}
return { sheet: s, converted: date };
});
obj.sort(function (a, b) { return a.converted > b.converted ? 1 : -1 });
obj.forEach(function (s, i) {
ss.setActiveSheet(s.sheet);
ss.moveActiveSheet(i + 1);
});
}
Copy
Step 14 :- Click to Copy Below Code and Paste to utils.gs File
/* @Include JavaScript and CSS Files */
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename)
.getContent();
}
function DMTest(){
var sDate = "27-08-2021";//searchDate; //
var arrDate1 = sDate.toString().split("-");
var cDay = arrDate1[0];
var cMon = arrDate1[1];
var cYear = arrDate1[2];
// set Month names
var monthNames = ["January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December"
];
console.log(monthNames[Number(cMon)]);
var dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saterday"];
var dayName = 'Friday';
var monthName = "July";
var year = Number(cYear);
var data = [];
}
function checkTime(){
// You could use now Date(); on its own but it will not look nice.
var sysDate = Utilities.formatDate(new Date(), 'Asia/Singapore', 'dd-MM-yyyy HH:mm')
var splitDate = sysDate.toString().split(" ");
var cutoffTime = splitDate[0]+" "+ "16:00";
if(sysDate > cutoffTime){
console.log(sysDate +" > "+ cutoffTime);
}
else{
console.log(sysDate +" < "+ cutoffTime);
}
}
Copy
Step 15 :- Click to Copy Below Code and Paste to covidDialog.gs File
Copy
Step 16 :- Click to Copy Below Code and Paste to backupcode.gs File
Copy
Step 17 :- Click to Deploy >> New Deployment >> Deploy >>
More Detail See Video :-