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();
8ebb2f9e7   Rishav   toogle implemente...
14
           
4bb02bb84   Rishav   new integration w...
15
          })
feacde5ff   Rishav   setup acuefuel in...
16

4bb02bb84   Rishav   new integration w...
17
18
19
20
21
22
23
24
25
26
27
          $(function() {
           $('#toggle-one1').bootstrapToggle();
          })   
          $(function() {
           $('#toggle-two').bootstrapToggle();
          })   
          $(function() {
           $('#toggle-three').bootstrapToggle();
          })   
          $(function() {
           $('#toggle-four').bootstrapToggle();
55e075d7e   Rishav   add contact, add ...
28
29
30
31
32
33
34
35
36
          })
  
          $(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...
37

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

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

b1f6160d4   Rishav   add contact and a...
124
125
126
127
128
129
130
131
132
133
134
        getData();
        function getData(){
          CustomersService.getAircraftMake().then(function(result) {
            $scope.aircraftMakeList = result;
          })
        }
        
        $scope.aircraftDetails = [{ 
              'tail':'',
              'make': '',
              'model': '',
3a9f4472b   Rishav   Implement contact...
135
136
              'sizeId' : '',
              'marginId': ''
b1f6160d4   Rishav   add contact and a...
137
138
139
140
141
142
143
          }];
      
          $scope.addNew = function(){
              $scope.aircraftDetails.push({ 
                'tail':'',
                'make': '',
                'model': '',
3a9f4472b   Rishav   Implement contact...
144
145
                'sizeId' : '',
                'marginId': ''
b1f6160d4   Rishav   add contact and a...
146
              });
b6f0311a3   Rishav   get Company api i...
147
              console.log($scope.aircraftDetails)
b1f6160d4   Rishav   add contact and a...
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
173
          };
  
          $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...
174
175
                  'sizeId' : $scope.aircraftDetails[i].sizeId,
                  'marginId': $scope.aircraftDetails[i].marginId
b1f6160d4   Rishav   add contact and a...
176
177
                });
            }
b6f0311a3   Rishav   get Company api i...
178
            console.log($scope.addData)
b1f6160d4   Rishav   add contact and a...
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
            $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...
199
          $scope.showAddress = true;
b1f6160d4   Rishav   add contact and a...
200
201
202
203
204
205
206
          $scope.showNote = function(){
            $scope.showNoteData = false;
          }
  
          $scope.company = function(){
            $scope.showCompanyName = false;
          }
48ed0c7bb   Rishav   update company co...
207
208
209
          $scope.addressChange = function(){
            $scope.showAddress = false;
          }
b1f6160d4   Rishav   add contact and a...
210
          $scope.editData = function(inputName) {
48ed0c7bb   Rishav   update company co...
211
              console.log($scope.companyData)
b1f6160d4   Rishav   add contact and a...
212
213
214
215
              if(inputName == 'showNoteData'){
                $scope.showNoteData = true;
              }else if(inputName == 'showCompanyName'){
                $scope.showCompanyName = true;
48ed0c7bb   Rishav   update company co...
216
217
              }else if(inputName == 'showAddress'){
                $scope.showAddress = true;              
b1f6160d4   Rishav   add contact and a...
218
              }
48ed0c7bb   Rishav   update company co...
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
  
              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...
238
239
              
          }
fd20aa6ce   Rishav   send confirmation...
240
241
242
243
244
245
          $scope.sendMail = function(){
            ViewCompanyService.sendMail(companyId).then(function(result) {
                if(result != null && result.success){
                  toastr.success(''+result.success+'', {
                    closeButton: true
                  })
3a9f4472b   Rishav   Implement contact...
246
                  $('#confirm1').css('display', 'none');
fd20aa6ce   Rishav   send confirmation...
247
248
249
250
251
252
253
                }else{
                  toastr.error(''+result.statusText+'', {
                    closeButton: true
                  })
                }
            })
          }
3a9f4472b   Rishav   Implement contact...
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
317
          $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 ...
318
    }]);