'use strict'; /** * controllers for ng-table * Simple table with sorting and filtering on AngularJS */ app.controller('feesStatusCtrl', ["$scope","$rootScope","toaster", "$filter", "ngTableParams", "API_POINTS", "$localStorage", "$http", "$state", function ($scope,$rootScope,toaster, $filter, ngTableParams, apiPoint, $localStorage, $http, $state) { $scope.myModel = { "studentName": "", "mobileNumber": "", "universityName":"", "courseName":"" }; $rootScope.userType = JSON.parse(localStorage.getItem('localObj')).localType; /* * updateModel default value * */ $scope.updateModel = { "feesType": "", "date": "", "billNo": "", "billAmount": "", "paymentOn": "", "internalComments":"", "studComments":"", "statusCode":"" }; /* * set model * */ $scope.setModel = { "feesType": "", }; /* * get payment options * */ $scope.paymentOptions = [ { "paymentOn":"CASH" }, { "paymentOn":"CHEQUE" }, { "paymentOn":"NEFT" }, { "paymentOn":"CASH DEPOSIT" } ]; // 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 getUniv = { method: 'POST', url: apiPoint.url + 'getUniversityCourseForFees/', headers: { 'Content-Type': 'application/json' }, data: { requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID } }; $http(getUniv).then(function (response) { if (response.data.status==200 && response.data.universityStatus) { $scope.university=response.data.univerSityDetails; } else { $scope.university=""; } }); } /* * get student details * created by kms * */ $scope.studentInfo=""; $scope.getStudentDetails = function (form,myModel) { if(myModel.universityName == null || myModel.universityName == '' || myModel.universityName == undefined){ $scope.univId = ""; } else{ $scope.univId = myModel.universityName.universityID; } 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 { var getStudent = { method: 'POST', url: apiPoint.url + 'getStudentListFees/', headers: { 'Content-Type': 'application/json' }, data: { studentName: myModel.studentName, mobileNumber: myModel.mobileNumber, university: $scope.univId, course:myModel.courseName, requestedtBy: JSON.parse(localStorage.getItem('localObj')).localUserID, branchId: JSON.parse(localStorage.getItem('localObj')).localBranchID, requestedDept: JSON.parse(localStorage.getItem('localObj')).localType, } }; $http(getStudent).then(function (response) { if (response.data.status==200 && response.data.studentStatus) { $scope.studentInfo=response.data.details; } else { $scope.studentInfo=""; } }); } } /* * get update fees details for student * created by kms * */ $scope.editId=-1; $scope.updateFees = function (p) { $scope.viewId=-1 $scope.getStudentFeesStructure(p.ID,p.CourseID,p.StudentID); $scope.editId=p.ID; } /* * set fees for student * */ $scope.viewId=-1; $scope.setFees = function (p) { $scope.editId=-1; $scope.getStudentSetFees(p.ID,p.CourseID,p.StudentID); $scope.viewId=p.ID; } /* * update total fees amount after change value * created by kms * */ $scope.changeTotalFees = function (model) { $scope.updateModel.billAmount = model.BalanceAmount; } /* * save fees details for student * created by kms * */ $scope.saveFees = function (myModel, form,updateModel, loading) { if(isNaN(updateModel.date)){ $scope.billDate = updateModel.date; } else{ $scope.getdate=new Date(updateModel.date).toDateString(); $scope.billDate = $filter('date')(new Date($scope.getdate), 'dd-MM-yyyy'); } 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 updateFees = { method: 'POST', url: apiPoint.url + 'updateFeesDetails/', headers: { 'Content-Type': 'application/json' }, data: { studID: myModel.StudentID, courseID:myModel.CourseID, courseAmount:updateModel.feesType.ActualFees, feesID: updateModel.feesType.FeesID, billNO: updateModel.billNo, billDate: $scope.billDate, billAmount:updateModel.billAmount, modeOfPayment: updateModel.paymentOn.paymentOn, commentsForStudent: updateModel.studComments, internalComments: updateModel.internalComments, createdBy: JSON.parse(localStorage.getItem('localObj')).localUserID, mobileNumber: myModel.MobileNumber, studentName: myModel.Firstname, university: myModel.UniversityName, course: myModel.CourseName, //statusCode: updateModel.statusCode, requestedBranch : JSON.parse(localStorage.getItem('localObj')).localBranchID } }; $http(updateFees).then(function (response) { if (response.data.status==200 && response.data.paidStatus) { $scope.ldloading[loading.replace('-', '_')] = false; swal("Success!", "Updated successfully.", "success"); /*$scope.updateModel = { "feesType": "", "date": "", "billNo": "", "billAmount": "", "paymentOn": "", "internalComments":"", "studComments":"", "statusCode":"" };*/ form.$setPristine(true); $scope.getStudentFeesStructure(myModel.ID,myModel.CourseID,myModel.StudentID); } else { $scope.ldloading[loading.replace('-', '_')] = false; swal("Failed!", response.data.message, "error"); //$scope.getStudentFeesStructure(myModel.ID,myModel.CourseID,myModel.StudentID); } }); } }; /* * set fees for student * */ $scope.submitFeesForStudent = function (myModel, form,updateModel, loading,installment) { 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 { if(isNaN(installment.date)){ $scope.pushDueDate1= $rootScope.lastInstallemtDate; } else{ $scope.convertGetDate1=new Date(installment.date).toDateString(); $scope.pushDueDate1 = $filter('date')(new Date($scope.convertGetDate1), 'dd-MM-yyyy'); } if(installment.ID !='' && installment.ID !==null && installment.ID !=undefined){ $rootScope.updateMoreItems.push({ ID: installment.ID, Name: installment.name, Amount: installment.amount, DueDate: $scope.pushDueDate1 }); } else{ $rootScope.updateMoreItems.push({ ID: "", Name: installment.name, Amount: installment.amount, DueDate: $scope.pushDueDate1 }); } angular.forEach($rootScope.updateMoreItems, function (value, key) { if(isNaN(value.DueDate)){ $scope.correctDate=''; } else{ $scope.convertGetDate2=new Date(value.DueDate).toDateString(); $scope.pushDueDate2 = $filter('date')(new Date($scope.convertGetDate2), 'dd-MM-yyyy'); $rootScope.updateMoreItems[key].DueDate=$scope.pushDueDate2; } }); $scope.ldloading5 = {}; $scope.ldloading5[loading.replace('-', '_')] = true; var updateFees = { method: 'POST', url: apiPoint.url + 'setFeesForStudent/', headers: { 'Content-Type': 'application/json' }, data: { studID: myModel.StudentID, courseID:myModel.CourseID, courseAmount:updateModel.ActualFees, feesID: updateModel.ID, STFWR:updateModel.STFOrWR, waiver: updateModel.Waiver, other: updateModel.Others, session: updateModel.SessionName, rollNo: updateModel.RollNo, createdBy: JSON.parse(localStorage.getItem('localObj')).localUserID, installmentItems:$rootScope.updateMoreItems } }; $http(updateFees).then(function (response) { if (response.data.status==200 && response.data.setStatus) { $scope.ldloading5[loading.replace('-', '_')] = false; swal("Success!", "Fees set successfully.", "success"); $scope.getStudentSetFees(myModel.ID,myModel.CourseID,myModel.StudentID); /*$scope.setModel = { "feesType": "", };*/ $scope.myModelInstallemt.ID=""; $scope.myModelInstallemt.name=""; $scope.myModelInstallemt.amount=""; $scope.myModelInstallemt.date=""; $rootScope.updateMoreItems=[]; $scope.setTotalAmount=''; form.$setPristine(true); } else { $scope.ldloading5[loading.replace('-', '_')] = false; swal("Failed!", response.data.message, "error"); $rootScope.updateMoreItems.splice($scope.updateMoreItems.length-1); // $scope.getStudentSetFees(myModel.ID,myModel.CourseID,myModel.StudentID); } }); } }; /* * Global method for get student fees structure * created by kms * */ $scope.studentFeesInfo=""; $scope.getStudentFeesStructure = function(ID,courseID,studeID){ $scope.updateModel = { "feesType": "", }; $scope.studentFeesInfo=""; $scope.existStudentFeesDetails=""; $scope.getFeesUpdateStatus=""; var getFees = { method: 'POST', url: apiPoint.url + 'getStudentFeesStructure/', headers: { 'Content-Type': 'application/json' }, data: { ID:ID, courseID: courseID, studentID: studeID, requestedtBy: JSON.parse(localStorage.getItem('localObj')).localUserID } }; $http(getFees).then(function (response) { if (response.data.status==200 && response.data.feesStatus) { $scope.studentFeesInfo=response.data.feesDetails; $scope.existStudentFeesDetails = response.data.getExistStudentFeesDetails; $scope.getFeesUpdateStatus = response.data.getFeesUpdateStatus; $scope.updateModel = { "feesType": $scope.studentFeesInfo[0], }; } else { $scope.studentFeesInfo=""; $scope.existStudentFeesDetails=""; $scope.getFeesUpdateStatus=""; swal("Warning!", response.data.message, "warning"); $scope.editId=-1; } }); } /* * get student set fees details * */ $scope.feesStructureInfo=""; $scope.getStudentSetFees = function (ID,courseID,studeID) { $scope.feesStructureInfo=""; $scope.myModelInstallemt.ID=""; $scope.myModelInstallemt.name=""; $scope.myModelInstallemt.amount=""; $scope.myModelInstallemt.date=""; $rootScope.lastInstallemtDate=""; $rootScope.updateMoreItems=[]; var setFees = { method: 'POST', url: apiPoint.url + 'getStudentFeesAssign/', headers: { 'Content-Type': 'application/json' }, data: { ID:ID, courseID: courseID, studentID: studeID, requestedtBy: JSON.parse(localStorage.getItem('localObj')).localUserID } }; $http(setFees).then(function (response) { if (response.data.status==200 && response.data.feesStatus) { $scope.feesStructureInfo=response.data.feesDetails; $scope.setModel = { "feesType": $scope.feesStructureInfo[0], }; $scope.setTotalAmount=$scope.feesStructureInfo[0].PayableFees; $rootScope.updateMoreItems=[]; if($scope.feesStructureInfo[0].InstallmentDetails != ''){ $scope.myModelInstallemt.ID=$scope.feesStructureInfo[0].InstallmentDetails[$scope.feesStructureInfo[0].InstallmentDetails.length-1].ID; $scope.myModelInstallemt.name=$scope.feesStructureInfo[0].InstallmentDetails[$scope.feesStructureInfo[0].InstallmentDetails.length-1].Name; $scope.myModelInstallemt.amount=$scope.feesStructureInfo[0].InstallmentDetails[$scope.feesStructureInfo[0].InstallmentDetails.length-1].Amount; $scope.myModelInstallemt.date=$scope.feesStructureInfo[0].InstallmentDetails[$scope.feesStructureInfo[0].InstallmentDetails.length-1].DueDate; $rootScope.lastInstallemtDate = $scope.myModelInstallemt.date; for(var i=0; i < $scope.feesStructureInfo[0].InstallmentDetails.length-1; i++){ $rootScope.updateMoreItems.push($scope.feesStructureInfo[0].InstallmentDetails[i]); } } } else { $scope.feesStructureInfo=""; $scope.setModel = { "feesType": "", }; } }); } $scope.cancel = function () { $scope.editId=-1; $scope.studentFeesInfo=""; $scope.existStudentFeesDetails=""; $scope.getFeesUpdateStatus=""; $scope.viewId=-1; } /* * get add more installment array * created by kms * */ $scope.myModelInstallemt = { "ID":"", "amount":"", "name":"", "date":"", }; $rootScope.updateMoreItems=[]; $rootScope.clickMoreItems = function (model,form,setModel) { $scope.convertGetDate=''; 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 { if(isNaN(model.date)){ $scope.pushDueDate= $rootScope.lastInstallemtDate; } else{ $scope.convertGetDate=new Date(model.date).toDateString(); $scope.pushDueDate = $filter('date')(new Date($scope.convertGetDate), 'dd-MM-yyyy'); } if(model.ID !='' && model.ID !==null && model.ID !=undefined){ $rootScope.updateMoreItems.push({ ID:model.ID, Name: model.name, Amount: model.amount, DueDate: $scope.pushDueDate }); } else{ $rootScope.updateMoreItems.push({ ID:"", Name: model.name, Amount: model.amount, DueDate: $scope.pushDueDate }); } $scope.myModelInstallemt.ID=""; $scope.myModelInstallemt.name=""; $scope.myModelInstallemt.amount=""; $scope.myModelInstallemt.date=""; } } /* * change installment values * */ $scope.changeInstallemt = function (model,form) { $rootScope.updateMoreItems=[]; if(model.InstallmentDetails != ''){ $scope.myModelInstallemt.ID=model.InstallmentDetails[model.InstallmentDetails.length-1].ID; $scope.myModelInstallemt.name=model.InstallmentDetails[model.InstallmentDetails.length-1].Name; $scope.myModelInstallemt.amount=model.InstallmentDetails[model.InstallmentDetails.length-1].Amount; $scope.myModelInstallemt.date=model.InstallmentDetails[model.InstallmentDetails.length-1].DueDate; $rootScope.lastInstallemtDate = $scope.myModelInstallemt.date; for(var i=0; i < model.InstallmentDetails.length-1; i++){ $rootScope.updateMoreItems.push(model.InstallmentDetails[i]); } } else{ $scope.myModelInstallemt.ID=""; $scope.myModelInstallemt.name=""; $scope.myModelInstallemt.amount=""; $scope.myModelInstallemt.date=""; $rootScope.lastInstallemtDate=""; } $scope.setFeesTotalAmount(model); form.$setPristine(true); } $scope.setTotalAmount=''; /* * get set fees total amount * */ $scope.setFeesTotalAmount = function (values) { if(values.ActualFees=='' || values.ActualFees==null || values.ActualFees==undefined){ $scope.actFees=0; } else{ $scope.actFees=values.ActualFees; } if(values.Others=='' || values.Others==null || values.Others==undefined){ $scope.othersFees=0; } else{ $scope.othersFees=values.Others; } if(values.STFOrWR=='' || values.STFOrWR==null || values.STFOrWR==undefined){ $scope.stfFees=0; } else{ $scope.stfFees=values.STFOrWR; } if(values.Waiver=='' || values.Waiver==null || values.Waiver==undefined){ $scope.wiverFees=0; } else{ $scope.wiverFees=values.Waiver; } $scope.setTotalAmount= parseInt($scope.actFees) + parseInt($scope.stfFees) + parseInt($scope.othersFees) - parseInt($scope.wiverFees); } }]); /*modal controller * */ app.controller('ModalDemoCtrl', ["$scope", "$modal", "$log", function ($scope, $modal, $log) { //Tooltip for print button $scope.dynamicTooltip = 'Click to View Bill Details'; // $scope.items = ['item1', 'item2', 'item3']; $scope.FeesName="" ; $scope.open = function (values) { $scope.FeesName = values; var modalInstance = $modal.open({ templateUrl: 'myModalContent.html', controller: 'FeesModalInstanceCtrl', // size: size, resolve: { items: function () { return $scope.FeesName; } } }); modalInstance.result.then(function (selectedItem) { $scope.selected = selectedItem; }, function () { $log.info('Modal dismissed at: ' + new Date()); }); }; }]); // Please note that $modalInstance represents a modal window (instance) dependency. // It is not the same as the $modal service used above. app.controller('FeesModalInstanceCtrl', ["$scope", "$modalInstance", "items","WordsService", function ($scope, $modalInstance, items,WordsService) { $scope.items = items; $scope.selected = { item: $scope.items[0] }; $scope.ok = function () { $modalInstance.close($scope.selected.item); }; $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; //show hide function for pdf design $scope.billNo=""; $scope.sessionName=""; $scope.paymentType=""; $scope.billDate=""; $scope.amountInWords = ""; $scope.billAmount = ""; $scope.branchName = ""; $scope.ShowHide = function (pdfValue) { $scope.showButton = true; $scope.billNo = pdfValue.BillNO; $scope.paymentType=pdfValue.ModeOfPayment; $scope.billDate=pdfValue.BillDate; $scope.amountInWords = WordsService.convertNumberToWords(pdfValue.BillAmount); $scope.billAmount = pdfValue.BillAmount; $scope.branchName = pdfValue.BranchName; } $scope.mouseLeave = function(){ $scope.showButton = false; $scope.billNo=""; $scope.sessionName=""; $scope.paymentType=""; $scope.billDate=""; $scope.amountInWords = ""; $scope.billAmount = ""; $scope.branchName = ""; } }]); app.directive('visible', function() { return { restrict: 'A', link: function(scope, element, attributes) { scope.$watch(attributes.visible, function(value){ element.css('visibility', value ? 'visible' : 'hidden'); }); } }; }); /*modal controller * */ app.controller('studentModalDemoCtrl', ["$scope", "$modal", "$log", "API_POINTS", "$http", function ($scope, $modal, $log,apiPoint,$http) { //Tooltip for print button $scope.dynamicTooltip = 'Student View'; // $scope.items = ['item1', 'item2', 'item3']; $scope.open = function (studentDetails) { // get student view details var getcourse = { method: 'POST', url: apiPoint.url + 'getStudentBasicInfo/', headers: { 'Content-Type': 'application/json' }, data: { requestedBy :studentDetails.MobileNumber, requestedFrom: 3 } }; $http(getcourse).then(function (response) { if (response.data.status == 200 && response.data.studentStatus== true) { $scope.courseEditLoading = false; // $scope.studentDetails = response.data.studentDetails; $scope.studentDetails = response.data; // $scope.courseDetails = response.data.courseDetails; var modalInstance = $modal.open({ templateUrl: 'assets/views/student/studentDetailsModal.html', controller: 'ModalInstanceCtrl', // size: size, resolve: { items: function () { return $scope.studentDetails; } } }); modalInstance.result.then(function (selectedItem) { $scope.selected = selectedItem; }, function () { $log.info('Modal dismissed at: ' + new Date()); }); } else { swal("Failed!", "This student is not registerd", "warning"); $scope.courseEditLoading = false; $scope.studentDetails = ""; $scope.courseDetails = ""; } }); }; $scope.open1 = function (values) { var modalInstance1 = $modal.open({ templateUrl: 'assets/views/student/studentPaymentModal.html', controller: 'ModalInstanceCtrl1', // size: size, resolve: { items1: function () { return values; } } }); modalInstance1.result.then(function (selectedItem) { $scope.selected = selectedItem; }, function () { $log.info('Modal dismissed at: ' + new Date()); }); }; }]); // Please note that $modalInstance represents a modal window (instance) dependency. // It is not the same as the $modal service used above. app.controller('ModalInstanceCtrl', ["$scope", "$modalInstance", "items","WordsService", function ($scope, $modalInstance, items,WordsService) { $scope.items = items; $scope.selected = { item: $scope.items[0] }; $scope.ok = function () { $modalInstance.close($scope.selected.item); }; $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; }]); app.controller('ModalInstanceCtrl1', ["$scope", "$modalInstance", "items1","WordsService", function ($scope, $modalInstance, items1,WordsService) { $scope.items1 = items1; $scope.ok = function () { $modalInstance.close($scope.selected.item); }; $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; }]); app.filter('unique', function() { return function(collection, primaryKey, secondaryKey) { //optional secondary key var output = [], keys = []; angular.forEach(collection, function(item) { var key; secondaryKey === undefined ? key = item[primaryKey] : key = item[primaryKey][secondaryKey]; if(keys.indexOf(key) === -1) { keys.push(key); output.push(item); } }); return output; }; });