Blame view
app/partials/customers/customers.controller.js
11.2 KB
feacde5ff
|
1 2 3 4 |
'use strict'; //Load controller angular.module('acufuel') |
eefc1c74d
![]() |
5 |
.controller('customersController', ['$scope', '$rootScope', '$uibModal', '$filter', '$http', '$state', 'CustomersService', 'ViewCompanyService', 'NgTableParams', customersController]); |
feacde5ff
|
6 |
|
eefc1c74d
![]() |
7 |
function customersController($scope, $rootScope, $uibModal, $filter, $http, $state, CustomersService, ViewCompanyService, NgTableParams) { |
4bb02bb84
|
8 |
$(document).ready(function() { |
05bfa28a2
|
9 |
// $('#example').DataTable(); |
4bb02bb84
|
10 |
}); |
a7a7cfeca
![]() |
11 |
$scope.userProfileId = JSON.parse(localStorage.getItem('userProfileId')) |
7152ff131
|
12 13 |
$scope.reset2 = function(){ $("input").val(""); |
49676befb
|
14 |
$scope.removeMarginValidation(); |
7152ff131
|
15 |
} |
05bfa28a2
|
16 |
|
7152ff131
|
17 |
|
4bb02bb84
|
18 19 20 |
$scope.data = {}; $scope.aircraft = {}; $scope.data.activate = true; |
05bfa28a2
|
21 |
$scope.showLoader = true; |
c2f3d77be
![]() |
22 23 24 25 26 27 |
$scope.jetShow = []; $scope.marginShow = []; $scope.jetShow[0] = true; $scope.marginShow[0] = true; |
b6f0311a3
|
28 |
getAllCompanies(); |
eefc1c74d
![]() |
29 |
/*function getAllCompanies(){ |
b6f0311a3
|
30 |
CustomersService.getAllCompanies().then(function(result) { |
b6f0311a3
|
31 |
$scope.companyList = result; |
3a9f4472b
|
32 33 34 |
for(var i=0; i<$scope.companyList.length; i++){ $scope.companyList[i].masterMargin = $scope.companyList[i].margin.id; } |
b6f0311a3
|
35 |
}) |
eefc1c74d
![]() |
36 37 38 39 40 41 42 43 |
}*/ $scope.statusFilter = [ {id: "", title: "Show All"}, {id: "true", title: "Active"}, {id: "false", title: "Inactive"} ] |
b97bc56e0
![]() |
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 |
function getAllCompanies(){ CustomersService.getAllCompanies().then(function(result) { console.log('log', result); $scope.companyList = result; for (var i = 0; i < $scope.companyList.length; i++) { if ($scope.companyList[i].companyContact != null) { if ($scope.companyList[i].companyContact.contactNumber != null || $scope.companyList[i].companyContact.contactNumber != undefined) { $scope.companyList[i].newContactNumber = $scope.companyList[i].companyContact.contactNumber; } } if ($scope.companyList[i].primaryContact != null) { if ($scope.companyList[i].primaryContact.firstName != null && $scope.companyList[i].primaryContact.lastName != null) { $scope.companyList[i].primaryContactName = $scope.companyList[i].primaryContact.firstName + ' ' + $scope.companyList[i].primaryContact.lastName; } } if ($scope.companyList[i].margin != null) { if ($scope.companyList[i].margin.marginName != null) { $scope.companyList[i].masterMargin = $scope.companyList[i].margin.id; } } } $scope.displayCompanyList = new NgTableParams({ page: 1, count: 10, }, { data: $scope.companyList }); |
05bfa28a2
|
71 |
$scope.showLoader = false; |
b97bc56e0
![]() |
72 |
}) |
b6f0311a3
|
73 |
} |
feacde5ff
|
74 |
|
3a9f4472b
|
75 |
$scope.editMargin = function(customer){ |
b97bc56e0
![]() |
76 |
console.log('customer', customer); |
52fea957f
|
77 |
$scope.showLoader = true; |
d24318592
|
78 |
event.stopPropagation(); |
3a9f4472b
|
79 80 81 82 83 84 85 |
var companyMargin = "companyName=" + customer.companyName + "&masterMargin=" + customer.masterMargin + "&addressOne=" + customer.addressOne + "&addressTwo=" + customer.addressTwo + "&city=" + customer.city + "&state=" + customer.state + "&country=" + customer.country + "&zipcode=" + customer.zipcode + "&internalNote=" + customer.internalNote + "&certificateType=" + customer.certificateType + "&baseTenant=" + customer.baseTenant + "&fuelerlinxCustomer=" + customer.fuelerlinxCustomer + "&contractFuelVendor=" + customer.contractFuelVendor + "&activate=" + customer.activate + "&baseIcao=" + customer.baseIcao + "&companyId=" + customer.id; |
cdf775224
|
86 |
ViewCompanyService.updateCompany(companyMargin).then(function(result) { |
3a9f4472b
|
87 |
if(result != null && result.success){ |
52fea957f
|
88 |
$scope.showLoader = false; |
3a9f4472b
|
89 90 91 92 |
toastr.success(''+result.success+'', { closeButton: true }) }else{ |
52fea957f
|
93 |
$scope.showLoader = false; |
3a9f4472b
|
94 95 96 97 98 99 |
toastr.error(''+result.statusText+'', { closeButton: true }) } }) } |
4bb02bb84
|
100 101 |
getData(); function getData(){ |
05bfa28a2
|
102 |
$scope.showLoader = true; |
4bb02bb84
|
103 |
CustomersService.getAircraftMake().then(function(result) { |
4bb02bb84
|
104 |
$scope.aircraftMakeList = result; |
05bfa28a2
|
105 |
$scope.showLoader = false; |
4bb02bb84
|
106 107 |
}) } |
3a9f4472b
|
108 |
|
a7a7cfeca
![]() |
109 110 111 112 113 114 |
// CustomersService.getMargin().then(function(result) { // $scope.marginList = result; // }) $scope.marginFilterOptions = []; CustomersService.getJetMargin($scope.userProfileId).then(function(result) { |
9aae3d136
|
115 |
$scope.showLoader = true; |
07328f442
![]() |
116 117 118 119 120 121 122 123 124 125 126 |
$scope.jetMarginList = result; $scope.marginFilterOptions.push({ 'id': '', 'title': 'Show All' }); for (var i = 0; i < result.length; i++) { $scope.marginFilterOptions.push({ 'id': result[i].id, 'title': result[i].marginName }) } $scope.showLoader = false; |
a7a7cfeca
![]() |
127 |
}) |
c95befcd3
![]() |
128 |
|
a7a7cfeca
![]() |
129 130 |
CustomersService.getAvgMargin($scope.userProfileId).then(function(result) { $scope.avgsMarginList = result; |
3a9f4472b
|
131 |
}) |
a7a7cfeca
![]() |
132 |
|
32286a73a
![]() |
133 134 135 136 |
$scope.showCompanyError = false; $scope.showMarginError = false; $scope.removeValidation = function(){ |
32286a73a
![]() |
137 138 |
$scope.showCompanyError = false; $('.companyNameInput').removeClass('customErrorInput'); |
5e7aae2d2
|
139 140 141 142 |
if($scope.data.companyName == 'undefined' || $scope.data.companyName == '') { $('.companyNameInput').addClass('customErrorInput'); $scope.showCompanyError = true; } |
32286a73a
![]() |
143 144 145 146 147 148 |
} $scope.removeMarginValidation = function(){ $scope.showMarginError = false; $('.marginSelectBox').removeClass('customErrorInput'); } |
6efd9a0a8
|
149 150 |
var companyData; |
4bb02bb84
|
151 |
$scope.addFirstData = function(sel, step){ |
9aae3d136
|
152 |
$scope.showLoader = true; |
3a9f4472b
|
153 |
if($scope.data.companyName == undefined){ |
32286a73a
![]() |
154 155 |
$scope.showCompanyError = true; $('.companyNameInput').addClass('customErrorInput'); |
3a9f4472b
|
156 |
}else if($scope.data.masterMargin == undefined){ |
32286a73a
![]() |
157 158 |
$scope.showMarginError = true; $('.marginSelectBox').addClass('customErrorInput'); |
3a9f4472b
|
159 |
}else{ |
cdf775224
|
160 161 162 163 164 165 166 167 168 |
$scope.aircraftDetails = [{ 'tail':'', 'make': '', 'model': '', 'sizeId' : '', 'marginId': $scope.data.masterMargin, 'avgasMarginId': $scope.data.avgasMargin }]; |
3a9f4472b
|
169 170 171 |
$(sel).trigger('next.m.' + step); getData(); } |
9aae3d136
|
172 |
$scope.showLoader = false; |
4bb02bb84
|
173 |
} |
55e075d7e
|
174 |
$scope.addNew = function(){ |
9aae3d136
|
175 |
$scope.showLoader = true; |
55e075d7e
|
176 177 178 179 |
$scope.aircraftDetails.push({ 'tail':'', 'make': '', 'model': '', |
3a9f4472b
|
180 |
'sizeId' : '', |
a7a7cfeca
![]() |
181 182 |
'marginId': $scope.data.masterMargin, 'avgasMarginId': $scope.data.avgasMargin |
55e075d7e
|
183 |
}); |
9aae3d136
|
184 |
$scope.showLoader = false; |
55e075d7e
|
185 186 187 |
}; $scope.getModal = function(makeId, index){ |
d24318592
|
188 |
$scope.showLoader = true; |
55e075d7e
|
189 190 191 |
$scope.aircraft.make = makeId; //var makeId = makeId; CustomersService.getModal($scope.aircraft.make).then(function(result) { |
d24318592
|
192 |
$scope.showLoader = false; |
55e075d7e
|
193 194 195 196 |
$scope.aircraftDetails[index].aircraftModalList = result; //$scope.aircraftDetails[index].model = $scope.aircraftModalList[0]; }) } |
4bb02bb84
|
197 |
|
55e075d7e
|
198 |
$scope.getSize = function(model, index){ |
d24318592
|
199 |
$scope.showLoader = true; |
55e075d7e
|
200 |
CustomersService.getAircraftSize($scope.aircraft.make, model).then(function(result) { |
d24318592
|
201 |
$scope.showLoader = false; |
7152ff131
|
202 |
$scope.aircraftDetails[index].aircraftSizeList = result; |
55e075d7e
|
203 |
//$scope.aircraftDetails[index].size = $scope.aircraftSizeList[0]; |
55e075d7e
|
204 205 206 207 208 209 |
}) } $scope.aircraftListData = {}; $scope.addData = []; $scope.saveCompanyData = function(){ |
cdf775224
|
210 |
CustomersService.addCompany($scope.data).then(function(result) { |
6efd9a0a8
|
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
$scope.accountId = result; $scope.aircraft.accountId = $scope.accountId; 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, 'sizeId' : $scope.aircraftDetails[i].sizeId, 'marginId': $scope.aircraftDetails[i].marginId, 'avgasMarginId': $scope.aircraftDetails[i].avgasMarginId }); } $scope.aircraftListData.aircraftList = $scope.addData; $scope.aircraftListData.accountId = $scope.aircraft.accountId; |
cdf775224
|
227 228 229 230 |
if($scope.aircraftListData.aircraftList[0].tail == "" || $scope.aircraftListData.aircraftList[0].make == null || $scope.aircraftListData.aircraftList[0].model == null){ $scope.aircraftListData.aircraftList = []; } |
6efd9a0a8
|
231 |
CustomersService.addAircraft($scope.aircraftListData).then(function(result) { |
b6f0311a3
|
232 |
|
6efd9a0a8
|
233 234 235 236 237 238 239 240 241 242 243 244 |
if(result != null && result.success){ toastr.success(''+result.success+'', { closeButton: true }) $('#demo-modal-3').modal('hide'); getAllCompanies(); }else{ toastr.error(''+result.statusText+'', { closeButton: true }) } }); |
cdf775224
|
245 |
|
6efd9a0a8
|
246 247 |
}) |
55e075d7e
|
248 249 250 251 252 253 254 255 |
} // $scope.appendText = function() { // getData(); // var newRow = $('<tr> <td> <input type="text" style="width:100px;" ng-model="aircraft.tail" class="form-control"> </td> <td style="width: 25%;"> <select class="form-control" ng-model="aircraft.make" ng-change="getModal()"> <option ng-repeat="make in aircraftMakeList">{{make}}</option> </select> </td> <td style="width: 20%;"> <select class="form-control" ng-model="aircraft.model" ng-change="getSize()"> <option ng-repeat="model in aircraftModalList">{{model}}</option> </select> </td> <td style="width: 25%;"> <select class="form-control" ng-model="aircraft.size"> <option ng-repeat="size in aircraftSizeList">{{size}}</option> </select> </td> <td> <select class="form-control"> <option>Margin1</option> <option>Margin2</option> </select> </td> </tr>'); // $('table.addRow').append(newRow); // } |
4bb02bb84
|
256 |
|
67044e31e
![]() |
257 258 259 260 |
$scope.setFuel = function(){ event.stopPropagation(); $state.go('app.updateFuelManager'); } |
eefc1c74d
![]() |
261 |
/* ng table */ |
52fea957f
|
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
$scope.exportCompany = function() { $scope.showLoader = true; var fileName = "companies.csv"; var a = document.createElement("a"); document.body.appendChild(a); CustomersService.exportCompany().then(function(result) { var file = new Blob([result], {type: 'application/csv'}); var fileURL = URL.createObjectURL(file); a.href = fileURL; a.download = fileName; a.click(); $scope.showLoader = false; }) } |
5e7aae2d2
|
277 278 279 |
getCompanyName(); function getCompanyName(){ CustomersService.getCompanyName().then(function(result) { |
a9aef0b1c
|
280 281 282 |
$scope.compNameList = result; }) } |
eefc1c74d
![]() |
283 |
|
c2f3d77be
![]() |
284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
$scope.checkJetWithTail = function(tail, index){ console.log("tail==============",tail, index) ViewCompanyService.checkJetType(tail).then(function(result) { console.log("result",result) if(result.jetA == "true"){ $scope.jetShow[index] = false; $scope.marginShow[index] = true; }else{ $scope.jetShow[index] = true; $scope.marginShow[index] = false; } }) } |
4bb02bb84
|
298 299 |
} |