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

<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() {
   // Cash.show();
    Cheque.hide();
    NEFT.hide();
    empty.hide();
	
});

$('#Cheque').click(function() {
    Cash.hide();
    NEFT.hide();
    empty.hide();
	
});
$('#NEFT').click(function() {
    Cash.hide();
    Cheque.hide();
    empty.hide();
	
});
$('#showAll').click(function() {
    Cash.show();
    Cheque.show();
    empty.show();
	 NEFT.show();
	
});
});
</script>
<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 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
                                    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" 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 ";
                                        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 ";
                                        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 ";
                                        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 ";
                                        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 ";
                                        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="daily1" 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="submit" name="delete_receipt" class="btn-classic margin">Deleted Receipt</button>
					
					
		<br>			
<input type="button" class="btn btn-danger" id="Cash" value="Cash"  />
<input type="button" class="btn btn-danger" id="Cheque" value="Cheque"  />
<input type="button" class="btn btn-danger" id="NEFT" value="NEFT"  />
<input type="button" class="btn btn-danger" id="showAll" value="showAll"  />

                  <button type="submit" name="cheque_report" class="btn-classic margin">Cheque Report</button>
				 <!-- <button type="submit" name="outstanding_wt_class" class="btn-classic margin">OverAll Due wt_class </button>-->
				  
				  
				  <button type="submit" name="outstanding_wt_class_section" class="btn-classic margin">OverAll Due wt_class_section </button>
				  
				  <button type="submit" name="new_add" class="btn-classic margin">New_add </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"]==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">
				<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
						//echo $db->getErMsg();
						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"]."'  ");
						//print_r($student_details);
						
						//echo  "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 $del_data[idno] ?></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();
		}
	}
	
	// new code
	
	
	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">
                    <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">
                    <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">
                    <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>
			<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>User</td>
					<td>Student Type</td>
                    <td>Receipt No</td>
                    <td>Payment Mode</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){
												
						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,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 status=1   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[0]);
								$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();
							}
							
							
						}*/
						
						$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]."' ");
							

							$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 //$mode= $db->getVal("select if(payment_mode ='',null, payment_mode) from receipt where id in (select id from receipt where  (udate between '$rdate1' and '$sdate1') 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 ");*/
						
                      
					
						?>
						
						
						<tr class="<?php //if(!empty($mode)){ echo $mode; } else echo '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 //$m= $db->getVal("select if(payment_mode ='',null, payment_mode) from receipt where id in ($recno) order by payment_mode DESC ");							
//if($m!='') echo $m;

							?></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>
					<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>
				</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">
				<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"])){
	
		$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"]."' 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- 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>user</td>
                     <td>Student Type</td>
                    <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){
					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;
						/*
						$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;
						}*/
						
						//tu
						$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]."' $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;
						}*/
						
						$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='".$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='".$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();
									}
									
								}*/
								
								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]."' $whereUser");
						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=".$s_id[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='".$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();
									$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;}
												}
											}
										}
										
									}
								}    //$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 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></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>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="10">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"]."' ";
		}
		
			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");
		
		$aryStudentList=$db->getRows("SELECT idno FROM `reff_receipt` WHERE  date between '$fdate' and '$tdate' and session='".$_SESSION["admin"]["session"]."' group by idno");
		
		
		//echo $db->getErMsg().$db->getLastQuery();
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			$tndate = date('Y/m/d', strtotime('-1 days',strtotime($tdate)));
			//echo $tndate." ".$fdate
			?>
            <center><h5><p style="float:right">Collection Date: 
			<?php if(strtotime($tndate)==strtotime($fdate)){
			echo date("d-M-Y",strtotime($tndate));?> - <?php echo date("l",strtotime($tndate));}
			else echo date("d-M-Y",strtotime($fdate)) ." to ".date("d-M-Y",strtotime($tndate)); ?></p> <p>Daily Collection Report- HOSTEL FEE</p>	</h5></center>
			<table class="table" cellspacing="0" cellpadding="0" border="1">
				<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){
						
						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;
						
						$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;
						}
						$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();
		}
	}
	elseif(isset($_REQUEST["hostel_income"])){
		$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllHostelOther=$overAllOther=0;$overAllFine=0;$overAllextra=array();$overAllNewextra=0;$overAllTot=0;
		$whereLocation="";
		if(isset($_GET["location"]) && $_GET["location"]!=""){
			$whereLocation=" and location='".$_GET["location"]."' ";
		}
		
		
			if(isset($_GET["user"]) && $_GET["user"]!=""){
			$whereUser=" and added_by='".$_GET["user"]."' ";
		}
		
		
		$aryStudentList=$db->getRows("select name,fname,admissionno,idno,class from student where school_id='".$_SESSION["admin"]["school_id"]."'  and status=1 $whereLocation and issue_TC=0");
		//print_r($aryStudentList); 
		//echo $db->getErMsg().$db->getLastQuery();
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			$tndate = date('Y/m/d', strtotime('-1 days',strtotime($tdate)));
			//echo $tndate." ".$fdate
			?>
            <center><h5><p style="float:right">Collection Date: 
			<?php if(strtotime($tndate)==strtotime($fdate)){
			echo date("d-M-Y",strtotime($tndate));?> - <?php echo date("l",strtotime($tndate));}
			else echo date("d-M-Y",strtotime($fdate)) ." to ".date("d-M-Y",strtotime($tndate)); ?></p> <p>Daily Collection Report- POCKET MONEY</p>	</h5></center>
			<table class="table" cellspacing="0" cellpadding="0" border="1">
				<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"]."' $whereUser");
					 $total+=$tot;
					 $overAllhotel+=$tot;
						$rdate=date("Y-m-d",strtotime($fdate));
						$sdate=date("Y-m-d",strtotime($tdate));
						$ref=$db->getRows("select * from transaction where type='deposit' and (udate between '$fdate' and '$tdate') and tfor='hostel-income' and rid='".$fStudent["idno"]."' $whereUser");
									$rids=array();
									$rrde=$db->getRows("select * from pocket_receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$fStudent["idno"]."' $whereUser");
									//echo $db->getLastQuery();
								//print_r($rrde);exit;
									//echo "<pre>";print_r($rrde);echo "</pre>";
									if(is_array($rrde) && count($rrde)>0){
										foreach($rrde as $rr){
											$rl_rrid=explode("-",$rr["rrid"]);
											//print_r($rl_rrid);exit;
										foreach($ref as $reff){
											//echo $reff['id'];exit;
											foreach($rl_rrid as $rrids){
											//echo $rrids;exit;
												if($rrids==$reff["id"]){
													$r=$rr['id'];
													if(!($r==$ridss)) {
													$ridss=$r;;
													$rids[]=$ridss;}
												}
											}
										}
										
									}
								}    //$recno=$ridss;
									$recno= implode(",",$rids);
						
						//echo $db->getErMsg();
						if($total>0){ $s++;
						?>
						<tr>
                        	<td><?php echo $s; ?></td>
							<td><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"] ?></td>
							<td><?php if($_GET["location"]=="")echo "All";else echo $db->getVal("select name from location where id='".$_GET["location"]."' and school_id='".$_SESSION["admin"]["school_id"]."'");//date("d-M-y",strtotime($fdate));//" to ".date("d/m/y",strtotime($tdate)); ?></td>
                            <td><?php echo $recno; ?></td>
							<td><?php echo $tot; ?></td>
							<td><?php echo $total;$overAllTotal+=$total; ?></td>
						</tr>
						<?php
						}
					}
					?>
                    
				</tbody>
				<tfoot>
					<td colspan="7">Gross Total</td>
					<td><?php echo $overAllhotel ?></td>
					<td id="completeFeeShw"><?php echo $overAllTotal; ?></td>
				</tfoot>
			</table>  
            Print Date : <?php echo date('d-M-Y'); ?>
			<?php
		}else{
			echo "No record found<br />".$db->getErMsg();
		}
	}
	elseif(isset($_REQUEST["hostel_expance"])){
		$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllHostelOther=$overAllOther=0;$overAllFine=0;$overAllextra=array();$overAllNewextra=0;$overAllTot=0;
		$whereLocation="";
		if(isset($_GET["location"]) && $_GET["location"]!=""){
			$whereLocation=" and location='".$_GET["location"]."' ";
		}
		
			if(isset($_GET["user"]) && $_GET["user"]!=""){
			$whereUser=" and added_by='".$_GET["user"]."' ";
		}
		
		
		$aryStudentList=$db->getRows("select name,fname,admissionno,idno,class from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 $whereLocation and issue_TC=0");
		
		//echo $db->getErMsg().$db->getLastQuery();
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			$tndate = date('Y/m/d', strtotime('-1 days',strtotime($tdate)));
			//echo $tndate." ".$fdate
			?>
            <center><h5><p style="float:right">Collection Date: 
			<?php if(strtotime($tndate)==strtotime($fdate)){
			echo date("d-M-Y",strtotime($tndate));?> - <?php echo date("l",strtotime($tndate));}
			else echo date("d-M-Y", strtotime($fdate)) ." to ".date("d-M-Y",strtotime($tndate)); ?></p> <p>Daily Collection Report- POCKET EXPENSE</p>	</h5></center>
			<table class="table" cellspacing="0" cellpadding="0" border="1">
				<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"]."' $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=array();$GrandNewextra=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">
            <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') $whereUser");
				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') $whereUser");
				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') $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=".$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') $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;
					}
				}
				$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[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') $whereUser"); ?></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>