'use strict'; angular.module('acufuel') .controller('analyticsController', ['$scope', 'analyticsService', function($scope, analyticsService) { $(document).ready(function() { $(function() { jQuery('#map').vectorMap({ map: 'us_lcc', backgroundColor: '#ffce99', color: '#dfdfdd', hoverOpacity: 0, selectedColor: '#5f8b98', hoverColor: '#5f8b98', enableZoom: true, showTooltip: true, scaleColors: ['#dfdfdd'], //values: sample_data onRegionClick: function(event, code) { var map = $('#map').vectorMap('get', 'mapObject'); var name = map.getRegionName(code); getRegionPap(name); }, normalizeFunction: 'polynomial' }); }); }) function getRegionPap(code) { $scope.showLoader = true; analyticsService.getRPP(code).then(function(result) { $scope.rppData = result; $scope.showLoader = false; $('#popup1').css('display', 'block'); }) } $scope.cancelStatus = function() { $('#popup1').css('display', 'none'); } $scope.ordersCost = 0; $scope.ordersCount = 0; $scope.orderCostAndCount = function() { analyticsService.orderCostAndCount().then(function(result) { $scope.ordersCost = result.cost; $scope.ordersCount = result.count; }) } $scope.drf = {}; $scope.hfp = {}; $scope.cs = {}; $scope.mfsValues = []; $scope.msfarray = []; $scope.getMFS = function() { //var makeId = makeId; analyticsService.getMFS().then(function(result) { $scope.mfsValues = result; $scope.optionsmfs = { chart: { type: 'multiBarChart', height: 450, margin: { top: 45, right: 20, bottom: 45, left: 45 }, clipEdge: true, //staggerLabels: true, duration: 500, stacked: false, color: ["#FEDFC3", "#990000", "#000099", "#009900"], xAxis: { axisLabel: 'Months', showMaxMin: false, }, yAxis: { axisLabel: 'Orders', axisLabelDistance: -20, tickFormat: function(d) { return d3.format(',.1f')(d); } } } }; $scope.datamfs = $scope.mfsValues; }) } $scope.orderCostAndCount(); $scope.getMFS(); $scope.csValues = []; $scope.getCS = function() { //var makeId = makeId; analyticsService.getCS().then(function(result) { $scope.csValues = result; $scope.optionscs = { chart: { type: 'pieChart', height: 500, // color: ["#FEDFC3","#D89700","#FFE8B3","FFD980","#FF7F0E","#fff2e6","#ffcc99","#ffa64d","#ff8c1a","#B37D00","#f5f5f0","#e0e0d1","#ccccb3","#adad85","#999966","#7a7a52"], x: function(d) { return d.key; }, y: function(d) { return d.y; }, showLabels: false, segmentShowStroke: false, animationSteps: 20, animationEasing: "linear", animateScale: true, duration: 500, labelThreshold: 0.01, labelSunbeamLayout: true, legend: { margin: { top: 5, right: 35, bottom: 5, left: 0 } } } }; $scope.datacs = $scope.csValues; }) } $scope.getCS(); $scope.hfpValues = []; $scope.getHfpChartData = function() { //var makeId = makeId; analyticsService.gethfpChart().then(function(result) { $scope.hfpValues = result; console.log('---kd result--',$scope.hfpValues); /*Historic Fuel Price */ $scope.optionshfp = { chart: { type: 'cumulativeLineChart', height: 450, margin: { top: 40, right: 20, bottom: 50, left: 65 }, x: function(d) { return d[0]; }, y: function(d) { return d[1] ; }, average: function(d) { return d.mean / 100; }, color: ["#FEDFC3"], duration: 300, useInteractiveGuideline: true, clipVoronoi: false, xAxis: { axisLabel: '', tickFormat: function(d) { // return d3.time.format('%m - %y')(new Date(d)) return d3.time.format('%b \-%y')(new Date(d)) }, showMaxMin: false, staggerLabels: true }, yAxis: { axisLabel: 'PaP/Retail Price', tickFormat: function(d) { //return d3.format('')(d).toFixed(2); return '$ '+d.toFixed(2) }, axisLabelDistance: 5 } } }; $scope.datahfp = [{ key: "Long", values: $scope.hfpValues, mean: 0 }]; }) } $scope.getHfpChartData(); /*Date Range Filter for Monthly fuel Sales*/ $scope.submitDate = function() { if ($scope.drf.fromDate === undefined) { $scope.fillForm = true; } else if ($scope.drf.fromDate != undefined && $scope.drf.toDate === undefined || $scope.drf.toDate === '') { $scope.fillForm = false; var today = new Date(); var DefaultToDate = today.getFullYear() + '-' + ("0" + (today.getMonth() + 1)).slice(-2) + '-' + ("0" + today.getDate()).slice(-2); //from date format $scope.dat1 = $scope.drf.fromDate; $scope.fd1 = $scope.dat1.split("/").reverse(); $scope.tmp = $scope.fd1[2]; $scope.fd1[2] = $scope.fd1[1]; $scope.fd1[1] = $scope.tmp; $scope.fd = $scope.fd1.join("-"); analyticsService.getDRFChart($scope.fd, DefaultToDate).then(function(result) { $scope.datamfs = []; $scope.datamfs = result; }) analyticsService.orderCostAndCountByDate($scope.fd, DefaultToDate).then(function(result) { $scope.ordersCost = result.cost; $scope.ordersCount = result.count; }) } else if ($scope.drf.fromDate != undefined && $scope.drf.toDate != undefined) { $scope.fillForm = false; //from date format $scope.dat1 = $scope.drf.fromDate; $scope.fd1 = $scope.dat1.split("/").reverse(); $scope.tmp = $scope.fd1[2]; $scope.fd1[2] = $scope.fd1[1]; $scope.fd1[1] = $scope.tmp; $scope.fd = $scope.fd1.join("-"); $scope.dat2 = $scope.drf.toDate; $scope.td1 = $scope.dat2.split("/").reverse(); $scope.tmp1 = $scope.td1[2]; $scope.td1[2] = $scope.td1[1]; $scope.td1[1] = $scope.tmp1; $scope.td = $scope.td1.join("-"); analyticsService.getDRFChart($scope.fd, $scope.td).then(function(result) { $scope.datamfs = []; $scope.datamfs = result; }) analyticsService.orderCostAndCountByDate($scope.fd, $scope.td).then(function(result) { $scope.ordersCost = result.cost; $scope.ordersCount = result.count; }) } else { $scope.fillForm = true; } } /*Date Range Filter for Historic fuel Price*/ $scope.submitDateHfp = function() { if ($scope.hfp.fromDate === undefined) { $scope.fillForm = true; } else if ($scope.hfp.fromDate != undefined && $scope.hfp.toDate === undefined || $scope.hfp.toDate === '') { $scope.fillForm = false; var today = new Date(); var DefaultToDate = today.getFullYear() + '-' + ("0" + (today.getMonth() + 1)).slice(-2) + '-' + ("0" + today.getDate()).slice(-2); //from date format $scope.dat1 = $scope.hfp.fromDate; $scope.fd1 = $scope.dat1.split("/").reverse(); $scope.tmp = $scope.fd1[2]; $scope.fd1[2] = $scope.fd1[1]; $scope.fd1[1] = $scope.tmp; $scope.fd = $scope.fd1.join("-"); analyticsService.getDRFHfpChart($scope.fd, DefaultToDate).then(function(result) { $scope.hfpValues = result; $scope.optionshfp = { chart: { type: 'cumulativeLineChart', height: 450, margin: { top: 40, right: 20, bottom: 50, left: 65 }, x: function(d) { return d[0]; }, y: function(d) { return d[1] ; }, average: function(d) { return d.mean / 100; }, color: ["#FEDFC3"], duration: 300, useInteractiveGuideline: true, clipVoronoi: false, xAxis: { axisLabel: '', tickFormat: function(d) { // return d3.time.format('%m - %y')(new Date(d)) return d3.time.format('%b \-%y')(new Date(d)) }, showMaxMin: false, staggerLabels: true }, yAxis: { axisLabel: 'PaP/Retail Price', tickFormat: function(d) { //return d3.format('')(d).toFixed(2); return '$ '+d.toFixed(2) }, axisLabelDistance: 5 } } }; $scope.datahfp = [{ key: "Long", values: $scope.hfpValues, mean: 0 }]; }) } else if ($scope.hfp.fromDate != undefined && $scope.hfp.toDate != undefined) { $scope.fillForm = false; //from date format $scope.dat1 = $scope.hfp.fromDate; $scope.fd1 = $scope.dat1.split("/").reverse(); $scope.tmp = $scope.fd1[2]; $scope.fd1[2] = $scope.fd1[1]; $scope.fd1[1] = $scope.tmp; $scope.fd = $scope.fd1.join("-"); //to date format $scope.dat2 = $scope.hfp.toDate; $scope.td1 = $scope.dat2.split("/").reverse(); $scope.tmp1 = $scope.td1[2]; $scope.td1[2] = $scope.td1[1]; $scope.td1[1] = $scope.tmp1; $scope.td = $scope.td1.join("-"); analyticsService.getDRFHfpChart($scope.fd, $scope.td).then(function(result) { $scope.hfpValues = result; $scope.optionshfp = { chart: { type: 'cumulativeLineChart', height: 450, margin: { top: 40, right: 20, bottom: 50, left: 65 }, x: function(d) { return d[0]; }, y: function(d) { return d[1] ; }, average: function(d) { return d.mean / 100; }, color: ["#FEDFC3"], duration: 300, useInteractiveGuideline: true, clipVoronoi: false, xAxis: { axisLabel: '', tickFormat: function(d) { // return d3.time.format('%m - %y')(new Date(d)) return d3.time.format('%b \-%y')(new Date(d)) }, showMaxMin: false, staggerLabels: true }, yAxis: { axisLabel: 'PaP/Retail Price', tickFormat: function(d) { //return d3.format('')(d).toFixed(2); return '$ '+d.toFixed(2) }, axisLabelDistance: 5 } } }; $scope.datahfp = [{ key: "Long", values:$scope.hfpValues, mean: 0 }]; }) } else { $scope.fillForm = true; } } /*Date Range Filter for Customer Sources*/ $scope.submitDateCs = function() { if ($scope.cs.fromDate === undefined) { $scope.fillForm = true; } else if ($scope.cs.fromDate != undefined && $scope.cs.toDate === undefined || $scope.cs.toDate === '') { $scope.fillForm = false; var today = new Date(); var DefaultToDate = today.getFullYear() + '-' + ("0" + (today.getMonth() + 1)).slice(-2) + '-' + ("0" + today.getDate()).slice(-2); //from date format $scope.dat1 = $scope.cs.fromDate; $scope.fd1 = $scope.dat1.split("/").reverse(); $scope.tmp = $scope.fd1[2]; $scope.fd1[2] = $scope.fd1[1]; $scope.fd1[1] = $scope.tmp; $scope.fd = $scope.fd1.join("-"); analyticsService.getDRFCSChart($scope.fd, DefaultToDate).then(function(result) { $scope.csValues = result; $scope.optionscs = { chart: { type: 'pieChart', height: 500, // color: ["#FEDFC3","#D89700","#FFE8B3","FFD980","#FF7F0E","#fff2e6","#ffcc99","#ffa64d","#ff8c1a","#B37D00","#f5f5f0","#e0e0d1","#ccccb3","#adad85","#999966","#7a7a52"], x: function(d) { return d.key; }, y: function(d) { return d.y; }, showLabels: false, segmentShowStroke: false, animationSteps: 20, animationEasing: "linear", animateScale: true, duration: 500, labelThreshold: 0.01, labelSunbeamLayout: true, legend: { margin: { top: 5, right: 35, bottom: 5, left: 0 } } } }; $scope.datacs = $scope.csValues; }) } else if ($scope.cs.fromDate != undefined && $scope.cs.toDate != undefined) { $scope.fillForm = false; //from date format $scope.dat1 = $scope.cs.fromDate; $scope.fd1 = $scope.dat1.split("/").reverse(); $scope.tmp = $scope.fd1[2]; $scope.fd1[2] = $scope.fd1[1]; $scope.fd1[1] = $scope.tmp; $scope.fd = $scope.fd1.join("-"); //to date format $scope.dat2 = $scope.cs.toDate; $scope.td1 = $scope.dat2.split("/").reverse(); $scope.tmp1 = $scope.td1[2]; $scope.td1[2] = $scope.td1[1]; $scope.td1[1] = $scope.tmp1; $scope.td = $scope.td1.join("-"); analyticsService.getDRFCSChart($scope.fd, $scope.td).then(function(result) { $scope.csValues = result; $scope.optionscs = { chart: { type: 'pieChart', height: 500, // color: ["#FEDFC3","#D89700","#FFE8B3","FFD980","#FF7F0E","#fff2e6","#ffcc99","#ffa64d","#ff8c1a","#B37D00","#f5f5f0","#e0e0d1","#ccccb3","#adad85","#999966","#7a7a52"], x: function(d) { return d.key; }, y: function(d) { return d.y; }, showLabels: false, segmentShowStroke: false, animationSteps: 20, animationEasing: "linear", animateScale: true, duration: 500, labelThreshold: 0.01, labelSunbeamLayout: true, legend: { margin: { top: 5, right: 35, bottom: 5, left: 0 } } } }; $scope.datacs = $scope.csValues; }) } else { $scope.fillForm = true; } } }]);