customers.controller.js
7.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
53
54
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
'use strict';
//Load controller
angular.module('acufuel')
.controller('customersController', ['$scope', '$rootScope', '$uibModal', '$filter', '$http', 'CustomersService', 'ViewCompanyService', customersController]);
function customersController($scope, $rootScope, $uibModal, $filter, $http, CustomersService, ViewCompanyService) {
$(document).ready(function() {
$('#example').DataTable();
});
$scope.reset2 = function(){
$("input").val("");
}
$scope.data = {};
$scope.aircraft = {};
$scope.data.activate = true;
$scope.showLoader = false;
getAllCompanies();
function getAllCompanies(){
CustomersService.getAllCompanies().then(function(result) {
$scope.companyList = result;
for(var i=0; i<$scope.companyList.length; i++){
$scope.companyList[i].masterMargin = $scope.companyList[i].margin.id;
}
})
}
$scope.editMargin = function(customer){
event.stopPropagation();
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;
ViewCompanyService.updateContact(companyMargin).then(function(result) {
if(result != null && result.success){
toastr.success(''+result.success+'', {
closeButton: true
})
}else{
toastr.error(''+result.statusText+'', {
closeButton: true
})
}
})
}
getData();
function getData(){
CustomersService.getAircraftMake().then(function(result) {
$scope.aircraftMakeList = result;
})
}
CustomersService.getMargin().then(function(result) {
$scope.marginList = result;
})
$scope.showCompanyError = false;
$scope.showMarginError = false;
$scope.removeValidation = function(){
$scope.showCompanyError = false;
$('.companyNameInput').removeClass('customErrorInput');
}
$scope.removeMarginValidation = function(){
$scope.showMarginError = false;
$('.marginSelectBox').removeClass('customErrorInput');
}
$scope.addFirstData = function(sel, step){
if($scope.data.companyName == undefined){
$scope.showCompanyError = true;
$('.companyNameInput').addClass('customErrorInput');
}else if($scope.data.masterMargin == undefined){
$scope.showMarginError = true;
$('.marginSelectBox').addClass('customErrorInput');
}else{
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) {
$scope.accountId = result;
$scope.aircraft.accountId = $scope.accountId;
})
$(sel).trigger('next.m.' + step);
getData();
}
}
$scope.aircraftDetails = [{
'tail':'',
'make': '',
'model': '',
'sizeId' : '',
'marginId': $scope.data.masterMargin
}];
$scope.addNew = function(){
$scope.aircraftDetails.push({
'tail':'',
'make': '',
'model': '',
'sizeId' : '',
'marginId': ''
});
};
$scope.getModal = function(makeId, index){
$scope.showLoader = true;
$scope.aircraft.make = makeId;
//var makeId = 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.getSize = function(model, index){
$scope.showLoader = true;
CustomersService.getAircraftSize($scope.aircraft.make, model).then(function(result) {
$scope.showLoader = false;
$scope.aircraftDetails[index].aircraftSizeList = result;
//$scope.aircraftDetails[index].size = $scope.aircraftSizeList[0];
})
}
$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,
'sizeId' : $scope.aircraftDetails[i].sizeId,
'marginId': $scope.aircraftDetails[i].marginId
});
}
$scope.aircraftListData.aircraftList = $scope.addData;
$scope.aircraftListData.accountId = $scope.aircraft.accountId;
CustomersService.addAircraft($scope.aircraftListData).then(function(result) {
if(result != null && result.success){
toastr.success(''+result.success+'', {
closeButton: true
})
$('#demo-modal-3').modal('hide');
getAllCompanies();
}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);
// }
}