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

$maindb = "consultmain";
$trandb = "consultsymp";
$formname = 'PATIENT NAME';
$file = "patient_historyrep_fr.php";
$zroot = $_SESSION["zdir"];

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);

$name = $_POST['patientname'];
$namecond = "";
if (!empty($name)) {
    $namecond = " AND a.`accode` = $name ";
}

$getpmain = mysqli_query($conn, "SELECT m.*,DATE_FORMAT(m.`vouchdt`, '%d-%m-%Y') AS date,DATE_FORMAT(m.`cmpltdt`, '%d-%m-%Y') AS cmpltdt, a.accode, a.name AS name FROM $maindb m
                                LEFT JOIN accmast a ON a.accode=m.accode
                                WHERE `vouchno`!='' $namecond") or die(mysqli_error($conn));
$getno2 = mysqli_num_rows($getpmain);
if (isset($_POST["view"])) {
    include("includes/linkshead.php");
?>
    <style>
        /* CSS */

        .button-29:active {
            box-shadow: #3c4fe0 0 3px 7px inset;
            transform: translateY(2px);
        }

        .sksahil {
            border-radius: 10px;
            background: rgb(11, 76, 120);
            background: linear-gradient(104deg, rgba(11, 76, 120, 1) 60%, rgba(255, 255, 255, 1) 100%);
            margin-left: 1%;
        }

        .sksahil2 {
            border-radius: 10px;
            background-color: #e6f1ff;
            margin-top: 5px;
            margin-bottom: 5px;
        }

        .skbtn {
            background-image: linear-gradient(135deg, #FFFEFF 10%, #D7FFFE 100%) !important;
            border: 1px solid #09C6F9 !important;
            border: 2px solid #0b4c78;
            color: #2A2A72;
            font-weight: bold;
            border-radius: 10px;
        }

        .skk {
            border-bottom: 1px solid grey !important;
            color: white;
        }

        .slk {
            background: black !important;
        }

        .txtt {
            color: whitesmoke;
            text-transform: uppercase;
            font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif
        }

        .adjcol {
            width: 4.33333333%;
        }

        .adjcolh {
            width: 5.33333333%;
        }

        .adjcol2 {
            width: 6.33333333%;
        }

        .adjcolh2 {
            width: 10.33333333%;
        }

        .adjcolh3 {
            width: 12.333333%;
        }

        .adjcolh1_5 {
            width: 8.7%;
        }

        .adjcola {
            width: 20%;
        }

        .adjcol3 {
            width: 25.9999999%;
        }

        .panel.with-nav-tabs .nav-tabs {
            border-bottom: none;
        }

        .panel.with-nav-tabs .nav-justified {
            margin-bottom: -1px;
        }

        .nav-tabs>li {
            margin-bottom: -1px;
            width: 142px;
        }

        .with-nav-tabs.panel-primary .nav-tabs>li>a,
        .with-nav-tabs.panel-primary .nav-tabs>li>a:hover,
        .with-nav-tabs.panel-primary .nav-tabs>li>a:focus {
            color: #fff;
        }

        .with-nav-tabs.panel-primary .nav-tabs>.open>a,
        .with-nav-tabs.panel-primary .nav-tabs>.open>a:hover,
        .with-nav-tabs.panel-primary .nav-tabs>.open>a:focus,
        .with-nav-tabs.panel-primary .nav-tabs>li>a:hover,
        .with-nav-tabs.panel-primary .nav-tabs>li>a:focus {
            color: #fff;
            background-color: #3071a9;
            border-color: transparent;
        }

        .with-nav-tabs.panel-primary .nav-tabs>li.active>a,
        .with-nav-tabs.panel-primary .nav-tabs>li.active>a:hover,
        .with-nav-tabs.panel-primary .nav-tabs>li.active>a:focus {
            color: #428bca;
            background-color: #fff !important;
            border-color: #428bca !important;
            border-bottom-color: transparent !important;
        }

        .with-nav-tabs.panel-primary .nav-tabs>li.dropdown .dropdown-menu {
            background-color: #428bca;
            border-color: #3071a9;
        }

        .with-nav-tabs.panel-primary .nav-tabs>li.dropdown .dropdown-menu>li>a {
            color: #fff;
        }

        .with-nav-tabs.panel-primary .nav-tabs>li.dropdown .dropdown-menu>li>a:hover,
        .with-nav-tabs.panel-primary .nav-tabs>li.dropdown .dropdown-menu>li>a:focus {
            background-color: #3071a9;
        }

        .with-nav-tabs.panel-primary .nav-tabs>li.dropdown .dropdown-menu>.active>a,
        .with-nav-tabs.panel-primary .nav-tabs>li.dropdown .dropdown-menu>.active>a:hover,
        .with-nav-tabs.panel-primary .nav-tabs>li.dropdown .dropdown-menu>.active>a:focus {
            background-color: #4a9fe9;

        }

        .purch {
            font-size: 12px;
        }

        .sknewbtn {
            background-image: linear-gradient(135deg, #09C6F9 10%, #045DE9 100%) !important;
            color: white !important;
        }

        .btn:hover {
            background-color: transparent;
        }

        .colramt {
            color: green;
            font-weight: bold;
        }

        .SKtable>tbody>tr>td {
            padding-right: 15px;
            padding-left: 15px;
        }

        input[type=text]:focus {
            background-color: transparent;
        }

        input[type=number]:focus {
            background-color: transparent;
        }

        input[type=date]:focus {
            background-color: transparent;
        }

        .skfontcolr {
            color: #0b4c78;
            font-weight: bold;
            font-size: 17px;
        }

        #borderimg {
            border: 2px solid #0b4c78;
            padding: 4px;
            border-radius: 7px;
        }

        .txttnew {
            color: #0b4c78;
            text-transform: uppercase;
            font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
            /* overflow-wrap: break-word; */
            margin-bottom: -15px;
            background-color: #f9f9fa;
            overflow: overlay;
            padding: 8px;
        }

        .table-responsive {
            position: relative;
        }

        .table-responsive input[type="checkbox"] {
            position: sticky;
            left: 0;
            z-index: 10;
            /* Ensure it stays above other content */
            background: white;
            /* Ensure visibility over table rows */
        }

        .dtlcolor {
            background-color: #EEEEEE;
            color: black;
            font-size: 14px !important;
        }

        .HDFont {
            font-family: "Verdana";
        }

        .parent-tab {
            width: 100% !important;
        }


        @media print {
            .noPrint {
                display: none;
            }

            /* font-family: "Verdana"; */

        }
    </style>
    </head>

    <script>
        $(document).ready(function() {
            
            $(".nav-tabs-custom").hide();

            $(".main-row").click(function() {
                var tr = $(this).closest("tr"),
                vouchno = tr.find(".vouchno").val(),
                tab_default = "#tabdefault" + "_" + vouchno;
                $(tab_default).toggle();
            });
        });
    </script>

    <body>
        <div class="container" style="width: 1200px;">
            <!-- <?php // include("includes/head_rep.php"); 
                    ?> -->
            <div class="" style="background-color: #aebcc9">
                <table class="" width="100%" id="head">
                    <tr>
                        <td style="font-size:22px" class="HDFont"> </td>
                        <td style="font-size:22px" class="HDFont">
                            <?php echo strtoupper($comp['compname']); ?>
                        </td>
                        <td style="text-align:right">
                            <button onclick="window.print();return false;" class="btn btn-primary noPrint"
                                style="text-align: right">Print</button>

                            <button id='cancel' style="background: #26A69A;" type="button" class="btn btn-danger noPrint"
                                onclick="window.close()">
                                Go Back
                            </button>
                        </td>
                    </tr>
                    <tr>
                        <td style="font-size: 12px" class="HDFont">
                            <?php echo $comp['hoadd1']; ?>
                            <?php echo $comp['hoadd2']; ?>
                            <?php echo $comp['hoadd3']; ?>
                        </td>
                        <td>
                        </td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td></td>
                    </tr>
                    <?php
                    if ($dtype == 1) {
                        $rtype = " - Summary";
                    } elseif ($dtype == 2) {
                        $rtype = " - Detail";
                    } elseif ($dtype == '') {
                        $rtype = '';
                    }

                    $searched_name = mysqli_query($conn, "SELECT accode, name FROM accmast WHERE `accode`='$name'") or die(mysqli_error($conn));
                    $pat_name = mysqli_fetch_array($searched_name);
                    $report_name = "(" . $pat_name['name'] . ")";
                    ?>
                    <tr>
                        <td style="font-size: 16px;color: white" class="HDFont"> </td>
                        <td style="font-size: 16px;color: white" class="HDFont">
                            <?php echo $formname . ' - ' . $report_name; ?>
                        </td>
                        <td style="font-size: 16px;color:white" align="right" class="HDFont">
                            Report Date - <?php echo Date("d-m-Y"); ?>
                        </td>
                    </tr>

                    <tr>
                        <td style="font-size: 14px" class="HDFont">
                            <?php if ($mfdt != '') { ?>
                                From Date -
                                <?php echo $mfdt; ?> &nbsp;&nbsp;&nbsp;
                            <?php }
                            if ($mtdt != '') { ?>
                                To Date -
                            <?php echo $mtdt;
                            } ?>
                        </td>
                        <td>
                        </td>
                    </tr>
                    <tr>
                        <td style="font-size: 14px" class="HDFont" colspan="2">
                            <?php echo $rtype2; ?>
                        </td>
                    </tr>
                    <tr>
                        <td style="font-size: 14px" class="HDFont" colspan="2">&nbsp;
                        </td>
                    </tr>
                    <?php

                    if ($getno2 > 0) {
                    ?>
                        <tr>
                            <td style="font-size: 15px;color:white;padding:5px" class="HDFont" colspan="2">
                                Total No. of Record :&nbsp;&nbsp;<b><?php echo $getno2; ?></b>
                            </td>
                        </tr>
                    <? }
                    ?>
                </table>
            </div>

            <div class="row">
                <div class="tab-pane fade  in active" id="tab1default">
                    <h4><b>Patient History</b></h4>

                    <table style="background: white;width: 100%" class="table table-bordered sktb">
                        <thead class="mySearchTr">
                            <tr>
                                <th width="3%;">Voucher</th>
                                <th width="8%;">Date</th>
                                <th width="15%;">Name</th>
                                <th width="5%;">Gender</th>
                                <th width="4%;">Age</th>
                                <th width="8%;">Mobile</th>
                                <th width="15%;">Email</th>
                                <th width="8%;">Regn.Date</th>
                                <th width="10%;">Complete Date</th>
                                <th width="24%;">Advice & Notice</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php

                            while ($pmain = mysqli_fetch_array($getpmain)) {
                                $getpat = mysqli_query($conn, "SELECT *,DATE_FORMAT(`regndt`, '%d-%m-%Y') AS regndt FROM `accmast` WHERE accode='$pmain[accode]'") or die(mysqli_error($conn));
                                $fetpat = mysqli_fetch_array($getpat);

                                $ctr++;

                                if ($fetpat['gender'] == 'M') {
                                    $gender = "Male";
                                } elseif ($fetpat['gender'] == 'F') {
                                    $gender = "Female";
                                } elseif ($fetpat['gender'] == 'O') {
                                    $gender = "Other";
                                }
                                $vouchno = $pmain['vouchno'];
                                echo "<tr class='main-row'>";
                                echo "<td>$vouchno</td>";
                                echo "<input type='hidden' name='vouchno' class='vouchno' value='$vouchno'>";
                                echo "<td>$pmain[date]</td>";
                                echo "<td>$pmain[name]</td>";
                                echo "<td>$gender</td>";
                                echo "<td>$fetpat[age]</td>";
                                echo "<td>$fetpat[mobile]</td>";
                                echo "<td>$fetpat[email]</td>";
                                echo "<td>$fetpat[regndt]</td>";
                                echo "<td>$pmain[cmpltdt]</td>";
                                echo "<td>$pmain[notes1] $pmain[notes2] $pmain[notes3] $pmain[notes4]</td>";
                                echo "</tr>";
                            ?>
                                <!-- // Navigation Tabs For Details -->

                                <?php
                                echo "<tr>";
                                echo "<td colspan='25'>";

                                ?>

                                <div class='nav-tabs-custom' id="tabdefault_<?= $vouchno ?>">

                                    <ul class='nav nav-tabs sksahil2'>
                                        <li class='active'><a href='#tab2default_<?= $ctr ?>' data-toggle='tab' aria-expanded='true'><b
                                                    style='font-size:15px;'>Consultation</b></a></li>
                                        <li class=''><a href='#tab3default_<?= $ctr ?>' data-toggle='tab' aria-expanded='false'><b
                                                    style='font-size:15px;'>Prescription</b></a></li>
                                        <li class=''><a href='#tab4default_<?= $ctr ?>' data-toggle='tab' aria-expanded='false'><b
                                                    style='font-size:15px;'>Billing</b></a></li>
                                        <li class=''><a href='#tab5default_<?= $ctr ?>' data-toggle='tab' aria-expanded='false'><b
                                                    style='font-size:15px;'>Schedule</b></a></li>
                                    </ul>

                                    <!-- // Navigation Tabs Ends Here    -->

                                    <!-- // tab2default Starts From Here -->


                                    <div class='tab-content'>

                                        <div class='tab-pane active' id='tab2default_<?= $ctr ?>'>
                                            <?php
                                            echo "<table style='background: white;width: 100%;' class='table table-condensed table-bordered'>";
                                            echo "<thead class='mySearchTr'>";
                                            echo "<tr>";
                                            echo "<th>Sr</th>";
                                            echo "<th>Concerns</th>";
                                            echo "<th colspan='2'>Symptoms</th>";
                                            echo "<th colspan='2'>Diagnosis</th>";
                                            echo "<th colspan='2'>Advice</th>";
                                            echo "<th colspan='2'>Investigation</th>";
                                            echo "</tr>";
                                            echo "</thead>";

                                            $ctr2 = 0;
                                            $totamt = 0;
                                            $symptoms = "";
                                            $getsymptoms = mysqli_query($conn, "SELECT * FROM $trandb WHERE vouchno=$pmain[vouchno]") or die(mysqli_error($conn));
                                            while ($fetsymptoms = mysqli_fetch_array($getsymptoms)) {
                                                $ctr2++;
                                                $symptoms .= " " . $fetsymptoms['symptoms'] . ',';
                                            }
                                            $symptoms = rtrim($symptoms, ', ');
                                                echo "<tr class='dtlcolor'>";
                                                echo "<td>$ctr2</td>";
                                                echo "<td>$pmain[concern1]</td>";
                                                echo "<td colspan='2'>$symptoms</td>";
                                                echo "<td colspan='2'>$pmain[diag1] $pmain[diag2]</td>";
                                                echo "<td colspan='2'>$pmain[advice]</td>";
                                                echo "<td colspan='2'>$pmain[invs] $pmain[invs1]</td>";
                                                echo "</tr>";
                                            echo "</table>";
                                            ?>

                                        </div>


                                        <!-- // tab3default Starts From Here -->

                                        <div class='tab-pane' id='tab3default_<?= $ctr ?>'>

                                            <?php
                                            echo "<table style='background: white;width: 100%' class='table table-condensed table-bordered'>";
                                            echo "<thead class='mySearchTr'>";
                                            echo "<tr>";
                                            echo "<th colspan='2'>Sr</th>";
                                            echo "<th colspan='2'>Treatment</th>";
                                            echo "<th colspan='2'>Remarks</th>";
                                            echo "<th colspan='2'>Nos.</th>";
                                            echo "<th colspan='2'>Days</th>";
                                            echo "</tr>";
                                            echo "</thead>";

                                            $ctr3 = 0;
                                            $totamt = 0;
                                            $gtsmtrant = mysqli_query($conn, "SELECT a.*,DATE_FORMAT(`firstdate`, '%d-%m-%Y') AS firstdate ,b.name from `consulttreat` a left join treatment b
                                                            on a.treatment = b.code WHERE vouchno=$pmain[vouchno] order by a.srno");
                                            while ($treatment = mysqli_fetch_array($gtsmtrant)) {
                                                $ctr2++;
                                                echo "<tr id='boldfont' class='dtlcolor'>";
                                                echo "<td colspan='2'>$treatment[srno]</td>";
                                                echo "<td colspan='2'>$treatment[name]</td>";
                                                echo "<td colspan='2'>$treatment[remarks]</td>";
                                                echo "<td colspan='2' class='text-right'>$treatment[qty]</td>";
                                                echo "<td colspan='2' class='text-right'>$treatment[duration]</td>";
                                                echo "</tr>";
                                            }

                                            echo "</table>";
                                            ?>
                                        </div>

                                        <!-- // tab4default Starts From Here -->

                                        <div class='tab-pane' id='tab4default_<?= $ctr ?>'>
                                            <?php
                                            echo "<table style='background: white;width: 100%' class='table table-condensed table-bordered'>";
                                            echo "<thead class='mySearchTr'>";
                                            echo "<tr>";
                                            echo "<th >Sr</th>";
                                            echo "<th colspan='1'>Medicine</th>";
                                            echo "<th colspan='1'>Dosage</th>";
                                            echo "<th>Days</th>";
                                            echo "<th>Qty</th>";
                                            echo "<th class='text-right'>Rate</th>";
                                            echo "<th class='text-right'>Amount</th>";
                                            echo "</tr>";
                                            echo "</thead>";

                                            $ctr4 = 0;
                                            $gtmdtran = mysqli_query($conn, "SELECT a.*,b.name AS medicine from `consultmed` a 
                                                        left join product b on a.item = b.code  WHERE a.`vouchno`='$pmain[vouchno]' order by a.srno");
                                            while ($medicine = mysqli_fetch_array($gtmdtran)) {
                                                $ctr3++;
                                                echo "<tr class='dtlcolor'>";
                                                echo "<td >$ctr3</td>";
                                                echo "<td >$medicine[medicine]</td>";
                                                echo "<td >$medicine[dosage]</td>";
                                                echo "<td >$medicine[duration]</td>";
                                                echo "<td >$medicine[qty]</td>";
                                                echo "<td class='text-right'>$medicine[rate]</td>";
                                                echo "<td class='text-right'>$medicine[amount]</td>";
                                                echo "</tr>";
                                            }
                                            echo "</table>";
                                            ?>
                                        </div>

                                        <!-- // tab5default Starts From Here -->

                                        <div class='tab-pane' id='tab5default_<?= $ctr ?>'>
                                            <?php
                                            echo "<table style='background: white;width: 100%' class='table table-condensed table-bordered'>";
                                            echo "<thead class='mySearchTr'>";
                                            echo "<tr>";
                                            echo "<th>Sr</th>";
                                            echo "<th>Treatment</th>";
                                            echo "<th>Schedule Date</th>";
                                            echo "<th>Remarks</th>";
                                            echo "<th>Complete Date</th>";
                                            echo "</tr>";
                                            echo "</thead>";

                                            $ctr5 = 0;
                                            $getschedule = mysqli_query($conn, "SELECT a.*,DATE_FORMAT(a.`scheddate`, '%d-%m-%Y') AS scheddate ,b.name AS treatment from `schedtreat` a left join treatment b on a.treatment = b.code
                                                 where a.vouchno='$pmain[vouchno]' order by a.scheddate ASC");
                                            while ($schedule = mysqli_fetch_array($getschedule)) {
                                                $ctr5++;
                                                echo "<tr class='dtlcolor'>";
                                                echo "<td>$schedule[srno]</td>";
                                                echo "<td>$schedule[treatment]</td>";
                                                echo "<td>$schedule[scheddate]</td>";
                                                echo "<td>$schedule[remarks]</td>";
                                                echo "<td>$schedule[compltdt]</td>";
                                                echo "</tr>";
                                            }

                                            echo "</table>";
                                            ?>

                                        </div>

                                    </div>

                                </div>
                            <?php
                                echo "</td>";
                                echo "</tr>";
                            }
                            ?>

                        </tbody>
                    </table>
                </div>
                <!-- </div> -->
            </div>
        </div>

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

    </html>
<?php
}

?>