Blame view

app/partials/viewFuelVendor/viewFuelVendor.controller.js 17.5 KB
cd330b5ee   Rishav   fuel vendor and v...
1
2
3
4
  'use strict';
  
   //Load controller
    angular.module('acufuel')
1b71872b2   Kuldeep Arora   email and code be...
5
    .controller('ViewFuelVendorController', ['$scope','$uibModal', '$stateParams', 'ViewFuelVendorService', 'CustomersService', 'ViewCompanyService', 'updateFuelManagerService','$state', function($scope , $uibModal, $stateParams, ViewFuelVendorService, CustomersService, ViewCompanyService, updateFuelManagerService,$state) {
cd330b5ee   Rishav   fuel vendor and v...
6
7
          $scope.data = {};
          $scope.data.priceEmail = true;
d1fe89776   Rishav Singla   view fuel vendor ...
8
          $scope.primayData = {};
d24318592   Rishav   changes and new i...
9
          $scope.showLoader = false;
d1fe89776   Rishav Singla   view fuel vendor ...
10
11
12
13
14
15
16
17
          $scope.showUpdateBtn = false;
          $scope.userProfileId = JSON.parse(localStorage.getItem('userProfileId'));
  
          $(document).ready(function() {
              $("#reset").click(function() {
                  $("input").val("");
              });
          });
cd330b5ee   Rishav   fuel vendor and v...
18
          var vendorId = $stateParams.id;
d1fe89776   Rishav Singla   view fuel vendor ...
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
          $scope.vendorData = {};
          getVendorDetail();
  
          function getVendorDetail(){
            ViewFuelVendorService.getFuelOrder(vendorId).then(function(result) {
              $scope.vendorData = result;
              if(result.margin != null){
                   $scope.vendorData.masterMargin = result.margin.id;
              }
              if(result.marginAVGAS != null){
                  $scope.vendorData.avgasMargin = result.marginAVGAS.id;
              }
            })
          }
          
64b3dc0e3   Kuldeep Arora   omit vendor and c...
34
                  
d1fe89776   Rishav Singla   view fuel vendor ...
35
36
37
          $scope.changeCompanyStatus = function(){
              $('#deleteVendor').css('display', 'block');
              if($scope.vendorData.activate == true){
cdf775224   Anchit Jindal   fixed company and...
38
                $scope.statusMessage = 'Please confirm! Are you sure you want to ACTIVATE this Vendor?'
d1fe89776   Rishav Singla   view fuel vendor ...
39
              }else{
cdf775224   Anchit Jindal   fixed company and...
40
                $scope.statusMessage = 'Please confirm! Are you sure you want to DEACTIVATE this Vendor?'
d1fe89776   Rishav Singla   view fuel vendor ...
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
              }
          }
  
          $scope.companyStatus = function(){
              var statusData = "status=" + $scope.vendorData.activate;
              ViewFuelVendorService.changeStatus(vendorId, statusData).then(function(result) {
                if(result.success){
                    $('#deleteVendor').css('display', 'none');
                    toastr.success(''+result.success+'', {
                        closeButton: true
                    })
                    getContactList();
                }
              })
          }
  
          $scope.cancelStatus = function(){
              $('#deleteVendor').css('display', 'none');
              $scope.vendorData.activate =  !$scope.vendorData.activate;
          }
cd330b5ee   Rishav   fuel vendor and v...
61
62
63
  
          getContactList();
          function getContactList(){
ea15674c8   Rishav   minor changes for...
64
            ViewFuelVendorService.getContact(vendorId).then(function(result) {
cd330b5ee   Rishav   fuel vendor and v...
65
              $scope.vendorContactList = result;
cd330b5ee   Rishav   fuel vendor and v...
66
67
            })
          }
cd330b5ee   Rishav   fuel vendor and v...
68
69
70
          $scope.contactData = {};
          $scope.contactData.contactList = [];
          $scope.addContact = function(){
d1fe89776   Rishav Singla   view fuel vendor ...
71
            $scope.data.companyId = vendorId;
cd330b5ee   Rishav   fuel vendor and v...
72
            $scope.contactData.contactList.push($scope.data);
ea15674c8   Rishav   minor changes for...
73
            ViewFuelVendorService.addContact($scope.contactData).then(function(result) {
d1fe89776   Rishav Singla   view fuel vendor ...
74
              if(result.status == 200){
cd330b5ee   Rishav   fuel vendor and v...
75
                  $('#contact-modal-3').modal('hide');
d1fe89776   Rishav Singla   view fuel vendor ...
76
77
                  $scope.primayData.id = result.data;
                  $scope.sendPrimaryContact();
e196b9b74   Anchit Jindal   new changes added
78
                  $scope.contactData.contactList = [];
d1fe89776   Rishav Singla   view fuel vendor ...
79
                  $scope.data = {};
e5448f302   Kuldeep Arora   delete fuelvendor UI
80
                  $scope.data.priceEmail = true;
cd330b5ee   Rishav   fuel vendor and v...
81
82
83
84
85
86
87
88
                  getContactList();
              }else{
                toastr.error(''+result.statusText+'', {
                    closeButton: true
                  })
              }
            })
          }
d1fe89776   Rishav Singla   view fuel vendor ...
89
90
91
92
93
94
          $scope.showNoteData = true;
          $scope.showCompanyName = true;
          $scope.showAddress = true;
          $scope.showNote = function(){
            $scope.showNoteData = false;
            $scope.showUpdateBtn = true;
cd330b5ee   Rishav   fuel vendor and v...
95
          }
d1fe89776   Rishav Singla   view fuel vendor ...
96
97
98
99
100
101
102
103
104
105
106
107
  
          $scope.company = function(){
            $scope.showCompanyName = false;
            $scope.showUpdateBtn = true;
          }
  
          $scope.addressChange = function(){
            $scope.showAddress = false;
            $scope.showUpdateBtn = true;
          }
  
          $scope.editData = function(inputName) {
e5448f302   Kuldeep Arora   delete fuelvendor UI
108
              //console.log($scope.vendorData)
d1fe89776   Rishav Singla   view fuel vendor ...
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
              $scope.showLoader = true;
              // if(inputName == 'showNoteData'){
              //   $scope.showNoteData = true;
              // }else if(inputName == 'showCompanyName'){
              //   $scope.showCompanyName = true;
              // }else if(inputName == 'showAddress'){
              //   $scope.showAddress = true;              
              // }
              $scope.showNoteData = true;
              $scope.showCompanyName = true;
              $scope.showAddress = true;
  
              var vendorData = "vendorName=" + $scope.vendorData.vendorName + "&masterMargin=" + $scope.vendorData.masterMargin 
                + "&addressOne=" + $scope.vendorData.addressOne + "&addressTwo=" + $scope.vendorData.addressTwo + "&city=" + $scope.vendorData.city + "&state=" 
                + $scope.vendorData.state + "&country=" + $scope.vendorData.country + "&zipcode=" + $scope.vendorData.zipcode + "&internalNote=" 
                + $scope.vendorData.internalNote + "&certificateType=" + $scope.vendorData.certificateType + "&baseTenant=" + $scope.vendorData.baseTenant
                + "&fuelerlinxCustomer=" + $scope.vendorData.fuelerlinxCustomer + "&contractFuelVendor=" + $scope.vendorData.contractFuelVendor 
                + "&activate=" + $scope.vendorData.activate + "&baseIcao=" + $scope.vendorData.baseIcao + "&vendorId=" + vendorId;
  
              ViewFuelVendorService.updateContact(vendorData).then(function(result) {
                if(result != null && result.success){
                  toastr.success(''+result.success+'', {
                    closeButton: true
                  })
                  $scope.showUpdateBtn = false;
                }else{
                  toastr.error(''+result.statusText+'', {
                    closeButton: true
                  })
                  $scope.showUpdateBtn = true;
                }
                $scope.showLoader = false;
              })
              
          }
  
          $scope.cancelData = function(){
a4884cfe7   Rishav   add aircraft issu...
146
              $scope.showNoteData = true;
a4884cfe7   Rishav   add aircraft issu...
147
              $scope.showCompanyName = true;
d1fe89776   Rishav Singla   view fuel vendor ...
148
149
150
151
152
153
154
              $scope.showAddress = true;
              $scope.showUpdateBtn = false;
          }
  
          $scope.sendMail = function(){
            $('#confirm2').css('display', 'none');
            ViewFuelVendorService.sendMail(vendorId).then(function(result) {
64b3dc0e3   Kuldeep Arora   omit vendor and c...
155
               // console.log("email", vendorId)
d1fe89776   Rishav Singla   view fuel vendor ...
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
181
182
183
184
185
186
                if(result != null && result.success){
                  toastr.success(''+result.success+'', {
                    closeButton: true
                  })
                }else{
                  toastr.error(''+result.statusText+'', {
                    closeButton: true
                  })
                }
            })
          }
  
          $scope.openConfirmMail = function(){
            $('#confirm2').css('display', 'block');
          }
  
  
          $scope.cancelAndCloseConfirm = function(){
            $('#confirm2').css('display', 'none');
          }
  
          $scope.primaryContact = false;
          $scope.cancelPrimaryContact = function(){
            $('#primaryContact').css('display', 'none');
            $scope.primaryContact = false;
          }
  
          $scope.checkPrimaryContact = function(){
            if($scope.primaryContact == true){
              $scope.primaryContact = true;
              ViewFuelVendorService.checkPrimaryContact(vendorId).then(function(result) {
e5448f302   Kuldeep Arora   delete fuelvendor UI
187
                //console.log(result)
d1fe89776   Rishav Singla   view fuel vendor ...
188
189
190
191
192
193
194
195
196
197
198
199
200
                if(result.status == 422){
                  $('#primaryContact').css('display', 'block');
                }
              })
            }
          }
  
          $scope.sendPrimaryContact = function(){
            $('#primaryContact').css('display', 'none');
            if($scope.primayData.id != null || $scope.primayData.id != undefined){
              var priamryContactData = "vendorContactId=" + $scope.primayData.id + "&primary=" + $scope.primaryContact;
  
              ViewFuelVendorService.addPrimaryContact(priamryContactData).then(function(result) {
e5448f302   Kuldeep Arora   delete fuelvendor UI
201
               // console.log(result)
d1fe89776   Rishav Singla   view fuel vendor ...
202
              })
cd330b5ee   Rishav   fuel vendor and v...
203
            }
d1fe89776   Rishav Singla   view fuel vendor ...
204
205
            
          }
a4884cfe7   Rishav   add aircraft issu...
206

d1fe89776   Rishav Singla   view fuel vendor ...
207
          $scope.updateData = ""
9d840540f   Anchit Jindal   fixed bugs and ne...
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
          $scope.showUpdateContact = function(data, value) {
              $('#updateContact').css('display', 'block');
              $scope.updateData = data;
              // console.log($scope.updateData)
              if ($scope.updateData.email == null) {
                  $scope.updateData.content = data.contactNumber;
              } else {
                  $scope.updateData.content = data.email;
              }
          }
          
          $scope.showUpdateEmail = function(data, value) {
              $('#updateEmail').css('display', 'block');
              $scope.updateData = data;
              // console.log($scope.updateData)
              if ($scope.updateData.email == null) {
                  $scope.updateData.content = data.contactNumber;
              } else {
                  $scope.updateData.content = data.email;
              }
d1fe89776   Rishav Singla   view fuel vendor ...
228
          }
9d840540f   Anchit Jindal   fixed bugs and ne...
229
          $scope.acceptUpdateField = function(newContactName){
e5448f302   Kuldeep Arora   delete fuelvendor UI
230
           // console.log($scope.updateData)
d1fe89776   Rishav Singla   view fuel vendor ...
231
232
233
234
235
236
237
238
            if($scope.updateData.content == undefined){
              toastr.error('Please add some content', {
                closeButton: true
              })
            }else{
              if(newContactName == 'phone'){
                var updateCustomData = "vendorId=" + vendorId + "&contactNumber=" + $scope.updateData.content + "&contactId=" + $scope.updateData.id
                  + "&title=" + $scope.updateData.title;
cd330b5ee   Rishav   fuel vendor and v...
239
              }else{
d1fe89776   Rishav Singla   view fuel vendor ...
240
241
                var updateCustomData = "vendorId=" + vendorId + "&email=" + $scope.updateData.content + "&contactId=" + $scope.updateData.id
                  + "&title=" + $scope.updateData.title;
cd330b5ee   Rishav   fuel vendor and v...
242
              }
d1fe89776   Rishav Singla   view fuel vendor ...
243
              ViewFuelVendorService.updateCustomField(updateCustomData).then(function(result) {
d1fe89776   Rishav Singla   view fuel vendor ...
244
                if(result != null && result.success){
9d840540f   Anchit Jindal   fixed bugs and ne...
245
246
247
              	  $('#updateContact').css('display', 'none');
                    $('#updateEmail').css('display', 'none');
                    getVendorDetail();
d1fe89776   Rishav Singla   view fuel vendor ...
248
249
250
251
                }
              })
            }
          }
9d840540f   Anchit Jindal   fixed bugs and ne...
252
253
254
255
256
257
258
259
260
261
262
          
          $scope.deleteContent = function(data){
          	ViewFuelVendorService.deleteCustomContact(data.id).then(function(result) {
                  if (result != null && result.success) {
                  	toastr.success('' + result.success + '', {
                          closeButton: true
                      })
                      getVendorDetail();
                  }
              })
          }
d1fe89776   Rishav Singla   view fuel vendor ...
263
264
265
266
267
268
  
          $scope.cancelUpdateField = function(){
            $('#updateContact').css('display', 'none');
          }
  
          $scope.showEditTier2 = function(number){
e5448f302   Kuldeep Arora   delete fuelvendor UI
269
           // console.log(number)
d1fe89776   Rishav Singla   view fuel vendor ...
270
271
            $scope.contactNumber = number;
          }
9d840540f   Anchit Jindal   fixed bugs and ne...
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
          
          $scope.addCustomPhone = function(value) {
              //console.log(value)
              if (value != null) {
                  $('#customFieldPhone').css('display', 'block');
              }
              $scope.custom = {};
          }
          
          $scope.addCustomEmail = function(value) {
              //console.log(value)
              if (value != null) {
                  $('#customFieldEmail').css('display', 'block');
              }
              $scope.custom = {};
d1fe89776   Rishav Singla   view fuel vendor ...
287
          }
9d840540f   Anchit Jindal   fixed bugs and ne...
288
289
290
          $scope.cancelCustomField = function() {
              $('#customFieldEmail').css('display', 'none');
              $('#customFieldPhone').css('display', 'none');
d1fe89776   Rishav Singla   view fuel vendor ...
291
292
          }
          
9d840540f   Anchit Jindal   fixed bugs and ne...
293
294
          
          $scope.acceptCustomField = function(contactName){
d1fe89776   Rishav Singla   view fuel vendor ...
295
296
297
298
299
300
301
302
            if($scope.custom.content == undefined){
              toastr.error('Please add some content', {
                closeButton: true
              })
            }else{
              if(contactName == 'phone'){
                var customData = "vendorId=" + vendorId + "&contactNumber=" + $scope.custom.content 
                  + "&title=" + $scope.custom.title;
a4884cfe7   Rishav   add aircraft issu...
303
              }else{
d1fe89776   Rishav Singla   view fuel vendor ...
304
305
306
307
                var customData = "vendorId=" + vendorId + "&email=" + $scope.custom.content 
                  + "&title=" + $scope.custom.title;
              }
              ViewFuelVendorService.addCustomField(customData).then(function(result) {
e5448f302   Kuldeep Arora   delete fuelvendor UI
308
               // console.log(result)
d1fe89776   Rishav Singla   view fuel vendor ...
309
                if(result.status == 200){
9d840540f   Anchit Jindal   fixed bugs and ne...
310
311
              	  $('#customFieldEmail').css('display', 'none');
                    $('#customFieldPhone').css('display', 'none');
d1fe89776   Rishav Singla   view fuel vendor ...
312
313
314
315
316
                  getVendorDetail();
                }
              })
            }
          }
64b3dc0e3   Kuldeep Arora   omit vendor and c...
317
          /* omit strike out here */
d1fe89776   Rishav Singla   view fuel vendor ...
318
319
          updateFuelManagerService.getFuelPricingNew().then(function(result) {
            $scope.fuelPricing = result;
64b3dc0e3   Kuldeep Arora   omit vendor and c...
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
            $scope.omitData;
             ViewFuelVendorService.getOmitVendor(vendorId).then(function(result){
                  $scope.omitData = result;
                 // console.log("omit data===",$scope.omitData);
                  for(var i = 0 ; i< $scope.fuelPricing.length; i++){
                      for(var j = 0; j<$scope.omitData.length; j++){
                          if($scope.omitData[j].marginId == $scope.fuelPricing[i].fuelPricing.id){
                              $scope.fuelPricing[i].fuelPricing.omit = $scope.omitData[j].omit;
                      }
                          }
                  }
              })
                //  console.log("$scope.fuelPricing",$scope.fuelPricing)
                      for (var i = 0; i<$scope.fuelPricing.length; i++) {
                        if ($scope.fuelPricing[i].fuelPricing.expirationDate != null) {
                            $scope.fuelPricing[i].fuelPricing.expirationDate = new Date($scope.fuelPricing[i].fuelPricing.expirationDate);
                            var newTime = new Date($scope.fuelPricing[i].fuelPricing.expirationDate);
                            var dmonth = newTime.getUTCMonth() + 1; //months from 1-12
                            var dday = newTime.getUTCDate();
                            var dyear = newTime.getUTCFullYear();
                            $scope.fuelPricing[i].fuelPricing.expirationDate = dmonth+'/'+dday+'/'+dyear;
                        }
                      }
a4884cfe7   Rishav   add aircraft issu...
343
          })
cd330b5ee   Rishav   fuel vendor and v...
344

d1fe89776   Rishav Singla   view fuel vendor ...
345
346
347
348
          
          CustomersService.getJetMargin($scope.userProfileId).then(function(result) {
            $scope.jetMarginList = result;
          })
3a9f4472b   Rishav   Implement contact...
349

d1fe89776   Rishav Singla   view fuel vendor ...
350
351
352
          CustomersService.getAvgMargin($scope.userProfileId).then(function(result) {
            $scope.avgsMarginList = result;
          })
3a9f4472b   Rishav   Implement contact...
353

d1fe89776   Rishav Singla   view fuel vendor ...
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
           $scope.changePriceEmail = function(id, index){
              event.stopPropagation();
              var contactId = id;
              var statusData = "status=" + $scope.vendorContactList[index].priceEmail;
              ViewFuelVendorService.changePriceEmail(contactId, statusData).then(function(result) {
                  if(result.success){
                      $('#toogleMail').css('display', 'block');
                      if($scope.vendorContactList[index].priceEmail == true){
                        $scope.messageText = 'You have enabled price distribution for this contact';
                      }else{
                        $scope.messageText = 'You have disabled price distribution for this contact';
                      }
                  }
              })
            }
3a9f4472b   Rishav   Implement contact...
369

d1fe89776   Rishav Singla   view fuel vendor ...
370
371
372
            $scope.cancelToogle = function(){
              $('#toogleMail').css('display', 'none');
            }
cdf775224   Anchit Jindal   fixed company and...
373
374
            
            $scope.updateOmit = function(fuel, omit) {
1b71872b2   Kuldeep Arora   email and code be...
375
376
377
378
379
380
381
382
              $scope.fuelData = {};
              $scope.fuelData.expirationDate = new Date(fuel.expirationDate);
              $scope.fuelData.customMarginId = fuel.id;
              $scope.fuelData.omit = fuel.omit;
              $scope.fuelData.papMargin = fuel.papMargin;
              $scope.fuelData.papTotal = fuel.papTotal;
              $scope.fuelData.cost = fuel.cost;
              if($scope.fuelData.omit == true)
bfbbd8668   Kuldeep Arora   UI service
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
              {
                 // console.log("Insert API called",$scope.fuelData)
                  var customData = "vendorId=" + vendorId + "&customMarginId=" + $scope.fuelData.customMarginId; 
                   console.log(customData)
                   ViewFuelVendorService.omitAddvendorFuel(customData).then(function(result) {
                      if (result.success) {
                          toastr.success('' + result.success + '', {
                              closeButton: true
                          })
                      } else {
                          toastr.error('' + result.statusText + '', {
                              closeButton: true
                          })
                      }
                  }) 
              }else{
64b3dc0e3   Kuldeep Arora   omit vendor and c...
399
400
401
                 // console.log("Delete API called",vendorId)
                   var data ="vendorId=" + vendorId + "&customMarginId=" + $scope.fuelData.customMarginId;
                  ViewFuelVendorService.omitDeleteVendorFuel(data).then(function(result){
bfbbd8668   Kuldeep Arora   UI service
402
403
404
405
406
407
408
409
410
411
412
                          if (result.success) {
                          toastr.success('' + result.success + '', {
                              closeButton: true
                          })
                        } else {
                          toastr.error('' + result.statusText + '', {
                              closeButton: true
                          })
                      }
                  })
              }
cdf775224   Anchit Jindal   fixed company and...
413
            }
3a9f4472b   Rishav   Implement contact...
414

e5448f302   Kuldeep Arora   delete fuelvendor UI
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
          var deleteVendorId = "";
          $scope.deleteVendor = function(vendorDataid){
              $('#delete2').css('display', 'block');
             // console.log("asda",vendorDataid)
              deleteVendorId = vendorDataid;
          }
  
          $scope.deleteVendorData = function(){
              ViewFuelVendorService.deleteFuelVendor(deleteVendorId).then(function(result) {
                     
                $('#delete2').css('display', 'none');
                if(result.success){
                toastr.success(''+result.success+'', {
                      closeButton: true
  
                  })
              }else{
                toastr.error(''+result.statusText+'', {
                  closeButton: true
  
                })
              }
              $state.go('app.FuelVendors')
               })
          }
          $scope.cancelDelete = function(){
          $('#delete2').css('display', 'none');
        }
cd330b5ee   Rishav   fuel vendor and v...
443
    }]);