Commit f49ed758aca18344ece2a89aebae53e6c8fbba09

Authored by Kuldeep Arora
1 parent e652e571f1
Exists in master

marginsetting fixed

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 toastr.success(''+result.success+'', { 111 toastr.success(''+result.success+'', {
112 closeButton: true 112 closeButton: true
113 }) 113 })
114 getAllCompanies();
114 }else{ 115 }else{
115 $scope.showLoader = false; 116 $scope.showLoader = false;
116 toastr.error(''+result.statusText+'', { 117 toastr.error(''+result.statusText+'', {
117 closeButton: true 118 closeButton: true
118 }) 119 })
119 } 120 }
120 }) 121 })
121 } 122 }
122 123
123 getData(); 124 getData();
124 function getData(){ 125 function getData(){
125 $scope.showLoader = true; 126 $scope.showLoader = true;
126 CustomersService.getAircraftMake().then(function(result) { 127 CustomersService.getAircraftMake().then(function(result) {
127 $scope.aircraftMakeList = result; 128 $scope.aircraftMakeList = result;
128 $scope.showLoader = false; 129 $scope.showLoader = false;
129 }) 130 })
130 } 131 }
131 132
132 133
133 // CustomersService.getMargin().then(function(result) { 134 // CustomersService.getMargin().then(function(result) {
134 // $scope.marginList = result; 135 // $scope.marginList = result;
135 // }) 136 // })
136 $scope.marginFilterOptions = []; 137 $scope.marginFilterOptions = [];
137 CustomersService.getJetMargin($scope.userProfileId).then(function(result) { 138 CustomersService.getJetMargin($scope.userProfileId).then(function(result) {
138 $scope.showLoader = true; 139 $scope.showLoader = true;
139 $scope.jetMarginList = result; 140 $scope.jetMarginList = result;
140 //console.log("jet margin",result,$scope.userProfileId) 141 //console.log("jet margin",result,$scope.userProfileId)
141 $scope.marginFilterOptions.push({ 142 $scope.marginFilterOptions.push({
142 'id': '', 'title': 'Show All' 143 'id': '', 'title': 'Show All'
143 }); 144 });
144 for (var i = 0; i < result.length; i++) { 145 for (var i = 0; i < result.length; i++) {
145 $scope.marginFilterOptions.push({ 146 $scope.marginFilterOptions.push({
146 'id': result[i].id, 147 'id': result[i].id,
147 'title': result[i].marginName 148 'title': result[i].marginName
148 }) 149 })
149 } 150 }
150 $scope.showLoader = false; 151 $scope.showLoader = false;
151 }) 152 })
152 153
153 CustomersService.getAvgMargin($scope.userProfileId).then(function(result) { 154 CustomersService.getAvgMargin($scope.userProfileId).then(function(result) {
154 $scope.avgsMarginList = result; 155 $scope.avgsMarginList = result;
155 // console.log('avgsMarginList',result) 156 // console.log('avgsMarginList',result)
156 }) 157 })
157 158
158 159
159 $scope.showCompanyError = false; 160 $scope.showCompanyError = false;
160 $scope.showMarginError = false; 161 $scope.showMarginError = false;
161 162
162 $scope.removeValidation = function(){ 163 $scope.removeValidation = function(){
163 $scope.showCompanyError = false; 164 $scope.showCompanyError = false;
164 $('.companyNameInput').removeClass('customErrorInput'); 165 $('.companyNameInput').removeClass('customErrorInput');
165 if($scope.data.companyName == 'undefined' || $scope.data.companyName == '') { 166 if($scope.data.companyName == 'undefined' || $scope.data.companyName == '') {
166 $('.companyNameInput').addClass('customErrorInput'); 167 $('.companyNameInput').addClass('customErrorInput');
167 $scope.showCompanyError = true; 168 $scope.showCompanyError = true;
168 } 169 }
169 } 170 }
170 171
171 $scope.removeMarginValidation = function(){ 172 $scope.removeMarginValidation = function(){
172 $scope.showMarginError = false; 173 $scope.showMarginError = false;
173 $('.marginSelectBox').removeClass('customErrorInput'); 174 $('.marginSelectBox').removeClass('customErrorInput');
174 } 175 }
175 176
176 var companyData; 177 var companyData;
177 $scope.addFirstData = function(sel, step){ 178 $scope.addFirstData = function(sel, step){
178 $scope.showLoader = true; 179 $scope.showLoader = true;
179 if($scope.data.companyName == undefined){ 180 if($scope.data.companyName == undefined){
180 $scope.showCompanyError = true; 181 $scope.showCompanyError = true;
181 $('.companyNameInput').addClass('customErrorInput'); 182 $('.companyNameInput').addClass('customErrorInput');
182 }else if($scope.data.masterMargin == undefined){ 183 }else if($scope.data.masterMargin == undefined){
183 $scope.showMarginError = true; 184 $scope.showMarginError = true;
184 $('.marginSelectBox').addClass('customErrorInput'); 185 $('.marginSelectBox').addClass('customErrorInput');
185 }else{ 186 }else{
186 $scope.aircraftDetails = [{ 187 $scope.aircraftDetails = [{
187 'tail':'', 188 'tail':'',
188 'make': '', 189 'make': '',
189 'model': '', 190 'model': '',
190 'sizeId' : '', 191 'sizeId' : '',
191 'marginId': $scope.data.masterMargin, 192 'marginId': $scope.data.masterMargin,
192 'avgasMarginId': $scope.data.avgasMargin 193 'avgasMarginId': $scope.data.avgasMargin
193 }]; 194 }];
194 195
195 $(sel).trigger('next.m.' + step); 196 $(sel).trigger('next.m.' + step);
196 getData(); 197 getData();
197 } 198 }
198 $scope.showLoader = false; 199 $scope.showLoader = false;
199 } 200 }
200 $scope.addNew = function(){ 201 $scope.addNew = function(){
201 $scope.showLoader = true; 202 $scope.showLoader = true;
202 $scope.aircraftDetails.push({ 203 $scope.aircraftDetails.push({
203 'tail':'', 204 'tail':'',
204 'make': '', 205 'make': '',
205 'model': '', 206 'model': '',
206 'sizeId' : '', 207 'sizeId' : '',
207 'marginId': $scope.data.masterMargin, 208 'marginId': $scope.data.masterMargin,
208 'avgasMarginId': $scope.data.avgasMargin 209 'avgasMarginId': $scope.data.avgasMargin
209 }); 210 });
210 $scope.showLoader = false; 211 $scope.showLoader = false;
211 }; 212 };
212 213
213 $scope.getModal = function(makeId, index){ 214 $scope.getModal = function(makeId, index){
214 $scope.showLoader = true; 215 $scope.showLoader = true;
215 //console.log(makeId) 216 //console.log(makeId)
216 $scope.aircraft.make = makeId; 217 $scope.aircraft.make = makeId;
217 //var makeId = makeId; 218 //var makeId = makeId;
218 CustomersService.getModal($scope.aircraft.make).then(function(result) { 219 CustomersService.getModal($scope.aircraft.make).then(function(result) {
219 $scope.showLoader = false; 220 $scope.showLoader = false;
220 $scope.aircraftDetails[index].aircraftModalList = result; 221 $scope.aircraftDetails[index].aircraftModalList = result;
221 //$scope.aircraftDetails[index].model = $scope.aircraftModalList[0]; 222 //$scope.aircraftDetails[index].model = $scope.aircraftModalList[0];
222 }) 223 })
223 } 224 }
224 225
225 $scope.getSize = function(model, index){ 226 $scope.getSize = function(model, index){
226 $scope.showLoader = true; 227 $scope.showLoader = true;
227 CustomersService.getAircraftSize($scope.aircraft.make, model).then(function(result) { 228 CustomersService.getAircraftSize($scope.aircraft.make, model).then(function(result) {
228 $scope.showLoader = false; 229 $scope.showLoader = false;
229 $scope.aircraftDetails[index].aircraftSizeList = result; 230 $scope.aircraftDetails[index].aircraftSizeList = result;
230 231
231 }) 232 })
232 } 233 }
233 234
234 235
235 236
236 $scope.aircraftListData = {}; 237 $scope.aircraftListData = {};
237 $scope.addData = []; 238 $scope.addData = [];
238 $scope.saveCompanyData = function(){ 239 $scope.saveCompanyData = function(){
239 CustomersService.addCompany($scope.data).then(function(result) { 240 CustomersService.addCompany($scope.data).then(function(result) {
240 $scope.accountId = result; 241 $scope.accountId = result;
241 $scope.aircraft.accountId = $scope.accountId; 242 $scope.aircraft.accountId = $scope.accountId;
242 243
243 for(var i=0; i<$scope.aircraftDetails.length;i++){ 244 for(var i=0; i<$scope.aircraftDetails.length;i++){
244 $scope.addData.push({ 245 $scope.addData.push({
245 'tail': $scope.aircraftDetails[i].tail, 246 'tail': $scope.aircraftDetails[i].tail,
246 'make': $scope.aircraftDetails[i].make, 247 'make': $scope.aircraftDetails[i].make,
247 'model': $scope.aircraftDetails[i].model, 248 'model': $scope.aircraftDetails[i].model,
248 'sizeId' : $scope.aircraftDetails[i].sizeId, 249 'sizeId' : $scope.aircraftDetails[i].sizeId,
249 'marginId': $scope.aircraftDetails[i].marginId, 250 'marginId': $scope.aircraftDetails[i].marginId,
250 'avgasMarginId': $scope.aircraftDetails[i].avgasMarginId 251 'avgasMarginId': $scope.aircraftDetails[i].avgasMarginId
251 }); 252 });
252 } 253 }
253 $scope.aircraftListData.aircraftList = $scope.addData; 254 $scope.aircraftListData.aircraftList = $scope.addData;
254 $scope.aircraftListData.accountId = $scope.aircraft.accountId; 255 $scope.aircraftListData.accountId = $scope.aircraft.accountId;
255 256
256 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){
257 $scope.aircraftListData.aircraftList = []; 258 $scope.aircraftListData.aircraftList = [];
258 } 259 }
259 260
260 CustomersService.addAircraft($scope.aircraftListData).then(function(result) { 261 CustomersService.addAircraft($scope.aircraftListData).then(function(result) {
261 262
262 if(result != null && result.success){ 263 if(result != null && result.success){
263 toastr.success(''+result.success+'', { 264 toastr.success(''+result.success+'', {
264 closeButton: true 265 closeButton: true
265 }) 266 })
266 $('#demo-modal-3').modal('hide'); 267 $('#demo-modal-3').modal('hide');
267 getAllCompanies(); 268 getAllCompanies();
268 }else{ 269 }else{
269 toastr.error(''+result.statusText+'', { 270 toastr.error(''+result.statusText+'', {
270 closeButton: true 271 closeButton: true
271 }) 272 })
272 } 273 }
273 }); 274 });
274 275
275 }) 276 })
276 277
277 278
278 } 279 }
279 280
280 /*add a fuel order*/ 281 /*add a fuel order*/
281 282
282 283
283 $scope.getOrders = function() { 284 $scope.getOrders = function() {
284 fuelOrdersService.getOrders().then(function(result) { 285 fuelOrdersService.getOrders().then(function(result) {
285 286
286 $scope.orderdata = result; 287 $scope.orderdata = result;
287 for(var i=0;i<$scope.orderdata.length;i++){ 288 for(var i=0;i<$scope.orderdata.length;i++){
288 $scope.orderdata[i].upliftDateS = new Date($scope.orderdata[i].upliftDate); 289 $scope.orderdata[i].upliftDateS = new Date($scope.orderdata[i].upliftDate);
289 290
290 // 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()
291 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()
292 // str = str.slice(4,16) 293 // str = str.slice(4,16)
293 $scope.orderdata[i].upliftDateString = str 294 $scope.orderdata[i].upliftDateString = str
294 // console.log(str); 295 // console.log(str);
295 296
296 } 297 }
297 298
298 $scope.displayFuelOrderList = new NgTableParams({ 299 $scope.displayFuelOrderList = new NgTableParams({
299 page: 1, 300 page: 1,
300 count: 10, 301 count: 10,
301 }, { 302 }, {
302 data: $scope.orderdata 303 data: $scope.orderdata
303 }); 304 });
304 $(document).ready(function(){ 305 $(document).ready(function(){
305 var myselect = document.getElementsByClassName('colorfulSelectbox'); 306 var myselect = document.getElementsByClassName('colorfulSelectbox');
306 307
307 for (var i = 0; i < myselect.length; i++) { 308 for (var i = 0; i < myselect.length; i++) {
308 var colourIndex = $(myselect[i]).prop('selectedIndex'); 309 var colourIndex = $(myselect[i]).prop('selectedIndex');
309 colourIndex = colourIndex + 1; 310 colourIndex = colourIndex + 1;
310 // console.log(colourIndex); 311 // console.log(colourIndex);
311 var getColor = $('.colorfulSelectbox option:nth-child('+colourIndex+')').css('color'); 312 var getColor = $('.colorfulSelectbox option:nth-child('+colourIndex+')').css('color');
312 $(myselect[i]).css('background-color', getColor); 313 $(myselect[i]).css('background-color', getColor);
313 // console.log('colour', getColor); 314 // console.log('colour', getColor);
314 myselect[i].blur(); 315 myselect[i].blur();
315 } 316 }
316 317
317 }) 318 })
318 319
319 }) 320 })
320 } 321 }
321 322
322 $scope.getOrders(); 323 $scope.getOrders();
323 324
324 $scope.addFuelData = function() { 325 $scope.addFuelData = function() {
325 $scope.showLoader = true; 326 $scope.showLoader = true;
326 327
327 if ($scope.order.priceQuote === null || $scope.order.priceQuote == '') { 328 if ($scope.order.priceQuote === null || $scope.order.priceQuote == '') {
328 // console.log("valid"); 329 // console.log("valid");
329 $scope.showLoader = false; 330 $scope.showLoader = false;
330 toastr.error('Please select Company and Price Quote.', { 331 toastr.error('Please select Company and Price Quote.', {
331 closeButton: true 332 closeButton: true
332 }) 333 })
333 }else{ 334 }else{
334 335
335 if ($scope.order.upliftDate != '') { 336 if ($scope.order.upliftDate != '') {
336 $scope.order.upliftDate = new Date($scope.order.upliftDate); 337 $scope.order.upliftDate = new Date($scope.order.upliftDate);
337 $scope.order.upliftDate = $scope.order.upliftDate.getTime(); 338 $scope.order.upliftDate = $scope.order.upliftDate.getTime();
338 } 339 }
339 if ($scope.order.departingDate != '') { 340 if ($scope.order.departingDate != '') {
340 $scope.order.departingDate = new Date($scope.order.departingDate); 341 $scope.order.departingDate = new Date($scope.order.departingDate);
341 $scope.order.departingDate = $scope.order.departingDate.getTime(); 342 $scope.order.departingDate = $scope.order.departingDate.getTime();
342 } 343 }
343 // console.log($scope.order.quotePrice); 344 // console.log($scope.order.quotePrice);
344 var obj =JSON.parse($scope.order.priceQuote); 345 var obj =JSON.parse($scope.order.priceQuote);
345 // console.log('obj.papMargin',obj.papMargin); 346 // console.log('obj.papMargin',obj.papMargin);
346 $scope.order.priceQuote = obj.papMargin; 347 $scope.order.priceQuote = obj.papMargin;
347 348
348 $scope.fuelData = {}; 349 $scope.fuelData = {};
349 $scope.fuelData.aircraftName = $scope.order.aircraftName 350 $scope.fuelData.aircraftName = $scope.order.aircraftName
350 $scope.fuelData.companyName = $scope.order.companyName 351 $scope.fuelData.companyName = $scope.order.companyName
351 $scope.fuelData.departingDate = $scope.order.departingDate 352 $scope.fuelData.departingDate = $scope.order.departingDate
352 $scope.fuelData.fboCost = $scope.order.fboCost 353 $scope.fuelData.fboCost = $scope.order.fboCost
353 $scope.fuelData.id = $scope.order.id 354 $scope.fuelData.id = $scope.order.id
354 $scope.fuelData.invoiced = $scope.order.invoiced 355 $scope.fuelData.invoiced = $scope.order.invoiced
355 $scope.fuelData.priceQuote = $scope.order.priceQuote 356 $scope.fuelData.priceQuote = $scope.order.priceQuote
356 $scope.fuelData.volume = $scope.order.volume 357 $scope.fuelData.volume = $scope.order.volume
357 $scope.fuelData.source = $scope.order.source 358 $scope.fuelData.source = $scope.order.source
358 $scope.fuelData.status = $scope.order.status 359 $scope.fuelData.status = $scope.order.status
359 $scope.fuelData.tierBreak = $scope.order.tierBreak 360 $scope.fuelData.tierBreak = $scope.order.tierBreak
360 $scope.fuelData.total = $scope.order.total 361 $scope.fuelData.total = $scope.order.total
361 $scope.fuelData.upliftDate = $scope.order.upliftDate 362 $scope.fuelData.upliftDate = $scope.order.upliftDate
362 $scope.fuelData.companyId = $scope.selectedCompanyId; 363 $scope.fuelData.companyId = $scope.selectedCompanyId;
363 364
364 365
365 366
366 $scope.dispatchOrder.fuelOrderList.push($scope.fuelData); 367 $scope.dispatchOrder.fuelOrderList.push($scope.fuelData);
367 // console.log('$scope.order', $scope.dispatchOrder); 368 // console.log('$scope.order', $scope.dispatchOrder);
368 fuelOrdersService.dispathFuelOrder($scope.dispatchOrder).then(function(result) { 369 fuelOrdersService.dispathFuelOrder($scope.dispatchOrder).then(function(result) {
369 //console.log("fuel data---",$scope.fuelData) 370 //console.log("fuel data---",$scope.fuelData)
370 //console.log("oder data",$scope.dispatchOrder) 371 //console.log("oder data",$scope.dispatchOrder)
371 //console.log('result', result); 372 //console.log('result', result);
372 $scope.showLoader = false; 373 $scope.showLoader = false;
373 $scope.order = {}; 374 $scope.order = {};
374 $('#demo-modal-4').css('display', ''); 375 $('#demo-modal-4').css('display', '');
375 $scope.getOrders(); 376 $scope.getOrders();
376 toastr.success('Fuel Order Dispatched Successfully', { 377 toastr.success('Fuel Order Dispatched Successfully', {
377 closeButton: true 378 closeButton: true
378 }) 379 })
379 }) 380 })
380 381
381 } 382 }
382 } 383 }
383 384
384 $scope.addTotal = function(value, valueOf){ 385 $scope.addTotal = function(value, valueOf){
385 if(valueOf == 'v'){ 386 if(valueOf == 'v'){
386 $scope.order.total = value * $scope.order.invoiced 387 $scope.order.total = value * $scope.order.invoiced
387 }else if(valueOf == 'i'){ 388 }else if(valueOf == 'i'){
388 $scope.order.total = $scope.order.volume * value 389 $scope.order.total = $scope.order.volume * value
389 } 390 }
390 } 391 }
391 392
392 $scope.getAircraft = function(company){ 393 $scope.getAircraft = function(company){
393 394
394 $scope.selectedCompanyName = company; 395 $scope.selectedCompanyName = company;
395 //$scope.showLoader = true; 396 //$scope.showLoader = true;
396 // console.log("id",company) 397 // console.log("id",company)
397 for (var i = 0; i < $scope.companyList.length; i++) { 398 for (var i = 0; i < $scope.companyList.length; i++) {
398 if ($scope.companyList[i].companyName == company) { 399 if ($scope.companyList[i].companyName == company) {
399 if($scope.companyList[i].margin != null && $scope.companyList[i].marginAVGAS != null){ 400 if($scope.companyList[i].margin != null && $scope.companyList[i].marginAVGAS != null){
400 fuelOrdersService.getFuelCost($scope.companyList[i].id).then(function(margins) { 401 fuelOrdersService.getFuelCost($scope.companyList[i].id).then(function(margins) {
401 $scope.marginList = margins; 402 $scope.marginList = margins;
402 //console.log('$scope.marginList', $scope.marginList); 403 //console.log('$scope.marginList', $scope.marginList);
403 }) 404 })
404 } 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) {
405 fuelOrdersService.getATypeFuelPricing($scope.companyList[i].id).then(function(margins) { 406 fuelOrdersService.getATypeFuelPricing($scope.companyList[i].id).then(function(margins) {
406 $scope.marginList = margins; 407 $scope.marginList = margins;
407 }) 408 })
408 } 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) {
409 fuelOrdersService.getVTypeFuelPricing($scope.companyList[i].id).then(function(margins) { 410 fuelOrdersService.getVTypeFuelPricing($scope.companyList[i].id).then(function(margins) {
410 $scope.marginList = margins; 411 $scope.marginList = margins;
411 }) 412 })
412 } 413 }
413 $scope.selectedCompanyId = $scope.companyList[i].id; 414 $scope.selectedCompanyId = $scope.companyList[i].id;
414 $scope.marginId = $scope.companyList[i].margin.id; 415 $scope.marginId = $scope.companyList[i].margin.id;
415 if ($scope.selectedCompanyId != '') { 416 if ($scope.selectedCompanyId != '') {
416 fuelOrdersService.getAircraft($scope.selectedCompanyId).then(function(aircraft) { 417 fuelOrdersService.getAircraft($scope.selectedCompanyId).then(function(aircraft) {
417 $scope.aircraftList = aircraft; 418 $scope.aircraftList = aircraft;
418 }) 419 })
419 } 420 }
420 if ($scope.marginId != '') { 421 if ($scope.marginId != '') {
421 fuelOrdersService.getJetTiers($scope.marginId).then(function(tiers) { 422 fuelOrdersService.getJetTiers($scope.marginId).then(function(tiers) {
422 $scope.tierList = tiers; 423 $scope.tierList = tiers;
423 // $scope.showLoader = false; 424 // $scope.showLoader = false;
424 }) 425 })
425 }else{ 426 }else{
426 // $scope.showLoader = false; 427 // $scope.showLoader = false;
427 } 428 }
428 } 429 }
429 } 430 }
430 431
431 } 432 }
432 433
433 $scope.setCost = function(cost){ 434 $scope.setCost = function(cost){
434 // console.log(cost); 435 // console.log(cost);
435 if(cost != null) { 436 if(cost != null) {
436 var obj =JSON.parse(cost); 437 var obj =JSON.parse(cost);
437 // console.log("0bj",obj) 438 // console.log("0bj",obj)
438 $scope.order.fboCost = obj.cost; 439 $scope.order.fboCost = obj.cost;
439 } 440 }
440 441
441 } 442 }
442 443
443 $scope.sourceList = [{source:"Direct Jet-A"},{source:"Direct AVGAS 100LL"}]; 444 $scope.sourceList = [{source:"Direct Jet-A"},{source:"Direct AVGAS 100LL"}];
444 $scope.cancelData = function() { 445 $scope.cancelData = function() {
445 $('#demo-modal-4').css('display', ''); 446 $('#demo-modal-4').css('display', '');
446 } 447 }
447 448
448 449
449 450
450 // $scope.appendText = function() { 451 // $scope.appendText = function() {
451 // getData(); 452 // getData();
452 // 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>');
453 // $('table.addRow').append(newRow); 454 // $('table.addRow').append(newRow);
454 // } 455 // }
455 456
456 $scope.setFuel = function(){ 457 $scope.setFuel = function(){
457 $('#demo-modal-4').css('display', 'block'); 458 $('#demo-modal-4').css('display', 'block');
458 // event.stopPropagation(); 459 // event.stopPropagation();
459 // $state.go('app.updateFuelManager'); 460 // $state.go('app.updateFuelManager');
460 } 461 }
461 462
462 /* ng table */ 463 /* ng table */
463 464
464 $scope.exportCompany = function() { 465 $scope.exportCompany = function() {
465 $scope.showLoader = true; 466 $scope.showLoader = true;
466 var fileName = "companies.csv"; 467 var fileName = "companies.csv";
467 var a = document.createElement("a"); 468 var a = document.createElement("a");
468 document.body.appendChild(a); 469 document.body.appendChild(a);
469 CustomersService.exportCompany().then(function(result) { 470 CustomersService.exportCompany().then(function(result) {
470 var file = new Blob([result], {type: 'application/csv'}); 471 var file = new Blob([result], {type: 'application/csv'});
471 var fileURL = URL.createObjectURL(file); 472 var fileURL = URL.createObjectURL(file);
472 a.href = fileURL; 473 a.href = fileURL;
473 a.download = fileName; 474 a.download = fileName;
474 a.click(); 475 a.click();
475 $scope.showLoader = false; 476 $scope.showLoader = false;
476 }) 477 })
477 } 478 }
478 getCompanyName(); 479 getCompanyName();
479 function getCompanyName(){ 480 function getCompanyName(){
480 CustomersService.getCompanyName().then(function(result) { 481 CustomersService.getCompanyName().then(function(result) {
481 $scope.compNameList = result; 482 $scope.compNameList = result;
482 //console.log("kd",result) 483 //console.log("kd",result)
483 }) 484 })
484 } 485 }
485 486
486 $scope.checkJetWithTail = function(tail, index){ 487 $scope.checkJetWithTail = function(tail, index){
487 488
488 //console.log("tail==============",tail, index) 489 //console.log("tail==============",tail, index)
489 ViewCompanyService.checkJetType(tail).then(function(result) { 490 ViewCompanyService.checkJetType(tail).then(function(result) {
490 //console.log("result",result) 491 //console.log("result",result)
491 if(result.jetA == "true"){ 492 if(result.jetA == "true"){
492 $scope.jetShow[index] = false; 493 $scope.jetShow[index] = false;
493 $scope.marginShow[index] = true; 494 $scope.marginShow[index] = true;
494 }else{ 495 }else{
495 $scope.jetShow[index] = true; 496 $scope.jetShow[index] = true;
496 $scope.marginShow[index] = false; 497 $scope.marginShow[index] = false;
497 } 498 }
498 }) 499 })
499 } 500 }
500 501
501 502
502 } 503 }