<?php require "_header.php";
error_reporting(1);
?>
<script language="javascript" type="text/javascript">
</script>
<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: 24px;
		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>

<?php
$branch_id = $_REQUEST['branch_hidden'];
$branchyear_id = $_REQUEST['branchyear_hidden'];
$year_id = $_REQUEST['year_hidden'];
$semester_id = $_REQUEST['semester_hidden'];
$student_id = $_REQUEST['student_hidden'];
$student_gturegno = $_REQUEST['student_gturegno'];
$show_detail = $_REQUEST['show_detail'];
if ($_REQUEST['student_gturegno'] == "" && $_REQUEST['branch_hidden'] == "") { ?>
	<script language="javascript" type="text/javascript">
		location.href = 'report-student-fees-records.php';
	</script>
	<?php
} elseif ($_SESSION['VedantnrCollegeId'] != "" && isset($_SESSION['VedantnrCollegeId'])) {
	ob_start();

	dbquery("SET group_concat_max_len = 102400");
	$objStudentMgmt = new StudentMgmt();
	$objStudentFeesRecMgmt = new StudentFeesRecMgmt();
	if ($_REQUEST['student_gturegno'] != "") {
		$condition = "";
		$condition .= "and sm.student_gturegno='" . Escape($_REQUEST['student_gturegno']) . "' order by sd.year_id";
		$res_studentdata = $objStudentMgmt->getstudentdata($condition);
		//$sql_studentdata = "SELECT sd.student_id,cur_branchid,cur_branchyearid,cur_semesterid,sd.year_id FROM `cms_studentmaster` sm,cms_studentdetail sd where sm.student_id=sd.student_id and sm.student_gturegno='" . Escape($_REQUEST['student_gturegno']) . "' order by sd.year_id";
		//$res_studentdata = dbQuery($sql_studentdata);
	} else {
		$condition1 = "";
		$condition1 .= "and sm.student_id='" . Escape($_REQUEST['student_hidden']) . "' order by sd.year_id";
		$res_studentdata = $objStudentMgmt->getstudentdata($condition1);
		//$sql_studentdata = "SELECT sd.student_id,cur_branchid,cur_branchyearid,cur_semesterid,sd.year_id FROM `cms_studentmaster` sm,cms_studentdetail sd where sm.student_id=sd.student_id and sm.student_id='" . Escape($_REQUEST['student_hidden']) . "' order by sd.year_id";
		//$res_studentdata = dbQuery($sql_studentdata);
	}

	if (dbRows($res_studentdata) > 0) {
		$studentprofileflag = 0;
		while ($rec_studentdata = dbArray($res_studentdata)) {
			$branch_id = $rec_studentdata['cur_branchid'];
			$semester_id = $rec_studentdata['cur_semesterid'];
			$branchyear_id = $rec_studentdata['cur_branchyearid'];
			$year_id = $rec_studentdata['year_id'];
			$gturegno = Escape($_REQUEST['student_gturegno']);
			$stuid = Escape($_REQUEST['student_hidden']);
			$order_by = 'student_gturegno';


			/*$SQL_STUDENT = "SELECT
												sm. *,
												sd.cur_semesterid,
												sd.cur_branchid,
												CONCAT(student_surname,' ',student_firstname,' ',SUBSTR(student_lastname,1,1),'.') AS student_name,
												SUBSTR(student_gender,1,1) AS student_gender,
												
												(SELECT branch_name 
														FROM cms_branchmaster bm 
														WHERE bm.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' and sd.cur_branchid =bm.branch_id) AS branch_name,
												(SELECT year_name 
														FROM cms_yearmaster ym  WHERE  sd.year_id  =ym.year_id) AS year_name,
												(SELECT branchyear_name
														FROM cms_branchyear bry 
														WHERE  bry.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' AND sd.cur_branchyearid = bry.branchyear_id) AS branchyear_name,
												(SELECT semester_name
														FROM cms_semestermaster sem 
														WHERE  sem.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' AND sd.cur_semesterid = sem.semester_id) AS semester_name                                                
										FROM
											cms_studentmaster sm,
											cms_studentdetail sd
										WHERE  
											sm.student_id = sd.student_id ";
											$RES_STUDENT = dbQuery($SQL_STUDENT);*/
			$condition2 = "";
			if ($branch_id != "") {
				$condition2 .= " AND sd.cur_branchid = " . $branch_id;
			}

			if ($year_id != "") {
				$condition2 .= " AND sd.year_id = " . $year_id;
			}

			if ($branchyear_id != "") {
				$condition2 .= " AND sd.cur_branchyearid = " . $branchyear_id;
			}

			if ($semester_id != "") {
				$condition2 .= " AND sd.cur_semesterid = " . $semester_id;
			}

			if ($gturegno != "") {
				$condition2 .= " AND sm.student_gturegno = '" . $gturegno . "' ";
			}

			if ($stuid != "") {
				$condition2 .= " AND sm.student_id = '" . $stuid . "' ";
			}

			$condition2 .= " ORDER BY sd.cur_branchid ASC, sd.cur_branchyearid ASC,sd.cur_semesterid  ASC ";

			if ($order_by != "" && $order_by != "undefined") {
				$condition2 .= " ,student_gturegno ASC ";
			}
			$RES_STUDENT = $objStudentMgmt->getstudentfeesdata($condition2);

			if (dbRows($RES_STUDENT) > 0) {
				while ($REC_STUDENT = dbArray($RES_STUDENT)) {
					if ($studentprofileflag == 0) {
						$studentprofileflag = 1;
						?>
						<table style="width: 70%; margin: 0 auto; border-collapse: collapse; border: 1px solid;" class="table-bordered">
							<tr style="vertical-align: middle;">
								<td colspan="5" style="border: 1px solid; padding: 5px; text-align: center;">
									<img src="<?php echo $SiteBaseUrl . $CollegeImagePath . $_SESSION["VedantnrCollegeLogo"]; ?>" alt="College Logo"
										style="width: 80px; height: auto; float: left; margin-right: 10px;">
										<div style="display: inline-block; vertical-align: middle;">
									<b style="font-size: 30px;"><?php echo $_SESSION["VedantnrCollegeName"]; ?></b><br>
									<?php echo $_SESSION["VedantnrCollegeAddress"]; ?><br>
									Phone: <?php echo $_SESSION["VedantnrCollegePhone"]; ?>&nbsp;&nbsp;
									Email: <?php echo $_SESSION["VedantnrCollegeEmail"]; ?>
								</div>
								</td>
							</tr>
							<tr style="border: 1px solid;">
								<td colspan="6" style="text-align: center; border: 1px solid;">
									<u><b>Student Profile Detail</b></u><br><br>
								</td>
							</tr>
							<tr>
								<td colspan="3" width="50%" style=" border-right:1px solid; border-bottom:1px solid;">&nbsp;<b>Student
										Name :</b>&nbsp;<?php echo $REC_STUDENT['student_name']; ?></td>
								<td colspan="3" width="50%" style="border-bottom:1px solid;">&nbsp;<b>Enrollment
										No : </b>&nbsp;<?php echo $REC_STUDENT['student_gturegno']; ?></td>
							</tr>
							<tr>
								<td colspan="3" width="50%" style=" border-right:1px solid; border-bottom:1px solid;">&nbsp;<b>Gr.
										No. : </b>&nbsp;<?php echo $REC_STUDENT['student_grno']; ?></td>
								<td colspan="3" width="50%" style="border-bottom:1px solid;">&nbsp;<b>Student
										Active : </b>&nbsp;<?php echo ($REC_STUDENT['student_active'] == 1) ? "Yes" : "No"; ?> </td>
							</tr>
							<tr>
								<td style="text-align:left; border-bottom:1px solid;" colspan="6">
									&nbsp;<b>Address :
									</b><?php echo $REC_STUDENT['student_addressat'] . ', ' . $REC_STUDENT['student_addresspost'] . ', ' . $REC_STUDENT['taluko_nameeng'] . ', ' . $REC_STUDENT['dist_nameeng'] . '-' . $REC_STUDENT['student_pincode'] . ', ' . $REC_STUDENT['state_nameeng']; ?>
								</td>
							</tr>
							<tr>
								<td style="text-align:left; border-right:1px solid; border-bottom:1px solid;" colspan="3" width="50%">
									&nbsp;<b>Phone(Parents) : </b><?php echo $REC_STUDENT['student_fathermobile']; ?>
								</td>
								<td style="text-align:left; border-bottom:1px solid;" colspan="3" width="50%">
									&nbsp;<b>Phone(Student) : </b><?php echo $REC_STUDENT['student_mobilestudents']; ?>
								</td>
							</tr>
							<tr>
								<td style="text-align:left; border-right:1px solid; " colspan="3" width="50%">&nbsp;<b>Email
										ID : </b><?php echo $REC_STUDENT['student_emailid']; ?></td>
								<td style="text-align:left;" colspan="3" width="50%">&nbsp;
									<b>DOB : </b><?php echo date('d-m-Y', strtotime($REC_STUDENT['student_birthdate'])); ?>
								</td>
							</tr>
						<?php }
					$condition3 = "";
					if ($student_id != "") {
						$condition3 .= " AND student_id = " . $student_id;
					}

					if ($branch_id != "") {
						$condition3 .= " AND branch_id = " . $branch_id;
					}

					if ($year_id != "") {
						$condition3 .= " AND year_id = " . $year_id;
					}
					// Main Fee Records Table

					$res_fees = $objStudentFeesRecMgmt->getAllFees($condition3);
					//$sql_fees = "SELECT * FROM cms_feesreceivemaster WHERE student_id = " . $REC_STUDENT['student_id'];
					//$res_fees = dbQuery($sql_fees);

					if (dbRows($res_fees) > 0) {
						?>
							<tr style="border: 1px solid;">
								<td colspan="6" style="text-align: center; border: 1px solid;">
									<u><b>Student Fees Records</b></u><br><br>
								</td>
							</tr>
							<tr>
								<td colspan="3" style="line-height:20px;text-align:left;  border-right:1px solid; border-bottom:1px solid;">
									&nbsp;<b>Course : </b>
									<?php echo $REC_STUDENT['branch_name']; ?><br>
								</td>
								<td colspan="3" style="line-height:20px;text-align:left; border-bottom:1px solid;">
									&nbsp;<b>Batch Year : </b><?php echo $REC_STUDENT['year_name']; ?><br>
								</td>
							</tr>
							<tr>
								<td colspan="3" style="line-height:20px;text-align:left; border-right:1px solid; border-bottom:1px solid;">
									<?php if ($REC_STUDENT['branchyear_name'] != "") { ?>
										&nbsp;<b>Course Year : </b><?php echo $REC_STUDENT['branchyear_name']; ?>
									<?php } ?>
								</td>
								<td colspan="3" style="line-height:20px;text-align:left; border-bottom:1px solid;">
									<?php if ($REC_STUDENT['semester_name'] != "") { ?>
										&nbsp;<b>Semester : </b><?php echo $REC_STUDENT['semester_name']; ?>
									<?php } ?>
								</td>
							</tr>
							<tr>
								<th style="text-align:center; border-right:1px solid; border-bottom:1px solid;"><b>Receipt No.</b></th>
								<th style="text-align:center; border-right:1px solid; border-bottom:1px solid;"><b>Date</b></th>
								<th style="text-align:center; border-right:1px solid; border-bottom:1px solid;"><b>Payment Mode</b></th>
								<th style="text-align:center; border-right:1px solid; border-bottom:1px solid;"><b>Detail</b></th>
								<th style="text-align:center; border-right:1px solid; border-bottom:1px solid;"><b>Amount</b></th>
							</tr>
							<?php
							$totalfees = 0;
							$feesreceive_ids = [];
							while ($rec_subject = dbArray($res_fees)) {
								$feesreceive_ids[] = $rec_subject['feesreceive_id'];
								$totalfees += $rec_subject['receive_amt'];
								?>
								<tr>
									<td style="text-align:center; border-right:1px solid; border-bottom:1px solid;">
										<?php echo $rec_subject['receipt_no']; ?>
									</td>
									<td style="text-align:center; border-right:1px solid; border-bottom:1px solid;">
										<?php echo date('d-m-Y', strtotime($rec_subject['receipt_date'])); ?>
									</td>
									<td style="text-align:center; border-right:1px solid; border-bottom:1px solid;">
										<?php
										echo $rec_subject['cheque_no'] ? 'Cheque' : ($rec_subject['ref_no'] ? 'Online' : 'Cash');
										?>
									</td>

									<td style="text-align:center; border-right:1px solid; border-bottom:1px solid;">
										<?php echo $rec_subject['cheque_no'] ? 'Cheque No : ' . $rec_subject['cheque_no'] . '<br>Bank Name : ' . $rec_subject['bank_name'] : ($rec_subject['ref_no'] ? 'Reference No : ' . $rec_subject['ref_no'] : '-');
										?>
									</td>
									<td style="text-align:center; border-right:1px solid; border-bottom:1px solid;">
										<?php echo $rec_subject['receive_amt']; ?>
									</td>
								</tr>
								<?php
								$feetotal += $rec_subject['receive_amt'];
								?>

							<?php } ?>
							<tr>
								<td colspan="4" style="border-right:1px solid;">
									<b>Total</b>
								</td>

								<td style="text-align:center; border-right:1px solid; border-bottom:1px solid;">
									<b><?php echo $totalfees; ?></b>
								</td>
							</tr>

							<?php
							if ($show_detail == 1) {
								$feesreceive_ids = implode(',', $feesreceive_ids);

								$condition4 = "";
								$condition4 .="and frd.feesreceive_id in($feesreceive_ids) ORDER BY fh.head_id";
								$res_fees1 = $objStudentFeesRecMgmt->getAllFeesReceipthead($condition4);

								/*|$sql_fees = "
																											SELECT frm.discount, fh.head_name, frd.recdetail_amt
																											FROM cms_feesreceivemaster frm,
																											 cms_feesreceivedetail frd ,
																											 cms_feeshead fh 
																											WHERE frm.feesreceive_id = frd.feesreceive_id and 
																											frd.head_id = fh.head_id and
																											frd.feesreceive_id in($feesreceive_ids)
																											ORDER BY fh.head_name";

																										//echo $sql_fees;
																										$res_fees = dbQuery($sql_fees);*/
								?>
								<tr style="border: 1px solid;">
									<td colspan="6" style="text-align: center; border: 1px solid;">
										<u><b>Student Fees Records Details</b></u><br><br>
									</td>
								</tr>
								<tr>
									<th colspan="4"
										style="text-align:center; border-top :1px solid ;border-right:1px solid; border-bottom:1px solid;">
										<b>Particulars</b>
									</th>
									<th colspan="2" style="text-align:center; border-right:1px solid; ">
										<b>Amount</b>
									</th>
								</tr>
								<tr>
									<td colspan="1" style="text-align:center;  border-right:1px solid; border-bottom:1px solid;"><b>Sr No.</b></td>
									<td colspan="3" style=" text-align:center; border-right:1px solid; border-bottom:1px solid;"><b>Head Name</b>
									</td>
									<td style=" text-align:center; border-right:1px solid; border-bottom:1px solid;"></td>
								</tr>
								<?php
								$feestotal=0;
								$srno = 1;
								if (dbRows($res_fees1) > 0) {
									while ($rec_fees = dbArray($res_fees1)) {
										$feestotal += $rec_fees['recdetail_amt'];
										if ($rec_fees['recdetail_amt'] != "" && $rec_fees['recdetail_amt'] != 0) {

											?>

											<tr>
												<td colspan="1" style="text-align:center;  border-right:1px solid; border-bottom:1px solid;">
													<?php echo $srno++; ?>
												</td>
												<td colspan="3" style=" text-align:center; border-right:1px solid; border-bottom:1px solid;">
													<?php if ($rec_fees["head_id"] == 'Last Year') {
											echo "Last Year";
										} else {
											echo $rec_fees["head_name"];
										} ?>:
												</td>
												<td style=" text-align:center; border-right:1px solid; border-bottom:1px solid;">
													<?php echo $rec_fees['recdetail_amt']; ?>
												</td>
											</tr>
											<?php
										}

										
									}
								}
								?>
								<tr>
									<th colspan='4' style="border-right:1px solid;"><b>Total Received:</b></th>
									<th colspan='2' style="text-align:center;"><b>Rs. <?php echo $feestotal; ?></b></th>
								</tr>
								<?php
							}
					}
				}
			} else {
				echo "NO DATA FOUND!";
			} ?>
				<?php
		}
	}
	?>
	</table>
	<?php
	$HtmlCode = ob_get_contents();
	ob_end_flush();
	$header_row_string = "";
	$HtmlUrl = "student-overall-report.html";
	$HtmlPath = "report/" . $HtmlUrl;
	createHTMLReportPage($header_row_string, $HtmlUrl, $HtmlPath, $HtmlCode, false);
	?>
	<br />
	<form name="frm" id="frm" action="" method="post">
		<input type="hidden" name="txtFile" id="txtFile" value="<?php echo $HtmlUrl; ?>" />
		<input type="button" style="width:50px;height:25px;" name="btnPrint" id="btnPrint" value="Print"
			onClick="SetPageAction('PRINT');" />
		<input type="button" name="btnHtml" style="width:90px;height:25px;" id="btnHtml" value="Create HTML"
			onclick="SetPageAction('HTML');" />
		<input type="button" name="btnPdf" style="width:90px;height:25px;" id="btnPdf" value="Create PDF"
			onclick="SetPageAction('PDF');" />
		<!--<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">
		//	SetPageAction('PRINT');
		function SetPageAction(varAction) {
			if (varAction == "PRINT") {
				document.frm.action = "print/create-print.php";
				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 }//section_id condition over
else {
	echo "Session Expired";
} ?>
<?php require "_footer.php"; ?>