Blame view
app/partials/customers/customers.controller.js
10.7 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 9 10 |
$(document).ready(function() { $('#example').DataTable(); }); |
a7a7cfeca
![]() |
11 |
$scope.userProfileId = JSON.parse(localStorage.getItem('userProfileId')) |
7152ff131
|
12 13 |
$scope.reset2 = function(){ $("input").val(""); |
49676befb
|
14 |
$scope.removeMarginValidation(); |
7152ff131
|
15 16 |
} |
4bb02bb84
|
17 18 19 |
$scope.data = {}; $scope.aircraft = {}; $scope.data.activate = true; |
d24318592
|
20 |
$scope.showLoader = false; |
b6f0311a3
|
21 |
getAllCompanies(); |
eefc1c74d
![]() |
22 |
/*function getAllCompanies(){ |
b6f0311a3
|
23 |
CustomersService.getAllCompanies().then(function(result) { |
b6f0311a3
|
24 |
$scope.companyList = result; |
3a9f4472b
|
25 26 27 |
for(var i=0; i<$scope.companyList.length; i++){ $scope.companyList[i].masterMargin = $scope.companyList[i].margin.id; } |
b6f0311a3
|
28 |
}) |
eefc1c74d
![]() |
29 30 31 32 33 34 35 36 |
}*/ $scope.statusFilter = [ {id: "", title: "Show All"}, {id: "true", title: "Active"}, {id: "false", title: "Inactive"} ] |
b97bc56e0
![]() |
37 |
/*function getAllCompanies(){ |
eefc1c74d
![]() |
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
$scope.displayCompanyList = new NgTableParams({ page: 1, count: 10 }, { total: 0, getData: function($defer, params) { CustomersService.getAllCompanies().then(function(result) { $scope.companyList = result; for(var i=0; i<$scope.companyList.length; i++){ $scope.companyList[i].masterMargin = $scope.companyList[i].margin.id; } var filteredData = params.filter() ? $filter('filter')($scope.companyList, params.filter()) : $scope.companyList; var orderedData = params.sorting() ? $filter('orderBy')(filteredData, params.orderBy()) : $scope.companyList; params.total(orderedData.length); $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count())); }) } }); |
b97bc56e0
![]() |
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 85 86 87 88 |
}*/ 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 }); }) |
b6f0311a3
|
89 |
} |
feacde5ff
|
90 |
|
3a9f4472b
|
91 |
$scope.editMargin = function(customer){ |
b97bc56e0
![]() |
92 |
console.log('customer', customer); |
d24318592
|
93 |
event.stopPropagation(); |
3a9f4472b
|
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
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; ViewCompanyService.updateContact(companyMargin).then(function(result) { if(result != null && result.success){ toastr.success(''+result.success+'', { closeButton: true }) }else{ toastr.error(''+result.statusText+'', { closeButton: true }) } }) } |
4bb02bb84
|
114 115 116 |
getData(); function getData(){ CustomersService.getAircraftMake().then(function(result) { |
4bb02bb84
|
117 |
$scope.aircraftMakeList = result; |
4bb02bb84
|
118 119 |
}) } |
3a9f4472b
|
120 |
|
a7a7cfeca
![]() |
121 122 123 124 125 126 127 |
// CustomersService.getMargin().then(function(result) { // $scope.marginList = result; // }) $scope.marginFilterOptions = []; CustomersService.getJetMargin($scope.userProfileId).then(function(result) { $scope.jetMarginList = result; |
c95befcd3
![]() |
128 129 130 131 132 133 134 135 136 |
$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 }) } |
a7a7cfeca
![]() |
137 |
}) |
c95befcd3
![]() |
138 |
|
a7a7cfeca
![]() |
139 140 |
CustomersService.getAvgMargin($scope.userProfileId).then(function(result) { $scope.avgsMarginList = result; |
3a9f4472b
|
141 |
}) |
a7a7cfeca
![]() |
142 |
|
32286a73a
![]() |
143 144 145 146 |
$scope.showCompanyError = false; $scope.showMarginError = false; $scope.removeValidation = function(){ |
32286a73a
![]() |
147 148 149 150 151 152 153 154 |
$scope.showCompanyError = false; $('.companyNameInput').removeClass('customErrorInput'); } $scope.removeMarginValidation = function(){ $scope.showMarginError = false; $('.marginSelectBox').removeClass('customErrorInput'); } |
6efd9a0a8
|
155 156 |
var companyData; |
4bb02bb84
|
157 |
$scope.addFirstData = function(sel, step){ |
3a9f4472b
|
158 |
if($scope.data.companyName == undefined){ |
32286a73a
![]() |
159 160 |
$scope.showCompanyError = true; $('.companyNameInput').addClass('customErrorInput'); |
3a9f4472b
|
161 |
}else if($scope.data.masterMargin == undefined){ |
32286a73a
![]() |
162 163 |
$scope.showMarginError = true; $('.marginSelectBox').addClass('customErrorInput'); |
3a9f4472b
|
164 |
}else{ |
6efd9a0a8
|
165 166 |
console.log($scope.data); companyData = "companyName=" + $scope.data.companyName + "&masterMargin=" + $scope.data.masterMargin |
3a9f4472b
|
167 168 169 170 |
+ "&addressOne=" + $scope.data.addressOne + "&addressTwo=" + $scope.data.addressTwo + "&city=" + $scope.data.city + "&state=" + $scope.data.state + "&country=" + $scope.data.country + "&zipcode=" + $scope.data.zipcode + "&internalNote=" + $scope.data.internalNote + "&certificateType=" + $scope.data.certificateType + "&baseTenant=" + $scope.data.baseTenant + "&fuelerlinxCustomer=" + $scope.data.fuelerlinxCustomer + "&contractFuelVendor=" + $scope.data.contractFuelVendor |
a7a7cfeca
![]() |
171 |
+ "&activate=" + $scope.data.activate + "&baseIcao=" + $scope.data.baseIcao + "&avgasMargin=" + $scope.data.avgasMargin; |
4bb02bb84
|
172 |
|
6efd9a0a8
|
173 |
|
3a9f4472b
|
174 175 176 |
$(sel).trigger('next.m.' + step); getData(); } |
4bb02bb84
|
177 |
} |
55e075d7e
|
178 179 180 181 |
$scope.aircraftDetails = [{ 'tail':'', 'make': '', 'model': '', |
3a9f4472b
|
182 |
'sizeId' : '', |
a7a7cfeca
![]() |
183 184 |
'marginId': $scope.data.masterMargin, 'avgasMarginId': $scope.data.avgasMargin |
55e075d7e
|
185 186 187 188 189 190 191 |
}]; $scope.addNew = function(){ $scope.aircraftDetails.push({ 'tail':'', 'make': '', 'model': '', |
3a9f4472b
|
192 |
'sizeId' : '', |
a7a7cfeca
![]() |
193 194 |
'marginId': $scope.data.masterMargin, 'avgasMarginId': $scope.data.avgasMargin |
55e075d7e
|
195 |
}); |
55e075d7e
|
196 197 198 |
}; $scope.getModal = function(makeId, index){ |
d24318592
|
199 |
$scope.showLoader = true; |
55e075d7e
|
200 201 202 |
$scope.aircraft.make = makeId; //var makeId = makeId; CustomersService.getModal($scope.aircraft.make).then(function(result) { |
d24318592
|
203 |
$scope.showLoader = false; |
55e075d7e
|
204 205 206 207 |
$scope.aircraftDetails[index].aircraftModalList = result; //$scope.aircraftDetails[index].model = $scope.aircraftModalList[0]; }) } |
4bb02bb84
|
208 |
|
55e075d7e
|
209 |
$scope.getSize = function(model, index){ |
d24318592
|
210 |
$scope.showLoader = true; |
55e075d7e
|
211 |
CustomersService.getAircraftSize($scope.aircraft.make, model).then(function(result) { |
d24318592
|
212 |
$scope.showLoader = false; |
7152ff131
|
213 |
$scope.aircraftDetails[index].aircraftSizeList = result; |
55e075d7e
|
214 |
//$scope.aircraftDetails[index].size = $scope.aircraftSizeList[0]; |
55e075d7e
|
215 216 217 218 219 220 |
}) } $scope.aircraftListData = {}; $scope.addData = []; $scope.saveCompanyData = function(){ |
6efd9a0a8
|
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
CustomersService.addCompany(companyData).then(function(result) { $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; CustomersService.addAircraft($scope.aircraftListData).then(function(result) { |
b6f0311a3
|
239 |
|
6efd9a0a8
|
240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
if(result != null && result.success){ toastr.success(''+result.success+'', { closeButton: true }) $('#demo-modal-3').modal('hide'); getAllCompanies(); }else{ toastr.error(''+result.statusText+'', { closeButton: true }) } }); }) |
55e075d7e
|
254 255 256 257 258 259 260 261 |
} // $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
|
262 |
|
67044e31e
![]() |
263 264 265 266 |
$scope.setFuel = function(){ event.stopPropagation(); $state.go('app.updateFuelManager'); } |
eefc1c74d
![]() |
267 |
/* ng table */ |
4bb02bb84
|
268 269 |
} |