Guest User

Untitled

a guest
Jan 17th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.94 KB | None | 0 0
  1. // code style: https://github.com/johnpapa/angular-styleguide
  2.  
  3. (function() {
  4. 'use strict';
  5. angular
  6. .module('app')
  7. .controller('RevenueCtrl', RevenueCtrl);
  8.  
  9. function RevenueCtrl($scope, lead, $timeout) {
  10.  
  11. var vm = $scope;
  12. google.charts.load('current', { 'packages': ['corechart', 'bar'] });
  13.  
  14.  
  15. var filter = {};
  16. vm.openLead = 0;
  17. vm.closeLead = 0;
  18. vm.convertedLead = 0;
  19. vm.hotLead = 0;
  20. vm.coldLead = 0;
  21. vm.todayCall = 0;
  22. vm.todayMeeting = 0;
  23. vm.thisMonthLead = 0;
  24.  
  25. lead.getRevenueDashboardData(filter)
  26. .success(function(res) {
  27.  
  28. vm.totalValue = res.totalValue;
  29. if ('OPEN' in res.leadStatus)
  30. vm.openLead = res.leadStatus.OPEN;
  31. if ('CLOSE' in res.leadStatus)
  32. vm.closeLead = res.leadStatus.CLOSE;
  33. if ('CONVERTED' in res.leadStatus)
  34. vm.convertedLead = res.leadStatus.CONVERTED;
  35.  
  36. vm.totalLead = vm.openLead + vm.closeLead + vm.convertedLead;
  37.  
  38. if ('HOT' in res.hotColdLeads)
  39. vm.hotLead = res.hotColdLeads.HOT;
  40. if ('COLD' in res.hotColdLeads)
  41. vm.coldLead = res.hotColdLeads.COLD;
  42.  
  43.  
  44. if (res.monthLeads.length > 0)
  45. vm.thisMonthLead = res.monthLeads[0].lead;
  46.  
  47. if ('call' in res.todos)
  48. vm.todayCall = res.todos.call;
  49. if ('meeting' in res.todos)
  50. vm.todayMeeting = res.todos.meeting;
  51.  
  52. vm.conversionRate = Math.round((vm.convertedLead / vm.totalLead) * 100);
  53. vm.conversionRate = isNaN(vm.conversionRate) ? 0 : vm.conversionRate;
  54.  
  55. var loadMonthLeadGraphData = [];
  56. loadMonthLeadGraphData.push(['Month', 'Revenue']);
  57. angular.forEach(res.monthLeads, function(element, index) {
  58. var tempTime = moment().month(element._id.month - 1).format("MMM") + ' ' + element._id.year;
  59. loadMonthLeadGraphData.push([tempTime, element.revenue]);
  60. });
  61. loadMonthLeadGraph(loadMonthLeadGraphData)
  62.  
  63.  
  64. loadStageLeadGraph(res.stageLeads)
  65. loadWonLeadGraph(res.userWonLeads)
  66.  
  67. var loadHotColdLeadGraphData = [];
  68. loadHotColdLeadGraphData.push(['Month', 'Leads']);
  69. for (var variable in res.hotColdLeads) {
  70. loadHotColdLeadGraphData.push([variable, res.hotColdLeads[variable]]);
  71. }
  72.  
  73. loadHotColdLeadGraph(loadHotColdLeadGraphData)
  74.  
  75.  
  76.  
  77. var loadCloseReasonLeadGraphData = [];
  78. loadCloseReasonLeadGraphData.push(['Reason', 'Leads']);
  79. for (var variable in res.closeLeads) {
  80. loadCloseReasonLeadGraphData.push([variable, res.closeLeads[variable]]);
  81. }
  82. loadCloseReasonLeadGraph(loadCloseReasonLeadGraphData)
  83.  
  84. })
  85. .error(function(error) {
  86.  
  87. })
  88.  
  89. function loadMonthLeadGraph(loadMonthLeadGraphData) {
  90. google.charts.setOnLoadCallback(drawChart);
  91.  
  92. function drawChart() {
  93. var data = google.visualization.arrayToDataTable(loadMonthLeadGraphData);
  94. var options = {
  95. title: 'Last five months report',
  96. height: 327,
  97. colors: ["blue"]
  98. };
  99. var chart = new google.charts.Bar(document.getElementById('month-leads'));
  100.  
  101. chart.draw(data, google.charts.Bar.convertOptions(options));
  102. }
  103. }
  104.  
  105.  
  106. function loadWonLeadGraph(loadWonLeadGraphData) {
  107. google.charts.setOnLoadCallback(drawChart);
  108.  
  109. function drawChart() {
  110. var data = google.visualization.arrayToDataTable(loadWonLeadGraphData);
  111.  
  112. var options = {
  113. title: 'Lead converted by person',
  114. width: 550,
  115. height: 400,
  116. legend: { position: 'top', maxLines: 3 },
  117. bar: { groupWidth: '75%' },
  118. isStacked: true,
  119. vAxis: {
  120. title: 'Revenue'
  121. }
  122. };
  123.  
  124.  
  125. var chart = new google.charts.Bar(document.getElementById('won-leads'));
  126.  
  127. chart.draw(data, google.charts.Bar.convertOptions(options));
  128. }
  129. }
  130.  
  131. function loadStageLeadGraph(loadStageLeadGraphData) {
  132. google.charts.setOnLoadCallback(drawChart);
  133.  
  134. function drawChart() {
  135.  
  136. var data = new google.visualization.arrayToDataTable(loadStageLeadGraphData);
  137.  
  138. var options = {
  139. height: 400,
  140. chart: {
  141. title: 'Lead by Stages'
  142. },
  143. series: {
  144. 0: { axis: 'lead' }, // Bind series 0 to an axis named 'distance'.
  145. 1: { axis: 'value' } // Bind series 1 to an axis named 'brightness'.
  146. },
  147. axes: {
  148. y: {
  149. lead: { label: 'Lead' }, // Left y-axis.
  150. value: { side: 'right', label: 'Value' } // Right y-axis.
  151. }
  152. }
  153. };
  154.  
  155.  
  156. var chart = new google.charts.Bar(document.getElementById('stage-leads'));
  157. chart.draw(data, google.charts.Bar.convertOptions(options));
  158.  
  159. }
  160. }
  161.  
  162. function loadHotColdLeadGraph(loadHotColdLeadGraphData) {
  163. google.charts.setOnLoadCallback(drawChart);
  164.  
  165. function drawChart() {
  166. var data = google.visualization.arrayToDataTable(loadHotColdLeadGraphData);
  167.  
  168. var options = {
  169. title: 'Last five month report',
  170. height: 400
  171. };
  172.  
  173.  
  174. var chart = new google.charts.Bar(document.getElementById('hot-cold-leads'));
  175.  
  176. chart.draw(data, google.charts.Bar.convertOptions(options));
  177. }
  178. }
  179.  
  180. function loadCloseReasonLeadGraph(loadCloseReasonLeadGraphData) {
  181. google.charts.setOnLoadCallback(drawChart);
  182.  
  183. function drawChart() {
  184. var data = google.visualization.arrayToDataTable(loadCloseReasonLeadGraphData);
  185.  
  186. var options = {
  187. title: 'Closed Lead by Reason',
  188. pieHole: 0.4,
  189. width: 550,
  190. height: 400
  191. };
  192.  
  193. var chart = new google.visualization.PieChart(document.getElementById('close-reason-leads'));
  194. chart.draw(data, options);
  195. }
  196. }
  197.  
  198. vm.getDayWiseLeadByDays = getDayWiseLeadByDays;
  199. vm.selectedDays = 7;
  200. vm.showDays = [{ val: 7, text: '7 Days' }, { val: 10, text: '10 Days' }, { val: 15, text: '15 Days' }, { val: 20, text: '20 Days' }, { val: 30, text: '30 Days' }]
  201. getDayWiseLeadByDays(7);
  202.  
  203. function getDayWiseLeadByDays() {
  204. lead.getDayWiseLeadByDays(vm.selectedDays)
  205. .success(function(res) {
  206. var loadDaysLeadGraphData = [];
  207. loadDaysLeadGraphData.push(['Date', 'Revenue']);
  208. angular.forEach(res, function(element, index) {
  209. loadDaysLeadGraphData.push([element._id, element.revenue]);
  210. });
  211.  
  212. google.charts.setOnLoadCallback(drawChart);
  213.  
  214. function drawChart() {
  215. var data = google.visualization.arrayToDataTable(loadDaysLeadGraphData);
  216. var options = {
  217. hAxis: {
  218. title: "Month",
  219. textPosition: 'out',
  220. slantedText: true,
  221. slantedTextAngle: 90
  222. },
  223. vAxis: {
  224. title: 'Revenue',
  225. minValue: 0,
  226. viewWindow: { min: 0 },
  227. format: '0',
  228. },
  229. height: 260,
  230. colors: ['#e0440e', '#e6693e', '#ec8f6e', '#f3b49f', '#f6c7b6']
  231. };
  232. var chart = new google.charts.ColumnChart(document.getElementById('days-leads'));
  233.  
  234. chart.draw(data, options);
  235. }
  236. })
  237. .error(function(err) {
  238.  
  239. })
  240. }
  241. }
  242.  
  243. })();
Add Comment
Please, Sign In to add comment