From 78173a5d713fcd1e8577a2317cebed849d852b4f Mon Sep 17 00:00:00 2001 From: gandhimathi Date: Thu, 4 Oct 2018 16:38:06 +0530 Subject: [PATCH] Expense report fixes --- .../js/controllers/report_expenseCtrl.js | 553 +++++++++--------- Apollo/assets/views/report_expense.html | 6 +- 2 files changed, 293 insertions(+), 266 deletions(-) diff --git a/Apollo/assets/js/controllers/report_expenseCtrl.js b/Apollo/assets/js/controllers/report_expenseCtrl.js index 5299bed3..a11f3190 100755 --- a/Apollo/assets/js/controllers/report_expenseCtrl.js +++ b/Apollo/assets/js/controllers/report_expenseCtrl.js @@ -1,26 +1,26 @@ 'use strict'; /*** controller***/ -app.controller('report_expenseCtrl', ["$scope", "API_POINTS", "$http", "SweetAlert", "$state", 'md5', 'ipCookie', '$window',"dateListDescService", +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": "", - }; - + }; + $scope.date = new 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')) { + 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'); @@ -37,45 +37,49 @@ app.controller('report_expenseCtrl', ["$scope", "API_POINTS", "$http", "SweetAle 'Content-Type': 'application/json' }, data: { - branch : JSON.parse(localStorage.getItem('localObj')).localBranchID - + branch: JSON.parse(localStorage.getItem('localObj')).localBranchID + } }; $http(filterlist).then(function (response) { if (response.data) { - $scope.batch=[]; + $scope.batch = []; $scope.batchlist = response.data.batch; $scope.university = response.data.university; //Desc order Batchlist - angular.forEach($scope.batchlist,function (values,key) { + 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]) + "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); + $scope.batch = dateListDescService.getOrderByList($scope.batch); //console.log($scope.branch); } else { } }); } - + $scope.expense_data = ''; + $scope.expense = ''; + $scope.totArray = ''; $scope.show = false; + $scope.Total = 0; + $scope.onSubmit = function (form) { - var firstError = null; + var firstError = null; if (form.$invalid) { var field = null, firstError = null; - $scope.show = true; + $scope.show = true; for (field in form) { if (field[0] != '$') { if (firstError === null && !form[field].$valid) { firstError = form[field].$addDate; - firstError = form[field].$toDate; + firstError = form[field].$toDate; } if (form[field].$pristine) { form[field].$dirty = true; @@ -83,262 +87,285 @@ app.controller('report_expenseCtrl', ["$scope", "API_POINTS", "$http", "SweetAle } } 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 + } else { + //alert($scope.batch.name); + + $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; + } + + }); + + + $scope.getTotal = function () { + var total = 0; + for (var i = 0; i < $scope.expense_data.length; i++) { + var item = $scope.expense_data[i]; + total += parseFloat(item.total); + + + } + $scope.Total = total; + $scope.totArray = { + + Expense_name:"Grand Total", + total: $scope.Total + } + + // console.log($scope.Total); + $scope.expense = $scope.expense_data.concat($scope.totArray); + // console.log($scope.expense_data); + // console.log($scope.totArray); + // console.log($scope.expense); + return total; + } + + } + - }; - - $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; - } - - }); - $scope.getTotal = function(){ - var total = 0; - for(var i = 0; i < $scope.expense_data.length; i++){ - var item = $scope.expense_data[i]; - total += parseFloat(item.total); - } - return total; } - } - - }; - + }; + var mystyle = { sheetid: 'EXPENSE REPORT', headers: true, caption: { - title:'EXPENSE REPORT', - width: '300px', - style:'font-size:50px;' + title: 'EXPENSE REPORT', + width: '300px', + style: 'font-size:50px;' }, // style:'background:#00FF00', column: { - style:'font-size:10px' + style: 'font-size:10px' }, - + + }; + $scope.exportData = function () { + alasql('SELECT CAST(SL_NO AS NUMBER) as SLNO,Expense_name as ExpenseName,CAST(January as NUMBER) as January,CAST(February as NUMBER) as February,CAST(March as NUMBER) as March,CAST(April as NUMBER) as April,CAST(May as NUMBER) as May,CAST(June as NUMBER) as June,CAST(July as NUMBER) as July,CAST(August as NUMBER) as August,CAST(September as NUMBER) as September,CAST(October as NUMBER) as October,CAST(November as NUMBER) as November,CAST(December as NUMBER) as December,CAST(total as NUMBER) as Amount INTO XLS("Expense_report.xls",?) FROM ?',[mystyle,$scope.expense]); }; - //pdf + var rows1 = 0; $scope.generatePFD = function (datas) { $scope.loadStaring = true; - - var o = {}; - var intDataSNo = 1; - var intDate = 0; - - for(var i = 0 ; i <= datas.length-1; ++i){ - var element = datas[i]; - //var element = datas[i-1]; - console.log('staff or trainee'); - var value = {}; - - value['SL_NO'] = element.ORDER_ID; - value['Expense_name'] = element.VoucherNumber; - value['January'] = element.PaidTo; - value['February'] = University; - value['March'] = element.Ty; - value['April'] = element.ReceiptNo || '-'; - value['May'] = element.ReceiptNoComments || '-'; - value['June'] = element.ModeOfPayment || '-'; - value['July'] = element.Status || '-'; - value['August'] = element.Status; - value['September'] = element.Balance || '-'; - value['October'] = element.Balance || '-'; - value['November'] = element.Balance || '-'; - value['December'] = element.Balance || '-'; - value['total'] = element.Balance || '-'; - o[intDate] = value; - intDate++; - intDataSNo++; - } - - rows1 = o; - var headers = { - fila_1: { - col_1: { text: 'SLNO', style: 'tableHeader', alignment: 'center', bold: true }, - col_2: { text: 'Description', style: 'tableHeader', alignment: 'center', bold: true }, - col_3: { text: 'January', style: 'tableHeader', alignment: 'center', bold: true }, - col_4: { text: 'February', style: 'tableHeader', alignment: 'center', bold: true }, - col_5: { text: 'March', style: 'tableHeader', alignment: 'center', bold: true }, - col_6: { text: 'April', style: 'tableHeader', alignment: 'center', bold: true }, - col_7: { text: 'May', style: 'tableHeader', alignment: 'center', bold: true }, - col_8: { text: 'June', style: 'tableHeader', alignment: 'center', bold: true }, - col_9: { text: 'July', style: 'tableHeader', alignment: 'center', bold: true }, - col_10: { text: 'August', style: 'tableHeader', alignment: 'center', bold: true }, - col_11: { text: 'September', style: 'tableHeader', alignment: 'center', bold: true }, - col_12: { text: 'October', style: 'tableHeader', alignment: 'center', bold: true }, - col_13: { text: 'November', style: 'tableHeader', alignment: 'center', bold: true }, - col_14: { text: 'December', style: 'tableHeader', alignment: 'center', bold: true }, - col_15: { text: 'Total Amount', style: 'tableHeader', alignment: 'center', bold: true }, - } - } - var body = []; - for (var key in headers) { - if (headers.hasOwnProperty(key)) { - var header = headers[key]; - var row = new Array(); - row.push(header.col_1); - row.push(header.col_2); - row.push(header.col_3); - row.push(header.col_4); - row.push(header.col_5); - row.push(header.col_6); - row.push(header.col_7); - row.push(header.col_8); - row.push(header.col_9); - row.push(header.col_10); - row.push(header.col_11); - row.push(header.col_12); - row.push(header.col_13); - row.push(header.col_14); - row.push(header.col_15); - body.push(row); - } - } - for (var key in rows1) { - if (rows1.hasOwnProperty(key)) { - var data = rows1[key]; - var row = new Array(); - row.push(data.SL_NO.toString()); - row.push(data.Expense_name.toString()); - row.push(data.January.toString()); - row.push(data.February.toString()); - row.push(data.March.toString()); - row.push(data.April.toString()); - row.push(data.May.toString()); - row.push(data.June.toString()); - row.push(data.July.toString()); - row.push(data.August.toString()); - row.push(data.September.toString()); - row.push(data.October.toString()); - row.push(data.November.toString()); - row.push(data.December.toString()); - row.push(data.total.toString()); - body.push(row); - } - } - - - var docDefinition = { - pageMargins: [20, 85, 20, 50], - pageOrientation: 'landscape', - header: function () { - return { - margin: 0, - columns: [ - { - text: ['Expense Report' ], - alignment: 'left', bold: true, margin: [20, 30, 0, 0], fontSize: 18 - } - ] - } - }, - footer: function (currentPage, pageCount) { - if (currentPage === pageCount) { - return { - columns: [ - { - text: ['Note'], - alignment: 'left', margin: [10, 0, 0, 0], fontSize: 8 - }, - { text: ['\n Page ' + currentPage.toString() + ' of ' + pageCount], alignment: 'right', margin: [0, 10, 10, 0], fontSize: 10 } - ] - }; - } else { - return { - text: 'Page ' + currentPage.toString() + ' of ' + pageCount, alignment: 'right', margin: [0, 10, 10, 0], fontSize: 10 - }; - } - }, - content: [ - { - // layout: 'lightHorizontalLines', // optional - table: { - - headerRows: 1, - keepWithHeaderRows: 0, - body: body - }, - layout: { - hLineWidth: function (i, node) { - return 0.5; - }, - vLineWidth: function (i, node) { - // return (i === 0 || i === node.table.widths.length) ? 0 : 40; - return 0.5; - }, - hLineColor: function (i, node) { - return '#2D4D81'; - }, - vLineColor: function (i, node) { - return '#2D4D81'; - }, - } - } - ], - styles: { - header: { - fontSize: 12, - bold: true - }, - subheader: { - fontSize: 12, - bold: true - }, - quote: { - italics: true - }, - small: { - fontSize: 6 - }, - sta: { - fontSize: 8, - bold: false, - alignment: 'justify' - } - } - }; - - - pdfMake.createPdf(docDefinition).download('Expense Report).pdf', function(res) { - if(res === 'success'){ - $scope.$apply(function(){ - $scope.loadStaring = false; - }); - }else{ - $scope.$apply(function(){ - $scope.loadStaring = false; - }); - } - }); - } + var o = {}; + var intDataSNo = 1; + var intDate = 0; + + for (var i = 0; i <= datas.length - 1; ++i) { + var element = datas[i]; + //var element = datas[i-1]; + console.log(datas); + var value = {}; + + value['SL_NO'] = element.SL_NO || ''; + value['Expense_name'] = element.Expense_name || '-'; + value['January'] = element.January || ''; + value['February'] =element. February || ''; + value['March'] = element.March || ''; + value['April'] = element.April || ''; + value['May'] = element.May || ''; + value['June'] = element.June || ''; + value['July'] = element.July || ''; + value['August'] = element.August || ''; + value['September'] = element.September || ''; + value['October'] = element.October || ''; + value['November'] = element.November || ''; + value['December'] = element.December || ''; + value['total'] = element.total || 0; + o[intDate] = value; + intDate++; + intDataSNo++; + } + + rows1 = o; + var headers = { + fila_1: { + col_1: { text: 'SLNO', style: 'tableHeader', alignment: 'center', bold: true }, + col_2: { text: 'Description', style: 'tableHeader', alignment: 'center', bold: true }, + col_3: { text: 'January', style: 'tableHeader', alignment: 'center', bold: true }, + col_4: { text: 'February', style: 'tableHeader', alignment: 'center', bold: true }, + col_5: { text: 'March', style: 'tableHeader', alignment: 'center', bold: true }, + col_6: { text: 'April', style: 'tableHeader', alignment: 'center', bold: true }, + col_7: { text: 'May', style: 'tableHeader', alignment: 'center', bold: true }, + col_8: { text: 'June', style: 'tableHeader', alignment: 'center', bold: true }, + col_9: { text: 'July', style: 'tableHeader', alignment: 'center', bold: true }, + col_10: { text: 'August', style: 'tableHeader', alignment: 'center', bold: true }, + col_11: { text: 'September', style: 'tableHeader', alignment: 'center', bold: true }, + col_12: { text: 'October', style: 'tableHeader', alignment: 'center', bold: true }, + col_13: { text: 'November', style: 'tableHeader', alignment: 'center', bold: true }, + col_14: { text: 'December', style: 'tableHeader', alignment: 'center', bold: true }, + col_15: { text: 'Total Amount', style: 'tableHeader', alignment: 'center', bold: true }, + } + } + var body = []; + for (var key in headers) { + if (headers.hasOwnProperty(key)) { + var header = headers[key]; + var row = new Array(); + row.push(header.col_1); + row.push(header.col_2); + row.push(header.col_3); + row.push(header.col_4); + row.push(header.col_5); + row.push(header.col_6); + row.push(header.col_7); + row.push(header.col_8); + row.push(header.col_9); + row.push(header.col_10); + row.push(header.col_11); + row.push(header.col_12); + row.push(header.col_13); + row.push(header.col_14); + row.push(header.col_15); + + body.push(row); + } + } + console.log(rows1); + for (var key in rows1) { + if (rows1.hasOwnProperty(key)) { + var data = rows1[key]; + + var row = new Array(); + row.push(data.SL_NO.toString()); + row.push(data.Expense_name.toString()); + row.push(data.January.toString()); + row.push(data.February.toString()); + row.push(data.March.toString()); + row.push(data.April.toString()); + row.push(data.May.toString()); + row.push(data.June.toString()); + row.push(data.July.toString()); + row.push(data.August.toString()); + row.push(data.September.toString()); + row.push(data.October.toString()); + row.push(data.November.toString()); + row.push(data.December.toString()); + row.push(data.total.toString()); + body.push(row); + } + } + + + var docDefinition = { + pageMargins: [20, 85, 20, 50], + pageOrientation: 'landscape', + header: function () { + return { + margin: 0, + columns: [ + { + text: ['Expense Report'], + alignment: 'left', bold: true, margin: [20, 30, 0, 0], fontSize: 18 + } + ] + } + }, + footer: function (currentPage, pageCount) { + if (currentPage === pageCount) { + return { + columns: [ + { + text: [''], + alignment: 'left', margin: [10, 0, 0, 0], fontSize: 8 + }, + { text: ['\n Page ' + currentPage.toString() + ' of ' + pageCount], alignment: 'right', margin: [0, 10, 10, 0], fontSize: 10 } + ] + }; + } else { + return { + text: 'Page ' + currentPage.toString() + ' of ' + pageCount, alignment: 'right', margin: [0, 10, 10, 0], fontSize: 10 + }; + } + }, + content: [ + { + // layout: 'lightHorizontalLines', // optional + table: { + + headerRows: 1, + keepWithHeaderRows: 0, + body: body + }, + layout: { + hLineWidth: function (i, node) { + return 0.5; + }, + vLineWidth: function (i, node) { + // return (i === 0 || i === node.table.widths.length) ? 0 : 40; + return 0.5; + }, + hLineColor: function (i, node) { + return '#2D4D81'; + }, + vLineColor: function (i, node) { + return '#2D4D81'; + }, + } + } + ], + styles: { + header: { + fontSize: 12, + bold: true + }, + subheader: { + fontSize: 12, + bold: true + }, + quote: { + italics: true + }, + small: { + fontSize: 6 + }, + sta: { + fontSize: 8, + bold: false, + alignment: 'justify' + } + } + }; + + + pdfMake.createPdf(docDefinition).download('Expense Report).pdf', function (res) { + if (res === 'success') { + $scope.$apply(function () { + $scope.loadStaring = false; + }); + } else { + $scope.$apply(function () { + $scope.loadStaring = false; + }); + } + }); + } //end of pdf - - $scope.exportData = function () { - alasql('SELECT CAST(SL_NO AS NUMBER) as SLNO,Expense_name as ExpenseName,CAST(January as NUMBER) as January,CAST(February as NUMBER) as February,CAST(March as NUMBER) as March,CAST(April as NUMBER) as April,CAST(May as NUMBER) as May,CAST(June as NUMBER) as June,CAST(July as NUMBER) as July,CAST(August as NUMBER) as August,CAST(September as NUMBER) as September,CAST(October as NUMBER) as October,CAST(November as NUMBER) as November,CAST(December as NUMBER) as December,CAST(total as NUMBER) as Amount INTO XLS("Expense_report.xls",?) FROM ?',[mystyle,$scope.expense_data]); - }; + + }]); diff --git a/Apollo/assets/views/report_expense.html b/Apollo/assets/views/report_expense.html index d1109884..169b4c45 100755 --- a/Apollo/assets/views/report_expense.html +++ b/Apollo/assets/views/report_expense.html @@ -81,11 +81,11 @@
- + - +

Apollo Distance Education College - {{expense_data[0].branch}}