236 lines
8.1 KiB
JavaScript
236 lines
8.1 KiB
JavaScript
'use strict';
|
|
/**
|
|
* controllers for ng-table
|
|
* Simple table with sorting and filtering on AngularJS
|
|
*/
|
|
app.controller('univFormPaymentCtrl', ["$scope","$rootScope","$filter", "ngTableParams", "API_POINTS", "$localStorage", "$http", "$state", "$modal", "$log", "SweetAlert", "$timeout", function ($scope,$rootScope, $filter, ngTableParams, apiPoint, $localStorage, $http, $state, $modal, SweetAlert, $log, $timeout) {
|
|
// ng-model object for payment search
|
|
$scope.paymentVerficationModel= {
|
|
'universitySearch':"",
|
|
};
|
|
// load when html page load
|
|
var localDetail = JSON.parse(localStorage.getItem('localObj'));
|
|
|
|
$scope.init = function () {
|
|
|
|
if (localDetail != null) {
|
|
if (localDetail.localType === 'R004') {
|
|
$scope.getPaymentUnivSearchData();
|
|
} else {
|
|
localStorage.removeItem('localObj');
|
|
$state.go('login.signin');
|
|
}
|
|
} else {
|
|
$state.go('login.signin');
|
|
}
|
|
}
|
|
/*
|
|
* get university details for search
|
|
* cretaed by kms
|
|
* */
|
|
$scope.universityPaymentSearchData=[];
|
|
$scope.getPaymentUnivSearchData = function () {
|
|
var paymentSearch = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'getUnivCourseFromFileDetails/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
data: localDetail
|
|
}
|
|
};
|
|
$http(paymentSearch).then(function (response) {
|
|
if (response.data.status) {
|
|
$scope.universityPaymentSearchData = response.data.details;
|
|
} else {
|
|
$scope.universityPaymentSearchData="";
|
|
}
|
|
});
|
|
}
|
|
/*
|
|
* add payment details
|
|
* created by kms
|
|
* */
|
|
$rootScope.addPaymentModel = {
|
|
'billNo':"",
|
|
'date':"",
|
|
'billAmount':"",
|
|
'receiptNo':"",
|
|
'comments':"",
|
|
'university':[]
|
|
};
|
|
$scope.addUniversityPaymentModal = function (values) {
|
|
$rootScope.addError="";
|
|
$rootScope.addPaymentModel.university=angular.fromJson(values.universitySearch);
|
|
$rootScope.paymentModal = $modal.open({
|
|
templateUrl: 'assets/views/student/addUniversityPaymentModal.html',
|
|
// controller: 'univFormPaymentCtrl',
|
|
// size: size,
|
|
resolve: {
|
|
items: function () {
|
|
return $scope.univPayDetails;
|
|
}
|
|
}
|
|
});
|
|
|
|
$rootScope.paymentModal.result.then(function (selectedItem) {
|
|
}, function () {
|
|
$rootScope.paymentModal.close();
|
|
$rootScope.addPaymentModel = {
|
|
'billNo':"",
|
|
'date':"",
|
|
'billAmount':"",
|
|
'receiptNo':"",
|
|
'comments':"",
|
|
'university':[]
|
|
};
|
|
});
|
|
};
|
|
/*
|
|
* add university payment details
|
|
* created by kms
|
|
* */
|
|
$rootScope.addError="";
|
|
$rootScope.addUnivPayment = function (form,addDetails) {
|
|
$rootScope.addError="";
|
|
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 getdate=new Date(addDetails.date).toDateString();
|
|
$scope.univPayData = {
|
|
"universityCode":addDetails.university.univCode,
|
|
"universityName":addDetails.university.univName,
|
|
"billNo":addDetails.billNo,
|
|
"billAmount":addDetails.billAmount,
|
|
"date":$filter('date')(new Date(getdate), 'yyyy-MM-dd'),
|
|
"receiptNo":addDetails.receiptNo,
|
|
"comments":addDetails.comments,
|
|
}
|
|
|
|
var submitPayment = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'addUniversityPaymentDetails/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
localDetails: localDetail,
|
|
details: $scope.univPayData,
|
|
}
|
|
};
|
|
$http(submitPayment).then(function (response) {
|
|
if (response.data.status==true) {
|
|
swal(" ", response.data.message, "success");
|
|
$rootScope.paymentModal.close();
|
|
$rootScope.addPaymentModel = {
|
|
'billNo':"",
|
|
'date':"",
|
|
'billAmount':"",
|
|
'receiptNo':"",
|
|
'comments':"",
|
|
'university':[]
|
|
};
|
|
$rootScope.getPaymentVerificationDetails($scope.paymentVerficationModel);
|
|
|
|
|
|
} else {
|
|
$rootScope.addError=response.data.message;
|
|
$timeout(function () {
|
|
$rootScope.addError="";
|
|
}, 4000);
|
|
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|
|
/*
|
|
* cancel add modal
|
|
* */
|
|
$rootScope.cancelAddPaymentModal=function () {
|
|
$rootScope.paymentModal.close();
|
|
$rootScope.addPaymentModel = {
|
|
'billNo':"",
|
|
'date':"",
|
|
'billAmount':"",
|
|
'receiptNo':"",
|
|
'comments':"",
|
|
'university':[]
|
|
};
|
|
$rootScope.addError="";
|
|
};
|
|
|
|
|
|
/*
|
|
* get payment details
|
|
* cretaed by kms
|
|
* */
|
|
$scope.paymentVerificationData="";
|
|
$scope.emptyList=true;
|
|
$scope.searchLoader = false;
|
|
$rootScope.getPaymentVerificationDetails = function (searchData) {
|
|
$scope.paymentVerificationData="";
|
|
$scope.emptyList=true;
|
|
$scope.searchLoader = true;
|
|
var paymentVerification = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'paymentVerficationDetails/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
localData: localDetail,
|
|
universityID: angular.fromJson(searchData.universitySearch).univCode,
|
|
universityName: angular.fromJson(searchData.universitySearch).univName,
|
|
}
|
|
};
|
|
$http(paymentVerification).then(function (response) {
|
|
if (response.data.status) {
|
|
$scope.searchLoader = false;
|
|
$scope.emptyList=false;
|
|
$scope.paymentVerificationData=response.data.details;
|
|
var tagMap = $scope.paymentVerificationData.reduce(function(map, tag,key) {
|
|
if(map.RunningBalance==undefined){
|
|
map['RunningBalance'] = parseInt(tag.CreditAmount)-parseInt(tag.DebitAmount);
|
|
tag['RunningBalance']=parseInt(tag.CreditAmount)-parseInt(tag.DebitAmount);;
|
|
}
|
|
else{
|
|
if(parseInt(tag.DebitAmount)<=0){
|
|
map['RunningBalance'] = parseInt(map.RunningBalance)+parseInt(tag.CreditAmount);
|
|
tag['RunningBalance']=parseInt(map.RunningBalance);
|
|
}
|
|
else{
|
|
map['RunningBalance'] = parseInt(map.RunningBalance)-parseInt(tag.DebitAmount);
|
|
tag['RunningBalance']=parseInt(map.RunningBalance);
|
|
}
|
|
|
|
}
|
|
return map;
|
|
}, {});
|
|
|
|
} else {
|
|
$scope.searchLoader = false;
|
|
$scope.emptyList=true;
|
|
$scope.paymentVerificationData=response.data.details;
|
|
}
|
|
});
|
|
};
|
|
|
|
}]); |