Blame view

app/partials/viewCompany/viewCompany.controller.js 12.7 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
16
17
18
  
          CustomersService.getMargin().then(function(result) {
            $scope.marginList = result;
          })
48ed0c7bb   Rishav   update company co...
19
          var value = "";
55e075d7e   Rishav   add contact, add ...
20
          var companyId = $stateParams.id;
e9a2edf03   Rishav   update custom field
21
22
23
24
25
26
27
28
29
30
31
32
  
          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 ...
33

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

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

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

a4884cfe7   Rishav   add aircraft issu...
123
        $scope.getSize = function(model, index){
d24318592   Rishav   changes and new i...
124
          $scope.showLoader = true;
a4884cfe7   Rishav   add aircraft issu...
125
126
127
128
129
130
          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...
131

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

a4884cfe7   Rishav   add aircraft issu...
220
221
222
223
224
225
226
227
228
229
230
231
232
233
        $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...
234

a4884cfe7   Rishav   add aircraft issu...
235
236
237
        $scope.openConfirmMail = function(){
          $('#confirm1').css('display', 'block');
        }
48ed0c7bb   Rishav   update company co...
238

b1f6160d4   Rishav   add contact and a...
239

a4884cfe7   Rishav   add aircraft issu...
240
241
242
        $scope.cancelAndCloseConfirm = function(){
          $('#confirm1').css('display', 'none');
        }
3a9f4472b   Rishav   Implement contact...
243

a4884cfe7   Rishav   add aircraft issu...
244
245
246
247
        $scope.cancelPrimaryContact = function(){
          $('#primaryContact').css('display', 'none');
          $scope.primaryContact = false;
        }
3a9f4472b   Rishav   Implement contact...
248

a4884cfe7   Rishav   add aircraft issu...
249
250
251
252
253
254
255
256
        $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...
257
          }
a4884cfe7   Rishav   add aircraft issu...
258
        }
3a9f4472b   Rishav   Implement contact...
259

a4884cfe7   Rishav   add aircraft issu...
260
261
262
263
264
        $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...
265

a4884cfe7   Rishav   add aircraft issu...
266
267
268
            ViewCompanyService.addPrimaryContact(priamryContactData).then(function(result) {
              console.log(result)
            })
3a9f4472b   Rishav   Implement contact...
269
          }
a4884cfe7   Rishav   add aircraft issu...
270
271
          
        }
3a9f4472b   Rishav   Implement contact...
272

a4884cfe7   Rishav   add aircraft issu...
273
274
275
276
277
278
279
280
281
282
283
        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...
284
          }
a4884cfe7   Rishav   add aircraft issu...
285
        }
3a9f4472b   Rishav   Implement contact...
286

a4884cfe7   Rishav   add aircraft issu...
287
288
289
290
291
292
293
294
295
296
        $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
297
            }else{
a4884cfe7   Rishav   add aircraft issu...
298
299
              var updateCustomData = "companyId=" + companyId + "&email=" + $scope.updateData.content + "&contactId=" + $scope.updateData.id
                + "&title=" + $scope.updateData.title;
e9a2edf03   Rishav   update custom field
300
            }
a4884cfe7   Rishav   add aircraft issu...
301
302
303
304
305
            ViewCompanyService.updateCustomField(updateCustomData).then(function(result) {
              console.log(result)
              if(result != null && result.success){
                $('#updateContact').css('display', 'none');
                getCompanyDetail();
e9a2edf03   Rishav   update custom field
306
              }
a4884cfe7   Rishav   add aircraft issu...
307
            })
e9a2edf03   Rishav   update custom field
308
          }
a4884cfe7   Rishav   add aircraft issu...
309
        }
e9a2edf03   Rishav   update custom field
310

a4884cfe7   Rishav   add aircraft issu...
311
312
313
        $scope.cancelUpdateField = function(){
          $('#updateContact').css('display', 'none');
        }
e9a2edf03   Rishav   update custom field
314

a4884cfe7   Rishav   add aircraft issu...
315
316
317
318
        $scope.showEditTier2 = function(number){
          console.log(number)
          $scope.contactNumber = number;
        }
8f88e39ed   Rishav   add custom field ...
319

e9a2edf03   Rishav   update custom field
320

a4884cfe7   Rishav   add aircraft issu...
321
322
323
324
325
326
        var contactName = '';
        $scope.addCustom = function(value){
          console.log(value)
          if(value != null){
            contactName = value;
            $('#customField').css('display', 'block');
3a9f4472b   Rishav   Implement contact...
327
          }
a4884cfe7   Rishav   add aircraft issu...
328
329
          
        }
8f88e39ed   Rishav   add custom field ...
330

a4884cfe7   Rishav   add aircraft issu...
331
332
333
334
335
336
337
338
339
340
341
342
343
        $scope.cancelCustomField = function(){
          $('#customField').css('display', 'none');
        }
        $scope.custom = {};
        $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...
344
            }else{
a4884cfe7   Rishav   add aircraft issu...
345
346
              var customData = "companyId=" + companyId + "&email=" + $scope.custom.content 
                + "&title=" + $scope.custom.title;
d24318592   Rishav   changes and new i...
347
            }
a4884cfe7   Rishav   add aircraft issu...
348
349
350
351
352
353
354
355
            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...
356
          }
a4884cfe7   Rishav   add aircraft issu...
357
        }
28af27a3f   Rishav   add fuelPriceapi
358
359
360
361
362
363
364
365
366
  
        updateFuelManagerService.getFuelPricing($scope.userProfileId).then(function(result) {
          $scope.fuelPricing = result;
          for (var i = 0; i<$scope.fuelPricing.length; i++) {
            if ($scope.fuelPricing[i].expirationDate != null) {
                $scope.fuelPricing[i].expirationDate = new Date($scope.fuelPricing[i].expirationDate)
            }
          }
        })
a4884cfe7   Rishav   add aircraft issu...
367
          
55e075d7e   Rishav   add contact, add ...
368
    }]);