Blame view

app/partials/viewCompany/viewCompany.controller.js 32.6 KB
feacde5ff   Rishav   setup acuefuel in...
1
2
3
4
5
  
  'use strict';
  
   //Load controller
    angular.module('acufuel')
676250262   Kuldeep Arora   enhancement fuel ...
6
  	.controller('viewCompanyController', ['$scope','$uibModal', '$stateParams', 'ViewCompanyService', 'CustomersService', 'updateFuelManagerService', 'ViewFuelVendorService', 'ViewcontactService','$state','fuelOrdersService','NgTableParams', function($scope , $uibModal, $stateParams, ViewCompanyService, CustomersService, updateFuelManagerService, ViewFuelVendorService, ViewcontactService,$state,fuelOrdersService,NgTableParams) {
55e075d7e   Rishav   add contact, add ...
7
8
          $scope.data = {};
          $scope.data.priceEmail = true;
b1f6160d4   Rishav   add contact and a...
9
          $scope.aircraft = {};
3a9f4472b   Rishav   Implement contact...
10
          $scope.primayData = {};
d24318592   Rishav   changes and new i...
11
          $scope.showLoader = false;
ba1d39503   Swarn Singh   view company form...
12
          $scope.showUpdateBtn = false;
28af27a3f   Rishav   add fuelPriceapi
13
          $scope.userProfileId = JSON.parse(localStorage.getItem('userProfileId'));
97f8c67f9   Rishav Singla   ui select impplem...
14
          $scope.selected = [];
07328f442   Rishav Singla   new code added fo...
15
16
17
18
19
          $scope.jetShow = [];
          $scope.marginShow = [];
  
          $scope.jetShow[0] = true;
          $scope.marginShow[0] = true;
676250262   Kuldeep Arora   enhancement fuel ...
20
21
22
23
24
25
26
27
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
64
65
66
67
68
69
70
71
72
73
           $scope.dispatchOrder = {};
          $scope.dispatchOrder.fuelOrderList = [];
          $scope.statusFilterOptions = [];
          $scope.companyList = {};
          $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'
        }
       
        );
          
  
         /*Get AllCompany api is used from CustomersService*/ 
        getAllCompanies();
  
        function getAllCompanies(){
        CustomersService.getAllCompanies().then(function(result) {
          //console.log('log', result);
          $scope.companyList = result;
          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;
        })
      }
3a9f4472b   Rishav   Implement contact...
74

7152ff131   Rishav   model handle
75
76
77
78
79
          $(document).ready(function() {
              $("#reset").click(function() {
                  $("input").val("");
              });
          });
97f8c67f9   Rishav Singla   ui select impplem...
80
81
82
83
84
85
86
87
          $scope.values = [
            {'id': 1, 'first': 'Tenant/Base Customer'}, 
            {'id': 2, 'first': 'FuelerLinx Customer'},
            {'id': 3, 'first': 'CAA Member'}
          ];
  
          $scope.changeValue = function(selected){
            $scope.showUpdateBtn = true;
18dcf8f5c   Kuldeep Arora   adding contacts
88
           // console.log("data to be true", selected);
97f8c67f9   Rishav Singla   ui select impplem...
89
            for (var i=0;i<selected.length;i++){
18dcf8f5c   Kuldeep Arora   adding contacts
90
            //  console.log(selected[i])
97f8c67f9   Rishav Singla   ui select impplem...
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
              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;
              }
  
              if(selected[i] == 'CAA Member'){
                $scope.companyData.contractFuelVendor = true;
              }else{
                $scope.companyData.contractFuelVendor = false;
              }
cf43d578a   Kuldeep Arora   delete company up...
107
             // console.log($scope.companyData)
97f8c67f9   Rishav Singla   ui select impplem...
108
109
110
111
112
113
114
115
116
117
              
            }
  
          }
  
          // $scope.selected =[
          //   {'id': 1, 'first': 'Tenant/Base Customer'}, 
          //   {'id': 2, 'first': 'FuelerLinx Customer'},
          //   {'id': 3, 'first': 'CAA Member'}
          // ];
d1fe89776   Rishav Singla   view fuel vendor ...
118
119
120
          // CustomersService.getMargin().then(function(result) {
          //   $scope.marginList = result;
          // })
3a9f4472b   Rishav   Implement contact...
121

48ed0c7bb   Rishav   update company co...
122
          var value = "";
55e075d7e   Rishav   add contact, add ...
123
          var companyId = $stateParams.id;
a9a8f570d   Anchit Jindal   new desing implem...
124
125
126
          $scope.companyData = {};
          $scope.multipleMsg = false;
          $scope.companyData.masterMargin = "";
a9aef0b1c   Anchit Jindal   new changes imple...
127
          $scope.isGlobal = false;
e9a2edf03   Rishav   update custom field
128
129
          getCompanyDetail();
          function getCompanyDetail(){
05bfa28a2   Mr. Hot Foods   remove save butto...
130
            $scope.showLoader = true;
e9a2edf03   Rishav   update custom field
131
132
            ViewCompanyService.getCompany(companyId).then(function(result) {
              $scope.companyData = result;
a9aef0b1c   Anchit Jindal   new changes imple...
133
              $scope.isGlobal = result.global;
97f8c67f9   Rishav Singla   ui select impplem...
134
135
136
              if(result.global == true){
                $scope.companyData.global = true;
              }
e9a2edf03   Rishav   update custom field
137
138
139
              if(result.margin != null){
                 $scope.companyData.masterMargin = result.margin.id;
              }
a9a8f570d   Anchit Jindal   new desing implem...
140
141
142
              if(result.marginAVGAS != null){
                  $scope.companyData.avgasMargin = result.marginAVGAS.id;
               }
97f8c67f9   Rishav Singla   ui select impplem...
143
144
145
146
147
148
               
  
  
               if($scope.companyData.baseTenant){
                
                $scope.selected.push({'first': 'Tenant/Base Customer'})
cf43d578a   Kuldeep Arora   delete company up...
149
               // console.log("$scope.selected",$scope.selected)
97f8c67f9   Rishav Singla   ui select impplem...
150
151
152
153
154
  
               }
  
               if($scope.companyData.fuelerlinxCustomer){
                $scope.selected.push({'first': 'FuelerLinx Customer'})
cf43d578a   Kuldeep Arora   delete company up...
155
               // console.log("$scope.selected",$scope.selected)
97f8c67f9   Rishav Singla   ui select impplem...
156
157
158
159
               }
  
               if($scope.companyData.contractFuelVendor){
                $scope.selected.push({'first': 'CAA Member'})
cf43d578a   Kuldeep Arora   delete company up...
160
               // console.log("$scope.selected",$scope.selected)
97f8c67f9   Rishav Singla   ui select impplem...
161
               }
cf43d578a   Kuldeep Arora   delete company up...
162
              // console.log("$scope.companyData",$scope.companyData)
7ee64838c   Anchit Jindal   new desing implem...
163
              getAircraftList();
e9a2edf03   Rishav   update custom field
164
165
166
167
              $scope.showLoader = false;
            })
          }
          
55e075d7e   Rishav   add contact, add ...
168

74c8ae4bb   Rishav   remove old toogle...
169
          $scope.changeCompanyStatus = function(){
da24c95c8   Rishav Singla   confirmation mess...
170
171
172
173
174
175
176
177
178
              $('#delete3').css('display', 'block');
              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?'
              }
          }
  
          $scope.companyStatus = function(){
05bfa28a2   Mr. Hot Foods   remove save butto...
179
            $scope.showLoader = true;
3a9f4472b   Rishav   Implement contact...
180
181
              var statusData = "status=" + $scope.companyData.activate;
              ViewCompanyService.changeStatus(companyId, statusData).then(function(result) {
c555af312   Rishav   price email, comp...
182
                if(result.success){
da24c95c8   Rishav Singla   confirmation mess...
183
                    $('#delete3').css('display', 'none');
c555af312   Rishav   price email, comp...
184
185
186
                    toastr.success(''+result.success+'', {
                        closeButton: true
                    })
6efd9a0a8   Anchit Jindal   new desing changes
187
                    getContactList();
c555af312   Rishav   price email, comp...
188
                }
3a9f4472b   Rishav   Implement contact...
189
              })
05bfa28a2   Mr. Hot Foods   remove save butto...
190
              $scope.showLoader = false;
c555af312   Rishav   price email, comp...
191
          }
3a9f4472b   Rishav   Implement contact...
192

8670c5905   Jaideep Singh   new changes
193
          
da24c95c8   Rishav Singla   confirmation mess...
194
195
196
197
          $scope.cancelStatus = function(){
              $('#delete3').css('display', 'none');
              $scope.companyData.activate =  !$scope.companyData.activate;
          }
3a9f4472b   Rishav   Implement contact...
198
          
48ed0c7bb   Rishav   update company co...
199
200
201
202
203
204
          getContactList();
          function getContactList(){
            ViewCompanyService.getContact(companyId).then(function(result) {
              $scope.companyContactList = result;
            })
          }
a9a8f570d   Anchit Jindal   new desing implem...
205
          $scope.aircraftmargins = [];
7ee64838c   Anchit Jindal   new desing implem...
206
         
b1f6160d4   Rishav   add contact and a...
207
208
209
          function getAircraftList(){
            ViewCompanyService.getAircraft(companyId).then(function(result) {
              $scope.contactAircraftList = result;
a9a8f570d   Anchit Jindal   new desing implem...
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
              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";
                          }
                  	}
                  }
              }
b1f6160d4   Rishav   add contact and a...
228
229
            })
          }
b1f6160d4   Rishav   add contact and a...
230

55e075d7e   Rishav   add contact, add ...
231
232
233
          $scope.contactData = {};
          $scope.contactData.contactList = [];
          $scope.addContact = function(){
05bfa28a2   Mr. Hot Foods   remove save butto...
234
            $scope.showLoader = true;
55e075d7e   Rishav   add contact, add ...
235
236
            $scope.data.companyId = companyId;
            $scope.contactData.contactList.push($scope.data);
55e075d7e   Rishav   add contact, add ...
237
            ViewCompanyService.addContact($scope.contactData).then(function(result) {
18dcf8f5c   Kuldeep Arora   adding contacts
238
239
               //console.log("data==",$scope.contactData)
            // console.log(result)
3a9f4472b   Rishav   Implement contact...
240
              if(result.status == 200){
cf43d578a   Kuldeep Arora   delete company up...
241
                  
55e075d7e   Rishav   add contact, add ...
242
                  $('#contact-modal-3').modal('hide');
3a9f4472b   Rishav   Implement contact...
243
                  $scope.primayData.id = result.data;
d1fe89776   Rishav Singla   view fuel vendor ...
244
                  $scope.data = {};
3a9f4472b   Rishav   Implement contact...
245
                  $scope.sendPrimaryContact();
48ed0c7bb   Rishav   update company co...
246
                  getContactList();
18dcf8f5c   Kuldeep Arora   adding contacts
247
248
249
250
                   $scope.contactData.contactList = [];
                   $scope.data.email='';
                  //console.log("data2==",$scope.contactData)
                    //toastr.success(''+result.success+'', {
cf43d578a   Kuldeep Arora   delete company up...
251
252
253
                    toastr.success('Created Successfully',{
                          closeButton: true
                   })
55e075d7e   Rishav   add contact, add ...
254
255
256
257
258
259
              }else{
                toastr.error(''+result.statusText+'', {
                    closeButton: true
                  })
              }
            })
05bfa28a2   Mr. Hot Foods   remove save butto...
260
            $scope.showLoader = false;
55e075d7e   Rishav   add contact, add ...
261
          }
feacde5ff   Rishav   setup acuefuel in...
262

b1f6160d4   Rishav   add contact and a...
263
264
        getData();
        function getData(){
05bfa28a2   Mr. Hot Foods   remove save butto...
265
          $scope.showLoader = true;
b1f6160d4   Rishav   add contact and a...
266
267
268
          CustomersService.getAircraftMake().then(function(result) {
            $scope.aircraftMakeList = result;
          })
05bfa28a2   Mr. Hot Foods   remove save butto...
269
          $scope.showLoader = false;
b1f6160d4   Rishav   add contact and a...
270
271
        }
        
a4884cfe7   Rishav   add aircraft issu...
272
273
274
        $scope.clearAircrafts = function(){
          $scope.aircraftDetails = [];
          $scope.aircraftDetails = [{ 
b1f6160d4   Rishav   add contact and a...
275
276
277
              'tail':'',
              'make': '',
              'model': '',
3a9f4472b   Rishav   Implement contact...
278
              'sizeId' : '',
7ee64838c   Anchit Jindal   new desing implem...
279
280
              'marginId': '',
          	'avgasMarginId': ''
b1f6160d4   Rishav   add contact and a...
281
          }];
a4884cfe7   Rishav   add aircraft issu...
282
        }
b1f6160d4   Rishav   add contact and a...
283
      
a4884cfe7   Rishav   add aircraft issu...
284
285
286
287
288
289
        $scope.addNew = function(){
            $scope.aircraftDetails.push({ 
              'tail':'',
              'make': '',
              'model': '',
              'sizeId' : '',
7ee64838c   Anchit Jindal   new desing implem...
290
291
              'marginId': '',
          	'avgasMarginId': ''
a4884cfe7   Rishav   add aircraft issu...
292
            });
cf43d578a   Kuldeep Arora   delete company up...
293
          //  console.log($scope.aircraftDetails)
a4884cfe7   Rishav   add aircraft issu...
294
295
296
297
298
299
300
301
302
303
304
305
        };
  
        $scope.getModal = function(makeId, index){
        $scope.showLoader = true;
        $scope.aircraft.make = makeId;
          //var makeId = makeId;
          CustomersService.getModal($scope.aircraft.make).then(function(result) {
            $scope.showLoader = false;
            $scope.aircraftDetails[index].aircraftModalList = result;
            //$scope.aircraftDetails[index].model = $scope.aircraftModalList[0];
          })
        }
b1f6160d4   Rishav   add contact and a...
306

a4884cfe7   Rishav   add aircraft issu...
307
        $scope.getSize = function(model, index){
d24318592   Rishav   changes and new i...
308
          $scope.showLoader = true;
a4884cfe7   Rishav   add aircraft issu...
309
310
311
312
313
314
          CustomersService.getAircraftSize($scope.aircraft.make, model).then(function(result) {
            $scope.showLoader = false;
            $scope.aircraftDetails[index].aircraftSizeList = result;
            //$scope.aircraftDetails[index].size = $scope.aircraftSizeList[0];
          })
        }
b1f6160d4   Rishav   add contact and a...
315

a4884cfe7   Rishav   add aircraft issu...
316
317
318
319
320
321
322
323
324
325
        $scope.aircraftListData = {};
        //$scope.addData = [];
        $scope.saveCompanyData = function(){
          for(var i=0; i<$scope.aircraftDetails.length;i++){
            $scope.addData = [];
            $scope.addData.push({ 
                'tail': $scope.aircraftDetails[i].tail,
                'make': $scope.aircraftDetails[i].make,
                'model': $scope.aircraftDetails[i].model,
                'sizeId' : $scope.aircraftDetails[i].sizeId,
7ee64838c   Anchit Jindal   new desing implem...
326
327
                'marginId': $scope.aircraftDetails[i].marginId,
  	          'avgasMarginId': $scope.aircraftDetails[i].avgasMarginId
a4884cfe7   Rishav   add aircraft issu...
328
              });
b1f6160d4   Rishav   add contact and a...
329
          }
cf43d578a   Kuldeep Arora   delete company up...
330
          //console.log($scope.addData)
a4884cfe7   Rishav   add aircraft issu...
331
332
333
334
335
336
337
338
339
340
341
342
343
344
          $scope.aircraftListData.aircraftList = $scope.addData;
          $scope.aircraftListData.accountId = companyId;
          
          CustomersService.addAircraft($scope.aircraftListData).then(function(result) {
            if(result != null && result.success){
              toastr.success(''+result.success+'', {
                  closeButton: true
                })
                $('#aircraft-modal-3').modal('hide');
                getAircraftList();
            }else{
              toastr.error(''+result.statusText+'', {
                  closeButton: true
                })
b1f6160d4   Rishav   add contact and a...
345
            }
a4884cfe7   Rishav   add aircraft issu...
346
          });
b1f6160d4   Rishav   add contact and a...
347
            
a4884cfe7   Rishav   add aircraft issu...
348
349
350
351
352
353
354
355
356
357
358
359
360
        }
        $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;
        }
7152ff131   Rishav   model handle
361
362
363
        $scope.base = function(){
          $scope.showUpdateBtn = true;
        }
a4884cfe7   Rishav   add aircraft issu...
364
365
366
367
368
369
        $scope.addressChange = function(){
          $scope.showAddress = false;
          $scope.showUpdateBtn = true;
        }
  
        $scope.editData = function(inputName) {
cf43d578a   Kuldeep Arora   delete company up...
370
            //console.log($scope.companyData)
a4884cfe7   Rishav   add aircraft issu...
371
372
373
374
375
376
377
378
379
380
381
            $scope.showLoader = true;
            /*if(inputName == 'showNoteData'){
              $scope.showNoteData = true;
            }else if(inputName == 'showCompanyName'){
              $scope.showCompanyName = true;
            }else if(inputName == 'showAddress'){
              $scope.showAddress = true;              
            }*/
            $scope.showNoteData = true;
            $scope.showCompanyName = true;
            $scope.showAddress = true;
a9a8f570d   Anchit Jindal   new desing implem...
382
            var companyData = "companyName=" + $scope.companyData.companyName + "&masterMargin=" + $scope.companyData.masterMargin + "&avgasMargin=" + $scope.companyData.avgasMargin
a4884cfe7   Rishav   add aircraft issu...
383
384
385
386
              + "&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 
97f8c67f9   Rishav Singla   ui select impplem...
387
              + "&activate=" + $scope.companyData.activate + "&baseIcao=" + $scope.companyData.baseIcao + "&companyId=" + companyId + "&global=" + $scope.companyData.global;
a4884cfe7   Rishav   add aircraft issu...
388

cdf775224   Anchit Jindal   fixed company and...
389
            ViewCompanyService.updateCompany(companyData).then(function(result) {
b1f6160d4   Rishav   add contact and a...
390
391
              if(result != null && result.success){
                toastr.success(''+result.success+'', {
a4884cfe7   Rishav   add aircraft issu...
392
393
394
                  closeButton: true
                })
                $scope.showUpdateBtn = false;
cdf775224   Anchit Jindal   fixed company and...
395
                getCompanyDetail();
b1f6160d4   Rishav   add contact and a...
396
397
              }else{
                toastr.error(''+result.statusText+'', {
a4884cfe7   Rishav   add aircraft issu...
398
399
400
                  closeButton: true
                })
                $scope.showUpdateBtn = true;
b1f6160d4   Rishav   add contact and a...
401
              }
a4884cfe7   Rishav   add aircraft issu...
402
403
              $scope.showLoader = false;
            })
a4884cfe7   Rishav   add aircraft issu...
404
        }
b1f6160d4   Rishav   add contact and a...
405

7152ff131   Rishav   model handle
406
407
408
409
410
411
        $scope.cancelData = function(){
            $scope.showNoteData = true;
            $scope.showCompanyName = true;
            $scope.showAddress = true;
            $scope.showUpdateBtn = false;
        }
a4884cfe7   Rishav   add aircraft issu...
412
        $scope.sendMail = function(){
d1fe89776   Rishav Singla   view fuel vendor ...
413
          $('#confirm1').css('display', 'none');
a4884cfe7   Rishav   add aircraft issu...
414
415
416
417
418
          ViewCompanyService.sendMail(companyId).then(function(result) {
              if(result != null && result.success){
                toastr.success(''+result.success+'', {
                  closeButton: true
                })
a4884cfe7   Rishav   add aircraft issu...
419
420
421
422
423
424
425
              }else{
                toastr.error(''+result.statusText+'', {
                  closeButton: true
                })
              }
          })
        }
b1f6160d4   Rishav   add contact and a...
426

a4884cfe7   Rishav   add aircraft issu...
427
428
429
        $scope.openConfirmMail = function(){
          $('#confirm1').css('display', 'block');
        }
48ed0c7bb   Rishav   update company co...
430

b1f6160d4   Rishav   add contact and a...
431

a4884cfe7   Rishav   add aircraft issu...
432
433
434
        $scope.cancelAndCloseConfirm = function(){
          $('#confirm1').css('display', 'none');
        }
6efd9a0a8   Anchit Jindal   new desing changes
435
436
        
        $scope.primaryContact = false;
a4884cfe7   Rishav   add aircraft issu...
437
438
439
440
        $scope.cancelPrimaryContact = function(){
          $('#primaryContact').css('display', 'none');
          $scope.primaryContact = false;
        }
3a9f4472b   Rishav   Implement contact...
441

a4884cfe7   Rishav   add aircraft issu...
442
443
        $scope.checkPrimaryContact = function(){
          if($scope.primaryContact == true){
6efd9a0a8   Anchit Jindal   new desing changes
444
445
          	$scope.primaryContact = true;
          	ViewCompanyService.checkPrimaryContact(companyId).then(function(result) {
cf43d578a   Kuldeep Arora   delete company up...
446
          		//console.log(result)
6efd9a0a8   Anchit Jindal   new desing changes
447
448
449
450
  				if(result.status == 422){
  				  $('#primaryContact').css('display', 'block');
  				}
          	})
3a9f4472b   Rishav   Implement contact...
451
          }
a4884cfe7   Rishav   add aircraft issu...
452
        }
3a9f4472b   Rishav   Implement contact...
453

a4884cfe7   Rishav   add aircraft issu...
454
        $scope.sendPrimaryContact = function(){
a4884cfe7   Rishav   add aircraft issu...
455
456
457
          $('#primaryContact').css('display', 'none');
          if($scope.primayData.id != null || $scope.primayData.id != undefined){
            var priamryContactData = "companyContactId=" + $scope.primayData.id + "&primary=" + $scope.primaryContact;
3a9f4472b   Rishav   Implement contact...
458

a4884cfe7   Rishav   add aircraft issu...
459
            ViewCompanyService.addPrimaryContact(priamryContactData).then(function(result) {
cf43d578a   Kuldeep Arora   delete company up...
460
             // console.log(result)
a4884cfe7   Rishav   add aircraft issu...
461
            })
3a9f4472b   Rishav   Implement contact...
462
          }
a4884cfe7   Rishav   add aircraft issu...
463
464
          
        }
3a9f4472b   Rishav   Implement contact...
465

a4884cfe7   Rishav   add aircraft issu...
466
467
468
469
470
471
        var newContactName = "";
        $scope.updateData = ""
        $scope.showContact = function(data, value){
          $('#updateContact').css('display', 'block');
          $scope.updateData = data;
          newContactName = value;
cf43d578a   Kuldeep Arora   delete company up...
472
         // console.log($scope.updateData)
a4884cfe7   Rishav   add aircraft issu...
473
474
475
476
          if($scope.updateData.email == null){
            $scope.updateData.content = data.contactNumber;
          }else{
            $scope.updateData.content = data.email;
3a9f4472b   Rishav   Implement contact...
477
          }
a4884cfe7   Rishav   add aircraft issu...
478
        }
3a9f4472b   Rishav   Implement contact...
479

a4884cfe7   Rishav   add aircraft issu...
480
        $scope.acceptUpdateField = function(){
cf43d578a   Kuldeep Arora   delete company up...
481
         // console.log($scope.updateData)
a4884cfe7   Rishav   add aircraft issu...
482
483
484
485
486
487
488
489
          if($scope.updateData.content == undefined){
            toastr.error('Please add some content', {
              closeButton: true
            })
          }else{
            if(newContactName == 'phone'){
              var updateCustomData = "companyId=" + companyId + "&contactNumber=" + $scope.updateData.content + "&contactId=" + $scope.updateData.id
                + "&title=" + $scope.updateData.title;
e9a2edf03   Rishav   update custom field
490
            }else{
a4884cfe7   Rishav   add aircraft issu...
491
492
              var updateCustomData = "companyId=" + companyId + "&email=" + $scope.updateData.content + "&contactId=" + $scope.updateData.id
                + "&title=" + $scope.updateData.title;
e9a2edf03   Rishav   update custom field
493
            }
a4884cfe7   Rishav   add aircraft issu...
494
            ViewCompanyService.updateCustomField(updateCustomData).then(function(result) {
cf43d578a   Kuldeep Arora   delete company up...
495
              //console.log(result)
a4884cfe7   Rishav   add aircraft issu...
496
497
498
              if(result != null && result.success){
                $('#updateContact').css('display', 'none');
                getCompanyDetail();
e9a2edf03   Rishav   update custom field
499
              }
a4884cfe7   Rishav   add aircraft issu...
500
            })
e9a2edf03   Rishav   update custom field
501
          }
a4884cfe7   Rishav   add aircraft issu...
502
        }
e9a2edf03   Rishav   update custom field
503

a4884cfe7   Rishav   add aircraft issu...
504
505
506
        $scope.cancelUpdateField = function(){
          $('#updateContact').css('display', 'none');
        }
e9a2edf03   Rishav   update custom field
507

a4884cfe7   Rishav   add aircraft issu...
508
        $scope.showEditTier2 = function(number){
cf43d578a   Kuldeep Arora   delete company up...
509
         // console.log(number)
a4884cfe7   Rishav   add aircraft issu...
510
511
          $scope.contactNumber = number;
        }
8f88e39ed   Rishav   add custom field ...
512

e9a2edf03   Rishav   update custom field
513

a4884cfe7   Rishav   add aircraft issu...
514
515
        var contactName = '';
        $scope.addCustom = function(value){
cf43d578a   Kuldeep Arora   delete company up...
516
          //console.log(value)
a4884cfe7   Rishav   add aircraft issu...
517
518
519
          if(value != null){
            contactName = value;
            $('#customField').css('display', 'block');
3a9f4472b   Rishav   Implement contact...
520
          }
7152ff131   Rishav   model handle
521
          $scope.custom = {};
a4884cfe7   Rishav   add aircraft issu...
522
        }
8f88e39ed   Rishav   add custom field ...
523

a4884cfe7   Rishav   add aircraft issu...
524
525
526
        $scope.cancelCustomField = function(){
          $('#customField').css('display', 'none');
        }
7152ff131   Rishav   model handle
527
        
a4884cfe7   Rishav   add aircraft issu...
528
529
530
531
532
533
534
535
536
        $scope.acceptCustomField = function(){
          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;
3a9f4472b   Rishav   Implement contact...
537
            }else{
a4884cfe7   Rishav   add aircraft issu...
538
539
              var customData = "companyId=" + companyId + "&email=" + $scope.custom.content 
                + "&title=" + $scope.custom.title;
d24318592   Rishav   changes and new i...
540
            }
cf43d578a   Kuldeep Arora   delete company up...
541
           // console.log(customData.email)
a4884cfe7   Rishav   add aircraft issu...
542
            ViewCompanyService.addCustomField(customData).then(function(result) {
cf43d578a   Kuldeep Arora   delete company up...
543
             // console.log(result)
a4884cfe7   Rishav   add aircraft issu...
544
545
546
547
548
              if(result != null && result.success){
                $('#customField').css('display', 'none');
                getCompanyDetail();
              }
            })
3a9f4472b   Rishav   Implement contact...
549
          }
a4884cfe7   Rishav   add aircraft issu...
550
        }
28af27a3f   Rishav   add fuelPriceapi
551

7152ff131   Rishav   model handle
552
        updateFuelManagerService.getFuelPricingNew().then(function(result) {
28af27a3f   Rishav   add fuelPriceapi
553
554
          $scope.fuelPricing = result;
          for (var i = 0; i<$scope.fuelPricing.length; i++) {
7152ff131   Rishav   model handle
555
            if ($scope.fuelPricing[i].fuelPricing.expirationDate != null) {
a9e3a7365   Swarn Singh   fix issues on vie...
556
557
558
559
560
561
                $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;
28af27a3f   Rishav   add fuelPriceapi
562
563
564
            }
          }
        })
67044e31e   Rishav Singla   modify changes an...
565

da24c95c8   Rishav Singla   confirmation mess...
566
        var deleteAircraftId = "";
67044e31e   Rishav Singla   modify changes an...
567
        $scope.deleteAircraft = function(id){
da24c95c8   Rishav Singla   confirmation mess...
568
569
570
571
572
573
            $('#delete1').css('display', 'block');
            deleteAircraftId = id;
        }
  
        $scope.aircraftDelete = function(){
            ViewCompanyService.deleteAircraft(deleteAircraftId).then(function(result) {
cf43d578a   Kuldeep Arora   delete company up...
574
             // console.log(result)
67044e31e   Rishav Singla   modify changes an...
575
              getAircraftList();
6efd9a0a8   Anchit Jindal   new desing changes
576
              getCompanyDetail();
da24c95c8   Rishav Singla   confirmation mess...
577
              $('#delete1').css('display', 'none');
67044e31e   Rishav Singla   modify changes an...
578
579
            })
        }
da24c95c8   Rishav Singla   confirmation mess...
580
581
582
583
  
        $scope.cancelDelete = function(){
          $('#delete1').css('display', 'none');
        }
a9a8f570d   Anchit Jindal   new desing implem...
584
        
da24c95c8   Rishav Singla   confirmation mess...
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
      	CustomersService.getJetMargin($scope.userProfileId).then(function(result) {
    		  $scope.jetMarginList = result;
    		})
  
    		CustomersService.getAvgMargin($scope.userProfileId).then(function(result) {
    		  $scope.avgsMarginList = result;
    		})
  
         $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';
                    }
                }
            })
          }
a9a8f570d   Anchit Jindal   new desing implem...
608

da24c95c8   Rishav Singla   confirmation mess...
609
610
611
          $scope.cancelToogle = function(){
            $('#toogleMail').css('display', 'none');
          }
8670c5905   Jaideep Singh   new changes
612
613
  
           $scope.checkboxStatus = function(value){
cf43d578a   Kuldeep Arora   delete company up...
614
           //  console.log("checkbox",value)
8670c5905   Jaideep Singh   new changes
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
             $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.'
              }
  
              
          }
  
         $scope.fuelerCancelStatus = function(){
              $('#fuelerchange').css('display', 'none');
              $scope.companyData.fuelerlinxCustomer =  !$scope.companyData.fuelerlinxCustomer;
          }
  
          $scope.fuelerAcceptStatus = function(){
cdf775224   Anchit Jindal   fixed company and...
635
636
            $('#fuelerchange').css('display', 'none');
            $scope.showLoader = true;
8670c5905   Jaideep Singh   new changes
637
638
639
640
641
642
643
644
            var statusData;
            if($scope.companyData.fuelerlinxCustomer == false){
              statusData = "status=true";
            } else {
              statusData = "status=false";
            }
            ViewCompanyService.fuelerPricingChange(companyId, statusData).then(function(result) {
              if(result.success){
cdf775224   Anchit Jindal   fixed company and...
645
              	$scope.showLoader = false;
8670c5905   Jaideep Singh   new changes
646
647
648
649
650
651
652
                    
                    $scope.editData();
                    getContactList();
                    
                }
            })
          }
a4884cfe7   Rishav   add aircraft issu...
653
          
cdf775224   Anchit Jindal   fixed company and...
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
          $scope.updateOmit = function(fuel, omit) {
        	  $scope.fuelData = {};
        	  $scope.fuelData.expirationDate = new Date(fuel.expirationDate);
        	  $scope.fuelData.id = fuel.id;
        	  $scope.fuelData.omit = fuel.omit;
        	  $scope.fuelData.papMargin = fuel.papMargin;
        	  $scope.fuelData.papTotal = fuel.papTotal;
        	  $scope.fuelData.cost = fuel.cost;
        	  ViewFuelVendorService.omitFuelPricing($scope.fuelData).then(function(result) {
              if(result.success){
            	  toastr.success(''+result.success+'', {
                      closeButton: true
                  })
              }else{
            	  toastr.error(''+result.statusText+'', {
            		  closeButton: true
            	  })
              }
        	  })
          }
07328f442   Rishav Singla   new code added fo...
674
675
676
  
         // $scope.aircraftData = {}
          $scope.checkJetWithTail = function(tail, index){
cf43d578a   Kuldeep Arora   delete company up...
677
          // console.log("tail==============",tail, index)
07328f442   Rishav Singla   new code added fo...
678
            ViewCompanyService.checkJetType(tail).then(function(result) {
cf43d578a   Kuldeep Arora   delete company up...
679
            //  console.log("result",result)
07328f442   Rishav Singla   new code added fo...
680
681
682
683
684
685
686
687
688
              if(result.jetA == "true"){
                $scope.jetShow[index] = false;
                $scope.marginShow[index] = true;
              }else{
                $scope.jetShow[index] = true;
                $scope.marginShow[index] = false;
              }
            })
          }
cf43d578a   Kuldeep Arora   delete company up...
689

676250262   Kuldeep Arora   enhancement fuel ...
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
721
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
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
          /*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();
                }
  
              })
             
            })
       }
       
       $scope.getOrders();
  
      $scope.addFuelData = function() {
         $scope.showLoader = true;
  
       if ($scope.order.priceQuote === null || $scope.order.priceQuote == '') {
           //  console.log("valid");
             $scope.showLoader = false;
             toastr.error('Please select Company and Price Quote.', {
                closeButton: true
              })
       }else{
  
        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("fuel data---",$scope.fuelData)
          //console.log("oder data",$scope.dispatchOrder)
          //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.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){
  
        $scope.selectedCompanyName = company;
        //$scope.showLoader = true;
      //  console.log("id",company)
        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);
           // console.log("0bj",obj)
            $scope.order.fboCost = obj.cost;
          }
            
        }
  
       $scope.sourceList = [{source:"Direct Jet-A"},{source:"Direct AVGAS 100LL"}];
       $scope.cancelData = function() {
              $('#demo-modal-4').css('display', '');
        }
  
        $scope.setFuel = function(){
           $('#demo-modal-4').css('display', 'block');
        
        }
cf43d578a   Kuldeep Arora   delete company up...
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
  
  
          /*delete company*/
           var deletecompanyId = "";
          $scope.deleteComp = function(companyDataid){
              $('#delete2').css('display', 'block');
              //console.log("asda",companyDataid)
              deletecompanyId = companyDataid;
          }
  
          $scope.deleteCompanyData = function(){
              ViewCompanyService.deleteCompany(deletecompanyId).then(function(result) {
                     
                $('#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');
        }
cdf775224   Anchit Jindal   fixed company and...
893
          
55e075d7e   Rishav   add contact, add ...
894
    }]);