text: var app = angular.module('timeLine', ["ngRoute"]);
  
  app.controller('TimeLineController', function ($scope, $timeout, $interval, $http) {
      var vm = this;
      var currentUrl = window.location.href.split('/');
      var leadId = currentUrl.pop() || currentUrl.pop();
  
      vm.fetchTimeLineDatas = function () {
          $http.get('/lead/timeline/' + leadId).then(function (res) {
              $scope.created = res.data.created;
              vm.timelineDatas = res.data.result;
          }, function errorCallback(response) {
              vm.error = 'Error in processing';
              Swal.fire("Error", vm.error, "error");
          });
      };
      vm.fetchTimeLineDatas();
      
      vm.fetchQualificationDatas = function () {
          $scope.IsQualificationListVisible = false;
          var leadid = document.forms["qualification-v2"]["leadid"].value;
          $http.get('/lead/qualification/list/' + leadid).then(function (res) {           
              vm.qualificationDatas = res.data.result;
              if(vm.qualificationDatas==''){
                  $scope.IsQualificationListVisible = false;
              }
              if(vm.qualificationDatas!=''){
                  $scope.IsQualificationListVisible = true;
              }
             
          }, function errorCallback(response) {
              $scope.IsQualificationListVisible = false;
              vm.error = 'Error in processing';
              Swal.fire("Error", vm.error, "error");
          });
      };
  
      vm.addQualification = function () {
          var course = document.forms["qualification-v2"]["course"].value;
          var english = document.forms["qualification-v2"]["english"].value;
          var yearofpass = document.forms["qualification-v2"]["yearofpass"].value;
          var gpa = document.forms["qualification-v2"]["gpa"].value;
          var comments = document.forms["qualification-v2"]["comments"].value;
          var subject = document.forms["qualification-v2"]["subject"].value;
          var school = document.forms["qualification-v2"]["school"].value;
          var board = document.forms["qualification-v2"]["board"].value;
          var leadid = document.forms["qualification-v2"]["leadid"].value;
  
          if (course == "") {
              Swal.fire(
                  'Error!',
                  'Please fill required fields!',
                  'error'
              );
              return false;
          }
          $http.post('/lead/qualification/create', {
              course: course,
              english: english,
              yearofpass: yearofpass,
              gpa: gpa,
              comments: comments,
              subject: subject,
              school: school,
              board: board,
              leadid: leadid,
          }).then(function (res) {
              vm.fetchQualificationDatas();
              this.qualificationv2.reset();
              Swal.fire(
                  'Success!',
                  res.message,
                  'success'
              );
          }, function errorCallback(response) {
  
          });
  
      };
      vm.appendQualificationId = function (id) {
          // $("#qualification-id").empty().append(id);
          $("#qualification-id").val(id);
      };
      vm.leadQualificationUpdate = function () {
  
          var course = document.forms["update-lead-qualification"]["course"].value;
          var english = document.forms["update-lead-qualification"]["english"].value;
          var yearofpass = document.forms["update-lead-qualification"]["yearofpass"].value;
          var gpa = document.forms["update-lead-qualification"]["gpa"].value;
          var comments = document.forms["update-lead-qualification"]["comments"].value;
          var subject = document.forms["update-lead-qualification"]["subject"].value;
          var school = document.forms["update-lead-qualification"]["school"].value;
          var board = document.forms["update-lead-qualification"]["board"].value;
          var leadid = document.forms["update-lead-qualification"]["lead-id"].value;
          var qualificationid = document.forms["update-lead-qualification"]["qualification-id"].value;
  
          $http.post('/lead/qualification/update/' + leadid + '/' + qualificationid, {
              course: course,
              english: english,
              yearofpass: yearofpass,
              gpa: gpa,
              comments: comments,
              subject: subject,
              school: school,
              board: board,
              leadid: leadid,
          }).then(function (res) {
              vm.fetchQualificationDatas();
              Swal.fire(
                  'Success!',
                  res.message,
                  'success'
              );
          }, function errorCallback(response) {
  
          });
      };
      vm.deleteQualification = function (leadId, id) {
          var leadid = document.forms["qualification-v2"]["leadid"].value;
  
          Swal.fire({
              title: 'Are you sure?',
              text: "You won't be able to delete this!",
              icon: 'warning',
              showCancelButton: true,
              confirmButtonColor: '#3085d6',
              cancelButtonColor: '#d33',
              confirmButtonText: 'Yes, delete it!'
          }).then((result) => {
              if (result.isConfirmed) {
                  $http.post('/lead/qualification/delete/' + leadId + '/' + id, {}).then(function (res) {
                      vm.fetchQualificationDatas();
                      Swal.fire(
                          'Success!',
                          res.message,
                          'success'
                      );
                  }, function errorCallback(response) {
  
                  });
  
              }
          });
      };
      vm.fetchFollowupsDatas = function () {
          var leadid = document.forms["update-lead-qualification"]["lead-id"].value;
  
          $http.get('/lead/followup/list/' + leadid).then(function (res) {
              vm.followupsDatas = res.data.result;
          }, function errorCallback(response) {
              vm.error = 'Error in processing';
              Swal.fire("Error", vm.error, "error");
          });
      };
      vm.fetchFollowupsDatas();
      vm.addFollowup = function () {
          var programType = document.forms["form-lead-followups"]["program_type"].value;
          var followUpStatus = document.forms["form-lead-followups"]["follow_up_status"].value;
          var follow_up_next_date = document.forms["form-lead-followups"]["follow_up_next_date"].value;
          var description = document.forms["form-lead-followups"]["description"].value;
          var leadid = document.forms["update-lead-qualification"]["lead-id"].value;
      
          if(followUpStatus==''){
              Swal.fire(
                  'Error!',
                  'Please select followup status!.',
                  'error'
              );
              return false;
          }
          if ((followUpStatus == "Followup")) {
              if ((programType == "") || (follow_up_next_date == "") || (description == "")) {
                  Swal.fire(
                      'Error!',
                      'Please fill in all the required fields.',
                      'error'
                  );
                  return false;
              }
          }
          if ((followUpStatus != "Followup") && (description == "")) {
              Swal.fire(
                  'Error!',
                  'Please add a description!',
                  'error'
              );
              return false;
          }
  
          $http.post('/lead/followup/' + leadid, {
              program_type: programType,
              follow_up_status: followUpStatus,
              follow_up_description: description,
              follow_up_next_date: follow_up_next_date,
          }).then(function (res) {
              this.formLeadFollowups.reset();
              vm.fetchFollowupsDatas();
              Swal.fire(
                  'Success!',
                  res.message,
                  'success'
              );
          }, function errorCallback(response) {
  
          });
      };
  
      $scope.IsExpressEntryVisible = false;
      $scope.IsQuebeVisible = false;
      $scope.IsCapVisible = false;
      $scope.IsUkVisible = false;
      $scope.IsAmountVisible = false;
      $scope.IsBtnVisible = false;
      $scope.IsEnterAmountVisible = false;
  
      $scope.programType = function (type) {
          $scope.schemeAmount = 0;
          if (type == "Express Entry") {
              $scope.IsExpressEntryVisible = true;
              $scope.IsBtnVisible = true;
              $scope.IsQuebeVisible = false;
              $scope.IsCapVisible = false;
              $scope.IsUkVisible = false;
              $scope.IsEnterAmountVisible = false;
          }
          if (type == "QUEBE Immigration") {
              $scope.IsExpressEntryVisible = false;
              $scope.IsBtnVisible = true;
              $scope.IsQuebeVisible = true;
              $scope.IsCapVisible = false;
              $scope.IsUkVisible = false;
              $scope.IsEnterAmountVisible = false;
          }
          if (type == "NZ CAP") {
              $scope.IsExpressEntryVisible = false;
              $scope.IsBtnVisible = true;
              $scope.IsQuebeVisible = false;
              $scope.IsCapVisible = true;
              $scope.IsUkVisible = false;
              $scope.IsEnterAmountVisible = true;
              $scope.IsAmountVisible = false;
          }
          if (type == "UK Student Visa") {
              $scope.IsExpressEntryVisible = false;
              $scope.IsBtnVisible = true;
              $scope.IsQuebeVisible = false;
              $scope.IsCapVisible = false;
              $scope.IsUkVisible = true;
              $scope.IsEnterAmountVisible = false;
          }
      };
  
      $scope.schemeType = function (schemeid) {
          $http.get('/scheme/getdetails/' + schemeid).then(function (res) {
              if (res.data.result.type != "NZ CAP") {
                  $scope.schemeAmount = res.data.result.amount;
                  $scope.IsAmountVisible = true;
                  $scope.selectedSchemeType = res.data.result.scheme;
                  $scope.selectedSchemeTypeId = res.data.result.id;
              } else {
                  $scope.IsEnterAmountVisible = true;
                  $scope.IsAmountVisible = false;
                  $scope.selectedSchemeType = res.data.result.scheme;
                  $scope.selectedSchemeTypeId = res.data.result.id;
              }
  
          }, function errorCallback(response) {
              vm.error = 'Error in processing';
              Swal.fire("Error", vm.error, "error");
          });
      };
      $scope.IsPaymentsDataVisible = false;
      vm.fetchLeadPaymentsRequestDatas = function () {
          var leadid = document.forms["update-lead-qualification"]["lead-id"].value;
          $http.get('/lead/getpayments/'+leadid).then(function (res) {
              if (res.data.result != '') {
                  vm.paymentsDatas = res.data.result;
                  $scope.IsPaymentsDataVisible = true;
              } else {
                  $scope.IsPaymentsDataVisible = false;
              }
  
          }, function errorCallback(response) {
              vm.error = 'Error in processing';
              Swal.fire("Error", vm.error, "error");
          });
      };
      vm.fetchLeadPaymentsRequestDatas();
      vm.addPayment = function () {
          var programType = document.forms["formleadpayments"]["program_type"].value;
          var scheme = document.forms["formleadpayments"]["selected-scheme-type"].value;
          if ((programType == "") || (scheme == "")) {
              Swal.fire(
                  'Error!',
                  'Please select required fields!',
                  'error'
              );
              return false;
          }
          var amount = "";
          if (programType != 'NZ CAP') {
              amount = document.forms["formleadpayments"]["scheme-amount"].value;
          } else {
              amount = document.forms["formleadpayments"]["enter-scheme-amount"].value;
          }
          var schemeId = document.forms["formleadpayments"]["selected-scheme-type-id"].value;
  
          $http.post('/lead/payment/request', {
              lead_id: leadId,
              scheme_id: schemeId,
              type: programType,
              scheme: scheme,
              amount: amount,
          }).then(function (res) {
              this.formleadpayments.reset();
              vm.fetchLeadPaymentsRequestDatas();
              Swal.fire(
                  'Success!',
                  res.message,
                  'success'
              );
          }, function errorCallback(response) {
              vm.error = 'Error in processing';
              Swal.fire("Error", vm.error, "error");
          });
      };
  
      vm.deletePaymentRequest = function (id) {
          $http.get('/lead/payment/delete/' + id).then(function (res) {
              vm.fetchLeadPaymentsRequestDatas();
          }, function errorCallback(response) {
              vm.error = 'Error in processing';
              Swal.fire("Error", vm.error, "error");
          });
      };
      vm.sendEmails = function (leadId, type) {
          Swal.fire({
              title: 'Are you sure?',
              text: "Do you want to send an email?",
              icon: 'warning',
              showCancelButton: true,
              confirmButtonColor: '#3085d6',
              cancelButtonColor: '#d33',
              confirmButtonText: 'Yes'
          }).then((result) => {
              if (result.isConfirmed) {
                  $http.post('/lead/send-email', {
                      lead_id: leadId,
                      type: type,
                  }).then(function (res) {
                      if (res.data.status == false) {
                          Swal.fire(
                              'Error!',
                              res.data.message,
                              'error'
                          );
                      }
                      if (res.data.status == true) {
                          Swal.fire(
                              'Success!',
                              res.data.message,
                              'success'
                          );
                      }
                  }, function errorCallback(response) {
                      vm.error = 'Error in processing';
                      Swal.fire("Error", vm.error, "error");
                  });
  
              }
          });
      };
  
  });