October 31, 2016
October 04, 2016
Attendance Tracking System online
Attendance Google Form |
Source code
function consolidatingAttendance(){
var attendanceSpreadSheet = SpreadsheetApp.openById("consumerfedAttendanceSheet");
var attendanceSheet = attendanceSpreadSheet.getSheetByName("ATTENDANCE");
var consolidationSheet = attendanceSpreadSheet.getSheetByName("CONSOLIDATION");
var startRowAttendance = consolidationSheet.getRange("H1").getValue();
var lastRowAttendance = attendanceSheet.getLastRow();
var lastRowOfAttendanceArray = lastRowAttendance - startRowAttendance - 1;
var branchListAS = attendanceSheet.getRange(startRowAttendance,2,lastRowOfAttendanceArray,1).getValues();
var empListAS = attendanceSheet.getRange(startRowAttendance,3,lastRowOfAttendanceArray,1).getValues();
var attndListAS = attendanceSheet.getRange(startRowAttendance,4,lastRowOfAttendanceArray,1).getValues();
//Logger.log(branchListAS);
var currentAttndRowPstn = startRowAttendance;
//var branchListCS = consolidationSheet.getRange(1,1,consolidationSheet.getLastRow(),1).getValues();
// Logger.log(branchListCS);
//var branchListCS = consolidationSheet.getRange(1,1,consolidationSheet.getLastRow(),1).getValues();
//var empListCS = consolidationSheet.getRange(1,2,consolidationSheet.getLastRow(),1).getValues();
Logger.log( " Len :"+branchListAS.length);
for(var rowCount = 0; rowCount < branchListAS.length; rowCount++){
//Logger.log(currentAttndRowPstn+" , "+branchListAS[rowCount]+" , "+empListAS[rowCount]+" , "+attndListAS[rowCount]);
var branchListCS = consolidationSheet.getRange(1,1,consolidationSheet.getLastRow(),1).getValues();
var empListCS = consolidationSheet.getRange(1,2,consolidationSheet.getLastRow(),1).getValues();
//Logger.log(" B :"+branchListCS[0]);
var lastRowCS = consolidationSheet.getLastRow();
var lastConsolidationRow = lastRowCS + 1;
var branchNameAS = branchListAS[rowCount].toString();
var employeeNameAS = empListAS[rowCount].toString();
var attendanceTypeAS = attndListAS[rowCount].toString(); // present,onduty etc
currentAttndRowPstn = currentAttndRowPstn + 1;
consolidationSheet.getRange("H1").setValue(currentAttndRowPstn);
var isInserted = 1;
for(var rowCS = 0; rowCS < branchListCS.length; rowCS++){
var attendanceType = attendanceTypeAS;
var branchNameCS = branchListCS[rowCS].toString();
var employeeNameCS = empListCS[rowCS].toString();
var as = branchNameAS.concat(employeeNameAS);
var cs = branchNameCS.concat(employeeNameCS);
var value = as.localeCompare(cs);
//Logger.log("v :"+value +"as :"+as +"cs :"+cs);
if(value == 0){
var row = rowCS + 1;
var choose = attendanceType;
attendanceType = "";
//Logger.log(" A :"+attendanceType+" R :"+row );
switch(choose){
case "PRESENT":
value = consolidationSheet.getRange("C"+row).getValue();
consolidationSheet.getRange("C"+row).setValue(value+1);
consolidationSheet.getRange("I"+row).setValue(new Date());
attendanceType = "";
// Logger.log('----'+value);
break;
case "FULL DAY(L)":
value = consolidationSheet.getRange("D"+row).getValue();
consolidationSheet.getRange("D"+row).setValue(value+1);
consolidationSheet.getRange("I"+row).setValue(new Date());
attendanceType = "";
//Logger.log('----'+value);
break;
case "HALF DAY - MORNING(L)":
value = consolidationSheet.getRange("E"+row).getValue();
consolidationSheet.getRange("E"+row).setValue(value+1);
consolidationSheet.getRange("I"+row).setValue(new Date());
attendanceType = "";
//Logger.log('----'+value);
break;
case "HALF DAY - AFTER NOON(L)":
value = consolidationSheet.getRange("F"+row).getValue();
consolidationSheet.getRange("F"+row).setValue(value+1);
consolidationSheet.getRange("I"+row).setValue(new Date());
attendanceType = "";
//Logger.log('----'+value);
break;
case "ON DUTY":
value = consolidationSheet.getRange("G"+row).getValue();
consolidationSheet.getRange("G"+row).setValue(value+1);
consolidationSheet.getRange("I"+row).setValue(new Date());
attendanceType = "";
//Logger.log('----'+value);
break;
default:
}
isInserted = 0;
attendanceType = "";
branchNameAS = "";
employeeNameAS = "";
}
else{
if(attendanceType.length > 0) {
var choose = attendanceType;
consolidationSheet.getRange("A"+lastConsolidationRow).setValue(branchNameAS);
consolidationSheet.getRange("B"+lastConsolidationRow).setValue(employeeNameAS);
Logger.log(" Before switch : "+choose);
switch(choose){
case "FULL DAY(L)":
consolidationSheet.getRange("D"+lastConsolidationRow).setValue(1);
consolidationSheet.getRange("C"+lastConsolidationRow).setValue(0);
consolidationSheet.getRange("E"+lastConsolidationRow).setValue(0);
consolidationSheet.getRange("F"+lastConsolidationRow).setValue(0);
consolidationSheet.getRange("G"+lastConsolidationRow).setValue(0);
break;
case "HALF DAY - MORNING(L)":
consolidationSheet.getRange("E"+lastConsolidationRow).setValue(1);
consolidationSheet.getRange("C"+lastConsolidationRow).setValue(0);
consolidationSheet.getRange("D"+lastConsolidationRow).setValue(0);
consolidationSheet.getRange("F"+lastConsolidationRow).setValue(0);
consolidationSheet.getRange("G"+lastConsolidationRow).setValue(0);
break;
case "HALF DAY - AFTER NOON(L)":
consolidationSheet.getRange("F"+lastConsolidationRow).setValue(1);
consolidationSheet.getRange("C"+lastConsolidationRow).setValue(0);
consolidationSheet.getRange("E"+lastConsolidationRow).setValue(0);
consolidationSheet.getRange("D"+lastConsolidationRow).setValue(0);
consolidationSheet.getRange("G"+lastConsolidationRow).setValue(0);
break;
case "ON DUTY":
consolidationSheet.getRange("G"+lastConsolidationRow).setValue(1);
consolidationSheet.getRange("C"+lastConsolidationRow).setValue(0);
consolidationSheet.getRange("E"+lastConsolidationRow).setValue(0);
consolidationSheet.getRange("F"+lastConsolidationRow).setValue(0);
consolidationSheet.getRange("D"+lastConsolidationRow).setValue(0);
break;
case "PRESENT":
consolidationSheet.getRange("C"+lastConsolidationRow).setValue(1);
consolidationSheet.getRange("D"+lastConsolidationRow).setValue(0);
consolidationSheet.getRange("E"+lastConsolidationRow).setValue(0);
consolidationSheet.getRange("F"+lastConsolidationRow).setValue(0);
consolidationSheet.getRange("G"+lastConsolidationRow).setValue(0);
break;
default :
Logger.log("test : "+attendanceType);
var values = [[ "0", "0", "0" , "0", "0"]];
consolidationSheet.getRange("C"+lastConsolidationRow+":G"+lastConsolidationRow).setValue(values);
} //end switch
}// if attendanceType
// consolidationSheet.getRange("I"+lastConsolidationRow).setValue(new Date());
} //end if - else
//Logger.log(" R: "+rowCount+" isInserted "+isInserted );
}
}
}
Link to attendance form
http://javabelazy.blogspot.in/
Labels:
attendance,
consumerfed,
google,
google form,
google script,
office,
spreadsheet
Location:
Dubai - United Arab Emirates
October 01, 2016
Subscribe to:
Posts (Atom)