<?php
ob_start();
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');

$root = $_SESSION["zdbroot"];

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];

$formname = 'Patient';
$maindb = 'consultmain';
$trandb = '';
$printfile = "";
$file = '';
$trandbexist = 0;
$grid = '';
$keyfld = "vouchno";
$keycond = " ";
$focusfield = "name";
mysqli_select_db($conn, $zdb);
$accode = $_GET["accode"];
if ($accode) {
    $accond = "Where a.`accode` ='$accode'";
}
include("includes/linkshead.php");
?>
<script type="text/javascript">
    $(document).ready(function () {

        $("body").on("click", ".confbook", confBook);
        $("body").on("click", ".newtreat", newTreat);




        function newTreat() {
            var accode = <?= $accode ?>;
            top.window.location = 'consult_ent.php?mode=true&accode= ' + accode;


        }
        function confBook() {
            var tr = $(this).closest("tr"),
                    vouchno = tr.find(".vouchno").val();
            $.post("confBook.php", {vouchno: vouchno}, function (data) {
                if (data > 0) {
                    alert("Booking Done.");
                    //                    window.location.reload();
                    top.window.location = 'mainmenu.php?action=default';
                }
            })
        }
    })
</script>
<style>
    #confbook {
        background-color: #454752;
        /* Charcoal black background */
        color: white;
        /* White text */
        border: none;
        /* No borders */
        padding: 2px 1px;
        /* Padding */
        margin-left: 15px;
        /* Padding */
        text-align: center;
        /* Centered text */
        align-items: center;
        /* Centered text */
        justify-content: center;
        /* Centered text */
        text-decoration: none;
        /* Remove underline */
        display: block;
        /* Block display for full width */
        font-size: 15px;
        /* Font size */
        border-radius: 8px;
        /* Rounded corners */
        line-height: 1.5em;
        /* Line height to center text vertically */
        height: 25px;
        width: 75px;
        transition: background-color 0.3s ease;
        /* Transition effect */
    }

    #confbook:hover {
        background-color: #adb5bd;
        /* Slightly lighter charcoal on hover */
    }
</style>
</head>

<body>
    <form action='' method='POST'>
        <!-- Default box -->
        <div class="row">
            <div class="col-lg-10">
            </div>
            <div class="col-lg-2">
                <button type="button" class='btn text-center form-control newtreat'>New Treatment</button>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">

                <div class="panel panel-default">
                    <div class="panel-body table-responsive" style="width:100%">
                        <table id="example1" class="table-bordered" width="100%">
                            <thead>
                                <tr class="mySearchTr">
                                    <th style="width: 5%;">Sr.</th>
                                    <th style="width: 5%;">Voucher No.</th>
                                    <th style="width: 5%;">Patient No.</th>
                                    <th style="width: 20%;">Patient Name</th>
                                    <th style="width: 25%;">Diagnosis</th>
                                    <th style="width: 5%;">Start Date</th>
                                    <th style="width: 8%;">Complete Date</th>
                                    <!-- <th style="width: 5%;"></th> -->

                                </tr>
                            </thead>
                            <tbody class="mytable table-bordered">
                                <?php
                                $srchresult = mysqli_query($conn, "SELECT a.*, DATE_FORMAT(a.`vouchdt`, '%d-%m-%Y')as vouchdt,DATE_FORMAT(a.`cmpltdt`, '%d-%m-%Y')as cmpltdt,
                                                                   b.name,b.mobile FROM `$maindb` a left join accmast b 
                                                                   on a.accode=b.accode $accond order by a.vouchdt DESC, a.vouchtime ASC") or die(mysqli_error($conn));

                                $ctr = 0;
                                $mctr = 0;
                                while ($row = mysqli_fetch_array($srchresult)) {
                                    $mctr++;

                                    echo "<tr >";
                                    //                                    echo "<tr class='clickable-row' data-href='consult_ent.php?vouchno=$row[vouchno]&mode=edit' data-target='_blank'>";
                                    echo "<td  style='align:center;' class=''>$mctr</td>";
                                    echo "<td><a href='consult_ent.php?vouchno=$row[vouchno]&mode=edit' target='_blank'>$row[vouchno]</a></td>";
                                    echo "<td  class=''>$row[accode]</td>";
                                    echo "<td  class=''>$row[name]</td>";
                                    echo "<td class=''>$row[diag1] $row[diag2]</td>";
                                    echo "<td  class=''>$row[vouchdt]</td>";
                                    echo "<td  class=''>$row[cmpltdt]</td>";
                                    // echo "<td class=''><a class='btn text-center form-control confbook' id='confbook'>Book</a>"
                                    // . "<input type='hidden' class='vouchno' value='$row[vouchno]'></td>";
                                    echo "</tr>";
                                    $ctr++;
                                }
                                ?>
                            <input type="text" style="display: none;" name="items" value="<? echo $ctr; ?>">
                            </tbody>
                        </table>

                    </div>
                </div>
            </div>
        </div>
    </form>

    <?php include("includes/linksfoot.php"); ?>

</body>

</html>