<style>

.popup-form{
	margin:0px;
	border:2px solid #600;
	padding:5px;
}
.title{
  text-align: center;
  color: #fff;
  background-color: #1443BD;
  padding: 4px;
  border: 1px inset #1443BD;
  box-shadow: 0px 0px 10px #050101;
  border-radius: 5px;
}
.btn-new{
  background-color: #05967A;
  color: #fff;
  border: 2px outset #05967A;
  padding: 4px 15px;
  font-weight: 700;
  border-radius: 5px;
  box-shadow: 0px 2px #352E2E;
}
.btn-delete{
  background-color: #CA1A1A;
  border: 2px outset #CA1A1A;
  box-shadow: 1px 3px #322C2C;
  color: #fff;
  padding: 4px 15px;
  font-weight: 700;
  border-radius: 5px;
}
.select-text{
	padding: 3px;
  border: 2px solid #747171;
  color: #380303;
  font-weight: 600;
}
.level, .btn-new, .btn-delete{
	margin-left: 10px;
  margin-right: 5px;
}
</style>
<link rel="stylesheet" href="<?php echo URL_ROOT; ?>js/jquery-ui.css">
<script src="<?php echo URL_ROOT; ?>js/jquery-1.10.2.js"></script>
<script src="<?php echo URL_ROOT; ?>js/jquery-ui.js"></script>
<h2 class="title">Sms Detail</h2>
<?php

if(isset($_GET['class']) && trim($_GET['class']) !='')
{ 
	  $month=0;
	  if($_GET["fmonth"]<=3){
		$month=$_GET["fmonth"]+9;
	  }
	  else{
		$month=($_GET["fmonth"]-3);
	  }	  
	  $where="";
	  if(isset($_GET['idno']) && trim($_GET['idno']) !='')$where=" and idno=".$_GET['idno'];
	if($_GET["section"]==''){
	$aryForms=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and (status=1 or status=2) and class='".$_GET["class"]."'  $where order by name");
	}
	
	else{
			$aryForms=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and (status=1 or status=2) and class='".$_GET["class"]."'  and section='".$_GET["section"]."' $where order by name");
		
	}
	//echo count($aryForms);
	
	if(is_array($aryForms) && count($aryForms)>0)
	{	$ij=0;
		foreach($aryForms as $aryForm)
		{ $ij++;
			$_GET["id"]=$aryForm["idno"]; $totalBus=0;$totalFee=0;
			//if($ij==6)exit;
?>
	
	
     <div id="demand-<?php echo $ij; ?>" style="height:100px;border-bottom:1px dotted red; ">
   		
    	 
           
                <center><em><strong><i class="icon-cog"></i> 
				<?php $newMyDate=date("Y")."-".($_GET["fmonth"])."-1";
					 $m= date("F",strtotime($newMyDate)); ?> </strong></em></center>
           
           
                    <?php 
						$aryInstall=$db->getRow("select * from installment where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and session='".$_SESSION["admin"]["session"]."'");
						$feeCount=array();$totalFee=0;$totalBus=0;$totalhostel=0;$extraFee=array();$totalExtra=0;$total=0;$dues=0;$duesother=0;
						$totalother=0;$totalhostelother=0;
						for($i=1;$i<=$month;$i++){
							$iis="i".$i;
							$iip="ip".$i;
							if($aryInstall[$iis]!="" && $aryInstall[$iis]!=0){
								$totalclasspayfee=$totalclasspayfee+$aryInstall[$iip];
								$is_rr=false;
								if($aryInstall[$iip]>0){}else{
									$totalFee+=$aryInstall[$iis];
								}
							}
						}
						$ji=0;
						for($i=1;$i<=$month;$i++){
							$iis="b".$i;
							$iip="bp".$i;$is_rr=false;
							if($aryInstall[$iis]!="" && $aryInstall[$iis]!=0){
								$totalbuspayfee=$totalbuspayfee+$aryInstall[$iip];$ji++;
								$is_rr=false;
								if($aryInstall[$iip]>0){}else{
									  $totalBus+=$aryInstall[$iis]; 
								}
							}
						}
						$aryInstall=$db->getRow("select * from hostelinstallment where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and session='".$_SESSION["admin"]["session"]."'");
						for($i=1;$i<=$month;$i++){
							$iis="i".$i;
							$iip="ip".$i;
							if($aryInstall[$iis]!="" && $aryInstall[$iis]!=0){
								$totalclasspayfee=$totalclasspayfee+$aryInstall[$iip];
								$is_rr=false;
								if($aryInstall[$iip]>0){}else{
									$totalhostel+=$aryInstall[$iis];
								}
							}
						}
						$checkextFee=$db->getRows("select * from extrafee_type where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'");	
						if(is_array($checkextFee) && count($checkextFee)>0){
							foreach($checkextFee as $chkExtFee){
								for($i=1;$i<=$month;$i++){
									$iip="p".$i;
									$mycheckInstall=$db->getRow("select fee,pay from extrafee where idno='".$_GET["id"]."' and type='".$chkExtFee["id"]."' and pid='".$iip."'");
									if($mycheckInstall["fee"]>0){
										$type=$chkExtFee["type"];
										if($mycheckInstall["pay"]==0 || $mycheckInstall["pay"]=="")
										$extraFee[$type]=$extraFee[$type]+$mycheckInstall["fee"];
										$totalExtra=$totalExtra+$extraFee[$type];
									}
								}
							}
						}$totalExt=0;
						/*$install=$db->getRow("select * from otherfee_structure where otype ='".$aryForm['idno']."' and name like '%b%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
						
							if(is_array($install) && count($install)>0){
								$installTution=$db->getRow("select * from installment_fine where idno=".$aryForm['idno']." and reasion = '".$install['name']."'");        if(is_array($installTution) && count($installTution)>0){
								if($install['fee']==$installTution['fine'])
									$dues=0;
								}
							   else 		
								$dues=$install['fee'];
							}*/
						?>
                 <table class="table" cellpadding="0" cellspacing="0" width="100%" border="1">
                 	<tr>
                    	
                <?php    $stype=$aryForm['stype'];
					if($stype=="old"){
						 $aryother=$db->getRows("select  distinct(name) from otherfee_structure where (otype ='' or otype ='old' or otype='".$aryForm['idno']."') and month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); }
						 
				    elseif($stype=="new"){ 
						 $aryother=$db->getRows("select  distinct(name) from otherfee_structure where (otype ='' or otype ='new' or otype='".$aryForm['idno']."') and month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); }
						 
						if(is_array($aryother) && count($aryother)>0){
							
					    		foreach($aryother as $other){?>
                        			
								<?php } }
                       $htype=$aryForm['htype'];
					if($htype=="old"){
						 $aryhostelother=$db->getRows("select  distinct(name) from hostel_otherfee_structure where (otype ='' or otype ='old' or otype='".$aryForm['idno']."') and month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); }
						 
				    elseif($htype=="new"){ 
						 $aryhostelother=$db->getRows("select  distinct(name) from hostel_otherfee_structure where (otype ='' or otype ='new' or otype='".$aryForm['idno']."') and month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); }
					else $aryhostelother=0;		
						if(is_array($aryhostelother) && count($aryhostelother)>0){ $c=0;
					    		foreach($aryhostelother as $other){$c++;?>
                        			
								<?php } } ?>                  
                       <!-- <th>Back Dues</th>-->
                        <?php foreach($extraFee as $key=>$value){ ?>
                        <?php  $key ?>
                        <?php }?>
                        
                    </tr>
                    <tr>
                    	
                <?php if($stype=="old"){
						 $aryother=$db->getRows("select * from otherfee_structure where (otype ='' or otype ='old' or otype='".$aryForm['idno']."') and month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); }
						 
				    elseif($stype=="new"){ 
						 $aryother=$db->getRows("select * from otherfee_structure where (otype ='' or otype ='new' or otype='".$aryForm['idno']."') and month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); } 
						 //echo $db->getLastQuery();
						 if(is_array($aryother) && count($aryother)>0){
					    	foreach($aryother as $other){
								$installOther=$db->getRows("select * from installment_fine where idno=".$aryForm['idno']." and reasion = '".$other['name']."'"); 
														    $total_fine=0;
								$installTution2=$db->getRow("select * from hostelotherfee_discount where idno=".$aryForm['idno']." and other_id='".$other['id']."' and class='".$aryForm["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
								//echo $db->getLastQuery();
								$t=$other['fee'];
								
							if(is_array($installTution2) && count($installTution2)>0){
										 $dis=$installTution2['discount'];
												if($other['fee']==$dis)
													$t=0;
												else 
													$t=$t-$dis;
							 }
					 if($t!=0 && $t<=$other['fee']){
							  if(is_array($installOther) && count($installOther)>0){
									foreach($installOther as $installOther1){
										$total_fine+=$installOther1['fine'];	
										  if($total_fine==$t)	
												$duesother=0;
										   	
										  else
										  	  $duesother=$t-$total_fine;	
							  		}
									if($total_fine!=$t)
										{ $duesother=$t-$total_fine;}
									if(stripos($other["name"], "b") !== FALSE){
										$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$aryForm['idno']." and reasion like 'remain%' ");							 			 $duesother=$duesother-$installTution_remain;
									}
							  }
							 
							   else 		
									$duesother=$t;
							
					 }
					 else{
						 $duesother=0;
					 }
						$totalother+=$duesother;			
						?>			
				     <?php } }?>
                   <?php  if($htype=="old"){
						 $aryhostelother=$db->getRows("select * from hostel_otherfee_structure where (otype ='' or otype ='old' or otype='".$aryForm['idno']."') and month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); }
						 
				    elseif($htype=="new"){ 
						 $aryhostelother=$db->getRows("select * from hostel_otherfee_structure where (otype ='' or otype ='new' or otype='".$aryForm['idno']."') and month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); } 
						 //echo $db->getLastQuery();
					else $aryhostelother=0;		 
						 if(is_array($aryhostelother) && count($aryhostelother)>0){$c=0;
					    	foreach($aryhostelother as $other){$c++;
								$installOther=$db->getRows("select * from installment_fine where idno=".$aryForm['idno']." and reasion = '".$other['name']."'");       	    $total_fine=0;
							  $installTution2=$db->getRow("select * from otherfee_discount where idno=".$aryForm['idno']." and other_id='".$other['id']."' and class='".$aryForm["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
								$t=$other['fee'];
						//echo $fStudent['idno'];exit;	
							if(is_array($installTution2) && count($installTution2)>0){
										 $dis=$installTution2['discount'];
												if($other['fee']==$dis)
													$t=0;
												else 
													$t=$t-$dis;
							 }
					 if($t!=0 && $t<=$other['fee']){
							  if(is_array($installOther) && count($installOther)>0){
									foreach($installOther as $installOther1){
										$total_fine+=$installOther1['fine'];	
										  if($total_fine==$t)	
												$duesother=0;
										   	
										  else
										  		$duesother=$t-$total_fine;	
							  		}
									if($total_fine!=$t)
										{$duesother=$t-$total_fine;}
									if(stripos($other["name"], "b") !== FALSE){
									$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$aryForm['idno']." and reasion like 'remain%' ");							  		$duesother=$duesother-$installTution_remain;
									}
							  }
							 
							   else 		
									$duesother=$t;
							
					 }
					 else{
						 $duesother=0;
					 }
						$totalhostelother+=$duesother;			
						?>		<?php  $duesother; ?>	
                        <?php if($duesother==0){?>
                 <script type="text/javascript">$('.hostelother<?php  $ij.$c ?>').hide()</script>
                        <?php } ?>
				     <?php } }?>
                       <!-- <th><?php  $dues; ?></th>-->
                        <?php foreach($extraFee as $key=>$value){ ?>
                        <?php  $value;$totalExt+=$value; ?>
                        <?php }?>
                        <?php  $total=$totalBus+$totalhostel+$totalFee+$totalExt+$dues+$totalother+$totalhostelother; ?>
						
						<th><?php 
						$d1=$LinksDetails["message"];
						$SMSdetail="Dear Parents, Remaining fee of your child(".$aryForm["name"].") till ".$m." month is Rs.".$total.". ".$d1."";
						
						//echo $total;
						//echo $m.'<br>';
						echo $SMSdetail;
						?>  </th>
						
                    </tr>
                  					
                 </table>
				 
				 
				 
				 
				 
                 
                 <?php if($total==0){?>
                 <script type="text/javascript">$('#demand-<?php echo $ij ?>').hide()</script>
                <!-- <style>#demand<?php echo $ij ?>{display:none;}</style>-->
                 <?php } ?>
                <input type="hidden" name="details[]" value="<?php echo $total."-".$_GET['fmonth']; ?>" />
          
        
    </div>
       

<?php
		}
	}
}

// end 


?> 