<?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;
}

$angka = 1540097;
?>
<table style="margin-top: -10px; width: 100%;">
<tr>
<td style="margin-top: -10px; width: 20%;"><img src="<?= base_url('images/logo.png'); ?>" width="70" height="50"></td>
<td style="margin-top: -10px; width: 80%; text-align:center;">
<b style='font-size:18px;'><?= $abdulradjak['NamaPerusahaan']; ?></b><br>
<?= $abdulradjak['AlamatPerusahaan']; ?><br>
<small>Telp. <?= $abdulradjak['TeleponPerusahaan']; ?>, Fax : <?= $abdulradjak['FaxPerusahaan']; ?></small>
</td>
</tr>
</table>
<hr>
<br>
<table border="0" style="border-collapse: collapse; width:100mm">
    <tr>
        <td  style='font-size:10px'>Case ID / No.MR</td>
        <td  style='font-size:10px'>&nbsp;:&nbsp;&nbsp;&nbsp; </td>
        <td  style='font-size:10px'><?= $data['Case ID']; ?> / <?= $data['PatientCode']; ?></td>
    </tr>
    <tr>
        <td  style='font-size:10px'>Nama</td>
        <td  style='font-size:10px'>&nbsp;:&nbsp;&nbsp;&nbsp; </td>
        <td  style='font-size:10px'><?= $data['Description']; ?></td>
    </tr>
    <tr>
        <td  style='font-size:10px'>Tanggal Kunjungan</td>
        <td  style='font-size:10px'>&nbsp;:&nbsp;&nbsp;&nbsp; </td>
        <td  style='font-size:10px'><?= date('d-m-Y', strtotime($data['Intake Date'])); ?></td>
    </tr>
    <tr>
        <td style='font-size:10px'>Penjamin</td>
        <td style='font-size:10px'>&nbsp;:&nbsp;&nbsp;&nbsp;</td>
        <td style='font-size:10px'><?= $data['CompanyName'] ?></td>
    </tr>
    <tr>
        <td style='font-size:10px'>Case Status</td>
        <td style='font-size:10px'>&nbsp;:&nbsp;&nbsp;&nbsp;</td>
        <td style='font-size:10px'><?= $data['Case Status'] ?></td>
    </tr>
    <tr>
        <td style='font-size:10px'>Poli</td>
        <td style='font-size:10px'>&nbsp;:&nbsp;&nbsp;&nbsp; </td>
    </tr>
</table>
<hr>
<br>
<small>
<table border="0" style="border-collapse: collapse; width:100mm">
        <tr>
            <td>&nbsp;&nbsp;Deskripsi</td>
            <td>&nbsp;&nbsp;Jumlah</td>
            <td>&nbsp;&nbsp;Harga</td>
            <td>&nbsp;&nbsp;Total</td>
        </tr>
        <?php foreach($result as $d) : ?>
        <tr>
            <td>&nbsp;&nbsp;<?= $d['Description']; ?></td>
            <td>&nbsp;&nbsp;&nbsp;&nbsp;<?= $d['Activity Count']; ?></td>
            <td>&nbsp;&nbsp;<?= number_format($d['Charge'],0); ?></td>
            <td>&nbsp;&nbsp;<?= number_format($d['Total'],0); ?></td>
        </tr>
        <?php endforeach; ?>
        <tr>
            <td colspan="4"><hr></td>
        </tr>
        <?php foreach ($drugs as $p) : ?>
            <tr>
                <td>&nbsp;&nbsp;<?= $p['Keterangan']; ?></td>
                <td></td>
                <td></td>
                <td>&nbsp;&nbsp;<?= number_format($p['TotalDrugs'], 0); ?></td>
            </tr>
        <?php endforeach; ?>
</table>
<hr>
<table>
    <tr>
        <td>Total Biaya</td>
        <td>:</td>
        <td><?= number_format($ttl['Total'],0); ?></td>
    </tr>
    <tr>
        <td>Total Bayar</td>
        <td>:</td>
        <td><?= number_format($payment['AmountPaid'],0); ?></td>
    </tr>
</table>
<hr>
<?php 
$totalbiaya = $ttl['Total'];
$totalbayar = $payment['AmountPaid'];
$biayapasien = $totalbiaya - $totalbayar;
?>
<table>
    <tr>
        <td>Harus Dibayar Pasien</td>
        <td>:</td>
        <td><?= number_format($biayapasien); ?></td>
    </tr>
    <tr>
        <td><b><i>*(<?= terbilang($biayapasien); ?>)</i></b></td>
    </tr>
</table>
</small>
<br>
<table>
<tr>
    <td>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    
        Jakarta, <?php date('Y-m-d'); ?><br>
    </td> 
    </tr>
    <tr>
    <td>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    DiTerima Oleh,<br>
    </td> 
    </tr>
<tr>
    <td>
        <br>
    </td>
</tr>
    <tr>
    <td>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;     
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;     
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    <u>Petugas Kasir</u><br>
    </td>
</tr>
</table>