<?php require "_header.php"; ?>
<script language="javascript" type="text/javascript">
</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
	$student_id = Escape($_REQUEST['ID']);

	if ($student_id == "") { ?>
		<script language="javascript" type="text/javascript">
			location.href = 'detain-student-list.php';
		</script><?php
	} elseif ($_SESSION['VedantnrCollegeId'] != "" && isset($_SESSION['VedantnrCollegeId'])) {
		ob_start();
		$sql_receipt = "
					SELECT 
						frm.feesreceive_id,
						frm.student_id,
						frm.receipt_no,
						frm.receipt_date,
						frm.cheque_no,
						frm.bank_name,
						frm.comments,
						frm.branch_id,
						frm.branchyear_id,
						frm.year_id,
						frm.semester_id,
						createdon
					FROM
						cms_feesreceivemaster frm 
					WHERE 1=1 ";
		$where = "";
		if ($student_id != 0)
			$where .= " AND frm.student_id = $student_id ";

		if ($where != "")
			$sql_receipt .= $where;

		$sql_receipt .= " ORDER By frm.branch_id ASC , frm.receipt_no ASC";
		$res_receipt = dbQuery($sql_receipt);

		if (dbRows($res_receipt) > 0) {

			$break = 0;

			while ($rec_receipt = dbArray($res_receipt)) {
				$receipt_no = $rec_receipt['receipt_no'];
				$feesreceive_id = $rec_receipt['feesreceive_id'];
				$student_id = $rec_receipt['student_id'];
				$receipt_date = $rec_receipt['receipt_date'];
				$comments = $rec_receipt['comments'];
				$cheque_no = $rec_receipt['cheque_no'];
				$bank_name = $rec_receipt['bank_name'];
				$branch_id = $rec_receipt['branch_id'];
				$year_id = $rec_receipt['year_id'];
				$branchyear_id = $rec_receipt['branchyear_id'];
				$semester_id = $rec_receipt['semester_id'];


				$sql_student = "
					SELECT 
						stud.student_surname,
						stud.student_firstname,
						stud.student_lastname,
						stud.student_gturegno,(SELECT branch_name 
				FROM cms_branchmaster sec 
				WHERE sec.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' and sec.branch_id=sd.cur_branchid) AS branch_name,
	  		  	(SELECT year_name 
				FROM cms_yearmaster ym 
				WHERE ym.year_id=sd.year_id) AS year_name,
	  		  	(SELECT branchyear_name 
				FROM cms_branchyear bry 
				WHERE bry.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' and bry.branchyear_id=sd.cur_branchyearid) AS branchyear_name,
	  		  	(SELECT semester_name
			   	 FROM cms_semestermaster sem 
			     WHERE  sem.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' AND sem.semester_id = sd.cur_semesterid) AS semester_name
			  			
					FROM
						cms_studentmaster stud,
						cms_studentdetail sd
					WHERE
						stud.student_id = sd.student_id AND
						stud.student_id = $student_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	
						frd.feesreceive_id = $feesreceive_id AND
						frm.feesreceive_id = frd.feesreceive_id AND
						frd.head_id = fh.head_id ORDER BY fh.head_id";
				$res_fees = dbQuery($sql_fees);
				if (dbRows($res_fees) > 0) {
					?>
					<table width="100%">
						<tr>
							<td align="center">
								<table class="table-report" cellpadding="0" cellspacing="0" width="70%">
									<tr>
										<td colspan="4" align="center">
											<table width="95%" cellpadding="0" cellspacing="0">
												<tr>
													<td rowspan="2">
														<img src="<?php echo $SiteBaseUrl . $CollegeImagePath . $_SESSION["VedantnrCollegeLogo"]; ?>"
															height="60" width="60" />
													</td>
													<td class="college_name"><?php echo $_SESSION["VedantnrCollegeName"]; ?></td>
												</tr>
												<tr>
													<td class="college_address" height="30">
														<?php echo $_SESSION["VedantnrCollegeAddress"]; ?>
														<br />
														Web: <?php echo $_SESSION["VedantnrCollegeUrl"]; ?>
														&nbsp;&nbsp;
														Email: <?php echo $_SESSION["VedantnrCollegeEmail"]; ?>
														&nbsp;&nbsp;
														Phone: <?php echo $_SESSION["VedantnrCollegePhone"]; ?>
													</td>
												</tr>
											</table>
										</td>
									</tr>
									<tr>
										<td colspan="4">
											<hr />
										</td>
									</tr>
									<tr>
										<th width="20%">Student Name:</th>
										<td width="60%">
											<?php echo $rec_student['student_surname'] . " " . $rec_student['student_firstname'] . " " . $rec_student['student_lastname']; ?>
										</td>
										<th width="18%">Receipt No:</th>
										<td><?php echo $receipt_no; ?></td>
									</tr>
									<tr>
										<th>MKBU No:</th>
										<td><?php echo $rec_student['student_gturegno']; ?></td>
										<th>Receipt Date:</th>
										<td><?php echo date('d-m-Y', strtotime($receipt_date)); ?></td>
									</tr>
									<tr>
										<th>Branch:</th>
										<td colspan="3">
											<?php echo $rec_student['branch_name'] . " - " . $rec_student['year_name'] . " - " . $rec_student['branchyear_name'] . " - " . $rec_student['semester_name']; ?>
										</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="80%" class="table-report-inner" cellpadding="0" cellspacing="0">
															<tr>
																<th style="text-align:left;">Particulars</th>
																<th style="text-align:right;">Amount</th>
															</tr>
															<?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']; ?></td>
																		<td style="text-align:right; padding-right:5px;">
																			<?php echo $rec_fees['recdetail_amt'];
																			$total = $total + $rec_fees['recdetail_amt']; ?>
																		</td>
																	</tr><?php
																} else { ?>
																	<tr>
																		<td>&nbsp;</td>
																		<td>&nbsp;</td>
																	</tr><?php
																}
															}
															?>
															<tr>
																<td colspan="2">
																	<hr />
																</td>
															</tr>
															<tr>
																<th>Total Received:</th>
																<th style="text-align:right; padding-right:5px;">
																	Rs.<?php echo $total; ?></th>
															</tr>
														</table>
													</td>
													<td valign="bottom" style="padding-bottom:20px;">
														<table width="100%" class="table-report-inner" cellpadding="0" cellspacing="0">
															<tr>
																<td><b>Received by:</b>&nbsp;&nbsp;
																	<?php
																	if ($cheque_no != "" && $bank_name != "") {
																		echo "Cheque <br /><br /> Cheque No:$cheque_no $bank_name";
																	} else {
																		echo "Cash";
																	}
																	?>
																</td>
															</tr>
														</table>
													</td>
												</tr>
											</table>
									</tr>
									<tr>
										<td colspan="4">
											<hr />
										</td>
									</tr>
									<tr>
										<td colspan="3" valign="top"><b>Comments:</b>&nbsp;&nbsp;<?php echo $comments; ?></td>
										<td align="right" style="padding-right:18px;">
											<table class="table-report">
												<tr>
													<td height="50px" width="40px">&nbsp;</td>
												</tr>
											</table>
										</td>
									</tr>
									<tr>
										<td colspan="4" style="text-align:right; vertical-align:bottom; padding:0px 5px 5px 0px;">
											Received by</td>
									</tr>
								</table>
							</td>
						<tr>
							<td align="center">
								<table class="table-report-footer" cellpadding="0" cellspacing="0" width="100%">
									<tr>
										<td align="left" width="50%">Created by <b><?php echo $_SESSION["VedantnrUserName"]; ?></b> on
											<b><?php echo date("d/m/Y, H:i", strtotime($rec_receipt['createdon'])); ?></b></td>
										<td align="right" width="50%">Developed By <b>Aum Imagineering Pvt. Ltd., A'bad</b>.
											Ph:079-40054004</td>
									</tr>
								</table>
							</td>
						</tr>
					</table>

					<br />
					<div class="break"> &nbsp;</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"; ?>