Blame view

app/partials/analytics/analytics.controller.js 21 KB
feacde5ff   Rishav   setup acuefuel in...
1
  'use strict';
d20181a2e   Anchit Jindal   fixed bugs
2
3
4
5
6
  angular.module('acufuel')
      .controller('analyticsController', ['$scope', 'analyticsService', function($scope, analyticsService) {
  
          $(document).ready(function() {
              $(function() {
d20181a2e   Anchit Jindal   fixed bugs
7
                  jQuery('#map').vectorMap({
1b71872b2   Kuldeep Arora   email and code be...
8
9
                      map: 'us_lcc',
                      backgroundColor: '#ffce99',
d20181a2e   Anchit Jindal   fixed bugs
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
                      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'
                  });
d20181a2e   Anchit Jindal   fixed bugs
25
              });
bd3a040f8   Kuldeep Arora   Regional Pap pric...
26
          })
d20181a2e   Anchit Jindal   fixed bugs
27
28
29
          function getRegionPap(code) {
              $scope.showLoader = true;
              analyticsService.getRPP(code).then(function(result) {
f6e8207e4   Kuldeep Arora   charts
30
31
32
                  $scope.rppData = result;
                  $scope.showLoader = false;
                  $('#popup1').css('display', 'block');
d20181a2e   Anchit Jindal   fixed bugs
33
34
35
              })
          }
          $scope.cancelStatus = function() {
bd3a040f8   Kuldeep Arora   Regional Pap pric...
36
              $('#popup1').css('display', 'none');
d20181a2e   Anchit Jindal   fixed bugs
37
38
39
40
41
          }
          $scope.ordersCost = 0;
          $scope.ordersCount = 0;
  
          $scope.orderCostAndCount = function() {
f6e8207e4   Kuldeep Arora   charts
42
43
              analyticsService.orderCostAndCount().then(function(result) {
                  $scope.ordersCost = result.cost;
d20181a2e   Anchit Jindal   fixed bugs
44
                  $scope.ordersCount = result.count;
f6e8207e4   Kuldeep Arora   charts
45
              })
d20181a2e   Anchit Jindal   fixed bugs
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
          }
  
          $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;
              })
bd3a040f8   Kuldeep Arora   Regional Pap pric...
127
          }
d20181a2e   Anchit Jindal   fixed bugs
128
          $scope.getCS();
cefbd3ffa   Anchit Jindal   email related issues
129
130
131
132
133
134
          
         
          $scope.hfpValues = [];
          $scope.getHfpChartData = function() {
              //var makeId = makeId;
              analyticsService.gethfpChart().then(function(result) {
cefbd3ffa   Anchit Jindal   email related issues
135
                  $scope.hfpValues = result;
f6e8207e4   Kuldeep Arora   charts
136
                  console.log('---kd result--',$scope.hfpValues);
cefbd3ffa   Anchit Jindal   email related issues
137
                  
d20181a2e   Anchit Jindal   fixed bugs
138
          /*Historic Fuel Price */
cefbd3ffa   Anchit Jindal   email related issues
139
          
d20181a2e   Anchit Jindal   fixed bugs
140
          $scope.optionshfp = {
cefbd3ffa   Anchit Jindal   email related issues
141
142
143
144
                  chart: {
                      type: 'cumulativeLineChart',
                      height: 450,
                      margin: {
6c5a99488   Kuldeep Arora   analytics and fue...
145
                          top: 40,
cefbd3ffa   Anchit Jindal   email related issues
146
147
148
149
150
151
152
153
                          right: 20,
                          bottom: 50,
                          left: 65
                      },
                      x: function(d) {
                          return d[0];
                      },
                      y: function(d) {
de02ae986   Kuldeep Arora   minor
154
                          return d[1] / 100 ;
cefbd3ffa   Anchit Jindal   email related issues
155
156
157
158
                      },
                      average: function(d) {
                          return d.mean / 100;
                      },
d20181a2e   Anchit Jindal   fixed bugs
159

cefbd3ffa   Anchit Jindal   email related issues
160
161
162
163
                      color: ["#FEDFC3"],
                      duration: 300,
                      useInteractiveGuideline: true,
                      clipVoronoi: false,
d20181a2e   Anchit Jindal   fixed bugs
164

cefbd3ffa   Anchit Jindal   email related issues
165
                      xAxis: {
6c5a99488   Kuldeep Arora   analytics and fue...
166
167
                          axisLabel: '',
                                                     
cefbd3ffa   Anchit Jindal   email related issues
168
                          tickFormat: function(d) {
de02ae986   Kuldeep Arora   minor
169
170
                              return d3.time.format('%m/%d/%y')(new Date(d))
                             //return d3.time.format('%b \-%y')(new Date(d))   
cefbd3ffa   Anchit Jindal   email related issues
171
172
173
                          },
                          showMaxMin: false,
                          staggerLabels: true
d20181a2e   Anchit Jindal   fixed bugs
174
                      },
d20181a2e   Anchit Jindal   fixed bugs
175

cefbd3ffa   Anchit Jindal   email related issues
176
                      yAxis: {
6c5a99488   Kuldeep Arora   analytics and fue...
177
                          axisLabel: 'PaP/Retail Price',
cefbd3ffa   Anchit Jindal   email related issues
178
179
                          
                          tickFormat: function(d) {
6c5a99488   Kuldeep Arora   analytics and fue...
180
181
                              //return d3.format('')(d).toFixed(2);
                              return '$ '+d.toFixed(2)
cefbd3ffa   Anchit Jindal   email related issues
182
                          },
6c5a99488   Kuldeep Arora   analytics and fue...
183
                          axisLabelDistance: 5
cefbd3ffa   Anchit Jindal   email related issues
184
                      }
a9aef0b1c   Anchit Jindal   new changes imple...
185
                  }
cefbd3ffa   Anchit Jindal   email related issues
186
              };
6c5a99488   Kuldeep Arora   analytics and fue...
187
188
189
190
191
                  $scope.datahfp = [{
                      key: "Long",
                      values: $scope.hfpValues,
                      mean: 0
                  }];
6c5a99488   Kuldeep Arora   analytics and fue...
192
193
194
195
196
                  
              })
          }
          
          $scope.getHfpChartData();
d121d5539   Kuldeep Arora   UI Changes
197

d20181a2e   Anchit Jindal   fixed bugs
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
          /*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;
                  })
565570086   Kuldeep Arora   highcharts(MFS,CS...
217
                  
f6e8207e4   Kuldeep Arora   charts
218
219
220
221
                  analyticsService.orderCostAndCountByDate($scope.fd, DefaultToDate).then(function(result) {
                      $scope.ordersCost = result.cost;
                      $scope.ordersCount = result.count;
                  })
d20181a2e   Anchit Jindal   fixed bugs
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
              } 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;
                  })
565570086   Kuldeep Arora   highcharts(MFS,CS...
242
                  
d20181a2e   Anchit Jindal   fixed bugs
243
                  analyticsService.orderCostAndCountByDate($scope.fd, $scope.td).then(function(result) {
f6e8207e4   Kuldeep Arora   charts
244
245
246
                      $scope.ordersCost = result.cost;
                      $scope.ordersCount = result.count;
                  })
d20181a2e   Anchit Jindal   fixed bugs
247
248
249
  
              } else {
                  $scope.fillForm = true;
565570086   Kuldeep Arora   highcharts(MFS,CS...
250
              }
d20181a2e   Anchit Jindal   fixed bugs
251

565570086   Kuldeep Arora   highcharts(MFS,CS...
252
          }
d20181a2e   Anchit Jindal   fixed bugs
253
254
255
256
          /*Date Range Filter for Historic fuel Price*/
          $scope.submitDateHfp = function() {
  
              if ($scope.hfp.fromDate === undefined) {
d20181a2e   Anchit Jindal   fixed bugs
257
258
259
260
261
262
263
264
265
266
267
268
                  $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("-");
d20181a2e   Anchit Jindal   fixed bugs
269
                  analyticsService.getDRFHfpChart($scope.fd, DefaultToDate).then(function(result) {
f6e8207e4   Kuldeep Arora   charts
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
                      $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) {
de02ae986   Kuldeep Arora   minor
285
                                  return d[1]  / 100;
f6e8207e4   Kuldeep Arora   charts
286
287
288
289
290
291
292
293
294
295
296
297
298
299
                              },
                              average: function(d) {
                                  return d.mean / 100;
                              },
  
                              color: ["#FEDFC3"],
                              duration: 300,
                              useInteractiveGuideline: true,
                              clipVoronoi: false,
  
                              xAxis: {
                                  axisLabel: '',
                                                             
                                  tickFormat: function(d) {
de02ae986   Kuldeep Arora   minor
300
301
                                     return d3.time.format('%d / %m / %y')(new Date(d))
                                    // return d3.time.format('%b \-%y')(new Date(d))   
f6e8207e4   Kuldeep Arora   charts
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
                                  },
                                  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
                          }];
d20181a2e   Anchit Jindal   fixed bugs
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
                  })
  
  
              } 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) {
f6e8207e4   Kuldeep Arora   charts
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
                      $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) {
de02ae986   Kuldeep Arora   minor
359
                                      return d[1] / 100 ;
f6e8207e4   Kuldeep Arora   charts
360
361
362
363
364
365
366
367
368
369
370
371
372
373
                                  },
                                  average: function(d) {
                                      return d.mean / 100;
                                  },
  
                                  color: ["#FEDFC3"],
                                  duration: 300,
                                  useInteractiveGuideline: true,
                                  clipVoronoi: false,
  
                                  xAxis: {
                                      axisLabel: '',
                                                                 
                                      tickFormat: function(d) {
de02ae986   Kuldeep Arora   minor
374
375
                                         return d3.time.format('%d / %m / %y')(new Date(d))
                                         //return d3.time.format('%b \-%y')(new Date(d))   
f6e8207e4   Kuldeep Arora   charts
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
                                      },
                                      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
                              }];
d20181a2e   Anchit Jindal   fixed bugs
397
398
399
400
                  })
  
              } else {
                  $scope.fillForm = true;
75d1c3d9f   Kuldeep Arora   analytics DRF UI
401
              }
d20181a2e   Anchit Jindal   fixed bugs
402

75d1c3d9f   Kuldeep Arora   analytics DRF UI
403
          }
d20181a2e   Anchit Jindal   fixed bugs
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
          /*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
b944d384c   Kuldeep Arora   analytics UI
447
                                  }
d20181a2e   Anchit Jindal   fixed bugs
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
                              }
                          }
                      };
                      $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
b944d384c   Kuldeep Arora   analytics UI
499
                                  }
d20181a2e   Anchit Jindal   fixed bugs
500
501
502
503
504
505
506
507
                              }
                          }
                      };
                      $scope.datacs = $scope.csValues;
                  })
  
              } else {
                  $scope.fillForm = true;
75d1c3d9f   Kuldeep Arora   analytics DRF UI
508
              }
75d1c3d9f   Kuldeep Arora   analytics DRF UI
509

d20181a2e   Anchit Jindal   fixed bugs
510
          }
75d1c3d9f   Kuldeep Arora   analytics DRF UI
511

feacde5ff   Rishav   setup acuefuel in...
512

d20181a2e   Anchit Jindal   fixed bugs
513
      }]);