Blame view

app/partials/FuelVendors/FuelVendors.controller.js 4.36 KB
4bb02bb84   Rishav   new integration w...
1
2
3
4
  'use strict';
  
   //Load controller
    angular.module('acufuel')
1926e07b6   Anchal Midha   implement fuel ve...
5
6
7
  	.controller('FuelVendorsController', ['$scope', '$rootScope', '$uibModal', '$filter', '$http', 'FuelVendorsService', 'CustomersService', FuelVendorsController]);
  
  	function FuelVendorsController($scope, $rootScope, $uibModal, $filter, $http, FuelVendorsService, CustomersService) {
4bb02bb84   Rishav   new integration w...
8

1926e07b6   Anchal Midha   implement fuel ve...
9
10
11
12
13
14
15
  		$(document).ready(function() {
  		    $('#example').DataTable();
  		});
  		$scope.data = {};
  		$scope.aircraft = {};
  		$scope.data.activate = true;
  		
cd330b5ee   Rishav   fuel vendor and v...
16
17
18
19
20
21
22
23
24
  		getAllVendor();
  
  		function getAllVendor(){
  			FuelVendorsService.getAllVendor().then(function(result) {
  				console.log(result)
  				$scope.vendorList = result;
  			})
  		}
  		
1926e07b6   Anchal Midha   implement fuel ve...
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
  
          $(function() {
  	     	$('#vendor-toggle-one2').bootstrapToggle();
  	     	$('#vendor-toggle-one2').change(function() {
  		      $('#console-event').html('Toggle: ' + $(this).prop('checked'));
  		      $scope.data.activate = $(this).prop('checked');
  		    })
          })
  
          getData();
      	function getData(){
  			CustomersService.getAircraftMake().then(function(result) {
  			  $scope.aircraftMakeList = result;
  			})
  		}
        
  	    $scope.addFirstData = function(sel, step){
  	    	// console.log($scope.data)
  
  	    	var vendorData = "vendorName=" + $scope.data.vendorName + "&masterMargin=" + $scope.data.masterMargin 
  	    	+ "&addressOne=" + $scope.data.addressOne + "&addressTwo=" + $scope.data.addressTwo + "&city=" + $scope.data.city + "&state=" 
  	    	+ $scope.data.state + "&country=" + $scope.data.country + "&zipcode=" + $scope.data.zipcode + "&internalNote=" 
  	    	+ $scope.data.internalNote + "&certificateType=" + $scope.data.certificateType + "&baseTenant=" + $scope.data.baseTenant
  	    	+ "&fuelerlinxCustomer=" + $scope.data.fuelerlinxCustomer + "&contractFuelVendor=" + $scope.data.contractFuelVendor 
  	    	+ "&activate=" + $scope.data.activate + "&baseIcao=" + $scope.data.baseIcao;
  
  	    	FuelVendorsService.addVendor(vendorData).then(function(result) {
              	console.log("result",result)
cd330b5ee   Rishav   fuel vendor and v...
53
54
              	$scope.accountId = result;
        			$scope.aircraft.accountId = $scope.accountId;
1926e07b6   Anchal Midha   implement fuel ve...
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
            	})
      	 	$(sel).trigger('next.m.' + step);
      	 	getData();
  	    }
  
  	    $scope.aircraftDetails = [{ 
              'tail':'',
              'make': '',
              'model': '',
              'sizeId' : ''
          }];
      
          $scope.addNew = function(){
              $scope.aircraftDetails.push({ 
                  'tail':'',
  	            'make': '',
  	            'model': '',
  	            'sizeId' : ''
              });
              console.log($scope.aircraftDetails)
          };
  
          $scope.getModal = function(makeId, index){
  	  		$scope.aircraft.make = makeId;
  	        //var makeId = makeId;
  	        CustomersService.getModal($scope.aircraft.make).then(function(result) {
  	          $scope.aircraftDetails[index].aircraftModalList = result;
  	          //$scope.aircraftDetails[index].model = $scope.aircraftModalList[0];
  	        })
        	}
  
        	$scope.getSize = function(model, index){
  	        CustomersService.getAircraftSize($scope.aircraft.make, model).then(function(result) {
  	        	console.log("result",result)
  	          $scope.aircraftDetails[index].aircraftSizeList = result;
  	          //$scope.aircraftDetails[index].size = $scope.aircraftSizeList[0];
  	          console.log($scope.aircraftDetails[index].size)
  	        })
        	}
  
        	$scope.aircraftListData = {};
        	$scope.addData = [];
        	$scope.saveVendorData = function(){
        		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
  	            });
        		}
  	        $scope.aircraftListData.aircraftList = $scope.addData;
cd330b5ee   Rishav   fuel vendor and v...
107
  	        $scope.aircraftListData.accountId = $scope.aircraft.accountId;
1926e07b6   Anchal Midha   implement fuel ve...
108
  	        
cd330b5ee   Rishav   fuel vendor and v...
109
  	        FuelVendorsService.addVendorAicraft($scope.aircraftListData).then(function(result) {
1926e07b6   Anchal Midha   implement fuel ve...
110
  	        	console.log(result)
cd330b5ee   Rishav   fuel vendor and v...
111

1926e07b6   Anchal Midha   implement fuel ve...
112
113
114
115
  	        	if(result != null && result.success){
  	        		toastr.success(''+result.success+'', {
  		            	closeButton: true
  		          	})
cd330b5ee   Rishav   fuel vendor and v...
116
117
  		          	$('#vendor-modal-3').modal('hide');
  		          	getAllVendor();
1926e07b6   Anchal Midha   implement fuel ve...
118
119
120
121
122
123
124
125
  	        	}else{
  	        		toastr.error(''+result.statusText+'', {
  		            	closeButton: true
  		          	})
  	        	}
  	        });
        	}
      }