diff --git a/app/partials/customers/customers.controller.js b/app/partials/customers/customers.controller.js index f253edd..7f7dca2 100644 --- a/app/partials/customers/customers.controller.js +++ b/app/partials/customers/customers.controller.js @@ -80,7 +80,6 @@ function customersController($scope, $rootScope, $uibModal, $filter, $http, $sta function getAllCompanies() { CustomersService.getAllCompanies().then(function(result) { - console.log('company list', result); $scope.companyList = result; for (var i = 0; i < $scope.companyList.length; i++) { if ($scope.companyList[i].companyContact != null) { @@ -214,6 +213,7 @@ function customersController($scope, $rootScope, $uibModal, $filter, $http, $sta } $scope.showLoader = false; } + $scope.addNew = function() { $scope.showLoader = true; $scope.aircraftDetails.push({ @@ -227,31 +227,104 @@ function customersController($scope, $rootScope, $uibModal, $filter, $http, $sta $scope.showLoader = false; }; - $scope.getModal = function(makeId, index) { + $scope.aircraftIdx = ''; + $scope.checkTail = function(tail, idx){ + var data = "tail=" + tail; + $scope.aircraftIdx = idx; + CustomersService.checkTailRegistration(data).then(function(result) { + if(result.error) { + $scope.aircraftMessage = result.error; + $scope.openAddAirCraftError(); + } else if(result.warning) { + $scope.aircraftMessage = result.warning; + $scope.openAddAirCraftWarning(); + } + }) + } + + $scope.openAddAirCraftError = function() { + $('#addAirCraftError').css('display', 'block'); + } + + $scope.openAddAirCraftWarning = function() { + $('#addAirCraftWarning').css('display', 'block'); + } + $scope.acceptAirCraftError = function() { + $('#addAirCraftWarning').css('display', 'none'); + } + + $scope.cancelAirCraftError = function() { + $scope.aircraftDetails[$scope.aircraftIdx].tail = ''; + $('#addAirCraftWarning').css('display', 'none'); + $('#addAirCraftError').css('display', 'none'); + } + + + /*$scope.getModal = function(makeId, index) { $scope.showLoader = true; - //console.log(makeId) - $scope.aircraft.make = makeId; - //var makeId = makeId; CustomersService.getModal($scope.aircraft.make).then(function(result) { $scope.showLoader = false; $scope.aircraftDetails[index].aircraftModalList = result; - //$scope.aircraftDetails[index].model = $scope.aircraftModalList[0]; }) - } + }*/ + $scope.getModal = function(makeId, index) { + $scope.showLoader = true; + $scope.aircraft.make = makeId; + CustomersService.getModal($scope.aircraft.make).then(function(result) { + $scope.showLoader = false; + $scope.aircraftDetails[index].aircraftModalList = result; + }) + } + + + $scope.selectedOption = ''; + $scope.getSize = function(model, index) { + $scope.showLoader = true; + $scope.aircraft.model = model; + CustomersService.getAircraftSize($scope.aircraft.make, model).then(function(result) { + $scope.showLoader = false; + $scope.aircraftDetails[index].aircraftSizeList = result; + + }) + } - $scope.getSize = function(model, index) { + /*$scope.getSize = function(model, index) { $scope.showLoader = true; CustomersService.getAircraftSize($scope.aircraft.make, model).then(function(result) { $scope.showLoader = false; $scope.aircraftDetails[index].aircraftSizeList = result; }) - } + }*/ + + $scope.getFuelType = function(size, index) { + $scope.showLoader = true; + var data = "model="+$scope.aircraft.model+"&make="+$scope.aircraft.make+"&sizeId="+size; + ViewCompanyService.checkFuelType(data).then(function(result){ + $scope.showLoader = false; + if (result.type == "JetA") { + $scope.jetShow[index] = false; + $scope.marginShow[index] = true; + } else if (result.type == "Avgas") { + $scope.jetShow[index] = true; + $scope.marginShow[index] = false; + }else { + $scope.jetShow[index] = true; + $scope.marginShow[index] = true; + } + }) + } $scope.aircraftListData = {}; $scope.addData = []; + $scope.tailArray = []; + function check(array){ + return (new Set(array)).size !== array.length; + } $scope.saveCompanyData = function() { - console.log("company data --",$scope.data) + // console.log("company data --",$scope.data) CustomersService.addCompany($scope.data).then(function(result) { + $scope.tailArray = []; + $scope.addData =[]; $scope.accountId = result; $scope.aircraft.accountId = $scope.accountId; @@ -264,37 +337,45 @@ function customersController($scope, $rootScope, $uibModal, $filter, $http, $sta 'marginId' : $scope.aircraftDetails[i].marginId, 'avgasMarginId' : $scope.aircraftDetails[i].avgasMarginId }); + $scope.tailArray.push($scope.aircraftDetails[i].tail); } - $scope.aircraftListData.aircraftList = $scope.addData; - $scope.aircraftListData.accountId = $scope.aircraft.accountId; - - if ($scope.aircraftListData.aircraftList[0].tail == "" || $scope.aircraftListData.aircraftList[0].make == null || $scope.aircraftListData.aircraftList[0].model == null) { - $scope.aircraftListData.aircraftList = []; - } - - CustomersService.addAircraft($scope.aircraftListData).then(function(result) { - - if (result != null && result.success) { - toastr.success('' + result.success + '', { - closeButton : true - }) - $('#demo-modal-3').css('display', 'none'); - $('.modal-backdrop').css('display', 'none'); - getAllCompanies(); - } else { - toastr.error('' + result.statusText + '', { - closeButton : true - }) + + if (check($scope.tailArray)) { + toastr.error('Duplicate Tail Added.', { + closeButton: true + }) + }else{ + $scope.aircraftListData.aircraftList = $scope.addData; + $scope.aircraftListData.accountId = $scope.aircraft.accountId; + /*if ($scope.aircraftListData.aircraftList[0].tail == "" || $scope.aircraftListData.aircraftList[0].make == null || $scope.aircraftListData.aircraftList[0].model == null) { + $scope.aircraftListData.aircraftList = []; + }*/ + + CustomersService.addAircraft($scope.aircraftListData).then(function(result) { + + if (result != null && result.success) { + + toastr.success('' + result.success + '', { + closeButton : true + }) + $('#demo-modal-3').css('display', 'none'); + $('.modal-backdrop').css('display', 'none'); + getAllCompanies(); + location.reload(); + } else { + toastr.error('' + result.statusText + '', { + closeButton : true + }) + } + }); } - }); - }) } /*add a fuel order*/ $scope.getOrders = function() { fuelOrdersService.getOrders().then(function(result) { - console.log("==get orders===",result) + //console.log("==get orders===",result) $scope.orderdata = result; for (var i = 0; i < $scope.orderdata.length; i++) { $scope.orderdata[i].upliftDateS = new Date($scope.orderdata[i].upliftDate); @@ -445,7 +526,7 @@ function customersController($scope, $rootScope, $uibModal, $filter, $http, $sta if ($scope.selectedCompanyId != '') { fuelOrdersService.getAircraft($scope.selectedCompanyId).then(function(aircraft) { $scope.aircraftList = aircraft; - console.log("===tail search====",aircraft); + //console.log("===tail search====",aircraft); }) } if ($scope.marginId != '') { @@ -506,10 +587,9 @@ function customersController($scope, $rootScope, $uibModal, $filter, $http, $sta }) } - $scope.checkJetWithTail = function(tail, index) { - //console.log("tail==============",tail, index) + // old api not use + /*$scope.checkJetWithTail = function(tail, index) { ViewCompanyService.checkJetType(tail).then(function(result) { - //console.log("result",result) if (result.jetA == "true") { $scope.jetShow[index] = false; $scope.marginShow[index] = true; @@ -518,7 +598,7 @@ function customersController($scope, $rootScope, $uibModal, $filter, $http, $sta $scope.marginShow[index] = false; } }) - } + }*/ $scope.etaTimeList = [{time:"12:00 AM"},{time:"12:30 AM"},{time:"01:00 AM"},{time:"01:30 AM"},{time:"02:00 AM"},{time:"02:30 AM"},{time:"03:00 AM"},{time:"03:30 AM"}, diff --git a/app/partials/customers/customers.html b/app/partials/customers/customers.html index ee4d989..b846326 100644 --- a/app/partials/customers/customers.html +++ b/app/partials/customers/customers.html @@ -368,50 +368,10 @@
+ {{aircraftMessage}} + |
+
+ {{aircraftMessage}} + |
+