'use strict'; /** * controllers for ng-table * Simple table with sorting and filtering on AngularJS */ app.controller('callTrackingCtrl', ["$scope","$rootScope","toaster", "$filter", "ngTableParams", "API_POINTS", "$localStorage", "$http", "$state", function ($scope,$rootScope,toaster, $filter, ngTableParams, apiPoint, $localStorage, $http, $state) { localStorage.setItem('searchName',''); localStorage.setItem('searchMobile',''); $scope.myModel = { "studentName": "", "mobileNumber": "", "universityName": "", "courseName": "", "date": new Date(), "activity": "", "assignedTo": "", "status": "", "referedBy": '', "comments":'', "enquiryStatus":'' }; //get current date $scope.hideDateSearch=true; $scope.currentDate=$filter('date')(new Date(), 'dd-MM-yyyy'); // get 30 plus date for follwup details $scope.modifyDate = moment(); $scope.modifyDate.add(30, 'days'); $scope.futureDate = $filter('date')($scope.modifyDate, 'dd-MM-yyyy'); $scope.myModel.date=$scope.currentDate; $scope.search=$scope.currentDate; $scope.myModel.searchDate=$scope.currentDate; $scope.checkDate = function (value) { if(value==null || value==undefined){ $scope.search=''; } else{ $scope.filterSearch=$filter('date')(value, 'dd-MM-yyyy'); $scope.search=$scope.filterSearch; } } /* * edit branch details * created by kms * */ $scope.setEditId = function (p,search1,search2,search3,search4,search5) { $scope.searchData = { "searchDate": search1, "searchName": search2, 'serachActivity': search3, 'searchAssignTo': search4, 'searchStatus': search5 } localStorage.setItem('searchObj', JSON.stringify($scope.searchData)); localStorage.setItem('trackID', p.TrackingID); localStorage.setItem('count', 0); $rootScope.followupDetails=p; /* $rootScope.myModel1.status=$rootScope.followupDetails.StatusCode; $rootScope.currentDate1=new Date().getFullYear() + '-' + ('0' + (new Date().getMonth() + 1)).slice(-2) + '-' + ('0' + new Date().getDate()).slice(-2); $rootScope.myModel1.date=$rootScope.followupDetails.followupDetails[0].FollowupOn;*/ /* $scope.editId = pid;*/ $state.go('app.trackingFollowup'); }; /* * Submit,update and reset branch details * @params myModel * created by kms * */ $scope.trackForm = { submit: function (form, myModel,loading) { if(isNaN(myModel.date)){ $scope.nextFollowupDate = myModel.date; } else{ $scope.getdate=new Date(myModel.date).toDateString(); $scope.nextFollowupDate = $filter('date')(new Date($scope.getdate), 'dd-MM-yyyy'); } var firstError = null; if (form.$invalid) { var field = null, firstError = null; for (field in form) { if (field[0] != '$') { if (firstError === null && !form[field].$valid) { firstError = form[field].$name; } if (form[field].$pristine) { form[field].$dirty = true; } } } angular.element('.ng-invalid[name=' + firstError + ']').focus(); // swal("The form cannot be submitted because it contains validation errors!", "Errors are marked with a red, dashed border!", "error"); } else { $scope.ldloading1 = {}; $scope.ldloading1[loading.replace('-', '_')] = true; var addLead = { method: 'POST', url: apiPoint.url + 'addLeadTrackingDetails/', headers: { 'Content-Type': 'application/json' }, data: { studentName: myModel.studentName, mobileNumber: myModel.mobileNumber, universityID: myModel.universityName, courseName: myModel.courseName, date: $scope.nextFollowupDate, activity: myModel.activity.activityID, assignedTo: myModel.assignedTo, status: myModel.status, referedBy: myModel.referedBy, comments:myModel.comments, enquiryStatus:myModel.enquiryStatus, createdBy: JSON.parse(localStorage.getItem('localObj')).localUserID } }; $http(addLead).then(function (response) { if (response.data.status==200 && response.data.leadStatus) { $scope.ldloading1[loading.replace('-', '_')] = false; swal("Success!", response.data.message, "success"); $state.go($state.current, {}, {reload: true}); } else { $scope.ldloading1[loading.replace('-', '_')] = false; swal("Failed!", response.data.message, "error"); } }); } }, reset: function (form) { $scope.myModel = angular.copy($scope.master); form.$setPristine(true); $scope.myModel = { "studentName": "", "mobileNumber": "", "universityName": "", "courseName": "", "activity": "", "assignedTo": "", "status": "", "referedBy": '', "comments":'' }; } }; /* * get student exist or not for add lead details * created by kms * */ $scope.loading=false; $scope.getLead = function (form,mobile) { //call form success if(form.mobilenumber.$valid){ $scope.loading=true; var lead = { method: 'POST', url: apiPoint.url + 'getTrackingLeadDetails/', headers: { 'Content-Type': 'application/json' }, data: { requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID, mobileNumber:mobile } }; $http(lead).then(function (response) { if (response.data.status==200) { $scope.myModel.courseName=response.data.existLeadDetails.CourseID; $scope.myModel.enquiryStatus=response.data.existLeadDetails.IsNewEnquiry; $scope.activity=response.data.activityDetails; $scope.status=response.data.statusDetails; $scope.staffDetails=response.data.staffDetails; //$scope.university=response.data.universityDetails; // $scope.myModel.status=$scope.status[0].ListCode; $scope.myModel.studentName=response.data.existLeadDetails.LeadName; $scope.myModel.universityName=response.data.existLeadDetails.University; $scope.myModel.courseName=response.data.existLeadDetails.Course; // find index for university drop down list /* for(var i in $scope.university) { if($scope.university[i].universityID==response.data.existLeadDetails.UniversityID){ $scope.myModel.universityName=$scope.university[i]; } }*/ $scope.loading=false; } else { $scope.loading=false; } }); } else{ $scope.loading=false; } }; // sorting function for table params $scope.sort = function(keyname){ $scope.sortKey = keyname; //set the sortKey to the param passed $scope.reverse = !$scope.reverse; //if true make it false and vice versa } /* *get tracking list * created by kms * */ $scope.init = function (form,myModel,type) { $scope.loader = true; var getTrackDetails = { method: 'POST', url: apiPoint.url + 'getTrackingDetails/', headers: { 'Content-Type': 'application/json' }, data: { requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID, requestedDept: JSON.parse(localStorage.getItem('localObj')).localType } }; $http(getTrackDetails).then(function (response) { if (response.data.status == 200 && response.data.trackingStatus == true) { $scope.loader = false; $rootScope.trackingStatus = response.data.statusDetails; $scope.data = response.data.trackingDetails; localStorage.setItem('trackingList', JSON.stringify($scope.data)); // this for search box /* $scope.search = {searchDate: ''}; $scope.tableParams = new ngTableParams({ page: 1, count: 10, filter: $scope.search }, { total: data.length, getData: function ($defer, params) { var orderedData = params.sorting() ? $filter('orderBy')(data, params.orderBy()) : data; orderedData = params.filter() ? $filter('filter')(orderedData, params.filter().followupDate) : orderedData; $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count())); } });*/ } else { $scope.loader = false; $scope.branchInfo = ''; $scope.data=''; } }); } }]); app.controller('callTrackingCtrl2', ["$scope","$rootScope","toaster", "$filter", "ngTableParams", "API_POINTS", "$localStorage", "$http", "$state", function ($scope,$rootScope,toaster, $filter, ngTableParams, apiPoint, $localStorage, $http, $state) { $scope.afterRefresh = function () { $rootScope.myModel1 = { "status":'', "date": '', "comments": "", }; $rootScope.loadFollowupDetails(localStorage.getItem('trackID')); }; /* * used to get tracking list * */ $rootScope.next = function(trackID){ $scope.ListOfTracks=JSON.parse(localStorage.getItem('trackingList')); $scope.searchedData=JSON.parse(localStorage.getItem('searchObj')); // search date in array list $scope.searchedTrackingList=[]; if($scope.searchedData.searchDate!='' && $scope.searchedData.searchDate!=null && $scope.searchedData.searchDate!=undefined){ angular.forEach($scope.ListOfTracks,function (value,key) { if((value.followupDetails)==$scope.searchedData.searchDate){ $scope.searchedTrackingList.push(value); } }); } else{ angular.forEach($scope.ListOfTracks,function (value,key) { $scope.searchedTrackingList.push(value); }); } // search name/mobile in array list $scope.searchedTrackingList_Name=[]; if($scope.searchedData.searchName!='' && $scope.searchedData.searchName!=null && $scope.searchedData.searchName!=undefined){ $scope.regInteger = /^\d+$/; if($scope.regInteger.test($scope.searchedData.searchName)){ $scope.searchText = $scope.searchedData.searchName; angular.forEach($scope.searchedTrackingList, function(item) { if( item.MobileNumber.indexOf($scope.searchText) >= 0 ){ $scope.searchedTrackingList_Name.push(item); } }); } else{ $scope.searchText = $scope.searchedData.searchName.toLowerCase(); angular.forEach($scope.searchedTrackingList, function(item) { if( item.LeadName.toLowerCase().indexOf($scope.searchText) >= 0 ){ $scope.searchedTrackingList_Name.push(item); } }); } } else{ angular.forEach($scope.searchedTrackingList,function (value,key) { $scope.searchedTrackingList_Name.push(value); }); } // serach activity in array list $scope.searchedTrackingList_Activity=[]; if($scope.searchedData.serachActivity!='' && $scope.searchedData.serachActivity!=null && $scope.searchedData.serachActivity!=undefined){ $scope.searchText_activity = $scope.searchedData.serachActivity.toLowerCase(); angular.forEach($scope.searchedTrackingList_Name, function(item) { if( item.ActivityName.toLowerCase().indexOf($scope.searchText_activity) >= 0 ){ $scope.searchedTrackingList_Activity.push(item); } }); } else{ angular.forEach($scope.searchedTrackingList_Name,function (value,key) { $scope.searchedTrackingList_Activity.push(value); }); } // serach assigned to in array list $scope.searchedTrackingList_AssignedTo=[]; if($scope.searchedData.searchAssignTo!='' && $scope.searchedData.searchAssignTo!=null && $scope.searchedData.searchAssignTo!=undefined){ $scope.searchText_assignedTo = $scope.searchedData.searchAssignTo.toLowerCase(); angular.forEach($scope.searchedTrackingList_Activity, function(item) { if( item.AssignedTo.toLowerCase().indexOf($scope.searchText_assignedTo) >= 0 ){ $scope.searchedTrackingList_AssignedTo.push(item); } }); } else{ angular.forEach($scope.searchedTrackingList_Activity,function (value,key) { $scope.searchedTrackingList_AssignedTo.push(value); }); } // search status in array list $scope.searchedTrackingList_Status=[]; if($scope.searchedData.searchStatus!='' && $scope.searchedData.searchStatus!=null && $scope.searchedData.searchStatus!=undefined){ $scope.searchText_status = $scope.searchedData.searchStatus.toLowerCase(); angular.forEach($scope.searchedTrackingList_AssignedTo, function(item) { if( item.statusName.toLowerCase().indexOf($scope.searchText_status) >= 0 ){ $scope.searchedTrackingList_Status.push(item); } }); } else{ angular.forEach($scope.searchedTrackingList_AssignedTo,function (value,key) { $scope.searchedTrackingList_Status.push(value); }); } /* * used to move next track list in searched array list * */ angular.forEach($scope.searchedTrackingList_Status,function (value,key) { if(value.TrackingID==trackID){ $scope.nextTrack=$scope.searchedTrackingList_Status[key+1]; if($scope.nextTrack!='' && $scope.nextTrack!=undefined){ $rootScope.loadFollowupDetails($scope.nextTrack.TrackingID); } else{ swal("EMPTY!", "This is an last tracking details.so please go previous", "info"); } } }); } /* * get previous track list in searched array list * */ $rootScope.previous = function(trackID){ $scope.prevListOfTracks=JSON.parse(localStorage.getItem('trackingList')); $scope.prevsearchedData=JSON.parse(localStorage.getItem('searchObj')); // search date in array list $scope.prevsearchedTrackingList=[]; if($scope.prevsearchedData.searchDate!='' && $scope.prevsearchedData.searchDate!=null && $scope.prevsearchedData.searchDate!=undefined){ angular.forEach($scope.prevListOfTracks,function (value,key) { if((value.followupDetails)==$scope.prevsearchedData.searchDate){ $scope.prevsearchedTrackingList.push(value); } }); } else{ angular.forEach($scope.prevListOfTracks,function (value,key) { $scope.prevsearchedTrackingList.push(value); }); } // search name/mobile in array list $scope.prevsearchedTrackingList_Name=[]; if($scope.prevsearchedData.searchName!='' && $scope.prevsearchedData.searchName!=null && $scope.prevsearchedData.searchName!=undefined){ $scope.prevregInteger = /^\d+$/; if($scope.prevregInteger.test($scope.prevsearchedData.searchName)){ $scope.prevsearchText = $scope.prevsearchedData.searchName; angular.forEach($scope.prevsearchedTrackingList, function(item) { if( item.MobileNumber.indexOf($scope.prevsearchText) >= 0 ){ $scope.prevsearchedTrackingList_Name.push(item); } }); } else{ $scope.prevsearchText = $scope.prevsearchedData.searchName.toLowerCase(); angular.forEach($scope.prevsearchedTrackingList, function(item) { if( item.LeadName.toLowerCase().indexOf($scope.prevsearchText) >= 0 ){ $scope.prevsearchedTrackingList_Name.push(item); } }); } } else{ angular.forEach($scope.prevsearchedTrackingList,function (value,key) { $scope.prevsearchedTrackingList_Name.push(value); }); } // serach activity in array list $scope.prevsearchedTrackingList_Activity=[]; if($scope.prevsearchedData.serachActivity!='' && $scope.prevsearchedData.serachActivity!=null && $scope.prevsearchedData.serachActivity!=undefined){ $scope.prevsearchText_activity = $scope.prevsearchedData.serachActivity.toLowerCase(); angular.forEach($scope.prevsearchedTrackingList_Name, function(item) { if( item.ActivityName.toLowerCase().indexOf($scope.prevsearchText_activity) >= 0 ){ $scope.prevsearchedTrackingList_Activity.push(item); } }); } else{ angular.forEach($scope.prevsearchedTrackingList_Name,function (value,key) { $scope.prevsearchedTrackingList_Activity.push(value); }); } // serach assigned to in array list $scope.prevsearchedTrackingList_AssignedTo=[]; if($scope.prevsearchedData.searchAssignTo!='' && $scope.prevsearchedData.searchAssignTo!=null && $scope.prevsearchedData.searchAssignTo!=undefined){ $scope.prevsearchText_assignedTo = $scope.prevsearchedData.searchAssignTo.toLowerCase(); angular.forEach($scope.prevsearchedTrackingList_Activity, function(item) { if( item.AssignedTo.toLowerCase().indexOf($scope.prevsearchText_assignedTo) >= 0 ){ $scope.prevsearchedTrackingList_AssignedTo.push(item); } }); } else{ angular.forEach($scope.prevsearchedTrackingList_Activity,function (value,key) { $scope.prevsearchedTrackingList_AssignedTo.push(value); }); } // search status in array list $scope.prevsearchedTrackingList_Status=[]; if($scope.prevsearchedData.searchStatus!='' && $scope.prevsearchedData.searchStatus!=null && $scope.prevsearchedData.searchStatus!=undefined){ $scope.prevsearchText_status = $scope.prevsearchedData.searchStatus.toLowerCase(); angular.forEach($scope.prevsearchedTrackingList_AssignedTo, function(item) { if( item.statusName.toLowerCase().indexOf($scope.prevsearchText_status) >= 0 ){ $scope.prevsearchedTrackingList_Status.push(item); } }); } else{ angular.forEach($scope.prevsearchedTrackingList_AssignedTo,function (value,key) { $scope.prevsearchedTrackingList_Status.push(value); }); } /* * final previous * result * */ angular.forEach($scope.prevsearchedTrackingList_Status,function (value,key) { if(value.TrackingID==trackID){ $scope.prevTrack=$scope.prevsearchedTrackingList_Status[key-1]; if($scope.prevTrack!='' && $scope.prevTrack!=undefined){ $rootScope.loadFollowupDetails($scope.prevTrack.TrackingID); } else{ swal("EMPTY!", "This is an last tracking details.so please go next", "info"); } } }); } /* * update the follow up details * created by kms * */ $rootScope.updateFollowup = function (followupDetails,myModel1, loading) { if(isNaN(myModel1.date)){ $scope.nextFollowupDate = myModel1.date; } else{ $scope.getdate=new Date(myModel1.date).toDateString(); $scope.nextFollowupDate = $filter('date')(new Date($scope.getdate), 'dd-MM-yyyy'); } if(myModel1.status==null || myModel1.status=='' || myModel1.status==undefined){ swal("Warning!", 'Please select status', "warning"); } else if (myModel1.comments=='') { swal("Warning!", 'Please enter comments', "warning"); } else { $rootScope.ldloading2 = {}; $rootScope.ldloading2[loading.replace('-', '_')] = true; var update = { method: 'POST', url: apiPoint.url + 'updateFollowupDetails/', headers: { 'Content-Type': 'application/json' }, data: { trackingID: followupDetails.TrackingID, date: $scope.nextFollowupDate, status: myModel1.status, comments: myModel1.comments, updatedBy: JSON.parse(localStorage.getItem('localObj')).localUserID } }; $http(update).then(function (response) { if (response.data.status==200 && response.data.followupStatus) { $rootScope.loadFollowupDetails(response.data.trackingID); $scope.ldloading2[loading.replace('-', '_')] = false; $rootScope.myModel1.comments=''; } else { $scope.ldloading[loading.replace('-', '_')] = false; swal("Failed!", response.data.message, "error"); } }); } }; $rootScope.loadFollowupDetails = function (trackID) { var load = { method: 'POST', url: apiPoint.url + 'loadFollowupDetails/', headers: { 'Content-Type': 'application/json' }, data: { trackingID: trackID, updatedBy: JSON.parse(localStorage.getItem('localObj')).localUserID } }; $http(load).then(function (response) { if (response.data.status==200 && response.data.followupStatus) { $rootScope.followupDetails=response.data.trackingDetails[0]; $rootScope.myModel1.status=$rootScope.followupDetails.StatusCode; $rootScope.currentDate1=new Date().getFullYear() + '-' + ('0' + (new Date().getMonth() + 1)).slice(-2) + '-' + ('0' + new Date().getDate()).slice(-2); $rootScope.myModel1.date=$rootScope.followupDetails.followupDetails[0].FollowupOn; // get 30 plus date for follwup details $rootScope.modifyDate1 = moment(); $rootScope.modifyDate1.add(30, 'days'); $rootScope.futureDate1 = $filter('date')($scope.modifyDate1, 'dd-MM-yyyy'); $rootScope.myModel1.status=$rootScope.followupDetails.StatusCode; $rootScope.trackingStatus=response.data.statusDetails; } else { swal("Failed!", response.data.message, "error"); } }); } /* * cancel the page * created by kms * */ $scope.cancel = function () { $state.go('app.tracking'); }; }]);