<div class="row" id="filter-content" style="<?=$active!='kasir'?'display: none':''?>">
  <div class="col-md-12">
    <div class="portlet light">
      <div class="portlet-title">
        <div class="caption">
          <i class="fa fa-filter"></i>Filter Data
        </div>
      </div>
      <div class="portlet-body form">
        <form id="form-filter" class="horizontal-form">
          <div class="form-body">
            <div class="row">
              <div class="col-md-2">
                <div class="form-group" id="form_tgl_kunjungan">
                  <label for="tgl_kunjungan" class="control-label">Dari Tanggal</label>
                  <div class="input-group date" id="datepicker_tglkun">
                    <span class="input-group-btn">
                        <button class="btn default" type="button"><i class="fa fa-calendar"></i></button>
                    </span>
                    <input type="text" id="tgl_kunjungan" name="tgl_kunjungan" class="form-control" placeholder="Tanggal Kunjungan" value="<?=isset($filter_tgl)?$filter_tgl:date('Y-m-d')?>">
                  </div>                  
                </div>
              </div>

              <div class="col-md-2">
                <div class="form-group" id="form_tgl_kunjungan">
                  <label for="tgl_kunjungan" class="control-label">Sampai</label>
                  <div class="input-group date" id="datepicker_tglkun2">
                    <span class="input-group-btn">
                        <button class="btn default" type="button"><i class="fa fa-calendar"></i></button>
                    </span>
                    <input type="text" id="tgl_kunjungan2" name="sampai_tgl" class="form-control" placeholder="Sampai" value="<?=isset($filter_tgl_sampai)?$filter_tgl_sampai:date('Y-m-d')?>">
                  </div>                  
                </div>
              </div>

              <div class="col-md-2">
                <div class="form-group" id="form_no_rekam_medis">
                  <label for="no_rekam_medis" class="control-label">Tipe Pasien</label><br>
                  <select name="id_tipe_pasien" class="form-control">
                      <option value="">Semua Tipe</option>
                      <?php foreach ($this->Content_m->select_db('bbmc_re_tipe_pasien')->result() as $key ) { ?>
                          <option value="<?=$key->id_tipe_pasien?>"><?=$key->tipe_pasien?></option>
                      <?php }?>
                  </select>         
                </div>
              </div>

              <div class="col-md-2">
                <div class="form-group" id="form_no_rekam_medis">
                  <label for="no_rekam_medis" class="control-label">No. RM</label>
                  <div class="input-group">
                    <span class="input-group-addon">BBMC - </span>
                    <input type="text" id="no_rekam_medis" name="no_rekam_medis" class="form-control" placeholder="Nomor RM">
                  </div>                   
                </div>
              </div>
              <div class="col-md-2">
                <div class="form-group" id="form_nama_pasien">
                  <label for="nama_pasien" class="control-label">Nama Pasien</label>
                  <input type="text" id="nama_pasien" name="nama_pasien" class="form-control" placeholder="Nama Pasien">
                </div>
              </div>
              
              <div class="col-md-2">
                <div class="form-group" id="form_nama_pasien">
                  <label for="nama_pasien" class="control-label">&nbsp;</label><br>
                  
                  <button class="btn green-jungle btn-sm" id="tampilkan" style="padding: 8.5px; width: 100%">
                    <i class="fa fa-search"></i> Tampilkan
                  </button>
                </div>
              </div>

              

            </div>
          </div>
            
          <div class="form-actions right">
            <!--
            <a class="btn yellow-lemon btn-sm" id="reset-filter">
              <i class="fa fa-refresh"></i> Reset Filter
            </a>
           
            <button class="btn green-jungle btn-sm" id="tampilkan">
              <i class="fa fa-search"></i> Tampilkan
            </button>
             -->
          </div>
        </form>
      </div>
    </div>
  </div>
</div>

<?=$this->session->flashdata('msg')?>

<div class="row" id="portlet-content">
  <div class="col-md-12">
    <div class="portlet light" style="position:relative">
      <div class="portlet-title col-md-4">
        <div class="caption">
          <i class="fa fa-th-list"></i>Data <?= $judul ?>
        </div>
      </div>
      <div class="col-md-8" id="tombol-added" style="margin-bottom:5px; padding:0px; border-bottom:0px" id="tombol-action" style="display:none">
        <div style="float:right; overflow:hidden; margin-top:5px;">
          
          <?php if($active != 'kasir'){ ?>
          <a class="btn btn-sm" id="reset-filter">
            <i class="fa fa-book"></i> Tampilkan semua data
          </a>
          <a class="btn red-soft btn-sm" id="filter">
            <i class="fa fa-filter"></i> Filter Data
          </a>
         
          <?php }?>
          <!--
          <a class="btn green btn-sm" target="_Blank" href="<?=site_url()?>/front_office/reg_dir/registrasi/whole_print">
            <i class="fa fa-print"></i> Print
          </a>
          -->
          <?php if($active!='kasir'){ ?>
          <!--
          <a class="btn blue btn-sm" href="<?= site_url('front_office/'.$controller_dir.$controller.'/tambah_kunjungan') ?>">
            <i class="fa fa-plus"></i> Tambah
          </a>   
          -->
          <?php }?>  
        </div>
      </div>
      <div class="portlet-body" id="page-content" style="display:none">
        <div class="table-responsive">
          <table id="<?= $controller ?>_table" class="table table-bordered table-hover" style="width:100%; font-size:11px !important">
            <thead>
              <tr  style="background:#5578eb; color:#ffffff;">
                <th class="text-left" style="min-width: 80px; text-transform: uppercase;"><i class="fa fa-th-large"></i></th>
                <th class="text-left" style="text-transform: uppercase;">No</th>
                <th class="text-left" style="min-width: 80px; text-transform: uppercase;">Registrasi</th>
                <th class="text-left" style="text-transform: uppercase;">TIPE</th>
                
                <th class="text-left" style="min-width: 80px; text-transform: uppercase;">Perawatan</th>
                <th class="text-left" style="min-width: 130px; text-transform: uppercase;">Tgl Kunjungan</th>
                <th class="text-left" style="min-width: 70px; text-transform: uppercase;">No. RM</th>
                
                <th class="text-left" style="min-width: 250px; text-transform: uppercase;">Nama Pasien</th>
                <th class="text-left" style="min-width: 140px; text-transform: uppercase;"><?=$active=='kasir'?'Tagihan':'Rujukan Dari'?></th>
                <th class="text-left" style="min-width: 130px; text-transform: uppercase;">Type Perawatan</th>
                
              </tr>
            </thead>
            
          </table>
          <br><br>
          <div style="font-size:9px; line-height: 13px">
          <i>
          Keterangan:<br>
          *Batalkan pemeriksaan jika ingin menghapus kunjungan. <br>*Pembatalan pemeriksaan hanya bisa dilakukan oleh akun dokter.</i>
          </div>
        </div>
      </div>
      <?php $this->load->view('front_office/include/loading'); ?>
    </div>
  </div>
</div>

<script>
  $(document).ready(function() {
    var table = $('#<?=$controller?>_table').DataTable({
      "order": [[2, 'asc' ]],
      "processing": true,
      "serverSide": true,
      "searching": true,
      "searching": false,
      //"lengthChange": false,
      "language": {
            "url": "<?=base_url('media/assets/global/plugins/datatables/media/js')?>/indonesian.json"
      },
       "aLengthMenu": [
        [10, 50, 100, 200, -1],
        [10, 50, 100, 200, "All"]
    ],
      "ajax": {
            url: "<?=site_url('front_office/'.$controller_dir.$controller.'/data_table'.'/'.$active)?>"+"?filter=true",
            type: 'POST',
            data: function (d) {
                d.form_filter = $('#form-filter').serialize();
                return d;
            }
      },
      "dom": "Blfrtip",
      "buttons": [
         'excel'
      ],
      
      "columnDefs": [
        //{"className": "text-left", "targets": [0,2,3,4,5,6,7,8,9,10,11,12,13,-1]}, // Class to assign to each cell in the column
         {"className": "text-center", "targets": [1]},
        {
          "targets": [0,-1],
          "bSortable": false // Enable or disable ordering on this column v 1.10++ (columns.orderable)
        }
      ],    
      "columns": [
            {"data": "aksi"},       
            {"data": "i"},      
            {"data": "tgl_registrasi"},
            {"data": "id_type_pasien"},
            
                 
            {"data": "status_perawatan"},
            {"data": "tgl_kunjungan"},
            {"data": "no_kunjungan"},
            
            {"data": "nama_pasien"},
            {"data": "rujukan_dari"},
            
            {"data": "type_perawatan"},
            /*
            {"data": "pemeriksaan_khusus"},
            {"data": "keluhan"},
            {"data": "no_surat"},      
            {"data": "nama_penanggung"},
            {"data": "alamat_penanggung"},
            {"data": "tlp_penanggung"},      
            {"data": "hub_dgn_pasien"},
            */
                
      ],
      "fnInitComplete": function(oSettings, json) {
        $('.dataTables_processing').css('display','none');
        $( "#loading-content" ).fadeOut( "fast", function() {
          $( "#tombol-action" ).fadeIn("fast");
          $( "#page-content" ).fadeIn("fast");
        });
      } 
    });   

    $('#form-filter').submit(function() {
        $('html, body').animate({scrollTop: $('#portlet-content').offset().top-70},500);
        table.ajax.url("<?=site_url('front_office/'.$controller_dir.$controller.'/data_table'.'/'.$active)?>"+"?filter=true").load();
        return false;
    });

     

    $('#reset-filter').click(function() {
      $('html, body').animate({scrollTop: $('#portlet-content').offset().top-70},500);
      $('#tgl_kunjungan, #tgl_kunjungan2, #tipe_pasien, #no_rekam_medis, #nama_pasien').val("");
      $('#<?=$controller?>_table').dataTable().fnSort([[ 2, 'asc' ]]);
      table.ajax.url("<?=site_url('front_office/'.$controller_dir.$controller.'/data_table'.'/'.$active)?>"+"?filter=true").load();
    });

    $('#tgl_kunjungan').datepicker({
      dateFormat: 'yy-mm-dd',
      clearBtn: true,
      language: 'id',
      autoclose: true,
      todayHighlight: true,
      changeMonth: true,
      changeYear: true
    });

  });

    /*-------------Datepicker-------------*/
    /*
    $('#datepicker_tglkun').datepicker({
      format: "yyyy-mm-dd",
      clearBtn: true,
      language: 'id',
      autoclose: true,
      todayHighlight: true
    });
    */

    $('#datepicker_tglkun2').datepicker({
      format: "yyyy-mm-dd",
      clearBtn: true,
      language: 'id',
      autoclose: true,
      todayHighlight: true
    });

    $("#type_perawatan").select2({
      placeholder: "Pilih Type Perawatan",
      closeOnSelect: false,
      language: "id"
    });     

    $('#filter').click(function() {
      $( "#filter-content" ).slideToggle('fast');
    });

  $('.hapusdata').click(function() {
    if(confirm("Apakah kamu yakin menghapus entry ini?")) {
      return true;
    }
    else {
      return false;
    }
  });
</script>
<?php $this->load->view('front_office/script/hapus_data');?>
