'use strict'; //Load controller angular.module('acufuel') .controller('customersController', [ '$scope', '$rootScope', '$uibModal', '$filter', '$http', '$state', 'CustomersService', 'ViewCompanyService', 'NgTableParams', 'fuelOrdersService', 'enterFuelOrderService', customersController ]); function customersController($scope, $rootScope, $uibModal, $filter, $http, $state, CustomersService, ViewCompanyService, NgTableParams, fuelOrdersService, enterFuelOrderService) { $(document).ready(function() { // $('#example').DataTable(); }); $scope.userProfileId = JSON.parse(localStorage.getItem('userProfileId')) $scope.reset2 = function() { $("input").val(""); $scope.removeMarginValidation(); } $scope.order = {}; $scope.order.upliftDate = ''; $scope.data = {}; $scope.aircraft = {}; $scope.data.activate = true; $scope.showLoader = true; $scope.jetShow = []; $scope.marginShow = []; $scope.jetShow[0] = true; $scope.marginShow[0] = true; $scope.dispatchOrder = {}; $scope.dispatchOrder.fuelOrderList = []; $scope.statusFilterOptions = []; $scope.companyList = {}; $scope.statusFilterOptions.push({ 'id' : '', 'title' : 'Show All' }, { 'id' : 'pending', 'title' : 'Pending' }, { 'id' : 'invoiced', 'title' : 'Invoiced' }, { 'id' : 'paid', 'title' : 'Paid' }, { 'id' : 'cancelled', 'title' : 'Cancelled' }, { 'id' : 'archived', 'title' : 'Archived' } ); /*function getAllCompanies(){ 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; } }) }*/ $scope.statusFilter = [ { id : "", title : "Show All" }, { id : "true", title : "Active" }, { id : "false", title : "Inactive" } ] function getAllCompanies() { CustomersService.getAllCompanies().then(function(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 }); $scope.showLoader = false; }) } getAllCompanies(); $scope.editMargin = function(customer) { //console.log('customer', customer); $scope.showLoader = true; event.stopPropagation(); 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.updateCompany(companyMargin).then(function(result) { if (result != null && result.success) { $scope.showLoader = false; toastr.success('' + result.success + '', { closeButton : true }) getAllCompanies(); } else { $scope.showLoader = false; toastr.error('' + result.statusText + '', { closeButton : true }) } }) } getData(); function getData() { $scope.showLoader = true; CustomersService.getAircraftMake().then(function(result) { //console.log("==aircrafts===",result) $scope.aircraftMakeList = result; $scope.showLoader = false; }) } // CustomersService.getMargin().then(function(result) { // $scope.marginList = result; // }) $scope.marginFilterOptions = []; CustomersService.getJetMargin($scope.userProfileId).then(function(result) { $scope.showLoader = true; $scope.jetMarginList = result; //console.log("jet margin",result,$scope.userProfileId) $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 }) } $scope.showLoader = false; }) CustomersService.getAvgMargin($scope.userProfileId).then(function(result) { $scope.avgsMarginList = result; // console.log('avgsMarginList',result) }) $scope.showCompanyError = false; $scope.showMarginError = false; $scope.removeValidation = function() { $scope.showCompanyError = false; $('.companyNameInput').removeClass('customErrorInput'); if ($scope.data.companyName == 'undefined' || $scope.data.companyName == '') { $('.companyNameInput').addClass('customErrorInput'); $scope.showCompanyError = true; } } $scope.removeMarginValidation = function() { $scope.showMarginError = false; $('.marginSelectBox').removeClass('customErrorInput'); } var companyData; $scope.addFirstData = function(sel, step) { $scope.showLoader = true; if ($scope.data.companyName == undefined) { $scope.showCompanyError = true; $('.companyNameInput').addClass('customErrorInput'); } else if ($scope.data.masterMargin == undefined) { $scope.showMarginError = true; $('.marginSelectBox').addClass('customErrorInput'); } else { $scope.aircraftDetails = [ { 'tail' : '', 'make' : '', 'model' : '', 'sizeId' : '', 'marginId' : $scope.data.masterMargin, 'avgasMarginId' : $scope.data.avgasMargin } ]; $(sel).trigger('next.m.' + step); getData(); } $scope.showLoader = false; } $scope.addNew = function() { $scope.showLoader = true; $scope.aircraftDetails.push({ 'tail' : '', 'make' : '', 'model' : '', 'sizeId' : '', 'marginId' : $scope.data.masterMargin, 'avgasMarginId' : $scope.data.avgasMargin }); $scope.showLoader = false; }; $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; CustomersService.getModal($scope.aircraft.make).then(function(result) { $scope.showLoader = false; $scope.aircraftDetails[index].aircraftModalList = result; }) }*/ $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.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) CustomersService.addCompany($scope.data).then(function(result) { $scope.tailArray = []; $scope.addData =[]; $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.tailArray.push($scope.aircraftDetails[i].tail); } 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) $scope.orderdata = result; for (var i = 0; i < $scope.orderdata.length; i++) { $scope.orderdata[i].upliftDateS = new Date($scope.orderdata[i].upliftDate); // var str = "" + $scope.orderdata[i].upliftDateS.getDate() + "/" + ($scope.orderdata[i].upliftDateS.getMonth() + 1) + "/" + $scope.orderdata[i].upliftDateS.getFullYear() var str = "" + ($scope.orderdata[i].upliftDateS.getMonth() + 1) + "/" + $scope.orderdata[i].upliftDateS.getDate() + "/" + $scope.orderdata[i].upliftDateS.getFullYear() // str = str.slice(4,16) $scope.orderdata[i].upliftDateString = str // console.log(str); } $scope.displayFuelOrderList = new NgTableParams({ page : 1, count : 10, }, { data : $scope.orderdata }); $(document).ready(function() { var myselect = document.getElementsByClassName('colorfulSelectbox'); for (var i = 0; i < myselect.length; i++) { var colourIndex = $(myselect[i]).prop('selectedIndex'); colourIndex = colourIndex + 1; // console.log(colourIndex); var getColor = $('.colorfulSelectbox option:nth-child(' + colourIndex + ')').css('color'); $(myselect[i]).css('background-color', getColor); // console.log('colour', getColor); myselect[i].blur(); } }) }) } $scope.getOrders(); $scope.tiervalue=function(){ $scope.order.tierBreak=$scope.selectedTier.minTierBreak+'-'+$scope.selectedTier.maxTierBreak; } $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.fuelData = {}; $scope.fuelData.companyId = $scope.selectedCompanyId; $scope.fuelData.companyName =$scope.order.defaultCompanyName; var aircraftObj =JSON.parse($scope.order.aircraftName); $scope.fuelData.aircraftName = aircraftObj.tail; $scope.fuelData.make = aircraftObj.make; $scope.fuelData.model = aircraftObj.model; $scope.fuelData.fuelOn = $scope.order.fuelOn; $scope.fuelData.invoiced = $scope.order.invoiced; $scope.fuelData.volume = $scope.order.volume; $scope.fuelData.source = $scope.order.source; $scope.fuelData.total = $scope.order.total; //tier no use $scope.fuelData.tierBreak = $scope.order.tierBreak; var obj =JSON.parse($scope.order.priceQuote); $scope.fuelData.priceQuote = obj.papTotal; $scope.fuelData.fboCost = obj.cost; $scope.fuelData.productName = obj.productName; $scope.fuelData.etaTime = $scope.order.etaTime; $scope.fuelData.etdTime = $scope.order.etdTime; $scope.fuelData.certificateType = $scope.order.certificateType; var currentDate = new Date(); var hours = currentDate.getHours(); var min = currentDate.getMinutes(); var sec = currentDate.getSeconds(); if ($scope.order.upliftDate != '') { $scope.order.upliftDate = $scope.order.upliftDate + ' ' + hours + ':' + min + ':' + sec; $scope.order.upliftDate = new Date($scope.order.upliftDate); $scope.fuelData.upliftDate = $scope.order.upliftDate.getTime(); } if ($scope.order.departingDate != '') { $scope.order.departingDate = $scope.order.departingDate + ' ' + hours + ':' + min + ':' + sec; $scope.order.departingDate = new Date($scope.order.departingDate); $scope.fuelData.departingDate = $scope.order.departingDate.getTime(); } if($scope.order.status === null || $scope.order.status === undefined){ $scope.fuelData.status = "pending"; //default status }else { $scope.fuelData.status = $scope.order.status; } $scope.dispatchOrder.fuelOrderList.push($scope.fuelData); // console.log("=====$scope.fueldata======",$scope.fuelData) fuelOrdersService.dispathFuelOrder($scope.dispatchOrder).then(function(result) { $scope.showLoader = false; $scope.order = {}; $scope.dispatchOrder.fuelOrderList = []; $('#demo-modal-4').css('display', ''); $scope.getOrders(); toastr.success('Fuel Order Dispatched Successfully', { closeButton: true }) }) } $scope.addTotal = function(value, valueOf) { if (value != undefined && valueOf != undefined) { value = JSON.parse(value) $scope.order.total = value.cost * valueOf; } } $scope.getAircraft = function(company) { $scope.selectedCompanyName = company; //$scope.showLoader = true; // console.log("id",company) for (var i = 0; i < $scope.companyList.length; i++) { if ($scope.companyList[i].companyName == company) { if ($scope.companyList[i].margin != null && $scope.companyList[i].marginAVGAS != null) { fuelOrdersService.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) { fuelOrdersService.getATypeFuelPricing($scope.companyList[i].id).then(function(margins) { $scope.marginList = margins; }) } else if ($scope.companyList[i].margin == null || $scope.companyList[i].marginAVGAS != null) { fuelOrdersService.getVTypeFuelPricing($scope.companyList[i].id).then(function(margins) { $scope.marginList = margins; }) } $scope.selectedCompanyId = $scope.companyList[i].id; $scope.marginId = $scope.companyList[i].margin.id; if ($scope.selectedCompanyId != '') { fuelOrdersService.getAircraft($scope.selectedCompanyId).then(function(aircraft) { $scope.aircraftList = aircraft; //console.log("===tail search====",aircraft); }) } if ($scope.marginId != '') { fuelOrdersService.getJetTiers($scope.marginId).then(function(tiers) { $scope.tierList = tiers; // $scope.showLoader = false; }) } else { // $scope.showLoader = false; } } } } $scope.sourceList = [ { source : "Direct Jet-A" }, { source : "Direct AVGAS 100LL" } ]; $scope.cancelData = function() { $scope.order = {}; $('#demo-modal-4').css('display', ''); } $scope.setFuel = function(companyName,certificateType) { $('#demo-modal-4').css('display', 'block'); $scope.order.defaultCompanyName = companyName; $scope.order.certificateType = certificateType; $scope.getAircraft(companyName); // event.stopPropagation(); // $state.go('app.updateFuelManager'); } /* ng table */ $scope.exportCompany = function() { $scope.showLoader = true; var fileName = "companies.csv"; var a = document.createElement("a"); document.body.appendChild(a); CustomersService.exportCompany().then(function(result) { var file = new Blob([ result ], { type : 'application/csv' }); var fileURL = URL.createObjectURL(file); a.href = fileURL; a.download = fileName; a.click(); $scope.showLoader = false; }) } getCompanyName(); function getCompanyName() { CustomersService.getCompanyName().then(function(result) { $scope.compNameList = result; //console.log("kd",result) }) } // old api not use /*$scope.checkJetWithTail = function(tail, index) { ViewCompanyService.checkJetType(tail).then(function(result) { if (result.jetA == "true") { $scope.jetShow[index] = false; $scope.marginShow[index] = true; } else { $scope.jetShow[index] = true; $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"}, {time:"04:00 AM"},{time:"04:30 AM"},{time:"05:00 AM"},{time:"05:30 AM"},{time:"06:00 AM"},{time:"06:30 AM"},{time:"07:00 AM"},{time:"07:30 AM"}, {time:"08:00 AM"},{time:"08:30 AM"},{time:"09:00 AM"},{time:"09:30 AM"},{time:"10:00 AM"},{time:"10:30 AM"},{time:"11:00 AM"},{time:"11:30 AM"}, {time:"12:00 PM"},{time:"12:30 PM"},{time:"01:00 PM"},{time:"01:30 PM"},{time:"02:00 PM"},{time:"02:30 PM"},{time:"03:00 PM"},{time:"03:30 PM"}, {time:"04:00 PM"},{time:"04:30 PM"},{time:"05:00 PM"},{time:"05:30 PM"},{time:"06:00 PM"},{time:"06:30 PM"},{time:"07:00 PM"},{time:"07:30 PM"}, {time:"08:00 PM"},{time:"08:30 PM"},{time:"9:00 PM"},{time:"09:30 PM"},{time:"10:00 PM"},{time:"10:30 PM"},{time:"11:00 PM"},{time:"11:30 PM"},]; $scope.etdTimeList = [{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"}, {time:"04:00 AM"},{time:"04:30 AM"},{time:"05:00 AM"},{time:"05:30 AM"},{time:"06:00 AM"},{time:"06:30 AM"},{time:"07:00 AM"},{time:"07:30 AM"}, {time:"08:00 AM"},{time:"08:30 AM"},{time:"09:00 AM"},{time:"09:30 AM"},{time:"10:00 AM"},{time:"10:30 AM"},{time:"11:00 AM"},{time:"11:30 AM"}, {time:"12:00 PM"},{time:"12:30 PM"},{time:"01:00 PM"},{time:"01:30 PM"},{time:"02:00 PM"},{time:"02:30 PM"},{time:"03:00 PM"},{time:"03:30 PM"}, {time:"04:00 PM"},{time:"04:30 PM"},{time:"05:00 PM"},{time:"05:30 PM"},{time:"06:00 PM"},{time:"06:30 PM"},{time:"07:00 PM"},{time:"07:30 PM"}, {time:"08:00 PM"},{time:"08:30 PM"},{time:"9:00 PM"},{time:"09:30 PM"},{time:"10:00 PM"},{time:"10:30 PM"},{time:"11:00 PM"},{time:"11:30 PM"},]; }