<?
 session_start();
$tbl=str_replace('.','',$REMOTE_ADDR);
$tbl.='X';
$t=0;
//print $regno.$billno.$reg1.$consulting.$drname;
?>
<style>
td{font-family:'arial'}
</style>

<TABLE border=0 CELLSPACING=0 CELLPADDING=1  width=65%>
<tr><td colspan=2><center><b> ALPHONSA HOSPITAL <br>PULLURAMPARA <br>PH:2276297</TD></TR>
<TR BGCOLOR=WHITE><TD ALIGN=CENTER COLSPAN=2><br><u>O.P CASH BILL</u><br>&nbsp;</td></tr>
<TR BGCOLOR=WHITE><TD>Bill No:<? print $billno?>&nbsp;&nbsp;&nbsp;&nbsp; </td><td align=right>Date <?print date("d-m-Y",time())?></td></tr>
<tr><td>Name: <?print strtoupper($pname) ?></td><td align=right> Reg. No : <?print (int)$regno?></td></tr>

<tr><td colspan=2 bgcolor=white><hr></td></tr>
<tr><td align=center bgcolor=white colspan=2>

<?
include("opendb.php");
if(strlen($dis)>0)
{
 $da=date("Y-m-d",time());
 $sq="insert into discount values('$billno','$dis','$regno','O.P','$da')";
 mysqli_query($db,$sq);
 $acsq="insert into actrans values('$billno','Discount Allowed','Expenses','$billno','$da', 'Discount Allowed','0','$dis','Being discount allowed to O.P','Cash','Discount Allowed','Cash','$dis')";
 mysqli_query($db,$acsq)or die(mysqli_error());

}
$sq="select * from $tbl where regno='$regno'";
$result=mysqli_query($db,$sq);
print "<table border=0 width=100%>";
?>
<tr><td align=center><u>Particulars</td><td align=center width=90><u>Amount</td></tr>
<?
 $dt=date("Y-m-d",time());
while($row=mysqli_fetch_array($result))
{
 print "<tr><td>$row[2]</td><td align=right>$row[3]</td></tr>";
 $sql="insert into opbill values('$regno','$row[2]','$row[3]','$billno','$row[date]','$drname','O.P')";
mysqli_query($db,$sql);
 $t+=$row[3];
 $dt=date("Y-m-d",time());
} // end while
 $dt=date("Y-m-d",time());
$result=mysqli_query($db,"select * from regfee");
$row=mysqli_fetch_row($result);
$reg_fee=$row[0];
if($reg1=='off')
 {
  print "<tr><td>Registration</td><td align=right>$reg_fee</td></tr>";
  $sq="insert into opbill (regno,item,amt,billno,date,doctor,type1) values('$regno','Re-Registration','$reg_fee','$billno','$dt','$drname','O.P')";
  mysqli_query($db,$sq)or die(mysqli_error());
  $t+=$reg_fee;
$acsq="insert into actrans values('$billno','Direct Inc.','Income','$billno','$dt', 'O.P.Registration Fee','$reg_fee','0','Being O.P. Regn.','Cash','Cash','O.P.Registration Fee','$reg_fee')";
	  mysqli_query($db,$acsq)or die(mysqli_error());
 }
if($drfees>0)
{
 print "<tr><td>Consultation</td><td align=right>$drfees</td></tr>";
  $sq="insert into opbill (regno,item,amt,billno,date,doctor,type1) values('$regno','Consultation','$drfees','$billno','$dt','$drname','O.P')";

  mysqli_query($db,$sq)or die(mysqli_error());
} 
$t+=$drfees;
$t+=$consulting;
 printf ("<tr><td valign=botom><b>Total</td><td align=right><hr><b>%12.2f</b><br>==========<br></td></tr>",$t);
if(strlen($dis)>0)
 {
  printf ("<tr><td>Less Concession</td><td align=right>%12.2f<hr></td></tr>",$dis);
  $t-=$dis;
 }
$totforac=($t-$reg_fee);
$acsq="insert into actrans values('$billno','Direct Inc.','Income','$billno','$dt', 'O.P.Collection','$totforac','0','Being O.P. collection.','Cash','Cash','O.P.Collection','$totforac')";
	  mysqli_query($db,$acsq)or die(mysqli_error());
if(strlen($dis)>0)
{
 printf ("<tr><td><b>Grand Total</td><td align=right><b>%12.2f</b><br>==========</td></tr>",$t);
}
 mysqli_query($db,"drop table $tbl") or die(mysqli_error());
?>
</table>
</td></tr>
<tr bgcolor=white><td colspan=2 align=right height=100 valign=bottom>Signature</td></tr>
</table>


<style>
td{font-family:'arial'}
</style>

<?
if($regn=='off')
{
$re=mysqli_query($db,"select * from regn where regno='$regno'")or die(mysqli_error());
$row=mysqli_fetch_array($re);
?>

<TABLE border=0 CELLSPACING=0 CELLPADDING=11 BGCOLOR=BLACK >
<tr BGCOLOR=WHITE><td colspan=2>
<?for($i=0;$i<100;$i++) print "-";?>
</td></tr>

<TR BGCOLOR=WHITE><TD ALIGN=left width=100>ALPHONSA HOSPITAL <BR>PULLURAMPARA <br>PH:2276297</TD>
<td align=right>Regn. Date: <?print date("d-m-Y",time())?>

<?
$r=mysqli_query($db,"select fee from regfee");
$f_row=mysqli_fetch_row($r);
$reg_fee=$f_row[0];
?>

<br> Fee: Rs.<?print (int)$reg_fee;?>/-</td>
</TR>
<TR BGCOLOR=WHITE><TD colspan=1><blockquote>
Name:  <b><?print strtoupper($row[name]) ?> </b>
<Br> House Name : <?print $row[house]?>
<br>
Age: <?print $row[age]?> Sex: <?print $row[sex]?>
<br> Regn No: <b><? print substr($regno,0,4).'-'.(int)substr($regno,4)?></b>
</td>
<td bgcolor=white></td></tr>
<tr BGCOLOR=WHITE><td colspan=2>
<?//for($i=0;$i<100;$i++) print "-";
?>
</td></tr>
</table>
<?
}
?>

