389 lines
12 KiB
JavaScript
Executable File
389 lines
12 KiB
JavaScript
Executable File
'use strict';
|
|
/**
|
|
* controllers for ng-table
|
|
* Simple table with sorting and filtering on AngularJS
|
|
*/
|
|
|
|
app.controller('batchCtrl', ["$scope","$rootScope","toaster", "$filter", "ngTableParams", "API_POINTS", "$sessionStorage", "$http", "$state", "dateListDescService", function ($scope,$rootScope,toaster, $filter, ngTableParams, apiPoint, $sessionStorage, $http, $state, dateListDescService) {
|
|
$scope.myModel = {
|
|
"batchCode": "",
|
|
"batchName": "",
|
|
"universityName":"",
|
|
"switchsetting": true,
|
|
};
|
|
|
|
|
|
/*
|
|
* edit batch details
|
|
* created by subaram
|
|
* */
|
|
$scope.editId = -1;
|
|
$scope.editModel = {
|
|
"editDate": "",
|
|
"editBatchName": "",
|
|
|
|
};
|
|
$scope.setEditId = function (pid,p) {
|
|
$scope.editModel.editBatchName = p.BatchName;
|
|
$scope.editModel.editDate = p.BatchDate;
|
|
$scope.localUniversityDetails="";
|
|
$scope.localUniversityDetails = JSON.parse(sessionStorage.getItem('localUniversityDetails'));
|
|
|
|
|
|
$scope.editId = pid;
|
|
$scope.viewId = -1;
|
|
|
|
// get inactive university id
|
|
|
|
|
|
var result = $filter('filter')($scope.localUniversityDetails, {'UniversityID':p.UniversityID}) ;
|
|
|
|
if(result.length==0){
|
|
$scope.localUniversityDetails.push({
|
|
"UniversityID":p.UniversityID,
|
|
"UniversityName":p.UniversityName,
|
|
});
|
|
}
|
|
};
|
|
|
|
/*
|
|
* cancel edit div
|
|
* created by subaram
|
|
* */
|
|
$scope.cancel = function () {
|
|
$scope.init();
|
|
$scope.editId = -1;
|
|
|
|
};
|
|
|
|
// 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
|
|
}
|
|
/*
|
|
* Submit,upload file and extract details
|
|
* @params myModel
|
|
* created by Bala
|
|
* */
|
|
|
|
$scope.extractFileDetails="";
|
|
$scope.readUploadXlsxDetails = function (workbook) {
|
|
/* DO SOMETHING WITH workbook HERE */
|
|
for (var sheetName in workbook.Sheets) {
|
|
var jsonData = XLSX.utils.sheet_to_json(workbook.Sheets[sheetName]);
|
|
if(jsonData.length!=0){
|
|
$scope.extractFileDetails=jsonData;
|
|
}
|
|
|
|
}
|
|
$scope.error = function (e) {
|
|
/* DO SOMETHING WHEN ERROR IS THROWN */
|
|
//console.log(e);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
$scope.UploadFileData = function (details,uploadForDetails) {
|
|
var updateUniversityEnrolment = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'fileUploadDataDetails/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
localDetails: localDetail,
|
|
details: details,
|
|
batchcode: myModel.batchCode,
|
|
batcheName: myModel.batchName,
|
|
universityName: myModel.universityName,
|
|
universityID: angular.fromJson(uploadForDetails.university).UniversityID,
|
|
// universityName: angular.fromJson(uploadForDetails.university).UniversityName,
|
|
|
|
}
|
|
};
|
|
|
|
$http(updateUniversityEnrolment).then(function (response) {
|
|
if (response.data.status == true) {
|
|
swal("", "Updated Successfully", "success");
|
|
$state.go($state.current, {}, {reload: true});
|
|
} else {
|
|
swal("", "Failed", "error");
|
|
}
|
|
});
|
|
}
|
|
// end
|
|
/*
|
|
* Submit,update and reset batch details
|
|
* @params myModel
|
|
* created by Bala
|
|
* */
|
|
$scope.batchForm = {
|
|
|
|
submit: function (form, myModel,loading) {
|
|
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.ldloading1 = {};
|
|
|
|
$scope.ldloading1[loading.replace('-', '_')] = true;
|
|
|
|
|
|
var addBatch = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'addBatchDetails/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
batchcode: myModel.batchCode,
|
|
batcheName: myModel.batchName,
|
|
batcheDate: $filter('date')(new Date(myModel.date), 'dd-MM-yyyy'),
|
|
universityName: myModel.universityName,
|
|
status: myModel.switchsetting,
|
|
createdBy: JSON.parse(sessionStorage.getItem('localObj')).localUserID,
|
|
branchCode:JSON.parse(sessionStorage.getItem('localObj')).localBranchID
|
|
}
|
|
};
|
|
$http(addBatch).then(function (response) {
|
|
if (response.data.status==200 && response.data.batchStatus) {
|
|
$scope.ldloading1[loading.replace('-', '_')] = false;
|
|
swal("", "Batch added successfully.", "success");
|
|
$state.go($state.current, {}, {reload: true});
|
|
} else {
|
|
$scope.ldloading1[loading.replace('-', '_')] = false;
|
|
swal("", response.data.message, "error");
|
|
}
|
|
});
|
|
|
|
|
|
}
|
|
},
|
|
reset: function (form) {
|
|
|
|
$scope.myModel = {
|
|
"batchCode": "",
|
|
"batchName": "",
|
|
"universityName":"",
|
|
"switchsetting": true
|
|
};
|
|
form.$setPristine(true);
|
|
}
|
|
};
|
|
/*
|
|
* update the batch details
|
|
* created by subaram
|
|
* */
|
|
$scope.updateBatch = function (myModel, form, loading,editModel) {
|
|
|
|
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].$stop_name;
|
|
}
|
|
|
|
if (form[field].$pristine) {
|
|
form[field].$dirty = true;
|
|
}
|
|
}
|
|
}
|
|
angular.element('.ng-invalid[name=' + firstError + ']').focus();
|
|
} else {
|
|
$scope.ldloading = {};
|
|
|
|
$scope.ldloading[loading.replace('-', '_')] = true;
|
|
|
|
|
|
var update = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'updateBatchDetails/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
batchCode: myModel.BatchCode,
|
|
batchName: editModel.editBatchName,
|
|
batchDate: editModel.editDate,
|
|
status: myModel.IsActive,
|
|
createdBy: JSON.parse(sessionStorage.getItem('localObj')).localUserID,
|
|
branchCode:JSON.parse(sessionStorage.getItem('localObj')).localBranchID
|
|
}
|
|
};
|
|
$http(update).then(function (response) {
|
|
if (response.data.status==200 && response.data.batchStatus) {
|
|
$scope.ldloading[loading.replace('-', '_')] = false;
|
|
$scope.editId = -1;
|
|
$scope.init();
|
|
swal("", "Updated Successfully.", "success");
|
|
|
|
|
|
} else {
|
|
$scope.ldloading[loading.replace('-', '_')] = false;
|
|
swal("", response.data.message, "error");
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
|
|
/*
|
|
* change default batch options
|
|
* */
|
|
$scope.changeBtachDefault = function (details) {
|
|
if(details.IsDefault==true){
|
|
$scope.defaultBatch = false;
|
|
}
|
|
else{
|
|
$scope.defaultBatch = true;
|
|
}
|
|
var changeDefault = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'updateBatchDefault/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
batchCode: details.BatchCode,
|
|
IsDefault: $scope.defaultBatch,
|
|
universityID: details.UniversityID,
|
|
updatedBy: JSON.parse(sessionStorage.getItem('localObj')).localUserID,
|
|
branchCode:JSON.parse(sessionStorage.getItem('localObj')).localBranchID
|
|
}
|
|
};
|
|
$http(changeDefault).then(function (response) {
|
|
if (response.data.status==200 && response.data.batchStatus) {
|
|
$scope.init();
|
|
swal("", "Updated Successfully.", "success");
|
|
|
|
|
|
} else {
|
|
|
|
swal("", response.data.message, "error");
|
|
}
|
|
});
|
|
|
|
|
|
}
|
|
/*
|
|
*get Batch details when page loading called from view file
|
|
*
|
|
* created by Srk
|
|
* */
|
|
$scope.loader='';
|
|
|
|
$scope.emptyData='';
|
|
|
|
$rootScope.init = function () {
|
|
|
|
var logcheck = JSON.parse(sessionStorage.getItem('localObj'));
|
|
|
|
const LOCALTYPE = logcheck.localType;
|
|
if (logcheck != null && (LOCALTYPE == 'R003' || LOCALTYPE == 'R004' || LOCALTYPE == 'R002' || LOCALTYPE == 'R005')) {
|
|
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');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sessionStorage.setItem('localUniversityDetails', '');
|
|
|
|
var getBranch = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'getBatchDetails/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
requestedBy: JSON.parse(sessionStorage.getItem('localObj')).localUserID,
|
|
branchCode:JSON.parse(sessionStorage.getItem('localObj')).localBranchID
|
|
}
|
|
};
|
|
|
|
$http(getBranch).then(function (response) {
|
|
if (response.data.status==200 && response.data.batchStatus) {
|
|
|
|
$scope.emptyData=true;
|
|
$scope.loader=true;
|
|
$scope.data = response.data.details;
|
|
// call service for make list in desc order based on date
|
|
angular.forEach($scope.data,function (value,key) {
|
|
var parts = value.BatchDate.split("-");
|
|
value.givenDateObject=new Date(parts[2], parts[1] - 1, parts[0]);
|
|
|
|
});
|
|
// end service call
|
|
$scope.data=dateListDescService.getOrderByList($scope.data);
|
|
|
|
$scope.university=response.data.universityDetails;
|
|
|
|
} else {
|
|
$scope.emptyData=false;
|
|
$scope.loader=true;
|
|
$scope.university=response.data.universityDetails;
|
|
|
|
}
|
|
sessionStorage.setItem('localUniversityDetails', JSON.stringify($scope.university));
|
|
|
|
});
|
|
};
|
|
|
|
|
|
/*
|
|
* get date format
|
|
* created by kms
|
|
* */
|
|
$scope.getDateFormat = function (modelDate,type) {
|
|
if(type=='1'){
|
|
$scope.myModel.batchName=$filter('date')(new Date(modelDate), 'MMM-yyyy');
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$scope.editModel.editBatchName=$filter('date')(new Date(modelDate), 'MMM-yyyy');
|
|
$scope.editModel.editDate=$filter('date')(new Date(modelDate), 'dd-MM-yyyy');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}]);
|