Blame view

app/views/updateFBODept/updateFBODept.controller.js 10 KB
a80703599   Rishav   FBO department fu...
1
2
3
4
  'use strict';
  
   //Load controller
    angular.module('acuefuel')
089f3a3c2   Rishav   check username av...
5
  	.controller('updateFBODeptController', function($scope, $stateParams, $state, UpdateAllFBODept, UpdateAllFBO, FBOFlight, FBOAdmin) {
2d8381335   Rishav   menu highlighted ...
6
7
8
        $(document).ready(function(){
          $('.fboflight').addClass('active');
        });
104d51edf   Rishav   all new api imple...
9
10
        $scope.showPayments = true;
        $scope.aircraft = {};
47e72f419   Rishav   update aircraft, ...
11
        $scope.updateData = {};
a80703599   Rishav   FBO department fu...
12
        var userProfileID = $stateParams.id;
a19001fdd   Anchit Jindal   new code added
13
14
        $scope.companyId;
        
a80703599   Rishav   FBO department fu...
15
        UpdateAllFBODept.getALlFBOData(userProfileID).then(function(result) {
a19001fdd   Anchit Jindal   new code added
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
            console.log(result)
            $scope.user = result;
           // $scope.aircraft.accountId = result.account.id;
            $scope.user.userTypeId = result.userType.id;
            UpdateAllFBODept.getNotes(userProfileID).then(function(response) {
              $scope.user.clientNote = response[0].notes
              $scope.user.userNoteId = response[0].id;
            })
            // $scope.feature = result.accountFeatureControl;
            // console.log($scope.feature,"dsdsdsds")
            if($scope.user.account.user.status == 'ACTIVE'){
              $scope.status = true;
            }else {
              $scope.status = false;
            }
a80703599   Rishav   FBO department fu...
31
          })
a19001fdd   Anchit Jindal   new code added
32
33
34
35
36
37
        
        UpdateAllFBODept.getAssociatedCompany(userProfileID).then(function(result) {
          console.log('=======q===',result)
          $scope.companyId = result.id;
          getCrafts(result.id);
          $scope.aircraft.accountId = result.id;
a80703599   Rishav   FBO department fu...
38
        })
a19001fdd   Anchit Jindal   new code added
39
40
41
        
        function getCrafts(id){
          UpdateAllFBODept.getAircrafts(id).then(function(response) {
104d51edf   Rishav   all new api imple...
42
            $scope.getCraftList = response;
16fa2ad10   Rishav   adding aircraft o...
43
            for(var i=0;i<$scope.getCraftList.length;i++){
a19001fdd   Anchit Jindal   new code added
44
45
              $scope.getCraftList[i].sizeId = $scope.getCraftList[i].compAircraftSize.id;
              $scope.getCraftList[i].size = $scope.getCraftList[i].compAircraftSize.size;
16fa2ad10   Rishav   adding aircraft o...
46
            }
47e72f419   Rishav   update aircraft, ...
47
48
49
          })
        }
        
104d51edf   Rishav   all new api imple...
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
        UpdateAllFBODept.getPaymentMethod(userProfileID).then(function(response) {
            $scope.paymentList = response;
  
        })
  
        $scope.openCard = function(payment){
          console.log(payment)
          $scope.showPayments = false;
          $scope.data = {};
          $scope.data.cardNumber = payment.cardNumber;
          $scope.data.cardType = payment.cardType;
          $scope.data.expiryDate = payment.expiryDate;
          $scope.data.id = payment.id;
          $scope.data.accountId = payment.user.account.id;
        }
  
        var cardData = {}
        cardData.paymentMethodList = [];
        $scope.updateCard = function(){
          console.log($scope.data)
          cardData.paymentMethodList.push($scope.data);
          console.log("cardData", cardData);
          UpdateAllFBODept.updatePaymentMethod(cardData).then(function(result) {
            console.log(result)
              toastr.success('Updated Successfully', {
                closeButton: true
              })
            $scope.reset();
          })
        }
  
  
        $scope.reset = function(){
          cardData.paymentMethodList = [];
        }
089f3a3c2   Rishav   check username av...
85
86
87
88
89
90
91
92
93
94
        $scope.checkUsername = function(){
          FBOAdmin.checkUsernameEmail($scope.user.email).then(function(status) {
            console.log(status)
            if(status != 200){
              toastr.error('This email has alreay taken', {
                closeButton: true
              })
            }
          })
        }
104d51edf   Rishav   all new api imple...
95
96
        $scope.userData = function(){
          console.log($scope.user.userTypeId)
db8e1f992   Rishav   pending user api,...
97
98
99
100
101
102
103
104
105
          if($scope.user.email == undefined || $scope.user.email == null){
            toastr.error('Please enter your email first', {
              closeButton: true
            })
          }else if($scope.user.firstName == undefined || $scope.user.firstName == null){
            toastr.error('Please enter your First Name', {
              closeButton: true
            })
          }else{
3433be3d6   Rishav   update status and...
106
            if($scope.status == true){
104d51edf   Rishav   all new api imple...
107
108
109
110
111
112
113
              $scope.user.status = 'active';
            }else{
              $scope.user.status = 'inactive';
            }
            $scope.user.username = $scope.user.email;
            $scope.user.userType = 'flightDetp';
            console.log($scope.user)
a4d4a8320   Rishav   update FBO code a...
114
115
116
            // if($scope.user.userNoteId == undefined){
            //   $scope.user.userNoteId = null;
            // }
104d51edf   Rishav   all new api imple...
117
118
119
120
121
122
            var updateData = "companyName=" + $scope.user.companyName + "&username=" + $scope.user.username + "&firstName=" + $scope.user.firstName + "&lastName=" + $scope.user.lastName + "&phone=" + $scope.user.phone + "&mobile=" + $scope.user.mobile + "&status=" + $scope.user.status + "&userType=" + $scope.user.userType + "&userNote=" + $scope.user.clientNote + "&userNoteId=" + $scope.user.userNoteId + "&userTypeId=" + $scope.user.userTypeId + "&userProfileId=" + userProfileID;
            UpdateAllFBO.updateUser(updateData).then(function(result) {
              toastr.success(''+result.success+'', {
                  closeButton: true
              })
            })
26e0d5d69   Rishav   save changes issue
123
            $state.go('index.flightDept');
db8e1f992   Rishav   pending user api,...
124
          }
104d51edf   Rishav   all new api imple...
125
126
127
128
129
130
131
132
133
134
        }
  
        getData();
        function getData(){
          FBOFlight.getAircraftMake().then(function(result) {
            $scope.aircraftMakeList = result;
            $scope.aircraft.make = $scope.aircraftMakeList[0];
            FBOFlight.getModal($scope.aircraft.make).then(function(result) {
              $scope.aircraftModalList = result;
              $scope.aircraft.model = $scope.aircraftModalList[0];
104d51edf   Rishav   all new api imple...
135

db8e1f992   Rishav   pending user api,...
136
137
              FBOFlight.getAircraftSize($scope.aircraft.make, $scope.aircraft.model).then(function(result) {
                $scope.aircraftSizeList = result;
16fa2ad10   Rishav   adding aircraft o...
138
                $scope.aircraft.sizeId = $scope.aircraftSizeList[0].aircraftSize.id;
db8e1f992   Rishav   pending user api,...
139
140
141
                  
              })
            })
104d51edf   Rishav   all new api imple...
142
143
144
              
          })
        }
104d51edf   Rishav   all new api imple...
145
146
  
        $scope.getModal = function(){
db8e1f992   Rishav   pending user api,...
147
148
          var makeId = $scope.aircraft.make
          FBOFlight.getModal(makeId).then(function(result) {
104d51edf   Rishav   all new api imple...
149
150
            $scope.aircraftModalList = result;
            $scope.aircraft.model = $scope.aircraftModalList[0];
db8e1f992   Rishav   pending user api,...
151
152
153
  
            FBOFlight.getAircraftSize(makeId, $scope.aircraft.model).then(function(result) {
              $scope.aircraftSizeList = result;
16fa2ad10   Rishav   adding aircraft o...
154
              $scope.aircraft.sizeId = $scope.aircraftSizeList[0].aircraftSize.id;
db8e1f992   Rishav   pending user api,...
155
            })
104d51edf   Rishav   all new api imple...
156
157
          })
        }
db8e1f992   Rishav   pending user api,...
158
159
160
161
  
        $scope.getSize = function(){
          FBOFlight.getAircraftSize($scope.aircraft.make, $scope.aircraft.model).then(function(result) {
            $scope.aircraftSizeList = result;
16fa2ad10   Rishav   adding aircraft o...
162
163
164
            console.log($scope.aircraftSizeList)
            $scope.aircraft.sizeId = $scope.aircraftSizeList[0].aircraftSize.id;
            console.log($scope.aircraft.sizeId)
db8e1f992   Rishav   pending user api,...
165
166
          })
        }
a19001fdd   Anchit Jindal   new code added
167
168
        
        
104d51edf   Rishav   all new api imple...
169
        $scope.addAircraft = function(){
a19001fdd   Anchit Jindal   new code added
170
171
172
173
174
175
176
177
178
179
180
181
182
183
      	  $scope.aircraftListData = {};
            $scope.addData = [];
            $scope.aircraftListData.aircraftList= [];
            
            $scope.addData.push({ 
              'tail': $scope.aircraft.tail,
              'make': $scope.aircraft.make,
              'model': $scope.aircraft.model,
              'sizeId' : $scope.aircraft.sizeId
            });
            console.log('$scope.addData',$scope.addData);
            
            $scope.aircraftListData.aircraftList = $scope.addData;
            $scope.aircraftListData.accountId = $scope.companyId;
16fa2ad10   Rishav   adding aircraft o...
184
          console.log($scope.aircraft)
a19001fdd   Anchit Jindal   new code added
185
          //$scope.aircraftData.aircraftList.push($scope.aircraft);
104d51edf   Rishav   all new api imple...
186
          
a19001fdd   Anchit Jindal   new code added
187
          FBOFlight.addAircraft($scope.aircraftListData).then(function(result) {
104d51edf   Rishav   all new api imple...
188
            $('#myModal4').modal('hide');
a19001fdd   Anchit Jindal   new code added
189
            getCrafts($scope.companyId);
104d51edf   Rishav   all new api imple...
190
191
192
193
            $scope.resetData();
            toastr.success('Created Successfully', {
              closeButton: true
            })
db8e1f992   Rishav   pending user api,...
194
195
196
197
198
199
200
          }, function (err) {
              toastr.error('Error in Adding Aircraft', {
                closeButton: true
              })
              $('#myModal4').modal('hide');
              $scope.getCraftList.splice($scope.aircraft);
          });
16fa2ad10   Rishav   adding aircraft o...
201
         }
104d51edf   Rishav   all new api imple...
202

47e72f419   Rishav   update aircraft, ...
203
204
205
206
207
208
        $scope.closeModal = function(){
          $("#myModal5").modal('hide');
          $scope.resetData();
        }
  
        $scope.update = function(airdata){
db8e1f992   Rishav   pending user api,...
209
          $("#myModal5").modal('show');
47e72f419   Rishav   update aircraft, ...
210
          $scope.aircraft = airdata;
a19001fdd   Anchit Jindal   new code added
211
212
          console.log('--------$scope.companyId---',$scope.companyId);
          $scope.aircraft.accountId = $scope.companyId;
db8e1f992   Rishav   pending user api,...
213
          
47e72f419   Rishav   update aircraft, ...
214
215
          FBOFlight.getModal($scope.aircraft.make).then(function(result) {
            $scope.aircraftModalList = result;
db8e1f992   Rishav   pending user api,...
216
217
            FBOFlight.getAircraftSize($scope.aircraft.make, $scope.aircraft.model).then(function(result) {
              $scope.aircraftSizeList = result;
16fa2ad10   Rishav   adding aircraft o...
218
219
              console.log($scope.aircraftSizeList)
              $scope.aircraft.sizeId = $scope.aircraftSizeList[0].aircraftSize.id;
db8e1f992   Rishav   pending user api,...
220
            })
47e72f419   Rishav   update aircraft, ...
221
222
223
224
225
226
227
228
229
230
231
          })
        }
  
        $scope.updatecraftData = {};
        $scope.updatecraftData.aircraftList = [];
        $scope.updateAircraftData = {};
  
        $scope.updateAircraft = function(updateAircraft){
          $scope.updateAircraftData.id = updateAircraft.id;
          $scope.updateAircraftData.make = updateAircraft.make;
          $scope.updateAircraftData.model = updateAircraft.model;
16fa2ad10   Rishav   adding aircraft o...
232
          $scope.updateAircraftData.sizeId = updateAircraft.sizeId;
47e72f419   Rishav   update aircraft, ...
233
          $scope.updateAircraftData.tail = updateAircraft.tail;
a19001fdd   Anchit Jindal   new code added
234
          $scope.updateAircraftData.accountId = $scope.companyId;
47e72f419   Rishav   update aircraft, ...
235
236
237
238
239
240
241
242
          console.log($scope.updateAircraftData)
  
          $scope.updatecraftData.aircraftList.push($scope.updateAircraftData);
          console.log($scope.updatecraftData.aircraftList)
          
          UpdateAllFBODept.updateAircraft($scope.updatecraftData).then(function(result) {
            $('#myModal5').modal('hide');
            $scope.resetData();
a19001fdd   Anchit Jindal   new code added
243
            getCrafts($scope.companyId);
47e72f419   Rishav   update aircraft, ...
244
245
246
            toastr.success('Updated Successfully', {
              closeButton: true
            })
db8e1f992   Rishav   pending user api,...
247
248
249
250
251
252
253
          }, function (err) {
              toastr.error('Error in Updating Aircraft', {
                closeButton: true
              })
              $('#myModal5').modal('hide');
              $scope.getCraftList.splice($scope.aircraft);
          });
47e72f419   Rishav   update aircraft, ...
254
255
256
257
258
259
260
261
        }
  
        $scope.remove = function(data){
          console.log(data)
          UpdateAllFBODept.removeAircraft(data.id).then(function(result) {
            toastr.success(''+result.success+'', {
              closeButton: true
            })
a19001fdd   Anchit Jindal   new code added
262
            getCrafts($scope.companyId);
47e72f419   Rishav   update aircraft, ...
263
264
          })
        }
104d51edf   Rishav   all new api imple...
265
266
        $scope.resetData = function() {
          $scope.aircraft = {};
a19001fdd   Anchit Jindal   new code added
267
268
          $scope.aircraft.accountId = $scope.companyId;
          $scope.aircraftListData.aircraftList = [];
104d51edf   Rishav   all new api imple...
269
270
          getData();
        }
a80703599   Rishav   FBO department fu...
271
    });