diff --git a/Apollo/assets/js/controllers/callTrackingCtrl.js b/Apollo/assets/js/controllers/callTrackingCtrl.js index 16e5f0f6..0fff435d 100755 --- a/Apollo/assets/js/controllers/callTrackingCtrl.js +++ b/Apollo/assets/js/controllers/callTrackingCtrl.js @@ -24,26 +24,101 @@ app.controller('callTrackingCtrl', ["$scope","$rootScope","toaster", "$filter", //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.search=$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) { - if(value==null || value==undefined){ - $scope.search=''; + + $scope.checkDate = function (value,type) { + if(value.searchDate==null || value.searchDate==undefined){ + + $scope.myModel.search=''; + $scope.toMinDate = ''; + $scope.myModel.dateTo=''; } else{ - $scope.filterSearch=$filter('date')(value, 'dd-MM-yyyy'); + 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); + } /* @@ -133,8 +208,8 @@ app.controller('callTrackingCtrl', ["$scope","$rootScope","toaster", "$filter", alterMobile:myModel.alterMobileNumber, address:myModel.address, enquiryStatus:myModel.enquiryStatus, - createdBy: JSON.parse(localStorage.getItem('localObj')).localUserID - + createdBy: JSON.parse(localStorage.getItem('localObj')).localUserID, + branchId: JSON.parse(localStorage.getItem('localObj')).localBranchID @@ -234,19 +309,22 @@ app.controller('callTrackingCtrl', ["$scope","$rootScope","toaster", "$filter", }; - // 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.init = function (myModel) { + $scope.data = []; + if(myModel!='' && myModel!=undefined){ + $scope.finalSearchArry=myModel; + } + else{ + $scope.finalSearchArry=""; + } + $scope.loader = true; var getTrackDetails = { @@ -257,12 +335,44 @@ app.controller('callTrackingCtrl', ["$scope","$rootScope","toaster", "$filter", }, data: { requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID, - requestedDept: JSON.parse(localStorage.getItem('localObj')).localType + 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); + } - if (response.data.status == 200 && response.data.trackingStatus == true) { + + + }); + + 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; @@ -270,33 +380,46 @@ app.controller('callTrackingCtrl', ["$scope","$rootScope","toaster", "$filter", $scope.data = response.data.trackingDetails; localStorage.setItem('trackingList', JSON.stringify($scope.data)); + } + else if (response.data.trackingStatus != true && response.data.pendingTrackingDetails.trackingStatus) { - // 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())); - } - });*/ + $scope.loader = false; + $rootScope.trackingStatus = response.data.statusDetails; - } else { + $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 + + } @@ -389,7 +512,8 @@ app.controller('callTrackingLeadCtrl', ["$scope","$rootScope","toaster", "$filte data: { loadDate:$scope.loadDate, requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID, - requestedDept: JSON.parse(localStorage.getItem('localObj')).localType + requestedDept: JSON.parse(localStorage.getItem('localObj')).localType, + branchId: JSON.parse(localStorage.getItem('localObj')).localBranchID } }; $http(getRecentlead).then(function (response) { @@ -515,7 +639,9 @@ app.controller('callTrackingCloseCtrl', ["$scope","$rootScope","toaster", "$filt data: { loadDate:$scope.loadDate, requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID, - requestedDept: JSON.parse(localStorage.getItem('localObj')).localType + requestedDept: JSON.parse(localStorage.getItem('localObj')).localType, + branchId: JSON.parse(localStorage.getItem('localObj')).localBranchID + } }; $http(getRecentclose).then(function (response) { @@ -641,7 +767,8 @@ app.controller('callTrackingPendingCtrl', ["$scope","$rootScope","toaster", "$fi data: { loadDate:$scope.loadDate, requestedBy: JSON.parse(localStorage.getItem('localObj')).localUserID, - requestedDept: JSON.parse(localStorage.getItem('localObj')).localType + requestedDept: JSON.parse(localStorage.getItem('localObj')).localType, + branchId: JSON.parse(localStorage.getItem('localObj')).localBranchID } }; $http(getRecentclose).then(function (response) { @@ -671,7 +798,9 @@ app.controller('callTrackingPendingCtrl', ["$scope","$rootScope","toaster", "$fi });*/ - } else { + } + + else { $scope.loader = false; $scope.data=''; @@ -1062,7 +1191,8 @@ app.controller('callTrackingCtrl2', ["$scope","$rootScope","toaster", "$filter", date: $scope.nextFollowupDate, status: myModel1.status, comments: myModel1.comments, - updatedBy: JSON.parse(localStorage.getItem('localObj')).localUserID + updatedBy: JSON.parse(localStorage.getItem('localObj')).localUserID, + branchId: JSON.parse(localStorage.getItem('localObj')).localBranchID, } }; $http(update).then(function (response) { @@ -1088,7 +1218,9 @@ app.controller('callTrackingCtrl2', ["$scope","$rootScope","toaster", "$filter", }, data: { trackingID: trackID, - updatedBy: JSON.parse(localStorage.getItem('localObj')).localUserID + updatedBy: JSON.parse(localStorage.getItem('localObj')).localUserID, + branchId: JSON.parse(localStorage.getItem('localObj')).localBranchID + } }; $http(load).then(function (response) { @@ -1139,6 +1271,24 @@ app.controller('callTrackingCtrl2', ["$scope","$rootScope","toaster", "$filter", }]); +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; + }; +});