apollodec/Apollo/assets/js/controllers/examAttendanceCtrl.js
2019-04-25 14:46:53 +05:30

470 lines
14 KiB
JavaScript

'use strict';
/**
* controllers for ng-table
* Simple table with sorting and filtering on AngularJS
*/
app.controller('examAttendanceCtrl', ["$scope","$rootScope","toaster", "$filter", "ngTableParams", "API_POINTS", "$sessionStorage", "$http", "$state","$modal","$log", function ($scope,$rootScope,toaster, $filter, ngTableParams, apiPoint, $sessionStorage, $http, $state,$modal,$log) {
$scope.myModel = {
"batchName":"",
"centerName":"",
"examDate":"",
"universityName":"",
"examAttendance":""
};
$scope.pdfModel = {
"universityDetails":"",
"studentDetails":"",
"batchDetails":"",
"courseDetails":"",
"centerDetails":"",
"semDataType":""
};
$rootScope.userType = JSON.parse(sessionStorage.getItem('localObj')).localType;
$scope.isTblShow = false;
$scope.isLoader = false;
$scope.isLoaderShow = false;
$scope.isLoaderTxt = "Loading...";
// sorting function for table params
$scope.sort = function(keyname){
$scope.sortKey = keyname; //set the sortKey to the param passed
$scope.reverse = !$scope.reverse; //if true make it false and vice versa
}
/*
* init function
* created by kms
* */
$scope.init = function () {
// var logcheck = JSON.parse(sessionStorage.getItem('localObj'));
// const LOCALTYPE = logcheck.localType;
// if (logcheck != null && (LOCALTYPE == 'R003' || LOCALTYPE == 'R004' )) {
// console.log("if");
// }else {
// if(logcheck != null && LOCALTYPE !='R001') {
// console.log("else if");
// $state.go('app.dashboard');
// } else {
// console.log("else else");
// //ipCookie.remove('cookiechk');
// window.sessionStorage.clear();
// $state.go('login.signin');
// }
// }
var getUniv = {
method: 'POST',
url: apiPoint.url + 'getUniversityCourseDetails/',
headers: {
'Content-Type': 'application/json'
},
data: {
requestedBy: JSON.parse(sessionStorage.getItem('localObj')).localUserID,
branchId:JSON.parse(sessionStorage.getItem('localObj')).localBranchID
}
};
$http(getUniv).then(function (response) {
if (response.data.status == 200 && response.data.universityStatus) {
//$scope.batchDetails = response.data.batchDetails;
$scope.university = response.data.univerSityDetails;
$scope.centerDetails = response.data.centerDetails;
} else {
$scope.batchDetails = "";
$scope.centerDetails = "";
}
});
}
/*
* get student details
* created by kms
* */
$scope.studentInfo="";
$scope.ExamAttendancee="";
$scope.getExamAttendanceDetails = function (form,myModel) {
//console.log(myModel);return false;
if(myModel.universityName == '' || myModel.universityName == null || myModel.universityName == undefined){
swal('Select University','','warning');
return false;
}
if(myModel.centerName == '' || myModel.centerName == null || myModel.centerName == undefined){
swal('Select Center','','warning');
return false;
}
if(myModel.batchName == null || myModel.batchName == '' || myModel.batchName == undefined){
swal('Select Batch','','warning');
return false;
}
if(myModel.examDate == null || myModel.examDate == '' || myModel.examDate == undefined){
swal('Select Date of Examination','','warning');
return false;
}
if(myModel.examAttendance == null || myModel.examAttendance == '' || myModel.examAttendance == undefined){
swal('Select Timing of Examination','','warning');
return false;
}
var firstError = null;
if (form.$invalid) {
var field = null, firstError = null;
for (field in form) {
if (field[0] != '$') {
if (firstError === null && !form[field].$valid) {
firstError = form[field].$name;
}
if (form[field].$pristine) {
form[field].$dirty = true;
}
}
}
angular.element('.ng-invalid[name=' + firstError + ']').focus();
// swal("The form cannot be submitted because it contains validation errors!", "Errors are marked with a red, dashed border!", "error");
} else {
// $scope.selectedStudentsID = [];
// $scope.isLoaderShow = true;
// $scope.myModel.all = false;
// $scope.isTblShow = false;
var centerName = myModel.centerName;
var examDate = myModel.examDate;
var batch = myModel.batchName;
var University =myModel.universityName;
var exam_attendance = myModel.examAttendance;
$scope.ExamAttendancee = exam_attendance;
//alert(examDate);
var getAttendance = {
method: 'POST',
url: apiPoint.url + 'getStudentDetailsForExamAttendance/',
headers: {
'Content-Type': 'application/json'
},
data: {
university:University,
centerName: centerName,
batch:batch,
examDate:examDate,
requestedtBy: JSON.parse(sessionStorage.getItem('localObj')).localUserID,
branchId: JSON.parse(sessionStorage.getItem('localObj')).localBranchID,
requestedDept: JSON.parse(sessionStorage.getItem('localObj')).localType,
exam_attendance:exam_attendance,
}
};
$http(getAttendance).then(function (response) {
//console.log(response);
if (response.data.status == 200 && response.data.studentDetails) {
$scope.studentInfo = response.data.studentDetails;
$scope.isLoaderShow = false;
$scope.studentInfoAM = [];
$scope.studentInfoPM = [];
angular.forEach($scope.studentInfo,function(value,key){
//var dateType = $filter('date')(new Date(value.FromTime),'a');
var dateType = value.FromTime.substr(-2);
if(dateType == "AM" || dateType == "am")
{
$scope.studentInfoAM.push(value);
}else if(dateType == "PM" || dateType == "pm")
{
$scope.studentInfoPM.push(value);
}
$rootScope.studentInfoAM_Length = $scope.studentInfoAM.length;
$rootScope.studentInfoPM_Length = $scope.studentInfoPM.length;
});
//console.log($scope.studentInfo);
$scope.open($scope.myModel.universityName['universityName'],$scope.studentInfoAM,$scope.studentInfoPM,myModel.centerName,$scope.selectedBatchName, myModel.examDate);
}
else
{
$scope.studentInfo="";
$scope.isLoaderShow = true;
//$scope.isTblShow = false;
$scope.isLoaderTxt = "No Records Found";
}
},function(error){
$scope.isLoaderShow = true;
//$scope.isTblShow = false;
$scope.isLoaderTxt = "No Records Found";
});
}
}
$scope.open = function (UNAME,PDFITEM_AM,PDFITEM_PM,PDFCENTER,PDFBATCH,PDFEXAMDATE) {
/****************************************************************/
$rootScope.dataForExamAttendanceAM = PDFITEM_AM;
$rootScope.dataForExamAttendancePM = PDFITEM_PM;
/****************************************************************/
$rootScope.pdfcenter = PDFCENTER;
$rootScope.pdfbatch = PDFBATCH;
$rootScope.pdfexamdate = PDFEXAMDATE;
$rootScope.pdfuname = UNAME;
$rootScope.ExamAttens = $scope.ExamAttendancee;
//console.log($rootScope.ExamAttens);return false;
var Size = {width:800};
var modalInstance = $modal.open({
templateUrl: 'assets/views/hallticket/examAttendancePDF.html',
controller: 'examAttendanceCtrl',
size:Size
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$rootScope.dataForExamAttendanceAM = "";
$rootScope.dataForExamAttendancePM = "";
$rootScope.pdfcenter = "";
$rootScope.pdfbatch = "";
$rootScope.pdfexamdate = "";
$rootScope.pdfuname = "";
$log.info('Modal dismissed at: ' + new Date());
});
};
$scope.captureCourseName = function()
{
$scope.selectedCourseName = course.options[course.selectedIndex].text;
};
$scope.captureBatchName = function()
{
$scope.selectedBatchName = batch.options[batch.selectedIndex].text;
};
$scope.printAttendanceDetails = function() {
var AttendanceTableID_AM = "";
var AttendanceTableID_PM = "";
// $scope.currentPage = 1;
// $scope.numPerPage = 10;
$scope.pdfExamDateToDisplay = $filter('date')(new Date($rootScope.pdfexamdate),'dd-MM-yyyy');
var fileNameAM = $rootScope.pdfuname+'-'+$rootScope.pdfcenter['CenterName']+"-"+$rootScope.pdfbatch+'- Attendance of '+$scope.pdfExamDateToDisplay+'ForeNoon Session.PDF';
var fileNamePM = $rootScope.pdfuname+'-'+$rootScope.pdfcenter['CenterName']+"-"+$rootScope.pdfbatch+'- Attendance of '+$scope.pdfExamDateToDisplay+'After Noon Session.PDF';
var margins = {
top: 70,
bottom: 40,
left: 30,
width: 500,
};
var pdfSize = 'a4';
var doc1 = new jsPDF('l', 'pt',pdfSize);
// doc1.setPage(10);
doc1.autoTableSetDefaults({
//
// styles: {cellPadding: 5.0, fontSize: 8, height:70, overflow: 'linebreak'
// },
styles: {overflow: 'linebreak', font: 'arial', fontSize: 8, cellPadding: 5, columnwidth: 'auto'},
// columStyles:{
// 0:{columnWidth:20},
// 1:{columnWidth:50},
// 2:{columnWidth:50},
// 3:{columnWidth:20},
// 4:{columnWidth:50},
// 5:{columnWidth:50},
// 6:{columnWidth:40},
// 7:{columnWidth:50},
// 8:{columnWidth:40},
// 9:{columnWidth:50}
// },
headerStyles: {fillColor: [245, 245, 240], textColor: 0}
});
var pdfSize = 'a4';
var doc2 = new jsPDF('l', 'pt',pdfSize);
// doc2.setPage(10);
doc2.autoTableSetDefaults({
// rowWidth: 'wrap',
// columnWidth: 'wrap',
// styles: {cellPadding: 5.0, fontSize: 8, height:70,overflow: 'linebreak',columnWidth: 'wrap'},
styles: {overflow: 'linebreak', font: 'arial', fontSize: 8, cellPadding: 5, columnwidth: 'auto'},
headerStyles: {fillColor: [245, 245, 240], textColor: 0}
});
if(document.getElementById("attendanceTableAM"))
{
var AttendanceTableID_AM = doc1.autoTableHtmlToJson(document.getElementById("attendanceTableAM"));
}
if(document.getElementById("attendanceTablePM"))
{
var AttendanceTableID_PM = doc2.autoTableHtmlToJson(document.getElementById("attendanceTablePM"));
}
var headerAM = function(data) {
var heading = $rootScope.pdfuname+' '+$rootScope.pdfbatch+' Examination'+' '+'Center'+' '+$rootScope.pdfcenter['CenterName']+' Attendance of '+ $scope.pdfExamDateToDisplay+' Forenoon Session ';
// var heading1='Attendance of '+$scope.pdfExamDateToDisplay+'Forenoon Session';
doc1.setFontSize(9);
doc1.setFontStyle('bold');
//doc1.text(60,30,heading);
var heading_length = heading.length;
console.log(heading_length);
var heading_start_point = 0;
// var heading1_start_point = 0;
if(heading_length <= 100)
{
var heading_start_point = 50;
// var heading1_start_point = 350;
console.log('heading_length <= 100');
}
else
{
var heading_start_point = 50;
// var heading1_start_point = 300;
console.log('else');
}
// console.log(heading_length);
// console.log((doc1.internal.pageSize.width/2));
// console.log((doc1.internal.pageSize.width/2)-(heading_length));
doc1.text(heading_start_point,30,heading);
doc1.setFontSize(9);
doc1.setFontStyle('bold');
//doc1.text(70,45,heading1);
// doc1.text(heading1_start_point,45,heading1);
};
// ctx.textAlign = "right";
//ctx.fillText("textAlign=right",150, 140);
var headerPM = function(data) {
var heading = $rootScope.pdfuname+' '+$rootScope.pdfbatch+' Examination'+' '+'Center'+' '+$rootScope.pdfcenter['CenterName']+' Attendance of '+ $scope.pdfExamDateToDisplay+' After Noon Session';
// var heading1='Attendance of '+$scope.pdfExamDateToDisplay+'After Noon Session';
doc2.setFontSize(9);
doc2.setFont("helvetica");
//doc2.setFontStyle('bold');
var heading_length = heading.length;
console.log(heading_length);
var heading_start_point = 0;
// var heading1_start_point = 0;
if(heading_length <= 100)
{
var heading_start_point = 50;
// var heading1_start_point = 350;
console.log('heading_length <= 100');
}
else
{
var heading_start_point = 50;
// var heading1_start_point = 300;
console.log('else');
}
doc2.text(heading_start_point,30,heading);
doc2.setFontSize(9);
doc2.setFont("helvetica");
//doc2.setFontStyle('bold');
// doc2.text(heading1_start_point,45,heading1);
};
var autoTableEndPosYvalue = 0;
var options1 = {
addPageContent: headerAM,
drawRow: function(row,data){
row.height=50
},
margin: {
top: 50
},
theme :'grid'
};
var options2 = {
addPageContent: headerPM,
drawRow: function(row,data){
row.height=50
},
margin: {
top: 50
},
theme :'grid'
};
if(AttendanceTableID_AM != "")
{
console.log('AttendanceTableID_AM');
doc1.autoTable(AttendanceTableID_AM.columns, AttendanceTableID_AM.data,
options1);
doc1.save(fileNameAM);
}
if(AttendanceTableID_PM != "")
{
console.log('AttendanceTableID_PM');
doc2.autoTable(AttendanceTableID_PM.columns, AttendanceTableID_PM.data, options2);
doc2.save(fileNamePM);
}
//console.log('END CALLED');
}
}]);