<?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 = 'New Patient';
$maindb = 'consultmain';
$trandb = '';
$printfile = "";
$file = '';
$trandbexist = 0;
$grid = '';
$keyfld = "vouchno";
$keycond = " ";
$focusfield = "name";
mysqli_select_db($conn, $zdb);
$count = $_POST["items"];
include("includes/linkshead.php");
?>
</head>

<body>
    <form action='' method='POST'>
        <!-- Default box -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-body table-responsive" style="width:100%">
                        <div class="row text-center">
                            <h4 style="color: red;font-size: 20px">New Patient</h4>
                        </div>
                        <!--                        <div class="row">
                                                    <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9"></div>
                                                    <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
                        
                                                        <input style="padding-right: 15px;float:right;"  type='submit' id="update" name='submit' value='SAVE' class="btn btn-success">
                                                    </div>
                                                </div>-->
                        <table id="example1" class="table-bordered" width="100%">
                            <thead>
                                <tr class="mySearchTr">
                                    <th style="width: 5%;">Sr.</th>
                                    <th style="width: 5%;">Reg. No.</th>
                                    <!--<th style="width: 8%;">Date</th>-->
                                    <th style="width: 20%;">Person Name</th>
                                    <th style="width: 5%;">Mobile</th>
                                    <th style="width: 20%;">Purpose</th>
                                    <th style="width: 20%;">Ref. By</th>

                                </tr>
                            </thead>
                            <tbody class="mytable table-bordered">
                                <?php
                                $tdate = date("Y-m-d");

//                                $srchresult = mysqli_query($conn, "SELECT a.*, DATE_FORMAT(a.`vouchdt`, '%d-%m-%Y')as vouchdt, b.name,b.mobile,b.acttype
//                                                                   FROM `$maindb` a left join accmast b on a.accode=b.accode where a.`apprv`= '' 
//                                                                   order by a.vouchdt DESC, a.vouchtime ASC") or die(mysqli_error($conn));
                                $srchresult = mysqli_query($conn, "SELECT a.*, DATE_FORMAT(a.`scheddate`, '%d-%m-%Y')as vouchdt, b.name,b.mobile,b.acttype
                                                                   FROM `schedtreat` a left join accmast b on a.accode=b.accode where a.`checkin`= '1' and a.consult = ''
                                                                   ANd a.scheddate = '$tdate'
                                                                   order by a.scheddate DESC, a.apttime ASC") or die(mysqli_error($conn));

                                $ctr = 0;
                                $mctr = 0;
                                while ($row = mysqli_fetch_array($srchresult)) {
                                    $purpvis = $scedule['purpvisit'];
                                    if ($row['treatment'] > 0) {
                                        $gettt = mysqli_query($conn, "SELECT code,name FROM `treatment` WHERE `code`='$row[treatment]'") or die(mysqli_error($conn));
                                        if (mysqli_num_rows($gettt) > 0) {
                                            $tcode = mysqli_fetch_array($gettt);
                                            $treatname = $tcode['name'];
                                            $purpvis = $treatname . " Appointment";
                                        }
                                    }

                                    if ($row['acttype'] == "P") {
                                        $href = "consult_ent.php?vouchno=$row[vouchno]&mode=edit";
                                    } else {
                                        $href = "patient.php?mode=edit&ajpara=C&accode=$row[accode]";
                                    }
                                    $mctr++;

                                    echo "<tr class='clickable-row' data-href='$href' data-target='_blank'>";
                                    Echo "<td style='align:center;' class=''>$mctr</td>";
                                    Echo "<td  class='' style='font-size:18px'>$row[vouchno]</td>";
//                                    Echo "<td  class='' style='font-size:18px'>$row[vouchdt]</td>";
                                    Echo "<td  class='' style='font-size:18px'>$row[name]</td>";
                                    Echo "<td class='' style='font-size:20px'>$row[mobile]</td>";
                                    Echo "<td class='' style='font-size:20px'>$purpvis</td>";
                                    Echo "<td class='' style='font-size:20px'>$row[refby]</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>