'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":"" }; /* * updateModel default value * */ $scope.updateModel = { "feesType": "", "sessionName": "", "STF_WR": "", "others": "", "waiver": "", "total": "", "date": "", "billNo": "", "billAmount": "", "paymentOn": "", "internalComments":"", "studComments":"", "statusCode":"" }; /* * 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 } }; $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.getStudentFeesStructure(p.ID,p.CourseID,p.StudentID); $scope.editId=p.ID; } /* * update total fees amount after change value * created by kms * */ $scope.changeTotalFees = function (model,type) { if(type=='0'){ if(model.feesType.PendingFees=='' || model.feesType.PendingFees==undefined){ $scope.courseAmt=0; } else{ $scope.courseAmt=model.feesType.PendingFees; } if(model.feesType.STFOrWR=='' || model.feesType.STFOrWR==undefined || model.feesType.STFOrWR=='0'){ $scope.updateModel.STF_WR=""; $scope.STFWRAmt=0; } else{ $scope.STFWRAmt=model.feesType.STFOrWR; $scope.updateModel.STF_WR=model.feesType.STFOrWR; } if(model.feesType.Others=='' || model.feesType.Others==undefined || model.feesType.Others=='0'){ $scope.otherAmt=0; $scope.updateModel.others=""; } else{ $scope.otherAmt=model.feesType.Others; $scope.updateModel.others=model.feesType.Others; } if(model.feesType.Waiver=='' || model.feesType.Waiver==undefined || model.feesType.Waiver=='0'){ $scope.waiverAmt=0; $scope.updateModel.waiver=""; } else{ $scope.updateModel.waiver=model.feesType.Waiver; } } else{ if(model.feesType.PendingFees=='' || model.feesType.PendingFees==undefined){ $scope.courseAmt=0; } else{ $scope.courseAmt=model.feesType.PendingFees; } if(model.STF_WR=='' || model.STF_WR==undefined){ $scope.STFWRAmt=0; } else{ $scope.STFWRAmt=model.STF_WR; } if(model.others=='' || model.others==undefined){ $scope.otherAmt=0; } else{ $scope.otherAmt=model.others; } if(model.waiver=='' || model.waiver==undefined){ $scope.waiverAmt=0; } else{ $scope.waiverAmt=model.waiver; } } $scope.updateModel.total = (parseFloat($scope.courseAmt)+parseFloat($scope.STFWRAmt)+parseFloat($scope.otherAmt))-parseFloat($scope.waiverAmt); $scope.updateModel.billAmount = (parseFloat($scope.courseAmt)+parseFloat($scope.STFWRAmt)+parseFloat($scope.otherAmt))-parseFloat($scope.waiverAmt); } /* * 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.PendingFees, feesID: updateModel.feesType.ID, STFWR:updateModel.STF_WR, waiver: updateModel.waiver, other: updateModel.others, session: updateModel.sessionName, 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, } }; $http(updateFees).then(function (response) { if (response.data.status==200 && response.data.paidStatus) { $scope.ldloading[loading.replace('-', '_')] = false; swal("Success!", response.data.message, "success"); $scope.getStudentFeesStructure(myModel.ID,myModel.CourseID,myModel.StudentID); $scope.updateModel = { "feesType": "", "sessionName": "", "STF_WR": "", "others": "", "waiver": "", "total": "", "date": "", "billNo": "", "billAmount": "", "paymentOn": "", "internalComments":"", "studComments":"", "statusCode":"" }; } else { $scope.ldloading[loading.replace('-', '_')] = false; swal("Failed!", response.data.message, "error"); $scope.getStudentFeesStructure(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.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; } else { $scope.studentFeesInfo=""; $scope.existStudentFeesDetails=""; $scope.getFeesUpdateStatus=""; } }); } $scope.cancel = function () { $scope.editId=-1; $scope.studentFeesInfo=""; $scope.existStudentFeesDetails=""; $scope.getFeesUpdateStatus=""; } }]); /*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: 'ModalInstanceCtrl', // 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('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'); }; //show hide function for pdf design $scope.billNo=""; $scope.sessionName=""; $scope.paymentType=""; $scope.billDate=""; $scope.amountInWords = ""; $scope.billAmount = ""; $scope.ShowHide = function (pdfValue) { $scope.showButton = true; $scope.billNo = pdfValue.BillNO; $scope.sessionName=pdfValue.SessionID; $scope.paymentType=pdfValue.ModeOfPayment; $scope.billDate=pdfValue.BillDate; $scope.amountInWords = WordsService.convertNumberToWords(pdfValue.BillAmount); $scope.billAmount = pdfValue.BillAmount; } $scope.mouseLeave = function(){ $scope.showButton = false; $scope.billNo=""; $scope.sessionName=""; $scope.paymentType=""; $scope.billDate=""; $scope.amountInWords = ""; $scope.billAmount = ""; } }]); app.directive('visible', function() { return { restrict: 'A', link: function(scope, element, attributes) { scope.$watch(attributes.visible, function(value){ element.css('visibility', value ? 'visible' : 'hidden'); }); } }; })