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

$maindb = "consultmain";
$trandb = "consultsymp";
$formname = 'Consultancy Register';
$file = "consultreg_fr.php";
$zroot = $_SESSION["zdir"];

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

$name = $_POST['name'];
$namecond = "";

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

if (($_GET["fdt"]) != '') {
    $mfrmdate = $_GET["fdt"];
    $mtodate = $_GET["tdt"];
    $mfdt = date("d-m-y", strtotime($mfrmdate));
    $mtdt = date("d-m-y", strtotime($mtodate));
    $dtype = $_GET["rpt"];
} else {

    $mfrmdate = trim($_POST["fromdt"]);
    $mtodate = trim($_POST["todt"]);


    if (empty($_POST["fromdt"])) {
        browse("From Date Cannot Be Empty");
        header("refresh:1; salereg.php");
    }
    if (empty($_POST["todt"])) {
        browse("To Date Cannot Be Empty");
        header("refresh:1; salereg.php");
    }
    $mfdt = date("d-m-Y", strtotime($mfrmdate));
    $mtdt = date("d-m-Y", strtotime($mtodate));
}

$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 `vouchdt` >= '$mfrmdate' AND `vouchdt` <= '$mtodate' $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 */
        }

        #tab6default {

            /* background-color: #bbc3c9; */
            /* Ensure visibility over table rows */
        }

        /* table styling */
        /* .table1 {
            width: 1000px !important;
        }

        .table2 {
            float: left;
            width: 500px;
            padding: 5px;
        } */

        /* Clearfix (clear floats) */
        .table1::after {
            content: "";
            clear: both;
            display: table;
        }
    </style>

    </head>

    <body>
        <div class="container-fluid" style="width: 1500px;">
            <?php include("includes/head_rep.php"); ?>
            <div class="row">
                <div class="col-lg-12 skbackcolor">
                    <div class="with-nav-tabs ">
                        <div class="">
                            <ul class="nav nav-tabs sksahil2">
                                <?php
                                if ($_POST["dtype"] == 1) {
                                    echo "<li class=active><a href='#tab1default' data-toggle='tab'><b style=font-size:15px;>Summary</b></a></li>";
                                } elseif ($_POST["dtype"] == 2) {
                                    echo "<li class=active><a href='#tab1default' data-toggle='tab'><b style=font-size:15px;>Summary</b></a></li>";
                                    echo "<li><a href='#tab2default' data-toggle='tab'><b style='font-size:15px;'>Consultation</b></a></li>";
                                    echo "<li><a href='#tab3default' data-toggle='tab'><b style='font-size:15px;'>Prescription</b></a></li>";
                                    // echo "<li><a href='#tab4default' data-toggle='tab'><b style='font-size:15px;'>Medicine </b></a></li>";
                                    echo "<li><a href='#tab4default' data-toggle='tab'><b style='font-size:15px;'>Billing </b></a></li>";
                                    echo "<li><a href='#tab5default' data-toggle='tab'><b style='font-size:15px;'>Schedule </b></a></li>";
                                    echo "<li><a href='#tab6default' data-toggle='tab'><b style='font-size:15px;'>Photos </b></a></li>";
                                }
                                ?>
                            </ul>
                        </div>
                        <div class="tab-content">

                            <div class="tab-pane fade  in active" id="tab1default">
                                <h4><b>Summary Details</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";
                                            }
                                            echo "<tr id='boldfont' class='clickable-row2 click-tab' data-href='consult_ent.php?vouchno=$pmain[vouchno]&mode=edit' data-target='_blank'>";
                                            echo "<td>$pmain[vouchno]</td>";
                                            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>";
                                        }
                                        ?>
                                    </tbody>
                                </table>
                            </div>


                            <!-- Tab 2 Start -->
                            <div class="tab-pane fade" id="tab2default">
                                <div class="row hidtabpane">

                                    <h4><b>Consultation</b></h4>

                                    <table style="background: white;width: 100%" class="table table-condensed table-striped table-hover table-bordered">
                                        <thead class="mySearchTr">
                                            <tr>
                                                <th width="33%;">Voucher</th>
                                                <th width="33%;">Date</th>
                                                <th width="34%;">Name</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php
                                            $getconsult = mysqli_query($conn, "SELECT m.*,DATE_FORMAT(m.`vouchdt`, '%d-%m-%Y') AS date, a.accode, a.name AS name FROM $maindb m
                                                                            LEFT JOIN accmast a ON a.accode=m.accode WHERE `vouchdt` >= '$mfrmdate' AND `vouchdt` <= '$mtodate' AND vouchno!='' $namecond") or die(mysqli_error($conn));
                                            while ($fetconsult = mysqli_fetch_array($getconsult)) {

                                                echo "<tr data-href='consult_ent.php?vouchno=$fetconsult[vouchno]&mode=edit' class='clickable-row2' style='cursor: pointer;$skstyle' [target]='_blank'>";
                                                echo "<td><b>$fetconsult[vouchno]</b></td>";
                                                echo "<td><b>$fetconsult[date]</b></td>";
                                                echo "<td><b>$fetconsult[name]</b></td>";
                                                echo "</tr>";

                                                if ($_POST["dtype"] == 2) {


                                                    echo "<tr class='' style='background-color:#BABFC2;font-size:14px;font-weight:bold'>";
                                                    echo "<th style='width:33%;'>Sr</th>";
                                                    echo "<th style='width:33%;'>Diagnosis</th>";
                                                    echo "<th style='width:34%;'>Symptoms</th>";
                                                    echo "</tr>";

                                                    $ctr2 = 0;
                                                    $totamt = 0;
                                                    $symptoms = "";
                                                    $getsymptoms = mysqli_query($conn, "SELECT * FROM $trandb WHERE vouchno=$fetconsult[vouchno]") or die(mysqli_error($conn));
                                                    while ($fetsymptoms = mysqli_fetch_array($getsymptoms)) {
                                                        $symptoms .=  " " . $fetsymptoms['symptoms'];
                                                    }
                                                    $ctr2++;
                                                    echo "<tr>";
                                                    echo "<td>$ctr2</td>";
                                                    echo "<td>$fetconsult[diag1] $fetconsult[diag2]</td>";
                                                    echo "<td>$symptoms</td>";
                                                    echo "</tr>";
                                                    echo "<tr style='background-color:#E6F1FF;font-weight:bold;'>";
                                                    echo "<td class='text-right'></td>";
                                                    echo "<td class='text-right'></td>";
                                                    echo "<td class='text-right'></td>";
                                                    echo "</tr>";
                                                }
                                            }
                                            ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            <!-- Tab 2 End -->


                            <!-- Tab 3 Start -->
                            <div class="table2 tab-pane fade" id="tab3default">
                                <div class="col-lg-12 row">
                                    <div class="table2 col-lg-6">
                                        <h4><b>Treatment</b></h4>

                                        <table style="background: white;width: 100%" class="table1 table table-condensed table-striped table-hover table-bordered">
                                            <thead class="mySearchTr">
                                                <tr>
                                                    <th width="7%;">Voucher</th>
                                                    <th width="15%;">Date</th>
                                                    <th width="20%;">Name</th>
                                                    <th width="60%;" colspan="9"></th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php
                                                $gettreat = mysqli_query($conn, "SELECT m.*,DATE_FORMAT(m.`vouchdt`, '%d-%m-%Y') AS date, a.accode, a.name AS name FROM $maindb m
                                                                            LEFT JOIN accmast a ON a.accode=m.accode WHERE `vouchdt` >= '$mfrmdate' AND `vouchdt` <= '$mtodate' AND vouchno!=''  $namecond") or die(mysqli_error($conn));
                                                while ($fettreat = mysqli_fetch_array($gettreat)) {

                                                    if ($photel['para'] == "M") {
                                                        $skstyle   =  "background-color:#e6f1ff";
                                                    }

                                                    echo "<tr data-href='consult_ent.php?vouchno=$fettreat[vouchno]&mode=edit' class='clickable-row2' style='cursor: pointer;$skstyle' [target]='_blank'>";
                                                    echo "<td><b>$fettreat[vouchno]</b></td>";
                                                    echo "<td><b>$fettreat[date]</b></td>";
                                                    echo "<td><b>$fettreat[name]</b></td>";
                                                    echo "<td colspan='9'></td>";
                                                    echo "</tr>";

                                                    $tothotelamt = $tothotelamt + $hotelamt;
                                                    $tothotelinramt = $tothotelinramt + $hotelinramt;

                                                    if ($_POST["dtype"] == 2) {

                                                        echo "<tr class='' style='background-color:#BABFC2;font-size:14px;font-weight:bold'>";
                                                        echo "<th style='width:5%;'>Sr</th>";
                                                        echo "<th style='width:15%;'>Treatment</th>";
                                                        echo "<th style='width:20%;'>Remarks</th>";
                                                        echo "<th style='width:3%;' class='text-right'>Nos.</th>";
                                                        echo "<th style='width:4%;' class='text-right'>Days</th>";
                                                        echo "<th style='width:5%;'>Approve</th>";
                                                        echo "<th style='width:9%;'>First Date</th>";
                                                        echo "</tr>";

                                                        $ctr2 = 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=$fettreat[vouchno] order by a.srno");
                                                        while ($treatment = mysqli_fetch_array($gtsmtrant)) {

                                                            $ctr2++;
                                                            echo "<tr  id='boldfont' class='clickable-row2 click-tab' data-href='consult_ent.php?vouchno=$treatment[vouchno]&mode=edit' data-target='_blank'>";
                                                            echo "<td>$treatment[srno]</td>";
                                                            echo "<td>$treatment[name]</td>";
                                                            echo "<td>$treatment[remarks]</td>";
                                                            echo "<td class='text-right'>$treatment[qty]</td>";
                                                            echo "<td class='text-right'>$treatment[duration]</td>";
                                                            echo "<td>$treatment[aprov]</td>";
                                                            echo "<td>$treatment[firstdate]</td>";
                                                            echo "</tr>";
                                                        }
                                                        echo "<tr style='background-color:#E6F1FF;font-weight:bold;'>";
                                                        echo "<td class='text-right' colspan='12'></td>";
                                                        echo "</tr>";
                                                    }
                                                }
                                                ?>
                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="table2 col-lg-6">
                                        <h4><b>Medicine</b></h4>

                                        <table style="background: white;width: 100%" class="table2 table table-condensed table-striped table-hover table-bordered">
                                            <thead class="mySearchTr">
                                                <tr>
                                                    <th width="10%;">Voucher</th>
                                                    <th width="10%;">Date</th>
                                                    <th width="20%;">Name</th>
                                                    <th colspan='4'></th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php
                                                $getmedicine = mysqli_query($conn, "SELECT m.*,DATE_FORMAT(m.`vouchdt`, '%d-%m-%Y') AS date, a.accode, a.name AS name FROM $maindb m
                                                                            LEFT JOIN accmast a ON a.accode=m.accode WHERE `vouchdt` >= '$mfrmdate' AND `vouchdt` <= '$mtodate' AND vouchno!='' $namecond") or die(mysqli_error($conn));
                                                while ($fetmedicine = mysqli_fetch_array($getmedicine)) {

                                                    echo "<tr data-href='consult_ent.php?vouchno=$fetmedicine[vouchno]&mode=edit' class='clickable-row2' style='cursor: pointer;$skstyle' [target]='_blank'>";
                                                    echo "<td><b>$fetmedicine[vouchno]</b></td>";
                                                    echo "<td><b>$fetmedicine[date]</b></td>";
                                                    echo "<td><b>$fetmedicine[name]</b></td>";
                                                    echo "<td colspan='4'><b></b></td>";
                                                    echo "</tr>";

                                                    if ($_POST["dtype"] == 2) {

                                                        echo "<tr class='' style='background-color:#BABFC2'>";
                                                        echo "<th style='width:5%;'>Sr</th>";
                                                        echo "<th style='width:20%;'>Medicine</th>";
                                                        echo "<th style='width:10%;'>Dosage</th>";
                                                        echo "<th style='width:10%;'>Days</th>";
                                                        echo "</tr>";

                                                        $ctr2 = 0;
                                                        $totamt = 0;
                                                        $totnight = 0;
                                                        $totpax = 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`='$fetmedicine[vouchno]' order by a.srno");
                                                        while ($medicine = mysqli_fetch_array($gtmdtran)) {
                                                            $ctr2++;
                                                            echo "<tr>";
                                                            echo "<td>$ctr2</td>";
                                                            echo "<td>$medicine[medicine]</td>";
                                                            echo "<td>$medicine[dosage]</td>";
                                                            echo "<td>$medicine[duration]</td>";
                                                            echo "</tr>";
                                                        }
                                                        echo "<tr style='background-color:#E6F1FF;font-weight:bold;'>";
                                                        echo "<td class='text-right' colspan='7'></td>";
                                                        echo "</tr>";
                                                    }
                                                }
                                                ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                            <!-- Tab 3 End -->

                            <!-- Tab 5 Start -->
                            <div class="table2 tab-pane fade" id="tab4default">
                                <div class="col-lg-12 row">
                                    <div class="table2 col-lg-6">
                                        <h4><b>Treatment Bill</b></h4>

                                        <table style="background: white;width: 100%" class="table1 table table-condensed table-striped table-hover table-bordered">
                                            <thead class="mySearchTr">
                                                <tr>
                                                    <th width="5%;">Voucher</th>
                                                    <th width="24%;">Name</th>
                                                    <th width="10;">Date</th>
                                                    <th width="12%;" class="text-right">Disc Amt</th>
                                                    <th width="13%;" class="text-right">Final Fees</th>
                                                    <th width="13%;" class="text-right">Paid Fees</th>
                                                    <th width="14%;" class="text-right">Balance Fees</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php
                                                $gettreat = mysqli_query($conn, "SELECT m.*,DATE_FORMAT(m.`vouchdt`, '%d-%m-%Y') AS date, a.accode, a.name AS name FROM $maindb m
                                                                            LEFT JOIN accmast a ON a.accode=m.accode WHERE `vouchdt` >= '$mfrmdate' AND `vouchdt` <= '$mtodate' AND vouchno!=''  $namecond") or die(mysqli_error($conn));
                                                while ($fettreat = mysqli_fetch_array($gettreat)) {

                                                    if ($photel['para'] == "M") {
                                                        $skstyle   =  "background-color:#e6f1ff";
                                                    }

                                                    $getpay = mysqli_query($conn, "SELECT sum(amount) as tamt,paidfor FROM `actran` WHERE slvouch='$fettreat[vouchno]' and accode='$fettreat[accode]' group by paidfor") or die(mysqli_error($conn));

                                                    if (!empty($getpay)) {
                                                        while ($mpay = mysqli_fetch_array($getpay)) {
                                                            $mpaid = $mpay["tamt"];
                                                            $paidfor = $mpay["paidfor"];

                                                            if ($paidfor == "C") {
                                                                $conspaid = $mpay["tamt"];
                                                            } else if ($paidfor == "T") {
                                                                $treatpaid = $mpay["tamt"];
                                                            } else if ($paidfor == "M") {
                                                                $medpaid = $mpay["tamt"];
                                                            } else {
                                                                $othpaid = $mpay["tamt"];
                                                            }
                                                            $paidamt = $paidamt + $mpaid;
                                                        }
                                                    }

                                                    $tottreat = $fettreat['treattotal'] - $fettreat['trdiscamt'];
                                                    $baltreat = $tottreat - $treatpaid;

                                                    echo "<tr data-href='consult_ent.php?vouchno=$fettreat[vouchno]&mode=edit' class='clickable-row2' style='cursor: pointer;$skstyle' [target]='_blank'>";
                                                    echo "<td><b>$fettreat[vouchno]</b></td>";
                                                    echo "<td><b>$fettreat[name]</b></td>";
                                                    echo "<td><b>$fettreat[date]</b></td>";
                                                    echo "<td class='text-right'><b>$fettreat[trdiscamt]</b></td>";
                                                    echo "<td class='text-right'><b>$tottreat</b></td>";
                                                    if ($treatpaid > 0) {
                                                        echo "<td class='text-right' style='color:green'><b>$treatpaid</b></td>";
                                                    } else {
                                                        echo "<td class='text-right'><b>0</b></td>";
                                                    }

                                                    if ($baltreat > 0) {
                                                        echo "<td colspan='2' class='text-right' style='color:red'><b>$baltreat</b></td>";
                                                    } else {
                                                        echo "<td colspan='2' class='text-right'><b>0</b></td>";
                                                    }
                                                    echo "</tr>";

                                                    $tothotelamt = $tothotelamt + $hotelamt;
                                                    $tothotelinramt = $tothotelinramt + $hotelinramt;

                                                    if ($_POST["dtype"] == 2) {

                                                        echo "<tr class='' style='background-color:#BABFC2;font-size:14px;font-weight:bold'>";
                                                        echo "<th style='width:5%;'>Sr</th>";
                                                        // echo "<th style='width:9%;' class='text-right'>First Date</th>";
                                                        echo "<th style='width:15%;'>Treatment</th>";
                                                        echo "<th style='width:10%;' class='text-right'>Nos.</th>";
                                                        echo "<th style='width:4%;' class='text-right'>Days</th>";
                                                        echo "<th style='width:5%;' class='text-right'>Rate</th>";
                                                        echo "<th style='width:9%;' class='text-right'>Amount</th>";
                                                        echo "<th style='width:9%;'>Apprv</th>";
                                                        echo "</tr>";

                                                        $ctr2 = 0;
                                                        $totamt = 0;

                                                        $gtsmtrant = mysqli_query($conn, "SELECT a.*,DATE_FORMAT(`firstdate`, '%d-%m-%Y') AS firstdate, b.name FROM `treatbill` a LEFT JOIN treatment b
                                                                                            ON a.treatment = b.code WHERE a.vouchno='$fettreat[vouchno]' ORDER BY a.srno");
                                                        while ($treatment = mysqli_fetch_array($gtsmtrant)) {

                                                            $ctr2++;
                                                            echo "<tr  id='boldfont' class='clickable-row2 click-tab' data-href='consult_ent.php?vouchno=$treatment[vouchno]&mode=edit' data-target='_blank'>";
                                                            echo "<td>$treatment[srno]</td>";
                                                            // echo "<td>$treatment[firstdate]</td>";
                                                            echo "<td>$treatment[name]</td>";
                                                            echo "<td class='text-right'>$treatment[qty]</td>";
                                                            echo "<td class='text-right'>$treatment[duration]</td>";
                                                            echo "<td class='text-right'>$treatment[rate]</td>";
                                                            echo "<td class='text-right'>$treatment[amt]</td>";
                                                            if ($treatment['aprov'] == 1) {
                                                                $apprv = "Yes";
                                                            } else {
                                                                $apprv = "No";
                                                            }
                                                            echo "<td>$apprv</td>";
                                                            echo "</tr>";
                                                        }
                                                        echo "<tr style='background-color:#E6F1FF;font-weight:bold;'>";
                                                        echo "<td class='text-right' colspan='12'></td>";
                                                        echo "</tr>";
                                                    }
                                                }
                                                ?>
                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="table2 col-lg-6">
                                        <h4><b>Medicine Bill</b></h4>

                                        <table style="background: white;width: 100%" class="table2 table table-condensed table-striped table-hover table-bordered">
                                            <thead class="mySearchTr">
                                                <tr>
                                                    <th width="5%;">Voucher</th>
                                                    <th width="21%;">Name</th>
                                                    <th width="10%;">Date</th>
                                                    <th width="12%;" class="text-right">Disc Amt</th>
                                                    <th width="13%;" class="text-right">Final Fees</th>
                                                    <th width="13%;" class="text-right">Paid Fees</th>
                                                    <th width="14%;" class="text-right">Balance Fees</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php
                                                $getmedicine = mysqli_query($conn, "SELECT m.*,DATE_FORMAT(m.`vouchdt`, '%d-%m-%Y') AS date, a.accode, a.name AS name FROM $maindb m
                                                                            LEFT JOIN accmast a ON a.accode=m.accode WHERE `vouchdt` >= '$mfrmdate' AND `vouchdt` <= '$mtodate' AND vouchno!='' $namecond") or die(mysqli_error($conn));
                                                while ($fetmedicine = mysqli_fetch_array($getmedicine)) {

                                                    $totmed = $fetmedicine['medtotal'] - $fetmedicine['meddiscamt'];

                                                    $getpay = mysqli_query($conn, "SELECT sum(amount) as tamt,paidfor FROM `actran` WHERE slvouch='$getvouch' and accode = '$get[accode]' group by paidfor") or die(mysqli_error($conn));
                                                    
                                                    if (!empty($getpay)) {

                                                        while ($mpay = mysqli_fetch_array($getpay)) {

                                                            $mpaid = $mpay["tamt"];

                                                            $paidfor = $mpay["paidfor"];
                                                            if ($paidfor == "C") {
                                                                $conspaid = $mpay["tamt"];
                                                            } else if ($paidfor == "T") {
                                                                $treatpaid = $mpay["tamt"];
                                                            } else if ($paidfor == "M") {
                                                                $medpaid = $mpay["tamt"];
                                                            } else {
                                                                $othpaid = $mpay["tamt"];
                                                            }
                                                            $paidamt = $paidamt + $mpaid;
                                                        }
                                                    }

                                                    $balmed = $totmed - $medpaid;

                                                    echo "<tr data-href='consult_ent.php?vouchno=$fetmedicine[vouchno]&mode=edit' class='clickable-row2' style='cursor: pointer;$skstyle' [target]='_blank'>";
                                                    echo "<td><b>$fetmedicine[vouchno]</b></td>";
                                                    echo "<td><b>$fetmedicine[name]</b></td>";
                                                    echo "<td><b>$fetmedicine[date]</b></td>";
                                                    echo "<td class='text-right'><b>$fetmedicine[meddiscamt]</b></td>";
                                                    echo "<td class='text-right'><b>$totmed</b></td>";
                                                    if($medpaid > 0){
                                                        echo "<td class='text-right' style='color:green'><b>$medpaid</b></td>";
                                                    }else{
                                                        echo "<td class='text-right'><b>0</b></td>";
                                                    }
                                                    
                                                    if($balmed){
                                                        echo "<td class='text-right' style='color:red'><b>$balmed</b></td>";
                                                    }else{
                                                        echo "<td class='text-right'><b>0</b></td>";
                                                    }
                                                    echo "</tr>";

                                                    if ($_POST["dtype"] == 2) {

                                                        echo "<tr class='' style='background-color:#BABFC2'>";
                                                        echo "<th style='width:5%;'>Sr</th>";
                                                        echo "<th style='width:20%;' colspan='2'>Medicine</th>";
                                                        echo "<th style='width:10%;' class='text-right'>Qty</th>";
                                                        echo "<th style='width:10%;' class='text-right'>Rate</th>";
                                                        echo "<th style='width:10%;' colspan='2' class='text-right'>Amount</th>";
                                                        echo "</tr>";

                                                        $ctr2 = 0;
                                                        $totamt = 0;
                                                        $totnight = 0;
                                                        $totpax = 0;

                                                        $gtmdtran = mysqli_query($conn, "SELECT a.*,b.name FROM `medbill` a LEFT JOIN product b
                                                                                            ON a.item = b.code WHERE a.vouchno='$fetmedicine[vouchno]' ORDER BY a.srno");
                                                        while ($medicine = mysqli_fetch_array($gtmdtran)) {
                                                            $ctr2++;
                                                            echo "<tr>";
                                                            echo "<td>$ctr2</td>";
                                                            echo "<td colspan='2'>$medicine[name]</td>";
                                                            echo "<td class='text-right'>$medicine[qty]</td>";
                                                            echo "<td class='text-right'>$medicine[rate]</td>";
                                                            echo "<td colspan='2' class='text-right'>$medicine[amount]</td>";
                                                            echo "</tr>";
                                                        }
                                                        echo "<tr style='background-color:#E6F1FF;font-weight:bold;'>";
                                                        echo "<td class='text-right' colspan='7'></td>";
                                                        echo "</tr>";
                                                    }
                                                }
                                                ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>












                            <!-- <div class="tab-pane fade" id="tab4default">

                                <h4><b>Billing</b></h4>

                                <table style="background: white;width: 100%" class="table table-condensed table-striped table-hover table-bordered">
                                    <thead class="mySearchTr">
                                        <tr>
                                            <th width="10%;">Voucher</th>
                                            <th width="10%;">Date</th>
                                            <th width="20%;">Name</th>
                                            <th colspan='2'></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $getbill = mysqli_query($conn, "SELECT m.*,DATE_FORMAT(m.`vouchdt`, '%d-%m-%Y') AS date, a.accode, a.name AS name FROM $maindb m
                                        LEFT JOIN accmast a ON a.accode=m.accode WHERE `vouchdt` >= '$mfrmdate' AND `vouchdt` <= '$mtodate' AND vouchno!='' $namecond") or die(mysqli_error($conn));
                                        while ($fetbill = mysqli_fetch_array($getbill)) {

                                            echo "<tr data-href='consult_ent.php?vouchno=$fetbill[vouchno]&mode=edit' class='clickable-row2' style='cursor: pointer;$skstyle' [target]='_blank'>";
                                            echo "<td><b>$fetbill[vouchno]</b></td>";
                                            echo "<td><b>$fetbill[date]</b></td>";
                                            echo "<td><b>$fetbill[name]</b></td>";
                                            echo "<td colspan='2'></td>";
                                            echo "</tr>";

                                            if ($_POST["dtype"] == 2) {

                                                echo "<tr class='' style='background-color:#BABFC2'>";
                                                echo "<th style='width:5%;'>Sr</th>";
                                                echo "<th style='width:10%;'>Consulting Fees</th>";
                                                echo "<th style='width:10%;'>Treatment Fees</th>";
                                                echo "<th style='width:30%;'>Medicine Fees</th>";
                                                echo "<th style='width:10%;'>Total Amount</th>";
                                                echo "</tr>";

                                                $ctr2 = 0;
                                                $totlaund = 0;
                                                $totnight = 0;
                                                $totpax = 0;

                                                $getbilling = mysqli_query($conn, "SELECT *,DATE_FORMAT(`vouchdt`, '%d-%m-%Y') AS date FROM $maindb WHERE vouchno='$fetbill[vouchno]'") or die(mysqli_error($conn));
                                                while ($billing = mysqli_fetch_array($getbilling)) {

                                                    $ctr2++;
                                                    echo "<tr>";
                                                    echo "<td>$ctr2</td>";
                                                    echo "<td>$billing[consultfees]</td>";
                                                    echo "<td>$billing[ttamount]</td>";
                                                    echo "<td>$billing[tmedamount]</td>";
                                                    echo "<td>$billing[billamt]</td>";
                                                    echo "</tr>";
                                                }
                                                echo "<tr style='background-color:#E6F1FF;font-weight:bold;'>";
                                                echo "<td class='text-right' colspan='5'></td>";
                                                echo "</tr>";
                                            }
                                        }
                                        ?>
                                    </tbody>
                                </table>
                            </div> -->
                            <!-- Tab 5 End -->

                            <!-- Tab 6 Start -->
                            <div class="tab-pane fade" id="tab5default">

                                <h4><b>Schedule</b></h4>

                                <table style="background: white;width: 100%" class="table table-condensed table-striped table-hover table-bordered">
                                    <thead class="mySearchTr">
                                        <tr>
                                            <th width="10%;">Voucher</th>
                                            <th width="10%;">Date</th>
                                            <th width="20%;">Name</th>
                                            <th colspan='2'></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $getschdl = mysqli_query($conn, "SELECT m.*,DATE_FORMAT(m.`vouchdt`, '%d-%m-%Y') AS date, a.accode, a.name AS name FROM $maindb m
                                        LEFT JOIN accmast a ON a.accode=m.accode WHERE `vouchdt` >= '$mfrmdate' AND `vouchdt` <= '$mtodate' AND vouchno!='' $namecond") or die(mysqli_error($conn));
                                        while ($fetschdl = mysqli_fetch_array($getschdl)) {

                                            $pctr++;
                                            echo "<tr data-href='consult_ent.php?vouchno=$fetschdl[vouchno]&mode=edit' class='clickable-row2' style='cursor: pointer;$skstyle' [target]='_blank'>";
                                            echo "<td><b>$fetschdl[vouchno]</b></td>";
                                            echo "<td><b>$fetschdl[date]</b></td>";
                                            echo "<td><b>$fetschdl[name]</b></td>";
                                            echo "</tr>";

                                            if ($_POST["dtype"] == 2) {

                                                echo "<tr class='' style='background-color:#BABFC2'>";
                                                echo "<th style='width:5%;'>Sr</th>";
                                                echo "<th style='width:10%;'>Treatment</th>";
                                                echo "<th style='width:10%;'>Schedule Date</th>";
                                                echo "<th style='width:10%;'>Remarks</th>";
                                                echo "<th style='width:10%;'>Complete Date</th>";
                                                echo "</tr>";

                                                $getschedule = mysqli_query($conn, "SELECT a.*,b.name AS treatment from `schedtreat` a left join treatment b on a.treatment = b.code
                                                 where a.vouchno='$fetschdl[vouchno]' order by a.scheddate ASC");
                                                while ($schedule = mysqli_fetch_array($getschedule)) {

                                                    $ctr2++;
                                                    echo "<tr data-href='sale.php?mode=edit&vouchno=$voucher' class='clickable-row2' style='cursor: pointer;$skstyle' [target]='_blank'>";
                                                    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 "<tr style='background-color:#E6F1FF;font-weight:bold;'>";
                                                echo "<td class='text-right' colspan='5'></td>";
                                                echo "</tr>";
                                            }
                                        }
                                        ?>
                                    </tbody>
                                </table>
                            </div>
                            <!-- Tab 6 End -->


                            <!-- Tab 7 Start -->
                            <div class="tab-pane fade" id="tab6default">

                                <h4><b>Photos</b></h4>
                                <table style="background: white;width: 100%" class="table table-condensed table-striped table-hover table-bordered">
                                    <thead class="mySearchTr">
                                        <tr>
                                            <th width="33%;">Voucher</th>
                                            <th width="33%;">Date</th>
                                            <th width="34%;">Name</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $getphoto = mysqli_query($conn, "SELECT m.*,DATE_FORMAT(m.`vouchdt`, '%d-%m-%Y') AS date, a.accode, a.name AS name FROM $maindb m
                                        LEFT JOIN accmast a ON a.accode=m.accode WHERE `vouchdt` >= '$mfrmdate' AND `vouchdt` <= '$mtodate' AND vouchno!='' $namecond") or die(mysqli_error($conn));
                                        while ($fetphoto = mysqli_fetch_array($getphoto)) {

                                            echo "<tr data-href='consult_ent.php?vouchno=$fetphoto[vouchno]&mode=edit' class='clickable-row2' style='cursor: pointer;$skstyle' [target]='_blank'>";
                                            echo "<td><b>$fetphoto[vouchno]</b></td>";
                                            echo "<td><b>$fetphoto[date]</b></td>";
                                            echo "<td><b>$fetphoto[name]</b></td>";
                                            echo "</tr>";


                                            if ($_POST["dtype"] == 2) {

                                                echo "<tr class='' style='background-color:#BABFC2'>";
                                                echo "<th style='width:10%;'>Image (Before)</th>";
                                                echo "<th style='width:10%;'>Image (After)</th>";
                                                echo "<th style='width:10%;'>Consent PDF</th>";
                                                echo "</tr>";

                                                $getimage = mysqli_query($conn, "SELECT m.*,DATE_FORMAT(m.`vouchdt`, '%d-%m-%Y') AS date, a.accode, a.name AS name FROM $maindb m
                                                LEFT JOIN accmast a ON a.accode=m.accode WHERE vouchno='$fetphoto[vouchno]' $namecond") or die(mysqli_error($conn));
                                                while ($fetimage = mysqli_fetch_array($getimage)) {

                                                    $consentpdf = $fetimage['consentpdf'];
                                                    $ctr2++;
                                                    echo "<tr data-href='sale.php?mode=edit&vouchno=$voucher' class='clickable-row2' style='cursor: pointer;$skstyle' [target]='_blank'>";
                                                    echo "<td><img src='$fetimage[imgbef]' style='width: 325px; height: 250px;' alt='Before Image Not Uploaded' /></td>";
                                                    echo "<td><img src='$fetimage[imgaft]' style='width: 325px; height: 250px;' alt='After Image Not Uploaded' /></td>";
                                                    if (file_exists("$consentpdf")) {
                                                        echo "<td><iframe src='$consentpdf' width='325' height='250' style='border:none;' scrolling='yes'></iframe></td>";
                                                    } else {
                                                        echo "<td><b>Consent Pdf Not Uploaded</b></td>";
                                                    }
                                                    echo "</tr>";
                                                }
                                                echo "<tr style='background-color:#E6F1FF;font-weight:bold;'>";
                                                echo "<td class='text-right' colspan='3'></td>";
                                                echo "</tr>";
                                            }
                                        }
                                        ?>
                                        <!-- <script>
                                            $(document).ready(function() {
                                                $('#myIframe').on('error', function() {
                                                    $('#message').text("File hasn't been uploaded yet");
                                                });
                                            });
                                        </script> -->
                                    </tbody>
                                </table>
                            </div>
                            <!-- Tab 7 End -->

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

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

    </html>
<?php
}

?>