<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="discount_report";
$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"=>"Account", "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="Account" />
    <input type="hidden" name="page_id" value="<?php echo $pgMod; ?>" />
	<div class="row-fluid">
            <div class="span12">
            	<div class="top-bar">
                    <br />
                     <button type="submit" name="discount_detail" class="btn-classic margin"> Discount Detail</button>
                    
				</div>
				<div class="well no-padding">

                    <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">
                                    	<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">
                                    	<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">
                                    	<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">
                                    	<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">
                                    	<option value="">Month</option>
                                     <?php
									    for($m = 1;$m <= 12; $m++){
                                            $newDate=date("Y")."-".$m."-1";
											$month =  date("F",strtotime($newDate));
											$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">
                                    	<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>

			</div>
			
    </div>
    
    </form>
    <form method="get" action="">
    <input type="hidden" name="src" value="Account" />
    <input type="hidden" name="page_id" value="<?php echo $pgMod; ?>" />
	<div class="row-fluid">
            <div class="span12">

				<div class="well no-padding">

                    <div class="controls controls-row">
                        <div class="control-group span6">
                          
                       <div class="control-group">
							<label class="control-label" for="discount_mode">Discount Mode</label>
							<div class="controls">
								<select class="span12" name="discount_mode" id="discount_mode" style="width:234px;">
                                	<option value="">none</option>
									<?php 
										$location=$db->getRows("select * from discount_mode where school_id='".$_SESSION["admin"]["school_id"]."'");
										if(is_array($location) && count($location)>0){
											foreach($location as $loc){
												?>
												<option <?php if($loc["name"]==$aryForm["discount_mode"])echo 'selected';?> value="<?php echo $loc["name"] ?>">
													<?php echo $loc["name"] ?>
												</option>
												<?php
											}
										}
									?>
								</select>
								<button type="submit" name="discount_Mode" class="btn-classic margin"> Discount Mode</button>
							</div>
							  
				</div>
                    </div>

			</div>
			
    </div>
    
    </form>
	<?php
	$where=array();
	$qry="";

	if(isset($_GET["fee"])){
		$conwhere="";
		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[]=" (rr.date between '$fdate' and '$tdate') ";
			$conwhere.=" and  (installment_fine.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."') ";
		}
		$where[]=" rr.idno=s.idno and s.session='".$_SESSION["admin"]["session"]."' and (rr.type='fee' or rr.type='busfee' or rr.type='hostelfee' or rr.type like 'extrafee%') and s.status=1 ";
		$table=" reff_receipt as rr, student as s";
		$result=$db->getRows("SELECT rr.*,rr.id as recid,s.class as sclass,s.section,s.name,s.medium,s.fname,s.dob,s.mname FROM ".$table." where rr.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0  AND ".implode(" AND ",$where)." group by rr.id order by rr.date");
		//echo "<pre>";print_r($result);echo "</pre>";echo $db->getLastQuery();
		?>
		 <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">
				 
                    <button onclick="printDiv('printDiv')" type="button" class="btn btn-primary">Print</button>
                    <button onclick="SMSComplete('completeFeeShw','completeFeeShowSMS')" type="button" class="btn btn-primary">SMS</button>
                    <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv">
            	<table class="table tableSummery" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>S. No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Section</th>
                            <th>Father</th>
                            <th>Mother</th>
                            <th>Receipt ID</th>
                            <th>Quater</th>
                            <th>Fee</th>
                            <th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $ollTotal=0;$ijk=0;
						if(is_array($result) && count($result)>0)
						{
							foreach($result as $detail)
							{$ijk++;
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo ucfirst($detail["name"]); ?></td>
                                    <td><?php echo $detail["sclass"]; ?></td>
                                    <td><?php echo $detail["section"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mname"]; ?></td>
                                    <td><?php 
									$rids=array();
									$rrde=$db->getRows("select * from receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."'");
									//echo "<pre>";print_r($rrde);echo "</pre>";
									if(is_array($rrde) && count($rrde)>0){
										foreach($rrde as $rr){
											$rel_rrid=explode("-",$rr["rrid"]);
											foreach($rel_rrid as $rrids){
												if($rrids==$detail["recid"]){
													$rids[]=$rr["id"];
												}
											}
										}
									}
									echo implode(",",$rids) ?></td>
                                    <td><?php $ins_iods = $detail["inst_id"];//." (".($detail["type"] == "fee" ? "School Fee" : "Bus Fee").")" 
									if($detail["type"]=="fee")
										echo "<span style='color:#FF0000'>$ins_iods(School Fee)</span>";
									else if($detail["type"]=="busfee")
										echo "<span style='color:#00CC00'>$ins_iods(Transport Fee)</span>"; 
									else if($detail["type"]=="hostelfee") 
										echo "<span style='color:#FF00FF'>$ins_iods(Hostel Fee)</span>";
									else{
										$det=$db->getVal("select type from extrafee_type where id='".str_replace("extrafee","",$detail["type"])."'");
										echo "<span style='color:#FF0000'>$ins_iods($det)</span>";
									}?></td>
                                    <td><?php echo $all=$detail["amount"];
									$ollTotal=$ollTotal+$all; ?></td>
                                    <td><?php echo $detail["date"]; ?></td>
                                </tr>
								<?php
							}
						}
						$result=$db->getRows("select student.idno,student.name,student.class as sclass,student.medium,student.fname,student.dob,student.mname,installment_fine.* from installment_fine,student where student.school_id='".$_SESSION["admin"]["school_id"]."' and student.session='".$_SESSION["admin"]["session"]."' and student.issue_TC=0 and installment_fine.status=1 and installment_fine.fine!='' and installment_fine.idno=student.idno $conwhere order by student.name");
						//echo $db->getErMsg().$db->getLastQuery();
						if(is_array($result) && count($result)>0){
							foreach($result as $detail){$ijk++;
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo $detail["name"]; ?></td>
                                    <td><?php echo $detail["sclass"]; ?></td>
                                     <td><?php echo $detail["section"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mname"]; ?></td>
                                    <td><?php $detail["id"];
									//echo $db->getVal("select id from receipt where rrid=(select id from reff_receipt where inst_id=".$detail["id"].")"); 
									$rids=array();
									$recpID=$db->getVal("select id from reff_receipt where inst_id='".$detail["id"]."'");
									$rrde=$db->getRows("select rrid,id from receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."'");
									if(is_array($rrde) && count($rrde)>0){
										foreach($rrde as $rr){
											//print_r($rr);
											$rel_rrid=explode("-",$rr["rrid"]);
											foreach($rel_rrid as $rrids){
												if($rrids==$recpID){
													$rids[]=$rr["id"];
													//echo "select id from receipt where rrid='".$rrids."'<br />";
												}
											}
										}
									}//echo $db->getLastQuery();
									echo implode(",",$rids).$db->getErMsg();
									?></td>
                                    <td><?php $qua=$detail["ins_name"];echo instFine($qua,$detail["reasion"]); ?></td>
                                    <td><?php $otfee=str_replace("_detail","_fee",$qua);
									echo $all=$detail["fine"];$ollTotal=$ollTotal+$all; ?></td>
                                    <td><?php echo $detail["udate"]; ?></td>
                                </tr>
								<?php
							}
						}
						$newwhere="";
						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"];
							$newwhere=" and (udate between '$fdate' and '$tdate') ";
						}
						$finalresult=$db->getRows("select * from transaction where type='deposit' $newwhere and rid=0 and tid=0");
						if(is_array($finalresult) && count($finalresult)>0){
							foreach($finalresult as $detail){$ijk++;
								?><tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td>--</td>
                                    <td>--</td>
                                    <td>--</td>
                                    <td>--</td>
                                    <td>--</td>
									<td>--</td>
                                    <td><?php echo $detail["detail"] ?></td>
                                    <td><?php echo $detail["amount"];$ollTotal+=$detail["amount"]; ?></td>
                                    <td><?php echo $detail["udate"] ?></td>
									<?php
							}
						}
						?>
                        
                    </tbody>
                    <tfoot>
                    	<tr style="border-top:1px solid #F00; color:#F00">
                        	<td colspan="6">Total</td><td></td><td></td><td id="completeFeeShw"><?php echo $ollTotal; ?></td><td></td>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
          </div>
		<?php
	}

	elseif(isset($_GET["discount_detail"])){
	    
		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') ";
			$conwhere="  and b.date between '$fdate' and '$tdate' ";
			
		$extrawhere="  and date >= '$fdate' and date <= '$tdate' ";	
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and s.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and s.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and s.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["section"]) && $_GET["section"]!=""){
			$where[]=" s.section='".$_GET["section"]."' ";
			$conwhere.=" and s.section='".$_GET["section"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and s.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and s.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 (s.dob between '".$end."' and '".$start."') ";
		}
		if(isset($_GET["location"]) && trim($_GET["location"])!=""){
			$where[]=" s.location='".$_GET["location"]."' ";
			$conwhere.=" and s.location='".$_GET["location"]."' ";
		}
		if(isset($_GET["discount_mode"]) && trim($_GET["discount_mode"])!=""){
		   
			$where[]=" s.discount_mode='".$_GET["discount_mode"]."' ";
			$conwhere.=" and s.discount_mode='".$_GET["discount_mode"]."' ";
		}
		$where[]=" s.session='".$_SESSION["admin"]["session"]."' and s.status=1 ";
		$table=" student as s";
		
		$result=$db->getRows("select b.idno,b.discount_amount,b.installment,b.type,b.session,b.school_id,b.date,b.added_by,s.idno,s.class,s.section,s.name,s.fname,s.mobile,s.discount_mode,s.admissionno,s.fincome,b.disc_mode from discount_detail as b inner join student as s on b.idno=s.idno  where b.session='".$_SESSION["admin"]["session"]."' and b.school_id='".$_SESSION["admin"]["school_id"]."'$conwhere group by b.idno ");
	
		 $s="select b.idno,b.discount_amount,b.installment,b.type,b.session,b.school_id,b.date,b.added_by,s.idno,s.class,s.section,s.name,s.fname,s.mobile,s.admissionno,s.fincome from discount_detail as b inner join student as s on b.idno=s.idno  where b.school_id='".$_SESSION["admin"]["school_id"]."'$conwhere group by b.idno  ";
		//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">
                    <button type="button" onclick="printDiv('printDiv2')" class="btn btn-primary">Print</button>
                    <button class="btn btn-primary" id="btn_excel" >Excel</button>
                    <!--<button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>-->
                </div>
            </div>
            <!--<h5>Detail-<?php echo $_GET["discount_mode"]?> </h5>-->
            <input type="hidden" id="filename" value="Discount Report" />
            <div class="well no-padding divclass" id="printDiv2">
                  	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th width="5%">S.No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Sec</th>
                            <th>Father</th> 
                            <th>Adm No</th>  
                            <th>Roll No</th>  
                            <th>Mobile</th>
							<th>Discount Mode</th>
                            <th>Discount By</th>
                            <th>Fee</th>
                            <th>Bus Fees</th>
                            <th>Hostel Fee</th>
							 <th>Hostel Other</th>
                            <th>Extra Fee</th>
                            <th>Other fee</th>
                            <th>Total</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $full_total=0;
						if(is_array($result) && count($result)>0){$ijk=0;
			 		
							foreach($result as $detail){$ijk++;
							
							$fee=$busfee=$hostelfee=0;$other_Fee=$total=0;$other_detail=""; $total=0;
							
						$pdate = date("Y-m-d", strtotime($detail["date"]));	
				
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo ucfirst($detail["name"]); ?></td>
                                    <td><?php echo $detail["class"]; ?></td>
                                    <td><?php echo $detail["section"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["admissionno"]; ?></td>
                                    <td><?php echo $detail["fincome"]; ?></td>
                                    <td><?php echo $detail["mobile"]; ?></td>
									<td><?php echo $detail["disc_mode"]; ?></td>
                                    <td><?php echo $addedby=$db->getVal("SELECT name FROM users  where school_id='".$_SESSION["admin"]["school_id"]."' and id='".$detail["added_by"]."'"); ?></td>
                                    <?php
                                    $feeall=$db->getRows("SELECT date FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' GROUP BY DATE_FORMAT(date, '%Y-%m-%d')");

                    				$fee=$db->getVal("SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='tution' $extrawhere ");

                                    $busfee=$db->getVal("SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='bus' $extrawhere ");
					  
                                    $s="SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='bus' and date_format(date, '%Y-%m-%d')='".$pdate = date("Y-m-d", strtotime($detail["date"]))."'";
                                    $hostelfee=$db->getVal("SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='hostel' $extrawhere ");
                                    
                                    $hostelother=$db->getVal("SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='hostelother' $extrawhere ");
                                    
                                    $extrafee=$db->getval("SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='extra' $extrawhere ");
                                    
                                    $otherfee=$db->getval("SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='otherfee' $extrawhere ");
					
                                    $total=$fee+$busfee+$hostelfee+$hostelother+$extrafee+$otherfee;
                                    $full_total+=$total;
                                ?>	
                      			<td><?php echo $fee; ?></td>
                                <td><?php echo $busfee; ?></td>
                                <td><?php echo $hostelfee; ?></td>
                                <td><?php echo $hostelother; ?></td>
                                <td><?php echo $extrafee; ?></td>
                                <td><?php echo $otherfee; ?></td>
                                <td><?php echo $total; ?></td>
                                </tr>
								<?php
								
							}?>
							<?php  ?>
                        <tr>
                        	<th colspan="16">Total</th>
                            <th><?php echo $full_total; ?></th>
                        </tr>    
				<?php }else{
							?><tr>
                            <td colspan="13">No record Found</td>
                            </tr><?php
						}
						?>
                    </tbody>
                 </table>
              </div>
          </div>
		<?php
	}
	
	
	//rahul
	
		elseif(isset($_GET["discount_Mode"])){
		
		if(isset($_GET["discount_mode"]) && trim($_GET["discount_mode"])!=""){
		   
			$where[]=" s.discount_mode='".$_GET["discount_mode"]."' ";
			
		  
			$conwhere.=" and s.discount_mode='".$_GET["discount_mode"]."' ";
		}
		else{
		    	$where[]=" s.discount_mode='".$_GET["discount_mode"]."' ";
			
		  
			$conwhere.=" and s.discount_mode!='' ";
		}
		$where[]=" s.session='".$_SESSION["admin"]["session"]."' and s.status=1 ";
		$table=" student as s";
		
		$result=$db->getRows("select b.idno,b.discount_amount,b.installment,b.type,b.session,b.school_id,b.date,b.added_by,s.idno,s.class,s.section,s.name,s.fname,s.mobile,s.admissionno,s.fincome from discount_detail as b inner join student as s on b.idno=s.idno  where b.session='".$_SESSION["admin"]["session"]."' and b.school_id='".$_SESSION["admin"]["school_id"]."'$conwhere group by b.idno ");
		  //print_r($result);
		  //  die();
		 $s="select b.idno,b.discount_amount,b.installment,b.type,b.session,b.school_id,b.date,b.added_by,s.idno,s.class,s.section,s.name,s.fname,s.mobile,s.admissionno,s.fincome from discount_detail as b inner join student as s on b.idno=s.idno  where b.school_id='".$_SESSION["admin"]["school_id"]."'$conwhere group by b.idno  ";
		//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">
                    <button type="button" onclick="printDiv('printDiv2')" class="btn btn-primary">Print</button>
                    <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv2">
                <h5>Detail-<?php echo $_GET["discount_mode"]?> </h5>
                  	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th width="5%">S.No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Sec</th>
                            <th>Father</th> 
                            <th>Adm No</th>  
                            <th>Roll No</th>  
                            <th>Mobile</th>
							
                            <th>Discount By</th>
                            <th>Fee</th>
                            <th>Bus Fees</th>
                            <th>Hostel Fee</th>
							 <th>Hostel Other</th>
                            <th>Extra Fee</th>
                            <th>Other fee</th>
                            <th>Total</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $full_total=0;
						if(is_array($result) && count($result)>0){$ijk=0;
							foreach($result as $detail){$ijk++;
							$fee=$busfee=$hostelfee=0;$other_Fee=$total=0;$other_detail=""; $total=0;
							
						$pdate = date("Y-m-d", strtotime($detail["date"]));	
				
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo ucfirst($detail["name"]); ?></td>
                                    <td><?php echo $detail["class"]; ?></td>
                                    <td><?php echo $detail["section"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["admissionno"]; ?></td>
                                    <td><?php echo $detail["fincome"]; ?></td>
                                    <td><?php echo $detail["mobile"]; ?></td>
									
                                    <td style="border-right:1px solid #FA0606;"><?php echo $addedby=$db->getVal("SELECT name FROM users  where school_id='".$_SESSION["admin"]["school_id"]."' and id='".$detail["added_by"]."'"); ?></td>
									
                <?php
     $feeall=$db->getRows("SELECT date FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' GROUP BY DATE_FORMAT(date, '%Y-%m-%d')");
	 
 //$ss="SELECT date FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' GROUP BY DATE_FORMAT(date, '%Y-%m-%d')";
 

				$fee=$db->getVal("SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='tution' $extrawhere ");
		//echo 	  $s="SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='tution' and date between '$fdate' and '$tdate'";
				 	  $busfee=$db->getVal("SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='bus' $extrawhere ");
					  
					   $s="SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='bus' and date_format(date, '%Y-%m-%d')='".$pdate = date("Y-m-d", strtotime($detail["date"]))."'";
					  $hostelfee=$db->getVal("SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='hostel' $extrawhere ");
					  
	    $hostelother=$db->getVal("SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='hostelother' $extrawhere ");

					  $extrafee=$db->getval("SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='extra' $extrawhere ");
					
					 $otherfee=$db->getval("SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='otherfee' $extrawhere ");
					
					 /* 
					  foreach($otherfee as $other){
						  $other_fee+=$other["discount"];
						  $other_detail[]=$other["detail"];
					  } $other_detail=implode(",",$other_detail);
					  */
					  $total=$fee+$busfee+$hostelfee+$hostelother+$extrafee+$otherfee;
					  $full_total+=$total;
					  ?>	
                      			<td style="border-right:1px solid #FA0606;"><?php echo $fee; ?></td>
                                <td style="border-right:1px solid #FA0606;"><?php echo $busfee; ?></td>
                                <td style="border-right:1px solid #FA0606;"><?php echo $hostelfee; ?></td>
                        <td style="border-right:1px solid #FA0606;"><?php echo $hostelother; ?></td>

                                <td style="border-right:1px solid #FA0606;"><?php echo $extrafee; ?></td>
                                <td style="border-right:1px solid #FA0606;"><?php echo $otherfee; ?></td>
                                <td ><?php echo $total; ?></td>
                                </tr>
								<?php
								
							}?>
							<?php  ?>
                        <tr>
                        	<th colspan="13">Total</th>
                            <th><?php echo $full_total; ?></th>
                        </tr>    
				<?php }else{
							?><tr>
                            <td colspan="13">No record Found</td>
                            </tr><?php
						}
						?>
                    </tbody>
                    <tfoot>
                    	<tr>
                        	<th colspan="13"></th>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
	}
	
	//end rahul
	//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");
		}
	}
	</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) {
            $(".contentdiv").remove();
            var filename = $("#filename").val();
            if(filename==''){filename='Report';}
            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>



