Blame view

app/partials/viewCompany/viewCompany.controller.js 23.7 KB
feacde5ff   Rishav   setup acuefuel in...
1
2
3
4
5
  
  'use strict';
  
   //Load controller
    angular.module('acufuel')
cf43d578a   Kuldeep Arora   delete company up...
6
  	.controller('viewCompanyController', ['$scope','$uibModal', '$stateParams', 'ViewCompanyService', 'CustomersService', 'updateFuelManagerService', 'ViewFuelVendorService', 'ViewcontactService','$state', function($scope , $uibModal, $stateParams, ViewCompanyService, CustomersService, updateFuelManagerService, ViewFuelVendorService, ViewcontactService,$state) {
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;
3a9f4472b   Rishav   Implement contact...
20

7152ff131   Rishav   model handle
21
22
23
24
25
          $(document).ready(function() {
              $("#reset").click(function() {
                  $("input").val("");
              });
          });
97f8c67f9   Rishav Singla   ui select impplem...
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
          $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;
            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;
              }
  
              if(selected[i] == 'CAA Member'){
                $scope.companyData.contractFuelVendor = true;
              }else{
                $scope.companyData.contractFuelVendor = false;
              }
cf43d578a   Kuldeep Arora   delete company up...
53
             // console.log($scope.companyData)
97f8c67f9   Rishav Singla   ui select impplem...
54
55
56
57
58
59
60
61
62
63
              
            }
  
          }
  
          // $scope.selected =[
          //   {'id': 1, 'first': 'Tenant/Base Customer'}, 
          //   {'id': 2, 'first': 'FuelerLinx Customer'},
          //   {'id': 3, 'first': 'CAA Member'}
          // ];
d1fe89776   Rishav Singla   view fuel vendor ...
64
65
66
          // CustomersService.getMargin().then(function(result) {
          //   $scope.marginList = result;
          // })
3a9f4472b   Rishav   Implement contact...
67

48ed0c7bb   Rishav   update company co...
68
          var value = "";
55e075d7e   Rishav   add contact, add ...
69
          var companyId = $stateParams.id;
a9a8f570d   Anchit Jindal   new desing implem...
70
71
72
          $scope.companyData = {};
          $scope.multipleMsg = false;
          $scope.companyData.masterMargin = "";
a9aef0b1c   Anchit Jindal   new changes imple...
73
          $scope.isGlobal = false;
e9a2edf03   Rishav   update custom field
74
75
          getCompanyDetail();
          function getCompanyDetail(){
05bfa28a2   Mr. Hot Foods   remove save butto...
76
            $scope.showLoader = true;
e9a2edf03   Rishav   update custom field
77
78
            ViewCompanyService.getCompany(companyId).then(function(result) {
              $scope.companyData = result;
a9aef0b1c   Anchit Jindal   new changes imple...
79
              $scope.isGlobal = result.global;
97f8c67f9   Rishav Singla   ui select impplem...
80
81
82
              if(result.global == true){
                $scope.companyData.global = true;
              }
e9a2edf03   Rishav   update custom field
83
84
85
              if(result.margin != null){
                 $scope.companyData.masterMargin = result.margin.id;
              }
a9a8f570d   Anchit Jindal   new desing implem...
86
87
88
              if(result.marginAVGAS != null){
                  $scope.companyData.avgasMargin = result.marginAVGAS.id;
               }
97f8c67f9   Rishav Singla   ui select impplem...
89
90
91
92
93
94
               
  
  
               if($scope.companyData.baseTenant){
                
                $scope.selected.push({'first': 'Tenant/Base Customer'})
cf43d578a   Kuldeep Arora   delete company up...
95
               // console.log("$scope.selected",$scope.selected)
97f8c67f9   Rishav Singla   ui select impplem...
96
97
98
99
100
  
               }
  
               if($scope.companyData.fuelerlinxCustomer){
                $scope.selected.push({'first': 'FuelerLinx Customer'})
cf43d578a   Kuldeep Arora   delete company up...
101
               // console.log("$scope.selected",$scope.selected)
97f8c67f9   Rishav Singla   ui select impplem...
102
103
104
105
               }
  
               if($scope.companyData.contractFuelVendor){
                $scope.selected.push({'first': 'CAA Member'})
cf43d578a   Kuldeep Arora   delete company up...
106
               // console.log("$scope.selected",$scope.selected)
97f8c67f9   Rishav Singla   ui select impplem...
107
               }
cf43d578a   Kuldeep Arora   delete company up...
108
              // console.log("$scope.companyData",$scope.companyData)
7ee64838c   Anchit Jindal   new desing implem...
109
              getAircraftList();
e9a2edf03   Rishav   update custom field
110
111
112
113
              $scope.showLoader = false;
            })
          }
          
55e075d7e   Rishav   add contact, add ...
114

74c8ae4bb   Rishav   remove old toogle...
115
          $scope.changeCompanyStatus = function(){
da24c95c8   Rishav Singla   confirmation mess...
116
117
118
119
120
121
122
123
124
              $('#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...
125
            $scope.showLoader = true;
3a9f4472b   Rishav   Implement contact...
126
127
              var statusData = "status=" + $scope.companyData.activate;
              ViewCompanyService.changeStatus(companyId, statusData).then(function(result) {
c555af312   Rishav   price email, comp...
128
                if(result.success){
da24c95c8   Rishav Singla   confirmation mess...
129
                    $('#delete3').css('display', 'none');
c555af312   Rishav   price email, comp...
130
131
132
                    toastr.success(''+result.success+'', {
                        closeButton: true
                    })
6efd9a0a8   Anchit Jindal   new desing changes
133
                    getContactList();
c555af312   Rishav   price email, comp...
134
                }
3a9f4472b   Rishav   Implement contact...
135
              })
05bfa28a2   Mr. Hot Foods   remove save butto...
136
              $scope.showLoader = false;
c555af312   Rishav   price email, comp...
137
          }
3a9f4472b   Rishav   Implement contact...
138

8670c5905   Jaideep Singh   new changes
139
          
da24c95c8   Rishav Singla   confirmation mess...
140
141
142
143
          $scope.cancelStatus = function(){
              $('#delete3').css('display', 'none');
              $scope.companyData.activate =  !$scope.companyData.activate;
          }
3a9f4472b   Rishav   Implement contact...
144
          
48ed0c7bb   Rishav   update company co...
145
146
147
148
149
150
          getContactList();
          function getContactList(){
            ViewCompanyService.getContact(companyId).then(function(result) {
              $scope.companyContactList = result;
            })
          }
a9a8f570d   Anchit Jindal   new desing implem...
151
          $scope.aircraftmargins = [];
7ee64838c   Anchit Jindal   new desing implem...
152
         
b1f6160d4   Rishav   add contact and a...
153
154
155
          function getAircraftList(){
            ViewCompanyService.getAircraft(companyId).then(function(result) {
              $scope.contactAircraftList = result;
a9a8f570d   Anchit Jindal   new desing implem...
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
              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...
174
175
            })
          }
b1f6160d4   Rishav   add contact and a...
176

55e075d7e   Rishav   add contact, add ...
177
178
179
          $scope.contactData = {};
          $scope.contactData.contactList = [];
          $scope.addContact = function(){
05bfa28a2   Mr. Hot Foods   remove save butto...
180
            $scope.showLoader = true;
55e075d7e   Rishav   add contact, add ...
181
182
            $scope.data.companyId = companyId;
            $scope.contactData.contactList.push($scope.data);
55e075d7e   Rishav   add contact, add ...
183
            ViewCompanyService.addContact($scope.contactData).then(function(result) {
cf43d578a   Kuldeep Arora   delete company up...
184
             console.log(result)
3a9f4472b   Rishav   Implement contact...
185
              if(result.status == 200){
cf43d578a   Kuldeep Arora   delete company up...
186
                  
55e075d7e   Rishav   add contact, add ...
187
                  $('#contact-modal-3').modal('hide');
3a9f4472b   Rishav   Implement contact...
188
                  $scope.primayData.id = result.data;
d1fe89776   Rishav Singla   view fuel vendor ...
189
                  $scope.data = {};
3a9f4472b   Rishav   Implement contact...
190
                  $scope.sendPrimaryContact();
48ed0c7bb   Rishav   update company co...
191
                  getContactList();
cf43d578a   Kuldeep Arora   delete company up...
192
193
194
195
                  // toastr.success(''+result.success+'', {
                    toastr.success('Created Successfully',{
                          closeButton: true
                   })
55e075d7e   Rishav   add contact, add ...
196
197
198
199
200
201
              }else{
                toastr.error(''+result.statusText+'', {
                    closeButton: true
                  })
              }
            })
05bfa28a2   Mr. Hot Foods   remove save butto...
202
            $scope.showLoader = false;
55e075d7e   Rishav   add contact, add ...
203
          }
feacde5ff   Rishav   setup acuefuel in...
204

b1f6160d4   Rishav   add contact and a...
205
206
        getData();
        function getData(){
05bfa28a2   Mr. Hot Foods   remove save butto...
207
          $scope.showLoader = true;
b1f6160d4   Rishav   add contact and a...
208
209
210
          CustomersService.getAircraftMake().then(function(result) {
            $scope.aircraftMakeList = result;
          })
05bfa28a2   Mr. Hot Foods   remove save butto...
211
          $scope.showLoader = false;
b1f6160d4   Rishav   add contact and a...
212
213
        }
        
a4884cfe7   Rishav   add aircraft issu...
214
215
216
        $scope.clearAircrafts = function(){
          $scope.aircraftDetails = [];
          $scope.aircraftDetails = [{ 
b1f6160d4   Rishav   add contact and a...
217
218
219
              'tail':'',
              'make': '',
              'model': '',
3a9f4472b   Rishav   Implement contact...
220
              'sizeId' : '',
7ee64838c   Anchit Jindal   new desing implem...
221
222
              'marginId': '',
          	'avgasMarginId': ''
b1f6160d4   Rishav   add contact and a...
223
          }];
a4884cfe7   Rishav   add aircraft issu...
224
        }
b1f6160d4   Rishav   add contact and a...
225
      
a4884cfe7   Rishav   add aircraft issu...
226
227
228
229
230
231
        $scope.addNew = function(){
            $scope.aircraftDetails.push({ 
              'tail':'',
              'make': '',
              'model': '',
              'sizeId' : '',
7ee64838c   Anchit Jindal   new desing implem...
232
233
              'marginId': '',
          	'avgasMarginId': ''
a4884cfe7   Rishav   add aircraft issu...
234
            });
cf43d578a   Kuldeep Arora   delete company up...
235
          //  console.log($scope.aircraftDetails)
a4884cfe7   Rishav   add aircraft issu...
236
237
238
239
240
241
242
243
244
245
246
247
        };
  
        $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...
248

a4884cfe7   Rishav   add aircraft issu...
249
        $scope.getSize = function(model, index){
d24318592   Rishav   changes and new i...
250
          $scope.showLoader = true;
a4884cfe7   Rishav   add aircraft issu...
251
252
253
254
255
256
          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...
257

a4884cfe7   Rishav   add aircraft issu...
258
259
260
261
262
263
264
265
266
267
        $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...
268
269
                'marginId': $scope.aircraftDetails[i].marginId,
  	          'avgasMarginId': $scope.aircraftDetails[i].avgasMarginId
a4884cfe7   Rishav   add aircraft issu...
270
              });
b1f6160d4   Rishav   add contact and a...
271
          }
cf43d578a   Kuldeep Arora   delete company up...
272
          //console.log($scope.addData)
a4884cfe7   Rishav   add aircraft issu...
273
274
275
276
277
278
279
280
281
282
283
284
285
286
          $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...
287
            }
a4884cfe7   Rishav   add aircraft issu...
288
          });
b1f6160d4   Rishav   add contact and a...
289
            
a4884cfe7   Rishav   add aircraft issu...
290
291
292
293
294
295
296
297
298
299
300
301
302
        }
        $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
303
304
305
        $scope.base = function(){
          $scope.showUpdateBtn = true;
        }
a4884cfe7   Rishav   add aircraft issu...
306
307
308
309
310
311
        $scope.addressChange = function(){
          $scope.showAddress = false;
          $scope.showUpdateBtn = true;
        }
  
        $scope.editData = function(inputName) {
cf43d578a   Kuldeep Arora   delete company up...
312
            //console.log($scope.companyData)
a4884cfe7   Rishav   add aircraft issu...
313
314
315
316
317
318
319
320
321
322
323
            $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...
324
            var companyData = "companyName=" + $scope.companyData.companyName + "&masterMargin=" + $scope.companyData.masterMargin + "&avgasMargin=" + $scope.companyData.avgasMargin
a4884cfe7   Rishav   add aircraft issu...
325
326
327
328
              + "&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...
329
              + "&activate=" + $scope.companyData.activate + "&baseIcao=" + $scope.companyData.baseIcao + "&companyId=" + companyId + "&global=" + $scope.companyData.global;
a4884cfe7   Rishav   add aircraft issu...
330

cdf775224   Anchit Jindal   fixed company and...
331
            ViewCompanyService.updateCompany(companyData).then(function(result) {
b1f6160d4   Rishav   add contact and a...
332
333
              if(result != null && result.success){
                toastr.success(''+result.success+'', {
a4884cfe7   Rishav   add aircraft issu...
334
335
336
                  closeButton: true
                })
                $scope.showUpdateBtn = false;
cdf775224   Anchit Jindal   fixed company and...
337
                getCompanyDetail();
b1f6160d4   Rishav   add contact and a...
338
339
              }else{
                toastr.error(''+result.statusText+'', {
a4884cfe7   Rishav   add aircraft issu...
340
341
342
                  closeButton: true
                })
                $scope.showUpdateBtn = true;
b1f6160d4   Rishav   add contact and a...
343
              }
a4884cfe7   Rishav   add aircraft issu...
344
345
              $scope.showLoader = false;
            })
a4884cfe7   Rishav   add aircraft issu...
346
        }
b1f6160d4   Rishav   add contact and a...
347

7152ff131   Rishav   model handle
348
349
350
351
352
353
        $scope.cancelData = function(){
            $scope.showNoteData = true;
            $scope.showCompanyName = true;
            $scope.showAddress = true;
            $scope.showUpdateBtn = false;
        }
a4884cfe7   Rishav   add aircraft issu...
354
        $scope.sendMail = function(){
d1fe89776   Rishav Singla   view fuel vendor ...
355
          $('#confirm1').css('display', 'none');
a4884cfe7   Rishav   add aircraft issu...
356
357
358
359
360
          ViewCompanyService.sendMail(companyId).then(function(result) {
              if(result != null && result.success){
                toastr.success(''+result.success+'', {
                  closeButton: true
                })
a4884cfe7   Rishav   add aircraft issu...
361
362
363
364
365
366
367
              }else{
                toastr.error(''+result.statusText+'', {
                  closeButton: true
                })
              }
          })
        }
b1f6160d4   Rishav   add contact and a...
368

a4884cfe7   Rishav   add aircraft issu...
369
370
371
        $scope.openConfirmMail = function(){
          $('#confirm1').css('display', 'block');
        }
48ed0c7bb   Rishav   update company co...
372

b1f6160d4   Rishav   add contact and a...
373

a4884cfe7   Rishav   add aircraft issu...
374
375
376
        $scope.cancelAndCloseConfirm = function(){
          $('#confirm1').css('display', 'none');
        }
6efd9a0a8   Anchit Jindal   new desing changes
377
378
        
        $scope.primaryContact = false;
a4884cfe7   Rishav   add aircraft issu...
379
380
381
382
        $scope.cancelPrimaryContact = function(){
          $('#primaryContact').css('display', 'none');
          $scope.primaryContact = false;
        }
3a9f4472b   Rishav   Implement contact...
383

a4884cfe7   Rishav   add aircraft issu...
384
385
        $scope.checkPrimaryContact = function(){
          if($scope.primaryContact == true){
6efd9a0a8   Anchit Jindal   new desing changes
386
387
          	$scope.primaryContact = true;
          	ViewCompanyService.checkPrimaryContact(companyId).then(function(result) {
cf43d578a   Kuldeep Arora   delete company up...
388
          		//console.log(result)
6efd9a0a8   Anchit Jindal   new desing changes
389
390
391
392
  				if(result.status == 422){
  				  $('#primaryContact').css('display', 'block');
  				}
          	})
3a9f4472b   Rishav   Implement contact...
393
          }
a4884cfe7   Rishav   add aircraft issu...
394
        }
3a9f4472b   Rishav   Implement contact...
395

a4884cfe7   Rishav   add aircraft issu...
396
        $scope.sendPrimaryContact = function(){
a4884cfe7   Rishav   add aircraft issu...
397
398
399
          $('#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...
400

a4884cfe7   Rishav   add aircraft issu...
401
            ViewCompanyService.addPrimaryContact(priamryContactData).then(function(result) {
cf43d578a   Kuldeep Arora   delete company up...
402
             // console.log(result)
a4884cfe7   Rishav   add aircraft issu...
403
            })
3a9f4472b   Rishav   Implement contact...
404
          }
a4884cfe7   Rishav   add aircraft issu...
405
406
          
        }
3a9f4472b   Rishav   Implement contact...
407

a4884cfe7   Rishav   add aircraft issu...
408
409
410
411
412
413
        var newContactName = "";
        $scope.updateData = ""
        $scope.showContact = function(data, value){
          $('#updateContact').css('display', 'block');
          $scope.updateData = data;
          newContactName = value;
cf43d578a   Kuldeep Arora   delete company up...
414
         // console.log($scope.updateData)
a4884cfe7   Rishav   add aircraft issu...
415
416
417
418
          if($scope.updateData.email == null){
            $scope.updateData.content = data.contactNumber;
          }else{
            $scope.updateData.content = data.email;
3a9f4472b   Rishav   Implement contact...
419
          }
a4884cfe7   Rishav   add aircraft issu...
420
        }
3a9f4472b   Rishav   Implement contact...
421

a4884cfe7   Rishav   add aircraft issu...
422
        $scope.acceptUpdateField = function(){
cf43d578a   Kuldeep Arora   delete company up...
423
         // console.log($scope.updateData)
a4884cfe7   Rishav   add aircraft issu...
424
425
426
427
428
429
430
431
          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
432
            }else{
a4884cfe7   Rishav   add aircraft issu...
433
434
              var updateCustomData = "companyId=" + companyId + "&email=" + $scope.updateData.content + "&contactId=" + $scope.updateData.id
                + "&title=" + $scope.updateData.title;
e9a2edf03   Rishav   update custom field
435
            }
a4884cfe7   Rishav   add aircraft issu...
436
            ViewCompanyService.updateCustomField(updateCustomData).then(function(result) {
cf43d578a   Kuldeep Arora   delete company up...
437
              //console.log(result)
a4884cfe7   Rishav   add aircraft issu...
438
439
440
              if(result != null && result.success){
                $('#updateContact').css('display', 'none');
                getCompanyDetail();
e9a2edf03   Rishav   update custom field
441
              }
a4884cfe7   Rishav   add aircraft issu...
442
            })
e9a2edf03   Rishav   update custom field
443
          }
a4884cfe7   Rishav   add aircraft issu...
444
        }
e9a2edf03   Rishav   update custom field
445

a4884cfe7   Rishav   add aircraft issu...
446
447
448
        $scope.cancelUpdateField = function(){
          $('#updateContact').css('display', 'none');
        }
e9a2edf03   Rishav   update custom field
449

a4884cfe7   Rishav   add aircraft issu...
450
        $scope.showEditTier2 = function(number){
cf43d578a   Kuldeep Arora   delete company up...
451
         // console.log(number)
a4884cfe7   Rishav   add aircraft issu...
452
453
          $scope.contactNumber = number;
        }
8f88e39ed   Rishav   add custom field ...
454

e9a2edf03   Rishav   update custom field
455

a4884cfe7   Rishav   add aircraft issu...
456
457
        var contactName = '';
        $scope.addCustom = function(value){
cf43d578a   Kuldeep Arora   delete company up...
458
          //console.log(value)
a4884cfe7   Rishav   add aircraft issu...
459
460
461
          if(value != null){
            contactName = value;
            $('#customField').css('display', 'block');
3a9f4472b   Rishav   Implement contact...
462
          }
7152ff131   Rishav   model handle
463
          $scope.custom = {};
a4884cfe7   Rishav   add aircraft issu...
464
        }
8f88e39ed   Rishav   add custom field ...
465

a4884cfe7   Rishav   add aircraft issu...
466
467
468
        $scope.cancelCustomField = function(){
          $('#customField').css('display', 'none');
        }
7152ff131   Rishav   model handle
469
        
a4884cfe7   Rishav   add aircraft issu...
470
471
472
473
474
475
476
477
478
        $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...
479
            }else{
a4884cfe7   Rishav   add aircraft issu...
480
481
              var customData = "companyId=" + companyId + "&email=" + $scope.custom.content 
                + "&title=" + $scope.custom.title;
d24318592   Rishav   changes and new i...
482
            }
cf43d578a   Kuldeep Arora   delete company up...
483
           // console.log(customData.email)
a4884cfe7   Rishav   add aircraft issu...
484
            ViewCompanyService.addCustomField(customData).then(function(result) {
cf43d578a   Kuldeep Arora   delete company up...
485
             // console.log(result)
a4884cfe7   Rishav   add aircraft issu...
486
487
488
489
490
              if(result != null && result.success){
                $('#customField').css('display', 'none');
                getCompanyDetail();
              }
            })
3a9f4472b   Rishav   Implement contact...
491
          }
a4884cfe7   Rishav   add aircraft issu...
492
        }
28af27a3f   Rishav   add fuelPriceapi
493

7152ff131   Rishav   model handle
494
        updateFuelManagerService.getFuelPricingNew().then(function(result) {
28af27a3f   Rishav   add fuelPriceapi
495
496
          $scope.fuelPricing = result;
          for (var i = 0; i<$scope.fuelPricing.length; i++) {
7152ff131   Rishav   model handle
497
            if ($scope.fuelPricing[i].fuelPricing.expirationDate != null) {
a9e3a7365   Swarn Singh   fix issues on vie...
498
499
500
501
502
503
                $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
504
505
506
            }
          }
        })
67044e31e   Rishav Singla   modify changes an...
507

da24c95c8   Rishav Singla   confirmation mess...
508
        var deleteAircraftId = "";
67044e31e   Rishav Singla   modify changes an...
509
        $scope.deleteAircraft = function(id){
da24c95c8   Rishav Singla   confirmation mess...
510
511
512
513
514
515
            $('#delete1').css('display', 'block');
            deleteAircraftId = id;
        }
  
        $scope.aircraftDelete = function(){
            ViewCompanyService.deleteAircraft(deleteAircraftId).then(function(result) {
cf43d578a   Kuldeep Arora   delete company up...
516
             // console.log(result)
67044e31e   Rishav Singla   modify changes an...
517
              getAircraftList();
6efd9a0a8   Anchit Jindal   new desing changes
518
              getCompanyDetail();
da24c95c8   Rishav Singla   confirmation mess...
519
              $('#delete1').css('display', 'none');
67044e31e   Rishav Singla   modify changes an...
520
521
            })
        }
da24c95c8   Rishav Singla   confirmation mess...
522
523
524
525
  
        $scope.cancelDelete = function(){
          $('#delete1').css('display', 'none');
        }
a9a8f570d   Anchit Jindal   new desing implem...
526
        
da24c95c8   Rishav Singla   confirmation mess...
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
      	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...
550

da24c95c8   Rishav Singla   confirmation mess...
551
552
553
          $scope.cancelToogle = function(){
            $('#toogleMail').css('display', 'none');
          }
8670c5905   Jaideep Singh   new changes
554
555
  
           $scope.checkboxStatus = function(value){
cf43d578a   Kuldeep Arora   delete company up...
556
           //  console.log("checkbox",value)
8670c5905   Jaideep Singh   new changes
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
             $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...
577
578
            $('#fuelerchange').css('display', 'none');
            $scope.showLoader = true;
8670c5905   Jaideep Singh   new changes
579
580
581
582
583
584
585
586
            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...
587
              	$scope.showLoader = false;
8670c5905   Jaideep Singh   new changes
588
589
590
591
592
593
594
                    
                    $scope.editData();
                    getContactList();
                    
                }
            })
          }
a4884cfe7   Rishav   add aircraft issu...
595
          
cdf775224   Anchit Jindal   fixed company and...
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
          $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...
616
617
618
  
         // $scope.aircraftData = {}
          $scope.checkJetWithTail = function(tail, index){
cf43d578a   Kuldeep Arora   delete company up...
619
          // console.log("tail==============",tail, index)
07328f442   Rishav Singla   new code added fo...
620
            ViewCompanyService.checkJetType(tail).then(function(result) {
cf43d578a   Kuldeep Arora   delete company up...
621
            //  console.log("result",result)
07328f442   Rishav Singla   new code added fo...
622
623
624
625
626
627
628
629
630
              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...
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
  
  
  
          /*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...
663
          
55e075d7e   Rishav   add contact, add ...
664
    }]);