<?php require "_header.php";
//require 'sample-gd.php';
?>
<script language="javascript" type="text/javascript">
document.getElementById("main-content").style.display = 'none';
</script>
<div id="main-report" align="center">
<style>
	.table-report{
		border:1px solid #000;	
		font-family:Verdana, Geneva, sans-serif;
		font-size:11px;
		text-align:left;
	}
	.table-report-inner{
		font-family:Verdana, Geneva, sans-serif;
		font-size:11px;
	}
	.table-report-footer{
		font-family:Verdana, Geneva, sans-serif;
		font-size:10px;
	}
	.table-report tr{
		padding:1px 1px 1px 1px;
	}
	.table-report td{
		padding:1px 1px 1px 1px;
	}
	.table-report th{
		padding:1px 1px 1px 1px;
		font-weight:bold;
		text-align:left;
	}	
	.college_name{
		font-family:QTAbbie;
		font-size:22px;	
		font-weight:bold;
		padding:1px 1px 1px 1px;
		text-align:center;
		vertical-align:top;
	}
	.college_address{
		font-family:Tahoma, Geneva, sans-serif;
		font-size:11px;	
		text-align:center;
		padding:1px 1px 1px 1px;
		vertical-align:top;
	}
	.break{
		page-break-after:always;
				
	}
</style>
<center><h4>Student Fees Receipt</h4></center>
<?php 
	$header_row_string="";
	
	$branch_id 		= Escape($_REQUEST['branch_hidden']);
	$semester_id 	= Escape($_REQUEST['semester_hidden']);
	$div_id		    = Escape($_REQUEST['division_id']);
	$student_id	 	= Escape($_REQUEST['student_hidden']); 
	$from_date		= DateConversion(Escape($_POST['feesrec_startdate']),"Y-m-d","d/m/Y");
	$to_date		= DateConversion(Escape($_POST['feesrec_enddate']),"Y-m-d","d/m/Y");
	$from_receiptno = Escape($_REQUEST['feesrec_startno']);
	$to_receiptno 	= Escape($_REQUEST['feesrec_endno']);
	 
	if($branch_id == "" ){?>
		<script language="javascript" type="text/javascript">
			location.href='report-form-student-feereceipt.php';
		</script><?php
	}
	
	elseif($_SESSION['VedantnrCollegeId']!="" && isset($_SESSION['VedantnrCollegeId'])){
				$sql_receipt = "
					SELECT 
						frm.feesreceive_id,
						frm.student_id,
						frm.receipt_no,
						frm.createdon,
						frm.receipt_date,
						frm.cheque_no,
						frm.bank_name,
						frm.comment_show,
						frm.comments,
						frm.branch_id,
						frm.semester_id,
						createdon
					FROM
						cms_feesreceivemaster frm 
					WHERE
						frm.year_id = ".$_SESSION["VedantnrYearId"];
		$where = "";
		if($student_id != 0)
			$where .= " AND frm.student_id = $student_id "; 
		if($from_date != "")
			$where .= " AND frm.receipt_date >= '$from_date' "; 
		if($to_date != "")
			$where .= " AND frm.receipt_date <= '$to_date' "; 
		if($from_receiptno != "")
			$where .= " AND frm.receipt_no >= $from_receiptno "; 
		if($to_receiptno != "")
			$where .= " AND frm.receipt_no <= $to_receiptno "; 
		if($branch_id != "" &&  $branch_id != "All")
			$where .= " AND frm.branch_id = ". $branch_id ; 	
		if($semester_id != "")
			$where .= " AND frm.semester_id = ". $semester_id ; 		
		if($div_id != "")
			$where  .= " AND frm.division_id = '".$div_id."'";

		if($where != "")
			$sql_receipt .= $where;
				
		$sql_receipt .= " ORDER By frm.branch_id ASC , frm.semester_id ASC, frm.receipt_no ASC";		
		//echo  $sql_receipt;		
		$res_receipt = dbQuery($sql_receipt);
 
		if(dbRows($res_receipt)>0){
			
			$break = 0;
			ob_start();
														
			while($rec_receipt = dbArray($res_receipt))
			{
				$receipt_no = $rec_receipt['receipt_no'];
				$createdon = date('YmdHis',strtotime($rec_receipt['createdon']));
				$student_id = $rec_receipt['student_id'];
				$receipt_date = $rec_receipt['receipt_date'];
				$comment_show = $rec_receipt['comment_show'];
				$comments = $rec_receipt['comments'];
				$cheque_no = $rec_receipt['cheque_no'];
				$bank_name = $rec_receipt['bank_name'];

				$branch_id = $rec_receipt['branch_id'];
            	$semester_id = $rec_receipt['semester_id'];
				$sql_student = "
					SELECT 
						stud.student_surname,
						stud.student_firstname,
						stud.student_lastname,
						stud.student_gturegno,
						bm.branch_name,
						sm.semester_name,
						sd.cur_divison
					FROM
						cms_studentmaster stud,
						cms_studentdetail sd,
						cms_branchmaster bm,
						cms_semestermaster sm	
					WHERE
						stud.student_id = sd.student_id AND
						stud.student_id = $student_id AND
						sd.cur_branchid = bm.branch_id  AND
						sd.cur_semesterid = sm.semester_id AND
						sd.cur_branchid = $branch_id AND
						sd.cur_semesterid = $semester_id";
				$res_student = dbQuery($sql_student);
				$rec_student = dbArray($res_student);
				$sql_fees = "
					SELECT
						fh.head_name,
						frd.recdetail_amt
					FROM
						cms_feesreceivemaster frm,
						cms_feesreceivedetail frd,
						cms_feeshead fh
					WHERE	
						frm.receipt_no = $receipt_no AND
						frm.feesreceive_id = frd.feesreceive_id AND
						frd.head_id = fh.head_id AND
						frm.year_id = ".$_SESSION["VedantnrYearId"]."
					ORDER BY fh.head_id";
				$res_fees = dbQuery($sql_fees);	
					
				if(dbRows($res_fees) > 0){
				?>
                	<br/><br/><br/>
                	<table width="100%">
                    <tr><td align="center">
                	<table class="table-report" cellpadding="0" cellspacing="0" width="95%">
                    	<tr>
                            <td colspan="4" align="center">	

                            </td>
                        </tr>
                        <tr>
                        	
                        </tr>
                    	<tr>
                        	<th width="15%">Student Name:</th>
                            <td width="65%"><?php echo $rec_student['student_surname']." ".$rec_student['student_firstname']." ".$rec_student['student_lastname']; ?></td>
                            
                        </tr>
                        <tr>
                        	
                            <th width="12%">Receipt Date:</th>
                            <td width="8%"><?php echo date('d-m-Y',strtotime($receipt_date)); ?></td>
                        </tr>
                        <tr>
                        	<th width="11%">Branch:</th>
                            <td colspan="3" width="89%"><?php echo $rec_student['branch_name']." - ".$rec_student['semester_name']." - ".$rec_student['cur_divison']; ?></td>
                        </tr>
                        <tr>
                        	<td colspan="4"><hr /></td>
                        </tr>
                        <tr><td colspan="4" align="left">
                        	<table width="100%">
                            <tr>
                            <td style="padding-left:50px;" width="55%">
                        	<table width="100%" class="table-report-inner" cellpadding="0" cellspacing="0">
                            	
                        <?php
							$total = 0;
							while($rec_fees = dbArray($res_fees)){
								if($rec_fees['recdetail_amt'] != "" && $rec_fees['recdetail_amt'] != 0){?>
								<tr>
                                	<td><?php echo $rec_fees['head_name'].' :-   '.$rec_fees['recdetail_amt']; $total = $total + $rec_fees['recdetail_amt']; ?> </td>   
                                </tr>
                                <tr>
                                    <td><b>Received by:</b>
                                        <?php 
                                            if($cheque_no != "" && $bank_name != ""){
                                                echo "Cheque &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
															 &nbsp&nbsp&nbsp&nbsp&nbsp&nbspCheque No:$cheque_no $bank_name";	
                                            }									
                                            else
                                            {
                                                echo "Cash";	
                                            }
                                        ?>
                                    </td>
                                </tr>
                                <?php	
								}
								
							}
						?>
                        	</table>
                            </td>
                            </tr>
                            </table>
                            </tr> 
                    </table>
                    </td>
                    <tr>
                    <td align="center">
                    <table class="table-report-footer" cellpadding="0" cellspacing="0" width="95%">  
                    </table>
                    </td>        
					</tr>
					</table>
                    <br/><br /><br /><br />
                    <div class="break"><br/><br /><br /></div> 
																		
                       <?php
				}				
			}	
			$HtmlCode= ob_get_contents();
			ob_end_flush();
			$HtmlUrl  =	"feereceipt-form-report.html";
			$HtmlPath =	"report/".$HtmlUrl;
			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";?>
