<?php
$pgMod="collection_sheet";
$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>
<form method="get" action="">
    <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 span5">
                        <label class="control-label" for="class">From Date</label>
                        <div class="controls">
                                <select class="span3" name="fdate" id="date">
                                    <option value="">Date</option>
                                    <?php
                                    for($m = 01;$m <= 31; $m++){ 
                                        $selected="";if($_GET["fdate"]==$m)$selected=" selected ";
                                        echo "<option $selected value='$m'>$m</option>";
                                    }
                                    ?> 
                                </select>
                                <select class="span5" name="fmonth" id="fmonth">
                                    <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 ";
                                        echo "<option $selected value='$m'>$month</option>";
                                    }
                                 ?> 
                                </select>
                                <select class="span4" name="fyear" id="fyear">
                                    <option value="">Year</option>
                                    <?php
                                    for($m = 2013;$m <= 2050; $m++){  
                                        $selected="";if($_GET["fyear"]==$m)$selected=" selected ";
                                        echo "<option $selected value='$m'>$m</option>";
                                    }
                                    ?> 
                                </select>
                            </div>
                    </div>
                    <div class="control-group span5">
                        <label class="control-label" for="medium">To date</label>
                        <div class="controls">
                                <select class="span3" name="tdate" id="tdate">
                                    <option value="">Date</option>
                                    <?php
                                    for($m = 01;$m <= 31; $m++){ 
                                         $selected="";if($_GET["tdate"]==$m)$selected=" selected ";
                                        echo "<option $selected value='$m'>$m</option>";
                                    }
                                    ?> 
                                </select>
                                <select class="span5" name="tmonth" id="tmonth">
                                    <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 ";
                                        echo "<option $selected value='$m'>$month</option>";
                                    }
                                 ?> 
                                </select>
                                <select class="span4" name="tyear" id="tyear">
                                    <option value="">Year</option>
                                    <?php
                                    for($m = 2013;$m <= 2050; $m++){  
                                         $selected="";if($_GET["tyear"]==$m)$selected=" selected ";
                                        echo "<option $selected value='$m'>$m</option>";
                                    }
                                    ?> 
                                </select>
                            </div>
                    </div>
                    <div class="control-group span2">
                    	<select class="span12" 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 span10" style="margin:0;">
                    <button type="submit" name="daily" class="btn-classic">Complete DCR</button>
                    <button type="submit" name="daily_withouthostel" class="btn-classic">Academic DCR</button>
                    <button type="submit" name="hostel_dcr" class="btn-classic">Hostel DCR</button>
                    <button type="submit" name="hostel_income" class="btn-classic">Pocket Income</button>
                    <button type="submit" name="hostel_expance" class="btn-classic">Pocket Expance</button>
                    <button type="submit" name="monthly" class="btn-classic margin">Monthly Report</button>
                   <button type="button" onclick="printDiv('printDiv')" class="btn btn-danger" style="float:right">Print</button>
                   <button onclick="SMSComplete('completeFeeShw','DCRSMS')" style="float:right" 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"]==2){
		echo "No records available";
	}else{
	if(isset($_REQUEST["daily"])){
			$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"]."' ";
		}
		$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");
		
		//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">
				<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>
                    <td>Receipt No</td>
                    <td>Month</td>
					<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){
						$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='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
							foreach($installTution as $installT){
								$tution+=$db->getVal("select ".$installT["ins_name"]." from installment where idno=".$fStudent["idno"]);
							}
							$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='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
							foreach($installTution as $installT){
								$trasnport+=$db->getVal("select ".$installT["ins_name"]." from installment where idno=".$fStudent["idno"]);
							}
							$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='".$fStudent["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=".$fStudent["idno"]);
							}
							$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='".$fStudent["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='".$fStudent["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='".$fStudent["idno"]."'");
						if(is_array($installOtherExtra) && count($installOtherExtra)>0){
							foreach($installOtherExtra as $installT){
								//other1_detail
								$idSdetail=str_replace("_detail","",$installT[0]);
								$idSdetail=str_replace("other","",$idSdetail);
								$otherExtra+=$db->getVal("select fine from installment_fine where ins_name='".$idSdetail."-otherfee' and idno=".$fStudent["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='".$fStudent["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=".$fStudent["idno"]);          						//echo $db->getLastQuery();
								$h1otherExtra+=$db->getVal("select sum(fine) from installment_fine where ins_name='".$idSdetail."-otherhostel' and idno=".$fStudent["idno"]);
								//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='".$fStudent["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='".$fStudent["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='".$fStudent["idno"]."'");
							//echo $db->getLastQuery();
								//print_r($ref);exit;
									$rids=array();$rrmonth=array();
									$rrde=$db->getRows("select * from receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$fStudent["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++;
						?>
						<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 $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 $recno; ?></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>
                    	<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>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"]."'"); ?></td>
                        <td><?php echo $tot;$overAllTot+=$tot;$overAllTotal+=$tot; ?></td>
                    </tr>
				</tbody>
				<tfoot>
					<td colspan="8">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>
				</tfoot>
			</table>  
            Print Date : <?php echo date('d-M-Y'); ?>
			<?php
		}else{
			echo "No record found<br />".$db->getErMsg();
		}
	}
elseif(isset($_REQUEST["daily_withouthostel"])){
		$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"]."' ";
		}
		$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 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- SCHOOL FEE</p>	</h5></center>
			<table class="table" cellspacing="0" cellpadding="0" border="1">
				<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>
                    <td>Receipt No</td>
                    <td>Month</td>
					<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>Income</th> 
				   <th>Total</th>
				</tr>
				</thead>
				<tbody>
					<?php $s=0;
					foreach($aryStudentList as $fStudent){
						$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='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
							foreach($installTution as $installT){
								$tution+=$db->getVal("select ".$installT["ins_name"]." from installment where idno=".$fStudent["idno"]);
							}
							$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='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
							foreach($installTution as $installT){
								$trasnport+=$db->getVal("select ".$installT["ins_name"]." from installment where idno=".$fStudent["idno"]);
							}
							$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='".$fStudent["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=".$fStudent["idno"]);
							}
							$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='".$fStudent["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='".$fStudent["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='".$fStudent["idno"]."'");
						if(is_array($installOtherExtra) && count($installOtherExtra)>0){
							foreach($installOtherExtra as $installT){
								//other1_detail
								$idSdetail=str_replace("_detail","",$installT[0]);
								$idSdetail=str_replace("other","",$idSdetail);
								$otherExtra+=$db->getVal("select fine from installment_fine where ins_name='".$idSdetail."-otherfee' and idno=".$fStudent["idno"]);
								//echo $db->getLastQuery();
							}
							$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='".$fStudent["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='".$fStudent["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='".$fStudent["idno"]."'");
							//echo $db->getLastQuery();
								//print_r($ref);exit;
									$rids=array();$rrmonth=array();
									$rrde=$db->getRows("select * from receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$fStudent["idno"]."'");
								
									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).")";
								}
							}
						}
					}
						//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 $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>0</td>
						   <td><?php echo $total;$overAllTotal+=$total; ?></td>
						</tr>
						<?php
						}
					}
					?>
                    <tr>
                    	<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>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><?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="8">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 $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();
		}
	}
	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"]."' ";
		}
		$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- HOSTEL FEE</p>	</h5></center>
			<table class="table" cellspacing="0" cellpadding="0" border="1">
				<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>
                    <td>Receipt No</td>
                    <td>Month</td>
					<th>Hostel Fee</th>
				    <th>Hostel Other</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;
						
						$installTution=$db->getRows("select ins_name from installment_time where ins_name like 'hp%' and (date between '$fdate' and '$tdate') and idno='".$fStudent["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=".$fStudent["idno"]);
							}
							$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='".$fStudent["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=".$fStudent["idno"]);          						//echo $db->getLastQuery();
								$h1otherExtra+=$db->getVal("select sum(fine) from installment_fine where ins_name='".$idSdetail."-otherhostel' and idno=".$fStudent["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='".$fStudent["idno"]."'");
									$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='".$fStudent["idno"]."'");
								
									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"]."' ";
		}
		$aryStudentList=$db->getRows("select name,fname,admissionno,idno,class from student where school_id='".$_SESSION["admin"]["school_id"]."'  and status=1 $whereLocation and issue_TC=0");
		//print_r($aryStudentList); 
		//echo $db->getErMsg().$db->getLastQuery();
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			$tndate = date('Y/m/d', strtotime('-1 days',strtotime($tdate)));
			//echo $tndate." ".$fdate
			?>
            <center><h5><p style="float:right">Collection Date: 
			<?php if(strtotime($tndate)==strtotime($fdate)){
			echo date("d-M-Y",strtotime($tndate));?> - <?php echo date("l",strtotime($tndate));}
			else echo date("d-M-Y",strtotime($fdate)) ." to ".date("d-M-Y",strtotime($tndate)); ?></p> <p>Daily Collection Report- POCKET MONEY</p>	</h5></center>
			<table class="table" cellspacing="0" cellpadding="0" border="1">
				<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>
                    <td>Receipt No</td>
					<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"]."'");
					 $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"]."'");
									$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"]."'");
									//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"]."' ";
		}
		$aryStudentList=$db->getRows("select name,fname,admissionno,idno,class from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 $whereLocation and issue_TC=0");
		
		//echo $db->getErMsg().$db->getLastQuery();
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			$tndate = date('Y/m/d', strtotime('-1 days',strtotime($tdate)));
			//echo $tndate." ".$fdate
			?>
            <center><h5><p style="float:right">Collection Date: 
			<?php if(strtotime($tndate)==strtotime($fdate)){
			echo date("d-M-Y",strtotime($tndate));?> - <?php echo date("l",strtotime($tndate));}
			else echo date("d-M-Y",strtotime($fdate)) ." to ".date("d-M-Y",strtotime($tndate)); ?></p> <p>Daily Collection Report- POCKET EXPENSE</p>	</h5></center>
			<table class="table" cellspacing="0" cellpadding="0" border="1">
				<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>
                    <td>Receipt No</td>
					<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"]."'");
					 $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"]."'");
									$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"]."'");
									//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=array();$GrandNewextra=0;
		$day=date_range($fdate, $tdate);
		$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">
            <thead>
            <tr style="cursor:pointer">
                <td width="5%">S.no</td>
                <td>Date</td>
                <td>Tution Fee</td>
                <td>Transport fee</td>
                <td>Hostel Fee</td>
               <?php
               if(is_array($aryFeeType) && count($aryFeeType)>0){
                foreach($aryFeeType as $ftype){
                    ?><td><?php echo $ftype["type"] ?></td><?php
                }
               }
               ?>
               <td>Term Fee/other</td>
               <td>Fine</td>
               <td>Extra</td> 
               <td>Income</td>
               <td>Total</td>
            </tr>
            </thead>
            <tbody>
		<?php $i=0;
		foreach($day as $thisday){ $i++;
			$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllFine=0;$overAllextra=array();$overAllNewextra=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;
				$installTution=$db->getRows("select ins_name,idno from installment_time where ins_name like 'ip%' and (date between '$fdate' and '$tdate')");
				if(is_array($installTution) && count($installTution)>0){
					foreach($installTution as $installT){
						$tution+=$db->getVal("select ".$installT["ins_name"]." from installment where idno=".$installT["idno"]);
					}
					$overAlltution+=$tution;
					$total+=$tution;
				}
				$installTution=$db->getRows("select ins_name,idno from installment_time where ins_name like 'bp%' and (date between '$fdate' and '$tdate')");
				if(is_array($installTution) && count($installTution)>0){
					foreach($installTution as $installT){
						$trasnport+=$db->getVal("select ".$installT["ins_name"]." from installment where idno=".$installT["idno"]);
					}
					$overAllTransport+=$trasnport;
					$total+=$trasnport;
				}
				$installTution=$db->getRows("select ins_name,idno from installment_time where ins_name like 'hp%' and (date between '$fdate' and '$tdate')");
				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=".$installT["idno"]);
					}
					$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')");$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;
					}
				}
				$installOtherExtra=$db->getRows("select ins_name,idno from installment_time where ins_name like 'other%' and (date between '$fdate' and '$tdate')");
				if(is_array($installOtherExtra) && count($installOtherExtra)>0){
					foreach($installOtherExtra as $installT){
						//other1_detail
						$idSdetail=str_replace("_detail","",$installT[0]);
						$idSdetail=str_replace("other","",$idSdetail);
						$otherExtra+=$db->getVal("select fine from installment_fine where ins_name='".$idSdetail."-otherfee' and idno=".$installT["idno"]);
						//echo $db->getLastQuery();
					}
					$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')");
				$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>
					<?php
					if(is_array($overAllextra) && count($overAllextra)>0){ $gi=0;
						foreach($overAllextra as $ftype){ $gi++;
							?><td><?php echo $ftype; $Grandextra[$gi]+=$ftype; ?></td><?php
						}
					}?>
				   <td><?php echo $overAllOther; $GrandOther+=$overAllOther; ?></td>
				   <td><?php echo $overAllFine; $GrandFine+=$overAllFine; ?></td>
				   <td><?php echo $overAllNewextra; $GrandNewextra+=$overAllNewextra; ?></td>
                   <td><?php echo $tot=(float)$db->getVal("select sum(amount) from transaction where type='deposit' and (udate between '$fdate' and '$tdate') and (tfor='cash' or tfor='cheque')"); ?></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>
            <?php
            if(is_array($Grandextra) && count($Grandextra)>0){
                foreach($Grandextra as $ftype){
                    ?><td><?php echo $ftype ?></td><?php
                }
           }?>
           <td><?php echo $GrandOther ?></td>
           <td><?php echo $GrandFine ?></td>
           <td><?php echo $GrandNewextra ?></td>
           <td><?php echo $overAllTot; ?></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>