<?php require "_header.php";?>
<script language="javascript" type="text/javascript">
document.getElementById("main-content").style.display = 'none';
</script>
<div id="main-report" align="center">
<style>
	.table-report{
		font-family:Verdana, Geneva, sans-serif;
		font-size:12px;
		text-align:left;
		border-right:0px none;
		border-bottom:0px none;
	}
	.table-report-inner{
		font-family:Verdana, Geneva, sans-serif;
		font-size:12px;
	}
	.table-report tr{
		padding:2px 2px 2px 2px;
	}
	.table-report td{
		padding:2px 2px 2px 2px;
		border-top:0px none;
		border-left:0px none;
	}
	.table-report th{
		padding:2px 2px 2px 2px;
		font-weight:bold;
		text-align:left;
		border-top:0px none;
		border-left:0px none;
	}	
	.college_name{
		font-family:QTAbbie;
		font-size:22px;	
		font-weight:bold;
		padding:2px 2px 2px 2px;
		text-align:center;
	}
	.college_address{
		font-family:Tahoma, Geneva, sans-serif;
		font-size:11px;	
		text-align:center;
		padding:2px 2px 2px 2px;
	}
	.report_name{
		font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
		font-size:13px;	
		background-color:#CCC;
		text-align:center;
		font-weight:bold;
		padding:2px 2px 2px 2px;
	}
</style>
<?php 
	$header_row_string="Student Debit Fees Report";
	$branch_id 	= Escape($_REQUEST['branch_hidden']);
	$semester_id  = $_REQUEST['semester_hidden']=='undefined'?"":Escape($_REQUEST['semester_hidden']);
	$div_id	   = Escape($_REQUEST['division_id']);
	$student_id   = Escape($_REQUEST['student_hidden']); 
	$gtuhead_id   = Escape($_REQUEST['head_hidden']); 
	$branch_disp  = Escape($_REQUEST['branch_disp']);
	$semester_disp = Escape($_REQUEST['semester_disp']);
	$gtuhead_name = Escape($_REQUEST['head_disp']);
	 
	if($branch_id == "" && $semester_id == ""){?>
		<script language="javascript" type="text/javascript">
			location.href='report-gtufees-dueamt.php';
		</script><?php
	}
	elseif($_SESSION['VedantnrCollegeId']!="" && isset($_SESSION['VedantnrCollegeId'])){
		ob_start();
		$i=1;
		$sub= array();
		$qry="select subject_id from cms_examsetup 
					where 
					branch_id = '".$branch_id."' AND ";
					if($semester_id != "" ){
						$qry .= " semester_id = '".$semester_id."'  AND";
					}
			$qry .= "  year_id = '".$_SESSION["VedantnrYearId"]."' AND 
					total_marks = 0 AND 
					passing_marks = 0 AND 
					subject_id != 0";
			
			//echo $qry;
					
			$rs = dbQuery($qry);		
			while($rec_tamount = dbArray($rs)){
				$sub []  =  $rec_tamount['subject_id'];
			}
			$sub1= implode(',',$sub);
			
	    $sql_student = "
			SELECT
				CONCAT(sm.student_surname,' ',sm.student_firstname,' ',sm.student_lastname) AS student_name,
				sm.student_id,
				sm.student_gturegno,
				gfr.noofsub,
				gfr.receive_amount,
				gfr.paid,
				student_mobileparents,
				student_mobilestudents,
				sem.semester_name,sd.cur_divison,branch.branch_name,
				count(res.subject_id) as totalfail_sub
			FROM
					cms_studentmaster sm LEFT JOIN cms_gtufeesreceive gfr ON sm.student_id = gfr.student_id ";
					if($branch_id != "" &&  $branch_id != "All"){
						$sql_student .= " AND gfr.branch_id = ".$branch_id;
					}
					if($semester_id != "" ){
						$sql_student .= " AND gfr.semester_id = ".$semester_id;
					}
					if($div_id != "" ){
						$sql_student .= " AND gfr.division = '".$div_id."'";
					}
					$sql_student .=
					" AND gfr.gtuhead_id = ".$gtuhead_id." 
					AND FIND_IN_SET(".$_SESSION["VedantnrYearId"].", gfr.year_id), 
				   	cms_studentdetail sd,
					cms_resultmaster res,
					cms_branchmaster branch,
					cms_semestermaster sem 
			WHERE 
				sm.student_id = sd.student_id AND
				sm.student_id = res.student_id AND
				sd.cur_semesterid = sem.semester_id AND
				sd.cur_branchid = branch.branch_id 	 AND
				sm.student_active = 1 ";
				if($branch_id != "" &&  $branch_id != "All"){
						$sql_student .= " AND sd.cur_branchid = ".$branch_id;
					}
					if($semester_id != "" ){
						$sql_student .= " AND sd.cur_semesterid = ".$semester_id;
					}
					if($div_id != "" ){
						$sql_student .= " AND sd.cur_divison = '".$div_id."'";
					}
				 $sql_student .=
				" and sd.year_id = ".$_SESSION["VedantnrYearId"]."  AND
				res.test_type = 'f' AND
				res.result = 'fail' AND
				res.subject_id NOT IN ('".$sub1."') AND 
				res.year_id = ".$_SESSION["VedantnrYearId"]." 
				group by res.student_id ";
				//"ORDER BY student_gturegno ASC, student_name ASC ";	
				$sql_student .= " ORDER BY sd.cur_branchid , sd.cur_semesterid, sd.cur_divison,student_gturegno ASC, student_name ASC";
			/*echo $sql_student;
			exit;*/
		$res_student = dbQuery($sql_student);

		$gtuhead_amount=0;
		$qryresult= dbQuery("select * from cms_gtufeeshead where gtuhead_id=$gtuhead_id");
		if(dbRows($qryresult) > 0)
			{
				$rec=dbArray($qryresult);
				$gtuhead_amount=$rec['gtuhead_amount'];
				$amt_receivable = $rec['gtuhead_amount'];
				$max_amount = $rec['max_amount'];
				$gtufee_type = $rec['gtufee_type'];
			}
		
		if(dbRows($res_student)>0){?>
        	<div class="college_name">
                <?php echo $_SESSION["VedantnrCollegeName"]; ?>
            </div>
            <div class="college_address">
                    <?php echo $_SESSION["VedantnrCollegeAddress"]; ?>
            </div>
            <div class="report_name">
                    Student Enrollment No Debit Fees Report
            </div>
            <br />
            <table width="100%"  cellpadding="0" cellspacing="0" >
                        <tr>
                        <td align="left" style="border:solid 0px red;"><b>Branch:</b>
                        <?php 
								echo $branch_disp;
								if($semester_disp != ""){
									echo " - ".$semester_disp;	
								}
								if($div_id != ""){
									echo " - ".$div_id;	
								}
						?>
                        </td>
                        
                      
                      <?php if($gtuhead_name != "")
                            { ?>
                        <td align="right" style="border:solid 0px red;" ><b>Head:</b><?php echo $gtuhead_name; ?></td>
                    		<?php } ?>
                    	</tr>
                    </table>                    
                    
            <table width="100%" class="table-report" border="1" cellpadding="0" cellspacing="0">
            	<tr>
                	<th style="text-align:center;">Sr.</th>
                	<th style="text-align:center;">Enrollment No</th>
                    <th style="text-align:center;">Student Name</th>
                    <th style="text-align:center;">ContactNo</th>
                    <th style="text-align:center;">No Of Subject</th>
                    <th style="text-align:center;">Receivable Amt</th>
                    <th style="text-align:center;">Recived Amt</th>
                </tr><?php	
				$total=0;	
				//$t=0;
				
				$temp = "";
				$temp1="";
				$temp2="";
				$total_receive_amount=0;	
					
				while($rec_student = dbArray($res_student))
				{
				
				 if(($rec_student['branch_name'] != $temp && $branch_disp==':: All ::') || ($rec_student['semester_name'] != $temp1 && $semester_disp=='' ) || ($rec_student['cur_divison'] != $temp2 && $div_id=='' ) ){ 
				 if($temp != ""){
				 ?>
                 
                  <tr>
                    	<th colspan="5" style="text-align:center;">Total</th>
                        <th style="text-align:right; padding-right:2px;">&nbsp;<?php echo $t_amnt; ?>&nbsp;&nbsp;</th>
                        <th style="text-align:right; padding-right:2px;">&nbsp;<?php echo $t; ?>&nbsp;&nbsp;</th>
                    </tr>
                    <?php $t=0;$t_amnt=0;
				 }
				$temp = $rec_student['branch_name'];
				$temp1 = $rec_student['semester_name'];
				$temp2 = $rec_student['cur_divison'];
				
				$i = 1;?>
               
               
                <tr><th colspan="10"><?php echo strtoupper($temp)."  ".$rec_student['semester_name'].'-'.$rec_student['cur_divison']; ?></th></tr>
                 
				<?php
			}?>			
				
                	<tr>
                    	<td style="text-align:center;"><?php echo $i++; ?></td>
                    	<td style="text-align:center;"><?php echo $rec_student['student_gturegno']; ?></td>
                        <td>&nbsp;<?php echo $rec_student['student_name']; ?></td>
                        <td style="text-align:center;"><?php 
						  if($rec_student['student_mobileparents'] != "")
						  		echo $rec_student['student_mobileparents']; 
                   		  else if($rec_student['student_mobilestudents'] != "")
						  			echo $rec_student['student_mobilestudents']; 
								else
									echo '-';
							
							if($rec_student["noofsub"]=="" OR $rec_student["noofsub"]== 0 ){
								$noofsub 		= $rec_student['totalfail_sub'];
							}else
							{
								$noofsub 		= $rec_student["noofsub"];
							}
							//$noofsub 		= ($rec_student["noofsub"]==""?$rec_student['totalfail_sub']:$rec_student["noofsub"]);
							$receive_amount =$rec_student["receive_amount"];
							if($receive_amount=="" || $receive_amount==0){
								$receive_amount=($noofsub*$amt_receivable);
								if($receive_amount > $max_amount){
									$receive_amount=$max_amount;
								}
								
							}
						?>
                    	</td>
                        <td style="text-align:center; padding-right:2px;">&nbsp;<?php echo $noofsub; ?></td>
                        <td style="text-align:right; padding-right:2px;">&nbsp;<?php echo $receive_amount; ?>&nbsp;&nbsp;</td>
                        <td style="text-align:right; padding-right:2px;">&nbsp;<?php echo $rec_student["receive_amount"]; ?>&nbsp;&nbsp;</td>
                        <?php 
							$t_amnt += $receive_amount;
							$t += $rec_student["receive_amount"];?>
                    </tr>
                   
                <?php
				
					$total_receive_amount+=$receive_amount;
					$total+=$rec_student["receive_amount"];
				 }
				 if(($rec_student['branch_name'] != $temp && $branch_disp==':: All ::') || ($rec_student['semester_name'] != $temp1 && $semester_disp=='' ) ){?>
                <tr>
                    	<th colspan="5" style="text-align:center;">Total</th>
                        <th style="text-align:right; padding-right:2px;">&nbsp;<?php echo $t_amnt; ?>&nbsp;&nbsp;</th>
                        <th style="text-align:right; padding-right:2px;">&nbsp;<?php echo $t; ?>&nbsp;&nbsp;</th>
                    </tr>
                    <?php $t=0;$t_amnt=0;
				 }?> 
			
			
             <tr>
                    	<th colspan="5" style="text-align:center;">Grand Total</th>
                        <th style="text-align:right; padding-right:2px;">&nbsp;<?php echo $total_receive_amount; ?>&nbsp;&nbsp;</th>
                        <th style="text-align:right; padding-right:2px;">&nbsp;<?php echo $total; ?>&nbsp;&nbsp;</th>
                       
                    </tr>
              <tr>
                    <td colspan="7" >
                    <table class="table-report-footer" cellpadding="0" cellspacing="0" width="100%">
                        <tr>
                            <td align="left" style="border:solid 0px red;" width="69%">Created by <b><?php echo $_SESSION["VedantnrUserName"]; ?></b> </td>
                            <td align="right" style="border:solid 0px red;" width="31%">Developed By <b>Aum Imagineering Pvt.Ltd.</b></td>
                        </tr>
                    </table>
                    </td>        
					</tr>
                    
            </table>
			<?php if($gtuhead_name == 'Enrollment Fee' && $semester_id % 2 == 0)
			{?>
           <br />
            <span style="color:#D41F00;font-weight:500; font-size:14px">If any of above student come for paying fees then please record it in a previous year!</span><br />
            <?php } ?>
			<?php				
			$HtmlCode= ob_get_contents();
			ob_end_flush();
			$HtmlUrl  =	"gtufeesdueamt-report.html";
			$HtmlPath =	"report/".$HtmlUrl;
			$header_row_string="";
			createHTMLReportPage($header_row_string,$HtmlUrl,$HtmlPath,$HtmlCode);
		?>
		<br/>
		<form name="frm" id="frm" action="" method="post">		
			<input type="hidden"   name="txtFile" id="txtFile" value="<?php echo $HtmlUrl ;?>" />
            <input type="button"  name="btnPrint" id="btnPrint" value="Print" onClick="SetPageAction('PRINT');"/>
			<input type="button"  name="btnPdf" id="btnPdf" value="Create PDF" onClick="SetPageAction('PDF');"/>
			<input type="button" name="btnHtml" id="btnHtml" value="Create HTML" onClick="SetPageAction('HTML');"/>
			<input type="button" name="btnWord" id="btnWord" value="Create WORD" onClick="SetPageAction('WORD');"/>
			<input type="button" name="btnExcel" id="btnExcel" value="Create EXCEL" onClick="SetPageAction('Excel');"/>
		</form>
		<script language="javascript" type="text/javascript">
            function SetPageAction(varAction) {
                if(varAction=="PRINT"){			
                    document.frm.action="print/create-print.php";
                    document.frm.target = "_blank";
                    document.frm.submit();
                }
                else if(varAction=="PDF"){			
                    document.frm.action="convertpdf/create-pdf.php";
                    document.frm.target = "_blank";
                    document.frm.submit();
                }
                else if(varAction=="HTML"){
                    document.frm.action="<?php echo $HtmlPath; ?>";
                    document.frm.target = "_blank";
                    document.frm.submit();
                }
                else if(varAction=="WORD"){
                    document.frm.action="convertword/create-word.php";
                    document.frm.target="_blank";
                    document.frm.submit();
                }
                else if(varAction=="Excel"){
                    document.frm.action="convertword/create-excel.php";
                    document.frm.target="_blank";
                    document.frm.submit();
                }
            }
        </script><?php
		}
		else{
			echo "No data found for selected criteria.";	
		}		
	}  
   	else{
      	echo "Session Expired";      
   	} 
?>
</div>
<?php require "_footer.php";?>