<script type="text/javascript" src="js/tableExport.js"></script>

<script type="text/javascript" src="js/jquery.base64.js"></script>

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

.outer .MigrateLeftFee{
  background-color: #DADADA !important;
  border: 5px solid #181616 !important;
  min-height: 440px;
  min-width:700px;
}
.st {
	width: 55px;
	font-size:10px;
	display: inline-block;
	color: #021EF0;
}
.size{
	font-size:12px;
}
.recepit {
	width: 717px !important;
	height: 344px !important;
}
.total{
	color: darkgreen;
    font-weight: 800;
}
</style>
<input type="hidden" name="tog" id="togglevalueforzeoshow" value="0" />
<script>


function checkAll(){
	if($('#checkboxa').prop('checked')) {
		$('.checkboxes').prop('checked', true);
		 
    } else {
		
        $('.checkboxes').prop('checked', false);
    }
	
	//var chk=$('input[name=cat]:checked').length;
	
	//alert(chk);
	
}
function  sendAll(){
	checked = $('input[name=sid]:checked');
        if( checked.length > 0 ) {
            var checkValues = checked.map(function(){
               return $(this).val();
            }).get();
			//alert(checkValues);
			//confirm();
			var chk=checkValues.toString();
			$.post( "?src=sms&page_id=sms&type=student", { type: "POST" ,chk: chk} , function( data ) {
	  
				window.location.href = './?src=sms&page_id=sms&type=student&chk='+chk+'';
		});
          /*$.ajax({
                type: "POST",
				 url: "http://127.0.0.1/sms/?page_id=sms&type=student",
                data: { ids: checkValues },
                success:function(data){
						window.location.href = '?page_id=sms&type=student';
					 },
            });*/
        }else{
             alert("You need to pick at least one checkbox!");
        }
	//var date=$("#date").val();
	//$.post( "ajax.php", { type: "DATE_SEARCH" ,date: date } , function( data ) {
	//  	$("#date_content").html(data);
	//	getTotal();
	//});
}

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();
	});
}
function SMS(type){
	if(confirm('Do you want to send sms now..!')){
	//var ids=document.getElementsByName('mobile[]');
	
	var ids=document.getElementsByName('idno[]');
	var detail=document.getElementsByName('details[]');
	var arr = [];
	for(var i=0;i<ids.length;i++){
		arr.push(ids[i].value+"-"+detail[i].value);
	}
	var Fee=arr.join(",");
	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: type ,fee: Fee, fdate:fdate, fmonth:fmonth, fyear:fyear, tdate:tdate, tmonth:tmonth, tyear:tyear,class: cls  } , function( data ) {
		alert(data);
	});
}}
function sendSMDTO(){
	//alert("sms sending process under constration...");
}

function filterPayleft(Tval){
	var val=$(Tval).val();
	if(val.trim()==""){
		$(".MyTotalFee").parent().show();
		$(".MyTotalFee").parent().addClass('none');
	}
	else
	if(!isNaN(val)){
		var allTot="";
		$(".MyTotalLeft").each(function(index, element) {
			var myVal=parseInt($(this).html());
			if(myVal>val)
			{
				$(this).parent().hide('slow');
				$(this).parent().removeClass('none');
			}
			else
			{
				$(this).parent().show('slow');
				$(this).parent().addClass('none');
			}
        });
		//alert(allTot);
	}else{
		alert("Please enter only number");
		$(Tval).val('');
		$(".MyTotalFee").parent().show('slow');
		$(".MyTotalFee").parent().addClass('none');
	}
	var MyTotalFee=0,MyTotalpaid=0,MyTotalLeft=0,MyDiscount=0;
	$(".none").each(function(index, element) {
		MyTotalFee+=parseInt($(this).children('.MyTotalFee').html());
		MyTotalpaid+=parseInt($(this).children('.MyTotalpaid').html());
		MyTotalLeft+=parseInt($(this).children('.MyTotalLeft').html());
		MyDiscount+=parseInt($(this).children('.MyDiscount').html());
	});
	$("#MyTotalFee").html(MyTotalFee);
	$("#MyTotalpaid").html(MyTotalpaid);
	$("#MyTotalLeft").html(MyTotalLeft);
	$("#MyDiscount").html(MyDiscount);
}

function filterPay(Tval){
	var val=$(Tval).val();
	if(val.trim()==""){
		$(".MyTotalFee").parent().show('slow');
		$(".MyTotalFee").parent().addClass('none');
		$(".dynamic").hide('slow');
	}
	else
	if(!isNaN(val)){
		$(".dynamic").show('slow');
		var allTot="";
		$(".MyTotalpaid").each(function(index, element) {
			var myVal=parseInt($(this).html());
			if(myVal>val)
			{
				$(this).parent().hide('slow');
				$(this).parent().removeClass('none');
			}
			else
			{
				$(this).parent().show('slow');
				$(this).parent().addClass('none');
			}
        });
		//alert(allTot);
	}
	else{
		alert("Please user only number");
		$(Tval).val('');
		$(".MyTotalFee").parent().show();
		$(".MyTotalFee").parent().addClass('none');
		$(".dynamic").hide();
	}
	var MyTotalFee=0,MyTotalpaid=0,MyTotalLeft=0,MyDiscount=0,MyTotalLeftDynamic=0;
	$(".none").each(function(index, element) {
		var totalleft=val-parseInt($(this).children('.MyTotalpaid').html());
		$(this).children('.MyTotalLeftDynamic').html(totalleft);
		MyTotalFee+=parseInt($(this).children('.MyTotalFee').html());
		MyTotalpaid+=parseInt($(this).children('.MyTotalpaid').html());
		MyTotalLeftDynamic+=parseInt($(this).children('.MyTotalLeftDynamic').html());
		MyTotalLeft+=parseInt($(this).children('.MyTotalLeft').html());
		MyDiscount+=parseInt($(this).children('.MyDiscount').html());
	});
	$("#MyTotalFee").html(MyTotalFee);
	$("#MyTotalpaid").html(MyTotalpaid);
	$("#MyTotalLeftDynamic").html(MyTotalLeftDynamic);
	$("#MyTotalLeft").html(MyTotalLeft);
	$("#MyDiscount").html(MyDiscount);
}
$(document).ready(function(e) {
	$("#btnduesend").click(function () {
		var ch=$("#togglevalueforzeoshow").val();
		if(ch==0){
			$("#togglevalueforzeoshow").val('1');
	   		filterLeftZero(0)
		}else{
			$("#togglevalueforzeoshow").val('0');
			filterLeftZero(1)
		}
	 });
});
function filterLeftZero(ids){
	var allTot="";
	$(".MyTotalLeft").each(function(index, element) {
		var myVal=parseInt($(this).html());
		if(myVal==0 && ids==0)
		{
			$(this).parent().hide('slow');
			$(this).parent().removeClass('none');
		}
		else
		{
			$(this).parent().show('slow');
			$(this).parent().addClass('none');
		}
	});
	//alert(allTot);
	
	var MyTotalFee=0,MyTotalpaid=0,MyTotalLeft=0,MyDiscount=0;
	$(".none").each(function(index, element) {
		MyTotalFee+=parseInt($(this).children('.MyTotalFee').html());
		MyTotalpaid+=parseInt($(this).children('.MyTotalpaid').html());
		MyTotalLeft+=parseInt($(this).children('.MyTotalLeft').html());
		MyDiscount+=parseInt($(this).children('.MyDiscount').html());
	});
	$("#MyTotalFee").html(MyTotalFee);
	$("#MyTotalpaid").html(MyTotalpaid);
	$("#MyTotalLeft").html(MyTotalLeft);
	$("#MyDiscount").html(MyDiscount);
}
</script>
<?php
$pgMod="attendance_detail";
$pgAct="view";

$monthsList = array(
    'January',
    'February',
    'March',
    'April',
    'May',
  
    'July ',
    'August',
    'September',
    'October',
    'November',
    'December',
);
$monthsList1 = array(
    1=>'Apr',
    2=>'May',
    3=>'Jul ',
    4=>'Aug',
    5=>'Sep',
    6=>'Oct',
    7=>'Nov',
    8=>'Dec',
	9=>'Jan',
    10=>'Feb',
    11=>'Mar'
);





if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);
if($pgAct=="delete" && isset($_GET['id']) && trim($_GET['id'])!='')
{
	$res=$db->delete("student","where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
	if(!is_null($res)) { $_SESSION['msg']='Deleted Successfully'; }
	else { array_push($alert_err,$db->getErMsg()); }
	redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Attandence", "page_id"=>$pgMod)));
}
if(isset($_SESSION['msg']) && $_SESSION['msg']!=""){
	?>
	<div class="alert alert-success">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-thumbs-up-alt"></i> <b>Notice</b><?php echo $_SESSION['msg'] ?></i>
	</div>
	<?php
	unset($_SESSION["msg"]);
}
if(is_array($alert_err) && count($alert_err)>0){
	?>
	<div class="alert alert-error">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-warning-sign"></i> <b>Notice</b> <?php echo $alert_err[0] ?></i>
	</div>
	<?php
}
function inst($str){
	$arr1 = str_split($str);
	if($arr1[1]=="p"){
		$i="Fee ";
		if($arr1[0]=="b")$i="Bus ";
		return $i." "." Installment ".$arr1[2];
	}
	else
		return $str;
}
function instFine($str,$reasion=""){
	global $db;
	$arr1 = explode("-",$str);
	if($arr1[1]=="class")
		$i="<span style='color:#FF0000'>$reasion (Class Fine)</span>";
	elseif($arr1[1]=="bus")
		$i="<span style='color:#00CC00'>$reasion (Bus Fine)</span>";
	elseif($arr1[1]=="otherfee")
		$i="<span style='color:#660000'>$reasion (Other Fee)</span>";
	elseif($arr1[1]=="hostel")
		$i="<span style='color:#FF00FF'>$reasion (Hostel Fine)</span>";
	else{
		$det=$db->getVal("select type from extrafee_type where id='".str_replace("extra","",$arr1[1])."'");
		if($det=="")
		$i="<span style='color:#660000'>$reasion (".$arr1[1].")</span>";
		else
		$i="<span style='color:#660000'>$reasion (".$det.")</span>";
	}
	//if($reasion!="")$i.=" ".$reasion."";
	return $i.$db->getErMsg();;
}
	?>
    <form method="get" action="">
    <input type="hidden" name="src" value="Attandence" />
    <input type="hidden" name="page_id" value="<?php echo $pgMod; ?>" />
	<div class="row-fluid">
            <div class="span12">
            	<div class="top-bar">
                    <br />
                
                    <fieldset style="width:100%; float:left">Detail Section</br>
						<button type="submit" name="attendance" class="btn-classic margin">SINGLE DAY CLASS WISE</button>
							<button type="submit" name="attendance_CLASS" class="btn-classic margin">SINGLE DAY OVERALL CLASS</button>
                     		
                     		

                    </fieldset>

				</div>
				<div class="well no-padding">
                	<div class="controls controls-row">
                        <div class="controls controls-row">
                        <div class="control-group span6">
                            <label class="control-label" for="class">From Date</label>
                            <div class="controls">
                                     <select class="span3" name="fdate"  id="date" style="width: 65px !important;">
                                    <option value="">Date</option>
                                    <?php
									$ndate=date("d");
									$mdate=date("m");
									$ydate=date("Y");
                                    for($m = 01;$m <= 31; $m++){ 
                                        $selected="";
										if($_GET["fdate"]==$m)
										{
											$selected=" selected ";
										}
										if($ndate==$m)
										{
											$selected=" selected ";
										}
                                        echo "<option $selected value='$m'>$m</option>";
                                    }
                                    ?> 
                                </select>
                                <select class="span5" name="fmonth" id="fmonth" style="width: 90px !important;">
                                    <option value="">Month</option>
                                 <?php
                                    for($m = 1;$m <= 12; $m++){ 
                                        $newDate=date("Y")."-".$m."-1";
                                        $month =  date("F",strtotime($newDate));//."(".($ij+3).")";
                                        //$month =  date("F", mktime(0, 0, 0, $m)); 
                                        $selected="";if($_GET["fmonth"]==$m)
										{
											$selected=" selected ";
										}
										
										if($mdate==$m)
										{
											$selected=" selected ";
										}
                                        echo "<option $selected value='$m'>$month</option>";
                                    }
                                 ?> 
                                </select>
                                <select class="span4" name="fyear" id="fyear" style="width: 73px !important;">
                                    <option value="">Year</option>
                                    <?php
                                    for($m = 2013;$m <= 2050; $m++){  
                                        $selected="";if($_GET["fyear"]==$m)
										{	
										$selected=" selected ";
										}										
										if($ydate==$m)
										{	
										$selected=" selected ";
										}
                                        echo "<option $selected value='$m'>$m</option>";
                                    }
                                    ?> 
                                </select>
                                </div>
                        </div>
                        <div class="control-group span6">
                            <label class="control-label" for="medium">To date</label>
                            <div class="controls">
                                    <select class="span3" name="tdate" id="tdate" style="width: 65px !important;">
                                    <option value="">Date</option>
                                    <?php
                                    for($m = 01;$m <= 31; $m++){ 
                                         $selected="";
										 if($_GET["tdate"]==$m)
										 {
											 $selected=" selected ";
										 }
										 if($ndate+1==$m)
										{
											$selected=" selected ";
										}
                                        echo "<option $selected value='$m'>$m</option>";
                                    }
                                    ?> 
                                </select>
                                <select class="span5" name="tmonth" id="tmonth" style="width: 90px !important;">
                                    <option value="">Month</option>
                                 <?php
                                    for($m = 1;$m <= 12; $m++){ 
                                        $newDate=date("Y")."-".$m."-1";
                                        $month =  date("F",strtotime($newDate));//."(".($ij+3).")";
                                        //$month =  date("F", mktime(0, 0, 0, $m)); 
                                        $selected="";if($_GET["tmonth"]==$m)
										{
										$selected=" selected ";
										}
										if($mdate==$m)
										{
											$selected=" selected ";
										}
                                        echo "<option $selected value='$m'>$month</option>";
                                    }
                                 ?> 
                                </select>
                                <select class="span4" name="tyear" id="tyear" style="width: 73px !important;">
                                    <option value="">Year</option>
                                    <?php
                                    for($m = 2013;$m <= 2050; $m++){  
                                         $selected="";if($_GET["tyear"]==$m)
										 {	 
										 $selected=" selected ";
										 }
										 if($ydate==$m)
										{
											$selected=" selected ";
										}
                                        echo "<option $selected value='$m'>$m</option>";
                                    }
                                    ?> 
                                </select>
                                </div>
                        </div>
                    </div>
                        
                      <br>  
                    <div style="float:left;">
                        
                        <select style="width: 165px !important;padding:20px;margin:15px;" name="studentclass" >
                            <option value="">--Select class--</option>
                            <?php 
                                $classes = $db->getRows("Select class from class where status=1 and school_id=1");
                               foreach($classes as $cls){
                                echo "<option>$cls[class]</option>";
                               }
                            ?>
                        </select>

                        <select style="width: 165px !important;padding:20px;margin:15px;" name="studentsection" >
                            <option value="">--Select Section--</option>
                            <?php 
                                $section = $db->getRows("Select name from section where school_id=1");
                               foreach($section as $sec){
                                echo "<option>$sec[name]</option>";
                               }
                            ?>
                        </select>

                        <!--<select style="width: 165px !important;padding:20px;" name="attendancemonth" >-->
                            <!--<option value=''>--Select Month--</option>-->
                                <?php/*
                                    for($m = 1;$m <= 12; $m++){
                                        $newDate=date("Y")."-".$m."-1"; 
                                        $month =  date("F",strtotime($newDate));//."(".($ij+3).")";
                                        echo "<option $selected value='$m'>$month</option>";
                                    }*/
                                 ?> 
                        <!--</select>--> 
                        
                        <!--<button type="submit" name="monthly_attendance" style="background:#FFC224;color:black;font-weight:bold;font-size:16px;border-radius:7px;padding:5px;">MONTHLY ATTENDANCE</button>-->

                        <!--<button type="submit" name="session_attendance" style="background:#FFC224;color:black;font-weight:bold;font-size:16px;border-radius:7px;padding:5px;margin-left:55px;">YEARLY ATTENDANCE</button>-->


                        <button type="submit" name="attendance_report" style="background:#FFC224;color:black;font-weight:bold;font-size:16px;border-radius:7px;padding:5px;margin-left:55px;">TOTAL ATTENDANCE REPORT</button>

                    </div>
                    <br><br><br>


                    </div>
                    
				</div>
			</div>
    </div>
    </form>
	<?php
	$where=array();
	$qry="";
	
	if(isset($_GET["attendance"])){

// 		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
// 			$where[]=" s.stype='".$_GET["stype"]."' ";
// 			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
// 		}
// 		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
// 			$where[]=" s.medium='".$_GET["medium"]."' ";
// 			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
// 		}
// 		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
// 			$where[]=" s.class='".$_GET["class"]."' ";
// 			$conwhere.=" and student.class='".$_GET["class"]."' ";
// 		}
// 		if(isset($_GET["section"]) && $_GET["section"]!=""){
// 			$where[]=" s.section='".$_GET["section"]."' ";
// 			$conwhere.=" and student.section='".$_GET["section"]."' ";
// 		}
// 		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
// 			$where[]=" s.gender='".$_GET["gender"]."' ";
// 			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
// 		}
// 		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
// 			$where[]=" s.cast='".$_GET["cast"]."' ";
// 			$conwhere.="   student.cast='".$_GET["cast"]."' ";
// 		}
// 		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
// 			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
// 			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
// 			$where[]=" (s.dob between '".$end."' and '".$start."')";
// 			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
// 		}
// 		if(isset($_GET["location"]) && trim($_GET["location"])!=""){
// 			$where[]=" s.location='".$_GET["location"]."' ";
// 			$conwhere.=" and student.location='".$_GET["location"]."' ";
// 		}
 
 
// 		$where[]=" s.session='".$_SESSION["admin"]["session"]."' and s.status=1 ";

	    if(isset($_GET["studentclass"]) && trim($_GET["studentclass"])!=""){
			$where[]=" class='".$_GET["studentclass"]."' ";
			$conwhere.=" where class='".$_GET["studentclass"]."' ";
		}
		
		if(isset($_GET["studentsection"]) && trim($_GET["studentsection"])!=""){
			$where[]=" section='".$_GET["studentsection"]."' ";
			$conwhere.=" AND section='".$_GET["studentsection"]."' ";
		}
		
//studentsection
		$where[]=" s.session='".$_SESSION["admin"]["session"]."' and s.status=1 ";

		if(isset($_GET["fyear"]) && trim($_GET["fyear"])!="" && isset($_GET["fmonth"]) && trim($_GET["fmonth"])!="" && isset($_GET["fdate"]) && trim($_GET["fdate"])!="" && isset($_GET["tyear"]) && trim($_GET["tyear"])!="" && isset($_GET["tmonth"]) && trim($_GET["tmonth"])!="" && isset($_GET["tdate"]) && trim($_GET["tdate"])!=""){
			$fdate=$_GET["fyear"]."-".$_GET["fmonth"]."-".$_GET["fdate"];
			$tdate=$_GET["tyear"]."-".$_GET["tmonth"]."-".$_GET["tdate"];
			$where[]=" (date between '$fdate' and '$tdate') ";
			$conwhere1 .=" AND date = '$fdate' ";
		}

		$table=" student as s";
		//echo "<pre>";print_r($result);echo "</pre>";echo $db->getLastQuery();		echo $db->getErMsg();
		?>
		 <div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <h3><i class="icon-cog"></i> Detail</h3>
                <div style="float:right; margin-top:5px">
				<!--<input  class="btn btn-primary" type="button"  onclick="$('.table').tableExport({type:'excel',escape:'false'});" id="btnExport" value=" Export To Excel " />-->
                    <button class="btn btn-success" onclick="exportTableToExcel('tblData', 'Attendance Detail')" style="margin-left:35px;">Excel</button>
                    <button type="button" onclick="printDiv('printDiv2')" class="btn btn-primary">Print</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv2">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>S.No</th>
                            <th>Name</th>
                            <th>Father Name</th>
                            <th>Mobile</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php
  	                    $result=$db->getRows("Select idno, name, fname, mobile  from student $conwhere and session='".$_SESSION["admin"]["session"]."'  and status='1'  order by name");
    					$i=0;  $pr=0;
							foreach($result as $detail){$i++;
								$total=0;
								?>
                                <tr>
                                    <td><?php echo $i; ?></td>
                                    <td><?php echo ucfirst($detail["name"]); ?></td>
                                    <td><?php echo ucfirst($detail["fname"]); ?></td>
                                    <td><?php echo $detail["mobile"]; ?></td>
                                         <?php  $stu_sib=$db->getVal("select count(id) from attandenc where idno='".$detail["idno"]."' and type='2' and date='$fdate' ") ;

                                         if($stu_sib===1)
                                         {
                                           $result_type=1; 
                                           $result_type_a=0; 
                                         
                                         $pr+=$result_type;    
                                         }
                                         else
                                         {
                                            $result_type=0;  
                                            $result_type_a=1;
                                             $pra+=$result_type_a;    
                                         }
                                        
                                          $ijk=0;
                                   
                                          	
                                         ?>
                                       <td><?php if($stu_sib === 1) { echo '<span style="color:red;">A</span>'; } else  { echo 'P'; }  ?></td> 
                                       <!--<td><?php  if($result_type_a=='1') { echo 'P'; } else  { echo 'A'; }  ?></td>  -->
                                   
                                </tr>
								<?php
								 $total=0;
							} //}
					

					
						?>
                    </tbody>
                    <tfoot>
                    	<tr>
                            <td>Total</td>
                            <td><?php echo $i;  ?></td>
                            <td colspan="2"></td>
                            <td><?php echo "<span style='color:red'>Absent - $pr</span>";  ?><br>
                            <?php echo "<span style='color:green'>Present - $pra</span>";  ?></td>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
	}


	if(isset($_GET["attendance_CLASS"])){
		if(isset($_GET["fyear"]) && trim($_GET["fyear"])!="" && isset($_GET["fmonth"]) && trim($_GET["fmonth"])!="" && isset($_GET["fdate"]) && trim($_GET["fdate"])!="" && isset($_GET["tyear"]) && trim($_GET["tyear"])!="" && isset($_GET["tmonth"]) && trim($_GET["tmonth"])!="" && isset($_GET["tdate"]) && trim($_GET["tdate"])!=""){
			$fdate=$_GET["fyear"]."-".$_GET["fmonth"]."-".$_GET["fdate"];
			$tdate=$_GET["tyear"]."-".$_GET["tmonth"]."-".$_GET["tdate"];
			$where[]=" (date between '$fdate' and '$tdate') ";
			$conwhere.="and (r.date between '$fdate' and '$tdate')";
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["section"]) && $_GET["section"]!=""){
			$where[]=" s.section='".$_GET["section"]."' ";
			$conwhere.=" and student.section='".$_GET["section"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.="   student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		if(isset($_GET["location"]) && trim($_GET["location"])!=""){
			$where[]=" s.location='".$_GET["location"]."' ";
			$conwhere.=" and student.location='".$_GET["location"]."' ";
		}
 
 
		$where[]=" s.session='".$_SESSION["admin"]["session"]."' and s.status=1 ";
		$table=" student as s";
		//echo "<pre>";print_r($result);echo "</pre>";echo $db->getLastQuery();		echo $db->getErMsg();
		?>
		 <div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <h3><i class="icon-cog"></i> Detail</h3>
                <div style="float:right; margin-top:5px">
				<!--<input  class="btn btn-primary" type="button"  onclick="$('.table').tableExport({type:'excel',escape:'false'});" id="btnExport" value=" Export To Excel " />-->
                    <button class="btn btn-success" onclick="exportTableToExcel('tblData', 'Attendance Detail')" style="margin-left:35px;">Excel</button>
                    <button type="button" onclick="printDiv('printDiv2')" class="btn btn-primary">Print</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv2">
                
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>S.No</th>
                            <th>Class</th>
                             <th>Section</th>
                             <th>Total No of Student</th>
                            <th>Total Absent</th>
                             <th>Total present</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php
                       $cla= $db->getRows("select class from class");	

	$i=0;$total_tution=0;$total_student=0;$tf=0;
	foreach($cla as $cl){
	
	    $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){$i++;
			
			$section=$sect['section'];
			if(!empty($section)){
			 $where_section=" and section='".$section."' ";

		$total_student= $db->getVal("SELECT count(idno) FROM student WHERE class='".$c."' $where_section AND school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and issue_TC=0 and status=1 ");
		 
			
		//echo '<br>';
		
      // dcr 
    		
		  ?>
                            <tr>
							     <td><?= $i;  ?></td>
							     <td><?=  $c; ?></td>
							     <td><?=  $section; ?></td>
								 <td><?= $total_student;  ?></td>
								  <?php  $stu_sib=$db->getRows("select * from attandenc as r INNER join student as s on s.idno=r.idno where s.class='$c' and s.section='$section' $conwhere and r.type='2'   ") ;
                                        // echo $ss="select * from attandenc as r INNER join student as s on s.idno=r.idno where s.class='$c' and s.section='$section' $conwhere and r.type='2'    ";

                                          $ijk=0;
                                          	foreach($stu_sib as $rows){  $ijk++;
                                             $total+= $ijk;
                                          	}
                                         ?>
                                       <td><?php echo  $ijk; ?></td>   
								  <td><?php echo  $total_student-$ijk;  ?></td>

                                <td>
                                    <?php
                                    $session = $_SESSION["admin"]["session"];
                                    $row_id = $db->getVal("select id from attandenc where class='$c' and section = '$section' and date='$fdate' and type='3' and session = '$session' and status='0' ");
                                    if ($ijk > 0 || $row_id != ''){
                                        echo "Marked";
                                    }else{
                                        echo "Not Marked";
                                    }
                                    ?>
                                </td>
							</tr>
		 <?php
		 $all_total_student+=$total_student; 
			$all_absent+=$ijk;
				$all_present+=$total_student-$ijk;
			    
			    
			}} unset($section);
	unset($where_section);
	
	} ?>
                    </tbody>
                    <tfoot>
                    	<tr>
                        	<th colspan="3">Total</th>
                        	<th col><?php echo  $all_total_student;  ?></th>
                        		<th ><?php echo  $all_absent;  ?></th>
                        			<th ><?php echo  $all_present;  ?></th>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
	}
	
	
	// 07-January-2020
	if(isset($_GET["monthly_attendance"])){
	    
	    if(isset($_GET["studentclass"]) && trim($_GET["studentclass"])!=""){
			$where[]=" class='".$_GET["studentclass"]."' ";
			$conwhere.=" where class='".$_GET["studentclass"]."' ";
		}
		
		if(isset($_GET["studentsection"]) && trim($_GET["studentsection"])!=""){
			$where[]=" section='".$_GET["studentsection"]."' ";
			$conwhere.=" AND section='".$_GET["studentsection"]."' ";
		}
		
//studentsection
		$where[]=" s.session='".$_SESSION["admin"]["session"]."' and s.status=1 ";
		
		
		$class=$_GET['studentclass'];
		$monthnum=$_GET['attendancemonth'];
		$monthname = date('F', mktime(0, 0, 0, $monthnum, 1));
		$currentyear = date("Y");
		
		if($monthnum > 3){
		    $year = ($currentyear-1);
		}
		else {
		    $year = $currentyear;
		}
		
		$total_days=cal_days_in_month(CAL_GREGORIAN, $monthnum, $year);
		
		function total_sun($month,$year)
        {
            $sundays=0;
            $total_days=cal_days_in_month(CAL_GREGORIAN, $month, $year);
            for($i=1;$i<=$total_days;$i++)
            if(date('N',strtotime($year.'-'.$month.'-'.$i))==7)
            $sundays++;
            return $sundays;
        }
        $totalsundays=total_sun($monthnum, $year);
        
        $holidays=$db->getRows("SELECT COUNT(*) FROM holiday WHERE session='".$_SESSION["admin"]["session"]."' AND month='$monthname' AND class='$class' GROUP BY id HAVING COUNT(*) >= '1' ");

        $totalholidays=count($holidays);
        
        $totalworkingdays= ($total_days - ($totalsundays + $totalholidays));

		?>
		<div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <h3><i class="icon-cog"></i> Detail</h3>
                <div style="float:right; margin-top:5px">
				<!--<input  class="btn btn-primary" type="button"  onclick="$('.table').tableExport({type:'excel',escape:'false'});" id="btnExport" value=" Export To Excel " />-->
                    <button class="btn btn-success" onclick="exportTableToExcel('tblData', 'Attendance Detail')" style="margin-left:35px;">Excel</button>
                    <button type="button" onclick="printDiv('printDiv2')" class="btn btn-primary">Print</button>
                </div>
                <div style="position:absolute;margin-top:60px;text-align:center;font-family:arial;font-weight:normal;font-size:18px;">
                    <table class="table-bordered">
                        <tr>
                            <td>Class  <?php echo $class; ?></td>
                            <td>Month  <?php echo $monthname; ?></td>
                            <td>Total Working Days  <?php echo $totalworkingdays; ?></td>
                        </tr>
                    </table>
                </div>

            </div>

             <div class="well no-padding" id="printDiv2">

                <table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>S.No</th>
                            <th>Name</th>
                            <th>F. Name</th>
                            <th>Total present</th>
                            <th>Total Absent</th>
                            <th>Total Working Days</th>
                            <th>Total Holidays</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                             $students = $db->getRows("Select idno, name, fname  from student $conwhere and session='".$_SESSION["admin"]["session"]."'  and status='1'  order by name");

                             $i=0;
                             foreach($students as $stu){ $i++;
                             
                             $result1 = $db->getRows("SELECT COUNT(attandenc.idno) as absent FROM attandenc WHERE idno='$stu[idno]' AND month='$monthname' AND session='".$_SESSION["admin"]["session"]."' ");
                             
                            foreach ($result1 as $row2) {
                                // print_r($row2);
                             $totalpresent=$totalworkingdays-$row2['absent'];
                             $studentid=$row[1];
                        ?>
                        <tr>
                        <td><?php echo $i; ?></td>
                        <td><?php echo $stu['name']; ?></td>
                        <td><?php echo $stu['fname']; ?></td>
                        <td><?php echo $totalpresent; ?></td>
                        <td><?php echo $row2['absent']; ?></td>
                        <td><?php echo $totalworkingdays; ?></td>
                        <td><?php echo $totalholidays; ?></td>
                        </tr>
                        <?php  } } ?>
                    </tbody>
                    
                    
                </table>
            
            
		    </div>
		</div>
	 <?php   
	}

/*
    if(isset($_GET["attendance_report"])){
        $where  =   "";
		if(isset($_GET["fyear"]) && trim($_GET["fyear"])!="" && isset($_GET["fmonth"]) && trim($_GET["fmonth"])!="" && isset($_GET["fdate"]) && trim($_GET["fdate"])!="" && isset($_GET["tyear"]) && trim($_GET["tyear"])!="" && isset($_GET["tmonth"]) && trim($_GET["tmonth"])!="" && isset($_GET["tdate"]) && trim($_GET["tdate"])!=""){
			$fdate=$_GET["fyear"]."-".$_GET["fmonth"]."-".$_GET["fdate"];
			$tdate=$_GET["tyear"]."-".$_GET["tmonth"]."-".$_GET["tdate"];
			$where.=" (date between '$fdate' and '$tdate') ";
// 			$conwhere1 .=" AND date = '$fdate' ";
		}


	    if(isset($_GET["studentclass"]) && trim($_GET["studentclass"])!=""){
// 			$where[]=" class='".$_GET["studentclass"]."' ";
			$conwhere.=" where class='".$_GET["studentclass"]."' ";
		}

		if(isset($_GET["studentsection"]) && trim($_GET["studentsection"])!=""){
// 			$where[]=" section='".$_GET["studentsection"]."' ";
			$conwhere.=" AND section='".$_GET["studentsection"]."' ";
		}

// 		$where[]=" s.session='".$_SESSION["admin"]["session"]."' and s.status=1 ";

        $class=$_GET['studentclass'];

        $currentmonth = date('m');

        $total_days_month = 0;
        $totalsundays = 0;
        $totalholidays=0;

        $start = new DateTime("$fdate");
        $end = new DateTime("$tdate");
        $days = $start->diff($end, true)->days;

        $totalsundays = intval($days / 7) + ($start->format('N') + $days % 7 >= 7);

        $holidays=$db->getRows("SELECT COUNT(*) FROM holiday WHERE session='".$_SESSION["admin"]["session"]."' AND $where AND class='$class' GROUP BY id HAVING COUNT(*) >= '1' ");

        $totalholidays = count($holidays);

        $totalworkingdays= ($days - ($totalsundays + $totalholidays));

        ?>

        <div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <h3><i class="icon-cog"></i> Detail</h3>
                <div style="float:right; margin-top:5px">
				<!--<input  class="btn btn-primary" type="button"  onclick="$('.table').tableExport({type:'excel',escape:'false'});" id="btnExport" value=" Export To Excel " />-->

                    <!--<button class="btn btn-success" onclick="exportTableToExcel('tblData', 'Attendance Detail')" style="margin-left:35px;">Excel</button>-->
                        <input type="button" class="btn btn-primary" id="btn_excel" value="Excel" style="float:right;"/>
                    <button type="button" onclick="printDiv('printDiv2')" class="btn btn-primary">Print</button>
                </div>
                

            </div>


            <div class="well no-padding divclass" id="printDiv2">
                <input type="hidden" id="filename" value="Student Attendance Report" />
                
                <table style="width:100%;">
            	     <tr>
            	         <td><img src="<?php echo $LinksDetails["logo"]; ?>" height="90px" width="110px" style="margin:0px 0px 3px 10px;"></td>
            	         <td style="text-align:center;margin-bottom:18px;padding-right:200px !important;"><h1 style="font-size:30px;margin:5px 0px 0px 0px;color: #EC1E1E;"><?php echo ucfirst($LinksDetails["site_name"]) ?></h1>
            		         <span style="font-size:16px;font-weight:800;  color: #186916;"> <?php echo ucfirst(nl2br($LinksDetails["contact_content"])) ?></span>
            	         </td>
            	     </tr>
            	 </table>
            	 <table class="table" cellspacing="0">
                    <tr>
                        <td>Class  <?php echo $class; ?></td>
                        <td>Total Working Days <?php echo $totalworkingdays; ?>  </td>
                    </tr>
                </table>
                <table class="table" cellspacing="0" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>S.No</th>
                            <th>Roll No.</th>
                            <th>Name</th>
                            <th>F. Name</th>
                            <th>Total present</th>
                            <th>Total Absent</th>
                            <th>Total Working Days</th>
                            <th>Total Holidays</th>
                            <th>Present Percentage</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                             $students = $db->getRows("Select idno, name, fname, fincome  from student $conwhere and session='".$_SESSION["admin"]["session"]."'  and status='1'  order by cast(fincome as signed), name");

                             $i=0;
                             foreach($students as $stu){ $i++;
                             $result1 = $db->getRows("SELECT COUNT(attandenc.idno) as absent FROM attandenc WHERE idno='$stu[idno]' AND date >= '$fdate' and date < '$tdate' AND session='".$_SESSION["admin"]["session"]."' and type='2' ");

                            foreach ($result1 as $row2) {
                             $totalpresent=$totalworkingdays-$row2['absent'];
                             $studentid=$row[1];
                        ?>
                        <tr>
                        <td><?php echo $i; ?></td>
                        <td><?php echo $stu['fincome']; ?></td>
                        <td><?php echo $stu['name']; ?></td>
                        <td><?php echo $stu['fname']; ?></td>
                        <td><?php echo $totalpresent; ?></td>
                        <td><?php echo $row2['absent']; ?></td>
                        <td><?php echo $totalworkingdays; ?></td>
                        <td><?php echo $totalholidays; ?></td>
                        <td><?php echo number_format(($totalpresent/$totalworkingdays)*100,2); ?> %</td>
                        </tr>
                        <?php  } } ?>
                    </tbody>

                </table>
                <style>
                    @media print {
                        .headPrint {display:none !important;}
                    }
                </style>
		    </div>

        </div>

        </div>
        <?php
    }
*/

    if(isset($_GET["attendance_report"])){
        $where  =   "";
		if(isset($_GET["fyear"]) && trim($_GET["fyear"])!="" && isset($_GET["fmonth"]) && trim($_GET["fmonth"])!="" && isset($_GET["fdate"]) && trim($_GET["fdate"])!="" && isset($_GET["tyear"]) && trim($_GET["tyear"])!="" && isset($_GET["tmonth"]) && trim($_GET["tmonth"])!="" && isset($_GET["tdate"]) && trim($_GET["tdate"])!=""){
			$fdate=$_GET["fyear"]."-".$_GET["fmonth"]."-".$_GET["fdate"];
			$fnewDate = date("d-M-Y", strtotime($fdate));
			$tdate=$_GET["tyear"]."-".$_GET["tmonth"]."-".$_GET["tdate"];
				$tnewDate = date("d-M-Y", strtotime($tdate));
			$where.=" (date between '$fdate' and '$tdate') ";
// 			$conwhere1 .=" AND date = '$fdate' ";
		}


	    if(isset($_GET["studentclass"]) && trim($_GET["studentclass"])!=""){
// 			$where[]=" class='".$_GET["studentclass"]."' ";
			$conwhere.=" where class='".$_GET["studentclass"]."' ";
		}

		if(isset($_GET["studentsection"]) && trim($_GET["studentsection"])!=""){
// 			$where[]=" section='".$_GET["studentsection"]."' ";
			$conwhere.=" AND section='".$_GET["studentsection"]."' ";
		}

// 		$where[]=" s.session='".$_SESSION["admin"]["session"]."' and s.status=1 ";

        ////////////////////////// where condition for correct holiday count ////////////

        $whereHoliday  =   "";
        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"];
            $fnewDate = date("d-M-Y", strtotime($fdate));
            $tdate=$_GET["tyear"]."-".$_GET["tmonth"]."-".$_GET["tdate"];
            $tnewDate = date("d-M-Y", strtotime($tdate));

            $to_date_one_less = (new DateTime("$tdate"))->sub(new DateInterval('P1D'));
            $to_date_where = $to_date_one_less->format('Y-m-d');
            $whereHoliday.=" (date between '$fdate' and '$to_date_where') ";
// 			$conwhere1 .=" AND date = '$fdate' ";
        }

        ////////////////////////////////////////////

        $class=$_GET['studentclass'];
        $section = $_GET['studentsection'];
        $currentmonth = date('m');

        $total_days_month = 0;
        $totalsundays = 0;
        $totalholidays=0;

        $start = new DateTime("$fdate");
        $end = new DateTime("$tdate");

        $days = $start->diff($end, true)->days;

        ////////////////// 1 day substracted from end date (sunday n holiday) for correct counting ///////////////
        $end_one_day_less = (new DateTime("$tdate"))->sub(new DateInterval('P1D'));

        $days_new = $start->diff($end_one_day_less, true)->days;

        $totalsundays = intval($days_new / 7) + ($start->format('N') + $days_new % 7 >= 7);

        $holidays=$db->getRows("SELECT COUNT(*) FROM holiday WHERE session='".$_SESSION["admin"]["session"]."' AND $whereHoliday AND class='$class' GROUP BY id HAVING COUNT(*) >= '1' ");

        $totalholidays = count($holidays);

        $totalworkingdays= ($days - ($totalsundays + $totalholidays));

        ?>

        <div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <h3><i class="icon-cog"></i> Detail</h3>
                <div style="float:right; margin-top:5px">
				<!--<input  class="btn btn-primary" type="button"  onclick="$('.table').tableExport({type:'excel',escape:'false'});" id="btnExport" value=" Export To Excel " />-->

                    <!--<button class="btn btn-success" onclick="exportTableToExcel('tblData', 'Attendance Detail')" style="margin-left:35px;">Excel</button>-->
                        <input type="button" class="btn btn-primary" id="btn_excel" value="Excel" style="float:right;"/>
                    <button type="button" onclick="printDiv('printDiv2')" class="btn btn-primary">Print</button>
                </div>
                

            </div>


            <div class="well no-padding divclass" id="printDiv2">
                <input type="hidden" id="filename" value="Student Attendance Report" />
                
                <table style="width:100%;">
            	     <tr>
            	         <td><img src="<?php echo $LinksDetails["logo"]; ?>" height="90px" width="110px" style="margin:0px 0px 3px 10px;"></td>
            	         <td style="text-align:center;margin-bottom:18px;padding-right:200px !important;"><h1 style="font-size:30px;margin:5px 0px 0px 0px;color: #EC1E1E;"><?php echo ucfirst($LinksDetails["site_name"]) ?></h1>
            		         <span style="font-size:16px;font-weight:800;  color: #186916;"> <?php echo ucfirst(nl2br($LinksDetails["contact_content"])) ?></span>
            	         </td>
            	         
            	     </tr>
            	     <!--<tr>-->
            	     <!--    <td><p>Attendance Report </p> </td>-->
            	     <!--</tr>-->
            	 </table>
            	 <table class="table" cellspacing="0">
                    <tr>
                        <td>Class  <?php echo $class; ?>-<?php echo $section; ?></td>
                        <td>Total Working Days <?php echo $totalworkingdays; ?>  </td>
                        <td style="text-align:center"><p>Attendance Report</p>  </td>
                        <td><p style="float:right">Date:<?php echo $fnewDate.' to '.$tnewDate; ?></p> </td>
                        
                    </tr>
                </table>
                <table class="table" cellspacing="0" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>S.No</th>
                            <th>Adm No.</th>
                            <th>Name</th>
                            <th>F. Name</th>
                            <th>Total present</th>
                            <th>Total Absent</th>
                            <th>Total Working Days</th>
                            <th>Total Holidays</th>
                            <th>Present Percentage</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                             $students = $db->getRows("Select idno, name, fname, fincome, admissionno  from student $conwhere and session='".$_SESSION["admin"]["session"]."'  and status='1'  order by cast(admissionno as signed), name");

                             $i=0;
                             foreach($students as $stu){ $i++;
                             $result1 = $db->getRows("SELECT COUNT(attandenc.idno) as absent FROM attandenc WHERE idno='$stu[idno]' AND date >= '$fdate' and date < '$tdate' AND session='".$_SESSION["admin"]["session"]."' and type='2' ");

                            foreach ($result1 as $row2) {
                             $totalpresent=$totalworkingdays-$row2['absent'];
                             $studentid=$row[1];
                        ?>
                        <tr>
                        <td><?php echo $i; ?></td>
                        <td><?php echo $stu['admissionno']; ?></td>
                        <td><?php echo $stu['name']; ?></td>
                        <td><?php echo $stu['fname']; ?></td>
                        <td><?php echo $totalpresent; ?></td>
                        <td><?php echo $row2['absent']; ?></td>
                        <td><?php echo $totalworkingdays; ?></td>
                        <td><?php echo $totalholidays; ?></td>
                        <td><?php echo number_format(($totalpresent/$totalworkingdays)*100,2); ?> %</td>
                        </tr>
                        <?php  } } ?>
                    </tbody>

                </table>
                <style>
                    @media print {
                        .headPrint {display:none !important;}
                    }
                </style>
		    </div>

        </div>

        </div>
        <?php
    }


	
	// 08-January-2020

    if(isset($_GET["session_attendance"])){
	    
	    if(isset($_GET["studentclass"]) && trim($_GET["studentclass"])!=""){
			$where[]=" class='".$_GET["studentclass"]."' ";
			$conwhere.=" where class='".$_GET["studentclass"]."' ";
		}
		
		if(isset($_GET["studentsection"]) && trim($_GET["studentsection"])!=""){
			$where[]=" section='".$_GET["studentsection"]."' ";
			$conwhere.=" AND section='".$_GET["studentsection"]."' ";
		}

		$where[]=" s.session='".$_SESSION["admin"]["session"]."' and s.status=1 ";

        $class=$_GET['studentclass'];

        $currentmonth = date('m');

        $total_days_month = 0;
        $totalsundays = 0;
        $totalholidays=0;

        function total_sun($month,$year)
        {
            $sundays=0;
            $total_days=cal_days_in_month(CAL_GREGORIAN, $month, $year);
            for($i=1;$i<=$total_days;$i++)
            if(date('N',strtotime($year.'-'.$month.'-'.$i))==7)
            $sundays++;
            return $sundays;
        }

        if($currentmonth == 1 || $currentmonth ==2 || $currentmonth == 3){

         $year = date('Y')-1;

          for($month=4;$month<=12;$month++){

            $monthname = date('F', mktime(0, 0, 0, $month, 1));

            $total_days_month +=cal_days_in_month(CAL_GREGORIAN, $month, $year);

            $totalsundays +=total_sun($month, $year);

            $holidays=$db->getRows("SELECT COUNT(*) FROM holiday WHERE session='".$_SESSION["admin"]["session"]."' AND month='$monthname' AND class='$class' GROUP BY id HAVING COUNT(*) >= '1' ");

            $totalholidays +=count($holidays);

            }

            for($m=1;$m<=$currentmonth;$m++){
                $monthname = date('F', mktime(0, 0, 0, $m, 1));

               $total_days_month +=cal_days_in_month(CAL_GREGORIAN, $m, $year+1); 

               $totalsundays +=total_sun($m, $year+1);

               $holidays=$db->getRows("SELECT COUNT(*) FROM holiday WHERE session='".$_SESSION["admin"]["session"]."' AND month='$monthname' AND class='$class' GROUP BY id HAVING COUNT(*) >= '1' ");

            $totalholidays +=count($holidays);

            }
            
            $totalworkingdays= ($total_days_month - ($totalsundays + $totalholidays));

        }
        else {
            
             $year = date('Y');

          for($month=4;$month<=$currentmonth;$month++){

            $monthname = date('F', mktime(0, 0, 0, $month, 1));

            $total_days_month +=cal_days_in_month(CAL_GREGORIAN, $month, $year);

            $totalsundays +=total_sun($month, $year);

            $holidays=$db->getRows("SELECT COUNT(*) FROM holiday WHERE session='".$_SESSION["admin"]["session"]."' AND month='$monthname' AND class='$class' GROUP BY id HAVING COUNT(*) >= '1' ");

            $totalholidays +=count($holidays);

            }
            $totalworkingdays= ($total_days_month - ($totalsundays + $totalholidays));
            
        }

        // echo "<br>Total Days till current month : ".$total_days_month;
        // echo "<br>Total Working Days : ".$totalworkingdays;
        // echo "<br>Sundays : ".$totalsundays;
        // echo "<br>Holidays : ".$totalholidays;

        ?>

        <div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <h3><i class="icon-cog"></i> Detail</h3>
                <div style="float:right; margin-top:5px">
				<!--<input  class="btn btn-primary" type="button"  onclick="$('.table').tableExport({type:'excel',escape:'false'});" id="btnExport" value=" Export To Excel " />-->

<button class="btn btn-success" onclick="exportTableToExcel('tblData', 'Attendance Detail')" style="margin-left:35px;">Excel</button>
                    <button type="button" onclick="printDiv('printDiv2')" class="btn btn-primary">Print</button>
                </div>
                <div style="position:absolute;margin-top:60px;text-align:center;font-family:arial;font-weight:normal;font-size:18px;">
                    <table class="table-bordered">
                        <tr>
                            <td>Class  <?php echo $class; ?></td>
                            <td>Total Working Days <?php echo $totalworkingdays; ?>  </td>
                        </tr>
                    </table>
                </div>

            </div>


            <div class="well no-padding" id="printDiv2">

                <table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>S.No</th>
                            <th>Name</th>
                            <th>F. Name</th>
                            <th>Total present</th>
                            <th>Total Absent</th>
                            <th>Total Working Days</th>
                            <th>Total Holidays</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                             $students = $db->getRows("Select idno, name, fname  from student $conwhere and session='".$_SESSION["admin"]["session"]."'  and status='1'  order by name");

                             $i=0;
                             foreach($students as $stu){ $i++;

                             $result1 = $db->getRows("SELECT COUNT(attandenc.idno) as absent FROM attandenc WHERE idno='$stu[idno]' AND month='$monthname' AND session='".$_SESSION["admin"]["session"]."' ");

                            foreach ($result1 as $row2) {
                             $totalpresent=$totalworkingdays-$row2['absent'];
                             $studentid=$row[1];
                        ?>
                        <tr>
                        <td><?php echo $i; ?></td>
                        <td><?php echo $stu['name']; ?></td>
                        <td><?php echo $stu['fname']; ?></td>
                        <td><?php echo $totalpresent; ?></td>
                        <td><?php echo $row2['absent']; ?></td>
                        <td><?php echo $totalworkingdays; ?></td>
                        <td><?php echo $totalholidays; ?></td>
                        </tr>
                        <?php  } } ?>
                    </tbody>

                </table>

		    </div>

        </div>

        <?php
    }

		
		
			if(isset($_GET["root_outstanding"])){
		if(isset($_GET["fyear"]) && trim($_GET["fyear"])!="" && isset($_GET["fmonth"]) && trim($_GET["fmonth"])!="" && isset($_GET["fdate"]) && trim($_GET["fdate"])!="" && isset($_GET["tyear"]) && trim($_GET["tyear"])!="" && isset($_GET["tmonth"]) && trim($_GET["tmonth"])!="" && isset($_GET["tdate"]) && trim($_GET["tdate"])!=""){
			$fdate=$_GET["fyear"]."/".$_GET["fmonth"]."/".$_GET["fdate"];
			$tdate=$_GET["tyear"]."/".$_GET["tmonth"]."/".$_GET["tdate"];
			$where[]=" (s.udate between '$fdate' and '$tdate') ";
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["section"]) && $_GET["section"]!=""){
			$where[]=" s.section='".$_GET["section"]."' ";
			$conwhere.=" and student.section='".$_GET["section"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		if(isset($_GET["location"]) && trim($_GET["location"])!=""){
			$where[]=" s.location='".$_GET["location"]."' ";
			$conwhere.=" and student.location='".$_GET["location"]."' ";
		}
	
	
	
	
	
			$overAllTotal=0;$overAllTransport=0;
		
		$month=$_GET["fmonth"];$m=0;
		  if($month<4){
			$m=($month+9);
		  }
		  else{
			$m=$month-3;
		  }
		  //echo $m;
		//if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
          <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List" style="float:left;" />
          <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Transport Fee outstanding</p>	</h5></center>
			<table class="table" cellpadding="0" cellspacing="0" border="1">
				<thead>
				<tr>
                	<td>S.No</td>
					<td>Student Name</td>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<td>Class</td>
                    <td>Section</td>
                     <td>Bus Root</td>
					<td>Contact No</td>
                     <?php
                    
                     if($_GET["fmonth"]=='4' ||$_GET["fmonth"]=='5')
                     {
                         
                     }
                     else
                     {
                     $m=$m-1;
                     }
			   if(is_array($monthsList) && count($monthsList)>0){
				for($i=1;$i<=$m;$i++){
				    
				    
					?><th width="0.5%"><?php echo $monthsList1[$i]; ?></th><?php
				}
			   }
			  
			  ?>
               <td>Total</td>
			</tr>
			</thead>
			<tbody>
		<?php
		$i=0;$total_comp=0;
                   	 $stu_sib=$db->getval("select bus from driver where idno='".$_GET['driver']."'");
									
		
									$csvString= "$stu_sib";
									
$options = explode(",", $csvString);
//print_r($options);
$options = array_filter($options);  
foreach($options as $val) {
		
	$aryStudentList=$db->getRows("SELECT * FROM student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and issue_TC=0  and status='1' and bus='".$val."' order by name");

		
		
		
					foreach($aryStudentList as $fStudent){$i++;
					$mn=$m;
					?>
                    <tr>
                        	<td><?php echo $i ?></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 echo $fStudent["section"] ?></td>
                        <td><?php echo  $stu_root=$db->getval("select root from bus where id='".$fStudent['bus']."'"); ?></td>

							<td><?php echo $fStudent["mobile"]//$newDate="2015-".$month."-1"; echo   date("F",strtotime($newDate)); ?></td>
                      <?php     
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$c=0;
							foreach($monthsList1 as $key=>$val){$c++;
							if($mn==0){
								
							}
							else{ $mn--;
							
						$installTution=$db->getRow("select b".$key.",bp".$key." from installment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
							if($installTution[1]=="" || $installTution[1]=="0")
								$trasnport=$installTution[0];
							else
								$trasnport=0;
						}else{
							$trasnport="";
						}
						$overAllTransport=$trasnport;
						
						if($overAllTransport=="0")
						 $total==0;
						elseif($overAllTransport=="")
						{$total="";}
						else $total=$overAllTransport;;
						$total_full=$total_full+$total;
							?><td><?php if($total=="0")echo "<lable style='color:red'>paid</label>";elseif($total=="") echo "<lable style='color:red'>X</label>"; else echo $total; ?></td>		<?php }}
					
						//echo $i."-".$t.$other1."<br/>";
					
						
					?><td class="MyTotalLeft"><?php echo $total_full; ?></td>
                    		
<?php $total_comp+=$total_full; } }?>
			</tbody>
			<?php
			
	
			
			?>
				<tfoot>
					<td colspan="<?php echo $m+8; ?>">Gross Total</td>
					
				   <td><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
         <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	   
<?php //}
	}
	//echo "<pre>";print_r($result);echo $db->getLastQuery();
	//echo $db->getErMsg();
	
?>

	<script type="text/javascript">
	$(document).ready(function(e) {
		var oTable = $('.table').dataTable( {
			"bPaginate": false,
			"bLengthChange": false,
			"bFilter": true,
			"bSort": true,
			"bInfo": true,
			"bAutoWidth": false
		});
	});
	function activeNowMe(id){
		$.ajax({
			url: "<?php echo URL_ROOT ?>Promote/ajax.php?type=activeMe&id="+id
		}).done(function(data) {
			$("#row"+id).hide("slow");
		});
	}
	function getStudentPopup(){
		var url="";
		$(".checkboxes").each(function(){
			if($(this).prop('checked')==true){
				var idno=$(this).val();
				var name=$(".name"+idno).html()
				var left=$(".left"+idno).html()
				url+="&"+name+"`"+idno+"="+left;
			}
		})
		if(url!=""){
			getPopup("<?php echo URL_ROOT ?>Promote/?page_id=MigrateLeftFee&class=<?php echo $_GET["class"] ?>"+url,"1","MigrateLeftFee");
			$(".close").click(function() {
				$(this).parent().remove();
			});
			$(".outer").click(function() {
				$(this).remove();
			});

		}else{
			alert("select atleast one student to mgrate");
		}
	}
	
	    function exportTableToExcel(tableID, filename = '',e){
    
    var tableType = document.getElementById('tblData').getAttribute("data-tblname");

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

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

    $("#btn_excel").click(function(e) {
            var filename = $("#filename").val();
            $(".newtable").hide();
        let file = new Blob([$('.divclass').html()], {type:"application/vnd.ms-excel"});
        let url = URL.createObjectURL(file);
        let a = $("<a />", {
        href: url,
        download: filename+".xls"}).appendTo("body").get(0).click();
        e.preventDefault();
    });
    
	</script>
    <style>
    tfoot{display: table-footer-group !important;}
	.MigrateLeftFee{width:650px !important}
    </style>