Blame view

app/partials/viewCompany/viewCompany.controller.js 11.3 KB
feacde5ff   Rishav   setup acuefuel in...
1
2
3
4
5
  
  'use strict';
  
   //Load controller
    angular.module('acufuel')
b1f6160d4   Rishav   add contact and a...
6
  	.controller('viewCompanyController', ['$scope','$uibModal', '$stateParams', 'ViewCompanyService', 'CustomersService', function($scope , $uibModal, $stateParams, ViewCompanyService, CustomersService) {
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 = {};
55e075d7e   Rishav   add contact, add ...
11

4bb02bb84   Rishav   new integration w...
12
          $(function() {
48ed0c7bb   Rishav   update company co...
13
           $('#company-one2').bootstrapToggle();
4bb02bb84   Rishav   new integration w...
14
          })
feacde5ff   Rishav   setup acuefuel in...
15

4bb02bb84   Rishav   new integration w...
16
17
18
19
20
21
22
23
24
25
26
          $(function() {
           $('#toggle-one1').bootstrapToggle();
          })   
          $(function() {
           $('#toggle-two').bootstrapToggle();
          })   
          $(function() {
           $('#toggle-three').bootstrapToggle();
          })   
          $(function() {
           $('#toggle-four').bootstrapToggle();
55e075d7e   Rishav   add contact, add ...
27
28
29
30
31
32
33
34
35
          })
  
          $(function() {
            $('#price-one2').bootstrapToggle();
            $('#price-one2').change(function() {
              $('#console-event').html('Toggle: ' + $(this).prop('checked'));
              $scope.data.priceEmail = $(this).prop('checked');
            })
          })
feacde5ff   Rishav   setup acuefuel in...
36

3a9f4472b   Rishav   Implement contact...
37
38
39
40
41
          
  
          CustomersService.getMargin().then(function(result) {
            $scope.marginList = result;
          })
48ed0c7bb   Rishav   update company co...
42
          var value = "";
55e075d7e   Rishav   add contact, add ...
43
          var companyId = $stateParams.id;
55e075d7e   Rishav   add contact, add ...
44
          ViewCompanyService.getCompany(companyId).then(function(result) {
b1f6160d4   Rishav   add contact and a...
45
            $scope.companyData = result;
3a9f4472b   Rishav   Implement contact...
46
47
48
49
            if(result.margin != null){
               $scope.companyData.masterMargin = result.margin.id;
            }
           
48ed0c7bb   Rishav   update company co...
50
51
52
53
54
55
            if($scope.companyData.activate == true){
              value = 'on';
            }else{
              value = 'off'
            }
            $('#company-one2').bootstrapToggle(value)
55e075d7e   Rishav   add contact, add ...
56
          })
c555af312   Rishav   price email, comp...
57
          $scope.changeStatus = function(){
3a9f4472b   Rishav   Implement contact...
58
59
60
61
62
63
64
            $('#company-one2').bootstrapToggle();
            $('#company-one2').change(function() {
              $('#console-event').html('Toggle: ' + $(this).prop('checked'));
              $scope.companyData.activate = $(this).prop('checked');
              console.log($scope.companyData.activate)
              var statusData = "status=" + $scope.companyData.activate;
              ViewCompanyService.changeStatus(companyId, statusData).then(function(result) {
c555af312   Rishav   price email, comp...
65
66
67
68
69
                if(result.success){
                    toastr.success(''+result.success+'', {
                        closeButton: true
                    })
                }
3a9f4472b   Rishav   Implement contact...
70
71
              })
            })
c555af312   Rishav   price email, comp...
72
          }
3a9f4472b   Rishav   Implement contact...
73
74
  
          
48ed0c7bb   Rishav   update company co...
75
76
77
78
          getContactList();
          function getContactList(){
            ViewCompanyService.getContact(companyId).then(function(result) {
              $scope.companyContactList = result;
88dad9efc   Rishav   remove unused fil...
79
80
81
82
83
84
85
86
87
88
89
              for(var i=0;i<$scope.companyContactList.length; i++){
                if($scope.companyContactList[i].priceEmail == true){
                  $scope.companyContactList[i].value1 = 'on';
                  console.log('aya')
                }else{
                  $scope.companyContactList[i].value1 = 'off';
  
                }
                console.log($scope.companyContactList[i])
                $('#'+$scope.companyContactList[i].id).bootstrapToggle($scope.companyContactList[i].value1)
              }
48ed0c7bb   Rishav   update company co...
90
91
            })
          }
55e075d7e   Rishav   add contact, add ...
92

b1f6160d4   Rishav   add contact and a...
93
94
95
96
97
98
99
          getAircraftList();
          function getAircraftList(){
            ViewCompanyService.getAircraft(companyId).then(function(result) {
              $scope.contactAircraftList = result;
            })
          }
          
55e075d7e   Rishav   add contact, add ...
100
101
102
103
104
          $scope.contactData = {};
          $scope.contactData.contactList = [];
          $scope.addContact = function(){
            $scope.data.companyId = companyId;
            $scope.contactData.contactList.push($scope.data);
55e075d7e   Rishav   add contact, add ...
105
            ViewCompanyService.addContact($scope.contactData).then(function(result) {
3a9f4472b   Rishav   Implement contact...
106
107
108
109
110
              console.log(result)
              if(result.status == 200){
                  // toastr.success(''+result.success+'', {
                  //   closeButton: true
                  // })
55e075d7e   Rishav   add contact, add ...
111
                  $('#contact-modal-3').modal('hide');
3a9f4472b   Rishav   Implement contact...
112
113
                  $scope.primayData.id = result.data;
                  $scope.sendPrimaryContact();
48ed0c7bb   Rishav   update company co...
114
                  getContactList();
55e075d7e   Rishav   add contact, add ...
115
116
117
118
119
120
121
              }else{
                toastr.error(''+result.statusText+'', {
                    closeButton: true
                  })
              }
            })
          }
feacde5ff   Rishav   setup acuefuel in...
122

b1f6160d4   Rishav   add contact and a...
123
124
125
126
127
128
129
130
131
132
133
        getData();
        function getData(){
          CustomersService.getAircraftMake().then(function(result) {
            $scope.aircraftMakeList = result;
          })
        }
        
        $scope.aircraftDetails = [{ 
              'tail':'',
              'make': '',
              'model': '',
3a9f4472b   Rishav   Implement contact...
134
135
              'sizeId' : '',
              'marginId': ''
b1f6160d4   Rishav   add contact and a...
136
137
138
139
140
141
142
          }];
      
          $scope.addNew = function(){
              $scope.aircraftDetails.push({ 
                'tail':'',
                'make': '',
                'model': '',
3a9f4472b   Rishav   Implement contact...
143
144
                'sizeId' : '',
                'marginId': ''
b1f6160d4   Rishav   add contact and a...
145
              });
b6f0311a3   Rishav   get Company api i...
146
              console.log($scope.aircraftDetails)
b1f6160d4   Rishav   add contact and a...
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
          };
  
          $scope.getModal = function(makeId, index){
          $scope.aircraft.make = makeId;
            //var makeId = makeId;
            CustomersService.getModal($scope.aircraft.make).then(function(result) {
              $scope.aircraftDetails[index].aircraftModalList = result;
              //$scope.aircraftDetails[index].model = $scope.aircraftModalList[0];
            })
          }
  
          $scope.getSize = function(model, index){
            CustomersService.getAircraftSize($scope.aircraft.make, model).then(function(result) {
              $scope.aircraftDetails[index].aircraftSizeList = result;
              //$scope.aircraftDetails[index].size = $scope.aircraftSizeList[0];
            })
          }
  
          $scope.aircraftListData = {};
          $scope.addData = [];
          $scope.saveCompanyData = function(){
            for(var i=0; i<$scope.aircraftDetails.length;i++){
              $scope.addData.push({ 
                  'tail': $scope.aircraftDetails[i].tail,
                  'make': $scope.aircraftDetails[i].make,
                  'model': $scope.aircraftDetails[i].model,
3a9f4472b   Rishav   Implement contact...
173
174
                  'sizeId' : $scope.aircraftDetails[i].sizeId,
                  'marginId': $scope.aircraftDetails[i].marginId
b1f6160d4   Rishav   add contact and a...
175
176
                });
            }
b6f0311a3   Rishav   get Company api i...
177
            console.log($scope.addData)
b1f6160d4   Rishav   add contact and a...
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
            $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
                  })
              }
            });
            
          }
          $scope.showNoteData = true;
          $scope.showCompanyName = true;
48ed0c7bb   Rishav   update company co...
198
          $scope.showAddress = true;
b1f6160d4   Rishav   add contact and a...
199
200
201
202
203
204
205
          $scope.showNote = function(){
            $scope.showNoteData = false;
          }
  
          $scope.company = function(){
            $scope.showCompanyName = false;
          }
48ed0c7bb   Rishav   update company co...
206
207
208
          $scope.addressChange = function(){
            $scope.showAddress = false;
          }
b1f6160d4   Rishav   add contact and a...
209
          $scope.editData = function(inputName) {
48ed0c7bb   Rishav   update company co...
210
              console.log($scope.companyData)
b1f6160d4   Rishav   add contact and a...
211
212
213
214
              if(inputName == 'showNoteData'){
                $scope.showNoteData = true;
              }else if(inputName == 'showCompanyName'){
                $scope.showCompanyName = true;
48ed0c7bb   Rishav   update company co...
215
216
              }else if(inputName == 'showAddress'){
                $scope.showAddress = true;              
b1f6160d4   Rishav   add contact and a...
217
              }
48ed0c7bb   Rishav   update company co...
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
  
              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) {
                if(result != null && result.success){
                  toastr.success(''+result.success+'', {
                    closeButton: true
                  })
                }else{
                  toastr.error(''+result.statusText+'', {
                    closeButton: true
                  })
                }
              })
b1f6160d4   Rishav   add contact and a...
237
238
              
          }
fd20aa6ce   Rishav   send confirmation...
239
240
241
242
243
244
          $scope.sendMail = function(){
            ViewCompanyService.sendMail(companyId).then(function(result) {
                if(result != null && result.success){
                  toastr.success(''+result.success+'', {
                    closeButton: true
                  })
3a9f4472b   Rishav   Implement contact...
245
                  $('#confirm1').css('display', 'none');
fd20aa6ce   Rishav   send confirmation...
246
247
248
249
250
251
252
                }else{
                  toastr.error(''+result.statusText+'', {
                    closeButton: true
                  })
                }
            })
          }
3a9f4472b   Rishav   Implement contact...
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
          $scope.openConfirmMail = function(){
            $('#confirm1').css('display', 'block');
          }
  
  
          $scope.cancelAndCloseConfirm = function(){
            $('#confirm1').css('display', 'none');
          }
  
          $scope.cancelPrimaryContact = function(){
            $('#primaryContact').css('display', 'none');
          }
  
          $scope.checkPrimaryContact = function(){
            if($scope.primaryContact == true){
              ViewCompanyService.checkPrimaryContact(companyId).then(function(result) {
                console.log(result)
                if(result.status == 422){
                  $('#primaryContact').css('display', 'block');
                }
              })
            }
          }
  
          $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;
  
              ViewCompanyService.addPrimaryContact(priamryContactData).then(function(result) {
                console.log(result)
              })
            }
            
          }
  
          var contactName = '';
          $scope.addCustom = function(value){
            console.log(value)
            if(value != null){
              contactName = value;
              $('#customField').css('display', 'block');
            }
            
          }
          $scope.acceptCustomField = function(){
            console.log(contactName)
            if(contactName == 'phone'){
              var customData = "companyId=" + companyId + "&contactNumber=" + $scope.custom.content 
                + "&title=" + $scope.custom.title;
            }else{
              var customData = "companyId=" + companyId + "&email=" + $scope.custom.content 
                + "&title=" + $scope.custom.title;
            }
            ViewCompanyService.addCustomField(customData).then(function(result) {
              console.log(result)
              if(result != null && result.success){
                $('#customField').css('display', 'none');
              }
            })
  
          }
          
55e075d7e   Rishav   add contact, add ...
317
    }]);