<?php

include("dbConfig.php");
session_start();
if(isset($_SESSION['username']) && isset($_SESSION['name']))
{
    $username=$_SESSION['username'];
    $name=$_SESSION['name'];
}
else
{
     echo '<META http-equiv="refresh" content="0;logout.php">';
}


if(isset($_GET['BillNo'])){
  $billno=$_GET['BillNo'];
$patid=$_GET['patid'];
$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){
while($row=$qu1->fetch_assoc()){
  $disamount=$row['DiscountAmount'];
  $Total=$row['TotAmount'];
  $payable=$row['PayableAmount'];
  $billtype=$row['PaymentMode'];
  $InsuranceName=$row['InsuranceName'];
$InsuranceNo=$row['InsuranceNo'];
  $bdate=$row['BDate'];
  $btime=$row['BTime'];

}
}
else{
  while($row=$qu2->fetch_assoc()){
  $disamount=$row['DiscountAmount'];
  $Total=$row['TotAmount'];
  $payable=$row['PayableAmount'];
  $billtype=$row['PaymentMode'];
  $InsuranceName=$row['InsuranceName'];
$InsuranceNo=$row['InsuranceNo'];
  $bdate=$row['BDate'];
  $btime=$row['BTime'];

}
}

$qu4=mysqli_query($db,"SELECT * FROM PatientDetails WHERE PatId='$patid'");
if(mysqli_num_rows($qu4)!=0){
   while($row=$qu4->fetch_assoc()){
$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'];
$PatientType="IPD";
$AdmitDate=$row['AdmitDate'];
$AdmitTime=$row['AdmitTime'];
} 
}
else{
    $qu5=mysqli_query($db,"SELECT * FROM OPDPatientRegister WHERE PatientId='$patid'");
while($row=$qu5->fetch_assoc()){
$Pname=$row['Name'];
$contact1=$row['Contact'];
$email=$row['Email'];
$age=$row['Age'];
$gender=$row['Gender'];
$Address=$row['Address'];
$Consultant=$row['Consultant'];
$PatientType="OPD";
}
}

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


?>
<!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;
  }
}

 @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;
}

</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;
<a href="index.php"><button type="button" class="btn btn-primary">Home</button></a>
</div>      

  <div style="margin:5%">
    <div class="row">
      <div class="col-md-3">
        <img src="assets/img/logo.png" style="width:196px">
      </div>
      <div class="col-md-6">
	  
	  <p style="text-align:center;margin:0px">
	  <label style="font-size: 19pt;"> <b>NEW PRIYADARSHINI HOSPITAL</b> </label><br/>
	  <label> #13, 4th Cross Road, 7th Main Road,<br/>KRS Rd, Brindavan Extension, Mysuru, Karnataka 570020</label><br/>
	  <label><b>Ph no:</b> 0821- 2330113 & +91-76194 27745</label><br/><br/>
	  <? 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>';
		}
  ?>
	  <!--<label style="font-size:15pt"><b>OUT PATIENT BILL</b></label>-->
	  </p>
	  
	  <!--
	  <table>
      <tr>
        <td valign="top">Address</td>
          <td>:4th Cross Road, 7th Main Road, #13, KRS Rd, Brindavan Extension, Mysuru, Karnataka 570020</td>
      </tr>
      <tr>
        <td valign="top">Website</td>
        <td>:www.newpriyadarshinihospital.com</td>
      </tr>
      <tr>
        <td valign="top">Contact</td>
        <td>:+91-76194 27745, 0821- 2330113</td>
      </tr>
      <tr>
        <td>Unit</td>
        <td>:Mysore</td>
      </tr>

    </table>-->
	  </div>
      <div class="col-md-3">
      
      </div>
    </div>
<hr>
<div class="row">
  <div class="col-md-6">
    <table class="top-tbl">
    <tr>
        <td valign="top"><b>Patient Id</b></td>
      <td valign="top">: <? echo $patid;?></td>
    </tr>
  <tr>
    <td valign="top"><b>Patient Name</b></td>
    <td valign="top">: <? echo $Pname;?></td>
  </tr>
    
  <?
	if($PatientType=="OPD"){?>
	 <tr>
    <td valign="top"><b>Ref. Dr. Name</b></td>
    <td valign="top">: <? echo $Consultant;?></td>
	</tr><? } ?>
</table>
  </div>
  <div class="col-md-6">
    <table class="top-tbl"> 
      <?
	if($PatientType=="IPD"){?>
  <tr>
    <td valign="top"><b>Gender/Age/Blood Group</b></td>
    <td valign="top">: <? echo $gender."/ ".$age." Years/ ".$blood;?></td>
  </tr>

  <tr>
    <td valign="top"><b>Consultant</b></td>
    <td valign="top">: <? echo $Consultant;?></td>
  </tr>
  <tr>
    <td valign="top"><b>Patient Type</b></td>
    <td valign="top">: <? echo $PatientType;?></td>
  </tr>
  <tr>
    <td valign="top"><b>Admit Date/Time</b></td>
    <td valign="top">: <? echo $AdmitDate.", ".$AdmitTime;?></td>
  </tr>
  <tr>
    <td valign="top"><b>Bill Type/Bill Date-Time</b></td>
    <td valign="top">: <? echo $billtype."/ ".$bdate.", ".$btime;?></td>
  </tr> 
  <?if($billtype=="Insurance"){
	echo "<tr><td>Insurance Name / Number</td>";
	echo "<td>:$InsuranceName, $InsuranceNo</td></tr>";
	}?>
<?}
else{?>
    <tr>
    <td valign="top"><b>Bill Type/Bill Date-Time</b></td>
    <td valign="top">: <? echo $billtype." / ".$bdate.", ".$btime;?></td>
  </tr> 
	<tr>
    <td valign="top"><b>Print Date</b></td>
    <td valign="top">: <? echo $bdate;?></td>
  </tr>
  <tr>
    <td valign="top"><b>Age/ Gender</b></td>
    <td valign="top">: <? echo $age?>Y <? echo $gender ?></td>
  </tr>
  
<?}
?>



     
</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">Consultant</th>
	<th scope="col">Quantity</th>
	<th scope="col">Unit Price</th>
    <th scope="col">Amount</th>
  </thead>
  <tbody>
    <?

$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>$Consultant</td>";
      echo "<td>".$row['Quantity']."</td>";
      echo "<td>".$row['UnitPrice']."</td>";
      echo "<td>".$row['Amount']."</td>";
    echo "</tr>";
    $i++;
}

?>

    <tr>
      <td colspan="4"></td>
      <td style="font-weight:bold">Sub Total</td>
      <td style="font-weight:bold"><b><? 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><? echo $Total;?></b></td>
  </tr>
 <!-- <tr>-->
	<!--	<td><b>Advance &nbsp;&nbsp;&nbsp;&nbsp;:</b></td>-->
	<!--	<td><b>-->
		    <? //echo $advanceAmount;?>
	<!--	    </b></td>-->
	<!--</tr>-->
  
  
  <tr>
    <td><b>Patient Payable Amount &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</b></td>
    <td><b><? echo $payable;?></b></td>
  </tr>
</table>


  </div>
  <div class="col-md-2"></div>
</div>
<br>
<?php
   
        function getIndianCurrency(float $number)
        {
            $decimal = round($number - ($no = floor($number)), 2) * 100;
            $hundred = null;
            $digits_length = strlen($no);
            $i = 0;
            $str = array();
            $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 > 0) ? "." . ($words[$decimal / 10] . " " . $words[$decimal % 10]) . ' Paise' : '';
            return ($Rupees ? $Rupees . 'Rupees ' : '') . $paise;
        }
        
    ?>
<div>
      <h6 style="font-weight:bold"><?php echo getIndianCurrency($payable)." only/-"; ?></h6>
  </div>

<div class="row mt-5">
  <div class="col-md-3">
      <p>Prepared by <b><? echo $name?></b></p>
  </div>
  <div class="col-md-6"></div>
  <div class="col-md-3">
<h6>Authorized Signatory</h6>
    
  </div>
</div>


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


<?
}
?>

