<?php
// echo 999;
// print_r($details);
// die();
?>


<main id="js-page-content" role="main" class="page-content">


    <ol class="breadcrumb page-breadcrumb">
        <li class="breadcrumb-item"><a href="javascript:void(0);">IC Portal</a></li>
        <li class="breadcrumb-item">MDRO Report</li>

        <li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li>
    </ol>
    <div id="content">
        <div class="row mb-2">
            <div class="col-xs-12 col-sm-7 col-md-7 col-lg-6">
                <h1> <span class="page-title txt-color-blueDark"><?php echo $page_heading ?></span></h1>
            </div>
            <?php if($groupBy != 'yes'){
            ?>
            <div class="col-xs-12 col-sm-5 col-md-5 col-lg-6 text-right">
                <button type="button" class="btn btn-primary" onclick="GetUniqueMdro()">MDRO Patient Wise</button>
            </div>
            <?php
            } ?>
        </div>
        <section>


            <div id="panel-1" class="panel">
                <div class="panel-container show">
                    <div class="panel-content">
                        <div class="row">
                            <!-- NEW WIDGET START -->
                            <div class="col-lg-12 mt">
                                <div class="col-md-3 col-6 my-3">
                                    <div class="form-group row">
                                        <div class="col-9">
                                            <label class="form-label">Select Date</label>
                                            <input type="text" class="form-control w-90 Purchase datefilter" id="datepicker" placeholder="Select date">
                                        </div>
                                        <div class="col-3">
                                            <button id="filterbtn" class="btn btn-primary mt-4" onclick="GetReportByDate('<?php echo $groupBy ?>')">Search</button>
                                        </div>
                                    </div>
                                </div>
                                <table id="datatable_tabletools" class="table table-bordered table-hover table-striped w-100">
                                    <thead class="bg-primary-600 bg-brand-gradient">
                                        <tr>
                                            <th nowrap>
                                                <center>MR No.</center>
                                            </th>
                                            <th nowrap>
                                                <center>Patient Name</center>
                                            </th>
                                            <th nowrap>
                                                <center>Admission Date</center>
                                            </th>
                                            <th nowrap>
                                                <center>Discharge Date</center>
                                            </th>
                                            <th nowrap>
                                                <center>MDRO Type</center>
                                            </th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php foreach ($details as $det) : ?>
                                            <tr>
                                                <td><?php echo $det['mr_no'] ?></td>
                                                <td><?php echo $det['pateint_name'] ?></td>
                                                <td><?php echo date('d-m-Y', strtotime($det['admission_date'])) ?></td>
                                                <td><?php echo date('d-m-Y', strtotime($det['discharge_date'])) ?></td>
                                                <td><?php echo $det['MDR'] ?></td>
                                            </tr>
                                        <?php endforeach; ?>
                                    </tbody>
                                </table>
                            </div>
                            <!-- end widget content -->
                        </div>
                        <!-- end widget div -->
                    </div>
                    <!-- end widget -->
                </div>
            </div>
        </section>
    </div>




</main>


<script>
    $('#datatable_tabletools').dataTable({
        responsive: true,
        lengthChange: false,
        dom: "<'row mb-3'<'col-sm-12 col-md-6 d-flex align-items-center justify-content-start'f><'col-sm-12 col-md-6 d-flex align-items-center justify-content-end'lB>>" +
            "<'row'<'col-sm-12'tr>>" +
            "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
        buttons: [{
                extend: 'colvis',
                text: 'Column Visibility',
                titleAttr: 'Col visibility',
                className: 'btn-outline-primary btn-sm mr-1'
            },
            {
                extend: 'pdfHtml5',
                text: 'PDF',
                titleAttr: 'Generate PDF',
                className: 'btn-outline-danger btn-sm mr-1'
            },
            {
                extend: 'excelHtml5',
                text: 'Excel',
                titleAttr: 'Generate Excel',
                className: 'btn-outline-success btn-sm mr-1'
            },
            {
                extend: 'csvHtml5',
                text: 'CSV',
                titleAttr: 'Generate CSV',
                className: 'btn-outline-primary btn-sm mr-1'
            },
            {
                extend: 'copyHtml5',
                text: 'Copy',
                titleAttr: 'Copy to clipboard',
                className: 'btn-outline-primary btn-sm mr-1'
            },
            {
                extend: 'print',
                text: 'Print',
                titleAttr: 'Print Table',
                className: 'btn-outline-primary btn-sm'
            }
        ],

    });

    $(document).ready(function() {
        $('#datepicker').daterangepicker({
            opens: 'left',
            startDate: moment(), // Set default start date
            endDate: moment(),
        }, function(start, end, label) {
            startDate = start.format('YYYY-MM-DD'); // Store start date in variable
            endDate = end.format('YYYY-MM-DD');
            // console.log("A new date selection was made: " + start + ' to ' + end.format('YYYY-MM-DD'));
        });
    });

    function GetReportByDate(groupBy) {

        if (groupBy == 'yes') {
            window.location.href = "<?php echo base_url('Infection/MdroReport/'); ?>" + startDate + "/" + endDate + "/yes";
        } else {
            window.location.href = "<?php echo base_url('Infection/MdroReport/'); ?>" + startDate + "/" + endDate;
        }
    }

    function GetUniqueMdro()
    {
        const currentDate = moment();
        console.log(currentDate);
        // const currentDate = new Date();
        startDate = currentDate.format('YYYY-MM-DD');
        endDate = currentDate.format('YYYY-MM-DD');
        window.location.href = "<?php echo base_url('Infection/MdroReport/'); ?>" + startDate + "/" + endDate + "/yes";

    }
</script>