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

if (!isset($_SESSION['username']) || !isset($_SESSION['name'])) {
    echo '<META http-equiv="refresh" content="0;logout.php">';
    exit;
}

$username = $_SESSION['username'];
$name = $_SESSION['name'];
?>

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

if (isset($_GET['Billno'])) {
    $billno = $_GET['Billno'];
    $type = $_GET['type'];

    // Fetch advance details
    $qu1 = mysqli_query($db, "SELECT * FROM advance WHERE BillNo='$billno' And `is_deleted` = 1 ");
    if ($row = mysqli_fetch_assoc($qu1)) {
        $patid = $row['PatId'];
        $amount = $row['Amount'];
        $advDate = $row['AdvanceDate'];
        $paymode = $row['PaymentMode'];
        $iname = $row['InsuranceName'];
        $ino = $row['InsuranceNo'];
        $PatientType = $row['PatientType'];
    }

    if ($type == "Advance") {
        // Fetch patient details
        $qu5 = mysqli_query($db, "SELECT * FROM patientdetails WHERE PatId='$patid'");
        if ($row = mysqli_fetch_assoc($qu5)) {
             $title = $row['title'];
            $Pname = $row['Name'];
            $contact1 = $row['Contact'];
            $email = $row['Email'];
            $dob = $row['Dob'];
            $age = $row['Age'];
            $gender = $row['Gender'];
            $blood = $row['BloodGroup'];
            $Address = $row['Address'];
            $Consultant = $row['Consultant'];
            $AdmitDate = $row['AdmitDate'];
            $AdmitTime = $row['AdmitTime'];
            $PatientType = $row['PatientType'];
        }
    }

?>
<!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>
<style>
    @media print {
  #printPageButton {
    display: none;
  }
}
table {
    border-collapse: collapse;
    font-weight: bold;
    font-size:1.3em;
}
.table td {
    padding: 2px;
    font-weight: bold;
}

</style>
</head>
<body>

<section>
  
<div class="row" id="printPageButton" style="margin:5%">
  <button  type="button" class="btn btn-primary" onclick="window.print()" >Print</button> &nbsp;&nbsp;&nbsp;
<button type="button" class="btn btn-primary" onclick="history.back()">Back</button>
</div>      

  <div style="margin:5%">
    <div class="row">
      <div class="col-md-3">
        <img src="assets/img/logo.png">
      </div>
      <div class="col-md-3"></div>
      <div class="col-md-6">
      <table>
      <tr>
        <td valign="top">Address</td>
          <td>:2876, 4th Cross, NS Road, Chamundipuram, Mysuru, Karnataka 570004</td>
      </tr>
     
      <tr>
        <td valign="top">Contact</td>
        <td>:+91-821 233 1655, +91-821 233 0555, +91 9035933963</td>
      </tr>
      <tr>
        <td>Unit</td>
        <td>:Mysore</td>
      </tr>

    </table>
      </div>
    </div>
<hr>
<div class="row">
    <div class="col-md-6">
        <table>
            <tr>
                <td valign="top">Bill No</td>
                <td valign="top">: <?php echo $billno; ?></td>
            </tr>
            <tr>
                <td valign="top">Patient Id</td>
                <td valign="top">: <?php echo $patid; ?></td>
            </tr>
            <tr>
                <td valign="top">Name</td>
                <td valign="top">:<?php echo $title . ' ' . $Pname; ?></td>
            </tr>
            <tr>
                <td valign="top">Contact No.</td>
                <td valign="top">: <?php echo isset($contact1) ? $contact1 : 'N/A'; ?></td>
            </tr>
            <?php if (!empty($email)) { ?>
                <tr>
                    <td valign="top">Email Id</td>
                    <td valign="top">: <?php echo $email; ?></td>
                </tr>
            <?php } ?>
            <tr>
                <td valign="top">Address</td>
                <td valign="top">: <?php echo isset($Address) ? $Address : 'N/A'; ?></td>
            </tr>
        </table>
    </div>
    <div class="col-md-6">
        <table>
            <tr>
                <td valign="top">Gender/Age/Blood Group</td>
                <td valign="top">: <?php echo isset($gender) ? $gender : 'N/A'; ?>/ <?php echo isset($age) ? $age : 'N/A'; ?> Years/ <?php echo isset($blood) ? $blood : 'N/A'; ?></td>
            </tr>
            <tr>
                <td valign="top">Consultant</td>
                <td valign="top">: <?php echo isset($Consultant) ? $Consultant : 'N/A'; ?></td>
            </tr>
            <tr>
                <td valign="top">Patient Type</td>
                <td valign="top">: <?php echo isset($PatientType) ? $PatientType : 'N/A'; ?></td>
            </tr>
            <?php if (!empty($AdmitDate)) { ?>
                <tr>
                    <td valign="top">Admit Date/Time</td>
                    <td valign="top">: <?php echo $AdmitDate . ", " . $AdmitTime; ?></td>
                </tr>
            <?php } ?>
            <tr>
                <td valign="top">Bill Type / Bill Date</td>
                <td valign="top">: <?php echo $paymode . " / " . $advDate; ?></td>
            </tr>
            <?php if (isset($iname) && isset($ino)) { ?>
                <tr>
                    <td valign="top">Insurance Name / Number</td>
                    <td valign="top">: <?php echo $iname . ", " . $ino; ?></td>
                </tr>
            <?php } ?>
        </table>
    </div>
</div>

<br>

<table class="table table-hover">
  <thead>
    <th scope="col">Sl No.</th>
    <th scope="col">Particulars</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' And `is_deleted` = 1 ");

while ($row = $qu2->fetch_assoc()) {
    echo "<tr>";
    echo "<td>$i</td>";
    echo "<td>" . $row['Particulars'] . "</td>";
    echo "<td>" . (!empty($row['consultant']) ? $row['consultant'] : 'N/A') . "</td>";
    
    echo "<td>" . $row['Quantity'] . "</td>";
    echo "<td>" . $row['UnitPrice'] . "</td>";
    echo "<td>" . $row['Amount'] . "</td>";
    echo "</tr>";
    $i++;
}
?>


    <tr>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td>Sub Total</td>
      <td><? echo $Total;?></td>
    </tr>
  


  </tbody>
</table>

<div class="row">
  <div class="col-md-6"></div>
  <div class="col-md-6">
    <table class="table table-bordered">
  <tr>
    <td>Advance Amount</td>
    <td><? echo $amount;?></td>
  </tr>
  
</table>


  </div>
</div>
<br><br><br><br>
<div class="row">
  <div class="col-md-1"></div>
  <div class="col-md-7">
    
   
    
  </div>
  <div class="col-md-4">

     <h6>Authorized Signatory</h6>
     <br><h6>Prepared by <?echo $name?></h6>
  </div>
</div>
<br><br><br><br>

    </div>
  



</section>
 <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>


<?
}

?>


