<?php
 require_once('convert_marathi.php');
$user=$_GET['user'];
$no=$_GET['no'];
$username = $_SESSION['User_Name'];
$flag=$_REQUEST['flag'];
########################################################### if user is tapal ################################################  
if($user==2)
{

include_once('dashboard_tapal.php');
$deptid=$_GET['deptid'];
$name=mysql_query("Select dept_nm from department_master where dept_id='$deptid'");
$deptnm=mysql_fetch_array($name);
?>

<!DOCTYPE html>
<html>
<head>
<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>
<script type="text/javascript" src="js/adduser.js"></script> 
</head>

    <div class="rightpanel">
        
        <ul class="breadcrumbs">
            <li><a href="dashboard_tapal.php"><i class="iconfa-home"></i></a> <span class="separator"></span></li>
            <li><a href="dashboard_tapal.php">Tables</a> <span class="separator"></span></li>
            <li>Table Dynamic</li>
        </ul>
        
        <div class="pageheader">
           
            <div class="pageicon"><span class="iconfa-table"></span></div>
            <div class="pagetitle">
                <h5>Tables</h5>
                <h1>Welcome <?php echo $username?> User</h1>
            </div>
        </div><!--pageheader-->
<?php }  

################################################# if user is bdo ################################################    
if($user==1)
{
include_once('dashboard_bdo.php');
$deptid=$_GET['deptid'];
$name=mysql_query("Select dept_nm from department_master where dept_id='$deptid'");
$deptnm=mysql_fetch_array($name);
?>

<!DOCTYPE html>
<html>
<head>
<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>
<script type="text/javascript" src="js/adduser.js"></script> 
</head>

    <div class="rightpanel">
        
        <ul class="breadcrumbs">
            <li><a href="dashboard_bdo.php"><i class="iconfa-home"></i></a> <span class="separator"></span></li>
            <li><a href="dashboard_bdo.php">Tables</a> <span class="separator"></span></li>
            <li>Table Dynamic</li>
        </ul>
        
        <div class="pageheader">
           
            <div class="pageicon"><span class="iconfa-table"></span></div>
            <div class="pagetitle">
                <h5>Tables</h5>
                <h1>Welcome <?php echo $username?> User</h1>
            </div>
        </div><!--pageheader-->
<?php } ?>     
        <div class="maincontent">
            <div class="maincontentinner">
				
				<?php 
				
				if ($no==1)
				{	
				?>			
						<h4 class="widgettitle"><?php echo $deptnm['dept_nm'];?> चे अस्वीकृत पत्राचे रिपोर्ट्स <h4>
						<form name="sadyasthiti" action="" method="post">
						<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="4">
								<div align="center">
									<input type="submit" onClick="return sadyasthitiDate()" name="ok" value="GO"/>
									<input type="reset" value="CLEAR" name="clear"/>
								</div>
								</td>
							</tr>
						</table>
					</div>
				</form>
				<form>
						

						<?php
						$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));
						echo '<br><br><center>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center><br>';$id = $date1;
						$id1= $date2;

							#########################		Pending report tapal user     #######################
						if($date123==''&& $date223=='')
							{	
								$qry1=mysql_query("Select * FROM  incoming_letters_transaction i, login l
								WHERE i.dept_id!='0' 
								AND (i.status='pending')
								AND l.login_id='$username' 
								AND i.dept_id='$deptid' ") OR die("aaaa".mysql_error());
								$cnt=mysql_num_rows($qry1);
								//echo "aaaaaaaaa".$cnt;
							}
						else
							{
								$qry1=mysql_query("Select * FROM  incoming_letters_transaction i, login l 
								WHERE i.dept_id!='0' 
								AND (i.status='pending') 
								AND l.login_id='$username' 
								AND i.dept_id='$deptid'
								AND (i.receive_dt BETWEEN '$date1' AND '$date2')") OR die("aaaa".mysql_error());
							}
							echo	"<table id='dyntable' class='table table-bordered'>
									<thead>
									<tr>
										<th class='head1 center'>पोलीस अधिक्षक <br> कार्यालयपोलीस अधिक्षक <br> कार्यालय<br> आवक क्रमांक <br>आवक दिनांक</th>
										<th class='head0 center'>विभागीय आवक क्रमांक <br>दिनांक</th>
										<th class='head1 center'>संदर्भ क्र. <br>संदर्भ दि. </th>
										<th class='head0 center'>संदर्भाचा प्रकार</th>
										<th class='head1 center'>विषय</th>
										<th class='head0 center'>कोणाकडून <br>प्राप्त झाला</th>
										<th class='head1 center'> केलेली <br>कार्यवाही </th>
									</tr></thead><tbody>";
						
							
						while($test = mysql_fetch_array($qry1))
						{
								$desk_ltr_rec_dt = date('d-m-Y',strtotime($test['desk_ltr_rec_dt']));
								$dept_rec_date 	= date('d-m-Y',strtotime($test['sent_dt']));
								if($test['status']=='pending')
								{
									$avno='स्वीकारणे बाकी ';
								}
								else
								{
									$avno=$test['dpt_inword_no'];
								}
								
								if($test['action_taken']=='')
								{
									$action="कार्यवाही केलेली नाही ";
								}
								else
								{
									$action=$test['action_taken'];
								}
								
								$receive_dt	= date('d-m-Y',strtotime($test['receive_dt']));
								$refdt	= date('d-m-Y',strtotime($test['ref_dt']));
								$m=$test['ltr_type'];
			
							echo "
							<tr class='gradeX'>
							<td class='center'>".$test['ltr_inword_no']."<br>".$receive_dt."</td>
							<td class='center'><font color='red'>".$avno."<br></font></td>
							<td class='center'>".$test['ref_no']."<br>".$refdt."</td>";
							
							$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
							$s=mysql_fetch_array($ltrtype);
							echo "<td class='center'>".$s['sandharbh_nm']."</td>
							<td class='center'>".$test['subject']."</td>
							<td class='center'>".$test['sender_name']."</td>
							<td class='center'><font color='red'>".$action."</font></td>
							</tr>";
						}
						echo "</tbody></table>";
			
						################################ print table ##################################
						echo "<div id='divToPrint' style='display:none;'>
							<center><table id='export' border='1px' >
							<tr><td colspan='7'><center>".$deptnm['dept_nm']." चे अस्वीकृत पत्राचे रिपोर्ट्स <br> दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
							
							echo ' <center><h2>पोलीस अधिक्षक कार्यालय, <br> जि.रायगड <h2></center>'; 
							#########################		Pending report tapal user     ##################
							
							$qry1=mysql_query("Select * FROM  incoming_letters_transaction, login WHERE incoming_letters_transaction.dept_id!='0' AND (incoming_letters_transaction.status='pending') AND login.login_id='$username' AND incoming_letters_transaction.dept_id='$deptid'") OR die("aaaa".mysql_error());
							$cnt=mysql_num_rows($qry1);
							//echo "aaaaaaaaa".$cnt;
							echo	"<tr>
										<th>पोलीस अधिक्षक <br> कार्यालय<br> आवक_क्रमांक <br>आवक_दिनांक</th>
										<th>विभागीय आवक_क्रमांक <br>आवक_दिनांक</th>
										<th>संदर्भ_क्रमांक <br>संदर्भ_दिनांक </th>
										<th>संदर्भाचा प्रकार</th>
										<th>विषय</th>
										<th>कोणाकडून <br>प्राप्त_झाला</th>
										<th>केलेली <br>कार्यवाही </th>
									</tr>";
							while($test = mysql_fetch_array($qry1))
							{
								$desk_ltr_rec_dt = date('d-m-Y',strtotime($test['desk_ltr_rec_dt']));
								$dept_rec_date 	= date('d-m-Y',strtotime($test['sent_dt']));
								if($test['status']=='pending')
								{
									$avno='स्वीकारणे बाकी ';
								}
								else
								{
									$avno=$test['dpt_inword_no'];
								}
								
								if($test['action_taken']=='')
								{
									$action="कार्यवाही केलेली नाही ";
								}
								else
								{
									$action=$test['action_taken'];
								}
								$receive_dt	= date('d-m-Y',strtotime($test['receive_dt']));
								$refdt	= date('d-m-Y',strtotime($test['ref_dt']));
								$m=$test['ltr_type'];
			
								echo "<tr>
								<td style='text-align:center;'>".$test['ltr_inword_no']."<br>".$receive_dt."</td>
								<td style='text-align:center;'>".$avno."</td>
								<td style='text-align:center;'>".$test['ref_no']."<br>".$refdt."</td>";
								$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
								$s=mysql_fetch_array($ltrtype);
								echo "<td style='text-align:center;'>".$s['sandharbh_nm']."</td>
								<td style='text-align:center;'>".$test['subject']."</td>
								<td style='text-align:center;'>".$test['sender_name']."</td>
								<td style='text-align:center;'>".$action."</td>
								</tr>";
							}
						echo"</table></center></div>";
				}//if no=1
				#########################	End Of Pending report tapal user     #############################
				
				#########################	Accepted Letter report tapal user     #############################
				else if($no==2)
				{
					if($flag=='')
						{
						?>	
			
					<h4 class="widgettitle"><?php echo $deptnm['dept_nm'];?> चे स्वीकृत पत्राचे रिपोर्ट्स <h4>
					<form method='post'>
						<form name="sadyasthiti" action="" method="post">
						<div align="center"><br><table align="center" cellpadding="2" cellspacing="0" class='myClass'>
						<table>
							<tr>
								<td><label>तारखेचा प्रकार निवडा  : </label></td>
								<td><span class="field unicode" lang="mr">
										<select name="datetype">
											<option value="">तारखेचा प्रकार निवडा</option>  
											<option value="1">आवक दिनांक</option>
											<option value="2">विभागीय आवक दिनांक</option>
											<option value="3">डेस्क आवक दिनांक</option>
										</select>
									</span>
								</td>
									  
								<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="4">
								<div align="center">
									<input type="submit" onClick="return sadyasthitiDate()" name="ok" value="GO"/>
									<input type="reset" value="CLEAR" name="clear"/>
								</div>
								</td>
							</tr>
						</table>
					</div>
				</form>
				<form action="" method="post">

						<?php
						$dt_type=$_POST['datetype'];
						//echo "date".$dt_type;
						$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=='' && $dt_type=='')
						{	
							echo '<br><br><center>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center><br>';$id = $date1;
							$id1= $date2;
								
								//accpeted by dept but deskid=0 or desk_apprval=pending
								$qry1=mysql_query("SELECT DISTINCT i.ltr_type, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt,t.returned_choice, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, 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.sent_to_desk_dt
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								WHERE t.dept_id_from='$deptid' 
								AND (t.desk_id='0' OR t.desk_approval='pending')") OR die("aabbhhaa".mysql_error());
								
								//accpeted by desk and ltrstatus!=closed
								$qry2=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id,t.returned_choice, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND de.ltr_status!='closed'
								AND de.ltr_approval!='transferred_todesk' ") OR die("aabbhhaa".mysql_error());
								
							}
							else if($date123!=''&& $date223!='' && $dt_type==1)
							{
								echo '<br><center><h4> <font color="red">आवक दिनांकनुसार संदर्भ </font></h4></center><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								
								$qry1=mysql_query("SELECT DISTINCT i.ltr_type, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt,t.returned_choice, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, 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.sent_to_desk_dt
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND (t.desk_id='0' OR t.desk_approval='pending') AND (i.receive_dt BETWEEN '$date1' AND '$date2')");
								
								$qry2=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id,t.returned_choice, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND de.ltr_status!='closed' AND de.ltr_approval!='transferred_todesk' AND (i.receive_dt BETWEEN '$date1' AND '$date2') ") OR die("aabbhhaa".mysql_error());
							}
							else if($date123!=''&& $date223!='' && $dt_type==2)
							{
								echo '<br><center><h4> <font color="red">आवक दिनांकनुसार संदर्भ </font></h4></center><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								
								$qry1=mysql_query("SELECT DISTINCT i.ltr_type, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt,t.returned_choice, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, 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.sent_to_desk_dt
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND (t.desk_id='0' OR t.desk_approval='pending') AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')");
								
								$qry2=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id,t.returned_choice, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND de.ltr_status!='closed' AND de.ltr_approval!='transferred_todesk' AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aabbhhaa".mysql_error());
							}
							else if($date123!=''&& $date223!='' && $dt_type==3)
							{
								echo '<br><center><h4> <font color="red">आवक दिनांकनुसार संदर्भ </font></h4></center><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								
								$qry1=mysql_query("SELECT DISTINCT i.ltr_type, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt,t.returned_choice, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, 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.sent_to_desk_dt
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND (t.desk_id='0' OR t.desk_approval='pending') AND (de.desk_ltr_rec_dt BETWEEN '$date1' AND '$date2')");
								
								$qry2=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id,t.returned_choice, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND de.ltr_status!='closed' AND de.ltr_approval!='transferred_todesk' AND (de.desk_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aabbhhaa".mysql_error());
							}
							
							//$cnt=mysql_num_rows($qry1);
							echo"  <br><br><table id='dyntable' class='table table-bordered'><thead>
									<tr>
									<th class='head1 center'>पोलीस अधिक्षक <br> कार्यालय <br> आवक क्रमांक <br>आवक_दिनांक</th>
									<th class='head0 center'>विभागीय आवक क्र.<br>आवक_दिनांक</th>
									<th class='head1 center'>डेस्कचा आवक क्र. <br>आवक_दिनांक</th>
									<th class='head0 center'>संदर्भ_क्रमांक <br>संदर्भ दि. </th>
									<th class='head1 center'>संदर्भाचा प्रकार</th>
									<th class='head0 center'>विषय</th>
									<th class='head1 center'>कोणाकडून <br>प्राप्त_झाला</th>
									<th class='head1 center'>केलेली <br>कार्यवाही </th>";
									
									 echo "</tr> </thead><tbody>";
									while($test = mysql_fetch_array($qry1))
									{
										$desk_ltr_rec_dt = date('d-m-Y',strtotime($test['desk_ltr_rec_dt']));
										$dept_rec_date 	= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
										$receive_dt	= date('d-m-Y',strtotime($test['receive_dt']));
										$refdt	= date('d-m-Y',strtotime($test['ref_dt']));
										$deskrec_dt	= date('d-m-Y',strtotime($test['sent_to_desk_dt']));
										$m=$test['ltr_type'];
										
										$dsk1=$test['desk_id_from'];
										convert_marathi();
										$qsk1=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk1'") or die("".mysql_error());
										$desk1=mysql_fetch_array($qsk1);
										
										$dsk2=$test['desk_id'];
										convert_marathi();
										$qsk2=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk2'") or die("".mysql_error());
										$desk2=mysql_fetch_array($qsk2);
										echo "
										<tr class='gradeX'>
										<td class='center'>".$test['ltr_inword_no']."<br>".$receive_dt."</td>
										<td class='center'>".$test['dpt_inword_no']."<br>".$dept_rec_date ."</td>";
										
										if($test['returned_choice']!='')
										{
											echo "<td class='center'>Letter Returned To <br> Tapal</td>";
										}
										else if($test['desk_id']=='' || $test['desk_id']=='0')
										{
											echo "<td class='center'><font color='red'>"."डेस्क लावणे बाकी  "."</font></td>";
										}
										else if($test['desk_ltr_inword_no']=='' || $test['desk_ltr_inword_no']=='0')
										{
											echo "<td class='center'><font color='red'>".$desk2['desk_nm']."<br>"."डेस्कने स्वीकारणे बाकी "."</font></td>";
										}
										else  if($test['desk_ltr_inword_no']!='0' || $test['desk_ltr_inword_no']!='')
										{
											echo "<td class='center'>".$desk1['desk_nm']."<br>".$test['desk_ltr_inword_no']."<br>".$deskrec_dt."</td>";
										}
										echo "<td class='center'>".$test['ref_no']."<br>".$refdt."</td>";
										$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
										$s=mysql_fetch_array($ltrtype);
										echo "<td class='center'>".$s['sandharbh_nm']."</td>
										<td class='center'>".$test['subject']."</td>
										<td class='center'>".$test['sender_name']."</td>";
										
										if($test['returned_choice']!='')
										{
											echo "<td class='center'>Letter Returned To <br> Tapal</td>";
										}
										else if($test['action_taken']=='')
										{
											echo "<td class='center'><font color='red'>कार्यवाही केलेली नाही  </font></td>";
										}
										else if($test['ltr_status']=='')
										{
											echo "<td class='center'><font color='red'>कार्यवाही केलेली नाही  </font></td>";
										}
										else
										{
											echo "<td class='center'>".$test['action_taken']."</td>";
										}
										echo "</tr>";
									}
									while($test = mysql_fetch_array($qry2))
									{
										$desk_ltr_rec_dt = date('d-m-Y',strtotime($test['desk_ltr_rec_dt']));
										$dept_rec_date 	= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
										$receive_dt	= date('d-m-Y',strtotime($test['receive_dt']));
										$refdt	= date('d-m-Y',strtotime($test['ref_dt']));
										$deskrec_dt	= date('d-m-Y',strtotime($test['sent_to_desk_dt']));
										$m=$test['ltr_type'];
										
										$dsk1=$test['desk_id_from'];
										convert_marathi();
										$qsk1=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk1'") or die("".mysql_error());
										$desk1=mysql_fetch_array($qsk1);
										
										$dsk2=$test['desk_id'];
										convert_marathi();
										$qsk2=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk2'") or die("".mysql_error());
										$desk2=mysql_fetch_array($qsk2);
										echo "
										<tr class='gradeX'>
										<td class='center'>".$test['ltr_inword_no']."<br>".$receive_dt."</td>
										<td class='center'>".$test['dpt_inword_no']."<br>".$dept_rec_date ."</td>";
										if($test['desk_id']=='' || $test['desk_id']=='0')
										{
											echo "<td class='center'><font color='red'>"."डेस्क लावणे बाकी  "."</font></td>";
										}
										else if($test['desk_ltr_inword_no']=='' || $test['desk_ltr_inword_no']=='0')
										{
											echo "<td class='center'><font color='red'>".$desk2['desk_nm']."<br>"."डेस्कने स्वीकारणे बाकी "."</font></td>";
										}
										else  if($test['desk_ltr_inword_no']!='0' || $test['desk_ltr_inword_no']!='')
										{
											echo "<td class='center'>".$desk1['desk_nm']."<br>".$test['desk_ltr_inword_no']."<br>".$deskrec_dt."</td>";
										}
										echo "<td class='center'>".$test['ref_no']."<br>".$refdt."</td>";
										$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
										$s=mysql_fetch_array($ltrtype);
										echo "<td class='center'>".$s['sandharbh_nm']."</td>
										<td class='center'>".$test['subject']."</td>
										<td class='center'>".$test['sender_name']."</td>";
										
										if($test['action_taken']=='')
										{
											echo "<td class='center'><font color='red'>कार्यवाही केलेली नाही  </font></td>";
										}
										else if($test['ltr_status']=='')
										{
											echo "<td class='center'><font color='red'>कार्यवाही केलेली नाही  </font></td>";
										}
										else
										{
											echo "<td class='center'>".$test['action_taken']."</td>";
										}
										echo "</tr>";
									}
								echo"</tbody></table>";	
								################################## div to print ############################
								
								echo "<div id='divToPrint' style='display:none;'>
								<center><table id='export' border='1px' >
								<tr><td colspan='8'><center>".$deptnm['dept_nm']." चे स्वीकृत पत्राचे रिपोर्ट्स <br> दिनांक ".$date123." पासून दिनांक ".$date223." </center></td></tr>";
								echo ' <center><h2>पोलीस अधिक्षक <br> कार्यालय <br> जि.रायगड<h2></center>';
							if($date123==''&& $date223=='' && $dt_type=='')
							{	
								
								$id = $date1;
								$id1= $date2;
								
								//accpeted by dept but deskid=0 or desk_apprval=pending
								$qry1=mysql_query("SELECT DISTINCT i.ltr_type, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt,t.returned_choice, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, 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.sent_to_desk_dt
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND (t.desk_id='0' OR t.desk_approval='pending')") OR die("aabbhhaa".mysql_error());
								
								//accpeted by desk and ltrstatus!=closed
								$qry2=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id,t.returned_choice, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND de.ltr_status!='closed' AND de.ltr_approval!='transferred_todesk' ") OR die("aabbhhaa".mysql_error());
								
							}
							else if($date123!=''&& $date223!='' && $dt_type==1)
							{
								$id = $date1;
								$id1= $date2; 
								
								$qry1=mysql_query("SELECT DISTINCT i.ltr_type, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt,t.returned_choice, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, 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.sent_to_desk_dt
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND (t.desk_id='0' OR t.desk_approval='pending') AND (i.receive_dt BETWEEN '$date1' AND '$date2')");
								
								$qry2=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id,t.returned_choice, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND de.ltr_status!='closed' AND de.ltr_approval!='transferred_todesk' AND (i.receive_dt BETWEEN '$date1' AND '$date2') ") OR die("aabbhhaa".mysql_error());
							}
							else if($date123!=''&& $date223!='' && $dt_type==2)
							{
								$id = $date1;
								$id1= $date2; 
								
								$qry1=mysql_query("SELECT DISTINCT i.ltr_type, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt,t.returned_choice, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, 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.sent_to_desk_dt
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND (t.desk_id='0' OR t.desk_approval='pending') AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')");
								
								$qry2=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id,t.returned_choice, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND de.ltr_status!='closed' AND de.ltr_approval!='transferred_todesk' AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aabbhhaa".mysql_error());
							}
							else if($date123!=''&& $date223!='' && $dt_type==3)
							{
								$id = $date1;
								$id1= $date2; 
								
								$qry1=mysql_query("SELECT DISTINCT i.ltr_type, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt,t.returned_choice, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, 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.sent_to_desk_dt
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND (t.desk_id='0' OR t.desk_approval='pending') AND (de.desk_ltr_rec_dt BETWEEN '$date1' AND '$date2')");
								
								$qry2=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id,t.returned_choice, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND de.ltr_status!='closed' AND de.ltr_approval!='transferred_todesk' AND (de.desk_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aabbhhaa".mysql_error());
							}
							$cnt=mysql_num_rows($qry1);
								echo	"<tr>
									<th>पोलीस अधिक्षक <br> कार्यालय <br> आवक क्रमांक <br>आवक_दिनांक</th>
									<th>विभागीय आवक क्र.<br>आवक_दिनांक</th>
									<th>डेस्कचा आवक क्र. <br>आवक_दिनांक</th>
									<th>संदर्भ_क्रमांक <br>संदर्भ दि. </th>
									<th>संदर्भाचा प्रकार</th>
									<th>विषय</th>
									<th>कोणाकडून <br>प्राप्त_झाला</th>
									<th>केलेली <br>कार्यवाही </th>";
									echo "</tr>";
									while($test = mysql_fetch_array($qry1))
									{
										$desk_ltr_rec_dt = date('d-m-Y',strtotime($test['desk_ltr_rec_dt']));
										$dept_rec_date 	= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
										$receive_dt	= date('d-m-Y',strtotime($test['receive_dt']));
										$refdt	= date('d-m-Y',strtotime($test['ref_dt']));
										$deskrec_dt	= date('d-m-Y',strtotime($test['sent_to_desk_dt']));
										$m=$test['ltr_type'];
										
										$dsk1=$test['desk_id_from'];
										convert_marathi();
										$qsk1=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk1'") or die("".mysql_error());
										$desk1=mysql_fetch_array($qsk1);
										
										$dsk2=$test['desk_id'];
										convert_marathi();
										$qsk2=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk2'") or die("".mysql_error());
										$desk2=mysql_fetch_array($qsk2);
										echo "
										<tr class='gradeX'>
										<td class='center'>".$test['ltr_inword_no']."<br>".$receive_dt."</td>
										<td class='center'>".$test['dpt_inword_no']."<br>".$dept_rec_date ."</td>";
										
										if($test['returned_choice']!='')
										{
											echo "<td class='center'>Letter Returned To <br> Tapal</td>";
										}
										else if($test['desk_id']=='' || $test['desk_id']=='0')
										{
											echo "<td class='center'>"."डेस्क लावणे बाकी  "."</td>";
										}
										else if($test['desk_ltr_inword_no']=='' || $test['desk_ltr_inword_no']=='0')
										{
											echo "<td class='center'>".$desk2['desk_nm']."<br>"."डेस्कने स्वीकारणे बाकी "."</td>";
										}
										else  if($test['desk_ltr_inword_no']!='0' || $test['desk_ltr_inword_no']!='')
										{
											echo "<td class='center'>".$desk1['desk_nm']."<br>".$test['desk_ltr_inword_no']."<br>".$deskrec_dt."</td>";
										}
										echo "<td class='center'>".$test['ref_no']."<br>".$refdt."</td>";
										$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
										$s=mysql_fetch_array($ltrtype);
										echo "<td class='center'>".$s['sandharbh_nm']."</td>
										<td class='center'>".$test['subject']."</td>
										<td class='center'>".$test['sender_name']."</td>";
										
										if($test['returned_choice']!='')
										{
											echo "<td class='center'>Letter Returned To <br> Tapal</td>";
										}
										else if($test['action_taken']=='')
										{
											echo "<td class='center'>कार्यवाही केलेली नाही  </td>";
										}
										else if($test['ltr_status']=='')
										{
											echo "<td class='center'>कार्यवाही केलेली नाही  </td>";
										}
										else
										{
											echo "<td class='center'>".$test['action_taken']."</td>";
										}
										echo "</tr>";
									}
									while($test = mysql_fetch_array($qry2))
									{
										$desk_ltr_rec_dt = date('d-m-Y',strtotime($test['desk_ltr_rec_dt']));
										$dept_rec_date 	= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
										$receive_dt	= date('d-m-Y',strtotime($test['receive_dt']));
										$refdt	= date('d-m-Y',strtotime($test['ref_dt']));
										$deskrec_dt	= date('d-m-Y',strtotime($test['sent_to_desk_dt']));
										$m=$test['ltr_type'];
										
										$dsk1=$test['desk_id_from'];
										convert_marathi();
										$qsk1=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk1'") or die("".mysql_error());
										$desk1=mysql_fetch_array($qsk1);
										
										$dsk2=$test['desk_id'];
										convert_marathi();
										$qsk2=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk2'") or die("".mysql_error());
										$desk2=mysql_fetch_array($qsk2);
										echo "
										<tr class='gradeX'>
										<td class='center'>".$test['ltr_inword_no']."<br>".$receive_dt."</td>
										<td class='center'>".$test['dpt_inword_no']."<br>".$dept_rec_date ."</td>";
										if($test['desk_id']=='' || $test['desk_id']=='0')
										{
											echo "<td class='center'>"."डेस्क लावणे बाकी  "."</td>";
										}
										else if($test['desk_ltr_inword_no']=='' || $test['desk_ltr_inword_no']=='0')
										{
											echo "<td class='center'>".$desk2['desk_nm']."<br>"."डेस्कने स्वीकारणे बाकी "."</td>";
										}
										else  if($test['desk_ltr_inword_no']!='0' || $test['desk_ltr_inword_no']!='')
										{
											echo "<td class='center'>".$desk1['desk_nm']."<br>".$test['desk_ltr_inword_no']."<br>".$deskrec_dt."</td>";
										}
										echo "<td class='center'>".$test['ref_no']."<br>".$refdt."</td>";
										$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
										$s=mysql_fetch_array($ltrtype);
										echo "<td class='center'>".$s['sandharbh_nm']."</td>
										<td class='center'>".$test['subject']."</td>
										<td class='center'>".$test['sender_name']."</td>";
										
										if($test['action_taken']=='')
										{
											echo "<td class='center'>कार्यवाही केलेली नाही  </td>";
										}
										else if($test['ltr_status']=='')
										{
											echo "<td class='center'>कार्यवाही केलेली नाही  </td>";
										}
										else
										{
											echo "<td class='center'>".$test['action_taken']."</td>";
										}
										echo "</tr>";
									}
					echo"</table></center></div>";	
					}
					
					else if($flag =='n')
					{
					?>
					
					<h4 class="widgettitle"><?php echo $deptnm['dept_nm'];?> चे स्वीकृत पत्राचे रिपोर्ट्स <h4>
					<form method='post'>
						<form name="sadyasthiti" action="" method="post">
						<div align="center"><br><table align="center" cellpadding="2" cellspacing="0" class='myClass'>
						<table>
							<tr>
								<td><label>तारखेचा प्रकार निवडा  : </label></td>
								<td><span class="field unicode" lang="mr">
										<select name="datetype">
											<option value="">तारखेचा प्रकार निवडा</option>  
											<option value="1">आवक दिनांक</option>
											<option value="2">विभागीय आवक दिनांक</option>
										</select>
									</span>
								</td>
									  
								<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="4">
								<div align="center">
									<input type="submit" onClick="return sadyasthitiDate()" name="ok" value="GO"/>
									<input type="reset" value="CLEAR" name="clear"/>
								</div>
								</td>
							</tr>
						</table>
					</div>
				</form>
				<form action="" method="post">

						<?php
						$dt_type=$_POST['datetype'];
						//echo "date".$dt_type;
						$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=='' && $dt_type=='')
						{	
								echo '<br><br><center>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center><br>';$id = $date1;
								$id1= $date2;
						
								/*$qry1=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.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, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id WHERE t.dept_id_from='$deptid'") OR die("aaaa".mysql_error());*/
								$qry1=mysql_query("SELECT DISTINCT i.ltr_type, 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.returned_choice, t.status, 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,t.sent_to_desk_dt, t.ltr_category, t.assign_no 
								FROM tapal_to_dpt_transaction t, incoming_letters_transaction  i 
								WHERE i.ltr_id = t.ltr_id 
								AND t.dept_id_from='$deptid' ") OR die("aaaa".mysql_error());
								
							}
							
							else if($date123!=''&& $date223!='' && $dt_type==1)
							{
								echo '<br><center><h4> <font color="red">आवक दिनांकनुसार संदर्भ </font></h4></center><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								
								/*$qry1=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.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, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id WHERE t.dept_id_from='$deptid' AND (i.receive_dt BETWEEN '$date1' AND '$date2')");*/
								$qry1=mysql_query("SELECT DISTINCT i.ltr_type, t.action_taken, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no,t.returned_choice, t.desk_id, t.dept_id_from, i.subject, t.update_date, t.dispatched_date, t.status, 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,t.sent_to_desk_dt, t.ltr_category, t.assign_no 
								FROM tapal_to_dpt_transaction t, incoming_letters_transaction  i 
								WHERE i.ltr_id = t.ltr_id 
								AND t.dept_id_from='$deptid'
								AND (i.receive_dt BETWEEN '$date1' AND '$date2')") OR die("bbbbb".mysql_error());
							}
							else if($date123!=''&& $date223!='' && $dt_type==2)
							{
								echo '<br><center><h4> <font color="red">आवक दिनांकनुसार संदर्भ </font></h4></center><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								
								/*$qry1=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.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, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id WHERE t.dept_id_from='$deptid' AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("ccccc".mysql_error());*/
								$qry1=mysql_query("SELECT DISTINCT i.ltr_type, 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,t.returned_choice, 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,t.sent_to_desk_dt, t.ltr_category, t.assign_no 
								FROM tapal_to_dpt_transaction t, incoming_letters_transaction  i 
								WHERE i.ltr_id = t.ltr_id 
								AND t.dept_id_from='$deptid'
								AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("ccccc".mysql_error());
							}
						/*	else if($date123!=''&& $date223!='' && $dt_type==3)
							{
								echo '<br><center><h4> <font color="red">आवक दिनांकनुसार संदर्भ </font></h4></center><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								
								$qry1=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.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, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id WHERE t.dept_id_from='$deptid' AND (de.desk_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("dddd".mysql_error());
								////////////
								$qry1=mysql_query("SELECT DISTINCT i.ltr_type, 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, 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,t.sent_to_desk_dt, t.ltr_category, t.assign_no 
								FROM tapal_to_dpt_transaction t, incoming_letters_transaction  i 
								WHERE i.ltr_id = t.ltr_id 
								AND t.dept_id_from='$deptid'
								AND i.status='approve' AND (de.desk_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("dddd".mysql_error());
							}
							*/
							
							//$cnt=mysql_num_rows($qry1);
							echo"  <br><br><table id='dyntable' class='table table-bordered'><thead>
									<tr>
									<th class='head1 center'>पोलीस अधिक्षक <br> कार्यालय <br> आवक क्रमांक <br>आवक_दिनांक</th>
									<th class='head0 center'>विभागीय आवक क्र.<br>आवक_दिनांक</th>
									<th class='head0 center'>संदर्भ_क्रमांक <br>संदर्भ दि. </th>
									<th class='head1 center'>संदर्भाचा प्रकार</th>
									<th class='head0 center'>विषय</th>
									<th class='head1 center'>कोणाकडून <br>प्राप्त_झाला</th>
									<th class='head1 center'>केलेली <br>कार्यवाही </th>";
									
									 echo "</tr> </thead><tbody>";
									while($test = mysql_fetch_array($qry1))
									{
										
										$dept_rec_date 	= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
										$receive_dt	= date('d-m-Y',strtotime($test['receive_dt']));
										$refdt	= date('d-m-Y',strtotime($test['ref_dt']));
										$deskrec_dt	= date('d-m-Y',strtotime($test['sent_to_desk_dt']));
										$m=$test['ltr_type'];
										$return_ch=$test['returned_choice'];
										
										echo "
										<tr class='gradeX'>
										<td class='center'>".$test['ltr_inword_no']."<br>".$receive_dt."</td>
										<td class='center'>".$test['dpt_inword_no']."<br>".$dept_rec_date ."</td>";
										
										echo "<td class='center'>".$test['ref_no']."<br>".$refdt."</td>";
										$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
										$s=mysql_fetch_array($ltrtype);
										echo "<td class='center'>".$s['sandharbh_nm']."</td>
										<td class='center'>".$test['subject']."</td>
										<td class='center'>".$test['sender_name']."</td>";
										////////////////////////////////////////////////////////////
										if($return_ch!='')
										{
											echo "<td style='text-align:center;'>Letter Returned To<br> Tapal </td>";
										}
										else if($test['ltr_status']=='')
										{
											echo "<td style='text-align:center;'><font color='red'>कार्यवाही केलेली नाही  </font></td>";
										}
										else
										{
											echo "<td style='text-align:center;'>".$test['action_taken']."</td>";
										}
										echo "</tr>";
									}
								echo"</tbody></table>";	
								################################## div to print ############################
								
								echo "<div id='divToPrint' style='display:none;'>
								<center><table id='export' border='1px' style='margin-left:50px;'>
								<tr><td colspan='7'><center>".$deptnm['dept_nm']." चे स्वीकृत पत्राचे रिपोर्ट्स <br> दिनांक ".$date123." पासून दिनांक ".$date223." </center></td></tr>";
								
								echo ' <center><h2>पोलीस अधिक्षक <br> कार्यालय <br> जि.रायगड<h2></center>';
								
							if($date123==''&& $date223=='' && $dt_type=='')
							{	
								$id = $date1;
								$id1= $date2;
						
								/*$qry1=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.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, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id WHERE t.dept_id_from='$deptid'") OR die("aaaa".mysql_error());*/
								$qry1=mysql_query("SELECT DISTINCT i.ltr_type, 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.returned_choice, t.status, 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,t.sent_to_desk_dt, t.ltr_category, t.assign_no 
								FROM tapal_to_dpt_transaction t, incoming_letters_transaction  i 
								WHERE i.ltr_id = t.ltr_id 
								AND t.dept_id_from='$deptid' ") OR die("aaaa".mysql_error());
								
							}
							
							else if($date123!=''&& $date223!='' && $dt_type==1)
							{
								$id = $date1;
								$id1= $date2; 
								
								/*$qry1=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.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, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id WHERE t.dept_id_from='$deptid' AND (i.receive_dt BETWEEN '$date1' AND '$date2')");*/
								$qry1=mysql_query("SELECT DISTINCT i.ltr_type, t.action_taken, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no,t.returned_choice, t.desk_id, t.dept_id_from, i.subject, t.update_date, t.dispatched_date, t.status, 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,t.sent_to_desk_dt, t.ltr_category, t.assign_no 
								FROM tapal_to_dpt_transaction t, incoming_letters_transaction  i 
								WHERE i.ltr_id = t.ltr_id 
								AND t.dept_id_from='$deptid'
								AND (i.receive_dt BETWEEN '$date1' AND '$date2')") OR die("bbbbb".mysql_error());
							}
							else if($date123!=''&& $date223!='' && $dt_type==2)
							{
								$id = $date1;
								$id1= $date2; 
								
								/*$qry1=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.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, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id WHERE t.dept_id_from='$deptid' AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("ccccc".mysql_error());*/
								$qry1=mysql_query("SELECT DISTINCT i.ltr_type, 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,t.returned_choice, 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,t.sent_to_desk_dt, t.ltr_category, t.assign_no 
								FROM tapal_to_dpt_transaction t, incoming_letters_transaction  i 
								WHERE i.ltr_id = t.ltr_id 
								AND t.dept_id_from='$deptid'
								AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("ccccc".mysql_error());
							}
						/*	else if($date123!=''&& $date223!='' && $dt_type==3)
							{
								echo '<br><center><h4> <font color="red">आवक दिनांकनुसार संदर्भ </font></h4></center><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								
								$qry1=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.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, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id WHERE t.dept_id_from='$deptid' AND (de.desk_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("dddd".mysql_error());
								////////////
								$qry1=mysql_query("SELECT DISTINCT i.ltr_type, 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, 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,t.sent_to_desk_dt, t.ltr_category, t.assign_no 
								FROM tapal_to_dpt_transaction t, incoming_letters_transaction  i 
								WHERE i.ltr_id = t.ltr_id 
								AND t.dept_id_from='$deptid'
								AND i.status='approve' AND (de.desk_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("dddd".mysql_error());
							}
							*/
								$cnt=mysql_num_rows($qry1);
								echo	"<tr>
									<th>पोलीस अधिक्षक <br> कार्यालय <br> आवक क्रमांक <br>आवक_दिनांक</th>
									<th>विभागीय आवक क्र.<br>आवक_दिनांक</th>
									<th>संदर्भ_क्रमांक <br>संदर्भ दि. </th>
									<th>संदर्भाचा प्रकार</th>
									<th>विषय</th>
									<th>कोणाकडून <br>प्राप्त_झाला</th>
									<th>केलेली <br>कार्यवाही </th>";
									echo "</tr>";
									while($test = mysql_fetch_array($qry1))
									{
										
										$dept_rec_date 	= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
										$receive_dt	= date('d-m-Y',strtotime($test['receive_dt']));
										$refdt	= date('d-m-Y',strtotime($test['ref_dt']));
										$deskrec_dt	= date('d-m-Y',strtotime($test['sent_to_desk_dt']));
										$m=$test['ltr_type'];
										$return_ch=$test['returned_choice'];
										
										echo "
										<tr class='gradeX'>
										<td class='center'>".$test['ltr_inword_no']."<br>".$receive_dt."</td>
										<td class='center'>".$test['dpt_inword_no']."<br>".$dept_rec_date ."</td>";
										
										echo "<td class='center'>".$test['ref_no']."<br>".$refdt."</td>";
										$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
										$s=mysql_fetch_array($ltrtype);
										echo "<td class='center'>".$s['sandharbh_nm']."</td>
										<td class='center'>".$test['subject']."</td>
										<td class='center'>".$test['sender_name']."</td>";
										////////////////////////////////////////////////////////////
										if($return_ch!='')
										{
											echo "<td style='text-align:center;'>Letter Returned To<br> Tapal </td>";
										}
										else if($test['ltr_status']=='')
										{
											echo "<td style='text-align:center;'>कार्यवाही केलेली नाही  </td>";
										}
										else
										{
											echo "<td style='text-align:center;'>".$test['action_taken']."</td>";
										}
										echo "</tr>";
									}
					echo"</table></center></div>";	
					}
					
			}//if=2	
		#########################	End Of Accepted Letter report tapal user     #############################
		
		#########################	Dispatched,Updated Letter report tapal user     #############################
				else if($no==3)
				{
			?>		
			
			 <h4 class="widgettitle"><?php echo $deptnm['dept_nm'];?> चे पाठवलेल्या पत्राचे रिपोर्ट्स <h4>
						<form action="" method="post">
						<form name="sadyasthiti" action="" method="post">
						<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="4">
								<div align="center">
									<input type="submit" onClick="return sadyasthitiDate()" name="ok" value="GO"/>
									<input type="reset" value="CLEAR" name="clear"/>
								</div>
								</td>
							</tr>
						</table>
					</div>
				</form>
				<form action="" method="post">
						

						<?php
						$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));
						echo '<br><br><center>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center><br>';$id = $date1;
						$id1= $date2;
					
					if($flag=='')
					{
						if($date123==''&& $date223=='')
						{
							$qry13=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no,  di.dispatched_to, i.sent_dt, di.dispatched_to,di.dept_id_to, de.ltr_category, de.assign_no 
							FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
							LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
							LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
							WHERE t.dept_id_from='$deptid' 
							AND (de.ltr_status='dispatched' OR de.ltr_status='updated')
							AND de.ltr_approval!='transferred_todesk' ") OR die("aaaa".mysql_error());
							
							$cnt=mysql_num_rows($qry13);
						}
						else
						{
							$qry13=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no,  di.dispatched_to, i.sent_dt, di.dispatched_to,di.dept_id_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id WHERE t.dept_id_from='$deptid' AND (de.ltr_status='dispatched' OR de.ltr_status='updated')
							AND de.ltr_approval!='transferred_todesk'
							AND (i.receive_dt BETWEEN '$date1' AND '$date2')") OR die("aaaa".mysql_error());
							$cnt=mysql_num_rows($qry13);
						
						}
						
						//echo "aaaaaaaaa".$cnt;
							echo"  <br><br><table id='dyntable' class='table table-bordered'><thead>
									<tr>
									<th class='head1 center'>पोलीस अधिक्षक <br> कार्यालय <br> आवक क्रमांक <br>आवक_दिनांक</th>
									<th class='head0 center'>विभागीय आवक क्र.<br>आवक_दिनांक</th>
									<th class='head1 center'>डेस्कचा आवक क्र. <br>आवक_दिनांक</th>
									<th class='head0 center'>संदर्भ_क्रमांक <br>संदर्भ दि. </th>
									<th class='head1 center'>संदर्भाचा प्रकार</th>
									<th class='head0 center'>विषय</th>
									<th class='head1 center'>कोणाकडून <br>प्राप्त_झाला</th>
									<th class='head0 center'>केलेली कार्यवाही</th>
									<th class='head0 center'>पत्राची_स्थिती </th>
									<th class='head1 center'>विभागीय <br>जावक_दिनांक</th>";
									echo "</tr>
									</thead>
									<tbody>";			
									while($test = mysql_fetch_array($qry13))
									{
										$dept_rec_date 	= date('d-m-Y',strtotime($test['sent_dt']));
										$receive_dt	= date('d-m-Y',strtotime($test['receive_dt']));
										$refdt	= date('d-m-Y',strtotime($test['ref_dt']));
										$deskrec_dt	= date('d-m-Y',strtotime($test['sent_to_desk_dt']));
										$update_date 		= date('d-m-Y',strtotime($test['update_date']));
										$dispose_date 		= date('d-m-Y',strtotime($test['dispatched_dt']));
										$m=$test['ltr_type'];
										
										//desk name
										$dsk1=$test['desk_id_from'];
										convert_marathi();
										$qsk1=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk1'") or die("".mysql_error());
										$desk1=mysql_fetch_array($qsk1);
									
										echo "<tr class='gradeX'>
										<td class='center'>".$test['ltr_inword_no']."<br>".$receive_dt."</td>
										<td class='center'>".$test['dpt_inword_no']."<br>".$dept_rec_date ."</td>";
										if($test['desk_id']=='' || $test['desk_id']==0)
										{
											echo "<td class='center'><font color='red'>"."डेस्क लावणे बाकी "."</font></td>";
										}
										else if($test['desk_ltr_inword_no']=='' || $test['desk_ltr_inword_no']=='0')
										{
											echo "<td class='center'><font color='red'>"."डेस्कने स्वीकारणे बाकी "."</font></td>";
										}
										else
										{
											echo "<td class='center'>".$desk1['desk_nm']."<br>".$test['desk_ltr_inword_no']."<br>".$deskrec_dt."</td>";
										}
										echo "<td class='center'>".$test['ref_no']."<br>".$refdt."</td>";
										$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
										$s=mysql_fetch_array($ltrtype);
										echo "<td class='center'>".$s['sandharbh_nm']."</td>
										<td class='center'>".$test['subject']."</td>
										<td class='center'>".$test['sender_name']."</td>";
										echo "<td class='center'>".$test['action_taken']."</td>";
										////////////////////////////////////////////////////////
										if($test['ltr_status']=='')
										{
											echo "<td class='center'><font color='red'> कार्यवाही करणे बाकी </font></td>";
										}
										else if($test['ltr_approval']=='transferred')
										{
											$dpt_to=$test['dept_id_to'];
											$q=mysql_query("SELECT dept_nm from department_master where dept_id='$dpt_to' ");
											$r=mysql_fetch_array($q);
											echo "<td class='center'>".$test['ltr_approval']." to <br>".$r['dept_nm']."</td>";
										}
										else
										{
											echo "<td class='center'>".$test['ltr_status']."</td>";
										}
										////////////////////////////////////////////////////
										if ($test['ltr_status']=='updated')
											{
												echo "<td class='center'>".$update_date."</td>";
											}
										else if($test['ltr_status']=='dispatched')
											{
												echo "<td class='center'>".$dispose_date."</td>";
											}
										echo "</tr>";

									}
					echo"</tbody></table>";

						
						echo "<div id='divToPrint' style='display:none;'>
								<center><table id='export' border='1px' style='margin-left:50px;'>
								<tr><td colspan='10'><center>".$deptnm['dept_nm']." चे पाठवलेल्या पत्राचे रिपोर्ट्स <br> दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
								
								echo ' <center><h2>पोलीस अधिक्षक <br> कार्यालय <br> जि.रायगड<h2></center>';
								
						if($date123==''&& $date223=='')
						{
							$qry13=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no,  di.dispatched_to, i.sent_dt, di.dispatched_to,di.dept_id_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id WHERE t.dept_id_from='$deptid' AND (de.ltr_status='dispatched' OR de.ltr_status='updated') AND de.ltr_approval!='transferred_todesk' ") OR die("aaaa".mysql_error());
							$cnt=mysql_num_rows($qry13);
						}
						else
						{
							$qry13=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no,  di.dispatched_to, i.sent_dt, di.dispatched_to,di.dept_id_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id WHERE t.dept_id_from='$deptid' AND (de.ltr_status='dispatched' OR de.ltr_status='updated') AND de.ltr_approval!='transferred_todesk' AND ((de.update_date BETWEEN '$date1' AND '$date2') OR (de.dispatched_dt BETWEEN '$date1' AND '$date2'))") OR die("aaaa".mysql_error());
							$cnt=mysql_num_rows($qry13);
						
						}
						$cnt=mysql_num_rows($qry13);
						//echo "aaaaaaaaa".$cnt;
						echo" <tr>
								<th>पोलीस अधिक्षक <br> कार्यालय <br> आवक क्रमांक <br>आवक_दिनांक</th>
								<th>विभागीय आवक क्र.<br>आवक_दिनांक</th>
								<th>डेस्कचा आवक क्र. <br>आवक_दिनांक</th>
								<th>संदर्भ_क्रमांक <br>संदर्भ दि. </th>
								<th>संदर्भाचा प्रकार</th>
								<th>विषय</th>
								<th>कोणाकडून <br>प्राप्त_झाला</th>
								<th>केलेली कार्यवाही</th>
								<th>पत्राची_स्थिती </th>
								<th>विभागीय <br>जावक_दिनांक</th>";
						echo "</tr>";			
						while($test = mysql_fetch_array($qry13))
						{
							$dept_rec_date 	= date('d-m-Y',strtotime($test['sent_dt']));
							$receive_dt	= date('d-m-Y',strtotime($test['receive_dt']));
							$refdt	= date('d-m-Y',strtotime($test['ref_dt']));
							$deskrec_dt	= date('d-m-Y',strtotime($test['sent_to_desk_dt']));
							$update_date 		= date('d-m-Y',strtotime($test['update_date']));
							$dispose_date 		= date('d-m-Y',strtotime($test['dispatched_dt']));
							
							$m=$test['ltr_type'];
							//desk name
							$dsk1=$test['desk_id_from'];
							convert_marathi();
							$qsk1=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk1'") or die("".mysql_error());
							$desk1=mysql_fetch_array($qsk1);
							
							echo "<tr>
							<td style='text-align:center;'>".$test['ltr_inword_no']."<br>".$receive_dt."</td>
							<td style='text-align:center;'>".$test['dpt_inword_no']."<br>".$dept_rec_date ."</td>";
							if($test['desk_id']=='' || $test['desk_id']==0)
							{
								echo "<td style='text-align:center;'><font color='red'>"."डेस्क लावणे बाकी "."</font></td>";
							}
							else if($test['desk_ltr_inword_no']=='' || $test['desk_ltr_inword_no']=='0')
							{
								echo "<td style='text-align:center;'><font color='red'>"."डेस्कने स्वीकारणे बाकी "."</font></td>";
							}
							else
							{
								echo "<td style='text-align:center;'>".$desk1['desk_nm']."<br>".$test['desk_ltr_inword_no']."<br>".$deskrec_dt."</td>";
							}
							echo "<td style='text-align:center;'>".$test['ref_no']."<br>".$refdt."</td>";
							$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
							$s=mysql_fetch_array($ltrtype);
							echo "<td style='text-align:center;'>".$s['sandharbh_nm']."</td>
							<td style='text-align:center;'>".$test['subject']."</td>
							<td style='text-align:center;'>".$test['sender_name']."</td>";
							echo "<td style='text-align:center;'>".$test['action_taken']."</td>";
							////////////////////////////////////////////////////////////////
							if($test['ltr_status']=='')
								{
									echo "<td style='text-align:center;'><font color='red'> कार्यवाही करणे बाकी </font></td>";
								}
							else if($test['ltr_approval']=='transferred')
							{
								$dpt_to=$test['dept_id_to'];
								$q=mysql_query("SELECT dept_nm from department_master where dept_id='$dpt_to' ");
								$r=mysql_fetch_array($q);
								echo "<td class='center'>".$test['ltr_approval']." to <br>".$r['dept_nm']."</td>";
							}
							else
							{
								echo "<td class='center'>".$test['ltr_status']."</td>";
							}
							////////////////////////////////////////////////////////////////////////////
							if ($test['ltr_status']=='updated')
								{
									echo "<td style='text-align:center;'>".$update_date."</td>";
								}
							else if($test['ltr_status']=='dispatched')
								{
									echo "<td style='text-align:center;'>".$dispose_date."</td>";
								}
							echo "</tr>";
						}
					echo"</table></center></div>";	
					
					} //if($flag=='')
					
					else if($flag=='n')
					{
						if($date123==''&& $date223=='')
						{
							/*$qry13=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no,  di.dispatched_to, i.sent_dt, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id WHERE t.dept_id_from='$deptid' AND (de.ltr_status='dispatched' OR de.ltr_status='updated')") OR die("aaaa".mysql_error());*/
							$qry13=mysql_query("SELECT DISTINCT t.action_taken, i.ltr_type, 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, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc, di.outword_no,  di.dispatched_to,di.dept_id_to, i.sent_dt, di.dispatched_to, t.ltr_category, t.assign_no 
							FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i 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.ltr_status='dispatched' OR t.ltr_status='updated')
							AND t.dept_id_from='$deptid'
							AND t.returned_choice='' ") OR die("aaaa".mysql_error());
							
							$cnt=mysql_num_rows($qry13);
						}
						else
						{
							/*$qry13=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no,  di.dispatched_to, i.sent_dt, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id WHERE t.dept_id_from='$deptid' AND (de.ltr_status='dispatched' OR de.ltr_status='updated') AND (i.receive_dt BETWEEN '$date1' AND '$date2')") OR die("aaaa".mysql_error());*/
							$qry13=mysql_query("SELECT DISTINCT t.action_taken, i.ltr_type, 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, di.dept_id_to, t.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc, di.outword_no,  di.dispatched_to, i.sent_dt, di.dispatched_to, t.ltr_category, t.assign_no 
							FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i 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.ltr_status='dispatched' OR t.ltr_status='updated')
							AND t.dept_id_from='$deptid'
							AND t.returned_choice='' AND (i.receive_dt BETWEEN '$date1' AND '$date2')") OR die("aaaa".mysql_error());
							
							$cnt=mysql_num_rows($qry13);
						
						}
						
						//echo "aaaaaaaaa".$cnt;
							echo"  <br><br><table id='dyntable' class='table table-bordered'><thead>
									<tr>
									<th class='head1 center'>पोलीस अधिक्षक <br> कार्यालय <br> आवक क्रमांक <br>आवक_दिनांक</th>
									<th class='head0 center'>विभागीय आवक क्र.<br>आवक_दिनांक</th>
									<th class='head0 center'>संदर्भ_क्रमांक <br>संदर्भ दि. </th>
									<th class='head1 center'>संदर्भाचा प्रकार</th>
									<th class='head0 center'>विषय</th>
									<th class='head1 center'>कोणाकडून <br>प्राप्त_झाला</th>
									<th class='head0 center'>केलेली कार्यवाही</th>
									<th class='head0 center'>पत्राची_स्थिती </th>
									<th class='head1 center'>विभागीय <br>जावक_दिनांक</th>";
									echo "</tr>
									</thead>
									<tbody>";			
									while($test = mysql_fetch_array($qry13))
									{
										$dept_rec_date 	= date('d-m-Y',strtotime($test['sent_dt']));
										$receive_dt	= date('d-m-Y',strtotime($test['receive_dt']));
										$refdt	= date('d-m-Y',strtotime($test['ref_dt']));
										//$deskrec_dt	= date('d-m-Y',strtotime($test['sent_to_desk_dt']));
										$update_date 		= date('d-m-Y',strtotime($test['update_date']));
										$dispose_date 		= date('d-m-Y',strtotime($test['dispatched_date']));
										$m=$test['ltr_type'];
										$dpt_to=$test['dept_id_to'];
										
										echo "<tr class='gradeX'>
										<td class='center'>".$test['ltr_inword_no']."<br>".$receive_dt."</td>
										<td class='center'>".$test['dpt_inword_no']."<br>".$dept_rec_date ."</td>";
										
										echo "<td class='center'>".$test['ref_no']."<br>".$refdt."</td>";
										$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
										$s=mysql_fetch_array($ltrtype);
										echo "<td class='center'>".$s['sandharbh_nm']."</td>
										<td class='center'>".$test['subject']."</td>
										<td class='center'>".$test['sender_name']."</td>";
										echo "<td class='center'>".$test['action_taken']."</td>";
										///////////////////////////////////////////////////
										if($test['ltr_status']=='')
										{
										echo "<td class='center'><font color='red'> कार्यवाही करणे बाकी </font></td>";
										}
										else if($test['status']=='transferred')
										{
											$q=mysql_query("SELECT dept_nm from  department_master where dept_id='$dpt_to'");
											$r=mysql_fetch_array($q);
										
											echo "<td class='center'>".$test['status']." to <br>".$r['dept_nm']." </td>";
										}
										else
										{
											echo "<td class='center'>".$test['ltr_status']."</td>";
										}
										///////////////////////////////////////
										if ($test['ltr_status']=='updated')
											{
												echo "<td class='center'>".$update_date."</td>";
											}
										else if($test['ltr_status']=='dispatched')
											{
												echo "<td class='center'>".$dispose_date."</td>";
											}
										echo "</tr>";

									}
					echo"</tbody></table>";

						
						echo "<div id='divToPrint' style='display:none;'>
								<center><table id='export' border='1px' style='margin-left:50px;'>
								<tr><td colspan='10'><center>".$deptnm['dept_nm']." चे पाठवलेल्या पत्राचे रिपोर्ट्स  <br>दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
								echo ' <center><h2>पोलीस अधिक्षक <br> कार्यालय <br> जि.रायगड<h2></center>';
						if($date123==''&& $date223=='')
						{
							$qry13=mysql_query("SELECT DISTINCT t.action_taken, i.ltr_type, 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, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc, di.outword_no,  di.dispatched_to,di.dept_id_to, i.sent_dt, di.dispatched_to, t.ltr_category, t.assign_no 
							FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i 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.ltr_status='dispatched' OR t.ltr_status='updated')
							AND t.dept_id_from='$deptid'
							AND t.returned_choice='' ") OR die("aaaa".mysql_error());
							
							$cnt=mysql_num_rows($qry13);
						}
						else
						{
							$qry13=mysql_query("SELECT DISTINCT t.action_taken, i.ltr_type, 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, di.dept_id_to, t.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc, di.outword_no,  di.dispatched_to, i.sent_dt, di.dispatched_to, t.ltr_category, t.assign_no 
							FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i 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.ltr_status='dispatched' OR t.ltr_status='updated')
							AND t.dept_id_from='$deptid'
							AND t.returned_choice='' AND (i.receive_dt BETWEEN '$date1' AND '$date2')") OR die("aaaa".mysql_error());
							
							$cnt=mysql_num_rows($qry13);
						
						}
						$cnt=mysql_num_rows($qry13);
						//echo "aaaaaaaaa".$cnt;
						echo" <tr>
								<th>पोलीस अधिक्षक <br> कार्यालय <br> आवक क्रमांक <br>आवक_दिनांक</th>
								<th>विभागीय आवक क्र.<br>आवक_दिनांक</th>
								<th>संदर्भ_क्रमांक <br>संदर्भ दि. </th>
								<th>संदर्भाचा प्रकार</th>
								<th>विषय</th>
								<th>कोणाकडून <br>प्राप्त_झाला</th>
								<th>केलेली कार्यवाही</th>
								<th>पत्राची_स्थिती </th>
								<th>विभागीय <br>जावक_दिनांक</th>";
						echo "</tr>";			
								while($test = mysql_fetch_array($qry13))
									{
										$dept_rec_date 	= date('d-m-Y',strtotime($test['sent_dt']));
										$receive_dt	= date('d-m-Y',strtotime($test['receive_dt']));
										$refdt	= date('d-m-Y',strtotime($test['ref_dt']));
										//$deskrec_dt	= date('d-m-Y',strtotime($test['sent_to_desk_dt']));
										$update_date 		= date('d-m-Y',strtotime($test['update_date']));
										$dispose_date 		= date('d-m-Y',strtotime($test['dispatched_date']));
										$m=$test['ltr_type'];
										$dpt_to=$test['dept_id_to'];
										
										echo "<tr class='gradeX'>
										<td class='center'>".$test['ltr_inword_no']."<br>".$receive_dt."</td>
										<td class='center'>".$test['dpt_inword_no']."<br>".$dept_rec_date ."</td>";
										
										echo "<td class='center'>".$test['ref_no']."<br>".$refdt."</td>";
										$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
										$s=mysql_fetch_array($ltrtype);
										echo "<td class='center'>".$s['sandharbh_nm']."</td>
										<td class='center'>".$test['subject']."</td>
										<td class='center'>".$test['sender_name']."</td>";
										echo "<td class='center'>".$test['action_taken']."</td>";
										///////////////////////////////////////////////////
										if($test['ltr_status']=='')
										{
										echo "<td class='center'> कार्यवाही करणे बाकी </td>";
										}
										else if($test['status']=='transferred')
										{
											$q=mysql_query("SELECT dept_nm from  department_master where dept_id='$dpt_to'");
											$r=mysql_fetch_array($q);
										
											echo "<td class='center'>".$test['status']." to <br>".$r['dept_nm']." </td>";
										}
										else
										{
											echo "<td class='center'>".$test['ltr_status']."</td>";
										}
										///////////////////////////////////////
										if ($test['ltr_status']=='updated')
											{
												echo "<td class='center'>".$update_date."</td>";
											}
										else if($test['ltr_status']=='dispatched')
											{
												echo "<td class='center'>".$dispose_date."</td>";
											}
										echo "</tr>";

									}
					echo"</table></center></div>";	
					
					} //else if($flag=='n')
					
				}//if=3					
							
		#########################	End Of Dispatched,Updated Letter report tapal user     #####################
		
		#########################	Approved But Not Worked Letter report tapal user     #############################
			else if($no==4)
			{
			
			if($flag=='')
{
	?>		
			
			 <h4 class="widgettitle"><?php echo $deptnm['dept_nm'];?> ने स्वीकृत परंतु कार्यवाही न केलेल्या पत्राचे रिपोर्ट  <h4>
			 
						<form name="sadyasthiti" action="" method="post">
						<div align="center"><br><table align="center" cellpadding="2" cellspacing="0" class='myClass'>
						<table>
							<tr>
							<td><label>तारखेचा प्रकार निवडा  : </label></td>
								<td><span class="field unicode" lang="mr">
										<select name="datetype">
											<option value="">तारखेचा प्रकार निवडा</option>  
											<option value="1">आवक दिनांक</option>
											<option value="2">विभागीय आवक दिनांक</option>
											<option value="3">डेस्क आवक दिनांक</option>
											<!--<option value="4">अपडेट/जावक दिनांक </option> -->
										</select>
									</span>
								</td>
								<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>
				</form>
				<form>
						

						<?php
						$dt_type=$_POST['datetype'];
						//echo "date".$dt_type;
						$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=='' && $dt_type=='')
							{
								echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
								$id = $date1;
								$id1= $date2; 
								
								//not assigned to desk OR assigned to desk but approval is pending
								$qry3=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.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 de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
								WHERE t.returned_choice='' 
								AND t.dept_id_from='$deptid' 
								AND (t.status='approve')
								AND (
										(t.desk_id='') OR 
										(t.desk_id='0') OR 
										(t.desk_id!='0' AND t.desk_approval='pending')
									)
								") OR die("aaaa".mysql_error());
								
								//desk accepted but not taken any action
								$qry4=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.returned_choice=''
								AND t.dept_id_from='$deptid' 
								AND de.ltr_approval='Approve' 
								AND de.desk_id_from=t.desk_id 
								AND  (de.ltr_status='' OR de.ltr_status='closed')") OR die("abxxba".mysql_error());
								
								//returned to dept
								$qry5=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.returned_choice='' 
								AND t.ltr_id=i.ltr_id 
								AND t.dept_id_from='$deptid'  
								AND t.status='pending' ") OR die("abxxba".mysql_error());
							}
						else if($date123!=''&& $date223!='' && $dt_type==1)
							{
								echo '<br><center><h4> <font color="red">आवक दिनांकनुसार संदर्भ </font></h4></center><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								$qry3=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.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 de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
								WHERE t.returned_choice='' 
								AND t.dept_id_from='$deptid' 
								AND (t.status='approve')
								AND (
										(t.desk_id='') OR 
										(t.desk_id='0') OR 
										(t.desk_id!='0' AND t.desk_approval='pending')
									)
								AND (i.receive_dt BETWEEN '$date1' AND '$date2')") OR die("xaaaa".mysql_error());
							
								$qry4=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.returned_choice=''
								AND t.dept_id_from='$deptid' 
								AND de.ltr_approval='Approve' 
								AND de.desk_id_from=t.desk_id 
								AND  (de.ltr_status='' OR de.ltr_status='closed')
								AND (i.receive_dt BETWEEN '$date1' AND '$date2')") OR die("yaaaa".mysql_error());
								
								$qry5=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.returned_choice='' 
								AND t.ltr_id=i.ltr_id 
								AND t.dept_id_from='$deptid'  
								AND t.status='pending'
								AND (i.receive_dt BETWEEN '$date1' AND '$date2')") OR die("yaaaa".mysql_error());
							}
							
							else if($date123!=''&& $date223!='' && $dt_type==2)
							{
								echo '<br><center><h4> <font color="red">विभागीय आवक दिनांकनुसार संदर्भ</font></h4></center><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								$qry3=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.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 de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
								WHERE t.returned_choice='' 
								AND t.dept_id_from='$deptid' 
								AND (t.status='approve')
								AND (
										(t.desk_id='') OR 
										(t.desk_id='0') OR 
										(t.desk_id!='0' AND t.desk_approval='pending')
									)
								AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aaaa".mysql_error());
							
								$qry4=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.returned_choice=''
								AND t.dept_id_from='$deptid' 
								AND de.ltr_approval='Approve' 
								AND de.desk_id_from=t.desk_id 
								AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aaxx".mysql_error());
								
								$qry5=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.returned_choice='' 
								AND t.ltr_id=i.ltr_id 
								AND t.dept_id_from='$deptid'  
								AND t.status='pending'
								AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aaxx".mysql_error());
							}
							
							else if($date123!=''&& $date223!='' && $dt_type==3)
							{
								echo '<br><center><h4> <font color="red">डेस्क आवक दिनांकनुसार संदर्भ</font></h4></center><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								$qry3=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.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 de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
								WHERE t.returned_choice='' 
								AND t.dept_id_from='$deptid' 
								AND (t.status='approve')
								AND (
										(t.desk_id='') OR 
										(t.desk_id='0') OR 
										(t.desk_id!='0' AND t.desk_approval='pending')
									)
								AND (de.desk_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aaaa".mysql_error());
							
								$qry4=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.returned_choice=''
								AND t.dept_id_from='$deptid' 
								AND de.ltr_approval='Approve' 
								AND de.desk_id_from=t.desk_id 
								AND (de.desk_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aaaa".mysql_error());
								
								$qry5=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.returned_choice='' 
								AND t.ltr_id=i.ltr_id 
								AND t.dept_id_from='$deptid'  
								AND t.status='pending'
								AND (de.desk_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aaaa".mysql_error());
							}
						echo"  <br><br><table id='dyntable' class='table table-bordered'>
								<thead>
								<tr>
									<th class='head1 center'>पोलीस अधिक्षक <br> कार्यालय <br> आवक क्रमांक <br>आवक_दिनांक</th>
									<th class='head0 center'>विभागीय आवक क्र.<br>आवक_दिनांक</th>
									<th class='head1 center'>डेस्कचा आवक क्र. <br>आवक_दिनांक</th>
									<th class='head0 center'>संदर्भ_क्रमांक <br>संदर्भ दि. </th>
									<th class='head0 center'>विषय</th>
									<th class='head1 center'>कोणाकडून <br>प्राप्त_झाला</th>
									<th class='head0 center'>केलेली कार्यवाही</th>	
								</tr>
								</thead>
							<tbody>";
						while($test = mysql_fetch_array($qry3))
						{
								$desk_ltr_rec_dt 	= date('d-m-Y',strtotime($test['sent_to_desk_dt']));
								$dept_rec_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
								$receive_dt		= date('d-m-Y',strtotime($test['receive_dt']));
								$refdt		= date('d-m-Y',strtotime($test['ref_dt']));
								$update_date 		= date('d-m-Y',strtotime($test['update_date']));
								$dispose_date 		= date('d-m-Y',strtotime($test['dispatched_dt']));
								$deskid=$test['desk_id'];
								
								//dept name
								$depti=$test['dept_id_from'];
								convert_marathi();
								$qdpt1=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("".mysql_error());
								$dept1=mysql_fetch_array($qdpt1);
								
								//desk nm
								$dsk1=$test['desk_id'];
								convert_marathi();
								$qsk1=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk1'") or die("".mysql_error());
								$desk1=mysql_fetch_array($qsk1);
								
								echo "<tr class='gradeX'>
									<td class='center'>".$test['ltr_inword_no']."<br>".$receive_dt."</td>
									<td class='center'>".$dept1['dept_nm']."<br>".$test['dpt_inword_no']."<br>".$dept_rec_date."</td>";
									if($test['desk_id']=='' || $test['desk_id']=='0')
									{
										echo "<td class='center'><font color='red'>डेस्क लावणे बाकी </font></td>";
									}
									else if($test['desk_ltr_inword_no']=='' || $test['desk_ltr_inword_no']=='0')
									{
										echo "<td class='center'><font color='red'>".$desk1['desk_nm']."<br>"."डेस्कने स्वीकारणे बाकी "."</font></td>";
									}
									else
									{
										echo "<td class='center'>".$desk1['desk_nm']."<br>".$test['desk_ltr_inword_no']."<br>".$desk_ltr_rec_dt."</td>";
									}
									echo "<td class='center'>".$test['ref_no']."<br>".$refdt."</td>
									<td class='center'>".$test['subject']."</font></td>
									<td class='center'>".$test['sender_name']."</font></td>";
									if($test['action_taken']=='' ||$test['action_taken']==0)
									{
										echo"<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
									}
									else if($test['ltr_status']=='' ||$test['ltr_status']==0)
									{
										echo"<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
									}
									else
									{
										echo"<td class='center'>".$test['action_taken']."</td>";
									}
										echo "</tr>";

						}
						while($test = mysql_fetch_array($qry4))
						{
							$desk_ltr_rec_dt 	= date('d-m-Y',strtotime($test['sent_to_desk_dt']));
							$dept_rec_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
							$receive_dt		= date('d-m-Y',strtotime($test['receive_dt']));
							$refdt		= date('d-m-Y',strtotime($test['ref_dt']));
							$update_date 		= date('d-m-Y',strtotime($test['update_date']));
							$dispose_date 		= date('d-m-Y',strtotime($test['dispatched_dt']));
							$deskid=$test['desk_id'];
							
							//dept name
							$depti=$test['dept_id_from'];
							convert_marathi();
							$qdpt1=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("".mysql_error());
							$dept1=mysql_fetch_array($qdpt1);
							
							//desk name
							$dsk1=$test['desk_id_from'];
							convert_marathi();
							$qsk1=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk1'") or die("".mysql_error());
							$desk1=mysql_fetch_array($qsk1);
								
							echo "<tr class='gradeX'>
								<td class='center'>".$test['ltr_inword_no']."<br>".$receive_dt."</td>
								<td class='center'>".$dept1['dept_nm']."<br>".$test['dpt_inword_no']."<br>".$dept_rec_date."</td>";
								if($test['desk_id']=='' || $test['desk_id']=='0')
								{
									echo "<td class='center'><font color='red'>डेस्क लावणे बाकी </font></td>";
								}
								else if($test['desk_ltr_inword_no']=='' || $test['desk_ltr_inword_no']=='0')
								{
									echo "<td class='center'><font color='red'>"."डेस्कने स्वीकारणे बाकी "."</font></td>";
								}
								else
								{
									echo "<td class='center'>".$desk1['desk_nm']."<br>".$test['desk_ltr_inword_no']."<br>".$desk_ltr_rec_dt."</td>";
								}
								echo "<td class='center'>".$test['ref_no']."<br>".$refdt."</td>
								<td class='center'>".$test['subject']."</font></td>
								<td class='center'>".$test['sender_name']."</font></td>";
								if($test['action_taken']=='' ||$test['action_taken']==0)
								{
									echo"<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								}
								else if($test['ltr_status']=='' ||$test['ltr_status']==0)
								{
									echo"<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								}
								else
								{
									echo"<td class='center'>".$test['action_taken']."</td>";
								}
							
											
										echo "</tr>";
						}
						while($test = mysql_fetch_array($qry5))
						{
								$desk_ltr_rec_dt 	= date('d-m-Y',strtotime($test['sent_to_desk_dt']));
								$dept_rec_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
								$receive_dt		= date('d-m-Y',strtotime($test['receive_dt']));
								$refdt		= date('d-m-Y',strtotime($test['ref_dt']));
								$update_date 		= date('d-m-Y',strtotime($test['update_date']));
								$dispose_date 		= date('d-m-Y',strtotime($test['dispatched_dt']));
								$deskid=$test['desk_id'];
								
								//dept name
								$depti=$test['dept_id_from'];
								convert_marathi();
								$qdpt1=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("".mysql_error());
								$dept1=mysql_fetch_array($qdpt1);
								
								//desk name
								//desk name
								$dsk1=$test['desk_id'];
								convert_marathi();
								$qsk1=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk1'") or die("".mysql_error());
								$desk1=mysql_fetch_array($qsk1);
								
								echo "<tr class='gradeX'>
									<td class='center'>".$test['ltr_inword_no']."<br>".$receive_dt."</td>
									<td class='center'>".$dept1['dept_nm']."<br>".$test['dpt_inword_no']."<br>".$dept_rec_date."</td>";
									if($test['desk_id']=='' || $test['desk_id']=='0')
									{
										echo "<td class='center'><font color='red'>डेस्क लावणे बाकी </font></td>";
									}
									else if($test['desk_ltr_inword_no']=='' || $test['desk_ltr_inword_no']=='0')
									{
										echo "<td class='center'><font color='red'>".$desk1['desk_nm']."<br>"."डेस्कने स्वीकारणे बाकी "."</font></td>";
									}
									else
									{
										echo "<td class='center'>".$desk1['desk_nm']."<br>".$test['desk_ltr_inword_no']."<br>".$desk_ltr_rec_dt."</td>";
									}
									echo "<td class='center'>".$test['ref_no']."<br>".$refdt."</td>
									<td class='center'>".$test['subject']."</font></td>
									<td class='center'>".$test['sender_name']."</font></td>";
									
									
									
									if($test['action_taken']=='' ||$test['action_taken']==0)
									{
										echo"<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
									}
									else if($test['ltr_status']=='' ||$test['ltr_status']==0)
									{
										echo"<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
									}
									else
									{
										echo"<td class='center'>".$test['action_taken']."</td>";
									}
										echo "</tr>";

						}
						echo"</tbody></table>";
				
				
				
				echo "<div id='divToPrint' style='display:none;'>
								<center><table id='export' border='1px' style='margin-left:50px;'>
								<tr><td colspan='7'><center> ".$deptnm['dept_nm']." ने स्वीकृत परंतु कार्यवाही न केलेल्या पत्राचे रिपोर्ट   <br>दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
							
							echo ' <center><h2>पोलीस अधिक्षक <br> कार्यालय <br> जि.रायगड<h2></center>';
								
						if($date123==''&& $date223=='' && $dt_type=='')
							{
								$id = $date1;
								$id1= $date2; 
								
								//not assigned to desk OR assigned to desk but approval is pending
								$qry3=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.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 de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
								WHERE t.returned_choice='' 
								AND t.dept_id_from='$deptid' 
								AND (t.status='approve')
								AND (
										(t.desk_id='') OR 
										(t.desk_id='0') OR 
										(t.desk_id!='0' AND t.desk_approval='pending')
									)
								") OR die("aaaa".mysql_error());
								
								//desk accepted but not taken any action
								$qry4=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.returned_choice=''
								AND t.dept_id_from='$deptid' 
								AND de.ltr_approval='Approve' 
								AND de.desk_id_from=t.desk_id 
								AND  (de.ltr_status='' OR de.ltr_status='closed')") OR die("abxxba".mysql_error());
								
								//returned to dept
								$qry5=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.returned_choice='' 
								AND t.ltr_id=i.ltr_id 
								AND t.dept_id_from='$deptid'  
								AND t.status='pending' ") OR die("abxxba".mysql_error());
							}
						else if($date123!=''&& $date223!='' && $dt_type==1)
							{
								$id = $date1;
								$id1= $date2; 
								$qry3=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.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 de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
								WHERE t.returned_choice='' 
								AND t.dept_id_from='$deptid' 
								AND (t.status='approve')
								AND (
										(t.desk_id='') OR 
										(t.desk_id='0') OR 
										(t.desk_id!='0' AND t.desk_approval='pending')
									)
								AND (i.receive_dt BETWEEN '$date1' AND '$date2')") OR die("xaaaa".mysql_error());
							
								$qry4=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.returned_choice=''
								AND t.dept_id_from='$deptid' 
								AND de.ltr_approval='Approve' 
								AND de.desk_id_from=t.desk_id 
								AND  (de.ltr_status='' OR de.ltr_status='closed')
								AND (i.receive_dt BETWEEN '$date1' AND '$date2')") OR die("yaaaa".mysql_error());
								
								$qry5=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.returned_choice='' 
								AND t.ltr_id=i.ltr_id 
								AND t.dept_id_from='$deptid'  
								AND t.status='pending'
								AND (i.receive_dt BETWEEN '$date1' AND '$date2')") OR die("yaaaa".mysql_error());
							}
							
							else if($date123!=''&& $date223!='' && $dt_type==2)
							{
								$id = $date1;
								$id1= $date2; 
								$qry3=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.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 de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
								WHERE t.returned_choice='' 
								AND t.dept_id_from='$deptid' 
								AND (t.status='approve')
								AND (
										(t.desk_id='') OR 
										(t.desk_id='0') OR 
										(t.desk_id!='0' AND t.desk_approval='pending')
									)
								AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aaaa".mysql_error());
							
								$qry4=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.returned_choice=''
								AND t.dept_id_from='$deptid' 
								AND de.ltr_approval='Approve' 
								AND de.desk_id_from=t.desk_id 
								AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aaxx".mysql_error());
								
								$qry5=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.returned_choice='' 
								AND t.ltr_id=i.ltr_id 
								AND t.dept_id_from='$deptid'  
								AND t.status='pending'
								AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aaxx".mysql_error());
							}
							
							else if($date123!=''&& $date223!='' && $dt_type==3)
							{
								$id = $date1;
								$id1= $date2; 
								$qry3=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.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 de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
								WHERE t.returned_choice='' 
								AND t.dept_id_from='$deptid' 
								AND (t.status='approve')
								AND (
										(t.desk_id='') OR 
										(t.desk_id='0') OR 
										(t.desk_id!='0' AND t.desk_approval='pending')
									)
								AND (de.desk_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aaaa".mysql_error());
							
								$qry4=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.returned_choice=''
								AND t.dept_id_from='$deptid' 
								AND de.ltr_approval='Approve' 
								AND de.desk_id_from=t.desk_id 
								AND (de.desk_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aaaa".mysql_error());
								
								$qry5=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.returned_choice='' 
								AND t.ltr_id=i.ltr_id 
								AND t.dept_id_from='$deptid'  
								AND t.status='pending'
								AND (de.desk_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aaaa".mysql_error());
							}
						echo "<tr>
								<th>पोलीस अधिक्षक <br> कार्यालय <br> आवक क्रमांक <br>आवक_दिनांक</th>
								<th>विभागीय आवक क्र.<br>आवक_दिनांक</th>
								<th>डेस्क आवक क्र. <br>आवक_दिनांक</th>
								<th>संदर्भ_क्रमांक <br>संदर्भ दि. </th>
								<th>विषय</th>
								<th>कोणाकडून <br>प्राप्त_झाला</th>
								<th>केलेली कार्यवाही</th>
								</tr>";
						while($test = mysql_fetch_array($qry3))
						{
								$desk_ltr_rec_dt 	= date('d-m-Y',strtotime($test['sent_to_desk_dt']));
								$dept_rec_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
								$receive_dt		= date('d-m-Y',strtotime($test['receive_dt']));
								$refdt		= date('d-m-Y',strtotime($test['ref_dt']));
								$update_date 		= date('d-m-Y',strtotime($test['update_date']));
								$dispose_date 		= date('d-m-Y',strtotime($test['dispatched_dt']));
								$deskid=$test['desk_id'];
								
								//dept name
								$depti=$test['dept_id_from'];
								convert_marathi();
								$qdpt1=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("".mysql_error());
								$dept1=mysql_fetch_array($qdpt1);
								
								//desk nm
								$dsk1=$test['desk_id'];
								convert_marathi();
								$qsk1=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk1'") or die("".mysql_error());
								$desk1=mysql_fetch_array($qsk1);
								
								echo "<tr class='gradeX'>
									<td class='center'>".$test['ltr_inword_no']."<br>".$receive_dt."</td>
									<td class='center'>".$dept1['dept_nm']."<br>".$test['dpt_inword_no']."<br>".$dept_rec_date."</td>";
									if($test['desk_id']=='' || $test['desk_id']=='0')
									{
										echo "<td class='center'>डेस्क लावणे बाकी </td>";
									}
									else if($test['desk_ltr_inword_no']=='' || $test['desk_ltr_inword_no']=='0')
									{
										echo "<td class='center'>".$desk1['desk_nm']."<br>"."डेस्कने स्वीकारणे बाकी "."</td>";
									}
									else
									{
										echo "<td class='center'>".$desk1['desk_nm']."<br>".$test['desk_ltr_inword_no']."<br>".$desk_ltr_rec_dt."</td>";
									}
									echo "<td class='center'>".$test['ref_no']."<br>".$refdt."</td>
									<td class='center'>".$test['subject']."</font></td>
									<td class='center'>".$test['sender_name']."</font></td>";
									if($test['action_taken']=='' ||$test['action_taken']==0)
									{
										echo"<td class='center'>"."कार्यवाही करणे बाकी "."</td>";
									}
									else if($test['ltr_status']=='' ||$test['ltr_status']==0)
									{
										echo"<td class='center'>"."कार्यवाही करणे बाकी "."</td>";
									}
									else
									{
										echo"<td class='center'>".$test['action_taken']."</td>";
									}
										echo "</tr>";

						}
						while($test = mysql_fetch_array($qry4))
						{
							$desk_ltr_rec_dt 	= date('d-m-Y',strtotime($test['sent_to_desk_dt']));
							$dept_rec_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
							$receive_dt		= date('d-m-Y',strtotime($test['receive_dt']));
							$refdt		= date('d-m-Y',strtotime($test['ref_dt']));
							$update_date 		= date('d-m-Y',strtotime($test['update_date']));
							$dispose_date 		= date('d-m-Y',strtotime($test['dispatched_dt']));
							$deskid=$test['desk_id'];
							
							//dept name
							$depti=$test['dept_id_from'];
							convert_marathi();
							$qdpt1=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("".mysql_error());
							$dept1=mysql_fetch_array($qdpt1);
							
							//desk name
							$dsk1=$test['desk_id_from'];
							convert_marathi();
							$qsk1=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk1'") or die("".mysql_error());
							$desk1=mysql_fetch_array($qsk1);
								
							echo "<tr class='gradeX'>
								<td class='center'>".$test['ltr_inword_no']."<br>".$receive_dt."</td>
								<td class='center'>".$dept1['dept_nm']."<br>".$test['dpt_inword_no']."<br>".$dept_rec_date."</td>";
								if($test['desk_id']=='' || $test['desk_id']=='0')
								{
									echo "<td class='center'>डेस्क लावणे बाकी </td>";
								}
								else if($test['desk_ltr_inword_no']=='' || $test['desk_ltr_inword_no']=='0')
								{
									echo "<td class='center'>"."डेस्कने स्वीकारणे बाकी "."</td>";
								}
								else
								{
									echo "<td class='center'>".$desk1['desk_nm']."<br>".$test['desk_ltr_inword_no']."<br>".$desk_ltr_rec_dt."</td>";
								}
								echo "<td class='center'>".$test['ref_no']."<br>".$refdt."</td>
								<td class='center'>".$test['subject']."</font></td>
								<td class='center'>".$test['sender_name']."</font></td>";
								if($test['action_taken']=='' ||$test['action_taken']==0)
								{
									echo"<td class='center'>"."कार्यवाही करणे बाकी "."</td>";
								}
								else if($test['ltr_status']=='' ||$test['ltr_status']==0)
								{
									echo"<td class='center'>"."कार्यवाही करणे बाकी "."</td>";
								}
								else
								{
									echo"<td class='center'>".$test['action_taken']."</td>";
								}
							
											
										echo "</tr>";
						}
						while($test = mysql_fetch_array($qry5))
						{
								$desk_ltr_rec_dt 	= date('d-m-Y',strtotime($test['sent_to_desk_dt']));
								$dept_rec_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
								$receive_dt		= date('d-m-Y',strtotime($test['receive_dt']));
								$refdt		= date('d-m-Y',strtotime($test['ref_dt']));
								$update_date 		= date('d-m-Y',strtotime($test['update_date']));
								$dispose_date 		= date('d-m-Y',strtotime($test['dispatched_dt']));
								$deskid=$test['desk_id'];
								
								//dept name
								$depti=$test['dept_id_from'];
								convert_marathi();
								$qdpt1=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("".mysql_error());
								$dept1=mysql_fetch_array($qdpt1);
								
								//desk name
								//desk name
								$dsk1=$test['desk_id'];
								convert_marathi();
								$qsk1=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk1'") or die("".mysql_error());
								$desk1=mysql_fetch_array($qsk1);
								
								echo "<tr class='gradeX'>
									<td class='center'>".$test['ltr_inword_no']."<br>".$receive_dt."</td>
									<td class='center'>".$dept1['dept_nm']."<br>".$test['dpt_inword_no']."<br>".$dept_rec_date."</td>";
									if($test['desk_id']=='' || $test['desk_id']=='0')
									{
										echo "<td class='center'>डेस्क लावणे बाकी </td>";
									}
									else if($test['desk_ltr_inword_no']=='' || $test['desk_ltr_inword_no']=='0')
									{
										echo "<td class='center'>".$desk1['desk_nm']."<br>"."डेस्कने स्वीकारणे बाकी "."</td>";
									}
									else
									{
										echo "<td class='center'>".$desk1['desk_nm']."<br>".$test['desk_ltr_inword_no']."<br>".$desk_ltr_rec_dt."</td>";
									}
									echo "<td class='center'>".$test['ref_no']."<br>".$refdt."</td>
									<td class='center'>".$test['subject']."</font></td>
									<td class='center'>".$test['sender_name']."</font></td>";
									
									
									
									if($test['action_taken']=='' ||$test['action_taken']==0)
									{
										echo"<td class='center'>"."कार्यवाही करणे बाकी "."</td>";
									}
									else if($test['ltr_status']=='' ||$test['ltr_status']==0)
									{
										echo"<td class='center'>"."कार्यवाही करणे बाकी "."</td>";
									}
									else
									{
										echo"<td class='center'>".$test['action_taken']."</td>";
									}
										echo "</tr>";

						}
				echo"</table></center></div>";
				} //if($flag=='')
					
	else if($flag=='n')
	{
		?>		
			
			 <h4 class="widgettitle"><?php echo $deptnm['dept_nm'];?>ने स्वीकृत परंतु कार्यवाही न केलेल्या पत्राचे रिपोर्ट   <h4>
						<form name="sadyasthiti" action="" method="post">
						<div align="center"><br><table align="center" cellpadding="2" cellspacing="0" class='myClass'>
						<table>
							<tr>
							<td><label>तारखेचा प्रकार निवडा  : </label></td>
								<td><span class="field unicode" lang="mr">
										<select name="datetype">
											<option value="">तारखेचा प्रकार निवडा</option>  
											<option value="1">आवक दिनांक</option>
											<option value="2">विभागीय आवक दिनांक</option>
										</select>
									</span>
								</td>
								<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>
				</form>
				<form>
						

						<?php
						$dt_type=$_POST['datetype'];
						//echo "date".$dt_type;
						$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=='' && $dt_type=='')
							{
								echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
								$id = $date1;
								$id1= $date2; 
								$qry3=mysql_query("SELECT DISTINCT t.action_taken, i.ltr_type, 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, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, t.ltr_category, t.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i 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='$deptid' 
								AND t.status='approve' 
								AND (t.ltr_category='' OR t.action_taken='')") OR die("aaaa".mysql_error());
								
							}
						else if($date123!=''&& $date223!='' && $dt_type==1)
							{
								echo '<br><center><h4> <font color="red">आवक दिनांकनुसार संदर्भ </font></h4></center><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								$qry3=mysql_query("SELECT DISTINCT t.action_taken, i.ltr_type, 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, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, t.ltr_category, t.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i 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='$deptid' 
								AND t.status='approve' 
								AND (t.ltr_category='' OR t.action_taken='') AND (i.receive_dt BETWEEN '$date1' AND '$date2')") OR die("xaaaa".mysql_error());
							}
							
							else if($date123!=''&& $date223!='' && $dt_type==2)
							{
								echo '<br><center><h4> <font color="red">विभागीय आवक दिनांकनुसार संदर्भ</font></h4></center><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								$qry3=mysql_query("SELECT DISTINCT t.action_taken, i.ltr_type, 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, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, t.ltr_category, t.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i 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='$deptid' 
								AND t.status='approve' 
								AND (t.ltr_category='' OR t.action_taken='')AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aaaa".mysql_error());
							}
								
						echo"  <br><br><table id='dyntable' class='table table-bordered'>
								<thead>
								<tr>
									<th class='head1 center'>पोलीस अधिक्षक <br> कार्यालय <br> आवक क्रमांक <br>आवक_दिनांक</th>
									<th class='head0 center'>विभागीय आवक क्र.<br>आवक_दिनांक</th>
									<th class='head0 center'>संदर्भ_क्रमांक <br>संदर्भ दि. </th>
									<th class='head0 center'>विषय</th>
									<th class='head1 center'>कोणाकडून <br>प्राप्त_झाला</th>
									<th class='head0 center'>केलेली कार्यवाही</th>	
								</tr>
								</thead>
							<tbody>";
						while($test = mysql_fetch_array($qry3))
						{
								$dept_rec_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
								$receive_dt		= date('d-m-Y',strtotime($test['receive_dt']));
								$refdt		= date('d-m-Y',strtotime($test['ref_dt']));
								$update_date 		= date('d-m-Y',strtotime($test['update_date']));
								$dispose_date 		= date('d-m-Y',strtotime($test['dispatched_date']));
								
								echo "<tr class='gradeX'>
									<td class='center'>".$test['ltr_inword_no']."<br>".$receive_dt."</td>
									<td class='center'>".$test['dpt_inword_no']."<br>".$dept_rec_date."</td>";
								
									echo "<td class='center'>".$test['ref_no']."<br>".$refdt."</td>
									<td class='center'>".$test['subject']."</font></td>
									<td class='center'>".$test['sender_name']."</font></td>";
									if($test['action_taken']=='' ||$test['action_taken']==0)
									{
										echo"<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
									}
									else if($test['ltr_status']=='' ||$test['ltr_status']==0)
									{
										echo"<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
									}
									else
									{
										echo"<td class='center'>".$test['action_taken']."</td>";
									}
										echo "</tr>";

						}
						echo"</tbody></table>";
				
				
				
				echo "<div id='divToPrint' style='display:none;'>
								<center><table id='export' border='1px' style='margin-left:50px;'>
								<tr><td colspan='7'><center> ".$deptnm['dept_nm']." ने स्वीकृत परंतु कार्यवाही न केलेल्या पत्राचे रिपोर्ट   <br>दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
								
								echo ' <center><h2>पोलीस अधिक्षक <br> कार्यालय <br> जि.रायगड<h2></center>';
								
						if($date123==''&& $date223=='' && $dt_type=='')
							{
								//echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								$qry3=mysql_query("SELECT DISTINCT t.action_taken, i.ltr_type, 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, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, t.ltr_category, t.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i 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='$deptid' 
								AND t.status='approve' 
								AND (t.ltr_category='' OR t.action_taken='')") OR die("aaaa".mysql_error());
							}
						else if($date123!=''&& $date223!='' && $dt_type==1)
							{
								//echo '<br><center><h4> <font color="red">आवक दिनांकनुसार संदर्भ </font></h4></center><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								$qry3=mysql_query("SELECT DISTINCT t.action_taken, i.ltr_type, 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, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, t.ltr_category, t.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i 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='$deptid' 
								AND t.status='approve' 
								AND (t.ltr_category='' OR t.action_taken='') AND (i.receive_dt BETWEEN '$date1' AND '$date2')") OR die("aaaa".mysql_error());
							}
							
							else if($date123!=''&& $date223!='' && $dt_type==2)
							{
								//echo '<br><center><h4> <font color="red">विभागीय आवक दिनांकनुसार संदर्भ</font></h4></center><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								$qry3=mysql_query("SELECT DISTINCT t.action_taken, i.ltr_type, 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, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, t.ltr_category, t.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i 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='$deptid' 
								AND t.status='approve' 
								AND (t.ltr_category='' OR t.action_taken='') AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aaaa".mysql_error());
								
							}
							
							echo "<tr>
								<th>पोलीस अधिक्षक <br> कार्यालय <br> आवक क्रमांक <br>आवक_दिनांक</th>
								<th>विभागीय आवक क्र.<br>आवक_दिनांक</th>
								<th>संदर्भ_क्रमांक <br>संदर्भ दि. </th>
								<th>विषय</th>
								<th>कोणाकडून <br>प्राप्त_झाला</th>
								<th>केलेली कार्यवाही</th>
								</tr>";
						while($test = mysql_fetch_array($qry3))
						{
								$dept_rec_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
								$receive_dt		= date('d-m-Y',strtotime($test['receive_dt']));
								$refdt		= date('d-m-Y',strtotime($test['ref_dt']));
								$update_date 		= date('d-m-Y',strtotime($test['update_date']));
								$dispose_date 		= date('d-m-Y',strtotime($test['dispatched_date']));
								$deskid=$test['desk_id'];
			
								echo "<tr>
									<td style='text-align:center;'>".$test['ltr_inword_no']."<br>".$receive_dt."</td>
									<td style='text-align:center;'>".$test['dpt_inword_no']."<br>".$dept_rec_date."</td>";
									echo "<td style='text-align:center;'>".$test['ref_no']."<br>".$refdt."</td>
									<td style='text-align:center;'>".$test['subject']."</font></td>
									<td style='text-align:center;'>".$test['sender_name']."</font></td>";
									if($test['action_taken']=='' ||$test['action_taken']==0)
									{
										echo"<td style='text-align:center;'>"."कार्यवाही करणे बाकी "."</td>";
									}
									else if($test['ltr_status']=='' ||$test['ltr_status']==0)
									{
										echo"<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
									}
									else
									{
										echo"<td style='text-align:center;'>".$test['action_taken']."</td>";
									}
									
									echo "</tr>";

						}
						echo"</table></center></div>";
			} //else if($flag=='n')
				
		} // else if($no==4)
	###################	End Of Accepted But Not Worked Letter report tapal user    #############################


	#################################### Total Letter report tapal user ############################				
				else if($no==5)
				{
				
					if($flag=='')
					{
					?>		
			
			 <h4 class="widgettitle"><?php echo $deptnm['dept_nm'];?>चे एकूण पत्राचे डेस्क नुसार रिपोर्ट्स  <h4>
			 
						<form name="sadyasthiti" action="" method="post">
						<div align="center"><br><table align="center" cellpadding="2" cellspacing="0" class='myClass'>
						<table>
							<tr>
							<td><label>तारखेचा प्रकार निवडा  : </label></td>
								<td><span class="field unicode" lang="mr">
										<select name="datetype">
											<option value="">तारखेचा प्रकार निवडा</option>  
											<option value="1">आवक दिनांक</option>
											<option value="2">विभागीय आवक दिनांक</option>
											<option value="3">डेस्क आवक दिनांक</option>
											<option value="4">अपडेट/जावक दिनांक </option>
										</select>
									</span>
								</td>
								<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>
				</form>
				<form>
						

						<?php
						$dt_type=$_POST['datetype'];
						//echo "".$dt_type;
						$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));
						$id = $date1;
						$id1= $date2;
						
						if($date123==''&& $date223=='' && $dt_type=='')
							{	

								echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2;
								
								//not accepted by dept
								$qry3=mysql_query("Select * FROM  incoming_letters_transaction i, login l
								WHERE i.dept_id!='0' 
								AND (i.status='pending') 
								AND l.login_id='$username' 
								AND i.dept_id='$deptid'") OR die("aaaa".mysql_error());
								
								//accpeted by dept but deskid=0 or desk_apprval=pending
								$qry4=mysql_query("SELECT DISTINCT i.ltr_type, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.returned_choice, t.dpt_inword_no, t.desk_id,t.desk_approval, t.dept_id_from, i.subject, 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.sent_to_desk_dt
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								WHERE t.dept_id_from='$deptid' 
								AND (t.desk_id='0' OR t.desk_approval='pending')") OR die("aabbhhaa".mysql_error());
								
								//accpeted by desk and ltrstatus!=closed
								$qry5=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.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, de. 	update_date, de.dispatched_dt, de.ltr_approval,di.dept_id_to, di.addressed_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND de.ltr_status!='closed' 
								AND de.ltr_approval!='transferred_todesk' ") OR die("aabbhhaa".mysql_error());
								
								
							}
						else if($date123!=''&& $date223!='' && $dt_type==1)
							{
								echo '<br><center><h4> <font color="red">आवक दिनांकनुसार संदर्भ </font></h4></center><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								$qry3=mysql_query("Select * FROM  incoming_letters_transaction, login WHERE incoming_letters_transaction.dept_id!='0' AND (incoming_letters_transaction.status='pending') AND login.login_id='$username' AND incoming_letters_transaction.dept_id='$deptid' AND (incoming_letters_transaction.receive_dt BETWEEN '$date1' AND '$date2')") OR die("aaaa".mysql_error());
							
								$qry4=mysql_query("SELECT DISTINCT i.ltr_type, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.returned_choice, t.dpt_inword_no, t.desk_id,t.desk_approval, t.dept_id_from, i.subject, 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.sent_to_desk_dt
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								WHERE t.dept_id_from='$deptid' 
								AND (t.desk_id='0' OR t.desk_approval='pending') AND (i.receive_dt BETWEEN '$date1' AND '$date2')")OR die("agg".mysql_error());
								
								$qry5=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt,t.returned_choice, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to,di.dept_id_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND de.ltr_status!='closed' AND de.ltr_approval!='transferred_todesk'
								AND (i.receive_dt BETWEEN '$date1' AND '$date2')") OR die("aabbhhaa".mysql_error());
							}
							
							else if($date123!=''&& $date223!='' && $dt_type==2)
							{
								echo '<br><center><h4> <font color="red">विभागीय आवक दिनांकनुसार संदर्भ</font></h4></center><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								$qry3=mysql_query("Select * FROM  incoming_letters_transaction, login WHERE incoming_letters_transaction.dept_id!='0' AND (incoming_letters_transaction.status='pending') AND login.login_id='$username' AND incoming_letters_transaction.dept_id='$deptid'") OR die("aaaa".mysql_error());
							
								$qry4=mysql_query("SELECT DISTINCT i.ltr_type, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.returned_choice, t.dpt_inword_no, t.desk_id,t.desk_approval, t.dept_id_from, i.subject, 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.sent_to_desk_dt
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								WHERE t.dept_id_from='$deptid' 
								AND (t.desk_id='0' OR t.desk_approval='pending') AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aaxx".mysql_error());
								
								$qry5=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt,t.returned_choice, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt,di.dept_id_to, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND de.ltr_status!='closed' AND de.ltr_approval!='transferred_todesk'
								AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aabbhhaa".mysql_error());
							}
							
							else if($date123!=''&& $date223!='' && $dt_type==3)
							{
								echo '<br><center><h4> <font color="red">डेस्क आवक दिनांकनुसार संदर्भ</font></h4></center><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								$qry3=mysql_query("Select * FROM  incoming_letters_transaction, login WHERE incoming_letters_transaction.dept_id!='0' AND (incoming_letters_transaction.status='pending') AND login.login_id='$username' AND incoming_letters_transaction.dept_id='$deptid'") OR die("aaaa".mysql_error());
							
								$qry4=mysql_query("SELECT DISTINCT i.ltr_type, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.returned_choice, t.dpt_inword_no, t.desk_id,t.desk_approval, t.dept_id_from, i.subject, 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.sent_to_desk_dt
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								WHERE t.dept_id_from='$deptid' 
								AND (t.desk_id='0' OR t.desk_approval='pending') AND (de.desk_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("mmm".mysql_error());
								
								$qry5=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt,t.returned_choice, t.dpt_inword_no, t.desk_id, t.dept_id_from,di.dept_id_to, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND de.ltr_status!='closed' AND de.ltr_approval!='transferred_todesk'
								AND (de.desk_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aabbhhaa".mysql_error());
							}
							
							else if($date123!=''&& $date223!='' && $dt_type==4)
							{
								echo '<br><center><h4> <font color="red">अपडेट/जावक दिनांकनुसार संदर्भ</font></h4></center><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								
								$qry3=mysql_query("Select * FROM  incoming_letters_transaction, login WHERE incoming_letters_transaction.dept_id!='0' AND (incoming_letters_transaction.status='pending') AND login.login_id='$username' AND incoming_letters_transaction.dept_id='$deptid'") OR die("aaaa".mysql_error());
							
								$qry4=mysql_query("SELECT DISTINCT i.ltr_type, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.returned_choice, t.dpt_inword_no, t.desk_id,t.desk_approval, t.dept_id_from, i.subject, 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.sent_to_desk_dt
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								WHERE t.dept_id_from='$deptid' 
								AND (t.desk_id='0' OR t.desk_approval='pending') AND ((de.update_date BETWEEN '$date1' AND '$date2') OR (de.dispatched_dt BETWEEN '$date1' AND '$date2')) ") OR die("avc".mysql_error());
								
								$qry5=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt,t.returned_choice, t.dpt_inword_no, t.desk_id, t.dept_id_from,di.dept_id_to, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND de.ltr_status!='closed' AND de.ltr_approval!='transferred_todesk'
								AND ((de.update_date BETWEEN '$date1' AND '$date2') OR (de.dispatched_dt BETWEEN '$date1' AND '$date2'))") OR die("aabbhhaa".mysql_error());
							}
						echo"  <br><br><table id='dyntable' class='table table-bordered'>
								<thead>
								<tr>
									<th class='head1 center'>पोलीस अधिक्षक <br> कार्यालय <br> आवक क्रमांक <br>आवक_दिनांक</th>
									<th class='head0 center'>विभागीय आवक क्र.<br>आवक_दिनांक</th>
									<th class='head1 center'>डेस्कचा आवक क्र. <br>आवक_दिनांक</th>
									<th class='head0 center'>संदर्भ_क्रमांक <br>संदर्भ दि. </th>
									<th class='head1 center'>संदर्भ_प्रकार</th>
									<th class='head0 center'>विषय</th>
									<th class='head1 center'>कोणाकडून <br>प्राप्त_झाला</th>
									<th class='head0 center'>केलेली_कार्यवाही</th>
									<th class='head0 center'>पत्राची_स्थिती </th>
									<th class='head1 center'>विभागीय <br>जावक_दिनांक</th>	
								</tr>
								</thead>
							<tbody>";
						
						while($test = mysql_fetch_array($qry3))
						{		
								$ltrinward=$test['ltr_inword_no'];	
								$dept_rec_date 	= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
								$receive_dt	= date('d-m-Y',strtotime($test['receive_dt']));
								$refdt	= date('d-m-Y',strtotime($test['ref_dt']));
								$m=$test['ltr_type'];
								$update_date 		= date('d-m-Y',strtotime($test['update_date']));
								$dispose_date 		= date('d-m-Y',strtotime($test['dispatched_dt']));
								$deskid=$test['desk_id'];
							echo "
							<tr class='gradeX'>
							<td class='center'>".$ltrinward."<br>".$receive_dt."</td>";
							if($test['dpt_inword_no']=='')
							{
								echo "<td class='center'><font color='red'>"." विभागाने स्वीकारणे बाकी" ."</font></td>";
							
							}
							else
							{
								echo "<td class='center'>".$test['dpt_inword_no']."<br>".$dept_rec_date ."</td>";
							}
							
							if($test['desk_id']=='' || $test['desk_id']==0)
							{
								echo "<td class='center'><font color='red'>"."डेस्क लावणे बाकी "."</font></td>";
							}
							else if($test['desk_ltr_inword_no']=='' || $test['desk_ltr_inword_no']=='0')
							{
								echo "<td class='center'><font color='red'>"."डेस्कने स्वीकारणे बाकी "."</font></td>";
							}
							else
							{
								echo "<td class='center'>".$test['desk_ltr_inword_no']."<br>".$deskrec_dt."</td>";
							}
							
							echo "<td class='center'>".$test['ref_no']."<br>".$refdt."</td>";
							$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
							$s=mysql_fetch_array($ltrtype);
							echo "<td class='center'>".$s['sandharbh_nm']."</td>
							<td class='center'>".$test['subject']."</td>
							<td class='center'>".$test['sender_name']."</td>";
							////////////////////////////////////////////////////////////////////////
							if($test['ltr_status']=='' ||$test['ltr_status']=='NULL')
							{
								echo"<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
							}
							else
							{
								echo"<td class='center'>".$test['action_taken']."</td>";
							}
							/////////////////////////////////////////////////////////////////////
							if($test['ltr_status']=='' || $test['ltr_status']=='NULL')
							{
								echo "<td class='center'><font color='red'> कार्यवाही करणे बाकी </font></td>";	
							}
							else
							{
								echo "<td class='center'>". $test['ltr_status'] ."</td>";
							}
							////////////////////////////////////////////////////////////////////
							if ($test['ltr_status']=='updated')
							{
								echo "<td class='center'>".$update_date."</td>";
							}
							else if($test1['ltr_status']=='dispatched')
							{
								echo "<td class='center'>".$dispose_date."</td>";
							}
							else 
							{
								echo "<td class='center'><font color='red'> कार्यवाही करणे बाकी </font></td>";
							}
							echo "</tr>";
						}
						
						while($test1 = mysql_fetch_array($qry4))
						{		
								$ltrinward=$test1['ltr_inword_no'];
								$desk_ltr_rec_dt = date('d-m-Y',strtotime($test1['desk_ltr_rec_dt']));
								$dept_rec_date 	= date('d-m-Y',strtotime($test1['dpt_ltr_rec_dt']));
								$receive_dt	= date('d-m-Y',strtotime($test1['receive_dt']));
								$refdt	= date('d-m-Y',strtotime($test1['ref_dt']));
								$deskrec_dt	= date('d-m-Y',strtotime($test1['sent_to_desk_dt']));
								$update_date 		= date('d-m-Y',strtotime($test1['update_date']));
								$dispose_date 		= date('d-m-Y',strtotime($test1['dispatched_dt']));
								$m=$test1['ltr_type'];
								$deskid=$test1['desk_id'];
								
								$dsk1=$test1['desk_id_from'];
								//echo $dsk."aaaaaaaaa";
								convert_marathi();
								$qsk1=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk1'") or die("".mysql_error());
								$desk1=mysql_fetch_array($qsk1);
								
								$dsk2=$test1['desk_id'];
								//echo $dsk."aaaaaaaaa";
								convert_marathi();
								$qsk2=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk2'") or die("".mysql_error());
								$desk2=mysql_fetch_array($qsk2);
								
								//closed lettr
								$ltrinward=$test1['ltr_inword_no'];
								$deskidfrom=$test1['desk_id_from'];
								if($test1['ltr_status']=='closed')
								{
									$query=mysql_query("select rtn_to_dsk from  returned_from_desk 
														where ltr_inword_no='$ltrinward'
														AND returned_from='$deskidfrom' ");		
									$result=mysql_fetch_array($query);
									//echo $result['rtn_to_dsk']."<br>";
								}
								
							echo "
							<tr class='gradeX'>
							<td class='center'>".$ltrinward."<br>".$receive_dt."</td>";
							if($test1['dpt_inword_no']=='')
							{
								echo "<td class='center'><font color='red'>"." विभागाने स्वीकारणे बाकी" ."</font></td>";
							
							}
							else
							{
								echo "<td class='center'>".$test1['dpt_inword_no']."<br>".$dept_rec_date ."</td>";
							}
							//////////////////////////////////////////////////////////////////
							if($test1['returned_choice']!='')
							{
								echo "<td class='center'>Letter Returned To<br> Tapal </td>";
							}
							else if( $test1['desk_id']=='' || $test1['desk_id']==0 )
							{
								echo "<td class='center'><font color='red'>"."डेस्क लावणे बाकी "."</font></td>";
							}
							else if($test1['desk_ltr_inword_no']=='' || $test1['desk_ltr_inword_no']=='0')
							{
								echo "<td class='center'><font color='red'>".$desk2['desk_nm']."<br>"."डेस्कने स्वीकारणे बाकी "."</font></td>";
							}
							else
							{
								echo "<td class='center'>".$desk1['desk_nm']."<br>".$test1['desk_ltr_inword_no']."<br>".$deskrec_dt."</td>";
							}
							///////////////////////////////////////////////////////////////////////
							echo "<td class='center'>".$test1['ref_no']."<br>".$refdt."</td>";
							$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
							$s=mysql_fetch_array($ltrtype);
							echo "<td class='center'>".$s['sandharbh_nm']."</td>
							<td class='center'>".$test1['subject']."</td>
							<td class='center'>".$test1['sender_name']."</td>";
							///////////////////////// Action taken //////////////////////////////
							if($result['rtn_to_dsk']=='')
							{
								$returnto=$deptnm['dept_nm'];
									
							}
							else
							{
								$dsk_nm=$result['rtn_to_dsk'];
								$qw=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk_nm'") or die("".mysql_error());
								$de=mysql_fetch_array($qw);
								$returnto=$de['desk_nm'];
							}
							if($test1['returned_choice']!='')
							{
								echo "<td class='center'>-- </td>";
							}	
							else if($test1['ltr_status']=='' ||$test1['ltr_status']=='NULL')
							{
								echo"<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
							}
							else if($test1['ltr_status']=='closed' )
							{
								echo"<td class='center'>Letter Returned To <br>".$returnto."</td>";
							}
							else
							{
								echo"<td class='center'>".$test1['action_taken']."</td>";
							}
							///////////////////////////////////////////////////////////////////////
							if($test1['returned_choice']!='')
							{
								echo "<td class='center'>Letter Returned To<br> Tapal </td>";
							}	
							else if($test1['ltr_status']=='' || $test1['ltr_status']=='NULL')
							{
								echo "<td class='center'><font color='red'> कार्यवाही करणे बाकी </font></td>";	
							}
							else if($test1['ltr_approval']=='transferred')
							{
								$dpt_to=$test1['dept_id_to'];
								$q=mysql_query("SELECT dept_nm from department_master where dept_id='$dpt_to' ");
								$r=mysql_fetch_array($q);
								echo "<td class='center'>".$test1['ltr_approval']." to <br>".$r['dept_nm']."</td>";
							}
							else
							{
								echo "<td class='center'>". $test1['ltr_status'] ."</td>";
							}
							///////////////////////////////////////////////////////////////
							if($test1['returned_choice']!='')
							{
								echo "<td class='center'>-- </td>";
							}	
							else if ($test1['ltr_status']=='updated')
							{
								echo "<td class='center'>".$update_date."</td>";
							}
							else if($test1['ltr_status']=='dispatched')
							{
								echo "<td class='center'>".$dispose_date."</td>";
							}
							else if($test1['ltr_status']=='closed')
							{
								echo "<td class='center'>--</td>";
							}
							else 
							{
								echo "<td class='center'><font color='red'> कार्यवाही करणे बाकी </font></td>";
							}
											
										echo "</tr>";
						}	
						while($test1 = mysql_fetch_array($qry5))
						{		
								$ltrinward=$test1['ltr_inword_no'];
								$desk_ltr_rec_dt = date('d-m-Y',strtotime($test1['desk_ltr_rec_dt']));
								$dept_rec_date 	= date('d-m-Y',strtotime($test1['dpt_ltr_rec_dt']));
								$receive_dt	= date('d-m-Y',strtotime($test1['receive_dt']));
								$refdt	= date('d-m-Y',strtotime($test1['ref_dt']));
								$deskrec_dt	= date('d-m-Y',strtotime($test1['sent_to_desk_dt']));
								$update_date 		= date('d-m-Y',strtotime($test1['update_date']));
								$dispose_date 		= date('d-m-Y',strtotime($test1['dispatched_dt']));
								$m=$test1['ltr_type'];
								$deskid=$test1['desk_id'];
								
								$dsk1=$test1['desk_id_from'];
								//echo $dsk."aaaaaaaaa";
								convert_marathi();
								$qsk1=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk1'") or die("".mysql_error());
								$desk1=mysql_fetch_array($qsk1);
								
								$dsk2=$test1['desk_id'];
								//echo $dsk."aaaaaaaaa";
								convert_marathi();
								$qsk2=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk2'") or die("".mysql_error());
								$desk2=mysql_fetch_array($qsk2);
								
								//closed lettr
								$ltrinward=$test1['ltr_inword_no'];
								$deskidfrom=$test1['desk_id_from'];
								if($test1['ltr_status']=='closed')
								{
									$query=mysql_query("select rtn_to_dsk from  returned_from_desk 
														where ltr_inword_no='$ltrinward'
														AND returned_from='$deskidfrom' ");		
									$result=mysql_fetch_array($query);
									//echo $result['rtn_to_dsk']."<br>";
								}
								
							echo "
							<tr class='gradeX'>
							<td class='center'>".$ltrinward."<br>".$receive_dt."</td>";
							if($test1['dpt_inword_no']=='')
							{
								echo "<td class='center'><font color='red'>"." विभागाने स्वीकारणे बाकी" ."</font></td>";
							
							}
							else
							{
								echo "<td class='center'>".$test1['dpt_inword_no']."<br>".$dept_rec_date ."</td>";
							}
							//////////////////////////////////////////////////////////////////
							if($test1['desk_id']=='' || $test1['desk_id']==0)
							{
								echo "<td class='center'><font color='red'>"."डेस्क लावणे बाकी "."</font></td>";
							}
							else if($test1['desk_ltr_inword_no']=='' || $test1['desk_ltr_inword_no']=='0')
							{
								echo "<td class='center'><font color='red'>".$desk2['desk_nm']."<br>"."डेस्कने स्वीकारणे बाकी "."</font></td>";
							}
							else
							{
								echo "<td class='center'>".$desk1['desk_nm']."<br>".$test1['desk_ltr_inword_no']."<br>".$deskrec_dt."</td>";
							}
							///////////////////////////////////////////////////////////////////////
							echo "<td class='center'>".$test1['ref_no']."<br>".$refdt."</td>";
							$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
							$s=mysql_fetch_array($ltrtype);
							echo "<td class='center'>".$s['sandharbh_nm']."</td>
							<td class='center'>".$test1['subject']."</td>
							<td class='center'>".$test1['sender_name']."</td>";
							///////////////////////// Action taken //////////////////////////////
							if($result['rtn_to_dsk']=='')
							{
								$returnto=$deptnm['dept_nm'];
									
							}
							else
							{
								$dsk_nm=$result['rtn_to_dsk'];
								$qw=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk_nm'") or die("".mysql_error());
								$de=mysql_fetch_array($qw);
								$returnto=$de['desk_nm'];
							}
								
							if($test1['ltr_status']=='' ||$test1['ltr_status']=='NULL')
							{
								echo"<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
							}
							else if($test1['ltr_status']=='closed' )
							{
								echo"<td class='center'>Letter Returned To <br>".$returnto."</td>";
							}
							else
							{
								echo"<td class='center'>".$test1['action_taken']."</td>";
							}
							///////////////////////////////////////////////////////////////////////
							if($test1['ltr_status']=='' || $test1['ltr_status']=='NULL')
							{
								echo "<td class='center'><font color='red'> कार्यवाही करणे बाकी </font></td>";	
							}
							else if($test1['ltr_approval']=='transferred')
							{
								$dpt_to=$test1['dept_id_to'];
								$q=mysql_query("SELECT dept_nm from department_master where dept_id='$dpt_to' ");
								$r=mysql_fetch_array($q);
								echo "<td class='center'>".$test1['ltr_approval']." to <br>".$r['dept_nm']."</td>";
							}
							else
							{
								echo "<td class='center'>". $test1['ltr_status'] ."</td>";
							}
							///////////////////////////////////////////////////////////////
							if ($test1['ltr_status']=='updated')
							{
								echo "<td class='center'>".$update_date."</td>";
							}
							else if($test1['ltr_status']=='dispatched')
							{
								echo "<td class='center'>".$dispose_date."</td>";
							}
							else if($test1['ltr_status']=='closed')
							{
								echo "<td class='center'>--</td>";
							}
							else 
							{
								echo "<td class='center'><font color='red'> कार्यवाही करणे बाकी </font></td>";
							}
											
										echo "</tr>";
						}	   
					echo "</tbody></table>";	
						
							
					
						echo "<div id='divToPrint' style='display:none;'>
						<center><table id='export' border='1px' style='margin-left:50px;'>
							<tr><td colspan='10'><center> ".$deptnm['dept_nm']."चे एकूण पत्राचे डेस्क नुसार रिपोर्ट्स  <br>दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
							echo ' <center><h2>पोलीस अधिक्षक <br> कार्यालय <br> जि.रायगड<h2></center>';
						$id1= $date2;
						 
						if($date123==''&& $date223=='' && $dt_type=='')
							{	

								$id = $date1;
								$id1= $date2;
								
								//not accepted by dept
								$qry3=mysql_query("Select * FROM  incoming_letters_transaction i, login l
								WHERE i.dept_id!='0' 
								AND (i.status='pending') 
								AND l.login_id='$username' 
								AND i.dept_id='$deptid'") OR die("aaaa".mysql_error());
								
								//accpeted by dept but deskid=0 or desk_apprval=pending
								$qry4=mysql_query("SELECT DISTINCT i.ltr_type, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.returned_choice, t.dpt_inword_no, t.desk_id,t.desk_approval, t.dept_id_from, i.subject, 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.sent_to_desk_dt
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								WHERE t.dept_id_from='$deptid' 
								AND (t.desk_id='0' OR t.desk_approval='pending')") OR die("aabbhhaa".mysql_error());
								
								//accpeted by desk and ltrstatus!=closed
								$qry5=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.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, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status,di.dept_id_to, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND de.ltr_status!='closed' AND de.ltr_approval!='transferred_todesk' ") OR die("aabbhhaa".mysql_error());
								
								
							}
						else if($date123!=''&& $date223!='' && $dt_type==1)
							{
								$id = $date1;
								$id1= $date2; 
								$qry3=mysql_query("Select * FROM  incoming_letters_transaction, login WHERE incoming_letters_transaction.dept_id!='0' AND (incoming_letters_transaction.status='pending') AND login.login_id='$username' AND incoming_letters_transaction.dept_id='$deptid' AND (incoming_letters_transaction.receive_dt BETWEEN '$date1' AND '$date2')") OR die("aaaa".mysql_error());
							
								$qry4=mysql_query("SELECT DISTINCT i.ltr_type, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.returned_choice, t.dpt_inword_no, t.desk_id,t.desk_approval, t.dept_id_from, i.subject, 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.sent_to_desk_dt
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								WHERE t.dept_id_from='$deptid' 
								AND (t.desk_id='0' OR t.desk_approval='pending') AND (i.receive_dt BETWEEN '$date1' AND '$date2')")OR die("agg".mysql_error());
								
								$qry5=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt,t.returned_choice, t.dpt_inword_no, t.desk_id, t.dept_id_from,di.dept_id_to, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND de.ltr_status!='closed' AND de.ltr_approval!='transferred_todesk'
								AND (i.receive_dt BETWEEN '$date1' AND '$date2')") OR die("aabbhhaa".mysql_error());
							}
							
							else if($date123!=''&& $date223!='' && $dt_type==2)
							{
								$id = $date1;
								$id1= $date2; 
								$qry3=mysql_query("Select * FROM  incoming_letters_transaction, login WHERE incoming_letters_transaction.dept_id!='0' AND (incoming_letters_transaction.status='pending') AND login.login_id='$username' AND incoming_letters_transaction.dept_id='$deptid'") OR die("aaaa".mysql_error());
							
								$qry4=mysql_query("SELECT DISTINCT i.ltr_type, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.returned_choice, t.dpt_inword_no, t.desk_id,t.desk_approval, t.dept_id_from, i.subject, 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.sent_to_desk_dt
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								WHERE t.dept_id_from='$deptid' 
								AND (t.desk_id='0' OR t.desk_approval='pending') AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aaxx".mysql_error());
								
								$qry5=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt,t.returned_choice, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt,di.dept_id_to, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND de.ltr_status!='closed' AND de.ltr_approval!='transferred_todesk'
								AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aabbhhaa".mysql_error());
							}
							
							else if($date123!=''&& $date223!='' && $dt_type==3)
							{
								$id = $date1;
								$id1= $date2; 
								$qry3=mysql_query("Select * FROM  incoming_letters_transaction, login WHERE incoming_letters_transaction.dept_id!='0' AND (incoming_letters_transaction.status='pending') AND login.login_id='$username' AND incoming_letters_transaction.dept_id='$deptid'") OR die("aaaa".mysql_error());
							
								$qry4=mysql_query("SELECT DISTINCT i.ltr_type, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.returned_choice, t.dpt_inword_no, t.desk_id,t.desk_approval, t.dept_id_from, i.subject, 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.sent_to_desk_dt
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								WHERE t.dept_id_from='$deptid' 
								AND (t.desk_id='0' OR t.desk_approval='pending') AND (de.desk_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("mmm".mysql_error());
								
								$qry5=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt,t.returned_choice, t.dpt_inword_no, t.desk_id, t.dept_id_from,di.dept_id_to, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND de.ltr_status!='closed' AND de.ltr_approval!='transferred_todesk'
								AND (de.desk_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aabbhhaa".mysql_error());
							}
							
							else if($date123!=''&& $date223!='' && $dt_type==4)
							{
								$id = $date1;
								$id1= $date2; 
								
								$qry3=mysql_query("Select * FROM  incoming_letters_transaction, login WHERE incoming_letters_transaction.dept_id!='0' AND (incoming_letters_transaction.status='pending') AND login.login_id='$username' AND incoming_letters_transaction.dept_id='$deptid'") OR die("aaaa".mysql_error());
							
								$qry4=mysql_query("SELECT DISTINCT i.ltr_type, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.returned_choice, t.dpt_inword_no, t.desk_id,t.desk_approval, t.dept_id_from, i.subject, 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.sent_to_desk_dt
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								WHERE t.dept_id_from='$deptid' 
								AND (t.desk_id='0' OR t.desk_approval='pending') AND ((de.update_date BETWEEN '$date1' AND '$date2') OR (de.dispatched_dt BETWEEN '$date1' AND '$date2')) ") OR die("avc".mysql_error());
								
								$qry5=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt,t.returned_choice, t.dpt_inword_no, t.desk_id, t.dept_id_from,di.dept_id_to, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.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, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
								WHERE t.dept_id_from='$deptid' 
								AND de.ltr_status!='closed' AND de.ltr_approval!='transferred_todesk'
								AND ((de.update_date BETWEEN '$date1' AND '$date2') OR (de.dispatched_dt BETWEEN '$date1' AND '$date2'))") OR die("aabbhhaa".mysql_error());
							}
						
						echo"<tr>
									<th class='head1 center'>पोलीस अधिक्षक <br> कार्यालय <br> आवक क्रमांक <br>आवक_दिनांक</th>
									<th class='head0 center'>विभागीय आवक क्र.<br>आवक_दिनांक</th>
									<th class='head1 center'>डेस्कचा आवक क्र. <br>आवक_दिनांक</th>
									<th class='head0 center'>संदर्भ_क्रमांक <br>संदर्भ दि. </th>
									<th class='head1 center'>संदर्भ_प्रकार</th>
									<th class='head0 center'>विषय</th>
									<th class='head1 center'>कोणाकडून <br>प्राप्त_झाला</th>
									<th class='head0 center'>केलेली_कार्यवाही</th>
									<th class='head0 center'>पत्राची_स्थिती </th>
									<th class='head1 center'>विभागीय <br>जावक_दिनांक</th>	
								</tr>";
						echo "</tr>";
						while($test = mysql_fetch_array($qry3))
						{		
								$ltrinward=$test['ltr_inword_no'];	
								$dept_rec_date 	= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
								$receive_dt	= date('d-m-Y',strtotime($test['receive_dt']));
								$refdt	= date('d-m-Y',strtotime($test['ref_dt']));
								$m=$test['ltr_type'];
								$update_date 		= date('d-m-Y',strtotime($test['update_date']));
								$dispose_date 		= date('d-m-Y',strtotime($test['dispatched_dt']));
								$deskid=$test['desk_id'];
							echo "
							<tr class='gradeX'>
							<td class='center'>".$ltrinward."<br>".$receive_dt."</td>";
							if($test['dpt_inword_no']=='')
							{
								echo "<td class='center'>"." विभागाने स्वीकारणे बाकी" ."</td>";
							
							}
							else
							{
								echo "<td class='center'>".$test['dpt_inword_no']."<br>".$dept_rec_date ."</td>";
							}
							
							if($test['desk_id']=='' || $test['desk_id']==0)
							{
								echo "<td class='center'>"."डेस्क लावणे बाकी "."</td>";
							}
							else if($test['desk_ltr_inword_no']=='' || $test['desk_ltr_inword_no']=='0')
							{
								echo "<td class='center'>"."डेस्कने स्वीकारणे बाकी "."</td>";
							}
							else
							{
								echo "<td class='center'>".$test['desk_ltr_inword_no']."<br>".$deskrec_dt."</td>";
							}
							
							echo "<td class='center'>".$test['ref_no']."<br>".$refdt."</td>";
							$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
							$s=mysql_fetch_array($ltrtype);
							echo "<td class='center'>".$s['sandharbh_nm']."</td>
							<td class='center'>".$test['subject']."</td>
							<td class='center'>".$test['sender_name']."</td>";
							
							if($test['ltr_status']=='' ||$test['ltr_status']=='NULL')
							{
								echo"<td class='center'>"."कार्यवाही करणे बाकी "."</td>";
							}
							else
							{
								echo"<td class='center'>".$test['action_taken']."</td>";
							}
							
							if($test['ltr_status']=='' || $test['ltr_status']=='NULL')
							{
								echo "<td class='center'> कार्यवाही करणे बाकी </td>";	
							}
							else
							{
								echo "<td class='center'>". $test['ltr_status'] ."</td>";
							}
							
							if ($test['ltr_status']=='updated')
							{
								echo "<td class='center'>".$update_date."</td>";
							}
							else if($test1['ltr_status']=='dispatched')
							{
								echo "<td class='center'>".$dispose_date."</td>";
							}
							else 
							{
								echo "<td class='center'> कार्यवाही करणे बाकी </td>";
							}
							echo "</tr>";
						}
						
						while($test1 = mysql_fetch_array($qry4))
						{		
								$ltrinward=$test1['ltr_inword_no'];
								$desk_ltr_rec_dt = date('d-m-Y',strtotime($test1['desk_ltr_rec_dt']));
								$dept_rec_date 	= date('d-m-Y',strtotime($test1['dpt_ltr_rec_dt']));
								$receive_dt	= date('d-m-Y',strtotime($test1['receive_dt']));
								$refdt	= date('d-m-Y',strtotime($test1['ref_dt']));
								$deskrec_dt	= date('d-m-Y',strtotime($test1['sent_to_desk_dt']));
								$update_date 		= date('d-m-Y',strtotime($test1['update_date']));
								$dispose_date 		= date('d-m-Y',strtotime($test1['dispatched_dt']));
								$m=$test1['ltr_type'];
								$deskid=$test1['desk_id'];
								
								$dsk1=$test1['desk_id_from'];
								//echo $dsk."aaaaaaaaa";
								convert_marathi();
								$qsk1=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk1'") or die("".mysql_error());
								$desk1=mysql_fetch_array($qsk1);
								
								$dsk2=$test1['desk_id'];
								//echo $dsk."aaaaaaaaa";
								convert_marathi();
								$qsk2=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk2'") or die("".mysql_error());
								$desk2=mysql_fetch_array($qsk2);
								
								//closed lettr
								$ltrinward=$test1['ltr_inword_no'];
								$deskidfrom=$test1['desk_id_from'];
								if($test1['ltr_status']=='closed')
								{
									$query=mysql_query("select rtn_to_dsk from  returned_from_desk 
														where ltr_inword_no='$ltrinward'
														AND returned_from='$deskidfrom' ");		
									$result=mysql_fetch_array($query);
									//echo $result['rtn_to_dsk']."<br>";
								}
								
							echo "
							<tr class='gradeX'>
							<td class='center'>".$ltrinward."<br>".$receive_dt."</td>";
							if($test1['dpt_inword_no']=='')
							{
								echo "<td class='center'>"." विभागाने स्वीकारणे बाकी" ."</td>";
							
							}
							else
							{
								echo "<td class='center'>".$test1['dpt_inword_no']."<br>".$dept_rec_date ."</td>";
							}
							//////////////////////////////////////////////////////////////////
							if($test1['returned_choice']!='')
							{
								echo "<td class='center'>Letter Returned To<br> Tapal </td>";
							}
							else if( $test1['desk_id']=='' || $test1['desk_id']==0 )
							{
								echo "<td class='center'>"."डेस्क लावणे बाकी "."</td>";
							}
							else if($test1['desk_ltr_inword_no']=='' || $test1['desk_ltr_inword_no']=='0')
							{
								echo "<td class='center'>".$desk2['desk_nm']."<br>"."डेस्कने स्वीकारणे बाकी "."</td>";
							}
							else
							{
								echo "<td class='center'>".$desk1['desk_nm']."<br>".$test1['desk_ltr_inword_no']."<br>".$deskrec_dt."</td>";
							}
							///////////////////////////////////////////////////////////////////////
							echo "<td class='center'>".$test1['ref_no']."<br>".$refdt."</td>";
							$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
							$s=mysql_fetch_array($ltrtype);
							echo "<td class='center'>".$s['sandharbh_nm']."</td>
							<td class='center'>".$test1['subject']."</td>
							<td class='center'>".$test1['sender_name']."</td>";
							///////////////////////// Action taken //////////////////////////////
							if($result['rtn_to_dsk']=='')
							{
								$returnto=$deptnm['dept_nm'];
									
							}
							else
							{
								$dsk_nm=$result['rtn_to_dsk'];
								$qw=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk_nm'") or die("".mysql_error());
								$de=mysql_fetch_array($qw);
								$returnto=$de['desk_nm'];
							}
							if($test1['returned_choice']!='')
							{
								echo "<td class='center'>-- </td>";
							}	
							else if($test1['ltr_status']=='' ||$test1['ltr_status']=='NULL')
							{
								echo"<td class='center'>"."कार्यवाही करणे बाकी "."</td>";
							}
							else if($test1['ltr_status']=='closed' )
							{
								echo"<td class='center'>Letter Returned To <br>".$returnto."</td>";
							}
							else
							{
								echo"<td class='center'>".$test1['action_taken']."</td>";
							}
							///////////////////////////////////////////////////////////////////////
							if($test1['returned_choice']!='')
							{
								echo "<td class='center'>Letter Returned To<br> Tapal </td>";
							}	
							else if($test1['ltr_status']=='' || $test1['ltr_status']=='NULL')
							{
								echo "<td class='center'> कार्यवाही करणे बाकी </td>";	
							}
							else if($test1['ltr_approval']=='transferred')
							{
								$dpt_to=$test1['dept_id_to'];
								$q=mysql_query("SELECT dept_nm from department_master where dept_id='$dpt_to' ");
								$r=mysql_fetch_array($q);
								echo "<td class='center'>".$test1['ltr_approval']." to <br>".$r['dept_nm']."</td>";
							}
							else
							{
								echo "<td class='center'>". $test1['ltr_status'] ."</td>";
							}
							///////////////////////////////////////////////////////////////
							if($test1['returned_choice']!='')
							{
								echo "<td class='center'>-- </td>";
							}	
							else if ($test1['ltr_status']=='updated')
							{
								echo "<td class='center'>".$update_date."</td>";
							}
							else if($test1['ltr_status']=='dispatched')
							{
								echo "<td class='center'>".$dispose_date."</td>";
							}
							else if($test1['ltr_status']=='closed')
							{
								echo "<td class='center'>--</td>";
							}
							else 
							{
								echo "<td class='center'> कार्यवाही करणे बाकी </td>";
							}
											
										echo "</tr>";
						}	
						
						while($test1 = mysql_fetch_array($qry5))
						{		
								$ltrinward=$test1['ltr_inword_no'];
								$desk_ltr_rec_dt = date('d-m-Y',strtotime($test1['desk_ltr_rec_dt']));
								$dept_rec_date 	= date('d-m-Y',strtotime($test1['dpt_ltr_rec_dt']));
								$receive_dt	= date('d-m-Y',strtotime($test1['receive_dt']));
								$refdt	= date('d-m-Y',strtotime($test1['ref_dt']));
								$deskrec_dt	= date('d-m-Y',strtotime($test1['sent_to_desk_dt']));
								$update_date 		= date('d-m-Y',strtotime($test1['update_date']));
								$dispose_date 		= date('d-m-Y',strtotime($test1['dispatched_dt']));
								$m=$test1['ltr_type'];
								$deskid=$test1['desk_id'];
								
								$dsk1=$test1['desk_id_from'];
								//echo $dsk."aaaaaaaaa";
								convert_marathi();
								$qsk1=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk1'") or die("".mysql_error());
								$desk1=mysql_fetch_array($qsk1);
								
								$dsk2=$test1['desk_id'];
								//echo $dsk."aaaaaaaaa";
								convert_marathi();
								$qsk2=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk2'") or die("".mysql_error());
								$desk2=mysql_fetch_array($qsk2);
								
								//closed lettr
								$ltrinward=$test1['ltr_inword_no'];
								$deskidfrom=$test1['desk_id_from'];
								if($test1['ltr_status']=='closed')
								{
									$query=mysql_query("select rtn_to_dsk from  returned_from_desk 
														where ltr_inword_no='$ltrinward'
														AND returned_from='$deskidfrom' ");		
									$result=mysql_fetch_array($query);
									//echo $result['rtn_to_dsk']."<br>";
								}
								
							echo "
							<tr class='gradeX'>
							<td class='center'>".$ltrinward."<br>".$receive_dt."</td>";
							if($test1['dpt_inword_no']=='')
							{
								echo "<td class='center'>"." विभागाने स्वीकारणे बाकी" ."</td>";
							
							}
							else
							{
								echo "<td class='center'>".$test1['dpt_inword_no']."<br>".$dept_rec_date ."</td>";
							}
							//////////////////////////////////////////////////////////////////
							if($test1['desk_id']=='' || $test1['desk_id']==0)
							{
								echo "<td class='center'>"."डेस्क लावणे बाकी "."</td>";
							}
							else if($test1['desk_ltr_inword_no']=='' || $test1['desk_ltr_inword_no']=='0')
							{
								echo "<td class='center'>".$desk2['desk_nm']."<br>"."डेस्कने स्वीकारणे बाकी "."</td>";
							}
							else
							{
								echo "<td class='center'>".$desk1['desk_nm']."<br>".$test1['desk_ltr_inword_no']."<br>".$deskrec_dt."</td>";
							}
							///////////////////////////////////////////////////////////////////////
							echo "<td class='center'>".$test1['ref_no']."<br>".$refdt."</td>";
							$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
							$s=mysql_fetch_array($ltrtype);
							echo "<td class='center'>".$s['sandharbh_nm']."</td>
							<td class='center'>".$test1['subject']."</td>
							<td class='center'>".$test1['sender_name']."</td>";
							///////////////////////// Action taken //////////////////////////////
							if($result['rtn_to_dsk']=='')
							{
								$returnto=$deptnm['dept_nm'];
									
							}
							else
							{
								$dsk_nm=$result['rtn_to_dsk'];
								$qw=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk_nm'") or die("".mysql_error());
								$de=mysql_fetch_array($qw);
								$returnto=$de['desk_nm'];
							}
								
							if($test1['ltr_status']=='' ||$test1['ltr_status']=='NULL')
							{
								echo"<td class='center'>"."कार्यवाही करणे बाकी "."</td>";
							}
							else if($test1['ltr_status']=='closed' )
							{
								echo"<td class='center'>Letter Returned To <br>".$returnto."</td>";
							}
							else
							{
								echo"<td class='center'>".$test1['action_taken']."</td>";
							}
							///////////////////////////////////////////////////////////////////////
							if($test1['ltr_status']=='' || $test1['ltr_status']=='NULL')
							{
								echo "<td class='center'> कार्यवाही करणे बाकी </td>";	
							}
							else if($test1['ltr_approval']=='transferred')
							{
								$dpt_to=$test1['dept_id_to'];
								$q=mysql_query("SELECT dept_nm from department_master where dept_id='$dpt_to' ");
								$r=mysql_fetch_array($q);
								echo "<td class='center'>".$test1['ltr_approval']." to <br>".$r['dept_nm']."</td>";
							}
							else
							{
								echo "<td class='center'>". $test1['ltr_status'] ."</td>";
							}
							///////////////////////////////////////////////////////////////
							if ($test1['ltr_status']=='updated')
							{
								echo "<td class='center'>".$update_date."</td>";
							}
							else if($test1['ltr_status']=='dispatched')
							{
								echo "<td class='center'>".$dispose_date."</td>";
							}
							else if($test1['ltr_status']=='closed')
							{
								echo "<td class='center'>--</td>";
							}
							else 
							{
								echo "<td class='center'>कार्यवाही करणे बाकी </td>";
							}
											
										echo "</tr>";
						}		   
						
					echo"</table></center></div>";							
					} //if($flag=='')
					
					else if($flag=='n')
					{
					?>		
			
			 <h4 class="widgettitle"><?php echo $deptnm['dept_nm'];?>चे एकूण पत्राचे रिपोर्ट्स  <h4>
						<form name="sadyasthiti" action="" method="post">
						<div align="center"><br><table align="center" cellpadding="2" cellspacing="0" class='myClass'>
						<table>
							<tr>
							<td><label>तारखेचा प्रकार निवडा  : </label></td>
								<td><span class="field unicode" lang="mr">
										<select name="datetype">
											<option value="">तारखेचा प्रकार निवडा</option>  
											<option value="1">आवक दिनांक</option>
											<option value="2">विभागीय आवक दिनांक</option>
											<option value="4">अपडेट/जावक दिनांक </option>
										</select>
									</span>
								</td>
								<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>
				</form>
				<form>
						

						<?php
						$dt_type=$_POST['datetype'];
						//echo "".$dt_type;
						$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));
						$id = $date1;
						$id1= $date2;
						
						if($date123==''&& $date223=='' && $dt_type=='')
							{	

								echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								
								//dept not accpted
								$qry3=mysql_query("Select * FROM  incoming_letters_transaction, login WHERE incoming_letters_transaction.dept_id!='0' AND (incoming_letters_transaction.status='pending') AND login.login_id='$username' AND incoming_letters_transaction.dept_id='$deptid'") OR die("aaaa".mysql_error());
								
								//dept accpted
								$qry4=mysql_query("SELECT DISTINCT i.ltr_type, 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.returned_choice, t.status, di.addressed_to,di.dept_id_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,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i 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='$deptid'") OR die("aabbhhaa".mysql_error());
							}
						else if($date123!=''&& $date223!='' && $dt_type==1)
							{
								echo '<br><center><h4> <font color="red">आवक दिनांकनुसार संदर्भ </font></h4></center><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								$qry3=mysql_query("Select * FROM  incoming_letters_transaction, login WHERE incoming_letters_transaction.dept_id!='0' AND (incoming_letters_transaction.status='pending') AND login.login_id='$username' AND incoming_letters_transaction.dept_id='$deptid' AND (incoming_letters_transaction.receive_dt BETWEEN '$date1' AND '$date2')") OR die("aaaa".mysql_error());
							
								$qry4=mysql_query("SELECT DISTINCT i.ltr_type, t.action_taken, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no,t.returned_choice, t.desk_id, t.dept_id_from, i.subject, t.update_date, t.dispatched_date, t.status, di.addressed_to,di.dept_id_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,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i 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='$deptid' AND (i.receive_dt BETWEEN '$date1' AND '$date2')")OR die("agg".mysql_error());
							}
							
							else if($date123!=''&& $date223!='' && $dt_type==2)
							{
								echo '<br><center><h4> <font color="red">विभागीय आवक दिनांकनुसार संदर्भ</font></h4></center><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								$qry3=mysql_query("Select * FROM  incoming_letters_transaction, login WHERE incoming_letters_transaction.dept_id!='0' AND (incoming_letters_transaction.status='pending') AND login.login_id='$username' AND incoming_letters_transaction.dept_id='$deptid'") OR die("aaaa".mysql_error());
							
								$qry4=mysql_query("SELECT DISTINCT i.ltr_type, 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,t.returned_choice, di.addressed_to,di.dept_id_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,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i 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='$deptid' AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aaxx".mysql_error());
							}
							
							else if($date123!=''&& $date223!='' && $dt_type==4)
							{
								echo '<br><center><h4> <font color="red">अपडेट/जावक दिनांकनुसार संदर्भ</font></h4></center><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';$id = $date1;
								$id1= $date2; 
								
								$qry3=mysql_query("Select * FROM  incoming_letters_transaction, login WHERE incoming_letters_transaction.dept_id!='0' AND (incoming_letters_transaction.status='pending') AND login.login_id='$username' AND incoming_letters_transaction.dept_id='$deptid'") OR die("aaaa".mysql_error());
							
								$qry4=mysql_query("SELECT DISTINCT i.ltr_type, 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,t.returned_choice, di.addressed_to,di.dept_id_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,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i 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='$deptid' AND ((de.update_date BETWEEN '$date1' AND '$date2') OR (de.dispatched_dt BETWEEN '$date1' AND '$date2')) ") OR die("avc".mysql_error());
							}
						echo"  <br><br><table id='dyntable' class='table table-bordered'>
								<thead>
								<tr>
									<th class='head1 center'>पोलीस अधिक्षक <br> कार्यालय <br> आवक क्रमांक <br>आवक_दिनांक</th>
									<th class='head0 center'>विभागीय आवक क्र.<br>आवक_दिनांक</th>
									<th class='head0 center'>संदर्भ_क्रमांक <br>संदर्भ दि. </th>
									<th class='head1 center'>संदर्भ_प्रकार</th>
									<th class='head0 center'>विषय</th>
									<th class='head1 center'>कोणाकडून <br>प्राप्त_झाला</th>
									<th class='head0 center'>केलेली_कार्यवाही</th>
									<th class='head0 center'>पत्राची_स्थिती </th>
									<th class='head1 center'>विभागीय <br>जावक_दिनांक</th>	
								</tr>
								</thead>
							<tbody>";
						
						while($test = mysql_fetch_array($qry3))
						{		
								$ltrinward=$test['ltr_inword_no'];	
								$dept_rec_date 	= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
								$receive_dt	= date('d-m-Y',strtotime($test['receive_dt']));
								$refdt	= date('d-m-Y',strtotime($test['ref_dt']));
								$m=$test['ltr_type'];
								$update_date 		= date('d-m-Y',strtotime($test['update_date']));
								$dispose_date 		= date('d-m-Y',strtotime($test['dispatched_date']));
							echo "
							<tr class='gradeX'>
							<td class='center'>".$ltrinward."<br>".$receive_dt."</td>";
							if($test['dpt_inword_no']=='')
							{
								echo "<td class='center'><font color='red'>"." विभागाने स्वीकारणे बाकी" ."</font></td>";
							
							}
							else
							{
								echo "<td class='center'>".$test['dpt_inword_no']."<br>".$dept_rec_date ."</td>";
							}
							
							echo "<td class='center'>".$test['ref_no']."<br>".$refdt."</td>";
							$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
							$s=mysql_fetch_array($ltrtype);
							echo "<td class='center'>".$s['sandharbh_nm']."</td>
							<td class='center'>".$test['subject']."</td>
							<td class='center'>".$test['sender_name']."</td>";
							/////////////////////////////////////////////////////////////////
							if($test['ltr_status']=='' ||$test['ltr_status']=='NULL')
							{
								echo"<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
							}
							else
							{
								echo"<td class='center'>".$test['action_taken']."</td>";
							}
							///////////////////////////////////////////////////////////////
							if($test['ltr_status']=='' || $test['ltr_status']=='NULL')
							{
								echo "<td class='center'><font color='red'> कार्यवाही करणे बाकी </font></td>";	
							}
							else
							{
								echo "<td class='center'>". $test['ltr_status'] ."bvn</td>";
							}
							if ($test['ltr_status']=='updated')
							{
								echo "<td class='center'>".$update_date."</td>";
							}
							else if($test1['ltr_status']=='dispatched')
							{
								echo "<td class='center'>".$dispose_date."</td>";
							}
							else 
							{
								echo "<td class='center'><font color='red'> कार्यवाही करणे बाकी </font></td>";
							}
						echo "</tr>";
						}
							
						while($test1 = mysql_fetch_array($qry4))
						{		
								$ltrinward=$test1['ltr_inword_no'];
								$dept_rec_date 	= date('d-m-Y',strtotime($test1['dpt_ltr_rec_dt']));
								$receive_dt	= date('d-m-Y',strtotime($test1['receive_dt']));
								$refdt	= date('d-m-Y',strtotime($test1['ref_dt']));
								$update_date 		= date('d-m-Y',strtotime($test1['update_date']));
								$dispose_date 		= date('d-m-Y',strtotime($test1['dispatched_date']));
								$m=$test1['ltr_type'];
								$return_ch=$test1['returned_choice'];
							echo "
							<tr class='gradeX'>
							<td class='center'>".$ltrinward."<br>".$receive_dt."</td>";
							if($test1['dpt_inword_no']=='')
							{
								echo "<td class='center'><font color='red'>"." विभागाने स्वीकारणे बाकी" ."</font></td>";
							
							}
							else
							{
								echo "<td class='center'>".$test1['dpt_inword_no']."<br>".$dept_rec_date ."</td>";
							}
							
							echo "<td class='center'>".$test1['ref_no']."<br>".$refdt."</td>";
							$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
							$s=mysql_fetch_array($ltrtype);
							echo "<td class='center'>".$s['sandharbh_nm']."</td>
							<td class='center'>".$test1['subject']."</td>
							<td class='center'>".$test1['sender_name']."</td>";
							
							///////////////////////////////////////////////////////////////
							if($return_ch!='')
							{
								echo"<td class='center'>Letter Returned To <br> Tapal</td>";
							}
							else if($test1['ltr_status']=='' ||$test1['ltr_status']=='NULL')
							{
								echo"<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
							}
							else
							{
								echo"<td class='center'>".$test1['action_taken']."</td>";
							}
							//////////////////////////////////////
							if($return_ch!='')
							{
								echo "<td class='center'>". $test1['status'] ."</td>";
							}
							else if($test1['ltr_status']=='' || $test1['ltr_status']=='NULL')
							{
								echo "<td class='center'><font color='red'> कार्यवाही करणे बाकी </font></td>";	
							}
							else if($test1['status']=='dispatched')
							{
								echo "<td class='center'>". $test1['status'] ."</td>";
							}
							else if($test1['status']=='transferred')
							{
								$dpt_to=$test1['dept_id_to'];
								$q=mysql_query("SELECT dept_nm from department_master where dept_id='$dpt_to' ");
								$r=mysql_fetch_array($q);
								echo "<td class='center'>".$test1['status']." to <br>".$r['dept_nm']."</td>";
							}
							else
							{
								echo "<td class='center'>". $test1['ltr_status'] ."</td>";
							}
							////////////////////////////////////////////
							if($return_ch!='')
							{
								echo "<td class='center'> -- </td>";
							}
							else if ($test1['ltr_status']=='updated')
							{
								echo "<td class='center'>".$update_date."</td>";
							}
							else if($test1['ltr_status']=='dispatched')
							{
								echo "<td class='center'>".$dispose_date."</td>";
							}
							else 
							{
								echo "<td class='center'><font color='red'> कार्यवाही करणे बाकी </font></td>";
							}
							echo "</tr>";
						}	
							   
					echo "</tbody></table>";	
						
							
					
						echo "<div id='divToPrint' style='display:none;'>
							<center><table id='export' border='1px' style='margin-left:50px;'>
							<tr><td colspan='10'><center> ".$deptnm['dept_nm']."चे एकूण पत्राचे डेस्क नुसार रिपोर्ट्स  <br>दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
							
							echo ' <center><h2>पोलीस अधिक्षक <br> कार्यालय <br> जि.रायगड<h2></center>';	
							
						$id1= $date2;
						 
						if($date123==''&& $date223=='' && $dt_type=='')
							{	

								$id = $date1;
								$id1= $date2; 
								
								//dept not accpted
								$qry3=mysql_query("Select * FROM  incoming_letters_transaction, login WHERE incoming_letters_transaction.dept_id!='0' AND (incoming_letters_transaction.status='pending') AND login.login_id='$username' AND incoming_letters_transaction.dept_id='$deptid'") OR die("aaaa".mysql_error());
								
								//dept accpted
								$qry4=mysql_query("SELECT DISTINCT i.ltr_type, 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.returned_choice, t.status, di.addressed_to, t.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt,di.dept_id_to, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i 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='$deptid'") OR die("aabbhhaa".mysql_error());
							}
						else if($date123!=''&& $date223!='' && $dt_type==1)
							{
								$id = $date1;
								$id1= $date2; 
								$qry3=mysql_query("Select * FROM  incoming_letters_transaction, login WHERE incoming_letters_transaction.dept_id!='0' AND (incoming_letters_transaction.status='pending') AND login.login_id='$username' AND incoming_letters_transaction.dept_id='$deptid' AND (incoming_letters_transaction.receive_dt BETWEEN '$date1' AND '$date2')") OR die("aaaa".mysql_error());
							
								$qry4=mysql_query("SELECT DISTINCT i.ltr_type, t.action_taken, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no,t.returned_choice, t.desk_id, t.dept_id_from,di.dept_id_to, 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,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i 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='$deptid' AND (i.receive_dt BETWEEN '$date1' AND '$date2')")OR die("agg".mysql_error());
							}
							
							else if($date123!=''&& $date223!='' && $dt_type==2)
							{
								$id = $date1;
								$id1= $date2; 
								$qry3=mysql_query("Select * FROM  incoming_letters_transaction, login WHERE incoming_letters_transaction.dept_id!='0' AND (incoming_letters_transaction.status='pending') AND login.login_id='$username' AND incoming_letters_transaction.dept_id='$deptid'") OR die("aaaa".mysql_error());
							
								$qry4=mysql_query("SELECT DISTINCT i.ltr_type, 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,t.returned_choice, di.addressed_to,di.dept_id_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,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i 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='$deptid' AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')") OR die("aaxx".mysql_error());
							}
							
							else if($date123!=''&& $date223!='' && $dt_type==4)
							{
								$id = $date1;
								$id1= $date2; 
								
								$qry3=mysql_query("Select * FROM  incoming_letters_transaction, login WHERE incoming_letters_transaction.dept_id!='0' AND (incoming_letters_transaction.status='pending') AND login.login_id='$username' AND incoming_letters_transaction.dept_id='$deptid'") OR die("aaaa".mysql_error());
							
								$qry4=mysql_query("SELECT DISTINCT i.ltr_type, 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,t.returned_choice, di.addressed_to,di.dept_id_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,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i 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='$deptid' AND ((de.update_date BETWEEN '$date1' AND '$date2') OR (de.dispatched_dt BETWEEN '$date1' AND '$date2')) ") OR die("avc".mysql_error());
							}
						
						echo"<tr>
									<th class='head1 center'>पोलीस अधिक्षक <br> कार्यालय <br> आवक क्रमांक <br>आवक_दिनांक</th>
									<th class='head0 center'>विभागीय आवक क्र.<br>आवक_दिनांक</th>
									<th class='head0 center'>संदर्भ_क्रमांक <br>संदर्भ दि. </th>
									<th class='head1 center'>संदर्भ_प्रकार</th>
									<th class='head0 center'>विषय</th>
									<th class='head1 center'>कोणाकडून <br>प्राप्त_झाला</th>
									<th class='head0 center'>केलेली_कार्यवाही</th>
									<th class='head0 center'>पत्राची_स्थिती </th>
									<th class='head1 center'>विभागीय <br>जावक_दिनांक</th>";
						echo "</tr>";
						while($test = mysql_fetch_array($qry3))
						{		
								$ltrinward=$test['ltr_inword_no'];	
								$dept_rec_date 	= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
								$receive_dt	= date('d-m-Y',strtotime($test['receive_dt']));
								$refdt	= date('d-m-Y',strtotime($test['ref_dt']));
								$m=$test['ltr_type'];
								$update_date 		= date('d-m-Y',strtotime($test['update_date']));
								$dispose_date 		= date('d-m-Y',strtotime($test['dispatched_date']));
							echo "
							<tr class='gradeX'>
							<td class='center'>".$ltrinward."<br>".$receive_dt."</td>";
							if($test['dpt_inword_no']=='')
							{
								echo "<td class='center'>"." विभागाने स्वीकारणे बाकी" ."</td>";
							
							}
							else
							{
								echo "<td class='center'>".$test['dpt_inword_no']."<br>".$dept_rec_date ."</td>";
							}
							
							echo "<td class='center'>".$test['ref_no']."<br>".$refdt."</td>";
							$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
							$s=mysql_fetch_array($ltrtype);
							echo "<td class='center'>".$s['sandharbh_nm']."</td>
							<td class='center'>".$test['subject']."</td>
							<td class='center'>".$test['sender_name']."</td>";
							if($test['ltr_status']=='' ||$test['ltr_status']=='NULL')
							{
								echo"<td class='center'>"."कार्यवाही करणे बाकी "."</td>";
							}
							else
							{
								echo"<td class='center'>".$test['action_taken']."</td>";
							}
							
							if($test['ltr_status']=='' || $test['ltr_status']=='NULL')
							{
								echo "<td class='center'> कार्यवाही करणे बाकी </td>";	
							}
							else
							{
								echo "<td class='center'>". $test['ltr_status'] ."</td>";
							}
											if ($test['ltr_status']=='updated')
											{
												echo "<td class='center'>".$update_date."</td>";
											}
											else if($test1['ltr_status']=='dispatched')
											{
												echo "<td class='center'>".$dispose_date."</td>";
											}
											else 
											{
											echo "<td class='center'> कार्यवाही करणे बाकी </td>";
											}
											
										echo "</tr>";
						}
						while($test1 = mysql_fetch_array($qry4))
						{		
								$ltrinward=$test1['ltr_inword_no'];
								$dept_rec_date 	= date('d-m-Y',strtotime($test1['dpt_ltr_rec_dt']));
								$receive_dt	= date('d-m-Y',strtotime($test1['receive_dt']));
								$refdt	= date('d-m-Y',strtotime($test1['ref_dt']));
								$update_date 		= date('d-m-Y',strtotime($test1['update_date']));
								$dispose_date 		= date('d-m-Y',strtotime($test1['dispatched_date']));
								$m=$test1['ltr_type'];
								$return_ch=$test1['returned_choice'];
							echo "
							<tr class='gradeX'>
							<td class='center'>".$ltrinward."<br>".$receive_dt."</td>";
							if($test1['dpt_inword_no']=='')
							{
								echo "<td class='center'>"." विभागाने स्वीकारणे बाकी" ."</td>";
							
							}
							else
							{
								echo "<td class='center'>".$test1['dpt_inword_no']."<br>".$dept_rec_date ."</td>";
							}
							
							echo "<td class='center'>".$test1['ref_no']."<br>".$refdt."</td>";
							$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
							$s=mysql_fetch_array($ltrtype);
							echo "<td class='center'>".$s['sandharbh_nm']."</td>
							<td class='center'>".$test1['subject']."</td>
							<td class='center'>".$test1['sender_name']."</td>";
							
							///////////////////////////////////////////////////////////////
							if($return_ch!='')
							{
								echo"<td class='center'>Letter Returned To <br> Tapal</td>";
							}
							else if($test1['ltr_status']=='' ||$test1['ltr_status']=='NULL')
							{
								echo"<td class='center'>"."कार्यवाही करणे बाकी "."</td>";
							}
							else
							{
								echo"<td class='center'>".$test1['action_taken']."</td>";
							}
							//////////////////////////////////////
							if($return_ch!='')
							{
								echo "<td class='center'>". $test1['status'] ."</td>";
							}
							else if($test1['ltr_status']=='' || $test1['ltr_status']=='NULL')
							{
								echo "<td class='center'> कार्यवाही करणे बाकी </td>";	
							}
							else if($test1['status']=='dispatched')
							{
								echo "<td class='center'>". $test1['status'] ."</td>";
							}
							else if($test1['status']=='transferred')
							{
								$dpt_to=$test1['dept_id_to'];
								$q=mysql_query("SELECT dept_nm from department_master where dept_id='$dpt_to' ");
								$r=mysql_fetch_array($q);
								echo "<td class='center'>".$test1['status']." to <br>".$r['dept_nm']."</td>";
							}
							else
							{
								echo "<td class='center'>". $test1['ltr_status'] ."</td>";
							}
							////////////////////////////////////////////
							if($return_ch!='')
							{
								echo "<td class='center'> -- </td>";
							}
							else if ($test1['ltr_status']=='updated')
							{
								echo "<td class='center'>".$update_date."</td>";
							}
							else if($test1['ltr_status']=='dispatched')
							{
								echo "<td class='center'>".$dispose_date."</td>";
							}
							else 
							{
								echo "<td class='center'> कार्यवाही करणे बाकी </td>";
							}
							echo "</tr>";
						}
						
					echo"</table></center></div>";	
					
					} // else if($flag=='n')
					
				}//if=5	
			######################### End OF Total Letter report tapal user #######################	
			
			############################## Returned Letter Report ##############################
				else if($no==6)
				{
						?>		
			
					<h4 class="widgettitle"><?php echo $deptnm['dept_nm'];?>रिटर्न केलेले पत्र रिपोर्ट्स  <h4>
					
				<form>
					

						<?php
						
						/*******************************************************************************
										Returned Letter
						****************************************************************************/		
						$qry1=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
						WHERE t.returned_choice!='' 
						AND t.ltr_id=i.ltr_id 
						AND t.dept_id_from='$deptid' 
						AND ((t.status='closed') OR ( t.desk_approval='returned'))") OR die("aaaa".mysql_error());
						$cnt=mysql_num_rows($qry1);
							echo" <br><br><table id='dyntable' class='table table-bordered'>
									<thead>
										<tr>
											<th class='head1 center'>पोलीस अधिक्षक <br> कार्यालय <br> आवक क्रमांक <br>आवक_दिनांक</th>
											<th class='head0 center'>विभागीय आवक क्र.<br>आवक_दिनांक</th>
											<th class='head0 center'>संदर्भ_क्रमांक <br>संदर्भ दि. </th>
											<th class='head1 center'>संदर्भाचा प्रकार</th>
											<th class='head0 center'>विषय</th>
											<th class='head1 center'>कोणाकडून <br>प्राप्त_झाला</th>";
								echo "</tr></thead>";
						
							
						while($test = mysql_fetch_array($qry1))
						{		
								$ltrinward=$test['ltr_inword_no'];
								$desk_ltr_rec_dt = date('d-m-Y',strtotime($test['desk_approval']));
								$dept_rec_date 	= date('d-m-Y',strtotime($test['sent_dt']));
								$receive_dt	= date('d-m-Y',strtotime($test['receive_dt']));
								$refdt	= date('d-m-Y',strtotime($test['ref_dt']));
								$deskrec_dt	= date('d-m-Y',strtotime($test['sent_to_desk_dt']));
								$m=$test['ltr_type'];
								$deskid=$test['desk_id'];
			
							echo "<tbody>
							<tr class='gradeX'>
							<td class='center'>".$ltrinward."<br>".$receive_dt."</td>";
							if($test['dpt_inword_no']=='')
							{
								echo "<td class='center'><font color=red>"." विभागाने स्वीकारणे बाकी" ."</font></td>";	
							}
							else
							{
								echo "<td class='center'>".$test['dpt_inword_no']."<br>".$dept_rec_date ."</td>";
							}
							
							
							echo "<td class='center'>".$test['ref_no']."<br>".$refdt."</td>";
							$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
							$s=mysql_fetch_array($ltrtype);
							echo "<td class='center'>".$s['sandharbh_nm']."</td>
							<td class='center'>".$test['subject']."</td>
							<td class='center'>".$test['sender_name']."</td>";
							

						}
						
					echo"</table>";		
						echo "<div id='divToPrint' style='display:none;'>
								<center><table id='export' border='1px' style='margin-left:50px;'>
								<tr><td colspan='8'><center><h4>".$deptnm['dept_nm']." रिटर्न केलेले पत्र रिपोर्ट्स <br>दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
								echo ' <center><h2>पोलीस अधिक्षक <br> कार्यालय <br> जि.रायगड<h2></center>';
							//	echo '<tr><td colspan="8"><center>दिनांक '.$date123.''.' पासून दिनांक '.''.$date223.' </center></tr>';
								$id = $date1;
								
						/*******************************************************************************
										Returned Letter
						****************************************************************************/
						$qry1=mysql_query("SELECT DISTINCT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de.update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, i.sent_dt, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
						WHERE t.returned_choice!='' 
						AND t.ltr_id=i.ltr_id 
						AND t.dept_id_from='$deptid' 
						AND ((t.status='closed') OR ( t.desk_approval='returned'))") OR die("aaaa".mysql_error());
						
						$cnt=mysql_num_rows($qry1);
							echo " 	<tr>
									<th>पोलीस अधिक्षक <br> कार्यालय <br> आवक_क्रमांक <br>आवक_दिनांक</th>
									<th>विभागीय आवक_क्र.<br>आवक_दिनांक</th>
									<th>संदर्भ_क्रमांक <br>संदर्भ दि. </th>
									<th>संदर्भाचा प्रकार</th>
									<th>विषय</th>
									<th>कोणाकडून <br>प्राप्त_झाला</th>";
									 echo "</tr>";
							while($test = mysql_fetch_array($qry1))
							{		
								$ltrinward=$test['ltr_inword_no'];
								$desk_ltr_rec_dt = date('d-m-Y',strtotime($test['desk_approval']));
								$dept_rec_date 	= date('d-m-Y',strtotime($test['sent_dt']));
								$receive_dt	= date('d-m-Y',strtotime($test['receive_dt']));
								$refdt	= date('d-m-Y',strtotime($test['ref_dt']));
								$deskrec_dt	= date('d-m-Y',strtotime($test['sent_to_desk_dt']));
								$m=$test['ltr_type'];
								$deskid=$test['desk_id'];
			
							echo "<tr>
							<td style='text-align:center;'>".$ltrinward."<br>".$receive_dt."</td>";
							if($test['dpt_inword_no']=='')
							{
								echo "<td style='text-align:center;'>"." विभागाने स्वीकारणे बाकी" ."</font></td>";
							}
							else
							{
							echo "<td style='text-align:center;'>".$test['dpt_inword_no']."<br>".$dept_rec_date ."</td>";
							}
							
							echo "<td style='text-align:center;'>".$test['ref_no']."<br>".$refdt."</td>";
							$ltrtype=mysql_query("select sandharbh_nm FROM sandharbh_master WHERE sandhrbh_id='$m'");
							$s=mysql_fetch_array($ltrtype);
							echo "<td style='text-align:center;'>".$s['sandharbh_nm']."</td>
							<td style='text-align:center;'>".$test['subject']."</td>
							<td style='text-align:center;'>".$test['sender_name']."</td>";
							
						}
						
					echo"</table></center></div>";								
					
				}//if=2									
						    		
            //if user tapal
######################## End Of Returned Letter Report ##############################   
		   ?>
                <br /><br />
                
               <p>	
				<center><input type="button" value=" Print Page " onclick="PrintDiv();" class="btn btn-primary"/>
			<input type="button" class="btn" onclick="tableToExcel('export', 'W3C Example Table')" value="Export to Excel"></center>
				</p></div>
			</form>
                
                <?php include_once('footer.php');
				?>
            
            </div><!--maincontentinner-->
        </div><!--maincontent-->
        
    </div><!--rightpanel-->
    
</div><!--mainwrapper-->
</body>
</html>