Blame view

app/views/updateFBODept/updateFBODept.controller.js 8.28 KB
a80703599   Rishav   FBO department fu...
1
2
3
4
  'use strict';
  
   //Load controller
    angular.module('acuefuel')
104d51edf   Rishav   all new api imple...
5
  	.controller('updateFBODeptController', function($scope, $stateParams, UpdateAllFBODept, UpdateAllFBO, FBOFlight) {
db8e1f992   Rishav   pending user api,...
6
7
8
9
10
        $scope.showCompany = true;
        $scope.editName = function(){
          $scope.showCompany = false;
  
        }
104d51edf   Rishav   all new api imple...
11
12
        $scope.showPayments = true;
        $scope.aircraft = {};
47e72f419   Rishav   update aircraft, ...
13
        $scope.updateData = {};
a80703599   Rishav   FBO department fu...
14
15
16
17
        var userProfileID = $stateParams.id;
        UpdateAllFBODept.getALlFBOData(userProfileID).then(function(result) {
          console.log(result)
          $scope.user = result;
104d51edf   Rishav   all new api imple...
18
19
          $scope.aircraft.accountId = result.account.id;
          $scope.user.userTypeId = result.userType.id;
a80703599   Rishav   FBO department fu...
20
21
          UpdateAllFBODept.getNotes(userProfileID).then(function(response) {
            $scope.user.clientNote = response[0].notes
104d51edf   Rishav   all new api imple...
22
            $scope.user.userNoteId = response[0].id;
a80703599   Rishav   FBO department fu...
23
24
25
26
27
28
29
30
31
          })
          // $scope.feature = result.accountFeatureControl;
          // console.log($scope.feature,"dsdsdsds")
          if($scope.user.account.user.status == 'ACTIVE'){
            $scope.status = true;
          }else {
            $scope.status = false;
          }
        })
47e72f419   Rishav   update aircraft, ...
32
33
34
        getCrafts();
        function getCrafts(){
          UpdateAllFBODept.getAircrafts(userProfileID).then(function(response) {
104d51edf   Rishav   all new api imple...
35
            $scope.getCraftList = response;
47e72f419   Rishav   update aircraft, ...
36
37
38
          })
        }
        
104d51edf   Rishav   all new api imple...
39
40
41
42
43
44
45
46
47
48
49
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
        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 = [];
        }
  
        $scope.userData = function(){
          console.log($scope.user.userTypeId)
db8e1f992   Rishav   pending user api,...
77
78
79
80
81
82
83
84
85
          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...
86
            if($scope.status == true){
104d51edf   Rishav   all new api imple...
87
88
89
90
91
92
93
              $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...
94
95
96
            // if($scope.user.userNoteId == undefined){
            //   $scope.user.userNoteId = null;
            // }
104d51edf   Rishav   all new api imple...
97
98
99
100
101
102
            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
              })
            })
db8e1f992   Rishav   pending user api,...
103
          }
104d51edf   Rishav   all new api imple...
104
105
106
107
108
109
110
111
112
113
        }
  
        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...
114

db8e1f992   Rishav   pending user api,...
115
116
117
118
119
120
              FBOFlight.getAircraftSize($scope.aircraft.make, $scope.aircraft.model).then(function(result) {
                $scope.aircraftSizeList = result;
                $scope.aircraft.size = $scope.aircraftSizeList[0];
                  
              })
            })
104d51edf   Rishav   all new api imple...
121
122
123
              
          })
        }
104d51edf   Rishav   all new api imple...
124
125
  
        $scope.getModal = function(){
db8e1f992   Rishav   pending user api,...
126
127
          var makeId = $scope.aircraft.make
          FBOFlight.getModal(makeId).then(function(result) {
104d51edf   Rishav   all new api imple...
128
129
            $scope.aircraftModalList = result;
            $scope.aircraft.model = $scope.aircraftModalList[0];
db8e1f992   Rishav   pending user api,...
130
131
132
133
134
  
            FBOFlight.getAircraftSize(makeId, $scope.aircraft.model).then(function(result) {
              $scope.aircraftSizeList = result;
              $scope.aircraft.size = $scope.aircraftSizeList[0];
            })
104d51edf   Rishav   all new api imple...
135
136
          })
        }
db8e1f992   Rishav   pending user api,...
137
138
139
140
141
142
143
  
        $scope.getSize = function(){
          FBOFlight.getAircraftSize($scope.aircraft.make, $scope.aircraft.model).then(function(result) {
            $scope.aircraftSizeList = result;
            $scope.aircraft.size = $scope.aircraftSizeList[0];
          })
        }
104d51edf   Rishav   all new api imple...
144
145
        $scope.aircraftData = {};
        $scope.aircraftData.aircraftList = [];
104d51edf   Rishav   all new api imple...
146
147
        $scope.addAircraft = function(){
          $scope.aircraftData.aircraftList.push($scope.aircraft);
104d51edf   Rishav   all new api imple...
148
149
150
          
          FBOFlight.addAircraft($scope.aircraftData).then(function(result) {
            $('#myModal4').modal('hide');
47e72f419   Rishav   update aircraft, ...
151
            getCrafts();
104d51edf   Rishav   all new api imple...
152
153
154
155
            $scope.resetData();
            toastr.success('Created Successfully', {
              closeButton: true
            })
db8e1f992   Rishav   pending user api,...
156
157
158
159
160
161
162
          }, function (err) {
              toastr.error('Error in Adding Aircraft', {
                closeButton: true
              })
              $('#myModal4').modal('hide');
              $scope.getCraftList.splice($scope.aircraft);
          });
104d51edf   Rishav   all new api imple...
163
        }
47e72f419   Rishav   update aircraft, ...
164
165
166
167
168
169
        $scope.closeModal = function(){
          $("#myModal5").modal('hide');
          $scope.resetData();
        }
  
        $scope.update = function(airdata){
db8e1f992   Rishav   pending user api,...
170
          $("#myModal5").modal('show');
47e72f419   Rishav   update aircraft, ...
171
          $scope.aircraft = airdata;
db8e1f992   Rishav   pending user api,...
172
          console.log($scope.aircraft)
47e72f419   Rishav   update aircraft, ...
173
          $scope.aircraft.accountId = $scope.user.account.id;
db8e1f992   Rishav   pending user api,...
174
          
47e72f419   Rishav   update aircraft, ...
175
176
          FBOFlight.getModal($scope.aircraft.make).then(function(result) {
            $scope.aircraftModalList = result;
db8e1f992   Rishav   pending user api,...
177
178
179
180
            FBOFlight.getAircraftSize($scope.aircraft.make, $scope.aircraft.model).then(function(result) {
              $scope.aircraftSizeList = result;
                
            })
47e72f419   Rishav   update aircraft, ...
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
          })
        }
  
        $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;
          $scope.updateAircraftData.size = updateAircraft.size;
          $scope.updateAircraftData.tail = updateAircraft.tail;
          $scope.updateAircraftData.accountId = updateAircraft.accountId;
          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();
            toastr.success('Updated Successfully', {
              closeButton: true
            })
db8e1f992   Rishav   pending user api,...
206
207
208
209
210
211
212
          }, function (err) {
              toastr.error('Error in Updating Aircraft', {
                closeButton: true
              })
              $('#myModal5').modal('hide');
              $scope.getCraftList.splice($scope.aircraft);
          });
47e72f419   Rishav   update aircraft, ...
213
214
215
216
217
218
219
220
221
222
223
        }
  
        $scope.remove = function(data){
          console.log(data)
          UpdateAllFBODept.removeAircraft(data.id).then(function(result) {
            toastr.success(''+result.success+'', {
              closeButton: true
            })
            getCrafts();
          })
        }
104d51edf   Rishav   all new api imple...
224
225
226
227
228
229
        $scope.resetData = function() {
          $scope.aircraft = {};
          $scope.aircraft.accountId = $scope.user.account.id;
          $scope.aircraftData.aircraftList = [];
          getData();
        }
a80703599   Rishav   FBO department fu...
230
    });