apollodec/Apollo/assets/js/controllers/incomeCtrl.js
2019-02-15 18:02:42 +05:30

289 lines
9.2 KiB
JavaScript

'use strict';
/**
* controllers for ng-table
* Simple table with sorting and filtering on AngularJS
*/
// var helloApp = angular.module("helloApp", []);
app.controller("incomeCtrl", ["$scope", "toaster", "$filter", "API_POINTS", "$sessionStorage", "$http", "$state", 'ipCookie', function ($scope, toaster, $filter, apiPoint, $sessionStorage, $http, $state, ipCookie) {
$scope.myModel = {
"StatusName": "",
"switchsetting": true
};
// get local client details
var localDetail = JSON.parse(sessionStorage.getItem('localObj'));
var localDetails = ipCookie('cookiechk');
$scope.initHead = function() {
// alert();
const LOCALTYPE = localDetail.localType;
if (localDetail != null && (LOCALTYPE == 'R003' || LOCALTYPE == 'R004' || LOCALTYPE == 'R002' || LOCALTYPE == 'R005')) {
}else {
if(localDetail != null) {
$state.go('app.dashboard');
} else {
ipCookie.remove('cookiechk');
$window.sessionStorage.clear();
$state.go('login.signin');
}
}
}
/*
* edit status details
* created by Surendiran
* */
$scope.editId = -1;
$scope.setEditId = function (pid) {
$scope.editId = pid;
$scope.viewId = -1;
};
/*
* cancel edit div
* created by Surendiran
* */
$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
}
$scope.statusForm = {
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 addstatus = {
method: 'POST',
url: apiPoint.url + 'addAccountnameDetails/',
headers: {
'Content-Type': 'application/json'
},
data: {
statusName: myModel.StatusName,
status: myModel.switchsetting,
createdBy: JSON.parse(sessionStorage.getItem('localObj')).localUserID,
branch : localDetail.localBranchID
}
};
$http(addstatus).then(function (response) {
if (response.data.status == 200 && response.data.Status) {
$scope.ldloading1[loading.replace('-', '_')] = false;
$scope.init();
swal(" ", "Status 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 = angular.copy($scope.master);
form.$setPristine(true);
$scope.myModel = {
"StatusName": "",
"switchsetting": true
};
}
};
/*
*get status details when page loading called from view file
*
*
* created by Surendiran
* */
$scope.loader = '';
$scope.emptyData = '';
$scope.init = function () {
var logcheck = JSON.parse(sessionStorage.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.sessionStorage.clear();
$state.go('login.signin');
}
}
var getStatus = {
method: 'POST',
url: apiPoint.url + 'getAccounttypes/',
headers: {
'Content-Type': 'application/json'
},
data: {
requestBranch: localDetail.localBranchID,
requestedBy: JSON.parse(sessionStorage.getItem('localObj')).localUserID
}
};
$http(getStatus).then(function (response) {
if (response.data.status == 200 && response.data.Status) {
// console.log(response.data.details);
$scope.emptyData = true;
$scope.loader = true;
$scope.statusInfo = response.data.details;
//console.log($scope.statusInfo);
} else {
$scope.emptyData = false;
$scope.loader = true;
$scope.statusInfo = '';
}
});
// var getBranchList = {
// method: 'POST',
// url: apiPoint.url + 'getBranchListStatusUpdate/',
// headers: {
// 'Content-Type': 'application/json'
// },
// data: {
// requestedBy: JSON.parse(sessionStorage.getItem('localObj')).localUserID
// }
// };
// $http(getBranchList).then(function (response) {
// if (response.data.branchListStatus == true) {
// $scope.branchList = response.data.branch_list_details;
// } else {
// $scope.branchListMessage = response.data.message;
// }
// });
};
/*
* update the status details
* created by Surendiran
* */
$scope.updatestatus = function (myModel, form, 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].$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 + 'updateStatusDetails/',
headers: {
'Content-Type': 'application/json'
},
data: {
ListCode: myModel.ListCode,
ListName: myModel.ListName,
status: myModel.IsActive,
requestBranch: localDetail.localBranchID,
updatedBy: JSON.parse(sessionStorage.getItem('localObj')).localUserID
}
};
$http(update).then(function (response) {
if (response.data.Status) {
$scope.ldloading[loading.replace('-', '_')] = false;
swal("", "Updated Successfully", "success");
$scope.editId = -1;
$scope.init();
} else {
$scope.ldloading[loading.replace('-', '_')] = false;
$scope.init();
swal("", response.data.message, "error");
}
});
}
};
$scope.localBranchDetails = '';
$scope.selectBranch = function(branchCode) {
// alert(branchCode);
var getBranchStatusList = {
method: 'POST',
url: apiPoint.url + 'getBranchStatusList/',
headers: {
'Content-Type': 'application/json'
},
data: {
requestedBy: localDetail,
branchCode: branchCode
}
};
$http(getBranchStatusList).then(function (response) {
if (response.data.branchListStatus == true) {
$scope.branchList = response.data.branch_list_details;
} else {
$scope.branchListMessage = response.data.message;
}
});
}
}]);