<?php require "_header.php";
error_reporting(1);
include("Numbers/Words.php");
$nw = new Numbers_Words();
global $SiteBaseUrl;
?>
<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>

<div style="float:left">
	<a href="addedit-feesreceive.php">&laquo;&nbsp;Back to Fee Recive</a>
</div>
<br>
<?php
$header_row_string = "";
$branch_id = Escape($_REQUEST['branch_hidden']);
$semester_id = Escape($_REQUEST['semester_hidden']);
$branchyear_id = Escape($_REQUEST['branchyear_hidden']);
$year_id = Escape($_REQUEST['year_hidden']);
$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");

if ($_REQUEST['branch_hidden'] == "") { ?>
	<script language="javascript" type="text/javascript">
		location.href = 'report-form-student-feereceipt.php';
	</script>
	<?php
} else if ($_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.comment_show,
			  frm.comments,
			  frm.branch_id,
			  frm.semester_id,
			  frm.createdon,
			  frm.discount
		  FROM
			  cms_feesreceivemaster frm
		  WHERE
			   frm.college_id = '" . $_SESSION['VedantnrCollegeId'] . "'";
			  
			  $res_receipt = dbQuery($sql_receipt);*/
	$condition = "";
	if ($student_id != "") {
		$condition .= " AND frm.student_id = " . $student_id . " ";
	}
	if ($from_date != "" && $to_date != "") {
		$condition .= " AND frm.receipt_date BETWEEN '{$from_date}' AND '{$to_date}'";
	}
	if ($branch_id != "") {
		$condition .= " AND frm.branch_id = " . $branch_id;
	}
	if ($year_id != "") {
		$condition .= " AND frm.year_id = " . $year_id;
	}
	if ($branchyear_id != "") {
		$condition .= " AND frm.branchyear_id = " . $branchyear_id;
	}
	if ($semester_id != "") {
		$condition .= " AND frm.semester_id = " . $semester_id;
	}
	$condition .= " ORDER By frm.receipt_no ASC";


	$objFees = new StudentFeesRecMgmt();
	$res_receipt = $objFees->getAllRecord($condition);
	if (dbRows($res_receipt) > 0) {
		$break = 0;

		ob_start();
		while ($rec_receipt = dbArray($res_receipt)) {
			extract($rec_receipt);

			$createdon = date('Ymd', strtotime($rec_receipt['receipt_date']));
			/*$sql_student = "SELECT 
														   stud.student_gturegno,
														   stud.student_grno,
														   CONCAT(stud.student_surname,' ',stud.student_firstname,' ',SUBSTR(stud.student_lastname,1,1),'.') AS student_name,
									   
														   (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 stud,
														   cms_studentdetail sd	
													   WHERE
														   stud.student_id = sd.student_id AND
														   stud.student_id = $student_id AND
														   sd.college_id = '" . $_SESSION['VedantnrCollegeId'] . "'  AND
														   stud.college_id = '" . $_SESSION['VedantnrCollegeId'] . "' ";*/
			$condition1 = "";
			if ($branch_id != "") {
				$condition1 .= " AND sd.cur_branchid = " . $branch_id;
			}
			if ($year_id != "") {
				$condition1 .= " AND sd.year_id = " . $year_id;
			}
			if ($branchyear_id != "") {
				$condition1 .= " AND sd.cur_branchyearid = " . $branchyear_id;
			}
			if ($semester_id != "" && $semester_id != 0) {
				$condition1 .= " AND sd.cur_semesterid = " . $semester_id;
			}

			$condition1 .= " AND stud.student_id = $student_id ";
			$res_student = $objFees->getstudentfeereceipt($condition1);
			//$res_student = dbQuery($sql_student);
			$rec_student = dbArray($res_student);
			$student_id = $rec_student['student_id'];
			/*$sql_fees = "
												SELECT
												   fh.head_name,
												   frd.recdetail_amt
											   FROM
												   cms_feesreceivemaster frm,
												   cms_feesreceivedetail frd,
												   cms_feeshead fh			
											   WHERE
												   fh.head_name != 'College Dev. Fee' AND
												   fh.head_name != 'Scope Fee' AND
												   frm.receipt_no = $receipt_no AND
												   frm.college_id = '" . $_SESSION['VedantnrCollegeId'] . "'  AND
												   frm.feesreceive_id = frd.feesreceive_id AND
												   frd.head_id = fh.head_id  
											   ORDER BY fh.head_id";
											   $res_fees = dbQuery($sql_fees);*/
			$condition2 = "";
			if ($branch_id != "") {
				$condition2 .= " AND frm.branch_id = " . $branch_id;
			}
			if ($year_id != "") {
				$condition2 .= " AND frm.year_id = " . $year_id;
			}
			if ($branchyear_id != "") {
				$condition2 .= " AND frm.branchyear_id = " . $branchyear_id;
			}
			if ($semester_id != "") {
				$condition2 .= " AND frm.semester_id = " . $semester_id;
			}
			$condition2 .= "  AND frm.receipt_no = '$receipt_no'";
			$condition2 .= " ORDER BY fh.head_id ";
			$res_fees = $objFees->getAllFeesReceipthead($condition2);
			if (dbRows($res_fees) > 0) { ?>

					<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>
							<td colspan="4" style="text-align: center; border: 1px solid; border-bottom: hidden;">
								<u><b>Fee Receipt</b></u><br><br>
							</td>
						</tr>
						<tr>
							<th style="line-height:20px;text-align:left;" width="20%"><b>Student Name:</b></th>
							<td style="line-height:20px;text-align:left;" width="30%">
							<?php echo $rec_student['student_name']; ?>
							</td>
							<th style="line-height:20px;text-align:left;" width="14%"><b>Receipt No:</b></th>
							<td style="line-height:20px;text-align:left;" width="8%"><?php echo $receipt_no; ?></td>
						</tr>
						<tr>
							<th style="line-height:20px;text-align:left;" width="14%"><b>Enrollment No:</b></th>
							<td style="line-height:20px;text-align:left;" width="40%"><?php echo $rec_student['student_gturegno']; ?>
							</td>
							<th style="line-height:20px;text-align:left;" width="14%"><b>GR No:</b></th>
							<td style="line-height:20px;text-align:left;" width="8%"><?php echo $rec_student['student_grno']; ?></td>
						</tr>
						<tr>
							<th style="line-height:20px;text-align:left;" width="11%"><b>Course:</b></th>
							<td style="line-height:20px;text-align:left;">
							<?php echo $rec_student['branch_name'] . "  " . $rec_student['year_name'] . " " . $rec_student['branchyear_name'] . "  " . $rec_student['semester_name']; ?>
							</td>
							<th style="line-height:20px;text-align:left;" width="18%"><b>Receipt Date:</b></th>
							<td style="line-height:20px;text-align:left;" width="15%">
							<?php echo date('d-m-Y', strtotime($receipt_date)); ?>
							</td>
						</tr>
						<tr>
							<td colspan="4">
								<table style="width: 100%; border-collapse: collapse; border-right: hidden; border-left:hidden;">
									<?php
									$total = 0;
									$total1 = 0;
									$counter = 0;
									?>
									<tr style="border: 1px solid;">
										<th style="line-height:20px; border-right:1px solid;text-align:center;" width="50%"><b>Fees Head</b>
										</th>
										<th style="line-height:20px; border-right:1px solid;text-align:center;" width="40%"><b>Amount</b>
										</th>
									</tr>
									<?php
									while ($rec_fees = dbArray($res_fees)) {
										if ($rec_fees['recdetail_amt'] != "" && $rec_fees['recdetail_amt'] != 0) {
											$no = 0;
											?>
											<tr style="border: 1px solid;">
												<td style="line-height:20px; border-right:1px solid;" width="50%">
												<?php 
											echo $rec_fees["head_name"];
										 ?>:
												</td>
												<td style="line-height:20px; " width="40%"><?php echo $rec_fees['recdetail_amt']; ?></td>
											</tr>
										<?php
										}
										$i++;
										$total = $total + $rec_fees['recdetail_amt'];
									}
									?>
									<tr style="border: 1px solid;">
										<td style="line-height:35px;font-weight: bold; border-right:1px solid;" width="80%">Grand Total(In
											Words) :<?php echo strtoupper($nw->toWords($total) . " Rs"); ?></td>
										<td style="line-height:20px;font-weight: bold; " width="20%"><?php echo $total; ?>
										</td>
									</tr>
								</table>
							</td>

						</tr>
						<?php
						$gtuo = $rec_student['student_gturegno'];
						$barcode = $receipt_no . $createdon . $gtuo;
						?>
						<tr>
							<td colspan="4">
								<table style="width: 100%; border-collapse: collapse;border-right: hidden; border-left:hidden;">
									<tr>

										<td valign="top" width="60%">
											<br></br>
										<?php echo "<img src='$SiteBaseUrl/bc.php?barcode=" . $barcode . "&width=550&height=50' alt='barcode' />"; ?>
										</td>
										<td valign="top" width="100%" style="text-align:right; ">For Principal</td>

										<td valign="top" width="100%" style="text-align:center; ">
											<br></br>
											_________________</br>
											Cashier
										</td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
				<?php
			}
			/*$sql_fees = "
									   SELECT
										  fh.head_name,
										  frd.recdetail_amt
									  FROM
										  cms_feesreceivemaster frm,
										  cms_feesreceivedetail frd,
										  cms_feeshead fh			
									  WHERE
										  fh.head_name != 'College Dev. Fee' AND
										  fh.head_name != 'Scope Fee' AND
										  frm.receipt_no = $receipt_no AND
										  frm.college_id = '" . $_SESSION['VedantnrCollegeId'] . "'  AND
										  frm.feesreceive_id = frd.feesreceive_id AND
										  frd.head_id = fh.head_id  
									  ORDER BY fh.head_id";
									   
									   $res_fees = dbQuery($sql_fees);*/
			$condition3 = "";
			if ($branch_id != "") {
				$condition3 .= " AND frm.branch_id = " . $branch_id;
			}
			if ($year_id != "") {
				$condition3 .= " AND frm.year_id = " . $year_id;
			}
			if ($branchyear_id != "") {
				$condition3 .= " AND frm.branchyear_id = " . $branchyear_id;
			}
			if ($semester_id != "") {
				$condition3 .= " AND frm.semester_id = " . $semester_id;
			}
			$condition3 .= " AND frm.receipt_no ='$receipt_no'";
			$condition3 .= " ORDER BY fh.head_id ";
			$res_fees = $objFees->getAllFeesReceipthead($condition3);
			if (dbRows($res_fees) > 0) { ?>

					<br></br>
					<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>
							<td colspan="4" style="text-align: center; border: 1px solid; border-bottom: hidden;">
								<u><b>Fee Receipt</b></u><br><br>
							</td>
						</tr>
						<tr>
							<th style="line-height:20px;text-align:left;" width="20%"><b>Student Name:</b></th>
							<td style="line-height:20px;text-align:left;" width="30%">
							<?php echo $rec_student['student_name']; ?>
							</td>
							<th style="line-height:20px;text-align:left;" width="14%"><b>Receipt No:</b></th>
							<td style="line-height:20px;text-align:left;" width="8%"><?php echo $receipt_no; ?></td>
						</tr>
						<tr>
							<th style="line-height:20px;text-align:left;" width="14%"><b>Enrollment No:</b></th>
							<td style="line-height:20px;text-align:left;" width="40%"><?php echo $rec_student['student_gturegno']; ?>
							</td>
							<th style="line-height:20px;text-align:left;" width="14%"><b>GR No:</b></th>
							<td style="line-height:20px;text-align:left;" width="8%"><?php echo $rec_student['student_grno']; ?></td>
						</tr>
						<tr>
							<th style="line-height:20px;text-align:left;" width="11%"><b>Course:</b></th>
							<td style="line-height:20px;text-align:left;">
							<?php echo $rec_student['branch_name'] . "  " . $rec_student['year_name'] . " " . $rec_student['branchyear_name'] . "  " . $rec_student['semester_name']; ?>
							</td>
							<th style="line-height:20px;text-align:left;" width="18%"><b>Receipt Date:</b></th>
							<td style="line-height:20px;text-align:left;" width="15%">
							<?php echo date('d-m-Y', strtotime($receipt_date)); ?>
							</td>
						</tr>
						<tr>
							<td colspan="4">
								<table style="width: 100%; border-collapse: collapse; border-right: hidden; border-left:hidden;">
									<?php
									$total = 0;
									$total1 = 0;
									$counter = 0;
									?>
									<tr style="border: 1px solid;">
										<th style="line-height:20px; border-right:1px solid;text-align:center;" width="50%"><b>Fees Head</b>
										</th>
										<th style="line-height:20px; border-right:1px solid;text-align:center;" width="40%"><b>Amount</b>
										</th>
									</tr>
									<?php
									while ($rec_fees = dbArray($res_fees)) {
										if ($rec_fees['recdetail_amt'] != "" && $rec_fees['recdetail_amt'] != 0) {
											$no = 0;
											?>

											<tr style="border: 1px solid;">
												<td style="line-height:20px; border-right:1px solid;" width="50%">
												
												<?php 
											echo $rec_fees["head_name"];
										 ?>:</td>
												<td style="line-height:20px; " width="40%"><?php echo $rec_fees['recdetail_amt']; ?></td>
											</tr>
										<?php
										}
										$i++;
										$total = $total + $rec_fees['recdetail_amt'];
									}
									?>
									<tr style="border: 1px solid;">
										<td style="line-height:35px;font-weight: bold; border-right:1px solid;" width="80%">Grand Total(In
											Words) :<?php echo strtoupper($nw->toWords($total) . " Rs"); ?></td>
										<td style="line-height:20px;font-weight: bold; " width="20%"><?php echo $total; ?>
										</td>
									</tr>
								</table>
							</td>
						</tr>
						<?php
						$gtuo = $rec_student['student_gturegno'];
						$barcode = $receipt_no . $createdon . $gtuo;
						?>
						<tr>
							<td colspan="4">
								<table style="width: 100%; border-collapse: collapse;border-right: hidden; border-left:hidden;">
									<tr>
										<td valign="top" width="60%">
											<br></br>
										<?php echo "<img src='$SiteBaseUrl/bc.php?barcode=" . $barcode . "&width=550&height=50' alt='barcode' />"; ?>
										</td>

										<td valign="top" width="100%" style="text-align:right; ">For Student</td>

										<td valign="top" width="100%" style="text-align:center; ">
											<br></br>
											_________________</br>
											Cashier
										</td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
					<br /><br />
				<?php
			}
		}
	} else {
		echo "No Data Found";
	}
	?>

		<?php
		$HtmlCode = ob_get_contents();
		//echo $HtmlCode;
		ob_end_flush();
		$HtmlUrl = "feereceipt-report.html";
		$HtmlPath = "report/" . $HtmlUrl;
		createHTMLReportPage($header_row_string, $HtmlUrl, $HtmlPath, $HtmlCode);
		?>
		<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">
			//	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
} else {
	echo "Session Expired";
}
?>
<?php require "_footer.php"; ?>