Blame view

app/partials/viewCompany/viewCompany.controller.js 44.5 KB
feacde5ff   Rishav   setup acuefuel in...
1
  'use strict';
5983d987a   Kuldeep Arora   jetmargin api
2
3
  //Load controller
  angular.module('acufuel')
feacde5ff   Rishav   setup acuefuel in...
4

9d840540f   Anchit Jindal   fixed bugs and ne...
5
      .controller('viewCompanyController', ['$scope', '$uibModal', '$stateParams', 'ViewCompanyService', 'CustomersService', 'updateFuelManagerService', 'ViewFuelVendorService', 'ViewcontactService', '$state', 'fuelOrdersService', 'enterFuelOrderService', 'NgTableParams', function($scope, $uibModal, $stateParams, ViewCompanyService, CustomersService, updateFuelManagerService, ViewFuelVendorService, ViewcontactService, $state, fuelOrdersService, enterFuelOrderService, NgTableParams) {
55e075d7e   Rishav   add contact, add ...
6
7
          $scope.data = {};
          $scope.data.priceEmail = true;
b1f6160d4   Rishav   add contact and a...
8
          $scope.aircraft = {};
3a9f4472b   Rishav   Implement contact...
9
          $scope.primayData = {};
d24318592   Rishav   changes and new i...
10
          $scope.showLoader = false;
ba1d39503   Swarn Singh   view company form...
11
          $scope.showUpdateBtn = false;
28af27a3f   Rishav   add fuelPriceapi
12
          $scope.userProfileId = JSON.parse(localStorage.getItem('userProfileId'));
97f8c67f9   Rishav Singla   ui select impplem...
13
          $scope.selected = [];
07328f442   Rishav Singla   new code added fo...
14
15
          $scope.jetShow = [];
          $scope.marginShow = [];
bfbbd8668   Kuldeep Arora   UI service
16
          $scope.compId = $stateParams.id;
07328f442   Rishav Singla   new code added fo...
17
18
          $scope.jetShow[0] = true;
          $scope.marginShow[0] = true;
5983d987a   Kuldeep Arora   jetmargin api
19
          $scope.dispatchOrder = {};
676250262   Kuldeep Arora   enhancement fuel ...
20
21
22
23
          $scope.dispatchOrder.fuelOrderList = [];
          $scope.statusFilterOptions = [];
          $scope.companyList = {};
          $scope.statusFilterOptions.push({
5983d987a   Kuldeep Arora   jetmargin api
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
                  'id': '',
                  'title': 'Show All'
              }, {
                  'id': 'pending',
                  'title': 'Pending'
              }, {
                  'id': 'invoiced',
                  'title': 'Invoiced'
              }, {
                  'id': 'paid',
                  'title': 'Paid'
              }, {
                  'id': 'cancelled',
                  'title': 'Cancelled'
              }, {
                  'id': 'archived',
                  'title': 'Archived'
676250262   Kuldeep Arora   enhancement fuel ...
41
              }
5983d987a   Kuldeep Arora   jetmargin api
42
43
  
          );
9d840540f   Anchit Jindal   fixed bugs and ne...
44
45
46
          $scope.order = {};
          $scope.order.companyName = '';
      	$scope.order.upliftDate = '';
5983d987a   Kuldeep Arora   jetmargin api
47
48
49
50
51
          /*Get AllCompany api is used from CustomersService*/
          getAllCompanies();
  
          function getAllCompanies() {
              CustomersService.getAllCompanies().then(function(result) {
40c8c308c   Kuldeep Arora   omit css
52
                 //console.log('log', result[2].id);
5983d987a   Kuldeep Arora   jetmargin api
53
                  $scope.companyList = result;
40c8c308c   Kuldeep Arora   omit css
54

5983d987a   Kuldeep Arora   jetmargin api
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
                  for (var i = 0; i < $scope.companyList.length; i++) {
                      if ($scope.companyList[i].companyContact != null) {
                          if ($scope.companyList[i].companyContact.contactNumber != null || $scope.companyList[i].companyContact.contactNumber != undefined) {
                              $scope.companyList[i].newContactNumber = $scope.companyList[i].companyContact.contactNumber;
                          }
                      }
                      if ($scope.companyList[i].primaryContact != null) {
                          if ($scope.companyList[i].primaryContact.firstName != null && $scope.companyList[i].primaryContact.lastName != null) {
                              $scope.companyList[i].primaryContactName = $scope.companyList[i].primaryContact.firstName + ' ' + $scope.companyList[i].primaryContact.lastName;
                          }
                      }
                      if ($scope.companyList[i].margin != null) {
                          if ($scope.companyList[i].margin.marginName != null) {
                              $scope.companyList[i].masterMargin = $scope.companyList[i].margin.id;
                          }
                      }
                  }
                  $scope.displayCompanyList = new NgTableParams({
                      page: 1,
                      count: 10,
                  }, {
                      data: $scope.companyList
                  });
                  $scope.showLoader = false;
              })
          }
676250262   Kuldeep Arora   enhancement fuel ...
81

3a9f4472b   Rishav   Implement contact...
82

7152ff131   Rishav   model handle
83
84
85
86
87
          $(document).ready(function() {
              $("#reset").click(function() {
                  $("input").val("");
              });
          });
5983d987a   Kuldeep Arora   jetmargin api
88
89
90
91
92
93
94
95
96
97
98
99
          $scope.values = [{
                  'id': 1,
                  'first': 'Tenant/Base Customer'
              },
              {
                  'id': 2,
                  'first': 'FuelerLinx Customer'
              },
              {
                  'id': 3,
                  'first': 'CAA Member'
              }
97f8c67f9   Rishav Singla   ui select impplem...
100
          ];
bfbbd8668   Kuldeep Arora   UI service
101
          
5983d987a   Kuldeep Arora   jetmargin api
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
          $scope.changeValue = function(selected) {
              $scope.showUpdateBtn = true;
              // console.log("data to be true", selected);
              for (var i = 0; i < selected.length; i++) {
                  //  console.log(selected[i])
                  if (selected[i] == 'Tenant/Base Customer') {
                      $scope.companyData.baseTenant = true;
                  } else {
                      $scope.companyData.baseTenant = false;
                  }
                  if (selected[i] == 'FuelerLinx Customer') {
                      $scope.companyData.fuelerlinxCustomer = true;
                  } else {
                      $scope.companyData.fuelerlinxCustomer = false;
                  }
97f8c67f9   Rishav Singla   ui select impplem...
117

5983d987a   Kuldeep Arora   jetmargin api
118
119
120
121
122
123
124
                  if (selected[i] == 'CAA Member') {
                      $scope.companyData.contractFuelVendor = true;
                  } else {
                      $scope.companyData.contractFuelVendor = false;
                  }
  
                  // console.log($scope.companyData)
97f8c67f9   Rishav Singla   ui select impplem...
125

5983d987a   Kuldeep Arora   jetmargin api
126
              }
97f8c67f9   Rishav Singla   ui select impplem...
127
128
129
130
131
132
133
134
  
          }
  
          // $scope.selected =[
          //   {'id': 1, 'first': 'Tenant/Base Customer'}, 
          //   {'id': 2, 'first': 'FuelerLinx Customer'},
          //   {'id': 3, 'first': 'CAA Member'}
          // ];
d1fe89776   Rishav Singla   view fuel vendor ...
135
136
137
          // CustomersService.getMargin().then(function(result) {
          //   $scope.marginList = result;
          // })
3a9f4472b   Rishav   Implement contact...
138

48ed0c7bb   Rishav   update company co...
139
          var value = "";
55e075d7e   Rishav   add contact, add ...
140
          var companyId = $stateParams.id;
bfbbd8668   Kuldeep Arora   UI service
141
          
a9a8f570d   Anchit Jindal   new desing implem...
142
143
144
          $scope.companyData = {};
          $scope.multipleMsg = false;
          $scope.companyData.masterMargin = "";
a9aef0b1c   Anchit Jindal   new changes imple...
145
          $scope.isGlobal = false;
0f34b8798   Anchit Jindal   desing and implem...
146
          $scope.fboPreffered = false;
e9a2edf03   Rishav   update custom field
147
          getCompanyDetail();
5983d987a   Kuldeep Arora   jetmargin api
148
149
150
151
152
153
  
          function getCompanyDetail() {
              $scope.showLoader = true;
              ViewCompanyService.getCompany(companyId).then(function(result) {
                  $scope.companyData = result;
                  $scope.isGlobal = result.global;
0f34b8798   Anchit Jindal   desing and implem...
154
                  $scope.fboPreffered = result.fboPreferred;
5983d987a   Kuldeep Arora   jetmargin api
155
156
157
158
159
160
161
162
163
                  if (result.global == true) {
                      $scope.companyData.global = true;
                  }
                  if (result.margin != null) {
                      $scope.companyData.masterMargin = result.margin.id;
                  }
                  if (result.marginAVGAS != null) {
                      $scope.companyData.avgasMargin = result.marginAVGAS.id;
                  }
97f8c67f9   Rishav Singla   ui select impplem...
164

97f8c67f9   Rishav Singla   ui select impplem...
165

5983d987a   Kuldeep Arora   jetmargin api
166
                  if ($scope.companyData.baseTenant) {
97f8c67f9   Rishav Singla   ui select impplem...
167

5983d987a   Kuldeep Arora   jetmargin api
168
169
170
171
                      $scope.selected.push({
                          'first': 'Tenant/Base Customer'
                      })
                      // console.log("$scope.selected",$scope.selected)
97f8c67f9   Rishav Singla   ui select impplem...
172

5983d987a   Kuldeep Arora   jetmargin api
173
                  }
97f8c67f9   Rishav Singla   ui select impplem...
174

5983d987a   Kuldeep Arora   jetmargin api
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
                  if ($scope.companyData.fuelerlinxCustomer) {
                      $scope.selected.push({
                          'first': 'FuelerLinx Customer'
                      })
                      // console.log("$scope.selected",$scope.selected)
                  }
  
                  if ($scope.companyData.contractFuelVendor) {
                      $scope.selected.push({
                          'first': 'CAA Member'
                      })
                      // console.log("$scope.selected",$scope.selected)
                  }
  
                  // console.log("$scope.companyData",$scope.companyData)
                  getAircraftList();
9d840540f   Anchit Jindal   fixed bugs and ne...
191
192
                  $scope.order.companyName = $scope.companyData.companyName;
                  $scope.getAircraft(result.companyName);
5983d987a   Kuldeep Arora   jetmargin api
193
194
                  $scope.showLoader = false;
              })
e9a2edf03   Rishav   update custom field
195
          }
55e075d7e   Rishav   add contact, add ...
196

5983d987a   Kuldeep Arora   jetmargin api
197
198
  
          $scope.changeCompanyStatus = function() {
da24c95c8   Rishav Singla   confirmation mess...
199
              $('#delete3').css('display', 'block');
5983d987a   Kuldeep Arora   jetmargin api
200
201
202
203
              if ($scope.companyData.activate == true) {
                  $scope.statusMessage = 'Please confirm! Are you sure you want to ACTIVATE this company?'
              } else {
                  $scope.statusMessage = 'Please confirm! Are you sure you want to DEACTIVATE this company?'
da24c95c8   Rishav Singla   confirmation mess...
204
205
              }
          }
5983d987a   Kuldeep Arora   jetmargin api
206
207
          $scope.companyStatus = function() {
              $scope.showLoader = true;
3a9f4472b   Rishav   Implement contact...
208
209
              var statusData = "status=" + $scope.companyData.activate;
              ViewCompanyService.changeStatus(companyId, statusData).then(function(result) {
5983d987a   Kuldeep Arora   jetmargin api
210
211
212
213
214
215
216
                  if (result.success) {
                      $('#delete3').css('display', 'none');
                      toastr.success('' + result.success + '', {
                          closeButton: true
                      })
                      getContactList();
                  }
3a9f4472b   Rishav   Implement contact...
217
              })
05bfa28a2   Mr. Hot Foods   remove save butto...
218
              $scope.showLoader = false;
c555af312   Rishav   price email, comp...
219
          }
3a9f4472b   Rishav   Implement contact...
220

5983d987a   Kuldeep Arora   jetmargin api
221
222
  
          $scope.cancelStatus = function() {
da24c95c8   Rishav Singla   confirmation mess...
223
              $('#delete3').css('display', 'none');
5983d987a   Kuldeep Arora   jetmargin api
224
              $scope.companyData.activate = !$scope.companyData.activate;
da24c95c8   Rishav Singla   confirmation mess...
225
          }
5983d987a   Kuldeep Arora   jetmargin api
226

48ed0c7bb   Rishav   update company co...
227
          getContactList();
5983d987a   Kuldeep Arora   jetmargin api
228
229
230
231
232
  
          function getContactList() {
              ViewCompanyService.getContact(companyId).then(function(result) {
                  $scope.companyContactList = result;
              })
48ed0c7bb   Rishav   update company co...
233
          }
a9a8f570d   Anchit Jindal   new desing implem...
234
          $scope.aircraftmargins = [];
5983d987a   Kuldeep Arora   jetmargin api
235

bcd6c1025   Kuldeep Arora   aircraft display-...
236
237
          $scope.abc = false;
          $scope.xyz = false;
5983d987a   Kuldeep Arora   jetmargin api
238
239
          function getAircraftList() {
              ViewCompanyService.getAircraft(companyId).then(function(result) {
bcd6c1025   Kuldeep Arora   aircraft display-...
240
                 
5983d987a   Kuldeep Arora   jetmargin api
241
242
243
244
245
246
                  $scope.contactAircraftList = result;
                  for (var i = 0; i < $scope.contactAircraftList.length; i++) {
                      if ($scope.contactAircraftList[i].aircraftsMargin != null) {
                          $scope.aircraftmargins.push({
                              'id': $scope.contactAircraftList[i].aircraftsMargin.id
                          })
cca8fa318   Kuldeep Arora   aircraft display ...
247
248
                          $scope.contactAircraftList[i].fuelType = "Jet-A";
                          $scope.contactAircraftList[i].marginValue = result[i].aircraftsMargin.marginValue;
dadb46117   Kuldeep Arora   color code for va...
249
                          $scope.abc = true;
bcd6c1025   Kuldeep Arora   aircraft display-...
250
251
252
                          
                      }else{
                          $scope.contactAircraftList[i].fuelType = "100LL";
a858eca3e   Kuldeep Arora   css
253
                          if (result[i].aircraftsAVGASMargin != null) {
cca8fa318   Kuldeep Arora   aircraft display ...
254
                          $scope.contactAircraftList[i].marginValue = result[i].aircraftsAVGASMargin.marginValue;
dadb46117   Kuldeep Arora   color code for va...
255
                          $scope.xyz = true;
a858eca3e   Kuldeep Arora   css
256
257
                              
                          }
5983d987a   Kuldeep Arora   jetmargin api
258
                      }
bcd6c1025   Kuldeep Arora   aircraft display-...
259

5983d987a   Kuldeep Arora   jetmargin api
260
261
262
263
264
265
266
267
268
                  }
                  if ($scope.aircraftmargins.length > 0) {
                      for (var i = 0; i < $scope.aircraftmargins.length; i++) {
                          if ($scope.aircraftmargins[i].id != $scope.companyData.masterMargin) {
                              $scope.multiple = true;
                              $scope.multipleMsg = true;
                              if ($scope.multiple) {
                                  $scope.companyData.masterMargin = "multiple";
                              }
a9a8f570d   Anchit Jindal   new desing implem...
269
                          }
5983d987a   Kuldeep Arora   jetmargin api
270
                      }
a9a8f570d   Anchit Jindal   new desing implem...
271
                  }
5983d987a   Kuldeep Arora   jetmargin api
272
              })
b1f6160d4   Rishav   add contact and a...
273
          }
b1f6160d4   Rishav   add contact and a...
274

5983d987a   Kuldeep Arora   jetmargin api
275

55e075d7e   Rishav   add contact, add ...
276
277
          $scope.contactData = {};
          $scope.contactData.contactList = [];
5983d987a   Kuldeep Arora   jetmargin api
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
          $scope.addContact = function() {
              $scope.showLoader = true;
              $scope.data.companyId = companyId;
              $scope.contactData.contactList.push($scope.data);
              ViewCompanyService.addContact($scope.contactData).then(function(result) {
                  //console.log("data==",$scope.contactData)
                  // console.log(result)
                  if (result.status == 200) {
  
                      $('#contact-modal-3').modal('hide');
                      $scope.primayData.id = result.data;
                      $scope.data = {};
                      $scope.sendPrimaryContact();
                      getContactList();
                      $scope.contactData.contactList = [];
                      $scope.data.email = '';
5983d987a   Kuldeep Arora   jetmargin api
294
                      toastr.success('Created Successfully', {
cf43d578a   Kuldeep Arora   delete company up...
295
                          closeButton: true
5983d987a   Kuldeep Arora   jetmargin api
296
297
298
299
300
301
302
303
                      })
                  } else {
                      toastr.error('' + result.statusText + '', {
                          closeButton: true
                      })
                  }
              })
              $scope.showLoader = false;
55e075d7e   Rishav   add contact, add ...
304
          }
feacde5ff   Rishav   setup acuefuel in...
305

5983d987a   Kuldeep Arora   jetmargin api
306
307
308
309
310
311
          getData();
  
          function getData() {
              $scope.showLoader = true;
              CustomersService.getAircraftMake().then(function(result) {
                  $scope.aircraftMakeList = result;
40c8c308c   Kuldeep Arora   omit css
312
                 // console.log("make",result)
5983d987a   Kuldeep Arora   jetmargin api
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
              })
              $scope.showLoader = false;
          }
  
          $scope.clearAircrafts = function() {
              $scope.aircraftDetails = [];
              $scope.aircraftDetails = [{
                  'tail': '',
                  'make': '',
                  'model': '',
                  'sizeId': '',
                  'marginId': '',
                  'avgasMarginId': ''
              }];
          }
  
          $scope.addNew = function() {
              $scope.aircraftDetails.push({
                  'tail': '',
                  'make': '',
                  'model': '',
                  'sizeId': '',
                  'marginId': '',
                  'avgasMarginId': ''
a4884cfe7   Rishav   add aircraft issu...
337
              });
5983d987a   Kuldeep Arora   jetmargin api
338
339
340
341
342
343
              //  console.log($scope.aircraftDetails)
          };
  
          $scope.getModal = function(makeId, index) {
              $scope.showLoader = true;
              $scope.aircraft.make = makeId;
5983d987a   Kuldeep Arora   jetmargin api
344
              CustomersService.getModal($scope.aircraft.make).then(function(result) {
33a64416f   Anchit Jindal   mbug fixes
345
346
347
348
                  $scope.showLoader = false;
                  $scope.aircraftDetails[index].aircraftModalList = result;
                  //$scope.aircraftDetails[index].model = $scope.aircraftModalList[0];
              })
b1f6160d4   Rishav   add contact and a...
349
          }
33a64416f   Anchit Jindal   mbug fixes
350
          
bfbbd8668   Kuldeep Arora   UI service
351
          $scope.selectedOption = '';
5983d987a   Kuldeep Arora   jetmargin api
352
353
          $scope.getSize = function(model, index) {
              $scope.showLoader = true;
33a64416f   Anchit Jindal   mbug fixes
354
              $scope.aircraft.model = model;
5983d987a   Kuldeep Arora   jetmargin api
355
356
357
              CustomersService.getAircraftSize($scope.aircraft.make, model).then(function(result) {
                  $scope.showLoader = false;
                  $scope.aircraftDetails[index].aircraftSizeList = result;
0a364e561   Kuldeep Arora   minor
358
                  $scope.getFuelType($scope.aircraftDetails[index].aircraftSizeList[0].aircraftSize.id,index);
88abaa681   Kuldeep Arora   size auto-populat...
359
                  
6367e69ba   Kuldeep Arora   minor
360
                  
5983d987a   Kuldeep Arora   jetmargin api
361
362
              })
          }
33a64416f   Anchit Jindal   mbug fixes
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
          
          $scope.getFuelType = function(size, index) {
          	$scope.showLoader = true;
          	var data = "model="+$scope.aircraft.model+"&make="+$scope.aircraft.make+"&sizeId="+size;
          	ViewCompanyService.checkFuelType(data).then(function(result){
                $scope.showLoader = false;
                if (result.type == "JetA") {
                    $scope.jetShow[index] = false;
                    $scope.marginShow[index] = true;
                } else if (result.type == "Avgas")   {
                    $scope.jetShow[index] = true;
                    $scope.marginShow[index] = false;
                }else {
                    $scope.jetShow[index] = true;
                    $scope.marginShow[index] = true;
                }
          	})
          }
5983d987a   Kuldeep Arora   jetmargin api
381
382
  
          $scope.aircraftListData = {};
359303f53   Kuldeep Arora   Adding company/ai...
383
384
385
386
387
          $scope.addData = [];
          $scope.tailArray = [];
          function check(array){
              return (new Set(array)).size !== array.length;
          }
5983d987a   Kuldeep Arora   jetmargin api
388
          $scope.saveCompanyData = function() {
359303f53   Kuldeep Arora   Adding company/ai...
389
              $scope.tailArray = [];
2075411ed   Kuldeep Arora   create fuel order...
390
                  for (var i = 0; i < $scope.aircraftDetails.length; i++) {
2075411ed   Kuldeep Arora   create fuel order...
391
392
393
394
395
396
397
398
                      $scope.addData.push({
                          'tail': $scope.aircraftDetails[i].tail,
                          'make': $scope.aircraftDetails[i].make,
                          'model': $scope.aircraftDetails[i].model,
                          'sizeId': $scope.aircraftDetails[i].sizeId,
                          'marginId': $scope.aircraftDetails[i].marginId,
                          'avgasMarginId': $scope.aircraftDetails[i].avgasMarginId
                      });
359303f53   Kuldeep Arora   Adding company/ai...
399
400
                      $scope.tailArray.push($scope.aircraftDetails[i].tail);
                  }
359303f53   Kuldeep Arora   Adding company/ai...
401
402
403
404
405
406
                  if (check($scope.tailArray)) {
                      toastr.error('Duplicate Tail Added.', {
                                  closeButton: true
                              })
                  }else{
                      $scope.aircraftListData.aircraftList = $scope.addData;
e443a586b   Kuldeep Arora   aircraftslist
407
                      $scope.aircraftListData.accountId = companyId;  
359303f53   Kuldeep Arora   Adding company/ai...
408
409
410
411
412
                      CustomersService.addAircraft($scope.aircraftListData).then(function(result) {
                          if (result != null && result.success) {
                              toastr.success('' + result.success + '', {
                                  closeButton: true
                              })
6367e69ba   Kuldeep Arora   minor
413
414
415
                              $scope.addData= [];
                              $scope.tailArray = [];
                              $scope.aircraftListData={};
359303f53   Kuldeep Arora   Adding company/ai...
416
417
                              $('#aircraft-modal-3').css('display', 'none');
                              $('.modal-backdrop').css('display', 'none');
8f525d21f   Kuldeep Arora   modalbox fixed
418
419
                              $('#aircraft-modal-3').modal('hide');
                              $('.modal-backdrop').modal('hide');
359303f53   Kuldeep Arora   Adding company/ai...
420
                              getAircraftList();
8f525d21f   Kuldeep Arora   modalbox fixed
421

359303f53   Kuldeep Arora   Adding company/ai...
422
                          } else {
8f525d21f   Kuldeep Arora   modalbox fixed
423
424
                              $('#aircraft-modal-3').css('display', 'none');
                              $('.modal-backdrop').css('display', 'none');
359303f53   Kuldeep Arora   Adding company/ai...
425
426
427
428
429
                              toastr.error('' + result.statusText + '', {
                                  closeButton: true
                              })
                          }
                      });
5983d987a   Kuldeep Arora   jetmargin api
430
                  }
2075411ed   Kuldeep Arora   create fuel order...
431
                  
5983d987a   Kuldeep Arora   jetmargin api
432
          }
2075411ed   Kuldeep Arora   create fuel order...
433

5983d987a   Kuldeep Arora   jetmargin api
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
          $scope.showNoteData = true;
          $scope.showCompanyName = true;
          $scope.showAddress = true;
          $scope.showNote = function() {
              $scope.showNoteData = false;
              $scope.showUpdateBtn = true;
          }
  
          $scope.company = function() {
              $scope.showCompanyName = false;
              $scope.showUpdateBtn = true;
          }
  
          $scope.base = function() {
              $scope.showUpdateBtn = true;
          }
  
          $scope.addressChange = function() {
              $scope.showAddress = false;
              $scope.showUpdateBtn = true;
          }
  
          $scope.editData = function(inputName) {
              //console.log($scope.companyData)
              $scope.showLoader = true;
              /*if(inputName == 'showNoteData'){
                $scope.showNoteData = true;
              }else if(inputName == 'showCompanyName'){
                $scope.showCompanyName = true;
              }else if(inputName == 'showAddress'){
                $scope.showAddress = true;              
              }*/
a4884cfe7   Rishav   add aircraft issu...
466
              $scope.showNoteData = true;
a4884cfe7   Rishav   add aircraft issu...
467
              $scope.showCompanyName = true;
5983d987a   Kuldeep Arora   jetmargin api
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
              $scope.showAddress = true;
  
              var companyData = "companyName=" + $scope.companyData.companyName + "&masterMargin=" + $scope.companyData.masterMargin + "&avgasMargin=" + $scope.companyData.avgasMargin +
                  "&addressOne=" + $scope.companyData.addressOne + "&addressTwo=" + $scope.companyData.addressTwo + "&city=" + $scope.companyData.city + "&state=" +
                  $scope.companyData.state + "&country=" + $scope.companyData.country + "&zipcode=" + $scope.companyData.zipcode + "&internalNote=" +
                  $scope.companyData.internalNote + "&certificateType=" + $scope.companyData.certificateType + "&baseTenant=" + $scope.companyData.baseTenant +
                  "&fuelerlinxCustomer=" + $scope.companyData.fuelerlinxCustomer + "&contractFuelVendor=" + $scope.companyData.contractFuelVendor +
                  "&activate=" + $scope.companyData.activate + "&baseIcao=" + $scope.companyData.baseIcao + "&companyId=" + companyId + "&global=" + $scope.companyData.global;
  
              ViewCompanyService.updateCompany(companyData).then(function(result) {
                  if (result != null && result.success) {
                      toastr.success('' + result.success + '', {
                          closeButton: true
                      })
                      $scope.showUpdateBtn = false;
                      getCompanyDetail();
                  } else {
9d840540f   Anchit Jindal   fixed bugs and ne...
485
                      toastr.error('Error Updating Company', {
5983d987a   Kuldeep Arora   jetmargin api
486
487
488
489
490
491
492
                          closeButton: true
                      })
                      $scope.showUpdateBtn = true;
                  }
                  $scope.showLoader = false;
              })
          }
9d840540f   Anchit Jindal   fixed bugs and ne...
493
          $scope.cancelUpdateData = function() {
5983d987a   Kuldeep Arora   jetmargin api
494
495
496
497
498
499
500
              $scope.showNoteData = true;
              $scope.showCompanyName = true;
              $scope.showAddress = true;
              $scope.showUpdateBtn = false;
          }
  
          $scope.sendMail = function() {
9d840540f   Anchit Jindal   fixed bugs and ne...
501
          	$scope.showLoader = true;
5983d987a   Kuldeep Arora   jetmargin api
502
503
504
505
506
507
508
              $('#confirm1').css('display', 'none');
              ViewCompanyService.sendMail(companyId).then(function(result) {
                  if (result != null && result.success) {
                      toastr.success('' + result.success + '', {
                          closeButton: true
                      })
                  } else {
9d840540f   Anchit Jindal   fixed bugs and ne...
509
                      toastr.error('Error Sending Email', {
5983d987a   Kuldeep Arora   jetmargin api
510
511
512
                          closeButton: true
                      })
                  }
9d840540f   Anchit Jindal   fixed bugs and ne...
513
                  $scope.showLoader = false;
5983d987a   Kuldeep Arora   jetmargin api
514
515
516
517
518
519
              })
          }
  
          $scope.openConfirmMail = function() {
              $('#confirm1').css('display', 'block');
          }
b1f6160d4   Rishav   add contact and a...
520

48ed0c7bb   Rishav   update company co...
521

5983d987a   Kuldeep Arora   jetmargin api
522
523
524
          $scope.cancelAndCloseConfirm = function() {
              $('#confirm1').css('display', 'none');
          }
b1f6160d4   Rishav   add contact and a...
525

a4884cfe7   Rishav   add aircraft issu...
526
          $scope.primaryContact = false;
5983d987a   Kuldeep Arora   jetmargin api
527
528
529
530
531
532
533
534
535
536
537
538
539
540
          $scope.cancelPrimaryContact = function() {
              $('#primaryContact').css('display', 'none');
              $scope.primaryContact = false;
          }
  
          $scope.checkPrimaryContact = function() {
              if ($scope.primaryContact == true) {
                  $scope.primaryContact = true;
                  ViewCompanyService.checkPrimaryContact(companyId).then(function(result) {
                      //console.log(result)
                      if (result.status == 422) {
                          $('#primaryContact').css('display', 'block');
                      }
                  })
a4884cfe7   Rishav   add aircraft issu...
541
              }
5983d987a   Kuldeep Arora   jetmargin api
542
543
544
545
546
547
548
549
550
551
          }
  
          $scope.sendPrimaryContact = function() {
              $('#primaryContact').css('display', 'none');
              if ($scope.primayData.id != null || $scope.primayData.id != undefined) {
                  var priamryContactData = "companyContactId=" + $scope.primayData.id + "&primary=" + $scope.primaryContact;
  
                  ViewCompanyService.addPrimaryContact(priamryContactData).then(function(result) {
                      // console.log(result)
                  })
8670c5905   Jaideep Singh   new changes
552
              }
8670c5905   Jaideep Singh   new changes
553
          }
5983d987a   Kuldeep Arora   jetmargin api
554
          $scope.updateData = ""
9d840540f   Anchit Jindal   fixed bugs and ne...
555
          $scope.showUpdateContact = function(data, value) {
5983d987a   Kuldeep Arora   jetmargin api
556
557
              $('#updateContact').css('display', 'block');
              $scope.updateData = data;
9d840540f   Anchit Jindal   fixed bugs and ne...
558
559
560
561
562
563
564
565
566
567
568
              // console.log($scope.updateData)
              if ($scope.updateData.email == null) {
                  $scope.updateData.content = data.contactNumber;
              } else {
                  $scope.updateData.content = data.email;
              }
          }
          
          $scope.showUpdateEmail = function(data, value) {
              $('#updateEmail').css('display', 'block');
              $scope.updateData = data;
5983d987a   Kuldeep Arora   jetmargin api
569
570
571
572
573
574
575
              // console.log($scope.updateData)
              if ($scope.updateData.email == null) {
                  $scope.updateData.content = data.contactNumber;
              } else {
                  $scope.updateData.content = data.email;
              }
          }
9d840540f   Anchit Jindal   fixed bugs and ne...
576
          $scope.acceptUpdateField = function(newContactName) {
5983d987a   Kuldeep Arora   jetmargin api
577
578
579
              // console.log($scope.updateData)
              if ($scope.updateData.content == undefined) {
                  toastr.error('Please add some content', {
cdf775224   Anchit Jindal   fixed company and...
580
581
                      closeButton: true
                  })
5983d987a   Kuldeep Arora   jetmargin api
582
583
584
585
586
587
588
589
590
              } else {
                  if (newContactName == 'phone') {
                      var updateCustomData = "companyId=" + companyId + "&contactNumber=" + $scope.updateData.content + "&contactId=" + $scope.updateData.id +
                          "&title=" + $scope.updateData.title;
                  } else {
                      var updateCustomData = "companyId=" + companyId + "&email=" + $scope.updateData.content + "&contactId=" + $scope.updateData.id +
                          "&title=" + $scope.updateData.title;
                  }
                  ViewCompanyService.updateCustomField(updateCustomData).then(function(result) {
5983d987a   Kuldeep Arora   jetmargin api
591
592
                      if (result != null && result.success) {
                          $('#updateContact').css('display', 'none');
9d840540f   Anchit Jindal   fixed bugs and ne...
593
                          $('#updateEmail').css('display', 'none');
5983d987a   Kuldeep Arora   jetmargin api
594
595
596
                          getCompanyDetail();
                      }
                  })
cdf775224   Anchit Jindal   fixed company and...
597
              }
cdf775224   Anchit Jindal   fixed company and...
598
          }
9d840540f   Anchit Jindal   fixed bugs and ne...
599
600
601
602
603
604
605
606
607
608
609
          
          $scope.deleteContent = function(data){
          	ViewCompanyService.deleteCustomContact(data.id).then(function(result) {
                  if (result != null && result.success) {
                  	toastr.success('' + result.success + '', {
                          closeButton: true
                      })
                      getCompanyDetail();
                  }
              })
          }
07328f442   Rishav Singla   new code added fo...
610

5983d987a   Kuldeep Arora   jetmargin api
611
612
          $scope.cancelUpdateField = function() {
              $('#updateContact').css('display', 'none');
9d840540f   Anchit Jindal   fixed bugs and ne...
613
              $('#updateEmail').css('display', 'none');
5983d987a   Kuldeep Arora   jetmargin api
614
615
616
617
618
619
          }
  
          $scope.showEditTier2 = function(number) {
              // console.log(number)
              $scope.contactNumber = number;
          }
07328f442   Rishav Singla   new code added fo...
620

5983d987a   Kuldeep Arora   jetmargin api
621

9d840540f   Anchit Jindal   fixed bugs and ne...
622
          $scope.addCustomPhone = function(value) {
5983d987a   Kuldeep Arora   jetmargin api
623
624
              //console.log(value)
              if (value != null) {
9d840540f   Anchit Jindal   fixed bugs and ne...
625
626
627
628
629
630
631
632
633
                  $('#customFieldPhone').css('display', 'block');
              }
              $scope.custom = {};
          }
          
          $scope.addCustomEmail = function(value) {
              //console.log(value)
              if (value != null) {
                  $('#customFieldEmail').css('display', 'block');
07328f442   Rishav Singla   new code added fo...
634
              }
5983d987a   Kuldeep Arora   jetmargin api
635
              $scope.custom = {};
07328f442   Rishav Singla   new code added fo...
636
          }
cf43d578a   Kuldeep Arora   delete company up...
637

5983d987a   Kuldeep Arora   jetmargin api
638
          $scope.cancelCustomField = function() {
9d840540f   Anchit Jindal   fixed bugs and ne...
639
640
              $('#customFieldEmail').css('display', 'none');
              $('#customFieldPhone').css('display', 'none');
5983d987a   Kuldeep Arora   jetmargin api
641
          }
676250262   Kuldeep Arora   enhancement fuel ...
642

9d840540f   Anchit Jindal   fixed bugs and ne...
643
          $scope.acceptCustomField = function(contactName) {
5983d987a   Kuldeep Arora   jetmargin api
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
              if ($scope.custom.content == undefined) {
                  toastr.error('Please add some content', {
                      closeButton: true
                  })
              } else {
                  if (contactName == 'phone') {
                      var customData = "companyId=" + companyId + "&contactNumber=" + $scope.custom.content +
                          "&title=" + $scope.custom.title;
                  } else {
                      var customData = "companyId=" + companyId + "&email=" + $scope.custom.content +
                          "&title=" + $scope.custom.title;
                  }
                  // console.log(customData.email)
                  ViewCompanyService.addCustomField(customData).then(function(result) {
                      // console.log(result)
                      if (result != null && result.success) {
9d840540f   Anchit Jindal   fixed bugs and ne...
660
661
662
                          $('#customFieldEmail').css('display', 'none');
                          $('#customFieldPhone').css('display', 'none');
                          $scope.custom = {};
5983d987a   Kuldeep Arora   jetmargin api
663
664
665
666
667
                          getCompanyDetail();
                      }
                  })
              }
          }
676250262   Kuldeep Arora   enhancement fuel ...
668

64b3dc0e3   Kuldeep Arora   omit vendor and c...
669
          /*  omit strike out*/
5983d987a   Kuldeep Arora   jetmargin api
670
671
          updateFuelManagerService.getFuelPricingNew().then(function(result) {
              $scope.fuelPricing = result;
bfbbd8668   Kuldeep Arora   UI service
672
673
674
              $scope.omitData;
              ViewCompanyService.getOmitCompany($scope.compId).then(function(result){
                  $scope.omitData = result;
64b3dc0e3   Kuldeep Arora   omit vendor and c...
675
676
677
678
679
680
681
682
                  //console.log("omit data===", $scope.omitData);
                  for(var i = 0 ; i< $scope.fuelPricing.length; i++){
                      for(var j = 0; j<$scope.omitData.length; j++){
                          if($scope.omitData[j].marginId == $scope.fuelPricing[i].fuelPricing.id){
                              $scope.fuelPricing[i].fuelPricing.omit = $scope.omitData[j].omit;
                      }
                          }
                  }
bfbbd8668   Kuldeep Arora   UI service
683
              })
64b3dc0e3   Kuldeep Arora   omit vendor and c...
684
             // console.log("$scope.fuelPricing",$scope.fuelPricing)
5983d987a   Kuldeep Arora   jetmargin api
685
              for (var i = 0; i < $scope.fuelPricing.length; i++) {
64b3dc0e3   Kuldeep Arora   omit vendor and c...
686
                //  console.log('$scope.fuelPricing[i].fuelPricing', $scope.fuelPricing[i].fuelPricing);
dadb46117   Kuldeep Arora   color code for va...
687
                //console.log("fuelid",$scope.fuelPricing[i].fuelPricing.id,"getid",$scope.omitData[j].id)
5983d987a   Kuldeep Arora   jetmargin api
688
689
690
691
692
693
694
695
                  if ($scope.fuelPricing[i].fuelPricing.expirationDate != null) {
                      $scope.fuelPricing[i].fuelPricing.expirationDate = new Date($scope.fuelPricing[i].fuelPricing.expirationDate);
                      var newTime = new Date($scope.fuelPricing[i].fuelPricing.expirationDate);
                      var dmonth = newTime.getUTCMonth() + 1; //months from 1-12
                      var dday = newTime.getUTCDate();
                      var dyear = newTime.getUTCFullYear();
                      $scope.fuelPricing[i].fuelPricing.expirationDate = dmonth + '/' + dday + '/' + dyear;
                  }
bfbbd8668   Kuldeep Arora   UI service
696
697
698
699
700
                  // for (var j = 0; j<$scope.omitData.length; j++) {
                  //     if($scope.fuelPricing[i].fuelPricing.id === $scope.omitData[j].id){
  
                  //     }
                  // }
5983d987a   Kuldeep Arora   jetmargin api
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
              }
          })
  
          var deleteAircraftId = "";
          $scope.deleteAircraft = function(id) {
              $('#delete1').css('display', 'block');
              deleteAircraftId = id;
          }
  
          $scope.aircraftDelete = function() {
              ViewCompanyService.deleteAircraft(deleteAircraftId).then(function(result) {
                  // console.log(result)
                  getAircraftList();
                  getCompanyDetail();
                  $('#delete1').css('display', 'none');
              })
          }
de63dd418   Kuldeep Arora   cancelbutton
718
          $scope.cancelAircraft = function() {
5983d987a   Kuldeep Arora   jetmargin api
719
720
721
722
723
724
725
726
727
728
              $('#delete1').css('display', 'none');
          }
  
          CustomersService.getJetMargin($scope.userProfileId).then(function(result) {
              $scope.jetMarginList = result;
          })
  
          CustomersService.getAvgMargin($scope.userProfileId).then(function(result) {
              $scope.avgsMarginList = result;
          })
676250262   Kuldeep Arora   enhancement fuel ...
729

5983d987a   Kuldeep Arora   jetmargin api
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
          $scope.changePriceEmail = function(id, index) {
              event.stopPropagation();
              var contactId = id;
              var statusData = "status=" + $scope.companyContactList[index].priceEmail;
              ViewcontactService.changePriceEmail(contactId, statusData).then(function(result) {
                  if (result.success) {
                      $('#toogleMail').css('display', 'block');
                      if ($scope.companyContactList[index].priceEmail == true) {
                          $scope.messageText = 'You have enabled price distribution for this contact';
                      } else {
                          $scope.messageText = 'You have disabled price distribution for this contact';
                      }
                  }
              })
          }
  
          $scope.cancelToogle = function() {
              $('#toogleMail').css('display', 'none');
          }
  
          $scope.checkboxStatus = function(value) {
              //  console.log("checkbox",value)
              $scope.showUpdateBtn = true;
          }
  
          $scope.fuelercheckboxStatus = function(value) {
              $('#fuelerchange').css('display', 'block');
              if (value == true) {
                  $scope.statusMessage = 'Please confirm! Enabling FuelerLinx for this customer will enable price distribution web services and disable price emails for the contacts in this company'
              } else {
                  $scope.statusMessage = 'Please confirm! Disabling FuelerLinx for this customer will disable price distribution web services into their FuelerLinx account. If you proceed then remember to enable price emails for the appropriate contacts in this company.'
676250262   Kuldeep Arora   enhancement fuel ...
761
              }
676250262   Kuldeep Arora   enhancement fuel ...
762

5983d987a   Kuldeep Arora   jetmargin api
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
  
          }
  
          $scope.fuelerCancelStatus = function() {
              $('#fuelerchange').css('display', 'none');
              $scope.companyData.fuelerlinxCustomer = !$scope.companyData.fuelerlinxCustomer;
          }
  
          $scope.fuelerAcceptStatus = function() {
              $('#fuelerchange').css('display', 'none');
              $scope.showLoader = true;
              var statusData;
              if ($scope.companyData.fuelerlinxCustomer == false) {
                  statusData = "status=true";
              } else {
                  statusData = "status=false";
              }
              ViewCompanyService.fuelerPricingChange(companyId, statusData).then(function(result) {
                  if (result.success) {
                      $scope.showLoader = false;
  
                      $scope.editData();
                      getContactList();
  
                  }
676250262   Kuldeep Arora   enhancement fuel ...
788
              })
5983d987a   Kuldeep Arora   jetmargin api
789
          }
bcd6c1025   Kuldeep Arora   aircraft display-...
790
      
5983d987a   Kuldeep Arora   jetmargin api
791
792
793
          $scope.updateOmit = function(fuel, omit) {
              $scope.fuelData = {};
              $scope.fuelData.expirationDate = new Date(fuel.expirationDate);
bfbbd8668   Kuldeep Arora   UI service
794
              $scope.fuelData.customMarginId = fuel.id;
5983d987a   Kuldeep Arora   jetmargin api
795
796
797
798
              $scope.fuelData.omit = fuel.omit;
              $scope.fuelData.papMargin = fuel.papMargin;
              $scope.fuelData.papTotal = fuel.papTotal;
              $scope.fuelData.cost = fuel.cost;
bfbbd8668   Kuldeep Arora   UI service
799
              $scope.fuelData.companyId = $scope.compId ;
bfbbd8668   Kuldeep Arora   UI service
800
801
              if($scope.fuelData.omit == true)
              {
bfbbd8668   Kuldeep Arora   UI service
802
                  var customData = "companyId=" + $scope.fuelData.companyId + "&customMarginId=" + $scope.fuelData.customMarginId;
20b4aefe7   Kuldeep Arora   viewcompany
803
               //   console.log(".")
bfbbd8668   Kuldeep Arora   UI service
804
805
806
807
808
809
810
811
812
813
814
815
                   ViewCompanyService.omitAddCompanyFuel(customData).then(function(result) {
                      if (result.success) {
                          toastr.success('' + result.success + '', {
                              closeButton: true
                          })
                      } else {
                          toastr.error('' + result.statusText + '', {
                              closeButton: true
                          })
                      }
                  }) 
              }else{
64b3dc0e3   Kuldeep Arora   omit vendor and c...
816
817
                       var data ="companyId=" + $scope.fuelData.companyId + "&customMarginId=" + $scope.fuelData.customMarginId;
                  ViewCompanyService.omitDeleteCompanyFuel(data).then(function(result){
bfbbd8668   Kuldeep Arora   UI service
818
819
820
821
822
823
824
825
826
827
828
                          if (result.success) {
                          toastr.success('' + result.success + '', {
                              closeButton: true
                          })
                        } else {
                          toastr.error('' + result.statusText + '', {
                              closeButton: true
                          })
                      }
                  })
              }
5983d987a   Kuldeep Arora   jetmargin api
829
          }
bfbbd8668   Kuldeep Arora   UI service
830

bcd6c1025   Kuldeep Arora   aircraft display-...
831
          //--fuel type based on tail is not in use--
5983d987a   Kuldeep Arora   jetmargin api
832
          // $scope.aircraftData = {}
1d6e37847   Kuldeep Arora   fueltype in addin...
833
          /*$scope.checkJetWithTail = function(tail, index) {
5983d987a   Kuldeep Arora   jetmargin api
834

1d6e37847   Kuldeep Arora   fueltype in addin...
835
                console.log("tail==============",tail, index)
5983d987a   Kuldeep Arora   jetmargin api
836
              ViewCompanyService.checkJetType(tail).then(function(result) {
1d6e37847   Kuldeep Arora   fueltype in addin...
837
                     console.log("result",result)
5983d987a   Kuldeep Arora   jetmargin api
838
839
840
841
842
843
844
                  if (result.jetA == "true") {
                      $scope.jetShow[index] = false;
                      $scope.marginShow[index] = true;
                  } else {
                      $scope.jetShow[index] = true;
                      $scope.marginShow[index] = false;
                  }
676250262   Kuldeep Arora   enhancement fuel ...
845
              })
1d6e37847   Kuldeep Arora   fueltype in addin...
846
          }*/
5983d987a   Kuldeep Arora   jetmargin api
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
  
          /*add a fuel order*/
  
  
          $scope.getOrders = function() {
              fuelOrdersService.getOrders().then(function(result) {
  
                  $scope.orderdata = result;
                  for (var i = 0; i < $scope.orderdata.length; i++) {
                      $scope.orderdata[i].upliftDateS = new Date($scope.orderdata[i].upliftDate);
  
                      // var str = "" + $scope.orderdata[i].upliftDateS.getDate() + "/" + ($scope.orderdata[i].upliftDateS.getMonth() + 1) + "/" + $scope.orderdata[i].upliftDateS.getFullYear()
                      var str = "" + ($scope.orderdata[i].upliftDateS.getMonth() + 1) + "/" + $scope.orderdata[i].upliftDateS.getDate() + "/" + $scope.orderdata[i].upliftDateS.getFullYear()
                      //  str = str.slice(4,16)
                      $scope.orderdata[i].upliftDateString = str
                      // console.log(str);
  
                  }
  
                  $scope.displayFuelOrderList = new NgTableParams({
                      page: 1,
                      count: 10,
                  }, {
                      data: $scope.orderdata
                  });
                  $(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();
                      }
676250262   Kuldeep Arora   enhancement fuel ...
884
                  })
5983d987a   Kuldeep Arora   jetmargin api
885

676250262   Kuldeep Arora   enhancement fuel ...
886
              })
5983d987a   Kuldeep Arora   jetmargin api
887
888
889
          }
  
          $scope.getOrders();
9d840540f   Anchit Jindal   fixed bugs and ne...
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
          
          $scope.tiervalue=function(){
      		$scope.order.tierBreak=$scope.selectedTier.minTierBreak+'-'+$scope.selectedTier.maxTierBreak;
      	}
  
      	$scope.setCost = function(cost){
      		if(cost != null) {
      			var obj =JSON.parse(cost);
      			$scope.order.fboCost = obj.cost;
      		}
      	}
  
      	$scope.cancelOrder = function() {
      		$scope.order = {};
      	}
      	
      	$scope.dispatchFuel = function(){
      		$scope.showLoader = true;
      		$scope.order.companyId = $scope.compId;
      		if ($scope.order.upliftDate != '') {
      			var currentDate = new Date();
                  var hours = currentDate.getHours();
                  var min = currentDate.getMinutes();
                  var sec = currentDate.getSeconds();
                  $scope.order.upliftDate = $scope.order.upliftDate + ' ' + hours + ':' + min + ':' + sec;
      			$scope.order.upliftDate = new Date($scope.order.upliftDate);
      			$scope.order.upliftDate = $scope.order.upliftDate.getTime();
      		}
      		$scope.order.status = 'pending';
      		var obj =JSON.parse($scope.order.priceQuote);
748fc1d4b   Anchit Jindal   minor changes
920
921
922
      		$scope.order.priceQuote = obj.papTotal;
      		$scope.order.fboCost = obj.cost;
      		$scope.order.total = obj.papTotal * $scope.order.volume;
9d840540f   Anchit Jindal   fixed bugs and ne...
923
924
925
926
927
928
929
930
931
932
933
      		var aircraftObj =JSON.parse($scope.order.aircraftName);
      		$scope.order.aircraftName = aircraftObj.tail;
      		$scope.order.make = aircraftObj.make;
      		$scope.order.model = aircraftObj.model;
      		$scope.dispatchOrder.fuelOrderList.push($scope.order);
      		enterFuelOrderService.dispathFuelOrder($scope.dispatchOrder).then(function(result) {
      			$scope.showLoader = false;
      			$scope.order = {};
      			$('#demo-modal-4').css('display', '');
      			toastr.success('Fuel Order Dispatched Successfully', {
                    closeButton: true
5983d987a   Kuldeep Arora   jetmargin api
934
                  })
9d840540f   Anchit Jindal   fixed bugs and ne...
935
936
      		})
      	}
5983d987a   Kuldeep Arora   jetmargin api
937
938
939
940
941
942
943
944
945
946
  
          $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.getAircraft = function(company) {
5983d987a   Kuldeep Arora   jetmargin api
947
              $scope.selectedCompanyName = company;
9d840540f   Anchit Jindal   fixed bugs and ne...
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
              
              if ($scope.companyData.margin != null && $scope.companyData.marginAVGAS != null) {
                  fuelOrdersService.getFuelCost($scope.companyData.id).then(function(margins) {
                      $scope.marginList = margins;
                      //console.log('$scope.marginList', $scope.marginList);
                  })
              } else if ($scope.companyData.margin != null || $scope.companyData.marginAVGAS == null) {
                  fuelOrdersService.getATypeFuelPricing($scope.companyData.id).then(function(margins) {
                      $scope.marginList = margins;
                  })
              } else if ($scope.companyData.margin == null || $scope.companyData.marginAVGAS != null) {
                  fuelOrdersService.getVTypeFuelPricing($scope.companyData.id).then(function(margins) {
                      $scope.marginList = margins;
                  })
              }
              
              
          	$scope.selectedCompanyId = $scope.companyData.id;
              $scope.marginId = $scope.companyData.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;
                  })
5983d987a   Kuldeep Arora   jetmargin api
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
              }
  
          }
  
          $scope.setCost = function(cost) {
              //  console.log(cost);
              if (cost != null) {
                  var obj = JSON.parse(cost);
                  // console.log("0bj",obj)
                  $scope.order.fboCost = obj.cost;
              }
  
          }
  
          $scope.sourceList = [{
              source: "Direct Jet-A"
          }, {
              source: "Direct AVGAS 100LL"
          }];
          $scope.cancelData = function() {
676250262   Kuldeep Arora   enhancement fuel ...
997
              $('#demo-modal-4').css('display', '');
5983d987a   Kuldeep Arora   jetmargin api
998
999
1000
1001
          }
  
          $scope.setFuel = function() {
              $('#demo-modal-4').css('display', 'block');
676250262   Kuldeep Arora   enhancement fuel ...
1002

5983d987a   Kuldeep Arora   jetmargin api
1003
          }
676250262   Kuldeep Arora   enhancement fuel ...
1004

cf43d578a   Kuldeep Arora   delete company up...
1005
          /*delete company*/
5983d987a   Kuldeep Arora   jetmargin api
1006
1007
          var deletecompanyId = "";
          $scope.deleteComp = function(companyDataid) {
cf43d578a   Kuldeep Arora   delete company up...
1008
1009
1010
1011
              $('#delete2').css('display', 'block');
              //console.log("asda",companyDataid)
              deletecompanyId = companyDataid;
          }
1d7e82fdd   Anchit Jindal   fixed bug
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
          $scope.aircraftIdx = '';
          $scope.checkTail = function(tail, idx){
          	var data = "tail=" + tail + "&id=" + companyId;
          	$scope.aircraftIdx = idx;
          	ViewCompanyService.checkTail(data).then(function(result) {
                  if(result.error) {
                  	$scope.aircraftMessage = result.error;
                  	$scope.openAddAirCraftError();
                  } else if(result.warning) {
                  	$scope.aircraftMessage = result.warning;
                  	$scope.openAddAirCraftWarning();
                  }
              })
          }
cf43d578a   Kuldeep Arora   delete company up...
1026

1d7e82fdd   Anchit Jindal   fixed bug
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
          $scope.openAddAirCraftError = function() {
          	$('#addAirCraftError').css('display', 'block');
          }
          
          $scope.openAddAirCraftWarning = function() {
         	 	$('#addAirCraftWarning').css('display', 'block');
          }
          $scope.acceptAirCraftError = function() {
          	$('#addAirCraftWarning').css('display', 'none');
          }
          
          $scope.cancelAirCraftError = function() {
          	$scope.aircraftDetails[$scope.aircraftIdx].tail = '';
          	$('#addAirCraftWarning').css('display', 'none');
          	$('#addAirCraftError').css('display', 'none');
          }
          
5983d987a   Kuldeep Arora   jetmargin api
1044
          $scope.deleteCompanyData = function() {
cf43d578a   Kuldeep Arora   delete company up...
1045
              ViewCompanyService.deleteCompany(deletecompanyId).then(function(result) {
cf43d578a   Kuldeep Arora   delete company up...
1046

5983d987a   Kuldeep Arora   jetmargin api
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
                  $('#delete2').css('display', 'none');
                  if (result.success) {
                      toastr.success('' + result.success + '', {
                          closeButton: true
  
                      })
                  } else {
                      toastr.error('' + result.statusText + '', {
                          closeButton: true
  
                      })
                  }
                  $state.go('app.customers')
              })
          }
          $scope.cancelDelete = function() {
              $('#delete2').css('display', 'none');
          }
cf43d578a   Kuldeep Arora   delete company up...
1065

5983d987a   Kuldeep Arora   jetmargin api
1066
1067
          $scope.editJetMargin = function(aircraftData, type) {
              $scope.showLoader = true;
6c5a99488   Kuldeep Arora   analytics and fue...
1068
              if (type == 'jet') {
cca8fa318   Kuldeep Arora   aircraft display ...
1069
                  
5983d987a   Kuldeep Arora   jetmargin api
1070
                  var aircraftdataMargin = "marginId=" + aircraftData.aircraftsMargin.id + "&type=" + type;
cca8fa318   Kuldeep Arora   aircraft display ...
1071
                  
5983d987a   Kuldeep Arora   jetmargin api
1072
              } else {
5983d987a   Kuldeep Arora   jetmargin api
1073
                  var aircraftdataMargin = "marginId=" + aircraftData.aircraftsAVGASMargin.id + "&type=" + type;
cf43d578a   Kuldeep Arora   delete company up...
1074
              }
5983d987a   Kuldeep Arora   jetmargin api
1075
1076
1077
1078
1079
1080
1081
1082
  
              var id = aircraftData.id;
              ViewCompanyService.updateAircraftMargin(aircraftdataMargin, id).then(function(result) {
                  if (result != null && result.success) {
                      $scope.showLoader = false;
                      toastr.success('' + result.success + '', {
                          closeButton: true
                      })
bcd6c1025   Kuldeep Arora   aircraft display-...
1083
1084
                     // getAircraftWithMarginList();
                     getAircraftList();
5983d987a   Kuldeep Arora   jetmargin api
1085
1086
1087
1088
1089
1090
1091
1092
                  } else {
                      $scope.showLoader = false;
                      toastr.error('' + result.statusText + '', {
                          closeButton: true
                      })
                  }
              })
          }
cca8fa318   Kuldeep Arora   aircraft display ...
1093
1094
  
          /* //not used currently 
5983d987a   Kuldeep Arora   jetmargin api
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
          function getAircraftWithMarginList() {
              ViewCompanyService.getJetAMargin(companyId).then(function(result) {
                  $scope.contactAircraftList = result;
                  for (var i = 0; i < $scope.contactAircraftList.length; i++) {
                      if ($scope.contactAircraftList[i].aircraftsMargin != null) {
                          $scope.aircraftmargins.push({
                              'id': $scope.contactAircraftList[i].aircraftsMargin.id
                          })
                      }
                  }
                  if ($scope.aircraftmargins.length > 0) {
                      for (var i = 0; i < $scope.aircraftmargins.length; i++) {
                          if ($scope.aircraftmargins[i].id != $scope.companyData.masterMargin) {
                              $scope.multiple = true;
                              $scope.multipleMsg = true;
                              if ($scope.multiple) {
                                  $scope.companyData.masterMargin = "multiple";
                              }
                          }
                      }
                  }
cf43d578a   Kuldeep Arora   delete company up...
1116
              })
cca8fa318   Kuldeep Arora   aircraft display ...
1117
          }*/
40c8c308c   Kuldeep Arora   omit css
1118

40c8c308c   Kuldeep Arora   omit css
1119

5983d987a   Kuldeep Arora   jetmargin api
1120
      }]);