<?php
date_default_timezone_set("Asia/Jakarta");
?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            Data Rekam Medis
            <small>Klinik</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li class="active">Record</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">

        <!-- SELECT2 EXAMPLE -->
        <div class="box box-primary">
            <div class="box-header with-border">
                <h3 class="box-title">Rekam Medis</h3>
                <div class="box-tools pull-right">
                    <button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
                    <button class="btn btn-box-tool" data-widget="remove"><i class="fa fa-remove"></i></button>
                </div>
            </div><!-- /.box-header -->
            <div class="box-body">
            <?php
                // Session 
                if ($this->session->flashdata('message')) {
                    echo $this->session->flashdata('message');
                }
            ?>
            <form action="<?= base_url('RekamMedis/filterdelete'); ?>" method="get">
                    <label for="">Tanggal</label>
                    <div class="input-group">
                        <div class="input-group-addon">
                            <i class="fa fa-calendar"></i>
                        </div>
                        <input type="date" onfocus="this.showPicker()" required name="tanggal" value="<?php echo $tanggal; ?>" class="form-control pull-right" width="20%">
                    </div><!-- /.input group -->
                    <button class="btn btn-primary" style="margin-top:8px;"><i class="fa fa-search"></i> Cari</button>
                </form>
                <br>
                <small>
                <form id="myForm" method="post" action="<?= base_url('rekamMedis/prosesdeletefilter') ?>" enctype="multipart/form-data">
                 <button type="button" onclick="checkIsChecked();" id="btnBulkProses" class="btn btn-danger"><i class="fa fa-trash fa-fw"></i> Bulk Proses</button>
                   <br><br>
                    <table id="example1" class="table table-bordered table-hover table-striped">
                        <thead>
                            <tr>
                                <th><input type="checkbox" id="checkAll" value="1"></th>
                                <th>No.</th>
                                <th>Case ID</th>
                                <th>Nama</th>
                                <th>Penjamin</th>
                                <th>Status Pasien</th>
                                <th>Tanggal Kunjungan</th>
                                <th>Opsi</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $no = 1;
                            foreach ($record as $data) :
                            ?>
                            <tr>
                                <td><input type="checkbox" name="proses[]" value="<?=  $data['Case ID']  ?>" class="checkBoxMonitoring"></td>
                                <td><?= $no++; ?></td>
                                <td><?= $data['Case ID']; ?></td>
                                <td><?= $data['Description']; ?></td>
                                <td><?= $data['CompanyName']; ?></td>
                                <td><?= $data['RegStatus']; ?></td>
                                <td><?= date("d/m/Y", strtotime($data['Intake Date'])); ?></td>
                                <td>
                                <a href="<?= base_url('rekamMedis/pemeriksaan/'.$data['Case ID']); ?>" style="width: 50%" class="btn btn-sm btn-success"><i class="fa fa-fw fa-book"></i> Lihat Detail</a>
                                <a href="<?= base_url('rekamMedis/deletepemeriksaan/'.$data['Case ID']); ?>" onclick="return confirm('Apakah anda yakin ingin menghapus Data Ini ?');" class="btn btn-sm btn-danger"><i class="fa fa-fw fa-trash"></i>Delete</a>
                                </td>
                            </tr>
                            <?php
                            endforeach;
                            ?>
                        </tbody>
                        <tfoot>
                            <tr>
                                <th>No.</th>
                                <th>Case ID</th>
                                <th>Nama</th>
                                <th>Penjamin</th>
                                <th>Status Pasien</th>
                                <th>Tanggal Kunjungan</th>
                                <th>Opsi</th>
                            </tr>
                        </tfoot>
                    </table>
                </form>
                </small>
            </div><!-- /.box-body -->
            <div class="box-footer">
                <small>Daftar Pasien <?= date('d F Y'); ?> - @Klinik <?= date('Y'); ?></small>
            </div>
        </div><!-- /.box -->

    </section><!-- /.content -->
</div><!-- /.content-wrapper -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
    $('#checkAll').on('click', function() {
        $(this).closest('table').find('tbody :checkbox')
            .prop('checked', this.checked)
            .closest('tr').toggleClass('selected', this.checked);
    });


    function checkIsChecked() {
        var isChecked = false;
        $('#example1').find('input[type="checkbox"]:checked').each(function() {
            isChecked = true;
        });

        if (isChecked) {
            if (confirm("Apakah yakin akan dihapus data yang dipilih?") == true) {
                document.getElementById("btnBulkProses").disabled = true;
                document.getElementById("myForm").submit();
            }
        } else {
            alert('silahkan pilih data');
        }
    }

    function prosesMonitoring($caseId) {

        if (confirm("Apakah yakin akan dihapus?") == true) {
            var url = "<?= base_url() ?>" + "rekamMedis/prosesdeletefilter1?c=" + $caseId;
            window.location = url;
        }
    }
</script>