'use strict'; //Load controller angular.module('acufuel') .controller('viewCompanyController', ['$scope', '$uibModal', '$stateParams', 'ViewCompanyService', 'CustomersService', 'updateFuelManagerService', 'ViewFuelVendorService', 'ViewcontactService', '$state', 'fuelOrdersService', 'enterFuelOrderService', 'NgTableParams', function($scope, $uibModal, $stateParams, ViewCompanyService, CustomersService, updateFuelManagerService, ViewFuelVendorService, ViewcontactService, $state, fuelOrdersService, enterFuelOrderService, NgTableParams) { $scope.data = {}; $scope.data.priceEmail = true; $scope.aircraft = {}; $scope.primayData = {}; $scope.showLoader = false; $scope.showUpdateBtn = false; $scope.userProfileId = JSON.parse(localStorage.getItem('userProfileId')); $scope.selected = []; $scope.jetShow = []; $scope.marginShow = []; $scope.compId = $stateParams.id; $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' } ); $scope.order = {}; $scope.order.companyName = ''; $scope.order.upliftDate = ''; /*Get AllCompany api is used from CustomersService*/ getAllCompanies(); function getAllCompanies() { CustomersService.getAllCompanies().then(function(result) { //console.log('log', result[2].id); $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; }) } $(document).ready(function() { $("#reset").click(function() { $("input").val(""); }); }); $scope.values = [{ 'id': 1, 'first': 'Tenant/Base Customer' }, { 'id': 2, 'first': 'FuelerLinx Customer' }, { 'id': 3, 'first': 'CAA Member' } ]; $scope.changeValue = function(selected) { $scope.showUpdateBtn = true; // console.log("data to be true", selected); for (var i = 0; i < selected.length; i++) { // console.log(selected[i]) if (selected[i] == 'Tenant/Base Customer') { $scope.companyData.baseTenant = true; } else { $scope.companyData.baseTenant = false; } if (selected[i] == 'FuelerLinx Customer') { $scope.companyData.fuelerlinxCustomer = true; } else { $scope.companyData.fuelerlinxCustomer = false; } if (selected[i] == 'CAA Member') { $scope.companyData.contractFuelVendor = true; } else { $scope.companyData.contractFuelVendor = false; } // console.log($scope.companyData) } } // $scope.selected =[ // {'id': 1, 'first': 'Tenant/Base Customer'}, // {'id': 2, 'first': 'FuelerLinx Customer'}, // {'id': 3, 'first': 'CAA Member'} // ]; // CustomersService.getMargin().then(function(result) { // $scope.marginList = result; // }) var value = ""; var companyId = $stateParams.id; $scope.companyData = {}; $scope.multipleMsg = false; $scope.companyData.masterMargin = ""; $scope.isGlobal = false; $scope.fboPreffered = false; getCompanyDetail(); function getCompanyDetail() { $scope.showLoader = true; ViewCompanyService.getCompany(companyId).then(function(result) { $scope.companyData = result; $scope.isGlobal = result.global; $scope.fboPreffered = result.fboPreferred; if (result.global == true) { $scope.companyData.global = true; } if (result.margin != null) { $scope.companyData.masterMargin = result.margin.id; } if (result.marginAVGAS != null) { $scope.companyData.avgasMargin = result.marginAVGAS.id; } if ($scope.companyData.baseTenant) { $scope.selected.push({ 'first': 'Tenant/Base Customer' }) // console.log("$scope.selected",$scope.selected) } if ($scope.companyData.fuelerlinxCustomer) { $scope.selected.push({ 'first': 'FuelerLinx Customer' }) // console.log("$scope.selected",$scope.selected) } if ($scope.companyData.contractFuelVendor) { $scope.selected.push({ 'first': 'CAA Member' }) // console.log("$scope.selected",$scope.selected) } // console.log("$scope.companyData",$scope.companyData) getAircraftList(); $scope.order.companyName = $scope.companyData.companyName; $scope.getAircraft(result.companyName); $scope.showLoader = false; }) } $scope.changeCompanyStatus = function() { $('#delete3').css('display', 'block'); if ($scope.companyData.activate == true) { $scope.statusMessage = 'Please confirm! Are you sure you want to ACTIVATE this company?' } else { $scope.statusMessage = 'Please confirm! Are you sure you want to DEACTIVATE this company?' } } $scope.companyStatus = function() { $scope.showLoader = true; var statusData = "status=" + $scope.companyData.activate; ViewCompanyService.changeStatus(companyId, statusData).then(function(result) { if (result.success) { $('#delete3').css('display', 'none'); toastr.success('' + result.success + '', { closeButton: true }) getContactList(); } }) $scope.showLoader = false; } $scope.cancelStatus = function() { $('#delete3').css('display', 'none'); $scope.companyData.activate = !$scope.companyData.activate; } getContactList(); function getContactList() { ViewCompanyService.getContact(companyId).then(function(result) { $scope.companyContactList = result; }) } $scope.aircraftmargins = []; $scope.abc = false; $scope.xyz = false; function getAircraftList() { ViewCompanyService.getAircraft(companyId).then(function(result) { $scope.contactAircraftList = result; for (var i = 0; i < $scope.contactAircraftList.length; i++) { if ($scope.contactAircraftList[i].aircraftsMargin != null) { $scope.aircraftmargins.push({ 'id': $scope.contactAircraftList[i].aircraftsMargin.id }) $scope.contactAircraftList[i].fuelType = "Jet-A"; $scope.contactAircraftList[i].marginValue = result[i].aircraftsMargin.marginValue; $scope.abc = true; }else{ $scope.contactAircraftList[i].fuelType = "100LL"; $scope.contactAircraftList[i].marginValue = result[i].aircraftsAVGASMargin.marginValue; $scope.xyz = true; } } if ($scope.aircraftmargins.length > 0) { for (var i = 0; i < $scope.aircraftmargins.length; i++) { if ($scope.aircraftmargins[i].id != $scope.companyData.masterMargin) { $scope.multiple = true; $scope.multipleMsg = true; if ($scope.multiple) { $scope.companyData.masterMargin = "multiple"; } } } } }) } $scope.contactData = {}; $scope.contactData.contactList = []; $scope.addContact = function() { $scope.showLoader = true; $scope.data.companyId = companyId; $scope.contactData.contactList.push($scope.data); ViewCompanyService.addContact($scope.contactData).then(function(result) { //console.log("data==",$scope.contactData) // console.log(result) if (result.status == 200) { $('#contact-modal-3').modal('hide'); $scope.primayData.id = result.data; $scope.data = {}; $scope.sendPrimaryContact(); getContactList(); $scope.contactData.contactList = []; $scope.data.email = ''; toastr.success('Created Successfully', { closeButton: true }) } else { toastr.error('' + result.statusText + '', { closeButton: true }) } }) $scope.showLoader = false; } getData(); function getData() { $scope.showLoader = true; CustomersService.getAircraftMake().then(function(result) { $scope.aircraftMakeList = result; // console.log("make",result) }) $scope.showLoader = false; } $scope.clearAircrafts = function() { $scope.aircraftDetails = []; $scope.aircraftDetails = [{ 'tail': '', 'make': '', 'model': '', 'sizeId': '', 'marginId': '', 'avgasMarginId': '' }]; } $scope.addNew = function() { $scope.aircraftDetails.push({ 'tail': '', 'make': '', 'model': '', 'sizeId': '', 'marginId': '', 'avgasMarginId': '' }); // console.log($scope.aircraftDetails) }; $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.aircraftDetails[index].model = $scope.aircraftModalList[0]; }) } $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.getFuelType($scope.aircraftDetails[index].aircraftSizeList[0].aircraftSize.id,index); }) } $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() { $scope.tailArray = []; 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 = companyId; CustomersService.addAircraft($scope.aircraftListData).then(function(result) { if (result != null && result.success) { toastr.success('' + result.success + '', { closeButton: true }) $scope.addData= []; $scope.tailArray = []; $scope.aircraftListData={}; $('#aircraft-modal-3').css('display', 'none'); $('.modal-backdrop').css('display', 'none'); getAircraftList(); } else { toastr.error('' + result.statusText + '', { closeButton: true }) } }); } } $scope.showNoteData = true; $scope.showCompanyName = true; $scope.showAddress = true; $scope.showNote = function() { $scope.showNoteData = false; $scope.showUpdateBtn = true; } $scope.company = function() { $scope.showCompanyName = false; $scope.showUpdateBtn = true; } $scope.base = function() { $scope.showUpdateBtn = true; } $scope.addressChange = function() { $scope.showAddress = false; $scope.showUpdateBtn = true; } $scope.editData = function(inputName) { //console.log($scope.companyData) $scope.showLoader = true; /*if(inputName == 'showNoteData'){ $scope.showNoteData = true; }else if(inputName == 'showCompanyName'){ $scope.showCompanyName = true; }else if(inputName == 'showAddress'){ $scope.showAddress = true; }*/ $scope.showNoteData = true; $scope.showCompanyName = true; $scope.showAddress = true; var companyData = "companyName=" + $scope.companyData.companyName + "&masterMargin=" + $scope.companyData.masterMargin + "&avgasMargin=" + $scope.companyData.avgasMargin + "&addressOne=" + $scope.companyData.addressOne + "&addressTwo=" + $scope.companyData.addressTwo + "&city=" + $scope.companyData.city + "&state=" + $scope.companyData.state + "&country=" + $scope.companyData.country + "&zipcode=" + $scope.companyData.zipcode + "&internalNote=" + $scope.companyData.internalNote + "&certificateType=" + $scope.companyData.certificateType + "&baseTenant=" + $scope.companyData.baseTenant + "&fuelerlinxCustomer=" + $scope.companyData.fuelerlinxCustomer + "&contractFuelVendor=" + $scope.companyData.contractFuelVendor + "&activate=" + $scope.companyData.activate + "&baseIcao=" + $scope.companyData.baseIcao + "&companyId=" + companyId + "&global=" + $scope.companyData.global; ViewCompanyService.updateCompany(companyData).then(function(result) { if (result != null && result.success) { toastr.success('' + result.success + '', { closeButton: true }) $scope.showUpdateBtn = false; getCompanyDetail(); } else { toastr.error('Error Updating Company', { closeButton: true }) $scope.showUpdateBtn = true; } $scope.showLoader = false; }) } $scope.cancelUpdateData = function() { $scope.showNoteData = true; $scope.showCompanyName = true; $scope.showAddress = true; $scope.showUpdateBtn = false; } $scope.sendMail = function() { $scope.showLoader = true; $('#confirm1').css('display', 'none'); ViewCompanyService.sendMail(companyId).then(function(result) { if (result != null && result.success) { toastr.success('' + result.success + '', { closeButton: true }) } else { toastr.error('Error Sending Email', { closeButton: true }) } $scope.showLoader = false; }) } $scope.openConfirmMail = function() { $('#confirm1').css('display', 'block'); } $scope.cancelAndCloseConfirm = function() { $('#confirm1').css('display', 'none'); } $scope.primaryContact = false; $scope.cancelPrimaryContact = function() { $('#primaryContact').css('display', 'none'); $scope.primaryContact = false; } $scope.checkPrimaryContact = function() { if ($scope.primaryContact == true) { $scope.primaryContact = true; ViewCompanyService.checkPrimaryContact(companyId).then(function(result) { //console.log(result) if (result.status == 422) { $('#primaryContact').css('display', 'block'); } }) } } $scope.sendPrimaryContact = function() { $('#primaryContact').css('display', 'none'); if ($scope.primayData.id != null || $scope.primayData.id != undefined) { var priamryContactData = "companyContactId=" + $scope.primayData.id + "&primary=" + $scope.primaryContact; ViewCompanyService.addPrimaryContact(priamryContactData).then(function(result) { // console.log(result) }) } } $scope.updateData = "" $scope.showUpdateContact = function(data, value) { $('#updateContact').css('display', 'block'); $scope.updateData = data; // console.log($scope.updateData) if ($scope.updateData.email == null) { $scope.updateData.content = data.contactNumber; } else { $scope.updateData.content = data.email; } } $scope.showUpdateEmail = function(data, value) { $('#updateEmail').css('display', 'block'); $scope.updateData = data; // console.log($scope.updateData) if ($scope.updateData.email == null) { $scope.updateData.content = data.contactNumber; } else { $scope.updateData.content = data.email; } } $scope.acceptUpdateField = function(newContactName) { // console.log($scope.updateData) if ($scope.updateData.content == undefined) { toastr.error('Please add some content', { closeButton: true }) } else { if (newContactName == 'phone') { var updateCustomData = "companyId=" + companyId + "&contactNumber=" + $scope.updateData.content + "&contactId=" + $scope.updateData.id + "&title=" + $scope.updateData.title; } else { var updateCustomData = "companyId=" + companyId + "&email=" + $scope.updateData.content + "&contactId=" + $scope.updateData.id + "&title=" + $scope.updateData.title; } ViewCompanyService.updateCustomField(updateCustomData).then(function(result) { if (result != null && result.success) { $('#updateContact').css('display', 'none'); $('#updateEmail').css('display', 'none'); getCompanyDetail(); } }) } } $scope.deleteContent = function(data){ ViewCompanyService.deleteCustomContact(data.id).then(function(result) { if (result != null && result.success) { toastr.success('' + result.success + '', { closeButton: true }) getCompanyDetail(); } }) } $scope.cancelUpdateField = function() { $('#updateContact').css('display', 'none'); $('#updateEmail').css('display', 'none'); } $scope.showEditTier2 = function(number) { // console.log(number) $scope.contactNumber = number; } $scope.addCustomPhone = function(value) { //console.log(value) if (value != null) { $('#customFieldPhone').css('display', 'block'); } $scope.custom = {}; } $scope.addCustomEmail = function(value) { //console.log(value) if (value != null) { $('#customFieldEmail').css('display', 'block'); } $scope.custom = {}; } $scope.cancelCustomField = function() { $('#customFieldEmail').css('display', 'none'); $('#customFieldPhone').css('display', 'none'); } $scope.acceptCustomField = function(contactName) { if ($scope.custom.content == undefined) { toastr.error('Please add some content', { closeButton: true }) } else { if (contactName == 'phone') { var customData = "companyId=" + companyId + "&contactNumber=" + $scope.custom.content + "&title=" + $scope.custom.title; } else { var customData = "companyId=" + companyId + "&email=" + $scope.custom.content + "&title=" + $scope.custom.title; } // console.log(customData.email) ViewCompanyService.addCustomField(customData).then(function(result) { // console.log(result) if (result != null && result.success) { $('#customFieldEmail').css('display', 'none'); $('#customFieldPhone').css('display', 'none'); $scope.custom = {}; getCompanyDetail(); } }) } } /* omit strike out*/ updateFuelManagerService.getFuelPricingNew().then(function(result) { $scope.fuelPricing = result; $scope.omitData; ViewCompanyService.getOmitCompany($scope.compId).then(function(result){ $scope.omitData = result; //console.log("omit data===", $scope.omitData); for(var i = 0 ; i< $scope.fuelPricing.length; i++){ for(var j = 0; j<$scope.omitData.length; j++){ if($scope.omitData[j].marginId == $scope.fuelPricing[i].fuelPricing.id){ $scope.fuelPricing[i].fuelPricing.omit = $scope.omitData[j].omit; } } } }) // console.log("$scope.fuelPricing",$scope.fuelPricing) for (var i = 0; i < $scope.fuelPricing.length; i++) { // console.log('$scope.fuelPricing[i].fuelPricing', $scope.fuelPricing[i].fuelPricing); //console.log("fuelid",$scope.fuelPricing[i].fuelPricing.id,"getid",$scope.omitData[j].id) if ($scope.fuelPricing[i].fuelPricing.expirationDate != null) { $scope.fuelPricing[i].fuelPricing.expirationDate = new Date($scope.fuelPricing[i].fuelPricing.expirationDate); var newTime = new Date($scope.fuelPricing[i].fuelPricing.expirationDate); var dmonth = newTime.getUTCMonth() + 1; //months from 1-12 var dday = newTime.getUTCDate(); var dyear = newTime.getUTCFullYear(); $scope.fuelPricing[i].fuelPricing.expirationDate = dmonth + '/' + dday + '/' + dyear; } // for (var j = 0; j<$scope.omitData.length; j++) { // if($scope.fuelPricing[i].fuelPricing.id === $scope.omitData[j].id){ // } // } } }) var deleteAircraftId = ""; $scope.deleteAircraft = function(id) { $('#delete1').css('display', 'block'); deleteAircraftId = id; } $scope.aircraftDelete = function() { ViewCompanyService.deleteAircraft(deleteAircraftId).then(function(result) { // console.log(result) getAircraftList(); getCompanyDetail(); $('#delete1').css('display', 'none'); }) } $scope.cancelAircraft = function() { $('#delete1').css('display', 'none'); } CustomersService.getJetMargin($scope.userProfileId).then(function(result) { $scope.jetMarginList = result; }) CustomersService.getAvgMargin($scope.userProfileId).then(function(result) { $scope.avgsMarginList = result; }) $scope.changePriceEmail = function(id, index) { event.stopPropagation(); var contactId = id; var statusData = "status=" + $scope.companyContactList[index].priceEmail; ViewcontactService.changePriceEmail(contactId, statusData).then(function(result) { if (result.success) { $('#toogleMail').css('display', 'block'); if ($scope.companyContactList[index].priceEmail == true) { $scope.messageText = 'You have enabled price distribution for this contact'; } else { $scope.messageText = 'You have disabled price distribution for this contact'; } } }) } $scope.cancelToogle = function() { $('#toogleMail').css('display', 'none'); } $scope.checkboxStatus = function(value) { // console.log("checkbox",value) $scope.showUpdateBtn = true; } $scope.fuelercheckboxStatus = function(value) { $('#fuelerchange').css('display', 'block'); if (value == true) { $scope.statusMessage = 'Please confirm! Enabling FuelerLinx for this customer will enable price distribution web services and disable price emails for the contacts in this company' } else { $scope.statusMessage = 'Please confirm! Disabling FuelerLinx for this customer will disable price distribution web services into their FuelerLinx account. If you proceed then remember to enable price emails for the appropriate contacts in this company.' } } $scope.fuelerCancelStatus = function() { $('#fuelerchange').css('display', 'none'); $scope.companyData.fuelerlinxCustomer = !$scope.companyData.fuelerlinxCustomer; } $scope.fuelerAcceptStatus = function() { $('#fuelerchange').css('display', 'none'); $scope.showLoader = true; var statusData; if ($scope.companyData.fuelerlinxCustomer == false) { statusData = "status=true"; } else { statusData = "status=false"; } ViewCompanyService.fuelerPricingChange(companyId, statusData).then(function(result) { if (result.success) { $scope.showLoader = false; $scope.editData(); getContactList(); } }) } $scope.updateOmit = function(fuel, omit) { $scope.fuelData = {}; $scope.fuelData.expirationDate = new Date(fuel.expirationDate); $scope.fuelData.customMarginId = fuel.id; $scope.fuelData.omit = fuel.omit; $scope.fuelData.papMargin = fuel.papMargin; $scope.fuelData.papTotal = fuel.papTotal; $scope.fuelData.cost = fuel.cost; $scope.fuelData.companyId = $scope.compId ; if($scope.fuelData.omit == true) { var customData = "companyId=" + $scope.fuelData.companyId + "&customMarginId=" + $scope.fuelData.customMarginId; ViewCompanyService.omitAddCompanyFuel(customData).then(function(result) { if (result.success) { toastr.success('' + result.success + '', { closeButton: true }) } else { toastr.error('' + result.statusText + '', { closeButton: true }) } }) }else{ var data ="companyId=" + $scope.fuelData.companyId + "&customMarginId=" + $scope.fuelData.customMarginId; ViewCompanyService.omitDeleteCompanyFuel(data).then(function(result){ if (result.success) { toastr.success('' + result.success + '', { closeButton: true }) } else { toastr.error('' + result.statusText + '', { closeButton: true }) } }) } } //--fuel type based on tail is not in use-- // $scope.aircraftData = {} /*$scope.checkJetWithTail = function(tail, index) { console.log("tail==============",tail, index) ViewCompanyService.checkJetType(tail).then(function(result) { console.log("result",result) if (result.jetA == "true") { $scope.jetShow[index] = false; $scope.marginShow[index] = true; } else { $scope.jetShow[index] = true; $scope.marginShow[index] = false; } }) }*/ /*add a fuel order*/ $scope.getOrders = function() { fuelOrdersService.getOrders().then(function(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.order.companyId = $scope.compId; if ($scope.order.upliftDate != '') { var currentDate = new Date(); var hours = currentDate.getHours(); var min = currentDate.getMinutes(); var sec = currentDate.getSeconds(); $scope.order.upliftDate = $scope.order.upliftDate + ' ' + hours + ':' + min + ':' + sec; $scope.order.upliftDate = new Date($scope.order.upliftDate); $scope.order.upliftDate = $scope.order.upliftDate.getTime(); } $scope.order.status = 'pending'; var obj =JSON.parse($scope.order.priceQuote); $scope.order.priceQuote = obj.papTotal; $scope.order.fboCost = obj.cost; $scope.order.total = obj.papTotal * $scope.order.volume; 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); enterFuelOrderService.dispathFuelOrder($scope.dispatchOrder).then(function(result) { $scope.showLoader = false; $scope.order = {}; $('#demo-modal-4').css('display', ''); toastr.success('Fuel Order Dispatched Successfully', { closeButton: true }) }) } $scope.addTotal = function(value, valueOf) { if (valueOf == 'v') { $scope.order.total = value * $scope.order.invoiced } else if (valueOf == 'i') { $scope.order.total = $scope.order.volume * value } } $scope.getAircraft = function(company) { $scope.selectedCompanyName = company; if ($scope.companyData.margin != null && $scope.companyData.marginAVGAS != null) { fuelOrdersService.getFuelCost($scope.companyData.id).then(function(margins) { $scope.marginList = margins; //console.log('$scope.marginList', $scope.marginList); }) } else if ($scope.companyData.margin != null || $scope.companyData.marginAVGAS == null) { fuelOrdersService.getATypeFuelPricing($scope.companyData.id).then(function(margins) { $scope.marginList = margins; }) } else if ($scope.companyData.margin == null || $scope.companyData.marginAVGAS != null) { fuelOrdersService.getVTypeFuelPricing($scope.companyData.id).then(function(margins) { $scope.marginList = margins; }) } $scope.selectedCompanyId = $scope.companyData.id; $scope.marginId = $scope.companyData.margin.id; if ($scope.selectedCompanyId != '') { fuelOrdersService.getAircraft($scope.selectedCompanyId).then(function(aircraft) { $scope.aircraftList = aircraft; }) } if ($scope.marginId != '') { fuelOrdersService.getJetTiers($scope.marginId).then(function(tiers) { $scope.tierList = tiers; // $scope.showLoader = false; }) } } $scope.setCost = function(cost) { // console.log(cost); if (cost != null) { var obj = JSON.parse(cost); // console.log("0bj",obj) $scope.order.fboCost = obj.cost; } } $scope.sourceList = [{ source: "Direct Jet-A" }, { source: "Direct AVGAS 100LL" }]; $scope.cancelData = function() { $('#demo-modal-4').css('display', ''); } $scope.setFuel = function() { $('#demo-modal-4').css('display', 'block'); } /*delete company*/ var deletecompanyId = ""; $scope.deleteComp = function(companyDataid) { $('#delete2').css('display', 'block'); //console.log("asda",companyDataid) deletecompanyId = companyDataid; } $scope.aircraftIdx = ''; $scope.checkTail = function(tail, idx){ var data = "tail=" + tail + "&id=" + companyId; $scope.aircraftIdx = idx; ViewCompanyService.checkTail(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.deleteCompanyData = function() { ViewCompanyService.deleteCompany(deletecompanyId).then(function(result) { $('#delete2').css('display', 'none'); if (result.success) { toastr.success('' + result.success + '', { closeButton: true }) } else { toastr.error('' + result.statusText + '', { closeButton: true }) } $state.go('app.customers') }) } $scope.cancelDelete = function() { $('#delete2').css('display', 'none'); } $scope.editJetMargin = function(aircraftData, type) { $scope.showLoader = true; if (type == 'jet') { var aircraftdataMargin = "marginId=" + aircraftData.aircraftsMargin.id + "&type=" + type; } else { var aircraftdataMargin = "marginId=" + aircraftData.aircraftsAVGASMargin.id + "&type=" + type; } var id = aircraftData.id; ViewCompanyService.updateAircraftMargin(aircraftdataMargin, id).then(function(result) { if (result != null && result.success) { $scope.showLoader = false; toastr.success('' + result.success + '', { closeButton: true }) // getAircraftWithMarginList(); getAircraftList(); } else { $scope.showLoader = false; toastr.error('' + result.statusText + '', { closeButton: true }) } }) } /* //not used currently function getAircraftWithMarginList() { ViewCompanyService.getJetAMargin(companyId).then(function(result) { $scope.contactAircraftList = result; for (var i = 0; i < $scope.contactAircraftList.length; i++) { if ($scope.contactAircraftList[i].aircraftsMargin != null) { $scope.aircraftmargins.push({ 'id': $scope.contactAircraftList[i].aircraftsMargin.id }) } } if ($scope.aircraftmargins.length > 0) { for (var i = 0; i < $scope.aircraftmargins.length; i++) { if ($scope.aircraftmargins[i].id != $scope.companyData.masterMargin) { $scope.multiple = true; $scope.multipleMsg = true; if ($scope.multiple) { $scope.companyData.masterMargin = "multiple"; } } } } }) }*/ }]);