<!DOCTYPE html>
<?php 
$flag=$_REQUEST['flag'];
if($flag=='')
{
#################################################### Display Letter Transfer Table ###############################################
include('dashboard_department.php');
require_once('convert_marathi.php');
$username = $_SESSION['User_Name'];
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script type="text/javascript">     
    function PrintDiv() {    
        var divToPrint = document.getElementById('divToPrint');
        var popupWin = window.open('', '_blank', 'width=600,height=600');
        popupWin.document.open();
        popupWin.document.write('<html><body onload="window.print()">' + divToPrint.innerHTML + '</html>');
        popupWin.document.close();
        }
 </script>
<script src="tableToExcel.js"></script>
</head>
<body>
<div class="mainwrapper">   
    <div class="rightpanel">
        <ul class="breadcrumbs">
            <li><a href=""><i class="iconfa-home"></i></a> <span class="separator"></span></li>
            <li><a href="">Tables</a> <span class="separator"></span></li>
            <li>पत्र फिर्तीनुसार रिपोर्ट्स </li>
        </ul>
        <div class="pageheader">
            <div class="pageicon"><span class="iconfa-table"></span></div>
            <div class="pagetitle">
                <h5>Tables</h5>
               <?php 
				$qryz=mysql_query("Select dept_id,dept_nm from department_master where dept_id=(select dept_id from login where login_id='$username')");
				$rsz=mysql_fetch_array($qryz);
				$deptid=$rsz['dept_id'];
				?>
                <h1><?php echo 	$rsz['dept_nm'];?> चे पत्र फिर्तीनुसार रिपोर्ट्स</h1>
            </div>
        </div><!--pageheader-->
        <div class="maincontent">
            <div class="maincontentinner">	
			    <h4 class="widgettitle"><?php echo 	$rsz['dept_nm'];?> पत्र फिर्तीनुसार रिपोर्ट्स </h4>
				<form method="post" action="">
					<div align="center"><br><table align="center" cellpadding="2" cellspacing="0" class='myClass'>
						<table>
							<tr>	  
								<td align="center"><label style="width:110px;">Start date</label></td>
								<td align="center"><input type="text" name="start_date" class="input-small"/></td>
								<td align="center"><label style="width:110px;">End Date</label></td>
								<td align="center"><input type="text" name="end_date" class="input-small"/></td>
							</tr>
							<tr>
								<td colspan="6">
								<div align="center">
									<input type="submit" onClick="return sadyasthitiDates()" name="ok" value="GO"/>
									<input type="reset" value="CLEAR" name="clear"/>
								</div>
								</td>
							</tr>
						</table>
					</div>
					<table id="dyntable" class="table table-bordered">
						<thead>
							<tr>
								<th class="head0 center">पोलीस अधिक्षक कार्यालय <br>आवक_क्रमांक<br>आवक_दिनांक</th>
								<th class="head1 center">संदर्भ क्र.<br> संदर्भ प्राप्त दिनांक</th> 
								<th class="head0 center">कोणाकडून प्राप्त झाला</th>
								<th class="head1 center">विषय </th> 
								<th class="head1 center">विभागीय आ क्र. <br>दि.</th>
								<th class="head1 center">डेस्क आ क्र. <br>दि.</th>
								<th class="head1 center">केलेली_कार्यवाही </th>
								<th class="head1 center">पत्राची स्थिती </th>
							</tr>
						</thead>
						<?php
						convert_marathi();
						$date123	= $_POST['start_date'];
						$date1	= date('Y-m-d',strtotime($date123));
						$date223	= $_POST['end_date'];
						$date2	= date('Y-m-d',strtotime($date223));
						//$date22	= date('d-m-Y',strtotime($date2));
						if($date123==''&& $date223=='')
						{
							echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
							$id1 = $date1;
							$id2= $date2;
							$result222=mysql_query("SELECT d.desk_ltr_id, d.desk_id_from, d.action_taken, d.desk_ltr_rec_dt, d.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, d. update_date, d.dispatched_dt, d.ltr_approval, di.addressed_to, d.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, d.scan_doc, di.outword_no, di.dispatched_to, d.ltr_category, d.assign_no 
							FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
							LEFT OUTER JOIN desk_transaction d ON d.dpt_ltr_id = t.dpt_ltr_id 
							LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = d.desk_ltr_id
							where t.dept_id_from=(select dept_id from login where login_id='$username') 
							AND d.ltr_approval='transferred' ") or die("".mysql_error());
						}
						else{
							echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
							$id1 = $date1;
							$id2= $date2;
							$result222=mysql_query("SELECT d.desk_ltr_id, d.desk_id_from, d.action_taken, d.desk_ltr_rec_dt, d.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, d. update_date, d.dispatched_dt, d.ltr_approval, di.addressed_to, d.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, d.scan_doc, di.outword_no, di.dispatched_to, d.ltr_category, d.assign_no 
							FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
							LEFT OUTER JOIN desk_transaction d ON d.dpt_ltr_id = t.dpt_ltr_id 
							LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = d.desk_ltr_id
							where t.dept_id_from=(select dept_id from login where login_id='$username') 
							AND d.ltr_approval='transferred' AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("".mysql_error());
						}
						$count=mysql_num_rows($result222);
						while($rws = mysql_fetch_array($result222))
						{
							$dsrecdt = strtotime($rws['desk_ltr_rec_dt']);
							$dsrecdt1= date('d-m-Y', $dsrecdt);
							$dprecdt = strtotime($rws['dpt_ltr_rec_dt']);
							$dprecdt1= date('d-m-Y', $dprecdt);
							$refdt = strtotime($rws['ref_dt']);
							$refdt1= date('d-m-Y', $refdt);
							$recdt = strtotime($rws['receive_dt']);
							$recdt1= date('d-m-Y', $recdt);
							?>
							<tr class="gradeX">	
							<?php 
							if($rws['desk_id']==0)
							{
								$dsk="डेस्क लावणे बाकी";
							}
							else
							{
								$q=mysql_query("select desk_nm from desk_master where desk_id='$rws[desk_id]'");
								$qj=mysql_fetch_array($q);
								$dsk=$qj['desk_nm'];
							}
							
							echo "<td class=center>".$rws['ltr_inword_no']."<br>".$recdt1." </td>
									<td class=center>".$rws['ref_no']."<br>".$refdt1."</td>
									<td class=center id=wrapping>".$rws['sender_name']."</td><td class=center id=wrapping>".$rws['subject']."</td>
									<td class=center>".$rws['dpt_inword_no']."<br>".$dprecdt1." </td>
									<td class='center'>".$rws['desk_ltr_inword_no']."<br>".$dsrecdt1."<br>".$dsk." </td>
									";
							echo "<td class=center>".$rws['action_taken']."</td>";	
							
							if($rws['ltr_approval']=='transferred')
								{
									echo "<td class=center><a href='report_dpt_ltr_transfer_op.php?ltrid=$rws[ltr_id]&user=dept'>".$rws['ltr_approval']."</a></td>";
								}
							else if($rws['ltr_approval']=='Approve')
								{
									echo "<td class=center>".$rws['ltr_approval']."</td>";
								}
                            echo" </select></tr>";
						}
						//mysql_close();
						echo"   </tbody>
						</table>";
						
						echo "<div id='divToPrint' style='display:none;'>
						<center><table id='export' border='1px' style='margin-left:50px;'>
						<tr><td colspan='8'><center>".$rsz['dept_nm']. " चे पत्र फिर्तीनुसार रिपोर्ट्स  <br>दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
						
						echo ' <center><h2>पोलीस अधिक्षक कार्यालय, <br> जि.रायगड <h2></center>';	
							
						echo "<tr>
								<th>पोलीस अधिक्षक कार्यालय <br>आवक_क्रमांक<br>आवक_दिनांक</th>
								<th>संदर्भ क्र.<br> संदर्भ प्राप्त दिनांक</th>  
								<th>कोणाकडून प्राप्त झाला</th>
								<th>विषय </th>
								<th>विभागीय आ क्र. <br>दि.</th>
								<th>डेस्क आ क्र. <br>दि.</th>
								<th>केलेली_कार्यवाही </th> 
								<th>पत्राची स्थिती </th>
							</tr>";
						convert_marathi();
						if($date123==''&& $date223=='')
						{
							$id1 = $date1;
							$id2= $date2;
							$result222=mysql_query("SELECT d.desk_ltr_id, d.desk_id_from, d.action_taken, d.desk_ltr_rec_dt, d.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, d. update_date, d.dispatched_dt, d.ltr_approval, di.addressed_to, d.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, d.scan_doc, di.outword_no, di.dispatched_to, d.ltr_category, d.assign_no 
							FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
							LEFT OUTER JOIN desk_transaction d ON d.dpt_ltr_id = t.dpt_ltr_id 
							LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = d.desk_ltr_id
							where t.dept_id_from=(select dept_id from login where login_id='$username') 
							AND d.ltr_approval='transferred' ") or die("".mysql_error());
						}
						else{
							$id1 = $date1;
							$id2= $date2;
							$result222=mysql_query("SELECT d.desk_ltr_id, d.desk_id_from, d.action_taken, d.desk_ltr_rec_dt, d.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, d. update_date, d.dispatched_dt, d.ltr_approval, di.addressed_to, d.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, d.scan_doc, di.outword_no, di.dispatched_to, d.ltr_category, d.assign_no 
							FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
							LEFT OUTER JOIN desk_transaction d ON d.dpt_ltr_id = t.dpt_ltr_id 
							LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = d.desk_ltr_id
							where t.dept_id_from=(select dept_id from login where login_id='$username') 
							AND d.ltr_approval='transferred' AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("".mysql_error());
						}
						while($rws = mysql_fetch_array($result222))
						{
							$dsrecdt = strtotime($rws['desk_ltr_rec_dt']);
							$dsrecdt1= date('d-m-Y', $dsrecdt);
							$dprecdt = strtotime($rws['dpt_ltr_rec_dt']);
							$dprecdt1= date('d-m-Y', $dprecdt);
							$refdt = strtotime($rws['ref_dt']);
							$refdt1= date('d-m-Y', $refdt);
							$recdt = strtotime($rws['receive_dt']);
							$recdt1= date('d-m-Y', $recdt);
							
							if($rws['desk_id']==0)
								{
									$dsk="डेस्क लावणे बाकी ";
								}
							else
								{
									$q=mysql_query("select desk_nm from desk_master where desk_id='$rws[desk_id]'");
									$qj=mysql_fetch_array($q);
									$dsk=$qj['desk_nm'];
								}
							echo "<tr>";
							echo "<td>".$rws['ltr_inword_no']."<br>".$recdt1." </td>
								<td>".$rws['ref_no']."<br>".$refdt1."</td>
								<td>".$rws['sender_name']."</td><td>".$rws['subject']."</td>
								<td>".$rws['dpt_inword_no']."<br>".$dprecdt1." </td>
								<td>".$rws['desk_ltr_inword_no']."<br>".$dsrecdt1."<br>".$dsk." </td>
								<td class=center>".$rws['action_taken']."</td>
							";	
							if($rws['ltr_approval']=='transferred')
							{
								echo "<td>".$rws['ltr_approval']."</td>";
							}
							else if($rws['ltr_approval']=='Approve')
							{
								echo "<td>".$rws['ltr_approval']."</td>";
							}
							
							
							
					  echo"</tr>";
						}
						//mysql_close();
						echo "</table></center></div>";
						?><br>
						<p>	
							<center><input type="submit" value=" Print Page " onclick="PrintDiv();" class="btn btn-primary"/>
							<input type="button" class="btn" onclick="tableToExcel('dyntable', 'W3C Example Table')" value="Export to Excel"></center>
						</p>
				</form>
                <br /><br />
				<?php include_once('footer.php'); ?>
            </div><!--maincontentinner-->
        </div><!--maincontent-->
    </div><!--rightpanel-->
</div><!--mainwrapper-->
</body>
</html>
<?php
} // if($flag=='')

//////////////////////////////////////////////////////////////////////////////////////////////////////

else if($flag=='n')
{
#################################################### Display Letter Transfer Table ###############################################
include('new_dashboard_department.php');
require_once('convert_marathi.php');
$username = $_SESSION['User_Name'];
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script type="text/javascript">     
    function PrintDiv() {    
        var divToPrint = document.getElementById('divToPrint');
        var popupWin = window.open('', '_blank', 'width=600,height=600');
        popupWin.document.open();
        popupWin.document.write('<html><body onload="window.print()">' + divToPrint.innerHTML + '</html>');
        popupWin.document.close();
        }
 </script>
<script src="tableToExcel.js"></script>
</head>
<body>
<div class="mainwrapper">   
    <div class="rightpanel">
        <ul class="breadcrumbs">
            <li><a href=""><i class="iconfa-home"></i></a> <span class="separator"></span></li>
            <li><a href="">Tables</a> <span class="separator"></span></li>
            <li>पत्र फिर्तीनुसार रिपोर्ट्स </li>
        </ul>
        <div class="pageheader">
            <div class="pageicon"><span class="iconfa-table"></span></div>
            <div class="pagetitle">
                <h5>Tables</h5>
               <?php 
				$qryz=mysql_query("Select dept_nm from department_master where dept_id=(select dept_id from login where login_id='$username')");
				$rsz=mysql_fetch_array($qryz);
				?>
                <h1><?php echo 	$rsz['dept_nm'];?> चे पत्र फिर्तीनुसार रिपोर्ट्स</h1>
            </div>
        </div><!--pageheader-->
        <div class="maincontent">
            <div class="maincontentinner">	
			    <h4 class="widgettitle"><?php echo 	$rsz['dept_nm'];?> पत्र फिर्तीनुसार रिपोर्ट्स </h4>
				<form method="post" action="">
					<div align="center"><br><table align="center" cellpadding="2" cellspacing="0" class='myClass'>
						<table>
							<tr>	  
								<td align="center"><label style="width:110px;">Start date</label></td>
								<td align="center"><input type="text" name="start_date" class="input-small"/></td>
								<td align="center"><label style="width:110px;">End Date</label></td>
								<td align="center"><input type="text" name="end_date" class="input-small"/></td>
							</tr>
							<tr>
								<td colspan="6">
								<div align="center">
									<input type="submit" onClick="return sadyasthitiDates()" name="ok" value="GO"/>
									<input type="reset" value="CLEAR" name="clear"/>
								</div>
								</td>
							</tr>
						</table>
					</div>
					<table id="dyntable" class="table table-bordered">
						<thead>
							<tr>
								<th class="head0 center">पोलीस अधिक्षक कार्यालय <br>आवक_क्रमांक<br>आवक_दिनांक</th>
								<th class="head1 center">संदर्भ क्र.<br> संदर्भ प्राप्त दिनांक</th>                          
								<th class="head0 center">कोणाकडून प्राप्त झाला</th>
								<th class="head1 center">विषय </th> 
								<th class="head1 center">विभागीय आ क्र. <br>दि.</th>
								<th class="head1 center">केलेली_कार्यवाही </th>
								<th class="head0 center">पत्राची स्थिती </th>
							</tr>
						</thead>
						<?php
						convert_marathi();
						$date123	= $_POST['start_date'];
						$date1	= date('Y-m-d',strtotime($date123));
						$date223	= $_POST['end_date'];
						$date2	= date('Y-m-d',strtotime($date223));
						//$date22	= date('d-m-Y',strtotime($date2));
						if($date123==''&& $date223=='')
						{
							echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
							$id1 = $date1;
							$id2= $date2;
							/*$result222=mysql_query("SELECT * FROM incoming_letters_transaction, tapal_to_dpt_transaction,desk_transaction where tapal_to_dpt_transaction.dept_id_from=(select dept_id from login where login_id='$username') AND tapal_to_dpt_transaction.ltr_id=incoming_letters_transaction.ltr_id AND desk_transaction.dpt_ltr_id=tapal_to_dpt_transaction.dpt_ltr_id") or die("".mysql_error());*/
							$result222=mysql_query("SELECT t.action_taken, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, t.update_date, t.dispatched_date, t.status, di.addressed_to, t.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no 
							FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
							LEFT OUTER JOIN dispatched_transaction di ON ( di.ltr_id = t.ltr_id AND di.desk_ltr_id='0')
							where t.dept_id_from=(select dept_id from login where login_id='$username') 
							AND t.status='transferred' ") or die("12sds".mysql_error());
						}
						else{
							echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
							$id1 = $date1;
							$id2= $date2;
							$result222=mysql_query("SELECT t.action_taken, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, t.update_date, t.dispatched_date, t.status, di.addressed_to, t.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no 
							FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
							LEFT OUTER JOIN dispatched_transaction di ON ( di.ltr_id = t.ltr_id AND di.desk_ltr_id='0')
							where t.dept_id_from=(select dept_id from login where login_id='$username') 
							AND t.status='transferred'  AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("".mysql_error());
						}
						$count=mysql_num_rows($result222);
						while($rws = mysql_fetch_array($result222))
						{
							$dsrecdt1= date('d-m-Y', $dsrecdt);
							$dprecdt = strtotime($rws['dpt_ltr_rec_dt']);
							$dprecdt1= date('d-m-Y', $dprecdt);
							$refdt = strtotime($rws['ref_dt']);
							$refdt1= date('d-m-Y', $refdt);
							$recdt = strtotime($rws['receive_dt']);
							$recdt1= date('d-m-Y', $recdt);
							?>
							<tr class="gradeX">	
							<?php 
							
							echo "<td class=center>".$rws['ltr_inword_no']."<br>".$recdt1." </td>
							<td class=center>".$rws['ref_no']."<br>".$refdt1."</td>
							<td class=center id=wrapping>".$rws['sender_name']."</td><td class=center id=wrapping>".$rws['subject']."</td>";
							echo "<td class=center>".$rws['dpt_inword_no']."<br>".$dprecdt1." </td>";
							echo "<td class=center>".$rws['action_taken']."</td>";
							
							if($rws['status']=='transferred')
							{
								echo "<td class=center><a href='report_dpt_ltr_transfer_op.php?flag=n&ltrid=$rws[ltr_id]&user=dept'>".$rws['status']."</a></td>";
							}
							else if($rws['status']=='approve')
							{
								echo "<td class=center>".$rws['status']."</td>";
							}
                            echo" </select></tr>";
						}
						//mysql_close();
						echo"   </tbody>
						</table>";
						
						echo "<div id='divToPrint' style='display:none;'>
						<center><table id='export' border='1px' style='margin-left:50px;'>
							<tr><td colspan='9'><center>". $rsz['dept_nm'] ." पत्र फिर्तीनुसार रिपोर्ट्स <br>दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
						echo ' <center><h2>पोलीस अधिक्षक कार्यालय, <br> जि.रायगड <h2></center>';
							echo "<tr>
								<th>पोलीस अधिक्षक कार्यालय <br>आवक_क्रमांक<br>आवक_दिनांक</th>
								<th>संदर्भ क्र.<br> संदर्भ प्राप्त दिनांक</th>                          
								<th>कोणाकडून प्राप्त झाला</th>
								<th>विषय </th>  
								<th>विभागीय आ क्र. <br>दि.</th>
								<th>केलेली_कार्यवाही </th>
								<th>पत्राची स्थिती </th>
							</tr>";
						convert_marathi();
						if($date123==''&& $date223=='')
						{
							$result222=mysql_query("SELECT t.action_taken, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, t.update_date, t.dispatched_date, t.status, di.addressed_to, t.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no 
							FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
							LEFT OUTER JOIN dispatched_transaction di ON ( di.ltr_id = t.ltr_id AND di.desk_ltr_id='0')
							where t.dept_id_from=(select dept_id from login where login_id='$username') 
							AND t.status='transferred' ") or die("".mysql_error());
						}
						else
						{
							$result222=mysql_query("SELECT t.action_taken, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, t.update_date, t.dispatched_date, t.status, di.addressed_to, t.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no 
							FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
							LEFT OUTER JOIN dispatched_transaction di ON ( di.ltr_id = t.ltr_id AND di.desk_ltr_id='0')
							where t.dept_id_from=(select dept_id from login where login_id='$username') 
							AND t.status='transferred'  AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("".mysql_error());
						}
						$count=mysql_num_rows($result222);
						while($rws = mysql_fetch_array($result222))
						{
							$dsrecdt1= date('d-m-Y', $dsrecdt);
							$dprecdt = strtotime($rws['dpt_ltr_rec_dt']);
							$dprecdt1= date('d-m-Y', $dprecdt);
							$refdt = strtotime($rws['ref_dt']);
							$refdt1= date('d-m-Y', $refdt);
							$recdt = strtotime($rws['receive_dt']);
							$recdt1= date('d-m-Y', $recdt);
							
							echo "<tr><td>".$rws['ltr_inword_no']."<br>".$recdt1." </td>
							<td>".$rws['ref_no']."<br>".$refdt1."</td>
							<td>".$rws['sender_name']."</td><td>".$rws['subject']."</td>";
							echo "<td>".$rws['dpt_inword_no']."<br>".$dprecdt1." </td>";
							echo "<td class=center>".$rws['action_taken']."</td>";	
							
							if($rws['status']=='transferred')
								{
									echo "<td>".$rws['status']."</td>";
								}
							else if($rws['status']=='approve')
								{
									echo "<td>".$rws['status']."</td>";
								}
                            echo"</tr>";
						}
						//mysql_close();
						echo "</table></center></div>";
						?><br>
						<p>	
							<center><input type="submit" value=" Print Page " onclick="PrintDiv();" class="btn btn-primary"/>
							<input type="button" class="btn" onclick="tableToExcel('dyntable', 'W3C Example Table')" value="Export to Excel"></center>
						</p>
				</form>
                <br /><br />
				<?php include_once('footer.php'); ?>
            </div><!--maincontentinner-->
        </div><!--maincontent-->
    </div><!--rightpanel-->
</div><!--mainwrapper-->
</body>
</html>
<?php
} // else if($flag=='n')
?>