'use strict'; /** * daybook details capturing * */ app.controller('daybookapprovalCtrl', ["$scope", "$rootScope", "toaster", "$filter", "ngTableParams", "API_POINTS", "$localStorage", "$http", "$state", 'ipCookie', '$window', function ($scope, $rootScope, toaster, $filter, ngTableParams, apiPoint, $localStorage, $http, $state, ipCookie, $window) { // get local client details var localDetail = JSON.parse(localStorage.getItem('localObj')); var localDetails = ipCookie('cookiechk'); $scope.localTypeViewAdmin = false; $scope.localTypeViewSuperAdmin = false; $scope.disableStatusUpdateButton = false; $scope.searchData = { "date": "", "dateTo": "" } // load functionality when page get loaded $scope.init = function () { const LOCALTYPE = localDetail.localType; if (LOCALTYPE === 'R002') { // getFinanceModuleAccess(); // // if(getFinanceModuleAccess()){ $scope.dayBookApprovalAccess = localDetail.is_DayBookApproval_Access; $scope.showTheRefValue = undefined; $scope.localTypeViewAdmin = true; $scope.currentDate = new Date(); var d = new Date(); $scope.oneMonthBefore = d.setMonth(d.getMonth()-1); var formate = "dd-MM-yyyy"; $scope.searchData.date = $filter('date')(new Date($scope.oneMonthBefore), formate); $scope.searchData.dateTo = $filter('date')(new Date($scope.currentDate), formate); $scope.getIncomeExpenseType_Status(); $scope.getDayBookList(); // } } else { ipCookie.remove('cookiechk'); $window.localStorage.clear(); $state.go('login.signin'); } } $scope.dayBookApprovalAccess = ''; // Finance module access control function getFinanceModuleAccess() { var getFinacnceModuleAcccessCtrl = { method: 'POST', url: apiPoint.url + 'empDayBookModuleAccessChk/', headers: { 'Content-Type': 'application/json' }, data: { localReqDetails: localDetails } }; $http(getFinacnceModuleAcccessCtrl).then(function (response) { if (response.data.dayBkAccessChkStatus) { $scope.dayBookApprovalAccess = response.data.dayBkAccessChk_Value; $scope.showTheRefValue = undefined; $scope.localTypeViewAdmin = true; $scope.currentDate = new Date(); var formate = "dd-MM-yyyy"; $scope.searchData.date = $filter('date')(new Date($scope.currentDate), formate); $scope.searchData.dateTo = $filter('date')(new Date($scope.currentDate), formate); $scope.getIncomeExpenseType_Status(); $scope.getDayBookList(); return true; } else { return true; } }); } // change from date, update and call search functionality $scope.changeDate = function () { if($scope.searchData.date !== undefined) { var formate = "dd-MM-yyyy"; $scope.searchData.date = $filter('date')(new Date($scope.searchData.date), formate); $scope.getDayBookList(); } else { $scope.searchData.date = ''; $scope.getDayBookList(); } } // change to date, update and call search functionality $scope.changeToDate = function () { if($scope.searchData.dateTo !== undefined) { var formate = "dd-MM-yyyy"; $scope.searchData.dateTo = $filter('date')(new Date($scope.searchData.dateTo), formate); $scope.getDayBookList(); } else { $scope.searchData.dateTo = ''; $scope.getDayBookList(); } } // sorting function for table params $scope.sort = function (keyname) { // alert(); $scope.sortKey = keyname; //set the sortKey to the param passed $scope.reverse = !$scope.reverse; //if true make it false and vice versa } // income expense type status list $scope.getIncomeExpenseType_Status = function () { var getIncomeExpenseType = { method: 'POST', url: apiPoint.url + 'getIncomeExpenseTypeState/', headers: { 'Content-Type': 'application/json' }, data: { localReqDetails: localDetails } }; $http(getIncomeExpenseType).then(function (response) { if (response.data.typeNameStatus) { $scope.incomeExpenseName = response.data.typeList; $scope.incomeExpenseType = response.data.typeNameList; } else { } }); } $scope.loadingsearch = false; $scope.noRecordFound = true; $scope.noRecordFoundSearch = false; $scope.dataLengthIncome = 0; $scope.dataLengthExpense = 0; // day book entry list $scope.getDayBookList = function () { $scope.loadingsearch = true; $scope.noRecordFoundSearch = false; var getDatBookListDetails = { method: 'POST', url: apiPoint.url + 'getDayBookApprovalDetails/', headers: { 'Content-Type': 'application/json' }, data: { data: $scope.searchData, localReqDetails: localDetails, } }; $http(getDatBookListDetails).then(function (response) { if (response.data.dayBookListStatus) { $scope.loadingsearch = false; // $scope.data = response.data.dayBookListDetails; // $scope.datas = response.data.dayBookListDetails; // const filterAddSelect = $scope.datas.filter(val => { // val['Selected'] = false; // return val; // }); $scope.searchResultDetails = response.data.dayBookListDetails; $scope.searchResultDetailsCopy = response.data.dayBookListDetails; } else { $scope.loadingsearch = false; } }); } // Select one row in a table once $scope.setOneSelect = function (value) { angular.forEach($scope.searchResultDetails, function (item) { item.Selected = false; }); value.Selected = true; $scope.OpenWindowStatus = true; $scope.openUpdateWind(); } $scope.unSelect = function () { // alert(value.Selected); angular.forEach($scope.searchResultDetails, function (item) { item.Selected = false; }); $scope.openUpdateWind(); } $scope.myStatusModel = { 'staus': '', 'description': '', } // End: select all or individual functionality $scope.OpenWindowStatus = false; // open popup window when checkbox get selected / close popup window uncheck the selected items $scope.openUpdateWind = function () { var ItemsSelected = $scope.searchResultDetails.filter(function (item) { if (item.Selected === true) { return true; } }); if (ItemsSelected.length) { $scope.myStatusModel = { 'staus': '', 'description': '', } $scope.OpenWindowStatus = true; } else { $scope.OpenWindowStatus = false; } } $scope.myStatusModel = { 'staus': '', 'description': '', 'ID':'' } $scope.editId = ''; $scope.updateStatus = function(p) { $scope.editId = p.ORDER_ID; $scope.myStatusModel.ID = p.ID; } $scope.updateStatusClose = function() { $scope.editId = ''; $scope.myStatusModel = { 'staus': '', 'description': '', 'ID':'' } } // update the status details $scope.statusUpdate = { submit: function (form, myStatusModel) { 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(); } else { var selectedItems = []; var ItemsSelected = $scope.searchResultDetails.filter(function (item) { if (item.Selected === true && item.Status === 'Pending' ) { let itemGetID = new getUpdateDetails(item.ID); selectedItems.push(itemGetID); return true; } }); function getUpdateDetails(id) { this.dabookListId = id; this.ListCodeStatus = $scope.myStatusModel.staus; this.comments = $scope.myStatusModel.description; } if(selectedItems.length > 0) { $scope.disableStatusUpdateButton = true; var updateStudyMaterial = { method: 'POST', url: apiPoint.url + 'updateDayBookStatusAdmin/', headers: { 'Content-Type': 'application/json' }, data: { data: selectedItems, requestDetails: localDetails } }; $http(updateStudyMaterial).then(function (response) { if (response.data.addStatus) { swal(" ", "Updated successfully,", "success"); $scope.getDayBookList(); $scope.disableStatusUpdateButton = false; $scope.updateStatusClose(); } else { swal(" ", response.data.message, "error"); $scope.disableStatusUpdateButton = false; } }); } else { swal(" ", "Item not Selected", "warning"); } } }, reset: function (form) { form.$setPristine(true); $scope.myStatusModel = { 'staus': '', 'description': '', } } } $scope.showTheResType = function (type) { // alert(type); if (type == undefined) { $scope.searchResultDetails = $scope.searchResultDetailsCopy; } else { $scope.searchResultDetails = $scope.searchResultDetailsCopy.filter(val => { return val.Name == type ? 1 : 0; }) } // const filterAddSelect = $scope.searchResultDetails.filter(val => { // }); } $scope.statusList = [{ "status_id": 'TS001', "name": "Pending", }, { "status_id": 'TS002', "name": "Approved", }, { "status_id": 'TS003', "name": "Rejected", }]; }]);