'use strict'; /*** controller***/ app.controller('report_expenseCtrl', ["$scope", "API_POINTS", "$http", "SweetAlert", "$state", 'md5', 'ipCookie', '$window',"dateListDescService", function ($scope, apiPoint, $http, SweetAlert, $state, md5, ipCookie, $window, dateListDescService) { // DataTables configurable options $scope.filters = { "from_date": "", "to_date": "", }; var localDetail = JSON.parse(localStorage.getItem('localObj')); const LOCALTYPE = localDetail.localType; //console.log(LOCALTYPE) if (localDetail != null && (LOCALTYPE == 'R003' || LOCALTYPE == 'R004' )) { }else { if((localDetail != null) && (LOCALTYPE !='R001')) { $state.go('app.dashboard'); } else { //ipCookie.remove('cookiechk'); window.localStorage.clear(); $state.go('login.signin'); } } $scope.filters = function () { var filterlist = { method: 'POST', url: apiPoint.url + 'report_filters/', headers: { 'Content-Type': 'application/json' }, data: { branch : JSON.parse(localStorage.getItem('localObj')).localBranchID } }; $http(filterlist).then(function (response) { if (response.data) { $scope.batch=[]; $scope.batchlist = response.data.batch; $scope.university = response.data.university; //Desc order Batchlist angular.forEach($scope.batchlist,function (values,key) { var parts = values.BatchDate.split("-"); $scope.batch.push({ "batchcode":values.batchcode, "batch":values.batch + '('+ values.batchcode + ')', "BatchDate":values.BatchDate, "givenDateObject":new Date(parts[2], parts[1] - 1, parts[0]) }) }); // call service for make a list in desc order based on date $scope.batch=dateListDescService.getOrderByList($scope.batch); //console.log($scope.branch); } else { } }); } $scope.show = false; $scope.onSubmit = function (form) { var firstError = null; if (form.$invalid) { var field = null, firstError = null; $scope.show = true; for (field in form) { if (field[0] != '$') { if (firstError === null && !form[field].$valid) { firstError = form[field].$addDate; firstError = form[field].$toDate; } if (form[field].$pristine) { form[field].$dirty = true; } } } angular.element('.ng-invalid[toDate=' + firstError + ']').focus(); }else { //alert($scope.batch.name); $scope.expense_data = ''; $scope.message = ''; var response_data = { method: 'POST', url: apiPoint.url + 'report_expense/', headers: { 'Content-Type': 'application/json' }, data: { branch: JSON.parse(localStorage.getItem('localObj')).localBranchID, from : $scope.filters.from_date, to : $scope.filters.to_date } }; $http(response_data).then(function (response) { if (response.data.expenseList == true) { $scope.expense_data = response.data.expense_data; for(var i=0;i<$scope.expense_data.length;i++) $scope.expense_data[i].SL_NO = i+1; } else { $scope.message = response.data.message; } }); } } var mystyle = { sheetid: 'EXPENSE REPORT', headers: true, caption: { title:'EXPENSE REPORT', width: '300px', style:'font-size:50px;' }, // style:'background:#00FF00', column: { style:'font-size:10px' }, }; $scope.exportData = function () { alasql('SELECT CAST(SL_NO AS NUMBER) as SLNO,Expense_name as ExpenseName,CAST(Amount as NUMBER) as Amount INTO XLS("Expense_report.xls",?) FROM ?',[mystyle,$scope.expense_data]); }; }]);