Blame view

app/partials/fuelOrders/fuelOrders.controller.js 17.5 KB
4bb02bb84   Rishav   new integration w...
1
  'use strict';
6284a85b9   Jaideep Singh   fuel orders page ...
2
3
4
5
6
7
8
9
  angular.module('acufuel')
  
  .controller('fuelOrdersController', ['$scope', '$rootScope', '$uibModal', '$filter', '$http', 'NgTableParams','fuelOrdersService', fuelOrdersController]);
  
  function fuelOrdersController($scope, $rootScope, $uibModal, $filter, $http, NgTableParams,fuelOrdersService) {
  
      $scope.showFuelOrderModal = false;
      $scope.optionSelected;
64e7e5f50   Mr. Hot Foods   view upload delet...
10
      $scope.orderdata = {}
9aae3d136   Mr. Hot Foods   show loaders and ...
11
      $scope.showLoader = false;
6284a85b9   Jaideep Singh   fuel orders page ...
12
13
  
       $scope.data = {};
8d682e773   Mr. Hot Foods   changes in fuel o...
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
       $scope.order = {};
       $scope.dispatchOrder = {};
    	$scope.dispatchOrder.fuelOrderList = [];
  
      $scope.statusFilterOptions = [];
      $scope.statusFilterOptions.push({
  		  	'id': '', 'title': 'Show All'
  		  },{
  		  	'id': 'pending', 'title': 'Pending'
  		  },{
  		  	'id': 'invoiced', 'title': 'Invoiced'
  		  },{
  		  	'id': 'paid', 'title': 'Paid'
  		  },{
  		  	'id': 'cancelled', 'title': 'Cancelled'
  		  },{
  		  	'id': 'archived', 'title': 'Archived'
  		  }
       
        );
5a7920053   Swarn Singh   selectbox color i...
34
35
36
37
38
39
40
41
42
43
44
      function colourFunction() {
        var myselect = document.getElementById('colorfulSelectbox'),
        colour = myselect.options[myselect.selectedIndex].className;
        myselect.style.background = colour;
        console.log('colour', myselect);
        myselect.blur();
      }
  
      //setInterval(function(){
       // colourFunction();
      //}, 1)
8d682e773   Mr. Hot Foods   changes in fuel o...
45
46
47
48
49
50
51
52
53
54
  
        $scope.attachmentFilterOptions = [];
      $scope.attachmentFilterOptions.push({
  		  	'id': '', 'title': 'Show All'
  		  },{
  		  	'id': '!null', 'title': 'Attachments'
  		  },{
  		  	'id': 'null', 'title': 'No Attachments'
  		  }
       );
9aae3d136   Mr. Hot Foods   show loaders and ...
55

f100849ce   Mr. Hot Foods   analytics updates
56
57
58
59
60
        //  $(document).ready(function() {
        //     $scope.showLoader = true;
        //       $('#example').DataTable();
        //       $scope.showLoader = false;
        //   });
6284a85b9   Jaideep Singh   fuel orders page ...
61
       
8d682e773   Mr. Hot Foods   changes in fuel o...
62
       $scope.getOrders = function() {
6284a85b9   Jaideep Singh   fuel orders page ...
63
            fuelOrdersService.getOrders().then(function(result) {
9aae3d136   Mr. Hot Foods   show loaders and ...
64
             
6284a85b9   Jaideep Singh   fuel orders page ...
65
66
              $scope.orderdata = result;
              for(var i=0;i<$scope.orderdata.length;i++){
8d682e773   Mr. Hot Foods   changes in fuel o...
67
                  $scope.orderdata[i].upliftDateS = new Date($scope.orderdata[i].upliftDate);
6284a85b9   Jaideep Singh   fuel orders page ...
68

8d682e773   Mr. Hot Foods   changes in fuel o...
69
70
71
                   var str = "" + $scope.orderdata[i].upliftDateS.getDate() + "/" + ($scope.orderdata[i].upliftDateS.getMonth() + 1) + "/" + $scope.orderdata[i].upliftDateS.getFullYear()
                  //  str = str.slice(4,16)
                  $scope.orderdata[i].upliftDateString = str
6284a85b9   Jaideep Singh   fuel orders page ...
72
73
74
75
76
77
78
79
80
81
                  console.log(str);
  
              }
             
               $scope.displayFuelOrderList = new NgTableParams({
                page: 1,
                count: 10,
              }, {
                data: $scope.orderdata
              });
5a7920053   Swarn Singh   selectbox color i...
82
83
84
85
86
87
88
89
90
91
92
93
94
95
              $(document).ready(function(){
                var myselect = document.getElementsByClassName('colorfulSelectbox');
  
                for (var i = 0; i < myselect.length; i++) {
                  var colourIndex = $(myselect[i]).prop('selectedIndex');
                  colourIndex = colourIndex + 1;
                  console.log(colourIndex);
                  var getColor = $('.colorfulSelectbox option:nth-child('+colourIndex+')').css('color');
                  $(myselect[i]).css('background-color', getColor);
                  console.log('colour', getColor);
                  myselect[i].blur();
                }
  
              })
9aae3d136   Mr. Hot Foods   show loaders and ...
96
             
6284a85b9   Jaideep Singh   fuel orders page ...
97
            })
8d682e773   Mr. Hot Foods   changes in fuel o...
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
       }
       
       $scope.getOrders();
       
       $scope.onFWSelect = function() {
                          if($scope.optionSelected == 'dt'){
                          $('#demo-modal-4').css('display', 'block');
                        }
                        if($scope.optionSelected == 'efo'){
                          	$scope.showLoader = true;
                              var fileName = "orders.csv";
                              var a = document.createElement("a");
                              document.body.appendChild(a);
                              fuelOrdersService.exportCompany().then(function(result) {
                                    var file = new Blob([result], {type: 'application/csv'});
                                    var fileURL = URL.createObjectURL(file);
                                    a.href = fileURL;
                                    a.download = fileName;
                                    a.click();
                                    $scope.showLoader = false;
                              })
                          }
                      }
64e7e5f50   Mr. Hot Foods   view upload delet...
121
122
123
124
     $scope.attachmentrowid = ""
  
     
     $scope.attachment = function(id, value, url) {
8d682e773   Mr. Hot Foods   changes in fuel o...
125
126
127
128
129
130
131
132
133
134
135
136
                              console.log(id, value)
                              $scope.attachmentrowid = id
                              //  $scope.attachmentdeleteid = attachdeleteid
                              if(value == 'uploadAttachment'){
                              $('#demo-modal-6').css('display', 'block');
                              }else if(value == 'viewAttachment'){
                              var win = window.open(url, '_blank');
                              win.focus();
                              }else if(value == 'deleteAttachment'){
                              $('#delete1').css('display', 'block');
                              }
                          }
dd378d69f   Mr. Hot Foods   changes in flight...
137

c277275bb   Mr. Hot Foods   login changes
138
    $scope.cancelDeleteAttachment = function() {
8d682e773   Mr. Hot Foods   changes in fuel o...
139
140
                              $('#delete1').css('display', '');
                        }
c277275bb   Mr. Hot Foods   login changes
141
142
  
    $scope.deleteAttachment = function() {
8d682e773   Mr. Hot Foods   changes in fuel o...
143
144
145
146
147
148
149
150
151
152
153
154
155
                              $scope.showLoader = true;
                              fuelOrdersService.deleteAttachment($scope.attachmentrowid).then(function(result) {
                                      console.log(result, $scope.attachmentrowid)
  
                                      if(result.success){
                                      toastr.success(''+result.success+'', {
                                                closeButton: true
                                            })
                                      }
                                  })
                                  $scope.showLoader = false;
                                  $('#delete1').css('display', '');
                            }
c277275bb   Mr. Hot Foods   login changes
156

dd378d69f   Mr. Hot Foods   changes in flight...
157
     $scope.saveUploadAttachment = function(attachmentData) {
9aae3d136   Mr. Hot Foods   show loaders and ...
158
       $scope.showLoader = true;
38628e5f5   Anchit Jindal   minor changes
159
  	   	$scope.data.media = attachmentData
64e7e5f50   Mr. Hot Foods   view upload delet...
160
  	   	$scope.data.id = $scope.attachmentrowid
38628e5f5   Anchit Jindal   minor changes
161
  		fuelOrdersService.uploadAttachment($scope.data).then(function(result) {
8d682e773   Mr. Hot Foods   changes in fuel o...
162
163
164
165
166
167
168
169
170
171
172
173
                                      console.log(result)
                                      if(result){
                                        // console.log(result.success)
                                            toastr.success(''+"Upload Successful"+'', {
                                                      closeButton: true
                                                  })
                                            }
                                            
                                      })
                                        $scope.showLoader = false;
                                        $('#demo-modal-6').css('display', 'none');
                                  }
dd378d69f   Mr. Hot Foods   changes in flight...
174
175
  
    $scope.cancelUploadAttachment = function() {
8d682e773   Mr. Hot Foods   changes in fuel o...
176
177
                                  $('#demo-modal-6').css('display', 'none');
                            }
6284a85b9   Jaideep Singh   fuel orders page ...
178

dd378d69f   Mr. Hot Foods   changes in flight...
179
    $scope.editdata = {};
8d682e773   Mr. Hot Foods   changes in fuel o...
180
    
6284a85b9   Jaideep Singh   fuel orders page ...
181
    $scope.editTableRow = function(rowData){
8d682e773   Mr. Hot Foods   changes in fuel o...
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
                          console.log('row data', rowData);
                          $scope.editdata = rowData;
                          $('#demo-modal-5').css('display', 'block');
                        }
  
    $scope.updateTotal = function(value, valueOf){
                          if(valueOf == 'v'){
                            $scope.editdata.total = value * $scope.editdata.invoiced
                          }else if(valueOf == 'i'){
                            $scope.editdata.total = $scope.editdata.requestedVolume * value 
                          }
                        }
  
    $scope.addTotal = function(value, valueOf){
                          if(valueOf == 'v'){
                            $scope.order.total = value * $scope.order.invoiced
                          }else if(valueOf == 'i'){
                            $scope.order.total = $scope.order.volume * value 
                          }
                        }                    
  
     $scope.addData = function() {
                            $scope.showLoader = true;
  
                           if ($scope.order.upliftDate != '') {
                                $scope.order.upliftDate = new Date($scope.order.upliftDate);
                                $scope.order.upliftDate = $scope.order.upliftDate.getTime();
                              }
                              if ($scope.order.departingDate != '') {
                                $scope.order.departingDate = new Date($scope.order.departingDate);
                                $scope.order.departingDate = $scope.order.departingDate.getTime();
                              }
                              console.log($scope.order.quotePrice);
                              var obj =JSON.parse($scope.order.priceQuote);
                              console.log('obj.papMargin',obj.papMargin);
                              $scope.order.priceQuote = obj.papMargin;
  
                             $scope.fuelData = {};
                            $scope.fuelData.aircraftName = $scope.order.aircraftName 
                            $scope.fuelData.companyName = $scope.order.companyName 
                            $scope.fuelData.departingDate = $scope.order.departingDate 
                            $scope.fuelData.fboCost = $scope.order.fboCost 
                            $scope.fuelData.id = $scope.order.id 
                            $scope.fuelData.invoiced = $scope.order.invoiced 
                            $scope.fuelData.priceQuote = $scope.order.priceQuote 
                            $scope.fuelData.volume = $scope.order.volume 
                            $scope.fuelData.source = $scope.order.source 
                            $scope.fuelData.status = $scope.order.status 
                            $scope.fuelData.tierBreak = $scope.order.tierBreak 
                            $scope.fuelData.total = $scope.order.total 
                            $scope.fuelData.upliftDate = $scope.order.upliftDate 
                            $scope.fuelData.companyId = $scope.selectedCompanyId;
                                
                                
                                
                                $scope.dispatchOrder.fuelOrderList.push($scope.fuelData);
                                console.log('$scope.order', $scope.dispatchOrder);
                                fuelOrdersService.dispathFuelOrder($scope.dispatchOrder).then(function(result) {
                                  console.log('result', result);
                                  $scope.showLoader = false;
                                  $scope.order = {};
                                  $('#demo-modal-4').css('display', '');
                                  $scope.getOrders();
                                  toastr.success('Fuel Order Dispatched Successfully', {
                                          closeButton: true
                                        })
                                })
                                
                              }
      $scope.updateStatus = function(row, status) {
5a7920053   Swarn Singh   selectbox color i...
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
        $scope.showLoader = true;
        $scope.fuelData = {};
        $scope.fuelData.aircraftName = row.aircraftName 
        $scope.fuelData.companyName = row.companyName 
        $scope.fuelData.departingDate = row.departingDate 
        $scope.fuelData.fboCost = row.fboCost 
        $scope.fuelData.id = row.id 
        $scope.fuelData.invoiced = row.invoiced 
        $scope.fuelData.priceQuote = row.priceQuote 
        $scope.fuelData.volume = row.requestedVolume 
        $scope.fuelData.source = row.source 
        $scope.fuelData.status = status 
        $scope.fuelData.tierBreak = row.tierBreak 
        $scope.fuelData.total = row.total 
        $scope.fuelData.upliftDate = row.upliftDate 
8d682e773   Mr. Hot Foods   changes in fuel o...
267

5a7920053   Swarn Singh   selectbox color i...
268
269
270
271
272
273
274
275
276
277
278
        $scope.dispatchOrder.fuelOrderList.push($scope.fuelData);
        fuelOrdersService.updateFuelOrder($scope.dispatchOrder).then(function(result) {
          console.log('result', result);
          $scope.showLoader = false;
          $scope.editdata = {};
          $('#demo-modal-5').css('display', '');
          $scope.getOrders();
          toastr.success('Fuel Order Updated Successfully', {
            closeButton: true
          });
      })
8d682e773   Mr. Hot Foods   changes in fuel o...
279

5a7920053   Swarn Singh   selectbox color i...
280
    }
8d682e773   Mr. Hot Foods   changes in fuel o...
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
  
        $scope.updateData = function() {
                            $scope.showLoader = true;
                            $scope.fuelData = {};
                            $scope.fuelData.aircraftName = $scope.editdata.aircraftName 
                            $scope.fuelData.companyName = $scope.editdata.companyName 
                            $scope.fuelData.departingDate = $scope.editdata.departingDate 
                            $scope.fuelData.fboCost = $scope.editdata.fboCost 
                            $scope.fuelData.id = $scope.editdata.id 
                            $scope.fuelData.invoiced = $scope.editdata.invoiced 
                            $scope.fuelData.priceQuote = $scope.editdata.priceQuote 
                            $scope.fuelData.volume = $scope.editdata.requestedVolume 
                            $scope.fuelData.source = $scope.editdata.source 
                            $scope.fuelData.status = $scope.editdata.status 
                            $scope.fuelData.tierBreak = $scope.editdata.tierBreak 
                            $scope.fuelData.total = $scope.editdata.total 
                            $scope.fuelData.upliftDate = $scope.editdata.upliftDate 
                            
  
  
                               $scope.dispatchOrder.fuelOrderList.push($scope.fuelData);
                                fuelOrdersService.updateFuelOrder($scope.dispatchOrder).then(function(result) {
                                  console.log('result', result);
                                  $scope.showLoader = false;
                                  $scope.editdata = {};
                                  $('#demo-modal-5').css('display', '');
                                  $scope.getOrders();
                                  toastr.success('Fuel Order Updated Successfully', {
                                          closeButton: true
                                        })
                                })
                              }
  
      $scope.getAircraft = function(company){
                                $scope.selectedCompanyName = company;
                                $scope.showLoader = true;
                                for (var i = 0; i < $scope.companyList.length; i++) {
                                  if ($scope.companyList[i].companyName == company) {
                                    if($scope.companyList[i].margin != null && $scope.companyList[i].marginAVGAS != null){
                                      fuelOrdersService.getFuelCost($scope.companyList[i].id).then(function(margins) {
                                        $scope.marginList = margins;
                                        //console.log('$scope.marginList', $scope.marginList);
                                      })
                                    } else if ($scope.companyList[i].margin != null || $scope.companyList[i].marginAVGAS == null) {
                                      fuelOrdersService.getATypeFuelPricing($scope.companyList[i].id).then(function(margins) {
                                        $scope.marginList = margins;
                                          })
                                    } else if ($scope.companyList[i].margin == null || $scope.companyList[i].marginAVGAS != null) {
                                      fuelOrdersService.getVTypeFuelPricing($scope.companyList[i].id).then(function(margins) {
                                            $scope.marginList = margins;
                                          })
                                    }
                                    $scope.selectedCompanyId = $scope.companyList[i].id;
                                    $scope.marginId = $scope.companyList[i].margin.id;
                                    if ($scope.selectedCompanyId != '') {
                                      fuelOrdersService.getAircraft($scope.selectedCompanyId).then(function(aircraft) {
                                        $scope.aircraftList = aircraft;
                                      })
                                    }
                                    if ($scope.marginId != '') {
                                      fuelOrdersService.getJetTiers($scope.marginId).then(function(tiers) {
                                                $scope.tierList = tiers;
                                                $scope.showLoader = false;
                                            })
                                    }else{
                                      $scope.showLoader = false;
                                    }
                                  }
                                }
  
                              }
       $scope.setCost = function(cost){
                                console.log(cost);
                                if(cost != null) {
                                  var obj =JSON.parse(cost);
                                  $scope.order.fboCost = obj.cost;
                                }
                                  
                              }
                              
6284a85b9   Jaideep Singh   fuel orders page ...
361
362
  
    $scope.cancelData = function() {
8d682e773   Mr. Hot Foods   changes in fuel o...
363
364
                              $('#demo-modal-4').css('display', '');
                        }
6284a85b9   Jaideep Singh   fuel orders page ...
365
    $scope.canceleditdata = function() {
8d682e773   Mr. Hot Foods   changes in fuel o...
366
367
                                $('#demo-modal-5').css('display', '');
                          }
6284a85b9   Jaideep Singh   fuel orders page ...
368

dd378d69f   Mr. Hot Foods   changes in flight...
369
   
6284a85b9   Jaideep Singh   fuel orders page ...
370
371
372
  	$scope.companyList = {};
  
  	fuelOrdersService.getAllCompanies().then(function(result) {
8d682e773   Mr. Hot Foods   changes in fuel o...
373
374
375
376
377
                                    $scope.showLoader = true;
                                    $scope.companyList = result;
                                    console.log(result)
                                    $scope.showLoader = false;
                                  })
4bb02bb84   Rishav   new integration w...
378

6284a85b9   Jaideep Singh   fuel orders page ...
379
    $scope.sourceList = [{source:"Direct Jet-A"},{source:"Direct AVGAS 100LL"}];
4bb02bb84   Rishav   new integration w...
380

6284a85b9   Jaideep Singh   fuel orders page ...
381
382
383
    $scope.data = {};
    
   
4bb02bb84   Rishav   new integration w...
384

6284a85b9   Jaideep Singh   fuel orders page ...
385
     }