<?php
function penyebut($nilai) {
    $nilai = abs($nilai);
    $huruf = array("", "satu", "dua", "tiga", "empat", "lima", "enam", "tujuh", "delapan", "sembilan", "sepuluh", "sebelas");
    $temp = "";
    if ($nilai < 12) {
        $temp = " ". $huruf[$nilai];
    } else if ($nilai <20) {
        $temp = penyebut($nilai - 10). " belas";
    } else if ($nilai < 100) {
        $temp = penyebut($nilai/10)." puluh". penyebut($nilai % 10);
    } else if ($nilai < 200) {
        $temp = " seratus" . penyebut($nilai - 100);
    } else if ($nilai < 1000) {
        $temp = penyebut($nilai/100) . " ratus" . penyebut($nilai % 100);
    } else if ($nilai < 2000) {
        $temp = " seribu" . penyebut($nilai - 1000);
    } else if ($nilai < 1000000) {
        $temp = penyebut($nilai/1000) . " ribu" . penyebut($nilai % 1000);
    } else if ($nilai < 1000000000) {
        $temp = penyebut($nilai/1000000) . " juta" . penyebut($nilai % 1000000);
    } else if ($nilai < 1000000000000) {
        $temp = penyebut($nilai/1000000000) . " milyar" . penyebut(fmod($nilai,1000000000));
    } else if ($nilai < 1000000000000000) {
        $temp = penyebut($nilai/1000000000000) . " triliun" . penyebut(fmod($nilai,1000000000000));
    }     
    return $temp;
}
 
function terbilang($nilai) {
    if($nilai<0) {
        $hasil = "minus ". trim(penyebut($nilai));
    } else {
        $hasil = trim(penyebut($nilai));
    }     
    return $hasil;
}
?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            Sistem Klinik
            <small>Rekam Medis</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Klinik</a></li>
            <li class="active">Dashboard</li>
        </ol>
    </section>

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

        <!-- Default box -->
        <div class="box">
            <div class="box-header with-border">
                <div class="box-tools pull-right">
                </div>
            <div class="box-body">
            <table class="table table-sm ">
                <tr>
                    <td>Case ID</td>
                    <td>:</td>
                    <td><?= $dt['Case ID']; ?></td>

                    <td>Mr</td>
                    <td>:</td>
                    <td><?= $dt['PatientCode']; ?></td>
                </tr>
                <tr>
                    <td>Nama</td>
                    <td>:</td>
                    <td><?= $dt['Description']; ?></td>

                    <td>Penjamin</td>
                    <td>:</td>
                    <td><?= $dt['CompanyName']; ?></td>
                </tr>
                <tr>
                    <td>Category</td>
                    <td>:</td>
                    <td><?= $dt['Category']; ?></td>

                    <td>Doctor</td>
                    <td>:</td>
                    <td><?= $dt['FirstName']; ?></td>
                </tr>
                <tr>
                    <td>Diagnosa</td>
                    <td>:</td>
                    <td><?= $dt['Presenting Problem']; ?></td>

                    <td>Status</td>
                    <td>:</td>
                    <td><?= $dt['Case Status']; ?></td>
                </tr>
                <tr>
                    <td>Intake Date</td>
                    <td>:</td>
                    <td><?= date('d-m-Y', strtotime($dt['Intake Date'])); ?>

                    <td>Close Date</td>
                    <td>:</td>
                    <td><?= date('d-m-Y', strtotime($dt['Closed Date'])); ?></td>
                </tr>
            </table>  
            <br>
            <?php
                $caseid = $this->uri->segment(3);
                $qcek = $this->db->query("Select [Case Status] from Cases where [Case ID] = $caseid")->row_array();
              if($qcek["Case Status"] == 'OPEN') {
            ?>
            <a href="<?= base_url('Transaction/AddTransaction/'.$dt['Case ID']); ?>" class="btn btn-success" >Add Transaction</a>
            <?php }else{ ?>
                <a href="#" class="btn btn-danger" disabled><?= $qcek['Case Status']; ?></a>
            <?php } ?> 
            <a href="" class="btn btn-success" >Preview</a>  
            <a href="<?= base_url('Transaction/detailheaderdepo/'.$dt['Case ID']); ?>" class="btn btn-primary" >Drug</a> 
            <a href="<?= base_url('Kasir/detailchasir/'.$dt['Case ID']); ?>" class="btn btn-warning" >Chasir</a>               
            </div>    
        </div>
        </div>
        <!-- Header -->
        <div class="box">
            <div class="box-body">
                <small>
                    <table class="table table-striped">
                    <th>Transaksi ID</th>
                    <th>Transaction Date</th>
                    <th>Total Charge</th>
                    <th>Category</th>
                    <?php 
                    $sum = 0;
                    $sum = $total['total'];
                    ?>
                    <tr>
                        <td><a href="<?= base_url('Transaction/detailTransaction/'.  $detail['Case ID'] .'/'. $detail['TransactionID']) ?>" id="btnCari"><?= $detail['TransactionID']; ?></a></td>
                        <td><?= date('d-m-Y', strtotime($detail['Transaction_Date'])); ?></td>
                        <td><?= number_format($sum,0); ?></td>
                        <td><?= $detail['RefferedBy']; ?></td>
                    </tr>
                    <tr style="background-color: greenyellow;">
                        <td colspan="3"><b><center>Total</center></b></td>
                        <td><b>Rp. <?= number_format($total['total'],0); ?></b></td>
                        <td><b><i>*(<?= terbilang($sum); ?>)</i></b></td>
                    </tr>
                    </table>
                </small>
            </div>
        </div>
        <!-- Detail -->
    </section>
</div>

