Blame view

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

3a9f4472b   Rishav   Implement contact...
7
  	function FuelVendorsController($scope, $rootScope, $uibModal, $filter, $http, FuelVendorsService, CustomersService, ViewFuelVendorService) {
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
  		getAllVendor();
  
  		function getAllVendor(){
  			FuelVendorsService.getAllVendor().then(function(result) {
  				console.log(result)
  				$scope.vendorList = result;
3a9f4472b   Rishav   Implement contact...
22
23
24
  				for(var i=0; i<$scope.vendorList.length; i++){
  					$scope.vendorList[i].masterMargin = $scope.vendorList[i].margin.id;
  				}
cd330b5ee   Rishav   fuel vendor and v...
25
26
27
  			})
  		}
  		
3a9f4472b   Rishav   Implement contact...
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
          $scope.editMargin = function(vendor){
          	console.log(vendor.masterMargin)
  
          	var companyMargin = "vendorName=" + vendor.vendorName + "&masterMargin=" + vendor.masterMargin 
                + "&addressOne=" + vendor.addressOne + "&addressTwo=" + vendor.addressTwo + "&city=" + vendor.city + "&state=" 
                + vendor.state + "&country=" + vendor.country + "&zipcode=" + vendor.zipcode + "&internalNote=" 
                + vendor.internalNote + "&certificateType=" + vendor.certificateType + "&baseTenant=" + vendor.baseTenant
                + "&fuelerlinxvendor=" + vendor.fuelerlinxvendor + "&contractFuelVendor=" + vendor.contractFuelVendor 
                + "&activate=" + vendor.activate + "&baseIcao=" + vendor.baseIcao + "&vendorId=" + vendor.id;
  
          	ViewFuelVendorService.updateContact(companyMargin).then(function(result) {
                if(result != null && result.success){
                  toastr.success(''+result.success+'', {
                    closeButton: true
                  })
                }else{
                  toastr.error(''+result.statusText+'', {
                    closeButton: true
                  })
                }
              })
          }
1926e07b6   Anchal Midha   implement fuel ve...
50
51
52
53
54
55
          getData();
      	function getData(){
  			CustomersService.getAircraftMake().then(function(result) {
  			  $scope.aircraftMakeList = result;
  			})
  		}
3a9f4472b   Rishav   Implement contact...
56
57
58
59
60
  		
  		CustomersService.getMargin().then(function(result) {
  		  $scope.marginList = result;
  		})
  		      
1926e07b6   Anchal Midha   implement fuel ve...
61
62
63
64
65
66
67
68
69
70
71
72
  	    $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...
73
74
              	$scope.accountId = result;
        			$scope.aircraft.accountId = $scope.accountId;
1926e07b6   Anchal Midha   implement fuel ve...
75
76
77
78
79
80
81
82
83
            	})
      	 	$(sel).trigger('next.m.' + step);
      	 	getData();
  	    }
  
  	    $scope.aircraftDetails = [{ 
              'tail':'',
              'make': '',
              'model': '',
3a9f4472b   Rishav   Implement contact...
84
85
              'sizeId' : '',
              'marginId': $scope.data.masterMargin
1926e07b6   Anchal Midha   implement fuel ve...
86
87
88
89
90
91
92
          }];
      
          $scope.addNew = function(){
              $scope.aircraftDetails.push({ 
                  'tail':'',
  	            'make': '',
  	            'model': '',
3a9f4472b   Rishav   Implement contact...
93
94
  	            'sizeId' : '',
  	            'marginId': ''
1926e07b6   Anchal Midha   implement fuel ve...
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
              });
              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,
3a9f4472b   Rishav   Implement contact...
125
126
  		            'sizeId' : $scope.aircraftDetails[i].sizeId,
  		            'marginId': $scope.aircraftDetails[i].marginId
1926e07b6   Anchal Midha   implement fuel ve...
127
128
129
  	            });
        		}
  	        $scope.aircraftListData.aircraftList = $scope.addData;
cd330b5ee   Rishav   fuel vendor and v...
130
  	        $scope.aircraftListData.accountId = $scope.aircraft.accountId;
1926e07b6   Anchal Midha   implement fuel ve...
131
  	        
cd330b5ee   Rishav   fuel vendor and v...
132
  	        FuelVendorsService.addVendorAicraft($scope.aircraftListData).then(function(result) {
1926e07b6   Anchal Midha   implement fuel ve...
133
  	        	console.log(result)
cd330b5ee   Rishav   fuel vendor and v...
134

1926e07b6   Anchal Midha   implement fuel ve...
135
136
137
138
  	        	if(result != null && result.success){
  	        		toastr.success(''+result.success+'', {
  		            	closeButton: true
  		          	})
cd330b5ee   Rishav   fuel vendor and v...
139
140
  		          	$('#vendor-modal-3').modal('hide');
  		          	getAllVendor();
1926e07b6   Anchal Midha   implement fuel ve...
141
142
143
144
145
146
147
148
  	        	}else{
  	        		toastr.error(''+result.statusText+'', {
  		            	closeButton: true
  		          	})
  	        	}
  	        });
        	}
      }