<?php require "_header.php";

?>
<script language="javascript" type="text/javascript">

</script>
<style>
	.table-report {
		font-family: Verdana, Geneva, sans-serif;
		font-size: 12px;
		text-align: left;
		border-right: 0px none;
		border-bottom: 0px none;
	}

	.table-report-inner {
		font-family: Verdana, Geneva, sans-serif;
		font-size: 12px;
	}

	.table-report tr {
		padding: 2px 2px 2px 2px;
	}

	.table-report td {
		padding: 2px 2px 2px 2px;
		border-top: 0px none;
		border-left: 0px none;
	}

	.table-report th {
		padding: 2px 2px 2px 2px;
		font-weight: bold;
		text-align: left;
		border-top: 0px none;
		border-left: 0px none;
	}

	.college_name {
		font-family: QTAbbie;
		font-size: 22px;
		font-weight: bold;
		padding: 2px 2px 2px 2px;
		text-align: center;
	}

	.college_address {
		font-family: Tahoma, Geneva, sans-serif;
		font-size: 11px;
		text-align: center;
		padding: 2px 2px 2px 2px;
	}

	.report_name {
		font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
		font-size: 13px;
		background-color: #CCC;
		text-align: center;
		font-weight: bold;
		padding: 2px 2px 2px 2px;
	}
</style>
<?php
$header_row_string = "";
$display_str = "";
$startdate = Escape($_REQUEST['feesrec_startdate']);
$enddate = Escape($_REQUEST['feesrec_enddate']);
$startrecno = Escape($_REQUEST['feesrec_startno']);
$endrecno = Escape($_REQUEST['feesrec_endno']);
$report_type = Escape($_REQUEST['report_type']);

//echo $enddate; exit;
$report_selection = Escape($_REQUEST['report_selection']);

if (($startdate == "" && $enddate == "") && ($startrecno == "" && $endrecno == "")) { ?>
	<script language="javascript" type="text/javascript">
		location.href = 'report-daily-fees-collection.php';
	</script><?php
} elseif ($_SESSION['VedantnrCollegeId'] != "" && isset($_SESSION['VedantnrCollegeId'])) {
	ob_start();

	$final_cash = 0;
	$final_bank = 0;
	$final_online = 0;
	$date_cash = 0;
	$date_bank = 0;
	$date_online = 0;
	$str_date = "";
	$condition = "";

	if ($report_selection == "recno_selection") {
		$condition .= " AND frm.receipt_no >= '$startrecno' AND frm.receipt_no <= '$endrecno' ";
		$display_str = "Receipt No: $startrecno - $endrecno";
	} else if ($report_selection == "date_selection") {
		$condition .= " AND frm.receipt_date >= '$startdate' AND frm.receipt_date <= '$enddate' ";

		if ($_REQUEST['feesrec_startdate'] != $_REQUEST['feesrec_enddate']) {
			$display_str = "Receipt Date: " . $_REQUEST['feesrec_startdate'] . " - " . $_REQUEST['feesrec_enddate'];
		} else {
			$display_str = "Receipt Date: " . $_POST['feesrec_startdate'];
		}
	}

	$objFeeshead = new FeesheadMgmt();
	$RES_HEADING = $objFeeshead->gethead($condition = "");
	$RES_HEADING1 = $objFeeshead->gethead($condition = "");
	//$SQL_HEADING = "SELECT Distinct(fees_type) FROM cms_feeshead WHERE head_name != 'ACPDC Adm Fee' ORDER BY head_id ASC";
	//	echo $SQL_HEADING;
	//$RES_HEADING = dbQuery($SQL_HEADING);

	if (dbRows($RES_HEADING) > 0) { ?>

<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>


		<div class="report_name">
			Daily Fees Collection - Descriptive Report</div>

		<table>
			<tr>
				<td style="text-align: left;border:none;  font-size: 11px;"><?php echo $display_str; ?></td>
				<td style="text-align: right;border:none;  font-size: 11px;">C:cash, B:cheque, O:Online</td>
			</tr>
		</table>

		<table class="table-report" border="1" cellpadding="0" cellspacing="0" width="80%">
			<tr>
				<th style="text-align:center;">Receipt No</th>
				<th style="text-align:center;">Date</th>

				<?php
				while ($REC_HEADING = dbArray($RES_HEADING)) { ?>

					<?php
				} ?>
				<th style="text-align:center;">Total Amount</th>
				<th style="text-align:left;">Received By</th>
				<th style="text-align:left;">Cash</th>
				<th style="text-align:left;">Cheque</th>
				<th style="text-align:left;">Online</th>
			</tr><?php
			while ($REC_HEADING1 = dbArray($RES_HEADING1)) {


				/*$SQL_SELECT = "SELECT
															frm.feesreceive_id,
															MAX(frm.receipt_no) as receipt,
															MIN(frm.receipt_no) as receipt1,
															sm.student_gturegno,
															CONCAT(sm.student_surname,' ',sm.student_firstname,' ',sm.student_lastname) AS student_name,
															SUM(frm.receive_amt) as receive_amt ,
															frm.total_receive_amt,
															frm.discount,
															frm.cheque_no,
															frm.receipt_date,
															(SELECT user_name 
																	FROM cms_usermaster um 
																	WHERE um.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' and frm.login_id =um.user_id) AS user_name,
														
														(SELECT branch_name 
																	FROM cms_branchmaster bm 
																	WHERE bm.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' and frm.branch_id =bm.branch_id) AS branch_name,
															(SELECT year_name 
																	FROM cms_yearmaster ym  WHERE  frm.year_id  =ym.year_id) AS year_name,
															(SELECT branchyear_name
																	FROM cms_branchyear bry 
																	WHERE  bry.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' AND frm.branchyear_id = bry.branchyear_id) AS branchyear_name,
															(SELECT semester_name
																	FROM cms_semestermaster sem 
																	WHERE  sem.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' AND frm.semester_id = sem.semester_id) AS semester_name	  							
											
														FROM
															cms_feesreceivemaster frm,
															cms_studentmaster sm
																	
														WHERE 
															sm.student_id = frm.student_id  ";

													$SQL_SELECT .= $condition;
													$SQL_SELECT .= " GROUP BY frm.receipt_date ASC ";
													$RES_SELECT = dbQuery($SQL_SELECT);*/

				$condition2 = "";
				$condition2 .= $condition;
				$condition2 .= " GROUP BY frm.receipt_date ASC ";
				$objFees = new StudentFeesRecMgmt();
				$RES_SELECT = $objFees->getfeessummary($condition2);
				//echo $SQL_SELECT;
				if (dbRows($RES_SELECT) > 0) {
					?>
					<tr>
						<th colspan="7" style="text-align:center;"><?php echo $REC_HEADING1['fees_type']; ?></th>
					</tr>

					<?php
					$sum = 0;
					$sum1 = 0;
					$sum2 = 0;
					$sum3 = 0;
					while ($REC_SELECT = dbArray($RES_SELECT)) {
						$receipt_date = date('d-m-Y', strtotime($REC_SELECT['receipt_date']));

						if ($startdate != $enddate) {
							if ($str_date != $receipt_date) {
								if ($date_cash > 0 || $date_bank > 0 || $date_online > 0) {
									if ($date_cash > 0 && $date_bank > 0 && $date_online > 0) { ?>
										<tr>
											<th colspan="14" style="text-align:right;">Cash Received</th>
											<th style="text-align:right;"><?php echo number_format($date_cash); ?></th>
											<th>&nbsp;</th>
										</tr>
										<tr>
											<th colspan="14" style="text-align:right;">Cheque Received</th>
											<th style="text-align:right;"><?php echo number_format($date_bank); ?></th>
											<th>&nbsp;</th>
										</tr>
										<tr>
											<th colspan="14" style="text-align:right;">Online Received</th>
											<th style="text-align:right;"><?php echo number_format($date_online); ?></th>
											<th>&nbsp;</th>
										</tr><?php
									} ?>
									<?php
								} ?>
								<?php
								$str_date = $receipt_date;
							}
						}
						?>
						<tr>
							<td style="text-align:center;"><?php echo $REC_SELECT['receipt1'] . ' - ' . $REC_SELECT['receipt']; ?></td>
							<td style="text-align:center;"><?php echo date('d-m-Y', strtotime($REC_SELECT['receipt_date'])); ?></td>
							<?php if ($REC_SELECT['receive_amt'] == 0) {
								?>
								<td style="text-align:center;">-</td>
								<?php
							} else {
								?>
								<td style="text-align:center;"><?php echo $REC_SELECT['receive_amt']; ?></td>
								<?php
							}
							?>
							<td style="text-align:center;"><?php echo $REC_SELECT['user_name']; ?></td>
							<td style="text-align:right; padding-right:2px;">
								<?php
								/*$SQL_CASH = " SELECT
																								SUM(receive_amt) AS receive_amt
																							FROM
																								cms_feesreceivemaster frm
																							WHERE
																								frm.cheque_no = '' AND	 
																								frm.fees_type = '$fees' AND	 
																								frm.receipt_date = '" . $REC_SELECT["receipt_date"] . "'";
																				$SQL_CASH .= $condition;
																				//echo $SQL_CASH;
																				$RES_CASH = dbQuery($SQL_CASH);*/

								$condition2 = "";
								$condition2 .= $condition;
								$condition2 .= " and frm.cheque_no = '' and frm.ref_no = '' AND frm.receipt_date = '" . $REC_SELECT["receipt_date"] . "'";
								$RES_CASH = $objFees->getfeessummary1($condition2);
								while ($REC_CASH = dbArray($RES_CASH)) {
									echo number_format($REC_CASH['receive_amt']);
									$sum += $REC_CASH['receive_amt'];
									break;
								} ?>
							</td>
							<td style="text-align:right; padding-right:2px;">
								<?php
								/*$SQL_CASH = "
																							SELECT
																								SUM(receive_amt) AS receive_amt
																							FROM
																								cms_feesreceivemaster frm
																							WHERE
																								frm.cheque_no != ''  ";
																				$SQL_CASH .= $condition;
																			
																				$RES_CASH = dbQuery($SQL_CASH); */
								$condition3 = "";
								$condition3 .= " AND frm.cheque_no != ''  
											AND	frm.receipt_date = '" . $REC_SELECT["receipt_date"] . "'";
								$condition3 .= $condition;

								$RES_CASH = $objFees->getfeessummary1($condition3);

								while ($REC_CASH = dbArray($RES_CASH)) {
									echo number_format($REC_CASH['receive_amt']);
									$sum1 += $REC_CASH['receive_amt'];
									break;

								} ?>
							</td>
							<td style="text-align:right; padding-right:2px;">
								<?php
								/*$SQL_CASH = "
																							SELECT
																								SUM(receive_amt) AS receive_amt
																							FROM
																								cms_feesreceivemaster frm
																							WHERE
																								frm.cheque_no != ''  ";
																				$SQL_CASH .= $condition;
																			
																				$RES_CASH = dbQuery($SQL_CASH); */
								$condition4 = "";
								$condition4 .= " AND frm.ref_no != ''  
											AND	frm.receipt_date = '" . $REC_SELECT["receipt_date"] . "'";
								$condition4 .= $condition;

								$RES_CASH = $objFees->getfeessummary1($condition4);

								while ($REC_CASH = dbArray($RES_CASH)) {
									echo number_format($REC_CASH['receive_amt']);
									$sum2 += $REC_CASH['receive_amt'];
									break;

								} ?>
							</td>
							<?php
							$sum3 += $REC_SELECT['receive_amt'];
					}
					?>
					<tr>
						<td style="text-align:Center; padding-right:2px;" colspan="2"><b>Total</b></td>
						<td style="text-align:Center; padding-right:2px;"><b><?php echo $sum3; ?></b></td>
						<td style="text-align:Center; padding-right:2px;"></td>
						<td style="text-align:right; padding-right:2px;"><b><?php echo $sum; ?></b></td>
						<td style="text-align:right; padding-right:2px;"><b><?php echo $sum1; ?></b></td>
						<td style="text-align:right; padding-right:2px;"><b><?php echo $sum2; ?></b></td>
					</tr>
					<?php
				}
			}
			?>
			</tr>
			<tr>
				<th colspan="17" style="text-align:center; color:#000; background-color:#CCC;">Received By</th>
			</tr>
			<tr>
				<td colspan="17" align="center">
					<table width="40%" border="1" cellpadding="0" cellspacing="0" class="table-report">
						<tr>
							<th>Receiver</th>
							<th style="text-align:right; padding-right:2px;">Cash</th>
							<th style="text-align:right; padding-right:2px;">Cheque</th>
							<th style="text-align:right; padding-right:2px;">Online</th>
							<th style="text-align:right; padding-right:2px;">Total</th>
						</tr>
						<?php
						/*$SQL_RECEIVER = "SELECT
																			SUM(receive_amt + total_receive_amt - amount_discount) AS receive_amt,
																			um.user_id,
																			um.user_name
																		FROM
																			cms_feesreceivemaster frm,
																			cms_usermaster um	 		
																		WHERE
																			um.user_id = frm.login_id ";
															$SQL_RECEIVER .= $condition;
															$SQL_RECEIVER .= " GROUP BY frm.login_id ORDER BY frm.receipt_no ASC ";
															$RES_RECEIVER = dbQuery($SQL_RECEIVER);*/
						$condition4 = "";
						$condition4 .= $condition;
						$condition4 .= " GROUP BY frm.login_id ORDER BY frm.receipt_no ASC ";
						$RES_RECEIVER = $objFees->getfeessummary2($condition4);
						if (dbRows($RES_RECEIVER) > 0) {
							while ($REC_RECEIVER = dbArray($RES_RECEIVER)) {
								?>
								<tr>
									<td><?php echo $REC_RECEIVER['user_name']; ?></td>
									<td style="text-align:right; padding-right:2px;">
										<?php
										/* $SQL_CASH = "
																		  SELECT
																			  SUM(receive_amt + total_receive_amt - amount_discount) AS receive_amt
																		  FROM
																			  cms_feesreceivemaster frm
																		  WHERE
																			  frm.cheque_no = '' AND	 
																			  frm.login_id = '" . $REC_RECEIVER['user_id'] . "'";
																	  $SQL_CASH .= $condition;
																	  $RES_CASH = dbQuery($SQL_CASH);*/
										$condition5 = "";
										$condition5 .= $condition;
										$condition5 .= " and
												frm.cheque_no = '' and
												frm.ref_no = ''AND	 
												frm.login_id = '" . $REC_RECEIVER['user_id'] . "'";
										$RES_CASH = $objFees->getfeessummary2($condition5);
										$REC_CASH = dbArray($RES_CASH);
										echo number_format($REC_CASH['receive_amt']);
										?>
									</td>
									<td style="text-align:right; padding-right:2px;">
										<?php
										/*$SQL_CASH = "
																		  SELECT
																			  SUM(receive_amt + total_receive_amt - amount_discount) AS receive_amt
																		  FROM
																			  cms_feesreceivemaster frm
																		  WHERE
																			  frm.cheque_no != '' AND	 
																			  frm.login_id = " . $REC_RECEIVER['user_id'];
																	  $SQL_CASH .= $condition;
																	  $RES_CASH = dbQuery($SQL_CASH);*/

										$condition6 = "";
										$condition6 .= $condition;
										$condition6 .= " and
												frm.cheque_no != '' AND	 
												frm.login_id = '" . $REC_RECEIVER['user_id'] . "'";
										$RES_CASH = $objFees->getfeessummary2($condition6);
										$REC_CASH = dbArray($RES_CASH);
										echo number_format($REC_CASH['receive_amt']);
										?>
									</td>
									<td style="text-align:right; padding-right:2px;">
										<?php
										/*$SQL_CASH = "
																		  SELECT
																			  SUM(receive_amt + total_receive_amt - amount_discount) AS receive_amt
																		  FROM
																			  cms_feesreceivemaster frm
																		  WHERE
																			  frm.cheque_no != '' AND	 
																			  frm.login_id = " . $REC_RECEIVER['user_id'];
																	  $SQL_CASH .= $condition;
																	  $RES_CASH = dbQuery($SQL_CASH);*/

										$condition7 = "";
										$condition7 .= $condition;
										$condition7 .= " and
												frm.ref_no != '' AND	 
												frm.login_id = '" . $REC_RECEIVER['user_id'] . "'";
										$RES_CASH = $objFees->getfeessummary2($condition7);
										$REC_CASH = dbArray($RES_CASH);
										echo number_format($REC_CASH['receive_amt']);
										?>
									</td>
									<td style="text-align:right; padding-right:2px;">
										<?php echo number_format($REC_RECEIVER['receive_amt']) . " Rs"; ?>
									</td>
								</tr>
								<?php
							}
						}
						?>
					</table>
				</td>
			</tr>
			
		</table>
		<?php
	}
	$HtmlCode = ob_get_contents();
	ob_end_flush();
	$HtmlUrl = "daily-fees-collection-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 "Session Expired";
}
?>

<?php require "_footer.php";
?>