Commit 65045c830a1212ba6f3ef1b37730582b3491dc3b

Authored by Kuldeep Arora
1 parent f49ed758ac
Exists in master

margin

app/partials/customers/customers.controller.js
1 'use strict'; 1 'use strict';
2 2
3 //Load controller 3 //Load controller
4 angular.module('acufuel') 4 angular.module('acufuel')
5 .controller('customersController', ['$scope', '$rootScope', '$uibModal', '$filter', '$http', '$state', 'CustomersService', 'ViewCompanyService', 'NgTableParams','fuelOrdersService', customersController]); 5 .controller('customersController', ['$scope', '$rootScope', '$uibModal', '$filter', '$http', '$state', 'CustomersService', 'ViewCompanyService', 'NgTableParams','fuelOrdersService', customersController]);
6 6
7 function customersController($scope, $rootScope, $uibModal, $filter, $http, $state, CustomersService, ViewCompanyService, NgTableParams,fuelOrdersService) { 7 function customersController($scope, $rootScope, $uibModal, $filter, $http, $state, CustomersService, ViewCompanyService, NgTableParams,fuelOrdersService) {
8 $(document).ready(function() { 8 $(document).ready(function() {
9 // $('#example').DataTable(); 9 // $('#example').DataTable();
10 }); 10 });
11 $scope.userProfileId = JSON.parse(localStorage.getItem('userProfileId')) 11 $scope.userProfileId = JSON.parse(localStorage.getItem('userProfileId'))
12 $scope.reset2 = function(){ 12 $scope.reset2 = function(){
13 $("input").val(""); 13 $("input").val("");
14 $scope.removeMarginValidation(); 14 $scope.removeMarginValidation();
15 } 15 }
16 16
17 17
18 $scope.data = {}; 18 $scope.data = {};
19 $scope.aircraft = {}; 19 $scope.aircraft = {};
20 $scope.data.activate = true; 20 $scope.data.activate = true;
21 $scope.showLoader = true; 21 $scope.showLoader = true;
22 $scope.jetShow = []; 22 $scope.jetShow = [];
23 $scope.marginShow = []; 23 $scope.marginShow = [];
24 24
25 $scope.jetShow[0] = true; 25 $scope.jetShow[0] = true;
26 $scope.marginShow[0] = true; 26 $scope.marginShow[0] = true;
27 $scope.dispatchOrder = {}; 27 $scope.dispatchOrder = {};
28 $scope.dispatchOrder.fuelOrderList = []; 28 $scope.dispatchOrder.fuelOrderList = [];
29 $scope.statusFilterOptions = []; 29 $scope.statusFilterOptions = [];
30 $scope.companyList = {}; 30 $scope.companyList = {};
31 $scope.statusFilterOptions.push({ 31 $scope.statusFilterOptions.push({
32 'id': '', 'title': 'Show All' 32 'id': '', 'title': 'Show All'
33 },{ 33 },{
34 'id': 'pending', 'title': 'Pending' 34 'id': 'pending', 'title': 'Pending'
35 },{ 35 },{
36 'id': 'invoiced', 'title': 'Invoiced' 36 'id': 'invoiced', 'title': 'Invoiced'
37 },{ 37 },{
38 'id': 'paid', 'title': 'Paid' 38 'id': 'paid', 'title': 'Paid'
39 },{ 39 },{
40 'id': 'cancelled', 'title': 'Cancelled' 40 'id': 'cancelled', 'title': 'Cancelled'
41 },{ 41 },{
42 'id': 'archived', 'title': 'Archived' 42 'id': 'archived', 'title': 'Archived'
43 } 43 }
44 44
45 ); 45 );
46 46
47 getAllCompanies(); 47 getAllCompanies();
48 48
49 /*function getAllCompanies(){ 49 /*function getAllCompanies(){
50 CustomersService.getAllCompanies().then(function(result) { 50 CustomersService.getAllCompanies().then(function(result) {
51 $scope.companyList = result; 51 $scope.companyList = result;
52 for(var i=0; i<$scope.companyList.length; i++){ 52 for(var i=0; i<$scope.companyList.length; i++){
53 $scope.companyList[i].masterMargin = $scope.companyList[i].margin.id; 53 $scope.companyList[i].masterMargin = $scope.companyList[i].margin.id;
54 } 54 }
55 }) 55 })
56 56
57 }*/ 57 }*/
58 58
59 $scope.statusFilter = [ 59 $scope.statusFilter = [
60 {id: "", title: "Show All"}, 60 {id: "", title: "Show All"},
61 {id: "true", title: "Active"}, 61 {id: "true", title: "Active"},
62 {id: "false", title: "Inactive"} 62 {id: "false", title: "Inactive"}
63 ] 63 ]
64 64
65 function getAllCompanies(){ 65 function getAllCompanies(){
66 CustomersService.getAllCompanies().then(function(result) { 66 CustomersService.getAllCompanies().then(function(result) {
67 //console.log('log', result); 67 //console.log('log', result);
68 $scope.companyList = result; 68 $scope.companyList = result;
69 for (var i = 0; i < $scope.companyList.length; i++) { 69 for (var i = 0; i < $scope.companyList.length; i++) {
70 if ($scope.companyList[i].companyContact != null) { 70 if ($scope.companyList[i].companyContact != null) {
71 if ($scope.companyList[i].companyContact.contactNumber != null || $scope.companyList[i].companyContact.contactNumber != undefined) { 71 if ($scope.companyList[i].companyContact.contactNumber != null || $scope.companyList[i].companyContact.contactNumber != undefined) {
72 $scope.companyList[i].newContactNumber = $scope.companyList[i].companyContact.contactNumber; 72 $scope.companyList[i].newContactNumber = $scope.companyList[i].companyContact.contactNumber;
73 } 73 }
74 } 74 }
75 if ($scope.companyList[i].primaryContact != null) { 75 if ($scope.companyList[i].primaryContact != null) {
76 if ($scope.companyList[i].primaryContact.firstName != null && $scope.companyList[i].primaryContact.lastName != null) { 76 if ($scope.companyList[i].primaryContact.firstName != null && $scope.companyList[i].primaryContact.lastName != null) {
77 $scope.companyList[i].primaryContactName = $scope.companyList[i].primaryContact.firstName + ' ' + $scope.companyList[i].primaryContact.lastName; 77 $scope.companyList[i].primaryContactName = $scope.companyList[i].primaryContact.firstName + ' ' + $scope.companyList[i].primaryContact.lastName;
78 } 78 }
79 } 79 }
80 if ($scope.companyList[i].margin != null) { 80 if ($scope.companyList[i].margin != null) {
81 if ($scope.companyList[i].margin.marginName != null) { 81 if ($scope.companyList[i].margin.marginName != null) {
82 $scope.companyList[i].masterMargin = $scope.companyList[i].margin.id; 82 $scope.companyList[i].masterMargin = $scope.companyList[i].margin.id;
83 } 83 }
84 } 84 }
85 } 85 }
86 $scope.displayCompanyList = new NgTableParams({ 86 $scope.displayCompanyList = new NgTableParams({
87 page: 1, 87 page: 1,
88 count: 10, 88 count: 10,
89 }, { 89 }, {
90 data: $scope.companyList 90 data: $scope.companyList
91 }); 91 });
92 $scope.showLoader = false; 92 $scope.showLoader = false;
93 }) 93 })
94 } 94 }
95 95
96 $scope.editMargin = function(customer){ 96 $scope.editMargin = function(customer){
97 console.log('customer', customer); 97 console.log('customer', customer);
98 $scope.showLoader = true; 98 $scope.showLoader = true;
99 event.stopPropagation(); 99 event.stopPropagation();
100 100
101 var companyMargin = "companyName=" + customer.companyName + "&masterMargin=" + customer.masterMargin 101 var companyMargin = "companyName=" + customer.companyName + "&masterMargin=" + customer.masterMargin
102 + "&addressOne=" + customer.addressOne + "&addressTwo=" + customer.addressTwo + "&city=" + customer.city + "&state=" 102 + "&addressOne=" + customer.addressOne + "&addressTwo=" + customer.addressTwo + "&city=" + customer.city + "&state="
103 + customer.state + "&country=" + customer.country + "&zipcode=" + customer.zipcode + "&internalNote=" 103 + customer.state + "&country=" + customer.country + "&zipcode=" + customer.zipcode + "&internalNote="
104 + customer.internalNote + "&certificateType=" + customer.certificateType + "&baseTenant=" + customer.baseTenant 104 + customer.internalNote + "&certificateType=" + customer.certificateType + "&baseTenant=" + customer.baseTenant
105 + "&fuelerlinxCustomer=" + customer.fuelerlinxCustomer + "&contractFuelVendor=" + customer.contractFuelVendor 105 + "&fuelerlinxCustomer=" + customer.fuelerlinxCustomer + "&contractFuelVendor=" + customer.contractFuelVendor
106 + "&activate=" + customer.activate + "&baseIcao=" + customer.baseIcao + "&companyId=" + customer.id; 106 + "&activate=" + customer.activate + "&baseIcao=" + customer.baseIcao + "&companyId=" + customer.id;
107 107
108 ViewCompanyService.updateCompany(companyMargin).then(function(result) { 108 ViewCompanyService.updateCompany(companyMargin).then(function(result) {
109 if(result != null && result.success){ 109 if(result != null && result.success){
110 $scope.showLoader = false; 110 $scope.showLoader = false;
111 getAllCompanies();
111 toastr.success(''+result.success+'', { 112 toastr.success(''+result.success+'', {
112 closeButton: true 113 closeButton: true
113 }) 114 })
114 getAllCompanies();
115 }else{ 115 }else{
116 $scope.showLoader = false; 116 $scope.showLoader = false;
117 toastr.error(''+result.statusText+'', { 117 toastr.error(''+result.statusText+'', {
118 closeButton: true 118 closeButton: true
119 }) 119 })
120 } 120 }
121 }) 121 })
122 } 122 }
123 123
124 getData(); 124 getData();
125 function getData(){ 125 function getData(){
126 $scope.showLoader = true; 126 $scope.showLoader = true;
127 CustomersService.getAircraftMake().then(function(result) { 127 CustomersService.getAircraftMake().then(function(result) {
128 $scope.aircraftMakeList = result; 128 $scope.aircraftMakeList = result;
129 $scope.showLoader = false; 129 $scope.showLoader = false;
130 }) 130 })
131 } 131 }
132 132
133 133
134 // CustomersService.getMargin().then(function(result) { 134 // CustomersService.getMargin().then(function(result) {
135 // $scope.marginList = result; 135 // $scope.marginList = result;
136 // }) 136 // })
137 $scope.marginFilterOptions = []; 137 $scope.marginFilterOptions = [];
138 CustomersService.getJetMargin($scope.userProfileId).then(function(result) { 138 CustomersService.getJetMargin($scope.userProfileId).then(function(result) {
139 $scope.showLoader = true; 139 $scope.showLoader = true;
140 $scope.jetMarginList = result; 140 $scope.jetMarginList = result;
141 //console.log("jet margin",result,$scope.userProfileId) 141 //console.log("jet margin",result,$scope.userProfileId)
142 $scope.marginFilterOptions.push({ 142 $scope.marginFilterOptions.push({
143 'id': '', 'title': 'Show All' 143 'id': '', 'title': 'Show All'
144 }); 144 });
145 for (var i = 0; i < result.length; i++) { 145 for (var i = 0; i < result.length; i++) {
146 $scope.marginFilterOptions.push({ 146 $scope.marginFilterOptions.push({
147 'id': result[i].id, 147 'id': result[i].id,
148 'title': result[i].marginName 148 'title': result[i].marginName
149 }) 149 })
150 } 150 }
151 $scope.showLoader = false; 151 $scope.showLoader = false;
152 }) 152 })
153 153
154 CustomersService.getAvgMargin($scope.userProfileId).then(function(result) { 154 CustomersService.getAvgMargin($scope.userProfileId).then(function(result) {
155 $scope.avgsMarginList = result; 155 $scope.avgsMarginList = result;
156 // console.log('avgsMarginList',result) 156 // console.log('avgsMarginList',result)
157 }) 157 })
158 158
159 159
160 $scope.showCompanyError = false; 160 $scope.showCompanyError = false;
161 $scope.showMarginError = false; 161 $scope.showMarginError = false;
162 162
163 $scope.removeValidation = function(){ 163 $scope.removeValidation = function(){
164 $scope.showCompanyError = false; 164 $scope.showCompanyError = false;
165 $('.companyNameInput').removeClass('customErrorInput'); 165 $('.companyNameInput').removeClass('customErrorInput');
166 if($scope.data.companyName == 'undefined' || $scope.data.companyName == '') { 166 if($scope.data.companyName == 'undefined' || $scope.data.companyName == '') {
167 $('.companyNameInput').addClass('customErrorInput'); 167 $('.companyNameInput').addClass('customErrorInput');
168 $scope.showCompanyError = true; 168 $scope.showCompanyError = true;
169 } 169 }
170 } 170 }
171 171
172 $scope.removeMarginValidation = function(){ 172 $scope.removeMarginValidation = function(){
173 $scope.showMarginError = false; 173 $scope.showMarginError = false;
174 $('.marginSelectBox').removeClass('customErrorInput'); 174 $('.marginSelectBox').removeClass('customErrorInput');
175 } 175 }
176 176
177 var companyData; 177 var companyData;
178 $scope.addFirstData = function(sel, step){ 178 $scope.addFirstData = function(sel, step){
179 $scope.showLoader = true; 179 $scope.showLoader = true;
180 if($scope.data.companyName == undefined){ 180 if($scope.data.companyName == undefined){
181 $scope.showCompanyError = true; 181 $scope.showCompanyError = true;
182 $('.companyNameInput').addClass('customErrorInput'); 182 $('.companyNameInput').addClass('customErrorInput');
183 }else if($scope.data.masterMargin == undefined){ 183 }else if($scope.data.masterMargin == undefined){
184 $scope.showMarginError = true; 184 $scope.showMarginError = true;
185 $('.marginSelectBox').addClass('customErrorInput'); 185 $('.marginSelectBox').addClass('customErrorInput');
186 }else{ 186 }else{
187 $scope.aircraftDetails = [{ 187 $scope.aircraftDetails = [{
188 'tail':'', 188 'tail':'',
189 'make': '', 189 'make': '',
190 'model': '', 190 'model': '',
191 'sizeId' : '', 191 'sizeId' : '',
192 'marginId': $scope.data.masterMargin, 192 'marginId': $scope.data.masterMargin,
193 'avgasMarginId': $scope.data.avgasMargin 193 'avgasMarginId': $scope.data.avgasMargin
194 }]; 194 }];
195 195
196 $(sel).trigger('next.m.' + step); 196 $(sel).trigger('next.m.' + step);
197 getData(); 197 getData();
198 } 198 }
199 $scope.showLoader = false; 199 $scope.showLoader = false;
200 } 200 }
201 $scope.addNew = function(){ 201 $scope.addNew = function(){
202 $scope.showLoader = true; 202 $scope.showLoader = true;
203 $scope.aircraftDetails.push({ 203 $scope.aircraftDetails.push({
204 'tail':'', 204 'tail':'',
205 'make': '', 205 'make': '',
206 'model': '', 206 'model': '',
207 'sizeId' : '', 207 'sizeId' : '',
208 'marginId': $scope.data.masterMargin, 208 'marginId': $scope.data.masterMargin,
209 'avgasMarginId': $scope.data.avgasMargin 209 'avgasMarginId': $scope.data.avgasMargin
210 }); 210 });
211 $scope.showLoader = false; 211 $scope.showLoader = false;
212 }; 212 };
213 213
214 $scope.getModal = function(makeId, index){ 214 $scope.getModal = function(makeId, index){
215 $scope.showLoader = true; 215 $scope.showLoader = true;
216 //console.log(makeId) 216 //console.log(makeId)
217 $scope.aircraft.make = makeId; 217 $scope.aircraft.make = makeId;
218 //var makeId = makeId; 218 //var makeId = makeId;
219 CustomersService.getModal($scope.aircraft.make).then(function(result) { 219 CustomersService.getModal($scope.aircraft.make).then(function(result) {
220 $scope.showLoader = false; 220 $scope.showLoader = false;
221 $scope.aircraftDetails[index].aircraftModalList = result; 221 $scope.aircraftDetails[index].aircraftModalList = result;
222 //$scope.aircraftDetails[index].model = $scope.aircraftModalList[0]; 222 //$scope.aircraftDetails[index].model = $scope.aircraftModalList[0];
223 }) 223 })
224 } 224 }
225 225
226 $scope.getSize = function(model, index){ 226 $scope.getSize = function(model, index){
227 $scope.showLoader = true; 227 $scope.showLoader = true;
228 CustomersService.getAircraftSize($scope.aircraft.make, model).then(function(result) { 228 CustomersService.getAircraftSize($scope.aircraft.make, model).then(function(result) {
229 $scope.showLoader = false; 229 $scope.showLoader = false;
230 $scope.aircraftDetails[index].aircraftSizeList = result; 230 $scope.aircraftDetails[index].aircraftSizeList = result;
231 231
232 }) 232 })
233 } 233 }
234 234
235 235
236 236
237 $scope.aircraftListData = {}; 237 $scope.aircraftListData = {};
238 $scope.addData = []; 238 $scope.addData = [];
239 $scope.saveCompanyData = function(){ 239 $scope.saveCompanyData = function(){
240 CustomersService.addCompany($scope.data).then(function(result) { 240 CustomersService.addCompany($scope.data).then(function(result) {
241 $scope.accountId = result; 241 $scope.accountId = result;
242 $scope.aircraft.accountId = $scope.accountId; 242 $scope.aircraft.accountId = $scope.accountId;
243 243
244 for(var i=0; i<$scope.aircraftDetails.length;i++){ 244 for(var i=0; i<$scope.aircraftDetails.length;i++){
245 $scope.addData.push({ 245 $scope.addData.push({
246 'tail': $scope.aircraftDetails[i].tail, 246 'tail': $scope.aircraftDetails[i].tail,
247 'make': $scope.aircraftDetails[i].make, 247 'make': $scope.aircraftDetails[i].make,
248 'model': $scope.aircraftDetails[i].model, 248 'model': $scope.aircraftDetails[i].model,
249 'sizeId' : $scope.aircraftDetails[i].sizeId, 249 'sizeId' : $scope.aircraftDetails[i].sizeId,
250 'marginId': $scope.aircraftDetails[i].marginId, 250 'marginId': $scope.aircraftDetails[i].marginId,
251 'avgasMarginId': $scope.aircraftDetails[i].avgasMarginId 251 'avgasMarginId': $scope.aircraftDetails[i].avgasMarginId
252 }); 252 });
253 } 253 }
254 $scope.aircraftListData.aircraftList = $scope.addData; 254 $scope.aircraftListData.aircraftList = $scope.addData;
255 $scope.aircraftListData.accountId = $scope.aircraft.accountId; 255 $scope.aircraftListData.accountId = $scope.aircraft.accountId;
256 256
257 if($scope.aircraftListData.aircraftList[0].tail == "" || $scope.aircraftListData.aircraftList[0].make == null || $scope.aircraftListData.aircraftList[0].model == null){ 257 if($scope.aircraftListData.aircraftList[0].tail == "" || $scope.aircraftListData.aircraftList[0].make == null || $scope.aircraftListData.aircraftList[0].model == null){
258 $scope.aircraftListData.aircraftList = []; 258 $scope.aircraftListData.aircraftList = [];
259 } 259 }
260 260
261 CustomersService.addAircraft($scope.aircraftListData).then(function(result) { 261 CustomersService.addAircraft($scope.aircraftListData).then(function(result) {
262 262
263 if(result != null && result.success){ 263 if(result != null && result.success){
264 toastr.success(''+result.success+'', { 264 toastr.success(''+result.success+'', {
265 closeButton: true 265 closeButton: true
266 }) 266 })
267 $('#demo-modal-3').modal('hide'); 267 $('#demo-modal-3').modal('hide');
268 getAllCompanies(); 268 getAllCompanies();
269 }else{ 269 }else{
270 toastr.error(''+result.statusText+'', { 270 toastr.error(''+result.statusText+'', {
271 closeButton: true 271 closeButton: true
272 }) 272 })
273 } 273 }
274 }); 274 });
275 275
276 }) 276 })
277 277
278 278
279 } 279 }
280 280
281 /*add a fuel order*/ 281 /*add a fuel order*/
282 282
283 283
284 $scope.getOrders = function() { 284 $scope.getOrders = function() {
285 fuelOrdersService.getOrders().then(function(result) { 285 fuelOrdersService.getOrders().then(function(result) {
286 286
287 $scope.orderdata = result; 287 $scope.orderdata = result;
288 for(var i=0;i<$scope.orderdata.length;i++){ 288 for(var i=0;i<$scope.orderdata.length;i++){
289 $scope.orderdata[i].upliftDateS = new Date($scope.orderdata[i].upliftDate); 289 $scope.orderdata[i].upliftDateS = new Date($scope.orderdata[i].upliftDate);
290 290
291 // var str = "" + $scope.orderdata[i].upliftDateS.getDate() + "/" + ($scope.orderdata[i].upliftDateS.getMonth() + 1) + "/" + $scope.orderdata[i].upliftDateS.getFullYear() 291 // var str = "" + $scope.orderdata[i].upliftDateS.getDate() + "/" + ($scope.orderdata[i].upliftDateS.getMonth() + 1) + "/" + $scope.orderdata[i].upliftDateS.getFullYear()
292 var str = "" + ($scope.orderdata[i].upliftDateS.getMonth() + 1) + "/" + $scope.orderdata[i].upliftDateS.getDate() + "/" + $scope.orderdata[i].upliftDateS.getFullYear() 292 var str = "" + ($scope.orderdata[i].upliftDateS.getMonth() + 1) + "/" + $scope.orderdata[i].upliftDateS.getDate() + "/" + $scope.orderdata[i].upliftDateS.getFullYear()
293 // str = str.slice(4,16) 293 // str = str.slice(4,16)
294 $scope.orderdata[i].upliftDateString = str 294 $scope.orderdata[i].upliftDateString = str
295 // console.log(str); 295 // console.log(str);
296 296
297 } 297 }
298 298
299 $scope.displayFuelOrderList = new NgTableParams({ 299 $scope.displayFuelOrderList = new NgTableParams({
300 page: 1, 300 page: 1,
301 count: 10, 301 count: 10,
302 }, { 302 }, {
303 data: $scope.orderdata 303 data: $scope.orderdata
304 }); 304 });
305 $(document).ready(function(){ 305 $(document).ready(function(){
306 var myselect = document.getElementsByClassName('colorfulSelectbox'); 306 var myselect = document.getElementsByClassName('colorfulSelectbox');
307 307
308 for (var i = 0; i < myselect.length; i++) { 308 for (var i = 0; i < myselect.length; i++) {
309 var colourIndex = $(myselect[i]).prop('selectedIndex'); 309 var colourIndex = $(myselect[i]).prop('selectedIndex');
310 colourIndex = colourIndex + 1; 310 colourIndex = colourIndex + 1;
311 // console.log(colourIndex); 311 // console.log(colourIndex);
312 var getColor = $('.colorfulSelectbox option:nth-child('+colourIndex+')').css('color'); 312 var getColor = $('.colorfulSelectbox option:nth-child('+colourIndex+')').css('color');
313 $(myselect[i]).css('background-color', getColor); 313 $(myselect[i]).css('background-color', getColor);
314 // console.log('colour', getColor); 314 // console.log('colour', getColor);
315 myselect[i].blur(); 315 myselect[i].blur();
316 } 316 }
317 317
318 }) 318 })
319 319
320 }) 320 })
321 } 321 }
322 322
323 $scope.getOrders(); 323 $scope.getOrders();
324 324
325 $scope.addFuelData = function() { 325 $scope.addFuelData = function() {
326 $scope.showLoader = true; 326 $scope.showLoader = true;
327 327
328 if ($scope.order.priceQuote === null || $scope.order.priceQuote == '') { 328 if ($scope.order.priceQuote === null || $scope.order.priceQuote == '') {
329 // console.log("valid"); 329 // console.log("valid");
330 $scope.showLoader = false; 330 $scope.showLoader = false;
331 toastr.error('Please select Company and Price Quote.', { 331 toastr.error('Please select Company and Price Quote.', {
332 closeButton: true 332 closeButton: true
333 }) 333 })
334 }else{ 334 }else{
335 335
336 if ($scope.order.upliftDate != '') { 336 if ($scope.order.upliftDate != '') {
337 $scope.order.upliftDate = new Date($scope.order.upliftDate); 337 $scope.order.upliftDate = new Date($scope.order.upliftDate);
338 $scope.order.upliftDate = $scope.order.upliftDate.getTime(); 338 $scope.order.upliftDate = $scope.order.upliftDate.getTime();
339 } 339 }
340 if ($scope.order.departingDate != '') { 340 if ($scope.order.departingDate != '') {
341 $scope.order.departingDate = new Date($scope.order.departingDate); 341 $scope.order.departingDate = new Date($scope.order.departingDate);
342 $scope.order.departingDate = $scope.order.departingDate.getTime(); 342 $scope.order.departingDate = $scope.order.departingDate.getTime();
343 } 343 }
344 // console.log($scope.order.quotePrice); 344 // console.log($scope.order.quotePrice);
345 var obj =JSON.parse($scope.order.priceQuote); 345 var obj =JSON.parse($scope.order.priceQuote);
346 // console.log('obj.papMargin',obj.papMargin); 346 // console.log('obj.papMargin',obj.papMargin);
347 $scope.order.priceQuote = obj.papMargin; 347 $scope.order.priceQuote = obj.papMargin;
348 348
349 $scope.fuelData = {}; 349 $scope.fuelData = {};
350 $scope.fuelData.aircraftName = $scope.order.aircraftName 350 $scope.fuelData.aircraftName = $scope.order.aircraftName
351 $scope.fuelData.companyName = $scope.order.companyName 351 $scope.fuelData.companyName = $scope.order.companyName
352 $scope.fuelData.departingDate = $scope.order.departingDate 352 $scope.fuelData.departingDate = $scope.order.departingDate
353 $scope.fuelData.fboCost = $scope.order.fboCost 353 $scope.fuelData.fboCost = $scope.order.fboCost
354 $scope.fuelData.id = $scope.order.id 354 $scope.fuelData.id = $scope.order.id
355 $scope.fuelData.invoiced = $scope.order.invoiced 355 $scope.fuelData.invoiced = $scope.order.invoiced
356 $scope.fuelData.priceQuote = $scope.order.priceQuote 356 $scope.fuelData.priceQuote = $scope.order.priceQuote
357 $scope.fuelData.volume = $scope.order.volume 357 $scope.fuelData.volume = $scope.order.volume
358 $scope.fuelData.source = $scope.order.source 358 $scope.fuelData.source = $scope.order.source
359 $scope.fuelData.status = $scope.order.status 359 $scope.fuelData.status = $scope.order.status
360 $scope.fuelData.tierBreak = $scope.order.tierBreak 360 $scope.fuelData.tierBreak = $scope.order.tierBreak
361 $scope.fuelData.total = $scope.order.total 361 $scope.fuelData.total = $scope.order.total
362 $scope.fuelData.upliftDate = $scope.order.upliftDate 362 $scope.fuelData.upliftDate = $scope.order.upliftDate
363 $scope.fuelData.companyId = $scope.selectedCompanyId; 363 $scope.fuelData.companyId = $scope.selectedCompanyId;
364 364
365 365
366 366
367 $scope.dispatchOrder.fuelOrderList.push($scope.fuelData); 367 $scope.dispatchOrder.fuelOrderList.push($scope.fuelData);
368 // console.log('$scope.order', $scope.dispatchOrder); 368 // console.log('$scope.order', $scope.dispatchOrder);
369 fuelOrdersService.dispathFuelOrder($scope.dispatchOrder).then(function(result) { 369 fuelOrdersService.dispathFuelOrder($scope.dispatchOrder).then(function(result) {
370 //console.log("fuel data---",$scope.fuelData) 370 //console.log("fuel data---",$scope.fuelData)
371 //console.log("oder data",$scope.dispatchOrder) 371 //console.log("oder data",$scope.dispatchOrder)
372 //console.log('result', result); 372 //console.log('result', result);
373 $scope.showLoader = false; 373 $scope.showLoader = false;
374 $scope.order = {}; 374 $scope.order = {};
375 $('#demo-modal-4').css('display', ''); 375 $('#demo-modal-4').css('display', '');
376 $scope.getOrders(); 376 $scope.getOrders();
377 toastr.success('Fuel Order Dispatched Successfully', { 377 toastr.success('Fuel Order Dispatched Successfully', {
378 closeButton: true 378 closeButton: true
379 }) 379 })
380 }) 380 })
381 381
382 } 382 }
383 } 383 }
384 384
385 $scope.addTotal = function(value, valueOf){ 385 $scope.addTotal = function(value, valueOf){
386 if(valueOf == 'v'){ 386 if(valueOf == 'v'){
387 $scope.order.total = value * $scope.order.invoiced 387 $scope.order.total = value * $scope.order.invoiced
388 }else if(valueOf == 'i'){ 388 }else if(valueOf == 'i'){
389 $scope.order.total = $scope.order.volume * value 389 $scope.order.total = $scope.order.volume * value
390 } 390 }
391 } 391 }
392 392
393 $scope.getAircraft = function(company){ 393 $scope.getAircraft = function(company){
394 394
395 $scope.selectedCompanyName = company; 395 $scope.selectedCompanyName = company;
396 //$scope.showLoader = true; 396 //$scope.showLoader = true;
397 // console.log("id",company) 397 // console.log("id",company)
398 for (var i = 0; i < $scope.companyList.length; i++) { 398 for (var i = 0; i < $scope.companyList.length; i++) {
399 if ($scope.companyList[i].companyName == company) { 399 if ($scope.companyList[i].companyName == company) {
400 if($scope.companyList[i].margin != null && $scope.companyList[i].marginAVGAS != null){ 400 if($scope.companyList[i].margin != null && $scope.companyList[i].marginAVGAS != null){
401 fuelOrdersService.getFuelCost($scope.companyList[i].id).then(function(margins) { 401 fuelOrdersService.getFuelCost($scope.companyList[i].id).then(function(margins) {
402 $scope.marginList = margins; 402 $scope.marginList = margins;
403 //console.log('$scope.marginList', $scope.marginList); 403 //console.log('$scope.marginList', $scope.marginList);
404 }) 404 })
405 } else if ($scope.companyList[i].margin != null || $scope.companyList[i].marginAVGAS == null) { 405 } else if ($scope.companyList[i].margin != null || $scope.companyList[i].marginAVGAS == null) {
406 fuelOrdersService.getATypeFuelPricing($scope.companyList[i].id).then(function(margins) { 406 fuelOrdersService.getATypeFuelPricing($scope.companyList[i].id).then(function(margins) {
407 $scope.marginList = margins; 407 $scope.marginList = margins;
408 }) 408 })
409 } else if ($scope.companyList[i].margin == null || $scope.companyList[i].marginAVGAS != null) { 409 } else if ($scope.companyList[i].margin == null || $scope.companyList[i].marginAVGAS != null) {
410 fuelOrdersService.getVTypeFuelPricing($scope.companyList[i].id).then(function(margins) { 410 fuelOrdersService.getVTypeFuelPricing($scope.companyList[i].id).then(function(margins) {
411 $scope.marginList = margins; 411 $scope.marginList = margins;
412 }) 412 })
413 } 413 }
414 $scope.selectedCompanyId = $scope.companyList[i].id; 414 $scope.selectedCompanyId = $scope.companyList[i].id;
415 $scope.marginId = $scope.companyList[i].margin.id; 415 $scope.marginId = $scope.companyList[i].margin.id;
416 if ($scope.selectedCompanyId != '') { 416 if ($scope.selectedCompanyId != '') {
417 fuelOrdersService.getAircraft($scope.selectedCompanyId).then(function(aircraft) { 417 fuelOrdersService.getAircraft($scope.selectedCompanyId).then(function(aircraft) {
418 $scope.aircraftList = aircraft; 418 $scope.aircraftList = aircraft;
419 }) 419 })
420 } 420 }
421 if ($scope.marginId != '') { 421 if ($scope.marginId != '') {
422 fuelOrdersService.getJetTiers($scope.marginId).then(function(tiers) { 422 fuelOrdersService.getJetTiers($scope.marginId).then(function(tiers) {
423 $scope.tierList = tiers; 423 $scope.tierList = tiers;
424 // $scope.showLoader = false; 424 // $scope.showLoader = false;
425 }) 425 })
426 }else{ 426 }else{
427 // $scope.showLoader = false; 427 // $scope.showLoader = false;
428 } 428 }
429 } 429 }
430 } 430 }
431 431
432 } 432 }
433 433
434 $scope.setCost = function(cost){ 434 $scope.setCost = function(cost){
435 // console.log(cost); 435 // console.log(cost);
436 if(cost != null) { 436 if(cost != null) {
437 var obj =JSON.parse(cost); 437 var obj =JSON.parse(cost);
438 // console.log("0bj",obj) 438 // console.log("0bj",obj)
439 $scope.order.fboCost = obj.cost; 439 $scope.order.fboCost = obj.cost;
440 } 440 }
441 441
442 } 442 }
443 443
444 $scope.sourceList = [{source:"Direct Jet-A"},{source:"Direct AVGAS 100LL"}]; 444 $scope.sourceList = [{source:"Direct Jet-A"},{source:"Direct AVGAS 100LL"}];
445 $scope.cancelData = function() { 445 $scope.cancelData = function() {
446 $('#demo-modal-4').css('display', ''); 446 $('#demo-modal-4').css('display', '');
447 } 447 }
448 448
449 449
450 450
451 // $scope.appendText = function() { 451 // $scope.appendText = function() {
452 // getData(); 452 // getData();
453 // 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>'); 453 // 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>');
454 // $('table.addRow').append(newRow); 454 // $('table.addRow').append(newRow);
455 // } 455 // }
456 456
457 $scope.setFuel = function(){ 457 $scope.setFuel = function(){
458 $('#demo-modal-4').css('display', 'block'); 458 $('#demo-modal-4').css('display', 'block');
459 // event.stopPropagation(); 459 // event.stopPropagation();
460 // $state.go('app.updateFuelManager'); 460 // $state.go('app.updateFuelManager');
461 } 461 }
462 462
463 /* ng table */ 463 /* ng table */
464 464
465 $scope.exportCompany = function() { 465 $scope.exportCompany = function() {
466 $scope.showLoader = true; 466 $scope.showLoader = true;
467 var fileName = "companies.csv"; 467 var fileName = "companies.csv";
468 var a = document.createElement("a"); 468 var a = document.createElement("a");
469 document.body.appendChild(a); 469 document.body.appendChild(a);
470 CustomersService.exportCompany().then(function(result) { 470 CustomersService.exportCompany().then(function(result) {
471 var file = new Blob([result], {type: 'application/csv'}); 471 var file = new Blob([result], {type: 'application/csv'});
472 var fileURL = URL.createObjectURL(file); 472 var fileURL = URL.createObjectURL(file);
473 a.href = fileURL; 473 a.href = fileURL;
474 a.download = fileName; 474 a.download = fileName;
475 a.click(); 475 a.click();
476 $scope.showLoader = false; 476 $scope.showLoader = false;
477 }) 477 })
478 } 478 }
479 getCompanyName(); 479 getCompanyName();
480 function getCompanyName(){ 480 function getCompanyName(){
481 CustomersService.getCompanyName().then(function(result) { 481 CustomersService.getCompanyName().then(function(result) {
482 $scope.compNameList = result; 482 $scope.compNameList = result;
483 //console.log("kd",result) 483 //console.log("kd",result)
484 }) 484 })
485 } 485 }
486 486
487 $scope.checkJetWithTail = function(tail, index){ 487 $scope.checkJetWithTail = function(tail, index){
488 488
489 //console.log("tail==============",tail, index) 489 //console.log("tail==============",tail, index)
490 ViewCompanyService.checkJetType(tail).then(function(result) { 490 ViewCompanyService.checkJetType(tail).then(function(result) {
491 //console.log("result",result) 491 //console.log("result",result)
492 if(result.jetA == "true"){ 492 if(result.jetA == "true"){
493 $scope.jetShow[index] = false; 493 $scope.jetShow[index] = false;
494 $scope.marginShow[index] = true; 494 $scope.marginShow[index] = true;
495 }else{ 495 }else{
496 $scope.jetShow[index] = true; 496 $scope.jetShow[index] = true;
497 $scope.marginShow[index] = false; 497 $scope.marginShow[index] = false;
498 } 498 }
499 }) 499 })
500 } 500 }
501 501
502 502