Blame view

app/partials/viewCompany/viewCompany.controller.js 15.2 KB
feacde5ff   Rishav   setup acuefuel in...
1
2
3
4
5
  
  'use strict';
  
   //Load controller
    angular.module('acufuel')
28af27a3f   Rishav   add fuelPriceapi
6
  	.controller('viewCompanyController', ['$scope','$uibModal', '$stateParams', 'ViewCompanyService', 'CustomersService', 'updateFuelManagerService', function($scope , $uibModal, $stateParams, ViewCompanyService, CustomersService, updateFuelManagerService) {
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
13
          $scope.showLoader = true;
          $scope.showUpdateBtn = false;
28af27a3f   Rishav   add fuelPriceapi
14
          $scope.userProfileId = JSON.parse(localStorage.getItem('userProfileId'));
3a9f4472b   Rishav   Implement contact...
15

7152ff131   Rishav   model handle
16
17
18
19
20
          $(document).ready(function() {
              $("#reset").click(function() {
                  $("input").val("");
              });
          });
3a9f4472b   Rishav   Implement contact...
21
22
23
          CustomersService.getMargin().then(function(result) {
            $scope.marginList = result;
          })
48ed0c7bb   Rishav   update company co...
24
          var value = "";
55e075d7e   Rishav   add contact, add ...
25
          var companyId = $stateParams.id;
a9a8f570d   Anchit Jindal   new desing implem...
26
27
28
          $scope.companyData = {};
          $scope.multipleMsg = false;
          $scope.companyData.masterMargin = "";
e9a2edf03   Rishav   update custom field
29
30
31
32
33
34
35
          getCompanyDetail();
          function getCompanyDetail(){
            ViewCompanyService.getCompany(companyId).then(function(result) {
              $scope.companyData = result;
              if(result.margin != null){
                 $scope.companyData.masterMargin = result.margin.id;
              }
a9a8f570d   Anchit Jindal   new desing implem...
36
37
38
              if(result.marginAVGAS != null){
                  $scope.companyData.avgasMargin = result.marginAVGAS.id;
               }
7ee64838c   Anchit Jindal   new desing implem...
39
              getAircraftList();
e9a2edf03   Rishav   update custom field
40
41
42
43
              $scope.showLoader = false;
            })
          }
          
55e075d7e   Rishav   add contact, add ...
44

74c8ae4bb   Rishav   remove old toogle...
45
          $scope.changeCompanyStatus = function(){
3a9f4472b   Rishav   Implement contact...
46
47
              var statusData = "status=" + $scope.companyData.activate;
              ViewCompanyService.changeStatus(companyId, statusData).then(function(result) {
c555af312   Rishav   price email, comp...
48
49
50
51
52
                if(result.success){
                    toastr.success(''+result.success+'', {
                        closeButton: true
                    })
                }
3a9f4472b   Rishav   Implement contact...
53
              })
c555af312   Rishav   price email, comp...
54
          }
3a9f4472b   Rishav   Implement contact...
55
56
  
          
48ed0c7bb   Rishav   update company co...
57
58
59
60
61
62
          getContactList();
          function getContactList(){
            ViewCompanyService.getContact(companyId).then(function(result) {
              $scope.companyContactList = result;
            })
          }
a9a8f570d   Anchit Jindal   new desing implem...
63
          $scope.aircraftmargins = [];
7ee64838c   Anchit Jindal   new desing implem...
64
         
b1f6160d4   Rishav   add contact and a...
65
66
67
          function getAircraftList(){
            ViewCompanyService.getAircraft(companyId).then(function(result) {
              $scope.contactAircraftList = result;
a9a8f570d   Anchit Jindal   new desing implem...
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
              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...
86
87
            })
          }
b1f6160d4   Rishav   add contact and a...
88

55e075d7e   Rishav   add contact, add ...
89
90
91
92
93
          $scope.contactData = {};
          $scope.contactData.contactList = [];
          $scope.addContact = function(){
            $scope.data.companyId = companyId;
            $scope.contactData.contactList.push($scope.data);
55e075d7e   Rishav   add contact, add ...
94
            ViewCompanyService.addContact($scope.contactData).then(function(result) {
3a9f4472b   Rishav   Implement contact...
95
96
97
98
99
              console.log(result)
              if(result.status == 200){
                  // toastr.success(''+result.success+'', {
                  //   closeButton: true
                  // })
55e075d7e   Rishav   add contact, add ...
100
                  $('#contact-modal-3').modal('hide');
3a9f4472b   Rishav   Implement contact...
101
102
                  $scope.primayData.id = result.data;
                  $scope.sendPrimaryContact();
48ed0c7bb   Rishav   update company co...
103
                  getContactList();
55e075d7e   Rishav   add contact, add ...
104
105
106
107
108
109
110
              }else{
                toastr.error(''+result.statusText+'', {
                    closeButton: true
                  })
              }
            })
          }
feacde5ff   Rishav   setup acuefuel in...
111

b1f6160d4   Rishav   add contact and a...
112
113
114
115
116
117
118
        getData();
        function getData(){
          CustomersService.getAircraftMake().then(function(result) {
            $scope.aircraftMakeList = result;
          })
        }
        
a4884cfe7   Rishav   add aircraft issu...
119
120
121
        $scope.clearAircrafts = function(){
          $scope.aircraftDetails = [];
          $scope.aircraftDetails = [{ 
b1f6160d4   Rishav   add contact and a...
122
123
124
              'tail':'',
              'make': '',
              'model': '',
3a9f4472b   Rishav   Implement contact...
125
              'sizeId' : '',
7ee64838c   Anchit Jindal   new desing implem...
126
127
              'marginId': '',
          	'avgasMarginId': ''
b1f6160d4   Rishav   add contact and a...
128
          }];
a4884cfe7   Rishav   add aircraft issu...
129
        }
b1f6160d4   Rishav   add contact and a...
130
      
a4884cfe7   Rishav   add aircraft issu...
131
132
133
134
135
136
        $scope.addNew = function(){
            $scope.aircraftDetails.push({ 
              'tail':'',
              'make': '',
              'model': '',
              'sizeId' : '',
7ee64838c   Anchit Jindal   new desing implem...
137
138
              'marginId': '',
          	'avgasMarginId': ''
a4884cfe7   Rishav   add aircraft issu...
139
140
141
142
143
144
145
146
147
148
149
150
151
152
            });
            console.log($scope.aircraftDetails)
        };
  
        $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...
153

a4884cfe7   Rishav   add aircraft issu...
154
        $scope.getSize = function(model, index){
d24318592   Rishav   changes and new i...
155
          $scope.showLoader = true;
a4884cfe7   Rishav   add aircraft issu...
156
157
158
159
160
161
          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...
162

a4884cfe7   Rishav   add aircraft issu...
163
164
165
166
167
168
169
170
171
172
        $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...
173
174
                'marginId': $scope.aircraftDetails[i].marginId,
  	          'avgasMarginId': $scope.aircraftDetails[i].avgasMarginId
a4884cfe7   Rishav   add aircraft issu...
175
              });
b1f6160d4   Rishav   add contact and a...
176
          }
a4884cfe7   Rishav   add aircraft issu...
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
          console.log($scope.addData)
          $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...
192
            }
a4884cfe7   Rishav   add aircraft issu...
193
          });
b1f6160d4   Rishav   add contact and a...
194
            
a4884cfe7   Rishav   add aircraft issu...
195
196
197
198
199
200
201
202
203
204
205
206
207
        }
        $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
208
209
210
        $scope.base = function(){
          $scope.showUpdateBtn = true;
        }
a4884cfe7   Rishav   add aircraft issu...
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
        $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;              
            }*/
            $scope.showNoteData = true;
            $scope.showCompanyName = true;
            $scope.showAddress = true;
a9a8f570d   Anchit Jindal   new desing implem...
229
            var companyData = "companyName=" + $scope.companyData.companyName + "&masterMargin=" + $scope.companyData.masterMargin + "&avgasMargin=" + $scope.companyData.avgasMargin
a4884cfe7   Rishav   add aircraft issu...
230
231
232
233
234
235
236
              + "&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;
  
            ViewCompanyService.updateContact(companyData).then(function(result) {
b1f6160d4   Rishav   add contact and a...
237
238
              if(result != null && result.success){
                toastr.success(''+result.success+'', {
a4884cfe7   Rishav   add aircraft issu...
239
240
241
                  closeButton: true
                })
                $scope.showUpdateBtn = false;
b1f6160d4   Rishav   add contact and a...
242
243
              }else{
                toastr.error(''+result.statusText+'', {
a4884cfe7   Rishav   add aircraft issu...
244
245
246
                  closeButton: true
                })
                $scope.showUpdateBtn = true;
b1f6160d4   Rishav   add contact and a...
247
              }
a4884cfe7   Rishav   add aircraft issu...
248
249
              $scope.showLoader = false;
            })
b1f6160d4   Rishav   add contact and a...
250
            
a4884cfe7   Rishav   add aircraft issu...
251
        }
b1f6160d4   Rishav   add contact and a...
252

7152ff131   Rishav   model handle
253
254
255
256
257
258
        $scope.cancelData = function(){
            $scope.showNoteData = true;
            $scope.showCompanyName = true;
            $scope.showAddress = true;
            $scope.showUpdateBtn = false;
        }
a4884cfe7   Rishav   add aircraft issu...
259
260
261
262
263
264
265
266
267
268
269
270
271
272
        $scope.sendMail = function(){
          ViewCompanyService.sendMail(companyId).then(function(result) {
              if(result != null && result.success){
                toastr.success(''+result.success+'', {
                  closeButton: true
                })
                $('#confirm1').css('display', 'none');
              }else{
                toastr.error(''+result.statusText+'', {
                  closeButton: true
                })
              }
          })
        }
b1f6160d4   Rishav   add contact and a...
273

a4884cfe7   Rishav   add aircraft issu...
274
275
276
        $scope.openConfirmMail = function(){
          $('#confirm1').css('display', 'block');
        }
48ed0c7bb   Rishav   update company co...
277

b1f6160d4   Rishav   add contact and a...
278

a4884cfe7   Rishav   add aircraft issu...
279
280
281
        $scope.cancelAndCloseConfirm = function(){
          $('#confirm1').css('display', 'none');
        }
3a9f4472b   Rishav   Implement contact...
282

a4884cfe7   Rishav   add aircraft issu...
283
284
285
286
        $scope.cancelPrimaryContact = function(){
          $('#primaryContact').css('display', 'none');
          $scope.primaryContact = false;
        }
3a9f4472b   Rishav   Implement contact...
287

a4884cfe7   Rishav   add aircraft issu...
288
289
290
291
292
293
294
295
        $scope.checkPrimaryContact = function(){
          if($scope.primaryContact == true){
            ViewCompanyService.checkPrimaryContact(companyId).then(function(result) {
              console.log(result)
              if(result.status == 422){
                $('#primaryContact').css('display', 'block');
              }
            })
3a9f4472b   Rishav   Implement contact...
296
          }
a4884cfe7   Rishav   add aircraft issu...
297
        }
3a9f4472b   Rishav   Implement contact...
298

a4884cfe7   Rishav   add aircraft issu...
299
300
301
302
303
        $scope.sendPrimaryContact = function(){
          $scope.primaryContact = true;
          $('#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...
304

a4884cfe7   Rishav   add aircraft issu...
305
306
307
            ViewCompanyService.addPrimaryContact(priamryContactData).then(function(result) {
              console.log(result)
            })
3a9f4472b   Rishav   Implement contact...
308
          }
a4884cfe7   Rishav   add aircraft issu...
309
310
          
        }
3a9f4472b   Rishav   Implement contact...
311

a4884cfe7   Rishav   add aircraft issu...
312
313
314
315
316
317
318
319
320
321
322
        var newContactName = "";
        $scope.updateData = ""
        $scope.showContact = function(data, value){
          $('#updateContact').css('display', 'block');
          $scope.updateData = data;
          newContactName = value;
          console.log($scope.updateData)
          if($scope.updateData.email == null){
            $scope.updateData.content = data.contactNumber;
          }else{
            $scope.updateData.content = data.email;
3a9f4472b   Rishav   Implement contact...
323
          }
a4884cfe7   Rishav   add aircraft issu...
324
        }
3a9f4472b   Rishav   Implement contact...
325

a4884cfe7   Rishav   add aircraft issu...
326
327
328
329
330
331
332
333
334
335
        $scope.acceptUpdateField = function(){
          console.log($scope.updateData)
          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
336
            }else{
a4884cfe7   Rishav   add aircraft issu...
337
338
              var updateCustomData = "companyId=" + companyId + "&email=" + $scope.updateData.content + "&contactId=" + $scope.updateData.id
                + "&title=" + $scope.updateData.title;
e9a2edf03   Rishav   update custom field
339
            }
a4884cfe7   Rishav   add aircraft issu...
340
341
342
343
344
            ViewCompanyService.updateCustomField(updateCustomData).then(function(result) {
              console.log(result)
              if(result != null && result.success){
                $('#updateContact').css('display', 'none');
                getCompanyDetail();
e9a2edf03   Rishav   update custom field
345
              }
a4884cfe7   Rishav   add aircraft issu...
346
            })
e9a2edf03   Rishav   update custom field
347
          }
a4884cfe7   Rishav   add aircraft issu...
348
        }
e9a2edf03   Rishav   update custom field
349

a4884cfe7   Rishav   add aircraft issu...
350
351
352
        $scope.cancelUpdateField = function(){
          $('#updateContact').css('display', 'none');
        }
e9a2edf03   Rishav   update custom field
353

a4884cfe7   Rishav   add aircraft issu...
354
355
356
357
        $scope.showEditTier2 = function(number){
          console.log(number)
          $scope.contactNumber = number;
        }
8f88e39ed   Rishav   add custom field ...
358

e9a2edf03   Rishav   update custom field
359

a4884cfe7   Rishav   add aircraft issu...
360
361
362
363
364
365
        var contactName = '';
        $scope.addCustom = function(value){
          console.log(value)
          if(value != null){
            contactName = value;
            $('#customField').css('display', 'block');
3a9f4472b   Rishav   Implement contact...
366
          }
7152ff131   Rishav   model handle
367
          $scope.custom = {};
a4884cfe7   Rishav   add aircraft issu...
368
        }
8f88e39ed   Rishav   add custom field ...
369

a4884cfe7   Rishav   add aircraft issu...
370
371
372
        $scope.cancelCustomField = function(){
          $('#customField').css('display', 'none');
        }
7152ff131   Rishav   model handle
373
        
a4884cfe7   Rishav   add aircraft issu...
374
375
376
377
378
379
380
381
382
        $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...
383
            }else{
a4884cfe7   Rishav   add aircraft issu...
384
385
              var customData = "companyId=" + companyId + "&email=" + $scope.custom.content 
                + "&title=" + $scope.custom.title;
d24318592   Rishav   changes and new i...
386
            }
a4884cfe7   Rishav   add aircraft issu...
387
388
389
390
391
392
393
394
            console.log(customData.email)
            ViewCompanyService.addCustomField(customData).then(function(result) {
              console.log(result)
              if(result != null && result.success){
                $('#customField').css('display', 'none');
                getCompanyDetail();
              }
            })
3a9f4472b   Rishav   Implement contact...
395
          }
a4884cfe7   Rishav   add aircraft issu...
396
        }
28af27a3f   Rishav   add fuelPriceapi
397

7152ff131   Rishav   model handle
398
        updateFuelManagerService.getFuelPricingNew().then(function(result) {
28af27a3f   Rishav   add fuelPriceapi
399
400
          $scope.fuelPricing = result;
          for (var i = 0; i<$scope.fuelPricing.length; i++) {
7152ff131   Rishav   model handle
401
            if ($scope.fuelPricing[i].fuelPricing.expirationDate != null) {
a9e3a7365   Swarn Singh   fix issues on vie...
402
403
404
405
406
407
                $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
408
409
410
            }
          }
        })
67044e31e   Rishav Singla   modify changes an...
411
412
413
414
415
416
417
  
        $scope.deleteAircraft = function(id){
            ViewCompanyService.deleteAircraft(id).then(function(result) {
              console.log(result)
              getAircraftList();
            })
        }
a9a8f570d   Anchit Jindal   new desing implem...
418
419
420
421
422
423
424
425
        
        	CustomersService.getJetMargin($scope.userProfileId).then(function(result) {
  		  $scope.jetMarginList = result;
  		})
  
  		CustomersService.getAvgMargin($scope.userProfileId).then(function(result) {
  		  $scope.avgsMarginList = result;
  		})
a4884cfe7   Rishav   add aircraft issu...
426
          
55e075d7e   Rishav   add contact, add ...
427
    }]);