<style>
    @media print {

        #myPrntbtn {
            display :  none;
        }

    }
</style>

<input type="button" onclick="printDiv('printableArea')" value="Print" />


<div id="printableArea">
    <div style="width:100%;text-align:center;">

        <img src="<?php echo $LinksDetails['logo']; ?>" style="width:200px;float:left;height:80px;"/>

        <h1><?php
            echo $LinksDetails['site_name']; ?>
        </h1>
        <label><?php
                echo $LinksDetails['contact_content']; ?>
        </label>

    </div>
<hr>

<?php
        if(isset($_GET["fyear"]) && trim($_GET["fyear"])!="" && isset($_GET["fmonth"]) && trim($_GET["fmonth"])!="" && isset($_GET["fdate"]) && trim($_GET["fdate"])!="" && isset($_GET["tyear"]) && trim($_GET["tyear"])!="" && isset($_GET["tmonth"]) && trim($_GET["tmonth"])!="" && isset($_GET["tdate"]) && trim($_GET["tdate"])!=""){
			$fdate=$_GET["fyear"]."/".$_GET["fmonth"]."/".$_GET["fdate"];
			$tdate=$_GET["tyear"]."/".$_GET["tmonth"]."/".$_GET["tdate"];
// 			$where[]=" (udate between '$fdate' and '$tdate') ";
		}

    if(isset($_REQUEST["daily1"])){
	//print_r($_GET["user1"]);
			
		$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllHostelOther=$overAllOther=0;$overAllFine=0;$overAllextra=array();$overAllNewextra=0;$overAllTot=0;$recno=0;$mode=0;
		$whereLocation="";
		if(isset($_GET["location"]) && $_GET["location"]!=""){
			$whereLocation=" and location='".$_GET["location"]."' ";
		}
		
		if(!empty($_GET["user1"]) ){
			$u=implode(',',$_GET["user1"]);
			$whereUser=" and added_by in ($u) ";		
		}
	
		
		$aryFeeType=$db->getRows("select distinct(type) from extrafee_type where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 order by type");
				
		$aryStudentList=$db->getRows("SELECT idno,added_by FROM `reff_receipt` WHERE  date between '$fdate' and '$tdate' and session='".$_SESSION["admin"]["session"]."'  $whereUser  group by idno");
				
		//echo $db->getErMsg().$db->getLastQuery();
		if(is_array($aryStudentList) && count($aryStudentList)>0){
				
			$tndate = date('Y/m/d', strtotime('-1 days',strtotime($tdate)));
			//echo $tndate." ".$fdate
			?>
			<!--<button onclick="printme()" id="myPrntbtn">Print</button>-->

            <center><h5><p style="float:right">Collection Date: 
			<?php if(strtotime($tndate)==strtotime($fdate)){
			echo date("d-M-Y",strtotime($tndate));?> - <?php echo date("l",strtotime($tndate));}
			else echo date("d-M-Y",strtotime($fdate)) ." to ".date("d-M-Y",strtotime($tndate)); ?></p> <p>Daily Collection Report</p>	</h5></center>

			<table class="table" cellspacing="0" cellpadding="0" border="1" id="tblData" style="width:100%;">
				<thead>
				<tr style="cursor:pointer">
                	<th>S.No</th>
					<th>Student Name</th>
                    <th>Father Name</th>
                    <th>Admission no</th>
					<th>Class</th>
					<th><div style="width:70px">Branch</div></th>
					<th>User</th>
					<th>Student Type</th>
                    <th>Receipt No</th>
                    <th>Payment Mode</th>
					
                    <th>Month</th>
					<th>Tution Fee</th>
					<th>Transport fee</th>
					<th>Hostel Fee</th>
				   <?php
				   if(is_array($aryFeeType) && count($aryFeeType)>0){
					foreach($aryFeeType as $ftype){
						?><th><?php echo $ftype["type"] ?></th><?php
					}
				   }
				   ?>
				   <th>Fee/other</td>
				   <th>Fine</th>
                   <th>Hostel Other</th>
				   <th>Extra</th> 
                   <th>Income</th> 
				   <th>Total</th>
				</tr>
				</thead>
				<tbody>
					<?php $s=0;
					//foreach($aryStudentList as $fStudent){
												
						foreach($aryStudentList as $s_id){
							$loc=$db->getRow("select idno from student where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' and session='".$_SESSION["admin"]["session"]."'   and issue_TC=0  $whereLocation");
							
						if(!empty($loc)){
							
							$fStudent=$db->getRow("select idno, name,fname,admissionno,stype,class,section,location from student where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' and session='".$_SESSION["admin"]["session"]."'    and issue_TC=0 ");
							
						
						
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$hotherExtra=$h1otherExtra=$hostelotherExtra=0;$total=0;$fine=0;
						/*$installTution=$db->getRows("select ins_name from installment_time where ins_name like 'ip%' and (date between '$fdate' and '$tdate') and idno='".$s_id[idno]."'  ");
						if(is_array($installTution) && count($installTution)>0){
							foreach($installTution as $installT){
								$tution+=$db->getVal("select ".$installT["ins_name"]." from installment where idno=".$s_id[idno]);
								
							}
							$overAlltution+=$tution;
							$total+=$tution;
						}*/
						// tution new
						$tution=$db->getVal("select sum(amount) from reff_receipt where idno='".$s_id[idno]."' and type='fee' and (date between '$fdate' and '$tdate') ");
							if(!empty($tution)){
							$overAlltution+=$tution;
							$total+=$tution;
							}
							
						/*$installTution=$db->getRows("select ins_name from installment_time where ins_name like 'bp%' and (date between '$fdate' and '$tdate') and idno='".$s_id[idno]."' ");
						if(is_array($installTution) && count($installTution)>0){
							foreach($installTution as $installT){
								$trasnport+=$db->getVal("select ".$installT["ins_name"]." from installment where idno=".$s_id[idno]);
							}
							$overAllTransport+=$trasnport;
							$total+=$trasnport;
						}*/
						// tranasport
						 $trasnport=$db->getVal("select sum(amount) from reff_receipt where idno='".$s_id[idno]."' and type='busfee' and (date between '$fdate' and '$tdate') ");
						

							if(!empty($trasnport)){
							$overAllTransport+=$trasnport;
							$total+=$trasnport;
							}
						
						/*$installTution=$db->getRows("select ins_name from installment_time where ins_name like 'hp%' and (date between '$fdate' and '$tdate') and idno='".$s_id[idno]."' ");
						if(is_array($installTution) && count($installTution)>0){
							foreach($installTution as $installT){
								$inst="ip".preg_replace("/hp/","",$installT["ins_name"]);
								$hostel+=$db->getVal("select ".$inst." from hostelinstallment where idno=".$s_id[idno] );
							}
							$overAllhotel+=$hostel;
							$total+=$hostel;
							}
							*/
														
							$hostel=$db->getVal("select sum(amount) from reff_receipt where idno='".$s_id[idno]."' and type='hostelfee' and (date between '$fdate' and '$tdate') ");
														
							if(!empty($hostel)){
							$overAllhotel+=$hostel;
							$total+=$hostel;
							}
													
						$extrasum=array();
						if(is_array($aryFeeType) && count($aryFeeType)>0){
							foreach($aryFeeType as $ftype){  
								$sums=0;
								$Ftypeid=$db->getVal("select id from extrafee_type where type='".$ftype["type"]."' and class='".$fStudent["class"]."'");
								
								
								/*$installTution=$db->getRows("select ins_name from installment_time where ins_name like 'ext-".$Ftypeid."-%' and (date between '$fdate' and '$tdate') and idno='".$s_id[idno]."' ");$no=array(); //if($s==0) {echo $db->getLastQuery();}
								if(is_array($installTution) && count($installTution)>0){
									foreach($installTution as $installT){
										$no=explode("-",$installT[0]);
										$sums+=$db->getVal("select pay from extrafee where idno='".$s_id[idno]."' and  pid='p".$no[2]."' and type='".$Ftypeid."' ");
										
										
										
								
										
										echo $db->getErMsg();
									}
									
								}*/
								
								
								
								if($Ftypeid) { //echo $Ftypeid;
								$sums=$db->getVal("select sum(amount) from reff_receipt where idno='".$s_id[idno]."' and type='extrafee".$Ftypeid."' and (date between '$fdate' and '$tdate') ");
								}
								$extrasum[]=$sums;
								$total+=$sums;$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
							}
						}
						
						
						$installOtherExtra=$db->getRows("select ins_name from installment_time where ins_name like 'other%' and (date between '$fdate' and '$tdate') and idno='".$s_id[idno]."' ");

						if(is_array($installOtherExtra) && count($installOtherExtra)>0){
							foreach($installOtherExtra as $installT){
								//other1_detail

								$idSdetail=str_replace("_detail","",$installT[ins_name]);
								// echo $installT[0];
								$idSdetail=str_replace("other","",$idSdetail);
								//$otherExtra+=$db->getVal("select fine from installment_fine where ins_name='".$idSdetail."-otherfee' and idno=".$s_id[idno]);
							$otherExtra+=$db->getVal("select fine from installment_fine where ins_name='".$idSdetail."-otherfee'  and  (udate between '$fdate' and '$tdate') and idno=".$s_id[idno]);


								//echo $db->getLastQuery();
							}
							
							
						}
						
						//$otherExtra=$db->getVal("select sum(fine) from installment_fine where ins_name like '%other%' and (udate between '$fdate' and '$tdate') and idno='".$s_id[idno]."' ");
						 //$ss="select sum(fine) from installment_fine where ins_name like '%other%' and (udate between '$fdate' and '$tdate') and idno='".$s_id[idno]."' ";
							

							$overAllOther+=$otherExtra;
							$total+=$otherExtra;
						
						/*$installOtherExtra=$db->getRows("select ins_name from installment_time where ins_name like 'hostelother%' and (date between '$fdate' and '$tdate') and idno='".$s_id[idno]."' ");
						if(is_array($installOtherExtra) && count($installOtherExtra)>0){
							foreach($installOtherExtra as $installT){
								//other1_detail
								$idSdetail=str_replace("_detail","",$installT[0]);
								$idSdetail=str_replace("hostelother","",$idSdetail);
								$hotherExtra+=$db->getVal("select fine from installment_fine where ins_name='".$idSdetail."-otherfeehostel' and idno=".$s_id[idno]);          						//echo $db->getLastQuery();
								$h1otherExtra+=$db->getVal("select sum(fine) from installment_fine where ins_name='".$idSdetail."-otherhostel' and idno=".$s_id[idno]);
								//echo $db->getLastQuery();
							}$hostelotherExtra=$hotherExtra+$h1otherExtra;
							$overAllHostelOther+=$hostelotherExtra;
							$total+=$hostelotherExtra;
						}*/
						
						$hostelotherExtra=$db->getVal("select sum(fine) from installment_fine where ins_name like '%hostel' and (udate between '$fdate' and '$tdate') and idno=".$s_id[idno]);
						
						$overAllHostelOther+=$hostelotherExtra;
						$total+=$hostelotherExtra;
						
						$fine=(float)$db->getVal("select sum(fine) from installment_fine where (ins_name like '%-class' or ins_name like '%-hostel' or ins_name like '%-bus' or ins_name like '%-extra%') and (udate between '$fdate' and '$tdate') and idno='".$s_id[idno]."'");
						$total+=$fine;
						$overAllFine+=$fine;
						$newExtra=(float)$db->getVal("select sum(fine) from installment_fine where (ins_name like '%-other') and (udate between '$fdate' and '$tdate') and idno='".$s_id[idno]."' ");
						$rdate=date("Y-m-d",strtotime($fdate));
						$sdate=date("Y-m-d",strtotime($tdate));
						$ref=$db->getRows("select * from reff_receipt where date > '$rdate' and date < '$sdate' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and idno='".$s_id[idno]."' ");
							//echo $db->getLastQuery();
								//print_r($ref);exit;
									$rids=array();$rrmonth=array();
									
						$rdate1=date("d-m-Y",strtotime($fdate));
						$sdate1=date("d-m-Y",strtotime($tdate));
						$rrde=$db->getRows("select * from receipt where  session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."'  ");
							
							
									//echo $db->getLastQuery();
								   //print_r($rrde);exit;
									//echo "<pre>";print_r($rrde);echo "</pre>";
									if(is_array($rrde) && count($rrde)>0){
										foreach($rrde as $rr){
											$rl_rrid=explode("-",$rr["rrid"]);
											//print_r($rl_rrid);exit;
										foreach($ref as $reff){
											//echo $reff['given_date'];exit;
											//if($reff["date"]!=$reff["given_date"])
												///$date_ary[]=date("d-m-Y",strtotime($reff["given_date"]));
											foreach($rl_rrid as $rrids){
											//echo $rrids;exit;
											if($rrids==$reff["id"]){
													$r=$rr['id'];
													if(!($r==$ridss)) {
													$ridss=$r;
													$rrmonth[]=$rr['Months'];
													$rids[]=$ridss;}
												}
											}
										}
										
									}
								}    //$recno=$ridss;
									$recno= implode(",",$rids);
						$total+=$newExtra;
						$overAllNewextra+=$newExtra;
						$fmonths="";$monthname1="";$monthname=array();
						$fmonths=implode(",",$rrmonth);
					$im=explode(",",$fmonths);
					$mn=array_unique($im);$months="";
					if(is_array($mn) && count($mn)){
						foreach($mn as $ipi){					
							if($ipi!=""){
								if($months!="")$months.=",";
								if($ipi<=9){
									$newDate=date("Y")."-".($ipi+3)."-1";
									$months.= date("M",strtotime($newDate));//."(".($ij+3).")";
								}
								else{
									$newDate=date("Y")."-".($ipi-9)."-1";
									$months.= date("M",strtotime($newDate));//."(".($ij-9).")";
								}
							}
						}
					}
						//echo $db->getErMsg();
						if($total>0){ $s++;
						?>
						<?php 
						$rdate2=date("Y-m-d",strtotime($fdate));
						$sdate2=date("Y-m-d",strtotime($tdate));
						
						$mode= $db->getVal("select if(payment_mode ='',null, payment_mode) from receipt where id in (select id from receipt where  (udate between '$rdate2' and '$sdate2') and session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."'  ) order by payment_mode DESC ");
					
						      //$mode=$db->getVal("select if(payment_mode ='',null, payment_mode) from receipt where id in ($recno) order by payment_mode DESC ");
  						      
				// 		echo "select if(payment_mode ='',null, payment_mode) from receipt where id in (select id from receipt where  (udate between '$rdate2' and '$sdate2') and session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."'  ) order by payment_mode DESC ";  
					
						?>
						
						
						<tr class="<?php if(!empty($mode)){ echo $mode; } else echo 'Cash' ;?> empty">
                        	<td><?php echo $s; ?></td>
							<td><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"] ?>-<?php echo $fStudent["section"] ?></td>
							<td><?php if($_GET["location"]=="")echo $db->getVal("select name from location where id='".$fStudent["location"]."' and school_id='".$_SESSION["admin"]["school_id"]."'"); 
							else echo $db->getVal("select name from location where id='".$_GET["location"]."' and school_id='".$_SESSION["admin"]["school_id"]."'");//date("d-M-y",strtotime($fdate));//" to ".date("d/m/y",strtotime($tdate)); ?></td>
                            <td><?php echo $db->getVal("select name from users where id='$s_id[added_by]'"); ?></td>
                            <td><?php echo $fStudent["stype"] ?></td>
                            <td><?php echo $recno; ?></td>
														
                            <td><?php 
							
							if(!empty($recno)){
							$m= $db->getVal("select if(payment_mode ='',null, payment_mode) from receipt where id in ($recno) order by payment_mode DESC ");
							} else { $m='';}	
							
if($m!='') echo $m; else echo 'Cash';

							?></td>
                            <td><?php echo $months; ?></td>
							<td><?php echo $tution; ?></td>
							<td><?php echo $trasnport ?></td>
							<td><?php echo $hostel ?></td>
							<?php  for($ij=0; $ij<count($aryFeeType); $ij++){ ?><td><?php echo $extrasum[$ij]; ?></td><?php } ?>
						   <td><?php echo $otherExtra; ?></td>
						   <td><?php echo $fine; ?></td>
                           <td><?php echo $hostelotherExtra; ?></td>
						   <td><?php echo $newExtra; ?></td>
                           <td>0</td>
						   <td><?php echo $total;$overAllTotal+=$total; ?></td>
						</tr>
						<?php
						}
					}
					}
					?>
                    <tr class="empty">
                    	<td></td>
                		<td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td><?php if($_GET["location"]=="")echo "All";else echo $db->getVal("select name from location where id='".$_GET["location"]."' and school_id='".$_SESSION["admin"]["school_id"]."'"); //echo $db->getLastQuery();//echo date("d-M-y",strtotime($fdate));//" to ".date("d/m/y",strtotime($tdate)); ?></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td>0</td>
                        <td>0</td>
                        <td>0</td>
                        <?php
						if(is_array($aryFeeType) && count($aryFeeType)>0){
							foreach($aryFeeType as $installT){
								?><td>0</td><?php
							}
						}
						?>
                        <td>0</td>
                        <td>0</td>
                        <td>0</td>
                        <td>0</td>
                        <td><?php echo $tot=$db->getVal("select sum(amount) from transaction where type='deposit' and (udate between '$fdate' and '$tdate') and (tfor='cash' or tfor='cheque' or tfor='hostel-income') and session='".$_SESSION["admin"]["session"]."' $whereUser"); ?></td>
                        <td><?php echo $tot;$overAllTot+=$tot;$overAllTotal+=$tot; ?></td>
                    </tr>
				</tbody>
				<tfoot>
				    <tr>
    					<td colspan="11">Gross Total</td>
    					<td><?php echo $overAlltution ?></td>
    					<td><?php echo $overAllTransport ?></td>
    					<td><?php echo $overAllhotel ?></td>
    					<?php
    					if(is_array($overAllextra) && count($overAllextra)>0){
    						foreach($overAllextra as $ftype){
    							?><td><?php echo $ftype ?></td><?php
    						}
    					   }?>
    				   <td><?php echo $overAllOther ?></td>
    				   <td><?php echo $overAllFine ?></td>
                       <td><?php echo $overAllHostelOther ?></td>
    				   <td><?php echo $overAllNewextra ?></td>
                       <td><?php echo $overAllTot; ?></td>
    				   <td id="completeFeeShw"><?php echo $overAllTotal; ?></td>
                    </tr>
				</tfoot>
			</table>  
            Print Date : <?php echo date('d-M-Y'); ?>
			<?php
		}else{
			echo "No record found<br />".$db->getErMsg();
		}
	}

    elseif(isset($_REQUEST["daily_withouthostel"])){

	$pmode  = array();
	$ptotal = array();
	$pusers = array();
    $temp   = array();
    $tempuser = array();

		$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllFine=0;$overAllextra=array();$overAllNewextra=0;$overAllTot=0;
		$whereLocation="";
		if(isset($_GET["location"]) && $_GET["location"]!=""){
			$whereLocation=" and location='".$_GET["location"]."' ";
		}

		/*if(isset($_GET["user"]) && $_GET["user"]!=""){
			$whereUser=" and added_by='".$_GET["user"]."' ";
		}*/
		
		if(!empty($_GET["user1"]) ){
			$u=implode(',',$_GET["user1"]);
			$whereUser=" and added_by in ($u) ";	
		}
		
		$aryFeeType=$db->getRows("select distinct(type) from extrafee_type where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'  order by type");

// 		$aryStudentList=$db->getRows("SELECT idno,added_by FROM `reff_receipt` WHERE  date between '$fdate' and '$tdate' and session='".$_SESSION["admin"]["session"]."' $whereUser  group by idno");
		$aryStudentList=$db->getRows("SELECT idno, added_by FROM `reff_receipt` WHERE  date between '$fdate' and '$tdate'  group by idno");		

		//echo $db->getErMsg().$db->getLastQuery();
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			$tndate = date('Y/m/d', strtotime('-1 days',strtotime($tdate)));
			//echo $tndate." ".$fdate
			?>
            <center><h5><p style="float:right">Collection Date: 
			<?php if(strtotime($tndate)==strtotime($fdate)){
			echo date("d-M-Y",strtotime($tndate));?> - <?php echo date("l",strtotime($tndate));}
			else echo date("d-M-Y",strtotime($fdate)) ." to ".date("d-M-Y",strtotime($tndate)); ?></p> <p>Daily Collection Report- SCHOOL FEE</p>	</h5></center>
			<table class="table" cellspacing="0" cellpadding="0" border="1" id="tblData">
				<thead>
				<tr style="cursor:pointer">
                	<td>S.No</td>
					<th>Student Name</th>
                    <th>Father Name</th>
                    <th>Admission no</th>
					<th>Class</th>
					<th><div style="width:70px">Branch</div></th>
                    <th>user</th>
                    <th>Student Type</th>
                    <th>Receipt No</th>
                    <th>Payment Mode</th>
                    <th>Month</th>
					<th>Tution Fee</th>
					<th>Transport fee</th>
					<!--<th>Hostel Fee</th>-->
				   <?php
				   if(is_array($aryFeeType) && count($aryFeeType)>0){
					foreach($aryFeeType as $ftype){
						?><th><?php echo $ftype["type"] ?></th><?php
					}
				   }
				   ?>
				   <th>Term Fee/other</th>
				   <th>Fine</th>
				   <th>Extra</th> 
                   <th>Income</th> 
				   <th>Total</th>
				</tr>
				</thead>
				<tbody>
					<?php $s=0;
					foreach($aryStudentList as $s_id){

						$rdate7=date("Y-m-d",strtotime($fdate));
						$sdate7=date("Y-m-d",strtotime($tdate));

						$ref7=$db->getRows("select * from reff_receipt where date > '$rdate7' and date < '$sdate7' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and idno='".$s_id[idno]."' $whereUser");

						$rids7=array();$rrmonth7=array();
						foreach($ref7 as $rr7){
                            $rids7[]= $rr7['id'];
                        }

						$recno7 = implode(",",$rids7);
//  print_r($recno7); 
                        if($_GET['head_name']!=""){
    						$rdate5=date("Y-m-d",strtotime($fdate));
    						$sdate5=date("Y-m-d",strtotime($tdate));
    						$ref5=$db->getRows("select * from reff_receipt where date > '$rdate5' and date < '$sdate5' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and idno='".$s_id[idno]."' $whereUser");

    									$rids5=array();$rrmonth5=array();
    									$rrde5=$db->getRows("select * from receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' $whereUser");

									if(is_array($rrde5) && count($rrde5)>0){
										foreach($rrde5 as $rr){
    											$rl_rrid5=explode("-",$rr["rrid"]);
    										foreach($ref5 as $reff){
    											foreach($rl_rrid5 as $rrids){
    											if($rrids==$reff["id"]){
    													$r5=$rr['id'];
    													if(!($r5==$ridss)) {
    													$ridss5=$r5;
    													$rrmonth5[]=$rr['Months'];
    													$rids5[]=$ridss5;}
    												}
    											}
    										}
    									}
    								}
    									$recno5 = implode(",",$rids5);
    					    $m5 = $db->getVal("select id from receipt where id in ($recno5) and payment_mode='$_GET[head_name]' ");
                        } else { $m5 = 1; }


						$loc=$db->getRow("select idno from student where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' and session='".$_SESSION["admin"]["session"]."'  and issue_TC=0  $whereLocation");

				// 		if(!empty($loc)){

					    if($m5 > 0){

                        $whereclass = '';
					    if($_GET['class']!=""){
					        $whereclass = " class='$_GET[class]' and ";
					    }

						$fStudent=$db->getRow("select idno, name,fname,admissionno,class,location from student where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' and (status=1  or status=3)   and issue_TC=0");

                        if(count($fStudent) > 1){

				// 		$fStudent=$db->getRow("select idno, name,fname,stype,section,admissionno,class,location from student where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' and session='".$_SESSION["admin"]["session"]."'    and issue_TC=0");
				// 		$fStudent=$db->getRow("select idno, name,fname,admissionno,class,location from student where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' and (status=1 or status=3)   and issue_TC=0");

						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;

                        $where_pay_mode = '';
                    	if($_GET['head_name']!=""){
                    	   // $where_pay_mode = " payment_mode='$_GET[head_name]' and ";
                    	   $where_pay_mode = " pay_type='$_GET[head_name]' and ";
                    	}

						$rdate=date("Y-m-d",strtotime($fdate));
						$sdate=date("Y-m-d",strtotime($tdate));


						// Tution
						$tution=$db->getVal("select sum(amount) from reff_receipt where $where_pay_mode idno='".$s_id[idno]."' and type='fee' and (date between '$fdate' and '$tdate')  and session='".$_SESSION["admin"]["session"]."' ");
							if(!empty($tution)){
							$overAlltution+=$tution;
							$total+=$tution;
							}
                        
                        // Transport
						$trasnport=$db->getVal("select sum(amount) from reff_receipt where $where_pay_mode idno='".$s_id[idno]."' and type='busfee' and (date between '$fdate' and '$tdate')  and session='".$_SESSION["admin"]["session"]."' ");
							if(!empty($trasnport)){
							$overAllTransport+=$trasnport;
							$total+=$trasnport;
							}

                        // Extra fee structure
						$extrasum=array();
						if(is_array($aryFeeType) && count($aryFeeType)>0){
							foreach($aryFeeType as $ftype){  
								$sums=0;
								$Ftypeid=$db->getVal("select id from extrafee_type where type='".$ftype["type"]."' and class='".$fStudent["class"]."'");

								if($Ftypeid) { //echo $Ftypeid;
								$sums=$db->getVal("select sum(amount) from reff_receipt where $where_pay_mode idno='".$s_id[idno]."' and type='extrafee".$Ftypeid."' and (date between '$fdate' and '$tdate') ");
								}
								$extrasum[]=$sums;
								$total+=$sums;$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
							}
						}


						// other
				// 		echo "select sum(amount) from reff_receipt where $where_pay_mode idno='".$s_id[idno]."' and (date between '$fdate' and '$tdate') and (type NOT like 'fee') and  (type NOT like 'busfee') and  (type NOT like '%extrafee%') and session='".$_SESSION["admin"]["session"]."' ";
						$otherExtra=$db->getVal("select sum(amount) from reff_receipt where $where_pay_mode idno='".$s_id[idno]."' and (date between '$fdate' and '$tdate') and (type NOT like 'fee') and  (type NOT like 'busfee') and  (type NOT like '%extrafee%') and session='".$_SESSION["admin"]["session"]."' ");
							if(!empty($otherExtra)){
							$overAllOther+=$otherExtra;
							$total+=$otherExtra;
							}

						$fine=(float)$db->getVal("select sum(fine) from installment_fine where (ins_name like '%-class' or ins_name like '%-hostel' or ins_name like '%-bus' or ins_name like '%-extra%') and (udate between '$fdate' and '$tdate') and idno='".$s_id[idno]."'");
						$total+=$fine;
						$overAllFine+=$fine;

					//  $newExtra=(float)$db->getVal("select sum(fine) from installment_fine where (ins_name like '%-other') and (udate between '$fdate' and '$tdate') and idno='".$s_id[idno]."'");
//						$newExtra=(float)$db->getVal("select sum(fine) from installment_fine where (ins_name like '%-other') and (reasion NOT like '%Admission_Fee')  and (reasion NOT like '%Computer_Science_lab') and  (reasion NOT like 'Annual_fee') and (reasion NOT like 'A.D.F') and (reasion NOT like 'Exam_Fee')   and (udate between '$fdate' and '$tdate') and idno='".$s_id[idno]."' $whereUser");
						$temptotal = 0;

						$ref=$db->getRows("select * from reff_receipt where $where_pay_mode date > '$rdate' and date < '$sdate' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and idno='".$s_id[idno]."' $whereUser");

                        $where_pay_mode1 = '';
                    	if($_GET['head_name']!=""){
                    	    $where_pay_mode1 = " payment_mode='$_GET[head_name]' and ";
                    	   //$where_pay_mode = " pay_type='$_GET[head_name]' and ";
                    	}

									$rids=array();$rrmonth=array(); 

									$rrde=$db->getRows("select * from receipt where $where_pay_mode1 session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' and rrid in($recno7) $whereUser");
   
									if(is_array($rrde) && count($rrde)>0){
										foreach($rrde as $rr){
                                            $temptotal += $rr['amount'];
    										array_push($ptotal, $rr['amount']);
										    $usr11 = $db->getVal("select name from users where id='$s_id[added_by]'"); 
                                            array_push($pusers, $usr11);

											$rl_rrid=explode("-",$rr["rrid"]);
											//print_r($rl_rrid);exit;
										foreach($ref as $reff){
											foreach($rl_rrid as $rrids){
											//echo $rrids;exit;
											if($rrids==$reff["id"]){
													$r=$rr['id'];
													if(!($r==$ridss)) {
													$ridss=$r;
													$rrmonth[]=$rr['Months'];
													$rids[]=$ridss;}
												}
											}
										}
										
									}
								}
								// else {
								//     array_push($ptotal, 0);
								// }    
									$recno= implode(",",$rids);
				// 		$total+=$newExtra;
				// 		$overAllNewextra+=$newExtra;
						$fmonths="";$monthname1="";$monthname=array();
						$fmonths=implode(",",$rrmonth);
					$im=explode(",",$fmonths);
					$mn=array_unique($im);$months="";
					if(is_array($mn) && count($mn)){
						foreach($mn as $ipi){					
							if($ipi!=""){
								if($months!="")$months.=",";
								if($ipi<=9){
									$newDate=date("Y")."-".($ipi+3)."-1";
									$months.= date("M",strtotime($newDate));//."(".($ij+3).")";
								}
								else{
									$newDate=date("Y")."-".($ipi-9)."-1";
									$months.= date("M",strtotime($newDate));//."(".($ij-9).")";
								}
							}
						}
					}

						//echo $db->getErMsg();

						if($total > 0){ $s++;

						?>
						<tr>
                        	<td><?php echo $s; ?></td>
							<td><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"] ?>-<?php echo $fStudent["section"] ?></td>
							<td><?php if($_GET["location"]=="")echo $db->getVal("select name from location where id='".$fStudent["location"]."' and school_id='".$_SESSION["admin"]["school_id"]."'"); 
							else echo $db->getVal("select name from location where id='".$_GET["location"]."' and school_id='".$_SESSION["admin"]["school_id"]."'");//date("d-M-y",strtotime($fdate));//" to ".date("d/m/y",strtotime($tdate)); ?></td>
							
                            <td><?php echo $usr1 = $db->getVal("select name from users where id='$s_id[added_by]'"); 
                                // array_push($pusers, $usr1); 
                                if(in_array($usr1, $tempuser)){
                                 
                                } else { 
                                    array_push($tempuser,$usr1);  
                                }
                            ?></td>
                             <td><?php echo $fStudent["stype"] ?></td>
                            <td><?php echo $recno; ?></td>
                             <td><?php 
                                if(!empty($recno)){
        							$m4 = $db->getRows("select payment_mode from receipt where id in ($recno)  ");
        							foreach($m4 as $m44){
        							   $m = $m44['payment_mode']; 
        							   echo $m.", ";
        							   $pm = $m;
           							 array_push($pmode, $m44['payment_mode']);
           							 
       				                         if(in_array($pm, $temp)){
                
                                            } else {
                                                array_push($temp,$pm);
                                            }
        							}
    
    							} else { $m='';
    							    echo 'Cash';
    							    $pm = 'Cash';
    							    array_push($pmode, $pm);
    
                                    if(in_array($pm, $temp)){
    
                                } else {
                                    array_push($temp,$pm);
                                }
    
    							}

							?></td>
                            <td><?php echo $months; ?></td>
							<td><?php echo $tution; ?></td>
							<td><?php echo $trasnport ?></td>

							<?php for($ij=0; $ij<count($aryFeeType); $ij++){ ?><td><?php echo $extrasum[$ij]; ?></td><?php } ?>
						   <td><?php echo $otherExtra; $overAllOther2+=$otherExtra; ?> </td>
						   <td><?php echo $fine; ?></td>
						   <td><?php echo $newExtra; ?></td>
                           <td>0</td>
						   
                           <td><?php echo $total; $overAllTotal+=$total; //$total;$overAllTotal+=$total;  ?></td>
						</tr>
						<?php
						}
						}
					}
					}
					?>

				</tbody>
				<tfoot>
					<td colspan="11">Gross Total</td>
					<td><?php echo $overAlltution ?></td>
					<td><?php echo $overAllTransport ?></td>
					<!--<td><?php echo $overAllhotel ?></td>-->
					<?php
					if(is_array($overAllextra) && count($overAllextra)>0){
						foreach($overAllextra as $ftype){
							?><td><?php echo $ftype ?></td><?php
						}
					   }?>
				   <td><?php echo $overAllOther2 ?></td>
				   <td><?php echo $overAllFine ?></td>
				   <td><?php echo $overAllNewextra ?></td>
                   <td><?php echo $overAllTot; ?></td>
				   <td id="completeFeeShw"><?php echo $overAllTotal; ?></td>
				</tfoot>
			</table>  
            <!--Print Date : <?php echo date('d-M-Y'); ?>-->
			<?php
		}else{
			echo "No record found<br />".$db->getErMsg();
		}
		
			if(isset($_GET["fyear"]) && trim($_GET["fyear"])!="" && isset($_GET["fmonth"]) && trim($_GET["fmonth"])!="" && isset($_GET["fdate"]) && trim($_GET["fdate"])!="" && isset($_GET["tyear"]) && trim($_GET["tyear"])!="" && isset($_GET["tmonth"]) && trim($_GET["tmonth"])!="" && isset($_GET["tdate"]) && trim($_GET["tdate"])!=""){
			$fdate=$_GET["fyear"]."/".$_GET["fmonth"]."/".$_GET["fdate"];
			$tdate=$_GET["tyear"]."/".$_GET["tmonth"]."/".$_GET["tdate"];
			$where[]=" (udate between '$fdate' and '$tdate') ";
		}

		$student=$db->getRows("Select * from enquiry where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 order by name");

			$tndate = date('Y/m/d', strtotime('-1 days',strtotime($tdate))); 
			?>
            <p>Daily Registration Report</p>
            	<table class="table tableSummery" style="text-align:center">
                    <thead>
                        <tr>
                            <th>S.No</th> 
                            <th>Name</th>
                            <th>Father Name</th>
                            <th>User</th>
                            <th>Date</th>
                            <th>Payment Mode</th>
                            <th>Class</th>
                            <th>Convenience</th>
                            <th>Receipt No</th>
                            <th>Amount</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $ollTotal=0;$ijk=0; $wherepaymode="";
                    	if($_GET['head_name']!=""){
                    	    $wherepaymode = " payment_mode='$_GET[head_name]' and ";
                    	}
						if(is_array($student) && count($student)>0){
							foreach($student as $s){
								$total=0;$rids=array();	$recno="";
							$table="transaction";
							$result=$db->getRows("SELECT * FROM ".$table." where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and detail like 'Enquiryfee%' and rid='".$s["idno"]."' AND ".implode(" AND ",$where)." group by id order by udate");
                                $user2="";
								if(is_array($result) && count($result)>0)
								{
									foreach($result as $detail)
									{
									    $user2 = $db->getVal("select name from users where id='$detail[added_by]'");
										
										$rrde=$db->getVal("select id from enquiry_receipt where $wherepaymode session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s["idno"]."' and rrid like '%".$detail["id"]."%' and paytype='Enquiry' ");
										if($rrde){
											$rids[]=$rrde;
											$total+=$detail["amount"];
										}
									}
									$ollTotal+=$total; 
									$rids=array_unique($rids);
									$recno= implode(",",$rids);
								}
								if($total>0){ $ijk++;?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo $s["name"]; ?></td>
                                    <td><?php echo $s["fname"]; ?></td>
                                    <td><?php echo $user2; ?></td>
                                    <td><?php echo date("d-m-Y",strtotime($s["udate"])); ?></td>
                                    <td><?php echo $db->getVal("select payment_mode from enquiry_receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s["idno"]."' and rrid like '%".$detail["id"]."%' and paytype='Enquiry' "); ?></td>
                                    <td><?php echo $s["class"]; ?></td>
                                    <td><?php echo $s["discount_mode"]; ?></td>
                                    <td><?php echo $recno; ?></td>
                                    <td><?php echo $total ?></td>
                                   
                                </tr>
								<?php }
							}
						}
			
						?>
                    </tbody>
                    <tfoot>
                    <tr>
                    <td colspan="9">Total</td>
                    <td><?php echo $ollTotal;?></td>
                    </tr>
                  </tfoot>
                 </table>




	    <h5>Counterwise Fees Collection Details</h5>
		<table class="table" style="text-align:center;" border="1">
            <thead>
		    <tr>
		        <th></th>
		        <th>Collected By</th>
		        <?php
		            foreach($temp as $pm1){
		                echo "<th>$pm1</th>";
		            }
		        ?>
		        <th>Total</th>
		    </tr>
		    </thead>
		    <tbody>
		    <?php $totalfeescollected = 0; $registrationtotal = 0;
            $j = 0;
            $valary = array(); 
            $feetotal = 0;
// print_r($ptotal);
// print_r($temp);
// print_r($pmode);
		    foreach($tempuser as $row){ ?> 
		    <tr>
		        <td></td>
		        <td>
		            <?php echo $row; $j++; ?>
		        </td>

		        <?php   $m = 0;
        		        $value = array();
                        $rowtotal = 0;

    		            foreach($pmode as $pt){

                            if($row == $pusers[$m]){
    		                $j = array_search($pt, $temp);
                                $value[$j] += $ptotal[$m];
                                $valary[$j] += $ptotal[$m];
    		                }
    		                $m++;
    		            }

                        $n = 0;
    		            foreach($temp as $vs1){
    		                
    		                if($value[$n]){
    		                echo "<td>$value[$n]</td>";
    		                $rowtotal += $value[$n];
    		                } else echo "<td>0</td>";
    		                $n++;
    		            }
		        ?>
		        <td><?php echo $rowtotal; ?></td>
		    </tr>
		    <?php } ?>
		    </tbody>
		    
		    <tfoot>
		        <tr>
		            <td>Total</td>
		            <td></td>
                    <?php $nm = 0;
		            foreach($temp as $vs1){
		                echo "<td>$valary[$nm]</td>";
		                $feetotal += $valary[$nm];
		                $nm++;
		            }	?>
		            <td><?php echo $feetotal; ?></td>
		        </tr>
		    </tfoot>
		</table>

	    <h5>Counterwise Registration Collection Details</h5>
        <?php   
                        $wherepaymode1="";
                    	if($_GET['head_name']!=""){
                    	    $wherepaymode1 = " where payment_mode='$_GET[head_name]' ";
                    	}
        
                $enquiry = $db->getRows("SELECT DISTINCT(payment_mode) FROM enquiry_receipt $wherepaymode1 ");
                $allusers = $db->getRows("SELECT DISTINCT(added_by) FROM enquiry_receipt  where session='".$_SESSION["admin"]["session"]."' AND ".implode(" AND ",$where)." ");
                
		if(isset($_GET["fyear"]) && trim($_GET["fyear"])!="" && isset($_GET["fmonth"]) && trim($_GET["fmonth"])!="" && isset($_GET["fdate"]) && trim($_GET["fdate"])!="" && isset($_GET["tyear"]) && trim($_GET["tyear"])!="" && isset($_GET["tmonth"]) && trim($_GET["tmonth"])!="" && isset($_GET["tdate"]) && trim($_GET["tdate"])!=""){
    		$fdate=$_GET["fdate"]."-".$_GET["fmonth"]."-".$_GET["fyear"];
    		$tdate=$_GET["tdate"]."-".$_GET["tmonth"]."-".$_GET["tyear"];
    		$where2[]=" (udate between '$fdate' and '$tdate') ";
    	}
    	$enquirytotal = 0;
        ?>

		<table class="table" style="text-align:center;" border="1">
            <thead>
		    <tr>
		        <th></th>
		        <th>Collected By</th>
		        <?php
		            foreach($enquiry as $pm1){
		                echo "<th>$pm1[payment_mode]</th>";
		            }
		        ?>
		        <th>Total</th>
		    </tr>
		    </thead>
		    <tbody>
		        <?php
		        if(is_array($enquiry) && count($enquiry)>0){
		        foreach($allusers as $user){ ?>
		        <tr>
		            <td></td>
		            <td><?php echo $db->getVal("select name from users where id='$user[added_by]'"); ?></td>
		            <?php foreach($enquiry as $pm2){
						$result2=$db->getVal("SELECT SUM(total) FROM enquiry_receipt where payment_mode='$pm2[payment_mode]' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' AND ".implode(" AND ",$where)." ");
						echo "<td>$result2</td>";
						$enquirytotal += $result2;
		            } 
		            ?>
		            <td><?php echo $enquirytotal; $registrationtotal+=$enquirytotal; ?></td>
		        </tr>
		        <?php } } ?>
		    </tbody>
		</table>

		<br>
		<table class="table" style="text-align:center;" border="1">
		    <tr>
		        <td>Total Fees Collected</td>
		        <td><?php echo $feetotal; ?></td>
		    </tr>
		    <tr>
		        <td>Registration Fees Collected</td>
		        <td><?php echo $registrationtotal; ?></td>
		    </tr>
		    <tr>
		        <td>Grand Total</td>
		        <td><?php echo $totalfeescollected = $feetotal+$registrationtotal; ?></td>
		    </tr>
		</table>
	<br><br>
	<table style="width:100%;">
	    <tr>
	        <td>Signature of Head Accountant</td>
	        <td>Signature of Cashier</td>
	        <td>Signature of Principal/HM</td>
	    </tr>
	</table>
	        <br><br>     
	        
	        <h2>Cancelled Receipt</h2>
	        <table class="table" style="width:100%;"  border="1">
	            <thead>
    	            <tr>
    	                <th>S.No.</th>
    	                <th>Name</th>
    	                <th>Father Name</th>
    	                <th>Class</th>
    	                <th>Receipt No.</th>
    	                <th>Payment Mode</th>
    	                <th>Detail</th>
    	                <th>User</th>
    	                <th>Amount</th>
    	            </tr>
	            </thead>
	            <tbody>

	                <?php $deletereceipt = $db->getRows("select * from delete_report where udate > '$rdate' and udate < '$sdate' and paytype='schoolreceipt' and session='".$_SESSION["admin"]["session"]."' order by id ASC ");
	                        $s = 0;
	                        foreach($deletereceipt as $rec){ $s++;
	                        $stu = $db->getRow("select * from student where idno='$rec[idno]' and session='".$_SESSION["admin"]["session"]."' ");
	                            ?>
	                            <tr>
	                                <td><?php echo $s; ?></td>
	                                <td><?php echo $stu['name']; ?></td>
	                                <td><?php echo $stu['fname']; ?></td>
	                                <td><?php echo $stu['class']; ?></td>
	                                <td><?php echo $rec['receipt_id']; ?></td>
	                                <td><?php echo $rec['payment_mode']; ?></td>
	                                <td><?php
	                                        $detail = json_decode($rec['detail'], true);
	                                        foreach($detail as $key=>$val){
                                                    echo "$key - $val<br>";
	                                        }
	                                    ?>
	                                </td>
	                                <td><?php echo $db->getVal("select name from users where id='$rec[added_by]' "); ?></td>
	                                <td><?php echo $rec['amount']; ?></td>
	                            </tr>
	                            <?php
	                        }
	                ?>
	            </tbody>

	        </table>
	        
	        
            Print Date : <?php echo date('d-M-Y'); ?>

	<br><br>
	
                 <?php
	}
	
	elseif(isset($_REQUEST["hostel_dcr"])){
	    
		$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllHostelOther=$overAllOther=0;$overAllFine=0;$overAllextra=array();$overAllNewextra=0;$overAllTot=0;
		$whereLocation="";
		if(isset($_GET["location"]) && $_GET["location"]!=""){
			$whereLocation=" and location='".$_GET["location"]."' ";
		}		
			if(isset($_GET["user"]) && $_GET["user"]!=""){
			$whereUser=" and added_by='".$_GET["user"]."' ";
		}
			
		$aryStudentList=$db->getRows("SELECT idno FROM `reff_receipt` WHERE  date between '$fdate' and '$tdate' and session='".$_SESSION["admin"]["session"]."' group by idno");
		
		//echo $db->getErMsg().$db->getLastQuery();
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			$tndate = date('Y/m/d', strtotime('-1 days',strtotime($tdate)));
			//echo $tndate." ".$fdate
			?>
            <center><h5><p style="float:right">Collection Date: 
			<?php if(strtotime($tndate)==strtotime($fdate)){
			echo date("d-M-Y",strtotime($tndate));?> - <?php echo date("l",strtotime($tndate));}
			else echo date("d-M-Y",strtotime($fdate)) ." to ".date("d-M-Y",strtotime($tndate)); ?></p> <p>Daily Collection Report- HOSTEL FEE</p>	</h5></center>

			<table class="table" cellspacing="0" cellpadding="0" border="1" id="tblData">
				<thead>
				<tr style="cursor:pointer">
                	<th>S.No</th>
					<th>Student Name</th>
                    <th>Father Name</th>
                    <th>Admission no</th>
					<th>Class</th>
					<th><div style="width:70px">Branch</div></th>
                    <th>Receipt No</th>
                    <th>Month</th>
					<th>Hostel Fee</th>
				    <th>Hostel Other</th>
				    <th>Total</th>
				</tr>
				</thead>
				<tbody>
					<?php $s=0;
					//foreach($aryStudentList as $fStudent){
						
						foreach($aryStudentList as $s_id){
							
						
							$fStudent=$db->getRow("select idno, name,fname,admissionno,class,location from student where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' and session='".$_SESSION["admin"]["session"]."'    and issue_TC=0");
												
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$hotherExtra=$h1otherExtra=$hostelotherExtra=0;$total=0;$fine=0;
						
						/*$installTution=$db->getRows("select ins_name from installment_time where ins_name like 'hp%' and (date between '$fdate' and '$tdate') and idno='".$s_id[idno]."' $whereUser");
						if(is_array($installTution) && count($installTution)>0){
							foreach($installTution as $installT){
								$inst="ip".preg_replace("/hp/","",$installT["ins_name"]);
								$hostel+=$db->getVal("select ".$inst." from hostelinstallment where idno=".$s_id[idno]);
							}
							$overAllhotel+=$hostel;
							$total+=$hostel;
						}*/
						
						$hostel=$db->getVal("select sum(amount) from reff_receipt where idno='".$s_id[idno]."' and type='hostelfee' and (date between '$fdate' and '$tdate') ");
																				
							if(!empty($hostel)){
							$overAllhotel+=$hostel;
							$total+=$hostel;
							}
						
												
						$installOtherExtra=$db->getRows("select ins_name from installment_time where ins_name like 'hostelother%' and (date between '$fdate' and '$tdate') and idno='".$s_id[idno]."' $whereUser");
						if(is_array($installOtherExtra) && count($installOtherExtra)>0){
							foreach($installOtherExtra as $installT){
								//other1_detail
								$idSdetail=str_replace("_detail","",$installT[ins_name]);
								$idSdetail=str_replace("hostelother","",$idSdetail);
								$hotherExtra+=$db->getVal("select fine from installment_fine where ins_name='".$idSdetail."-otherfeehostel' and idno=".$s_id[idno]);          						//echo $db->getLastQuery();
								$h1otherExtra+=$db->getVal("select sum(fine) from installment_fine where ins_name='".$idSdetail."-otherhostel' and idno=".$s_id[idno]);
								//echo $db->getLastQuery();
							}
				// 			echo $hotherExtra; 
							$hostelotherExtra=$hotherExtra+$h1otherExtra;
							$overAllHostelOther+=$hostelotherExtra;
							$total+=$hostelotherExtra;
						}
						$rdate=date("Y-m-d",strtotime($fdate));
						$sdate=date("Y-m-d",strtotime($tdate));
						$ref=$db->getRows("select * from reff_receipt where date > '$rdate' and date < '$sdate' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and idno='".$s_id[idno]."' $whereUser");
									$rids=array();$rrmonth=array();
									$rrde=$db->getRows("select * from hostel_receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' $whereUser");
								
									if(is_array($rrde) && count($rrde)>0){
										foreach($rrde as $rr){
											$rl_rrid=explode("-",$rr["rrid"]);
											//print_r($rl_rrid);exit;
										foreach($ref as $reff){
											foreach($rl_rrid as $rrids){
											//echo $rrids;exit;
											if($rrids==$reff["id"]){
													$r=$rr['id'];
													if(!($r==$ridss)) {
													$ridss=$r;
													$rrmonth[]=$rr['Months'];
													$rids[]=$ridss;}
												}
											}
										}
										
									}
								}    //$recno=$ridss;
									$recno= implode(",",$rids);
						$total+=$newExtra;
						$overAllNewextra+=$newExtra;
						$fmonths="";$monthname1="";$monthname=array();
						$fmonths=implode(",",$rrmonth);
					$im=explode(",",$fmonths);
					$mn=array_unique($im);$months="";
					if(is_array($mn) && count($mn)){
						foreach($mn as $ipi){					
							if($ipi!=""){
								if($months!="")$months.=",";
								if($ipi<=9){
									$newDate=date("Y")."-".($ipi+3)."-1";
									$months.= date("M",strtotime($newDate));//."(".($ij+3).")";
								}
								else{
									$newDate=date("Y")."-".($ipi-9)."-1";
									$months.= date("M",strtotime($newDate));//."(".($ij-9).")";
								}
							}
						}
					}
						$total+=$newExtra;
						$overAllNewextra+=$newExtra;
						//echo $db->getErMsg();
						if($total>0){ $s++;
						?>
						<tr>
                        	<td><?php echo $s; ?></td>
							<td><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"] ?></td>
							<td><?php if($_GET["location"]=="")echo "All";else echo $db->getVal("select name from location where id='".$_GET["location"]."' and school_id='".$_SESSION["admin"]["school_id"]."'");//date("d-M-y",strtotime($fdate));//" to ".date("d/m/y",strtotime($tdate)); ?></td>
                            <td><?php echo $recno; ?></td>
                            <td><?php echo $months; ?></td>
							<td><?php echo $hostel ?></td>
							<td><?php echo $hostelotherExtra; ?></td>
						    <td><?php echo $total; $overAllTotal+=$total; ?></td>
						</tr>
						<?php
						}
					}
					?>
                    
				</tbody>
				<tfoot>
					<td colspan="8">Gross Total</td>
					<td><?php echo $overAllhotel ?></td>
					<td><?php echo $overAllHostelOther ?></td>
				    <td id="completeFeeShw"><?php echo $overAllTotal; ?></td>
				</tfoot>
			</table>  
            Print Date : <?php echo date('d-M-Y'); ?>
			<?php
		}else{
			echo "No record found<br />".$db->getErMsg();
		}
	}

	elseif(isset($_REQUEST["hostel_income"])){
		$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllHostelOther=$overAllOther=0;$overAllFine=0;$overAllextra=array();$overAllNewextra=0;$overAllTot=0;
		$whereLocation="";
		if(isset($_GET["location"]) && $_GET["location"]!=""){
			$whereLocation=" and location='".$_GET["location"]."' ";
		}
		
		
			if(isset($_GET["user"]) && $_GET["user"]!=""){
			$whereUser=" and added_by='".$_GET["user"]."' ";
		}
		
		
		$aryStudentList=$db->getRows("select name,fname,admissionno,idno,class from student where school_id='".$_SESSION["admin"]["school_id"]."'  and status=1 $whereLocation and issue_TC=0");
		//print_r($aryStudentList); 
		//echo $db->getErMsg().$db->getLastQuery();
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			$tndate = date('Y/m/d', strtotime('-1 days',strtotime($tdate)));
			//echo $tndate." ".$fdate
			?>
            <center><h5><p style="float:right">Collection Date: 
			<?php if(strtotime($tndate)==strtotime($fdate)){
			echo date("d-M-Y",strtotime($tndate));?> - <?php echo date("l",strtotime($tndate));}
			else echo date("d-M-Y",strtotime($fdate)) ." to ".date("d-M-Y",strtotime($tndate)); ?></p> <p>Daily Collection Report- POCKET MONEY</p>	</h5></center>

			<table class="table" cellspacing="0" cellpadding="0" border="1" id="tblData">
				<thead>
				<tr style="cursor:pointer">
                	<th>S.No</th>
					<th>Student Name</th>
                    <th>Father Name</th>
                    <th>Admission no</th>
					<th>Class</th>
					<th><div style="width:70px">Branch</div></th>
                    <th>Receipt No</th>
					<th>Hostel Income</th>
				    <th>Total</th>
				</tr>
				</thead>
				<tbody>
					<?php $s=0;
					foreach($aryStudentList as $fStudent){
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$hotherExtra=$h1otherExtra=$hostelotherExtra=0;$total=0;$fine=0;
						
					 $tot=$db->getVal("select sum(amount) from transaction where type='deposit' and (udate between '$fdate' and '$tdate') and tfor='hostel-income' and rid='".$fStudent["idno"]."' and session='".$_SESSION["admin"]["session"]."' $whereUser");
					 $total+=$tot;
					 $overAllhotel+=$tot;
						$rdate=date("Y-m-d",strtotime($fdate));
						$sdate=date("Y-m-d",strtotime($tdate));
						$ref=$db->getRows("select * from transaction where type='deposit' and (udate between '$fdate' and '$tdate') and tfor='hostel-income' and rid='".$fStudent["idno"]."' $whereUser");
									$rids=array();
									$rrde=$db->getRows("select * from pocket_receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$fStudent["idno"]."' $whereUser");
									//echo $db->getLastQuery();
								//print_r($rrde);exit;
									//echo "<pre>";print_r($rrde);echo "</pre>";
									if(is_array($rrde) && count($rrde)>0){
										foreach($rrde as $rr){
											$rl_rrid=explode("-",$rr["rrid"]);
											//print_r($rl_rrid);exit;
										foreach($ref as $reff){
											//echo $reff['id'];exit;
											foreach($rl_rrid as $rrids){
											//echo $rrids;exit;
												if($rrids==$reff["id"]){
													$r=$rr['id'];
													if(!($r==$ridss)) {
													$ridss=$r;;
													$rids[]=$ridss;}
												}
											}
										}
										
									}
								}    //$recno=$ridss;
									$recno= implode(",",$rids);
						
						//echo $db->getErMsg();
						if($total>0){ $s++;
						?>
						<tr>
                        	<td><?php echo $s; ?></td>
							<td><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"] ?></td>
							<td><?php if($_GET["location"]=="")echo "All";else echo $db->getVal("select name from location where id='".$_GET["location"]."' and school_id='".$_SESSION["admin"]["school_id"]."'");//date("d-M-y",strtotime($fdate));//" to ".date("d/m/y",strtotime($tdate)); ?></td>
                            <td><?php echo $recno; ?></td>
							<td><?php echo $tot; ?></td>
							<td><?php echo $total;$overAllTotal+=$total; ?></td>
						</tr>
						<?php
						}
					}
					?>
                    
				</tbody>
				<tfoot>
					<td colspan="7">Gross Total</td>
					<td><?php echo $overAllhotel ?></td>
					<td id="completeFeeShw"><?php echo $overAllTotal; ?></td>
				</tfoot>
			</table>  
            Print Date : <?php echo date('d-M-Y'); ?>
			<?php
		}else{
			echo "No record found<br />".$db->getErMsg();
		}
	}

	elseif(isset($_REQUEST["hostel_expance"])){
		$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllHostelOther=$overAllOther=0;$overAllFine=0;$overAllextra=array();$overAllNewextra=0;$overAllTot=0;
		$whereLocation="";
		if(isset($_GET["location"]) && $_GET["location"]!=""){
			$whereLocation=" and location='".$_GET["location"]."' ";
		}
		
			if(isset($_GET["user"]) && $_GET["user"]!=""){
			$whereUser=" and added_by='".$_GET["user"]."' ";
		}
		
		
		$aryStudentList=$db->getRows("select name,fname,admissionno,idno,class from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 $whereLocation and issue_TC=0");
		
		//echo $db->getErMsg().$db->getLastQuery();
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			$tndate = date('Y/m/d', strtotime('-1 days',strtotime($tdate)));
			//echo $tndate." ".$fdate
			?>
            <center><h5><p style="float:right">Collection Date: 
			<?php if(strtotime($tndate)==strtotime($fdate)){
			echo date("d-M-Y",strtotime($tndate));?> - <?php echo date("l",strtotime($tndate));}
			else echo date("d-M-Y", strtotime($fdate)) ." to ".date("d-M-Y",strtotime($tndate)); ?></p> <p>Daily Collection Report- POCKET EXPENSE</p>	</h5></center>


			<table class="table" cellspacing="0" cellpadding="0" border="1" id="tblData">
				<thead>
				<tr style="cursor:pointer">
                	<th>S.No</th>
					<th>Student Name</th>
                    <th>Father Name</th>
                    <th>Admission no</th>
					<th>Class</th>
					<th><div style="width:70px">Branch</div></th>
                    <th>Receipt No</th>
					<th>Hostel Income</th>
				    <th>Total</th>
				</tr>
				</thead>
				<tbody>
					<?php $s=0;
					foreach($aryStudentList as $fStudent){
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$hotherExtra=$h1otherExtra=$hostelotherExtra=0;$total=0;$fine=0;
						
					 $tot=$db->getVal("select sum(amount) from transaction where type='withdraw' and (udate between '$fdate' and '$tdate') and tfor='hostel-expance' and rid='".$fStudent["idno"]."' $whereUser");
					 $total+=$tot;
					 $overAllhotel+=$tot;
						$rdate=date("Y-m-d",strtotime($fdate));
						$sdate=date("Y-m-d",strtotime($tdate));
						$ref=$db->getRows("select * from transaction where type='withdraw' and (udate between '$fdate' and '$tdate') and tfor='hostel-expance' and rid='".$fStudent["idno"]."' $whereUser");
									$rids=array();
									$rrde=$db->getRows("select * from pocket_receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$fStudent["idno"]."' $whereUser");
									//echo $db->getLastQuery();
								//print_r($rrde);exit;
									//echo "<pre>";print_r($rrde);echo "</pre>";
									if(is_array($rrde) && count($rrde)>0){
										foreach($rrde as $rr){
											$rl_rrid=explode("-",$rr["rrid"]);
											//print_r($rl_rrid);exit;
										foreach($ref as $reff){
											//echo $reff['id'];exit;
											foreach($rl_rrid as $rrids){
											//echo $rrids;exit;
												if($rrids==$reff["id"]){
													$r=$rr['id'];
													if(!($r==$ridss)) {
													$ridss=$r;;
													$rids[]=$ridss;}
												}
											}
										}
										
									}
								}    //$recno=$ridss;
									$recno= implode(",",$rids);
						
						//echo $db->getErMsg();
						if($total>0){ $s++;
						?>
						<tr>
                        	<td><?php echo $s; ?></td>
							<td><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"] ?></td>
							<td><?php if($_GET["location"]=="")echo "All";else echo $db->getVal("select name from location where id='".$_GET["location"]."' and school_id='".$_SESSION["admin"]["school_id"]."'");//date("d-M-y",strtotime($fdate));//" to ".date("d/m/y",strtotime($tdate)); ?></td>
                            <td><?php echo $recno; ?></td>
							<td><?php echo $tot; ?></td>
							<td><?php echo $total;$overAllTotal+=$total; ?></td>
						</tr>
						<?php
						}
					}
					?>
                    
				</tbody>
				<tfoot>
					<td colspan="7">Gross Total</td>
					<td><?php echo $overAllhotel ?></td>
					<td id="completeFeeShw"><?php echo $overAllTotal; ?></td>
				</tfoot>
			</table>  
            Print Date : <?php echo date('d-M-Y'); ?>
			<?php
		}else{
			echo "No record found<br />".$db->getErMsg();
		}
	}

    elseif(isset($_REQUEST["inventory"])){

		$overAllTotal=0;

		$inventoryReceipt = $db->getRows("SELECT *, r.id as rid,i.name as item FROM inventory_receipt r left join inventory i on r.inventory_id=i.id WHERE r.school_id='".$_SESSION["admin"]["school_id"]."' and issue_date between '$fdate' and '$tdate'");
// 		echo $db->getErMsg().$db->getLastQuery();
		if(is_array($inventoryReceipt) && count($inventoryReceipt)>0){
			$tndate = date('Y/m/d', strtotime('-1 days',strtotime($tdate)));

			?>
            <center><h5><p style="float:right">Collection Date: 
			<?php if(strtotime($tndate)==strtotime($fdate)){
			echo date("d-M-Y",strtotime($tndate));?> - <?php echo date("l",strtotime($tndate));}
			else echo date("d-M-Y",strtotime($fdate)) ." to ".date("d-M-Y",strtotime($tndate)); ?></p> <p>Inventory Collection Report</p>	</h5></center>


			<table class="table" cellspacing="0" cellpadding="0" border="1" id="tblData">
				<thead>
				<tr style="cursor:pointer">
                	<th>S.No</th>
					<th>Student Name</th>
                    <th>Father Name</th>
                    <th>Admission no</th>
					<th>Class</th>
					<th>Item</th>
					<th>Quantity</th>
                    <th>Amount</th>
                    <th>Issue Date</th>
				</tr>
				</thead>
				<tbody>
					<?php $s=1;
						foreach($inventoryReceipt as $inv){
							$student=$db->getRow("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$inv[idno]."' and session='".$_SESSION["admin"]["session"]."' and issue_TC=0");
                            ?>						
						<tr>
                        	<td><?php echo $s; ?></td>
							<td><?php echo $student["name"] ?></td>
                            <td><?php echo $student["fname"] ?></td>
                            <td><?php echo $student["admissionno"] ?></td>
							<td><?php echo $student["class"] ?>-<?php echo $student["section"] ?></td>
                            <td><?php echo $inv["item"] ?></td>
                            <td><?php echo $inv["num_item"]; ?></td>
                            <td><?php echo $inv["total_amount"]; $overAllTotal+=$inv["total_amount"]; ?></td>
							<td><?php echo date("d-m-Y",strtotime($inv['issue_date'])); ?></td>
						</tr>
						<?php
						$s++;
						}
					?>
				</tbody>
				
				<tfoot>
					<tr>
					    <td colspan="7">Total</td>
					    <td><? echo $overAllTotal; ?></td>
					    <td></td>
					</tr>
				</tfoot>
			</table>  
            Print Date : <?php echo date('d-M-Y'); ?>
			<?php
		}else{
			echo "No record found<br />".$db->getErMsg();
		}
}
	
	elseif(isset($_REQUEST["search_head_fee"])){

	$pmode  = array();
	$ptotal = array();
	$pusers = array();
    $temp   = array();
    $tempuser = array();		    
    $feeheadary = array();
    
    $tempfeeary = array();
    
    	$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllFine=0;$overAllextra=array();$overAllNewextra=0;$overAllTot=0;
		$whereLocation=""; $overAllOtherAry = array();
		if(isset($_GET["location"]) && $_GET["location"]!=""){
			$whereLocation=" and location='".$_GET["location"]."' ";
		}

		if(isset($_GET["user"]) && $_GET["user"]!=""){
			$whereUser=" and added_by='".$_GET["user"]."' ";
		}

		$aryFeeType=$db->getRows("select distinct(type) from extrafee_type where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 order by type");

		$aryStudentList=$db->getRows("SELECT idno, added_by FROM `reff_receipt` WHERE  date between '$fdate' and '$tdate' group by idno");

		$id_exist=$db->getRows("select idno from student where class not in ('PNUR','NUR','LKG','UKG') and session='".$_SESSION["admin"]["session"]."' and school_id='".
		$_SESSION["admin"]["school_id"]."'");

		 foreach($id_exist as $id_ex){
			 $id_array[]= $id_ex[idno];
		 }

		$id_exist_general=$db->getRows("select idno from student where (section in ('e') and class in ('iv','v')) or (section in ('f') and class in ('vi','vii','viii')) or (section in ('g') and class in ('vii','viii','ix','x')) or (section in ('h') and class in ('ix'))  and session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."'");

		 foreach($id_exist_general as $id_exist_gen){
			 $id_gen[]= $id_exist_gen[idno];
		 }

		 $id_array=array_diff($id_array, $id_gen);

        $feehead = $db->getRows("SELECT DISTINCT name FROM `otherfee_structure` WHERE ( otype='' OR otype='new' or otype='old') and session='".$_SESSION["admin"]["session"]."' ");

        $extrafeetype = $db->getRows("select distinct(type) from extrafee_type where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'  order by type");

		//echo $db->getErMsg().$db->getLastQuery();
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			$tndate = date('Y/m/d', strtotime('-1 days',strtotime($tdate)));
			//echo $tndate." ".$fdate
			?>
            <center><h5><p style="float:right">Collection Date: 
			<?php if(strtotime($tndate)==strtotime($fdate)){
			echo date("d-M-Y",strtotime($tndate));?> - <?php echo date("l",strtotime($tndate));}
			else echo date("d-M-Y",strtotime($fdate)) ." to ".date("d-M-Y",strtotime($tndate)); ?></p> <p>Daily Collection Report- SCHOOL FEE</p><strong>YEAR</strong> : <?php echo $_SESSION["admin"]["session"]." - <b>".ucwords($db->getVal("Select name from users where id='".$_SESSION["admin"]["uid"]."'"))."</b>"; ?>	</h5></center>

			<table class="table" cellspacing="0" cellpadding="0" border="1" id="tblData">
				<thead>
				<tr style="cursor:pointer">
                	<td>S.No</td>
					<th>Student Name</th>
                    <th>Father Name</th>
                    <th>Admission no</th>
					<td>Class</th>
					
					<th><div style="width:70px">Branch</div></th>
					<th>Txn date</th>
					<th>User</th>
                    <th>Date</th>
                    <td>Receipt No</td>
                    <td>Payment Mode</td>
                    <td>Month</td>

                    <?php 
                        if($_GET['head_type']==""){
                            echo "<th>Tution</th> <th>Transport</th>";
                            foreach($feehead as $cls){
                                $feeheadary[]= " ( type NOT like '%$cls[name]' )";
                                echo "<th>$cls[name]</th>";
                            }
                            foreach($extrafeetype as $feetype){
                                echo "<th>$feetype[type]</th>";
                            }
                            echo "<th>Fee/other</th>";
                            echo "<th>Total</th>";
                        } else {
                    echo "<th>$_GET[head_type]</th>";
                    }
                    ?>



				</tr>
				</thead>
				<tbody>
					<?php $s=0;
						$rdate=date("Y-m-d",strtotime($fdate));
						$sdate=date("Y-m-d",strtotime($tdate));

                        foreach($feehead as $cls){
                            $tempfeeary[]= $cls[name];
                        }

					foreach($aryStudentList as $s_id){

						$rdate7=date("Y-m-d",strtotime($fdate));
						$sdate7=date("Y-m-d",strtotime($tdate));

						$ref7=$db->getRows("select * from reff_receipt where date > '$rdate7' and date < '$sdate7' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and idno='".$s_id[idno]."' $whereUser");

						$rids7=array();$rrmonth7=array();
						foreach($ref7 as $rr7){
                            $rids7[]= $rr7['id'];
                        }

						$recno7 = implode(",",$rids7);
						
                        if($_GET['head_name']!=""){
    						$rdate5=date("Y-m-d",strtotime($fdate));
    						$sdate5=date("Y-m-d",strtotime($tdate));
    						$ref5=$db->getRows("select * from reff_receipt where date > '$rdate5' and date < '$sdate5' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and idno='".$s_id[idno]."' $whereUser");

    									$rids5=array();$rrmonth5=array();
    									$rrde5=$db->getRows("select * from receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' $whereUser");

									if(is_array($rrde5) && count($rrde5)>0){
										foreach($rrde5 as $rr){
    											$rl_rrid5=explode("-",$rr["rrid"]);
    										foreach($ref5 as $reff){
    											foreach($rl_rrid5 as $rrids){
    											if($rrids==$reff["id"]){
    													$r5=$rr['id'];
    													if(!($r5==$ridss)) {
    													$ridss5=$r5;
    													$rrmonth5[]=$rr['Months'];
    													$rids5[]=$ridss5;}
    												}
    											}
    										}
    									}
    								}
    									$recno5 = implode(",",$rids5);
    					    $m5 = $db->getVal("select id from receipt where id in ($recno5) and payment_mode='$_GET[head_name]' ");
                        } else { $m5 = 1; }

					    if($m5 > 0){
							$d=$s_id[idno];

                        $whereclass = '';
					    if($_GET['class']!=""){
					        $whereclass = " class='$_GET[class]' and ";
					    }

						$fStudent=$db->getRow("select idno, name,fname,admissionno,class,location from student where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' and (status=1  or status=3)   and issue_TC=0");

                        if(count($fStudent) > 1){

                            foreach($extrafeetype as $feetype){
							$Ftypeid=$db->getVal("select id from extrafee_type where type='".$feetype["type"]."' and class='".$fStudent["class"]."' ");
                                $feeheadary[]=" ( type NOT like '%extrafee".$Ftypeid."' )";
                            }

						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$another=0;
    				            $otherarray = array(); $extraarray = array();
    				            $otherExtra_head = 0; 

                        $where_pay_mode = '';
                    	if($_GET['head_name']!=""){
                    	   // $where_pay_mode = " payment_mode='$_GET[head_name]' and ";
	                       	   $where_pay_mode = " pay_type='$_GET[head_name]' and ";
                    	}

						$rdate=date("Y-m-d",strtotime($fdate));
						$sdate=date("Y-m-d",strtotime($tdate));
                     $wherereason = '';
                        if($_GET['head_type']==""){

                        // Tution
						$tution=$db->getVal("select sum(amount) from reff_receipt where $where_pay_mode idno='".$s_id[idno]."' and type='fee' and (date between '$fdate' and '$tdate')  and session='".$_SESSION["admin"]["session"]."' ");
							if(!empty($tution)){
							$overAlltution+=$tution;
							$total+=$tution;
							}

                            // Transport
    						$trasnport=$db->getVal("select sum(amount) from reff_receipt where $where_pay_mode idno='".$s_id[idno]."' and type='busfee' and (date between '$fdate' and '$tdate')  and session='".$_SESSION["admin"]["session"]."' ");
							if(!empty($trasnport)){
							$overAllTransport+=$trasnport;
							$total+=$trasnport;
							}

                            // Other fee structure
                            //     foreach($feehead as $fh){
                            //          $singleother = 0;
                            //         $wherereason = " (type like '$fh[name]') ";
                            //         $allotherextra = $db->getRows("select * from reff_receipt where $where_pay_mode date > '$rdate' and date < '$sdate'  and $wherereason and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'  and idno='".$s_id[idno]."' $whereUser");
                            //         if(count($allotherextra)>0){
                            //         foreach($allotherextra as $other){
            				            // $rrid = $other['id'];
                				        //     $test = $db->getVal("select sum(amount) from receipt where $where_pay_mode  session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' and rrid like '%$rrid%' $whereUser");
                				        //     if($test > 0){
                				        //         $another+=$other['amount'];
                				        //         $singleother+=$other['amount'];
                				        //     } else {
                				        //         $singleother+= 0;
                				        //     }
                            //             }
                            //         } else {
                            //             $singleother+= 0; 
                            //         }
                            //       $otherarray[]=$singleother;
                            //     }
                            //     $total+=$another;

                                    foreach($feehead as $fh){
                                    $singleother = 0;
                                    $wherereason = " (type like '$fh[name]') ";
                                    $otherExtra=$db->getVal("select sum(amount) from reff_receipt where $where_pay_mode idno='".$s_id[idno]."' and (date between '$fdate' and '$tdate') and $wherereason and session='".$_SESSION["admin"]["session"]."' ");
            							if(!empty($otherExtra)){
                							$overAllOther+=$otherExtra;
                							$another+=$otherExtra;
                							$singleother+=$otherExtra;
            							} else {
            							    $singleother+= 0;
            							}
                                        $otherarray[]=$singleother;

                                }
                                $total+=$another;
                            

                                // Extra fee structure
        						$extrasum=array();
        						if(is_array($aryFeeType) && count($aryFeeType)>0){
        							foreach($aryFeeType as $ftype){  
        								$sums=0;
        								$Ftypeid=$db->getVal("select id from extrafee_type where type='".$ftype["type"]."' and class='".$fStudent["class"]."'");
        								if($Ftypeid) {
        								$sums=$db->getVal("select sum(amount) from reff_receipt where $where_pay_mode idno='".$s_id[idno]."' and type='extrafee".$Ftypeid."' and (date between '$fdate' and '$tdate') ");
        								}
        								$extrasum[]=$sums;
        								$total+=$sums;
        								$tp=$ftype["type"];
        								$overAllextra[$tp]+=$sums;
        							}
        						}

                                // Fee/other
        						$otherExtra=$db->getVal("select sum(amount) from reff_receipt where $where_pay_mode idno='".$s_id[idno]."' and (date between '$fdate' and '$tdate') and (type NOT like 'fee') and  (type NOT like 'busfee') AND ".implode(" AND ",$feeheadary)." and session='".$_SESSION["admin"]["session"]."' ");
        							if(!empty($otherExtra)){
        							$overAllOther+=$otherExtra;
        							$total+=$otherExtra;
        							}

                        }

                        elseif($_GET['head_type']=="Tuition"){

    						$tution=$db->getVal("select sum(amount) from reff_receipt where $where_pay_mode idno='".$s_id[idno]."' and type='fee' and (date between '$fdate' and '$tdate')  and session='".$_SESSION["admin"]["session"]."' ");
    							if(!empty($tution)){
    							$overAlltution+=$tution;
    							$total+=$tution;
    							}
    							
                        }

                        elseif($_GET['head_type']=="Transport"){
        						$trasnport=$db->getVal("select sum(amount) from reff_receipt where $where_pay_mode idno='".$s_id[idno]."' and type='busfee' and (date between '$fdate' and '$tdate')  and session='".$_SESSION["admin"]["session"]."' ");
    							if(!empty($trasnport)){
    							$overAllTransport+=$trasnport;
    							$total+=$trasnport;
    							}
                            }

                        elseif($_GET['head_type']=="Fee/other"){
                                // Fee/other
        				        // $allotherextra = $db->getRows("select * from reff_receipt where date > '$rdate' and date < '$sdate'  and (type NOT like 'fee') and  (type NOT like '%busfee') AND ".implode(" AND ",$feeheadary)." and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'  and idno='".$s_id[idno]."' $whereUser");
        				        // foreach($allotherextra as $other){
        				        //     $rrid = $other['id'];
        				        //     $test = $db->getVal("select sum(amount) from receipt where $where_pay_mode  session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' and rrid like '%$rrid%' $whereUser");
        				        //     if($test > 0){
                    //                     $otherExtra+= $other['amount'];
            				    //         $overAllOther+=$other['amount'];
        				        //     }
        				        // }
                    //             $total+=$otherExtra;
                    
        						$otherExtra=$db->getVal("select sum(amount) from reff_receipt where $where_pay_mode idno='".$s_id[idno]."' and (date between '$fdate' and '$tdate') and (type NOT like 'fee') and  (type NOT like 'busfee') AND ".implode(" AND ",$feeheadary)." and session='".$_SESSION["admin"]["session"]."' ");
        							if(!empty($otherExtra)){
        							$overAllOther+=$otherExtra;
        							$total+=$otherExtra;
        							}
                        }

                        else {

                            $wherereason = '';
        					if(in_array("$_GET[head_type]", $tempfeeary))
                            {
                              $wherereason = " type= '$_GET[head_type]'  ";
                            }
                            else
                            {
								$Ftypeid1=$db->getVal("select id from extrafee_type where type='".$_GET["head_type"]."' and class='".$fStudent["class"]."'");
								$wherereason = " type = 'extrafee".$Ftypeid1."'  ";
                            }

                            // $wherereason = " (reasion like '$_GET[head_type]') ";

    				// 		$otherExtra_head=$db->getVal("select sum(fine) from installment_fine where $wherereason and (udate between '$fdate' and '$tdate') and idno='".$s_id[idno]."' $whereUser");
    				// 		$overAllOther_head+=$otherExtra_head;
    				// 		$total+=$otherExtra_head;

		        				$otherExtra_head = 0;
                                $otherExtra=$db->getVal("select sum(amount) from reff_receipt where $where_pay_mode idno='".$s_id[idno]."' and (date between '$fdate' and '$tdate') and $wherereason and session='".$_SESSION["admin"]["session"]."' ");
            							if(!empty($otherExtra)){
                							$otherExtra_head+=$otherExtra;
                							$overAllOther_head+=$otherExtra;
            							}
        				        // $allcomputer = $db->getRows("select * from reff_receipt where date > '$rdate' and date < '$sdate' and $wherereason and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'  and idno='".$s_id[idno]."' $whereUser");
        				        // foreach($allcomputer as $computer){
        				        //     $rrid = $computer['id'];
        				        //     $test = $db->getVal("select sum(amount) from receipt where $where_pay_mode  session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' and rrid like '%$rrid%' $whereUser");
        				        //     if($test > 0){
                    //                     $otherExtra_head+= $computer['amount'];
            				    //         $overAllOther_head+=$computer['amount'];
        				        //     }
        				        // }
                                $total+=$otherExtra_head;
    				
                        }

                        $wherereason1 = '';
                        if($_GET['head_type']==""){
                            $wherereason1 = "";
                        }
                        elseif($_GET['head_type']=="Tuition"){
                            $wherereason1 = " type= 'fee' and ";
                        }
                        elseif($_GET['head_type']=="Transport"){
                            $wherereason1 = " type= 'busfee' and";
                        }
                        elseif($_GET['head_type']=="Fee/other"){
                            $wherereason1 = " (type NOT like 'fee') and  (type NOT like '%busfee') AND ".implode(" AND ",$feeheadary)." and ";
                        }
                        else{
        					if(in_array("$_GET[head_type]", $tempfeeary))
                            {
                              $wherereason1 = " type= '$_GET[head_type]' and ";
                            }
                            else
                            {
								$Ftypeid1=$db->getVal("select id from extrafee_type where type='".$_GET["head_type"]."' and class='".$fStudent["class"]."'");
								$wherereason1 = " type = 'extrafee".$Ftypeid1."' and ";
                            }
                        }

                        $temptotal = 0;

						$ref=$db->getRows("select * from reff_receipt where $where_pay_mode date > '$rdate' and date < '$sdate' and $wherereason1 school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and idno='".$s_id[idno]."' $whereUser");
									$rids=array();$rrmonth=array();

			                        $where_pay_mode1 = '';
                                    	if($_GET['head_name']!=""){
                                    	    $where_pay_mode1 = " payment_mode='$_GET[head_name]' and ";
                                    	   //$where_pay_mode = " pay_type='$_GET[head_name]' and ";
                                    	}

									//$rrde=$db->getRows("select * from receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' $whereUser");
            						$rrde=$db->getRows("select * from receipt where $where_pay_mode1 session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' and rrid in($recno7) $whereUser");		
									if(is_array($rrde) && count($rrde)>0){ 
										foreach($rrde as $rr){
										    $temptotal+= $rr['amount'];
										    array_push($ptotal, $rr['amount']);
										    $usr11 = $db->getVal("select name from users where id='$s_id[added_by]'");
										    array_push($pusers, $usr11);
											$rl_rrid=explode("-",$rr["rrid"]);
											//print_r($rl_rrid);exit;
										foreach($ref as $reff){
											foreach($rl_rrid as $rrids){
											//echo $rrids;exit;
											if($rrids==$reff["id"]){
													$r=$rr['id'];
													if(!($r==$ridss)) {
													$ridss=$r;
													$rrmonth[]=$rr['Months'];
													$rids[]=$ridss;}
												}
											}
										}
										
									}
								}
								// else {
								//     array_push($ptotal, 0);
								// }
									$recno= implode(",",$rids);


				// 		$total+=$newExtra;
				// 		$overAllNewextra+=$newExtra;
						$fmonths="";$monthname1="";$monthname=array();
						$fmonths=implode(",",$rrmonth);
					$im=explode(",",$fmonths);
					$mn=array_unique($im);$months="";
					if(is_array($mn) && count($mn)){
						foreach($mn as $ipi){					
							if($ipi!=""){
								if($months!="")$months.=",";
								if($ipi<=9){
									$newDate=date("Y")."-".($ipi+3)."-1";
									$months.= date("M",strtotime($newDate));//."(".($ij+3).")";
								}
								else{
									$newDate=date("Y")."-".($ipi-9)."-1"; 
									$months.= date("M",strtotime($newDate));//."(".($ij-9).")";
								}
							}
						}
					}



						if($total>0){ $s++;
						?>
						<tr>
                        	<td><?php echo $s; ?></td>
							<td><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"]."-"; echo $fStudent["section"] ?></td>

							<td><?php echo $db->getVal("select txnid from receipt where id in ($recno) "); ?></td>
							<td><?php echo $db->getVal("select tdate from receipt where id in ($recno) "); ?></td>
                            <td>
                                <?php echo $usr1 = $db->getVal("select name from users where id='$s_id[added_by]'"); 
                                // array_push($pusers, $usr1); 
                                if(in_array($usr1, $tempuser)){
                                 
                                } else {
                                    array_push($tempuser,$usr1);  
                                }
                                ?>
                            </td>
                            <td><?php echo date('d-m-Y'); ?></td>
                            <td><?php echo $recno; ?></td>
                            <td><?php
                                if(!empty($recno)){
    							$m4 = $db->getRows("select payment_mode from receipt where id in ($recno)");
    							foreach($m4 as $m44){
    							   $m = $m44['payment_mode']; 
    							   echo $m.", ";
    							   $pm = $m;
       							 array_push($pmode, $m44['payment_mode']);
       							 
   				                         if(in_array($pm, $temp)){
            
                                        } else {
                                            array_push($temp,$pm);
                                        }
        							}
    
    							} else { $m='';
    							    echo 'Cash';
    							    $pm = 'Cash';
    							    array_push($pmode, $pm);
    
                                    if(in_array($pm, $temp)){
    
                                    } else {
                                        array_push($temp,$pm);
                                    }
    
    							}
							?>
							</td>
                            <td><?php echo $months; ?></td>

                                     <?php 
                                        if($_GET['head_type']==""){
                                            echo "<td>$tution</td>";
                                            echo "<td>$trasnport</td>";
                                            $ik=0;
                                            foreach($otherarray as $val){
                                                echo "<td>$val</td>";
                                                $overAllOtherAry[$ik]+=$val;
                                                $ik++;
                                            }
                                            
                                            for($ij=0; $ij<count($aryFeeType); $ij++){ ?><td><?php echo $extrasum[$ij]; ?></td><?php } 
                                            
                                            echo "<td>$otherExtra</td>";
                                            // echo "<td>$temptotal</td>"; 
                                            // $overAllTotal+=$temptotal;
                                            echo "<td>$total</td>";
                                            $overAllTotal+=$total;
                                        }
                                        elseif($_GET['head_type']=="Tuition"){
                                            echo "<td>$tution</td>";
                                        }
                                        elseif($_GET['head_type']=="Transport"){
                                            echo "<td>$trasnport</td>";
                                        } 
                                        elseif($_GET['head_type']=="Fee/other"){
                                            echo "<td>$otherExtra</td>";
                                        }
                                        else {
                                            echo "<td>$otherExtra_head</td>";
                                        }
                                        ?>

						</tr>
						<?php
						}
                        }
					}
					}
					?>

				</tbody>
				<tfoot>
					<td colspan="12">Gross Total</td>

                    <?php   if($_GET['head_type']==""){
                                echo "<td>$overAlltution</td>";
                                echo "<td>$overAllTransport</td>";
                                $ik=0;
                                foreach($overAllOtherAry as $otherfee){
                                    echo "<td>$otherfee</td>";
                                }
                                
                                if(is_array($overAllextra) && count($overAllextra)>0){
            						foreach($overAllextra as $ftype){
            							?><td><?php echo $ftype ?></td><?php
            						}
        					    }
                                echo "<td>$overAllOther</td>";
                                echo "<td>$overAllTotal</td>";
                            }
                            elseif($_GET['head_type']=="Tuition"){
                                echo "<td>$overAlltution</td>";
                            }
                            elseif($_GET['head_type']=="Transport"){
                                echo "<td>$overAllTransport</td>";
                            } 
                            elseif($_GET['head_type']=="Fee/other"){
                                echo "<td>$overAllOther</td>";
                            }
                            else{
                                echo "<td>$overAllOther_head</td>"; 
                            }

                    ?>
                    
				   <!--<td id="completeFeeShw"><?php //echo $overAllTotal; ?> </td>-->
				</tfoot>
			</table>  
            <!--Print Date : <?php echo date('d-M-Y'); ?>-->
			<?php
		}else{
			echo "No record found<br />".$db->getErMsg();
		}
        
        if($_GET['head_type']==""){
        		
		// Registration Report
		if(isset($_GET["fyear"]) && trim($_GET["fyear"])!="" && isset($_GET["fmonth"]) && trim($_GET["fmonth"])!="" && isset($_GET["fdate"]) && trim($_GET["fdate"])!="" && isset($_GET["tyear"]) && trim($_GET["tyear"])!="" && isset($_GET["tmonth"]) && trim($_GET["tmonth"])!="" && isset($_GET["tdate"]) && trim($_GET["tdate"])!=""){
			$fdate=$_GET["fyear"]."/".$_GET["fmonth"]."/".$_GET["fdate"];
			$tdate=$_GET["tyear"]."/".$_GET["tmonth"]."/".$_GET["tdate"];
			$where[]=" (udate between '$fdate' and '$tdate') ";
		}

		$student=$db->getRows("Select * from enquiry where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 order by name");

			$tndate = date('Y/m/d', strtotime('-1 days',strtotime($tdate))); 
			?>
            <p>Daily Registration Report</p>
            	<table class="table tableSummery" style="text-align:center">
                    <thead>
                        <tr>
                            <th>S.No</th> 
                            <th>Name</th>
                            <th>Father Name</th>
                            <th>User</th>
                            <th>Date</th>
                            <th>Payment Mode</th>
                            <th>Class</th>
                            <th>Convenience</th>
                            <th>Receipt No</th>
                            <th>Amount</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $ollTotal=0;$ijk=0; $wherepaymode="";
                    	if($_GET['head_name']!=""){
                    	    $wherepaymode = " payment_mode='$_GET[head_name]' and ";
                    	}
						if(is_array($student) && count($student)>0){
							foreach($student as $s){
								$total=0;$rids=array();	$recno="";
							$table="transaction";
							$result=$db->getRows("SELECT * FROM ".$table." where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and detail like 'Enquiryfee%' and rid='".$s["idno"]."' AND ".implode(" AND ",$where)." group by id order by udate");
                                $user2="";
								if(is_array($result) && count($result)>0)
								{
									foreach($result as $detail)
									{
									    $user2 = $db->getVal("select name from users where id='$detail[added_by]'");
										
										$rrde=$db->getVal("select id from enquiry_receipt where $wherepaymode session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s["idno"]."' and rrid like '%".$detail["id"]."%' and paytype='Enquiry' ");
										if($rrde){
											$rids[]=$rrde;
											$total+=$detail["amount"];
										}
									}
									$ollTotal+=$total; 
									$rids=array_unique($rids);
									$recno= implode(",",$rids);
								}
								if($total>0){ $ijk++;?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo $s["name"]; ?></td>
                                    <td><?php echo $s["fname"]; ?></td>
                                    <td><?php echo $user2; ?></td>
                                    <td><?php echo date("d-m-Y",strtotime($s["udate"])); ?></td>
                                    <td><?php echo $db->getVal("select payment_mode from enquiry_receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s["idno"]."' and rrid like '%".$detail["id"]."%' and paytype='Enquiry' "); ?></td>
                                    <td><?php echo $s["class"]; ?></td>
                                    <td><?php echo $s["discount_mode"]; ?></td>
                                    <td><?php echo $recno; ?></td>
                                    <td><?php echo $total ?></td>
                                   
                                </tr>
								<?php }
							}
						}
			
						?>
                    </tbody>
                    <tfoot>
                    <tr>
                    <td colspan="9">Total</td>
                    <td><?php echo $ollTotal;?></td>
                    </tr>
                  </tfoot>
                 </table>


 	    <h5>Counterwise Fees Collection Details</h5>
		<table class="table" style="text-align:center;" border="1">
            <thead>
		    <tr>
		        <th></th>
		        <th>Collected By</th>
		        <?php
		            foreach($temp as $pm1){
		                echo "<th>$pm1</th>";
		            }
		        ?>
		        <th>Total</th>
		    </tr>
		    </thead>
		    <tbody>
		    <?php $totalfeescollected = 0; $registrationtotal = 0;
            $j = 0;
            $valary = array(); 
            $feetotal = 0;

		    foreach($tempuser as $row){ ?> 
		    <tr>
		        <td></td>
		        <td>
		            <?php echo $row; $j++; ?>
		        </td>

		        <?php   $m = 0;
        		        $value = array();
                        $rowtotal = 0;

    		            foreach($pmode as $pt){

                            if($row == $pusers[$m]){
    		                $j = array_search($pt, $temp);
                                $value[$j] += $ptotal[$m];
                                $valary[$j] += $ptotal[$m];
    		                }
    		                $m++;
    		            }

                        $n = 0;
    		            foreach($temp as $vs1){
    		                
    		                if($value[$n]){
    		                echo "<td>$value[$n]</td>";
    		                $rowtotal += $value[$n];
    		                } else echo "<td>0</td>";
    		                $n++;
    		            }
		        ?>
		        <td><?php echo $rowtotal; ?></td>
		    </tr>
		    <?php } ?>
		    </tbody>
		    
		    <tfoot>
		        <tr>
		            <td>Total</td>
		            <td></td>
                    <?php $nm = 0;
		            foreach($temp as $vs1){
		                echo "<td>$valary[$nm]</td>";
		                $feetotal += $valary[$nm];
		                $nm++;
		            }	?>
		            <td><?php echo $feetotal; ?></td>
		        </tr>
		    </tfoot>
		</table>


	    <h5>Counterwise Registration Collection Details</h5>
        <?php   
                        $wherepaymode1="";
                    	if($_GET['head_name']!=""){
                    	    $wherepaymode1 = " where payment_mode='$_GET[head_name]' ";
                    	}
        
                $enquiry = $db->getRows("SELECT DISTINCT(payment_mode) FROM enquiry_receipt $wherepaymode1 ");
                $allusers = $db->getRows("SELECT DISTINCT(added_by) FROM enquiry_receipt where session='".$_SESSION["admin"]["session"]."' AND ".implode(" AND ",$where)."");
                
		if(isset($_GET["fyear"]) && trim($_GET["fyear"])!="" && isset($_GET["fmonth"]) && trim($_GET["fmonth"])!="" && isset($_GET["fdate"]) && trim($_GET["fdate"])!="" && isset($_GET["tyear"]) && trim($_GET["tyear"])!="" && isset($_GET["tmonth"]) && trim($_GET["tmonth"])!="" && isset($_GET["tdate"]) && trim($_GET["tdate"])!=""){
    		$fdate=$_GET["fdate"]."-".$_GET["fmonth"]."-".$_GET["fyear"];
    		$tdate=$_GET["tdate"]."-".$_GET["tmonth"]."-".$_GET["tyear"];
    		$where2[]=" (udate between '$fdate' and '$tdate') ";
    	}
    	$enquirytotal = 0;
        ?>

		<table class="table" style="text-align:center;" border="1">
            <thead>
		    <tr>
		        <th></th>
		        <th>Collected By</th>
		        <?php
		            foreach($enquiry as $pm1){
		                echo "<th>$pm1[payment_mode]</th>";
		            }
		        ?>
		        <th>Total</th>
		    </tr>
		    </thead>
		    <tbody>
		        <?php
                if(is_array($enquiry) && count($enquiry)>0){
		        foreach($allusers as $user){ ?>
		        <tr>
		            <td></td>
		            <td><?php echo $db->getVal("select name from users where id='$user[added_by]'"); ?></td>
		            <?php foreach($enquiry as $pm2){
						$result2=$db->getVal("SELECT SUM(total) FROM enquiry_receipt where payment_mode='$pm2[payment_mode]' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' AND ".implode(" AND ",$where)." ");
						echo "<td>$result2</td>";
						$enquirytotal += $result2;
		            } 
		            ?>
		            <td><?php echo $enquirytotal; $registrationtotal+=$enquirytotal; ?></td>
		        </tr>
		        <?php } } ?>
		    </tbody>
		</table>
	
		<br>
		<table class="table" style="text-align:center;" border="1">
		    <tr>
		        <td>Total Fees Collected</td>
		        <td><?php echo $feetotal; ?></td>
		    </tr>
		    <tr>
		        <td>Registration Fees Collected</td>
		        <td><?php echo $registrationtotal; ?></td>
		    </tr>
		    <tr>
		        <td>Grand Total</td>
		        <td><?php echo $totalfeescollected = $feetotal+$registrationtotal; ?></td>
		    </tr>
		</table>
	<br><br>
	<table style="width:100%;">
	    <tr>
	        <td>Signature of Head Accountant</td>
	        <td>Signature of Cashier</td>
	        <td>Signature of Principal/HM</td>
	    </tr>
	</table>
	        <br><br>

	        <h2>Cancelled Receipt</h2>
	        <table class="table" style="width:100%;" border="1">
	            <thead>
    	            <tr>
    	                <th>S.No.</th>
    	                <th>Name</th>
    	                <th>Father Name</th>
    	                <th>Class</th>
    	                <th>Receipt No.</th>
    	                <th>Payment Mode</th>
    	                <th>Detail</th>
    	                <th>User</th>
    	                <th>Amount</th>
    	            </tr>
	            </thead>
	            <tbody>

	                <?php $deletereceipt = $db->getRows("select * from delete_report where udate > '$rdate' and udate < '$sdate' and paytype='schoolreceipt' and session='".$_SESSION["admin"]["session"]."' order by id ASC ");
	                        $s = 0;
	                        foreach($deletereceipt as $rec){ $s++;
	                        $stu = $db->getRow("select * from student where idno='$rec[idno]' and session='".$_SESSION["admin"]["session"]."' ");
	                            ?>
	                            <tr>
	                                <td><?php echo $s; ?></td>
	                                <td><?php echo $stu['name']; ?></td>
	                                <td><?php echo $stu['fname']; ?></td>
	                                <td><?php echo $stu['class']; ?></td>
	                                <td><?php echo $rec['receipt_id']; ?></td>
	                                <td><?php echo $rec['payment_mode']; ?></td>
	                                <td><?php
	                                        $detail = json_decode($rec['detail'], true);
	                                        foreach($detail as $key=>$val){
                                                    echo "$key - $val<br>";
	                                        }
	                                    ?>
	                                </td>
	                                <td><?php echo $db->getVal("select name from users where id='$rec[added_by]' "); ?></td>
	                                <td><?php echo $rec['amount']; ?></td>
	                            </tr>
	                            <?php
	                        }
	                ?>
	            </tbody>

	        </table>

	        
            <?php } echo "Print Date : ".date('d-M-Y'); ?>

<?php
}

	elseif(isset($_REQUEST["search_hostel_fee"])){

	$pmode  = array();
	$ptotal = array();
	$pusers = array();
    $temp   = array();
    $tempuser = array();		    
    $feeheadary = array();
    
    $tempfeeary = array();
    
    	$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllFine=0;$overAllextra=array();$overAllNewextra=0;$overAllTot=0;
		$whereLocation=""; $overAllOtherAry = array();
		if(isset($_GET["location"]) && $_GET["location"]!=""){
			$whereLocation=" and location='".$_GET["location"]."' ";
		}

		if(isset($_GET["user"]) && $_GET["user"]!=""){
			$whereUser=" and added_by='".$_GET["user"]."' ";
		}

    $hostelextra = $db->getRows("SELECT DISTINCT name FROM `hostel_otherfee_structure` WHERE ( otype='' OR otype='new' or otype='old') and session='".$_SESSION["admin"]["session"]."' ");

// 		$aryFeeType=$db->getRows("select distinct(type) from extrafee_type where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 order by type");

		$aryStudentList=$db->getRows("SELECT idno, added_by FROM `reff_receipt` WHERE  date between '$fdate' and '$tdate' group by idno");

		if(is_array($aryStudentList) && count($aryStudentList)>0){
			$tndate = date('Y/m/d', strtotime('-1 days',strtotime($tdate)));
			//echo $tndate." ".$fdate
			?>
            <center><h5><p style="float:right">Collection Date: 
			<?php if(strtotime($tndate)==strtotime($fdate)){
			echo date("d-M-Y",strtotime($tndate));?> - <?php echo date("l",strtotime($tndate));}
			else echo date("d-M-Y",strtotime($fdate)) ." to ".date("d-M-Y",strtotime($tndate)); ?></p> <p>Daily Collection Report- SCHOOL FEE</p><strong>YEAR</strong> : <?php echo $_SESSION["admin"]["session"]." - <b>".ucwords($db->getVal("Select name from users where id='".$_SESSION["admin"]["uid"]."'"))."</b>"; ?>	</h5></center>

			<table class="table" cellspacing="0" cellpadding="0" border="1" id="tblData">
				<thead>
				<tr style="cursor:pointer">
                	<td>S.No</td>
					<th>Student Name</th>
                    <th>Father Name</th>
                    <th>Admission no</th>
					<td>Class</th>
					
					<th><div style="width:70px">Branch</div></th>
					<th>Txn date</th>
					<th>User</th>
                    <th>Date</th>
                    <td>Receipt No</td>
                    <td>Payment Mode</td>
                    <td>Month</td>

                    <?php 
                        if($_GET['head_type']==""){
                            echo "<th>Hostel Fee</th>";
                            foreach($hostelextra as $cls){
                                $feeheadary[]= " ( type NOT like '%$cls[name]' )";
                                echo "<th>$cls[name]</th>";
                            }

                            echo "<th>Total</th>";
                        } else {
                    echo "<th>$_GET[head_type]</th>"; 
                    }
                    ?>

				</tr>
				</thead>
				<tbody>
					<?php $s=0;
						$rdate=date("Y-m-d",strtotime($fdate));
						$sdate=date("Y-m-d",strtotime($tdate));

                        foreach($hostelextra as $cls){
                            $tempfeeary[]= $cls[name];
                        }

					foreach($aryStudentList as $s_id){

						$rdate7=date("Y-m-d",strtotime($fdate));
						$sdate7=date("Y-m-d",strtotime($tdate));

						$ref7=$db->getRows("select * from reff_receipt where date > '$rdate7' and date < '$sdate7' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and idno='".$s_id[idno]."' $whereUser");

						$rids7=array();$rrmonth7=array();
						foreach($ref7 as $rr7){
                            $rids7[]= $rr7['id'];
                        }

						$recno7 = implode(",",$rids7);
						
                        if($_GET['head_name']!=""){
    						$rdate5=date("Y-m-d",strtotime($fdate));
    						$sdate5=date("Y-m-d",strtotime($tdate));
    						$ref5=$db->getRows("select * from reff_receipt where date > '$rdate5' and date < '$sdate5' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and idno='".$s_id[idno]."' $whereUser");

									$rids5=array();$rrmonth5=array();
									$rrde5=$db->getRows("select * from hostel_receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' $whereUser");

									if(is_array($rrde5) && count($rrde5)>0){ 
										foreach($rrde5 as $rr){
    											$rl_rrid5=explode("-",$rr["rrid"]);
    										foreach($ref5 as $reff){
    											foreach($rl_rrid5 as $rrids){
    											if($rrids==$reff["id"]){
    													$r5=$rr['id'];
    													if(!($r5==$ridss)) {
    													$ridss5=$r5;
    													$rrmonth5[]=$rr['Months'];
    													$rids5[]=$ridss5;}
    												}
    											}
    										}
    									}
    								}
    									$recno5 = implode(",",$rids5);
    					    $m5 = $db->getVal("select id from hostel_receipt where id in ($recno5) and payment_mode='$_GET[head_name]' ");
                        } else { $m5 = 1; }

					    if($m5 > 0){
							$d=$s_id[idno];

                        $whereclass = '';
					    if($_GET['class']!=""){
					        $whereclass = " class='$_GET[class]' and ";
					    }

						$fStudent=$db->getRow("select idno, name,fname,admissionno,class,location from student where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' and (status=1 or status=3)   and issue_TC=0");

                        if(count($fStudent) > 1){

						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$another=0;
    				            $otherarray = array(); $extraarray = array();
    				            $otherExtra_head = 0; 

                        $where_pay_mode = '';
                    	if($_GET['head_name']!=""){ 
                    	   // $where_pay_mode = " payment_mode='$_GET[head_name]' and ";
                    	   $where_pay_mode = " pay_type='$_GET[head_name]' and ";
                    	}

						$rdate=date("Y-m-d",strtotime($fdate));
						$sdate=date("Y-m-d",strtotime($tdate));
                        $wherereason = '';
                        if($_GET['head_type']==""){

                            // Hostel
            				// $alltution = $db->getRows("select * from reff_receipt where date > '$rdate' and date < '$sdate' and type='hostelfee' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'  and idno='".$s_id[idno]."' $whereUser");
    				        // foreach($alltution as $tut){
    				        //     $rrid = $tut['id'];
    				        //     $test = $db->getVal("select sum(amount) from hostel_receipt where $where_pay_mode  session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' and rrid like '%$rrid%' $whereUser");
    				        //     if($test > 0){
                //                     $tution += $tut['amount'];
        				    //         $overAlltution+= $tut['amount'];
    				        //     }
    				        // }
                //             $total+=$tution;

						$tution=$db->getVal("select sum(amount) from reff_receipt where $where_pay_mode idno='".$s_id[idno]."' and type='hostelfee' and (date between '$fdate' and '$tdate')  and session='".$_SESSION["admin"]["session"]."' ");
							if(!empty($tution)){
							$overAlltution+=$tution;
							$total+=$tution;
							}

                            // Other fee structure

                            //     foreach($hostelextra as $fh){
                            //          $singleother = 0;
                            //         $wherereason = " (type like '$fh[name]') ";
                            //         $allotherextra = $db->getRows("select * from reff_receipt where date > '$rdate' and date < '$sdate'  and $wherereason and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'  and idno='".$s_id[idno]."' $whereUser");

                            //         if(count($allotherextra)>0){
                            //         foreach($allotherextra as $other){
            				            // $rrid = $other['id'];
                				        //     $test = $db->getVal("select sum(amount) from hostel_receipt where $where_pay_mode  session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' and rrid like '%$rrid%' $whereUser");
                				        //     if($test > 0){
                				        //         $another+=$other['amount'];
                				        //         $singleother+=$other['amount'];
                				        //     } else {
                				        //         $singleother+= 0;
                				        //     }
                            //             }
                            //         } else {
                            //             $singleother+= 0; 
                            //         }
                            //       $otherarray[]=$singleother;
                            //     }
                            //     $total+=$another;
                            
                                foreach($hostelextra as $fh){
                                    $singleother = 0;
                                    $wherereason = " (type like '$fh[name]') ";
                                    $otherExtra=$db->getVal("select sum(amount) from reff_receipt where $where_pay_mode idno='".$s_id[idno]."' and (date between '$fdate' and '$tdate') and $wherereason and session='".$_SESSION["admin"]["session"]."' ");
            							if(!empty($otherExtra)){
                							$overAllOther+=$otherExtra;
                							$another+=$otherExtra;
                							$singleother+=$otherExtra;
            							} else {
            							    $singleother+= 0;
            							}
                                        $otherarray[]=$singleother;

                                }
                                $total+=$another;

                        }

                        elseif($_GET['head_type']=="Hostel"){
                            // Hostel
            				// $alltution = $db->getRows("select * from reff_receipt where date > '$rdate' and date < '$sdate' and type='hostelfee' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'  and idno='".$s_id[idno]."' $whereUser");
    				        // foreach($alltution as $tut){
    				        //     $rrid = $tut['id'];
    				        //     $test = $db->getVal("select sum(amount) from hostel_receipt where $where_pay_mode  session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' and rrid like '%$rrid%' $whereUser");
    				        //     if($test > 0){
                //                     $tution += $tut['amount'];
        				    //         $overAlltution+= $tut['amount'];
    				        //     }
    				        // }
                //             $total+=$tution;
                
                	$tution=$db->getVal("select sum(amount) from reff_receipt where $where_pay_mode idno='".$s_id[idno]."' and type='hostelfee' and (date between '$fdate' and '$tdate')  and session='".$_SESSION["admin"]["session"]."' ");
							if(!empty($tution)){
							$overAlltution+=$tution;
							$total+=$tution;
							}
                        }

                        else {

                            $wherereason = '';
        					if(in_array("$_GET[head_type]", $tempfeeary))
                            {
                              $wherereason = " type= '$_GET[head_type]' ";
                            }

		        				$otherExtra_head = 0;
		        				$otherExtra_head = 0;
                                $otherExtra=$db->getVal("select sum(amount) from reff_receipt where $where_pay_mode idno='".$s_id[idno]."' and (date between '$fdate' and '$tdate') and $wherereason and session='".$_SESSION["admin"]["session"]."' ");
        							if(!empty($otherExtra)){
            							$otherExtra_head+=$otherExtra;
            							$overAllOther_head+=$otherExtra;
        							}

        				        // $allcomputer = $db->getRows("select * from reff_receipt where date > '$rdate' and date < '$sdate' and $wherereason and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'  and idno='".$s_id[idno]."' $whereUser");
        				        // foreach($allcomputer as $computer){
        				        //     $rrid = $computer['id'];
        				        //     $test = $db->getVal("select sum(amount) from hostel_receipt where $where_pay_mode  session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' and rrid like '%$rrid%' $whereUser");
        				        //     if($test > 0){
                    //                     $otherExtra_head+= $computer['amount'];
            				    //         $overAllOther_head+=$computer['amount'];
        				        //     }
        				        // }
                                $total+=$otherExtra_head;

                        }

                        $wherereason1 = '';
                        if($_GET['head_type']==""){
                            $wherereason1 = "";
                        }
                        elseif($_GET['head_type']=="Hostel"){
                            $wherereason1 = " type= 'hostelfee' and ";
                        }
                        else{
                             $wherereason1 = " type= '$_GET[head_type]' and ";
                        }

                        $temptotal = 0;
						$ref=$db->getRows("select * from reff_receipt where $where_pay_mode date > '$rdate' and date < '$sdate' and $wherereason1 school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and idno='".$s_id[idno]."' $whereUser");
									$rids=array();$rrmonth=array();
                                    $where_pay_mode1 = '';
                                    	if($_GET['head_name']!=""){
                                    	    $where_pay_mode1 = " payment_mode='$_GET[head_name]' and ";
                                    	   //$where_pay_mode = " pay_type='$_GET[head_name]' and ";
                                    	}
            						$rrde=$db->getRows("select * from hostel_receipt where $where_pay_mode1 session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' and rrid in($recno7) $whereUser");		
									if(is_array($rrde) && count($rrde)>0){ 
										foreach($rrde as $rr){
										    $temptotal+= $rr['amount'];
										    array_push($ptotal, $rr['amount']);
										    $usr11 = $db->getVal("select name from users where id='$s_id[added_by]'");
										    array_push($pusers, $usr11);
											$rl_rrid=explode("-",$rr["rrid"]);
											//print_r($rl_rrid);exit;
										foreach($ref as $reff){
											foreach($rl_rrid as $rrids){
											//echo $rrids;exit;
											if($rrids==$reff["id"]){
													$r=$rr['id'];
													if(!($r==$ridss)) {
													$ridss=$r;
													$rrmonth[]=$rr['Months'];
													$rids[]=$ridss;}
												}
											}
										}
										
									}
								}else {
								    array_push($ptotal, 0);
								}
									$recno= implode(",",$rids);


				// 		$total+=$newExtra;
				// 		$overAllNewextra+=$newExtra;
						$fmonths="";$monthname1="";$monthname=array();
						$fmonths=implode(",",$rrmonth);
					$im=explode(",",$fmonths);
					$mn=array_unique($im);$months="";
					if(is_array($mn) && count($mn)){
						foreach($mn as $ipi){					
							if($ipi!=""){
								if($months!="")$months.=",";
								if($ipi<=9){
									$newDate=date("Y")."-".($ipi+3)."-1";
									$months.= date("M",strtotime($newDate));//."(".($ij+3).")";
								}
								else{
									$newDate=date("Y")."-".($ipi-9)."-1"; 
									$months.= date("M",strtotime($newDate));//."(".($ij-9).")";
								}
							}
						}
					}

						if($total>0){ $s++;
						?>
						<tr>
                        	<td><?php echo $s; ?></td>
							<td><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"]."-"; echo $fStudent["section"] ?></td>

							<td><?php echo $db->getVal("select txnid from hostel_receipt where id in ($recno) "); ?></td>
							<td><?php echo $db->getVal("select tdate from hostel_receipt where id in ($recno) "); ?></td>
                            <td>
                                <?php echo $usr1 = $db->getVal("select name from users where id='$s_id[added_by]'"); 
                                // array_push($pusers, $usr1);
                                if(in_array($usr1, $tempuser)){
                                 
                                } else {
                                    array_push($tempuser,$usr1);  
                                }
                                ?>
                            </td>
                            <td><?php echo date('d-m-Y'); ?></td>
                            <td><?php echo $recno; ?></td>
                            <td><?php
                                if(!empty($recno)){
    							$m4 = $db->getRows("select payment_mode from hostel_receipt where id in ($recno) ");
    							foreach($m4 as $m44){
    							   $m = $m44['payment_mode']; 
    							   echo $m.", ";
    							   $pm = $m;
       							 array_push($pmode, $m44['payment_mode']);
       							 
   				                         if(in_array($pm, $temp)){
            
                                        } else {
                                            array_push($temp,$pm);
                                        }
        							}
    							} else { $m='';
    							    echo 'Cash';
    							    $pm = 'Cash';
    							    array_push($pmode, $pm);
    
                                    if(in_array($pm, $temp)){
    
                                    } else {
                                        array_push($temp,$pm);
                                    }
    							}
							?>
							</td>
                            <td><?php echo $months; ?></td>

                                     <?php 
                                        if($_GET['head_type']==""){
                                            echo "<td>$tution</td>";

                                            $ik=0;
                                            foreach($otherarray as $val){
                                                echo "<td>$val</td>";
                                                $overAllOtherAry[$ik]+=$val;
                                                $ik++;
                                            }

                                            // echo "<td>$temptotal</td>"; 
                                            // $overAllTotal+=$temptotal;
                                            
                                             echo "<td>$total</td>"; 
                                            $overAllTotal+=$total;
                                            
                                        }
                                        elseif($_GET['head_type']=="Hostel"){
                                            echo "<td>$tution</td>";
                                        }

                                        else {
                                            echo "<td>$otherExtra_head</td>";
                                        }
                                        ?>

						</tr>
						<?php
						}
                        }
					}
					}
					?>

				</tbody>
				<tfoot> 
					<td colspan="12">Gross Total</td>

                    <?php   if($_GET['head_type']==""){
                                echo "<td>$overAlltution</td>";
                                $ik=0;
                                foreach($overAllOtherAry as $otherfee){
                                    echo "<td>$otherfee</td>";
                                }
                                echo "<td>$overAllTotal</td>";
                            }
                            elseif($_GET['head_type']=="Hostel"){
                                echo "<td>$overAlltution</td>";
                            }

                            else{
                                echo "<td>$overAllOther_head</td>";
                            }

                    ?>

				   <!--<td id="completeFeeShw"><?php //echo $overAllTotal; ?> </td>-->
				</tfoot>
			</table>  
            <!--Print Date : <?php echo date('d-M-Y'); ?>-->
			<?php
		}else{
			echo "No record found<br />".$db->getErMsg();
		}
        
        if($_GET['head_type']==""){
        		
		// Registration Report
		if(isset($_GET["fyear"]) && trim($_GET["fyear"])!="" && isset($_GET["fmonth"]) && trim($_GET["fmonth"])!="" && isset($_GET["fdate"]) && trim($_GET["fdate"])!="" && isset($_GET["tyear"]) && trim($_GET["tyear"])!="" && isset($_GET["tmonth"]) && trim($_GET["tmonth"])!="" && isset($_GET["tdate"]) && trim($_GET["tdate"])!=""){
			$fdate=$_GET["fyear"]."/".$_GET["fmonth"]."/".$_GET["fdate"];
			$tdate=$_GET["tyear"]."/".$_GET["tmonth"]."/".$_GET["tdate"];
			$where[]=" (udate between '$fdate' and '$tdate') ";
		}

			?>


 	    <h5>Counterwise Fees Collection Details</h5>
		<table class="table" style="text-align:center;" border="1">
            <thead>
		    <tr>
		        <th></th>
		        <th>Collected By</th>
		        <?php
		            foreach($temp as $pm1){
		                echo "<th>$pm1</th>";
		            }
		        ?>
		        <th>Total</th>
		    </tr>
		    </thead>
		    <tbody>
		    <?php $totalfeescollected = 0; $registrationtotal = 0;
            $j = 0;
            $arun = array(); 
            $feetotal = 0;

		    foreach($tempuser as $row){ ?> 
		    <tr>
		        <td></td>
		        <td>
		            <?php echo $row; $j++; ?>
		        </td>

		        <?php   $m = 0;
        		        $value = array();
                        $rowtotal = 0;

    		            foreach($pmode as $pt){

                            if($row == $pusers[$m]){
    		                $j = array_search($pt, $temp);
                                $value[$j] += $ptotal[$m];
                                $arun[$j] += $ptotal[$m];
    		                }
    		                $m++;
    		            }

                        $n = 0;
    		            foreach($temp as $vs1){
    		                
    		                if($value[$n]){
    		                echo "<td>$value[$n]</td>";
    		                $rowtotal += $value[$n];
    		                } else echo "<td>0</td>";
    		                $n++;
    		            }
		        ?>
		        <td><?php echo $rowtotal; ?></td>
		    </tr>
		    <?php } ?>
		    </tbody>
		    
		    <tfoot>
		        <tr>
		            <td>Total</td>
		            <td></td>
                    <?php $nm = 0;
		            foreach($temp as $vs1){
		                echo "<td>$arun[$nm]</td>";
		                $feetotal += $arun[$nm];
		                $nm++;
		            }	?>
		            <td><?php echo $feetotal; ?></td>
		        </tr>
		    </tfoot>
		</table>



		<br>
		<table class="table" style="text-align:center;" border="1">
		    <tr>
		        <td>Total Fees Collected</td>
		        <td><?php echo $feetotal; ?></td>
		    </tr>

		    <tr>
		        <td>Grand Total</td>
		        <td><?php echo $totalfeescollected = $feetotal; ?></td>
		    </tr>
		</table>
	<br><br>
	<table style="width:100%;">
	    <tr>
	        <td>Signature of Head Accountant</td>
	        <td>Signature of Cashier</td>
	        <td>Signature of Principal/HM</td>
	    </tr>
	</table>
	        <br><br>     
	        
	        
        <h2>Cancelled Receipt</h2>
	        <table class="table" style="width:100%;"  border="1">
	            <thead>
    	            <tr>
    	                <th>S.No.</th>
    	                <th>Name</th>
    	                <th>Father Name</th>
    	                <th>Class</th>
    	                <th>Receipt No.</th>
    	                <th>Payment Mode</th>
    	                <th>Detail</th>
    	                <th>User</th>
    	                <th>Amount</th>
    	            </tr>
	            </thead>
	            <tbody>

	                <?php $deletereceipt = $db->getRows("select * from delete_report where udate > '$rdate' and udate < '$sdate' and paytype='hostelreceipt' and session='".$_SESSION["admin"]["session"]."' order by id ASC ");
	                        $s = 0;
	                        foreach($deletereceipt as $rec){ $s++;
	                        $stu = $db->getRow("select * from student where idno='$rec[idno]' and session='".$_SESSION["admin"]["session"]."' ");
	                            ?>
	                            <tr>
	                                <td><?php echo $s; ?></td>
	                                <td><?php echo $stu['name']; ?></td>
	                                <td><?php echo $stu['fname']; ?></td>
	                                <td><?php echo $stu['class']; ?></td>
	                                <td><?php echo $rec['receipt_id']; ?></td>
	                                <td><?php echo $rec['payment_mode']; ?></td>
	                                <td><?php
	                                        $detail = json_decode($rec['detail'], true);
	                                        foreach($detail as $key=>$val){
                                                    echo "$key - $val<br>";
	                                        }
	                                    ?>
	                                </td>
	                                <td><?php echo $db->getVal("select name from users where id='$rec[added_by]' "); ?></td>
	                                <td><?php echo $rec['amount']; ?></td>
	                            </tr>
	                            <?php
	                        }
	                ?>
	            </tbody>

	        </table>

	        
            <?php } echo "Print Date : ".date('d-M-Y'); ?>

<?php
}


?>
</div>

<script>

function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

     document.body.innerHTML = printContents;

     window.print();

     document.body.innerHTML = originalContents;
}

</script>

