<?php require "_header.php";?>
<div>
	<?php
	if ($_REQUEST['student_hidden'] == "") {

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

		$objStudentDocumentMgmt = new StudentDocumentMgmt();
		// Initialize SQL query for unique dates with optional date range filter
		/*$sql_dates = "
						SELECT DISTINCT sd.docrecive_date
						FROM cms_studentdocument sd
						WHERE 
							sd.college_id = " . $_SESSION["VedantnrCollegeId"] . " 
							AND sd.student_id = '$student_id'"; */
		$condition = "";
		$condition .= "  AND sd.student_id = '$student_id'";
		if ($_REQUEST['docrecive_startdate'] != "" && $_REQUEST['docrecive_enddate'] != "") {
			$startdate = Escape($_REQUEST['docrecive_startdate']);
			$enddate = Escape($_REQUEST['docrecive_enddate']);
			$condition .= " AND sd.docrecive_date BETWEEN '$startdate' AND '$enddate'";
		}
		$condition .= " ORDER BY sd.docrecive_date";
		//$res_dates = dbQuery($sql_dates);
		$res_dates = $objStudentDocumentMgmt->getdocument($condition);
		if (dbRows($res_dates) > 0) {
			while ($date_data = dbArray($res_dates)) {
				$docrecive_date = $date_data['docrecive_date'];
				/*	$sql_studentdata = "
											 SELECT 
												 sm.student_id,
												 CONCAT(sm.student_surname, ' ', sm.student_firstname, ' ', sm.student_lastname) AS student_name,
												 bry.branchyear_name,
												 b.branch_name,
												 sem.semester_name,
												 y.year_name
											 FROM 
												 cms_studentdocument sd
												
												  LEFT JOIN cms_branchmaster b ON sd.branch_id = b.branch_id
												   LEFT JOIN cms_branchyear bry ON sd.branchyear_id = bry.branchyear_id
												  LEFT JOIN cms_semestermaster sem ON sd.semester_id =sem.semester_id
												  LEFT JOIN cms_yearmaster y ON sd.year_id =y.year_id
												 LEFT JOIN cms_studentmaster sm ON sd.student_id = sm.student_id
											 WHERE 
												 sd.college_id = " . $_SESSION["VedantnrCollegeId"] . " 
												 AND sd.student_id = '$student_id'
												 AND sd.docrecive_date = '$docrecive_date'
											 GROUP BY 
												 sd.student_id";  */
				$condition1 = "";
				if ($branch_id != "" && $branch_id != "All") {
					$condition1 .= " AND sd.branch_id = '" . $branch_id . "'";
				}
				if ($semester_id != "" && $semester_id != "undefined") {
					$condition1 .= " AND sd.semester_id = '" . $semester_id . "'";
				}

				if ($year_id != "" && $year_id != "undefined") {
					$condition1 .= " AND sd.year_id = '" . $year_id . "'";
				}

				if ($branchyear_id != "" && $branchyear_id != "undefined") {
					$condition1 .= " AND sd.branchyear_id = '" . $branchyear_id . "'";
				}

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

				$condition1 .= " AND sd.student_id = '$student_id' AND sd.docrecive_date = '$docrecive_date'  
				GROUP BY  sd.student_id ";
				//$res_studentdata = dbQuery($sql_studentdata);
				$res_studentdata = $objStudentDocumentMgmt->getstudentdocument($condition1);
				if (dbRows($res_studentdata) > 0) {
					$student_data = dbArray($res_studentdata);
					$student_name = $student_data['student_name'];
					$branch_name = $student_data['branch_name'];
					$year_name = $student_data['year_name'];
					$branchyear_name = $student_data['branchyear_name'];
					$semester_name = $student_data['semester_name'];

					/*$sql_documentdata = "
													  SELECT 
														  dm.document_name,
														  sd.noofdocument
													  FROM 
														  cms_studentdocument sd
														  LEFT JOIN cms_documentmaster dm ON sd.document_id = dm.document_id
													  WHERE 
														  sd.college_id = " . $_SESSION["VedantnrCollegeId"] . " 
														  AND sd.student_id = '$student_id'
														  AND sd.docrecive_date = '$docrecive_date'";
												  $res_documentdata = dbQuery($sql_documentdata);*/
					$condition2 = "";
					$condition2 .= " AND sd.student_id = '$student_id'  AND sd.docrecive_date = '$docrecive_date'";
					$res_documentdata = $objStudentDocumentMgmt->getstudentdocumentdata($condition2);
					?>
					<table style="width: 70%; margin: 0 auto; border-collapse: collapse; border: 1px solid;" class="table-bordered">
						<tr style="vertical-align: middle;">
							<td colspan="6" 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="6" style="text-align: center; border: 1px solid; border-bottom: hidden;">
								<u>Student's Original Documents Receiving Detail List </u><br><br>
							</td>
						</tr>
						<tr>
							<td width="30%" style="border-right: hidden; border-bottom: hidden;">Name of the Student:</td>
							<td width="60%" style="border-right: hidden; border-bottom: hidden;"><?php echo $student_name; ?></td>
							<td rowspan="2" style="border-left: hidden; border-bottom: hidden;">&nbsp;</td>
						</tr>
						<tr>
							<td style="border: 1px solid; border-right: hidden; border-bottom: hidden;">Course:</td>
							<td style="border: 1px solid;border-bottom: hidden ; "><?php echo $branch_name; ?></td>
						</tr>
						<tr>
							<td style="border: 1px solid; border-right: hidden; border-bottom: hidden;">Batch Year:</td>
							<td style="border: 1px solid;  border-right: hidden;  border-bottom: hidden ; "><?php echo $year_name; ?>
							</td>
						</tr>
						<tr>
							<?php if ($_REQUEST['branchyear_hidden'] != "") { ?>
								<td style="border: 1px solid; border-right: hidden; border-bottom: hidden;">Course Year:</td>
								<td style="border: 1px solid; border-right: hidden;  border-bottom: hidden;"><?php echo $branchyear_name; ?>
								</td>
							<?php } ?>
						</tr>
						<tr>
							<?php if ($_REQUEST['semester_hidden'] != "") { ?>
								<td style="border: 1px solid; border-right: hidden; border-bottom: hidden;">Semester:</td>
								<td style="border: 1px solid; border-right: hidden; border-bottom: hidden;"><?php echo $semester_name; ?>
								</td>
							<?php } ?>
						</tr>
						<tr>
							<td style="border: 1px solid; border-right: hidden; border-top: hidden;">Date of Receiving Document:</td>
							<td style="border: 1px solid; border-right: hidden; border-top: hidden;"><?php echo $docrecive_date; ?></td>
							<td style="border: 1px solid; border-top: hidden;">Sr. No. &nbsp;&nbsp;&nbsp;&nbsp;1</td>
						</tr>
						<tr>
							<td colspan="3">
								<table style="width: 100%; border-collapse: collapse;">
									<tr>
										<th width="5%" style="border: 1px solid;">Sr. No</th>
										<th width="50%" style="border: 1px solid;">Name of the Document</th>
										<th width="10%" style="border: 1px solid;">No. of Documents Received</th>
										<th width="5%" style="border: 1px solid;">Received (Yes/No)</th>
										<th width="15%" style="border: 1px solid;">Remark</th>
									</tr>
									<?php
									$i = 1;
									$total = 0;
									while ($document_data = dbArray($res_documentdata)) {
										$document_name = $document_data['document_name'];
										$noofdocument = $document_data['noofdocument'];
										$total += $noofdocument;
										?>
										<tr>
											<td style="text-align: center; border: 1px solid;"><?php echo $i++; ?></td>
											<td style="text-align: center; border: 1px solid;"><?php echo $document_name; ?></td>
											<td style="text-align: center; border: 1px solid;"><?php echo $noofdocument; ?></td>
											<td style="border: 1px solid;"><?php echo $noofdocument > 0 ? 'Yes' : 'No'; ?></td>
											<td style="border: 1px solid;">&nbsp;</td>
										</tr>
										<?php
									}
									?>
									<tr>
										<td style="border: 1px solid;">&nbsp;</td>
										<td style="text-align: center; border: 1px solid;">Total</td>
										<td style="text-align: center; border: 1px solid;"><?php echo $total; ?></td>
										<td style="border: 1px solid;">&nbsp;</td>
										<td width="10%" style="border: 1px solid;">Total <?php echo $total; ?>
											(<?php echo numberToWords($total); ?>) Original Documents Given at Shital Institute of
											Nursing</td>
									</tr>
								</table>
							</td>
						</tr>
						<tr>
							<td colspan="3" style="border: 1px solid;">
								<table border="0" style="border-collapse: collapse;">
									<tr style="line-height: 12px; height: 30px;">
										<td width="6%" style="border: hidden;">&nbsp;&nbsp;</td>
										<td width="20%" style="border: hidden;">&nbsp;&nbsp;</td>
										<td width="54%" style="border: hidden;">&nbsp;&nbsp;</td>
										<td style="border: hidden;">&nbsp;</td>
									</tr>
									<tr style="line-height: 12px; height: 60px;">
										<td width="6%" style="border: hidden;">&nbsp;&nbsp;</td>
										<td width="20%" style="border: hidden;">&nbsp;Signature Of Student</td>
										<td width="54%" style="border: hidden;">&nbsp;&nbsp;</td>
										<td style="border: hidden;">Signature Parents/Guardian</td>
									</tr>
								</table>
							</td>
						</tr>
						<tr>
							<td colspan="3" style="border: 1px solid;">
								<div style="display: flex; align-items: center; justify-content: center;">
									<ol>
										<li>Note:</li>
										<li>&nbsp;&nbsp;1. This receipt contains details of student's original documents received at
											Shital Institute of Nursing, Ghodariya on admission time.</li>
										<li>&nbsp;&nbsp;2. The Student will have to show the Student Copy and return it to the
											institution at the time of completion of the course and in case of cancellation of
											admission.</li>
										<li>&nbsp;&nbsp;3. Without this receipt being received by the institution, the original
											documents will not be returned or handed over to the student under any circumstances. The
											student will be responsible for this.</li>
									</ol>
								</div>
							</td>
						</tr>
					</table>
					<br><br>
					<?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" 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
	}
	?>
</div>
<?php require "_footer.php";?>