<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( "?page_id=sms&type=student", { type: "POST" ,chk: chk} , function( data ) {
	  
				window.location.href = './?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="student_list";
$pgAct="view";
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"=>"Student", "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();;
}
	?>
	    <input type="button" class="btn btn-primary" id="btn_excel" value="Excel" style="float:right;"/>
<button type="button" style="float:right" onclick="printDiv('printDiv')" class="btn btn-danger">Print</button>
<div id="printDiv" class="divclass">
	<?php
		$aryClass=$db->getRows("select * from class where school_id='".$_SESSION["admin"]["school_id"]."' and status=1 order by id");
		$section=$db->getRows("select * from section where school_id='".$_SESSION["admin"]["school_id"]."' order by name ");
		
		if(is_array($aryClass) && count($aryClass)>0){
			?>
      <center><h2>Class Wise Total Student List</h2></center>

		<table class="table" cellpadding="0" cellspacing="0" border="1" id="tblData" data-tblname="Student List">
			<thead>
				<tr>
                	<th>S.No</th>
					<th>Class</th>
                    <th>Boys</th>
                    <th>Girls</th>
					<th>Section Total </th>
					<th>Dropout</th>
                    <th>TC</th>
                    <th>New</th>
    			</tr>
			</thead>
			<tbody>
		<?php	$i=0;$total_male=$total_female=$total_student=$total_cancel=0;$total=0; $totaltc = 0; $totalnew = 0;
					foreach($aryClass as $fclass){ $totalsecboys = 0; $totalsecgirls = 0; $totalsection = 0;
					            $totalsecdropout = 0; $totalsectc = 0; $totalsecnew = 0;
                        $allstudent = $db->getVal("select Count(*) from student where class='".$fclass["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 ");
                        if($allstudent > 0){
                        
    					$male=$db->getVal("select Count(*) from student where class='".$fclass["class"]."' and section='' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 and gender = 'male'");
    					$female=$db->getVal("select Count(*) from student where class='".$fclass["class"]."' and section='' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 and gender = 'female'");
    					$tcStudent=$db->getVal("select Count(*) from student where class='".$fclass["class"]."' and section='' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=3 and remarks='TC' and issue_TC=0 ");
    					$cancelStudent=$db->getVal("select Count(*) from student where class='".$fclass["class"]."' and section='' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=3 and issue_TC=0 ");

                        $newstudent = $db->getVal("select Count(*) from student where class='".$fclass["class"]."' and section='' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 and stype='new' ");

                        $sectotal = $db->getVal("select Count(*) from student where class='".$fclass["class"]."' and section='' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 ");
                        if($sectotal > 0){
        						$total_male+=$male;	$total_female+=$female;	$total_student+=$sectotal; $total_cancel+=$cancelStudent;
        						$totaltc+=$tcStudent; $totalnew+=$newstudent;
        						$totalsecboys+=$male; $totalsecgirls+=$female; 
        				// 		$totalsection+=$male+$female;
                				$totalsection+=$sectotal;
        						$totalsecdropout+=$cancelStudent;
        						$totalsectc+=$tcStudent;
        						$totalsecnew+=$newstudent;
                        ?>
                            <tr>
                            	<td><?php echo $i ?></td>
        						<td><?php echo $fclass["class"]."-".$sec["name"]; ?></td>
                                <td><?php echo $male; ?></td>
                                <td><?php echo $female;	?></td>
        						<td><?php echo $sectotal; ?></td>
        						<td><?php echo $cancelStudent; ?></td>
        						<td><?php echo $tcStudent; ?></td>
        						<td><?php echo $newstudent; ?></td>
        					</tr>
                        
                        
                        <?php }
    					foreach($section as $sec){
    					$male=$db->getVal("select Count(*) from student where class='".$fclass["class"]."' and section='$sec[name]' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 and gender = 'male'");
    					$female=$db->getVal("select Count(*) from student where class='".$fclass["class"]."' and section='$sec[name]' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 and gender = 'female'");
    					$tcStudent=$db->getVal("select Count(*) from student where class='".$fclass["class"]."' and section='$sec[name]' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=3 and remarks='TC' and issue_TC=0 ");
    					$cancelStudent=$db->getVal("select Count(*) from student where class='".$fclass["class"]."' and section='$sec[name]' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=3 and issue_TC=0 ");
    
                        $newstudent = $db->getVal("select Count(*) from student where class='".$fclass["class"]."' and section='$sec[name]' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 and stype='new' ");
    
                        $sectotal = $db->getVal("select Count(*) from student where class='".$fclass["class"]."' and section='$sec[name]' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 ");
    
        				// 	$sectotal = $male+$female;
        					if($sectotal > 0){$i++;
        					?>
                            <tr>
                            	<td><?php echo $i ?></td>
        						<td><?php echo $fclass["class"]."-".$sec["name"]; ?></td>
                                <td><?php echo $male ?></td>
                                <td><?php echo $female ?></td>
        						<td><?php echo $sectotal ?></td>
        						<td><?php echo $cancelStudent ?></td>
        						<td><?php echo $tcStudent; ?></td>
        						<td><?php echo $newstudent; ?></td>
        					</tr>
                              <?php
        						$total_male+=$male;	$total_female+=$female;	$total_student+=$sectotal; $total_cancel+=$cancelStudent;
        						$totaltc+=$tcStudent; $totalnew+=$newstudent;
        						$totalsecboys+=$male; $totalsecgirls+=$female; 
        				// 		$totalsection+=$male+$female;
                				$totalsection+=$sectotal;
        						$totalsecdropout+=$cancelStudent;
        						$totalsectc+=$tcStudent;
        						$totalsecnew+=$newstudent;
        					}
    
    					}
                        echo "<tr>
                            <th colspan='2' style='text-align:center;'>Total for Class - $fclass[class]</th>
                            <th>$totalsecboys</th>
                            <th>$totalsecgirls</th>
                            <th>$totalsection</th>
                            <th>$totalsecdropout</th>
                            <th>$totalsectc</th>
                            <th>$totalsecnew</th>
                    </tr>";
					 } } ?>
			</tbody>
				<tfoot><td></td><td>Total</td>
					<td><?php echo $total_male ?></td>
					<td><?php echo $total_female ?></td>
				    <td><?php echo $total_student ?></td>
                    <td><?php echo $total_cancel ?></td>
                    <td><?php echo $totaltc; ?></td>
                    <td><?php echo $totalnew; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
<?php }

	echo $db->getErMsg();
	
?>
</div>
	<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");
		}
	}
	</script>
    <style>
    tfoot{display: table-footer-group !important;}
	.MigrateLeftFee{width:650px !important}
    </style>
    
    
<script>
    function exportTableToExcel(tableID, filename = '',e){
    
    var tableType = document.getElementById('tblData').getAttribute("data-tblname");

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

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

        $("#btn_excel").click(function(e) {
            var filename = $("#filename").val();

        let file = new Blob([$('.divclass').html()], {type:"application/vnd.ms-excel"});
        let url = URL.createObjectURL(file);
        let a = $("<a />", {
        href: url,
        download: "Student List.xls"}).appendTo("body").get(0).click();
        e.preventDefault();
        });
    
</script>
    
    
    
    