Blame view

app/partials/viewCompany/viewCompany.controller.js 11.1 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
          })
3a9f4472b   Rishav   Implement contact...
57
58
59
60
61
62
63
64
65
66
67
68
69
70
          $(function() {
            $('#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) {
  
              })
            })
          })
  
          
48ed0c7bb   Rishav   update company co...
71
72
73
74
          getContactList();
          function getContactList(){
            ViewCompanyService.getContact(companyId).then(function(result) {
              $scope.companyContactList = result;
88dad9efc   Rishav   remove unused fil...
75
76
77
78
79
80
81
82
83
84
85
              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...
86
87
            })
          }
55e075d7e   Rishav   add contact, add ...
88

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

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