<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            Apotik Pharmacy <label style="font-weight: normal; font-size:15px" id="timer"></label>
            <small><?= $abdulradjak['NamaPerusahaan']; ?></small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Vclaim</a></li>
            <li class="active">Data Pasien</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <!-- Default box -->
        <?php
        if ($Countpasien > 0) {
        ?>
            <!-- <audio src="<?= base_url('aset/bell.mp3'); ?>" id="my_audio" loop="loop"></audio>
            <script type="text/javascript">
                setTimeout(function() {
                    document.getElementById("my_audio").play();
                    console.log("play sound");
                }, 3000) -->
            </script>
            <div class="row">
                <div class="col-md-12">
                    <div class="box box-warning box-solid" id="status">
                        <div class="box-header with-border">
                            <h3 class="box-title">Permintaan Baru</h3>
                            <div class="box-tools pull-right">
                                <button class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                            </div><!-- /.box-tools -->
                        </div><!-- /.box-header -->
                        <div class="box-body">
                            <?php
                            $noted = $this->db->query("SELECT TOP 1 * FROM Resep_Header WHERE [Status] = '1' ORDER BY InTakeDate DESC")->row_array();
                            $sNm = $noted['CaseID'];
                            $nM = $this->db->query("SELECT [Description] FROM Cases WHERE [Case ID] = '$sNm'")->row_array();

                            ?>
                            Pasien masuk atas nama <b><?= $nM['Description']; ?></b>
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->
                </div>
            </div>
        <?php
        }
        ?>

        <div class="box">
            <div class="box-body">
                <small>
                    <table id="example1" class="table table-bordered table-striped">
                        <thead>
                            <tr>
                                <th>Resep ID</th>
                                <th>Intake Date</th>
                                <th>Case ID</th>
                                <th>Nama</th>
                                <th>Kategori</th>
                                <th>Dokter Pengirim</th>
                                <th>Jaminan</th>
                                <th>No Antrian</th>
                                <th>Jenis</th>
                                <th>Aleri Obat</th>
                                <th>Opsi</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $jenisNo = 1;
                            foreach ($pasien as $data) :
                                $un = $data['CaseID'];
                                $cm = $data['CompanyCode'];
                                $dUn = $this->db->query("SELECT * FROM CaseAdmin WHERE [Case ID] = '$un'")->row_array();
                                $dCm = $this->db->query("SELECT * FROM Company WHERE [CompanyCode] = '$cm'")->row_array();
                            ?>
                                <tr>
                                    <td><?= $data['ResepId']; ?></td>
                                    <td><?= $data['Intake Date']; ?></td>
                                    <td><?= $data['CaseID']; ?></td>
                                    <td><?= $data['Description']; ?></td>
                                    <td>
                                        <?php
                                        if ($data['Category'] == "IP") {
                                            echo "R.Inap";
                                        } else if ($data['Category'] == "OP") {
                                            echo "R.Jalan";
                                        } else {
                                            echo "";
                                        }
                                        ?>
                                    </td>
                                    <td><?= $data['dokter']; ?></td>
                                    <td><?= $dCm['CompanyName']; ?></td>
                                    <td><?= $data['NoAntrian']; ?></td>
                                    <td>
                                        <?php
                                        if ($data['Jenis'] == 'RACIKAN') {
                                        ?>
                                            <label class="badge badge-info" style="background: green;">RACIKAN</label>
                                        <?php
                                        } else {
                                        ?>
                                            <label class="badge badge-success" style="background: blue;">NON-RACIKAN</label>
                                        <?php
                                        }
                                        ?>
                                    </td>
                                    <td><label class="badge badge-success" style="background: blue;"><?= $data['alergi'].''.$data['alergiobat'] ?></label></td>
                                    <td>

                                        <?php
                                        if ($data['Jenis'] == 'NON-RACIKAN') {
                                        ?>
                                            <a href="<?= base_url('apotik/detailApotekTrans/' . $data['ResepId']); ?>?case=<?= $data['CaseID']; ?>&doct=<?= $data['DoctorId']; ?>"  onclick="return confirm('Apakah anda yakin ingin di proses?')" class="btn btn-sm btn-success">Proses</a>
                                        <?php
                                        } else {
                                        ?>
                                            <a href="<?= base_url('apotik/detailApotekRacikan/' . $data['ResepId']); ?>?case=<?= $data['CaseID']; ?>&doct=<?= $data['DoctorId']; ?>" onclick="return confirm('Apakah anda yakin ingin di proses?')" class="btn btn-sm btn-success">Proses</a>
                                        <?php
                                        }
                                        ?>
                                         <button type="button" data-toggle="modal" data-target="#modal-info<?= $data['CaseID']; ?>"  class="btn btn-sm btn-primary"><i class="fa fa-solid fa-eye"></i> Lihat Resep</button>
                                    </td>

                                </tr>
                            <?php
                            endforeach;
                            ?>
                        </tbody>

                    </table>

                </small>
            </div><!-- /.box-body -->
        </div><!-- /.box -->

    </section><!-- /.content -->


</div><!-- /.content-wrapper -->

<?php
foreach ($pasien as $dview) :
$ResepId =  $dview['ResepId'];
    $rDetail =  $this->db->query("SELECT * FROM Resep_Detail RD, Pharmacy P WHERE RD.PharmacyCode=P.PharmacyCode AND ResepId = '$ResepId'")->result_array();
?>
<div id="modal-info<?= $dview['CaseID']; ?>" class="modal fade">
        <div class="modal-dialog">
        <form action="<?php echo site_url('Modal/add/'); ?>" method="post">
        <div class="modal-content">
            <div class="modal-header bg-primary">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">Vie Data Resep</h4>
            </div>
            <div class="modal-body">
            <p><?= $dview['CaseID']; ?></p>
            <table style="font-size: 10px;" id="example1" class="table table-bordered table-hover table-striped">
                    <tr>
                        <td>ResepID</td>
                        <td>Pharmacy</td>
                        <td>Qty</td>
                        <td>CaraPakai</td>
                        <td>Dosis</td>
                        <td>Unit</td>
                        <?php
                            foreach($rDetail as $dataHeader) :
                        ?>
                    </tr>
                    <tr>
                            <td><?= $dataHeader['ResepId']; ?></td>
                            <td><?= $dataHeader['PharmacyCode']; ?> ~ <?= $dataHeader['Description']; ?></td>
                            <td><?= $dataHeader['iQty']; ?></td>
                            <td><?= $dataHeader['CaraPakai']; ?></td>
                            <td><?= $dataHeader['frekuensi']; ?></td>
                            <td><?= $dataHeader['PharmacyUnit']; ?></td>
                    </tr>
                    <?php endforeach; ?>
                </table>
            <br><br><br><br><br><br><br>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
         </form>
        </div>
        </div>    
        </div>
    <?php endforeach; ?>

<script type="text/javascript">
    var count = 59;
    var periode = 1;
    var counter = setInterval(timer, 500);

    function timer() {
        count = count - 1;
        if (count <= 0) {
            clearInterval(counter);
            location.reload();
        }

        document.getElementById("timer").innerHTML = 'Akan memuat pada <strong style="color:orange;">' + count + "</strong> detik";
    }
    $(document).ready(function() {
        timer();
    });
</script>
<script>
    function blink_text() {
        $('#status').fadeOut(700);
        $('#status').fadeIn(700);
    }
    setInterval(blink_text, 750);
</script>