Blame view

app/partials/viewCompany/viewCompany.controller.js 9.83 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

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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
          };
  
          $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...
123
124
                  'sizeId' : $scope.aircraftDetails[i].sizeId,
                  'marginId': $scope.aircraftDetails[i].marginId
b1f6160d4   Rishav   add contact and a...
125
126
                });
            }
b6f0311a3   Rishav   get Company api i...
127
            console.log($scope.addData)
b1f6160d4   Rishav   add contact and a...
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
            $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...
148
          $scope.showAddress = true;
b1f6160d4   Rishav   add contact and a...
149
150
151
152
153
154
155
          $scope.showNote = function(){
            $scope.showNoteData = false;
          }
  
          $scope.company = function(){
            $scope.showCompanyName = false;
          }
48ed0c7bb   Rishav   update company co...
156
157
158
          $scope.addressChange = function(){
            $scope.showAddress = false;
          }
b1f6160d4   Rishav   add contact and a...
159
          $scope.editData = function(inputName) {
48ed0c7bb   Rishav   update company co...
160
              console.log($scope.companyData)
b1f6160d4   Rishav   add contact and a...
161
162
163
164
              if(inputName == 'showNoteData'){
                $scope.showNoteData = true;
              }else if(inputName == 'showCompanyName'){
                $scope.showCompanyName = true;
48ed0c7bb   Rishav   update company co...
165
166
              }else if(inputName == 'showAddress'){
                $scope.showAddress = true;              
b1f6160d4   Rishav   add contact and a...
167
              }
48ed0c7bb   Rishav   update company co...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
  
              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...
187
188
              
          }
fd20aa6ce   Rishav   send confirmation...
189
190
191
192
193
194
          $scope.sendMail = function(){
            ViewCompanyService.sendMail(companyId).then(function(result) {
                if(result != null && result.success){
                  toastr.success(''+result.success+'', {
                    closeButton: true
                  })
3a9f4472b   Rishav   Implement contact...
195
                  $('#confirm1').css('display', 'none');
fd20aa6ce   Rishav   send confirmation...
196
197
198
199
200
201
202
                }else{
                  toastr.error(''+result.statusText+'', {
                    closeButton: true
                  })
                }
            })
          }
3a9f4472b   Rishav   Implement contact...
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
          $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)
              })
            }
            
          }
8f88e39ed   Rishav   add custom field ...
239
240
241
242
          $scope.showEditTier2 = function(number){
            console.log(number)
            $scope.contactNumber = number;
          }
3a9f4472b   Rishav   Implement contact...
243
244
245
246
247
248
249
250
251
          var contactName = '';
          $scope.addCustom = function(value){
            console.log(value)
            if(value != null){
              contactName = value;
              $('#customField').css('display', 'block');
            }
            
          }
8f88e39ed   Rishav   add custom field ...
252
253
254
255
  
          $scope.cancelCustomField = function(){
            $('#customField').css('display', 'none');
          }
3a9f4472b   Rishav   Implement contact...
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
          $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 ...
274
    }]);