MOON
Server: Apache
System: Linux e2e-78-16.ssdcloudindia.net 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64
User: imensosw (1005)
PHP: 8.0.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/imensosw/www/imenso.co/dev/impactify-it/js/dashboard.js
var canvasWidth=$('.card-body').width();
$(document).on('click','.graph-tab',function(){
   if($(this).attr("data-name")=="Utilization")
   {
      $('.Progress-tab').hide();
      $('.Utilization-tab').show();
   }
   else
   {
      $('.Progress-tab').show();
      $('.Utilization-tab').hide();
   }

});

/*funds_utilization open*/
function funds_utilization(totalApproved,totalReceived,totalUtilized)
{
      

       var table="";
           table+="<tr style='font-size:25px;'>";
           table+="<th>Week</th>";
           table+="<th>Approved</th>";
           table+="<th>Disbursed</th>";
           table+="<th>Utilized</th>";
           table+="</tr>";
        for(i=totalApproved.length-1;i>=0;i--)
        {

           table+="<tr>";
           table+="<td>"+totalApproved[i]['label'].replace('<br>Total Approved',"");+"</td>";
           table+="<td>"+totalApproved[i]['y']+"</td>";
           table+="<td>"+totalReceived[i]['y']+"</td>";
           table+="<td>"+totalUtilized[i]['y']+"</td>";
           table+="</tr>";
        }
  
   $('#Funds_Utilization_xls').html(table);

  

    var chart = new CanvasJS.Chart("chart_funds_utilization", {
      animationEnabled: true,
       width:canvasWidth,
      title: {
        text: ""
      },
      legend: {
                verticalAlign: "top",
                horizontalAlign: "right",
                dockInsidePlotArea: false,
                fontSize: 12
              },
      axisX: {
        valueFormatString: "MMM YY",
        interval:1,
        intervalType: "month"
      },
      axisY: {
        title: "",
        titleFontColor: "#4F81BC",
        suffix: "",
        valueFormatString: "₹ #,###,.##K",   // "₹ #,##,###.#"   // #,###,,.##M   // #,###,.##K
      },
      data: [
      {
        indexLabelFontColor: "darkSlateGray",
        name: "Approved",
        type: "splineArea",
        yValueFormatString: "₹ #,###,.##K",   //"₹ #,##,###.#",
        showInLegend: true,
        legendMarkerType: "square",
        color: "rgba(0,69,238,.7)",
        xValueType: "dateTime",
        dataPoints: totalApproved
      },
      {
        indexLabelFontColor: "darkSlateGray",
        name: "Disbursed",
        type: "splineArea",
        yValueFormatString: "₹ #,###,.##K",    // "₹ #,##,###.#",
        showInLegend: true,
        legendMarkerType: "square",
        color: "rgba(112,173,71,.7)",
        xValueType: "dateTime",
        dataPoints: totalReceived

      },
      {
        indexLabelFontColor: "darkSlateGray",
        name: "Utilized",
        type: "splineArea",
        yValueFormatString:  "₹ #,###,.##K" ,   // "₹ #,##,###.#",
        showInLegend: true,
        legendMarkerType: "square",
        color: "rgba(255,192,37,.7)",
        xValueType: "dateTime",
        dataPoints: totalUtilized
      }
      ]
    });
    chart.render();
     // budget_1 end
   }



// category open
function category(categorywaisebu){
     
 console.log(categorywaisebu);

       var table="";
          table+="<tr style='font-size:25px'>";
           table+="<td>Category</td>";
           table+="<td>Amount</td>";
           table+="</tr>";

         
     for(i=categorywaisebu.length-1;i>=0;i--)
        {

          table+="<tr>";
           table+="<td>"+categorywaisebu[i]['label']+"</td>";
           table+="<td>"+categorywaisebu[i]['y']+"</td>";
         table+="</tr>";
        }
         
      
        $('#Funds_Breakdown_by_Category_xls').html(table);

     var chart1 = new CanvasJS.Chart("chart_category", {
          animationEnabled: true,
          width:canvasWidth,
          theme: "light1",
          title:{
           // text: "Budget by category",
            fontSize: 18,
            padding: 10,
            fontWeight: "normal",
            fontFamily: "tahoma",
          },
           toolTip:{
                 contentFormatter: function(e){
                        return (  e.entries[0].dataPoint.label + " : ₹ " +  custom_number_format(e.entries[0].dataPoint.y) + "" ) ;
                      },
             },
          legend: {
             horizontalAlign: "right", // left, center ,right 
             verticalAlign: "top",  // top, center, bottom
            fontSize: 12,

           },
             axisX:{
          // interval: 1,
        },
          axisY: {
            title: "",
            titleFontSize: 14,
            // titleFontColor: "red",
            titleFontWeight: "bold",
            gridThickness: 1,
            gridColor: "rgba(0,0,0,.08)",
            valueFormatString:  "₹ #,###,.##K" //"₹ #,##0,###.#"
          },
          data: [{        
            type: "column",  
            legendMarkerColor: "grey",
            showInLegend: false,
            // yValueFormatString:  "₹ #,###,.##K",
            yValueFormatString:  "₹ #,###,.##K",
            dataPoints:categorywaisebu,
            
            //toolTipContent: "<b>{label} : {y}",
          }]
        });
     chart1.render();
   }

 
    // category end
    //projectWiseFundUtilization start
    function projectWiseFundUtilization(ProjectTotalBugget,ProjectTotalResive,ProjectTotaluti){
     
     var urlpath="";

     var table="";
     table+="<tr style='font-size:25px;'>";
     table+="<td>Project Name</td>";
     table+="<td>Approved</td>";
     table+="<td>Disbursed</td>";
     table+="<td>Utilized</td>";
     table+="</tr>";

     for(i=ProjectTotalBugget.length-1;i>=0;i--)
        {

          table+="<tr>";
           table+="<td>"+ProjectTotalBugget[i]['label'].replace('<br>Total Approved',"");+"</td>";
           table+="<td>"+ProjectTotalBugget[i]['y']+"</td>";
          table+="<td>"+ProjectTotalResive[i]['y']+"</td>";
           table+="<td>"+ProjectTotaluti[i]['y']+"</td>";
         table+="</tr>";
        }
        $('#Project_Wise_Fund_Utilization_xls').html(table);
     
      var chart2 = new CanvasJS.Chart("chart_projectWiseFundUtilization", {
        width:canvasWidth,
        title:{
         // text: "Project Wise utilization ",
          fontSize: 10,
          fontWeight: "normal",
          fontFamily: "tahoma"
        },
        legend: {
          horizontalAlign: "right", // left, center ,right 
          verticalAlign: "top",  // top, center, bottom
          fontSize: 12
        },
        axisX:{
          gridThickness: 2,
          gridColor: "rgba(0,0,0,.08)",
          valueFormatString: "₹ #,##0,###.#"
        },
        axisY: {
            gridThickness: 1,
            gridDashType: "dot",
            gridColor: "rgba(0,0,0,.08)",
            fontSize: 5,
            fontWeight: "normal",
            valueFormatString:  "₹ #,###,.##K"    // "₹ #,##0,###.#"

        },
        data: [
        {

          click: function(e){
            // alert(e.dataPoint.id);
            window.open(path+"user/project/edit/"+e.dataPoint.id);
           },
          type: "bar",
          legendText: "Approved",
          fontWeight: "normal",
          showInLegend: "true",
          fontSize: 5,
          color: "rgba(0,69,238,.7)",
          yValueFormatString:  "₹ #,###,.##K",
          // toolTipContent: "<b>Total Budget : {y}",

          dataPoints:ProjectTotalBugget
        },
        {
         click: function(e){
             window.open(path+"user/project/edit/"+e.dataPoint.id);
           },
          type: "bar",
          legendText: "Disbursed",
          fontWeight: "normal",
          showInLegend: "true",
          fontSize:5,
          color: "rgba(112,173,71,.7)",
          // toolTipContent: "<b>Received Budget : {y}",
          yValueFormatString:  "₹ #,###,.##K",
          dataPoints:ProjectTotalResive
        },
        {
        click: function(e){
             window.open(path+"user/project/edit/"+e.dataPoint.id);
           },
          type: "bar",
          legendText: "Utilized",
          fontWeight: "normal",
          showInLegend: "true",
          fontSize: 5,
          color: "rgba(255,192,37,.7)",
          // toolTipContent: "<b>Utilized Budget : {y}",
          yValueFormatString:  "₹ #,###,.##K",
          dataPoints: ProjectTotaluti
        }

        ]
      });
     chart2.render();
   }


   //ProjectTotalKpi Chart start
    function projectTotalKpiChart(ProjectTotalKpiBaseline,ProjectTotalKpiTarget,ProjectTotalKpiStatus){
     
     var urlpath="";

     var table="";
     table+="<tr style='font-size:25px;'>";
     table+="<td>Project Name</td>";
     table+="<td>Baseline</td>";
     table+="<td>Target</td>";
     table+="<td>Status</td>";
     table+="</tr>";

     for(i=ProjectTotalKpiBaseline.length-1;i>=0;i--)
        {

          table+="<tr>";
           table+="<td>"+ProjectTotalKpiBaseline[i]['label']+"</td>";
           table+="<td>"+ProjectTotalKpiBaseline[i]['baseline']+"</td>";
          table+="<td>"+ProjectTotalKpiTarget[i]['target']+"</td>";
           table+="<td>"+ProjectTotalKpiStatus[i]['status']+"</td>";
         table+="</tr>";
        }
        $('#Project_Wise_Kpi_xls').html(table);
     
      var chart2 = new CanvasJS.Chart("chart_ProjectWiseKPI", {
        width:canvasWidth,
        title:{
         // text: "Project Wise utilization ",
          fontSize: 10,
          fontWeight: "normal",
          fontFamily: "tahoma"
        },
        legend: {
          horizontalAlign: "right", // left, center ,right 
          verticalAlign: "top",  // top, center, bottom
          fontSize: 12
        },
        axisX:{
          gridThickness: 2,
          gridColor: "rgba(0,0,0,.08)",
          valueFormatString: "₹ #,##0,###.#"
        },
        axisY: {
            gridThickness: 1,
            gridDashType: "dot",
            gridColor: "rgba(0,0,0,.08)",
            fontSize: 5,
            fontWeight: "normal",
            valueFormatString: "₹ #,###,.##K"   // "₹ #,##0,###.#"

        },
        data: [
        {

          click: function(e){
            // alert(e.dataPoint.id);
            window.open(path+"user/project/edit/"+e.dataPoint.id);
           },
          type: "bar",
          legendText: "Baseline",
          fontWeight: "normal",
          showInLegend: "true",
          fontSize: 5,
          color: "#89deff",//"rgba(0,69,238,.7)",
          // toolTipContent: "<b>Kpi Baseline : {y}",
          yValueFormatString:  "₹ #,###,.##K",

          dataPoints:ProjectTotalKpiBaseline
        },
        {
         click: function(e){
             window.open(path+"user/project/edit/"+e.dataPoint.id);
           },
          type: "bar",
          legendText: "Target",
          fontWeight: "normal",
          showInLegend: "true",
          fontSize:5,
          color: "#ef8b35", //"rgba(112,173,71,.7)",
          // toolTipContent: "<b>Kpi Target : {y}",
          yValueFormatString:  "₹ #,###,.##K",

          dataPoints:ProjectTotalKpiTarget
        },
        {
        click: function(e){
             window.open(path+"user/project/edit/"+e.dataPoint.id);
           },
          type: "bar",
          legendText: "Status",
          fontWeight: "normal",
          showInLegend: "true",
          fontSize: 5,
          color: "rgba(255,192,37,.7)",
          // toolTipContent: "<b>Kpi Status : {y}",
          yValueFormatString:  "₹ #,###,.##K",

          dataPoints: ProjectTotalKpiStatus
        }

        ]
      });
     chart2.render();
   }



   //chart_SummaryPerformance
    function SummaryPerformance(bubalchart){
      var max =[];
      for (var i = 0; i < bubalchart.length; i++) {
      max.push(bubalchart[i]['x']);
    }

      var interval=10;
      if(Math.max.apply(Math, max)<=100)
      {
        interval=10;
      }
      else if(Math.max.apply(Math, max)>100 && Math.max.apply(Math, max)<=300)
      {
        interval=30;
      }
      else if(Math.max.apply(Math, max)>300 && Math.max.apply(Math, max)<=600)
      {
        interval=50;
      }
      else if(Math.max.apply(Math, max)>600 && Math.max.apply(Math, max)<=1000)
      {
        interval=100;
      }
      else if(Math.max.apply(Math, max)>1000 && Math.max.apply(Math, max)<=2000)
      {
        interval=300;
      }
      

      urlpath="";
      var table="";
          table+="<tr style='font-size:25px;'>";
           table+="<td>Project Name</td>";
           table+="<td>Complete</td>";
           table+="<td>Budget</td>";
           table+="<td>Utilized</td>";
           table+="</tr>";

     for(i=bubalchart.length-1;i>=0;i--)
        {

          table+="<tr>";
           table+="<td>"+bubalchart[i]['name']+"</td>";
           table+="<td>"+bubalchart[i]['x']+" %</td>";
          table+="<td>"+bubalchart[i]['y']+"</td>";
           table+="<td>"+bubalchart[i]['z'].toFixed(2)+" %</td>";
         table+="</tr>";
        }
        $('#Summary_of_Project_Performance_xls').html(table);
        var chart3 = new CanvasJS.Chart("chart_SummaryPerformance", {
        animationEnabled: true,
        width:canvasWidth,
        title:{
         // text: "Summary of Project Performance",
          fontSize: 18,
          padding: 10,
          fontWeight: "normal",
          fontFamily: "tahoma",
          color: "rgba(112,173,71,.7)"
        },
         toolTip:{
             contentFormatter: function(e){
              return ("<b>"+e.entries[0].dataPoint.name+"</b><br/>Complete  : "+(e.entries[0].dataPoint.x).toFixed(2)+" %<br/> Budget : ₹ "+number_formates(e.entries[0].dataPoint.y)+" <br> Utilized: "+e.entries[0].dataPoint.z.toFixed(2)+" %<br/>")
            },
         },
        legend: {
          verticalAlign: "top",
          horizontalAlign: "right",
          dockInsidePlotArea: false,
          fontSize: 12
        },
        axisX: {

          title:"Complete %",
          titleFontSize: 13,
          titleFontWeight: "bold",
          interval: interval,
         
          legendMarkerColor: "grey",
          valueFormatString: "#,##,###.#",
         color: "rgba(240,90,40,.7)" 
        },
        axisY: {
          title:"",
          titleFontSize: 13,
          titleFontWeight: "bold",
            legendMarkerColor: "grey",
         // color: "rgba(0,69,238,1)"
            gridThickness: 1,
            gridColor: "rgba(0,0,0,.08)" ,
          valueFormatString:  "₹ #,###,.##K"    // "₹ #,##0,###.#",

        },
        data: [{
           click: function(e){
            
            window.open(path+"user/project/edit/"+e.dataPoint.id);
           },
          type: "bubble",
          showInLegend: false ,
            // legendText: "Size of Bubble Represents Population in Millions",
            legendMarkerType: "circle",
            legendMarkerColor: "grey",
            dataPoints:bubalchart
          }]
        });
     chart3.render();
   }
     // budget_4 close

        // budget_5 open
   function StatusNumberofProjects(Delayed,noProgress,onTrack){


         var table="";
         table+="<tr style='font-size:25px;'>";
         table+="<td>No Progress</td>";
         table+="<td>OnTrack</td>";
         table+="<td>Delayed</td>";
         table+="</tr>";

         table+="<tr>";
         table+="<td>"+noProgress+"</td>";
         table+="<td>"+onTrack+"</td>";
         table+="<td>"+Delayed+"</td>";
         table+="</tr>";
  
        $('#Progress_Status_By_Number_of_Projects_xls').html(table);

     var chart5 = new CanvasJS.Chart("chart_StatusNumberofProjects", {
        animationEnabled: true,
        title:{
         // text: "Number of Projects by Progress Status",
          horizontalAlign: "center",
          fontSize: 18,
          padding: 10,
          fontWeight: "normal",
          fontFamily: "tahoma",
          valueFormatString: "₹ #,##0,###.#"

        },
        toolTip:{
             contentFormatter: function(e){

              return ("<b>"+e.entries[0].dataPoint.label+" : "+custom_number_format(e.entries[0].dataPoint.y) +"")
            },
         },
        legend: {
          verticalAlign: "top",
          horizontalAlign: "right",
          dockInsidePlotArea: false,
          fontSize: 12
        },
        data: [{
          type: "doughnut",
          startAngle: 60,
            //innerRadius: 60,
            indexLabelFontSize: 13,
            indexLabel: "{label} - {labely}",
          //  toolTipContent: "<b>{label}:</b> {y} (#percent%)",
            dataPoints: [
            { y: Delayed, label: "Delayed",labely:number_formates(Delayed), color: "rgba(240,90,40,.7)" },
            { y: noProgress, label: "No Progress",labely:number_formates(noProgress), color: "rgba(192,0,0,.7)" },
            { y: onTrack, label: "onTrack",labely:number_formates(onTrack), color: "rgba(112,173,71,.7)"}
            ]
          }]
        });
     chart5.render();
   }
     // budget_5 close

     // budget_6 open
    function StatusBudgetofProjects(Delayedb,noProgressb,onTrackb){

      label_Delayedb = number_formates(Delayedb);
      label_noProgressb = number_formates(noProgressb);
      label_onTrackb = number_formates(onTrackb);

      var table="";
         table+="<tr style='font-size:25px;'>";
         table+="<td>No Progress</td>";
         table+="<td>OnTrack</td>";
         table+="<td>Delayed</td>";
         table+="</tr>";

         table+="<tr>";
         table+="<td>"+noProgressb+"</td>";
         table+="<td>"+onTrackb+"</td>";
         table+="<td>"+Delayedb+"</td>";
         table+="</tr>";
  
        $('#Progress_Status_By_Budget_of_Projects_xls').html(table);

    var chart6 = new CanvasJS.Chart("chart_StatusBudgetofProjects", {
        animationEnabled: true,
        title:{
         // text: "Number of Projects by Progress Status",
          horizontalAlign: "center",
          fontSize: 18,
          padding: 10,
          fontWeight: "normal",
          fontFamily: "tahoma",

        },
          toolTip:{
             contentFormatter: function(e){
              return ("<b>"+e.entries[0].dataPoint.label+" : ₹ "+custom_number_format(e.entries[0].dataPoint.y) +"")
            },
         },
    
        data: [{
          type: "doughnut",
          startAngle: 60,
            //innerRadius: 60,
            indexLabelFontSize: 13,
            //indexLabel: "{label} - {y}",
            indexLabel: "{label} - {labely}",
            valueFormatString: "₹ #,##0,###.#",

            //toolTipContent: "<b>{label}:</b> {y} (#percent%)",
            dataPoints: [
            { y: Delayedb, label: "Delayed", labely:number_formates(Delayedb), color: "rgba(240,90,40,.7)" },
            { y: noProgressb, label: "No Progress", labely:number_formates(noProgressb), color: "rgba(192,0,0,.7)" },
            { y: onTrackb, label: "onTrack", labely:number_formates(onTrackb), color: "rgba(112,173,71,.7)"}
            ]
          }]
        });
     chart6.render();
   }
     // budget_6 close

   function ProjectbudgetsProgress(noProgress_rs,Delayed_rs,onTrack_rs){
    
        var urlpath="";

var table=""; 
          table+="<tr style='font-size:25px;'>";
           table+="<td>Project Name</td>";
           table+="<td>Budget</td>";
           table+="<td>Status</td>";
           table+="</tr>";

    for(i=noProgress_rs.length-1;i>=0;i--)
        {
          table+="<tr>";
           table+="<td>"+noProgress_rs[i]['label']+"</td>";
           table+="<td>"+noProgress_rs[i]['y']+" </td>";
          table+="<td>No Progress</td>";
         table+="</tr>";
        }
     for(i=Delayed_rs.length-1;i>=0;i--)
        {
          table+="<tr>";
           table+="<td>"+Delayed_rs[i]['label']+"</td>";
           table+="<td>"+Delayed_rs[i]['y']+" </td>";
          table+="<td>Delayed</td>";
         table+="</tr>";
        }
        for(i=onTrack_rs.length-1;i>=0;i--)
        {
          table+="<tr>";
           table+="<td>"+onTrack_rs[i]['label']+"</td>";
           table+="<td>"+onTrack_rs[i]['y']+" </td>";
          table+="<td>On Track</td>";
         table+="</tr>";
        }
        $('#Project_budgets_by_Progress_Status_xls').html(table); 
       var chart7 = new CanvasJS.Chart("chart_ProjectbudgetsNoProgress", {
        animationEnabled: true,
        width:canvasWidth,

        title:{
         // text:"Project budgets by Progress Status",
          fontSize: 18,
          padding: 10,
          fontWeight: "normal",
          fontFamily: "tahoma",
          valueFormatString: "₹ #,##0,###.#"

        },
         toolTip:{
             contentFormatter: function(e){
              return ("<b>"+e.entries[0].dataPoint.label+" : ₹ "+number_formates(e.entries[0].dataPoint.y) +"")
            },
         },
        axisX:{
        //  interval: 1,
          gridThickness: 1,
          gridColor: "rgba(0,0,0,.08)"
        },
        axisY:{
          interlacedColor: "rgba(1,77,101,.02)",
          gridColor: "rgba(0,0,0,.08)",
          titleFontSize: 14,
          valueFormatString: "₹ #,###,.##K",   // "₹ #,##0,###.#",
          title: "",        

          // titleFontColor: "red",
          titleFontWeight: "bold",
          legendMarkerColor: "grey",

        },
        data: [{
           click: function(e){
            window.open(path+"user/project/edit/"+e.dataPoint.id);
           },
          type: "bar",
          // axisYType: "secondary",
          color: "rgba(192,0,0,.7)",
          dataPoints:noProgress_rs,
        }]
      });
     chart7.render();
     // budget_7 close

     // budget_8 open
     var chart8 = new CanvasJS.Chart("chart_ProjectbudgetsDelayed", {
        animationEnabled: true,
        width:canvasWidth,
        title:{
          //text:"Project budgets by Progress Status",
          fontSize: 18,
          padding: 10,
          fontWeight: "normal",
          fontFamily: "tahoma"
        },
         toolTip:{
             contentFormatter: function(e){
              return ("<b>"+e.entries[0].dataPoint.label+" : ₹ "+number_formates(e.entries[0].dataPoint.y) +"")
            },
         },
        axisX:{
          //interval: 1,
          gridThickness: 1,
          gridColor: "rgba(0,0,0,.08)"
        },
        axisY:{
        interlacedColor: "rgba(1,77,101,.02)",
        gridColor: "rgba(0,0,0,.08)",
        title: "",        
        titleFontSize: 14,
        // titleFontColor: "red",
        titleFontWeight: "bold",
        legendMarkerColor: "grey",
        valueFormatString: "₹ #,###,.##K",   //"₹ #,##0,###.#"
        },
        data: [{
           click: function(e){
           window.open(path+"user/project/edit/"+e.dataPoint.id);
           },
          type: "bar",
          name: "Projects",
          // axisYType: "secondary",
          color: "rgba(240,90,40,.7)",
          dataPoints:Delayed_rs
        }]
      });
     chart8.render();
     // budget_8 close

     // budget_9 open
     var chart9 = new CanvasJS.Chart("chart_ProjectbudgetsOnTrack", {
        animationEnabled: true,
        width:canvasWidth,

        title:{
         // text:"Project budgets by Progress Status",
          fontSize: 18,
          padding: 10,
          fontWeight: "normal",
          fontFamily: "tahoma"
        },
         toolTip:{
             contentFormatter: function(e){
              return ("<b>"+e.entries[0].dataPoint.label+" : ₹ "+number_formates(e.entries[0].dataPoint.y) +"")
            },
         },
        axisX:{
          gridThickness: 1,
          gridColor: "rgba(0,0,0,.08)"

        },
        axisY:{
          interlacedColor: "rgba(1,77,101,.02)",
          gridColor: "rgba(0,0,0,.08)",
          title: "",        
          titleFontSize: 14,
          // titleFontColor: "red",
          titleFontWeight: "bold",
          legendMarkerColor: "grey",
          valueFormatString: "₹ #,###,.##K", //"₹ #,##0,###.#"

        },
        data: [{
           click: function(e){
            window.open(path+"user/project/edit/"+e.dataPoint.id);
           },
          type: "bar",
          name: "Projects",
          // axisYType: "secondary",
          color: "rgba(112,173,71,.7)",
          dataPoints:onTrack_rs

        }]
      });
      chart9.render();
    }

   function number_formates(number, decimals, dec_point, thousands_point) {

//     if (number == null || !isFinite(number)) {
//         throw new TypeError("number is not valid");
//     }






//            x=number.toString();
// var lastThree = x.substring(x.length-3);
// var otherNumbers = x.substring(0,x.length-3);
// if(otherNumbers != '')
//     lastThree = ',' + lastThree;
// var res = otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree;
// return res;


if (number == null || !isFinite(number)) {
     //   throw new TypeError("number is not valid");
     return 0;
    }

    x=number.toString();
    var lastThree = x.substring(x.length-3);
    var otherNumbers = x.substring(0,x.length-3);
    if(otherNumbers != '')
        lastThree = ',' + lastThree;
    var res = otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree;

    
    if (!decimals) {
       
        var len = number.toString().split('.').length;
        decimals = len > 1 ? len : 0;
    }

    if (!dec_point) {
        dec_point = '.';
    }

    if (!thousands_point) {
        thousands_point = ',';
    }

    number = parseFloat(number).toFixed(decimals);

    number = number.replace(".", dec_point);

    var splitNum = number.split(dec_point);
    splitNum[0] = splitNum[0].replace(/\B(?=(\d{3})+(?!\d))/g, thousands_point);
  return    number = splitNum.join(dec_point);
  
}

// download xls code 

var tablesToExcel = (function() {
    var uri = 'data:application/vnd.ms-excel;base64,'
    , tmplWorkbookXML = '<?xml version="1.0"?><?mso-application progid="Excel.Sheet"?><Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">'
      + '<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"><Author>Axel Richter</Author><Created>{created}</Created></DocumentProperties>'
      + '<Styles>'
      + '<Style ss:ID="Currency"><NumberFormat ss:Format="Currency"></NumberFormat></Style>'
      + '<Style ss:ID="Date"><NumberFormat ss:Format="Medium Date"></NumberFormat></Style>'
      + '</Styles>' 
      + '{worksheets}</Workbook>'
    , tmplWorksheetXML = '<Worksheet ss:Name="{nameWS}"><Table>{rows}</Table></Worksheet>'
    , tmplCellXML = '<Cell{attributeStyleID}{attributeFormula}><Data ss:Type="{nameType}">{data}</Data></Cell>'
    , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
    , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
    return function(tables, wsnames, wbname, appname) {
      var ctx = "";
      var workbookXML = "";
      var worksheetsXML = "";
      var rowsXML = "";

      for (var i = 0; i < tables.length; i++) {
        if (!tables[i].nodeType) tables[i] = document.getElementById(tables[i]);
        for (var j = 0; j < tables[i].rows.length; j++) {
          rowsXML += '<Row>'
          for (var k = 0; k < tables[i].rows[j].cells.length; k++) {
            var dataType = tables[i].rows[j].cells[k].getAttribute("data-type");
            var dataStyle = tables[i].rows[j].cells[k].getAttribute("data-style");

            var dataValue = tables[i].rows[j].cells[k].getAttribute("data-value");
            dataValue = (dataValue)?dataValue:tables[i].rows[j].cells[k].innerHTML;
            var dataFormula = tables[i].rows[j].cells[k].getAttribute("data-formula");
            dataFormula = (dataFormula)?dataFormula:(appname=='Calc' && dataType=='DateTime')?dataValue:null;
            ctx = {  attributeStyleID: (dataStyle=='Currency' || dataStyle=='Date')?' ss:StyleID="'+dataStyle+'"':''
                   , nameType: (dataType=='Number' || dataType=='DateTime' || dataType=='Boolean' || dataType=='Error')?dataType:'String'
                   , data: (dataFormula)?'':dataValue
                   , attributeFormula: (dataFormula)?' ss:Formula="'+dataFormula+'"':''
                  };
            rowsXML += format(tmplCellXML, ctx);
          }
          rowsXML += '</Row>'
        }
        ctx = {rows: rowsXML, nameWS: wsnames[i] || 'Sheet' + i};
        worksheetsXML += format(tmplWorksheetXML, ctx);
        rowsXML = "";
      }

      ctx = {created: (new Date()).getTime(), worksheets: worksheetsXML};
      workbookXML = format(tmplWorkbookXML, ctx);



      var link = document.createElement("A");
      link.href = uri + base64(workbookXML);
      link.download = wbname || 'Workbook.xls';
      link.target = '_blank';
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
    }
  })();

$(document).on('click','.all_xls',function(){
  if($('.graph-tab').eq(0).hasClass('active'))
  {
     $('.utilization_xls').trigger('click');
  }
  else
  {
     $('.progress_xls').trigger('click'); 
  }

});

//end download xls

// filter 

$(document).on('click','.current_financial',function(){
  $('.current_financial').removeClass('active');
  $(this).addClass('active');
  $('.filter_status').trigger('change');

})
$(document).on('change','.filter_status',function(){
  if($(this).val()=="team")
      {
          $('.team-box').show(); $('.sponsor-box,.sector-box').hide();
          $('#sponsor_filter,#sector_filter').val('');
      }
     else if($(this).val()=="sponsor")
      {
          $('.sponsor-box').show(); $('.sector-box,.team-box').hide();
          $('#team_filter,#sector_filter').val('');
      }
      else if($(this).val()=="sector")
      {
          $('.sector-box').show(); $('.sponsor-box,.team-box').hide();
          $('#sponsor_filter,#team_filter').val('');
      }
      else
      {
         $('.sponsor-box,.sector-box,.team-box').hide();
         $('#sponsor_filter,#sector_filter,#team_filter').val('');
      }
      $('#team_filter').trigger('change');
});

$(document).on('change','.filter',function(){
  
    dashboardFilter();
  });

function dashboardFilter()
{
  if($('.current_financial').eq(0).hasClass('active'))
    {
         var current_12= $('.current_financial').eq(0).attr('data-status');
    }
    else
    {
        var current_12= $('.current_financial').eq(1).attr('data-status');
    }
    
    var manager=$('#team_filter').val();
    var sector=$('#sector_filter').val();
    var sponsor=$('#sponsor_filter').val();
    var project=$('#ptoject_filter').val();
    $.ajax({
     url:path+'user/dashboard/filter',
     type:'POST',
     data:{
         _token:$('meta[name="csrf-token"]').attr('content'),
         manager:manager,
        sector:sector,
        sponsor:sponsor,
        current_12:current_12,
        project:project
    },
    success: function(response)
    {
      if(response.success==true)
      {
          DateWiseResivedbugget=response.data['DateWiseResivedbugget'];
          DateWiseDisbursedbugget=response.data['DateWiseDisbursedbugget'];
          DateWiseUtilizeddbugget=response.data['DateWiseUtilizeddbugget'];

          categorywaisebu=response.data['categorywaisebu'];
          ProjectTotalBugget=response.data['ProjectTotalBugget'];
          ProjectTotalResive=response.data['ProjectTotalResive'];
          ProjectTotaluti=response.data['ProjectTotaluti'];
          bubalchart=response.data['bubalchart'];

          Delayed=response.data['Delayed'];
          noProgress=response.data['noProgress'];
          onTrack=response.data['onTrack'];
          Delayedb=response.data['Delayedb'];
          noProgressb=response.data['noProgressb'];
          onTrackb=response.data['onTrackb'];

          noProgress_rs=response.data['noProgress_rs'];
          Delayed_rs=response.data['Delayed_rs'];
          onTrack_rs=response.data['onTrack_rs'];
          ProjectTotalKpiBaseline = response.data['ProjectTotalKpiBaseline'];
          ProjectTotalKpiTarget = response.data['ProjectTotalKpiTarget'];
          ProjectTotalKpiStatus = response.data['ProjectTotalKpiStatus'];

          funds_utilization(DateWiseDisbursedbugget,DateWiseResivedbugget,DateWiseUtilizeddbugget);
          category(categorywaisebu);
          projectWiseFundUtilization(ProjectTotalBugget,ProjectTotalResive,ProjectTotaluti);
          SummaryPerformance(bubalchart);
          StatusNumberofProjects(Delayed,noProgress,onTrack);
          StatusBudgetofProjects(Delayedb,noProgressb,onTrackb);
          ProjectbudgetsProgress(noProgress_rs,Delayed_rs,onTrack_rs);
          projectTotalKpiChart(ProjectTotalKpiBaseline,ProjectTotalKpiTarget,ProjectTotalKpiStatus);
      }
    },
    error:function(data)
    {
      var errors = data.responseJSON; 
    },
    dataType:"json"
  });

}

dashboardFilter();

 function custom_number_format(n, precision = 1) {
        if (n < 900) {
        // Default
         n_format = number_formates(n);
        } else if (n < 900000) {
        // Thausand
       $n_format = number_formates(n / 1000, precision)+ 'K';
        } else if (n < 900000000) {
        // Million
        n_format = number_formates(n / 1000000, precision)+ 'M';
        } else if (n < 900000000000) {
        // Billion
        n_format = number_formates(n / 1000000000, precision)+ 'B';
        } else {
        // Trillion
        n_format = number_formates(n / 1000000000000, precision)+ 'T';
    }
    return n_format;
    }

// filter end;