<style>
th{text-decoration:underline}
</style>

<?
include("opendb.php");
include ("test.php");
  $df=$y.'-'.$m.'-'.$d;
  $dt=$y1.'-'.$m1.'-'.$d1;
  if(!checkdate($m,$d,$y))
    { print "<script> alert('Invalid date'); </script>"; return;}
  if(!checkdate($m1,$d1,$y1))
    { print "<script> alert('Invalid date'); </script>"; return;}

$re=mysqli_query($db,"select to_days('$y1-$m1-$d1')-to_days('$y-$m-$d')")or die(mysqli_error());
$diff_row=mysqli_fetch_row($re)or die(mysqli_error());

 if($diff_row[0]<0)
  { print "<script> alert('Invaild Date'); </script>";return;}

 print "<table border=0 width=60%><tr> <td align=center><b>Alphonsa Hospital </b><br>$type Report summary <br> from <font color='dark brown'>".datetohtml($df)."</font> To <font color='dark brown'>".datetohtml($dt)."</font></tr></td><tr><td>";
   $result=mysqli_query($db," select item,count(item),sum(amt) from opbill  where  date>='$df' and date<='$dt' and type1='$type' group by item") or die(mysqli_error());

 print "<table border=0 width=100%><th>Item <th width=20>Nos.<th width=120>Amount";
 $t=0;
 while($row=mysqli_fetch_array($result))
 {
  print "<tr><td>$row[0]</td><td align=right>$row[1]</td><td align=right>$row[2]</td></tr>";
  $t+=$row[2];
 }
 print "<tr><td colspan=2><b> Total </td><td align=right><b>";
 printf("%12.2f </td></tr>",$t);
//}
$sq="select sum(amt) from discount where  dt>='$df' and dt<='$dt' and type='$type'";
   $result=mysqli_query($db,$sq) or die(mysqli_error());
$disrow=mysqli_fetch_row($result);
 if(mysqli_num_rows($result)<=0)
 {
  print " <br><font color=red> <blink>No record </blink></font>";
  return;
 }

printf("<tr><td colspan=2>Less Concession </td><td align=right>%12.2f</td></tr>",$disrow[0]);
printf("<tr><td colspan=2><b>Grant Total </td><td align=right><b>%12.2f</td></tr></b>",($t-$disrow[0]));
$gtot=abs($t+($disrow[0]*-1));

 print "</table></tr></td><tr><td align=center><FONT FACE=ARIAL SIZE=2> RUPEES <FONT COLOR='DARK BROWN'>".word($gtot)."</FONT> ONLY <hr>";
print "</td></tr></table>";


?>
