Blame view

app/partials/customers/customers.controller.js 10.2 KB
feacde5ff   Rishav   setup acuefuel in...
1
2
3
4
  'use strict';
  
   //Load controller
    angular.module('acufuel')
eefc1c74d   Swarn Singh   minor updates
5
  	.controller('customersController', ['$scope', '$rootScope', '$uibModal', '$filter', '$http', '$state', 'CustomersService', 'ViewCompanyService', 'NgTableParams', customersController]);
feacde5ff   Rishav   setup acuefuel in...
6

eefc1c74d   Swarn Singh   minor updates
7
   	function customersController($scope, $rootScope, $uibModal, $filter, $http, $state, CustomersService, ViewCompanyService, NgTableParams) {
4bb02bb84   Rishav   new integration w...
8
  		$(document).ready(function() {
05bfa28a2   Mr. Hot Foods   remove save butto...
9
  		    // $('#example').DataTable();
4bb02bb84   Rishav   new integration w...
10
  		});
a7a7cfeca   Rishav Singla   fuel vendor page ...
11
  		$scope.userProfileId = JSON.parse(localStorage.getItem('userProfileId'))
7152ff131   Rishav   model handle
12
13
  		$scope.reset2 = function(){
  			$("input").val("");
49676befb   Anchit Jindal   new changes applied
14
  			$scope.removeMarginValidation();
7152ff131   Rishav   model handle
15
  		}
05bfa28a2   Mr. Hot Foods   remove save butto...
16

7152ff131   Rishav   model handle
17
  		
4bb02bb84   Rishav   new integration w...
18
19
20
  		$scope.data = {};
  		$scope.aircraft = {};
  		$scope.data.activate = true;
05bfa28a2   Mr. Hot Foods   remove save butto...
21
  		$scope.showLoader = true;
b6f0311a3   Rishav   get Company api i...
22
  		getAllCompanies();
eefc1c74d   Swarn Singh   minor updates
23
  		/*function getAllCompanies(){
b6f0311a3   Rishav   get Company api i...
24
  			CustomersService.getAllCompanies().then(function(result) {
b6f0311a3   Rishav   get Company api i...
25
  				$scope.companyList = result;
3a9f4472b   Rishav   Implement contact...
26
27
28
  				for(var i=0; i<$scope.companyList.length; i++){
  					$scope.companyList[i].masterMargin = $scope.companyList[i].margin.id;
  				}
b6f0311a3   Rishav   get Company api i...
29
  			})
eefc1c74d   Swarn Singh   minor updates
30
31
32
33
34
35
36
37
  
  		}*/
  
  		$scope.statusFilter = [
  			{id: "", title: "Show All"},
  			{id: "true", title: "Active"},
  			{id: "false", title: "Inactive"}
  		]
b97bc56e0   Swarn Singh   table search and ...
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  		function getAllCompanies(){
  			CustomersService.getAllCompanies().then(function(result) {
  				console.log('log', 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
  		      });
05bfa28a2   Mr. Hot Foods   remove save butto...
65
  			  $scope.showLoader = false;
b97bc56e0   Swarn Singh   table search and ...
66
  			})
b6f0311a3   Rishav   get Company api i...
67
  		}
feacde5ff   Rishav   setup acuefuel in...
68

3a9f4472b   Rishav   Implement contact...
69
          $scope.editMargin = function(customer){
b97bc56e0   Swarn Singh   table search and ...
70
          	console.log('customer', customer);
52fea957f   Anchit Jindal   csv and search co...
71
          	$scope.showLoader = true;
d24318592   Rishav   changes and new i...
72
          	event.stopPropagation();
3a9f4472b   Rishav   Implement contact...
73
74
75
76
77
78
79
  
          	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;
cdf775224   Anchit Jindal   fixed company and...
80
          	ViewCompanyService.updateCompany(companyMargin).then(function(result) {
3a9f4472b   Rishav   Implement contact...
81
                if(result != null && result.success){
52fea957f   Anchit Jindal   csv and search co...
82
              	$scope.showLoader = false;
3a9f4472b   Rishav   Implement contact...
83
84
85
86
                  toastr.success(''+result.success+'', {
                    closeButton: true
                  })
                }else{
52fea957f   Anchit Jindal   csv and search co...
87
              	$scope.showLoader = false;
3a9f4472b   Rishav   Implement contact...
88
89
90
91
92
93
                  toastr.error(''+result.statusText+'', {
                    closeButton: true
                  })
                }
              })
          }
4bb02bb84   Rishav   new integration w...
94
95
          getData();
      	function getData(){
05bfa28a2   Mr. Hot Foods   remove save butto...
96
  			$scope.showLoader = true;
4bb02bb84   Rishav   new integration w...
97
  			CustomersService.getAircraftMake().then(function(result) {
4bb02bb84   Rishav   new integration w...
98
  			  $scope.aircraftMakeList = result;
05bfa28a2   Mr. Hot Foods   remove save butto...
99
  			  $scope.showLoader = false;
4bb02bb84   Rishav   new integration w...
100
101
  			})
  		}
3a9f4472b   Rishav   Implement contact...
102
        	
a7a7cfeca   Rishav Singla   fuel vendor page ...
103
104
105
106
107
108
  
  		// CustomersService.getMargin().then(function(result) {
  		//   $scope.marginList = result;
  		// })
  		$scope.marginFilterOptions = [];
  		CustomersService.getJetMargin($scope.userProfileId).then(function(result) {
9aae3d136   Mr. Hot Foods   show loaders and ...
109
  			$scope.showLoader = true;
a7a7cfeca   Rishav Singla   fuel vendor page ...
110
  		  $scope.jetMarginList = result;
c95befcd3   Swarn Singh   table issue, filt...
111
112
113
114
115
116
117
118
119
  		  $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
  		  	})
  		  }
9aae3d136   Mr. Hot Foods   show loaders and ...
120
  		  $scope.showLoader = false;
a7a7cfeca   Rishav Singla   fuel vendor page ...
121
  		})
c95befcd3   Swarn Singh   table issue, filt...
122

a7a7cfeca   Rishav Singla   fuel vendor page ...
123
124
  		CustomersService.getAvgMargin($scope.userProfileId).then(function(result) {
  		  $scope.avgsMarginList = result;
3a9f4472b   Rishav   Implement contact...
125
  		})
a7a7cfeca   Rishav Singla   fuel vendor page ...
126

32286a73a   Swarn Singh   tier issue resolved
127
128
129
130
  		$scope.showCompanyError = false;
  		$scope.showMarginError = false;
  
  		$scope.removeValidation = function(){
32286a73a   Swarn Singh   tier issue resolved
131
132
133
134
135
136
137
138
  			$scope.showCompanyError = false;
  	    	$('.companyNameInput').removeClass('customErrorInput');
  		}
  
  		$scope.removeMarginValidation = function(){
  			$scope.showMarginError = false;
  	    	$('.marginSelectBox').removeClass('customErrorInput');
  		}
6efd9a0a8   Anchit Jindal   new desing changes
139
140
  		
  		var companyData;
4bb02bb84   Rishav   new integration w...
141
  	    $scope.addFirstData = function(sel, step){
9aae3d136   Mr. Hot Foods   show loaders and ...
142
  			$scope.showLoader = true;
3a9f4472b   Rishav   Implement contact...
143
  	    	if($scope.data.companyName == undefined){
32286a73a   Swarn Singh   tier issue resolved
144
145
  	    		$scope.showCompanyError = true;
  	    		$('.companyNameInput').addClass('customErrorInput');
3a9f4472b   Rishav   Implement contact...
146
  	    	}else if($scope.data.masterMargin == undefined){
32286a73a   Swarn Singh   tier issue resolved
147
148
  	    		$scope.showMarginError = true;
  	    		$('.marginSelectBox').addClass('customErrorInput');
3a9f4472b   Rishav   Implement contact...
149
  	    	}else{
cdf775224   Anchit Jindal   fixed company and...
150
151
152
153
154
155
156
157
158
  	    		$scope.aircraftDetails = [{ 
  	                'tail':'',
  	                'make': '',
  	                'model': '',
  	                'sizeId' : '',
  	                'marginId': $scope.data.masterMargin,
  	                'avgasMarginId': $scope.data.avgasMargin
  	            }];
  	    	    
3a9f4472b   Rishav   Implement contact...
159
160
161
  	    	 	$(sel).trigger('next.m.' + step);
  	    	 	getData();
  	    	}
9aae3d136   Mr. Hot Foods   show loaders and ...
162
  			$scope.showLoader = false;
4bb02bb84   Rishav   new integration w...
163
  	    }
55e075d7e   Rishav   add contact, add ...
164
          $scope.addNew = function(){
9aae3d136   Mr. Hot Foods   show loaders and ...
165
  			$scope.showLoader = true;
55e075d7e   Rishav   add contact, add ...
166
167
168
169
              $scope.aircraftDetails.push({ 
                  'tail':'',
  	            'make': '',
  	            'model': '',
3a9f4472b   Rishav   Implement contact...
170
  	            'sizeId' : '',
a7a7cfeca   Rishav Singla   fuel vendor page ...
171
172
  	            'marginId': $scope.data.masterMargin,
              	'avgasMarginId': $scope.data.avgasMargin
55e075d7e   Rishav   add contact, add ...
173
              });
9aae3d136   Mr. Hot Foods   show loaders and ...
174
  			$scope.showLoader = false;
55e075d7e   Rishav   add contact, add ...
175
176
177
          };
  
          $scope.getModal = function(makeId, index){
d24318592   Rishav   changes and new i...
178
          	$scope.showLoader = true;
55e075d7e   Rishav   add contact, add ...
179
180
181
  	  		$scope.aircraft.make = makeId;
  	        //var makeId = makeId;
  	        CustomersService.getModal($scope.aircraft.make).then(function(result) {
d24318592   Rishav   changes and new i...
182
  	        	$scope.showLoader = false;
55e075d7e   Rishav   add contact, add ...
183
184
185
186
  	          $scope.aircraftDetails[index].aircraftModalList = result;
  	          //$scope.aircraftDetails[index].model = $scope.aircraftModalList[0];
  	        })
        	}
4bb02bb84   Rishav   new integration w...
187

55e075d7e   Rishav   add contact, add ...
188
        	$scope.getSize = function(model, index){
d24318592   Rishav   changes and new i...
189
        		$scope.showLoader = true;
55e075d7e   Rishav   add contact, add ...
190
  	        CustomersService.getAircraftSize($scope.aircraft.make, model).then(function(result) {
d24318592   Rishav   changes and new i...
191
  	        	$scope.showLoader = false;
7152ff131   Rishav   model handle
192
  	          	$scope.aircraftDetails[index].aircraftSizeList = result;
55e075d7e   Rishav   add contact, add ...
193
  	          //$scope.aircraftDetails[index].size = $scope.aircraftSizeList[0];
55e075d7e   Rishav   add contact, add ...
194
195
196
197
198
199
  	        })
        	}
  
        	$scope.aircraftListData = {};
        	$scope.addData = [];
        	$scope.saveCompanyData = function(){
cdf775224   Anchit Jindal   fixed company and...
200
        		CustomersService.addCompany($scope.data).then(function(result) {
6efd9a0a8   Anchit Jindal   new desing changes
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
              	$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.aircraftListData.aircraftList = $scope.addData;
      	        $scope.aircraftListData.accountId = $scope.aircraft.accountId;
      	        
cdf775224   Anchit Jindal   fixed company and...
217
218
219
220
      	        if($scope.aircraftListData.aircraftList[0].tail == "" || $scope.aircraftListData.aircraftList[0].make == null || $scope.aircraftListData.aircraftList[0].model == null){
      	        	$scope.aircraftListData.aircraftList = [];
      	        }
      	        
6efd9a0a8   Anchit Jindal   new desing changes
221
      	        CustomersService.addAircraft($scope.aircraftListData).then(function(result) {
b6f0311a3   Rishav   get Company api i...
222

6efd9a0a8   Anchit Jindal   new desing changes
223
224
225
226
227
228
229
230
231
232
233
234
      	        	if(result != null && result.success){
      	        		toastr.success(''+result.success+'', {
      		            	closeButton: true
      		          	})
      		          	$('#demo-modal-3').modal('hide');
      		          	getAllCompanies();
      	        	}else{
      	        		toastr.error(''+result.statusText+'', {
      		            	closeButton: true
      		          	})
      	        	}
      	        });
cdf775224   Anchit Jindal   fixed company and...
235
      	        
6efd9a0a8   Anchit Jindal   new desing changes
236
237
            	})
        		
55e075d7e   Rishav   add contact, add ...
238
239
240
241
242
243
244
245
  	        
        	}
  
  	    // $scope.appendText = function() {
       //      getData();
  	    //   var newRow =  $('<tr> <td> <input type="text" style="width:100px;" ng-model="aircraft.tail" class="form-control"> </td> <td style="width: 25%;"> <select class="form-control" ng-model="aircraft.make" ng-change="getModal()"> <option ng-repeat="make in aircraftMakeList">{{make}}</option> </select> </td> <td style="width: 20%;"> <select class="form-control" ng-model="aircraft.model" ng-change="getSize()"> <option ng-repeat="model in aircraftModalList">{{model}}</option> </select> </td> <td style="width: 25%;"> <select class="form-control" ng-model="aircraft.size"> <option ng-repeat="size in aircraftSizeList">{{size}}</option> </select> </td> <td> <select class="form-control"> <option>Margin1</option> <option>Margin2</option> </select> </td> </tr>');  
  	    //   $('table.addRow').append(newRow);
  	    // }
4bb02bb84   Rishav   new integration w...
246

67044e31e   Rishav Singla   modify changes an...
247
248
249
250
  	    $scope.setFuel = function(){
  	    	event.stopPropagation();
  	    	$state.go('app.updateFuelManager');
  	    }
eefc1c74d   Swarn Singh   minor updates
251
  	    /*  ng table  */
52fea957f   Anchit Jindal   csv and search co...
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
  	    
  	    $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;
  	    	 })
  	    }
eefc1c74d   Swarn Singh   minor updates
267

4bb02bb84   Rishav   new integration w...
268
269
  
      }