text: var home={init:function(){home.initDatePicker();home.getDetailsThisMonth();home.getLatestPurchases();home.sortPaymentType();home.billStatus();home.registerEvents()},registerEvents:function(){$("#reportrange").on("cancel.daterangepicker",function(){$("#reportrange span").html(moment().subtract(29,"days").format("MMMM D, YYYY")+" - "+moment().format("MMMM D, YYYY"))});$('#toggleController input[type="checkbox"]').on("click",function(){home.doToggling()})},initDatePicker:function(){function i(n,t){$("#reportrange span").html(n.format("MMMM D, YYYY")+" - "+t.format("MMMM D, YYYY"));home.bindData(common.formatDateTime(n._d),common.formatDateTime(t._d))}var n=moment().subtract(30,"days"),t=moment();$("#reportrange").daterangepicker({startDate:n,endDate:t,opens:"left",autoUpdateInput:!1,locale:{cancelLabel:"Clear"},ranges:{Today:[moment(),moment()],Yesterday:[moment().subtract(1,"days"),moment().subtract(1,"days")],"Last 7 Days":[moment().subtract(6,"days"),moment()],"This Month":[moment().startOf("month"),moment().endOf("month")],"Last Month":[moment().subtract(1,"month").startOf("month"),moment().subtract(1,"month").endOf("month")],"Last 3 Months":[moment().subtract(3,"month").startOf("month"),moment().subtract(1,"month").endOf("month")],"Last 6 Months":[moment().subtract(6,"month").startOf("month"),moment().subtract(1,"month").endOf("month")]}},i);i(n,t)},calculateDay:function(){var n=$("#reportrange span").html(),t=new Date(n.split("-")[0]),i=new Date(n.split("-")[1]);return Math.ceil(parseInt(i-t)/864e5)},bindData:function(n,t){$.ajax({type:"GET",url:"/Admin/Home/GetRevenue",data:{fromDate:n,toDate:t},success:function(n){home.dataCollection=[];home.revenue=[];home.profit=[];home.funds=[];home.session=[];$.each(n.Finance,function(n,t){home.revenue.push([new Date(t.Date).getTime(),t.Revenue]);home.profit.push([new Date(t.Date).getTime(),t.Profit]);home.funds.push([new Date(t.Date).getTime(),t.Funds])});$.each(n.Session,function(n,t){home.session.push(t.TotalSession)});home.revenue.length>0&&(home.dataCollection.push(home.revenue,home.profit,home.funds),$("#toggleController").find("input[type='checkbox']:checked").length==0?($("#toggleController").find("input[type='checkbox']").click(),home.doToggling(),home.doSparklineTotalSession(home.session),home.doSparklineTotalRevenue(home.revenue)):(home.doToggling(),home.doSparklineTotalSession(home.session),home.doSparklineTotalRevenue(home.revenue)))}})},doToggling:function(){function u(n,t,i){$('<div id="tooltip">'+i+"<\/div>").css({position:"absolute",display:"none",top:t+5,left:n+20,border:"2px solid #4572A7",padding:"2px",size:"10","background-color":"#fff",opacity:.8}).appendTo("body").fadeIn(200)}home.dataSet=[];$.each($('#toggleController input[type="checkbox"]'),function(n,t){var r=$(t).is(":checked"),i;r&&(i=parseInt($(t).attr("data-id")),home.dataSet.push({label:home.labelCollection[i],data:home.dataCollection[i],color:home.lineChartColorCollection[i]}))});var n=home.calculateDay(),t=n>=89?[1,"month"]:[4,"day"],i=n>=89?"%b/%y":"%d/%m",r={series:{lines:{show:!0,fill:!0,lineWidth:1},points:{radius:3,fill:!0,show:!0}},colors:["#3F97EB","#72c380","#f7cb38"],xaxis:{mode:"time",tickSize:t,timeformat:i,axisLabelUseCanvas:!0,axisLabelFontSizePixels:12,axisLabelFontFamily:"Verdana, Arial",axisLabelPadding:10},yaxes:[{}],grid:{borderWidth:0,borderHeight:0,hoverable:!0,clickable:!0,backgroundColor:{colors:["#ffffff","#EDF5FF"]},autoHighlight:!0,mouseActiveRadius:30},legend:{position:"ne",margin:[0,-18],noColumns:0,labelFormatter:function(n){return n+"&nbsp;&nbsp;"},width:40,height:1}};$.fn.UseTooltip=function(){var n=null;$(this).bind("plothover",function(t,i,r){if(r){if(n!=r.dataIndex){n=r.dataIndex;$("#tooltip").remove();var f=r.datapoint[0],e=r.datapoint[1];u(r.pageX,r.pageY,new Date(f).toString("MMM/dd/yyyy")+"<br/><strong>$"+common.formartNumber(e,"0,0")+"<\/strong> ("+r.series.label+")")}}else $("#tooltip").remove(),n=null})};$.plot($("#chart_plot_02"),home.dataSet,r);$("#chart_plot_02").UseTooltip()},doSparklineTotalSession:function(n){$(".sparkline11").sparkline(n,{type:"bar",height:"40",barWidth:8,colorMap:{"7":"#a1a1a1"},barSpacing:2,barColor:"#26B99A"});var t=0;$.each(n,function(n,i){t+=i});$("#total-session").html(t)},doSparklineTotalRevenue:function(n){$(".sparkline22").sparkline(n,{type:"line",numberFormatter:function(n){return"$"+common.formartNumber(n,"0,0")},height:"40",width:"200",lineColor:"#26B99A",fillColor:"#ffffff",lineWidth:3,spotColor:"#34495E",minSpotColor:"#34495E"});var t=0;$.each(n,function(n,i){t+=i[1]});$("#total-revenue").html("$"+common.formartNumber(t,"0,0"))},getDetailsThisMonth:function(){$.ajax({type:"GET",url:"/Admin/Home/GetDetailThisMonth",success:function(n){var t=common.formatDate(new Date);$("#new-account").html(n.NewAccount);$("#new-acc-detail").html(n.NewAccount+" new sign ups in this month.");$("#new-product").html(n.NewProduct);$("#new-product-detail").html(n.NewProduct+" new products added in this month.");$("#total-sold").html(n.Sold);$("#sold-detail").html("There have been "+n.Sold+" solds in this month.");$("#bill-delivered").html(n.CompletedBill);$("#bill-delivered-detail").html(n.CompletedBill+" bills delivered successfully in this month.")}})},getLatestPurchases:function(){var n="",t=$("#tbl-latest-purchases-template").html();$.ajax({type:"GET",url:"/Admin/Home/LatestPurchase",dataType:"json",success:function(i){$.each(i,function(i,r){var u={};u.BorderColor=i%2==0?"border-aero":"border-green";u.Icon=i%2==0?"fa-user aero":"fa-user green";u.Name=r.Bill.CustomerName;u.Address=r.Bill.CustomerAddress;u.TotalCost=common.formartNumber(r.TotalCost,"0,0");u.Quantity=r.Quantity;u.Date=common.formatDate(r.Bill.CreatedDate);n+=Mustache.render(t,u)});$("#latest-purchases-body").html(n)}})},initPieChart:function(n,t){if(typeof Chart!="undefined"&&$(".canvasDoughnut").length){var i={type:"doughnut",tooltipFillColor:"rgba(51, 51, 51, 0.55)",data:{labels:t,datasets:[{data:n,backgroundColor:home.doughnutChartColorCollection,hoverBackgroundColor:home.doughnutChartColorCollection}]},options:{legend:!1,responsive:!1}};$(".canvasDoughnut").each(function(){var n=$(this),t=new Chart(n,i)})}},sortPaymentType:function(){var n=[],t=[],i="",r=$("#tbl-payment-pie-template").html();$.ajax({type:"GET",url:"/Admin/Home/PaymentReport",dataType:"json",success:function(u){var f=0;$.each(u.Payments,function(e,o){n.push(e);t.push(o);var s={};s.Color=home.doughnutChartColorCollection[f];f++;s.Name=e;s.Percent=(o/u.Total*100).toFixed(2);i+=Mustache.render(r,s)});home.initPieChart(t,n);$("#tbl-pie-body").html(i)}})},billStatus:function(){var n="",t=$("#bill-cindition-template").html();$.ajax({type:"GET",url:"/Admin/Home/BillReport",dataType:"json",success:function(i){n+="<h4>Bill condition all time<\/h4>";$.each(i,function(i,r){var u={};u.Name=r.BillName;u.Percent=r.Percent;n+=Mustache.render(t,u)});$("#bill-condition-body").html(n)}})},labelCollection:["Revenue Report","Profit Report","Funds Report",],lineChartColorCollection:["#3F97EB","#72c380","#f7cb38"],doughnutChartColorCollection:["#ed6868","#efb65f","#5fe22f","#7de8db","#0dbce8","#c98bef","#ad4391"],dataCollection:[],dataSet:[],revenue:[],profit:[],funds:[],session:[]};home.init();