define(['app'], function (app) {
app.controller('UserRegistrationCtrl', function ($scope, $rootScope, AppData, $location) {
$rootScope.menucont = true;
$rootScope.pageLoadComp = false;
$scope.formLoad = false;
$scope.listFound = false;
$scope.pageData = registrationData[$rootScope.selLanguage];
$scope.submenu = $scope.pageData.sidemenu;
$scope.url = "../senddata/log/";
$scope.pageurl = "../senddata/report/";
$scope.exporturl = "../senddata/reportdownload/";
$scope.commonurl = "../senddata/common/";
$scope.userurl = "../senddata/user/";
$rootScope.sideselect = $scope.pageData.sidemenu[0];
//Check Session//
$scope.formData = {}
$rootScope.formData = {}
$scope.dseInactive=false;
$scope.remarkslist=[];
$scope.currentDate = moment().format("YYYY-MM-DD");
console.log($scope.currentDate)
$scope.startingDate = moment().startOf('month').format('YYYY-MM-DD');
$scope.startingMonth = moment().startOf('month').format('MMMM YYYY');
$scope.totalremarkscount=0;
//pagination
$scope.viewby = '10';
$scope.currentPage = 1;
$scope.itemsPerPage = $scope.viewby;
$scope.maxSize = 5; //Number of pager buttons to show
//Check Session//
$scope.formData.ismenuload = "Yes";
if ($rootScope.items == undefined || $rootScope.items == null) {
$scope.formData.ismenuload = "No";
}
$scope.formData.funName = "checksession";
$scope.formData.lang = $rootScope.selLanguage;
$scope.formData.start = 2;
$scope.formData.limit = 5;
console.log($scope.startingMonth)
$scope.formData.ismenuload = "Yes";
if ($rootScope.items == undefined || $rootScope.items == null) {
$scope.formData.ismenuload = "No";
}
$scope.formData.funName = "checksession";
$scope.formData.lang = $rootScope.selLanguage;
$scope.formData.start = 0;
$scope.formData.limit = 2;
AppData.sendData($scope.url, $scope.formData, function (res) {
if (res.cont) {
if ($rootScope.items == undefined || $rootScope.items == null) {
$rootScope.items = res.item.control;
}
if ($rootScope.items != undefined) {
for (var i = 0; i < $rootScope.items.length; i++) {
if ($location.path() == $rootScope.items[i].modulepath) {
$rootScope.modulename = $rootScope.items[i].modulename;
$scope.usercontrol = String($rootScope.items[i].permission).split("|");
}
}
}
angular.element(document.querySelector('.table_area')).bind('scroll', function () {
$('.datepicker').datepicker("hide")
})
// $scope.getZm();
$scope.listClick($scope.submenu[0])
console.log($rootScope.sideselect.id)
} else {
$location.path("/login");
}
})
$scope.listClick = function (obj) {
console.log(obj.id)
$scope.formData = {}
// $scope.currentPage = 1;
$rootScope.sideselect = obj;
$rootScope.sideselect.name = obj.name;
if (obj.id == 1) {
// $("").appendTo( 'head' );
} else if (obj.id == 2) {
$scope.formData = {};
// $("").appendTo( 'head' );
$scope.selectTab('1')
}
$scope.getZm();
}
///////////// Zone Data /////////////////
$scope.getZm = function () {
$scope.formData = {};
$scope.dseInactive=false;
$scope.formData.datetype = '4';
$scope.formData.from_month = $scope.startingMonth
$scope.formData.regtype = '1';
console.log($scope.formData)
if ($scope.formData.datetype == '1' || $scope.formData.datetype == '2' || $scope.formData.datetype == '3' || $scope.formData.datetype == '4') {
$scope.formData.from_date = '';
$scope.formData.to_date = '';
} else {
$scope.formData.from_date = $scope.startingDate;
$scope.formData.to_date = $scope.currentDate;
}
$scope.formData.zm_email = "all";
$scope.rmInactive = true;
$scope.amInactive = true;
var zobj = {};
zobj.funName = "zmlist";
zobj.lang = $rootScope.selLanguage;
AppData.sendData($scope.commonurl, zobj, function (res) {
console.log(res)
$scope.zmuser_list = res.item;
$scope.zmChange()
})
}
$scope.zmChange = function () {
$scope.dseInactive=false;
$scope.dealerInactive=true;
console.log($scope.formData.zm_email)
$scope.formData.rm_email = "all";
$scope.formData.am_email = "all";
if ($scope.formData.zm_email == "all") {
$scope.rmInactive = true;
$scope.amInactive = true;
if ($rootScope.sideselect.id == 1) {
$scope.userRegistrationData()
$scope.userRegistrationList()
} else if ($rootScope.sideselect.id == 2) {
$scope.userActivationData()
} else if ($rootScope.sideselect.id == 3) {
$scope.userInactiveRegistrationData()
$scope.userInactiveRegistrationList()
}
} else {
$scope.rmInactive = false;
$scope.amInactive = true;
$scope.getRm();
}
}
///////////// Regional Data //////////////
$scope.getRm = function () {
$scope.dseInactive=false;
$scope.formData.rm_email = "all";
var robj = {};
robj.funName = "rmlist";
robj.lang = $rootScope.selLanguage;
robj.zm_email = $scope.formData.zm_email;
AppData.sendData($scope.commonurl, robj, function (res) {
console.log(res)
$scope.rmuser_list = res.item;
$scope.rmChange()
})
}
$scope.rmChange = function () {
$scope.dseInactive=false;
$scope.dealerInactive=true;
$scope.formData.am_email = "all"
$scope.formData.dealer_code = "";
if ($scope.formData.rm_email == "all") {
$scope.amInactive = true;
if ($rootScope.sideselect.id == 1) {
$scope.userRegistrationData()
$scope.userRegistrationList()
} else if ($rootScope.sideselect.id == 2) {
$scope.userActivationData()
} else if ($rootScope.sideselect.id == 3) {
$scope.userInactiveRegistrationData()
$scope.userInactiveRegistrationList()
}
} else {
// alert($scope.formData.rm_email)
$scope.amInactive = false;
if ($rootScope.sideselect.id == 1) {
$scope.userRegistrationData()
$scope.userRegistrationList()
} else if ($rootScope.sideselect.id == 2) {
$scope.userActivationData()
} else if ($rootScope.sideselect.id == 3) {
$scope.userInactiveRegistrationData()
$scope.userInactiveRegistrationList()
}
$scope.getAm();
}
}
//////////// Area Manager Data ///////////////////
$scope.getAm = function () {
$scope.dseInactive=false;
var aobj = {};
aobj.funName = "amlist";
aobj.lang = $rootScope.selLanguage;
aobj.rm_email = $scope.formData.rm_email;
AppData.sendData($scope.commonurl, aobj, function (res) {
console.log(res)
$scope.amuser_list = res.item;
// $scope.amChange()
})
}
$scope.amChange = function () {
$scope.dseInactive=false;
$scope.dealerInactive=true;
if ($rootScope.sideselect.id == 1) {
$scope.userRegistrationData()
$scope.userRegistrationList()
} else if ($rootScope.sideselect.id == 2) {
$scope.userActivationData()
} else if ($rootScope.sideselect.id == 3) {
$scope.userInactiveRegistrationData()
$scope.userInactiveRegistrationList()
}
$scope.getDealer()
}
$scope.chartData = function () {
$scope.userRegistrationData()
$scope.userRegistrationList();
}
$scope.inactiveChartData = function () {
$scope.userInactiveRegistrationData()
$scope.userInactiveRegistrationList();
}
$scope.userRegistrationList = function () {
var obj = {};
// obj.funName = "user_registration_percent";
obj.funName = "user_registration_percent_v2";
obj.zm_email = $scope.formData.zm_email;
obj.rm_email = $scope.formData.rm_email;
obj.am_email = $scope.formData.am_email;
obj.from_date = $scope.formData.from_date;
obj.to_date = $scope.formData.to_date;
obj.regtype = $scope.formData.regtype;
obj.datetype = $scope.formData.datetype;
AppData.sendData($scope.pageurl, obj, function (res) {
if (res.cont) {
console.log(res.item)
$scope.userPercentList = res.item;
} else {
$scope.userPercentList = []
}
})
}
$scope.userInactiveRegistrationList = function () {
// alert("initialized-->"+$scope.currentPage)
var obj = {};
$scope.searchvalue = ($scope.formData.mymodel != '') ? $scope.formData.mymodel : "";
obj.funName = "inactive_user_registration_list";
obj.zm_email = $scope.formData.zm_email;
obj.rm_email = $scope.formData.rm_email;
obj.am_email = $scope.formData.am_email;
obj.from_date = $scope.formData.from_date;
obj.to_date = $scope.formData.to_date;
obj.regtype = $scope.formData.regtype
obj.lang = $rootScope.selLanguage;
obj.pn = $scope.currentPage;
obj.nr = $scope.itemsPerPage;
obj.key = $scope.searchvalue
AppData.sendData($scope.pageurl, obj, function (res) {
if (res.cont) {
console.log(res.item)
$scope.userPercentList = res.item;
$scope.totalItems = res.item.total_records;
$scope.listFound = true;
$scope.search_box = true;
}else{
$scope.listFound = false;
$scope.errorMsg = res.mess;
}
})
$scope.pageChanged = function(tempval) {
$scope.currentPage=tempval
console.log('Page changed to: ' + $scope.currentPage);
$scope.userInactiveRegistrationList();
};
$scope.filterData = function() {
console.log($scope.searchtext)
$scope.userInactiveRegistrationList();
}
}
$scope.onSearchChange = function () {
console.log($scope.formData.mymodel)
$scope.userInactiveRegistrationList();
}
$scope.selectStatus = function () {
$scope.userRegistrationData();
$scope.userRegistrationList();
}
$scope.selectInActiveStatus = function () {
$scope.userInactiveRegistrationList()
// $scope.userRegistrationData();
// $scope.userRegistrationList();
}
$scope.selectActiveStatus = function () {
$scope.userActivationData();
}
//////////////// User Registration Report ////////////////////
$scope.userRegistrationData = function () {
$scope.userLabel = [];
$scope.userValue = [];
// $scope.formData.status = [];
$scope.formData.funName = "user_registration";
// $scope.formData.from_date = $scope.formData.fromDate;
// $scope.formData.to_date = $scope.formData.toDate;
AppData.sendData($scope.pageurl, $scope.formData, function (res) {
if (res.cont) {
console.log(res.item)
$scope.userReport = res.item;
$rootScope.modulename = 'report';
for (var i = 0; i < $scope.userReport.value.length; i++) {
$scope.userLabel.push($scope.userReport.value[i].title)
$scope.userValue.push(Number($scope.userReport.value[i].value))
}
console.log($scope.userLabel)
console.log($scope.userValue)
var showChart;
if (Math.max(...$scope.userValue) == 0) {
console.log('false')
showChart = false;
$('.inner-container').html('');
$('.inner-container').html("
No data found
");
} else {
showChart = true;
$scope.areaChart();
}
} else {
$scope.userReport = [];
$('.inner-container').html('');
$('.inner-container').html("No data found
");
}
})
}
//////////////// User Registration Report ////////////////////
$scope.userInactiveRegistrationData = function () {
$scope.userLabel = [];
$scope.userValue = [];
$scope.formData.funName = "inactive_user_registration";
// $scope.formData.from_date = $scope.formData.fromDate;
// $scope.formData.to_date = $scope.formData.toDate;
AppData.sendData($scope.pageurl, $scope.formData, function (res) {
if (res.cont) {
console.log(res.item)
$scope.userReport = res.item;
$rootScope.modulename = 'report';
for (var i = 0; i < $scope.userReport.value.length; i++) {
$scope.userLabel.push($scope.userReport.value[i].title)
$scope.userValue.push(Number($scope.userReport.value[i].value))
}
console.log($scope.userLabel)
console.log($scope.userValue)
var showChart;
if (Math.max(...$scope.userValue) == 0) {
console.log('false')
showChart = false;
$('.inner-container').html('');
$('.inner-container').html("No data found
");
} else {
showChart = true;
$scope.areaChart();
}
} else {
$scope.userReport = [];
$('.inner-container').html('');
$('.inner-container').html("No data found
");
}
})
}
$scope.areaChart = function () {
var maxValue = 0;
if (Math.max.apply(Math, $scope.userValue) == 0) {
maxValue += 10
} else {
maxValue += Math.max.apply(Math, $scope.userValue) + 1;
}
console.log(maxValue)
$('.inner-container').html('');
$('.inner-container').html('');
var ctx = document.getElementById('registrationChart').getContext("2d");
Chart.defaults.global.legend.display = true;
var gradientStroke = ctx.createLinearGradient(500, 0, 100, 0);
gradientStroke.addColorStop(0, '#80b6f4');
gradientStroke.addColorStop(1, '#f49080');
var gradientFill = ctx.createLinearGradient(500, 0, 100, 0);
gradientFill.addColorStop(0, "rgba(128, 182, 244, 0.6)");
gradientFill.addColorStop(1, "rgba(244, 144, 128, 0.6)");
var registrationChart = new Chart(ctx, {
type: 'line',
data: {
labels: $scope.userLabel,
datasets: [{
label: "User Registration",
borderColor: gradientStroke,
pointBorderColor: gradientStroke,
pointBackgroundColor: gradientStroke,
pointHoverBackgroundColor: gradientStroke,
pointHoverBorderColor: gradientStroke,
pointBorderWidth: 10,
pointHoverRadius: 10,
pointHoverBorderWidth: 1,
pointRadius: 3,
fill: true,
backgroundColor: gradientFill,
borderWidth: 4,
scaleStartValue: 0,
data: $scope.userValue
}]
},
options: {
beginAtZero: true,
legend: {
position: "bottom"
},
scales: {
yAxes: [{
ticks: {
min: 0,
suggestedMin: 0,
fontColor: "rgba(0,0,0,0.5)",
fontStyle: "bold",
maxTicksLimit: 5,
padding: 20,
max: maxValue,
},
gridLines: {
drawTicks: false,
display: false
}
}],
xAxes: [{
gridLines: {
zeroLineColor: "transparent"
},
ticks: {
padding: 20,
fontColor: "rgba(0,0,0,0.5)",
fontStyle: "bold",
}
}]
},
}
});
}
$scope.exportData = function () {
if ($rootScope.sideselect.id == 1) {
$scope.formData.funName = "user_registration"
} else if ($rootScope.sideselect.id == 2) {
$scope.formData.funName = "activeinactive_report"
// $scope.formData.funName="activeinactive_report_v2"
} else if ($rootScope.sideselect.id == 3) {
$scope.formData.funName = "inactive_user_registration"
}
AppData.sendData($scope.exporturl, $scope.formData, function (res) {
if (res.cont) {
$('body').append("");
var setO = setTimeout(function () {
clearTimeout(setO);
$('#fileDownload').remove();
}, 2000);
}
})
}
$scope.viewdetails = function(id){
$rootScope.cofirmWindow = true;
$rootScope.modalShown = true;
$rootScope.message = $scope.pageData.errorMsg[4];
$scope.formData.userid = id;
}
$scope.$on("confirmDelete", function () {
$scope.formData.funName = "activeuser";
AppData.sendData($scope.userurl, $scope.formData, function (res) {
console.log(res);
if (res.cont) {
$scope.userInactiveRegistrationList();
}
})
})
$scope.exportTableData = function () {
if ($rootScope.sideselect.id == 1) {
$scope.formData.funName = "user_registration_percent"
} else if ($rootScope.sideselect.id == 2) {
$scope.formData.funName = "inactive_user_table"
} else if ($rootScope.sideselect.id == 3) {
$scope.formData.funName = "inactive_user_registration"
}
AppData.sendData($scope.exporturl, $scope.formData, function (res) {
if (res.cont) {
$('body').append("");
var setO = setTimeout(function () {
clearTimeout(setO);
$('#fileDownload').remove();
}, 2000);
}
})
}
/////////// Custom Filter /////////////
$scope.dataFilter = function () {
if ($scope.formData.datetype == '1' || $scope.formData.datetype == '2' || $scope.formData.datetype == '3' || $scope.formData.datetype == '4') {
$scope.formData.from_date = '';
$scope.formData.to_date = '';
} else {
$scope.formData.from_date = $scope.startingDate;
$scope.formData.to_date = $scope.currentDate;
}
$scope.userRegistrationData();
$scope.userRegistrationList();
}
///////////////////////// Active / Inactive Report /////////////////////
$scope.activeChart = function () {
console.log($scope.tabActive)
$('.inner-container' + $scope.tabActive).html('');
$('.inner-container' + $scope.tabActive).html('');
var ctx = document.getElementById("statusChart" + $scope.tabActive).getContext("2d");
Chart.defaults.global.legend.display = true;
var gradientStroke = ctx.createLinearGradient(500, 0, 100, 0);
gradientStroke.addColorStop(0, '#80b6f4');
gradientStroke.addColorStop(1, '#f49080');
var yAxesticks = [];
var highestVal;
var statusChart1 = new Chart(ctx, {
type: 'line',
data: {
labels: $scope.activeLabel,
datasets: [
{
label: "Initial Users",
borderColor: "#FD5F80",
pointBorderColor: "#FD5F80",
pointBackgroundColor: "#FD5F80",
pointHoverBackgroundColor: "#FD5F80",
pointHoverBorderColor: "#FD5F80",
pointBorderWidth: 10,
pointHoverRadius: 10,
pointHoverBorderWidth: 1,
pointRadius: 3,
fill: false,
borderWidth: 4,
backgroundColor: '#FD5F80',
data: $scope.initialArray
},
{
label: "Active Users",
borderColor: "#31A0EA",
pointBorderColor: "#31A0EA",
pointBackgroundColor: "#31A0EA",
pointHoverBackgroundColor: "#31A0EA",
pointHoverBorderColor: "#31A0EA",
pointBorderWidth: 10,
pointHoverRadius: 10,
pointHoverBorderWidth: 1,
pointRadius: 3,
fill: false,
borderWidth: 4,
backgroundColor: '#31A0EA',
data: $scope.activeArray
}, {
label: "Inactive Users",
borderColor: "#FEC94D",
pointBorderColor: "#FEC94D",
pointBackgroundColor: "#FEC94D",
pointHoverBackgroundColor: "#FEC94D",
pointHoverBorderColor: "#FEC94D",
pointBorderWidth: 10,
pointHoverRadius: 10,
pointHoverBorderWidth: 1,
pointRadius: 3,
fill: false,
borderWidth: 4,
backgroundColor: '#FEC94D',
data: $scope.inactiveArray
}
]
},
options: {
legend: {
position: "bottom"
},
scales: {
yAxes: [{
ticks: {
fontColor: "rgba(0,0,0,0.5)",
fontStyle: "bold",
beginAtZero: true,
maxTicksLimit: 3,
padding: 20,
scaleStartValue: 0,
min: 0,
suggestedmin: 0,
callback: function (value, index, values) {
yAxesticks = values;
return value;
}
},
gridLines: {
drawTicks: false,
display: false
}
}],
xAxes: [{
gridLines: {
zeroLineColor: "transparent"
},
ticks: {
padding: 20,
fontColor: "rgba(0,0,0,0.5)",
fontStyle: "bold"
}
}]
}
}
});
// statusChart1.options.scales.yAxes[0].ticks.min = 0;
// statusChart1.update();
console.log(statusChart1.options.scales.yAxes[0].ticks.min)
}
$scope.selectTab = function (tab) {
$scope.tabActive = tab;
$scope.userActivationData();
// setTimeout(function () {
// $scope.activeChart();
// }, 100)
}
$scope.activeData = function () {
$scope.userActivationData();
}
$scope.userActivationData = function () {
// console.log("hai");
// console.log($("#from").val())
console.log($scope.formData)
var val = $("#from").val();
if (val == '' || val == undefined) {
$('#from').datepicker("setDate", "today");
$('#to').datepicker("setDate", "today");
// $("#from").val($scope.startingMonth)
// $("#to").val($scope.startingMonth)
$scope.startMonth = moment($scope.startingMonth).format("YYYY-MM-DD");
$scope.endMonth = moment($scope.startingMonth).format("YYYY-MM-DD");
} else {
$scope.startMonth = moment($("#from").val()).format("YYYY-MM-DD");
$scope.endMonth = moment($("#to").val()).format("YYYY-MM-DD");
}
// $scope.formData.from_month = moment($("#from").val()).format("DD-MM-YYYY");
// $scope.formData.to_month = moment($("#to").val()).format("DD-MM-YYYY");
// console.log($("#to").val())
if ($scope.tabActive == 1) {
$scope.formData.type = 0;
} else if ($scope.tabActive == 2) {
$scope.formData.type = 1;
}
// $scope.formData.funName = "activeinactive_report";
$scope.formData.funName = "activeinactive_report_v2";
$scope.formData.from_date = $scope.startMonth
$scope.formData.to_date = $scope.endMonth
// console.log($scope.formData)
AppData.sendData($scope.pageurl, $scope.formData, function (res) {
if (res.cont) {
console.log(res.item)
$scope.userPercentList = res.item;
// userPercentList=res.list
// console.log(res.cont)
// $scope.userActiveReport = res.item;
// $scope.activeLabel = res.item.label;
// $scope.activeReportValue = $scope.userActiveReport.value;
// console.log($scope.userActiveReport);
// $scope.activeArray=[]
// $scope.inactiveArray=[]
// $scope.initialArray=[]
// for(var i=0;i<$scope.activeReportValue.length;i++){
// $scope.activeArray.push($scope.activeReportValue[i].active)
// $scope.inactiveArray.push($scope.activeReportValue[i].inactive)
// $scope.initialArray.push($scope.activeReportValue[i].inital)
// }
// var arr = [$scope.activeArray, $scope.inactiveArray,$scope.initialArray];
// var maxRow = arr.map(function(row){ return Math.max.apply(Math, row) });
// if(Math.max(...maxRow)!=0){
// $scope.activeChart();
// }else{
// $('.inner-container' + $scope.tabActive).html('');
// $('.inner-container'+ $scope.tabActive).html("No data found
");
// }
}
})
}
$scope.getDealer = function () {
$scope.dealerInactive=false;
// $scope.dseInactive=true;
$scope.formData.dealer_code='all';
var aobj = {};
aobj.funName = "dealerlist";
aobj.lang = $rootScope.selLanguage;
aobj.am_email = $scope.formData.am_email;
AppData.sendData($scope.commonurl, aobj, function (res) {
$scope.dealer_userlist = res.item;
// $scope.amChange()
})
}
$scope.dealerChange = function(){
if($scope.formData.dealer_code =='all'){
$scope.dseInactive=false;
}else{
$scope.dseInactive=true;
}
$scope.userActivationData();
}
$scope.modal_dismiss = function(){
// if($scope.currentPage>=2){
// $scope.currentPage = 1;
// $scope.setPage($scope.currentPage);
// }
// $(".pagination li").removeClass("active");
// $('#modal').on('hidden.bs.modal', function() {
// $(this).removeData('bs.modal');
// });
$('.myViewModal').modal('hide');
// console.log('page'+$scope.currentPage )
}
$scope.viewremarks =function(paramvalue){
console.log(paramvalue);
var aobj = {};
aobj.funName = "dse_remark";
aobj.userid = paramvalue.userid;
aobj.pn='0';
aobj.nr='10';
AppData.sendData($scope.pageurl, aobj, function (res) {
$scope.remarkslist = res.item.report;
$scope.totalremarkscount=res.total_records;
$scope.totalItems=$scope.totalremarkscount;
console.log("$scope.remarkslist--->,$scope.remarkslist")
})
}
});
});