<?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);


$custcond = "";

$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["frmdt"]);
    $mtodate = trim($_POST["todt"]);


    if (empty($_POST["frmdt"])) {
        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, a.accode, a.name AS name FROM $maindb m
                                LEFT JOIN accmast a ON a.accode=m.accode
                                WHERE `vouchdt` >= '$mfrmdate' AND `vouchdt` <= '$mtodate' $statuscond $custcond $paracond") or die(mysqli_error($conn));
$getno2 = mysqli_num_rows($getpmain);
if (isset($_POST["view"]) || ($_GET["view"])) {

    include("includes/linkshead.php");
?>
    <style type="text/css">
        #tabital {
            font-style: italic;
        }

        #font1 {
            font-style: italic;
        }

        #boldfont {
            font-weight: bold;
        }

        /* CSS */
        .button-29 {
            align-items: center;
            appearance: none;
            background: transparent;
            border: 2px solid #0b4c78;
            border-radius: 6px;
            box-sizing: border-box;
            color: #0b4c78;
            cursor: pointer;
            display: inline-flex;
            font-family: "JetBrains Mono", monospace;
            height: 38px;
            width: 88px;
            justify-content: center;
            line-height: 1;
            list-style: none;
            overflow: hidden;
            padding-left: 16px;
            padding-right: 16px;
            position: relative;
            text-align: left;
            text-decoration: none;
            transition: box-shadow .15s, transform .15s;
            user-select: none;
            -webkit-user-select: none;
            touch-action: manipulation;
            white-space: nowrap;
            will-change: box-shadow, transform;
            font-size: 18px;
        }

        .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;
            margin-bottom: -15px;
            background-color: #f9f9fa;
            overflow: overlay;
            padding: 8px;
        }
    </style>

    </head>
        <script>
            $(document).ready(function() {
                
            });
        </script>
    <body>
        <div class="container">
            <?php include("includes/head_rep.php"); ?>
            <div class="row">
                <div class="col-lg-12 ">
                    <table style="background: white;width: 100%" class="table table-condensed table-hover table-bordered">
                        <thead class="mySearchTr">
                            <tr>
                                <th width="15%;">Voucher</th>
                                <th width="15%;">Date</th>
                                <th width="15%;">Name</th>
                                <th width="55%;">Advice & Notice</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $ctr = 0;
                            $tothotelpuramt = 0;

                            while ($pmain = mysqli_fetch_array($getpmain)) {
                                $ctr++;

                                echo "<tr id='boldfont' class='clickable-row2 click-tab' data-href='laundsl.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>$pmain[notes1] $pmain[notes2] $pmain[notes3] $pmain[notes4]</td>";
                                echo "</tr>";

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

                                    echo "<tr style='height:10px;'>";
                                    echo "<td colspan='25'>";
                                    echo "<table style='width:100%;' id='tabital' class='table table-condensed table-hover table-bordered'>";
                                    echo "<thead>";
                                    echo "<tr class='' style='background-color:#BABFC2'>";
                                    echo "<th style='width:3%;'>Sr</th>";
                                    echo "<th style='width:7%;'>Check In</th>";
                                    echo "<th style='width:7%;'>Check Out</th>";
                                    echo "<th style='width:10%;'>Hotel</th>";
                                    echo "<th style='width:6%;'>No. Nights</th>";
                                    echo "<th style='width:5%;'>No. Pax</th>";
                                    echo "<th style='width:4%;' class='text-right'>Rate</th>";
                                    echo "<th style='width:7%;' class='text-right'>Amount</th>";
                                    echo "</tr>";
                                    echo "</thead>";

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

                                    $gettran = mysqli_query($conn, "SELECT t.*,DATE_FORMAT(t.`checkin`, '%d-%m-%Y') as checkin ,DATE_FORMAT(t.`checkout`, '%d-%m-%Y') as checkout, h.hotelnm as hotelname
                                                                       FROM `$trandb` t LEFT JOIN hotels h ON t.hotel=h.code WHERE vouchno ='$pmain[vouchno]' 
                                                                       order by srno") or die(mysqli_error($conn));

                                    while ($fettran = mysqli_fetch_array($gettran)) {

                                        $ctr2++;
                                        echo "<tr>";
                                        echo "<td>$ctr2</td>";
                                        echo "<td>$fettran[checkin]</td>";
                                        echo "<td>$fettran[checkout]</td>";
                                        echo "<td>$fettran[hotelname]</td>";
                                        echo "<td>$fettran[nonights]</td>";
                                        echo "<td>$fettran[nopax]</td>";
                                        echo "<td class='text-right'>$fettran[rate]</td>";
                                        echo "<td class='text-right'>$fettran[amount]</td>";
                                        echo "</tr>";

                                        $totnight += $fettran['nonights'];
                                        $totpax   += $fettran['nopax'];
                                        $totamt   += $fettran['amount'];
                                    }

                                    echo "<tr style='background-color:#c7ecee;font-weight:bold;'>";
                                    echo "<td colspan='3' class='' colspan=''>Total</td>";
                                    echo "<td class='font-bolder'></td>";
                                    echo "<td class='font-bolder'>$totnight</td>";
                                    echo "<td class='font-bolder'>$totpax</td>";
                                    echo "<td class='font-bolder'></td>";
                                    echo "<td class='text-right font-bolder'>$totamt</td>";
                                    echo "</tr>";
                                    echo "</table>";
                                    echo "</td>";
                                    echo "</tr>";
                                }
                            }
                            ?>

                            <!-- CODE BY OBAID FOR ADDING TABS IN REGISTERS -->
                            <table class="with-nav-tabs ">
                                <div class="">
                                    <ul class="nav nav-tabs sksahil2">
                                        <li class="active"><a href="#tab1default" data-toggle="tab"><b style="font-size:14px;">Personal Details</b></a></li>
                                        <li><a href="#tab2default" data-toggle="tab"><b style="font-size:15px;">Consultation</b></a></li>
                                        <li><a href="#tab3default" data-toggle="tab"><b style="font-size:15px;">Treatment</b></a></li>
                                        <li><a href="#tab4default" data-toggle="tab"><b style="font-size:15px;">Medicine</b></a></li>
                                        <li><a href="#tab5default" data-toggle="tab"><b style="font-size:15px;">Billing</b></a></li>
                                        <li><a href="#tab6default" data-toggle="tab"><b style="font-size:15px;">Schedule</b></a></li>
                                        <?php
                                        if ($msched <= 0) {
                                            $vis = "display:none;";
                                        }
                                        ?>
                                        <li style="<?= $vis ?>" class="tab5"><a href="#tab5default" data-toggle="tab"><b style="font-size:15px;">Schedule</b></a></li>
                                    </ul>
                                </div>

                                <table class="table table-condensed table-hover table-bordered" id="tab1default" style="background: white;width: 100%">
                                    <thead class="row mySearchTr" style="color: #045DE9; background-color:#454752">
                                        <tr>
                                            <th style='width:10%;'>Name</th>
                                            <th style='width:10%;'>Address</th>
                                            <th style='width:5%;'>Gender</th>
                                            <th style='width:7%;'>DOB</th>
                                            <th style='width:5%;'>Age</th>
                                            <th style='width:5%;'>Mobile</th>
                                            <th style='width:10%;'>Email</th>
                                            <th style='width:5%;'>Regn.Date</th>
                                            <th style='width:10%;'>Complete Date</th>
                                        </tr>
                                    </thead>
                                    <?

                                    $getdetails = mysqli_query($conn, "SELECT m.*,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 a.accode!=''") or die(mysqli_error($conn));
                                    while ($details = mysqli_fetch_array($getdetails)) {

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

                                        $address = $fetpat['add1'] . $fetpat['add2'] . $fetpat['add3'];
                                        if ($fetpat['gender'] == 'M') {
                                            $gender = "Male";
                                        } else if ($fetpat['gender'] == 'F') {
                                            $gender = "Female";
                                        } else if ($fetpat['gender'] == 'O') {
                                            $gender = "Other";
                                        }


                                        echo "<tbody>";
                                        echo "<tr  id='boldfont' class='clickable-row2 click-tab' data-href='laundsl.php?vouchno=$pmain[vouchno]&mode=edit' data-target='_blank'>";
                                        echo "<td>$details[name]</td>";
                                        echo "<td>$details[address]</td>";
                                        echo "<td>$gender</td>";
                                        echo "<td>$fetpat[dob]</td>";
                                        echo "<td>$fetpat[age]</td>";
                                        echo "<td>$fetpat[mobile]</td>";
                                        echo "<td>$fetpat[email]</td>";
                                        echo "<td>$fetpat[regndt]</td>";
                                        echo "<td>$details[cmpltdt]</td>";
                                        echo "</tr>";
                                        echo "</tbody>";
                                    } ?>

                                </table>
                                <!-- ///////////////////  FOOD TAB   ///////////////// -->

                                <table class="tab-pane fade table table-condensed table-hover table-bordered" id="tab2default">
                                    <thead class="row" style="color: #045DE9; background-color:#454752">
                                        <tr>
                                            <th style='width:10%;'>Diagnosis</th>
                                            <th style='width:10%;'>Symptoms</th>
                                            <!-- <th style='width:10%;'>Advice & Notices</th> -->
                                        </tr>
                                    </thead>

                                    <?

                                    $getconsult = mysqli_query($conn, "SELECT m.*,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 a.accode!=''") or die(mysqli_error($conn));
                                    while ($consult = mysqli_fetch_array($getconsult)) {

                                        $getsymptoms = mysqli_query($conn, "SELECT * FROM $trandb WHERE vouchno=$consult[vouchno]") or die(mysqli_error($conn));
                                        $symptoms = mysqli_fetch_array($getsymptoms);

                                        echo "<tbody>";
                                        echo "<tr  id='boldfont' class='clickable-row2 click-tab' data-href='laundsl.php?vouchno=$pmain[vouchno]&mode=edit' data-target='_blank'>";
                                        echo "<td>$consult[diag1] $consult[diag2]</td>";
                                        echo "<td>$symptoms[symptoms]</td>";
                                        // echo "<td>$consult[notes1] $consult[notes2] $consult[notes3] $consult[notes4]</td>";
                                        echo "</tr>";
                                        echo "</tbody>";
                                    } ?>
                                </table>

                                <!-- ///////////////////  FOOD TAB   ///////////////// -->

                                <table class="tab-pane fade table table-condensed table-hover table-bordered" id="tab3default">
                                    <thead class="row" style="color: #045DE9; background-color:#454752">
                                        <tr>
                                            <th style='width:5%;'>Sr</th>
                                            <th style='width:11%;'>Treatment</th>
                                            <th style='width:5%;'>Nos.</th>
                                            <th style='width:5%;'>Days</th>
                                            <th style='width:10%;'>Remarks</th>
                                            <th style='width:10%;'>Approve</th>
                                            <th style='width:10%;'>First Date</th>
                                            <th style='width:5%;'>Rate</th>
                                            <th style='width:10%;'>Amount</th>
                                            <th style='width:10%;'>Approve Nos.</th>
                                            <th style='width:10%;'>Approve Rate</th>
                                            <th style='width:10%;'>Approve Amount</th>
                                        </tr>
                                    </thead>

                                    <?

                                    $gtsmtrant = mysqli_query($conn, "SELECT a.*,b.name from `consulttreat` a left join treatment b
                                                            on a.treatment = b.code where vouchno!='' order by a.srno");
                                    while ($treatment = mysqli_fetch_array($gtsmtrant)) {

                                        echo "<tbody>";
                                        echo "<tr  id='boldfont' class='clickable-row2 click-tab' data-href='laundsl.php?vouchno=$pmain[vouchno]&mode=edit' data-target='_blank'>";
                                        echo "<td>$treatment[srno]</td>";
                                        echo "<td>$treatment[name]</td>";
                                        echo "<td>$treatment[qty]</td>";
                                        echo "<td>$treatment[duration]</td>";
                                        echo "<td>$treatment[remarks]</td>";
                                        echo "<td>$treatment[aprov]</td>";
                                        echo "<td>$treatment[firstdate]</td>";
                                        echo "<td>$treatment[treatrate]</td>";
                                        echo "<td>$treatment[treatamt]</td>";
                                        echo "<td>$treatment[aprvqty]</td>";
                                        echo "<td>$treatment[rate]</td>";
                                        echo "<td>$treatment[amt]</td>";
                                        echo "</tr>";
                                        echo "</tbody>";
                                    } ?>
                                </table>

                                <!-- TAB 4 STARTS FROM HERE -->

                                <table class="tab-pane fade table table-condensed table-hover table-bordered" id="tab4default" style="background: white;width: 100%">
                                    <thead class="row mySearchTr" style="color: #045DE9; background-color:#454752">
                                        <tr>
                                            <th style='width:10%;'>Sr</th>
                                            <th style='width:10%;'>Medicine</th>
                                            <th style='width:5%;'>Dosage</th>
                                            <th style='width:7%;'>Days</th>
                                            <th style='width:5%;'>Qty</th>
                                            <th style='width:5%;'>Rate</th>
                                            <th style='width:10%;'>Amount</th>
                                        </tr>
                                    </thead>
                                    <?

                                    $gtmdtran = mysqli_query($conn, "SELECT a.*,b.name AS medicine from `consultmed` a 
                                                        left join product b on a.item = b.code order by a.srno");
                                    while ($medicine = mysqli_fetch_array($gtmdtran)) {

                                        echo "<tbody>";
                                        echo "<tr  id='boldfont'>";
                                        echo "<td>$medicine[srno]</td>";
                                        echo "<td>$medicine[medicine]</td>";
                                        echo "<td>$medicine[dosage]</td>";
                                        echo "<td>$medicine[duration]</td>";
                                        echo "<td>$medicine[qty]</td>";
                                        echo "<td>$medicine[rate]</td>";
                                        echo "<td>$medicine[amount]</td>";
                                        echo "</tr>";
                                        echo "</tbody>";
                                    } ?>

                                </table>

                                <!-- tab 5 starts from here -->

                                <table class="tab-pane fade table table-condensed table-hover table-bordered" id="tab5default">
                                    <thead class="row" style="color: #045DE9; background-color:#454752">
                                        <tr>
                                            <th class="text-right" style='width:5%;'>Consulting Fees</th>
                                            <th class="text-right" style='width:11%;'>Treatment Fees</th>
                                            <th class="text-right" style='width:5%;'>Medicine Fees</th>
                                            <th class="text-right" style='width:5%;'>Total Amount</th>
                                        </tr>
                                    </thead>

                                    <?

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

                                        echo "<tbody>";
                                        echo "<tr  id='boldfont' class='clickable-row2 click-tab' data-href='laundsl.php?vouchno=$pmain[vouchno]&mode=edit' data-target='_blank'>";
                                        echo "<td class='text-right'>$billing[consultfees]</td>";
                                        echo "<td class='text-right'>$billing[ttamount]</td>";
                                        echo "<td class='text-right'>$billing[tmedamount]</td>";
                                        echo "<td class='text-right'>$billing[billamt]</td>";
                                        echo "</tr>";

                                        $totbillamt += $billing['billamt'];
                                        echo "</tbody>";
                                    }

                                    echo "<tr> ";
                                    echo "<td align='right' style='color:$colr;' id='font'><h4><b></b></h4></td>";
                                    echo "<td align='right' style='color:$colr;' id='font'><h4><b></b></h4></td>";
                                    echo "<td align='right' style='color:$colr;' id='font'><h4><b>Total</b></h4></td>";
                                    echo "<td align='right' style='color:$colr;' id='font'><h4><b>$totbillamt</b></h4></td>";
                                    echo "</tr>";
                                    ?>
                                </table>

                                <!-- tab 6 starts from here -->

                                <table class="tab-pane fade table table-condensed table-hover table-bordered" id="tab6default">
                                    <thead class="row" style="color: #045DE9; background-color:#454752">
                                        <tr>
                                            <th style='width:5%;'>Sr</th>
                                            <th style='width:11%;'>Treatment</th>
                                            <th style='width:5%;'>Schedule Date</th>
                                            <th style='width:5%;'>Remarks</th>
                                            <th style='width:5%;'>Complete Date</th>
                                        </tr>
                                    </thead>

                                    <?

                                    $billamt = 0;
                                    $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!='' order by a.scheddate ASC");
                                    while ($schedule = mysqli_fetch_array($getschedule)) {

                                        echo "<tbody>";
                                        echo "<tr  id='boldfont' class='clickable-row2 click-tab' data-href='laundsl.php?vouchno=$pmain[vouchno]&mode=edit' data-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>";
                                    } ?>
                                </table>

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

                                    <div class="row hidtabpane">

                                        <div class="row" style="padding-left:2%">

                                            <table class="table table-bordered" style="width: 100%">
                                                <thead>
                                                    <tr class="mySearchTr">
                                                        <th style="width:3%"></th>
                                                        <th style="width:3%">Sr.</th>
                                                        <th style="width:40%">Treatment</th>
                                                        <th style="width:5%">Schedule Date</th>
                                                        <th style="width:30%">Remarks</th>
                                                        <th style="width:5%">Completed Date</th>
                                                        <th style="width:10%">Details</th>
                                                    </tr>

                                                </thead>

                                                <tbody class="schedbody">
                                                    <?php
                                                    if ($addflag != '1') {
                                                        $sdctr = 0;
                                                        $rctr = 0;
                                                        $gtsched = mysqli_query($conn, "Select a.*,
                                                    b.name from `schedtreat` a left join treatment b
                                                    on a.treatment = b.code where a.vouchno='$get[vouchno]' order by a.scheddate ASC");
                                                        if (mysqli_num_rows($gtsched) > 0) {

                                                            while ($rowsched = mysqli_fetch_array($gtsched)) {
                                                                $rctr++;
                                                                $rd = "";
                                                                $vis = "style='display:none'";

                                                                if ($rowsched['compltdt'] != "0000-00-00") {
                                                                    $rd = "readonly";
                                                                    $vis = "";
                                                                }
                                                                echo "<tr>";
                                                                echo "<td></td>";
                                                                echo "<td><input type='text' class='form-control form srno' value='$rctr' name='srno_$sdctr'></td>";
                                                                echo "<td>";
                                                                echo "<select id='streatment' name='streatment_$sdctr' class='form-control streatment form' style='width:100%'>";
                                                                echo "<option value='$rowsched[treatment]'>$rowsched[name]</option>";
                                                                echo "</select>";
                                                                echo "</td>";
                                                                echo "<td><input type='date' class='form-control form scheddate' value='$rowsched[scheddate]' name='scheddate_$sdctr' $rd></td>";
                                                                echo "<td><input type='text' class='form-control form remarks' value='$rowsched[remarks]' name='sremarks_$sdctr'></td>";
                                                                echo "<td><input type='date' class='form-control form compltdt' value='$rowsched[compltdt]' name='compltdt_$sdctr' $rd></td>";
                                                                echo "<td><button type='button' class='treatdet form-control btn' $vis>Details</button></td>";
                                                                echo "</tr>";
                                                                $sdctr++;
                                                            }
                                                        }
                                                    }
                                                    ?>
                                                    <input type="hidden" name="schedcnt" id="schedcnt" value="<?php echo ($addflag != 1) ? $sdctr : "1"; ?>">
                                                </tbody>

                                            </table>

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

                            <!-- <tr style='background-color: #0375bc;color: white;'>
                                <td style='font-size:14px;font-weight:bold' class='text-right'>Total</td>
                                <td style='font-size:14px;font-weight:bold' class='text-right'>$grandtot</td>
                                <td style='font-size:14px;font-weight:bold' class='text-right'>$grandtotinr</td>
                            </tr> -->

                        </tbody>
                    </table>
                </div>
            </div>
        </div>

        <!-- tabs by obaid -->

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

    </html>
<?php
}
if (isset($_POST["excel"])) {

    $contents .= "Voucher, Date, Customer, Print Name, ROE, Remarks, FE, INR \n";

    $ctr = 0;
    $tothotelpuramt = 0;

    while ($pmain = mysqli_fetch_array($getpmain)) {

        $ctr++;

        $remark = $pmain['remark1'] . "" . $pmain['remark2'];

        $contents .= "$pmain[vouchno]" . ",";
        $contents .= "$pmain[date]" . ",";
        $contents .= "$pmain[custname]" . ",";
        $contents .= "$pmain[prname]" . ",";
        $contents .= "$pmain[roe]" . ",";
        $contents .= "$remark" . ",";
        $contents .= "$pmain[laundamt]" . ",";
        $contents .= "$pmain[laundinramt]" . "\n";

        $grandtot += $pmain['laundinramt'];
        if ($_POST["dtype"] == 2) {

            $contents .= "Sr., Check In, Check Out, Hotel, No. Nights, No. Pax, Rate, Amount \n";

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

            $gettran = mysqli_query($conn, "SELECT t.*,DATE_FORMAT(t.`checkin`, '%d-%m-%Y') as checkin ,DATE_FORMAT(t.`checkout`, '%d-%m-%Y') as checkout, h.hotelnm as hotelname
                                       FROM `$trandb` t LEFT JOIN hotels h ON t.hotel=h.code WHERE vouchno ='$pmain[vouchno]' 
                                       order by srno") or die(mysqli_error($conn));

            while ($fettran = mysqli_fetch_array($gettran)) {

                $ctr2++;
                $contents .= "$ctr2" . ",";
                $contents .= "$fettran[checkin]" . ",";
                $contents .= "$fettran[checkout]" . ",";
                $contents .= "$fettran[hotelname]" . ",";
                $contents .= "$fettran[nonights]" . ",";
                $contents .= "$fettran[nopax]" . ",";
                $contents .= "$fettran[rate]" . ",";
                $contents .= "$fettran[amount]" . "\n";

                $totnight += $fettran['nonights'];
                $totpax   += $fettran['nopax'];
                $totamt   += $fettran['amount'];
            }

            $contents .= "" . ",,,";
            $contents .= "Total" . ",";
            $contents .= "$totnight" . ",";
            $contents .= "$totpax" . ",";
            $contents .= "" . ",";
            $contents .= "$totamt" . "\n";
        }
    }

    $contents .= "" . ",,,,,,";
    $contents .= "Total" . ",";
    $contents .= "$grandtot" . "\n";

    $contents = strip_tags($contents);

    if ($_POST["dtype"] == 1) {
        header("Content-Disposition: attachment; filename=$formname" . "_Summary" . date('d-m-Y') . ".csv");
        print $contents;
    } else {
        header("Content-Disposition: attachment; filename=$formname" . "_Detail" . date('d-m-Y') . ".csv");
        print $contents;
    }
}
?>