<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            <small>Billing</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">
                <br>
                <input type="text" name="caricase" class="form-control" id="searchCase" placeholder="Case ID..">
                <div class="box-body">
                    <small>
                        <table id="example1" class="table table-responsive table-striped">
                            <thead>
                                <tr class="bg-blue-gradient">
                                    <th>Case ID</th>
                                    <th>No. Mr</th>
                                    <th>Nama</th>
                                    <th>Intake Date</th>
                                    <th>Penjamin</th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                            <tbody id="tableBody"></tbody>
                        </table>
                    </small>
                </div>
            </div>
        </div>
    </section>
</div>

<!-- View PDF -->
<div class="modal fade" id="Modalview" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
    <div class="modal-dialog modal-lg modal-dialog-scrollable" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <a href="#" onclick="openWin()" class="btn btn-success">Tanda Tangan</a>
                <button onclick="confirmasi()" class="btn btn-warning">verification Total Bill </button>
                <input type="hidden" name="caseid" id="textcaseid">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div id="pdfbiling"></div>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>
            </div>
        </div>
    </div>
</div>
</div>

<!-- View Tanda Tangan -->
<div class="modal fade" id="Modalttd" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
    <div class="modal-dialog modal-lg modal-dialog-scrollable" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h1>View StatmentDetail</h1>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div id="ttd"></div>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>
            </div>
        </div>
    </div>
</div>
</div>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
    function confirmasi() {
        $('#Modalview').hide();
        $('#Modalttd').modal('show');
        var textcaseid = $('#textcaseid').val()
        var baseUrl = "<?= base_url('kasir/printstruk/'); ?>" + textcaseid;
        var html = '';
        html += '<iframe id="if1" width="100%" height="900" style="visibility:visible" src="' + baseUrl + '"></iframe>'
        $("#ttd").html(html)
    }
    $(document).on('click', '.btnmodal', function() {
        var caseID = $(this).data('caseid');
        $("#textcaseid").val(caseID);

        var baseUrl = "<?= base_url('kasir/StatmentDetail/'); ?>" + caseID;
        var html = '';
        html += '<iframe id="if1" width="30%" height="560" style="visibility:visible" src="' + baseUrl + '"></iframe>'
        $("#pdfbiling").html(html)

        // Tampilkan modal
        $('#Modalview').modal('show');
    });


    $('#searchCase').keyup(function() {
        var cari = $(this).val();
        if (cari != '') {
            ListPasien(cari);
        } else {
            ListPasien();
        }
    });

    function ListPasien(cari) {
        $.ajax({
            type: 'POST',
            url: '<?= base_url('biling/kasir/get_cases') ?>',
            async: true,
            dataType: 'json',
            data: {
                cari: cari
            },
            success: function(data) {
                var html = '';
                var i;
                for (i = 0; i < data.length; i++) {
                    html += '<tr>' +
                        '<td>' + data[i].CaseID + '</td>' +
                        '<td>' + data[i].PatientCode + '</td>' +
                        '<td>' + data[i].Description + '</td>' +
                        '<td>' + data[i].IntakeDate + '</td>' +
                        '<td>' + data[i].CompanyName + '</td>' +
                        '<td><a href="#" class="btn btn-primary btnmodal" data-caseid="' + data[i].CaseID + '">Pilih</a></td>' +
                        '</tr>';
                }
                $('#tableBody').html(html);
            },
            error: function() {
                console.log('haii')
            }

        });
    }

    function openWin() {
        var textcaseid = $('#textcaseid').val()
        myWindow = window.open("<?= base_url('GeneralConsent/signature/'); ?>" + textcaseid, "_blank", "width=1000, height=800");
    }
</script>