FuelVendors.controller.js
6.09 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
'use strict';
//Load controller
angular.module('acufuel')
.controller('FuelVendorsController', ['$scope', '$rootScope', '$uibModal', '$filter', '$http', 'FuelVendorsService', 'CustomersService', 'ViewFuelVendorService', 'NgTableParams', FuelVendorsController]);
function FuelVendorsController($scope, $rootScope, $uibModal, $filter, $http, FuelVendorsService, CustomersService, ViewFuelVendorService, NgTableParams) {
$scope.userProfileId = JSON.parse(localStorage.getItem('userProfileId'))
$scope.reset = function(){
$("input").val("");
$scope.removeMarginValidation();
}
$scope.data = {};
$scope.data.activate = true;
$scope.showLoader = false;
getAllVendor();
function getAllVendor(){
$scope.showLoader = true;
FuelVendorsService.getAllVendor().then(function(result) {
//console.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.companyList[i].source = "Vendor"
}
$scope.displayVendorList = new NgTableParams({
page: 1,
count: 10,
}, {
data: $scope.companyList
});
$scope.showLoader = false;
})
}
$scope.editMargin = function(vendor){
$scope.showLoader = true;
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){
$scope.showLoader = false;
toastr.success(''+result.success+'', {
closeButton: true
})
}else{
$scope.showLoader = false;
toastr.error(''+result.statusText+'', {
closeButton: true
})
}
})
}
CustomersService.getJetMargin($scope.userProfileId).then(function(result) {
$scope.jetMarginList = result;
})
CustomersService.getAvgMargin($scope.userProfileId).then(function(result) {
$scope.avgsMarginList = 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.marginFilterOptions = [];
CustomersService.getJetMargin($scope.userProfileId).then(function(result) {
$scope.jetMarginList = result;
$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
})
}
})
$scope.addFirstData = function(sel, step){
// console.log($scope.data)
if($scope.data.vendorName == undefined){
$scope.showCompanyError = true;
$('.companyNameInput').addClass('customErrorInput');
}else if($scope.data.masterMargin == undefined){
$scope.showMarginError = true;
$('.marginSelectBox').addClass('customErrorInput');
}else{
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($scope.data).then(function(result) {
$scope.accountId = result;
$scope.data = {};
$scope.data.activate = true;
$('#vendor-modal-3').modal('hide');
getAllVendor();
})
}
}
$scope.exportVendors = function() {
$scope.showLoader = true;
var fileName = "vendors.csv";
var a = document.createElement("a");
document.body.appendChild(a);
FuelVendorsService.exportVendors().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;
})
}
}