apollodec/Apollo/assets/js/controllers/callTrackingCtrl.js
2018-01-06 19:43:49 +05:30

1296 lines
44 KiB
JavaScript
Executable File

'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":'',
"alterMobileNumber":'',
"address":''
};
//get current date
$scope.hideDateSearch=true;
$scope.modifyMinDate = moment();
$scope.minDate = $filter('date')($scope.modifyMinDate, 'MM-dd-yyyy');
$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.myModel.search=$filter('date')(new Date(), 'yyyy-MM-dd');
$scope.myModel.searchDate=$scope.currentDate;
$scope.toMinDate = $filter('date')($scope.modifyMinDate, 'MM-dd-yyyy');
$scope.checkDate = function (value,type) {
if(value.searchDate==null || value.searchDate==undefined){
$scope.myModel.search='';
$scope.toMinDate = '';
$scope.myModel.dateTo='';
}
else{
if(type=='2'){
$scope.myModel.search = $filter('date')(value.searchDate, 'yyyy-MM-dd');
$scope.toMinDate = $filter('date')(value.searchDate, 'MM-dd-yyyy');
}
}
$scope.searchDateArray(value);
}
/*
* check to date
* */
$scope.checkToDate = function (value) {
if(value.searchDate==null || value.searchDate==undefined){
swal("Failed!", 'Please Select From Date', "error");
$scope.myModel.dateTo='';
$scope.myModel.search='';
$scope.toMinDate = '';
}
else{
$scope.filterSearch=$filter('date')(value.searchDate, 'dd-MM-yyyy');
$scope.search=$scope.filterSearch;
}
$scope.searchDateArray(value);
}
/*
* make a search date array
*/
$scope.searchDateArray=function (dateValue) {
var listDate = [];
if((dateValue.search !=null && dateValue.search !=undefined) && (dateValue.dateTo !=null && dateValue.dateTo !=undefined && dateValue.dateTo !='')){
var startDate =dateValue.search;
var endDate = $filter('date')(dateValue.dateTo, 'yyyy-MM-dd');
var dateMove = new Date(startDate);
var strDate = startDate;
if(strDate == endDate){
var startDate =dateValue.search;
// var endDate = $filter('date')(dateValue.searchDate, 'yyyy-MM-dd');
var strDate = startDate;
var arrayDate = $filter('date')(strDate, 'dd-MM-yyyy');
listDate.push(arrayDate);
}
else{
while (strDate < endDate){
var strDate = dateMove.toISOString().slice(0,10);
var arrayDate = $filter('date')(strDate, 'dd-MM-yyyy');
listDate.push(arrayDate);
dateMove.setDate(dateMove.getDate()+1);
};
}
}
else if((dateValue.search !=null && dateValue.search !=undefined) && (dateValue.dateTo ==null || dateValue.dateTo ==undefined || dateValue.dateTo =='')){
var startDate =dateValue.search;
// var endDate = $filter('date')(dateValue.searchDate, 'yyyy-MM-dd');
var strDate = startDate;
var arrayDate = $filter('date')(strDate, 'dd-MM-yyyy');
listDate.push(arrayDate);
}
$scope.init(listDate);
}
/*
* edit track 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,
'callFrom':"details"
}
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.call.trackingFollowup');
};
/*
* Submit,update and reset track 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,
alterMobile:myModel.alterMobileNumber,
address:myModel.address,
enquiryStatus:myModel.enquiryStatus,
createdBy: JSON.parse(localStorage.getItem('localObj')).localUserID,
branchId: JSON.parse(localStorage.getItem('localObj')).localBranchID
}
};
$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;
$scope.myModel.alterMobileNumber=response.data.existLeadDetails.AlternateMobile;
$scope.myModel.address=response.data.existLeadDetails.Address;
// 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;
}
};
/*
*get tracking list
* created by kms
* */
$scope.init = function (myModel) {
$scope.data = [];
if(myModel!='' && myModel!=undefined){
$scope.finalSearchArry=myModel;
}
else{
$scope.finalSearchArry="";
}
$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,
branchId: JSON.parse(localStorage.getItem('localObj')).localBranchID,
searchDate: $scope.finalSearchArry
}
};
$http(getTrackDetails).then(function (response) {
if(response.data.pendingTrackingDetails.trackingStatus && response.data.trackingDetails.length > 0){
$scope.loader = false;
//$scope.currentDate1=$filter('date')(new Date(), 'dd-MM-yyyy');
$scope.tillPendingDetails = response.data.pendingTrackingDetails.trackingDetails;
angular.forEach($scope.tillPendingDetails, function (value, key) {
$scope.currentDate = new Date().getFullYear() + '-' + ('0' + (new Date().getMonth() + 1)).slice(-2) + '-' + ('0' + new Date().getDate()).slice(-2);
// $scope.currentDate = new Date().getFullYear() + '-' + ('0' + (new Date().getMonth() + 1)).slice(-2) + '-' + ('0' + new Date().getDate()).slice(-2);
$scope.currentDate=$filter('date')(new Date(), 'dd-MM-yyyy');
if (($scope.currentDate) > (value.followupDetails) && (value.statusName!='CLOSE')) {
$scope.data.push(value);
}
});
angular.forEach(response.data.trackingDetails, function (value1, key1) {
$scope.data.push(value1);
});
$rootScope.trackingStatus = response.data.statusDetails;
localStorage.setItem('trackingList', JSON.stringify($scope.data));
}
else if (response.data.status == 200 && response.data.trackingStatus == true && response.data.pendingTrackingDetails.trackingStatus !=true) {
$scope.loader = false;
$rootScope.trackingStatus = response.data.statusDetails;
$scope.data = response.data.trackingDetails;
localStorage.setItem('trackingList', JSON.stringify($scope.data));
}
else if (response.data.trackingStatus != true && response.data.pendingTrackingDetails.trackingStatus) {
$scope.loader = false;
$rootScope.trackingStatus = response.data.statusDetails;
$scope.tillPendingDetails = response.data.pendingTrackingDetails.trackingDetails;
angular.forEach($scope.tillPendingDetails, function (value, key) {
$scope.currentDate = new Date().getFullYear() + '-' + ('0' + (new Date().getMonth() + 1)).slice(-2) + '-' + ('0' + new Date().getDate()).slice(-2);
// $scope.currentDate = new Date().getFullYear() + '-' + ('0' + (new Date().getMonth() + 1)).slice(-2) + '-' + ('0' + new Date().getDate()).slice(-2);
$scope.currentDate=$filter('date')(new Date(), 'dd-MM-yyyy');
if (($scope.currentDate) > (value.followupDetails) && (value.statusName!='CLOSE')) {
$scope.data.push(value);
}
});
localStorage.setItem('trackingList', JSON.stringify($scope.data));
}
else {
$scope.loader = false;
$scope.branchInfo = '';
$scope.data='';
}
});
}
// 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
}
}]);
/*
* lead controller
* */
app.controller('callTrackingLeadCtrl', ["$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 = {
"leadDate": new Date(),
};
//get current date
$scope.currentDate=$filter('date')(new Date(), 'dd-MM-yyyy');
$scope.maxDate=moment();
// 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.leadDate=$scope.currentDate;
/*
* edit track 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,
'callFrom': "lead"
}
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.call.trackingFollowup');
};
// 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) {
if(isNaN(myModel.leadDate)){
$scope.loadDate= $filter('date')(new Date(), 'yyyy-MM-dd');
}
else if(myModel.leadDate==null || myModel.leadDate==''){
$scope.loadDate="";
}
else{
$scope.getdate=new Date(myModel.leadDate).toDateString();
$scope.loadDate = $filter('date')(new Date($scope.getdate), 'yyyy-MM-dd');
}
$scope.loader = true;
var getRecentlead = {
method: 'POST',
url: apiPoint.url + 'getRecentLeadDetails/',
headers: {
'Content-Type': 'application/json'
},
data: {
loadDate:$scope.loadDate,
requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID,
requestedDept: JSON.parse(localStorage.getItem('localObj')).localType,
branchId: JSON.parse(localStorage.getItem('localObj')).localBranchID
}
};
$http(getRecentlead).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.data='';
}
});
}
}]);
/*
* close tracking controller
* */
app.controller('callTrackingCloseCtrl', ["$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 = {
"closeDate": new Date(),
};
//get current date
$scope.currentDate=$filter('date')(new Date(), 'dd-MM-yyyy');
$scope.maxDate=moment();
// 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.closeDate=$scope.currentDate;
/*
* edit track 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,
'callFrom': "close"
}
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.call.trackingFollowup');
};
// 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) {
if(isNaN(myModel.closeDate)){
$scope.loadDate= $filter('date')(new Date(), 'yyyy-MM-dd');
}
else if(myModel.closeDate==null || myModel.closeDate==''){
$scope.loadDate="";
}
else{
$scope.getdate=new Date(myModel.closeDate).toDateString();
$scope.loadDate = $filter('date')(new Date($scope.getdate), 'yyyy-MM-dd');
}
$scope.loader = true;
var getRecentclose = {
method: 'POST',
url: apiPoint.url + 'getRecentCloseDetails/',
headers: {
'Content-Type': 'application/json'
},
data: {
loadDate:$scope.loadDate,
requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID,
requestedDept: JSON.parse(localStorage.getItem('localObj')).localType,
branchId: JSON.parse(localStorage.getItem('localObj')).localBranchID
}
};
$http(getRecentclose).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.data='';
}
});
}
}]);
/*
* pending tracking controller
* */
app.controller('callTrackingPendingCtrl', ["$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 = {
"pendingDate": new Date(),
};
//get current date
$scope.currentDate=$filter('date')(new Date(), 'dd-MM-yyyy');
$scope.maxDate=moment();
// 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.pendingDate=$scope.currentDate;
/*
* edit track 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,
'callFrom': "pending"
}
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.call.trackingFollowup');
};
// 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) {
if(isNaN(myModel.pendingDate)){
$scope.loadDate= $filter('date')(new Date(), 'yyyy-MM-dd');
}
else if(myModel.pendingDate==null || myModel.pendingDate==''){
$scope.loadDate="";
}
else{
$scope.getdate=new Date(myModel.pendingDate).toDateString();
$scope.loadDate = $filter('date')(new Date($scope.getdate), 'yyyy-MM-dd');
}
$scope.loader = true;
var getRecentclose = {
method: 'POST',
url: apiPoint.url + 'getRecentPendingDetails/',
headers: {
'Content-Type': 'application/json'
},
data: {
loadDate:$scope.loadDate,
requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID,
requestedDept: JSON.parse(localStorage.getItem('localObj')).localType,
branchId: JSON.parse(localStorage.getItem('localObj')).localBranchID
}
};
$http(getRecentclose).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.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.Firstname.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!", "No more records to display", "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.Firstname.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!", "No more records to display", "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,
branchId: JSON.parse(localStorage.getItem('localObj')).localBranchID,
}
};
$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,
branchId: JSON.parse(localStorage.getItem('localObj')).localBranchID
}
};
$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 () {
if(JSON.parse(localStorage.getItem('searchObj')).callFrom=='details'){
$state.go('app.call.tracking');
}
else if(JSON.parse(localStorage.getItem('searchObj')).callFrom=='lead'){
$state.go('app.call.lead');
}
else if(JSON.parse(localStorage.getItem('searchObj')).callFrom=='close'){
$state.go('app.call.close');
}
else if(JSON.parse(localStorage.getItem('searchObj')).callFrom=='pending'){
$state.go('app.call.pending');
}
else{
$state.go('app.call.tracking');
}
};
}]);
app.filter('unique', function() {
return function(collection, primaryKey, secondaryKey) { //optional secondary key
var output = [],
keys = [];
angular.forEach(collection, function(item) {
var key;
secondaryKey === undefined ? key = item[primaryKey] : key = item[primaryKey][secondaryKey];
if(keys.indexOf(key) === -1) {
keys.push(key);
output.push(item);
}
});
return output;
};
});