  var table 

  var query_y    = getQueryVariable("y");
  var query_m    = getQueryVariable("m");
  var query_d    = getQueryVariable("d");


  function get_total_plans(yy='not',mm='not',dd='not'){

    $.ajax({
                    url : 'models/crul_dashboard.php',
                    type : 'POST',
                    data : {
                              yy:yy,
                              mm:mm,
                              dd:dd,
                              type:'get_total_plans'
                            },
                    dataType : 'json',
                    success : function(response) {
                          
                          $("#total_plans").html((response[0]['total_price']));                          

                    },
                    complete: function() {
                           //  me.data('requestRunning', false);
                    }

              }); // submit ajax

  }

  function get_total_visit(yy='not',mm='not',dd='not'){

    $.ajax({
                    url : 'models/crul_dashboard.php',
                    type : 'POST',
                    data : {
                              yy:yy,
                              mm:mm,
                              dd:dd,
                              type:'get_total_visit'
                            },
                    dataType : 'json',
                    success : function(response) {
                          
                          $("#total_visits").html((response[0]['total_price']));                          

                    },
                    complete: function() {
                           //  me.data('requestRunning', false);
                    }

              }); // submit ajax

  }

  function get_total_doctor_visit(yy='not',mm='not',dd='not'){

    $.ajax({
                    url : 'models/crul_dashboard.php',
                    type : 'POST',
                    data : {
                              yy:yy,
                              mm:mm,
                              dd:dd,
                              type:'get_total_doctor_visit'
                            },
                    dataType : 'json',
                    success : function(response) {
                          
                          $("#total_doctor_visit").html((response[0]['total_price']));                          

                    },
                    complete: function() {
                           //  me.data('requestRunning', false);
                    }

              }); // submit ajax

  }

  function get_total_pharmacy_visit(yy='not',mm='not',dd='not'){

    $.ajax({
                    url : 'models/crul_dashboard.php',
                    type : 'POST',
                    data : {
                              yy:yy,
                              mm:mm,
                              dd:dd,
                              type:'get_total_pharmacy_visit'
                            },
                    dataType : 'json',
                    success : function(response) {
                          
                          $("#total_pharmacy_visit").html((response[0]['total_price']));                          

                    },
                    complete: function() {
                           //  me.data('requestRunning', false);
                    }

              }); // submit ajax

  }

  function get_total_doctor(yy='not',mm='not',dd='not'){

    $.ajax({
                    url : 'models/crul_dashboard.php',
                    type : 'POST',
                    data : {
                              yy:yy,
                              mm:mm,
                              dd:dd,
                              type:'get_total_doctor'
                            },
                    dataType : 'json',
                    success : function(response) {
                          
                          $("#total_doctor").html((response[0]['total_price']));                          

                    },
                    complete: function() {
                           //  me.data('requestRunning', false);
                    }

              }); // submit ajax

  }

  function get_total_pharmacy(yy='not',mm='not',dd='not'){

    $.ajax({
                    url : 'models/crul_dashboard.php',
                    type : 'POST',
                    data : {
                              yy:yy,
                              mm:mm,
                              dd:dd,
                              type:'get_total_pharmacy'
                            },
                    dataType : 'json',
                    success : function(response) {
                          
                          $("#total_pharmacy").html((response[0]['total_price']));                          

                    },
                    complete: function() {
                           //  me.data('requestRunning', false);
                    }

              }); // submit ajax

  }

  function get_total_product(yy='not',mm='not',dd='not'){

    $.ajax({
                    url : 'models/crul_dashboard.php',
                    type : 'POST',
                    data : {
                              yy:yy,
                              mm:mm,
                              dd:dd,
                              type:'get_total_product'
                            },
                    dataType : 'json',
                    success : function(response) {
                          
                          $("#total_product").html((response[0]['total_price']));                          

                    },
                    complete: function() {
                           //  me.data('requestRunning', false);
                    }

              }); // submit ajax

  }

  function get_total_ordered_product(yy='not',mm='not',dd='not'){

    $.ajax({
                    url : 'models/crul_dashboard.php',
                    type : 'POST',
                    data : {
                              yy:yy,
                              mm:mm,
                              dd:dd,
                              type:'get_total_ordered_product'
                            },
                    dataType : 'json',
                    success : function(response) {
                          
                          $("#total_ordered_product").html((response[0]['total_price']));                          

                    },
                    complete: function() {
                           //  me.data('requestRunning', false);
                    }

              }); // submit ajax

  }

  function get_total_delivery(yy='not',mm='not',dd='not'){

    $.ajax({
                    url : 'models/crul_dashboard.php',
                    type : 'POST',
                    data : {
                              yy:yy,
                              mm:mm,
                              dd:dd,
                              type:'get_total_delivery'
                            },
                    dataType : 'json',
                    success : function(response) {
                          
                          $("#total_delivery").html((response[0]['total_price']));                          

                    },
                    complete: function() {
                           //  me.data('requestRunning', false);
                    }

              }); // submit ajax

  }

  function get_total_not_delivery(yy='not',mm='not',dd='not'){

    $.ajax({
                    url : 'models/crul_dashboard.php',
                    type : 'POST',
                    data : {
                              yy:yy,
                              mm:mm,
                              dd:dd,
                              type:'get_total_not_delivery'
                            },
                    dataType : 'json',
                    success : function(response) {
                          
                          $("#total_not_delivery").html((response[0]['total_price']));                          

                    },
                    complete: function() {
                           //  me.data('requestRunning', false);
                    }

              }); // submit ajax

  }

  function get_total_in_way(yy='not',mm='not',dd='not'){

    $.ajax({
                    url : 'models/crul_dashboard.php',
                    type : 'POST',
                    data : {
                              yy:yy,
                              mm:mm,
                              dd:dd,
                              type:'get_total_in_way'
                            },
                    dataType : 'json',
                    success : function(response) {
                          
                          $("#total_in_way").html((response[0]['total_price']));                          

                    },
                    complete: function() {
                           //  me.data('requestRunning', false);
                    }

              }); // submit ajax

  }

  function get_total_saleman(yy='not',mm='not',dd='not'){

    $.ajax({
                    url : 'models/crul_dashboard.php',
                    type : 'POST',
                    data : {
                              yy:yy,
                              mm:mm,
                              dd:dd,
                              type:'get_total_saleman'
                            },
                    dataType : 'json',
                    success : function(response) {
                          
                          $("#total_saleman").html((response[0]['total_price']));                          

                    },
                    complete: function() {
                           //  me.data('requestRunning', false);
                    }

              }); // submit ajax

  }





  



  function get_pie_visit(yy='not',mm='not',dd='not',city_id=0){

      $.ajax({
                      url : 'models/crul_dashboard.php',
                      type : 'POST',
                      data : {
                                yy:yy,
                                mm:mm,
                                dd:dd,
                                city_id:city_id,
                                type:'get_pie_visit'
                              },
                      dataType : 'json',
                      success : function(response) {
                         
                         draw_pie_visit(response);
                          
                          
                      },
                      complete: function() {
                             
                      }

                }); // submit ajax

  }


  function get_pie_ordered(yy='not',mm='not',dd='not',city_id=0){

      $.ajax({
                      url : 'models/crul_dashboard.php',
                      type : 'POST',
                      data : {
                                yy:yy,
                                mm:mm,
                                dd:dd,
                                city_id:city_id,
                                type:'get_pie_ordered'
                              },
                      dataType : 'json',
                      success : function(response) {
                         
                         draw_pie_ordered(response);
                          
                          
                      },
                      complete: function() {
                             
                      }

                }); // submit ajax

  }


  function get_pie_expenses(yy='not',mm='not',dd='not'){

      $.ajax({
                      url : 'models/crul_dashboard.php',
                      type : 'POST',
                      data : {
                                yy:yy,
                                mm:mm,
                                dd:dd,
                                type:'get_pie_expenses'
                              },
                      dataType : 'json',
                      success : function(response) {
                         
                         draw_pie_expenses(response);
                          
                          
                      },
                      complete: function() {
                             
                      }

                }); // submit ajax

  }


  function get_pie_purchase(yy='not',mm='not',dd='not'){

      $.ajax({
                      url : 'models/crul_dashboard.php',
                      type : 'POST',
                      data : {
                                yy:yy,
                                mm:mm,
                                dd:dd,
                                type:'get_pie_purchase'
                              },
                      dataType : 'json',
                      success : function(response) {
                         
                         draw_pie_purchase(response);
                          
                          
                      },
                      complete: function() {
                             
                      }

                }); // submit ajax

  }





    

   


    


    function get_user_sells(){

      $.ajax({
                      url : 'models/crul_dashboard.php',
                      type : 'POST',
                      data : {type:'get_user_sells'},
                      dataType : 'json',
                      success : function(response) {
                          console.log(response)
                          var Balance_today     =0;
                          var Balance_yesterday =0;
                          var pri               = 0;
                          var tt =` <tr class="active border-double">
                                      <td colspan="5">Today</td>
                                      <td class="text-right">
                                        <span class="progress-meter" id="today-progress" data-progress="30"></span>
                                      </td>
                                    </tr>`;

                          var yy =` <tr class="active border-double">
                                      <td colspan="5">Yesterday</td>
                                      <td class="text-right">
                                        <span class="progress-meter" id="yesterday-progress" data-progress="65"></span>
                                      </td>
                                    </tr>`;
                          // just to calculate Total Sell price and compute the ratio

                          for (var i = 0; i < response.length; i++) {
                            pri = response[i][1] ;

                            if(response[i][5]==0){
                              Balance_today     = +Balance_today + +pri;
                            }else{
                              Balance_yesterday = +Balance_yesterday + +pri;
                            }
                            
                          }

                          for (var i = 0; i < response.length; i++) {
                            pri = response[i][1] ;
                            var img = "image/profile/noimg.png";
                            if(response[i][4] !=null && response[i][4] !=''){
                                img = "image/profile/"+response[i][4] ;
                            }
                            if(response[i][5]==0){
                              var ratio = pri * (100 / Balance_today);
                              ratio     = parseFloat(ratio).toFixed(2);
                               tt = tt + `

                                <tr>
                                  <td>
                                    <div class="media-left media-middle">
                                      <a href="#"><img src="`+img+`" class="img-circle img-xs" alt=""></a>
                                    </div>
                                    <div class="media-left">
                                      <div class=""><a href="#" class="text-default text-semibold">`+response[i][2]+`</a></div>
                                      <div class="text-muted text-size-small">
                                        <span class="status-mark border-blue position-left"></span>
                                        `+response[i][3]+`
                                      </div>
                                    </div>
                                  </td>
                                  <td><span class="text-muted">`+response[i][0]+`</span></td>
                                  <td><span class="text-success-600"><i class="icon-stats-growth2 position-left"></i>`+ratio+`%</span></td>
                                  <td><h6 class="text-semibold">`+currency_format_display(pri)+`</h6></td>
                                  <td><span class="label bg-blue">Active</span></td>
                                </tr>


                               
                            `;
                            }else{
                              var ratio = pri * (100 / Balance_yesterday);
                              ratio     = parseFloat(ratio).toFixed(2);
                              yy = yy + `

                                <tr>
                                  <td>
                                    <div class="media-left media-middle">
                                      <a href="#"><img src="`+img+`" class="img-circle img-xs" alt=""></a>
                                    </div>
                                    <div class="media-left">
                                      <div class=""><a href="#" class="text-default text-semibold">`+response[i][2]+`</a></div>
                                      <div class="text-muted text-size-small">
                                        <span class="status-mark border-blue position-left"></span>
                                        `+response[i][3]+`
                                      </div>
                                    </div>
                                  </td>
                                  <td><span class="text-muted">`+response[i][0]+`</span></td>
                                  <td><span class="text-success-600"><i class="icon-stats-growth2 position-left"></i>`+ratio+`%</span></td>
                                  <td><h6 class="text-semibold">`+currency_format_display(pri)+`</h6></td>
                                  <td><span class="label bg-blue">Active</span></td>
                                </tr>


                               
                              `;
                            }


                           

                          }
                            $("#user_active").html(response.length + " Activity");
                            $("#today").html(tt+yy);

                      },
                      complete: function() {
                             //  me.data('requestRunning', false);
                      }

                }); // submit ajax

    }

    function get_City(){

      $.ajax({
                      url : 'models/crul_city.php',
                      type : 'POST',
                      data : {type:'get'},
                      dataType : 'json',
                      success : function(response) {
                        console.log(response)
                          var attach ='<option value="" selected="selected">'+Translation('Select City')+'</option>';
                          
                            for(var i=response.length-1 ; i >= 0;i--){
                              
                              attach = attach + '<option value="'+response[i][0]+'">'+response[i][1]+'</option>';
                             

                            }
                            $("#city_id").html(attach);
                            $('#city_id').selectpicker('refresh');
                           

                      },
                      complete: function() {
                             //  me.data('requestRunning', false);
                      }

                }); // submit ajax

    }

    


$(document).ready(function() {

    get_City();
    
    // for top widget
    get_total_plans(query_y,query_m,query_d);
    get_total_visit(query_y,query_m,query_d);
    get_total_doctor_visit(query_y,query_m,query_d);
    get_total_pharmacy_visit(query_y,query_m,query_d);
    get_total_doctor(query_y,query_m,query_d);
    get_total_pharmacy(query_y,query_m,query_d);
    get_total_product(query_y,query_m,query_d);
    get_total_ordered_product(query_y,query_m,query_d);
    get_total_delivery(query_y,query_m,query_d);
    get_total_not_delivery(query_y,query_m,query_d);
    get_total_in_way(query_y,query_m,query_d);
    get_total_saleman(query_y,query_m,query_d);
    // end to widget

   

    //  FOr Pie Chart
    get_pie_visit(query_y,query_m,query_d);
    get_pie_ordered(query_y,query_m,query_d);
    // get_pie_expenses(query_y,query_m,query_d);
    // get_pie_purchase(query_y,query_m,query_d);


    $("#city_id").on('change',function(e){    
      var ID   = $(this).val();
      get_pie_visit(query_y,query_m,query_d,ID);
      get_pie_ordered(query_y,query_m,query_d,ID);
    });

   

    $("#select_date").html()

    $('#filter_btn').on('click',function(){
      
      if($("#year_filter").val()!='' || $("#month_filter").val()!='' ){
        var yy = $("#year_filter").val();
        var mm = $("#month_filter").val();
        
        var _href ="index.php?p=dashboard";

        if(yy !=''){
         
          _href = _href + "&y="+yy;
        }

        if(mm !=''){
         
          _href = _href + "&m="+mm;
        }


        if($("#day_filter").val()!=''){
          var dd = $("#day_filter").val();
          _href = _href + "&d="+dd;
        }

      
        window.location = _href;
      }else{
            swal({
                    title:"Error",
                    text: Translation('الرجاء قم بتحديد السنة وا الشهر'),
                    confirmButtonColor: "#66BB6A",
                    type: "warning"
                });
      }


    });

  

});
  

function draw_pie_visit(res){

    var months_val = ['0','0','0','0','0','0','0','0','0','0','0','0','0'];

    for (var i = 0; i < res.length; i++) {
                            
        months_val[res[i].montn_no] = res[i].no_of_orders

    }


    if(res.length ==0){
      if(query_y =='not'){
        var yyy = (new Date()).getFullYear();
      }else{
        var yyy = query_y;
      }
      
    }else{
      var yyy = res[0].year;
    }
  
    require.config({
          paths: {
              echarts: 'assets/js/plugins/visualization/echarts'
          }
      });


     
     

      // Configuration
      // ------------------------------

      require(
          [
              'echarts',
              'echarts/theme/limitless',
              'echarts/chart/bar',
              'echarts/chart/line',
              'echarts/chart/pie',
              'echarts/chart/funnel'
          ],


          // Charts setup
          function (ec, limitless) {


              // Initialize charts
              // ------------------------------

               var rose_diagram_visible = ec.init(document.getElementById('rose_diagram_visible'), limitless);
             
              // Charts setup
              // ------------------------------                    

  
              //
              // Nightingale roses with visible labels options
              //

              rose_diagram_visible_options = {

                  // Add title
                  title: {
                      text: 'Visit\'s review',
                      subtext: yyy,
                      x: 'center'
                  },

                  // Add tooltip
                  tooltip: {
                      trigger: 'item',
                      formatter: "{a} <br/>{b}: +{c} ({d}%)"
                  },

                  // Add legend
                  legend: {
                      x: 'left',
                      y: 'top',
                      orient: 'vertical',
                      data: ['January','February','March','April','May','June','July','August','September','October','November','December']
                  },

                  // Display toolbox
                  toolbox: {
                      show: true,
                      orient: 'vertical',
                      feature: {
                          mark: {
                              show: true,
                              title: {
                                  mark: 'Markline switch',
                                  markUndo: 'Undo markline',
                                  markClear: 'Clear markline'
                              }
                          },
                          dataView: {
                              show: true,
                              readOnly: false,
                              title: 'View data',
                              lang: ['View chart data', 'Close', 'Update']
                          },
                          magicType: {
                              show: true,
                              title: {
                                  pie: 'Switch to pies',
                                  funnel: 'Switch to funnel',
                              },
                              type: ['pie', 'funnel']
                          },
                          restore: {
                              show: true,
                              title: 'Restore'
                          },
                          saveAsImage: {
                              show: true,
                              title: 'Same as image',
                              lang: ['Save']
                          }
                      }
                  },

                  // Enable drag recalculate
                  calculable: false,

                  // Add series
                  series: [
                      {
                          name: 'Number of Visits',
                          type: 'pie',
                          radius: ['15%', '73%'],
                          center: ['50%', '57%'],
                          roseType: 'area',

                          // Funnel
                          width: '40%',
                          height: '78%',
                          x: '30%',
                          y: '17.5%',
                          max: 450,
                          sort: 'ascending',

                          data: [
                              {value: months_val[1], name: 'January'},
                              {value: months_val[2], name: 'February'},
                              {value: months_val[3], name: 'March'},
                              {value: months_val[4], name: 'April'},
                              {value: months_val[5], name: 'May'},
                              {value: months_val[6], name: 'June'},
                              {value: months_val[7], name: 'July'},
                              {value: months_val[8], name: 'August'},
                              {value: months_val[9], name: 'September'},
                              {value: months_val[10], name: 'October'},
                              {value: months_val[11], name: 'November'},
                              {value: months_val[12], name: 'December'}
                          ]
                      }
                  ]
              };


             



              // Apply options
              // ------------------------------
              rose_diagram_visible.setOption(rose_diagram_visible_options);
              


              // Resize charts
              // ------------------------------

              window.onresize = function () {
                  setTimeout(function (){

                      rose_diagram_visible.resize();
                   }, 200);
              }
          }


         
      );
}




function draw_pie_ordered(res){

    var months_val = ['0','0','0','0','0','0','0','0','0','0','0','0','0'];

    for (var i = 0; i < res.length; i++) {
                            
        months_val[res[i].montn_no] = res[i].final_price

    }


    if(res.length ==0){
      if(query_y =='not'){
        var yyy = (new Date()).getFullYear();
      }else{
        var yyy = query_y;
      }
      
    }else{
      var yyy = res[0].year;
    }
  
    require.config({
          paths: {
              echarts: 'assets/js/plugins/visualization/echarts'
          }
      });


     
     

      // Configuration
      // ------------------------------

      require(
          [
              'echarts',
              'echarts/theme/limitless',
              'echarts/chart/bar',
              'echarts/chart/line',
              'echarts/chart/pie',
              'echarts/chart/funnel'
          ],


          // Charts setup
          function (ec, limitless) {


              // Initialize charts
              // ------------------------------

               var rose_diagram_visible = ec.init(document.getElementById('rose_diagram_visible_sells'), limitless);
             
              // Charts setup
              // ------------------------------                    

  
              //
              // Nightingale roses with visible labels options
              //

              rose_diagram_visible_options = {

                  // Add title
                  title: {
                      text: 'Ordered Quantity Poroducts',
                      subtext: yyy,
                      x: 'center'
                  },

                  // Add tooltip
                  tooltip: {
                      trigger: 'item',
                      formatter: "{a} <br/>{b} : {c} Qty ({d}%)"
                  },

                  // Add legend
                  legend: {
                      x: 'left',
                      y: 'top',
                      orient: 'vertical',
                      data: ['January','February','March','April','May','June','July','August','September','October','November','December']
                  },

                  // Display toolbox
                  toolbox: {
                      show: true,
                      orient: 'vertical',
                      feature: {
                          mark: {
                              show: true,
                              title: {
                                  mark: 'Markline switch',
                                  markUndo: 'Undo markline',
                                  markClear: 'Clear markline'
                              }
                          },
                          dataView: {
                              show: true,
                              readOnly: false,
                              title: 'View data',
                              lang: ['View chart data', 'Close', 'Update']
                          },
                          magicType: {
                              show: true,
                              title: {
                                  pie: 'Switch to pies',
                                  funnel: 'Switch to funnel',
                              },
                              type: ['pie', 'funnel']
                          },
                          restore: {
                              show: true,
                              title: 'Restore'
                          },
                          saveAsImage: {
                              show: true,
                              title: 'Same as image',
                              lang: ['Save']
                          }
                      }
                  },

                  // Enable drag recalculate
                  calculable: false,

                  // Add series
                  series: [
                      {
                          name: 'Total Ordered Quantity',
                          type: 'pie',
                          radius: ['15%', '73%'],
                          center: ['50%', '57%'],
                          roseType: 'area',

                          // Funnel
                          width: '40%',
                          height: '78%',
                          x: '30%',
                          y: '17.5%',
                          max: 450,
                          sort: 'ascending',

                          data: [
                              {value: months_val[1], name: 'January'},
                              {value: months_val[2], name: 'February'},
                              {value: months_val[3], name: 'March'},
                              {value: months_val[4], name: 'April'},
                              {value: months_val[5], name: 'May'},
                              {value: months_val[6], name: 'June'},
                              {value: months_val[7], name: 'July'},
                              {value: months_val[8], name: 'August'},
                              {value: months_val[9], name: 'September'},
                              {value: months_val[10], name: 'October'},
                              {value: months_val[11], name: 'November'},
                              {value: months_val[12], name: 'December'}
                          ]
                      }
                  ]
              };


             



              // Apply options
              // ------------------------------
              rose_diagram_visible.setOption(rose_diagram_visible_options);
              


              // Resize charts
              // ------------------------------

              window.onresize = function () {
                  setTimeout(function (){

                      rose_diagram_visible.resize();
                   }, 200);
              }
          }


         
      );
}



function draw_pie_expenses(res){

    var months_val = ['0','0','0','0','0','0','0','0','0','0','0','0','0'];

    for (var i = 0; i < res.length; i++) {
                            
        months_val[res[i].montn_no] = res[i].final_price

    }


    if(res.length ==0){
      if(query_y =='not'){
        var yyy = (new Date()).getFullYear();
      }else{
        var yyy = query_y;
      }
      
    }else{
      var yyy = res[0].year;
    }
  
    require.config({
          paths: {
              echarts: 'assets/js/plugins/visualization/echarts'
          }
      });


     
     

      // Configuration
      // ------------------------------

      require(
          [
              'echarts',
              'echarts/theme/limitless',
              'echarts/chart/bar',
              'echarts/chart/line',
              'echarts/chart/pie',
              'echarts/chart/funnel'
          ],


          // Charts setup
          function (ec, limitless) {


              // Initialize charts
              // ------------------------------

               var rose_diagram_visible = ec.init(document.getElementById('rose_diagram_visible_expenses'), limitless);
             
              // Charts setup
              // ------------------------------                    

  
              //
              // Nightingale roses with visible labels options
              //

              rose_diagram_visible_options = {

                  // Add title
                  title: {
                      text: 'Expense\'s review',
                      subtext: yyy,
                      x: 'center'
                  },

                  // Add tooltip
                  tooltip: {
                      trigger: 'item',
                      formatter: "{a} <br/>{b}: {c} $ ({d}%)"
                  },

                  // Add legend
                  legend: {
                      x: 'left',
                      y: 'top',
                      orient: 'vertical',
                      data: ['January','February','March','April','May','June','July','August','September','October','November','December']
                  },

                  // Display toolbox
                  toolbox: {
                      show: true,
                      orient: 'vertical',
                      feature: {
                          mark: {
                              show: true,
                              title: {
                                  mark: 'Markline switch',
                                  markUndo: 'Undo markline',
                                  markClear: 'Clear markline'
                              }
                          },
                          dataView: {
                              show: true,
                              readOnly: false,
                              title: 'View data',
                              lang: ['View chart data', 'Close', 'Update']
                          },
                          magicType: {
                              show: true,
                              title: {
                                  pie: 'Switch to pies',
                                  funnel: 'Switch to funnel',
                              },
                              type: ['pie', 'funnel']
                          },
                          restore: {
                              show: true,
                              title: 'Restore'
                          },
                          saveAsImage: {
                              show: true,
                              title: 'Same as image',
                              lang: ['Save']
                          }
                      }
                  },

                  // Enable drag recalculate
                  calculable: false,

                  // Add series
                  series: [
                      {
                          name: 'Total Expense Price',
                          type: 'pie',
                          radius: ['15%', '73%'],
                          center: ['50%', '57%'],
                          roseType: 'area',

                          // Funnel
                          width: '40%',
                          height: '78%',
                          x: '30%',
                          y: '17.5%',
                          max: 450,
                          sort: 'ascending',

                          data: [
                              {value: months_val[1], name: 'January'},
                              {value: months_val[2], name: 'February'},
                              {value: months_val[3], name: 'March'},
                              {value: months_val[4], name: 'April'},
                              {value: months_val[5], name: 'May'},
                              {value: months_val[6], name: 'June'},
                              {value: months_val[7], name: 'July'},
                              {value: months_val[8], name: 'August'},
                              {value: months_val[9], name: 'September'},
                              {value: months_val[10], name: 'October'},
                              {value: months_val[11], name: 'November'},
                              {value: months_val[12], name: 'December'}
                          ]
                      }
                  ]
              };


             



              // Apply options
              // ------------------------------
              rose_diagram_visible.setOption(rose_diagram_visible_options);
              


              // Resize charts
              // ------------------------------

              window.onresize = function () {
                  setTimeout(function (){

                      rose_diagram_visible.resize();
                   }, 200);
              }
          }


         
      );
}


function draw_pie_purchase(res){

    var months_val = ['0','0','0','0','0','0','0','0','0','0','0','0','0'];

    for (var i = 0; i < res.length; i++) {
                            
        months_val[res[i].montn_no] = res[i].final_price

    }


    if(res.length ==0){
      if(query_y =='not'){
        var yyy = (new Date()).getFullYear();
      }else{
        var yyy = query_y;
      }
      
    }else{
      var yyy = res[0].year;
    }
  
    require.config({
          paths: {
              echarts: 'assets/js/plugins/visualization/echarts'
          }
      });


     
     

      // Configuration
      // ------------------------------

      require(
          [
              'echarts',
              'echarts/theme/limitless',
              'echarts/chart/bar',
              'echarts/chart/line',
              'echarts/chart/pie',
              'echarts/chart/funnel'
          ],


          // Charts setup
          function (ec, limitless) {


              // Initialize charts
              // ------------------------------

               var rose_diagram_visible = ec.init(document.getElementById('rose_diagram_visible_purchase'), limitless);
             
              // Charts setup
              // ------------------------------                    

  
              //
              // Nightingale roses with visible labels options
              //

              rose_diagram_visible_options = {

                  // Add title
                  title: {
                      text: 'Purchase\'s Review',
                      subtext: yyy,
                      x: 'center'
                  },

                  // Add tooltip
                  tooltip: {
                      trigger: 'item',
                      formatter: "{a} <br/>{b}: {c} $ ({d}%)"
                  },

                  // Add legend
                  legend: {
                      x: 'left',
                      y: 'top',
                      orient: 'vertical',
                      data: ['January','February','March','April','May','June','July','August','September','October','November','December']
                  },

                  // Display toolbox
                  toolbox: {
                      show: true,
                      orient: 'vertical',
                      feature: {
                          mark: {
                              show: true,
                              title: {
                                  mark: 'Markline switch',
                                  markUndo: 'Undo markline',
                                  markClear: 'Clear markline'
                              }
                          },
                          dataView: {
                              show: true,
                              readOnly: false,
                              title: 'View data',
                              lang: ['View chart data', 'Close', 'Update']
                          },
                          magicType: {
                              show: true,
                              title: {
                                  pie: 'Switch to pies',
                                  funnel: 'Switch to funnel',
                              },
                              type: ['pie', 'funnel']
                          },
                          restore: {
                              show: true,
                              title: 'Restore'
                          },
                          saveAsImage: {
                              show: true,
                              title: 'Same as image',
                              lang: ['Save']
                          }
                      }
                  },

                  // Enable drag recalculate
                  calculable: false,

                  // Add series
                  series: [
                      {
                          name: 'Total Purchase Price',
                          type: 'pie',
                          radius: ['15%', '73%'],
                          center: ['50%', '57%'],
                          roseType: 'area',

                          // Funnel
                          width: '40%',
                          height: '78%',
                          x: '30%',
                          y: '17.5%',
                          max: 450,
                          sort: 'ascending',

                          data: [
                              {value: months_val[1], name: 'January'},
                              {value: months_val[2], name: 'February'},
                              {value: months_val[3], name: 'March'},
                              {value: months_val[4], name: 'April'},
                              {value: months_val[5], name: 'May'},
                              {value: months_val[6], name: 'June'},
                              {value: months_val[7], name: 'July'},
                              {value: months_val[8], name: 'August'},
                              {value: months_val[9], name: 'September'},
                              {value: months_val[10], name: 'October'},
                              {value: months_val[11], name: 'November'},
                              {value: months_val[12], name: 'December'}
                          ]
                      }
                  ]
              };


             



              // Apply options
              // ------------------------------
              rose_diagram_visible.setOption(rose_diagram_visible_options);
              


              // Resize charts
              // ------------------------------

              window.onresize = function () {
                  setTimeout(function (){

                      rose_diagram_visible.resize();
                   }, 200);
              }
          }


         
      );
}

  


$(function() {

  


  if(query_y != 'not' ){
    $("#year_filter").val(query_y);
  }

  if( query_m != 'not'){
    $("#month_filter").val(query_m);
  }

  
  if(query_d != 'not'){
    $("#day_filter").val(query_d);
  }

    // Set paths
    // ------------------------------

    





});



