Blame view

app/partials/customers/customers.controller.js 5.15 KB
feacde5ff   Rishav   setup acuefuel in...
1
2
3
4
  'use strict';
  
   //Load controller
    angular.module('acufuel')
55e075d7e   Rishav   add contact, add ...
5
  	.controller('customersController', ['$scope', '$rootScope', '$uibModal', '$filter', '$http', 'CustomersService', customersController]);
feacde5ff   Rishav   setup acuefuel in...
6

55e075d7e   Rishav   add contact, add ...
7
   	function customersController($scope, $rootScope, $uibModal, $filter, $http, CustomersService) {
4bb02bb84   Rishav   new integration w...
8
9
10
11
12
13
  		$(document).ready(function() {
  		    $('#example').DataTable();
  		});
  		$scope.data = {};
  		$scope.aircraft = {};
  		$scope.data.activate = true;
55e075d7e   Rishav   add contact, add ...
14
  		
b6f0311a3   Rishav   get Company api i...
15
16
17
18
19
20
21
22
  		getAllCompanies();
  
  		function getAllCompanies(){
  			CustomersService.getAllCompanies().then(function(result) {
  				console.log(result)
  				$scope.companyList = result;
  			})
  		}
feacde5ff   Rishav   setup acuefuel in...
23

4bb02bb84   Rishav   new integration w...
24
25
26
27
28
29
30
          $(function() {
  	     	$('#toggle-one2').bootstrapToggle();
  	     	$('#toggle-one2').change(function() {
  		      $('#console-event').html('Toggle: ' + $(this).prop('checked'));
  		      $scope.data.activate = $(this).prop('checked');
  		    })
          })
feacde5ff   Rishav   setup acuefuel in...
31

4bb02bb84   Rishav   new integration w...
32
33
34
35
36
          
  
          getData();
      	function getData(){
  			CustomersService.getAircraftMake().then(function(result) {
4bb02bb84   Rishav   new integration w...
37
  			  $scope.aircraftMakeList = result;
4bb02bb84   Rishav   new integration w...
38
39
40
  			})
  		}
        
4bb02bb84   Rishav   new integration w...
41
42
  	    $scope.addFirstData = function(sel, step){
  	    	// console.log($scope.data)
55e075d7e   Rishav   add contact, add ...
43
44
45
46
47
48
49
50
51
52
53
54
  	    	var companyData = "companyName=" + $scope.data.companyName + "&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;
  
  	    	CustomersService.addCompany(companyData).then(function(result) {
              	console.log(result)
              	$scope.accountId = result;
        			$scope.aircraft.accountId = $scope.accountId;
            	})
4bb02bb84   Rishav   new integration w...
55
56
57
      	 	$(sel).trigger('next.m.' + step);
      	 	getData();
  	    }
55e075d7e   Rishav   add contact, add ...
58
59
60
61
  	    $scope.aircraftDetails = [{ 
              'tail':'',
              'make': '',
              'model': '',
b6f0311a3   Rishav   get Company api i...
62
              'sizeId' : ''
55e075d7e   Rishav   add contact, add ...
63
64
65
66
67
68
69
          }];
      
          $scope.addNew = function(){
              $scope.aircraftDetails.push({ 
                  'tail':'',
  	            'make': '',
  	            'model': '',
b6f0311a3   Rishav   get Company api i...
70
  	            'sizeId' : ''
55e075d7e   Rishav   add contact, add ...
71
72
73
74
75
76
77
78
79
80
81
82
              });
              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];
  	        })
        	}
4bb02bb84   Rishav   new integration w...
83

55e075d7e   Rishav   add contact, add ...
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
        	$scope.getSize = function(model, index){
  	        CustomersService.getAircraftSize($scope.aircraft.make, model).then(function(result) {
  	          $scope.aircraftDetails[index].aircraftSizeList = result;
  	          //$scope.aircraftDetails[index].size = $scope.aircraftSizeList[0];
  	          console.log($scope.aircraftDetails[index].size)
  	        })
        	}
  
        	$scope.aircraftListData = {};
        	$scope.addData = [];
        	$scope.saveCompanyData = 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,
b6f0311a3   Rishav   get Company api i...
100
  		            'sizeId' : $scope.aircraftDetails[i].sizeId
55e075d7e   Rishav   add contact, add ...
101
102
103
104
105
106
107
  	            });
        		}
  	        $scope.aircraftListData.aircraftList = $scope.addData;
  	        $scope.aircraftListData.accountId = $scope.aircraft.accountId;
  	        
  	        CustomersService.addAircraft($scope.aircraftListData).then(function(result) {
  	        	console.log(result)
b6f0311a3   Rishav   get Company api i...
108

b1f6160d4   Rishav   add contact and a...
109
  	        	if(result != null && result.success){
55e075d7e   Rishav   add contact, add ...
110
111
112
113
  	        		toastr.success(''+result.success+'', {
  		            	closeButton: true
  		          	})
  		          	$('#demo-modal-3').modal('hide');
b6f0311a3   Rishav   get Company api i...
114
  		          	getAllCompanies();
55e075d7e   Rishav   add contact, add ...
115
116
117
118
119
120
121
122
123
124
125
126
127
128
  	        	}else{
  	        		toastr.error(''+result.statusText+'', {
  		            	closeButton: true
  		          	})
  	        	}
  	        });
  	        
        	}
  
  	    // $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...
129
130
131
  
  
      }