Blame view

app/partials/viewCompany/viewCompany.controller.js 10.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 = {};
d24318592   Rishav   changes and new i...
11
          $scope.showLoader = false;
3a9f4472b   Rishav   Implement contact...
12
13
14
15
  
          CustomersService.getMargin().then(function(result) {
            $scope.marginList = result;
          })
48ed0c7bb   Rishav   update company co...
16
          var value = "";
55e075d7e   Rishav   add contact, add ...
17
          var companyId = $stateParams.id;
55e075d7e   Rishav   add contact, add ...
18
          ViewCompanyService.getCompany(companyId).then(function(result) {
b1f6160d4   Rishav   add contact and a...
19
            $scope.companyData = result;
3a9f4472b   Rishav   Implement contact...
20
21
22
            if(result.margin != null){
               $scope.companyData.masterMargin = result.margin.id;
            }
55e075d7e   Rishav   add contact, add ...
23
          })
74c8ae4bb   Rishav   remove old toogle...
24
          $scope.changeCompanyStatus = function(){
3a9f4472b   Rishav   Implement contact...
25
26
              var statusData = "status=" + $scope.companyData.activate;
              ViewCompanyService.changeStatus(companyId, statusData).then(function(result) {
c555af312   Rishav   price email, comp...
27
28
29
30
31
                if(result.success){
                    toastr.success(''+result.success+'', {
                        closeButton: true
                    })
                }
3a9f4472b   Rishav   Implement contact...
32
              })
c555af312   Rishav   price email, comp...
33
          }
3a9f4472b   Rishav   Implement contact...
34
35
  
          
48ed0c7bb   Rishav   update company co...
36
37
38
39
40
41
          getContactList();
          function getContactList(){
            ViewCompanyService.getContact(companyId).then(function(result) {
              $scope.companyContactList = result;
            })
          }
55e075d7e   Rishav   add contact, add ...
42

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

b1f6160d4   Rishav   add contact and a...
73
74
75
76
77
78
79
80
81
82
83
        getData();
        function getData(){
          CustomersService.getAircraftMake().then(function(result) {
            $scope.aircraftMakeList = result;
          })
        }
        
        $scope.aircraftDetails = [{ 
              'tail':'',
              'make': '',
              'model': '',
3a9f4472b   Rishav   Implement contact...
84
85
              'sizeId' : '',
              'marginId': ''
b1f6160d4   Rishav   add contact and a...
86
87
88
89
90
91
92
          }];
      
          $scope.addNew = function(){
              $scope.aircraftDetails.push({ 
                'tail':'',
                'make': '',
                'model': '',
3a9f4472b   Rishav   Implement contact...
93
94
                'sizeId' : '',
                'marginId': ''
b1f6160d4   Rishav   add contact and a...
95
              });
b6f0311a3   Rishav   get Company api i...
96
              console.log($scope.aircraftDetails)
b1f6160d4   Rishav   add contact and a...
97
98
99
          };
  
          $scope.getModal = function(makeId, index){
d24318592   Rishav   changes and new i...
100
          $scope.showLoader = true;
b1f6160d4   Rishav   add contact and a...
101
102
103
          $scope.aircraft.make = makeId;
            //var makeId = makeId;
            CustomersService.getModal($scope.aircraft.make).then(function(result) {
d24318592   Rishav   changes and new i...
104
              $scope.showLoader = false;
b1f6160d4   Rishav   add contact and a...
105
106
107
108
109
110
              $scope.aircraftDetails[index].aircraftModalList = result;
              //$scope.aircraftDetails[index].model = $scope.aircraftModalList[0];
            })
          }
  
          $scope.getSize = function(model, index){
d24318592   Rishav   changes and new i...
111
            $scope.showLoader = true;
b1f6160d4   Rishav   add contact and a...
112
            CustomersService.getAircraftSize($scope.aircraft.make, model).then(function(result) {
d24318592   Rishav   changes and new i...
113
              $scope.showLoader = false;
b1f6160d4   Rishav   add contact and a...
114
115
116
117
118
119
120
121
122
123
124
125
126
              $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...
127
128
                  'sizeId' : $scope.aircraftDetails[i].sizeId,
                  'marginId': $scope.aircraftDetails[i].marginId
b1f6160d4   Rishav   add contact and a...
129
130
                });
            }
b6f0311a3   Rishav   get Company api i...
131
            console.log($scope.addData)
b1f6160d4   Rishav   add contact and a...
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
            $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...
152
          $scope.showAddress = true;
b1f6160d4   Rishav   add contact and a...
153
154
155
156
157
158
159
          $scope.showNote = function(){
            $scope.showNoteData = false;
          }
  
          $scope.company = function(){
            $scope.showCompanyName = false;
          }
48ed0c7bb   Rishav   update company co...
160
161
162
          $scope.addressChange = function(){
            $scope.showAddress = false;
          }
b1f6160d4   Rishav   add contact and a...
163
          $scope.editData = function(inputName) {
48ed0c7bb   Rishav   update company co...
164
              console.log($scope.companyData)
b1f6160d4   Rishav   add contact and a...
165
166
167
168
              if(inputName == 'showNoteData'){
                $scope.showNoteData = true;
              }else if(inputName == 'showCompanyName'){
                $scope.showCompanyName = true;
48ed0c7bb   Rishav   update company co...
169
170
              }else if(inputName == 'showAddress'){
                $scope.showAddress = true;              
b1f6160d4   Rishav   add contact and a...
171
              }
48ed0c7bb   Rishav   update company co...
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
  
              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...
191
192
              
          }
fd20aa6ce   Rishav   send confirmation...
193
194
195
196
197
198
          $scope.sendMail = function(){
            ViewCompanyService.sendMail(companyId).then(function(result) {
                if(result != null && result.success){
                  toastr.success(''+result.success+'', {
                    closeButton: true
                  })
3a9f4472b   Rishav   Implement contact...
199
                  $('#confirm1').css('display', 'none');
fd20aa6ce   Rishav   send confirmation...
200
201
202
203
204
205
206
                }else{
                  toastr.error(''+result.statusText+'', {
                    closeButton: true
                  })
                }
            })
          }
3a9f4472b   Rishav   Implement contact...
207
208
209
210
211
212
213
214
215
216
217
          $scope.openConfirmMail = function(){
            $('#confirm1').css('display', 'block');
          }
  
  
          $scope.cancelAndCloseConfirm = function(){
            $('#confirm1').css('display', 'none');
          }
  
          $scope.cancelPrimaryContact = function(){
            $('#primaryContact').css('display', 'none');
d24318592   Rishav   changes and new i...
218
            $scope.primaryContact = false;
3a9f4472b   Rishav   Implement contact...
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
          }
  
          $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)
              })
            }
            
          }
8f88e39ed   Rishav   add custom field ...
244
245
246
247
          $scope.showEditTier2 = function(number){
            console.log(number)
            $scope.contactNumber = number;
          }
3a9f4472b   Rishav   Implement contact...
248
249
250
251
252
253
254
255
256
          var contactName = '';
          $scope.addCustom = function(value){
            console.log(value)
            if(value != null){
              contactName = value;
              $('#customField').css('display', 'block');
            }
            
          }
8f88e39ed   Rishav   add custom field ...
257
258
259
260
  
          $scope.cancelCustomField = function(){
            $('#customField').css('display', 'none');
          }
d24318592   Rishav   changes and new i...
261
          $scope.custom = {};
3a9f4472b   Rishav   Implement contact...
262
          $scope.acceptCustomField = function(){
d24318592   Rishav   changes and new i...
263
264
265
266
            if($scope.custom.content == undefined){
              toastr.error('Please add some content', {
                closeButton: true
              })
3a9f4472b   Rishav   Implement contact...
267
            }else{
d24318592   Rishav   changes and new i...
268
269
270
271
272
273
              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;
3a9f4472b   Rishav   Implement contact...
274
              }
d24318592   Rishav   changes and new i...
275
276
277
278
279
280
281
282
283
              console.log(customData.email)
              ViewCompanyService.addCustomField(customData).then(function(result) {
                console.log(result)
                if(result != null && result.success){
                  $('#customField').css('display', 'none');
                }
              })
            }
            
3a9f4472b   Rishav   Implement contact...
284
285
286
  
          }
          
55e075d7e   Rishav   add contact, add ...
287
    }]);