<!-- Content Wrapper. Contains page content -->
<?php
date_default_timezone_set("Asia/Jakarta");
?>
<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>
            <br>
            <div class="box-body">
                <div class="table-responsive">
                <form action="<?= base_url('kasir/search'); ?>" method="get">
                <table border="0" class="table table-sm table-bordered table-striped dataTable dtr-inline">
                    <!-- <tr>
                        <td colspan="3">
                            <div class="input-group col-md-12">
                            <select name="jenis" style="margin-bottom: 5px;" class="form-control" onchange="DisableMenu()" id="status" required>
                            <option value="1">Case ID</option>
                            <option value="2">No Mr</option>
                            <option value="3">Nama</option>
                            </select>
                            </div>
                        </td>
                        <td colspan="3">
                            <div class="input-group col-md-12">
                                <input type="text" class="form-control" name="cari" value="" id="" placeholder="Search By">
                                <span class="input-group-btn">
                                <button style="width: 100%; border-radius: 0px;" type="submit" class="btn btn btn-primary bg-green-gradient"><i class="fa fa-fw fa-search"></i> Cari</button>
                                </span>
                            </div>
                        </td>
                    </tr> -->
                </form>
                <?php foreach($cari as $d) : ?>
                            <tr>
                                <td>No.MR</td>
                                <td>:&nbsp;&nbsp;&nbsp; </td>
                                <td><?= $d["PatientCode"]; ?></td>

                                <td>No.Reg</td>
                                <td>:&nbsp;&nbsp;&nbsp; </td>
                                <td><?= $d["Case ID"]; ?></td>

                                <td>Nama</td>
                                <td>:&nbsp;&nbsp;&nbsp; </td>
                                <td><?= $d["Description"]; ?></td>
                            </tr>
                            <tr>
                                <td>UserName</td>
                                <td>:&nbsp;&nbsp;&nbsp; </td>
                                <td><?= $user["nama"]; ?></td>

                                <td>Category</td>
                                <td>:&nbsp;&nbsp;&nbsp; </td>
                                <td><?= $d["Category"]; ?></td>

                                <td>Intake Date</td>
                                <td>:&nbsp;&nbsp;&nbsp; </td>
                                <td><?= $d["Intake Date"]; ?></td>
                            </tr>
                            <tr>
                                <td>Close Date</td>
                                <td>:&nbsp;&nbsp;&nbsp; </td>
                                <td><?= $d["Closed Date"]; ?></td>

                                <td>Penjamin</td>
                                <td>:&nbsp;&nbsp;&nbsp; </td>
                                <td><?= $d["CompanyName"]; ?></td>

                                <td>Treatment & Drug</td>
                                <td>:&nbsp;&nbsp;&nbsp; </td>
                                <td><input type="text" class="form-control" name="" id="" value="<?=  number_format($totalcharge['Total'],0); ?>" placeholder="Treatment & Drug"></td>
                            </tr>
                            <tr>
                                <td>Payment</td>
                                <td>&nbsp;&nbsp;&nbsp; </td>
                                <td colspan="3"><input type="text" class="form-control" name="" id="" placeholder="Payment"></td> 

                                <td>Status</td>
                                <td>&nbsp;&nbsp;&nbsp; </td>
                                <td colspan="4"><b class="display-4 text-right text-red"><b><?= $d["Case Status"]; ?></b></b></td>          
                            </tr>
                        </table>
                    </div>
                   <?php endforeach; ?>
                </div>
                <br>
                <div class="row">
                <div class="col-md-6">
                <div class="box">
                <div class="box-header with-border">
                  <h3 class="box-title">Category</h3>
                </div><!-- /.box-header -->
                <div class="box-body">
                <table id="example1" class="table table-bordered table-hover table-striped">
                    <th>Category</th>
                    <th>Total Treatment</th>
                    <tbody>
                        <?php foreach($rincian as $d): ?>
                      <tr>
                        <td><?= $d['Category']; ?></td>
                        <td>Rp.<?= number_format($d['Total Treatment']).',-'; ?></td>
                      </tr>
                        <?php endforeach; ?>
                    </tbody>
                 </table>
                </div>
                </div>
                </div>

                <div class="col-md-6">
                <div class="box">
                <div class="box-header with-border">
                  <h3 class="box-title">Payment</h3>
                </div><!-- /.box-header -->
                <div class="box-body">
                <table id="example1" class="table table-bordered table-hover table-striped">
                    <th>Payment Date</th>
                    <th>Invoice ID</th>
                    <th>Type</th>
                    <th>Total</th>
                    <th>Print</th>
                    <tbody>
                    <?php foreach($Payment as $d) : ?>
                        <tr>
                            <td><?= $d["Payment Date"]; ?></td>
                            <td><?= $d["Invoice ID"]; ?></td>
                            <td><?= $d["Transaction Type"]; ?></td>
                            <td><?= number_format($d['AmountTotal'],0); ?></td>
                            <td><a href="<?= base_url('kasir/PrintCreatePayment/'.$d["Invoice ID"].'/'.$d["Case ID"]); ?>" class="btn btn-sm btn-sucess bg-green-gradient" target="new_tab"><i class="fa fa-print"></i></a></td>
                        </tr>
                    </tbody>
                    <?php endforeach; ?>   
                 </table>
                </div>
                </div>
                <?php foreach($cari as $d) : ?>
                <?php if($d['Case Status'] == "OPEN") { ?>
                <a href="" data-toggle="modal" data-target="#createpayment<?= $d["Case ID"]; ?>" class="btn btn-sm btn-sucess bg-green-gradient" data-backdrop="static" data-keyboard="false"><i class="fa fa-usd"></i> Create Payment</a>
                <a href="<?= base_url('kasir/PrintClaimNote/'.$d["Case ID"]); ?>" target="_blank" class="btn btn-sm btn-primary bg-blue-gradient"><i class="fa fa-print"> Print Claim Note</i></a>
                <?php }else{ ?>
                    <a href="" data-toggle="modal" data-target="#" class="btn btn-sm btn-danger bg-red-gradient" data-backdrop="static" data-keyboard="false" disabled><i class="fa fa-usd"></i> Create Payment</a> 
                    <a href="#" class="btn btn-sm btn-primary bg-red-gradient" disabled><i class="fa fa-print"> Print Claim Note</i></a>
                <?php } ?>
              
                <a href="" target="_blank" data-toggle="modal" data-target="#printstatment<?= $d["Case ID"] ?>" class="btn btn-sm btn-sucess bg-yellow-gradient" data-backdrop="static" data-keyboard="false"><i class="fa fa-print"></i> Print Statment</a>
                <?php endforeach; ?>
            </div>
                </div>
            <!-- <div class="box-tools pull-right">
               <div class="col-lg-6">
                <div class="info-box mb-3 bg-black color-palette">
                    <span class="info-box-icon bg-success elevation-1"><i class="fa fa-usd"></i></span>
                    <div class="info-box-content bg-black color-palette">
                    <h1 class="display-4 text-right text-yellow"><b>Rp. 1.500.000,</b></h1>
                </div>
                </div>
                </div> -->
            </div>
            </div>
        </div>
    </section>
    </div>
</div>
</div>
<!-- Modal Detail -->
<?php foreach($cari as $d) : ?>
<div class="modal fade" id="createpayment<?= $d['Case ID']; ?>" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
    <div class="modal-dialog modal-lg modal-dialog-scrollable" role="document">
    <form onsubmit="btnSubmitSave.disabled = true; return true;"  action="<?= base_url('kasir/savebayar'); ?>" method="post">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Create Payment</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
            <table id="example1" class="table table-bordered table-hover table-striped">
            <tr>
                                <td>Recived</td>
                                <td><input type="text" class="form-control" name="invoice" id="" value="#INVID" placeholder="Invoice ID" Disabled></td>
                                <td><input type="text" class="form-control" name="status" id="" value="OK" placeholder="Invoice ID" readonly></td>
                                <td><input type="text" class="form-control" name="transactionid" id="" value="<?= $idinv['NoNumeric'] ?>" placeholder="ID" readonly></td>
                            </tr>
                            <tr>
                                <td>Case ID</td>
                                <td><input type="text" class="form-control" name="caseid" id="" value="<?= $d['Case ID']; ?>" placeholder="Case ID"></td>
                                <td><input type="text" class="form-control" name="tanggal" id="" value="<?= date('d-m-y'); ?>" placeholder="Tanggal"></td>
                                <td><input type="text" class="form-control" name="waktu" id="" value="<?= date('h:i a'); ?>" placeholder="Waktu"></td>
                            </tr>
                            <tr>
                                <td>MR ID</td>
                                <td><input type="text" class="form-control" name="mr" id="" value="<?= $d['PatientCode']; ?>" placeholder="MR ID"></td>
                                <td colspan="2"><input type="text" class="form-control" name="nama" id="" value="<?= $d['Description']; ?>" placeholder="Patient Name"></td>
                            </tr>
                            <tr>
                                <td>Recived From</td>
                                <td colspan="3"><input type="text" class="form-control" name="tujuannama" id="" value="<?= $d['Description']; ?>" placeholder="Invoice ID"></td>
                            </tr>
            </table>
            <hr>
            <table id="example1" class="table table-bordered table-hover table-striped">
            <tr>
                <td>Payment Type</td>
                <td>
                    <select name="kategori" id="kategori"" class="teanganData kategori" required data-live-search="true">
                                        <?php foreach($paymentype as $d) : ?>
                                        <option value="<?= $d['TransactionType']; ?>"><?= $d['TransactionType']; ?></option>
                                        <?php endforeach; ?>
                                     </select>
                </td>

                <td>Rounding</td>
                <td><input type="text" name="rounding" value="" class="form-control"></td>
            </tr>
            <tr>
                <td>Amount Paid</td>
                <td><input type="text" name="amountpaid" value="<?=  number_format($totalcharge["Total"],0); ?>" class="form-control"></td>

                <td>Bank Name</td>
                <td><input type="text" name="bankname" value="" class="form-control"></td>
            </tr>
            <tr>
                <td>Total</td>
                <td><input type="text" name="total" value="<?=  number_format($totalcharge["Total"],0); ?>" class="form-control" readonly></td>

                <td>Card Type</td>
                <td><input type="text" name="cardtype" value="" class="form-control"></td>
            </tr>
            <tr>
                <td>Description</td>
                <td><textarea class="form-control" name="description"></textarea></td>

                <td>Recived By</td>
                <td><input type="text" name="pengirim" value="<?= $user['nama']; ?>" class="form-control" readonly></td>
            </tr>
            <tr>
                <td></td>
                <td></td>

                <td>Shift</td>
                <td><input type="text" name="shift" value="<?= $shift; ?>" class="form-control" readonly></td>
            </tr>
            </table>
            </div>
            <div class="modal-footer">
                  <button type="submit" name="btnSubmitSave" id="btnSubmitSave" class="btn btn-success" onkeypress="">Save</button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>
            </div>
        </div>
        </form>
    </div>
</div>
<?php endforeach; ?>
<!-- End of Modal Detail -->
<!-- Modal PrintStatmentDetail -->
<?php foreach($cari as $ad) : ?>
<div class="modal fade" id="printstatment<?= $ad['Case ID']; ?>" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
    <div class="modal-dialog modal-lg modal-dialog-scrollable" role="document">
    <form action="<?= base_url('Kasir/PrintStatmentDetail'); ?>"  target="_blank" method="get">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Print Statment</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
            <div class="form-group">
            <label for="recipient-name" class="col-form-label">Type Print</label>
            <select name="item" id="kategori" class="form-control" required data-live-search="true">>
            <option value="">-- Pilih Item --</option>
            <option value="Yes">Yes</option>
            <option value="No">No</option>
            </select>
          </div>
          <div class="form-group">
            <input type="hidden" name="caseid" value="<?= $ad['Case ID']; ?>">
          </div>
            </div>
            <div class="modal-footer">
                  <button type="submit" class="btn btn-success" onkeypress="">Print</button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>
            </div>
        </div>
        </form>
    </div>
</div>
<?php endforeach; ?>
<!-- End of Modal Detail -->