<?php
session_start();

include 'dbc.php';

$userid=$_SESSION['userid'];

$id=$_REQUEST["id"];
$sql1 = "SELECT * FROM addclass where user_id = '$userid'";
$result1=$conn->query($sql1);
$row1 = $result1->fetch_assoc();
$feedisc1=$row1['feedisc1'] ;
$feedisc2=$row1['feedisc2'] ;
$feedisc3=$row1['feedisc3'] ;
$feedisc4=$row1['feedisc4'] ;
$feedisc5=$row1['feedisc5'] ;
$feedisc6=$row1['feedisc6'] ;


  $sqlcus = "select * from rec_fee where id='$id' and user_id='$userid'";
   $result=$conn->query($sqlcus);
$ppp = $result->fetch_assoc();
   $adm_no=$ppp['adm_no'] ;
    $feerec=$ppp['feerec'] ;
	 $fee1rec=$ppp['fee1rec'] ;
	  $fee2rec=$ppp['fee2rec'] ;
	   $fee3rec=$ppp['fee3rec'] ;
	    $fee4rec=$ppp['fee4rec'] ;
		 $fee5rec=$ppp['fee5rec'] ;
		  $fee6rec=$ppp['fee6rec'] ;
		   $disfee=$ppp['disfee'] ;
		   $disfee1=$ppp['disfee1'] ;
		   $disfee2=$ppp['disfee2'] ;
		   $disfee3=$ppp['disfee3'] ;
		   $disfee4=$ppp['disfee4'] ;
		   $disfee5=$ppp['disfee5'] ;
		   $disfee6=$ppp['disfee6'] ;
   $month_period=$ppp['month_period'] ;
$sql2 = "SELECT * FROM issueslip where adm_no = '$adm_no' and  month_name='$month_period' and  user_id='$userid'";
$result2=$conn->query($sql2);
$row2 = $result2->fetch_assoc();

$totalfee=$row2['totalfee'] ;
$totalfeebal=$row2['totalfeebal'] ;

 	     $netqty =0;
$qtysale=0;
$qtypur=0;
 $netqty1 =0;
$qtysale1=0;
$qtypur1=0;
 $netqty2 =0;
$qtysale2=0;
$qtypur2=0;
 $netqty3 =0;
$qtysale3=0;
$qtypur3=0;
 $netqty4 =0;
$qtysale4=0;
$qtypur4=0;
 $netqty5 =0;
$qtysale5=0;
$qtypur5=0;
 $netqty6 =0;
$qtysale6=0;
$qtypur6=0;

  $sql4 = "select * from issueslip where  adm_no='$adm_no' and user_id='$userid'";
$result4=$conn->query($sql4);
while($ppp4 = $result4->fetch_assoc())
{
  $qtysale= $qtysale + $ppp4["feebal"];
  $qtysale1= $qtysale1 + $ppp4["fee1bal"];
  $qtysale2= $qtysale2 + $ppp4["fee2bal"];
  $qtysale3= $qtysale3 + $ppp4["fee3bal"];
  $qtysale4= $qtysale4 + $ppp4["fee4bal"];
  $qtysale5= $qtysale5 + $ppp4["fee5bal"]; 
  $qtysale6= $qtysale6 + $ppp4["fee6bal"];  
 } 
  
$sql3 = "select * from rec_fee where adm_no='$adm_no' and user_id='$userid'";
$result3=$conn->query($sql3);
while($ppp3 = $result3->fetch_assoc())
{
  $qtypur= $qtypur + $ppp3["feerec"];
  $qtypur1= $qtypur1 + $ppp3["fee1rec"];
  $qtypur2= $qtypur2 + $ppp3["fee2rec"];
  $qtypur3= $qtypur3 + $ppp3["fee3rec"];
  $qtypur4= $qtypur4 + $ppp3["fee4rec"];
  $qtypur5= $qtypur5 + $ppp3["fee5rec"];
  $qtypur6= $qtypur6 + $ppp3["fee6rec"];
 } 
 
 
 

$netqty = ($qtysale ) - ($qtypur + $disfee );
$netqty1 = ($qtysale1 ) - ($qtypur1 + $disfee1);
$netqty2 = ($qtysale2 ) - ($qtypur2 + $disfee2);
$netqty3= ($qtysale3 ) - ($qtypur3 + $disfee3);
$netqty4 = ($qtysale4 ) - ($qtypur4 + $disfee4);
$netqty5 = ($qtysale5 ) - ($qtypur5 + $disfee5);
$netqty6 = ($qtysale6 ) - ($qtypur6 + $disfee6);
$totalfee= $netqty  + $feerec + $fee1rec + $fee2rec + $fee3rec + $fee4rec + $fee5rec + $fee6rec + $netqty1 + $netqty2 + $netqty3 + $netqty4 + $netqty5 + $netqty6;
$totalfeerec= $feerec + $fee1rec + $fee2rec + $fee3rec + $fee4rec + $fee5rec + $fee6rec;
$totalfeebal= $totalfee - $totalfeerec;
		
echo "<table border=1 width=50% align=center bgcolor=white>";
?>
<tr>
<td align="center" colspan="4"><img src="logo1.jpg" /></td>

</tr>
<?php
echo "<tr>";
echo "<th bgcolor=white align=center colspan=4>  $userid </th>";
echo "</tr>";
echo "<tr>";
echo "<th bgcolor=white align=center colspan=4>  The Ambassador Schools Toba Tek Singh. 03326116988 / 03463595988</th>";
echo "</tr>";

echo "<tr>";
echo "<th bgcolor=white align=center colspan=4>  Monthly Fee Receipt </th>";
echo "</tr>";
echo "<tr>";
  echo "<th bgcolor=white align=left>  Date </th>";
  echo "<td>"  .$ppp["date"] . "</td>" ; 
  echo "<th bgcolor=white align=left> Receipt No </th>";
  echo "<td>"  .$ppp["id"] . "</td>" ;
  echo "</tr>";
  echo "<tr>";
  echo "<th bgcolor=white align=left>  Roll No </th>";
  echo "<td>"  .$ppp["portal_id"] . "</td>" ; 
  echo "<th bgcolor=white align=left> Month </th>";
  echo "<td>"  .$ppp["month_period"] . "</td>" ;
  echo "</tr>";

echo "<tr>";
  echo "<th bgcolor=white align=left>  Student Name </th>";
  echo "<td>"  .$ppp["std_name"] . "</td>" ; 
   echo "<th bgcolor=white align=left> Class  </th>";
  echo "<td>"  .$ppp["class_name"] . "</td>" ; 
  echo "</tr>";
  
  echo "<tr>";
  echo "<th bgcolor=white align=left colspan=3> Fee descrtipton  </th>";
   echo "<th bgcolor=white align=left > Amount  </th>";
  echo "</tr>";
 
  echo "<tr>";
  echo "<th bgcolor=white align=left colspan=3> Receipt Fee  </th>";
    echo "<td>"  .$ppp["feerec"] . "</td>" ; 
  echo "</tr>";
 echo "<tr>";
  echo "<th bgcolor=white align=left colspan=3> $feedisc1  </th>";
  echo "<td>"  .$ppp["fee1rec"] . "</td>" ; 
  echo "</tr>";
  echo "<tr>";
  echo "<th bgcolor=white align=left colspan=3> $feedisc2  </th>";
  echo "<td>"  .$ppp["fee2rec"] . "</td>" ; 
  echo "</tr>";
  
  echo "<tr>";
  echo "<th bgcolor=white align=left colspan=3> $feedisc3  </th>";
  echo "<td>"  .$ppp["fee3rec"] . "</td>" ; 
  echo "</tr>";
     echo "<tr>";
  echo "<th bgcolor=white align=left colspan=3> $feedisc4  </th>";
  echo "<td>"  .$ppp["fee4rec"] . "</td>" ; 
  echo "</tr>";
   echo "<tr>";
  echo "<th bgcolor=white align=left colspan=3> $feedisc5  </th>";
  echo "<td>"  .$ppp["fee5rec"] . "</td>" ; 
  echo "</tr>";
   echo "<tr>";
  echo "<th bgcolor=white align=left colspan=3> $feedisc6  </th>";
  echo "<td>"  .$ppp["fee6rec"] . "</td>" ; 
  echo "</tr>";
   echo "<tr>";
  echo "<th bgcolor=white align=left colspan=3> Discount Amount  </th>";
  echo "<td>"  .$ppp["disfee"] . "</td>" ; 
  echo "</tr>";
  echo "<tr>";
  echo "<th bgcolor=white align=left colspan=3> Total Payable  </th>";
 			 echo "<td>"  .$totalfee . "</td>" ; 
  echo "</tr>";
  echo "<tr>";
  echo "<th bgcolor=white align=left colspan=3> Total Receipt  </th>";
  echo "<td>"  .$totalfeerec . "</td>" ; 
  echo "</tr>";
  echo "<tr>";
  echo "<th bgcolor=white align=left colspan=3> Balance  </th>";
  echo "<td>"  .$totalfeebal . "</td>" ; 
  echo "</tr>";
   echo "<tr>";
  echo "<th bgcolor=white align=left colspan=3> Collected By  </th>";
  echo "<td>"  .$ppp["username"] . "</td>" ; 
  echo "</tr>";
  
   
 
 echo "</table>";
	 
 
?>

<br />


