<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            Apotik Pharmacy
            <small><?= $abdulradjak['NamaPerusahaan']; ?> - <?= $abdulradjak['KodePPK']; ?></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 -->
        <div class="box">
            <div class="box-body">
                <small>
                    <table class="table table-striped">
                        <tr>
                            <th>No.MR</th>
                            <th>Nama</th>
                            <th>Tanggal Lahir</th>
                            <th>Umur</th>
                            <th>Tgl.Kunjungan</th>
                            <th>Kategori</th>
                            <th>Jaminan </th>
                            <th>Status </th>
                        </tr>
                        <tr>
                            <td><?= $pasienDetail['PatientCode']; ?></td>
                            <td><?= $pasienDetail['Description']; ?></td>
                            <?php
                            extract($_GET);
                            $dtP = $pasienDetail['PatientCode'];
                            $sPasien = $this->db->query("SELECT * FROM Patient WHERE PatientCode = '$dtP'")->row_array();
                            ?>
                            <td><?= date('d F Y', strtotime($sPasien['DOB'])); ?></td>
                            <td>
                                <?php
                                if ($sPasien['DOB'] == '') {
                                } else {
                                    $tgll = date('Y-m-d', strtotime(@$sPasien['DOB']));
                                    $tanggal_lahir = new DateTime($tgll);
                                    $sekarang = new DateTime("today");
                                    if ($tanggal_lahir > $sekarang) {
                                        $thn = "0";
                                        $bln = "0";
                                        $tgl = "0";
                                    }
                                    $thn = $sekarang->diff($tanggal_lahir)->y;
                                    $bln = $sekarang->diff($tanggal_lahir)->m;
                                    $tgl = $sekarang->diff($tanggal_lahir)->d;
                                    echo $thn . " tahun " . $bln . " bulan " . $tgl . " hari";
                                }
                                ?>
                            </td>
                            <td><?= date('d F Y', strtotime($pasienDetail['Intake Date'])); ?></td>
                            <td>
                                <?php
                                if ($pasienDetail['Category'] == "IP") {
                                    echo "R.Inap";
                                } else if ($pasienDetail['Category'] == "OP") {
                                    echo "R.Jalan";
                                } else {
                                    echo "";
                                }
                                ?>
                            </td>
                            <td>
                                <?php
                                $sCom = $pasienDetail['CompanyCode'];
                                $cc = $this->db->query("SELECT * FROM Company WHERE CompanyCode = '$sCom'")->row_array();
                                ?>
                                <?= $cc['CompanyName']; ?>
                            </td>
                            <td><?= $pasienDetail['Case Status']; ?></td>
                        </tr>
                    </table>
                </small>
            </div><!-- /.box-body -->
        </div><!-- /.box -->

        <div class="row">
            <div class="col-md-6">
                <div class="box">
                    <div class="box-body"> 
                        <?php
                        if (isset($isi)) {
                        ?>
                            <a href="#" disabled style="margin-bottom: 5px;" class="btn btn-sm btn-primary">Tambah Transaksi</a>
                        <?php
                        } else {
                        ?>
                          
                        <?php
                        }
                        ?>
                        <?php
                        if ($pasienDetail['Case Status'] == 'CLOSED') {
                        ?>
                            <a href="#" disabled style="margin-bottom: 5px;" class="btn btn-sm btn-primary">Tambah Transaksi</a>
                        <?php
                        } else {
                        ?>
                            <a href="" data-toggle="modal" data-target="#tambahTransaksi" style="margin-bottom: 5px;" class="btn btn-sm btn-primary">Tambah Transaksi</a>
                        <?php
                        }
                        ?>
                        <small>
                            <table class="table table-striped">
                                <tr>
                                    <th>Tran ID</th>
                                    <th>Transaction Time</th>
                                    <th>Doctor</th>
                                    <th>Class</th>
                                    <th></th>
                                </tr>
                                <?php
                                foreach ($apotikDetail as $header) :
                                    $noT = $header['TransactionID'];
                                    $idT = $this->db->query("SELECT TransactionID FROM [Activity Drugs] WHERE TransactionID = '$noT' ")->num_rows();
                                ?>
                                    <tr>
                                        <td><?= $header['TransactionID']; ?></td>
                                        <td><a href="<?= base_url('apotik/transaksiPharmacy/' . $header['Case ID'] . '?isi=' . $header['TransactionID']); ?>"><?= $header['Transaction_Date']; ?></a></td>
                                        <td><?= $header['DoctorID']; ?></td>
                                        <td><?= $header['Class']; ?></td>
                                        <td> <?= $idT; ?>
                                            <?php
                                            if ($idT > 0) {
                                            ?>
                                                <a href="#" disabled style="cursor:default; color:gray"><i class="fa fa-fw fa-trash"></i></a>
                                            <?php
                                            } else {
                                            ?>
                                                <a onclick="return confirm('Hapus transaksi?')" href="<?= base_url('apotik/hapusTransaksi/' . $header['TransactionID'] . '/' . $header['Case ID']); ?>">
                                                    <i class="fa fa-fw fa-trash"></i></a>
                                            <?php
                                            }
                                            ?>
                                        </td>
                                    </tr>
                                <?php
                                endforeach;
                                ?>
                            </table>
                        </small>
                    </div><!-- /.box-body -->
                </div>
            </div>
            <div class="col-md-6">
                <?php
                extract($_GET);
                if (isset($isi)) {
                    $this->load->view('apotek/viewpharmacy/isiTransaksi');
                }
                ?>
            </div>
        </div>

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


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

<!-- Modal -->
<div class="modal fade" id="tambahTransaksi" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <form action="<?= base_url('apotik/prosesHeader/' . $pasienDetail['Case ID']); ?>" method="post">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Transaksi Baru</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <input type="text" hidden name="user" value="<?= $user['nama']; ?>">
                    <input type="text" hidden name="caseID" value="<?= $pasienDetail['Case ID']; ?>">
                    <input type="text" hidden name="PatientCode" value="<?= $pasienDetail['PatientCode']; ?>">

                    <div class="row">
                        <div class="col-md-3">Dokter</div>
                        <div class="col-md-9">
                            <?php
                            $dokter = $this->db->query("SELECT * FROM Doctor")->result_array();
                            ?>
                            <select name="DoctorID" class="form-control" required>
                                <option value=""></option>
                                <?php
                                foreach ($dokter as $dok) :
                                    if ($pasienDetail['DoctIncharge'] == $dok['DoctorID']) {
                                ?>
                                        <option value="<?= $dok['DoctorID']; ?>" selected><?= $dok['FirstName']; ?></option>
                                    <?php
                                    } else {
                                    ?>
                                        <option value="<?= $dok['DoctorID']; ?>"><?= $dok['FirstName']; ?></option>
                                <?php
                                    }
                                endforeach;
                                ?>
                            </select>
                        </div>
                    </div>

                    <div class="row" style="margin-top: 5px;">
                        <div class="col-md-3">Class</div>
                        <div class="col-md-9">
                            <input type="text" name="Class" value="<?= $pasienDetail['Class']; ?>" class="form-control" required>
                        </div>
                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-primary">Save</button>
                </div>
            </div>
        </form>
    </div>
</div>
     