enterFuelOrder.controller.js
5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
'use strict';
angular.module('acufuel')
.controller('enterFuelOrderController', ['$scope', '$rootScope', '$uibModal', '$filter', '$http', 'enterFuelOrderService', enterFuelOrderController]);
function enterFuelOrderController($scope, $rootScope, $uibModal, $filter, $http, enterFuelOrderService) {
$scope.showLoader = true;
$scope.companyList = {};
enterFuelOrderService.getAllCompanies().then(function(result) {
$scope.showLoader = false;
$scope.companyList = result;
//console.log("---",result);
})
$scope.order = {};
$scope.dispatchOrder = {};
$scope.dispatchOrder.fuelOrderList = [];
$scope.order.upliftDate = '';
//$scope.order.departingDate = '';
$scope.selectedCompanyName = '';
$scope.selectedCompanyId = '';
$scope.marginId = '';
$scope.selectedTier = '';
$scope.getAircraft = function(company){
$scope.selectedCompanyName = company;
$scope.showLoader = true;
//console.log(--company---,$scope.selectedCompanyName);
for (var i = 0; i < $scope.companyList.length; i++) {
if ($scope.companyList[i].companyName == company) {
//console.log($scope.companyList[i].margin);
//console.log($scope.companyList[i].marginAVGAS);
if($scope.companyList[i].margin != null && $scope.companyList[i].marginAVGAS != null){
enterFuelOrderService.getFuelCost($scope.companyList[i].id).then(function(margins) {
$scope.marginList = margins;
//console.log('$scope.marginList', $scope.marginList);
})
} else if ($scope.companyList[i].margin != null && $scope.companyList[i].marginAVGAS == null) {
//console.log('--------------------',$scope.companyList[i].margin);
//console.log('--------------------',$scope.companyList[i].marginAVGAS);
enterFuelOrderService.getATypeFuelPricing($scope.companyList[i].id).then(function(margins) {
$scope.marginList = margins;
})
} else if ($scope.companyList[i].margin == null && $scope.companyList[i].marginAVGAS != null) {
enterFuelOrderService.getVTypeFuelPricing($scope.companyList[i].id).then(function(margins) {
$scope.marginList = margins;
})
} else if ($scope.companyList[i].margin == null && $scope.companyList[i].marginAVGAS == null) {
enterFuelOrderService.getPapFuelPricing($scope.companyList[i].id).then(function(margins) {
$scope.marginList = margins;
})
//console.log('--------------------',$scope.companyList[i].margin);
}
$scope.selectedCompanyId = $scope.companyList[i].id;
if ($scope.selectedCompanyId != '') {
enterFuelOrderService.getAircraft($scope.selectedCompanyId).then(function(aircraft) {
$scope.aircraftList = aircraft;
//console.log("aircraft",$scope.aircraftList);
})
}
if($scope.companyList[i].margin == null) {
$scope.tierList = [];
$scope.tierList.push({
'minTierBreak': '0', 'maxTierBreak': '∞'
});
$scope.showLoader = false;
} else {
$scope.marginId = $scope.companyList[i].margin.id;
if ($scope.marginId != '') {
enterFuelOrderService.getJetTiers($scope.marginId).then(function(tiers) {
$scope.tierList = tiers;
$scope.showLoader = false;
$scope.selectedTier = $scope.tierList[0];
//console.log("--tier--",$scope.tierList)
})
}else{
$scope.showLoader = false;
}
}
}
}
}
$scope.tiervalue=function(){
$scope.order.tierBreak=$scope.selectedTier.minTierBreak+'-'+$scope.selectedTier.maxTierBreak;
//console.log('tier value', $scope.order.tierBreak);
}
$scope.setCost = function(cost){
if(cost != null) {
var obj =JSON.parse(cost);
$scope.order.fboCost = obj.cost;
}
}
$scope.cancelOrder = function() {
$scope.order = {};
}
$scope.dispatchFuel = function(){
$scope.showLoader = true;
$scope.order.companyId = $scope.selectedCompanyId;
if ($scope.order.upliftDate != '') {
$scope.order.upliftDate = new Date($scope.order.upliftDate);
$scope.order.upliftDate = $scope.order.upliftDate.getTime();
}
/*if ($scope.order.departingDate != '') {
$scope.order.departingDate = new Date($scope.order.departingDate);
$scope.order.departingDate = $scope.order.departingDate.getTime();
}*/
$scope.order.status = 'pending';
//console.log($scope.order.quotePrice);
var obj =JSON.parse($scope.order.priceQuote);
//console.log('obj.papMargin',obj.papMargin);
$scope.order.priceQuote = obj.papMargin;
var aircraftObj =JSON.parse($scope.order.aircraftName);
$scope.order.aircraftName = aircraftObj.tail;
$scope.order.make = aircraftObj.make;
$scope.order.model = aircraftObj.model;
$scope.dispatchOrder.fuelOrderList.push($scope.order);
//console.log('$scope.order', $scope.dispatchOrder);
enterFuelOrderService.dispathFuelOrder($scope.dispatchOrder).then(function(result) {
console.log("--final data--",$scope.dispatchOrder)
//console.log('result', result);
$scope.showLoader = false;
$scope.order = {};
toastr.success('Fuel Order Dispatched Successfully', {
closeButton: true
})
})
}
}