Blame view

app/partials/analytics/analytics.controller.js 34 KB
feacde5ff   Rishav   setup acuefuel in...
1
  'use strict';
d20181a2e   Anchit Jindal   fixed bugs
2
3
  angular.module('acufuel')
      .controller('analyticsController', ['$scope', 'analyticsService', function($scope, analyticsService) {
7b21cec8f   Kuldeep Arora   analytical region...
4

89c9d6ecd   Kuldeep Arora   drilldown map for...
5
6
           // Sand Signika Overview without drill down -KD 
         /* $scope.getAllRegionalPap = function() {
7b21cec8f   Kuldeep Arora   analytical region...
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
              $scope.flag=true;
              $scope.stateList = [{region:'Alabama',code:'AL'},{region:'Alaska',code:'AK'},{region:'Arizona',code:'AZ'},{region:'Arkansas',code:'AR'},
                  {region:'California',code:'CA' },{region:'Colorado',code:'CO'},{region:'Connecticut',code:'CT'},{region:'Delaware',code:'DE'},
                  {region:'Florida' ,code:'FL'},{region:'Georgia' ,code:'GA'},{region:'Hawaii' ,code:'HI'},{region:'Idaho' ,code:'ID'},
                  {region:'Illinois',code:'IL'},{region:'Indiana' ,code:'IN'},{region:'Iowa' ,code:'IA'},{region:'Kansas' ,code:'KS'},
                  {region:'Kentucky' ,code:'KY'},{region:'Louisiana' ,code:'LA'},{region:'Maine' ,code:'ME'},{region:'Maryland' ,code:'MD'},
                  {region:'Massachusetts' ,code:'MA'},{region:'Michigan' ,code:'MI'},{region:'Minnesota' ,code:'MN'},
                  {region:'Mississippi' ,code:'MS'},{region:'Missouri' ,code:'MO'},{region:'Montana',code:'MT'},{region:'Nebraska' ,code:'NE'},
                  {region:'Nevada' ,code:'NV'},{region:'New Hampshire' ,code:'NH'},{region:'New Jersey' ,code:'NJ'},{region:'New Mexico' ,code:'NM'},
                  {region:'New York' ,code:'NY'},{region:'North Carolina' ,code:'NC'},{region:'North Dakota' ,code:'ND'},{region:'Ohio' ,code:'OH'},
                  {region:'Oklahoma' ,code:'OK'},{region:'Oregon' ,code:'OR'},{region:'Pennsylvania',code:'PA'},{region:'Rhode Island' ,code:'RI'},
                  {region:'South Carolina' ,code:'SC'},{region:'South Dakota' ,code:'SD'},{region:'Tennessee' ,code:'TN'},{region:'Texas' ,code:'TX'},
                  {region:'Utah' ,code:'UT'},{region:'Vermont' ,code:'VT'},{region:'Virginia' ,code:'VA'},{region:'Washington' ,code:'WA'},
                  {region:'West Virginia' ,code:'WV'},{region:'Wisconsin' ,code:'WI'},{region:'Wyoming',code:'WY'}]
             
              analyticsService.getAllRPP().then(function(result) {
                      for (var i = 0; i < $scope.stateList.length; i++) {
                          for (var j = 0; j<result.length; j++){
                              if ($scope.stateList[i].region === result[j].region) {
                                  result[j].code = $scope.stateList[i].code; 
938f3037d   Kuldeep Arora   decimal fixed ana...
27
                                  result[j].averagePAP = result[j].averagePAP.toFixed(2);
7b21cec8f   Kuldeep Arora   analytical region...
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
                              }
                          }                   
                      }
                       $scope.flag=false;
                      // Instantiate the map
                      Highcharts.mapChart('regional-pap', {
  
                          chart: {
                              map: 'countries/us/us-all',
                              borderWidth: 1,
                          },
  
                          title: {
                              text: 'Regional PAP'
                          },
  
                          exporting: {
                              sourceWidth: 600,
                              sourceHeight: 500
                          },
  
                          legend: {
                              layout: 'vertical',
                              borderWidth: 0,
                              backgroundColor: 'rgba(255,255,255,0.85)',
                              floating: true,
                              width:'12px',
                              height:'200px',
                              verticalAlign: 'bottom',
                              y: 0,
                              x: -230,
                          },
  
                          mapNavigation: {
                              enabled: true
                          },
89c9d6ecd   Kuldeep Arora   drilldown map for...
64
                           colorAxis: {
7b21cec8f   Kuldeep Arora   analytical region...
65
66
67
68
69
70
71
72
73
                               min: 1,
                               type: 'logarithmic',
                               minColor: '#2b908f',
                               maxColor: '#000022',
                               stops: [
                                   [0, '#EFEFFF'],
                                   [5, '#f45b5b'],
                                   [10, 'rgb(117,0,0)']
                               ]
89c9d6ecd   Kuldeep Arora   drilldown map for...
74
                           },
7b21cec8f   Kuldeep Arora   analytical region...
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
  
                          series: [{
                              animation: {
                                  duration: 1000
                              },
                              data: result,
                              joinBy: ['postal-code', 'code'],
                              dataLabels: {
                                  enabled: true,
                                  color: '#FFFFFF',
                                  format: '{point.code}'
                              },
                              name: 'Data' ,
                              tooltip: {
                                  pointFormat: '{point.region} : {point.averagePAP}'
                              },
                          }]
                      });
              })
          }
89c9d6ecd   Kuldeep Arora   drilldown map for...
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
           $scope.getAllRegionalPap();*/
  
        
              //Implemented drill down chart and Now used this on  07 Sep 2018 -KD
  
              /*
              TODO:
              - Check data labels after drilling. Label rank? New positions?
              */
              $scope.getAllRegionalPapDrilldown = function() {
                  $scope.flag=true;//for spinner
              var data = Highcharts.geojson(Highcharts.maps['countries/us/us-all']);
               var   separators = Highcharts.geojson(Highcharts.maps['countries/us/us-all'], 'mapline');
                  // Some responsiveness
                   //var small = $('#container').width() < 400;
  
              analyticsService.getAllRPP().then(function(result) {
                      for (var i = 0; i < data.length; i++) {
                          for (var j = 0; j<result.length; j++){
                              if (data[i].name === result[j].region) {
                                  
                                  data[i].value = result[j].averagePAP.toFixed(2);
                             
                              }
                          }      
                          
                      }
  
                      $.each(data, function (i) {
                          this.drilldown = this.properties['hc-key'];
                          this.value = this.value;  
                      });
  
                   $scope.flag=false; 
              // Instantiate the map
              Highcharts.mapChart('container', {
                  chart: {
                      events: {
                          drilldown: function (e) {
                              if (!e.seriesOptions) {
                                  var chart = this,
                                      mapKey = 'countries/us/' + e.point.drilldown + '-all',
                                      
                                      // Handle error, the timeout is cleared on success
                                      fail = setTimeout(function () {
                                          if (!Highcharts.maps[mapKey]) {
                                              chart.showLoading('<i class="icon-frown"></i> Failed loading ' + e.point.name);
                                              fail = setTimeout(function () {
                                                  chart.hideLoading();
                                              }, 1000);
                                          }
                                      }, 3000);
  
                                  // Show the spinner
                                  chart.showLoading('<i class="icon-spinner icon-spin icon-3x"></i>'); // Font Awesome spinner
  
                                  // Load the drilldown map
                                  $.getScript('https://code.highcharts.com/mapdata/' + mapKey + '.js', function () {
  
                                      var region = e.point.name;
                                      //called the get api region wise 
                                     analyticsService.getRPP(region).then(function(result) {
  
                                      data = Highcharts.geojson(Highcharts.maps[mapKey]);
  
                                       for (var i = 0; i < data.length; i++) {
                                            for (var j = 0; j<result.length; j++){
                                              
                                              //delete the County word from api result to match with map data
                                              result[j].region = result[j].region.replace("County","");
  
                                                  if (data[i].name.trim() === result[j].region.trim()) {
                                                         
                                                          data[i].value = result[j].averagePAP.toFixed(2);
                                                  
                                                      } 
                                                  }      
                                                      
                                              }                                      
                                          })
                                               
                                      // Set a non-random bogus value
  
                                      $.each(data, function (i) {
                                          this.value = this.value;                                            
                                      });
  
                                      // Hide loading and add series
                                      chart.hideLoading();
                                      clearTimeout(fail);
                                      chart.addSeriesAsDrilldown(e.point, {
                                          name: e.point.name,
                                          data: data,
                                          dataLabels: {
                                              enabled: true,
                                              format: '{point.name}'
                                          }
                                      });
                                  });
                              }
  
                              this.setTitle(null, { text: e.point.name });
                          },
                          drillup: function () {
                              this.setTitle(null, { text: '' });
                          }
                      }
                  },
  
                  title: {
                      text: 'USA Map-Drilldown for Regional Pricing'
                  },
  
                  subtitle: {
                      text: '',
                      floating: true,
                      align: 'right',
                      y: 50,
                      style: {
                          fontSize: '16px'
                      }
                  },
  
                 /* legend: small ? {} : {
                      layout: 'vertical',
                      align: 'right',
                      verticalAlign: 'middle'
                  },
  
                  colorAxis: {
                      min: 0,
                      minColor: '#E6E7E8',
                      maxColor: '#005645'
                  },*/
  
                  mapNavigation: {
                      enabled: true,
                      buttonOptions: {
                          verticalAlign: 'bottom'
                      }
                  },
  
                  plotOptions: {
                      map: {
                          states: {
                              hover: {
                                  color: '#EEDD66'
                              }
                          }
                      }
                  },
  
                  series: [{
                      data: data,
                      name: 'USA',
                      dataLabels: {
                          enabled: true,
                          format: '{point.properties.postal-code}'
                      }
                  }, {
                      type: 'mapline',
                      data: separators,
                      color: 'silver',
                      enableMouseTracking: false,
                      animation: {
                          duration: 500
                      }
                  }],
  
                  drilldown: {
                      activeDataLabelStyle: {
                          color: '#FFFFFF',
                          textDecoration: 'none',
                          textOutline: '1px #000000'
                      },
                      drillUpButton: {
                          relativeTo: 'spacingBox',
                          position: {
                              x: 0,
                              y: 60
                          }
                      }
                  }
              });
          })
      }
  
      $scope.getAllRegionalPapDrilldown();
7b21cec8f   Kuldeep Arora   analytical region...
283
284
          
          /*$(document).ready(function() {
d20181a2e   Anchit Jindal   fixed bugs
285
              $(function() {
d20181a2e   Anchit Jindal   fixed bugs
286
                  jQuery('#map').vectorMap({
1b71872b2   Kuldeep Arora   email and code be...
287
288
                      map: 'us_lcc',
                      backgroundColor: '#ffce99',
d20181a2e   Anchit Jindal   fixed bugs
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
                      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
304
              });
89c9d6ecd   Kuldeep Arora   drilldown map for...
305
          })
7b21cec8f   Kuldeep Arora   analytical region...
306

bd3a040f8   Kuldeep Arora   Regional Pap pric...
307

d20181a2e   Anchit Jindal   fixed bugs
308
309
310
          function getRegionPap(code) {
              $scope.showLoader = true;
              analyticsService.getRPP(code).then(function(result) {
f6e8207e4   Kuldeep Arora   charts
311
312
313
                  $scope.rppData = result;
                  $scope.showLoader = false;
                  $('#popup1').css('display', 'block');
d20181a2e   Anchit Jindal   fixed bugs
314
              })
89c9d6ecd   Kuldeep Arora   drilldown map for...
315
          }*/
7b21cec8f   Kuldeep Arora   analytical region...
316

89c9d6ecd   Kuldeep Arora   drilldown map for...
317
           
d20181a2e   Anchit Jindal   fixed bugs
318
          $scope.cancelStatus = function() {
bd3a040f8   Kuldeep Arora   Regional Pap pric...
319
              $('#popup1').css('display', 'none');
d20181a2e   Anchit Jindal   fixed bugs
320
321
322
323
324
          }
          $scope.ordersCost = 0;
          $scope.ordersCount = 0;
  
          $scope.orderCostAndCount = function() {
f6e8207e4   Kuldeep Arora   charts
325
326
              analyticsService.orderCostAndCount().then(function(result) {
                  $scope.ordersCost = result.cost;
d20181a2e   Anchit Jindal   fixed bugs
327
                  $scope.ordersCount = result.count;
f6e8207e4   Kuldeep Arora   charts
328
              })
d20181a2e   Anchit Jindal   fixed bugs
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
          }
  
          $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,
fcb9c5ee6   Kuldeep Arora   monthly fuel char...
344
                          reduceXTicks: false,
d20181a2e   Anchit Jindal   fixed bugs
345
346
347
348
349
350
351
352
353
354
                          margin: {
                              top: 45,
                              right: 20,
                              bottom: 45,
                              left: 45
                          },
                          clipEdge: true,
                          //staggerLabels: true,
                          duration: 500,
                          stacked: false,
d1e8d9afb   Kuldeep Arora   fuel order & home...
355
356
                          /*color: ["#FEDFC3", "#990000", "#000099", "#009900"],*/
                          color: ["#A9A9A9", "#000099", "#990000", "#009900"],
d20181a2e   Anchit Jindal   fixed bugs
357
358
359
360
361
362
363
364
365
366
367
                          xAxis: {
                              axisLabel: 'Months',
                              showMaxMin: false,
                          },
                          yAxis: {
                              axisLabel: 'Orders',
                              axisLabelDistance: -20,
                              tickFormat: function(d) {
                                  return d3.format(',.1f')(d);
                              }
                          }
fcb9c5ee6   Kuldeep Arora   monthly fuel char...
368
                              
d20181a2e   Anchit Jindal   fixed bugs
369
370
371
372
373
374
375
376
377
378
379
380
                      }
                  };
                  $scope.datamfs = $scope.mfsValues;
              })
          }
  
          $scope.orderCostAndCount();
          $scope.getMFS();
          $scope.csValues = [];
          $scope.getCS = function() {
              //var makeId = makeId;
              analyticsService.getCS().then(function(result) {
039002959   Kuldeep Arora   minor change
381
                  //console.log("===customersupports===",result)
d20181a2e   Anchit Jindal   fixed bugs
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
                  $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...
414
          }
d20181a2e   Anchit Jindal   fixed bugs
415
          $scope.getCS();
bb09cc25d   Kuldeep Arora   historic fuel cha...
416
417
418
419
420
421
422
423
424
425
426
  
  
          $scope.hfpValuesOne = {};
          $scope.hfpValuesOne.key = "JET-A Full Service";
          $scope.hfpValuesOne.values = [];
  
          $scope.hfpValuesTwo = {};
          $scope.hfpValuesTwo.key = "100LL Full Service";
          $scope.hfpValuesTwo.values = [];
  
          $scope.hfpFinalData = [];
cefbd3ffa   Anchit Jindal   email related issues
427
          
cefbd3ffa   Anchit Jindal   email related issues
428
          $scope.getHfpChartData = function() {
cefbd3ffa   Anchit Jindal   email related issues
429
              analyticsService.gethfpChart().then(function(result) {
bb09cc25d   Kuldeep Arora   historic fuel cha...
430
431
432
433
                  for(var i=0; i<result.length; i++) {
                      if(result[i].includes("JET-A Full Service") ){
                          let datePusha = result[i][0];
                          let tempValue = result[i][1].toFixed(2);
039002959   Kuldeep Arora   minor change
434
                          let valePusha = parseFloat(tempValue);
bb09cc25d   Kuldeep Arora   historic fuel cha...
435
436
437
438
                          $scope.hfpValuesOne.values.push([datePusha, valePusha])
                      }else if(result[i].includes("100LL Full Service") ) {
                          let datePushb = result[i][0];
                          let tempvalePushb = result[i][1].toFixed(2);
039002959   Kuldeep Arora   minor change
439
                          let valePushb = parseFloat(tempvalePushb);
bb09cc25d   Kuldeep Arora   historic fuel cha...
440
                          $scope.hfpValuesTwo.values.push([datePushb, valePushb])
cefbd3ffa   Anchit Jindal   email related issues
441
                      }
a9aef0b1c   Anchit Jindal   new changes imple...
442
                  }
bb09cc25d   Kuldeep Arora   historic fuel cha...
443
                  $scope.hfpFinalData.push($scope.hfpValuesOne, $scope.hfpValuesTwo);
039002959   Kuldeep Arora   minor change
444
                //  console.log('$scope.hfpFinalData', $scope.hfpFinalData);
bb09cc25d   Kuldeep Arora   historic fuel cha...
445
446
447
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
  
                       var chart = nv.models.lineChart()
                              .x(function(d) { return d[0] })
                              //adjusting, 100% is 1.00, not 100 as it is in the data
                              .y(function(d) { return d[1]})
                              .color(d3.scale.category10().range())
                              .useInteractiveGuideline(true)
                              ;
  
                            chart.xAxis
                              .tickFormat(function(d) {
                                return d3.time.format('%x')(new Date(d))
                              });
  
                            chart.yAxis
                            .axisLabel("PaP / Retail Price")
                            .axisLabelDistance(-5)
                            .tickFormat(d3.format(',.2f')).showMaxMin(false);
  
                            d3.select('#chart svg')
                              .datum($scope.hfpFinalData)
                              .transition().duration(500)
                              .call(chart)
                              ;
  
                            nv.utils.windowResize(chart.update);
  
                            return chart;
                  });
6c5a99488   Kuldeep Arora   analytics and fue...
474
          }
6c5a99488   Kuldeep Arora   analytics and fue...
475
          $scope.getHfpChartData();
bb09cc25d   Kuldeep Arora   historic fuel cha...
476
477
478
479
480
481
482
483
484
485
486
487
488
489
          /*Date Range Filter for Historic fuel Price*/
          $scope.submitDateHfp = function() {
  
          $scope.hfpValuesFirst = {};
          $scope.hfpValuesFirst.key = "JET-A Full Service";
          $scope.hfpValuesFirst.values = [];
  
          $scope.hfpValuesSecond = {};
          $scope.hfpValuesSecond.key = "100LL Full Service";
          $scope.hfpValuesSecond.values = [];
  
          $scope.hfpRangeData = [];
  
              if ($scope.hfp.fromDate === undefined) {
d121d5539   Kuldeep Arora   UI Changes
490

d20181a2e   Anchit Jindal   fixed bugs
491
                  $scope.fillForm = true;
bb09cc25d   Kuldeep Arora   historic fuel cha...
492
              } else if ($scope.hfp.fromDate != undefined && $scope.hfp.toDate === undefined || $scope.hfp.toDate === '') {
d20181a2e   Anchit Jindal   fixed bugs
493
494
                  $scope.fillForm = false;
                  var today = new Date();
039002959   Kuldeep Arora   minor change
495
                  var DefaultToDate = today.getFullYear() + '-' + ("0" + (today.getMonth() + 1)).slice(-2) + '-' + ("0" + today.getDate()).slice(-2) + " " + '23:59:59';
d20181a2e   Anchit Jindal   fixed bugs
496
                  //from date format                  
bb09cc25d   Kuldeep Arora   historic fuel cha...
497
                  $scope.dat1 = $scope.hfp.fromDate;
d20181a2e   Anchit Jindal   fixed bugs
498
499
500
501
502
                  $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("-");
039002959   Kuldeep Arora   minor change
503
                 // console.log("===date====",$scope.fd,"===dad====",DefaultToDate)
bb09cc25d   Kuldeep Arora   historic fuel cha...
504
505
506
507
508
509
                  analyticsService.getDRFHfpChart($scope.fd, DefaultToDate).then(function(result) {
                    //  console.log("===date range===",$scope.fd,DefaultToDate)
                      for(var i=0; i<result.length; i++) {
                      if(result[i].includes("JET-A Full Service") ){
                          let datePusha = result[i][0];
                          let tempValue = result[i][1].toFixed(2);
039002959   Kuldeep Arora   minor change
510
                          let valePusha = parseFloat(tempValue);
bb09cc25d   Kuldeep Arora   historic fuel cha...
511
512
513
514
                          $scope.hfpValuesFirst.values.push([datePusha, valePusha])
                      }else if(result[i].includes("100LL Full Service") ) {
                          let datePushb = result[i][0];
                          let tempvalePushb = result[i][1].toFixed(2);
039002959   Kuldeep Arora   minor change
515
                          let valePushb = parseFloat(tempvalePushb);
bb09cc25d   Kuldeep Arora   historic fuel cha...
516
517
518
519
                          $scope.hfpValuesSecond.values.push([datePushb, valePushb])
                      }
                  }
                  $scope.hfpRangeData.push($scope.hfpValuesFirst, $scope.hfpValuesSecond);
039002959   Kuldeep Arora   minor change
520
                  //console.log('$scope.hfpRangeData', $scope.hfpRangeData);
bb09cc25d   Kuldeep Arora   historic fuel cha...
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
  
                       var chart = nv.models.lineChart()
                              .x(function(d) { if(d.length >0){return d[0]}})
                              //adjusting, 100% is 1.00, not 100 as it is in the data
                              .y(function(d) { return d[1]})
                              .color(d3.scale.category10().range())
                              .useInteractiveGuideline(true)
                              ;
  
                            chart.xAxis
                              .tickFormat(function(d) {
                                return d3.time.format('%x')(new Date(d))
                              });
  
                            chart.yAxis
                            .axisLabel("PaP / Retail Price")
                            .axisLabelDistance(-5)
                            .tickFormat(d3.format(',.2f')).showMaxMin(false);
  
                            d3.select('#chart svg')
                              .datum($scope.hfpRangeData)
                              .transition().duration(500)
                              .call(chart)
                              ;
  
                            nv.utils.windowResize(chart.update);
  
                            return chart;
f6e8207e4   Kuldeep Arora   charts
549
                  })
bb09cc25d   Kuldeep Arora   historic fuel cha...
550
551
552
  
  
              } else if ($scope.hfp.fromDate != undefined && $scope.hfp.toDate != undefined) {
d20181a2e   Anchit Jindal   fixed bugs
553
554
                  $scope.fillForm = false;
                  //from date format
bb09cc25d   Kuldeep Arora   historic fuel cha...
555
                  $scope.dat1 = $scope.hfp.fromDate;
d20181a2e   Anchit Jindal   fixed bugs
556
557
558
559
560
                  $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("-");
bb09cc25d   Kuldeep Arora   historic fuel cha...
561
562
                  //to date format
                  $scope.dat2 = $scope.hfp.toDate;
d20181a2e   Anchit Jindal   fixed bugs
563
564
565
566
                  $scope.td1 = $scope.dat2.split("/").reverse();
                  $scope.tmp1 = $scope.td1[2];
                  $scope.td1[2] = $scope.td1[1];
                  $scope.td1[1] = $scope.tmp1;
039002959   Kuldeep Arora   minor change
567
568
                  $scope.td = $scope.td1.join("-") + " " + '23:59:59';
                 // console.log("===both dates==",$scope.td)
bb09cc25d   Kuldeep Arora   historic fuel cha...
569
570
571
572
573
574
                  analyticsService.getDRFHfpChart($scope.fd, $scope.td).then(function(result) {
                      //console.log("===date range22===",result);
                      for(var i=0; i<result.length; i++) {
                      if(result[i].includes("JET-A Full Service") ){
                          let datePusha = result[i][0];
                          let tempValue = result[i][1].toFixed(2);
039002959   Kuldeep Arora   minor change
575
                          let valePusha = parseFloat(tempValue);
bb09cc25d   Kuldeep Arora   historic fuel cha...
576
577
578
579
                          $scope.hfpValuesFirst.values.push([datePusha, valePusha])
                      }else if(result[i].includes("100LL Full Service") ) {
                          let datePushb = result[i][0];
                          let tempvalePushb = result[i][1].toFixed(2);
039002959   Kuldeep Arora   minor change
580
                          let valePushb = parseFloat(tempvalePushb);
bb09cc25d   Kuldeep Arora   historic fuel cha...
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
                          $scope.hfpValuesSecond.values.push([datePushb, valePushb])
                      }
                  }
                  $scope.hfpRangeData.push($scope.hfpValuesFirst, $scope.hfpValuesSecond);
                 // console.log('$scope.hfpRangeData', $scope.hfpRangeData);
  
                       var chart = nv.models.lineChart()
                              .x(function(d) { if(d.length >0){return d[0] }})
                              //adjusting, 100% is 1.00, not 100 as it is in the data
                              .y(function(d) { return d[1]})
                              .color(d3.scale.category10().range())
                              .useInteractiveGuideline(true)
                              ;
  
                            chart.xAxis
                              .tickFormat(function(d) {
                                return d3.time.format('%x')(new Date(d))
                              });
  
                            chart.yAxis
                            .axisLabel("PaP / Retail Price")
                            .axisLabelDistance(-5)
                            .tickFormat(d3.format(',.2f')).showMaxMin(false);
  
                            d3.select('#chart svg')
                              .datum($scope.hfpRangeData)
                              .transition().duration(500)
                              .call(chart)
                              ;
  
                            nv.utils.windowResize(chart.update);
  
                            return chart;
f6e8207e4   Kuldeep Arora   charts
614
                  })
d20181a2e   Anchit Jindal   fixed bugs
615
616
617
  
              } else {
                  $scope.fillForm = true;
565570086   Kuldeep Arora   highcharts(MFS,CS...
618
              }
d20181a2e   Anchit Jindal   fixed bugs
619

565570086   Kuldeep Arora   highcharts(MFS,CS...
620
          }
bb09cc25d   Kuldeep Arora   historic fuel cha...
621
622
623
624
         
          /*Date Range Filter for Monthly fuel Sales*/
          $scope.submitDate = function() {
              if ($scope.drf.fromDate === undefined) {
d20181a2e   Anchit Jindal   fixed bugs
625
                  $scope.fillForm = true;
bb09cc25d   Kuldeep Arora   historic fuel cha...
626
              } else if ($scope.drf.fromDate != undefined && $scope.drf.toDate === undefined || $scope.drf.toDate === '') {
d20181a2e   Anchit Jindal   fixed bugs
627
628
629
630
                  $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                  
bb09cc25d   Kuldeep Arora   historic fuel cha...
631
                  $scope.dat1 = $scope.drf.fromDate;
d20181a2e   Anchit Jindal   fixed bugs
632
633
634
635
636
                  $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("-");
bb09cc25d   Kuldeep Arora   historic fuel cha...
637
638
639
                  analyticsService.getDRFChart($scope.fd, DefaultToDate).then(function(result) {
                      $scope.datamfs = [];
                      $scope.datamfs = result;
d20181a2e   Anchit Jindal   fixed bugs
640
                  })
bb09cc25d   Kuldeep Arora   historic fuel cha...
641
642
643
644
645
646
                  
                  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) {
d20181a2e   Anchit Jindal   fixed bugs
647
648
                  $scope.fillForm = false;
                  //from date format
bb09cc25d   Kuldeep Arora   historic fuel cha...
649
                  $scope.dat1 = $scope.drf.fromDate;
d20181a2e   Anchit Jindal   fixed bugs
650
651
652
653
654
                  $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("-");
bb09cc25d   Kuldeep Arora   historic fuel cha...
655
                  $scope.dat2 = $scope.drf.toDate;
d20181a2e   Anchit Jindal   fixed bugs
656
657
658
659
660
                  $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("-");
bb09cc25d   Kuldeep Arora   historic fuel cha...
661
662
663
664
665
666
667
668
                  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;
d20181a2e   Anchit Jindal   fixed bugs
669
670
671
672
                  })
  
              } else {
                  $scope.fillForm = true;
75d1c3d9f   Kuldeep Arora   analytics DRF UI
673
              }
d20181a2e   Anchit Jindal   fixed bugs
674

75d1c3d9f   Kuldeep Arora   analytics DRF UI
675
          }
bb09cc25d   Kuldeep Arora   historic fuel cha...
676
677
          
          
d20181a2e   Anchit Jindal   fixed bugs
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
          /*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
721
                                  }
d20181a2e   Anchit Jindal   fixed bugs
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
                              }
                          }
                      };
                      $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
773
                                  }
d20181a2e   Anchit Jindal   fixed bugs
774
775
776
777
778
779
780
781
                              }
                          }
                      };
                      $scope.datacs = $scope.csValues;
                  })
  
              } else {
                  $scope.fillForm = true;
75d1c3d9f   Kuldeep Arora   analytics DRF UI
782
              }
75d1c3d9f   Kuldeep Arora   analytics DRF UI
783

d20181a2e   Anchit Jindal   fixed bugs
784
          }
75d1c3d9f   Kuldeep Arora   analytics DRF UI
785

feacde5ff   Rishav   setup acuefuel in...
786

d20181a2e   Anchit Jindal   fixed bugs
787
      }]);