<?php require "../_header.php";?>
<div id="main-content1" align="center">
<center><h1><br/>Book Issue Register Report</h1></center>
  <?php
 if($_REQUEST['registerid']=="" && $_REQUEST['bookdate_from']=="" && $_REQUEST['bookdate_to']=="")
{
?>
  <script language="javascript" type="text/javascript">
		location.href='report-form-book-issue-register.php';
	</script>
  <?php
}
elseif($_SESSION['aCollegeId']!="" && isset($_SESSION['aCollegeId'])) 
{
		$header_row_string = "Book Issue Register Report";
		
		
		$register  = Escape($_REQUEST['registerid']);
		
		$date_from = Escape($_POST['bookdate_from']); print "<br/>";
	    $date_to   = Escape($_POST['bookdate_to']);
					
		if($register != ""){
		  	$condition .= " and lid.book_registerid = '$register'";
	    }
		                  
			if($date_from != "From"){
			$date_from=DateConversion(Escape($_POST['bookdate_from']),"Y-m-d","d/m/Y");
		    $condition .= " and issue_date >= '$date_from' ";
	     }
 	    if($date_to != "To"){
			$date_to=DateConversion(Escape($_POST['bookdate_to']),"Y-m-d","d/m/Y");
			$condition .= " and issue_date <= '$date_to' ";
	     }
		
		 $order_field="";	
	   	 $order_type="";
	   
	  	 $objIssueMgmt = new IssueMgmt();
	   	 $result = $objIssueMgmt -> getdistincDate("","",$condition,$order_field,$order_type);
	   		
			if(dbRows($result)>0) { 
			 ob_start();
			?>
    <table width="70%" cellspacing="0" cellpadding="0">
     <thead>
      <tr>
        <th align="center" width="15%" style="text-align:center">Book Reg.No</th>
        <th align="left" width="30%" style="text-align:left">Book Name</th>
        <th align="center" width="12%" style="text-align:center">Issue Date</th>
        <th align="center" width="13%" style="text-align:center">Member Id</th>
        <th align="left" width="30%" style="text-align:left">Member Name</th>
      </tr>
    </thead> <?php 
		 while($row = dbArray($result)) { 
		        
			 $t = $row['issue_date'];
				
				$condition ="";
				
				$condition = " and issue_date = '$t' and issue_isreturned='0'"; 			    				
				
				if($register != ""){
		 		 	$condition .= " and lid.book_registerid = '$register'";
			    }
				
				$qry = "SELECT lbm.book_registerno,
								lbm.book_name,
								DATE_FORMAT(issue_date,'$SQLDateFormat') As issuedate,
								lim.member_id,						
								CASE WHEN(lim.member_type='1') 
									 THEN (
										SELECT CONCAT(student_firstname,' ',student_lastname,' ',student_surname) 
										FROM sms_studentmaster 
										WHERE school_id ='".$_SESSION["aCollegeId"]."' AND student_id=lim.member_id)
										
									WHEN(lim.member_type='2') 
									THEN (
										SELECT employee_name 
										FROM sms_employeemaster 
										WHERE school_id ='".$_SESSION["aCollegeId"]."' AND employee_id=lim.member_id)
										
									WHEN(lim.member_type='3') 
									THEN (
										SELECT member_name 
										FROM lms_membermaster 
										WHERE school_id ='".$_SESSION["aCollegeId"]."' AND member_id=lim.member_id)
								END AS member_name
		          		from 
								lms_bookmaster lbm ,
								lms_issuedetail lid,
								lms_issuemaster lim
						
					  where lbm.school_id ='".$_SESSION["aCollegeId"]."' AND 
							lid.school_id ='".$_SESSION["aCollegeId"]."' AND 
							lim.school_id ='".$_SESSION["aCollegeId"]."' AND
							
							lid.issue_id = lim.issue_id AND 						
							lbm.book_registerid = lid.book_registerid AND  
							lbm.book_id = lid.book_id"; 
													
                $qry .= $condition;
				$qry .= "ORDER BY lim.member_id ASC" ; 
				   $result1=dbQuery($qry);
				  if(dbRows($result1)>0) {
					while($row1=dbArray($result1))
					  {
							 
						  extract($row1) ; ?>
						    <tr>
								  <td align="center" width="15%" style="text-align:center"><?php echo $book_registerno;?></td>
								  <td align="left" width="30%" style="text-align:left"><?php echo $book_name;?></td>
								  <td align="center" width="12%" style="text-align:center"><?php echo $issuedate;?></td>
								  <td align="center" width="13%" style="text-align:center"><?php echo $member_id;?></td>
								  <td align="left" width="30%" style="text-align:left"><?php echo $member_name;?></td>
						 </tr>
					    
				<?php  }
			  }
			 } ?>
  </table>
  <?php     
					  
	                $HtmlCode= ob_get_contents();
			        ob_end_flush();   
			     	$HtmlUrl 	=	"book-issue-register-report-". $_SESSION["aUserId"].".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="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=="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 "<b>No Data Found</b>";
			    }
  }else {
       echo "Session Expired"; 
      }
?>
</div>
<?php require "../_footer.php";?>
