<?php 
$pgMod="cancelled_report";
$pgAct="view";
?>
<style>.top-bar-minimize{display:none;}
thead, tfoot {display: table-header-group;}
.top-bar+.well,.accordion .accordion-heading+.accordion-body{display: inline-block !important;width: 100% !important;overflow: inherit !important;} 
.dynamic{display:none} 
table td {
padding: 6px !important;
}
legend{line-height: 16px;font-weight:100;}
</style> 


<script>
$(document).ready(function(){
var rows = $('table.table tr'); 
var Cash = rows.filter('.Cash');
var Cheque = rows.filter('.Cheque');
var NEFT = rows.filter('.NEFT');
var empty = rows.filter('.empty');

$('#Cash').click(function() {
    Cheque.hide();
    NEFT.hide();
    empty.hide();
    Cash.show();
});

$('#Cheque').click(function() {
    Cash.hide();
    NEFT.hide();
    empty.hide();
    Cheque.show();	
});
$('#NEFT').click(function() {
    Cash.hide();
    Cheque.hide();
    empty.hide();
    NEFT.show();
});
$('#showAll').click(function() {
    Cash.show();
    Cheque.show();
    empty.show();
	 NEFT.show();
	
});
});
</script>
<form method="get" action="">
    <input type="hidden" name="src" value="Account" />
    <input type="hidden" name="page_id" value="<?php echo $pgMod; ?>" />
	<div class="row-fluid">
        <div class="span12">
            <div class="well no-padding">
                <div class="controls controls-row">
                    <div class="control-group span4">
                        <label class="control-label" for="class">From Date</label>
                        <div class="controls" style=" margin-left: 81px;  !important;" >
                                  <select class="span3" name="fdate"  id="date" style="width: 65px !important;">
                                    <option value="">Date</option>
                                    <?php
									$ndate=date("d");
									$mdate=date("m");
									$ydate=date("Y");
                                    for($m = 01;$m <= 31; $m++){ 
                                        $selected="";
										if($_GET["fdate"]==$m)
										{
											$selected=" selected ";
										}
										if($ndate==$m)
										{
											$selected=" selected ";
										}
                                        echo "<option $selected value='$m'>$m</option>";
                                    }
                                    ?> 
                                </select>
                                <select class="span5" name="fmonth" id="fmonth" style="width: 90px !important;">
                                    <option value="">Month</option>
                                 <?php
                                    for($m = 1;$m <= 12; $m++){ 
                                        $newDate=date("Y")."-".$m."-1";
                                        $month =  date("F",strtotime($newDate));//."(".($ij+3).")";
                                        //$month =  date("F", mktime(0, 0, 0, $m)); 
                                        $selected="";
                                        if($_GET["fmonth"]==$m)
										{
											$selected=" selected ";
										}
										
										if($mdate==$m)
										{
											$selected=" selected ";
										}
                                        echo "<option $selected value='$m'>$month</option>";
                                    }
                                 ?> 
                                </select>
                                <select class="span4" name="fyear" id="fyear" style="width: 73px !important;">
                                    <option value="">Year</option>
                                    <?php
                                    for($m = 2013;$m <= 2050; $m++){  
                                        $selected="";
                                        if($_GET["fyear"]==$m)
										{	
										$selected=" selected ";
										}										
										if($ydate==$m)
										{	
										$selected=" selected ";
										}
                                        echo "<option $selected value='$m'>$m</option>";
                                    }
                                    ?> 
                                </select>
                            </div>
                    </div>
                    <div class="control-group span4">
                        <label class="control-label" for="medium">To date</label>
                        <div class="controls" style=" margin-left: 81px;  !important;">
                                 <select class="span3" name="tdate" id="tdate" style="width: 65px !important;">
                                    <option value="">Date</option>
                                    <?php
                                    for($m = 01;$m <= 31; $m++){ 
                                         $selected="";
										 if($_GET["tdate"]==$m)
										 {
											 $selected=" selected ";
										 }
										 if($ndate+1==$m)
										{
											$selected=" selected ";
										}
                                        echo "<option $selected value='$m'>$m</option>";
                                    }
                                    ?> 
                                </select>
                                <select class="span5" name="tmonth" id="tmonth" style="width: 90px !important;">
                                    <option value="">Month</option>
                                 <?php
                                    for($m = 1;$m <= 12; $m++){ 
                                        $newDate=date("Y")."-".$m."-1";
                                        $month =  date("F",strtotime($newDate));//."(".($ij+3).")";
                                        //$month =  date("F", mktime(0, 0, 0, $m)); 
                                        $selected="";if($_GET["tmonth"]==$m)
										{
										$selected=" selected ";
										}
										if($mdate==$m)
										{
											$selected=" selected ";
										}
                                        echo "<option $selected value='$m'>$month</option>";
                                    }
                                 ?> 
                                </select>
                                <select class="span4" name="tyear" id="tyear" style="width: 73px !important;">
                                    <option value="">Year</option>
                                    <?php
                                    for($m = 2013;$m <= 2050; $m++){  
                                         $selected="";if($_GET["tyear"]==$m)
										 {	 
										 $selected=" selected ";
										 }
										 if($ydate==$m)
										{
											$selected=" selected ";
										}
                                        echo "<option $selected value='$m'>$m</option>";
                                    }
                                    ?> 
                                </select>
                            </div>
                    </div>
                    <div class="control-group span2">
                    	<select class="span6" name="location" id="location">
                            <option value="">All</option>
                           <?php 
                                $location=$db->getRows("select * from location where school_id='".$_SESSION["admin"]["school_id"]."'");
                                if(is_array($location) && count($location)>0){
                                    foreach($location as $loc){
                                        ?>
                                        <option <?php if($loc["id"]==$_GET["location"])echo 'selected';?> value="<?php echo $loc["id"] ?>">
                                            <?php echo $loc["name"] ?>
                                        </option>
                                        <?php
                                    }
                                }
                            ?>
                        </select>
                    </div>
					
					<!--<div class="control-group span2">
                    	<select class="span9" name="user" id="user">
                            <option value="">All User</option>
                            <?php 
                                $user=$db->getRows("select * from users where school_id='".$_SESSION["admin"]["school_id"]."'");
                                if(is_array($user) && count($user)>0){
                                    foreach($user as $usr){
                                        ?>
                                        <option <?php if($usr["id"]==$_GET["user"])echo 'selected';?> value="<?php echo $usr["id"] ?>">
                                            <?php echo $usr["name"] ?>
                                        </option>
                                        <?php
                                    }
                                }
                            ?>
                        </select>
                    </div>-->
					
					<div class="control-group span2">
					<?php 
                                $user=$db->getRows("select * from users where school_id='".$_SESSION["admin"]["school_id"]."'");
                                if(is_array($user) && count($user)>0){
                                    foreach($user as $usr){
                                        ?>
					<input type="checkbox" name="user1[]" value="<?php echo $usr["id"] ?>"><?php echo $usr["name"] ?>
					<br>
					<?php
                                    }
                                }
                            ?>
					 </div>
					
                    <div class="control-group span10" style="margin-top:-22px; margin-left:2px">
                    <button type="submit" name="school_receipt" class="btn-classic">School Receipt</button>
                    <button type="submit" name="hostel_receipt" class="btn-classic">Hostel Receipt</button>
                    <button type="submit" name="student_inventory" class="btn-classic">Student Inventory Receipt</button>
                    <button type="submit" name="faculty_inventory" class="btn-classic">Hostel Inventory Receipt</button>


                    <br>

                  
                  <br>



                   <button class="btn btn-danger" onclick="exportTableToExcel('tblData', 'Collection Sheet')" style="float:right;margin-top:10px;">Excel</button>
                   
                   <button type="button" onclick="printDiv('printDiv')" class="btn btn-danger" style="float:right;margin:0px 10px 0px 10px;margin-top:10px;">Print</button>
			   
                   <button onclick="SMSComplete('completeFeeShw','DCRSMS')" style="float:right;margin-top:10px;" type="button" class="btn btn-primary">SMS</button>

                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<div id="printDiv">
<?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"];
	if($_GET["fdate"]==7&&$_GET["fmonth"]==14){
		echo "No records available";
	}else{
		
		if(isset($_REQUEST["delete_receipt"])){
		/*	
		$whereLocation="";
		if(isset($_GET["location"]) && $_GET["location"]!=""){
			$whereLocation=" and location='".$_GET["location"]."' ";
		}*/
		//$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 name,fname,admissionno,idno,class,location from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 $whereLocation and issue_TC=0");
		
		
	    $f=date("Y-m-d",strtotime($fdate));
		$t= date("Y-m-d",strtotime($tdate));
		
		  $del_rec=$db->getRows("select * from receipt_delete where school_id='".$_SESSION["admin"]["school_id"]."' and udate between '$f' and '$t'  ");
				
		//print_r($del_rec);
		
		//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</p>	</h5></center>
			<table class="table" cellspacing="0" cellpadding="0" border="1" id="tblData">
				<thead>
				<tr style="cursor:pointer">
                	<td>S.No</td>
					<!--<th>idno </th>-->
					<th>Student Name</th>
                    <th>Father Name</th>
                    <th>Admission no</th>
					<td>Class</th>
				
                    <td>Receipt No</td>
                    <!--<th>udate</th>
                    <th>detail</th> -->
					<td>amount</th>
					
					
				</tr>
				</thead>
				<tbody>
					<?php
						foreach($del_rec as $del_data){ $s++;
						$student_details=$db->getRow("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and idno='$del_data[idno]' and session='".$_SESSION["admin"]["session"]."'  ");
						?>
						<tr>
                        	<td><?php echo $s; ?></td>
							<td><?php echo $student_details[name] ?></td>
							<td><?php echo $student_details[fname] ?></td>
							<td><?php echo $student_details[admissionno] ?></td>
							<td><?php echo $student_details['class'] ?></td>
							<td><?php echo $del_data[id] ?></td>
                           <!-- <td><?php echo $del_data[udate] ?></td>
                            <td><?php echo $del_data[detail]  ?></td> -->
							<td><?php  echo $del_data[amount] ?></td>
							
						</tr>
						<?php } ?>

				</tbody>

			</table>  
            Print Date : <?php echo date('d-M-Y'); ?>
			<?php
		}else{
			echo "No record found<br />".$db->getErMsg();
		}
	}

    elseif(isset($_REQUEST["school_receipt"])){
			$rdate=date("Y-m-d",strtotime($fdate)); 
			$sdate=date("Y-m-d",strtotime($tdate));
     
        $deletereceipt = $db->getRows("select * from delete_report where (udate between '$rdate' and '$sdate') and paytype='schoolreceipt' and session='".$_SESSION["admin"]["session"]."' order by id ASC ");
		if(is_array($deletereceipt) && count($deletereceipt)>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>Deleted School Receipt    </p>	</h5></center>
	        <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 
	                        $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'); ?>
			<?php
		}else{
			echo "No record found<br />".$db->getErMsg();
		}
	
        
    }
    
    elseif(isset($_REQUEST["hostel_receipt"])){

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

        $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 ");
		if(is_array($deletereceipt) && count($deletereceipt)>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>Deleted School Receipt    </p>	</h5></center>
	        <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 
	                        $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'); ?>
			<?php
		}else{
			echo "No record found<br />".$db->getErMsg();
		}
   
    }
	
	
	elseif(isset($_REQUEST["student_inventory"])){

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

        $deletereceipt = $db->getRows("select * from delete_report where udate > '$rdate' and udate < '$sdate' and paytype='studentinventoryreceipt' and session='".$_SESSION["admin"]["session"]."' order by id ASC ");
		if(is_array($deletereceipt) && count($deletereceipt)>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>Deleted School Receipt    </p>	</h5></center>
	        <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 
	                        $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'); ?>
			<?php
		}else{
			echo "No record found<br />".$db->getErMsg();
		}
   
    }
	
	elseif(isset($_REQUEST["faculty_inventory"])){

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

        $deletereceipt = $db->getRows("select * from delete_report where udate > '$rdate' and udate < '$sdate' and paytype='facultyinventoryreceipt' and session='".$_SESSION["admin"]["session"]."' order by id ASC ");
		if(is_array($deletereceipt) && count($deletereceipt)>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>Deleted School Receipt    </p>	</h5></center>
	        <table class="table" style="width:100%;" border="1">
	            <thead>
    	            <tr>
    	                <th>S.No.</th>
    	                <th>Name</th>
    	                <th>Father Name</th>
    	                <th>Department</th>
    	                <th>Mobile No.</th>
    	                <th>Receipt No.</th>
    	                <th>Payment Mode</th>
    	                <!--<th>Detail</th>-->
    	                <th>User</th>
    	                <th>Amount</th>
    	            </tr> 
	            </thead>
	            <tbody>

	                <?php 
	                        $s = 0;
	                        foreach($deletereceipt as $rec){ $s++;
	                        $stu = $db->getRow("select * from staff 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['department']; ?></td>
	                                <td><?php echo $stu['mobile']; ?></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'); ?>
			<?php
		}else{
			echo "No record found<br />".$db->getErMsg();
		}
   
    }
	
	// new code 

	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"]."' ";
		}

            foreach($hostelextra as $cls){
                $hostelfeeheadary[]= " ( type NOT like '%$cls[name]' )";
            }

		$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);
		 	
		//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>

            <a class="btn btn-primary" id="myPrntbtn" href="<?php echo URL_ROOT."print/?page_id=collection_sheet&fdate=$_GET[fdate]&fmonth=$_GET[fmonth]&fyear=$_GET[fyear]&tdate=$_GET[tdate]&tmonth=$_GET[tmonth]&tyear=$_GET[tyear]&location=$_GET[location]&search_head_fee=&head_name=$_GET[head_name]&class=$_GET[class]&head_type=$_GET[head_type]"; ?>" target="_blank" >Full Screen</a>

            <style>
                @media print {
            
                    #myPrntbtn {
                        display :  none;
                    }
            
                }
            </style>

			<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;
                            
                            // echo $overAllOther;

                                // 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  (type NOT like 'hostelfee') AND ".implode(" AND ",$feeheadary)." AND ".implode(" And ", $hostelfeeheadary)." 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["main_account"])){

	$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"]."' ";
		}

		$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);


		if(is_array($aryStudentList) && count($aryStudentList)>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>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>
                    <td>Receipt No</td>
                    <td>Payment Mode</td>
                    <td>Month</td>
					<th>Tution Fee</th>
					<th>Transport fee</th>
				   <?php
				   if(is_array($aryFeeType) && count($aryFeeType)>0){
					foreach($aryFeeType as $ftype){
						?><th><?php echo $ftype["type"] ?></th><?php
					}
				   }
				   ?>
   				   <th>Annual_fee</th>
				   <th>Computer_Science_lab</th>
				   <th>Admission_fee</th>

                   <th>Fee/other</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);

                        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];

				// 		 if(in_array("$d", $id_array)){ 
				// 			$fStudent=$db->getRow("select idno, name,fname,admissionno,class,section,location from student where school_id='".$_SESSION["admin"]["school_id"]."' and idno='$d' and session='".$_SESSION["admin"]["session"]."' and status=1   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   and issue_TC=0");
						 
				// 		print_r($aryStudentList);
						
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=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]."' $whereUser");
				// 		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;
				// 		}

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

						$rdate=date("Y-m-d",strtotime($fdate));
						$sdate=date("Y-m-d",strtotime($tdate));
						
        				$otherExtra_annual = 0;
				        $alltution = $db->getRows("select * from reff_receipt where date > '$rdate' and date < '$sdate' and type='fee' 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 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+=$tution;
				            }
				        }
                        $total+=$overAlltution;
						
				// 		$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]."' $whereUser");
				// 		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;
				// 		}
				

				        $allbus = $db->getRows("select * from reff_receipt where date > '$rdate' and date < '$sdate' and type='busfee' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'  and idno='".$s_id[idno]."' $whereUser");
				        foreach($allbus as $bus){
				            $rrid = $bus['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){
                                $trasnport += $bus['amount'];
    				            $overAllTransport+=$trasnport;
				            }
				        }
                        $total+=$overAllTransport;

						$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]."' $whereUser");$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();
									}
									
								}
								$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]."' $whereUser");
				// 		if(is_array($installOtherExtra) && count($installOtherExtra)>0){
				// 			foreach($installOtherExtra as $installT){
				// 				//other1_detail
				// 				$idSdetail=str_replace("_detail","",$installT['ins_name']);
				// 				$idSdetail=str_replace("other","",$idSdetail);
				// 				$otherExtra+=$db->getVal("select fine from installment_fine where ins_name='".$idSdetail."-otherfee' and (reasion NOT like '%Computer_Science_lab')  and (reasion NOT like '%Admission_fee') and  (reasion NOT like 'Annual_fee') and (udate between '$fdate' and '$tdate') and idno='".$s_id[idno]."' $whereUser");
				// 			}
				// 			$overAllOther+=$otherExtra;
				// 			$total+=$otherExtra;
				// 		}

				        $allotherextra = $db->getRows("select * from reff_receipt where date > '$rdate' and date < '$sdate'  and (type NOT like 'fee') and  (type NOT like '%busfee') and (type NOT like '%Computer_Science_lab')  and (type NOT like '%Admission_fee') and  (type NOT like '%Annual_fee') 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+=$overAllOther;

                        // Annual_fee
				// 		$otherExtra_annual=$db->getVal("select sum(fine) from installment_fine where (reasion like '%Annual_fee') and (udate between '$fdate' and '$tdate') and idno='".$s_id[idno]."' $whereUser");
				// 		$overAllOther_annual+=$otherExtra_annual;
				// 		$total+=$otherExtra_annual;

        				$otherExtra_annual = 0;
				        $allannual = $db->getRows("select * from reff_receipt where date > '$rdate' and date < '$sdate' and type='Annual_fee' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'  and idno='".$s_id[idno]."' $whereUser");
				        foreach($allannual as $annual){
				            $rrid = $annual['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_annual+= $annual['amount'];
    				            $overAllOther_annual+=$annual['amount'];
				            }
				        }
                        $total+=$otherExtra_annual;

                        // Computer_fee
				// 		$otherExtra_computer=$db->getVal("select sum(fine) from installment_fine where (reasion like '%Computer_Science_lab') and (udate between '$fdate' and '$tdate') and idno='".$s_id[idno]."' $whereUser");
				// 		$overAllOther_computer+=$otherExtra_computer;
				// 		$total+=$otherExtra_computer;
        				$otherExtra_computer = 0;
				        $allcomputer = $db->getRows("select * from reff_receipt where date > '$rdate' and date < '$sdate' and type='Computer_Science_lab' 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_computer+= $computer['amount'];
    				            $overAllOther_computer+=$otherExtra_computer;
				            }
				        }
                        $total+=$otherExtra_computer;

                        // Admission_fee
				// 		$otherExtra_admission=$db->getVal("select sum(fine) from installment_fine where (reasion like '%Admission_fee') and (udate between '$fdate' and '$tdate') and idno='".$s_id[idno]."' $whereUser");
				// 		$overAllOther_admission+=$otherExtra_admission;
				// 		$total+=$otherExtra_admission;
        				$otherExtra_admission = 0;
				        $alladmission = $db->getRows("select * from reff_receipt where date > '$rdate' and date < '$sdate' and type='Admission_fee' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'  and idno='".$s_id[idno]."' $whereUser");
				        foreach($alladmission as $admission){
				            $rrid = $admission['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_admission+= $admission['amount'];
    				            $overAllOther_admission+=$otherExtra_admission;
				            }
				        }
                        $total+=$otherExtra_admission;

						$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]."' $whereUser ");
						$total+=$fine;
						$overAllFine+=$fine;

						$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 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 receipt where $where_pay_mode 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"]);

										foreach($ref as $reff){
											foreach($rl_rrid as $rrids){

											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).")";
								}
							}
						}
					}

						if($temptotal>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 if($_GET["location"]=="")echo "All";else echo $db->getVal("select name from location where id='".$_GET["location"]."' and school_id='".$_SESSION["admin"]["school_id"]."'"); ?></td>-->
							<td><?php echo $db->getVal("select txnid from receipt where id in ($recno) order by payment_mode DESC "); ?></td>
							<td><?php echo $db->getVal("select tdate from receipt where id in ($recno) order by payment_mode DESC "); ?></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 $recno; ?></td>
                            <td><?php
                            // echo "select if(payment_mode ='',null, payment_mode) from receipt where id in ($recno) order by payment_mode DESC "
				// 			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; $pm = $m;} else {echo 'Cash'; $pm = 'Cash';}

    //                         array_push($pmode, $pm);

    //                         if(in_array($pm, $temp)){

    //                         } else {
    //                             array_push($temp,$pm);
    //                         }

                            if(!empty($recno)){
    							$m4 = $db->getRows("select payment_mode from receipt where id in ($recno) order by payment_mode DESC ");
    							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_annual; ?></td>
						    <td><?php echo $otherExtra_computer; ?></td>
                			<td><?php echo $otherExtra_admission; ?></td>

                            <td><?php echo $otherExtra; ?> </td>
                            <!--<td><?php echo $fine; ?></td>-->
                            <!--<td><?php echo $newExtra; ?></td>-->

                            <td><?php echo $temptotal; $overAllTotal+=$temptotal; //$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 $overAllOther_annual; ?></td>
   				   <td><?php echo $overAllOther_computer; ?></td>
				   <td><?php echo $overAllOther_admission; ?></td>


				   <td><?php echo $overAllOther ?></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();
		}
		?>

		<?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') ";
		}

		$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;
            $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>


	    <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>     
            Print Date : <?php echo date('d-M-Y'); ?>
		<?php
		
}


    // Hostel dynamic fee
	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"]."' ";
		}

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

            <a class="btn btn-primary" id="myPrntbtn" href="<?php echo URL_ROOT."print/?page_id=collection_sheet&fdate=$_GET[fdate]&fmonth=$_GET[fmonth]&fyear=$_GET[fyear]&tdate=$_GET[tdate]&tmonth=$_GET[tmonth]&tyear=$_GET[tyear]&location=$_GET[location]&search_hostel_fee=&head_name=$_GET[head_name]&class=$_GET[class]&head_type=$_GET[head_type]"; ?>" target="_blank" >Full Screen</a>

            <style>
                @media print {
            
                    #myPrntbtn {
                        display :  none;
                    }
            
                }
            </style>

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

	
	elseif(isset($_GET["outstanding_wt_class"])){ 
		
    $cla= $db->getRows("select class from class" );
	?>
	   
			<div class="row-fluid">
			<?php $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</p>	</h5></center>
			
       
            <div class="well no-padding" id="printDiv1">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>                        
                            <td>Serial No</td>                         
                            <td>Class</td>                  
                            <td>Total Fee</td>
                            <td>Total paid</td>
                             <td>Discount</td>                            
                            <td>Total Left</td>                            
                            <td>DCR</td>
                        </tr>
                    </thead>
                    <tbody>
<?php
$i=0;
	foreach($cla as $cl){$i++;
	    $c= $cl["class"]; 
		
      // dcr 
      $refpay=$db->getVal("SELECT sum(amount) FROM `reff_receipt` WHERE idno in (select idno from student where class='".$c."' and session='".$_SESSION["admin"]["session"]."') and date between '$fdate' and '$tdate' and session='".$_SESSION["admin"]["session"]."'  ");
		 	 
		// tution fee
		$total=$db->getVal("SELECT fee from class where class='".$c."' ");
 	
		$total_student= $db->getVal("SELECT count(idno) FROM student WHERE class='".$c."' AND session='".$_SESSION["admin"]["session"]."' and status='1' ");
				
		$total_tution=$total*$total_student;
		
		// bus fee

		$bus=$db->getVal("select sum(total) from (select student.bus, bus.fee as f, count(student.bus) as bus_count, count(student.bus) *  bus.fee as total FROM student  inner join bus on bus.id=student.bus where student.class='".$c."' and student.bus!='' and student.session='".$_SESSION["admin"]["session"]."' and student.status='1' GROUP BY student.bus) as result");
		
		
		// other fee
		
		$total_other=$db->getVal("SELECT COALESCE(sum(fee),0) as result from otherfee_structure  WHERE class='$c' and otype='' and session='".$_SESSION["admin"]["session"]."' ");
				
		$other_fee_all= $total_student*$total_other;
		
		//new other
		$total_student_new= $db->getVal("SELECT count(idno) FROM student WHERE class='".$c."' and stype='new' AND session='".$_SESSION["admin"]["session"]."' and status='1' ");
		
		$total_other_new=$db->getVal("SELECT COALESCE(sum(fee),0) as result from otherfee_structure  WHERE class='$c' and otype='new'   and session='".$_SESSION["admin"]["session"]."' ");
		
		$other_fee_new= $total_student_new*$total_other_new;
		// old other
		
		$total_student_old= $db->getVal("SELECT count(idno) FROM student WHERE class='".$c."' and stype='old' AND session='".$_SESSION["admin"]["session"]."' and status='1' ");
		 
		$total_other_old=$db->getVal("SELECT COALESCE(sum(fee),0) as result from otherfee_structure  WHERE class='$c' and otype='old'   and session='".$_SESSION["admin"]["session"]."' ");
				
		
				
			$total_other_id=$db->getVal("SELECT COALESCE(sum(fee),0) as result from otherfee_structure  WHERE otype in (select idno from student where class='".$c."'   and session='".$_SESSION["admin"]["session"]."')  and session='".$_SESSION["admin"]["session"]."'  ");
		
		
        $other_fee_old= $total_student_old*$total_other_old;		
		
	    $total_other_fee= $other_fee_all+$other_fee_new+$other_fee_old+$total_other_id;
	 
		
		$total_paid=$db->getVal("SELECT sum(COALESCE(amount,0)) as amt from reff_receipt  WHERE idno IN (SELECT idno FROM student WHERE class='".$c."' AND session='".$_SESSION["admin"]["session"]."'and status='1') ");
		
	

		// discount
		$discount=$db->getVal("SELECT sum(COALESCE(discount,0)+COALESCE(busdiscount,0)) as tution_dis from installment  WHERE idno IN (SELECT idno FROM student WHERE class='".$c."' AND session='".$_SESSION["admin"]["session"]."'and status='1')");
		
		$total_other_discount=$db->getVal("SELECT COALESCE(sum(discount),0) as result from otherfee_discount  WHERE class='$c' and session='".$_SESSION["admin"]["session"]."'");
							
		
		
		$dis=$discount+$total_other_discount;
		$tf=$total_tution+$bus+$total_other_fee-$dis;
		
		$tl=$tf-$total_paid;
		$total_bus=0;			
		  ?>
                            <tr>
							     <td><?= $i;  ?></td>
							     <td><?=  $c; ?></td>
				                 <td><?php echo $tf; $MyTotalFee +=$tf; ?></td>
							     <td><?php  echo $total_paid; $MyTotalpaid+=$total_paid; ?></td>
							     <td><?php echo $dis; $MyDiscount+=$dis;?></td> 
								
								<td> <?php  echo $tl; $MyTotalLeft+=$tl; ?></td>
							    
								 <td><?php echo $refpay; $tref+=$refpay; ?></td>
                            	
							</tr>
	<?php  } ?>						
                    </tbody>
   
                    <tfoot>
                    	<tr style="color: #fff; background:LightGray; font-size:20px" >
                        	<th></th>
                        	<th>Gross Total</th>
                            <th id="MyTotalFee"><?php echo $MyTotalFee?></th>
                            <th id="MyTotalpaid"><?php echo $MyTotalpaid;?></th>
                           <th id="MyDiscount"><?php echo $MyDiscount; ?></th>
                            <th id="MyTotalLeft"><?php echo $MyTotalLeft; ?></th>
                            
							<th><?php echo $tref; ?></th>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          
		<?php
		echo $db->getErMsg();
	}
	
	// new code end
	
	// new code	
	elseif(isset($_GET["outstanding_wt_class_section"])){
 		
      $cla= $db->getRows("select class from class");
	  	  
	?>
	   
			<div class="row-fluid">
			<?php $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</p>	</h5></center>
			
       
            <div class="well no-padding" id="printDiv1">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>                        
                            <td>Serial No</td>                         
                            <td>Class</td>                  
                            <td>Section</td>
                            <td>No of Student</td>  							
                            <td>Tution</td>  							
                            <td>Transport</td>  							
                            <td>Other</td>  							
                            <td>Total Fee</td>
                            <td>Tution paid</td>  							
                            <td>Transport Paid</td>  							
                            <td>Other Paid</td>  							
                            <td>Total paid</td>
                             <td>Discount</td>                            
                            <td>Total Left</td>                            
                            <td>DCR</td>
                        </tr>
                    </thead>
                    <tbody>
<?php
$i=0;$total_tution=0;$total_student=0;$tf=0;
	foreach($cla as $cl){$i++;
	
	    $c= $cl["class"]; 
		 $sec= $db->getRows("select section from student where class='". $c."' and session='".$_SESSION["admin"]["session"]."' group by section");
		 
		 
		 foreach($sec as $sect){
			
			$section=$sect['section'];
			if(!empty($section)){
			 $where_section=" and section='".$section."' ";
			 
			
		//echo '<br>';
		
      // dcr 
      $refpay=$db->getVal("SELECT sum(amount) FROM `reff_receipt` WHERE idno in (select idno from student where class='".$c."' $where_section and session='".$_SESSION["admin"]["session"]."') and date between '$fdate' and '$tdate' and session='".$_SESSION["admin"]["session"]."'  ");
		 	 
		// tution fee
		if($_SESSION["admin"]["session"]=='2018-2019'){
			$total=$db->getVal("SELECT fee from class_old where class='".$c."' ");
			
		}else{
			$total=$db->getVal("SELECT fee from class where class='".$c."' ");
			
		}
			
		$total_student= $db->getVal("SELECT count(idno) FROM student WHERE class='".$c."' $where_section AND session='".$_SESSION["admin"]["session"]."' and status='1' and bpl='0' ");
		
		 $total_tution=$total*$total_student;
		
		// bus fee

		if($_SESSION["admin"]["session"]=='2018-2019'){
			$bus=$db->getVal("select sum(total) from (select student.bus, bus_old.fee as f, count(student.bus) as bus_count, count(student.bus) *  bus_old.fee as total FROM student  inner join bus_old on bus_old.id=student.bus where student.class='".$c."' and student.section='".$section."' and student.bus!='' and student.session='".$_SESSION["admin"]["session"]."' and student.status='1' GROUP BY student.bus) as result");
			
		}else{
			$bus=$db->getVal("select sum(total) from (select student.bus, bus.fee as f, count(student.bus) as bus_count, count(student.bus) *  bus.fee as total FROM student  inner join bus on bus.id=student.bus where student.class='".$c."' and student.section='".$section."' and student.bus!='' and student.session='".$_SESSION["admin"]["session"]."' and student.status='1' GROUP BY student.bus) as result");
			
		}
				
		// other fee
		
		$total_other=$db->getVal("SELECT COALESCE(sum(fee),0) as result from otherfee_structure  WHERE class='$c' and otype='' and session='".$_SESSION["admin"]["session"]."' ");
				
		$other_fee_all= $total_student*$total_other;
		
		//new other
		$total_student_new= $db->getVal("SELECT count(idno) FROM student WHERE class='".$c."' $where_section  and stype='new' AND session='".$_SESSION["admin"]["session"]."' and status='1' ");
		
		$total_other_new=$db->getVal("SELECT COALESCE(sum(fee),0) as result from otherfee_structure  WHERE class='$c' and otype='new'   and session='".$_SESSION["admin"]["session"]."' ");
		
		$other_fee_new= $total_student_new*$total_other_new;
		// old other
		
		$total_student_old= $db->getVal("SELECT count(idno) FROM student WHERE class='".$c."' $where_section and stype='old' AND session='".$_SESSION["admin"]["session"]."' and status='1' ");
		 
		$total_other_old=$db->getVal("SELECT COALESCE(sum(fee),0) as result from otherfee_structure  WHERE class='$c' and otype='old'   and session='".$_SESSION["admin"]["session"]."' ");
				
		$total_other_id=$db->getVal("SELECT COALESCE(sum(fee),0) as result from otherfee_structure  WHERE otype in (select idno from student where class='".$c."' $where_section  and session='".$_SESSION["admin"]["session"]."' and status='1')  and session='".$_SESSION["admin"]["session"]."'  ");
				
				
        $other_fee_old= $total_student_old*$total_other_old;		
		
	    $total_other_fee= $other_fee_all+$other_fee_new+$other_fee_old+$total_other_id;
	   
	


      $total_paid_tution=$db->getVal("SELECT sum(COALESCE(amount,0)) as amt from reff_receipt  WHERE idno IN (SELECT idno FROM student WHERE class='".$c."' $where_section AND session='".$_SESSION["admin"]["session"]."'and status='1') and type='fee' ");
	  
      $total_paid_bus=$db->getVal("SELECT sum(COALESCE(amount,0)) as amt from reff_receipt  WHERE idno IN (SELECT idno FROM student WHERE class='".$c."' $where_section AND session='".$_SESSION["admin"]["session"]."'and status='1') and type='busfee' ");
	  
      $total_paid_other=$db->getVal("SELECT sum(COALESCE(amount,0)) as amt from reff_receipt  WHERE idno IN (SELECT idno FROM student WHERE class='".$c."' $where_section AND session='".$_SESSION["admin"]["session"]."'and status='1')  and type not in ('busfee','fee') ");
	  
	  $total_paid=$db->getVal("SELECT sum(COALESCE(amount,0)) as amt from reff_receipt  WHERE idno IN (SELECT idno FROM student WHERE class='".$c."' $where_section AND session='".$_SESSION["admin"]["session"]."'and status='1') ");

		// discount
		$discount=$db->getVal("SELECT sum(COALESCE(discount,0)+COALESCE(busdiscount,0)) as tution_dis from installment  WHERE idno IN (SELECT idno FROM student WHERE class='".$c."' $where_section AND session='".$_SESSION["admin"]["session"]."'and status='1')");
		
		
		
		$total_other_discount=$db->getVal("SELECT COALESCE(sum(discount),0) as result from otherfee_discount  WHERE idno IN (SELECT idno FROM student WHERE class='".$c."' $where_section AND session='".$_SESSION["admin"]["session"]."'and status='1')");
							
				
		$dis=$discount+$total_other_discount;
		$tf=$total_tution+$bus+$total_other_fee-$dis;
		//$tf=$total_other_fee-$total_other_discount;
		
		

		$tl=$tf-$total_paid;
		$total_bus=0;			
		  ?>
                            <tr>
							     <td><?= $i;  ?></td>
							     <td><?=  $c; ?></td>
							     <td><?=  $section; ?></td>
								  <td><?=  $total_student;  ?></td>
								  <td><?php  echo $total_tution; $t1+=$total_tution; ?></td>
								  <td><?php   echo $bus; $t2+=$bus; ?></td>
								  <td><?php  echo $total_other_fee-$dis; $t3+=$total_other_fee-$dis; ?></td>
				                 <td><?php echo $tf; $MyTotalFee +=$tf; ?></td>
							     
								 <td><?php echo $total_paid_tution; $t4+= $total_paid_tution;?></td>
								 <td><?php echo $total_paid_bus; $t5+=$total_paid_bus; ?></td>
								 <td><?php echo $total_paid_other; $t6+=$total_paid_other; ?></td>
								
								 <td><?php  echo $total_paid; $MyTotalpaid+=$total_paid; ?></td>
							     <td><?php echo $dis; $MyDiscount+=$dis;?></td> 
								
								<td> <?php  echo $tl; $MyTotalLeft+=$tl; ?></td>
							    
								 <td><?php echo $refpay; $tref+=$refpay; ?></td>
                            	
							</tr>
		 <?php }} unset($section);
	unset($where_section);
	
	} ?>


                    </tbody>
   
                    <tfoot>
                    	<tr style="color: #fff; background:LightGray; font-size:15px" >
                        	<th></th>
                        	<th colspan='3'>Gross Total</th>
							
							<th><?php echo $t1; ?></th>
							<th><?php echo $t2; ?></th>
							<th><?php echo $t3; ?></th>
                            <th id="MyTotalFee"><?php echo $MyTotalFee?></th>
                            
							<th><?php echo $t4; ?></th>
							<th><?php echo $t5; ?></th>
							<th><?php echo $t6; ?></th>
							<th id="MyTotalpaid"><?php echo $MyTotalpaid;?></th>
                           <th id="MyDiscount"><?php echo $MyDiscount; ?></th>
                            <th id="MyTotalLeft"><?php echo $MyTotalLeft; ?></th>
                            
							<th><?php echo $tref; ?></th>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          
		<?php
		echo $db->getErMsg();
	}
	
	// new code end
	

	// new code	
	elseif(isset($_GET["new_add"])){

	?> 
			<div class="row-fluid">
			<?php $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</p>	</h5></center>
			
       
            <div class="well no-padding" id="printDiv1">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>                        
                            <td>S No</td>                         
                            <td>Name</td>                         
                            <td>status</td>                         
                            <td>Class</td> 
                            <td>Tution</td>							
                            <td>Transport</td>							
                            <td>Other</td>							
                            <td>Amount</td>
                            <td>Left Amount</td>  							
                            <td>Net Total</td>
                            
                        </tr>
                    </thead>
                    <tbody>
<?php 
        $stu=$db->getRows("SELECT idno,stype, name,class,section, case when status= 1 then 'active'  when status= 3 then 'Inactive' end as status FROM student WHERE (admission_date between '$fdate' and '$tdate' or idate between '$fdate' and '$tdate'  ) and session='".$_SESSION["admin"]["session"]."'  ");
		
				
		$i=0;
		$total_bus=0;$total_tution=0;
		
foreach($stu as $stu1){ $i++;

    
		$_REQUEST[id]=$stu1['idno'];
		$cls = $stu1['class'];
		$type =$stu1['stype'];
	
	   // $total=$db->getVal("SELECT (COALESCE(bus,0)+total) as result from installment  WHERE idno='".$_REQUEST[id]."' and session='".$_SESSION["admin"]["session"]."'  ");
		
	    $total_tution=$db->getVal("SELECT COALESCE(total,0) as result from installment  WHERE idno='".$_REQUEST[id]."' and session='".$_SESSION["admin"]["session"]."'  ");
		
	    $total_bus=$db->getVal("SELECT COALESCE(bus,0) as result from installment  WHERE idno='".$_REQUEST[id]."' and session='".$_SESSION["admin"]["session"]."'  ");
		
				
        $total=$total_tution+$total_bus;
		
		$total_other=$db->getVal("SELECT COALESCE(sum(fee),0) as result from otherfee_structure  WHERE class='$cls' and month='$i' and (otype='".$_REQUEST[id]."' or otype='$type' or otype='' ) and session='".$_SESSION["admin"]["session"]."' ");
		
		$total_other_discount=$db->getVal("SELECT COALESCE(sum(discount),0) as result from otherfee_discount  WHERE  idno='".$_REQUEST[id]."' and month='$i' and class='$cls' and session='".$_SESSION["admin"]["session"]."' ");
		
		$other_fee_name= $db->getVal("SELECT sum(fee) from otherfee_structure  WHERE class='$cls'  and (otype='".$_REQUEST[id]."' or otype='$type' or otype='') and session='".$_SESSION["admin"]["session"]."' ");
		
	//$total_pay+=$total+$total_bus+$total_other-$total_other_discount;
	$total_pay=$total+$other_fee_name;	
	//$tot=$total_pay-$total_other_given;
	$tot=$total_pay;
?>
				   <tr>
						 <td><?= $i;  ?></td>
						 <td><?= $stu1['name']; ?></td>
						 <td><?= $stu1['status'] ?></td>
				         <td><?= $stu1['class'].'-'.$stu1['section'] ?></td>
						 <td><?php echo $total_tution; $t+=$total_tution; ?></td>
						 <td><?php  if($total_bus) echo $total_bus; else echo 0; $b+=$total_bus;  ?></td>
						 <td><?php  if($other_fee_name) echo $other_fee_name; else echo 0; $o+=$other_fee_name ?></td>
						 <td><?php if($stu1['status']=='active'){ echo $tot; $act+=$tot;}?></td>
						 <td><?php if($stu1['status']=='Inactive'){ echo $tot; $inac+=$tot;}?></td>
						 <td> </td>						
					</tr>		 
<?php } ?>
                    </tbody>  
                    <tfoot>
                    	<tr style="color: #fff; background:LightGray; font-size:20px" >
                        	<th></th>
                        	<th colspan='3'>Gross Total</th>
							<th><?=  $t; ?></th>
							<th><?=  $b; ?></th>
							<th><?=  $o; ?></th>
                            <th id="MyTotalFee"><?= $act; ?></th>
                            <th id="MyTotalpaid"><?= $inac; ?></th>
                         
                            <th id="MyTotalLeft"><?php echo $act-$inac; ?></th>
                            
							<th></th>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          
		<?php
		echo $db->getErMsg();
			}
	
	// new code end

    // my test code start
    elseif(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
			?>
            <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>

			<a class="btn btn-primary" id="myPrntbtn" href="<?php echo URL_ROOT."print/?page_id=collection_sheet&fdate=$_GET[fdate]&fmonth=$_GET[fmonth]&fyear=$_GET[fyear]&tdate=$_GET[tdate]&tmonth=$_GET[tmonth]&tyear=$_GET[tyear]&location=$_GET[location]&daily1=&head_name=$_GET[head_name]&class=$_GET[class]&head_type=$_GET[head_type]"; ?>" target="_blank" >Full Screen</a>
            <style>
                @media print {
            
                    #myPrntbtn {
                        display :  none;
                    }
            
                }
            </style>
			<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>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["inventory"])){

		$overAllTotal=0;

		$inventoryReceipt = $db->getRows("SELECT *, r.id as rid, r.rid as rrid, 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' GROUP BY r.rid");
// 		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>

            <a class="btn btn-primary" id="myPrntbtn" href="<?php echo URL_ROOT."print/?page_id=collection_sheet&fdate=$_GET[fdate]&fmonth=$_GET[fmonth]&fyear=$_GET[fyear]&tdate=$_GET[tdate]&tmonth=$_GET[tmonth]&tyear=$_GET[tyear]&location=$_GET[location]&inventory=&head_name=$_GET[head_name]&class=$_GET[class]&head_type=$_GET[head_type]"; ?>" target="_blank" >Full Screen</a>

            <style>
                @media print {
            
                    #myPrntbtn {
                        display :  none;
                    }
            
                }
            </style>



			<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>Receipt No.</th>
					<th>payment Mode</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");
                            $total = $db->getVal("select sum(total_amount) from inventory_receipt where rid='".$inv["rrid"]."' ");
                            ?>
						<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["rrid"] ?></td>
							<td><?php echo $inv["payment_mode"] ?></td>
                            <td><?php echo $inv["item"] ?></td>
                            <td><?php echo $inv["num_item"]; ?></td>
                            <td><?php echo $total; 
                            $overAllTotal+=$total; ?></td>
							<td><?php echo date("d-m-Y",strtotime($inv['issue_date'])); ?></td>
						</tr>
						<?php
						$s++;
						}
					?>
				</tbody>
				
				<tfoot>
					<tr>
					    <td colspan="9">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();
		}
}
    // my test code end	
    elseif(isset($_REQUEST["cheque_report"])){ ?>

            <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>Cheque 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>class</th>
					<th>Cheque No</th>
					<th>Cheque Date</th>
					<th>Bank Name</th>
					<th>Branch Name</th>
					<th>Receipt No</th>
					<th>Cheque Amount</th>
				</tr>
				</thead>
				<?php  $cheque=$db->getRows("select * from chequefee where  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
	
	$i=0;
foreach($cheque as $chequ){ $i++;
	$id=$chequ['id'];
	$stu=$db->getRow("select * from student where idno='".$chequ['idno']."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
	
?>
    <tr>
         <td><?= $i; ?></td>       
         <td><?= $stu['name'] ?></td>       
         <td><?= $stu['class'] ?></td>       
         <td><?= $chequ['number'];?></td>       
         <td><?= $chequ['udate'];?></td>       
         <td><?= $chequ['bankname'];?></td>       
         <td><?= $chequ['bankno'];?></td>       
         <td><?= $id; ?></td>       
         <td><?= $chequ['amount']; $total+=$chequ['amount']; ?></td>
       
    </tr>
<?php } ?>

   <tr>
        <td colspan="8">Total Amount</td>
		<td><?= $total ?></td>
    </tr>
	
</table>
	<?php }

    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");		

            foreach($hostelextra as $cls){
                $feeheadary[]= " ( type NOT like '%$cls[name]' )";
            }


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

			<a class="btn btn-primary" id="myPrntbtn" href="<?php echo URL_ROOT."print/?page_id=collection_sheet&fdate=$_GET[fdate]&fmonth=$_GET[fmonth]&fyear=$_GET[fyear]&tdate=$_GET[tdate]&tmonth=$_GET[tmonth]&tyear=$_GET[tyear]&location=$_GET[location]&daily_withouthostel=&head_name=$_GET[head_name]&class=$_GET[class]&head_type=$_GET[head_type]"; ?>" target="_blank" >Full Screen</a>
            <style>
                @media print {
            
                    #myPrntbtn {
                        display :  none;
                    }
            
                }
            </style>

			<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
						$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 (type NOT like 'hostelfee') AND ".implode(" AND ",$feeheadary)." 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
	}
	
	// academic online start
	elseif(isset($_REQUEST["academic_online"])){
	
		$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllFine=0;$overAllextra=array();$overAllNewextra=0;$overAllTot=0;$hostelotherExtra=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"]."' and pay_type='online' $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
			?>
            <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">
                	<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>Txn Id</th>
                    <th>Txn Date</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</td>
				   <th>Fine</th>
				   <th>Extra</th>
				   <th>Hostel other</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 status=1  and issue_TC=0  $whereLocation");
							
						if(!empty($loc)){
							$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 status=1   and issue_TC=0");							
						
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;
						
						
						//tu
						$tution=$db->getVal("select sum(amount) from reff_receipt where idno='".$s_id[idno]."' and pay_type='online' and type='fee' and (date between '$fdate' and '$tdate') ");
						//echo $ss="select sum(amount) from reff_receipt where idno='".$s_id[idno]."' and pay_type='online' and type='fee' and (date between '$fdate' and '$tdate') ";
					
							if(!empty($tution)){
							$overAlltution+=$tution;
							$total+=$tution;
							}
							
						
						
						$trasnport=$db->getVal("select sum(amount) from reff_receipt where idno='".$s_id[idno]."' and type='busfee' and pay_type='online'   and (date between '$fdate' and '$tdate') ");
						
							if(!empty($trasnport)){
							$overAllTransport+=$trasnport;
							$total+=$trasnport;
							}
						
			$hostel=$db->getVal("select sum(amount) from reff_receipt where idno='".$s_id[idno]."' and type='hostelfee' and pay_type='online'   and (date between '$fdate' and '$tdate') ");
						
							if(!empty($hostel)){
							$overAllThostel+=$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"]."'");
								
								
								if($Ftypeid) { //echo $Ftypeid;
								$sums=$db->getVal("select sum(amount) from reff_receipt where idno='".$s_id[idno]."' and type='extrafee".$Ftypeid."' and pay_type='online'  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]."' $whereUser");
						if(is_array($installOtherExtra) && count($installOtherExtra)>0){
							foreach($installOtherExtra as $installT){
								//other1_detail
								$idSdetail=str_replace("_detail","",$installT[ins_name]);
								$idSdetail=str_replace("other","",$idSdetail);
								$otherExtra+=$db->getVal("select fine from installment_fine where ins_name='".$idSdetail."-otherfee' and idno=".$s_id[idno]);
								
								//echo $db->getLastQuery();
							}
							$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]."' $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]."' $whereUser");          						//echo $db->getLastQuery();
								$h1otherExtra+=$db->getVal("select sum(fine) from installment_fine where ins_name='".$idSdetail."-otherhostel' and (udate between '$fdate' and '$tdate') and idno='".$s_id[idno]."' $whereUser");
								//echo $db->getLastQuery();
							}$hostelotherExtra=$hotherExtra+$h1otherExtra;
							$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]."' $whereUser");
							//echo $db->getLastQuery();
								//print_r($ref);exit;
									$rids=array();$rrmonth=array();
									$rrtxnid = ''; $rrtdate = '';
									$rrde=$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($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;}
												}
											}
										}
										if($rr['txnid'] != "") {
										$rrtxnid .= $rr['txnid'].", ";
										}
										if($rr['tdate'] != "") {
										$rrtdate .= $rr['tdate'].", ";
										}
										
									}
								}    //$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++;
						?>
						<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 $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 $rrtxnid; ?></td>
							<td><?php echo $rrtdate; ?></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 $newExtra; ?></td>
                           
                           <td><?php echo $hostelotherExtra;  ?></td>
                           <td>0</td>
						   <td><?php echo $total;$overAllTotal+=$total; ?></td>
						</tr>
						<?php
						}
					}
					}
					?>
                    <tr>
                    	<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"]."'");  ?></td>
                        <td></td>
                        <td></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>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') and session='".$_SESSION["admin"]["session"]."'"); ?></td>
                        <td><?php echo $tot;$overAllTot+=$tot;$overAllTotal+=$tot; ?></td>
                    </tr>
				</tbody>
				<tfoot>
					<td colspan="13">Gross Total</td>
					<td><?php echo $overAlltution ?></td>
					<td><?php echo $overAllTransport ?></td>
					<td><?php echo $overAllThostel ?></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 $overAllNewextra ?></td>
				   
				    <td><?php echo $overAllHostelOther ?></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();
		}
	}
	
	// academic online end
	// hostel online start
	elseif(isset($_REQUEST["hostel_online"])){
		$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"]."' and pay_type='online'  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 status=1   and issue_TC=0");
												
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$hotherExtra=$h1otherExtra=$hostelotherExtra=0;$total=0;$fine=0;
						
						
						$hostel=$db->getVal("select sum(amount) from reff_receipt where idno='".$s_id[idno]."' and type='hostelfee' and pay_type='online' 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[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;
						}
						$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();
		}
	}	

	//  online payment start
	elseif(isset($_REQUEST["online_payment"])){
		$v=$LinksDetails["voice_id"];
		$conn=new mysqli('localhost','savarna_payment','techno@123','savarna_payment_db');
		if($conn->connect_error) echo $conn->connect_error; 
		//if($conn) echo 22; else echo 55;
		//die;
		 $sql="select * from mss_pay_log where school_name='".$v."' and  date(udate) between '$fdate' and '$tdate'";
		
$result = $conn->query($sql);

if($result->num_rows>0){
	
//while($row=$result->fetch_assoc()){

	//print_r($row);
//}
//}		
/*	
$url='http://savarnacloud.com/payment/get_school_data.php?school_name='.$school_name; 
// path to your JSON file
$data = file_get_contents($url); 
// put the contents of the file into a variable
$characters = json_decode($data);
//echo $d2[id]; 
$object=$characters;
$arr = json_decode(json_encode($characters), True);*/
?>
<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>Class</th>
					<th>Status</th>
					<th>Software Status</th>
					<th>Month</th>
					<th>Date</th>
					<th>Payment Type</th>					
					<th>Tax</th>					
					<th>Cnv Amt</th>					
					<th>Fee Amt</th>					
					<th>Total Amount</th>									   
				</tr>
				</thead> 
				<tbody>
				<?php
				$i=0;
//foreach($arr as $d2){$i++;

while($d2=$result->fetch_assoc()){
	$i++;
//print_r($d2[id]);
?>
		<tr>
		    <td><?= $i;?></td>
		    <td><?php  $stud=$db->getRow("select name,fname,class from student where idno='".$d2[idno]."'");
			echo $stud[name];
			?></td>
		    <td><?= $stud['fname']?></td>
		    <td><?= $stud['class']?></td>
		    <td><?= $d2['status']?></td>
		    <td><?= $d2['soft_update']?></td>
		    <td><?= $d2['month']?></td>
		    <td><?= $d2['udate']?></td>
		    <td><?= $d2['pay_type']?></td>
		    <td><?php echo $tax=$d2['tax']; $tax_t+=$tax;?></td>
		    <td><?php echo $cnv= $d2['cnv_amt']; $cnv_t+=$cnv; ?></td>
		    <td><?php echo $fee= $d2['fee_amt']; $fee_t+=$fee;?></td>
		    <td><?php echo $amt= $d2['amount']; $amt_t+=$amt; ?></td>		    		   
		</tr>
<?php
}
?>
</tbody>
               <tfoot>
					<td colspan="9" text-align="right">Gross Total</td>
					<td><?= $tax_t; ?></td>
					<td><?= $cnv_t; ?></td>
					<td><?= $fee_t; ?></td>
				    <td><?= $amt_t; ?></td>				    
				</tfoot>
</table>
<?php
	
   }	
	}
	
	//  online payment end
	
	
	// hostel online end
	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>

			<a class="btn btn-primary" id="myPrntbtn" href="<?php echo URL_ROOT."print/?page_id=collection_sheet&fdate=$_GET[fdate]&fmonth=$_GET[fmonth]&fyear=$_GET[fyear]&tdate=$_GET[tdate]&tmonth=$_GET[tmonth]&tyear=$_GET[tyear]&location=$_GET[location]&hostel_dcr=&head_name=$_GET[head_name]&class=$_GET[class]&head_type=$_GET[head_type]"; ?>" target="_blank" >Full Screen</a>

            <style>
                @media print {
            
                    #myPrntbtn {
                        display :  none;
                    }
            
                }
            </style>

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

            <a class="btn btn-primary" id="myPrntbtn" href="<?php echo URL_ROOT."print/?page_id=collection_sheet&fdate=$_GET[fdate]&fmonth=$_GET[fmonth]&fyear=$_GET[fyear]&tdate=$_GET[tdate]&tmonth=$_GET[tmonth]&tyear=$_GET[tyear]&location=$_GET[location]&hostel_income=&head_name=$_GET[head_name]&class=$_GET[class]&head_type=$_GET[head_type]"; ?>" target="_blank" >Full Screen</a>

            <style>
                @media print {
            
                    #myPrntbtn {
                        display :  none;
                    }
            
                }
            </style>

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

            <a class="btn btn-primary" id="myPrntbtn" href="<?php echo URL_ROOT."print/?page_id=collection_sheet&fdate=$_GET[fdate]&fmonth=$_GET[fmonth]&fyear=$_GET[fyear]&tdate=$_GET[tdate]&tmonth=$_GET[tmonth]&tyear=$_GET[tyear]&location=$_GET[location]&hostel_expance=&head_name=$_GET[head_name]&class=$_GET[class]&head_type=$_GET[head_type]"; ?>" target="_blank" >Full Screen</a>

                <style>
                @media print {
            
                    #myPrntbtn {
                        display :  none;
                    }
            
                }
            </style>

			<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["monthly"])){
		$GrandTotal=0;$Grandtution=0;$GrandTransport=0;$Grandhotel=0;$GrandOther=0;$GrandFine=0;$Grandextra=0;$GrandNewextra=0;$Grandhotel=0;
		$day=date_range($fdate, $tdate);
		
		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");
		$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));else echo date("d-M-Y",strtotime($fdate)) ." to ".date("d-M-Y",strtotime($tndate)); ?></p> <p>Monthly Income Report</p>	</h5></center>
		<table class="table" cellpadding="0" cellspacing="0" border="1" id="tblData">
            <thead>
            <tr style="cursor:pointer">
                <th width="5%">S.no</th>
                <th>Date</th>
                <th>Tution Fee</th>
                <th>Transport fee</th>
                <th>Hostel Fee</th>
                <th>Extra Fee</th>
                <th>Other Fee</th>
                <th>Hostel Other</th>
                <th>Total</th>
            </tr>
            </thead>
            <tbody>
		<?php $i=0;
		foreach($day as $thisday){ $i++;
			$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllFine=0;$overAllextra=0;$overAllNewextra=0;$overAllHostelOther=0;
			if(count($day)==$i){
			}else{
			$fdate=$thisday;
			$tdate = date('Y-m-d', strtotime('+1 days',strtotime($thisday)));
			{
				$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;
		
				//	$tution=$db->getVal("select sum(amount) from reff_receipt where  type='fee' and (date between '$fdate' and '$tdate') ");
	                	$tution=$db->getVal("select sum(amount) from reff_receipt as r INNER join student as s on s.idno=r.idno where r.type='fee' and (r.date between '$fdate' and '$tdate') and s.status=1");
							if(!empty($tution)){
							$overAlltution+=$tution;
							$total+=$tution;
							}		
				

                       $trasnport=$db->getVal("select sum(amount) from reff_receipt as r INNER join student as s on s.idno=r.idno where r.type='busfee' and (r.date between '$fdate' and '$tdate') and s.status=1" );
							if(!empty($trasnport)){
							$overAllTransport+=$trasnport;
							$total+=$trasnport;
							}	
				
		
				

			//	$hostel=$db->getVal("select sum(amount) from reff_receipt where  type='hostelfee' and (date between '$fdate' and '$tdate') ");
				$hostel=$db->getVal("select sum(amount) from reff_receipt as r INNER join student as s on s.idno=r.idno where r.type='hostelfee' and (r.date between '$fdate' and '$tdate') and s.status=1" );
										
							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,idno from installment_time where ins_name like 'ext-".$Ftypeid."%' and (date between '$fdate' and '$tdate') $whereUser");$no=array();
						if(is_array($installTution) && count($installTution)>0){
							foreach($installTution as $installT){
								$no=explode("-",$installT[0]);
								$sums+=$db->getVal("select pay from extrafee where idno='".$installT["idno"]."' and  pid='p".$no[2]."' and type='".$Ftypeid."'");
								echo $db->getErMsg();
							}
							
						}
						$extrasum[]=$sums;
						$total+=$sums;$tp=$ftype["type"];
						$overAllextra[$tp]+=$sums;
					}
				}
				
				*/
	
			
				$extra=$db->getVal("select sum(amount) from reff_receipt as r INNER join student as s on s.idno=r.idno where (r.type like '%extrafee%') and (r.date between '$fdate' and '$tdate') and s.status=1" );
											
							if(!empty($extra)){
							$overAllextra+=$extra;
							$total+=$extra;
							}	
		
		//	echo $ss="select ins_name,idno from installment_time where ins_name like 'other%' and (date between '$fdate' and '$tdate') $whereUser";
				$installOtherExtra=$db->getRows("select ins_name,idno from installment_time where ins_name like 'other%' and (date between '$fdate' and '$tdate') $whereUser");
				if(is_array($installOtherExtra) && count($installOtherExtra)>0){
					foreach($installOtherExtra as $installT){
						//other1_detail
						$idSdetail=str_replace("_detail","",$installT[ins_name]);
						$idSdetail=str_replace("other","",$idSdetail);
						$otherExtra+=$db->getVal("select fine from installment_fine where ins_name='".$idSdetail."-otherfee' and (udate between '$fdate' and '$tdate') ");
					//echo $ss="select fine from installment_fine where ins_name='".$idSdetail."-otherfee' ";
						//echo $db->getLastQuery();
					}
					$overAllOther+=$otherExtra;
					$total+=$otherExtra;
				}
				
	         	$hostelotherExtra=$db->getVal("select sum(fine) from installment_fine where ins_name like '%hostel' and (udate between '$fdate' and '$tdate') ");
						
						$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')");
				$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')");
				$total+=$newExtra;
				$overAllNewextra+=$newExtra;
				if($total>0){
					$overAllTotal+=$total;
				}
				
					?>
				<tr>
                	<td><?php echo $i; ?></td>
					<td><?php echo date("d-M-Y",strtotime($fdate)); ?></td>
					<td><?php echo $overAlltution; $Grandtution+=$overAlltution; ?></td>
					<td><?php echo $overAllTransport; $GrandTransport+=$overAllTransport; ?></td>
					<td><?php echo $overAllhotel; $Grandhotel+=$overAllhotel; ?></td>
				     <td><?php echo $overAllextra; $Grandextra+=$overAllextra; ?></td>
				     <td><?php echo $overAllOther; $GrandOther+=$overAllOther; ?></td>
				     <td><?php echo $overAllHostelOther; $GrandFine+=$overAllHostelOther; ?></td>
				   <td><?php echo $overAllTotal+$tot; $overAllTot=$overAllTot+$tot; $GrandTotal+=$overAllTotal+$tot; ?></td>
				</tr>
			<?php
			}
		}
	}
		?>
		</tbody>
        <tfoot>
            <td></td>
            <td>Gross Total</td>
            <td><?php echo $Grandtution ?></td>
            <td><?php echo $GrandTransport ?></td>
            <td><?php echo $Grandhotel ?></td>
            <td><?php echo $Grandextra ?></td>
           <td><?php echo $GrandOther ?></td>
           <td><?php echo $GrandFine ?></td>
          
          
           <td><?php echo $GrandTotal; ?></td>
        </tfoot>
	</table>  Print Date : <?php echo date('d-M-Y'); ?>
		<?php
		//echo "<pre>";print_r($day);
	}

	}
}else{
	echo "Please select date First";
}

?>
</div>
<script type="text/javascript">
	$(document).ready(function(e) {
		var oTable = $('.table').dataTable( {
			"bPaginate": false,
			"bLengthChange": true,
			"bFilter": true,
			"bSort": true,
			"bInfo": true,
			"fnRowCallback" : function(nRow, aData, iDisplayIndex){
                $("td:first", nRow).html(iDisplayIndex +1);
               return nRow;
            },
			"bAutoWidth": false
		});
	});
	
	function SMSComplete(valueid,act){
	$(this).hide();
	var Fee=$("#"+valueid).html();
	var fdate='<?php if($_GET["fdate"]!="")echo $_GET["fdate"];else echo "0" ?>';
	var fmonth='<?php if($_GET["fmonth"]!="")echo $_GET["fmonth"];else echo "0" ?>';
	var fyear='<?php if($_GET["fyear"]!="")echo $_GET["fyear"];else echo "0" ?>';
	var tdate='<?php if($_GET["tdate"]!="")echo $_GET["tdate"];else echo "0" ?>';
	var tmonth='<?php if($_GET["tmonth"]!="")echo $_GET["tmonth"];else echo "0" ?>';
	var tyear='<?php if($_GET["tyear"]!="")echo $_GET["tyear"];else echo "0" ?>';
	var cls='<?php if($_GET["class"]!="")echo $_GET["class"];else echo "0" ?>';
	$.post( "ajax.php", { type: act ,fee: Fee, fdate:fdate, fmonth:fmonth, fyear:fyear, tdate:tdate, tmonth:tmonth, tyear:tyear,class: cls  } , function( data ) {
	  	//$("#ins").html(data);getTotal();
		alert(data);
		$(this).show();
	});
    }
	</script>
    <style>
    tfoot{display: table-footer-group !important;}
    </style>
    
    
    
    
    <script>
    function exportTableToExcel(tableID, filename = '',e){
    
    var tableType = document.getElementById('tblData').getAttribute("data-tblname");

    var downloadLink;
    var dataType = 'application/vnd.ms-excel';
    var tableSelect = document.getElementById(tableID);
    var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');

    // Specify file name
    filename = filename?filename+'.xls':'excel_data.xls';
    
    // Create download link element
    downloadLink = document.createElement("a");
    
    document.body.appendChild(downloadLink);
    
    if(navigator.msSaveOrOpenBlob){
        var blob = new Blob(['\ufeff', tableHTML], {
            type: dataType
        });
        navigator.msSaveOrOpenBlob( blob, filename);
    }else{
        // Create a link to the file
        downloadLink.href = 'data:' + dataType + ', ' + tableHTML;
    
        // Setting the file name
        downloadLink.download = filename;
        
        //triggering the function
        downloadLink.click();
    }
    e.preventDefault();
}
</script>

<style>
     #myPrntbtn {
                margin-top:-80px;
        }
</style>


