  <?php
    $controler = $this->uri->segment(3);
    $char = substr($this->uri->segment(3), -8);
    // echo $a;
  ?>

<div class="row">
    <div class="col-md-12">
        <a name="bulan"></a>
        <div class="box">
            <div class="box-header with-border">
                <h3 class="box-title">Kunjungan Pasien Rawat <?php echo $title; ?></h3>
                <div class="box-tools pull-right">
                    <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
                    <a href="<?php echo base_url('admin/home'); ?>" class="btn btn-box-tool"><i class="fa fa-times"></i></a>
                </div>
            </div>
            
            <div class="box-body">
                <!-- <div class="row"> -->
                    <!-- <div class="col-md-6"> -->
                    
                      <!--<div class="form-group">-->
                      <!--  <label>Filter Periode</label>-->
                      <!--  <div class="input-group">-->
                      <!--    <div class="input-group-addon">-->
                      <!--      <i class="fa fa-calendar"></i>-->
                      <!--    </div>-->
                      <!--    <input class="form-control" id="filter" name="periode" onchange="periode();" placeholder="Masukkan periode waktu">-->
                      <!--  </div>-->
                      <!--</div>-->
                      
                    <!-- </div> -->
<!-- 
                    <div class="col-md-6">
                        <div class="form-group">
                          <label>Periode Bulanan</label>
                          <select class="form-control" id="periodebulan" name="periodebulan" onchange="periodebulan();">
                              <option>-- Pilih Bulan --</option>
                              <option value="01" <?php //if($this->uri->segment(4) == '01'){ echo 'selected="selected"'; } ?>>Januari</option>
                              <option value="02" <?php //if($this->uri->segment(4) == '02'){ echo 'selected="selected"'; } ?>>Februari</option>
                              <option value="03" <?php //if($this->uri->segment(4) == '03'){ echo 'selected="selected"'; } ?>>Maret</option>
                              <option value="04" <?php //if($this->uri->segment(4) == '04'){ echo 'selected="selected"'; } ?>>April</option>
                              <option value="05" <?php //if($this->uri->segment(4) == '05'){ echo 'selected="selected"'; } ?>>Mei</option>
                              <option value="06" <?php //if($this->uri->segment(4) == '06'){ echo 'selected="selected"'; } ?>>Juni</option>
                              <option value="07" <?php //if($this->uri->segment(4) == '07'){ echo 'selected="selected"'; } ?>>Juli</option>
                              <option value="08" <?php //if($this->uri->segment(4) == '08'){ echo 'selected="selected"'; } ?>>Agustus</option>
                              <option value="09" <?php //if($this->uri->segment(4) == '09'){ echo 'selected="selected"'; } ?>>September</option>
                              <option value="10" <?php //if($this->uri->segment(4) == '10'){ echo 'selected="selected"'; } ?>>Oktober</option>
                              <option value="11" <?php //if($this->uri->segment(4) == '11'){ echo 'selected="selected"'; } ?>>Nopember</option>
                              <option value="12" <?php //if($this->uri->segment(4) == '12'){ echo 'selected="selected"'; } ?>>Desember</option>
                          </select>
                        </div>
                    </div>
 -->                    
                <!-- </div> -->
                <center><h4><?php echo $periode; ?></h4></center>
                <div id="chart" class="chart"></div>
            </div>
            <div class="box-footer"><i class="fa fa-clock-o"></i> Data realtime</div>
        </div>
    </div>
</div>

<script type="text/javascript">
// ===== KUNJUNGAN IRJA HARI INI =====
var chart = AmCharts.makeChart( "chart", {
  "type": "serial",
  "theme": "light",
  "depth3D": 20,
  "angle": 30,
  "legend": {
    "align": "center",
    "horizontalGap": 10,
    "useGraphSettings": true,
    "markerSize": 10
  },
  "dataProvider": [
        <?php foreach ($data as $content){ ?>
        {
            "polycode" : "<?php echo $content->instalasi; ?>",
            "jkn" : <?php echo $content->jkn; ?>,
            "umum" : <?php echo $content->umum; ?>
        },
        <?php } ?>
  ],
  "valueAxes": [ {
    "stackType": "regular",
    "axisAlpha": 0,
    "gridAlpha": 0,
    "position": "left",
    "title": "Total Kunjungan"
  } ],
  "graphs": [ {
    "balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>",
    "fillAlphas": 0.8,
    "labelText": "[[value]]",
    "lineAlpha": 0.3,
    "title": "JKN",
    "type": "column",
    "color": "#000000",
    "valueField": "jkn"
  }, {
    "balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>",
    "fillAlphas": 0.8,
    "labelText": "[[value]]",
    "lineAlpha": 0.3,
    "title": "UMUM",
    "type": "column",
    "color": "#000000",
    "valueField": "umum"
  } ],
  "categoryField": "polycode",
  "categoryAxis": {
    "gridPosition": "start",
    "axisAlpha": 0,
    "gridAlpha": 0,
    "position": "left"
    //"labelRotation": 90
  },
  "export": {
    "enabled": true
  }

});

function periode(){
  var periode = document.getElementById("filter").value;
  window.location.replace("<?php echo base_url('admin/view/'.$this->uri->segment(3)); ?>"+'/'+periode+"");
}

$(function() {
    $('#filter').daterangepicker(
      {
        "opens": "center",
        format: "YYYY-MM-DD",
        separator: ' to ',
        ranges   : {
          'Today'       : [moment(), moment()],
          'Yesterday'   : [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
          'Last 7 Days' : [moment().subtract(6, 'days'), moment()],
          'Last 30 Days': [moment().subtract(29, 'days'), moment()],
          'This Month'  : [moment().startOf('month'), moment().endOf('month')],
          'Last Month'  : [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
        },
        startDate: moment().subtract(29, 'days'),
        endDate  : moment()
      },
      function (start, end) {
        $('#daterange-btn span').html(start.format('YYYY-MM-DD') + ' s.d. ' + end.format('YYYY-MM-DD'))
      }
    )
});
</script>