Blame view

app/partials/viewCompany/viewCompany.controller.js 13.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;
e9a2edf03   Rishav   update custom field
26
27
28
29
30
31
32
33
34
35
36
37
  
          getCompanyDetail();
          function getCompanyDetail(){
            ViewCompanyService.getCompany(companyId).then(function(result) {
              $scope.companyData = result;
              if(result.margin != null){
                 $scope.companyData.masterMargin = result.margin.id;
              }
              $scope.showLoader = false;
            })
          }
          
55e075d7e   Rishav   add contact, add ...
38

74c8ae4bb   Rishav   remove old toogle...
39
          $scope.changeCompanyStatus = function(){
3a9f4472b   Rishav   Implement contact...
40
41
              var statusData = "status=" + $scope.companyData.activate;
              ViewCompanyService.changeStatus(companyId, statusData).then(function(result) {
c555af312   Rishav   price email, comp...
42
43
44
45
46
                if(result.success){
                    toastr.success(''+result.success+'', {
                        closeButton: true
                    })
                }
3a9f4472b   Rishav   Implement contact...
47
              })
c555af312   Rishav   price email, comp...
48
          }
3a9f4472b   Rishav   Implement contact...
49
50
  
          
48ed0c7bb   Rishav   update company co...
51
52
53
54
55
56
          getContactList();
          function getContactList(){
            ViewCompanyService.getContact(companyId).then(function(result) {
              $scope.companyContactList = result;
            })
          }
55e075d7e   Rishav   add contact, add ...
57

b1f6160d4   Rishav   add contact and a...
58
59
60
61
62
63
64
          getAircraftList();
          function getAircraftList(){
            ViewCompanyService.getAircraft(companyId).then(function(result) {
              $scope.contactAircraftList = result;
            })
          }
          
55e075d7e   Rishav   add contact, add ...
65
66
67
68
69
          $scope.contactData = {};
          $scope.contactData.contactList = [];
          $scope.addContact = function(){
            $scope.data.companyId = companyId;
            $scope.contactData.contactList.push($scope.data);
55e075d7e   Rishav   add contact, add ...
70
            ViewCompanyService.addContact($scope.contactData).then(function(result) {
3a9f4472b   Rishav   Implement contact...
71
72
73
74
75
              console.log(result)
              if(result.status == 200){
                  // toastr.success(''+result.success+'', {
                  //   closeButton: true
                  // })
55e075d7e   Rishav   add contact, add ...
76
                  $('#contact-modal-3').modal('hide');
3a9f4472b   Rishav   Implement contact...
77
78
                  $scope.primayData.id = result.data;
                  $scope.sendPrimaryContact();
48ed0c7bb   Rishav   update company co...
79
                  getContactList();
55e075d7e   Rishav   add contact, add ...
80
81
82
83
84
85
86
              }else{
                toastr.error(''+result.statusText+'', {
                    closeButton: true
                  })
              }
            })
          }
feacde5ff   Rishav   setup acuefuel in...
87

b1f6160d4   Rishav   add contact and a...
88
89
90
91
92
93
94
        getData();
        function getData(){
          CustomersService.getAircraftMake().then(function(result) {
            $scope.aircraftMakeList = result;
          })
        }
        
a4884cfe7   Rishav   add aircraft issu...
95
96
97
        $scope.clearAircrafts = function(){
          $scope.aircraftDetails = [];
          $scope.aircraftDetails = [{ 
b1f6160d4   Rishav   add contact and a...
98
99
100
              'tail':'',
              'make': '',
              'model': '',
3a9f4472b   Rishav   Implement contact...
101
102
              'sizeId' : '',
              'marginId': ''
b1f6160d4   Rishav   add contact and a...
103
          }];
a4884cfe7   Rishav   add aircraft issu...
104
        }
b1f6160d4   Rishav   add contact and a...
105
      
a4884cfe7   Rishav   add aircraft issu...
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
        $scope.addNew = function(){
            $scope.aircraftDetails.push({ 
              'tail':'',
              'make': '',
              'model': '',
              'sizeId' : '',
              'marginId': ''
            });
            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...
127

a4884cfe7   Rishav   add aircraft issu...
128
        $scope.getSize = function(model, index){
d24318592   Rishav   changes and new i...
129
          $scope.showLoader = true;
a4884cfe7   Rishav   add aircraft issu...
130
131
132
133
134
135
          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...
136

a4884cfe7   Rishav   add aircraft issu...
137
138
139
140
141
142
143
144
145
146
147
148
        $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,
                'marginId': $scope.aircraftDetails[i].marginId
              });
b1f6160d4   Rishav   add contact and a...
149
          }
a4884cfe7   Rishav   add aircraft issu...
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
          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...
165
            }
a4884cfe7   Rishav   add aircraft issu...
166
          });
b1f6160d4   Rishav   add contact and a...
167
            
a4884cfe7   Rishav   add aircraft issu...
168
169
170
171
172
173
174
175
176
177
178
179
180
        }
        $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
181
182
183
        $scope.base = function(){
          $scope.showUpdateBtn = true;
        }
a4884cfe7   Rishav   add aircraft issu...
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
        $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;
  
            var companyData = "companyName=" + $scope.companyData.companyName + "&masterMargin=" + $scope.companyData.masterMargin 
              + "&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...
211
212
              if(result != null && result.success){
                toastr.success(''+result.success+'', {
a4884cfe7   Rishav   add aircraft issu...
213
214
215
                  closeButton: true
                })
                $scope.showUpdateBtn = false;
b1f6160d4   Rishav   add contact and a...
216
217
              }else{
                toastr.error(''+result.statusText+'', {
a4884cfe7   Rishav   add aircraft issu...
218
219
220
                  closeButton: true
                })
                $scope.showUpdateBtn = true;
b1f6160d4   Rishav   add contact and a...
221
              }
a4884cfe7   Rishav   add aircraft issu...
222
223
              $scope.showLoader = false;
            })
b1f6160d4   Rishav   add contact and a...
224
            
a4884cfe7   Rishav   add aircraft issu...
225
        }
b1f6160d4   Rishav   add contact and a...
226

7152ff131   Rishav   model handle
227
228
229
230
231
232
        $scope.cancelData = function(){
            $scope.showNoteData = true;
            $scope.showCompanyName = true;
            $scope.showAddress = true;
            $scope.showUpdateBtn = false;
        }
a4884cfe7   Rishav   add aircraft issu...
233
234
235
236
237
238
239
240
241
242
243
244
245
246
        $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...
247

a4884cfe7   Rishav   add aircraft issu...
248
249
250
        $scope.openConfirmMail = function(){
          $('#confirm1').css('display', 'block');
        }
48ed0c7bb   Rishav   update company co...
251

b1f6160d4   Rishav   add contact and a...
252

a4884cfe7   Rishav   add aircraft issu...
253
254
255
        $scope.cancelAndCloseConfirm = function(){
          $('#confirm1').css('display', 'none');
        }
3a9f4472b   Rishav   Implement contact...
256

a4884cfe7   Rishav   add aircraft issu...
257
258
259
260
        $scope.cancelPrimaryContact = function(){
          $('#primaryContact').css('display', 'none');
          $scope.primaryContact = false;
        }
3a9f4472b   Rishav   Implement contact...
261

a4884cfe7   Rishav   add aircraft issu...
262
263
264
265
266
267
268
269
        $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...
270
          }
a4884cfe7   Rishav   add aircraft issu...
271
        }
3a9f4472b   Rishav   Implement contact...
272

a4884cfe7   Rishav   add aircraft issu...
273
274
275
276
277
        $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...
278

a4884cfe7   Rishav   add aircraft issu...
279
280
281
            ViewCompanyService.addPrimaryContact(priamryContactData).then(function(result) {
              console.log(result)
            })
3a9f4472b   Rishav   Implement contact...
282
          }
a4884cfe7   Rishav   add aircraft issu...
283
284
          
        }
3a9f4472b   Rishav   Implement contact...
285

a4884cfe7   Rishav   add aircraft issu...
286
287
288
289
290
291
292
293
294
295
296
        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...
297
          }
a4884cfe7   Rishav   add aircraft issu...
298
        }
3a9f4472b   Rishav   Implement contact...
299

a4884cfe7   Rishav   add aircraft issu...
300
301
302
303
304
305
306
307
308
309
        $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
310
            }else{
a4884cfe7   Rishav   add aircraft issu...
311
312
              var updateCustomData = "companyId=" + companyId + "&email=" + $scope.updateData.content + "&contactId=" + $scope.updateData.id
                + "&title=" + $scope.updateData.title;
e9a2edf03   Rishav   update custom field
313
            }
a4884cfe7   Rishav   add aircraft issu...
314
315
316
317
318
            ViewCompanyService.updateCustomField(updateCustomData).then(function(result) {
              console.log(result)
              if(result != null && result.success){
                $('#updateContact').css('display', 'none');
                getCompanyDetail();
e9a2edf03   Rishav   update custom field
319
              }
a4884cfe7   Rishav   add aircraft issu...
320
            })
e9a2edf03   Rishav   update custom field
321
          }
a4884cfe7   Rishav   add aircraft issu...
322
        }
e9a2edf03   Rishav   update custom field
323

a4884cfe7   Rishav   add aircraft issu...
324
325
326
        $scope.cancelUpdateField = function(){
          $('#updateContact').css('display', 'none');
        }
e9a2edf03   Rishav   update custom field
327

a4884cfe7   Rishav   add aircraft issu...
328
329
330
331
        $scope.showEditTier2 = function(number){
          console.log(number)
          $scope.contactNumber = number;
        }
8f88e39ed   Rishav   add custom field ...
332

e9a2edf03   Rishav   update custom field
333

a4884cfe7   Rishav   add aircraft issu...
334
335
336
337
338
339
        var contactName = '';
        $scope.addCustom = function(value){
          console.log(value)
          if(value != null){
            contactName = value;
            $('#customField').css('display', 'block');
3a9f4472b   Rishav   Implement contact...
340
          }
7152ff131   Rishav   model handle
341
          $scope.custom = {};
a4884cfe7   Rishav   add aircraft issu...
342
        }
8f88e39ed   Rishav   add custom field ...
343

a4884cfe7   Rishav   add aircraft issu...
344
345
346
        $scope.cancelCustomField = function(){
          $('#customField').css('display', 'none');
        }
7152ff131   Rishav   model handle
347
        
a4884cfe7   Rishav   add aircraft issu...
348
349
350
351
352
353
354
355
356
        $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...
357
            }else{
a4884cfe7   Rishav   add aircraft issu...
358
359
              var customData = "companyId=" + companyId + "&email=" + $scope.custom.content 
                + "&title=" + $scope.custom.title;
d24318592   Rishav   changes and new i...
360
            }
a4884cfe7   Rishav   add aircraft issu...
361
362
363
364
365
366
367
368
            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...
369
          }
a4884cfe7   Rishav   add aircraft issu...
370
        }
28af27a3f   Rishav   add fuelPriceapi
371

7152ff131   Rishav   model handle
372
        updateFuelManagerService.getFuelPricingNew().then(function(result) {
28af27a3f   Rishav   add fuelPriceapi
373
374
          $scope.fuelPricing = result;
          for (var i = 0; i<$scope.fuelPricing.length; i++) {
7152ff131   Rishav   model handle
375
376
            if ($scope.fuelPricing[i].fuelPricing.expirationDate != null) {
                $scope.fuelPricing[i].fuelPricing.expirationDate = new Date($scope.fuelPricing[i].fuelPricing.expirationDate)
28af27a3f   Rishav   add fuelPriceapi
377
378
379
            }
          }
        })
a4884cfe7   Rishav   add aircraft issu...
380
          
55e075d7e   Rishav   add contact, add ...
381
    }]);