<?php
include("dbConfig.php");
session_start();

// Check if user is logged in
if (isset($_SESSION['username']) && isset($_SESSION['name'])) {
  $username = $_SESSION['username'];
  $name = $_SESSION['name'];
} else {
  echo '<META http-equiv="refresh" content="0;logout.php">';
  exit(); // Always add exit after redirect
}

// Check if BillNo is set
if (isset($_GET['BillNo'])) {
  $billno = $_GET['BillNo'];
  $patid = $_GET['patid'];

  // Fetch from the bill table
  $qu1 = mysqli_query($db, "SELECT * FROM bill WHERE BillNo='$billno'");
  $qu2 = mysqli_query($db, "SELECT * FROM inbill WHERE BillNo='$billno'");

  if (mysqli_num_rows($qu1) != 0) {
    $row = $qu1->fetch_assoc(); // Fetching first result
  } else {
    $row = $qu2->fetch_assoc();
  }

  if ($row) {
    $disamount = $row['DiscountAmount'] ?? 0;
    $Total = $row['TotAmount'] ?? 0;
    $payable = $row['PayableAmount'] ?? 0;
    $billtype = $row['PaymentMode'] ?? '';
    $InsuranceName = $row['InsuranceName'] ?? '';
    $InsuranceNo = $row['InsuranceNo'] ?? '';
    $bank = $row['bank'] ?? '';
    $cardno = $row['cardno'] ?? '';
    $upi = $row['upi'] ?? '';
    $cash = $row['cash'] ?? '';
    $bdate = $row['BDate'] ?? '';
    $btime = $row['BTime'] ?? '';
  }

  // Fetch patient details
  $qu4 = mysqli_query($db, "SELECT * FROM patientdetails WHERE PatId='$patid'");
  if (mysqli_num_rows($qu4) != 0) {
    $row = $qu4->fetch_assoc();
    $PatientType = "IPD";
  } else {
    $qu5 = mysqli_query($db, "SELECT * FROM opdpatientregister WHERE PatientId='$patid'");
    $row = $qu5->fetch_assoc();
    $PatientType = "OPD";
  }

  if ($row) {
    $title = $row['title'] ?? '';
    $Pname = $row['Name'] ?? '';
    $contact1 = $row['Contact'] ?? '';
    $email = $row['Email'] ?? '';
    $age = $row['Age'] ?? '';
    $gender = $row['Gender'] ?? '';
    $Address = $row['Address'] ?? '';
    $Consultant = $row['Consultant'] ?? '';
    $AdmitDate = $row['AdmitDate'] ?? '';
    $opdAdmitDate = $row['admitDate'] ?? '';
    $AdmitTime = $row['AdmitTime'] ?? '';
  }

  // Handling advance amount
  $advanceAmount = 0;
  $advance = mysqli_query($db, "SELECT * FROM advance WHERE PatId='$patid'");
  while ($row = $advance->fetch_assoc()) {
    $advanceAmount += $row['Amount'];
  }

  // Ensure values are numeric before passing them to any functions
  $Total = (float)($Total ?? 0.0);
  $payable = (float)($payable ?? 0.0);

?>

  <!DOCTYPE html>
  <html>

  <head>
    <title>
    </title>
    <meta charset="UTF-8">
    <link href="assets/img/favicon.png" rel="icon">
    <link href="assets/img/apple-touch-icon.png" rel="apple-touch-icon">
    <script src='https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js'></script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>
    <link href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.css'>
    <link href='https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css'>
    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,700,700i|Raleway:300,400,500,700,800|Montserrat:300,400,700" rel="stylesheet">
    <link href='https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css'>
    <link href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.css'>

    <!-- Vendor CSS Files -->
    <link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="assets/vendor/ionicons/css/ionicons.min.css" rel="stylesheet">
    <link href="assets/vendor/animate.css/animate.min.css" rel="stylesheet">
    <link href="assets/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <link href="assets/vendor/venobox/venobox.css" rel="stylesheet">
    <link href="assets/vendor/owl.carousel/assets/owl.carousel.min.css" rel="stylesheet">
    <link href="assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
    <script src="https://code.jquery.com/jquery.min.js"></script>
    <script src="jquery.dependent.fields.js"></script>
    <!-- Template Main CSS File -->
    <link href="assets/css/style.css" rel="stylesheet">
    <script src="https://code.jquery.com/jquery.min.js"></script>
    <script src="jquery.dependent.fields.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0-alpha1/js/bootstrap.min.js" integrity="sha512-eHx4nbBTkIr2i0m9SANm/cczPESd0DUEcfl84JpIuutE6oDxPhXvskMR08Wmvmfx5wUpVjlWdi82G5YLvqqJdA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    <style>
      @media print {
        #printPageButton {
          display: none;
        }
      }

      @media print {
        .opd-patient-bill .grey {
          background-color: #9d9898 !important;
          -webkit-print-color-adjust: exact;
          /* For Chrome */
          print-color-adjust: exact;
          /* For Firefox */
        }
      }

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


      .table td,
      .table th {
        padding: 5px;
        vertical-align: top;
        font-size: 19pt;
        border-top: 1px solid black;
        border: 1px solid black;
      }

      .table thead tr {
        border-bottom: 3px solid black;

      }

      .top-tbl {
        font-size: 19pt;
      }

      .normal-bill {
        display: block;
      }

      .opd-patient-bill {
        display: none;
      }

      body.opd-preview .normal-bill {
        display: none;
      }

      body.opd-preview .opd-patient-bill {
        display: block;
        padding: 0;
        margin: 0;
      }

      h6 {
        color: black !important;
      }

      .grey {
        background-color: #9d9898 !important;
      }

      .common-text-right {
        text-align: right !important;
        color: black !important;
        padding-right: 20px !important;
      }

      .no-border {
        border: none !important;
        /* Removes border from the table */
      }

      .no-border th,
      .no-border td {
        border: none !important;
        /* Removes borders from header and data cells */
      }

      hr {
        border: none;
        height: 1px;
        background-color: black;
        margin: 10px;
      }
    </style>
  </head>

  <body>

    <section>

      <div class="row" id="printPageButton" style="margin:5%">
        <button type="button" class="btn btn-primary" onclick="triggerPrint()">Print</button> &nbsp;&nbsp;&nbsp;
        <a href="index.php"><button type="button" class="btn btn-primary">Home</button></a>
      </div>
      <script>
        document.addEventListener('DOMContentLoaded', function() {
          var PatientType = "<?php echo $PatientType; ?>";

          // Select elements without the dot and handle them correctly
          var opdBillElements = document.getElementsByClassName('opd-patient-bill');
          var normalBillElements = document.getElementsByClassName('normal-bill');

          // Check if PatientType is OPD and display the OPD patient bill
          if (PatientType === "OPD") {
            // Hide normal bill
            for (var i = 0; i < normalBillElements.length; i++) {
              normalBillElements[i].style.display = 'none';
            }

            // Show OPD bill
            for (var i = 0; i < opdBillElements.length; i++) {
              opdBillElements[i].style.display = 'block'; // Show the OPD bill
            }
          } else {
            // Hide OPD bill if PatientType is not OPD
            for (var i = 0; i < opdBillElements.length; i++) {
              opdBillElements[i].style.display = 'none';
            }
          }
        });

        function triggerPrint() {
          var PatientType = "<?php echo $PatientType; ?>";
          if (PatientType === "OPD") {
            document.body.classList.add('opd-preview');
          }
          window.print();
          setTimeout(function() {
            document.body.classList.remove('opd-preview');
          }, 100);
        }

        // Listen for the 'keydown' event for Ctrl+P
        document.addEventListener('keydown', function(event) {
          if (event.ctrlKey && event.key === 'p') {
            event.preventDefault(); // Prevent the default print dialog
            triggerPrint(); // Call the custom print function
          }
        });
      </script>

      <div class="normal-bill">
        <div style="margin:5%">
          <div class="row">
            <div class="col-md-6 col-sm-6">
              <img src="assets/img/logo.png">
              <span class="spanfont"><b>Vidhyaranya Hospital PVT LTD.</b></span>
            </div>
            <div class="col-md-6 col-sm-6">

              <table>
                <tr>
                  <td valign="top">Address</td>
                  <td>:2876, 4th Cross, NS Road, Chamundipuram, Mysuru, Karnataka 570004</td>
                </tr>
                <tr>
                  <td valign="top">Website</td>
                  <td>:www.vidhyaranya</td>
                </tr>
                <tr>
                  <td valign="top">Contact</td>
                  <td>:+91-821 233 1655</td>
                </tr>
                <tr>
                  <td>Unit</td>
                  <td>:Mysore</td>
                </tr>
              </table>
            </div>
          </div>
          <div class="row text-center mt-3">
            <div class="col-md-12">
              <?php if ($PatientType == "OPD") {
                echo '<label style="font-size:15pt"><b>OUT PATIENT BILL</b></label>';
              } elseif ($PatientType == "IPD") {
                echo '<label style="font-size:15pt"><b>IN PATIENT BILL</b></label>';
              } else {
                echo '<label style="font-size:15pt"><b>PATIENT BILL</b></label>';
              }
              ?>
            </div>
          </div>
          <hr>
          <div class="row d-flex justify-content-between">
            <div class="col-md-6 col-sm-6 row1 text-left">
              <table class="top-tbl">
                <tr>
                  <td valign="top"><b>Patient Id</b></td>
                  <td valign="top">: <?php echo $patid; ?></td>
                </tr>
                <tr>
                  <td valign="top"><b>Patient Name</b></td>
                  <td valign="top">: <?php echo $title . ' ' . $Pname; ?></td>
                </tr>
                <tr>
                  <td valign="top"><b>Print Date</b></td>
                  <td valign="top">: <?php echo $bdate; ?></td>
                </tr>
                <tr>
                  <td valign="top"><b>Age/ Gender</b></td>
                  <td valign="top">: <?php echo $age; ?> <?php echo $gender; ?></td>
                </tr>
                <?
                if ($PatientType == "OPD") { ?>
                  <tr>
                    <td valign="top"><b>Ref. Dr. Name</b></td>
                    <td valign="top">: <?php echo $Consultant; ?></td>
                  </tr><?php } ?>
              </table>
            </div>
            <div class="col-md-6 col-sm-6 row2">
              <table class="top-tbl">
                <?php if ($PatientType == "IPD") { ?>
                  <tr>
                    <td valign="top"><b>Gender/Age/Blood Group</b></td>
                    <td valign="top">: <?php echo $gender . "/ " . $age . " / " . $blood; ?></td>
                  </tr>

                  <tr>
                    <td valign="top"><b>Consultant</b></td>
                    <td valign="top">: <?php echo $Consultant; ?></td>
                  </tr>

                  <tr>
                    <td valign="top"><b>Patient Type</b></td>
                    <td valign="top">: <?php echo $PatientType; ?></td>
                  </tr>

                  <tr>
                    <td valign="top"><b>Admit Date/Time</b></td>
                    <td valign="top">: <?php echo $AdmitDate . ", " . $AdmitTime; ?></td>
                  </tr>

                  <tr>
                    <td valign="top"><b>Bill Type/Bill Date-Time</b></td>
                    <td valign="top">: <?php echo $billtype . " / " . $bdate . ", " . $btime; ?></td>
                  </tr>

                  <?php if ($billtype == "Insurance") { ?>
                    <tr>
                      <td>Insurance Name / Number</td>
                      <td>: <?php echo $InsuranceName . ", " . $InsuranceNo; ?></td>
                    </tr>
                  <?php } elseif ($billtype == "Card") { ?>
                    <tr>
                      <td>Bank Name / Card Number</td>
                      <td>: <?php echo $bank . ", " . $cardno; ?></td>
                    </tr>
                  <?php } elseif ($billtype == "Cash and UPI") { ?>
                    <tr>

                      <td>Cash Amount / UPI Amount</td>
                      <td>: <?php echo $cash . ", " . $upi; ?></td>
                    </tr>
                  <?php } else { ?>
                    <!--<tr>-->
                    <!--  <td valign="top"><b>Bill Type/Bill Date-Time</b></td>-->
                    <!--  <td valign="top">: <?php echo $billtype . " / " . $bdate . ", " . $btime; ?></td>-->
                    <!--</tr>-->

                  <?php } ?>
                <?php } ?>
              </table>
            </div>
          </div>


          <table style="padding:0px" class="table table-hover">
            <thead>
              <th scope="col">Sl No.</th>
              <th scope="col">Particulars</th>
              <th scope="col">Radiology / Lab</th>
              <th scope="col">Consultant</th>
              <th scope="col">Quantity</th>
              <th scope="col">Unit Price</th>
              <th scope="col">Amount</th>
            </thead>
            <tbody>
              <?php

              $i = 1;
              $qu2 = mysqli_query($db, "SELECT * FROM billparticulars where BillNo='$billno'");
              while ($row = $qu2->fetch_assoc()) {

                echo "<tr><td>$i</td>";
                echo "<td>" . $row['Particulars'] . "</td>";
                echo "<td>" . (!empty($row['optionlab']) ? $row['optionlab'] : "N/A") . "</td>";


                echo "<td>" . $row['consultant'] . "</td>";
                echo "<td>" . $row['Quantity'] . "</td>";
                echo "<td>" . $row['UnitPrice'] . "</td>";
                echo "<td>" . $row['Amount'] . "</td>";
                echo "</tr>";
                $i++;
              }

              ?>

              <tr>
                <td colspan="5"></td>
                <td style="font-weight:bold">Sub Total</td>
                <td style="font-weight:bold"><b><?php echo $Total; ?></b></td>
              </tr>



            </tbody>
          </table>
          <div class="row">
            <div class="col-md-4"></div>
            <div class="col-md-6">

              <table style="padding:0px" class="table table-bordered">
                <tr>
                  <td><b>Total Bill Amount &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :</b></td>
                  <td><b><?php echo $Total; ?></b></td>
                </tr>
                <!-- <tr>-->
                <!--	<td><b>Advance &nbsp;&nbsp;&nbsp;&nbsp;:</b></td>-->
                <!--	<td><b>-->
                <?php //echo $advanceAmount;
                ?>
                <!--	    </b></td>-->
                <!--</tr>-->


                <!--<tr>-->
                <!--  <td><b>Patient Payable Amount &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</b></td>-->
                <!--  <td><b>?php echo  getIndianCurrency($payable); ?></b></td>-->
                <!--</tr>-->
              </table>


            </div>
            <div class="col-md-2"></div>
          </div>
        </div>



      </div>

      </div>
      <br>
      <?php

      function getIndianCurrency(float $number)
      {
        // Your conversion logic here (example below)
        $decimal = round($number - ($no = floor($number)), 2) * 100;
        $hundred = null;
        $digits_length = strlen($no);
        $i = 0;
        $str = [];
        $words = array(
          0 => '',
          1 => 'one',
          2 => 'two',
          3 => 'three',
          4 => 'four',
          5 => 'five',
          6 => 'six',
          7 => 'seven',
          8 => 'eight',
          9 => 'nine',
          10 => 'ten',
          11 => 'eleven',
          12 => 'twelve',
          13 => 'thirteen',
          14 => 'fourteen',
          15 => 'fifteen',
          16 => 'sixteen',
          17 => 'seventeen',
          18 => 'eighteen',
          19 => 'nineteen',
          20 => 'twenty',
          30 => 'thirty',
          40 => 'forty',
          50 => 'fifty',
          60 => 'sixty',
          70 => 'seventy',
          80 => 'eighty',
          90 => 'ninety'
        );
        $digits = array('', 'hundred', 'thousand', 'lakh', 'crore');
        while ($i < $digits_length) {
          $divider = ($i == 2) ? 10 : 100;
          $number = floor($no % $divider);
          $no = floor($no / $divider);
          $i += ($divider == 10) ? 1 : 2;
          if ($number) {
            $plural = (($counter = count($str)) && $number > 9) ? 's' : null;
            $hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
            $str[] = ($number < 21) ? $words[$number] . " " . $digits[$counter] . $plural . " " . $hundred
              : $words[floor($number / 10) * 10] . " " . $words[$number % 10] . " " . $digits[$counter] . $plural . " " . $hundred;
          } else $str[] = null;
        }
        $rupees = implode('', array_reverse($str));
        $paise = ($decimal) ? " and " . ($words[$decimal - $decimal % 10] . " " . $words[$decimal % 10]) . " paise" : '';
        return ($rupees ? $rupees . "rupees " : '') . $paise;
      }

      ?>
      <div class="normal-bill ml-5">
        <h6 style="font-weight:bold"><?php echo getIndianCurrency($payable) . " only/-"; ?></h6>
      </div>

      <div class="row normal-bill text-right">
        
        <div class="col-md-8"></div>
        <div class="col-md-3">
             <p>Prepared by <b><?php echo $name ?></b></p>
          <h6>Authorized Signatory</h6>
        </div>
         <div class="col-md-1"></div>
      </div>
    </section>

    <div class="opd-patient-bill" style="color: black;">
      <div style="margin:5%">
        <div style="border: 1px solid black;">
          <div class="row">
            <div class="col-md-6 col-sm-6">
              <img src="assets/img/logo.png" alt="Hospital Logo" style="width: 100px;height:100px;float:left;padding:10px;">
              <h1><b>VIDYARANYA <br> HOSPITAL <br> PVT LTD.,</b></h1>
            </div>
            <div class="col-md-6 col-sm-6">
              <table style="padding-top: 10px;">
                <tr>
                  <th>
                    <h3><b style="align-items: center;">Vidyanarayana Hospital</b></h3>
                  </th>
                </tr>
                <tr>
                  <th>2876, 4th Cross, NS Road, Chamundipuram, Mysuru, Karnataka 570004</th>
                </tr>
              </table>
            </div>
          </div>
          <div class="col-md-12 text-center print-background" style="border: 1px solid black;background-color:#9d9898;">
            <label style="font-size:15pt"><b>OUT PATIENT BILL</b></label>
          </div>
          <div class="row d-flex justify-content-between">
            <div class="col-md-6 col-sm-6 row1 text-left">
              <table class="top-tbl ml-3">
                <tr>
                  <td valign="top"><b>Patient Name</b></td>
                  <td valign="top">: <?php echo $title . ' ' . $Pname; ?></td>
                </tr>
                <tr>
                  <td valign="top"><b>Age/ Sex</b></td>
                  <td valign="top">: <?php echo $age; ?> <?php echo $gender; ?></td>
                </tr>
                <tr>
                  <td valign="top"><b>Ref. Dr. Name</b></td>
                  <td valign="top">: <?php echo $Consultant; ?></td>
                </tr>
                <tr>
                  <td valign="top"><b>Visit Date</b></td>
                  <td valign="top">: <?php echo $opdAdmitDate; ?></td>
                </tr>
                <tr>
                  <td valign="top"><b>Patient Class</b></td>
                  <td valign="top">: <?php echo $Class = "GENERAL"; ?></td>
                </tr>
                <tr>
                  <td valign="top"><b>Mobile No</b></td>
                  <td valign="top">: <?php echo "+" . $contact1; ?></td>
                </tr>

              </table>
            </div>
            <div class="col-md-6 col-sm-6 row2">
              <table class="top-tbl">
                <tr>
                  <td valign="top"><b>Hospital Id (UHID)</b></td>
                  <td valign="top">: </td>
                </tr>
                <tr>
                  <td valign="top"><b>Bill No</b></td>
                  <td valign="top">: <?php echo $billno; ?></td>
                </tr>
                <tr>
                  <td valign="top"><b>Bill Date</b></td>
                  <td valign="top">: <?php echo $bdate; ?></td>
                </tr>
                <tr>
                  <td valign="top"><b>Regn Type</b></td>
                  <td valign="top">: <?php echo $PatientType; ?></td>
                </tr>
                <tr>
                  <td valign="top"><b>Debit To</b></td>
                  <td valign="top">: SELF</td>
                </tr>
                <tr>
                  <td valign="top"><b>Consultant Doctor</b></td>
                  <td valign="top">: <?php echo $Consultant ?></td>
                </tr>
              </table>
            </div>
            <hr>
          </div>
          <hr>
          <div style="display: flex; justify-content: center; padding: 10px;" class="opd-patient-bill">
            <table style="width: 100%;" class="table table-hover border">
  <thead class="grey">
    <tr>
      <th scope="col">Sl No.</th>
      <th scope="col">Particulars</th>
      <th scope="col">Radiology / Lab</th>
      <th scope="col">Consultant</th>
      <th scope="col">Quantity</th>
      <th scope="col">Unit Price</th>
      <th scope="col">Amount</th>
    </tr>
  </thead>

  <tbody>
    <?php
    $i = 1;
    $qu2 = mysqli_query($db, "SELECT * FROM billparticulars WHERE BillNo='$billno'");
    while ($row = $qu2->fetch_assoc()) {
      echo "<tr>";
      echo "<td>$i</td>";
      echo "<td>" . htmlspecialchars($row['Particulars']) . "</td>";
      echo "<td>" . (!empty($row['optionlab']) ? htmlspecialchars($row['optionlab']) : "N/A") . "</td>";
      echo "<td>" . htmlspecialchars($row['consultant']) . "</td>";
      echo "<td>" . htmlspecialchars($row['Quantity']) . "</td>";
      echo "<td>" . htmlspecialchars($row['UnitPrice']) . "</td>";
      echo "<td>" . htmlspecialchars($row['Amount']) . "</td>";
      echo "</tr>";
      $i++;
    }
    ?>

    <!-- Sub Total Row -->
    <tr>
      <td colspan="5"></td>
      <td style="font-weight:bold">Sub Total</td>
      <td style="font-weight:bold"><b><?php echo htmlspecialchars($Total); ?></b></td>
    </tr>
  </tbody>
</table>

<style>
  /* Custom style to ensure the table is well-formatted */
  table {
    width: 100%;
    border-collapse: collapse; /* Removes space between cells */
  }
  th, td {
    padding: 8px; /* Provides consistent spacing */
    text-align: left; /* Aligns text to the left */
    border: 1px solid #ddd; /* Adds border to table cells */
  }
  tr:nth-child(even) {
    background-color: #f2f2f2; /* Adds alternating row colors for better readability */
  }
  th {
    background-color: #f8f9fa; /* Light background for the header */
    font-weight: bold;
  }
</style>

          </div>

          <hr>
          <div class="common-text-right">
            <h6>Total Bill Amount: <b><?php echo number_format($Total, 2); ?></b></h6>
            <h6>Net Bill Amount Rounded: <b><?php echo number_format(floor($Total), 2); ?></b></h6>
            <h6>Received Amount: <b><?php echo number_format($Total, 2); ?></b></h6>
            <h6>Balance Amount: <b>0.00</b></h6>
            <h6>Refund Amount: <b>0.00</b></h6>
            <h6>Net Received Amount After Refund:<b><?php echo number_format($Total, 2); ?></b> </h6>
          </div>
          <hr>
          <div>
            <h6 style="font-weight:bold; color:black;margin-top:0;" class="pl-3">Received With Thanks <?php echo strtoupper(getIndianCurrency($payable)) . " ONLY/-"; ?></h6>
          </div>

          <div style="display: flex;flex-wrap:wrap; justify-content: center; padding: 10px;padding-top:0;">
            <h6 style="margin:0;background-color:#9d9898;padding-top:5px;width:100%;">Receipt Details :</h6>

            <table style="width: 100%;border-top:1px solid black; border-bottom:1px solid black;">
              <tr style="background-color:#9d9898;padding-bottom:5px;">
                <th>Receipt No</th>
                <th>Receipt Date</th>
                <th>Payment Details</th>
                <th>Receipt Type</th>
                <th>Amount</th>
              </tr>
              <tr>
                <td><?php echo $billno ?></td>
                <td><?php echo $bdate; ?></td>
                <td><?php echo $billtype; ?></td>
                <td>Final Bill Settlement</td>
                <td><?php echo $Total; ?></td>
              </tr>
            </table>
          </div>
          <h6 style="text-align: end;padding-right: 8%;">Total Receipt Amount : <?php echo $Total; ?></h6>
          <hr>
          <div class="col-md-12" style="display: flex; justify-content: space-between; align-items: center;">
            <h6 style="margin: 0;">*All amounts are in INR</h6> <!-- Aligns to the left -->
            <h6 style="margin: 0;">Authorized By  <?php echo $name ?></h6> <!-- Aligns to the right -->
              <h6 style="margin: 0;">Authorized Signatory</h6> 
          </div>
          <hr>
          <h6 class="pl-3">All cheques/Payorders/Demand Drafts should be payable in the name of Vidyaranya Hospital</h6>
        </div>
      </div>
    </div>

    <script src='https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js'></script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>
    <script src="assets/vendor/jquery/jquery.min.js"></script>
    <script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
    <script src="assets/vendor/jquery.easing/jquery.easing.min.js"></script>
    <script src="assets/vendor/php-email-form/validate.js"></script>
    <script src="assets/vendor/wow/wow.min.js"></script>
    <script src="assets/vendor/venobox/venobox.min.js"></script>
    <script src="assets/vendor/owl.carousel/owl.carousel.min.js"></script>
    <script src="assets/vendor/jquery-sticky/jquery.sticky.js"></script>
    <script src="assets/vendor/superfish/superfish.min.js"></script>
    <script src="assets/vendor/hoverIntent/hoverIntent.js"></script>
    <script src="assets/vendor/isotope-layout/isotope.pkgd.min.js"></script>
    <script src="assets/js/main.js"></script>
  </body>

  </html>
<?
}
?>