<?php require "_header.php";?>
<script language="javascript" type="text/javascript">
document.getElementById("main-content").style.display = 'none';
</script>
<div id="main-report" align="center">
<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;
	}
</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;
		$date_cash = 0;
		$date_bank = 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: ".$_REQUEST['feesrec_startdate'];
			}
		}
		
		if($report_type == "summarize_type"){
			$SQL_SELECT = "
				SELECT
					*
				FROM
					cms_chequefeereceive frm,					
					cms_branchmaster bm,
					cms_semestermaster sem,
					cms_usermaster um	 		
				WHERE
					um.user_id = frm.login_id AND
					frm.branch_id = bm.branch_id AND
					frm.semester_id = sem.semester_id AND 
					
					frm.year_id = ".$_SESSION["VedantnrYearId"];
			$SQL_SELECT .= $condition;
			$SQL_SELECT .= " ORDER BY frm.receipt_no ASC ";
			$RES_SELECT = dbQuery($SQL_SELECT);	
			
		
			if(dbRows($RES_SELECT) > 0){?>
				<div class="college_name"><?php echo $_SESSION["VedantnrCollegeName"]; ?></div>
                    <div class="college_address"><?php echo $_SESSION["VedantnrCollegeAddress"]; ?></div>
                    <div class="college_address">
                        Web Site: <?php echo $_SESSION["VedantnrCollegeUrl"] ;?> 
                        &nbsp;&nbsp; 
                        Email: <?php echo $_SESSION["VedantnrCollegeEmail"] ;?> 
                        &nbsp;&nbsp; 
                        Phone: <?php echo $_SESSION["VedantnrCollegePhone"] ;?> 
        </div>
				
            	<center><h4>Daily Exam Fees Collection - Summary Report</h4></center>
                <br /><br />
                <table width="100%">
                <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</td>
                </tr>
                </table>
                
                <table width="100%" class="table-report" border="1" cellpadding="0" cellspacing="0"> 
				<tr>
					
                	<th style="text-align:center;">Receipt No</th>
					<th style="text-align:center;">Date</th>
                    <th style="text-align:center;">Course</th>
        			<th style="text-align:center;">Semester</th>            
		           
                    <th style="text-align:left;">Student Name</th>
                    <th style="text-align:right;">Amount</th>
					<th style="text-align:right;">Late Fee</th>
                    <th style="text-align:left;">Received By</th>
                </tr><?php $counter = 1;
				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){
								if($date_cash > 0 && $date_bank > 0){?>
								<tr>
									<th colspan="5" style="text-align:right;">Cash Received</th>
									<th style="text-align:right;"><?php echo $date_cash; ?></th>
                                    <th>&nbsp;</th>
								</tr>
								<tr>
									<th colspan="5" style="text-align:right;">Cheque Received</th>
									<th style="text-align:right;"><?php echo $date_bank; ?></th>
                                    <th>&nbsp;</th>
								</tr><?php 
								}?>
								<tr>
									<th colspan="5" style="text-align:right;">Total Received Amount</th>
									<th style="text-align:right;"><?php echo $date_cash+$date_bank; ?></th>
                                    <th style="text-align:right;"><?php echo $date_cash1+$date_bank1; ?></th>
									 <th>&nbsp;</th>
								</tr>
								<?php	
								$date_bank = 0;
								$date_cash = 0;
								$date_bank1 = 0;
								$date_cash1 = 0;
							}
							if($counter > 1)
								{
								?>
							        
						<tr style="page-break-after: always;">
								<td colspan="<?php echo $count+8?>">&nbsp;</td>
							</tr>
								<?php
								
								}
								$counter++;
								?>
						<tr>
							<td colspan="8" style="text-align:left;">Receipt Date: <?php echo date('d-m-Y',strtotime($REC_SELECT['receipt_date'])); ?></td>
						</tr><?php 
							$str_date = $receipt_date;
						}
					}
					?>
                	<tr>
						<?php $rollno = "select student_rollno from cms_studentdetail where student_id ='".$REC_SELECT['student_id']."' 
							AND cur_semesterid = '".$REC_SELECT['semester_id']."'AND cur_branchid= '".$REC_SELECT['branch_id']."'";
							
							$rqry = dbQuery($rollno);
							$rollqry = dbArray($rqry);
							?>
							
                    	<td style="text-align:center;"><?php echo $REC_SELECT['receipt_no']; ?></td>
						<td style="text-align:center;"><?php echo date('d-m-Y',strtotime($REC_SELECT['receipt_date'])); ?></td>
                        <td style="text-align:center;"><?php echo $REC_SELECT['branch_name']; ?></td>
                        <td style="text-align:center;"><?php echo $REC_SELECT['semester_name']; ?></td>
                       
                        <td style="text-align:left;"><?php echo $REC_SELECT['student_name']; ?></td>
              
           <?php  if($REC_SELECT['discount'] == 0)
           {
           	?> 
                        <td style="text-align:right;">
							
							<?php echo $REC_SELECT['receive_amt'];?>
							
							
                            <?php
							if($REC_SELECT['cheque_no'] == ""){
								echo "(C)";
								$final_cash += $REC_SELECT['receive_amt'];
								$date_cash += $REC_SELECT['receive_amt'];
							}
							else{
								echo "(B)";
								$final_bank += $REC_SELECT['receive_amt'];
								$date_bank += $REC_SELECT['receive_amt']; 
							}
							?>
              </td> 
			  <td style="text-align:right;">
							
							<?php echo $REC_SELECT['latefee'];?>
							
							
                            <?php
							if($REC_SELECT['cheque_no'] == ""){
								echo "(C)";
								$final_cash1 += $REC_SELECT['latefee'];
								$date_cash1 += $REC_SELECT['latefee'];
							}
							else{
								echo "(B)";
								$final_bank1 += $REC_SELECT['latefee'];
								$date_bank1 += $REC_SELECT['latefee']; 
							}
							?>
              </td> 
            <?php
          }
          else
          {  
           ?>
                       <td style="text-align:right;">
							
							<?php echo $REC_SELECT['receive_amt'];?>
							
                            <?php
							if($REC_SELECT['cheque_no'] == ""){
								echo "(C)";
								$final_cash += $REC_SELECT['receive_amt'];
								$date_cash += $REC_SELECT['receive_amt'];
							}
							else{
								echo "(B)";
								$final_bank += $REC_SELECT['receive_amt'];
								$date_bank += $REC_SELECT['receive_amt']; 
							}
							?>
              </td>
			   <td style="text-align:right;"><?php echo $REC_SELECT['late_fee'];?> </td>
           
          <?php
        	}
        	?>
         
                        <td style="text-align:center;"><?php echo $REC_SELECT['user_name']; ?></td>
                    </tr><?php
				}?>
                <?php
					if($startdate != $enddate){
						if($date_cash > 0 || $date_bank > 0){
							if($date_cash > 0 && $date_bank > 0){?>
							<tr>
								<th colspan="5" style="text-align:right;">Cash Received</th>
								<th style="text-align:right;"><?php echo $date_cash; ?></th>
                                <th>&nbsp;</th>
							</tr>
							<tr>
								<th colspan="5" style="text-align:right;">Cheque Received</th>
								<th style="text-align:right;"><?php echo $date_bank; ?></th>
                                <th>&nbsp;</th>
							</tr><?php 
							}?>
							<tr>
								<th colspan="5" style="text-align:right;">Total Received Amount</th>
								<th style="text-align:right;"><?php echo $date_cash+$date_bank; ?></th>
                              	<th style="text-align:right;"><?php echo $date_cash1+$date_bank1; ?></th>
								  <th>&nbsp;</th>
							</tr>
							<?php	
							$date_bank = 0;
							$date_cash = 0;
							$date_bank1 = 0;
							$date_cash1 = 0;
						}?>           
						<tr>
							<th colspan="8" style="text-align:center; color:#000; background-color:#CCC;">FINAL TOTAL</th>
						</tr><?php
					}
				?>
                <?php if($final_cash > 0 && $final_bank > 0){ ?>
                <tr>
                	<th colspan="6" style="text-align:right;">Total Cash Received</th>
                    <th style="text-align:right;"><?php echo number_format($final_cash)." Rs"; ?></th>
                    <th>&nbsp;</th>
                </tr>
                <tr>
                	<th colspan="6" style="text-align:right;">Total Cheque Received</th>
                    <th style="text-align:right;"><?php echo number_format($final_bank)." Rs"; ?></th>
                    <th>&nbsp;</th>
                </tr>
                <?php }?>
                <tr>
                	<th colspan="5" style="text-align:right;">Total Received Amount</th>
                    <th style="text-align:right;"><?php echo number_format($final_cash+$final_bank)." Rs"; ?></th>
                    <th style="text-align:right;"><?php echo number_format($final_cash1+$final_bank1)." Rs"; ?></th>
					 <th>&nbsp;</th>
					
                </tr>
                <tr>
					<th colspan="10" style="text-align:center; color:#000; background-color:#CCC;">Received By</th>
				</tr>
                <tr>
                	<td colspan="9" 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;">Total</th>
                            </tr>
                            <?php
                            	$SQL_RECEIVER = "
									SELECT
										SUM(receive_amt+latefee) AS receive_amt,
										um.user_id,
										um.user_name
									FROM
										cms_chequefeereceive frm,
										cms_usermaster um	 		
									WHERE
										um.user_id = frm.login_id AND
										frm.year_id = ".$_SESSION["VedantnrYearId"];
								$SQL_RECEIVER .= $condition;	
								$SQL_RECEIVER .= " GROUP BY frm.login_id ORDER BY frm.receipt_no ASC ";
								$RES_RECEIVER = dbQuery($SQL_RECEIVER);
								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+latefee) AS receive_amt
											FROM
												cms_chequefeereceive frm
											WHERE
												frm.cheque_no = '' AND	 
												frm.login_id = ".$REC_RECEIVER['user_id']." AND
												frm.year_id = ".$_SESSION["VedantnrYearId"];
										$SQL_CASH .= $condition;	
										$RES_CASH = dbQuery($SQL_CASH);
										$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+latefee) AS receive_amt
											FROM
												cms_chequefeereceive frm
											WHERE
												frm.cheque_no != '' AND	
												frm.year_id = ".$_SESSION["VedantnrYearId"]." AND  
												frm.login_id = ".$REC_RECEIVER['user_id'];
										$SQL_CASH .= $condition;	
										$RES_CASH = dbQuery($SQL_CASH);
										$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>
          <!--      <tr>
                    <td colspan="7" >
                    <table class="table-report-footer" cellpadding="0" cellspacing="0" width="100%">
                        <tr>
                            <td align="left" style="border:solid 0px red; padding:0px;" width="70%">Created by <b><?php echo $_SESSION["VedantnrUserName"]; ?></b> </td>
                            <td align="right" style="border:solid 0px red; padding:0px;" width="30%">Developed By <b>Aum Imagineering Pvt.Ltd.</b></td>
                        </tr>
                    </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";      
   	} 
?>
</div>
<?php require "_footer.php";
?>
