367 lines
9.6 KiB
JavaScript
367 lines
9.6 KiB
JavaScript
'use strict';
|
|
/**
|
|
* This Controller for Promote Students Funcitonality.
|
|
* Simple table with sorting and filtering on AngularJS
|
|
*/
|
|
app.controller('BatchmomentCtrl', ["$scope","$rootScope","toaster", "$filter", "ngTableParams", "API_POINTS", "$localStorage", "$http", "$state","$modal","$log", function ($scope,$rootScope,toaster, $filter, ngTableParams, apiPoint, $localStorage, $http, $state,$modal,$log) {
|
|
|
|
$scope.myModel = {
|
|
"universityName":"",
|
|
"batchName":"",
|
|
"batchID":""
|
|
};
|
|
|
|
$scope.isTblShow = false;
|
|
$scope.isLoader = false;
|
|
$scope.isLoaderShow = false;
|
|
$scope.isSubLoaderShow = false;
|
|
$scope.isLoaderTxt = "Loading...";
|
|
$scope.isShowNxtBatch = false;
|
|
$scope.getStudentButtonTxt = 'GET STUDENTS';
|
|
$scope.promoteButtonTxt = 'PROMOTE';
|
|
$scope.promoteButtonStatus = false;
|
|
|
|
|
|
|
|
/*
|
|
* init function
|
|
* created by velz
|
|
* */
|
|
$scope.init = function () {
|
|
|
|
|
|
// var logcheck = JSON.parse(localStorage.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.localStorage.clear();
|
|
// $state.go('login.signin');
|
|
// }
|
|
// }
|
|
|
|
var getUniv = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'getUniversityBatchDetails/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID,
|
|
branchId:JSON.parse(localStorage.getItem('localObj')).localBranchID
|
|
}
|
|
};
|
|
$http(getUniv).then(function (response) {
|
|
if (response.data.status==200 && response.data.universityStatus) {
|
|
$scope.university = response.data.univerSityDetails;
|
|
|
|
|
|
} else {
|
|
swal('University Not Found','','error');
|
|
$scope.university = "";
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
|
|
|
|
$scope.getStudentDetails = function () {
|
|
|
|
if($scope.myModel.universityName == null || $scope.myModel.universityName == '' || $scope.myModel.universityName == undefined){
|
|
swal('Select University','','warning');
|
|
return false;
|
|
}
|
|
|
|
if($scope.myModel.batchName == null || $scope.myModel.batchName == '' || $scope.myModel.batchName == undefined){
|
|
swal('Select Batch','','warning');
|
|
return false;
|
|
}
|
|
|
|
$scope.isLoaderTxt = "Loading...";
|
|
$scope.getStudentButtonTxt = 'PLEASE WAIT';
|
|
$scope.selectedStudentsID = [];
|
|
$scope.isLoaderShow = true;
|
|
$scope.isSubLoaderShow = false;
|
|
$scope.myModel.all = false;
|
|
$scope.isTblShow = false;
|
|
var university = $scope.myModel.universityName;
|
|
var batch = $scope.myModel.batchName;
|
|
var getStudents = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'getStudentListForPromoteBatch/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
university: university,
|
|
batch:batch,
|
|
branchId: JSON.parse(localStorage.getItem('localObj')).localBranchID,
|
|
}
|
|
};
|
|
$http(getStudents).then(function (response) {
|
|
if (response.data.status == 200 && response.data.studentStatus) {
|
|
$scope.studentInfo = response.data.studentDetails;
|
|
$scope.nextBatchDetails = response.data.nextbatchDetails;
|
|
$scope.isLoaderShow = false;
|
|
$scope.isTblShow = true;
|
|
$scope.isShowNxtBatch = true;
|
|
$scope.getStudentButtonTxt = 'GET STUDENTS';
|
|
|
|
}
|
|
else
|
|
{
|
|
$scope.studentInfo="";
|
|
$scope.isLoaderShow = true;
|
|
$scope.isSubLoaderShow = true;
|
|
$scope.isTblShow = false;
|
|
$scope.isLoaderTxt = "No Records Found";
|
|
$scope.isShowNxtBatch = false;
|
|
$scope.nextBatchDetails = "";
|
|
$scope.getStudentButtonTxt = 'GET STUDENTS';
|
|
}
|
|
},function(error){
|
|
$scope.isLoaderShow = true;
|
|
$scope.isSubLoaderShow = true;
|
|
$scope.isTblShow = false;
|
|
$scope.isLoaderTxt = "No Records Found";
|
|
$scope.isShowNxtBatch = false;
|
|
$scope.nextBatchDetails = "";
|
|
$scope.getStudentButtonTxt = 'GET STUDENTS';
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.selectedStudentsID = [];
|
|
$scope.isClick = function(e)
|
|
{
|
|
|
|
|
|
var ide = e.target;
|
|
var val = (ide.checked ? true : false);
|
|
var sid = e.target.id;
|
|
angular.forEach($scope.studentInfo,function(value,key){
|
|
if(sid == value.StudentID)
|
|
{
|
|
sid = value;
|
|
}
|
|
});
|
|
|
|
var pos = $scope.selectedStudentsID.indexOf(sid);
|
|
|
|
if(val)
|
|
{
|
|
if( pos == -1)
|
|
{
|
|
|
|
$scope.selectedStudentsID.push(sid);
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
$scope.selectedStudentsID.splice(pos,1);
|
|
}
|
|
|
|
//console.log($scope.selectedStudentsID);
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.isCheckAll = function(e)
|
|
{
|
|
var val = (e.target.checked ? true : false);
|
|
|
|
if(val)
|
|
{
|
|
var len = $scope.studentInfo.length;
|
|
var i = 0;
|
|
for(i=0;i<len;i++)
|
|
{
|
|
if($scope.selectedStudentsID.indexOf($scope.studentInfo[i]) === -1)
|
|
{
|
|
$scope.selectedStudentsID.push($scope.studentInfo[i]);
|
|
}
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
$scope.selectedStudentsID = [];
|
|
}
|
|
//console.log($scope.selectedStudentsID);
|
|
}
|
|
|
|
|
|
$scope.promoteStudents = function()
|
|
{
|
|
if($scope.selectedStudentsID.length == 0 )
|
|
{
|
|
swal('Select Proper Details..!','University, Batch, and atleast one student','warning');
|
|
return false;
|
|
}
|
|
|
|
if($scope.nextBatchDetails == "")
|
|
{
|
|
swal('No Batch Available','It seems to be, There is no next immediate batch. create new Batch in Batch Master ','warning');
|
|
return false;
|
|
|
|
}
|
|
|
|
var sessionCount = 0;
|
|
angular.forEach($scope.studentInfo,function(value,key){
|
|
|
|
if(value.SessionName == "" || value.nextSessionName == "")
|
|
{
|
|
sessionCount = sessionCount + 1;
|
|
}
|
|
|
|
});
|
|
|
|
if(sessionCount != 0)
|
|
{
|
|
// swal('No Sessions Available','It seems to be, There is no current OR next immediate session for some studnets. Ensure Session details before Promote students ','warning');
|
|
// return false;
|
|
swal({
|
|
title: "No Sessions Available!",
|
|
text: "It seems to be, There are no current OR next immediate session not available for some studnets. Ensure Session details before Promote next batch",
|
|
icon: "warning",
|
|
buttons: true,
|
|
dangerMode: true,
|
|
})
|
|
.then((willPromote) => {
|
|
if (!willPromote)
|
|
{
|
|
return false;
|
|
}
|
|
});
|
|
}
|
|
|
|
//calculate Due Dates
|
|
$scope.promoteButtonStatus = true;
|
|
$scope.promoteButtonTxt = "PLEASE WAIT";
|
|
|
|
var nxtBatchDate1 = $scope.nextBatchDetails[0].BatchDate;
|
|
var nxtBatchDate2 = nxtBatchDate1.split('-');
|
|
//console.log(nxtBatchDate);
|
|
var nxtBatchDate = nxtBatchDate2[2]+'-'+nxtBatchDate2[1]+'-'+nxtBatchDate2[0];
|
|
//console.log(nxtBatchDate);
|
|
nxtBatchDate = new Date(nxtBatchDate);
|
|
var currentDate = new Date();
|
|
//console.log(currentDate);
|
|
//console.log(nxtBatchDate);
|
|
var seconddue = new Date();
|
|
|
|
if(nxtBatchDate < currentDate)
|
|
{
|
|
seconddue = new Date();
|
|
}
|
|
else
|
|
{
|
|
//console.log('CAL');
|
|
var timeDiff = Math.abs(currentDate.getTime() - nxtBatchDate.getTime());
|
|
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
|
|
//console.log(diffDays);
|
|
if(diffDays > 30)
|
|
{
|
|
|
|
seconddue = new Date((nxtBatchDate2[2]+'-'+nxtBatchDate2[1]+'-'+nxtBatchDate2[0]));
|
|
seconddue.setDate(nxtBatchDate.getDate() - 30);
|
|
|
|
//console.log(seconddue);
|
|
}
|
|
else if(diffDays < 30 && diffDays >= 15)
|
|
{
|
|
seconddue = new Date((nxtBatchDate2[2]+'-'+nxtBatchDate2[1]+'-'+nxtBatchDate2[0]));
|
|
seconddue.setDate(nxtBatchDate.getDate() - 15);
|
|
//console.log(seconddue);
|
|
}
|
|
|
|
}
|
|
|
|
/*End of calculate Due Dates*/
|
|
|
|
/*Store All info*/
|
|
var promoteBatch = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'promoteBatchInfomation/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
|
|
UniversityID : $scope.myModel.universityName.universityID,
|
|
BatchDetails : $scope.nextBatchDetails[0],
|
|
StudentDetails : $scope.selectedStudentsID,
|
|
FirstDueDate : currentDate,
|
|
SecondDueDate : seconddue,
|
|
requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID,
|
|
branchId:JSON.parse(localStorage.getItem('localObj')).localBranchID
|
|
}
|
|
};
|
|
|
|
$http(promoteBatch).then(function (response) {
|
|
if (response.data.status == 200) {
|
|
swal('Saved Sucessfully','','success')
|
|
$state.go($state.current, {}, {reload: true});
|
|
} else {
|
|
swal('Someting Went Wrong','Try Later','error')
|
|
$state.go($state.current, {}, {reload: true});}
|
|
},function(error){
|
|
swal('Someting Went Wrong','Try Later','error')
|
|
$state.go($state.current, {}, {reload: true});
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}]);
|
|
|
|
|
|
app.filter('nxtSemFormat', function() {
|
|
return function(x) {
|
|
// console.log('FIRST'+x);
|
|
// console.log('FIRST'+x.length);
|
|
x = x.replace(/ +/g, "");
|
|
x = x.toUpperCase();
|
|
var txt = "";
|
|
var n = x.lastIndexOf("SEM");
|
|
// console.log('FIRST'+n);
|
|
if(n >= 0)
|
|
{
|
|
var num = x.substr(-1);
|
|
num = parseInt(num)+1;
|
|
txt = 'SEM'+num;
|
|
}
|
|
else
|
|
{
|
|
n = x.lastIndexOf("YEAR");
|
|
if(n >= 0)
|
|
{
|
|
var num = x.substr(-1);
|
|
num = parseInt(num)+1;
|
|
txt = 'YEAR'+num;
|
|
}
|
|
}
|
|
return txt;
|
|
};
|
|
}); |